@burdenoff/microfe-healthybowl 2026.924.1 → 2026.1002.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,31 +3,35 @@ import { PRODUCT as t, reportAssistantAiTokenUsage as n } from "../../services/a
3
3
  import { useWorkspaceWriteAccess as r } from "../../hooks/useWorkspaceWriteAccess.js";
4
4
  import { describeCurrentPage as i, gatherPageContext as a } from "../../utils/pageContext.js";
5
5
  import { buildPromptForMode as o } from "../../utils/assistantPrompt.js";
6
- import { jsx as s } from "react/jsx-runtime";
7
- import { AIAssistantPanel as c } from "@burdenoff/fe-libs/shared/assistant/ui/AIAssistantPanel";
8
- import { AssistantProductProvider as l } from "@burdenoff/fe-libs/shared/assistant/product";
9
- import { getActorId as u, getWorkspaceId as d } from "@burdenoff/fe-libs/shared/assistant/context";
6
+ import { LOCAL_UI_COMMANDS as s, WRITE_APPROVAL as c } from "./assistantProductOptions.js";
7
+ import { jsx as l } from "react/jsx-runtime";
8
+ import { AIAssistantPanel as u } from "@burdenoff/fe-libs/shared/assistant/ui/AIAssistantPanel";
9
+ import { AssistantProductProvider as d } from "@burdenoff/fe-libs/shared/assistant/product";
10
+ import { getActorId as f, getWorkspaceId as p } from "@burdenoff/fe-libs/shared/assistant/context";
10
11
  //#region src/components/assistant/AIAssistantPanel.tsx
