@roll-agent/relay-client 0.2.2 → 0.3.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.
package/README.md CHANGED
@@ -103,3 +103,7 @@ error.
103
103
  `@roll-agent/relay-client/testing` exports `createRelayClientForTesting()` and the minimal WebSocket
104
104
  and scheduler interfaces. Inject a deterministic transport without adding Node APIs to production
105
105
  Browser code.
106
+
107
+ ### Context recovery and Wire 1.3
108
+
109
+ `RelayThreadView.contextRecovery` carries the latest bounded recovery gate state from snapshots and `context.recovery.changed` events. It is `null` for older peers. The default session advertisement remains `["1.2", "1.1"]` for existing Relay services with strict version allowlists. After upgrading the Relay service and Companion together, pass `relayProtocolVersions: ["1.3", "1.2", "1.1"]` to `createRelayClient`. Companion's bridge accepts `protocolVersion: "1.3"`; the Core host session factory accepts `relayProtocolVersion: "1.3"`. The deployed Relay service must support 1.3 ticket negotiation and routing before enabling either option.
package/dist/client.d.ts CHANGED
@@ -1,17 +1,17 @@
1
- import { relayRequestMethodSchemasV12, type RelayInteractionRequestV11, type RelayRequestParamsForVersion, type RelayRequestResultForVersion } from "@roll-agent/relay-protocol";
1
+ import { relayRequestMethodSchemasV13, type RelayInteractionRequestV11, type RelayRequestParamsForVersion, type RelayRequestResultForVersion } from "@roll-agent/relay-protocol";
2
2
  import { z } from "zod/v4";
3
3
  import { type RelayClientErrorDetails, type RelayConnectionState, type RelayThreadView } from "./schemas.ts";
4
4
  import { type RelayClientRuntimeDependencies } from "./transport.ts";
5
- type ThreadListWireInput = z.input<(typeof relayRequestMethodSchemasV12)["thread.list"]["params"]>;
6
- type ThreadCreateWireInput = z.input<(typeof relayRequestMethodSchemasV12)["thread.create"]["params"]>;
7
- type ThreadListWireResult = RelayRequestResultForVersion<"1.2", "thread.list">;
8
- type ThreadOpenWireResult = RelayRequestResultForVersion<"1.2", "thread.open">;
9
- type ThreadSnapshotWireResult = RelayRequestResultForVersion<"1.2", "thread.snapshot">;
10
- type TurnStartWireResult = RelayRequestResultForVersion<"1.2", "turn.start">;
11
- type TurnCancelWireResult = RelayRequestResultForVersion<"1.2", "turn.cancel">;
12
- type InteractionCandidateWireResult = RelayRequestResultForVersion<"1.2", "interaction.candidate">;
13
- export type RelayOperationResult = RelayRequestResultForVersion<"1.2", "operation.result.get">;
14
- export type RelayThreadCapabilities = RelayRequestResultForVersion<"1.2", "thread.capabilities">;
5
+ type ThreadListWireInput = z.input<(typeof relayRequestMethodSchemasV13)["thread.list"]["params"]>;
6
+ type ThreadCreateWireInput = z.input<(typeof relayRequestMethodSchemasV13)["thread.create"]["params"]>;
7
+ type ThreadListWireResult = RelayRequestResultForVersion<"1.3", "thread.list">;
8
+ type ThreadOpenWireResult = RelayRequestResultForVersion<"1.3", "thread.open"> | RelayRequestResultForVersion<"1.2", "thread.open">;
9
+ type ThreadSnapshotWireResult = RelayRequestResultForVersion<"1.3", "thread.snapshot"> | RelayRequestResultForVersion<"1.2", "thread.snapshot">;
10
+ type TurnStartWireResult = RelayRequestResultForVersion<"1.3", "turn.start">;
11
+ type TurnCancelWireResult = RelayRequestResultForVersion<"1.3", "turn.cancel">;
12
+ type InteractionCandidateWireResult = RelayRequestResultForVersion<"1.3", "interaction.candidate">;
13
+ export type RelayOperationResult = RelayRequestResultForVersion<"1.3", "operation.result.get">;
14
+ export type RelayThreadCapabilities = RelayRequestResultForVersion<"1.3", "thread.capabilities">;
15
15
  export type RelayThreadId = ThreadOpenWireResult["thread"]["id"];
16
16
  export type RelayTurnId = RelayRequestParamsForVersion<"1.2", "turn.cancel">["turnId"];
17
17
  export type RelayInteractionId = RelayInteractionRequestV11["interactionId"];
@@ -27,7 +27,7 @@ export type RelayTurnCancelResult = TurnCancelWireResult;
27
27
  export type RelayInteractionCandidateResult = InteractionCandidateWireResult;
28
28
  export interface RelaySessionProviderInput {
29
29
  readonly signal: AbortSignal;
30
- readonly supportedRelayProtocolVersions: readonly ["1.2", "1.1"];
30
+ readonly supportedRelayProtocolVersions: readonly ("1.3" | "1.2" | "1.1")[];
31
31
  }
32
32
  export type RelaySessionProvider = (input: RelaySessionProviderInput) => Promise<unknown>;
