@alexkroman1/aai-cli 5.13.2 → 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 (236) 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 +32 -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 +21 -30
  53. package/dist/templates/dispatch-center/agent.ts +4 -31
  54. package/dist/templates/dispatch-center/client.tsx +41 -28
  55. package/dist/templates/dispatch-center/shared.ts +73 -66
  56. package/dist/templates/dispatch-center/tools/incident_add_note.ts +13 -15
  57. package/dist/templates/dispatch-center/tools/incident_create.ts +42 -45
  58. package/dist/templates/dispatch-center/tools/incident_escalate.ts +60 -62
  59. package/dist/templates/dispatch-center/tools/incident_get.ts +10 -6
  60. package/dist/templates/dispatch-center/tools/incident_triage.ts +44 -46
  61. package/dist/templates/dispatch-center/tools/incident_update_status.ts +40 -42
  62. package/dist/templates/dispatch-center/tools/ops_dashboard.ts +3 -6
  63. package/dist/templates/dispatch-center/tools/ops_protocols.ts +1 -1
  64. package/dist/templates/dispatch-center/tools/ops_run_scenario.ts +21 -24
  65. package/dist/templates/dispatch-center/tools/resources_dispatch.ts +53 -55
  66. package/dist/templates/dispatch-center/tools/resources_get_available.ts +3 -5
  67. package/dist/templates/dispatch-center/tools/resources_update_status.ts +40 -43
  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 +32 -28
  82. package/dist/templates/infocom-adventure/shared.ts +36 -16
  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 +59 -58
  102. package/dist/templates/pizza-ordering/agent.ts +10 -159
  103. package/dist/templates/pizza-ordering/client.tsx +4 -4
  104. package/dist/templates/pizza-ordering/shared.ts +44 -27
  105. package/dist/templates/pizza-ordering/tools/add_pizza.ts +31 -0
  106. package/dist/templates/pizza-ordering/tools/place_order.ts +22 -0
  107. package/dist/templates/pizza-ordering/tools/remove_pizza.ts +22 -0
  108. package/dist/templates/pizza-ordering/tools/set_customer_name.ts +13 -0
  109. package/dist/templates/pizza-ordering/tools/update_pizza.ts +28 -0
  110. package/dist/templates/pizza-ordering/tools/view_order.ts +21 -0
  111. package/dist/templates/plan-and-execute/agent.test.ts +411 -0
  112. package/dist/templates/plan-and-execute/agent.ts +23 -0
  113. package/dist/templates/plan-and-execute/client.tsx +115 -0
  114. package/dist/templates/plan-and-execute/graph.ts +178 -0
  115. package/dist/templates/plan-and-execute/prompts.ts +110 -0
  116. package/dist/templates/plan-and-execute/shared.ts +161 -0
  117. package/dist/templates/plan-and-execute/system-prompt.md +18 -0
  118. package/dist/templates/plan-and-execute/tools/plan_status.ts +20 -0
  119. package/dist/templates/plan-and-execute/tools/revise_plan.ts +63 -0
  120. package/dist/templates/plan-and-execute/tools/start_plan.ts +51 -0
  121. package/dist/templates/plan-and-execute/tools/work_next_step.ts +101 -0
  122. package/dist/templates/recap-workflow/agent.test.ts +762 -0
  123. package/dist/templates/recap-workflow/agent.ts +95 -0
  124. package/dist/templates/recap-workflow/shared.ts +43 -0
  125. package/dist/templates/recap-workflow/tools/cancel_recap.ts +23 -0
  126. package/dist/templates/recap-workflow/tools/keep_transcript.ts +31 -0
  127. package/dist/templates/recap-workflow/tools/recap_progress.ts +27 -0
  128. package/dist/templates/recap-workflow/tools/recap_status.ts +46 -0
  129. package/dist/templates/recap-workflow/tools/request_recap.ts +43 -0
  130. package/dist/templates/recap-workflow/workflows/recap.ts +544 -0
  131. package/dist/templates/recap-workflow/workflows/tokens.ts +26 -0
  132. package/dist/templates/redline/agent.test.ts +222 -0
  133. package/dist/templates/redline/agent.ts +89 -0
  134. package/dist/templates/redline/client.tsx +184 -0
  135. package/dist/templates/redline/workflows/prompts.ts +68 -0
  136. package/dist/templates/redline/workflows/redline.ts +258 -0
  137. package/dist/templates/research-workflow/agent.test.ts +525 -0
  138. package/dist/templates/research-workflow/agent.ts +94 -0
  139. package/dist/templates/research-workflow/shared.ts +35 -0
  140. package/dist/templates/research-workflow/tools/file_it_now.ts +22 -0
  141. package/dist/templates/research-workflow/tools/request_research.ts +33 -0
  142. package/dist/templates/research-workflow/tools/research_progress.ts +26 -0
  143. package/dist/templates/research-workflow/tools/research_status.ts +40 -0
  144. package/dist/templates/research-workflow/workflows/prompts.ts +143 -0
  145. package/dist/templates/research-workflow/workflows/research.ts +558 -0
  146. package/dist/templates/retail/agent.test.ts +319 -256
  147. package/dist/templates/retail/agent.ts +6 -46
  148. package/dist/templates/retail/authenticate.ts +2 -2
  149. package/dist/templates/retail/client.tsx +45 -24
  150. package/dist/templates/retail/registry.test.ts +40 -25
  151. package/dist/templates/retail/resolve.test.ts +17 -16
  152. package/dist/templates/retail/resolve.ts +32 -67
  153. package/dist/templates/retail/shared.test.ts +21 -19
  154. package/dist/templates/retail/shared.ts +61 -23
  155. package/dist/templates/retail/store.test.ts +47 -52
  156. package/dist/templates/retail/store.ts +92 -79
  157. package/dist/templates/retail/swap.test.ts +20 -17
  158. package/dist/templates/retail/swap.ts +7 -14
  159. package/dist/templates/retail/tools/cancel_pending_order.ts +7 -11
  160. package/dist/templates/retail/tools/exchange_delivered_order_items.ts +26 -14
  161. package/dist/templates/retail/tools/find_user_id_by_email.ts +5 -9
  162. package/dist/templates/retail/tools/find_user_id_by_name_zip.ts +5 -7
  163. package/dist/templates/retail/tools/get_item_details.ts +7 -8
  164. package/dist/templates/retail/tools/get_order_details.ts +7 -8
  165. package/dist/templates/retail/tools/get_product_details.ts +6 -8
  166. package/dist/templates/retail/tools/get_user_details.ts +6 -8
  167. package/dist/templates/retail/tools/list_all_product_types.ts +5 -7
  168. package/dist/templates/retail/tools/modify_pending_order_address.ts +6 -10
  169. package/dist/templates/retail/tools/modify_pending_order_items.ts +8 -20
  170. package/dist/templates/retail/tools/modify_pending_order_payment.ts +7 -13
  171. package/dist/templates/retail/tools/modify_user_address.ts +6 -10
  172. package/dist/templates/retail/tools/return_delivered_order_items.ts +7 -13
  173. package/dist/templates/retail/tools/transfer_to_human_agents.ts +1 -1
  174. package/dist/templates/solo-rpg/agent.test.ts +169 -54
  175. package/dist/templates/solo-rpg/agent.ts +4 -22
  176. package/dist/templates/solo-rpg/client.tsx +19 -6
  177. package/dist/templates/solo-rpg/shared.ts +20 -20
  178. package/dist/templates/solo-rpg/tools/action_roll.ts +3 -5
  179. package/dist/templates/solo-rpg/tools/burn_momentum.ts +3 -5
  180. package/dist/templates/solo-rpg/tools/check_state.ts +7 -7
  181. package/dist/templates/solo-rpg/tools/load_game.ts +3 -3
  182. package/dist/templates/solo-rpg/tools/oracle.ts +19 -12
  183. package/dist/templates/solo-rpg/tools/save_game.ts +11 -8
  184. package/dist/templates/solo-rpg/tools/setup_character.ts +3 -3
  185. package/dist/templates/solo-rpg/tools/update_state.ts +13 -13
  186. package/dist/templates/support-line/agent.test.ts +343 -0
  187. package/dist/templates/support-line/agent.ts +27 -0
  188. package/dist/templates/support-line/client.tsx +122 -0
  189. package/dist/templates/support-line/graph.ts +224 -0
  190. package/dist/templates/support-line/knowledge.json +65 -0
  191. package/dist/templates/support-line/prompts.ts +95 -0
  192. package/dist/templates/support-line/shared.ts +240 -0
  193. package/dist/templates/support-line/system-prompt.md +17 -0
  194. package/dist/templates/support-line/tools/answer_question.ts +72 -0
  195. package/dist/templates/support-line/tools/list_topics.ts +22 -0
  196. package/dist/templates/support-line/tools/log_ticket.ts +30 -0
  197. package/dist/templates/transcription-workflow/agent.test.ts +563 -0
  198. package/dist/templates/transcription-workflow/agent.ts +92 -0
  199. package/dist/templates/transcription-workflow/client.tsx +234 -0
  200. package/dist/templates/transcription-workflow/workflows/transcribe.ts +416 -0
  201. package/dist/templates/transcription-workflow/workflows/wav.ts +314 -0
  202. package/dist/templates/travel-concierge/agent.test.ts +338 -0
  203. package/dist/templates/travel-concierge/agent.ts +29 -0
  204. package/dist/templates/travel-concierge/client.tsx +161 -0
  205. package/dist/templates/travel-concierge/routing.ts +138 -0
  206. package/dist/templates/travel-concierge/shared.ts +547 -0
  207. package/dist/templates/travel-concierge/system-prompt.md +24 -0
  208. package/dist/templates/travel-concierge/tools/book_car_rental.ts +20 -0
  209. package/dist/templates/travel-concierge/tools/book_excursion.ts +18 -0
  210. package/dist/templates/travel-concierge/tools/book_hotel.ts +20 -0
  211. package/dist/templates/travel-concierge/tools/cancel_action.ts +7 -0
  212. package/dist/templates/travel-concierge/tools/cancel_ticket.ts +16 -0
  213. package/dist/templates/travel-concierge/tools/complete_or_escalate.ts +7 -0
  214. package/dist/templates/travel-concierge/tools/confirm_action.ts +7 -0
  215. package/dist/templates/travel-concierge/tools/lookup_booking.ts +35 -0
  216. package/dist/templates/travel-concierge/tools/search_car_rentals.ts +33 -0
  217. package/dist/templates/travel-concierge/tools/search_excursions.ts +37 -0
  218. package/dist/templates/travel-concierge/tools/search_flights.ts +43 -0
  219. package/dist/templates/travel-concierge/tools/search_hotels.ts +36 -0
  220. package/dist/templates/travel-concierge/tools/to_car_rental_assistant.ts +11 -0
  221. package/dist/templates/travel-concierge/tools/to_excursion_assistant.ts +11 -0
  222. package/dist/templates/travel-concierge/tools/to_flight_assistant.ts +11 -0
  223. package/dist/templates/travel-concierge/tools/to_hotel_assistant.ts +11 -0
  224. package/dist/templates/travel-concierge/tools/update_ticket.ts +22 -0
  225. package/dist/templates/web-researcher/agent.ts +0 -2
  226. package/dist/templates/web-researcher/system-prompt.md +10 -0
  227. package/dist/{test-2LWBcXvY.mjs → test-B6ZBxSpk.mjs} +2 -2
  228. package/dist/typecheck.mjs +17 -15
  229. package/dist/worker-bundler-CIdDhZ0c.mjs +398 -0
  230. package/dist/worker-bundler.d.ts +14 -0
  231. package/dist/worker-bundler.mjs +1 -108
  232. package/dist/workflow-B-O97AqI.mjs +125 -0
  233. package/dist/workflow-bundler.d.ts +133 -0
  234. package/dist/workflow.d.ts +67 -0
  235. package/package.json +13 -9
  236. package/dist/build-DQJ1ZSm9.mjs +0 -39
