@alexkroman1/aai-cli 16.1.0 → 17.0.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 (183) hide show
  1. package/README.md +2 -1
  2. package/dist/{_build-target-ClEEuUuW.mjs → _build-target-C08aM-Es.mjs} +504 -43
  3. package/dist/_build-target.d.ts +98 -19
  4. package/dist/_deno-target.d.ts +15 -14
  5. package/dist/_dev-env.d.ts +19 -13
  6. package/dist/{_dev-server-D1wKiA0_.mjs → _dev-server-CLU9xjH5.mjs} +25 -17
  7. package/dist/_dev-server.d.ts +4 -3
  8. package/dist/_init.d.ts +39 -0
  9. package/dist/_modal-target.d.ts +11 -6
  10. package/dist/_preflight-CnW9QiE7.mjs +116 -0
  11. package/dist/_preflight.d.ts +110 -5
  12. package/dist/_target-bundle.d.ts +112 -0
  13. package/dist/_target-entry.d.ts +81 -0
  14. package/dist/{_templates-CuP74F8D.mjs → _templates-IMeKMVIj.mjs} +1 -1
  15. package/dist/{_vitest-runner-BiAMIir1.mjs → _vitest-runner-CZNGj0ZC.mjs} +21 -16
  16. package/dist/_vitest-runner.d.ts +35 -23
  17. package/dist/{build-O6BT51x_.mjs → build-DrQTSc2R.mjs} +128 -293
  18. package/dist/build.d.ts +34 -4
  19. package/dist/cli.mjs +20 -16
  20. package/dist/{deploy-lldQyJVj.mjs → deploy-B68-x7xM.mjs} +12 -4
  21. package/dist/deploy.d.ts +9 -0
  22. package/dist/{dev-Du8pCWFq.mjs → dev-ChsrNHpK.mjs} +1 -1
  23. package/dist/dev.d.ts +1 -1
  24. package/dist/{eval-Ducmkt1n.mjs → eval-DB07kTxO.mjs} +1 -1
  25. package/dist/init-W-4k-lCF.mjs +559 -0
  26. package/dist/init.d.ts +43 -3
  27. package/dist/scaffold/CLAUDE.md +51 -64
  28. package/dist/scaffold/package.json +6 -6
  29. package/dist/scaffold/vite.config.ts +29 -1
  30. package/dist/{studio-It7SRfUN.mjs → studio-DEAJGBXa.mjs} +19 -9
  31. package/dist/templates/applicant-screening-agent/agent.eval.test.ts +20 -6
  32. package/dist/templates/applicant-screening-agent/agent.ts +28 -0
  33. package/dist/templates/applicant-screening-agent/shared.ts +11 -11
  34. package/dist/templates/call-audit-workflow/agent.ts +2 -0
  35. package/dist/templates/code-interpreter-agent/agent.eval.test.ts +3 -2
  36. package/dist/templates/code-interpreter-agent/agent.ts +1 -0
  37. package/dist/templates/coding-agent/agent.eval.test.ts +136 -0
  38. package/dist/templates/coding-agent/agent.test.ts +109 -0
  39. package/dist/templates/coding-agent/agent.ts +45 -0
  40. package/dist/templates/coding-agent/chat.ts +63 -0
  41. package/dist/templates/coding-agent/shared.ts +46 -0
  42. package/dist/templates/coding-agent/system-prompt.md +32 -0
  43. package/dist/templates/coding-agent/tools/bash.ts +6 -0
  44. package/dist/templates/coding-agent/tools/delete_file.ts +6 -0
  45. package/dist/templates/coding-agent/tools/edit_file.ts +6 -0
  46. package/dist/templates/coding-agent/tools/glob.ts +6 -0
  47. package/dist/templates/coding-agent/tools/grep.ts +6 -0
  48. package/dist/templates/coding-agent/tools/list_files.ts +6 -0
  49. package/dist/templates/coding-agent/tools/read_file.ts +6 -0
  50. package/dist/templates/coding-agent/tools/todo_write.ts +6 -0
  51. package/dist/templates/coding-agent/tools/write_file.ts +6 -0
  52. package/dist/templates/custom-pipeline-agent/agent.ts +1 -0
  53. package/dist/templates/document-redline-workflow/agent.ts +2 -0
  54. package/dist/templates/emergency-dispatch-agent/agent.test.ts +103 -0
  55. package/dist/templates/emergency-dispatch-agent/agent.ts +15 -0
  56. package/dist/templates/emergency-dispatch-agent/guardrails.ts +105 -0
  57. package/dist/templates/emergency-dispatch-agent/system-prompt.md +1 -0
  58. package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +8 -1
  59. package/dist/templates/entertainment-picks-agent/agent.ts +1 -0
  60. package/dist/templates/entertainment-picks-agent/system-prompt.md +6 -0
  61. package/dist/templates/entertainment-picks-agent/tools/revisit.ts +7 -0
  62. package/dist/templates/executive-inbox-agent/agent.eval.test.ts +84 -23
  63. package/dist/templates/executive-inbox-agent/agent.ts +1 -0
  64. package/dist/templates/executive-inbox-agent/meeting.ts +1 -1
  65. package/dist/templates/executive-inbox-agent/prompts.ts +3 -1
  66. package/dist/templates/executive-inbox-agent/system-prompt.md +3 -3
  67. package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +3 -3
  68. package/dist/templates/executive-inbox-agent/tools/open_email.ts +8 -16
  69. package/dist/templates/hotel-reception-agent/agent.eval.test.ts +85 -21
  70. package/dist/templates/hotel-reception-agent/agent.test.ts +2 -1
  71. package/dist/templates/hotel-reception-agent/agent.ts +6 -3
  72. package/dist/templates/hotel-reception-agent/client.tsx +14 -2
  73. package/dist/templates/hotel-reception-agent/concierge.ts +2 -1
  74. package/dist/templates/hotel-reception-agent/desk-seams.test.ts +2 -1
  75. package/dist/templates/hotel-reception-agent/disputes.ts +9 -11
  76. package/dist/templates/hotel-reception-agent/events.ts +2 -1
  77. package/dist/templates/hotel-reception-agent/session.ts +56 -0
  78. package/dist/templates/hotel-reception-agent/shared.ts +20 -21
  79. package/dist/templates/hotel-reception-agent/system-prompt.md +1 -1
  80. package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +2 -1
  81. package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +2 -1
  82. package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +2 -1
  83. package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +2 -1
  84. package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +2 -1
  85. package/dist/templates/hotel-reception-agent/tools/check_restaurant_availability.ts +1 -1
  86. package/dist/templates/hotel-reception-agent/tools/check_room_availability.ts +1 -1
  87. package/dist/templates/hotel-reception-agent/tools/choose_room.ts +1 -1
  88. package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +2 -1
  89. package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +2 -1
  90. package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +2 -1
  91. package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +2 -1
  92. package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +2 -1
  93. package/dist/templates/hotel-reception-agent/tools/lookup_guest_history.ts +1 -1
  94. package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +2 -1
  95. package/dist/templates/hotel-reception-agent/tools/lookup_restaurant_reservation.ts +1 -1
  96. package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +1 -1
  97. package/dist/templates/hotel-reception-agent/tools/record_card.ts +1 -1
  98. package/dist/templates/hotel-reception-agent/tools/record_followup.ts +2 -1
  99. package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +2 -1
  100. package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +1 -1
  101. package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +1 -1
  102. package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +2 -1
  103. package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +2 -1
  104. package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +1 -1
  105. package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +2 -1
  106. package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +2 -1
  107. package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +2 -1
  108. package/dist/templates/hotel-reception-agent/tools/set_extras.ts +1 -1
  109. package/dist/templates/hotel-reception-agent/tools/set_stay.ts +2 -1
  110. package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +2 -1
  111. package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +2 -1
  112. package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +2 -1
  113. package/dist/templates/hotel-reception-agent/tools/transfer_call.ts +2 -1
  114. package/dist/templates/hotel-reception-agent/tools/update_card.ts +2 -1
  115. package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +2 -1
  116. package/dist/templates/link-digest-workflow/agent.eval.test.ts +16 -1
  117. package/dist/templates/link-digest-workflow/agent.ts +5 -0
  118. package/dist/templates/medication-safety-agent/agent.test.ts +54 -0
  119. package/dist/templates/medication-safety-agent/agent.ts +48 -1
  120. package/dist/templates/meeting-recap-agent/agent.test.ts +2 -2
  121. package/dist/templates/meeting-recap-agent/agent.ts +4 -0
  122. package/dist/templates/pizza-ordering-agent/agent.ts +3 -0
  123. package/dist/templates/podcast-digest-workflow/agent.ts +4 -0
  124. package/dist/templates/quickstart-agent/agent.eval.test.ts +39 -3
  125. package/dist/templates/quickstart-agent/agent.test.ts +22 -0
  126. package/dist/templates/quickstart-agent/agent.ts +18 -2
  127. package/dist/templates/quickstart-agent/system-prompt.md +8 -0
  128. package/dist/templates/quickstart-agent/tools/get_weather.ts +59 -0
  129. package/dist/templates/research-handoff-agent/agent.ts +4 -0
  130. package/dist/templates/research-planner-agent/agent.eval.test.ts +24 -2
  131. package/dist/templates/research-planner-agent/agent.ts +3 -0
  132. package/dist/templates/research-planner-agent/system-prompt.md +1 -1
  133. package/dist/templates/retail-orders-agent/agent.ts +32 -3
  134. package/dist/templates/retail-orders-agent/keyterms.ts +154 -0
  135. package/dist/templates/retail-orders-agent/resolve.ts +18 -3
  136. package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +37 -5
  137. package/dist/templates/roadside-assistance-agent/agent.test.ts +38 -6
  138. package/dist/templates/roadside-assistance-agent/agent.ts +4 -0
  139. package/dist/templates/roadside-assistance-agent/shared.ts +12 -0
  140. package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +14 -0
  141. package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +11 -0
  142. package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +17 -11
  143. package/dist/templates/roadside-assistance-agent/yard.test.ts +4 -0
  144. package/dist/templates/spoken-summary-workflow/agent.ts +4 -0
  145. package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +6 -0
  146. package/dist/templates/tabletop-rpg-agent/agent.test.ts +125 -1
  147. package/dist/templates/tabletop-rpg-agent/agent.ts +30 -1
  148. package/dist/templates/tabletop-rpg-agent/shared.ts +81 -0
  149. package/dist/templates/tabletop-rpg-agent/system-prompt.md +1 -1
  150. package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +16 -7
  151. package/dist/templates/technical-support-agent/agent.test.ts +3 -3
  152. package/dist/templates/technical-support-agent/agent.ts +5 -1
  153. package/dist/templates/technical-support-agent/knowledge.ts +165 -0
  154. package/dist/templates/technical-support-agent/nodes.ts +3 -2
  155. package/dist/templates/technical-support-agent/procedure.ts +4 -3
  156. package/dist/templates/technical-support-agent/shared.ts +10 -146
  157. package/dist/templates/technical-support-agent/tools/list_topics.ts +2 -1
  158. package/dist/templates/text-adventure-agent/agent.eval.test.ts +39 -6
  159. package/dist/templates/text-adventure-agent/agent.test.ts +79 -1
  160. package/dist/templates/text-adventure-agent/agent.ts +30 -1
  161. package/dist/templates/text-adventure-agent/shared.ts +37 -0
  162. package/dist/templates/text-adventure-agent/system-prompt.md +9 -2
  163. package/dist/templates/topic-briefing-agent/agent.eval.test.ts +18 -4
  164. package/dist/templates/topic-briefing-agent/agent.test.ts +23 -11
  165. package/dist/templates/topic-briefing-agent/agent.ts +4 -1
  166. package/dist/templates/topic-briefing-agent/shared.ts +10 -10
  167. package/dist/templates/topic-briefing-agent/system-prompt.md +13 -8
  168. package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +43 -5
  169. package/dist/templates/transcription-workflow/agent.ts +3 -0
  170. package/dist/templates/travel-concierge-agent/agent.ts +4 -0
  171. package/dist/templates/web-research-agent/agent.eval.test.ts +31 -5
  172. package/dist/templates/web-research-agent/agent.test.ts +16 -0
  173. package/dist/templates/web-research-agent/agent.ts +30 -0
  174. package/dist/templates/web-research-agent/system-prompt.md +8 -2
  175. package/dist/templates/word-game-agent/agent.eval.test.ts +79 -18
  176. package/dist/templates/word-game-agent/agent.ts +20 -0
  177. package/dist/test-CjKPQ9_B.mjs +102 -0
  178. package/dist/test.d.ts +37 -12
  179. package/package.json +5 -5
  180. package/dist/_init-Bp1CjRrU.mjs +0 -199
  181. package/dist/_preflight-CcAR577V.mjs +0 -46
  182. package/dist/init-CY4NAXAA.mjs +0 -183
  183. package/dist/test-PHHv0Vj6.mjs +0 -83
