assistant-ui 0.0.123 → 0.0.125

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.
Files changed (54) hide show
  1. package/README.md +7 -0
  2. package/dist/codemods/v0-11/content-part-to-message-part.d.ts.map +1 -1
  3. package/dist/codemods/v0-11/content-part-to-message-part.js +126 -40
  4. package/dist/codemods/v0-11/content-part-to-message-part.js.map +1 -1
  5. package/dist/codemods/v0-12/event-names-to-camelcase.d.ts.map +1 -1
  6. package/dist/codemods/v0-12/event-names-to-camelcase.js +2 -2
  7. package/dist/codemods/v0-12/event-names-to-camelcase.js.map +1 -1
  8. package/dist/codemods/v0-12/primitive-if-to-aui-if.d.ts.map +1 -1
  9. package/dist/codemods/v0-12/primitive-if-to-aui-if.js +57 -41
  10. package/dist/codemods/v0-12/primitive-if-to-aui-if.js.map +1 -1
  11. package/dist/codemods/v0-8/ui-package-split.d.ts.map +1 -1
  12. package/dist/codemods/v0-8/ui-package-split.js +11 -35
  13. package/dist/codemods/v0-8/ui-package-split.js.map +1 -1
  14. package/dist/codemods/v0-9/edge-package-split.d.ts.map +1 -1
  15. package/dist/codemods/v0-9/edge-package-split.js +15 -69
  16. package/dist/codemods/v0-9/edge-package-split.js.map +1 -1
  17. package/dist/commands/cloud.d.ts.map +1 -1
  18. package/dist/commands/cloud.js +12 -3
  19. package/dist/commands/cloud.js.map +1 -1
  20. package/dist/commands/info.d.ts.map +1 -1
  21. package/dist/commands/info.js +8 -1
  22. package/dist/commands/info.js.map +1 -1
  23. package/dist/lib/cloud-auth.d.ts +1 -0
  24. package/dist/lib/cloud-auth.d.ts.map +1 -1
  25. package/dist/lib/cloud-auth.js +4 -3
  26. package/dist/lib/cloud-auth.js.map +1 -1
  27. package/dist/lib/cloud-remote.d.ts +22 -0
  28. package/dist/lib/cloud-remote.d.ts.map +1 -0
  29. package/dist/lib/cloud-remote.js +74 -0
  30. package/dist/lib/cloud-remote.js.map +1 -0
  31. package/dist/lib/utils/package-installer.d.ts.map +1 -1
  32. package/dist/lib/utils/package-installer.js +3 -2
  33. package/dist/lib/utils/package-installer.js.map +1 -1
  34. package/package.json +1 -1
  35. package/src/codemods/v0-11/__tests__/content-part-to-message-part.test.ts +268 -2
  36. package/src/codemods/v0-11/content-part-to-message-part.ts +211 -80
  37. package/src/codemods/v0-12/__tests__/event-names-to-camelcase.test.ts +23 -0
  38. package/src/codemods/v0-12/__tests__/primitive-if-to-aui-if.test.ts +150 -1
  39. package/src/codemods/v0-12/event-names-to-camelcase.ts +2 -8
  40. package/src/codemods/v0-12/primitive-if-to-aui-if.ts +92 -61
  41. package/src/codemods/v0-8/__tests__/ui-package-split.test.ts +83 -0
  42. package/src/codemods/v0-8/ui-package-split.ts +21 -59
  43. package/src/codemods/v0-9/edge-package-split.test.ts +100 -0
  44. package/src/codemods/v0-9/edge-package-split.ts +30 -139
  45. package/src/commands/cloud.test.ts +58 -0
  46. package/src/commands/cloud.ts +19 -2
  47. package/src/commands/info.ts +26 -1
  48. package/src/lib/cloud-auth.ts +14 -8
  49. package/src/lib/cloud-remote.test.ts +156 -0
  50. package/src/lib/cloud-remote.ts +150 -0
  51. package/src/lib/utils/package-installer.test.ts +39 -0
  52. package/src/lib/utils/package-installer.ts +3 -1
  53. package/templates/cloud-harness/components/assistant-ui/elements/tool-fallback.aui.tsx +17 -8
  54. package/templates/cloud-harness/package.json +2 -2
