@pikku/assistant-ui 0.12.6 → 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,19 @@
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
+
9
+ ## 0.12.7
10
+
11
+ ### Patch Changes
12
+
13
+ - 41ce2cb: Upgrade to TypeScript 6 and raise the minimum Node.js version to 22.
14
+
15
+ All packages now build against `typescript@^6.0.3` and declare `engines.node >= 22`. Internal tooling (`ts-json-schema-generator`, `zod-to-ts`) was bumped to TypeScript 6-compatible releases.
16
+
3
17
  ## 0.12.6
4
18
 
5
19
  ### 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)
@@ -10,11 +19,14 @@ var __rest = (this && this.__rest) || function (s, e) {
10
19
  }
11
20
  return t;
12
21
  };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
13
25
  Object.defineProperty(exports, "__esModule", { value: true });
14
26
  exports.PikkuAgentChat = PikkuAgentChat;
15
27
  const jsx_runtime_1 = require("react/jsx-runtime");
16
28
  const react_1 = require("react");
17
- const react_markdown_1 = require("react-markdown");
29
+ const react_markdown_1 = __importDefault(require("react-markdown"));
18
30
  const react_2 = require("@assistant-ui/react");
19
31
  const use_pikku_agent_runtime_js_1 = require("./use-pikku-agent-runtime.js");
20
32
  const lightColors = {
@@ -70,12 +82,13 @@ function shouldHideToolCall(hideToolCalls, toolName) {
70
82
  return hideToolCalls.includes(toolName);
71
83
  }
72
84
  const ToolCallDisplay = ({ toolCallId, toolName, args, result, status, addResult }) => {
85
+ var _a, _b;
73
86
  const colors = (0, react_1.useContext)(ColorsContext);
74
87
  const hideToolCalls = (0, react_1.useContext)(HideToolCallsContext);
75
- const { handleApproval } = (0, use_pikku_agent_runtime_js_1.usePikkuApproval)();
88
+ const { handleApproval, pendingApprovals } = (0, use_pikku_agent_runtime_js_1.usePikkuApproval)();
76
89
  const [expanded, setExpanded] = (0, react_1.useState)(false);
77
90
  const isApproval = status.type === 'requires-action';
78
- 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;
79
92
  const displayArgs = Object.assign({}, args);
80
93
  delete displayArgs.__approvalReason;
81
94
  const [responded, setResponded] = (0, react_1.useState)(null);
@@ -110,11 +123,12 @@ const ToolCallDisplay = ({ toolCallId, toolName, args, result, status, addResult
110
123
  overflow: 'auto',
111
124
  marginBottom: 8,
112
125
  color: colors.text,
113
- }, 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* () {
114
127
  setResponded('approved');
115
- handleApproval(toolCallId, true);
116
- addResult === null || addResult === void 0 ? void 0 : addResult({ approved: true });
117
- }, style: {
128
+ if (yield handleApproval(toolCallId, true)) {
129
+ addResult === null || addResult === void 0 ? void 0 : addResult({ approved: true });
130
+ }
131
+ }), style: {
118
132
  padding: '4px 12px',
119
133
  fontSize: 12,
120
134
  border: `1px solid ${colors.successColor}`,
@@ -122,11 +136,12 @@ const ToolCallDisplay = ({ toolCallId, toolName, args, result, status, addResult
122
136
  background: colors.successBg,
123
137
  color: colors.successColor,
124
138
  cursor: 'pointer',
125
- }, 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* () {
126
140
  setResponded('denied');
127
- handleApproval(toolCallId, false);
128
- addResult === null || addResult === void 0 ? void 0 : addResult({ approved: false });
129
- }, style: {
141
+ if (yield handleApproval(toolCallId, false)) {
142
+ addResult === null || addResult === void 0 ? void 0 : addResult({ approved: false });
143
+ }
144
+ }), style: {
130
145
  padding: '4px 12px',
131
146
  fontSize: 12,
132
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
  };