@reinsjs/core 0.11.0 → 0.13.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 +14 -0
- package/README.md +2 -2
- package/dist/core-h3S4jFh-.d.ts +1256 -0
- package/dist/index.d.ts +34 -573
- package/dist/index.js +48 -16
- package/dist/index.js.map +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/types-CFO8uTd0.d.ts +0 -682
package/dist/index.js
CHANGED
|
@@ -661,13 +661,26 @@ function isReplayable(tool) {
|
|
|
661
661
|
return tool.replayable ?? tool.risk === "low";
|
|
662
662
|
}
|
|
663
663
|
function startedToolCallIds(timeline) {
|
|
664
|
-
|
|
664
|
+
return new Set(toolStartedAt(timeline).keys());
|
|
665
|
+
}
|
|
666
|
+
function toolStartedAt(timeline) {
|
|
667
|
+
const started = /* @__PURE__ */ new Map();
|
|
665
668
|
for (const raw of timeline) {
|
|
666
669
|
const e = raw;
|
|
667
|
-
if (e.type === "core.tool_started"
|
|
670
|
+
if (e.type === "core.tool_started" && !started.has(e.payload.toolCallId))
|
|
671
|
+
started.set(e.payload.toolCallId, e.at);
|
|
668
672
|
}
|
|
669
673
|
return started;
|
|
670
674
|
}
|
|
675
|
+
function withStartedAt(text, at) {
|
|
676
|
+
if (at === void 0) return text;
|
|
677
|
+
const date = new Date(at);
|
|
678
|
+
if (Number.isNaN(date.getTime())) return text;
|
|
679
|
+
return `${text} This call started at ${date.toISOString()}.`;
|
|
680
|
+
}
|
|
681
|
+
function outcomeUnknownText(tool, startedAt) {
|
|
682
|
+
return tool !== void 0 && !isReplayable(tool) ? withStartedAt(OUTCOME_UNKNOWN_TEXT, startedAt) : OUTCOME_UNKNOWN_TEXT;
|
|
683
|
+
}
|
|
671
684
|
|
|
672
685
|
// src/loop/retry.ts
|
|
673
686
|
var DEFAULT_RETRY_MAX_ATTEMPTS = 3;
|
|
@@ -917,6 +930,17 @@ function assertRunStateShape(raw) {
|
|
|
917
930
|
const ok = typeof s === "object" && s !== null && s.v === 1 && typeof s.sessionId === "string" && Number.isInteger(s.lastSeq) && Array.isArray(s.pendingToolCallIds) && s.pendingToolCallIds.every((id) => typeof id === "string") && typeof s.configHash === "string" && typeof s.pendingDigest === "string" && (s.modelDigest === void 0 || typeof s.modelDigest === "string") && (s.pendingToolsDigest === void 0 || typeof s.pendingToolsDigest === "string") && (s.sig === void 0 || typeof s.sig === "string");
|
|
918
931
|
if (!ok) throw new RunStateError("malformed", "run state is not in the v1 shape");
|
|
919
932
|
}
|
|
933
|
+
function pausedStateOf(event) {
|
|
934
|
+
if (event?.type !== "core.run_paused") return void 0;
|
|
935
|
+
const state = event.payload.state;
|
|
936
|
+
if (state === void 0) return void 0;
|
|
937
|
+
try {
|
|
938
|
+
assertRunStateShape(state);
|
|
939
|
+
} catch {
|
|
940
|
+
return void 0;
|
|
941
|
+
}
|
|
942
|
+
return state;
|
|
943
|
+
}
|
|
920
944
|
async function validateResume(input) {
|
|
921
945
|
const { state } = input;
|
|
922
946
|
assertRunStateShape(state);
|
|
@@ -1269,12 +1293,13 @@ async function* runLoop(cfg) {
|
|
|
1269
1293
|
const timeline = await readTimeline(log, sessionId, { registry });
|
|
1270
1294
|
const pending = pendingToolCalls(timeline);
|
|
1271
1295
|
if (pending.length === 0) return [];
|
|
1272
|
-
const started =
|
|
1296
|
+
const started = toolStartedAt(timeline);
|
|
1273
1297
|
return append(
|
|
1274
1298
|
pending.map((call) => {
|
|
1275
1299
|
const { toolCallId, name } = call.payload;
|
|
1276
1300
|
const tool = baseTools.find((t) => t.name === name);
|
|
1277
|
-
const
|
|
1301
|
+
const startedAt2 = started.get(toolCallId);
|
|
1302
|
+
const text = startedAt2 === void 0 ? texts.notExecuted : tool !== void 0 && isReplayable(tool) ? texts.inProgress : outcomeUnknownText(tool, startedAt2);
|
|
1278
1303
|
return {
|
|
1279
1304
|
type: "core.tool_result",
|
|
1280
1305
|
actor: "tool",
|
|
@@ -1291,20 +1316,20 @@ async function* runLoop(cfg) {
|
|
|
1291
1316
|
const reason = texts ? "host" : requested;
|
|
1292
1317
|
const interruptions = texts ? [{ kind: "host", note: texts.note }] : requestedInterruptions;
|
|
1293
1318
|
const settled = texts ? await settleStopped(texts) : [];
|
|
1294
|
-
const events = [
|
|
1295
|
-
...settled,
|
|
1296
|
-
...await append([{ type: "core.run_paused", actor: "system", payload: { reason } }])
|
|
1297
|
-
];
|
|
1298
1319
|
const pending = pendingToolCalls(await readTimeline(log, sessionId, { registry }));
|
|
1299
1320
|
const state = await serializeRunState({
|
|
1300
1321
|
sessionId,
|
|
1301
|
-
lastSeq,
|
|
1322
|
+
lastSeq: lastSeq + 1,
|
|
1302
1323
|
pending,
|
|
1303
1324
|
configHash,
|
|
1304
1325
|
model,
|
|
1305
1326
|
tools: baseTools,
|
|
1306
1327
|
...cfg.secret !== void 0 ? { secret: cfg.secret } : {}
|
|
1307
1328
|
});
|
|
1329
|
+
const events = [
|
|
1330
|
+
...settled,
|
|
1331
|
+
...await append([{ type: "core.run_paused", actor: "system", payload: { reason, state } }])
|
|
1332
|
+
];
|
|
1308
1333
|
return { events, result: { status: "paused", sessionId, lastSeq, reason, interruptions, state } };
|
|
1309
1334
|
};
|
|
1310
1335
|
const spendInto = (ctx) => (usage) => {
|
|
@@ -1767,7 +1792,7 @@ async function* executeToolCalls(ctx, calls, timeline, deps) {
|
|
|
1767
1792
|
};
|
|
1768
1793
|
const decisions = /* @__PURE__ */ new Map();
|
|
1769
1794
|
const requested = /* @__PURE__ */ new Set();
|
|
1770
|
-
const started =
|
|
1795
|
+
const started = toolStartedAt(timeline);
|
|
1771
1796
|
for (const raw of timeline) {
|
|
1772
1797
|
const e = raw;
|
|
1773
1798
|
if (e.type === "core.approval_decision") decisions.set(e.payload.toolCallId, e.payload);
|
|
@@ -1789,7 +1814,7 @@ async function* executeToolCalls(ctx, calls, timeline, deps) {
|
|
|
1789
1814
|
payload: { toolCallId, name, content: [{ type: "text", text }], isError: true }
|
|
1790
1815
|
});
|
|
1791
1816
|
if (started.has(toolCallId) && (tool === void 0 || !isReplayable(tool))) {
|
|
1792
|
-
yield* await settle(errorResult(
|
|
1817
|
+
yield* await settle(errorResult(outcomeUnknownText(tool, started.get(toolCallId))));
|
|
1793
1818
|
continue;
|
|
1794
1819
|
}
|
|
1795
1820
|
const decided = decisions.get(toolCallId);
|
|
@@ -1868,11 +1893,14 @@ async function* executeToolCalls(ctx, calls, timeline, deps) {
|
|
|
1868
1893
|
const replayable = isReplayable(tool);
|
|
1869
1894
|
const markStarted = async function* () {
|
|
1870
1895
|
if (started.has(toolCallId)) return;
|
|
1871
|
-
started.add(toolCallId);
|
|
1872
1896
|
yield* await flush();
|
|
1873
|
-
|
|
1897
|
+
const [ev] = await append([
|
|
1874
1898
|
{ type: "core.tool_started", actor: "system", parentId: call.id, payload: { toolCallId } }
|
|
1875
1899
|
]);
|
|
1900
|
+
if (ev) {
|
|
1901
|
+
started.set(toolCallId, ev.at);
|
|
1902
|
+
yield ev;
|
|
1903
|
+
}
|
|
1876
1904
|
};
|
|
1877
1905
|
if (!replayable) yield* markStarted();
|
|
1878
1906
|
let result;
|
|
@@ -1898,7 +1926,7 @@ async function* executeToolCalls(ctx, calls, timeline, deps) {
|
|
|
1898
1926
|
};
|
|
1899
1927
|
} catch (err) {
|
|
1900
1928
|
result = errorResult(
|
|
1901
|
-
!replayable && cfg.signal?.aborted ?
|
|
1929
|
+
!replayable && cfg.signal?.aborted ? outcomeUnknownText(tool, started.get(toolCallId)) : `Tool execution failed: ${errorMessageOf(err)}`
|
|
1902
1930
|
);
|
|
1903
1931
|
}
|
|
1904
1932
|
for (const s of sockets) {
|
|
@@ -2183,7 +2211,7 @@ function memoryStore() {
|
|
|
2183
2211
|
}
|
|
2184
2212
|
|
|
2185
2213
|
// src/index.ts
|
|
2186
|
-
var REINS_VERSION = "0.
|
|
2214
|
+
var REINS_VERSION = "0.13.0";
|
|
2187
2215
|
export {
|
|
2188
2216
|
BUILTIN_APPROVAL_POLICY,
|
|
2189
2217
|
CORE_SCHEMAS,
|
|
@@ -2262,6 +2290,8 @@ export {
|
|
|
2262
2290
|
memoryStore,
|
|
2263
2291
|
needsUntrustedMark,
|
|
2264
2292
|
normalizeToolOutput,
|
|
2293
|
+
outcomeUnknownText,
|
|
2294
|
+
pausedStateOf,
|
|
2265
2295
|
pendingToolCalls,
|
|
2266
2296
|
project,
|
|
2267
2297
|
readEvents,
|
|
@@ -2287,6 +2317,7 @@ export {
|
|
|
2287
2317
|
toolCallArgumentsMeta,
|
|
2288
2318
|
toolResultTrust,
|
|
2289
2319
|
toolSpecOf,
|
|
2320
|
+
toolStartedAt,
|
|
2290
2321
|
toolsBoundDrafts,
|
|
2291
2322
|
untrustedOpenTag,
|
|
2292
2323
|
untrustedSourceOf,
|
|
@@ -2294,6 +2325,7 @@ export {
|
|
|
2294
2325
|
uuidv7,
|
|
2295
2326
|
validateResume,
|
|
2296
2327
|
verifyRunState,
|
|
2297
|
-
visibilityFilter
|
|
2328
|
+
visibilityFilter,
|
|
2329
|
+
withStartedAt
|
|
2298
2330
|
};
|
|
2299
2331
|
//# sourceMappingURL=index.js.map
|