@pgege/kaboo-react 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.
@@ -0,0 +1,226 @@
1
+ import { ReactElement } from 'react';
2
+
3
+ /**
4
+ * A single tool invocation captured within an agent's activity group. One
5
+ * `ToolCall` maps to one AG-UI tool-call and carries enough state to render the
6
+ * live tool row, its input summary, and its result (or cancellation).
7
+ */
8
+ interface ToolCall {
9
+ /** AG-UI tool-call id. Stable key used to correlate rows, cards, and gates. */
10
+ toolUseId: string;
11
+ /** The tool's machine name (e.g. `run_sql`, `ask_user`). */
12
+ toolName: string;
13
+ /** Optional human-friendly label shown instead of `toolName`. */
14
+ toolLabel?: string;
15
+ /** The raw tool input (arbitrary JSON), summarized by the formatters. */
16
+ toolInput?: unknown;
17
+ /** The raw tool result, if the call has completed. */
18
+ toolResult?: string;
19
+ /** Lifecycle state of the call, driving the row's icon and status text. */
20
+ status: "running" | "done" | "success" | "error" | "cancelled";
21
+ }
22
+ /**
23
+ * One chronological entry in an agent's timeline: either a streamed text segment
24
+ * or a tool call, interleaved in the order they occurred.
25
+ */
26
+ type TimelineEntry = {
27
+ /** Discriminator: a streamed text segment. */
28
+ type: "text";
29
+ /** The streamed text for this segment. */
30
+ text: string;
31
+ } | {
32
+ /** Discriminator: a tool call. */
33
+ type: "tool";
34
+ /** The tool call for this entry. */
35
+ tool: ToolCall;
36
+ };
37
+ /**
38
+ * A single question in a human-in-the-loop form interrupt. `type` selects the
39
+ * input control; `options` supplies the choices for `radio`/`checkbox`.
40
+ */
41
+ interface FormQuestion {
42
+ /** The prompt text shown to the user. */
43
+ question: string;
44
+ /** Which input control to render for this question. */
45
+ type: "radio" | "checkbox" | "text";
46
+ /** Selectable choices for `radio`/`checkbox` questions. */
47
+ options?: string[];
48
+ }
49
+ /**
50
+ * An approval interrupt: the agent is asking the user to approve or reject a
51
+ * gated tool call before it runs.
52
+ */
53
+ interface ApprovalReason {
54
+ /** Discriminator marking this as an approval gate. */
55
+ type: "approval";
56
+ /** Human-readable description of what is being approved. */
57
+ message: string;
58
+ /** Name of the gated tool awaiting approval. */
59
+ tool_name: string;
60
+ /** The proposed tool input, shown for review. */
61
+ tool_input?: unknown;
62
+ }
63
+ /**
64
+ * A form interrupt: the agent is asking the user one or more questions and
65
+ * waiting for the answers before it continues.
66
+ */
67
+ interface FormReason {
68
+ /** Discriminator marking this as a form prompt. */
69
+ type: "form";
70
+ /** The questions to present, rendered in order. */
71
+ questions: FormQuestion[];
72
+ }
73
+ /**
74
+ * The reason a run paused for human input — either an {@link ApprovalReason}
75
+ * (approve/reject a gated tool) or a {@link FormReason} (answer questions).
76
+ */
77
+ type InterruptReason = ApprovalReason | FormReason;
78
+ /**
79
+ * A single open interrupt from the AG-UI run, as delivered by CopilotKit.
80
+ * Multiple can be open at once (e.g. parallel gates); each is resolved by `id`.
81
+ */
82
+ interface InterruptData {
83
+ /** Unique interrupt id, used to resolve this gate independently. */
84
+ id: string;
85
+ /** The interrupt's name (typically the originating tool name). */
86
+ name: string;
87
+ /** Why the run paused, and what input it needs. */
88
+ reason: InterruptReason;
89
+ }
90
+ /**
91
+ * Props for a custom interrupt renderer supplied via `interruptRenderers`.
92
+ * Receives the reason plus resolve/cancel callbacks so a bespoke UI can drive
93
+ * the gate.
94
+ */
95
+ interface InterruptRendererProps {
96
+ /** Why the run paused, and what input it needs. */
97
+ reason: InterruptReason;
98
+ /** Resume the run with the user's answer/approval payload. */
99
+ onResolve: (payload: unknown) => void;
100
+ /** Cancel/reject the gate, resuming the run without a positive answer. */
101
+ onCancel: () => void;
102
+ /**
103
+ * The interrupt's originating tool-call id, when available. Used to correlate
104
+ * the answered form with the durable tool-call card that renders the Q&A
105
+ * inline in the transcript.
106
+ */
107
+ toolCallId?: string;
108
+ }
109
+ /**
110
+ * One node of kaboo's hierarchical activity tree: a single agent run and its
111
+ * streamed text, tool calls, timeline, structured output, and (optional)
112
+ * open interrupt. Groups nest via {@link StreamGroup.parentGroup} to form the
113
+ * drill-down hierarchy.
114
+ */
115
+ interface StreamGroup {
116
+ /** Display title for the group's card. */
117
+ title: string;
118
+ /** The agent's machine name (used to correlate inline cards). */
119
+ agentName: string;
120
+ /** Parent group id, or `null` for a top-level group. */
121
+ parentGroup: string | null;
122
+ /**
123
+ * The delegating tool-call id (AG-UI `toolCallId`) that spawned this group.
124
+ * Stable key for correlating an inline chat card with its activity group.
125
+ * `null`/absent for the entry agent and non-delegated groups.
126
+ */
127
+ toolCallId?: string | null;
128
+ /**
129
+ * The AG-UI `runId` of the turn that produced this group. `null`/absent for
130
+ * older streams. Note: an interrupt/resume changes the `runId` mid-turn, so
131
+ * prefer {@link StreamGroup.turnId} for turn scoping.
132
+ */
133
+ runId?: string | null;
134
+ /**
135
+ * The logical turn that produced this group — stable across an
136
+ * interrupt/resume (server-stamped). All groups of one user turn share it, so
137
+ * the UI can bind them to that turn's single chat reply without fragmenting
138
+ * on `runId`. `null`/absent for older streams.
139
+ */
140
+ turnId?: string | null;
141
+ /**
142
+ * The task this agent was handed (its latest human/handoff message), shown at
143
+ * the top of the card so you can see what each agent was asked to do.
144
+ */
145
+ task?: string | null;
146
+ /**
147
+ * True when this agent's streamed text IS the chat reply (the swarm/graph
148
+ * `chat_output`, or a delegate manager). Inline cards suppress only this
149
+ * group's text so the answer isn't duplicated between the card and the bubble.
150
+ */
151
+ isChatReply?: boolean;
152
+ /**
153
+ * True for a plain-agent entry group: its text and tool calls are already
154
+ * rendered inline in the chat by the host (CopilotKit), so this group exists
155
+ * only to enrich those tool rows (labels, formatted results, error status)
156
+ * and must never be drawn as its own card.
157
+ */
158
+ inlineChatOwner?: boolean;
159
+ /** Lifecycle state of the group's run. */
160
+ status: "active" | "completed" | "error" | "interrupted";
161
+ /** Every tool call made in this group, in call order. */
162
+ tools: ToolCall[];
163
+ /** Accumulated streamed text tokens for this group. */
164
+ tokens: string;
165
+ /** Interleaved text/tool entries in chronological order. */
166
+ timeline: TimelineEntry[];
167
+ /** The open interrupt for this group, when it is paused for input. */
168
+ interrupt?: InterruptData;
169
+ /** Structured (schema-shaped) output emitted by the agent, if any. */
170
+ structuredOutput?: Record<string, unknown>;
171
+ /** Name of the schema for {@link StreamGroup.structuredOutput}, selecting a renderer. */
172
+ outputSchemaName?: string;
173
+ }
174
+ /**
175
+ * The full activity snapshot for a conversation: every {@link StreamGroup}
176
+ * keyed by group id. This is what {@link useActivity} exposes.
177
+ */
178
+ interface ActivityState {
179
+ /** All activity groups for the current thread, keyed by group id. */
180
+ groups: Record<string, StreamGroup>;
181
+ }
182
+ /**
183
+ * Drill-down navigation state: the current path into the activity tree plus the
184
+ * actions to move through it. Exposed by {@link useDrill}.
185
+ */
186
+ interface DrillState {
187
+ /** Group ids from root to the current level. */
188
+ drillPath: string[];
189
+ /** The deepest group id in the path, or `null` at the root. */
190
+ activeDrill: string | null;
191
+ /** Push a group id, descending one level. */
192
+ drillIn: (groupId: string) => void;
193
+ /** Pop the last group id, ascending one level. */
194
+ drillUp: () => void;
195
+ /** Clear the path, returning to the root. */
196
+ drillToRoot: () => void;
197
+ /** Trim the path to `level` (0-based), jumping to a breadcrumb. */
198
+ drillToLevel: (level: number) => void;
199
+ }
200
+
201
+ /** Props for {@link KabooInterruptHandler}. */
202
+ interface KabooInterruptHandlerProps {
203
+ /** Restrict handling to a single CopilotKit agent (optional). */
204
+ agentId?: string;
205
+ /** Per-interrupt-type renderer overrides. */
206
+ renderers?: Partial<Record<InterruptReason["type"], React.ComponentType<InterruptRendererProps>>>;
207
+ /**
208
+ * Also publish the active interrupts to the InterruptBridge so each renders
209
+ * inside the drill-down detail view (not just the chat). Defaults to `true`;
210
+ * requires an `InterruptBridgeProvider` (included in `KabooProvider`).
211
+ */
212
+ bridge?: boolean;
213
+ }
214
+ /**
215
+ * Ready-made human-in-the-loop interrupt handler. CopilotKit surfaces every open
216
+ * interrupt of a run at once (e.g. two gated tools called in parallel); we render
217
+ * one card per interrupt and resolve each independently by its own id. The client
218
+ * accumulates the per-id responses and only resumes the run once every open
219
+ * interrupt has been answered — so resolving with `intr.id` (never the bare
220
+ * `resolve()`, which would only ever answer the first) is what keeps N parallel
221
+ * gates from wedging. Prompts anchored to an on-screen tool render inline at that
222
+ * tool's position; the rest fall back to the chat slot.
223
+ */
224
+ declare function KabooInterruptHandler({ agentId, renderers, bridge, }: KabooInterruptHandlerProps): ReactElement | null;
225
+
226
+ export { type ActivityState as A, type DrillState as D, type FormQuestion as F, type InterruptReason as I, KabooInterruptHandler as K, type StreamGroup as S, type ToolCall as T, type KabooInterruptHandlerProps as a, type InterruptRendererProps as b, type TimelineEntry as c, type ApprovalReason as d, type FormReason as e, type InterruptData as f };