33
33
  export interface RelayRequestOptions {
@@ -36,6 +36,8 @@ export interface RelayRequestOptions {
36
36
  }
37
37
  export interface CreateRelayClientOptions {
38
38
  readonly getSession: RelaySessionProvider;
39
+ /** Opt into 1.3 only after the Relay service and Companion support it. */
40
+ readonly relayProtocolVersions?: readonly ("1.3" | "1.2" | "1.1")[];
39
41
  readonly requestTimeoutMs?: number;
40
42
  }
41
43
  export type RelayConnectionListener = (state: RelayConnectionState) => void;
package/dist/client.js CHANGED
@@ -1 +1 @@
1
- import{RELAY_ERROR_CODES_V11 as e,RELAY_MESSAGE_TYPES_V11 as t,RELAY_REQUEST_METHODS_V11 as s,RELAY_REQUEST_METHOD_DISPOSITIONS_V12 as n,parseRelayInteractionCandidateForRequestV11 as i,parseRelayRequestParamsForVersion as r,parseRelayRequestResultForVersion as o,relayAckSchemaV11 as a,relayMessageSchemaV12 as c,relayRequestIdSchema as l,relayRequestMethodSchemasV12 as d,relayRuntimeRequestSchemaV12 as h}from"@roll-agent/relay-protocol";import{parseRelayBrowserFirstControlFrameAny as u,relayBrowserControlMessageSchemaAny as p,relaySessionDescriptorSchema as y}from"@roll-agent/relay-protocol/control";import{z as m}from"zod/v4";import{RELAY_CLIENT_TRANSPORT_ERROR_CODES as f,getPendingInteractionRequest as g,relayClientErrorDetailsSchema as v,relayConnectionStateSchema as w,relayThreadViewSchema as R}from"./schemas.js";import{browserRelayRuntimeDependencies as S}from"./transport.js";export class RelayClientError extends Error{details;constructor(e){super(e.message),this.name="RelayClientError",this.details=v.parse(e)}}const b=3e4,I=1,q=-1,k={normal:1e3,invalidFrame:4002,sessionFatal:4008,sessionRetryable:4012},C=new Set(["completed","cancelled","failed"]);function T(e,t,s){return new RelayClientError({kind:"transport",code:e,message:t,retryable:s})}function E(e){return e instanceof RelayClientError?e:T(f.transportError,e instanceof Error?e.message:"Relay transport failed",!0)}function P(e,t){try{e(t)}catch(e){if("function"==typeof globalThis.reportError)try{globalThis.reportError(e)}catch{}}}function M(e){if("string"!=typeof e)throw T(f.protocolError,"Relay sent a non-text frame",!1);try{return JSON.parse(e)}catch{throw T(f.protocolError,"Relay sent invalid JSON",!1)}}function A(e){try{return u(e)}catch{throw T(f.protocolError,"Relay first frame must be Control 1.0 session.ready for Wire 1.1",!1)}}function B(e){const t=e.activeTurn;return void 0===t?{status:"idle"}:"cancelling"===t.status?{status:"cancelling",turnId:t.id}:{status:"running",turnId:t.id}}function O(e,t){const s=e.findIndex(e=>e.streamId===t.streamId);return-1===s?[...e,t]:e.map((e,n)=>n===s?t:e)}function x(e,t){return{status:e,interactionId:t.interactionId,threadId:t.threadId,turnId:t.turnId,method:t.method}}class RelayThreadImpl{id;#e;#t=new Set;#s;constructor(e,t){this.#e=e,this.id=t,this.#s=R.parse({status:"loading",threadId:t,snapshot:null,liveAssistantMessages:[],interactions:[],turn:{status:"idle"}})}getSnapshot(){return this.#s}subscribe(e){return this.#t.add(e),P(e,this.#s),()=>{this.#t.delete(e)}}async send(e,t){const s=await this.#e.startTurn(this.id,e,t);return this.#n({status:"running",turnId:s.turnId}),s}async cancel(e,t){const s=await this.#e.cancelTurn(this.id,e,t);return s.cancelling&&this.#n({status:"cancelling",turnId:e}),s}async respond(e,t,s){const n=this.#s.interactions.find(t=>{const s=g(t);return s?.interactionId===e}),i=void 0===n?void 0:g(n);if(void 0===i)throw T(f.connectionUnavailable,"Interaction is no longer pending in this Browser session",!1);this.#i(e,"responding");try{return await this.#e.respondToInteraction(i,t,s)}catch(t){throw this.#i(e,"pending"),t}}getResult(e,t){return this.#e.getOperationResult(this.id,e,t)}capabilities(e){return this.#e.getThreadCapabilities(this.id,e)}async refresh(e){try{const t=await this.#e.getThreadSnapshot(this.id,e);return this.applySnapshot(t),t}catch(e){throw this.applyError(E(e).details),e}}applySnapshot(e){this.#r({status:"ready",threadId:this.id,snapshot:e,liveAssistantMessages:[],interactions:this.#s.interactions,turn:B(e)})}applyError(e){this.#r({status:"error",threadId:this.id,snapshot:this.#s.snapshot,liveAssistantMessages:this.#s.liveAssistantMessages,interactions:this.#s.interactions,turn:this.#s.turn,error:e})}applyRuntimeEvent(e){const t=e.event,s=t.event,n=t.turnId;let i=this.#s.liveAssistantMessages,r=this.#s.turn;if("message.started"===s.type)i=O(i,{status:"streaming",streamId:s.streamId,text:""});else if("message.delta"===s.type){const e=i.find(e=>e.streamId===s.streamId);i=O(i,{status:"streaming",streamId:s.streamId,text:`${e?.text??""}${s.delta}`})}else"message.completed"===s.type?i=O(i,{status:"completed",streamId:s.streamId,text:s.text}):"turn.started"===s.type&&void 0!==n?r={status:"running",turnId:n}:"turn.completed"===s.type&&void 0!==n?r={status:"completed",turnId:n}:"turn.cancelled"===s.type&&void 0!==n?r={status:"cancelled",turnId:n}:"turn.failed"===s.type&&void 0!==n&&(r={status:"failed",turnId:n,stage:s.stage});this.#o({liveAssistantMessages:i,turn:r}),"turn.completed"!==s.type&&"turn.cancelled"!==s.type&&"turn.failed"!==s.type||this.refresh().catch(()=>{})}applyInteractionRequest(e){const t=this.#s.interactions.findIndex(t=>{const s=g(t);return s?.interactionId===e.interactionId}),s={status:"pending",request:e},n=-1===t?[...this.#s.interactions,s]:this.#s.interactions.map((e,n)=>n===t?s:e);this.#o({interactions:n})}applyInteractionTerminal(e){const s=x(e.type===t.interactionResolved?"resolved":"cancelled",e),n=this.#s.interactions.findIndex(t=>{const s=g(t);return s?.interactionId===e.interactionId}),i=-1===n?[...this.#s.interactions,s]:this.#s.interactions.map((e,t)=>t===n?s:e);this.#o({interactions:i})}#n(e){const t=this.#s.turn;"idle"!==t.status&&t.turnId===e.turnId&&C.has(t.status)||this.#o({turn:e})}#i(e,t){const s=this.#s.interactions.map(s=>{const n=g(s);return n?.interactionId===e?{status:t,request:n}:s});this.#o({interactions:s})}#o(e){const t={threadId:this.id,snapshot:this.#s.snapshot,liveAssistantMessages:e.liveAssistantMessages??this.#s.liveAssistantMessages,interactions:e.interactions??this.#s.interactions,turn:e.turn??this.#s.turn};this.#r(null===this.#s.snapshot?{status:"loading",...t,snapshot:null}:{status:"ready",...t,snapshot:this.#s.snapshot})}#r(e){this.#s=R.parse(e);for(const e of this.#t)P(e,this.#s)}}export class RelayClientImpl{#a;#c;#l=new Set;#d=new Map;#h=new Map;#u=new Map;#p={status:"idle"};#y;#m;#f="1.1";#g=new Map;#v;#w;#R;#S=0;#b=!1;#I=!1;#q=q;#k=!1;#C=0;#T=!1;#E;constructor(e,t){if(this.#a=e,this.#c=t,this.#E=e.requestTimeoutMs??b,!Number.isFinite(this.#E)||this.#E<=0)throw new TypeError("requestTimeoutMs must be a positive finite number")}async connect(e){if("connected"===this.#p.status)return;if(this.#b)throw T(f.closed,"Relay client is closed",!1);this.#P();const t=this.#v;return void 0!==t?t:(this.#I=!1,this.#S=0,this.#M({status:"connecting",attempt:1}),this.#A(e?.signal,e?.timeoutMs).catch(e=>{const t=E(e);throw this.#b||this.#I||this.#M({status:"closed",reason:"session"===t.details.kind?"session":"transport"}),t}))}close(){this.#b||(this.#b=!0,this.#I=!0,this.#w?.abort(),this.#P(),this.#B("client closed"),this.#O(!0),this.#M({status:"closed",reason:"client"}))}getConnectionState(){return this.#p}subscribeConnection(e){return this.#l.add(e),P(e,this.#p),()=>{this.#l.delete(e)}}async listThreads(e={},t){return this.#x(s.threadList,e,t)}async createThread(e={},t){const n=await this.#x(s.threadCreate,{...e,requestId:this.#c.createUuid()},t),i=this.#F(n.thread.id);return await i.refresh(t).catch(()=>{}),i}async openThread(e,t){const n=await this.#x(s.threadOpen,{threadId:e},t),i=this.#F(e);return i.applySnapshot(n),i}async startTurn(e,t,n){return this.#x(s.turnStart,{requestId:this.#c.createUuid(),threadId:e,turnId:this.#c.createUuid(),input:{text:t}},n)}async cancelTurn(e,t,n){return this.#x(s.turnCancel,{requestId:this.#c.createUuid(),threadId:e,turnId:t},n)}async respondToInteraction(e,t,n){const r=i(e,t);return this.#x(s.interactionCandidate,r,n)}async getThreadCapabilities(e,t){return this.#x("thread.capabilities",{threadId:e},t)}getOperationResult(e,t,s){if("1.2"!==this.#f)return Promise.reject(T(f.protocolError,"App results require Relay Wire 1.2",!1));const n=`${this.#C}:${this.#m}:${e}:${t}`;if(void 0===s){const e=this.#g.get(n);if(e)return e}const i=this.#x("operation.result.get",{threadId:e,operationId:t},s);return void 0===s&&(this.#g.set(n,i),i.finally(()=>{this.#g.get(n)===i&&this.#g.delete(n)}).catch(()=>{})),i}async getThreadSnapshot(e,t){return this.#x(s.threadSnapshot,{threadId:e,limit:100},t)}async#W(e,t){const s=t??this.#E;if(!Number.isFinite(s)||s<=0)throw new TypeError("timeoutMs must be a positive finite number");const n=new AbortController;this.#w=n;let i=!1;const r=()=>{n.abort()};e?.addEventListener("abort",r,{once:!0}),!0===e?.aborted&&n.abort();const o=this.#c.scheduler.setTimer(()=>{i=!0,n.abort()},s),a=new Promise((e,t)=>{const s=()=>{t(T(i?f.requestTimeout:f.aborted,i?"Relay session connection timed out":"Relay session request was aborted",i)),this.#y?.close(k.normal,"session attempt cancelled")};n.signal.aborted?s():n.signal.addEventListener("abort",s,{once:!0})});try{await Promise.race([this.#j(n.signal),a])}finally{this.#c.scheduler.clearTimer(o),e?.removeEventListener("abort",r),this.#w===n&&(this.#w=void 0)}}async#j(e){try{let t;try{t=await this.#a.getSession({signal:e,supportedRelayProtocolVersions:["1.2","1.1"]})}catch(t){if(e.aborted)throw T(f.aborted,"Relay session request was aborted",!1);throw E(t)}if(e.aborted)throw T(f.aborted,"Relay session request was aborted",!1);const s=y.safeParse(t);if(!s.success)throw T(f.invalidSession,"Session endpoint returned an invalid Relay session",!1);if(Date.parse(s.data.expiresAt)<=this.#c.scheduler.now())throw T(f.invalidSession,"Session endpoint returned an expired Relay session",!1);this.#B("superseded relay session");const n=this.#c.createWebSocket(s.data.connectUrl);this.#y=n,await this.#L(n)}catch(e){throw E(e)}}#L(e){return new Promise((t,s)=>{const n={ready:!1,settled:!1},i=e=>{n.settled||(n.settled=!0,s(e))};e.setHandlers({onOpen:()=>{},onMessage:s=>{if(!n.ready||this.#y===e)try{const e=M(s);if(!n.ready){const s=A(e);if(void 0!==this.#m&&this.#m!==s.workspaceId)throw T(f.protocolError,"Relay session changed the bound Workspace",!1);return this.#m=s.workspaceId,this.#f=s.relayProtocolVersion,this.#g.clear(),n.ready=!0,n.settled=!0,this.#S=0,this.#T=!0,this.#M({status:"connected",workspaceStatus:s.workspaceStatus}),this.#U(),"online"===s.workspaceStatus&&this.#z(),void t()}this.#$(e)}catch(t){const s=E(t);n.ready?this.#V(s):i(s),e.close(k.invalidFrame,"invalid relay frame")}},onClose:()=>{const t=this.#y===e;t&&(this.#y=void 0),n.ready?t&&this.#N():i(T(f.transportError,"Relay connection closed before session.ready",!0))},onError:()=>{n.ready||i(T(f.transportError,"Relay WebSocket failed before session.ready",!0))}})})}#$(e){const t=p.safeParse(e);if(t.success)return void this.#G(t.data);const s=c.safeParse(e);if(!s.success)throw T(f.protocolError,"Relay sent an invalid Control 1.0 or Wire 1.1 frame",!1);this.#H(s.data)}#G(e){if("session.ready"===e.type)throw T(f.protocolError,"session.ready may only be the first frame",!1);if("workspace.status"===e.type){this.#D(e.workspaceId);const t=this.#p,s="connected"===t.status&&"offline"===t.workspaceStatus&&"online"===e.status;return this.#M({status:"connected",workspaceStatus:e.status}),s&&(this.#T=!0,this.#J()),void("online"===e.status&&this.#z())}const t=new RelayClientError({kind:"session",code:e.code,message:`Relay session failed: ${e.code}`,retryable:e.retryable});if(e.retryable)this.#y?.close(k.sessionRetryable,"retryable relay session error");else{this.#I=!0,this.#O(!0);for(const e of this.#d.values())e.applyError(t.details);this.#M({status:"closed",reason:"session"}),this.#y?.close(k.sessionFatal,"non-retryable relay session error")}}#H(e){if(e.type!==t.runtimeResponse){if(e.type===t.runtimeGap)return this.#D(e.workspaceId),this.#Q(e.throughRelaySequence),void this.#K(e.throughRelaySequence);if(e.type!==t.runtimeEvent&&e.type!==t.interactionRequest&&e.type!==t.interactionResolved&&e.type!==t.interactionCancelled)throw T(f.protocolError,`Relay sent disallowed Browser inbound frame: ${e.type}`,!1);this.#X({relaySequence:e.relaySequence,message:e})}else this.#Y(e)}#Y(t){this.#D(t.workspaceId);const s=this.#h.get(t.requestId);if(void 0!==s){if(void 0!==t.error){const n=t.error.code===e.remoteRequestDenied?"Remote request denied":t.error.message;return void this.#Z(s,new RelayClientError({kind:"remote",code:t.error.code,message:n,retryable:t.error.retryable}))}if(void 0!==t.result)try{const e=o(this.#f,s.method,t.result);this.#Z(s,void 0,e)}catch{this.#Z(s,T(f.protocolError,`Relay returned an invalid ${s.method} result`,!1))}else this.#Z(s,T(f.protocolError,"runtime.response contains neither result nor error",!1))}}#X(e){if(this.#D(e.message.workspaceId),this.#Q(e.relaySequence),e.relaySequence<=this.#q)this.#U();else if(this.#k)this.#u.set(e.relaySequence,e);else{if(e.relaySequence!==this.#q+1)return this.#u.set(e.relaySequence,e),void this.#K(e.relaySequence-1);this.#_(e.message),this.#q=e.relaySequence,this.#U()}}#_(e){const s=e.type===t.runtimeEvent?e.event.threadId:e.threadId,n=this.#F(s);e.type===t.runtimeEvent?n.applyRuntimeEvent(e):e.type===t.interactionRequest?n.applyInteractionRequest(e):n.applyInteractionTerminal(e)}#K(e){if(e<=this.#q)return void this.#U();if(this.#k)return;this.#k=!0;const t=e,s=this.#C,n=[...this.#d.values()].map(async e=>e.refresh());Promise.all(n).then(()=>{if(this.#C===s){this.#q=t;for(const e of[...this.#u.keys()])e<=t&&this.#u.delete(e);this.#k=!1,this.#U(),this.#ee()}}).catch(()=>{this.#C===s&&(this.#k=!1,this.#y?.close(k.sessionRetryable,"snapshot recovery failed"))})}#Q(e){this.#T&&(this.#T=!1,e>this.#q||(this.#C+=1,this.#q=q,this.#u.clear(),this.#k=!1,this.#J()))}#J(){for(const e of this.#d.values())e.refresh().catch(()=>{})}#ee(){for(;!this.#k;){const e=this.#q+1,t=this.#u.get(e);if(void 0===t){const t=[...this.#u.keys()].sort((e,t)=>e-t)[0];return void(void 0!==t&&t>e&&this.#K(t-1))}this.#u.delete(e),this.#_(t.message),this.#q=e,this.#U()}}#U(){const e=this.#m,s=this.#y;if(void 0===e||1!==s?.readyState)return;const n=a.parse({type:t.runtimeAck,workspaceId:e,throughRelaySequence:this.#q});s.send(JSON.stringify(n))}#N(){this.#b||this.#I||(this.#te(),this.#se())}#se(){if(void 0!==this.#R||this.#b||this.#I)return;this.#S+=1;const e=this.#c.reconnectDelayMs(this.#S),t=new Date(this.#c.scheduler.now()+e).toISOString();this.#M({status:"reconnecting",attempt:this.#S,retryAt:t}),this.#R=this.#c.scheduler.setTimer(()=>{this.#R=void 0,this.#b||this.#I||void 0!==this.#v||"connected"===this.#p.status||this.#A().catch(e=>{if(this.#b)return;if(!E(e).details.retryable)return this.#I=!0,this.#O(!0),void this.#M({status:"closed",reason:"session"});this.#se()})},e)}#A(e,t){const s=this.#W(e,t).finally(()=>{this.#v===s&&(this.#v=void 0)});return this.#v=s,s}#B(e){const t=this.#y;void 0!==t&&(this.#y=void 0,t.close(k.normal,e))}#P(){void 0!==this.#R&&(this.#c.scheduler.clearTimer(this.#R),this.#R=void 0)}#z(){for(const e of this.#h.values())e.mutation&&this.#ne(e)}#x(e,s,i){if("connected"!==this.#p.status||"online"!==this.#p.workspaceStatus||void 0===this.#m){const e="connected"===this.#p.status&&"offline"===this.#p.workspaceStatus;return Promise.reject(T(e?f.workspaceOffline:f.connectionUnavailable,e?"The local Workspace is offline":"Relay is not connected",!0))}if(!0===i?.signal?.aborted)return Promise.reject(T(f.aborted,"Relay request was aborted",!1));const o=r("1.2",e,s),a=l.parse(this.#c.createUuid()),c=h.parse({type:t.runtimeRequest,requestId:a,workspaceId:this.#m,method:e,params:o}),d=i?.timeoutMs??this.#E;if(!Number.isFinite(d)||d<=0)return Promise.reject(new TypeError("timeoutMs must be a positive finite number"));const u="mutation"===n[e];return new Promise((t,s)=>{const n=i?.signal?()=>{const e=this.#h.get(a);if(void 0===e)return;const t=e.mutation&&e.sent;this.#Z(e,T(t?f.outcomeUnknown:f.aborted,t?"Mutation outcome is unknown after Browser cancellation":"Relay request was aborted",!1))}:void 0,r={requestId:a,method:e,frame:JSON.stringify(c),mutation:u,sent:!1,resolve:e=>{t(e)},reject:s,signal:i?.signal,abortListener:n,timeoutHandle:void 0};r.timeoutHandle=this.#c.scheduler.setTimer(()=>{const e=this.#h.get(a);if(void 0===e)return;const t=e.mutation&&e.sent;this.#Z(e,T(t?f.outcomeUnknown:f.requestTimeout,t?"Mutation outcome is unknown after Relay timeout":"Relay request timed out",!t))},d),i?.signal?.addEventListener("abort",n??(()=>{}),{once:!0}),this.#h.set(a,r),this.#ne(r)})}#ne(e){const t=this.#y;1===t?.readyState&&"connected"===this.#p.status&&"online"===this.#p.workspaceStatus&&(t.send(e.frame),e.sent=!0)}#Z(e,t,s){this.#h.delete(e.requestId)&&(void 0!==e.timeoutHandle&&this.#c.scheduler.clearTimer(e.timeoutHandle),void 0!==e.signal&&void 0!==e.abortListener&&e.signal.removeEventListener("abort",e.abortListener),void 0!==t?e.reject(t):e.resolve(s))}#te(){for(const e of[...this.#h.values()])e.mutation||this.#Z(e,T(f.transportError,"Relay disconnected before the query completed",!0))}#O(e){for(const t of[...this.#h.values()]){const s=e&&t.mutation&&t.sent;this.#Z(t,T(s?f.outcomeUnknown:f.closed,s?"Mutation outcome is unknown after Relay closed":"Relay client is closed",!1))}}#D(e){if(this.#m!==e)throw T(f.protocolError,"Relay frame does not match the bound Workspace",!1)}#F(e){const t=this.#d.get(e);if(void 0!==t)return t;const s=new RelayThreadImpl(this,e);return this.#d.set(e,s),s}#M(e){this.#p=w.parse(e);for(const e of this.#l)P(e,this.#p)}#V(e){this.#I=!0,this.#O(!0);for(const t of this.#d.values())t.applyError(e.details);this.#M({status:"closed",reason:"protocol"})}}export function createRelayClientWithRuntime(e,t){return new RelayClientImpl(e,t)}export function createRelayClient(e){return createRelayClientWithRuntime(e,S)}
1
+ import{RELAY_ERROR_CODES_V11 as e,RELAY_MESSAGE_TYPES_V11 as t,RELAY_REQUEST_METHODS_V11 as s,RELAY_REQUEST_METHOD_DISPOSITIONS_V12 as n,parseRelayInteractionCandidateForRequestV11 as i,parseRelayRequestParamsForVersion as r,parseRelayRequestResultForVersion as o,relayAckSchemaV11 as a,relayMessageSchemaV13 as c,relayRequestIdSchema as l,relayRequestMethodSchemasV13 as d,relayRuntimeRequestSchemaV12 as h}from"@roll-agent/relay-protocol";import{parseRelayBrowserFirstControlFrameAny as u,relayBrowserControlMessageSchemaAny as p,relaySessionDescriptorSchema as y}from"@roll-agent/relay-protocol/control";import{z as m}from"zod/v4";import{RELAY_CLIENT_TRANSPORT_ERROR_CODES as f,getPendingInteractionRequest as v,relayClientErrorDetailsSchema as g,relayConnectionStateSchema as w,relayThreadViewSchema as R}from"./schemas.js";import{browserRelayRuntimeDependencies as S}from"./transport.js";export class RelayClientError extends Error{details;constructor(e){super(e.message),this.name="RelayClientError",this.details=g.parse(e)}}const b=3e4,I=1,q=-1,k={normal:1e3,invalidFrame:4002,sessionFatal:4008,sessionRetryable:4012},C=new Set(["completed","cancelled","failed"]);function T(e,t,s){return new RelayClientError({kind:"transport",code:e,message:t,retryable:s})}function E(e){return e instanceof RelayClientError?e:T(f.transportError,e instanceof Error?e.message:"Relay transport failed",!0)}function P(e,t){try{e(t)}catch(e){if("function"==typeof globalThis.reportError)try{globalThis.reportError(e)}catch{}}}function M(e){if("string"!=typeof e)throw T(f.protocolError,"Relay sent a non-text frame",!1);try{return JSON.parse(e)}catch{throw T(f.protocolError,"Relay sent invalid JSON",!1)}}function A(e){try{return u(e)}catch{throw T(f.protocolError,"Relay first frame must be Control 1.0 session.ready for Wire 1.1",!1)}}function x(e){const t=e.activeTurn;return void 0===t?{status:"idle"}:"cancelling"===t.status?{status:"cancelling",turnId:t.id}:{status:"running",turnId:t.id}}function B(e,t){const s=e.findIndex(e=>e.streamId===t.streamId);return-1===s?[...e,t]:e.map((e,n)=>n===s?t:e)}function O(e,t){return{status:e,interactionId:t.interactionId,threadId:t.threadId,turnId:t.turnId,method:t.method}}class RelayThreadImpl{id;#e;#t=new Set;#s;constructor(e,t){this.#e=e,this.id=t,this.#s=R.parse({status:"loading",threadId:t,snapshot:null,liveAssistantMessages:[],interactions:[],turn:{status:"idle"}})}getSnapshot(){return this.#s}subscribe(e){return this.#t.add(e),P(e,this.#s),()=>{this.#t.delete(e)}}async send(e,t){const s=await this.#e.startTurn(this.id,e,t);return this.#n({status:"running",turnId:s.turnId}),s}async cancel(e,t){const s=await this.#e.cancelTurn(this.id,e,t);return s.cancelling&&this.#n({status:"cancelling",turnId:e}),s}async respond(e,t,s){const n=this.#s.interactions.find(t=>{const s=v(t);return s?.interactionId===e}),i=void 0===n?void 0:v(n);if(void 0===i)throw T(f.connectionUnavailable,"Interaction is no longer pending in this Browser session",!1);this.#i(e,"responding");try{return await this.#e.respondToInteraction(i,t,s)}catch(t){throw this.#i(e,"pending"),t}}getResult(e,t){return this.#e.getOperationResult(this.id,e,t)}capabilities(e){return this.#e.getThreadCapabilities(this.id,e)}async refresh(e){try{const t=await this.#e.getThreadSnapshot(this.id,e);return this.applySnapshot(t),t}catch(e){throw this.applyError(E(e).details),e}}applySnapshot(e){this.#r({status:"ready",threadId:this.id,snapshot:e,liveAssistantMessages:[],interactions:this.#s.interactions,turn:x(e),contextRecovery:"contextRecovery"in e?e.contextRecovery:null})}applyError(e){this.#r({status:"error",threadId:this.id,snapshot:this.#s.snapshot,liveAssistantMessages:this.#s.liveAssistantMessages,interactions:this.#s.interactions,turn:this.#s.turn,contextRecovery:this.#s.contextRecovery,error:e})}applyRuntimeEvent(e){const t=e.event,s=t.event,n=t.turnId;let i=this.#s.liveAssistantMessages,r=this.#s.turn;if("message.started"===s.type)i=B(i,{status:"streaming",streamId:s.streamId,text:""});else if("message.delta"===s.type){const e=i.find(e=>e.streamId===s.streamId);i=B(i,{status:"streaming",streamId:s.streamId,text:`${e?.text??""}${s.delta}`})}else"message.completed"===s.type?i=B(i,{status:"completed",streamId:s.streamId,text:s.text}):"turn.started"===s.type&&void 0!==n?r={status:"running",turnId:n}:"turn.completed"===s.type&&void 0!==n?r={status:"completed",turnId:n}:"turn.cancelled"===s.type&&void 0!==n?r={status:"cancelled",turnId:n}:"turn.failed"===s.type&&void 0!==n&&(r={status:"failed",turnId:n,stage:s.stage});this.#o({liveAssistantMessages:i,turn:r,..."context.recovery.changed"===s.type?{contextRecovery:s.contextRecovery}:{}}),"turn.completed"!==s.type&&"turn.cancelled"!==s.type&&"turn.failed"!==s.type||this.refresh().catch(()=>{})}applyInteractionRequest(e){const t=this.#s.interactions.findIndex(t=>{const s=v(t);return s?.interactionId===e.interactionId}),s={status:"pending",request:e},n=-1===t?[...this.#s.interactions,s]:this.#s.interactions.map((e,n)=>n===t?s:e);this.#o({interactions:n})}applyInteractionTerminal(e){const s=O(e.type===t.interactionResolved?"resolved":"cancelled",e),n=this.#s.interactions.findIndex(t=>{const s=v(t);return s?.interactionId===e.interactionId}),i=-1===n?[...this.#s.interactions,s]:this.#s.interactions.map((e,t)=>t===n?s:e);this.#o({interactions:i})}#n(e){const t=this.#s.turn;"idle"!==t.status&&t.turnId===e.turnId&&C.has(t.status)||this.#o({turn:e})}#i(e,t){const s=this.#s.interactions.map(s=>{const n=v(s);return n?.interactionId===e?{status:t,request:n}:s});this.#o({interactions:s})}#o(e){const t={threadId:this.id,snapshot:this.#s.snapshot,liveAssistantMessages:e.liveAssistantMessages??this.#s.liveAssistantMessages,interactions:e.interactions??this.#s.interactions,turn:e.turn??this.#s.turn,contextRecovery:void 0===e.contextRecovery?this.#s.contextRecovery:e.contextRecovery};this.#r(null===this.#s.snapshot?{status:"loading",...t,snapshot:null}:{status:"ready",...t,snapshot:this.#s.snapshot})}#r(e){this.#s=R.parse(e);for(const e of this.#t)P(e,this.#s)}}export class RelayClientImpl{#a;#c;#l=new Set;#d=new Map;#h=new Map;#u=new Map;#p={status:"idle"};#y;#m;#f="1.1";#v=new Map;#g;#w;#R;#S=0;#b=!1;#I=!1;#q=q;#k=!1;#C=0;#T=!1;#E;constructor(e,t){if(this.#a=e,this.#c=t,this.#E=e.requestTimeoutMs??b,!Number.isFinite(this.#E)||this.#E<=0)throw new TypeError("requestTimeoutMs must be a positive finite number")}async connect(e){if("connected"===this.#p.status)return;if(this.#b)throw T(f.closed,"Relay client is closed",!1);this.#P();const t=this.#g;return void 0!==t?t:(this.#I=!1,this.#S=0,this.#M({status:"connecting",attempt:1}),this.#A(e?.signal,e?.timeoutMs).catch(e=>{const t=E(e);throw this.#b||this.#I||this.#M({status:"closed",reason:"session"===t.details.kind?"session":"transport"}),t}))}close(){this.#b||(this.#b=!0,this.#I=!0,this.#w?.abort(),this.#P(),this.#x("client closed"),this.#B(!0),this.#M({status:"closed",reason:"client"}))}getConnectionState(){return this.#p}subscribeConnection(e){return this.#l.add(e),P(e,this.#p),()=>{this.#l.delete(e)}}async listThreads(e={},t){return this.#O(s.threadList,e,t)}async createThread(e={},t){const n=await this.#O(s.threadCreate,{...e,requestId:this.#c.createUuid()},t),i=this.#F(n.thread.id);return await i.refresh(t).catch(()=>{}),i}async openThread(e,t){const n=await this.#O(s.threadOpen,{threadId:e},t),i=this.#F(e);return i.applySnapshot(n),i}async startTurn(e,t,n){return this.#O(s.turnStart,{requestId:this.#c.createUuid(),threadId:e,turnId:this.#c.createUuid(),input:{text:t}},n)}async cancelTurn(e,t,n){return this.#O(s.turnCancel,{requestId:this.#c.createUuid(),threadId:e,turnId:t},n)}async respondToInteraction(e,t,n){const r=i(e,t);return this.#O(s.interactionCandidate,r,n)}async getThreadCapabilities(e,t){return this.#O("thread.capabilities",{threadId:e},t)}getOperationResult(e,t,s){if("1.1"===this.#f)return Promise.reject(T(f.protocolError,"App results require Relay Wire 1.2",!1));const n=`${this.#C}:${this.#m}:${e}:${t}`;if(void 0===s){const e=this.#v.get(n);if(e)return e}const i=this.#O("operation.result.get",{threadId:e,operationId:t},s);return void 0===s&&(this.#v.set(n,i),i.finally(()=>{this.#v.get(n)===i&&this.#v.delete(n)}).catch(()=>{})),i}async getThreadSnapshot(e,t){return this.#O(s.threadSnapshot,{threadId:e,limit:100},t)}async#W(e,t){const s=t??this.#E;if(!Number.isFinite(s)||s<=0)throw new TypeError("timeoutMs must be a positive finite number");const n=new AbortController;this.#w=n;let i=!1;const r=()=>{n.abort()};e?.addEventListener("abort",r,{once:!0}),!0===e?.aborted&&n.abort();const o=this.#c.scheduler.setTimer(()=>{i=!0,n.abort()},s),a=new Promise((e,t)=>{const s=()=>{t(T(i?f.requestTimeout:f.aborted,i?"Relay session connection timed out":"Relay session request was aborted",i)),this.#y?.close(k.normal,"session attempt cancelled")};n.signal.aborted?s():n.signal.addEventListener("abort",s,{once:!0})});try{await Promise.race([this.#j(n.signal),a])}finally{this.#c.scheduler.clearTimer(o),e?.removeEventListener("abort",r),this.#w===n&&(this.#w=void 0)}}async#j(e){try{let t;try{t=await this.#a.getSession({signal:e,supportedRelayProtocolVersions:this.#a.relayProtocolVersions??["1.2","1.1"]})}catch(t){if(e.aborted)throw T(f.aborted,"Relay session request was aborted",!1);throw E(t)}if(e.aborted)throw T(f.aborted,"Relay session request was aborted",!1);const s=y.safeParse(t);if(!s.success)throw T(f.invalidSession,"Session endpoint returned an invalid Relay session",!1);if(Date.parse(s.data.expiresAt)<=this.#c.scheduler.now())throw T(f.invalidSession,"Session endpoint returned an expired Relay session",!1);this.#x("superseded relay session");const n=this.#c.createWebSocket(s.data.connectUrl);this.#y=n,await this.#L(n)}catch(e){throw E(e)}}#L(e){return new Promise((t,s)=>{const n={ready:!1,settled:!1},i=e=>{n.settled||(n.settled=!0,s(e))};e.setHandlers({onOpen:()=>{},onMessage:s=>{if(!n.ready||this.#y===e)try{const e=M(s);if(!n.ready){const s=A(e);if(void 0!==this.#m&&this.#m!==s.workspaceId)throw T(f.protocolError,"Relay session changed the bound Workspace",!1);return this.#m=s.workspaceId,this.#f=s.relayProtocolVersion,this.#v.clear(),n.ready=!0,n.settled=!0,this.#S=0,this.#T=!0,this.#M({status:"connected",workspaceStatus:s.workspaceStatus}),this.#U(),"online"===s.workspaceStatus&&this.#z(),void t()}this.#V(e)}catch(t){const s=E(t);n.ready?this.#$(s):i(s),e.close(k.invalidFrame,"invalid relay frame")}},onClose:()=>{const t=this.#y===e;t&&(this.#y=void 0),n.ready?t&&this.#N():i(T(f.transportError,"Relay connection closed before session.ready",!0))},onError:()=>{n.ready||i(T(f.transportError,"Relay WebSocket failed before session.ready",!0))}})})}#V(e){const t=p.safeParse(e);if(t.success)return void this.#G(t.data);const s=c.safeParse(e);if(!s.success)throw T(f.protocolError,"Relay sent an invalid Control 1.0 or Wire 1.1 frame",!1);this.#H(s.data)}#G(e){if("session.ready"===e.type)throw T(f.protocolError,"session.ready may only be the first frame",!1);if("workspace.status"===e.type){this.#D(e.workspaceId);const t=this.#p,s="connected"===t.status&&"offline"===t.workspaceStatus&&"online"===e.status;return this.#M({status:"connected",workspaceStatus:e.status}),s&&(this.#T=!0,this.#J()),void("online"===e.status&&this.#z())}const t=new RelayClientError({kind:"session",code:e.code,message:`Relay session failed: ${e.code}`,retryable:e.retryable});if(e.retryable)this.#y?.close(k.sessionRetryable,"retryable relay session error");else{this.#I=!0,this.#B(!0);for(const e of this.#d.values())e.applyError(t.details);this.#M({status:"closed",reason:"session"}),this.#y?.close(k.sessionFatal,"non-retryable relay session error")}}#H(e){if(e.type!==t.runtimeResponse){if(e.type===t.runtimeGap)return this.#D(e.workspaceId),this.#Q(e.throughRelaySequence),void this.#K(e.throughRelaySequence);if(e.type!==t.runtimeEvent&&e.type!==t.interactionRequest&&e.type!==t.interactionResolved&&e.type!==t.interactionCancelled)throw T(f.protocolError,`Relay sent disallowed Browser inbound frame: ${e.type}`,!1);this.#X({relaySequence:e.relaySequence,message:e})}else this.#Y(e)}#Y(t){this.#D(t.workspaceId);const s=this.#h.get(t.requestId);if(void 0!==s){if(void 0!==t.error){const n=t.error.code===e.remoteRequestDenied?"Remote request denied":t.error.message;return void this.#Z(s,new RelayClientError({kind:"remote",code:t.error.code,message:n,retryable:t.error.retryable}))}if(void 0!==t.result)try{const e=o(this.#f,s.method,t.result);this.#Z(s,void 0,e)}catch{this.#Z(s,T(f.protocolError,`Relay returned an invalid ${s.method} result`,!1))}else this.#Z(s,T(f.protocolError,"runtime.response contains neither result nor error",!1))}}#X(e){if(this.#D(e.message.workspaceId),this.#Q(e.relaySequence),e.relaySequence<=this.#q)this.#U();else if(this.#k)this.#u.set(e.relaySequence,e);else{if(e.relaySequence!==this.#q+1)return this.#u.set(e.relaySequence,e),void this.#K(e.relaySequence-1);this.#_(e.message),this.#q=e.relaySequence,this.#U()}}#_(e){const s=e.type===t.runtimeEvent?e.event.threadId:e.threadId,n=this.#F(s);e.type===t.runtimeEvent?n.applyRuntimeEvent(e):e.type===t.interactionRequest?n.applyInteractionRequest(e):n.applyInteractionTerminal(e)}#K(e){if(e<=this.#q)return void this.#U();if(this.#k)return;this.#k=!0;const t=e,s=this.#C,n=[...this.#d.values()].map(async e=>e.refresh());Promise.all(n).then(()=>{if(this.#C===s){this.#q=t;for(const e of[...this.#u.keys()])e<=t&&this.#u.delete(e);this.#k=!1,this.#U(),this.#ee()}}).catch(()=>{this.#C===s&&(this.#k=!1,this.#y?.close(k.sessionRetryable,"snapshot recovery failed"))})}#Q(e){this.#T&&(this.#T=!1,e>this.#q||(this.#C+=1,this.#q=q,this.#u.clear(),this.#k=!1,this.#J()))}#J(){for(const e of this.#d.values())e.refresh().catch(()=>{})}#ee(){for(;!this.#k;){const e=this.#q+1,t=this.#u.get(e);if(void 0===t){const t=[...this.#u.keys()].sort((e,t)=>e-t)[0];return void(void 0!==t&&t>e&&this.#K(t-1))}this.#u.delete(e),this.#_(t.message),this.#q=e,this.#U()}}#U(){const e=this.#m,s=this.#y;if(void 0===e||1!==s?.readyState)return;const n=a.parse({type:t.runtimeAck,workspaceId:e,throughRelaySequence:this.#q});s.send(JSON.stringify(n))}#N(){this.#b||this.#I||(this.#te(),this.#se())}#se(){if(void 0!==this.#R||this.#b||this.#I)return;this.#S+=1;const e=this.#c.reconnectDelayMs(this.#S),t=new Date(this.#c.scheduler.now()+e).toISOString();this.#M({status:"reconnecting",attempt:this.#S,retryAt:t}),this.#R=this.#c.scheduler.setTimer(()=>{this.#R=void 0,this.#b||this.#I||void 0!==this.#g||"connected"===this.#p.status||this.#A().catch(e=>{if(this.#b)return;if(!E(e).details.retryable)return this.#I=!0,this.#B(!0),void this.#M({status:"closed",reason:"session"});this.#se()})},e)}#A(e,t){const s=this.#W(e,t).finally(()=>{this.#g===s&&(this.#g=void 0)});return this.#g=s,s}#x(e){const t=this.#y;void 0!==t&&(this.#y=void 0,t.close(k.normal,e))}#P(){void 0!==this.#R&&(this.#c.scheduler.clearTimer(this.#R),this.#R=void 0)}#z(){for(const e of this.#h.values())e.mutation&&this.#ne(e)}#O(e,s,i){if("connected"!==this.#p.status||"online"!==this.#p.workspaceStatus||void 0===this.#m){const e="connected"===this.#p.status&&"offline"===this.#p.workspaceStatus;return Promise.reject(T(e?f.workspaceOffline:f.connectionUnavailable,e?"The local Workspace is offline":"Relay is not connected",!0))}if(!0===i?.signal?.aborted)return Promise.reject(T(f.aborted,"Relay request was aborted",!1));const o=r("1.2",e,s),a=l.parse(this.#c.createUuid()),c=h.parse({type:t.runtimeRequest,requestId:a,workspaceId:this.#m,method:e,params:o}),d=i?.timeoutMs??this.#E;if(!Number.isFinite(d)||d<=0)return Promise.reject(new TypeError("timeoutMs must be a positive finite number"));const u="mutation"===n[e];return new Promise((t,s)=>{const n=i?.signal?()=>{const e=this.#h.get(a);if(void 0===e)return;const t=e.mutation&&e.sent;this.#Z(e,T(t?f.outcomeUnknown:f.aborted,t?"Mutation outcome is unknown after Browser cancellation":"Relay request was aborted",!1))}:void 0,r={requestId:a,method:e,frame:JSON.stringify(c),mutation:u,sent:!1,resolve:e=>{t(e)},reject:s,signal:i?.signal,abortListener:n,timeoutHandle:void 0};r.timeoutHandle=this.#c.scheduler.setTimer(()=>{const e=this.#h.get(a);if(void 0===e)return;const t=e.mutation&&e.sent;this.#Z(e,T(t?f.outcomeUnknown:f.requestTimeout,t?"Mutation outcome is unknown after Relay timeout":"Relay request timed out",!t))},d),i?.signal?.addEventListener("abort",n??(()=>{}),{once:!0}),this.#h.set(a,r),this.#ne(r)})}#ne(e){const t=this.#y;1===t?.readyState&&"connected"===this.#p.status&&"online"===this.#p.workspaceStatus&&(t.send(e.frame),e.sent=!0)}#Z(e,t,s){this.#h.delete(e.requestId)&&(void 0!==e.timeoutHandle&&this.#c.scheduler.clearTimer(e.timeoutHandle),void 0!==e.signal&&void 0!==e.abortListener&&e.signal.removeEventListener("abort",e.abortListener),void 0!==t?e.reject(t):e.resolve(s))}#te(){for(const e of[...this.#h.values()])e.mutation||this.#Z(e,T(f.transportError,"Relay disconnected before the query completed",!0))}#B(e){for(const t of[...this.#h.values()]){const s=e&&t.mutation&&t.sent;this.#Z(t,T(s?f.outcomeUnknown:f.closed,s?"Mutation outcome is unknown after Relay closed":"Relay client is closed",!1))}}#D(e){if(this.#m!==e)throw T(f.protocolError,"Relay frame does not match the bound Workspace",!1)}#F(e){const t=this.#d.get(e);if(void 0!==t)return t;const s=new RelayThreadImpl(this,e);return this.#d.set(e,s),s}#M(e){this.#p=w.parse(e);for(const e of this.#l)P(e,this.#p)}#$(e){this.#I=!0,this.#B(!0);for(const t of this.#d.values())t.applyError(e.details);this.#M({status:"closed",reason:"protocol"})}}export function createRelayClientWithRuntime(e,t){return new RelayClientImpl(e,t)}export function createRelayClient(e){return createRelayClientWithRuntime(e,S)}
package/dist/schemas.d.ts CHANGED
@@ -30,7 +30,7 @@ export declare const relayConnectionStateSchema: z.ZodDiscriminatedUnion<[z.ZodR
30
30
  transport: "transport";
31
31
  protocol: "protocol";
32
32
  }>;
33
- }, z.core.$strict>>]>;
33
+ }, z.core.$strict>>], "status">;
34
34
  export declare const RELAY_CLIENT_TRANSPORT_ERROR_CODES: {
35
35
  readonly aborted: "ABORTED";
36
36
  readonly closed: "CLIENT_CLOSED";
@@ -85,7 +85,7 @@ export declare const relayClientErrorDetailsSchema: z.ZodDiscriminatedUnion<[z.Z
85
85
  message: z.ZodString;
86
86
  retryable: z.ZodBoolean;
87
87
  kind: z.ZodLiteral<"remote">;
88
- }, z.core.$strict>>]>;
88
+ }, z.core.$strict>>], "kind">;
89
89
  export declare const relayLiveAssistantMessageSchema: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
