A Bun-first TypeScript monorepo that ports the visible behavior of the original mixed Rust/Python x-algorithm/ codebase into local TypeScript 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.
bun install
bun run typecheck
bun test
bun run startapps/api/src/server.ts exposes:
GET /healthPOST /scored-postsPOST /debug-scored-postsPOST /for-you-feedPOST /for-you-feed-urtPOST /thunder/postsPOST /grox/run
Example:
curl -s http://localhost:3000/scored-posts \
-H 'content-type: application/json' \
-d '{"viewerId":1,"userFeatures":{"followedUserIds":[10]}}'- Vercel AI SDK provider routing in
packages/phoenix/src/ai-sdk.ts.- Supports
xai,openai,anthropic, andgoogleproviders. - Uses
X_ALGORITHM_MODEL=provider:model. - Also exposes embedding routing via
X_ALGORITHM_EMBEDDING_MODEL.
- Supports
- 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.
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 startThe 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.
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.
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.
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.
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.
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.
Assumption: original production feature-switch, decider, stats, service-builder, and private feed clients are unavailable.
Replacement:
- Feature switches are represented through
query.paramsand componentenable(...)hooks. - Sources/hydrators/scorers/selectors preserve visible local logic with injected-client seams.
- For You and Phoenix pipelines expose
buildWithClients,mock, andprodlocal adapter constructors.
bun run typecheck
bun testExpected result: typecheck passes and the test suite passes.