@case-framework/survey-assistant 0.2.2 → 0.3.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 (107) hide show
  1. package/dist/{authoring-references-DYuOAdVx.mjs → authoring-references-yyYC4Ydi.mjs} +9 -3
  2. package/dist/authoring-references-yyYC4Ydi.mjs.map +1 -0
  3. package/dist/{capabilities-DlC1l6qy.d.mts → capabilities-CnsVuJ1k.d.mts} +12 -4
  4. package/dist/capabilities-CnsVuJ1k.d.mts.map +1 -0
  5. package/dist/capabilities-default.d.mts +1 -1
  6. package/dist/capabilities-default.d.mts.map +1 -1
  7. package/dist/capabilities-default.mjs +38 -4
  8. package/dist/capabilities-default.mjs.map +1 -1
  9. package/dist/{constants-D-5m_KGB.d.mts → constants-DrGZXtQf.d.mts} +12 -7
  10. package/dist/constants-DrGZXtQf.d.mts.map +1 -0
  11. package/dist/{controller-proxy-0WJZUZYx.mjs → controller-proxy-CpkQRezb.mjs} +3 -2
  12. package/dist/controller-proxy-CpkQRezb.mjs.map +1 -0
  13. package/dist/{controller-proxy-Hkuub9dt.d.mts → controller-proxy-DmBdzqKs.d.mts} +5 -2
  14. package/dist/controller-proxy-DmBdzqKs.d.mts.map +1 -0
  15. package/dist/{digest-BvXpeWcR.d.mts → digest-Dyjch_sC.d.mts} +2 -2
  16. package/dist/{digest-BvXpeWcR.d.mts.map → digest-Dyjch_sC.d.mts.map} +1 -1
  17. package/dist/digest.d.mts +1 -1
  18. package/dist/{engine-0AJrv0hI.mjs → engine-CWTuN3o2.mjs} +866 -663
  19. package/dist/engine-CWTuN3o2.mjs.map +1 -0
  20. package/dist/engine.d.mts +3 -3
  21. package/dist/engine.mjs +3 -3
  22. package/dist/fair-guidance-CEdJYccK.mjs +21 -0
  23. package/dist/fair-guidance-CEdJYccK.mjs.map +1 -0
  24. package/dist/form-authoring-DCd9XfXf.mjs +155 -0
  25. package/dist/form-authoring-DCd9XfXf.mjs.map +1 -0
  26. package/dist/{index-JXH-t2EJ.d.mts → index-Bo4dHAo8.d.mts} +68 -6
  27. package/dist/index-Bo4dHAo8.d.mts.map +1 -0
  28. package/dist/{index-MEOL9_Gr.d.mts → index-D4OitUg4.d.mts} +5 -430
  29. package/dist/index-D4OitUg4.d.mts.map +1 -0
  30. package/dist/{index-BcyfBeDj.d.mts → index-DZk20e3k.d.mts} +44 -22
  31. package/dist/index-DZk20e3k.d.mts.map +1 -0
  32. package/dist/{index-CneD8ibB.d.mts → index-Dxgg0-D_.d.mts} +12 -3
  33. package/dist/index-Dxgg0-D_.d.mts.map +1 -0
  34. package/dist/lifecycle-DWv5CiSu.d.mts +523 -0
  35. package/dist/lifecycle-DWv5CiSu.d.mts.map +1 -0
  36. package/dist/{memory-thread-repository-1ocPOda8.mjs → memory-thread-repository-acbz6HZJ.mjs} +181 -26
  37. package/dist/memory-thread-repository-acbz6HZJ.mjs.map +1 -0
  38. package/dist/{protocol-DpCYmCjr.mjs → protocol-DATvkr1S.mjs} +125 -6
  39. package/dist/protocol-DATvkr1S.mjs.map +1 -0
  40. package/dist/protocol.d.mts +4 -3
  41. package/dist/protocol.mjs +2 -2
  42. package/dist/{react-DXK5zWNo.mjs → react-Br5YE8H-.mjs} +132 -12
  43. package/dist/react-Br5YE8H-.mjs.map +1 -0
  44. package/dist/react-integration.d.mts +1 -1
  45. package/dist/react-integration.mjs +1 -1
  46. package/dist/react.d.mts +2 -2
  47. package/dist/react.mjs +2 -2
  48. package/dist/references/assistant-operations.md +13 -18
  49. package/dist/references/embedded-forms.md +41 -2
  50. package/dist/references/expressions.md +17 -9
  51. package/dist/references/fair-by-design.md +80 -0
  52. package/dist/references/item-types.md +19 -3
  53. package/dist/references/localization.md +7 -4
  54. package/dist/references/source-material-surveys.md +6 -4
  55. package/dist/{request-context-BBzU3VdG.mjs → request-context-BEjnaaFr.mjs} +10 -5
  56. package/dist/request-context-BEjnaaFr.mjs.map +1 -0
  57. package/dist/server-agent.d.mts +44 -22
  58. package/dist/server-agent.d.mts.map +1 -1
  59. package/dist/server-agent.mjs +71 -14
  60. package/dist/server-agent.mjs.map +1 -1
  61. package/dist/server-runtime.d.mts +22 -11
  62. package/dist/server-runtime.d.mts.map +1 -1
  63. package/dist/server-runtime.mjs +47 -19
  64. package/dist/server-runtime.mjs.map +1 -1
  65. package/dist/server-tasks.d.mts +1 -1
  66. package/dist/server-tasks.mjs +6 -4
  67. package/dist/server-tasks.mjs.map +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 +16 -7
  71. package/dist/server.d.mts.map +1 -1
  72. package/dist/server.mjs +4 -4
  73. package/dist/storage-postgres.d.mts +1 -1
  74. package/dist/{tasks-DcfQNJwO.d.mts → tasks-DQgL449A.d.mts} +8 -4
  75. package/dist/tasks-DQgL449A.d.mts.map +1 -0
  76. package/dist/{thread-documents-BlxNjc7S.d.mts → thread-documents-Dvo6XS7o.d.mts} +1 -1
  77. package/dist/{thread-documents-BlxNjc7S.d.mts.map → thread-documents-Dvo6XS7o.d.mts.map} +1 -1
  78. package/dist/{thread-handlers-uddXwQjp.d.mts → thread-handlers-CeYl45xG.d.mts} +9 -4
  79. package/dist/thread-handlers-CeYl45xG.d.mts.map +1 -0
  80. package/dist/{tools-wgLen05n.mjs → tools-Dg9HZrYU.mjs} +404 -78
  81. package/dist/tools-Dg9HZrYU.mjs.map +1 -0
  82. package/dist/ui.css +2 -2
  83. package/dist/ui.d.mts +94 -10
  84. package/dist/ui.d.mts.map +1 -1
  85. package/dist/ui.mjs +343 -112
  86. package/dist/ui.mjs.map +1 -1
  87. package/docs/integration.md +74 -6
  88. package/package.json +25 -19
  89. package/dist/authoring-references-DYuOAdVx.mjs.map +0 -1
  90. package/dist/capabilities-DKbNCnBf.mjs +0 -66
  91. package/dist/capabilities-DKbNCnBf.mjs.map +0 -1
  92. package/dist/capabilities-DlC1l6qy.d.mts.map +0 -1
  93. package/dist/constants-D-5m_KGB.d.mts.map +0 -1
  94. package/dist/controller-proxy-0WJZUZYx.mjs.map +0 -1
  95. package/dist/controller-proxy-Hkuub9dt.d.mts.map +0 -1
  96. package/dist/engine-0AJrv0hI.mjs.map +0 -1
  97. package/dist/index-BcyfBeDj.d.mts.map +0 -1
  98. package/dist/index-CneD8ibB.d.mts.map +0 -1
  99. package/dist/index-JXH-t2EJ.d.mts.map +0 -1
  100. package/dist/index-MEOL9_Gr.d.mts.map +0 -1
  101. package/dist/memory-thread-repository-1ocPOda8.mjs.map +0 -1
  102. package/dist/protocol-DpCYmCjr.mjs.map +0 -1
  103. package/dist/react-DXK5zWNo.mjs.map +0 -1
  104. package/dist/request-context-BBzU3VdG.mjs.map +0 -1
  105. package/dist/tasks-DcfQNJwO.d.mts.map +0 -1
  106. package/dist/thread-handlers-uddXwQjp.d.mts.map +0 -1
  107. package/dist/tools-wgLen05n.mjs.map +0 -1
