@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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @reinsjs/core
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e820efb: A paused run can now be resumed from a replay, not only from the stream that saw it pause. The signed resume state is written into the `core.run_paused` event (`payload.state`, model-invisible — the same object as `RunResult.state`), and a replay-only stream whose session ends at that pause carries it in the `end` frame (`state`); with `@reinsjs/ui-agui` it is `RUN_FINISHED.result.state` next to `status: "replayed"`. A page reloaded, reopened or opened on another device can therefore still approve or reject. The state is the one signed at the moment of the pause — never recomputed when read — so configuration drift is still caught. The frame carries the state of the latest pause whatever its reason (approval, budget, abort, stop); decide whether to show an approval card from `state.pendingToolCallIds` and the replayed `core.approval_request` events — after a stop the list is empty. New helper `pausedStateOf(lastEvent)` in `@reinsjs/core` returns the state when the given (last) event is such a pause.
8
+
9
+ ## 0.11.0
10
+
11
+ ### Minor Changes
12
+
13
+ - b79d193: Add `pullInput` for input that arrives while a run is going. The loop calls it before every model call (not on a turn that only finishes leftover tool calls, not once `maxTurns` is reached) and appends the returned drafts ahead of that turn's socket notes. Only `core.user_message`, `core.system_note` and `ext.*` are accepted; a malformed return value ends the run with `status: "error"` (`core.error` category `input`) and writes none of the batch; a throwing callback is recorded as a model-invisible `core.error` (category `host`) and the run carries on; drafts pulled after an abort are not written. `agent.run()` passes it through. It is per run: `AgentDefinition` (and so `createAgent` options) now omits `pullInput`, so the HTTP handler and `asTool` sub-agents never pull.
14
+
3
15
  ## 0.10.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -37,7 +37,7 @@ type RunResult =
37
37
  | { status: "error"; sessionId; lastSeq; error }
38
38
  ```
39
39
 
40
- Pausing is a return value, not a blocking callback. `state` is small (ids and hashes, HMAC-signed when you pass `secret`) and enough to resume in another process: `runLoop({ ...config, resume: state, decisions: [...] })` re-validates it against the log (signature, pending-call digest, and that the model and the definitions of the tools behind the pending calls are unchanged — adding or removing other tools no longer blocks a resume; the model is told about the change instead) before writing anything.
40
+ Pausing is a return value, not a blocking callback. `state` is small (ids and hashes, HMAC-signed when you pass `secret`) and enough to resume in another process: `runLoop({ ...config, resume: state, decisions: [...] })` re-validates it against the log (signature, pending-call digest, and that the model and the definitions of the tools behind the pending calls are unchanged — adding or removing other tools no longer blocks a resume; the model is told about the change instead) before writing anything. The same signed `state` is also written into the `core.run_paused` event (model-invisible), so whoever reads the log later can resume too: `pausedStateOf(lastEvent)` returns it when the session's last event is that pause, and `undefined` once anything else has been appended.
41
41
 
42
42
  **Stopping vs. aborting.** Aborting `signal` for any reason pauses the run and leaves unanswered tool calls pending, so the next run executes them first — right for a lost lease or a dropped connection. When the *user* pressed stop, abort with `controller.abort(new RunStop())` instead: every pending call (including ones waiting for approval or for a client result) is closed with an error result saying it was not executed, and the next run asks the model directly, so it can follow whatever the user says next. The result is still `paused` with reason `host` and the note `stopped by the user`.
43
43
 
@@ -61,6 +61,42 @@ runLoop({ ...config, input: briefedInput("Ticket #12 was edited by Ana an hour a
61
61
 
62
62
  Every draft goes through the same checks — type whitelist (`core.user_message`, `core.tool_result`, `core.system_note`, `ext.*`), a valid actor, the basic payload shape of the three core types, and registration in your registry — and one bad draft rejects the whole batch before anything is written; content parts cannot be mixed with drafts. The envelope (`actor`, `trust`) and the shape of your own `ext.*` payloads are yours to get right: in-process input is trusted host code. Keep one user message per batch: compaction keeps only the most recent one verbatim, while background notes fold like any other note (put what must stay in a pin). Lowering keeps the order on Chat and Responses; on Anthropic models that accept mid-conversation system messages the note lands right after the user message, because a system message may not come first or follow an assistant one. The HTTP handler in `@reinsjs/server` does not accept draft arrays — this is for in-process hosts.
63
63
 
64
+ ## Input that arrives mid-run
65
+
66
+ A run can take minutes. Messages that reach your host meanwhile (a teammate changed direction, someone signed off a plan) can be handed to the model before its next call instead of waiting for the run to end. Pass `pullInput`: the loop calls it before every model call — not on a turn that only finishes leftover tool calls, and not once `maxTurns` is reached — and appends whatever drafts it returns, ahead of that turn's socket notes. Your queue stays the source of truth: offer what is waiting, and claim a delivery only when its event comes back out of the loop.
67
+
68
+ ```ts
69
+ /** A host mailbox: offer everything unclaimed at each gap; claim when the loop has written it. */
70
+ function mailbox() {
71
+ const waiting = new Map<string, string>()
72
+ return {
73
+ post(id: string, text: string) {
74
+ waiting.set(id, text)
75
+ },
76
+ pullInput: (): EventDraft[] =>
77
+ [...waiting].map(([id, text]) => ({
78
+ type: "core.user_message",
79
+ actor: "user",
80
+ provenance: { source: "mailbox", ref: id },
81
+ payload: { content: [{ type: "text", text }] },
82
+ })),
83
+ claim(event: Event) {
84
+ if (event.provenance?.source === "mailbox" && event.provenance.ref) waiting.delete(event.provenance.ref)
85
+ },
86
+ }
87
+ }
88
+
89
+ const box = mailbox()
90
+ for await (const event of runLoop({ ...config, input: "Plan the shoot.", pullInput: box.pullInput })) box.claim(event)
91
+ ```
92
+
93
+ - Claim while handling the event, before asking the loop for the next one. If you only claim later, the next gap offers the same drafts again and they are written twice.
94
+ - Only `core.user_message`, `core.system_note` and `ext.*` are accepted here (no `core.tool_result`: there is no open call to answer at that point). A return value that is not an array, or holds anything else, ends the run with `status: "error"` and writes none of the batch. If the callback throws, the loop records a `core.error` the model cannot see and carries on; the messages are still in your queue. If the run is aborted while you were pulling, the drafts are not written.
95
+ - Anything that arrives after the last pull is not part of this run: check your queue once more when the run returns. A callback that never settles stalls the run, so put your own timeout on it.
96
+ - A run that absorbs follow-ups lives longer: per-run budget limits (turns, wall time, tokens) trip sooner.
97
+ - On Anthropic models that accept mid-conversation system messages, a mid-run `system_note` follows a tool result, so it becomes a real system message placed after the user message; at the start of a run it usually follows an assistant reply and is sent as tagged user text instead.
98
+ - `pullInput` is per run: `runLoop` and `agent.run()` take it; agent definitions, the HTTP handler and `asTool` sub-agents do not.
99
+
64
100
  ## Tools
65
101
 
66
102
  ```ts