@case-framework/survey-assistant 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/README.md +58 -3
  2. package/dist/{attachments-B0hg3vpT.mjs → attachments-BuNni5vB.mjs} +1 -1
  3. package/dist/{attachments-B0hg3vpT.mjs.map → attachments-BuNni5vB.mjs.map} +1 -1
  4. package/dist/{authoring-references-BJQ_1nMX.mjs → authoring-references-CmwLc_C8.mjs} +49 -32
  5. package/dist/authoring-references-CmwLc_C8.mjs.map +1 -0
  6. package/dist/capabilities-D55dq-fO.mjs +582 -0
  7. package/dist/capabilities-D55dq-fO.mjs.map +1 -0
  8. package/dist/capabilities-default.d.mts +5 -12
  9. package/dist/capabilities-default.d.mts.map +1 -1
  10. package/dist/capabilities-default.mjs +2 -411
  11. package/dist/capabilities-z95e1mti.d.mts +117 -0
  12. package/dist/capabilities-z95e1mti.d.mts.map +1 -0
  13. package/dist/{constants-0UHGFcRJ.mjs → constants-Ct-vv9cu.mjs} +1 -1
  14. package/dist/{constants-0UHGFcRJ.mjs.map → constants-Ct-vv9cu.mjs.map} +1 -1
  15. package/dist/{constants-Be91Gay9.d.mts → constants-HL_klgJl.d.mts} +7 -28
  16. package/dist/constants-HL_klgJl.d.mts.map +1 -0
  17. package/dist/{controller-proxy-BH05e-C2.mjs → controller-proxy-BQ1YsVxJ.mjs} +12 -21
  18. package/dist/controller-proxy-BQ1YsVxJ.mjs.map +1 -0
  19. package/dist/controller-proxy-Cmzdr9tV.d.mts +65 -0
  20. package/dist/controller-proxy-Cmzdr9tV.d.mts.map +1 -0
  21. package/dist/default-D22AKTqE.mjs +233 -0
  22. package/dist/default-D22AKTqE.mjs.map +1 -0
  23. package/dist/{digest-SJmoYVaK.d.mts → digest-FnTTDBq2.d.mts} +2 -3
  24. package/dist/digest-FnTTDBq2.d.mts.map +1 -0
  25. package/dist/digest.d.mts +1 -1
  26. package/dist/digest.mjs.map +1 -1
  27. package/dist/engine-D950TfvC.mjs +3098 -0
  28. package/dist/engine-D950TfvC.mjs.map +1 -0
  29. package/dist/engine.d.mts +4 -3
  30. package/dist/engine.mjs +3 -3
  31. package/dist/{fair-guidance-CRYCRxQm.mjs → fair-guidance-BmO4PswW.mjs} +1 -1
  32. package/dist/{fair-guidance-CRYCRxQm.mjs.map → fair-guidance-BmO4PswW.mjs.map} +1 -1
  33. package/dist/{index-l_EK4yK7.d.mts → index-B8TLBd1G.d.mts} +18 -72
  34. package/dist/index-B8TLBd1G.d.mts.map +1 -0
  35. package/dist/index-CaX3hZmr.d.mts +23813 -0
  36. package/dist/index-CaX3hZmr.d.mts.map +1 -0
  37. package/dist/{index-x0qprHgK.d.mts → index-CeUlGkoU.d.mts} +58 -28
  38. package/dist/index-CeUlGkoU.d.mts.map +1 -0
  39. package/dist/{index-nhrgbgO5.d.mts → index-DYHdvSE8.d.mts} +347 -88
  40. package/dist/index-DYHdvSE8.d.mts.map +1 -0
  41. package/dist/lifecycle-DFzxVxpq.d.mts +54346 -0
  42. package/dist/lifecycle-DFzxVxpq.d.mts.map +1 -0
  43. package/dist/{memory-thread-repository-KWHQWFEW.mjs → memory-thread-repository-DmLadygY.mjs} +60 -30
  44. package/dist/memory-thread-repository-DmLadygY.mjs.map +1 -0
  45. package/dist/protocol-BQ7uIDYT.mjs +569 -0
  46. package/dist/protocol-BQ7uIDYT.mjs.map +1 -0
  47. package/dist/protocol.d.mts +4 -4
  48. package/dist/protocol.mjs +4 -3
  49. package/dist/{react-B3ybjJ-X.mjs → react-DybJ5pWw.mjs} +159 -46
  50. package/dist/react-DybJ5pWw.mjs.map +1 -0
  51. package/dist/react-integration.d.mts +2 -2
  52. package/dist/react-integration.mjs +2 -2
  53. package/dist/react.d.mts +3 -3
  54. package/dist/react.mjs +3 -3
  55. package/dist/references/assistant-operations.md +224 -180
  56. package/dist/references/core-rules.md +6 -3
  57. package/dist/references/element-types.md +189 -0
  58. package/dist/references/expressions.md +307 -168
  59. package/dist/references/fair-by-design.md +9 -9
  60. package/dist/references/follow-ups.md +151 -0
  61. package/dist/references/localization.md +26 -12
  62. package/dist/references/response-variables.md +38 -0
  63. package/dist/references/rich-text-content.md +22 -43
  64. package/dist/references/source-material-surveys.md +20 -24
  65. package/dist/references/survey-data-model.md +36 -102
  66. package/dist/{request-context-CG4SWijt.mjs → request-context-KVh8VjgH.mjs} +4 -10
  67. package/dist/request-context-KVh8VjgH.mjs.map +1 -0
  68. package/dist/{request-guardrails-TmgQtqp4.mjs → request-guardrails-C0ugBOp0.mjs} +6 -5
  69. package/dist/request-guardrails-C0ugBOp0.mjs.map +1 -0
  70. package/dist/server-agent.d.mts +62 -43
  71. package/dist/server-agent.d.mts.map +1 -1
  72. package/dist/server-agent.mjs +73 -40
  73. package/dist/server-agent.mjs.map +1 -1
  74. package/dist/server-runtime.d.mts +24 -42
  75. package/dist/server-runtime.d.mts.map +1 -1
  76. package/dist/server-runtime.mjs +12 -12
  77. package/dist/server-runtime.mjs.map +1 -1
  78. package/dist/server-tasks.d.mts +2 -2
  79. package/dist/server-tasks.mjs +2 -313
  80. package/dist/server-tools.d.mts +1 -1
  81. package/dist/server-tools.mjs +1 -1
  82. package/dist/server.d.mts +14 -36
  83. package/dist/server.d.mts.map +1 -1
  84. package/dist/server.mjs +5 -5
  85. package/dist/server.mjs.map +1 -1
  86. package/dist/storage-postgres.d.mts +9 -25
  87. package/dist/storage-postgres.d.mts.map +1 -1
  88. package/dist/storage-postgres.mjs +5 -4
  89. package/dist/storage-postgres.mjs.map +1 -1
  90. package/dist/tasks-Coh5N027.mjs +397 -0
  91. package/dist/tasks-Coh5N027.mjs.map +1 -0
  92. package/dist/{tasks-CYqrcaRO.d.mts → tasks-wb9M-bak.d.mts} +25 -41
  93. package/dist/tasks-wb9M-bak.d.mts.map +1 -0
  94. package/dist/thread-documents-DrHbaXqP.d.mts +119 -0
  95. package/dist/thread-documents-DrHbaXqP.d.mts.map +1 -0
  96. package/dist/{thread-handlers-DBAaU7BA.d.mts → thread-handlers-C3Iya92v.d.mts} +9 -40
  97. package/dist/thread-handlers-C3Iya92v.d.mts.map +1 -0
  98. package/dist/{tools-BvSovehT.mjs → tools-D0KBDolR.mjs} +677 -459
  99. package/dist/tools-D0KBDolR.mjs.map +1 -0
  100. package/dist/turn-survey-draft-B34lggSG.d.mts +185 -0
  101. package/dist/turn-survey-draft-B34lggSG.d.mts.map +1 -0
  102. package/dist/ui.css +1 -1
  103. package/dist/ui.d.mts +15 -54
  104. package/dist/ui.d.mts.map +1 -1
  105. package/dist/ui.mjs +203 -156
  106. package/dist/ui.mjs.map +1 -1
  107. package/docs/integration.md +11 -1
  108. package/package.json +41 -36
  109. package/dist/authoring-references-BJQ_1nMX.mjs.map +0 -1
  110. package/dist/capabilities-1KNnNO1_.mjs +0 -73
  111. package/dist/capabilities-1KNnNO1_.mjs.map +0 -1
  112. package/dist/capabilities-DVTfogjv.d.mts +0 -193
  113. package/dist/capabilities-DVTfogjv.d.mts.map +0 -1
  114. package/dist/capabilities-default.mjs.map +0 -1
  115. package/dist/constants-Be91Gay9.d.mts.map +0 -1
  116. package/dist/controller-proxy-BH05e-C2.mjs.map +0 -1
  117. package/dist/controller-proxy-Bd0ZHBPF.d.mts +0 -85
  118. package/dist/controller-proxy-Bd0ZHBPF.d.mts.map +0 -1
  119. package/dist/digest-SJmoYVaK.d.mts.map +0 -1
  120. package/dist/engine-Bo85Oyj0.mjs +0 -6723
  121. package/dist/engine-Bo85Oyj0.mjs.map +0 -1
  122. package/dist/index-Tnqv-yKW.d.mts +0 -777
  123. package/dist/index-Tnqv-yKW.d.mts.map +0 -1
  124. package/dist/index-l_EK4yK7.d.mts.map +0 -1
  125. package/dist/index-nhrgbgO5.d.mts.map +0 -1
  126. package/dist/index-x0qprHgK.d.mts.map +0 -1
  127. package/dist/lifecycle-Bx0aq_4S.d.mts +0 -529
  128. package/dist/lifecycle-Bx0aq_4S.d.mts.map +0 -1
  129. package/dist/memory-thread-repository-KWHQWFEW.mjs.map +0 -1
  130. package/dist/protocol-BhzQbx81.mjs +0 -1173
  131. package/dist/protocol-BhzQbx81.mjs.map +0 -1
  132. package/dist/react-B3ybjJ-X.mjs.map +0 -1
  133. package/dist/references/embedded-forms.md +0 -126
  134. package/dist/references/item-types.md +0 -407
  135. package/dist/request-context-CG4SWijt.mjs.map +0 -1
  136. package/dist/request-guardrails-TmgQtqp4.mjs.map +0 -1
  137. package/dist/server-tasks.mjs.map +0 -1
  138. package/dist/tasks-CYqrcaRO.d.mts.map +0 -1
  139. package/dist/thread-documents-rmd6nyX9.d.mts +0 -107
  140. package/dist/thread-documents-rmd6nyX9.d.mts.map +0 -1
  141. package/dist/thread-handlers-DBAaU7BA.d.mts.map +0 -1
  142. package/dist/tools-BvSovehT.mjs.map +0 -1
