@pikku/assistant-ui 0.12.7 → 0.12.8

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,4 +1,4 @@
1
- export { usePikkuAgentRuntime, usePikkuAgentNonStreamingRuntime, PikkuApprovalContext, usePikkuApproval, convertDbMessages, isDeniedResult, resolvePikkuToolStatus, } from './use-pikku-agent-runtime.js';
1
+ export { usePikkuAgentRuntime, PikkuApprovalContext, usePikkuApproval, convertDbMessages, isDeniedResult, resolvePikkuToolStatus, } from './use-pikku-agent-runtime.js';
2
2
  export type { PikkuAgentRuntimeOptions, PendingApproval, PikkuApprovalContextValue, PikkuToolStatusType, PikkuToolStatus, MissingCredentialPayload, } from './use-pikku-agent-runtime.js';
3
3
  export { PikkuAgentChat } from './pikku-agent-chat.js';
4
4
  export type { PikkuAgentChatProps } from './pikku-agent-chat.js';
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { usePikkuAgentRuntime, usePikkuAgentNonStreamingRuntime, PikkuApprovalContext, usePikkuApproval, convertDbMessages, isDeniedResult, resolvePikkuToolStatus, } from './use-pikku-agent-runtime.js';
1
+ export { usePikkuAgentRuntime, PikkuApprovalContext, usePikkuApproval, convertDbMessages, isDeniedResult, resolvePikkuToolStatus, } from './use-pikku-agent-runtime.js';
2
2
  export { PikkuAgentChat } from './pikku-agent-chat.js';
3
3
  export { useFileAttachment, INLINE_SIZE_LIMIT } from './use-file-attachment.js';
4
4
  export { modelSupportsVision } from './model-capabilities.js';
