@reinsjs/core 0.10.0 → 0.12.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 +12 -0
- package/README.md +37 -1
- package/dist/core-h3S4jFh-.d.ts +1256 -0
- package/dist/index.d.ts +10 -554
- package/dist/index.js +93 -7
- 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
|
@@ -917,6 +917,17 @@ function assertRunStateShape(raw) {
|
|
|
917
917
|
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
918
|
if (!ok) throw new RunStateError("malformed", "run state is not in the v1 shape");
|
|
919
919
|
}
|
|
920
|
+
function pausedStateOf(event) {
|
|
921
|
+
if (event?.type !== "core.run_paused") return void 0;
|
|
922
|
+
const state = event.payload.state;
|
|
923
|
+
if (state === void 0) return void 0;
|
|
924
|
+
try {
|
|
925
|
+
assertRunStateShape(state);
|
|
926
|
+
} catch {
|
|
927
|
+
return void 0;
|
|
928
|
+
}
|
|
929
|
+
return state;
|
|
930
|
+
}
|
|
920
931
|
async function validateResume(input) {
|
|
921
932
|
const { state } = input;
|
|
922
933
|
assertRunStateShape(state);
|
|
@@ -1199,6 +1210,35 @@ function inputDrafts(input) {
|
|
|
1199
1210
|
}
|
|
1200
1211
|
return [checkInputDraft(input)];
|
|
1201
1212
|
}
|
|
1213
|
+
var PULLED_DRAFT_TYPES = /* @__PURE__ */ new Set(["core.user_message", "core.system_note"]);
|
|
1214
|
+
function checkPulledDrafts(value, registry) {
|
|
1215
|
+
if (!Array.isArray(value)) {
|
|
1216
|
+
throw new RangeError(`pullInput must return an array of event drafts, got ${describe(value)}`);
|
|
1217
|
+
}
|
|
1218
|
+
return value.map((raw) => {
|
|
1219
|
+
const draft = typeof raw === "object" && raw !== null ? raw : {};
|
|
1220
|
+
const type = draft.type;
|
|
1221
|
+
if (typeof type !== "string" || !PULLED_DRAFT_TYPES.has(type) && !type.startsWith("ext.")) {
|
|
1222
|
+
throw new RangeError(
|
|
1223
|
+
`pullInput draft rejects event type ${String(type)}: only core.user_message, core.system_note or ext.* are accepted`
|
|
1224
|
+
);
|
|
1225
|
+
}
|
|
1226
|
+
checkInputDraft(draft);
|
|
1227
|
+
if (!registry.has(type)) throw new RangeError(`pullInput draft type ${type} is not registered`);
|
|
1228
|
+
return draft;
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
function describeThrown(value) {
|
|
1232
|
+
if (value instanceof Error) return value.message;
|
|
1233
|
+
try {
|
|
1234
|
+
return String(value);
|
|
1235
|
+
} catch {
|
|
1236
|
+
return "a value that cannot be printed";
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
function describe(value) {
|
|
1240
|
+
return value === null ? "null" : typeof value;
|
|
1241
|
+
}
|
|
1202
1242
|
function isInputArray(input) {
|
|
1203
1243
|
return Array.isArray(input);
|
|
1204
1244
|
}
|
|
@@ -1262,20 +1302,20 @@ async function* runLoop(cfg) {
|
|
|
1262
1302
|
const reason = texts ? "host" : requested;
|
|
1263
1303
|
const interruptions = texts ? [{ kind: "host", note: texts.note }] : requestedInterruptions;
|
|
1264
1304
|
const settled = texts ? await settleStopped(texts) : [];
|
|
1265
|
-
const events = [
|
|
1266
|
-
...settled,
|
|
1267
|
-
...await append([{ type: "core.run_paused", actor: "system", payload: { reason } }])
|
|
1268
|
-
];
|
|
1269
1305
|
const pending = pendingToolCalls(await readTimeline(log, sessionId, { registry }));
|
|
1270
1306
|
const state = await serializeRunState({
|
|
1271
1307
|
sessionId,
|
|
1272
|
-
lastSeq,
|
|
1308
|
+
lastSeq: lastSeq + 1,
|
|
1273
1309
|
pending,
|
|
1274
1310
|
configHash,
|
|
1275
1311
|
model,
|
|
1276
1312
|
tools: baseTools,
|
|
1277
1313
|
...cfg.secret !== void 0 ? { secret: cfg.secret } : {}
|
|
1278
1314
|
});
|
|
1315
|
+
const events = [
|
|
1316
|
+
...settled,
|
|
1317
|
+
...await append([{ type: "core.run_paused", actor: "system", payload: { reason, state } }])
|
|
1318
|
+
];
|
|
1279
1319
|
return { events, result: { status: "paused", sessionId, lastSeq, reason, interruptions, state } };
|
|
1280
1320
|
};
|
|
1281
1321
|
const spendInto = (ctx) => (usage) => {
|
|
@@ -1359,7 +1399,52 @@ async function* runLoop(cfg) {
|
|
|
1359
1399
|
return result;
|
|
1360
1400
|
}
|
|
1361
1401
|
const turnStartedAt = now();
|
|
1362
|
-
|
|
1402
|
+
let timeline = await readTimeline(log, sessionId, { registry });
|
|
1403
|
+
if (cfg.pullInput !== void 0 && turns < maxTurns && pendingToolCalls(timeline).length === 0) {
|
|
1404
|
+
let raw = [];
|
|
1405
|
+
let thrown;
|
|
1406
|
+
try {
|
|
1407
|
+
raw = await cfg.pullInput({ sessionId, turn: turns + 1 });
|
|
1408
|
+
} catch (err) {
|
|
1409
|
+
thrown = { value: err };
|
|
1410
|
+
}
|
|
1411
|
+
if (cfg.signal?.aborted) continue;
|
|
1412
|
+
if (thrown !== void 0) {
|
|
1413
|
+
const errors = await append([
|
|
1414
|
+
{
|
|
1415
|
+
type: "core.error",
|
|
1416
|
+
actor: "system",
|
|
1417
|
+
payload: {
|
|
1418
|
+
category: "host",
|
|
1419
|
+
message: `pullInput threw: ${describeThrown(thrown.value)}`,
|
|
1420
|
+
retryable: true,
|
|
1421
|
+
detail: { phase: "pullInput" }
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
]);
|
|
1425
|
+
yield* errors;
|
|
1426
|
+
timeline = [...timeline, ...errors];
|
|
1427
|
+
} else {
|
|
1428
|
+
let pulled;
|
|
1429
|
+
try {
|
|
1430
|
+
pulled = checkPulledDrafts(raw, registry);
|
|
1431
|
+
} catch (err) {
|
|
1432
|
+
const { events, result } = await fail({
|
|
1433
|
+
category: "input",
|
|
1434
|
+
message: describeThrown(err),
|
|
1435
|
+
retryable: false,
|
|
1436
|
+
detail: { phase: "pullInput" }
|
|
1437
|
+
});
|
|
1438
|
+
yield* events;
|
|
1439
|
+
return result;
|
|
1440
|
+
}
|
|
1441
|
+
if (pulled.length > 0) {
|
|
1442
|
+
const written = await append(pulled);
|
|
1443
|
+
yield* written;
|
|
1444
|
+
timeline = [...timeline, ...written];
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1363
1448
|
const lastUsage = lastBudgetUsage(timeline)?.payload.tokens;
|
|
1364
1449
|
const projected = project({
|
|
1365
1450
|
timeline,
|
|
@@ -2109,7 +2194,7 @@ function memoryStore() {
|
|
|
2109
2194
|
}
|
|
2110
2195
|
|
|
2111
2196
|
// src/index.ts
|
|
2112
|
-
var REINS_VERSION = "0.
|
|
2197
|
+
var REINS_VERSION = "0.12.0";
|
|
2113
2198
|
export {
|
|
2114
2199
|
BUILTIN_APPROVAL_POLICY,
|
|
2115
2200
|
CORE_SCHEMAS,
|
|
@@ -2188,6 +2273,7 @@ export {
|
|
|
2188
2273
|
memoryStore,
|
|
2189
2274
|
needsUntrustedMark,
|
|
2190
2275
|
normalizeToolOutput,
|
|
2276
|
+
pausedStateOf,
|
|
2191
2277
|
pendingToolCalls,
|
|
2192
2278
|
project,
|
|
2193
2279
|
readEvents,
|