@case-framework/survey-assistant 0.3.0 → 0.5.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 +20 -4
- package/dist/capabilities-default.d.mts +1 -1
- package/dist/capabilities-default.mjs +1 -1
- package/dist/{constants-DrGZXtQf.d.mts → constants-DbrJxxOh.d.mts} +5 -2
- package/dist/constants-DbrJxxOh.d.mts.map +1 -0
- package/dist/{controller-proxy-DmBdzqKs.d.mts → controller-proxy-BdKF2yrq.d.mts} +2 -2
- package/dist/{controller-proxy-DmBdzqKs.d.mts.map → controller-proxy-BdKF2yrq.d.mts.map} +1 -1
- package/dist/{controller-proxy-CpkQRezb.mjs → controller-proxy-jWIPOZAv.mjs} +17 -8
- package/dist/controller-proxy-jWIPOZAv.mjs.map +1 -0
- package/dist/{engine-CWTuN3o2.mjs → engine-DcSdLRle.mjs} +172 -12
- package/dist/engine-DcSdLRle.mjs.map +1 -0
- package/dist/engine.d.mts +2 -2
- package/dist/engine.mjs +3 -3
- package/dist/{form-authoring-DCd9XfXf.mjs → form-authoring-BQh40yDb.mjs} +2 -2
- package/dist/{form-authoring-DCd9XfXf.mjs.map → form-authoring-BQh40yDb.mjs.map} +1 -1
- package/dist/{index-D4OitUg4.d.mts → index-BApnIiCI.d.mts} +7 -4
- package/dist/index-BApnIiCI.d.mts.map +1 -0
- package/dist/{index-Bo4dHAo8.d.mts → index-Da_Hb9-1.d.mts} +28 -4
- package/dist/index-Da_Hb9-1.d.mts.map +1 -0
- package/dist/{index-DZk20e3k.d.mts → index-DhNQKOwr.d.mts} +9 -5
- package/dist/index-DhNQKOwr.d.mts.map +1 -0
- package/dist/{index-Dxgg0-D_.d.mts → index-dV6df0W3.d.mts} +11 -5
- package/dist/index-dV6df0W3.d.mts.map +1 -0
- package/dist/{memory-thread-repository-acbz6HZJ.mjs → memory-thread-repository-CvYZwni6.mjs} +87 -28
- package/dist/memory-thread-repository-CvYZwni6.mjs.map +1 -0
- package/dist/{protocol-DATvkr1S.mjs → protocol-DJUP4gc0.mjs} +10 -4
- package/dist/protocol-DJUP4gc0.mjs.map +1 -0
- package/dist/protocol.d.mts +1 -1
- package/dist/protocol.mjs +1 -1
- package/dist/{react-Br5YE8H-.mjs → react-CY6N7lVi.mjs} +25 -5
- package/dist/react-CY6N7lVi.mjs.map +1 -0
- package/dist/react-integration.d.mts +1 -1
- package/dist/react-integration.mjs +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.mjs +2 -2
- package/dist/{request-context-BEjnaaFr.mjs → request-context-D1sC54ZA.mjs} +3 -3
- package/dist/request-context-D1sC54ZA.mjs.map +1 -0
- package/dist/server-agent.d.mts +8 -6
- package/dist/server-agent.d.mts.map +1 -1
- package/dist/server-agent.mjs +4 -3
- package/dist/server-agent.mjs.map +1 -1
- package/dist/server-runtime.d.mts +354 -7
- package/dist/server-runtime.d.mts.map +1 -1
- package/dist/server-runtime.mjs +361 -24
- package/dist/server-runtime.mjs.map +1 -1
- package/dist/server-tasks.d.mts +1 -1
- package/dist/server-tasks.mjs +5 -4
- package/dist/server-tasks.mjs.map +1 -1
- package/dist/server-tools.d.mts +1 -1
- package/dist/server-tools.mjs +1 -1
- package/dist/server.d.mts +7 -7
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +2 -2
- package/dist/storage-postgres.mjs +3 -0
- package/dist/storage-postgres.mjs.map +1 -1
- package/dist/{tasks-DQgL449A.d.mts → tasks-CCtxjhwh.d.mts} +3 -3
- package/dist/{tasks-DQgL449A.d.mts.map → tasks-CCtxjhwh.d.mts.map} +1 -1
- package/dist/{thread-handlers-CeYl45xG.d.mts → thread-handlers-Bt9cDo-F.d.mts} +21 -6
- package/dist/{thread-handlers-CeYl45xG.d.mts.map → thread-handlers-Bt9cDo-F.d.mts.map} +1 -1
- package/dist/{tools-Dg9HZrYU.mjs → tools-3tq-XqI0.mjs} +31 -6
- package/dist/{tools-Dg9HZrYU.mjs.map → tools-3tq-XqI0.mjs.map} +1 -1
- package/dist/ui.css +1 -1
- package/dist/ui.d.mts +3 -3
- package/dist/ui.d.mts.map +1 -1
- package/dist/ui.mjs +438 -140
- package/dist/ui.mjs.map +1 -1
- package/docs/integration.md +113 -58
- package/package.json +3 -3
- package/dist/constants-DrGZXtQf.d.mts.map +0 -1
- package/dist/controller-proxy-CpkQRezb.mjs.map +0 -1
- package/dist/engine-CWTuN3o2.mjs.map +0 -1
- package/dist/index-Bo4dHAo8.d.mts.map +0 -1
- package/dist/index-D4OitUg4.d.mts.map +0 -1
- package/dist/index-DZk20e3k.d.mts.map +0 -1
- package/dist/index-Dxgg0-D_.d.mts.map +0 -1
- package/dist/memory-thread-repository-acbz6HZJ.mjs.map +0 -1
- package/dist/protocol-DATvkr1S.mjs.map +0 -1
- package/dist/react-Br5YE8H-.mjs.map +0 -1
- package/dist/request-context-BEjnaaFr.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ import {
|
|
|
46
46
|
|
|
47
47
|
import {
|
|
48
48
|
createSurveyAssistantRuntime,
|
|
49
|
+
parseSurveyAssistantConfigurationDocument,
|
|
49
50
|
parseSurveyAssistantEnvironment,
|
|
50
51
|
} from "@case-framework/survey-assistant/server/runtime";
|
|
51
52
|
|
|
@@ -84,9 +85,10 @@ Markdown authoring references. `/server/tools` owns the standard
|
|
|
84
85
|
request-context tools, and `/server/agent` owns their Agent,
|
|
85
86
|
instructions, thread-scoped Observational Memory defaults, and optional
|
|
86
87
|
history-compatibility policy for custom memory setups. `/server/runtime` is the
|
|
87
|
-
high-level composition layer: it parses
|
|
88
|
-
|
|
89
|
-
discovery), applies
|
|
88
|
+
high-level composition layer: it parses a versioned provider/model policy
|
|
89
|
+
document or the legacy injected environment, resolves the approved model catalog
|
|
90
|
+
(including optional Azure deployment discovery), applies same-provider chat,
|
|
91
|
+
task, and memory roles,
|
|
90
92
|
exposes standard Mastra agents and gateways, and creates the Web handlers. The
|
|
91
93
|
host still constructs the standard Mastra instance and owns
|
|
92
94
|
credentials, authorization, storage connection lifecycle, logging, and route
|
|
@@ -172,6 +174,12 @@ For the supported real-app setup, configuration reference, route/auth contract,
|
|
|
172
174
|
attachment policy, apply settlement, observability, cleanup, and acceptance
|
|
173
175
|
checklist, see [Real-host integration](./docs/integration.md).
|
|
174
176
|
|
|
177
|
+
The repository's Survey Editor host keeps its active configuration local. Start
|
|
178
|
+
from
|
|
179
|
+
[`apps/survey-editor/config/survey-assistant.example.yaml`](../../apps/survey-editor/config/survey-assistant.example.yaml)
|
|
180
|
+
and keep provider credentials in the environment variables named by
|
|
181
|
+
`apiKeyEnv`.
|
|
182
|
+
|
|
175
183
|
`createSurveyAssistantSurveyLifecycle(...).forSurvey(surveyId, resourceId)`
|
|
176
184
|
provides one shared thread identity, chat authorizer, panel-prop object, and
|
|
177
185
|
per-user cleanup method so those paths cannot drift onto different survey
|
|
@@ -258,7 +266,7 @@ variables, create hidden singletons, or own connection shutdown.
|
|
|
258
266
|
Use the highest level that fits the host; the lower layers remain available for
|
|
259
267
|
custom authentication, provider policy, UI, or storage.
|
|
260
268
|
|
|
261
|
-
- **Standard server:** `
|
|
269
|
+
- **Standard server:** `parseSurveyAssistantConfigurationDocument` plus
|
|
262
270
|
`createSurveyAssistantRuntime`, then register its `agents` and `gateways` in a
|
|
263
271
|
normal `Mastra` instance and call `runtime.createHandlers(...)`.
|
|
264
272
|
- **Custom server:** compose `createSurveyAssistantAgent`, individual chat,
|
|
@@ -270,3 +278,11 @@ custom authentication, provider policy, UI, or storage.
|
|
|
270
278
|
|
|
271
279
|
The high-level APIs are thin composition helpers over the same exported
|
|
272
280
|
primitives. They do not introduce a second runtime or hide Mastra.
|
|
281
|
+
|
|
282
|
+
Importing hosts can optionally require the additional
|
|
283
|
+
`SURVEY_ASSISTANT_ALLOW_EXPERIMENTAL_IDENTITY=true` production rollout gate by
|
|
284
|
+
passing `requireExperimentalIdentityOptIn: true` to a configuration parser.
|
|
285
|
+
The option does not choose or authorize an identity, and most authenticated
|
|
286
|
+
hosts should omit it unless they want that extra deployment switch. See
|
|
287
|
+
[Real-host integration](./docs/integration.md#optional-experimental-identity-rollout-gate)
|
|
288
|
+
for the exact enablement rules.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ut as SurveyAssistantCapabilitySet, zt as AssistantItemCapabilityAdapter } from "./index-Da_Hb9-1.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/capabilities/default.d.ts
|
|
4
4
|
declare const rootItemAssistantCapability: AssistantItemCapabilityAdapter;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as normalizeFormAuthoringConfig, i as isValidSimpleFormConfig, l as createSurveyAssistantCapabilities } from "./form-authoring-
|
|
1
|
+
import { a as normalizeFormAuthoringConfig, i as isValidSimpleFormConfig, l as createSurveyAssistantCapabilities } from "./form-authoring-BQh40yDb.mjs";
|
|
2
2
|
import { ValueType } from "@case-framework/survey-core";
|
|
3
3
|
//#region src/capabilities/default.ts
|
|
4
4
|
const COMMON_OPERATIONS = [
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Ct as SurveyDocumentSnapshot, o as SurveyAssistantApplyOutcome, wt as SurveyDocumentVersion } from "./lifecycle-DWv5CiSu.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { Ut as SurveyAssistantCapabilitySet, b as TurnSurveyDraft, kt as SurveyAssistantEngineContext } from "./index-Da_Hb9-1.mjs";
|
|
3
3
|
import { n as SurveyAssistantModelAttachment, t as SurveyAssistantAttachmentAccess } from "./thread-documents-Dvo6XS7o.mjs";
|
|
4
4
|
import { RequestContext } from "@mastra/core/request-context";
|
|
5
|
+
import { AgentExecutionOptions } from "@mastra/core/agent";
|
|
5
6
|
import { OpenAICompatibleConfig } from "@mastra/core/llm";
|
|
6
7
|
|
|
7
8
|
//#region src/server/request-context.d.ts
|
|
@@ -17,6 +18,8 @@ interface SurveyAssistantIdentityContext {
|
|
|
17
18
|
interface SurveyAssistantModelSelection {
|
|
18
19
|
id: string;
|
|
19
20
|
model: string | OpenAICompatibleConfig;
|
|
21
|
+
providerName?: string;
|
|
22
|
+
providerOptions?: AgentExecutionOptions["providerOptions"];
|
|
20
23
|
}
|
|
21
24
|
type SurveyAssistantDocumentTransition = {
|
|
22
25
|
status: "no-baseline";
|
|
@@ -96,4 +99,4 @@ declare const SURVEY_ASSISTANT_AGENT_ID = "survey-assistant-agent";
|
|
|
96
99
|
declare const SURVEY_ASSISTANT_TASK_AGENT_ID = "survey-assistant-task-agent";
|
|
97
100
|
//#endregion
|
|
98
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 };
|
|
99
|
-
//# sourceMappingURL=constants-
|
|
102
|
+
//# sourceMappingURL=constants-DbrJxxOh.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants-DbrJxxOh.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;EAC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SurveyAssistantSuggestItemLabelResult, l as SurveyAssistantSuggestItemKeyResult, m as SurveyAssistantTaskInvocationMode, p as SurveyAssistantTaskContext, u as SurveyAssistantSuggestItemLabelInput, v as SurveyAssistantTranslateContentInput, y as SurveyAssistantTranslateContentResult } from "./index-
|
|
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-BApnIiCI.mjs";
|
|
2
2
|
import { Tt as SurveyEditorUIContext, h as SurveyChangeSet, i as SurveyApplyResult, m as SurveyBatchApplyResult, xt as SurveyAssistantSnapshot } from "./lifecycle-DWv5CiSu.mjs";
|
|
3
3
|
import { FileUIPart } from "ai";
|
|
4
4
|
|
|
@@ -82,4 +82,4 @@ declare const createSurveyAssistantControllerProxy: (getController: () => Survey
|
|
|
82
82
|
declare const createSurveyAssistantControllerBridge: (options?: CreateSurveyAssistantControllerProxyOptions) => SurveyAssistantControllerBridge;
|
|
83
83
|
//#endregion
|
|
84
84
|
export { createSurveyAssistantThreadLauncher as _, SurveyAssistantController as a, SurveyAssistantTaskExecutionOptions as c, SurveyAssistantTaskExecutorRequestOptions as d, createSurveyAssistantTaskClient as f, SurveyAssistantThreadLauncher as g, SurveyAssistantThreadLaunch as h, createSurveyAssistantControllerProxy as i, SurveyAssistantTaskExecutor as l, SurveyAssistantLaunchUIContext as m, SurveyAssistantControllerBridge as n, SurveyAssistantTaskClient as o, createSurveyAssistantTaskExecutor as p, createSurveyAssistantControllerBridge as r, SurveyAssistantTaskClientOptions as s, CreateSurveyAssistantControllerProxyOptions as t, SurveyAssistantTaskExecutorCacheContext as u };
|
|
85
|
-
//# sourceMappingURL=controller-proxy-
|
|
85
|
+
//# sourceMappingURL=controller-proxy-BdKF2yrq.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-proxy-
|
|
1
|
+
{"version":3,"file":"controller-proxy-BdKF2yrq.d.mts","names":[],"sources":["../src/react/thread-launcher.ts","../src/react/task-client.ts","../src/react/controller.ts","../src/react/controller-proxy.ts"],"mappings":";;;;;KAOY,8BAAA,GAAiC,OAAA,CAAQ,IAAA,CAAK,qBAAA;AAAA,UAEzC,2BAAA;;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;;;UCxEtC,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,kCAAA,EACP,OAAA,EAAS,0BAAA,EACT,OAAA,GAAU,yCAAA,EACV,KAAA,GAAQ,uCAAA,GACP,OAAA,CAAQ,mCAAA;EACX,gBAAA,CACE,KAAA,EAAO,oCAAA,EACP,OAAA,EAAS,0BAAA,EACT,OAAA,GAAU,yCAAA,EACV,KAAA,GAAQ,uCAAA,GACP,OAAA,CAAQ,qCAAA;EACX,gBAAA,CACE,KAAA,EAAO,oCAAA,EACP,OAAA,EAAS,0BAAA,EACT,OAAA,GAAU,yCAAA,EACV,KAAA,GAAQ,uCAAA,GACP,OAAA,CAAQ,qCAAA;AAAA;AAAA,cAGA,+BAAA;EAAmC,GAAA;EAAA,UAAA;EAAA,UAAA;EAAA;AAAA,IAK7C,gCAAA,KAAwC,yBAAA;AAAA,cA8C9B,iCAAA,GACX,OAAA,GAAS,gCAAA,KACR,2BAAA;;;UC1Hc,yBAAA;EACf,WAAA,IAAe,uBAAA;EACf,oBAAA,EAAsB,MAAA,EAAQ,eAAA,GAAkB,iBAAA;EAChD,qBAAA,EAAuB,OAAA,EAAS,eAAA,KAAoB,sBAAA;AAAA;;;UCPrC,2CAAA;EACf,eAAA;AAAA;AAAA,UAGe,+BAAA;EACf,UAAA,EAAY,yBAAA;EACZ,aAAA,CAAc,UAAA,EAAY,yBAAA;AAAA;AAAA,cAWf,oCAAA,GACX,aAAA,QAAqB,yBAAA;EACrB;AAAA,IAEG,2CAAA,KACF,yBAAA;AAAA,cAUU,qCAAA,GACX,OAAA,GAAU,2CAAA,KACT,+BAAA"}
|
|
@@ -1,24 +1,33 @@
|
|
|
1
|
-
import { O as surveyAssistantTranslateContentResultSchema, b as surveyAssistantSuggestItemLabelResultSchema, jt as parseSurveyAssistantError, v as surveyAssistantSuggestItemKeyResultSchema } from "./protocol-
|
|
1
|
+
import { O as surveyAssistantTranslateContentResultSchema, b as surveyAssistantSuggestItemLabelResultSchema, jt as parseSurveyAssistantError, v as surveyAssistantSuggestItemKeyResultSchema } from "./protocol-DJUP4gc0.mjs";
|
|
2
2
|
//#region src/react/client-error.ts
|
|
3
3
|
var SurveyAssistantClientError = class extends Error {
|
|
4
4
|
code;
|
|
5
|
-
|
|
5
|
+
retryable;
|
|
6
|
+
constructor(code, message, retryable = false) {
|
|
6
7
|
super(message);
|
|
7
8
|
this.name = "SurveyAssistantClientError";
|
|
8
9
|
this.code = code;
|
|
10
|
+
this.retryable = retryable;
|
|
9
11
|
}
|
|
10
12
|
};
|
|
11
13
|
const readSurveyAssistantJson = async (response, fallback = "The assistant request could not be completed.") => {
|
|
12
|
-
const body = await response.json().catch(() => ({}));
|
|
13
14
|
if (!response.ok) {
|
|
14
|
-
const
|
|
15
|
-
|
|
15
|
+
const responseText = await response.text().catch(() => "");
|
|
16
|
+
let body;
|
|
17
|
+
try {
|
|
18
|
+
body = responseText ? JSON.parse(responseText) : void 0;
|
|
19
|
+
} catch {
|
|
20
|
+
body = void 0;
|
|
21
|
+
}
|
|
22
|
+
const detail = typeof body === "object" && body !== null && "error" in body && typeof body.error === "string" ? body.error : responseText.trim() || fallback;
|
|
23
|
+
const parsed = parseSurveyAssistantError(typeof body === "object" && body !== null && "code" in body && typeof body.code === "string" ? {
|
|
16
24
|
code: body.code,
|
|
17
25
|
detail
|
|
18
26
|
} : detail);
|
|
19
|
-
|
|
27
|
+
const retryable = (typeof body === "object" && body !== null && "retryable" in body && typeof body.retryable === "boolean" ? body.retryable : void 0) ?? (parsed.code === "rate_limited" || (parsed.code === "request_failed" || parsed.code === "attachment_unavailable") && response.status >= 500);
|
|
28
|
+
throw new SurveyAssistantClientError(parsed.code, parsed.detail ?? detail, retryable);
|
|
20
29
|
}
|
|
21
|
-
return
|
|
30
|
+
return response.json().catch(() => ({}));
|
|
22
31
|
};
|
|
23
32
|
//#endregion
|
|
24
33
|
//#region src/react/thread-launcher.ts
|
|
@@ -159,4 +168,4 @@ const createSurveyAssistantControllerBridge = (options) => {
|
|
|
159
168
|
//#endregion
|
|
160
169
|
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 };
|
|
161
170
|
|
|
162
|
-
//# sourceMappingURL=controller-proxy-
|
|
171
|
+
//# sourceMappingURL=controller-proxy-jWIPOZAv.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller-proxy-jWIPOZAv.mjs","names":[],"sources":["../src/react/client-error.ts","../src/react/thread-launcher.ts","../src/react/task-client.ts","../src/react/controller-proxy.ts"],"sourcesContent":["import { parseSurveyAssistantError, type SurveyAssistantErrorCode } from \"../protocol\";\n\nexport class SurveyAssistantClientError extends Error {\n readonly code: SurveyAssistantErrorCode;\n readonly retryable: boolean;\n\n constructor(code: SurveyAssistantErrorCode, message: string, retryable = false) {\n super(message);\n this.name = \"SurveyAssistantClientError\";\n this.code = code;\n this.retryable = retryable;\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\" &&\n body !== null &&\n \"error\" in body &&\n typeof body.error === \"string\"\n ? body.error\n : responseText.trim() || fallback;\n const parsed = parseSurveyAssistantError(\n typeof body === \"object\" &&\n body !== null &&\n \"code\" in body &&\n typeof body.code === \"string\"\n ? { code: body.code, detail }\n : detail,\n );\n const explicitRetryable =\n typeof body === \"object\" &&\n body !== null &&\n \"retryable\" in body &&\n typeof body.retryable === \"boolean\"\n ? body.retryable\n : undefined;\n const retryable =\n explicitRetryable ??\n (parsed.code === \"rate_limited\" ||\n ((parsed.code === \"request_failed\" || parsed.code === \"attachment_unavailable\") &&\n response.status >= 500));\n throw new SurveyAssistantClientError(parsed.code, parsed.detail ?? detail, retryable);\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 applyAssistantChange: (change) =>\n getController()?.applyAssistantChange?.(change) ?? failedResult(change, notReadyMessage),\n applyAssistantChanges: (changes): SurveyBatchApplyResult =>\n getController()?.applyAssistantChanges?.(changes) ?? {\n results: changes.map((change) => failedResult(change, notReadyMessage)),\n },\n});\n\nexport const createSurveyAssistantControllerBridge = (\n options?: CreateSurveyAssistantControllerProxyOptions,\n): SurveyAssistantControllerBridge => {\n let currentController: SurveyAssistantController | null | undefined;\n return {\n controller: createSurveyAssistantControllerProxy(() => currentController, options),\n setController(controller) {\n currentController = controller;\n },\n };\n};\n"],"mappings":";;AAEA,IAAa,6BAAb,cAAgD,MAAM;CACpD;CACA;CAEA,YAAY,MAAgC,SAAiB,YAAY,OAAO;AAC9E,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,OAAO;AACZ,OAAK,YAAY;;;AAIrB,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,YAChB,S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AAW,aAAa,QAAQ,gBAAgB,CAAC,EACxE;CACJ;AAED,MAAa,yCACX,YACoC;CACpC,IAAI;AACJ,QAAO;EACL,YAAY,2CAA2C,mBAAmB,QAAQ;EAClF,cAAc,YAAY;AACxB,uBAAoB;;EAEvB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { I as rawSurveyDocumentSchema, f as surveyChangeSetSchema, l as surveyAssistantTurnFinalSchema } from "./protocol-
|
|
2
|
-
import { a as normalizeFormAuthoringConfig, c as assertSurveyAssistantCapabilities, i as isValidSimpleFormConfig, o as transitionFormAuthoringMode, r as isCompatibleSimpleFieldUpsert, t as getFormAuthoringMode } from "./form-authoring-
|
|
1
|
+
import { I as rawSurveyDocumentSchema, f as surveyChangeSetSchema, l as surveyAssistantTurnFinalSchema } from "./protocol-DJUP4gc0.mjs";
|
|
2
|
+
import { a as normalizeFormAuthoringConfig, c as assertSurveyAssistantCapabilities, i as isValidSimpleFormConfig, o as transitionFormAuthoringMode, r as isCompatibleSimpleFieldUpsert, t as getFormAuthoringMode } from "./form-authoring-BQh40yDb.mjs";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { ContentType, Expression, ExpressionType, FunctionExpressionNames, JsonPatchError, ReservedSurveyItemTypes, SurveyItemTranslations, SurveyTranslations, ValueReferenceMethod, ValueType, applyJsonPatch, generateId, getContentPlainText, isContentEmpty, parseJsonPointer, structuredCloneMethod } from "@case-framework/survey-core";
|
|
4
|
+
import { ContentType, Expression, ExpressionType, FunctionExpressionNames, JsonPatchError, ReservedSurveyItemTypes, SurveyItemTranslations, SurveyTranslations, ValueReference, ValueReferenceMethod, ValueType, analyzeSurveyExpressionReferences, applyJsonPatch, findIntroducedExpressionReferenceDiagnostics, generateId, getContentPlainText, isContentEmpty, parseJsonPointer, structuredCloneMethod } from "@case-framework/survey-core";
|
|
5
5
|
//#region src/engine/context.ts
|
|
6
|
-
const isRecord$
|
|
6
|
+
const isRecord$7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
7
|
const asString$1 = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
8
8
|
const asArray$1 = (value) => Array.isArray(value) ? value : [];
|
|
9
9
|
const getChildIds = (item) => {
|
|
10
|
-
return asArray$1((isRecord$
|
|
10
|
+
return asArray$1((isRecord$7(item.config) ? item.config : void 0)?.items).filter((entry) => typeof entry === "string");
|
|
11
11
|
};
|
|
12
12
|
const getFieldValueType = (field) => {
|
|
13
13
|
switch (field.type) {
|
|
@@ -23,8 +23,8 @@ const addResponseSlot = (lookup, itemId, slotId, valueType) => {
|
|
|
23
23
|
lookup[`${itemId}...${ValueReferenceMethod.isDefined}...${slotId}`] = ValueType.boolean;
|
|
24
24
|
};
|
|
25
25
|
const addFormResponseSlots = ({ config, itemId, lookup, slotPrefix }) => {
|
|
26
|
-
if (!isRecord$
|
|
27
|
-
for (const group of asArray$1(config.fieldGroups).filter(isRecord$
|
|
26
|
+
if (!isRecord$7(config)) return;
|
|
27
|
+
for (const group of asArray$1(config.fieldGroups).filter(isRecord$7)) for (const field of asArray$1(group.fields).filter(isRecord$7)) {
|
|
28
28
|
const key = asString$1(field.key);
|
|
29
29
|
if (!key) continue;
|
|
30
30
|
addResponseSlot(lookup, itemId, slotPrefix ? `${slotPrefix}.${key}` : key, getFieldValueType(field));
|
|
@@ -39,10 +39,10 @@ const deriveResponseSlotTypes = (survey, trustedCapabilities) => {
|
|
|
39
39
|
continue;
|
|
40
40
|
}
|
|
41
41
|
if (item.itemType === "choiceItem") {
|
|
42
|
-
const config = isRecord$
|
|
42
|
+
const config = isRecord$7(item.config) ? item.config : {};
|
|
43
43
|
const slotId = asString$1(config.id) ?? item.id;
|
|
44
44
|
addResponseSlot(lookup, item.id, slotId, config.maxSelection === 1 ? ValueType.reference : ValueType.referenceArray);
|
|
45
|
-
for (const option of asArray$1(config.options).filter(isRecord$
|
|
45
|
+
for (const option of asArray$1(config.options).filter(isRecord$7)) {
|
|
46
46
|
const optionId = asString$1(option.id);
|
|
47
47
|
if (optionId && option.embeddedForm) addFormResponseSlots({
|
|
48
48
|
config: option.embeddedForm,
|
|
@@ -98,7 +98,7 @@ const buildDerivedContext = (snapshot, trustedCapabilities, requestedFocusItemId
|
|
|
98
98
|
});
|
|
99
99
|
for (const childId of getChildIds(item)) visit(childId, depth + 1);
|
|
100
100
|
};
|
|
101
|
-
const explicitRoot = rawItems.find((item) => isRecord$
|
|
101
|
+
const explicitRoot = rawItems.find((item) => isRecord$7(item.config) && item.config.isRoot === true);
|
|
102
102
|
if (explicitRoot) visit(explicitRoot.id, 0);
|
|
103
103
|
for (const item of [...rawItems].sort((left, right) => left.id.localeCompare(right.id))) if (!visited.has(item.id)) visit(item.id, 0);
|
|
104
104
|
const keyIndex = outline.map((node) => ({
|
|
@@ -455,6 +455,36 @@ const validateExpression = ({ expression, expectedReturnType, issues, operationI
|
|
|
455
455
|
}));
|
|
456
456
|
};
|
|
457
457
|
//#endregion
|
|
458
|
+
//#region src/engine/expression-reference-integrity.ts
|
|
459
|
+
const isRecord$6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
460
|
+
const choiceAllowedValues = (survey, ref) => {
|
|
461
|
+
let parsed;
|
|
462
|
+
try {
|
|
463
|
+
parsed = new ValueReference(ref);
|
|
464
|
+
} catch {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
if (parsed.name !== ValueReferenceMethod.get) return void 0;
|
|
468
|
+
const item = survey.surveyItems.find((candidate) => candidate.id === parsed.itemId);
|
|
469
|
+
if (item?.itemType !== "choiceItem" || !isRecord$6(item.config)) return void 0;
|
|
470
|
+
const slotId = typeof item.config.id === "string" ? item.config.id : item.id;
|
|
471
|
+
if (parsed.slotId !== slotId || !Array.isArray(item.config.options)) return void 0;
|
|
472
|
+
return item.config.options.flatMap((option) => isRecord$6(option) && typeof option.id === "string" ? [option.id] : []);
|
|
473
|
+
};
|
|
474
|
+
const deriveSurveyExpressionResponseSlots = (survey, trustedCapabilities) => Object.entries(deriveResponseSlotTypes(survey, trustedCapabilities)).flatMap(([ref, valueType]) => {
|
|
475
|
+
if (!valueType) return [];
|
|
476
|
+
const allowedReferenceValues = valueType === ValueType.reference || valueType === ValueType.referenceArray ? choiceAllowedValues(survey, ref) : void 0;
|
|
477
|
+
return [{
|
|
478
|
+
ref,
|
|
479
|
+
valueType,
|
|
480
|
+
...allowedReferenceValues ? { allowedReferenceValues } : {}
|
|
481
|
+
}];
|
|
482
|
+
});
|
|
483
|
+
const analyzeSurveyAssistantExpressionReferences = (survey, trustedCapabilities) => analyzeSurveyExpressionReferences({
|
|
484
|
+
survey,
|
|
485
|
+
responseSlots: deriveSurveyExpressionResponseSlots(survey, trustedCapabilities)
|
|
486
|
+
});
|
|
487
|
+
//#endregion
|
|
458
488
|
//#region src/engine/inspection.ts
|
|
459
489
|
const DEFAULT_LIMIT = 12;
|
|
460
490
|
const MAX_LIMIT = 50;
|
|
@@ -2469,6 +2499,17 @@ const validateSurveyTreeStructure = (survey, operationId, availableItemTypes) =>
|
|
|
2469
2499
|
}
|
|
2470
2500
|
return issues;
|
|
2471
2501
|
};
|
|
2502
|
+
const collectIntroducedExpressionIntegrityIssues = ({ after, before, operationId, operationIndex = 0, snapshot }) => findIntroducedExpressionReferenceDiagnostics({
|
|
2503
|
+
before: analyzeSurveyAssistantExpressionReferences(before, snapshot.trustedCapabilities),
|
|
2504
|
+
after: analyzeSurveyAssistantExpressionReferences(after, snapshot.trustedCapabilities)
|
|
2505
|
+
}).map((diagnostic) => createIssue({
|
|
2506
|
+
severity: "warning",
|
|
2507
|
+
code: diagnostic.code,
|
|
2508
|
+
message: `${diagnostic.message}${diagnostic.candidates?.length ? ` Available replacements include: ${diagnostic.candidates.join(", ")}.` : ""} Update or clear every affected expression in the same assistant turn; the editor will reject the final batch while this remains unresolved.`,
|
|
2509
|
+
operationIndex,
|
|
2510
|
+
operationId,
|
|
2511
|
+
itemId: diagnostic.ownerItemId
|
|
2512
|
+
}));
|
|
2472
2513
|
const validateSurveyJsonPatchOperation = ({ operation, snapshot }) => {
|
|
2473
2514
|
const operationId = getOperationId(operation);
|
|
2474
2515
|
const issues = [];
|
|
@@ -2564,6 +2605,12 @@ const validateSurveyJsonPatchOperation = ({ operation, snapshot }) => {
|
|
|
2564
2605
|
operationId
|
|
2565
2606
|
}));
|
|
2566
2607
|
}
|
|
2608
|
+
warnings.push(...collectIntroducedExpressionIntegrityIssues({
|
|
2609
|
+
after: patchedSurvey,
|
|
2610
|
+
before: snapshot.survey,
|
|
2611
|
+
operationId,
|
|
2612
|
+
snapshot
|
|
2613
|
+
}));
|
|
2567
2614
|
if (getRawItemsFromSurvey(patchedSurvey).length !== getRawSurveyItems(snapshot).length) warnings.push(createIssue({
|
|
2568
2615
|
severity: "warning",
|
|
2569
2616
|
code: "raw-patch-changed-item-count",
|
|
@@ -4627,6 +4674,23 @@ const validateSurveyOperations = ({ maxOperations = 200, operations, snapshot: s
|
|
|
4627
4674
|
}
|
|
4628
4675
|
}
|
|
4629
4676
|
});
|
|
4677
|
+
if (issues.length === 0) try {
|
|
4678
|
+
const prospectiveSurvey = applyValidatedSurveyOperationsToDraft({
|
|
4679
|
+
operations: normalizedOperations,
|
|
4680
|
+
survey: snapshot.survey
|
|
4681
|
+
});
|
|
4682
|
+
warnings.push(...collectIntroducedExpressionIntegrityIssues({
|
|
4683
|
+
after: prospectiveSurvey,
|
|
4684
|
+
before: snapshot.survey,
|
|
4685
|
+
operationIndex: Math.max(0, normalizedOperations.length - 1),
|
|
4686
|
+
snapshot
|
|
4687
|
+
}));
|
|
4688
|
+
} catch (error) {
|
|
4689
|
+
issues.push(createIssue({
|
|
4690
|
+
code: "expression-integrity-check-failed",
|
|
4691
|
+
message: `The resulting survey could not be checked for expression integrity: ${error instanceof Error ? error.message : String(error)}`
|
|
4692
|
+
}));
|
|
4693
|
+
}
|
|
4630
4694
|
return {
|
|
4631
4695
|
valid: issues.length === 0,
|
|
4632
4696
|
issues,
|
|
@@ -5106,6 +5170,11 @@ const QUALITY_PRINCIPLES = [
|
|
|
5106
5170
|
title: "Response option quality",
|
|
5107
5171
|
prompt: "Are options mutually exclusive, collectively sufficient, balanced, ordered, and consistently scaled?"
|
|
5108
5172
|
},
|
|
5173
|
+
{
|
|
5174
|
+
id: "key-semantic-consistency",
|
|
5175
|
+
title: "Coding-key consistency",
|
|
5176
|
+
prompt: "Do item, option, and field keys follow the survey's established convention and avoid contradicting the content they currently identify? Generic, numeric, or opaque keys are acceptable when that is the survey's consistent pattern; flag descriptive keys when they have become stale or misleading, and mixed conventions when the inconsistency appears accidental."
|
|
5177
|
+
},
|
|
5109
5178
|
{
|
|
5110
5179
|
id: "flow",
|
|
5111
5180
|
title: "Flow and completeness",
|
|
@@ -5143,6 +5212,75 @@ const translationText = (context, locale, itemId, contentKey) => {
|
|
|
5143
5212
|
const content = (isRecord$1(itemTranslations?.[itemId]) ? itemTranslations[itemId] : void 0)?.[contentKey];
|
|
5144
5213
|
return content ? getContentPlainText(content).trim() : "";
|
|
5145
5214
|
};
|
|
5215
|
+
const summarizeItemContent = (context, locale, item) => {
|
|
5216
|
+
if (!locale) return {};
|
|
5217
|
+
const itemContent = context.survey.translations?.[locale]?.itemTranslations?.[item.id];
|
|
5218
|
+
if (!isRecord$1(itemContent)) return {};
|
|
5219
|
+
for (const contentKey of [
|
|
5220
|
+
"title",
|
|
5221
|
+
"content",
|
|
5222
|
+
"subtitle",
|
|
5223
|
+
"topContent",
|
|
5224
|
+
"bottomContent"
|
|
5225
|
+
]) {
|
|
5226
|
+
const content = itemContent[contentKey];
|
|
5227
|
+
if (!content) continue;
|
|
5228
|
+
const text = getContentPlainText(content).trim();
|
|
5229
|
+
if (text) return {
|
|
5230
|
+
contentKey,
|
|
5231
|
+
content: text
|
|
5232
|
+
};
|
|
5233
|
+
}
|
|
5234
|
+
return {};
|
|
5235
|
+
};
|
|
5236
|
+
const collectKeyReviewEntries = (context, sourceLocale) => {
|
|
5237
|
+
const entries = [];
|
|
5238
|
+
const addFormFields = (item, groups, contentPrefix) => {
|
|
5239
|
+
for (const group of groups) for (const field of records(group.fields)) {
|
|
5240
|
+
if (typeof field.id !== "string" || typeof field.key !== "string") continue;
|
|
5241
|
+
const contentKey = `${contentPrefix}fields.${field.id}.label`;
|
|
5242
|
+
const content = sourceLocale ? translationText(context, sourceLocale, item.id, contentKey) : "";
|
|
5243
|
+
entries.push({
|
|
5244
|
+
kind: "form-field",
|
|
5245
|
+
itemId: item.id,
|
|
5246
|
+
itemKey: item.key,
|
|
5247
|
+
key: field.key,
|
|
5248
|
+
keySource: "explicit",
|
|
5249
|
+
contentKey,
|
|
5250
|
+
...content ? { content } : {}
|
|
5251
|
+
});
|
|
5252
|
+
}
|
|
5253
|
+
};
|
|
5254
|
+
for (const item of context.survey.surveyItems) {
|
|
5255
|
+
entries.push({
|
|
5256
|
+
kind: "item",
|
|
5257
|
+
itemId: item.id,
|
|
5258
|
+
itemKey: item.key,
|
|
5259
|
+
key: item.key,
|
|
5260
|
+
keySource: "explicit",
|
|
5261
|
+
...summarizeItemContent(context, sourceLocale, item)
|
|
5262
|
+
});
|
|
5263
|
+
const config = isRecord$1(item.config) ? item.config : {};
|
|
5264
|
+
if (item.itemType === "choiceItem") for (const option of records(config.options)) {
|
|
5265
|
+
if (typeof option.id !== "string") continue;
|
|
5266
|
+
const explicitKey = typeof option.key === "string" && option.key.trim() ? option.key : null;
|
|
5267
|
+
const contentKey = `options.${option.id}.label`;
|
|
5268
|
+
const content = sourceLocale ? translationText(context, sourceLocale, item.id, contentKey) : "";
|
|
5269
|
+
entries.push({
|
|
5270
|
+
kind: "choice-option",
|
|
5271
|
+
itemId: item.id,
|
|
5272
|
+
itemKey: item.key,
|
|
5273
|
+
key: explicitKey ?? option.id,
|
|
5274
|
+
keySource: explicitKey ? "explicit" : "fallback-id",
|
|
5275
|
+
contentKey,
|
|
5276
|
+
...content ? { content } : {}
|
|
5277
|
+
});
|
|
5278
|
+
if (option.embeddedForm) addFormFields(item, getGroups(item, option.id), `embeddedForms.${option.id}.`);
|
|
5279
|
+
}
|
|
5280
|
+
else if (item.itemType === "formItem") addFormFields(item, getGroups(item), "");
|
|
5281
|
+
}
|
|
5282
|
+
return entries;
|
|
5283
|
+
};
|
|
5146
5284
|
const getGroups = (item, optionId) => {
|
|
5147
5285
|
const config = isRecord$1(item.config) ? item.config : {};
|
|
5148
5286
|
if (!optionId) return records(config.fieldGroups);
|
|
@@ -5221,6 +5359,10 @@ const auditSurvey = (context, options = {}) => {
|
|
|
5221
5359
|
const locales = context.inspection.locales;
|
|
5222
5360
|
const sourceLocale = options.sourceLocale ?? context.ui.selectedLocale ?? locales[0];
|
|
5223
5361
|
const targetLocales = options.targetLocales ?? locales.filter((locale) => locale !== sourceLocale);
|
|
5362
|
+
const allKeyReviewEntries = collectKeyReviewEntries(context, sourceLocale);
|
|
5363
|
+
const keyReviewOffset = Math.min(options.keyReviewOffset ?? 0, allKeyReviewEntries.length);
|
|
5364
|
+
const keyReviewLimit = options.keyReviewLimit ?? 30;
|
|
5365
|
+
const keyReviewEntries = allKeyReviewEntries.slice(keyReviewOffset, keyReviewOffset + keyReviewLimit);
|
|
5224
5366
|
const manifests = new Map(context.capabilities.itemTypes.map((entry) => [entry.itemType, entry]));
|
|
5225
5367
|
for (const item of items) {
|
|
5226
5368
|
const manifest = manifests.get(item.itemType);
|
|
@@ -5309,6 +5451,15 @@ const auditSurvey = (context, options = {}) => {
|
|
|
5309
5451
|
});
|
|
5310
5452
|
}
|
|
5311
5453
|
}
|
|
5454
|
+
for (const diagnostic of analyzeSurveyAssistantExpressionReferences(context.survey, context.trustedCapabilities)) add({
|
|
5455
|
+
code: diagnostic.code,
|
|
5456
|
+
severity: "error",
|
|
5457
|
+
category: "logic",
|
|
5458
|
+
message: diagnostic.message,
|
|
5459
|
+
...diagnostic.ownerItemId ? { itemId: diagnostic.ownerItemId } : {},
|
|
5460
|
+
contentKey: diagnostic.location,
|
|
5461
|
+
suggestion: diagnostic.candidates && diagnostic.candidates.length > 0 ? `Use one of the valid current references: ${diagnostic.candidates.join(", ")}.` : "Inspect the current response slots and expression location before repairing it."
|
|
5462
|
+
});
|
|
5312
5463
|
const assets = context.survey.assets ?? {};
|
|
5313
5464
|
for (const [assetId, asset] of Object.entries(assets)) {
|
|
5314
5465
|
const metadata = isRecord$1(asset.metadata) ? asset.metadata : {};
|
|
@@ -5343,6 +5494,15 @@ const auditSurvey = (context, options = {}) => {
|
|
|
5343
5494
|
},
|
|
5344
5495
|
findings: limited,
|
|
5345
5496
|
qualityReviewPrinciples: QUALITY_PRINCIPLES,
|
|
5497
|
+
keyReview: {
|
|
5498
|
+
sourceLocale,
|
|
5499
|
+
entryCount: allKeyReviewEntries.length,
|
|
5500
|
+
offset: keyReviewOffset,
|
|
5501
|
+
returnedEntryCount: keyReviewEntries.length,
|
|
5502
|
+
truncated: keyReviewOffset + keyReviewEntries.length < allKeyReviewEntries.length,
|
|
5503
|
+
entries: keyReviewEntries,
|
|
5504
|
+
note: "These key/content pairs are evidence for qualitative review, not deterministic defects. Judge them against the survey's own naming pattern; generic or opaque keys are not inherently problematic."
|
|
5505
|
+
},
|
|
5346
5506
|
note: "Technical findings are deterministic. Quality principles are a structured review rubric; apply them with human/model judgment and domain context, and do not present them as psychometric validation."
|
|
5347
5507
|
};
|
|
5348
5508
|
};
|
|
@@ -5864,6 +6024,6 @@ var SurveyAssistantTaskResultCache = class {
|
|
|
5864
6024
|
}
|
|
5865
6025
|
};
|
|
5866
6026
|
//#endregion
|
|
5867
|
-
export {
|
|
6027
|
+
export { validateExpression as $, getRawSurvey$1 as A, resolveItemSummary as B, clampLimit as C, formFieldGroupLayoutSchema as D, formFieldGroupDetailsSchema as E, mapKeyIndexById as F, summarizeKeyIndexEntry as G, summarizeFocusItemNode as H, mapOutlineById as I, translationEntrySchema as J, summarizeOutlineNode as K, mapRawItemsById as L, itemConfigDetailsSchema as M, itemMatchesQuery as N, formSelectOptionDetailsSchema as O, itemSummarySchema as P, inferExpressionReturnType as Q, normalizeText as R, choiceOptionDetailsSchema as S, formFieldDetailsSchema as T, summarizeItemById as U, sliceWithCursor as V, summarizeKeyIndexEntries as W, analyzeSurveyAssistantExpressionReferences as X, unique as Y, deriveSurveyExpressionResponseSlots as Z, buildConfigSearchText as _, MAX_SURVEY_ASSISTANT_OPERATIONS_PER_PROPOSAL as a, buildItemTranslationEntries as b, buildSurveyDocumentVersion as c, normalizeSurveyChangeOperations as d, createSurveyAssistantEngineContext as et, buildExpressionMutationPatches as f, MAX_LIMIT as g, DEFAULT_LIMIT as h, auditSurvey as i, getRawSurveyItems as j, getKeyIndexEntries as k, createSurveyChangeSet as l, expressionSchema as m, buildSurveyAssistantTaskContext as n, MAX_SURVEY_ASSISTANT_OPERATIONS_PER_TURN_DRAFT as o, expressionMutationSchema as p, summarizeRawItem as q, TurnSurveyDraft as r, applyValidatedSurveyOperationsToDraft as s, SurveyAssistantTaskResultCache as t, deriveResponseSlotTypes as tt, validateSurveyOperations as u, buildEmbeddedFormDetails as v, findDirectChildrenByFullKey as w, buildSurveyTranslations as x, buildItemConfigDetails as y, parseCursor as z };
|
|
5868
6028
|
|
|
5869
|
-
//# sourceMappingURL=engine-
|
|
6029
|
+
//# sourceMappingURL=engine-DcSdLRle.mjs.map
|