Import the Translation Agent as private `apps/server` and `apps/console` workspace apps by diogoascarneiro · Pull Request #55 · cloudflare/polystella · GitHub
Skip to content

Import the Translation Agent as private apps/server and apps/console workspace apps - #55

Open
diogoascarneiro wants to merge 7 commits into
mainfrom
import-translation-agent
Open

diogoascarneiro wants to merge 7 commits into
mainfrom
import-translation-agent

Conversation

@diogoascarneiro

Copy link
Copy Markdown
Collaborator

Summary

This adds the Translation Agent to the monorepo as two private workspace apps. It's the first step toward running the Agent on @cloudflare/polystella-core.

  • apps/server (polystella-server): the Agent's Hono API Worker. This covers /api/translate, the model adapters, streaming, the content guardrail, and the evaluation scripts.
  • apps/console (polystella-console): the Agent's existing React translation UI and its static-assets Worker. It talks to the server only over HTTP; neither app depends on the other in the workspace.

No published package changes. The changeset is empty.

The code comes from the old repo at 0757e8f, moved without changes except where noted below. The old repo stays authoritative for production and language resources. This port runs in isolation until parity is confirmed, and it is not deployed.

What changed

Apps

  • The old repo's api/ becomes apps/server/, including docs/openapi.yaml and NOTICE. Its ui/ becomes apps/console/.
  • package.json is split between the two apps by dependency. Tests moved to apps/server/vitest.config.ts; the console's vite.config.ts is build and dev only.
  • The only source fix needed: in apps/console/styles.css, the Kumo @source path changed from ../node_modules/… to ./node_modules/….
  • Checked against a build of the pre-split code:
    • Server bundle code is identical.
    • Console JS is byte-identical.
    • Console CSS gains 5 unused utility rules and loses none. Tailwind's source detection now starts at the package root.
  • Both Wrangler configs have no production account, route, or zone. Worker names end in -local, with workers_dev: false and preview_urls: false.
  • Real glossaries, guardrail allowlists, and evaluation data are not committed. Empty or synthetic placeholders keep tests and builds deterministic.
  • Each app has a README. apps/server/README.md maps old-repo paths to port paths so upstream changes can be replayed while the port runs in isolation.

Language resources now come from PolyStella glossaries

  • apps/server/scripts/load-glossaries.ts runs Core's glossary loader (@cloudflare/polystella-core/cli/glossary) before dev and build. It writes the gitignored src/generated/glossaries.json, which is bundled into the Worker. Two variables control it:
    • GLOSSARY_SOURCE: JSON in Core's glossary config shape (file, http, or r2). If unset, the loader writes {}.
    • GLOSSARY_LOCALES: optional. Defaults to every supported locale plus default. Required for http and r2, because those sources fail on a missing locale.
  • prompt-utils.ts builds the prompt from the target locale's glossary:
    • Terminology comes from preferredTranslations. The Agent's ; alias syntax in keys is still supported.
    • Do-not-translate terms come from doNotTranslate.
    • The style guide comes from styleRules and notes.
    • Do-not-translate terms and the style guide fall back to the default glossary.
  • Removed src/terminology.ts, locales/utils.ts, and the node:fs readFileSync style-guide lookup (which couldn't run on Workerd).
  • Core is a dev dependency of the server (workspace:*). The Worker imports only the Glossary type.
  • In tests, a small Vite plugin in vitest.config.ts replaces the generated file with {}. prompt-utils.test.ts installs synthetic glossaries.

Workspace and CI

  • Root scripts:
    • New: test:apps, typecheck:apps, build:apps, dev:apps.
    • test and typecheck now include the apps.
  • CI runs pnpm test:apps and pnpm build:apps. build:apps is a Wrangler dry run with no deploy.
  • Added braintrust to allowBuilds.
  • Updated the AGENTS.md command table and added a "Modify the hosted Translation Agent" row.

Security overrides (pnpm audit:prod was failing)

Behaviour differences from the old repo

  • Language resources come from PolyStella glossaries (GLOSSARY_SOURCE) instead of the bundled terminology.ts, locales/utils.ts, and language-guide-new/*.md. With no source set, prompts have no terminology, do-not-translate list, or style guide.
  • The style guide is rendered from the glossary's styleRules (one ### <category> section each) and notes, instead of the .md file verbatim. The text is the same, but headings become the converted category names.
  • Do-not-translate terms are per locale, with a default fallback, instead of one global list. A converted glossary repeats the global list in each locale, so the output is the same.
  • meta.styleGuideSource and the style_guide_source span field read glossary:<locale> or glossary:default instead of <locale>.md or default.md.
  • The HTTP contract (POST /api/translate request fields, response shape, meta[locale].model, limits) is unchanged.

Testing

  • pnpm test: all suites pass (server: 249 passed, 4 skipped; 4 new style-guide and fallback tests)
  • pnpm typecheck, with an empty glossary file and with 19 real glossaries loaded
  • pnpm build:apps
  • pnpm check:packages
  • pnpm format:check
  • pnpm audit:prod: no known vulnerabilities
  • From a clean checkout with no generated file, test:apps and typecheck:apps pass
  • Loading glossaries from a local file source writes 19 glossaries, and the prompt picks up terminology, do-not-translate terms, and glossary:<locale> or glossary:default style guides
  • Console wrangler deploy --dry-run
  • Live wrangler dev smoke test: not run. The AI binding always uses remote Workers AI, so it needs Cloudflare auth and incurs inference charges.

@github-actions github-actions Bot added the review/needs-review No maintainer review yet label Sep 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot added area/github GitHub workflows and repo management size/XL 500+ changed lines labels Sep 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 14,188 lines across 82 files. PolyStella is maintained by a small team, so smaller focused PRs are more likely to be reviewed.

If this scope is intentional, no action is required.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Failed ❌

View logs ↗
74590e5 2026-09-29T16:23:22.389Z View logs ↗

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
polystella-docs 74590e5 Commit Preview URL

Branch Preview URL
Sep 29 2026, 04:24 PM

@pkg-pr-new

pkg-pr-new Bot commented Sep 29, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/github GitHub workflows and repo management review/needs-review No maintainer review yet size/XL 500+ changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant