@alexkroman1/aai-cli 5.3.0 → 5.5.0

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 (99) hide show
  1. package/README.md +51 -0
  2. package/dist/{_agent-D8zBb3M5.mjs → _agent-DMyOab9_.mjs} +2 -2
  3. package/dist/{_bundler-DFS4xxqE.mjs → _bundler-Cjaxa2wi.mjs} +1 -1
  4. package/dist/{_config-D3F9km8X.mjs → _config-5AEqhh-O.mjs} +2 -2
  5. package/dist/{_dev-server-BBUWo0sb.mjs → _dev-server-vV05Fnki.mjs} +3 -3
  6. package/dist/{_init-DU-sXH6S.mjs → _init-BZ9t_Kz-.mjs} +3 -56
  7. package/dist/{_slug-api-19R5kZ0U.mjs → _slug-api-DaqQJHk8.mjs} +1 -1
  8. package/dist/_templates-Bv8CR800.mjs +69 -0
  9. package/dist/_templates.d.ts +6 -0
  10. package/dist/{build-Xq1xxoSg.mjs → build-D_PgQOD4.mjs} +1 -1
  11. package/dist/cli.mjs +59 -17
  12. package/dist/{client-bundler-BWDkUeEP.mjs → client-bundler-yiWoXrgb.mjs} +3 -0
  13. package/dist/client-bundler.d.ts +9 -0
  14. package/dist/client-bundler.mjs +1 -1
  15. package/dist/{delete-kSXFLxek.mjs → delete-DXilFBb1.mjs} +1 -1
  16. package/dist/{deploy-Ci0X1gp2.mjs → deploy-1eaXcfUw.mjs} +3 -3
  17. package/dist/{dev-g7sGt8qX.mjs → dev-gVNdGFYY.mjs} +1 -1
  18. package/dist/{init-BjeK8crW.mjs → init-DoU4_txp.mjs} +3 -3
  19. package/dist/login-C59ZHzuO.mjs +109 -0
  20. package/dist/login.d.ts +34 -0
  21. package/dist/scaffold/CLAUDE.md +190 -120
  22. package/dist/scaffold/package.json +3 -3
  23. package/dist/{secret-DOva9OGk.mjs → secret-CGAIAbUx.mjs} +1 -1
  24. package/dist/{storage-vM6HjDZZ.mjs → storage-CnhOayhm.mjs} +1 -1
  25. package/dist/templates/code-interpreter/agent.ts +1 -2
  26. package/dist/templates/dispatch-center/agent.test.ts +3 -3
  27. package/dist/templates/dispatch-center/agent.ts +7 -7
  28. package/dist/templates/dispatch-center/client.tsx +7 -2
  29. package/dist/templates/dispatch-center/tools/incident_add_note.ts +1 -1
  30. package/dist/templates/dispatch-center/tools/incident_create.ts +1 -1
  31. package/dist/templates/dispatch-center/tools/incident_escalate.ts +1 -1
  32. package/dist/templates/dispatch-center/tools/incident_get.ts +1 -1
  33. package/dist/templates/dispatch-center/tools/incident_triage.ts +1 -1
  34. package/dist/templates/dispatch-center/tools/incident_update_status.ts +1 -1
  35. package/dist/templates/dispatch-center/tools/ops_protocols.ts +1 -1
  36. package/dist/templates/dispatch-center/tools/ops_run_scenario.ts +1 -1
  37. package/dist/templates/dispatch-center/tools/resources_dispatch.ts +1 -1
  38. package/dist/templates/dispatch-center/tools/resources_get_available.ts +1 -1
  39. package/dist/templates/dispatch-center/tools/resources_update_status.ts +1 -1
  40. package/dist/templates/embedded-assets/agent.ts +2 -3
  41. package/dist/templates/health-assistant/agent.ts +3 -4
  42. package/dist/templates/infocom-adventure/agent.ts +10 -12
  43. package/dist/templates/infocom-adventure/client.tsx +5 -5
  44. package/dist/templates/math-buddy/agent.ts +7 -6
  45. package/dist/templates/night-owl/agent.ts +2 -3
  46. package/dist/templates/personal-finance/agent.ts +1 -2
  47. package/dist/templates/pipeline-simple/agent.test.ts +13 -13
  48. package/dist/templates/pipeline-simple/agent.ts +5 -6
  49. package/dist/templates/pizza-ordering/agent.test.ts +13 -11
  50. package/dist/templates/pizza-ordering/agent.ts +5 -6
  51. package/dist/templates/retail/address.ts +29 -0
  52. package/dist/templates/retail/agent.test.ts +1030 -0
  53. package/dist/templates/retail/agent.ts +71 -0
  54. package/dist/templates/retail/authenticate.ts +34 -0
  55. package/dist/templates/retail/client.tsx +459 -0
  56. package/dist/templates/retail/refund.ts +19 -0
  57. package/dist/templates/retail/registry.test.ts +182 -0
  58. package/dist/templates/retail/resolve.test.ts +158 -0
  59. package/dist/templates/retail/resolve.ts +158 -0
  60. package/dist/templates/retail/seed.json +4260 -0
  61. package/dist/templates/retail/seed.test.ts +224 -0
  62. package/dist/templates/retail/shared.test.ts +192 -0
  63. package/dist/templates/retail/shared.ts +430 -0
  64. package/dist/templates/retail/store.test.ts +256 -0
  65. package/dist/templates/retail/store.ts +243 -0
  66. package/dist/templates/retail/swap.test.ts +186 -0
  67. package/dist/templates/retail/swap.ts +138 -0
  68. package/dist/templates/retail/system-prompt.md +111 -0
  69. package/dist/templates/retail/tools/cancel_pending_order.ts +82 -0
  70. package/dist/templates/retail/tools/exchange_delivered_order_items.ts +83 -0
  71. package/dist/templates/retail/tools/find_user_id_by_email.ts +32 -0
  72. package/dist/templates/retail/tools/find_user_id_by_name_zip.ts +38 -0
  73. package/dist/templates/retail/tools/get_item_details.ts +29 -0
  74. package/dist/templates/retail/tools/get_order_details.ts +41 -0
  75. package/dist/templates/retail/tools/get_product_details.ts +33 -0
  76. package/dist/templates/retail/tools/get_user_details.ts +44 -0
  77. package/dist/templates/retail/tools/list_all_product_types.ts +24 -0
  78. package/dist/templates/retail/tools/modify_pending_order_address.ts +46 -0
  79. package/dist/templates/retail/tools/modify_pending_order_items.ts +102 -0
  80. package/dist/templates/retail/tools/modify_pending_order_payment.ts +103 -0
  81. package/dist/templates/retail/tools/modify_user_address.ts +38 -0
  82. package/dist/templates/retail/tools/return_delivered_order_items.ts +101 -0
  83. package/dist/templates/retail/tools/transfer_to_human_agents.ts +22 -0
  84. package/dist/templates/simple/agent.test.ts +18 -0
  85. package/dist/templates/simple/agent.ts +3 -0
  86. package/dist/templates/solo-rpg/agent.test.ts +2 -2
  87. package/dist/templates/solo-rpg/agent.ts +1 -2
  88. package/dist/templates/solo-rpg/tools/action_roll.ts +1 -1
  89. package/dist/templates/solo-rpg/tools/load_game.ts +1 -1
  90. package/dist/templates/solo-rpg/tools/oracle.ts +1 -1
  91. package/dist/templates/solo-rpg/tools/save_game.ts +1 -1
  92. package/dist/templates/solo-rpg/tools/setup_character.ts +1 -1
  93. package/dist/templates/solo-rpg/tools/update_state.ts +1 -1
  94. package/dist/templates/web-researcher/agent.ts +1 -2
  95. package/dist/typecheck.d.ts +18 -0
  96. package/dist/typecheck.mjs +8 -0
  97. package/dist/worker-bundler.d.ts +9 -1
  98. package/dist/worker-bundler.mjs +8 -0
  99. package/package.json +3 -3
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+ import { a as unwrapCancel, n as log, o as CliError, u as ok } from "./_ui-8kOEB-JH.mjs";
3
+ import { i as readGlobalConfig, r as getConfigDir, s as writeGlobalConfig, t as approveServer } from "./_config-5AEqhh-O.mjs";
4
+ import { a as resolveServerUrl } from "./_agent-DMyOab9_.mjs";
5
+ import * as p from "@clack/prompts";
6
+ //#region login.ts
7
+ /**
8
+ * `aai login` — email sign-in against the platform, ending with the
9
+ * account's AssemblyAI API key stored in the global config (the same slot
10
+ * `ensureApiKey` reads), so every other command is untouched by how the
11
+ * key was acquired.
12
+ *
13
+ * Flow (the CLI mirror of the browser studio's two gates):
14
+ * 1. `GET /studio/auth` names the login mode.
15
+ * - `supabase`: Supabase email OTP — `POST /auth/v1/otp` emails a
16
+ * one-time code, the user types it here, `POST /auth/v1/verify`
17
+ * returns the session. The magic LINK in the same email targets the
18
+ * browser; the CLI uses the code because a terminal has no redirect
19
+ * to land on. (The Supabase email template must include the
20
+ * `{{ .Token }}` code for this to work.)
21
+ * - `dev`: mint the same self-describing dev token the studio's local
22
+ * login mints — nothing is emailed anywhere.
23
+ * 2. `GET /studio/account` — when no key is on file yet, prompt for one
24
+ * and `PUT /studio/account/key` (the same mandatory onboarding step
25
+ * the browser shows after sign-in).
26
+ * 3. `GET /studio/account/key` — fetch the key and save it locally.
27
+ * Unlike the browser, the CLI needs the RAW key: `aai dev` runs the
28
+ * provider pipeline in-process on it.
29
+ */
30
+ async function jsonBody(res, what) {
31
+ const body = await res.json().catch(() => null);
32
+ if (!res.ok) throw new CliError("login_failed", `${what} failed: ${body?.error ?? body?.msg ?? `HTTP ${res.status}`}`);
33
+ if (body === null) throw new CliError("login_failed", `${what} returned an invalid response`);
34
+ return body;
35
+ }
36
+ function requireTty() {
37
+ if (!process.stdin.isTTY) throw new CliError("login_interactive", "`aai login` is interactive and needs a TTY.", "Non-interactive setups can set the ASSEMBLYAI_API_KEY environment variable instead.");
38
+ }
39
+ /** The same self-describing token the studio's local-dev login mints. */
40
+ function mintDevToken(email) {
41
+ return `dev.${Buffer.from(JSON.stringify({
42
+ id: `dev:${email}`,
43
+ email
44
+ })).toString("base64url").replace(/=+$/, "")}.dev`;
45
+ }
46
+ /** Supabase email OTP: send the code, prompt for it, verify to a session. */
47
+ async function supabaseSession(auth, email, fetchFn) {
48
+ const base = auth.supabaseUrl.replace(/\/+$/, "");
49
+ const headers = {
50
+ apikey: auth.supabasePublishableKey,
51
+ "Content-Type": "application/json"
52
+ };
53
+ await jsonBody(await fetchFn(`${base}/auth/v1/otp`, {
54
+ method: "POST",
55
+ headers,
56
+ body: JSON.stringify({
57
+ email,
58
+ create_user: true
59
+ })
60
+ }), "Sending the sign-in code");
61
+ log.info(`Sent a sign-in code to ${email}.`);
62
+ const code = unwrapCancel(await p.text({ message: "Enter the code from your email" }), "Login cancelled").trim();
63
+ const session = await jsonBody(await fetchFn(`${base}/auth/v1/verify`, {
64
+ method: "POST",
65
+ headers,
66
+ body: JSON.stringify({
67
+ type: "email",
68
+ email,
69
+ token: code
70
+ })
71
+ }), "Verifying the code");
72
+ if (!session.access_token) throw new CliError("login_failed", "Verifying the code did not return a session.");
73
+ return session.access_token;
74
+ }
75
+ async function executeLogin(opts, deps = {}) {
76
+ const fetchFn = deps.fetchFn ?? globalThis.fetch;
77
+ requireTty();
78
+ const globalConfig = await readGlobalConfig();
79
+ const serverUrl = resolveServerUrl(opts.server, void 0, globalConfig.approvedServers ?? []);
80
+ if (opts.server) await approveServer(serverUrl);
81
+ const auth = await jsonBody(await fetchFn(`${serverUrl}/studio/auth`), "Reading the server's login configuration");
82
+ if (auth.mode === "none") throw new CliError("login_unavailable", "This server has no browser/email login configured.", "Set the ASSEMBLYAI_API_KEY environment variable, or run any platform command to be prompted for a key.");
83
+ const email = unwrapCancel(await p.text({ message: "Email address" }), "Login cancelled").trim();
84
+ const bearer = { Authorization: `Bearer ${auth.mode === "dev" ? mintDevToken(email) : await supabaseSession(auth, email, fetchFn)}` };
85
+ if (!(await jsonBody(await fetchFn(`${serverUrl}/studio/account`, { headers: bearer }), "Loading your account")).hasKey) {
86
+ const newKey = unwrapCancel(await p.password({ message: "Enter your AssemblyAI API key (stored with your account)" }), "Login cancelled").trim();
87
+ await jsonBody(await fetchFn(`${serverUrl}/studio/account/key`, {
88
+ method: "PUT",
89
+ headers: {
90
+ ...bearer,
91
+ "Content-Type": "application/json"
92
+ },
93
+ body: JSON.stringify({ apiKey: newKey })
94
+ }), "Saving your API key");
95
+ }
96
+ const { apiKey } = await jsonBody(await fetchFn(`${serverUrl}/studio/account/key`, { headers: bearer }), "Fetching your API key");
97
+ const dir = getConfigDir();
98
+ await writeGlobalConfig(dir, {
99
+ ...await readGlobalConfig(dir),
100
+ apiKey
101
+ });
102
+ log.success(`Signed in as ${email} — your API key is saved for future commands.`);
103
+ return ok({
104
+ email,
105
+ server: serverUrl
106
+ });
107
+ }
108
+ //#endregion
109
+ export { executeLogin };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * `aai login` — email sign-in against the platform, ending with the
3
+ * account's AssemblyAI API key stored in the global config (the same slot
4
+ * `ensureApiKey` reads), so every other command is untouched by how the
5
+ * key was acquired.
6
+ *
7
+ * Flow (the CLI mirror of the browser studio's two gates):
8
+ * 1. `GET /studio/auth` names the login mode.
9
+ * - `supabase`: Supabase email OTP — `POST /auth/v1/otp` emails a
10
+ * one-time code, the user types it here, `POST /auth/v1/verify`
11
+ * returns the session. The magic LINK in the same email targets the
12
+ * browser; the CLI uses the code because a terminal has no redirect
13
+ * to land on. (The Supabase email template must include the
14
+ * `{{ .Token }}` code for this to work.)
15
+ * - `dev`: mint the same self-describing dev token the studio's local
16
+ * login mints — nothing is emailed anywhere.
17
+ * 2. `GET /studio/account` — when no key is on file yet, prompt for one
18
+ * and `PUT /studio/account/key` (the same mandatory onboarding step
19
+ * the browser shows after sign-in).
20
+ * 3. `GET /studio/account/key` — fetch the key and save it locally.
21
+ * Unlike the browser, the CLI needs the RAW key: `aai dev` runs the
22
+ * provider pipeline in-process on it.
23
+ */
24
+ import { type CommandResult } from "./_output.ts";
25
+ export type LoginDeps = {
26
+ /** Test seam — never set outside tests. */
27
+ fetchFn?: typeof globalThis.fetch;
28
+ };
29
+ export declare function executeLogin(opts: {
30
+ server?: string | undefined;
31
+ }, deps?: LoginDeps): Promise<CommandResult<{
32
+ email: string;
33
+ server: string;
34
+ }>>;