@kingsoftcloud/agentkit-harness-node 0.0.12 → 0.0.14
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/index.mjs +172 -91
- package/dist/rpc-entry.mjs +174 -93
- package/package.json +3 -2
- package/src/native/activity-status.mjs +32 -1
- package/src/native/children.mjs +18 -7
- package/src/native/conversation-presentation.mjs +31 -0
- package/src/native/local-command-policy-worker.mjs +2 -1
- package/src/native/local-command-tools.mjs +6 -1
- package/src/native/model-anthropic.mjs +6 -1
- package/src/native/model-openai-chat.mjs +17 -2
- package/src/native/model-port.mjs +5 -1
- package/src/native/model-provider-error.mjs +44 -0
- package/src/native/model-responses.mjs +15 -37
- package/src/native/python-grammar.mjs +14 -0
- package/src/native/python-syntax-worker.mjs +4 -3
- package/src/native/run-observation.mjs +2 -2
- package/src/native/sqlite-store.mjs +24 -0
- package/src/native/workspace-instructions.mjs +18 -3
package/dist/rpc-entry.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { realpathSync as realpathSync2 } from "node:fs";
|
|
|
7
7
|
import { resolve as resolvePath } from "node:path";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import * as readline from "node:readline";
|
|
10
|
-
import { NativeKernel, configure, initialSnapshot, canonical as
|
|
10
|
+
import { NativeKernel, configure, initialSnapshot, canonical as canonical8, terminal as terminal3, runKey as runKey2, NativeError, isNativeError } from "@kingsoftcloud/agentkit-harness-core";
|
|
11
11
|
|
|
12
12
|
// packages/agentkit-harness-node/src/native/sqlite-session-inbox.mjs
|
|
13
13
|
import { appendSessionInjection, canonical, invariant, parseNativeJson } from "@kingsoftcloud/agentkit-harness-core";
|
|
@@ -384,6 +384,18 @@ function nativeContextStatus(record, { driving = false } = {}) {
|
|
|
384
384
|
|
|
385
385
|
// packages/agentkit-harness-node/src/native/activity-status.mjs
|
|
386
386
|
import { createHash as createHash2 } from "node:crypto";
|
|
387
|
+
import { canonical as canonical4 } from "@kingsoftcloud/agentkit-harness-core";
|
|
388
|
+
var settledCommandStates = /* @__PURE__ */ new Set(["completed", "failed", "canceled", "timed_out", "output_limit"]);
|
|
389
|
+
function foregroundReceiptState(record, ref, intent) {
|
|
390
|
+
if (ref.sourceRunId !== record.snapshot.runId || intent?.kind !== "tool" || intent.payload.calls?.length !== 1) return null;
|
|
391
|
+
const definition = record.configuration?.tools.find((tool) => tool.name === intent.payload.calls[0].name);
|
|
392
|
+
if (definition?.backgroundCommandPolicy !== "owned-command-launch/v1") return null;
|
|
393
|
+
const receipt = record.receipts?.find((row) => row.operationKey === ref.operationKey);
|
|
394
|
+
const results = receipt?.result?.results;
|
|
395
|
+
const result = results?.length === 1 ? results[0] : null;
|
|
396
|
+
if (receipt?.status !== "committed" || result?.status !== "ok" || result.backgroundCommandFinished !== true || !result.backgroundCommandRef || canonical4(result.backgroundCommandRef) !== canonical4(ref) || result.content?.task_id !== ref.taskId || result.content.evidence_incomplete === true || !settledCommandStates.has(result.content.status)) return null;
|
|
397
|
+
return result.content.status;
|
|
398
|
+
}
|
|
387
399
|
function nativeActivityStatus(record, { driving = false } = {}) {
|
|
388
400
|
if (!record) return null;
|
|
389
401
|
const { snapshot } = record;
|
|
@@ -406,7 +418,7 @@ function nativeActivityStatus(record, { driving = false } = {}) {
|
|
|
406
418
|
id: ref.taskId,
|
|
407
419
|
runId: snapshot.runId,
|
|
408
420
|
title: call?.arguments.command?.slice(0, 512) || ref.taskId,
|
|
409
|
-
state: observed?.status ?? "unknown",
|
|
421
|
+
state: observed?.status ?? foregroundReceiptState(record, ref, intent) ?? "unknown",
|
|
410
422
|
canCancel: false
|
|
411
423
|
};
|
|
412
424
|
});
|
|
@@ -427,14 +439,14 @@ function nativeActivityStatus(record, { driving = false } = {}) {
|
|
|
427
439
|
}
|
|
428
440
|
|
|
429
441
|
// packages/agentkit-harness-node/src/native/a2a-receipt-source.mjs
|
|
430
|
-
import { canonical as
|
|
442
|
+
import { canonical as canonical5 } from "@kingsoftcloud/agentkit-harness-core";
|
|
431
443
|
function nativeA2aReceiptWaitSource(record) {
|
|
432
444
|
const snapshot = record?.snapshot, marker = snapshot?.toolReconciliation;
|
|
433
445
|
if (snapshot?.phase !== "awaiting_reconciliation" || snapshot.pendingIntent !== null || marker?.contract !== "agentkit.tool-receipt-observation/v1") return null;
|
|
434
446
|
const intent = record.intents.find((item) => item.operationKey === marker.operationKey);
|
|
435
447
|
const call = intent?.payload.calls?.[0], definition = record.configuration.tools.find((item) => item.name === call?.name);
|
|
436
448
|
const receipt = record.receipts.find((item) => item.operationKey === marker.operationKey);
|
|
437
|
-
if (call?.name !== "call_a2a_agent" || definition?.recoveryPolicy !== "receipt-observation/v1" || intent.kind !== "tool" || intent.status !== "running" || intent.payload.calls.length !== 1 || !Number.isSafeInteger(intent.claimedFence) || intent.claimedFence <= 0 || call.callId !== marker.callId ||
|
|
449
|
+
if (call?.name !== "call_a2a_agent" || definition?.recoveryPolicy !== "receipt-observation/v1" || intent.kind !== "tool" || intent.status !== "running" || intent.payload.calls.length !== 1 || !Number.isSafeInteger(intent.claimedFence) || intent.claimedFence <= 0 || call.callId !== marker.callId || canonical5(snapshot.pendingTools.slice(0, 1)) !== canonical5([call]) || !receipt || !(receipt.status === "uncertain" || receipt.result.results?.[0]?.status === "uncertain")) return null;
|
|
438
450
|
return { intent, call, definition };
|
|
439
451
|
}
|
|
440
452
|
|
|
@@ -451,7 +463,7 @@ function canCloseNativeReadInterruption(record) {
|
|
|
451
463
|
|
|
452
464
|
// packages/agentkit-harness-node/src/native/run-observation.mjs
|
|
453
465
|
var NATIVE_RUN_OBSERVATION = "agentkit.native-run-observation/v1";
|
|
454
|
-
var NATIVE_COMMIT_PROJECTION = "agentkit.native-commit-projection/
|
|
466
|
+
var NATIVE_COMMIT_PROJECTION = "agentkit.native-commit-projection/v3";
|
|
455
467
|
function contextProjection(previous, record) {
|
|
456
468
|
let lastPlan = previous?.lastPlan ?? null, lastAdmission = previous?.lastAdmission ?? null;
|
|
457
469
|
for (const event of record.events ?? []) if (event.kind === "context.planned") {
|
|
@@ -482,7 +494,8 @@ function observationHeader(s) {
|
|
|
482
494
|
"outcome",
|
|
483
495
|
"reason",
|
|
484
496
|
"pendingIntent",
|
|
485
|
-
"toolReconciliation"
|
|
497
|
+
"toolReconciliation",
|
|
498
|
+
"retryNotBefore"
|
|
486
499
|
].filter((key) => s[key] !== void 0).map((key) => [key, s[key]]));
|
|
487
500
|
header.diagnostics = Object.fromEntries(["providerUsageIncomplete", "descendantUsageIncomplete", "lastModelFailure"].filter((key) => s.diagnostics[key] !== void 0).map((key) => [key, s.diagnostics[key]]));
|
|
488
501
|
return header;
|
|
@@ -606,7 +619,7 @@ function advanceNativeRunCommitObservation(previous, state, changes) {
|
|
|
606
619
|
// packages/agentkit-harness-node/src/native/sqlite-store.mjs
|
|
607
620
|
import {
|
|
608
621
|
TransactionalRunStore,
|
|
609
|
-
canonical as
|
|
622
|
+
canonical as canonical6,
|
|
610
623
|
invariant as invariant3,
|
|
611
624
|
scopeKey,
|
|
612
625
|
runKey,
|
|
@@ -679,7 +692,7 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
679
692
|
for (const row of legacy) {
|
|
680
693
|
const item = parseNativeJson2(row.data);
|
|
681
694
|
invariant3(typeof item.fingerprint === "string", "invalid_commit_fingerprint");
|
|
682
|
-
compact.run(
|
|
695
|
+
compact.run(canonical6({ ...item, fingerprint: commitFingerprint(item.fingerprint) }), row.rowid);
|
|
683
696
|
}
|
|
684
697
|
if (versions.length && versions[0].version === 1) db.prepare("UPDATE native_schema SET version=2").run();
|
|
685
698
|
db.exec("COMMIT");
|
|
@@ -705,7 +718,7 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
705
718
|
scopeKey(scope);
|
|
706
719
|
const row = db.prepare(`SELECT data FROM native_runs
|
|
707
720
|
WHERE json_extract(data,'$.snapshot.scope')=? AND json_extract(data,'$.snapshot.sessionId')=?
|
|
708
|
-
ORDER BY rowid DESC LIMIT 1`).get(
|
|
721
|
+
ORDER BY rowid DESC LIMIT 1`).get(canonical6(scope), sessionId);
|
|
709
722
|
return row ? parseNativeJson2(row.data).snapshot : null;
|
|
710
723
|
};
|
|
711
724
|
const read = (key) => {
|
|
@@ -774,14 +787,14 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
774
787
|
return row ? parseNativeJson2(row.data) : null;
|
|
775
788
|
};
|
|
776
789
|
const writeDeliveryHead = (key, snapshot) => db.prepare(`INSERT INTO native_delivery_heads VALUES (?,?)
|
|
777
|
-
ON CONFLICT(run_key) DO UPDATE SET data=excluded.data`).run(key,
|
|
790
|
+
ON CONFLICT(run_key) DO UPDATE SET data=excluded.data`).run(key, canonical6(deliveryJournalHead(snapshot)));
|
|
778
791
|
const appendDelivery = (key, evidence, snapshot) => {
|
|
779
792
|
const insert = db.prepare(`INSERT INTO native_delivery_items VALUES (?,?,?,?)
|
|
780
793
|
ON CONFLICT(run_key,collection,item_key) DO UPDATE SET data=CASE
|
|
781
794
|
WHEN native_delivery_items.collection='tools'
|
|
782
795
|
OR native_delivery_items.collection='outcomes' AND native_delivery_items.data='"not_dispatched"'
|
|
783
796
|
THEN native_delivery_items.data ELSE excluded.data END`);
|
|
784
|
-
for (const row of sessionDeliveryEntries(evidence)) insert.run(key, row.collection, row.key,
|
|
797
|
+
for (const row of sessionDeliveryEntries(evidence)) insert.run(key, row.collection, row.key, canonical6(row.data));
|
|
785
798
|
writeDeliveryHead(key, snapshot);
|
|
786
799
|
};
|
|
787
800
|
const rebuildDelivery = (key, record) => {
|
|
@@ -790,21 +803,21 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
790
803
|
};
|
|
791
804
|
const persist = (key, previous, record) => {
|
|
792
805
|
const { events, intents, receipts, commands, commits, ...metadata } = record;
|
|
793
|
-
db.prepare("INSERT INTO native_runs(key,data) VALUES (?,?) ON CONFLICT(key) DO UPDATE SET data=excluded.data").run(key,
|
|
806
|
+
db.prepare("INSERT INTO native_runs(key,data) VALUES (?,?) ON CONFLICT(key) DO UPDATE SET data=excluded.data").run(key, canonical6(metadata));
|
|
794
807
|
invariant3(events.length >= (previous?.events.length ?? 0), "events_immutable");
|
|
795
808
|
for (const event of events.slice(previous?.events.length ?? 0))
|
|
796
|
-
db.prepare("INSERT INTO native_events VALUES (?,?,?,?)").run(key, event.seq, event.eventId,
|
|
809
|
+
db.prepare("INSERT INTO native_events VALUES (?,?,?,?)").run(key, event.seq, event.eventId, canonical6(event));
|
|
797
810
|
for (const [collection, identify] of Object.entries(collections)) {
|
|
798
|
-
const old = new Map((previous?.[collection] ?? []).map((item) => [identify(item),
|
|
811
|
+
const old = new Map((previous?.[collection] ?? []).map((item) => [identify(item), canonical6(item)]));
|
|
799
812
|
invariant3(record[collection].length >= old.size, "ledger_items_immutable");
|
|
800
813
|
for (const item of record[collection]) {
|
|
801
|
-
const id = identify(item), data =
|
|
814
|
+
const id = identify(item), data = canonical6(item);
|
|
802
815
|
if (old.get(id) !== data) db.prepare("INSERT INTO native_items VALUES (?,?,?,?) ON CONFLICT(run_key,collection,item_key) DO UPDATE SET data=excluded.data").run(key, collection, id, data);
|
|
803
816
|
}
|
|
804
817
|
}
|
|
805
818
|
if (!previous) inbox.consume(record.snapshot);
|
|
806
819
|
db.prepare(`INSERT INTO native_run_observations VALUES (?,?)
|
|
807
|
-
ON CONFLICT(run_key) DO UPDATE SET data=excluded.data`).run(key,
|
|
820
|
+
ON CONFLICT(run_key) DO UPDATE SET data=excluded.data`).run(key, canonical6(projectNativeRunObservation(record)));
|
|
808
821
|
rebuildDelivery(key, record);
|
|
809
822
|
beforeCommit?.({ key, record });
|
|
810
823
|
};
|
|
@@ -861,7 +874,7 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
861
874
|
const row = db.prepare("SELECT data FROM native_run_observations WHERE run_key=?").get(key);
|
|
862
875
|
const observation = row ? parseNativeJson2(row.data) : null;
|
|
863
876
|
const exceptional = !current || ["interrupted", "awaiting_reconciliation", "reconciling_tool"].some((phase) => current.snapshot.phase === phase || batch.snapshot.phase === phase);
|
|
864
|
-
const compatible = observation?.contract === NATIVE_RUN_OBSERVATION && observation.commitProjection?.contract === NATIVE_COMMIT_PROJECTION && Array.isArray(observation.commitProjection?.tools?.calls) && Array.isArray(observation.facts?.toolOutcomes) && observation.snapshot.revision === current?.snapshot.revision && observation.snapshot.eventSeq === current?.snapshot.eventSeq && observation.snapshot.configDigest === current?.snapshot.configDigest && observation.snapshot.runId === current?.snapshot.runId && observation.snapshot.sessionId === current?.snapshot.sessionId &&
|
|
877
|
+
const compatible = observation?.contract === NATIVE_RUN_OBSERVATION && observation.commitProjection?.contract === NATIVE_COMMIT_PROJECTION && Array.isArray(observation.commitProjection?.tools?.calls) && Array.isArray(observation.facts?.toolOutcomes) && observation.snapshot.revision === current?.snapshot.revision && observation.snapshot.eventSeq === current?.snapshot.eventSeq && observation.snapshot.configDigest === current?.snapshot.configDigest && observation.snapshot.runId === current?.snapshot.runId && observation.snapshot.sessionId === current?.snapshot.sessionId && canonical6(observation.snapshot.scope) === canonical6(current?.snapshot.scope);
|
|
865
878
|
if (exceptional || !compatible || !matchesDeliveryJournal(deliveryHead(key), current.snapshot)) {
|
|
866
879
|
const previous = read(key), result = change(previous ? projectLedgerCommitState(previous, batch) : null);
|
|
867
880
|
if (result.changes) persist(key, previous, applyLedgerCommitChanges(previous, result.changes));
|
|
@@ -871,16 +884,16 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
871
884
|
const { changes, value } = change(current);
|
|
872
885
|
if (changes) {
|
|
873
886
|
const { commands, intents, existingReceiptKeys, existingEventIds, duplicateCommit, ...metadata } = current;
|
|
874
|
-
db.prepare("UPDATE native_runs SET data=? WHERE key=?").run(
|
|
887
|
+
db.prepare("UPDATE native_runs SET data=? WHERE key=?").run(canonical6({ ...metadata, snapshot: changes.snapshot }), key);
|
|
875
888
|
const eventInsert = db.prepare("INSERT INTO native_events VALUES (?,?,?,?)");
|
|
876
|
-
for (const event of changes.events) eventInsert.run(key, event.seq, event.eventId,
|
|
889
|
+
for (const event of changes.events) eventInsert.run(key, event.seq, event.eventId, canonical6(event));
|
|
877
890
|
const itemInsert = db.prepare("INSERT INTO native_items VALUES (?,?,?,?)");
|
|
878
891
|
for (const [collection, items] of [["intents", changes.intents], ["receipts", changes.receipts], ["commits", [changes.commit]]])
|
|
879
|
-
for (const item of items) itemInsert.run(key, collection, collections[collection](item),
|
|
892
|
+
for (const item of items) itemInsert.run(key, collection, collections[collection](item), canonical6(item));
|
|
880
893
|
const commandUpdate = db.prepare("UPDATE native_items SET data=? WHERE run_key=? AND collection='commands' AND item_key=?");
|
|
881
|
-
for (const row2 of changes.commands) commandUpdate.run(
|
|
894
|
+
for (const row2 of changes.commands) commandUpdate.run(canonical6(row2), key, row2.command.commandId);
|
|
882
895
|
const advanced = advanceNativeRunCommitObservation(observation, current, changes);
|
|
883
|
-
db.prepare("UPDATE native_run_observations SET data=? WHERE run_key=?").run(
|
|
896
|
+
db.prepare("UPDATE native_run_observations SET data=? WHERE run_key=?").run(canonical6(advanced), key);
|
|
884
897
|
appendDelivery(key, {
|
|
885
898
|
events: changes.events,
|
|
886
899
|
receipts: changes.receipts,
|
|
@@ -919,27 +932,27 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
919
932
|
const presentationCurrent = matchesDeliveryJournal(deliveryHead(key), current.snapshot);
|
|
920
933
|
const cached = db.prepare("SELECT data FROM native_run_observations WHERE run_key=?").get(key);
|
|
921
934
|
let observation = cached ? parseNativeJson2(cached.data) : null;
|
|
922
|
-
if (!observation || observation.contract !== NATIVE_RUN_OBSERVATION || observation.commitProjection?.contract !== NATIVE_COMMIT_PROJECTION || !Array.isArray(observation.commitProjection?.tools?.calls) || !Array.isArray(observation.facts?.toolOutcomes) || observation.snapshot.revision !== current.snapshot.revision || observation.snapshot.eventSeq !== current.snapshot.eventSeq || observation.snapshot.configDigest !== current.snapshot.configDigest || observation.snapshot.runId !== current.snapshot.runId || observation.snapshot.sessionId !== current.snapshot.sessionId ||
|
|
935
|
+
if (!observation || observation.contract !== NATIVE_RUN_OBSERVATION || observation.commitProjection?.contract !== NATIVE_COMMIT_PROJECTION || !Array.isArray(observation.commitProjection?.tools?.calls) || !Array.isArray(observation.facts?.toolOutcomes) || observation.snapshot.revision !== current.snapshot.revision || observation.snapshot.eventSeq !== current.snapshot.eventSeq || observation.snapshot.configDigest !== current.snapshot.configDigest || observation.snapshot.runId !== current.snapshot.runId || observation.snapshot.sessionId !== current.snapshot.sessionId || canonical6(observation.snapshot.scope) !== canonical6(current.snapshot.scope))
|
|
923
936
|
observation = projectNativeRunObservation(read(key));
|
|
924
937
|
if (changes.claim) {
|
|
925
938
|
const { snapshot, intent } = changes.claim;
|
|
926
|
-
db.prepare("UPDATE native_runs SET data=json_set(data,'$.snapshot',json(?)) WHERE key=?").run(
|
|
939
|
+
db.prepare("UPDATE native_runs SET data=json_set(data,'$.snapshot',json(?)) WHERE key=?").run(canonical6(snapshot), key);
|
|
927
940
|
const result = db.prepare(`UPDATE native_items SET data=?
|
|
928
|
-
WHERE run_key=? AND collection='intents' AND item_key=?`).run(
|
|
941
|
+
WHERE run_key=? AND collection='intents' AND item_key=?`).run(canonical6(intent), key, intent.operationKey);
|
|
929
942
|
invariant3(result.changes === 1, "pending_intent_missing");
|
|
930
943
|
}
|
|
931
944
|
if (changes.commands) {
|
|
932
|
-
const previous = new Map(current.commands.map((row) => [row.command.commandId,
|
|
945
|
+
const previous = new Map(current.commands.map((row) => [row.command.commandId, canonical6(row)]));
|
|
933
946
|
for (const row of changes.commands) {
|
|
934
|
-
const data =
|
|
947
|
+
const data = canonical6(row), id = row.command.commandId;
|
|
935
948
|
if (previous.get(id) !== data) db.prepare(`INSERT INTO native_items VALUES (?,?,?,?)
|
|
936
949
|
ON CONFLICT(run_key,collection,item_key) DO UPDATE SET data=excluded.data`).run(key, "commands", id, data);
|
|
937
950
|
}
|
|
938
951
|
}
|
|
939
|
-
if (changes.projections) db.prepare("UPDATE native_runs SET data=json_set(data,'$.projections',json(?)) WHERE key=?").run(
|
|
952
|
+
if (changes.projections) db.prepare("UPDATE native_runs SET data=json_set(data,'$.projections',json(?)) WHERE key=?").run(canonical6(changes.projections), key);
|
|
940
953
|
const updated = advanceNativeRunControlObservation(observation, current, changes);
|
|
941
954
|
db.prepare(`INSERT INTO native_run_observations VALUES (?,?)
|
|
942
|
-
ON CONFLICT(run_key) DO UPDATE SET data=excluded.data`).run(key,
|
|
955
|
+
ON CONFLICT(run_key) DO UPDATE SET data=excluded.data`).run(key, canonical6(updated));
|
|
943
956
|
if (presentationCurrent) writeDeliveryHead(key, changes.claim?.snapshot ?? current.snapshot);
|
|
944
957
|
}
|
|
945
958
|
db.exec("COMMIT");
|
|
@@ -957,7 +970,7 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
957
970
|
'revision',json_extract(data,'$.snapshot.revision'), 'eventSeq',json_extract(data,'$.snapshot.eventSeq'),
|
|
958
971
|
'backgroundCommands',json_extract(data,'$.snapshot.backgroundCommands'), 'lease',json_extract(data,'$.lease')) AS head
|
|
959
972
|
FROM native_runs WHERE json_extract(data,'$.snapshot.scope')=? AND json_extract(data,'$.snapshot.sessionId')=?
|
|
960
|
-
ORDER BY rowid DESC LIMIT 1`).get(
|
|
973
|
+
ORDER BY rowid DESC LIMIT 1`).get(canonical6(scope), sessionId);
|
|
961
974
|
return row ? parseNativeJson2(row.head) : null;
|
|
962
975
|
},
|
|
963
976
|
projectionCursors: (key) => {
|
|
@@ -1033,7 +1046,7 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
1033
1046
|
...row.retirement === null ? {} : { resourceRetirementReview: parseNativeJson2(row.retirement) }
|
|
1034
1047
|
} : null);
|
|
1035
1048
|
invariant3(row, "run_not_found");
|
|
1036
|
-
db.prepare(`UPDATE native_runs SET data=json_set(data,'$.lease',json(?),'$.fence',?) WHERE key=?`).run(
|
|
1049
|
+
db.prepare(`UPDATE native_runs SET data=json_set(data,'$.lease',json(?),'$.fence',?) WHERE key=?`).run(canonical6(record.lease), record.fence, key);
|
|
1037
1050
|
db.exec("COMMIT");
|
|
1038
1051
|
return value;
|
|
1039
1052
|
} catch (error) {
|
|
@@ -1084,7 +1097,7 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
1084
1097
|
open2();
|
|
1085
1098
|
return db.prepare(`SELECT json_extract(data,'$.snapshot') AS snapshot FROM native_runs
|
|
1086
1099
|
WHERE json_extract(data,'$.snapshot.scope')=?
|
|
1087
|
-
${sessionId === void 0 ? "" : "AND json_extract(data,'$.snapshot.sessionId')=?"} ORDER BY rowid`).all(
|
|
1100
|
+
${sessionId === void 0 ? "" : "AND json_extract(data,'$.snapshot.sessionId')=?"} ORDER BY rowid`).all(canonical6(scope), ...sessionId === void 0 ? [] : [sessionId]).map((row) => parseNativeJson2(row.snapshot));
|
|
1088
1101
|
},
|
|
1089
1102
|
heads: (scope, sessionId) => {
|
|
1090
1103
|
open2();
|
|
@@ -1094,7 +1107,7 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
1094
1107
|
'revision',json_extract(data,'$.snapshot.revision'), 'eventSeq',json_extract(data,'$.snapshot.eventSeq'),
|
|
1095
1108
|
'backgroundCommands',json_extract(data,'$.snapshot.backgroundCommands'), 'lease',json_extract(data,'$.lease')) AS head
|
|
1096
1109
|
FROM native_runs WHERE json_extract(data,'$.snapshot.scope')=?
|
|
1097
|
-
${sessionId === void 0 ? "" : "AND json_extract(data,'$.snapshot.sessionId')=?"} ORDER BY rowid`).all(
|
|
1110
|
+
${sessionId === void 0 ? "" : "AND json_extract(data,'$.snapshot.sessionId')=?"} ORDER BY rowid`).all(canonical6(scope), ...sessionId === void 0 ? [] : [sessionId]).map((row) => parseNativeJson2(row.head));
|
|
1098
1111
|
},
|
|
1099
1112
|
values: () => {
|
|
1100
1113
|
open2();
|
|
@@ -1136,6 +1149,29 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
1136
1149
|
}
|
|
1137
1150
|
}
|
|
1138
1151
|
});
|
|
1152
|
+
this.traceView = (scope, runId, after = 0) => {
|
|
1153
|
+
open2();
|
|
1154
|
+
invariant3(Number.isSafeInteger(after) && after >= 0, "invalid_trace_cursor");
|
|
1155
|
+
const key = runKey(scope, runId);
|
|
1156
|
+
db.exec("BEGIN");
|
|
1157
|
+
try {
|
|
1158
|
+
const row = db.prepare(`SELECT json_object(
|
|
1159
|
+
'scope',json_extract(data,'$.snapshot.scope'), 'runId',json_extract(data,'$.snapshot.runId'),
|
|
1160
|
+
'sessionId',json_extract(data,'$.snapshot.sessionId'), 'phase',json_extract(data,'$.snapshot.phase'),
|
|
1161
|
+
'revision',json_extract(data,'$.snapshot.revision'), 'eventSeq',json_extract(data,'$.snapshot.eventSeq'),
|
|
1162
|
+
'usage',json_extract(data,'$.snapshot.usage'), 'outcome',json_extract(data,'$.snapshot.outcome')) AS snapshot
|
|
1163
|
+
FROM native_runs WHERE key=?`).get(key);
|
|
1164
|
+
invariant3(row, "run_not_found");
|
|
1165
|
+
const snapshot = parseNativeJson2(row.snapshot);
|
|
1166
|
+
invariant3(snapshot.runId === runId && canonical6(snapshot.scope) === canonical6(scope), "native_trace_identity_mismatch");
|
|
1167
|
+
const events = db.prepare("SELECT data FROM native_events WHERE run_key=? AND seq>? AND seq<=? ORDER BY seq").all(key, after, snapshot.eventSeq).map((row2) => parseNativeJson2(row2.data));
|
|
1168
|
+
db.exec("COMMIT");
|
|
1169
|
+
return { contract: "agentkit.native-trace-view/v1", snapshot, events };
|
|
1170
|
+
} catch (error) {
|
|
1171
|
+
db.exec("ROLLBACK");
|
|
1172
|
+
throw error;
|
|
1173
|
+
}
|
|
1174
|
+
};
|
|
1139
1175
|
this.sessionDeliveryState = (scope, runId) => {
|
|
1140
1176
|
open2();
|
|
1141
1177
|
const key = runKey(scope, runId);
|
|
@@ -1147,7 +1183,7 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
1147
1183
|
invariant3(row, "run_not_found");
|
|
1148
1184
|
const snapshot = parseNativeJson2(row.snapshot), presence = parseNativeJson2(row.presence);
|
|
1149
1185
|
for (const [name, type] of Object.entries(presence)) if (type === null) delete snapshot[name];
|
|
1150
|
-
invariant3(snapshot.runId === runId &&
|
|
1186
|
+
invariant3(snapshot.runId === runId && canonical6(snapshot.scope) === canonical6(scope), "delivery_identity_mismatch");
|
|
1151
1187
|
return { snapshot, configuration: parseNativeJson2(row.configuration), projections: parseNativeJson2(row.projections) };
|
|
1152
1188
|
};
|
|
1153
1189
|
db.exec("BEGIN");
|
|
@@ -1171,11 +1207,11 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
1171
1207
|
WHERE run_key=? AND collection='receipts' AND item_key=?`).get(path, path + ".status", path + ".context", path + ".content", key, reference.operationKey);
|
|
1172
1208
|
}
|
|
1173
1209
|
if (receipt?.status === "committed" && receipt.observed === "object") return {
|
|
1174
|
-
context: receipt.context === null ? { content:
|
|
1210
|
+
context: receipt.context === null ? { content: canonical6(parseNativeJson2(receipt.content)) } : toolContext2(parseNativeJson2(receipt.context)),
|
|
1175
1211
|
isError: receipt.resultStatus !== "ok"
|
|
1176
1212
|
};
|
|
1177
1213
|
const unknown = intent?.status === "running" && (!receipt || receipt.status === "uncertain");
|
|
1178
|
-
return { context: { content:
|
|
1214
|
+
return { context: { content: canonical6({
|
|
1179
1215
|
status: unknown ? "uncertain" : "not_dispatched",
|
|
1180
1216
|
reason: unknown ? "effect_outcome_unknown" : current.snapshot.reason ?? "run_ended"
|
|
1181
1217
|
}) }, isError: true };
|
|
@@ -1209,9 +1245,9 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
1209
1245
|
invariant3(head, "run_not_found");
|
|
1210
1246
|
view = projectNativeRunObservation(read(key));
|
|
1211
1247
|
db.prepare(`INSERT INTO native_run_observations VALUES (?,?)
|
|
1212
|
-
ON CONFLICT(run_key) DO UPDATE SET data=excluded.data`).run(key,
|
|
1248
|
+
ON CONFLICT(run_key) DO UPDATE SET data=excluded.data`).run(key, canonical6(view));
|
|
1213
1249
|
}
|
|
1214
|
-
invariant3(
|
|
1250
|
+
invariant3(canonical6(view.snapshot.scope) === canonical6(scope) && view.snapshot.runId === runId && view.snapshot.sessionId === head.sessionId, "observation_identity_mismatch");
|
|
1215
1251
|
view.lease = head.lease === null ? null : parseNativeJson2(head.lease);
|
|
1216
1252
|
view.fence = head.fence;
|
|
1217
1253
|
view.projections = parseNativeJson2(head.projections);
|
|
@@ -1238,7 +1274,7 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
1238
1274
|
OR json_extract(v.data,'$.snapshot.configDigest')<>json_extract(r.data,'$.snapshot.configDigest')
|
|
1239
1275
|
OR json_extract(v.data,'$.snapshot.scope')<>json_extract(r.data,'$.snapshot.scope')
|
|
1240
1276
|
OR json_extract(v.data,'$.snapshot.sessionId')<>json_extract(r.data,'$.snapshot.sessionId')
|
|
1241
|
-
OR json_extract(v.data,'$.snapshot.runId')<>json_extract(r.data,'$.snapshot.runId'))`).all(
|
|
1277
|
+
OR json_extract(v.data,'$.snapshot.runId')<>json_extract(r.data,'$.snapshot.runId'))`).all(canonical6(scope), sessionId, NATIVE_RUN_OBSERVATION, NATIVE_COMMIT_PROJECTION);
|
|
1242
1278
|
for (const { runId } of missing) this.observation(scope, runId);
|
|
1243
1279
|
return db.prepare(`SELECT json_extract(v.data,'$.snapshot.runId') AS runId,
|
|
1244
1280
|
json_extract(v.data,'$.snapshot.turnId') AS turnId, json_extract(c.value,'$.callId') AS callId,
|
|
@@ -1250,7 +1286,7 @@ var SqliteRunStore = class extends TransactionalRunStore {
|
|
|
1250
1286
|
AND json_extract(v.data,'$.snapshot.sessionId')=json_extract(r.data,'$.snapshot.sessionId')
|
|
1251
1287
|
AND json_extract(v.data,'$.snapshot.runId')=json_extract(r.data,'$.snapshot.runId')
|
|
1252
1288
|
AND json_extract(c.value,'$.status') IN ('uncertain','not_dispatched')
|
|
1253
|
-
ORDER BY r.rowid,callId`).all(
|
|
1289
|
+
ORDER BY r.rowid,callId`).all(canonical6(scope), sessionId).map((row) => ({ ...row }));
|
|
1254
1290
|
};
|
|
1255
1291
|
this.uncertainToolCalls = (scope, sessionId) => this.sessionToolOutcomes(scope, sessionId).filter((row) => row.status === "uncertain").map(({ status, ...row }) => row);
|
|
1256
1292
|
this.listScopes = (principal) => {
|
|
@@ -1613,7 +1649,7 @@ async function* readModelSse(body, { maxBytes = 8 * 1024 * 1024, idleTimeoutMs,
|
|
|
1613
1649
|
|
|
1614
1650
|
// packages/agentkit-harness-node/src/native/model-replay.mjs
|
|
1615
1651
|
import { createHash as createHash4 } from "node:crypto";
|
|
1616
|
-
import { canonical as
|
|
1652
|
+
import { canonical as canonical7, modelWireToolCall } from "@kingsoftcloud/agentkit-harness-core";
|
|
1617
1653
|
var SEALED_KINDS = /* @__PURE__ */ new Set(["tool_calls", "final_candidate", "output_limit"]);
|
|
1618
1654
|
function profileFingerprint(profile) {
|
|
1619
1655
|
return `${String(profile?.profileId ?? "")}\0${String(profile?.profileVersion ?? "")}\0${String(profile?.compatibilityDigest ?? "")}`;
|
|
@@ -1671,7 +1707,7 @@ function anthropicReplayContent(message, profile) {
|
|
|
1671
1707
|
if (!validateReplayPairing(blocks, message)) return null;
|
|
1672
1708
|
const view = message.providerReplayProjection;
|
|
1673
1709
|
if (view) {
|
|
1674
|
-
const contentDigest = createHash4("sha256").update(
|
|
1710
|
+
const contentDigest = createHash4("sha256").update(canonical7(replay.anthropicContent)).digest("hex");
|
|
1675
1711
|
if (profile.providerReplayProjectionPolicy !== "anthropic-client-compaction/v1" || view.version !== "anthropic-client-compaction/v1" || view.profileDigest !== profile.compatibilityDigest || view.originalContentDigest !== contentDigest || !/^[0-9a-f]{64}$/.test(view.prefixDigest))
|
|
1676
1712
|
throw new ProtocolError("anthropic_replay_projection_mismatch");
|
|
1677
1713
|
blocks = blocks.filter((block) => !["thinking", "redacted_thinking"].includes(block?.type));
|
|
@@ -2122,6 +2158,61 @@ function explicitLiteralTypes(schema) {
|
|
|
2122
2158
|
return result;
|
|
2123
2159
|
}
|
|
2124
2160
|
|
|
2161
|
+
// packages/agentkit-harness-node/src/native/model-provider-error.mjs
|
|
2162
|
+
var RETRYABLE_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
2163
|
+
"rate_limit_error",
|
|
2164
|
+
"rate_limit_exceeded",
|
|
2165
|
+
"overloaded_error",
|
|
2166
|
+
"server_error",
|
|
2167
|
+
"api_error",
|
|
2168
|
+
"service_unavailable_error",
|
|
2169
|
+
"server_is_overloaded",
|
|
2170
|
+
"timeout_error",
|
|
2171
|
+
"MODEL_PROVIDER_RATE_LIMIT",
|
|
2172
|
+
"MODEL_PROVIDER_UNAVAILABLE"
|
|
2173
|
+
]);
|
|
2174
|
+
var TERMINAL_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
2175
|
+
"invalid_request_error",
|
|
2176
|
+
"invalid_api_key",
|
|
2177
|
+
"authentication_error",
|
|
2178
|
+
"permission_error",
|
|
2179
|
+
"not_found_error",
|
|
2180
|
+
"request_too_large",
|
|
2181
|
+
"billing_error",
|
|
2182
|
+
"insufficient_quota",
|
|
2183
|
+
"MODEL_PROVIDER_AUTHENTICATION",
|
|
2184
|
+
"MODEL_PROVIDER_PERMISSION",
|
|
2185
|
+
"MODEL_PROVIDER_INVALID_REQUEST",
|
|
2186
|
+
"MODEL_PROVIDER_NOT_FOUND",
|
|
2187
|
+
"MODEL_PROVIDER_QUOTA_EXHAUSTED"
|
|
2188
|
+
]);
|
|
2189
|
+
function classifyOpenAIProviderError(error) {
|
|
2190
|
+
const invalid = { kind: "provider_terminal_error", failureKind: "invalid_response" };
|
|
2191
|
+
if (!error || typeof error !== "object" || Array.isArray(error)) return invalid;
|
|
2192
|
+
if (error.type != null && typeof error.type !== "string") return invalid;
|
|
2193
|
+
const status = typeof error.code === "number" ? error.code : null;
|
|
2194
|
+
if (status != null && (!Number.isInteger(status) || status < 400 || status > 599)) return invalid;
|
|
2195
|
+
const codes = [status == null ? error.code : null, error.type].filter((value) => value != null);
|
|
2196
|
+
if (codes.some((value) => typeof value !== "string")) return invalid;
|
|
2197
|
+
if (codes.some((value) => TERMINAL_ERROR_CODES.has(value))) {
|
|
2198
|
+
return { kind: "provider_terminal_error", failureKind: "client_error" };
|
|
2199
|
+
}
|
|
2200
|
+
if (status != null) {
|
|
2201
|
+
if (status === 408) return { kind: "provider_retryable_error", failureKind: "request_timeout" };
|
|
2202
|
+
if (status === 429) return { kind: "provider_retryable_error", failureKind: "rate_limit" };
|
|
2203
|
+
return {
|
|
2204
|
+
kind: status >= 500 ? "provider_retryable_error" : "provider_terminal_error",
|
|
2205
|
+
failureKind: status >= 500 ? "server_error" : "client_error"
|
|
2206
|
+
};
|
|
2207
|
+
}
|
|
2208
|
+
const code = codes.find((value) => RETRYABLE_ERROR_CODES.has(value));
|
|
2209
|
+
if (code) return {
|
|
2210
|
+
kind: "provider_retryable_error",
|
|
2211
|
+
failureKind: ["rate_limit_error", "rate_limit_exceeded", "MODEL_PROVIDER_RATE_LIMIT"].includes(code) ? "rate_limit" : code === "timeout_error" ? "request_timeout" : "server_error"
|
|
2212
|
+
};
|
|
2213
|
+
return invalid;
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2125
2216
|
// packages/agentkit-harness-node/src/native/model-chat-usage.mjs
|
|
2126
2217
|
var CUMULATIVE_CHAT_USAGE = "cumulative-snapshots/v1";
|
|
2127
2218
|
var fields = ["inputTokens", "outputTokens", "cachedInputTokens", "reasoningTokens"];
|
|
@@ -2313,7 +2404,14 @@ function parseOpenAIBuffered(bodyText, request, { captureReplay = false, binding
|
|
|
2313
2404
|
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
2314
2405
|
throw new ProtocolError("invalid response envelope", "envelope_invalid");
|
|
2315
2406
|
}
|
|
2316
|
-
if ("error" in payload)
|
|
2407
|
+
if ("error" in payload) {
|
|
2408
|
+
if (payload.choices != null && (!Array.isArray(payload.choices) || payload.choices.length)) {
|
|
2409
|
+
throw new ProtocolError("conflicting error envelope", "envelope_invalid");
|
|
2410
|
+
}
|
|
2411
|
+
throw Object.assign(new ProtocolError("provider rejected generation", "provider_error"), {
|
|
2412
|
+
streamError: classifyOpenAIProviderError(payload.error)
|
|
2413
|
+
});
|
|
2414
|
+
}
|
|
2317
2415
|
const choices = payload.choices;
|
|
2318
2416
|
if (!Array.isArray(choices) || choices.length > 1) {
|
|
2319
2417
|
throw new ProtocolError("expected one completion choice", "choice_invalid");
|
|
@@ -2489,7 +2587,14 @@ function createOpenAIStreamTurn(profile, binding) {
|
|
|
2489
2587
|
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
2490
2588
|
throw new ProtocolError("invalid stream envelope", "envelope_invalid");
|
|
2491
2589
|
}
|
|
2492
|
-
if ("error" in payload)
|
|
2590
|
+
if ("error" in payload) {
|
|
2591
|
+
if (payload.choices != null && (!Array.isArray(payload.choices) || payload.choices.length)) {
|
|
2592
|
+
throw new ProtocolError("conflicting error envelope", "envelope_invalid");
|
|
2593
|
+
}
|
|
2594
|
+
throw Object.assign(new ProtocolError("provider rejected generation", "provider_error"), {
|
|
2595
|
+
streamError: classifyOpenAIProviderError(payload.error)
|
|
2596
|
+
});
|
|
2597
|
+
}
|
|
2493
2598
|
if (payload.id != null) {
|
|
2494
2599
|
if (typeof payload.id !== "string" || !payload.id) throw new ProtocolError("invalid completion ID", "identity_conflict");
|
|
2495
2600
|
if (this.completionId != null && payload.id !== this.completionId) {
|
|
@@ -2944,7 +3049,7 @@ function projectAnthropicMessages(request, maxInlineImageBytes) {
|
|
|
2944
3049
|
if (profile.providerReplayProjectionPolicy === "anthropic-client-compaction/v1") {
|
|
2945
3050
|
const originals = message.providerReplay.anthropicContent.filter((block) => block?.type === "tool_use");
|
|
2946
3051
|
for (const [index, block] of originals.entries()) wireIds.set(message.toolCalls[index].callId, block.id);
|
|
2947
|
-
const inverse = new Map([...wireIds].map(([
|
|
3052
|
+
const inverse = new Map([...wireIds].map(([canonical9, original]) => [canonical9, original]));
|
|
2948
3053
|
blocks = replayContent.map((block) => block?.type === "tool_use" ? { ...block, id: inverse.get(block.id) ?? block.id } : block);
|
|
2949
3054
|
} else blocks = replayContent;
|
|
2950
3055
|
} else {
|
|
@@ -3005,8 +3110,13 @@ function parseAnthropicBuffered(bodyText, request, { captureReplay = false, onTh
|
|
|
3005
3110
|
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
3006
3111
|
throw new ProtocolError("invalid response envelope", "envelope_invalid");
|
|
3007
3112
|
}
|
|
3113
|
+
if ("error" in payload) {
|
|
3114
|
+
if (payload.type !== "error") throw new ProtocolError("conflicting error envelope", "envelope_invalid");
|
|
3115
|
+
throw Object.assign(new ProtocolError("provider rejected generation", "provider_error"), {
|
|
3116
|
+
streamError: classifyAnthropicStreamError(payload.error)
|
|
3117
|
+
});
|
|
3118
|
+
}
|
|
3008
3119
|
if ("type" in payload && payload.type !== "message") throw new ProtocolError("invalid response envelope", "envelope_invalid");
|
|
3009
|
-
if ("error" in payload) throw new ProtocolError("invalid response envelope", "envelope_invalid");
|
|
3010
3120
|
if (typeof payload.stop_sequence !== "undefined" && payload.stop_sequence !== null && typeof payload.stop_sequence !== "string") {
|
|
3011
3121
|
throw new ProtocolError("invalid stop_sequence");
|
|
3012
3122
|
}
|
|
@@ -3500,33 +3610,6 @@ var HOSTED_ITEM_TYPES = /* @__PURE__ */ new Set([
|
|
|
3500
3610
|
"mcp_call",
|
|
3501
3611
|
"local_shell_call"
|
|
3502
3612
|
]);
|
|
3503
|
-
var RETRYABLE_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
3504
|
-
"rate_limit_error",
|
|
3505
|
-
"rate_limit_exceeded",
|
|
3506
|
-
"overloaded_error",
|
|
3507
|
-
"server_error",
|
|
3508
|
-
"api_error",
|
|
3509
|
-
"service_unavailable_error",
|
|
3510
|
-
"server_is_overloaded",
|
|
3511
|
-
"timeout_error",
|
|
3512
|
-
"MODEL_PROVIDER_RATE_LIMIT",
|
|
3513
|
-
"MODEL_PROVIDER_UNAVAILABLE"
|
|
3514
|
-
]);
|
|
3515
|
-
var TERMINAL_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
3516
|
-
"invalid_request_error",
|
|
3517
|
-
"invalid_api_key",
|
|
3518
|
-
"authentication_error",
|
|
3519
|
-
"permission_error",
|
|
3520
|
-
"not_found_error",
|
|
3521
|
-
"request_too_large",
|
|
3522
|
-
"billing_error",
|
|
3523
|
-
"insufficient_quota",
|
|
3524
|
-
"MODEL_PROVIDER_AUTHENTICATION",
|
|
3525
|
-
"MODEL_PROVIDER_PERMISSION",
|
|
3526
|
-
"MODEL_PROVIDER_INVALID_REQUEST",
|
|
3527
|
-
"MODEL_PROVIDER_NOT_FOUND",
|
|
3528
|
-
"MODEL_PROVIDER_QUOTA_EXHAUSTED"
|
|
3529
|
-
]);
|
|
3530
3613
|
function securityHeaders3() {
|
|
3531
3614
|
return /* @__PURE__ */ new Set(["authorization", "x-api-key", "anthropic-version", "content-type", "accept"]);
|
|
3532
3615
|
}
|
|
@@ -3787,9 +3870,9 @@ function projectResponsesOutput(payload, { status }) {
|
|
|
3787
3870
|
reasoning.push(partsText(item.content, /* @__PURE__ */ new Set(["reasoning_text", "text"])));
|
|
3788
3871
|
}
|
|
3789
3872
|
}
|
|
3790
|
-
const
|
|
3873
|
+
const canonical9 = messages.join("");
|
|
3791
3874
|
const convenience = optionalText(payload.output_text);
|
|
3792
|
-
if ("output" in payload && payload.output_text != null &&
|
|
3875
|
+
if ("output" in payload && payload.output_text != null && canonical9 !== convenience) {
|
|
3793
3876
|
throw new ProtocolError("invalid model frame", "envelope_invalid");
|
|
3794
3877
|
}
|
|
3795
3878
|
let finish;
|
|
@@ -3809,7 +3892,7 @@ function projectResponsesOutput(payload, { status }) {
|
|
|
3809
3892
|
finish = "content_filter";
|
|
3810
3893
|
calls.length = 0;
|
|
3811
3894
|
}
|
|
3812
|
-
return { finish, content:
|
|
3895
|
+
return { finish, content: canonical9 || convenience, reasoning: reasoning.join(""), calls, refused };
|
|
3813
3896
|
}
|
|
3814
3897
|
function responseMessageContent(value) {
|
|
3815
3898
|
if (!Array.isArray(value)) throw new ProtocolError("invalid model frame", "envelope_invalid");
|
|
@@ -3849,8 +3932,13 @@ function parseResponsesBuffered(bodyText, request, { captureReplay = false, onTh
|
|
|
3849
3932
|
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
3850
3933
|
throw new ProtocolError("invalid response envelope", "envelope_invalid");
|
|
3851
3934
|
}
|
|
3935
|
+
if (payload.error != null || payload.status === "failed") {
|
|
3936
|
+
if (payload.status != null && payload.status !== "failed") throw new ProtocolError("conflicting response envelope", "envelope_invalid");
|
|
3937
|
+
throw Object.assign(new ProtocolError("provider rejected generation", "provider_error"), {
|
|
3938
|
+
streamError: classifyOpenAIProviderError(payload.error)
|
|
3939
|
+
});
|
|
3940
|
+
}
|
|
3852
3941
|
const status = identityOf(payload.status);
|
|
3853
|
-
if (payload.error != null) throw new ProtocolError("invalid response envelope", "envelope_invalid");
|
|
3854
3942
|
if (status === "failed") throw new ProtocolError("invalid response envelope", "envelope_invalid");
|
|
3855
3943
|
validateBufferedIdentity(payload);
|
|
3856
3944
|
const reportedUsage = parseResponsesUsage(payload.usage);
|
|
@@ -4383,21 +4471,7 @@ function createResponsesStreamState(profile) {
|
|
|
4383
4471
|
}
|
|
4384
4472
|
const usage = parseResponsesUsage(failedBody.usage);
|
|
4385
4473
|
if (usage != null) this.usage = usage;
|
|
4386
|
-
|
|
4387
|
-
const code = String(errorObj.code || errorObj.type || "");
|
|
4388
|
-
let kind;
|
|
4389
|
-
let failureKind;
|
|
4390
|
-
if (RETRYABLE_ERROR_CODES.has(code)) {
|
|
4391
|
-
kind = "provider_retryable_error";
|
|
4392
|
-
failureKind = code === "rate_limit_error" || code === "rate_limit_exceeded" ? "rate_limit" : "server_error";
|
|
4393
|
-
} else if (TERMINAL_ERROR_CODES.has(code)) {
|
|
4394
|
-
kind = "provider_terminal_error";
|
|
4395
|
-
failureKind = "client_error";
|
|
4396
|
-
} else {
|
|
4397
|
-
kind = "provider_terminal_error";
|
|
4398
|
-
failureKind = "invalid_response";
|
|
4399
|
-
}
|
|
4400
|
-
this.streamError = { kind, failureKind };
|
|
4474
|
+
this.streamError = classifyOpenAIProviderError(failedBody.error);
|
|
4401
4475
|
},
|
|
4402
4476
|
handleTerminal(event, { text: drainText, reasoning: drainReasoning }, emit) {
|
|
4403
4477
|
const responsePayload = objectOf(event.response);
|
|
@@ -4494,6 +4568,9 @@ function createResponsesStreamState(profile) {
|
|
|
4494
4568
|
const { usage, usageReported } = sealUsage(this.usage);
|
|
4495
4569
|
const reasoning = this.reasoning;
|
|
4496
4570
|
if (this.streamError) {
|
|
4571
|
+
if (this.streamError.kind === "provider_retryable_error" && (this.refused || this.finish === "content_filter")) {
|
|
4572
|
+
return { kind: "policy_abort", text: this.text, toolCalls: [], usage, usageReported };
|
|
4573
|
+
}
|
|
4497
4574
|
return {
|
|
4498
4575
|
kind: this.streamError.kind,
|
|
4499
4576
|
text: this.text,
|
|
@@ -4808,6 +4885,10 @@ async function bufferedResponse(response, request, binding, maxBytes, emit, obse
|
|
|
4808
4885
|
}
|
|
4809
4886
|
return withFailure(parseOpenAIBuffered(bodyText, request, { captureReplay, binding, onThinking }), binding, "buffered", "protocol_invalid");
|
|
4810
4887
|
} catch (error) {
|
|
4888
|
+
if (error instanceof ProtocolError && error.streamError) {
|
|
4889
|
+
const result = { ...terminalResult(error.streamError.failureKind), kind: error.streamError.kind };
|
|
4890
|
+
return withFailure(result, binding, "buffered", "provider_error");
|
|
4891
|
+
}
|
|
4811
4892
|
return withFailure(terminalResult("invalid_response"), binding, "buffered", protocolCode(error));
|
|
4812
4893
|
}
|
|
4813
4894
|
}
|
|
@@ -5195,7 +5276,7 @@ var ERR = {
|
|
|
5195
5276
|
var success = (id, result) => ({ jsonrpc: "2.0", id, result });
|
|
5196
5277
|
var errorResponse = (id, e, data) => ({ jsonrpc: "2.0", id, error: publicFailureContent({ code: e.code, message: e.message, ...data ? { data } : {} }) });
|
|
5197
5278
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
5198
|
-
var digest = (value) => createHash7("sha256").update(
|
|
5279
|
+
var digest = (value) => createHash7("sha256").update(canonical8(value)).digest("hex");
|
|
5199
5280
|
var runIdFor = (requestId) => "rpc:" + createHash7("sha256").update(requestId).digest("hex");
|
|
5200
5281
|
function nativeErrorToRpc(e) {
|
|
5201
5282
|
if (isNativeError(e)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kingsoftcloud/agentkit-harness-node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone Native Harness Node adapters: a durable SQLite run store, a one-request model HTTP port, and a minimal versioned JSON-RPC 2.0 over NDJSON process entry. Reuses the shared Native adapter implementations and externalizes @kingsoftcloud/agentkit-harness-core; depends on no Studio/DSH code at runtime.",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"./native/component-tools": "./src/native/component-tools.mjs",
|
|
36
36
|
"./native/context-counter": "./src/native/context-counter.mjs",
|
|
37
37
|
"./native/conversation-command-control": "./src/native/conversation-command-control.mjs",
|
|
38
|
+
"./native/conversation-presentation": "./src/native/conversation-presentation.mjs",
|
|
38
39
|
"./native/delivery-timeline": "./src/native/delivery-timeline.mjs",
|
|
39
40
|
"./native/dsh-background-ownership": "./src/native/dsh-background-ownership.mjs",
|
|
40
41
|
"./native/dsh-managed-ownership": "./src/native/dsh-managed-ownership.mjs",
|
|
@@ -137,7 +138,7 @@
|
|
|
137
138
|
"src/package-integrity.mjs"
|
|
138
139
|
],
|
|
139
140
|
"dependencies": {
|
|
140
|
-
"@kingsoftcloud/agentkit-harness-core": "0.0.
|
|
141
|
+
"@kingsoftcloud/agentkit-harness-core": "0.0.14",
|
|
141
142
|
"@astral-sh/ruff-wasm-nodejs": "0.16.8",
|
|
142
143
|
"parse5": "7.3.0",
|
|
143
144
|
"playwright-core": "1.58.2",
|