@case-framework/survey-assistant 0.8.0 → 0.9.0

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.
Files changed (114) hide show
  1. package/dist/{authoring-references-DbuOKerg.mjs → authoring-references-CmwLc_C8.mjs} +40 -32
  2. package/dist/authoring-references-CmwLc_C8.mjs.map +1 -0
  3. package/dist/capabilities-D55dq-fO.mjs +582 -0
  4. package/dist/capabilities-D55dq-fO.mjs.map +1 -0
  5. package/dist/capabilities-default.d.mts +4 -12
  6. package/dist/capabilities-default.d.mts.map +1 -1
  7. package/dist/capabilities-default.mjs +2 -2
  8. package/dist/capabilities-z95e1mti.d.mts +117 -0
  9. package/dist/capabilities-z95e1mti.d.mts.map +1 -0
  10. package/dist/{constants-B6HzpEsx.d.mts → constants-HL_klgJl.d.mts} +4 -4
  11. package/dist/{constants-B6HzpEsx.d.mts.map → constants-HL_klgJl.d.mts.map} +1 -1
  12. package/dist/{controller-proxy-DEeFl9IA.mjs → controller-proxy-BQ1YsVxJ.mjs} +4 -3
  13. package/dist/controller-proxy-BQ1YsVxJ.mjs.map +1 -0
  14. package/dist/{controller-proxy-D7uQfm5f.d.mts → controller-proxy-Cmzdr9tV.d.mts} +4 -4
  15. package/dist/{controller-proxy-D7uQfm5f.d.mts.map → controller-proxy-Cmzdr9tV.d.mts.map} +1 -1
  16. package/dist/default-D22AKTqE.mjs +233 -0
  17. package/dist/default-D22AKTqE.mjs.map +1 -0
  18. package/dist/{digest-C39WyAWG.d.mts → digest-FnTTDBq2.d.mts} +2 -2
  19. package/dist/digest-FnTTDBq2.d.mts.map +1 -0
  20. package/dist/digest.d.mts +1 -1
  21. package/dist/engine-D950TfvC.mjs +3098 -0
  22. package/dist/engine-D950TfvC.mjs.map +1 -0
  23. package/dist/engine.d.mts +4 -3
  24. package/dist/engine.mjs +3 -3
  25. package/dist/{index-WB5kfnz0.d.mts → index-B8TLBd1G.d.mts} +8 -6
  26. package/dist/index-B8TLBd1G.d.mts.map +1 -0
  27. package/dist/index-CaX3hZmr.d.mts +23813 -0
  28. package/dist/index-CaX3hZmr.d.mts.map +1 -0
  29. package/dist/{index-r5riv4md.d.mts → index-CeUlGkoU.d.mts} +27 -6
  30. package/dist/index-CeUlGkoU.d.mts.map +1 -0
  31. package/dist/{index-D7wT6P3t.d.mts → index-DYHdvSE8.d.mts} +83 -41
  32. package/dist/index-DYHdvSE8.d.mts.map +1 -0
  33. package/dist/lifecycle-DFzxVxpq.d.mts +54346 -0
  34. package/dist/lifecycle-DFzxVxpq.d.mts.map +1 -0
  35. package/dist/{memory-thread-repository-DAnOGIB3.mjs → memory-thread-repository-DmLadygY.mjs} +15 -9
  36. package/dist/{memory-thread-repository-DAnOGIB3.mjs.map → memory-thread-repository-DmLadygY.mjs.map} +1 -1
  37. package/dist/protocol-BQ7uIDYT.mjs +569 -0
  38. package/dist/protocol-BQ7uIDYT.mjs.map +1 -0
  39. package/dist/protocol.d.mts +4 -4
  40. package/dist/protocol.mjs +3 -2
  41. package/dist/{react-C_GY-Fsc.mjs → react-DybJ5pWw.mjs} +17 -11
  42. package/dist/react-DybJ5pWw.mjs.map +1 -0
  43. package/dist/react-integration.d.mts +1 -1
  44. package/dist/react-integration.mjs +1 -1
  45. package/dist/react.d.mts +2 -2
  46. package/dist/react.mjs +2 -2
  47. package/dist/references/assistant-operations.md +190 -215
  48. package/dist/references/core-rules.md +2 -2
  49. package/dist/references/element-types.md +189 -0
  50. package/dist/references/expressions.md +215 -238
  51. package/dist/references/follow-ups.md +151 -0
  52. package/dist/references/localization.md +26 -12
  53. package/dist/references/response-variables.md +3 -3
  54. package/dist/references/rich-text-content.md +22 -43
  55. package/dist/references/source-material-surveys.md +20 -25
  56. package/dist/references/survey-data-model.md +36 -117
  57. package/dist/{request-context-Dg4jSwN1.mjs → request-context-KVh8VjgH.mjs} +4 -4
  58. package/dist/request-context-KVh8VjgH.mjs.map +1 -0
  59. package/dist/server-agent.d.mts +28 -7
  60. package/dist/server-agent.d.mts.map +1 -1
  61. package/dist/server-agent.mjs +33 -25
  62. package/dist/server-agent.mjs.map +1 -1
  63. package/dist/server-runtime.d.mts +6 -5
  64. package/dist/server-runtime.d.mts.map +1 -1
  65. package/dist/server-runtime.mjs +3 -3
  66. package/dist/server-tasks.d.mts +1 -1
  67. package/dist/server-tasks.mjs +1 -1
  68. package/dist/server-tools.d.mts +1 -1
  69. package/dist/server-tools.mjs +1 -1
  70. package/dist/server.d.mts +7 -6
  71. package/dist/server.d.mts.map +1 -1
  72. package/dist/server.mjs +3 -3
  73. package/dist/{tasks-BZEiwgxA.mjs → tasks-Coh5N027.mjs} +16 -15
  74. package/dist/tasks-Coh5N027.mjs.map +1 -0
  75. package/dist/{tasks-B9h3LPam.d.mts → tasks-wb9M-bak.d.mts} +11 -11
  76. package/dist/{tasks-B9h3LPam.d.mts.map → tasks-wb9M-bak.d.mts.map} +1 -1
  77. package/dist/{thread-handlers-Bef0td9N.d.mts → thread-handlers-C3Iya92v.d.mts} +6 -5
  78. package/dist/thread-handlers-C3Iya92v.d.mts.map +1 -0
  79. package/dist/{tools-CEsv-WoO.mjs → tools-D0KBDolR.mjs} +435 -408
  80. package/dist/tools-D0KBDolR.mjs.map +1 -0
  81. package/dist/turn-survey-draft-B34lggSG.d.mts +185 -0
  82. package/dist/turn-survey-draft-B34lggSG.d.mts.map +1 -0
  83. package/dist/ui.d.mts +3 -3
  84. package/dist/ui.d.mts.map +1 -1
  85. package/dist/ui.mjs +35 -23
  86. package/dist/ui.mjs.map +1 -1
  87. package/package.json +7 -7
  88. package/dist/authoring-references-DbuOKerg.mjs.map +0 -1
  89. package/dist/capabilities-CmeeAjEc.d.mts +0 -192
  90. package/dist/capabilities-CmeeAjEc.d.mts.map +0 -1
  91. package/dist/capabilities-DCMA71PP.mjs +0 -58
  92. package/dist/capabilities-DCMA71PP.mjs.map +0 -1
  93. package/dist/controller-proxy-DEeFl9IA.mjs.map +0 -1
  94. package/dist/default-fhSon2RM.mjs +0 -760
  95. package/dist/default-fhSon2RM.mjs.map +0 -1
  96. package/dist/digest-C39WyAWG.d.mts.map +0 -1
  97. package/dist/engine-nXoCWYpQ.mjs +0 -6888
  98. package/dist/engine-nXoCWYpQ.mjs.map +0 -1
  99. package/dist/index-Ciq7vHIs.d.mts +0 -716
  100. package/dist/index-Ciq7vHIs.d.mts.map +0 -1
  101. package/dist/index-D7wT6P3t.d.mts.map +0 -1
  102. package/dist/index-WB5kfnz0.d.mts.map +0 -1
  103. package/dist/index-r5riv4md.d.mts.map +0 -1
  104. package/dist/lifecycle-Dm8u7QFh.d.mts +0 -545
  105. package/dist/lifecycle-Dm8u7QFh.d.mts.map +0 -1
  106. package/dist/protocol-CF4Bh_Ch.mjs +0 -1255
  107. package/dist/protocol-CF4Bh_Ch.mjs.map +0 -1
  108. package/dist/react-C_GY-Fsc.mjs.map +0 -1
  109. package/dist/references/embedded-forms.md +0 -146
  110. package/dist/references/item-types.md +0 -641
  111. package/dist/request-context-Dg4jSwN1.mjs.map +0 -1
  112. package/dist/tasks-BZEiwgxA.mjs.map +0 -1
  113. package/dist/thread-handlers-Bef0td9N.d.mts.map +0 -1
  114. package/dist/tools-CEsv-WoO.mjs.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@case-framework/survey-assistant",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Shared protocol, engine, and runtime for the CASE survey assistant.",
