Skip to content

refactor: split the extractor into contracts, ai and quotation workspaces - #1

Merged
aidev1-technext merged 7 commits into
mainfrom
chore/restructure-layout
Sep 30, 2026
Merged

aidev1-technext merged 7 commits into
mainfrom
chore/restructure-layout

Conversation

@aidev1-technext

Copy link
Copy Markdown
Collaborator

What changed

The repo is reorganised into four workspaces with one dependency direction:

contracts  <-  ai  <-  quotation  <-  bff
Workspace Contents
contracts/ Bff* schemas, GuestType, TransportType, vendored upstream spec (bff-contract/)
ai/ (was packages/extractor) message → Trip + reply only: extract, questions, synthesis, converse, providers, eval. No pricing, no Odoo.
quotation/ pricing, rates, quotation draft, validity window, odooHandoff, inquiryLead, tripDiff, converseWithQuotation
bff/ (was apps/casa-bff) Hono app, logic unchanged
tools/ old scripts/, split into ops/, live-eval/, site/

Why

ai/ is being moved into tn-casa-quotation-estimator, whose rule for ai/ is: no Odoo client, no pricing, no submit, types only from contracts. Before this change ai/ owned pricing, rates and the Odoo handoff, and converse() built a priced draft.

Design notes

  • converse() no longer builds the draft. quotation's converseWithQuotation() adds it behind the same ENABLE_HONO_QUOTATION_TOOL switch, and bff calls that. Behaviour is unchanged.
  • Two dependency cycles are removed. synthesis ↔ converse is broken by moving ConversationTurn to ai/src/domain/conversation.ts. domain/quotationValidity → application/quotationTool is broken by moving the draft types to quotation/src/domain/quotationDraft.ts.
  • Cross-package imports go only through <pkg>/src/index.ts. They stay relative rather than @casa/*, because the workspace symlink did not resolve in the Vercel bundle (see the note at the top of bff/src/app.ts).
  • New npm run check:boundaries (tools/ops/check-boundaries.mjs) runs in verify and therefore in CI. It rejects a wrong-direction import and a deep import into another package; both were checked by adding a violation on purpose.
  • .agents/ (36 MB of third-party skills) is no longer tracked and is now git-ignored.

Bugs found on the way

  • The scripts in scripts/ imported files that no longer existed (src/converse.js, src/providerFromEnv.js). They now point at the ai barrel.
  • bff/src/dev.ts read ../../.env.local, a path from the old apps/casa-bff depth.
  • Without a vitest.config, vitest searched parent directories and loaded a stray E:\vite.config.ts. contracts/ now has its own config.

Also in this branch

It also contains 4 earlier commits from another session: the Anthropic provider, the settings-driven provider with a circuit breaker, the /admin/ai dashboard, and the /admin route in vercel.json. The restructure commit edits their files, so they cannot be split out cleanly. Review them as their own commits: 9d4e9e9, 866122b, 5e859dd, dada2df.

How it was tested

  • npm run verify passes: boundaries ok, typecheck ok in all 4 workspaces, 939 tests pass (contracts 3 new, ai 308, quotation 120, bff 508).
  • No test lost: ai 308 + quotation 120 = 428, the count the old ai/ suite ran at dada2df. The handoff tests from questions.test.ts moved to quotation/test/handoffEnvelope.test.ts.
  • Dev server runs: /healthz, / and /status return 200, and /v1/extract returns a real Trip. api/index.ts loads and exports GET/POST/PUT.
  • Not verified: a Vercel preview deployment. Please check the preview before merging.
  • The dev server log showed the DeepSeek gateway returning 404 ("Application not found") and falling back to Gemini. That is an env configuration issue, not caused by this change.

Not in this PR

  • Heavy media in public/ (31 MB of mp4/png).
  • The outdated diagram docs/diagrams/repo-structure.*.
  • Porting to tn-casa-quotation-estimator, including reconciling contracts/ with their official trip.zod.ts.

🤖 Generated with Claude Code

aidev1-technext and others added 6 commits September 30, 2026 13:13
…ack .agents/

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…-level circuit breaker, answering-provider in meta

- providers take timeouts/base URL as options (no more module-level constants)
- createProviderFromSettings + createResilientProvider (stats callback, answeredBy)
- one table of default models; meta.provider names the provider that answered
- docs: decisions list for Anthony

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…crypted keys, health, audit

- admin role (ADMIN_ACCESS_KEY, from the key typed, never a form field); staff cannot open /admin
- settings in KV over the environment; 30s cache cleared on write; process-level provider with its breaker
- provider/apiKey overrides on /v1/extract and /v1/converse now need a staff session; /test no longer takes a key
- shared KV client; per-provider counters; audit of the last 50 changes (no keys)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…aces

The AI package now stops at "guest message in, Trip and reply out". Pricing,
rates, the quotation draft, its validity window and the Odoo handoff moved to
quotation/, and the BFF schema we mirror from upstream moved to contracts/.
One dependency direction: contracts <- ai <- quotation <- bff.

- ai/: converse() no longer builds a quotation draft; quotation's
  converseWithQuotation() adds it behind the same ENABLE_HONO_QUOTATION_TOOL
  switch, and bff calls that. ConversationTurn moved to domain/conversation.ts
  to break the synthesis <-> converse cycle.
- quotation/: draft types split into domain/quotationDraft.ts so
  domain/quotationValidity.ts no longer imports application code.
- Cross-package imports go through each package's src/index.ts; they stay
  relative because the workspace symlink did not resolve on Vercel.
- tools/ops/check-boundaries.mjs enforces both rules and runs in verify/CI.
- scripts/ moved to tools/{ops,live-eval,site}; their broken imports of
  files that no longer existed now point at the ai barrel.
- bff/src/dev.ts read ../../.env.local, a path from the old apps/ depth.

Tests: 939 pass (contracts 3 new, ai 308, quotation 120, bff 508); the 428
ai + quotation tests equal the 428 the old ai/ suite ran. Handoff tests in
questions.test.ts moved to quotation/test/handoffEnvelope.test.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
technext-edge-casa-bff Ready Ready Preview Sep 30, 2026 7:27am UTC

Comment thread ai/src/infra/providers/deepseek.ts Fixed
Comment thread bff/test/adminAi.test.ts Fixed
…egex

CodeQL flagged `.replace(/\/+$/, "")` on the DeepSeek base URL, which is now
admin-settings input: on a long run of '/' not at the end it backtracks
polynomially (measured: 4.5 s for 100k slashes). A loop does the same trim
in linear time. The admin page test's <script> regex is now case-insensitive
and accepts `</script >`, per CodeQL's bad-HTML-filtering alert.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aidev1-technext
aidev1-technext merged commit 619007f into main Sep 30, 2026
5 of 7 checks passed
@aidev1-technext
aidev1-technext deleted the chore/restructure-layout branch September 30, 2026 08:04

This branch was successfully deployed

1 active deployment
Preview — b67869ef Deployed Sep 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants