@desplega.ai/agent-swarm 1.104.0 → 1.106.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/{actions-2expzt47.js → actions-pk6xqa2y.js} +6 -6
- package/dist/{anthropic-messages-8q7p5vyq.js → anthropic-messages-8nc6r2dw.js} +10 -4
- package/dist/{app-dr8hwx7z.js → app-pmfvefkh.js} +3 -3
- package/dist/{assistant-9rhgsw7v.js → assistant-wcjpqxk6.js} +9 -9
- package/dist/{azure-openai-responses-0dmr2hzc.js → azure-openai-responses-6yfzw3qw.js} +10 -18
- package/dist/{boot-reembed-9kt97g1z.js → boot-reembed-atv4kcrh.js} +3 -3
- package/dist/{boot-reembed-3q1aywnz.js → boot-reembed-zanbm36c.js} +4 -4
- package/dist/{boot-scrub-logs-vskq108e.js → boot-scrub-logs-asq051ff.js} +2 -2
- package/dist/{claude-adapter-e3dhkq85.js → claude-adapter-w96mzan4.js} +2 -2
- package/dist/{claude-managed-adapter-z29hjgzz.js → claude-managed-adapter-vj9kzegz.js} +4 -4
- package/dist/{claude-managed-setup-ftbmvmvx.js → claude-managed-setup-t0wkvzgz.js} +1 -1
- package/dist/{cli-92fqyjcv.js → cli-07er7wrs.js} +1 -1
- package/dist/{cli-y9p3e94h.js → cli-08fnz4jm.js} +3 -3
- package/dist/{cli-yjt8a36k.js → cli-39jaysbv.js} +8 -6
- package/dist/{cli-5pf0b84v.js → cli-4fwzc50f.js} +2 -2
- package/dist/{cli-p03mawph.js → cli-50nss8e8.js} +928 -335
- package/dist/{cli-e7bwjntj.js → cli-6hqvenfv.js} +1 -1
- package/dist/{cli-0jw6j755.js → cli-6xn2xv4r.js} +24 -8
- package/dist/{cli-2g9jf9ek.js → cli-842gfjn1.js} +1 -1
- package/dist/{cli-v1syqkcb.js → cli-84gyjn6h.js} +146 -3
- package/dist/{cli-7b9ctyfq.js → cli-8da61htc.js} +1 -1
- package/dist/{cli-nzc0h54v.js → cli-8fhhmzbh.js} +1 -1
- package/dist/{cli-khe4x17a.js → cli-anrn8brw.js} +3 -3
- package/dist/{cli-2q1ct4en.js → cli-bsyka9ta.js} +104 -3
- package/dist/{cli-p04j6hjv.js → cli-dqhz8451.js} +1 -1
- package/dist/{cli-s42f54ja.js → cli-f7ypwjgh.js} +1 -1
- package/dist/{cli-p4cj4vhc.js → cli-hmqkes02.js} +1 -1
- package/dist/{cli-23zk7xqy.js → cli-j1172z85.js} +26 -18
- package/dist/{cli-yp2krx5r.js → cli-jk4tj5m6.js} +9 -3
- package/dist/{cli-q5tshxd6.js → cli-k7gt5r0p.js} +1 -1
- package/dist/{cli-54h5daha.js → cli-n38fcvhe.js} +6 -6
- package/dist/{cli-2hap19dv.js → cli-p7hff99g.js} +3 -3
- package/dist/cli-pscrc6tw.js +73 -0
- package/dist/{cli-yvektv79.js → cli-pxddwmyc.js} +1 -1
- package/dist/{cli-ncg70f07.js → cli-q44nxhwq.js} +1 -1
- package/dist/{cli-d4z1csms.js → cli-qtr61agf.js} +3 -3
- package/dist/{cli-zaxksbgj.js → cli-rp5kaak8.js} +5 -5
- package/dist/{cli-0fxvpa2q.js → cli-sdpnhajn.js} +150 -163
- package/dist/{cli-w1nfskkg.js → cli-sp3c9fwf.js} +2 -2
- package/dist/{cli-gj2n2ec1.js → cli-tfcrm7ds.js} +1 -1
- package/dist/{cli-0k9dc6ks.js → cli-tghre7g6.js} +1 -0
- package/dist/{cli-qvzgncd8.js → cli-v90vvqt8.js} +401 -125
- package/dist/{cli-zghef0em.js → cli-v9853xza.js} +1 -1
- package/dist/{cli-t9v14cnd.js → cli-wfhe4tgs.js} +1 -1
- package/dist/{cli-7v4y3hyd.js → cli-xgssgdqn.js} +2 -2
- package/dist/{cli-etvgz5x8.js → cli-xvs40j7w.js} +4 -4
- package/dist/{cli-jntqphs0.js → cli-ygcrdkqt.js} +15 -9
- package/dist/{cli-2957pqpj.js → cli-yv9dttkh.js} +32 -9
- package/dist/cli.js +20 -17
- package/dist/{codex-adapter-w0xharsg.js → codex-adapter-h9rj59tj.js} +5 -5
- package/dist/{codex-session-runner-kzbjcm2k.js → codex-session-runner-2ybavr0w.js} +5 -5
- package/dist/{commands-wfrkef57.js → commands-075ak6vf.js} +2 -2
- package/dist/{db-c42pxt7h.js → db-60fj8j7t.js} +2 -2
- package/dist/{google-generative-ai-mdn340ga.js → google-generative-ai-rf42vj2h.js} +9 -4
- package/dist/{google-vertex-mkdewpwe.js → google-vertex-m92pj5fb.js} +9 -4
- package/dist/{handlers-n36zkfvx.js → handlers-96j9z4gk.js} +9 -9
- package/dist/{hook-gw3vhv6s.js → hook-f58wyvmy.js} +3 -3
- package/dist/{http-59ygpn2h.js → http-naqhj1n0.js} +579 -52
- package/dist/{index-xf6fp4y1.js → index-45bqm6xc.js} +5 -5
- package/dist/{index-xz8vaa5c.js → index-f5e873a5.js} +10 -10
- package/dist/{index-jca7jdpt.js → index-jscerv2x.js} +10 -6
- package/dist/{index-881c1baf.js → index-v3r40ak0.js} +8 -8
- package/dist/{keepalive-mj4302vw.js → keepalive-8gbgeg21.js} +4 -4
- package/dist/{lead-qm0xjvkv.js → lead-hj6stakm.js} +26 -26
- package/dist/{maintenance-xppxbe4t.js → maintenance-1nvd0jva.js} +4 -4
- package/dist/{mistral-conversations-j380wd2q.js → mistral-conversations-26yrnbf1.js} +2 -2
- package/dist/{onboard-ejx6yxh8.js → onboard-8myqe0jh.js} +2 -2
- package/dist/{openai-codex-responses-v80z7kgx.js → openai-codex-responses-8h6kvfv8.js} +16 -25
- package/dist/{openai-completions-39vefwrq.js → openai-completions-x6kjnqjd.js} +11 -5
- package/dist/{openai-responses-dp5bkm3q.js → openai-responses-7jwyz3ds.js} +8 -16
- package/dist/{opencode-adapter-s8vsmzpy.js → opencode-adapter-p2w6efwc.js} +2 -2
- package/dist/{openrouter-images-54cva05t.js → openrouter-images-537nmn1r.js} +5 -1
- package/dist/{otel-impl-zs5exkpk.js → otel-impl-tddx9x81.js} +4510 -4465
- package/dist/{pi-mono-adapter-zf7dt1wg.js → pi-mono-adapter-y037wnp4.js} +596 -297
- package/dist/{pricing-refresh-nqyf8bkb.js → pricing-refresh-f6cgj5br.js} +4 -4
- package/dist/{seed-pricing-w3x550cj.js → seed-pricing-3tqmbe0p.js} +3 -3
- package/dist/{setup-7729ktfj.js → setup-tq3ept9k.js} +2 -2
- package/dist/{worker-4ttemwhw.js → worker-526psbtb.js} +26 -26
- package/openapi.json +315 -1
- package/package.json +8 -6
- package/src/be/db.ts +6 -2
- package/src/be/memory/access.ts +5 -0
- package/src/be/migrations/102_script_apis.sql +31 -0
- package/src/be/modelsdev-cache.json +22170 -7247
- package/src/be/scripts/db.ts +214 -1
- package/src/be/seed-pricing.ts +1 -1
- package/src/commands/claude-managed-setup.ts +1 -1
- package/src/hooks/tool-loop-detection.test.ts +81 -1
- package/src/hooks/tool-loop-detection.ts +53 -10
- package/src/http/index.ts +11 -1
- package/src/http/mcp.ts +49 -0
- package/src/http/memory.ts +21 -11
- package/src/http/pages-public.ts +123 -2
- package/src/http/scripts.ts +213 -0
- package/src/http/session-data.ts +16 -0
- package/src/http/x.ts +244 -0
- package/src/otel-impl.ts +73 -0
- package/src/otel.ts +12 -0
- package/src/prompts/session-templates.ts +5 -1
- package/src/providers/claude-managed-models.ts +9 -0
- package/src/server.ts +2 -0
- package/src/tests/agents-list-model-display.test.ts +5 -0
- package/src/tests/bedrock-model-groups.test.ts +3 -0
- package/src/tests/claude-managed-adapter.test.ts +14 -0
- package/src/tests/claude-managed-setup.test.ts +3 -3
- package/src/tests/context-window.test.ts +1 -0
- package/src/tests/harness-provider-resolution.test.ts +39 -0
- package/src/tests/http-api-integration.test.ts +1 -1
- package/src/tests/mcp-user-route.test.ts +70 -5
- package/src/tests/memory-get-tool.test.ts +132 -0
- package/src/tests/memory-http-recall-gating.test.ts +17 -1
- package/src/tests/migration-046-budgets.test.ts +32 -0
- package/src/tests/otel-impl-secret-scrubbing.test.ts +101 -3
- package/src/tests/otel-session-cost-metrics.test.ts +281 -0
- package/src/tests/pages-authed-mode.test.ts +50 -0
- package/src/tests/preload.ts +26 -0
- package/src/tests/register-service-security.test.ts +194 -0
- package/src/tests/script-apis-mcp.test.ts +308 -0
- package/src/tests/scripts-external-api.test.ts +449 -0
- package/src/tests/session-costs-model-key-normalize.test.ts +1 -0
- package/src/tests/update-profile-auth.test.ts +35 -1
- package/src/tools/memory-get.ts +17 -2
- package/src/tools/register-service.ts +68 -4
- package/src/tools/script-apis.ts +158 -0
- package/src/tools/script-common.ts +1 -1
- package/src/tools/tool-config.ts +2 -1
- package/src/tools/update-profile.ts +84 -1
- package/src/types.ts +27 -1
- package/src/utils/context-window.ts +1 -0
- package/src/utils/harness-provider.ts +35 -6
- package/src/utils/short-id.ts +44 -0
- package/templates/community/code-health-reports/run.sh +12 -6
- package/templates/community/dora-metrics/run.sh +10 -2
- package/templates/official/coder/start-up.sh +2 -2
- package/templates/official/content-reviewer/start-up.sh +2 -2
- package/templates/official/content-strategist/start-up.sh +2 -2
- package/templates/official/content-writer/start-up.sh +2 -2
- package/templates/official/discoverability-optimizer/start-up.sh +2 -2
- package/templates/official/ux-principles/start-up.sh +5 -5
- package/templates/skills/swarm-scripts/SKILL.md +4 -0
- package/templates/skills/swarm-scripts/content.md +4 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createSwarmEventHandler
|
|
3
|
-
} from "./cli-
|
|
3
|
+
} from "./cli-07er7wrs.js";
|
|
4
4
|
import {
|
|
5
5
|
checkToolLoop
|
|
6
|
-
} from "./cli-
|
|
6
|
+
} from "./cli-yv9dttkh.js";
|
|
7
7
|
import {
|
|
8
8
|
readPkgVersion
|
|
9
9
|
} from "./cli-d6n0thxw.js";
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
clampContextPercent,
|
|
16
16
|
computeContextUsedUnified,
|
|
17
17
|
getContextWindowSize
|
|
18
|
-
} from "./cli-
|
|
18
|
+
} from "./cli-tghre7g6.js";
|
|
19
19
|
import {
|
|
20
20
|
init_secret_scrubber,
|
|
21
21
|
scrubSecrets
|
|
@@ -38,6 +38,12 @@ var CLAUDE_MANAGED_MODEL_PRICING = {
|
|
|
38
38
|
cacheReadPerMillion: 1,
|
|
39
39
|
cacheWritePerMillion: 12.5
|
|
40
40
|
},
|
|
41
|
+
"claude-sonnet-5": {
|
|
42
|
+
inputPerMillion: 3,
|
|
43
|
+
outputPerMillion: 15,
|
|
44
|
+
cacheReadPerMillion: 0.3,
|
|
45
|
+
cacheWritePerMillion: 3.75
|
|
46
|
+
},
|
|
41
47
|
"claude-sonnet-4-6": {
|
|
42
48
|
inputPerMillion: 3,
|
|
43
49
|
outputPerMillion: 15,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
getScriptVersion,
|
|
10
10
|
listRelationalCredentialBindings,
|
|
11
11
|
validateScriptImports
|
|
12
|
-
} from "./cli-
|
|
12
|
+
} from "./cli-84gyjn6h.js";
|
|
13
13
|
import {
|
|
14
14
|
checkpointStep,
|
|
15
15
|
checkpointStepFailure,
|
|
@@ -19,14 +19,14 @@ import {
|
|
|
19
19
|
interpolateNodeConfig,
|
|
20
20
|
runStepValidation,
|
|
21
21
|
walkGraph
|
|
22
|
-
} from "./cli-
|
|
22
|
+
} from "./cli-v9853xza.js";
|
|
23
23
|
import {
|
|
24
24
|
getAppUrl
|
|
25
25
|
} from "./cli-dh55d5fg.js";
|
|
26
26
|
import {
|
|
27
27
|
withSiblingAwareness,
|
|
28
28
|
workflowContextKey
|
|
29
|
-
} from "./cli-
|
|
29
|
+
} from "./cli-6hqvenfv.js";
|
|
30
30
|
import {
|
|
31
31
|
FollowUpConfigSchema,
|
|
32
32
|
ModelTierSchema,
|
|
@@ -59,7 +59,7 @@ import {
|
|
|
59
59
|
splitLegacyModelAlias,
|
|
60
60
|
updateWorkflowRun,
|
|
61
61
|
updateWorkflowRunStep
|
|
62
|
-
} from "./cli-
|
|
62
|
+
} from "./cli-6xn2xv4r.js";
|
|
63
63
|
import {
|
|
64
64
|
init_zod
|
|
65
65
|
} from "./cli-q21d49ac.js";
|
|
@@ -1428,7 +1428,7 @@ class HumanInTheLoopExecutor extends BaseExecutor {
|
|
|
1428
1428
|
}
|
|
1429
1429
|
if (notification.channel === "slack") {
|
|
1430
1430
|
try {
|
|
1431
|
-
const { getSlackApp } = await import("./app-
|
|
1431
|
+
const { getSlackApp } = await import("./app-pmfvefkh.js");
|
|
1432
1432
|
const slackApp = getSlackApp();
|
|
1433
1433
|
if (!slackApp) {
|
|
1434
1434
|
console.warn("[HITL] Slack not initialized — cannot send notification");
|
|
@@ -1542,7 +1542,7 @@ class NotifyExecutor extends BaseExecutor {
|
|
|
1542
1542
|
}
|
|
1543
1543
|
}
|
|
1544
1544
|
case "slack": {
|
|
1545
|
-
const { getSlackApp } = await import("./app-
|
|
1545
|
+
const { getSlackApp } = await import("./app-pmfvefkh.js");
|
|
1546
1546
|
const app = getSlackApp();
|
|
1547
1547
|
if (!app) {
|
|
1548
1548
|
return {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
recordUnmappedIdentity
|
|
3
|
-
} from "./cli-
|
|
3
|
+
} from "./cli-tfcrm7ds.js";
|
|
4
4
|
import {
|
|
5
5
|
findOrCreateUserByEmail,
|
|
6
6
|
findUserByExternalId,
|
|
7
7
|
linkIdentity
|
|
8
|
-
} from "./cli-
|
|
8
|
+
} from "./cli-pxddwmyc.js";
|
|
9
9
|
import {
|
|
10
10
|
getKv,
|
|
11
11
|
init_db,
|
|
12
12
|
upsertKv
|
|
13
|
-
} from "./cli-
|
|
13
|
+
} from "./cli-6xn2xv4r.js";
|
|
14
14
|
|
|
15
15
|
// src/slack/enrich.ts
|
|
16
16
|
init_db();
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// node_modules/@earendil-works/pi-ai/dist/utils/error-body.js
|
|
2
|
+
var MAX_PROVIDER_ERROR_BODY_CHARS = 4000;
|
|
3
|
+
function normalizeProviderError(error) {
|
|
4
|
+
if (!(error instanceof Error)) {
|
|
5
|
+
return { message: safeJsonStringify(error), messageCarriesBody: false };
|
|
6
|
+
}
|
|
7
|
+
const sdkError = error;
|
|
8
|
+
const status = extractStatus(sdkError);
|
|
9
|
+
const body = extractBody(sdkError);
|
|
10
|
+
const messageCarriesBody = body === undefined || error.message.includes(body);
|
|
11
|
+
return {
|
|
12
|
+
status,
|
|
13
|
+
body,
|
|
14
|
+
message: error.message,
|
|
15
|
+
messageCarriesBody
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function extractStatus(error) {
|
|
19
|
+
if (typeof error.statusCode === "number")
|
|
20
|
+
return error.statusCode;
|
|
21
|
+
if (typeof error.status === "number")
|
|
22
|
+
return error.status;
|
|
23
|
+
if (typeof error.$metadata?.httpStatusCode === "number")
|
|
24
|
+
return error.$metadata.httpStatusCode;
|
|
25
|
+
if (typeof error.$response?.statusCode === "number")
|
|
26
|
+
return error.$response.statusCode;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
function extractBody(error) {
|
|
30
|
+
const bodyText = pickBodyText(error);
|
|
31
|
+
if (bodyText === undefined)
|
|
32
|
+
return;
|
|
33
|
+
const trimmed = bodyText.trim();
|
|
34
|
+
if (trimmed.length === 0)
|
|
35
|
+
return;
|
|
36
|
+
return truncateErrorText(trimmed, MAX_PROVIDER_ERROR_BODY_CHARS);
|
|
37
|
+
}
|
|
38
|
+
function pickBodyText(error) {
|
|
39
|
+
if (typeof error.body === "string")
|
|
40
|
+
return error.body;
|
|
41
|
+
if (isNonEmptyObject(error.error))
|
|
42
|
+
return safeJsonStringify(error.error);
|
|
43
|
+
const responseBody = error.$response?.body;
|
|
44
|
+
if (typeof responseBody === "string")
|
|
45
|
+
return responseBody;
|
|
46
|
+
if (isNonEmptyObject(responseBody))
|
|
47
|
+
return safeJsonStringify(responseBody);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
function isNonEmptyObject(value) {
|
|
51
|
+
return typeof value === "object" && value !== null && Object.keys(value).length > 0;
|
|
52
|
+
}
|
|
53
|
+
function formatProviderError(norm, prefix) {
|
|
54
|
+
if (norm.messageCarriesBody || norm.status === undefined || norm.body === undefined) {
|
|
55
|
+
return prefix !== undefined && norm.status !== undefined ? `${prefix} (${norm.status}): ${norm.message}` : norm.message;
|
|
56
|
+
}
|
|
57
|
+
return prefix !== undefined ? `${prefix} (${norm.status}): ${norm.body}` : `${norm.status}: ${norm.body}`;
|
|
58
|
+
}
|
|
59
|
+
function truncateErrorText(text, maxChars) {
|
|
60
|
+
if (text.length <= maxChars)
|
|
61
|
+
return text;
|
|
62
|
+
return `${text.slice(0, maxChars)}... [truncated ${text.length - maxChars} chars]`;
|
|
63
|
+
}
|
|
64
|
+
function safeJsonStringify(value) {
|
|
65
|
+
try {
|
|
66
|
+
const serialized = JSON.stringify(value);
|
|
67
|
+
return serialized === undefined ? String(value) : serialized;
|
|
68
|
+
} catch {
|
|
69
|
+
return String(value);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { normalizeProviderError, formatProviderError };
|
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
getNextResumeGeneration,
|
|
5
5
|
getResumeGeneration,
|
|
6
6
|
repointTrackerSyncBySwarmId
|
|
7
|
-
} from "./cli-
|
|
7
|
+
} from "./cli-f7ypwjgh.js";
|
|
8
8
|
import {
|
|
9
9
|
getExecutorRegistry,
|
|
10
10
|
recoverIncompleteRuns
|
|
11
|
-
} from "./cli-
|
|
11
|
+
} from "./cli-n38fcvhe.js";
|
|
12
12
|
import {
|
|
13
13
|
assignUnassignedTaskPending,
|
|
14
14
|
backfillSupersedeTaskResumeTaskId,
|
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
resolveTemplate,
|
|
44
44
|
supersedeTask,
|
|
45
45
|
updateAgentStatus
|
|
46
|
-
} from "./cli-
|
|
46
|
+
} from "./cli-6xn2xv4r.js";
|
|
47
47
|
|
|
48
48
|
// src/heartbeat/heartbeat.ts
|
|
49
49
|
init_db();
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
getTaskById,
|
|
26
26
|
init_db,
|
|
27
27
|
setSlackMessageTracking
|
|
28
|
-
} from "./cli-
|
|
28
|
+
} from "./cli-6xn2xv4r.js";
|
|
29
29
|
import {
|
|
30
30
|
require_receiver,
|
|
31
31
|
require_sender,
|
|
@@ -54980,13 +54980,13 @@ async function initSlackApp() {
|
|
|
54980
54980
|
socketMode: true,
|
|
54981
54981
|
logLevel: import_bolt.LogLevel.DEBUG
|
|
54982
54982
|
});
|
|
54983
|
-
const { registerMessageHandler } = await import("./handlers-
|
|
54984
|
-
const { registerCommandHandler } = await import("./commands-
|
|
54985
|
-
const { registerActionHandlers } = await import("./actions-
|
|
54983
|
+
const { registerMessageHandler } = await import("./handlers-96j9z4gk.js");
|
|
54984
|
+
const { registerCommandHandler } = await import("./commands-075ak6vf.js");
|
|
54985
|
+
const { registerActionHandlers } = await import("./actions-pk6xqa2y.js");
|
|
54986
54986
|
registerMessageHandler(app);
|
|
54987
54987
|
registerCommandHandler(app);
|
|
54988
54988
|
registerActionHandlers(app);
|
|
54989
|
-
const { createAssistant } = await import("./assistant-
|
|
54989
|
+
const { createAssistant } = await import("./assistant-wcjpqxk6.js");
|
|
54990
54990
|
app.assistant(createAssistant());
|
|
54991
54991
|
return app;
|
|
54992
54992
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "./cli-zyxs93y9.js";
|
|
7
7
|
import {
|
|
8
8
|
transformMessages
|
|
9
|
-
} from "./cli-
|
|
9
|
+
} from "./cli-bsyka9ta.js";
|
|
10
10
|
import {
|
|
11
11
|
sanitizeSurrogates
|
|
12
12
|
} from "./cli-y2apkfe2.js";
|
|
@@ -199,11 +199,56 @@ function convertResponsesTools(tools, options) {
|
|
|
199
199
|
}));
|
|
200
200
|
}
|
|
201
201
|
async function processResponsesStream(openaiStream, output, stream, model, options) {
|
|
202
|
-
let currentItem = null;
|
|
203
|
-
let currentBlock = null;
|
|
204
202
|
let sawTerminalResponseEvent = false;
|
|
205
|
-
const
|
|
206
|
-
const
|
|
203
|
+
const outputSlots = new Map;
|
|
204
|
+
const getSlot = (outputIndex, type) => {
|
|
205
|
+
const slot = outputSlots.get(outputIndex);
|
|
206
|
+
return slot?.type === type ? slot : undefined;
|
|
207
|
+
};
|
|
208
|
+
const createSlot = (outputIndex, item) => {
|
|
209
|
+
if (item.type === "reasoning") {
|
|
210
|
+
const block = { type: "thinking", thinking: "" };
|
|
211
|
+
output.content.push(block);
|
|
212
|
+
const slot = {
|
|
213
|
+
type: "thinking",
|
|
214
|
+
block,
|
|
215
|
+
contentIndex: output.content.length - 1
|
|
216
|
+
};
|
|
217
|
+
outputSlots.set(outputIndex, slot);
|
|
218
|
+
stream.push({ type: "thinking_start", contentIndex: slot.contentIndex, partial: output });
|
|
219
|
+
return slot;
|
|
220
|
+
}
|
|
221
|
+
if (item.type === "message") {
|
|
222
|
+
const block = { type: "text", text: "" };
|
|
223
|
+
output.content.push(block);
|
|
224
|
+
const slot = { type: "text", block, contentIndex: output.content.length - 1 };
|
|
225
|
+
outputSlots.set(outputIndex, slot);
|
|
226
|
+
stream.push({ type: "text_start", contentIndex: slot.contentIndex, partial: output });
|
|
227
|
+
return slot;
|
|
228
|
+
}
|
|
229
|
+
if (item.type === "function_call") {
|
|
230
|
+
const block = {
|
|
231
|
+
type: "toolCall",
|
|
232
|
+
id: `${item.call_id}|${item.id}`,
|
|
233
|
+
name: item.name,
|
|
234
|
+
arguments: {},
|
|
235
|
+
partialJson: item.arguments || ""
|
|
236
|
+
};
|
|
237
|
+
output.content.push(block);
|
|
238
|
+
const slot = {
|
|
239
|
+
type: "toolCall",
|
|
240
|
+
block,
|
|
241
|
+
contentIndex: output.content.length - 1
|
|
242
|
+
};
|
|
243
|
+
outputSlots.set(outputIndex, slot);
|
|
244
|
+
stream.push({ type: "toolcall_start", contentIndex: slot.contentIndex, partial: output });
|
|
245
|
+
return slot;
|
|
246
|
+
}
|
|
247
|
+
return;
|
|
248
|
+
};
|
|
249
|
+
const getOrCreateSlot = (outputIndex, item) => {
|
|
250
|
+
return outputSlots.get(outputIndex) ?? createSlot(outputIndex, item);
|
|
251
|
+
};
|
|
207
252
|
const finalizeResponse = (response) => {
|
|
208
253
|
sawTerminalResponseEvent = true;
|
|
209
254
|
if (response?.id) {
|
|
@@ -216,6 +261,7 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
|
|
|
216
261
|
output: response.usage.output_tokens || 0,
|
|
217
262
|
cacheRead: cachedTokens,
|
|
218
263
|
cacheWrite: 0,
|
|
264
|
+
reasoning: response.usage.output_tokens_details?.reasoning_tokens || 0,
|
|
219
265
|
totalTokens: response.usage.total_tokens || 0,
|
|
220
266
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
|
|
221
267
|
};
|
|
@@ -234,194 +280,135 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
|
|
|
234
280
|
if (event.type === "response.created") {
|
|
235
281
|
output.responseId = event.response.id;
|
|
236
282
|
} else if (event.type === "response.output_item.added") {
|
|
237
|
-
|
|
238
|
-
if (item.type === "reasoning") {
|
|
239
|
-
currentItem = item;
|
|
240
|
-
currentBlock = { type: "thinking", thinking: "" };
|
|
241
|
-
output.content.push(currentBlock);
|
|
242
|
-
stream.push({ type: "thinking_start", contentIndex: blockIndex(), partial: output });
|
|
243
|
-
} else if (item.type === "message") {
|
|
244
|
-
currentItem = item;
|
|
245
|
-
currentBlock = { type: "text", text: "" };
|
|
246
|
-
output.content.push(currentBlock);
|
|
247
|
-
stream.push({ type: "text_start", contentIndex: blockIndex(), partial: output });
|
|
248
|
-
} else if (item.type === "function_call") {
|
|
249
|
-
currentItem = item;
|
|
250
|
-
currentBlock = {
|
|
251
|
-
type: "toolCall",
|
|
252
|
-
id: `${item.call_id}|${item.id}`,
|
|
253
|
-
name: item.name,
|
|
254
|
-
arguments: {},
|
|
255
|
-
partialJson: item.arguments || ""
|
|
256
|
-
};
|
|
257
|
-
output.content.push(currentBlock);
|
|
258
|
-
stream.push({ type: "toolcall_start", contentIndex: blockIndex(), partial: output });
|
|
259
|
-
}
|
|
260
|
-
} else if (event.type === "response.reasoning_summary_part.added") {
|
|
261
|
-
if (currentItem && currentItem.type === "reasoning") {
|
|
262
|
-
currentItem.summary = currentItem.summary || [];
|
|
263
|
-
currentItem.summary.push(event.part);
|
|
264
|
-
}
|
|
283
|
+
createSlot(event.output_index, event.item);
|
|
265
284
|
} else if (event.type === "response.reasoning_summary_text.delta") {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
partial: output
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
}
|
|
285
|
+
const slot = getSlot(event.output_index, "thinking");
|
|
286
|
+
if (!slot)
|
|
287
|
+
continue;
|
|
288
|
+
slot.block.thinking += event.delta;
|
|
289
|
+
stream.push({
|
|
290
|
+
type: "thinking_delta",
|
|
291
|
+
contentIndex: slot.contentIndex,
|
|
292
|
+
delta: event.delta,
|
|
293
|
+
partial: output
|
|
294
|
+
});
|
|
280
295
|
} else if (event.type === "response.reasoning_summary_part.done") {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
currentBlock.thinking += `
|
|
296
|
+
const slot = getSlot(event.output_index, "thinking");
|
|
297
|
+
if (!slot)
|
|
298
|
+
continue;
|
|
299
|
+
slot.block.thinking += `
|
|
286
300
|
|
|
287
301
|
`;
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
type: "thinking_delta",
|
|
293
|
-
contentIndex: blockIndex(),
|
|
294
|
-
delta: `
|
|
302
|
+
stream.push({
|
|
303
|
+
type: "thinking_delta",
|
|
304
|
+
contentIndex: slot.contentIndex,
|
|
305
|
+
delta: `
|
|
295
306
|
|
|
296
307
|
`,
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
}
|
|
308
|
+
partial: output
|
|
309
|
+
});
|
|
301
310
|
} else if (event.type === "response.reasoning_text.delta") {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if (currentItem?.type === "message") {
|
|
313
|
-
currentItem.content = currentItem.content || [];
|
|
314
|
-
if (event.part.type === "output_text" || event.part.type === "refusal") {
|
|
315
|
-
currentItem.content.push(event.part);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
311
|
+
const slot = getSlot(event.output_index, "thinking");
|
|
312
|
+
if (!slot)
|
|
313
|
+
continue;
|
|
314
|
+
slot.block.thinking += event.delta;
|
|
315
|
+
stream.push({
|
|
316
|
+
type: "thinking_delta",
|
|
317
|
+
contentIndex: slot.contentIndex,
|
|
318
|
+
delta: event.delta,
|
|
319
|
+
partial: output
|
|
320
|
+
});
|
|
318
321
|
} else if (event.type === "response.output_text.delta") {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
contentIndex: blockIndex(),
|
|
330
|
-
delta: event.delta,
|
|
331
|
-
partial: output
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
}
|
|
322
|
+
const slot = getSlot(event.output_index, "text");
|
|
323
|
+
if (!slot)
|
|
324
|
+
continue;
|
|
325
|
+
slot.block.text += event.delta;
|
|
326
|
+
stream.push({
|
|
327
|
+
type: "text_delta",
|
|
328
|
+
contentIndex: slot.contentIndex,
|
|
329
|
+
delta: event.delta,
|
|
330
|
+
partial: output
|
|
331
|
+
});
|
|
335
332
|
} else if (event.type === "response.refusal.delta") {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
333
|
+
const slot = getSlot(event.output_index, "text");
|
|
334
|
+
if (!slot)
|
|
335
|
+
continue;
|
|
336
|
+
slot.block.text += event.delta;
|
|
337
|
+
stream.push({
|
|
338
|
+
type: "text_delta",
|
|
339
|
+
contentIndex: slot.contentIndex,
|
|
340
|
+
delta: event.delta,
|
|
341
|
+
partial: output
|
|
342
|
+
});
|
|
343
|
+
} else if (event.type === "response.function_call_arguments.delta") {
|
|
344
|
+
const slot = getSlot(event.output_index, "toolCall");
|
|
345
|
+
if (!slot)
|
|
346
|
+
continue;
|
|
347
|
+
slot.block.partialJson += event.delta;
|
|
348
|
+
slot.block.arguments = parseStreamingJson(slot.block.partialJson);
|
|
349
|
+
stream.push({
|
|
350
|
+
type: "toolcall_delta",
|
|
351
|
+
contentIndex: slot.contentIndex,
|
|
352
|
+
delta: event.delta,
|
|
353
|
+
partial: output
|
|
354
|
+
});
|
|
355
|
+
} else if (event.type === "response.function_call_arguments.done") {
|
|
356
|
+
const slot = getSlot(event.output_index, "toolCall");
|
|
357
|
+
if (!slot)
|
|
358
|
+
continue;
|
|
359
|
+
const previousPartialJson = slot.block.partialJson;
|
|
360
|
+
slot.block.partialJson = event.arguments;
|
|
361
|
+
slot.block.arguments = parseStreamingJson(slot.block.partialJson);
|
|
362
|
+
if (event.arguments.startsWith(previousPartialJson)) {
|
|
363
|
+
const delta = event.arguments.slice(previousPartialJson.length);
|
|
364
|
+
if (delta.length > 0) {
|
|
344
365
|
stream.push({
|
|
345
|
-
type: "
|
|
346
|
-
contentIndex:
|
|
347
|
-
delta
|
|
366
|
+
type: "toolcall_delta",
|
|
367
|
+
contentIndex: slot.contentIndex,
|
|
368
|
+
delta,
|
|
348
369
|
partial: output
|
|
349
370
|
});
|
|
350
371
|
}
|
|
351
372
|
}
|
|
352
|
-
} else if (event.type === "response.function_call_arguments.delta") {
|
|
353
|
-
if (currentItem?.type === "function_call" && currentBlock?.type === "toolCall") {
|
|
354
|
-
currentBlock.partialJson += event.delta;
|
|
355
|
-
currentBlock.arguments = parseStreamingJson(currentBlock.partialJson);
|
|
356
|
-
stream.push({
|
|
357
|
-
type: "toolcall_delta",
|
|
358
|
-
contentIndex: blockIndex(),
|
|
359
|
-
delta: event.delta,
|
|
360
|
-
partial: output
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
} else if (event.type === "response.function_call_arguments.done") {
|
|
364
|
-
if (currentItem?.type === "function_call" && currentBlock?.type === "toolCall") {
|
|
365
|
-
const previousPartialJson = currentBlock.partialJson;
|
|
366
|
-
currentBlock.partialJson = event.arguments;
|
|
367
|
-
currentBlock.arguments = parseStreamingJson(currentBlock.partialJson);
|
|
368
|
-
if (event.arguments.startsWith(previousPartialJson)) {
|
|
369
|
-
const delta = event.arguments.slice(previousPartialJson.length);
|
|
370
|
-
if (delta.length > 0) {
|
|
371
|
-
stream.push({
|
|
372
|
-
type: "toolcall_delta",
|
|
373
|
-
contentIndex: blockIndex(),
|
|
374
|
-
delta,
|
|
375
|
-
partial: output
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
373
|
} else if (event.type === "response.output_item.done") {
|
|
381
374
|
const item = event.item;
|
|
382
|
-
|
|
375
|
+
const slot = getOrCreateSlot(event.output_index, item);
|
|
376
|
+
if (item.type === "reasoning" && slot?.type === "thinking") {
|
|
383
377
|
const summaryText = item.summary?.map((s) => s.text).join(`
|
|
384
378
|
|
|
385
379
|
`) || "";
|
|
386
380
|
const contentText = item.content?.map((c) => c.text).join(`
|
|
387
381
|
|
|
388
382
|
`) || "";
|
|
389
|
-
|
|
390
|
-
|
|
383
|
+
slot.block.thinking = summaryText || contentText || slot.block.thinking;
|
|
384
|
+
slot.block.thinkingSignature = JSON.stringify(item);
|
|
391
385
|
stream.push({
|
|
392
386
|
type: "thinking_end",
|
|
393
|
-
contentIndex:
|
|
394
|
-
content:
|
|
387
|
+
contentIndex: slot.contentIndex,
|
|
388
|
+
content: slot.block.thinking,
|
|
395
389
|
partial: output
|
|
396
390
|
});
|
|
397
|
-
|
|
398
|
-
} else if (item.type === "message" &&
|
|
399
|
-
|
|
400
|
-
|
|
391
|
+
outputSlots.delete(event.output_index);
|
|
392
|
+
} else if (item.type === "message" && slot?.type === "text") {
|
|
393
|
+
slot.block.text = item.content?.map((c) => c.type === "output_text" ? c.text : c.refusal).join("") || "";
|
|
394
|
+
slot.block.textSignature = encodeTextSignatureV1(item.id, item.phase ?? undefined);
|
|
401
395
|
stream.push({
|
|
402
396
|
type: "text_end",
|
|
403
|
-
contentIndex:
|
|
404
|
-
content:
|
|
397
|
+
contentIndex: slot.contentIndex,
|
|
398
|
+
content: slot.block.text,
|
|
405
399
|
partial: output
|
|
406
400
|
});
|
|
407
|
-
|
|
408
|
-
} else if (item.type === "function_call") {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
toolCall
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
id: `${item.call_id}|${item.id}`,
|
|
419
|
-
name: item.name,
|
|
420
|
-
arguments: args
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
currentBlock = null;
|
|
424
|
-
stream.push({ type: "toolcall_end", contentIndex: blockIndex(), toolCall, partial: output });
|
|
401
|
+
outputSlots.delete(event.output_index);
|
|
402
|
+
} else if (item.type === "function_call" && slot?.type === "toolCall") {
|
|
403
|
+
slot.block.arguments = parseStreamingJson(item.arguments || slot.block.partialJson || "{}");
|
|
404
|
+
delete slot.block.partialJson;
|
|
405
|
+
stream.push({
|
|
406
|
+
type: "toolcall_end",
|
|
407
|
+
contentIndex: slot.contentIndex,
|
|
408
|
+
toolCall: slot.block,
|
|
409
|
+
partial: output
|
|
410
|
+
});
|
|
411
|
+
outputSlots.delete(event.output_index);
|
|
425
412
|
}
|
|
426
413
|
} else if (event.type === "response.completed" || event.type === "response.incomplete") {
|
|
427
414
|
finalizeResponse(event.response);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildModelsDevSeedRows
|
|
3
|
-
} from "./cli-
|
|
3
|
+
} from "./cli-xgssgdqn.js";
|
|
4
4
|
import {
|
|
5
5
|
createLogEntry,
|
|
6
6
|
getActivePricingRow,
|
|
7
7
|
getDb,
|
|
8
8
|
init_db,
|
|
9
9
|
insertPricingRow
|
|
10
|
-
} from "./cli-
|
|
10
|
+
} from "./cli-6xn2xv4r.js";
|
|
11
11
|
import {
|
|
12
12
|
init_secret_scrubber,
|
|
13
13
|
scrubSecrets
|