@pikku/assistant-ui 0.12.0 → 0.12.1

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.
@@ -1,6 +1,332 @@
1
- import { useMemo, useEffect, useRef, useCallback } from 'react';
2
- import { useDataStreamRuntime } from '@assistant-ui/react-data-stream';
3
- const convertDbMessages = (dbMessages) => {
1
+ import { createContext, useContext, useMemo, useRef, useState, useCallback, } from 'react';
2
+ import { useLocalRuntime, } from '@assistant-ui/react';
3
+ export const PikkuApprovalContext = createContext({
4
+ pendingApprovals: [],
5
+ handleApproval: () => { },
6
+ });
7
+ export const usePikkuApproval = () => useContext(PikkuApprovalContext);
8
+ async function* parseSSEStream(reader) {
9
+ const decoder = new TextDecoder();
10
+ let buffer = '';
11
+ while (true) {
12
+ const { done, value } = await reader.read();
13
+ if (done)
14
+ break;
15
+ buffer += decoder.decode(value, { stream: true });
16
+ const lines = buffer.split('\n');
17
+ buffer = lines.pop();
18
+ for (const line of lines) {
19
+ if (line.startsWith('data: ')) {
20
+ const data = line.slice(6);
21
+ if (data) {
22
+ try {
23
+ yield JSON.parse(data);
24
+ }
25
+ catch {
26
+ // skip unparseable lines
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }
33
+ /**
34
+ * Shared helper: consume an SSE stream and populate text/toolCalls.
35
+ * Returns an array of PendingApprovals when the stream requests them, or empty when done.
36
+ */
37
+ async function processStream(reader, text, toolCalls, yieldContent, onFinish) {
38
+ const pendingApprovals = [];
39
+ for await (const event of parseSSEStream(reader)) {
40
+ switch (event.type) {
41
+ case 'text-delta':
42
+ text.value += event.text;
43
+ break;
44
+ case 'tool-call': {
45
+ let parsedArgs = event.args;
46
+ if (typeof event.args === 'string') {
47
+ try {
48
+ parsedArgs = JSON.parse(event.args);
49
+ }
50
+ catch {
51
+ parsedArgs = {};
52
+ }
53
+ }
54
+ toolCalls.push({
55
+ type: 'tool-call',
56
+ toolCallId: event.toolCallId,
57
+ toolName: event.toolName,
58
+ args: parsedArgs,
59
+ });
60
+ break;
61
+ }
62
+ case 'tool-result': {
63
+ // Skip tool-results that contain __approvalRequired
64
+ const resultObj = typeof event.result === 'object' ? event.result : null;
65
+ if (resultObj && '__approvalRequired' in resultObj) {
66
+ break;
67
+ }
68
+ const tc = toolCalls.find((t) => t.toolCallId === event.toolCallId);
69
+ if (tc) {
70
+ tc.result =
71
+ typeof event.result === 'string'
72
+ ? event.result
73
+ : JSON.stringify(event.result);
74
+ if (event.isError) {
75
+ tc.isError = true;
76
+ }
77
+ }
78
+ break;
79
+ }
80
+ case 'approval-request':
81
+ pendingApprovals.push({
82
+ toolCallId: event.toolCallId,
83
+ toolName: event.toolName,
84
+ args: event.args,
85
+ reason: event.reason,
86
+ runId: event.runId,
87
+ });
88
+ break;
89
+ case 'error':
90
+ text.value += `\n\nError: ${event.message || event.errorText || 'Unknown error'}`;
91
+ break;
92
+ case 'done':
93
+ onFinish?.();
94
+ continue;
95
+ }
96
+ yieldContent();
97
+ }
98
+ return pendingApprovals;
99
+ }
100
+ export function isDeniedResult(result) {
101
+ if (result == null)
102
+ return false;
103
+ try {
104
+ const parsed = typeof result === 'string' ? JSON.parse(result) : result;
105
+ return parsed && typeof parsed === 'object' && parsed.approved === false;
106
+ }
107
+ catch {
108
+ return false;
109
+ }
110
+ }
111
+ export function resolvePikkuToolStatus(status, result) {
112
+ if (status.type === 'running')
113
+ return { type: 'running' };
114
+ if (status.type === 'requires-action')
115
+ return { type: 'requires-action' };
116
+ if (isDeniedResult(result))
117
+ return { type: 'denied' };
118
+ if (typeof result === 'string' && result.startsWith('Error:'))
119
+ return { type: 'error' };
120
+ return { type: 'completed' };
121
+ }
122
+ function buildContent(text, toolCalls) {
123
+ const content = [];
124
+ if (text.value)
125
+ content.push({ type: 'text', text: text.value });
126
+ content.push(...toolCalls);
127
+ return content;
128
+ }
129
+ function createPikkuStreamingAdapter(optionsRef, pendingApprovalsRef, approvalDecisionsRef, setPendingApprovalsRef, onFinishRef) {
130
+ return {
131
+ async *run({ messages, abortSignal }) {
132
+ const opts = optionsRef.current;
133
+ // Check if this run() is a continuation after approval decisions.
134
+ // assistant-ui calls run() again after addResult provides tool results for ALL tool calls.
135
+ const pendingApprovals = pendingApprovalsRef.current;
136
+ if (pendingApprovals.length > 0) {
137
+ // Read the decisions accumulated by handleApproval() from click handlers.
138
+ const decisions = approvalDecisionsRef.current;
139
+ approvalDecisionsRef.current = [];
140
+ if (decisions.length === 0) {
141
+ // No decisions set — shouldn't happen if composer is disabled.
142
+ return;
143
+ }
144
+ // Clear pending approvals state
145
+ pendingApprovalsRef.current = [];
146
+ setPendingApprovalsRef.current([]);
147
+ // Send /resume for each decision sequentially.
148
+ // All but the last resume will return quickly (just tool-result + done).
149
+ // The last resume triggers continuation (next LLM step).
150
+ let lastText = { value: '' };
151
+ let lastToolCalls = [];
152
+ let nextApprovals = [];
153
+ for (let i = 0; i < decisions.length; i++) {
154
+ const decision = decisions[i];
155
+ // Find the runId from the matching pending approval
156
+ const matchingApproval = pendingApprovals.find((p) => p.toolCallId === decision.toolCallId);
157
+ const runId = matchingApproval?.runId ?? pendingApprovals[0]?.runId;
158
+ const resumeResponse = await fetch(`${opts.api}/${opts.agentName}/resume`, {
159
+ method: 'POST',
160
+ headers: {
161
+ 'Content-Type': 'application/json',
162
+ ...opts.headers,
163
+ },
164
+ body: JSON.stringify({
165
+ runId,
166
+ toolCallId: decision.toolCallId,
167
+ approved: decision.approved,
168
+ }),
169
+ signal: abortSignal,
170
+ credentials: opts.credentials,
171
+ });
172
+ if (!resumeResponse.ok || !resumeResponse.body) {
173
+ const errorText = resumeResponse.body
174
+ ? await resumeResponse.text().catch(() => '')
175
+ : '';
176
+ throw new Error(`Resume failed: ${resumeResponse.status}${errorText ? ` - ${errorText}` : ''}`);
177
+ }
178
+ const text = { value: '' };
179
+ const toolCalls = [];
180
+ const reader = resumeResponse.body.getReader();
181
+ const streamApprovals = await processStream(reader, text, toolCalls, () => { }, i === decisions.length - 1
182
+ ? (onFinishRef.current ?? undefined)
183
+ : undefined);
184
+ // Keep the last resume's output (it has continuation content)
185
+ lastText = text;
186
+ lastToolCalls = toolCalls;
187
+ if (streamApprovals.length > 0) {
188
+ nextApprovals = streamApprovals;
189
+ }
190
+ }
191
+ // Build content from the last resume's output
192
+ const content = buildContent(lastText, lastToolCalls);
193
+ if (nextApprovals.length > 0) {
194
+ // More approvals from continuation — show them
195
+ pendingApprovalsRef.current = nextApprovals;
196
+ setPendingApprovalsRef.current(nextApprovals);
197
+ // Add approval tool calls to content
198
+ for (const approval of nextApprovals) {
199
+ const approvalToolCall = {
200
+ type: 'tool-call',
201
+ toolCallId: approval.toolCallId,
202
+ toolName: approval.toolName,
203
+ args: {
204
+ ...(typeof approval.args === 'object' && approval.args !== null
205
+ ? approval.args
206
+ : {}),
207
+ ...(approval.reason
208
+ ? { __approvalReason: approval.reason }
209
+ : {}),
210
+ },
211
+ };
212
+ const idx = lastToolCalls.findIndex((tc) => tc.toolCallId === approval.toolCallId && !tc.result);
213
+ if (idx !== -1) {
214
+ lastToolCalls[idx] = approvalToolCall;
215
+ }
216
+ else {
217
+ lastToolCalls.push(approvalToolCall);
218
+ }
219
+ }
220
+ const updatedContent = buildContent(lastText, lastToolCalls);
221
+ yield {
222
+ content: updatedContent,
223
+ status: {
224
+ type: 'requires-action',
225
+ reason: 'tool-calls',
226
+ },
227
+ };
228
+ }
229
+ else if (content.length > 0) {
230
+ yield { content };
231
+ }
232
+ return;
233
+ }
234
+ // Normal flow: new user message → stream
235
+ const lastUserMsg = [...messages].reverse().find((m) => m.role === 'user');
236
+ if (!lastUserMsg)
237
+ return;
238
+ let messageText = '';
239
+ if (lastUserMsg.content) {
240
+ for (const part of lastUserMsg.content) {
241
+ if ('text' in part && part.type === 'text') {
242
+ messageText += part.text;
243
+ }
244
+ }
245
+ }
246
+ const response = await fetch(`${opts.api}/${opts.agentName}/stream`, {
247
+ method: 'POST',
248
+ headers: { 'Content-Type': 'application/json', ...opts.headers },
249
+ body: JSON.stringify({
250
+ agentName: opts.agentName,
251
+ message: messageText,
252
+ threadId: opts.threadId,
253
+ resourceId: opts.resourceId,
254
+ model: opts.model,
255
+ temperature: opts.temperature,
256
+ }),
257
+ signal: abortSignal,
258
+ credentials: opts.credentials,
259
+ });
260
+ if (!response.ok || !response.body) {
261
+ throw new Error(`Agent stream failed: ${response.status}`);
262
+ }
263
+ const text = { value: '' };
264
+ const toolCalls = [];
265
+ let pendingContent = null;
266
+ const yieldContent = () => {
267
+ const content = buildContent(text, toolCalls);
268
+ if (content.length > 0)
269
+ pendingContent = content;
270
+ };
271
+ const reader = response.body.getReader();
272
+ const approvals = await processStream(reader, text, toolCalls, yieldContent, onFinishRef.current ?? undefined);
273
+ if (approvals.length === 0) {
274
+ // No approval needed — yield final content and done
275
+ if (pendingContent) {
276
+ yield { content: pendingContent };
277
+ }
278
+ return;
279
+ }
280
+ // Approvals requested: store them for the next run() call
281
+ pendingApprovalsRef.current = approvals;
282
+ setPendingApprovalsRef.current(approvals);
283
+ // Each approval tool call needs to be shown without a result
284
+ // so assistant-ui renders them as requires-action
285
+ for (const approval of approvals) {
286
+ const approvalToolCall = {
287
+ type: 'tool-call',
288
+ toolCallId: approval.toolCallId,
289
+ toolName: approval.toolName,
290
+ args: {
291
+ ...(typeof approval.args === 'object' && approval.args !== null
292
+ ? approval.args
293
+ : {}),
294
+ ...(approval.reason ? { __approvalReason: approval.reason } : {}),
295
+ },
296
+ };
297
+ // Replace the existing tool call (if any) with the approval version
298
+ const parentIdx = toolCalls.findIndex((tc) => tc.toolCallId === approval.toolCallId && !tc.result);
299
+ if (parentIdx !== -1) {
300
+ toolCalls[parentIdx] = approvalToolCall;
301
+ }
302
+ else {
303
+ toolCalls.push(approvalToolCall);
304
+ }
305
+ }
306
+ // Remove any forwarded sub-agent tool calls that duplicate approval tool names
307
+ const approvalToolCallIds = new Set(approvals.map((a) => a.toolCallId));
308
+ const approvalToolNames = new Set(approvals.map((a) => a.toolName));
309
+ for (let i = toolCalls.length - 1; i >= 0; i--) {
310
+ if (approvalToolNames.has(toolCalls[i].toolName) &&
311
+ !approvalToolCallIds.has(toolCalls[i].toolCallId)) {
312
+ toolCalls.splice(i, 1);
313
+ }
314
+ }
315
+ const content = buildContent(text, toolCalls);
316
+ yield {
317
+ content,
318
+ status: {
319
+ type: 'requires-action',
320
+ reason: 'tool-calls',
321
+ },
322
+ };
323
+ // Generator returns here. assistant-ui will show the approval UI for each tool call.
324
+ // When the user clicks Approve/Deny on ALL tools → handleApproval accumulates decisions →
325
+ // addResult for each → run() is called again when all have results.
326
+ },
327
+ };
328
+ }
329
+ export const convertDbMessages = (dbMessages) => {
4
330
  const result = [];
5
331
  let currentAssistant = null;
6
332
  for (const msg of dbMessages) {
@@ -97,67 +423,221 @@ const convertDbMessages = (dbMessages) => {
97
423
  return result;
98
424
  };
99
425
  export function usePikkuAgentRuntime(options) {
100
- const { api, threadId = null, initialMessages: rawInitialMessages, onThreadCreated, onFinish, onApprovalRequest, credentials, headers, } = options;
101
- const threadIdRef = useRef(threadId);
102
- threadIdRef.current = threadId;
103
- const justCreatedThreadRef = useRef(false);
104
- const bodyFn = useCallback(() => {
105
- let currentThreadId = threadIdRef.current;
106
- if (!currentThreadId) {
107
- currentThreadId = crypto.randomUUID();
108
- justCreatedThreadRef.current = true;
109
- onThreadCreated?.(currentThreadId);
110
- }
111
- return { threadId: currentThreadId };
112
- }, [onThreadCreated]);
113
- const onData = useCallback((event) => {
114
- if (event.name === 'approval-request') {
115
- const approval = event.data;
116
- onApprovalRequest?.({
117
- toolCallId: approval.toolCallId,
426
+ const [pendingApprovals, setPendingApprovals] = useState([]);
427
+ const optionsRef = useRef(options);
428
+ optionsRef.current = options;
429
+ const onFinishRef = useRef(options.onFinish);
430
+ onFinishRef.current = options.onFinish;
431
+ const pendingApprovalsRef = useRef([]);
432
+ const approvalDecisionsRef = useRef([]);
433
+ const setPendingApprovalsRef = useRef(setPendingApprovals);
434
+ setPendingApprovalsRef.current = setPendingApprovals;
435
+ const adapter = useMemo(() => createPikkuStreamingAdapter(optionsRef, pendingApprovalsRef, approvalDecisionsRef, setPendingApprovalsRef, onFinishRef), []);
436
+ const initialMessages = useMemo(() => options.initialMessages
437
+ ? convertDbMessages(options.initialMessages)
438
+ : undefined, [options.initialMessages]);
439
+ const runtime = useLocalRuntime(adapter, { initialMessages });
440
+ // handleApproval is called from the Approve/Deny button click handler.
441
+ // It accumulates the decision in the ref. assistant-ui will call run()
442
+ // when ALL tool calls have results (via addResult).
443
+ const handleApproval = useCallback((toolCallId, approved) => {
444
+ approvalDecisionsRef.current.push({ toolCallId, approved });
445
+ }, []);
446
+ const isAwaitingApproval = pendingApprovals.length > 0;
447
+ return {
448
+ runtime,
449
+ pendingApprovals,
450
+ isAwaitingApproval,
451
+ handleApproval,
452
+ };
453
+ }
454
+ function createPikkuNonStreamingAdapter(optionsRef, pendingApprovalsRef, approvalDecisionsRef, setPendingApprovalsRef, onFinishRef) {
455
+ return {
456
+ async *run({ messages, abortSignal }) {
457
+ const opts = optionsRef.current;
458
+ // Continuation after approval decisions
459
+ const pendingApprovals = pendingApprovalsRef.current;
460
+ if (pendingApprovals.length > 0) {
461
+ const decisions = approvalDecisionsRef.current;
462
+ approvalDecisionsRef.current = [];
463
+ if (decisions.length === 0)
464
+ return;
465
+ pendingApprovalsRef.current = [];
466
+ setPendingApprovalsRef.current([]);
467
+ // Resume uses SSE (same as streaming mode)
468
+ let lastText = { value: '' };
469
+ let lastToolCalls = [];
470
+ let nextApprovals = [];
471
+ for (let i = 0; i < decisions.length; i++) {
472
+ const decision = decisions[i];
473
+ const matchingApproval = pendingApprovals.find((p) => p.toolCallId === decision.toolCallId);
474
+ const runId = matchingApproval?.runId ?? pendingApprovals[0]?.runId;
475
+ const resumeResponse = await fetch(`${opts.api}/${opts.agentName}/resume`, {
476
+ method: 'POST',
477
+ headers: {
478
+ 'Content-Type': 'application/json',
479
+ ...opts.headers,
480
+ },
481
+ body: JSON.stringify({
482
+ runId,
483
+ toolCallId: decision.toolCallId,
484
+ approved: decision.approved,
485
+ }),
486
+ signal: abortSignal,
487
+ credentials: opts.credentials,
488
+ });
489
+ if (!resumeResponse.ok || !resumeResponse.body) {
490
+ const errorText = resumeResponse.body
491
+ ? await resumeResponse.text().catch(() => '')
492
+ : '';
493
+ throw new Error(`Resume failed: ${resumeResponse.status}${errorText ? ` - ${errorText}` : ''}`);
494
+ }
495
+ const text = { value: '' };
496
+ const toolCalls = [];
497
+ const reader = resumeResponse.body.getReader();
498
+ const streamApprovals = await processStream(reader, text, toolCalls, () => { }, i === decisions.length - 1
499
+ ? (onFinishRef.current ?? undefined)
500
+ : undefined);
501
+ lastText = text;
502
+ lastToolCalls = toolCalls;
503
+ if (streamApprovals.length > 0) {
504
+ nextApprovals = streamApprovals;
505
+ }
506
+ }
507
+ const content = buildContent(lastText, lastToolCalls);
508
+ if (nextApprovals.length > 0) {
509
+ pendingApprovalsRef.current = nextApprovals;
510
+ setPendingApprovalsRef.current(nextApprovals);
511
+ for (const approval of nextApprovals) {
512
+ const approvalToolCall = {
513
+ type: 'tool-call',
514
+ toolCallId: approval.toolCallId,
515
+ toolName: approval.toolName,
516
+ args: {
517
+ ...(typeof approval.args === 'object' && approval.args !== null
518
+ ? approval.args
519
+ : {}),
520
+ ...(approval.reason
521
+ ? { __approvalReason: approval.reason }
522
+ : {}),
523
+ },
524
+ };
525
+ const idx = lastToolCalls.findIndex((tc) => tc.toolCallId === approval.toolCallId && !tc.result);
526
+ if (idx !== -1) {
527
+ lastToolCalls[idx] = approvalToolCall;
528
+ }
529
+ else {
530
+ lastToolCalls.push(approvalToolCall);
531
+ }
532
+ }
533
+ const updatedContent = buildContent(lastText, lastToolCalls);
534
+ yield {
535
+ content: updatedContent,
536
+ status: {
537
+ type: 'requires-action',
538
+ reason: 'tool-calls',
539
+ },
540
+ };
541
+ }
542
+ else if (content.length > 0) {
543
+ yield { content };
544
+ }
545
+ return;
546
+ }
547
+ // Normal flow: new user message → non-streaming POST
548
+ const lastUserMsg = [...messages].reverse().find((m) => m.role === 'user');
549
+ if (!lastUserMsg)
550
+ return;
551
+ let messageText = '';
552
+ if (lastUserMsg.content) {
553
+ for (const part of lastUserMsg.content) {
554
+ if ('text' in part && part.type === 'text') {
555
+ messageText += part.text;
556
+ }
557
+ }
558
+ }
559
+ const response = await fetch(`${opts.api}/${opts.agentName}`, {
560
+ method: 'POST',
561
+ headers: { 'Content-Type': 'application/json', ...opts.headers },
562
+ body: JSON.stringify({
563
+ agentName: opts.agentName,
564
+ message: messageText,
565
+ threadId: opts.threadId,
566
+ resourceId: opts.resourceId,
567
+ model: opts.model,
568
+ temperature: opts.temperature,
569
+ }),
570
+ signal: abortSignal,
571
+ credentials: opts.credentials,
118
572
  });
119
- }
120
- }, [onApprovalRequest]);
121
- const onFinishCb = useCallback(() => {
122
- onFinish?.();
123
- }, [onFinish]);
124
- const initialMessages = useMemo(() => (rawInitialMessages ? convertDbMessages(rawInitialMessages) : []), [rawInitialMessages]);
125
- const runtime = useDataStreamRuntime({
126
- api,
127
- protocol: 'ui-message-stream',
128
- body: bodyFn,
129
- onData,
130
- onFinish: onFinishCb,
131
- initialMessages,
132
- credentials,
133
- headers,
134
- });
135
- const prevThreadIdRef = useRef(threadId);
136
- const hasResetRef = useRef(false);
137
- useEffect(() => {
138
- if (prevThreadIdRef.current !== threadId) {
139
- prevThreadIdRef.current = threadId;
140
- if (justCreatedThreadRef.current) {
141
- justCreatedThreadRef.current = false;
142
- hasResetRef.current = true;
573
+ if (!response.ok) {
574
+ throw new Error(`Agent run failed: ${response.status}`);
575
+ }
576
+ const json = await response.json();
577
+ if (json.status === 'suspended' && json.pendingApprovals?.length > 0) {
578
+ const approvals = json.pendingApprovals;
579
+ pendingApprovalsRef.current = approvals;
580
+ setPendingApprovalsRef.current(approvals);
581
+ const toolCalls = approvals.map((approval) => ({
582
+ type: 'tool-call',
583
+ toolCallId: approval.toolCallId,
584
+ toolName: approval.toolName,
585
+ args: {
586
+ ...(typeof approval.args === 'object' && approval.args !== null
587
+ ? approval.args
588
+ : {}),
589
+ ...(approval.reason ? { __approvalReason: approval.reason } : {}),
590
+ },
591
+ }));
592
+ const content = [];
593
+ if (json.result) {
594
+ content.push({ type: 'text', text: json.result });
595
+ }
596
+ content.push(...toolCalls);
597
+ yield {
598
+ content,
599
+ status: {
600
+ type: 'requires-action',
601
+ reason: 'tool-calls',
602
+ },
603
+ };
143
604
  return;
144
605
  }
145
- hasResetRef.current = false;
146
- if (rawInitialMessages) {
147
- ;
148
- runtime.thread.reset(convertDbMessages(rawInitialMessages));
149
- hasResetRef.current = true;
606
+ // No approvals — yield complete content
607
+ onFinishRef.current?.();
608
+ const content = [];
609
+ if (json.result) {
610
+ content.push({ type: 'text', text: String(json.result) });
150
611
  }
151
- else {
152
- ;
153
- runtime.thread.reset([]);
612
+ if (content.length > 0) {
613
+ yield { content };
154
614
  }
155
- }
156
- else if (!hasResetRef.current && rawInitialMessages) {
157
- ;
158
- runtime.thread.reset(convertDbMessages(rawInitialMessages));
159
- hasResetRef.current = true;
160
- }
161
- }, [threadId, rawInitialMessages, runtime]);
162
- return runtime;
615
+ },
616
+ };
617
+ }
618
+ export function usePikkuAgentNonStreamingRuntime(options) {
619
+ const [pendingApprovals, setPendingApprovals] = useState([]);
620
+ const optionsRef = useRef(options);
621
+ optionsRef.current = options;
622
+ const onFinishRef = useRef(options.onFinish);
623
+ onFinishRef.current = options.onFinish;
624
+ const pendingApprovalsRef = useRef([]);
625
+ const approvalDecisionsRef = useRef([]);
626
+ const setPendingApprovalsRef = useRef(setPendingApprovals);
627
+ setPendingApprovalsRef.current = setPendingApprovals;
628
+ const adapter = useMemo(() => createPikkuNonStreamingAdapter(optionsRef, pendingApprovalsRef, approvalDecisionsRef, setPendingApprovalsRef, onFinishRef), []);
629
+ const initialMessages = useMemo(() => options.initialMessages
630
+ ? convertDbMessages(options.initialMessages)
631
+ : undefined, [options.initialMessages]);
632
+ const runtime = useLocalRuntime(adapter, { initialMessages });
633
+ const handleApproval = useCallback((toolCallId, approved) => {
634
+ approvalDecisionsRef.current.push({ toolCallId, approved });
635
+ }, []);
636
+ const isAwaitingApproval = pendingApprovals.length > 0;
637
+ return {
638
+ runtime,
639
+ pendingApprovals,
640
+ isAwaitingApproval,
641
+ handleApproval,
642
+ };
163
643
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/assistant-ui",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@assistant-ui/react": "^0.12.12",
23
- "@assistant-ui/react-data-stream": "^0.12.5"
23
+ "react-markdown": "^10.1.0"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": "^18 || ^19",
package/src/index.ts CHANGED
@@ -1,4 +1,18 @@
1
- export { usePikkuAgentRuntime } from './use-pikku-agent-runtime.js'
2
- export type { PikkuAgentRuntimeOptions } from './use-pikku-agent-runtime.js'
1
+ export {
2
+ usePikkuAgentRuntime,
3
+ usePikkuAgentNonStreamingRuntime,
4
+ PikkuApprovalContext,
5
+ usePikkuApproval,
6
+ convertDbMessages,
7
+ isDeniedResult,
8
+ resolvePikkuToolStatus,
9
+ } from './use-pikku-agent-runtime.js'
10
+ export type {
11
+ PikkuAgentRuntimeOptions,
12
+ PendingApproval,
13
+ PikkuApprovalContextValue,
14
+ PikkuToolStatusType,
15
+ PikkuToolStatus,
16
+ } from './use-pikku-agent-runtime.js'
3
17
  export { PikkuAgentChat } from './pikku-agent-chat.js'
4
18
  export type { PikkuAgentChatProps } from './pikku-agent-chat.js'