11
- var f = {
12
+ var m = {
12
13
  attachments: "/HealthyBowl/AI Assistant/Attachments",
13
14
  artifacts: "/HealthyBowl/AI Assistant/Artifacts"
14
- }, p = (p) => {
15
- let m = r(u(), d() || null);
16
- return /* @__PURE__ */ s(l, {
15
+ }, h = (h) => {
16
+ let g = r(f(), p() || null);
17
+ return /* @__PURE__ */ l(d, {
17
18
  product: t,
18
19
  modes: e,
19
20
  describeCurrentPage: i,
20
21
  gatherPageContext: a,
21
22
  buildPrompt: o,
22
23
  reportTokenUsage: n,
23
- storageFolders: f,
24
- children: /* @__PURE__ */ s(c, {
25
- ...p,
26
- writeAccess: m
24
+ storageFolders: m,
25
+ localUiCommands: s,
26
+ reportTurnTimings: !0,
27
+ writeApproval: c,
28
+ children: /* @__PURE__ */ l(u, {
29
+ ...h,
30
+ writeAccess: g
27
31
  })
28
32
  });
29
33
  };
30
34
  //#endregion
31
- export { p as AIAssistantPanel };
35
+ export { h as AIAssistantPanel };
32
36
 
33
37
  //# sourceMappingURL=AIAssistantPanel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AIAssistantPanel.js","names":[],"sources":["../../../src/components/assistant/AIAssistantPanel.tsx"],"sourcesContent":["/**\n * HealthyBowl's AI assistant.\n *\n * ★★ Everything below this file is now shared. The panel, the orchestrator, the\n * transport, the voice session, the composer and every component in them live in\n * `fe-libs/shared/assistant` and answer to any product that mounts them. What is\n * left here is the four things that are genuinely HealthyBowl's, and nothing\n * else:\n *\n * modes which use cases this product offers.\n * describeCurrentPage what to CALL the page the user is on.\n * gatherPageContext the same page, as structured context for the agent.\n * buildPrompt the system preamble — that this is an agronomy\n * assistant, what it may do, and in which language.\n * reportTokenUsage the charge, against HealthyBowl's OWN mutation.\n *\n * Plus `writeAccess`, which is a PROP rather than a fifth seam field: which\n * resource types prove \"this user can write here\" is a product answer, but the\n * product can simply compute it and hand it down. A capability a product can\n * work out for itself does not belong in an interface every product must\n * satisfy.\n *\n * ★ The provider wraps from OUTSIDE the shared panel rather than sitting inside\n * its tree: the panel calls `useAssistantProduct()` and `useAssistantTr()` in its\n * own body, so a provider nested in its JSX would be below the consumer and read\n * as null — which does not throw, it silently renders English with no modes.\n */\n\nimport type { FC } from 'react';\nimport {\n AIAssistantPanel as SharedAIAssistantPanel,\n type AIAssistantPanelProps as SharedProps,\n} from '@burdenoff/fe-libs/shared/assistant/ui/AIAssistantPanel';\nimport { AssistantProductProvider } from '@burdenoff/fe-libs/shared/assistant/product';\nimport { getActorId, getWorkspaceId } from '@burdenoff/fe-libs/shared/assistant/context';\nimport { ASSISTANT_MODES } from '@/types/assistant';\nimport { PRODUCT, reportAssistantAiTokenUsage } from '@/services/assistantApi';\nimport { useWorkspaceWriteAccess } from '@/hooks/useWorkspaceWriteAccess';\nimport { describeCurrentPage, gatherPageContext } from '@/utils/pageContext';\nimport { buildPromptForMode } from '@/utils/assistantPrompt';\n\n/**\n * Where this product's assistant files already live.\n *\n * ★★ These strings are LOAD-BEARING and must not be \"tidied\". They are the real\n * folders in the workspace file library holding every attachment and artifact\n * users have saved. Changing them does not fail — it starts a second folder\n * beside the first and orphans everything in the original.\n *\n * ★ Note the capitalisation: `/HealthyBowl/…`, while the product id is\n * `healthybowl`. That mismatch is exactly why fe-libs cannot derive this and why\n * it is supplied here. The shared default (`/<product>/AI Assistant/…`) is right\n * for a product starting fresh and would be a rename for this one.\n */\nconst STORAGE_FOLDERS = {\n attachments: '/HealthyBowl/AI Assistant/Attachments',\n artifacts: '/HealthyBowl/AI Assistant/Artifacts',\n} as const;\n\nexport type AIAssistantPanelProps = Omit<SharedProps, 'writeAccess'>;\n\nexport const AIAssistantPanel: FC<AIAssistantPanelProps> = (props) => {\n /**\n * ★ Advisory, never a gate — see `useWorkspaceWriteAccess`. The `@rbac` check\n * on each mutation is the authority; this only warns before the effort instead\n * of after it. A client-side permission read can be wrong, and a wrong GATE\n * would hide Take-action from a user who is allowed to use it. (The \"no roles\n * provisioned\" reading of 2026-09-02 was one uninitialised workspace, fixed on\n * 2026-09-07 — not the platform.)\n */\n const writeAccess = useWorkspaceWriteAccess(getActorId(), getWorkspaceId() || null);\n\n return (\n <AssistantProductProvider\n product={PRODUCT}\n modes={ASSISTANT_MODES}\n describeCurrentPage={describeCurrentPage}\n gatherPageContext={gatherPageContext}\n buildPrompt={buildPromptForMode}\n reportTokenUsage={reportAssistantAiTokenUsage}\n storageFolders={STORAGE_FOLDERS}\n >\n <SharedAIAssistantPanel {...props} writeAccess={writeAccess} />\n </AssistantProductProvider>\n );\n};\n"],"mappings":";;;;;;;;;;AAsDA,IAAM,IAAkB;CACtB,aAAa;CACb,WAAW;AACb,GAIa,KAA+C,MAAU;CASpE,IAAM,IAAc,EAAwB,EAAW,GAAG,EAAe,KAAK,IAAI;CAElF,OACE,kBAAC,GAAD;EACE,SAAS;EACT,OAAO;EACc;EACF;EACnB,aAAa;EACb,kBAAkB;EAClB,gBAAgB;YAEhB,kBAAC,GAAD;GAAwB,GAAI;GAAoB;EAAc,CAAA;CACtC,CAAA;AAE9B"}
1
+ {"version":3,"file":"AIAssistantPanel.js","names":[],"sources":["../../../src/components/assistant/AIAssistantPanel.tsx"],"sourcesContent":["/**\n * HealthyBowl's AI assistant.\n *\n * ★★ Everything below this file is now shared. The panel, the orchestrator, the\n * transport, the voice session, the composer and every component in them live in\n * `fe-libs/shared/assistant` and answer to any product that mounts them. What is\n * left here is the four things that are genuinely HealthyBowl's, and nothing\n * else:\n *\n * modes which use cases this product offers.\n * describeCurrentPage what to CALL the page the user is on.\n * gatherPageContext the same page, as structured context for the agent.\n * buildPrompt the system preamble — that this is an agronomy\n * assistant, what it may do, and in which language.\n * reportTokenUsage the charge, against HealthyBowl's OWN mutation.\n * localUiCommands how \"dark mode\" / \"use the dark theme\" is read.\n * reportTurnTimings whether turns feed the latency histograms.\n * writeApproval which write flow Take action REQUESTS (BOFF-7803 5a:\n * `proposal-v1`, every change waits for its card's\n * button).\n *\n * The one question left unanswered on purpose is `confirmWrite`, so HIGH-risk\n * proposals are confirmed in fe-libs' shared `AssistantWriteConfirmDialog`.\n * HealthyBowl's own `ConfirmProvider` is a generic OK/Cancel dialog with no\n * readback, target count, consequences, arming, trusted-click check or Enter\n * guard, so it cannot meet the `confirmWrite` contract and the shared dialog is\n * the stronger one. That departs from write-approval contract §3.4 / W3.3\n * (recorded on BOFF-7803). The reasoning, and the three newer values, live in\n * `assistantProductOptions.ts`.\n *\n * Plus `writeAccess`, which is a PROP rather than a fifth seam field: which\n * resource types prove \"this user can write here\" is a product answer, but the\n * product can simply compute it and hand it down. A capability a product can\n * work out for itself does not belong in an interface every product must\n * satisfy.\n *\n * ★ The provider wraps from OUTSIDE the shared panel rather than sitting inside\n * its tree: the panel calls `useAssistantProduct()` and `useAssistantTr()` in its\n * own body, so a provider nested in its JSX would be below the consumer and read\n * as null — which does not throw, it silently renders English with no modes.\n */\n\nimport type { FC } from 'react';\nimport {\n AIAssistantPanel as SharedAIAssistantPanel,\n type AIAssistantPanelProps as SharedProps,\n} from '@burdenoff/fe-libs/shared/assistant/ui/AIAssistantPanel';\nimport { AssistantProductProvider } from '@burdenoff/fe-libs/shared/assistant/product';\nimport { getActorId, getWorkspaceId } from '@burdenoff/fe-libs/shared/assistant/context';\nimport { ASSISTANT_MODES } from '@/types/assistant';\nimport { PRODUCT, reportAssistantAiTokenUsage } from '@/services/assistantApi';\nimport { useWorkspaceWriteAccess } from '@/hooks/useWorkspaceWriteAccess';\nimport { describeCurrentPage, gatherPageContext } from '@/utils/pageContext';\nimport { buildPromptForMode } from '@/utils/assistantPrompt';\nimport { LOCAL_UI_COMMANDS, REPORT_TURN_TIMINGS, WRITE_APPROVAL } from './assistantProductOptions';\n\n/**\n * Where this product's assistant files already live.\n *\n * ★★ These strings are LOAD-BEARING and must not be \"tidied\". They are the real\n * folders in the workspace file library holding every attachment and artifact\n * users have saved. Changing them does not fail — it starts a second folder\n * beside the first and orphans everything in the original.\n *\n * ★ Note the capitalisation: `/HealthyBowl/…`, while the product id is\n * `healthybowl`. That mismatch is exactly why fe-libs cannot derive this and why\n * it is supplied here. The shared default (`/<product>/AI Assistant/…`) is right\n * for a product starting fresh and would be a rename for this one.\n */\nconst STORAGE_FOLDERS = {\n attachments: '/HealthyBowl/AI Assistant/Attachments',\n artifacts: '/HealthyBowl/AI Assistant/Artifacts',\n} as const;\n\nexport type AIAssistantPanelProps = Omit<SharedProps, 'writeAccess'>;\n\nexport const AIAssistantPanel: FC<AIAssistantPanelProps> = (props) => {\n /**\n * ★ Advisory, never a gate — see `useWorkspaceWriteAccess`. The `@rbac` check\n * on each mutation is the authority; this only warns before the effort instead\n * of after it. A client-side permission read can be wrong, and a wrong GATE\n * would hide Take-action from a user who is allowed to use it. (The \"no roles\n * provisioned\" reading of 2026-09-02 was one uninitialised workspace, fixed on\n * 2026-09-07 — not the platform.)\n */\n const writeAccess = useWorkspaceWriteAccess(getActorId(), getWorkspaceId() || null);\n\n return (\n <AssistantProductProvider\n product={PRODUCT}\n modes={ASSISTANT_MODES}\n describeCurrentPage={describeCurrentPage}\n gatherPageContext={gatherPageContext}\n buildPrompt={buildPromptForMode}\n reportTokenUsage={reportAssistantAiTokenUsage}\n storageFolders={STORAGE_FOLDERS}\n localUiCommands={LOCAL_UI_COMMANDS}\n reportTurnTimings={REPORT_TURN_TIMINGS}\n writeApproval={WRITE_APPROVAL}\n >\n <SharedAIAssistantPanel {...props} writeAccess={writeAccess} />\n </AssistantProductProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;AAqEA,IAAM,IAAkB;CACtB,aAAa;CACb,WAAW;AACb,GAIa,KAA+C,MAAU;CASpE,IAAM,IAAc,EAAwB,EAAW,GAAG,EAAe,KAAK,IAAI;CAElF,OACE,kBAAC,GAAD;EACE,SAAS;EACT,OAAO;EACc;EACF;EACnB,aAAa;EACb,kBAAkB;EAClB,gBAAgB;EAChB,iBAAiB;EACjB,mBAAA;EACA,eAAe;YAEf,kBAAC,GAAD;GAAwB,GAAI;GAAoB;EAAc,CAAA;CACtC,CAAA;AAE9B"}
@@ -0,0 +1,6 @@
1
+ //#region src/components/assistant/assistantProductOptions.ts
2
+ var e = { themeWords: "any" }, t = "proposal-v1";
3
+ //#endregion
4
+ export { e as LOCAL_UI_COMMANDS, t as WRITE_APPROVAL };
5
+
6
+ //# sourceMappingURL=assistantProductOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assistantProductOptions.js","names":[],"sources":["../../../src/components/assistant/assistantProductOptions.ts"],"sourcesContent":["/**\n * The three answers fe-libs 2026.929.1 asks every product for, beyond the ones\n * HealthyBowl already gave (BOFF-7801, BOFF-7802, BOFF-7803 5a), plus the list\n * of every answer the panel wrapper gives.\n *\n * ★ A LEAF, deliberately. Its imports are types only, so they are erased at\n * build time, and it loads nothing at run time. The wrapper that mounts the\n * provider (`AIAssistantPanel.tsx`) imports the shared panel, whose\n * react-markdown touches `document` at module scope. Tests that need these\n * VALUES, to run them through fe-libs' own readers, would then need a DOM just\n * to read three constants. So the values live here and the wrapper hands them\n * to the provider.\n */\nimport type { LocalUiCommandOptions } from '@burdenoff/fe-libs/shared/assistant/localUiCommands';\nimport type { AssistantProductCapabilities } from '@burdenoff/fe-libs/shared/assistant/product';\nimport type { WriteApprovalMode } from '@burdenoff/fe-libs/shared/assistant/writeProposals';\n\n/**\n * How the panel reads a UI command it carries out itself (BOFF-7802).\n *\n * ★★ `any`, fe-libs' default, stated rather than left implicit. fe-libs'\n * guidance: pick `mode-only` only when the product's CONTENT has themes of its\n * own (a BigConsole dashboard, a document designer), where \"use the dark theme\"\n * is about the content and must reach the model. HealthyBowl's content (farms,\n * crops, livestock, orders, the marketplace) has no theme of its own. The only\n * theme a farmer can mean is the app's, so \"use the dark theme\" and \"dark mode\"\n * both change it locally, with no turn spent on the model.\n */\nexport const LOCAL_UI_COMMANDS: LocalUiCommandOptions = { themeWords: 'any' };\n\n/**\n * Whether HealthyBowl's finished turns feed the production latency histograms\n * (BOFF-7801).\n *\n * ★ On. That is fe-libs' own default (on unless `false`) and what HealthyBowl\n * does today: the provider never set the field, so its turns have been reported\n * by default. The reports carry timings and coarse dimensions only, and the\n * proposal flow's latency is a measurement the 5a rollout needs.\n */\nexport const REPORT_TURN_TIMINGS: boolean = true;\n\n/**\n * Which write-approval flow HealthyBowl's assistant REQUESTS (BOFF-7803 5a).\n *\n * ★★★ At `proposal-v1` fe-libs provisions Ask and Take action through the\n * `assistant:use`-gated `provisionAssistantSandbox`, requests the proposal flow\n * for Take action, and lets a spoken Take-action turn through only when the\n * sandbox's own `/health` also says v1. Every change then waits for the button\n * on its card; the sandbox and wspace-sandbox-svc decide whether it runs.\n *\n * ★★ That provisioning path has NO `createSandbox` fallback: while\n * wspace-sandbox-svc cannot answer it (its session relay switched off), the\n * assistant cannot start at all. This flag reaches users only when\n * healthybowl-app pins the microfe version that carries it, so the app bump is\n * the release switch.\n *\n * ★ It decides what the panel ASKS FOR, never which UI it shows: cards, the\n * confirm dialog and the prompt's write rules all follow the issuing sandbox's\n * own `/health`.\n */\nexport const WRITE_APPROVAL: WriteApprovalMode = 'proposal-v1';\n\n/**\n * Every question the shared panel asks that HealthyBowl answers, each passed to\n * `<AssistantProductProvider>` in `AIAssistantPanel.tsx` as `field={VALUE}`.\n * `productSeam.test.ts` checks the wrapper source against this list.\n */\nexport const ANSWERED_CAPABILITIES = [\n 'modes',\n 'describeCurrentPage',\n 'gatherPageContext',\n 'buildPrompt',\n 'reportTokenUsage',\n 'storageFolders',\n 'localUiCommands',\n 'reportTurnTimings',\n 'writeApproval',\n] as const satisfies readonly (keyof AssistantProductCapabilities)[];\n\n/**\n * The one question HealthyBowl leaves to fe-libs ON PURPOSE.\n *\n * ★★ `confirmWrite`: with none, a HIGH-risk write proposal is confirmed in\n * fe-libs' shared `AssistantWriteConfirmDialog` (BOFF-7803 5a), because that is\n * the STRONGER of the two dialogs HealthyBowl could use.\n *\n * HealthyBowl does have a dialog of its own: `ConfirmProvider` / `useConfirm`\n * in `src/healthybowl/components/ConfirmDialog.tsx`, mounted in\n * `HealthyBowlRoot.tsx`. It is a generic OK/Cancel `AlertDialog` (title,\n * message, two buttons) built for delete prompts. It has no server readback,\n * no target count, no consequences, no 600 ms arming, no trusted-click check\n * and no Enter guard, so an adapter over it cannot meet the contract fe-libs\n * sets for `confirmWrite` (readback, `targetCount`, consequences, the exact\n * `confirmLabel`, payload options read-only, sensitive values masked). The\n * shared dialog meets all of it. (It is also mounted only inside\n * `HealthyBowlRoot`, while the assistant panel mounts in the app shell outside\n * it, where `useConfirm` throws.)\n *\n * This keeps the operator's 09-26 intent, \"HIGH proposals use the stronger\n * dialog\". It DEPARTS from the write-approval contract §3.4 and checklist W3.3,\n * which planned an adapter over HealthyBowl's `ConfirmProvider`; the departure\n * is recorded on BOFF-7803. Adopt `confirmWrite` only with a HealthyBowl dialog\n * that meets the whole contract, plus a contract test.\n */\nexport const LEFT_TO_FE_LIBS = ['confirmWrite'] as const satisfies readonly (keyof AssistantProductCapabilities)[];\n\n/**\n * ★★ Compile-time, enforced by `type:check`: every field of fe-libs'\n * `AssistantProductCapabilities` is either answered above or deliberately left\n * to fe-libs. Every field there is OPTIONAL, so a field fe-libs adds would\n * otherwise go unanswered with no error anywhere. It silently takes fe-libs'\n * default, which is how a product ends up on a behaviour nobody chose. When\n * this line fails, decide the new field and add it to one of the two lists.\n */\ntype Unanswered = Exclude<\n keyof AssistantProductCapabilities,\n (typeof ANSWERED_CAPABILITIES)[number] | (typeof LEFT_TO_FE_LIBS)[number]\n>;\nexport const EVERY_CAPABILITY_DECIDED: [Unanswered] extends [never] ? true : false = true;\n"],"mappings":";AA4BA,IAAa,IAA2C,EAAE,YAAY,MAAM,GAgC/D,IAAoC"}
@@ -1,40 +1,45 @@
1
+ import { PROPOSAL_WRITE_RULES as e } from "@burdenoff/fe-libs/shared/assistant/proposalWriteRules";
1
2
  //#region src/utils/assistantPrompt.ts
2
- var e = "--- User request ---", t = [
3
+ var t = "--- User request ---", n = [
3
4
  "You are in api-calls mode for HealthyBowl and can run GraphQL queries and mutations on the user's behalf.",
4
5
  "Before performing ANY write (create, update, delete — any mutation):",
5
6
  "1. State exactly what you are about to change (entity, fields, and values).",
6
7
  "2. Ask the user to confirm, and WAIT for an explicit \"yes\"/\"confirm\" before executing it.",
7
8
  "Read-only queries may run without confirmation. Confirm each write separately; never batch mutations behind a single confirmation.",
8
9
  "",
9
- e
10
- ].join("\n"), n = [
10
+ t
11
+ ].join("\n"), r = `${e("HealthyBowl")}\n\n${t}`;
12
+ function i(e) {
13
+ return e?.writeApproval === "proposal-v1" ? r : n;
14
+ }
15
+ var a = [
11
16
  "This message was DICTATED using speech recognition, so some words may be mis-heard.",
12
17
  "Errors cluster on English technical terms, product and crop names, and numbers spoken inside a sentence in another language.",
13
18
  "Read the message for INTENT rather than literally: where a word is clearly a recognition error, infer what was meant from the agricultural context instead of answering the garbled word.",
14
19
  "But do NOT guess when a mis-heard word would change what is being asked — a crop, a chemical, a quantity or a unit. Ask one short clarifying question instead. A wrong dose is far worse than an extra question."
15
- ].join("\n"), r = [
20
+ ].join("\n"), o = [
16
21
  "Your answer will be SPOKEN ALOUD and shown as a live caption, not read as a document.",
17
22
  "Write plain conversational sentences. Use NO markdown whatsoever: no #, ##, ###, no **bold**, no bullet or numbered lists, no tables, no code fences.",
18
23
  "Keep it SHORT — normally one to four sentences. The listener cannot skim, so a long answer is worse than an incomplete one.",
19
24
  "If the full answer is genuinely long, give the useful part first and offer to go deeper, rather than listing every option.",
20
25
  "Speak numbers, units and quantities the way a person says them."
21
26
  ].join("\n");
22
- function i(e, t = !1) {
27
+ function s(e, t = !1) {
23
28
  return [
24
29
  `Answer in ${e}.`,
25
30
  t ? `The user has chosen ${e} deliberately: answer in it even when their message is written in another language.` : "If the user writes in a different language, answer in THAT language instead — what they wrote in always wins.",
26
31
  "Your documentation and tool output are in English: translate what you quote from them rather than switching language."
27
32
  ].join("\n");
28
33
  }
29
- function a(a, o, s, c = !1, l = !1) {
30
- let u = [
31
- s ? i(s, c) : "",
32
- l ? n : "",
33
- l ? r : ""
34
- ].filter(Boolean).join("\n\n"), d = u ? `${u}\n\n` : "";
35
- return a === "api-calls" ? `${d}${t}\n${o}` : d ? `${d}${e}\n${o}` : o;
34
+ function c(e, n, r, c = !1, l = !1, u) {
35
+ let d = [
36
+ r ? s(r, c) : "",
37
+ l ? a : "",
38
+ l ? o : ""
39
+ ].filter(Boolean).join("\n\n"), f = d ? `${d}\n\n` : "";
40
+ return e === "api-calls" ? `${f}${i(u)}\n${n}` : f ? `${f}${t}\n${n}` : n;
36
41
  }
37
42
  //#endregion
38
- export { a as buildPromptForMode };
43
+ export { c as buildPromptForMode };
39
44
 
40
45
  //# sourceMappingURL=assistantPrompt.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"assistantPrompt.js","names":[],"sources":["../../src/utils/assistantPrompt.ts"],"sourcesContent":["/**\n * Soft confirm-before-mutate guardrail for the assistant's api-calls (write)\n * mode: a describe-and-confirm instruction prepended to the user's TURN (not the\n * session system prompt, which would clobber the agent's api-calls behaviour).\n * This is ADVISORY — the model is asked, not made. What holds a write is the\n * sandbox: since 2026-09-07 it refuses the mutation and keeps it pending until\n * the user presses Approve on the pending-write card, behind the admin gate and\n * the consent dialog. This text shapes what the model says before that card\n * appears. Only the agent receives the prepended text — the user-facing message\n * bubble keeps the raw content.\n */\n\nimport type { AssistantMode } from '@/types/assistant';\n\n/**\n * Marks where our instructions stop and the user's words begin. Exactly one may\n * exist in a prompt, and it must be last — see `buildPromptForMode`.\n */\nexport const USER_REQUEST_DELIMITER = '--- User request ---';\n\nexport const API_CALLS_CONFIRM_PREAMBLE = [\n \"You are in api-calls mode for HealthyBowl and can run GraphQL queries and mutations on the user's behalf.\",\n 'Before performing ANY write (create, update, delete — any mutation):',\n '1. State exactly what you are about to change (entity, fields, and values).',\n '2. Ask the user to confirm, and WAIT for an explicit \"yes\"/\"confirm\" before executing it.',\n 'Read-only queries may run without confirmation. Confirm each write separately; never batch mutations behind a single confirmation.',\n '',\n USER_REQUEST_DELIMITER,\n].join('\\n');\n\n/**\n * Ask for the reply in the user's language (BOFF-7107).\n *\n * Nothing else does. The sandbox system prompt carries no language instruction,\n * the grounding documentation is entirely in English, and the persona insists on\n * grounding in it — so every force in the session pushes the answer towards\n * English regardless of what the user wrote. The model's tendency to mirror the\n * input is the only thing resisting that, and it is being outvoted.\n *\n * Three deliberate choices:\n *\n * - **The user's own language wins over the UI language.** The chrome being in\n * English says nothing about the person typing Tamil into it; treating the\n * locale as an instruction rather than a default would be the actual bug.\n * - **Translate the docs, do not switch to their language.** This is the clause\n * that matters. Without it a grounded answer drifts back to English mid-reply\n * simply because the source material is English.\n * - **Prepended per TURN, not sent as `system`.** The transport's `system` field\n * REPLACES the whole mode prompt, which would silently delete the docs and\n * api-calls instructions along with it.\n */\n/**\n * The instruction lines only — deliberately WITHOUT the delimiter.\n *\n * The delimiter marks where our instructions stop and the user's words begin, so\n * exactly one may exist and it must be last. Emitting it here too put a second\n * one mid-prompt, which left the api-calls safety instructions sitting *after* a\n * \"User request\" marker — i.e. presented to the model as though the user had\n * written them. `buildPromptForMode` owns placing it, once.\n */\n/**\n * Told to the model when the turn was SPOKEN rather than typed.\n *\n * Speech recognition does not fail uniformly — it fails on specific words, and\n * the ones it fails on here are predictable: English technical terms, product\n * and crop names, and numbers spoken inside an Indic sentence. A recogniser set\n * to `ta-IN` has no good model for \"urea\", \"pH\" or \"NPK\", so a Tamil sentence\n * comes back mostly right with a few words wrong. That is exactly the report:\n * \"some word some times\".\n *\n * The model is far better placed to repair that than the recogniser is, because\n * it has the farming context — but only if it is TOLD the text was dictated.\n * Otherwise it answers the garbled word literally, which is what makes the\n * assistant look like it misunderstood.\n *\n * ★ The refusal to guess is the important half. Charitable interpretation is\n * right for a mangled verb and dangerous for a mangled QUANTITY: this is\n * agriculture, and a dose or a unit that the recogniser mis-heard must be asked\n * about, not inferred. One extra question costs a few seconds; a wrong dose\n * costs a crop.\n */\nconst DICTATION_PREAMBLE = [\n 'This message was DICTATED using speech recognition, so some words may be mis-heard.',\n 'Errors cluster on English technical terms, product and crop names, and numbers spoken inside a sentence in another language.',\n 'Read the message for INTENT rather than literally: where a word is clearly a recognition error, infer what was meant from the agricultural context instead of answering the garbled word.',\n 'But do NOT guess when a mis-heard word would change what is being asked — a crop, a chemical, a quantity or a unit. Ask one short clarifying question instead. A wrong dose is far worse than an extra question.',\n].join('\\n');\n\n/**\n * Told to the model when its answer will be SPOKEN ALOUD, not read.\n *\n * The assistant was never told this, so it replied the way it replies in chat:\n * documentation-style markdown with `##` headings, `**bold**` and long\n * enumerated sections. In the chat panel that renders correctly. In the voice\n * panel it is read aloud AND shown as a caption, where the syntax is literal\n * and the length is unusable — the operator screenshotted a live session whose\n * caption was a wall of \"### **Budget Planning Features:**\".\n *\n * ★ This is the fix at SOURCE. Stripping markdown at render time is a\n * necessary backstop, but it cannot shorten a 500-word answer that was never\n * meant to be listened to. A spoken reply has to be short because the listener\n * cannot skim it.\n */\nconst VOICE_REPLY_PREAMBLE = [\n 'Your answer will be SPOKEN ALOUD and shown as a live caption, not read as a document.',\n 'Write plain conversational sentences. Use NO markdown whatsoever: no #, ##, ###, no **bold**, no bullet or numbered lists, no tables, no code fences.',\n 'Keep it SHORT — normally one to four sentences. The listener cannot skim, so a long answer is worse than an incomplete one.',\n 'If the full answer is genuinely long, give the useful part first and offer to go deeper, rather than listing every option.',\n 'Speak numbers, units and quantities the way a person says them.',\n].join('\\n');\n\nexport function buildLanguagePreamble(languageName: string, isExplicitChoice = false): string {\n return [\n `Answer in ${languageName}.`,\n // The mirror clause is right for a DEFAULT and wrong for a CHOICE.\n //\n // Derived from the interface language it is only a guess, and the language\n // the user actually wrote in is better evidence. But once they have picked a\n // language deliberately, \"what they wrote in wins\" silently overrides them —\n // and it does so hardest for people who TYPE, since a typed English question\n // would come back in English no matter what they selected. That makes the\n // preference inert for exactly the users who cannot dictate.\n isExplicitChoice\n ? `The user has chosen ${languageName} deliberately: answer in it even when their message is written in another language.`\n : 'If the user writes in a different language, answer in THAT language instead — what they wrote in always wins.',\n 'Your documentation and tool output are in English: translate what you quote from them rather than switching language.',\n ].join('\\n');\n}\n\n/**\n * `languageName` is the human name of the user's language (\"Tamil\"), not a code:\n * a code invites the model to answer *about* the tag instead of *in* it.\n * Omitted (or empty) leaves the prompt untouched, so a caller without locale\n * context behaves exactly as before.\n *\n * Order is load-bearing: instructions, then the delimiter, then the user's text.\n * The language preamble goes FIRST so the api-calls preamble keeps its own\n * delimiter adjacent to the content it introduces.\n */\nexport function buildPromptForMode(\n mode: AssistantMode,\n content: string,\n languageName?: string,\n isExplicitChoice = false,\n dictated = false\n): string {\n // Dictation goes AFTER the language lines and before the delimiter: it is an\n // instruction about the user's text, so it belongs with the instructions, not\n // inside them. Defaults to false, so every typed turn is byte-identical to\n // before — the composer's own dictation is excluded deliberately, because the\n // user can read and edit that text before sending it.\n const preamble = [\n languageName ? buildLanguagePreamble(languageName, isExplicitChoice) : '',\n dictated ? DICTATION_PREAMBLE : '',\n // A dictated turn is a SPOKEN conversation, so the reply is spoken too.\n dictated ? VOICE_REPLY_PREAMBLE : '',\n ]\n .filter(Boolean)\n .join('\\n\\n');\n const language = preamble ? `${preamble}\\n\\n` : '';\n if (mode === 'api-calls') return `${language}${API_CALLS_CONFIRM_PREAMBLE}\\n${content}`;\n return language ? `${language}${USER_REQUEST_DELIMITER}\\n${content}` : content;\n}\n"],"mappings":";AAkBA,IAAa,IAAyB,wBAEzB,IAA6B;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,EAAE,KAAK,IAAI,GAqDL,IAAqB;CACzB;CACA;CACA;CACA;AACF,EAAE,KAAK,IAAI,GAiBL,IAAuB;CAC3B;CACA;CACA;CACA;CACA;AACF,EAAE,KAAK,IAAI;AAEX,SAAgB,EAAsB,GAAsB,IAAmB,IAAe;CAC5F,OAAO;EACL,aAAa,EAAa;EAS1B,IACI,uBAAuB,EAAa,uFACpC;EACJ;CACF,EAAE,KAAK,IAAI;AACb;AAYA,SAAgB,EACd,GACA,GACA,GACA,IAAmB,IACnB,IAAW,IACH;CAMR,IAAM,IAAW;EACf,IAAe,EAAsB,GAAc,CAAgB,IAAI;EACvE,IAAW,IAAqB;EAEhC,IAAW,IAAuB;CACpC,EACG,OAAO,OAAO,EACd,KAAK,MAAM,GACR,IAAW,IAAW,GAAG,EAAS,QAAQ;CAEhD,OADI,MAAS,cAAoB,GAAG,IAAW,EAA2B,IAAI,MACvE,IAAW,GAAG,IAAW,EAAuB,IAAI,MAAY;AACzE"}
1
+ {"version":3,"file":"assistantPrompt.js","names":[],"sources":["../../src/utils/assistantPrompt.ts"],"sourcesContent":["/**\n * The write rules for the assistant's api-calls (\"Take action\") mode, prepended\n * to the user's TURN (not the session system prompt, which would clobber the\n * agent's api-calls behaviour). Only the agent receives the prepended text; the\n * user-facing message bubble keeps the raw content.\n *\n * Which rules a turn gets depends on what the sandbox it goes to ENFORCES, which\n * fe-libs passes as `buildPrompt`'s sixth argument from that sandbox's own\n * `/health` (BOFF-7803 5a):\n *\n * - `legacy`: a describe-and-confirm instruction. ADVISORY: the model is asked,\n * not made. What holds a write is the sandbox: since 2026-09-07 it refuses the\n * mutation and keeps it pending until the user presses Approve on the\n * pending-write card, behind the consent dialog. This text shapes what the\n * model says before that card appears. Unchanged by 5a, byte for byte.\n * - `proposal-v1`: the helper only PROPOSES a mutation, and only the button on\n * its card confirms it. Asking for a typed \"yes\" there would contradict the\n * sandbox, so the turn carries fe-libs' `PROPOSAL_WRITE_RULES` instead.\n */\n\nimport type { AssistantPromptOptions } from '@burdenoff/fe-libs/shared/assistant/product';\nimport { PROPOSAL_WRITE_RULES } from '@burdenoff/fe-libs/shared/assistant/proposalWriteRules';\nimport type { AssistantMode } from '@/types/assistant';\n\n/**\n * Marks where our instructions stop and the user's words begin. Exactly one may\n * exist in a prompt, and it must be last — see `buildPromptForMode`.\n */\nexport const USER_REQUEST_DELIMITER = '--- User request ---';\n\n/**\n * The write rules for a Take-action turn to a LEGACY sandbox, which runs a\n * mutation itself once the pending-write card is approved. Unchanged by\n * BOFF-7803 5a, byte for byte.\n */\nexport const API_CALLS_CONFIRM_PREAMBLE = [\n \"You are in api-calls mode for HealthyBowl and can run GraphQL queries and mutations on the user's behalf.\",\n 'Before performing ANY write (create, update, delete — any mutation):',\n '1. State exactly what you are about to change (entity, fields, and values).',\n '2. Ask the user to confirm, and WAIT for an explicit \"yes\"/\"confirm\" before executing it.',\n 'Read-only queries may run without confirmation. Confirm each write separately; never batch mutations behind a single confirmation.',\n '',\n USER_REQUEST_DELIMITER,\n].join('\\n');\n\n/**\n * The write rules for a Take-action turn to a PROPOSAL-V1 sandbox (BOFF-7803\n * 5a), composed exactly as fe-libs documents it: the shared rules, a blank line,\n * then this product's own delimiter.\n *\n * ★★ The rules are fe-libs' `PROPOSAL_WRITE_RULES`, not a HealthyBowl rewrite.\n * They are kept consistent with the sandbox's own proposal policy, so a local\n * copy would be a second text to keep in step with it. They carry no delimiter\n * of their own, so this one is the only one, and it is last, as after the\n * legacy preamble.\n */\nexport const API_CALLS_PROPOSAL_PREAMBLE = `${PROPOSAL_WRITE_RULES('HealthyBowl')}\\n\\n${USER_REQUEST_DELIMITER}`;\n\n/**\n * The write preamble for a Take-action turn, by what the receiving sandbox\n * enforces. Only exactly `proposal-v1` selects the proposal rules; anything\n * else, or no options at all, keeps the legacy text, which is what fe-libs sends\n * for a sandbox that has not reported the v1 protocol.\n */\nfunction writePreambleFor(options: AssistantPromptOptions | undefined): string {\n return options?.writeApproval === 'proposal-v1' ? API_CALLS_PROPOSAL_PREAMBLE : API_CALLS_CONFIRM_PREAMBLE;\n}\n\n/**\n * Ask for the reply in the user's language (BOFF-7107).\n *\n * Nothing else does. The sandbox system prompt carries no language instruction,\n * the grounding documentation is entirely in English, and the persona insists on\n * grounding in it — so every force in the session pushes the answer towards\n * English regardless of what the user wrote. The model's tendency to mirror the\n * input is the only thing resisting that, and it is being outvoted.\n *\n * Three deliberate choices:\n *\n * - **The user's own language wins over the UI language.** The chrome being in\n * English says nothing about the person typing Tamil into it; treating the\n * locale as an instruction rather than a default would be the actual bug.\n * - **Translate the docs, do not switch to their language.** This is the clause\n * that matters. Without it a grounded answer drifts back to English mid-reply\n * simply because the source material is English.\n * - **Prepended per TURN, not sent as `system`.** The transport's `system` field\n * REPLACES the whole mode prompt, which would silently delete the docs and\n * api-calls instructions along with it.\n */\n/**\n * The instruction lines only — deliberately WITHOUT the delimiter.\n *\n * The delimiter marks where our instructions stop and the user's words begin, so\n * exactly one may exist and it must be last. Emitting it here too put a second\n * one mid-prompt, which left the api-calls safety instructions sitting *after* a\n * \"User request\" marker — i.e. presented to the model as though the user had\n * written them. `buildPromptForMode` owns placing it, once.\n */\n/**\n * Told to the model when the turn was SPOKEN rather than typed.\n *\n * Speech recognition does not fail uniformly — it fails on specific words, and\n * the ones it fails on here are predictable: English technical terms, product\n * and crop names, and numbers spoken inside an Indic sentence. A recogniser set\n * to `ta-IN` has no good model for \"urea\", \"pH\" or \"NPK\", so a Tamil sentence\n * comes back mostly right with a few words wrong. That is exactly the report:\n * \"some word some times\".\n *\n * The model is far better placed to repair that than the recogniser is, because\n * it has the farming context — but only if it is TOLD the text was dictated.\n * Otherwise it answers the garbled word literally, which is what makes the\n * assistant look like it misunderstood.\n *\n * ★ The refusal to guess is the important half. Charitable interpretation is\n * right for a mangled verb and dangerous for a mangled QUANTITY: this is\n * agriculture, and a dose or a unit that the recogniser mis-heard must be asked\n * about, not inferred. One extra question costs a few seconds; a wrong dose\n * costs a crop.\n */\nconst DICTATION_PREAMBLE = [\n 'This message was DICTATED using speech recognition, so some words may be mis-heard.',\n 'Errors cluster on English technical terms, product and crop names, and numbers spoken inside a sentence in another language.',\n 'Read the message for INTENT rather than literally: where a word is clearly a recognition error, infer what was meant from the agricultural context instead of answering the garbled word.',\n 'But do NOT guess when a mis-heard word would change what is being asked — a crop, a chemical, a quantity or a unit. Ask one short clarifying question instead. A wrong dose is far worse than an extra question.',\n].join('\\n');\n\n/**\n * Told to the model when its answer will be SPOKEN ALOUD, not read.\n *\n * The assistant was never told this, so it replied the way it replies in chat:\n * documentation-style markdown with `##` headings, `**bold**` and long\n * enumerated sections. In the chat panel that renders correctly. In the voice\n * panel it is read aloud AND shown as a caption, where the syntax is literal\n * and the length is unusable — the operator screenshotted a live session whose\n * caption was a wall of \"### **Budget Planning Features:**\".\n *\n * ★ This is the fix at SOURCE. Stripping markdown at render time is a\n * necessary backstop, but it cannot shorten a 500-word answer that was never\n * meant to be listened to. A spoken reply has to be short because the listener\n * cannot skim it.\n */\nconst VOICE_REPLY_PREAMBLE = [\n 'Your answer will be SPOKEN ALOUD and shown as a live caption, not read as a document.',\n 'Write plain conversational sentences. Use NO markdown whatsoever: no #, ##, ###, no **bold**, no bullet or numbered lists, no tables, no code fences.',\n 'Keep it SHORT — normally one to four sentences. The listener cannot skim, so a long answer is worse than an incomplete one.',\n 'If the full answer is genuinely long, give the useful part first and offer to go deeper, rather than listing every option.',\n 'Speak numbers, units and quantities the way a person says them.',\n].join('\\n');\n\nexport function buildLanguagePreamble(languageName: string, isExplicitChoice = false): string {\n return [\n `Answer in ${languageName}.`,\n // The mirror clause is right for a DEFAULT and wrong for a CHOICE.\n //\n // Derived from the interface language it is only a guess, and the language\n // the user actually wrote in is better evidence. But once they have picked a\n // language deliberately, \"what they wrote in wins\" silently overrides them —\n // and it does so hardest for people who TYPE, since a typed English question\n // would come back in English no matter what they selected. That makes the\n // preference inert for exactly the users who cannot dictate.\n isExplicitChoice\n ? `The user has chosen ${languageName} deliberately: answer in it even when their message is written in another language.`\n : 'If the user writes in a different language, answer in THAT language instead — what they wrote in always wins.',\n 'Your documentation and tool output are in English: translate what you quote from them rather than switching language.',\n ].join('\\n');\n}\n\n/**\n * `languageName` is the human name of the user's language (\"Tamil\"), not a code:\n * a code invites the model to answer *about* the tag instead of *in* it.\n * Omitted (or empty) leaves the prompt untouched, so a caller without locale\n * context behaves exactly as before.\n *\n * Order is load-bearing: instructions, then the delimiter, then the user's text.\n * The language preamble goes FIRST so the api-calls preamble keeps its own\n * delimiter adjacent to the content it introduces. Both api-calls preambles end\n * with that delimiter, so it is never added a second time.\n *\n * ★★ `options` is fe-libs' sixth argument (BOFF-7803 5a): what the sandbox this\n * turn goes to enforces, from its own `/health`, never this product's\n * `writeApproval` flag, which only says what HealthyBowl ASKS for. A\n * proposal-v1 sandbox gets the proposal rules; every other turn is composed\n * exactly as before.\n *\n * ★ A dictated Take-action turn exists only against a proposal-v1 sandbox:\n * fe-libs refuses a spoken send in a write-capable mode unless the turn is\n * proposal-bound (this product asks for `proposal-v1` AND the sandbox's own\n * `/health` says v1). So dictation and the legacy \"wait for yes\" text never\n * meet; dictation and the proposal rules can.\n */\nexport function buildPromptForMode(\n mode: AssistantMode,\n content: string,\n languageName?: string,\n isExplicitChoice = false,\n dictated = false,\n options?: AssistantPromptOptions\n): string {\n // Dictation goes AFTER the language lines and before the delimiter: it is an\n // instruction about the user's text, so it belongs with the instructions, not\n // inside them. Defaults to false, so every typed turn is byte-identical to\n // before — the composer's own dictation is excluded deliberately, because the\n // user can read and edit that text before sending it.\n const preamble = [\n languageName ? buildLanguagePreamble(languageName, isExplicitChoice) : '',\n dictated ? DICTATION_PREAMBLE : '',\n // A dictated turn is a SPOKEN conversation, so the reply is spoken too.\n dictated ? VOICE_REPLY_PREAMBLE : '',\n ]\n .filter(Boolean)\n .join('\\n\\n');\n const language = preamble ? `${preamble}\\n\\n` : '';\n if (mode === 'api-calls') return `${language}${writePreambleFor(options)}\\n${content}`;\n return language ? `${language}${USER_REQUEST_DELIMITER}\\n${content}` : content;\n}\n"],"mappings":";;AA4BA,IAAa,IAAyB,wBAOzB,IAA6B;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,EAAE,KAAK,IAAI,GAaE,IAA8B,GAAG,EAAqB,aAAa,EAAE,MAAM;AAQxF,SAAS,EAAiB,GAAqD;CAC7E,OAAO,GAAS,kBAAkB,gBAAgB,IAA8B;AAClF;AAqDA,IAAM,IAAqB;CACzB;CACA;CACA;CACA;AACF,EAAE,KAAK,IAAI,GAiBL,IAAuB;CAC3B;CACA;CACA;CACA;CACA;AACF,EAAE,KAAK,IAAI;AAEX,SAAgB,EAAsB,GAAsB,IAAmB,IAAe;CAC5F,OAAO;EACL,aAAa,EAAa;EAS1B,IACI,uBAAuB,EAAa,uFACpC;EACJ;CACF,EAAE,KAAK,IAAI;AACb;AAyBA,SAAgB,EACd,GACA,GACA,GACA,IAAmB,IACnB,IAAW,IACX,GACQ;CAMR,IAAM,IAAW;EACf,IAAe,EAAsB,GAAc,CAAgB,IAAI;EACvE,IAAW,IAAqB;EAEhC,IAAW,IAAuB;CACpC,EACG,OAAO,OAAO,EACd,KAAK,MAAM,GACR,IAAW,IAAW,GAAG,EAAS,QAAQ;CAEhD,OADI,MAAS,cAAoB,GAAG,IAAW,EAAiB,CAAO,EAAE,IAAI,MACtE,IAAW,GAAG,IAAW,EAAuB,IAAI,MAAY;AACzE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/microfe-healthybowl",
3
- "version": "2026.924.1",
3
+ "version": "2026.1002.1",
4
4
  "description": "Burdenoff HealthyBowl Microfrontend - Comprehensive organic farming and agro-foods management platform",
5
5
  "type": "module",
6
6
  "files": [
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@apollo/client": "^4.0.11",
51
- "@burdenoff/fe-libs": "2026.917.2",
51
+ "@burdenoff/fe-libs": "2026.1002.1",
52
52
  "@burdenoff/planmagnet-fe-sdk": "2026.831.1",
53
53
  "@tanstack/react-query": "^5.90.16",
54
54
  "clsx": "^2.1.1",