@case-framework/survey-assistant 0.2.2 → 0.2.3
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/dist/{authoring-references-DYuOAdVx.mjs → authoring-references-ChDTVnms.mjs} +8 -2
- package/dist/authoring-references-ChDTVnms.mjs.map +1 -0
- package/dist/{capabilities-DlC1l6qy.d.mts → capabilities-CnsVuJ1k.d.mts} +12 -4
- package/dist/capabilities-CnsVuJ1k.d.mts.map +1 -0
- package/dist/capabilities-default.d.mts +1 -1
- package/dist/capabilities-default.d.mts.map +1 -1
- package/dist/capabilities-default.mjs +38 -4
- package/dist/capabilities-default.mjs.map +1 -1
- package/dist/{constants-D-5m_KGB.d.mts → constants-BK1-g6pR.d.mts} +12 -7
- package/dist/constants-BK1-g6pR.d.mts.map +1 -0
- package/dist/{controller-proxy-Hkuub9dt.d.mts → controller-proxy-CIDRd8Wu.d.mts} +2 -2
- package/dist/{controller-proxy-Hkuub9dt.d.mts.map → controller-proxy-CIDRd8Wu.d.mts.map} +1 -1
- package/dist/{controller-proxy-0WJZUZYx.mjs → controller-proxy-DY36XFV3.mjs} +2 -2
- package/dist/{controller-proxy-0WJZUZYx.mjs.map → controller-proxy-DY36XFV3.mjs.map} +1 -1
- package/dist/{digest-BvXpeWcR.d.mts → digest-Dyjch_sC.d.mts} +2 -2
- package/dist/{digest-BvXpeWcR.d.mts.map → digest-Dyjch_sC.d.mts.map} +1 -1
- package/dist/digest.d.mts +1 -1
- package/dist/{engine-0AJrv0hI.mjs → engine-CWTuN3o2.mjs} +866 -663
- package/dist/engine-CWTuN3o2.mjs.map +1 -0
- package/dist/engine.d.mts +3 -3
- package/dist/engine.mjs +3 -3
- package/dist/fair-guidance-CEdJYccK.mjs +21 -0
- package/dist/fair-guidance-CEdJYccK.mjs.map +1 -0
- package/dist/form-authoring-DCd9XfXf.mjs +155 -0
- package/dist/form-authoring-DCd9XfXf.mjs.map +1 -0
- package/dist/{index-BcyfBeDj.d.mts → index-Bp5W_oPa.d.mts} +25 -5
- package/dist/index-Bp5W_oPa.d.mts.map +1 -0
- package/dist/{index-JXH-t2EJ.d.mts → index-CPOQgkTN.d.mts} +67 -6
- package/dist/index-CPOQgkTN.d.mts.map +1 -0
- package/dist/{index-MEOL9_Gr.d.mts → index-EDL1V168.d.mts} +98 -4
- package/dist/{index-MEOL9_Gr.d.mts.map → index-EDL1V168.d.mts.map} +1 -1
- package/dist/{index-CneD8ibB.d.mts → index-SPHf3OoJ.d.mts} +9 -3
- package/dist/index-SPHf3OoJ.d.mts.map +1 -0
- package/dist/{memory-thread-repository-1ocPOda8.mjs → memory-thread-repository-acbz6HZJ.mjs} +181 -26
- package/dist/memory-thread-repository-acbz6HZJ.mjs.map +1 -0
- package/dist/{protocol-DpCYmCjr.mjs → protocol-DATvkr1S.mjs} +125 -6
- package/dist/protocol-DATvkr1S.mjs.map +1 -0
- package/dist/protocol.d.mts +3 -3
- package/dist/protocol.mjs +2 -2
- package/dist/{react-DXK5zWNo.mjs → react-3kSE6WtS.mjs} +127 -9
- package/dist/react-3kSE6WtS.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/references/assistant-operations.md +13 -18
- package/dist/references/embedded-forms.md +41 -2
- package/dist/references/expressions.md +17 -9
- package/dist/references/fair-by-design.md +80 -0
- package/dist/references/item-types.md +19 -3
- package/dist/references/localization.md +7 -4
- package/dist/references/source-material-surveys.md +6 -4
- package/dist/{request-context-BBzU3VdG.mjs → request-context-BEjnaaFr.mjs} +10 -5
- package/dist/request-context-BEjnaaFr.mjs.map +1 -0
- package/dist/server-agent.d.mts +26 -6
- package/dist/server-agent.d.mts.map +1 -1
- package/dist/server-agent.mjs +70 -13
- package/dist/server-agent.mjs.map +1 -1
- package/dist/server-runtime.d.mts +22 -11
- package/dist/server-runtime.d.mts.map +1 -1
- package/dist/server-runtime.mjs +47 -19
- package/dist/server-runtime.mjs.map +1 -1
- package/dist/server-tasks.d.mts +1 -1
- package/dist/server-tasks.mjs +4 -3
- 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 +16 -7
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +4 -4
- package/dist/storage-postgres.d.mts +1 -1
- package/dist/{tasks-DcfQNJwO.d.mts → tasks-DIZgr4nD.d.mts} +8 -4
- package/dist/tasks-DIZgr4nD.d.mts.map +1 -0
- package/dist/{thread-documents-BlxNjc7S.d.mts → thread-documents-C3kf0Vds.d.mts} +1 -1
- package/dist/{thread-documents-BlxNjc7S.d.mts.map → thread-documents-C3kf0Vds.d.mts.map} +1 -1
- package/dist/{thread-handlers-uddXwQjp.d.mts → thread-handlers-DZ1WsorO.d.mts} +9 -4
- package/dist/thread-handlers-DZ1WsorO.d.mts.map +1 -0
- package/dist/{tools-wgLen05n.mjs → tools-GDd5_GUh.mjs} +403 -77
- package/dist/tools-GDd5_GUh.mjs.map +1 -0
- 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 +152 -36
- package/dist/ui.mjs.map +1 -1
- package/docs/integration.md +73 -5
- package/package.json +3 -3
- package/dist/authoring-references-DYuOAdVx.mjs.map +0 -1
- package/dist/capabilities-DKbNCnBf.mjs +0 -66
- package/dist/capabilities-DKbNCnBf.mjs.map +0 -1
- package/dist/capabilities-DlC1l6qy.d.mts.map +0 -1
- package/dist/constants-D-5m_KGB.d.mts.map +0 -1
- package/dist/engine-0AJrv0hI.mjs.map +0 -1
- package/dist/index-BcyfBeDj.d.mts.map +0 -1
- package/dist/index-CneD8ibB.d.mts.map +0 -1
- package/dist/index-JXH-t2EJ.d.mts.map +0 -1
- package/dist/memory-thread-repository-1ocPOda8.mjs.map +0 -1
- package/dist/protocol-DpCYmCjr.mjs.map +0 -1
- package/dist/react-DXK5zWNo.mjs.map +0 -1
- package/dist/request-context-BBzU3VdG.mjs.map +0 -1
- package/dist/tasks-DcfQNJwO.d.mts.map +0 -1
- package/dist/thread-handlers-uddXwQjp.d.mts.map +0 -1
- package/dist/tools-wgLen05n.mjs.map +0 -1
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as SurveyAssistantThreadDocumentRepository } from "./thread-documents-
|
|
1
|
+
import { E as SurveyAssistantModelCatalog } from "./index-EDL1V168.mjs";
|
|
2
|
+
import { Bt as SurveyAssistantCapabilitySet } from "./index-CPOQgkTN.mjs";
|
|
3
|
+
import { a as SurveyAssistantThreadDocumentRepository } from "./thread-documents-C3kf0Vds.mjs";
|
|
4
|
+
import { a as SurveyAssistantModelSelection } from "./constants-BK1-g6pR.mjs";
|
|
4
5
|
import { SurveyAssistantObservationalMemoryOptions, createSurveyAssistantAgent } from "./server-agent.mjs";
|
|
5
|
-
import { O as SurveyAssistantRequestLimits, c as SurveyAssistantAuthorize, f as SurveyAssistantResolveModel, t as CreateSurveyAssistantThreadHandlersOptions, u as SurveyAssistantChatHandlerOptions } from "./thread-handlers-
|
|
6
|
-
import { c as createSurveyAssistantTaskAgent, n as CreateSurveyAssistantTaskHandlerOptions, s as SurveyAssistantTaskModelResolutionInput } from "./tasks-
|
|
6
|
+
import { O as SurveyAssistantRequestLimits, c as SurveyAssistantAuthorize, f as SurveyAssistantResolveModel, t as CreateSurveyAssistantThreadHandlersOptions, u as SurveyAssistantChatHandlerOptions } from "./thread-handlers-DZ1WsorO.mjs";
|
|
7
|
+
import { c as createSurveyAssistantTaskAgent, n as CreateSurveyAssistantTaskHandlerOptions, s as SurveyAssistantTaskModelResolutionInput } from "./tasks-DIZgr4nD.mjs";
|
|
7
8
|
import { AgentExecutionOptions } from "@mastra/core/agent";
|
|
8
9
|
import { AzureOpenAIGatewayConfig, MastraModelGatewayInterface } from "@mastra/core/llm";
|
|
9
10
|
import { Mastra } from "@mastra/core/mastra";
|
|
10
11
|
|
|
11
12
|
//#region src/server/runtime-config.d.ts
|
|
12
|
-
type SurveyAssistantProvider = "azure-openai" | "mistral" | "openai";
|
|
13
|
-
type SurveyAssistantProviderOptionsKey = "azure" | "mistral" | "openai";
|
|
13
|
+
type SurveyAssistantProvider = "azure-openai" | "lmstudio" | "mistral" | "openai";
|
|
14
|
+
type SurveyAssistantProviderOptionsKey = "azure" | "lmstudio" | "mistral" | "openai";
|
|
14
15
|
interface SurveyAssistantAzureConfig {
|
|
15
16
|
apiKey?: string;
|
|
16
17
|
apiVersion: string;
|
|
@@ -18,8 +19,15 @@ interface SurveyAssistantAzureConfig {
|
|
|
18
19
|
management?: AzureOpenAIGatewayConfig["management"];
|
|
19
20
|
resourceName?: string;
|
|
20
21
|
}
|
|
22
|
+
interface SurveyAssistantLmStudioConfig {
|
|
23
|
+
apiKey?: string;
|
|
24
|
+
baseUrl: string;
|
|
25
|
+
}
|
|
21
26
|
interface SurveyAssistantExecutionConfig {
|
|
27
|
+
firstResponseTimeoutMs: number;
|
|
28
|
+
idleTimeoutMs: number;
|
|
22
29
|
maxConcurrentRequests: number;
|
|
30
|
+
/** Absolute execution ceiling. Active streams still stop when this duration is reached. */
|
|
23
31
|
maxDurationMs: number;
|
|
24
32
|
maxSteps: number;
|
|
25
33
|
providerOptions?: AgentExecutionOptions["providerOptions"];
|
|
@@ -27,6 +35,7 @@ interface SurveyAssistantExecutionConfig {
|
|
|
27
35
|
}
|
|
28
36
|
interface SurveyAssistantRuntimeConfig {
|
|
29
37
|
azure?: SurveyAssistantAzureConfig;
|
|
38
|
+
lmstudio?: SurveyAssistantLmStudioConfig;
|
|
30
39
|
/** Default chat model and fallback for chat requests without a selection. */
|
|
31
40
|
defaultModelId: string;
|
|
32
41
|
enabled: boolean;
|
|
@@ -46,6 +55,7 @@ interface SurveyAssistantRuntimeConfig {
|
|
|
46
55
|
execution: SurveyAssistantExecutionConfig;
|
|
47
56
|
}
|
|
48
57
|
interface ParseSurveyAssistantEnvironmentOptions {
|
|
58
|
+
defaultLmStudioModel?: string;
|
|
49
59
|
defaultMistralModel?: string;
|
|
50
60
|
defaultOpenAIModel?: string;
|
|
51
61
|
defaultProvider?: SurveyAssistantProvider;
|
|
@@ -55,6 +65,7 @@ interface ParseSurveyAssistantEnvironmentOptions {
|
|
|
55
65
|
type Environment = Record<string, string | undefined>;
|
|
56
66
|
declare const resolveSurveyAssistantProviderOptionsKey: (provider: SurveyAssistantProvider) => SurveyAssistantProviderOptionsKey;
|
|
57
67
|
declare const parseSurveyAssistantEnvironment: (env: Environment, {
|
|
68
|
+
defaultLmStudioModel,
|
|
58
69
|
defaultMistralModel,
|
|
59
70
|
defaultOpenAIModel,
|
|
60
71
|
defaultProvider,
|
|
@@ -64,17 +75,17 @@ declare const parseSurveyAssistantEnvironment: (env: Environment, {
|
|
|
64
75
|
//#endregion
|
|
65
76
|
//#region src/server/runtime.d.ts
|
|
66
77
|
interface SurveyAssistantModelRouter {
|
|
67
|
-
defaultModel:
|
|
78
|
+
defaultModel: SurveyAssistantModelSelection["model"];
|
|
68
79
|
gateways?: Record<string, MastraModelGatewayInterface>;
|
|
69
80
|
getCatalog(options?: {
|
|
70
81
|
refresh?: boolean;
|
|
71
82
|
}): Promise<SurveyAssistantModelCatalog>;
|
|
72
|
-
memoryModel:
|
|
83
|
+
memoryModel: SurveyAssistantModelSelection["model"];
|
|
73
84
|
providerName: string;
|
|
74
85
|
providerOptions?: AgentExecutionOptions["providerOptions"];
|
|
75
86
|
resolveModel: SurveyAssistantResolveModel;
|
|
76
87
|
resolveTaskModel(input: SurveyAssistantTaskModelResolutionInput): ReturnType<SurveyAssistantResolveModel>;
|
|
77
|
-
taskModel?:
|
|
88
|
+
taskModel?: SurveyAssistantModelSelection["model"];
|
|
78
89
|
}
|
|
79
90
|
declare const createSurveyAssistantModelRouter: (config: SurveyAssistantRuntimeConfig) => SurveyAssistantModelRouter;
|
|
80
91
|
interface SurveyAssistantRuntimeComponents {
|
|
@@ -135,5 +146,5 @@ interface CreateSurveyAssistantRuntimeOptions {
|
|
|
135
146
|
*/
|
|
136
147
|
declare const createSurveyAssistantRuntime: (config: SurveyAssistantRuntimeConfig, runtimeOptions?: CreateSurveyAssistantRuntimeOptions) => SurveyAssistantRuntime;
|
|
137
148
|
//#endregion
|
|
138
|
-
export { CreateConfiguredSurveyAssistantRuntimeHandlersOptions, CreateSurveyAssistantRuntimeHandlersOptions, CreateSurveyAssistantRuntimeOptions, type ParseSurveyAssistantEnvironmentOptions, type SurveyAssistantAzureConfig, type SurveyAssistantExecutionConfig, SurveyAssistantModelRouter, type SurveyAssistantProvider, type SurveyAssistantProviderOptionsKey, SurveyAssistantRuntime, SurveyAssistantRuntimeComponents, type SurveyAssistantRuntimeConfig, createSurveyAssistantModelRouter, createSurveyAssistantRuntime, createSurveyAssistantRuntimeComponents, createSurveyAssistantRuntimeHandlers, parseSurveyAssistantEnvironment, resolveSurveyAssistantProviderOptionsKey };
|
|
149
|
+
export { CreateConfiguredSurveyAssistantRuntimeHandlersOptions, CreateSurveyAssistantRuntimeHandlersOptions, CreateSurveyAssistantRuntimeOptions, type ParseSurveyAssistantEnvironmentOptions, type SurveyAssistantAzureConfig, type SurveyAssistantExecutionConfig, type SurveyAssistantLmStudioConfig, SurveyAssistantModelRouter, type SurveyAssistantProvider, type SurveyAssistantProviderOptionsKey, SurveyAssistantRuntime, SurveyAssistantRuntimeComponents, type SurveyAssistantRuntimeConfig, createSurveyAssistantModelRouter, createSurveyAssistantRuntime, createSurveyAssistantRuntimeComponents, createSurveyAssistantRuntimeHandlers, parseSurveyAssistantEnvironment, resolveSurveyAssistantProviderOptionsKey };
|
|
139
150
|
//# sourceMappingURL=server-runtime.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-runtime.d.mts","names":[],"sources":["../src/server/runtime-config.ts","../src/server/runtime.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"server-runtime.d.mts","names":[],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;AAAA;;;;;;cAQX,4BAAA,GACX,MAAA,EAAQ,4BAAA,EACR,cAAA,GAAgB,mCAAA,KACf,sBAAA"}
|
package/dist/server-runtime.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { n as SURVEY_ASSISTANT_TASK_AGENT_ID, t as SURVEY_ASSISTANT_AGENT_ID } from "./constants-CFUWrRtl.mjs";
|
|
2
2
|
import { n as SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS } from "./request-guardrails-h4t6u8mP.mjs";
|
|
3
|
-
import { i as createSurveyAssistantChatHandler, n as createSurveyAssistantThreadHandlers, r as SurveyAssistantAuthorizationError, t as createMastraMemoryThreadRepository } from "./memory-thread-repository-
|
|
4
|
-
import { t as SURVEY_ASSISTANT_TOOL_IDS } from "./tools-
|
|
3
|
+
import { i as createSurveyAssistantChatHandler, n as createSurveyAssistantThreadHandlers, r as SurveyAssistantAuthorizationError, t as createMastraMemoryThreadRepository } from "./memory-thread-repository-acbz6HZJ.mjs";
|
|
4
|
+
import { t as SURVEY_ASSISTANT_TOOL_IDS } from "./tools-GDd5_GUh.mjs";
|
|
5
5
|
import { SURVEY_ASSISTANT_OBSERVATIONAL_MEMORY_DEFAULTS, createSurveyAssistantAgent, createSurveyAssistantObservationalMemoryOptions } from "./server-agent.mjs";
|
|
6
6
|
import { createSurveyAssistantTaskAgent, createSurveyAssistantTaskHandler } from "./server-tasks.mjs";
|
|
7
7
|
import { AzureOpenAIGateway } from "@mastra/core/llm";
|
|
8
8
|
//#region src/server/runtime-config.ts
|
|
9
9
|
const DEFAULT_MAX_STEPS = 48;
|
|
10
10
|
const HARD_MAX_STEPS = 64;
|
|
11
|
-
const
|
|
11
|
+
const DEFAULT_FIRST_RESPONSE_TIMEOUT_MS = 900 * 1e3;
|
|
12
|
+
const DEFAULT_IDLE_TIMEOUT_MS = 300 * 1e3;
|
|
13
|
+
const DEFAULT_MAX_DURATION_MS = 3600 * 1e3;
|
|
12
14
|
const DEFAULT_CATALOG_TTL_MS = 300 * 1e3;
|
|
13
15
|
const getValue = (env, name) => {
|
|
14
16
|
return env[name]?.trim() || void 0;
|
|
@@ -34,20 +36,20 @@ const getEnum = (env, name, values) => {
|
|
|
34
36
|
return value;
|
|
35
37
|
};
|
|
36
38
|
const getCommaSeparatedValues = (env, name) => [...new Set((getValue(env, name) ?? "").split(",").map((value) => value.trim()).filter(Boolean))];
|
|
37
|
-
const getSameProviderModelId = (value, name) => {
|
|
38
|
-
if (value.includes("/")) throw new Error(`${name} must be a model or deployment id without a provider prefix. All survey assistant models use SURVEY_ASSISTANT_PROVIDER.`);
|
|
39
|
+
const getSameProviderModelId = (value, name, { allowNestedId = false } = {}) => {
|
|
40
|
+
if (!allowNestedId && value.includes("/")) throw new Error(`${name} must be a model or deployment id without a provider prefix. All survey assistant models use SURVEY_ASSISTANT_PROVIDER.`);
|
|
39
41
|
return value;
|
|
40
42
|
};
|
|
41
|
-
const getOptionalSameProviderModelId = (env, name) => {
|
|
43
|
+
const getOptionalSameProviderModelId = (env, name, options) => {
|
|
42
44
|
const value = getValue(env, name);
|
|
43
|
-
return value ? getSameProviderModelId(value, name) : void 0;
|
|
45
|
+
return value ? getSameProviderModelId(value, name, options) : void 0;
|
|
44
46
|
};
|
|
45
47
|
const resolveSurveyAssistantProviderOptionsKey = (provider) => provider === "azure-openai" ? "azure" : provider;
|
|
46
48
|
const parseProvider = (env, fallback) => {
|
|
47
49
|
const value = getValue(env, "SURVEY_ASSISTANT_PROVIDER")?.toLowerCase();
|
|
48
50
|
if (value === "azure" || value === "azure-openai") return "azure-openai";
|
|
49
|
-
if (value === "openai" || value === "mistral") return value;
|
|
50
|
-
if (value) throw new Error("SURVEY_ASSISTANT_PROVIDER must be one of: openai, mistral, azure-openai.");
|
|
51
|
+
if (value === "lmstudio" || value === "openai" || value === "mistral") return value;
|
|
52
|
+
if (value) throw new Error("SURVEY_ASSISTANT_PROVIDER must be one of: openai, mistral, lmstudio, azure-openai.");
|
|
51
53
|
return fallback;
|
|
52
54
|
};
|
|
53
55
|
const parseAzureManagement = (env) => {
|
|
@@ -73,12 +75,15 @@ const getReadinessError = ({ azure, env, modelWasConfigured, provider, requireSt
|
|
|
73
75
|
}
|
|
74
76
|
return null;
|
|
75
77
|
};
|
|
76
|
-
const parseSurveyAssistantEnvironment = (env, { defaultMistralModel = "mistral-medium-latest", defaultOpenAIModel = "gpt-5.4-nano", defaultProvider = "openai", requireExperimentalIdentityOptIn = false, requireStorage = true } = {}) => {
|
|
78
|
+
const parseSurveyAssistantEnvironment = (env, { defaultLmStudioModel, defaultMistralModel = "mistral-medium-latest", defaultOpenAIModel = "gpt-5.4-nano", defaultProvider = "openai", requireExperimentalIdentityOptIn = false, requireStorage = true } = {}) => {
|
|
77
79
|
const provider = parseProvider(env, defaultProvider);
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const
|
|
80
|
+
const modelIdOptions = { allowNestedId: provider === "lmstudio" };
|
|
81
|
+
const configuredModelId = getOptionalSameProviderModelId(env, "SURVEY_ASSISTANT_MODEL", modelIdOptions);
|
|
82
|
+
if (provider === "lmstudio" && !configuredModelId && !defaultLmStudioModel) throw new Error("SURVEY_ASSISTANT_MODEL must be configured when SURVEY_ASSISTANT_PROVIDER is lmstudio.");
|
|
83
|
+
const defaultModelId = configuredModelId ?? getSameProviderModelId(provider === "lmstudio" ? defaultLmStudioModel : provider === "mistral" ? defaultMistralModel : defaultOpenAIModel, provider === "lmstudio" ? "defaultLmStudioModel" : provider === "mistral" ? "defaultMistralModel" : "defaultOpenAIModel", modelIdOptions);
|
|
84
|
+
const configuredModelIds = getCommaSeparatedValues(env, "SURVEY_ASSISTANT_MODELS").map((modelId) => getSameProviderModelId(modelId, "SURVEY_ASSISTANT_MODELS", modelIdOptions));
|
|
85
|
+
const modelIds = [...new Set(configuredModelIds.includes(defaultModelId) ? configuredModelIds : [defaultModelId, ...configuredModelIds])];
|
|
86
|
+
const taskModelId = getOptionalSameProviderModelId(env, "SURVEY_ASSISTANT_TASK_MODEL", modelIdOptions);
|
|
82
87
|
const sendReasoning = getBoolean(env, "SURVEY_ASSISTANT_SEND_REASONING", true);
|
|
83
88
|
const providerOptionsKey = resolveSurveyAssistantProviderOptionsKey(provider);
|
|
84
89
|
const reasoningEffort = getValue(env, `SURVEY_ASSISTANT_${providerOptionsKey.toUpperCase()}_REASONING_EFFORT`) ?? getValue(env, "SURVEY_ASSISTANT_REASONING_EFFORT") ?? (provider === "openai" || provider === "azure-openai" ? "low" : "none");
|
|
@@ -101,9 +106,9 @@ const parseSurveyAssistantEnvironment = (env, { defaultMistralModel = "mistral-m
|
|
|
101
106
|
"off",
|
|
102
107
|
"none"
|
|
103
108
|
]);
|
|
104
|
-
const reasoningSummary = reasoningSummaryValue === "off" || reasoningSummaryValue === "none" ? void 0 : reasoningSummaryValue ?? "
|
|
109
|
+
const reasoningSummary = reasoningSummaryValue === "off" || reasoningSummaryValue === "none" ? void 0 : reasoningSummaryValue ?? "detailed";
|
|
105
110
|
const resolvedReasoningEffort = reasoningEffort === "default" || reasoningEffort === "provider-default" ? void 0 : reasoningEffort;
|
|
106
|
-
const providerOptions = { [providerOptionsKey]: {
|
|
111
|
+
const providerOptions = provider === "lmstudio" ? void 0 : { [providerOptionsKey]: {
|
|
107
112
|
parallelToolCalls: false,
|
|
108
113
|
...resolvedReasoningEffort ? { reasoningEffort: resolvedReasoningEffort } : {},
|
|
109
114
|
...provider === "openai" || provider === "azure-openai" ? {
|
|
@@ -121,7 +126,11 @@ const parseSurveyAssistantEnvironment = (env, { defaultMistralModel = "mistral-m
|
|
|
121
126
|
discoverModels: getBoolean(env, "SURVEY_ASSISTANT_AZURE_DISCOVER_MODELS", false),
|
|
122
127
|
management: parseAzureManagement(env)
|
|
123
128
|
} : void 0;
|
|
124
|
-
const
|
|
129
|
+
const lmstudio = provider === "lmstudio" ? {
|
|
130
|
+
baseUrl: getValue(env, "SURVEY_ASSISTANT_LMSTUDIO_BASE_URL") ?? "http://127.0.0.1:1234/v1",
|
|
131
|
+
apiKey: getValue(env, "SURVEY_ASSISTANT_LMSTUDIO_API_KEY")
|
|
132
|
+
} : void 0;
|
|
133
|
+
const memoryModelId = getOptionalSameProviderModelId(env, "SURVEY_ASSISTANT_MEMORY_MODEL", modelIdOptions) ?? defaultModelId;
|
|
125
134
|
const memoryModel = `${provider}/${memoryModelId}`;
|
|
126
135
|
const observationalMemory = getBoolean(env, "SURVEY_ASSISTANT_MEMORY_ENABLED", true) ? createSurveyAssistantObservationalMemoryOptions({
|
|
127
136
|
model: memoryModel,
|
|
@@ -144,6 +153,7 @@ const parseSurveyAssistantEnvironment = (env, { defaultMistralModel = "mistral-m
|
|
|
144
153
|
modelIds,
|
|
145
154
|
modelCatalogTtlMs: getPositiveNumber(env, "SURVEY_ASSISTANT_MODEL_CATALOG_TTL_MS", DEFAULT_CATALOG_TTL_MS),
|
|
146
155
|
azure,
|
|
156
|
+
lmstudio,
|
|
147
157
|
enabled,
|
|
148
158
|
readinessError: getReadinessError({
|
|
149
159
|
azure,
|
|
@@ -160,6 +170,8 @@ const parseSurveyAssistantEnvironment = (env, { defaultMistralModel = "mistral-m
|
|
|
160
170
|
maxTotalAttachmentBytes: getPositiveNumber(env, "SURVEY_ASSISTANT_MAX_TOTAL_ATTACHMENT_BYTES", SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxTotalAttachmentBytes)
|
|
161
171
|
},
|
|
162
172
|
execution: {
|
|
173
|
+
firstResponseTimeoutMs: getPositiveNumber(env, "SURVEY_ASSISTANT_FIRST_RESPONSE_TIMEOUT_MS", DEFAULT_FIRST_RESPONSE_TIMEOUT_MS),
|
|
174
|
+
idleTimeoutMs: getPositiveNumber(env, "SURVEY_ASSISTANT_IDLE_TIMEOUT_MS", DEFAULT_IDLE_TIMEOUT_MS),
|
|
163
175
|
maxConcurrentRequests: getPositiveNumber(env, "SURVEY_ASSISTANT_MAX_CONCURRENT_REQUESTS", 4),
|
|
164
176
|
maxDurationMs: getPositiveNumber(env, "SURVEY_ASSISTANT_MAX_DURATION_MS", DEFAULT_MAX_DURATION_MS),
|
|
165
177
|
maxSteps: Math.min(configuredMaxSteps, HARD_MAX_STEPS),
|
|
@@ -174,6 +186,15 @@ const parseSurveyAssistantEnvironment = (env, { defaultMistralModel = "mistral-m
|
|
|
174
186
|
//#region src/server/runtime.ts
|
|
175
187
|
const createSurveyAssistantModelRouter = (config) => {
|
|
176
188
|
const toProviderModel = (modelId, configName) => {
|
|
189
|
+
if (config.provider === "lmstudio") {
|
|
190
|
+
if (!config.lmstudio) throw new Error("LM Studio configuration is missing for the lmstudio provider.");
|
|
191
|
+
return {
|
|
192
|
+
providerId: "lmstudio",
|
|
193
|
+
modelId,
|
|
194
|
+
url: config.lmstudio.baseUrl,
|
|
195
|
+
...config.lmstudio.apiKey ? { apiKey: config.lmstudio.apiKey } : {}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
177
198
|
if (modelId.includes("/")) throw new Error(`${configName} must be a model or deployment id without a provider prefix. All survey assistant models use the configured provider.`);
|
|
178
199
|
return `${config.provider}/${modelId}`;
|
|
179
200
|
};
|
|
@@ -186,7 +207,8 @@ const createSurveyAssistantModelRouter = (config) => {
|
|
|
186
207
|
const taskModel = config.taskModelId ? toProviderModel(config.taskModelId, "taskModelId") : void 0;
|
|
187
208
|
const memoryModel = toProviderModel(config.memoryModelId, "memoryModelId");
|
|
188
209
|
if (config.observationalMemory !== false) {
|
|
189
|
-
|
|
210
|
+
const configuredMemoryModel = `${config.provider}/${config.memoryModelId}`;
|
|
211
|
+
if (typeof config.observationalMemory.model !== "string" || config.observationalMemory.model !== configuredMemoryModel || config.observationalMemory.observation?.model !== void 0 || config.observationalMemory.reflection?.model !== void 0) throw new Error("The standard runtime requires observationalMemory to use memoryModelId for both observation and reflection. Use the low-level Agent factory for custom memory model routing.");
|
|
190
212
|
}
|
|
191
213
|
const deploymentIds = [...new Set([
|
|
192
214
|
...chatModelIds,
|
|
@@ -248,11 +270,15 @@ const createSurveyAssistantRuntimeComponents = (config) => {
|
|
|
248
270
|
const modelRouter = createSurveyAssistantModelRouter(config);
|
|
249
271
|
const chatModel = ({ requestContext }) => requestContext.get("modelSelection")?.model ?? modelRouter.defaultModel;
|
|
250
272
|
const taskModel = modelRouter.taskModel ?? chatModel;
|
|
273
|
+
const observationalMemory = config.provider === "lmstudio" && config.observationalMemory !== false ? {
|
|
274
|
+
...config.observationalMemory,
|
|
275
|
+
model: modelRouter.memoryModel
|
|
276
|
+
} : config.observationalMemory;
|
|
251
277
|
return {
|
|
252
278
|
agents: {
|
|
253
279
|
[SURVEY_ASSISTANT_AGENT_ID]: createSurveyAssistantAgent({
|
|
254
280
|
model: chatModel,
|
|
255
|
-
observationalMemory
|
|
281
|
+
observationalMemory
|
|
256
282
|
}),
|
|
257
283
|
[SURVEY_ASSISTANT_TASK_AGENT_ID]: createSurveyAssistantTaskAgent({ model: taskModel })
|
|
258
284
|
},
|
|
@@ -270,8 +296,10 @@ const createSurveyAssistantRuntimeHandlers = ({ authorize, chat = {}, config, ma
|
|
|
270
296
|
agentId: SURVEY_ASSISTANT_AGENT_ID,
|
|
271
297
|
activeTools: chat.activeTools ?? (config.observationalMemory === false ? SURVEY_ASSISTANT_TOOL_IDS : [...SURVEY_ASSISTANT_TOOL_IDS, "recall"]),
|
|
272
298
|
authorize: authorize.chat,
|
|
299
|
+
firstResponseTimeoutMs: chat.firstResponseTimeoutMs ?? config.execution.firstResponseTimeoutMs,
|
|
273
300
|
getReadinessError,
|
|
274
301
|
isEnabled,
|
|
302
|
+
idleTimeoutMs: chat.idleTimeoutMs ?? config.execution.idleTimeoutMs,
|
|
275
303
|
maxConcurrentRequests: chat.maxConcurrentRequests ?? config.execution.maxConcurrentRequests,
|
|
276
304
|
maxDurationMs: chat.maxDurationMs ?? config.execution.maxDurationMs,
|
|
277
305
|
maxSteps: chat.maxSteps ?? config.execution.maxSteps,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-runtime.mjs","names":[],"sources":["../src/server/runtime-config.ts","../src/server/runtime.ts"],"sourcesContent":["import type { AgentExecutionOptions } from \"@mastra/core/agent\";\nimport type { AzureOpenAIGatewayConfig } from \"@mastra/core/llm\";\nimport {\n createSurveyAssistantObservationalMemoryOptions,\n SURVEY_ASSISTANT_OBSERVATIONAL_MEMORY_DEFAULTS,\n type SurveyAssistantObservationalMemoryOptions,\n} from \"./agent\";\nimport {\n SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS,\n type SurveyAssistantRequestLimits,\n} from \"./request-guardrails\";\n\nexport type SurveyAssistantProvider = \"azure-openai\" | \"mistral\" | \"openai\";\nexport type SurveyAssistantProviderOptionsKey = \"azure\" | \"mistral\" | \"openai\";\n\nexport interface SurveyAssistantAzureConfig {\n apiKey?: string;\n apiVersion: string;\n discoverModels: boolean;\n management?: AzureOpenAIGatewayConfig[\"management\"];\n resourceName?: string;\n}\n\nexport interface SurveyAssistantExecutionConfig {\n maxConcurrentRequests: number;\n maxDurationMs: number;\n maxSteps: number;\n providerOptions?: AgentExecutionOptions[\"providerOptions\"];\n sendReasoning: boolean;\n}\n\nexport interface SurveyAssistantRuntimeConfig {\n azure?: SurveyAssistantAzureConfig;\n /** Default chat model and fallback for chat requests without a selection. */\n defaultModelId: string;\n enabled: boolean;\n /** Fixed same-provider model shared by memory observation and reflection. */\n memoryModelId: string;\n modelCatalogTtlMs: number;\n modelIds: string[];\n observationalMemory: SurveyAssistantObservationalMemoryOptions | false;\n provider: SurveyAssistantProvider;\n requestLimits: Pick<\n SurveyAssistantRequestLimits,\n | \"maxAttachmentBytes\"\n | \"maxAttachments\"\n | \"maxRequestBytes\"\n | \"maxTextPartChars\"\n | \"maxTotalAttachmentBytes\"\n >;\n readinessError: string | null;\n /**\n * Fixed model for one-shot tasks. When omitted, tasks follow the\n * server-authorized chat model selection.\n */\n taskModelId?: string;\n execution: SurveyAssistantExecutionConfig;\n}\n\nexport interface ParseSurveyAssistantEnvironmentOptions {\n defaultMistralModel?: string;\n defaultOpenAIModel?: string;\n defaultProvider?: SurveyAssistantProvider;\n requireExperimentalIdentityOptIn?: boolean;\n requireStorage?: boolean;\n}\n\ntype Environment = Record<string, string | undefined>;\n\nconst DEFAULT_MAX_STEPS = 48;\nconst HARD_MAX_STEPS = 64;\nconst DEFAULT_MAX_DURATION_MS = 3 * 60 * 1_000;\nconst DEFAULT_CATALOG_TTL_MS = 5 * 60 * 1_000;\n\nconst getValue = (env: Environment, name: string) => {\n const value = env[name]?.trim();\n return value || undefined;\n};\n\nconst getBoolean = (env: Environment, name: string, fallback: boolean) => {\n const value = getValue(env, name)?.toLowerCase();\n if (value === \"true\") return true;\n if (value === \"false\") return false;\n if (value !== undefined) {\n throw new Error(`${name} must be \"true\" or \"false\".`);\n }\n return fallback;\n};\n\nconst getPositiveNumber = (env: Environment, name: string, fallback: number) => {\n const configured = getValue(env, name);\n if (configured === undefined) return fallback;\n const value = Number(configured);\n if (!Number.isSafeInteger(value) || value <= 0) {\n throw new Error(`${name} must be a positive integer.`);\n }\n return value;\n};\n\nconst getEnum = <TValue extends string>(\n env: Environment,\n name: string,\n values: readonly TValue[],\n) => {\n const value = getValue(env, name);\n if (!value) return undefined;\n if (!(values as readonly string[]).includes(value)) {\n throw new Error(`${name} must be one of: ${values.join(\", \")}.`);\n }\n return value as TValue;\n};\n\nconst getCommaSeparatedValues = (env: Environment, name: string) => [\n ...new Set(\n (getValue(env, name) ?? \"\")\n .split(\",\")\n .map((value) => value.trim())\n .filter(Boolean),\n ),\n];\n\nconst getSameProviderModelId = (value: string, name: string) => {\n if (value.includes(\"/\")) {\n throw new Error(\n `${name} must be a model or deployment id without a provider prefix. ` +\n \"All survey assistant models use SURVEY_ASSISTANT_PROVIDER.\",\n );\n }\n return value;\n};\n\nconst getOptionalSameProviderModelId = (env: Environment, name: string) => {\n const value = getValue(env, name);\n return value ? getSameProviderModelId(value, name) : undefined;\n};\n\nexport const resolveSurveyAssistantProviderOptionsKey = (\n provider: SurveyAssistantProvider,\n): SurveyAssistantProviderOptionsKey => (provider === \"azure-openai\" ? \"azure\" : provider);\n\nconst parseProvider = (\n env: Environment,\n fallback: SurveyAssistantProvider,\n): SurveyAssistantProvider => {\n const value = getValue(env, \"SURVEY_ASSISTANT_PROVIDER\")?.toLowerCase();\n if (value === \"azure\" || value === \"azure-openai\") return \"azure-openai\";\n if (value === \"openai\" || value === \"mistral\") return value;\n if (value) {\n throw new Error(\"SURVEY_ASSISTANT_PROVIDER must be one of: openai, mistral, azure-openai.\");\n }\n return fallback;\n};\n\nconst parseAzureManagement = (\n env: Environment,\n): AzureOpenAIGatewayConfig[\"management\"] | undefined => {\n if (!getBoolean(env, \"SURVEY_ASSISTANT_AZURE_DISCOVER_MODELS\", false)) return undefined;\n const management = {\n tenantId: getValue(env, \"AZURE_TENANT_ID\"),\n clientId: getValue(env, \"AZURE_CLIENT_ID\"),\n clientSecret: getValue(env, \"AZURE_CLIENT_SECRET\"),\n subscriptionId: getValue(env, \"AZURE_SUBSCRIPTION_ID\"),\n resourceGroup: getValue(env, \"AZURE_RESOURCE_GROUP\"),\n };\n return Object.values(management).every(Boolean)\n ? (management as AzureOpenAIGatewayConfig[\"management\"])\n : undefined;\n};\n\nconst getReadinessError = ({\n azure,\n env,\n modelWasConfigured,\n provider,\n requireStorage,\n}: {\n azure?: SurveyAssistantAzureConfig;\n env: Environment;\n modelWasConfigured: boolean;\n provider: SurveyAssistantProvider;\n requireStorage: boolean;\n}) => {\n if (\n requireStorage &&\n !getValue(env, \"SURVEY_ASSISTANT_DATABASE_URL\") &&\n !getValue(env, \"DATABASE_URL\")\n ) {\n return \"Survey assistant storage is not configured.\";\n }\n if (provider === \"openai\" && !getValue(env, \"OPENAI_API_KEY\")) {\n return \"The OpenAI API key is not configured for the survey assistant.\";\n }\n if (provider === \"mistral\" && !getValue(env, \"MISTRAL_API_KEY\")) {\n return \"The Mistral API key is not configured for the survey assistant.\";\n }\n if (provider === \"azure-openai\") {\n if (!azure?.resourceName) {\n return \"The Azure OpenAI resource name is not configured for the survey assistant.\";\n }\n if (!azure.apiKey) {\n return \"The Azure OpenAI API key is not configured for the survey assistant.\";\n }\n if (!modelWasConfigured) {\n return \"The Azure OpenAI deployment name is not configured for the survey assistant.\";\n }\n if (azure.discoverModels && !azure.management) {\n return \"Azure deployment discovery requires complete tenant, client, subscription, and resource-group settings.\";\n }\n }\n return null;\n};\n\nexport const parseSurveyAssistantEnvironment = (\n env: Environment,\n {\n defaultMistralModel = \"mistral-medium-latest\",\n defaultOpenAIModel = \"gpt-5.4-nano\",\n defaultProvider = \"openai\",\n requireExperimentalIdentityOptIn = false,\n requireStorage = true,\n }: ParseSurveyAssistantEnvironmentOptions = {},\n): SurveyAssistantRuntimeConfig => {\n const provider = parseProvider(env, defaultProvider);\n const configuredModelId = getOptionalSameProviderModelId(env, \"SURVEY_ASSISTANT_MODEL\");\n const defaultModelId =\n configuredModelId ??\n getSameProviderModelId(\n provider === \"mistral\" ? defaultMistralModel : defaultOpenAIModel,\n provider === \"mistral\" ? \"defaultMistralModel\" : \"defaultOpenAIModel\",\n );\n const modelIds = [\n ...new Set([\n defaultModelId,\n ...getCommaSeparatedValues(env, \"SURVEY_ASSISTANT_MODELS\").map((modelId) =>\n getSameProviderModelId(modelId, \"SURVEY_ASSISTANT_MODELS\"),\n ),\n ]),\n ];\n const taskModelId = getOptionalSameProviderModelId(env, \"SURVEY_ASSISTANT_TASK_MODEL\");\n const sendReasoning = getBoolean(env, \"SURVEY_ASSISTANT_SEND_REASONING\", true);\n const providerOptionsKey = resolveSurveyAssistantProviderOptionsKey(provider);\n const providerReasoningEffort = getValue(\n env,\n `SURVEY_ASSISTANT_${providerOptionsKey.toUpperCase()}_REASONING_EFFORT`,\n );\n const reasoningEffort =\n providerReasoningEffort ??\n getValue(env, \"SURVEY_ASSISTANT_REASONING_EFFORT\") ??\n (provider === \"openai\" || provider === \"azure-openai\" ? \"low\" : \"none\");\n const promptCacheRetention = getEnum(\n env,\n provider === \"azure-openai\"\n ? \"SURVEY_ASSISTANT_AZURE_PROMPT_CACHE_RETENTION\"\n : \"SURVEY_ASSISTANT_PROMPT_CACHE_RETENTION\",\n [\"in_memory\", \"24h\"] as const,\n );\n const serviceTier = getEnum(env, \"SURVEY_ASSISTANT_OPENAI_SERVICE_TIER\", [\n \"auto\",\n \"flex\",\n \"priority\",\n \"default\",\n ] as const);\n const textVerbosity = getEnum(env, \"SURVEY_ASSISTANT_OPENAI_TEXT_VERBOSITY\", [\n \"low\",\n \"medium\",\n \"high\",\n ] as const);\n const reasoningSummaryValue = getEnum(env, \"SURVEY_ASSISTANT_OPENAI_REASONING_SUMMARY\", [\n \"auto\",\n \"concise\",\n \"detailed\",\n \"off\",\n \"none\",\n ] as const);\n const reasoningSummary =\n reasoningSummaryValue === \"off\" || reasoningSummaryValue === \"none\"\n ? undefined\n : (reasoningSummaryValue ?? \"auto\");\n const resolvedReasoningEffort =\n reasoningEffort === \"default\" || reasoningEffort === \"provider-default\"\n ? undefined\n : reasoningEffort;\n const providerOptions: AgentExecutionOptions[\"providerOptions\"] = {\n [providerOptionsKey]: {\n parallelToolCalls: false,\n ...(resolvedReasoningEffort ? { reasoningEffort: resolvedReasoningEffort } : {}),\n ...(provider === \"openai\" || provider === \"azure-openai\"\n ? {\n promptCacheKey:\n getValue(env, \"SURVEY_ASSISTANT_PROMPT_CACHE_KEY\") ?? \"survey-assistant-chat-v21\",\n ...(promptCacheRetention ? { promptCacheRetention } : {}),\n ...(sendReasoning && reasoningSummary ? { reasoningSummary } : {}),\n ...(provider === \"openai\" && serviceTier ? { serviceTier } : {}),\n ...(textVerbosity ? { textVerbosity } : {}),\n }\n : {}),\n },\n };\n const azure: SurveyAssistantAzureConfig | undefined =\n provider === \"azure-openai\"\n ? {\n resourceName: getValue(env, \"AZURE_RESOURCE_NAME\"),\n apiKey: getValue(env, \"AZURE_API_KEY\"),\n apiVersion: getValue(env, \"SURVEY_ASSISTANT_AZURE_API_VERSION\") ?? \"v1\",\n discoverModels: getBoolean(env, \"SURVEY_ASSISTANT_AZURE_DISCOVER_MODELS\", false),\n management: parseAzureManagement(env),\n }\n : undefined;\n const memoryModelId =\n getOptionalSameProviderModelId(env, \"SURVEY_ASSISTANT_MEMORY_MODEL\") ?? defaultModelId;\n const memoryModel = `${provider}/${memoryModelId}`;\n const observationalMemory = getBoolean(env, \"SURVEY_ASSISTANT_MEMORY_ENABLED\", true)\n ? createSurveyAssistantObservationalMemoryOptions({\n model: memoryModel,\n temporalMarkers: getBoolean(env, \"SURVEY_ASSISTANT_MEMORY_TEMPORAL_MARKERS\", false),\n observation: {\n messageTokens: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MEMORY_MESSAGE_TOKENS\",\n SURVEY_ASSISTANT_OBSERVATIONAL_MEMORY_DEFAULTS.messageTokens,\n ),\n bufferOnIdle: getBoolean(env, \"SURVEY_ASSISTANT_MEMORY_BUFFER_ON_IDLE\", false),\n observeAttachments: false,\n },\n reflection: {\n observationTokens: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MEMORY_OBSERVATION_TOKENS\",\n SURVEY_ASSISTANT_OBSERVATIONAL_MEMORY_DEFAULTS.observationTokens,\n ),\n },\n })\n : false;\n const configuredMaxSteps = getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MAX_STEPS\",\n DEFAULT_MAX_STEPS,\n );\n const enabledSetting = getValue(env, \"SURVEY_ASSISTANT_ENABLED\")?.toLowerCase();\n if (enabledSetting !== undefined && enabledSetting !== \"true\" && enabledSetting !== \"false\") {\n throw new Error('SURVEY_ASSISTANT_ENABLED must be \"true\" or \"false\".');\n }\n const enabled =\n enabledSetting === \"false\"\n ? false\n : enabledSetting === \"true\"\n ? !requireExperimentalIdentityOptIn ||\n env.NODE_ENV === \"development\" ||\n getBoolean(env, \"SURVEY_ASSISTANT_ALLOW_EXPERIMENTAL_IDENTITY\", false)\n : env.NODE_ENV === \"development\";\n\n return {\n provider,\n defaultModelId,\n memoryModelId,\n modelIds,\n modelCatalogTtlMs: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MODEL_CATALOG_TTL_MS\",\n DEFAULT_CATALOG_TTL_MS,\n ),\n azure,\n enabled,\n readinessError: getReadinessError({\n azure,\n env,\n modelWasConfigured: Boolean(configuredModelId),\n provider,\n requireStorage,\n }),\n requestLimits: {\n maxAttachmentBytes: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MAX_ATTACHMENT_BYTES\",\n SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxAttachmentBytes,\n ),\n maxAttachments: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MAX_ATTACHMENTS\",\n SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxAttachments,\n ),\n maxRequestBytes: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MAX_REQUEST_BYTES\",\n SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxRequestBytes,\n ),\n maxTextPartChars: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MAX_TEXT_PART_CHARS\",\n SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxTextPartChars,\n ),\n maxTotalAttachmentBytes: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MAX_TOTAL_ATTACHMENT_BYTES\",\n SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxTotalAttachmentBytes,\n ),\n },\n execution: {\n maxConcurrentRequests: getPositiveNumber(env, \"SURVEY_ASSISTANT_MAX_CONCURRENT_REQUESTS\", 4),\n maxDurationMs: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MAX_DURATION_MS\",\n DEFAULT_MAX_DURATION_MS,\n ),\n maxSteps: Math.min(configuredMaxSteps, HARD_MAX_STEPS),\n providerOptions,\n sendReasoning,\n },\n observationalMemory,\n taskModelId,\n };\n};\n","import type { AgentExecutionOptions } from \"@mastra/core/agent\";\nimport { AzureOpenAIGateway, type MastraModelGatewayInterface } from \"@mastra/core/llm\";\nimport type { Mastra } from \"@mastra/core/mastra\";\nimport type { RequestContext } from \"@mastra/core/request-context\";\nimport type { SurveyAssistantModelCatalog } from \"../protocol\";\nimport { createSurveyAssistantAgent, type CreateSurveyAssistantAgentOptions } from \"./agent\";\nimport { SURVEY_ASSISTANT_AGENT_ID, SURVEY_ASSISTANT_TASK_AGENT_ID } from \"./constants\";\nimport {\n createSurveyAssistantChatHandler,\n SurveyAssistantAuthorizationError,\n type SurveyAssistantAuthorize,\n type SurveyAssistantChatHandlerOptions,\n type SurveyAssistantResolveModel,\n} from \"./handler\";\nimport { createMastraMemoryThreadRepository } from \"./memory-thread-repository\";\nimport type { SurveyAssistantRequestContext } from \"./request-context\";\nimport type { SurveyAssistantCapabilitySet } from \"../engine\";\nimport type { SurveyAssistantRuntimeConfig } from \"./runtime-config\";\nimport {\n createSurveyAssistantTaskAgent,\n createSurveyAssistantTaskHandler,\n type CreateSurveyAssistantTaskHandlerOptions,\n type SurveyAssistantTaskModelResolutionInput,\n} from \"./tasks\";\nimport type { SurveyAssistantThreadDocumentRepository } from \"./thread-documents\";\nimport {\n createSurveyAssistantThreadHandlers,\n type CreateSurveyAssistantThreadHandlersOptions,\n} from \"./thread-handlers\";\nimport { SURVEY_ASSISTANT_TOOL_IDS } from \"./tools\";\n\nexport {\n parseSurveyAssistantEnvironment,\n resolveSurveyAssistantProviderOptionsKey,\n type ParseSurveyAssistantEnvironmentOptions,\n type SurveyAssistantAzureConfig,\n type SurveyAssistantExecutionConfig,\n type SurveyAssistantProvider,\n type SurveyAssistantProviderOptionsKey,\n type SurveyAssistantRuntimeConfig,\n} from \"./runtime-config\";\n\nexport interface SurveyAssistantModelRouter {\n defaultModel: string;\n gateways?: Record<string, MastraModelGatewayInterface>;\n getCatalog(options?: { refresh?: boolean }): Promise<SurveyAssistantModelCatalog>;\n memoryModel: string;\n providerName: string;\n providerOptions?: AgentExecutionOptions[\"providerOptions\"];\n resolveModel: SurveyAssistantResolveModel;\n resolveTaskModel(\n input: SurveyAssistantTaskModelResolutionInput,\n ): ReturnType<SurveyAssistantResolveModel>;\n taskModel?: string;\n}\n\nexport const createSurveyAssistantModelRouter = (\n config: SurveyAssistantRuntimeConfig,\n): SurveyAssistantModelRouter => {\n const toProviderModel = (modelId: string, configName: string) => {\n if (modelId.includes(\"/\")) {\n throw new Error(\n `${configName} must be a model or deployment id without a provider prefix. ` +\n \"All survey assistant models use the configured provider.\",\n );\n }\n return `${config.provider}/${modelId}`;\n };\n const defaultModel = toProviderModel(config.defaultModelId, \"defaultModelId\");\n const chatModelIds = config.modelIds.map((modelId) => {\n toProviderModel(modelId, \"modelIds\");\n return modelId;\n });\n if (!chatModelIds.includes(config.defaultModelId)) {\n throw new Error(\"modelIds must include defaultModelId.\");\n }\n const taskModel = config.taskModelId\n ? toProviderModel(config.taskModelId, \"taskModelId\")\n : undefined;\n const memoryModel = toProviderModel(config.memoryModelId, \"memoryModelId\");\n if (config.observationalMemory !== false) {\n if (\n typeof config.observationalMemory.model !== \"string\" ||\n config.observationalMemory.model !== memoryModel ||\n config.observationalMemory.observation?.model !== undefined ||\n config.observationalMemory.reflection?.model !== undefined\n ) {\n throw new Error(\n \"The standard runtime requires observationalMemory to use memoryModelId \" +\n \"for both observation and reflection. Use the low-level Agent factory \" +\n \"for custom memory model routing.\",\n );\n }\n }\n const deploymentIds = [\n ...new Set([\n ...chatModelIds,\n ...(config.taskModelId ? [config.taskModelId] : []),\n config.memoryModelId,\n ]),\n ];\n const azureGateway = config.azure\n ? new AzureOpenAIGateway({\n resourceName: config.azure.resourceName ?? \"\",\n apiKey: config.azure.apiKey,\n apiVersion: config.azure.apiVersion,\n useResponsesAPI: true,\n ...(config.azure.management\n ? { management: config.azure.management }\n : { deployments: deploymentIds }),\n })\n : undefined;\n let cachedCatalog: { expiresAt: number; value: SurveyAssistantModelCatalog } | undefined;\n\n const getCatalog = async ({ refresh = false }: { refresh?: boolean } = {}) => {\n if (!refresh && cachedCatalog && cachedCatalog.expiresAt > Date.now()) {\n return cachedCatalog.value;\n }\n let ids = chatModelIds;\n if (azureGateway && config.azure?.discoverModels) {\n try {\n const providers = await azureGateway.fetchProviders();\n ids = [...new Set([...chatModelIds, ...(providers[\"azure-openai\"]?.models ?? [])])];\n } catch {\n // Keep the explicit catalog available when Azure management discovery is temporarily down.\n }\n }\n const value = {\n defaultModelId: config.defaultModelId,\n models: ids.map((id) => ({ id, label: id })),\n } satisfies SurveyAssistantModelCatalog;\n cachedCatalog = { expiresAt: Date.now() + config.modelCatalogTtlMs, value };\n return value;\n };\n const resolveRequestedModel = async (requestedModelId?: string) => {\n const catalog = await getCatalog();\n const id = requestedModelId ?? catalog.defaultModelId;\n return catalog.models.some((model) => model.id === id)\n ? { id, model: toProviderModel(id, \"requestedModelId\") }\n : null;\n };\n\n return {\n defaultModel,\n gateways: azureGateway\n ? {\n // Mastra 1.47 narrows one method's environment type in the concrete class.\n \"azure-openai\": azureGateway as unknown as MastraModelGatewayInterface,\n }\n : undefined,\n getCatalog,\n memoryModel,\n providerName: config.provider,\n providerOptions: config.execution.providerOptions,\n resolveModel: async ({ requestedModelId }) => resolveRequestedModel(requestedModelId),\n resolveTaskModel: async ({ requestedModelId }) =>\n config.taskModelId\n ? { id: config.taskModelId, model: taskModel! }\n : resolveRequestedModel(requestedModelId),\n taskModel,\n };\n};\n\nexport interface SurveyAssistantRuntimeComponents {\n agents: Record<\n string,\n | ReturnType<typeof createSurveyAssistantAgent>\n | ReturnType<typeof createSurveyAssistantTaskAgent>\n >;\n gateways?: Record<string, MastraModelGatewayInterface>;\n modelRouter: SurveyAssistantModelRouter;\n}\n\nexport const createSurveyAssistantRuntimeComponents = (\n config: SurveyAssistantRuntimeConfig,\n): SurveyAssistantRuntimeComponents => {\n const modelRouter = createSurveyAssistantModelRouter(config);\n const chatModel: CreateSurveyAssistantAgentOptions[\"model\"] = ({\n requestContext,\n }: {\n requestContext: RequestContext<SurveyAssistantRequestContext>;\n }) => requestContext.get(\"modelSelection\")?.model ?? modelRouter.defaultModel;\n const taskModel = modelRouter.taskModel ?? chatModel;\n return {\n agents: {\n [SURVEY_ASSISTANT_AGENT_ID]: createSurveyAssistantAgent({\n model: chatModel,\n observationalMemory: config.observationalMemory,\n }),\n [SURVEY_ASSISTANT_TASK_AGENT_ID]: createSurveyAssistantTaskAgent({ model: taskModel }),\n },\n gateways: modelRouter.gateways,\n modelRouter,\n };\n};\n\ntype ChatHandlerOverrides = Partial<\n Omit<\n SurveyAssistantChatHandlerOptions,\n \"authorize\" | \"mastra\" | \"providerName\" | \"providerOptions\" | \"resolveModel\"\n >\n>;\ntype TaskHandlerOverrides = Partial<\n Omit<\n CreateSurveyAssistantTaskHandlerOptions,\n \"agent\" | \"authorize\" | \"providerOptions\" | \"resolveModel\"\n >\n>;\n\nexport interface CreateSurveyAssistantRuntimeHandlersOptions {\n authorize: {\n chat: SurveyAssistantAuthorize;\n model?: (request: Request) => unknown | Promise<unknown>;\n task: CreateSurveyAssistantTaskHandlerOptions[\"authorize\"];\n thread: CreateSurveyAssistantThreadHandlersOptions[\"authorize\"];\n };\n chat?: ChatHandlerOverrides;\n config: SurveyAssistantRuntimeConfig;\n mastra: Mastra | (() => Mastra | Promise<Mastra>);\n modelRouter: SurveyAssistantModelRouter;\n task?: TaskHandlerOverrides;\n threadDocuments?: SurveyAssistantThreadDocumentRepository;\n}\n\nexport type CreateConfiguredSurveyAssistantRuntimeHandlersOptions = Omit<\n CreateSurveyAssistantRuntimeHandlersOptions,\n \"config\" | \"modelRouter\"\n>;\n\nconst resolveMastra = async (mastra: Mastra | (() => Mastra | Promise<Mastra>)) =>\n typeof mastra === \"function\" ? mastra() : mastra;\n\nexport const createSurveyAssistantRuntimeHandlers = ({\n authorize,\n chat = {},\n config,\n mastra,\n modelRouter,\n task = {},\n threadDocuments,\n}: CreateSurveyAssistantRuntimeHandlersOptions) => {\n const isEnabled = chat.isEnabled ?? (() => config.enabled);\n const getReadinessError = chat.getReadinessError ?? (() => config.readinessError);\n const chatHandler = createSurveyAssistantChatHandler({\n ...chat,\n mastra,\n agentId: SURVEY_ASSISTANT_AGENT_ID,\n activeTools:\n chat.activeTools ??\n (config.observationalMemory === false\n ? SURVEY_ASSISTANT_TOOL_IDS\n : [...SURVEY_ASSISTANT_TOOL_IDS, \"recall\"]),\n authorize: authorize.chat,\n getReadinessError,\n isEnabled,\n maxConcurrentRequests: chat.maxConcurrentRequests ?? config.execution.maxConcurrentRequests,\n maxDurationMs: chat.maxDurationMs ?? config.execution.maxDurationMs,\n maxSteps: chat.maxSteps ?? config.execution.maxSteps,\n providerName: modelRouter.providerName,\n providerOptions: modelRouter.providerOptions,\n requestLimits: { ...config.requestLimits, ...chat.requestLimits },\n resolveModel: modelRouter.resolveModel,\n sendReasoning: chat.sendReasoning ?? config.execution.sendReasoning,\n threadDocuments,\n });\n const taskHandler = createSurveyAssistantTaskHandler({\n ...task,\n agent: async () => (await resolveMastra(mastra)).getAgent(SURVEY_ASSISTANT_TASK_AGENT_ID),\n authorize: authorize.task,\n getReadinessError: task.getReadinessError ?? getReadinessError,\n isEnabled: task.isEnabled ?? isEnabled,\n maxConcurrentRequests: task.maxConcurrentRequests ?? config.execution.maxConcurrentRequests,\n maxDurationMs: task.maxDurationMs ?? config.execution.maxDurationMs,\n providerOptions: modelRouter.providerOptions,\n resolveModel: modelRouter.resolveTaskModel,\n });\n const getMemory = async () => {\n const memory = await (\n await resolveMastra(mastra)\n )\n .getAgent(SURVEY_ASSISTANT_AGENT_ID)\n .getMemory();\n if (!memory) throw new Error(\"Survey assistant memory is not configured.\");\n return memory;\n };\n const threads = createSurveyAssistantThreadHandlers({\n authorize: async (request) => {\n if (!config.enabled) {\n throw new SurveyAssistantAuthorizationError(\"Survey assistant is disabled.\", 404);\n }\n return authorize.thread(request);\n },\n repository: createMastraMemoryThreadRepository({ getMemory, threadDocuments }),\n });\n const models = async (request: Request) => {\n if (!config.enabled) {\n return Response.json(\n { code: \"authorization_failed\", error: \"Survey assistant is disabled.\" },\n { status: 404 },\n );\n }\n try {\n if (authorize.model) {\n await authorize.model(request);\n } else {\n await authorize.task({ request });\n }\n return Response.json(await modelRouter.getCatalog());\n } catch (error) {\n const status =\n typeof error === \"object\" &&\n error !== null &&\n \"status\" in error &&\n typeof error.status === \"number\"\n ? error.status\n : 403;\n return Response.json(\n {\n code: \"authorization_failed\",\n error: \"The survey assistant request is not authorized.\",\n },\n { status },\n );\n }\n };\n\n return {\n chat: chatHandler,\n models,\n task: taskHandler,\n threads,\n };\n};\n\nexport interface SurveyAssistantRuntime extends SurveyAssistantRuntimeComponents {\n config: SurveyAssistantRuntimeConfig;\n createHandlers(\n options: CreateConfiguredSurveyAssistantRuntimeHandlersOptions,\n ): ReturnType<typeof createSurveyAssistantRuntimeHandlers>;\n}\n\nexport interface CreateSurveyAssistantRuntimeOptions {\n /** Trusted server-side capabilities for custom registry item types. */\n trustedCapabilities?: SurveyAssistantCapabilitySet;\n}\n\n/**\n * Creates the reusable assistant runtime without hiding Mastra from the host.\n * Register `agents` and `gateways` in the host's standard Mastra instance, then\n * call `createHandlers` with that instance and host authorization policy.\n */\nexport const createSurveyAssistantRuntime = (\n config: SurveyAssistantRuntimeConfig,\n runtimeOptions: CreateSurveyAssistantRuntimeOptions = {},\n): SurveyAssistantRuntime => {\n const components = createSurveyAssistantRuntimeComponents(config);\n return {\n ...components,\n config,\n createHandlers: (handlerOptions) =>\n createSurveyAssistantRuntimeHandlers({\n ...handlerOptions,\n chat: {\n ...handlerOptions.chat,\n trustedCapabilities:\n handlerOptions.chat?.trustedCapabilities ?? runtimeOptions.trustedCapabilities,\n },\n config,\n modelRouter: components.modelRouter,\n }),\n };\n};\n"],"mappings":";;;;;;;;AAqEA,MAAM,oBAAoB;AAC1B,MAAM,iBAAiB;AACvB,MAAM,0BAA0B,MAAS;AACzC,MAAM,yBAAyB,MAAS;AAExC,MAAM,YAAY,KAAkB,SAAiB;AAEnD,QADc,IAAI,OAAO,MAAM,IACf,KAAA;;AAGlB,MAAM,cAAc,KAAkB,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CACF,MAAM,YAAY,YAAY;EAC5B,MAAM,SAAS,OACb,MAAM,cAAc,OAAO,EAE1B,SAAS,0BAA0B,CACnC,WAAW;AACd,MAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,6CAA6C;AAC1E,SAAO;;CAET,MAAM,UAAU,oCAAoC;EAClD,WAAW,OAAO,YAAY;AAC5B,OAAI,CAAC,OAAO,QACV,OAAM,IAAI,kCAAkC,iCAAiC,IAAI;AAEnF,UAAO,UAAU,OAAO,QAAQ;;EAElC,YAAY,mCAAmC;GAAE;GAAW;GAAiB,CAAC;EAC/E,CAAC;CACF,MAAM,SAAS,OAAO,YAAqB;AACzC,MAAI,CAAC,OAAO,QACV,QAAO,SAAS,KACd;GAAE,MAAM;GAAwB,OAAO;GAAiC,EACxE,EAAE,QAAQ,KAAK,CAChB;AAEH,MAAI;AACF,OAAI,UAAU,MACZ,OAAM,UAAU,MAAM,QAAQ;OAE9B,OAAM,UAAU,KAAK,EAAE,SAAS,CAAC;AAEnC,UAAO,SAAS,KAAK,MAAM,YAAY,YAAY,CAAC;WAC7C,OAAO;GACd,MAAM,SACJ,OAAO,UAAU,YACjB,UAAU,QACV,YAAY,SACZ,OAAO,MAAM,WAAW,WACpB,MAAM,SACN;AACN,UAAO,SAAS,KACd;IACE,MAAM;IACN,OAAO;IACR,EACD,EAAE,QAAQ,CACX;;;AAIL,QAAO;EACL,MAAM;EACN;EACA,MAAM;EACN;EACD;;;;;;;AAoBH,MAAa,gCACX,QACA,iBAAsD,EAAE,KAC7B;CAC3B,MAAM,aAAa,uCAAuC,OAAO;AACjE,QAAO;EACL,GAAG;EACH;EACA,iBAAiB,mBACf,qCAAqC;GACnC,GAAG;GACH,MAAM;IACJ,GAAG,eAAe;IAClB,qBACE,eAAe,MAAM,uBAAuB,eAAe;IAC9D;GACD;GACA,aAAa,WAAW;GACzB,CAAC;EACL"}
|
|
1
|
+
{"version":3,"file":"server-runtime.mjs","names":[],"sources":["../src/server/runtime-config.ts","../src/server/runtime.ts"],"sourcesContent":["import type { AgentExecutionOptions } from \"@mastra/core/agent\";\nimport type { AzureOpenAIGatewayConfig } from \"@mastra/core/llm\";\nimport {\n createSurveyAssistantObservationalMemoryOptions,\n SURVEY_ASSISTANT_OBSERVATIONAL_MEMORY_DEFAULTS,\n type SurveyAssistantObservationalMemoryOptions,\n} from \"./agent\";\nimport {\n SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS,\n type SurveyAssistantRequestLimits,\n} from \"./request-guardrails\";\n\nexport type SurveyAssistantProvider = \"azure-openai\" | \"lmstudio\" | \"mistral\" | \"openai\";\nexport type SurveyAssistantProviderOptionsKey = \"azure\" | \"lmstudio\" | \"mistral\" | \"openai\";\n\nexport interface SurveyAssistantAzureConfig {\n apiKey?: string;\n apiVersion: string;\n discoverModels: boolean;\n management?: AzureOpenAIGatewayConfig[\"management\"];\n resourceName?: string;\n}\n\nexport interface SurveyAssistantLmStudioConfig {\n apiKey?: string;\n baseUrl: string;\n}\n\nexport interface SurveyAssistantExecutionConfig {\n firstResponseTimeoutMs: number;\n idleTimeoutMs: number;\n maxConcurrentRequests: number;\n /** Absolute execution ceiling. Active streams still stop when this duration is reached. */\n maxDurationMs: number;\n maxSteps: number;\n providerOptions?: AgentExecutionOptions[\"providerOptions\"];\n sendReasoning: boolean;\n}\n\nexport interface SurveyAssistantRuntimeConfig {\n azure?: SurveyAssistantAzureConfig;\n lmstudio?: SurveyAssistantLmStudioConfig;\n /** Default chat model and fallback for chat requests without a selection. */\n defaultModelId: string;\n enabled: boolean;\n /** Fixed same-provider model shared by memory observation and reflection. */\n memoryModelId: string;\n modelCatalogTtlMs: number;\n modelIds: string[];\n observationalMemory: SurveyAssistantObservationalMemoryOptions | false;\n provider: SurveyAssistantProvider;\n requestLimits: Pick<\n SurveyAssistantRequestLimits,\n | \"maxAttachmentBytes\"\n | \"maxAttachments\"\n | \"maxRequestBytes\"\n | \"maxTextPartChars\"\n | \"maxTotalAttachmentBytes\"\n >;\n readinessError: string | null;\n /**\n * Fixed model for one-shot tasks. When omitted, tasks follow the\n * server-authorized chat model selection.\n */\n taskModelId?: string;\n execution: SurveyAssistantExecutionConfig;\n}\n\nexport interface ParseSurveyAssistantEnvironmentOptions {\n defaultLmStudioModel?: string;\n defaultMistralModel?: string;\n defaultOpenAIModel?: string;\n defaultProvider?: SurveyAssistantProvider;\n requireExperimentalIdentityOptIn?: boolean;\n requireStorage?: boolean;\n}\n\ntype Environment = Record<string, string | undefined>;\n\nconst DEFAULT_MAX_STEPS = 48;\nconst HARD_MAX_STEPS = 64;\nconst DEFAULT_FIRST_RESPONSE_TIMEOUT_MS = 15 * 60 * 1_000;\nconst DEFAULT_IDLE_TIMEOUT_MS = 5 * 60 * 1_000;\nconst DEFAULT_MAX_DURATION_MS = 60 * 60 * 1_000;\nconst DEFAULT_CATALOG_TTL_MS = 5 * 60 * 1_000;\n\nconst getValue = (env: Environment, name: string) => {\n const value = env[name]?.trim();\n return value || undefined;\n};\n\nconst getBoolean = (env: Environment, name: string, fallback: boolean) => {\n const value = getValue(env, name)?.toLowerCase();\n if (value === \"true\") return true;\n if (value === \"false\") return false;\n if (value !== undefined) {\n throw new Error(`${name} must be \"true\" or \"false\".`);\n }\n return fallback;\n};\n\nconst getPositiveNumber = (env: Environment, name: string, fallback: number) => {\n const configured = getValue(env, name);\n if (configured === undefined) return fallback;\n const value = Number(configured);\n if (!Number.isSafeInteger(value) || value <= 0) {\n throw new Error(`${name} must be a positive integer.`);\n }\n return value;\n};\n\nconst getEnum = <TValue extends string>(\n env: Environment,\n name: string,\n values: readonly TValue[],\n) => {\n const value = getValue(env, name);\n if (!value) return undefined;\n if (!(values as readonly string[]).includes(value)) {\n throw new Error(`${name} must be one of: ${values.join(\", \")}.`);\n }\n return value as TValue;\n};\n\nconst getCommaSeparatedValues = (env: Environment, name: string) => [\n ...new Set(\n (getValue(env, name) ?? \"\")\n .split(\",\")\n .map((value) => value.trim())\n .filter(Boolean),\n ),\n];\n\nconst getSameProviderModelId = (\n value: string,\n name: string,\n { allowNestedId = false }: { allowNestedId?: boolean } = {},\n) => {\n if (!allowNestedId && value.includes(\"/\")) {\n throw new Error(\n `${name} must be a model or deployment id without a provider prefix. ` +\n \"All survey assistant models use SURVEY_ASSISTANT_PROVIDER.\",\n );\n }\n return value;\n};\n\nconst getOptionalSameProviderModelId = (\n env: Environment,\n name: string,\n options?: { allowNestedId?: boolean },\n) => {\n const value = getValue(env, name);\n return value ? getSameProviderModelId(value, name, options) : undefined;\n};\n\nexport const resolveSurveyAssistantProviderOptionsKey = (\n provider: SurveyAssistantProvider,\n): SurveyAssistantProviderOptionsKey => (provider === \"azure-openai\" ? \"azure\" : provider);\n\nconst parseProvider = (\n env: Environment,\n fallback: SurveyAssistantProvider,\n): SurveyAssistantProvider => {\n const value = getValue(env, \"SURVEY_ASSISTANT_PROVIDER\")?.toLowerCase();\n if (value === \"azure\" || value === \"azure-openai\") return \"azure-openai\";\n if (value === \"lmstudio\" || value === \"openai\" || value === \"mistral\") return value;\n if (value) {\n throw new Error(\n \"SURVEY_ASSISTANT_PROVIDER must be one of: openai, mistral, lmstudio, azure-openai.\",\n );\n }\n return fallback;\n};\n\nconst parseAzureManagement = (\n env: Environment,\n): AzureOpenAIGatewayConfig[\"management\"] | undefined => {\n if (!getBoolean(env, \"SURVEY_ASSISTANT_AZURE_DISCOVER_MODELS\", false)) return undefined;\n const management = {\n tenantId: getValue(env, \"AZURE_TENANT_ID\"),\n clientId: getValue(env, \"AZURE_CLIENT_ID\"),\n clientSecret: getValue(env, \"AZURE_CLIENT_SECRET\"),\n subscriptionId: getValue(env, \"AZURE_SUBSCRIPTION_ID\"),\n resourceGroup: getValue(env, \"AZURE_RESOURCE_GROUP\"),\n };\n return Object.values(management).every(Boolean)\n ? (management as AzureOpenAIGatewayConfig[\"management\"])\n : undefined;\n};\n\nconst getReadinessError = ({\n azure,\n env,\n modelWasConfigured,\n provider,\n requireStorage,\n}: {\n azure?: SurveyAssistantAzureConfig;\n env: Environment;\n modelWasConfigured: boolean;\n provider: SurveyAssistantProvider;\n requireStorage: boolean;\n}) => {\n if (\n requireStorage &&\n !getValue(env, \"SURVEY_ASSISTANT_DATABASE_URL\") &&\n !getValue(env, \"DATABASE_URL\")\n ) {\n return \"Survey assistant storage is not configured.\";\n }\n if (provider === \"openai\" && !getValue(env, \"OPENAI_API_KEY\")) {\n return \"The OpenAI API key is not configured for the survey assistant.\";\n }\n if (provider === \"mistral\" && !getValue(env, \"MISTRAL_API_KEY\")) {\n return \"The Mistral API key is not configured for the survey assistant.\";\n }\n if (provider === \"azure-openai\") {\n if (!azure?.resourceName) {\n return \"The Azure OpenAI resource name is not configured for the survey assistant.\";\n }\n if (!azure.apiKey) {\n return \"The Azure OpenAI API key is not configured for the survey assistant.\";\n }\n if (!modelWasConfigured) {\n return \"The Azure OpenAI deployment name is not configured for the survey assistant.\";\n }\n if (azure.discoverModels && !azure.management) {\n return \"Azure deployment discovery requires complete tenant, client, subscription, and resource-group settings.\";\n }\n }\n return null;\n};\n\nexport const parseSurveyAssistantEnvironment = (\n env: Environment,\n {\n defaultLmStudioModel,\n defaultMistralModel = \"mistral-medium-latest\",\n defaultOpenAIModel = \"gpt-5.4-nano\",\n defaultProvider = \"openai\",\n requireExperimentalIdentityOptIn = false,\n requireStorage = true,\n }: ParseSurveyAssistantEnvironmentOptions = {},\n): SurveyAssistantRuntimeConfig => {\n const provider = parseProvider(env, defaultProvider);\n const modelIdOptions = { allowNestedId: provider === \"lmstudio\" };\n const configuredModelId = getOptionalSameProviderModelId(\n env,\n \"SURVEY_ASSISTANT_MODEL\",\n modelIdOptions,\n );\n if (provider === \"lmstudio\" && !configuredModelId && !defaultLmStudioModel) {\n throw new Error(\n \"SURVEY_ASSISTANT_MODEL must be configured when SURVEY_ASSISTANT_PROVIDER is lmstudio.\",\n );\n }\n const defaultModelId =\n configuredModelId ??\n getSameProviderModelId(\n provider === \"lmstudio\"\n ? defaultLmStudioModel!\n : provider === \"mistral\"\n ? defaultMistralModel\n : defaultOpenAIModel,\n provider === \"lmstudio\"\n ? \"defaultLmStudioModel\"\n : provider === \"mistral\"\n ? \"defaultMistralModel\"\n : \"defaultOpenAIModel\",\n modelIdOptions,\n );\n const configuredModelIds = getCommaSeparatedValues(env, \"SURVEY_ASSISTANT_MODELS\").map(\n (modelId) => getSameProviderModelId(modelId, \"SURVEY_ASSISTANT_MODELS\", modelIdOptions),\n );\n const modelIds = [\n ...new Set(\n configuredModelIds.includes(defaultModelId)\n ? configuredModelIds\n : [defaultModelId, ...configuredModelIds],\n ),\n ];\n const taskModelId = getOptionalSameProviderModelId(\n env,\n \"SURVEY_ASSISTANT_TASK_MODEL\",\n modelIdOptions,\n );\n const sendReasoning = getBoolean(env, \"SURVEY_ASSISTANT_SEND_REASONING\", true);\n const providerOptionsKey = resolveSurveyAssistantProviderOptionsKey(provider);\n const providerReasoningEffort = getValue(\n env,\n `SURVEY_ASSISTANT_${providerOptionsKey.toUpperCase()}_REASONING_EFFORT`,\n );\n const reasoningEffort =\n providerReasoningEffort ??\n getValue(env, \"SURVEY_ASSISTANT_REASONING_EFFORT\") ??\n (provider === \"openai\" || provider === \"azure-openai\" ? \"low\" : \"none\");\n const promptCacheRetention = getEnum(\n env,\n provider === \"azure-openai\"\n ? \"SURVEY_ASSISTANT_AZURE_PROMPT_CACHE_RETENTION\"\n : \"SURVEY_ASSISTANT_PROMPT_CACHE_RETENTION\",\n [\"in_memory\", \"24h\"] as const,\n );\n const serviceTier = getEnum(env, \"SURVEY_ASSISTANT_OPENAI_SERVICE_TIER\", [\n \"auto\",\n \"flex\",\n \"priority\",\n \"default\",\n ] as const);\n const textVerbosity = getEnum(env, \"SURVEY_ASSISTANT_OPENAI_TEXT_VERBOSITY\", [\n \"low\",\n \"medium\",\n \"high\",\n ] as const);\n const reasoningSummaryValue = getEnum(env, \"SURVEY_ASSISTANT_OPENAI_REASONING_SUMMARY\", [\n \"auto\",\n \"concise\",\n \"detailed\",\n \"off\",\n \"none\",\n ] as const);\n const reasoningSummary =\n reasoningSummaryValue === \"off\" || reasoningSummaryValue === \"none\"\n ? undefined\n : (reasoningSummaryValue ?? \"detailed\");\n const resolvedReasoningEffort =\n reasoningEffort === \"default\" || reasoningEffort === \"provider-default\"\n ? undefined\n : reasoningEffort;\n const providerOptions: AgentExecutionOptions[\"providerOptions\"] =\n provider === \"lmstudio\"\n ? undefined\n : {\n [providerOptionsKey]: {\n parallelToolCalls: false,\n ...(resolvedReasoningEffort ? { reasoningEffort: resolvedReasoningEffort } : {}),\n ...(provider === \"openai\" || provider === \"azure-openai\"\n ? {\n promptCacheKey:\n getValue(env, \"SURVEY_ASSISTANT_PROMPT_CACHE_KEY\") ??\n \"survey-assistant-chat-v21\",\n ...(promptCacheRetention ? { promptCacheRetention } : {}),\n ...(sendReasoning && reasoningSummary ? { reasoningSummary } : {}),\n ...(provider === \"openai\" && serviceTier ? { serviceTier } : {}),\n ...(textVerbosity ? { textVerbosity } : {}),\n }\n : {}),\n },\n };\n const azure: SurveyAssistantAzureConfig | undefined =\n provider === \"azure-openai\"\n ? {\n resourceName: getValue(env, \"AZURE_RESOURCE_NAME\"),\n apiKey: getValue(env, \"AZURE_API_KEY\"),\n apiVersion: getValue(env, \"SURVEY_ASSISTANT_AZURE_API_VERSION\") ?? \"v1\",\n discoverModels: getBoolean(env, \"SURVEY_ASSISTANT_AZURE_DISCOVER_MODELS\", false),\n management: parseAzureManagement(env),\n }\n : undefined;\n const lmstudio: SurveyAssistantLmStudioConfig | undefined =\n provider === \"lmstudio\"\n ? {\n baseUrl:\n getValue(env, \"SURVEY_ASSISTANT_LMSTUDIO_BASE_URL\") ?? \"http://127.0.0.1:1234/v1\",\n apiKey: getValue(env, \"SURVEY_ASSISTANT_LMSTUDIO_API_KEY\"),\n }\n : undefined;\n const memoryModelId =\n getOptionalSameProviderModelId(env, \"SURVEY_ASSISTANT_MEMORY_MODEL\", modelIdOptions) ??\n defaultModelId;\n const memoryModel = `${provider}/${memoryModelId}`;\n const observationalMemory = getBoolean(env, \"SURVEY_ASSISTANT_MEMORY_ENABLED\", true)\n ? createSurveyAssistantObservationalMemoryOptions({\n model: memoryModel,\n temporalMarkers: getBoolean(env, \"SURVEY_ASSISTANT_MEMORY_TEMPORAL_MARKERS\", false),\n observation: {\n messageTokens: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MEMORY_MESSAGE_TOKENS\",\n SURVEY_ASSISTANT_OBSERVATIONAL_MEMORY_DEFAULTS.messageTokens,\n ),\n bufferOnIdle: getBoolean(env, \"SURVEY_ASSISTANT_MEMORY_BUFFER_ON_IDLE\", false),\n observeAttachments: false,\n },\n reflection: {\n observationTokens: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MEMORY_OBSERVATION_TOKENS\",\n SURVEY_ASSISTANT_OBSERVATIONAL_MEMORY_DEFAULTS.observationTokens,\n ),\n },\n })\n : false;\n const configuredMaxSteps = getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MAX_STEPS\",\n DEFAULT_MAX_STEPS,\n );\n const enabledSetting = getValue(env, \"SURVEY_ASSISTANT_ENABLED\")?.toLowerCase();\n if (enabledSetting !== undefined && enabledSetting !== \"true\" && enabledSetting !== \"false\") {\n throw new Error('SURVEY_ASSISTANT_ENABLED must be \"true\" or \"false\".');\n }\n const enabled =\n enabledSetting === \"false\"\n ? false\n : enabledSetting === \"true\"\n ? !requireExperimentalIdentityOptIn ||\n env.NODE_ENV === \"development\" ||\n getBoolean(env, \"SURVEY_ASSISTANT_ALLOW_EXPERIMENTAL_IDENTITY\", false)\n : env.NODE_ENV === \"development\";\n\n return {\n provider,\n defaultModelId,\n memoryModelId,\n modelIds,\n modelCatalogTtlMs: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MODEL_CATALOG_TTL_MS\",\n DEFAULT_CATALOG_TTL_MS,\n ),\n azure,\n lmstudio,\n enabled,\n readinessError: getReadinessError({\n azure,\n env,\n modelWasConfigured: Boolean(configuredModelId),\n provider,\n requireStorage,\n }),\n requestLimits: {\n maxAttachmentBytes: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MAX_ATTACHMENT_BYTES\",\n SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxAttachmentBytes,\n ),\n maxAttachments: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MAX_ATTACHMENTS\",\n SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxAttachments,\n ),\n maxRequestBytes: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MAX_REQUEST_BYTES\",\n SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxRequestBytes,\n ),\n maxTextPartChars: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MAX_TEXT_PART_CHARS\",\n SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxTextPartChars,\n ),\n maxTotalAttachmentBytes: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MAX_TOTAL_ATTACHMENT_BYTES\",\n SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxTotalAttachmentBytes,\n ),\n },\n execution: {\n firstResponseTimeoutMs: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_FIRST_RESPONSE_TIMEOUT_MS\",\n DEFAULT_FIRST_RESPONSE_TIMEOUT_MS,\n ),\n idleTimeoutMs: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_IDLE_TIMEOUT_MS\",\n DEFAULT_IDLE_TIMEOUT_MS,\n ),\n maxConcurrentRequests: getPositiveNumber(env, \"SURVEY_ASSISTANT_MAX_CONCURRENT_REQUESTS\", 4),\n maxDurationMs: getPositiveNumber(\n env,\n \"SURVEY_ASSISTANT_MAX_DURATION_MS\",\n DEFAULT_MAX_DURATION_MS,\n ),\n maxSteps: Math.min(configuredMaxSteps, HARD_MAX_STEPS),\n providerOptions,\n sendReasoning,\n },\n observationalMemory,\n taskModelId,\n };\n};\n","import type { AgentExecutionOptions } from \"@mastra/core/agent\";\nimport { AzureOpenAIGateway, type MastraModelGatewayInterface } from \"@mastra/core/llm\";\nimport type { Mastra } from \"@mastra/core/mastra\";\nimport type { RequestContext } from \"@mastra/core/request-context\";\nimport type { SurveyAssistantModelCatalog } from \"../protocol\";\nimport { createSurveyAssistantAgent, type CreateSurveyAssistantAgentOptions } from \"./agent\";\nimport { SURVEY_ASSISTANT_AGENT_ID, SURVEY_ASSISTANT_TASK_AGENT_ID } from \"./constants\";\nimport {\n createSurveyAssistantChatHandler,\n SurveyAssistantAuthorizationError,\n type SurveyAssistantAuthorize,\n type SurveyAssistantChatHandlerOptions,\n type SurveyAssistantResolveModel,\n} from \"./handler\";\nimport { createMastraMemoryThreadRepository } from \"./memory-thread-repository\";\nimport type {\n SurveyAssistantModelSelection,\n SurveyAssistantRequestContext,\n} from \"./request-context\";\nimport type { SurveyAssistantCapabilitySet } from \"../engine\";\nimport type { SurveyAssistantRuntimeConfig } from \"./runtime-config\";\nimport {\n createSurveyAssistantTaskAgent,\n createSurveyAssistantTaskHandler,\n type CreateSurveyAssistantTaskHandlerOptions,\n type SurveyAssistantTaskModelResolutionInput,\n} from \"./tasks\";\nimport type { SurveyAssistantThreadDocumentRepository } from \"./thread-documents\";\nimport {\n createSurveyAssistantThreadHandlers,\n type CreateSurveyAssistantThreadHandlersOptions,\n} from \"./thread-handlers\";\nimport { SURVEY_ASSISTANT_TOOL_IDS } from \"./tools\";\n\nexport {\n parseSurveyAssistantEnvironment,\n resolveSurveyAssistantProviderOptionsKey,\n type ParseSurveyAssistantEnvironmentOptions,\n type SurveyAssistantAzureConfig,\n type SurveyAssistantExecutionConfig,\n type SurveyAssistantLmStudioConfig,\n type SurveyAssistantProvider,\n type SurveyAssistantProviderOptionsKey,\n type SurveyAssistantRuntimeConfig,\n} from \"./runtime-config\";\n\nexport interface SurveyAssistantModelRouter {\n defaultModel: SurveyAssistantModelSelection[\"model\"];\n gateways?: Record<string, MastraModelGatewayInterface>;\n getCatalog(options?: { refresh?: boolean }): Promise<SurveyAssistantModelCatalog>;\n memoryModel: SurveyAssistantModelSelection[\"model\"];\n providerName: string;\n providerOptions?: AgentExecutionOptions[\"providerOptions\"];\n resolveModel: SurveyAssistantResolveModel;\n resolveTaskModel(\n input: SurveyAssistantTaskModelResolutionInput,\n ): ReturnType<SurveyAssistantResolveModel>;\n taskModel?: SurveyAssistantModelSelection[\"model\"];\n}\n\nexport const createSurveyAssistantModelRouter = (\n config: SurveyAssistantRuntimeConfig,\n): SurveyAssistantModelRouter => {\n const toProviderModel = (\n modelId: string,\n configName: string,\n ): SurveyAssistantModelSelection[\"model\"] => {\n if (config.provider === \"lmstudio\") {\n if (!config.lmstudio) {\n throw new Error(\"LM Studio configuration is missing for the lmstudio provider.\");\n }\n return {\n providerId: \"lmstudio\",\n modelId,\n url: config.lmstudio.baseUrl,\n ...(config.lmstudio.apiKey ? { apiKey: config.lmstudio.apiKey } : {}),\n };\n }\n if (modelId.includes(\"/\")) {\n throw new Error(\n `${configName} must be a model or deployment id without a provider prefix. ` +\n \"All survey assistant models use the configured provider.\",\n );\n }\n return `${config.provider}/${modelId}`;\n };\n const defaultModel = toProviderModel(config.defaultModelId, \"defaultModelId\");\n const chatModelIds = config.modelIds.map((modelId) => {\n toProviderModel(modelId, \"modelIds\");\n return modelId;\n });\n if (!chatModelIds.includes(config.defaultModelId)) {\n throw new Error(\"modelIds must include defaultModelId.\");\n }\n const taskModel = config.taskModelId\n ? toProviderModel(config.taskModelId, \"taskModelId\")\n : undefined;\n const memoryModel = toProviderModel(config.memoryModelId, \"memoryModelId\");\n if (config.observationalMemory !== false) {\n const configuredMemoryModel = `${config.provider}/${config.memoryModelId}`;\n if (\n typeof config.observationalMemory.model !== \"string\" ||\n config.observationalMemory.model !== configuredMemoryModel ||\n config.observationalMemory.observation?.model !== undefined ||\n config.observationalMemory.reflection?.model !== undefined\n ) {\n throw new Error(\n \"The standard runtime requires observationalMemory to use memoryModelId \" +\n \"for both observation and reflection. Use the low-level Agent factory \" +\n \"for custom memory model routing.\",\n );\n }\n }\n const deploymentIds = [\n ...new Set([\n ...chatModelIds,\n ...(config.taskModelId ? [config.taskModelId] : []),\n config.memoryModelId,\n ]),\n ];\n const azureGateway = config.azure\n ? new AzureOpenAIGateway({\n resourceName: config.azure.resourceName ?? \"\",\n apiKey: config.azure.apiKey,\n apiVersion: config.azure.apiVersion,\n useResponsesAPI: true,\n ...(config.azure.management\n ? { management: config.azure.management }\n : { deployments: deploymentIds }),\n })\n : undefined;\n let cachedCatalog: { expiresAt: number; value: SurveyAssistantModelCatalog } | undefined;\n\n const getCatalog = async ({ refresh = false }: { refresh?: boolean } = {}) => {\n if (!refresh && cachedCatalog && cachedCatalog.expiresAt > Date.now()) {\n return cachedCatalog.value;\n }\n let ids = chatModelIds;\n if (azureGateway && config.azure?.discoverModels) {\n try {\n const providers = await azureGateway.fetchProviders();\n ids = [...new Set([...chatModelIds, ...(providers[\"azure-openai\"]?.models ?? [])])];\n } catch {\n // Keep the explicit catalog available when Azure management discovery is temporarily down.\n }\n }\n const value = {\n defaultModelId: config.defaultModelId,\n models: ids.map((id) => ({ id, label: id })),\n } satisfies SurveyAssistantModelCatalog;\n cachedCatalog = { expiresAt: Date.now() + config.modelCatalogTtlMs, value };\n return value;\n };\n const resolveRequestedModel = async (requestedModelId?: string) => {\n const catalog = await getCatalog();\n const id = requestedModelId ?? catalog.defaultModelId;\n return catalog.models.some((model) => model.id === id)\n ? { id, model: toProviderModel(id, \"requestedModelId\") }\n : null;\n };\n\n return {\n defaultModel,\n gateways: azureGateway\n ? {\n // Mastra 1.47 narrows one method's environment type in the concrete class.\n \"azure-openai\": azureGateway as unknown as MastraModelGatewayInterface,\n }\n : undefined,\n getCatalog,\n memoryModel,\n providerName: config.provider,\n providerOptions: config.execution.providerOptions,\n resolveModel: async ({ requestedModelId }) => resolveRequestedModel(requestedModelId),\n resolveTaskModel: async ({ requestedModelId }) =>\n config.taskModelId\n ? { id: config.taskModelId, model: taskModel! }\n : resolveRequestedModel(requestedModelId),\n taskModel,\n };\n};\n\nexport interface SurveyAssistantRuntimeComponents {\n agents: Record<\n string,\n | ReturnType<typeof createSurveyAssistantAgent>\n | ReturnType<typeof createSurveyAssistantTaskAgent>\n >;\n gateways?: Record<string, MastraModelGatewayInterface>;\n modelRouter: SurveyAssistantModelRouter;\n}\n\nexport const createSurveyAssistantRuntimeComponents = (\n config: SurveyAssistantRuntimeConfig,\n): SurveyAssistantRuntimeComponents => {\n const modelRouter = createSurveyAssistantModelRouter(config);\n const chatModel: CreateSurveyAssistantAgentOptions[\"model\"] = ({\n requestContext,\n }: {\n requestContext: RequestContext<SurveyAssistantRequestContext>;\n }) => requestContext.get(\"modelSelection\")?.model ?? modelRouter.defaultModel;\n const taskModel = modelRouter.taskModel ?? chatModel;\n const observationalMemory =\n config.provider === \"lmstudio\" && config.observationalMemory !== false\n ? { ...config.observationalMemory, model: modelRouter.memoryModel }\n : config.observationalMemory;\n return {\n agents: {\n [SURVEY_ASSISTANT_AGENT_ID]: createSurveyAssistantAgent({\n model: chatModel,\n observationalMemory,\n }),\n [SURVEY_ASSISTANT_TASK_AGENT_ID]: createSurveyAssistantTaskAgent({ model: taskModel }),\n },\n gateways: modelRouter.gateways,\n modelRouter,\n };\n};\n\ntype ChatHandlerOverrides = Partial<\n Omit<\n SurveyAssistantChatHandlerOptions,\n \"authorize\" | \"mastra\" | \"providerName\" | \"providerOptions\" | \"resolveModel\"\n >\n>;\ntype TaskHandlerOverrides = Partial<\n Omit<\n CreateSurveyAssistantTaskHandlerOptions,\n \"agent\" | \"authorize\" | \"providerOptions\" | \"resolveModel\"\n >\n>;\n\nexport interface CreateSurveyAssistantRuntimeHandlersOptions {\n authorize: {\n chat: SurveyAssistantAuthorize;\n model?: (request: Request) => unknown | Promise<unknown>;\n task: CreateSurveyAssistantTaskHandlerOptions[\"authorize\"];\n thread: CreateSurveyAssistantThreadHandlersOptions[\"authorize\"];\n };\n chat?: ChatHandlerOverrides;\n config: SurveyAssistantRuntimeConfig;\n mastra: Mastra | (() => Mastra | Promise<Mastra>);\n modelRouter: SurveyAssistantModelRouter;\n task?: TaskHandlerOverrides;\n threadDocuments?: SurveyAssistantThreadDocumentRepository;\n}\n\nexport type CreateConfiguredSurveyAssistantRuntimeHandlersOptions = Omit<\n CreateSurveyAssistantRuntimeHandlersOptions,\n \"config\" | \"modelRouter\"\n>;\n\nconst resolveMastra = async (mastra: Mastra | (() => Mastra | Promise<Mastra>)) =>\n typeof mastra === \"function\" ? mastra() : mastra;\n\nexport const createSurveyAssistantRuntimeHandlers = ({\n authorize,\n chat = {},\n config,\n mastra,\n modelRouter,\n task = {},\n threadDocuments,\n}: CreateSurveyAssistantRuntimeHandlersOptions) => {\n const isEnabled = chat.isEnabled ?? (() => config.enabled);\n const getReadinessError = chat.getReadinessError ?? (() => config.readinessError);\n const chatHandler = createSurveyAssistantChatHandler({\n ...chat,\n mastra,\n agentId: SURVEY_ASSISTANT_AGENT_ID,\n activeTools:\n chat.activeTools ??\n (config.observationalMemory === false\n ? SURVEY_ASSISTANT_TOOL_IDS\n : [...SURVEY_ASSISTANT_TOOL_IDS, \"recall\"]),\n authorize: authorize.chat,\n firstResponseTimeoutMs: chat.firstResponseTimeoutMs ?? config.execution.firstResponseTimeoutMs,\n getReadinessError,\n isEnabled,\n idleTimeoutMs: chat.idleTimeoutMs ?? config.execution.idleTimeoutMs,\n maxConcurrentRequests: chat.maxConcurrentRequests ?? config.execution.maxConcurrentRequests,\n maxDurationMs: chat.maxDurationMs ?? config.execution.maxDurationMs,\n maxSteps: chat.maxSteps ?? config.execution.maxSteps,\n providerName: modelRouter.providerName,\n providerOptions: modelRouter.providerOptions,\n requestLimits: { ...config.requestLimits, ...chat.requestLimits },\n resolveModel: modelRouter.resolveModel,\n sendReasoning: chat.sendReasoning ?? config.execution.sendReasoning,\n threadDocuments,\n });\n const taskHandler = createSurveyAssistantTaskHandler({\n ...task,\n agent: async () => (await resolveMastra(mastra)).getAgent(SURVEY_ASSISTANT_TASK_AGENT_ID),\n authorize: authorize.task,\n getReadinessError: task.getReadinessError ?? getReadinessError,\n isEnabled: task.isEnabled ?? isEnabled,\n maxConcurrentRequests: task.maxConcurrentRequests ?? config.execution.maxConcurrentRequests,\n maxDurationMs: task.maxDurationMs ?? config.execution.maxDurationMs,\n providerOptions: modelRouter.providerOptions,\n resolveModel: modelRouter.resolveTaskModel,\n });\n const getMemory = async () => {\n const memory = await (\n await resolveMastra(mastra)\n )\n .getAgent(SURVEY_ASSISTANT_AGENT_ID)\n .getMemory();\n if (!memory) throw new Error(\"Survey assistant memory is not configured.\");\n return memory;\n };\n const threads = createSurveyAssistantThreadHandlers({\n authorize: async (request) => {\n if (!config.enabled) {\n throw new SurveyAssistantAuthorizationError(\"Survey assistant is disabled.\", 404);\n }\n return authorize.thread(request);\n },\n repository: createMastraMemoryThreadRepository({ getMemory, threadDocuments }),\n });\n const models = async (request: Request) => {\n if (!config.enabled) {\n return Response.json(\n { code: \"authorization_failed\", error: \"Survey assistant is disabled.\" },\n { status: 404 },\n );\n }\n try {\n if (authorize.model) {\n await authorize.model(request);\n } else {\n await authorize.task({ request });\n }\n return Response.json(await modelRouter.getCatalog());\n } catch (error) {\n const status =\n typeof error === \"object\" &&\n error !== null &&\n \"status\" in error &&\n typeof error.status === \"number\"\n ? error.status\n : 403;\n return Response.json(\n {\n code: \"authorization_failed\",\n error: \"The survey assistant request is not authorized.\",\n },\n { status },\n );\n }\n };\n\n return {\n chat: chatHandler,\n models,\n task: taskHandler,\n threads,\n };\n};\n\nexport interface SurveyAssistantRuntime extends SurveyAssistantRuntimeComponents {\n config: SurveyAssistantRuntimeConfig;\n createHandlers(\n options: CreateConfiguredSurveyAssistantRuntimeHandlersOptions,\n ): ReturnType<typeof createSurveyAssistantRuntimeHandlers>;\n}\n\nexport interface CreateSurveyAssistantRuntimeOptions {\n /** Trusted server-side capabilities for custom registry item types. */\n trustedCapabilities?: SurveyAssistantCapabilitySet;\n}\n\n/**\n * Creates the reusable assistant runtime without hiding Mastra from the host.\n * Register `agents` and `gateways` in the host's standard Mastra instance, then\n * call `createHandlers` with that instance and host authorization policy.\n */\nexport const createSurveyAssistantRuntime = (\n config: SurveyAssistantRuntimeConfig,\n runtimeOptions: CreateSurveyAssistantRuntimeOptions = {},\n): SurveyAssistantRuntime => {\n const components = createSurveyAssistantRuntimeComponents(config);\n return {\n ...components,\n config,\n createHandlers: (handlerOptions) =>\n createSurveyAssistantRuntimeHandlers({\n ...handlerOptions,\n chat: {\n ...handlerOptions.chat,\n trustedCapabilities:\n handlerOptions.chat?.trustedCapabilities ?? runtimeOptions.trustedCapabilities,\n },\n config,\n modelRouter: components.modelRouter,\n }),\n };\n};\n"],"mappings":";;;;;;;;AA+EA,MAAM,oBAAoB;AAC1B,MAAM,iBAAiB;AACvB,MAAM,oCAAoC,MAAU;AACpD,MAAM,0BAA0B,MAAS;AACzC,MAAM,0BAA0B,OAAU;AAC1C,MAAM,yBAAyB,MAAS;AAExC,MAAM,YAAY,KAAkB,SAAiB;AAEnD,QADc,IAAI,OAAO,MAAM,IACf,KAAA;;AAGlB,MAAM,cAAc,KAAkB,MAAc,aAAsB;CACxE,MAAM,QAAQ,SAAS,KAAK,KAAK,EAAE,aAAa;AAChD,KAAI,UAAU,OAAQ,QAAO;AAC7B,KAAI,UAAU,QAAS,QAAO;AAC9B,KAAI,UAAU,KAAA,EACZ,OAAM,IAAI,MAAM,GAAG,KAAK,6BAA6B;AAEvD,QAAO;;AAGT,MAAM,qBAAqB,KAAkB,MAAc,aAAqB;CAC9E,MAAM,aAAa,SAAS,KAAK,KAAK;AACtC,KAAI,eAAe,KAAA,EAAW,QAAO;CACrC,MAAM,QAAQ,OAAO,WAAW;AAChC,KAAI,CAAC,OAAO,cAAc,MAAM,IAAI,SAAS,EAC3C,OAAM,IAAI,MAAM,GAAG,KAAK,8BAA8B;AAExD,QAAO;;AAGT,MAAM,WACJ,KACA,MACA,WACG;CACH,MAAM,QAAQ,SAAS,KAAK,KAAK;AACjC,KAAI,CAAC,MAAO,QAAO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,MAAM;EACN;EACA,MAAM;EACN;EACD;;;;;;;AAoBH,MAAa,gCACX,QACA,iBAAsD,EAAE,KAC7B;CAC3B,MAAM,aAAa,uCAAuC,OAAO;AACjE,QAAO;EACL,GAAG;EACH;EACA,iBAAiB,mBACf,qCAAqC;GACnC,GAAG;GACH,MAAM;IACJ,GAAG,eAAe;IAClB,qBACE,eAAe,MAAM,uBAAuB,eAAe;IAC9D;GACD;GACA,aAAa,WAAW;GACzB,CAAC;EACL"}
|
package/dist/server-tasks.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as SurveyAssistantTaskAuthorizationInput, c as createSurveyAssistantTaskAgent, d as runSurveyAssistantSuggestItemLabelTask, f as runSurveyAssistantTask, i as RunSurveyAssistantTaskOptions, l as createSurveyAssistantTaskHandler, n as CreateSurveyAssistantTaskHandlerOptions, o as SurveyAssistantTaskAuthorizedIdentity, p as runSurveyAssistantTranslateContentTask, r as RunSurveyAssistantBuiltInTaskOptions, s as SurveyAssistantTaskModelResolutionInput, t as CreateSurveyAssistantTaskAgentOptions, u as runSurveyAssistantSuggestItemKeyTask } from "./tasks-
|
|
1
|
+
import { a as SurveyAssistantTaskAuthorizationInput, c as createSurveyAssistantTaskAgent, d as runSurveyAssistantSuggestItemLabelTask, f as runSurveyAssistantTask, i as RunSurveyAssistantTaskOptions, l as createSurveyAssistantTaskHandler, n as CreateSurveyAssistantTaskHandlerOptions, o as SurveyAssistantTaskAuthorizedIdentity, p as runSurveyAssistantTranslateContentTask, r as RunSurveyAssistantBuiltInTaskOptions, s as SurveyAssistantTaskModelResolutionInput, t as CreateSurveyAssistantTaskAgentOptions, u as runSurveyAssistantSuggestItemKeyTask } from "./tasks-DIZgr4nD.mjs";
|
|
2
2
|
export { CreateSurveyAssistantTaskAgentOptions, CreateSurveyAssistantTaskHandlerOptions, RunSurveyAssistantBuiltInTaskOptions, RunSurveyAssistantTaskOptions, SurveyAssistantTaskAuthorizationInput, SurveyAssistantTaskAuthorizedIdentity, SurveyAssistantTaskModelResolutionInput, createSurveyAssistantTaskAgent, createSurveyAssistantTaskHandler, runSurveyAssistantSuggestItemKeyTask, runSurveyAssistantSuggestItemLabelTask, runSurveyAssistantTask, runSurveyAssistantTranslateContentTask };
|
package/dist/server-tasks.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { T as surveyAssistantTaskRequestSchema } from "./protocol-DATvkr1S.mjs";
|
|
2
2
|
import { n as SURVEY_ASSISTANT_TASK_AGENT_ID } from "./constants-CFUWrRtl.mjs";
|
|
3
3
|
import { d as readSurveyAssistantRequestJson, u as SurveyAssistantRequestError } from "./request-guardrails-h4t6u8mP.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { i as surveyAuthoringReferences } from "./authoring-references-ChDTVnms.mjs";
|
|
5
|
+
import { n as FAIR_ITEM_KEY_RULES_TEXT } from "./fair-guidance-CEdJYccK.mjs";
|
|
5
6
|
import { z } from "zod";
|
|
6
7
|
import { RequestContext } from "@mastra/core/request-context";
|
|
7
8
|
import { Agent } from "@mastra/core/agent";
|
|
@@ -109,7 +110,7 @@ const runSurveyAssistantSuggestItemKeyTask = async (input, options) => {
|
|
|
109
110
|
"Return one surveyPattern key that follows the strongest detected local pattern. Preserve that pattern's casing and increment a clear sequence rather than copying an existing number. If no meaningful pattern exists, use a consistent descriptive key.",
|
|
110
111
|
"Return one compact key: a recognizable 2-5 character uppercase abbreviation using only A-Z and digits.",
|
|
111
112
|
"Return one preferred key: the key you consider clearest and most useful without category-specific naming constraints, while still using only letters, digits, and underscores.",
|
|
112
|
-
|
|
113
|
+
`Return one fair key following these FAIR-by-design rules: ${FAIR_ITEM_KEY_RULES_TEXT}. Meaning belongs in metadata, so do not turn it into a sentence.`,
|
|
113
114
|
`You may return up to ${Math.max(0, maxSuggestions - 4)} genuinely useful alternatives when another category has more than one strong candidate. Tag each alternative with its category.`,
|
|
114
115
|
"Never repeat the same suggestion, including case-only or punctuation-only variations.",
|
|
115
116
|
"Do not return the current key, a sibling key, or a semantically unrelated abbreviation.",
|