@appsolutely-io/waypoint 0.0.0-stage → 0.1.1-next.1

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 (161) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +297 -2
  3. package/dist/block-reply-r8u-DNmZ.d.cts +181 -0
  4. package/dist/block-reply-z8El20nD.d.ts +181 -0
  5. package/dist/blocks-2ABWECKG.js +1 -0
  6. package/dist/blocks-7453YTYJ.cjs +1 -0
  7. package/dist/chunk-3KV7TDDR.cjs +3 -0
  8. package/dist/chunk-4BWV3SEL.cjs +1 -0
  9. package/dist/chunk-5Q3INHKA.js +1 -0
  10. package/dist/chunk-5TBO732O.js +1 -0
  11. package/dist/chunk-6OZSKCPT.cjs +1 -0
  12. package/dist/chunk-A3YOSFLE.cjs +1 -0
  13. package/dist/chunk-BRUQ75G3.cjs +1 -0
  14. package/dist/chunk-C3VS33WJ.js +1 -0
  15. package/dist/chunk-D2EGPBCX.cjs +1 -0
  16. package/dist/chunk-D4Q46KWA.js +1 -0
  17. package/dist/chunk-FBADWFRR.cjs +1 -0
  18. package/dist/chunk-FQSWQLRW.js +1 -0
  19. package/dist/chunk-GT6PI4CT.cjs +1 -0
  20. package/dist/chunk-II26UWZM.cjs +1 -0
  21. package/dist/chunk-IPI4O4LP.js +1 -0
  22. package/dist/chunk-JFMVVGGB.js +1 -0
  23. package/dist/chunk-K73VV7KA.js +1 -0
  24. package/dist/chunk-L4PFFRDE.js +3 -0
  25. package/dist/chunk-LLPGVQUT.cjs +1 -0
  26. package/dist/chunk-M63QOANE.js +1 -0
  27. package/dist/chunk-MEKDQDSV.js +1 -0
  28. package/dist/chunk-OEPKPDLD.js +1 -0
  29. package/dist/chunk-OWT55N6J.js +3 -0
  30. package/dist/chunk-PFR2J5BV.js +1 -0
  31. package/dist/chunk-Q7BULGQG.cjs +1 -0
  32. package/dist/chunk-QFBAOEPD.js +1 -0
  33. package/dist/chunk-QS3MKZOY.cjs +3 -0
  34. package/dist/chunk-RZ3AGK3U.cjs +1 -0
  35. package/dist/chunk-RZZDQWC2.js +1 -0
  36. package/dist/chunk-S73WZWDP.js +1 -0
  37. package/dist/chunk-T5XF2R74.js +1 -0
  38. package/dist/chunk-TCFCSGQ3.js +1 -0
  39. package/dist/chunk-TODYQ3SG.cjs +1 -0
  40. package/dist/chunk-TVSQHTK2.cjs +1 -0
  41. package/dist/chunk-VGGJGRNK.cjs +1 -0
  42. package/dist/chunk-XSHOLIC7.cjs +1 -0
  43. package/dist/chunk-XTKUDSDK.cjs +1 -0
  44. package/dist/chunk-XWDB2LS3.cjs +1 -0
  45. package/dist/cli.js +3 -0
  46. package/dist/confirmation-view-5BZ2PP7J.cjs +1 -0
  47. package/dist/confirmation-view-Z5JHY2F5.js +1 -0
  48. package/dist/conformance.cjs +1 -0
  49. package/dist/conformance.d.cts +10 -0
  50. package/dist/conformance.d.ts +10 -0
  51. package/dist/conformance.js +1 -0
  52. package/dist/flow-parser.cjs +1 -0
  53. package/dist/flow-parser.d.cts +3 -0
  54. package/dist/flow-parser.d.ts +3 -0
  55. package/dist/flow-parser.js +1 -0
  56. package/dist/flows-panel-2SCPYZ3X.js +1 -0
  57. package/dist/flows-panel-HQYJMOP4.cjs +1 -0
  58. package/dist/form-extras-RNMBCYV7.cjs +1 -0
  59. package/dist/form-extras-X3B3JCMH.js +1 -0
  60. package/dist/form-fill-C32AHxSr.d.cts +653 -0
  61. package/dist/form-fill-Dp3ut1_Y.d.ts +653 -0
  62. package/dist/form-session.cjs +1 -0
  63. package/dist/form-session.d.cts +7 -0
  64. package/dist/form-session.d.ts +7 -0
  65. package/dist/form-session.js +1 -0
  66. package/dist/frame-decoder.cjs +3 -0
  67. package/dist/frame-decoder.d.cts +5 -0
  68. package/dist/frame-decoder.d.ts +5 -0
  69. package/dist/frame-decoder.js +3 -0
  70. package/dist/generated-C9tbjwK0.d.cts +797 -0
  71. package/dist/generated-C9tbjwK0.d.ts +797 -0
  72. package/dist/hooks/index.cjs +1 -0
  73. package/dist/hooks/index.d.cts +48 -0
  74. package/dist/hooks/index.d.ts +48 -0
  75. package/dist/hooks/index.js +1 -0
  76. package/dist/i18n-WC9f-h_q.d.cts +151 -0
  77. package/dist/i18n-WC9f-h_q.d.ts +151 -0
  78. package/dist/index-B5idIFTx.d.cts +34 -0
  79. package/dist/index-DPzoKXCK.d.ts +34 -0
  80. package/dist/index.cjs +3 -0
  81. package/dist/index.d.cts +38 -0
  82. package/dist/index.d.ts +38 -0
  83. package/dist/index.js +3 -0
  84. package/dist/intent-BQPPows1.d.cts +154 -0
  85. package/dist/intent-BuvqEU3Q.d.ts +154 -0
  86. package/dist/intent.cjs +1 -0
  87. package/dist/intent.d.cts +2 -0
  88. package/dist/intent.d.ts +2 -0
  89. package/dist/intent.js +1 -0
  90. package/dist/markdown-5NUOCOGY.js +23 -0
  91. package/dist/markdown-CG7NXI7X.cjs +23 -0
  92. package/dist/message-actions-ORBVYGNE.cjs +1 -0
  93. package/dist/message-actions-XNBBFHGW.js +1 -0
  94. package/dist/messages/en/index.cjs +1 -0
  95. package/dist/messages/en/index.d.cts +3 -0
  96. package/dist/messages/en/index.d.ts +3 -0
  97. package/dist/messages/en/index.js +1 -0
  98. package/dist/messages/index.cjs +1 -0
  99. package/dist/messages/index.d.cts +14 -0
  100. package/dist/messages/index.d.ts +14 -0
  101. package/dist/messages/index.js +1 -0
  102. package/dist/messages/zh-Hans/index.cjs +1 -0
  103. package/dist/messages/zh-Hans/index.d.cts +3 -0
  104. package/dist/messages/zh-Hans/index.d.ts +3 -0
  105. package/dist/messages/zh-Hans/index.js +1 -0
  106. package/dist/on-demand.cjs +1 -0
  107. package/dist/on-demand.d.cts +56 -0
  108. package/dist/on-demand.d.ts +56 -0
  109. package/dist/on-demand.js +1 -0
  110. package/dist/problem-messages-THONMXFZ.cjs +1 -0
  111. package/dist/problem-messages-Z5QGO6RE.js +1 -0
  112. package/dist/react/index.cjs +1 -0
  113. package/dist/react/index.d.cts +421 -0
  114. package/dist/react/index.d.ts +421 -0
  115. package/dist/react/index.js +1 -0
  116. package/dist/reads-Bk84x_rt.d.ts +38 -0
  117. package/dist/reads-DlpCt8dE.d.cts +38 -0
  118. package/dist/recovery-panel-6EBUMANX.js +3 -0
  119. package/dist/recovery-panel-EQIIV7TT.cjs +3 -0
  120. package/dist/reply-controls-HUYHUO3W.js +1 -0
  121. package/dist/reply-controls-LGY2RKRJ.cjs +1 -0
  122. package/dist/run-XBABOEXK.js +1 -0
  123. package/dist/schema.json +2900 -0
  124. package/dist/skin-antd/index.cjs +1 -0
  125. package/dist/skin-antd/index.d.cts +30 -0
  126. package/dist/skin-antd/index.d.ts +30 -0
  127. package/dist/skin-antd/index.js +1 -0
  128. package/dist/skin-default/index.cjs +1 -0
  129. package/dist/skin-default/index.d.cts +42 -0
  130. package/dist/skin-default/index.d.ts +42 -0
  131. package/dist/skin-default/index.js +1 -0
  132. package/dist/step-name-BlgVvshf.d.ts +19 -0
  133. package/dist/step-name-CB3d3kkP.d.cts +19 -0
  134. package/dist/storage-commit.cjs +1 -0
  135. package/dist/storage-commit.d.cts +17 -0
  136. package/dist/storage-commit.d.ts +17 -0
  137. package/dist/storage-commit.js +1 -0
  138. package/dist/stream-reads.cjs +1 -0
  139. package/dist/stream-reads.d.cts +22 -0
  140. package/dist/stream-reads.d.ts +22 -0
  141. package/dist/stream-reads.js +1 -0
  142. package/dist/styles.css +811 -0
  143. package/dist/testing/index.cjs +1 -0
  144. package/dist/testing/index.d.cts +57 -0
  145. package/dist/testing/index.d.ts +57 -0
  146. package/dist/testing/index.js +1 -0
  147. package/docs/examples/message-versions.tsx +74 -0
  148. package/docs/form-fill-protocol.md +83 -0
  149. package/docs/message-versions.md +64 -0
  150. package/docs/plan-protocol.md +83 -0
  151. package/docs/reply-protocol.md +75 -0
  152. package/etc/hooks.api.md +2394 -0
  153. package/etc/index.api.md +2159 -0
  154. package/etc/messages-en.api.md +13 -0
  155. package/etc/messages-zh-Hans.api.md +13 -0
  156. package/etc/messages.api.md +186 -0
  157. package/etc/react.api.md +2977 -0
  158. package/etc/skin-antd.api.md +2998 -0
  159. package/etc/skin-default.api.md +61 -0
  160. package/etc/testing.api.md +3043 -0
  161. package/package.json +169 -4