@@ -1,7 +1,8 @@
1
+ import { isToolFailure } from "@alexkroman1/aai";
1
2
  import { z } from "zod";
2
- import { findItem, getState, isError, retailTool } from "../store.ts";
3
+ import { findItem, retailTool } from "../store.ts";
3
4
 
4
- export const getItemDetails = retailTool({
5
+ export default retailTool({
5
6
  name: "get_item_details",
6
7
  description:
7
8
  "Get one specific item's options, price and availability. Takes an ITEM id, which is not the " +
@@ -10,11 +11,9 @@ export const getItemDetails = retailTool({
10
11
  item_id: z.string().max(60).describe("The item id, e.g. '1008292230'"),
11
12
  }),
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 found = findItem(getState(ctx), args.item_id);
17
- if (isError(found)) return found;
14
+ execute: (args, state) => {
15
+ const found = findItem(state, args.item_id);
16
+ if (isToolFailure(found)) return found;
18
17
  return {
19
18
  item_id: found.variant.item_id,
20
19
  product_id: found.product.product_id,
@@ -25,5 +24,5 @@ export const getItemDetails = retailTool({
25
24
  };
26
25
  },
27
26
  summary: (_args, result) =>
28
- "error" in result ? "item read failed" : `read item ${result.item_id}`,
27
+ isToolFailure(result) ? "item read failed" : `read item ${result.item_id}`,
29
28
  });
@@ -1,8 +1,9 @@
1
+ import { isToolFailure } from "@alexkroman1/aai";
1
2
  import { z } from "zod";
2
3
  import { resolveOrder } from "../resolve.ts";
3
- import { getState, isError, retailTool, setFocus } from "../store.ts";
4
+ import { retailTool, setFocus } from "../store.ts";
4
5
 
5
- export const getOrderDetails = retailTool({
6
+ export default retailTool({
6
7
  name: "get_order_details",
7
8
  description:
8
9
  "Get the status and full details of one of the authenticated customer's orders. Accepts the " +
@@ -14,12 +15,9 @@ export const getOrderDetails = retailTool({
14
15
  .max(120)
15
16
  .describe("Order id such as '#W0000000', or a spoken reference to one of their orders"),
16
17
  }),
17
- // `execute` before `summary`: see find_user_id_by_email.ts for why the order
18
- // is load-bearing for the generic `result` type in `summary`.
19
- execute: (args, ctx) => {
20
- const state = getState(ctx);
18
+ execute: (args, state) => {
21
19
  const order = resolveOrder(state, args.order_id);
22
- if (isError(order)) return order;
20
+ if (isToolFailure(order)) return order;
23
21
  setFocus(state, { orderId: order.order_id });
24
22
  return {
25
23
  order_id: order.order_id,
@@ -37,5 +35,6 @@ export const getOrderDetails = retailTool({
37
35
  ...(order.cancel_reason ? { cancel_reason: order.cancel_reason } : {}),
38
36
  };
39
37
  },
40
- 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}`,
41
40
  });
@@ -1,7 +1,8 @@
1
+ import { isToolFailure } from "@alexkroman1/aai";
1
2
  import { z } from "zod";
2
- import { findProduct, getState, isError, retailTool, setFocus } from "../store.ts";
3
+ import { findProduct, retailTool, setFocus } from "../store.ts";
3
4
 
4
- export const getProductDetails = retailTool({
5
+ export default retailTool({
5
6
  name: "get_product_details",
6
7
  description:
7
8
  "Get a product's variants — each with its item id, options, price and availability. Takes a " +
@@ -10,12 +11,9 @@ export const getProductDetails = retailTool({
10
11
  product_id: z.string().max(60).describe("The product id, e.g. '6086499569'"),
11
12
  }),
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 = getState(ctx);
14
+ execute: (args, state) => {
17
15
  const product = findProduct(state, args.product_id);
18
- if (isError(product)) return product;
16
+ if (isToolFailure(product)) return product;
19
17
  setFocus(state, { productId: product.product_id });
20
18
  return {
21
19
  name: product.name,
@@ -29,5 +27,5 @@ export const getProductDetails = retailTool({
29
27
  };
30
28
  },
31
29
  summary: (_args, result) =>
32
- "error" in result ? "product read failed" : `read product ${result.name}`,
30
+ isToolFailure(result) ? "product read failed" : `read product ${result.name}`,
33
31
  });
@@ -1,7 +1,8 @@
1
+ import { isToolFailure } from "@alexkroman1/aai";
1
2
  import { z } from "zod";
2
- import { authenticatedUser, getState, isError, retailTool } from "../store.ts";
3
+ import { authenticatedUser, retailTool } from "../store.ts";
3
4
 
4
- export const getUserDetails = retailTool({
5
+ export default retailTool({
5
6
  name: "get_user_details",
6
7
  description:
7
8
  "Get the authenticated customer's profile: name, email, default address, payment methods " +
@@ -9,12 +10,9 @@ export const getUserDetails = retailTool({
9
10
  inputSchema: z.object({
10
11
  user_id: z.string().max(100).describe("The user id, e.g. 'sara_doe_496'"),
11
12
  }),
12
- // `execute` before `summary`: see find_user_id_by_email.ts for why the order
13
- // is load-bearing for the generic `result` type in `summary`.
14
- execute: (args, ctx) => {
15
- const state = getState(ctx);
13
+ execute: (args, state) => {
16
14
  const user = authenticatedUser(state);
17
- if (isError(user)) return user;
15
+ if (isToolFailure(user)) return user;
18
16
  if (user.user_id !== args.user_id) {
19
17
  return {
20
18
  error: `${args.user_id} is not the customer on this call. You can help only one customer per conversation.`,
@@ -40,5 +38,5 @@ export const getUserDetails = retailTool({
40
38
  };
41
39
  },
42
40
  summary: (_args, result) =>
43
- "error" in result ? "profile read failed" : `read profile ${result.user_id}`,
41
+ isToolFailure(result) ? "profile read failed" : `read profile ${result.user_id}`,
44
42
  });
@@ -1,7 +1,8 @@
1
+ import { isToolFailure } from "@alexkroman1/aai";
1
2
  import { z } from "zod";
2
- import { getState, 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 = getState(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
  });
@@ -1,9 +1,10 @@
1
+ import { isToolFailure } from "@alexkroman1/aai";
1
2
  import { z } from "zod";
2
3
  import { AddressFields, formatAddress, toAddress } from "../address.ts";
3
4
  import { resolveOrder } from "../resolve.ts";
4
- import { getState, isError, retailTool, setFocus } from "../store.ts";
5
+ import { retailTool, setFocus } from "../store.ts";
5
6
 
6
- export const modifyPendingOrderAddress = retailTool({
7
+ export default retailTool({
7
8
  name: "modify_pending_order_address",
8
9
  description:
9
10
  "Change the shipping address of a pending order. Read the new address back to the caller and " +
@@ -15,14 +16,9 @@ export const modifyPendingOrderAddress = retailTool({
15
16
  .describe("Order id such as '#W0000000', or a spoken reference to one of their orders"),
16
17
  ...AddressFields,
17
18
  }),
18
- // `execute` before `summary`: TS infers the wrapper's generic `R` from
19
- // `execute`'s return type, and processes object literal properties in
20
- // source order — with `summary` first, `result` in its signature can't be
21
- // inferred and silently falls back to `unknown`.
22
- execute: (args, ctx) => {
23
- const state = getState(ctx);
19
+ execute: (args, state) => {
24
20
  const order = resolveOrder(state, args.order_id);
25
- if (isError(order)) return order;
21
+ if (isToolFailure(order)) return order;
26
22
  setFocus(state, { orderId: order.order_id });
27
23
 
28
24
  // Any pending variant is fine here — unlike cancel and modify-items, which
@@ -42,5 +38,5 @@ export const modifyPendingOrderAddress = retailTool({
42
38
  };
43
39
  },
44
40
  summary: (_args, result) =>
45
- "error" in result ? "address change failed" : `re-addressed ${result.order_id}`,
41
+ isToolFailure(result) ? "address change failed" : `re-addressed ${result.order_id}`,
46
42
  });
@@ -1,17 +1,10 @@
1
+ import { isToolFailure } from "@alexkroman1/aai";
1
2
  import { z } from "zod";
2
3
  import { resolveOrder } from "../resolve.ts";
3
- import {
4
- authenticatedUser,
5
- getState,
6
- isError,
7
- isGiftCard,
8
- money,
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,17 +30,12 @@ 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 = getState(ctx);
33
+ execute: (args, state) => {
46
34
  const user = authenticatedUser(state);
47
- if (isError(user)) return user;
35
+ if (isToolFailure(user)) return user;
48
36
 
49
37
  const order = resolveOrder(state, args.order_id);
50
- if (isError(order)) return order;
38
+ if (isToolFailure(order)) return order;
51
39
  setFocus(state, { orderId: order.order_id });
52
40
 
53
41
  // Exactly 'pending'. A 'pending (item modified)' order has already used its
@@ -61,7 +49,7 @@ export const modifyPendingOrderItems = retailTool({
61
49
  const plan = planItemSwap(state, order, args.item_ids, args.new_item_ids, {
62
50
  requireDifferent: true,
63
51
  });
64
- if (isError(plan)) return plan;
52
+ if (isToolFailure(plan)) return plan;
65
53
 
66
54
  const blocked = assertCanCoverDiff(user, args.payment_method_id, plan.diff);
67
55
  if (blocked) return blocked;
@@ -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
  });
@@ -1,17 +1,16 @@
1
+ import { isToolFailure } from "@alexkroman1/aai";
1
2
  import { z } from "zod";
2
3
  import { resolveOrder } from "../resolve.ts";
3
4
  import {
4
5
  authenticatedUser,
5
6
  findPaymentMethod,
6
- getState,
7
- isError,
8
7
  isGiftCard,
9
8
  money,
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,17 +26,12 @@ 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 = getState(ctx);
29
+ execute: (args, state) => {
36
30
  const user = authenticatedUser(state);
37
- if (isError(user)) return user;
31
+ if (isToolFailure(user)) return user;
38
32
 
39
33
  const order = resolveOrder(state, args.order_id);
40
- if (isError(order)) return order;
34
+ if (isToolFailure(order)) return order;
41
35
  setFocus(state, { orderId: order.order_id });
42
36
 
43
37
  if (!order.status.startsWith("pending")) {
@@ -47,7 +41,7 @@ export const modifyPendingOrderPayment = retailTool({
47
41
  }
48
42
 
49
43
  const newMethod = findPaymentMethod(user, args.payment_method_id);
50
- if (isError(newMethod)) return newMethod;
44
+ if (isToolFailure(newMethod)) return newMethod;
51
45
 
52
46
  const original = order.payment_history[0];
53
47
  if (order.payment_history.length !== 1 || original?.transaction_type !== "payment") {
@@ -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,8 +1,9 @@
1
+ import { isToolFailure } from "@alexkroman1/aai";
1
2
  import { z } from "zod";
2
3
  import { AddressFields, formatAddress, toAddress } from "../address.ts";
3
- import { authenticatedUser, getState, isError, retailTool } from "../store.ts";
4
+ import { authenticatedUser, retailTool } from "../store.ts";
4
5
 
5
- export const modifyUserAddress = retailTool({
6
+ export default retailTool({
6
7
  name: "modify_user_address",
7
8
  description:
8
9
  "Change the customer's default address, used for future orders. Read the new address back and " +
@@ -12,14 +13,9 @@ export const modifyUserAddress = retailTool({
12
13
  user_id: z.string().max(100).describe("The user id, e.g. 'sara_doe_496'"),
13
14
  ...AddressFields,
14
15
  }),
15
- // `execute` before `summary`: TS infers the wrapper's generic `R` from
16
- // `execute`'s return type, and processes object literal properties in
17
- // source order — with `summary` first, `result` in its signature can't be
18
- // inferred and silently falls back to `unknown`.
19
- execute: (args, ctx) => {
20
- const state = getState(ctx);
16
+ execute: (args, state) => {
21
17
  const user = authenticatedUser(state);
22
- if (isError(user)) return user;
18
+ if (isToolFailure(user)) return user;
23
19
  if (user.user_id !== args.user_id) {
24
20
  return {
25
21
  error: `${args.user_id} is not the customer on this call. You can help only one customer per conversation.`,
@@ -34,5 +30,5 @@ export const modifyUserAddress = retailTool({
34
30
  };
35
31
  },
36
32
  summary: (_args, result) =>
37
- "error" in result ? "profile address change failed" : `re-addressed ${result.user_id}`,
33
+ isToolFailure(result) ? "profile address change failed" : `re-addressed ${result.user_id}`,
38
34
  });
@@ -1,16 +1,15 @@
1
+ import { isToolFailure } from "@alexkroman1/aai";
1
2
  import { z } from "zod";
2
3
  import { resolveOrder } from "../resolve.ts";
3
4
  import {
4
5
  authenticatedUser,
5
6
  findPaymentMethod,
6
- getState,
7
- isError,
8
7
  isGiftCard,
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,17 +31,12 @@ 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 = getState(ctx);
34
+ execute: (args, state) => {
41
35
  const user = authenticatedUser(state);
42
- if (isError(user)) return user;
36
+ if (isToolFailure(user)) return user;
43
37
 
44
38
  const order = resolveOrder(state, args.order_id);
45
- if (isError(order)) return order;
39
+ if (isToolFailure(order)) return order;
46
40
  setFocus(state, { orderId: order.order_id });
47
41
 
48
42
  if (order.status !== "delivered") {
@@ -52,7 +46,7 @@ export const returnDeliveredOrderItems = retailTool({
52
46
  }
53
47
 
54
48
  const method = findPaymentMethod(user, args.payment_method_id);
55
- if (isError(method)) return method;
49
+ if (isToolFailure(method)) return method;
56
50
 
57
51
  const originalMethodId = order.payment_history[0]?.payment_method_id;
58
52
  if (!isGiftCard(method) && args.payment_method_id !== originalMethodId) {
@@ -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, " +