@ai-matrx/agents 0.2.1 → 0.5.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 +62 -3
- package/README.md +68 -6
- package/dist/index.cjs +831 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +803 -50
- package/dist/index.js.map +1 -1
- package/dist/matrx/index.cjs +747 -0
- package/dist/matrx/index.cjs.map +1 -0
- package/dist/matrx/index.d.cts +691 -0
- package/dist/matrx/index.d.ts +691 -0
- package/dist/matrx/index.js +723 -0
- package/dist/matrx/index.js.map +1 -0
- package/dist/projection/request.cjs +1 -1
- package/dist/projection/request.cjs.map +1 -1
- package/dist/projection/request.js +1 -1
- package/dist/projection/request.js.map +1 -1
- package/dist/projection/workflow.cjs +145 -18
- package/dist/projection/workflow.cjs.map +1 -1
- package/dist/projection/workflow.d.cts +18 -1
- package/dist/projection/workflow.d.ts +18 -1
- package/dist/projection/workflow.js +145 -19
- package/dist/projection/workflow.js.map +1 -1
- package/dist/stream/ndjson.cjs +143 -30
- package/dist/stream/ndjson.cjs.map +1 -1
- package/dist/stream/ndjson.d.cts +42 -7
- package/dist/stream/ndjson.d.ts +42 -7
- package/dist/stream/ndjson.js +142 -31
- package/dist/stream/ndjson.js.map +1 -1
- package/dist/stream/sse.cjs +69 -0
- package/dist/stream/sse.cjs.map +1 -0
- package/dist/stream/sse.d.cts +76 -0
- package/dist/stream/sse.d.ts +76 -0
- package/dist/stream/sse.js +65 -0
- package/dist/stream/sse.js.map +1 -0
- package/package.json +22 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,77 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0 — 2026-08-29
|
|
4
|
+
|
|
5
|
+
- Added `@ai-matrx/agents/matrx` — the Matrx API client: run an agent
|
|
6
|
+
end-to-end against the AI Matrx server over ONE injected, fetch-shaped
|
|
7
|
+
`MatrxTransport` port (base URL, credentials, org header, retry, and
|
|
8
|
+
diagnostics stay the host's job — this package never implements auth).
|
|
9
|
+
- The conversation-start contract as a discriminated union (client-minted
|
|
10
|
+
`conversation_id`, `is_new`, `store`; ephemeral `prior_messages` is only
|
|
11
|
+
representable with `store: false`) plus builders for all four cells.
|
|
12
|
+
- Run lifecycle: `startAgentRun` (`POST /ai/agents/{id}`),
|
|
13
|
+
`continueAgentConversation`, `resumeAgentConversation`, `cancelAgentRun`
|
|
14
|
+
(`X-Request-ID` only), and `runAgentToCompletion` — every stream parsed
|
|
15
|
+
through the package's own NDJSON kernel; `stream: true` is forced so a
|
|
16
|
+
caller flag can never flip the response off NDJSON. `X-Request-ID` /
|
|
17
|
+
`X-Conversation-ID` surface on the handle before any event.
|
|
18
|
+
- Reconnect surface: identify by request id or feature link, durable
|
|
19
|
+
seq-cursored event pages, `followRuntimeOperationEvents` (SSE
|
|
20
|
+
replay-then-follow with `Last-Event-ID`, riding `stream/sse`; comment
|
|
21
|
+
heartbeats and malformed frames surface as liveness, terminal `end`
|
|
22
|
+
carries the root status), and `rejoinRuntimeOperation` (replay the
|
|
23
|
+
original NDJSON response; 409 = fall back to the lifecycle stream).
|
|
24
|
+
- Delegated tools: `submitAgentToolResults` (idempotent; the
|
|
25
|
+
`continuation_needed` signal for `/resume`), per-conversation and
|
|
26
|
+
per-user pending-call discovery with optional instance claim.
|
|
27
|
+
- `MatrxApiError` preserves the server's structured error body and extracts
|
|
28
|
+
its richest message/code (`user_message` → `message` → joined details →
|
|
29
|
+
FastAPI `detail` shapes).
|
|
30
|
+
- Every route, header, and response shape verified against the aidream
|
|
31
|
+
server source (routers `agents`/`conversations`/`cancel`/
|
|
32
|
+
`runtime_operations`, matrx-connect's streaming response headers).
|
|
33
|
+
|
|
34
|
+
## 0.4.0 — 2026-08-28
|
|
35
|
+
|
|
36
|
+
- Added `@ai-matrx/agents/stream/sse` — the pure incremental `text/event-stream`
|
|
37
|
+
frame kernel (`createMatrxSseFramer`, `parseMatrxSseFrame`,
|
|
38
|
+
`readMatrxSseStream`). Extracted from the two identical hand-rolled parsers in
|
|
39
|
+
the Matrix rejoin paths; covers all three SSE line/frame terminators by
|
|
40
|
+
construction (the production CRLF incident), byte-split UTF-8, comment
|
|
41
|
+
heartbeats as liveness-bearing frames, integer `id:` surfaced as the
|
|
42
|
+
`Last-Event-ID` cursor, and unterminated tails reported as diagnostics rather
|
|
43
|
+
than delivered as events. Host policy (fetch, stall timers, retry budgets,
|
|
44
|
+
cursor advancement) deliberately stays host-side.
|
|
45
|
+
|
|
46
|
+
## 0.3.0 — 2026-08-24
|
|
47
|
+
|
|
48
|
+
- Added a transport-independent incremental NDJSON framer for fragmented text
|
|
49
|
+
and bytes, including split UTF-8 and unterminated trailing input.
|
|
50
|
+
- Added exact valid-envelope observation, physical-line malformed diagnostics,
|
|
51
|
+
cancellation proof, bounded configurable read-ahead, and ordered partial
|
|
52
|
+
transport failure behavior.
|
|
53
|
+
- Preserved top-level `stream_seq` through wire normalization so projector
|
|
54
|
+
replay suppression receives the server's transport sequence.
|
|
55
|
+
- Aligned tool status semantics with execution: server `tool_started` remains
|
|
56
|
+
streaming; only `tool_delegated` suspends for client work.
|
|
57
|
+
- Bounded workflow render-block assembly by open sets, frames, and UTF-8 bytes;
|
|
58
|
+
malformed or invalid completions now produce typed diagnostics instead of
|
|
59
|
+
disappearing silently.
|
|
60
|
+
- Expanded TypeScript checking to include every projection source and test.
|
|
61
|
+
|
|
3
62
|
## 0.2.1 — 2026-08-24
|
|
4
63
|
|
|
5
64
|
- Published the documented workflow projection entry point that workspace
|
|
6
65
|
consumers already used but the immutable 0.2.0 registry artifact omitted.
|
|
66
|
+
- Added the portable workflow `node_stream` projection inlet with strict
|
|
67
|
+
answer/reasoning separation, bounded render-block assembly, replay
|
|
68
|
+
suppression, and shadowed-text state.
|
|
7
69
|
- Added every request and workflow projection test to the normal package test
|
|
8
70
|
gate; the previous Vitest include list silently ran only stream and
|
|
9
71
|
presentation tests.
|
|
10
72
|
|
|
11
73
|
## 0.2.0 — 2026-08-22
|
|
12
74
|
|
|
13
|
-
- Added the portable workflow `node_stream` projection inlet with strict
|
|
14
|
-
answer/reasoning separation, bounded render-block assembly, replay
|
|
15
|
-
suppression, and shadowed-text state.
|
|
16
75
|
- Added a framework-free request event projector for identity, status, answer/reasoning, phases, operations, tools, render blocks, Content IR metadata, completion, and errors.
|
|
17
76
|
- Added golden lifecycle fixtures, replay suppression, and copy-on-write guarantees.
|
|
18
77
|
- Added conditional ESM/CommonJS artifacts and loader canaries for mixed Vite, Next.js, and Jest consumers.
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @ai-matrx/agents
|
|
2
2
|
|
|
3
|
-
Portable client-side primitives for AI Matrx agent applications.
|
|
4
|
-
|
|
5
|
-
Creator-facing result
|
|
3
|
+
Portable client-side primitives for AI Matrx agent applications. The package
|
|
4
|
+
standardizes the stream wire, pure request/workflow projection, and safe
|
|
5
|
+
Creator-facing result boundaries without importing React, Redux, Next.js, or
|
|
6
6
|
application code.
|
|
7
7
|
|
|
8
8
|
## Install
|
|
@@ -25,8 +25,30 @@ for await (const envelope of readMatrxNdjsonStream(response.body!, {
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
The reader preserves split UTF-8, drains the network independently of consumer
|
|
28
|
-
work
|
|
29
|
-
reports malformed or unknown
|
|
28
|
+
work up to the configurable `maxReadAhead` bound, supports cancellation,
|
|
29
|
+
normalizes full and compact Matrx envelopes, and reports malformed or unknown
|
|
30
|
+
input through explicit callbacks. `onValidEnvelope` observes the exact parsed
|
|
31
|
+
wire value before normalization without consuming it. Full-envelope
|
|
32
|
+
`stream_seq` is preserved for projector replay suppression.
|
|
33
|
+
|
|
34
|
+
## Frame non-ReadableStream transports
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { createMatrxNdjsonFramer } from "@ai-matrx/agents/stream/ndjson";
|
|
38
|
+
|
|
39
|
+
const framer = createMatrxNdjsonFramer({
|
|
40
|
+
onMalformedLine: reportProtocolDamage,
|
|
41
|
+
onValidEnvelope: persistRawEnvelope,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
handleEvents(framer.pushBytes(extensionMessageBytes));
|
|
45
|
+
handleEvents(framer.pushText(desktopBridgeFragment));
|
|
46
|
+
handleEvents(framer.finish());
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The same incremental framer works with browser-extension messages, desktop
|
|
50
|
+
bridges, WebSockets, and tests. `finish()` flushes split UTF-8 and diagnoses an
|
|
51
|
+
invalid unterminated final line with `atCompletion: true`.
|
|
30
52
|
|
|
31
53
|
## Present a settled result safely
|
|
32
54
|
|
|
@@ -55,7 +77,47 @@ node = projectWorkflowNodeEvent(node, nodeStreamFrame);
|
|
|
55
77
|
This is the single workflow presentation inlet. It keeps answer and private
|
|
56
78
|
reasoning separate, rejects replayed frames, assembles bounded server
|
|
57
79
|
`render_block` snapshots, and prevents shadowed text from being interpreted as
|
|
58
|
-
a second copy of the same content.
|
|
80
|
+
a second copy of the same content. Configure `maxOpenFrameSets`,
|
|
81
|
+
`maxFramesPerBlock`, and `maxBytesPerBlock` when creating the projection;
|
|
82
|
+
rejected or malformed blocks are observable through `lastRenderBlockIssue`.
|
|
83
|
+
|
|
84
|
+
## Run an agent end-to-end (`./matrx`)
|
|
85
|
+
|
|
86
|
+
The `@ai-matrx/agents/matrx` subpath is the Matrx API client. You inject ONE
|
|
87
|
+
fetch-shaped transport — base URL, credentials (user JWT, guest fingerprint,
|
|
88
|
+
or API key), the org header, and retry policy are yours; the package owns the
|
|
89
|
+
wire semantics (paths, bodies, streaming headers, the `Last-Event-ID` cursor):
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import {
|
|
93
|
+
newEphemeralConversationStart,
|
|
94
|
+
runAgentToCompletion,
|
|
95
|
+
type MatrxTransport,
|
|
96
|
+
} from "@ai-matrx/agents/matrx";
|
|
97
|
+
|
|
98
|
+
const transport: MatrxTransport = {
|
|
99
|
+
fetch: (path, init) =>
|
|
100
|
+
fetch(`https://server.app.matrxserver.com${path}`, {
|
|
101
|
+
...init,
|
|
102
|
+
headers: { ...init.headers, Authorization: `Bearer ${token}` },
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const run = await runAgentToCompletion(transport, agentId, {
|
|
107
|
+
...newEphemeralConversationStart(),
|
|
108
|
+
organization_id: orgId,
|
|
109
|
+
user_input: "Summarize this quarter's numbers.",
|
|
110
|
+
}, { onChunk: (text) => render(text) });
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Lower-level pieces: `startAgentRun` / `continueAgentConversation` /
|
|
114
|
+
`resumeAgentConversation` return a `MatrxRunHandle` (`X-Request-ID` and
|
|
115
|
+
`X-Conversation-ID` before any event, plus the normalized envelope stream);
|
|
116
|
+
`cancelAgentRun` stops a run by its server request id;
|
|
117
|
+
`getRuntimeOperationStatus` / `listRuntimeOperationEvents` /
|
|
118
|
+
`followRuntimeOperationEvents` / `rejoinRuntimeOperation` are the reconnect
|
|
119
|
+
ladder; `submitAgentToolResults` + pending-call discovery drive delegated
|
|
120
|
+
client tools (watch `continuation_needed` → `resumeAgentConversation`).
|
|
59
121
|
|
|
60
122
|
## Runtime support
|
|
61
123
|
|