@@ -4,4 +4,4 @@ const SURVEY_ASSISTANT_TASK_AGENT_ID = "survey-assistant-task-agent";
4
4
  //#endregion
5
5
  export { SURVEY_ASSISTANT_TASK_AGENT_ID as n, SURVEY_ASSISTANT_AGENT_ID as t };
6
6
 
7
- //# sourceMappingURL=constants-0UHGFcRJ.mjs.map
7
+ //# sourceMappingURL=constants-Ct-vv9cu.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants-0UHGFcRJ.mjs","names":[],"sources":["../src/server/constants.ts"],"sourcesContent":["export const SURVEY_ASSISTANT_AGENT_ID = \"survey-assistant-agent\";\nexport const SURVEY_ASSISTANT_TASK_AGENT_ID = \"survey-assistant-task-agent\";\n"],"mappings":";AAAA,MAAa,4BAA4B;AACzC,MAAa,iCAAiC"}
1
+ {"version":3,"file":"constants-Ct-vv9cu.mjs","names":[],"sources":["../src/server/constants.ts"],"sourcesContent":["export const SURVEY_ASSISTANT_AGENT_ID = \"survey-assistant-agent\";\nexport const SURVEY_ASSISTANT_TASK_AGENT_ID = \"survey-assistant-task-agent\";\n"],"mappings":";AAAA,MAAa,4BAA4B;AACzC,MAAa,iCAAiC"}
@@ -1,14 +1,11 @@
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
- import { n as SurveyAssistantModelAttachment, t as SurveyAssistantAttachmentAccess } from "./thread-documents-rmd6nyX9.mjs";
1
+ import "./index-DYHdvSE8.mjs";
2
+ import { Ct as SurveyDocumentVersion, St as SurveyDocumentSnapshot, o as SurveyAssistantApplyOutcome } from "./lifecycle-DFzxVxpq.mjs";
3
+ import { _ as SurveyAssistantCapabilitySet, i as SurveyAssistantEngineContext, n as TurnSurveyDraft } from "./turn-survey-draft-B34lggSG.mjs";
4
+ import { r as SurveyAssistantModelAttachment, t as SurveyAssistantAttachmentAccess } from "./thread-documents-DrHbaXqP.mjs";
4
5
  import { RequestContext } from "@mastra/core/request-context";
5
6
  import { AgentExecutionOptions } from "@mastra/core/agent";
6
7
  import { OpenAICompatibleConfig } from "@mastra/core/llm";
7
-
8
8
  //#region src/server/request-context.d.ts
9
- interface SurveyAssistantInvocationContext {
10
- kind: "chat";
11
- }
12
9
  interface SurveyAssistantIdentityContext {
13
10
  authority: "experimental-client-request" | "authenticated-host";
14
11
  resourceId: string;
@@ -41,18 +38,13 @@ type SurveyAssistantDocumentTransition = {
41
38
  capabilitiesChanged: boolean;
42
39
  };
43
40
  interface SurveyAssistantRequestContext {
44
- invocation: SurveyAssistantInvocationContext;
45
41
  turnId: string;
46
42
  turnDraft: TurnSurveyDraft;
47
43
  identity: SurveyAssistantIdentityContext;
48
- authenticatedResourceId?: string;
49
- authorizedThreadId?: string;
50
- applyPolicy?: "auto" | "review" | "deny";
51
44
  mastra__resourceId?: string;
52
45
  mastra__threadId?: string;
53
46
  documentTransition?: SurveyAssistantDocumentTransition;
54
47
  engineContext?: SurveyAssistantEngineContext;
55
- documentSnapshot?: SurveyDocumentSnapshot;
56
48
  modelAttachments?: SurveyAssistantModelAttachment[];
57
49
  attachmentAccess?: SurveyAssistantAttachmentAccess;
58
50
  modelSelection?: SurveyAssistantModelSelection;
@@ -61,24 +53,11 @@ interface SurveyAssistantRequestContext {
61
53
  declare const parseSurveyAssistantSnapshot: (value: unknown) => SurveyDocumentSnapshot | null;
62
54
  declare const parseSurveyAssistantPreviousSettledVersion: (value: unknown) => SurveyDocumentVersion | null;
63
55
  declare const parseSurveyAssistantPreviousApplyOutcome: (value: unknown) => SurveyAssistantApplyOutcome | null;
64
- declare const deriveSurveyAssistantDocumentTransition: ({
65
- current,
66
- previous
67
- }: {
56
+ declare const deriveSurveyAssistantDocumentTransition: ({ current, previous }: {
68
57
  current: SurveyDocumentSnapshot | null;
69
58
  previous: SurveyDocumentVersion | null;
70
59
  }) => SurveyAssistantDocumentTransition | undefined;
71
- declare const buildSurveyAssistantRequestContext: ({
72
- turnDraft,
73
- identity,
74
- snapshot,
75
- previousSettledVersion,
76
- trustedCapabilities,
77
- attachmentAccess,
78
- modelAttachments,
79
- modelSelection,
80
- previousApplyOutcome
81
- }: {
60
+ declare const buildSurveyAssistantRequestContext: ({ turnDraft, identity, snapshot, previousSettledVersion, trustedCapabilities, attachmentAccess, modelAttachments, modelSelection, previousApplyOutcome }: {
82
61
  turnDraft: TurnSurveyDraft;
83
62
  identity: SurveyAssistantIdentityContext;
84
63
  snapshot: SurveyDocumentSnapshot | null;
@@ -99,4 +78,4 @@ declare const SURVEY_ASSISTANT_AGENT_ID = "survey-assistant-agent";
99
78
  declare const SURVEY_ASSISTANT_TASK_AGENT_ID = "survey-assistant-task-agent";
100
79
  //#endregion
101
80
  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-Be91Gay9.d.mts.map
81
+ //# sourceMappingURL=constants-HL_klgJl.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants-HL_klgJl.d.mts","names":[],"sources":["../src/server/request-context.ts","../src/server/constants.ts"],"mappings":";;;;;;;;UA2BiB;EACf;EACA;EACA;EACA;;UAGe;EACf;EACA,gBAAgB;EAChB;EACA,kBAAkB;;KAGR;EACN;;EAEA;EACA;EACA;;EAGA;EACA;EACA;EACA;;EAGA;EACA;EACA;EACA;EACA,iBAAiB;EACjB;;UAGW;EACf;EACA,WAAW;EACX,UAAU;EACV;EACA;EACA,qBAAqB;EACrB,gBAAgB;EAChB,mBAAmB;EACnB,mBAAmB;EACnB,iBAAiB;EACjB,uBAAuB;;cAGZ,+BAAgC,mBAAiB;cAQjD,6CACX,mBACC;cAQU,2CACX,mBACC;cAQU,4CAA2C,SAAA;EAItD,SAAS;EACT,UAAU;MACR;cAqDS,uCAAsC,WAAA,UAAA,UAAA,wBAAA,qBAAA,kBAAA,kBAAA,gBAAA;EAWjD,WAAW;EACX,UAAU;EACV,UAAU;EACV,yBAAyB;EACzB,sBAAsB;EACtB,mBAAmB;EACnB,mBAAmB;EACnB,iBAAiB;EACjB,uBAAuB;MACrB,eAAe;cAiDN,kCACX,gBAAgB,eAAe;;;;;;cC1OpB;cACA"}
@@ -1,4 +1,4 @@
1
- import { Mt as parseSurveyAssistantError, O as surveyAssistantTranslateContentResultSchema, b as surveyAssistantSuggestItemLabelResultSchema, jt as isSurveyAssistantErrorRetryable, v as surveyAssistantSuggestItemKeyResultSchema } from "./protocol-BhzQbx81.mjs";
1
+ import { A as surveyAssistantTranslateContentResultSchema, J as isSurveyAssistantErrorRetryable, S as surveyAssistantSuggestResponseSettingsResultSchema, Y as parseSurveyAssistantError, b as surveyAssistantSuggestResponseNameResultSchema, v as surveyAssistantSuggestItemLabelResultSchema } from "./protocol-BQ7uIDYT.mjs";
2
2
  //#region src/react/client-error.ts
3
3
  var SurveyAssistantClientError = class extends Error {
4
4
  code;
@@ -42,10 +42,11 @@ const readSurveyAssistantJson = async (response, fallback = "The assistant reque
42
42
  //#endregion
43
43
  //#region src/react/thread-launcher.ts
44
44
  const launcherStates = /* @__PURE__ */ new WeakMap();
45
- const applySurveyAssistantLaunchUIContext = (snapshot, uiContext) => snapshot && uiContext ? {
45
+ const applySurveyAssistantLaunchUIContext = (snapshot, uiContext, threadTask) => snapshot && (uiContext || threadTask) ? {
46
46
  ...snapshot,
47
47
  ui: {
48
48
  ...snapshot.ui,
49
+ ...threadTask ? { task: threadTask } : {},
49
50
  ...uiContext
50
51
  }
51
52
  } : snapshot;
@@ -109,9 +110,9 @@ const connectSurveyAssistantThreadLauncher = (launcher, handler) => {
109
110
  };
110
111
  //#endregion
111
112
  //#region src/react/task-client.ts
112
- const createSurveyAssistantTaskClient = ({ api = "/api/survey-assistant/tasks", getModelId, resourceId, surveyId } = {}) => {
113
+ const createSurveyAssistantTaskClient = ({ api = "/api/survey-assistant/tasks", resourceId, surveyId } = {}) => {
113
114
  const run = async (taskId, input, context, options) => {
114
- const modelId = options?.modelId ?? getModelId?.();
115
+ const modelId = options?.modelId;
115
116
  return readSurveyAssistantJson(await fetch(api, {
116
117
  body: JSON.stringify({
117
118
  taskId,
@@ -128,8 +129,11 @@ const createSurveyAssistantTaskClient = ({ api = "/api/survey-assistant/tasks",
128
129
  }), "The survey assistant task could not be completed.");
129
130
  };
130
131
  return {
131
- async suggestItemKey(input, context, options) {
132
- return surveyAssistantSuggestItemKeyResultSchema.parse(await run("suggest-item-key", input, context, options));
132
+ async suggestResponseSettings(input, context, options) {
133
+ return surveyAssistantSuggestResponseSettingsResultSchema.parse(await run("suggest-response-settings", input, context, options));
134
+ },
135
+ async suggestResponseName(input, context, options) {
136
+ return surveyAssistantSuggestResponseNameResultSchema.parse(await run("suggest-response-name", input, context, options));
133
137
  },
134
138
  async suggestItemLabel(input, context, options) {
135
139
  return surveyAssistantSuggestItemLabelResultSchema.parse(await run("suggest-item-label", input, context, options));
@@ -139,19 +143,6 @@ const createSurveyAssistantTaskClient = ({ api = "/api/survey-assistant/tasks",
139
143
  }
140
144
  };
141
145
  };
142
- const createSurveyAssistantTaskExecutor = (options = {}) => {
143
- const client = createSurveyAssistantTaskClient(options);
144
- const executionOptions = (request, cache) => ({
145
- mode: request?.mode,
146
- modelId: cache?.cacheScope,
147
- signal: request?.signal
148
- });
149
- return {
150
- suggestItemKey: (input, context, request, cache) => client.suggestItemKey(input, context, executionOptions(request, cache)),
151
- suggestItemLabel: (input, context, request, cache) => client.suggestItemLabel(input, context, executionOptions(request, cache)),
152
- translateContent: (input, context, request, cache) => client.translateContent(input, context, executionOptions(request, cache))
153
- };
154
- };
155
146
  //#endregion
156
147
  //#region src/react/controller-proxy.ts
157
148
  const failedResult = (change, message) => ({
@@ -179,6 +170,6 @@ const createSurveyAssistantControllerBridge = (options) => {
179
170
  };
180
171
  };
181
172
  //#endregion
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 };
173
+ export { connectSurveyAssistantThreadLauncher as a, readSurveyAssistantJson as c, applySurveyAssistantLaunchUIContext as i, createSurveyAssistantControllerProxy as n, createSurveyAssistantThreadLauncher as o, createSurveyAssistantTaskClient as r, SurveyAssistantClientError as s, createSurveyAssistantControllerBridge as t };
183
174
 
184
- //# sourceMappingURL=controller-proxy-BH05e-C2.mjs.map
175
+ //# sourceMappingURL=controller-proxy-BQ1YsVxJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller-proxy-BQ1YsVxJ.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 SurveyEditorUITask,\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 /** Opening-turn context. Its task is also persisted on the created thread. */\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 threadTask?: SurveyEditorUITask,\n): SurveyAssistantSnapshot | null =>\n snapshot && (uiContext || threadTask)\n ? {\n ...snapshot,\n ui: {\n ...snapshot.ui,\n ...(threadTask ? { task: threadTask } : {}),\n ...uiContext,\n },\n }\n : snapshot;\n\nconst getLauncherState = (launcher: SurveyAssistantThreadLauncher) => {\n const state = launcherStates.get(launcher);\n if (!state) {\n throw new Error(\n \"The survey assistant thread launcher was not created by createSurveyAssistantThreadLauncher.\",\n );\n }\n return state;\n};\n\nconst drainPendingLaunches = async (state: LauncherState) => {\n if (state.draining) return;\n state.draining = true;\n try {\n while (state.handler && state.pending.length > 0) {\n const pending = state.pending.shift();\n if (!pending) continue;\n try {\n pending.resolve(await state.handler(pending.input));\n } catch (error) {\n pending.reject(error);\n }\n }\n } finally {\n state.draining = false;\n }\n};\n\nexport const createSurveyAssistantThreadLauncher = (): SurveyAssistantThreadLauncher => {\n const state: LauncherState = { handler: null, pending: [], draining: false };\n const launcher: SurveyAssistantThreadLauncher = {\n startThread(input) {\n const prompt = input.prompt.trim();\n if (!prompt && (input.files?.length ?? 0) === 0) {\n return Promise.reject(new Error(\"A survey assistant prompt or attachment is required.\"));\n }\n\n return new Promise((resolve, reject) => {\n state.pending.push({\n input: {\n ...input,\n prompt,\n ...(input.files ? { files: [...input.files] } : {}),\n ...(input.modelId ? { modelId: input.modelId.trim() } : {}),\n ...(input.title ? { title: input.title.trim() } : {}),\n },\n reject,\n resolve,\n });\n void drainPendingLaunches(state);\n });\n },\n };\n launcherStates.set(launcher, state);\n return launcher;\n};\n\nexport const connectSurveyAssistantThreadLauncher = (\n launcher: SurveyAssistantThreadLauncher,\n handler: LaunchHandler,\n) => {\n const state = getLauncherState(launcher);\n if (state.handler && state.handler !== handler) {\n throw new Error(\"A survey assistant thread launcher can only control one mounted panel.\");\n }\n state.handler = handler;\n void drainPendingLaunches(state);\n\n return () => {\n if (state.handler === handler) state.handler = null;\n };\n};\n","import {\n surveyAssistantSuggestResponseSettingsResultSchema,\n type SurveyAssistantSuggestResponseSettingsInput,\n type SurveyAssistantSuggestResponseSettingsResult,\n} from \"../protocol/tasks\";\nimport {\n surveyAssistantSuggestResponseNameResultSchema,\n surveyAssistantSuggestItemLabelResultSchema,\n surveyAssistantTranslateContentResultSchema,\n type SurveyAssistantSuggestResponseNameInput,\n type SurveyAssistantSuggestResponseNameResult,\n type SurveyAssistantSuggestItemLabelInput,\n type SurveyAssistantSuggestItemLabelResult,\n type SurveyAssistantTaskContext,\n type SurveyAssistantTaskInvocationMode,\n type SurveyAssistantTranslateContentInput,\n type SurveyAssistantTranslateContentResult,\n} from \"../protocol\";\nimport { readSurveyAssistantJson } from \"./client-error\";\n\nexport interface SurveyAssistantTaskClientOptions {\n api?: string;\n resourceId?: string;\n surveyId?: string;\n}\n\nexport interface SurveyAssistantTaskExecutionOptions {\n mode?: SurveyAssistantTaskInvocationMode;\n modelId?: string;\n signal?: AbortSignal;\n}\n\nexport interface SurveyAssistantTaskClient {\n suggestResponseSettings(\n input: SurveyAssistantSuggestResponseSettingsInput,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutionOptions,\n ): Promise<SurveyAssistantSuggestResponseSettingsResult>;\n suggestResponseName(\n input: SurveyAssistantSuggestResponseNameInput,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutionOptions,\n ): Promise<SurveyAssistantSuggestResponseNameResult>;\n suggestItemLabel(\n input: SurveyAssistantSuggestItemLabelInput,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutionOptions,\n ): Promise<SurveyAssistantSuggestItemLabelResult>;\n translateContent(\n input: SurveyAssistantTranslateContentInput,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutionOptions,\n ): Promise<SurveyAssistantTranslateContentResult>;\n}\n\nexport const createSurveyAssistantTaskClient = ({\n api = \"/api/survey-assistant/tasks\",\n resourceId,\n surveyId,\n}: SurveyAssistantTaskClientOptions = {}): SurveyAssistantTaskClient => {\n const run = async (\n taskId:\n | \"suggest-response-settings\"\n | \"suggest-response-name\"\n | \"suggest-item-label\"\n | \"translate-content\",\n input: unknown,\n context: SurveyAssistantTaskContext,\n options?: SurveyAssistantTaskExecutionOptions,\n ) => {\n const modelId = options?.modelId;\n return readSurveyAssistantJson(\n await fetch(api, {\n body: JSON.stringify({\n taskId,\n input,\n context,\n ...(options?.mode ? { mode: options.mode } : {}),\n ...(modelId ? { modelId } : {}),\n ...(resourceId ? { resourceId } : {}),\n ...(surveyId ? { surveyId } : {}),\n }),\n headers: { \"content-type\": \"application/json\" },\n method: \"POST\",\n signal: options?.signal,\n }),\n \"The survey assistant task could not be completed.\",\n );\n };\n\n return {\n async suggestResponseSettings(input, context, options) {\n return surveyAssistantSuggestResponseSettingsResultSchema.parse(\n await run(\"suggest-response-settings\", input, context, options),\n );\n },\n async suggestResponseName(input, context, options) {\n return surveyAssistantSuggestResponseNameResultSchema.parse(\n await run(\"suggest-response-name\", input, context, options),\n );\n },\n async suggestItemLabel(input, context, options) {\n return surveyAssistantSuggestItemLabelResultSchema.parse(\n await run(\"suggest-item-label\", input, context, options),\n );\n },\n async translateContent(input, context, options) {\n return surveyAssistantTranslateContentResultSchema.parse(\n await run(\"translate-content\", input, context, options),\n );\n },\n };\n};\n","import type { SurveyApplyResult, SurveyBatchApplyResult, SurveyChangeSet } from \"../protocol\";\nimport type { SurveyAssistantController } from \"./controller\";\n\nexport interface CreateSurveyAssistantControllerProxyOptions {\n notReadyMessage?: string;\n}\n\nexport interface SurveyAssistantControllerBridge {\n controller: SurveyAssistantController;\n setController(controller: SurveyAssistantController | null | undefined): void;\n}\n\nconst failedResult = (change: SurveyChangeSet, message: string): SurveyApplyResult => ({\n status: \"failed\",\n changeId: change.id,\n summary: change.summary,\n message,\n appliedOperations: 0,\n});\n\nexport const createSurveyAssistantControllerProxy = (\n getController: () => SurveyAssistantController | null | undefined,\n {\n notReadyMessage = \"The survey editor is not ready.\",\n }: CreateSurveyAssistantControllerProxyOptions = {},\n): SurveyAssistantController => ({\n getSnapshot: () => getController()?.getSnapshot() ?? null,\n applyAssistantChanges: (changes): SurveyBatchApplyResult => {\n const controller = getController();\n if (!controller) {\n return { results: changes.map((change) => failedResult(change, notReadyMessage)) };\n }\n return controller.applyAssistantChanges(changes);\n },\n});\n\nexport const createSurveyAssistantControllerBridge = (\n options?: CreateSurveyAssistantControllerProxyOptions,\n): SurveyAssistantControllerBridge => {\n let currentController: SurveyAssistantController | null | undefined;\n return {\n controller: createSurveyAssistantControllerProxy(() => currentController, options),\n setController(controller) {\n currentController = controller;\n },\n };\n};\n"],"mappings":";;AAOA,IAAa,6BAAb,cAAgD,MAAM;CACpD;CACA;CACA;CACA;CACA;CAEA,YACE,MACA,SACA,YAAY,OACZ,cAGI,CAAC,GACL;EACA,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,YAAY;EACjB,KAAK,iBAAiB,YAAY;EAClC,KAAK,oBAAoB,YAAY;EACrC,KAAK,kBAAkB,YAAY;CACrC;AACF;AAEA,MAAa,0BAA0B,OACrC,UACA,WAAW,oDACR;CACH,IAAI,CAAC,SAAS,IAAI;EAChB,MAAM,eAAe,MAAM,SAAS,KAAK,CAAC,CAAC,YAAY,EAAE;EACzD,IAAI;EACJ,IAAI;GACF,OAAO,eAAe,KAAK,MAAM,YAAY,IAAI,KAAA;EACnD,QAAQ;GACN,OAAO,KAAA;EACT;EACA,MAAM,SACJ,OAAO,SAAS,YAAY,SAAS,QAAQ,WAAW,QAAQ,OAAO,KAAK,UAAU,WAClF,KAAK,QACL,aAAa,KAAK,KAAK;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,oBACL,KAAA;GACN,iBACE,qBAAqB,QAAQ,OAAO,KAAK,oBAAoB,WACzD,KAAK,kBACL,KAAA;EACR,IACA,MACN;EACA,MAAM,YAAY,gCAAgC,QAAQ,SAAS,MAAM;EACzE,MAAM,IAAI,2BA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,CAC5D;EACF;EACA,MAAM,iBAAiB,OAAO,SAAS,SAAS;GAC9C,OAAO,4CAA4C,MACjD,MAAM,IAAI,sBAAsB,OAAO,SAAS,OAAO,CACzD;EACF;EACA,MAAM,iBAAiB,OAAO,SAAS,SAAS;GAC9C,OAAO,4CAA4C,MACjD,MAAM,IAAI,qBAAqB,OAAO,SAAS,OAAO,CACxD;EACF;CACF;AACF;;;ACpGA,MAAM,gBAAgB,QAAyB,aAAwC;CACrF,QAAQ;CACR,UAAU,OAAO;CACjB,SAAS,OAAO;CAChB;CACA,mBAAmB;AACrB;AAEA,MAAa,wCACX,eACA,EACE,kBAAkB,sCAC6B,CAAC,OACnB;CAC/B,mBAAmB,cAAc,CAAC,EAAE,YAAY,KAAK;CACrD,wBAAwB,YAAoC;EAC1D,MAAM,aAAa,cAAc;EACjC,IAAI,CAAC,YACH,OAAO,EAAE,SAAS,QAAQ,KAAK,WAAW,aAAa,QAAQ,eAAe,CAAC,EAAE;EAEnF,OAAO,WAAW,sBAAsB,OAAO;CACjD;AACF;AAEA,MAAa,yCACX,YACoC;CACpC,IAAI;CACJ,OAAO;EACL,YAAY,2CAA2C,mBAAmB,OAAO;EACjF,cAAc,YAAY;GACxB,oBAAoB;EACtB;CACF;AACF"}
@@ -0,0 +1,65 @@
1
+ import { G as SurveyAssistantThread, b as SurveyAssistantTranslateContentInput, c as SurveyAssistantSuggestItemLabelInput, d as SurveyAssistantSuggestResponseNameResult, f as SurveyAssistantSuggestResponseSettingsInput, g as SurveyAssistantTaskInvocationMode, h as SurveyAssistantTaskContext, l as SurveyAssistantSuggestItemLabelResult, p as SurveyAssistantSuggestResponseSettingsResult, u as SurveyAssistantSuggestResponseNameInput, x as SurveyAssistantTranslateContentResult } from "./index-DYHdvSE8.mjs";
2
+ import { bt as SurveyAssistantSnapshot, h as SurveyChangeSet, m as SurveyBatchApplyResult, wt as SurveyEditorUIContext } from "./lifecycle-DFzxVxpq.mjs";
3
+ import { FileUIPart } from "ai";
4
+ //#region src/react/thread-launcher.d.ts
5
+ type SurveyAssistantLaunchUIContext = Partial<Omit<SurveyEditorUIContext, "history">>;
6
+ interface SurveyAssistantThreadLaunch {
7
+ /** User-visible prompt submitted as the first message in the new thread. */
8
+ prompt: string;
9
+ files?: FileUIPart[];
10
+ /** Optional model used for the opening assistant turn. */
11
+ modelId?: string;
12
+ /** Optional manual thread title. The prompt-derived automatic title is used by default. */
13
+ title?: string;
14
+ /** Opening-turn context. Its task is also persisted on the created thread. */
15
+ uiContext?: SurveyAssistantLaunchUIContext;
16
+ }
17
+ interface SurveyAssistantThreadLauncher {
18
+ /**
19
+ * Creates a new thread and submits its first prompt when a connected panel is ready.
20
+ * Calls made before the panel mounts are queued.
21
+ */
22
+ startThread(input: SurveyAssistantThreadLaunch): Promise<SurveyAssistantThread>;
23
+ }
24
+ declare const createSurveyAssistantThreadLauncher: () => SurveyAssistantThreadLauncher;
25
+ //#endregion
26
+ //#region src/react/controller.d.ts
27
+ interface SurveyAssistantController {
28
+ /** Snapshot version.sessionId identifies the editor document session, independently of this wrapper's identity. */
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
34
+ //#region src/react/task-client.d.ts
35
+ interface SurveyAssistantTaskClientOptions {
36
+ api?: string;
37
+ resourceId?: string;
38
+ surveyId?: string;
39
+ }
40
+ interface SurveyAssistantTaskExecutionOptions {
41
+ mode?: SurveyAssistantTaskInvocationMode;
42
+ modelId?: string;
43
+ signal?: AbortSignal;
44
+ }
45
+ interface SurveyAssistantTaskClient {
46
+ suggestResponseSettings(input: SurveyAssistantSuggestResponseSettingsInput, context: SurveyAssistantTaskContext, options?: SurveyAssistantTaskExecutionOptions): Promise<SurveyAssistantSuggestResponseSettingsResult>;
47
+ suggestResponseName(input: SurveyAssistantSuggestResponseNameInput, context: SurveyAssistantTaskContext, options?: SurveyAssistantTaskExecutionOptions): Promise<SurveyAssistantSuggestResponseNameResult>;
48
+ suggestItemLabel(input: SurveyAssistantSuggestItemLabelInput, context: SurveyAssistantTaskContext, options?: SurveyAssistantTaskExecutionOptions): Promise<SurveyAssistantSuggestItemLabelResult>;
49
+ translateContent(input: SurveyAssistantTranslateContentInput, context: SurveyAssistantTaskContext, options?: SurveyAssistantTaskExecutionOptions): Promise<SurveyAssistantTranslateContentResult>;
50
+ }
51
+ declare const createSurveyAssistantTaskClient: ({ api, resourceId, surveyId }?: SurveyAssistantTaskClientOptions) => SurveyAssistantTaskClient;
52
+ //#endregion
53
+ //#region src/react/controller-proxy.d.ts
54
+ interface CreateSurveyAssistantControllerProxyOptions {
55
+ notReadyMessage?: string;
56
+ }
57
+ interface SurveyAssistantControllerBridge {
58
+ controller: SurveyAssistantController;
59
+ setController(controller: SurveyAssistantController | null | undefined): void;
60
+ }
61
+ declare const createSurveyAssistantControllerProxy: (getController: () => SurveyAssistantController | null | undefined, { notReadyMessage }?: CreateSurveyAssistantControllerProxyOptions) => SurveyAssistantController;
62
+ declare const createSurveyAssistantControllerBridge: (options?: CreateSurveyAssistantControllerProxyOptions) => SurveyAssistantControllerBridge;
63
+ //#endregion
64
+ export { SurveyAssistantTaskClient as a, createSurveyAssistantTaskClient as c, SurveyAssistantThreadLaunch as d, SurveyAssistantThreadLauncher as f, createSurveyAssistantControllerProxy as i, SurveyAssistantController as l, SurveyAssistantControllerBridge as n, SurveyAssistantTaskClientOptions as o, createSurveyAssistantThreadLauncher as p, createSurveyAssistantControllerBridge as r, SurveyAssistantTaskExecutionOptions as s, CreateSurveyAssistantControllerProxyOptions as t, SurveyAssistantLaunchUIContext as u };
65
+ //# sourceMappingURL=controller-proxy-Cmzdr9tV.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller-proxy-Cmzdr9tV.d.mts","names":[],"sources":["../src/react/thread-launcher.ts","../src/react/controller.ts","../src/react/task-client.ts","../src/react/controller-proxy.ts"],"mappings":";;;;KAQY,iCAAiC,QAAQ,KAAK;UAEzC;;EAEf;EACA,QAAQ;;EAER;;EAEA;;EAEA,YAAY;;UAGG;;;;;EAKf,YAAY,OAAO,8BAA8B,QAAQ;;cA+D9C,2CAA0C;;;UCxFtC;;EAEf,eAAe;;EAEf,sBAAsB,SAAS,oBAAoB;;;;UCcpC;EACf;EACA;EACA;;UAGe;EACf,OAAO;EACP;EACA,SAAS;;UAGM;EACf,wBACE,OAAO,6CACP,SAAS,4BACT,UAAU,sCACT,QAAQ;EACX,oBACE,OAAO,yCACP,SAAS,4BACT,UAAU,sCACT,QAAQ;EACX,iBACE,OAAO,sCACP,SAAS,4BACT,UAAU,sCACT,QAAQ;EACX,iBACE,OAAO,sCACP,SAAS,4BACT,UAAU,sCACT,QAAQ;;cAGA,oCAAmC,KAAA,YAAA,aAI7C,qCAAwC;;;UCxD1B;EACf;;UAGe;EACf,YAAY;EACZ,cAAc,YAAY;;cAWf,uCACX,qBAAqB,gDACrB,oBAEG,gDACF;cAWU,wCACX,UAAU,gDACT"}
@@ -0,0 +1,233 @@
1
+ import { V as jsonValueSchema, r as assistantElementTypeManifestSchema } from "./capabilities-D55dq-fO.mjs";
2
+ import { buildCapabilityDigest, stableStringify } from "./digest.mjs";
3
+ import { generateId } from "@case-framework/survey-core";
4
+ import { createBuiltInElement, createChoiceMatrixPreset, defaultElementRegistry } from "@case-framework/survey-items";
5
+ import { allocateCopiedResponseNames } from "@case-framework/survey-core/editor";
6
+ import { choiceMatrixConfigSchema, getChoiceMatrixConfigIssues } from "@case-framework/survey-items/choice-matrix";
7
+ //#region src/engine/capabilities.ts
8
+ const resolveAssistantCapabilityReference = ({ capabilities, elementType, topic }) => capabilities?.byElementType.get(elementType)?.references?.find((reference) => reference.topic === topic);
9
+ const inspectAssistantElement = ({ capabilities, element }) => {
10
+ const capability = capabilities?.byElementType.get(element.elementType);
11
+ if (!capabilities || !capability?.inspectElement) return void 0;
12
+ const parsed = capabilities.registry.get(element.elementType).schema.safeParse(element);
13
+ if (!parsed.success) return {
14
+ summary: `${capability.manifest.displayName} configuration needs repair.`,
15
+ details: { issues: parsed.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`) }
16
+ };
17
+ return capability.inspectElement(parsed.data);
18
+ };
19
+ function createSurveyAssistantCapabilities(registry, capabilities) {
20
+ const supplied = /* @__PURE__ */ new Map();
21
+ for (const capability of capabilities) {
22
+ const manifest = assistantElementTypeManifestSchema.parse(capability.manifest);
23
+ if (supplied.has(manifest.elementType)) throw new Error(`Duplicate survey assistant capability for element type "${manifest.elementType}".`);
24
+ registry.get(manifest.elementType);
25
+ if (manifest.create === "deterministic" && !manifest.supportedOperations.includes("create-item")) throw new Error(`Deterministically creatable element "${manifest.elementType}" must support creation inside a content item.`);
26
+ if (manifest.creationPresets?.length && !capability.materializePreset) throw new Error(`Element "${manifest.elementType}" declares presets without a trusted materializer.`);
27
+ const topics = new Set(manifest.referenceTopics ?? []);
28
+ for (const reference of capability.references ?? []) if (!topics.has(reference.topic)) throw new Error(`Capability reference "${reference.topic}" for "${manifest.elementType}" is not declared.`);
29
+ supplied.set(manifest.elementType, {
30
+ ...capability,
31
+ manifest
32
+ });
33
+ }
34
+ const byElementType = new Map(registry.definitions.map((definition) => [definition.elementType, supplied.get(definition.elementType) ?? createUnsupportedElementCapability({
35
+ elementType: definition.elementType,
36
+ displayName: definition.labelByLocale?.en ?? Object.values(definition.labelByLocale ?? {})[0] ?? definition.elementType
37
+ })]));
38
+ const elementTypes = [...byElementType.values()].map((adapter) => structuredClone(adapter.manifest)).sort((a, b) => a.elementType.localeCompare(b.elementType));
39
+ return {
40
+ registry,
41
+ byElementType,
42
+ manifest: {
43
+ elementTypes,
44
+ digest: buildCapabilityDigest({ elementTypes })
45
+ }
46
+ };
47
+ }
48
+ const getDeterministicCreateElementTypes = (manifest) => manifest.elementTypes.filter((entry) => entry.create === "deterministic").map((entry) => entry.elementType);
49
+ const createUnsupportedElementCapability = ({ displayName, elementType }) => ({ manifest: {
50
+ elementType,
51
+ displayName,
52
+ capabilityVersion: "unsupported-v1",
53
+ create: "unsupported",
54
+ supportedOperations: []
55
+ } });
56
+ var SurveyAssistantCapabilityMismatchError = class extends Error {
57
+ code = "survey-assistant-capability-mismatch";
58
+ constructor(message = "Survey assistant capabilities changed; start a fresh turn and retry.") {
59
+ super(message);
60
+ this.name = "SurveyAssistantCapabilityMismatchError";
61
+ }
62
+ };
63
+ const assertSurveyAssistantCapabilities = ({ manifest, trustedCapabilities, versionDigest }) => {
64
+ const { digest, ...body } = manifest;
65
+ if (digest !== buildCapabilityDigest(body) || versionDigest !== digest) throw new SurveyAssistantCapabilityMismatchError();
66
+ if (trustedCapabilities && stableStringify(body.elementTypes) !== stableStringify(trustedCapabilities.manifest.elementTypes)) throw new SurveyAssistantCapabilityMismatchError("The editor and server use different survey assistant capabilities; refresh and retry.");
67
+ };
68
+ //#endregion
69
+ //#region src/capabilities/matrix-inspection.ts
70
+ const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
71
+ const PREVIEW_LIMIT = 12;
72
+ const describeList = (name, values) => `${name}: ${values.length}; ${JSON.stringify(values.slice(0, PREVIEW_LIMIT))}${values.length > PREVIEW_LIMIT ? " (first 12 shown; inspect full details for the rest)" : ""}.`;
73
+ /** Summarize authored state, not the model's claimed intent or respondent visibility. */
74
+ const summarizeMatrixState = (elementType, config) => {
75
+ if (elementType !== "formMatrix" && elementType !== "choiceMatrix" || !isRecord(config) || !Array.isArray(config.rows)) return "";
76
+ const rows = config.rows.map((row) => isRecord(row) ? {
77
+ id: row.id,
78
+ rowName: row.rowName
79
+ } : row);
80
+ const lines = ["Current authored matrix state (IDs/coding names, configured order):", describeList("Rows", rows)];
81
+ if (elementType === "formMatrix" && Array.isArray(config.columns) && Array.isArray(config.cells)) lines.push(describeList("Columns", config.columns.map((column) => isRecord(column) ? {
82
+ id: column.id,
83
+ columnName: column.columnName
84
+ } : column)), `Cells: ${config.cells.length}.`, describeList("Explicit cell overrides", config.cells.flatMap((cell) => isRecord(cell) && isRecord(cell.fieldOverride) ? [{
85
+ cellId: cell.id,
86
+ rowId: cell.rowId,
87
+ columnId: cell.columnId,
88
+ type: cell.fieldOverride.type,
89
+ ...cell.fieldOverride.type === "date" ? { precision: cell.fieldOverride.precision } : {}
90
+ }] : [])));
91
+ else if (elementType === "choiceMatrix" && Array.isArray(config.options)) {
92
+ lines.push(describeList("Regular option columns", config.options.map((option) => isRecord(option) ? option.id : option)));
93
+ for (const position of ["leading", "trailing"]) {
94
+ const option = config[`${position}NonScoring`];
95
+ lines.push(`${position} non-scoring option ID: ${isRecord(option) ? JSON.stringify(option.id) : "none"}.`);
96
+ }
97
+ }
98
+ return lines.join(" ");
99
+ };
100
+ //#endregion
101
+ //#region src/capabilities/default.ts
102
+ const commonOperations = [
103
+ "create-item",
104
+ "insert-element",
105
+ "insert-blocks",
106
+ "insert-preset",
107
+ "move-element",
108
+ "move-block",
109
+ "remove-content",
110
+ "update-layout",
111
+ "patch-element-config",
112
+ "update-response-settings",
113
+ "update-content",
114
+ "update-placed-image",
115
+ "patch-item-config",
116
+ "remove-item",
117
+ "move-item",
118
+ "reorder-items",
119
+ "survey-json-patch"
120
+ ];
121
+ const presets = {
122
+ "information.default": "information",
123
+ "text.short": "text",
124
+ "text.long": "longText",
125
+ "number.input": "number",
126
+ "number.slider": "slider",
127
+ "date.default": "date",
128
+ "boolean.radio": "boolean",
129
+ "boolean.switch": "switch",
130
+ "choice.radio": "radio",
131
+ "choice.checkbox": "checkbox",
132
+ "choice.dropdown": "dropdown",
133
+ "consent.default": "consent",
134
+ "formMatrix.default": "formMatrix"
135
+ };
136
+ const descriptions = {
137
+ information: { hint: "Rich content with no response slot. Use the body content role." },
138
+ text: { hint: "Short or long text input; use a label or an unambiguous enclosing title." },
139
+ number: { hint: "Localized numeric input or slider, with optional unit and constraints." },
140
+ date: { hint: "Calendar input with year, year-month or year-month-day precision; keep regional formatting separate." },
141
+ boolean: { hint: "Yes/no radio or switch. Appearance does not change the boolean response domain." },
142
+ choice: { hint: "Radio and checkbox lists are full-width and may own option-inline follow-ups. Dropdowns are compact and cannot own follow-ups." },
143
+ consent: { hint: "Explicit boolean decision with inline or dialog information and own/inherited semantic heading context." },
144
+ choiceMatrix: { hint: "Categorical row slots plus persisted score/sum slot IDs. Codes, option labels and scores are separate; preserve non-scoring options." },
145
+ formMatrix: { hint: "Independent cell slots with column defaults and per-cell overrides. Preserve row/column naming, date precision and cell-specific UI." }
146
+ };
147
+ const configSummaries = {
148
+ information: "Display-only element with empty config and rich body role. Use actual document content, not a placeholder or a description of absent content. Load rich-text-content for formatting and source-material-surveys when implementing supplied documents.",
149
+ text: "Config: slotId, variableName, presentation short|long; optional purpose text|email|tel|url|password, required, rows, autocomplete and validations. Roles label/help/placeholder/message; individual validation IDs own message. Use an explicit label or unambiguous enclosing title. A placeholder is not a label. Preserve source constraints and create real inputs for respondent blanks.",
150
+ number: "Config: slotId, variableName, presentation input|slider; optional step, min, max, showValue, required and validations (integer). min/max are a number or {expression, fallback?}; a missing expression value leaves the bound unapplied unless it has a fallback, and slider expression bounds need one. Roles label/help/placeholder/message/unit. Units are localized wording, not part of the numeric answer. Preserve requested bounds and step; do not invent domain limits. Slider and input share numeric semantics.",
151
+ date: "Config: slotId, variableName, precision year|year-month|year-month-day; optional required, min and max. Calendar values are YYYY, YYYY-MM or YYYY-MM-DD, never timestamps. Display format is independent of language and precision. min/max are a calendar string or {expression, fallback?}; a missing expression value leaves the bound unapplied unless it has a fallback. Use survey_expression for expression bounds and preserve precision.",
152
+ boolean: "Config: slotId, variableName, presentation radio|switch; optional required and validations. Roles include label/help/yesLabel/noLabel/message. False is a defined answer. Use get compared with true/false for conditions about the answer; isDefined means either answer exists. Do not substitute a switch for the consent document/decision experience.",
153
+ choice: "Config: slotId, variableName, presentation radio|checkbox|dropdown, options, optional required/shuffleOptions; checkbox maxSelection null=unlimited or positive cap. Options own label/description and optional visibility/disabled. Radio/checkbox may own followUp bodies, never dropdowns; load follow-ups for the complete example. Put option, body and owner-role translations in one creation/config edit. Use fresh IDs for new owners and preserve inspected IDs on edits. Response types: radio/dropdown reference, checkbox reference[]. Codes, labels and IDs are separate. Disabled selections remain active; use visibility for inapplicability and avoid self-locking exclusivity.",
154
+ consent: "Config: slotId, variableName, presentation inline|dialog, subtitleMode inherit|custom|none. Element label overrides the nearest semantic title; custom subtitle uses the element subtitle role. Body must contain actual terms, not a document description. Preserve supplied terms; otherwise draft proactively and report assumptions/gaps afterward. Optional acceptLabel/declineLabel, unansweredLabel/acceptedLabel/declinedLabel, reviewLabel/changeLabel override UI wording. True=agree, false=decline, absent=unanswered; isDefined does not mean accepted. No required setting or effects list. Load element-types for complete content and interaction guidance.",
155
+ choiceMatrix: "Config: prefix, rows with id/rowName/scoreSlotId, options with id/code/score, sumSlotId, layout. Presets are editable starting points; match anchors to the construct. Scores are all present or all absent; zero is a defined score. Leading/trailing non-scoring options are single objects, not arrays. Use row/option owner labels and element startLabel/endLabel for bipolar anchors. Preserve IDs on edits; reverse score values without reordering labels. Naming derives from prefix/rowName, never hand-rename computed slots. Load element-types before structural/scoring edits.",
156
+ formMatrix: "Config: prefix, rows, columns and complete persistent cells rectangle; field types text/number/date/dropdown/boolean/static/empty. Each cell has id/rowId/columnId and optional complete field override. Dates use mode; number unit is config text. Add/remove rows or columns with all associated cells in one patch. Duplicate every override with fresh nested IDs and copy all locale content; resetting an override restores column defaults. Preserve surviving IDs. Naming derives from prefix/rowName/columnName. Load element-types for effective field, ownership and duplication rules."
157
+ };
158
+ function createCapability(elementType) {
159
+ const info = Object.entries(descriptions).find(([type]) => type === elementType)?.[1];
160
+ const configSummary = Object.entries(configSummaries).find(([type]) => type === elementType)?.[1];
161
+ if (!info || !configSummary) throw new Error(`Missing built-in assistant guidance for ${elementType}`);
162
+ const available = elementType === "choiceMatrix" ? [
163
+ "yesNo",
164
+ "fivePoint",
165
+ "sevenPoint",
166
+ "bipolarFive"
167
+ ].map((id) => `choiceMatrix.${id}`) : Object.entries(presets).filter(([, type]) => (type === "longText" ? "text" : type === "slider" ? "number" : type === "switch" ? "boolean" : type === "radio" || type === "checkbox" || type === "dropdown" ? "choice" : type) === elementType).map(([id]) => id);
168
+ return {
169
+ manifest: {
170
+ elementType,
171
+ capabilityVersion: "composition-v1",
172
+ displayName: defaultElementRegistry.get(elementType).labelByLocale?.en ?? elementType,
173
+ description: info.hint,
174
+ create: "deterministic",
175
+ referenceTopics: [
176
+ "element-types",
177
+ "response-variables",
178
+ "expressions",
179
+ "localization",
180
+ "rich-text-content",
181
+ ...elementType === "choice" ? ["follow-ups"] : []
182
+ ],
183
+ supportedOperations: commonOperations,
184
+ creationPresets: available.map((id) => ({ id })),
185
+ authoring: {
186
+ compactHint: info.hint,
187
+ configSummary
188
+ }
189
+ },
190
+ materializePreset(presetId, locale, usedNames) {
191
+ if (!available.includes(presetId)) throw new Error(`Unknown preset "${presetId}" for "${elementType}".`);
192
+ let element;
193
+ let content;
194
+ if (elementType === "choiceMatrix") {
195
+ const name = presetId.slice(13);
196
+ if (name !== "yesNo" && name !== "fivePoint" && name !== "sevenPoint" && name !== "bipolarFive") throw new Error("Unknown matrix preset");
197
+ const preset = createChoiceMatrixPreset(name, locale);
198
+ element = {
199
+ id: generateId(),
200
+ kind: "element",
201
+ elementType,
202
+ config: preset.config
203
+ };
204
+ content = preset.content;
205
+ } else element = createBuiltInElement(presets[presetId], usedNames);
206
+ return {
207
+ element: allocateCopiedResponseNames(defaultElementRegistry.elementSchema, element, defaultElementRegistry, usedNames),
208
+ ...content ? { content } : {}
209
+ };
210
+ },
211
+ inspectElement(element) {
212
+ const config = jsonValueSchema.parse(element.config);
213
+ return {
214
+ summary: [summarizeMatrixState(elementType, config), info.hint].filter(Boolean).join(" ") + (elementType === "choice" ? config !== null && typeof config === "object" && !Array.isArray(config) && config.shuffleOptions === true ? " Options are listed in configured order; respondents see shuffled order." : " Option positions match respondent-visible order, with hidden options omitted." : ""),
215
+ details: config
216
+ };
217
+ },
218
+ ...elementType === "choiceMatrix" ? { validateElement(element) {
219
+ return getChoiceMatrixConfigIssues(choiceMatrixConfigSchema.parse(element.config)).map((message) => ({
220
+ severity: "error",
221
+ code: "invalid-matrix",
222
+ message
223
+ }));
224
+ } } : {}
225
+ };
226
+ }
227
+ const defaultSurveyAssistantCapabilities = defaultElementRegistry.definitions.map((definition) => createCapability(definition.elementType));
228
+ const defaultSurveyAssistantCapabilitySet = createSurveyAssistantCapabilities(defaultElementRegistry, defaultSurveyAssistantCapabilities);
229
+ const getDefaultSurveyAssistantCapability = (elementType) => defaultSurveyAssistantCapabilitySet.byElementType.get(elementType);
230
+ //#endregion
231
+ export { assertSurveyAssistantCapabilities as a, getDeterministicCreateElementTypes as c, SurveyAssistantCapabilityMismatchError as i, inspectAssistantElement as l, defaultSurveyAssistantCapabilitySet as n, createSurveyAssistantCapabilities as o, getDefaultSurveyAssistantCapability as r, createUnsupportedElementCapability as s, defaultSurveyAssistantCapabilities as t, resolveAssistantCapabilityReference as u };
232
+
233
+ //# sourceMappingURL=default-D22AKTqE.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-D22AKTqE.mjs","names":[],"sources":["../src/engine/capabilities.ts","../src/capabilities/matrix-inspection.ts","../src/capabilities/default.ts"],"sourcesContent":["import type { ElementRegistry, RuntimeElement, Content } from \"@case-framework/survey-core\";\nimport type {\n AssistantElementTypeManifest,\n JsonValue,\n SurveyAssistantCapabilityManifest,\n SurveyOperation,\n SurveyValidationIssue,\n} from \"../protocol\";\nimport { assistantElementTypeManifestSchema } from \"../protocol/capabilities\";\nimport { buildCapabilityDigest, stableStringify } from \"../protocol/digest\";\n\nexport interface AssistantCapabilityReference {\n topic: string;\n title?: string;\n markdown: string;\n}\nexport interface AssistantElementInspection {\n summary: string;\n details?: JsonValue;\n}\n/** Authoring policy supplements the registry; it never supplies a substitute slot/ownership schema. */\nexport interface AssistantElementCapabilityAdapter {\n manifest: AssistantElementTypeManifest;\n references?: AssistantCapabilityReference[];\n materializePreset?: (\n presetId: string,\n locale: string,\n usedNames: ReadonlySet<string>,\n ) => {\n element: RuntimeElement;\n content?: Record<string, Record<string, Content>>;\n };\n /** Deterministic element diagnostics. New errors block edits; unchanged errors\n * on the same element/type may remain during repair. Removed nodes are not\n * validated. Use supportedOperations/supportsOperation to restrict mutations.\n */\n validateElement?: (element: RuntimeElement) => SurveyValidationIssue[];\n supportsOperation?: (operation: SurveyOperation) => boolean;\n /** Receives a node validated by inspectAssistantElement with the active trusted registry. */\n inspectElement?: (element: RuntimeElement) => AssistantElementInspection;\n}\nexport interface SurveyAssistantCapabilitySet {\n manifest: SurveyAssistantCapabilityManifest;\n registry: ElementRegistry;\n byElementType: ReadonlyMap<string, AssistantElementCapabilityAdapter>;\n}\nexport const resolveAssistantCapabilityReference = ({\n capabilities,\n elementType,\n topic,\n}: {\n capabilities: SurveyAssistantCapabilitySet | undefined;\n elementType: string;\n topic: string;\n}) =>\n capabilities?.byElementType\n .get(elementType)\n ?.references?.find((reference) => reference.topic === topic);\nexport const inspectAssistantElement = ({\n capabilities,\n element,\n}: {\n capabilities: SurveyAssistantCapabilitySet | undefined;\n element: RuntimeElement;\n}): AssistantElementInspection | undefined => {\n const capability = capabilities?.byElementType.get(element.elementType);\n if (!capabilities || !capability?.inspectElement) return undefined;\n const parsed = capabilities.registry.get(element.elementType).schema.safeParse(element);\n if (!parsed.success)\n return {\n summary: `${capability.manifest.displayName} configuration needs repair.`,\n details: {\n issues: parsed.error.issues.map((issue) => `${issue.path.join(\".\")}: ${issue.message}`),\n },\n };\n return capability.inspectElement(parsed.data);\n};\n\nexport function createSurveyAssistantCapabilities(\n registry: ElementRegistry,\n capabilities: readonly AssistantElementCapabilityAdapter[],\n): SurveyAssistantCapabilitySet {\n const supplied = new Map<string, AssistantElementCapabilityAdapter>();\n for (const capability of capabilities) {\n const manifest = assistantElementTypeManifestSchema.parse(capability.manifest);\n if (supplied.has(manifest.elementType))\n throw new Error(\n `Duplicate survey assistant capability for element type \"${manifest.elementType}\".`,\n );\n registry.get(manifest.elementType); // Never install executable behavior from a serialized manifest.\n if (\n manifest.create === \"deterministic\" &&\n !manifest.supportedOperations.includes(\"create-item\")\n )\n throw new Error(\n `Deterministically creatable element \"${manifest.elementType}\" must support creation inside a content item.`,\n );\n if (manifest.creationPresets?.length && !capability.materializePreset)\n throw new Error(\n `Element \"${manifest.elementType}\" declares presets without a trusted materializer.`,\n );\n const topics = new Set(manifest.referenceTopics ?? []);\n for (const reference of capability.references ?? [])\n if (!topics.has(reference.topic))\n throw new Error(\n `Capability reference \"${reference.topic}\" for \"${manifest.elementType}\" is not declared.`,\n );\n supplied.set(manifest.elementType, { ...capability, manifest });\n }\n const byElementType = new Map(\n registry.definitions.map((definition) => [\n definition.elementType,\n supplied.get(definition.elementType) ??\n createUnsupportedElementCapability({\n elementType: definition.elementType,\n displayName:\n definition.labelByLocale?.en ??\n Object.values(definition.labelByLocale ?? {})[0] ??\n definition.elementType,\n }),\n ]),\n );\n const elementTypes = [...byElementType.values()]\n .map((adapter) => structuredClone(adapter.manifest))\n .sort((a, b) => a.elementType.localeCompare(b.elementType));\n return {\n registry,\n byElementType,\n manifest: { elementTypes, digest: buildCapabilityDigest({ elementTypes }) },\n };\n}\nexport const getDeterministicCreateElementTypes = (manifest: SurveyAssistantCapabilityManifest) =>\n manifest.elementTypes\n .filter((entry) => entry.create === \"deterministic\")\n .map((entry) => entry.elementType);\nexport const createUnsupportedElementCapability = ({\n displayName,\n elementType,\n}: {\n displayName: string;\n elementType: string;\n}): AssistantElementCapabilityAdapter => ({\n manifest: {\n elementType,\n displayName,\n capabilityVersion: \"unsupported-v1\",\n create: \"unsupported\",\n supportedOperations: [],\n },\n});\nexport class SurveyAssistantCapabilityMismatchError extends Error {\n readonly code = \"survey-assistant-capability-mismatch\";\n constructor(message = \"Survey assistant capabilities changed; start a fresh turn and retry.\") {\n super(message);\n this.name = \"SurveyAssistantCapabilityMismatchError\";\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, ...body } = manifest;\n if (digest !== buildCapabilityDigest(body) || versionDigest !== digest)\n throw new SurveyAssistantCapabilityMismatchError();\n // A browser cannot grant operations or claim server presets. Both sides share\n // the same complete trusted capability contract, including preset identifiers.\n if (\n trustedCapabilities &&\n stableStringify(body.elementTypes) !==\n stableStringify(trustedCapabilities.manifest.elementTypes)\n )\n throw new SurveyAssistantCapabilityMismatchError(\n \"The editor and server use different survey assistant capabilities; refresh and retry.\",\n );\n};\n","import type { JsonValue } from \"../protocol\";\n\nconst isRecord = (value: JsonValue | undefined): value is Record<string, JsonValue> =>\n value !== null && typeof value === \"object\" && !Array.isArray(value);\nconst PREVIEW_LIMIT = 12;\nconst describeList = (name: string, values: JsonValue[]) =>\n `${name}: ${values.length}; ${JSON.stringify(values.slice(0, PREVIEW_LIMIT))}${values.length > PREVIEW_LIMIT ? \" (first 12 shown; inspect full details for the rest)\" : \"\"}.`;\n\n/** Summarize authored state, not the model's claimed intent or respondent visibility. */\nexport const summarizeMatrixState = (elementType: string, config: JsonValue): string => {\n if (\n (elementType !== \"formMatrix\" && elementType !== \"choiceMatrix\") ||\n !isRecord(config) ||\n !Array.isArray(config.rows)\n )\n return \"\";\n const rows = config.rows.map((row) =>\n isRecord(row) ? { id: row.id, rowName: row.rowName } : row,\n );\n const lines = [\n \"Current authored matrix state (IDs/coding names, configured order):\",\n describeList(\"Rows\", rows),\n ];\n if (\n elementType === \"formMatrix\" &&\n Array.isArray(config.columns) &&\n Array.isArray(config.cells)\n ) {\n lines.push(\n describeList(\n \"Columns\",\n config.columns.map((column) =>\n isRecord(column) ? { id: column.id, columnName: column.columnName } : column,\n ),\n ),\n `Cells: ${config.cells.length}.`,\n describeList(\n \"Explicit cell overrides\",\n config.cells.flatMap((cell) =>\n isRecord(cell) && isRecord(cell.fieldOverride)\n ? [\n {\n cellId: cell.id,\n rowId: cell.rowId,\n columnId: cell.columnId,\n type: cell.fieldOverride.type,\n ...(cell.fieldOverride.type === \"date\"\n ? { precision: cell.fieldOverride.precision }\n : {}),\n },\n ]\n : [],\n ),\n ),\n );\n } else if (elementType === \"choiceMatrix\" && Array.isArray(config.options)) {\n lines.push(\n describeList(\n \"Regular option columns\",\n config.options.map((option) => (isRecord(option) ? option.id : option)),\n ),\n );\n for (const position of [\"leading\", \"trailing\"]) {\n const option = config[`${position}NonScoring`];\n lines.push(\n `${position} non-scoring option ID: ${isRecord(option) ? JSON.stringify(option.id) : \"none\"}.`,\n );\n }\n }\n return lines.join(\" \");\n};\n","import { generateId, type RuntimeElement } from \"@case-framework/survey-core\";\nimport { allocateCopiedResponseNames } from \"@case-framework/survey-core/editor\";\nimport {\n choiceMatrixConfigSchema,\n getChoiceMatrixConfigIssues,\n} from \"@case-framework/survey-items/choice-matrix\";\nimport {\n createBuiltInElement,\n createChoiceMatrixPreset,\n defaultElementRegistry,\n type BuiltInPresetType,\n type BuiltInElementType,\n} from \"@case-framework/survey-items\";\nimport {\n createSurveyAssistantCapabilities,\n type AssistantElementCapabilityAdapter,\n} from \"../engine/capabilities\";\nimport { jsonValueSchema } from \"../protocol/content\";\nimport type { AssistantElementTypeManifest } from \"../protocol/capabilities\";\nimport { summarizeMatrixState } from \"./matrix-inspection\";\n\nconst commonOperations = [\n \"create-item\",\n \"insert-element\",\n \"insert-blocks\",\n \"insert-preset\",\n \"move-element\",\n \"move-block\",\n \"remove-content\",\n \"update-layout\",\n \"patch-element-config\",\n \"update-response-settings\",\n \"update-content\",\n \"update-placed-image\",\n \"patch-item-config\",\n \"remove-item\",\n \"move-item\",\n \"reorder-items\",\n \"survey-json-patch\",\n] satisfies AssistantElementTypeManifest[\"supportedOperations\"];\nconst presets: Record<string, BuiltInPresetType> = {\n \"information.default\": \"information\",\n \"text.short\": \"text\",\n \"text.long\": \"longText\",\n \"number.input\": \"number\",\n \"number.slider\": \"slider\",\n \"date.default\": \"date\",\n \"boolean.radio\": \"boolean\",\n \"boolean.switch\": \"switch\",\n \"choice.radio\": \"radio\",\n \"choice.checkbox\": \"checkbox\",\n \"choice.dropdown\": \"dropdown\",\n \"consent.default\": \"consent\",\n \"formMatrix.default\": \"formMatrix\",\n};\nconst descriptions = {\n information: {\n hint: \"Rich content with no response slot. Use the body content role.\",\n },\n text: {\n hint: \"Short or long text input; use a label or an unambiguous enclosing title.\",\n },\n number: {\n hint: \"Localized numeric input or slider, with optional unit and constraints.\",\n },\n date: {\n hint: \"Calendar input with year, year-month or year-month-day precision; keep regional formatting separate.\",\n },\n boolean: {\n hint: \"Yes/no radio or switch. Appearance does not change the boolean response domain.\",\n },\n choice: {\n hint: \"Radio and checkbox lists are full-width and may own option-inline follow-ups. Dropdowns are compact and cannot own follow-ups.\",\n },\n consent: {\n hint: \"Explicit boolean decision with inline or dialog information and own/inherited semantic heading context.\",\n },\n choiceMatrix: {\n hint: \"Categorical row slots plus persisted score/sum slot IDs. Codes, option labels and scores are separate; preserve non-scoring options.\",\n },\n formMatrix: {\n hint: \"Independent cell slots with column defaults and per-cell overrides. Preserve row/column naming, date precision and cell-specific UI.\",\n },\n} satisfies Record<BuiltInElementType, { hint: string }>;\nconst configSummaries = {\n information:\n \"Display-only element with empty config and rich body role. Use actual document content, not a placeholder or a description of absent content. Load rich-text-content for formatting and source-material-surveys when implementing supplied documents.\",\n text: \"Config: slotId, variableName, presentation short|long; optional purpose text|email|tel|url|password, required, rows, autocomplete and validations. Roles label/help/placeholder/message; individual validation IDs own message. Use an explicit label or unambiguous enclosing title. A placeholder is not a label. Preserve source constraints and create real inputs for respondent blanks.\",\n number:\n \"Config: slotId, variableName, presentation input|slider; optional step, min, max, showValue, required and validations (integer). min/max are a number or {expression, fallback?}; a missing expression value leaves the bound unapplied unless it has a fallback, and slider expression bounds need one. Roles label/help/placeholder/message/unit. Units are localized wording, not part of the numeric answer. Preserve requested bounds and step; do not invent domain limits. Slider and input share numeric semantics.\",\n date: \"Config: slotId, variableName, precision year|year-month|year-month-day; optional required, min and max. Calendar values are YYYY, YYYY-MM or YYYY-MM-DD, never timestamps. Display format is independent of language and precision. min/max are a calendar string or {expression, fallback?}; a missing expression value leaves the bound unapplied unless it has a fallback. Use survey_expression for expression bounds and preserve precision.\",\n boolean:\n \"Config: slotId, variableName, presentation radio|switch; optional required and validations. Roles include label/help/yesLabel/noLabel/message. False is a defined answer. Use get compared with true/false for conditions about the answer; isDefined means either answer exists. Do not substitute a switch for the consent document/decision experience.\",\n choice:\n \"Config: slotId, variableName, presentation radio|checkbox|dropdown, options, optional required/shuffleOptions; checkbox maxSelection null=unlimited or positive cap. Options own label/description and optional visibility/disabled. Radio/checkbox may own followUp bodies, never dropdowns; load follow-ups for the complete example. Put option, body and owner-role translations in one creation/config edit. Use fresh IDs for new owners and preserve inspected IDs on edits. Response types: radio/dropdown reference, checkbox reference[]. Codes, labels and IDs are separate. Disabled selections remain active; use visibility for inapplicability and avoid self-locking exclusivity.\",\n consent:\n \"Config: slotId, variableName, presentation inline|dialog, subtitleMode inherit|custom|none. Element label overrides the nearest semantic title; custom subtitle uses the element subtitle role. Body must contain actual terms, not a document description. Preserve supplied terms; otherwise draft proactively and report assumptions/gaps afterward. Optional acceptLabel/declineLabel, unansweredLabel/acceptedLabel/declinedLabel, reviewLabel/changeLabel override UI wording. True=agree, false=decline, absent=unanswered; isDefined does not mean accepted. No required setting or effects list. Load element-types for complete content and interaction guidance.\",\n choiceMatrix:\n \"Config: prefix, rows with id/rowName/scoreSlotId, options with id/code/score, sumSlotId, layout. Presets are editable starting points; match anchors to the construct. Scores are all present or all absent; zero is a defined score. Leading/trailing non-scoring options are single objects, not arrays. Use row/option owner labels and element startLabel/endLabel for bipolar anchors. Preserve IDs on edits; reverse score values without reordering labels. Naming derives from prefix/rowName, never hand-rename computed slots. Load element-types before structural/scoring edits.\",\n formMatrix:\n \"Config: prefix, rows, columns and complete persistent cells rectangle; field types text/number/date/dropdown/boolean/static/empty. Each cell has id/rowId/columnId and optional complete field override. Dates use mode; number unit is config text. Add/remove rows or columns with all associated cells in one patch. Duplicate every override with fresh nested IDs and copy all locale content; resetting an override restores column defaults. Preserve surviving IDs. Naming derives from prefix/rowName/columnName. Load element-types for effective field, ownership and duplication rules.\",\n} satisfies Record<BuiltInElementType, string>;\nfunction createCapability(elementType: string): AssistantElementCapabilityAdapter {\n const info = Object.entries(descriptions).find(([type]) => type === elementType)?.[1];\n const configSummary = Object.entries(configSummaries).find(([type]) => type === elementType)?.[1];\n if (!info || !configSummary)\n throw new Error(`Missing built-in assistant guidance for ${elementType}`);\n const available =\n elementType === \"choiceMatrix\"\n ? [\"yesNo\", \"fivePoint\", \"sevenPoint\", \"bipolarFive\"].map((id) => `choiceMatrix.${id}`)\n : Object.entries(presets)\n .filter(\n ([, type]) =>\n (type === \"longText\"\n ? \"text\"\n : type === \"slider\"\n ? \"number\"\n : type === \"switch\"\n ? \"boolean\"\n : type === \"radio\" || type === \"checkbox\" || type === \"dropdown\"\n ? \"choice\"\n : type) === elementType,\n )\n .map(([id]) => id);\n return {\n manifest: {\n elementType,\n capabilityVersion: \"composition-v1\",\n displayName: defaultElementRegistry.get(elementType).labelByLocale?.en ?? elementType,\n description: info.hint,\n create: \"deterministic\",\n referenceTopics: [\n \"element-types\",\n \"response-variables\",\n \"expressions\",\n \"localization\",\n \"rich-text-content\",\n ...(elementType === \"choice\" ? [\"follow-ups\"] : []),\n ],\n supportedOperations: commonOperations,\n creationPresets: available.map((id) => ({ id })),\n authoring: { compactHint: info.hint, configSummary },\n },\n materializePreset(presetId, locale, usedNames) {\n if (!available.includes(presetId))\n throw new Error(`Unknown preset \"${presetId}\" for \"${elementType}\".`);\n let element: RuntimeElement;\n let content: ReturnType<typeof createChoiceMatrixPreset>[\"content\"] | undefined;\n if (elementType === \"choiceMatrix\") {\n const name = presetId.slice(\"choiceMatrix.\".length);\n if (\n name !== \"yesNo\" &&\n name !== \"fivePoint\" &&\n name !== \"sevenPoint\" &&\n name !== \"bipolarFive\"\n )\n throw new Error(\"Unknown matrix preset\");\n const preset = createChoiceMatrixPreset(name, locale);\n element = { id: generateId(), kind: \"element\", elementType, config: preset.config };\n content = preset.content;\n } else element = createBuiltInElement(presets[presetId], usedNames);\n return {\n element: allocateCopiedResponseNames(\n defaultElementRegistry.elementSchema,\n element,\n defaultElementRegistry,\n usedNames,\n ),\n ...(content ? { content } : {}),\n };\n },\n inspectElement(element) {\n // Inspection receives the active document's parsed nodes. Re-parsing a choice\n // with the default registry would reject custom elements in its follow-ups.\n const config = jsonValueSchema.parse(element.config);\n return {\n summary:\n [summarizeMatrixState(elementType, config), info.hint].filter(Boolean).join(\" \") +\n (elementType === \"choice\"\n ? config !== null &&\n typeof config === \"object\" &&\n !Array.isArray(config) &&\n config.shuffleOptions === true\n ? \" Options are listed in configured order; respondents see shuffled order.\"\n : \" Option positions match respondent-visible order, with hidden options omitted.\"\n : \"\"),\n details: config,\n };\n },\n ...(elementType === \"choiceMatrix\"\n ? {\n validateElement(element: RuntimeElement) {\n return getChoiceMatrixConfigIssues(choiceMatrixConfigSchema.parse(element.config)).map(\n (message) => ({ severity: \"error\" as const, code: \"invalid-matrix\", message }),\n );\n },\n }\n : {}),\n };\n}\nexport const defaultSurveyAssistantCapabilities = defaultElementRegistry.definitions.map(\n (definition) => createCapability(definition.elementType),\n);\nexport const defaultSurveyAssistantCapabilitySet = createSurveyAssistantCapabilities(\n defaultElementRegistry,\n defaultSurveyAssistantCapabilities,\n);\nexport const getDefaultSurveyAssistantCapability = (elementType: string) =>\n defaultSurveyAssistantCapabilitySet.byElementType.get(elementType);\n"],"mappings":";;;;;;;AA8CA,MAAa,uCAAuC,EAClD,cACA,aACA,YAMA,cAAc,cACX,IAAI,WAAW,CAAC,EACf,YAAY,MAAM,cAAc,UAAU,UAAU,KAAK;AAC/D,MAAa,2BAA2B,EACtC,cACA,cAI4C;CAC5C,MAAM,aAAa,cAAc,cAAc,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OAAO,WAAW,YAClB,CAAC,MAAM,QAAQ,MAAM,KACrB,OAAO,mBAAmB,OACxB,6EACA,mFACF;IACN,SAAS;GACX;EACF;EACA,GAAI,gBAAgB,iBAChB,EACE,gBAAgB,SAAyB;GACvC,OAAO,4BAA4B,yBAAyB,MAAM,QAAQ,MAAM,CAAC,CAAC,CAAC,KAChF,aAAa;IAAE,UAAU;IAAkB,MAAM;IAAkB;GAAQ,EAC9E;EACF,EACF,IACA,CAAC;CACP;AACF;AACA,MAAa,qCAAqC,uBAAuB,YAAY,KAClF,eAAe,iBAAiB,WAAW,WAAW,CACzD;AACA,MAAa,sCAAsC,kCACjD,wBACA,kCACF;AACA,MAAa,uCAAuC,gBAClD,oCAAoC,cAAc,IAAI,WAAW"}
@@ -1,9 +1,8 @@
1
- import { o as SurveyAssistantCapabilityManifest } from "./capabilities-DVTfogjv.mjs";
2
-
1
+ import { i as SurveyAssistantCapabilityManifest } from "./capabilities-z95e1mti.mjs";
3
2
  //#region src/protocol/digest.d.ts
4
3
  declare const stableStringify: (value: unknown) => string;
5
4
  declare const hashString: (input: string) => string;
6
5
  declare const buildCapabilityDigest: (manifest: Omit<SurveyAssistantCapabilityManifest, "digest">) => string;
7
6
  //#endregion
8
7
  export { hashString as n, stableStringify as r, buildCapabilityDigest as t };
9
- //# sourceMappingURL=digest-SJmoYVaK.d.mts.map
8
+ //# sourceMappingURL=digest-FnTTDBq2.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digest-FnTTDBq2.d.mts","names":[],"sources":["../src/protocol/digest.ts"],"mappings":";;cAEa,kBAAmB;cAcnB,aAAc;cASd,wBACX,UAAU,KAAK"}
package/dist/digest.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { n as hashString, r as stableStringify, t as buildCapabilityDigest } from "./digest-SJmoYVaK.mjs";
1
+ import { n as hashString, r as stableStringify, t as buildCapabilityDigest } from "./digest-FnTTDBq2.mjs";
2
2
  export { buildCapabilityDigest, hashString, stableStringify };
@@ -1 +1 @@
1
- {"version":3,"file":"digest.mjs","names":[],"sources":["../src/protocol/digest.ts"],"sourcesContent":["import type { SurveyAssistantCapabilityManifest } from \"./capabilities\";\n\nexport const stableStringify = (value: unknown): string => {\n if (value === undefined) return \"undefined\";\n if (value === null || typeof value !== \"object\") {\n return JSON.stringify(value) ?? \"undefined\";\n }\n if (Array.isArray(value)) {\n return `[${value.map((entry) => stableStringify(entry)).join(\",\")}]`;\n }\n return `{${Object.entries(value)\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([key, entry]) => `${JSON.stringify(key)}:${stableStringify(entry)}`)\n .join(\",\")}}`;\n};\n\nexport const hashString = (input: string): string => {\n let hash = 2166136261;\n for (let index = 0; index < input.length; index += 1) {\n hash ^= input.charCodeAt(index);\n hash = Math.imul(hash, 16777619);\n }\n return (hash >>> 0).toString(36);\n};\n\nexport const buildCapabilityDigest = (\n manifest: Omit<SurveyAssistantCapabilityManifest, \"digest\">,\n): string => hashString(stableStringify(manifest));\n"],"mappings":";AAEA,MAAa,mBAAmB,UAA2B;AACzD,KAAI,UAAU,KAAA,EAAW,QAAO;AAChC,KAAI,UAAU,QAAQ,OAAO,UAAU,SACrC,QAAO,KAAK,UAAU,MAAM,IAAI;AAElC,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,IAAI,MAAM,KAAK,UAAU,gBAAgB,MAAM,CAAC,CAAC,KAAK,IAAI,CAAC;AAEpE,QAAO,IAAI,OAAO,QAAQ,MAAM,CAC7B,MAAM,CAAC,OAAO,CAAC,WAAW,KAAK,cAAc,MAAM,CAAC,CACpD,KAAK,CAAC,KAAK,WAAW,GAAG,KAAK,UAAU,IAAI,CAAC,GAAG,gBAAgB,MAAM,GAAG,CACzE,KAAK,IAAI,CAAC;;AAGf,MAAa,cAAc,UAA0B;CACnD,IAAI,OAAO;AACX,MAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS,GAAG;AACpD,UAAQ,MAAM,WAAW,MAAM;AAC/B,SAAO,KAAK,KAAK,MAAM,SAAS;;AAElC,SAAQ,SAAS,GAAG,SAAS,GAAG;;AAGlC,MAAa,yBACX,aACW,WAAW,gBAAgB,SAAS,CAAC"}
1
+ {"version":3,"file":"digest.mjs","names":[],"sources":["../src/protocol/digest.ts"],"sourcesContent":["import type { SurveyAssistantCapabilityManifest } from \"./capabilities\";\n\nexport const stableStringify = (value: unknown): string => {\n if (value === undefined) return \"undefined\";\n if (value === null || typeof value !== \"object\") {\n return JSON.stringify(value) ?? \"undefined\";\n }\n if (Array.isArray(value)) {\n return `[${value.map((entry) => stableStringify(entry)).join(\",\")}]`;\n }\n return `{${Object.entries(value)\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([key, entry]) => `${JSON.stringify(key)}:${stableStringify(entry)}`)\n .join(\",\")}}`;\n};\n\nexport const hashString = (input: string): string => {\n let hash = 2166136261;\n for (let index = 0; index < input.length; index += 1) {\n hash ^= input.charCodeAt(index);\n hash = Math.imul(hash, 16777619);\n }\n return (hash >>> 0).toString(36);\n};\n\nexport const buildCapabilityDigest = (\n manifest: Omit<SurveyAssistantCapabilityManifest, \"digest\">,\n): string => hashString(stableStringify(manifest));\n"],"mappings":";AAEA,MAAa,mBAAmB,UAA2B;CACzD,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,IAAI,UAAU,QAAQ,OAAO,UAAU,UACrC,OAAO,KAAK,UAAU,KAAK,KAAK;CAElC,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,IAAI,MAAM,KAAK,UAAU,gBAAgB,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;CAEpE,OAAO,IAAI,OAAO,QAAQ,KAAK,CAAC,CAC7B,MAAM,CAAC,OAAO,CAAC,WAAW,KAAK,cAAc,KAAK,CAAC,CAAC,CACpD,KAAK,CAAC,KAAK,WAAW,GAAG,KAAK,UAAU,GAAG,EAAE,GAAG,gBAAgB,KAAK,GAAG,CAAC,CACzE,KAAK,GAAG,EAAE;AACf;AAEA,MAAa,cAAc,UAA0B;CACnD,IAAI,OAAO;CACX,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS,GAAG;EACpD,QAAQ,MAAM,WAAW,KAAK;EAC9B,OAAO,KAAK,KAAK,MAAM,QAAQ;CACjC;CACA,QAAQ,SAAS,EAAA,CAAG,SAAS,EAAE;AACjC;AAEA,MAAa,yBACX,aACW,WAAW,gBAAgB,QAAQ,CAAC"}