90
90
  status: z.ZodLiteral<"streaming">;
91
91
  streamId: z.ZodString;
@@ -94,22 +94,22 @@ export declare const relayLiveAssistantMessageSchema: z.ZodDiscriminatedUnion<[z
94
94
  status: z.ZodLiteral<"completed">;
95
95
  streamId: z.ZodString;
96
96
  text: z.ZodString;
97
- }, z.core.$strict>>]>;
97
+ }, z.core.$strict>>], "status">;
98
98
  export declare const relayInteractionStateSchema: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
99
99
  status: z.ZodLiteral<"pending">;
100
100
  request: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
101
101
  method: z.ZodLiteral<"approval.request">;
102
102
  projection: z.ZodReadonly<z.ZodObject<{
103
- approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId">;
103
+ approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId", "out">;
104
104
  agentName: z.ZodString;
105
105
  toolName: z.ZodString;
106
106
  explanation: z.ZodOptional<z.ZodString>;
107
107
  }, z.core.$strict>>;
108
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
108
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
109
109
  relaySequence: z.ZodNumber;
110
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
111
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
112
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
110
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
111
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
112
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
113
113
  expiresAt: z.ZodString;
114
114
  sensitivity: z.ZodLiteral<"normal">;
115
115
  type: z.ZodLiteral<"interaction.request">;
