@hsb3/carbon-agui-adapter 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/README.md +102 -0
- package/dist/adapter.d.ts +104 -0
- package/dist/adapter.js +557 -0
- package/dist/coverage.d.ts +25 -0
- package/dist/coverage.js +82 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/transport.d.ts +22 -0
- package/dist/transport.js +93 -0
- package/dist/types.d.ts +460 -0
- package/dist/types.js +5 -0
- package/dist/validate.d.ts +28 -0
- package/dist/validate.js +99 -0
- package/package.json +41 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AgUiEvent, AgUiRunner } from './types.js';
|
|
2
|
+
export interface SseRunnerOptions {
|
|
3
|
+
url: string;
|
|
4
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
5
|
+
fetch?: typeof fetch;
|
|
6
|
+
}
|
|
7
|
+
/** POST RunAgentInput as JSON, read back `text/event-stream` of AG-UI events. */
|
|
8
|
+
export declare function createSseRunner(opts: SseRunnerOptions): AgUiRunner;
|
|
9
|
+
/** Parse an SSE byte stream into AG-UI events (one JSON object per `data:` block). */
|
|
10
|
+
export declare function parseSse(body: ReadableStream<Uint8Array>): AsyncGenerator<AgUiEvent>;
|
|
11
|
+
/** Minimal rxjs-compatible shape, so `@ag-ui/client`'s `agent.run(input)` plugs in without importing rxjs here. */
|
|
12
|
+
export interface ObservableLike<T> {
|
|
13
|
+
subscribe(observer: {
|
|
14
|
+
next: (v: T) => void;
|
|
15
|
+
error: (e: unknown) => void;
|
|
16
|
+
complete: () => void;
|
|
17
|
+
}): {
|
|
18
|
+
unsubscribe(): void;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Bridge an Observable (e.g. `new HttpAgent({url}).run(input)`) to the AsyncIterable the adapter consumes. */
|
|
22
|
+
export declare function fromObservable<T>(obs: ObservableLike<T>, signal?: AbortSignal): AsyncGenerator<T>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** POST RunAgentInput as JSON, read back `text/event-stream` of AG-UI events. */
|
|
2
|
+
export function createSseRunner(opts) {
|
|
3
|
+
const doFetch = opts.fetch ?? globalThis.fetch;
|
|
4
|
+
return async function* (input, { signal }) {
|
|
5
|
+
const extra = typeof opts.headers === 'function' ? await opts.headers() : opts.headers ?? {};
|
|
6
|
+
const res = await doFetch(opts.url, {
|
|
7
|
+
method: 'POST',
|
|
8
|
+
headers: { 'content-type': 'application/json', accept: 'text/event-stream', ...extra },
|
|
9
|
+
body: JSON.stringify(input),
|
|
10
|
+
signal,
|
|
11
|
+
});
|
|
12
|
+
if (!res.ok || !res.body)
|
|
13
|
+
throw new Error(`AG-UI request failed: HTTP ${res.status}`);
|
|
14
|
+
yield* parseSse(res.body);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** Parse an SSE byte stream into AG-UI events (one JSON object per `data:` block). */
|
|
18
|
+
export async function* parseSse(body) {
|
|
19
|
+
const reader = body.getReader();
|
|
20
|
+
const decoder = new TextDecoder();
|
|
21
|
+
let buf = '';
|
|
22
|
+
const drain = function* (final) {
|
|
23
|
+
let idx;
|
|
24
|
+
while ((idx = buf.indexOf('\n\n')) !== -1) {
|
|
25
|
+
const block = buf.slice(0, idx);
|
|
26
|
+
buf = buf.slice(idx + 2);
|
|
27
|
+
const ev = parseBlock(block);
|
|
28
|
+
if (ev)
|
|
29
|
+
yield ev;
|
|
30
|
+
}
|
|
31
|
+
if (final && buf.trim()) {
|
|
32
|
+
const ev = parseBlock(buf);
|
|
33
|
+
buf = '';
|
|
34
|
+
if (ev)
|
|
35
|
+
yield ev;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
try {
|
|
39
|
+
for (;;) {
|
|
40
|
+
const { done, value } = await reader.read();
|
|
41
|
+
if (done)
|
|
42
|
+
break;
|
|
43
|
+
buf += decoder.decode(value, { stream: true }).replace(/\r\n/g, '\n');
|
|
44
|
+
yield* drain(false);
|
|
45
|
+
}
|
|
46
|
+
buf += decoder.decode();
|
|
47
|
+
yield* drain(true);
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
reader.releaseLock();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function parseBlock(block) {
|
|
54
|
+
const data = block
|
|
55
|
+
.split('\n')
|
|
56
|
+
.filter((l) => l.startsWith('data:'))
|
|
57
|
+
.map((l) => l.slice(5).replace(/^ /, ''))
|
|
58
|
+
.join('\n');
|
|
59
|
+
return data ? JSON.parse(data) : null;
|
|
60
|
+
}
|
|
61
|
+
/** Bridge an Observable (e.g. `new HttpAgent({url}).run(input)`) to the AsyncIterable the adapter consumes. */
|
|
62
|
+
export async function* fromObservable(obs, signal) {
|
|
63
|
+
const queue = [];
|
|
64
|
+
let done = false;
|
|
65
|
+
let error;
|
|
66
|
+
let wake;
|
|
67
|
+
const notify = () => { wake?.(); wake = undefined; };
|
|
68
|
+
const sub = obs.subscribe({
|
|
69
|
+
next: (v) => { queue.push(v); notify(); },
|
|
70
|
+
error: (e) => { error = e; done = true; notify(); },
|
|
71
|
+
complete: () => { done = true; notify(); },
|
|
72
|
+
});
|
|
73
|
+
const onAbort = () => { error = signal?.reason ?? new Error('aborted'); done = true; notify(); };
|
|
74
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
75
|
+
try {
|
|
76
|
+
for (;;) {
|
|
77
|
+
if (queue.length) {
|
|
78
|
+
yield queue.shift();
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (done) {
|
|
82
|
+
if (error !== undefined)
|
|
83
|
+
throw error;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
await new Promise((r) => { wake = r; });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
sub.unsubscribe();
|
|
91
|
+
signal?.removeEventListener('abort', onAbort);
|
|
92
|
+
}
|
|
93
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
export type AgUiRole = 'developer' | 'system' | 'assistant' | 'user' | 'tool';
|
|
2
|
+
export interface AgUiToolCall {
|
|
3
|
+
id: string;
|
|
4
|
+
type: 'function';
|
|
5
|
+
function: {
|
|
6
|
+
name: string;
|
|
7
|
+
arguments: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface AgUiMessage {
|
|
11
|
+
id: string;
|
|
12
|
+
role: AgUiRole;
|
|
13
|
+
content?: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
toolCalls?: AgUiToolCall[];
|
|
16
|
+
toolCallId?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface AgUiTool {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
parameters: unknown;
|
|
22
|
+
}
|
|
23
|
+
export interface AgUiContext {
|
|
24
|
+
description: string;
|
|
25
|
+
value: string;
|
|
26
|
+
}
|
|
27
|
+
export interface RunAgentInput {
|
|
28
|
+
threadId: string;
|
|
29
|
+
runId: string;
|
|
30
|
+
state: unknown;
|
|
31
|
+
messages: AgUiMessage[];
|
|
32
|
+
tools: AgUiTool[];
|
|
33
|
+
context: AgUiContext[];
|
|
34
|
+
forwardedProps: unknown;
|
|
35
|
+
/** Resume a suspended run (LangGraph interrupt). One entry per interrupt. */
|
|
36
|
+
resume?: ResumeEntry[];
|
|
37
|
+
}
|
|
38
|
+
/** A single LangGraph interrupt, as promoted into `RUN_FINISHED.outcome`. */
|
|
39
|
+
export interface Interrupt {
|
|
40
|
+
id: string;
|
|
41
|
+
reason?: string;
|
|
42
|
+
message?: string;
|
|
43
|
+
toolCallId?: string;
|
|
44
|
+
/** Graph-supplied JSON schema for the expected resume payload. */
|
|
45
|
+
responseSchema?: unknown;
|
|
46
|
+
/** The original `interrupt()` value verbatim lives under langgraph.raw. */
|
|
47
|
+
metadata?: {
|
|
48
|
+
langgraph?: {
|
|
49
|
+
raw?: {
|
|
50
|
+
action?: string;
|
|
51
|
+
args?: Record<string, unknown>;
|
|
52
|
+
message?: string;
|
|
53
|
+
[k: string]: unknown;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** `RUN_FINISHED.outcome` — only the interrupt variant is handled here. */
|
|
59
|
+
export interface RunOutcome {
|
|
60
|
+
type: string;
|
|
61
|
+
interrupts?: Interrupt[];
|
|
62
|
+
}
|
|
63
|
+
export type ResumeStatus = 'resolved' | 'cancelled';
|
|
64
|
+
/** One resume decision on the wire (`RunAgentInput.resume[]`). */
|
|
65
|
+
export interface ResumeEntry {
|
|
66
|
+
interruptId: string;
|
|
67
|
+
status: ResumeStatus;
|
|
68
|
+
payload: unknown;
|
|
69
|
+
}
|
|
70
|
+
/** A user's decision on an interrupt. Edit carries the overriding args. */
|
|
71
|
+
export type Decision = {
|
|
72
|
+
type: 'approve';
|
|
73
|
+
} | {
|
|
74
|
+
type: 'edit';
|
|
75
|
+
args: Record<string, unknown>;
|
|
76
|
+
} | {
|
|
77
|
+
type: 'reject';
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Payload carried in the Carbon `user_defined` item's `user_defined` field so a
|
|
81
|
+
* host renderer can draw the approve/reject/edit card. `kind` discriminates it
|
|
82
|
+
* from any other user_defined response the host may render.
|
|
83
|
+
*/
|
|
84
|
+
export interface InterruptDecisionData {
|
|
85
|
+
kind: 'interrupt';
|
|
86
|
+
interruptId: string;
|
|
87
|
+
message?: string;
|
|
88
|
+
action?: string;
|
|
89
|
+
args?: Record<string, unknown>;
|
|
90
|
+
responseSchema?: unknown;
|
|
91
|
+
toolCallId?: string;
|
|
92
|
+
}
|
|
93
|
+
export interface JsonPatchOp {
|
|
94
|
+
op: 'add' | 'remove' | 'replace' | 'move' | 'copy' | 'test';
|
|
95
|
+
path: string;
|
|
96
|
+
value?: unknown;
|
|
97
|
+
from?: string;
|
|
98
|
+
}
|
|
99
|
+
export type AgUiEvent = {
|
|
100
|
+
type: 'RUN_STARTED';
|
|
101
|
+
threadId: string;
|
|
102
|
+
runId: string;
|
|
103
|
+
} | {
|
|
104
|
+
type: 'RUN_FINISHED';
|
|
105
|
+
threadId: string;
|
|
106
|
+
runId: string;
|
|
107
|
+
result?: unknown;
|
|
108
|
+
outcome?: RunOutcome;
|
|
109
|
+
} | {
|
|
110
|
+
type: 'RUN_ERROR';
|
|
111
|
+
message: string;
|
|
112
|
+
code?: string;
|
|
113
|
+
} | {
|
|
114
|
+
type: 'STEP_STARTED';
|
|
115
|
+
stepName: string;
|
|
116
|
+
} | {
|
|
117
|
+
type: 'STEP_FINISHED';
|
|
118
|
+
stepName: string;
|
|
119
|
+
} | {
|
|
120
|
+
type: 'TEXT_MESSAGE_START';
|
|
121
|
+
messageId: string;
|
|
122
|
+
role: 'assistant';
|
|
123
|
+
} | {
|
|
124
|
+
type: 'TEXT_MESSAGE_CONTENT';
|
|
125
|
+
messageId: string;
|
|
126
|
+
delta: string;
|
|
127
|
+
} | {
|
|
128
|
+
type: 'TEXT_MESSAGE_END';
|
|
129
|
+
messageId: string;
|
|
130
|
+
} | {
|
|
131
|
+
type: 'TEXT_MESSAGE_CHUNK';
|
|
132
|
+
messageId?: string;
|
|
133
|
+
role?: 'assistant';
|
|
134
|
+
delta?: string;
|
|
135
|
+
} | {
|
|
136
|
+
type: 'TOOL_CALL_START';
|
|
137
|
+
toolCallId: string;
|
|
138
|
+
toolCallName: string;
|
|
139
|
+
parentMessageId?: string;
|
|
140
|
+
} | {
|
|
141
|
+
type: 'TOOL_CALL_ARGS';
|
|
142
|
+
toolCallId: string;
|
|
143
|
+
delta: string;
|
|
144
|
+
} | {
|
|
145
|
+
type: 'TOOL_CALL_END';
|
|
146
|
+
toolCallId: string;
|
|
147
|
+
} | {
|
|
148
|
+
type: 'TOOL_CALL_CHUNK';
|
|
149
|
+
toolCallId?: string;
|
|
150
|
+
toolCallName?: string;
|
|
151
|
+
parentMessageId?: string;
|
|
152
|
+
delta?: string;
|
|
153
|
+
} | {
|
|
154
|
+
type: 'TOOL_CALL_RESULT';
|
|
155
|
+
messageId: string;
|
|
156
|
+
toolCallId: string;
|
|
157
|
+
content: string;
|
|
158
|
+
role?: 'tool';
|
|
159
|
+
} | {
|
|
160
|
+
type: 'STATE_SNAPSHOT';
|
|
161
|
+
snapshot: unknown;
|
|
162
|
+
} | {
|
|
163
|
+
type: 'STATE_DELTA';
|
|
164
|
+
delta: JsonPatchOp[];
|
|
165
|
+
} | {
|
|
166
|
+
type: 'MESSAGES_SNAPSHOT';
|
|
167
|
+
messages: AgUiMessage[];
|
|
168
|
+
} | {
|
|
169
|
+
type: 'REASONING_START';
|
|
170
|
+
messageId: string;
|
|
171
|
+
} | {
|
|
172
|
+
type: 'REASONING_END';
|
|
173
|
+
messageId: string;
|
|
174
|
+
} | {
|
|
175
|
+
type: 'REASONING_MESSAGE_START';
|
|
176
|
+
messageId: string;
|
|
177
|
+
role: 'reasoning';
|
|
178
|
+
} | {
|
|
179
|
+
type: 'REASONING_MESSAGE_CONTENT';
|
|
180
|
+
messageId: string;
|
|
181
|
+
delta: string;
|
|
182
|
+
} | {
|
|
183
|
+
type: 'REASONING_MESSAGE_END';
|
|
184
|
+
messageId: string;
|
|
185
|
+
} | {
|
|
186
|
+
type: 'REASONING_MESSAGE_CHUNK';
|
|
187
|
+
messageId?: string;
|
|
188
|
+
delta?: string;
|
|
189
|
+
} | {
|
|
190
|
+
type: 'REASONING_ENCRYPTED_VALUE';
|
|
191
|
+
subtype: 'tool-call' | 'message';
|
|
192
|
+
entityId: string;
|
|
193
|
+
encryptedValue: string;
|
|
194
|
+
} | {
|
|
195
|
+
type: 'ACTIVITY_SNAPSHOT';
|
|
196
|
+
messageId: string;
|
|
197
|
+
activityType: string;
|
|
198
|
+
content: Record<string, unknown>;
|
|
199
|
+
replace?: boolean;
|
|
200
|
+
} | {
|
|
201
|
+
type: 'ACTIVITY_DELTA';
|
|
202
|
+
messageId: string;
|
|
203
|
+
activityType: string;
|
|
204
|
+
patch: JsonPatchOp[];
|
|
205
|
+
} | {
|
|
206
|
+
type: 'THINKING_START';
|
|
207
|
+
title?: string;
|
|
208
|
+
} | {
|
|
209
|
+
type: 'THINKING_END';
|
|
210
|
+
} | {
|
|
211
|
+
type: 'THINKING_TEXT_MESSAGE_START';
|
|
212
|
+
} | {
|
|
213
|
+
type: 'THINKING_TEXT_MESSAGE_CONTENT';
|
|
214
|
+
delta: string;
|
|
215
|
+
} | {
|
|
216
|
+
type: 'THINKING_TEXT_MESSAGE_END';
|
|
217
|
+
} | {
|
|
218
|
+
type: 'RAW';
|
|
219
|
+
event: unknown;
|
|
220
|
+
source?: string;
|
|
221
|
+
} | {
|
|
222
|
+
type: 'CUSTOM';
|
|
223
|
+
name: string;
|
|
224
|
+
value: unknown;
|
|
225
|
+
};
|
|
226
|
+
/** Transport: given a run input, yield AG-UI events. Must respect `signal`. */
|
|
227
|
+
export type AgUiRunner = (input: RunAgentInput, opts: {
|
|
228
|
+
signal?: AbortSignal;
|
|
229
|
+
}) => AsyncIterable<AgUiEvent>;
|
|
230
|
+
export interface CarbonMessageRequest {
|
|
231
|
+
id?: string;
|
|
232
|
+
input: {
|
|
233
|
+
text?: string;
|
|
234
|
+
};
|
|
235
|
+
thread_id?: string;
|
|
236
|
+
}
|
|
237
|
+
export interface CarbonItemStreamingMetadata {
|
|
238
|
+
id: string;
|
|
239
|
+
stream_stopped?: boolean;
|
|
240
|
+
cancellable?: boolean;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Mirrors Carbon's `GenericItemMessageFeedbackOptions` — thumbs-up/down config.
|
|
244
|
+
* Attaches per-item via `message_item_options.feedback` (NOT per-response
|
|
245
|
+
* message_options). `is_on` toggles the control; `id` is required for the
|
|
246
|
+
* feedback to persist in history. carbon-compat.ts proves this lines up.
|
|
247
|
+
*/
|
|
248
|
+
export interface CarbonMessageFeedbackOptions {
|
|
249
|
+
is_on?: boolean;
|
|
250
|
+
id?: string;
|
|
251
|
+
categories?: string[] | {
|
|
252
|
+
positive?: string[];
|
|
253
|
+
negative?: string[];
|
|
254
|
+
};
|
|
255
|
+
max_length?: number;
|
|
256
|
+
title?: string;
|
|
257
|
+
prompt?: string;
|
|
258
|
+
placeholder?: string;
|
|
259
|
+
}
|
|
260
|
+
export interface CarbonGenericItem {
|
|
261
|
+
response_type: string;
|
|
262
|
+
streaming_metadata?: CarbonItemStreamingMetadata;
|
|
263
|
+
text?: string;
|
|
264
|
+
/** Carbon's `UserDefinedItem.user_defined` bucket — arbitrary host payload. */
|
|
265
|
+
user_defined?: Record<string, unknown>;
|
|
266
|
+
/** Carbon's per-item `message_item_options` — carries feedback (thumbs) config. */
|
|
267
|
+
message_item_options?: {
|
|
268
|
+
feedback?: CarbonMessageFeedbackOptions;
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
export interface CarbonTextItem extends CarbonGenericItem {
|
|
272
|
+
response_type: 'text';
|
|
273
|
+
text: string;
|
|
274
|
+
}
|
|
275
|
+
/** A Carbon `user_defined` response item; the host renders it via `renderUserDefinedResponse`. */
|
|
276
|
+
export interface CarbonUserDefinedItem extends CarbonGenericItem {
|
|
277
|
+
response_type: 'user_defined';
|
|
278
|
+
user_defined: Record<string, unknown>;
|
|
279
|
+
}
|
|
280
|
+
/** Carbon `button` item. `button_type` runtime values: post_back | custom_event | show_panel | url. */
|
|
281
|
+
export interface CarbonButtonItem extends CarbonGenericItem {
|
|
282
|
+
response_type: 'button';
|
|
283
|
+
button_type: string;
|
|
284
|
+
label?: string;
|
|
285
|
+
url?: string;
|
|
286
|
+
kind?: string;
|
|
287
|
+
}
|
|
288
|
+
/** Carbon `card` item — a container that renders nested response items. */
|
|
289
|
+
export interface CarbonCardItem extends CarbonGenericItem {
|
|
290
|
+
response_type: 'card';
|
|
291
|
+
body?: CarbonGenericItem[];
|
|
292
|
+
footer?: CarbonGenericItem[];
|
|
293
|
+
max_width?: string;
|
|
294
|
+
}
|
|
295
|
+
/** Carbon `option` item — a list of choices rendered as buttons or a dropdown. */
|
|
296
|
+
export interface CarbonOptionItem extends CarbonGenericItem {
|
|
297
|
+
response_type: 'option';
|
|
298
|
+
options: {
|
|
299
|
+
label: string;
|
|
300
|
+
value: {
|
|
301
|
+
input: {
|
|
302
|
+
text?: string;
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
}[];
|
|
306
|
+
title?: string;
|
|
307
|
+
description?: string;
|
|
308
|
+
}
|
|
309
|
+
/** Carbon `image` item. */
|
|
310
|
+
export interface CarbonImageItem extends CarbonGenericItem {
|
|
311
|
+
response_type: 'image';
|
|
312
|
+
source: string;
|
|
313
|
+
title?: string;
|
|
314
|
+
description?: string;
|
|
315
|
+
alt_text?: string;
|
|
316
|
+
}
|
|
317
|
+
/** Carbon `video` item. */
|
|
318
|
+
export interface CarbonVideoItem extends CarbonGenericItem {
|
|
319
|
+
response_type: 'video';
|
|
320
|
+
source: string;
|
|
321
|
+
title?: string;
|
|
322
|
+
description?: string;
|
|
323
|
+
alt_text?: string;
|
|
324
|
+
}
|
|
325
|
+
/** Carbon `audio` item. */
|
|
326
|
+
export interface CarbonAudioItem extends CarbonGenericItem {
|
|
327
|
+
response_type: 'audio';
|
|
328
|
+
source: string;
|
|
329
|
+
title?: string;
|
|
330
|
+
description?: string;
|
|
331
|
+
alt_text?: string;
|
|
332
|
+
}
|
|
333
|
+
/** Carbon `iframe` item. */
|
|
334
|
+
export interface CarbonIFrameItem extends CarbonGenericItem {
|
|
335
|
+
response_type: 'iframe';
|
|
336
|
+
source: string;
|
|
337
|
+
title?: string;
|
|
338
|
+
description?: string;
|
|
339
|
+
}
|
|
340
|
+
/** Carbon `date` item — prompts a date picker; carries no fields beyond the base. */
|
|
341
|
+
export interface CarbonDateItem extends CarbonGenericItem {
|
|
342
|
+
response_type: 'date';
|
|
343
|
+
}
|
|
344
|
+
/** Carbon `pause` item — a rendering pause before subsequent items. */
|
|
345
|
+
export interface CarbonPauseItem extends CarbonGenericItem {
|
|
346
|
+
response_type: 'pause';
|
|
347
|
+
time?: number;
|
|
348
|
+
typing?: boolean;
|
|
349
|
+
}
|
|
350
|
+
/** Carbon `inline_error` item — a user-friendly inline error message. */
|
|
351
|
+
export interface CarbonInlineErrorItem extends CarbonGenericItem {
|
|
352
|
+
response_type: 'inline_error';
|
|
353
|
+
text?: string;
|
|
354
|
+
}
|
|
355
|
+
/** Carbon `system` item — a status / informational system line. */
|
|
356
|
+
export interface CarbonSystemMessageItem extends CarbonGenericItem {
|
|
357
|
+
response_type: 'system';
|
|
358
|
+
title: string;
|
|
359
|
+
variant?: 'default' | 'date' | 'agent';
|
|
360
|
+
}
|
|
361
|
+
/** Carbon `carousel` item — a horizontally-scrolling set of nested items. */
|
|
362
|
+
export interface CarbonCarouselItem extends CarbonGenericItem {
|
|
363
|
+
response_type: 'carousel';
|
|
364
|
+
items: CarbonGenericItem[];
|
|
365
|
+
}
|
|
366
|
+
/** Carbon `grid` item — a column/row layout of nested items. */
|
|
367
|
+
export interface CarbonGridItem extends CarbonGenericItem {
|
|
368
|
+
response_type: 'grid';
|
|
369
|
+
columns: {
|
|
370
|
+
width: string;
|
|
371
|
+
}[];
|
|
372
|
+
rows: {
|
|
373
|
+
cells: {
|
|
374
|
+
items: CarbonGenericItem[];
|
|
375
|
+
}[];
|
|
376
|
+
}[];
|
|
377
|
+
}
|
|
378
|
+
/** Carbon `preview_card` item — a card that can trigger a workspace view. */
|
|
379
|
+
export interface CarbonPreviewCardItem extends CarbonGenericItem {
|
|
380
|
+
response_type: 'preview_card';
|
|
381
|
+
workspace_id: string;
|
|
382
|
+
title?: string;
|
|
383
|
+
subtitle?: string;
|
|
384
|
+
}
|
|
385
|
+
/** Carbon `conversational_search` item — AI text with optional source citations. */
|
|
386
|
+
export interface CarbonConversationalSearchItem extends CarbonGenericItem {
|
|
387
|
+
response_type: 'conversational_search';
|
|
388
|
+
text: string;
|
|
389
|
+
citations?: {
|
|
390
|
+
url?: string;
|
|
391
|
+
text?: string;
|
|
392
|
+
title?: string;
|
|
393
|
+
}[];
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Every Carbon response item the adapter can emit, discriminated by
|
|
397
|
+
* `response_type`. Carbon renders each natively except `user_defined`.
|
|
398
|
+
*/
|
|
399
|
+
export type CarbonResponseItem = CarbonTextItem | CarbonUserDefinedItem | CarbonButtonItem | CarbonCardItem | CarbonOptionItem | CarbonImageItem | CarbonVideoItem | CarbonAudioItem | CarbonIFrameItem | CarbonDateItem | CarbonPauseItem | CarbonInlineErrorItem | CarbonSystemMessageItem | CarbonCarouselItem | CarbonGridItem | CarbonPreviewCardItem | CarbonConversationalSearchItem;
|
|
400
|
+
/** Maps to Carbon's ChainOfThoughtStep — how Carbon renders tool calls. */
|
|
401
|
+
export interface CarbonChainOfThoughtStep {
|
|
402
|
+
title?: string;
|
|
403
|
+
description?: string;
|
|
404
|
+
tool_name?: string;
|
|
405
|
+
request?: {
|
|
406
|
+
args?: unknown;
|
|
407
|
+
};
|
|
408
|
+
response?: {
|
|
409
|
+
content: unknown;
|
|
410
|
+
};
|
|
411
|
+
status?: 'processing' | 'failure' | 'success';
|
|
412
|
+
}
|
|
413
|
+
/** Maps to Carbon's ReasoningStep. `content` mirrors Carbon's `string | GenericItem[]`; the adapter only emits the string form. */
|
|
414
|
+
export interface CarbonReasoningStep {
|
|
415
|
+
title: string;
|
|
416
|
+
open_state?: 'open' | 'close' | 'default';
|
|
417
|
+
content?: string | CarbonGenericItem[];
|
|
418
|
+
}
|
|
419
|
+
/** Maps to Carbon's ReasoningSteps — the reasoning sibling of chain_of_thought. */
|
|
420
|
+
export interface CarbonReasoningSteps {
|
|
421
|
+
open_state?: 'open' | 'close' | 'default';
|
|
422
|
+
steps?: CarbonReasoningStep[];
|
|
423
|
+
content?: string | CarbonGenericItem[];
|
|
424
|
+
}
|
|
425
|
+
export interface CarbonMessageResponse {
|
|
426
|
+
id?: string;
|
|
427
|
+
request_id?: string;
|
|
428
|
+
output: {
|
|
429
|
+
generic?: CarbonGenericItem[];
|
|
430
|
+
};
|
|
431
|
+
thread_id?: string;
|
|
432
|
+
message_options?: {
|
|
433
|
+
chain_of_thought?: CarbonChainOfThoughtStep[];
|
|
434
|
+
reasoning?: CarbonReasoningSteps;
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
export type CarbonStreamChunk = {
|
|
438
|
+
partial_item: Partial<CarbonGenericItem>;
|
|
439
|
+
streaming_metadata?: {
|
|
440
|
+
response_id: string;
|
|
441
|
+
};
|
|
442
|
+
} | {
|
|
443
|
+
complete_item: CarbonGenericItem;
|
|
444
|
+
streaming_metadata?: {
|
|
445
|
+
response_id: string;
|
|
446
|
+
};
|
|
447
|
+
} | {
|
|
448
|
+
final_response: CarbonMessageResponse;
|
|
449
|
+
};
|
|
450
|
+
export interface CarbonSendMessageOptions {
|
|
451
|
+
signal?: AbortSignal;
|
|
452
|
+
silent?: boolean;
|
|
453
|
+
}
|
|
454
|
+
export interface CarbonChatInstanceLike {
|
|
455
|
+
messaging: {
|
|
456
|
+
addMessageChunk(chunk: CarbonStreamChunk): void | Promise<void>;
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
/** Shape of `PublicConfigMessaging.customSendMessage`. */
|
|
460
|
+
export type CarbonCustomSendMessage = (request: CarbonMessageRequest, options: CarbonSendMessageOptions, instance: CarbonChatInstanceLike) => Promise<void>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// AG-UI (https://docs.ag-ui.com) — structural mirror of @ag-ui/core.
|
|
3
|
+
// Kept local so the adapter has zero runtime deps; swap for @ag-ui/core if wanted.
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AgUiEvent, CarbonGenericItem } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* IN seam. Validate a raw runner event against the AG-UI protocol schema.
|
|
4
|
+
* On success the parsed value is a canonical event; the cast to the adapter's
|
|
5
|
+
* local `AgUiEvent` is justified because it was validated against the
|
|
6
|
+
* protocol's own union and the local type is a structural subset the switch
|
|
7
|
+
* handles. On failure, `error` is zod's error summary.
|
|
8
|
+
*/
|
|
9
|
+
export declare function validateAgUiEvent(raw: unknown): {
|
|
10
|
+
ok: true;
|
|
11
|
+
event: AgUiEvent;
|
|
12
|
+
} | {
|
|
13
|
+
ok: false;
|
|
14
|
+
error: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* OUT seam. Validate a raw CUSTOM-carried Carbon item before the adapter emits
|
|
18
|
+
* it: it must be an object, carry a `response_type` string in `known` (the
|
|
19
|
+
* adapter passes its KNOWN_CARBON_TYPES allowlist so this file needs no coverage
|
|
20
|
+
* import), and satisfy the required top-level fields for that response_type.
|
|
21
|
+
*/
|
|
22
|
+
export declare function validateCarbonItem(raw: unknown, known: Set<string>): {
|
|
23
|
+
ok: true;
|
|
24
|
+
item: CarbonGenericItem;
|
|
25
|
+
} | {
|
|
26
|
+
ok: false;
|
|
27
|
+
reason: string;
|
|
28
|
+
};
|