@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @pikku/assistant-ui
2
2
 
3
+ ## 0.12.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 416606c: Replace the hand-rolled SSE parser with the AG-UI client runtime (`@ag-ui/client` + `@assistant-ui/react-ag-ui`); agent chat is now streaming-only, with the approval/resume flow preserved.
8
+
3
9
  ## 0.12.7
4
10
 
5
11
  ### Patch Changes
@@ -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/cjs/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.modelSupportsVision = exports.INLINE_SIZE_LIMIT = exports.useFileAttachment = exports.PikkuAgentChat = exports.resolvePikkuToolStatus = exports.isDeniedResult = exports.convertDbMessages = exports.usePikkuApproval = exports.PikkuApprovalContext = exports.usePikkuAgentNonStreamingRuntime = exports.usePikkuAgentRuntime = void 0;
3
+ exports.modelSupportsVision = exports.INLINE_SIZE_LIMIT = exports.useFileAttachment = exports.PikkuAgentChat = exports.resolvePikkuToolStatus = exports.isDeniedResult = exports.convertDbMessages = exports.usePikkuApproval = exports.PikkuApprovalContext = exports.usePikkuAgentRuntime = void 0;
4
4
  var use_pikku_agent_runtime_js_1 = require("./use-pikku-agent-runtime.js");
5
5
  Object.defineProperty(exports, "usePikkuAgentRuntime", { enumerable: true, get: function () { return use_pikku_agent_runtime_js_1.usePikkuAgentRuntime; } });
6
- Object.defineProperty(exports, "usePikkuAgentNonStreamingRuntime", { enumerable: true, get: function () { return use_pikku_agent_runtime_js_1.usePikkuAgentNonStreamingRuntime; } });
7
6
  Object.defineProperty(exports, "PikkuApprovalContext", { enumerable: true, get: function () { return use_pikku_agent_runtime_js_1.PikkuApprovalContext; } });
8
7
  Object.defineProperty(exports, "usePikkuApproval", { enumerable: true, get: function () { return use_pikku_agent_runtime_js_1.usePikkuApproval; } });
9
8
  Object.defineProperty(exports, "convertDbMessages", { enumerable: true, get: function () { return use_pikku_agent_runtime_js_1.convertDbMessages; } });
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __rest = (this && this.__rest) || function (s, e) {
3
12
  var t = {};
4
13
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -73,12 +82,13 @@ function shouldHideToolCall(hideToolCalls, toolName) {
73
82
  return hideToolCalls.includes(toolName);
74
83
  }
75
84
  const ToolCallDisplay = ({ toolCallId, toolName, args, result, status, addResult }) => {
85
+ var _a, _b;
76
86
  const colors = (0, react_1.useContext)(ColorsContext);
77
87
  const hideToolCalls = (0, react_1.useContext)(HideToolCallsContext);
78
- const { handleApproval } = (0, use_pikku_agent_runtime_js_1.usePikkuApproval)();
88
+ const { handleApproval, pendingApprovals } = (0, use_pikku_agent_runtime_js_1.usePikkuApproval)();
79
89
  const [expanded, setExpanded] = (0, react_1.useState)(false);
80
90
  const isApproval = status.type === 'requires-action';
81
- const approvalReason = args === null || args === void 0 ? void 0 : args.__approvalReason;
91
+ const approvalReason = (_a = args === null || args === void 0 ? void 0 : args.__approvalReason) !== null && _a !== void 0 ? _a : (_b = pendingApprovals.find((a) => a.toolCallId === toolCallId && a.type !== 'credential-request')) === null || _b === void 0 ? void 0 : _b.reason;
82
92
  const displayArgs = Object.assign({}, args);
83
93
  delete displayArgs.__approvalReason;
84
94
  const [responded, setResponded] = (0, react_1.useState)(null);
@@ -113,11 +123,12 @@ const ToolCallDisplay = ({ toolCallId, toolName, args, result, status, addResult
113
123
  overflow: 'auto',
114
124
  marginBottom: 8,
115
125
  color: colors.text,
116
- }, children: JSON.stringify(displayArgs, null, 2) }), (0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', gap: 8 }, children: [(0, jsx_runtime_1.jsx)("button", { onClick: () => {
126
+ }, children: JSON.stringify(displayArgs, null, 2) }), (0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', gap: 8 }, children: [(0, jsx_runtime_1.jsx)("button", { onClick: () => __awaiter(void 0, void 0, void 0, function* () {
117
127
  setResponded('approved');
118
- handleApproval(toolCallId, true);
119
- addResult === null || addResult === void 0 ? void 0 : addResult({ approved: true });
120
- }, style: {
128
+ if (yield handleApproval(toolCallId, true)) {
129
+ addResult === null || addResult === void 0 ? void 0 : addResult({ approved: true });
130
+ }
131
+ }), style: {
121
132
  padding: '4px 12px',
122
133
  fontSize: 12,
123
134
  border: `1px solid ${colors.successColor}`,
@@ -125,11 +136,12 @@ const ToolCallDisplay = ({ toolCallId, toolName, args, result, status, addResult
125
136
  background: colors.successBg,
126
137
  color: colors.successColor,
127
138
  cursor: 'pointer',
128
- }, children: "Approve" }), (0, jsx_runtime_1.jsx)("button", { onClick: () => {
139
+ }, children: "Approve" }), (0, jsx_runtime_1.jsx)("button", { onClick: () => __awaiter(void 0, void 0, void 0, function* () {
129
140
  setResponded('denied');
130
- handleApproval(toolCallId, false);
131
- addResult === null || addResult === void 0 ? void 0 : addResult({ approved: false });
132
- }, style: {
141
+ if (yield handleApproval(toolCallId, false)) {
142
+ addResult === null || addResult === void 0 ? void 0 : addResult({ approved: false });
143
+ }
144
+ }), style: {
133
145
  padding: '4px 12px',
134
146
  fontSize: 12,
135
147
  border: `1px solid ${colors.errorColor}`,
@@ -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
  };