@@ -163,32 +163,32 @@ export declare const relayInteractionStateSchema: z.ZodDiscriminatedUnion<[z.Zod
163
163
  description: z.ZodOptional<z.ZodString>;
164
164
  required: z.ZodBoolean;
165
165
  type: z.ZodLiteral<"choice">;
166
- }, z.core.$strict>>]>>;
166
+ }, z.core.$strict>>], "type">>;
167
167
  }, z.core.$strict>>;
168
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
168
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
169
169
  relaySequence: z.ZodNumber;
170
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
171
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
172
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
170
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
171
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
172
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
173
173
  expiresAt: z.ZodString;
174
174
  sensitivity: z.ZodLiteral<"normal">;
175
175
  type: z.ZodLiteral<"interaction.request">;
176
- }, z.core.$strict>>]>;
176
+ }, z.core.$strict>>], "method">;
177
177
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
178
178
  status: z.ZodLiteral<"responding">;
179
179
  request: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
180
180
  method: z.ZodLiteral<"approval.request">;
181
181
  projection: z.ZodReadonly<z.ZodObject<{
182
- approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId">;
182
+ approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId", "out">;
183
183
  agentName: z.ZodString;
184
184
  toolName: z.ZodString;
185
185
  explanation: z.ZodOptional<z.ZodString>;
186
186
  }, z.core.$strict>>;