@@ -37,7 +37,8 @@ import {
37
37
  resolveRoomConflict,
38
38
  } from "./hotel.ts";
39
39
  import { PRICING, type Ticket } from "./records.ts";
40
- import { hotelSlot, requireVerified } from "./shared.ts";
40
+ import { hotelSlot } from "./session.ts";
41
+ import { requireVerified } from "./shared.ts";
41
42
  import type recordCard from "./tools/record_card.ts";
42
43
 
43
44
  const run = toolRunner(agentDef);
@@ -38,21 +38,19 @@ import {
38
38
  * annotation is what types `candidate` in both members and what would catch a
39
39
  * `describe` that returned something other than a string.
40
40
  *
41
- * The scorer is this desk's own vocabulary, and it is deliberately not a fuzzy
42
- * distance: a whole word of the label, matched in the caller's words, is one
43
- * point — so "late checkout fee" finds `Late checkout` and "room" alone ties
44
- * `Room (3 nights)` with `Room service` and is refused as ambiguous, which is
45
- * the outcome a receptionist wants.
41
+ * The matching is `resolveOne`'s own `match` — a whole word of the label, said
42
+ * by the caller, is one point, and deliberately not a fuzzy distance: "late
43
+ * checkout fee" finds `Late checkout`, and "room" alone ties `Room (3 nights)`
44
+ * with `Room service` and is refused as ambiguous, which is the outcome a
45
+ * receptionist wants. The label's own split-and-filter used to be written here;
46
+ * it was one of four incompatible copies across the templates, and the one
47
+ * behaviour that changed in adopting the built-in is the right one — a word is
48
+ * matched as a WORD now, not as a substring of whatever the caller said.
46
49
  */
47
50
  export const LINE_ITEM_PICK: ResolveOneOptions<LineItem> = {
48
51
  label: "invoice line",
49
52
  describe: (item) => `${item.label} (${speakUsd(item.amount)})`,
50
- score: (item, text) =>
51
- item.label
52
- .toLowerCase()
53
- .split(/[^a-z0-9]+/)
54
- .filter((word) => word.length > 2)
55
- .filter((word) => text.includes(word)).length,
53
+ match: (item) => item.label,
56
54
  };
57
55
 
58
56
  export type DisputeAction =
@@ -28,7 +28,8 @@ import type { SessionEventHandler, SessionEventHandlers, SlotHolder } from "@ale
28
28
  import { bookingStatus } from "./booking.ts";
29
29
  import type { Ticket } from "./records.ts";
30
30
  import { digitsOf } from "./records.ts";
31
- import { addTicket, hotelSlot, note } from "./shared.ts";
31
+ import { hotelSlot } from "./session.ts";
32
+ import { addTicket, note } from "./shared.ts";
32
33
 
33
34
  /**
34
35
  * File the abandoned booking, if there was one, and return the ticket.
@@ -0,0 +1,56 @@
1
+ // Copyright 2026 the AAI authors. MIT license.
2
+ /**
3
+ * The session's hotel: the seeded factory, the slot it fills, and the
4
+ * projection both ends read.
5
+ *
6
+ * **This module exists to keep `seed.ts` out of the browser bundle**, and it is
7
+ * the same split `retail-orders-agent` makes for the same reason. A slot's
8
+ * factory is a live reference held by the slot object, so nothing can shake it
9
+ * out: any module that reaches `hotelSlot` reaches {@link createHotelState},
10
+ * which reaches `seedHotel`, which is 18.5 KB of seeded bookings on top of
11
+ * `records.ts`. While all three lived in `shared.ts` — the module `client.tsx`
12
+ * imports for its view — every one of those bytes shipped to the page. Measured
13
+ * before this split: all 43 of `seed.ts`'s guest phone numbers were present in
14
+ * the built client bundle.
15
+ *
16
+ * So the rule this file enforces is a layering one: `shared.ts` holds the
17
+ * SHAPES and the pure {@link deskView}, both halves import it freely, and it
18
+ * reaches no seed. Everything that touches seeded data lives here, and the
19
+ * browser never imports this module.
20
+ */
21
+
22
+ import { sessionSlot } from "@alexkroman1/aai";
23
+ import { TODAY } from "./records.ts";
24
+ import { seedHotel } from "./seed.ts";
25
+ import { deskView, emptyHotelState, type HotelState } from "./shared.ts";
26
+
27
+ /**
28
+ * A pristine hotel per session, seeded around {@link TODAY}.
29
+ *
30
+ * Built on top of `emptyHotelState()` so the SHAPE is declared once, in
31
+ * `shared.ts`, where the browser's pre-first-call fallback can reach it without
32
+ * reaching the seed.
33
+ */
34
+ export function createHotelState(): HotelState {
35
+ return { ...emptyHotelState(), ...seedHotel(TODAY) };
36
+ }
37
+
38
+ /**
39
+ * The session's hotel, as one typed slot.
40
+ *
41
+ * No `after` hook: nothing stored here is derived from anything else stored
42
+ * here. An invoice is written beside its booking by the one function that
43
+ * prices a stay, and a refund decrements the invoice where the dispute is filed.
44
+ * The call log is the one append-only list, and its bound is declared on the
45
+ * slot so it holds whatever path writes it.
46
+ */
47
+ export const hotelSlot = sessionSlot("hotel", createHotelState, { caps: { log: 40 } });
48
+
49
+ /**
50
+ * The projection `syncState` pushes.
51
+ *
52
+ * `client.tsx` deliberately does NOT import this — see the note there. It
53
+ * derives its own empty frame from `deskView` instead, because taking the
54
+ * projection would take the slot, and the slot takes the seed.
55
+ */
56
+ export const deskProjection = hotelSlot.projection(deskView);
@@ -13,7 +13,7 @@
13
13
  *
14
14
  * | hotel_receptionist | here |
15
15
  * | --- | --- |
16
- * | `HotelDB` over apsw/SQLite, seeded by `fake_data/seed.py` | {@link HotelState}, one `sessionSlot` seeded from `seed.ts` per session |
16
+ * | `HotelDB` over apsw/SQLite, seeded by `fake_data/seed.py` | {@link HotelState}, one `sessionSlot` (in `session.ts`) seeded from `seed.ts` per session |
17
17
  * | `Userdata` (verified booking, turn counters, transferred_to) | the same fields on {@link HotelState} |
18
18
  * | `VerifyBookingTask` (last name + code, or + card last four; three strikes) | `tools/verify_booking.ts` + {@link requireVerified}, checked by every booking tool |
19
19
  * | `BookRoomTask` + `ModifyBookingTask` (one `AgentTask` each, `_step()` derived from captured values) | ONE `booking` dialog in `desk.ts`, `nextStep` in `booking.ts`, a `mode` on the draft |
@@ -28,7 +28,7 @@
28
28
  * | `record_followup`, `take_guest_message`, `dispatch_emergency`, … (write-only tables) | {@link Ticket}s on the slot, rendered by `client.tsx` |
29
29
  * | a caller who rings off mid-booking (their `abandoned_booking` followup) | `events.ts`, on `agent({ events })` — the one write no tool can make |
30
30
  * | `HOTEL_TODAY=2026-06-08` (the simulation pin) | {@link TODAY}, fixed |
31
- * | `ui_view.py` (SQLite changesets streamed to the playground) | `deskProjection`, the slot pushed by `syncState` |
31
+ * | `ui_view.py` (SQLite changesets streamed to the playground) | `deskView`, pushed by `syncState` via `session.ts`'s `deskProjection` |
32
32
  *
33
33
  * **The LLM never owns a money value**, which is their README's first
34
34
  * sentence and this port's too: every total comes out of {@link computeInvoice},
@@ -52,7 +52,7 @@
52
52
  */
53
53
 
54
54
  import type { DeepReadonly, Message, ToolFailure } from "@alexkroman1/aai";
55
- import { sessionSlot, toolFailure } from "@alexkroman1/aai";
55
+ import { toolFailure } from "@alexkroman1/aai";
56
56
  import {
57
57
  type Dispute,
58
58
  type GuestHistory,
@@ -73,7 +73,6 @@ import {
73
73
  type TransferDestination,
74
74
  usd,
75
75
  } from "./records.ts";
76
- import { seedHotel } from "./seed.ts";
77
76
 
78
77
  // ─── The booking draft ───────────────────────────────────────────────────────
79
78
 
@@ -161,10 +160,24 @@ export interface HotelState {
161
160
  log: string[];
162
161
  }
163
162
 
164
- /** A pristine hotel per session, seeded around {@link TODAY}. */
165
- export function createHotelState(): HotelState {
163
+ /**
164
+ * The hotel's shape with nothing in it — no seed.
165
+ *
166
+ * `session.ts`'s {@link createHotelState} builds the real seeded state on top
167
+ * of this, so the shape is declared once. It lives HERE, apart from that,
168
+ * because `client.tsx` needs a `HotelState` for its pre-first-call fallback and
169
+ * must not import `session.ts`: that module pulls `seed.ts`, which would then
170
+ * land in the browser bundle.
171
+ */
172
+ export function emptyHotelState(): HotelState {
166
173
  return {
167
- ...seedHotel(TODAY),
174
+ rooms: [],
175
+ tables: [],
176
+ bookings: [],
177
+ reservations: [],
178
+ invoices: [],
179
+ disputes: [],
180
+ guestHistory: [],
168
181
  tickets: [],
169
182
  verifiedCode: null,
170
183
  verifyAttempts: 0,
@@ -176,17 +189,6 @@ export function createHotelState(): HotelState {
176
189
  };
177
190
  }
178
191
 
179
- /**
180
- * The session's hotel, as one typed slot.
181
- *
182
- * No `after` hook: nothing stored here is derived from anything else stored
183
- * here. An invoice is written beside its booking by the one function that
184
- * prices a stay, and a refund decrements the invoice where the dispute is filed.
185
- * The call log is the one append-only list, and its bound is declared on the
186
- * slot so it holds whatever path writes it.
187
- */
188
- export const hotelSlot = sessionSlot("hotel", createHotelState, { caps: { log: 40 } });
189
-
190
192
  /** The hotel as a READ hands it out: deep-frozen, and typed to say so. */
191
193
  export type FrozenHotelState = DeepReadonly<HotelState>;
192
194
 
@@ -349,6 +351,3 @@ function bookingCounts(state: FrozenHotelState): { inHouse: number; arrivingToda
349
351
  }
350
352
  return { inHouse, arrivingToday };
351
353
  }
352
-
353
- /** The projection BOTH ends use: `syncState` on the agent, `useAgentState` in the client. */
354
- export const deskProjection = hotelSlot.projection(deskView);
@@ -45,7 +45,7 @@ Don't narrate what you're about to do, what you just did, or any errors. A real
45
45
  - Browse without booking: check_room_availability, check_restaurant_availability, lookup_booking, lookup_restaurant_reservation. None of these change anything.
46
46
  - A returning guest ("I've stayed before"): lookup_guest_history, and offer to set up what they liked before. Only surface preferences the lookup returns.
47
47
  - Sold out: be honest, offer the nights either side, and offer the waitlist (add_to_waitlist) - nothing is held.
48
- - Caller wants a room: start_room_booking - the call IS your response. Don't ask for name, email, phone or card without the flow running; it is the only path that creates a booking. Inside the flow, follow the status each tool returns: set_stay, choose_room, set_extras, record_guest_details, record_card, the read-back, then confirm_booking once the caller agrees. Two rooms in one call is start_room_booking twice.
48
+ - Caller wants a room: start_room_booking - the call IS your response. Don't ask for name, email, phone or card without the flow running; it is the only path that creates a booking. Inside the flow, follow the status each tool returns, in this order and never ahead of it: set_stay, choose_room, set_extras, record_guest_details, record_card, the read-back, then confirm_booking once the caller agrees. Each of those steps takes the values the caller has ALREADY given - the dates and party size they opened with go straight into set_stay rather than being asked for again, which is what stops this feeling like a form. What you must not do is skip a step to use them: set_stay before start_room_booking has opened the flow is refused, and there is nothing to record into. Two rooms in one call is start_room_booking twice.
49
49
  - Changes to an existing booking (dates, room type, view, extras, party size): verify, then start_booking_modification. A guest whose room isn't the view or type they booked is a room MOVE through that flow, not a callback - only fall back to a manager followup if no matching room exists. Cancel via cancel_room_booking (abandon_booking first if a modification is open). Late arrival: flag_late_arrival.
50
50
  - Wake-up call: schedule_wakeup_call sets it - never a followup note. Do-not-disturb: set_do_not_disturb, and say an emergency still gets through.
51
51
  - Concierge: tours, spa, business centre, flowers - lookup_policy first to present the catalog, let the caller pick, then book_tour / book_spa_appointment / book_business_center / order_flowers. Flight reconfirmation: request_flight_reconfirmation - never claim the flight is confirmed. Ride to the airport: book_airport_car (departures only).
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { deskFlow, IN_BOOKING } from "../desk.ts";
3
- import { hotelSlot, note } from "../shared.ts";
3
+ import { hotelSlot } from "../session.ts";
4
+ import { note } from "../shared.ts";
4
5
 
5
6
  /**
6
7
  * Their `give_up`, on every task: end the flow without making the booking, or
@@ -1,7 +1,8 @@
1
1
  import { toolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { isoDate, MAX_PARTY_SIZE, speakCode, spokenDate } from "../records.ts";
4
- import { addTicket, hotelSlot } from "../shared.ts";
4
+ import { hotelSlot } from "../session.ts";
5
+ import { addTicket } from "../shared.ts";
5
6
 
6
7
  /** Their `add_to_waitlist`: for dates the hotel is sold out on. Holds nothing. */
7
8
  export default hotelSlot.updateTool({
@@ -11,7 +11,8 @@ import {
11
11
  spokenTime,
12
12
  TODAY,
13
13
  } from "../records.ts";
14
- import { addTicket, hotelSlot } from "../shared.ts";
14
+ import { hotelSlot } from "../session.ts";
15
+ import { addTicket } from "../shared.ts";
15
16
 
16
17
  /** Their `book_airport_car`: the hotel car, hotel-to-airport only, charged to the room. */
17
18
  export default hotelSlot.updateTool({
@@ -2,7 +2,8 @@ import { toolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { spokenDate, spokenTime } from "../records.ts";
4
4
  import { findReservation } from "../restaurant.ts";
5
- import { hotelSlot, note } from "../shared.ts";
5
+ import { hotelSlot } from "../session.ts";
6
+ import { note } from "../shared.ts";
6
7
 
7
8
  /** Their `cancel_restaurant_reservation`: last name + RES code, no card, no email. */
8
9
  export default hotelSlot.updateTool({
@@ -1,7 +1,8 @@
1
1
  import { isToolFailure, toolFailure } from "@alexkroman1/aai";
2
2
  import { cancelBooking } from "../hotel.ts";
3
3
  import { daysBetween, PRICING, speakUsd, TODAY } from "../records.ts";
4
- import { callerTurns, hotelSlot, requireVerified } from "../shared.ts";
4
+ import { hotelSlot } from "../session.ts";
5
+ import { callerTurns, requireVerified } from "../shared.ts";
5
6
 
6
7
  /**
7
8
  * Cancel the verified booking and say what comes back — their
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { isoDate, MAX_PARTY_SIZE, spokenDate, spokenTime } from "../records.ts";
3
3
  import { openDinnerSlots } from "../restaurant.ts";
4
- import { hotelSlot } from "../shared.ts";
4
+ import { hotelSlot } from "../session.ts";
5
5
 
6
6
  /** Their `check_restaurant_availability`: the open slots for a date and party. */
7
7
  export default hotelSlot.tool({
@@ -2,7 +2,7 @@ import { toolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { describeRoomOptions, listRoomOptions } from "../hotel.ts";
4
4
  import { isoDate, MAX_PARTY_SIZE, ROOM_TYPES, spokenDate } from "../records.ts";
5
- import { hotelSlot } from "../shared.ts";
5
+ import { hotelSlot } from "../session.ts";
6
6
 
7
7
  /** Their `check_room_availability`: read-only browsing, never a booking. */
8
8
  export default hotelSlot.tool({
@@ -4,7 +4,7 @@ import { bookingStatus, nextStep, requote } from "../booking.ts";
4
4
  import { AFTER_STAY, deskFlow } from "../desk.ts";
5
5
  import { describeRoomOptions, listRoomOptions } from "../hotel.ts";
6
6
  import { daysBetween, describeExtras, ROOM_TYPES, ROOM_VIEWS, speakUsd } from "../records.ts";
7
- import { hotelSlot } from "../shared.ts";
7
+ import { hotelSlot } from "../session.ts";
8
8
 
9
9
  /**
10
10
  * Record the room type (and view) the caller picked from the options `set_stay`
@@ -4,7 +4,8 @@ import { bookingStatus, changedFields, nextStep } from "../booking.ts";
4
4
  import { deskFlow } from "../desk.ts";
5
5
  import { bookRoom, updateBooking } from "../hotel.ts";
6
6
  import { speakCode, speakUsd } from "../records.ts";
7
- import { bookingByCode, callerTurns, hotelSlot, note } from "../shared.ts";
7
+ import { hotelSlot } from "../session.ts";
8
+ import { bookingByCode, callerTurns, note } from "../shared.ts";
8
9
 
9
10
  /**
10
11
  * Finalize the booking — their `confirm_booking` and `confirm_changes`, one
@@ -2,7 +2,8 @@ import { isToolFailure, toolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { requireRoom } from "../hotel.ts";
4
4
  import { EMERGENCY_KINDS, type EmergencyKind } from "../records.ts";
5
- import { addTicket, hotelSlot } from "../shared.ts";
5
+ import { hotelSlot } from "../session.ts";
6
+ import { addTicket } from "../shared.ts";
6
7
 
7
8
  /** What the caller is told to do THEMSELVES, per kind — never a substitute for sending hotel people. */
8
9
  const DIRECTION: Record<EmergencyKind, string> = {
@@ -8,7 +8,8 @@ import {
8
8
  } from "../disputes.ts";
9
9
  import { invoiceFor } from "../hotel.ts";
10
10
  import { DISPUTE_CATEGORIES, mintCode } from "../records.ts";
11
- import { hotelSlot, note, requireVerified, takenCodes } from "../shared.ts";
11
+ import { hotelSlot } from "../session.ts";
12
+ import { note, requireVerified, takenCodes } from "../shared.ts";
12
13
 
13
14
  /**
14
15
  * Handle a dispute on a line item — their `dispute_charge`.
@@ -1,6 +1,7 @@
1
1
  import { isToolFailure, toolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
- import { hotelSlot, note, requireVerified } from "../shared.ts";
3
+ import { hotelSlot } from "../session.ts";
4
+ import { note, requireVerified } from "../shared.ts";
4
5
 
5
6
  /** Their `flag_late_arrival`: a note on the booking so the desk holds the room. */
6
7
  export default hotelSlot.updateTool({
@@ -1,7 +1,8 @@
1
1
  import { isToolFailure } from "@alexkroman1/aai";
2
2
  import { roomConflict } from "../hotel.ts";
3
3
  import { daysBetween, speakUsd, spokenDate } from "../records.ts";
4
- import { hotelSlot, requireVerified } from "../shared.ts";
4
+ import { hotelSlot } from "../session.ts";
5
+ import { requireVerified } from "../shared.ts";
5
6
 
6
7
  /**
7
8
  * Read-only lookup of the verified booking — their `lookup_booking`, including
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { hotelSlot } from "../shared.ts";
2
+ import { hotelSlot } from "../session.ts";
3
3
 
4
4
  /** Their `lookup_guest_history`: a returning guest's remembered preferences, or none. */
5
5
  export default hotelSlot.tool({
@@ -1,7 +1,8 @@
1
1
  import { isToolFailure, toolFailure } from "@alexkroman1/aai";
2
2
  import { invoiceFor } from "../hotel.ts";
3
3
  import { speakUsd } from "../records.ts";
4
- import { hotelSlot, requireVerified } from "../shared.ts";
4
+ import { hotelSlot } from "../session.ts";
5
+ import { requireVerified } from "../shared.ts";
5
6
 
6
7
  /** Their `lookup_invoice`: the verified booking's line items, read back. */
7
8
  export default hotelSlot.tool({
@@ -2,7 +2,7 @@ import { toolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { spokenDate, spokenTime } from "../records.ts";
4
4
  import { findReservation } from "../restaurant.ts";
5
- import { hotelSlot } from "../shared.ts";
5
+ import { hotelSlot } from "../session.ts";
6
6
 
7
7
  /** Their `lookup_restaurant_reservation`: restaurants verify with last name + RES code. */
8
8
  export default hotelSlot.tool({
@@ -12,7 +12,7 @@ import {
12
12
  TODAY,
13
13
  } from "../records.ts";
14
14
  import { findReservation, modifyReservation, openDinnerSlots } from "../restaurant.ts";
15
- import { hotelSlot } from "../shared.ts";
15
+ import { hotelSlot } from "../session.ts";
16
16
 
17
17
  /**
18
18
  * Move a reservation — their `modify_restaurant_reservation`, one step, same
@@ -3,7 +3,7 @@ import { z } from "zod";
3
3
  import { bookingStatus, nextStep } from "../booking.ts";
4
4
  import { validateCard } from "../card.ts";
5
5
  import { AFTER_DETAILS, deskFlow } from "../desk.ts";
6
- import { hotelSlot } from "../shared.ts";
6
+ import { hotelSlot } from "../session.ts";
7
7
 
8
8
  /**
9
9
  * Take the card for a new booking — their `GetCardTask`, whose four recording
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { digitsOf, FOLLOWUP_KINDS, speakCode } from "../records.ts";
3
- import { addTicket, hotelSlot } from "../shared.ts";
3
+ import { hotelSlot } from "../session.ts";
4
+ import { addTicket } from "../shared.ts";
4
5
 
5
6
  /**
6
7
  * Capture something for a human to follow up on — their `record_followup`, the
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { digitsOf, isoDate, speakCode } from "../records.ts";
3
- import { addTicket, hotelSlot } from "../shared.ts";
3
+ import { hotelSlot } from "../session.ts";
4
+ import { addTicket } from "../shared.ts";
4
5
 
5
6
  /** Their `record_group_inquiry`: fifteen or more guests is a block, never a booking. */
6
7
  export default hotelSlot.updateTool({
@@ -3,7 +3,7 @@ import { z } from "zod";
3
3
  import { bookingStatus, nextStep } from "../booking.ts";
4
4
  import { AFTER_EXTRAS, deskFlow } from "../desk.ts";
5
5
  import { digitsOf } from "../records.ts";
6
- import { hotelSlot } from "../shared.ts";
6
+ import { hotelSlot } from "../session.ts";
7
7
 
8
8
  /**
9
9
  * Record the guest's name, email and phone — their three `beta.workflows`
@@ -2,7 +2,7 @@ import { isToolFailure, toolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { reinstateBooking } from "../hotel.ts";
4
4
  import { normalizeCode, speakCode, speakUsd, spokenDate, TODAY } from "../records.ts";
5
- import { hotelSlot } from "../shared.ts";
5
+ import { hotelSlot } from "../session.ts";
6
6
 
7
7
  /**
8
8
  * Bring back a cancelled booking — their `reinstate_booking`, the one flow that
@@ -2,7 +2,8 @@ import { isToolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { requireRoom } from "../hotel.ts";
4
4
  import { isoDate, speakCode } from "../records.ts";
5
- import { addTicket, hotelSlot } from "../shared.ts";
5
+ import { hotelSlot } from "../session.ts";
6
+ import { addTicket } from "../shared.ts";
6
7
 
7
8
  /** Their `request_flight_reconfirmation`: the concierge calls the carrier and rings the room. */
8
9
  export default hotelSlot.updateTool({
@@ -1,6 +1,7 @@
1
1
  import { isToolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
- import { addTicket, hotelSlot, requireVerified } from "../shared.ts";
3
+ import { hotelSlot } from "../session.ts";
4
+ import { addTicket, requireVerified } from "../shared.ts";
4
5
 
5
6
  /**
6
7
  * Re-send a document to the email ON FILE — their `resend_confirmation` over
@@ -11,7 +11,7 @@ import {
11
11
  TODAY,
12
12
  } from "../records.ts";
13
13
  import { openDinnerSlots, reserveTable } from "../restaurant.ts";
14
- import { hotelSlot } from "../shared.ts";
14
+ import { hotelSlot } from "../session.ts";
15
15
 
16
16
  /**
17
17
  * Book a table — their `BookRestaurantTask`, collapsed to one call.
@@ -1,7 +1,8 @@
1
1
  import { isToolFailure } from "@alexkroman1/aai";
2
2
  import { resolveRoomConflict } from "../hotel.ts";
3
3
  import { spokenDate } from "../records.ts";
4
- import { hotelSlot, requireVerified } from "../shared.ts";
4
+ import { hotelSlot } from "../session.ts";
5
+ import { requireVerified } from "../shared.ts";
5
6
 
6
7
  /**
7
8
  * Fix a double-booked room on the verified booking — their
@@ -2,7 +2,8 @@ import { isToolFailure, toolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { requireRoom } from "../hotel.ts";
4
4
  import { clockTime, isoDate, speakCode, spokenDate, spokenTime, TODAY } from "../records.ts";
5
- import { addTicket, hotelSlot } from "../shared.ts";
5
+ import { hotelSlot } from "../session.ts";
6
+ import { addTicket } from "../shared.ts";
6
7
 
7
8
  /** Their `schedule_wakeup_call`: it actually sets the call — never a followup note instead. */
8
9
  export default hotelSlot.updateTool({
@@ -2,7 +2,8 @@ import { isToolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { requireRoom } from "../hotel.ts";
4
4
  import { speakCode } from "../records.ts";
5
- import { addTicket, hotelSlot } from "../shared.ts";
5
+ import { hotelSlot } from "../session.ts";
6
+ import { addTicket } from "../shared.ts";
6
7
 
7
8
  /** Their `set_do_not_disturb`: a standing hold on a room's calls and messages. */
8
9
  export default hotelSlot.updateTool({
@@ -3,7 +3,7 @@ import { z } from "zod";
3
3
  import { bookingStatus, nextStep, requote } from "../booking.ts";
4
4
  import { AFTER_ROOM, deskFlow } from "../desk.ts";
5
5
  import { type RoomExtra, speakUsd } from "../records.ts";
6
- import { hotelSlot } from "../shared.ts";
6
+ import { hotelSlot } from "../session.ts";
7
7
 
8
8
  /**
9
9
  * Record the caller's answer on each extra — their `set_extras`.
@@ -4,7 +4,8 @@ import { bookingStatus, nextStep, requote } from "../booking.ts";
4
4
  import { deskFlow, IN_BOOKING } from "../desk.ts";
5
5
  import { describeRoomOptions, listRoomOptions } from "../hotel.ts";
6
6
  import { daysBetween, isoDate, MAX_PARTY_SIZE, spokenDate, TODAY } from "../records.ts";
7
- import { bookingByCode, hotelSlot } from "../shared.ts";
7
+ import { hotelSlot } from "../session.ts";
8
+ import { bookingByCode } from "../shared.ts";
8
9
 
9
10
  const MAX_NIGHTS = 30;
10
11
 
@@ -4,7 +4,8 @@ import { draftForModification } from "../booking.ts";
4
4
  import { deskFlow } from "../desk.ts";
5
5
  import { requireFloorPlanRoom } from "../hotel.ts";
6
6
  import { speakUsd, spokenDate, TODAY } from "../records.ts";
7
- import { hotelSlot, requireVerified } from "../shared.ts";
7
+ import { hotelSlot } from "../session.ts";
8
+ import { requireVerified } from "../shared.ts";
8
9
 
9
10
  /**
10
11
  * Open the modification flow on the verified booking — their
@@ -3,7 +3,8 @@ import { z } from "zod";
3
3
  import { bookingStatus, draftForNewBooking } from "../booking.ts";
4
4
  import { deskFlow } from "../desk.ts";
5
5
  import { speakCode } from "../records.ts";
6
- import { callerTurns, hotelSlot } from "../shared.ts";
6
+ import { hotelSlot } from "../session.ts";
7
+ import { callerTurns } from "../shared.ts";
7
8
 
8
9
  /**
9
10
  * Open the room-booking flow — their `start_room_booking`, which `await`ed a
@@ -2,7 +2,8 @@ import { toolFailure } from "@alexkroman1/aai";
2
2
  import { countWords } from "@alexkroman1/aai/utils";
3
3
  import { z } from "zod";
4
4
  import { digitsOf, speakCode, TODAY } from "../records.ts";
5
- import { addTicket, hotelSlot } from "../shared.ts";
5
+ import { hotelSlot } from "../session.ts";
6
+ import { addTicket } from "../shared.ts";
6
7
 
7
8
  /**
8
9
  * Take a message for someone who may be a guest — their `take_guest_message`.
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { TRANSFER_DESTINATIONS } from "../records.ts";
3
- import { addTicket, hotelSlot } from "../shared.ts";
3
+ import { hotelSlot } from "../session.ts";
4
+ import { addTicket } from "../shared.ts";
4
5
 
5
6
  /**
6
7
  * Transfer the caller to a DEPARTMENT — their `transfer_call`, a stub that
@@ -1,7 +1,8 @@
1
1
  import { isToolFailure, toolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { validateCard } from "../card.ts";
4
- import { hotelSlot, note, requireVerified } from "../shared.ts";
4
+ import { hotelSlot } from "../session.ts";
5
+ import { note, requireVerified } from "../shared.ts";
5
6
 
6
7
  /**
7
8
  * Replace the card on file — their `start_card_update`, which verified and then
@@ -1,7 +1,8 @@
1
1
  import { toolFailure } from "@alexkroman1/aai";
2
2
  import { z } from "zod";
3
3
  import { digitsOf, normalizeCode, speakCode, spokenDate } from "../records.ts";
4
- import { hotelSlot, note } from "../shared.ts";
4
+ import { hotelSlot } from "../session.ts";
5
+ import { note } from "../shared.ts";
5
6
 
6
7
  /** Failed lookups before a human takes over — their `_attempts >= 3`. */
7
8
  export const MAX_VERIFY_ATTEMPTS = 3;
@@ -135,7 +135,22 @@ describeWorkflowEval(agentDef, (test) => {
135
135
  const url = mode === "live" ? await servePage(ARTICLE_HTML) : "https://example.test/otters";
136
136
  if (mode === "stub") scriptBothLegs(ARTICLE_HTML);
137
137
 
138
- const run = await app.run(digest, { url });
138
+ // Run TWICE at most, and only for a reply that came back the wrong SHAPE.
139
+ //
140
+ // The digest step asks its call site for six attempts precisely because a
141
+ // model that answers with prose, or with JSON it truncated, may well obey
142
+ // the next time — `stepGenerateJsonOrFail` throws retryably for exactly
143
+ // that. This harness has no retry to give it (`maxAttempts: 1`, and the eval
144
+ // engine says so in as many words), so a live run here spends the step's
145
+ // whole reliability budget on one draw and a single malformed reply failed
146
+ // the case: "Expected JSON from the model, got: {"headline"…". That is the
147
+ // harness being thinner than production, not the flow being wrong, so the
148
+ // retry is restored HERE — narrowly, on the one error the deployed run
149
+ // would ride out, and never on a `FatalError`, which must still fail once.
150
+ let run = await app.run(digest, { url });
151
+ if (mode === "live" && /Expected JSON from the model/.test(run.error ?? "")) {
152
+ run = await app.run(digest, { url });
153
+ }
139
154
 
140
155
  // The error FIRST, so a failed run names its own reason instead of reporting
141
156
  // "expected 'failed' to be 'completed'".