use-agentenkit 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/LICENSE +21 -0
- package/README.md +179 -0
- package/dist/config.d.ts +150 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +138 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +10 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +23 -0
- package/dist/context.js.map +1 -0
- package/dist/format.d.ts +19 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +101 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +12 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +9 -0
- package/dist/provider.js.map +1 -0
- package/dist/types.d.ts +101 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/useAgentThread.d.ts +42 -0
- package/dist/useAgentThread.d.ts.map +1 -0
- package/dist/useAgentThread.js +572 -0
- package/dist/useAgentThread.js.map +1 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eadwin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# use-agentenkit
|
|
2
|
+
|
|
3
|
+
A React hook for an [`agentenkit`](../agentenkit) backend: durable
|
|
4
|
+
threads, live streaming, human-in-the-loop approvals and nested runs.
|
|
5
|
+
|
|
6
|
+
It owns the client state machine — hydrate from the durable snapshot, replay
|
|
7
|
+
the active run, then tail the event stream — and leaves every endpoint, string
|
|
8
|
+
and transport to you.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
bun add use-agentenkit
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
**[Full documentation](https://eadwincode.github.io/agentic-kit/)** · [React guide](https://eadwincode.github.io/agentic-kit/react) ·
|
|
15
|
+
[the HTTP contract it expects](https://eadwincode.github.io/agentic-kit/http-api)
|
|
16
|
+
|
|
17
|
+
## Use it
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
'use client';
|
|
21
|
+
import { useAgentThread } from 'use-agentenkit';
|
|
22
|
+
|
|
23
|
+
export function Chat() {
|
|
24
|
+
const { entries, run, stop, agentState, pendingInputs, respondToInput } =
|
|
25
|
+
useAgentThread();
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<>
|
|
29
|
+
{entries.map((e) => (
|
|
30
|
+
<p key={e.id}>{e.role}: {e.text}</p>
|
|
31
|
+
))}
|
|
32
|
+
{pendingInputs.map((input) => (
|
|
33
|
+
<button key={input.toolCallId} onClick={() => respondToInput(input.toolCallId, true)}>
|
|
34
|
+
Approve {input.toolName}
|
|
35
|
+
</button>
|
|
36
|
+
))}
|
|
37
|
+
<button onClick={() => (agentState === 'RUNNING' ? stop() : run('hello'))}>
|
|
38
|
+
{agentState === 'RUNNING' ? 'Stop' : 'Send'}
|
|
39
|
+
</button>
|
|
40
|
+
</>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
With no config it calls the default routes below. Nothing else is assumed.
|
|
46
|
+
|
|
47
|
+
## Routes
|
|
48
|
+
|
|
49
|
+
| Route | Method | Default | Carries |
|
|
50
|
+
| --- | --- | --- | --- |
|
|
51
|
+
| `run` | POST | `/api/agent/run` | `{ threadId?, prompt, model, editMessageId? }` |
|
|
52
|
+
| `stop` | POST | `/api/agent/control` | `{ threadId }` |
|
|
53
|
+
| `respond` | POST | `/api/agent/respond` | `{ threadId, toolCallId, approved, payload? }` |
|
|
54
|
+
| `stream` | GET (SSE) | `/api/agent/stream` | `?threadId=&since=` |
|
|
55
|
+
| `history` | GET | `/api/agent/history` | `?threadId=` |
|
|
56
|
+
| `usage` | GET | `/api/agent/usage` | `?threadId=` |
|
|
57
|
+
| `threads` | GET | `/api/threads` | — |
|
|
58
|
+
| `deleteThread` | DELETE | `/api/threads` | `?threadId=` |
|
|
59
|
+
|
|
60
|
+
Override any subset. A route is either a path the hook appends its own query
|
|
61
|
+
to, or a function that builds the whole URL — the function form covers path
|
|
62
|
+
parameters, a different query vocabulary, or another host:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
useAgentThread({
|
|
66
|
+
baseUrl: 'https://api.example.com',
|
|
67
|
+
routes: {
|
|
68
|
+
run: '/v2/agent/start',
|
|
69
|
+
history: ({ threadId }) => `/v2/threads/${threadId}`,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Configure once
|
|
75
|
+
|
|
76
|
+
`AgentRunProvider` sets the config for everything below it. A hook's own
|
|
77
|
+
options still win, section by section, so a component can replace one route
|
|
78
|
+
without restating the rest.
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
'use client';
|
|
82
|
+
import { AgentRunProvider } from 'use-agentenkit';
|
|
83
|
+
|
|
84
|
+
export function Providers({ children }) {
|
|
85
|
+
return (
|
|
86
|
+
<AgentRunProvider config={{ routes: { run: '/v2/agent/start' } }}>
|
|
87
|
+
{children}
|
|
88
|
+
</AgentRunProvider>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Everything else you can change
|
|
94
|
+
|
|
95
|
+
| Option | Default | What it is for |
|
|
96
|
+
| --- | --- | --- |
|
|
97
|
+
| `fetch` | global `fetch` | auth wrappers, retries, a test double |
|
|
98
|
+
| `headers` | none | sent with every request; a function is called per request, so a rotating token stays fresh |
|
|
99
|
+
| `openStream` | `browserEventStream` | how the event stream is opened — see below |
|
|
100
|
+
| `defaultModel` | `'gpt-4o'` | used when `run()` names no model |
|
|
101
|
+
| `persistence` | `browserPersistence()` | where the open thread id is remembered; `false` keeps it in memory only |
|
|
102
|
+
| `labels` | English | every user-facing string the hook produces |
|
|
103
|
+
| `format` | plain text | how tool calls, results and subagent notices render |
|
|
104
|
+
| `onEvent` | none | see every event first; return `true` to handle it yourself |
|
|
105
|
+
| `threadsRefreshMs` | `30000` | background refresh of the thread list; `false` disables it |
|
|
106
|
+
| `loadThreadsOnMount` | `true` | off for a single-thread embed |
|
|
107
|
+
|
|
108
|
+
### Auth on the stream
|
|
109
|
+
|
|
110
|
+
`headers` does **not** reach the event stream. The browser's `EventSource`
|
|
111
|
+
cannot send headers — that is a limitation of the API, not of this package. Use
|
|
112
|
+
a cookie, or supply your own `openStream`:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
useAgentThread({
|
|
116
|
+
openStream: (url, { onMessage, onError }) => {
|
|
117
|
+
const source = new MyAuthedEventSource(url, { token });
|
|
118
|
+
source.onmessage = (e) => onMessage(e.data);
|
|
119
|
+
source.onerror = onError;
|
|
120
|
+
return { close: () => source.close() };
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Your own events
|
|
126
|
+
|
|
127
|
+
`onEvent` runs before the built-in reducer and can claim an event:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
useAgentThread({
|
|
131
|
+
onEvent: (event) => {
|
|
132
|
+
if (event.type === 'MY_APP_EVENT') {
|
|
133
|
+
handle(event.payload);
|
|
134
|
+
return true; // handled — skip the built-in reducer
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Streaming thought
|
|
141
|
+
|
|
142
|
+
Models that expose their reasoning stream it separately from the answer. The
|
|
143
|
+
hook keeps the two apart: thinking arrives as entries with `kind: 'reasoning'`,
|
|
144
|
+
in order, so a UI can show it live and fold it away once the answer starts.
|
|
145
|
+
|
|
146
|
+
```tsx
|
|
147
|
+
{entries.map((e) =>
|
|
148
|
+
e.kind === 'reasoning' ? <Thought key={e.id} text={e.text} /> : <Bubble key={e.id} {...e} />,
|
|
149
|
+
)}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
It reads the same on a reload as it did live: a persisted message's reasoning
|
|
153
|
+
parts are lifted into their own entry rather than folded into the answer text.
|
|
154
|
+
|
|
155
|
+
Whether you see anything depends on the model. Providers that do not expose
|
|
156
|
+
reasoning simply never send it, and no reasoning entries appear — OpenAI's
|
|
157
|
+
`gpt-4o` is one of those, and the o-series reports reasoning *token counts*
|
|
158
|
+
without the text. Anthropic extended thinking and DeepSeek R1 do send it.
|
|
159
|
+
|
|
160
|
+
## What the hook returns
|
|
161
|
+
|
|
162
|
+
State: `threadId`, `entries`, `agentState`, `activity`, `historyLoading`,
|
|
163
|
+
`pendingInputs`, `subagents`, `threads`, `threadsLoading`, `usage`.
|
|
164
|
+
|
|
165
|
+
Actions: `run`, `stop`, `respondToInput`, `newThread`, `selectThread`,
|
|
166
|
+
`deleteThread`, `loadThreads`, `loadUsage`.
|
|
167
|
+
|
|
168
|
+
An entry is `{ id, kind, role, text, agentId }`, where `kind` is `'text'`,
|
|
169
|
+
`'tool'` or `'reasoning'`.
|
|
170
|
+
|
|
171
|
+
## Notes
|
|
172
|
+
|
|
173
|
+
- The server is the only source of truth. A reload, or a second tab, rebuilds
|
|
174
|
+
from the durable snapshot and then resumes the stream at its cursor.
|
|
175
|
+
- `run()` adds the user's turn locally before the request goes out, then
|
|
176
|
+
replaces it with the durable one when the server confirms it, so the id is
|
|
177
|
+
real and the message can be edited.
|
|
178
|
+
- Config is read fresh on every request, but an open stream keeps the URL it
|
|
179
|
+
was opened with. Change routes at mount, not mid-run.
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { StreamEvent } from './types.js';
|
|
2
|
+
/** Just the call signature. `typeof fetch` also carries runtime-specific
|
|
3
|
+
* extras (Bun adds `preconnect`) that a plain wrapper cannot satisfy. */
|
|
4
|
+
export type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
5
|
+
/** A route is either a path the hook appends its own query to, or a function
|
|
6
|
+
* that builds the whole URL. The function form is the escape hatch: it covers
|
|
7
|
+
* path parameters (`/threads/:id/history`), a different query vocabulary, or
|
|
8
|
+
* an entirely different host — cases a fixed path cannot express. */
|
|
9
|
+
export type Route<P = void> = P extends void ? string : string | ((params: P) => string);
|
|
10
|
+
export interface AgentRoutes {
|
|
11
|
+
/** POST { threadId?, prompt, model, editMessageId? } → RunResult */
|
|
12
|
+
run: string;
|
|
13
|
+
/** POST { threadId } — stop the active run */
|
|
14
|
+
stop: string;
|
|
15
|
+
/** POST { threadId, toolCallId, approved, payload? } — answer an approval */
|
|
16
|
+
respond: string;
|
|
17
|
+
/** GET, server-sent events. Resumes from `since`. */
|
|
18
|
+
stream: Route<{
|
|
19
|
+
threadId: string;
|
|
20
|
+
since: number;
|
|
21
|
+
}>;
|
|
22
|
+
/** GET → ThreadSnapshot */
|
|
23
|
+
history: Route<{
|
|
24
|
+
threadId: string;
|
|
25
|
+
}>;
|
|
26
|
+
/** GET → ThreadUsage */
|
|
27
|
+
usage: Route<{
|
|
28
|
+
threadId: string;
|
|
29
|
+
}>;
|
|
30
|
+
/** GET → { threads: ThreadListItem[] } */
|
|
31
|
+
threads: string;
|
|
32
|
+
/** DELETE — remove a thread and everything under it */
|
|
33
|
+
deleteThread: Route<{
|
|
34
|
+
threadId: string;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
export declare const defaultRoutes: AgentRoutes;
|
|
38
|
+
/** Every user-facing string the hook produces, in one place so an app can
|
|
39
|
+
* translate or reword them without forking the state machine. */
|
|
40
|
+
export interface ActivityLabels {
|
|
41
|
+
idle: string;
|
|
42
|
+
loading: string;
|
|
43
|
+
thinking: string;
|
|
44
|
+
responding: string;
|
|
45
|
+
reviewingSources: string;
|
|
46
|
+
preparingToolCall: string;
|
|
47
|
+
callingTool: string;
|
|
48
|
+
toolCompleted: string;
|
|
49
|
+
waitingApproval: string;
|
|
50
|
+
approvalExpired: string;
|
|
51
|
+
approvalSent: string;
|
|
52
|
+
requestDenied: string;
|
|
53
|
+
subagentWorking: string;
|
|
54
|
+
subagentCompleted: string;
|
|
55
|
+
completed: string;
|
|
56
|
+
stopped: string;
|
|
57
|
+
failed: string;
|
|
58
|
+
runFailed: string;
|
|
59
|
+
loadFailed: string;
|
|
60
|
+
}
|
|
61
|
+
export declare const defaultLabels: ActivityLabels;
|
|
62
|
+
/** How a message turns into display text. The defaults are plain and
|
|
63
|
+
* ASCII-marked; override to render your own tool cards. */
|
|
64
|
+
export interface EntryFormat {
|
|
65
|
+
truncate(text: string, max: number): string;
|
|
66
|
+
toolCall(toolName: string, args: unknown): string;
|
|
67
|
+
toolResult(toolName: string | undefined, result: unknown): string;
|
|
68
|
+
subagentStarted(name: string): string;
|
|
69
|
+
}
|
|
70
|
+
export declare const defaultFormat: EntryFormat;
|
|
71
|
+
/** Where the open thread id is remembered between reloads. This is app policy,
|
|
72
|
+
* not library policy — an app with its own router should supply its own, and
|
|
73
|
+
* one that wants a clean slate every load can pass `false`. */
|
|
74
|
+
export interface ThreadPersistence {
|
|
75
|
+
load(): string | undefined;
|
|
76
|
+
save(threadId: string): void;
|
|
77
|
+
clear(): void;
|
|
78
|
+
}
|
|
79
|
+
/** The default: a `threadId` query parameter so a conversation is linkable,
|
|
80
|
+
* backed by localStorage so a bare visit reopens the last one. */
|
|
81
|
+
export declare function browserPersistence(storageKey?: string): ThreadPersistence;
|
|
82
|
+
export interface StreamHandlers {
|
|
83
|
+
/** One event frame, still encoded. */
|
|
84
|
+
onMessage: (data: string) => void;
|
|
85
|
+
onError: (error: unknown) => void;
|
|
86
|
+
}
|
|
87
|
+
export interface StreamSubscription {
|
|
88
|
+
close(): void;
|
|
89
|
+
}
|
|
90
|
+
/** Open the event stream. Handlers go in and something closeable comes back —
|
|
91
|
+
* rather than an EventSource look-alike, so an implementation is free to use
|
|
92
|
+
* fetch streaming, a WebSocket, or a test double without imitating the
|
|
93
|
+
* browser's property API. */
|
|
94
|
+
export type OpenStream = (url: string, handlers: StreamHandlers) => StreamSubscription;
|
|
95
|
+
export declare const browserEventStream: OpenStream;
|
|
96
|
+
export interface AgentRunConfig {
|
|
97
|
+
/** Override any subset; the rest keep their defaults. */
|
|
98
|
+
routes?: Partial<AgentRoutes>;
|
|
99
|
+
/** Prefix applied to string routes — for an API on another origin. Routes
|
|
100
|
+
* given as functions build their own URL and are left alone. */
|
|
101
|
+
baseUrl?: string;
|
|
102
|
+
/** Swap the transport: auth wrappers, retries, a test double. */
|
|
103
|
+
fetch?: FetchLike;
|
|
104
|
+
/** Sent with every request the hook makes. A function is called per request,
|
|
105
|
+
* so a token that rotates stays fresh. */
|
|
106
|
+
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
107
|
+
/** Open the event stream. The default uses the browser's EventSource, which
|
|
108
|
+
* CANNOT send headers — so `headers` does not reach the stream. An API
|
|
109
|
+
* behind a bearer token needs its own implementation here (or a cookie). */
|
|
110
|
+
openStream?: OpenStream;
|
|
111
|
+
/** Used by `run()` when the caller names no model. */
|
|
112
|
+
defaultModel?: string;
|
|
113
|
+
/** `false` keeps the thread id in memory only. */
|
|
114
|
+
persistence?: ThreadPersistence | false;
|
|
115
|
+
labels?: Partial<ActivityLabels>;
|
|
116
|
+
format?: Partial<EntryFormat>;
|
|
117
|
+
/** Every event, before the hook interprets it. Return `true` to say the
|
|
118
|
+
* event is handled and stop the built-in reducer — that is how an app adds
|
|
119
|
+
* its own event types, or overrides one. */
|
|
120
|
+
onEvent?: (event: StreamEvent) => boolean | void;
|
|
121
|
+
/** Background refresh for the thread list, in ms. `false` disables it —
|
|
122
|
+
* other tabs and the worker can change thread state without this tab
|
|
123
|
+
* seeing an event, which is the only reason it exists. */
|
|
124
|
+
threadsRefreshMs?: number | false;
|
|
125
|
+
/** Load the thread list on mount. Off for a single-thread embed. */
|
|
126
|
+
loadThreadsOnMount?: boolean;
|
|
127
|
+
}
|
|
128
|
+
export interface ResolvedConfig {
|
|
129
|
+
routes: AgentRoutes;
|
|
130
|
+
baseUrl: string;
|
|
131
|
+
fetch: FetchLike;
|
|
132
|
+
headers: () => HeadersInit | Promise<HeadersInit>;
|
|
133
|
+
openStream: OpenStream;
|
|
134
|
+
defaultModel: string;
|
|
135
|
+
persistence: ThreadPersistence | null;
|
|
136
|
+
labels: ActivityLabels;
|
|
137
|
+
format: EntryFormat;
|
|
138
|
+
onEvent: ((event: StreamEvent) => boolean | void) | undefined;
|
|
139
|
+
threadsRefreshMs: number | false;
|
|
140
|
+
loadThreadsOnMount: boolean;
|
|
141
|
+
}
|
|
142
|
+
export declare function resolveConfig(config?: AgentRunConfig): ResolvedConfig;
|
|
143
|
+
/** Append query parameters without disturbing a relative path or a query the
|
|
144
|
+
* route already carries. `new URL` cannot be used here — it would force every
|
|
145
|
+
* route to be absolute. */
|
|
146
|
+
export declare function withQuery(path: string, params: Record<string, string | number | undefined>): string;
|
|
147
|
+
/** Resolve one route to a URL. A string gets the base prefix and the hook's
|
|
148
|
+
* standard query; a function is trusted to return a complete URL. */
|
|
149
|
+
export declare function routeUrl<P extends Record<string, string | number | undefined>>(route: string | ((params: P) => string), params: P, baseUrl: string): string;
|
|
150
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;0EAC0E;AAC1E,MAAM,MAAM,SAAS,GAAG,CACtB,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,KACf,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB;;;sEAGsE;AACtE,MAAM,MAAM,KAAK,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,SAAS,IAAI,GACxC,MAAM,GACN,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,CAAC,CAAC;AAErC,MAAM,WAAW,WAAW;IAC1B,oEAAoE;IACpE,GAAG,EAAE,MAAM,CAAC;IACZ,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,MAAM,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,2BAA2B;IAC3B,OAAO,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrC,wBA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,EAAE,CAAC,KAAK,MAAM,CAAC,EACvC,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,MAAM,GACd,MAAM,CAGR"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
export const defaultRoutes = {
|
|
2
|
+
run: '/api/agent/run',
|
|
3
|
+
stop: '/api/agent/control',
|
|
4
|
+
respond: '/api/agent/respond',
|
|
5
|
+
stream: '/api/agent/stream',
|
|
6
|
+
history: '/api/agent/history',
|
|
7
|
+
usage: '/api/agent/usage',
|
|
8
|
+
threads: '/api/threads',
|
|
9
|
+
deleteThread: '/api/threads',
|
|
10
|
+
};
|
|
11
|
+
export const defaultLabels = {
|
|
12
|
+
idle: 'Idle',
|
|
13
|
+
loading: 'Loading conversation',
|
|
14
|
+
thinking: 'Thinking',
|
|
15
|
+
responding: 'Responding',
|
|
16
|
+
reviewingSources: 'Reviewing sources',
|
|
17
|
+
preparingToolCall: 'Preparing tool call',
|
|
18
|
+
callingTool: 'Calling tool',
|
|
19
|
+
toolCompleted: 'Tool completed',
|
|
20
|
+
waitingApproval: 'Waiting for approval',
|
|
21
|
+
approvalExpired: 'Approval expired',
|
|
22
|
+
approvalSent: 'Approval sent',
|
|
23
|
+
requestDenied: 'Request denied',
|
|
24
|
+
subagentWorking: 'Subagent working',
|
|
25
|
+
subagentCompleted: 'Subagent completed',
|
|
26
|
+
completed: 'Completed',
|
|
27
|
+
stopped: 'Stopped',
|
|
28
|
+
failed: 'Failed',
|
|
29
|
+
runFailed: 'Could not start run',
|
|
30
|
+
loadFailed: 'Could not load conversation',
|
|
31
|
+
};
|
|
32
|
+
const json = (value) => {
|
|
33
|
+
try {
|
|
34
|
+
return JSON.stringify(value);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return String(value);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const defaultFormat = {
|
|
41
|
+
truncate: (text, max) => (text.length > max ? `${text.slice(0, max)}…` : text),
|
|
42
|
+
toolCall: (toolName, args) => `⚙ ${toolName}(${defaultFormat.truncate(json(args ?? {}), 120)})`,
|
|
43
|
+
toolResult: (toolName, result) => `↳ ${toolName ? `${toolName}: ` : ''}${defaultFormat.truncate(json(result), 220)}`,
|
|
44
|
+
subagentStarted: (name) => `▸ subagent "${name}" started`,
|
|
45
|
+
};
|
|
46
|
+
/** The default: a `threadId` query parameter so a conversation is linkable,
|
|
47
|
+
* backed by localStorage so a bare visit reopens the last one. */
|
|
48
|
+
export function browserPersistence(storageKey = 'use-agentenkit:last-thread') {
|
|
49
|
+
const canUseDom = () => typeof window !== 'undefined';
|
|
50
|
+
const read = () => {
|
|
51
|
+
try {
|
|
52
|
+
return window.localStorage.getItem(storageKey);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null; // private mode, or storage disabled
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
load: () => {
|
|
60
|
+
if (!canUseDom())
|
|
61
|
+
return undefined;
|
|
62
|
+
const fromUrl = new URLSearchParams(window.location.search).get('threadId');
|
|
63
|
+
return fromUrl || read() || undefined;
|
|
64
|
+
},
|
|
65
|
+
save: (threadId) => {
|
|
66
|
+
if (!canUseDom())
|
|
67
|
+
return;
|
|
68
|
+
try {
|
|
69
|
+
window.localStorage.setItem(storageKey, threadId);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// storage is a convenience; never break the conversation over it
|
|
73
|
+
}
|
|
74
|
+
const url = new URL(window.location.href);
|
|
75
|
+
url.searchParams.set('threadId', threadId);
|
|
76
|
+
window.history.replaceState({}, '', url);
|
|
77
|
+
},
|
|
78
|
+
clear: () => {
|
|
79
|
+
if (!canUseDom())
|
|
80
|
+
return;
|
|
81
|
+
try {
|
|
82
|
+
window.localStorage.removeItem(storageKey);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// as above
|
|
86
|
+
}
|
|
87
|
+
const url = new URL(window.location.href);
|
|
88
|
+
url.searchParams.delete('threadId');
|
|
89
|
+
window.history.replaceState({}, '', url);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export const browserEventStream = (url, { onMessage, onError }) => {
|
|
94
|
+
const source = new EventSource(url);
|
|
95
|
+
source.onmessage = (event) => onMessage(event.data);
|
|
96
|
+
source.onerror = (event) => onError(event);
|
|
97
|
+
return { close: () => source.close() };
|
|
98
|
+
};
|
|
99
|
+
export function resolveConfig(config = {}) {
|
|
100
|
+
// Hoisted: TypeScript cannot narrow `config.headers` inside the closure.
|
|
101
|
+
const headers = config.headers;
|
|
102
|
+
return {
|
|
103
|
+
routes: { ...defaultRoutes, ...config.routes },
|
|
104
|
+
baseUrl: config.baseUrl ?? '',
|
|
105
|
+
// Bound to globalThis: an unbound reference throws "Illegal invocation"
|
|
106
|
+
// in the browser.
|
|
107
|
+
fetch: config.fetch ?? ((...args) => globalThis.fetch(...args)),
|
|
108
|
+
headers: typeof headers === 'function' ? headers : () => headers ?? {},
|
|
109
|
+
openStream: config.openStream ?? browserEventStream,
|
|
110
|
+
defaultModel: config.defaultModel ?? 'gpt-4o',
|
|
111
|
+
persistence: config.persistence === false ? null : (config.persistence ?? browserPersistence()),
|
|
112
|
+
labels: { ...defaultLabels, ...config.labels },
|
|
113
|
+
format: { ...defaultFormat, ...config.format },
|
|
114
|
+
onEvent: config.onEvent,
|
|
115
|
+
threadsRefreshMs: config.threadsRefreshMs ?? 30_000,
|
|
116
|
+
loadThreadsOnMount: config.loadThreadsOnMount ?? true,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** Append query parameters without disturbing a relative path or a query the
|
|
120
|
+
* route already carries. `new URL` cannot be used here — it would force every
|
|
121
|
+
* route to be absolute. */
|
|
122
|
+
export function withQuery(path, params) {
|
|
123
|
+
const search = Object.entries(params)
|
|
124
|
+
.filter(([, value]) => value !== undefined)
|
|
125
|
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
|
|
126
|
+
.join('&');
|
|
127
|
+
if (!search)
|
|
128
|
+
return path;
|
|
129
|
+
return `${path}${path.includes('?') ? '&' : '?'}${search}`;
|
|
130
|
+
}
|
|
131
|
+
/** Resolve one route to a URL. A string gets the base prefix and the hook's
|
|
132
|
+
* standard query; a function is trusted to return a complete URL. */
|
|
133
|
+
export function routeUrl(route, params, baseUrl) {
|
|
134
|
+
if (typeof route === 'function')
|
|
135
|
+
return route(params);
|
|
136
|
+
return withQuery(baseUrl + route, params);
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAoCA,MAAM,CAAC,MAAM,aAAa,GAAgB;IACxC,GAAG,EAAE,gBAAgB;IACrB,IAAI,EAAE,oBAAoB;IAC1B,OAAO,EAAE,oBAAoB;IAC7B,MAAM,EAAE,mBAAmB;IAC3B,OAAO,EAAE,oBAAoB;IAC7B,KAAK,EAAE,kBAAkB;IACzB,OAAO,EAAE,cAAc;IACvB,YAAY,EAAE,cAAc;CAC7B,CAAC;AA0BF,MAAM,CAAC,MAAM,aAAa,GAAmB;IAC3C,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,sBAAsB;IAC/B,QAAQ,EAAE,UAAU;IACpB,UAAU,EAAE,YAAY;IACxB,gBAAgB,EAAE,mBAAmB;IACrC,iBAAiB,EAAE,qBAAqB;IACxC,WAAW,EAAE,cAAc;IAC3B,aAAa,EAAE,gBAAgB;IAC/B,eAAe,EAAE,sBAAsB;IACvC,eAAe,EAAE,kBAAkB;IACnC,YAAY,EAAE,eAAe;IAC7B,aAAa,EAAE,gBAAgB;IAC/B,eAAe,EAAE,kBAAkB;IACnC,iBAAiB,EAAE,oBAAoB;IACvC,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,qBAAqB;IA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,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AgentRunConfig } from './config.js';
|
|
2
|
+
/** Holds the RAW config, not a resolved one: a hook's own options are merged
|
|
3
|
+
* over it before defaults are applied, so a component can override one route
|
|
4
|
+
* without restating the rest. */
|
|
5
|
+
export declare const AgentRunContext: import("react").Context<AgentRunConfig | null>;
|
|
6
|
+
/** The config from the nearest provider, if there is one. */
|
|
7
|
+
export declare function useAgentRunConfig(): AgentRunConfig | null;
|
|
8
|
+
/** Later wins, per section — so `{ routes: { run } }` replaces only `run`. */
|
|
9
|
+
export declare function mergeConfig(base: AgentRunConfig | null, over: AgentRunConfig): AgentRunConfig;
|
|
10
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;kCAEkC;AAClC,eAAO,MAAM,eAAe,gDAA6C,CAAC;AAE1E,6DAA6D;AAC7D,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,IAAI,CAEzD;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CACzB,IAAI,EAAE,cAAc,GAAG,IAAI,EAC3B,IAAI,EAAE,cAAc,GACnB,cAAc,CAShB"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createContext, useContext } from 'react';
|
|
3
|
+
/** Holds the RAW config, not a resolved one: a hook's own options are merged
|
|
4
|
+
* over it before defaults are applied, so a component can override one route
|
|
5
|
+
* without restating the rest. */
|
|
6
|
+
export const AgentRunContext = createContext(null);
|
|
7
|
+
/** The config from the nearest provider, if there is one. */
|
|
8
|
+
export function useAgentRunConfig() {
|
|
9
|
+
return useContext(AgentRunContext);
|
|
10
|
+
}
|
|
11
|
+
/** Later wins, per section — so `{ routes: { run } }` replaces only `run`. */
|
|
12
|
+
export function mergeConfig(base, over) {
|
|
13
|
+
if (!base)
|
|
14
|
+
return over;
|
|
15
|
+
return {
|
|
16
|
+
...base,
|
|
17
|
+
...over,
|
|
18
|
+
routes: { ...base.routes, ...over.routes },
|
|
19
|
+
labels: { ...base.labels, ...over.labels },
|
|
20
|
+
format: { ...base.format, ...over.format },
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAGlD;;kCAEkC;AAClC,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAwB,IAAI,CAAC,CAAC;AAE1E,6DAA6D;AAC7D,MAAM,UAAU,iBAAiB;IAC/B,OAAO,UAAU,CAAC,eAAe,CAAC,CAAC;AACrC,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,WAAW,CACzB,IAA2B,EAC3B,IAAoB;IAEpB,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,OAAO;QACL,GAAG,IAAI;QACP,GAAG,IAAI;QACP,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE;QAC1C,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE;QAC1C,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE;KAC3C,CAAC;AACJ,CAAC"}
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ActivityLabels, EntryFormat } from './config.js';
|
|
2
|
+
import type { AgentActivity, AgentState, ChatEntry, SnapshotMessage } from './types.js';
|
|
3
|
+
/** Flatten AI-SDK message content into something a bubble can render. */
|
|
4
|
+
export declare function contentToText(content: unknown, format: EntryFormat): string;
|
|
5
|
+
/** One durable message → one entry, or null when it carries nothing to show.
|
|
6
|
+
* A message that is only tool activity is marked `kind: 'tool'` so a UI can
|
|
7
|
+
* style it apart from conversation. */
|
|
8
|
+
export declare function messageToEntry(message: SnapshotMessage, format: EntryFormat): ChatEntry | null;
|
|
9
|
+
/** The model's thinking, as persisted on a message. Providers that do not
|
|
10
|
+
* expose it simply have no such parts, and this returns ''. */
|
|
11
|
+
export declare function reasoningText(content: unknown): string;
|
|
12
|
+
/** One durable message → the entries it renders as: its thinking first, then
|
|
13
|
+
* the answer. Split because they stream separately and a UI folds thinking
|
|
14
|
+
* away, so keeping them in one bubble would make a reload look different from
|
|
15
|
+
* the live run. */
|
|
16
|
+
export declare function messageToEntries(message: SnapshotMessage, format: EntryFormat): ChatEntry[];
|
|
17
|
+
/** The activity a thread state implies when nothing more specific is happening. */
|
|
18
|
+
export declare function stateActivity(state: AgentState, labels: ActivityLabels): AgentActivity;
|
|
19
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAUxF,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,MAAM,CAiB3E;AAED;;wCAEwC;AACxC,wBAAgB,cAAc,CAC5B,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,WAAW,GAClB,SAAS,GAAG,IAAI,CAoBlB;AAED;gEACgE;AAChE,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAMtD;AAED;;;oBAGoB;AACpB,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,EAAE,CAe3F;AAED,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,GAAG,aAAa,CAetF"}
|