187
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
187
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
188
188
  relaySequence: z.ZodNumber;
189
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
190
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
191
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
189
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
190
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
191
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
192
192
  expiresAt: z.ZodString;
193
193
  sensitivity: z.ZodLiteral<"normal">;
194
194
  type: z.ZodLiteral<"interaction.request">;
@@ -242,56 +242,62 @@ export declare const relayInteractionStateSchema: z.ZodDiscriminatedUnion<[z.Zod
242
242
  description: z.ZodOptional<z.ZodString>;
243
243
  required: z.ZodBoolean;
244
244
  type: z.ZodLiteral<"choice">;
245
- }, z.core.$strict>>]>>;
245
+ }, z.core.$strict>>], "type">>;
246
246
  }, z.core.$strict>>;
247
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
247
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
248
248
  relaySequence: z.ZodNumber;
249
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
250
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
251
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
249
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
250
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
251
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
252
252
  expiresAt: z.ZodString;
253
253
  sensitivity: z.ZodLiteral<"normal">;
254
254
  type: z.ZodLiteral<"interaction.request">;
255
- }, z.core.$strict>>]>;
255
+ }, z.core.$strict>>], "method">;
256
256
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
257
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
258
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
259
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
257
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
258
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
259
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
260
260
  method: z.ZodUnion<[z.ZodLiteral<"approval.request">, z.ZodLiteral<"userInput.request">]>;
261
261
  status: z.ZodLiteral<"resolved">;
262
262
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
263
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
264
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
265
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
263
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
264
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
265
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
266
266
  method: z.ZodUnion<[z.ZodLiteral<"approval.request">, z.ZodLiteral<"userInput.request">]>;
267
267
  status: z.ZodLiteral<"cancelled">;
268
- }, z.core.$strict>>]>;
268
+ }, z.core.$strict>>], "status">;
269
269
  export declare const relayTurnStateSchema: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
270
270
  status: z.ZodLiteral<"idle">;
271
271
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
272
272
  status: z.ZodLiteral<"running">;
273
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
273
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
274
274
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
275
275
  status: z.ZodLiteral<"cancelling">;
276
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
276
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
277
277
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
278
278
  status: z.ZodLiteral<"completed">;
279
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
279
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
280
280
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
281
281
  status: z.ZodLiteral<"cancelled">;
282
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
282
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
283
283
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
284
284
  status: z.ZodLiteral<"failed">;
285
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
285
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
286
286
  stage: z.ZodEnum<{
287
287
  bootstrap: "bootstrap";
288
288
  plan: "plan";
289
289
  execute: "execute";
290
290
  }>;
291
- }, z.core.$strict>>]>;
291
+ }, z.core.$strict>>], "status">;
292
292
  export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
293
293
  snapshot: z.ZodNull;
294
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
294
+ contextRecovery: z.ZodDefault<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
295
+ checkpointId: z.ZodString;
296
+ required: z.ZodBoolean;
297
+ unextracted: z.ZodBoolean;
298
+ requiredItemCount: z.ZodNumber;
299
+ }, z.core.$strict>>>>;
300
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
295
301
  liveAssistantMessages: z.ZodReadonly<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
296
302
  status: z.ZodLiteral<"streaming">;
297
303
  streamId: z.ZodString;
@@ -300,22 +306,22 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
300
306
  status: z.ZodLiteral<"completed">;
301
307
  streamId: z.ZodString;
302
308
  text: z.ZodString;
303
- }, z.core.$strict>>]>>>;
309
+ }, z.core.$strict>>], "status">>>;
304
310
  interactions: z.ZodReadonly<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
305
311
  status: z.ZodLiteral<"pending">;
306
312
  request: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
307
313
  method: z.ZodLiteral<"approval.request">;
308
314
  projection: z.ZodReadonly<z.ZodObject<{
309
- approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId">;
315
+ approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId", "out">;
310
316
  agentName: z.ZodString;
311
317
  toolName: z.ZodString;
312
318
  explanation: z.ZodOptional<z.ZodString>;
313
319
  }, z.core.$strict>>;
314
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
320
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
315
321
  relaySequence: z.ZodNumber;
316
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
317
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
318
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
322
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
323
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
324
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
319
325
  expiresAt: z.ZodString;
320
326
  sensitivity: z.ZodLiteral<"normal">;
321
327
  type: z.ZodLiteral<"interaction.request">;
@@ -369,32 +375,32 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
369
375
  description: z.ZodOptional<z.ZodString>;
370
376
  required: z.ZodBoolean;
371
377
  type: z.ZodLiteral<"choice">;
372
- }, z.core.$strict>>]>>;
378
+ }, z.core.$strict>>], "type">>;
373
379
  }, z.core.$strict>>;
374
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
380
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
375
381
  relaySequence: z.ZodNumber;
376
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
377
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
378
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
382
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
383
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
384
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
379
385
  expiresAt: z.ZodString;
380
386
  sensitivity: z.ZodLiteral<"normal">;
381
387
  type: z.ZodLiteral<"interaction.request">;
382
- }, z.core.$strict>>]>;
388
+ }, z.core.$strict>>], "method">;
383
389
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
384
390
  status: z.ZodLiteral<"responding">;
385
391
  request: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
386
392
  method: z.ZodLiteral<"approval.request">;
387
393
  projection: z.ZodReadonly<z.ZodObject<{
388
- approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId">;
394
+ approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId", "out">;
389
395
  agentName: z.ZodString;
390
396
  toolName: z.ZodString;
391
397
  explanation: z.ZodOptional<z.ZodString>;
392
398
  }, z.core.$strict>>;
393
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
399
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
394
400
  relaySequence: z.ZodNumber;
395
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
396
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
397
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
401
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
402
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
403
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
398
404
  expiresAt: z.ZodString;
399
405
  sensitivity: z.ZodLiteral<"normal">;
400
406
  type: z.ZodLiteral<"interaction.request">;
@@ -448,58 +454,151 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
448
454
  description: z.ZodOptional<z.ZodString>;
449
455
  required: z.ZodBoolean;
450
456
  type: z.ZodLiteral<"choice">;
451
- }, z.core.$strict>>]>>;
457
+ }, z.core.$strict>>], "type">>;
452
458
  }, z.core.$strict>>;
453
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
459
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
454
460
  relaySequence: z.ZodNumber;
455
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
456
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
457
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
461
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
462
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
463
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
458
464
  expiresAt: z.ZodString;
459
465
  sensitivity: z.ZodLiteral<"normal">;
460
466
  type: z.ZodLiteral<"interaction.request">;
461
- }, z.core.$strict>>]>;
467
+ }, z.core.$strict>>], "method">;
462
468
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
463
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
464
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
465
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
469
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
470
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
471
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
466
472
  method: z.ZodUnion<[z.ZodLiteral<"approval.request">, z.ZodLiteral<"userInput.request">]>;
467
473
  status: z.ZodLiteral<"resolved">;
468
474
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
469
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
470
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
471
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
475
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
476
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
477
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
472
478
  method: z.ZodUnion<[z.ZodLiteral<"approval.request">, z.ZodLiteral<"userInput.request">]>;
473
479
  status: z.ZodLiteral<"cancelled">;
474
- }, z.core.$strict>>]>>>;
480
+ }, z.core.$strict>>], "status">>>;
475
481
  turn: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
476
482
  status: z.ZodLiteral<"idle">;
477
483
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
478
484
  status: z.ZodLiteral<"running">;
479
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
485
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
480
486
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
481
487
  status: z.ZodLiteral<"cancelling">;