5
5
  "license": "ISC",
6
6
  "files": [
@@ -85,12 +85,12 @@
85
85
  "./package.json": "./package.json"
86
86
  },
87
87
  "dependencies": {
88
- "@case-framework/survey-items": "0.2.0",
89
- "@case-framework/ui-localization": "0.2.1",
88
+ "@case-framework/survey-items": "0.3.0",
89
+ "@case-framework/ui-localization": "0.3.0",
90
90
  "class-variance-authority": "^0.7.1",
91
91
  "clsx": "^2.1.1",
92
92
  "fflate": "^0.8.3",
93
- "lucide-react": "^1.46.0",
93
+ "lucide-react": "^1.47.0",
94
94
  "motion": "^12.42.2",
95
95
  "shiki": "^4.4.3",
96
96
  "streamdown": "2.5.0",
@@ -102,13 +102,13 @@
102
102
  "devDependencies": {
103
103
  "@ai-sdk/react": "^4.0.96",
104
104
  "@base-ui/react": "^1.8.0",
105
- "@case-framework/survey-core": "0.8.0",
105
+ "@case-framework/survey-core": "0.9.0",
106
106
  "@mastra/ai-sdk": "^1.10.1",
107
107
  "@mastra/core": "^1.64.0",
108
108
  "@mastra/memory": "^1.28.2",
109
109
  "@mastra/pg": "^1.22.3",
110
110
  "@tailwindcss/vite": "^4.3.2",
111
- "@types/node": "^25.9.7",
111
+ "@types/node": "^25.9.8",
112
112
  "@types/react": "^19.3.0",
113
113
  "@types/react-dom": "19.3.0",
114
114
  "@types/react-test-renderer": "19.3.0",
@@ -125,7 +125,7 @@
125
125
  "peerDependencies": {
126
126
  "@ai-sdk/react": "^4.0.81",
127
127
  "@base-ui/react": "^1.8.0",
128
- "@case-framework/survey-core": "^0.8.0",
128
+ "@case-framework/survey-core": "^0.9.0",
129
129
  "@mastra/ai-sdk": "^1.9.1",
130
130
  "@mastra/core": "^1.61.0",
131
131
  "@mastra/memory": "^1.27.0",
@@ -1 +0,0 @@
1
- {"version":3,"file":"authoring-references-DbuOKerg.mjs","names":[],"sources":["../../../node_modules/.pnpm/tsdown@0.23.0_@volar+typescript@2.4.28_typescript@6.0.3__typescript@6.0.3_unrun@0.2.39/node_modules/tsdown/esm-shims.js","../src/server/authoring-references.ts"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","import { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nconst loadReference = (fileName: string) =>\n readFileSync(resolve(__dirname, \"references\", fileName), \"utf8\").trim();\n\nexport const surveyAuthoringReferenceTopics = [\n \"core-rules\",\n \"survey-data-model\",\n \"response-variables\",\n \"source-material-surveys\",\n \"localization\",\n \"rich-text-content\",\n \"item-types\",\n \"embedded-forms\",\n \"expressions\",\n \"assistant-operations\",\n \"fair-by-design\",\n \"survey-quality\",\n] as const;\n\nexport type SurveyAuthoringReferenceTopic = (typeof surveyAuthoringReferenceTopics)[number];\n\ntype SurveyAuthoringReferenceEntry = {\n title: string;\n content: string;\n loadWhen: string;\n};\n\nconst ITEM_TYPE_SECTION_HEADINGS: Readonly<Record<string, string>> = {\n group: \"group\",\n \"page-break\": \"page-break\",\n infoItem: \"infoItem\",\n consentItem: \"consentItem\",\n choiceItem: \"choiceItem\",\n formItem: \"formItem\",\n choiceMatrix: \"choiceMatrix\",\n formMatrix: \"formMatrix\",\n};\n\nexport const builtInSurveyAuthoringItemTypes = Object.freeze(\n Object.keys(ITEM_TYPE_SECTION_HEADINGS),\n);\n\nconst extractLevelTwoSection = (markdown: string, heading: string): string | undefined => {\n const lines = markdown.split(\"\\n\");\n const sectionStart = lines.findIndex((line) => line.trim() === `## ${heading}`);\n if (sectionStart < 0) {\n return undefined;\n }\n\n const nextSectionOffset = lines\n .slice(sectionStart + 1)\n .findIndex((line) => line.startsWith(\"## \"));\n const sectionEnd = nextSectionOffset < 0 ? lines.length : sectionStart + 1 + nextSectionOffset;\n\n return lines.slice(sectionStart, sectionEnd).join(\"\\n\").trim();\n};\n\nexport const surveyAuthoringReferences = {\n \"core-rules\": {\n title: \"Core authoring rules\",\n content: loadReference(\"core-rules.md\"),\n loadWhen:\n \"Load when the task depends on canonical tool choice, validation/apply semantics, identifier handling, or another cross-cutting authoring rule that the current turn has not already established.\",\n },\n \"response-variables\": {\n title: \"Response variables and coding\",\n content: loadReference(\"response-variables.md\"),\n loadWhen:\n \"Load before creating response inputs, changing variable names, option codes, matrix coding components, or export settings. Inspect current response slots for exact IDs and domains.\",\n },\n \"survey-data-model\": {\n title: \"Survey data model\",\n content: loadReference(\"survey-data-model.md\"),\n loadWhen:\n \"Load before reasoning about raw survey storage, hierarchy, ids, translation maps, assets, template values, or any direct survey-json-patch path whose exact location has not already been inspected and documented in the current turn.\",\n },\n \"source-material-surveys\": {\n title: \"Source-material survey implementation\",\n content: loadReference(\"source-material-surveys.md\"),\n loadWhen:\n \"Load before implementing or adapting a questionnaire, document, image, or other supplied source material so completeness, respondent-input mapping, meaningful layout, language, and digital adaptation rules are available before the first mutation.\",\n },\n localization: {\n title: \"Survey localization\",\n content: loadReference(\"localization.md\"),\n loadWhen:\n \"Load before adding, removing, translating, or assessing a survey locale, including requests for localization completeness or locale lifecycle changes.\",\n },\n \"rich-text-content\": {\n title: \"Rich text content\",\n content: loadReference(\"rich-text-content.md\"),\n loadWhen:\n \"Load before authoring or changing meaningful formatting, links, images, headings, lists, info boxes, separators, footnotes, or existing structured rich-text content; do not load it for ordinary unformatted plain text.\",\n },\n \"item-types\": {\n title: \"Item types\",\n content: loadReference(\"item-types.md\"),\n loadWhen:\n \"Load with itemType before creating or changing an item when its configuration, response behavior, or content surfaces are not already fully specified by the current capability and focused operation contract; omit itemType only for a genuine cross-type comparison.\",\n },\n \"embedded-forms\": {\n title: \"Choice option embedded forms\",\n content: loadReference(\"embedded-forms.md\"),\n loadWhen:\n 'Load before creating or changing a choice-option follow-up or embedded form, including \"Other, specify\", option-specific inputs, embedded field groups, or embedded-form layout and translations.',\n },\n expressions: {\n title: \"Expressions\",\n content: loadReference(\"expressions.md\"),\n loadWhen:\n \"Load before the first survey_expression prepare call for expression, condition, validation-expression, prefill, or template-value work unless the exact relevant JsonExpression and mutation shapes were already supplied by a current-turn authoring reference. survey_expression context supplies currently available runtime references and value types, but it does not replace the grammar reference. Expressions are not assumed to be survey-response-only; use the references and variable sources supported by the current runtime and reference.\",\n },\n \"assistant-operations\": {\n title: \"Assistant operations\",\n content: loadReference(\"assistant-operations.md\"),\n loadWhen:\n \"Load with operationKind before the first survey_change call when the exact canonical fields of that operation are not already present in the current turn; add itemType when item-specific configuration or capability guidance is needed. Prefer compact detail and use full only for protocol debugging.\",\n },\n \"fair-by-design\": {\n title: \"FAIR-by-design survey authoring\",\n content: loadReference(\"fair-by-design.md\"),\n loadWhen:\n \"Load before advising or editing when FAIR, interoperability, harmonization, cross-study reuse, stable coding, value sets, missingness semantics, metadata, provenance, versioning, standard instruments, controlled vocabularies, or machine-readable export is material; do not impose it on ordinary authoring.\",\n },\n \"survey-quality\": {\n title: \"Survey quality review\",\n content: loadReference(\"survey-quality.md\"),\n loadWhen:\n \"Load before a substantive questionnaire-quality critique, wording or flow review, respondent-burden assessment, or recommendations about measurement quality; it is not required for a purely technical defect check.\",\n },\n} as const satisfies Record<SurveyAuthoringReferenceTopic, SurveyAuthoringReferenceEntry>;\n\nexport const formatSurveyAuthoringReferenceRoutingInstructions = (): string =>\n [\n \"Authoring-reference routing rules:\",\n \"Load a relevant focused reference before the first affected mutation or substantive advice, not after guessing a payload or learning through validator failures. Do not reload a reference when its exact relevant contract is already present in the current turn. References define stable authoring conventions and payload grammar; current survey state and currently available runtime references still come from inspection and context tools.\",\n \"For installed capability-specific references, use the capability manifest's advertised reference topics. Load a relevant topic with itemType before changing unfamiliar capability configuration or behavior.\",\n ...surveyAuthoringReferenceTopics.map(\n (topic) => `- ${topic}: ${surveyAuthoringReferences[topic].loadWhen}`,\n ),\n ].join(\"\\n\");\n\nexport const getBuiltInItemTypeAuthoringReference = (\n itemType: string,\n): { title: string; content: string } | undefined => {\n const heading = ITEM_TYPE_SECTION_HEADINGS[itemType];\n if (!heading) {\n return undefined;\n }\n\n const content = extractLevelTwoSection(surveyAuthoringReferences[\"item-types\"].content, heading);\n return content ? { title: `${heading} item type`, content } : undefined;\n};\n"],"x_google_ignoreList":[0],"mappings":";;;;AAIA,MAAM,oBAAoB,cAAc,YAAY,GAAG;AACvD,MAAM,mBAAmB,KAAK,QAAQ,YAAY,CAAC;AAEnD,MAAa,YAA4B,2BAAW;;;ACJpD,MAAM,iBAAiB,aACrB,aAAa,QAAQ,WAA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mBAAmB;EAC1C,UACE;CACJ;CACA,aAAa;EACX,OAAO;EACP,SAAS,cAAc,gBAAgB;EACvC,UACE;CACJ;CACA,wBAAwB;EACtB,OAAO;EACP,SAAS,cAAc,yBAAyB;EAChD,UACE;CACJ;CACA,kBAAkB;EAChB,OAAO;EACP,SAAS,cAAc,mBAAmB;EAC1C,UACE;CACJ;CACA,kBAAkB;EAChB,OAAO;EACP,SAAS,cAAc,mBAAmB;EAC1C,UACE;CACJ;AACF;AAEA,MAAa,0DACX;CACE;CACA;CACA;CACA,GAAG,+BAA+B,KAC/B,UAAU,KAAK,MAAM,IAAI,0BAA0B,MAAM,CAAC,UAC7D;AACF,CAAC,CAAC,KAAK,IAAI;AAEb,MAAa,wCACX,aACmD;CACnD,MAAM,UAAU,2BAA2B;CAC3C,IAAI,CAAC,SACH;CAGF,MAAM,UAAU,uBAAuB,0BAA0B,aAAa,CAAC,SAAS,OAAO;CAC/F,OAAO,UAAU;EAAE,OAAO,GAAG,QAAQ;EAAa;CAAQ,IAAI,KAAA;AAChE"}
@@ -1,192 +0,0 @@
1
- import { z } from "zod";
2
- //#region src/protocol/capabilities.d.ts
3
- declare const assistantItemCreateModeSchema: z.ZodEnum<{
4
- deterministic: "deterministic";
5
- "interactive-only": "interactive-only";
6
- unsupported: "unsupported";
7
- }>;
8
- declare const assistantContentSurfaceSchema: z.ZodObject<{
9
- key: z.ZodString;
10
- role: z.ZodEnum<{
11
- primary: "primary";
12
- secondary: "secondary";
13
- option: "option";
14
- field: "field";
15
- validation: "validation";
16
- }>;
17
- format: z.ZodEnum<{
18
- plain: "plain";
19
- rich: "rich";
20
- }>;
21
- requiredOnCreate: z.ZodOptional<z.ZodBoolean>;
22
- pattern: z.ZodOptional<z.ZodBoolean>;
23
- aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
24
- }, z.core.$strip>;
25
- declare const assistantResponseSlotSchema: z.ZodObject<{
26
- key: z.ZodString;
27
- valueType: z.ZodString;
28
- }, z.core.$strip>;
29
- declare const assistantItemAuthoringSchema: z.ZodObject<{
30
- compactHint: z.ZodOptional<z.ZodString>;
31
- configSummary: z.ZodOptional<z.ZodString>;
32
- }, z.core.$strip>;
33
- declare const assistantItemTypeManifestSchema: z.ZodObject<{
34
- itemType: z.ZodString;
35
- capabilityVersion: z.ZodString;
36
- displayName: z.ZodString;
37
- description: z.ZodOptional<z.ZodString>;
38
- defaultItemKeyPrefix: z.ZodOptional<z.ZodString>;
39
- create: z.ZodEnum<{
40
- deterministic: "deterministic";
41
- "interactive-only": "interactive-only";
42
- unsupported: "unsupported";
43
- }>;
44
- supportedOperations: z.ZodArray<z.ZodEnum<{
45
- "update-response-settings": "update-response-settings";
46
- "create-item": "create-item";
47
- "update-item-label": "update-item-label";
48
- "update-item-color": "update-item-color";
49
- "update-item-translation": "update-item-translation";
50
- "update-placed-image": "update-placed-image";
51
- "patch-item-config": "patch-item-config";
52
- "upsert-form-field-group": "upsert-form-field-group";
53
- "remove-form-field-group": "remove-form-field-group";
54
- "reorder-form-field-groups": "reorder-form-field-groups";
55
- "upsert-form-field": "upsert-form-field";
56
- "remove-form-field": "remove-form-field";
57
- "move-form-field": "move-form-field";
58
- "set-embedded-form": "set-embedded-form";
59
- "remove-embedded-form": "remove-embedded-form";
60
- "add-choice-option": "add-choice-option";
61
- "update-choice-option-label": "update-choice-option-label";
62
- "remove-choice-option": "remove-choice-option";
63
- "reorder-choice-options": "reorder-choice-options";
64
- "remove-item": "remove-item";
65
- "move-item": "move-item";
66
- "reorder-items": "reorder-items";
67
- "update-survey-metadata": "update-survey-metadata";
68
- "update-survey-pagination": "update-survey-pagination";
69
- "update-survey-translation": "update-survey-translation";
70
- "add-survey-locale": "add-survey-locale";
71
- "remove-survey-locale": "remove-survey-locale";
72
- "set-image-asset": "set-image-asset";
73
- "update-image-asset-metadata": "update-image-asset-metadata";
74
- "remove-image-asset": "remove-image-asset";
75
- "survey-json-patch": "survey-json-patch";
76
- }>>;
77
- contentSurfaces: z.ZodArray<z.ZodObject<{
78
- key: z.ZodString;
79
- role: z.ZodEnum<{
80
- primary: "primary";
81
- secondary: "secondary";
82
- option: "option";
83
- field: "field";
84
- validation: "validation";
85
- }>;
86
- format: z.ZodEnum<{
87
- plain: "plain";
88
- rich: "rich";
89
- }>;
90
- requiredOnCreate: z.ZodOptional<z.ZodBoolean>;
91
- pattern: z.ZodOptional<z.ZodBoolean>;
92
- aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
93
- }, z.core.$strip>>;
94
- responseSlots: z.ZodOptional<z.ZodArray<z.ZodObject<{
95
- key: z.ZodString;
96
- valueType: z.ZodString;
97
- }, z.core.$strip>>>;
98
- creationPresets: z.ZodOptional<z.ZodArray<z.ZodObject<{
99
- id: z.ZodString;
100
- }, z.core.$strip>>>;
101
- referenceTopics: z.ZodOptional<z.ZodArray<z.ZodString>>;
102
- authoring: z.ZodOptional<z.ZodObject<{
103
- compactHint: z.ZodOptional<z.ZodString>;
104
- configSummary: z.ZodOptional<z.ZodString>;
105
- }, z.core.$strip>>;
106
- }, z.core.$strip>;
107
- declare const surveyAssistantCapabilityManifestSchema: z.ZodObject<{
108
- digest: z.ZodString;
109
- itemTypes: z.ZodArray<z.ZodObject<{
110
- itemType: z.ZodString;
111
- capabilityVersion: z.ZodString;
112
- displayName: z.ZodString;
113
- description: z.ZodOptional<z.ZodString>;
114
- defaultItemKeyPrefix: z.ZodOptional<z.ZodString>;
115
- create: z.ZodEnum<{
116
- deterministic: "deterministic";
117
- "interactive-only": "interactive-only";
118
- unsupported: "unsupported";
119
- }>;
120
- supportedOperations: z.ZodArray<z.ZodEnum<{
121
- "update-response-settings": "update-response-settings";
122
- "create-item": "create-item";
123
- "update-item-label": "update-item-label";
124
- "update-item-color": "update-item-color";
125
- "update-item-translation": "update-item-translation";
126
- "update-placed-image": "update-placed-image";
127
- "patch-item-config": "patch-item-config";
128
- "upsert-form-field-group": "upsert-form-field-group";
129
- "remove-form-field-group": "remove-form-field-group";
130
- "reorder-form-field-groups": "reorder-form-field-groups";
131
- "upsert-form-field": "upsert-form-field";
132
- "remove-form-field": "remove-form-field";
133
- "move-form-field": "move-form-field";
134
- "set-embedded-form": "set-embedded-form";
135
- "remove-embedded-form": "remove-embedded-form";
136
- "add-choice-option": "add-choice-option";
137
- "update-choice-option-label": "update-choice-option-label";
138
- "remove-choice-option": "remove-choice-option";
139
- "reorder-choice-options": "reorder-choice-options";
140
- "remove-item": "remove-item";
141
- "move-item": "move-item";
142
- "reorder-items": "reorder-items";
143
- "update-survey-metadata": "update-survey-metadata";
144
- "update-survey-pagination": "update-survey-pagination";
145
- "update-survey-translation": "update-survey-translation";
146
- "add-survey-locale": "add-survey-locale";
147
- "remove-survey-locale": "remove-survey-locale";
148
- "set-image-asset": "set-image-asset";
149
- "update-image-asset-metadata": "update-image-asset-metadata";
150
- "remove-image-asset": "remove-image-asset";
151
- "survey-json-patch": "survey-json-patch";
152
- }>>;
153
- contentSurfaces: z.ZodArray<z.ZodObject<{
154
- key: z.ZodString;
155
- role: z.ZodEnum<{
156
- primary: "primary";
157
- secondary: "secondary";
158
- option: "option";
159
- field: "field";
160
- validation: "validation";
161
- }>;
162
- format: z.ZodEnum<{
163
- plain: "plain";
164
- rich: "rich";
165
- }>;
166
- requiredOnCreate: z.ZodOptional<z.ZodBoolean>;
167
- pattern: z.ZodOptional<z.ZodBoolean>;
168
- aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
169
- }, z.core.$strip>>;
170
- responseSlots: z.ZodOptional<z.ZodArray<z.ZodObject<{
171
- key: z.ZodString;
172
- valueType: z.ZodString;
173
- }, z.core.$strip>>>;
174
- creationPresets: z.ZodOptional<z.ZodArray<z.ZodObject<{
175
- id: z.ZodString;
176
- }, z.core.$strip>>>;
177
- referenceTopics: z.ZodOptional<z.ZodArray<z.ZodString>>;
178
- authoring: z.ZodOptional<z.ZodObject<{
179
- compactHint: z.ZodOptional<z.ZodString>;
180
- configSummary: z.ZodOptional<z.ZodString>;
181
- }, z.core.$strip>>;
182
- }, z.core.$strip>>;
183
- }, z.core.$strip>;
184
- type AssistantItemCreateMode = z.infer<typeof assistantItemCreateModeSchema>;
185
- type AssistantContentSurface = z.infer<typeof assistantContentSurfaceSchema>;
186
- type AssistantResponseSlot = z.infer<typeof assistantResponseSlotSchema>;
187
- type AssistantItemAuthoring = z.infer<typeof assistantItemAuthoringSchema>;
188
- type AssistantItemTypeManifest = z.infer<typeof assistantItemTypeManifestSchema>;
189
- type SurveyAssistantCapabilityManifest = z.infer<typeof surveyAssistantCapabilityManifestSchema>;
190
- //#endregion
191
- export { AssistantResponseSlot as a, assistantItemAuthoringSchema as c, assistantResponseSlotSchema as d, surveyAssistantCapabilityManifestSchema as f, AssistantItemTypeManifest as i, assistantItemCreateModeSchema as l, AssistantItemAuthoring as n, SurveyAssistantCapabilityManifest as o, AssistantItemCreateMode as r, assistantContentSurfaceSchema as s, AssistantContentSurface as t, assistantItemTypeManifestSchema as u };
192
- //# sourceMappingURL=capabilities-CmeeAjEc.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"capabilities-CmeeAjEc.d.mts","names":[],"sources":["../src/protocol/capabilities.ts"],"mappings":";;cAGa,+BAA6B,EAAA;;;;;cAM7B,+BAA6B,EAAA;;;;;;;;;;;;;;;;GAOxC,EAAA,KAAA;cAEW,6BAA2B,EAAA;;;GAGtC,EAAA,KAAA;cAEW,8BAA4B,EAAA;;;GAGvC,EAAA,KAAA;cAMW,iCAA+B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAa1C,EAAA,KAAA;cAEW,yCAAuC,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAGlD,EAAA,KAAA;KAEU,0BAA0B,EAAE,aAAa;KACzC,0BAA0B,EAAE,aAAa;KACzC,wBAAwB,EAAE,aAAa;KACvC,yBAAyB,EAAE,aAAa;KAExC,4BAA4B,EAAE,aAAa;KAC3C,oCAAoC,EAAE,aACzC"}
@@ -1,58 +0,0 @@
1
- import { Y as assistantItemTypeManifestSchema } from "./protocol-CF4Bh_Ch.mjs";
2
- import { buildCapabilityDigest, stableStringify } from "./digest.mjs";
3
- //#region src/engine/capabilities.ts
4
- const resolveAssistantCapabilityReference = ({ capabilities, itemType, topic }) => capabilities?.byItemType.get(itemType)?.references?.find((reference) => reference.topic === topic);
5
- const inspectAssistantItem = ({ capabilities, item }) => capabilities?.byItemType.get(item.itemType)?.inspectItem?.(item);
6
- const createSurveyAssistantCapabilities = (capabilities) => {
7
- const byItemType = /* @__PURE__ */ new Map();
8
- const normalizedManifests = [];
9
- for (const capability of capabilities) {
10
- const manifest = assistantItemTypeManifestSchema.parse(capability.manifest);
11
- const itemType = manifest.itemType;
12
- if (byItemType.has(itemType)) throw new Error(`Duplicate survey assistant capability for item type "${itemType}".`);
13
- if (manifest.create === "deterministic" && !manifest.supportedOperations.includes("create-item")) throw new Error(`Deterministically creatable item type "${itemType}" must support "create-item".`);
14
- if (manifest.create === "deterministic" && capability.deriveResponseSlots && !capability.deriveResponseSlotDefinitions && !capability.itemCore) throw new Error(`Creatable response item type "${itemType}" must supply deriveResponseSlotDefinitions with persistent slot IDs and separate variable names. Type-only deriveResponseSlots cannot define current response coding.`);
15
- const declaredReferenceTopics = new Set(manifest.referenceTopics ?? []);
16
- for (const reference of capability.references ?? []) if (!declaredReferenceTopics.has(reference.topic)) throw new Error(`Capability reference "${reference.topic}" for item type "${itemType}" is missing from manifest.referenceTopics.`);
17
- byItemType.set(itemType, capability);
18
- normalizedManifests.push(assistantItemTypeManifestSchema.parse(JSON.parse(JSON.stringify(manifest))));
19
- }
20
- const manifestWithoutDigest = { itemTypes: normalizedManifests.sort((left, right) => left.itemType.localeCompare(right.itemType)) };
21
- return {
22
- manifest: {
23
- ...manifestWithoutDigest,
24
- digest: buildCapabilityDigest(manifestWithoutDigest)
25
- },
26
- byItemType
27
- };
28
- };
29
- const getDeterministicCreateItemTypes = (manifest) => manifest.itemTypes.filter((entry) => entry.create === "deterministic").map((entry) => entry.itemType);
30
- const createUnsupportedItemCapability = ({ displayName, itemType }) => ({ manifest: {
31
- itemType,
32
- capabilityVersion: "unsupported-v1",
33
- displayName,
34
- create: "unsupported",
35
- supportedOperations: [],
36
- contentSurfaces: []
37
- } });
38
- var SurveyAssistantCapabilityMismatchError = class extends Error {
39
- code = "survey-assistant-capability-mismatch";
40
- constructor(message = "Survey assistant capabilities changed; start a fresh turn and retry.") {
41
- super(message);
42
- this.name = "SurveyAssistantCapabilityMismatchError";
43
- }
44
- };
45
- const assertSurveyAssistantCapabilities = ({ manifest, trustedCapabilities, versionDigest }) => {
46
- const { digest: claimedDigest, ...manifestWithoutDigest } = manifest;
47
- if (claimedDigest !== buildCapabilityDigest(manifestWithoutDigest) || versionDigest !== claimedDigest) throw new SurveyAssistantCapabilityMismatchError();
48
- if (trustedCapabilities) {
49
- const withoutContextualPresets = ({ creationPresets: _creationPresets, ...capability }) => capability;
50
- const claimedBaseCapabilities = manifest.itemTypes.map(withoutContextualPresets);
51
- const trustedBaseCapabilities = trustedCapabilities.manifest.itemTypes.map(withoutContextualPresets);
52
- if (stableStringify(claimedBaseCapabilities) !== stableStringify(trustedBaseCapabilities)) throw new SurveyAssistantCapabilityMismatchError("The editor and server use different survey assistant capabilities; refresh and retry.");
53
- }
54
- };
55
- //#endregion
56
- export { getDeterministicCreateItemTypes as a, createUnsupportedItemCapability as i, assertSurveyAssistantCapabilities as n, inspectAssistantItem as o, createSurveyAssistantCapabilities as r, resolveAssistantCapabilityReference as s, SurveyAssistantCapabilityMismatchError as t };
57
-
58
- //# sourceMappingURL=capabilities-DCMA71PP.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"capabilities-DCMA71PP.mjs","names":[],"sources":["../src/engine/capabilities.ts"],"sourcesContent":["import type { z } from \"zod\";\nimport type {\n ItemTypeRegistry,\n RawSurveyItem,\n ResponseSlotDefinition,\n ValueType,\n} from \"@case-framework/survey-core\";\nimport type {\n AssistantItemTypeManifest,\n JsonValue,\n SurveyAssistantCapabilityManifest,\n SurveyOperation,\n SurveyValidationIssue,\n} from \"../protocol\";\nimport { assistantItemTypeManifestSchema } from \"../protocol\";\nimport { buildCapabilityDigest, stableStringify } from \"../protocol/digest\";\n\nexport interface AssistantCapabilityReference {\n topic: string;\n title?: string;\n markdown: string;\n}\n\nexport interface AssistantItemInspection {\n summary: string;\n details?: JsonValue;\n}\n\nexport interface AssistantItemCapabilityAdapter {\n manifest: AssistantItemTypeManifest;\n /** Trusted server-safe core shared with the player, including response activation dependencies. */\n itemCore?: ItemTypeRegistry[string];\n references?: AssistantCapabilityReference[];\n configurationSchema?: z.ZodType;\n materializePreset?: (\n presetId: string,\n locale: string,\n ) => {\n config: RawSurveyItem[\"config\"];\n translations: NonNullable<Extract<SurveyOperation, { kind: \"create-item\" }>[\"translations\"]>;\n };\n validContentKeys?: (item: RawSurveyItem) => string[];\n normalizeCreate?: (item: RawSurveyItem) => RawSurveyItem;\n requiredCreateContentKeys?: (item: RawSurveyItem) => string[];\n validateItem?: (item: RawSurveyItem) => SurveyValidationIssue[];\n supportsOperation?: (operation: SurveyOperation) => boolean;\n deriveResponseSlotDefinitions?: (item: RawSurveyItem) => ResponseSlotDefinition[];\n /** Type-only inspection adapter. Creatable response items require full definitions. */\n deriveResponseSlots?: (item: RawSurveyItem) => Record<string, ValueType>;\n inspectItem?: (item: RawSurveyItem) => AssistantItemInspection;\n}\n\nexport interface SurveyAssistantCapabilitySet {\n manifest: SurveyAssistantCapabilityManifest;\n byItemType: ReadonlyMap<string, AssistantItemCapabilityAdapter>;\n}\n\nexport const resolveAssistantCapabilityReference = ({\n capabilities,\n itemType,\n topic,\n}: {\n capabilities: SurveyAssistantCapabilitySet | undefined;\n itemType: string;\n topic: string;\n}): AssistantCapabilityReference | undefined =>\n capabilities?.byItemType\n .get(itemType)\n ?.references?.find((reference) => reference.topic === topic);\n\nexport const inspectAssistantItem = ({\n capabilities,\n item,\n}: {\n capabilities: SurveyAssistantCapabilitySet | undefined;\n item: RawSurveyItem;\n}): AssistantItemInspection | undefined =>\n capabilities?.byItemType.get(item.itemType)?.inspectItem?.(item);\n\nexport const createSurveyAssistantCapabilities = (\n capabilities: readonly AssistantItemCapabilityAdapter[],\n): SurveyAssistantCapabilitySet => {\n const byItemType = new Map<string, AssistantItemCapabilityAdapter>();\n const normalizedManifests: AssistantItemTypeManifest[] = [];\n\n for (const capability of capabilities) {\n const manifest = assistantItemTypeManifestSchema.parse(capability.manifest);\n const itemType = manifest.itemType;\n if (byItemType.has(itemType)) {\n throw new Error(`Duplicate survey assistant capability for item type \"${itemType}\".`);\n }\n if (\n manifest.create === \"deterministic\" &&\n !manifest.supportedOperations.includes(\"create-item\")\n ) {\n throw new Error(\n `Deterministically creatable item type \"${itemType}\" must support \"create-item\".`,\n );\n }\n if (\n manifest.create === \"deterministic\" &&\n capability.deriveResponseSlots &&\n !capability.deriveResponseSlotDefinitions &&\n !capability.itemCore\n ) {\n throw new Error(\n `Creatable response item type \"${itemType}\" must supply deriveResponseSlotDefinitions with persistent slot IDs and separate variable names. Type-only deriveResponseSlots cannot define current response coding.`,\n );\n }\n const declaredReferenceTopics = new Set(manifest.referenceTopics ?? []);\n for (const reference of capability.references ?? []) {\n if (!declaredReferenceTopics.has(reference.topic)) {\n throw new Error(\n `Capability reference \"${reference.topic}\" for item type \"${itemType}\" is missing from manifest.referenceTopics.`,\n );\n }\n }\n byItemType.set(itemType, capability);\n normalizedManifests.push(\n assistantItemTypeManifestSchema.parse(JSON.parse(JSON.stringify(manifest))),\n );\n }\n\n const itemTypes = normalizedManifests.sort((left, right) =>\n left.itemType.localeCompare(right.itemType),\n );\n const manifestWithoutDigest = { itemTypes };\n\n return {\n manifest: {\n ...manifestWithoutDigest,\n digest: buildCapabilityDigest(manifestWithoutDigest),\n },\n byItemType,\n };\n};\n\nexport const getDeterministicCreateItemTypes = (\n manifest: SurveyAssistantCapabilityManifest,\n): string[] =>\n manifest.itemTypes\n .filter((entry) => entry.create === \"deterministic\")\n .map((entry) => entry.itemType);\n\nexport const createUnsupportedItemCapability = ({\n displayName,\n itemType,\n}: {\n displayName: string;\n itemType: string;\n}): AssistantItemCapabilityAdapter => ({\n manifest: {\n itemType,\n capabilityVersion: \"unsupported-v1\",\n displayName,\n create: \"unsupported\",\n supportedOperations: [],\n contentSurfaces: [],\n },\n});\n\nexport class SurveyAssistantCapabilityMismatchError extends Error {\n readonly code = \"survey-assistant-capability-mismatch\";\n\n constructor(message = \"Survey assistant capabilities changed; start a fresh turn and retry.\") {\n super(message);\n this.name = \"SurveyAssistantCapabilityMismatchError\";\n }\n}\n\nexport const assertSurveyAssistantCapabilities = ({\n manifest,\n trustedCapabilities,\n versionDigest,\n}: {\n manifest: SurveyAssistantCapabilityManifest;\n trustedCapabilities?: SurveyAssistantCapabilitySet;\n versionDigest: string;\n}): void => {\n const { digest: claimedDigest, ...manifestWithoutDigest } = manifest;\n const computedDigest = buildCapabilityDigest(manifestWithoutDigest);\n if (claimedDigest !== computedDigest || versionDigest !== claimedDigest) {\n throw new SurveyAssistantCapabilityMismatchError();\n }\n\n if (trustedCapabilities) {\n const withoutContextualPresets = ({\n creationPresets: _creationPresets,\n ...capability\n }: AssistantItemTypeManifest): Omit<AssistantItemTypeManifest, \"creationPresets\"> => capability;\n const claimedBaseCapabilities = manifest.itemTypes.map(withoutContextualPresets);\n const trustedBaseCapabilities =\n trustedCapabilities.manifest.itemTypes.map(withoutContextualPresets);\n\n // Creation presets are editor-registry context for the model. They do not\n // grant operations or install executable adapters, so the server validates\n // the stable capability contract while retaining its own trusted adapters.\n if (stableStringify(claimedBaseCapabilities) !== stableStringify(trustedBaseCapabilities)) {\n throw new SurveyAssistantCapabilityMismatchError(\n \"The editor and server use different survey assistant capabilities; refresh and retry.\",\n );\n }\n }\n};\n"],"mappings":";;;AAyDA,MAAa,uCAAuC,EAClD,cACA,UAC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UAAU,MAAM,WAAW,eAAe,CAAC,CACnD,KAAK,UAAU,MAAM,QAAQ;AAElC,MAAa,mCAAmC,EAC9C,aACA,gBAIqC,EACrC,UAAU;CACR;CACA,mBAAmB;CACnB;CACA,QAAQ;CACR,qBAAqB,CAAC;CACtB,iBAAiB,CAAC;AACpB,EACF;AAEA,IAAa,yCAAb,cAA4D,MAAM;CAChE,OAAgB;CAEhB,YAAY,UAAU,wEAAwE;EAC5F,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;AAEA,MAAa,qCAAqC,EAChD,UACA,qBACA,oBAKU;CACV,MAAM,EAAE,QAAQ,eAAe,GAAG,0BAA0B;CAE5D,IAAI,kBADmB,sBAAsB,qBACV,KAAK,kBAAkB,eACxD,MAAM,IAAI,uCAAuC;CAGnD,IAAI,qBAAqB;EACvB,MAAM,4BAA4B,EAChC,iBAAiB,kBACjB,GAAG,iBACgF;EACrF,MAAM,0BAA0B,SAAS,UAAU,IAAI,wBAAwB;EAC/E,MAAM,0BACJ,oBAAoB,SAAS,UAAU,IAAI,wBAAwB;EAKrE,IAAI,gBAAgB,uBAAuB,MAAM,gBAAgB,uBAAuB,GACtF,MAAM,IAAI,uCACR,uFACF;CAEJ;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"controller-proxy-DEeFl9IA.mjs","names":[],"sources":["../src/react/client-error.ts","../src/react/thread-launcher.ts","../src/react/task-client.ts","../src/react/controller-proxy.ts"],"sourcesContent":["import {\n isSurveyAssistantErrorRetryable,\n parseSurveyAssistantError,\n type SurveyAssistantErrorCode,\n type SurveyAssistantErrorInfo,\n} from \"../protocol\";\n\nexport class SurveyAssistantClientError extends Error {\n readonly code: SurveyAssistantErrorCode;\n readonly retryable: boolean;\n readonly upstreamStatus?: number;\n readonly providerRequestId?: string;\n readonly providerMessage?: string;\n\n constructor(\n code: SurveyAssistantErrorCode,\n message: string,\n retryable = false,\n diagnostics: Pick<\n SurveyAssistantErrorInfo,\n \"providerMessage\" | \"providerRequestId\" | \"upstreamStatus\"\n > = {},\n ) {\n super(message);\n this.name = \"SurveyAssistantClientError\";\n this.code = code;\n this.retryable = retryable;\n this.upstreamStatus = diagnostics.upstreamStatus;\n this.providerRequestId = diagnostics.providerRequestId;\n this.providerMessage = diagnostics.providerMessage;\n }\n}\n\nexport const readSurveyAssistantJson = async (\n response: Response,\n fallback = \"The assistant request could not be completed.\",\n) => {\n if (!response.ok) {\n const responseText = await response.text().catch(() => \"\");\n let body: unknown;\n try {\n body = responseText ? JSON.parse(responseText) : undefined;\n } catch {\n body = undefined;\n }\n const detail =\n typeof body === \"object\" && body !== null && \"error\" in body && typeof body.error === \"string\"\n ? body.error\n : responseText.trim() || fallback;\n const parsed = parseSurveyAssistantError(\n typeof body === \"object\" && body !== null && \"code\" in body && typeof body.code === \"string\"\n ? {\n code: body.code,\n detail,\n retryable:\n \"retryable\" in body && typeof body.retryable === \"boolean\"\n ? body.retryable\n : undefined,\n upstreamStatus:\n \"upstreamStatus\" in body && typeof body.upstreamStatus === \"number\"\n ? body.upstreamStatus\n : undefined,\n providerRequestId:\n \"providerRequestId\" in body && typeof body.providerRequestId === \"string\"\n ? body.providerRequestId\n : undefined,\n providerMessage:\n \"providerMessage\" in body && typeof body.providerMessage === \"string\"\n ? body.providerMessage\n : undefined,\n }\n : detail,\n );\n const retryable = isSurveyAssistantErrorRetryable(parsed, response.status);\n throw new SurveyAssistantClientError(parsed.code, parsed.detail ?? detail, retryable, parsed);\n }\n return response.json().catch(() => ({}));\n};\n","import type {\n SurveyAssistantSnapshot,\n SurveyAssistantThread,\n SurveyEditorUIContext,\n} from \"../protocol\";\nimport type { FileUIPart } from \"ai\";\n\nexport type SurveyAssistantLaunchUIContext = Partial<Omit<SurveyEditorUIContext, \"history\">>;\n\nexport interface SurveyAssistantThreadLaunch {\n /** User-visible prompt submitted as the first message in the new thread. */\n prompt: string;\n files?: FileUIPart[];\n /** Optional model used for the opening assistant turn. */\n modelId?: string;\n /** Optional manual thread title. The prompt-derived automatic title is used by default. */\n title?: string;\n /** Turn-local editor context merged into the snapshot captured when the prompt is submitted. */\n uiContext?: SurveyAssistantLaunchUIContext;\n}\n\nexport interface SurveyAssistantThreadLauncher {\n /**\n * Creates a new thread and submits its first prompt when a connected panel is ready.\n * Calls made before the panel mounts are queued.\n */\n startThread(input: SurveyAssistantThreadLaunch): Promise<SurveyAssistantThread>;\n}\n\ntype LaunchHandler = (input: SurveyAssistantThreadLaunch) => Promise<SurveyAssistantThread>;\n\ninterface PendingLaunch {\n input: SurveyAssistantThreadLaunch;\n reject(error: unknown): void;\n resolve(thread: SurveyAssistantThread): void;\n}\n\ninterface LauncherState {\n handler: LaunchHandler | null;\n pending: PendingLaunch[];\n draining: boolean;\n}\n\nconst launcherStates = new WeakMap<SurveyAssistantThreadLauncher, LauncherState>();\n\nexport const applySurveyAssistantLaunchUIContext = (\n snapshot: SurveyAssistantSnapshot | null,\n uiContext: SurveyAssistantLaunchUIContext | undefined,\n): SurveyAssistantSnapshot | null =>\n snapshot && uiContext\n ? {\n ...snapshot,\n ui: {\n ...snapshot.ui,\n ...uiContext,\n },\n }\n : snapshot;\n\nconst getLauncherState = (launcher: SurveyAssistantThreadLauncher) => {\n const state = launcherStates.get(launcher);\n if (!state) {\n throw new Error(\n \"The survey assistant thread launcher was not created by createSurveyAssistantThreadLauncher.\",\n );\n }\n return state;\n};\n\nconst drainPendingLaunches = async (state: LauncherState) => {\n if (state.draining) return;\n state.draining = true;\n try {\n while (state.handler && state.pending.length > 0) {\n const pending = state.pending.shift();\n if (!pending) continue;\n try {\n pending.resolve(await state.handler(pending.input));\n } catch (error) {\n pending.reject(error);\n }\n }\n } finally {\n state.draining = false;\n }\n};\n\nexport const createSurveyAssistantThreadLauncher = (): SurveyAssistantThreadLauncher => {\n const state: LauncherState = { handler: null, pending: [], draining: false };\n const launcher: SurveyAssistantThreadLauncher = {\n startThread(input) {\n const prompt = input.prompt.trim();\n if (!prompt && (input.files?.length ?? 0) === 0) {\n return Promise.reject(new Error(\"A survey assistant prompt or attachment is required.\"));\n }\n\n return new Promise((resolve, reject) => {\n state.pending.push({\n input: {\n ...input,\n prompt,\n ...(input.files ? { files: [...input.files] } : {}),\n ...(input.modelId ? { modelId: input.modelId.trim() } : {}),\n ...(input.title ? { title: input.title.trim() } : {}),\n },\n reject,\n resolve,\n });\n void drainPendingLaunches(state);\n });\n },\n };\n launcherStates.set(launcher, state);\n return launcher;\n};\n\nexport const connectSurveyAssistantThreadLauncher = (\n launcher: SurveyAssistantThreadLauncher,\n handler: LaunchHandler,\n) => {\n const state = getLauncherState(launcher);\n if (state.handler && state.handler !== handler) {\n throw new Error(\"A survey assistant thread launcher can only control one mounted panel.\");\n }\n state.handler = handler;\n void drainPendingLaunches(state);\n\n return () => {\n if (state.handler === handler) state.handler = null;\n };\n};\n","import {\n surveyAssistantSuggestResponseSettingsResultSchema,\n type SurveyAssistantSuggestResponseSettingsInput,\n type SurveyAssistantSuggestResponseSettingsResult,\n} from \"../protocol/tasks\";\nimport {\n surveyAssistantSuggestResponseNameResultSchema,\n surveyAssistantSuggestItemLabelResultSchema,\n surveyAssistantTranslateContentResultSchema,\n type SurveyAssistantSuggestResponseNameInput,\n type SurveyAssistantSuggestResponseNameResult,\n type SurveyAssistantSuggestItemLabelInput,\n type SurveyAssistantSuggestItemLabelResult,\n type SurveyAssistantTaskContext,\n type SurveyAssistantTaskInvocationMode,\n type SurveyAssistantTranslateContentInput,\n type SurveyAssistantTranslateContentResult,\n} from \"../protocol\";\nimport { readSurveyAssistantJson } from \"./client-error\";\n\nexport interface SurveyAssistantTaskClientOptions {\n api?: string;\n resourceId?: string;\n surveyId?: string;\n}\n\nexport interface SurveyAssistantTaskExecutionOptions {\n mode?: SurveyAssistantTaskInvocationMode;\n modelId?: string;\n signal?: AbortSignal;\n}\n\nexport interface SurveyAssistantTaskClient {\n suggestResponseSettings(\n input: SurveyAssistantSuggestResponseSettingsInput,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutionOptions,\n ): Promise<SurveyAssistantSuggestResponseSettingsResult>;\n suggestResponseName(\n input: SurveyAssistantSuggestResponseNameInput,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutionOptions,\n ): Promise<SurveyAssistantSuggestResponseNameResult>;\n suggestItemLabel(\n input: SurveyAssistantSuggestItemLabelInput,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutionOptions,\n ): Promise<SurveyAssistantSuggestItemLabelResult>;\n translateContent(\n input: SurveyAssistantTranslateContentInput,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutionOptions,\n ): Promise<SurveyAssistantTranslateContentResult>;\n}\n\nexport const createSurveyAssistantTaskClient = ({\n api = \"/api/survey-assistant/tasks\",\n resourceId,\n surveyId,\n}: SurveyAssistantTaskClientOptions = {}): SurveyAssistantTaskClient => {\n const run = async (\n taskId:\n | \"suggest-response-settings\"\n | \"suggest-response-name\"\n | \"suggest-item-label\"\n | \"translate-content\",\n input: unknown,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutionOptions,\n ) => {\n const modelId = options?.modelId;\n return readSurveyAssistantJson(\n await fetch(api, {\n body: JSON.stringify({\n taskId,\n input,\n context,\n ...(options?.mode ? { mode: options.mode } : {}),\n ...(modelId ? { modelId } : {}),\n ...(resourceId ? { resourceId } : {}),\n ...(surveyId ? { surveyId } : {}),\n }),\n headers: { \"content-type\": \"application/json\" },\n method: \"POST\",\n signal: options?.signal,\n }),\n \"The survey assistant task could not be completed.\",\n );\n };\n\n return {\n async suggestResponseSettings(input, context, options) {\n return surveyAssistantSuggestResponseSettingsResultSchema.parse(\n await run(\"suggest-response-settings\", input, context, options),\n );\n },\n async suggestResponseName(input, context, options) {\n return surveyAssistantSuggestResponseNameResultSchema.parse(\n await run(\"suggest-response-name\", input, context, options),\n );\n },\n async suggestItemLabel(input, context, options) {\n return surveyAssistantSuggestItemLabelResultSchema.parse(\n await run(\"suggest-item-label\", input, context, options),\n );\n },\n async translateContent(input, context, options) {\n return surveyAssistantTranslateContentResultSchema.parse(\n await run(\"translate-content\", input, context, options),\n );\n },\n };\n};\n","import type { SurveyApplyResult, SurveyBatchApplyResult, SurveyChangeSet } from \"../protocol\";\nimport type { SurveyAssistantController } from \"./controller\";\n\nexport interface CreateSurveyAssistantControllerProxyOptions {\n notReadyMessage?: string;\n}\n\nexport interface SurveyAssistantControllerBridge {\n controller: SurveyAssistantController;\n setController(controller: SurveyAssistantController | null | undefined): void;\n}\n\nconst failedResult = (change: SurveyChangeSet, message: string): SurveyApplyResult => ({\n status: \"failed\",\n changeId: change.id,\n summary: change.summary,\n message,\n appliedOperations: 0,\n});\n\nexport const createSurveyAssistantControllerProxy = (\n getController: () => SurveyAssistantController | null | undefined,\n {\n notReadyMessage = \"The survey editor is not ready.\",\n }: CreateSurveyAssistantControllerProxyOptions = {},\n): SurveyAssistantController => ({\n getSnapshot: () => getController()?.getSnapshot() ?? null,\n applyAssistantChanges: (changes): SurveyBatchApplyResult => {\n const controller = getController();\n if (!controller) {\n return { results: changes.map((change) => failedResult(change, notReadyMessage)) };\n }\n return controller.applyAssistantChanges(changes);\n },\n});\n\nexport const createSurveyAssistantControllerBridge = (\n options?: CreateSurveyAssistantControllerProxyOptions,\n): SurveyAssistantControllerBridge => {\n let currentController: SurveyAssistantController | null | undefined;\n return {\n controller: createSurveyAssistantControllerProxy(() => currentController, options),\n setController(controller) {\n currentController = controller;\n },\n };\n};\n"],"mappings":";;AAOA,IAAa,6BAAb,cAAgD,MAAM;CACpD;CACA;CACA;CACA;CACA;CAEA,YACE,MACA,SACA,YAAY,OACZ,cAGI,CAAC,GACL;EACA,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,YAAY;EACjB,KAAK,iBAAiB,YAAY;EAClC,KAAK,oBAAoB,YAAY;EACrC,KAAK,kBAAkB,YAAY;CACrC;AACF;AAEA,MAAa,0BAA0B,OACrC,UACA,WAAW,oDACR;CACH,IAA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