@@ -0,0 +1,150 @@
1
+ import { validateCloudUrl } from "./cloud-url";
2
+
3
+ export const CLOUD_CLI_RUN_PATH = "/api/cli/run";
4
+
5
+ export type CloudCliAction = { type: string; [key: string]: unknown };
6
+
7
+ export type CloudCliResponse = {
8
+ stdout?: string;
9
+ stderr?: string;
10
+ exitCode: number;
11
+ actions?: CloudCliAction[];
12
+ };
13
+
14
+ const SAFE = /^[A-Za-z0-9_@%+=:,./-]+$/;
15
+
16
+ export const joinCloudArgs = (args: readonly string[]): string =>
17
+ args
18
+ .map((arg) => (SAFE.test(arg) ? arg : `'${arg.replaceAll("'", `'\\''`)}'`))
19
+ .join(" ");
20
+
21
+ export const parseCloudCliResponse = (
22
+ value: unknown,
23
+ ): CloudCliResponse | null => {
24
+ if (!value || typeof value !== "object") return null;
25
+ const body = value as Record<string, unknown>;
26
+ const exitCode = body["exitCode"];
27
+ if (
28
+ typeof exitCode !== "number" ||
29
+ !Number.isInteger(exitCode) ||
30
+ exitCode < 0 ||
31
+ exitCode > 255
32
+ ) {
33
+ return null;
34
+ }
35
+ for (const key of ["stdout", "stderr"]) {
36
+ if (body[key] !== undefined && typeof body[key] !== "string") return null;
37
+ }
38
+ const actions = body["actions"];
39
+ if (
40
+ actions !== undefined &&
41
+ !(
42
+ Array.isArray(actions) &&
43
+ actions.every(
44
+ (action) =>
45
+ !!action &&
46
+ typeof action === "object" &&
47
+ typeof (action as CloudCliAction).type === "string",
48
+ )
49
+ )
50
+ ) {
51
+ return null;
52
+ }
53
+ return body as CloudCliResponse;
54
+ };
55
+
56
+ const cliVersion: string =
57
+ typeof __AUI_PACKAGE_VERSION__ === "string"
58
+ ? __AUI_PACKAGE_VERSION__
59
+ : "0.0.0";
60
+
61
+ export const sendCloudCommand = async (
62
+ cloudUrl: string,
63
+ args: readonly string[],
64
+ accessToken: string | null,
65
+ ): Promise<CloudCliResponse> => {
66
+ const url = `${validateCloudUrl(cloudUrl)}${CLOUD_CLI_RUN_PATH}`;
67
+ let response: Response;
68
+ try {
69
+ response = await fetch(url, {
70
+ method: "POST",
71
+ headers: {
72
+ "Content-Type": "application/json",
73
+ ...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
74
+ },
75
+ body: JSON.stringify({
76
+ command: joinCloudArgs(args),
77
+ client: {
78
+ name: "assistant-ui",
79
+ version: cliVersion,
80
+ platform: `${process.platform}-${process.arch}`,
81
+ },
82
+ }),
83
+ redirect: "error",
84
+ signal: AbortSignal.timeout(60_000),
85
+ });
86
+ } catch (error) {
87
+ const cause = (error as Error).cause as NodeJS.ErrnoException | undefined;
88
+ throw new Error(
89
+ `Could not reach ${url}: ${cause?.message || cause?.code || (error as Error).message}`,
90
+ );
91
+ }
92
+ const body = parseCloudCliResponse(await response.json().catch(() => null));
93
+ if (!body) {
94
+ throw new Error(
95
+ `Unexpected response from ${url} (${response.status} ${response.statusText}).`,
96
+ );
97
+ }
98
+ return body;
99
+ };
100
+
101
+ // A response naming an action this client lacks fails before printing, so the
102
+ // server can roll a new action out behind the client version it is sent.
103
+ const ACTION_HANDLERS: Record<
104
+ string,
105
+ (action: CloudCliAction) => Promise<number>
106
+ > = {};
107
+
108
+ export const runCloudCommand = async (
109
+ args: readonly string[],
110
+ deps: {
111
+ cloudUrl: string;
112
+ accessToken: () => Promise<string | null>;
113
+ stdout: (text: string) => void;
114
+ stderr: (text: string) => void;
115
+ send?: typeof sendCloudCommand;
116
+ },
117
+ ): Promise<number> => {
118
+ let response: CloudCliResponse;
119
+ try {
120
+ response = await (deps.send ?? sendCloudCommand)(
121
+ deps.cloudUrl,
122
+ args,
123
+ await deps.accessToken().catch((error: unknown) => {
124
+ deps.stderr(
125
+ `${error instanceof Error ? error.message : String(error)}\n`,
126
+ );
127
+ return null;
128
+ }),
129
+ );
130
+ } catch (error) {
131
+ deps.stderr(`${error instanceof Error ? error.message : String(error)}\n`);
132
+ return 1;
133
+ }
134
+ const unknown = response.actions?.find(
135
+ (action) => !Object.hasOwn(ACTION_HANDLERS, action.type),
136
+ );
137
+ if (unknown) {
138
+ deps.stderr(
139
+ `This command needs a newer assistant-ui (unsupported action "${unknown.type}"). Update the CLI and try again.\n`,
140
+ );
141
+ return 1;
142
+ }
143
+ if (response.stdout) deps.stdout(response.stdout);
144
+ if (response.stderr) deps.stderr(response.stderr);
145
+ for (const action of response.actions ?? []) {
146
+ const code = await ACTION_HANDLERS[action.type]!(action);
147
+ if (code !== 0) return code;
148
+ }
149
+ return response.exitCode;
150
+ };
@@ -0,0 +1,39 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { installPackageIfNeeded } from "./package-installer";
3
+
4
+ const mocks = vi.hoisted(() => ({
5
+ askQuestion: vi.fn(),
6
+ installPackage: vi.fn(),
7
+ }));
8
+
9
+ vi.mock("./file-scanner", async (importOriginal) => ({
10
+ ...(await importOriginal<typeof import("./file-scanner")>()),
11
+ scanForImport: () => true,
12
+ }));
13
+
14
+ vi.mock("./package-manager", async (importOriginal) => ({
15
+ ...(await importOriginal<typeof import("./package-manager")>()),
16
+ isPackageInstalled: () => false,
17
+ askQuestion: mocks.askQuestion,
18
+ installPackage: mocks.installPackage,
19
+ }));
20
+
21
+ describe("installPackageIfNeeded", () => {
22
+ it.each(["y", ""])(
23
+ "rejects a failed required install after accepting with %j",
24
+ async (answer) => {
25
+ mocks.askQuestion.mockResolvedValue(answer);
26
+ mocks.installPackage.mockResolvedValue(false);
27
+
28
+ await expect(
29
+ installPackageIfNeeded({
30
+ packageName: "@assistant-ui/ai-sdk",
31
+ importPatterns: ["@assistant-ui/ai-sdk"],
32
+ promptMessage: "Install?",
33
+ skipMessage: "Already installed",
34
+ notFoundMessage: "Not found",
35
+ }),
36
+ ).rejects.toThrow("Failed to install @assistant-ui/ai-sdk");
37
+ },
38
+ );
39
+ });
@@ -31,7 +31,9 @@ export async function installPackageIfNeeded(
31
31
 
32
32
  const answer = await askQuestion(config.promptMessage);
33
33
  if (answer === "" || answer.toLowerCase().startsWith("y")) {
34
- await installPackage(config.packageName);
34
+ if (!(await installPackage(config.packageName))) {
35
+ throw new Error(`Failed to install ${config.packageName}`);
36
+ }
35
37
  } else {
36
38
  logger.info("Skipping installation.");
37
39
  }
@@ -141,11 +141,13 @@ function ToolFallbackDuration({
141
141
  function ToolFallbackTrigger({
142
142
  toolName,
143
143
  status,
144
+ responseDeliveryStatus,
144
145
  className,
145
146
  ...props
146
147
  }: React.ComponentProps<typeof CollapsibleTrigger> & {
147
148
  toolName: string;
148
149
  status?: ToolCallMessagePartStatus;
150
+ responseDeliveryStatus?: ToolCallMessagePart["responseDeliveryStatus"];
149
151
  }) {
150
152
  const statusType = status?.type ?? "complete";
151
153
  const isRunning = statusType === "running";
@@ -154,13 +156,15 @@ function ToolFallbackTrigger({
154
156
 
155
157
  const Icon = statusIconMap[statusType];
156
158
  const label =
157
- statusType === "running"
158
- ? "Running tool"
159
- : statusType === "requires-action"
160
- ? "Waiting on tool"
161
- : statusType === "incomplete"
162
- ? `${isCancelled ? "Cancelled" : "Failed"} tool`
163
- : "Used tool";
159
+ responseDeliveryStatus === "queued"
160
+ ? "Reply queued, not sent yet"
161
+ : statusType === "running"
162
+ ? "Running tool"
163
+ : statusType === "requires-action"
164
+ ? "Waiting on tool"
165
+ : statusType === "incomplete"
166
+ ? `${isCancelled ? "Cancelled" : "Failed"} tool`
167
+ : "Used tool";
164
168
 
165
169
  return (
166
170
  <CollapsibleTrigger
@@ -1195,6 +1199,7 @@ const ToolFallbackImpl: ToolCallMessagePartComponent = ({
1195
1199
  argsText,
1196
1200
  result,
1197
1201
  status,
1202
+ responseDeliveryStatus,
1198
1203
  addResult,
1199
1204
  resume,
1200
1205
  interrupt,
@@ -1243,7 +1248,11 @@ const ToolFallbackImpl: ToolCallMessagePartComponent = ({
1243
1248
 
1244
1249
  return (
1245
1250
  <ToolFallbackRoot open={open} onOpenChange={setOpen}>
1246
- <ToolFallbackTrigger toolName={toolName} status={status} />
1251
+ <ToolFallbackTrigger
1252
+ toolName={toolName}
1253
+ status={status}
1254
+ responseDeliveryStatus={responseDeliveryStatus}
1255
+ />
1247
1256
  <ToolFallbackContent>
1248
1257
  <ToolFallbackError status={status} />
1249
1258
  <ToolFallbackArgs
@@ -28,13 +28,13 @@
28
28
  "cn": "^0.4.0",
29
29
  "harness-sdk": "file:vendor/harness-sdk-0.3.1.tgz",
30
30
  "lucide-react": "^1.52.0",
31
- "next": "^16.4.0",
31
+ "next": "^16.4.1",
32
32
  "react": "^19.3.0",
33
33
  "react-dom": "^19.3.0",
34
34
  "remark-gfm": "^4.0.1",
35
35
  "statewire": "file:vendor/statewire-0.19.3.tgz",
36
36
  "tw-animate-css": "^1.4.0",
37
- "tw-shimmer": "^0.4.13",
37
+ "tw-shimmer": "^0.4.14",
38
38
  "zustand": "^5.0.15"
39
39
  },
40
40
  "devDependencies": {