482
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
488
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
483
489
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
484
490
  status: z.ZodLiteral<"completed">;
485
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
491
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
486
492
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
487
493
  status: z.ZodLiteral<"cancelled">;
488
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
494
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
489
495
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
490
496
  status: z.ZodLiteral<"failed">;
491
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
497
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
492
498
  stage: z.ZodEnum<{
493
499
  bootstrap: "bootstrap";
494
500
  plan: "plan";
495
501
  execute: "execute";
496
502
  }>;
497
- }, z.core.$strict>>]>;
503
+ }, z.core.$strict>>], "status">;
498
504
  status: z.ZodLiteral<"loading">;
499
505
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
500
- snapshot: z.ZodReadonly<z.ZodObject<{
506
+ snapshot: z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
507
+ thread: z.ZodReadonly<z.ZodObject<{
508
+ id: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
509
+ title: z.ZodOptional<z.ZodString>;
510
+ model: z.ZodOptional<z.ZodString>;
511
+ createdAt: z.ZodString;
512
+ updatedAt: z.ZodString;
513
+ messageCount: z.ZodNumber;
514
+ }, z.core.$strict>>;
515
+ messages: z.ZodReadonly<z.ZodObject<{
516
+ items: z.ZodArray<z.ZodReadonly<z.ZodObject<{
517
+ sequence: z.ZodNumber;
518
+ role: z.ZodEnum<{
519
+ user: "user";
520
+ assistant: "assistant";
521
+ }>;
522
+ createdAt: z.ZodString;
523
+ parts: z.ZodArray<z.ZodReadonly<z.ZodObject<{
524
+ type: z.ZodLiteral<"text">;
525
+ text: z.ZodString;
526
+ }, z.core.$strict>>>;
527
+ }, z.core.$strict>>>;
528
+ nextBeforeSequence: z.ZodNullable<z.ZodNumber>;
529
+ }, z.core.$strict>>;
530
+ activeTurn: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
531
+ id: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
532
+ status: z.ZodEnum<{
533
+ running: "running";
534
+ cancelling: "cancelling";
535
+ }>;
536
+ startedAt: z.ZodString;
537
+ }, z.core.$strict>>>;
538
+ pendingApprovals: z.ZodArray<z.ZodReadonly<z.ZodObject<{
539
+ id: z.core.$ZodBranded<z.ZodString, "ApprovalId", "out">;
540
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
541
+ agentName: z.ZodString;
542
+ toolName: z.ZodString;
543
+ preview: z.ZodJSONSchema;
544
+ reason: z.ZodOptional<z.ZodString>;
545
+ }, z.core.$strict>>>;
546
+ transcriptCompleteness: z.ZodEnum<{
547
+ complete: "complete";
548
+ legacy_snapshot: "legacy_snapshot";
549
+ }>;
550
+ operations: z.ZodReadonly<z.ZodObject<{
551
+ items: z.ZodArray<z.ZodReadonly<z.ZodObject<{
552
+ id: z.core.$ZodBranded<z.ZodString, "OperationId", "out">;
553
+ sequence: z.ZodNumber;
554
+ toolCallId: z.ZodString;
555
+ agentName: z.ZodString;
556
+ toolName: z.ZodString;
557
+ createdAt: z.ZodString;
558
+ outcome: z.ZodReadonly<z.ZodObject<{
559
+ kind: z.ZodEnum<{
560
+ success: "success";
561
+ user_rejected: "user_rejected";
562
+ policy_denied: "policy_denied";
563
+ invalid_input: "invalid_input";
564
+ cancelled: "cancelled";
565
+ tool_failed: "tool_failed";
566
+ }>;
567
+ reason: z.ZodOptional<z.ZodString>;
568
+ }, z.core.$strict>>;
569
+ display: z.ZodJSONSchema;
570
+ appOutput: z.ZodOptional<z.ZodReadonly<z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
571
+ status: z.ZodLiteral<"rejected">;
572
+ reason: z.ZodEnum<{
573
+ credential_field: "credential_field";
574
+ credential_value: "credential_value";
575
+ }>;
576
+ field: z.ZodOptional<z.ZodString>;
577
+ }, z.core.$strict>>, z.ZodObject<{
578
+ status: z.ZodLiteral<"available">;
579
+ schemaId: z.ZodString;
580
+ schemaVersion: z.ZodNumber;
581
+ }, z.core.$strict>, z.ZodObject<{
582
+ status: z.ZodEnum<{
583
+ not_provided: "not_provided";
584
+ invalid: "invalid";
585
+ too_large: "too_large";
586
+ expired: "expired";
587
+ denied: "denied";
588
+ }>;
589
+ }, z.core.$strict>], "status">>>;
590
+ }, z.core.$strict>>>;
591
+ nextBeforeSequence: z.ZodNullable<z.ZodNumber>;
592
+ }, z.core.$strict>>;
593
+ contextRecovery: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
594
+ checkpointId: z.ZodString;
595
+ required: z.ZodBoolean;
596
+ unextracted: z.ZodBoolean;
597
+ requiredItemCount: z.ZodNumber;
598
+ }, z.core.$strict>>>;
599
+ }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
501
600
  thread: z.ZodReadonly<z.ZodObject<{
502
- id: z.core.$ZodBranded<z.ZodString, "ThreadId">;
601
+ id: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
503
602
  title: z.ZodOptional<z.ZodString>;
504
603
  model: z.ZodOptional<z.ZodString>;
505
604
  createdAt: z.ZodString;
@@ -522,7 +621,7 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
522
621
  nextBeforeSequence: z.ZodNullable<z.ZodNumber>;
523
622
  }, z.core.$strict>>;
524
623
  activeTurn: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
525
- id: z.core.$ZodBranded<z.ZodString, "TurnId">;
624
+ id: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
526
625
  status: z.ZodEnum<{
527
626
  running: "running";
528
627
  cancelling: "cancelling";
@@ -530,8 +629,8 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
530
629
  startedAt: z.ZodString;
531
630
  }, z.core.$strict>>>;
532
631
  pendingApprovals: z.ZodArray<z.ZodReadonly<z.ZodObject<{
533
- id: z.core.$ZodBranded<z.ZodString, "ApprovalId">;
534
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
632
+ id: z.core.$ZodBranded<z.ZodString, "ApprovalId", "out">;
633
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
535
634
  agentName: z.ZodString;
536
635
  toolName: z.ZodString;
537
636
  preview: z.ZodJSONSchema;
@@ -543,7 +642,7 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
543
642
  }>;
544
643
  operations: z.ZodReadonly<z.ZodObject<{
545
644
  items: z.ZodArray<z.ZodReadonly<z.ZodObject<{
546
- id: z.core.$ZodBranded<z.ZodString, "OperationId">;
645
+ id: z.core.$ZodBranded<z.ZodString, "OperationId", "out">;
547
646
  sequence: z.ZodNumber;
548
647
  toolCallId: z.ZodString;
549
648
  agentName: z.ZodString;
@@ -580,12 +679,18 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
580
679
  expired: "expired";
581
680
  denied: "denied";
582
681
  }>;
583
- }, z.core.$strict>]>>>;
682
+ }, z.core.$strict>], "status">>>;
584
683
  }, z.core.$strict>>>;
585
684
  nextBeforeSequence: z.ZodNullable<z.ZodNumber>;
586
685
  }, z.core.$strict>>;
587
- }, z.core.$strict>>;
588
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
686
+ }, z.core.$strict>>]>;
687
+ contextRecovery: z.ZodDefault<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
688
+ checkpointId: z.ZodString;
689
+ required: z.ZodBoolean;
690
+ unextracted: z.ZodBoolean;
691
+ requiredItemCount: z.ZodNumber;
692
+ }, z.core.$strict>>>>;
693
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
589
694
  liveAssistantMessages: z.ZodReadonly<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
590
695
  status: z.ZodLiteral<"streaming">;
591
696
  streamId: z.ZodString;
@@ -594,22 +699,22 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
594
699
  status: z.ZodLiteral<"completed">;
595
700
  streamId: z.ZodString;
596
701
  text: z.ZodString;
597
- }, z.core.$strict>>]>>>;
702
+ }, z.core.$strict>>], "status">>>;
598
703
  interactions: z.ZodReadonly<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
599
704
  status: z.ZodLiteral<"pending">;
600
705
  request: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
601
706
  method: z.ZodLiteral<"approval.request">;
602
707
  projection: z.ZodReadonly<z.ZodObject<{
603
- approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId">;
708
+ approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId", "out">;
604
709
  agentName: z.ZodString;
605
710
  toolName: z.ZodString;
606
711
  explanation: z.ZodOptional<z.ZodString>;
607
712
  }, z.core.$strict>>;
608
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
713
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
609
714
  relaySequence: z.ZodNumber;
610
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
611
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
612
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
715
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
716
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
717
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
613
718
  expiresAt: z.ZodString;
614
719
  sensitivity: z.ZodLiteral<"normal">;
615
720
  type: z.ZodLiteral<"interaction.request">;
@@ -663,32 +768,32 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
663
768
  description: z.ZodOptional<z.ZodString>;
664
769
  required: z.ZodBoolean;
665
770
  type: z.ZodLiteral<"choice">;
666
- }, z.core.$strict>>]>>;
771
+ }, z.core.$strict>>], "type">>;
667
772
  }, z.core.$strict>>;
668
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
773
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
669
774
  relaySequence: z.ZodNumber;
670
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
671
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
672
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
775
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
776
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
777
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
673
778
  expiresAt: z.ZodString;
674
779
  sensitivity: z.ZodLiteral<"normal">;
675
780
  type: z.ZodLiteral<"interaction.request">;
676
- }, z.core.$strict>>]>;
781
+ }, z.core.$strict>>], "method">;
677
782
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
678
783
  status: z.ZodLiteral<"responding">;
679
784
  request: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
680
785
  method: z.ZodLiteral<"approval.request">;
681
786
  projection: z.ZodReadonly<z.ZodObject<{
682
- approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId">;
787
+ approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId", "out">;
683
788
  agentName: z.ZodString;
684
789
  toolName: z.ZodString;
685
790
  explanation: z.ZodOptional<z.ZodString>;
686
791
  }, z.core.$strict>>;
687
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
792
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
688
793
  relaySequence: z.ZodNumber;
689
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
690
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
691
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
794
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
795
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
796
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
692
797
  expiresAt: z.ZodString;
693
798
  sensitivity: z.ZodLiteral<"normal">;
694
799
  type: z.ZodLiteral<"interaction.request">;
@@ -742,58 +847,58 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
742
847
  description: z.ZodOptional<z.ZodString>;
743
848
  required: z.ZodBoolean;
744
849
  type: z.ZodLiteral<"choice">;
745
- }, z.core.$strict>>]>>;
850
+ }, z.core.$strict>>], "type">>;
746
851
  }, z.core.$strict>>;
747
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
852
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
748
853
  relaySequence: z.ZodNumber;
749
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
750
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
751
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
854
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
855
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
856
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
752
857
  expiresAt: z.ZodString;
753
858
  sensitivity: z.ZodLiteral<"normal">;
754
859
  type: z.ZodLiteral<"interaction.request">;
755
- }, z.core.$strict>>]>;
860
+ }, z.core.$strict>>], "method">;
756
861
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
757
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
758
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
759
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
862
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
863
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
864
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
760
865
  method: z.ZodUnion<[z.ZodLiteral<"approval.request">, z.ZodLiteral<"userInput.request">]>;
761
866
  status: z.ZodLiteral<"resolved">;
762
867
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
763
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
764
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
765
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
868
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
869
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
870
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
766
871
  method: z.ZodUnion<[z.ZodLiteral<"approval.request">, z.ZodLiteral<"userInput.request">]>;
767
872
  status: z.ZodLiteral<"cancelled">;
768
- }, z.core.$strict>>]>>>;
873
+ }, z.core.$strict>>], "status">>>;
769
874
  turn: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
770
875
  status: z.ZodLiteral<"idle">;
771
876
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
772
877
  status: z.ZodLiteral<"running">;
773
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
878
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
774
879
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
775
880
  status: z.ZodLiteral<"cancelling">;
776
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
881
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
777
882
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
778
883
  status: z.ZodLiteral<"completed">;