@@ -7,7 +7,7 @@ storage credentials, logs, and deployment policy.
7
7
 
8
8
  ## Compatibility and release gate
9
9
 
10
- - Node.js 20 or newer and standard Web `Request`/`Response` route handlers.
10
+ - Node.js 22.13.0 or newer and standard Web `Request`/`Response` route handlers.
11
11
  - React and React DOM 19.2 or newer for `/react` and `/ui`.
12
12
  - `@case-framework/survey-core` 0.4.2 or newer within the 0.4 line; the
13
13
  assistant uses its browser-safe `editor/colors` entry.
@@ -62,10 +62,26 @@ OPENAI_API_KEY=...
62
62
  DATABASE_URL=...
63
63
  ```
64
64
 
65
- One deployment uses one provider. `SURVEY_ASSISTANT_MODEL`,
66
- `SURVEY_ASSISTANT_MODELS`, `SURVEY_ASSISTANT_TASK_MODEL`, and
67
- `SURVEY_ASSISTANT_MEMORY_MODEL` therefore contain bare model or Azure deployment
68
- ids, not `provider/model` strings. Provider-prefixed values fail at startup.
65
+ One deployment uses one provider. For OpenAI, Mistral, and Azure,
66
+ `SURVEY_ASSISTANT_MODEL`, `SURVEY_ASSISTANT_MODELS`, `SURVEY_ASSISTANT_TASK_MODEL`,
67
+ and `SURVEY_ASSISTANT_MEMORY_MODEL` contain bare model or deployment ids, not
68
+ `provider/model` strings. Provider-prefixed values fail at startup.
69
+
70
+ LM Studio is available as an opt-in local development provider through Mastra's
71
+ built-in OpenAI-compatible model configuration. Set an explicit native model id;
72
+ the endpoint defaults to LM Studio's standard local server:
73
+
74
+ ```dotenv
75
+ SURVEY_ASSISTANT_PROVIDER=lmstudio
76
+ SURVEY_ASSISTANT_MODEL=qwen/qwen3.6-27b
77
+ SURVEY_ASSISTANT_MODELS=qwen/qwen3.6-27b,qwen/qwen3.6-35b-a3b
78
+ # SURVEY_ASSISTANT_LMSTUDIO_BASE_URL=http://127.0.0.1:1234/v1
79
+ # SURVEY_ASSISTANT_LMSTUDIO_API_KEY=
80
+ ```
81
+
82
+ LM Studio model ids are passed through verbatim and may contain slashes. The
83
+ configured model list remains the server-owned allowlist; the integration does
84
+ not discover or expose every model loaded in the local server.
69
85
 
70
86
  `SURVEY_ASSISTANT_MODEL` is the default chat model and
71
87
  `SURVEY_ASSISTANT_MODELS` is the server-owned chat picker allowlist. When
@@ -74,6 +90,12 @@ server-authorized chat selection; setting it pins all built-in tasks to that
74
90
  model. The memory model is fixed per runtime and defaults to the configured chat
75
91
  default. It is shared by Mastra's Observer and Reflector.
76
92
 
93
+ The default observational-memory instructions retain user requirements, actual
94
+ completion state, concrete validation/runtime failures, and actionable recovery
95
+ guidance. Unsupported assistant refusals or speculative claims about tool
96
+ availability, payload size, or inability to retry are not promoted into durable
97
+ task constraints.
98
+
77
99
  This same-provider rule applies to the standard runtime. Hosts that genuinely
78
100
  need custom dynamic or cross-provider model routing can compose the exported
79
101
  low-level Agent and handler factories instead.
@@ -82,7 +104,9 @@ Optional operational settings have useful defaults:
82
104
 
83
105
  ```dotenv
