@alexkroman1/aai-cli 5.14.0 → 6.1.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 (231) hide show
  1. package/dist/{_agent-C8Jk-ZcP.mjs → _agent-vGW5SBnX.mjs} +23 -5
  2. package/dist/_agent.d.ts +18 -0
  3. package/dist/{_api-client-BX8Qv51n.mjs → _api-client-LgLksMhN.mjs} +45 -8
  4. package/dist/_api-client.d.ts +39 -0
  5. package/dist/{_bundler-BuIyDdvs.mjs → _bundler-BapCUUJN.mjs} +42 -14
  6. package/dist/_bundler.d.ts +43 -5
  7. package/dist/_cli-common.d.ts +67 -3
  8. package/dist/{_config-CzwAWOWr.mjs → _config-D_s09e7g.mjs} +36 -18
  9. package/dist/_deploy.d.ts +2 -5
  10. package/dist/_dev-restart.d.ts +6 -1
  11. package/dist/{_dev-server-Ch7K8e8i.mjs → _dev-server-DQ1t9sbw.mjs} +94 -38
  12. package/dist/_dev-server.d.ts +30 -2
  13. package/dist/_e2e-test-utils.d.ts +80 -0
  14. package/dist/_fault-mode.d.ts +175 -0
  15. package/dist/{_init-CbkrE2wq.mjs → _init-CpISqoR8.mjs} +3 -3
  16. package/dist/{_output-CC300DzW.mjs → _output-CKkmWs7i.mjs} +8 -1
  17. package/dist/_output.d.ts +9 -2
  18. package/dist/{_server-common-61fL__39.mjs → _server-common-6e0QI4mq.mjs} +1 -1
  19. package/dist/{_slug-api-D30zPmsn.mjs → _slug-api-D2heILuC.mjs} +2 -2
  20. package/dist/{_studio-D2ciIhbi.mjs → _studio-zAJycZ8j.mjs} +3 -3
  21. package/dist/{_templates-B1kt3BGt.mjs → _templates-iDGjGiPf.mjs} +4 -6
  22. package/dist/{_typecheck-gate-4v9UBZHh.mjs → _typecheck-gate-BXvUNnfs.mjs} +1 -1
  23. package/dist/{_utils-0DHbcqUb.mjs → _utils-B8QmtFhK.mjs} +21 -7
  24. package/dist/_utils.d.ts +18 -2
  25. package/dist/{_vite-env-Dg_QlVv0.mjs → _vite-env-BNveawd1.mjs} +31 -1
  26. package/dist/_vite-env.d.ts +30 -0
  27. package/dist/build-BO1Ni6oJ.mjs +62 -0
  28. package/dist/build.d.ts +19 -0
  29. package/dist/cli-workflow.d.ts +10 -0
  30. package/dist/cli.d.ts +1 -2
  31. package/dist/cli.mjs +406 -224
  32. package/dist/{client-bundler-C9qXL8A2.mjs → client-bundler-B8Q9F8gJ.mjs} +3 -22
  33. package/dist/client-bundler.mjs +1 -1
  34. package/dist/{delete-DCRX3d96.mjs → delete-4I0uNR4a.mjs} +6 -7
  35. package/dist/delete.d.ts +2 -8
  36. package/dist/{deploy-DjsEV-40.mjs → deploy-DJ3HRcia.mjs} +13 -14
  37. package/dist/{dev-CvPH5dbF.mjs → dev-C6SWaAZP.mjs} +3 -3
  38. package/dist/{eject-LgBRfnbH.mjs → eject-Zrzk5KV3.mjs} +41 -15
  39. package/dist/eject.d.ts +30 -3
  40. package/dist/{init-BppxMR8r.mjs → init-BTRGiPQr.mjs} +61 -26
  41. package/dist/init.d.ts +11 -0
  42. package/dist/{login-BQQaxJhL.mjs → login-k0Z3VQu9.mjs} +5 -5
  43. package/dist/project-config.mjs +1 -1
  44. package/dist/scaffold/CLAUDE.md +498 -91
  45. package/dist/scaffold/package.json +11 -8
  46. package/dist/scaffold/pnpm-workspace.yaml +8 -0
  47. package/dist/scaffold/server.mjs +53 -57
  48. package/dist/{secret-Ds9dvqAj.mjs → secret-DzSQx1Ds.mjs} +6 -3
  49. package/dist/{storage-DbrQSHFk.mjs → storage-C-Do0mIA.mjs} +18 -6
  50. package/dist/{studio-GSFd4s5O.mjs → studio-BGVmCA2G.mjs} +10 -10
  51. package/dist/templates/code-interpreter/agent.ts +0 -2
  52. package/dist/templates/dispatch-center/agent.test.ts +17 -19
  53. package/dist/templates/dispatch-center/agent.ts +2 -29
  54. package/dist/templates/dispatch-center/client.tsx +33 -16
  55. package/dist/templates/dispatch-center/shared.ts +53 -19
  56. package/dist/templates/dispatch-center/tools/incident_add_note.ts +12 -14
  57. package/dist/templates/dispatch-center/tools/incident_create.ts +41 -44
  58. package/dist/templates/dispatch-center/tools/incident_escalate.ts +59 -61
  59. package/dist/templates/dispatch-center/tools/incident_get.ts +3 -4
  60. package/dist/templates/dispatch-center/tools/incident_triage.ts +43 -45
  61. package/dist/templates/dispatch-center/tools/incident_update_status.ts +39 -41
  62. package/dist/templates/dispatch-center/tools/ops_dashboard.ts +2 -5
  63. package/dist/templates/dispatch-center/tools/ops_protocols.ts +1 -1
  64. package/dist/templates/dispatch-center/tools/ops_run_scenario.ts +20 -23
  65. package/dist/templates/dispatch-center/tools/resources_dispatch.ts +52 -54
  66. package/dist/templates/dispatch-center/tools/resources_get_available.ts +2 -4
  67. package/dist/templates/dispatch-center/tools/resources_update_status.ts +39 -42
  68. package/dist/templates/embedded-assets/agent.test.ts +83 -0
  69. package/dist/templates/embedded-assets/agent.ts +1 -48
  70. package/dist/templates/embedded-assets/shared.ts +17 -0
  71. package/dist/templates/embedded-assets/system-prompt.md +13 -0
  72. package/dist/templates/embedded-assets/tools/list_topics.ts +9 -0
  73. package/dist/templates/embedded-assets/tools/search_knowledge.ts +26 -0
  74. package/dist/templates/health-assistant/agent.test.ts +169 -0
  75. package/dist/templates/health-assistant/agent.ts +1 -166
  76. package/dist/templates/health-assistant/fda.ts +100 -0
  77. package/dist/templates/health-assistant/tools/check_drug_interaction.ts +59 -0
  78. package/dist/templates/health-assistant/tools/medication_lookup.ts +31 -0
  79. package/dist/templates/infocom-adventure/agent.test.ts +205 -0
  80. package/dist/templates/infocom-adventure/agent.ts +3 -106
  81. package/dist/templates/infocom-adventure/client.tsx +28 -12
  82. package/dist/templates/infocom-adventure/shared.ts +28 -11
  83. package/dist/templates/infocom-adventure/tools/game_state_drop.ts +13 -0
  84. package/dist/templates/infocom-adventure/tools/game_state_flag.ts +13 -0
  85. package/dist/templates/infocom-adventure/tools/game_state_get.ts +16 -0
  86. package/dist/templates/infocom-adventure/tools/game_state_history.ts +14 -0
  87. package/dist/templates/infocom-adventure/tools/game_state_move.ts +14 -0
  88. package/dist/templates/infocom-adventure/tools/game_state_restart.ts +13 -0
  89. package/dist/templates/infocom-adventure/tools/game_state_score.ts +13 -0
  90. package/dist/templates/infocom-adventure/tools/game_state_take.ts +13 -0
  91. package/dist/templates/link-digest/agent.test.ts +223 -0
  92. package/dist/templates/link-digest/agent.ts +79 -0
  93. package/dist/templates/link-digest/client.tsx +146 -0
  94. package/dist/templates/link-digest/workflows/digest.ts +248 -0
  95. package/dist/templates/math-buddy/agent.ts +0 -2
  96. package/dist/templates/night-owl/agent.test.ts +80 -0
  97. package/dist/templates/night-owl/agent.ts +1 -68
  98. package/dist/templates/night-owl/system-prompt.md +10 -0
  99. package/dist/templates/night-owl/tools/recommend.ts +64 -0
  100. package/dist/templates/personal-finance/agent.ts +0 -2
  101. package/dist/templates/pizza-ordering/agent.test.ts +52 -47
  102. package/dist/templates/pizza-ordering/agent.ts +9 -158
  103. package/dist/templates/pizza-ordering/shared.ts +35 -12
  104. package/dist/templates/pizza-ordering/tools/add_pizza.ts +31 -0
  105. package/dist/templates/pizza-ordering/tools/place_order.ts +22 -0
  106. package/dist/templates/pizza-ordering/tools/remove_pizza.ts +22 -0
  107. package/dist/templates/pizza-ordering/tools/set_customer_name.ts +13 -0
  108. package/dist/templates/pizza-ordering/tools/update_pizza.ts +28 -0
  109. package/dist/templates/pizza-ordering/tools/view_order.ts +21 -0
  110. package/dist/templates/plan-and-execute/agent.test.ts +411 -0
  111. package/dist/templates/plan-and-execute/agent.ts +23 -0
  112. package/dist/templates/plan-and-execute/client.tsx +115 -0
  113. package/dist/templates/plan-and-execute/graph.ts +178 -0
  114. package/dist/templates/plan-and-execute/prompts.ts +110 -0
  115. package/dist/templates/plan-and-execute/shared.ts +161 -0
  116. package/dist/templates/plan-and-execute/system-prompt.md +18 -0
  117. package/dist/templates/plan-and-execute/tools/plan_status.ts +20 -0
  118. package/dist/templates/plan-and-execute/tools/revise_plan.ts +63 -0
  119. package/dist/templates/plan-and-execute/tools/start_plan.ts +51 -0
  120. package/dist/templates/plan-and-execute/tools/work_next_step.ts +101 -0
  121. package/dist/templates/recap-workflow/agent.test.ts +762 -0
  122. package/dist/templates/recap-workflow/agent.ts +95 -0
  123. package/dist/templates/recap-workflow/shared.ts +43 -0
  124. package/dist/templates/recap-workflow/tools/cancel_recap.ts +23 -0
  125. package/dist/templates/recap-workflow/tools/keep_transcript.ts +31 -0
  126. package/dist/templates/recap-workflow/tools/recap_progress.ts +27 -0
  127. package/dist/templates/recap-workflow/tools/recap_status.ts +46 -0
  128. package/dist/templates/recap-workflow/tools/request_recap.ts +43 -0
  129. package/dist/templates/recap-workflow/workflows/recap.ts +544 -0
  130. package/dist/templates/recap-workflow/workflows/tokens.ts +26 -0
  131. package/dist/templates/redline/agent.test.ts +222 -0
  132. package/dist/templates/redline/agent.ts +89 -0
  133. package/dist/templates/redline/client.tsx +184 -0
  134. package/dist/templates/redline/workflows/prompts.ts +68 -0
  135. package/dist/templates/redline/workflows/redline.ts +258 -0
  136. package/dist/templates/research-workflow/agent.test.ts +525 -0
  137. package/dist/templates/research-workflow/agent.ts +94 -0
  138. package/dist/templates/research-workflow/shared.ts +35 -0
  139. package/dist/templates/research-workflow/tools/file_it_now.ts +22 -0
  140. package/dist/templates/research-workflow/tools/request_research.ts +33 -0
  141. package/dist/templates/research-workflow/tools/research_progress.ts +26 -0
  142. package/dist/templates/research-workflow/tools/research_status.ts +40 -0
  143. package/dist/templates/research-workflow/workflows/prompts.ts +143 -0
  144. package/dist/templates/research-workflow/workflows/research.ts +558 -0
  145. package/dist/templates/retail/agent.test.ts +236 -172
  146. package/dist/templates/retail/agent.ts +5 -42
  147. package/dist/templates/retail/client.tsx +33 -11
  148. package/dist/templates/retail/registry.test.ts +31 -16
  149. package/dist/templates/retail/resolve.ts +28 -64
  150. package/dist/templates/retail/shared.test.ts +4 -3
  151. package/dist/templates/retail/shared.ts +24 -7
  152. package/dist/templates/retail/store.test.ts +12 -10
  153. package/dist/templates/retail/store.ts +69 -30
  154. package/dist/templates/retail/tools/cancel_pending_order.ts +4 -9
  155. package/dist/templates/retail/tools/exchange_delivered_order_items.ts +22 -11
  156. package/dist/templates/retail/tools/find_user_id_by_email.ts +5 -9
  157. package/dist/templates/retail/tools/find_user_id_by_name_zip.ts +5 -7
  158. package/dist/templates/retail/tools/get_item_details.ts +5 -7
  159. package/dist/templates/retail/tools/get_order_details.ts +5 -7
  160. package/dist/templates/retail/tools/get_product_details.ts +4 -7
  161. package/dist/templates/retail/tools/get_user_details.ts +4 -7
  162. package/dist/templates/retail/tools/list_all_product_types.ts +5 -7
  163. package/dist/templates/retail/tools/modify_pending_order_address.ts +4 -9
  164. package/dist/templates/retail/tools/modify_pending_order_items.ts +4 -16
  165. package/dist/templates/retail/tools/modify_pending_order_payment.ts +3 -9
  166. package/dist/templates/retail/tools/modify_user_address.ts +4 -9
  167. package/dist/templates/retail/tools/return_delivered_order_items.ts +3 -9
  168. package/dist/templates/retail/tools/transfer_to_human_agents.ts +1 -1
  169. package/dist/templates/solo-rpg/agent.test.ts +152 -29
  170. package/dist/templates/solo-rpg/agent.ts +3 -21
  171. package/dist/templates/solo-rpg/client.tsx +19 -6
  172. package/dist/templates/solo-rpg/shared.ts +19 -11
  173. package/dist/templates/solo-rpg/tools/action_roll.ts +2 -4
  174. package/dist/templates/solo-rpg/tools/burn_momentum.ts +2 -4
  175. package/dist/templates/solo-rpg/tools/check_state.ts +6 -6
  176. package/dist/templates/solo-rpg/tools/load_game.ts +1 -1
  177. package/dist/templates/solo-rpg/tools/oracle.ts +18 -11
  178. package/dist/templates/solo-rpg/tools/save_game.ts +10 -7
  179. package/dist/templates/solo-rpg/tools/setup_character.ts +1 -1
  180. package/dist/templates/solo-rpg/tools/update_state.ts +3 -4
  181. package/dist/templates/support-line/agent.test.ts +343 -0
  182. package/dist/templates/support-line/agent.ts +27 -0
  183. package/dist/templates/support-line/client.tsx +122 -0
  184. package/dist/templates/support-line/graph.ts +224 -0
  185. package/dist/templates/support-line/knowledge.json +65 -0
  186. package/dist/templates/support-line/prompts.ts +95 -0
  187. package/dist/templates/support-line/shared.ts +240 -0
  188. package/dist/templates/support-line/system-prompt.md +17 -0
  189. package/dist/templates/support-line/tools/answer_question.ts +72 -0
  190. package/dist/templates/support-line/tools/list_topics.ts +22 -0
  191. package/dist/templates/support-line/tools/log_ticket.ts +30 -0
  192. package/dist/templates/transcription-workflow/agent.test.ts +563 -0
  193. package/dist/templates/transcription-workflow/agent.ts +92 -0
  194. package/dist/templates/transcription-workflow/client.tsx +234 -0
  195. package/dist/templates/transcription-workflow/workflows/transcribe.ts +416 -0
  196. package/dist/templates/transcription-workflow/workflows/wav.ts +314 -0
  197. package/dist/templates/travel-concierge/agent.test.ts +338 -0
  198. package/dist/templates/travel-concierge/agent.ts +29 -0
  199. package/dist/templates/travel-concierge/client.tsx +161 -0
  200. package/dist/templates/travel-concierge/routing.ts +138 -0
  201. package/dist/templates/travel-concierge/shared.ts +547 -0
  202. package/dist/templates/travel-concierge/system-prompt.md +24 -0
  203. package/dist/templates/travel-concierge/tools/book_car_rental.ts +20 -0
  204. package/dist/templates/travel-concierge/tools/book_excursion.ts +18 -0
  205. package/dist/templates/travel-concierge/tools/book_hotel.ts +20 -0
  206. package/dist/templates/travel-concierge/tools/cancel_action.ts +7 -0
  207. package/dist/templates/travel-concierge/tools/cancel_ticket.ts +16 -0
  208. package/dist/templates/travel-concierge/tools/complete_or_escalate.ts +7 -0
  209. package/dist/templates/travel-concierge/tools/confirm_action.ts +7 -0
  210. package/dist/templates/travel-concierge/tools/lookup_booking.ts +35 -0
  211. package/dist/templates/travel-concierge/tools/search_car_rentals.ts +33 -0
  212. package/dist/templates/travel-concierge/tools/search_excursions.ts +37 -0
  213. package/dist/templates/travel-concierge/tools/search_flights.ts +43 -0
  214. package/dist/templates/travel-concierge/tools/search_hotels.ts +36 -0
  215. package/dist/templates/travel-concierge/tools/to_car_rental_assistant.ts +11 -0
  216. package/dist/templates/travel-concierge/tools/to_excursion_assistant.ts +11 -0
  217. package/dist/templates/travel-concierge/tools/to_flight_assistant.ts +11 -0
  218. package/dist/templates/travel-concierge/tools/to_hotel_assistant.ts +11 -0
  219. package/dist/templates/travel-concierge/tools/update_ticket.ts +22 -0
  220. package/dist/templates/web-researcher/agent.ts +0 -2
  221. package/dist/templates/web-researcher/system-prompt.md +10 -0
  222. package/dist/{test-2LWBcXvY.mjs → test-B6ZBxSpk.mjs} +2 -2
  223. package/dist/typecheck.mjs +17 -15
  224. package/dist/worker-bundler-CIdDhZ0c.mjs +398 -0
  225. package/dist/worker-bundler.d.ts +14 -0
  226. package/dist/worker-bundler.mjs +1 -108
  227. package/dist/workflow-B-O97AqI.mjs +125 -0
  228. package/dist/workflow-bundler.d.ts +133 -0
  229. package/dist/workflow.d.ts +67 -0
  230. package/package.json +13 -9
  231. package/dist/build-DQJ1ZSm9.mjs +0 -39
