8000 GitHub - AshrithSathu/x-algorithm-ts · GitHub
[go: up one dir, main page]

Skip to content

About

No description, website, or topics provided.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Repository files navigation

X Algorithm in TypeScript

A Bun-first TypeScript monorepo that ports the visible behavior of the original mixed Rust/Python x-algorithm/ codebase into local TypeScript packages.

Packages

  • packages/core — shared types, params, scoring utilities, and candidate-pipeline framework.
  • packages/phoenix — Phoenix/Grok retrieval and ranking model seams, runners, local deterministic model fallbacks, and Vercel AI SDK routing.
  • packages/thunder — in-memory in-network post store, Thunder service, Kafka-style adapters, and binary deserialization helpers.
  • packages/home-mixer — Home Mixer filters, scorers, selectors, sources, ads blending, pipeline wiring, query building, and endpoint service logic.
  • packages/grox — Grox content-understanding plans, tasks, classifiers, embedders, data loaders, generators, dispatcher, and runtime lifecycle.
  • apps/api — Bun HTTP API for local endpoints.

Run

bun install
bun run typecheck
bun test
bun run start

Endpoints

apps/api/src/server.ts exposes:

  • GET /health
  • POST /scored-posts
  • POST /debug-scored-posts
  • POST /for-you-feed
  • POST /for-you-feed-urt
  • POST /thunder/posts
  • POST /grox/run

Example:

curl -s http://localhost:3000/scored-posts \
  -H 'content-type: application/json' \
  -d '{"viewerId":1,"userFeatures":{"followedUserIds":[10]}}'

Additions made in this TypeScript port

  • Vercel AI SDK provider routing in packages/phoenix/src/ai-sdk.ts.
    • Supports xai, openai, anthropic, and google providers.
    • Uses X_ALGORITHM_MODEL=provider:model.
    • Also exposes embedding routing via X_ALGORITHM_EMBEDDING_MODEL.
  • Local runnable adapters for private runtime dependencies that are not available outside XAI.
  • Bun workspace structure with TypeScript project references.
  • Strict typechecking for source and tests via bun run typecheck.
  • Local parity tests covering Phoenix, Thunder, Home Mixer, Grox, and the candidate-pipeline framework.
  • Bun HTTP API instead of the original private gRPC/service-builder runtime.

Model provider examples

X_ALGORITHM_MODEL=xai:grok-3-mini bun run start
X_ALGORITHM_MODEL=openai:gpt-5.4-mini bun run start
X_ALGORITHM_MODEL=anthropic:claude-haiku-4-5-20251001 bun run start
X_ALGORITHM_MODEL=google:gemini-3.1-flash-lite bun run start

License and attribution

The original x-algorithm/ repository is licensed under the Apache License 2.0. This TypeScript/Bun port keeps the same Apache-2.0 license in LICENSE and marks the package as Apache-2.0 in package.json.

This repository is a modified/translated TypeScript implementation of the visible behavior from the original mixed Rust/Python source. Changes include the Bun workspace layout, TypeScript package boundaries, local adapter replacements for private infrastructure, Vercel AI SDK provider routing, and Bun HTTP endpoints.

Apache-2.0 permits use, modification, distribution, and derivative works, provided that redistributions keep the license text and preserve applicable copyright, patent, trademark, and attribution notices. No original NOTICE file was present in the source tree.

Assumptions and local replacements

The original repository depends on private infrastructure and generated schemas that are not present in this workspace. This port keeps the visible behavior and call boundaries, but replaces unavailable production pieces with local TypeScript interfaces, mocks, deterministic fallbacks, or payload builders.

Private schemas and generated types

Assumption: exact private protobuf/thrift definitions are unavailable.

Replacement:

  • Shared local interfaces live in packages/core/src/types.ts.
  • Thunder binary payloads are decoded at the visible wire/protocol boundary where possible.
  • Unknown generated enum values are represented by string unions, numbers, or inferred local fields based on visible call sites.

Private services and storage

Assumption: production Kafka, Redis, Manhattan, Strato, TES, Gizmoduck, social graph, visibility filtering, safety-label stores, stats receivers, and tracing systems are unavailable.

Replacement:

  • Local adapter interfaces and in-memory clients are used.
  • Side effects build local payloads and record local metric objects instead of publishing to private infrastructure.
  • Query/candidate hydrators read from injected clients, query.sourceData, or in-memory maps.

Phoenix model artifacts

Assumption: JAX/Haiku .npz checkpoints, embedding tables, and ANN/corpus artifacts are unavailable.

Replacement:

  • Phoenix runners expose checkpoint/embedding-table seams.
  • Local deterministic vector/model fallbacks preserve input-building, masking, ranking, and retrieval behavior.
  • Exact production numerical parity is not claimed without the private artifacts.

Grox model and ASR systems

Assumption: private Grok sampler endpoints, prompt stores, ASR backend, Kafka topics, and production sinks are unavailable.

Replacement:

  • Classifiers preserve visible conversation construction, parsing, policy routing, and local fallback behavior.
  • ASR/data-loader/generator/runtime flows use local queue and adapter seams.
  • Publishing tasks build local content-analysis, annotation, reply-ranking, embedding, and safety payloads.

Home Mixer runtime

Assumption: original production feature-switch, decider, stats, service-builder, and private feed clients are unavailable.

Replacement:

  • Feature switches are represented through query.params and component enable(...) hooks.
  • Sources/hydrators/scorers/selectors preserve visible local logic with injected-client seams.
  • For You and Phoenix pipelines expose buildWithClients, mock, and prod local adapter constructors.

Current validation

bun run typecheck
bun test

Expected result: typecheck passes and the test suite passes.

About

No description, website, or topics provided.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0