@mcoda/mswarm 0.1.90 → 0.1.91
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/codali-executor.d.ts +107 -6
- package/dist/codali-executor.d.ts.map +1 -1
- package/dist/codali-executor.js +500 -26
- package/dist/codali-executor.js.map +1 -1
- package/dist/runtime.d.ts +4 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +18 -5
- package/dist/runtime.js.map +1 -1
- package/dist/vendor/codali/cli/DatasetCommand.d.ts +38 -0
- package/dist/vendor/codali/cli/DatasetCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/DatasetCommand.js +959 -0
- package/dist/vendor/codali/cli/EvalCommand.d.ts +3 -0
- package/dist/vendor/codali/cli/EvalCommand.d.ts.map +1 -1
- package/dist/vendor/codali/cli/EvalCommand.js +55 -1
- package/dist/vendor/codali/cli/ImprovementCommand.d.ts +97 -0
- package/dist/vendor/codali/cli/ImprovementCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/ImprovementCommand.js +1879 -0
- package/dist/vendor/codali/cli.d.ts.map +1 -1
- package/dist/vendor/codali/cli.js +15 -0
- package/dist/vendor/codali/dataset-cli.d.ts +3 -0
- package/dist/vendor/codali/dataset-cli.d.ts.map +1 -0
- package/dist/vendor/codali/dataset-cli.js +30 -0
- package/dist/vendor/codali/eval/CodaliGatewayLiveHarness.d.ts +90 -1
- package/dist/vendor/codali/eval/CodaliGatewayLiveHarness.d.ts.map +1 -1
- package/dist/vendor/codali/eval/CodaliGatewayLiveHarness.js +443 -9
- package/dist/vendor/codali/eval/GatewayDatasetEval.d.ts +70 -0
- package/dist/vendor/codali/eval/GatewayDatasetEval.d.ts.map +1 -0
- package/dist/vendor/codali/eval/GatewayDatasetEval.js +477 -0
- package/dist/vendor/codali/eval/GatewayEvalSuite.d.ts +52 -0
- package/dist/vendor/codali/eval/GatewayEvalSuite.d.ts.map +1 -1
- package/dist/vendor/codali/eval/GatewayEvalSuite.js +135 -1
- package/dist/vendor/codali/gateway/CodaliGateway.d.ts +4 -0
- package/dist/vendor/codali/gateway/CodaliGateway.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/CodaliGateway.js +37 -1
- package/dist/vendor/codali/gateway/CodaliGatewaySchemas.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/CodaliGatewaySchemas.js +0 -4
- package/dist/vendor/codali/gateway/CodaliGatewayStore.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/CodaliGatewayStore.js +1 -0
- package/dist/vendor/codali/gateway/GatewayPlanner.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/GatewayPlanner.js +355 -41
- package/dist/vendor/codali/gateway/GatewayStateMachine.d.ts +1 -0
- package/dist/vendor/codali/gateway/GatewayStateMachine.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/GatewayStateMachine.js +221 -5
- package/dist/vendor/codali/improvement/CandidateReleaseBuilder.d.ts +201 -0
- package/dist/vendor/codali/improvement/CandidateReleaseBuilder.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/CandidateReleaseBuilder.js +1175 -0
- package/dist/vendor/codali/improvement/DatasetEligibilityGate.d.ts +75 -0
- package/dist/vendor/codali/improvement/DatasetEligibilityGate.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/DatasetEligibilityGate.js +497 -0
- package/dist/vendor/codali/improvement/DatasetExportManifestReader.d.ts +88 -0
- package/dist/vendor/codali/improvement/DatasetExportManifestReader.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/DatasetExportManifestReader.js +333 -0
- package/dist/vendor/codali/improvement/DocdexRetrievalCandidateBuilder.d.ts +192 -0
- package/dist/vendor/codali/improvement/DocdexRetrievalCandidateBuilder.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/DocdexRetrievalCandidateBuilder.js +625 -0
- package/dist/vendor/codali/improvement/EvalReplayCandidateBuilder.d.ts +173 -0
- package/dist/vendor/codali/improvement/EvalReplayCandidateBuilder.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/EvalReplayCandidateBuilder.js +363 -0
- package/dist/vendor/codali/improvement/FineTuneJobPlanner.d.ts +281 -0
- package/dist/vendor/codali/improvement/FineTuneJobPlanner.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/FineTuneJobPlanner.js +823 -0
- package/dist/vendor/codali/improvement/ImprovementEvalRunner.d.ts +50 -0
- package/dist/vendor/codali/improvement/ImprovementEvalRunner.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/ImprovementEvalRunner.js +648 -0
- package/dist/vendor/codali/improvement/ImprovementPolicy.d.ts +272 -0
- package/dist/vendor/codali/improvement/ImprovementPolicy.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/ImprovementPolicy.js +1450 -0
- package/dist/vendor/codali/improvement/ModelRouterCandidateBuilder.d.ts +186 -0
- package/dist/vendor/codali/improvement/ModelRouterCandidateBuilder.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/ModelRouterCandidateBuilder.js +880 -0
- package/dist/vendor/codali/improvement/OperatorInspector.d.ts +182 -0
- package/dist/vendor/codali/improvement/OperatorInspector.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/OperatorInspector.js +604 -0
- package/dist/vendor/codali/improvement/ProductionGovernance.d.ts +91 -0
- package/dist/vendor/codali/improvement/ProductionGovernance.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/ProductionGovernance.js +329 -0
- package/dist/vendor/codali/improvement/PromptSchemaToolMetadataCandidateBuilder.d.ts +152 -0
- package/dist/vendor/codali/improvement/PromptSchemaToolMetadataCandidateBuilder.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/PromptSchemaToolMetadataCandidateBuilder.js +480 -0
- package/dist/vendor/codali/improvement/PublishOrchestrator.d.ts +113 -0
- package/dist/vendor/codali/improvement/PublishOrchestrator.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/PublishOrchestrator.js +590 -0
- package/dist/vendor/codali/improvement/ReleaseOutcomeReporter.d.ts +133 -0
- package/dist/vendor/codali/improvement/ReleaseOutcomeReporter.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/ReleaseOutcomeReporter.js +501 -0
- package/dist/vendor/codali/improvement/StorageServiceImprovementClient.d.ts +71 -0
- package/dist/vendor/codali/improvement/StorageServiceImprovementClient.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/StorageServiceImprovementClient.js +245 -0
- package/dist/vendor/codali/index.d.ts +43 -0
- package/dist/vendor/codali/index.d.ts.map +1 -1
- package/dist/vendor/codali/index.js +21 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +0 -2
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/CodaliRuntime.js +0 -5
- package/dist/vendor/codali/storage/CodaliDatasetPrivacyEngine.d.ts +138 -0
- package/dist/vendor/codali/storage/CodaliDatasetPrivacyEngine.d.ts.map +1 -0
- package/dist/vendor/codali/storage/CodaliDatasetPrivacyEngine.js +417 -0
- package/dist/vendor/codali/storage/CodaliFeedbackReviewIngestion.d.ts +50 -0
- package/dist/vendor/codali/storage/CodaliFeedbackReviewIngestion.d.ts.map +1 -0
- package/dist/vendor/codali/storage/CodaliFeedbackReviewIngestion.js +141 -0
- package/dist/vendor/codali/storage/CodaliStorageContracts.d.ts +337 -0
- package/dist/vendor/codali/storage/CodaliStorageContracts.d.ts.map +1 -0
- package/dist/vendor/codali/storage/CodaliStorageContracts.js +1555 -0
- package/dist/vendor/codali/storage/DatasetExportJob.d.ts +51 -0
- package/dist/vendor/codali/storage/DatasetExportJob.d.ts.map +1 -0
- package/dist/vendor/codali/storage/DatasetExportJob.js +358 -0
- package/dist/vendor/codali/storage/DatasetReviewQueue.d.ts +98 -0
- package/dist/vendor/codali/storage/DatasetReviewQueue.d.ts.map +1 -0
- package/dist/vendor/codali/storage/DatasetReviewQueue.js +426 -0
- package/dist/vendor/codali/storage/GatewayDatasetStore.d.ts +233 -0
- package/dist/vendor/codali/storage/GatewayDatasetStore.d.ts.map +1 -0
- package/dist/vendor/codali/storage/GatewayDatasetStore.js +2070 -0
- package/package.json +3 -3
|
@@ -93,7 +93,150 @@ const isRecord = (value) => Boolean(value && typeof value === "object" && !Array
|
|
|
93
93
|
const readString = (record, key) => typeof record[key] === "string" && record[key].trim()
|
|
94
94
|
? record[key].trim()
|
|
95
95
|
: undefined;
|
|
96
|
-
const
|
|
96
|
+
const readFlexibleBoolean = (record, key) => {
|
|
97
|
+
const snakeKey = key.replace(/[A-Z]/g, (char) => `_${char.toLowerCase()}`);
|
|
98
|
+
for (const candidateKey of [key, snakeKey]) {
|
|
99
|
+
const value = record[candidateKey];
|
|
100
|
+
if (typeof value === "boolean")
|
|
101
|
+
return value;
|
|
102
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
103
|
+
if (value === 1)
|
|
104
|
+
return true;
|
|
105
|
+
if (value === 0)
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (typeof value === "string") {
|
|
109
|
+
const normalized = value.trim().toLowerCase();
|
|
110
|
+
if (["true", "yes", "y", "1", "needed", "required"].includes(normalized)) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
if (["false", "no", "n", "0", "none", "not_needed", "not required"].includes(normalized)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
};
|
|
120
|
+
const readClassifierQueryType = (record) => readString(record, "queryType") ??
|
|
121
|
+
readString(record, "query_type") ??
|
|
122
|
+
readString(record, "intent") ??
|
|
123
|
+
readString(record, "type") ??
|
|
124
|
+
readString(record, "category") ??
|
|
125
|
+
readString(record, "route");
|
|
126
|
+
const CLASSIFIER_WRAPPER_KEYS = [
|
|
127
|
+
"classifier",
|
|
128
|
+
"classification",
|
|
129
|
+
"routing",
|
|
130
|
+
"route",
|
|
131
|
+
"output",
|
|
132
|
+
"result",
|
|
133
|
+
];
|
|
134
|
+
const hasClassifierSignals = (record) => Boolean(readClassifierQueryType(record) ||
|
|
135
|
+
"needsPrivateData" in record ||
|
|
136
|
+
"needs_private_data" in record ||
|
|
137
|
+
"needsFreshData" in record ||
|
|
138
|
+
"needs_fresh_data" in record ||
|
|
139
|
+
"needsDocdex" in record ||
|
|
140
|
+
"needs_docdex" in record ||
|
|
141
|
+
"needsAppTools" in record ||
|
|
142
|
+
"needs_app_tools" in record ||
|
|
143
|
+
"needsImageWorker" in record ||
|
|
144
|
+
"needs_image_worker" in record);
|
|
145
|
+
const unwrapClassifierRecord = (value) => {
|
|
146
|
+
if (!isRecord(value))
|
|
147
|
+
return undefined;
|
|
148
|
+
if (hasClassifierSignals(value))
|
|
149
|
+
return value;
|
|
150
|
+
for (const key of CLASSIFIER_WRAPPER_KEYS) {
|
|
151
|
+
const nested = value[key];
|
|
152
|
+
if (isRecord(nested) && hasClassifierSignals(nested)) {
|
|
153
|
+
return nested;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return value;
|
|
157
|
+
};
|
|
158
|
+
const readAliasValue = (record, keys) => {
|
|
159
|
+
for (const key of keys) {
|
|
160
|
+
if (key in record)
|
|
161
|
+
return record[key];
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
};
|
|
165
|
+
const readStringFromKeys = (record, keys) => {
|
|
166
|
+
for (const key of keys) {
|
|
167
|
+
const value = readString(record, key);
|
|
168
|
+
if (value)
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
return undefined;
|
|
172
|
+
};
|
|
173
|
+
const stringListFromValue = (value) => {
|
|
174
|
+
if (Array.isArray(value)) {
|
|
175
|
+
const items = value
|
|
176
|
+
.flatMap((item) => {
|
|
177
|
+
if (typeof item === "string")
|
|
178
|
+
return [item.trim()];
|
|
179
|
+
if (isRecord(item)) {
|
|
180
|
+
const name = readStringFromKeys(item, ["name", "tool", "id", "source"]);
|
|
181
|
+
return name ? [name] : [];
|
|
182
|
+
}
|
|
183
|
+
return [];
|
|
184
|
+
})
|
|
185
|
+
.filter(Boolean);
|
|
186
|
+
return items.length > 0 ? items : undefined;
|
|
187
|
+
}
|
|
188
|
+
if (typeof value === "string") {
|
|
189
|
+
const items = value
|
|
190
|
+
.split(/[\n,;]+/g)
|
|
191
|
+
.map((item) => item.trim())
|
|
192
|
+
.filter(Boolean);
|
|
193
|
+
return items.length > 0 ? items : undefined;
|
|
194
|
+
}
|
|
195
|
+
return undefined;
|
|
196
|
+
};
|
|
197
|
+
const hasAppToolContract = (value) => {
|
|
198
|
+
if (!isRecord(value))
|
|
199
|
+
return false;
|
|
200
|
+
return Object.keys(value).length > 0;
|
|
201
|
+
};
|
|
202
|
+
const inferClassifierDefaults = (input, policyCompilation) => {
|
|
203
|
+
const request = input?.request;
|
|
204
|
+
const allowedTools = policyCompilation
|
|
205
|
+
? allowedToolNames(policyCompilation)
|
|
206
|
+
: request?.policy.allowedTools ?? [];
|
|
207
|
+
const hasDocdexTool = allowedTools.some((tool) => tool === "docdex_search" || tool.startsWith("docdex_"));
|
|
208
|
+
const docdex = request?.docdex;
|
|
209
|
+
const needsDocdex = Boolean(docdex?.required === true ||
|
|
210
|
+
docdex?.enabled === true ||
|
|
211
|
+
docdex?.repoId ||
|
|
212
|
+
docdex?.repoRoot ||
|
|
213
|
+
hasDocdexTool);
|
|
214
|
+
const appToolNames = new Set();
|
|
215
|
+
for (const tool of request?.policy.appVirtualTools ?? []) {
|
|
216
|
+
appToolNames.add(tool);
|
|
217
|
+
}
|
|
218
|
+
if (hasAppToolContract(request?.policy.appToolContracts)) {
|
|
219
|
+
for (const tool of Object.keys(request?.policy.appToolContracts ?? {})) {
|
|
220
|
+
appToolNames.add(tool);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
for (const tool of allowedTools) {
|
|
224
|
+
if (tool !== "docdex_search" && !tool.startsWith("docdex_")) {
|
|
225
|
+
appToolNames.add(tool);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const needsAppTools = Boolean(appToolNames.size > 0 || request?.policy.appToolGateway);
|
|
229
|
+
const tenantScoped = Boolean(request?.tenant?.id || request?.tenant?.slug || request?.tenant?.realm);
|
|
230
|
+
const usesRuntimeData = needsDocdex || needsAppTools;
|
|
231
|
+
return {
|
|
232
|
+
queryType: request?.mode === "image" ? "image" : "general",
|
|
233
|
+
needsPrivateData: Boolean((tenantScoped && usesRuntimeData) || docdex?.required === true),
|
|
234
|
+
needsFreshData: needsAppTools,
|
|
235
|
+
needsDocdex,
|
|
236
|
+
needsAppTools,
|
|
237
|
+
needsImageWorker: request?.mode === "image" && request?.policy.allowImageWorker === true,
|
|
238
|
+
};
|
|
239
|
+
};
|
|
97
240
|
const parseJsonObject = (content) => {
|
|
98
241
|
const trimmed = content.trim();
|
|
99
242
|
const fenced = trimmed.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i)?.[1]?.trim();
|
|
@@ -110,9 +253,10 @@ const parseJsonObject = (content) => {
|
|
|
110
253
|
throw new CodaliGatewayPlannerError("GATEWAY_JSON_PARSE_FAILED", "Planner stage returned non-JSON content.");
|
|
111
254
|
}
|
|
112
255
|
};
|
|
113
|
-
const validateClassifierOutput = (value) => {
|
|
256
|
+
const validateClassifierOutput = (value, input, policyCompilation) => {
|
|
114
257
|
const issues = [];
|
|
115
|
-
|
|
258
|
+
const record = unwrapClassifierRecord(value);
|
|
259
|
+
if (!record) {
|
|
116
260
|
return {
|
|
117
261
|
issues: [
|
|
118
262
|
{
|
|
@@ -123,14 +267,8 @@ const validateClassifierOutput = (value) => {
|
|
|
123
267
|
],
|
|
124
268
|
};
|
|
125
269
|
}
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
issues.push({
|
|
129
|
-
path: "$.queryType",
|
|
130
|
-
code: "expected_non_empty_string",
|
|
131
|
-
message: "queryType is required.",
|
|
132
|
-
});
|
|
133
|
-
}
|
|
270
|
+
const defaults = inferClassifierDefaults(input, policyCompilation);
|
|
271
|
+
const queryType = readClassifierQueryType(record) ?? defaults.queryType;
|
|
134
272
|
const requiredBooleans = [
|
|
135
273
|
"needsPrivateData",
|
|
136
274
|
"needsFreshData",
|
|
@@ -140,31 +278,13 @@ const validateClassifierOutput = (value) => {
|
|
|
140
278
|
];
|
|
141
279
|
const booleans = {};
|
|
142
280
|
for (const key of requiredBooleans) {
|
|
143
|
-
|
|
144
|
-
const valueForKey = readBoolean(value, key) ?? readBoolean(value, snakeKey);
|
|
145
|
-
if (valueForKey === undefined) {
|
|
146
|
-
issues.push({
|
|
147
|
-
path: `$.${key}`,
|
|
148
|
-
code: "expected_boolean",
|
|
149
|
-
message: `${key} is required and must be a boolean.`,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
booleans[key] = valueForKey;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
const confidence = readString(value, "confidence");
|
|
157
|
-
if (confidence !== undefined &&
|
|
158
|
-
confidence !== "high" &&
|
|
159
|
-
confidence !== "medium" &&
|
|
160
|
-
confidence !== "low") {
|
|
161
|
-
issues.push({
|
|
162
|
-
path: "$.confidence",
|
|
163
|
-
code: "expected_enum",
|
|
164
|
-
message: "confidence must be high, medium, or low.",
|
|
165
|
-
});
|
|
281
|
+
booleans[key] = readFlexibleBoolean(record, key) ?? defaults[key];
|
|
166
282
|
}
|
|
167
|
-
|
|
283
|
+
const confidenceValue = readString(record, "confidence")?.toLowerCase();
|
|
284
|
+
const confidence = confidenceValue === "high" || confidenceValue === "medium" || confidenceValue === "low"
|
|
285
|
+
? confidenceValue
|
|
286
|
+
: undefined;
|
|
287
|
+
if (issues.length > 0) {
|
|
168
288
|
return { issues };
|
|
169
289
|
}
|
|
170
290
|
return {
|
|
@@ -176,11 +296,11 @@ const validateClassifierOutput = (value) => {
|
|
|
176
296
|
needsDocdex: booleans.needsDocdex ?? false,
|
|
177
297
|
needsAppTools: booleans.needsAppTools ?? false,
|
|
178
298
|
needsImageWorker: booleans.needsImageWorker ?? false,
|
|
179
|
-
directAnswerCandidate: readString(
|
|
180
|
-
readString(
|
|
181
|
-
rationale: readString(
|
|
299
|
+
directAnswerCandidate: readString(record, "directAnswerCandidate") ??
|
|
300
|
+
readString(record, "direct_answer_candidate"),
|
|
301
|
+
rationale: readString(record, "rationale"),
|
|
182
302
|
confidence,
|
|
183
|
-
metadata: isRecord(
|
|
303
|
+
metadata: isRecord(record.metadata) ? record.metadata : undefined,
|
|
184
304
|
},
|
|
185
305
|
};
|
|
186
306
|
};
|
|
@@ -271,6 +391,200 @@ const buildRepairMessages = (stage, originalMessages, rawContent, error) => [
|
|
|
271
391
|
].join("\n"),
|
|
272
392
|
},
|
|
273
393
|
];
|
|
394
|
+
const PLANNER_WRAPPER_KEYS = [
|
|
395
|
+
"planner",
|
|
396
|
+
"planning",
|
|
397
|
+
"plan",
|
|
398
|
+
"routing",
|
|
399
|
+
"output",
|
|
400
|
+
"result",
|
|
401
|
+
];
|
|
402
|
+
const hasPlannerSignals = (record) => Boolean(readStringFromKeys(record, ["queryType", "query_type", "intent", "type", "category"]) ||
|
|
403
|
+
readAliasValue(record, ["subquestions", "sub_questions", "questions"]) ||
|
|
404
|
+
readAliasValue(record, ["workerTasks", "worker_tasks", "tasks", "steps", "workers"]));
|
|
405
|
+
const unwrapPlannerRecord = (value) => {
|
|
406
|
+
if (Array.isArray(value)) {
|
|
407
|
+
return { workerTasks: value };
|
|
408
|
+
}
|
|
409
|
+
if (!isRecord(value))
|
|
410
|
+
return undefined;
|
|
411
|
+
if (hasPlannerSignals(value))
|
|
412
|
+
return value;
|
|
413
|
+
for (const key of PLANNER_WRAPPER_KEYS) {
|
|
414
|
+
const nested = value[key];
|
|
415
|
+
if (Array.isArray(nested)) {
|
|
416
|
+
return { workerTasks: nested };
|
|
417
|
+
}
|
|
418
|
+
if (isRecord(nested) && hasPlannerSignals(nested)) {
|
|
419
|
+
return nested;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return value;
|
|
423
|
+
};
|
|
424
|
+
const normalizePlannerSubquestions = (record, request) => {
|
|
425
|
+
const input = readAliasValue(record, [
|
|
426
|
+
"subquestions",
|
|
427
|
+
"sub_questions",
|
|
428
|
+
"questions",
|
|
429
|
+
"researchQuestions",
|
|
430
|
+
"research_questions",
|
|
431
|
+
]);
|
|
432
|
+
if (!Array.isArray(input)) {
|
|
433
|
+
return [];
|
|
434
|
+
}
|
|
435
|
+
const output = [];
|
|
436
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
437
|
+
const item = input[index];
|
|
438
|
+
if (typeof item === "string" && item.trim()) {
|
|
439
|
+
output.push({ id: `sq-${index + 1}`, question: item.trim() });
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
if (!isRecord(item))
|
|
443
|
+
continue;
|
|
444
|
+
const question = readStringFromKeys(item, ["question", "query", "objective", "task", "description"]) ??
|
|
445
|
+
request.query;
|
|
446
|
+
output.push({
|
|
447
|
+
id: readStringFromKeys(item, ["id", "name", "key"]) ?? `sq-${index + 1}`,
|
|
448
|
+
question,
|
|
449
|
+
rationale: readStringFromKeys(item, ["rationale", "reason"]),
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
return output;
|
|
453
|
+
};
|
|
454
|
+
const defaultPlannerTools = (classifier, policyCompilation) => {
|
|
455
|
+
if (!classifier.needsDocdex &&
|
|
456
|
+
!classifier.needsAppTools &&
|
|
457
|
+
!classifier.needsFreshData &&
|
|
458
|
+
!classifier.needsPrivateData) {
|
|
459
|
+
return [];
|
|
460
|
+
}
|
|
461
|
+
return allowedToolNames(policyCompilation);
|
|
462
|
+
};
|
|
463
|
+
const defaultWorkerRole = (toolsAllowed, classifier) => {
|
|
464
|
+
if (classifier.needsImageWorker)
|
|
465
|
+
return "image_worker";
|
|
466
|
+
if (toolsAllowed.some((tool) => tool !== "docdex_search" && !tool.startsWith("docdex_"))) {
|
|
467
|
+
return "tool_worker";
|
|
468
|
+
}
|
|
469
|
+
if (toolsAllowed.length > 0 || classifier.needsDocdex) {
|
|
470
|
+
return "rag_worker";
|
|
471
|
+
}
|
|
472
|
+
return "direct_answer";
|
|
473
|
+
};
|
|
474
|
+
const normalizePlannerWorkerTask = (item, index, request, classifier, policyCompilation) => {
|
|
475
|
+
const fallbackTools = defaultPlannerTools(classifier, policyCompilation);
|
|
476
|
+
if (typeof item === "string" && item.trim()) {
|
|
477
|
+
return {
|
|
478
|
+
id: `task-${index + 1}`,
|
|
479
|
+
workerRole: defaultWorkerRole(fallbackTools, classifier),
|
|
480
|
+
objective: item.trim(),
|
|
481
|
+
query: request.query,
|
|
482
|
+
toolsAllowed: fallbackTools,
|
|
483
|
+
outputFormat: fallbackTools.length > 0 ? "evidence_items" : "answer_outline",
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
if (!isRecord(item))
|
|
487
|
+
return undefined;
|
|
488
|
+
const toolsAllowed = stringListFromValue(readAliasValue(item, [
|
|
489
|
+
"toolsAllowed",
|
|
490
|
+
"tools_allowed",
|
|
491
|
+
"allowedTools",
|
|
492
|
+
"allowed_tools",
|
|
493
|
+
"tools",
|
|
494
|
+
"toolNames",
|
|
495
|
+
"tool_names",
|
|
496
|
+
"tool",
|
|
497
|
+
])) ?? fallbackTools;
|
|
498
|
+
const query = readStringFromKeys(item, [
|
|
499
|
+
"query",
|
|
500
|
+
"searchQuery",
|
|
501
|
+
"search_query",
|
|
502
|
+
"question",
|
|
503
|
+
]);
|
|
504
|
+
const objective = readStringFromKeys(item, [
|
|
505
|
+
"objective",
|
|
506
|
+
"task",
|
|
507
|
+
"description",
|
|
508
|
+
"instruction",
|
|
509
|
+
"question",
|
|
510
|
+
"query",
|
|
511
|
+
]) ?? request.query;
|
|
512
|
+
const task = {
|
|
513
|
+
id: readStringFromKeys(item, ["id", "name", "key"]) ?? `task-${index + 1}`,
|
|
514
|
+
workerRole: readStringFromKeys(item, ["workerRole", "worker_role", "worker", "role"]) ??
|
|
515
|
+
defaultWorkerRole(toolsAllowed, classifier),
|
|
516
|
+
objective,
|
|
517
|
+
toolsAllowed,
|
|
518
|
+
outputFormat: readStringFromKeys(item, ["outputFormat", "output_format", "format", "expectedOutput"]) ??
|
|
519
|
+
(toolsAllowed.length > 0 ? "evidence_items" : "answer_outline"),
|
|
520
|
+
};
|
|
521
|
+
if (query) {
|
|
522
|
+
task.query = query;
|
|
523
|
+
}
|
|
524
|
+
const expectedSources = stringListFromValue(readAliasValue(item, ["expectedSources", "expected_sources", "sources", "sourceTypes"]));
|
|
525
|
+
if (expectedSources) {
|
|
526
|
+
task.expectedSources = expectedSources;
|
|
527
|
+
}
|
|
528
|
+
const constraints = stringListFromValue(readAliasValue(item, ["constraints"]));
|
|
529
|
+
if (constraints) {
|
|
530
|
+
task.constraints = constraints;
|
|
531
|
+
}
|
|
532
|
+
const metadata = isRecord(item.metadata) ? item.metadata : undefined;
|
|
533
|
+
if (metadata) {
|
|
534
|
+
task.metadata = metadata;
|
|
535
|
+
}
|
|
536
|
+
return task;
|
|
537
|
+
};
|
|
538
|
+
const normalizePlannerWorkerTasks = (record, request, classifier, policyCompilation) => {
|
|
539
|
+
const input = readAliasValue(record, [
|
|
540
|
+
"workerTasks",
|
|
541
|
+
"worker_tasks",
|
|
542
|
+
"tasks",
|
|
543
|
+
"steps",
|
|
544
|
+
"workers",
|
|
545
|
+
"toolTasks",
|
|
546
|
+
"tool_tasks",
|
|
547
|
+
]);
|
|
548
|
+
const rawTasks = Array.isArray(input) ? input : [];
|
|
549
|
+
const tasks = rawTasks
|
|
550
|
+
.map((item, index) => normalizePlannerWorkerTask(item, index, request, classifier, policyCompilation))
|
|
551
|
+
.filter((task) => Boolean(task));
|
|
552
|
+
if (tasks.length > 0) {
|
|
553
|
+
return tasks;
|
|
554
|
+
}
|
|
555
|
+
const toolsAllowed = defaultPlannerTools(classifier, policyCompilation);
|
|
556
|
+
if (toolsAllowed.length === 0) {
|
|
557
|
+
return [];
|
|
558
|
+
}
|
|
559
|
+
return [
|
|
560
|
+
{
|
|
561
|
+
id: "task-1",
|
|
562
|
+
workerRole: defaultWorkerRole(toolsAllowed, classifier),
|
|
563
|
+
objective: "Gather relevant evidence for the user request.",
|
|
564
|
+
query: request.query,
|
|
565
|
+
toolsAllowed,
|
|
566
|
+
outputFormat: "evidence_items",
|
|
567
|
+
},
|
|
568
|
+
];
|
|
569
|
+
};
|
|
570
|
+
const normalizePlannerOutput = (value, input, classifier, policyCompilation) => {
|
|
571
|
+
const record = unwrapPlannerRecord(value);
|
|
572
|
+
if (!record)
|
|
573
|
+
return value;
|
|
574
|
+
const workerTasks = normalizePlannerWorkerTasks(record, input.request, classifier, policyCompilation);
|
|
575
|
+
const normalized = {
|
|
576
|
+
queryType: readStringFromKeys(record, ["queryType", "query_type", "intent", "type", "category"]) ??
|
|
577
|
+
classifier.queryType,
|
|
578
|
+
summary: readStringFromKeys(record, ["summary", "rationale", "reasoning"]),
|
|
579
|
+
subquestions: normalizePlannerSubquestions(record, input.request),
|
|
580
|
+
workerTasks,
|
|
581
|
+
expectedEvidenceCount: workerTasks.length > 0 ? Math.max(workerTasks.length, 1) : undefined,
|
|
582
|
+
maxIterations: Math.max(1, Math.min(input.request.policy.maxIterations, Math.max(workerTasks.length, 1))),
|
|
583
|
+
requiresFinalLargeModel: input.request.policy.requireFinalLargeModel,
|
|
584
|
+
metadata: isRecord(record.metadata) ? record.metadata : undefined,
|
|
585
|
+
};
|
|
586
|
+
return normalized;
|
|
587
|
+
};
|
|
274
588
|
const sanitizePlannerOutput = (planner, input) => {
|
|
275
589
|
const policy = input.policyCompilation ?? compileCodaliGatewayPolicy({ request: input.request });
|
|
276
590
|
const allowed = new Set(allowedToolNames(policy));
|
|
@@ -307,7 +621,7 @@ export class CodaliGatewayPlanner {
|
|
|
307
621
|
}
|
|
308
622
|
async classify(input) {
|
|
309
623
|
const messages = buildCodaliGatewayClassifierMessages(input);
|
|
310
|
-
const response = await this.generateValidated("classifier", messages, CLASSIFIER_RESPONSE_FORMAT, validateClassifierOutput);
|
|
624
|
+
const response = await this.generateValidated("classifier", messages, CLASSIFIER_RESPONSE_FORMAT, (value) => validateClassifierOutput(value, input, input.policyCompilation));
|
|
311
625
|
const warnings = [];
|
|
312
626
|
const classifier = { ...response.value };
|
|
313
627
|
if (classifier.needsImageWorker && input.request.policy.allowImageWorker !== true) {
|
|
@@ -324,7 +638,7 @@ export class CodaliGatewayPlanner {
|
|
|
324
638
|
const classifierResult = await this.classify({ ...input, policyCompilation });
|
|
325
639
|
const plannerMessages = buildCodaliGatewayPlannerMessages({ ...input, policyCompilation }, classifierResult.classifier);
|
|
326
640
|
const plannerResult = await this.generateValidated("planner", plannerMessages, PLANNER_RESPONSE_FORMAT, (value) => {
|
|
327
|
-
const validation = validateCodaliGatewayPlannerOutput(value);
|
|
641
|
+
const validation = validateCodaliGatewayPlannerOutput(normalizePlannerOutput(value, { ...input, policyCompilation }, classifierResult.classifier, policyCompilation));
|
|
328
642
|
return validation.ok
|
|
329
643
|
? { output: validation.value, issues: [] }
|
|
330
644
|
: { issues: validation.issues };
|
|
@@ -156,6 +156,7 @@ export declare class CodaliGatewayStateMachine {
|
|
|
156
156
|
private resolveVerificationStopReason;
|
|
157
157
|
private buildVerificationLoopResult;
|
|
158
158
|
private prepareTasks;
|
|
159
|
+
private dispatchAssignedAppGatewayTools;
|
|
159
160
|
private runTask;
|
|
160
161
|
private persistWorkerResult;
|
|
161
162
|
private skipTask;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatewayStateMachine.d.ts","sourceRoot":"","sources":["../../src/gateway/GatewayStateMachine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,8BAA8B,EAC9B,0BAA0B,EAC1B,oBAAoB,EACpB,0BAA0B,EAC1B,2BAA2B,EAC3B,uBAAuB,EACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EACnC,MAAM,yBAAyB,CAAC;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