@agent-native/agentkit 0.1.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/ARCHITECTURE.md +290 -0
- package/README.md +822 -0
- package/dist/adapters/http.d.ts +56 -0
- package/dist/adapters/http.d.ts.map +1 -0
- package/dist/adapters/http.js +950 -0
- package/dist/adapters/http.js.map +1 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +2 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/client/client.d.ts +240 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +1605 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +3 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/state.d.ts +72 -0
- package/dist/client/state.d.ts.map +1 -0
- package/dist/client/state.js +385 -0
- package/dist/client/state.js.map +1 -0
- package/dist/conformance/index.d.ts +41 -0
- package/dist/conformance/index.d.ts.map +1 -0
- package/dist/conformance/index.js +924 -0
- package/dist/conformance/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol/agui-codec.d.ts +28 -0
- package/dist/protocol/agui-codec.d.ts.map +1 -0
- package/dist/protocol/agui-codec.js +250 -0
- package/dist/protocol/agui-codec.js.map +1 -0
- package/dist/protocol/agui.d.ts +144 -0
- package/dist/protocol/agui.d.ts.map +1 -0
- package/dist/protocol/agui.js +253 -0
- package/dist/protocol/agui.js.map +1 -0
- package/dist/protocol/compatibility.d.ts +35 -0
- package/dist/protocol/compatibility.d.ts.map +1 -0
- package/dist/protocol/compatibility.js +160 -0
- package/dist/protocol/compatibility.js.map +1 -0
- package/dist/protocol/errors.d.ts +24 -0
- package/dist/protocol/errors.d.ts.map +1 -0
- package/dist/protocol/errors.js +77 -0
- package/dist/protocol/errors.js.map +1 -0
- package/dist/protocol/index.d.ts +982 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +56 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/validation.d.ts +94 -0
- package/dist/protocol/validation.d.ts.map +1 -0
- package/dist/protocol/validation.js +1871 -0
- package/dist/protocol/validation.js.map +1 -0
- package/dist/protocol/version.d.ts +7 -0
- package/dist/protocol/version.d.ts.map +1 -0
- package/dist/protocol/version.js +9 -0
- package/dist/protocol/version.js.map +1 -0
- package/dist/react/chat.d.ts +34 -0
- package/dist/react/chat.d.ts.map +1 -0
- package/dist/react/chat.js +23 -0
- package/dist/react/chat.js.map +1 -0
- package/dist/react/components.d.ts +96 -0
- package/dist/react/components.d.ts.map +1 -0
- package/dist/react/components.js +1300 -0
- package/dist/react/components.js.map +1 -0
- package/dist/react/context.d.ts +259 -0
- package/dist/react/context.d.ts.map +1 -0
- package/dist/react/context.js +359 -0
- package/dist/react/context.js.map +1 -0
- package/dist/react/headless.d.ts +3 -0
- package/dist/react/headless.d.ts.map +1 -0
- package/dist/react/headless.js +3 -0
- package/dist/react/headless.js.map +1 -0
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +6 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/root.d.ts +58 -0
- package/dist/react/root.d.ts.map +1 -0
- package/dist/react/root.js +151 -0
- package/dist/react/root.js.map +1 -0
- package/dist/react/streaming-text.d.ts +19 -0
- package/dist/react/streaming-text.d.ts.map +1 -0
- package/dist/react/streaming-text.js +259 -0
- package/dist/react/streaming-text.js.map +1 -0
- package/dist/react/styles.css +1477 -0
- package/package.json +112 -0
package/ARCHITECTURE.md
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
# AgentKit architecture
|
|
2
|
+
|
|
3
|
+
Agent-Native is the application framework and execution platform. AgentKit is
|
|
4
|
+
its agent interaction and experience layer. Toolkit is the semantic
|
|
5
|
+
design-system and workspace layer. These layers are designed to work together
|
|
6
|
+
without collapsing their ownership boundaries.
|
|
7
|
+
|
|
8
|
+
| Layer | Owns | Does not own |
|
|
9
|
+
| ------------ | ------------------------------------------------------------------------------------------ | ----------------------------------------------- |
|
|
10
|
+
| Agent-Native | Actions, SQL, application state, agent execution, auth, access, persistence, deployment | Portable conversation UI contracts |
|
|
11
|
+
| AgentKit | Protocol, event validation, client state, transports, React bindings, agent UI composition | App data, authorization policy, agent execution |
|
|
12
|
+
| Toolkit | Semantic controls, composer building blocks, design-system adapters, workspace UI | Conversation state or backend behavior |
|
|
13
|
+
|
|
14
|
+
AgentKit also runs with another backend. That backend must own the same
|
|
15
|
+
execution and security responsibilities that Agent-Native normally provides.
|
|
16
|
+
Each layer has one source of truth and a narrow dependency direction.
|
|
17
|
+
|
|
18
|
+
```text
|
|
19
|
+
Agent-Native Core or another agent runtime
|
|
20
|
+
↓ runtime adapter
|
|
21
|
+
versioned AgentKit protocol + validation
|
|
22
|
+
↓ transport
|
|
23
|
+
headless AgentKit client + event reducer
|
|
24
|
+
↓ subscription
|
|
25
|
+
React provider + AgentKit UI using Toolkit semantics
|
|
26
|
+
↓ composition
|
|
27
|
+
app slots, registries, callbacks, and workspace chrome
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Ownership model
|
|
31
|
+
|
|
32
|
+
The backend owns durable truth. The AgentKit client owns the live normalized
|
|
33
|
+
projection and optimistic command state. React owns presentation. The app owns
|
|
34
|
+
its product composition.
|
|
35
|
+
|
|
36
|
+
An application chooses exactly one client source per conversation:
|
|
37
|
+
|
|
38
|
+
- `endpoint` lets `AgentKitRoot` create and dispose an HTTP transport and
|
|
39
|
+
controller.
|
|
40
|
+
- `transport` lets `AgentKitRoot` create and dispose a controller around a
|
|
41
|
+
host-owned transport.
|
|
42
|
+
- `controller` keeps lifecycle in the host. AgentKit does not load or dispose
|
|
43
|
+
another controller behind it.
|
|
44
|
+
|
|
45
|
+
Inject the same controller into every coordinated view. A second controller,
|
|
46
|
+
stream reader, queue, approval store, or optimistic message list creates two
|
|
47
|
+
behavioral owners and violates the contract.
|
|
48
|
+
|
|
49
|
+
## Invariants
|
|
50
|
+
|
|
51
|
+
1. Events are append-only, ordered, replayable, and explicitly terminal.
|
|
52
|
+
2. A reconnect begins after the last accepted sequence. Duplicate events are
|
|
53
|
+
harmless.
|
|
54
|
+
3. Binary data never enters messages or event logs. Uploads negotiate a target
|
|
55
|
+
and complete into portable file references.
|
|
56
|
+
4. Widgets invoke stable action identifiers. They do not call app routes or
|
|
57
|
+
mutate app state directly.
|
|
58
|
+
5. Hidden chain-of-thought is not a UI contract. Agents publish safe reasoning
|
|
59
|
+
summaries and named activities instead.
|
|
60
|
+
6. Rich formatting is opt-in per text part. Plain text remains the secure,
|
|
61
|
+
visually quiet default.
|
|
62
|
+
7. Suggestions are agent-authored post-response actions, never unexplained
|
|
63
|
+
template defaults.
|
|
64
|
+
8. Smart objects contain portable identity. Hosts own authorization,
|
|
65
|
+
navigation, and rendering.
|
|
66
|
+
9. The headless client is the behavioral source of truth for default and
|
|
67
|
+
custom views.
|
|
68
|
+
10. Optional capabilities are negotiated. Unsupported behavior fails clearly
|
|
69
|
+
instead of being silently coerced into success.
|
|
70
|
+
11. Tasks model delegable workflow state. Activities model execution evidence.
|
|
71
|
+
12. Approval authorization is explicit. Option ids and user-facing labels never
|
|
72
|
+
determine whether a response approves or denies work.
|
|
73
|
+
A host may expose either capability without pretending one is the other.
|
|
74
|
+
13. The agent roster is a current-state projection. Agent interactions are an
|
|
75
|
+
append-only audit of collaboration. Lifecycle state never replaces the
|
|
76
|
+
activity that explains what an agent actually did.
|
|
77
|
+
14. Work outside the thread declares `scope` and a portable `source` smart
|
|
78
|
+
object. The protocol never assumes that an app, workspace object, or remote
|
|
79
|
+
agent shares the chat host's navigation or authorization model.
|
|
80
|
+
15. One controller owns a conversation's state and command lifecycle. A host
|
|
81
|
+
may project an existing runtime through that contract, but it must not open
|
|
82
|
+
a parallel stream or maintain duplicate message, queue, or approval state.
|
|
83
|
+
16. `resubscribeRun` reconnects to existing work. Retrying work is a separate,
|
|
84
|
+
host-defined, idempotency-aware action and is never inferred from a network
|
|
85
|
+
failure.
|
|
86
|
+
17. Host and agent-authored renderers fail within their own surface boundary.
|
|
87
|
+
Users receive safe copy. Host observability receives the original failure
|
|
88
|
+
with thread and surface identity.
|
|
89
|
+
18. Aborting non-stream request context cancels only that operation. Aborting a
|
|
90
|
+
run subscription releases only that subscriber's resources. Neither action
|
|
91
|
+
implicitly cancels or otherwise mutates the remote run.
|
|
92
|
+
19. A durable snapshot is self-contained. Empty projections are present as
|
|
93
|
+
empty arrays, its checkpoint covers every included run, and active-run ids
|
|
94
|
+
resolve only to included non-terminal runs.
|
|
95
|
+
20. Capability omission means unknown. Unsupported and temporarily unavailable
|
|
96
|
+
states are explicit, typed, and never coerced into a successful no-op.
|
|
97
|
+
21. Actor, workspace, access, audit, trace, and context metadata are portable
|
|
98
|
+
references, not authorization grants. The receiving host re-resolves them
|
|
99
|
+
at its trust boundary.
|
|
100
|
+
22. Events are contiguous within a run. A consumer rejects a sequence gap
|
|
101
|
+
before advancing its replay cursor so reconnect cannot make a missing event
|
|
102
|
+
permanent.
|
|
103
|
+
23. Approval continuation binds an explicit approve-or-deny decision to the
|
|
104
|
+
exact pending request id. Option labels and localized identifiers never
|
|
105
|
+
imply authorization.
|
|
106
|
+
24. AgentKit publishes as one compatibility-tested package. Its subpaths stay
|
|
107
|
+
separate module graphs, so a consumer loads only the surface it imports.
|
|
108
|
+
|
|
109
|
+
## Protocol boundaries
|
|
110
|
+
|
|
111
|
+
Version discovery occurs before versioned envelope exchange.
|
|
112
|
+
`negotiateAgentKitProtocolVersion()` selects the highest mutual version or
|
|
113
|
+
returns a typed, non-retryable incompatibility. Once selected, every received
|
|
114
|
+
envelope, command, event, result, and persisted snapshot passes through its
|
|
115
|
+
matching runtime parser. Unknown envelope fields and unsupported versions fail
|
|
116
|
+
loudly; opaque payload and metadata values must still be JSON-safe.
|
|
117
|
+
|
|
118
|
+
`AgentThreadSnapshot` supports existing partial transports.
|
|
119
|
+
`AgentDurableThreadSnapshot` is the canonical persistence and restart contract.
|
|
120
|
+
It carries both normalized current projections and ordered events through an
|
|
121
|
+
`AgentReplayCheckpoint`. The projection prevents an application from having to
|
|
122
|
+
re-derive messages, tools, activities, tasks, approvals, widgets, agents,
|
|
123
|
+
interactions, artifacts, or suggestions after restart. The checkpoint prevents
|
|
124
|
+
the client from replaying accepted deltas or skipping active work.
|
|
125
|
+
|
|
126
|
+
Errors cross process boundaries as `AgentError` values. Capability,
|
|
127
|
+
unsupported-operation, and version failures use their typed refinements with
|
|
128
|
+
explicit retryability and correlation identity. A local transport may throw
|
|
129
|
+
`AgentKitProtocolError`, which preserves the serializable error unchanged for
|
|
130
|
+
an adapter or caller.
|
|
131
|
+
|
|
132
|
+
Non-stream transport operations accept an optional provider-neutral
|
|
133
|
+
`AgentRequestContext`. Its abort signal and correlation identity are ephemeral
|
|
134
|
+
request controls rather than wire payload. Adapters propagate them to backend
|
|
135
|
+
work and return a typed `request_aborted` error when cancellation wins. Stream
|
|
136
|
+
subscription signals remain consumer-local and never imply `cancelRun()`.
|
|
137
|
+
|
|
138
|
+
## Extension model
|
|
139
|
+
|
|
140
|
+
Use a standard protocol field when behavior affects every host. Use an `x-*`
|
|
141
|
+
event or capability only for backend-specific data. React presentation extends
|
|
142
|
+
through slots for broad replacement and kind registries for widgets, tools, and
|
|
143
|
+
activities. App operations extend through `invokeAction`. App navigation
|
|
144
|
+
extends through smart-object and client-effect callbacks.
|
|
145
|
+
|
|
146
|
+
Multi-agent renderers compose at three levels: `agent` replaces identity,
|
|
147
|
+
`agentInteraction` replaces lifecycle rows, and activity registries replace
|
|
148
|
+
domain-specific work. Hosts can therefore preserve one behavioral contract
|
|
149
|
+
while presenting a lightweight chat feed, an operations timeline, or a full
|
|
150
|
+
agent observability workspace.
|
|
151
|
+
|
|
152
|
+
## Adapter model
|
|
153
|
+
|
|
154
|
+
Agent-Native provides the first-party production adapter:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { createAgentNativeAgentKitTransport } from "@agent-native/core/client/agent-chat";
|
|
158
|
+
|
|
159
|
+
const transport = createAgentNativeAgentKitTransport({
|
|
160
|
+
threadId,
|
|
161
|
+
surface: "app",
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
It binds the built-in Agent-Native chat endpoint to AgentKit thread snapshots,
|
|
166
|
+
run streams, approval continuation, feedback, durable queue operations, and
|
|
167
|
+
thread forking. It preserves Core's runtime and request boundaries.
|
|
168
|
+
|
|
169
|
+
Runtime implementers that already expose Core's `AgentChatRuntime` can use
|
|
170
|
+
`createAgentKitProtocolAdapter()` from `@agent-native/core/client/chat`.
|
|
171
|
+
Provider-neutral backends implement `AgentTransport` directly. They may expose
|
|
172
|
+
that transport with `createAgentKitHttpHandler()` and consume it with
|
|
173
|
+
`createAgentKitHttpTransport()`.
|
|
174
|
+
|
|
175
|
+
The protocol types and the HTTP adapter do not provide authentication,
|
|
176
|
+
authorization, persistence, tenancy, or agent execution. Those remain backend
|
|
177
|
+
responsibilities.
|
|
178
|
+
|
|
179
|
+
## Agent-Native contract mapping
|
|
180
|
+
|
|
181
|
+
### Actions
|
|
182
|
+
|
|
183
|
+
AgentKit widgets carry stable action identifiers and serializable payloads.
|
|
184
|
+
They call `AgentTransport.invokeAction`. In an Agent-Native app, map that
|
|
185
|
+
operation to the same named `defineAction` surface used by the UI and agent.
|
|
186
|
+
The production adapter advertises the `actions` capability only when the host
|
|
187
|
+
supplies `operations.invokeAction`.
|
|
188
|
+
|
|
189
|
+
Validate the payload at the action boundary and preserve normal request context
|
|
190
|
+
and access checks. Do not route widget actions to product URLs or mutate SQL
|
|
191
|
+
from a renderer.
|
|
192
|
+
|
|
193
|
+
### Context and navigation
|
|
194
|
+
|
|
195
|
+
`AgentObjectReference` provides portable identity for a file, record, artifact,
|
|
196
|
+
or view. `onOpenObject` resolves it into host navigation. `client.effect` and
|
|
197
|
+
`client.deeplink` events reach `onClientEffect`. If opening an object changes
|
|
198
|
+
Agent-Native application state, use the app's existing named helper or action.
|
|
199
|
+
The protocol never writes `application_state` directly.
|
|
200
|
+
|
|
201
|
+
### Security
|
|
202
|
+
|
|
203
|
+
Thread ids, run ids, action ids, widget payloads, and smart objects are not
|
|
204
|
+
authorization grants. The host must authenticate transport requests, scope
|
|
205
|
+
thread reads and writes, assert action access, validate uploads, and re-resolve
|
|
206
|
+
objects before navigation. Mount the generic HTTP handler only after those
|
|
207
|
+
controls. Keep Agent-Native apps on Core's existing auth, request-context, and
|
|
208
|
+
ownable-data boundaries.
|
|
209
|
+
|
|
210
|
+
## Configure, compose, and eject
|
|
211
|
+
|
|
212
|
+
Customization follows an ownership ladder:
|
|
213
|
+
|
|
214
|
+
1. Configure labels, semantic tokens, composer props, callbacks, slots, and
|
|
215
|
+
renderer registries.
|
|
216
|
+
2. Compose a product with `AgentKitRoot`, the headless hooks, selected AgentKit
|
|
217
|
+
regions, and Toolkit workspace components.
|
|
218
|
+
3. Eject the smallest installed unit listed by `agent-native eject --list`.
|
|
219
|
+
A headless composition can take ownership of Toolkit's composer with
|
|
220
|
+
`agent-native eject toolkit/composer --app <app> --apply`.
|
|
221
|
+
|
|
222
|
+
AgentKit does not advertise an AgentKit-wide ejection unit. Do not copy its
|
|
223
|
+
private source. Ejecting a Toolkit region transfers only that presentation
|
|
224
|
+
source. Core auth, persistence, action execution, application state, chat
|
|
225
|
+
transport, and agent execution stay on public package contracts.
|
|
226
|
+
|
|
227
|
+
## Migration from Core chat UI
|
|
228
|
+
|
|
229
|
+
An existing Agent-Native app can migrate presentation without replacing its
|
|
230
|
+
runtime:
|
|
231
|
+
|
|
232
|
+
1. Keep the app shell, thread routing, actions, application-state keys, auth,
|
|
233
|
+
access checks, and agent runtime.
|
|
234
|
+
2. Create `createAgentNativeAgentKitTransport()` for the default runtime. For a
|
|
235
|
+
custom Core runtime, wrap its `AgentChatRuntime` with
|
|
236
|
+
`createAgentKitProtocolAdapter()`.
|
|
237
|
+
3. Replace the old transcript surface with `AgentChat`, or compose
|
|
238
|
+
`AgentKitRoot` and `AgentKitChat`.
|
|
239
|
+
4. Move visual overrides into slots and kind registries. Move commands into
|
|
240
|
+
`useAgentKitControl()` or the injected controller.
|
|
241
|
+
5. Remove the old controller and stream owner in the same migration. Keep one
|
|
242
|
+
source of message, run, queue, and approval state.
|
|
243
|
+
|
|
244
|
+
## Public distribution
|
|
245
|
+
|
|
246
|
+
Applications install one package, `@agent-native/agentkit`. The root import
|
|
247
|
+
exposes only the dependency-free protocol and headless client. HTTP, React, and
|
|
248
|
+
conformance live behind the explicit `/http`, `/react`, and `/conformance`
|
|
249
|
+
subpaths, so a server, native client, or alternate renderer does not load
|
|
250
|
+
unrelated runtime code. The five former sibling packages (`agentkit-protocol`,
|
|
251
|
+
`agentkit-client`, `agentkit-adapters`, `agentkit-conformance`, and
|
|
252
|
+
`agentkit-react`) map onto those subpaths; the
|
|
253
|
+
[README](./README.md#package-layout) carries the mapping.
|
|
254
|
+
|
|
255
|
+
## Stability path
|
|
256
|
+
|
|
257
|
+
New transports run `assertAgentTransportConformance()` before release. New event
|
|
258
|
+
shapes require validators, reducer coverage, replay tests, and documentation.
|
|
259
|
+
Breaking wire changes increment the protocol version and must fail loudly at
|
|
260
|
+
the envelope boundary.
|
|
261
|
+
|
|
262
|
+
The package API follows the package version, but wire compatibility does not
|
|
263
|
+
depend on it. Network discovery offers `AGENTKIT_SUPPORTED_PROTOCOL_VERSIONS`
|
|
264
|
+
and selects the highest mutual version, so a client and a backend on different
|
|
265
|
+
package versions still negotiate a shared protocol. Capability discovery
|
|
266
|
+
distinguishes available, degraded, unavailable, unsupported, and omitted unknown
|
|
267
|
+
state. During the pre-1.0 period, consumers should review minor-release notes
|
|
268
|
+
before upgrading a custom adapter.
|
|
269
|
+
|
|
270
|
+
Protocol v2 is one such explicitly breaking pre-1.0 minor. Its AG-UI envelope
|
|
271
|
+
is not wire-compatible with v1, so clients and servers must upgrade together
|
|
272
|
+
and custom adapters must rerun conformance before deployment. V2-only peers
|
|
273
|
+
reject v1 at negotiation instead of guessing a fallback; the deprecated
|
|
274
|
+
`resolveApproval` API is only a source-compatibility bridge after both peers
|
|
275
|
+
have upgraded.
|
|
276
|
+
|
|
277
|
+
Approvals follow AG-UI's terminal interrupt lifecycle. The request closes the
|
|
278
|
+
interrupted protocol run, and `resumeRun()` returns a distinct replacement run
|
|
279
|
+
that contains the resolution and continued events.
|
|
280
|
+
|
|
281
|
+
Conformance enforces `resumeRun()` for transports that advertise protocol v2.
|
|
282
|
+
Unversioned compatibility transports may temporarily use the deprecated
|
|
283
|
+
`resolveApproval()` bridge while custom adapters migrate.
|
|
284
|
+
|
|
285
|
+
Conformance follows negotiated capabilities. A transport that declares
|
|
286
|
+
`resumableRuns` must prove cursor replay. A transport that declares
|
|
287
|
+
`durableThreadSnapshots` must return a value accepted by
|
|
288
|
+
`parseAgentDurableThreadSnapshot()`. A transport that cannot survive a process
|
|
289
|
+
restart must declare both capabilities false even if it can replay an in-memory
|
|
290
|
+
stream during that process.
|