@@ -58,10 +58,11 @@ function shouldHideToolCall(hideToolCalls, toolName) {
58
58
  const ToolCallDisplay = ({ toolCallId, toolName, args, result, status, addResult }) => {
59
59
  const colors = useContext(ColorsContext);
60
60
  const hideToolCalls = useContext(HideToolCallsContext);
61
- const { handleApproval } = usePikkuApproval();
61
+ const { handleApproval, pendingApprovals } = usePikkuApproval();
62
62
  const [expanded, setExpanded] = useState(false);
63
63
  const isApproval = status.type === 'requires-action';
64
- const approvalReason = args?.__approvalReason;
64
+ const approvalReason = args?.__approvalReason ??
65
+ pendingApprovals.find((a) => a.toolCallId === toolCallId && a.type !== 'credential-request')?.reason;
65
66
  const displayArgs = { ...args };
66
67
  delete displayArgs.__approvalReason;
67
68
  const [responded, setResponded] = useState(null);
@@ -96,10 +97,11 @@ const ToolCallDisplay = ({ toolCallId, toolName, args, result, status, addResult
96
97
  overflow: 'auto',
97
98
  marginBottom: 8,
98
99
  color: colors.text,
99
- }, children: JSON.stringify(displayArgs, null, 2) }), _jsxs("div", { style: { display: 'flex', gap: 8 }, children: [_jsx("button", { onClick: () => {
100
+ }, children: JSON.stringify(displayArgs, null, 2) }), _jsxs("div", { style: { display: 'flex', gap: 8 }, children: [_jsx("button", { onClick: async () => {
100
101
  setResponded('approved');
101
- handleApproval(toolCallId, true);
102
- addResult?.({ approved: true });
102
+ if (await handleApproval(toolCallId, true)) {
103
+ addResult?.({ approved: true });
104
+ }
103
105
  }, style: {
104
106
  padding: '4px 12px',
105
107
  fontSize: 12,
@@ -108,10 +110,11 @@ const ToolCallDisplay = ({ toolCallId, toolName, args, result, status, addResult
108
110
  background: colors.successBg,
109
111
  color: colors.successColor,
110
112
  cursor: 'pointer',
111
- }, children: "Approve" }), _jsx("button", { onClick: () => {
113
+ }, children: "Approve" }), _jsx("button", { onClick: async () => {
112
114
  setResponded('denied');
113
- handleApproval(toolCallId, false);
114
- addResult?.({ approved: false });
115
+ if (await handleApproval(toolCallId, false)) {
116
+ addResult?.({ approved: false });
117
+ }
115
118
  }, style: {
116
119
  padding: '4px 12px',
117
120
  fontSize: 12,
@@ -4,7 +4,6 @@ export interface PikkuAgentRuntimeOptions {
4
4
  agentName: string;
5
5
  threadId: string;
6
6
  resourceId: string;
7
- initialMessages?: any[];
8
7
  onFinish?: () => void;
9
8
  credentials?: RequestCredentials;
10
9
  headers?: Record<string, string>;
@@ -14,13 +13,18 @@ export interface PikkuAgentRuntimeOptions {
14
13
  * Provide upfront state (e.g. current org/project/branch/deployment IDs)
15
14
  * so the agent can call tools without asking the user. */
16
15
  context?: string;
16
+ /** Prior messages to hydrate the thread with (e.g. converted from persisted
17
+ * DB history via `convertDbMessages`). Loaded once on mount, so the
18
+ * consumer must keep the chat unmounted until these are available (key or
19
+ * gate on load) — the runtime does not re-hydrate when they change later. */
20
+ initialMessages?: ThreadMessageLike[];
17
21
  }
18
22
  export interface PendingApproval {
19
23
  toolCallId: string;
20
24
  toolName: string;
21
25
  args: unknown;
22
26
  reason?: string;
23
- runId: string;
27
+ runId?: string;
24
28
  type?: 'approval-request' | 'credential-request';
25
29
  credentialName?: string;
26
30
  credentialType?: 'oauth2' | 'apikey';
@@ -28,7 +32,10 @@ export interface PendingApproval {
28
32
  }
29
33
  export interface PikkuApprovalContextValue {
30
34
  pendingApprovals: PendingApproval[];
31
- handleApproval: (toolCallId: string, approved: boolean) => void;
35
+ /** Resolve an approval/credential request. Returns `true` when the request
36
+ * was found and acknowledged — callers must gate their `addResult` call on
37
+ * this so a stray result can't start a resume run with nothing queued. */
38
+ handleApproval: (toolCallId: string, approved: boolean) => Promise<boolean>;
32
39
  }
33
40
  export declare const PikkuApprovalContext: import("react").Context<PikkuApprovalContextValue>;
34
41
  export declare const usePikkuApproval: () => PikkuApprovalContextValue;
@@ -51,14 +58,8 @@ export declare function resolvePikkuToolStatus(status: {
51
58
  }, result?: unknown): PikkuToolStatus;
52
59
  export declare const convertDbMessages: (dbMessages: any[]) => ThreadMessageLike[];
53
60
  export declare function usePikkuAgentRuntime(options: PikkuAgentRuntimeOptions): {
54
- runtime: import("@assistant-ui/react").AssistantRuntime;
61
+ runtime: import("@assistant-ui/react-ag-ui").AgUiAssistantRuntime;
55
62
  pendingApprovals: PendingApproval[];
56
63
  isAwaitingApproval: boolean;
57
- handleApproval: (toolCallId: string, approved: boolean) => void;
58
- };
59
- export declare function usePikkuAgentNonStreamingRuntime(options: PikkuAgentRuntimeOptions): {
60
- runtime: import("@assistant-ui/react").AssistantRuntime;
61
- pendingApprovals: PendingApproval[];
62
- isAwaitingApproval: boolean;
63
- handleApproval: (toolCallId: string, approved: boolean) => void;
64
+ handleApproval: (toolCallId: string, approved: boolean) => Promise<boolean>;
64
65
  };