@@ -0,0 +1,181 @@
1
+ import { W as WaypointClient, b as ClientSnapshot, x as KeepChangesReviewResult, L as ReplyOutcome } from './form-fill-Dp3ut1_Y.js';
2
+ import { a3 as Message, ad as PlanState, Z as IntentKind, ac as PlanRecord, ag as Reply, B as Block } from './generated-C9tbjwK0.js';
3
+ import { d as IntentOverlay, c as IntentNotice, I as IntentAlert } from './intent-BuvqEU3Q.js';
4
+ import { M as MessageKey } from './i18n-WC9f-h_q.js';
5
+
6
+ declare function useWaypointSnapshot(client?: WaypointClient): ClientSnapshot;
7
+ /**
8
+ * Part of the client's snapshot: the component renders again only when the
9
+ * selected value changes, by `isEqual` (`Object.is` unless given), not on
10
+ * every change to the snapshot, such as each delta of a reply.
11
+ */
12
+ declare function useWaypointSelector<T>(selector: (snapshot: ClientSnapshot) => T, isEqual?: (a: T, b: T) => boolean, client?: WaypointClient): T;
13
+ /**
14
+ * One message of the conversation shown: the component renders again only
15
+ * when that message changes (a delta into it, a new status), so a list can
16
+ * give each row its own subscription.
17
+ */
18
+ declare function useWaypointMessage(messageId: string, client?: WaypointClient): Message | undefined;
19
+
20
+ interface ViewMessage {
21
+ key: MessageKey;
22
+ values?: Record<string, number>;
23
+ }
24
+ type Tone = "neutral" | "progress" | "warning" | "success";
25
+ interface StepStatus {
26
+ stepId: string;
27
+ /** Its place in the plan, from 1; with `resource`, what `stepName` names it by. */
28
+ index: number;
29
+ resource?: string;
30
+ truth: "done" | "not-done" | "unknown";
31
+ textKey: MessageKey;
32
+ lateReport?: "contradicted";
33
+ }
34
+ type ActionId = "confirm" | "stop" | "decline" | "leave" | "keep" | "status" | "undoSelected" | "continue";
35
+ interface ActionEntry {
36
+ id: ActionId;
37
+ /** The label; it takes no values. */
38
+ labelKey: MessageKey;
39
+ /**
40
+ * A label that also says how many changes there are ("Apply 2 changes"),
41
+ * formatted with `labelValues`; Confirm has one. Without it, or without
42
+ * the values, `labelKey` alone names the action ("Apply these changes").
43
+ */
44
+ countedLabelKey?: MessageKey;
45
+ /** The values `countedLabelKey` takes: the number of changes. */
46
+ labelValues?: Record<string, number>;
47
+ available: boolean;
48
+ reasonKey?: MessageKey;
49
+ reasonValues?: Record<string, number>;
50
+ busy?: boolean;
51
+ schedule?: boolean;
52
+ }
53
+ interface PlanViewStatus {
54
+ dataStatus: string;
55
+ wireState: PlanState;
56
+ label: ViewMessage;
57
+ tone: Tone;
58
+ attention: boolean;
59
+ result?: "kept";
60
+ }
61
+ interface PlanViewAlert {
62
+ serial: number;
63
+ action?: "checkStatus" | "retry" | "signIn" | "hostGuidance" | "wait";
64
+ restoreFocus?: true;
65
+ message?: ViewMessage;
66
+ retryAvailable: boolean;
67
+ retryReasonKey?: MessageKey;
68
+ retryValues?: Record<string, number>;
69
+ }
70
+ interface PlanView {
71
+ planId: string;
72
+ /** Null for a plan without the recovery profile (legacy). */
73
+ status: PlanViewStatus | null;
74
+ intent: {
75
+ kind: IntentKind;
76
+ status: IntentOverlay["delivery"];
77
+ } | null;
78
+ steps: StepStatus[];
79
+ lines: ViewMessage[];
80
+ notice: ViewMessage[];
81
+ alert: PlanViewAlert | null;
82
+ actions: ActionEntry[];
83
+ pending: readonly IntentKind[];
84
+ conversationUnavailable: boolean;
85
+ /** A protected plan this client cannot control: shown, never acted on. */
86
+ readOnly?: true;
87
+ }
88
+ interface PlanViewInput {
89
+ plan: PlanRecord | null;
90
+ capabilities: readonly string[];
91
+ conversationUnavailable: boolean;
92
+ overlay: IntentOverlay | undefined;
93
+ notice: IntentNotice | null;
94
+ alert: IntentAlert | null;
95
+ keepReview: KeepChangesReviewResult;
96
+ pending: readonly IntentKind[];
97
+ now: number;
98
+ conversationId: string;
99
+ readOnly?: boolean;
100
+ }
101
+ /** The notice's messages, built only from what the host reported. */
102
+ declare function noticeMessages(notice: IntentNotice): ViewMessage[];
103
+ /** The view of the current plan, or null without one. */
104
+ declare function planView(input: PlanViewInput): PlanView | null;
105
+ interface KeepSheetView {
106
+ messages: ViewMessage[];
107
+ proceed: {
108
+ available: boolean;
109
+ reasonKey?: MessageKey;
110
+ };
111
+ }
112
+ /** What the Keep confirmation states for the review captured at opening. */
113
+ declare function keepSheet(review: {
114
+ review: "forward-only" | "end-retention";
115
+ remaining: number;
116
+ }, view: PlanView): KeepSheetView;
117
+ /** A message block as part data: its identity only, never its body. */
118
+ interface BlockSummary {
119
+ id: string;
120
+ type: string;
121
+ answered: boolean;
122
+ }
123
+
124
+ interface KeepSheet {
125
+ messages: ViewMessage[];
126
+ proceed: {
127
+ available: boolean;
128
+ reasonKey?: ViewMessage["key"];
129
+ };
130
+ onProceed(): void;
131
+ onCancel(): void;
132
+ }
133
+ /**
134
+ * The plan view of the current plan and its presses, for every renderer.
135
+ * Presses go through the client; this hook only tracks a press that has no
136
+ * overlay yet, so the view can show it as pending.
137
+ */
138
+ declare function usePlanView(client?: WaypointClient): {
139
+ view: PlanView | null;
140
+ press: (id: ActionId | "retry") => void;
141
+ sheet: KeepSheet | null;
142
+ };
143
+
144
+ /** An answer to a card, without the ids the hook fills in. */
145
+ type BlockAnswer = Pick<Reply, "kind"> & Record<string, unknown>;
146
+ interface BlockReply {
147
+ /**
148
+ * Ids of this conversation's cards with an answer in flight or accepted
149
+ * here, by card id alone; `isAnswered` with a message id tells cards of
150
+ * different messages apart.
151
+ */
152
+ answered: ReadonlySet<string>;
153
+ /**
154
+ * Whether a card takes no answer: the host marks it answered, or one is
155
+ * in flight or was accepted here. Pass the card's message id when card
156
+ * ids repeat.
157
+ */
158
+ isAnswered(block: Pick<Block, "id" | "answered">, messageId?: string): boolean;
159
+ /**
160
+ * Sends one answer to the card of `messageId` (when given), with a reply
161
+ * id built from the card and the answer (see `cardReplyId`). A press on a
162
+ * card that takes no answer here does nothing and resolves with nothing.
163
+ * Otherwise resolves with the outcome once the client has read the
164
+ * conversation after the answer; a card whose answer was refused or lost
165
+ * is then shown as the host reports it, and one whose answer was
166
+ * accepted stays answered.
167
+ */
168
+ reply(block: Pick<Block, "id">, answer: BlockAnswer, messageId?: string): Promise<ReplyOutcome | void>;
169
+ }
170
+ /**
171
+ * A card's reply id: the same for the same answer to the same card, in any
172
+ * page or tab, so a host deduplicates a resend, and another for another
173
+ * answer, which a host that already holds one refuses. It is opaque: its
174
+ * parts and a digest of the answer (whatever the order of its keys),
175
+ * escaped by code unit, and a digest of all of it past 128 characters.
176
+ */
177
+ declare function cardReplyId(conversationId: string, messageId: string, blockId: string, answer: BlockAnswer): string;
178
+ /** The card answer lock every renderer uses. */
179
+ declare function useBlockReply(client?: WaypointClient): BlockReply;
180
+
181
+ export { type ActionEntry as A, type BlockAnswer as B, type KeepSheet as K, type PlanView as P, type StepStatus as S, type Tone as T, type ViewMessage as V, type ActionId as a, type BlockReply as b, type KeepSheetView as c, type PlanViewAlert as d, type PlanViewInput as e, type PlanViewStatus as f, cardReplyId as g, usePlanView as h, useWaypointMessage as i, useWaypointSelector as j, keepSheet as k, useWaypointSnapshot as l, type BlockSummary as m, noticeMessages as n, planView as p, useBlockReply as u };
@@ -0,0 +1 @@
1
+ import{a as f}from"./chunk-MEKDQDSV.js";import{a as h}from"./chunk-D4Q46KWA.js";import{a as B,b as x}from"./chunk-PFR2J5BV.js";import{J as v,q as P,y as g}from"./chunk-IPI4O4LP.js";import{a as S}from"./chunk-FQSWQLRW.js";import{a as w}from"./chunk-C3VS33WJ.js";import"./chunk-OWT55N6J.js";import"./chunk-QFBAOEPD.js";import"./chunk-RZZDQWC2.js";import"./chunk-M63QOANE.js";import"./chunk-L4PFFRDE.js";import"./chunk-T5XF2R74.js";import"./chunk-K73VV7KA.js";import"./chunk-5TBO732O.js";import{useId as N,useState as q}from"react";import{Fragment as U,jsx as e,jsxs as u}from"react/jsx-runtime";P(B,x);var A=a=>Array.isArray(a)?a.length>0:String(a??"").trim()!=="",F={"compare-and-set":"chat.block.undoCompareAndSet","archive-created":"chat.block.undoArchiveCreated"},y=a=>a>=200&&a<300,I=(a,d)=>a("chat.block.status",{status:a(`chat.block.state.${d}`)});function V({record:a,slots:d,view:i,changesShown:k}){let{format:r,extraUrlSchemes:b,planLabels:c}=g();return a.plan.kind!=="immediate"?e("p",{children:I(r,a.state)}):e("ol",{children:a.plan.steps.map((t,m)=>{let o=a.outcomes.find(s=>s.stepId===t.id),l=t.undo.startsWith("inverse:")?"chat.block.undoInverse":F[t.undo];return e(v,{name:"planNode",slots:d,data:i?{view:i}:void 0,children:e("li",{children:u(v,{name:"stepRow",slots:d,data:{step:{id:t.id,operation:t.operation,resource:t.resource,view:t.view,tier:t.tier,undo:t.undo,stepUp:t.stepUp}},children:[e("strong",{children:w(r,c,{index:m+1,resource:t.resource})}),k?null:e("dl",{children:t.fields.map((s,n)=>u("div",{children:[e("dt",{children:c?.field?.(t.resource,s)||r("chat.fieldName",{index:n+1})}),u("dd",{children:[e(f,{value:t.before?.[s],t:r})," ",e("span",{"aria-hidden":"true",children:"\u2192"}),e("span",{className:"wp-sr-only",children:r("chat.changesTo")})," ",e(f,{value:t.after?.[s],t:r})]})]},s))}),u("ul",{className:"wp-step-facts",children:[e("li",{children:r(t.tier==="sensitive"?"chat.block.tierSensitive":"chat.block.tierLow")}),t.undo==="none"?e("li",{children:e("strong",{children:r("chat.irreversible")})}):l?e("li",{children:r(l)}):null,t.stepUp?e("li",{children:r("chat.verify")}):null,o&&!y(o.status)?e("li",{"data-tone":"danger",children:e("strong",{children:r("chat.block.status",{status:r("chat.block.outcomeFailed")})})}):e("li",{children:o?r("chat.block.status",{status:r("chat.block.outcomeDone")}):I(r,a.state)}),o?.reason&&!y(o.status)?e("li",{"data-tone":"danger",children:o.reason}):null,o?.retryable!==void 0&&!y(o.status)?e("li",{children:r(o.retryable?"chat.block.retryable":"chat.block.notRetryable")}):null,S(t.view,b)?e("li",{children:e("a",{href:t.view,children:r("chat.view")})}):null]})]})})},t.id)})})}var C=(a,d)=>a.id===d.blockId?a.body?.actions?.find(i=>"actionId"in d&&i.id===d.actionId)?.label:(a.body?.blocks??[]).map(i=>C(i,d)).find(Boolean);function J({block:a}){let{format:d}=g(),i=a.answer&&C(a,a.answer);return e("p",{children:i?d("chat.block.answeredWith",{answer:i}):d("chat.block.answered")})}function R({block:a,onReply:d,disabled:i}){let k=N(),{format:r,primitives:b}=g(),c=a.body,[t,m]=q(()=>a.type==="form"?Object.fromEntries((c?.fields??[]).filter(o=>typeof o.value=="string").map(o=>[o.name,o.value])):{});switch(a.type){case"form.fill":{let l=a.body?.values;return!l||typeof l!="object"||Array.isArray(l)||Object.values(l).some(s=>!s||typeof s!="object")?e("p",{children:a.fallback}):e("dl",{children:Object.entries(l).map(([s,n])=>u("div",{children:[e("dt",{children:typeof n.label=="string"?n.label:s}),u("dd",{children:[e("p",{children:typeof n.value=="string"?n.value:JSON.stringify(n.value)}),e("p",{children:r(n.validation?.status==="valid"?"form.valid":"form.invalid")}),n.validation?.messages?.map((p,M)=>e("p",{children:p},M)),n.validation?.guidance&&e("p",{children:n.validation.guidance})]})]},s))})}case"table":return e("div",{"data-scroll-region":"",tabIndex:0,role:"region","aria-label":r("chat.scrollRegion"),children:u("table",{children:[e("thead",{children:e("tr",{children:(c.columns??[]).map((o,l)=>e("th",{children:o},l))})}),e("tbody",{children:(c.rows??[]).map((o,l)=>e("tr",{children:o.map((s,n)=>e("td",{children:String(s)},n))},l))})]})});case"diff":return u("dl",{children:[e("dt",{children:r("chat.before")}),e("dd",{children:e(f,{value:c.before,t:r})}),e("dt",{children:r("chat.after")}),e("dd",{children:e(f,{value:c.after,t:r})})]});case"form":{let o=c.fields??[],l=o.some(n=>n.required&&!A(t[n.name])),s=()=>{!i&&!l&&d({kind:"form",blockId:a.id,values:t})};return u("form",{onSubmit:n=>{n.preventDefault(),s()},children:[o.map(n=>e(b.input,{label:n.required?r("chat.block.required",{label:n.label}):n.label,required:n.required,value:String(t[n.name]??""),disabled:i,onChange:p=>m({...t,[n.name]:p})},n.name)),e(h,{disabled:i,blocked:l,reason:r("chat.block.requiredMissing"),onPress:s})]})}case"choice":{let o=!A(t.answer),l=()=>{!i&&!o&&d({kind:"form",blockId:a.id,values:t})};return u("fieldset",{disabled:i,children:[c.mode==="text"?e(b.input,{label:a.fallback,value:String(t.answer??""),onChange:s=>m({answer:s})}):u(U,{children:[e("legend",{children:a.fallback}),e("div",{children:(c.options??[]).map(s=>u("label",{children:[e("input",{type:c.mode==="multi"?"checkbox":"radio",name:k,disabled:i,checked:c.mode==="multi"?(t.answer??[]).includes(s):t.answer===s,onChange:n=>m({answer:c.mode==="multi"?n.target.checked?[...t.answer??[],s]:(t.answer??[]).filter(p=>p!==s):s})}),s]},s))})]}),e(h,{disabled:i,blocked:o,reason:r("chat.block.answerMissing"),onPress:l})]})}case"plan":return e("p",{children:a.fallback});default:return e("p",{children:a.fallback})}}export{J as Answered,V as PlanSteps,R as default};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkXWDB2LS3cjs = require('./chunk-XWDB2LS3.cjs');var _chunkXTKUDSDKcjs = require('./chunk-XTKUDSDK.cjs');var _chunkVGGJGRNKcjs = require('./chunk-VGGJGRNK.cjs');var _chunkA3YOSFLEcjs = require('./chunk-A3YOSFLE.cjs');var _chunkFBADWFRRcjs = require('./chunk-FBADWFRR.cjs');var _chunkTODYQ3SGcjs = require('./chunk-TODYQ3SG.cjs');require('./chunk-QS3MKZOY.cjs');require('./chunk-RZ3AGK3U.cjs');require('./chunk-4BWV3SEL.cjs');require('./chunk-GT6PI4CT.cjs');require('./chunk-3KV7TDDR.cjs');require('./chunk-Q7BULGQG.cjs');require('./chunk-XSHOLIC7.cjs');require('./chunk-II26UWZM.cjs');var _react = require('react');var _jsxruntime = require('react/jsx-runtime');_chunkA3YOSFLEcjs.q.call(void 0, _chunkVGGJGRNKcjs.a,_chunkVGGJGRNKcjs.b);var A=a=>Array.isArray(a)?a.length>0:String(_nullishCoalesce(a, () => (""))).trim()!=="",F={"compare-and-set":"chat.block.undoCompareAndSet","archive-created":"chat.block.undoArchiveCreated"},y=a=>a>=200&&a<300,I=(a,d)=>a("chat.block.status",{status:a(`chat.block.state.${d}`)});function V({record:a,slots:d,view:i,changesShown:k}){let{format:r,extraUrlSchemes:b,planLabels:c}=_chunkA3YOSFLEcjs.y.call(void 0, );return a.plan.kind!=="immediate"?_jsxruntime.jsx.call(void 0, "p",{children:I(r,a.state)}):_jsxruntime.jsx.call(void 0, "ol",{children:a.plan.steps.map((t,m)=>{let o=a.outcomes.find(s=>s.stepId===t.id),l=t.undo.startsWith("inverse:")?"chat.block.undoInverse":F[t.undo];return _jsxruntime.jsx.call(void 0, _chunkA3YOSFLEcjs.J,{name:"planNode",slots:d,data:i?{view:i}:void 0,children:_jsxruntime.jsx.call(void 0, "li",{children:_jsxruntime.jsxs.call(void 0, _chunkA3YOSFLEcjs.J,{name:"stepRow",slots:d,data:{step:{id:t.id,operation:t.operation,resource:t.resource,view:t.view,tier:t.tier,undo:t.undo,stepUp:t.stepUp}},children:[_jsxruntime.jsx.call(void 0, "strong",{children:_chunkTODYQ3SGcjs.a.call(void 0, r,c,{index:m+1,resource:t.resource})}),k?null:_jsxruntime.jsx.call(void 0, "dl",{children:t.fields.map((s,n)=>_jsxruntime.jsxs.call(void 0, "div",{children:[_jsxruntime.jsx.call(void 0, "dt",{children:_optionalChain([c, 'optionalAccess', _ => _.field, 'optionalCall', _2 => _2(t.resource,s)])||r("chat.fieldName",{index:n+1})}),_jsxruntime.jsxs.call(void 0, "dd",{children:[_jsxruntime.jsx.call(void 0, _chunkXWDB2LS3cjs.a,{value:_optionalChain([t, 'access', _3 => _3.before, 'optionalAccess', _4 => _4[s]]),t:r})," ",_jsxruntime.jsx.call(void 0, "span",{"aria-hidden":"true",children:"\u2192"}),_jsxruntime.jsx.call(void 0, "span",{className:"wp-sr-only",children:r("chat.changesTo")})," ",_jsxruntime.jsx.call(void 0, _chunkXWDB2LS3cjs.a,{value:_optionalChain([t, 'access', _5 => _5.after, 'optionalAccess', _6 => _6[s]]),t:r})]})]},s))}),_jsxruntime.jsxs.call(void 0, "ul",{className:"wp-step-facts",children:[_jsxruntime.jsx.call(void 0, "li",{children:r(t.tier==="sensitive"?"chat.block.tierSensitive":"chat.block.tierLow")}),t.undo==="none"?_jsxruntime.jsx.call(void 0, "li",{children:_jsxruntime.jsx.call(void 0, "strong",{children:r("chat.irreversible")})}):l?_jsxruntime.jsx.call(void 0, "li",{children:r(l)}):null,t.stepUp?_jsxruntime.jsx.call(void 0, "li",{children:r("chat.verify")}):null,o&&!y(o.status)?_jsxruntime.jsx.call(void 0, "li",{"data-tone":"danger",children:_jsxruntime.jsx.call(void 0, "strong",{children:r("chat.block.status",{status:r("chat.block.outcomeFailed")})})}):_jsxruntime.jsx.call(void 0, "li",{children:o?r("chat.block.status",{status:r("chat.block.outcomeDone")}):I(r,a.state)}),_optionalChain([o, 'optionalAccess', _7 => _7.reason])&&!y(o.status)?_jsxruntime.jsx.call(void 0, "li",{"data-tone":"danger",children:o.reason}):null,_optionalChain([o, 'optionalAccess', _8 => _8.retryable])!==void 0&&!y(o.status)?_jsxruntime.jsx.call(void 0, "li",{children:r(o.retryable?"chat.block.retryable":"chat.block.notRetryable")}):null,_chunkFBADWFRRcjs.a.call(void 0, t.view,b)?_jsxruntime.jsx.call(void 0, "li",{children:_jsxruntime.jsx.call(void 0, "a",{href:t.view,children:r("chat.view")})}):null]})]})})},t.id)})})}var C=(a,d)=>a.id===d.blockId?_optionalChain([a, 'access', _9 => _9.body, 'optionalAccess', _10 => _10.actions, 'optionalAccess', _11 => _11.find, 'call', _12 => _12(i=>"actionId"in d&&i.id===d.actionId), 'optionalAccess', _13 => _13.label]):(_nullishCoalesce(_optionalChain([a, 'access', _14 => _14.body, 'optionalAccess', _15 => _15.blocks]), () => ([]))).map(i=>C(i,d)).find(Boolean);function J({block:a}){let{format:d}=_chunkA3YOSFLEcjs.y.call(void 0, ),i=a.answer&&C(a,a.answer);return _jsxruntime.jsx.call(void 0, "p",{children:i?d("chat.block.answeredWith",{answer:i}):d("chat.block.answered")})}function R({block:a,onReply:d,disabled:i}){let k=_react.useId.call(void 0, ),{format:r,primitives:b}=_chunkA3YOSFLEcjs.y.call(void 0, ),c=a.body,[t,m]=_react.useState.call(void 0, ()=>a.type==="form"?Object.fromEntries((_nullishCoalesce(_optionalChain([c, 'optionalAccess', _16 => _16.fields]), () => ([]))).filter(o=>typeof o.value=="string").map(o=>[o.name,o.value])):{});switch(a.type){case"form.fill":{let l=_optionalChain([a, 'access', _17 => _17.body, 'optionalAccess', _18 => _18.values]);return!l||typeof l!="object"||Array.isArray(l)||Object.values(l).some(s=>!s||typeof s!="object")?_jsxruntime.jsx.call(void 0, "p",{children:a.fallback}):_jsxruntime.jsx.call(void 0, "dl",{children:Object.entries(l).map(([s,n])=>_jsxruntime.jsxs.call(void 0, "div",{children:[_jsxruntime.jsx.call(void 0, "dt",{children:typeof n.label=="string"?n.label:s}),_jsxruntime.jsxs.call(void 0, "dd",{children:[_jsxruntime.jsx.call(void 0, "p",{children:typeof n.value=="string"?n.value:JSON.stringify(n.value)}),_jsxruntime.jsx.call(void 0, "p",{children:r(_optionalChain([n, 'access', _19 => _19.validation, 'optionalAccess', _20 => _20.status])==="valid"?"form.valid":"form.invalid")}),_optionalChain([n, 'access', _21 => _21.validation, 'optionalAccess', _22 => _22.messages, 'optionalAccess', _23 => _23.map, 'call', _24 => _24((p,M)=>_jsxruntime.jsx.call(void 0, "p",{children:p},M))]),_optionalChain([n, 'access', _25 => _25.validation, 'optionalAccess', _26 => _26.guidance])&&_jsxruntime.jsx.call(void 0, "p",{children:n.validation.guidance})]})]},s))})}case"table":return _jsxruntime.jsx.call(void 0, "div",{"data-scroll-region":"",tabIndex:0,role:"region","aria-label":r("chat.scrollRegion"),children:_jsxruntime.jsxs.call(void 0, "table",{children:[_jsxruntime.jsx.call(void 0, "thead",{children:_jsxruntime.jsx.call(void 0, "tr",{children:(_nullishCoalesce(c.columns, () => ([]))).map((o,l)=>_jsxruntime.jsx.call(void 0, "th",{children:o},l))})}),_jsxruntime.jsx.call(void 0, "tbody",{children:(_nullishCoalesce(c.rows, () => ([]))).map((o,l)=>_jsxruntime.jsx.call(void 0, "tr",{children:o.map((s,n)=>_jsxruntime.jsx.call(void 0, "td",{children:String(s)},n))},l))})]})});case"diff":return _jsxruntime.jsxs.call(void 0, "dl",{children:[_jsxruntime.jsx.call(void 0, "dt",{children:r("chat.before")}),_jsxruntime.jsx.call(void 0, "dd",{children:_jsxruntime.jsx.call(void 0, _chunkXWDB2LS3cjs.a,{value:c.before,t:r})}),_jsxruntime.jsx.call(void 0, "dt",{children:r("chat.after")}),_jsxruntime.jsx.call(void 0, "dd",{children:_jsxruntime.jsx.call(void 0, _chunkXWDB2LS3cjs.a,{value:c.after,t:r})})]});case"form":{let o=_nullishCoalesce(c.fields, () => ([])),l=o.some(n=>n.required&&!A(t[n.name])),s=()=>{!i&&!l&&d({kind:"form",blockId:a.id,values:t})};return _jsxruntime.jsxs.call(void 0, "form",{onSubmit:n=>{n.preventDefault(),s()},children:[o.map(n=>_jsxruntime.jsx.call(void 0, b.input,{label:n.required?r("chat.block.required",{label:n.label}):n.label,required:n.required,value:String(_nullishCoalesce(t[n.name], () => (""))),disabled:i,onChange:p=>m({...t,[n.name]:p})},n.name)),_jsxruntime.jsx.call(void 0, _chunkXTKUDSDKcjs.a,{disabled:i,blocked:l,reason:r("chat.block.requiredMissing"),onPress:s})]})}case"choice":{let o=!A(t.answer),l=()=>{!i&&!o&&d({kind:"form",blockId:a.id,values:t})};return _jsxruntime.jsxs.call(void 0, "fieldset",{disabled:i,children:[c.mode==="text"?_jsxruntime.jsx.call(void 0, b.input,{label:a.fallback,value:String(_nullishCoalesce(t.answer, () => (""))),onChange:s=>m({answer:s})}):_jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment,{children:[_jsxruntime.jsx.call(void 0, "legend",{children:a.fallback}),_jsxruntime.jsx.call(void 0, "div",{children:(_nullishCoalesce(c.options, () => ([]))).map(s=>_jsxruntime.jsxs.call(void 0, "label",{children:[_jsxruntime.jsx.call(void 0, "input",{type:c.mode==="multi"?"checkbox":"radio",name:k,disabled:i,checked:c.mode==="multi"?(_nullishCoalesce(t.answer, () => ([]))).includes(s):t.answer===s,onChange:n=>m({answer:c.mode==="multi"?n.target.checked?[..._nullishCoalesce(t.answer, () => ([])),s]:(_nullishCoalesce(t.answer, () => ([]))).filter(p=>p!==s):s})}),s]},s))})]}),_jsxruntime.jsx.call(void 0, _chunkXTKUDSDKcjs.a,{disabled:i,blocked:o,reason:r("chat.block.answerMissing"),onPress:l})]})}case"plan":return _jsxruntime.jsx.call(void 0, "p",{children:a.fallback});default:return _jsxruntime.jsx.call(void 0, "p",{children:a.fallback})}}exports.Answered = J; exports.PlanSteps = V; exports.default = R;
@@ -0,0 +1,3 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkQ7BULGQGcjs = require('./chunk-Q7BULGQG.cjs');var _chunkXSHOLIC7cjs = require('./chunk-XSHOLIC7.cjs');var oe={code:"retryable",id:"stream-reads-load"},Ie,Rt,he=()=>Rt??=Promise.resolve().then(() => _interopRequireWildcard(require("./stream-reads.cjs"))).then(i=>Ie=i,()=>{throw Rt=void 0,{...oe}});async function Pt(){await he()}async function or(i,u,l){return(await _asyncNullishCoalesce(Ie, async () => (await he()))).handleToolRead(i,u,l)}async function sr(i,u,l){return(await _asyncNullishCoalesce(Ie, async () => (await he()))).handlePlanningRead(i,u,l)}var St=(i,u)=>{let l=i.recovery,w=l.versions;return JSON.stringify([u,l.executionId?[1,l.executionId]:[2,l.generation],l.round,l.slots[u],u==="leave"&&[l.decisionKey,w.evidence,w.winner,w.decisionResolution,l.evidenceDigest,l.unknownCount]])};var xe=Object.freeze(["favourites","most-used","recent","presets"]);function dn(i){return typeof i=="string"?i:i.id}var ae=class extends Error{constructor(l,w,o){super("Conversation read failed");this.conversationId=l;this.status=w;this.name="ConversationReadError";let y=o;y&&typeof y.id=="string"&&y.id!==""&&Ct.includes(y.code)&&(this.problem=un(y,y.id))}};function br(i=!1){let u=new Map;return{get:l=>i?Promise.resolve(_nullishCoalesce(u.get(l), () => (null))):_nullishCoalesce(u.get(l), () => (null)),set:(l,w)=>(u.set(l,w),i?Promise.resolve():void 0),remove:l=>(u.delete(l),i?Promise.resolve():void 0),compareAndSet:(l,w,o)=>{let y=(_nullishCoalesce(u.get(l), () => (null)))===w;return y&&u.set(l,o),i?Promise.resolve(y):y}}}var Ht=128,Yt=16,ln=1e4,$t=["proposal","initial-review","forward-active","readback","completed","cancelled","left-known","left-unconfirmed","left-reopened"],kt=[250,500,1e3,2e3,4e3],zt=1e4,Gt=4e3,Xt=1e3,It=1e3,Zt=3e4,se=Symbol("budget-exceeded");function cn(i){let u=typeof i=="object"&&i!==null?i.code:void 0;return u==="sign-in"?"sign-in":u==="update-required"?"update-required":"unavailable"}function ht(i){if(typeof i!="object"||i===null)return!1;let u=i;return typeof u.protocol=="string"&&u.protocol.trim()!==""&&Array.isArray(u.capabilities)&&u.capabilities.every(l=>typeof l=="string")&&(u.agreementId===void 0||typeof u.agreementId=="string"&&/^[A-Za-z0-9._~-]{1,128}$/.test(u.agreementId))}function xt(i,u){return _chunkQ7BULGQGcjs.c.call(void 0, _chunkQ7BULGQGcjs.b.filter(l=>i.capabilities.includes(l)&&u.includes(l)&&(l!=="form-fill"||i.protocol==="1.1")))}function yr(i){let u=new Set;for(let e of _nullishCoalesce(i.tabs, () => (xe))){let n=dn(e);if(u.has(n)||typeof e!="string"&&xe.includes(n))throw new Error("Invalid flow tab id");u.add(n)}let l=new Set,w=new Set,o={protocol:null,replyState:"none",conversationId:i.conversationId,conversation:null,conversationUnavailable:!1,draft:"",pending:[],problem:null,announcement:0,observerFailures:0,capabilities:[],status:"unsubscribed",plan:null,flows:{},flowTab:dn(_nullishCoalesce((_nullishCoalesce(i.tabs, () => (xe)))[0], () => (xe[0]))),flowTabs:_nullishCoalesce(i.tabs, () => (xe)),hints:[],sending:!1,withdrawing:[],restored:[],toolSteps:[],streamUnavailable:!1,intentOverlays:{},intentNotice:null,intentAlert:null},y,L,Ce,Me,W=_chunkQ7BULGQGcjs.f.call(void 0, "client"),m=()=>W.signal.aborted,T=!1,b=_chunkQ7BULGQGcjs.f.call(void 0, "conversation",W.signal),On=()=>{b.abort(),b=_chunkQ7BULGQGcjs.f.call(void 0, "conversation",W.signal)},Te=0,de=new Map,Fn=new WeakMap,Ae=(e,n=b.signal)=>{if(e)for(let[r,a]of de)a&&(r.abort(),de.delete(r));let t=_chunkQ7BULGQGcjs.f.call(void 0, "plan-read",n);return de.set(t,e),t},V=e=>{let n=!e.signal.aborted;return de.delete(e),e.end(),n},En,Un,le=()=>{},ce=-1,We=Promise.resolve(),Nn=!1,G=e=>!!_optionalChain([e, 'optionalAccess', _2 => _2.recovery])&&!!_optionalChain([i, 'access', _3 => _3.plans, 'optionalAccess', _4 => _4.intent])&&o.capabilities.includes("plan-recovery")&&e.recovery.profile==="plan-recovery-v1"&&$t.includes(e.recovery.phase),pn=new Set,ue=new Map,_n=Object.freeze({disabled:"capabilityMissing"}),A=e=>!!_optionalChain([e, 'optionalAccess', _5 => _5.recovery])&&(!G(e)||pn.has(e.id)),g=e=>{if(m())return;o={...o,...e},L!==void 0&&(i.platform.clock.clearTimeout(L),L=void 0);let n=i.platform.clock.now(),t=_optionalChain([o, 'access', _6 => _6.conversation, 'optionalAccess', _7 => _7.messages, 'access', _8 => _8.at, 'call', _9 => _9(-1)]),r=_optionalChain([t, 'optionalAccess', _10 => _10.role])==="assistant"&&t.status==="writing";r?(_optionalChain([Ce, 'optionalAccess', _11 => _11.id])!==t.id||Ce.content!==t.content)&&(Ce={id:t.id,content:t.content,at:n}):Ce=void 0;let a=r?_optionalChain([Ce, 'optionalAccess', _12 => _12.at]):void 0;if(o={...o,planReadOnly:A(o.plan),replyState:tr({messages:_nullishCoalesce(_optionalChain([o, 'access', _13 => _13.conversation, 'optionalAccess', _14 => _14.messages]), () => ([])),pending:o.pending,now:i.platform.clock.now(),overdueAt:_nullishCoalesce(_optionalChain([o, 'access', _15 => _15.conversation, 'optionalAccess', _16 => _16.replyOverdueAt]), () => (void 0)),unavailable:_optionalChain([o, 'access', _17 => _17.conversation, 'optionalAccess', _18 => _18.replyStatus])==="unavailable",failed:_optionalChain([o, 'access', _19 => _19.conversation, 'optionalAccess', _20 => _20.replyStatus])==="failed",streamLost:o.streamUnavailable,activityAt:a,heldUntil:Me})},o.replyState==="none"&&(Me=void 0),o.replyState==="writing"&&a!==void 0){let s=Math.max(a+An,_nullishCoalesce(Me, () => (0)))-n;s>0&&(L=i.platform.clock.setTimeout(()=>{L=void 0,g({})},s))}let d=_optionalChain([o, 'access', _21 => _21.conversation, 'optionalAccess', _22 => _22.messages, 'access', _23 => _23.at, 'call', _24 => _24(-1)]);if(o.replyState==="writing"&&_optionalChain([d, 'optionalAccess', _25 => _25.role])==="user"){let s=Math.max(d.createdAt+15e3,_nullishCoalesce(_optionalChain([o, 'access', _26 => _26.conversation, 'optionalAccess', _27 => _27.replyOverdueAt]), () => (0)),_nullishCoalesce(Me, () => (0)))-i.platform.clock.now();s>0&&(L=i.platform.clock.setTimeout(()=>{L=void 0,g({})},s))}for(let s of l)s()},j=e=>{for(let n of w)try{n(Object.freeze({...e}))}catch (e2){g({observerFailures:o.observerFailures+1})}},f=e=>{g({problem:e,announcement:o.announcement+1}),j({type:"problem",problemId:e.id})},Ve=e=>JSON.stringify(["waypoint",i.accountId,e]),fn={revision:0,draft:"",draftRevision:0,draftWriter:"",pending:[],restored:[]},Mt=Math.random().toString(36).slice(2),qn=e=>`${e.draftRevision}:${e.draftWriter}`,Dn=e=>e!==null&&e.code!=="in-doubt",Tt=e=>e.open.length===0&&Dn(e.failure),At=(e,n)=>({...e,draft:n,draftRevision:e.draftRevision+1,draftWriter:Mt}),Je=(e,n)=>{if(n.kind==="draft")return!m()||qn(e)===n.seen?At(e,n.value):e;if(n.kind==="add")return e.pending.some(d=>d.id===n.row.id)?e:{...e,pending:[...e.pending,n.row]};if(n.kind==="discard")return{...e,restored:e.restored.filter(d=>d.id!==n.id)};let t=e.pending.find(d=>d.id===n.id);if(!t)return e;let r=e.pending.filter(d=>d!==t);if(n.kind==="withdraw")return Tt(t)?{...e,pending:r,restored:[...e.restored,{id:n.restoredId,content:t.content}]}:e;if(n.kind==="remove")return{...e,pending:r};let a=n.kind==="claim"?{...t,open:[...t.open,n.attempt],failure:null}:{...t,open:Dn(n.failure)?t.open.filter(d=>d!==n.attempt):t.open,failure:n.failure};return{...e,pending:e.pending.map(d=>d===t?a:d)}},Kn=e=>({revision:_chunkXSHOLIC7cjs.a.call(void 0, e),draft:typeof _optionalChain([e, 'optionalAccess', _28 => _28.draft])=="string"?e.draft:"",draftRevision:typeof _optionalChain([e, 'optionalAccess', _29 => _29.draftRevision])=="number"?e.draftRevision:0,draftWriter:typeof _optionalChain([e, 'optionalAccess', _30 => _30.draftWriter])=="string"?e.draftWriter:"",pending:(Array.isArray(_optionalChain([e, 'optionalAccess', _31 => _31.pending]))?e.pending:[]).filter(Qt).map(n=>{let t=n.open;return{...n,open:Array.isArray(t)?t.filter(r=>typeof r=="string"):[]}}),restored:(Array.isArray(_optionalChain([e, 'optionalAccess', _32 => _32.restored]))?e.restored:[]).filter(n=>typeof _optionalChain([n, 'optionalAccess', _33 => _33.id])=="string"&&typeof n.content=="string")}),S=fn,je=Ve(i.conversationId),I=[],Oe=[],Bn=new WeakSet,pe=new Set,H=fn,fe=()=>{H=I.reduce(Je,S);let e=H.pending.filter(n=>_optionalChain([o, 'access', _34 => _34.conversation, 'optionalAccess', _35 => _35.messages, 'access', _36 => _36.some, 'call', _37 => _37(t=>t.clientMessageId===n.id)]));if(e.length){for(let n of e)I.push({kind:"remove",id:n.id});H=I.reduce(Je,S),F()}g({draft:H.draft,restored:H.restored,pending:H.pending.map(n=>({id:n.id,content:n.content,failure:n.open.some(t=>pe.has(t))?null:n.open.length===0&&n.failure?n.failure:{code:"in-doubt",id:n.id},...n.extensions?{extensions:n.extensions}:{}}))})},_=e=>{I.push(e),fe()},ge=e=>H.pending.find(n=>n.id===e),gn=()=>({seen:qn(H)}),F=()=>{if(m())return We;let e=i.storage,n=je;return We=We.then(async()=>{let t=[...I,...Oe];Oe=[];let r=S,a;try{e?a=await(await Promise.resolve().then(() => _interopRequireWildcard(require("./storage-commit.cjs")))).commitRecord(e,n,d=>{let s=Kn(d);return s.revision<S.revision&&(s=S),r=t.reduce(Je,s),r===s&&s!==S?null:{...r}}):(r=t.reduce(Je,S),r!==S&&(r={...r,revision:S.revision+1}))}catch (e3){f({code:"unavailable",id:"storage-write"});return}if(n===je){S={...r,revision:_nullishCoalesce(a, () => (r.revision))};for(let d of t)Bn.add(d);I=I.filter(d=>!t.includes(d)),m()||fe()}}),We},Ln=async(e,n)=>{try{let t=await _optionalChain([i, 'access', _38 => _38.storage, 'optionalAccess', _39 => _39.get, 'call', _40 => _40(Ve(e))]);if(!t||n.aborted||Ve(e)!==je)return;let r=Kn(JSON.parse(t));if(r.revision<S.revision)return;S=r,fe()}catch (e4){f({code:"unavailable",id:"storage-read"})}},me,q=[],Y=new Set,Fe=!1,Wn,Ot=new Promise(e=>{Wn=e}),D=()=>me==="form-fill",ve=()=>me!=="ordinary",Vn=e=>["tool.call","planning-read","plan.draft","plan.final","plan.step"].includes(e.type),Jn=async(e,n)=>{try{await we(e,n)}catch (e5){!m()&&!n.aborted&&f({code:"unavailable",id:"frame-dispatch"})}},Ft=()=>{let e=q;q=[],Y.clear();for(let{frame:n,origin:t}of e)t.aborted||(ce=Math.max(ce,n.sequence),D()?we(n,t):Jn(n,t))},h,be=new Map,mn=(e,n)=>o.conversation&&g({conversation:{...o.conversation,messages:o.conversation.messages.map(t=>t.id===e?{...t,...n(t)}:t)}}),vn=(e,n)=>mn(e,()=>({status:n})),bn=(e,n,t)=>be.set(e,{binding:P,status:n,at:Te,read:t}),jn=e=>{for(let n of be.values())n.binding===e&&n.status==="writing"&&(n.reopen=Te)},Hn=e=>{for(let[n,t]of be)t.binding===e&&(be.delete(n),vn(n,t.read))},X=new Map,Z=new Map,He=e=>Z.has(e.id)?Z.get(e.id):_nullishCoalesce(e.versionIndex, () => (1)),Yn=e=>{let n=X.get(e),t=_optionalChain([o, 'access', _41 => _41.conversation, 'optionalAccess', _42 => _42.messages, 'access', _43 => _43.find, 'call', _44 => _44(a=>a.id===e)]),r=t&&He(t);return n&&(n.version===void 0||r===void 0||r<=n.version)?n:void 0},Et=e=>{let n=Z.get(e.id);Z.has(e.id)&&(n===void 0?e.status==="writing":(_nullishCoalesce(e.versionIndex, () => (1)))>=n)&&Z.delete(e.id);let t=X.get(e.id);return t&&e.status==="writing"&&(t.version===void 0||(_nullishCoalesce(e.versionIndex, () => (1)))<=t.version)?{...e,status:"stopped",content:t.content}:e},Ut=(e,n)=>({...e,messages:Nt(e,n).map(Et)}),Nt=(e,n)=>{let t=_nullishCoalesce(_optionalChain([o, 'access', _45 => _45.conversation, 'optionalAccess', _46 => _46.messages]), () => ([]));return e.messages.map(r=>{let a=be.get(r.id);return!a||a.binding!==P||(a.reopen!==void 0&&n>a.reopen&&(a.reopen=void 0,r.status||(a.status=void 0)),!a.status)?r:n<=a.at?_nullishCoalesce(t.find(d=>d.id===r.id), () => (r)):(a.read=r.status,r.status&&r.status!=="writing"&&(a.status=r.status,a.at=n),{...r,status:a.status})})},ye=[],Ee=new WeakMap,_t=0,$n=(e=!1)=>{let n=ye;ye=[];for(let t of n)we(t.frame,t.scope,e)},zn=async(e,n)=>{if(Fe)return{kind:"unavailable",conversationId:o.conversationId};let t=++Te,r=b.signal,a=o.conversationId,d=k;try{let s=await i.transport.read(a,Ke());if(r.aborted||_optionalChain([e, 'optionalAccess', _47 => _47.aborted])||m())return{kind:"superseded",conversationId:a};if(t!==Te&&(me!==void 0||_optionalChain([h, 'optionalAccess', _48 => _48.scope])===r&&h.token>t&&h.result.kind==="missing"))return{kind:"superseded",conversationId:a};for(let p of s.messages)p.clientMessageId&&ge(p.clientMessageId)&&I.push({kind:"remove",id:p.clientMessageId});let c={kind:"loaded",conversationId:a,conversation:s};h={scope:r,token:t,result:c},en(d),me=s.mode==="form-fill"?"form-fill":"ordinary";try{g({conversation:Ut(s,t),conversationUnavailable:!1,...["conversation-read","conversation-unavailable"].includes(_nullishCoalesce(_optionalChain([o, 'access', _49 => _49.problem, 'optionalAccess', _50 => _50.id]), () => ("")))?{problem:null}:{}}),fe()}finally{Ft()}if(s.mode==="form-fill")for(let p of s.messages)for(let v of p.blocks)v.type==="form.fill"&&_optionalChain([i, 'access', _51 => _51.formSession, 'optionalAccess', _52 => _52.receive, 'call', _53 => _53(v.body)]);return await F(),c}catch(s){if(m()||r.aborted)return{kind:"superseded",conversationId:a};if(t!==Te)return{kind:"superseded",conversationId:a};if(_optionalChain([n, 'optionalCall', _54 => _54(s instanceof ae&&s.status===401?"sign-in":s instanceof ae?cn(s.problem):cn(s))]),Be(s)){let c=d!==void 0&&d===k;return Le(d),c||f(Tn(s,"conversation-read")),{kind:"unavailable",conversationId:a}}if(s instanceof ae&&s.conversationId===a&&(s.status===404||s.status===410)){let c={kind:"missing",conversationId:a,status:s.status};return h={scope:r,token:t,result:c},g({conversation:null,conversationUnavailable:!0}),f({code:"unavailable",id:"conversation-read"}),c}return f(Tn(s,"conversation-read")),{kind:"unavailable",conversationId:a}}},Ue,Ne,E=async e=>{$n();let n=b.signal,t=o.conversationId,r=h,a,d={scope:n,id:t,result:new Promise(p=>{a=p})};Ne=d;let s=zn(e);Ue={scope:n,done:s},s.then(a).finally(()=>{_optionalChain([Ue, 'optionalAccess', _55 => _55.done])===s&&(Ue=void 0)});let c=d;for(;;){let p=await c.result;if(m()||n.aborted||t!==o.conversationId)return{kind:"superseded",conversationId:t};if(Ne===c)return p.kind==="unavailable"&&h!==r&&_optionalChain([h, 'optionalAccess', _56 => _56.scope])===n&&h.result.conversationId===t?h.result:p;if(_optionalChain([Ne, 'optionalAccess', _57 => _57.scope])!==n||Ne.id!==t)return{kind:"superseded",conversationId:t};c=Ne}},_e=!1,yn=!1,wn=[],we=(e,n,t=!1)=>{if(m()||n.aborted)return;let r=wn.length;if(!t&&(r||!_e&&i.reads&&!D()&&(e.type==="tool.call"||e.type==="planning-read"))){if(wn.push({frame:e,scope:n}),r)return;let a=d=>{_e=d!==!1,_e||(yn=!0),_e&&_optionalChain([o, 'access', _58 => _58.problem, 'optionalAccess', _59 => _59.id])===oe.id&&g({problem:null});for(let s of wn.splice(0))we(s.frame,s.scope,!_e)};Pt().then(a,()=>a(!1));return}qt(e,n,t)},qt=(e,n,t)=>{if(m()||n.aborted)return;if(D()&&Vn(e)){f({code:"refused",id:"form-tools"});return}if(e.type==="block"&&e.block.type==="form.fill"&&D()&&_optionalChain([i, 'access', _60 => _60.formSession, 'optionalAccess', _61 => _61.receive, 'call', _62 => _62(e.block.body)]),e.type==="tool.call"||e.type==="planning-read"){Ee.has(e)||$n(t);let d=o.conversationId,s=e.type==="tool.call"?e.call:void 0,c=v=>{if(!s||!p())return;let R={id:s.id,...s.label&&{label:s.label},status:v},B=o.toolSteps.findIndex(Cn=>Cn.id===s.id);g({toolSteps:B<0?[...o.toolSteps,R]:o.toolSteps.map((Cn,jt)=>jt===B?R:Cn)})},p=()=>!m()&&!n.aborted&&d===o.conversationId;return c("running"),(async()=>{if(t)throw{...oe};let v=i.reads;if(!v)return f({code:"invalid-read",id:"read-unavailable"});let R=await(await _asyncNullishCoalesce(Ie, async () => (await he()))).answerRead(e,v,d,p,f,B=>kn(n,B));c(R===!1?"failed":"done")})().catch(v=>{if(c("failed"),!!p()){if(_optionalChain([v, 'optionalAccess', _63 => _63.id])!==oe.id)return f({code:"invalid-read",id:"read-failed"});if(Ee.has(e)||Ee.set(e,_t++),ye.push({frame:e,scope:_nullishCoalesce(_optionalChain([P, 'optionalAccess', _64 => _64.scope, 'access', _65 => _65.signal]), () => (n))}),ye.sort((R,B)=>Ee.get(R.frame)-Ee.get(B.frame)),ye.length>Yt&&ye.shift(),t){if(!yn)return;yn=!1}f({...oe})}})}if((e.type==="plan.draft"||e.type==="plan.final")&&i.plans)return gt(e.plan.id,n);if(e.type==="problem"){f(e.problem);return}let r="messageId"in e?be.get(e.messageId):void 0,a="messageId"in e&&_optionalChain([o, 'access', _66 => _66.conversation, 'optionalAccess', _67 => _67.messages, 'access', _68 => _68.find, 'call', _69 => _69(d=>d.id===e.messageId)]);if(e.type==="message.start"&&e.role==="assistant"&&o.conversation&&(o.conversation.replyStatus==="failed"||o.conversation.replyStatus==="unavailable")&&g({conversation:{...o.conversation,replyStatus:void 0}}),!(e.type==="text.delta"&&Yn(e.messageId))){if(e.type==="text.delta"){let d=r&&r.binding===P&&!r.status;d&&bn(e.messageId,"writing",r.read),mn(e.messageId,s=>({content:s.content+e.text,...d&&{status:"writing"}}))}if(e.type==="message.start"&&e.role==="assistant"&&(!a||a.role==="assistant")){let d=a?a.status==="writing"?He(a):i.versions?Math.max(_nullishCoalesce(a.versionCount, () => (1)),_nullishCoalesce(Z.get(e.messageId), () => (0)))+1:void 0:1;Z.set(e.messageId,d);let s=X.get(e.messageId);s&&(s.version===void 0||d===void 0||d>s.version)&&X.delete(e.messageId),bn(e.messageId,"writing",_optionalChain([r, 'optionalAccess', _70 => _70.read])),mn(e.messageId,()=>({status:"writing",content:"",blocks:[]}))}e.type==="message.end"&&a&&["completed","failed","unavailable","stopped"].includes(e.status)&&!(Yn(e.messageId)&&e.status!=="stopped")&&(r?r.binding===P:!a.status||a.status==="writing")&&(bn(e.messageId,e.status,_nullishCoalesce(_optionalChain([r, 'optionalAccess', _71 => _71.read]), () => (a.status))),vn(e.messageId,e.status)),e.type==="message.start"&&o.conversation&&!a&&g({conversation:{...o.conversation,messages:[...o.conversation.messages,{id:e.messageId,role:e.role,content:"",blocks:[],createdAt:i.platform.clock.now(),...e.role==="assistant"&&{status:"writing"}}]}}),(e.type==="stale"||e.type==="message.end")&&E(n)}},qe=e=>{le(),q=q.filter(s=>!s.origin.aborted),Y.clear();for(let s of q)Y.add(s.frame.sequence);ce=-1;let n=_nullishCoalesce(e, () => (Dt()));e&&jn(e);let t=_chunkQ7BULGQGcjs.f.call(void 0, "connection",n.scope.signal),r=()=>{};_chunkQ7BULGQGcjs.g.call(void 0, t.signal,()=>r()),le=()=>t.abort();let a=k,d=!1;r=i.transport.subscribe(o.conversationId,s=>{if(t.signal.aborted)return;if(s.type==="invalidate")return Zn();if(s.type==="status"){let p=s.status==="reconnecting"||s.status==="unavailable";if(p&&jn(n),a!==void 0&&p)return t.abort(),g({status:"reconnecting"}),j({type:"transport.status",conversationId:o.conversationId}),Xn(n);if((s.status==="open"||s.status==="reconnecting")&&(ce=-1,E(t.signal)),a!==void 0&&s.status==="open"&&!d){d=!0,_optionalChain([o, 'access', _72 => _72.problem, 'optionalAccess', _73 => _73.id])==="stream"&&g({problem:null});let v=i.platform.clock.setTimeout(()=>{t.signal.aborted||(n.failures=0)},zt);_chunkQ7BULGQGcjs.g.call(void 0, t.signal,()=>i.platform.clock.clearTimeout(v))}g({status:s.status}),j({type:"transport.status",conversationId:o.conversationId});return}let c=s.frame;if(!(c.sequence<=ce)){if(ce=c.sequence,c.protocol!==o.protocol){f({code:"update-required",id:"stream-version"});return}Vn(c)?me===void 0?Y.has(c.sequence)||(Y.add(c.sequence),q.push({frame:c,origin:t.signal}),q.length>=Ht&&(Fe=!0,g({conversationUnavailable:!0}),Wn(),On(),le(),q=[],Y.clear(),f({code:"unavailable",id:"conversation-unavailable"}))):D()?we(c,t.signal):Jn(c,t.signal):we(c,t.signal)}},Ke()),t.signal.aborted&&r()},P,Dt=()=>(_optionalChain([P, 'optionalAccess', _74 => _74.scope, 'access', _75 => _75.abort, 'call', _76 => _76()]),Hn(P),P={scope:_chunkQ7BULGQGcjs.f.call(void 0, "stream",b.signal),failures:0,gaveUp:!1,createdBy:K},o.streamUnavailable&&g({streamUnavailable:!1}),P),Gn=(e,n,t)=>new Promise(r=>{let a=i.platform.clock.setTimeout(r,e);_optionalChain([t, 'optionalCall', _77 => _77(r)]),_chunkQ7BULGQGcjs.g.call(void 0, n,()=>{i.platform.clock.clearTimeout(a),r()})}),Xn=e=>{if(e!==P||e.scope.signal.aborted||e.gaveUp||e.episode&&!e.episode.signal.aborted)return;let n=_chunkQ7BULGQGcjs.f.call(void 0, "recovery",e.scope.signal);e.episode=n;let t=n.signal,r=(a,d)=>{e.gaveUp=d,d&&Hn(e),g({status:"unavailable",streamUnavailable:d}),f({code:a,id:"stream"})};(async()=>{for(;;){if(e.failures>=kt.length)return r("unavailable",!0);await Gn(kt[e.failures],t);let a=!1;for(;!t.aborted&&!i.platform.online();)a=!0,await Gn(Gt,t,p=>{e.online=p});if(e.online=void 0,a&&(e.failures=0),t.aborted)return;e.failures++;let d=k,s="unavailable",c=await zn(t,p=>{s=p});if(await e.settling,t.aborted||e!==P||d!==k||K!==void 0&&K!==e.createdBy||re)return;if(c.kind==="loaded")return e.episode=void 0,qe(e);if(c.kind==="missing")return;if(s!=="unavailable")return r(s,!1)}})().finally(()=>{e.episode===n&&(e.episode=void 0),n.end()})},Kt=()=>{let e=P;!e||e.scope.signal.aborted||(e.failures=0,_optionalChain([e, 'access', _78 => _78.online, 'optionalCall', _79 => _79()]),e.gaveUp&&(e.gaveUp=!1,g({streamUnavailable:!1}),Xn(e)))},Ye,Zn=()=>{let e=b.signal,n=_optionalChain([Ue, 'optionalAccess', _80 => _80.scope])===e?Ue.done:void 0;if(!n)return void E();Ye!==e&&(Ye=e,n.finally(()=>{Ye===e&&(Ye=void 0,e.aborted||Zn())}))},Qn=async e=>{let n=b.signal,t=o.conversationId,r=k;if(!ge(e))return;g({sending:!0});let d=Math.random().toString(36).slice(2);pe.add(d);let s={kind:"claim",id:e,attempt:d};_(s),await F();let c=I.includes(s)?void 0:S.pending.find(v=>v.id===e),p=v=>(_({kind:"finish",id:e,attempt:d,failure:v}),F());I.includes(s)&&(I=I.filter(v=>v!==s),_({kind:"finish",id:e,attempt:d,failure:{code:"unavailable",id:e}}));try{if(m()||n.aborted||!_optionalChain([c, 'optionalAccess', _81 => _81.open, 'access', _82 => _82.includes, 'call', _83 => _83(d)]))return;if(o.conversationUnavailable){await p({code:"unavailable",id:e});return}if(await i.transport.send({kind:"message",protocol:o.protocol,clientReplyId:e,clientMessageId:e,content:c.content,...c.extensions?{extensions:c.extensions}:{}},t,Ke(r)),n.aborted)return;en(r),pe.delete(d),g({problem:null}),_({kind:"remove",id:e}),await F(),await E()}catch(v){if(n.aborted)return;let R=un(v,e);pe.delete(d),f(R),await p(R),R.code==="agreement-expired"&&Le(r)}finally{pe.delete(d)&&fe(),n.aborted||g({sending:!1})}},U=new Map,O=e=>JSON.stringify([o.conversationId,e]),et=e=>{let n=U.get(O(e.id)),t=e.recovery;return t?typeof t.generation!="string"||!Number.isSafeInteger(t.revision)||t.revision<0||t.conversationId!==o.conversationId||n&&n.generation!==t.generation?"error":!n||t.revision>n.revision?"adopt":t.revision<n.revision||JSON.stringify(e)===n.bytes?"ignore":"error":n?"error":"adopt"},Bt=e=>{G(e)&&Rn(),e.recovery&&U.set(O(e.id),{generation:e.recovery.generation,revision:e.recovery.revision,bytes:JSON.stringify(e),record:JSON.parse(JSON.stringify(e))})},Re=e=>_optionalChain([U, 'access', _84 => _84.get, 'call', _85 => _85(O(e)), 'optionalAccess', _86 => _86.record]),x,Pe=new Map,nt=e=>"lkcs".indexOf(e[0]),tt=e=>(_optionalChain([x, 'optionalAccess', _87 => _87.pending, 'call', _88 => _88(e)])||Pe.has(e))&&(Q(),!0),Q=()=>f({code:"refused",id:"intentPending"}),rt=!1,it,Rn=()=>it??=Promise.resolve().then(() => _interopRequireWildcard(require("./intent.cjs"))).then(e=>{x??=e.createIntentMachine({config:i,publish:g,client:M,scope:()=>b.signal,report:f,read(n){let t=Ae(!0);return[t,Qe(n,t.signal),()=>V(t)]}})},()=>{it=void 0}).finally(()=>{rt=!x,g({})}),$e=(e,n,t="user",r=!1)=>{if(A(Re(e.id)))return Q();let a=b.signal,d=e.id,s=St(e,n),c=!x&&Pe.get(d);if(c){if(c.key===s)return c.settled;if(nt(n)<=nt(c.kind))return Q()}let p=B=>x.submit(e,n,t,r,B);if(x)return p();let v=i.platform.clock.now(),R={kind:n,key:s,settled:Se(Rn(),1e4,a).then(()=>{if(Pe.get(d)===R&&Pe.delete(d),!a.aborted&&!m())return x?p(v):f({code:"retryable",id:"intent-load"})})};return Pe.set(d,R),R.settled},ze=(e=_optionalChain([o, 'access', _89 => _89.plan, 'optionalAccess', _90 => _90.id]))=>e&&(A(Re(e))?Promise.resolve(Q()):_nullishCoalesce(_optionalChain([Pe, 'access', _91 => _91.get, 'call', _92 => _92(e), 'optionalAccess', _93 => _93.settled]), () => (_optionalChain([x, 'optionalAccess', _94 => _94.status, 'call', _95 => _95(e)]))))||Promise.resolve(),ot=()=>{let e=b.signal;return i.plans?_chunkQ7BULGQGcjs.j.call(void 0, {...i.plans,signal:e,read:n=>{let t=Ae(!1);return Qe(n,e).then(r=>{V(t);let a=et(r);if(a==="error")throw f({code:"invalid-plan",id:r.id}),new _chunkQ7BULGQGcjs.h;let d=a==="ignore"?_nullishCoalesce(_optionalChain([U, 'access', _96 => _96.get, 'call', _97 => _97(O(r.id)), 'optionalAccess', _98 => _98.record]), () => (r)):r;if(A(d))throw new _chunkQ7BULGQGcjs.h;let s=JSON.parse(JSON.stringify(d));return Fn.set(s,t.signal),s},r=>{throw V(t),r})},clock:i.platform.clock,interrupted:async(n,t)=>{let r=_optionalChain([U, 'access', _99 => _99.get, 'call', _100 => _100(O(n)), 'optionalAccess', _101 => _101.record]);r&&G(r)&&await $e(r,"stop",t,!0)},onRecord:n=>{e.aborted||_optionalChain([Fn, 'access', _102 => _102.get, 'call', _103 => _103(n), 'optionalAccess', _104 => _104.aborted])||dt(n)&&_optionalChain([i, 'access', _105 => _105.plans, 'optionalAccess', _106 => _106.onRecord, 'optionalCall', _107 => _107(n)])}}):void 0},ee=ot(),Ge=new Set,De=new Map,ne=Promise.resolve(),te=new Map,Pn=e=>JSON.stringify([o.conversationId,e]),Sn=e=>{let n=st(e);return Ge.add(e),_optionalChain([ee, 'optionalAccess', _108 => _108.stop, 'call', _109 => _109(e)]),n},st=e=>{let n=!1;for(let[t,r]of te)r.planId===e&&(n||=!!r.active,te.delete(t));return De.delete(Pn(e)),n},at,C=e=>(at??=Promise.resolve().then(() => _interopRequireWildcard(require("./on-demand.cjs"))).then(n=>n.createOnDemand({ready:z,config:i,client:M,state:()=>o,live:()=>T&&!m(),disposed:m,restricted:ve,formMode:D,report:f,emit:j,refresh:E,stopped:t=>Ge.has(t),versionAsking:t=>{let r=_optionalChain([o, 'access', _110 => _110.conversation, 'optionalAccess', _111 => _111.messages, 'access', _112 => _112.find, 'call', _113 => _113(d=>d.id===t)]),a=r&&He(r);return()=>{let d=X.get(t);d&&(d.version===void 0||a===void 0||d.version<=a)&&X.delete(t)}},refusedPending:tt,readOnly:t=>A(Re(t)),confirmedDigest:t=>De.get(Pn(t)),finishPlanRead:V,showPlan:gt,switchTo:ft,update:g,tabSelected:()=>Nn,sendReply:kn,confirmed:(t,r)=>De.set(Pn(t),r),run:(t,r,a,d)=>d?_optionalChain([ee, 'optionalAccess', _114 => _114.run, 'call', _115 => _115(r,a,d), 'access', _116 => _116.catch, 'call', _117 => _117(s=>{!t.aborted&&!(s instanceof _chunkQ7BULGQGcjs.h)&&f({code:"unavailable",id:r})})]):M.runPlan(r,a)}),n=>{throw at=void 0,n})).then(e,()=>f({code:"retryable",id:"on-demand-load"})),dt=e=>{if(ve())return!1;let n=et(e);if(n==="error")return f({code:"invalid-plan",id:e.id}),!1;let t=(n==="adopt"||_optionalChain([e, 'access', _118 => _118.recovery, 'optionalAccess', _119 => _119.revision])===_optionalChain([U, 'access', _120 => _120.get, 'call', _121 => _121(O(e.id)), 'optionalAccess', _122 => _122.revision]))&&pn.delete(e.id);if(n==="ignore")return t&&g({}),!1;if(Bt(e),A(e)){let r=O(e.id);ue.set(r,(_nullishCoalesce(ue.get(r), () => (0)))+1)}["completed","undone","cancelled","submitted"].includes(e.state)&&st(e.id);for(let r of de.keys())r.abort();return de.clear(),g({plan:JSON.parse(JSON.stringify(e))}),j({type:"plan.state",planId:e.id}),!0},M={get ready(){return z},getSnapshot:()=>o,subscribe:e=>(l.add(e),()=>{l.delete(e)}),on:e=>(w.add(e),()=>{w.delete(e)}),editMessage:(e,n)=>{let t=b.signal;return C(r=>r.version(t,"edit",e,n))},regenerate:e=>{let n=b.signal;return C(t=>t.version(n,"regenerate",e))},selectVersion:(e,n)=>{let t=b.signal;return C(r=>r.version(t,"select",e,void 0,n))},canChangeVersions:()=>!!i.versions,canSendFeedback:()=>!!i.feedback,sendFeedback:(e,n)=>{let t=b.signal;return C(r=>r.feedback(t,e,n)).then(r=>r===!0)},async setDraft(e){_({kind:"draft",value:e,...gn()}),await z,await F()},async send(){if(await z,!T||m()||o.conversationUnavailable||o.sending||!o.draft.trim())return;let e=b.signal,n=o.draft;if(D()){if(!i.formSession){f({code:"refused",id:"form-session"});return}g({sending:!0});try{let t={text:n,field:_optionalChain([o, 'access', _123 => _123.conversation, 'optionalAccess', _124 => _124.field])},r=JSON.stringify([o.conversationId,t,i.formSession.getSnapshot().fields]);_optionalChain([y, 'optionalAccess', _125 => _125.key])!==r&&(y={key:r,request:i.formSession.begin(t)});let a=y.request;await M.reply({kind:"form-fill",clientReplyId:a.requestId,request:a})&&(e.aborted||(y=void 0,o.draft===n&&g({draft:""})))}finally{e.aborted||g({sending:!1})}return}g({sending:!0,toolSteps:[]});try{let t={},r=[],a=!1;for(let p of _nullishCoalesce(i.contributions, () => ([]))){let v=await p.evaluate({draft:n,conversationId:o.conversationId});v.hold&&(a=!0),v.hint&&r.push(v.hint),v.payload!==void 0&&(t[p.id]=v.payload)}if(g({hints:r}),a||e.aborted||o.conversationUnavailable)return;let d=i.platform.ids(),s={kind:"message",protocol:o.protocol,clientReplyId:d,clientMessageId:d,content:n},c=await _optionalChain([i, 'access', _126 => _126.beforeSend, 'optionalCall', _127 => _127(s)]);if(c===!1||e.aborted||o.conversationUnavailable)return;if(c&&(s=c),s.kind!=="message"||s.clientReplyId!==d||s.clientMessageId!==d)throw new Error("Invalid middleware reply");_({kind:"add",row:{id:d,content:s.content,failure:null,extensions:t,open:[]}}),_({kind:"draft",value:o.draft===n?"":o.draft,...gn()}),j({type:"send",conversationId:o.conversationId,replyId:d}),await Qn(d)}catch (e6){f({code:"refused",id:"before-send"})}finally{e.aborted||g({sending:!1})}},async retry(e){await z,!D()&&(!T||m()||o.conversationUnavailable||o.sending||ge(e)&&(j({type:"send",conversationId:o.conversationId,replyId:e}),await Qn(e)))},async withdraw(e){if(!ge(e)||o.withdrawing.includes(e))return;let n={kind:"withdraw",id:e,restoredId:i.platform.ids()};Oe.push(n),g({withdrawing:[...o.withdrawing,e]}),await F(),Oe=Oe.filter(t=>t!==n),g({withdrawing:o.withdrawing.filter(t=>t!==e)}),Bn.has(n)&&ge(e)&&f({code:"refused",id:"sending"})},async editRestored(e){let n=o.restored.find(t=>t.id===e);n&&(_({kind:"draft",value:[o.draft,n.content].filter(Boolean).join(`
2
+
3
+ `),...gn()}),await F())},async discardRestored(e){_({kind:"discard",id:e}),await F()},async dismiss(e){o.sending||(ge(e)&&_({kind:"remove",id:e}),await F())},reply:e=>kn(void 0,e),replyOutcome:e=>ut(void 0,e),refresh:()=>(_optionalChain([P, 'optionalAccess', _128 => _128.gaveUp])&&T&&!m()&&qe(),T&&re&&!m()?Vt():!T&&!m()?on().then(e=>_nullishCoalesce(e, () => ({kind:"unavailable",conversationId:o.conversationId}))):o.conversationUnavailable&&Fe?M.switchConversation(o.conversationId):E()),switchConversation:e=>ft(e),report:f,confirmPlan(){let e=b.signal,n=o.plan;if(D()||m()||!n)return ne;if(A(n))return f({code:"refused",id:n.id}),ne;if(Ge.has(n.id))return f({code:"stopped",id:n.id}),ne;let t=_optionalChain([er, 'call', _129 => _129(n,o.conversationId), 'optionalAccess', _130 => _130.token]);if(tt(n.id)||!t)return ne;let r=n.plan.digest,a=`${n.id}:${t}`,d=te.get(a);if(_optionalChain([d, 'optionalAccess', _131 => _131.active]))return d.active;if(n.state!=="awaiting-confirmation")return ne;let s=_nullishCoalesce(d, () => ({id:i.platform.ids(),planId:n.id}));te.set(a,s);let c=O(n.id),p=ue.get(c),v=()=>A(Re(n.id))||p!==ue.get(c);return s.active=C(R=>R.confirm({scope:e,planId:n.id,token:t,digest:r,replyId:s.id,current:()=>te.get(a)===s,stale:v,refused:B=>G(n)&&!B||v()})).finally(()=>{delete s.active}),s.active},async runPlan(e,n){if(ve()||(await z,ve())||m())return;if(Ge.has(e)){f({code:"stopped",id:e});return}if(!T)return;if(U.has(O(e))||_optionalChain([o, 'access', _132 => _132.plan, 'optionalAccess', _133 => _133.id])===e&&o.plan.recovery){f({code:"refused",id:e});return}let t=b.signal;if(e)try{await _optionalChain([ee, 'optionalAccess', _134 => _134.run, 'call', _135 => _135(e,n)])}catch(r){!t.aborted&&!Be(r)&&f({code:"invalid-plan",id:e})}},stopPlan(e=_optionalChain([o, 'access', _136 => _136.plan, 'optionalAccess', _137 => _137.id])){if(e&&A(Re(e)))f({code:"refused",id:e});else if(e){let n=Sn(e),t=_optionalChain([U, 'access', _138 => _138.get, 'call', _139 => _139(O(e)), 'optionalAccess', _140 => _140.record]);G(t)&&$e(t,"stop","user",n)}},async declinePlan(){let e=o.plan;if(e){if(A(e))return Q();if(!G(e)){f({code:"unavailable",id:"plan-decline"});return}Sn(e.id),await $e(e,"cancel-initial")}},checkIntentStatus:ze,checkSavedChoice:ze,checkKeepStatus:ze,retryIntent:ze,keepChangesReview(e=_optionalChain([o, 'access', _141 => _141.plan, 'optionalAccess', _142 => _142.id])){return e&&A(Re(e))?_n:x?x.keepReview(e?_optionalChain([U, 'access', _143 => _143.get, 'call', _144 => _144(O(e)), 'optionalAccess', _145 => _145.record]):void 0):(Rn(),{disabled:rt?"intentUnavailable":"loading"})},canKeepChanges(e){return!("disabled"in M.keepChangesReview(e))},keepChanges:e=>e===_n?Promise.resolve(Q()):_nullishCoalesce(_optionalChain([x, 'optionalAccess', _146 => _146.keepChanges, 'call', _147 => _147(e)]), () => (Promise.resolve(f({code:"unavailable",id:"plan-keep"})))),async leavePlan(e=_optionalChain([o, 'access', _148 => _148.plan, 'optionalAccess', _149 => _149.id])){let n=e?_optionalChain([U, 'access', _150 => _150.get, 'call', _151 => _151(O(e)), 'optionalAccess', _152 => _152.record]):void 0;if(A(n))return Q();let t=_optionalChain([n, 'optionalAccess', _153 => _153.recovery, 'optionalAccess', _154 => _154.phase]);if(!G(n)||!o.capabilities.includes("plan-leave")||!["readback","left-reopened","forward-active"].includes(t)){f({code:"unavailable",id:"plan-leave"});return}t==="forward-active"&&Sn(n.id),await $e(n,"leave")},resumePlan(){let e=b.signal;return C(n=>n.resumePlan(e))},retryUndo(){let e=b.signal,n=_optionalChain([o, 'access', _155 => _155.plan, 'optionalAccess', _156 => _156.id]),t=Ae(!1);return C(r=>r.retryUndo(e,t,n)).finally(()=>V(t))},readPlan(e=_optionalChain([o, 'access', _157 => _157.plan, 'optionalAccess', _158 => _158.id])){let n=b.signal;return C(t=>t.readPlan(n,e))},setPlan(e){dt(e)},loadFlows(){if(!i.flowSource)return ne;_optionalChain([En, 'optionalAccess', _159 => _159.abort, 'call', _160 => _160()]);let e=En=_chunkQ7BULGQGcjs.f.call(void 0, "flow-load",W.signal);return C(n=>n.loadFlows(e))},selectFlowTab(e){let n=dn(e);(_nullishCoalesce(i.tabs, () => (xe))).some(t=>dn(t)===n)&&(Nn=!0,g({flowTab:n}))},setFavourite:(e,n)=>C(t=>t.setFavourite(e,n)),canPrepareFlow:()=>!!_optionalChain([i, 'access', _161 => _161.flowSource, 'optionalAccess', _162 => _162.load]),keepWaiting(){Me=i.platform.clock.now()+An,g({})},retryReply(){let e=_optionalChain([o, 'access', _163 => _163.conversation, 'optionalAccess', _164 => _164.messages, 'access', _165 => _165.at, 'call', _166 => _166(-1)]),n=lt();if(n||o.replyState==="failed"&&_optionalChain([e, 'optionalAccess', _167 => _167.role])==="assistant"){if(i.versions)return M.regenerate((_nullishCoalesce(n, () => (e))).id);if(n)return Promise.resolve()}return M.keepWaiting(),M.refresh().then(()=>{})},canRetryReply:()=>!lt()||!!i.versions,canStopReply:()=>!!ct()&&o.capabilities.includes("reply-stop"),stopReply(){let e=ct();if(!e||!M.canStopReply())return Promise.resolve();let n=i.platform.ids(),t=He(e);return X.set(e.id,{replyId:n,content:e.content,version:t}),vn(e.id,"stopped"),C(r=>r.stopReply(e.id,n,t))},prepareFlow(e){let n=b.signal;return C(t=>t.prepareFlow(n,e))},runFlow(e,n){if(ve())return ne;_optionalChain([Un, 'optionalAccess', _168 => _168.abort, 'call', _169 => _169()]);let t=Un=_chunkQ7BULGQGcjs.f.call(void 0, "flow-run",W.signal),r=b.signal;return C(a=>a.runFlow(t,r,e,n))},dispose(){q=[],Y.clear(),Fe=!1,y=void 0,_optionalChain([i, 'access', _170 => _170.formSession, 'optionalAccess', _171 => _171.dispose, 'call', _172 => _172()]),te.clear(),De.clear(),_optionalChain([ee, 'optionalAccess', _173 => _173.dispose, 'call', _174 => _174()]),L!==void 0&&i.platform.clock.clearTimeout(L),W.abort(),le(),l.clear(),w.clear()}},lt=()=>{let e=_optionalChain([o, 'access', _175 => _175.conversation, 'optionalAccess', _176 => _176.messages, 'access', _177 => _177.at, 'call', _178 => _178(-1)]);return _optionalChain([e, 'optionalAccess', _179 => _179.role])==="assistant"&&(e.status==="failed"||e.status==="unavailable")&&o.replyState===e.status?e:void 0},ct=()=>{let e=_optionalChain([o, 'access', _180 => _180.conversation, 'optionalAccess', _181 => _181.messages, 'access', _182 => _182.at, 'call', _183 => _183(-1)]);return _optionalChain([e, 'optionalAccess', _184 => _184.role])==="assistant"&&e.status==="writing"?e:void 0},kn=async(e,n,t)=>(await ut(e,n,t)).accepted,ut=async(e,n,t)=>{let r={accepted:!1},a=o.conversationId,d=b.signal,s=()=>!m()&&!d.aborted&&!_optionalChain([e, 'optionalAccess', _185 => _185.aborted])&&a===o.conversationId;if(await z,!T||o.conversationUnavailable||!s()||ve()&&n.kind!=="form-fill"||n.kind==="form-fill"&&(!D()||o.protocol!=="1.1"||!o.capabilities.includes("form-fill")))return r;j({type:"reply",conversationId:a,replyId:n.clientReplyId});let c=k;try{let p=await i.transport.send({...n,protocol:o.protocol},a,Ke(c));return s()&&_optionalChain([t, 'optionalCall', _186 => _186(p)]),s()&&en(c),s()&&await pt(E(e)),{accepted:!0}}catch(p){let v=un(p,n.clientReplyId);return s()&&f(v),s()&&Be(p)?Le(c):s()&&await pt(E(e)),{accepted:!1,problem:v}}},pt=async e=>{await Se(e,ln)===se&&(m()||f({code:"unavailable",id:"conversation-read"}))},ft=async(e,n=[])=>{if(await z,await F(),n.some(a=>a.aborted)||m())return{kind:"superseded",conversationId:e};let t=e===o.conversationId;le(),On(),me=void 0,q=[],Y.clear(),Fe=!1,y=void 0,_optionalChain([i, 'access', _187 => _187.formSession, 'optionalAccess', _188 => _188.cancel, 'call', _189 => _189()]),te.clear(),De.clear(),_optionalChain([ee, 'optionalAccess', _190 => _190.dispose, 'call', _191 => _191()]),ee=ot(),pe.clear(),t||(je=Ve(e),S=fn,I=[]),g({conversationId:e,conversation:null,status:"unsubscribed",...t?{}:{conversationUnavailable:!1},plan:null,problem:null,sending:!1,streamUnavailable:!1,toolSteps:[]}),fe();let r=b.signal;return t||await Ln(e,r),m()||r.aborted?{kind:"superseded",conversationId:e}:T?(qe(),E()):{kind:"unavailable",conversationId:e}},Xe={capabilities:_chunkQ7BULGQGcjs.b.filter(e=>e!=="plan-recovery"&&e!=="plan-leave"&&e!=="plan-keep"||!!_optionalChain([i, 'access', _192 => _192.plans, 'optionalAccess', _193 => _193.intent]))},k,K,Ze=!1,re=!1,Ke=(e=k)=>e===void 0?void 0:{agreementId:e},gt=(e,n)=>{let t=Ae(!0,n);return Qe(e,n).then(r=>{V(t)&&M.setPlan(r)},r=>{V(t)&&!Be(r)&&f(Tn(r,"plan-read"))})},Qe=async(e,n)=>{let t=k;try{let r=await i.plans.read(e,Ke(t));return n.aborted||en(t),r}catch(r){throw!n.aborted&&Be(r)&&Le(t),r}},Be=e=>(e instanceof ae?_optionalChain([e, 'access', _194 => _194.problem, 'optionalAccess', _195 => _195.code]):typeof e=="object"&&e!==null?e.code:void 0)==="agreement-expired",en=e=>{_optionalChain([x, 'optionalAccess', _196 => _196.authenticated, 'call', _197 => _197()]),!(re||e===void 0||e!==k)&&(Ze=!1,_optionalChain([o, 'access', _198 => _198.problem, 'optionalAccess', _199 => _199.id])==="agreement"&&g({problem:null}))},nn=e=>{re=!0,f({code:e,id:"agreement"})},Lt=async()=>{let e=_chunkQ7BULGQGcjs.f.call(void 0, "binding",W.signal);try{return await Wt(e.signal)}finally{e.end()}},Wt=async e=>{le();let n;try{let c=await Se(i.transport.negotiate(_chunkQ7BULGQGcjs.a,Xe),ln);if(c===se)throw new Error("negotiation budget");n=c}catch(c){e.aborted||nn(cn(c));return}if(e.aborted)return;if(!ht(n)||n.agreementId===void 0){nn("unavailable");return}if(n.protocol!==o.protocol){nn("update-required");return}k=n.agreementId,Ze=!0;let t=o.capabilities.includes("plan-recovery"),r=xt(n,Xe.capabilities);if(t!==r.includes("plan-recovery"))for(let[c,{record:p}]of U)p.recovery&&(ue.set(c,(_nullishCoalesce(ue.get(c), () => (0)))+1),t||pn.add(p.id));if(g({capabilities:r}),_optionalChain([x, 'optionalAccess', _200 => _200.authenticated, 'call', _201 => _201()]),e.aborted||(qe(),e.aborted))return;let a=E();P&&(P.settling=a);let d=await a,s=_optionalChain([o, 'access', _202 => _202.plan, 'optionalAccess', _203 => _203.id]);if(!e.aborted&&!re&&s&&i.plans){let c=Ae(!0);Qe(s,b.signal).then(p=>{V(c)&&_optionalChain([o, 'access', _204 => _204.plan, 'optionalAccess', _205 => _205.id])===p.id&&M.setPlan(p)}).catch(()=>V(c))}return d},Le=e=>{if(m()||e===void 0||e!==k)return;if(_optionalChain([ee, 'optionalAccess', _206 => _206.interrupt, 'optionalCall', _207 => _207()]),Ze){nn("unavailable");return}if(K)return K;let n=Lt().finally(()=>{K===n&&(K=void 0),xn()});return K=n,n},Vt=async()=>(re=!1,Ze=!1,await _asyncNullishCoalesce(await(_nullishCoalesce(K, () => (Le(k)))), async () => ({kind:"unavailable",conversationId:o.conversationId}))),Se=(e,n,t=W.signal)=>new Promise((r,a)=>{if(e.catch(()=>{}),m()){r(se);return}let d=()=>{},s=i.platform.clock.setTimeout(()=>{d(),r(se)},n),c=()=>{i.platform.clock.clearTimeout(s),d()};d=_chunkQ7BULGQGcjs.g.call(void 0, t,()=>{i.platform.clock.clearTimeout(s),r(se)}),e.then(p=>{c(),r(p)},p=>{c(),a(p)})}),$=null,In=!1,ie,J,tn=It,hn=[],mt=Se(Ln(o.conversationId,b.signal),Xt).catch(()=>{}),rn=()=>!m()&&!re&&!K&&(!T||!In&&_optionalChain([h, 'optionalAccess', _208 => _208.scope])!==b.signal),xn=()=>{if(m()||J!==void 0||ie||!rn()||$==="update-required"||$==="sign-in")return;let e=tn;tn=Math.min(tn*2,Zt),J=i.platform.clock.setTimeout(()=>{J=void 0,rn()&&(i.platform.online()&&i.platform.visibility()?on():xn())},e)},Jt=async()=>{if(!T){let r;try{let a=await Se(i.transport.negotiate(_chunkQ7BULGQGcjs.a,Xe),ln);if(a===se)throw new Error("negotiation budget");r=a}catch(a){if(m())return;$=cn(a),f({code:$,id:"negotiation"});return}if(m())return;if(!ht(r)){$="unavailable",f({code:"unavailable",id:"negotiation"});return}if(!_chunkQ7BULGQGcjs.a.includes(r.protocol)){$="update-required",f({code:"update-required",id:"negotiation"});return}if(T=!0,$=null,k=r.agreementId,g({protocol:r.protocol,capabilities:xt(r,Xe.capabilities),..._optionalChain([o, 'access', _209 => _209.problem, 'optionalAccess', _210 => _210.id])==="negotiation"?{problem:null}:{}}),await mt,m()||(qe(),m()))return}let e=b.signal,n=o.conversationId,t=await Promise.race([Se(E(),ln),Ot.then(()=>{})]);if(!m())return e.aborted?(In=!0,{kind:"superseded",conversationId:n}):t===se?_optionalChain([h, 'optionalAccess', _211 => _211.scope])===e?h.result:(f({code:"unavailable",id:"conversation-read"}),{kind:"unavailable",conversationId:o.conversationId}):(t||(In=!0),t)},on=()=>{if(ie)return ie;J!==void 0&&(i.platform.clock.clearTimeout(J),J=void 0);let e=Jt().catch(()=>{}).finally(()=>{ie===e&&(ie=void 0),rn()||(tn=It),xn()});return ie=e,e},vt=e=>{!e||!rn()||ie||$!=="update-required"&&(!i.platform.online()||!i.platform.visibility()||on())};for(let[e,n]of[[i.platform.subscribeOnline,t=>{vt(t),t&&Kt()}],[i.platform.subscribeVisibility,vt]])if(e)try{hn.push(e.call(i.platform,n))}catch (e7){}_chunkQ7BULGQGcjs.g.call(void 0, W.signal,()=>{J!==void 0&&i.platform.clock.clearTimeout(J),J=void 0;for(let e of hn)e();hn=[]});let z=Promise.allSettled([on(),mt]).then(()=>{});return M}function Qt(i){return typeof i=="object"&&i!==null&&typeof i.id=="string"&&typeof i.content=="string"}function un(i,u){let l=i,w=_optionalChain([l, 'optionalAccess', _212 => _212.code]),o=_optionalChain([l, 'optionalAccess', _213 => _213.confirmation, 'optionalAccess', _214 => _214.reason]),y=_optionalChain([l, 'optionalAccess', _215 => _215.retryAfter]);return Ct.includes(w)?{code:w,id:u,...w==="refused"&&nr.includes(o)&&{confirmation:{reason:o}},...Number.isInteger(y)&&y>=0&&{retryAfter:y}}:{code:"in-doubt",id:u}}function Tn(i,u){let l=un(i instanceof ae?i.problem:i,u).retryAfter;return l===void 0?{code:"unavailable",id:u}:{code:"rate-limited",id:u,retryAfter:l}}function er(i,u){let l=_optionalChain([i, 'optionalAccess', _216 => _216.confirmation]);return l&&l.planId===i.id&&l.conversationId===u&&Number.isInteger(l.revision)&&l.revision===(_nullishCoalesce(i.recovery, () => (l))).revision?l:void 0}var nr=["expired","used","stale","mismatch","missing"],Ct=["update-required","in-doubt","replaced","retryable","refused","closed","full","declined","unavailable","sign-in","rate-limited","step-up-cancelled","mismatch","invalid-read","invalid-plan","needs-attention","stopped","plan-changed","agreement-expired"],An=15e3;function tr(i){let u=i.messages.at(-1);return _optionalChain([u, 'optionalAccess', _217 => _217.role])==="assistant"&&u.status==="writing"&&!i.pending.some(l=>!l.failure)?i.unavailable||i.streamLost?"unavailable":i.failed?"failed":i.activityAt!==void 0&&i.now>=Math.max(i.activityAt+An,_nullishCoalesce(i.heldUntil, () => (0)))?"overdue":"writing":_optionalChain([u, 'optionalAccess', _218 => _218.role])==="assistant"&&(u.status==="failed"||u.status==="unavailable")&&!i.pending.some(l=>!l.failure)?u.status:_optionalChain([u, 'optionalAccess', _219 => _219.role])!=="user"&&!i.pending.some(l=>!l.failure)?"none":i.pending.some(l=>!l.failure)?"writing":i.unavailable?"unavailable":i.failed?"failed":i.now>=Math.max((_nullishCoalesce(_optionalChain([u, 'optionalAccess', _220 => _220.createdAt]), () => (i.now)))+15e3,(_nullishCoalesce(i.askedAt, () => (0)))+15e3,_nullishCoalesce(i.overdueAt, () => (0)),_nullishCoalesce(i.heldUntil, () => (0)))?"overdue":"writing"}function wr(i){let u=_nullishCoalesce(i.versionIndex, () => (1)),l=_nullishCoalesce(i.versionCount, () => (1));return!Number.isInteger(u)||!Number.isInteger(l)||l<2||u<1||u>l?null:{index:u,count:l,previous:u>1?u-1:null,next:u<l?u+1:null}}exports.a = oe; exports.b = Pt; exports.c = or; exports.d = sr; exports.e = xe; exports.f = dn; exports.g = ae; exports.h = br; exports.i = yr; exports.j = un; exports.k = Tn; exports.l = er; exports.m = tr; exports.n = wr;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var t={background:"#ffffff",foreground:"#18212f",muted:"#526071",accent:"#245ad1",border:"#ccd4df",surface:"#f2f5f9",danger:"#b42318",space:"0.75rem",radius:"0.5rem",fontSize:"1rem",fontFamily:"system-ui, sans-serif",shadow:"0 0.25rem 1rem #0002",motion:"120ms",space1:"0.25rem",space2:"0.5rem",fontSizeSm:"0.875rem",fontSizeLg:"1.125rem",motionFast:"80ms",motionSlow:"200ms",easing:"cubic-bezier(0.2, 0, 0, 1)",focusRing:"#245ad1",controlBorder:"#6b7889",success:"#1a7f37",warning:"#8a5c00"},s= exports.b ={...t,background:"#141b25",foreground:"#eef2f7",muted:"#aebbc9",accent:"#8fb1ff",border:"#465363",surface:"#202b39",danger:"#ffaaa4",focusRing:"#8fb1ff",controlBorder:"#8593a5",success:"#6fdd8b",warning:"#f2cc60"};function f(r){return Object.fromEntries(Object.entries(r).filter(e=>e[1]!==void 0).map(([e,o])=>[`--wp-${e.replace(/[A-Z]/g,n=>"-"+n.toLowerCase())}`,o]))}exports.a = t; exports.b = s; exports.c = f;
@@ -0,0 +1 @@
1
+ import{H as G,J,b as H,e as q,k as X,m as $,n as z,u as V,v as j,x as L,y as O}from"./chunk-IPI4O4LP.js";import{useEffect as te,useId as re,useRef as R,useState as K}from"react";import{jsx as B,jsxs as Q}from"react/jsx-runtime";function U({children:e,label:u,onRegenerate:w,disabled:y,reason:d,slots:h,wrapper:c}){let r=re(),S=L(),[N,p]=K(!1),[f,P]=K(!1),x=R(!1),l=R(!1),m=R(!1),F=R(null),v=R(void 0),i=()=>{clearTimeout(v.current),v.current=void 0};return te(()=>i,[]),Q("div",{ref:c,className:"wp-field-parent",style:{colorScheme:S},onClickCapture:b=>{let n=!!F.current&&H(F.current,b.target);n&&(m.current=!0),$(b,b.currentTarget,()=>{n&&(m.current=!1,!l.current&&!x.current&&(i(),p(!1)))})},onPointerEnter:()=>{x.current=!0,i(),p(!0)},onPointerLeave:()=>{x.current=!1,i(),v.current=setTimeout(()=>{!l.current&&!m.current&&p(!1)},400)},onFocus:()=>{l.current=!0,m.current=!1,i(),p(!0),P(!0)},onBlur:b=>{H(b.currentTarget,b.relatedTarget)||(l.current=!1,P(!1),!x.current&&!m.current&&(i(),p(!1)))},children:[e,Q("span",{ref:F,className:"wp-field-adornment",hidden:!N,children:[B(J,{name:"fieldAdornment",slots:h,label:u,onPress:d?void 0:w,disabled:y,"aria-disabled":d?!0:void 0,describedBy:d?r:void 0,children:B("button",{type:"button","aria-label":u,disabled:y,"aria-disabled":d?!0:void 0,"aria-describedby":d?r:void 0,onClick:()=>{d||w()},children:u})}),d?B("span",{id:r,className:"wp-sr-only",children:d}):null]}),B("span",{role:"status",className:"wp-sr-only",children:N&&f?u:""})]})}import{useEffect as Y,useId as Z,useRef as D,useState as I,useSyncExternalStore as ne}from"react";import{Fragment as ee,jsx as t,jsxs as C}from"react/jsx-runtime";var W=V(()=>import("./form-extras-X3B3JCMH.js"));function _(){let e=j(W);return Y(()=>W.request(),[]),e}var oe=e=>{let u=e.trim()===""?NaN:Number(e);return Number.isFinite(u)?u:void 0};function se(e){return ne(e.subscribe,e.getSnapshot,e.getSnapshot)}function Fe({session:e,onRegenerate:u,slots:w,renderField:y}){let d=se(e),{fields:h,pending:c}=d,{format:r,primitives:S}=O(),N=Z(),p=_(),f=p.status==="ready"?p.module:void 0,P=S.input,x=S.checkbox,l=Object.values(h).some(n=>n.localInvalid),[m,F]=I(""),v=D(new Map),i=D(""),b=q(()=>[v.current.get(i.current)?.querySelector("input,textarea,select,button,[tabindex]")]);return C(ee,{children:[Object.entries(h).map(([n,o],M)=>{let T=`${N}-${M}`,k=o.validation?.status==="invalid"||!!o.localInvalid,g=o.value,A={label:o.label,invalid:k,describedBy:T};return C(U,{reason:f?l?r("form.fixFirst"):c?r("form.revertWait"):void 0:r(p.status==="failed"?"form.toolsFailed":"form.toolsLoading"),label:r("form.regenerate",{field:o.label}),slots:w,onRegenerate:()=>u(n),wrapper:a=>v.current.set(n,a),children:[y?y({name:n,label:o.label,value:g,onChange:a=>e.edit(n,a),invalid:k,describedBy:T}):typeof g=="string"?t(P,{...A,value:g,onChange:a=>e.edit(n,a)}):typeof g=="number"?t(P,{...A,type:"number",value:o.localText??String(g),onChange:a=>{let s=oe(a);s===void 0?e.markEdited(n,a):e.edit(n,s)}}):typeof g=="boolean"?t(x,{...A,checked:g,onChange:a=>e.edit(n,a)}):C("div",{children:[o.label,": ",f?t(f.Value,{value:g,t:r}):null," ",r("form.editInForm")]}),C("div",{id:T,className:k?"wp-invalid":void 0,children:[k?t("strong",{children:r("form.invalid")}):null,o.localInvalid?t("p",{children:r("form.number")}):null,o.validation?.messages.map((a,s)=>t("p",{children:a},s)),o.validation?.guidance&&t("p",{children:o.validation.guidance})]}),t("div",{onFocus:a=>{i.current=n,b(a)},children:o.replacement&&f?t(f.Suggestion,{name:n,draft:o,session:e,t:r,primitives:S,onReplace:()=>F(f.attentionText(e.getSnapshot(),r))}):null})]},n)}),f?t(f.FieldsStatus,{text:m}):null]})}function ye({session:e,open:u,onClose:w,field:y,source:d,attachments:h}){let{format:c,primitives:r}=O(),[S,N]=I(""),[p,f]=I(""),[P,x]=I(""),l=_(),m=l.status==="ready"?l.module:void 0,F=D(null),v=D(0),i=D(void 0),b=r.button,n=r.drawer,o=r.textarea,M=z(),T=Z();Y(()=>(v.current++,()=>{v.current++,e.cancel()}),[u,e,y]);let k=()=>{v.current++,e.cancel(),w()},g=s=>s.some(E=>E.type.startsWith("image/"))?(i.current?i.current([...s]):x(c(h?"form.imagesNow":"form.imagesHere")),!0):!1,A=q(()=>[F.current?.querySelector("textarea")]),a=L();return C(X,{as:n,open:u,label:c("form.title"),onClose:k,closeLabel:c("chat.close"),...M,children:[C("div",{ref:F,style:{colorScheme:a},onPasteCapture:s=>{g(Array.from(s.clipboardData.files))&&h&&i.current&&s.preventDefault()},onDragOver:s=>{s.dataTransfer.types.includes("Files")&&s.preventDefault()},onDrop:s=>{if(!s.dataTransfer.files.length)return;s.preventDefault();let E=Array.from(s.dataTransfer.files);g(E)||i.current?.(E)},children:[t("p",{children:c("chat.message")}),t(o,{label:c("chat.message"),value:S,onChange:N}),t("p",{children:c("form.references")}),t(o,{label:c("form.references"),value:p,onChange:f})]}),m?null:t("p",{role:"status",children:P}),m?t(m.PopupBody,{session:e,open:u,field:y,source:d,attachments:h,text:S,references:p,scope:v,upload:i,messageField:()=>F.current?.querySelector("textarea")??null}):C(ee,{children:[l.status==="failed"||l.status==="loading"&&l.retrying?t(G,{retrying:l.status==="loading",onRetry:()=>W.request(!0),onFocus:A}):null,t(b,{"aria-disabled":!0,"aria-describedby":T,children:c("form.generate")}),t("span",{id:T,children:c(l.status==="failed"?"form.toolsFailed":"form.toolsLoading")})]})]})}export{U as a,se as b,Fe as c,ye as d};
@@ -0,0 +1 @@
1
+ var g=Object.create;var e=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var m=(b,a)=>()=>(a||b((a={exports:{}}).exports,a),a.exports),n=(b,a)=>{for(var c in a)e(b,c,{get:a[c],enumerable:!0})},l=(b,a,c,f)=>{if(a&&typeof a=="object"||typeof a=="function")for(let d of i(a))!k.call(b,d)&&d!==c&&e(b,d,{get:()=>a[d],enumerable:!(f=h(a,d))||f.enumerable});return b};var o=(b,a,c)=>(c=b!=null?g(j(b)):{},l(a||!b||!b.__esModule?e(c,"default",{value:b,enumerable:!0}):c,b));export{m as a,n as b,o as c};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }async function f(t,s){let n=/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/.exec(t);if(!n)throw new Error("Invalid flow frontmatter");let{loadFrontmatter:o}=await Promise.resolve().then(() => _interopRequireWildcard(require("./flow-parser.cjs"))),r=o(n[1]);return i(typeof r=="object"&&r!==null?{...r,body:_nullishCoalesce(n[2], () => (""))}:r,s)}function i(t,s){if(typeof t!="object"||t===null||Array.isArray(t))throw new Error("Invalid flow");let n=t;if(n.format!=="1.0"||typeof n.id!="string"||!n.id||typeof n.title!="string"||!n.title||!["prompt","structured"].includes(n.kind)||!Array.isArray(n.parameters)||!Array.isArray(n.tags)||!n.tags.every(r=>typeof r=="string")||typeof n.body!="string")throw new Error("Invalid flow");let o=new Set;for(let r of n.parameters){if(!r||typeof r.name!="string"||!r.name||o.has(r.name)||!["string","number","boolean"].includes(r.type)||typeof r.required!="boolean"||typeof r.label!="string"||r.default!==void 0&&typeof r.default!==r.type)throw new Error("Invalid flow parameter");o.add(r.name)}if(n.kind==="structured"){if(!Array.isArray(n.steps)||!n.steps.length)throw new Error("Invalid flow steps");for(let r of n.steps){if(!r||!s.includes(r.operation)||typeof r.arguments!="object"||r.arguments===null||Array.isArray(r.arguments))throw new Error("Unknown operation");for(let e of JSON.stringify(r.arguments).matchAll(/\{\{([^}]+)\}\}/g))if(!o.has(e[1]))throw new Error("Unknown parameter")}}else if(n.steps!==void 0)throw new Error("Prompt cannot contain steps");return n}function p(t,s){let n=Object.create(null);for(let r of t.parameters){let e=_nullishCoalesce(s[r.name], () => (r.default));if(e===void 0&&r.required)throw new Error("Missing parameter");if(e!==void 0&&typeof e!==r.type)throw new Error("Invalid parameter type");n[r.name]=e}let o=r=>{if(typeof r=="string"){let e=/^\{\{([^}]+)\}\}$/.exec(r);return e?n[e[1]]:r}return Array.isArray(r)?r.map(o):r&&typeof r=="object"?Object.fromEntries(Object.entries(r).map(([e,a])=>[e,o(a)])):r};return(_nullishCoalesce(t.steps, () => ([]))).map(r=>({operation:r.operation,arguments:o(r.arguments)}))}exports.a = f; exports.b = i; exports.c = p;