779
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
884
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
780
885
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
781
886
  status: z.ZodLiteral<"cancelled">;
782
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
887
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
783
888
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
784
889
  status: z.ZodLiteral<"failed">;
785
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
890
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
786
891
  stage: z.ZodEnum<{
787
892
  bootstrap: "bootstrap";
788
893
  plan: "plan";
789
894
  execute: "execute";
790
895
  }>;
791
- }, z.core.$strict>>]>;
896
+ }, z.core.$strict>>], "status">;
792
897
  status: z.ZodLiteral<"ready">;
793
898
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
794
- snapshot: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
899
+ snapshot: z.ZodNullable<z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
795
900
  thread: z.ZodReadonly<z.ZodObject<{
796
- id: z.core.$ZodBranded<z.ZodString, "ThreadId">;
901
+ id: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
797
902
  title: z.ZodOptional<z.ZodString>;
798
903
  model: z.ZodOptional<z.ZodString>;
799
904
  createdAt: z.ZodString;
@@ -816,7 +921,7 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
816
921
  nextBeforeSequence: z.ZodNullable<z.ZodNumber>;
817
922
  }, z.core.$strict>>;
818
923
  activeTurn: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
819
- id: z.core.$ZodBranded<z.ZodString, "TurnId">;
924
+ id: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
820
925
  status: z.ZodEnum<{
821
926
  running: "running";
822
927
  cancelling: "cancelling";
@@ -824,8 +929,8 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
824
929
  startedAt: z.ZodString;
825
930
  }, z.core.$strict>>>;
826
931
  pendingApprovals: z.ZodArray<z.ZodReadonly<z.ZodObject<{
827
- id: z.core.$ZodBranded<z.ZodString, "ApprovalId">;
828
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
932
+ id: z.core.$ZodBranded<z.ZodString, "ApprovalId", "out">;
933
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
829
934
  agentName: z.ZodString;
830
935
  toolName: z.ZodString;
831
936
  preview: z.ZodJSONSchema;
@@ -837,7 +942,7 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
837
942
  }>;
838
943
  operations: z.ZodReadonly<z.ZodObject<{
839
944
  items: z.ZodArray<z.ZodReadonly<z.ZodObject<{
840
- id: z.core.$ZodBranded<z.ZodString, "OperationId">;
945
+ id: z.core.$ZodBranded<z.ZodString, "OperationId", "out">;
841
946
  sequence: z.ZodNumber;
842
947
  toolCallId: z.ZodString;
843
948
  agentName: z.ZodString;
@@ -874,11 +979,104 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
874
979
  expired: "expired";
875
980
  denied: "denied";
876
981
  }>;
877
- }, z.core.$strict>]>>>;
982
+ }, z.core.$strict>], "status">>>;
878
983
  }, z.core.$strict>>>;
879
984
  nextBeforeSequence: z.ZodNullable<z.ZodNumber>;
880
985
  }, z.core.$strict>>;
881
- }, z.core.$strict>>>;
986
+ contextRecovery: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
987
+ checkpointId: z.ZodString;
988
+ required: z.ZodBoolean;
989
+ unextracted: z.ZodBoolean;
990
+ requiredItemCount: z.ZodNumber;
991
+ }, z.core.$strict>>>;
992
+ }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
993
+ thread: z.ZodReadonly<z.ZodObject<{
994
+ id: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
995
+ title: z.ZodOptional<z.ZodString>;
996
+ model: z.ZodOptional<z.ZodString>;
997
+ createdAt: z.ZodString;
998
+ updatedAt: z.ZodString;
999
+ messageCount: z.ZodNumber;
1000
+ }, z.core.$strict>>;
1001
+ messages: z.ZodReadonly<z.ZodObject<{
1002
+ items: z.ZodArray<z.ZodReadonly<z.ZodObject<{
1003
+ sequence: z.ZodNumber;
1004
+ role: z.ZodEnum<{
1005
+ user: "user";
1006
+ assistant: "assistant";
1007
+ }>;
1008
+ createdAt: z.ZodString;
1009
+ parts: z.ZodArray<z.ZodReadonly<z.ZodObject<{
1010
+ type: z.ZodLiteral<"text">;
1011
+ text: z.ZodString;
1012
+ }, z.core.$strict>>>;
1013
+ }, z.core.$strict>>>;
1014
+ nextBeforeSequence: z.ZodNullable<z.ZodNumber>;
1015
+ }, z.core.$strict>>;
1016
+ activeTurn: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
1017
+ id: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
1018
+ status: z.ZodEnum<{
1019
+ running: "running";
1020
+ cancelling: "cancelling";
1021
+ }>;
1022
+ startedAt: z.ZodString;
1023
+ }, z.core.$strict>>>;
1024
+ pendingApprovals: z.ZodArray<z.ZodReadonly<z.ZodObject<{
1025
+ id: z.core.$ZodBranded<z.ZodString, "ApprovalId", "out">;
1026
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
1027
+ agentName: z.ZodString;
1028
+ toolName: z.ZodString;
1029
+ preview: z.ZodJSONSchema;
1030
+ reason: z.ZodOptional<z.ZodString>;
1031
+ }, z.core.$strict>>>;
1032
+ transcriptCompleteness: z.ZodEnum<{
1033
+ complete: "complete";
1034
+ legacy_snapshot: "legacy_snapshot";
1035
+ }>;
1036
+ operations: z.ZodReadonly<z.ZodObject<{
1037
+ items: z.ZodArray<z.ZodReadonly<z.ZodObject<{
1038
+ id: z.core.$ZodBranded<z.ZodString, "OperationId", "out">;
1039
+ sequence: z.ZodNumber;
1040
+ toolCallId: z.ZodString;
1041
+ agentName: z.ZodString;
1042
+ toolName: z.ZodString;
1043
+ createdAt: z.ZodString;
1044
+ outcome: z.ZodReadonly<z.ZodObject<{
1045
+ kind: z.ZodEnum<{
1046
+ success: "success";
1047
+ user_rejected: "user_rejected";
1048
+ policy_denied: "policy_denied";
1049
+ invalid_input: "invalid_input";
1050
+ cancelled: "cancelled";
1051
+ tool_failed: "tool_failed";
1052
+ }>;
1053
+ reason: z.ZodOptional<z.ZodString>;
1054
+ }, z.core.$strict>>;
1055
+ display: z.ZodJSONSchema;
1056
+ appOutput: z.ZodOptional<z.ZodReadonly<z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
1057
+ status: z.ZodLiteral<"rejected">;
1058
+ reason: z.ZodEnum<{
1059
+ credential_field: "credential_field";
1060
+ credential_value: "credential_value";
1061
+ }>;
1062
+ field: z.ZodOptional<z.ZodString>;
1063
+ }, z.core.$strict>>, z.ZodObject<{
1064
+ status: z.ZodLiteral<"available">;
1065
+ schemaId: z.ZodString;
1066
+ schemaVersion: z.ZodNumber;
1067
+ }, z.core.$strict>, z.ZodObject<{
1068
+ status: z.ZodEnum<{
1069
+ not_provided: "not_provided";
1070
+ invalid: "invalid";
1071
+ too_large: "too_large";
1072
+ expired: "expired";
1073
+ denied: "denied";
1074
+ }>;
1075
+ }, z.core.$strict>], "status">>>;
1076
+ }, z.core.$strict>>>;
1077
+ nextBeforeSequence: z.ZodNullable<z.ZodNumber>;
1078
+ }, z.core.$strict>>;
1079
+ }, z.core.$strict>>]>>;
882
1080
  error: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
883
1081
  code: z.ZodEnum<{
884
1082
  readonly aborted: "ABORTED";
@@ -911,8 +1109,14 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
911
1109
  message: z.ZodString;
912
1110
  retryable: z.ZodBoolean;
913
1111
  kind: z.ZodLiteral<"remote">;
914
- }, z.core.$strict>>]>;
915
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
1112
+ }, z.core.$strict>>], "kind">;
1113
+ contextRecovery: z.ZodDefault<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
1114
+ checkpointId: z.ZodString;
1115
+ required: z.ZodBoolean;
1116
+ unextracted: z.ZodBoolean;
1117
+ requiredItemCount: z.ZodNumber;
1118
+ }, z.core.$strict>>>>;
1119
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
916
1120
  liveAssistantMessages: z.ZodReadonly<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
917
1121
  status: z.ZodLiteral<"streaming">;
918
1122
  streamId: z.ZodString;
@@ -921,22 +1125,22 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
921
1125
  status: z.ZodLiteral<"completed">;
922
1126
  streamId: z.ZodString;
923
1127
  text: z.ZodString;
924
- }, z.core.$strict>>]>>>;
1128
+ }, z.core.$strict>>], "status">>>;
925
1129
  interactions: z.ZodReadonly<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
926
1130
  status: z.ZodLiteral<"pending">;
927
1131
  request: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
928
1132
  method: z.ZodLiteral<"approval.request">;
929
1133
  projection: z.ZodReadonly<z.ZodObject<{
930
- approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId">;
1134
+ approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId", "out">;
931
1135
  agentName: z.ZodString;
932
1136
  toolName: z.ZodString;
933
1137
  explanation: z.ZodOptional<z.ZodString>;
934
1138
  }, z.core.$strict>>;
935
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
1139
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
936
1140
  relaySequence: z.ZodNumber;
937
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
938
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
939
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
1141
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
1142
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
1143
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
940
1144
  expiresAt: z.ZodString;
941
1145
  sensitivity: z.ZodLiteral<"normal">;
942
1146
  type: z.ZodLiteral<"interaction.request">;
@@ -990,32 +1194,32 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
990
1194
  description: z.ZodOptional<z.ZodString>;
991
1195
  required: z.ZodBoolean;
992
1196
  type: z.ZodLiteral<"choice">;
993
- }, z.core.$strict>>]>>;
1197
+ }, z.core.$strict>>], "type">>;
994
1198
  }, z.core.$strict>>;
995
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
1199
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
996
1200
  relaySequence: z.ZodNumber;
997
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
998
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
999
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
1201
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
1202
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
1203
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
1000
1204
  expiresAt: z.ZodString;
1001
1205
  sensitivity: z.ZodLiteral<"normal">;
1002
1206
  type: z.ZodLiteral<"interaction.request">;
1003
- }, z.core.$strict>>]>;
1207
+ }, z.core.$strict>>], "method">;
1004
1208
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
1005
1209
  status: z.ZodLiteral<"responding">;
1006
1210
  request: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
1007
1211
  method: z.ZodLiteral<"approval.request">;
1008
1212
  projection: z.ZodReadonly<z.ZodObject<{
1009
- approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId">;
1213
+ approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId", "out">;
1010
1214
  agentName: z.ZodString;
1011
1215
  toolName: z.ZodString;
1012
1216
  explanation: z.ZodOptional<z.ZodString>;
1013
1217
  }, z.core.$strict>>;
1014
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
1218
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
1015
1219
  relaySequence: z.ZodNumber;
1016
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
1017
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
1018
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
1220
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
1221
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
1222
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
1019
1223
  expiresAt: z.ZodString;
1020
1224
  sensitivity: z.ZodLiteral<"normal">;
1021
1225
  type: z.ZodLiteral<"interaction.request">;
@@ -1069,55 +1273,55 @@ export declare const relayThreadViewSchema: z.ZodDiscriminatedUnion<[z.ZodReadon
1069
1273
  description: z.ZodOptional<z.ZodString>;
1070
1274
  required: z.ZodBoolean;
1071
1275
  type: z.ZodLiteral<"choice">;
1072
- }, z.core.$strict>>]>>;
1276
+ }, z.core.$strict>>], "type">>;
1073
1277
  }, z.core.$strict>>;
1074
- workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId">;
1278
+ workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
1075
1279
  relaySequence: z.ZodNumber;
1076
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
1077
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
1078
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
1280
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
1281
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
1282
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
1079
1283
  expiresAt: z.ZodString;
1080
1284
  sensitivity: z.ZodLiteral<"normal">;
1081
1285
  type: z.ZodLiteral<"interaction.request">;
