@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,38 @@
1
+ import { V as TransportEvent, X as TransportPort, l as ConversationSource } from './form-fill-Dp3ut1_Y.js';
2
+ export { A as AttachmentPort, B as BuiltinFlowTab, h as CAPABILITIES, i as Capability, C as ClientConfig, b as ClientSnapshot, j as ComposerContribution, k as ConversationReadError, d as ConversationReadResult, m as ConversationSummary, D as DEFAULT_FLOW_TABS, n as FORM_SESSION_UNAVAILABLE, o as FeedbackInput, p as FeedbackPort, q as FlowSource, r as FlowSummary, s as FlowTab, t as FormDraft, u as FormField, v as FormMaterial, a as FormSession, F as FormSessionConfig, w as FormSnapshot, K as KeepChangesReview, x as KeepChangesReviewResult, y as KeepDisabledReason, M as MaybePromise, z as MessageVersionInput, E as MessageVersionPort, N as NegotiationOffer, P as PendingSend, G as PlanReadRefused, H as PlanRunner, I as PlatformPorts, f as ReadPorts, J as ReaderRequestContext, e as ReplyDelivery, R as ReplyInput, L as ReplyOutcome, g as ReplyState, O as RestoredMessage, Q as RunnerPorts, a7 as SUPPORTED_PROTOCOLS, S as StepContext, T as StoragePort, U as ToolStep, W as WaypointClient, c as WaypointEvent, Y as asProblem, a8 as blockFallback, Z as canTransition, _ as confirmationOf, $ as createMemoryStorage, a0 as createPlanRunner, a1 as createWaypointClient, a2 as flowTabId, a3 as loadFormSession, a9 as negotiate, a4 as readProblem, a5 as replyRow, a6 as versionWalk, aa as withPrerequisites } from './form-fill-Dp3ut1_Y.js';
3
+ import { H as HttpRequest } from './index-DPzoKXCK.js';
4
+ export { b as CONFORMANCE_UNAVAILABLE, c as ConformanceBlock, a as ConformanceConfig, C as ConformanceResult, d as HttpInit, e as HttpResult, r as runConformance, f as runFormFillConformance, g as runPlanConformance } from './index-DPzoKXCK.js';
5
+ export { R as ReadResult, h as handlePlanningRead, a as handleToolRead, l as loadReadHandlers } from './reads-Bk84x_rt.js';
6
+ import { F as Frame, a as Flow } from './generated-C9tbjwK0.js';
7
+ export { B as Block, b as BlockButtons, c as BlockCard, d as BlockChoice, e as BlockDetails, f as BlockDiff, g as BlockForm, h as BlockFormFill, i as BlockList, j as BlockMarkdown, k as BlockNotice, l as BlockPlan, m as BlockRouteLink, n as BlockTable, C as CanonicalRequest, o as CardAnswer, p as ConfirmationItem, q as ConfirmationRecord, r as ConfirmationSchedule, s as Conversation, t as CreateConversation, D as DecisionVersions, E as ExecutionAcceptance, u as ExtensionBlock, v as FinalHistory, w as FlowParameter, x as FormFillField, y as FormFillRequest, z as FormFillValue, A as FormSubject, G as FormValidation, H as FrameBlock, I as FrameMessageEnd, J as FrameMessageStart, K as FramePlanDraft, L as FramePlanFinal, N as FramePlanStep, O as FramePlanningRead, Q as FrameProblem, S as FrameStale, U as FrameTextDelta, V as FrameToolCall, W as ImmediateDraft, X as ImmediatePlan, Y as IntentCause, Z as IntentKind, _ as IntentRequest, $ as IntentTarget, a0 as IntentWinner, a1 as KeptFact, a2 as LeaveAcknowledgment, M as ManifestEntry, a3 as Message, a4 as Negotiated, a5 as Negotiation, a6 as NegotiationOfferWire, a7 as Outcome, a8 as PatchFlow, a9 as Plan, aa as PlanCommand, ab as PlanIntentReply, ac as PlanRecord, ad as PlanState, P as Problem, R as ReadTemplate, ae as RecoveryPhase, af as RecoveryView, ag as Reply, ah as ReplyAction, ai as ReplyConfirm, aj as ReplyDecline, ak as ReplyForm, al as ReplyFormFill, am as ReplyMessage, an as ReplyPlanValues, ao as ReplyStop, ap as ReplyToolResult, aq as RunFlow, ar as Source, as as Step, at as TimedPlan, T as ToolCall, au as WaypointProtocol, av as WinnerKind } from './generated-C9tbjwK0.js';
8
+ export { I as IntentAlert, b as IntentFailure, c as IntentNotice, d as IntentOverlay, a as ScopeSignal } from './intent-BuvqEU3Q.js';
9
+
10
+ /** The problem a failed load of the read handlers' code rejects with. */
11
+ declare const STREAM_READS_UNAVAILABLE: {
12
+ readonly code: "retryable";
13
+ readonly id: "stream-reads-load";
14
+ };
15
+
16
+ /**
17
+ * Decodes SSE or NDJSON text chunks into frames. Its code is loaded on
18
+ * first use, outside the core bundle.
19
+ */
20
+ declare function decodeFrames(chunks: AsyncIterable<string>, format: "sse" | "ndjson"): AsyncGenerator<Frame>;
21
+ interface StreamPort {
22
+ subscribe(path: string, onChunk: (chunk: string) => void, onStatus: (status: "connecting" | "open" | "reconnecting" | "unavailable") => void): () => void;
23
+ }
24
+ declare function createHttpTransport(request: HttpRequest, stream: StreamPort, format?: "sse" | "ndjson" | "signals"): TransportPort;
25
+ declare function createSignalTransport(request: HttpRequest, stream: StreamPort): TransportPort;
26
+ declare function createSseTransport(request: HttpRequest, stream: StreamPort): TransportPort;
27
+ declare function createFetchStreamTransport(request: HttpRequest, stream: StreamPort): TransportPort;
28
+ type TransportListener = (event: TransportEvent) => void;
29
+ declare function createHttpConversationSource(request: HttpRequest): ConversationSource;
30
+
31
+ declare function parseFlow(source: string, operations: readonly string[]): Promise<Flow>;
32
+ declare function validateFlowDocument(value: unknown, operations: readonly string[]): Flow;
33
+ declare function bindFlow(flow: Flow, values: Record<string, unknown>): {
34
+ operation: string;
35
+ arguments: Record<string, unknown>;
36
+ }[];
37
+
38
+ export { ConversationSource, Flow, Frame, HttpRequest, STREAM_READS_UNAVAILABLE, type StreamPort, TransportEvent, type TransportListener, TransportPort, bindFlow, createFetchStreamTransport, createHttpConversationSource, createHttpTransport, createSignalTransport, createSseTransport, decodeFrames, parseFlow, validateFlowDocument };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import{a as k,b as A,c as O}from"./chunk-S73WZWDP.js";import{a as T,b as I,c as H,d as q,e as j,f as E,g,h as N,i as U,j as $,k as M,l as B,m as L,n as V}from"./chunk-L4PFFRDE.js";import{a as C,b as x,c as S,d as R,e as F,h,i as w,j as P}from"./chunk-T5XF2R74.js";import"./chunk-K73VV7KA.js";import"./chunk-5TBO732O.js";var b={code:"retryable",id:"conformance-load"},m=async()=>{try{return await import("./conformance.js")}catch{throw{...b}}};async function J(e){return(await m()).runConformance(e)}async function _(e){return(await m()).runPlanConformance(e)}async function D(e){return(await m()).runFormFillConformance(e)}async function*z(e,t){yield*(await import("./frame-decoder.js")).decodeFrames(e,t)}function d(e,t,i="sse"){let u=o=>o?{"Waypoint-Agreement":o.agreementId}:{},y=async(o,n,r)=>{let s=await e(o,{method:"POST",headers:{"Content-Type":"application/json",...u(r)},body:JSON.stringify(n)});if(s.status<200||s.status>=300)throw s.body;return s.body};return{negotiate:async(o,n)=>{let r=await e("/negotiate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({protocol:"1.0",supported:o,...n?{offer:{capabilities:[...n.capabilities]}}:{}})});if(r.status===401)throw{code:"sign-in",id:"negotiation"};if(r.status<200||r.status>=300)throw r.body;return r.body},read:async(o,n)=>{let r=await e(`/conversations/${encodeURIComponent(o)}`,n?{headers:u(n)}:void 0);if(r.status!==200)throw new g(o,r.status,r.body);return r.body},send:async(o,n,r)=>await y(`/conversations/${encodeURIComponent(n)}/${o.kind==="message"?"messages":"replies"}`,o,r),subscribe(o,n,r){let s="",p=[],f=a=>{try{let l=JSON.parse(a);n({type:"frame",frame:l})}catch{n({type:"status",status:"unavailable"})}};return t.subscribe(`/conversations/${encodeURIComponent(o)}/stream${r?`?waypointAgreement=${encodeURIComponent(r.agreementId)}`:""}`,a=>{s+=a;let l;for(;(l=s.indexOf(`
2
+ `))>=0;){let c=s.slice(0,l).replace(/\r$/,"");s=s.slice(l+1),i==="signals"?c.trim()&&n({type:"invalidate"}):i!=="sse"?c.trim()&&f(c):c===""?(p.length&&f(p.join(`
3
+ `)),p=[]):c.startsWith("data:")&&p.push(c.slice(5).replace(/^ /,""))}},a=>{(a==="reconnecting"||a==="open")&&(s="",p=[]),n({type:"status",status:a})})}}}function K(e,t){return d(e,t,"signals")}function Q(e,t){return d(e,t,"sse")}function X(e,t){return d(e,t,"ndjson")}function Y(e){return{async list(t){let i=await e(`/conversations${t?`?subject=${encodeURIComponent(t)}`:""}`);if(i.status!==200||!Array.isArray(i.body))throw new Error("Conversation list unavailable");return i.body},async create(t){let i=await e("/conversations",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(i.status<200||i.status>=300)throw i.body;return i.body}}}var v={code:"retryable",id:"form-session-load"};async function ee(e){let t;try{t=await import("./form-session.js")}catch{throw{...v}}return t.createFormSession(e)}export{x as CAPABILITIES,b as CONFORMANCE_UNAVAILABLE,g as ConversationReadError,j as DEFAULT_FLOW_TABS,v as FORM_SESSION_UNAVAILABLE,h as PlanReadRefused,T as STREAM_READS_UNAVAILABLE,C as SUPPORTED_PROTOCOLS,$ as asProblem,O as bindFlow,F as blockFallback,w as canTransition,B as confirmationOf,X as createFetchStreamTransport,Y as createHttpConversationSource,d as createHttpTransport,N as createMemoryStorage,P as createPlanRunner,K as createSignalTransport,Q as createSseTransport,U as createWaypointClient,z as decodeFrames,E as flowTabId,q as handlePlanningRead,H as handleToolRead,ee as loadFormSession,I as loadReadHandlers,R as negotiate,k as parseFlow,M as readProblem,L as replyRow,J as runConformance,D as runFormFillConformance,_ as runPlanConformance,A as validateFlowDocument,V as versionWalk,S as withPrerequisites};
@@ -0,0 +1,154 @@
1
+ import { Z as IntentKind, $ as IntentTarget, a2 as LeaveAcknowledgment, _ as IntentRequest, ab as PlanIntentReply, ac as PlanRecord, Y as IntentCause } from './generated-C9tbjwK0.cjs';
2
+
3
+ interface ScopeSignal {
4
+ readonly aborted: boolean;
5
+ addEventListener(type: "abort", listener: () => void, options?: {
6
+ once?: boolean;
7
+ }): void;
8
+ removeEventListener(type: "abort", listener: () => void): void;
9
+ }
10
+ interface Scope {
11
+ readonly signal: ScopeSignal;
12
+ abort(): void;
13
+ /** Releases the link to the parent once the work has finished. */
14
+ end(): void;
15
+ }
16
+
17
+ interface CapturedIntent {
18
+ kind: IntentKind;
19
+ planId: string;
20
+ target: IntentTarget;
21
+ capturedRound: number;
22
+ expectedSlotVersion: number;
23
+ correlation: string;
24
+ acknowledgment?: LeaveAcknowledgment;
25
+ review?: IntentRequest["review"];
26
+ }
27
+ interface Clock {
28
+ setTimeout(fn: () => void, ms: number): unknown;
29
+ clearTimeout(handle: unknown): void;
30
+ }
31
+ /** What the core captured synchronously: the adopted record it saw. */
32
+ interface IntentSource {
33
+ record: PlanRecord;
34
+ kind: IntentKind;
35
+ correlation: string;
36
+ }
37
+ /** The exact target, round, slot version and acknowledgment of a capture. */
38
+ declare function captureFrom(source: IntentSource): CapturedIntent;
39
+ declare function buildIntent(captured: CapturedIntent, cause: IntentCause): IntentRequest;
40
+ /** A reply is accepted only when it answers this exact request. */
41
+ declare function answers(reply: unknown, request: IntentRequest): reply is PlanIntentReply;
42
+ /** One protected plan's pending terminal intent, as the snapshot shows it. */
43
+ interface IntentOverlay {
44
+ planId: string;
45
+ kind: IntentKind;
46
+ request: IntentRequest;
47
+ producer: "user" | "automatic";
48
+ delivery: "sending" | "uncertain" | "not-sent";
49
+ ownRun: boolean;
50
+ retryAt?: number;
51
+ lastProblem?: {
52
+ key: string;
53
+ cause: IntentFailure;
54
+ };
55
+ }
56
+ type IntentFailure = "offline" | "sign-in" | "forbidden" | "rate-limited" | "timeout" | "connection-lost";
57
+ type IntentNotice = Omit<PlanIntentReply, "slotVersion"> & {
58
+ resolvedSlotVersion: number;
59
+ };
60
+ type IntentAlert = {
61
+ serial: number;
62
+ action: "checkStatus" | "retry" | "signIn" | "hostGuidance" | "wait";
63
+ } | {
64
+ serial: number;
65
+ restoreFocus: true;
66
+ };
67
+ /** A terminal action handed to the machine by the core. */
68
+ interface IntentPress {
69
+ captured: IntentSource;
70
+ cause: IntentCause;
71
+ producer: "user" | "automatic";
72
+ scope: ScopeSignal;
73
+ capability?: string;
74
+ ownRun: boolean;
75
+ startedAt: number;
76
+ done(): void;
77
+ }
78
+ interface IntentContext {
79
+ config: {
80
+ plans?: {
81
+ intent?(request: IntentRequest): Promise<PlanIntentReply>;
82
+ };
83
+ platform: {
84
+ clock: Clock & {
85
+ now(): number;
86
+ };
87
+ online(): boolean;
88
+ ids(): string;
89
+ };
90
+ };
91
+ publish(patch: {
92
+ intentOverlays?: Record<string, IntentOverlay>;
93
+ intentNotice?: IntentNotice | null;
94
+ intentAlert?: IntentAlert | null;
95
+ }): void;
96
+ client: {
97
+ getSnapshot(): {
98
+ capabilities: readonly string[];
99
+ };
100
+ setPlan(record: PlanRecord): void;
101
+ };
102
+ scope(): ScopeSignal;
103
+ report(problem: {
104
+ code: string;
105
+ id: string;
106
+ retryAfter?: number;
107
+ }): void;
108
+ read(planId: string): [
109
+ {
110
+ signal: ScopeSignal;
111
+ abort(): void;
112
+ },
113
+ Promise<PlanRecord>,
114
+ () => boolean
115
+ ];
116
+ }
117
+ interface IntentMachine {
118
+ press(press: IntentPress, deferred?: boolean): void;
119
+ submit(record: PlanRecord, kind: IntentKind, cause: IntentCause, ownRun: boolean, pressedAt?: number): Promise<void>;
120
+ status(planId: string): Promise<void>;
121
+ authenticated(): void;
122
+ pending(planId: string): boolean;
123
+ keepReview(record: PlanRecord | undefined): KeepReviewResult;
124
+ keepChanges(review: object): Promise<void>;
125
+ }
126
+ type KeepReviewResult = {
127
+ review: "forward-only" | "end-retention";
128
+ remaining: number;
129
+ acknowledgment: LeaveAcknowledgment;
130
+ } | {
131
+ disabled: "capabilityMissing" | "keepNoDecision" | "sealed" | "keepBlockedActive" | "keepBlockedUnknown";
132
+ };
133
+ /**
134
+ * Whether a sign-in-blocked intent may be sent once more after a successful
135
+ * authenticated call: it is waiting on sign-in, has no delivery in flight,
136
+ * has not used its one automatic retry, and its scope is still alive.
137
+ */
138
+ declare function signInRetryAllowed(live: {
139
+ attempt?: unknown;
140
+ autoRetried: boolean;
141
+ overlay: {
142
+ lastProblem?: {
143
+ cause: IntentFailure;
144
+ };
145
+ };
146
+ scope: {
147
+ aborted: boolean;
148
+ };
149
+ }): boolean;
150
+ /** Equal for two requests the host treats as the same intent. */
151
+ declare const semantic: (request: IntentRequest) => string;
152
+ declare function createIntentMachine(context: IntentContext): IntentMachine;
153
+
154
+ export { type CapturedIntent as C, type IntentAlert as I, type KeepReviewResult as K, type Scope as S, type ScopeSignal as a, type IntentFailure as b, type IntentNotice as c, type IntentOverlay as d, type IntentContext as e, type IntentMachine as f, type IntentPress as g, type IntentSource as h, answers as i, buildIntent as j, captureFrom as k, createIntentMachine as l, signInRetryAllowed as m, semantic as s };
@@ -0,0 +1,154 @@
1
+ import { Z as IntentKind, $ as IntentTarget, a2 as LeaveAcknowledgment, _ as IntentRequest, ab as PlanIntentReply, ac as PlanRecord, Y as IntentCause } from './generated-C9tbjwK0.js';
2
+
3
+ interface ScopeSignal {
4
+ readonly aborted: boolean;
5
+ addEventListener(type: "abort", listener: () => void, options?: {
6
+ once?: boolean;
7
+ }): void;
8
+ removeEventListener(type: "abort", listener: () => void): void;
9
+ }
10
+ interface Scope {
11
+ readonly signal: ScopeSignal;
12
+ abort(): void;
13
+ /** Releases the link to the parent once the work has finished. */
14
+ end(): void;
15
+ }
16
+
17
+ interface CapturedIntent {
18
+ kind: IntentKind;
19
+ planId: string;
20
+ target: IntentTarget;
21
+ capturedRound: number;
22
+ expectedSlotVersion: number;
23
+ correlation: string;
24
+ acknowledgment?: LeaveAcknowledgment;
25
+ review?: IntentRequest["review"];
26
+ }
27
+ interface Clock {
28
+ setTimeout(fn: () => void, ms: number): unknown;
29
+ clearTimeout(handle: unknown): void;
30
+ }
31
+ /** What the core captured synchronously: the adopted record it saw. */
32
+ interface IntentSource {
33
+ record: PlanRecord;
34
+ kind: IntentKind;
35
+ correlation: string;
36
+ }
37
+ /** The exact target, round, slot version and acknowledgment of a capture. */
38
+ declare function captureFrom(source: IntentSource): CapturedIntent;
39
+ declare function buildIntent(captured: CapturedIntent, cause: IntentCause): IntentRequest;
40
+ /** A reply is accepted only when it answers this exact request. */
41
+ declare function answers(reply: unknown, request: IntentRequest): reply is PlanIntentReply;
42
+ /** One protected plan's pending terminal intent, as the snapshot shows it. */
43
+ interface IntentOverlay {
44
+ planId: string;
45
+ kind: IntentKind;
46
+ request: IntentRequest;
47
+ producer: "user" | "automatic";
48
+ delivery: "sending" | "uncertain" | "not-sent";
49
+ ownRun: boolean;
50
+ retryAt?: number;
51
+ lastProblem?: {
52
+ key: string;
53
+ cause: IntentFailure;
54
+ };
55
+ }
56
+ type IntentFailure = "offline" | "sign-in" | "forbidden" | "rate-limited" | "timeout" | "connection-lost";
57
+ type IntentNotice = Omit<PlanIntentReply, "slotVersion"> & {
58
+ resolvedSlotVersion: number;
59
+ };
60
+ type IntentAlert = {
61
+ serial: number;
62
+ action: "checkStatus" | "retry" | "signIn" | "hostGuidance" | "wait";
63
+ } | {
64
+ serial: number;
65
+ restoreFocus: true;
66
+ };
67
+ /** A terminal action handed to the machine by the core. */
68
+ interface IntentPress {
69
+ captured: IntentSource;
70
+ cause: IntentCause;
71
+ producer: "user" | "automatic";
72
+ scope: ScopeSignal;
73
+ capability?: string;
74
+ ownRun: boolean;
75
+ startedAt: number;
76
+ done(): void;
77
+ }
78
+ interface IntentContext {
79
+ config: {
80
+ plans?: {
81
+ intent?(request: IntentRequest): Promise<PlanIntentReply>;
82
+ };
83
+ platform: {
84
+ clock: Clock & {
85
+ now(): number;
86
+ };
87
+ online(): boolean;
88
+ ids(): string;
89
+ };
90
+ };
91
+ publish(patch: {
92
+ intentOverlays?: Record<string, IntentOverlay>;
93
+ intentNotice?: IntentNotice | null;
94
+ intentAlert?: IntentAlert | null;
95
+ }): void;
96
+ client: {
97
+ getSnapshot(): {
98
+ capabilities: readonly string[];
99
+ };
100
+ setPlan(record: PlanRecord): void;
101
+ };
102
+ scope(): ScopeSignal;
103
+ report(problem: {
104
+ code: string;
105
+ id: string;
106
+ retryAfter?: number;
107
+ }): void;
108
+ read(planId: string): [
109
+ {
110
+ signal: ScopeSignal;
111
+ abort(): void;
112
+ },
113
+ Promise<PlanRecord>,
114
+ () => boolean
115
+ ];
116
+ }
117
+ interface IntentMachine {
118
+ press(press: IntentPress, deferred?: boolean): void;
119
+ submit(record: PlanRecord, kind: IntentKind, cause: IntentCause, ownRun: boolean, pressedAt?: number): Promise<void>;
120
+ status(planId: string): Promise<void>;
121
+ authenticated(): void;
122
+ pending(planId: string): boolean;
123
+ keepReview(record: PlanRecord | undefined): KeepReviewResult;
124
+ keepChanges(review: object): Promise<void>;
125
+ }
126
+ type KeepReviewResult = {
127
+ review: "forward-only" | "end-retention";
128
+ remaining: number;
129
+ acknowledgment: LeaveAcknowledgment;
130
+ } | {
131
+ disabled: "capabilityMissing" | "keepNoDecision" | "sealed" | "keepBlockedActive" | "keepBlockedUnknown";
132
+ };
133
+ /**
134
+ * Whether a sign-in-blocked intent may be sent once more after a successful
135
+ * authenticated call: it is waiting on sign-in, has no delivery in flight,
136
+ * has not used its one automatic retry, and its scope is still alive.
137
+ */
138
+ declare function signInRetryAllowed(live: {
139
+ attempt?: unknown;
140
+ autoRetried: boolean;
141
+ overlay: {
142
+ lastProblem?: {
143
+ cause: IntentFailure;
144
+ };
145
+ };
146
+ scope: {
147
+ aborted: boolean;
148
+ };
149
+ }): boolean;
150
+ /** Equal for two requests the host treats as the same intent. */
151
+ declare const semantic: (request: IntentRequest) => string;
152
+ declare function createIntentMachine(context: IntentContext): IntentMachine;
153
+
154
+ export { type CapturedIntent as C, type IntentAlert as I, type KeepReviewResult as K, type Scope as S, type ScopeSignal as a, type IntentFailure as b, type IntentNotice as c, type IntentOverlay as d, type IntentContext as e, type IntentMachine as f, type IntentPress as g, type IntentSource as h, answers as i, buildIntent as j, captureFrom as k, createIntentMachine as l, signInRetryAllowed as m, semantic as s };
@@ -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 _chunk3KV7TDDRcjs = require('./chunk-3KV7TDDR.cjs');var _chunkQ7BULGQGcjs = require('./chunk-Q7BULGQG.cjs');require('./chunk-XSHOLIC7.cjs');require('./chunk-II26UWZM.cjs');function F(t){let r=t.recovery;return{sourceDecisionKey:r.decisionKey,evidenceVersion:r.versions.evidence,winnerVersion:r.versions.winner,decisionResolutionVersion:r.versions.decisionResolution,evidenceDigest:r.evidenceDigest,unknownCount:r.unknownCount}}var b=1e4,U=["applied","replaced","already-closed","already-stopped","defeated","superseded","needs-review","conflict","unavailable","invalid-target","refused","kept","already-kept","sealed"];function j(t){let{record:r,kind:a}=t,i=r.recovery;return{kind:a,planId:r.id,target:a==="cancel-review"&&i.reviewId?{type:"review",id:i.reviewId}:i.executionId?{type:"execution",id:i.executionId}:{type:"generation",id:i.generation},capturedRound:i.round,expectedSlotVersion:i.slots[a],correlation:t.correlation,...a==="keep"?{review:(_nullishCoalesce(i.remaining, () => (0)))>0?"forward-only":"end-retention"}:{},...a==="leave"||a==="keep"?{acknowledgment:F(r)}:{}}}function G(t,r){return{...t,target:{...t.target},...t.acknowledgment?{acknowledgment:{...t.acknowledgment}}:{},cause:r}}function $(t,r){let a=t;return typeof a=="object"&&a!==null&&a.planId===r.planId&&a.kind===r.kind&&a.correlation===r.correlation&&a.capturedRound===r.capturedRound&&typeof a.slotVersion=="number"&&U.includes(a.result)&&Array.isArray(a.keys)&&a.keys.every(i=>typeof i=="string")}function z(t){return!t.attempt&&!t.autoRetried&&_optionalChain([t, 'access', _2 => _2.overlay, 'access', _3 => _3.lastProblem, 'optionalAccess', _4 => _4.cause])==="sign-in"&&!t.scope.aborted}var V={stop:4,"cancel-initial":3,"cancel-review":3,keep:2,leave:1},_={stop:"stop","cancel-initial":"cancelInitial","cancel-review":"cancelReview",leave:"leave",keep:"keep"},E= exports.semantic =t=>JSON.stringify([t.target,t.capturedRound,t.expectedSlotVersion,_nullishCoalesce(t.acknowledgment, () => (null)),_nullishCoalesce(t.review, () => (null)),_nullishCoalesce(t.payload, () => (null))]),J=(t,r)=>{let a=_[t.kind];return r==="timeout"&&t.delivery!=="not-sent"||r==="connection-lost"?`${a}Unconfirmed`:r==="forbidden"?`${a}Refused`:t.kind==="stop"&&!t.ownRun?"stopNotSentElsewhere":`${a}NotSent`},W={timeout:"checkStatus","connection-lost":"checkStatus",offline:"retry","sign-in":"signIn",forbidden:"hostGuidance","rate-limited":"wait"};function Z(t){let r=t.config.platform.clock,a=n=>t.client.getSnapshot().capabilities.includes(n),i=new Map,K=new WeakMap,x=0,S=0,I,P=new Map,m=()=>{let n={};for(let[e,o]of i)n[e]={...o.overlay};t.publish({intentOverlays:n})},f=n=>{for(let e of n.splice(0))e()},h=(n,e)=>{e.attempt&&(r.clearTimeout(e.attempt.timer),f(e.attempt.waiters),e.attempt=void 0),e.retryTimer!==void 0&&r.clearTimeout(e.retryTimer),f(e.waiting),i.get(n)===e&&i.delete(n)},q=n=>{I!==n&&(I=n,t.publish({intentAlert:{serial:++S,action:W[n]}}))},T=(n,e)=>{_optionalChain([P, 'access', _5 => _5.get, 'call', _6 => _6(n), 'optionalCall', _7 => _7()]);let[o,s,c]=t.read(n),u=r.now()+b,d=!1,k=()=>{d=!0,r.clearTimeout(p),P.get(n)===y&&P.delete(n)},y=()=>{d||(k(),o.abort())},v=()=>{if(d)return;let l=!e.aborted&&!o.signal.aborted;k(),o.abort(),l&&t.report({code:"unavailable",id:"plan-read"})},p=r.setTimeout(v,b);_chunkQ7BULGQGcjs.g.call(void 0, e,y),_chunkQ7BULGQGcjs.g.call(void 0, o.signal,y),P.set(n,y);let g=l=>{if(!d&&r.now()>=u&&v(),d)return c();k(),l(c())};s.then(l=>g(N=>N&&t.client.setPlan(l)),l=>g(N=>N&&!e.aborted&&t.report(_chunk3KV7TDDRcjs.k.call(void 0, l,"plan-read"))))},w=(n,e,o)=>{let s={...n.overlay,delivery:o};n.overlay={...s,lastProblem:{key:J(s,e),cause:e}},q(e),m()},A=(n,e,o)=>{let s=e.waiting.splice(0);if(e.scope.aborted){f(s),h(n,e),m();return}if(e.capability&&!a(e.capability)){t.report({code:"unavailable",id:e.capability}),f(s),h(n,e),m();return}e.overlay={...e.overlay,delivery:"sending"};let c=r.now()>=o;if(c||!t.config.platform.online()){w(e,c?"timeout":"offline","not-sent"),f(s);return}let d={id:++x,timer:void 0,waiters:s};e.attempt=d,m();let k=()=>{v(),w(e,"timeout","uncertain"),T(n,e.scope),f(s)},y=()=>e.attempt!==d||i.get(n)!==e?!1:r.now()<o?!0:(k(),!1),v=()=>{r.clearTimeout(d.timer),e.attempt=void 0};d.timer=r.setTimeout(()=>{e.attempt===d&&i.get(n)===e&&k()},o-r.now()),t.config.plans.intent(e.overlay.request).then(p=>{if(y()){if(v(),$(p,e.overlay.request)){let{slotVersion:g,...l}=p;i.delete(n),I!==void 0&&(I=void 0,t.publish({intentAlert:{serial:S,restoreFocus:!0}})),t.publish({intentNotice:{...l,resolvedSlotVersion:g}}),m()}else w(e,"connection-lost","uncertain");T(n,e.scope),f(s)}},p=>{if(!y())return;v();let g=typeof p=="object"&&p?p.status:void 0;if(g===401)w(e,"sign-in","not-sent"),t.report({code:"sign-in",id:"intent"});else if(g===403)w(e,"forbidden","not-sent");else if(g===429){let l=Number.isInteger(p.retryAfter)&&p.retryAfter>=0?p.retryAfter:1;e.overlay={...e.overlay,retryAt:r.now()+l*1e3},w(e,"rate-limited","not-sent"),e.retryTimer=r.setTimeout(()=>{e.retryTimer=void 0,i.get(n)===e&&I==="rate-limited"&&t.publish({intentAlert:{serial:S,action:"retry"}})},l*1e3)}else w(e,"connection-lost","uncertain"),T(n,e.scope);f(s)})},R=new Set,C=new Map,D=()=>{for(let n of R){let e=i.get(n);e&&!e.attempt&&A(n,e,_nullishCoalesce(C.get(n), () => (r.now()+b)))}R.clear(),C.clear()},L=(n,e=!1)=>{let o=n.captured.record.id;if(n.scope.aborted)return n.done();if(n.capability&&!a(n.capability))return t.report({code:"unavailable",id:n.capability}),n.done();let s=G(j(n.captured),n.cause),c=i.get(o);if(c&&c.overlay.kind===s.kind){if(E(c.overlay.request)!==E(s))return t.report({code:"refused",id:"intentPending"}),n.done();c.attempt?c.attempt.waiters.push(n.done):R.has(o)?c.waiting.push(n.done):n.done();return}if(c&&V[s.kind]<=V[c.overlay.kind])return t.report({code:"refused",id:"intentPending"}),n.done();c&&h(o,c);let u={overlay:{planId:o,kind:s.kind,request:s,producer:n.producer,delivery:"sending",ownRun:n.ownRun},scope:n.scope,...n.capability?{capability:n.capability}:{},waiting:[n.done],autoRetried:!1};i.set(o,u),B(o,u),e?(R.size||Promise.resolve().then(D),R.add(o),C.set(o,n.startedAt+b),m()):A(o,u,n.startedAt+b)},B=(n,e)=>{e.scope.addEventListener("abort",()=>{i.get(n)===e&&(h(n,e),m())},{once:!0})};return{press:L,submit:(n,e,o,s,c)=>new Promise(u=>L({captured:{record:n,kind:e,correlation:t.config.platform.ids()},cause:o,producer:o==="user"?"user":"automatic",scope:t.scope(),...e==="leave"?{capability:"plan-leave"}:{},ownRun:s,startedAt:_nullishCoalesce(c, () => (r.now())),done:u},c!==void 0)),status(n){let e=i.get(n);return e?new Promise(o=>{if(e.attempt){e.attempt.waiters.push(o);return}if(e.overlay.retryAt!==void 0&&_optionalChain([e, 'access', _8 => _8.overlay, 'access', _9 => _9.lastProblem, 'optionalAccess', _10 => _10.cause])==="rate-limited"&&r.now()<e.overlay.retryAt){t.report({code:"rate-limited",id:"intent",retryAfter:Math.ceil((e.overlay.retryAt-r.now())/1e3)}),o();return}e.waiting.push(o),A(n,e,r.now()+b)}):Promise.resolve()},authenticated(){for(let[n,e]of i)z(e)&&(e.autoRetried=!0,A(n,e,r.now()+b))},pending:n=>i.has(n),keepReview(n){let e=_optionalChain([n, 'optionalAccess', _11 => _11.recovery]),o=_optionalChain([e, 'optionalAccess', _12 => _12.phase]),s=t.client.getSnapshot().capabilities,c=s.includes("plan-keep")?!_optionalChain([e, 'optionalAccess', _13 => _13.executionId])||!s.includes("plan-recovery")?"keepNoDecision":e.sealed?"sealed":o==="forward-active"?"keepBlockedActive":(_nullishCoalesce(e.unknownCount, () => (0)))>0||o!=="readback"&&o!=="completed"&&o!=="left-known"?"keepBlockedUnknown":void 0:"capabilityMissing";if(c)return{disabled:c};let u=_nullishCoalesce(e.remaining, () => (0)),d={review:u>0?"forward-only":"end-retention",remaining:u,acknowledgment:F(n)};return K.set(d,{source:{record:n,kind:"keep",correlation:t.config.platform.ids()},scope:t.scope()}),d},keepChanges(n){let e=K.get(n);return e?new Promise(o=>L({captured:e.source,cause:"user",producer:"user",scope:e.scope,capability:"plan-keep",ownRun:!1,startedAt:r.now(),done:o})):(t.report({code:"unavailable",id:"plan-keep"}),Promise.resolve())}}}exports.answers = $; exports.buildIntent = G; exports.captureFrom = j; exports.createIntentMachine = Z; exports.semantic = E; exports.signInRetryAllowed = z;
@@ -0,0 +1,2 @@
1
+ export { C as CapturedIntent, I as IntentAlert, e as IntentContext, b as IntentFailure, f as IntentMachine, c as IntentNotice, d as IntentOverlay, g as IntentPress, h as IntentSource, K as KeepReviewResult, i as answers, j as buildIntent, k as captureFrom, l as createIntentMachine, s as semantic, m as signInRetryAllowed } from './intent-BQPPows1.cjs';
2
+ import './generated-C9tbjwK0.cjs';
@@ -0,0 +1,2 @@
1
+ export { C as CapturedIntent, I as IntentAlert, e as IntentContext, b as IntentFailure, f as IntentMachine, c as IntentNotice, d as IntentOverlay, g as IntentPress, h as IntentSource, K as KeepReviewResult, i as answers, j as buildIntent, k as captureFrom, l as createIntentMachine, s as semantic, m as signInRetryAllowed } from './intent-BuvqEU3Q.js';
2
+ import './generated-C9tbjwK0.js';
package/dist/intent.js ADDED
@@ -0,0 +1 @@
1
+ import{k as M}from"./chunk-L4PFFRDE.js";import{g as O}from"./chunk-T5XF2R74.js";import"./chunk-K73VV7KA.js";import"./chunk-5TBO732O.js";function F(t){let r=t.recovery;return{sourceDecisionKey:r.decisionKey,evidenceVersion:r.versions.evidence,winnerVersion:r.versions.winner,decisionResolutionVersion:r.versions.decisionResolution,evidenceDigest:r.evidenceDigest,unknownCount:r.unknownCount}}var b=1e4,U=["applied","replaced","already-closed","already-stopped","defeated","superseded","needs-review","conflict","unavailable","invalid-target","refused","kept","already-kept","sealed"];function j(t){let{record:r,kind:a}=t,i=r.recovery;return{kind:a,planId:r.id,target:a==="cancel-review"&&i.reviewId?{type:"review",id:i.reviewId}:i.executionId?{type:"execution",id:i.executionId}:{type:"generation",id:i.generation},capturedRound:i.round,expectedSlotVersion:i.slots[a],correlation:t.correlation,...a==="keep"?{review:(i.remaining??0)>0?"forward-only":"end-retention"}:{},...a==="leave"||a==="keep"?{acknowledgment:F(r)}:{}}}function G(t,r){return{...t,target:{...t.target},...t.acknowledgment?{acknowledgment:{...t.acknowledgment}}:{},cause:r}}function $(t,r){let a=t;return typeof a=="object"&&a!==null&&a.planId===r.planId&&a.kind===r.kind&&a.correlation===r.correlation&&a.capturedRound===r.capturedRound&&typeof a.slotVersion=="number"&&U.includes(a.result)&&Array.isArray(a.keys)&&a.keys.every(i=>typeof i=="string")}function z(t){return!t.attempt&&!t.autoRetried&&t.overlay.lastProblem?.cause==="sign-in"&&!t.scope.aborted}var V={stop:4,"cancel-initial":3,"cancel-review":3,keep:2,leave:1},_={stop:"stop","cancel-initial":"cancelInitial","cancel-review":"cancelReview",leave:"leave",keep:"keep"},E=t=>JSON.stringify([t.target,t.capturedRound,t.expectedSlotVersion,t.acknowledgment??null,t.review??null,t.payload??null]),J=(t,r)=>{let a=_[t.kind];return r==="timeout"&&t.delivery!=="not-sent"||r==="connection-lost"?`${a}Unconfirmed`:r==="forbidden"?`${a}Refused`:t.kind==="stop"&&!t.ownRun?"stopNotSentElsewhere":`${a}NotSent`},W={timeout:"checkStatus","connection-lost":"checkStatus",offline:"retry","sign-in":"signIn",forbidden:"hostGuidance","rate-limited":"wait"};function Z(t){let r=t.config.platform.clock,a=n=>t.client.getSnapshot().capabilities.includes(n),i=new Map,K=new WeakMap,x=0,S=0,I,P=new Map,m=()=>{let n={};for(let[e,o]of i)n[e]={...o.overlay};t.publish({intentOverlays:n})},f=n=>{for(let e of n.splice(0))e()},h=(n,e)=>{e.attempt&&(r.clearTimeout(e.attempt.timer),f(e.attempt.waiters),e.attempt=void 0),e.retryTimer!==void 0&&r.clearTimeout(e.retryTimer),f(e.waiting),i.get(n)===e&&i.delete(n)},q=n=>{I!==n&&(I=n,t.publish({intentAlert:{serial:++S,action:W[n]}}))},T=(n,e)=>{P.get(n)?.();let[o,s,c]=t.read(n),u=r.now()+b,d=!1,k=()=>{d=!0,r.clearTimeout(p),P.get(n)===y&&P.delete(n)},y=()=>{d||(k(),o.abort())},v=()=>{if(d)return;let l=!e.aborted&&!o.signal.aborted;k(),o.abort(),l&&t.report({code:"unavailable",id:"plan-read"})},p=r.setTimeout(v,b);O(e,y),O(o.signal,y),P.set(n,y);let g=l=>{if(!d&&r.now()>=u&&v(),d)return c();k(),l(c())};s.then(l=>g(N=>N&&t.client.setPlan(l)),l=>g(N=>N&&!e.aborted&&t.report(M(l,"plan-read"))))},w=(n,e,o)=>{let s={...n.overlay,delivery:o};n.overlay={...s,lastProblem:{key:J(s,e),cause:e}},q(e),m()},A=(n,e,o)=>{let s=e.waiting.splice(0);if(e.scope.aborted){f(s),h(n,e),m();return}if(e.capability&&!a(e.capability)){t.report({code:"unavailable",id:e.capability}),f(s),h(n,e),m();return}e.overlay={...e.overlay,delivery:"sending"};let c=r.now()>=o;if(c||!t.config.platform.online()){w(e,c?"timeout":"offline","not-sent"),f(s);return}let d={id:++x,timer:void 0,waiters:s};e.attempt=d,m();let k=()=>{v(),w(e,"timeout","uncertain"),T(n,e.scope),f(s)},y=()=>e.attempt!==d||i.get(n)!==e?!1:r.now()<o?!0:(k(),!1),v=()=>{r.clearTimeout(d.timer),e.attempt=void 0};d.timer=r.setTimeout(()=>{e.attempt===d&&i.get(n)===e&&k()},o-r.now()),t.config.plans.intent(e.overlay.request).then(p=>{if(y()){if(v(),$(p,e.overlay.request)){let{slotVersion:g,...l}=p;i.delete(n),I!==void 0&&(I=void 0,t.publish({intentAlert:{serial:S,restoreFocus:!0}})),t.publish({intentNotice:{...l,resolvedSlotVersion:g}}),m()}else w(e,"connection-lost","uncertain");T(n,e.scope),f(s)}},p=>{if(!y())return;v();let g=typeof p=="object"&&p?p.status:void 0;if(g===401)w(e,"sign-in","not-sent"),t.report({code:"sign-in",id:"intent"});else if(g===403)w(e,"forbidden","not-sent");else if(g===429){let l=Number.isInteger(p.retryAfter)&&p.retryAfter>=0?p.retryAfter:1;e.overlay={...e.overlay,retryAt:r.now()+l*1e3},w(e,"rate-limited","not-sent"),e.retryTimer=r.setTimeout(()=>{e.retryTimer=void 0,i.get(n)===e&&I==="rate-limited"&&t.publish({intentAlert:{serial:S,action:"retry"}})},l*1e3)}else w(e,"connection-lost","uncertain"),T(n,e.scope);f(s)})},R=new Set,C=new Map,D=()=>{for(let n of R){let e=i.get(n);e&&!e.attempt&&A(n,e,C.get(n)??r.now()+b)}R.clear(),C.clear()},L=(n,e=!1)=>{let o=n.captured.record.id;if(n.scope.aborted)return n.done();if(n.capability&&!a(n.capability))return t.report({code:"unavailable",id:n.capability}),n.done();let s=G(j(n.captured),n.cause),c=i.get(o);if(c&&c.overlay.kind===s.kind){if(E(c.overlay.request)!==E(s))return t.report({code:"refused",id:"intentPending"}),n.done();c.attempt?c.attempt.waiters.push(n.done):R.has(o)?c.waiting.push(n.done):n.done();return}if(c&&V[s.kind]<=V[c.overlay.kind])return t.report({code:"refused",id:"intentPending"}),n.done();c&&h(o,c);let u={overlay:{planId:o,kind:s.kind,request:s,producer:n.producer,delivery:"sending",ownRun:n.ownRun},scope:n.scope,...n.capability?{capability:n.capability}:{},waiting:[n.done],autoRetried:!1};i.set(o,u),B(o,u),e?(R.size||Promise.resolve().then(D),R.add(o),C.set(o,n.startedAt+b),m()):A(o,u,n.startedAt+b)},B=(n,e)=>{e.scope.addEventListener("abort",()=>{i.get(n)===e&&(h(n,e),m())},{once:!0})};return{press:L,submit:(n,e,o,s,c)=>new Promise(u=>L({captured:{record:n,kind:e,correlation:t.config.platform.ids()},cause:o,producer:o==="user"?"user":"automatic",scope:t.scope(),...e==="leave"?{capability:"plan-leave"}:{},ownRun:s,startedAt:c??r.now(),done:u},c!==void 0)),status(n){let e=i.get(n);return e?new Promise(o=>{if(e.attempt){e.attempt.waiters.push(o);return}if(e.overlay.retryAt!==void 0&&e.overlay.lastProblem?.cause==="rate-limited"&&r.now()<e.overlay.retryAt){t.report({code:"rate-limited",id:"intent",retryAfter:Math.ceil((e.overlay.retryAt-r.now())/1e3)}),o();return}e.waiting.push(o),A(n,e,r.now()+b)}):Promise.resolve()},authenticated(){for(let[n,e]of i)z(e)&&(e.autoRetried=!0,A(n,e,r.now()+b))},pending:n=>i.has(n),keepReview(n){let e=n?.recovery,o=e?.phase,s=t.client.getSnapshot().capabilities,c=s.includes("plan-keep")?!e?.executionId||!s.includes("plan-recovery")?"keepNoDecision":e.sealed?"sealed":o==="forward-active"?"keepBlockedActive":(e.unknownCount??0)>0||o!=="readback"&&o!=="completed"&&o!=="left-known"?"keepBlockedUnknown":void 0:"capabilityMissing";if(c)return{disabled:c};let u=e.remaining??0,d={review:u>0?"forward-only":"end-retention",remaining:u,acknowledgment:F(n)};return K.set(d,{source:{record:n,kind:"keep",correlation:t.config.platform.ids()},scope:t.scope()}),d},keepChanges(n){let e=K.get(n);return e?new Promise(o=>L({captured:e.source,cause:"user",producer:"user",scope:e.scope,capability:"plan-keep",ownRun:!1,startedAt:r.now(),done:o})):(t.report({code:"unavailable",id:"plan-keep"}),Promise.resolve())}}}export{$ as answers,G as buildIntent,j as captureFrom,Z as createIntentMachine,E as semantic,z as signInRetryAllowed};