@arnilo/prism 0.5.4 → 0.5.5
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 +5 -0
- package/README.md +10 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/run-limits.js +7 -2
- package/docs/credential-storage.md +1 -1
- package/docs/graft.md +1 -1
- package/docs/{0.1.0-readiness.md → history/0.1.0-readiness.md} +6 -6
- package/docs/history/README.md +11 -0
- package/docs/{migrate-to-0.4.md → history/migrate-to-0.4.md} +4 -4
- package/docs/history/migration-0.0.md +738 -0
- package/docs/history/migration-0.1.md +151 -0
- package/docs/history/migration-0.2.md +173 -0
- package/docs/history/migration-0.3.md +39 -0
- package/docs/history/migration-0.4.md +6 -0
- package/docs/{persistence-credentials-multimodality-primitives.md → history/persistence-credentials-multimodality-primitives.md} +13 -13
- package/docs/history/release-handoffs.md +848 -0
- package/docs/{workflow-orchestration-primitives.md → history/workflow-orchestration-primitives.md} +11 -11
- package/docs/host-security.md +1 -1
- package/docs/index.md +157 -143
- package/docs/migrate-to-0.5.md +1 -1
- package/docs/migration.md +15 -1042
- package/docs/multimodal-content.md +1 -1
- package/docs/performance.md +1 -1
- package/docs/postgres-persistence.md +1 -1
- package/docs/provider-packages.md +20 -20
- package/docs/release-and-install.md +57 -842
- package/docs/runs-and-usage.md +2 -2
- package/docs/session-stores-and-branching.md +1 -122
- package/docs/sqlite-persistence.md +1 -1
- package/docs/workflows.md +1 -1
- package/package.json +1 -1
- /package/docs/{workflow-tui-primitives.md → history/workflow-tui-primitives.md} +0 -0
package/docs/runs-and-usage.md
CHANGED
|
@@ -59,9 +59,9 @@ await session.run("Summarize", {
|
|
|
59
59
|
});
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
Defaults are the unconfigured fence (OWASP LLM10): turns 16, provider attempts 24, tool rounds 8, tool calls 32, wall time 120 seconds, request and response bytes 8 MiB each, input tokens 40,000, output tokens 10,000, total tokens 50,000. Hard process ceilings exist only for request/response bytes (64 MiB each), so a bug cannot OOM the host through a giant provider frame; those two axes reject `null
|
|
62
|
+
Defaults are the unconfigured fence (OWASP LLM10): turns 16, provider attempts 24, tool rounds 8, tool calls 32, wall time 120 seconds, request and response bytes 8 MiB each, input tokens 40,000, output tokens 10,000, total tokens 50,000. Hard process ceilings exist only for request/response bytes (64 MiB each), so a bug cannot OOM the host through a giant provider frame; those two axes reject `null` and are charged **per frame** (request payload, provider event), not as a run-lifetime sum — a 2 MiB prompt sent forty times is 2 MiB frames, not an 80 MiB parse. Snapshots still report the cumulative `requestBytes`/`responseBytes` counters for telemetry. Every other axis is host policy (0.5.4): omit a key for the default, set a positive safe integer sized to the workload, or set `null` to disable the axis — overnight sessions raise turns/wall/tokens, and a disabled wall still honors `RunOptions.signal`. Resolution stays narrowing-only: `RunOptions.limits` may lower `AgentConfig.limits`, `null` acts as +Infinity (agent 16 + run `null` → 16), and a raised/disabled `maxTurns` lifts an omitted `maxProviderAttempts` (default 24) to at least `maxTurns` so attempts cannot undercut turns; explicitly set attempts values are lifted only when both are finite. Cumulative token counters are billed usage across the whole run, not the context window (`contextBudget` governs window compaction). For production, prefer an explicit `maxCost`: cost needs a finite non-negative amount plus one currency, and when cost is limited, absent, non-finite, or mixed-currency provider cost fails closed. Vendors that omit usage charge zero to the token counters (local/Ollama report none), so a configured `maxCost` is the fail-closed envelope for usage-less vendors.
|
|
63
63
|
|
|
64
|
-
Prism charges turns before assembly, provider attempts
|
|
64
|
+
Prism charges turns before assembly, provider attempts before generation, request bytes per request payload, response bytes per provider event (each frame must fit the byte cap on its own), tool rounds before a batch, tool calls before dispatch, and usage before another turn. A breach stops new work, aborts active work through the run signal, emits exactly one redacted `run_limit_exceeded` event/ledger row, and throws `AgentRunError` with `result.limit` (`limit`, `maximum`, `observed`, optional `currency`). Provider-reported token/cost totals arrive after generation, so that completed provider turn can be the unavoidable overshoot boundary.
|
|
65
65
|
|
|
66
66
|
`createRunLimitTracker()` and `resolveRunLimits()` are public for adapters that need the same validation and accounting semantics. Workflow agent nodes forward `RunWorkflowOptions.limits`; supervisor delegation narrows its step/tool/token/timeout budget into core limits; MCP tool calls use a per-call tracker.
|
|
67
67
|
|
|
@@ -1,124 +1,3 @@
|
|
|
1
1
|
# Session stores and branching
|
|
2
2
|
|
|
3
|
-
> Compatibility
|
|
4
|
-
|
|
5
|
-
## What it does
|
|
6
|
-
|
|
7
|
-
Session store helpers define branch-aware session entries and pure utilities for creating entries, listing branch leaves, reading a leaf path, and rebuilding provider context from a selected leaf. For atomic append options, `SessionAppendConflictError`, branch handles, and production `readBranchPath` guidance, start with [Session stores](session-stores.md#atomic-append-and-branch-handles).
|
|
8
|
-
|
|
9
|
-
Public helpers:
|
|
10
|
-
|
|
11
|
-
- `createSessionEntry(options)`
|
|
12
|
-
- `createMemorySessionStore(initialEntries?)`
|
|
13
|
-
- `getSessionBranchEntries(entries, options)` and `getSessionBranchEntries(reader, query)`
|
|
14
|
-
- `listSessionBranches(entries)`
|
|
15
|
-
- `rebuildSessionContext(entries, options)` and `rebuildSessionContext(reader, query)`
|
|
16
|
-
|
|
17
|
-
## When to use it
|
|
18
|
-
|
|
19
|
-
Use these helpers when a host, runtime session, or store adapter needs durable, branch-aware session data without coupling stores to providers, tools, credentials, or files.
|
|
20
|
-
|
|
21
|
-
Do not use them as a database layer, migration system, lock service, compaction strategy, retry policy, CLI/RPC protocol, or hidden global store registry.
|
|
22
|
-
|
|
23
|
-
## Inputs / request
|
|
24
|
-
|
|
25
|
-
`SessionEntry` has stable branch fields plus typed payloads:
|
|
26
|
-
|
|
27
|
-
| Field | Purpose |
|
|
28
|
-
| --- | --- |
|
|
29
|
-
| `id` | Unique entry id. |
|
|
30
|
-
| `parentId` | Previous entry on the branch, if any. |
|
|
31
|
-
| `sessionId` | Session that owns the entry. |
|
|
32
|
-
| `timestamp` | ISO timestamp chosen by the caller/helper. |
|
|
33
|
-
| `kind` | `message`, `event`, `summary`, `metadata`, `model_change`, `label`, `custom`, or `compaction`. |
|
|
34
|
-
| `runId` | Optional run id. |
|
|
35
|
-
| `message`, `event`, `model`, `previousModel`, `label`, `summary`, `data`, `metadata` | Optional payload fields for the entry kind. |
|
|
36
|
-
|
|
37
|
-
`rebuildSessionContext()` and `getSessionBranchEntries()` accept an optional `leafId`. If omitted, the last entry is used as the leaf. The async reader overloads accept `SessionBranchRead { sessionId, leafId?, cursor?, limit? }` and call a `BranchReader` / `readBranchPath` implementation so database adapters can return one ancestor chain without `list(sessionId)`. `createMemorySessionStore()` accepts optional initial entries.
|
|
38
|
-
|
|
39
|
-
## Outputs / response / events
|
|
40
|
-
|
|
41
|
-
| Helper | Output |
|
|
42
|
-
| --- | --- |
|
|
43
|
-
| `createSessionEntry()` | A `SessionEntry` with generated `id` and `timestamp` when omitted. |
|
|
44
|
-
| `getSessionBranchEntries()` | Ordered entries from root to selected leaf (deep copies). |
|
|
45
|
-
| `listSessionBranches()` | Leaf ids and their root-to-leaf entry paths (deep copies). |
|
|
46
|
-
| `rebuildSessionContext()` | `{ leafId, entries, messages, summaries }` for provider input rebuild; with a compaction entry, raw `entries` stay intact while `messages` becomes recent context and `summaries` includes the compaction summary. All arrays and objects are deep copies. |
|
|
47
|
-
| `createMemorySessionStore()` | Async `SessionStore` with `append()`, `list(sessionId)`, and `get(id)`. `list()` and `get()` return deep copies. |
|
|
48
|
-
|
|
49
|
-
Helpers throw on duplicate entry ids, unknown leaves, or missing parents. They do not mutate input arrays.
|
|
50
|
-
|
|
51
|
-
For `kind: "compaction"`, `data` may contain `throughEntryId`, `keepEntryIds`, `strategy`, and `trigger`. The latest valid compaction entry on a branch is used as the provider-context boundary; raw history remains in `entries`.
|
|
52
|
-
|
|
53
|
-
## Request/response example
|
|
54
|
-
|
|
55
|
-
```json
|
|
56
|
-
{
|
|
57
|
-
"leafId": "entry_2",
|
|
58
|
-
"messages": [{ "role": "user", "content": [{ "type": "text", "text": "Hi" }] }]
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Implementation example
|
|
63
|
-
|
|
64
|
-
```ts
|
|
65
|
-
import { createMemorySessionStore, createSessionEntry, rebuildSessionContext } from "@arnilo/prism";
|
|
66
|
-
|
|
67
|
-
const first = createSessionEntry({
|
|
68
|
-
id: "entry_1",
|
|
69
|
-
sessionId: "s1",
|
|
70
|
-
kind: "message",
|
|
71
|
-
message: { role: "user", content: [{ type: "text", text: "Hi" }] },
|
|
72
|
-
});
|
|
73
|
-
const label = createSessionEntry({
|
|
74
|
-
id: "entry_2",
|
|
75
|
-
parentId: first.id,
|
|
76
|
-
sessionId: "s1",
|
|
77
|
-
kind: "label",
|
|
78
|
-
label: "investigation",
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
const store = createMemorySessionStore([first]);
|
|
82
|
-
await store.append(label);
|
|
83
|
-
|
|
84
|
-
const context = rebuildSessionContext(await store.list("s1"), { leafId: label.id });
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## Extension and configuration notes
|
|
88
|
-
|
|
89
|
-
Stores and extensions can use these data helpers directly. Store adapters only need append/list/get behavior; branch queries are derived in memory from listed entries unless the store implements `readBranchPath`. See [Session stores](session-stores.md) for `SessionAppendOptions`, `SessionAppendConflictError`, and `(sessionId, leafId)` branch-handle guidance.
|
|
90
|
-
|
|
91
|
-
`createMemorySessionStore()` is the built-in in-memory implementation. It preserves append order per session, isolates session ids, returns entries by id in O(1), rejects duplicate entry ids, and returns deep copies from `list()` and `get()`. It is process memory only; hosts that need durability should pass another `SessionStore`.
|
|
92
|
-
|
|
93
|
-
`getSessionBranchEntries()` and `rebuildSessionContext()` also return deep copies of entries and messages, so callers cannot mutate the input arrays or the memory store by editing returned objects.
|
|
94
|
-
|
|
95
|
-
`AgentSession` uses `AgentSessionConfig.store` before `AgentConfig.store`, otherwise a private memory store. It appends user, assistant, tool-result, and model-change entries, resumes from `leafId`, rebuilds provider history from the selected branch, checks out old leaves, forks by selecting a leaf in the same session, and clones the selected branch to a new session id.
|
|
96
|
-
|
|
97
|
-
Node hosts that need simple file durability can import `createJsonlSessionStore()` from the explicit `@arnilo/prism/node/session-store-jsonl` subpath.
|
|
98
|
-
|
|
99
|
-
Use `createDefaultCompactionStrategy()` to create compaction entries that `rebuildSessionContext()` understands. Compaction adds summaries; it does not delete or rewrite raw store entries.
|
|
100
|
-
|
|
101
|
-
`createSessionEntry()` accepts injectable `createId` and `now` functions for deterministic tests or host id policy. Prism does not create a global store or id service.
|
|
102
|
-
|
|
103
|
-
## Security and performance notes
|
|
104
|
-
|
|
105
|
-
- Helpers are pure data functions: no provider calls, tool calls, settings reads, credential resolution, filesystem access, network access, timers, or dependencies.
|
|
106
|
-
- Store only host-approved session entries. Do not put provider credentials, credential resolvers, provider objects, full provider requests, or secrets in entries.
|
|
107
|
-
- Branch rebuild is linear over listed entries for development stores. Production stores should implement `readBranchPath` and return one branch ancestor chain so large sessions are not fully loaded.
|
|
108
|
-
- Compaction-aware rebuild keeps raw branch entries in `entries`; only provider-context `messages`/`summaries` are reduced.
|
|
109
|
-
- Memory store lookup by id is O(1); list is O(n) for that session.
|
|
110
|
-
- Duplicate ids and missing parents fail clearly instead of guessing a branch.
|
|
111
|
-
|
|
112
|
-
## Related APIs
|
|
113
|
-
|
|
114
|
-
- [Migration guide](migration.md): moving branch-handle reads from the dev `list(sessionId)` path to a database-backed `readBranchPath`.
|
|
115
|
-
- [Session stores](session-stores.md): canonical overview for `SessionAppendOptions`, `SessionAppendConflictError`, branch handles, and dev-vs-production branch reads.
|
|
116
|
-
- [Public contracts](public-contracts.md): `SessionEntry`, `SessionStore`, `StoreFactory`, and session contracts.
|
|
117
|
-
- [Agent/session runtime](agent-session-runtime.md): runtime sessions use these branch helpers for store-backed history, checkout, fork, and clone.
|
|
118
|
-
- [Node JSONL session store](node-jsonl-session-store.md): optional Node filesystem store for caller-named JSONL files.
|
|
119
|
-
- [Compaction and retry policies](compaction-and-retry.md): default strategy for creating compaction entries.
|
|
120
|
-
- [Input and prompt assembly](input-and-prompt-assembly.md): provider input assembly consumes rebuilt `messages` and `summaries`.
|
|
121
|
-
- [Credentials and redaction](credentials-and-redaction.md): security boundary for secrets that must not enter session entries.
|
|
122
|
-
- [Workflows](workflows.md): optional orchestration that reuses session `leafId` on resume rather than reloading full transcripts into the scheduler.
|
|
123
|
-
|
|
124
|
-
Session stores persist the entries they receive. Configure `AgentConfig.redactor` or `RunOptions.redactor` before a run when known secrets must be removed before entries reach durable stores.
|
|
3
|
+
> Compatibility stub: the canonical session-store overview — `SessionStore`, atomic append, `SessionAppendConflictError`, branch handles, and `readBranchPath` — lives at [Session stores](session-stores.md).
|
|
@@ -126,7 +126,7 @@ SQLite applies migrations **006**/**007** for per-run event sequence compatibili
|
|
|
126
126
|
- [Database persistence](database-persistence.md): shared schema model, conditional append pattern, indexes.
|
|
127
127
|
- [Session store conformance](session-store-conformance.md): `assertSessionStoreConforms` / `runSessionStoreConformance`.
|
|
128
128
|
- [Run ledger conformance](run-ledger-conformance.md): `assertRunLedgerConforms` / `runRunLedgerConformance`.
|
|
129
|
-
- [Persistence, credentials, and multimodality primitives](persistence-credentials-multimodality-primitives.md): package matrix and threat model.
|
|
129
|
+
- [Persistence, credentials, and multimodality primitives](history/persistence-credentials-multimodality-primitives.md): package matrix and threat model.
|
|
130
130
|
- [Node JSONL session store](node-jsonl-session-store.md): dev-only single-process alternative.
|
|
131
131
|
- [Workflows](workflows.md): adapt `persistence.checkpoints` and pass `persistence.leases` to `createWorkflowCoordinator()` and `createWorkflowSchedules()` for durable background execution and schedules.
|
|
132
132
|
- [Migration guide](migration.md): moving from JSONL/in-memory to database-backed persistence.
|
package/docs/workflows.md
CHANGED
|
@@ -432,7 +432,7 @@ Use workflows for known, durable, replayable graphs. Use optional supervisor del
|
|
|
432
432
|
## Related APIs
|
|
433
433
|
|
|
434
434
|
- Examples: `examples/workflow-research-and-review.ts`, `examples/workflow-parallel-research.ts`, `examples/workflow-tool-approval.ts`, `examples/workflow-multimodal-document.ts`, `examples/workflow-sqlite-resume.ts`, `examples/workflow-postgres-resume.ts`, `examples/workflow-event-sink.ts`, `examples/workflow-rpc-cancel.ts`, `examples/workflow-distributed-coordinator.ts`, `examples/autonomous-coding-loop.ts` (host-loop iterate-until-done) — offline runnable demos; PostgreSQL safely skips unless `PRISM_TEST_POSTGRES_URL` is set.
|
|
435
|
-
- [Workflow orchestration primitives](workflow-orchestration-primitives.md): Task 0–1 inventory and locked adapter contracts
|
|
435
|
+
- [Workflow orchestration primitives](history/workflow-orchestration-primitives.md): Task 0–1 inventory and locked adapter contracts
|
|
436
436
|
- [Agent/session runtime](agent-session-runtime.md): `AgentSession.run()`/`stream()`, abort, subscribe
|
|
437
437
|
- [Guardrails](guardrails.md): `RunWorkflowOptions.guardrails` routes tool nodes through core dispatch before policy and side effects.
|
|
438
438
|
- [Supervisor delegation](supervisors.md): bounded dynamic child selection.
|
package/package.json
CHANGED
|
File without changes
|