@case-framework/survey-assistant 0.1.0 → 0.2.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 +71 -11
- package/dist/{authoring-references-X6uRaWuf.mjs → authoring-references-DYuOAdVx.mjs} +26 -2
- package/dist/authoring-references-DYuOAdVx.mjs.map +1 -0
- package/dist/{capabilities-B6tvE7fK.mjs → capabilities-DZ0a_o2y.mjs} +2 -2
- package/dist/{capabilities-B6tvE7fK.mjs.map → capabilities-DZ0a_o2y.mjs.map} +1 -1
- package/dist/{capabilities-DvSKtjAw.d.mts → capabilities-DlC1l6qy.d.mts} +4 -1
- package/dist/capabilities-DlC1l6qy.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 +6 -3
- package/dist/capabilities-default.mjs.map +1 -1
- package/dist/{constants-Jw0k8ojS.d.mts → constants-56jf_4ls.d.mts} +36 -9
- package/dist/constants-56jf_4ls.d.mts.map +1 -0
- package/dist/{controller-proxy-BRDusFiO.d.mts → controller-proxy-2VH0b_5E.d.mts} +29 -4
- package/dist/controller-proxy-2VH0b_5E.d.mts.map +1 -0
- package/dist/{controller-proxy-Duxo2IFE.mjs → controller-proxy-ClsY4lFI.mjs} +74 -5
- package/dist/controller-proxy-ClsY4lFI.mjs.map +1 -0
- package/dist/{digest-BsoVq49o.d.mts → digest-BvXpeWcR.d.mts} +2 -2
- package/dist/{digest-BsoVq49o.d.mts.map → digest-BvXpeWcR.d.mts.map} +1 -1
- package/dist/digest.d.mts +1 -1
- package/dist/{engine-sPvuixWg.mjs → engine-DQrCO_ur.mjs} +392 -50
- package/dist/engine-DQrCO_ur.mjs.map +1 -0
- package/dist/engine.d.mts +2 -2
- package/dist/engine.mjs +2 -2
- package/dist/{index-MpEMQzTm.d.mts → index-B_x2IYi7.d.mts} +5 -1
- package/dist/index-B_x2IYi7.d.mts.map +1 -0
- package/dist/{index-BWNHkpkh.d.mts → index-C_x686M7.d.mts} +27 -5
- package/dist/index-C_x686M7.d.mts.map +1 -0
- package/dist/{index-TFtvBiSQ.d.mts → index-DVxVyhAu.d.mts} +31 -9
- package/dist/index-DVxVyhAu.d.mts.map +1 -0
- package/dist/{index-CUqbBjkc.d.mts → index-DZ6KBwVR.d.mts} +16 -3
- package/dist/index-DZ6KBwVR.d.mts.map +1 -0
- package/dist/{memory-thread-repository-CJkkVE2-.mjs → memory-thread-repository-Cm1BJyRw.mjs} +110 -41
- package/dist/memory-thread-repository-Cm1BJyRw.mjs.map +1 -0
- package/dist/{protocol-DV0ka9WT.mjs → protocol-7EEgcYja.mjs} +70 -97
- package/dist/protocol-7EEgcYja.mjs.map +1 -0
- package/dist/protocol.d.mts +3 -3
- package/dist/protocol.mjs +2 -2
- package/dist/{react-VuYe-cPh.mjs → react-B_5smfiK.mjs} +145 -38
- package/dist/react-B_5smfiK.mjs.map +1 -0
- package/dist/react-integration.d.mts +2 -2
- package/dist/react-integration.mjs +2 -2
- package/dist/react.d.mts +3 -3
- package/dist/react.mjs +3 -3
- package/dist/references/assistant-operations.md +6 -0
- package/dist/references/core-rules.md +6 -0
- package/dist/references/embedded-forms.md +21 -14
- package/dist/references/expressions.md +3 -0
- package/dist/references/item-types.md +37 -10
- package/dist/references/source-material-surveys.md +9 -1
- package/dist/references/survey-data-model.md +13 -0
- package/dist/request-context-BDBw4-Gw.mjs +79 -0
- package/dist/request-context-BDBw4-Gw.mjs.map +1 -0
- package/dist/request-guardrails-h4t6u8mP.mjs +129 -0
- package/dist/request-guardrails-h4t6u8mP.mjs.map +1 -0
- package/dist/server-agent.d.mts +6 -2
- package/dist/server-agent.d.mts.map +1 -1
- package/dist/server-agent.mjs +39 -24
- package/dist/server-agent.mjs.map +1 -1
- package/dist/server-runtime.d.mts +21 -5
- package/dist/server-runtime.d.mts.map +1 -1
- package/dist/server-runtime.mjs +98 -32
- package/dist/server-runtime.mjs.map +1 -1
- package/dist/server-tasks.d.mts +2 -78
- package/dist/server-tasks.mjs +103 -46
- 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 +89 -21
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +136 -5
- package/dist/server.mjs.map +1 -0
- package/dist/storage-postgres.d.mts +12 -2
- package/dist/storage-postgres.d.mts.map +1 -1
- package/dist/storage-postgres.mjs +11 -6
- package/dist/storage-postgres.mjs.map +1 -1
- package/dist/tasks-COQnhSeT.d.mts +140 -0
- package/dist/tasks-COQnhSeT.d.mts.map +1 -0
- package/dist/{thread-documents-DamIq9Od.d.mts → thread-documents-BlxNjc7S.d.mts} +21 -5
- package/dist/thread-documents-BlxNjc7S.d.mts.map +1 -0
- package/dist/{thread-handlers-DpynUc64.d.mts → thread-handlers-l79JBl5m.d.mts} +38 -5
- package/dist/thread-handlers-l79JBl5m.d.mts.map +1 -0
- package/dist/{tools-Hz2p7vyv.mjs → tools-DDXaJ8Za.mjs} +257 -38
- package/dist/tools-DDXaJ8Za.mjs.map +1 -0
- package/dist/ui.d.mts +5 -3
- package/dist/ui.d.mts.map +1 -1
- package/dist/ui.mjs +91 -12
- package/dist/ui.mjs.map +1 -1
- package/docs/integration.md +234 -0
- package/package.json +9 -7
- package/dist/authoring-references-Cy8J-DWt.d.mts +0 -48
- package/dist/authoring-references-Cy8J-DWt.d.mts.map +0 -1
- package/dist/authoring-references-X6uRaWuf.mjs.map +0 -1
- package/dist/capabilities-DvSKtjAw.d.mts.map +0 -1
- package/dist/constants-Jw0k8ojS.d.mts.map +0 -1
- package/dist/controller-proxy-BRDusFiO.d.mts.map +0 -1
- package/dist/controller-proxy-Duxo2IFE.mjs.map +0 -1
- package/dist/engine-sPvuixWg.mjs.map +0 -1
- package/dist/index-BWNHkpkh.d.mts.map +0 -1
- package/dist/index-CUqbBjkc.d.mts.map +0 -1
- package/dist/index-MpEMQzTm.d.mts.map +0 -1
- package/dist/index-TFtvBiSQ.d.mts.map +0 -1
- package/dist/memory-thread-repository-CJkkVE2-.mjs.map +0 -1
- package/dist/protocol-DV0ka9WT.mjs.map +0 -1
- package/dist/react-VuYe-cPh.mjs.map +0 -1
- package/dist/request-context-jcmXT_Q2.mjs +0 -44
- package/dist/request-context-jcmXT_Q2.mjs.map +0 -1
- package/dist/request-guardrails-C59IWnH8.mjs +0 -73
- package/dist/request-guardrails-C59IWnH8.mjs.map +0 -1
- package/dist/server-tasks.d.mts.map +0 -1
- package/dist/thread-documents-DamIq9Od.d.mts.map +0 -1
- package/dist/thread-handlers-DpynUc64.d.mts.map +0 -1
- package/dist/tools-Hz2p7vyv.mjs.map +0 -1
package/dist/server-runtime.mjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { n as SURVEY_ASSISTANT_TASK_AGENT_ID, t as SURVEY_ASSISTANT_AGENT_ID } from "./constants-CFUWrRtl.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
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-Cm1BJyRw.mjs";
|
|
4
|
+
import { t as SURVEY_ASSISTANT_TOOL_IDS } from "./tools-DDXaJ8Za.mjs";
|
|
4
5
|
import { SURVEY_ASSISTANT_OBSERVATIONAL_MEMORY_DEFAULTS, createSurveyAssistantAgent, createSurveyAssistantObservationalMemoryOptions } from "./server-agent.mjs";
|
|
5
6
|
import { createSurveyAssistantTaskAgent, createSurveyAssistantTaskHandler } from "./server-tasks.mjs";
|
|
6
7
|
import { AzureOpenAIGateway } from "@mastra/core/llm";
|
|
7
8
|
//#region src/server/runtime-config.ts
|
|
8
9
|
const DEFAULT_MAX_STEPS = 48;
|
|
9
10
|
const HARD_MAX_STEPS = 64;
|
|
11
|
+
const DEFAULT_MAX_DURATION_MS = 180 * 1e3;
|
|
10
12
|
const DEFAULT_CATALOG_TTL_MS = 300 * 1e3;
|
|
11
13
|
const getValue = (env, name) => {
|
|
12
14
|
return env[name]?.trim() || void 0;
|
|
@@ -15,22 +17,37 @@ const getBoolean = (env, name, fallback) => {
|
|
|
15
17
|
const value = getValue(env, name)?.toLowerCase();
|
|
16
18
|
if (value === "true") return true;
|
|
17
19
|
if (value === "false") return false;
|
|
20
|
+
if (value !== void 0) throw new Error(`${name} must be "true" or "false".`);
|
|
18
21
|
return fallback;
|
|
19
22
|
};
|
|
20
23
|
const getPositiveNumber = (env, name, fallback) => {
|
|
21
|
-
const
|
|
22
|
-
|
|
24
|
+
const configured = getValue(env, name);
|
|
25
|
+
if (configured === void 0) return fallback;
|
|
26
|
+
const value = Number(configured);
|
|
27
|
+
if (!Number.isSafeInteger(value) || value <= 0) throw new Error(`${name} must be a positive integer.`);
|
|
28
|
+
return value;
|
|
23
29
|
};
|
|
24
30
|
const getEnum = (env, name, values) => {
|
|
25
31
|
const value = getValue(env, name);
|
|
26
|
-
|
|
32
|
+
if (!value) return void 0;
|
|
33
|
+
if (!values.includes(value)) throw new Error(`${name} must be one of: ${values.join(", ")}.`);
|
|
34
|
+
return value;
|
|
27
35
|
};
|
|
28
36
|
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
|
+
return value;
|
|
40
|
+
};
|
|
41
|
+
const getOptionalSameProviderModelId = (env, name) => {
|
|
42
|
+
const value = getValue(env, name);
|
|
43
|
+
return value ? getSameProviderModelId(value, name) : void 0;
|
|
44
|
+
};
|
|
29
45
|
const resolveSurveyAssistantProviderOptionsKey = (provider) => provider === "azure-openai" ? "azure" : provider;
|
|
30
46
|
const parseProvider = (env, fallback) => {
|
|
31
47
|
const value = getValue(env, "SURVEY_ASSISTANT_PROVIDER")?.toLowerCase();
|
|
32
48
|
if (value === "azure" || value === "azure-openai") return "azure-openai";
|
|
33
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.");
|
|
34
51
|
return fallback;
|
|
35
52
|
};
|
|
36
53
|
const parseAzureManagement = (env) => {
|
|
@@ -58,9 +75,10 @@ const getReadinessError = ({ azure, env, modelWasConfigured, provider, requireSt
|
|
|
58
75
|
};
|
|
59
76
|
const parseSurveyAssistantEnvironment = (env, { defaultMistralModel = "mistral-medium-latest", defaultOpenAIModel = "gpt-5.4-nano", defaultProvider = "openai", requireExperimentalIdentityOptIn = false, requireStorage = true } = {}) => {
|
|
60
77
|
const provider = parseProvider(env, defaultProvider);
|
|
61
|
-
const configuredModelId =
|
|
62
|
-
const defaultModelId = configuredModelId ?? (provider === "mistral" ? defaultMistralModel : defaultOpenAIModel);
|
|
63
|
-
const modelIds = [...new Set([defaultModelId, ...getCommaSeparatedValues(env, "SURVEY_ASSISTANT_MODELS")])];
|
|
78
|
+
const configuredModelId = getOptionalSameProviderModelId(env, "SURVEY_ASSISTANT_MODEL");
|
|
79
|
+
const defaultModelId = configuredModelId ?? getSameProviderModelId(provider === "mistral" ? defaultMistralModel : defaultOpenAIModel, provider === "mistral" ? "defaultMistralModel" : "defaultOpenAIModel");
|
|
80
|
+
const modelIds = [...new Set([defaultModelId, ...getCommaSeparatedValues(env, "SURVEY_ASSISTANT_MODELS").map((modelId) => getSameProviderModelId(modelId, "SURVEY_ASSISTANT_MODELS"))])];
|
|
81
|
+
const taskModelId = getOptionalSameProviderModelId(env, "SURVEY_ASSISTANT_TASK_MODEL");
|
|
64
82
|
const sendReasoning = getBoolean(env, "SURVEY_ASSISTANT_SEND_REASONING", true);
|
|
65
83
|
const providerOptionsKey = resolveSurveyAssistantProviderOptionsKey(provider);
|
|
66
84
|
const reasoningEffort = getValue(env, `SURVEY_ASSISTANT_${providerOptionsKey.toUpperCase()}_REASONING_EFFORT`) ?? getValue(env, "SURVEY_ASSISTANT_REASONING_EFFORT") ?? (provider === "openai" || provider === "azure-openai" ? "low" : "none");
|
|
@@ -103,8 +121,8 @@ const parseSurveyAssistantEnvironment = (env, { defaultMistralModel = "mistral-m
|
|
|
103
121
|
discoverModels: getBoolean(env, "SURVEY_ASSISTANT_AZURE_DISCOVER_MODELS", false),
|
|
104
122
|
management: parseAzureManagement(env)
|
|
105
123
|
} : void 0;
|
|
106
|
-
const
|
|
107
|
-
const memoryModel =
|
|
124
|
+
const memoryModelId = getOptionalSameProviderModelId(env, "SURVEY_ASSISTANT_MEMORY_MODEL") ?? defaultModelId;
|
|
125
|
+
const memoryModel = `${provider}/${memoryModelId}`;
|
|
108
126
|
const observationalMemory = getBoolean(env, "SURVEY_ASSISTANT_MEMORY_ENABLED", true) ? createSurveyAssistantObservationalMemoryOptions({
|
|
109
127
|
model: memoryModel,
|
|
110
128
|
temporalMarkers: getBoolean(env, "SURVEY_ASSISTANT_MEMORY_TEMPORAL_MARKERS", false),
|
|
@@ -117,10 +135,12 @@ const parseSurveyAssistantEnvironment = (env, { defaultMistralModel = "mistral-m
|
|
|
117
135
|
}) : false;
|
|
118
136
|
const configuredMaxSteps = getPositiveNumber(env, "SURVEY_ASSISTANT_MAX_STEPS", DEFAULT_MAX_STEPS);
|
|
119
137
|
const enabledSetting = getValue(env, "SURVEY_ASSISTANT_ENABLED")?.toLowerCase();
|
|
138
|
+
if (enabledSetting !== void 0 && enabledSetting !== "true" && enabledSetting !== "false") throw new Error("SURVEY_ASSISTANT_ENABLED must be \"true\" or \"false\".");
|
|
120
139
|
const enabled = enabledSetting === "false" ? false : enabledSetting === "true" ? !requireExperimentalIdentityOptIn || env.NODE_ENV === "development" || getBoolean(env, "SURVEY_ASSISTANT_ALLOW_EXPERIMENTAL_IDENTITY", false) : env.NODE_ENV === "development";
|
|
121
140
|
return {
|
|
122
141
|
provider,
|
|
123
142
|
defaultModelId,
|
|
143
|
+
memoryModelId,
|
|
124
144
|
modelIds,
|
|
125
145
|
modelCatalogTtlMs: getPositiveNumber(env, "SURVEY_ASSISTANT_MODEL_CATALOG_TTL_MS", DEFAULT_CATALOG_TTL_MS),
|
|
126
146
|
azure,
|
|
@@ -132,32 +152,61 @@ const parseSurveyAssistantEnvironment = (env, { defaultMistralModel = "mistral-m
|
|
|
132
152
|
provider,
|
|
133
153
|
requireStorage
|
|
134
154
|
}),
|
|
155
|
+
requestLimits: {
|
|
156
|
+
maxAttachmentBytes: getPositiveNumber(env, "SURVEY_ASSISTANT_MAX_ATTACHMENT_BYTES", SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxAttachmentBytes),
|
|
157
|
+
maxAttachments: getPositiveNumber(env, "SURVEY_ASSISTANT_MAX_ATTACHMENTS", SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxAttachments),
|
|
158
|
+
maxRequestBytes: getPositiveNumber(env, "SURVEY_ASSISTANT_MAX_REQUEST_BYTES", SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxRequestBytes),
|
|
159
|
+
maxTextPartChars: getPositiveNumber(env, "SURVEY_ASSISTANT_MAX_TEXT_PART_CHARS", SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxTextPartChars),
|
|
160
|
+
maxTotalAttachmentBytes: getPositiveNumber(env, "SURVEY_ASSISTANT_MAX_TOTAL_ATTACHMENT_BYTES", SURVEY_ASSISTANT_DEFAULT_REQUEST_LIMITS.maxTotalAttachmentBytes)
|
|
161
|
+
},
|
|
135
162
|
execution: {
|
|
136
163
|
maxConcurrentRequests: getPositiveNumber(env, "SURVEY_ASSISTANT_MAX_CONCURRENT_REQUESTS", 4),
|
|
164
|
+
maxDurationMs: getPositiveNumber(env, "SURVEY_ASSISTANT_MAX_DURATION_MS", DEFAULT_MAX_DURATION_MS),
|
|
137
165
|
maxSteps: Math.min(configuredMaxSteps, HARD_MAX_STEPS),
|
|
138
166
|
providerOptions,
|
|
139
167
|
sendReasoning
|
|
140
168
|
},
|
|
141
|
-
observationalMemory
|
|
169
|
+
observationalMemory,
|
|
170
|
+
taskModelId
|
|
142
171
|
};
|
|
143
172
|
};
|
|
144
173
|
//#endregion
|
|
145
174
|
//#region src/server/runtime.ts
|
|
146
175
|
const createSurveyAssistantModelRouter = (config) => {
|
|
176
|
+
const toProviderModel = (modelId, configName) => {
|
|
177
|
+
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
|
+
return `${config.provider}/${modelId}`;
|
|
179
|
+
};
|
|
180
|
+
const defaultModel = toProviderModel(config.defaultModelId, "defaultModelId");
|
|
181
|
+
const chatModelIds = config.modelIds.map((modelId) => {
|
|
182
|
+
toProviderModel(modelId, "modelIds");
|
|
183
|
+
return modelId;
|
|
184
|
+
});
|
|
185
|
+
if (!chatModelIds.includes(config.defaultModelId)) throw new Error("modelIds must include defaultModelId.");
|
|
186
|
+
const taskModel = config.taskModelId ? toProviderModel(config.taskModelId, "taskModelId") : void 0;
|
|
187
|
+
const memoryModel = toProviderModel(config.memoryModelId, "memoryModelId");
|
|
188
|
+
if (config.observationalMemory !== false) {
|
|
189
|
+
if (typeof config.observationalMemory.model !== "string" || config.observationalMemory.model !== memoryModel || 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
|
+
}
|
|
191
|
+
const deploymentIds = [...new Set([
|
|
192
|
+
...chatModelIds,
|
|
193
|
+
...config.taskModelId ? [config.taskModelId] : [],
|
|
194
|
+
config.memoryModelId
|
|
195
|
+
])];
|
|
147
196
|
const azureGateway = config.azure ? new AzureOpenAIGateway({
|
|
148
197
|
resourceName: config.azure.resourceName ?? "",
|
|
149
198
|
apiKey: config.azure.apiKey,
|
|
150
199
|
apiVersion: config.azure.apiVersion,
|
|
151
200
|
useResponsesAPI: true,
|
|
152
|
-
...config.azure.management ? { management: config.azure.management } : { deployments:
|
|
201
|
+
...config.azure.management ? { management: config.azure.management } : { deployments: deploymentIds }
|
|
153
202
|
}) : void 0;
|
|
154
203
|
let cachedCatalog;
|
|
155
204
|
const getCatalog = async ({ refresh = false } = {}) => {
|
|
156
205
|
if (!refresh && cachedCatalog && cachedCatalog.expiresAt > Date.now()) return cachedCatalog.value;
|
|
157
|
-
let ids =
|
|
206
|
+
let ids = chatModelIds;
|
|
158
207
|
if (azureGateway && config.azure?.discoverModels) try {
|
|
159
208
|
const providers = await azureGateway.fetchProviders();
|
|
160
|
-
ids = [...new Set([...
|
|
209
|
+
ids = [...new Set([...chatModelIds, ...providers["azure-openai"]?.models ?? []])];
|
|
161
210
|
} catch {}
|
|
162
211
|
const value = {
|
|
163
212
|
defaultModelId: config.defaultModelId,
|
|
@@ -172,39 +221,47 @@ const createSurveyAssistantModelRouter = (config) => {
|
|
|
172
221
|
};
|
|
173
222
|
return value;
|
|
174
223
|
};
|
|
224
|
+
const resolveRequestedModel = async (requestedModelId) => {
|
|
225
|
+
const catalog = await getCatalog();
|
|
226
|
+
const id = requestedModelId ?? catalog.defaultModelId;
|
|
227
|
+
return catalog.models.some((model) => model.id === id) ? {
|
|
228
|
+
id,
|
|
229
|
+
model: toProviderModel(id, "requestedModelId")
|
|
230
|
+
} : null;
|
|
231
|
+
};
|
|
175
232
|
return {
|
|
176
|
-
defaultModel
|
|
233
|
+
defaultModel,
|
|
177
234
|
gateways: azureGateway ? { "azure-openai": azureGateway } : void 0,
|
|
178
235
|
getCatalog,
|
|
236
|
+
memoryModel,
|
|
179
237
|
providerName: config.provider,
|
|
180
238
|
providerOptions: config.execution.providerOptions,
|
|
181
|
-
resolveModel: async ({ requestedModelId }) =>
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
} : null;
|
|
188
|
-
}
|
|
239
|
+
resolveModel: async ({ requestedModelId }) => resolveRequestedModel(requestedModelId),
|
|
240
|
+
resolveTaskModel: async ({ requestedModelId }) => config.taskModelId ? {
|
|
241
|
+
id: config.taskModelId,
|
|
242
|
+
model: taskModel
|
|
243
|
+
} : resolveRequestedModel(requestedModelId),
|
|
244
|
+
taskModel
|
|
189
245
|
};
|
|
190
246
|
};
|
|
191
247
|
const createSurveyAssistantRuntimeComponents = (config) => {
|
|
192
248
|
const modelRouter = createSurveyAssistantModelRouter(config);
|
|
193
|
-
const
|
|
249
|
+
const chatModel = ({ requestContext }) => requestContext.get("modelSelection")?.model ?? modelRouter.defaultModel;
|
|
250
|
+
const taskModel = modelRouter.taskModel ?? chatModel;
|
|
194
251
|
return {
|
|
195
252
|
agents: {
|
|
196
253
|
[SURVEY_ASSISTANT_AGENT_ID]: createSurveyAssistantAgent({
|
|
197
|
-
model,
|
|
254
|
+
model: chatModel,
|
|
198
255
|
observationalMemory: config.observationalMemory
|
|
199
256
|
}),
|
|
200
|
-
[SURVEY_ASSISTANT_TASK_AGENT_ID]: createSurveyAssistantTaskAgent({ model })
|
|
257
|
+
[SURVEY_ASSISTANT_TASK_AGENT_ID]: createSurveyAssistantTaskAgent({ model: taskModel })
|
|
201
258
|
},
|
|
202
259
|
gateways: modelRouter.gateways,
|
|
203
260
|
modelRouter
|
|
204
261
|
};
|
|
205
262
|
};
|
|
206
263
|
const resolveMastra = async (mastra) => typeof mastra === "function" ? mastra() : mastra;
|
|
207
|
-
const createSurveyAssistantRuntimeHandlers = ({ authorize, chat = {}, config, mastra, modelRouter, threadDocuments }) => {
|
|
264
|
+
const createSurveyAssistantRuntimeHandlers = ({ authorize, chat = {}, config, mastra, modelRouter, task = {}, threadDocuments }) => {
|
|
208
265
|
const isEnabled = chat.isEnabled ?? (() => config.enabled);
|
|
209
266
|
const getReadinessError = chat.getReadinessError ?? (() => config.readinessError);
|
|
210
267
|
const chatHandler = createSurveyAssistantChatHandler({
|
|
@@ -216,20 +273,28 @@ const createSurveyAssistantRuntimeHandlers = ({ authorize, chat = {}, config, ma
|
|
|
216
273
|
getReadinessError,
|
|
217
274
|
isEnabled,
|
|
218
275
|
maxConcurrentRequests: chat.maxConcurrentRequests ?? config.execution.maxConcurrentRequests,
|
|
276
|
+
maxDurationMs: chat.maxDurationMs ?? config.execution.maxDurationMs,
|
|
219
277
|
maxSteps: chat.maxSteps ?? config.execution.maxSteps,
|
|
220
278
|
providerName: modelRouter.providerName,
|
|
221
279
|
providerOptions: modelRouter.providerOptions,
|
|
280
|
+
requestLimits: {
|
|
281
|
+
...config.requestLimits,
|
|
282
|
+
...chat.requestLimits
|
|
283
|
+
},
|
|
222
284
|
resolveModel: modelRouter.resolveModel,
|
|
223
285
|
sendReasoning: chat.sendReasoning ?? config.execution.sendReasoning,
|
|
224
286
|
threadDocuments
|
|
225
287
|
});
|
|
226
288
|
const taskHandler = createSurveyAssistantTaskHandler({
|
|
289
|
+
...task,
|
|
227
290
|
agent: async () => (await resolveMastra(mastra)).getAgent(SURVEY_ASSISTANT_TASK_AGENT_ID),
|
|
228
291
|
authorize: authorize.task,
|
|
229
|
-
getReadinessError,
|
|
230
|
-
isEnabled,
|
|
292
|
+
getReadinessError: task.getReadinessError ?? getReadinessError,
|
|
293
|
+
isEnabled: task.isEnabled ?? isEnabled,
|
|
294
|
+
maxConcurrentRequests: task.maxConcurrentRequests ?? config.execution.maxConcurrentRequests,
|
|
295
|
+
maxDurationMs: task.maxDurationMs ?? config.execution.maxDurationMs,
|
|
231
296
|
providerOptions: modelRouter.providerOptions,
|
|
232
|
-
resolveModel: modelRouter.
|
|
297
|
+
resolveModel: modelRouter.resolveTaskModel
|
|
233
298
|
});
|
|
234
299
|
const getMemory = async () => {
|
|
235
300
|
const memory = await (await resolveMastra(mastra)).getAgent(SURVEY_ASSISTANT_AGENT_ID).getMemory();
|
|
@@ -252,13 +317,14 @@ const createSurveyAssistantRuntimeHandlers = ({ authorize, chat = {}, config, ma
|
|
|
252
317
|
error: "Survey assistant is disabled."
|
|
253
318
|
}, { status: 404 });
|
|
254
319
|
try {
|
|
255
|
-
|
|
320
|
+
if (authorize.model) await authorize.model(request);
|
|
321
|
+
else await authorize.task({ request });
|
|
256
322
|
return Response.json(await modelRouter.getCatalog());
|
|
257
323
|
} catch (error) {
|
|
258
324
|
const status = typeof error === "object" && error !== null && "status" in error && typeof error.status === "number" ? error.status : 403;
|
|
259
325
|
return Response.json({
|
|
260
326
|
code: "authorization_failed",
|
|
261
|
-
error:
|
|
327
|
+
error: "The survey assistant request is not authorized."
|
|
262
328
|
}, { status });
|
|
263
329
|
}
|
|
264
330
|
};
|
|
@@ -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\";\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 maxSteps: number;\n providerOptions?: AgentExecutionOptions[\"providerOptions\"];\n sendReasoning: boolean;\n}\n\nexport interface SurveyAssistantRuntimeConfig {\n azure?: SurveyAssistantAzureConfig;\n defaultModelId: string;\n enabled: boolean;\n modelCatalogTtlMs: number;\n modelIds: string[];\n observationalMemory: SurveyAssistantObservationalMemoryOptions | false;\n provider: SurveyAssistantProvider;\n readinessError: string | null;\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_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 return fallback;\n};\n\nconst getPositiveNumber = (env: Environment, name: string, fallback: number) => {\n const value = Number(getValue(env, name));\n return Number.isFinite(value) && value > 0 ? value : fallback;\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 return value && (values as readonly string[]).includes(value) ? (value as TValue) : undefined;\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\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 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 = getValue(env, \"SURVEY_ASSISTANT_MODEL\");\n const defaultModelId =\n configuredModelId ?? (provider === \"mistral\" ? defaultMistralModel : defaultOpenAIModel);\n const modelIds = [\n ...new Set([defaultModelId, ...getCommaSeparatedValues(env, \"SURVEY_ASSISTANT_MODELS\")]),\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 ?? \"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 memoryModelValue = getValue(env, \"SURVEY_ASSISTANT_MEMORY_MODEL\");\n const memoryModel = memoryModelValue\n ? memoryModelValue.includes(\"/\")\n ? memoryModelValue\n : `${provider}/${memoryModelValue}`\n : `${provider}/${defaultModelId}`;\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 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 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 execution: {\n maxConcurrentRequests: getPositiveNumber(env, \"SURVEY_ASSISTANT_MAX_CONCURRENT_REQUESTS\", 4),\n maxSteps: Math.min(configuredMaxSteps, HARD_MAX_STEPS),\n providerOptions,\n sendReasoning,\n },\n observationalMemory,\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} 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 providerName: string;\n providerOptions?: AgentExecutionOptions[\"providerOptions\"];\n resolveModel: SurveyAssistantResolveModel;\n}\n\nexport const createSurveyAssistantModelRouter = (\n config: SurveyAssistantRuntimeConfig,\n): SurveyAssistantModelRouter => {\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: config.modelIds }),\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 = config.modelIds;\n if (azureGateway && config.azure?.discoverModels) {\n try {\n const providers = await azureGateway.fetchProviders();\n ids = [...new Set([...config.modelIds, ...(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\n return {\n defaultModel: `${config.provider}/${config.defaultModelId}`,\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 providerName: config.provider,\n providerOptions: config.execution.providerOptions,\n resolveModel: async ({ requestedModelId }) => {\n const catalog = await getCatalog();\n const id = requestedModelId ?? catalog.defaultModelId;\n return catalog.models.some((model) => model.id === id)\n ? { id, model: `${config.provider}/${id}` }\n : null;\n },\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 model: CreateSurveyAssistantAgentOptions[\"model\"] = ({\n requestContext,\n }: {\n requestContext: RequestContext<SurveyAssistantRequestContext>;\n }) => requestContext.get(\"modelSelection\")?.model ?? modelRouter.defaultModel;\n return {\n agents: {\n [SURVEY_ASSISTANT_AGENT_ID]: createSurveyAssistantAgent({\n model,\n observationalMemory: config.observationalMemory,\n }),\n [SURVEY_ASSISTANT_TASK_AGENT_ID]: createSurveyAssistantTaskAgent({ model }),\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>;\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 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 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 maxSteps: chat.maxSteps ?? config.execution.maxSteps,\n providerName: modelRouter.providerName,\n providerOptions: modelRouter.providerOptions,\n resolveModel: modelRouter.resolveModel,\n sendReasoning: chat.sendReasoning ?? config.execution.sendReasoning,\n threadDocuments,\n });\n const taskHandler = createSurveyAssistantTaskHandler({\n agent: async () => (await resolveMastra(mastra)).getAgent(SURVEY_ASSISTANT_TASK_AGENT_ID),\n authorize: authorize.task,\n getReadinessError,\n isEnabled,\n providerOptions: modelRouter.providerOptions,\n resolveModel: modelRouter.resolveModel,\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 await (authorize.model ?? authorize.task)(request);\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:\n error instanceof Error\n ? error.message\n : \"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":";;;;;;;AAgDA,MAAM,oBAAoB;AAC1B,MAAM,iBAAiB;AACvB,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,QAAO;;AAGT,MAAM,qBAAqB,KAAkB,MAAc,aAAqB;CAC9E,MAAM,QAAQ,OAAO,SAAS,KAAK,KAAK,CAAC;AACzC,QAAO,OAAO,SAAS,MAAM,IAAI,QAAQ,IAAI,QAAQ;;AAGvD,MAAM,WACJ,KACA,MACA,WACG;CACH,MAAM,QAAQ,SAAS,KAAK,KAAK;AACjC,QAAO,SAAU,OAA6B,SAAS,MAAM,GAAI,QAAmB,KAAA;;AAGtF,MAAM,2BAA2B,KAAkB,SAAiB,CAClE,GAAG,IAAI,KACJ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I,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,UAAO,UAAU,SAAS,UAAU,MAAM,QAAQ;AAClD,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,OACE,iBAAiB,QACb,MAAM,UACN;IACP,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\" | \"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,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,K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U,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"}
|
package/dist/server-tasks.d.mts
CHANGED
|
@@ -1,78 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { t as SurveyAuthoringReferenceTopic } from "./authoring-references-Cy8J-DWt.mjs";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
import { RequestContext } from "@mastra/core/request-context";
|
|
6
|
-
import * as _$_mastra_core_agent0 from "@mastra/core/agent";
|
|
7
|
-
import { Agent, AgentConfig, AgentExecutionOptions } from "@mastra/core/agent";
|
|
8
|
-
|
|
9
|
-
//#region src/server/tasks.d.ts
|
|
10
|
-
type SurveyAssistantTaskAgentConfig = AgentConfig<typeof SURVEY_ASSISTANT_TASK_AGENT_ID, Record<string, never>, undefined, SurveyAssistantRequestContext>;
|
|
11
|
-
interface CreateSurveyAssistantTaskAgentOptions {
|
|
12
|
-
model: SurveyAssistantTaskAgentConfig["model"];
|
|
13
|
-
}
|
|
14
|
-
declare const createSurveyAssistantTaskAgent: ({
|
|
15
|
-
model
|
|
16
|
-
}: CreateSurveyAssistantTaskAgentOptions) => Agent<"survey-assistant-task-agent", Record<string, never>, undefined, SurveyAssistantRequestContext, _$_mastra_core_agent0.AgentEditorConfig | undefined>;
|
|
17
|
-
interface RunSurveyAssistantTaskOptions<TSchema extends z.ZodType> {
|
|
18
|
-
agent: Pick<Agent, "generate">;
|
|
19
|
-
taskId: string;
|
|
20
|
-
input: unknown;
|
|
21
|
-
context: SurveyAssistantTaskContext;
|
|
22
|
-
schema: TSchema;
|
|
23
|
-
instructions: readonly string[];
|
|
24
|
-
referenceTopics?: readonly SurveyAuthoringReferenceTopic[];
|
|
25
|
-
requestContext?: RequestContext<SurveyAssistantRequestContext>;
|
|
26
|
-
providerOptions?: AgentExecutionOptions["providerOptions"];
|
|
27
|
-
abortSignal?: AbortSignal;
|
|
28
|
-
}
|
|
29
|
-
declare const runSurveyAssistantTask: <TSchema extends z.ZodType>({
|
|
30
|
-
agent,
|
|
31
|
-
taskId,
|
|
32
|
-
input,
|
|
33
|
-
context,
|
|
34
|
-
schema,
|
|
35
|
-
instructions,
|
|
36
|
-
referenceTopics,
|
|
37
|
-
requestContext,
|
|
38
|
-
providerOptions,
|
|
39
|
-
abortSignal
|
|
40
|
-
}: RunSurveyAssistantTaskOptions<TSchema>) => Promise<z.output<TSchema>>;
|
|
41
|
-
interface RunSurveyAssistantBuiltInTaskOptions {
|
|
42
|
-
agent: Pick<Agent, "generate">;
|
|
43
|
-
context: SurveyAssistantTaskContext;
|
|
44
|
-
mode?: SurveyAssistantTaskInvocationMode;
|
|
45
|
-
requestContext?: RequestContext<SurveyAssistantRequestContext>;
|
|
46
|
-
providerOptions?: AgentExecutionOptions["providerOptions"];
|
|
47
|
-
abortSignal?: AbortSignal;
|
|
48
|
-
}
|
|
49
|
-
declare const runSurveyAssistantSuggestItemKeyTask: (input: SurveyAssistantSuggestItemKeyInput, options: RunSurveyAssistantBuiltInTaskOptions) => Promise<SurveyAssistantSuggestItemKeyResult>;
|
|
50
|
-
declare const runSurveyAssistantSuggestItemLabelTask: (input: SurveyAssistantSuggestItemLabelInput, options: RunSurveyAssistantBuiltInTaskOptions) => Promise<SurveyAssistantSuggestItemLabelResult>;
|
|
51
|
-
declare const runSurveyAssistantTranslateContentTask: (input: SurveyAssistantTranslateContentInput, options: RunSurveyAssistantBuiltInTaskOptions) => Promise<SurveyAssistantTranslateContentResult>;
|
|
52
|
-
interface SurveyAssistantTaskAuthorizedIdentity {
|
|
53
|
-
resourceId: string;
|
|
54
|
-
}
|
|
55
|
-
interface SurveyAssistantTaskModelResolutionInput {
|
|
56
|
-
identity: SurveyAssistantTaskAuthorizedIdentity;
|
|
57
|
-
request: Request;
|
|
58
|
-
requestedModelId?: string;
|
|
59
|
-
}
|
|
60
|
-
interface CreateSurveyAssistantTaskHandlerOptions {
|
|
61
|
-
agent: Pick<Agent, "generate"> | (() => Pick<Agent, "generate"> | Promise<Pick<Agent, "generate">>);
|
|
62
|
-
authorize(request: Request): SurveyAssistantTaskAuthorizedIdentity | Promise<SurveyAssistantTaskAuthorizedIdentity>;
|
|
63
|
-
getReadinessError?(request: Request): string | null | Promise<string | null>;
|
|
64
|
-
isEnabled?(request: Request): boolean | Promise<boolean>;
|
|
65
|
-
providerOptions?: AgentExecutionOptions["providerOptions"];
|
|
66
|
-
resolveModel?(input: SurveyAssistantTaskModelResolutionInput): SurveyAssistantModelSelection | null | undefined | Promise<SurveyAssistantModelSelection | null | undefined>;
|
|
67
|
-
}
|
|
68
|
-
declare const createSurveyAssistantTaskHandler: ({
|
|
69
|
-
agent,
|
|
70
|
-
authorize,
|
|
71
|
-
getReadinessError,
|
|
72
|
-
isEnabled,
|
|
73
|
-
providerOptions,
|
|
74
|
-
resolveModel
|
|
75
|
-
}: CreateSurveyAssistantTaskHandlerOptions) => (request: Request) => Promise<Response>;
|
|
76
|
-
//#endregion
|
|
77
|
-
export { CreateSurveyAssistantTaskAgentOptions, CreateSurveyAssistantTaskHandlerOptions, RunSurveyAssistantBuiltInTaskOptions, RunSurveyAssistantTaskOptions, SurveyAssistantTaskAuthorizedIdentity, SurveyAssistantTaskModelResolutionInput, createSurveyAssistantTaskAgent, createSurveyAssistantTaskHandler, runSurveyAssistantSuggestItemKeyTask, runSurveyAssistantSuggestItemLabelTask, runSurveyAssistantTask, runSurveyAssistantTranslateContentTask };
|
|
78
|
-
//# sourceMappingURL=server-tasks.d.mts.map
|
|
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-COQnhSeT.mjs";
|
|
2
|
+
export { CreateSurveyAssistantTaskAgentOptions, CreateSurveyAssistantTaskHandlerOptions, RunSurveyAssistantBuiltInTaskOptions, RunSurveyAssistantTaskOptions, SurveyAssistantTaskAuthorizationInput, SurveyAssistantTaskAuthorizedIdentity, SurveyAssistantTaskModelResolutionInput, createSurveyAssistantTaskAgent, createSurveyAssistantTaskHandler, runSurveyAssistantSuggestItemKeyTask, runSurveyAssistantSuggestItemLabelTask, runSurveyAssistantTask, runSurveyAssistantTranslateContentTask };
|