@case-framework/survey-assistant 0.6.0 → 0.7.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.
- package/README.md +9 -4
- package/dist/{authoring-references-CW38pYzK.mjs → authoring-references-BJQ_1nMX.mjs} +2 -2
- package/dist/authoring-references-BJQ_1nMX.mjs.map +1 -0
- package/dist/capabilities-1KNnNO1_.mjs +73 -0
- package/dist/capabilities-1KNnNO1_.mjs.map +1 -0
- package/dist/capabilities-default.d.mts +1 -1
- package/dist/capabilities-default.d.mts.map +1 -1
- package/dist/capabilities-default.mjs +22 -25
- package/dist/capabilities-default.mjs.map +1 -1
- package/dist/{constants-BMGTgfjv.d.mts → constants-Be91Gay9.d.mts} +3 -3
- package/dist/{constants-BMGTgfjv.d.mts.map → constants-Be91Gay9.d.mts.map} +1 -1
- package/dist/{controller-proxy-DMTqer6T.mjs → controller-proxy-BH05e-C2.mjs} +21 -8
- package/dist/controller-proxy-BH05e-C2.mjs.map +1 -0
- package/dist/{controller-proxy-mRvez2qw.d.mts → controller-proxy-Bd0ZHBPF.d.mts} +11 -11
- package/dist/controller-proxy-Bd0ZHBPF.d.mts.map +1 -0
- package/dist/{engine-CQwOAcwK.mjs → engine-Bo85Oyj0.mjs} +2985 -2347
- package/dist/engine-Bo85Oyj0.mjs.map +1 -0
- package/dist/engine.d.mts +2 -2
- package/dist/engine.mjs +3 -3
- package/dist/{index-D6nqkz0O.d.mts → index-Tnqv-yKW.d.mts} +56 -71
- package/dist/index-Tnqv-yKW.d.mts.map +1 -0
- package/dist/index-l_EK4yK7.d.mts +404 -0
- package/dist/index-l_EK4yK7.d.mts.map +1 -0
- package/dist/{index-DvTqML-0.d.mts → index-nhrgbgO5.d.mts} +19 -5
- package/dist/index-nhrgbgO5.d.mts.map +1 -0
- package/dist/{index-B0lxsAzx.d.mts → index-x0qprHgK.d.mts} +19 -7
- package/dist/index-x0qprHgK.d.mts.map +1 -0
- package/dist/{lifecycle-BmGAIUlv.d.mts → lifecycle-Bx0aq_4S.d.mts} +7 -1
- package/dist/{lifecycle-BmGAIUlv.d.mts.map → lifecycle-Bx0aq_4S.d.mts.map} +1 -1
- package/dist/{memory-thread-repository-CjFGVNZh.mjs → memory-thread-repository-KWHQWFEW.mjs} +43 -12
- package/dist/memory-thread-repository-KWHQWFEW.mjs.map +1 -0
- package/dist/{protocol-DJUP4gc0.mjs → protocol-BhzQbx81.mjs} +66 -16
- package/dist/protocol-BhzQbx81.mjs.map +1 -0
- package/dist/protocol.d.mts +3 -3
- package/dist/protocol.mjs +2 -2
- package/dist/react-B3ybjJ-X.mjs +1620 -0
- package/dist/react-B3ybjJ-X.mjs.map +1 -0
- package/dist/react-integration.d.mts +1 -1
- package/dist/react-integration.mjs +1 -1
- package/dist/react.d.mts +3 -3
- package/dist/react.mjs +3 -3
- package/dist/references/assistant-operations.md +45 -39
- package/dist/references/expressions.md +28 -0
- package/dist/references/item-types.md +1 -1
- package/dist/references/localization.md +5 -4
- package/dist/references/rich-text-content.md +60 -27
- package/dist/references/source-material-surveys.md +9 -2
- package/dist/references/survey-data-model.md +9 -1
- package/dist/{request-context-BjTHNcDd.mjs → request-context-CG4SWijt.mjs} +3 -3
- package/dist/{request-context-BjTHNcDd.mjs.map → request-context-CG4SWijt.mjs.map} +1 -1
- package/dist/server-agent.d.mts +19 -8
- package/dist/server-agent.d.mts.map +1 -1
- package/dist/server-agent.mjs +7 -11
- package/dist/server-agent.mjs.map +1 -1
- package/dist/server-runtime.d.mts +19 -13
- package/dist/server-runtime.d.mts.map +1 -1
- package/dist/server-runtime.mjs +7 -2
- package/dist/server-runtime.mjs.map +1 -1
- package/dist/server-tasks.d.mts +1 -1
- package/dist/server-tasks.mjs +2 -2
- package/dist/server-tools.d.mts +1 -1
- package/dist/server-tools.mjs +1 -1
- package/dist/server.d.mts +5 -5
- package/dist/server.mjs +3 -3
- package/dist/{tasks-DxzD25Zc.d.mts → tasks-CYqrcaRO.d.mts} +4 -4
- package/dist/{tasks-DxzD25Zc.d.mts.map → tasks-CYqrcaRO.d.mts.map} +1 -1
- package/dist/{thread-handlers-AbQbt4sX.d.mts → thread-handlers-DBAaU7BA.d.mts} +6 -4
- package/dist/thread-handlers-DBAaU7BA.d.mts.map +1 -0
- package/dist/{tools-CFh35R4d.mjs → tools-BvSovehT.mjs} +431 -495
- package/dist/tools-BvSovehT.mjs.map +1 -0
- package/dist/ui.css +1 -1
- package/dist/ui.d.mts +5 -4
- package/dist/ui.d.mts.map +1 -1
- package/dist/ui.mjs +619 -66
- package/dist/ui.mjs.map +1 -1
- package/docs/integration.md +40 -0
- package/package.json +21 -19
- package/dist/authoring-references-CW38pYzK.mjs.map +0 -1
- package/dist/controller-proxy-DMTqer6T.mjs.map +0 -1
- package/dist/controller-proxy-mRvez2qw.d.mts.map +0 -1
- package/dist/engine-CQwOAcwK.mjs.map +0 -1
- package/dist/form-authoring-kQDgC5oz.mjs +0 -155
- package/dist/form-authoring-kQDgC5oz.mjs.map +0 -1
- package/dist/index-B0lxsAzx.d.mts.map +0 -1
- package/dist/index-BS-Xjk1h.d.mts +0 -224
- package/dist/index-BS-Xjk1h.d.mts.map +0 -1
- package/dist/index-D6nqkz0O.d.mts.map +0 -1
- package/dist/index-DvTqML-0.d.mts.map +0 -1
- package/dist/memory-thread-repository-CjFGVNZh.mjs.map +0 -1
- package/dist/protocol-DJUP4gc0.mjs.map +0 -1
- package/dist/react-Dqlmasrs.mjs +0 -768
- package/dist/react-Dqlmasrs.mjs.map +0 -1
- package/dist/thread-handlers-AbQbt4sX.d.mts.map +0 -1
- package/dist/tools-CFh35R4d.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -188,7 +188,8 @@ metadata.
|
|
|
188
188
|
`/protocol`, `/engine`, and `/capabilities/default` may not import React,
|
|
189
189
|
Next.js, Mastra, AI SDK, `survey-ui`, or Node-only storage. `/protocol` has Zod
|
|
190
190
|
plus the narrow browser-safe `survey-core/editor/colors` runtime dependency;
|
|
191
|
-
`/engine` may use the
|
|
191
|
+
`/engine` and `/capabilities/default` may use the headless `survey-items`
|
|
192
|
+
domain and the full `survey-core` API. `/server` is
|
|
192
193
|
server-only and may import Mastra, AI SDK, and Node APIs, but never React,
|
|
193
194
|
Next.js, or `survey-ui`. The separate server entries prevent handler-only
|
|
194
195
|
consumers from eagerly loading Agent/Memory code. `@case-framework/survey-editor-ui`
|
|
@@ -253,13 +254,17 @@ received from a browser snapshot.
|
|
|
253
254
|
```bash
|
|
254
255
|
pnpm --filter @case-framework/survey-assistant check
|
|
255
256
|
pnpm --filter @case-framework/survey-assistant check:release
|
|
257
|
+
pnpm benchmark:survey-assistant-operations
|
|
256
258
|
```
|
|
257
259
|
|
|
258
260
|
`check` typechecks and builds all entries, copies server references, verifies
|
|
259
261
|
their source and built import graphs, and runs unit tests. `check:release` also
|
|
260
|
-
builds the clean Next host fixture.
|
|
261
|
-
|
|
262
|
-
|
|
262
|
+
builds the clean Next host fixture. `benchmark:survey-assistant-operations`
|
|
263
|
+
uses the current built engine output to profile maximum-size typed validation
|
|
264
|
+
and the raw-patch path against a synthetic 5,002-item survey; run `build` first
|
|
265
|
+
when source has changed. The optional Postgres entry accepts a host-owned
|
|
266
|
+
`PostgresStore` or store configuration; it does not read environment variables,
|
|
267
|
+
create hidden singletons, or own connection shutdown.
|
|
263
268
|
|
|
264
269
|
## Integration Levels
|
|
265
270
|
|
|
@@ -51,7 +51,7 @@ const surveyAuthoringReferences = {
|
|
|
51
51
|
"source-material-surveys": {
|
|
52
52
|
title: "Source-material survey implementation",
|
|
53
53
|
content: loadReference("source-material-surveys.md"),
|
|
54
|
-
loadWhen: "Load before implementing or adapting a questionnaire, document, image, or other supplied source material so completeness, respondent-input mapping, language, and digital adaptation rules are available before the first mutation."
|
|
54
|
+
loadWhen: "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."
|
|
55
55
|
},
|
|
56
56
|
localization: {
|
|
57
57
|
title: "Survey localization",
|
|
@@ -112,4 +112,4 @@ const getBuiltInItemTypeAuthoringReference = (itemType) => {
|
|
|
112
112
|
//#endregion
|
|
113
113
|
export { surveyAuthoringReferences as a, surveyAuthoringReferenceTopics as i, formatSurveyAuthoringReferenceRoutingInstructions as n, getBuiltInItemTypeAuthoringReference as r, builtInSurveyAuthoringItemTypes as t };
|
|
114
114
|
|
|
115
|
-
//# sourceMappingURL=authoring-references-
|
|
115
|
+
//# sourceMappingURL=authoring-references-BJQ_1nMX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authoring-references-BJQ_1nMX.mjs","names":[],"sources":["../../../node_modules/.pnpm/tsdown@0.21.10_synckit@0.11.13_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 \"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 choiceItem: \"choiceItem\",\n formItem: \"formItem\",\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 \"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,OAAO,KAAK,IAAI;AACxD,MAAM,mBAAmB,KAAK,QAAQ,aAAa,CAAC;AAEpD,MAAa,YAA4B,4BAAY;;;ACJrD,MAAM,iBAAiB,aACrB,aAAa,QAAQ,WAAW,cAAc,SAAS,EAAE,OAAO,CAAC,MAAM;AAEzE,MAAa,iCAAiC;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAUD,MAAM,6BAA+D;CACnE,OAAO;CACP,cAAc;CACd,UAAU;CACV,YAAY;CACZ,UAAU;CACX;AAED,MAAa,kCAAkC,OAAO,OACpD,OAAO,KAAK,2BAA2B,CACxC;AAED,MAAM,0BAA0B,UAAkB,YAAwC;CACxF,MAAM,QAAQ,SAAS,MAAM,KAAK;CAClC,MAAM,eAAe,MAAM,WAAW,SAAS,KAAK,MAAM,KAAK,MAAM,UAAU;AAC/E,KAAI,eAAe,EACjB;CAGF,MAAM,oBAAoB,MACvB,MAAM,eAAe,EAAE,CACvB,WAAW,SAAS,KAAK,WAAW,MAAM,CAAC;CAC9C,MAAM,aAAa,oBAAoB,IAAI,MAAM,SAAS,eAAe,IAAI;AAE7E,QAAO,MAAM,MAAM,cAAc,WAAW,CAAC,KAAK,KAAK,CAAC,MAAM;;AAGhE,MAAa,4BAA4B;CACvC,cAAc;EACZ,OAAO;EACP,SAAS,cAAc,gBAAgB;EACvC,UACE;EACH;CACD,qBAAqB;EACnB,OAAO;EACP,SAAS,cAAc,uBAAuB;EAC9C,UACE;EACH;CACD,2BAA2B;EACzB,OAAO;EACP,SAAS,cAAc,6BAA6B;EACpD,UACE;EACH;CACD,cAAc;EACZ,OAAO;EACP,SAAS,cAAc,kBAAkB;EACzC,UACE;EACH;CACD,qBAAqB;EACnB,OAAO;EACP,SAAS,cAAc,uBAAuB;EAC9C,UACE;EACH;CACD,cAAc;EACZ,OAAO;EACP,SAAS,cAAc,gBAAgB;EACvC,UACE;EACH;CACD,kBAAkB;EAChB,OAAO;EACP,SAAS,cAAc,oBAAoB;EAC3C,UACE;EACH;CACD,aAAa;EACX,OAAO;EACP,SAAS,cAAc,iBAAiB;EACxC,UACE;EACH;CACD,wBAAwB;EACtB,OAAO;EACP,SAAS,cAAc,0BAA0B;EACjD,UACE;EACH;CACD,kBAAkB;EAChB,OAAO;EACP,SAAS,cAAc,oBAAoB;EAC3C,UACE;EACH;CACD,kBAAkB;EAChB,OAAO;EACP,SAAS,cAAc,oBAAoB;EAC3C,UACE;EACH;CACF;AAED,MAAa,0DACX;CACE;CACA;CACA;CACA,GAAG,+BAA+B,KAC/B,UAAU,KAAK,MAAM,IAAI,0BAA0B,OAAO,WAC5D;CACF,CAAC,KAAK,KAAK;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"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { q as assistantItemTypeManifestSchema } from "./protocol-BhzQbx81.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
|
+
const declaredReferenceTopics = new Set(manifest.referenceTopics ?? []);
|
|
15
|
+
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.`);
|
|
16
|
+
byItemType.set(itemType, capability);
|
|
17
|
+
normalizedManifests.push(assistantItemTypeManifestSchema.parse(JSON.parse(JSON.stringify(manifest))));
|
|
18
|
+
}
|
|
19
|
+
const manifestWithoutDigest = { itemTypes: normalizedManifests.sort((left, right) => left.itemType.localeCompare(right.itemType)) };
|
|
20
|
+
return {
|
|
21
|
+
manifest: {
|
|
22
|
+
...manifestWithoutDigest,
|
|
23
|
+
digest: buildCapabilityDigest(manifestWithoutDigest)
|
|
24
|
+
},
|
|
25
|
+
byItemType
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const getDeterministicCreateItemTypes = (manifest) => manifest.itemTypes.filter((entry) => entry.create === "deterministic").map((entry) => entry.itemType);
|
|
29
|
+
const resolveAssistantItemCreation = ({ itemType, manifest, parentItemId }) => {
|
|
30
|
+
const capability = manifest.itemTypes.find((entry) => entry.itemType === itemType);
|
|
31
|
+
if (capability?.create === "deterministic") return { kind: "deterministic" };
|
|
32
|
+
if (capability?.create === "interactive-only") return {
|
|
33
|
+
kind: "ui-intent",
|
|
34
|
+
intent: {
|
|
35
|
+
kind: "open-create-item",
|
|
36
|
+
itemType,
|
|
37
|
+
parentItemId
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
kind: "unsupported",
|
|
42
|
+
reason: capability ? `Item type "${itemType}" does not support assistant creation.` : `Item type "${itemType}" is not installed.`
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const createUnsupportedItemCapability = ({ displayName, itemType }) => ({ manifest: {
|
|
46
|
+
itemType,
|
|
47
|
+
capabilityVersion: "unsupported-v1",
|
|
48
|
+
displayName,
|
|
49
|
+
create: "unsupported",
|
|
50
|
+
supportedOperations: [],
|
|
51
|
+
contentSurfaces: []
|
|
52
|
+
} });
|
|
53
|
+
var SurveyAssistantCapabilityMismatchError = class extends Error {
|
|
54
|
+
code = "survey-assistant-capability-mismatch";
|
|
55
|
+
constructor(message = "Survey assistant capabilities changed; start a fresh turn and retry.") {
|
|
56
|
+
super(message);
|
|
57
|
+
this.name = "SurveyAssistantCapabilityMismatchError";
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const assertSurveyAssistantCapabilities = ({ manifest, trustedCapabilities, versionDigest }) => {
|
|
61
|
+
const { digest: claimedDigest, ...manifestWithoutDigest } = manifest;
|
|
62
|
+
if (claimedDigest !== buildCapabilityDigest(manifestWithoutDigest) || versionDigest !== claimedDigest) throw new SurveyAssistantCapabilityMismatchError();
|
|
63
|
+
if (trustedCapabilities) {
|
|
64
|
+
const withoutContextualPresets = ({ creationPresets: _creationPresets, ...capability }) => capability;
|
|
65
|
+
const claimedBaseCapabilities = manifest.itemTypes.map(withoutContextualPresets);
|
|
66
|
+
const trustedBaseCapabilities = trustedCapabilities.manifest.itemTypes.map(withoutContextualPresets);
|
|
67
|
+
if (stableStringify(claimedBaseCapabilities) !== stableStringify(trustedBaseCapabilities)) throw new SurveyAssistantCapabilityMismatchError("The editor and server use different survey assistant capabilities; refresh and retry.");
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
//#endregion
|
|
71
|
+
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 };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=capabilities-1KNnNO1_.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities-1KNnNO1_.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, 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 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 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 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 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) {\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":";;;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;CACpE,MAAM,sBAAmD,EAAE;AAE3D,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,mBACpB,CAAC,SAAS,oBAAoB,SAAS,cAAc,CAErD,OAAM,IAAI,MACR,0CAA0C,SAAS,+BACpD;EAEH,MAAM,0BAA0B,IAAI,IAAI,SAAS,mBAAmB,EAAE,CAAC;AACvE,OAAK,MAAM,aAAa,WAAW,cAAc,EAAE,CACjD,KAAI,CAAC,wBAAwB,IAAI,UAAU,MAAM,CAC/C,OAAM,IAAI,MACR,yBAAyB,UA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EAChC,iBAAiB,kBACjB,GAAG,iBACgF;EACrF,MAAM,0BAA0B,SAAS,UAAU,IAAI,yBAAyB;EAChF,MAAM,0BACJ,oBAAoB,SAAS,UAAU,IAAI,yBAAyB;AAKtE,MAAI,gBAAgB,wBAAwB,KAAK,gBAAgB,wBAAwB,CACvF,OAAM,IAAI,uCACR,wFACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ut as AssistantItemCapabilityAdapter, qt as SurveyAssistantCapabilitySet } from "./index-Tnqv-yKW.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/capabilities/default.d.ts
|
|
4
4
|
declare const rootItemAssistantCapability: AssistantItemCapabilityAdapter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities-default.d.mts","names":[],"sources":["../src/capabilities/default.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"capabilities-default.d.mts","names":[],"sources":["../src/capabilities/default.ts"],"mappings":";;;cAoNa,2BAAA,EAA6B,8BAAA;AAAA,cAY7B,4BAAA,EAA8B,8BAAA;AAAA,cAsB9B,gCAAA,EAAkC,8BAAA;AAAA,cAsBlC,2BAAA,EAA6B,8BAAA;AAAA,cA6B7B,6BAAA,EAA+B,8BAAA;AAAA,cAyF/B,2BAAA,EAA6B,8BAAA;AAAA,cA2D7B,kCAAA,YAAkC,8BAAA,EAAA,8BAAA,EAAA,8BAAA,EAAA,8BAAA,EAAA,8BAAA,EAAA,8BAAA;AAAA,cASlC,mCAAA,EAEZ,4BAAA;AAAA,cAEY,mCAAA,GACX,QAAA,aACC,8BAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { r as createSurveyAssistantCapabilities } from "./capabilities-1KNnNO1_.mjs";
|
|
2
|
+
import { createFormItemConfig, getFormFieldValueType, isValidSimpleFormConfig, normalizeFormAuthoringConfig } from "@case-framework/survey-items/form";
|
|
3
|
+
import { createChoiceItemConfig, getChoiceOptionEmbeddedFormResponseSlotPrefix, getChoiceResponseValueType } from "@case-framework/survey-items/choice";
|
|
3
4
|
//#region src/capabilities/default.ts
|
|
4
5
|
const COMMON_OPERATIONS = [
|
|
5
6
|
"create-item",
|
|
@@ -91,33 +92,29 @@ const materializeGroupCreate = (item) => withMaterializedConfig(item, {
|
|
|
91
92
|
shuffleItems: false
|
|
92
93
|
});
|
|
93
94
|
const materializeEmptyConfigCreate = (item) => withMaterializedConfig(item, {});
|
|
94
|
-
const materializeChoiceCreate = (item) =>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
95
|
+
const materializeChoiceCreate = (item) => {
|
|
96
|
+
const config = isRecord(item.config) ? item.config : {};
|
|
97
|
+
const defaults = createChoiceItemConfig(item.id);
|
|
98
|
+
return normalizeEmbeddedFormAuthoringModes({
|
|
99
|
+
...item,
|
|
100
|
+
config: {
|
|
101
|
+
...defaults,
|
|
102
|
+
...config,
|
|
103
|
+
id: item.id,
|
|
104
|
+
maxSelection: "maxSelection" in config ? config.maxSelection : defaults.maxSelection,
|
|
105
|
+
shuffleOptions: "shuffleOptions" in config ? config.shuffleOptions : defaults.shuffleOptions,
|
|
106
|
+
options: Array.isArray(config.options) ? config.options : defaults.options
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
104
110
|
const materializeFormCreate = (item) => ({
|
|
105
111
|
...item,
|
|
106
112
|
config: normalizeFormAuthoringConfig({
|
|
107
|
-
|
|
113
|
+
...createFormItemConfig(item.id),
|
|
108
114
|
...isRecord(item.config) ? item.config : {},
|
|
109
115
|
id: item.id
|
|
110
116
|
})
|
|
111
117
|
});
|
|
112
|
-
const getFieldValueType = (field) => {
|
|
113
|
-
switch (field.type) {
|
|
114
|
-
case "number":
|
|
115
|
-
case "slider": return ValueType.number;
|
|
116
|
-
case "datepicker": return ValueType.date;
|
|
117
|
-
case "switch": return ValueType.boolean;
|
|
118
|
-
default: return ValueType.string;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
118
|
const deriveFormResponseSlots = (config, prefix) => {
|
|
122
119
|
if (!isRecord(config) || !Array.isArray(config.fieldGroups)) return {};
|
|
123
120
|
const slots = {};
|
|
@@ -125,17 +122,17 @@ const deriveFormResponseSlots = (config, prefix) => {
|
|
|
125
122
|
if (!Array.isArray(group.fields)) continue;
|
|
126
123
|
for (const field of group.fields.filter(isRecord)) {
|
|
127
124
|
if (typeof field.key !== "string" || field.key.length === 0) continue;
|
|
128
|
-
slots[prefix ? `${prefix}.${field.key}` : field.key] =
|
|
125
|
+
slots[prefix ? `${prefix}.${field.key}` : field.key] = getFormFieldValueType(field);
|
|
129
126
|
}
|
|
130
127
|
}
|
|
131
128
|
return slots;
|
|
132
129
|
};
|
|
133
130
|
const deriveChoiceResponseSlots = (item) => {
|
|
134
131
|
const config = isRecord(item.config) ? item.config : {};
|
|
135
|
-
const slots = { [typeof config.id === "string" && config.id.length > 0 ? config.id : item.id]: config.maxSelection === 1 ?
|
|
132
|
+
const slots = { [typeof config.id === "string" && config.id.length > 0 ? config.id : item.id]: getChoiceResponseValueType(config.maxSelection === 1 ? 1 : null) };
|
|
136
133
|
if (Array.isArray(config.options)) for (const option of config.options.filter(isRecord)) {
|
|
137
134
|
if (typeof option.id !== "string" || !option.embeddedForm) continue;
|
|
138
|
-
Object.assign(slots, deriveFormResponseSlots(option.embeddedForm,
|
|
135
|
+
Object.assign(slots, deriveFormResponseSlots(option.embeddedForm, getChoiceOptionEmbeddedFormResponseSlotPrefix(option.id)));
|
|
139
136
|
}
|
|
140
137
|
return slots;
|
|
141
138
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities-default.mjs","names":[],"sources":["../src/capabilities/default.ts"],"sourcesContent":["import type { AssistantContentSurface, AssistantItemTypeManifest } from \"../protocol\";\nimport { ValueType, type RawSurveyItem } from \"@case-framework/survey-core\";\nimport {\n createSurveyAssistantCapabilities,\n type AssistantItemCapabilityAdapter,\n} from \"../engine/capabilities\";\nimport { isValidSimpleFormConfig, normalizeFormAuthoringConfig } from \"../engine/form-authoring\";\n\nconst COMMON_OPERATIONS = [\n \"create-item\",\n \"update-item-key\",\n \"update-item-label\",\n \"update-item-color\",\n \"update-item-translation\",\n \"update-placed-image\",\n \"patch-item-config\",\n \"remove-item\",\n \"move-item\",\n \"survey-json-patch\",\n] satisfies AssistantItemTypeManifest[\"supportedOperations\"];\n\nconst QUESTION_CONTENT_SURFACES: AssistantContentSurface[] = [\n {\n key: \"title\",\n role: \"primary\",\n format: \"rich\",\n requiredOnCreate: true,\n aliases: [\"content\", \"label\", \"prompt\", \"question\", \"text\"],\n },\n {\n key: \"subtitle\",\n role: \"secondary\",\n format: \"rich\",\n aliases: [\"subheading\", \"subtext\"],\n },\n {\n key: \"topContent\",\n role: \"secondary\",\n format: \"rich\",\n aliases: [\"preContent\", \"preResponse\"],\n },\n {\n key: \"bottomContent\",\n role: \"secondary\",\n format: \"rich\",\n aliases: [\"postContent\", \"postResponse\"],\n },\n {\n key: \"cardFooter\",\n role: \"secondary\",\n format: \"rich\",\n aliases: [\"footer\"],\n },\n];\n\nconst FIELD_CONTENT_SURFACES: AssistantContentSurface[] = [\n \"label\",\n \"description\",\n \"error\",\n \"placeholder\",\n \"unit\",\n \"checkedLabel\",\n \"uncheckedLabel\",\n].map((key) => ({\n key: `fields.<fieldId>.${key}`,\n role: key === \"error\" ? \"validation\" : \"field\",\n format: \"rich\",\n pattern: true,\n}));\n\nconst createManifest = (\n manifest: Omit<AssistantItemTypeManifest, \"capabilityVersion\">,\n): AssistantItemTypeManifest => ({ capabilityVersion: \"1\", ...manifest });\n\nconst STRUCTURE_REFERENCE = {\n topic: \"item-types\",\n markdown:\n \"Groups are containers. Create a group without child ids, then create or move children through separate operations. Page breaks are standalone structural boundaries.\",\n};\nconst QUESTION_REFERENCE = {\n topic: \"item-types\",\n markdown:\n \"Question titles and supporting text are translations. Configuration stores response behavior; respondent-visible option and field labels use the declared dynamic content surfaces.\",\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst withMaterializedConfig = (\n item: RawSurveyItem,\n defaults: Record<string, unknown>,\n): RawSurveyItem => ({\n ...item,\n config: {\n ...defaults,\n ...(isRecord(item.config) ? item.config : {}),\n },\n});\n\nconst materializeGroupCreate = (item: RawSurveyItem): RawSurveyItem =>\n withMaterializedConfig(item, { items: [], shuffleItems: false });\n\nconst materializeEmptyConfigCreate = (item: RawSurveyItem): RawSurveyItem =>\n withMaterializedConfig(item, {});\n\nconst materializeChoiceCreate = (item: RawSurveyItem): RawSurveyItem =>\n normalizeEmbeddedFormAuthoringModes({\n ...item,\n config: {\n ...(isRecord(item.config) ? item.config : {}),\n id: item.id,\n maxSelection:\n isRecord(item.config) && \"maxSelection\" in item.config ? item.config.maxSelection : 1,\n shuffleOptions:\n isRecord(item.config) && \"shuffleOptions\" in item.config\n ? item.config.shuffleOptions\n : false,\n options:\n isRecord(item.config) && Array.isArray(item.config.options) ? item.config.options : [],\n },\n });\n\nconst materializeFormCreate = (item: RawSurveyItem): RawSurveyItem => ({\n ...item,\n config: normalizeFormAuthoringConfig({\n fieldGroups: [],\n ...(isRecord(item.config) ? item.config : {}),\n id: item.id,\n }),\n});\n\nconst getFieldValueType = (field: Record<string, unknown>): ValueType => {\n switch (field.type) {\n case \"number\":\n case \"slider\":\n return ValueType.number;\n case \"datepicker\":\n return ValueType.date;\n case \"switch\":\n return ValueType.boolean;\n default:\n return ValueType.string;\n }\n};\n\nconst deriveFormResponseSlots = (config: unknown, prefix?: string): Record<string, ValueType> => {\n if (!isRecord(config) || !Array.isArray(config.fieldGroups)) {\n return {};\n }\n\n const slots: Record<string, ValueType> = {};\n for (const group of config.fieldGroups.filter(isRecord)) {\n if (!Array.isArray(group.fields)) continue;\n for (const field of group.fields.filter(isRecord)) {\n if (typeof field.key !== \"string\" || field.key.length === 0) continue;\n slots[prefix ? `${prefix}.${field.key}` : field.key] = getFieldValueType(field);\n }\n }\n return slots;\n};\n\nconst deriveChoiceResponseSlots = (item: RawSurveyItem): Record<string, ValueType> => {\n const config = isRecord(item.config) ? item.config : {};\n const responseId = typeof config.id === \"string\" && config.id.length > 0 ? config.id : item.id;\n const slots: Record<string, ValueType> = {\n [responseId]: config.maxSelection === 1 ? ValueType.reference : ValueType.referenceArray,\n };\n\n if (Array.isArray(config.options)) {\n for (const option of config.options.filter(isRecord)) {\n if (typeof option.id !== \"string\" || !option.embeddedForm) continue;\n Object.assign(slots, deriveFormResponseSlots(option.embeddedForm, `embedded.${option.id}`));\n }\n }\n return slots;\n};\n\nconst normalizeEmbeddedFormAuthoringModes = (item: RawSurveyItem): RawSurveyItem => {\n if (!isRecord(item.config) || !Array.isArray(item.config.options)) {\n return item;\n }\n\n return {\n ...item,\n config: {\n ...item.config,\n options: item.config.options.map((option) => {\n if (!isRecord(option) || !isRecord(option.embeddedForm)) {\n return option;\n }\n return {\n ...option,\n embeddedForm: normalizeFormAuthoringConfig(option.embeddedForm),\n };\n }),\n },\n };\n};\n\nconst getSimpleFormValidationIssues = (config: unknown, subject: string) =>\n isValidSimpleFormConfig(config)\n ? []\n : [\n {\n severity: \"error\" as const,\n code: \"invalid-simple-form-structure\",\n message: `${subject} with authoringMode \"simple\" must contain one single-column field group without group display behavior and exactly one supported field whose controller type matches the field type. Use authoringMode \"custom\" for any other structure.`,\n },\n ];\n\nexport const rootItemAssistantCapability: AssistantItemCapabilityAdapter = {\n manifest: createManifest({\n itemType: \"root\",\n displayName: \"Survey root\",\n description: \"The existing root container. A second root cannot be created.\",\n create: \"unsupported\",\n supportedOperations: [\"update-item-key\", \"update-item-label\", \"update-item-color\"],\n contentSurfaces: [],\n referenceTopics: [\"survey-data-model\", \"item-types\"],\n }),\n};\n\nexport const groupItemAssistantCapability: AssistantItemCapabilityAdapter = {\n manifest: createManifest({\n itemType: \"group\",\n displayName: \"Group\",\n description: \"A structural container whose children are created as separate items.\",\n defaultItemKeyPrefix: \"group\",\n create: \"deterministic\",\n supportedOperations: [...COMMON_OPERATIONS, \"reorder-items\"],\n contentSurfaces: [\n {\n key: \"title\",\n role: \"primary\",\n format: \"rich\",\n aliases: [\"content\", \"label\", \"name\", \"text\"],\n },\n ],\n referenceTopics: [\"survey-data-model\", \"item-types\"],\n }),\n references: [STRUCTURE_REFERENCE],\n normalizeCreate: materializeGroupCreate,\n};\n\nexport const pageBreakItemAssistantCapability: AssistantItemCapabilityAdapter = {\n manifest: createManifest({\n itemType: \"page-break\",\n displayName: \"Page break\",\n description: \"A structural page boundary.\",\n defaultItemKeyPrefix: \"page\",\n create: \"deterministic\",\n supportedOperations: COMMON_OPERATIONS,\n contentSurfaces: [\n {\n key: \"title\",\n role: \"primary\",\n format: \"rich\",\n aliases: [\"content\", \"label\", \"name\", \"text\"],\n },\n ],\n referenceTopics: [\"survey-data-model\", \"item-types\"],\n }),\n references: [STRUCTURE_REFERENCE],\n normalizeCreate: materializeEmptyConfigCreate,\n};\n\nexport const infoItemAssistantCapability: AssistantItemCapabilityAdapter = {\n manifest: createManifest({\n itemType: \"infoItem\",\n displayName: \"Info\",\n description: \"Display-only formatted content without a response slot.\",\n defaultItemKeyPrefix: \"info\",\n create: \"deterministic\",\n supportedOperations: COMMON_OPERATIONS,\n contentSurfaces: [\n {\n key: \"content\",\n role: \"primary\",\n format: \"rich\",\n requiredOnCreate: true,\n aliases: [\"body\", \"label\", \"prompt\", \"question\", \"text\", \"title\"],\n },\n ],\n referenceTopics: [\"item-types\", \"rich-text-content\"],\n }),\n references: [\n {\n topic: \"rich-text-content\",\n markdown:\n \"Info content uses the rich `content` surface. Markdown strings are not parsed; send structured rich text when formatting matters.\",\n },\n ],\n normalizeCreate: materializeEmptyConfigCreate,\n};\n\nexport const choiceItemAssistantCapability: AssistantItemCapabilityAdapter = {\n manifest: createManifest({\n itemType: \"choiceItem\",\n displayName: \"Choice question\",\n description: \"A single- or multiple-choice question with optional embedded forms.\",\n defaultItemKeyPrefix: \"choice\",\n create: \"deterministic\",\n supportedOperations: [\n ...COMMON_OPERATIONS,\n \"add-choice-option\",\n \"update-choice-option-label\",\n \"remove-choice-option\",\n \"reorder-choice-options\",\n \"upsert-form-field-group\",\n \"remove-form-field-group\",\n \"reorder-form-field-groups\",\n \"upsert-form-field\",\n \"remove-form-field\",\n \"move-form-field\",\n \"set-embedded-form\",\n \"remove-embedded-form\",\n ],\n contentSurfaces: [\n ...QUESTION_CONTENT_SURFACES,\n {\n key: \"options.<optionId>.label\",\n role: \"option\",\n format: \"rich\",\n pattern: true,\n },\n ...FIELD_CONTENT_SURFACES.map((surface) => ({\n ...surface,\n key: `embeddedForms.<optionId>.${surface.key}`,\n })),\n {\n key: \"embeddedForms.<optionId>.fields.<fieldId>.options.<optionId>.label\",\n role: \"option\",\n format: \"rich\",\n pattern: true,\n },\n {\n key: \"embeddedForms.<optionId>.fields.<fieldId>.validations.<validationId>.message\",\n role: \"validation\",\n format: \"rich\",\n pattern: true,\n },\n {\n key: \"embeddedForms.<optionId>.fieldGroups.<groupId>.title\",\n role: \"field\",\n format: \"rich\",\n pattern: true,\n },\n {\n key: \"embeddedForms.<optionId>.fieldGroups.<groupId>.description\",\n role: \"field\",\n format: \"rich\",\n pattern: true,\n },\n ],\n responseSlots: [{ key: \"<responseId>\", valueType: \"reference|referenceArray\" }],\n referenceTopics: [\n \"item-types\",\n \"embedded-forms\",\n \"localization\",\n \"expressions\",\n \"rich-text-content\",\n ],\n authoring: {\n compactHint:\n \"presets choice.single=maxSelection 1; choice.multiple=maxSelection null; embedded one supported field=simple; embedded blank/structured=custom\",\n configSummary:\n \"Config stores id, maxSelection, shuffleOptions, and options. Put every initial option and inline embeddedForm in create-item config; choice option operations edit only choice items already present in the live snapshot. Default an eligible one-field embedded form to authoringMode simple; use custom for blank or structured follow-ups. Embedded field content uses embeddedForms.<choiceOption.id> (case-sensitive), never the option key or embeddedForm id. Form layout values are column counts 1-4; one column makes a lone field full width.\",\n },\n }),\n references: [QUESTION_REFERENCE],\n normalizeCreate: materializeChoiceCreate,\n validateItem: (item) => {\n if (!isRecord(item.config) || !Array.isArray(item.config.options)) {\n return [];\n }\n return item.config.options.flatMap((option) =>\n isRecord(option) && isRecord(option.embeddedForm)\n ? getSimpleFormValidationIssues(option.embeddedForm, \"An embedded form\")\n : [],\n );\n },\n deriveResponseSlots: deriveChoiceResponseSlots,\n};\n\nexport const formItemAssistantCapability: AssistantItemCapabilityAdapter = {\n manifest: createManifest({\n itemType: \"formItem\",\n displayName: \"Form\",\n description: \"A form with groups, typed fields, validations, and select options.\",\n defaultItemKeyPrefix: \"form\",\n create: \"deterministic\",\n supportedOperations: [\n ...COMMON_OPERATIONS,\n \"upsert-form-field-group\",\n \"remove-form-field-group\",\n \"reorder-form-field-groups\",\n \"upsert-form-field\",\n \"remove-form-field\",\n \"move-form-field\",\n ],\n contentSurfaces: [\n ...QUESTION_CONTENT_SURFACES,\n {\n key: \"fieldGroups.<groupId>.title\",\n role: \"field\",\n format: \"rich\",\n pattern: true,\n },\n {\n key: \"fieldGroups.<groupId>.description\",\n role: \"field\",\n format: \"rich\",\n pattern: true,\n },\n ...FIELD_CONTENT_SURFACES,\n {\n key: \"fields.<fieldId>.options.<optionId>.label\",\n role: \"option\",\n format: \"rich\",\n pattern: true,\n },\n {\n key: \"fields.<fieldId>.validations.<validationId>.message\",\n role: \"validation\",\n format: \"rich\",\n pattern: true,\n },\n ],\n responseSlots: [{ key: \"<fieldKey>\", valueType: \"field-dependent\" }],\n referenceTopics: [\"item-types\", \"localization\", \"expressions\", \"rich-text-content\"],\n authoring: {\n compactHint:\n \"presets form.text=input|form.long-text=textarea|form.number=number|form.slider=slider|form.dropdown=select|form.date=datepicker|form.switch=switch; form.blank=custom\",\n configSummary:\n 'Config stores authoringMode and fieldGroups with typed fields. Use authoringMode \"simple\" only for exactly one internal group with exactly one field: text=input, long text=textarea, number=number, slider=slider, dropdown=select, date=datepicker, switch=switch. Use \"custom\" for blank or multi-field forms. Structural changes are a one-way transition to custom. The controller type must match the field type; full date uses datepicker/year-month-day. Layout values are column counts 1-4, not spans.',\n },\n }),\n references: [QUESTION_REFERENCE],\n normalizeCreate: materializeFormCreate,\n validateItem: (item) => getSimpleFormValidationIssues(item.config, \"A formItem\"),\n deriveResponseSlots: (item) => deriveFormResponseSlots(item.config),\n};\n\nexport const defaultSurveyAssistantCapabilities = [\n rootItemAssistantCapability,\n groupItemAssistantCapability,\n pageBreakItemAssistantCapability,\n infoItemAssistantCapability,\n choiceItemAssistantCapability,\n formItemAssistantCapability,\n] as const;\n\nexport const defaultSurveyAssistantCapabilitySet = createSurveyAssistantCapabilities(\n defaultSurveyAssistantCapabilities,\n);\n\nexport const getDefaultSurveyAssistantCapability = (\n itemType: string,\n): AssistantItemCapabilityAdapter | undefined =>\n defaultSurveyAssistantCapabilitySet.byItemType.get(itemType);\n"],"mappings":";;;AAQA,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,4BAAuD;CAC3D;EACE,KAAK;EACL,MAAM;EACN,QAAQ;EACR,kBAAkB;EAClB,SAAS;GAAC;GAAW;GAAS;GAAU;GAAY;GAAO;EAC5D;CACD;EACE,KAAK;EACL,MAAM;EACN,QAAQ;EACR,SAAS,CAAC,cAAc,UAAU;EACnC;CACD;EACE,KAAK;EACL,MAAM;EACN,QAAQ;EACR,SAAS,CAAC,cAAc,cAAc;EACvC;CACD;EACE,KAAK;EACL,MAAM;EACN,QAAQ;EACR,SAAS,CAAC,eAAe,eAAe;EACzC;CACD;EACE,KAAK;EACL,MAAM;EACN,QAAQ;EACR,SAAS,CAAC,SAAS;EACpB;CACF;AAED,MAAM,yBAAoD;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,SAAS;CACd,KAAK,oBAAoB;CACzB,MAAM,QAAQ,UAAU,eAAe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MAAa,8BAA8D;CACzE,UAAU,eAAe;EACvB,UAAU;EACV,aAAa;EACb,aAAa;EACb,sBAAsB;EACtB,QAAQ;EACR,qBAAqB;GACnB,GAAG;GACH;GACA;GACA;GACA;GACA;GACA;GACD;EACD,iBAAiB;GACf,GAAG;GACH;IACE,KAAK;IACL,MAAM;IACN,QAAQ;IACR,SAAS;IACV;GACD;IACE,KAAK;IACL,MAAM;IACN,QAAQ;IACR,SAAS;IACV;GACD,GAAG;GACH;IACE,KAAK;IACL,MAAM;IACN,QAAQ;IACR,SAAS;IACV;GACD;IACE,KAAK;IACL,MAAM;IACN,QAAQ;IACR,SAAS;IACV;GACF;EACD,eAAe,CAAC;GAAE,KAAK;GAAc,WAAW;GAAmB,CAAC;EACpE,iBAAiB;GAAC;GAAc;GAAgB;GAAe;GAAoB;EACnF,WAAW;GACT,aACE;GACF,eACE;GACH;EACF,CAAC;CACF,YAAY,CAAC,mBAAmB;CAChC,iBAAiB;CACjB,eAAe,SAAS,8BAA8B,KAAK,QAAQ,aAAa;CAChF,sBAAsB,SAAS,wBAAwB,KAAK,OAAO;CACpE;AAED,MAAa,qCAAqC;CAChD;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,sCAAsC,kCACjD,mCACD;AAED,MAAa,uCACX,aAEA,oCAAoC,WAAW,IAAI,SAAS"}
|
|
1
|
+
{"version":3,"file":"capabilities-default.mjs","names":[],"sources":["../src/capabilities/default.ts"],"sourcesContent":["import type { AssistantContentSurface, AssistantItemTypeManifest } from \"../protocol\";\nimport { ValueType, type RawSurveyItem } from \"@case-framework/survey-core\";\nimport {\n createChoiceItemConfig,\n getChoiceOptionEmbeddedFormResponseSlotPrefix,\n getChoiceResponseValueType,\n} from \"@case-framework/survey-items/choice\";\nimport {\n createSurveyAssistantCapabilities,\n type AssistantItemCapabilityAdapter,\n} from \"../engine/capabilities\";\nimport {\n createFormItemConfig,\n getFormFieldValueType,\n isValidSimpleFormConfig,\n normalizeFormAuthoringConfig,\n} from \"@case-framework/survey-items/form\";\n\nconst COMMON_OPERATIONS = [\n \"create-item\",\n \"update-item-key\",\n \"update-item-label\",\n \"update-item-color\",\n \"update-item-translation\",\n \"update-placed-image\",\n \"patch-item-config\",\n \"remove-item\",\n \"move-item\",\n \"survey-json-patch\",\n] satisfies AssistantItemTypeManifest[\"supportedOperations\"];\n\nconst QUESTION_CONTENT_SURFACES: AssistantContentSurface[] = [\n {\n key: \"title\",\n role: \"primary\",\n format: \"rich\",\n requiredOnCreate: true,\n aliases: [\"content\", \"label\", \"prompt\", \"question\", \"text\"],\n },\n {\n key: \"subtitle\",\n role: \"secondary\",\n format: \"rich\",\n aliases: [\"subheading\", \"subtext\"],\n },\n {\n key: \"topContent\",\n role: \"secondary\",\n format: \"rich\",\n aliases: [\"preContent\", \"preResponse\"],\n },\n {\n key: \"bottomContent\",\n role: \"secondary\",\n format: \"rich\",\n aliases: [\"postContent\", \"postResponse\"],\n },\n {\n key: \"cardFooter\",\n role: \"secondary\",\n format: \"rich\",\n aliases: [\"footer\"],\n },\n];\n\nconst FIELD_CONTENT_SURFACES: AssistantContentSurface[] = [\n \"label\",\n \"description\",\n \"error\",\n \"placeholder\",\n \"unit\",\n \"checkedLabel\",\n \"uncheckedLabel\",\n].map((key) => ({\n key: `fields.<fieldId>.${key}`,\n role: key === \"error\" ? \"validation\" : \"field\",\n format: \"rich\",\n pattern: true,\n}));\n\nconst createManifest = (\n manifest: Omit<AssistantItemTypeManifest, \"capabilityVersion\">,\n): AssistantItemTypeManifest => ({ capabilityVersion: \"1\", ...manifest });\n\nconst STRUCTURE_REFERENCE = {\n topic: \"item-types\",\n markdown:\n \"Groups are containers. Create a group without child ids, then create or move children through separate operations. Page breaks are standalone structural boundaries.\",\n};\nconst QUESTION_REFERENCE = {\n topic: \"item-types\",\n markdown:\n \"Question titles and supporting text are translations. Configuration stores response behavior; respondent-visible option and field labels use the declared dynamic content surfaces.\",\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst withMaterializedConfig = (\n item: RawSurveyItem,\n defaults: Record<string, unknown>,\n): RawSurveyItem => ({\n ...item,\n config: {\n ...defaults,\n ...(isRecord(item.config) ? item.config : {}),\n },\n});\n\nconst materializeGroupCreate = (item: RawSurveyItem): RawSurveyItem =>\n withMaterializedConfig(item, { items: [], shuffleItems: false });\n\nconst materializeEmptyConfigCreate = (item: RawSurveyItem): RawSurveyItem =>\n withMaterializedConfig(item, {});\n\nconst materializeChoiceCreate = (item: RawSurveyItem): RawSurveyItem => {\n const config = isRecord(item.config) ? item.config : {};\n const defaults = createChoiceItemConfig(item.id);\n\n return normalizeEmbeddedFormAuthoringModes({\n ...item,\n config: {\n ...defaults,\n ...config,\n id: item.id,\n maxSelection: \"maxSelection\" in config ? config.maxSelection : defaults.maxSelection,\n shuffleOptions: \"shuffleOptions\" in config ? config.shuffleOptions : defaults.shuffleOptions,\n options: Array.isArray(config.options) ? config.options : defaults.options,\n },\n });\n};\n\nconst materializeFormCreate = (item: RawSurveyItem): RawSurveyItem => ({\n ...item,\n config: normalizeFormAuthoringConfig({\n ...createFormItemConfig(item.id),\n ...(isRecord(item.config) ? item.config : {}),\n id: item.id,\n }),\n});\n\nconst deriveFormResponseSlots = (config: unknown, prefix?: string): Record<string, ValueType> => {\n if (!isRecord(config) || !Array.isArray(config.fieldGroups)) {\n return {};\n }\n\n const slots: Record<string, ValueType> = {};\n for (const group of config.fieldGroups.filter(isRecord)) {\n if (!Array.isArray(group.fields)) continue;\n for (const field of group.fields.filter(isRecord)) {\n if (typeof field.key !== \"string\" || field.key.length === 0) continue;\n slots[prefix ? `${prefix}.${field.key}` : field.key] = getFormFieldValueType(field);\n }\n }\n return slots;\n};\n\nconst deriveChoiceResponseSlots = (item: RawSurveyItem): Record<string, ValueType> => {\n const config = isRecord(item.config) ? item.config : {};\n const responseId = typeof config.id === \"string\" && config.id.length > 0 ? config.id : item.id;\n const slots: Record<string, ValueType> = {\n [responseId]: getChoiceResponseValueType(config.maxSelection === 1 ? 1 : null),\n };\n\n if (Array.isArray(config.options)) {\n for (const option of config.options.filter(isRecord)) {\n if (typeof option.id !== \"string\" || !option.embeddedForm) continue;\n Object.assign(\n slots,\n deriveFormResponseSlots(\n option.embeddedForm,\n getChoiceOptionEmbeddedFormResponseSlotPrefix(option.id),\n ),\n );\n }\n }\n return slots;\n};\n\nconst normalizeEmbeddedFormAuthoringModes = (item: RawSurveyItem): RawSurveyItem => {\n if (!isRecord(item.config) || !Array.isArray(item.config.options)) {\n return item;\n }\n\n return {\n ...item,\n config: {\n ...item.config,\n options: item.config.options.map((option) => {\n if (!isRecord(option) || !isRecord(option.embeddedForm)) {\n return option;\n }\n return {\n ...option,\n embeddedForm: normalizeFormAuthoringConfig(option.embeddedForm),\n };\n }),\n },\n };\n};\n\nconst getSimpleFormValidationIssues = (config: unknown, subject: string) =>\n isValidSimpleFormConfig(config)\n ? []\n : [\n {\n severity: \"error\" as const,\n code: \"invalid-simple-form-structure\",\n message: `${subject} with authoringMode \"simple\" must contain one single-column field group without group display behavior and exactly one supported field whose controller type matches the field type. Use authoringMode \"custom\" for any other structure.`,\n },\n ];\n\nexport const rootItemAssistantCapability: AssistantItemCapabilityAdapter = {\n manifest: createManifest({\n itemType: \"root\",\n displayName: \"Survey root\",\n description: \"The existing root container. A second root cannot be created.\",\n create: \"unsupported\",\n supportedOperations: [\"update-item-key\", \"update-item-label\", \"update-item-color\"],\n contentSurfaces: [],\n referenceTopics: [\"survey-data-model\", \"item-types\"],\n }),\n};\n\nexport const groupItemAssistantCapability: AssistantItemCapabilityAdapter = {\n manifest: createManifest({\n itemType: \"group\",\n displayName: \"Group\",\n description: \"A structural container whose children are created as separate items.\",\n defaultItemKeyPrefix: \"group\",\n create: \"deterministic\",\n supportedOperations: [...COMMON_OPERATIONS, \"reorder-items\"],\n contentSurfaces: [\n {\n key: \"title\",\n role: \"primary\",\n format: \"rich\",\n aliases: [\"content\", \"label\", \"name\", \"text\"],\n },\n ],\n referenceTopics: [\"survey-data-model\", \"item-types\"],\n }),\n references: [STRUCTURE_REFERENCE],\n normalizeCreate: materializeGroupCreate,\n};\n\nexport const pageBreakItemAssistantCapability: AssistantItemCapabilityAdapter = {\n manifest: createManifest({\n itemType: \"page-break\",\n displayName: \"Page break\",\n description: \"A structural page boundary.\",\n defaultItemKeyPrefix: \"page\",\n create: \"deterministic\",\n supportedOperations: COMMON_OPERATIONS,\n contentSurfaces: [\n {\n key: \"title\",\n role: \"primary\",\n format: \"rich\",\n aliases: [\"content\", \"label\", \"name\", \"text\"],\n },\n ],\n referenceTopics: [\"survey-data-model\", \"item-types\"],\n }),\n references: [STRUCTURE_REFERENCE],\n normalizeCreate: materializeEmptyConfigCreate,\n};\n\nexport const infoItemAssistantCapability: AssistantItemCapabilityAdapter = {\n manifest: createManifest({\n itemType: \"infoItem\",\n displayName: \"Info\",\n description: \"Display-only formatted content without a response slot.\",\n defaultItemKeyPrefix: \"info\",\n create: \"deterministic\",\n supportedOperations: COMMON_OPERATIONS,\n contentSurfaces: [\n {\n key: \"content\",\n role: \"primary\",\n format: \"rich\",\n requiredOnCreate: true,\n aliases: [\"body\", \"label\", \"prompt\", \"question\", \"text\", \"title\"],\n },\n ],\n referenceTopics: [\"item-types\", \"rich-text-content\"],\n }),\n references: [\n {\n topic: \"rich-text-content\",\n markdown:\n \"Info content uses the rich `content` surface. Markdown strings are not parsed; send structured rich text when formatting matters.\",\n },\n ],\n normalizeCreate: materializeEmptyConfigCreate,\n};\n\nexport const choiceItemAssistantCapability: AssistantItemCapabilityAdapter = {\n manifest: createManifest({\n itemType: \"choiceItem\",\n displayName: \"Choice question\",\n description: \"A single- or multiple-choice question with optional embedded forms.\",\n defaultItemKeyPrefix: \"choice\",\n create: \"deterministic\",\n supportedOperations: [\n ...COMMON_OPERATIONS,\n \"add-choice-option\",\n \"update-choice-option-label\",\n \"remove-choice-option\",\n \"reorder-choice-options\",\n \"upsert-form-field-group\",\n \"remove-form-field-group\",\n \"reorder-form-field-groups\",\n \"upsert-form-field\",\n \"remove-form-field\",\n \"move-form-field\",\n \"set-embedded-form\",\n \"remove-embedded-form\",\n ],\n contentSurfaces: [\n ...QUESTION_CONTENT_SURFACES,\n {\n key: \"options.<optionId>.label\",\n role: \"option\",\n format: \"rich\",\n pattern: true,\n },\n ...FIELD_CONTENT_SURFACES.map((surface) => ({\n ...surface,\n key: `embeddedForms.<optionId>.${surface.key}`,\n })),\n {\n key: \"embeddedForms.<optionId>.fields.<fieldId>.options.<optionId>.label\",\n role: \"option\",\n format: \"rich\",\n pattern: true,\n },\n {\n key: \"embeddedForms.<optionId>.fields.<fieldId>.validations.<validationId>.message\",\n role: \"validation\",\n format: \"rich\",\n pattern: true,\n },\n {\n key: \"embeddedForms.<optionId>.fieldGroups.<groupId>.title\",\n role: \"field\",\n format: \"rich\",\n pattern: true,\n },\n {\n key: \"embeddedForms.<optionId>.fieldGroups.<groupId>.description\",\n role: \"field\",\n format: \"rich\",\n pattern: true,\n },\n ],\n responseSlots: [{ key: \"<responseId>\", valueType: \"reference|referenceArray\" }],\n referenceTopics: [\n \"item-types\",\n \"embedded-forms\",\n \"localization\",\n \"expressions\",\n \"rich-text-content\",\n ],\n authoring: {\n compactHint:\n \"presets choice.single=maxSelection 1; choice.multiple=maxSelection null; embedded one supported field=simple; embedded blank/structured=custom\",\n configSummary:\n \"Config stores id, maxSelection, shuffleOptions, and options. Put every initial option and inline embeddedForm in create-item config; choice option operations edit only choice items already present in the live snapshot. Default an eligible one-field embedded form to authoringMode simple; use custom for blank or structured follow-ups. Embedded field content uses embeddedForms.<choiceOption.id> (case-sensitive), never the option key or embeddedForm id. Form layout values are column counts 1-4; one column makes a lone field full width.\",\n },\n }),\n references: [QUESTION_REFERENCE],\n normalizeCreate: materializeChoiceCreate,\n validateItem: (item) => {\n if (!isRecord(item.config) || !Array.isArray(item.config.options)) {\n return [];\n }\n return item.config.options.flatMap((option) =>\n isRecord(option) && isRecord(option.embeddedForm)\n ? getSimpleFormValidationIssues(option.embeddedForm, \"An embedded form\")\n : [],\n );\n },\n deriveResponseSlots: deriveChoiceResponseSlots,\n};\n\nexport const formItemAssistantCapability: AssistantItemCapabilityAdapter = {\n manifest: createManifest({\n itemType: \"formItem\",\n displayName: \"Form\",\n description: \"A form with groups, typed fields, validations, and select options.\",\n defaultItemKeyPrefix: \"form\",\n create: \"deterministic\",\n supportedOperations: [\n ...COMMON_OPERATIONS,\n \"upsert-form-field-group\",\n \"remove-form-field-group\",\n \"reorder-form-field-groups\",\n \"upsert-form-field\",\n \"remove-form-field\",\n \"move-form-field\",\n ],\n contentSurfaces: [\n ...QUESTION_CONTENT_SURFACES,\n {\n key: \"fieldGroups.<groupId>.title\",\n role: \"field\",\n format: \"rich\",\n pattern: true,\n },\n {\n key: \"fieldGroups.<groupId>.description\",\n role: \"field\",\n format: \"rich\",\n pattern: true,\n },\n ...FIELD_CONTENT_SURFACES,\n {\n key: \"fields.<fieldId>.options.<optionId>.label\",\n role: \"option\",\n format: \"rich\",\n pattern: true,\n },\n {\n key: \"fields.<fieldId>.validations.<validationId>.message\",\n role: \"validation\",\n format: \"rich\",\n pattern: true,\n },\n ],\n responseSlots: [{ key: \"<fieldKey>\", valueType: \"field-dependent\" }],\n referenceTopics: [\"item-types\", \"localization\", \"expressions\", \"rich-text-content\"],\n authoring: {\n compactHint:\n \"presets form.text=input|form.long-text=textarea|form.number=number|form.slider=slider|form.dropdown=select|form.date=datepicker|form.switch=switch; form.blank=custom\",\n configSummary:\n 'Config stores authoringMode and fieldGroups with typed fields. Use authoringMode \"simple\" only for exactly one internal group with exactly one field: text=input, long text=textarea, number=number, slider=slider, dropdown=select, date=datepicker, switch=switch. Use \"custom\" for blank or multi-field forms. Structural changes are a one-way transition to custom. The controller type must match the field type; full date uses datepicker/year-month-day. Layout values are column counts 1-4, not spans.',\n },\n }),\n references: [QUESTION_REFERENCE],\n normalizeCreate: materializeFormCreate,\n validateItem: (item) => getSimpleFormValidationIssues(item.config, \"A formItem\"),\n deriveResponseSlots: (item) => deriveFormResponseSlots(item.config),\n};\n\nexport const defaultSurveyAssistantCapabilities = [\n rootItemAssistantCapability,\n groupItemAssistantCapability,\n pageBreakItemAssistantCapability,\n infoItemAssistantCapability,\n choiceItemAssistantCapability,\n formItemAssistantCapability,\n] as const;\n\nexport const defaultSurveyAssistantCapabilitySet = createSurveyAssistantCapabilities(\n defaultSurveyAssistantCapabilities,\n);\n\nexport const getDefaultSurveyAssistantCapability = (\n itemType: string,\n): AssistantItemCapabilityAdapter | undefined =>\n defaultSurveyAssistantCapabilitySet.byItemType.get(itemType);\n"],"mappings":";;;;AAkBA,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,4BAAuD;CAC3D;EACE,KAAK;EACL,MAAM;EACN,QAAQ;EACR,kBAAkB;EAClB,SAAS;GAAC;GAAW;GAAS;GAAU;GAAY;GAAO;EAC5D;CACD;EACE,KAAK;EACL,MAAM;EACN,QAAQ;EACR,SAAS,CAAC,cAAc,UAAU;EACnC;CACD;EACE,KAAK;EACL,MAAM;EACN,QAAQ;EACR,SAAS,CAAC,cAAc,cAAc;EACvC;CACD;EACE,KAAK;EACL,MAAM;EACN,QAAQ;EACR,SAAS,CAAC,eAAe,eAAe;EACzC;CACD;EACE,KAAK;EACL,MAAM;EACN,QAAQ;EACR,SAAS,CAAC,SAAS;EACpB;CACF;AAED,MAAM,yBAAoD;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,SAAS;CACd,KAAK,oBAAoB;CACzB,MAAM,QAAQ,UAAU,eAAe;CACvC,QAAQ;CACR,SAAS;CACV,EAAE;AAEH,MAAM,kBACJ,cAC+B;CAAE,mBAAmB;CAAK,GAAG;CAAU;AAExE,MAAM,sBAAsB;CAC1B,OAAO;CACP,UACE;CACH;AACD,MAAM,qBAAqB;CACzB,OAAO;CACP,UACE;CACH;AAED,MAAM,YAAY,UAChB,OAAO,U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IACR,SAAS;IACV;GACF;EACD,eAAe,CAAC;GAAE,KAAK;GAAc,WAAW;GAAmB,CAAC;EACpE,iBAAiB;GAAC;GAAc;GAAgB;GAAe;GAAoB;EACnF,WAAW;GACT,aACE;GACF,eACE;GACH;EACF,CAAC;CACF,YAAY,CAAC,mBAAmB;CAChC,iBAAiB;CACjB,eAAe,SAAS,8BAA8B,KAAK,QAAQ,aAAa;CAChF,sBAAsB,SAAS,wBAAwB,KAAK,OAAO;CACpE;AAED,MAAa,qCAAqC;CAChD;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,sCAAsC,kCACjD,mCACD;AAED,MAAa,uCACX,aAEA,oCAAoC,WAAW,IAAI,SAAS"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Ct as SurveyDocumentSnapshot, o as SurveyAssistantApplyOutcome, wt as SurveyDocumentVersion } from "./lifecycle-
|
|
2
|
-
import {
|
|
1
|
+
import { Ct as SurveyDocumentSnapshot, o as SurveyAssistantApplyOutcome, wt as SurveyDocumentVersion } from "./lifecycle-Bx0aq_4S.mjs";
|
|
2
|
+
import { Nt as SurveyAssistantEngineContext, qt as SurveyAssistantCapabilitySet, x as TurnSurveyDraft } from "./index-Tnqv-yKW.mjs";
|
|
3
3
|
import { n as SurveyAssistantModelAttachment, t as SurveyAssistantAttachmentAccess } from "./thread-documents-rmd6nyX9.mjs";
|
|
4
4
|
import { RequestContext } from "@mastra/core/request-context";
|
|
5
5
|
import { AgentExecutionOptions } from "@mastra/core/agent";
|
|
@@ -99,4 +99,4 @@ declare const SURVEY_ASSISTANT_AGENT_ID = "survey-assistant-agent";
|
|
|
99
99
|
declare const SURVEY_ASSISTANT_TASK_AGENT_ID = "survey-assistant-task-agent";
|
|
100
100
|
//#endregion
|
|
101
101
|
export { SurveyAssistantModelSelection as a, deriveSurveyAssistantDocumentTransition as c, parseSurveyAssistantSnapshot as d, requireSurveyAssistantTurnState as f, SurveyAssistantIdentityContext as i, parseSurveyAssistantPreviousApplyOutcome as l, SURVEY_ASSISTANT_TASK_AGENT_ID as n, SurveyAssistantRequestContext as o, SurveyAssistantDocumentTransition as r, buildSurveyAssistantRequestContext as s, SURVEY_ASSISTANT_AGENT_ID as t, parseSurveyAssistantPreviousSettledVersion as u };
|
|
102
|
-
//# sourceMappingURL=constants-
|
|
102
|
+
//# sourceMappingURL=constants-Be91Gay9.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants-
|
|
1
|
+
{"version":3,"file":"constants-Be91Gay9.d.mts","names":[],"sources":["../src/server/request-context.ts","../src/server/constants.ts"],"mappings":";;;;;;;;UA2BiB,gCAAA;EACf,IAAA;AAAA;AAAA,UAGe,8BAAA;EACf,SAAA;EACA,UAAA;EACA,QAAA;EACA,QAAA;AAAA;AAAA,UAGe,6BAAA;EACf,EAAA;EACA,KAAA,WAAgB,sBAAA;EAChB,YAAA;EACA,eAAA,GAAkB,qBAAA;AAAA;AAAA,KAGR,iCAAA;EACN,MAAA;AAAA;EAEA,MAAA;EACA,oBAAA;EACA,mBAAA;AAAA;EAGA,MAAA;EACA,oBAAA;EACA,mBAAA;EACA,mBAAA;AAAA;EAGA,MAAA;EACA,oBAAA;EACA,mBAAA;EACA,gBAAA;EACA,eAAA,EAAiB,KAAA;EACjB,mBAAA;AAAA;AAAA,UAGW,6BAAA;EACf,UAAA,EAAY,gCAAA;EACZ,MAAA;EACA,SAAA,EAAW,eAAA;EACX,QAAA,EAAU,8BAAA;EACV,uBAAA;EACA,kBAAA;EACA,WAAA;EACA,kBAAA;EACA,gBAAA;EACA,kBAAA,GAAqB,iCAAA;EACrB,aAAA,GAAgB,4BAAA;EAChB,gBAAA,GAAmB,sBAAA;EACnB,gBAAA,GAAmB,8BAAA;EACnB,gBAAA,GAAmB,+BAAA;EACnB,cAAA,GAAiB,6BAAA;EACjB,oBAAA,GAAuB,2BAAA;AAAA;AAAA,cAGZ,4BAAA,GAAgC,KAAA,cAAiB,sBAAA;AAAA,cAQjD,0CAAA,GACX,KAAA,cACC,qBAAA;AAAA,cAQU,wCAAA,GACX,KAAA,cACC,2BAAA;AAAA,cAQU,uCAAA;EAA2C,OAAA;EAAA;AAAA;EAItD,OAAA,EAAS,sBAAA;EACT,QAAA,EAAU,qBAAA;AAAA,MACR,iCAAA;AAAA,cAqDS,kCAAA;EAAsC,SAAA;EAAA,QAAA;EAAA,QAAA;EAAA,sBAAA;EAAA,mBAAA;EAAA,gBAAA;EAAA,gBAAA;EAAA,cAAA;EAAA;AAAA;EAWjD,SAAA,EAAW,eAAA;EACX,QAAA,EAAU,8BAAA;EACV,QAAA,EAAU,sBAAA;EACV,sBAAA,GAAyB,qBAAA;EACzB,mBAAA,GAAsB,4BAAA;EACtB,gBAAA,GAAmB,+BAAA;EACnB,gBAAA,GAAmB,8BAAA;EACnB,cAAA,GAAiB,6BAAA;EACjB,oBAAA,GAAuB,2BAAA;AAAA,MACrB,cAAA,CAAe,6BAAA;AAAA,cAuDN,+BAAA,GACX,cAAA,EAAgB,cAAA,CAAe,6BAAA;;;;;;cCzPpB,yBAAA;AAAA,cACA,8BAAA"}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import { O as surveyAssistantTranslateContentResultSchema, b as surveyAssistantSuggestItemLabelResultSchema, jt as
|
|
1
|
+
import { Mt as parseSurveyAssistantError, O as surveyAssistantTranslateContentResultSchema, b as surveyAssistantSuggestItemLabelResultSchema, jt as isSurveyAssistantErrorRetryable, v as surveyAssistantSuggestItemKeyResultSchema } from "./protocol-BhzQbx81.mjs";
|
|
2
2
|
//#region src/react/client-error.ts
|
|
3
3
|
var SurveyAssistantClientError = class extends Error {
|
|
4
4
|
code;
|
|
5
5
|
retryable;
|
|
6
|
-
|
|
6
|
+
upstreamStatus;
|
|
7
|
+
providerRequestId;
|
|
8
|
+
providerMessage;
|
|
9
|
+
constructor(code, message, retryable = false, diagnostics = {}) {
|
|
7
10
|
super(message);
|
|
8
11
|
this.name = "SurveyAssistantClientError";
|
|
9
12
|
this.code = code;
|
|
10
13
|
this.retryable = retryable;
|
|
14
|
+
this.upstreamStatus = diagnostics.upstreamStatus;
|
|
15
|
+
this.providerRequestId = diagnostics.providerRequestId;
|
|
16
|
+
this.providerMessage = diagnostics.providerMessage;
|
|
11
17
|
}
|
|
12
18
|
};
|
|
13
19
|
const readSurveyAssistantJson = async (response, fallback = "The assistant request could not be completed.") => {
|
|
@@ -22,10 +28,14 @@ const readSurveyAssistantJson = async (response, fallback = "The assistant reque
|
|
|
22
28
|
const detail = typeof body === "object" && body !== null && "error" in body && typeof body.error === "string" ? body.error : responseText.trim() || fallback;
|
|
23
29
|
const parsed = parseSurveyAssistantError(typeof body === "object" && body !== null && "code" in body && typeof body.code === "string" ? {
|
|
24
30
|
code: body.code,
|
|
25
|
-
detail
|
|
31
|
+
detail,
|
|
32
|
+
retryable: "retryable" in body && typeof body.retryable === "boolean" ? body.retryable : void 0,
|
|
33
|
+
upstreamStatus: "upstreamStatus" in body && typeof body.upstreamStatus === "number" ? body.upstreamStatus : void 0,
|
|
34
|
+
providerRequestId: "providerRequestId" in body && typeof body.providerRequestId === "string" ? body.providerRequestId : void 0,
|
|
35
|
+
providerMessage: "providerMessage" in body && typeof body.providerMessage === "string" ? body.providerMessage : void 0
|
|
26
36
|
} : detail);
|
|
27
|
-
const retryable = (
|
|
28
|
-
throw new SurveyAssistantClientError(parsed.code, parsed.detail ?? detail, retryable);
|
|
37
|
+
const retryable = isSurveyAssistantErrorRetryable(parsed, response.status);
|
|
38
|
+
throw new SurveyAssistantClientError(parsed.code, parsed.detail ?? detail, retryable, parsed);
|
|
29
39
|
}
|
|
30
40
|
return response.json().catch(() => ({}));
|
|
31
41
|
};
|
|
@@ -153,8 +163,11 @@ const failedResult = (change, message) => ({
|
|
|
153
163
|
});
|
|
154
164
|
const createSurveyAssistantControllerProxy = (getController, { notReadyMessage = "The survey editor is not ready." } = {}) => ({
|
|
155
165
|
getSnapshot: () => getController()?.getSnapshot() ?? null,
|
|
156
|
-
|
|
157
|
-
|
|
166
|
+
applyAssistantChanges: (changes) => {
|
|
167
|
+
const controller = getController();
|
|
168
|
+
if (!controller) return { results: changes.map((change) => failedResult(change, notReadyMessage)) };
|
|
169
|
+
return controller.applyAssistantChanges(changes);
|
|
170
|
+
}
|
|
158
171
|
});
|
|
159
172
|
const createSurveyAssistantControllerBridge = (options) => {
|
|
160
173
|
let currentController;
|
|
@@ -168,4 +181,4 @@ const createSurveyAssistantControllerBridge = (options) => {
|
|
|
168
181
|
//#endregion
|
|
169
182
|
export { applySurveyAssistantLaunchUIContext as a, SurveyAssistantClientError as c, createSurveyAssistantTaskExecutor as i, readSurveyAssistantJson as l, createSurveyAssistantControllerProxy as n, connectSurveyAssistantThreadLauncher as o, createSurveyAssistantTaskClient as r, createSurveyAssistantThreadLauncher as s, createSurveyAssistantControllerBridge as t };
|
|
170
183
|
|
|
171
|
-
//# sourceMappingURL=controller-proxy-
|
|
184
|
+
//# sourceMappingURL=controller-proxy-BH05e-C2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller-proxy-BH05e-C2.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 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 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,EAAE,EACN;AACA,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,OAAO;AACZ,OAAK,YAAY;AACjB,OAAK,iBAAiB,YAAY;AAClC,OAAK,oBAAoB,YAAY;AACrC,OAAK,kBAAkB,YAAY;;;AAIvC,MAAa,0BAA0B,OACrC,UACA,WAAW,oDACR;AACH,KAAI,CAAC,SAAS,IAAI;EAChB,MAAM,eAAe,MAAM,SAAS,MAAM,CAAC,YAAY,GAAG;EAC1D,IAAI;AACJ,MAAI;AACF,UAAO,eAAe,KAAK,MAAM,aAAa,GAAG,KAAA;UAC3C;AACN,UAAO,KAAA;;EAET,MAAM,SACJ,OAAO,SAAS,YAAY,SAAS,QAAQ,WAAW,QAAQ,OAAO,KAAK,UAAU,WAClF,KAAK,QACL,aAAa,MAAM,IAAI;EAC7B,MAAM,SAAS,0BACb,OAAO,SAAS,YAAY,SAAS,QAAQ,UAAU,QAAQ,OAAO,KAAK,SAAS,WAChF;GACE,MAAM,KAAK;GACX;GACA,WACE,eAAe,QAAQ,OAAO,KAAK,cAAc,YAC7C,KAAK,YACL,KAAA;GACN,gBACE,oBAAoB,QAAQ,OAAO,KAAK,mBAAmB,WACvD,KAAK,iBACL,KAAA;GACN,mBACE,uBAAuB,QAAQ,OAAO,KAAK,sBAAsB,WAC7D,KAAK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KeyInput, d as SurveyAssistantSuggestItemLabelResult, l as SurveyAssistantSuggestItemKeyResult, m as SurveyAssistantTaskInvocationMode, p as SurveyAssistantTaskContext, u as SurveyAssistantSuggestItemLabelInput, v as SurveyAssistantTranslateContentInput, y as SurveyAssistantTranslateContentResult } from "./index-
|
|
2
|
-
import { Tt as SurveyEditorUIContext, h as SurveyChangeSet,
|
|
1
|
+
import { L as SurveyAssistantThread, c as SurveyAssistantSuggestItemKeyInput, d as SurveyAssistantSuggestItemLabelResult, l as SurveyAssistantSuggestItemKeyResult, m as SurveyAssistantTaskInvocationMode, p as SurveyAssistantTaskContext, u as SurveyAssistantSuggestItemLabelInput, v as SurveyAssistantTranslateContentInput, y as SurveyAssistantTranslateContentResult } from "./index-nhrgbgO5.mjs";
|
|
2
|
+
import { Tt as SurveyEditorUIContext, h as SurveyChangeSet, m as SurveyBatchApplyResult, xt as SurveyAssistantSnapshot } from "./lifecycle-Bx0aq_4S.mjs";
|
|
3
3
|
import { FileUIPart } from "ai";
|
|
4
4
|
|
|
5
5
|
//#region src/react/thread-launcher.d.ts
|
|
@@ -24,6 +24,13 @@ interface SurveyAssistantThreadLauncher {
|
|
|
24
24
|
}
|
|
25
25
|
declare const createSurveyAssistantThreadLauncher: () => SurveyAssistantThreadLauncher;
|
|
26
26
|
//#endregion
|
|
27
|
+
//#region src/react/controller.d.ts
|
|
28
|
+
interface SurveyAssistantController {
|
|
29
|
+
getSnapshot(): SurveyAssistantSnapshot | null;
|
|
30
|
+
/** Applies the authorized turn, including a one-change turn, and returns one result per change. */
|
|
31
|
+
applyAssistantChanges(changes: SurveyChangeSet[]): SurveyBatchApplyResult;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
27
34
|
//#region src/react/task-client.d.ts
|
|
28
35
|
interface SurveyAssistantTaskClientOptions {
|
|
29
36
|
api?: string;
|
|
@@ -61,13 +68,6 @@ declare const createSurveyAssistantTaskClient: ({
|
|
|
61
68
|
}?: SurveyAssistantTaskClientOptions) => SurveyAssistantTaskClient;
|
|
62
69
|
declare const createSurveyAssistantTaskExecutor: (options?: SurveyAssistantTaskClientOptions) => SurveyAssistantTaskExecutor;
|
|
63
70
|
//#endregion
|
|
64
|
-
//#region src/react/controller.d.ts
|
|
65
|
-
interface SurveyAssistantController {
|
|
66
|
-
getSnapshot(): SurveyAssistantSnapshot | null;
|
|
67
|
-
applyAssistantChange?(change: SurveyChangeSet): SurveyApplyResult;
|
|
68
|
-
applyAssistantChanges?(changes: SurveyChangeSet[]): SurveyBatchApplyResult;
|
|
69
|
-
}
|
|
70
|
-
//#endregion
|
|
71
71
|
//#region src/react/controller-proxy.d.ts
|
|
72
72
|
interface CreateSurveyAssistantControllerProxyOptions {
|
|
73
73
|
notReadyMessage?: string;
|
|
@@ -81,5 +81,5 @@ declare const createSurveyAssistantControllerProxy: (getController: () => Survey
|
|
|
81
81
|
}?: CreateSurveyAssistantControllerProxyOptions) => SurveyAssistantController;
|
|
82
82
|
declare const createSurveyAssistantControllerBridge: (options?: CreateSurveyAssistantControllerProxyOptions) => SurveyAssistantControllerBridge;
|
|
83
83
|
//#endregion
|
|
84
|
-
export { createSurveyAssistantThreadLauncher as _,
|
|
85
|
-
//# sourceMappingURL=controller-proxy-
|
|
84
|
+
export { createSurveyAssistantThreadLauncher as _, SurveyAssistantTaskClient as a, SurveyAssistantTaskExecutor as c, createSurveyAssistantTaskClient as d, createSurveyAssistantTaskExecutor as f, SurveyAssistantThreadLauncher as g, SurveyAssistantThreadLaunch as h, createSurveyAssistantControllerProxy as i, SurveyAssistantTaskExecutorCacheContext as l, SurveyAssistantLaunchUIContext as m, SurveyAssistantControllerBridge as n, SurveyAssistantTaskClientOptions as o, SurveyAssistantController as p, createSurveyAssistantControllerBridge as r, SurveyAssistantTaskExecutionOptions as s, CreateSurveyAssistantControllerProxyOptions as t, SurveyAssistantTaskExecutorRequestOptions as u };
|
|
85
|
+
//# sourceMappingURL=controller-proxy-Bd0ZHBPF.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller-proxy-Bd0ZHBPF.d.mts","names":[],"sources":["../src/react/thread-launcher.ts","../src/react/controller.ts","../src/react/task-client.ts","../src/react/controller-proxy.ts"],"mappings":";;;;;KAOY,8BAAA,GAAiC,OAAA,CAAQ,IAAA,CAAK,qBAAA;AAAA,UAEzC,2BAAA;;EAEf,MAAA;EACA,KAAA,GAAQ,UAAA;;EAER,OAAA;EAPmD;EASnD,KAAA;EATkD;EAWlD,SAAA,GAAY,8BAAA;AAAA;AAAA,UAGG,6BAAA;EAdyC;;;AAE1D;EAiBE,WAAA,CAAY,KAAA,EAAO,2BAAA,GAA8B,OAAA,CAAQ,qBAAA;AAAA;AAAA,cA6D9C,mCAAA,QAA0C,6BAAA;;;UCrFtC,yBAAA;EACf,WAAA,IAAe,uBAAA;;EAEf,qBAAA,CAAsB,OAAA,EAAS,eAAA,KAAoB,sBAAA;AAAA;;;UCUpC,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,mCAAA,GACT,OAAA,CAAQ,qCAAA;AAAA;AAAA,UAGI,yCAAA;EACf,IAAA,GAAO,iCAAA;EACP,MAAA,GAAS,WAAA;AAAA;AAAA,UAGM,uCAAA;EACf,UAAA;AAAA;AAAA,UAGe,2BAAA;EACf,cAAA,CACE,KAAA,EAAO,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