@@ -2,12 +2,12 @@ import { isToolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { creditRefund, REFUND_DELAY_NOTE, REFUND_IMMEDIATE_NOTE } from "../refund.ts";
4
4
  import { resolveOrder } from "../resolve.ts";
5
- import { authenticatedUser, retailSlot, retailTool, setFocus } from "../store.ts";
5
+ import { authenticatedUser, retailTool, setFocus } from "../store.ts";
6
6
 
7
7
  /** tau2 accepts exactly these two. Anything else is refused. */
8
8
  const CANCEL_REASONS = ["no longer needed", "ordered by mistake"] as const;
9
9
 
10
- export const cancelPendingOrder = retailTool({
10
+ export default retailTool({
11
11
  name: "cancel_pending_order",
12
12
  description:
13
13
  "Cancel a pending order. Only an order whose status is exactly 'pending' can be cancelled — " +
@@ -23,12 +23,7 @@ export const cancelPendingOrder = retailTool({
23
23
  .enum(CANCEL_REASONS)
24
24
  .describe("Either 'no longer needed' or 'ordered by mistake' — no other reason is accepted"),
25
25
  }),
26
- // `execute` before `summary`: TS infers the wrapper's generic `R` from
27
- // `execute`'s return type, and processes object literal properties in
28
- // source order — with `summary` first, `result` in its signature can't be
29
- // inferred and silently falls back to `unknown`.
30
- execute: (args, ctx) => {
31
- const state = retailSlot.get(ctx);
26
+ execute: (args, state) => {
32
27
  const user = authenticatedUser(state);
33
28
  if (isToolFailure(user)) return user;
34
29
 
@@ -79,5 +74,5 @@ export const cancelPendingOrder = retailTool({
79
74
  };
80
75
  },
81
76
  summary: (_args, result) =>
82
- "error" in result ? "cancel failed" : `cancelled ${result.order_id}`,
77
+ isToolFailure(result) ? "cancel failed" : `cancelled ${result.order_id}`,
83
78
  });
@@ -1,10 +1,10 @@
1
1
  import { isToolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { resolveOrder } from "../resolve.ts";
4
- import { authenticatedUser, retailSlot, retailTool, setFocus } from "../store.ts";
4
+ import { authenticatedUser, money, retailTool, setFocus } from "../store.ts";
5
5
  import { assertCanCoverDiff, planItemSwap } from "../swap.ts";
6
6
 
7
- export const exchangeDeliveredOrderItems = retailTool({
7
+ export default retailTool({
8
8
  name: "exchange_delivered_order_items",
9
9
  description:
10
10
  "Request an exchange of items in a delivered order for different options of the SAME products. " +
@@ -30,12 +30,7 @@ export const exchangeDeliveredOrderItems = retailTool({
30
30
  .max(80)
31
31
  .describe("Method to charge or refund the price difference"),
32
32
  }),
33
- // `execute` before `summary`: TS infers the wrapper's generic `R` from
34
- // `execute`'s return type, and processes object literal properties in
35
- // source order — with `summary` first, `result` in its signature can't be
36
- // inferred and silently falls back to `unknown`.
37
- execute: (args, ctx) => {
38
- const state = retailSlot.get(ctx);
33
+ execute: (args, state) => {
39
34
  const user = authenticatedUser(state);
40
35
  if (isToolFailure(user)) return user;
41
36
 
@@ -62,6 +57,18 @@ export const exchangeDeliveredOrderItems = retailTool({
62
57
  // No balance moves and no items change: this records a REQUEST. The money
63
58
  // and the item swap settle when the originals come back.
64
59
  order.status = "exchange requested";
60
+ // SORTED INDEPENDENTLY, verbatim from tau2 (`order.exchange_items =
61
+ // sorted(item_ids)` / `sorted(new_item_ids)`, the same shape
62
+ // `return_delivered_order_items` uses one list of) — kept because
63
+ // `seed.json` is tau2's data and these fields are what a tau2 task's
64
+ // expected end state is compared against. They are therefore two SETS of
65
+ // ids, not a pairing: sorting each list separately permutes the second
66
+ // against the first whenever the caller named more than one item.
67
+ //
68
+ // Which is why the ANSWER carries `exchanges` instead. `planItemSwap`
69
+ // priced this positionally, so returning the two sorted lists as if they
70
+ // lined up told the caller a pairing the quote was not for — the one thing
71
+ // this result must not do, since the model reads it back down a phone.
65
72
  order.exchange_items = [...args.item_ids].sort();
66
73
  order.exchange_new_items = [...args.new_item_ids].sort();
67
74
  order.exchange_payment_method_id = args.payment_method_id;
@@ -71,8 +78,12 @@ export const exchangeDeliveredOrderItems = retailTool({
71
78
  order_id: order.order_id,
72
79
  status: order.status,
73
80
  price_difference: plan.diff,
74
- exchange_items: order.exchange_items,
75
- exchange_new_items: order.exchange_new_items,
81
+ // The pairing AS PRICED, per line, in the order the caller gave it.
82
+ exchanges: plan.pairs.map((pair) => ({
83
+ item_id: pair.item.item_id,
84
+ new_item_id: pair.newVariant.item_id,
85
+ price_difference: money(pair.newVariant.price - pair.item.price),
86
+ })),
76
87
  message:
77
88
  plan.diff > 0
78
89
  ? `Exchange requested on ${order.order_id}. $${plan.diff.toFixed(2)} will be charged to ${args.payment_method_id}. An email with return instructions is on its way.`
@@ -80,5 +91,5 @@ export const exchangeDeliveredOrderItems = retailTool({
80
91
  };
81
92
  },
82
93
  summary: (_args, result) =>
83
- "error" in result ? "exchange failed" : `exchange requested on ${result.order_id}`,
94
+ isToolFailure(result) ? "exchange failed" : `exchange requested on ${result.order_id}`,
84
95
  });
@@ -1,8 +1,9 @@
1
+ import { isToolFailure } from "@alexkroman1/aai";
1
2
  import { z } from "zod";
2
3
  import { authenticateAs } from "../authenticate.ts";
3
- import { retailSlot, retailTool } from "../store.ts";
4
+ import { retailTool } from "../store.ts";
4
5
 
5
- export const findUserIdByEmail = retailTool({
6
+ export default retailTool({
6
7
  name: "find_user_id_by_email",
7
8
  description:
8
9
  "Find a customer's user id by their email address. This is how you authenticate the caller — " +
@@ -12,12 +13,7 @@ export const findUserIdByEmail = retailTool({
12
13
  email: z.string().max(200).describe("The customer's email, e.g. 'something@example.com'"),
13
14
  }),
14
15
  requiresAuth: false,
15
- // `execute` must come before `summary` in this object literal: TS infers the
16
- // wrapper's generic `R` from `execute`'s return type, and processes object
17
- // literal properties in source order — with `summary` first, `result` in its
18
- // signature can't be inferred and silently falls back to `unknown`.
19
- execute: (args, ctx) => {
20
- const state = retailSlot.get(ctx);
16
+ execute: (args, state) => {
21
17
  const target = args.email.trim().toLowerCase();
22
18
  const match = Object.values(state.store.users).find(
23
19
  (user) => user.email.toLowerCase() === target,
@@ -28,5 +24,5 @@ export const findUserIdByEmail = retailTool({
28
24
  return authenticateAs(state, match);
29
25
  },
30
26
  summary: (_args, result) =>
31
- "error" in result ? "lookup failed" : `identified ${result.user_id}`,
27
+ isToolFailure(result) ? "lookup failed" : `identified ${result.user_id}`,
32
28
  });
@@ -1,8 +1,9 @@
1
+ import { isToolFailure } from "@alexkroman1/aai";
1
2
  import { z } from "zod";
2
3
  import { authenticateAs } from "../authenticate.ts";
3
- import { retailSlot, retailTool } from "../store.ts";
4
+ import { retailTool } from "../store.ts";
4
5
 
5
- export const findUserIdByNameZip = retailTool({
6
+ export default retailTool({
6
7
  name: "find_user_id_by_name_zip",
7
8
  description:
8
9
  "Find a customer's user id by first name, last name and zip code. Use this only when the " +
@@ -13,10 +14,7 @@ export const findUserIdByNameZip = retailTool({
13
14
  zip: z.string().max(20).describe("Zip code, e.g. '12345'"),
14
15
  }),
15
16
  requiresAuth: false,
16
- // `execute` before `summary`: see find_user_id_by_email.ts for why the order
17
- // is load-bearing for the generic `result` type in `summary`.
18
- execute: (args, ctx) => {
19
- const state = retailSlot.get(ctx);
17
+ execute: (args, state) => {
20
18
  const first = args.first_name.trim().toLowerCase();
21
19
  const last = args.last_name.trim().toLowerCase();
22
20
  const zip = args.zip.replace(/\D/g, "");
@@ -34,5 +32,5 @@ export const findUserIdByNameZip = retailTool({
34
32
  return authenticateAs(state, match);
35
33
  },
36
34
  summary: (_args, result) =>
37
- "error" in result ? "lookup failed" : `identified ${result.user_id}`,
35
+ isToolFailure(result) ? "lookup failed" : `identified ${result.user_id}`,
38
36
  });
@@ -1,8 +1,8 @@
1
1
  import { isToolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
- import { findItem, retailSlot, retailTool } from "../store.ts";
3
+ import { findItem, retailTool } from "../store.ts";
4
4
 
5
- export const getItemDetails = retailTool({
5
+ export default retailTool({
6
6
  name: "get_item_details",
7
7
  description:
8
8
  "Get one specific item's options, price and availability. Takes an ITEM id, which is not the " +
@@ -11,10 +11,8 @@ export const getItemDetails = retailTool({
11
11
  item_id: z.string().max(60).describe("The item id, e.g. '1008292230'"),
12
12
  }),
13
13
  requiresAuth: false,
14
- // `execute` before `summary`: see find_user_id_by_email.ts for why the order
15
- // is load-bearing for the generic `result` type in `summary`.
16
- execute: (args, ctx) => {
17
- const found = findItem(retailSlot.get(ctx), args.item_id);
14
+ execute: (args, state) => {
15
+ const found = findItem(state, args.item_id);
18
16
  if (isToolFailure(found)) return found;
19
17
  return {
20
18
  item_id: found.variant.item_id,
@@ -26,5 +24,5 @@ export const getItemDetails = retailTool({
26
24
  };
27
25
  },
28
26
  summary: (_args, result) =>
29
- "error" in result ? "item read failed" : `read item ${result.item_id}`,
27
+ isToolFailure(result) ? "item read failed" : `read item ${result.item_id}`,
30
28
  });
@@ -1,9 +1,9 @@
1
1
  import { isToolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { resolveOrder } from "../resolve.ts";
4
- import { retailSlot, retailTool, setFocus } from "../store.ts";
4
+ import { retailTool, setFocus } from "../store.ts";
5
5
 
6
- export const getOrderDetails = retailTool({
6
+ export default retailTool({
7
7
  name: "get_order_details",
8
8
  description:
9
9
  "Get the status and full details of one of the authenticated customer's orders. Accepts the " +
@@ -15,10 +15,7 @@ export const getOrderDetails = retailTool({
15
15
  .max(120)
16
16
  .describe("Order id such as '#W0000000', or a spoken reference to one of their orders"),
17
17
  }),
18
- // `execute` before `summary`: see find_user_id_by_email.ts for why the order
19
- // is load-bearing for the generic `result` type in `summary`.
20
- execute: (args, ctx) => {
21
- const state = retailSlot.get(ctx);
18
+ execute: (args, state) => {
22
19
  const order = resolveOrder(state, args.order_id);
23
20
  if (isToolFailure(order)) return order;
24
21
  setFocus(state, { orderId: order.order_id });
@@ -38,5 +35,6 @@ export const getOrderDetails = retailTool({
38
35
  ...(order.cancel_reason ? { cancel_reason: order.cancel_reason } : {}),
39
36
  };
40
37
  },
41
- summary: (_args, result) => ("error" in result ? "order read failed" : `read ${result.order_id}`),
38
+ summary: (_args, result) =>
39
+ isToolFailure(result) ? "order read failed" : `read ${result.order_id}`,
42
40
  });
@@ -1,8 +1,8 @@
1
1
  import { isToolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
- import { findProduct, retailSlot, retailTool, setFocus } from "../store.ts";
3
+ import { findProduct, retailTool, setFocus } from "../store.ts";
4
4
 
5
- export const getProductDetails = retailTool({
5
+ export default retailTool({
6
6
  name: "get_product_details",
7
7
  description:
8
8
  "Get a product's variants — each with its item id, options, price and availability. Takes a " +
@@ -11,10 +11,7 @@ export const getProductDetails = retailTool({
11
11
  product_id: z.string().max(60).describe("The product id, e.g. '6086499569'"),
12
12
  }),
13
13
  requiresAuth: false,
14
- // `execute` before `summary`: see find_user_id_by_email.ts for why the order
15
- // is load-bearing for the generic `result` type in `summary`.
16
- execute: (args, ctx) => {
17
- const state = retailSlot.get(ctx);
14
+ execute: (args, state) => {
18
15
  const product = findProduct(state, args.product_id);
19
16
  if (isToolFailure(product)) return product;
20
17
  setFocus(state, { productId: product.product_id });
@@ -30,5 +27,5 @@ export const getProductDetails = retailTool({
30
27
  };
31
28
  },
32
29
  summary: (_args, result) =>
33
- "error" in result ? "product read failed" : `read product ${result.name}`,
30
+ isToolFailure(result) ? "product read failed" : `read product ${result.name}`,
34
31
  });
@@ -1,8 +1,8 @@
1
1
  import { isToolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
- import { authenticatedUser, retailSlot, retailTool } from "../store.ts";
3
+ import { authenticatedUser, retailTool } from "../store.ts";
4
4
 
5
- export const getUserDetails = retailTool({
5
+ export default retailTool({
6
6
  name: "get_user_details",
7
7
  description:
8
8
  "Get the authenticated customer's profile: name, email, default address, payment methods " +
@@ -10,10 +10,7 @@ export const getUserDetails = retailTool({
10
10
  inputSchema: z.object({
11
11
  user_id: z.string().max(100).describe("The user id, e.g. 'sara_doe_496'"),
12
12
  }),
13
- // `execute` before `summary`: see find_user_id_by_email.ts for why the order
14
- // is load-bearing for the generic `result` type in `summary`.
15
- execute: (args, ctx) => {
16
- const state = retailSlot.get(ctx);
13
+ execute: (args, state) => {
17
14
  const user = authenticatedUser(state);
18
15
  if (isToolFailure(user)) return user;
19
16
  if (user.user_id !== args.user_id) {
@@ -41,5 +38,5 @@ export const getUserDetails = retailTool({
41
38
  };
42
39
  },
43
40
  summary: (_args, result) =>
44
- "error" in result ? "profile read failed" : `read profile ${result.user_id}`,
41
+ isToolFailure(result) ? "profile read failed" : `read profile ${result.user_id}`,
45
42
  });
@@ -1,7 +1,8 @@
1
+ import { isToolFailure } from "@alexkroman1/aai";
1
2
  import { z } from "zod";
2
- import { retailSlot, retailTool } from "../store.ts";
3
+ import { retailTool } from "../store.ts";
3
4
 
4
- export const listAllProductTypes = retailTool({
5
+ export default retailTool({
5
6
  name: "list_all_product_types",
6
7
  description:
7
8
  "List every product type the store carries, as a name-to-product-id map. Each product type " +
@@ -10,15 +11,12 @@ export const listAllProductTypes = retailTool({
10
11
  // that is where the per-call UI-update invariant lives.
11
12
  inputSchema: z.object({}),
12
13
  requiresAuth: false,
13
- // `execute` before `summary`: see find_user_id_by_email.ts for why the order
14
- // is load-bearing for the generic `result` type in `summary`.
15
- execute: (_args, ctx) => {
16
- const state = retailSlot.get(ctx);
14
+ execute: (_args, state) => {
17
15
  const entries = Object.values(state.store.products)
18
16
  .map((product) => [product.name, product.product_id] as const)
19
17
  .sort(([a], [b]) => a.localeCompare(b));
20
18
  return { count: entries.length, products: Object.fromEntries(entries) };
21
19
  },
22
20
  summary: (_args, result) =>
23
- "error" in result ? "catalog read failed" : `listed ${result.count} product types`,
21
+ isToolFailure(result) ? "catalog read failed" : `listed ${result.count} product types`,
24
22
  });
@@ -2,9 +2,9 @@ import { isToolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { AddressFields, formatAddress, toAddress } from "../address.ts";
4
4
  import { resolveOrder } from "../resolve.ts";
5
- import { retailSlot, retailTool, setFocus } from "../store.ts";
5
+ import { retailTool, setFocus } from "../store.ts";
6
6
 
7
- export const modifyPendingOrderAddress = retailTool({
7
+ export default retailTool({
8
8
  name: "modify_pending_order_address",
9
9
  description:
10
10
  "Change the shipping address of a pending order. Read the new address back to the caller and " +
@@ -16,12 +16,7 @@ export const modifyPendingOrderAddress = retailTool({
16
16
  .describe("Order id such as '#W0000000', or a spoken reference to one of their orders"),
17
17
  ...AddressFields,
18
18
  }),
19
- // `execute` before `summary`: TS infers the wrapper's generic `R` from
20
- // `execute`'s return type, and processes object literal properties in
21
- // source order — with `summary` first, `result` in its signature can't be
22
- // inferred and silently falls back to `unknown`.
23
- execute: (args, ctx) => {
24
- const state = retailSlot.get(ctx);
19
+ execute: (args, state) => {
25
20
  const order = resolveOrder(state, args.order_id);
26
21
  if (isToolFailure(order)) return order;
27
22
  setFocus(state, { orderId: order.order_id });
@@ -43,5 +38,5 @@ export const modifyPendingOrderAddress = retailTool({
43
38
  };
44
39
  },
45
40
  summary: (_args, result) =>
46
- "error" in result ? "address change failed" : `re-addressed ${result.order_id}`,
41
+ isToolFailure(result) ? "address change failed" : `re-addressed ${result.order_id}`,
47
42
  });
@@ -1,17 +1,10 @@
1
1
  import { isToolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { resolveOrder } from "../resolve.ts";
4
- import {
5
- authenticatedUser,
6
- isGiftCard,
7
- money,
8
- retailSlot,
9
- retailTool,
10
- setFocus,
11
- } from "../store.ts";
4
+ import { authenticatedUser, isGiftCard, money, retailTool, setFocus } from "../store.ts";
12
5
  import { applySwap, assertCanCoverDiff, planItemSwap } from "../swap.ts";
13
6
 
14
- export const modifyPendingOrderItems = retailTool({
7
+ export default retailTool({
15
8
  name: "modify_pending_order_items",
16
9
  description:
17
10
  "Change items in a pending order to different options of the SAME products. This can be done " +
@@ -37,12 +30,7 @@ export const modifyPendingOrderItems = retailTool({
37
30
  .max(80)
38
31
  .describe("Method to charge or refund the price difference, e.g. 'gift_card_0000000'"),
39
32
  }),
40
- // `execute` before `summary`: TS infers the wrapper's generic `R` from
41
- // `execute`'s return type, and processes object literal properties in
42
- // source order — with `summary` first, `result` in its signature can't be
43
- // inferred and silently falls back to `unknown`.
44
- execute: (args, ctx) => {
45
- const state = retailSlot.get(ctx);
33
+ execute: (args, state) => {
46
34
  const user = authenticatedUser(state);
47
35
  if (isToolFailure(user)) return user;
48
36
 
@@ -96,7 +84,7 @@ export const modifyPendingOrderItems = retailTool({
96
84
  };
97
85
  },
98
86
  summary: (_args, result) =>
99
- "error" in result
87
+ isToolFailure(result)
100
88
  ? "item change failed"
101
89
  : `modified ${result.order_id} (${result.price_difference >= 0 ? "+" : ""}${result.price_difference})`,
102
90
  });
@@ -6,12 +6,11 @@ import {
6
6
  findPaymentMethod,
7
7
  isGiftCard,
8
8
  money,
9
- retailSlot,
10
9
  retailTool,
11
10
  setFocus,
12
11
  } from "../store.ts";
13
12
 
14
- export const modifyPendingOrderPayment = retailTool({
13
+ export default retailTool({
15
14
  name: "modify_pending_order_payment",
16
15
  description:
17
16
  "Change which payment method a pending order is charged to. The new method must be different " +
@@ -27,12 +26,7 @@ export const modifyPendingOrderPayment = retailTool({
27
26
  .max(80)
28
27
  .describe("The new payment method id, e.g. 'gift_card_0000000'"),
29
28
  }),
30
- // `execute` before `summary`: TS infers the wrapper's generic `R` from
31
- // `execute`'s return type, and processes object literal properties in
32
- // source order — with `summary` first, `result` in its signature can't be
33
- // inferred and silently falls back to `unknown`.
34
- execute: (args, ctx) => {
35
- const state = retailSlot.get(ctx);
29
+ execute: (args, state) => {
36
30
  const user = authenticatedUser(state);
37
31
  if (isToolFailure(user)) return user;
38
32
 
@@ -99,5 +93,5 @@ export const modifyPendingOrderPayment = retailTool({
99
93
  };
100
94
  },
101
95
  summary: (_args, result) =>
102
- "error" in result ? "payment change failed" : `re-paid ${result.order_id}`,
96
+ isToolFailure(result) ? "payment change failed" : `re-paid ${result.order_id}`,
103
97
  });
@@ -1,9 +1,9 @@
1
1
  import { isToolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { AddressFields, formatAddress, toAddress } from "../address.ts";
4
- import { authenticatedUser, retailSlot, retailTool } from "../store.ts";
4
+ import { authenticatedUser, retailTool } from "../store.ts";
5
5
 
6
- export const modifyUserAddress = retailTool({
6
+ export default retailTool({
7
7
  name: "modify_user_address",
8
8
  description:
9
9
  "Change the customer's default address, used for future orders. Read the new address back and " +
@@ -13,12 +13,7 @@ export const modifyUserAddress = retailTool({
13
13
  user_id: z.string().max(100).describe("The user id, e.g. 'sara_doe_496'"),
14
14
  ...AddressFields,
15
15
  }),
16
- // `execute` before `summary`: TS infers the wrapper's generic `R` from
17
- // `execute`'s return type, and processes object literal properties in
18
- // source order — with `summary` first, `result` in its signature can't be
19
- // inferred and silently falls back to `unknown`.
20
- execute: (args, ctx) => {
21
- const state = retailSlot.get(ctx);
16
+ execute: (args, state) => {
22
17
  const user = authenticatedUser(state);
23
18
  if (isToolFailure(user)) return user;
24
19
  if (user.user_id !== args.user_id) {
@@ -35,5 +30,5 @@ export const modifyUserAddress = retailTool({
35
30
  };
36
31
  },
37
32
  summary: (_args, result) =>
38
- "error" in result ? "profile address change failed" : `re-addressed ${result.user_id}`,
33
+ isToolFailure(result) ? "profile address change failed" : `re-addressed ${result.user_id}`,
39
34
  });
@@ -5,12 +5,11 @@ import {
5
5
  authenticatedUser,
6
6
  findPaymentMethod,
7
7
  isGiftCard,
8
- retailSlot,
9
8
  retailTool,
10
9
  setFocus,
11
10
  } from "../store.ts";
12
11
 
13
- export const returnDeliveredOrderItems = retailTool({
12
+ export default retailTool({
14
13
  name: "return_delivered_order_items",
15
14
  description:
16
15
  "Request a return of items from a delivered order. Only a 'delivered' order can be returned, " +
@@ -32,12 +31,7 @@ export const returnDeliveredOrderItems = retailTool({
32
31
  .max(80)
33
32
  .describe("Where the refund goes — the original method, or one of their gift cards"),
34
33
  }),
35
- // `execute` before `summary`: TS infers the wrapper's generic `R` from
36
- // `execute`'s return type, and processes object literal properties in
37
- // source order — with `summary` first, `result` in its signature can't be
38
- // inferred and silently falls back to `unknown`.
39
- execute: (args, ctx) => {
40
- const state = retailSlot.get(ctx);
34
+ execute: (args, state) => {
41
35
  const user = authenticatedUser(state);
42
36
  if (isToolFailure(user)) return user;
43
37
 
@@ -97,5 +91,5 @@ export const returnDeliveredOrderItems = retailTool({
97
91
  };
98
92
  },
99
93
  summary: (_args, result) =>
100
- "error" in result ? "return failed" : `return requested on ${result.order_id}`,
94
+ isToolFailure(result) ? "return failed" : `return requested on ${result.order_id}`,
101
95
  });
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { retailTool } from "../store.ts";
3
3
 
4
- export const transferToHumanAgents = retailTool({
4
+ export default retailTool({
5
5
  name: "transfer_to_human_agents",
6
6
  description:
7
7
  "Hand the caller to a human agent. Use this ONLY when the caller explicitly asks for a human, " +