1082
- }, z.core.$strict>>]>;
1286
+ }, z.core.$strict>>], "method">;
1083
1287
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
1084
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
1085
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
1086
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
1288
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
1289
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
1290
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
1087
1291
  method: z.ZodUnion<[z.ZodLiteral<"approval.request">, z.ZodLiteral<"userInput.request">]>;
1088
1292
  status: z.ZodLiteral<"resolved">;
1089
1293
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
1090
- interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId">;
1091
- threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
1092
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
1294
+ interactionId: z.core.$ZodBranded<z.ZodString, "InteractionId", "out">;
1295
+ threadId: z.core.$ZodBranded<z.ZodString, "ThreadId", "out">;
1296
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
1093
1297
  method: z.ZodUnion<[z.ZodLiteral<"approval.request">, z.ZodLiteral<"userInput.request">]>;
1094
1298
  status: z.ZodLiteral<"cancelled">;
1095
- }, z.core.$strict>>]>>>;
1299
+ }, z.core.$strict>>], "status">>>;
1096
1300
  turn: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
1097
1301
  status: z.ZodLiteral<"idle">;
1098
1302
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
1099
1303
  status: z.ZodLiteral<"running">;
1100
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
1304
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
1101
1305
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
1102
1306
  status: z.ZodLiteral<"cancelling">;
1103
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
1307
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
1104
1308
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
1105
1309
  status: z.ZodLiteral<"completed">;
1106
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
1310
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
1107
1311
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
1108
1312
  status: z.ZodLiteral<"cancelled">;
1109
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
1313
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
1110
1314
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
1111
1315
  status: z.ZodLiteral<"failed">;
1112
- turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
1316
+ turnId: z.core.$ZodBranded<z.ZodString, "TurnId", "out">;
1113
1317
  stage: z.ZodEnum<{
1114
1318
  bootstrap: "bootstrap";
1115
1319
  plan: "plan";
1116
1320
  execute: "execute";
1117
1321
  }>;
1118
- }, z.core.$strict>>]>;
1322
+ }, z.core.$strict>>], "status">;
1119
1323
  status: z.ZodLiteral<"error">;
1120
- }, z.core.$strict>>]>;
1324
+ }, z.core.$strict>>], "status">;
1121
1325
  export type RelayConnectionState = z.output<typeof relayConnectionStateSchema>;
1122
1326
  export type RelayClientTransportErrorCode = z.output<typeof relayClientTransportErrorCodeSchema>;
1123
1327
  export type RelayClientErrorDetails = z.output<typeof relayClientErrorDetailsSchema>;
package/dist/schemas.js CHANGED
@@ -1 +1 @@
1
- import{relayInteractionRequestSchemaV11 as t,relayRequestMethodSchemasV12 as e}from"@roll-agent/relay-protocol";import{relayClientErrorCodeSchema as r}from"@roll-agent/relay-protocol/control";import{z as n}from"zod/v4";const a=e["thread.open"].params.def.innerType.shape.threadId,o=e["turn.cancel"].params.def.innerType.shape.turnId,s=e["thread.snapshot"].result;export const RELAY_CONNECTION_STATUSES={idle:"idle",connecting:"connecting",connected:"connected",reconnecting:"reconnecting",closed:"closed"};export const relayConnectionStateSchema=n.discriminatedUnion("status",[n.object({status:n.literal(RELAY_CONNECTION_STATUSES.idle)}).strict().readonly(),n.object({status:n.literal(RELAY_CONNECTION_STATUSES.connecting),attempt:n.number().int().positive()}).strict().readonly(),n.object({status:n.literal(RELAY_CONNECTION_STATUSES.connected),workspaceStatus:n.enum(["online","offline"])}).strict().readonly(),n.object({status:n.literal(RELAY_CONNECTION_STATUSES.reconnecting),attempt:n.number().int().positive(),retryAt:n.string().datetime({offset:!0})}).strict().readonly(),n.object({status:n.literal(RELAY_CONNECTION_STATUSES.closed),reason:n.enum(["client","session","transport","protocol"])}).strict().readonly()]);export const RELAY_CLIENT_TRANSPORT_ERROR_CODES={aborted:"ABORTED",closed:"CLIENT_CLOSED",connectionUnavailable:"CONNECTION_UNAVAILABLE",invalidSession:"INVALID_SESSION",outcomeUnknown:"OUTCOME_UNKNOWN",protocolError:"PROTOCOL_ERROR",requestTimeout:"REQUEST_TIMEOUT",transportError:"TRANSPORT_ERROR",workspaceOffline:"WORKSPACE_OFFLINE"};export const relayClientTransportErrorCodeSchema=n.enum(RELAY_CLIENT_TRANSPORT_ERROR_CODES);const i={message:n.string(),retryable:n.boolean()};export const relayClientErrorDetailsSchema=n.discriminatedUnion("kind",[n.object({kind:n.literal("transport"),...i,code:relayClientTransportErrorCodeSchema}).strict().readonly(),n.object({kind:n.literal("session"),...i,code:r}).strict().readonly(),n.object({kind:n.literal("remote"),...i,code:n.string().min(1)}).strict().readonly()]);export const relayLiveAssistantMessageSchema=n.discriminatedUnion("status",[n.object({status:n.literal("streaming"),streamId:n.string().uuid(),text:n.string()}).strict().readonly(),n.object({status:n.literal("completed"),streamId:n.string().uuid(),text:n.string()}).strict().readonly()]);const l={interactionId:t.options[0].def.innerType.shape.interactionId,threadId:a,turnId:o,method:t.options[0].def.innerType.shape.method.or(t.options[1].def.innerType.shape.method)};export const relayInteractionStateSchema=n.discriminatedUnion("status",[n.object({status:n.literal("pending"),request:t}).strict().readonly(),n.object({status:n.literal("responding"),request:t}).strict().readonly(),n.object({status:n.literal("resolved"),...l}).strict().readonly(),n.object({status:n.literal("cancelled"),...l}).strict().readonly()]);export const relayTurnStateSchema=n.discriminatedUnion("status",[n.object({status:n.literal("idle")}).strict().readonly(),n.object({status:n.literal("running"),turnId:o}).strict().readonly(),n.object({status:n.literal("cancelling"),turnId:o}).strict().readonly(),n.object({status:n.literal("completed"),turnId:o}).strict().readonly(),n.object({status:n.literal("cancelled"),turnId:o}).strict().readonly(),n.object({status:n.literal("failed"),turnId:o,stage:n.enum(["bootstrap","plan","execute"])}).strict().readonly()]);const c={threadId:a,liveAssistantMessages:n.array(relayLiveAssistantMessageSchema).readonly(),interactions:n.array(relayInteractionStateSchema).readonly(),turn:relayTurnStateSchema};export const relayThreadViewSchema=n.discriminatedUnion("status",[n.object({status:n.literal("loading"),...c,snapshot:n.null()}).strict().readonly(),n.object({status:n.literal("ready"),...c,snapshot:s}).strict().readonly(),n.object({status:n.literal("error"),...c,snapshot:s.nullable(),error:relayClientErrorDetailsSchema}).strict().readonly()]);export function getPendingInteractionRequest(t){return"pending"===t.status||"responding"===t.status?t.request:void 0}
1
+ import{relayInteractionRequestSchemaV11 as t,relayRequestMethodSchemasV12 as e,relayThreadSnapshotSchemaV13 as r}from"@roll-agent/relay-protocol";import{relayClientErrorCodeSchema as n}from"@roll-agent/relay-protocol/control";import{z as o}from"zod/v4";const a=e["thread.open"].params.def.innerType.shape.threadId,s=e["turn.cancel"].params.def.innerType.shape.turnId,i=o.union([r,e["thread.snapshot"].result]);export const RELAY_CONNECTION_STATUSES={idle:"idle",connecting:"connecting",connected:"connected",reconnecting:"reconnecting",closed:"closed"};export const relayConnectionStateSchema=o.discriminatedUnion("status",[o.object({status:o.literal(RELAY_CONNECTION_STATUSES.idle)}).strict().readonly(),o.object({status:o.literal(RELAY_CONNECTION_STATUSES.connecting),attempt:o.number().int().positive()}).strict().readonly(),o.object({status:o.literal(RELAY_CONNECTION_STATUSES.connected),workspaceStatus:o.enum(["online","offline"])}).strict().readonly(),o.object({status:o.literal(RELAY_CONNECTION_STATUSES.reconnecting),attempt:o.number().int().positive(),retryAt:o.string().datetime({offset:!0})}).strict().readonly(),o.object({status:o.literal(RELAY_CONNECTION_STATUSES.closed),reason:o.enum(["client","session","transport","protocol"])}).strict().readonly()]);export const RELAY_CLIENT_TRANSPORT_ERROR_CODES={aborted:"ABORTED",closed:"CLIENT_CLOSED",connectionUnavailable:"CONNECTION_UNAVAILABLE",invalidSession:"INVALID_SESSION",outcomeUnknown:"OUTCOME_UNKNOWN",protocolError:"PROTOCOL_ERROR",requestTimeout:"REQUEST_TIMEOUT",transportError:"TRANSPORT_ERROR",workspaceOffline:"WORKSPACE_OFFLINE"};export const relayClientTransportErrorCodeSchema=o.enum(RELAY_CLIENT_TRANSPORT_ERROR_CODES);const l={message:o.string(),retryable:o.boolean()};export const relayClientErrorDetailsSchema=o.discriminatedUnion("kind",[o.object({kind:o.literal("transport"),...l,code:relayClientTransportErrorCodeSchema}).strict().readonly(),o.object({kind:o.literal("session"),...l,code:n}).strict().readonly(),o.object({kind:o.literal("remote"),...l,code:o.string().min(1)}).strict().readonly()]);export const relayLiveAssistantMessageSchema=o.discriminatedUnion("status",[o.object({status:o.literal("streaming"),streamId:o.string().uuid(),text:o.string()}).strict().readonly(),o.object({status:o.literal("completed"),streamId:o.string().uuid(),text:o.string()}).strict().readonly()]);const c={interactionId:t.options[0].def.innerType.shape.interactionId,threadId:a,turnId:s,method:t.options[0].def.innerType.shape.method.or(t.options[1].def.innerType.shape.method)};export const relayInteractionStateSchema=o.discriminatedUnion("status",[o.object({status:o.literal("pending"),request:t}).strict().readonly(),o.object({status:o.literal("responding"),request:t}).strict().readonly(),o.object({status:o.literal("resolved"),...c}).strict().readonly(),o.object({status:o.literal("cancelled"),...c}).strict().readonly()]);export const relayTurnStateSchema=o.discriminatedUnion("status",[o.object({status:o.literal("idle")}).strict().readonly(),o.object({status:o.literal("running"),turnId:s}).strict().readonly(),o.object({status:o.literal("cancelling"),turnId:s}).strict().readonly(),o.object({status:o.literal("completed"),turnId:s}).strict().readonly(),o.object({status:o.literal("cancelled"),turnId:s}).strict().readonly(),o.object({status:o.literal("failed"),turnId:s,stage:o.enum(["bootstrap","plan","execute"])}).strict().readonly()]);const d={contextRecovery:r.def.innerType.shape.contextRecovery.default(null),threadId:a,liveAssistantMessages:o.array(relayLiveAssistantMessageSchema).readonly(),interactions:o.array(relayInteractionStateSchema).readonly(),turn:relayTurnStateSchema};export const relayThreadViewSchema=o.discriminatedUnion("status",[o.object({status:o.literal("loading"),...d,snapshot:o.null()}).strict().readonly(),o.object({status:o.literal("ready"),...d,snapshot:i}).strict().readonly(),o.object({status:o.literal("error"),...d,snapshot:i.nullable(),error:relayClientErrorDetailsSchema}).strict().readonly()]);export function getPendingInteractionRequest(t){return"pending"===t.status||"responding"===t.status?t.request:void 0}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roll-agent/relay-client",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "repository": {
@@ -31,8 +31,8 @@
31
31
  "node": ">=22.6.0"
32
32
  },
33
33
  "dependencies": {
34
- "@roll-agent/relay-protocol": "0.4.2",
35
- "zod": "3.25.76"
34
+ "@roll-agent/relay-protocol": "0.5.1",
35
+ "zod": "4.6.6"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "^22.0.0",