@reinsjs/core 0.12.0 → 0.14.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/CHANGELOG.md +20 -0
- package/README.md +2 -1
- package/dist/{chunk-3QMUURRG.js → chunk-DFXHUJV4.js} +2 -1
- package/dist/{chunk-3QMUURRG.js.map → chunk-DFXHUJV4.js.map} +1 -1
- package/dist/{core-h3S4jFh-.d.ts → core-BhmO9N-j.d.ts} +51 -1
- package/dist/index.d.ts +129 -5
- package/dist/index.js +239 -82
- package/dist/index.js.map +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
createEvent,
|
|
9
9
|
renderToolReference,
|
|
10
10
|
uuidv7
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-DFXHUJV4.js";
|
|
12
12
|
|
|
13
13
|
// src/events/core.ts
|
|
14
14
|
function contextTokensOf(usage) {
|
|
@@ -35,7 +35,8 @@ var DEFAULT_MODEL_INVISIBLE_TYPES = /* @__PURE__ */ new Set([
|
|
|
35
35
|
"core.handoff",
|
|
36
36
|
"core.error",
|
|
37
37
|
"core.tools_bound",
|
|
38
|
-
"core.tool_started"
|
|
38
|
+
"core.tool_started",
|
|
39
|
+
"core.run_ended"
|
|
39
40
|
]);
|
|
40
41
|
function visibilityFilter(opts = {}) {
|
|
41
42
|
const invisible = opts.invisibleTypes ? new Set(opts.invisibleTypes) : DEFAULT_MODEL_INVISIBLE_TYPES;
|
|
@@ -661,13 +662,26 @@ function isReplayable(tool) {
|
|
|
661
662
|
return tool.replayable ?? tool.risk === "low";
|
|
662
663
|
}
|
|
663
664
|
function startedToolCallIds(timeline) {
|
|
664
|
-
|
|
665
|
+
return new Set(toolStartedAt(timeline).keys());
|
|
666
|
+
}
|
|
667
|
+
function toolStartedAt(timeline) {
|
|
668
|
+
const started = /* @__PURE__ */ new Map();
|
|
665
669
|
for (const raw of timeline) {
|
|
666
670
|
const e = raw;
|
|
667
|
-
if (e.type === "core.tool_started"
|
|
671
|
+
if (e.type === "core.tool_started" && !started.has(e.payload.toolCallId))
|
|
672
|
+
started.set(e.payload.toolCallId, e.at);
|
|
668
673
|
}
|
|
669
674
|
return started;
|
|
670
675
|
}
|
|
676
|
+
function withStartedAt(text, at) {
|
|
677
|
+
if (at === void 0) return text;
|
|
678
|
+
const date = new Date(at);
|
|
679
|
+
if (Number.isNaN(date.getTime())) return text;
|
|
680
|
+
return `${text} This call started at ${date.toISOString()}.`;
|
|
681
|
+
}
|
|
682
|
+
function outcomeUnknownText(tool, startedAt) {
|
|
683
|
+
return tool !== void 0 && !isReplayable(tool) ? withStartedAt(OUTCOME_UNKNOWN_TEXT, startedAt) : OUTCOME_UNKNOWN_TEXT;
|
|
684
|
+
}
|
|
671
685
|
|
|
672
686
|
// src/loop/retry.ts
|
|
673
687
|
var DEFAULT_RETRY_MAX_ATTEMPTS = 3;
|
|
@@ -800,6 +814,159 @@ async function readTimeline(log, sessionId, opts) {
|
|
|
800
814
|
return out;
|
|
801
815
|
}
|
|
802
816
|
|
|
817
|
+
// src/loop/tools.ts
|
|
818
|
+
function toolResultTrust(tool, isError) {
|
|
819
|
+
if (!tool || tool.resultTrust === void 0 || isError) return void 0;
|
|
820
|
+
return tool.resultTrust;
|
|
821
|
+
}
|
|
822
|
+
function isClientTool(tool) {
|
|
823
|
+
return !tool.execute || tool.side === "client";
|
|
824
|
+
}
|
|
825
|
+
function defineTool(tool) {
|
|
826
|
+
return tool;
|
|
827
|
+
}
|
|
828
|
+
function toolSpecOf(tool) {
|
|
829
|
+
return { name: tool.name, description: tool.description, inputSchema: tool.inputSchema };
|
|
830
|
+
}
|
|
831
|
+
function deferredToolSpecOf(tool, deferred) {
|
|
832
|
+
return deferred ? { ...toolSpecOf(tool), deferLoading: true } : toolSpecOf(tool);
|
|
833
|
+
}
|
|
834
|
+
function isDuration(x) {
|
|
835
|
+
return x === void 0 || typeof x === "number" && Number.isFinite(x) && x > 0;
|
|
836
|
+
}
|
|
837
|
+
function isContentPart(x) {
|
|
838
|
+
if (typeof x !== "object" || x === null) return false;
|
|
839
|
+
const p = x;
|
|
840
|
+
switch (p.type) {
|
|
841
|
+
case "text":
|
|
842
|
+
return typeof p.text === "string";
|
|
843
|
+
case "image":
|
|
844
|
+
return typeof p.mime === "string" && typeof p.data === "string";
|
|
845
|
+
case "video":
|
|
846
|
+
case "audio":
|
|
847
|
+
return typeof p.mime === "string" && p.mime.startsWith(`${p.type}/`) && typeof p.data === "string" && isDuration(p.durationSec);
|
|
848
|
+
case "tool_reference":
|
|
849
|
+
return typeof p.name === "string" && typeof p.description === "string" && typeof p.inputSchema === "object" && p.inputSchema !== null && !Array.isArray(p.inputSchema);
|
|
850
|
+
default:
|
|
851
|
+
return false;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
function isToolResult(x) {
|
|
855
|
+
if (typeof x !== "object" || x === null) return false;
|
|
856
|
+
const r = x;
|
|
857
|
+
return Array.isArray(r.content) && r.content.every(isContentPart) && (r.isError === void 0 || typeof r.isError === "boolean");
|
|
858
|
+
}
|
|
859
|
+
function normalizeToolOutput(output) {
|
|
860
|
+
if (typeof output === "string") return { content: [{ type: "text", text: output }] };
|
|
861
|
+
if (output === void 0 || output === null) return { content: [{ type: "text", text: "" }] };
|
|
862
|
+
if (Array.isArray(output) && output.every(isContentPart)) return { content: output };
|
|
863
|
+
if (isToolResult(output)) return output;
|
|
864
|
+
const json = JSON.stringify(output);
|
|
865
|
+
return { content: [{ type: "text", text: typeof json === "string" ? json : String(output) }] };
|
|
866
|
+
}
|
|
867
|
+
function errorMessageOf(err) {
|
|
868
|
+
if (err instanceof Error) return err.message;
|
|
869
|
+
return typeof err === "string" ? err : JSON.stringify(err) ?? String(err);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
// src/loop/run-status.ts
|
|
873
|
+
var RUN_MARKER_TYPES = ["core.tools_bound", "core.run_paused", "core.run_ended"];
|
|
874
|
+
var MARKER_SET = new Set(RUN_MARKER_TYPES);
|
|
875
|
+
function lastRunMarker(events) {
|
|
876
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
877
|
+
const e = events[i];
|
|
878
|
+
if (e !== void 0 && MARKER_SET.has(e.type)) return e;
|
|
879
|
+
}
|
|
880
|
+
return void 0;
|
|
881
|
+
}
|
|
882
|
+
function awaitingOf(input) {
|
|
883
|
+
const requestedAt = /* @__PURE__ */ new Map();
|
|
884
|
+
const decided = /* @__PURE__ */ new Set();
|
|
885
|
+
for (const raw of input.timeline) {
|
|
886
|
+
const id = raw.payload?.toolCallId;
|
|
887
|
+
if (typeof id !== "string") continue;
|
|
888
|
+
if (raw.type === "core.approval_request" && !requestedAt.has(id)) requestedAt.set(id, raw.at);
|
|
889
|
+
if (raw.type === "core.approval_decision") decided.add(id);
|
|
890
|
+
}
|
|
891
|
+
const awaiting = [];
|
|
892
|
+
for (const call of input.pending) {
|
|
893
|
+
const { toolCallId, name } = call.payload;
|
|
894
|
+
const at = requestedAt.get(toolCallId);
|
|
895
|
+
if (at !== void 0 && !decided.has(toolCallId)) {
|
|
896
|
+
awaiting.push({ kind: "approval", toolCallId, name, requestedAt: at });
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
const tool = input.tools.find((t) => t.name === name);
|
|
900
|
+
if (tool !== void 0 && isClientTool(tool)) {
|
|
901
|
+
awaiting.push({ kind: "client_tool", toolCallId, name });
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
904
|
+
const sub = input.interruptions.find((i) => i.kind === "subagent" && i.toolCallId === toolCallId);
|
|
905
|
+
if (sub?.kind === "subagent") {
|
|
906
|
+
awaiting.push({
|
|
907
|
+
kind: "subagent",
|
|
908
|
+
toolCallId,
|
|
909
|
+
name,
|
|
910
|
+
childSessionId: sub.childSessionId,
|
|
911
|
+
reason: sub.reason
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
return awaiting;
|
|
916
|
+
}
|
|
917
|
+
var PAUSE_REASONS = /* @__PURE__ */ new Set(["approval", "budget", "host"]);
|
|
918
|
+
var isNonEmptyString = (x) => typeof x === "string" && x !== "";
|
|
919
|
+
function isAwaitingCall(x) {
|
|
920
|
+
if (typeof x !== "object" || x === null) return false;
|
|
921
|
+
const a = x;
|
|
922
|
+
if (!isNonEmptyString(a.toolCallId) || typeof a.name !== "string") return false;
|
|
923
|
+
if (a.kind === "approval") return typeof a.requestedAt === "number" && Number.isFinite(a.requestedAt);
|
|
924
|
+
if (a.kind === "client_tool") return true;
|
|
925
|
+
if (a.kind === "subagent")
|
|
926
|
+
return isNonEmptyString(a.childSessionId) && typeof a.reason === "string" && PAUSE_REASONS.has(a.reason);
|
|
927
|
+
return false;
|
|
928
|
+
}
|
|
929
|
+
function runStatusOf(input) {
|
|
930
|
+
if (input.held) return { state: "running" };
|
|
931
|
+
if (input.lastMarker === void 0) return { state: "idle" };
|
|
932
|
+
let marker;
|
|
933
|
+
try {
|
|
934
|
+
marker = (input.registry ?? createCoreRegistry()).read(input.lastMarker);
|
|
935
|
+
} catch {
|
|
936
|
+
return { state: "unknown" };
|
|
937
|
+
}
|
|
938
|
+
const p = typeof marker.payload === "object" && marker.payload !== null ? marker.payload : {};
|
|
939
|
+
const { seq, at } = marker;
|
|
940
|
+
switch (marker.type) {
|
|
941
|
+
case "core.tools_bound":
|
|
942
|
+
return p.marksEnd === true ? { state: "interrupted", seq, startedAt: at } : { state: "unknown" };
|
|
943
|
+
case "core.run_paused": {
|
|
944
|
+
if (typeof p.reason !== "string" || !PAUSE_REASONS.has(p.reason)) return { state: "unknown" };
|
|
945
|
+
if (p.stopped !== void 0 && p.stopped !== true) return { state: "unknown" };
|
|
946
|
+
if (p.awaiting !== void 0 && !(Array.isArray(p.awaiting) && p.awaiting.every(isAwaitingCall)))
|
|
947
|
+
return { state: "unknown" };
|
|
948
|
+
return {
|
|
949
|
+
state: "paused",
|
|
950
|
+
seq,
|
|
951
|
+
endedAt: at,
|
|
952
|
+
reason: p.reason,
|
|
953
|
+
stopped: p.stopped === true,
|
|
954
|
+
awaiting: p.awaiting
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
case "core.run_ended": {
|
|
958
|
+
if (p.status === "done") return { state: "done", seq, endedAt: at };
|
|
959
|
+
if (p.status === "handoff" && isNonEmptyString(p.toSessionId))
|
|
960
|
+
return { state: "handoff", seq, endedAt: at, toSessionId: p.toSessionId };
|
|
961
|
+
if (p.status === "error" && typeof p.category === "string")
|
|
962
|
+
return { state: "error", seq, endedAt: at, category: p.category };
|
|
963
|
+
return { state: "unknown" };
|
|
964
|
+
}
|
|
965
|
+
default:
|
|
966
|
+
return { state: "unknown" };
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
803
970
|
// src/loop/state.ts
|
|
804
971
|
function pendingToolCalls(timeline) {
|
|
805
972
|
const answered = /* @__PURE__ */ new Set();
|
|
@@ -1045,58 +1212,6 @@ function isSubagentPause(value) {
|
|
|
1045
1212
|
return typeof value === "object" && value !== null && value[SUBAGENT_PAUSE] === true;
|
|
1046
1213
|
}
|
|
1047
1214
|
|
|
1048
|
-
// src/loop/tools.ts
|
|
1049
|
-
function toolResultTrust(tool, isError) {
|
|
1050
|
-
if (!tool || tool.resultTrust === void 0 || isError) return void 0;
|
|
1051
|
-
return tool.resultTrust;
|
|
1052
|
-
}
|
|
1053
|
-
function defineTool(tool) {
|
|
1054
|
-
return tool;
|
|
1055
|
-
}
|
|
1056
|
-
function toolSpecOf(tool) {
|
|
1057
|
-
return { name: tool.name, description: tool.description, inputSchema: tool.inputSchema };
|
|
1058
|
-
}
|
|
1059
|
-
function deferredToolSpecOf(tool, deferred) {
|
|
1060
|
-
return deferred ? { ...toolSpecOf(tool), deferLoading: true } : toolSpecOf(tool);
|
|
1061
|
-
}
|
|
1062
|
-
function isDuration(x) {
|
|
1063
|
-
return x === void 0 || typeof x === "number" && Number.isFinite(x) && x > 0;
|
|
1064
|
-
}
|
|
1065
|
-
function isContentPart(x) {
|
|
1066
|
-
if (typeof x !== "object" || x === null) return false;
|
|
1067
|
-
const p = x;
|
|
1068
|
-
switch (p.type) {
|
|
1069
|
-
case "text":
|
|
1070
|
-
return typeof p.text === "string";
|
|
1071
|
-
case "image":
|
|
1072
|
-
return typeof p.mime === "string" && typeof p.data === "string";
|
|
1073
|
-
case "video":
|
|
1074
|
-
case "audio":
|
|
1075
|
-
return typeof p.mime === "string" && p.mime.startsWith(`${p.type}/`) && typeof p.data === "string" && isDuration(p.durationSec);
|
|
1076
|
-
case "tool_reference":
|
|
1077
|
-
return typeof p.name === "string" && typeof p.description === "string" && typeof p.inputSchema === "object" && p.inputSchema !== null && !Array.isArray(p.inputSchema);
|
|
1078
|
-
default:
|
|
1079
|
-
return false;
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
function isToolResult(x) {
|
|
1083
|
-
if (typeof x !== "object" || x === null) return false;
|
|
1084
|
-
const r = x;
|
|
1085
|
-
return Array.isArray(r.content) && r.content.every(isContentPart) && (r.isError === void 0 || typeof r.isError === "boolean");
|
|
1086
|
-
}
|
|
1087
|
-
function normalizeToolOutput(output) {
|
|
1088
|
-
if (typeof output === "string") return { content: [{ type: "text", text: output }] };
|
|
1089
|
-
if (output === void 0 || output === null) return { content: [{ type: "text", text: "" }] };
|
|
1090
|
-
if (Array.isArray(output) && output.every(isContentPart)) return { content: output };
|
|
1091
|
-
if (isToolResult(output)) return output;
|
|
1092
|
-
const json = JSON.stringify(output);
|
|
1093
|
-
return { content: [{ type: "text", text: typeof json === "string" ? json : String(output) }] };
|
|
1094
|
-
}
|
|
1095
|
-
function errorMessageOf(err) {
|
|
1096
|
-
if (err instanceof Error) return err.message;
|
|
1097
|
-
return typeof err === "string" ? err : JSON.stringify(err) ?? String(err);
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
1215
|
// src/loop/tools-bound.ts
|
|
1101
1216
|
function lastToolsBound(timeline) {
|
|
1102
1217
|
for (let i = timeline.length - 1; i >= 0; i--) {
|
|
@@ -1123,7 +1238,15 @@ function renderToolChangeNote(diff) {
|
|
|
1123
1238
|
function toolsBoundDrafts(input) {
|
|
1124
1239
|
const toolNames = [...input.toolNames].sort();
|
|
1125
1240
|
const drafts = [
|
|
1126
|
-
{
|
|
1241
|
+
{
|
|
1242
|
+
type: "core.tools_bound",
|
|
1243
|
+
actor: "system",
|
|
1244
|
+
payload: {
|
|
1245
|
+
toolNames,
|
|
1246
|
+
configHash: input.configHash,
|
|
1247
|
+
...input.marksEnd ? { marksEnd: true } : {}
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1127
1250
|
];
|
|
1128
1251
|
const previous = lastToolsBound(input.timeline);
|
|
1129
1252
|
if (!input.announce || previous === void 0) return drafts;
|
|
@@ -1280,12 +1403,13 @@ async function* runLoop(cfg) {
|
|
|
1280
1403
|
const timeline = await readTimeline(log, sessionId, { registry });
|
|
1281
1404
|
const pending = pendingToolCalls(timeline);
|
|
1282
1405
|
if (pending.length === 0) return [];
|
|
1283
|
-
const started =
|
|
1406
|
+
const started = toolStartedAt(timeline);
|
|
1284
1407
|
return append(
|
|
1285
1408
|
pending.map((call) => {
|
|
1286
1409
|
const { toolCallId, name } = call.payload;
|
|
1287
1410
|
const tool = baseTools.find((t) => t.name === name);
|
|
1288
|
-
const
|
|
1411
|
+
const startedAt2 = started.get(toolCallId);
|
|
1412
|
+
const text = startedAt2 === void 0 ? texts.notExecuted : tool !== void 0 && isReplayable(tool) ? texts.inProgress : outcomeUnknownText(tool, startedAt2);
|
|
1289
1413
|
return {
|
|
1290
1414
|
type: "core.tool_result",
|
|
1291
1415
|
actor: "tool",
|
|
@@ -1302,7 +1426,9 @@ async function* runLoop(cfg) {
|
|
|
1302
1426
|
const reason = texts ? "host" : requested;
|
|
1303
1427
|
const interruptions = texts ? [{ kind: "host", note: texts.note }] : requestedInterruptions;
|
|
1304
1428
|
const settled = texts ? await settleStopped(texts) : [];
|
|
1305
|
-
const
|
|
1429
|
+
const timeline = await readTimeline(log, sessionId, { registry });
|
|
1430
|
+
const pending = pendingToolCalls(timeline);
|
|
1431
|
+
const awaiting = awaitingOf({ timeline, pending, tools: baseTools, interruptions });
|
|
1306
1432
|
const state = await serializeRunState({
|
|
1307
1433
|
sessionId,
|
|
1308
1434
|
lastSeq: lastSeq + 1,
|
|
@@ -1314,7 +1440,13 @@ async function* runLoop(cfg) {
|
|
|
1314
1440
|
});
|
|
1315
1441
|
const events = [
|
|
1316
1442
|
...settled,
|
|
1317
|
-
...await append([
|
|
1443
|
+
...await append([
|
|
1444
|
+
{
|
|
1445
|
+
type: "core.run_paused",
|
|
1446
|
+
actor: "system",
|
|
1447
|
+
payload: { reason, state, awaiting, ...texts ? { stopped: true } : {} }
|
|
1448
|
+
}
|
|
1449
|
+
])
|
|
1318
1450
|
];
|
|
1319
1451
|
return { events, result: { status: "paused", sessionId, lastSeq, reason, interruptions, state } };
|
|
1320
1452
|
};
|
|
@@ -1323,7 +1455,10 @@ async function* runLoop(cfg) {
|
|
|
1323
1455
|
ctx.budget.tokensSpent = tokensSpent;
|
|
1324
1456
|
};
|
|
1325
1457
|
const fail = async (payload) => {
|
|
1326
|
-
const events = await append([
|
|
1458
|
+
const events = await append([
|
|
1459
|
+
{ type: "core.error", actor: "system", payload },
|
|
1460
|
+
{ type: "core.run_ended", actor: "system", payload: { status: "error", category: payload.category } }
|
|
1461
|
+
]);
|
|
1327
1462
|
const error = events[0];
|
|
1328
1463
|
return { events, result: { status: "error", sessionId, lastSeq, error } };
|
|
1329
1464
|
};
|
|
@@ -1333,7 +1468,8 @@ async function* runLoop(cfg) {
|
|
|
1333
1468
|
const forwardedDecisions = (cfg.decisions ?? []).filter(
|
|
1334
1469
|
(d) => d.sessionId !== void 0 && d.sessionId !== sessionId
|
|
1335
1470
|
);
|
|
1336
|
-
|
|
1471
|
+
const resuming = cfg.resume !== void 0 || ownDecisions.length > 0;
|
|
1472
|
+
if (resuming) {
|
|
1337
1473
|
const timeline = await readTimeline(log, sessionId, { registry });
|
|
1338
1474
|
if (cfg.resume !== void 0) {
|
|
1339
1475
|
await validateResume({
|
|
@@ -1360,6 +1496,20 @@ async function* runLoop(cfg) {
|
|
|
1360
1496
|
);
|
|
1361
1497
|
}
|
|
1362
1498
|
}
|
|
1499
|
+
}
|
|
1500
|
+
if (!cfg.signal?.aborted) {
|
|
1501
|
+
yield* await append(
|
|
1502
|
+
toolsBoundDrafts({
|
|
1503
|
+
timeline: await readTimeline(log, sessionId, { registry }),
|
|
1504
|
+
toolNames: baseTools.map((t) => t.name),
|
|
1505
|
+
configHash,
|
|
1506
|
+
announce: cfg.announceToolChanges ?? true,
|
|
1507
|
+
marksEnd: true
|
|
1508
|
+
})
|
|
1509
|
+
);
|
|
1510
|
+
}
|
|
1511
|
+
if (resuming) {
|
|
1512
|
+
const decisions = ownDecisions;
|
|
1363
1513
|
if (cfg.resume !== void 0) {
|
|
1364
1514
|
const by = decisions[0]?.by;
|
|
1365
1515
|
yield* await append([
|
|
@@ -1379,16 +1529,6 @@ async function* runLoop(cfg) {
|
|
|
1379
1529
|
}))
|
|
1380
1530
|
);
|
|
1381
1531
|
}
|
|
1382
|
-
if (!cfg.signal?.aborted) {
|
|
1383
|
-
yield* await append(
|
|
1384
|
-
toolsBoundDrafts({
|
|
1385
|
-
timeline: await readTimeline(log, sessionId, { registry }),
|
|
1386
|
-
toolNames: baseTools.map((t) => t.name),
|
|
1387
|
-
configHash,
|
|
1388
|
-
announce: cfg.announceToolChanges ?? true
|
|
1389
|
-
})
|
|
1390
|
-
);
|
|
1391
|
-
}
|
|
1392
1532
|
yield* await append(input.map((d) => withResultTrust(d, baseTools)));
|
|
1393
1533
|
while (true) {
|
|
1394
1534
|
if (cfg.signal?.aborted) {
|
|
@@ -1702,7 +1842,10 @@ async function* runLoop(cfg) {
|
|
|
1702
1842
|
}
|
|
1703
1843
|
yield* await flush();
|
|
1704
1844
|
if (decision === "continue") return void 0;
|
|
1705
|
-
if (decision === "stop")
|
|
1845
|
+
if (decision === "stop") {
|
|
1846
|
+
yield* await append([{ type: "core.run_ended", actor: "system", payload: { status: "done" } }]);
|
|
1847
|
+
return { status: "done", sessionId, lastSeq };
|
|
1848
|
+
}
|
|
1706
1849
|
if ("pause" in decision) {
|
|
1707
1850
|
const note = decision.pause.note ?? `a socket requested a pause (${decision.pause.reason})`;
|
|
1708
1851
|
const kind = decision.pause.reason;
|
|
@@ -1741,6 +1884,9 @@ async function* runLoop(cfg) {
|
|
|
1741
1884
|
);
|
|
1742
1885
|
await log.append(openingEvents);
|
|
1743
1886
|
yield* openingEvents;
|
|
1887
|
+
yield* await append([
|
|
1888
|
+
{ type: "core.run_ended", actor: "system", payload: { status: "handoff", toSessionId } }
|
|
1889
|
+
]);
|
|
1744
1890
|
await cfg.onHandoff?.(sessionId, toSessionId);
|
|
1745
1891
|
return { status: "handoff", sessionId, lastSeq, toSessionId };
|
|
1746
1892
|
}
|
|
@@ -1778,7 +1924,7 @@ async function* executeToolCalls(ctx, calls, timeline, deps) {
|
|
|
1778
1924
|
};
|
|
1779
1925
|
const decisions = /* @__PURE__ */ new Map();
|
|
1780
1926
|
const requested = /* @__PURE__ */ new Set();
|
|
1781
|
-
const started =
|
|
1927
|
+
const started = toolStartedAt(timeline);
|
|
1782
1928
|
for (const raw of timeline) {
|
|
1783
1929
|
const e = raw;
|
|
1784
1930
|
if (e.type === "core.approval_decision") decisions.set(e.payload.toolCallId, e.payload);
|
|
@@ -1800,7 +1946,7 @@ async function* executeToolCalls(ctx, calls, timeline, deps) {
|
|
|
1800
1946
|
payload: { toolCallId, name, content: [{ type: "text", text }], isError: true }
|
|
1801
1947
|
});
|
|
1802
1948
|
if (started.has(toolCallId) && (tool === void 0 || !isReplayable(tool))) {
|
|
1803
|
-
yield* await settle(errorResult(
|
|
1949
|
+
yield* await settle(errorResult(outcomeUnknownText(tool, started.get(toolCallId))));
|
|
1804
1950
|
continue;
|
|
1805
1951
|
}
|
|
1806
1952
|
const decided = decisions.get(toolCallId);
|
|
@@ -1870,7 +2016,7 @@ async function* executeToolCalls(ctx, calls, timeline, deps) {
|
|
|
1870
2016
|
batch.held.push(toolCallId);
|
|
1871
2017
|
continue;
|
|
1872
2018
|
}
|
|
1873
|
-
if (
|
|
2019
|
+
if (isClientTool(tool) || !tool.execute) {
|
|
1874
2020
|
summary.interruptions.push({ kind: "client_tool", toolCallId, call: call.payload });
|
|
1875
2021
|
batch.held.push(toolCallId);
|
|
1876
2022
|
continue;
|
|
@@ -1879,11 +2025,14 @@ async function* executeToolCalls(ctx, calls, timeline, deps) {
|
|
|
1879
2025
|
const replayable = isReplayable(tool);
|
|
1880
2026
|
const markStarted = async function* () {
|
|
1881
2027
|
if (started.has(toolCallId)) return;
|
|
1882
|
-
started.add(toolCallId);
|
|
1883
2028
|
yield* await flush();
|
|
1884
|
-
|
|
2029
|
+
const [ev] = await append([
|
|
1885
2030
|
{ type: "core.tool_started", actor: "system", parentId: call.id, payload: { toolCallId } }
|
|
1886
2031
|
]);
|
|
2032
|
+
if (ev) {
|
|
2033
|
+
started.set(toolCallId, ev.at);
|
|
2034
|
+
yield ev;
|
|
2035
|
+
}
|
|
1887
2036
|
};
|
|
1888
2037
|
if (!replayable) yield* markStarted();
|
|
1889
2038
|
let result;
|
|
@@ -1909,7 +2058,7 @@ async function* executeToolCalls(ctx, calls, timeline, deps) {
|
|
|
1909
2058
|
};
|
|
1910
2059
|
} catch (err) {
|
|
1911
2060
|
result = errorResult(
|
|
1912
|
-
!replayable && cfg.signal?.aborted ?
|
|
2061
|
+
!replayable && cfg.signal?.aborted ? outcomeUnknownText(tool, started.get(toolCallId)) : `Tool execution failed: ${errorMessageOf(err)}`
|
|
1913
2062
|
);
|
|
1914
2063
|
}
|
|
1915
2064
|
for (const s of sockets) {
|
|
@@ -2194,7 +2343,7 @@ function memoryStore() {
|
|
|
2194
2343
|
}
|
|
2195
2344
|
|
|
2196
2345
|
// src/index.ts
|
|
2197
|
-
var REINS_VERSION = "0.
|
|
2346
|
+
var REINS_VERSION = "0.14.0";
|
|
2198
2347
|
export {
|
|
2199
2348
|
BUILTIN_APPROVAL_POLICY,
|
|
2200
2349
|
CORE_SCHEMAS,
|
|
@@ -2217,6 +2366,7 @@ export {
|
|
|
2217
2366
|
LoweringError,
|
|
2218
2367
|
OUTCOME_UNKNOWN_TEXT,
|
|
2219
2368
|
REINS_VERSION,
|
|
2369
|
+
RUN_MARKER_TYPES,
|
|
2220
2370
|
RunStateError,
|
|
2221
2371
|
RunStop,
|
|
2222
2372
|
STOPPED_IN_PROGRESS_TEXT,
|
|
@@ -2227,6 +2377,7 @@ export {
|
|
|
2227
2377
|
UNTRUSTED_CLOSE_TAG,
|
|
2228
2378
|
UNTRUSTED_TAG,
|
|
2229
2379
|
assertRunStateShape,
|
|
2380
|
+
awaitingOf,
|
|
2230
2381
|
backoffDelayMs,
|
|
2231
2382
|
budgetTruncate,
|
|
2232
2383
|
computeConfigHash,
|
|
@@ -2256,6 +2407,7 @@ export {
|
|
|
2256
2407
|
foldedToolResults,
|
|
2257
2408
|
forkSession,
|
|
2258
2409
|
inputDrafts,
|
|
2410
|
+
isClientTool,
|
|
2259
2411
|
isCompaction,
|
|
2260
2412
|
isContentPart,
|
|
2261
2413
|
isModelOutput,
|
|
@@ -2266,6 +2418,7 @@ export {
|
|
|
2266
2418
|
isSubagentPause,
|
|
2267
2419
|
isTransientFailure,
|
|
2268
2420
|
keptBy,
|
|
2421
|
+
lastRunMarker,
|
|
2269
2422
|
lastToolsBound,
|
|
2270
2423
|
lossesOf,
|
|
2271
2424
|
markUntrusted,
|
|
@@ -2273,6 +2426,7 @@ export {
|
|
|
2273
2426
|
memoryStore,
|
|
2274
2427
|
needsUntrustedMark,
|
|
2275
2428
|
normalizeToolOutput,
|
|
2429
|
+
outcomeUnknownText,
|
|
2276
2430
|
pausedStateOf,
|
|
2277
2431
|
pendingToolCalls,
|
|
2278
2432
|
project,
|
|
@@ -2287,6 +2441,7 @@ export {
|
|
|
2287
2441
|
resolveSocketContributions,
|
|
2288
2442
|
roughTokenEstimate,
|
|
2289
2443
|
runLoop,
|
|
2444
|
+
runStatusOf,
|
|
2290
2445
|
serializeRunState,
|
|
2291
2446
|
signRunState,
|
|
2292
2447
|
splitTurns,
|
|
@@ -2299,6 +2454,7 @@ export {
|
|
|
2299
2454
|
toolCallArgumentsMeta,
|
|
2300
2455
|
toolResultTrust,
|
|
2301
2456
|
toolSpecOf,
|
|
2457
|
+
toolStartedAt,
|
|
2302
2458
|
toolsBoundDrafts,
|
|
2303
2459
|
untrustedOpenTag,
|
|
2304
2460
|
untrustedSourceOf,
|
|
@@ -2306,6 +2462,7 @@ export {
|
|
|
2306
2462
|
uuidv7,
|
|
2307
2463
|
validateResume,
|
|
2308
2464
|
verifyRunState,
|
|
2309
|
-
visibilityFilter
|
|
2465
|
+
visibilityFilter,
|
|
2466
|
+
withStartedAt
|
|
2310
2467
|
};
|
|
2311
2468
|
//# sourceMappingURL=index.js.map
|