@godspeedai/cognate-ag-ui 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/README.md +95 -39
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,44 +1,100 @@
1
1
  # @godspeedai/cognate-ag-ui
2
2
 
3
- AG-UI 1.0.0 interoperability adapter (spec §24, §31.8, §32; ADR-0008). An
4
- optional boundary, not the internal event model: native Cognate execution
5
- and UI work unchanged if this package is removed (spec §40.H).
6
-
7
- - `createProjector` folds a run's durable event stream into schema-valid
8
- AG-UI events (bracketed text messages, tool calls, state snapshots/deltas,
9
- continuation CUSTOM events, RUN_FINISHED/RUN_ERROR).
10
- - `createAgUiHandler` is an HTTP endpoint: POST `RunAgentInput` → SSE stream.
11
- Actions (start, resolve a continuation, cancel) go through
12
- `RuntimeService` with the transport-authenticated caller. A valid
13
- `forwardedProps.cognate.cursor` resumes with `STATE_SNAPSHOT` + newer
14
- events; an unknown/expired cursor triggers a full resync
15
- (`RUN_STARTED`, `MESSAGES_SNAPSHOT`, `STATE_SNAPSHOT`, …). Disconnecting
16
- never cancels the durable run.
17
-
18
- ## Compatibility matrix (`matrix`, `ignoredFrameworkEvents`)
19
-
20
- All 31 AG-UI 1.0.0 `EventType` values are covered, one row each:
21
-
22
- - **Supported (outbound):** `RUN_STARTED`, `RUN_FINISHED`, `RUN_ERROR`,
23
- `TEXT_MESSAGE_*` (not `_CHUNK`), `TOOL_CALL_*` (not `_CHUNK`),
24
- `STATE_SNAPSHOT`, `STATE_DELTA`, `MESSAGES_SNAPSHOT`, `CUSTOM`.
25
- - **Unsupported (none):** the `_CHUNK` shorthands, `ACTIVITY_*`, `RAW`,
26
- `STEP_*`, `REASONING_*`, `SUBAGENT_*` — Cognate has no matching concept
27
- yet; each row's `note` says why.
28
- - `TOOL_CALL_ARGS` carries the recorded invocation input (`run.invocation`
29
- payload `input`; `{}` after that payload is erased).
30
-
31
- `ignoredFrameworkEvents` lists Cognate event types deliberately not
32
- projected: `run.step.completed`, `run.resumed`, `run.wait.closed`,
33
- `run.recall` (replay/determinism bookkeeping). Artifacts are projected as
34
- `CUSTOM` `cognate.artifact` events (AG-UI 1.0.0 has no artifact event).
3
+ AG-UI 1.0 interoperability adapter: projects a Cognate run's durable event stream as schema-valid AG-UI events over SSE, and maps inbound AG-UI actions (messages, tool results, approvals, cancellation) onto the runtime's `RuntimeService` with the transport-authenticated caller.
4
+
5
+ **When to use this package:** an [AG-UI](https://docs.ag-ui.com) client (or any SSE consumer speaking the AG-UI event grammar) should drive your Cognate agent. It is an optional boundary — native Cognate execution and UIs work unchanged without it, and Cognate's internal events are never rewritten as AG-UI aliases. For A2A agents see [`@godspeedai/cognate-a2a`](https://www.npmjs.com/package/@godspeedai/cognate-a2a).
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ bun add @godspeedai/cognate-ag-ui
11
+ ```
12
+
13
+ Requires [Bun](https://bun.sh) >= 1.4.0. Depends on `@ag-ui/core`, `@ag-ui/encoder`, and the service types from [`@godspeedai/cognate-runtime-api`](https://www.npmjs.com/package/@godspeedai/cognate-runtime-api); pair it with [`@godspeedai/cognate-runtime-bun`](https://www.npmjs.com/package/@godspeedai/cognate-runtime-bun) for the runtime itself.
14
+
15
+ ## Quick start
16
+
17
+ ```ts
18
+ import { createAgUiHandler } from "@godspeedai/cognate-ag-ui";
19
+ import { createRuntime } from "@godspeedai/cognate-runtime-bun";
20
+
21
+ const runtime = await createRuntime({
22
+ store: "./app.sqlite",
23
+ agents: [/* your AgentDefinitions */],
24
+ policy,
25
+ actions,
26
+ });
27
+
28
+ const handler = createAgUiHandler({
29
+ service: runtime.service,
30
+ defaultAgent: "agent.copilot", // agent started for new user messages
31
+ authenticate: (headers) => myBearerAuth(headers), // Caller | undefined
32
+ });
33
+
34
+ Bun.serve({ port: 3000, fetch: handler });
35
+ ```
36
+
37
+ A client POSTs an AG-UI `RunAgentInput` and reads the SSE stream:
38
+
39
+ ```ts
40
+ const response = await fetch("http://127.0.0.1:3000/", {
41
+ method: "POST",
42
+ headers: { "content-type": "application/json", authorization: "Bearer alice", accept: "text/event-stream" },
43
+ body: JSON.stringify({
44
+ threadId: "t-1",
45
+ runId: "r-1",
46
+ messages: [{ id: "m1", role: "user", content: "I was double charged" }],
47
+ tools: [],
48
+ context: [],
49
+ state: {},
50
+ forwardedProps: {},
51
+ }),
52
+ });
53
+ // response.body streams AG-UI events: RUN_STARTED, TEXT_MESSAGE_*, STATE_*, RUN_FINISHED, ...
54
+ ```
55
+
56
+ Unauthenticated requests get HTTP 401; a `ServiceError` from an inbound action arrives as a `RUN_ERROR` event carrying the service error code.
57
+
58
+ ## Inbound actions
59
+
60
+ The handler reads intent from the last user/tool message and from `forwardedProps.cognate`:
61
+
62
+ | Input | Action taken |
63
+ | --- | --- |
64
+ | last message with `role: "user"` | starts a run of `forwardedProps.cognate.agent` (or `defaultAgent`); message text and `context` become the run input; a non-empty `state` seeds shared state |
65
+ | last message with `role: "tool"` | resolves the frontend-capability or remote-offer continuation addressed by `toolCallId` with the parsed `content` |
66
+ | `forwardedProps.cognate.resolve` | resolves a continuation (`continuationId`, `action` `"resume"`/`"cancel"`, `input`, optional `expectedVersion`) |
67
+ | `forwardedProps.cognate.cancel` | cancels the thread's current run |
68
+ | `forwardedProps.cognate.cursor` | resumes the SSE stream from a durable event position |
69
+
70
+ All runs started for one AG-UI thread share a correlation id, so resolve/cancel/reconnect route to the thread's most recent run even after a server restart. An unknown or expired cursor triggers a full resync (`RUN_STARTED`, `MESSAGES_SNAPSHOT`, `STATE_SNAPSHOT`, then newer events). Disconnecting the HTTP stream never cancels the durable run.
35
71
 
36
72
  ## Continuation mapping
37
73
 
38
- A `frontend_capability` continuation (or `type: "frontend:<capability>"`,
39
- runtime-api's convention) becomes `TOOL_CALL_START/ARGS/END` with
40
- `toolCallId` = the continuation id. A `human_approval` continuation becomes
41
- `CUSTOM "cognate.continuation"`. Any other kind (e.g. `oauth_callback`) has
42
- no faithful AG-UI representation and becomes
43
- `CUSTOM "cognate.unsupported_interaction"`, and the run's `RUN_FINISHED`
44
- reports `status: "waiting_unsupported"` instead of `"waiting"`.
74
+ - A frontend-capability continuation (`type: "frontend:<capability>"`) projects as `TOOL_CALL_START`/`ARGS`/`END` with `toolCallId` set to the continuation id; the client's `role: "tool"` message resolves it.
75
+ - A `human_approval` continuation projects as a `CUSTOM` event named `cognate.continuation`, self-sufficient for a generic client to resolve via `forwardedProps.cognate.resolve`.
76
+ - Continuation kinds with no faithful AG-UI representation project as `CUSTOM` `cognate.unsupported_interaction`, and the run's `RUN_FINISHED` reports `status: "waiting_unsupported"` instead of `"waiting"`.
77
+ - Artifacts (AG-UI 1.0 has no artifact event) project as `CUSTOM` `cognate.artifact`.
78
+
79
+ ## Event coverage
80
+
81
+ `matrix` documents all 31 AG-UI 1.0 `EventType` values, one row each: which are produced outbound (`RUN_STARTED`/`RUN_FINISHED`/`RUN_ERROR`, `TEXT_MESSAGE_*`, `TOOL_CALL_*`, `STATE_SNAPSHOT`/`STATE_DELTA`, `MESSAGES_SNAPSHOT`, `CUSTOM`) and which Cognate cannot produce yet (the `_CHUNK` shorthands, `ACTIVITY_*`, `RAW`, `STEP_*`, `REASONING_*`, `SUBAGENT_*`), each with the reason. `ignoredFrameworkEvents` lists the Cognate event types deliberately not projected.
82
+
83
+ For direct use, `createProjector({ threadId, runId })` folds ordered durable events into AG-UI events (`push`, plus `snapshot()`/`stateOnly()` for reconnects), and `threadCorrelationId(threadId)` gives the correlation id grouping a thread's runs.
84
+
85
+ ## Limitations
86
+
87
+ - One adapter, one direction of truth: durable Cognate events are the source; AG-UI output is a projection. Nothing an AG-UI client sends writes history except through `RuntimeService` actions.
88
+ - Model text streaming arrives via `TEXT_MESSAGE_*`; there is no reasoning/thinking channel, subagent nesting, or raw event passthrough.
89
+ - `TOOL_CALL_ARGS` for a completed invocation carries the recorded invocation input; after that payload is erased it becomes `{}`.
90
+
91
+ ## Related packages
92
+
93
+ - [`@godspeedai/cognate-react`](https://www.npmjs.com/package/@godspeedai/cognate-react) and [`@godspeedai/cognate-ui-astryx`](https://www.npmjs.com/package/@godspeedai/cognate-ui-astryx) — headless React bindings and reference UI over the same client contracts.
94
+ - [`@godspeedai/cognate-a2a`](https://www.npmjs.com/package/@godspeedai/cognate-a2a) — the A2A protocol adapter.
95
+ - [`@godspeedai/cognate-profile-copilot`](https://www.npmjs.com/package/@godspeedai/cognate-profile-copilot) — a composed interactive chat application built on this endpoint.
96
+ - [`@godspeedai/cognate`](https://www.npmjs.com/package/@godspeedai/cognate) — the SDK umbrella.
97
+
98
+ ## License
99
+
100
+ Apache-2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@godspeedai/cognate-ag-ui",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "AG-UI projection and interoperability adapter: outbound event mapping, inbound actions through native authorization, SSE endpoint with reconnect (spec §24). Internal events are never AG-UI aliases.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -24,9 +24,9 @@
24
24
  "dependencies": {
25
25
  "@ag-ui/core": "1.0.0",
26
26
  "@ag-ui/encoder": "1.0.0",
27
- "@godspeedai/cognate-client": "^0.1.0",
28
- "@godspeedai/cognate-events": "^0.1.0",
29
- "@godspeedai/cognate-runtime-api": "^0.1.0"
27
+ "@godspeedai/cognate-client": "^0.1.2",
28
+ "@godspeedai/cognate-events": "^0.1.2",
29
+ "@godspeedai/cognate-runtime-api": "^0.1.2"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@ag-ui/client": "1.0.0",