@valerypopoff/rivet2-core 2.22.1 → 2.24.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/dist/cjs/bundle.cjs +1166 -797
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/webAppRuntime.cjs +4 -1
- package/dist/cjs/webAppRuntime.cjs.map +2 -2
- package/dist/esm/exports.js +0 -1
- package/dist/esm/index.js +3 -0
- package/dist/esm/integrations/CodeRunner.js +6 -3
- package/dist/esm/integrations/CodeRunnerNamespace.js +10 -0
- package/dist/esm/model/AgentResponseTracePresentation.js +5 -1
- package/dist/esm/model/ChildInvocationOwnership.js +51 -0
- package/dist/esm/model/GraphProcessor.js +32 -54
- package/dist/esm/model/NodeRegistration.js +2 -6
- package/dist/esm/model/classifier/baseten.js +78 -0
- package/dist/esm/model/classifier/credentials.js +17 -9
- package/dist/esm/model/classifier/images.js +4 -4
- package/dist/esm/model/classifier/jev.js +45 -0
- package/dist/esm/model/classifier/json.js +1 -1
- package/dist/esm/model/classifier/limits.js +13 -13
- package/dist/esm/model/classifier/openai.js +20 -2
- package/dist/esm/model/classifier/preparation.js +5 -5
- package/dist/esm/model/classifier/profile.js +14 -13
- package/dist/esm/model/classifier/profileExecution.js +26 -23
- package/dist/esm/model/classifier/providers.js +170 -74
- package/dist/esm/model/classifier/questionHelpers.js +21 -2
- package/dist/esm/model/classifier/questions.js +37 -7
- package/dist/esm/model/classifier/response.js +8 -2
- package/dist/esm/model/classifier/state.js +2 -2
- package/dist/esm/model/classifier/subq.js +51 -0
- package/dist/esm/model/nodes/ClassifierEvaluateNode.js +32 -61
- package/dist/esm/model/nodes/ClassifierProfileNode.js +9 -9
- package/dist/esm/model/nodes/ClassifierQuestionNode.js +53 -34
- package/dist/types/index.d.ts +1 -1
- package/dist/types/integrations/CodeRunner.d.ts +4 -1
- package/dist/types/integrations/CodeRunnerNamespace.d.ts +5 -0
- package/dist/types/model/AgentResponseTracePresentation.d.ts +2 -0
- package/dist/types/model/ChildInvocationOwnership.d.ts +36 -0
- package/dist/types/model/classifier/baseten.d.ts +8 -0
- package/dist/types/model/classifier/credentials.d.ts +2 -0
- package/dist/types/model/classifier/jev.d.ts +9 -0
- package/dist/types/model/classifier/profileExecution.d.ts +1 -1
- package/dist/types/model/classifier/providers.d.ts +26 -5
- package/dist/types/model/classifier/questionHelpers.d.ts +3 -1
- package/dist/types/model/classifier/questions.d.ts +2 -1
- package/dist/types/model/classifier/state.d.ts +1 -0
- package/dist/types/model/classifier/subq.d.ts +8 -0
- package/dist/types/model/classifier/types.d.ts +9 -2
- package/dist/types/model/nodes/ClassifierEvaluateNode.d.ts +2 -4
- package/dist/types/model/nodes/ClassifierQuestionNode.d.ts +2 -2
- package/package.json +2 -2
package/dist/cjs/bundle.cjs
CHANGED
|
@@ -42,6 +42,8 @@ __export(src_exports, {
|
|
|
42
42
|
AssembleMessageNodeImpl: () => AssembleMessageNodeImpl,
|
|
43
43
|
AssemblePromptNodeImpl: () => AssemblePromptNodeImpl,
|
|
44
44
|
AudioNodeImpl: () => AudioNodeImpl,
|
|
45
|
+
BASETEN_DECISIONS_ENDPOINT: () => BASETEN_DECISIONS_ENDPOINT,
|
|
46
|
+
BASETEN_DEFAULT_CREDENTIAL_NAMES: () => BASETEN_DEFAULT_CREDENTIAL_NAMES,
|
|
45
47
|
BooleanNodeImpl: () => BooleanNodeImpl,
|
|
46
48
|
BrowserNativeApi: () => BrowserNativeApi,
|
|
47
49
|
BuildKnowledgeContextNodeImpl: () => BuildKnowledgeContextNodeImpl,
|
|
@@ -211,6 +213,8 @@ __export(src_exports, {
|
|
|
211
213
|
RivetLLMProfileHealthPolicyError: () => RivetLLMProfileHealthPolicyError,
|
|
212
214
|
RivetStoredValueController: () => RivetStoredValueController,
|
|
213
215
|
STREAM_RESPONSE_HELPER_MESSAGE: () => STREAM_RESPONSE_HELPER_MESSAGE,
|
|
216
|
+
SUBQ_DECISIONS_ENDPOINT: () => SUBQ_DECISIONS_ENDPOINT,
|
|
217
|
+
SUBQ_DEFAULT_CREDENTIAL_NAMES: () => SUBQ_DEFAULT_CREDENTIAL_NAMES,
|
|
214
218
|
SearchKnowledgeNodeImpl: () => SearchKnowledgeNodeImpl,
|
|
215
219
|
SetGlobalNodeImpl: () => SetGlobalNodeImpl,
|
|
216
220
|
SetStoredValueNodeImpl: () => SetStoredValueNodeImpl,
|
|
@@ -262,6 +266,7 @@ __export(src_exports, {
|
|
|
262
266
|
autoevalsPlugin: () => autoevals_default,
|
|
263
267
|
base64ToUint8Array: () => base64ToUint8Array,
|
|
264
268
|
baseDirs: () => baseDirs,
|
|
269
|
+
basetenClassifierProvider: () => basetenClassifierProvider,
|
|
265
270
|
booleanNode: () => booleanNode,
|
|
266
271
|
buildAgentProfileAttemptInspectorRows: () => buildAgentProfileAttemptInspectorRows,
|
|
267
272
|
buildAgentResponseTrace: () => buildAgentResponseTrace,
|
|
@@ -469,6 +474,7 @@ __export(src_exports, {
|
|
|
469
474
|
getProcessorEvents: () => getProcessorEvents,
|
|
470
475
|
getProcessorSSEStream: () => getProcessorSSEStream,
|
|
471
476
|
getProfileAttemptOmissionNotice: () => getProfileAttemptOmissionNotice,
|
|
477
|
+
getProfileDisplayName: () => getProfileDisplayName,
|
|
472
478
|
getProjectConnectionComparisonKey: () => getProjectConnectionComparisonKey,
|
|
473
479
|
getProjectGlobalVariableIds: () => getProjectGlobalVariableIds,
|
|
474
480
|
getProjectNodeFieldComparisons: () => getProjectNodeFieldComparisons,
|
|
@@ -770,6 +776,7 @@ __export(src_exports, {
|
|
|
770
776
|
stringifyToolResult: () => stringifyToolResult,
|
|
771
777
|
stringifyUiGraphValue: () => stringifyUiGraphValue,
|
|
772
778
|
subGraphNode: () => subGraphNode,
|
|
779
|
+
subqClassifierProvider: () => subqClassifierProvider,
|
|
773
780
|
summarizeAgentResponseCalls: () => summarizeAgentResponseCalls,
|
|
774
781
|
summarizeChatV2RequestPlan: () => summarizeChatV2RequestPlan,
|
|
775
782
|
summarizeDataValueForLog: () => summarizeDataValueForLog,
|
|
@@ -824,6 +831,8 @@ __export(exports_exports, {
|
|
|
824
831
|
AssembleMessageNodeImpl: () => AssembleMessageNodeImpl,
|
|
825
832
|
AssemblePromptNodeImpl: () => AssemblePromptNodeImpl,
|
|
826
833
|
AudioNodeImpl: () => AudioNodeImpl,
|
|
834
|
+
BASETEN_DECISIONS_ENDPOINT: () => BASETEN_DECISIONS_ENDPOINT,
|
|
835
|
+
BASETEN_DEFAULT_CREDENTIAL_NAMES: () => BASETEN_DEFAULT_CREDENTIAL_NAMES,
|
|
827
836
|
BooleanNodeImpl: () => BooleanNodeImpl,
|
|
828
837
|
BrowserNativeApi: () => BrowserNativeApi,
|
|
829
838
|
BuildKnowledgeContextNodeImpl: () => BuildKnowledgeContextNodeImpl,
|
|
@@ -992,6 +1001,8 @@ __export(exports_exports, {
|
|
|
992
1001
|
RivetLLMProfileHealthPolicyError: () => RivetLLMProfileHealthPolicyError,
|
|
993
1002
|
RivetStoredValueController: () => RivetStoredValueController,
|
|
994
1003
|
STREAM_RESPONSE_HELPER_MESSAGE: () => STREAM_RESPONSE_HELPER_MESSAGE,
|
|
1004
|
+
SUBQ_DECISIONS_ENDPOINT: () => SUBQ_DECISIONS_ENDPOINT,
|
|
1005
|
+
SUBQ_DEFAULT_CREDENTIAL_NAMES: () => SUBQ_DEFAULT_CREDENTIAL_NAMES,
|
|
995
1006
|
SearchKnowledgeNodeImpl: () => SearchKnowledgeNodeImpl,
|
|
996
1007
|
SetGlobalNodeImpl: () => SetGlobalNodeImpl,
|
|
997
1008
|
SetStoredValueNodeImpl: () => SetStoredValueNodeImpl,
|
|
@@ -1043,6 +1054,7 @@ __export(exports_exports, {
|
|
|
1043
1054
|
autoevalsPlugin: () => autoevals_default,
|
|
1044
1055
|
base64ToUint8Array: () => base64ToUint8Array,
|
|
1045
1056
|
baseDirs: () => baseDirs,
|
|
1057
|
+
basetenClassifierProvider: () => basetenClassifierProvider,
|
|
1046
1058
|
booleanNode: () => booleanNode,
|
|
1047
1059
|
buildAgentProfileAttemptInspectorRows: () => buildAgentProfileAttemptInspectorRows,
|
|
1048
1060
|
buildAgentResponseTrace: () => buildAgentResponseTrace,
|
|
@@ -1250,6 +1262,7 @@ __export(exports_exports, {
|
|
|
1250
1262
|
getProcessorEvents: () => getProcessorEvents,
|
|
1251
1263
|
getProcessorSSEStream: () => getProcessorSSEStream,
|
|
1252
1264
|
getProfileAttemptOmissionNotice: () => getProfileAttemptOmissionNotice,
|
|
1265
|
+
getProfileDisplayName: () => getProfileDisplayName,
|
|
1253
1266
|
getProjectConnectionComparisonKey: () => getProjectConnectionComparisonKey,
|
|
1254
1267
|
getProjectGlobalVariableIds: () => getProjectGlobalVariableIds,
|
|
1255
1268
|
getProjectNodeFieldComparisons: () => getProjectNodeFieldComparisons,
|
|
@@ -1551,6 +1564,7 @@ __export(exports_exports, {
|
|
|
1551
1564
|
stringifyToolResult: () => stringifyToolResult,
|
|
1552
1565
|
stringifyUiGraphValue: () => stringifyUiGraphValue,
|
|
1553
1566
|
subGraphNode: () => subGraphNode,
|
|
1567
|
+
subqClassifierProvider: () => subqClassifierProvider,
|
|
1554
1568
|
summarizeAgentResponseCalls: () => summarizeAgentResponseCalls,
|
|
1555
1569
|
summarizeChatV2RequestPlan: () => summarizeChatV2RequestPlan,
|
|
1556
1570
|
summarizeDataValueForLog: () => summarizeDataValueForLog,
|
|
@@ -5330,11 +5344,11 @@ var import_lodash_es2 = require("lodash");
|
|
|
5330
5344
|
// src/model/chat-v2/llmChatV2NodeMigration.ts
|
|
5331
5345
|
function normalizeSerializedLLMTemperatureData(nodeType, data) {
|
|
5332
5346
|
if (!["llmChatV2", "llmProfile"].includes(nodeType) || data == null || typeof data !== "object") return data;
|
|
5333
|
-
const
|
|
5334
|
-
if (!Object.hasOwn(
|
|
5335
|
-
if (
|
|
5347
|
+
const record4 = data;
|
|
5348
|
+
if (!Object.hasOwn(record4, "temperature")) return data;
|
|
5349
|
+
if (record4.temperature != null && !(typeof record4.temperature === "number" && Number.isNaN(record4.temperature)))
|
|
5336
5350
|
return data;
|
|
5337
|
-
const copy = { ...
|
|
5351
|
+
const copy = { ...record4 };
|
|
5338
5352
|
delete copy.temperature;
|
|
5339
5353
|
return copy;
|
|
5340
5354
|
}
|
|
@@ -5369,9 +5383,6 @@ function keys(o) {
|
|
|
5369
5383
|
function values(o) {
|
|
5370
5384
|
return Object.values(o);
|
|
5371
5385
|
}
|
|
5372
|
-
function mapValues2(o, fn) {
|
|
5373
|
-
return Object.fromEntries(Object.entries(o).map(([key, value]) => [key, fn(value)]));
|
|
5374
|
-
}
|
|
5375
5386
|
|
|
5376
5387
|
// src/model/NodeGraph.ts
|
|
5377
5388
|
var import_non_secure3 = require("nanoid/non-secure");
|
|
@@ -6853,6 +6864,57 @@ var GraphSharedExecutionState = class _GraphSharedExecutionState {
|
|
|
6853
6864
|
}
|
|
6854
6865
|
};
|
|
6855
6866
|
|
|
6867
|
+
// src/model/ChildInvocationOwnership.ts
|
|
6868
|
+
function resolveChildInvocationOwnership(mode, context) {
|
|
6869
|
+
const { run } = context;
|
|
6870
|
+
switch (mode.kind) {
|
|
6871
|
+
case "continuation":
|
|
6872
|
+
return {
|
|
6873
|
+
parent: context.parent,
|
|
6874
|
+
abortOwner: context.abortOwner,
|
|
6875
|
+
sameGraphOwner: context.sameGraphOwner,
|
|
6876
|
+
suppressPartialOutputs: false,
|
|
6877
|
+
suppressLifecycle: true,
|
|
6878
|
+
state: {
|
|
6879
|
+
attachedNodeData: run.attachedNodeData,
|
|
6880
|
+
graphInputNodeValues: run.graphInputNodeValues,
|
|
6881
|
+
graphOutputs: mode.graphOutputs
|
|
6882
|
+
},
|
|
6883
|
+
identity: { rootRunId: run.rootRunId, graphRunId: run.graphRunId, parentGraphRunId: run.parentGraphRunId }
|
|
6884
|
+
};
|
|
6885
|
+
case "async":
|
|
6886
|
+
return {
|
|
6887
|
+
parent: context.sameGraphOwner,
|
|
6888
|
+
abortOwner: context.root,
|
|
6889
|
+
suppressPartialOutputs: true,
|
|
6890
|
+
suppressLifecycle: context.rootGraphOrigin,
|
|
6891
|
+
state: {
|
|
6892
|
+
attachedNodeData: run.attachedNodeData,
|
|
6893
|
+
graphInputNodeValues: run.graphInputNodeValues,
|
|
6894
|
+
graphOutputs: {}
|
|
6895
|
+
},
|
|
6896
|
+
identity: context.rootGraphOrigin ? { rootRunId: run.rootRunId, graphRunId: run.graphRunId, parentGraphRunId: run.parentGraphRunId } : {
|
|
6897
|
+
rootRunId: context.rootIdentity.rootRunId,
|
|
6898
|
+
graphRunId: context.newGraphRunId(),
|
|
6899
|
+
parentGraphRunId: context.sameGraphIdentity.graphRunId
|
|
6900
|
+
}
|
|
6901
|
+
};
|
|
6902
|
+
case "watch":
|
|
6903
|
+
return {
|
|
6904
|
+
parent: context.parent,
|
|
6905
|
+
abortOwner: context.root,
|
|
6906
|
+
suppressPartialOutputs: true,
|
|
6907
|
+
suppressLifecycle: true,
|
|
6908
|
+
state: { attachedNodeData: /* @__PURE__ */ new Map(), graphInputNodeValues: { ...run.graphInputNodeValues }, graphOutputs: {} },
|
|
6909
|
+
identity: {
|
|
6910
|
+
rootRunId: context.rootIdentity.rootRunId,
|
|
6911
|
+
graphRunId: mode.graphRunId,
|
|
6912
|
+
parentGraphRunId: run.graphRunId
|
|
6913
|
+
}
|
|
6914
|
+
};
|
|
6915
|
+
}
|
|
6916
|
+
}
|
|
6917
|
+
|
|
6856
6918
|
// src/model/SchedulerBoundaryPlanner.ts
|
|
6857
6919
|
function indexConnections(connections) {
|
|
6858
6920
|
const outgoingByNodeId = /* @__PURE__ */ new Map();
|
|
@@ -9851,8 +9913,8 @@ function normalizeRivetStoredValueKey(value) {
|
|
|
9851
9913
|
}
|
|
9852
9914
|
return value;
|
|
9853
9915
|
}
|
|
9854
|
-
function setStoredValueRecordEntry(
|
|
9855
|
-
Object.defineProperty(
|
|
9916
|
+
function setStoredValueRecordEntry(record4, key, value) {
|
|
9917
|
+
Object.defineProperty(record4, key, { configurable: true, enumerable: true, value, writable: true });
|
|
9856
9918
|
}
|
|
9857
9919
|
function cloneRivetStoredValue(value, label = "Stored value") {
|
|
9858
9920
|
return clonePortableValue(value, label, /* @__PURE__ */ new Set());
|
|
@@ -10078,8 +10140,8 @@ function buildDelegatedToolCallOutputs(records, preToolMessage, cost, costBreakd
|
|
|
10078
10140
|
type: "string",
|
|
10079
10141
|
value: preToolMessage
|
|
10080
10142
|
};
|
|
10081
|
-
const executionTimesSeconds = records.map((
|
|
10082
|
-
const executionTimeMs = getExecutionTimeMs(
|
|
10143
|
+
const executionTimesSeconds = records.map((record4) => {
|
|
10144
|
+
const executionTimeMs = getExecutionTimeMs(record4);
|
|
10083
10145
|
return executionTimeMs == null ? void 0 : executionTimeMs / 1e3;
|
|
10084
10146
|
});
|
|
10085
10147
|
const executionTimeOutput = executionTimesSeconds.every((executionTimeSeconds) => executionTimeSeconds != null) ? records.length === 1 ? {
|
|
@@ -10114,21 +10176,21 @@ function buildDelegatedToolCallOutputs(records, preToolMessage, cost, costBreakd
|
|
|
10114
10176
|
} : {
|
|
10115
10177
|
["tool-name"]: {
|
|
10116
10178
|
type: "string[]",
|
|
10117
|
-
value: records.map((
|
|
10179
|
+
value: records.map((record4) => record4.name)
|
|
10118
10180
|
},
|
|
10119
10181
|
["tool-arguments"]: {
|
|
10120
10182
|
type: "object[]",
|
|
10121
|
-
value: records.map((
|
|
10183
|
+
value: records.map((record4) => record4.arguments)
|
|
10122
10184
|
},
|
|
10123
10185
|
["assistant-message"]: preToolMessageOutput,
|
|
10124
10186
|
["output"]: {
|
|
10125
10187
|
type: "string[]",
|
|
10126
|
-
value: records.map((
|
|
10188
|
+
value: records.map((record4) => record4.output)
|
|
10127
10189
|
},
|
|
10128
10190
|
["execution-time"]: executionTimeOutput,
|
|
10129
10191
|
["message"]: {
|
|
10130
10192
|
type: "chat-message[]",
|
|
10131
|
-
value: records.map((
|
|
10193
|
+
value: records.map((record4) => record4.message)
|
|
10132
10194
|
}
|
|
10133
10195
|
};
|
|
10134
10196
|
if (cost != null) {
|
|
@@ -10307,8 +10369,8 @@ function getCurrentTimeMs() {
|
|
|
10307
10369
|
var _a, _b;
|
|
10308
10370
|
return ((_b = (_a = globalThis.performance) == null ? void 0 : _a.now) == null ? void 0 : _b.call(_a)) ?? Date.now();
|
|
10309
10371
|
}
|
|
10310
|
-
function getExecutionTimeMs(
|
|
10311
|
-
const { executionTimeMs } =
|
|
10372
|
+
function getExecutionTimeMs(record4) {
|
|
10373
|
+
const { executionTimeMs } = record4;
|
|
10312
10374
|
return typeof executionTimeMs === "number" && Number.isFinite(executionTimeMs) && executionTimeMs >= 0 ? executionTimeMs : void 0;
|
|
10313
10375
|
}
|
|
10314
10376
|
|
|
@@ -13512,6 +13574,20 @@ function resolveCodeInterpolationExpression(inputs, expression, graphInputValues
|
|
|
13512
13574
|
});
|
|
13513
13575
|
}
|
|
13514
13576
|
|
|
13577
|
+
// src/integrations/CodeRunnerNamespace.ts
|
|
13578
|
+
var namespace;
|
|
13579
|
+
function installCodeRunnerNamespace(value) {
|
|
13580
|
+
namespace = value;
|
|
13581
|
+
}
|
|
13582
|
+
function getCodeRunnerNamespace() {
|
|
13583
|
+
if (!namespace) {
|
|
13584
|
+
throw new Error(
|
|
13585
|
+
"The Rivet code namespace is unavailable. Import the public core entrypoint or supply a code runner."
|
|
13586
|
+
);
|
|
13587
|
+
}
|
|
13588
|
+
return namespace;
|
|
13589
|
+
}
|
|
13590
|
+
|
|
13515
13591
|
// src/integrations/CodeRunnerOptions.ts
|
|
13516
13592
|
var ALL_CODE_RUNNER_OPTIONS = Object.freeze({
|
|
13517
13593
|
includeRequire: true,
|
|
@@ -13523,6 +13599,9 @@ var ALL_CODE_RUNNER_OPTIONS = Object.freeze({
|
|
|
13523
13599
|
|
|
13524
13600
|
// src/integrations/CodeRunner.ts
|
|
13525
13601
|
var IsomorphicCodeRunner = class {
|
|
13602
|
+
constructor(resolveNamespace = getCodeRunnerNamespace) {
|
|
13603
|
+
this.resolveNamespace = resolveNamespace;
|
|
13604
|
+
}
|
|
13526
13605
|
async runCode(code, inputs, options2, graphInputs, contextValues, globalValues) {
|
|
13527
13606
|
const argNames = ["inputs"];
|
|
13528
13607
|
const args = [inputs];
|
|
@@ -13536,7 +13615,7 @@ var IsomorphicCodeRunner = class {
|
|
|
13536
13615
|
}
|
|
13537
13616
|
if (options2.includeRivet) {
|
|
13538
13617
|
argNames.push("Rivet");
|
|
13539
|
-
args.push(
|
|
13618
|
+
args.push(this.resolveNamespace());
|
|
13540
13619
|
}
|
|
13541
13620
|
if (graphInputs) {
|
|
13542
13621
|
argNames.push("graphInputs");
|
|
@@ -15291,7 +15370,6 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
15291
15370
|
var _a, _b;
|
|
15292
15371
|
const root = this.getRootProcessor();
|
|
15293
15372
|
const sameGraphOwner = this.#sameGraphRunOwnerOverride ?? this;
|
|
15294
|
-
const isRootGraphOrigin = !sameGraphOwner.#isSubProcessor;
|
|
15295
15373
|
if (root.#run.abortController.signal.aborted) {
|
|
15296
15374
|
throw createGraphAbortErrorFromSignal(root.#run.abortController.signal, "Async branch aborted before it started");
|
|
15297
15375
|
}
|
|
@@ -15308,29 +15386,8 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
15308
15386
|
),
|
|
15309
15387
|
onCreated: onProcessorCreated
|
|
15310
15388
|
});
|
|
15311
|
-
processor.#parent = sameGraphOwner;
|
|
15312
|
-
processor.#abortOwnerOverride = root;
|
|
15313
|
-
processor.#suppressGraphPartialOutputs = true;
|
|
15314
|
-
processor.#suppressGraphLifecycleEvents = isRootGraphOrigin;
|
|
15315
|
-
processor.#sharedRunStateOverride = {
|
|
15316
|
-
attachedNodeData: this.#run.attachedNodeData,
|
|
15317
|
-
graphInputNodeValues: this.#run.graphInputNodeValues,
|
|
15318
|
-
// Async branches cannot contain Graph Output nodes. Keep their synthetic
|
|
15319
|
-
// boundary outputs private so branch finalization cannot seed the root's
|
|
15320
|
-
// derived cost output before the root has accumulated every path.
|
|
15321
|
-
graphOutputs: {}
|
|
15322
|
-
};
|
|
15323
15389
|
const branchRunToNodeIds = (_b = this.runToNodeIds) == null ? void 0 : _b.filter((nodeId) => plan.nodeIds.has(nodeId));
|
|
15324
15390
|
processor.runToNodeIds = (branchRunToNodeIds == null ? void 0 : branchRunToNodeIds.length) ? branchRunToNodeIds : void 0;
|
|
15325
|
-
processor.#executionIdentityOverride = isRootGraphOrigin ? {
|
|
15326
|
-
rootRunId: this.#run.rootRunId,
|
|
15327
|
-
graphRunId: this.#run.graphRunId,
|
|
15328
|
-
parentGraphRunId: this.#run.parentGraphRunId
|
|
15329
|
-
} : {
|
|
15330
|
-
rootRunId: root.#run.rootRunId,
|
|
15331
|
-
graphRunId: (0, import_non_secure12.nanoid)(),
|
|
15332
|
-
parentGraphRunId: sameGraphOwner.#run.graphRunId
|
|
15333
|
-
};
|
|
15334
15391
|
processor.preloadNodeData(triggerNode.id, triggerOutputs);
|
|
15335
15392
|
processor.#suppressedPreloadedNodeIds.add(triggerNode.id);
|
|
15336
15393
|
const unwireEvents = this.#wireChildEvents(processor, root, {
|
|
@@ -16086,23 +16143,14 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
16086
16143
|
throw new Error("Cannot execute a tool continuation branch because the current graph has no ID.");
|
|
16087
16144
|
}
|
|
16088
16145
|
const branchGraphOutputs = createGraphOutputsOverlay(this.#run.graphOutputs);
|
|
16089
|
-
const processor = this.#constructChildInvocation({
|
|
16090
|
-
|
|
16091
|
-
|
|
16092
|
-
processor.#suppressGraphLifecycleEvents = true;
|
|
16093
|
-
processor.#sharedRunStateOverride = {
|
|
16094
|
-
attachedNodeData: this.#run.attachedNodeData,
|
|
16095
|
-
graphInputNodeValues: this.#run.graphInputNodeValues,
|
|
16146
|
+
const processor = this.#constructChildInvocation({
|
|
16147
|
+
kind: "continuation",
|
|
16148
|
+
graph: branchPlan.graph,
|
|
16096
16149
|
graphOutputs: branchGraphOutputs.view
|
|
16097
|
-
};
|
|
16150
|
+
});
|
|
16098
16151
|
const branchNodeIds = new Set(branchPlan.graph.nodes.map((node) => node.id));
|
|
16099
16152
|
const branchRunToNodeIds = (_b = this.runToNodeIds) == null ? void 0 : _b.filter((nodeId) => branchNodeIds.has(nodeId));
|
|
16100
16153
|
processor.runToNodeIds = (branchRunToNodeIds == null ? void 0 : branchRunToNodeIds.length) ? branchRunToNodeIds : void 0;
|
|
16101
|
-
processor.#executionIdentityOverride = {
|
|
16102
|
-
rootRunId: this.#run.rootRunId,
|
|
16103
|
-
graphRunId: this.#run.graphRunId,
|
|
16104
|
-
parentGraphRunId: this.#run.parentGraphRunId
|
|
16105
|
-
};
|
|
16106
16154
|
for (const [nodeId, outputs] of branchPlan.preloadedOutputs) {
|
|
16107
16155
|
processor.preloadNodeData(nodeId, outputs);
|
|
16108
16156
|
processor.#suppressedPreloadedNodeIds.add(nodeId);
|
|
@@ -16749,22 +16797,9 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
16749
16797
|
processor = this.#constructChildInvocation({
|
|
16750
16798
|
kind: "watch",
|
|
16751
16799
|
graph: plan.graph,
|
|
16752
|
-
watchNodeId: plan.watchNode.id
|
|
16753
|
-
|
|
16754
|
-
|
|
16755
|
-
processor.#suppressGraphPartialOutputs = true;
|
|
16756
|
-
processor.#suppressGraphLifecycleEvents = true;
|
|
16757
|
-
processor.#sharedRunStateOverride = {
|
|
16758
|
-
// Repeated node IDs do not imply shared race/loop state between snapshots.
|
|
16759
|
-
attachedNodeData: /* @__PURE__ */ new Map(),
|
|
16760
|
-
graphInputNodeValues: { ...this.#run.graphInputNodeValues },
|
|
16761
|
-
graphOutputs: {}
|
|
16762
|
-
};
|
|
16763
|
-
processor.#executionIdentityOverride = {
|
|
16764
|
-
rootRunId: root.#run.rootRunId,
|
|
16765
|
-
graphRunId: historyIteration.graphRunId,
|
|
16766
|
-
parentGraphRunId: this.#run.graphRunId
|
|
16767
|
-
};
|
|
16800
|
+
watchNodeId: plan.watchNode.id,
|
|
16801
|
+
graphRunId: historyIteration.graphRunId
|
|
16802
|
+
});
|
|
16768
16803
|
processor.#streamingWatchInvocation = {
|
|
16769
16804
|
plan,
|
|
16770
16805
|
historyIteration,
|
|
@@ -17108,8 +17143,8 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
17108
17143
|
execution: parentExecution
|
|
17109
17144
|
});
|
|
17110
17145
|
}
|
|
17111
|
-
/**
|
|
17112
|
-
*
|
|
17146
|
+
/** One construction boundary applies the discriminated ownership contract;
|
|
17147
|
+
* scheduling and terminal commits remain with their respective branch owner. */
|
|
17113
17148
|
#constructChildInvocation(invocation) {
|
|
17114
17149
|
const ordinary = invocation.kind === "subgraph";
|
|
17115
17150
|
const processor = new _GraphProcessor(
|
|
@@ -17148,6 +17183,27 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
|
|
|
17148
17183
|
processor.#graphCallPath = this.#graphCallPath;
|
|
17149
17184
|
processor.#frozenNodeOutputResolver = this.#frozenNodeOutputResolver;
|
|
17150
17185
|
processor.#executor = this.#executor;
|
|
17186
|
+
if (!ordinary) {
|
|
17187
|
+
const sameGraphOwner = this.#sameGraphRunOwnerOverride ?? this;
|
|
17188
|
+
const ownership = resolveChildInvocationOwnership(invocation, {
|
|
17189
|
+
parent: this,
|
|
17190
|
+
root: this.getRootProcessor(),
|
|
17191
|
+
abortOwner: this.#abortOwnerOverride ?? this,
|
|
17192
|
+
sameGraphOwner,
|
|
17193
|
+
rootGraphOrigin: !sameGraphOwner.#isSubProcessor,
|
|
17194
|
+
run: this.#run,
|
|
17195
|
+
rootIdentity: this.getRootProcessor().#run,
|
|
17196
|
+
sameGraphIdentity: sameGraphOwner.#run,
|
|
17197
|
+
newGraphRunId: () => (0, import_non_secure12.nanoid)()
|
|
17198
|
+
});
|
|
17199
|
+
processor.#parent = ownership.parent;
|
|
17200
|
+
processor.#abortOwnerOverride = ownership.abortOwner;
|
|
17201
|
+
processor.#sameGraphRunOwnerOverride = ownership.sameGraphOwner;
|
|
17202
|
+
processor.#suppressGraphPartialOutputs = ownership.suppressPartialOutputs;
|
|
17203
|
+
processor.#suppressGraphLifecycleEvents = ownership.suppressLifecycle;
|
|
17204
|
+
processor.#sharedRunStateOverride = ownership.state;
|
|
17205
|
+
processor.#executionIdentityOverride = ownership.identity;
|
|
17206
|
+
}
|
|
17151
17207
|
return processor;
|
|
17152
17208
|
}
|
|
17153
17209
|
#wireChildEvents(processor, owner, options2 = {}) {
|
|
@@ -21238,10 +21294,6 @@ var NodeRegistration = class {
|
|
|
21238
21294
|
get #dynamicImpls() {
|
|
21239
21295
|
return this.#implsMap;
|
|
21240
21296
|
}
|
|
21241
|
-
get #dynamicDisplayNames() {
|
|
21242
|
-
const displayNameMap = mapValues2(this.#infos, (info) => info.displayName);
|
|
21243
|
-
return displayNameMap;
|
|
21244
|
-
}
|
|
21245
21297
|
registerPlugin(plugin) {
|
|
21246
21298
|
if (plugin.register) {
|
|
21247
21299
|
plugin.register((definition) => this.registerPluginNode(definition, plugin));
|
|
@@ -21279,7 +21331,7 @@ var NodeRegistration = class {
|
|
|
21279
21331
|
return this.#getInfo(type).displayName;
|
|
21280
21332
|
}
|
|
21281
21333
|
getDynamicDisplayName(type) {
|
|
21282
|
-
const displayName = this.#
|
|
21334
|
+
const displayName = Object.hasOwn(this.#infos, type) ? this.#infos[type].displayName : void 0;
|
|
21283
21335
|
if (!displayName) {
|
|
21284
21336
|
throw new Error(`Unknown node type: ${type}`);
|
|
21285
21337
|
}
|
|
@@ -23647,10 +23699,10 @@ var import_ai_sdk_provider = require("@openrouter/ai-sdk-provider");
|
|
|
23647
23699
|
var import_ai = require("ai");
|
|
23648
23700
|
function normalizeEmbeddedError(error) {
|
|
23649
23701
|
if (error instanceof Error || error == null || typeof error !== "object" || Array.isArray(error)) return error;
|
|
23650
|
-
const
|
|
23651
|
-
if (typeof
|
|
23652
|
-
const normalized = new Error(
|
|
23653
|
-
const code = typeof
|
|
23702
|
+
const record4 = error;
|
|
23703
|
+
if (typeof record4.message !== "string") return error;
|
|
23704
|
+
const normalized = new Error(record4.message, { cause: error });
|
|
23705
|
+
const code = typeof record4.code === "string" && /^\d{3}$/.test(record4.code) ? Number(record4.code) : record4.code;
|
|
23654
23706
|
if (typeof code === "number" && Number.isInteger(code) && code >= 400 && code <= 599) {
|
|
23655
23707
|
return Object.assign(normalized, { name: "AI_APICallError", statusCode: code });
|
|
23656
23708
|
}
|
|
@@ -26665,9 +26717,9 @@ function isRecord8(value) {
|
|
|
26665
26717
|
return false;
|
|
26666
26718
|
}
|
|
26667
26719
|
}
|
|
26668
|
-
function getRecordProperty(
|
|
26720
|
+
function getRecordProperty(record4, key) {
|
|
26669
26721
|
try {
|
|
26670
|
-
return
|
|
26722
|
+
return record4[key];
|
|
26671
26723
|
} catch {
|
|
26672
26724
|
return void 0;
|
|
26673
26725
|
}
|
|
@@ -26793,8 +26845,8 @@ function coerceHttpStatusCode(value) {
|
|
|
26793
26845
|
}
|
|
26794
26846
|
return void 0;
|
|
26795
26847
|
}
|
|
26796
|
-
function getRecordStatusCode(
|
|
26797
|
-
return coerceHttpStatusCode(getRecordProperty(
|
|
26848
|
+
function getRecordStatusCode(record4) {
|
|
26849
|
+
return coerceHttpStatusCode(getRecordProperty(record4, "statusCode")) ?? coerceHttpStatusCode(getRecordProperty(record4, "status"));
|
|
26798
26850
|
}
|
|
26799
26851
|
function getChatV2ProviderErrorStatusCode(error, seen = /* @__PURE__ */ new Set()) {
|
|
26800
26852
|
if (!isRecord8(error)) {
|
|
@@ -27602,7 +27654,7 @@ async function runChatV2PipelineWithToolContinuation(options2) {
|
|
|
27602
27654
|
assistantMessage: result.response
|
|
27603
27655
|
});
|
|
27604
27656
|
delegatedToolCalls.push(
|
|
27605
|
-
...toolResultMessages.map((message2) => message2.delegatedToolCall).filter((
|
|
27657
|
+
...toolResultMessages.map((message2) => message2.delegatedToolCall).filter((record4) => record4 != null)
|
|
27606
27658
|
);
|
|
27607
27659
|
if (decision.kind === "direct-tool-response") {
|
|
27608
27660
|
const directResultMessage = (_a = toolResultMessages[0]) == null ? void 0 : _a.value;
|
|
@@ -28425,12 +28477,12 @@ function restoreOpenAICompatibleInstructionRoles(body, roles) {
|
|
|
28425
28477
|
if (body == null || typeof body !== "object" || Array.isArray(body)) {
|
|
28426
28478
|
throw new Error("Could not preserve developer messages: provider request body is not a JSON object.");
|
|
28427
28479
|
}
|
|
28428
|
-
const
|
|
28429
|
-
const listKey = Array.isArray(
|
|
28480
|
+
const record4 = body;
|
|
28481
|
+
const listKey = Array.isArray(record4.messages) ? "messages" : Array.isArray(record4.input) ? "input" : void 0;
|
|
28430
28482
|
if (listKey == null) {
|
|
28431
28483
|
throw new Error("Could not preserve developer messages: provider request body has no messages or input array.");
|
|
28432
28484
|
}
|
|
28433
|
-
const items =
|
|
28485
|
+
const items = record4[listKey];
|
|
28434
28486
|
const instructionIndexes = items.flatMap(
|
|
28435
28487
|
(item, index) => item != null && typeof item === "object" && !Array.isArray(item) && (item.role === "system" || item.role === "developer") ? [index] : []
|
|
28436
28488
|
);
|
|
@@ -28447,7 +28499,7 @@ function restoreOpenAICompatibleInstructionRoles(body, roles) {
|
|
|
28447
28499
|
};
|
|
28448
28500
|
});
|
|
28449
28501
|
return {
|
|
28450
|
-
...
|
|
28502
|
+
...record4,
|
|
28451
28503
|
[listKey]: rewrittenItems
|
|
28452
28504
|
};
|
|
28453
28505
|
}
|
|
@@ -43870,7 +43922,7 @@ function classifierPreparationCheck(signal, deadline, timeoutMs) {
|
|
|
43870
43922
|
signal.throwIfAborted();
|
|
43871
43923
|
if (Date.now() >= deadline)
|
|
43872
43924
|
throw new Error(
|
|
43873
|
-
`
|
|
43925
|
+
`Decision AI preparation/request timed out${timeoutMs === void 0 ? "" : ` after ${timeoutMs} ms`}.`
|
|
43874
43926
|
);
|
|
43875
43927
|
};
|
|
43876
43928
|
}
|
|
@@ -43883,7 +43935,7 @@ var ClassifierValueBudget = class {
|
|
|
43883
43935
|
}, maxBytes = CLASSIFIER_LIMITS.requestBytes) {
|
|
43884
43936
|
this.check = check;
|
|
43885
43937
|
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0)
|
|
43886
|
-
throw new ClassifierResourceLimitError("
|
|
43938
|
+
throw new ClassifierResourceLimitError("Decision AI byte limit must be a positive safe integer.");
|
|
43887
43939
|
this.maxBytes = Math.min(maxBytes, CLASSIFIER_LIMITS.requestBytes);
|
|
43888
43940
|
}
|
|
43889
43941
|
bytes = 0;
|
|
@@ -43898,7 +43950,7 @@ var ClassifierValueBudget = class {
|
|
|
43898
43950
|
const maxBytes = this.maxBytes;
|
|
43899
43951
|
const size = maxBytes >= 1e6 ? maxBytes % (1024 * 1024) === 0 ? `${maxBytes / (1024 * 1024)} MiB` : `${maxBytes / 1e6} MB` : `${maxBytes}-byte`;
|
|
43900
43952
|
throw new ClassifierResourceLimitError(
|
|
43901
|
-
`
|
|
43953
|
+
`Decision AI input exceeds the ${size} resource limit. Reduce input content or image size.`
|
|
43902
43954
|
);
|
|
43903
43955
|
}
|
|
43904
43956
|
}
|
|
@@ -43923,9 +43975,9 @@ var ClassifierValueBudget = class {
|
|
|
43923
43975
|
value(depth) {
|
|
43924
43976
|
this.check();
|
|
43925
43977
|
if (++this.values > CLASSIFIER_LIMITS.values)
|
|
43926
|
-
throw new ClassifierResourceLimitError("
|
|
43978
|
+
throw new ClassifierResourceLimitError("Decision AI input has too many expanded values.");
|
|
43927
43979
|
if (depth > CLASSIFIER_LIMITS.depth)
|
|
43928
|
-
throw new ClassifierResourceLimitError("
|
|
43980
|
+
throw new ClassifierResourceLimitError("Decision AI input exceeds the maximum nesting depth of 64.");
|
|
43929
43981
|
}
|
|
43930
43982
|
inspect(value, json) {
|
|
43931
43983
|
const startBytes = this.bytes;
|
|
@@ -43955,13 +44007,13 @@ var ClassifierValueBudget = class {
|
|
|
43955
44007
|
if (hook && (!("value" in hook) || typeof hook.value === "function"))
|
|
43956
44008
|
throw new Error(`${json.label} must not contain JSON serialization hooks.`);
|
|
43957
44009
|
}
|
|
43958
|
-
if (path.has(item)) throw new Error("
|
|
44010
|
+
if (path.has(item)) throw new Error("Decision AI input contains a circular reference.");
|
|
43959
44011
|
path.add(item);
|
|
43960
44012
|
this.add(2);
|
|
43961
44013
|
const copy = (json == null ? void 0 : json.copy) ? Array.isArray(item) ? [] : {} : void 0;
|
|
43962
44014
|
if (Array.isArray(item)) {
|
|
43963
44015
|
if (item.length > CLASSIFIER_LIMITS.values)
|
|
43964
|
-
throw new ClassifierResourceLimitError("
|
|
44016
|
+
throw new ClassifierResourceLimitError("Decision AI input has too many expanded values.");
|
|
43965
44017
|
for (let i = 0; i < item.length; i++) {
|
|
43966
44018
|
if (i > 0) this.add(1);
|
|
43967
44019
|
const descriptor = Object.getOwnPropertyDescriptor(item, String(i));
|
|
@@ -43976,7 +44028,7 @@ var ClassifierValueBudget = class {
|
|
|
43976
44028
|
} else {
|
|
43977
44029
|
const keys2 = Object.keys(item);
|
|
43978
44030
|
if (keys2.length > CLASSIFIER_LIMITS.values)
|
|
43979
|
-
throw new ClassifierResourceLimitError("
|
|
44031
|
+
throw new ClassifierResourceLimitError("Decision AI input has too many expanded values.");
|
|
43980
44032
|
let index = 0;
|
|
43981
44033
|
for (const key of keys2) {
|
|
43982
44034
|
this.string(key);
|
|
@@ -44022,18 +44074,18 @@ function checkClassifierJsonWork(text2, check, label = "response") {
|
|
|
44022
44074
|
} else if (character === '"') quoted = true;
|
|
44023
44075
|
else if (character === "{" || character === "[") {
|
|
44024
44076
|
if (++depth > CLASSIFIER_LIMITS.depth)
|
|
44025
|
-
throw new ClassifierResourceLimitError(`
|
|
44077
|
+
throw new ClassifierResourceLimitError(`Decision AI ${label} exceeds the maximum nesting depth of 64.`);
|
|
44026
44078
|
separators++;
|
|
44027
44079
|
} else if (character === "}" || character === "]") depth--;
|
|
44028
44080
|
else if (character === "," || character === ":") separators++;
|
|
44029
44081
|
if (separators > CLASSIFIER_LIMITS.values * 2)
|
|
44030
|
-
throw new ClassifierResourceLimitError(`
|
|
44082
|
+
throw new ClassifierResourceLimitError(`Decision AI ${label} has too many values.`);
|
|
44031
44083
|
}
|
|
44032
44084
|
}
|
|
44033
44085
|
async function readClassifierResponse(response, signal, check = () => signal.throwIfAborted(), onBody) {
|
|
44034
44086
|
const length = response.headers.get("content-length");
|
|
44035
44087
|
if (length && Number(length) > CLASSIFIER_LIMITS.responseBytes)
|
|
44036
|
-
throw new ClassifierResourceLimitError("
|
|
44088
|
+
throw new ClassifierResourceLimitError("Decision AI response exceeds the 8 MiB response limit.");
|
|
44037
44089
|
if (!response.body) return JSON.parse("");
|
|
44038
44090
|
const reader = response.body.getReader();
|
|
44039
44091
|
const cancel = () => {
|
|
@@ -44049,14 +44101,14 @@ async function readClassifierResponse(response, signal, check = () => signal.thr
|
|
|
44049
44101
|
for (; ; ) {
|
|
44050
44102
|
check();
|
|
44051
44103
|
const { done, value } = await reader.read().catch((cause) => {
|
|
44052
|
-
throw new ClassifierResponseReadError("
|
|
44104
|
+
throw new ClassifierResponseReadError("Decision AI response body could not be read.", { cause });
|
|
44053
44105
|
});
|
|
44054
44106
|
check();
|
|
44055
44107
|
if (done) break;
|
|
44056
44108
|
const chunk = classifierByteView(value);
|
|
44057
44109
|
bytes += chunk.byteLength;
|
|
44058
44110
|
if (bytes > CLASSIFIER_LIMITS.responseBytes)
|
|
44059
|
-
throw new ClassifierResourceLimitError("
|
|
44111
|
+
throw new ClassifierResourceLimitError("Decision AI response exceeds the 8 MiB response limit.");
|
|
44060
44112
|
pending += decoder.decode(chunk, { stream: true });
|
|
44061
44113
|
if (pending.length >= 64 * 1024) {
|
|
44062
44114
|
text2.push(pending);
|
|
@@ -44110,7 +44162,7 @@ var ClassifierQuestionPreparation = class {
|
|
|
44110
44162
|
check = () => {
|
|
44111
44163
|
this.deadlineCheck();
|
|
44112
44164
|
if (++this.operations > CLASSIFIER_LIMITS.values * 10)
|
|
44113
|
-
throw new ClassifierResourceLimitError("
|
|
44165
|
+
throw new ClassifierResourceLimitError("Decision AI question preparation has too much expanded work.");
|
|
44114
44166
|
};
|
|
44115
44167
|
capture(value) {
|
|
44116
44168
|
this.inspect(value, false);
|
|
@@ -44130,7 +44182,7 @@ var ClassifierQuestionPreparation = class {
|
|
|
44130
44182
|
output = (fragment, previousLength) => {
|
|
44131
44183
|
this.check();
|
|
44132
44184
|
if (fragment.length + previousLength > this.budget.remainingBytes)
|
|
44133
|
-
throw new ClassifierResourceLimitError("
|
|
44185
|
+
throw new ClassifierResourceLimitError("Decision AI question interpolation exceeds its remaining byte budget.");
|
|
44134
44186
|
};
|
|
44135
44187
|
processing = (input, name, parameter) => {
|
|
44136
44188
|
this.check();
|
|
@@ -44142,7 +44194,7 @@ var ClassifierQuestionPreparation = class {
|
|
|
44142
44194
|
const nextWhitespace = /\s/.test(input[i]);
|
|
44143
44195
|
if (name === "chain" && input[i] === "|" || (name === "chain" || name === "wrap") && nextWhitespace && !whitespace || name !== "chain" && name !== "wrap" && input[i] === "\n") {
|
|
44144
44196
|
if (++pieces > CLASSIFIER_LIMITS.values)
|
|
44145
|
-
throw new ClassifierResourceLimitError("
|
|
44197
|
+
throw new ClassifierResourceLimitError("Decision AI interpolation processor has too many expanded pieces.");
|
|
44146
44198
|
}
|
|
44147
44199
|
whitespace = nextWhitespace;
|
|
44148
44200
|
}
|
|
@@ -44151,14 +44203,14 @@ var ClassifierQuestionPreparation = class {
|
|
|
44151
44203
|
const value = parameter ?? (name === "indent" ? 0 : 1);
|
|
44152
44204
|
const prefix = name === "indent" ? value : name === "quote" ? value * 2 : (value - 1) * 2 + 2;
|
|
44153
44205
|
if (!Number.isSafeInteger(value) || value < (name === "list" ? 1 : 0))
|
|
44154
|
-
throw new Error(`Invalid
|
|
44206
|
+
throw new Error(`Invalid Decision AI interpolation ${name} parameter.`);
|
|
44155
44207
|
let lines = 1;
|
|
44156
44208
|
for (let i = 0; i < input.length; i++) {
|
|
44157
44209
|
if ((i & 4095) === 0) this.check();
|
|
44158
44210
|
if (input[i] === "\n") lines++;
|
|
44159
44211
|
}
|
|
44160
44212
|
if (input.length + lines * prefix > this.budget.remainingBytes)
|
|
44161
|
-
throw new ClassifierResourceLimitError("
|
|
44213
|
+
throw new ClassifierResourceLimitError("Decision AI interpolation processor exceeds its remaining byte budget.");
|
|
44162
44214
|
};
|
|
44163
44215
|
};
|
|
44164
44216
|
|
|
@@ -44170,7 +44222,7 @@ function classifierDataProperty(value, key, label = "State") {
|
|
|
44170
44222
|
return property == null ? void 0 : property.value;
|
|
44171
44223
|
}
|
|
44172
44224
|
function classifierInputDataValue(inputs, port) {
|
|
44173
|
-
const label = `
|
|
44225
|
+
const label = `Decision AI ${port} input`;
|
|
44174
44226
|
const input = classifierDataProperty(inputs, port, label);
|
|
44175
44227
|
if (input === void 0) return void 0;
|
|
44176
44228
|
if (input === null || typeof input !== "object" || Array.isArray(input))
|
|
@@ -44211,18 +44263,333 @@ function assertClassifierInstructions(value, label = "Instructions") {
|
|
|
44211
44263
|
assertClassifierInstructionsKind(value, label);
|
|
44212
44264
|
}
|
|
44213
44265
|
|
|
44266
|
+
// src/model/classifier/images.ts
|
|
44267
|
+
var InvalidClassifierImageError = class extends Error {
|
|
44268
|
+
};
|
|
44269
|
+
var invalidImage = () => new InvalidClassifierImageError(
|
|
44270
|
+
"State images must contain inline base64 PNG, JPEG, GIF or WebP image data with valid headers and matching media type."
|
|
44271
|
+
);
|
|
44272
|
+
function isBase64(value) {
|
|
44273
|
+
return value.length > 0 && value.length % 4 === 0 && /^[A-Za-z0-9+/]+={0,2}$/.test(value);
|
|
44274
|
+
}
|
|
44275
|
+
function jpegInfo(size, read, check) {
|
|
44276
|
+
const byte = (offset2) => read(offset2, 1)[0];
|
|
44277
|
+
const uint16 = (offset2) => {
|
|
44278
|
+
const bytes = read(offset2, 2);
|
|
44279
|
+
return (bytes[0] << 8) + bytes[1];
|
|
44280
|
+
};
|
|
44281
|
+
let offset = 2;
|
|
44282
|
+
while (offset + 4 <= size) {
|
|
44283
|
+
check == null ? void 0 : check();
|
|
44284
|
+
if (byte(offset++) !== 255) break;
|
|
44285
|
+
while (byte(offset) === 255) {
|
|
44286
|
+
if ((offset & 4095) === 0) check == null ? void 0 : check();
|
|
44287
|
+
offset++;
|
|
44288
|
+
}
|
|
44289
|
+
const marker2 = byte(offset++);
|
|
44290
|
+
if (marker2 === void 0 || marker2 === 218 || marker2 === 217) break;
|
|
44291
|
+
if (marker2 === 1 || marker2 >= 208 && marker2 <= 215) continue;
|
|
44292
|
+
if (offset + 2 > size) break;
|
|
44293
|
+
const length = uint16(offset);
|
|
44294
|
+
if (length < 2 || offset + length > size) break;
|
|
44295
|
+
if ([192, 193, 194, 195, 197, 198, 199, 201, 202, 203, 205, 206, 207].includes(marker2) && length >= 8)
|
|
44296
|
+
return { mediaType: "image/jpeg", width: uint16(offset + 5), height: uint16(offset + 3) };
|
|
44297
|
+
offset += length;
|
|
44298
|
+
}
|
|
44299
|
+
return void 0;
|
|
44300
|
+
}
|
|
44301
|
+
function imageInfo(bytes, check) {
|
|
44302
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
44303
|
+
const ascii = (offset, length) => String.fromCharCode(...bytes.subarray(offset, offset + length));
|
|
44304
|
+
let info;
|
|
44305
|
+
if (bytes.length >= 33 && ascii(0, 8) === "\x89PNG\r\n\n" && view.getUint32(8) === 13 && ascii(12, 4) === "IHDR") {
|
|
44306
|
+
info = { mediaType: "image/png", width: view.getUint32(16), height: view.getUint32(20) };
|
|
44307
|
+
} else if (bytes.length >= 13 && ["GIF87a", "GIF89a"].includes(ascii(0, 6))) {
|
|
44308
|
+
info = { mediaType: "image/gif", width: view.getUint16(6, true), height: view.getUint16(8, true) };
|
|
44309
|
+
} else if (bytes.length >= 25 && ascii(0, 4) === "RIFF" && ascii(8, 4) === "WEBP") {
|
|
44310
|
+
const chunk = ascii(12, 4);
|
|
44311
|
+
const uint24 = (offset) => bytes[offset] + (bytes[offset + 1] << 8) + (bytes[offset + 2] << 16);
|
|
44312
|
+
if (chunk === "VP8X" && bytes.length >= 30)
|
|
44313
|
+
info = { mediaType: "image/webp", width: uint24(24) + 1, height: uint24(27) + 1 };
|
|
44314
|
+
else if (chunk === "VP8 " && bytes.length >= 30 && ascii(23, 3) === "\x9D*")
|
|
44315
|
+
info = {
|
|
44316
|
+
mediaType: "image/webp",
|
|
44317
|
+
width: view.getUint16(26, true) & 16383,
|
|
44318
|
+
height: view.getUint16(28, true) & 16383
|
|
44319
|
+
};
|
|
44320
|
+
else if (chunk === "VP8L" && bytes[20] === 47) {
|
|
44321
|
+
const bits = view.getUint32(21, true);
|
|
44322
|
+
info = { mediaType: "image/webp", width: (bits & 16383) + 1, height: (bits >>> 14 & 16383) + 1 };
|
|
44323
|
+
}
|
|
44324
|
+
} else if (bytes.length >= 4 && bytes[0] === 255 && bytes[1] === 216) {
|
|
44325
|
+
info = jpegInfo(bytes.length, (offset, length) => bytes.subarray(offset, offset + length), check);
|
|
44326
|
+
}
|
|
44327
|
+
if (!info || info.width === 0 || info.height === 0) throw invalidImage();
|
|
44328
|
+
return info;
|
|
44329
|
+
}
|
|
44330
|
+
function base64ImageInfo(payload, check) {
|
|
44331
|
+
if (payload.startsWith("/9j/")) {
|
|
44332
|
+
const size = payload.length / 4 * 3 - (payload.endsWith("==") ? 2 : payload.endsWith("=") ? 1 : 0);
|
|
44333
|
+
let start = -1;
|
|
44334
|
+
let window = new Uint8Array();
|
|
44335
|
+
const info = jpegInfo(
|
|
44336
|
+
size,
|
|
44337
|
+
(offset, length) => {
|
|
44338
|
+
if (offset < start || offset + length > start + window.length) {
|
|
44339
|
+
start = Math.floor(offset / 3) * 3;
|
|
44340
|
+
window = base64ToUint8Array(payload.slice(start / 3 * 4, start / 3 * 4 + 4096));
|
|
44341
|
+
}
|
|
44342
|
+
return window.subarray(offset - start, offset - start + length);
|
|
44343
|
+
},
|
|
44344
|
+
check
|
|
44345
|
+
);
|
|
44346
|
+
if (!info || info.width === 0 || info.height === 0) throw invalidImage();
|
|
44347
|
+
return info;
|
|
44348
|
+
}
|
|
44349
|
+
return imageInfo(base64ToUint8Array(payload.slice(0, 48)));
|
|
44350
|
+
}
|
|
44351
|
+
function prepareNativeClassifierImage(value, check) {
|
|
44352
|
+
if (!value || typeof value !== "object") throw invalidImage();
|
|
44353
|
+
const data = classifierDataProperty(value, "data");
|
|
44354
|
+
const mediaType = classifierDataProperty(value, "mediaType");
|
|
44355
|
+
if (!(data instanceof Uint8Array)) throw invalidImage();
|
|
44356
|
+
const bytes = classifierByteView(data);
|
|
44357
|
+
assertClassifierResourceLimits(bytes, check);
|
|
44358
|
+
const info = imageInfo(bytes, check);
|
|
44359
|
+
if (info.mediaType !== mediaType) throw invalidImage();
|
|
44360
|
+
check == null ? void 0 : check();
|
|
44361
|
+
return { ...info, dataUrl: `data:${info.mediaType};base64,${uint8ArrayToBase64Sync(bytes)}` };
|
|
44362
|
+
}
|
|
44363
|
+
function inspectClassifierImage(value, check) {
|
|
44364
|
+
check == null ? void 0 : check();
|
|
44365
|
+
if (typeof value !== "string") throw invalidImage();
|
|
44366
|
+
const prefix = /^data:(image\/(?:png|jpeg|gif|webp));base64,/.exec(value);
|
|
44367
|
+
if (!prefix) throw invalidImage();
|
|
44368
|
+
const payload = value.slice(prefix[0].length);
|
|
44369
|
+
if (!isBase64(payload)) throw invalidImage();
|
|
44370
|
+
const info = base64ImageInfo(payload, check);
|
|
44371
|
+
if (info.mediaType !== prefix[1]) throw invalidImage();
|
|
44372
|
+
return info;
|
|
44373
|
+
}
|
|
44374
|
+
function prepareClassifierImageText(value, check) {
|
|
44375
|
+
check == null ? void 0 : check();
|
|
44376
|
+
if (value.length > CLASSIFIER_LIMITS.requestBytes)
|
|
44377
|
+
throw new Error("Decision AI image/text exceeds the 32 MiB input limit.");
|
|
44378
|
+
if (value.startsWith("data:image/")) {
|
|
44379
|
+
return { ...inspectClassifierImage(value, check), dataUrl: value };
|
|
44380
|
+
}
|
|
44381
|
+
if (!/^(?:iVBOR|\/9j\/|R0lGOD|UklGR)/.test(value) || !isBase64(value)) return void 0;
|
|
44382
|
+
try {
|
|
44383
|
+
const info = base64ImageInfo(value, check);
|
|
44384
|
+
return { ...info, dataUrl: `data:${info.mediaType};base64,${value}` };
|
|
44385
|
+
} catch (error) {
|
|
44386
|
+
if (error instanceof InvalidClassifierImageError) return void 0;
|
|
44387
|
+
throw error;
|
|
44388
|
+
}
|
|
44389
|
+
}
|
|
44390
|
+
function assertLiquidImageLimits(images, check) {
|
|
44391
|
+
if (images.length > 8) throw new Error("Liquid Decision AI State must contain at most 8 images.");
|
|
44392
|
+
let patches = 0;
|
|
44393
|
+
for (const { width, height } of images) {
|
|
44394
|
+
check == null ? void 0 : check();
|
|
44395
|
+
if (Math.max(width, height) / Math.min(width, height) > 100)
|
|
44396
|
+
throw new Error("Liquid Decision AI images must have an aspect ratio at most 100:1.");
|
|
44397
|
+
patches += Math.ceil(width / 32) * Math.ceil(height / 32);
|
|
44398
|
+
}
|
|
44399
|
+
if (patches > 1e4)
|
|
44400
|
+
throw new Error("Liquid Decision AI images must contain at most 10,000 patches of 32 by 32 pixels in total.");
|
|
44401
|
+
}
|
|
44402
|
+
|
|
44403
|
+
// src/model/classifier/state.ts
|
|
44404
|
+
var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
44405
|
+
var nativeImage = (value) => record(value) && (classifierDataProperty(value, "type") === "image" || "mediaType" in value && classifierDataProperty(value, "data") instanceof Uint8Array);
|
|
44406
|
+
var message = (value) => record(value) && "type" in value && "message" in value;
|
|
44407
|
+
function prepareClassifierState(input, budget) {
|
|
44408
|
+
if (input.stateInput !== void 0) {
|
|
44409
|
+
if (input.state !== "" || input.stateMessages !== void 0)
|
|
44410
|
+
throw new Error("Rivet State input and provider State cannot be supplied together.");
|
|
44411
|
+
return prepareRivetState(input.stateInput, budget);
|
|
44412
|
+
}
|
|
44413
|
+
if (input.stateMessages === void 0) {
|
|
44414
|
+
if (typeof input.state !== "string" && !record(input.state) && !Array.isArray(input.state))
|
|
44415
|
+
throw new Error("State must be text, a JSON object or an array.");
|
|
44416
|
+
return { kind: "json", value: snapshotClassifierJson(input.state, "State", budget) };
|
|
44417
|
+
}
|
|
44418
|
+
if (input.state !== "")
|
|
44419
|
+
throw new Error("Structured State and multimodal State messages cannot be supplied together.");
|
|
44420
|
+
const messages = snapshotClassifierJson(input.stateMessages, "State", budget);
|
|
44421
|
+
const images = inspectStateMessages(messages, budget.check);
|
|
44422
|
+
return { kind: "messages", messages, images };
|
|
44423
|
+
}
|
|
44424
|
+
function normalizeClassifierState(input, check, maxBytes) {
|
|
44425
|
+
const state = input === void 0 ? { kind: "json", value: "" } : prepareRivetState(input, new ClassifierValueBudget(check, maxBytes));
|
|
44426
|
+
return state.kind === "json" ? { state: state.value } : { state: "", stateMessages: state.messages };
|
|
44427
|
+
}
|
|
44428
|
+
function prepareRivetState(input, budget) {
|
|
44429
|
+
const check = budget.check;
|
|
44430
|
+
if (input === null || typeof input !== "object" || Array.isArray(input))
|
|
44431
|
+
throw new Error("State input must contain a Rivet data value.");
|
|
44432
|
+
const type = classifierDataProperty(input, "type");
|
|
44433
|
+
const value = classifierDataProperty(input, "value");
|
|
44434
|
+
if (typeof type !== "string") throw new Error("State input type must be a string.");
|
|
44435
|
+
if (![
|
|
44436
|
+
"string",
|
|
44437
|
+
"string[]",
|
|
44438
|
+
"image",
|
|
44439
|
+
"image[]",
|
|
44440
|
+
"chat-message",
|
|
44441
|
+
"chat-message[]",
|
|
44442
|
+
"object",
|
|
44443
|
+
"object[]",
|
|
44444
|
+
"any",
|
|
44445
|
+
"any[]"
|
|
44446
|
+
].includes(type))
|
|
44447
|
+
throw new Error(`Unsupported State input type '${type}'.`);
|
|
44448
|
+
if (type.endsWith("[]") && !Array.isArray(value)) throw new Error("State array input must contain an array.");
|
|
44449
|
+
if (type === "string" && typeof value !== "string") throw new Error("State string input must contain a string.");
|
|
44450
|
+
if (type === "object" && !record(value) && !Array.isArray(value))
|
|
44451
|
+
throw new Error("State object input must contain a JSON object or array.");
|
|
44452
|
+
if ((type === "image" || type === "chat-message") && Array.isArray(value))
|
|
44453
|
+
throw new Error("State scalar input must not contain an array.");
|
|
44454
|
+
if (type === "object" || type === "object[]")
|
|
44455
|
+
return { kind: "json", value: snapshotClassifierJson(value, "State", budget) };
|
|
44456
|
+
budget.inspect(value);
|
|
44457
|
+
const imageTexts = /* @__PURE__ */ new Map();
|
|
44458
|
+
const textImage = (text2) => {
|
|
44459
|
+
const image = imageTexts.get(text2) ?? prepareClassifierImageText(text2, check);
|
|
44460
|
+
if (image) imageTexts.set(text2, image);
|
|
44461
|
+
return image;
|
|
44462
|
+
};
|
|
44463
|
+
const hasContent = (item) => nativeImage(item) || message(item) || typeof item === "string" && textImage(item) !== void 0;
|
|
44464
|
+
const arrayHasContent = () => {
|
|
44465
|
+
for (const item of classifierArrayValues(value, "State")) {
|
|
44466
|
+
check();
|
|
44467
|
+
if (hasContent(item)) return true;
|
|
44468
|
+
}
|
|
44469
|
+
return false;
|
|
44470
|
+
};
|
|
44471
|
+
const contentType = ["image", "image[]", "string[]", "chat-message", "chat-message[]"].includes(type);
|
|
44472
|
+
const inferredContent = (type === "any" || type === "any[]") && (hasContent(value) || Array.isArray(value) && arrayHasContent());
|
|
44473
|
+
if (!(contentType || inferredContent || type === "string" && textImage(value))) {
|
|
44474
|
+
if (typeof value !== "string" && !record(value) && !Array.isArray(value))
|
|
44475
|
+
throw new Error("State must be text, a JSON object/array, images, or user messages.");
|
|
44476
|
+
return {
|
|
44477
|
+
kind: "json",
|
|
44478
|
+
value: typeof value === "string" ? value : snapshotClassifierJson(value, "State", new ClassifierValueBudget(check))
|
|
44479
|
+
};
|
|
44480
|
+
}
|
|
44481
|
+
const values2 = Array.isArray(value) ? value : [value];
|
|
44482
|
+
if (type === "image[]" && values2.length > 128) throw new Error("State must contain at most 128 images.");
|
|
44483
|
+
const messages = [];
|
|
44484
|
+
const images = [];
|
|
44485
|
+
let partCount = 0;
|
|
44486
|
+
const imagePart = (prepare) => {
|
|
44487
|
+
if (images.length >= 128) throw new Error("State must contain at most 128 images.");
|
|
44488
|
+
const image = prepare();
|
|
44489
|
+
images.push(image);
|
|
44490
|
+
return { type: "image", dataUrl: image.dataUrl };
|
|
44491
|
+
};
|
|
44492
|
+
let parts = [];
|
|
44493
|
+
const flush = () => {
|
|
44494
|
+
if (parts.length) {
|
|
44495
|
+
if (messages.length >= CLASSIFIER_LIMITS.messages) throw new Error("State has too many messages.");
|
|
44496
|
+
messages.push({ parts });
|
|
44497
|
+
parts = [];
|
|
44498
|
+
}
|
|
44499
|
+
};
|
|
44500
|
+
const part = (item) => {
|
|
44501
|
+
check();
|
|
44502
|
+
if (++partCount > CLASSIFIER_LIMITS.parts) throw new Error("State has too many content parts.");
|
|
44503
|
+
if (typeof item === "string") {
|
|
44504
|
+
const image = textImage(item);
|
|
44505
|
+
return image ? imagePart(() => image) : { type: "text", text: item };
|
|
44506
|
+
}
|
|
44507
|
+
if (nativeImage(item)) return imagePart(() => prepareNativeClassifierImage(item, check));
|
|
44508
|
+
throw new Error("Multimodal State accepts only text, native images, image data URLs, and user messages.");
|
|
44509
|
+
};
|
|
44510
|
+
for (const item of classifierArrayValues(values2, "State")) {
|
|
44511
|
+
check();
|
|
44512
|
+
if (type === "image" || type === "image[]") {
|
|
44513
|
+
if (++partCount > CLASSIFIER_LIMITS.parts) throw new Error("State has too many content parts.");
|
|
44514
|
+
parts.push(imagePart(() => prepareNativeClassifierImage(item, check)));
|
|
44515
|
+
} else if (type === "string[]" && typeof item !== "string") {
|
|
44516
|
+
throw new Error("State string array must contain only strings.");
|
|
44517
|
+
} else if (message(item)) {
|
|
44518
|
+
if (classifierDataProperty(item, "type") !== "user" || "function_call" in item || "function_calls" in item)
|
|
44519
|
+
throw new Error(
|
|
44520
|
+
"Decision AI State supports only user messages, not system, developer, assistant, or tool messages."
|
|
44521
|
+
);
|
|
44522
|
+
flush();
|
|
44523
|
+
if (messages.length >= CLASSIFIER_LIMITS.messages) throw new Error("State has too many messages.");
|
|
44524
|
+
const contentValue = classifierDataProperty(item, "message");
|
|
44525
|
+
const content = Array.isArray(contentValue) ? contentValue : [contentValue];
|
|
44526
|
+
messages.push({
|
|
44527
|
+
parts: content.length ? Array.from(classifierArrayValues(content, "State"), part) : [{ type: "text", text: "" }]
|
|
44528
|
+
});
|
|
44529
|
+
} else {
|
|
44530
|
+
if (type === "chat-message" || type === "chat-message[]")
|
|
44531
|
+
throw new Error("State must contain valid user messages.");
|
|
44532
|
+
parts.push(part(item));
|
|
44533
|
+
}
|
|
44534
|
+
}
|
|
44535
|
+
flush();
|
|
44536
|
+
return messages.length ? { kind: "messages", messages, images } : { kind: "json", value: "" };
|
|
44537
|
+
}
|
|
44538
|
+
function inspectStateMessages(messages, check) {
|
|
44539
|
+
if (!Array.isArray(messages)) throw new Error("State messages must be an array.");
|
|
44540
|
+
if (messages.length > CLASSIFIER_LIMITS.messages) throw new Error("State has too many messages.");
|
|
44541
|
+
const images = [];
|
|
44542
|
+
let parts = 0;
|
|
44543
|
+
for (const message2 of messages) {
|
|
44544
|
+
if (!record(message2) || !Array.isArray(message2.parts)) throw new Error("State message parts must be an array.");
|
|
44545
|
+
for (const part of message2.parts) {
|
|
44546
|
+
check();
|
|
44547
|
+
if (++parts > CLASSIFIER_LIMITS.parts) throw new Error("State has too many content parts.");
|
|
44548
|
+
if (!record(part)) throw new Error("Invalid State content part.");
|
|
44549
|
+
if (part.type === "image" && typeof part.dataUrl === "string") {
|
|
44550
|
+
if (images.length >= 128) throw new Error("State must contain at most 128 images.");
|
|
44551
|
+
images.push({ ...inspectClassifierImage(part.dataUrl, check), dataUrl: part.dataUrl });
|
|
44552
|
+
} else if (part.type !== "text" || typeof part.text !== "string") throw new Error("Invalid State content part.");
|
|
44553
|
+
}
|
|
44554
|
+
}
|
|
44555
|
+
return images;
|
|
44556
|
+
}
|
|
44557
|
+
function systemOneState(input) {
|
|
44558
|
+
if (!input.stateMessages) return { state: input.state };
|
|
44559
|
+
const images = [];
|
|
44560
|
+
const state = input.stateMessages.map(
|
|
44561
|
+
({ parts }) => parts.map((part) => {
|
|
44562
|
+
if (part.type === "text") return part.text;
|
|
44563
|
+
images.push(part.dataUrl);
|
|
44564
|
+
return `[Image ${images.length}]`;
|
|
44565
|
+
}).join("\n")
|
|
44566
|
+
).join("\n\n");
|
|
44567
|
+
return { state, ...images.length ? { images } : {} };
|
|
44568
|
+
}
|
|
44569
|
+
|
|
44214
44570
|
// src/model/classifier/questionHelpers.ts
|
|
44215
44571
|
var STRUCTURED_ENTRY_TYPES = ["string", "object", "object[]", "any", "any[]"];
|
|
44216
44572
|
function getInstructionsInputDefinition() {
|
|
44217
44573
|
return {
|
|
44218
44574
|
id: "instructions",
|
|
44219
44575
|
title: "Instructions",
|
|
44220
|
-
dataType: STRUCTURED_ENTRY_TYPES,
|
|
44576
|
+
dataType: [...STRUCTURED_ENTRY_TYPES, "string[]", "image", "image[]", "chat-message", "chat-message[]"],
|
|
44221
44577
|
required: true,
|
|
44222
44578
|
splitRunBehavior: "preserve-array",
|
|
44223
|
-
description: "
|
|
44579
|
+
description: "Text/JSON, an image, or assembled User messages. Question images require Jev or OpenAI."
|
|
44224
44580
|
};
|
|
44225
44581
|
}
|
|
44582
|
+
function getQuestionInstructionsInput(inputs, preparation) {
|
|
44583
|
+
const input = classifierDataProperty(inputs, "instructions", "Instructions");
|
|
44584
|
+
if (!input) throw new Error("Instructions input is required.");
|
|
44585
|
+
const normalized = normalizeClassifierState(input, preparation.check);
|
|
44586
|
+
if (normalized.stateMessages && (input.type !== "string[]" || normalized.stateMessages.some(({ parts }) => parts.some((part) => part.type === "image"))))
|
|
44587
|
+
return { instructions: "", instructionsMessages: normalized.stateMessages };
|
|
44588
|
+
if (input.type === "image[]" || input.type === "chat-message[]")
|
|
44589
|
+
throw new Error("Instructions must not contain empty image or User-message arrays.");
|
|
44590
|
+
if (!normalized.stateMessages) return { instructions: normalized.state };
|
|
44591
|
+
return { instructions: getStructuredInput(inputs, "instructions", "Instructions") };
|
|
44592
|
+
}
|
|
44226
44593
|
function getCriteriaInputDefinition(dataTypes2) {
|
|
44227
44594
|
return {
|
|
44228
44595
|
id: "criteria",
|
|
@@ -44335,6 +44702,81 @@ function abbreviate(value, maximum = 72) {
|
|
|
44335
44702
|
return compact.length <= maximum ? compact : `${compact.slice(0, maximum - 3)}...`;
|
|
44336
44703
|
}
|
|
44337
44704
|
|
|
44705
|
+
// src/model/classifier/questions.ts
|
|
44706
|
+
function createQuestionMap(questions, instructionsFor = (question) => question.instructionsMessages ? systemOneState({ state: "", stateMessages: question.instructionsMessages }).state : question.instructions) {
|
|
44707
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
44708
|
+
for (const question of questions) {
|
|
44709
|
+
const instructions = instructionsFor(question);
|
|
44710
|
+
const providerQuestion = (question.type === "noul" || question.type === "box") && question.criteria === void 0 ? { type: question.type, instructions } : { type: question.type, instructions, criteria: question.criteria };
|
|
44711
|
+
Object.defineProperty(result, question.questionId, { enumerable: true, value: providerQuestion });
|
|
44712
|
+
}
|
|
44713
|
+
return result;
|
|
44714
|
+
}
|
|
44715
|
+
function prepareClassifierQuestion(value, budget) {
|
|
44716
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
44717
|
+
throw new Error("Question inputs must contain question definition objects.");
|
|
44718
|
+
if ("images" in value)
|
|
44719
|
+
throw new Error(
|
|
44720
|
+
"Question-level images fields are not supported. Connect images to Question Instructions (Jev/OpenAI), or to Decision AI run's State input for shared evidence."
|
|
44721
|
+
);
|
|
44722
|
+
if ("instructionsMessages" in value) {
|
|
44723
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, "instructionsMessages");
|
|
44724
|
+
if (!(descriptor == null ? void 0 : descriptor.enumerable) || !("value" in descriptor))
|
|
44725
|
+
throw new Error("Question instructionsMessages must be an own, enumerable data field.");
|
|
44726
|
+
}
|
|
44727
|
+
for (const key of ["questionId", "type", "instructions"]) {
|
|
44728
|
+
if (!Object.prototype.propertyIsEnumerable.call(value, key))
|
|
44729
|
+
throw new Error(`Every Decision AI question must have an own, enumerable '${key}' field.`);
|
|
44730
|
+
}
|
|
44731
|
+
const criteriaProperty = Object.getOwnPropertyDescriptor(value, "criteria");
|
|
44732
|
+
if (criteriaProperty && (!criteriaProperty.enumerable || !("value" in criteriaProperty)))
|
|
44733
|
+
throw new Error("Decision AI question criteria must be an own, enumerable field.");
|
|
44734
|
+
const question = snapshotClassifierJson(value, "Question", budget, true);
|
|
44735
|
+
if (typeof question.questionId !== "string" || question.questionId.trim() === "")
|
|
44736
|
+
throw new Error("Every Decision AI question must have a non-empty Question ID.");
|
|
44737
|
+
if (!["choice", "score", "noul", "box"].includes(question.type))
|
|
44738
|
+
throw new Error(`Question '${question.questionId}' has an unsupported type.`);
|
|
44739
|
+
if (question.instructionsMessages !== void 0) {
|
|
44740
|
+
if (question.instructions !== "")
|
|
44741
|
+
throw new Error("Question instructions and instructionsMessages cannot be supplied together.");
|
|
44742
|
+
inspectStateMessages(question.instructionsMessages, budget.check);
|
|
44743
|
+
if (!question.instructionsMessages.some(
|
|
44744
|
+
({ parts }) => parts.some((part) => part.type === "image" || part.text.trim() !== "")
|
|
44745
|
+
))
|
|
44746
|
+
throw new Error(`Question '${question.questionId}' instructions must not be empty.`);
|
|
44747
|
+
} else {
|
|
44748
|
+
assertClassifierInstructionsKind(question.instructions, `Question '${question.questionId}' instructions`);
|
|
44749
|
+
}
|
|
44750
|
+
const criteria = question.criteria;
|
|
44751
|
+
if (question.type === "box" && criteria !== void 0)
|
|
44752
|
+
throw new Error(`Bounding Box question '${question.questionId}' does not accept criteria.`);
|
|
44753
|
+
if (question.type === "choice") {
|
|
44754
|
+
if (typeof criteria !== "object" || criteria === null || Array.isArray(criteria))
|
|
44755
|
+
throw new Error(`Choice question '${question.questionId}' requires object criteria.`);
|
|
44756
|
+
const keys2 = Object.keys(criteria);
|
|
44757
|
+
if (keys2.length < 2 || keys2.length > 255)
|
|
44758
|
+
throw new Error(`Choice question '${question.questionId}' requires 2 to 255 options.`);
|
|
44759
|
+
for (const key of keys2)
|
|
44760
|
+
assertClassifierEntryKind(
|
|
44761
|
+
criteria[key],
|
|
44762
|
+
`Question '${question.questionId}' criteria.${key}`
|
|
44763
|
+
);
|
|
44764
|
+
} else if (question.type === "score") {
|
|
44765
|
+
if (!Array.isArray(criteria) || criteria.length < 2 || criteria.length > 10)
|
|
44766
|
+
throw new Error(`Score question '${question.questionId}' requires 2 to 10 levels.`);
|
|
44767
|
+
let index = 0;
|
|
44768
|
+
for (const entry of classifierArrayValues(criteria, "Criteria"))
|
|
44769
|
+
assertClassifierEntryKind(entry, `Question '${question.questionId}' criteria[${index++}]`);
|
|
44770
|
+
} else if (question.type === "noul" && criteria !== void 0) {
|
|
44771
|
+
if (typeof criteria !== "object" || criteria === null || Array.isArray(criteria) || !Object.prototype.propertyIsEnumerable.call(criteria, "true") || !Object.prototype.propertyIsEnumerable.call(criteria, "false"))
|
|
44772
|
+
throw new Error(`Noul question '${question.questionId}' criteria must contain true and false entries.`);
|
|
44773
|
+
const entries2 = criteria;
|
|
44774
|
+
assertClassifierEntryKind(entries2.true, `Question '${question.questionId}' criteria.true`);
|
|
44775
|
+
assertClassifierEntryKind(entries2.false, `Question '${question.questionId}' criteria.false`);
|
|
44776
|
+
}
|
|
44777
|
+
return question;
|
|
44778
|
+
}
|
|
44779
|
+
|
|
44338
44780
|
// src/model/nodes/ClassifierQuestionNode.ts
|
|
44339
44781
|
var defaultOptions = () => [
|
|
44340
44782
|
{ key: "", value: "" },
|
|
@@ -44357,7 +44799,7 @@ var ClassifierQuestionNodeImpl = class extends NodeImpl {
|
|
|
44357
44799
|
static create() {
|
|
44358
44800
|
return {
|
|
44359
44801
|
type: "classifierQuestion",
|
|
44360
|
-
title: "
|
|
44802
|
+
title: "Decision AI Question",
|
|
44361
44803
|
id: (0, import_non_secure109.nanoid)(),
|
|
44362
44804
|
visualData: { x: 0, y: 0, width: 280 },
|
|
44363
44805
|
data: {
|
|
@@ -44384,7 +44826,7 @@ var ClassifierQuestionNodeImpl = class extends NodeImpl {
|
|
|
44384
44826
|
const data = this.data;
|
|
44385
44827
|
const inputs = [];
|
|
44386
44828
|
if (data.useInstructionsInput) inputs.push(getInstructionsInputDefinition());
|
|
44387
|
-
if (data.useCriteriaInput) {
|
|
44829
|
+
if (data.questionType !== "box" && data.useCriteriaInput) {
|
|
44388
44830
|
inputs.push(getCriteriaInputDefinition(getCriteriaInputTypes(data.questionType)));
|
|
44389
44831
|
} else if (data.questionType === "noul") {
|
|
44390
44832
|
const criteriaType = getCriteriaType(data);
|
|
@@ -44399,7 +44841,7 @@ var ClassifierQuestionNodeImpl = class extends NodeImpl {
|
|
|
44399
44841
|
data.instructionsLines,
|
|
44400
44842
|
data.instructionsObjectTemplate
|
|
44401
44843
|
);
|
|
44402
|
-
if (!data.useCriteriaInput) {
|
|
44844
|
+
if (data.questionType !== "box" && !data.useCriteriaInput) {
|
|
44403
44845
|
if (data.questionType === "choice") {
|
|
44404
44846
|
if (getCriteriaType(data) === "text") templates.push(...(data.options ?? []).map((option) => option.value));
|
|
44405
44847
|
else {
|
|
@@ -44441,7 +44883,8 @@ var ClassifierQuestionNodeImpl = class extends NodeImpl {
|
|
|
44441
44883
|
options: [
|
|
44442
44884
|
{ value: "noul", label: "Noul" },
|
|
44443
44885
|
{ value: "choice", label: "Choice" },
|
|
44444
|
-
{ value: "score", label: "Score" }
|
|
44886
|
+
{ value: "score", label: "Score" },
|
|
44887
|
+
{ value: "box", label: "Bounding Box" }
|
|
44445
44888
|
],
|
|
44446
44889
|
defaultValue: "choice",
|
|
44447
44890
|
allowOptionWrap: false
|
|
@@ -44501,7 +44944,7 @@ var ClassifierQuestionNodeImpl = class extends NodeImpl {
|
|
|
44501
44944
|
type: "group",
|
|
44502
44945
|
label: "Criteria",
|
|
44503
44946
|
presentation: "section",
|
|
44504
|
-
hideIf: (data) => data.questionType === "noul" && Boolean(data.useCriteriaInput),
|
|
44947
|
+
hideIf: (data) => data.questionType === "box" || data.questionType === "noul" && Boolean(data.useCriteriaInput),
|
|
44505
44948
|
editors: [
|
|
44506
44949
|
{
|
|
44507
44950
|
type: "dropdown",
|
|
@@ -44632,17 +45075,17 @@ var ClassifierQuestionNodeImpl = class extends NodeImpl {
|
|
|
44632
45075
|
}
|
|
44633
45076
|
static getUIData() {
|
|
44634
45077
|
return {
|
|
44635
|
-
contextMenuTitle: "
|
|
44636
|
-
infoBoxTitle: "
|
|
44637
|
-
infoBoxBody: "Builds one typed
|
|
44638
|
-
group: ["
|
|
45078
|
+
contextMenuTitle: "Decision AI Question",
|
|
45079
|
+
infoBoxTitle: "Decision AI Question",
|
|
45080
|
+
infoBoxBody: "Builds one typed Decision AI question without making a network request.",
|
|
45081
|
+
group: ["Decision AI"]
|
|
44639
45082
|
};
|
|
44640
45083
|
}
|
|
44641
45084
|
async process(inputs, context) {
|
|
44642
45085
|
const preparation = new ClassifierQuestionPreparation(context);
|
|
44643
45086
|
const data = this.data;
|
|
44644
45087
|
preparation.capture(data.questionId);
|
|
44645
|
-
const criteria = data.useCriteriaInput ? getQuestionInputValue(inputs, "criteria", "Criteria") : void 0;
|
|
45088
|
+
const criteria = data.questionType !== "box" && data.useCriteriaInput ? getQuestionInputValue(inputs, "criteria", "Criteria") : void 0;
|
|
44646
45089
|
if (data.questionType === "score") {
|
|
44647
45090
|
const count = data.useCriteriaInput ? Array.isArray(criteria) ? criteria.length : 0 : (data.scoreCriteria ?? data.levels ?? defaultLevels()).length;
|
|
44648
45091
|
if (count < 2 || count > 10) throw new Error("Score questions require 2 to 10 levels.");
|
|
@@ -44650,23 +45093,27 @@ var ClassifierQuestionNodeImpl = class extends NodeImpl {
|
|
|
44650
45093
|
const count = data.useCriteriaInput ? criteria && typeof criteria === "object" && !Array.isArray(criteria) ? Object.keys(criteria).length : 0 : (getCriteriaType(data) === "text" ? data.options ?? defaultOptions() : data.choiceCriteria ?? data.options ?? defaultOptions()).length;
|
|
44651
45094
|
if (count < 2 || count > 255) throw new Error("Choice questions require 2 to 255 options.");
|
|
44652
45095
|
}
|
|
44653
|
-
if (data.useInstructionsInput) preparation.capture(getQuestionInputValue(inputs, "instructions", "Instructions"));
|
|
44654
45096
|
const questionId = requireQuestionId(data.questionId);
|
|
44655
|
-
const
|
|
44656
|
-
|
|
44657
|
-
|
|
44658
|
-
|
|
44659
|
-
|
|
44660
|
-
|
|
44661
|
-
|
|
44662
|
-
|
|
44663
|
-
|
|
44664
|
-
|
|
44665
|
-
|
|
45097
|
+
const instructionInput = data.useInstructionsInput ? getQuestionInstructionsInput(inputs, preparation) : {
|
|
45098
|
+
instructions: resolveAuthoredClassifierEntry({
|
|
45099
|
+
type: data.instructionsType,
|
|
45100
|
+
text: data.instructions,
|
|
45101
|
+
lines: data.instructionsLines,
|
|
45102
|
+
objectTemplate: data.instructionsObjectTemplate,
|
|
45103
|
+
inputs,
|
|
45104
|
+
context,
|
|
45105
|
+
label: "Instructions",
|
|
45106
|
+
preparation
|
|
45107
|
+
})
|
|
45108
|
+
};
|
|
45109
|
+
const { instructions } = instructionInput;
|
|
45110
|
+
if (data.useInstructionsInput) preparation.capture(instructionInput);
|
|
45111
|
+
if (!instructionInput.instructionsMessages) assertClassifierInstructions(instructions);
|
|
44666
45112
|
const question = createQuestionDefinition(data, inputs, context, questionId, instructions, preparation);
|
|
44667
|
-
|
|
45113
|
+
if (instructionInput.instructionsMessages) question.instructionsMessages = instructionInput.instructionsMessages;
|
|
45114
|
+
const prepared = prepareClassifierQuestion(question, new ClassifierValueBudget(preparation.check));
|
|
44668
45115
|
preparation.check();
|
|
44669
|
-
return { ["question"]: { type: "object", value:
|
|
45116
|
+
return { ["question"]: { type: "object", value: prepared } };
|
|
44670
45117
|
}
|
|
44671
45118
|
};
|
|
44672
45119
|
function getCriteriaInputTypes(questionType) {
|
|
@@ -44683,6 +45130,7 @@ function getNoulCriteriaInputDefinition(id, title, criteriaType) {
|
|
|
44683
45130
|
};
|
|
44684
45131
|
}
|
|
44685
45132
|
function getQuestionTypeLabel(questionType) {
|
|
45133
|
+
if (questionType === "box") return "Bounding Box";
|
|
44686
45134
|
return questionType === "noul" ? "Noul" : questionType[0].toUpperCase() + questionType.slice(1);
|
|
44687
45135
|
}
|
|
44688
45136
|
function getClassifierQuestionBodySections(data) {
|
|
@@ -44696,7 +45144,10 @@ function getClassifierQuestionBodySections(data) {
|
|
|
44696
45144
|
]
|
|
44697
45145
|
},
|
|
44698
45146
|
instructions,
|
|
44699
|
-
{
|
|
45147
|
+
data.questionType === "box" ? {
|
|
45148
|
+
id: "capability",
|
|
45149
|
+
fields: [{ label: "Requires", value: "Jev 1.14 and an image (experimental)" }]
|
|
45150
|
+
} : {
|
|
44700
45151
|
id: "criteria",
|
|
44701
45152
|
fields: [{ label: "Criteria", value: data.useCriteriaInput ? "input" : getCriteriaSummary(data) }]
|
|
44702
45153
|
}
|
|
@@ -44724,6 +45175,7 @@ function getInstructionsBodySection(data) {
|
|
|
44724
45175
|
return { id: "instructions", fields: [], summary: abbreviate(data.instructions) || "(required)" };
|
|
44725
45176
|
}
|
|
44726
45177
|
function createQuestionDefinition(data, inputs, context, questionId, instructions, preparation) {
|
|
45178
|
+
if (data.questionType === "box") return { questionId, type: "box", instructions };
|
|
44727
45179
|
if (data.questionType === "choice") {
|
|
44728
45180
|
return createChoiceQuestion(data, inputs, context, questionId, instructions, preparation);
|
|
44729
45181
|
}
|
|
@@ -44902,7 +45354,7 @@ function hasClassifierCriteriaValue(value) {
|
|
|
44902
45354
|
if (typeof value !== "object") return true;
|
|
44903
45355
|
return Object.keys(value).length > 0;
|
|
44904
45356
|
}
|
|
44905
|
-
var classifierQuestionNode = nodeDefinition(ClassifierQuestionNodeImpl, "
|
|
45357
|
+
var classifierQuestionNode = nodeDefinition(ClassifierQuestionNodeImpl, "Decision AI Question");
|
|
44906
45358
|
|
|
44907
45359
|
// src/model/nodes/ClassifierEvaluateNode.ts
|
|
44908
45360
|
var import_non_secure110 = require("nanoid/non-secure");
|
|
@@ -44930,6 +45382,14 @@ var PERPLEXITY_DEFAULT_CREDENTIAL_NAMES = {
|
|
|
44930
45382
|
programmaticName: "perplexityApiKey",
|
|
44931
45383
|
environmentVariableName: "PERPLEXITY_API_KEY"
|
|
44932
45384
|
};
|
|
45385
|
+
var SUBQ_DEFAULT_CREDENTIAL_NAMES = {
|
|
45386
|
+
programmaticName: "subqApiKey",
|
|
45387
|
+
environmentVariableName: "SUBQ_API_KEY"
|
|
45388
|
+
};
|
|
45389
|
+
var BASETEN_DEFAULT_CREDENTIAL_NAMES = {
|
|
45390
|
+
programmaticName: "basetenApiKey",
|
|
45391
|
+
environmentVariableName: "BASETEN_API_KEY"
|
|
45392
|
+
};
|
|
44933
45393
|
var programmaticNamePattern2 = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
44934
45394
|
var environmentVariableNamePattern2 = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
44935
45395
|
function isValidClassifierProgrammaticCredentialName(name) {
|
|
@@ -44941,25 +45401,25 @@ function isValidClassifierEnvironmentCredentialName(name) {
|
|
|
44941
45401
|
function normalizeClassifierCredentialNames(value, defaults = JEV_DEFAULT_CREDENTIAL_NAMES) {
|
|
44942
45402
|
var _a, _b;
|
|
44943
45403
|
if (value != null && (typeof value !== "object" || Array.isArray(value))) {
|
|
44944
|
-
throw new Error("
|
|
45404
|
+
throw new Error("Decision AI API key names must be an object.");
|
|
44945
45405
|
}
|
|
44946
45406
|
const raw = value;
|
|
44947
45407
|
if ((raw == null ? void 0 : raw.programmaticName) != null && typeof raw.programmaticName !== "string") {
|
|
44948
|
-
throw new Error("
|
|
45408
|
+
throw new Error("Decision AI programmatic API key name must be a string.");
|
|
44949
45409
|
}
|
|
44950
45410
|
if ((raw == null ? void 0 : raw.environmentVariableName) != null && typeof raw.environmentVariableName !== "string") {
|
|
44951
|
-
throw new Error("
|
|
45411
|
+
throw new Error("Decision AI API key environment variable must be a string.");
|
|
44952
45412
|
}
|
|
44953
45413
|
const programmaticName = ((_a = raw == null ? void 0 : raw.programmaticName) == null ? void 0 : _a.trim()) || defaults.programmaticName;
|
|
44954
45414
|
const environmentVariableName = ((_b = raw == null ? void 0 : raw.environmentVariableName) == null ? void 0 : _b.trim()) || defaults.environmentVariableName;
|
|
44955
45415
|
if (!isValidClassifierProgrammaticCredentialName(programmaticName)) {
|
|
44956
45416
|
throw new Error(
|
|
44957
|
-
"
|
|
45417
|
+
"Decision AI programmatic API key name must be a JavaScript-style identifier without a leading digit."
|
|
44958
45418
|
);
|
|
44959
45419
|
}
|
|
44960
45420
|
if (!isValidClassifierEnvironmentCredentialName(environmentVariableName)) {
|
|
44961
45421
|
throw new Error(
|
|
44962
|
-
"
|
|
45422
|
+
"Decision AI API key environment variable must contain letters, digits, and _ without a leading digit."
|
|
44963
45423
|
);
|
|
44964
45424
|
}
|
|
44965
45425
|
return { programmaticName, environmentVariableName };
|
|
@@ -44984,11 +45444,11 @@ function resolveClassifierApiKey({
|
|
|
44984
45444
|
}) {
|
|
44985
45445
|
var _a, _b, _c, _d, _e;
|
|
44986
45446
|
if (apiKeySource === "classifier-settings") {
|
|
44987
|
-
const read = (value, key) => value !== null && typeof value === "object" ? classifierDataProperty(value, key, "
|
|
45447
|
+
const read = (value, key) => value !== null && typeof value === "object" ? classifierDataProperty(value, key, "Decision AI settings credentials") : void 0;
|
|
44988
45448
|
const saved = getNonEmptyString2(read(read(read(context.settings, "classifierProviders"), providerId), "apiKey"));
|
|
44989
45449
|
if (!saved)
|
|
44990
45450
|
throw new ClassifierCredentialMissingError(
|
|
44991
|
-
`
|
|
45451
|
+
`Decision AI settings API key for ${providerId} is not set. No automatic fallback is used.`
|
|
44992
45452
|
);
|
|
44993
45453
|
return saved;
|
|
44994
45454
|
}
|
|
@@ -44999,7 +45459,7 @@ function resolveClassifierApiKey({
|
|
|
44999
45459
|
return value;
|
|
45000
45460
|
}
|
|
45001
45461
|
if (apiKeySource !== void 0 && apiKeySource !== "configured")
|
|
45002
|
-
throw new Error("Unknown
|
|
45462
|
+
throw new Error("Unknown Decision AI API key source.");
|
|
45003
45463
|
const names = normalizeClassifierCredentialNames(apiKeyNames, defaults);
|
|
45004
45464
|
const namedValue = resolveNamedClassifierApiKey(
|
|
45005
45465
|
context,
|
|
@@ -45016,7 +45476,7 @@ function resolveClassifierApiKey({
|
|
|
45016
45476
|
}
|
|
45017
45477
|
}
|
|
45018
45478
|
throw new ClassifierCredentialMissingError(
|
|
45019
|
-
`${providerId === "jev" ? "Jev" : "
|
|
45479
|
+
`${providerId === "jev" ? "Jev" : "Decision AI"} API key is not set. Pass ${names.programmaticName}, configure ${names.environmentVariableName}, or set the configured key in Settings > Decision AI.`
|
|
45020
45480
|
);
|
|
45021
45481
|
}
|
|
45022
45482
|
function resolveNamedClassifierApiKey(context, names, useLegacyOpenAIKey = false) {
|
|
@@ -45037,316 +45497,12 @@ function getNonEmptyString2(value) {
|
|
|
45037
45497
|
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
45038
45498
|
}
|
|
45039
45499
|
|
|
45040
|
-
// src/model/classifier/images.ts
|
|
45041
|
-
var InvalidClassifierImageError = class extends Error {
|
|
45042
|
-
};
|
|
45043
|
-
var invalidImage = () => new InvalidClassifierImageError(
|
|
45044
|
-
"State images must contain inline base64 PNG, JPEG, GIF or WebP image data with valid headers and matching media type."
|
|
45045
|
-
);
|
|
45046
|
-
function isBase64(value) {
|
|
45047
|
-
return value.length > 0 && value.length % 4 === 0 && /^[A-Za-z0-9+/]+={0,2}$/.test(value);
|
|
45048
|
-
}
|
|
45049
|
-
function jpegInfo(size, read, check) {
|
|
45050
|
-
const byte = (offset2) => read(offset2, 1)[0];
|
|
45051
|
-
const uint16 = (offset2) => {
|
|
45052
|
-
const bytes = read(offset2, 2);
|
|
45053
|
-
return (bytes[0] << 8) + bytes[1];
|
|
45054
|
-
};
|
|
45055
|
-
let offset = 2;
|
|
45056
|
-
while (offset + 4 <= size) {
|
|
45057
|
-
check == null ? void 0 : check();
|
|
45058
|
-
if (byte(offset++) !== 255) break;
|
|
45059
|
-
while (byte(offset) === 255) {
|
|
45060
|
-
if ((offset & 4095) === 0) check == null ? void 0 : check();
|
|
45061
|
-
offset++;
|
|
45062
|
-
}
|
|
45063
|
-
const marker2 = byte(offset++);
|
|
45064
|
-
if (marker2 === void 0 || marker2 === 218 || marker2 === 217) break;
|
|
45065
|
-
if (marker2 === 1 || marker2 >= 208 && marker2 <= 215) continue;
|
|
45066
|
-
if (offset + 2 > size) break;
|
|
45067
|
-
const length = uint16(offset);
|
|
45068
|
-
if (length < 2 || offset + length > size) break;
|
|
45069
|
-
if ([192, 193, 194, 195, 197, 198, 199, 201, 202, 203, 205, 206, 207].includes(marker2) && length >= 8)
|
|
45070
|
-
return { mediaType: "image/jpeg", width: uint16(offset + 5), height: uint16(offset + 3) };
|
|
45071
|
-
offset += length;
|
|
45072
|
-
}
|
|
45073
|
-
return void 0;
|
|
45074
|
-
}
|
|
45075
|
-
function imageInfo(bytes, check) {
|
|
45076
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
45077
|
-
const ascii = (offset, length) => String.fromCharCode(...bytes.subarray(offset, offset + length));
|
|
45078
|
-
let info;
|
|
45079
|
-
if (bytes.length >= 33 && ascii(0, 8) === "\x89PNG\r\n\n" && view.getUint32(8) === 13 && ascii(12, 4) === "IHDR") {
|
|
45080
|
-
info = { mediaType: "image/png", width: view.getUint32(16), height: view.getUint32(20) };
|
|
45081
|
-
} else if (bytes.length >= 13 && ["GIF87a", "GIF89a"].includes(ascii(0, 6))) {
|
|
45082
|
-
info = { mediaType: "image/gif", width: view.getUint16(6, true), height: view.getUint16(8, true) };
|
|
45083
|
-
} else if (bytes.length >= 25 && ascii(0, 4) === "RIFF" && ascii(8, 4) === "WEBP") {
|
|
45084
|
-
const chunk = ascii(12, 4);
|
|
45085
|
-
const uint24 = (offset) => bytes[offset] + (bytes[offset + 1] << 8) + (bytes[offset + 2] << 16);
|
|
45086
|
-
if (chunk === "VP8X" && bytes.length >= 30)
|
|
45087
|
-
info = { mediaType: "image/webp", width: uint24(24) + 1, height: uint24(27) + 1 };
|
|
45088
|
-
else if (chunk === "VP8 " && bytes.length >= 30 && ascii(23, 3) === "\x9D*")
|
|
45089
|
-
info = {
|
|
45090
|
-
mediaType: "image/webp",
|
|
45091
|
-
width: view.getUint16(26, true) & 16383,
|
|
45092
|
-
height: view.getUint16(28, true) & 16383
|
|
45093
|
-
};
|
|
45094
|
-
else if (chunk === "VP8L" && bytes[20] === 47) {
|
|
45095
|
-
const bits = view.getUint32(21, true);
|
|
45096
|
-
info = { mediaType: "image/webp", width: (bits & 16383) + 1, height: (bits >>> 14 & 16383) + 1 };
|
|
45097
|
-
}
|
|
45098
|
-
} else if (bytes.length >= 4 && bytes[0] === 255 && bytes[1] === 216) {
|
|
45099
|
-
info = jpegInfo(bytes.length, (offset, length) => bytes.subarray(offset, offset + length), check);
|
|
45100
|
-
}
|
|
45101
|
-
if (!info || info.width === 0 || info.height === 0) throw invalidImage();
|
|
45102
|
-
return info;
|
|
45103
|
-
}
|
|
45104
|
-
function base64ImageInfo(payload, check) {
|
|
45105
|
-
if (payload.startsWith("/9j/")) {
|
|
45106
|
-
const size = payload.length / 4 * 3 - (payload.endsWith("==") ? 2 : payload.endsWith("=") ? 1 : 0);
|
|
45107
|
-
let start = -1;
|
|
45108
|
-
let window = new Uint8Array();
|
|
45109
|
-
const info = jpegInfo(
|
|
45110
|
-
size,
|
|
45111
|
-
(offset, length) => {
|
|
45112
|
-
if (offset < start || offset + length > start + window.length) {
|
|
45113
|
-
start = Math.floor(offset / 3) * 3;
|
|
45114
|
-
window = base64ToUint8Array(payload.slice(start / 3 * 4, start / 3 * 4 + 4096));
|
|
45115
|
-
}
|
|
45116
|
-
return window.subarray(offset - start, offset - start + length);
|
|
45117
|
-
},
|
|
45118
|
-
check
|
|
45119
|
-
);
|
|
45120
|
-
if (!info || info.width === 0 || info.height === 0) throw invalidImage();
|
|
45121
|
-
return info;
|
|
45122
|
-
}
|
|
45123
|
-
return imageInfo(base64ToUint8Array(payload.slice(0, 48)));
|
|
45124
|
-
}
|
|
45125
|
-
function prepareNativeClassifierImage(value, check) {
|
|
45126
|
-
if (!value || typeof value !== "object") throw invalidImage();
|
|
45127
|
-
const data = classifierDataProperty(value, "data");
|
|
45128
|
-
const mediaType = classifierDataProperty(value, "mediaType");
|
|
45129
|
-
if (!(data instanceof Uint8Array)) throw invalidImage();
|
|
45130
|
-
const bytes = classifierByteView(data);
|
|
45131
|
-
assertClassifierResourceLimits(bytes, check);
|
|
45132
|
-
const info = imageInfo(bytes, check);
|
|
45133
|
-
if (info.mediaType !== mediaType) throw invalidImage();
|
|
45134
|
-
check == null ? void 0 : check();
|
|
45135
|
-
return { ...info, dataUrl: `data:${info.mediaType};base64,${uint8ArrayToBase64Sync(bytes)}` };
|
|
45136
|
-
}
|
|
45137
|
-
function inspectClassifierImage(value, check) {
|
|
45138
|
-
check == null ? void 0 : check();
|
|
45139
|
-
if (typeof value !== "string") throw invalidImage();
|
|
45140
|
-
const prefix = /^data:(image\/(?:png|jpeg|gif|webp));base64,/.exec(value);
|
|
45141
|
-
if (!prefix) throw invalidImage();
|
|
45142
|
-
const payload = value.slice(prefix[0].length);
|
|
45143
|
-
if (!isBase64(payload)) throw invalidImage();
|
|
45144
|
-
const info = base64ImageInfo(payload, check);
|
|
45145
|
-
if (info.mediaType !== prefix[1]) throw invalidImage();
|
|
45146
|
-
return info;
|
|
45147
|
-
}
|
|
45148
|
-
function prepareClassifierImageText(value, check) {
|
|
45149
|
-
check == null ? void 0 : check();
|
|
45150
|
-
if (value.length > CLASSIFIER_LIMITS.requestBytes)
|
|
45151
|
-
throw new Error("Classifier image/text exceeds the 32 MiB input limit.");
|
|
45152
|
-
if (value.startsWith("data:image/")) {
|
|
45153
|
-
return { ...inspectClassifierImage(value, check), dataUrl: value };
|
|
45154
|
-
}
|
|
45155
|
-
if (!/^(?:iVBOR|\/9j\/|R0lGOD|UklGR)/.test(value) || !isBase64(value)) return void 0;
|
|
45156
|
-
try {
|
|
45157
|
-
const info = base64ImageInfo(value, check);
|
|
45158
|
-
return { ...info, dataUrl: `data:${info.mediaType};base64,${value}` };
|
|
45159
|
-
} catch (error) {
|
|
45160
|
-
if (error instanceof InvalidClassifierImageError) return void 0;
|
|
45161
|
-
throw error;
|
|
45162
|
-
}
|
|
45163
|
-
}
|
|
45164
|
-
function assertLiquidImageLimits(images, check) {
|
|
45165
|
-
if (images.length > 8) throw new Error("Liquid d1 State must contain at most 8 images.");
|
|
45166
|
-
let patches = 0;
|
|
45167
|
-
for (const { width, height } of images) {
|
|
45168
|
-
check == null ? void 0 : check();
|
|
45169
|
-
if (Math.max(width, height) / Math.min(width, height) > 100)
|
|
45170
|
-
throw new Error("Liquid d1 images must have an aspect ratio at most 100:1.");
|
|
45171
|
-
patches += Math.ceil(width / 32) * Math.ceil(height / 32);
|
|
45172
|
-
}
|
|
45173
|
-
if (patches > 1e4)
|
|
45174
|
-
throw new Error("Liquid d1 images must contain at most 10,000 patches of 32 by 32 pixels in total.");
|
|
45175
|
-
}
|
|
45176
|
-
|
|
45177
|
-
// src/model/classifier/state.ts
|
|
45178
|
-
var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
45179
|
-
var nativeImage = (value) => record(value) && (classifierDataProperty(value, "type") === "image" || "mediaType" in value && classifierDataProperty(value, "data") instanceof Uint8Array);
|
|
45180
|
-
var message = (value) => record(value) && "type" in value && "message" in value;
|
|
45181
|
-
function prepareClassifierState(input, budget) {
|
|
45182
|
-
if (input.stateInput !== void 0) {
|
|
45183
|
-
if (input.state !== "" || input.stateMessages !== void 0)
|
|
45184
|
-
throw new Error("Rivet State input and provider State cannot be supplied together.");
|
|
45185
|
-
return prepareRivetState(input.stateInput, budget);
|
|
45186
|
-
}
|
|
45187
|
-
if (input.stateMessages === void 0) {
|
|
45188
|
-
if (typeof input.state !== "string" && !record(input.state) && !Array.isArray(input.state))
|
|
45189
|
-
throw new Error("State must be text, a JSON object or an array.");
|
|
45190
|
-
return { kind: "json", value: snapshotClassifierJson(input.state, "State", budget) };
|
|
45191
|
-
}
|
|
45192
|
-
if (input.state !== "")
|
|
45193
|
-
throw new Error("Structured State and multimodal State messages cannot be supplied together.");
|
|
45194
|
-
const messages = snapshotClassifierJson(input.stateMessages, "State", budget);
|
|
45195
|
-
const images = inspectStateMessages(messages, budget.check);
|
|
45196
|
-
return { kind: "messages", messages, images };
|
|
45197
|
-
}
|
|
45198
|
-
function normalizeClassifierState(input, check, maxBytes) {
|
|
45199
|
-
const state = input === void 0 ? { kind: "json", value: "" } : prepareRivetState(input, new ClassifierValueBudget(check, maxBytes));
|
|
45200
|
-
return state.kind === "json" ? { state: state.value } : { state: "", stateMessages: state.messages };
|
|
45201
|
-
}
|
|
45202
|
-
function prepareRivetState(input, budget) {
|
|
45203
|
-
const check = budget.check;
|
|
45204
|
-
if (input === null || typeof input !== "object" || Array.isArray(input))
|
|
45205
|
-
throw new Error("State input must contain a Rivet data value.");
|
|
45206
|
-
const type = classifierDataProperty(input, "type");
|
|
45207
|
-
const value = classifierDataProperty(input, "value");
|
|
45208
|
-
if (typeof type !== "string") throw new Error("State input type must be a string.");
|
|
45209
|
-
if (![
|
|
45210
|
-
"string",
|
|
45211
|
-
"string[]",
|
|
45212
|
-
"image",
|
|
45213
|
-
"image[]",
|
|
45214
|
-
"chat-message",
|
|
45215
|
-
"chat-message[]",
|
|
45216
|
-
"object",
|
|
45217
|
-
"object[]",
|
|
45218
|
-
"any",
|
|
45219
|
-
"any[]"
|
|
45220
|
-
].includes(type))
|
|
45221
|
-
throw new Error(`Unsupported State input type '${type}'.`);
|
|
45222
|
-
if (type.endsWith("[]") && !Array.isArray(value)) throw new Error("State array input must contain an array.");
|
|
45223
|
-
if (type === "string" && typeof value !== "string") throw new Error("State string input must contain a string.");
|
|
45224
|
-
if (type === "object" && !record(value) && !Array.isArray(value))
|
|
45225
|
-
throw new Error("State object input must contain a JSON object or array.");
|
|
45226
|
-
if ((type === "image" || type === "chat-message") && Array.isArray(value))
|
|
45227
|
-
throw new Error("State scalar input must not contain an array.");
|
|
45228
|
-
if (type === "object" || type === "object[]")
|
|
45229
|
-
return { kind: "json", value: snapshotClassifierJson(value, "State", budget) };
|
|
45230
|
-
budget.inspect(value);
|
|
45231
|
-
const imageTexts = /* @__PURE__ */ new Map();
|
|
45232
|
-
const textImage = (text2) => {
|
|
45233
|
-
const image = imageTexts.get(text2) ?? prepareClassifierImageText(text2, check);
|
|
45234
|
-
if (image) imageTexts.set(text2, image);
|
|
45235
|
-
return image;
|
|
45236
|
-
};
|
|
45237
|
-
const hasContent = (item) => nativeImage(item) || message(item) || typeof item === "string" && textImage(item) !== void 0;
|
|
45238
|
-
const arrayHasContent = () => {
|
|
45239
|
-
for (const item of classifierArrayValues(value, "State")) {
|
|
45240
|
-
check();
|
|
45241
|
-
if (hasContent(item)) return true;
|
|
45242
|
-
}
|
|
45243
|
-
return false;
|
|
45244
|
-
};
|
|
45245
|
-
const contentType = ["image", "image[]", "string[]", "chat-message", "chat-message[]"].includes(type);
|
|
45246
|
-
const inferredContent = (type === "any" || type === "any[]") && (hasContent(value) || Array.isArray(value) && arrayHasContent());
|
|
45247
|
-
if (!(contentType || inferredContent || type === "string" && textImage(value))) {
|
|
45248
|
-
if (typeof value !== "string" && !record(value) && !Array.isArray(value))
|
|
45249
|
-
throw new Error("State must be text, a JSON object/array, images, or user messages.");
|
|
45250
|
-
return {
|
|
45251
|
-
kind: "json",
|
|
45252
|
-
value: typeof value === "string" ? value : snapshotClassifierJson(value, "State", new ClassifierValueBudget(check))
|
|
45253
|
-
};
|
|
45254
|
-
}
|
|
45255
|
-
const values2 = Array.isArray(value) ? value : [value];
|
|
45256
|
-
if (type === "image[]" && values2.length > 128) throw new Error("State must contain at most 128 images.");
|
|
45257
|
-
const messages = [];
|
|
45258
|
-
const images = [];
|
|
45259
|
-
let partCount = 0;
|
|
45260
|
-
const imagePart = (prepare) => {
|
|
45261
|
-
if (images.length >= 128) throw new Error("State must contain at most 128 images.");
|
|
45262
|
-
const image = prepare();
|
|
45263
|
-
images.push(image);
|
|
45264
|
-
return { type: "image", dataUrl: image.dataUrl };
|
|
45265
|
-
};
|
|
45266
|
-
let parts = [];
|
|
45267
|
-
const flush = () => {
|
|
45268
|
-
if (parts.length) {
|
|
45269
|
-
if (messages.length >= CLASSIFIER_LIMITS.messages) throw new Error("State has too many messages.");
|
|
45270
|
-
messages.push({ parts });
|
|
45271
|
-
parts = [];
|
|
45272
|
-
}
|
|
45273
|
-
};
|
|
45274
|
-
const part = (item) => {
|
|
45275
|
-
check();
|
|
45276
|
-
if (++partCount > CLASSIFIER_LIMITS.parts) throw new Error("State has too many content parts.");
|
|
45277
|
-
if (typeof item === "string") {
|
|
45278
|
-
const image = textImage(item);
|
|
45279
|
-
return image ? imagePart(() => image) : { type: "text", text: item };
|
|
45280
|
-
}
|
|
45281
|
-
if (nativeImage(item)) return imagePart(() => prepareNativeClassifierImage(item, check));
|
|
45282
|
-
throw new Error("Multimodal State accepts only text, native images, image data URLs, and user messages.");
|
|
45283
|
-
};
|
|
45284
|
-
for (const item of classifierArrayValues(values2, "State")) {
|
|
45285
|
-
check();
|
|
45286
|
-
if (type === "image" || type === "image[]") {
|
|
45287
|
-
if (++partCount > CLASSIFIER_LIMITS.parts) throw new Error("State has too many content parts.");
|
|
45288
|
-
parts.push(imagePart(() => prepareNativeClassifierImage(item, check)));
|
|
45289
|
-
} else if (type === "string[]" && typeof item !== "string") {
|
|
45290
|
-
throw new Error("State string array must contain only strings.");
|
|
45291
|
-
} else if (message(item)) {
|
|
45292
|
-
if (classifierDataProperty(item, "type") !== "user" || "function_call" in item || "function_calls" in item)
|
|
45293
|
-
throw new Error(
|
|
45294
|
-
"Classifier State supports only user messages, not system, developer, assistant, or tool messages."
|
|
45295
|
-
);
|
|
45296
|
-
flush();
|
|
45297
|
-
if (messages.length >= CLASSIFIER_LIMITS.messages) throw new Error("State has too many messages.");
|
|
45298
|
-
const contentValue = classifierDataProperty(item, "message");
|
|
45299
|
-
const content = Array.isArray(contentValue) ? contentValue : [contentValue];
|
|
45300
|
-
messages.push({
|
|
45301
|
-
parts: content.length ? Array.from(classifierArrayValues(content, "State"), part) : [{ type: "text", text: "" }]
|
|
45302
|
-
});
|
|
45303
|
-
} else {
|
|
45304
|
-
if (type === "chat-message" || type === "chat-message[]")
|
|
45305
|
-
throw new Error("State must contain valid user messages.");
|
|
45306
|
-
parts.push(part(item));
|
|
45307
|
-
}
|
|
45308
|
-
}
|
|
45309
|
-
flush();
|
|
45310
|
-
return messages.length ? { kind: "messages", messages, images } : { kind: "json", value: "" };
|
|
45311
|
-
}
|
|
45312
|
-
function inspectStateMessages(messages, check) {
|
|
45313
|
-
if (!Array.isArray(messages)) throw new Error("State messages must be an array.");
|
|
45314
|
-
if (messages.length > CLASSIFIER_LIMITS.messages) throw new Error("State has too many messages.");
|
|
45315
|
-
const images = [];
|
|
45316
|
-
let parts = 0;
|
|
45317
|
-
for (const message2 of messages) {
|
|
45318
|
-
if (!record(message2) || !Array.isArray(message2.parts)) throw new Error("State message parts must be an array.");
|
|
45319
|
-
for (const part of message2.parts) {
|
|
45320
|
-
check();
|
|
45321
|
-
if (++parts > CLASSIFIER_LIMITS.parts) throw new Error("State has too many content parts.");
|
|
45322
|
-
if (!record(part)) throw new Error("Invalid State content part.");
|
|
45323
|
-
if (part.type === "image" && typeof part.dataUrl === "string") {
|
|
45324
|
-
if (images.length >= 128) throw new Error("State must contain at most 128 images.");
|
|
45325
|
-
images.push({ ...inspectClassifierImage(part.dataUrl, check), dataUrl: part.dataUrl });
|
|
45326
|
-
} else if (part.type !== "text" || typeof part.text !== "string") throw new Error("Invalid State content part.");
|
|
45327
|
-
}
|
|
45328
|
-
}
|
|
45329
|
-
return images;
|
|
45330
|
-
}
|
|
45331
|
-
function systemOneState(input) {
|
|
45332
|
-
if (!input.stateMessages) return { state: input.state };
|
|
45333
|
-
const images = [];
|
|
45334
|
-
const state = input.stateMessages.map(
|
|
45335
|
-
({ parts }) => parts.map((part) => {
|
|
45336
|
-
if (part.type === "text") return part.text;
|
|
45337
|
-
images.push(part.dataUrl);
|
|
45338
|
-
return `[Image ${images.length}]`;
|
|
45339
|
-
}).join("\n")
|
|
45340
|
-
).join("\n\n");
|
|
45341
|
-
return { state, ...images.length ? { images } : {} };
|
|
45342
|
-
}
|
|
45343
|
-
|
|
45344
45500
|
// src/model/classifier/response.ts
|
|
45345
45501
|
function isRecord9(value) {
|
|
45346
45502
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45347
45503
|
}
|
|
45348
|
-
function responseField(
|
|
45349
|
-
return Object.prototype.hasOwnProperty.call(
|
|
45504
|
+
function responseField(record4, key) {
|
|
45505
|
+
return Object.prototype.hasOwnProperty.call(record4, key) ? record4[key] : void 0;
|
|
45350
45506
|
}
|
|
45351
45507
|
function requireResponseNumber(value, label, providerLabel) {
|
|
45352
45508
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
@@ -45365,10 +45521,10 @@ function requireProbabilityMap(value, keys2, label, providerLabel) {
|
|
|
45365
45521
|
const probabilities = requireResponseMap(value, keys2, label, providerLabel);
|
|
45366
45522
|
for (const key of keys2) requireResponseNumber(probabilities[key], `${label}.${key}`, providerLabel);
|
|
45367
45523
|
}
|
|
45368
|
-
function validateApiCompatibleClassifierResponse(body, questions, providerLabel = "
|
|
45524
|
+
function validateApiCompatibleClassifierResponse(body, questions, providerLabel = "Decision AI provider") {
|
|
45369
45525
|
return validateClassifierEvaluationResponse(body, questions, providerLabel);
|
|
45370
45526
|
}
|
|
45371
|
-
function validateClassifierEvaluationResponse(body, questions, providerLabel = "
|
|
45527
|
+
function validateClassifierEvaluationResponse(body, questions, providerLabel = "Decision AI provider") {
|
|
45372
45528
|
const model = isRecord9(body) ? responseField(body, "model") : void 0;
|
|
45373
45529
|
const answers = isRecord9(body) ? responseField(body, "answers") : void 0;
|
|
45374
45530
|
const usage = isRecord9(body) ? responseField(body, "usage") : void 0;
|
|
@@ -45409,6 +45565,16 @@ function validateClassifierEvaluationResponse(body, questions, providerLabel = "
|
|
|
45409
45565
|
providerLabel
|
|
45410
45566
|
);
|
|
45411
45567
|
requireResponseMap(responseField(answer, "legend"), keys2, `${question.questionId}.legend`, providerLabel);
|
|
45568
|
+
} else if (question.type === "box") {
|
|
45569
|
+
const box = requireResponseMap(
|
|
45570
|
+
responseField(answer, "box"),
|
|
45571
|
+
["top", "bottom", "left", "right"],
|
|
45572
|
+
`${question.questionId}.box`,
|
|
45573
|
+
providerLabel
|
|
45574
|
+
);
|
|
45575
|
+
for (const edge of ["top", "bottom", "left", "right"])
|
|
45576
|
+
requireResponseNumber(box[edge], `${question.questionId}.box.${edge}`, providerLabel);
|
|
45577
|
+
requireResponseNumber(responseField(answer, "confidence"), `${question.questionId}.confidence`, providerLabel);
|
|
45412
45578
|
} else {
|
|
45413
45579
|
requireResponseNumber(responseField(answer, "noul"), `${question.questionId}.noul`, providerLabel);
|
|
45414
45580
|
}
|
|
@@ -45433,7 +45599,14 @@ function createOpenAIDecisionRequest(args) {
|
|
|
45433
45599
|
)
|
|
45434
45600
|
})) : typeof state.value === "string" ? state.value : JSON.stringify(state.value),
|
|
45435
45601
|
questions: args.questions.map((question) => {
|
|
45436
|
-
|
|
45602
|
+
if (question.type === "box") throw new Error("OpenAI Decisions does not support Bounding Box questions.");
|
|
45603
|
+
const instructions = question.instructionsMessages ? question.instructionsMessages.flatMap(({ parts }, index) => [
|
|
45604
|
+
...index ? [{ type: "input_text", text: "\n\n" }] : [],
|
|
45605
|
+
...parts.map(
|
|
45606
|
+
(part) => part.type === "text" ? { type: "input_text", text: part.text } : { type: "input_image", image_url: part.dataUrl }
|
|
45607
|
+
)
|
|
45608
|
+
]) : text(question.instructions);
|
|
45609
|
+
const common = { name: question.questionId, instructions };
|
|
45437
45610
|
if (question.type === "choice")
|
|
45438
45611
|
return {
|
|
45439
45612
|
...common,
|
|
@@ -45453,10 +45626,19 @@ function createOpenAIDecisionRequest(args) {
|
|
|
45453
45626
|
return {
|
|
45454
45627
|
...common,
|
|
45455
45628
|
type: "predicate",
|
|
45456
|
-
instructions: criteria ? `${
|
|
45629
|
+
instructions: criteria ? typeof instructions === "string" ? `${instructions}
|
|
45457
45630
|
|
|
45458
45631
|
True criterion: ${text(criteria.true)}
|
|
45459
|
-
False criterion: ${text(criteria.false)}` :
|
|
45632
|
+
False criterion: ${text(criteria.false)}` : [
|
|
45633
|
+
...instructions,
|
|
45634
|
+
{
|
|
45635
|
+
type: "input_text",
|
|
45636
|
+
text: `
|
|
45637
|
+
|
|
45638
|
+
True criterion: ${text(criteria.true)}
|
|
45639
|
+
False criterion: ${text(criteria.false)}`
|
|
45640
|
+
}
|
|
45641
|
+
] : common.instructions
|
|
45460
45642
|
};
|
|
45461
45643
|
})
|
|
45462
45644
|
};
|
|
@@ -45569,60 +45751,165 @@ function assertPerplexityDecisionLimits({ model, state, questions }, check) {
|
|
|
45569
45751
|
for (const part of Array.isArray(state.value) ? state.value : [state.value]) {
|
|
45570
45752
|
check();
|
|
45571
45753
|
if (!part || typeof part !== "object" || Array.isArray(part)) continue;
|
|
45572
|
-
const
|
|
45573
|
-
if (
|
|
45754
|
+
const record4 = part;
|
|
45755
|
+
if (record4.type !== "image_url") continue;
|
|
45574
45756
|
if (++imageCount > 128) throw new Error("State must contain at most 128 images.");
|
|
45575
|
-
const image =
|
|
45757
|
+
const image = record4.image_url;
|
|
45576
45758
|
const url = image && typeof image === "object" && !Array.isArray(image) ? image.url : void 0;
|
|
45577
45759
|
inspect(inspectClassifierImage(url, check));
|
|
45578
45760
|
}
|
|
45579
45761
|
}
|
|
45580
45762
|
|
|
45581
|
-
// src/model/classifier/
|
|
45582
|
-
|
|
45583
|
-
|
|
45584
|
-
|
|
45585
|
-
|
|
45586
|
-
|
|
45587
|
-
|
|
45588
|
-
|
|
45589
|
-
|
|
45763
|
+
// src/model/classifier/jev.ts
|
|
45764
|
+
var JEV_IMAGE_MODELS = ["jev-latest", "jev-preview", "jev-1.13.0", "jev-1.14.0"];
|
|
45765
|
+
var JEV_BOX_MODELS = ["jev-latest", "jev-preview", "jev-1.14.0"];
|
|
45766
|
+
function assertJevImageLimits(images, check) {
|
|
45767
|
+
for (const { dataUrl, mediaType, width, height } of images) {
|
|
45768
|
+
check();
|
|
45769
|
+
if (mediaType !== "image/png" && mediaType !== "image/jpeg")
|
|
45770
|
+
throw new Error("Jev images must be still PNG or JPEG. Convert other formats upstream.");
|
|
45771
|
+
if (Math.min(width, height) < 280 || Math.max(width, height) > 1568)
|
|
45772
|
+
throw new Error("Jev image width and height must each be between 280 and 1568 pixels. Resize upstream.");
|
|
45773
|
+
const payload = dataUrl.slice(dataUrl.indexOf(",") + 1);
|
|
45774
|
+
const bytes = payload.length / 4 * 3 - (payload.endsWith("==") ? 2 : payload.endsWith("=") ? 1 : 0);
|
|
45775
|
+
if (bytes > 16 * 1024 * 1024) throw new Error("Jev image files must not exceed 16 MiB decoded.");
|
|
45590
45776
|
}
|
|
45591
|
-
|
|
45592
|
-
|
|
45593
|
-
|
|
45594
|
-
|
|
45595
|
-
|
|
45596
|
-
|
|
45597
|
-
|
|
45598
|
-
|
|
45599
|
-
|
|
45600
|
-
|
|
45601
|
-
|
|
45602
|
-
|
|
45603
|
-
|
|
45604
|
-
|
|
45605
|
-
|
|
45606
|
-
|
|
45607
|
-
|
|
45608
|
-
|
|
45609
|
-
|
|
45610
|
-
|
|
45611
|
-
|
|
45612
|
-
|
|
45613
|
-
|
|
45614
|
-
|
|
45615
|
-
|
|
45616
|
-
|
|
45617
|
-
|
|
45618
|
-
|
|
45619
|
-
|
|
45620
|
-
|
|
45621
|
-
|
|
45622
|
-
|
|
45623
|
-
|
|
45777
|
+
}
|
|
45778
|
+
function createJevDecisionRequest({
|
|
45779
|
+
model,
|
|
45780
|
+
state,
|
|
45781
|
+
questions
|
|
45782
|
+
}) {
|
|
45783
|
+
const references = /* @__PURE__ */ new Map();
|
|
45784
|
+
const assets = {};
|
|
45785
|
+
const messagesText = (messages) => messages.map(
|
|
45786
|
+
({ parts }) => parts.map((part) => {
|
|
45787
|
+
if (part.type === "text") return part.text;
|
|
45788
|
+
let reference = references.get(part.dataUrl);
|
|
45789
|
+
if (!reference) {
|
|
45790
|
+
reference = globalThis.crypto.randomUUID();
|
|
45791
|
+
references.set(part.dataUrl, reference);
|
|
45792
|
+
assets[reference] = {
|
|
45793
|
+
type: "image",
|
|
45794
|
+
format: part.dataUrl.startsWith("data:image/png;") ? "png" : "jpg",
|
|
45795
|
+
data_base64: part.dataUrl.slice(part.dataUrl.indexOf(",") + 1)
|
|
45796
|
+
};
|
|
45797
|
+
}
|
|
45798
|
+
return reference;
|
|
45799
|
+
}).join("\n")
|
|
45800
|
+
).join("\n\n");
|
|
45801
|
+
const value = state.kind === "json" ? state.value : messagesText(state.messages);
|
|
45802
|
+
const questionMap = createQuestionMap(
|
|
45803
|
+
questions,
|
|
45804
|
+
(question) => question.instructionsMessages ? messagesText(question.instructionsMessages) : question.instructions
|
|
45805
|
+
);
|
|
45806
|
+
return { model, state: value, questions: questionMap, ...references.size ? { assets } : {} };
|
|
45807
|
+
}
|
|
45808
|
+
|
|
45809
|
+
// src/model/classifier/subq.ts
|
|
45810
|
+
var SUBQ_DECISION_MODELS = ["subq-snap-1.1"];
|
|
45811
|
+
function subqDecisionState(state) {
|
|
45812
|
+
if (state.kind === "json") return { state: state.value };
|
|
45813
|
+
const wire = systemOneState({ state: "", stateMessages: state.messages });
|
|
45814
|
+
return {
|
|
45815
|
+
state: wire.state,
|
|
45816
|
+
...state.images.length ? {
|
|
45817
|
+
images: state.images.map(({ mediaType, dataUrl }) => ({
|
|
45818
|
+
mediaType,
|
|
45819
|
+
base64: dataUrl.slice(dataUrl.indexOf(",") + 1)
|
|
45820
|
+
}))
|
|
45821
|
+
} : {}
|
|
45822
|
+
};
|
|
45823
|
+
}
|
|
45824
|
+
function assertSubQDecisionLimits({ state, questions }, check) {
|
|
45825
|
+
if (questions.length > 128) throw new Error("SubQ Snap supports at most 128 questions per request.");
|
|
45826
|
+
for (const question of questions) {
|
|
45827
|
+
let characters = 0;
|
|
45828
|
+
for (const _character of question.questionId) {
|
|
45829
|
+
check();
|
|
45830
|
+
if (++characters > 100) throw new Error("SubQ Snap question IDs must contain at most 100 characters.");
|
|
45831
|
+
}
|
|
45832
|
+
}
|
|
45833
|
+
if (state.kind !== "messages") return;
|
|
45834
|
+
if (state.images.length > 4) throw new Error("SubQ Snap supports at most 4 images per request.");
|
|
45835
|
+
let total = 0;
|
|
45836
|
+
for (const { mediaType, dataUrl } of state.images) {
|
|
45837
|
+
check();
|
|
45838
|
+
if (!["image/png", "image/jpeg", "image/webp"].includes(mediaType))
|
|
45839
|
+
throw new Error("SubQ Snap accepts PNG, JPEG and WebP images, not GIF.");
|
|
45840
|
+
const payload = dataUrl.slice(dataUrl.indexOf(",") + 1);
|
|
45841
|
+
const bytes = payload.length / 4 * 3 - (payload.endsWith("==") ? 2 : payload.endsWith("=") ? 1 : 0);
|
|
45842
|
+
if (bytes > 4 * 1024 * 1024) throw new Error("SubQ Snap images must not exceed 4 MiB decoded each.");
|
|
45843
|
+
total += bytes;
|
|
45844
|
+
}
|
|
45845
|
+
if (total > 8 * 1024 * 1024) throw new Error("SubQ Snap images must not exceed 8 MiB decoded in total.");
|
|
45846
|
+
}
|
|
45847
|
+
|
|
45848
|
+
// src/model/classifier/baseten.ts
|
|
45849
|
+
var BASETEN_DECISION_MODELS = [
|
|
45850
|
+
"decision-models/baseten-elephant-9b-latest",
|
|
45851
|
+
"decision-models/baseten-mammoth-27b-latest"
|
|
45852
|
+
];
|
|
45853
|
+
function basetenDecisionState(state) {
|
|
45854
|
+
if (state.kind === "json") return state.value;
|
|
45855
|
+
return {
|
|
45856
|
+
messages: state.messages.map(({ parts }) => ({
|
|
45857
|
+
role: "user",
|
|
45858
|
+
content: parts.map(
|
|
45859
|
+
(part) => part.type === "text" ? { type: "text", text: part.text } : { type: "image_url", image_url: { url: part.dataUrl } }
|
|
45860
|
+
)
|
|
45861
|
+
}))
|
|
45862
|
+
};
|
|
45863
|
+
}
|
|
45864
|
+
var record3 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
45865
|
+
function assertBasetenDecisionLimits({ model, state, questions }, check) {
|
|
45866
|
+
let options2 = 0;
|
|
45867
|
+
for (const question of questions) {
|
|
45868
|
+
check();
|
|
45869
|
+
options2 += question.type === "noul" ? 2 : Object.keys(question.criteria ?? {}).length;
|
|
45870
|
+
}
|
|
45871
|
+
if (options2 > 512) throw new Error("Baseten supports at most 512 options across all questions; Noul counts as two.");
|
|
45872
|
+
const wire = basetenDecisionState(state);
|
|
45873
|
+
let characters = 0, images = 0;
|
|
45874
|
+
const text2 = (value) => {
|
|
45875
|
+
for (const _character of value) {
|
|
45876
|
+
check();
|
|
45877
|
+
if (++characters > 5e4) throw new Error("Baseten rendered State must fit within 50,000 characters.");
|
|
45878
|
+
}
|
|
45879
|
+
};
|
|
45880
|
+
if (!record3(wire) || !Array.isArray(wire.messages)) {
|
|
45881
|
+
text2(typeof wire === "string" ? wire : JSON.stringify(wire));
|
|
45882
|
+
return;
|
|
45883
|
+
}
|
|
45884
|
+
for (const message2 of wire.messages) {
|
|
45885
|
+
check();
|
|
45886
|
+
if (!record3(message2) || message2.role !== "user" && message2.role !== "assistant")
|
|
45887
|
+
throw new Error("Baseten State messages must have user or assistant roles.");
|
|
45888
|
+
if (typeof message2.content === "string") {
|
|
45889
|
+
text2(message2.content);
|
|
45890
|
+
continue;
|
|
45891
|
+
}
|
|
45892
|
+
if (!Array.isArray(message2.content)) throw new Error("Baseten message content must be text or content parts.");
|
|
45893
|
+
for (const part of message2.content) {
|
|
45894
|
+
check();
|
|
45895
|
+
if (!record3(part)) throw new Error("Invalid Baseten State content part.");
|
|
45896
|
+
if (part.type === "text" && typeof part.text === "string") {
|
|
45897
|
+
text2(part.text);
|
|
45898
|
+
continue;
|
|
45899
|
+
}
|
|
45900
|
+
if (part.type !== "image_url" || !record3(part.image_url))
|
|
45901
|
+
throw new Error("Baseten State supports text and image_url parts only.");
|
|
45902
|
+
if (message2.role !== "user") throw new Error("Baseten accepts images in user messages only.");
|
|
45903
|
+
if (!BASETEN_DECISION_MODELS.some((id) => id === model))
|
|
45904
|
+
throw new Error("Image support is not known for this Baseten model.");
|
|
45905
|
+
if (++images > 4) throw new Error("Baseten supports at most four images per request.");
|
|
45906
|
+
if (part.image_url.detail !== void 0 && part.image_url.detail !== "auto")
|
|
45907
|
+
throw new Error("Baseten image detail must be auto or omitted.");
|
|
45908
|
+
const image = inspectClassifierImage(part.image_url.url, check);
|
|
45909
|
+
if (!["image/png", "image/jpeg", "image/webp"].includes(image.mediaType))
|
|
45910
|
+
throw new Error("Baseten accepts PNG, JPEG and WebP images, not GIF.");
|
|
45911
|
+
}
|
|
45624
45912
|
}
|
|
45625
|
-
return question;
|
|
45626
45913
|
}
|
|
45627
45914
|
|
|
45628
45915
|
// src/model/classifier/providers.ts
|
|
@@ -45631,12 +45918,14 @@ var LIQUID_SYSTEM_ONE_ENDPOINT = "https://api.liquid.ai/decisions/v1/systemone";
|
|
|
45631
45918
|
var OPENAI_DECISIONS_ENDPOINT = "https://api.openai.com/v1/decisions";
|
|
45632
45919
|
var OPENROUTER_DECISIONS_ENDPOINT = "https://openrouter.ai/api/alpha/decisions";
|
|
45633
45920
|
var PERPLEXITY_DECISIONS_ENDPOINT = "https://api.perplexity.ai/v1/decisions";
|
|
45921
|
+
var SUBQ_DECISIONS_ENDPOINT = "https://api.subq.ai/v1/systemone";
|
|
45922
|
+
var BASETEN_DECISIONS_ENDPOINT = "https://inference.baseten.co/v1/systemone";
|
|
45634
45923
|
var JEV_TOKEN_PRICING = {
|
|
45635
45924
|
inputPerMillionTokens: 0.042,
|
|
45636
45925
|
outputPerMillionTokens: 0
|
|
45637
45926
|
};
|
|
45638
45927
|
var LIQUID_TOKEN_PRICING = {
|
|
45639
|
-
inputPerMillionTokens: 0.
|
|
45928
|
+
inputPerMillionTokens: 0.02,
|
|
45640
45929
|
outputPerMillionTokens: 0
|
|
45641
45930
|
};
|
|
45642
45931
|
var TOKENS_PER_MILLION = 1e6;
|
|
@@ -45657,22 +45946,46 @@ function createApiCompatibleClassifierProvider(config) {
|
|
|
45657
45946
|
validateResponse: validateClassifierEvaluationResponse
|
|
45658
45947
|
});
|
|
45659
45948
|
}
|
|
45660
|
-
var jevClassifierProvider =
|
|
45949
|
+
var jevClassifierProvider = createClassifierProvider({
|
|
45661
45950
|
id: "jev",
|
|
45662
45951
|
label: "Jev",
|
|
45663
45952
|
defaultModel: "jev-latest",
|
|
45953
|
+
modelOptions: ["jev-latest", "jev-preview", "jev-1.14.0", "jev-1.13.0"].map((value) => ({ value, label: value })),
|
|
45954
|
+
modelHelp: "Jev images are experimental: use still PNG/JPEG, 280\u20131568 pixels per side. Image requests enable TypeSafe\u2019s experimental image API.",
|
|
45664
45955
|
credentialNames: JEV_DEFAULT_CREDENTIAL_NAMES,
|
|
45665
45956
|
endpoint: JEV_SYSTEM_ONE_ENDPOINT,
|
|
45666
|
-
|
|
45957
|
+
browserExecutionSupported: false,
|
|
45958
|
+
modelPricing: [{ models: ["jev-latest", "jev-preview", "jev-1.13.0", "jev-1.14.0"], pricing: JEV_TOKEN_PRICING }],
|
|
45959
|
+
supportsImages: (model) => JEV_IMAGE_MODELS.includes(model),
|
|
45960
|
+
supportsQuestionImages: (model) => JEV_IMAGE_MODELS.includes(model),
|
|
45961
|
+
supportsBoxQuestions: (model) => JEV_BOX_MODELS.includes(model),
|
|
45962
|
+
checkState: (state, check) => {
|
|
45963
|
+
if (state.kind === "messages") assertJevImageLimits(state.images, check);
|
|
45964
|
+
},
|
|
45965
|
+
checkRequest: ({ questions }, check) => {
|
|
45966
|
+
for (const question of questions)
|
|
45967
|
+
if (question.instructionsMessages)
|
|
45968
|
+
assertJevImageLimits(inspectStateMessages(question.instructionsMessages, check), check);
|
|
45969
|
+
},
|
|
45970
|
+
buildRequest: createJevDecisionRequest,
|
|
45971
|
+
requestHeaders: ({ state, questions }) => state.kind === "messages" && state.images.length || questions.some(
|
|
45972
|
+
(question) => {
|
|
45973
|
+
var _a;
|
|
45974
|
+
return question.type === "box" || ((_a = question.instructionsMessages) == null ? void 0 : _a.some(({ parts }) => parts.some((part) => part.type === "image")));
|
|
45975
|
+
}
|
|
45976
|
+
) ? { "TypeSafe-Danger-Zone-Images": "true" } : {},
|
|
45977
|
+
validateResponse: validateClassifierEvaluationResponse
|
|
45667
45978
|
});
|
|
45668
45979
|
var liquidClassifierProvider = createApiCompatibleClassifierProvider({
|
|
45669
45980
|
id: "liquid",
|
|
45670
45981
|
label: "Liquid AI",
|
|
45671
45982
|
defaultModel: "d1",
|
|
45983
|
+
modelOptions: ["d1", "d1.1"].map((value) => ({ value, label: value })),
|
|
45984
|
+
modelHelp: "Images belong in shared State, not Question Instructions.",
|
|
45672
45985
|
credentialNames: LIQUID_DEFAULT_CREDENTIAL_NAMES,
|
|
45673
45986
|
endpoint: LIQUID_SYSTEM_ONE_ENDPOINT,
|
|
45674
45987
|
modelPricing: [{ models: ["d1"], pricing: LIQUID_TOKEN_PRICING }],
|
|
45675
|
-
supportsImages: (model) => model === "d1",
|
|
45988
|
+
supportsImages: (model) => model === "d1" || model === "d1.1",
|
|
45676
45989
|
maxRequestBytes: 45e5,
|
|
45677
45990
|
checkState: (state, check) => {
|
|
45678
45991
|
if (state.kind === "messages") assertLiquidImageLimits(state.images, check);
|
|
@@ -45682,6 +45995,7 @@ var openrouterClassifierProvider = createApiCompatibleClassifierProvider({
|
|
|
45682
45995
|
id: "openrouter",
|
|
45683
45996
|
label: "OpenRouter",
|
|
45684
45997
|
defaultModel: "microsoft/microsoft-decision-1",
|
|
45998
|
+
modelOptions: [{ value: "microsoft/microsoft-decision-1", label: "Microsoft Decision-1" }],
|
|
45685
45999
|
credentialNames: OPENROUTER_DEFAULT_CREDENTIAL_NAMES,
|
|
45686
46000
|
endpoint: OPENROUTER_DECISIONS_ENDPOINT,
|
|
45687
46001
|
modelPricing: [
|
|
@@ -45695,10 +46009,12 @@ var openaiClassifierProvider = createClassifierProvider({
|
|
|
45695
46009
|
id: "openai",
|
|
45696
46010
|
label: "OpenAI",
|
|
45697
46011
|
defaultModel: "gpt-6-luna",
|
|
46012
|
+
modelOptions: [{ value: "gpt-6-luna", label: "gpt-6-luna" }],
|
|
45698
46013
|
credentialNames: OPENAI_DEFAULT_CREDENTIAL_NAMES,
|
|
45699
46014
|
browserExecutionSupported: false,
|
|
45700
46015
|
endpoint: OPENAI_DECISIONS_ENDPOINT,
|
|
45701
46016
|
supportsImages: (model) => model === "gpt-6-luna",
|
|
46017
|
+
supportsQuestionImages: (model) => model === "gpt-6-luna",
|
|
45702
46018
|
modelPricing: [
|
|
45703
46019
|
{
|
|
45704
46020
|
models: ["gpt-6-luna"],
|
|
@@ -45716,6 +46032,7 @@ var perplexityClassifierProvider = createClassifierProvider({
|
|
|
45716
46032
|
id: "perplexity",
|
|
45717
46033
|
label: "Perplexity",
|
|
45718
46034
|
defaultModel: "pplx-decider-v1.1-27b",
|
|
46035
|
+
modelOptions: PERPLEXITY_DECISION_MODELS.map((value) => ({ value, label: value })),
|
|
45719
46036
|
credentialNames: PERPLEXITY_DEFAULT_CREDENTIAL_NAMES,
|
|
45720
46037
|
browserExecutionSupported: false,
|
|
45721
46038
|
endpoint: PERPLEXITY_DECISIONS_ENDPOINT,
|
|
@@ -45734,19 +46051,62 @@ var perplexityClassifierProvider = createClassifierProvider({
|
|
|
45734
46051
|
}),
|
|
45735
46052
|
validateResponse: validateClassifierEvaluationResponse
|
|
45736
46053
|
});
|
|
46054
|
+
var subqClassifierProvider = createClassifierProvider({
|
|
46055
|
+
id: "subq",
|
|
46056
|
+
label: "SubQ",
|
|
46057
|
+
defaultModel: "subq-snap-1.1",
|
|
46058
|
+
modelOptions: SUBQ_DECISION_MODELS.map((value) => ({ value, label: value })),
|
|
46059
|
+
credentialNames: SUBQ_DEFAULT_CREDENTIAL_NAMES,
|
|
46060
|
+
browserExecutionSupported: false,
|
|
46061
|
+
endpoint: SUBQ_DECISIONS_ENDPOINT,
|
|
46062
|
+
supportsImages: (model) => SUBQ_DECISION_MODELS.includes(model),
|
|
46063
|
+
modelPricing: [{ models: SUBQ_DECISION_MODELS, pricing: { inputPerMillionTokens: 0.04, outputPerMillionTokens: 0 } }],
|
|
46064
|
+
maxRequestBytes: 13 * 1024 * 1024,
|
|
46065
|
+
checkRequest: assertSubQDecisionLimits,
|
|
46066
|
+
buildRequest: ({ model, state, questions }) => ({
|
|
46067
|
+
model,
|
|
46068
|
+
...subqDecisionState(state),
|
|
46069
|
+
questions: createQuestionMap(questions)
|
|
46070
|
+
}),
|
|
46071
|
+
validateResponse: validateClassifierEvaluationResponse
|
|
46072
|
+
});
|
|
46073
|
+
var basetenClassifierProvider = createClassifierProvider({
|
|
46074
|
+
id: "baseten",
|
|
46075
|
+
label: "Baseten",
|
|
46076
|
+
defaultModel: BASETEN_DECISION_MODELS[0],
|
|
46077
|
+
modelOptions: [
|
|
46078
|
+
{ value: BASETEN_DECISION_MODELS[0], label: "Elephant-1" },
|
|
46079
|
+
{ value: BASETEN_DECISION_MODELS[1], label: "Mammoth-1" }
|
|
46080
|
+
],
|
|
46081
|
+
modelHelp: "Images belong in shared State, not Question Instructions.",
|
|
46082
|
+
credentialNames: BASETEN_DEFAULT_CREDENTIAL_NAMES,
|
|
46083
|
+
browserExecutionSupported: false,
|
|
46084
|
+
endpoint: BASETEN_DECISIONS_ENDPOINT,
|
|
46085
|
+
supportsImages: (model) => BASETEN_DECISION_MODELS.some((id) => id === model),
|
|
46086
|
+
checkRequest: assertBasetenDecisionLimits,
|
|
46087
|
+
buildRequest: ({ model, state, questions }) => ({
|
|
46088
|
+
model,
|
|
46089
|
+
state: basetenDecisionState(state),
|
|
46090
|
+
questions: createQuestionMap(questions)
|
|
46091
|
+
}),
|
|
46092
|
+
validateResponse: validateClassifierEvaluationResponse
|
|
46093
|
+
// A temporary free promotion is not permanent pricing. Unknown cost stays unknown.
|
|
46094
|
+
});
|
|
45737
46095
|
var classifierProviders = [
|
|
45738
46096
|
jevClassifierProvider,
|
|
45739
46097
|
liquidClassifierProvider,
|
|
45740
46098
|
openaiClassifierProvider,
|
|
45741
46099
|
openrouterClassifierProvider,
|
|
45742
|
-
perplexityClassifierProvider
|
|
46100
|
+
perplexityClassifierProvider,
|
|
46101
|
+
subqClassifierProvider,
|
|
46102
|
+
basetenClassifierProvider
|
|
45743
46103
|
];
|
|
45744
46104
|
var ClassifierProviderError = class extends Error {
|
|
45745
46105
|
constructor(message2, kind, statusCode, options2) {
|
|
45746
46106
|
super(message2, options2);
|
|
45747
46107
|
this.kind = kind;
|
|
45748
46108
|
this.statusCode = statusCode;
|
|
45749
|
-
this.name = "
|
|
46109
|
+
this.name = "DecisionAIProviderError";
|
|
45750
46110
|
}
|
|
45751
46111
|
};
|
|
45752
46112
|
function classifierFailureKind(kind, status) {
|
|
@@ -45754,47 +46114,49 @@ function classifierFailureKind(kind, status) {
|
|
|
45754
46114
|
}
|
|
45755
46115
|
function classifierErrorMessage(error, apiKey) {
|
|
45756
46116
|
try {
|
|
45757
|
-
const text2 = error instanceof Error ? error.message : typeof error === "string" ? error : "
|
|
46117
|
+
const text2 = error instanceof Error ? error.message : typeof error === "string" ? error : "Decision AI request failed.";
|
|
45758
46118
|
return (apiKey ? text2.split(apiKey).join("[redacted]") : text2).slice(0, 2e3);
|
|
45759
46119
|
} catch {
|
|
45760
|
-
return "
|
|
46120
|
+
return "Decision AI request failed with unreadable error metadata.";
|
|
45761
46121
|
}
|
|
45762
46122
|
}
|
|
45763
46123
|
function createOperation(args, label) {
|
|
45764
|
-
if (!Number.isFinite(args.timeoutMs) || args.timeoutMs <= 0 || args.deadline !== void 0 && !Number.isFinite(args.deadline))
|
|
45765
|
-
throw new Error("
|
|
46124
|
+
if (args.timeoutMs !== void 0 && (!Number.isFinite(args.timeoutMs) || args.timeoutMs <= 0) || args.deadline !== void 0 && !Number.isFinite(args.deadline))
|
|
46125
|
+
throw new Error("Decision AI timeout and deadline must be finite, with a positive timeout.");
|
|
45766
46126
|
const now = Date.now();
|
|
45767
|
-
const deadline = Math.min(now + args.timeoutMs, args.deadline ?? Infinity);
|
|
45768
|
-
if (deadline - now > MAX_TIMER_DELAY_MS)
|
|
45769
|
-
throw new Error(`
|
|
45770
|
-
const
|
|
46127
|
+
const deadline = Math.min(args.timeoutMs === void 0 ? Infinity : now + args.timeoutMs, args.deadline ?? Infinity);
|
|
46128
|
+
if (Number.isFinite(deadline) && deadline - now > MAX_TIMER_DELAY_MS)
|
|
46129
|
+
throw new Error(`Decision AI effective timeout must not exceed ${MAX_TIMER_DELAY_MS} ms.`);
|
|
46130
|
+
const timeoutMessage = `${label} request timed out${args.timeoutMs === void 0 ? "" : ` after ${args.timeoutMs} ms`}.`;
|
|
45771
46131
|
return {
|
|
45772
46132
|
signal: args.signal,
|
|
45773
46133
|
deadline,
|
|
46134
|
+
timeoutMessage,
|
|
45774
46135
|
check(attemptSignal) {
|
|
45775
46136
|
throwIfAborted2(args.signal, label);
|
|
45776
|
-
if (Date.now() >= deadline || (attemptSignal == null ? void 0 : attemptSignal.aborted))
|
|
46137
|
+
if (Date.now() >= deadline || (attemptSignal == null ? void 0 : attemptSignal.aborted))
|
|
46138
|
+
throw new ClassifierProviderError(timeoutMessage, "timeout");
|
|
45777
46139
|
}
|
|
45778
46140
|
};
|
|
45779
46141
|
}
|
|
45780
46142
|
function createClassifierProvider(spec) {
|
|
45781
|
-
const { endpoint, buildRequest, validateResponse, checkState, checkRequest, ...provider } = spec;
|
|
46143
|
+
const { endpoint, buildRequest, requestHeaders, validateResponse, checkState, checkRequest, ...provider } = spec;
|
|
45782
46144
|
const evaluate = async (input) => {
|
|
45783
|
-
var _a;
|
|
46145
|
+
var _a, _b, _c;
|
|
45784
46146
|
if ("images" in input) throw new Error("Pass image evidence through State, not a separate images field.");
|
|
45785
46147
|
const args = { ...input, fetchImplementation: input.fetchImplementation ?? fetch };
|
|
45786
46148
|
const operation = createOperation(args, provider.label);
|
|
45787
46149
|
operation.check();
|
|
45788
|
-
if (typeof args.model !== "string") throw new Error("
|
|
46150
|
+
if (typeof args.model !== "string") throw new Error("Decision AI model must be a nonblank string.");
|
|
45789
46151
|
const budget = new ClassifierValueBudget(operation.check, provider.maxRequestBytes);
|
|
45790
46152
|
budget.inspect(args.model);
|
|
45791
|
-
if (args.model.trim() === "") throw new Error("
|
|
46153
|
+
if (args.model.trim() === "") throw new Error("Decision AI model must be a nonblank string.");
|
|
45792
46154
|
if (typeof args.apiKey !== "string" || args.apiKey.trim() === "" || /[\r\n]/.test(args.apiKey))
|
|
45793
|
-
throw new Error("
|
|
46155
|
+
throw new Error("Decision AI API key must be a nonblank string without line breaks.");
|
|
45794
46156
|
if (!Array.isArray(args.questions) || args.questions.length === 0)
|
|
45795
|
-
throw new Error("
|
|
46157
|
+
throw new Error("Decision AI run requires at least one question.");
|
|
45796
46158
|
if (args.questions.length > CLASSIFIER_LIMITS.questions)
|
|
45797
|
-
throw new Error("
|
|
46159
|
+
throw new Error("Decision AI run supports at most 1000 questions.");
|
|
45798
46160
|
const state = prepareClassifierState(args, budget);
|
|
45799
46161
|
const questions = [];
|
|
45800
46162
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -45805,9 +46167,32 @@ function createClassifierProvider(spec) {
|
|
|
45805
46167
|
ids.add(question.questionId);
|
|
45806
46168
|
questions.push(question);
|
|
45807
46169
|
}
|
|
45808
|
-
|
|
46170
|
+
let imageCount = state.kind === "messages" ? state.images.length : 0;
|
|
46171
|
+
for (const question of questions) {
|
|
46172
|
+
const images = question.instructionsMessages ? inspectStateMessages(question.instructionsMessages, operation.check) : [];
|
|
46173
|
+
imageCount += images.length;
|
|
46174
|
+
if (question.type === "box") {
|
|
46175
|
+
if (!((_a = provider.supportsBoxQuestions) == null ? void 0 : _a.call(provider, args.model)))
|
|
46176
|
+
throw new ClassifierProviderError(
|
|
46177
|
+
`${provider.label} model '${args.model}' does not support Bounding Box questions.`,
|
|
46178
|
+
"capability"
|
|
46179
|
+
);
|
|
46180
|
+
if (!(state.kind === "messages" && state.images.length) && !images.length)
|
|
46181
|
+
throw new ClassifierProviderError(
|
|
46182
|
+
`Bounding Box question '${question.questionId}' requires an image in shared State or its own Instructions.`,
|
|
46183
|
+
"capability"
|
|
46184
|
+
);
|
|
46185
|
+
}
|
|
46186
|
+
if (images.length && !((_b = provider.supportsQuestionImages) == null ? void 0 : _b.call(provider, args.model)))
|
|
46187
|
+
throw new ClassifierProviderError(
|
|
46188
|
+
`${provider.label} model '${args.model}' does not support images in question instructions. Use a compatible Jev or OpenAI profile.`,
|
|
46189
|
+
"capability"
|
|
46190
|
+
);
|
|
46191
|
+
}
|
|
46192
|
+
if (imageCount > 128) throw new Error("State and questions together must contain at most 128 images.");
|
|
46193
|
+
if (state.kind === "messages" && state.images.length && !((_c = provider.supportsImages) == null ? void 0 : _c.call(provider, args.model)))
|
|
45809
46194
|
throw new ClassifierProviderError(
|
|
45810
|
-
`${provider.label} model '${args.model}' does not support
|
|
46195
|
+
`${provider.label} model '${args.model}' does not support Decision AI images.`,
|
|
45811
46196
|
"capability"
|
|
45812
46197
|
);
|
|
45813
46198
|
try {
|
|
@@ -45816,7 +46201,7 @@ function createClassifierProvider(spec) {
|
|
|
45816
46201
|
} catch (error) {
|
|
45817
46202
|
operation.check();
|
|
45818
46203
|
throw new ClassifierProviderError(
|
|
45819
|
-
error instanceof Error ? error.message : `${provider.label} does not support this
|
|
46204
|
+
error instanceof Error ? error.message : `${provider.label} does not support this Decision AI evidence.`,
|
|
45820
46205
|
"capability",
|
|
45821
46206
|
void 0,
|
|
45822
46207
|
{ cause: error }
|
|
@@ -45825,7 +46210,7 @@ function createClassifierProvider(spec) {
|
|
|
45825
46210
|
operation.check();
|
|
45826
46211
|
const result = await callClassifierHttp(
|
|
45827
46212
|
args,
|
|
45828
|
-
{ ...provider, endpoint, validateResponse },
|
|
46213
|
+
{ ...provider, endpoint, requestHeaders, validateResponse },
|
|
45829
46214
|
{ model: args.model, state, questions },
|
|
45830
46215
|
buildRequest,
|
|
45831
46216
|
operation
|
|
@@ -45840,7 +46225,7 @@ function normalizeModelPricing(provider) {
|
|
|
45840
46225
|
}
|
|
45841
46226
|
function getClassifierProvider(id) {
|
|
45842
46227
|
const provider = classifierProviders.find((candidate) => candidate.id === (id || jevClassifierProvider.id));
|
|
45843
|
-
if (!provider) throw new Error(`Unknown
|
|
46228
|
+
if (!provider) throw new Error(`Unknown Decision AI provider '${id}'.`);
|
|
45844
46229
|
return provider;
|
|
45845
46230
|
}
|
|
45846
46231
|
function getClassifierProviderEnvironmentVariableNames() {
|
|
@@ -45862,19 +46247,13 @@ function calculateClassifierUsageCost(provider, usage, models) {
|
|
|
45862
46247
|
const totalCost = (usage.input_tokens * pricing.inputPerMillionTokens + usage.output_tokens * pricing.outputPerMillionTokens) / TOKENS_PER_MILLION;
|
|
45863
46248
|
return Number.isFinite(totalCost) && totalCost >= 0 ? totalCost : void 0;
|
|
45864
46249
|
}
|
|
45865
|
-
function createQuestionMap(questions) {
|
|
45866
|
-
const result = /* @__PURE__ */ Object.create(null);
|
|
45867
|
-
for (const question of questions) {
|
|
45868
|
-
const providerQuestion = question.type === "noul" && question.criteria === void 0 ? { type: question.type, instructions: question.instructions } : { type: question.type, instructions: question.instructions, criteria: question.criteria };
|
|
45869
|
-
Object.defineProperty(result, question.questionId, { enumerable: true, value: providerQuestion });
|
|
45870
|
-
}
|
|
45871
|
-
return result;
|
|
45872
|
-
}
|
|
45873
46250
|
async function callClassifierHttp(args, spec, prepared, buildRequest, operation) {
|
|
46251
|
+
var _a;
|
|
45874
46252
|
const { apiKey, fetchImplementation, retryOnNon200, retryOnNon200CooldownMs, retryOnNon200RepeatTimes } = args;
|
|
45875
46253
|
const { endpoint, label: providerLabel, validateResponse, maxRequestBytes } = spec;
|
|
45876
|
-
const { signal, deadline } = operation;
|
|
46254
|
+
const { signal, deadline, timeoutMessage } = operation;
|
|
45877
46255
|
const request = buildRequest(prepared);
|
|
46256
|
+
const requestHeaders = (_a = spec.requestHeaders) == null ? void 0 : _a.call(spec, prepared);
|
|
45878
46257
|
const configuredRetryCount = retryOnNon200 ? normalizeClassifierNon200RetryCount(retryOnNon200RepeatTimes) : 0;
|
|
45879
46258
|
const configuredCooldownMs = normalizeClassifierNon200RetryCooldownMs(retryOnNon200CooldownMs);
|
|
45880
46259
|
let automaticRetryCount = 0;
|
|
@@ -45891,9 +46270,9 @@ async function callClassifierHttp(args, spec, prepared, buildRequest, operation)
|
|
|
45891
46270
|
let attemptIndex = -1;
|
|
45892
46271
|
let attemptStartedAt = 0;
|
|
45893
46272
|
const report = (outcome, status, kind, classifierUsage, error) => {
|
|
45894
|
-
var
|
|
46273
|
+
var _a2;
|
|
45895
46274
|
try {
|
|
45896
|
-
(
|
|
46275
|
+
(_a2 = args.onAttempt) == null ? void 0 : _a2.call(args, {
|
|
45897
46276
|
attemptIndex,
|
|
45898
46277
|
durationMs: Math.max(0, Date.now() - attemptStartedAt),
|
|
45899
46278
|
outcome,
|
|
@@ -45921,7 +46300,7 @@ async function callClassifierHttp(args, spec, prepared, buildRequest, operation)
|
|
|
45921
46300
|
const controller = new AbortController();
|
|
45922
46301
|
const onAbort = () => controller.abort(signal.reason);
|
|
45923
46302
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
45924
|
-
const timer = setTimeout(() => controller.abort(new Error(`${providerLabel} request timeout`)), remainingMs);
|
|
46303
|
+
const timer = Number.isFinite(remainingMs) ? setTimeout(() => controller.abort(new Error(`${providerLabel} request timeout`)), remainingMs) : void 0;
|
|
45925
46304
|
const cleanupAttempt = () => {
|
|
45926
46305
|
clearTimeout(timer);
|
|
45927
46306
|
signal.removeEventListener("abort", onAbort);
|
|
@@ -45933,7 +46312,7 @@ async function callClassifierHttp(args, spec, prepared, buildRequest, operation)
|
|
|
45933
46312
|
fetchImplementation(endpoint, {
|
|
45934
46313
|
method: "POST",
|
|
45935
46314
|
redirect: "error",
|
|
45936
|
-
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
46315
|
+
headers: { ...requestHeaders, Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
45937
46316
|
body: requestJson,
|
|
45938
46317
|
signal: controller.signal
|
|
45939
46318
|
}),
|
|
@@ -45952,7 +46331,7 @@ async function callClassifierHttp(args, spec, prepared, buildRequest, operation)
|
|
|
45952
46331
|
void 0,
|
|
45953
46332
|
kind,
|
|
45954
46333
|
void 0,
|
|
45955
|
-
kind === "timeout" ?
|
|
46334
|
+
kind === "timeout" ? timeoutMessage : `${providerLabel} transport request failed.`
|
|
45956
46335
|
);
|
|
45957
46336
|
operation.check(controller.signal);
|
|
45958
46337
|
if (automaticRetryCount >= MAX_AUTOMATIC_ATTEMPTS - 1) {
|
|
@@ -45977,17 +46356,18 @@ async function callClassifierHttp(args, spec, prepared, buildRequest, operation)
|
|
|
45977
46356
|
response.status,
|
|
45978
46357
|
signal.aborted ? void 0 : "timeout",
|
|
45979
46358
|
void 0,
|
|
45980
|
-
signal.aborted ? `${providerLabel} request was canceled.` :
|
|
46359
|
+
signal.aborted ? `${providerLabel} request was canceled.` : timeoutMessage
|
|
45981
46360
|
);
|
|
45982
46361
|
throw error;
|
|
45983
46362
|
}
|
|
45984
46363
|
if (!response.ok) {
|
|
46364
|
+
const accessDeniedMessage = response.status === 403 ? `${providerLabel} access denied (HTTP 403). Check API key permissions and requested model access.` : void 0;
|
|
45985
46365
|
report(
|
|
45986
46366
|
"failure",
|
|
45987
46367
|
response.status,
|
|
45988
46368
|
"http",
|
|
45989
46369
|
void 0,
|
|
45990
|
-
|
|
46370
|
+
accessDeniedMessage ?? (response.status === 401 ? `${providerLabel} authentication failed (HTTP ${response.status}). Check the ${providerLabel} API key.` : `${providerLabel} rejected the request (HTTP ${response.status}).`)
|
|
45991
46371
|
);
|
|
45992
46372
|
const retryable = RETRYABLE_STATUSES.has(response.status);
|
|
45993
46373
|
const permanent = [400, 401, 402, 403, 413, 422].includes(response.status);
|
|
@@ -46021,7 +46401,7 @@ async function callClassifierHttp(args, spec, prepared, buildRequest, operation)
|
|
|
46021
46401
|
}
|
|
46022
46402
|
if (response.status === 401 || response.status === 403) {
|
|
46023
46403
|
throw new ClassifierProviderError(
|
|
46024
|
-
`${providerLabel} authentication failed. Check the ${providerLabel} API key.`,
|
|
46404
|
+
accessDeniedMessage ?? `${providerLabel} authentication failed. Check the ${providerLabel} API key.`,
|
|
46025
46405
|
"http",
|
|
46026
46406
|
response.status
|
|
46027
46407
|
);
|
|
@@ -46058,7 +46438,7 @@ async function callClassifierHttp(args, spec, prepared, buildRequest, operation)
|
|
|
46058
46438
|
response.status,
|
|
46059
46439
|
kind,
|
|
46060
46440
|
void 0,
|
|
46061
|
-
kind === "timeout" ?
|
|
46441
|
+
kind === "timeout" ? timeoutMessage : error instanceof ClassifierResourceLimitError ? error.message : kind === "transport" ? `${providerLabel} response body could not be read.` : `${providerLabel} returned an invalid JSON response.`
|
|
46062
46442
|
);
|
|
46063
46443
|
discardResponseBody(response);
|
|
46064
46444
|
operation.check(controller.signal);
|
|
@@ -46081,10 +46461,10 @@ async function callClassifierHttp(args, spec, prepared, buildRequest, operation)
|
|
|
46081
46461
|
response.status,
|
|
46082
46462
|
"response-validation",
|
|
46083
46463
|
classifierAttemptUsage(body, spec, args.model),
|
|
46084
|
-
error instanceof Error ? error.message : `${providerLabel} returned an invalid
|
|
46464
|
+
error instanceof Error ? error.message : `${providerLabel} returned an invalid Decision AI response.`
|
|
46085
46465
|
);
|
|
46086
46466
|
throw new ClassifierProviderError(
|
|
46087
|
-
error instanceof Error ? error.message : `${providerLabel} returned an invalid
|
|
46467
|
+
error instanceof Error ? error.message : `${providerLabel} returned an invalid Decision AI response.`,
|
|
46088
46468
|
"response-validation",
|
|
46089
46469
|
void 0,
|
|
46090
46470
|
{ cause: error }
|
|
@@ -46164,22 +46544,26 @@ function throwIfAborted2(signal, providerLabel) {
|
|
|
46164
46544
|
function throwAbort(signal, providerLabel) {
|
|
46165
46545
|
throw signal.reason instanceof Error ? signal.reason : new Error(`${providerLabel} request aborted.`);
|
|
46166
46546
|
}
|
|
46167
|
-
function waitForRetry(delayMs, signal, providerLabel) {
|
|
46547
|
+
async function waitForRetry(delayMs, signal, providerLabel) {
|
|
46168
46548
|
throwIfAborted2(signal, providerLabel);
|
|
46169
|
-
|
|
46170
|
-
|
|
46171
|
-
|
|
46172
|
-
|
|
46173
|
-
|
|
46174
|
-
|
|
46175
|
-
|
|
46176
|
-
|
|
46177
|
-
|
|
46178
|
-
|
|
46179
|
-
|
|
46180
|
-
|
|
46181
|
-
|
|
46182
|
-
|
|
46549
|
+
while (delayMs > 0) {
|
|
46550
|
+
const chunkMs = Math.min(delayMs, MAX_TIMER_DELAY_MS);
|
|
46551
|
+
await new Promise((resolve, reject) => {
|
|
46552
|
+
const onAbort = () => {
|
|
46553
|
+
clearTimeout(timer);
|
|
46554
|
+
signal.removeEventListener("abort", onAbort);
|
|
46555
|
+
reject(signal.reason instanceof Error ? signal.reason : new Error(`${providerLabel} request aborted.`));
|
|
46556
|
+
};
|
|
46557
|
+
const timer = setTimeout(() => {
|
|
46558
|
+
signal.removeEventListener("abort", onAbort);
|
|
46559
|
+
resolve();
|
|
46560
|
+
}, chunkMs);
|
|
46561
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
46562
|
+
if (signal.aborted) onAbort();
|
|
46563
|
+
});
|
|
46564
|
+
throwIfAborted2(signal, providerLabel);
|
|
46565
|
+
delayMs -= chunkMs;
|
|
46566
|
+
}
|
|
46183
46567
|
}
|
|
46184
46568
|
function getRetryDelayMs(retryAfter, attempt, deadline) {
|
|
46185
46569
|
let requestedMs;
|
|
@@ -46223,7 +46607,7 @@ function pickClassifierProfileData(data) {
|
|
|
46223
46607
|
function positive(value, fallback, label, maximum = 6e5) {
|
|
46224
46608
|
const result = value ?? fallback;
|
|
46225
46609
|
if (!Number.isSafeInteger(result) || result < 1 || result > maximum)
|
|
46226
|
-
throw new Error(`
|
|
46610
|
+
throw new Error(`Decision AI Profile ${label} must be an integer between 1 and ${maximum}.`);
|
|
46227
46611
|
return result;
|
|
46228
46612
|
}
|
|
46229
46613
|
function classifierProfileResponseTimeout(configuration) {
|
|
@@ -46255,34 +46639,35 @@ function classifierProfileHealthPolicy(configuration) {
|
|
|
46255
46639
|
}
|
|
46256
46640
|
function normalizeClassifierProfileValue(value) {
|
|
46257
46641
|
return normalizeDetachedProfile(
|
|
46258
|
-
snapshotClassifierJson(value, "
|
|
46642
|
+
snapshotClassifierJson(value, "Decision AI Profile", new ClassifierValueBudget(), true)
|
|
46259
46643
|
);
|
|
46260
46644
|
}
|
|
46261
46645
|
function normalizeDetachedProfile(value) {
|
|
46262
46646
|
var _a;
|
|
46263
46647
|
const profile = value;
|
|
46264
46648
|
if (!profile || profile.version !== 1 || !profile.configuration || typeof profile.configuration !== "object" || Array.isArray(profile.configuration) || !profile.credential || typeof profile.credential !== "object" || Array.isArray(profile.credential))
|
|
46265
|
-
throw new Error("
|
|
46649
|
+
throw new Error("Decision AI Profiles input requires a version 1 Decision AI Profile.");
|
|
46266
46650
|
const { configuration, credential } = profile;
|
|
46267
46651
|
if (typeof configuration.provider !== "string" || typeof configuration.model !== "string" || !configuration.model.trim())
|
|
46268
|
-
throw new Error("
|
|
46652
|
+
throw new Error("Decision AI Profile requires a provider and a nonblank model.");
|
|
46269
46653
|
getClassifierProvider(configuration.provider);
|
|
46270
46654
|
if (credential.value !== void 0 && (typeof credential.value !== "string" || /[\r\n]/.test(credential.value)))
|
|
46271
|
-
throw new Error("
|
|
46655
|
+
throw new Error("Decision AI Profile credential must be a string without line breaks.");
|
|
46272
46656
|
if (profile.profileName !== void 0 && typeof profile.profileName !== "string")
|
|
46273
|
-
throw new Error("Invalid
|
|
46657
|
+
throw new Error("Invalid Decision AI Profile name.");
|
|
46274
46658
|
if (profile.sourceNodeId !== void 0 && (typeof profile.sourceNodeId !== "string" || !profile.sourceNodeId.trim()))
|
|
46275
|
-
throw new Error("Invalid
|
|
46659
|
+
throw new Error("Invalid Decision AI Profile source node.");
|
|
46276
46660
|
if (configuration.enableCircuitBreaker !== void 0 && typeof configuration.enableCircuitBreaker !== "boolean")
|
|
46277
|
-
throw new Error("
|
|
46661
|
+
throw new Error("Decision AI Profile automatic suspension must be a boolean.");
|
|
46278
46662
|
if (configuration.apiKeySource !== void 0 && !["configured", "classifier-settings", "input"].includes(configuration.apiKeySource))
|
|
46279
|
-
throw new Error("Unknown
|
|
46663
|
+
throw new Error("Unknown Decision AI API key source.");
|
|
46280
46664
|
classifierProfileResponseTimeout(configuration);
|
|
46281
46665
|
classifierProfileHealthPolicy(configuration);
|
|
46282
46666
|
return {
|
|
46283
46667
|
version: 1,
|
|
46284
46668
|
sourceNodeId: profile.sourceNodeId,
|
|
46285
|
-
|
|
46669
|
+
// Blank names are absent, but authored whitespace must survive exact-default display aliases.
|
|
46670
|
+
profileName: ((_a = profile.profileName) == null ? void 0 : _a.trim()) ? profile.profileName : void 0,
|
|
46286
46671
|
credential: credential.value === void 0 ? {} : { value: credential.value.trim() },
|
|
46287
46672
|
configuration: {
|
|
46288
46673
|
...pickClassifierProfileData(configuration),
|
|
@@ -46294,15 +46679,15 @@ function normalizeDetachedProfile(value) {
|
|
|
46294
46679
|
}
|
|
46295
46680
|
function normalizeClassifierProfiles(value, check) {
|
|
46296
46681
|
if (Array.isArray(value) && (value.length === 0 || value.length > 128))
|
|
46297
|
-
throw new Error("
|
|
46298
|
-
const detached = snapshotClassifierJson(value, "
|
|
46682
|
+
throw new Error("Decision AI Profiles requires between 1 and 128 profiles.");
|
|
46683
|
+
const detached = snapshotClassifierJson(value, "Decision AI Profiles", new ClassifierValueBudget(check), true);
|
|
46299
46684
|
return (Array.isArray(detached) ? detached : [detached]).map(normalizeDetachedProfile);
|
|
46300
46685
|
}
|
|
46301
46686
|
function resolveClassifierProfile(data, inputs, context) {
|
|
46302
46687
|
var _a, _b, _c;
|
|
46303
46688
|
const provider = getClassifierProvider(data.provider);
|
|
46304
46689
|
const model = data.useModelInput ? (_a = classifierInputDataValue(inputs, "model")) == null ? void 0 : _a.value : ((_b = data.model) == null ? void 0 : _b.trim()) || provider.defaultModel;
|
|
46305
|
-
if (typeof model !== "string" || !model.trim()) throw new Error("
|
|
46690
|
+
if (typeof model !== "string" || !model.trim()) throw new Error("Decision AI Profile model is required.");
|
|
46306
46691
|
let value;
|
|
46307
46692
|
try {
|
|
46308
46693
|
value = resolveClassifierApiKey({
|
|
@@ -46344,6 +46729,107 @@ function classifierProfileHealthIdentity(profile, projectId, fallbackNodeId) {
|
|
|
46344
46729
|
};
|
|
46345
46730
|
}
|
|
46346
46731
|
|
|
46732
|
+
// src/model/AgentResponseTracePresentation.ts
|
|
46733
|
+
function getProfileDisplayName(name, family) {
|
|
46734
|
+
return family === "classifier" && name === "Classifier Profile" ? "Decision AI Profile" : name;
|
|
46735
|
+
}
|
|
46736
|
+
function buildAgentProfileAttemptInspectorRows(attempts) {
|
|
46737
|
+
return attempts.map((attempt) => {
|
|
46738
|
+
var _a;
|
|
46739
|
+
return {
|
|
46740
|
+
eventId: attempt.eventId,
|
|
46741
|
+
providerAndModel: [
|
|
46742
|
+
...attempt.profileName == null || attempt.profileName.trim() === "" ? [] : [`Profile: ${getProfileDisplayName(attempt.profileName, attempt.family).trim()}`],
|
|
46743
|
+
`${formatProvider(attempt)} / ${attempt.model}`
|
|
46744
|
+
].join(" \xB7 "),
|
|
46745
|
+
context: [
|
|
46746
|
+
((_a = attempt.failureKind) == null ? void 0 : _a.replaceAll("-", " ")) ?? describeStage(attempt.stage),
|
|
46747
|
+
describeOutcome(attempt),
|
|
46748
|
+
attempt.profileIndex == null ? void 0 : `profile ${attempt.profileIndex + 1}`,
|
|
46749
|
+
attempt.family === "classifier" ? void 0 : `round ${attempt.roundIndex + 1}`,
|
|
46750
|
+
attempt.attemptIndex == null ? void 0 : `attempt ${attempt.attemptIndex + 1}`,
|
|
46751
|
+
attempt.status == null ? void 0 : `HTTP ${attempt.status}`,
|
|
46752
|
+
attempt.durationMs == null ? isClassifierRequest(attempt) ? "duration unavailable" : void 0 : `${(attempt.durationMs / 1e3).toFixed(2)} sec`,
|
|
46753
|
+
attempt.classifierUsage == null ? isClassifierRequest(attempt) ? "usage not reported" : void 0 : `${attempt.classifierUsage.inputTokens} input / ${attempt.classifierUsage.outputTokens} output tokens`,
|
|
46754
|
+
attempt.classifierUsage == null ? isClassifierRequest(attempt) ? "cost unknown" : void 0 : attempt.classifierUsage.estimatedCostUsd == null ? "cost unknown" : `estimated $${attempt.classifierUsage.estimatedCostUsd.toPrecision(4)}`
|
|
46755
|
+
].filter((value) => value != null).join(" / "),
|
|
46756
|
+
...attempt.error == null ? {} : { error: attempt.error }
|
|
46757
|
+
};
|
|
46758
|
+
});
|
|
46759
|
+
}
|
|
46760
|
+
function isClassifierRequest(attempt) {
|
|
46761
|
+
return attempt.family === "classifier" && attempt.attemptIndex != null;
|
|
46762
|
+
}
|
|
46763
|
+
function getClassifierRequestCount(trace) {
|
|
46764
|
+
var _a;
|
|
46765
|
+
if (trace.summary.classifierRequestCount != null) return trace.summary.classifierRequestCount;
|
|
46766
|
+
const attempts = (_a = trace.profileAttempts) == null ? void 0 : _a.filter((attempt) => attempt.family === "classifier");
|
|
46767
|
+
if (trace.scope !== "classifier-invocation" && !(attempts == null ? void 0 : attempts.length)) return void 0;
|
|
46768
|
+
return (attempts == null ? void 0 : attempts.filter(isClassifierRequest).length) ?? 0;
|
|
46769
|
+
}
|
|
46770
|
+
function formatClassifierRequestCount(trace) {
|
|
46771
|
+
const count = getClassifierRequestCount(trace);
|
|
46772
|
+
if (count == null) return void 0;
|
|
46773
|
+
return trace.summary.classifierRequestCount == null && (trace.omittedProfileAttemptCount ?? 0) > 0 ? `${count} (retained evidence only)` : String(count);
|
|
46774
|
+
}
|
|
46775
|
+
function getProfileAttemptOmissionNotice(trace) {
|
|
46776
|
+
const omitted = trace.omittedProfileAttemptCount ?? 0;
|
|
46777
|
+
return omitted > 0 ? `${omitted} additional profile-attempt rows (requests or decisions) omitted by the trace limit.` : void 0;
|
|
46778
|
+
}
|
|
46779
|
+
function formatProvider(attempt) {
|
|
46780
|
+
return attempt.provider === "custom" ? getCustomProviderApiContract(attempt.customProviderApi).label : attempt.provider;
|
|
46781
|
+
}
|
|
46782
|
+
function describeStage(stage) {
|
|
46783
|
+
switch (stage) {
|
|
46784
|
+
case "health-gate":
|
|
46785
|
+
return "reliability check";
|
|
46786
|
+
case "health-update":
|
|
46787
|
+
return "reliability update";
|
|
46788
|
+
case "response-validation":
|
|
46789
|
+
return "response validation";
|
|
46790
|
+
default:
|
|
46791
|
+
return stage;
|
|
46792
|
+
}
|
|
46793
|
+
}
|
|
46794
|
+
function describeOutcome(attempt) {
|
|
46795
|
+
if (attempt.skipReason === "unreached") return "not reached";
|
|
46796
|
+
if (attempt.healthDisposition === "deny") {
|
|
46797
|
+
return attempt.retryAt == null ? "profile suspended; skipped" : `profile suspended until ${new Date(attempt.retryAt).toLocaleString()}`;
|
|
46798
|
+
}
|
|
46799
|
+
if (attempt.healthDisposition === "fail-open") {
|
|
46800
|
+
return "reliability service unavailable; profile request continued";
|
|
46801
|
+
}
|
|
46802
|
+
if (attempt.timeoutKind === "first-output") return "first output timed out";
|
|
46803
|
+
if (attempt.timeoutKind === "stream-inactivity") return "stream became inactive";
|
|
46804
|
+
if (attempt.timeoutKind === "response") return "response timed out";
|
|
46805
|
+
if (attempt.stage === "health-update" && attempt.healthOutcome) {
|
|
46806
|
+
return `recorded ${describeReliabilityOutcome(attempt.healthOutcome)}${describeReliabilityState(attempt.healthState)}`;
|
|
46807
|
+
}
|
|
46808
|
+
return `${attempt.outcome}${describeReliabilityState(attempt.healthState)}`;
|
|
46809
|
+
}
|
|
46810
|
+
function describeReliabilityOutcome(outcome) {
|
|
46811
|
+
switch (outcome) {
|
|
46812
|
+
case "healthy":
|
|
46813
|
+
return "success";
|
|
46814
|
+
case "unhealthy":
|
|
46815
|
+
return "failure";
|
|
46816
|
+
default:
|
|
46817
|
+
return "ignored result";
|
|
46818
|
+
}
|
|
46819
|
+
}
|
|
46820
|
+
function describeReliabilityState(state) {
|
|
46821
|
+
switch (state) {
|
|
46822
|
+
case "open":
|
|
46823
|
+
return "; profile suspended";
|
|
46824
|
+
case "half-open":
|
|
46825
|
+
return "; recovery attempt in progress";
|
|
46826
|
+
case "closed":
|
|
46827
|
+
return "; profile available";
|
|
46828
|
+
default:
|
|
46829
|
+
return "";
|
|
46830
|
+
}
|
|
46831
|
+
}
|
|
46832
|
+
|
|
46347
46833
|
// src/model/classifier/profileExecution.ts
|
|
46348
46834
|
function classifierProfileSummary(profiles, attempts) {
|
|
46349
46835
|
return profiles.map((profile, index) => {
|
|
@@ -46369,20 +46855,20 @@ function classifierProfileSummary(profiles, attempts) {
|
|
|
46369
46855
|
outcome !== "suspended" && healthState === "open" ? "; profile is suspended" : "",
|
|
46370
46856
|
healthState === "half-open" ? "; recovery attempt in progress" : ""
|
|
46371
46857
|
].join("");
|
|
46372
|
-
return `${index + 1}. ${profile.profileName || "
|
|
46858
|
+
return `${index + 1}. ${getProfileDisplayName(profile.profileName, "classifier") || "Decision AI Profile"} (${profile.configuration.provider}/${profile.configuration.model}): ${outcome}${details}`;
|
|
46373
46859
|
}).join("\n");
|
|
46374
46860
|
}
|
|
46375
46861
|
var ClassifierProfileExhaustedError = class extends Error {
|
|
46376
46862
|
constructor(attempts, summary, options2, statusCode) {
|
|
46377
46863
|
const details = attempts.filter((attempt) => attempt.outcome === "failure" || attempt.outcome === "aborted").map((attempt) => {
|
|
46378
|
-
const profile = `Profile ${(attempt.profileIndex ?? 0) + 1}${attempt.profileName ? ` (${attempt.profileName})` : ""}`;
|
|
46864
|
+
const profile = `Profile ${(attempt.profileIndex ?? 0) + 1}${attempt.profileName ? ` (${getProfileDisplayName(attempt.profileName, "classifier")})` : ""}`;
|
|
46379
46865
|
const request = attempt.attemptIndex === void 0 ? "" : ` attempt ${attempt.attemptIndex + 1}`;
|
|
46380
46866
|
const status = attempt.status === void 0 ? "" : ` (HTTP ${attempt.status})`;
|
|
46381
46867
|
const reason = attempt.error ? `: ${attempt.error.replace(/\r\n|\r|\n/g, "\n ")}` : "";
|
|
46382
46868
|
return `${profile}, ${attempt.failureKind ?? attempt.stage}${request} ${attempt.outcome}${status}${reason}`;
|
|
46383
46869
|
}).join("\n");
|
|
46384
46870
|
super(
|
|
46385
|
-
`
|
|
46871
|
+
`Decision AI profile chain exhausted.
|
|
46386
46872
|
${summary}${details ? `
|
|
46387
46873
|
|
|
46388
46874
|
Attempt details:
|
|
@@ -46392,21 +46878,22 @@ ${details}` : ""}`,
|
|
|
46392
46878
|
this.attempts = attempts;
|
|
46393
46879
|
this.summary = summary;
|
|
46394
46880
|
this.statusCode = statusCode;
|
|
46395
|
-
this.name = "
|
|
46881
|
+
this.name = "DecisionAIProfileExhaustedError";
|
|
46396
46882
|
}
|
|
46397
46883
|
};
|
|
46398
46884
|
async function runClassifierProfiles(input) {
|
|
46399
46885
|
var _a, _b;
|
|
46400
46886
|
const attempts = [];
|
|
46401
46887
|
const { context } = input;
|
|
46888
|
+
const deadline = input.deadline ?? Infinity;
|
|
46402
46889
|
let lastError;
|
|
46403
46890
|
let httpFailuresOnly = true;
|
|
46404
46891
|
let lastHttpStatus;
|
|
46405
|
-
const
|
|
46892
|
+
const record4 = (attempt) => {
|
|
46406
46893
|
var _a2;
|
|
46407
46894
|
const event = {
|
|
46408
46895
|
...attempt,
|
|
46409
|
-
...attempt.stage === "health-update" && attempt.outcome === "failure" ? { error: "
|
|
46896
|
+
...attempt.stage === "health-update" && attempt.outcome === "failure" ? { error: "Decision AI profile health service unavailable." } : {},
|
|
46410
46897
|
family: "classifier",
|
|
46411
46898
|
profileName: (_a2 = input.profiles[attempt.profileIndex ?? 0]) == null ? void 0 : _a2.profileName
|
|
46412
46899
|
};
|
|
@@ -46418,10 +46905,10 @@ async function runClassifierProfiles(input) {
|
|
|
46418
46905
|
};
|
|
46419
46906
|
for (let profileIndex = 0; profileIndex < input.profiles.length; profileIndex++) {
|
|
46420
46907
|
context.signal.throwIfAborted();
|
|
46421
|
-
if (Date.now() >=
|
|
46422
|
-
lastError = new ClassifierProviderError("
|
|
46908
|
+
if (Date.now() >= deadline) {
|
|
46909
|
+
lastError = new ClassifierProviderError("Decision AI overall deadline expired.", "timeout");
|
|
46423
46910
|
const profile2 = input.profiles[profileIndex];
|
|
46424
|
-
|
|
46911
|
+
record4({
|
|
46425
46912
|
roundIndex: 0,
|
|
46426
46913
|
profileIndex,
|
|
46427
46914
|
provider: profile2.configuration.provider,
|
|
@@ -46429,7 +46916,7 @@ async function runClassifierProfiles(input) {
|
|
|
46429
46916
|
stage: "request",
|
|
46430
46917
|
outcome: "failure",
|
|
46431
46918
|
failureKind: "timeout",
|
|
46432
|
-
error: "
|
|
46919
|
+
error: "Decision AI overall deadline expired."
|
|
46433
46920
|
});
|
|
46434
46921
|
httpFailuresOnly = false;
|
|
46435
46922
|
break;
|
|
@@ -46449,7 +46936,7 @@ async function runClassifierProfiles(input) {
|
|
|
46449
46936
|
try {
|
|
46450
46937
|
const begin = await runBoundedHealthOperation({
|
|
46451
46938
|
operation: "begin",
|
|
46452
|
-
timeoutMs: Math.max(1, Math.min(2e3,
|
|
46939
|
+
timeoutMs: Math.max(1, Math.min(2e3, deadline - Date.now())),
|
|
46453
46940
|
signal: context.signal,
|
|
46454
46941
|
run: () => store.begin(health),
|
|
46455
46942
|
onLateResolve: async (late) => {
|
|
@@ -46458,19 +46945,19 @@ async function runClassifierProfiles(input) {
|
|
|
46458
46945
|
}
|
|
46459
46946
|
});
|
|
46460
46947
|
if (begin.disposition === "deny") {
|
|
46461
|
-
|
|
46948
|
+
record4({
|
|
46462
46949
|
...base,
|
|
46463
46950
|
stage: "health-gate",
|
|
46464
46951
|
outcome: "skipped",
|
|
46465
46952
|
healthDisposition: "deny",
|
|
46466
46953
|
healthState: begin.state,
|
|
46467
46954
|
retryAt: begin.retryAt,
|
|
46468
|
-
error: "
|
|
46955
|
+
error: "Decision AI profile is suspended."
|
|
46469
46956
|
});
|
|
46470
46957
|
continue;
|
|
46471
46958
|
}
|
|
46472
46959
|
if (!begin.permitId) throw new Error("Profile health service did not return a permit.");
|
|
46473
|
-
|
|
46960
|
+
record4({
|
|
46474
46961
|
...base,
|
|
46475
46962
|
stage: "health-gate",
|
|
46476
46963
|
outcome: "success",
|
|
@@ -46487,34 +46974,34 @@ async function runClassifierProfiles(input) {
|
|
|
46487
46974
|
operationTimeoutMs: 2e3,
|
|
46488
46975
|
executionCorrelationId: context.llmProfileHealthExecutionCorrelationId,
|
|
46489
46976
|
signal: context.signal,
|
|
46490
|
-
recordAttempt:
|
|
46977
|
+
recordAttempt: record4
|
|
46491
46978
|
});
|
|
46492
46979
|
} catch {
|
|
46493
46980
|
context.signal.throwIfAborted();
|
|
46494
|
-
|
|
46981
|
+
record4({
|
|
46495
46982
|
...base,
|
|
46496
46983
|
stage: "health-gate",
|
|
46497
46984
|
outcome: "failure",
|
|
46498
46985
|
healthDisposition: "fail-open",
|
|
46499
|
-
error: "
|
|
46986
|
+
error: "Decision AI profile health service unavailable."
|
|
46500
46987
|
});
|
|
46501
46988
|
}
|
|
46502
46989
|
}
|
|
46503
46990
|
try {
|
|
46504
46991
|
context.signal.throwIfAborted();
|
|
46505
46992
|
if (!provider.browserExecutionSupported && context.executor === "browser")
|
|
46506
|
-
throw new ClassifierProviderError("
|
|
46993
|
+
throw new ClassifierProviderError("Decision AI provider requires the Node executor.", "capability");
|
|
46507
46994
|
if (!((_b = profile.credential.value) == null ? void 0 : _b.trim()))
|
|
46508
|
-
throw new ClassifierProviderError("
|
|
46509
|
-
const remainingMs =
|
|
46995
|
+
throw new ClassifierProviderError("Decision AI Profile API key is not set.", "configuration");
|
|
46996
|
+
const remainingMs = deadline - Date.now();
|
|
46510
46997
|
const timeoutMs = health ? Math.min(classifierProfileResponseTimeout(profile.configuration), remainingMs) : remainingMs;
|
|
46511
|
-
if (timeoutMs <= 0) throw new ClassifierProviderError("
|
|
46998
|
+
if (timeoutMs <= 0) throw new ClassifierProviderError("Decision AI overall deadline expired.", "timeout");
|
|
46512
46999
|
const result = await provider.evaluate({
|
|
46513
47000
|
...input.state,
|
|
46514
47001
|
questions: input.questions,
|
|
46515
47002
|
apiKey: profile.credential.value,
|
|
46516
47003
|
model,
|
|
46517
|
-
timeoutMs,
|
|
47004
|
+
...Number.isFinite(timeoutMs) ? { timeoutMs } : {},
|
|
46518
47005
|
deadline: input.deadline,
|
|
46519
47006
|
signal: context.signal,
|
|
46520
47007
|
retryOnNon200: input.retryOnNon200,
|
|
@@ -46526,7 +47013,7 @@ async function runClassifierProfiles(input) {
|
|
|
46526
47013
|
observedRequest = true;
|
|
46527
47014
|
observedAbort = attempt.outcome === "aborted";
|
|
46528
47015
|
lastPhysicalFailure = attempt.outcome === "failure" ? { kind, status: attempt.status } : void 0;
|
|
46529
|
-
|
|
47016
|
+
record4({
|
|
46530
47017
|
...base,
|
|
46531
47018
|
...attempt,
|
|
46532
47019
|
stage: kind === "response-validation" || kind === "response-parsing" ? "response-validation" : "request",
|
|
@@ -46536,15 +47023,13 @@ async function runClassifierProfiles(input) {
|
|
|
46536
47023
|
}
|
|
46537
47024
|
});
|
|
46538
47025
|
context.signal.throwIfAborted();
|
|
46539
|
-
if (Date.now() >=
|
|
46540
|
-
throw new ClassifierProviderError("Classifier overall deadline expired.", "timeout");
|
|
47026
|
+
if (Date.now() >= deadline) throw new ClassifierProviderError("Decision AI overall deadline expired.", "timeout");
|
|
46541
47027
|
await (permit == null ? void 0 : permit.finish("healthy"));
|
|
46542
47028
|
context.signal.throwIfAborted();
|
|
46543
|
-
if (Date.now() >=
|
|
46544
|
-
throw new ClassifierProviderError("Classifier overall deadline expired.", "timeout");
|
|
47029
|
+
if (Date.now() >= deadline) throw new ClassifierProviderError("Decision AI overall deadline expired.", "timeout");
|
|
46545
47030
|
for (let unreached = profileIndex + 1; unreached < input.profiles.length; unreached++) {
|
|
46546
47031
|
const candidate = input.profiles[unreached];
|
|
46547
|
-
|
|
47032
|
+
record4({
|
|
46548
47033
|
roundIndex: 0,
|
|
46549
47034
|
profileIndex: unreached,
|
|
46550
47035
|
provider: candidate.configuration.provider,
|
|
@@ -46563,7 +47048,7 @@ async function runClassifierProfiles(input) {
|
|
|
46563
47048
|
if (httpFailure) lastHttpStatus = providerError.statusCode;
|
|
46564
47049
|
const alreadyReported = context.signal.aborted && observedAbort || providerError && (lastPhysicalFailure == null ? void 0 : lastPhysicalFailure.kind) === providerError.kind && (providerError.kind !== "http" || lastPhysicalFailure.status === providerError.statusCode);
|
|
46565
47050
|
if (!alreadyReported)
|
|
46566
|
-
|
|
47051
|
+
record4({
|
|
46567
47052
|
...base,
|
|
46568
47053
|
stage: providerError ? providerError.kind === "configuration" || providerError.kind === "capability" ? "configuration" : providerError.kind === "response-validation" || providerError.kind === "response-parsing" ? "response-validation" : "request" : "configuration",
|
|
46569
47054
|
failureKind: context.signal.aborted ? void 0 : providerError ? classifierFailureKind(providerError.kind, providerError.statusCode) : "configuration",
|
|
@@ -46575,17 +47060,17 @@ async function runClassifierProfiles(input) {
|
|
|
46575
47060
|
const unhealthy = (providerError == null ? void 0 : providerError.kind) === "timeout" || (providerError == null ? void 0 : providerError.kind) === "transport" || (providerError == null ? void 0 : providerError.kind) === "http" && (providerError.statusCode === 408 || providerError.statusCode === 429 || (providerError.statusCode ?? 0) >= 500);
|
|
46576
47061
|
await (permit == null ? void 0 : permit.finish(!context.signal.aborted && observedRequest && unhealthy ? "unhealthy" : "ignored"));
|
|
46577
47062
|
context.signal.throwIfAborted();
|
|
46578
|
-
if (Date.now() >=
|
|
47063
|
+
if (Date.now() >= deadline) {
|
|
46579
47064
|
httpFailuresOnly = false;
|
|
46580
|
-
lastError = new ClassifierProviderError("
|
|
47065
|
+
lastError = new ClassifierProviderError("Decision AI overall deadline expired.", "timeout", void 0, {
|
|
46581
47066
|
cause: error
|
|
46582
47067
|
});
|
|
46583
47068
|
if ((providerError == null ? void 0 : providerError.kind) !== "timeout")
|
|
46584
|
-
|
|
47069
|
+
record4({
|
|
46585
47070
|
...base,
|
|
46586
47071
|
stage: "request",
|
|
46587
47072
|
outcome: "failure",
|
|
46588
|
-
error: "
|
|
47073
|
+
error: "Decision AI overall deadline expired.",
|
|
46589
47074
|
failureKind: "timeout"
|
|
46590
47075
|
});
|
|
46591
47076
|
break;
|
|
@@ -46609,13 +47094,13 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
|
|
|
46609
47094
|
static create() {
|
|
46610
47095
|
return {
|
|
46611
47096
|
type: "classifierEvaluate",
|
|
46612
|
-
title: "
|
|
47097
|
+
title: "Decision AI run",
|
|
46613
47098
|
id: (0, import_non_secure110.nanoid)(),
|
|
46614
47099
|
visualData: { x: 0, y: 0, width: 260 },
|
|
46615
47100
|
// Keep the default model in the provider descriptor rather than
|
|
46616
47101
|
// serializing Jev's model into every new node. A future provider then
|
|
46617
47102
|
// receives its own default when an author changes the Provider field.
|
|
46618
|
-
data: { provider: "jev",
|
|
47103
|
+
data: { provider: "jev", errorOnNon200: true, catchRequestFailed: false }
|
|
46619
47104
|
};
|
|
46620
47105
|
}
|
|
46621
47106
|
getInputDefinitions(connections) {
|
|
@@ -46643,12 +47128,12 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
|
|
|
46643
47128
|
if (this.data.configurationMode === "profile") {
|
|
46644
47129
|
inputs.unshift({
|
|
46645
47130
|
id: "classifierProfile",
|
|
46646
|
-
title: "
|
|
47131
|
+
title: "Decision AI Profiles",
|
|
46647
47132
|
dataType: ["classifier-config", "classifier-config[]"],
|
|
46648
47133
|
required: true,
|
|
46649
47134
|
coerced: true,
|
|
46650
47135
|
splitRunBehavior: "preserve-array",
|
|
46651
|
-
description: "One
|
|
47136
|
+
description: "One Decision AI Profile or an ordered fallback chain."
|
|
46652
47137
|
});
|
|
46653
47138
|
}
|
|
46654
47139
|
if (this.data.configurationMode !== "profile" && this.data.useModelInput) {
|
|
@@ -46687,11 +47172,11 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
|
|
|
46687
47172
|
outputs.push({ id: "responseBody", title: "Response body", dataType: "object" });
|
|
46688
47173
|
}
|
|
46689
47174
|
if (this.data.outputClassifierAttempts)
|
|
46690
|
-
outputs.push({ id: "classifierAttempts", title: "
|
|
47175
|
+
outputs.push({ id: "classifierAttempts", title: "Decision AI Attempts", dataType: "object[]" });
|
|
46691
47176
|
if (this.data.configurationMode === "profile" && this.data.outputClassifierProfileSummary)
|
|
46692
47177
|
outputs.push({
|
|
46693
47178
|
id: "classifierProfileSummary",
|
|
46694
|
-
title: "
|
|
47179
|
+
title: "Decision AI Profile Summary",
|
|
46695
47180
|
dataType: "string"
|
|
46696
47181
|
});
|
|
46697
47182
|
return [...outputs, ...getRunFailureOutputDefinitions({ catchRequestFailed: this.data.catchRequestFailed })];
|
|
@@ -46699,7 +47184,7 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
|
|
|
46699
47184
|
getEditors() {
|
|
46700
47185
|
return [
|
|
46701
47186
|
{ type: "custom", label: "Configuration", customEditorId: "ClassifierConfiguration" },
|
|
46702
|
-
{ ...getClassifierModelEditor(
|
|
47187
|
+
{ ...getClassifierModelEditor(), hideIf: (data) => data.configurationMode === "profile" },
|
|
46703
47188
|
{
|
|
46704
47189
|
type: "group",
|
|
46705
47190
|
label: "Outputs",
|
|
@@ -46714,7 +47199,7 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
|
|
|
46714
47199
|
type: "toggle",
|
|
46715
47200
|
label: "Request body",
|
|
46716
47201
|
dataKey: "outputRequestBody",
|
|
46717
|
-
helperMessage: "Adds the exact
|
|
47202
|
+
helperMessage: "Adds the exact Decision AI request JSON body sent to the provider. It excludes authorization headers and Rivet-managed API keys."
|
|
46718
47203
|
},
|
|
46719
47204
|
{
|
|
46720
47205
|
type: "toggle",
|
|
@@ -46722,31 +47207,15 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
|
|
|
46722
47207
|
dataKey: "outputResponseBody",
|
|
46723
47208
|
helperMessage: "Shows the provider response, including rejected or invalid responses. Non-JSON responses appear as raw text. Captured content may contain sensitive input."
|
|
46724
47209
|
},
|
|
46725
|
-
{ type: "toggle", label: "
|
|
47210
|
+
{ type: "toggle", label: "Decision AI attempts", dataKey: "outputClassifierAttempts" },
|
|
46726
47211
|
{
|
|
46727
47212
|
type: "toggle",
|
|
46728
|
-
label: "
|
|
47213
|
+
label: "Decision AI profile summary",
|
|
46729
47214
|
dataKey: "outputClassifierProfileSummary",
|
|
46730
47215
|
hideIf: (data) => data.configurationMode !== "profile"
|
|
46731
47216
|
}
|
|
46732
47217
|
]
|
|
46733
47218
|
},
|
|
46734
|
-
{
|
|
46735
|
-
type: "group",
|
|
46736
|
-
label: "Advanced",
|
|
46737
|
-
editors: [
|
|
46738
|
-
{
|
|
46739
|
-
type: "number",
|
|
46740
|
-
label: "Overall timeout (seconds)",
|
|
46741
|
-
dataKey: this.data.configurationMode === "profile" ? "profileChainTimeoutMs" : "timeoutMs",
|
|
46742
|
-
defaultValue: this.data.configurationMode === "profile" ? 18e4 : 3e4,
|
|
46743
|
-
storageMultiplier: 1e3,
|
|
46744
|
-
min: 1e3,
|
|
46745
|
-
max: 6e5,
|
|
46746
|
-
step: 1e3
|
|
46747
|
-
}
|
|
46748
|
-
]
|
|
46749
|
-
},
|
|
46750
47219
|
{
|
|
46751
47220
|
type: "group",
|
|
46752
47221
|
label: "Error behavior",
|
|
@@ -46809,10 +47278,10 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
|
|
|
46809
47278
|
}
|
|
46810
47279
|
static getUIData() {
|
|
46811
47280
|
return {
|
|
46812
|
-
contextMenuTitle: "
|
|
46813
|
-
infoBoxTitle: "
|
|
46814
|
-
infoBoxBody: "Evaluates shared state and optional images against typed
|
|
46815
|
-
group: ["
|
|
47281
|
+
contextMenuTitle: "Decision AI run",
|
|
47282
|
+
infoBoxTitle: "Decision AI run",
|
|
47283
|
+
infoBoxBody: "Evaluates shared state and optional images against typed Decision AI questions. Images are shared evidence for every question.",
|
|
47284
|
+
group: ["Decision AI"]
|
|
46816
47285
|
};
|
|
46817
47286
|
}
|
|
46818
47287
|
async process(inputs, context) {
|
|
@@ -46867,13 +47336,11 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
|
|
|
46867
47336
|
async processRun(inputs, context, attempts, diagnostics) {
|
|
46868
47337
|
var _a, _b, _c, _d;
|
|
46869
47338
|
if (this.data.configurationMode !== void 0 && this.data.configurationMode !== "inline" && this.data.configurationMode !== "profile")
|
|
46870
|
-
throw new Error("Unknown
|
|
46871
|
-
const
|
|
46872
|
-
const deadline = Date.now() + timeoutMs;
|
|
46873
|
-
const checkPreparation = classifierPreparationCheck(context.signal, deadline, timeoutMs);
|
|
47339
|
+
throw new Error("Unknown Decision AI configuration mode.");
|
|
47340
|
+
const checkPreparation = () => context.signal.throwIfAborted();
|
|
46874
47341
|
checkPreparation();
|
|
46875
47342
|
if (this.data.configurationMode === "profile")
|
|
46876
|
-
return this.processProfiles(inputs, context,
|
|
47343
|
+
return this.processProfiles(inputs, context, checkPreparation, attempts, diagnostics);
|
|
46877
47344
|
const provider = getClassifierProvider(this.data.provider);
|
|
46878
47345
|
if (!provider.browserExecutionSupported && context.executor === "browser") {
|
|
46879
47346
|
throw new Error(
|
|
@@ -46913,7 +47380,7 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
|
|
|
46913
47380
|
flattenQuestions(input.value, questions, checkPreparation, /* @__PURE__ */ new Set(), 0, flattenWork);
|
|
46914
47381
|
}
|
|
46915
47382
|
}
|
|
46916
|
-
if (questions.length === 0) throw new Error("
|
|
47383
|
+
if (questions.length === 0) throw new Error("Decision AI run requires at least one question.");
|
|
46917
47384
|
const result = await (provider.evaluateInput ?? provider.evaluate).call(provider, {
|
|
46918
47385
|
apiKey,
|
|
46919
47386
|
model: modelValue,
|
|
@@ -46923,8 +47390,6 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
|
|
|
46923
47390
|
retryOnNon200RepeatTimes: this.data.retryOnNon200RepeatTimes,
|
|
46924
47391
|
signal: context.signal,
|
|
46925
47392
|
...state,
|
|
46926
|
-
timeoutMs,
|
|
46927
|
-
deadline,
|
|
46928
47393
|
...diagnostics,
|
|
46929
47394
|
onAttempt: ({ kind, ...attempt }) => {
|
|
46930
47395
|
var _a2;
|
|
@@ -46977,7 +47442,7 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
|
|
|
46977
47442
|
...this.data.configurationMode === "profile" && this.data.outputClassifierProfileSummary && summary !== void 0 ? { ["classifierProfileSummary"]: { type: "string", value: summary } } : {}
|
|
46978
47443
|
};
|
|
46979
47444
|
}
|
|
46980
|
-
async processProfiles(inputs, context,
|
|
47445
|
+
async processProfiles(inputs, context, check, attempts, diagnostics) {
|
|
46981
47446
|
var _a, _b, _c;
|
|
46982
47447
|
const profiles = normalizeClassifierProfiles((_a = classifierInputDataValue(inputs, "classifierProfile")) == null ? void 0 : _a.value, check);
|
|
46983
47448
|
const graph = (_c = context.project) == null ? void 0 : _c.graphs[(_b = context.execution) == null ? void 0 : _b.graphId];
|
|
@@ -46994,7 +47459,7 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
|
|
|
46994
47459
|
const input = classifierInputDataValue(inputs, port);
|
|
46995
47460
|
if (input) flattenQuestions(input.value, values2, check, /* @__PURE__ */ new Set(), 0, work);
|
|
46996
47461
|
}
|
|
46997
|
-
if (!values2.length) throw new Error("
|
|
47462
|
+
if (!values2.length) throw new Error("Decision AI run requires at least one question.");
|
|
46998
47463
|
const ids = /* @__PURE__ */ new Set();
|
|
46999
47464
|
const questions = values2.map((value) => {
|
|
47000
47465
|
const question = prepareClassifierQuestion(value, budget);
|
|
@@ -47009,7 +47474,6 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
|
|
|
47009
47474
|
questions,
|
|
47010
47475
|
context,
|
|
47011
47476
|
nodeId: this.chartNode.id,
|
|
47012
|
-
deadline,
|
|
47013
47477
|
retryOnNon200: this.data.retryOnNon200,
|
|
47014
47478
|
retryOnNon200RepeatTimes: this.data.retryOnNon200RepeatTimes,
|
|
47015
47479
|
retryOnNon200CooldownMs: this.data.retryOnNon200CooldownMs,
|
|
@@ -47032,7 +47496,7 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
|
|
|
47032
47496
|
};
|
|
47033
47497
|
}
|
|
47034
47498
|
};
|
|
47035
|
-
function getClassifierModelEditor(
|
|
47499
|
+
function getClassifierModelEditor() {
|
|
47036
47500
|
return {
|
|
47037
47501
|
type: "group",
|
|
47038
47502
|
label: "Model",
|
|
@@ -47046,11 +47510,11 @@ function getClassifierModelEditor(data) {
|
|
|
47046
47510
|
options: classifierProviders.map((provider) => ({ value: provider.id, label: provider.label }))
|
|
47047
47511
|
},
|
|
47048
47512
|
{
|
|
47049
|
-
type: "
|
|
47513
|
+
type: "custom",
|
|
47050
47514
|
label: "Model",
|
|
47051
47515
|
dataKey: "model",
|
|
47052
47516
|
useInputToggleDataKey: "useModelInput",
|
|
47053
|
-
|
|
47517
|
+
customEditorId: "ClassifierModel"
|
|
47054
47518
|
},
|
|
47055
47519
|
{
|
|
47056
47520
|
type: "segmented",
|
|
@@ -47060,7 +47524,7 @@ function getClassifierModelEditor(data) {
|
|
|
47060
47524
|
defaultValue: "configured",
|
|
47061
47525
|
options: [
|
|
47062
47526
|
{ value: "configured", label: "Automatic" },
|
|
47063
|
-
{ value: "classifier-settings", label: "
|
|
47527
|
+
{ value: "classifier-settings", label: "Decision AI settings" },
|
|
47064
47528
|
{ value: "input", label: "Input port" }
|
|
47065
47529
|
],
|
|
47066
47530
|
helperMessage: getApiKeySourceHelperMessage2
|
|
@@ -47069,7 +47533,7 @@ function getClassifierModelEditor(data) {
|
|
|
47069
47533
|
type: "custom",
|
|
47070
47534
|
label: "Configured API key names",
|
|
47071
47535
|
customEditorId: "ClassifierCredentialNames",
|
|
47072
|
-
hideIf: (
|
|
47536
|
+
hideIf: (data) => data.apiKeySource === "input" || data.apiKeySource === "classifier-settings"
|
|
47073
47537
|
}
|
|
47074
47538
|
]
|
|
47075
47539
|
};
|
|
@@ -47126,8 +47590,8 @@ function getApiKeySourceHelperMessage2(data) {
|
|
|
47126
47590
|
if (data.apiKeySource === "input") return "Uses the API Key input port instead of a configured provider key.";
|
|
47127
47591
|
const provider = getProviderForDisplay(data.provider);
|
|
47128
47592
|
if (data.apiKeySource === "classifier-settings")
|
|
47129
|
-
return `Uses only Settings >
|
|
47130
|
-
return "Automatic checks the named programmatic setting, then the named environment variable, then the saved
|
|
47593
|
+
return `Uses only Settings > Decision AI > ${provider.label} API Key on the executor. Does not fall back to named or environment credentials.`;
|
|
47594
|
+
return "Automatic checks the named programmatic setting, then the named environment variable, then the saved Decision AI key (default names only). OpenAI also accepts its legacy general key; Jev accepts its legacy plugin key last. Resolution happens on the executor, not in this editor.";
|
|
47131
47595
|
}
|
|
47132
47596
|
function flattenQuestions(value, target, check, seen = /* @__PURE__ */ new Set(), depth = 0, work = { values: 0 }) {
|
|
47133
47597
|
check();
|
|
@@ -47136,8 +47600,7 @@ function flattenQuestions(value, target, check, seen = /* @__PURE__ */ new Set()
|
|
|
47136
47600
|
if (Array.isArray(value)) {
|
|
47137
47601
|
if (seen.has(value)) throw new Error("Question inputs must not contain circular arrays.");
|
|
47138
47602
|
seen.add(value);
|
|
47139
|
-
if (value.length > CLASSIFIER_LIMITS.questions)
|
|
47140
|
-
throw new Error("Classifier Evaluate supports at most 1000 questions.");
|
|
47603
|
+
if (value.length > CLASSIFIER_LIMITS.questions) throw new Error("Decision AI run supports at most 1000 questions.");
|
|
47141
47604
|
for (const item of classifierArrayValues(value, "Questions"))
|
|
47142
47605
|
flattenQuestions(item, target, check, seen, depth + 1, work);
|
|
47143
47606
|
seen.delete(value);
|
|
@@ -47146,14 +47609,10 @@ function flattenQuestions(value, target, check, seen = /* @__PURE__ */ new Set()
|
|
|
47146
47609
|
if (typeof value !== "object" || value === null) {
|
|
47147
47610
|
throw new Error("Question inputs must contain question definition objects or nested arrays of definitions.");
|
|
47148
47611
|
}
|
|
47149
|
-
if (target.length >= CLASSIFIER_LIMITS.questions)
|
|
47150
|
-
throw new Error("Classifier Evaluate supports at most 1000 questions.");
|
|
47612
|
+
if (target.length >= CLASSIFIER_LIMITS.questions) throw new Error("Decision AI run supports at most 1000 questions.");
|
|
47151
47613
|
target.push(value);
|
|
47152
47614
|
}
|
|
47153
|
-
|
|
47154
|
-
return typeof timeoutMs === "number" && Number.isFinite(timeoutMs) && timeoutMs > 0 ? Math.min(timeoutMs, 6e5) : 3e4;
|
|
47155
|
-
}
|
|
47156
|
-
var classifierEvaluateNode = nodeDefinition(ClassifierEvaluateNodeImpl, "Classifier Evaluate");
|
|
47615
|
+
var classifierEvaluateNode = nodeDefinition(ClassifierEvaluateNodeImpl, "Decision AI run");
|
|
47157
47616
|
|
|
47158
47617
|
// src/model/nodes/ClassifierProfileNode.ts
|
|
47159
47618
|
var import_non_secure111 = require("nanoid/non-secure");
|
|
@@ -47161,7 +47620,7 @@ var ClassifierProfileNodeImpl = class extends NodeImpl {
|
|
|
47161
47620
|
static create() {
|
|
47162
47621
|
return {
|
|
47163
47622
|
type: "classifierProfile",
|
|
47164
|
-
title: "
|
|
47623
|
+
title: "Decision AI Profile",
|
|
47165
47624
|
id: (0, import_non_secure111.nanoid)(),
|
|
47166
47625
|
visualData: { x: 0, y: 0, width: 260 },
|
|
47167
47626
|
data: { provider: "jev", responseTimeoutMs: DEFAULT_CLASSIFIER_PROFILE_RESPONSE_TIMEOUT_MS }
|
|
@@ -47179,16 +47638,16 @@ var ClassifierProfileNodeImpl = class extends NodeImpl {
|
|
|
47179
47638
|
id: "profile",
|
|
47180
47639
|
title: "Profile",
|
|
47181
47640
|
dataType: "classifier-config",
|
|
47182
|
-
description: "Sensitive resolved
|
|
47641
|
+
description: "Sensitive resolved Decision AI configuration. Combine profiles with Array for ordered fallback."
|
|
47183
47642
|
}
|
|
47184
47643
|
];
|
|
47185
47644
|
}
|
|
47186
47645
|
getEditors() {
|
|
47187
47646
|
return [
|
|
47188
|
-
getClassifierModelEditor(
|
|
47647
|
+
getClassifierModelEditor(),
|
|
47189
47648
|
{
|
|
47190
47649
|
type: "group",
|
|
47191
|
-
label: "
|
|
47650
|
+
label: "Decision AI profile suspension",
|
|
47192
47651
|
editors: [
|
|
47193
47652
|
{
|
|
47194
47653
|
type: "info",
|
|
@@ -47260,10 +47719,10 @@ var ClassifierProfileNodeImpl = class extends NodeImpl {
|
|
|
47260
47719
|
}
|
|
47261
47720
|
static getUIData() {
|
|
47262
47721
|
return {
|
|
47263
|
-
contextMenuTitle: "
|
|
47264
|
-
infoBoxTitle: "
|
|
47265
|
-
infoBoxBody: "Reusable
|
|
47266
|
-
group: ["
|
|
47722
|
+
contextMenuTitle: "Decision AI Profile",
|
|
47723
|
+
infoBoxTitle: "Decision AI Profile",
|
|
47724
|
+
infoBoxBody: "Reusable Decision AI provider/model/credential configuration. Combine profiles with Array for ordered fallback.",
|
|
47725
|
+
group: ["Decision AI"]
|
|
47267
47726
|
};
|
|
47268
47727
|
}
|
|
47269
47728
|
async process(inputs, context) {
|
|
@@ -47273,7 +47732,7 @@ var ClassifierProfileNodeImpl = class extends NodeImpl {
|
|
|
47273
47732
|
};
|
|
47274
47733
|
}
|
|
47275
47734
|
};
|
|
47276
|
-
var classifierProfileNode = nodeDefinition(ClassifierProfileNodeImpl, "
|
|
47735
|
+
var classifierProfileNode = nodeDefinition(ClassifierProfileNodeImpl, "Decision AI Profile");
|
|
47277
47736
|
|
|
47278
47737
|
// src/model/Nodes.ts
|
|
47279
47738
|
var registerBuiltInNodes = (registry) => {
|
|
@@ -47340,104 +47799,6 @@ var BrowserNativeApi = class {
|
|
|
47340
47799
|
}
|
|
47341
47800
|
};
|
|
47342
47801
|
|
|
47343
|
-
// src/model/AgentResponseTracePresentation.ts
|
|
47344
|
-
function buildAgentProfileAttemptInspectorRows(attempts) {
|
|
47345
|
-
return attempts.map((attempt) => {
|
|
47346
|
-
var _a;
|
|
47347
|
-
return {
|
|
47348
|
-
eventId: attempt.eventId,
|
|
47349
|
-
providerAndModel: [
|
|
47350
|
-
...attempt.profileName == null || attempt.profileName.trim() === "" ? [] : [`Profile: ${attempt.profileName.trim()}`],
|
|
47351
|
-
`${formatProvider(attempt)} / ${attempt.model}`
|
|
47352
|
-
].join(" \xB7 "),
|
|
47353
|
-
context: [
|
|
47354
|
-
((_a = attempt.failureKind) == null ? void 0 : _a.replaceAll("-", " ")) ?? describeStage(attempt.stage),
|
|
47355
|
-
describeOutcome(attempt),
|
|
47356
|
-
attempt.profileIndex == null ? void 0 : `profile ${attempt.profileIndex + 1}`,
|
|
47357
|
-
attempt.family === "classifier" ? void 0 : `round ${attempt.roundIndex + 1}`,
|
|
47358
|
-
attempt.attemptIndex == null ? void 0 : `attempt ${attempt.attemptIndex + 1}`,
|
|
47359
|
-
attempt.status == null ? void 0 : `HTTP ${attempt.status}`,
|
|
47360
|
-
attempt.durationMs == null ? isClassifierRequest(attempt) ? "duration unavailable" : void 0 : `${(attempt.durationMs / 1e3).toFixed(2)} sec`,
|
|
47361
|
-
attempt.classifierUsage == null ? isClassifierRequest(attempt) ? "usage not reported" : void 0 : `${attempt.classifierUsage.inputTokens} input / ${attempt.classifierUsage.outputTokens} output tokens`,
|
|
47362
|
-
attempt.classifierUsage == null ? isClassifierRequest(attempt) ? "cost unknown" : void 0 : attempt.classifierUsage.estimatedCostUsd == null ? "cost unknown" : `estimated $${attempt.classifierUsage.estimatedCostUsd.toPrecision(4)}`
|
|
47363
|
-
].filter((value) => value != null).join(" / "),
|
|
47364
|
-
...attempt.error == null ? {} : { error: attempt.error }
|
|
47365
|
-
};
|
|
47366
|
-
});
|
|
47367
|
-
}
|
|
47368
|
-
function isClassifierRequest(attempt) {
|
|
47369
|
-
return attempt.family === "classifier" && attempt.attemptIndex != null;
|
|
47370
|
-
}
|
|
47371
|
-
function getClassifierRequestCount(trace) {
|
|
47372
|
-
var _a;
|
|
47373
|
-
if (trace.summary.classifierRequestCount != null) return trace.summary.classifierRequestCount;
|
|
47374
|
-
const attempts = (_a = trace.profileAttempts) == null ? void 0 : _a.filter((attempt) => attempt.family === "classifier");
|
|
47375
|
-
if (trace.scope !== "classifier-invocation" && !(attempts == null ? void 0 : attempts.length)) return void 0;
|
|
47376
|
-
return (attempts == null ? void 0 : attempts.filter(isClassifierRequest).length) ?? 0;
|
|
47377
|
-
}
|
|
47378
|
-
function formatClassifierRequestCount(trace) {
|
|
47379
|
-
const count = getClassifierRequestCount(trace);
|
|
47380
|
-
if (count == null) return void 0;
|
|
47381
|
-
return trace.summary.classifierRequestCount == null && (trace.omittedProfileAttemptCount ?? 0) > 0 ? `${count} (retained evidence only)` : String(count);
|
|
47382
|
-
}
|
|
47383
|
-
function getProfileAttemptOmissionNotice(trace) {
|
|
47384
|
-
const omitted = trace.omittedProfileAttemptCount ?? 0;
|
|
47385
|
-
return omitted > 0 ? `${omitted} additional profile-attempt rows (requests or decisions) omitted by the trace limit.` : void 0;
|
|
47386
|
-
}
|
|
47387
|
-
function formatProvider(attempt) {
|
|
47388
|
-
return attempt.provider === "custom" ? getCustomProviderApiContract(attempt.customProviderApi).label : attempt.provider;
|
|
47389
|
-
}
|
|
47390
|
-
function describeStage(stage) {
|
|
47391
|
-
switch (stage) {
|
|
47392
|
-
case "health-gate":
|
|
47393
|
-
return "reliability check";
|
|
47394
|
-
case "health-update":
|
|
47395
|
-
return "reliability update";
|
|
47396
|
-
case "response-validation":
|
|
47397
|
-
return "response validation";
|
|
47398
|
-
default:
|
|
47399
|
-
return stage;
|
|
47400
|
-
}
|
|
47401
|
-
}
|
|
47402
|
-
function describeOutcome(attempt) {
|
|
47403
|
-
if (attempt.skipReason === "unreached") return "not reached";
|
|
47404
|
-
if (attempt.healthDisposition === "deny") {
|
|
47405
|
-
return attempt.retryAt == null ? "profile suspended; skipped" : `profile suspended until ${new Date(attempt.retryAt).toLocaleString()}`;
|
|
47406
|
-
}
|
|
47407
|
-
if (attempt.healthDisposition === "fail-open") {
|
|
47408
|
-
return "reliability service unavailable; profile request continued";
|
|
47409
|
-
}
|
|
47410
|
-
if (attempt.timeoutKind === "first-output") return "first output timed out";
|
|
47411
|
-
if (attempt.timeoutKind === "stream-inactivity") return "stream became inactive";
|
|
47412
|
-
if (attempt.timeoutKind === "response") return "response timed out";
|
|
47413
|
-
if (attempt.stage === "health-update" && attempt.healthOutcome) {
|
|
47414
|
-
return `recorded ${describeReliabilityOutcome(attempt.healthOutcome)}${describeReliabilityState(attempt.healthState)}`;
|
|
47415
|
-
}
|
|
47416
|
-
return `${attempt.outcome}${describeReliabilityState(attempt.healthState)}`;
|
|
47417
|
-
}
|
|
47418
|
-
function describeReliabilityOutcome(outcome) {
|
|
47419
|
-
switch (outcome) {
|
|
47420
|
-
case "healthy":
|
|
47421
|
-
return "success";
|
|
47422
|
-
case "unhealthy":
|
|
47423
|
-
return "failure";
|
|
47424
|
-
default:
|
|
47425
|
-
return "ignored result";
|
|
47426
|
-
}
|
|
47427
|
-
}
|
|
47428
|
-
function describeReliabilityState(state) {
|
|
47429
|
-
switch (state) {
|
|
47430
|
-
case "open":
|
|
47431
|
-
return "; profile suspended";
|
|
47432
|
-
case "half-open":
|
|
47433
|
-
return "; recovery attempt in progress";
|
|
47434
|
-
case "closed":
|
|
47435
|
-
return "; profile available";
|
|
47436
|
-
default:
|
|
47437
|
-
return "";
|
|
47438
|
-
}
|
|
47439
|
-
}
|
|
47440
|
-
|
|
47441
47802
|
// src/model/DebuggerTransportSentinel.ts
|
|
47442
47803
|
var DEBUGGER_TRANSPORT_SENTINEL_KEY = "__rivetDebuggerTransportSentinel";
|
|
47443
47804
|
var DEBUGGER_TRANSPORT_SENTINEL_VERSION = 1;
|
|
@@ -50712,8 +51073,8 @@ var PineconeKnowledgeStoreDriver = class {
|
|
|
50712
51073
|
return (await this.#readManifest(sourceId, context)).manifest;
|
|
50713
51074
|
}
|
|
50714
51075
|
async #readManifest(sourceId, context) {
|
|
50715
|
-
const
|
|
50716
|
-
const url = `${this.config.indexHost}/vectors/fetch?ids=${encodeURIComponent(MANIFEST_RECORD_ID)}&namespace=${encodeURIComponent(
|
|
51076
|
+
const namespace2 = this.#namespace(sourceId);
|
|
51077
|
+
const url = `${this.config.indexHost}/vectors/fetch?ids=${encodeURIComponent(MANIFEST_RECORD_ID)}&namespace=${encodeURIComponent(namespace2)}`;
|
|
50717
51078
|
const response = await this.#request(url, { method: "GET" }, context);
|
|
50718
51079
|
const indexedLsn = readPineconeLsn(response.headers, "x-pinecone-max-indexed-lsn");
|
|
50719
51080
|
const payload = await parseJsonResponse(response, "fetching the knowledge-source manifest");
|
|
@@ -50746,12 +51107,12 @@ var PineconeKnowledgeStoreDriver = class {
|
|
|
50746
51107
|
};
|
|
50747
51108
|
}
|
|
50748
51109
|
async upsertChunks(sourceId, version, chunks, context) {
|
|
50749
|
-
const
|
|
51110
|
+
const namespace2 = this.#namespace(sourceId);
|
|
50750
51111
|
const records = chunks.map((chunk) => this.#chunkRecord(sourceId, version, chunk));
|
|
50751
51112
|
const batches = batchNdjson(records, 32, 15e5);
|
|
50752
51113
|
for (let index = 0; index < batches.length; index += 1) {
|
|
50753
51114
|
const response = await this.#request(
|
|
50754
|
-
`${this.config.indexHost}/records/namespaces/${encodeURIComponent(
|
|
51115
|
+
`${this.config.indexHost}/records/namespaces/${encodeURIComponent(namespace2)}/upsert`,
|
|
50755
51116
|
{ method: "POST", body: batches[index], headers: { "Content-Type": "application/x-ndjson" } },
|
|
50756
51117
|
context
|
|
50757
51118
|
);
|
|
@@ -50759,8 +51120,8 @@ var PineconeKnowledgeStoreDriver = class {
|
|
|
50759
51120
|
}
|
|
50760
51121
|
}
|
|
50761
51122
|
async commitManifest(manifest, context) {
|
|
50762
|
-
const
|
|
50763
|
-
const
|
|
51123
|
+
const namespace2 = this.#namespace(manifest.sourceId);
|
|
51124
|
+
const record4 = {
|
|
50764
51125
|
_id: MANIFEST_RECORD_ID,
|
|
50765
51126
|
[this.config.textField]: `Rivet knowledge-source manifest for ${manifest.sourceId}, version ${manifest.activeVersion}.`,
|
|
50766
51127
|
rivet_record_type: "manifest",
|
|
@@ -50768,10 +51129,10 @@ var PineconeKnowledgeStoreDriver = class {
|
|
|
50768
51129
|
rivet_source_version: manifest.activeVersion,
|
|
50769
51130
|
rivet_manifest_json: JSON.stringify(manifest)
|
|
50770
51131
|
};
|
|
50771
|
-
validatePineconeRecordMetadataSize(
|
|
51132
|
+
validatePineconeRecordMetadataSize(record4, this.config.textField, `manifest for source "${manifest.sourceId}"`);
|
|
50772
51133
|
const response = await this.#request(
|
|
50773
|
-
`${this.config.indexHost}/records/namespaces/${encodeURIComponent(
|
|
50774
|
-
{ method: "POST", body: JSON.stringify(
|
|
51134
|
+
`${this.config.indexHost}/records/namespaces/${encodeURIComponent(namespace2)}/upsert`,
|
|
51135
|
+
{ method: "POST", body: JSON.stringify(record4), headers: { "Content-Type": "application/x-ndjson" } },
|
|
50775
51136
|
context
|
|
50776
51137
|
);
|
|
50777
51138
|
const writeLsn = readPineconeLsn(response.headers, "x-pinecone-request-lsn") ?? readPineconeLsn(response.headers, "x-pinecone-max-indexed-lsn");
|
|
@@ -50789,7 +51150,7 @@ var PineconeKnowledgeStoreDriver = class {
|
|
|
50789
51150
|
);
|
|
50790
51151
|
}
|
|
50791
51152
|
async search(request, context) {
|
|
50792
|
-
const
|
|
51153
|
+
const namespace2 = this.#namespace(request.sourceId);
|
|
50793
51154
|
const filter = combinePineconeFilters(
|
|
50794
51155
|
{
|
|
50795
51156
|
$and: [{ rivet_record_type: { $eq: "chunk" } }, { rivet_source_version: { $eq: request.version } }]
|
|
@@ -50814,7 +51175,7 @@ var PineconeKnowledgeStoreDriver = class {
|
|
|
50814
51175
|
}
|
|
50815
51176
|
}
|
|
50816
51177
|
const response = await this.#request(
|
|
50817
|
-
`${this.config.indexHost}/records/namespaces/${encodeURIComponent(
|
|
51178
|
+
`${this.config.indexHost}/records/namespaces/${encodeURIComponent(namespace2)}/search`,
|
|
50818
51179
|
{ method: "POST", body: JSON.stringify(body), headers: { "Content-Type": "application/json" } },
|
|
50819
51180
|
context
|
|
50820
51181
|
);
|
|
@@ -50859,14 +51220,14 @@ var PineconeKnowledgeStoreDriver = class {
|
|
|
50859
51220
|
});
|
|
50860
51221
|
}
|
|
50861
51222
|
async deleteVersion(sourceId, version, context) {
|
|
50862
|
-
const
|
|
51223
|
+
const namespace2 = this.#namespace(sourceId);
|
|
50863
51224
|
const response = await this.#request(
|
|
50864
51225
|
`${this.config.indexHost}/vectors/delete`,
|
|
50865
51226
|
{
|
|
50866
51227
|
method: "POST",
|
|
50867
51228
|
headers: { "Content-Type": "application/json" },
|
|
50868
51229
|
body: JSON.stringify({
|
|
50869
|
-
namespace,
|
|
51230
|
+
namespace: namespace2,
|
|
50870
51231
|
filter: {
|
|
50871
51232
|
$and: [{ rivet_record_type: { $eq: "chunk" } }, { rivet_source_version: { $eq: version } }]
|
|
50872
51233
|
}
|
|
@@ -50894,7 +51255,7 @@ var PineconeKnowledgeStoreDriver = class {
|
|
|
50894
51255
|
);
|
|
50895
51256
|
}
|
|
50896
51257
|
}
|
|
50897
|
-
const
|
|
51258
|
+
const record4 = {
|
|
50898
51259
|
_id: chunk.id,
|
|
50899
51260
|
[this.config.textField]: chunk.text,
|
|
50900
51261
|
rivet_record_type: "chunk",
|
|
@@ -50906,18 +51267,18 @@ var PineconeKnowledgeStoreDriver = class {
|
|
|
50906
51267
|
rivet_chunks_in_document: chunk.chunksInDocument,
|
|
50907
51268
|
...metadata
|
|
50908
51269
|
};
|
|
50909
|
-
validatePineconeRecordMetadataSize(
|
|
50910
|
-
return
|
|
51270
|
+
validatePineconeRecordMetadataSize(record4, this.config.textField, `knowledge chunk "${chunk.id}"`);
|
|
51271
|
+
return record4;
|
|
50911
51272
|
}
|
|
50912
51273
|
#namespace(sourceId) {
|
|
50913
51274
|
const readableSourceId = sourceId.replace(/[^a-zA-Z0-9._-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 120) || "source";
|
|
50914
51275
|
const sourceHash = import_crypto_js6.default.SHA256(sourceId).toString(import_crypto_js6.default.enc.Hex).slice(0, 24);
|
|
50915
51276
|
const safeSourceId = `${readableSourceId}--${sourceHash}`;
|
|
50916
|
-
const
|
|
50917
|
-
if (!
|
|
50918
|
-
if (
|
|
51277
|
+
const namespace2 = this.config.namespaceTemplate.replaceAll("{sourceId}", safeSourceId).trim();
|
|
51278
|
+
if (!namespace2) throw new Error("Pinecone Namespace Template produced an empty namespace.");
|
|
51279
|
+
if (namespace2.length > 512)
|
|
50919
51280
|
throw new Error("Pinecone Namespace Template produced a namespace longer than 512 characters.");
|
|
50920
|
-
return
|
|
51281
|
+
return namespace2;
|
|
50921
51282
|
}
|
|
50922
51283
|
async #request(url, init2, context) {
|
|
50923
51284
|
const headers = new Headers(init2.headers);
|
|
@@ -51029,8 +51390,8 @@ function batchNdjson(records, maxRecords, maxBytes) {
|
|
|
51029
51390
|
const batches = [];
|
|
51030
51391
|
let lines = [];
|
|
51031
51392
|
let bytes = 0;
|
|
51032
|
-
for (const
|
|
51033
|
-
const line = JSON.stringify(
|
|
51393
|
+
for (const record4 of records) {
|
|
51394
|
+
const line = JSON.stringify(record4);
|
|
51034
51395
|
const lineBytes = encoder.encode(line).byteLength + (lines.length ? 1 : 0);
|
|
51035
51396
|
if (lineBytes > maxBytes) throw new Error(`A single Pinecone knowledge record exceeds ${maxBytes} bytes.`);
|
|
51036
51397
|
if (lines.length && (lines.length >= maxRecords || bytes + lineBytes > maxBytes)) {
|
|
@@ -51044,9 +51405,9 @@ function batchNdjson(records, maxRecords, maxBytes) {
|
|
|
51044
51405
|
if (lines.length) batches.push(lines.join("\n"));
|
|
51045
51406
|
return batches;
|
|
51046
51407
|
}
|
|
51047
|
-
function validatePineconeRecordMetadataSize(
|
|
51408
|
+
function validatePineconeRecordMetadataSize(record4, textField, label) {
|
|
51048
51409
|
const storedMetadata = Object.fromEntries(
|
|
51049
|
-
Object.entries(
|
|
51410
|
+
Object.entries(record4).filter(([key]) => key !== "_id" && key !== textField)
|
|
51050
51411
|
);
|
|
51051
51412
|
if (new TextEncoder().encode(JSON.stringify(storedMetadata)).byteLength > 40 * 1024) {
|
|
51052
51413
|
throw new Error(`Pinecone metadata for ${label} exceeds 40 KB.`);
|
|
@@ -55099,6 +55460,7 @@ function loadProjectAndAttachedDataFromString(content) {
|
|
|
55099
55460
|
}
|
|
55100
55461
|
|
|
55101
55462
|
// src/index.ts
|
|
55463
|
+
installCodeRunnerNamespace(exports_exports);
|
|
55102
55464
|
var Rivet = void 0;
|
|
55103
55465
|
// Annotate the CommonJS export names for ESM import in node:
|
|
55104
55466
|
0 && (module.exports = {
|
|
@@ -55114,6 +55476,8 @@ var Rivet = void 0;
|
|
|
55114
55476
|
AssembleMessageNodeImpl,
|
|
55115
55477
|
AssemblePromptNodeImpl,
|
|
55116
55478
|
AudioNodeImpl,
|
|
55479
|
+
BASETEN_DECISIONS_ENDPOINT,
|
|
55480
|
+
BASETEN_DEFAULT_CREDENTIAL_NAMES,
|
|
55117
55481
|
BooleanNodeImpl,
|
|
55118
55482
|
BrowserNativeApi,
|
|
55119
55483
|
BuildKnowledgeContextNodeImpl,
|
|
@@ -55283,6 +55647,8 @@ var Rivet = void 0;
|
|
|
55283
55647
|
RivetLLMProfileHealthPolicyError,
|
|
55284
55648
|
RivetStoredValueController,
|
|
55285
55649
|
STREAM_RESPONSE_HELPER_MESSAGE,
|
|
55650
|
+
SUBQ_DECISIONS_ENDPOINT,
|
|
55651
|
+
SUBQ_DEFAULT_CREDENTIAL_NAMES,
|
|
55286
55652
|
SearchKnowledgeNodeImpl,
|
|
55287
55653
|
SetGlobalNodeImpl,
|
|
55288
55654
|
SetStoredValueNodeImpl,
|
|
@@ -55334,6 +55700,7 @@ var Rivet = void 0;
|
|
|
55334
55700
|
autoevalsPlugin,
|
|
55335
55701
|
base64ToUint8Array,
|
|
55336
55702
|
baseDirs,
|
|
55703
|
+
basetenClassifierProvider,
|
|
55337
55704
|
booleanNode,
|
|
55338
55705
|
buildAgentProfileAttemptInspectorRows,
|
|
55339
55706
|
buildAgentResponseTrace,
|
|
@@ -55541,6 +55908,7 @@ var Rivet = void 0;
|
|
|
55541
55908
|
getProcessorEvents,
|
|
55542
55909
|
getProcessorSSEStream,
|
|
55543
55910
|
getProfileAttemptOmissionNotice,
|
|
55911
|
+
getProfileDisplayName,
|
|
55544
55912
|
getProjectConnectionComparisonKey,
|
|
55545
55913
|
getProjectGlobalVariableIds,
|
|
55546
55914
|
getProjectNodeFieldComparisons,
|
|
@@ -55842,6 +56210,7 @@ var Rivet = void 0;
|
|
|
55842
56210
|
stringifyToolResult,
|
|
55843
56211
|
stringifyUiGraphValue,
|
|
55844
56212
|
subGraphNode,
|
|
56213
|
+
subqClassifierProvider,
|
|
55845
56214
|
summarizeAgentResponseCalls,
|
|
55846
56215
|
summarizeChatV2RequestPlan,
|
|
55847
56216
|
summarizeDataValueForLog,
|