84
106
  SURVEY_ASSISTANT_MAX_CONCURRENT_REQUESTS=4
85
- SURVEY_ASSISTANT_MAX_DURATION_MS=180000
107
+ SURVEY_ASSISTANT_FIRST_RESPONSE_TIMEOUT_MS=900000
108
+ SURVEY_ASSISTANT_IDLE_TIMEOUT_MS=300000
109
+ SURVEY_ASSISTANT_MAX_DURATION_MS=3600000
86
110
  SURVEY_ASSISTANT_MAX_STEPS=48
87
111
  SURVEY_ASSISTANT_SEND_REASONING=true
88
112
  SURVEY_ASSISTANT_MEMORY_ENABLED=true
@@ -94,6 +118,36 @@ SURVEY_ASSISTANT_MAX_TOTAL_ATTACHMENT_BYTES=12582912
94
118
  SURVEY_ASSISTANT_MAX_TEXT_PART_CHARS=64000
95
119
  ```
96
120
 
121
+ Chat execution uses three complementary limits. The first-response timeout
122
+ covers model loading and prompt processing until meaningful output begins. The
123
+ idle timeout resets whenever text, reasoning, or tool activity is streamed. The
124
+ maximum duration is a final safety ceiling and does not reset. Client disconnects
125
+ and explicit Stop actions still abort immediately. One-shot tasks are not
126
+ streamed, so they use only the maximum-duration ceiling.
127
+
128
+ Every streamed turn ends with a versioned turn-final part. New turn finals also
129
+ carry authoritative `startedAt`/`durationMs` timing and, for failed or aborted
130
+ turns, a machine-readable `terminationReason`. Hosts should preserve that part
131
+ in history and render its terminal state instead of inferring completion from
132
+ whether an assistant text part exists. Validated `survey_change` results include
133
+ an explicitly bounded `postChange` preview derived from the canonical
134
+ request-scoped draft. It preserves operation order, reports shown/total coverage
135
+ for every bounded collection, and labels shortened text with its full character
136
+ count. The complete draft remains authoritative when the preview omits a target
137
+ or field. Substantial, complex, truncated, or newly regressing changes also
138
+ carry bounded `verification` metadata. The agent must use focused inspection or
139
+ the deterministic audit before claiming those changes are complete; this does
140
+ not lower the global operation limits for legitimate large edits.
141
+
142
+ Model-facing recovery remains registry-derived and explicit. Unknown focused
143
+ reference, operation, or item-type names return bounded canonical suggestions
144
+ without silently accepting an alias. Oversized `survey_inspect` raw-path lists
145
+ are processed in request order with shown/total coverage, while an explicit
146
+ `itemRef` takes precedence over conflicting paths. `survey_audit` retains its
147
+ full structured report for the application but gives the model grouped counts,
148
+ bounded ordered examples, and an explicit reminder that deterministic findings
149
+ do not establish fidelity to an attached source.
150
+
97
151
  Explicit malformed booleans, enums, or positive integers fail at startup.
98
152
  `readinessError` reports missing credentials/storage without exposing them.
99
153
 
@@ -197,6 +251,14 @@ silently discarding a requested approval. Use `"deny"` for read-only
197
251
  deployments. These policies do not remove inspection, chat, tasks, or
198
252
  attachments.
199
253
 
254
+ The client carries the latest unsuccessful post-generation outcome into the
255
+ next request. This lets the model distinguish a server-validated draft from a
256
+ change that was later rejected by the editor, declined during review, or left
257
+ unsettled by the host. Failed, interrupted, and unresolved blocked turns also
258
+ report their bounded prepared-change summaries as discarded and not applied.
259
+ The current editor snapshot remains authoritative; the reported outcome is
260
+ bounded lifecycle evidence, not an authorization input.
261
+
200
262
  ## Attachments
201
263
 
202
264
  Uploads remain enabled by default for PDF, GIF, JPEG, PNG, and WebP. The server
@@ -210,6 +272,12 @@ files and 200 MiB per thread, independently from the stricter per-request
210
272
  defaults. Both storage limits are configurable when constructing the repository
211
273
  or Postgres runtime.
212
274
 
275
+ The attachment tool can include an optional one-based PDF page range and short
276
+ section/question focus. The complete original is still attached and remains
277
+ authoritative; the range is a bounded reading cue, not extracted or cached
278
+ document text. Source-faithful continuation loads the original before browsing
279
+ lossy conversational memory.
280
+
213
281
  For higher-risk deployments, add malware scanning before the route or in a
214
282
  host-owned repository wrapper. Never render attachment bytes as executable
215
283
  HTML, and keep provider/storage retention in the host privacy policy.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@case-framework/survey-assistant",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Shared protocol, engine, and runtime for the CASE survey assistant.",
5
5
  "license": "ISC",
6
6
  "files": [
@@ -90,45 +90,48 @@
90
90
  "clsx": "^2.1.1",
91
91
  "lucide-react": "^1.11.0",
92
92
  "motion": "^12.42.2",
93
- "radix-ui": "^1.6.1",
93
+ "radix-ui": "^1.6.7",
94
94
  "shiki": "^4.3.0",
95
95
  "streamdown": "2.5.0",
96
96
  "tailwind-merge": "^3.5.0",
97
97
  "tw-animate-css": "^1.4.0",
98
98
  "use-stick-to-bottom": "^1.1.6",
99
- "zod": "^4.3.6",
99
+ "zod": "^4.4.3",
100
100
  "@case-framework/ui-localization": "0.2.1"
101
101
  },
102
102
  "devDependencies": {
103
- "@ai-sdk/react": "^4.0.10",
103
+ "@ai-sdk/react": "^4.0.55",
104
104
  "@jest/globals": "30.3.0",
105
- "@mastra/ai-sdk": "^1.6.0",
106
- "@mastra/core": "^1.47.0",
107
- "@mastra/memory": "^1.21.2",
108
- "@mastra/pg": "^1.14.2",
105
+ "@mastra/ai-sdk": "^1.7.1",
106
+ "@mastra/core": "^1.56.0",
107
+ "@mastra/memory": "^1.25.0",
108
+ "@mastra/pg": "^1.19.0",
109
109
  "@tailwindcss/vite": "^4.3.2",
110
110
  "@types/jest": "^30.0.0",
111
111
  "@types/node": "^25.6.0",
112
- "@types/react": "^19.2.14",
113
- "ai": "^7.0.15",
112
+ "@types/react": "^19.2.18",
113
+ "@types/react-test-renderer": "19.1.0",
114
+ "ai": "^7.0.52",
114
115
  "jest": "^30.3.0",
115
- "react": "~19.2.5",
116
+ "react": "~19.2.8",
117
+ "react-dom": "~19.2.8",
118
+ "react-test-renderer": "19.2.8",
116
119
  "ts-jest": "^29.4.9",
117
120
  "tsdown": "^0.21.10",
118
121
  "typescript": "^6.0.3",
119
122
  "vite": "^8.0.10",
120
- "@case-framework/survey-core": "0.6.0"
123
+ "@case-framework/survey-core": "0.6.1"
121
124
  },
122
125
  "peerDependencies": {
123
- "@ai-sdk/react": "^4.0.10",
124
- "@mastra/ai-sdk": "^1.6.0",
125
- "@mastra/core": "^1.47.0",
126
- "@mastra/memory": "^1.21.2",
127
- "@mastra/pg": "^1.14.2",
128
- "ai": "^7.0.15",
126
+ "@ai-sdk/react": "^4.0.55",
127
+ "@mastra/ai-sdk": "^1.7.1",
128
+ "@mastra/core": "^1.56.0",
129
+ "@mastra/memory": "^1.25.0",
130
+ "@mastra/pg": "^1.19.0",
131
+ "ai": "^7.0.52",
129
132
  "react": ">=19.2.0",
130
133
  "react-dom": ">=19.2.0",
131
- "@case-framework/survey-core": "0.6.0"
134
+ "@case-framework/survey-core": "0.6.1"
132
135
  },
133
136
  "peerDependenciesMeta": {
134
137
  "@mastra/ai-sdk": {
@@ -156,6 +159,9 @@
156
159
  "optional": true
157
160
  }
158
161
  },
162
+ "engines": {
163
+ "node": ">=22.13.0"
164
+ },
159
165
  "scripts": {
160
166
  "build": "tsdown && vite build --config vite.ui.config.ts",
161
167
  "test": "jest --config jest.config.cjs --runInBand",
@@ -1 +0,0 @@
1
- {"version":3,"file":"authoring-references-DYuOAdVx.mjs","names":[],"sources":["../../../node_modules/.pnpm/tsdown@0.21.10_synckit@0.11.12_typescript@6.0.3/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 \"source-material-surveys\",\n \"localization\",\n \"rich-text-content\",\n \"item-types\",\n \"embedded-forms\",\n \"expressions\",\n \"assistant-operations\",\n \"survey-quality\",\n] as const;\n\nexport type SurveyAuthoringReferenceTopic = (typeof surveyAuthoringReferenceTopics)[number];\n\nconst ITEM_TYPE_SECTION_HEADINGS: Readonly<Record<string, string>> = {\n group: \"group\",\n \"page-break\": \"page-break\",\n infoItem: \"infoItem\",\n choiceItem: \"choiceItem\",\n formItem: \"formItem\",\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 },\n \"survey-data-model\": {\n title: \"Survey data model\",\n content: loadReference(\"survey-data-model.md\"),\n },\n \"source-material-surveys\": {\n title: \"Source-material survey implementation\",\n content: loadReference(\"source-material-surveys.md\"),\n },\n localization: {\n title: \"Survey localization\",\n content: loadReference(\"localization.md\"),\n },\n \"rich-text-content\": {\n title: \"Rich text content\",\n content: loadReference(\"rich-text-content.md\"),\n },\n \"item-types\": {\n title: \"Item types\",\n content: loadReference(\"item-types.md\"),\n },\n \"embedded-forms\": {\n title: \"Choice option embedded forms\",\n content: loadReference(\"embedded-forms.md\"),\n },\n expressions: {\n title: \"Expressions\",\n content: loadReference(\"expressions.md\"),\n },\n \"assistant-operations\": {\n title: \"Assistant operations\",\n content: loadReference(\"assistant-operations.md\"),\n },\n \"survey-quality\": {\n title: \"Survey quality review\",\n content: loadReference(\"survey-quality.md\"),\n },\n} as const satisfies Record<SurveyAuthoringReferenceTopic, { title: string; content: string }>;\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,OAAO,KAAK,IAAI;AACxD,MAAM,mBAAmB,KAAK,QAAQ,aAAa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C5C;CACF;AAED,MAAa,wCACX,aACmD;CACnD,MAAM,UAAU,2BAA2B;AAC3C,KAAI,CAAC,QACH;CAGF,MAAM,UAAU,uBAAuB,0BAA0B,cAAc,SAAS,QAAQ;AAChG,QAAO,UAAU;EAAE,OAAO,GAAG,QAAQ;EAAa;EAAS,GAAG,KAAA"}
@@ -1,66 +0,0 @@
1
- import { G as assistantItemTypeManifestSchema } from "./protocol-DpCYmCjr.mjs";
2
- import { buildCapabilityDigest } 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
- for (const capability of capabilities) {
9
- const manifest = assistantItemTypeManifestSchema.parse(capability.manifest);
10
- const itemType = manifest.itemType;
11
- if (byItemType.has(itemType)) throw new Error(`Duplicate survey assistant capability for item type "${itemType}".`);
12
- if (manifest.create === "deterministic" && !manifest.supportedOperations.includes("create-item")) throw new Error(`Deterministically creatable item type "${itemType}" must support "create-item".`);
13
- const declaredReferenceTopics = new Set(manifest.referenceTopics ?? []);
14
- 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.`);
15
- byItemType.set(itemType, capability);
16
- }
17
- const manifestWithoutDigest = { itemTypes: Array.from(byItemType.values()).map((capability) => capability.manifest).sort((left, right) => left.itemType.localeCompare(right.itemType)) };
18
- return {
19
- manifest: {
20
- ...manifestWithoutDigest,
21
- digest: buildCapabilityDigest(manifestWithoutDigest)
22
- },
23
- byItemType
24
- };
25
- };
26
- const getDeterministicCreateItemTypes = (manifest) => manifest.itemTypes.filter((entry) => entry.create === "deterministic").map((entry) => entry.itemType);
27
- const resolveAssistantItemCreation = ({ itemType, manifest, parentItemId }) => {
28
- const capability = manifest.itemTypes.find((entry) => entry.itemType === itemType);
29
- if (capability?.create === "deterministic") return { kind: "deterministic" };
30
- if (capability?.create === "interactive-only") return {
31
- kind: "ui-intent",
32
- intent: {
33
- kind: "open-create-item",
34
- itemType,
35
- parentItemId
36
- }
37
- };
38
- return {
39
- kind: "unsupported",
40
- reason: capability ? `Item type "${itemType}" does not support assistant creation.` : `Item type "${itemType}" is not installed.`
41
- };
42
- };
43
- const createUnsupportedItemCapability = ({ displayName, itemType }) => ({ manifest: {
44
- itemType,
45
- capabilityVersion: "unsupported-v1",
46
- displayName,
47
- create: "unsupported",
48
- supportedOperations: [],
49
- contentSurfaces: []
50
- } });
51
- var SurveyAssistantCapabilityMismatchError = class extends Error {
52
- code = "survey-assistant-capability-mismatch";
53
- constructor(message = "Survey assistant capabilities changed; start a fresh turn and retry.") {
54
- super(message);
55
- this.name = "SurveyAssistantCapabilityMismatchError";
56
- }
57
- };
58
- const assertSurveyAssistantCapabilities = ({ manifest, trustedCapabilities, versionDigest }) => {
59
- const { digest: claimedDigest, ...manifestWithoutDigest } = manifest;
60
- if (claimedDigest !== buildCapabilityDigest(manifestWithoutDigest) || versionDigest !== claimedDigest) throw new SurveyAssistantCapabilityMismatchError();
61
- if (trustedCapabilities && trustedCapabilities.manifest.digest !== claimedDigest) throw new SurveyAssistantCapabilityMismatchError("The editor and server use different survey assistant capabilities; refresh and retry.");
62
- };
63
- //#endregion
64
- export { getDeterministicCreateItemTypes as a, resolveAssistantItemCreation as c, createUnsupportedItemCapability as i, assertSurveyAssistantCapabilities as n, inspectAssistantItem as o, createSurveyAssistantCapabilities as r, resolveAssistantCapabilityReference as s, SurveyAssistantCapabilityMismatchError as t };
65
-
66
- //# sourceMappingURL=capabilities-DKbNCnBf.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"capabilities-DKbNCnBf.mjs","names":[],"sources":["../src/engine/capabilities.ts"],"sourcesContent":["import type { RawSurveyItem, ValueType } 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 } 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 references?: AssistantCapabilityReference[];\n normalizeCreate?: (item: RawSurveyItem) => RawSurveyItem;\n validateItem?: (item: RawSurveyItem) => SurveyValidationIssue[];\n supportsOperation?: (operation: SurveyOperation) => boolean;\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 type AssistantItemCreationResolution =\n | { kind: \"deterministic\" }\n | {\n kind: \"ui-intent\";\n intent: { kind: \"open-create-item\"; itemType: string; parentItemId?: string };\n }\n | { kind: \"unsupported\"; reason: string };\n\nexport const createSurveyAssistantCapabilities = (\n capabilities: readonly AssistantItemCapabilityAdapter[],\n): SurveyAssistantCapabilitySet => {\n const byItemType = new Map<string, AssistantItemCapabilityAdapter>();\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 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 }\n\n const itemTypes = Array.from(byItemType.values())\n .map((capability) => capability.manifest)\n .sort((left, right) => left.itemType.localeCompare(right.itemType));\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 resolveAssistantItemCreation = ({\n itemType,\n manifest,\n parentItemId,\n}: {\n itemType: string;\n manifest: SurveyAssistantCapabilityManifest;\n parentItemId?: string;\n}): AssistantItemCreationResolution => {\n const capability = manifest.itemTypes.find((entry) => entry.itemType === itemType);\n if (capability?.create === \"deterministic\") {\n return { kind: \"deterministic\" };\n }\n if (capability?.create === \"interactive-only\") {\n return {\n kind: \"ui-intent\",\n intent: { kind: \"open-create-item\", itemType, parentItemId },\n };\n }\n return {\n kind: \"unsupported\",\n reason: capability\n ? `Item type \"${itemType}\" does not support assistant creation.`\n : `Item type \"${itemType}\" is not installed.`,\n };\n};\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 && trustedCapabilities.manifest.digest !== claimedDigest) {\n throw new SurveyAssistantCapabilityMismatchError(\n \"The editor and server use different survey assistant capabilities; refresh and retry.\",\n );\n }\n};\n"],"mappings":";;;AAqCA,MAAa,uCAAuC,EAClD,cACA,UACA,YAMA,cAAc,WACX,IAAI,SAAS,EACZ,YAAY,MAAM,cAAc,UAAU,UAAU,MAAM;AAEhE,MAAa,wBAAwB,EACnC,cACA,WAKA,cAAc,WAAW,IAAI,KAAK,SAAS,EAAE,cAAc,KAAK;AAUlE,MAAa,qCACX,iBACiC;CACjC,MAAM,6BAAa,IAAI,KAA6C;AAEpE,MAAK,MAAM,cAAc,cAAc;EACrC,MAAM,WAAW,gCAAgC,MAAM,WAAW,SAAS;EAC3E,MAAM,WAAW,SAAS;AAC1B,MAAI,WAAW,IAAI,SAAS,CAC1B,OAAM,IAAI,MAAM,wDAAwD,SAAS,IAAI;AAEvF,MACE,SAAS,WAAW,mB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AAM,QAAQ;AACd,OAAK,OAAO;;;AAIhB,MAAa,qCAAqC,EAChD,UACA,qBACA,oBAKU;CACV,MAAM,EAAE,QAAQ,eAAe,GAAG,0BAA0B;AAE5D,KAAI,kBADmB,sBAAsB,sBACT,IAAI,kBAAkB,cACxD,OAAM,IAAI,wCAAwC;AAGpD,KAAI,uBAAuB,oBAAoB,SAAS,WAAW,cACjE,OAAM,IAAI,uCACR,wFACD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"capabilities-DlC1l6qy.d.mts","names":[],"sources":["../src/protocol/capabilities.ts"],"mappings":";;;cAGa,6BAAA,EAA6B,CAAA,CAAA,OAAA;;;;;cAM7B,6BAAA,EAA6B,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;cAS7B,2BAAA,EAA2B,CAAA,CAAA,SAAA;;;;cAK3B,4BAAA,EAA4B,CAAA,CAAA,SAAA;;;;cAK5B,+BAAA,EAA+B,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAc/B,uCAAA,EAAuC,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAKxC,uBAAA,GAA0B,CAAA,CAAE,KAAA,QAAa,6BAAA;AAAA,KACzC,uBAAA,GAA0B,CAAA,CAAE,KAAA,QAAa,6BAAA;AAAA,KACzC,qBAAA,GAAwB,CAAA,CAAE,KAAA,QAAa,2BAAA;AAAA,KACvC,sBAAA,GAAyB,CAAA,CAAE,KAAA,QAAa,4BAAA;AAAA,KACxC,yBAAA,GAA4B,CAAA,CAAE,KAAA,QAAa,+BAAA;AAAA,KAC3C,iCAAA,GAAoC,CAAA,CAAE,KAAA,QACzC,uCAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants-D-5m_KGB.d.mts","names":[],"sources":["../src/server/request-context.ts","../src/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;EACnB,cAAA,GAAiB,6BAAA;AAAA,MACf,cAAA,CAAe,6BAAA;AAAA,cAoDN,+BAAA,GACX,cAAA,EAAgB,cAAA,CAAe,6BAAA;;;;;;cCnOpB,yBAAA;AAAA,cACA,8BAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"controller-proxy-0WJZUZYx.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 { parseSurveyAssistantError, type SurveyAssistantErrorCode } from \"../protocol\";\n\nexport class SurveyAssistantClientError extends Error {\n readonly code: SurveyAssistantErrorCode;\n\n constructor(code: SurveyAssistantErrorCode, message: string) {\n super(message);\n this.name = \"SurveyAssistantClientError\";\n this.code = code;\n }\n}\n\nexport const readSurveyAssistantJson = async (\n response: Response,\n fallback = \"The assistant request could not be completed.\",\n) => {\n const body = await response.json().catch(() => ({}));\n if (!response.ok) {\n const detail = typeof body?.error === \"string\" ? body.error : fallback;\n const parsed = parseSurveyAssistantError(\n typeof body?.code === \"string\" ? { code: body.code, detail } : detail,\n );\n throw new SurveyAssistantClientError(parsed.code, parsed.detail ?? detail);\n }\n return body;\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 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.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 surveyAssistantSuggestItemKeyResultSchema,\n surveyAssistantSuggestItemLabelResultSchema,\n surveyAssistantTranslateContentResultSchema,\n type SurveyAssistantSuggestItemKeyInput,\n type SurveyAssistantSuggestItemKeyResult,\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 getModelId?: () => string | undefined;\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 suggestItemKey(\n input: SurveyAssistantSuggestItemKeyInput,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutionOptions,\n ): Promise<SurveyAssistantSuggestItemKeyResult>;\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 interface SurveyAssistantTaskExecutorRequestOptions {\n mode?: SurveyAssistantTaskInvocationMode;\n signal?: AbortSignal;\n}\n\nexport interface SurveyAssistantTaskExecutorCacheContext {\n cacheScope?: string;\n}\n\nexport interface SurveyAssistantTaskExecutor {\n suggestItemKey(\n input: SurveyAssistantSuggestItemKeyInput,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutorRequestOptions,\n cache?: SurveyAssistantTaskExecutorCacheContext,\n ): Promise<SurveyAssistantSuggestItemKeyResult>;\n suggestItemLabel(\n input: SurveyAssistantSuggestItemLabelInput,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutorRequestOptions,\n cache?: SurveyAssistantTaskExecutorCacheContext,\n ): Promise<SurveyAssistantSuggestItemLabelResult>;\n translateContent(\n input: SurveyAssistantTranslateContentInput,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutorRequestOptions,\n cache?: SurveyAssistantTaskExecutorCacheContext,\n ): Promise<SurveyAssistantTranslateContentResult>;\n}\n\nexport const createSurveyAssistantTaskClient = ({\n api = \"/api/survey-assistant/tasks\",\n getModelId,\n resourceId,\n surveyId,\n}: SurveyAssistantTaskClientOptions = {}): SurveyAssistantTaskClient => {\n const run = async (\n taskId: \"suggest-item-key\" | \"suggest-item-label\" | \"translate-content\",\n input: unknown,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutionOptions,\n ) => {\n const modelId = options?.modelId ?? getModelId?.();\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 suggestItemKey(input, context, options) {\n return surveyAssistantSuggestItemKeyResultSchema.parse(\n await run(\"suggest-item-key\", 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\nexport const createSurveyAssistantTaskExecutor = (\n options: SurveyAssistantTaskClientOptions = {},\n): SurveyAssistantTaskExecutor => {\n const client = createSurveyAssistantTaskClient(options);\n const executionOptions = (\n request?: SurveyAssistantTaskExecutorRequestOptions,\n cache?: SurveyAssistantTaskExecutorCacheContext,\n ): SurveyAssistantTaskExecutionOptions => ({\n mode: request?.mode,\n modelId: cache?.cacheScope,\n signal: request?.signal,\n });\n\n return {\n suggestItemKey: (input, context, request, cache) =>\n client.suggestItemKey(input, context, executionOptions(request, cache)),\n suggestItemLabel: (input, context, request, cache) =>\n client.suggestItemLabel(input, context, executionOptions(request, cache)),\n translateContent: (input, context, request, cache) =>\n client.translateContent(input, context, executionOptions(request, cache)),\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 applyAssistantChange: (change) =>\n getController()?.applyAssistantChange?.(change) ?? failedResult(change, notReadyMessage),\n applyAssistantChanges: (changes): SurveyBatchApplyResult =>\n getController()?.applyAssistantChanges?.(changes) ?? {\n results: changes.map((change) => failedResult(change, notReadyMessage)),\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":";;AAEA,IAAa,6BAAb,cAAgD,MAAM;CACpD;CAEA,YAAY,MAAgC,SAAiB;AAC3D,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,OAAO;;;AAIhB,MAAa,0BAA0B,OACrC,UACA,WAAW,oDACR;CACH,MAAM,OAAO,MAAM,SAAS,MAAM,CAAC,aAAa,EAAE,EAAE;AACpD,KAAI,CAAC,SAAS,IAAI;EAChB,MAAM,SAAS,OAAO,MAAM,UAAU,WAAW,KAAK,QAAQ;EAC9D,MAAM,SAAS,0BACb,OAAO,MAAM,SAAS,WAAW;GAAE,MAAM,KAAK;GAAM;GAAQ,GAAG,OAChE;AACD,QAAM,IAAI,2BAA2B,OAAO,MAAM,OAAO,UAAU,OAAO;;AAE5E,QAAO;;;;ACiBT,MAAM,iCAAiB,IAAI,SAAuD;AAElF,MAAa,uCACX,UACA,cAEA,YAAY,YACR;CACE,GAAG;CACH,IAAI;EACF,GAAG,SAAS;EACZ,GAAG;EACJ;CACF,GACD;AAEN,MAAM,oBAAoB,aAA4C;CACpE,MAAM,QAAQ,eAAe,IAAI,SAAS;AAC1C,KAAI,CAAC,MACH,OAAM,IAAI,MACR,+FACD;AAEH,QAAO;;AAGT,MAAM,uBAAuB,OAAO,UAAyB;AAC3D,KAAI,MAAM,SAAU;AACpB,OAAM,WAAW;AACjB,KAAI;AACF,SAAO,MAAM,WAAW,MAAM,QAAQ,SAAS,GAAG;GAChD,MAAM,UAAU,MAAM,QAAQ,OAAO;AACrC,OAAI,CAAC,QAAS;AACd,OAAI;AACF,YAAQ,QAAQ,MAAM,MAAM,QAAQ,QAAQ,MA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eAAe,EAAE,uBAAuB,OAAO,IAAI,aAAa,QAAQ,gBAAgB;CAC1F,wBAAwB,YACtB,eAAe,EAAE,wBAAwB,QAAQ,IAAI,EACnD,SAAS,QAAQ,KAAK,WAAW,aAAa,QAAQ,gBAAgB,CAAC,EACxE;CACJ;AAED,MAAa,yCACX,YACoC;CACpC,IAAI;AACJ,QAAO;EACL,YAAY,2CAA2C,mBAAmB,QAAQ;EAClF,cAAc,YAAY;AACxB,uBAAoB;;EAEvB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"controller-proxy-Hkuub9dt.d.mts","names":[],"sources":["../src/react/thread-launcher.ts","../src/react/task-client.ts","../src/react/controller.ts","../src/react/controller-proxy.ts"],"mappings":";;;;KAOY,8BAAA,GAAiC,OAAA,CAAQ,IAAA,CAAK,qBAAA;AAAA,UAEzC,2BAAA;EAFL;EAIV,MAAA;EACA,KAAA,GAAQ,UAAA;EALgD;EAOxD,KAAA;EAP2C;EAS3C,SAAA,GAAY,8BAAA;AAAA;AAAA,UAGG,6BAAA;EAZoC;;;;EAiBnD,WAAA,CAAY,KAAA,EAAO,2BAAA,GAA8B,OAAA,CAAQ,qBAAA;AAAA;AAAA,cA6D9C,mCAAA,QAA0C,6BAAA;;;UCtEtC,gCAAA;EACf,GAAA;EACA,UAAA;EACA,UAAA;EACA,QAAA;AAAA;AAAA,UAGe,mCAAA;EACf,IAAA,GAAO,iCAAA;EACP,OAAA;EACA,MAAA,GAAS,WAAA;AAAA;AAAA,UAGM,yBAAA;EACf,cAAA,CACE,KAAA,EAAO,kCAAA,EACP,OAAA,EAAS,0BAAA,EACT,OAAA,GAAU,mCAAA,GACT,OAAA,CAAQ,mCAAA;EACX,gBAAA,CACE,KAAA,EAAO,oCAAA,EACP,OAAA,EAAS,0BAAA,EACT,OAAA,GAAU,mCAAA,GACT,OAAA,CAAQ,qCAAA;EACX,gBAAA,CACE,KAAA,EAAO,oCAAA,EACP,OAAA,EAAS,0BAAA,EACT,OAAA,GAAU,mCA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