@noodleseed/assistant 1.19.0 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,14 +58,16 @@ interface AssistantToolProposedDetail extends TurnDetail {
58
58
  readonly requiresConfirmation?: true;
59
59
  }
60
60
  /**
61
- * A capability the visitor must sign in to reach (ADR 0201, 5.6b). `continuation` is the value the host
62
- * page hands to its **own** backend, which spends it with its own client credentials; on its own it names
63
- * a conversation and nothing more.
61
+ * A capability the visitor must sign in to reach (ADR 0201, 5.6b). `signInTicket` is the value the host
62
+ * page hands to its **own** backend, which spends it with its own client credentials
63
+ * (`createAssistantSession({ signInTicket })`); on its own it names a conversation and nothing more.
64
+ * It is deliberately not called a continuation: the server-held interaction continuation must never
65
+ * reach browser code, and this value's whole job is to travel through the browser.
64
66
  */
65
67
  interface AssistantAuthRequestedDetail extends TurnDetail {
66
68
  readonly id: string;
67
69
  readonly tool: string;
68
- readonly continuation: string;
70
+ readonly signInTicket: string;
69
71
  readonly expiresAt: string;
70
72
  }
71
73
  interface AssistantInputRequestedDetail extends TurnDetail {
@@ -131,7 +133,9 @@ type AssistantClientLifecycleEvent = NamedEvent<'session_started', {
131
133
  readonly modelContext: AssistantModelContextUpdate;
132
134
  }> | NamedEvent<'message_started', {
133
135
  readonly message: string;
134
- }> | NamedEvent<'message_completed', Readonly<Record<string, never>>> | NamedEvent<'interaction_started', {
136
+ }> | NamedEvent<'message_completed', Readonly<Record<string, never>>> | NamedEvent<'resume_started', {
137
+ readonly tool: string;
138
+ }> | NamedEvent<'interaction_started', {
135
139
  readonly id: string;
136
140
  readonly action: 'accept' | 'decline' | 'cancel';
137
141
  }> | NamedEvent<'interaction_completed', {
@@ -199,6 +203,11 @@ type AssistantSessionSourceOptions = {
199
203
  readonly sessionEndpoint?: undefined;
200
204
  };
201
205
 
206
+ declare class AssistantClientError extends Error {
207
+ readonly detail: AssistantErrorDetail;
208
+ constructor(detail: AssistantErrorDetail, message: string, options?: ErrorOptions);
209
+ }
210
+
202
211
  type AssistantContextValue = string | number | boolean | null;
203
212
  type AssistantContext = Readonly<Record<string, AssistantContextValue>>;
204
213
  interface AssistantClientContext {
@@ -224,6 +233,10 @@ interface AssistantSessionResponse {
224
233
  readonly sandbox?: string;
225
234
  };
226
235
  readonly configuration?: AssistantConfiguration;
236
+ /** Armed post-sign-in resume hint: present only on an elevation exchange (issue #1177). */
237
+ readonly resume?: {
238
+ readonly tool: string;
239
+ };
227
240
  }
228
241
 
229
242
  interface AssistantClientBehaviorOptions<TPageContext extends AssistantPageContext = AssistantContext> {
@@ -251,6 +264,8 @@ interface AssistantClient<TPageContext extends AssistantPageContext = AssistantC
251
264
  getChatState(): AssistantChatState;
252
265
  connect(): Promise<void>;
253
266
  hasSession(): boolean;
267
+ /** A request holds the single-flight slot. Optional so external implementations stay valid. */
268
+ isBusy?(): boolean;
254
269
  sendMessage(message: string): Promise<void>;
255
270
  respond(id: string, response: AssistantInteractionResponse): Promise<void>;
256
271
  updateContext(context: AssistantContext): void;
@@ -265,10 +280,6 @@ interface AssistantClient<TPageContext extends AssistantPageContext = AssistantC
265
280
  resetSession(): void;
266
281
  abort(): void;
267
282
  }
268
- declare class AssistantClientError extends Error {
269
- readonly detail: AssistantErrorDetail;
270
- constructor(detail: AssistantErrorDetail, message: string, options?: ErrorOptions);
271
- }
272
283
  declare function createAssistantClient<TPageContext extends AssistantPageContext = AssistantContext>(options: CreateAssistantClientOptions<TPageContext>): AssistantClient<TPageContext>;
273
284
 
274
285
  export { type AssistantPageContext as A, type AssistantInteractionStatus as B, type CreateAssistantClientOptions as C, type AssistantJsonValue as D, type AssistantSessionResponse as E, type AssistantToolCompletedDetail as F, type AssistantToolCompletedEvent as G, type AssistantToolProposedDetail as H, type AssistantToolProposedEvent as I, type AssistantToolResultData as J, type AssistantToolStartedDetail as K, type AssistantToolStartedEvent as L, type AssistantUIDataTypes as M, type AssistantUIMessage as N, type AssistantUnrecognizedEvent as O, type AssistantViewData as P, createAssistantClient as Q, type AssistantContext as a, type AssistantChatState as b, type AssistantClient as c, type AssistantViewAvailableDetail as d, type AssistantModelContextUpdate as e, type AssistantClientEvent as f, type AssistantErrorDetail as g, type AssistantInteractionResponse as h, type AssistantEvent as i, type AssistantViewAvailableEvent as j, type AssistantChatError as k, type AssistantClientContext as l, AssistantClientError as m, type AssistantClientLifecycleEvent as n, type AssistantConfirmationData as o, type AssistantContentDetail as p, type AssistantContentEvent as q, type AssistantContextValue as r, type AssistantDoneEvent as s, type AssistantErrorEvent as t, type AssistantErrorEventDetail as u, type AssistantInputRequestData as v, type AssistantInputRequestedDetail as w, type AssistantInputRequestedEvent as x, type AssistantInteractionResolvedDetail as y, type AssistantInteractionResolvedEvent as z };
@@ -58,14 +58,16 @@ interface AssistantToolProposedDetail extends TurnDetail {
58
58
  readonly requiresConfirmation?: true;
59
59
  }
60
60
  /**
61
- * A capability the visitor must sign in to reach (ADR 0201, 5.6b). `continuation` is the value the host
62
- * page hands to its **own** backend, which spends it with its own client credentials; on its own it names
63
- * a conversation and nothing more.
61
+ * A capability the visitor must sign in to reach (ADR 0201, 5.6b). `signInTicket` is the value the host
62
+ * page hands to its **own** backend, which spends it with its own client credentials
63
+ * (`createAssistantSession({ signInTicket })`); on its own it names a conversation and nothing more.
64
+ * It is deliberately not called a continuation: the server-held interaction continuation must never
65
+ * reach browser code, and this value's whole job is to travel through the browser.
64
66
  */
65
67
  interface AssistantAuthRequestedDetail extends TurnDetail {
66
68
  readonly id: string;
67
69
  readonly tool: string;
68
- readonly continuation: string;
70
+ readonly signInTicket: string;
69
71
  readonly expiresAt: string;
70
72
  }
71
73
  interface AssistantInputRequestedDetail extends TurnDetail {
@@ -131,7 +133,9 @@ type AssistantClientLifecycleEvent = NamedEvent<'session_started', {
131
133
  readonly modelContext: AssistantModelContextUpdate;
132
134
  }> | NamedEvent<'message_started', {
133
135
  readonly message: string;
134
- }> | NamedEvent<'message_completed', Readonly<Record<string, never>>> | NamedEvent<'interaction_started', {
136
+ }> | NamedEvent<'message_completed', Readonly<Record<string, never>>> | NamedEvent<'resume_started', {
137
+ readonly tool: string;
138
+ }> | NamedEvent<'interaction_started', {
135
139
  readonly id: string;
136
140
  readonly action: 'accept' | 'decline' | 'cancel';
137
141
  }> | NamedEvent<'interaction_completed', {
@@ -199,6 +203,11 @@ type AssistantSessionSourceOptions = {
199
203
  readonly sessionEndpoint?: undefined;
200
204
  };
201
205
 
206
+ declare class AssistantClientError extends Error {
207
+ readonly detail: AssistantErrorDetail;
208
+ constructor(detail: AssistantErrorDetail, message: string, options?: ErrorOptions);
209
+ }
210
+
202
211
  type AssistantContextValue = string | number | boolean | null;
203
212
  type AssistantContext = Readonly<Record<string, AssistantContextValue>>;
204
213
  interface AssistantClientContext {
@@ -224,6 +233,10 @@ interface AssistantSessionResponse {
224
233
  readonly sandbox?: string;
225
234
  };
226
235
  readonly configuration?: AssistantConfiguration;
236
+ /** Armed post-sign-in resume hint: present only on an elevation exchange (issue #1177). */
237
+ readonly resume?: {
238
+ readonly tool: string;
239
+ };
227
240
  }
228
241
 
229
242
  interface AssistantClientBehaviorOptions<TPageContext extends AssistantPageContext = AssistantContext> {
@@ -251,6 +264,8 @@ interface AssistantClient<TPageContext extends AssistantPageContext = AssistantC
251
264
  getChatState(): AssistantChatState;
252
265
  connect(): Promise<void>;
253
266
  hasSession(): boolean;
267
+ /** A request holds the single-flight slot. Optional so external implementations stay valid. */
268
+ isBusy?(): boolean;
254
269
  sendMessage(message: string): Promise<void>;
255
270
  respond(id: string, response: AssistantInteractionResponse): Promise<void>;
256
271
  updateContext(context: AssistantContext): void;
@@ -265,10 +280,6 @@ interface AssistantClient<TPageContext extends AssistantPageContext = AssistantC
265
280
  resetSession(): void;
266
281
  abort(): void;
267
282
  }
268
- declare class AssistantClientError extends Error {
269
- readonly detail: AssistantErrorDetail;
270
- constructor(detail: AssistantErrorDetail, message: string, options?: ErrorOptions);
271
- }
272
283
  declare function createAssistantClient<TPageContext extends AssistantPageContext = AssistantContext>(options: CreateAssistantClientOptions<TPageContext>): AssistantClient<TPageContext>;
273
284
 
274
285
  export { type AssistantPageContext as A, type AssistantInteractionStatus as B, type CreateAssistantClientOptions as C, type AssistantJsonValue as D, type AssistantSessionResponse as E, type AssistantToolCompletedDetail as F, type AssistantToolCompletedEvent as G, type AssistantToolProposedDetail as H, type AssistantToolProposedEvent as I, type AssistantToolResultData as J, type AssistantToolStartedDetail as K, type AssistantToolStartedEvent as L, type AssistantUIDataTypes as M, type AssistantUIMessage as N, type AssistantUnrecognizedEvent as O, type AssistantViewData as P, createAssistantClient as Q, type AssistantContext as a, type AssistantChatState as b, type AssistantClient as c, type AssistantViewAvailableDetail as d, type AssistantModelContextUpdate as e, type AssistantClientEvent as f, type AssistantErrorDetail as g, type AssistantInteractionResponse as h, type AssistantEvent as i, type AssistantViewAvailableEvent as j, type AssistantChatError as k, type AssistantClientContext as l, AssistantClientError as m, type AssistantClientLifecycleEvent as n, type AssistantConfirmationData as o, type AssistantContentDetail as p, type AssistantContentEvent as q, type AssistantContextValue as r, type AssistantDoneEvent as s, type AssistantErrorEvent as t, type AssistantErrorEventDetail as u, type AssistantInputRequestData as v, type AssistantInputRequestedDetail as w, type AssistantInputRequestedEvent as x, type AssistantInteractionResolvedDetail as y, type AssistantInteractionResolvedEvent as z };
package/dist/client.cjs CHANGED
@@ -22639,6 +22639,12 @@ var AssistantChatStateStore = class {
22639
22639
  case "interaction_started":
22640
22640
  this.#beginInteraction(event.data.id);
22641
22641
  return;
22642
+ case "resume_started":
22643
+ this.#status = "submitted";
22644
+ this.#error = void 0;
22645
+ this.#startOperation();
22646
+ this.#notify();
22647
+ return;
22642
22648
  case "content":
22643
22649
  this.#writeText(event.data.delta);
22644
22650
  return;
@@ -22894,6 +22900,78 @@ function isRecord(value) {
22894
22900
  return typeof value === "object" && value !== null && !Array.isArray(value);
22895
22901
  }
22896
22902
 
22903
+ // src/client-errors.ts
22904
+ async function refusalCode(response) {
22905
+ try {
22906
+ const body = await response.clone().json();
22907
+ const code = body.code;
22908
+ return typeof code === "string" ? code : void 0;
22909
+ } catch {
22910
+ return void 0;
22911
+ }
22912
+ }
22913
+ var UNRETRYABLE_SERVICE_CODES = /* @__PURE__ */ new Set([
22914
+ "daily_turn_budget_exhausted",
22915
+ "daily_session_budget_exhausted"
22916
+ ]);
22917
+ var AssistantClientError = class extends Error {
22918
+ detail;
22919
+ constructor(detail, message, options) {
22920
+ super(message, options);
22921
+ this.name = "AssistantClientError";
22922
+ this.detail = detail;
22923
+ }
22924
+ };
22925
+ function parseSession(value) {
22926
+ if (!isRecord2(value) || !isRecord2(value.endpoints)) {
22927
+ throw clientError("session_failed", "Assistant session response is invalid", true);
22928
+ }
22929
+ const interactions = value.endpoints.interactions;
22930
+ const apps = value.endpoints.apps;
22931
+ const sandbox = value.endpoints.sandbox;
22932
+ if (typeof value.token !== "string" || typeof value.expiresAt !== "string" || typeof value.endpoints.turns !== "string" || typeof value.endpoints.toolConfirmations !== "string" || interactions !== void 0 && typeof interactions !== "string" || apps !== void 0 && typeof apps !== "string" || sandbox !== void 0 && typeof sandbox !== "string") {
22933
+ throw clientError("session_failed", "Assistant session response is invalid", true);
22934
+ }
22935
+ return {
22936
+ token: value.token,
22937
+ expiresAt: value.expiresAt,
22938
+ endpoints: {
22939
+ turns: value.endpoints.turns,
22940
+ toolConfirmations: value.endpoints.toolConfirmations,
22941
+ ...typeof interactions === "string" ? { interactions } : {},
22942
+ ...typeof apps === "string" ? { apps } : {},
22943
+ ...typeof sandbox === "string" ? { sandbox } : {}
22944
+ },
22945
+ ...isRecord2(value.configuration) ? { configuration: value.configuration } : {},
22946
+ ...isRecord2(value.resume) && typeof value.resume.tool === "string" ? { resume: { tool: value.resume.tool } } : {}
22947
+ };
22948
+ }
22949
+ function isRecord2(value) {
22950
+ return typeof value === "object" && value !== null && !Array.isArray(value);
22951
+ }
22952
+ async function readStableErrorCode(response) {
22953
+ let value;
22954
+ try {
22955
+ value = await response.json();
22956
+ } catch {
22957
+ return void 0;
22958
+ }
22959
+ if (!isRecord2(value) || typeof value.code !== "string") return void 0;
22960
+ return /^[A-Za-z0-9_.-]{1,64}$/.test(value.code) ? value.code : void 0;
22961
+ }
22962
+ function clientError(code, message, retryable, status, options, serviceCode) {
22963
+ return new AssistantClientError(
22964
+ {
22965
+ code,
22966
+ ...status === void 0 ? {} : { status },
22967
+ retryable,
22968
+ ...serviceCode === void 0 ? {} : { serviceCode }
22969
+ },
22970
+ message,
22971
+ options
22972
+ );
22973
+ }
22974
+
22897
22975
  // src/events.ts
22898
22976
  function toAssistantClientEvent(event) {
22899
22977
  const value = event.data;
@@ -22909,20 +22987,25 @@ function toAssistantClientEvent(event) {
22909
22987
  }
22910
22988
  break;
22911
22989
  case "tool_proposed":
22912
- if (hasString(value, "id") && hasString(value, "tool") && hasOptionalString(value.title) && hasOptionalString(value.description) && hasOptionalJson(value.arguments) && (value.reviewSchema === void 0 || isRecord2(value.reviewSchema)) && hasOptionalString(value.expiresAt) && (value.requiresConfirmation === void 0 || value.requiresConfirmation === true) && hasOptionalTurnId(value)) {
22990
+ if (hasString(value, "id") && hasString(value, "tool") && hasOptionalString(value.title) && hasOptionalString(value.description) && hasOptionalJson(value.arguments) && (value.reviewSchema === void 0 || isRecord3(value.reviewSchema)) && hasOptionalString(value.expiresAt) && (value.requiresConfirmation === void 0 || value.requiresConfirmation === true) && hasOptionalTurnId(value)) {
22913
22991
  return event;
22914
22992
  }
22915
22993
  break;
22916
22994
  case "input_requested":
22917
- if (hasString(value, "id") && hasString(value, "message") && isRecord2(value.requestedSchema) && hasString(value, "expiresAt") && hasOptionalTurnId(value)) {
22995
+ if (hasString(value, "id") && hasString(value, "message") && isRecord3(value.requestedSchema) && hasString(value, "expiresAt") && hasOptionalTurnId(value)) {
22918
22996
  return event;
22919
22997
  }
22920
22998
  break;
22921
- case "auth_requested":
22922
- if (hasString(value, "id") && hasString(value, "tool") && hasString(value, "continuation") && hasString(value, "expiresAt") && hasOptionalTurnId(value)) {
22923
- return event;
22999
+ case "auth_requested": {
23000
+ const signInTicket = typeof value.signInTicket === "string" ? value.signInTicket : typeof value.continuation === "string" ? value.continuation : void 0;
23001
+ if (hasString(value, "id") && hasString(value, "tool") && signInTicket !== void 0 && hasString(value, "expiresAt") && hasOptionalTurnId(value)) {
23002
+ return {
23003
+ event: "auth_requested",
23004
+ data: { ...value, signInTicket }
23005
+ };
22924
23006
  }
22925
23007
  break;
23008
+ }
22926
23009
  case "interaction_resolved":
22927
23010
  if (hasString(value, "id") && (value.action === void 0 || isInteractionAction(value.action)) && hasOptionalTurnId(value)) {
22928
23011
  return event;
@@ -22953,7 +23036,7 @@ function toAssistantClientEvent(event) {
22953
23036
  return { event: "unrecognized", data: { name: event.event, payload: value } };
22954
23037
  }
22955
23038
  function isViewAvailableDetail(value) {
22956
- return hasString(value, "id") && hasString(value, "tool") && typeof value.resourceUri === "string" && value.resourceUri.startsWith("ui://") && hasOptionalString(value.title) && (value.replayed === void 0 || value.replayed === true) && isJsonValue(value.result, 0) && hasOptionalJson(value.arguments) && hasOptionalString(value.html) && (value.resourceMeta === void 0 || isRecord2(value.resourceMeta)) && (value.allowedOpenDomains === void 0 || Array.isArray(value.allowedOpenDomains) && value.allowedOpenDomains.every(isHttpsUrl)) && hasOptionalTurnId(value);
23039
+ return hasString(value, "id") && hasString(value, "tool") && typeof value.resourceUri === "string" && value.resourceUri.startsWith("ui://") && hasOptionalString(value.title) && (value.replayed === void 0 || value.replayed === true) && isJsonValue(value.result, 0) && hasOptionalJson(value.arguments) && hasOptionalString(value.html) && (value.resourceMeta === void 0 || isRecord3(value.resourceMeta)) && (value.allowedOpenDomains === void 0 || Array.isArray(value.allowedOpenDomains) && value.allowedOpenDomains.every(isHttpsUrl)) && hasOptionalTurnId(value);
22957
23040
  }
22958
23041
  function isHttpsUrl(value) {
22959
23042
  if (typeof value !== "string") return false;
@@ -22986,11 +23069,11 @@ function isJsonValue(value, depth) {
22986
23069
  if (Array.isArray(value)) {
22987
23070
  return value.length <= 256 && value.every((entry) => isJsonValue(entry, depth + 1));
22988
23071
  }
22989
- if (!isRecord2(value)) return false;
23072
+ if (!isRecord3(value)) return false;
22990
23073
  const entries = Object.entries(value);
22991
23074
  return entries.length <= 256 && entries.every(([, entry]) => isJsonValue(entry, depth + 1));
22992
23075
  }
22993
- function isRecord2(value) {
23076
+ function isRecord3(value) {
22994
23077
  return typeof value === "object" && value !== null && !Array.isArray(value);
22995
23078
  }
22996
23079
 
@@ -23230,15 +23313,15 @@ function parseFrame(frame) {
23230
23313
  if (event === "done" && !isValidDonePayload(parsed)) {
23231
23314
  throw invalidStream("assistant event stream contained an invalid done event");
23232
23315
  }
23233
- return { event, data: isRecord3(parsed) ? parsed : { value: parsed } };
23316
+ return { event, data: isRecord4(parsed) ? parsed : { value: parsed } };
23234
23317
  }
23235
23318
  function normalizeLineEndings(input) {
23236
23319
  return input.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
23237
23320
  }
23238
23321
  function isValidDonePayload(value) {
23239
- return isRecord3(value) && (value.turnId === void 0 || typeof value.turnId === "string" && value.turnId.length > 0);
23322
+ return isRecord4(value) && (value.turnId === void 0 || typeof value.turnId === "string" && value.turnId.length > 0);
23240
23323
  }
23241
- function isRecord3(value) {
23324
+ function isRecord4(value) {
23242
23325
  return typeof value === "object" && value !== null && !Array.isArray(value);
23243
23326
  }
23244
23327
  function invalidStream(message, cause) {
@@ -23249,27 +23332,6 @@ function isAbortError2(error51) {
23249
23332
  }
23250
23333
 
23251
23334
  // src/client.ts
23252
- async function refusalCode(response) {
23253
- try {
23254
- const body = await response.clone().json();
23255
- const code = body.code;
23256
- return typeof code === "string" ? code : void 0;
23257
- } catch {
23258
- return void 0;
23259
- }
23260
- }
23261
- var UNRETRYABLE_SERVICE_CODES = /* @__PURE__ */ new Set([
23262
- "daily_turn_budget_exhausted",
23263
- "daily_session_budget_exhausted"
23264
- ]);
23265
- var AssistantClientError = class extends Error {
23266
- detail;
23267
- constructor(detail, message, options) {
23268
- super(message, options);
23269
- this.name = "AssistantClientError";
23270
- this.detail = detail;
23271
- }
23272
- };
23273
23335
  var DefaultAssistantClient = class {
23274
23336
  #source;
23275
23337
  #fetch;
@@ -23304,12 +23366,50 @@ var DefaultAssistantClient = class {
23304
23366
  hasSession() {
23305
23367
  return this.#session !== void 0;
23306
23368
  }
23369
+ /** Whether a request holds the single-flight slot, so callers can refuse before mutating UI. */
23370
+ isBusy() {
23371
+ return this.#active !== void 0;
23372
+ }
23307
23373
  async connect() {
23308
23374
  if (this.#session) return;
23309
23375
  await this.#singleFlight(async (signal) => {
23310
- if (!this.#session) await this.#createSession(signal);
23376
+ if (this.#session) return;
23377
+ const session = await this.#createSession(signal);
23378
+ if (session.resume) {
23379
+ try {
23380
+ await this.#runChatOperation(signal, () => this.#resumeTurn(session, signal));
23381
+ } catch {
23382
+ }
23383
+ }
23311
23384
  });
23312
23385
  }
23386
+ /** POST the one-shot resume trigger; a 409 means nothing was pending, which renders as silence. */
23387
+ async #resumeTurn(session, signal) {
23388
+ const response = await this.#request(
23389
+ session.endpoints.turns,
23390
+ {
23391
+ method: "POST",
23392
+ headers: authorizedHeaders(session.token, "text/event-stream"),
23393
+ body: JSON.stringify({ resume: true }),
23394
+ signal
23395
+ },
23396
+ "turn_failed"
23397
+ );
23398
+ if (response.status === 409) return;
23399
+ if (!response.ok) {
23400
+ throw clientError(
23401
+ "turn_failed",
23402
+ `Assistant turn failed (${response.status})`,
23403
+ false,
23404
+ response.status,
23405
+ void 0,
23406
+ await refusalCode(response)
23407
+ );
23408
+ }
23409
+ this.#emit({ event: "resume_started", data: { tool: session.resume?.tool ?? "" } });
23410
+ await this.#consume(response);
23411
+ this.#emit({ event: "message_completed", data: {} });
23412
+ }
23313
23413
  async sendMessage(text2) {
23314
23414
  const message = text2.trim();
23315
23415
  if (!message) return;
@@ -23714,10 +23814,10 @@ function authorizedHeaders(token, accept) {
23714
23814
  };
23715
23815
  }
23716
23816
  function parseAppInteraction(value) {
23717
- if (!isRecord4(value) || !isRecord4(value.interaction)) return void 0;
23817
+ if (!isRecord2(value) || !isRecord2(value.interaction)) return void 0;
23718
23818
  const event = value.interaction.event;
23719
23819
  const data = value.interaction.data;
23720
- if (event !== "tool_proposed" && event !== "input_requested" || !isRecord4(data)) {
23820
+ if (event !== "tool_proposed" && event !== "input_requested" || !isRecord2(data)) {
23721
23821
  return void 0;
23722
23822
  }
23723
23823
  const parsed = toAssistantClientEvent({ event, data });
@@ -23737,54 +23837,6 @@ function appInteractionStopped(action) {
23737
23837
  isError: true
23738
23838
  };
23739
23839
  }
23740
- function parseSession(value) {
23741
- if (!isRecord4(value) || !isRecord4(value.endpoints)) {
23742
- throw clientError("session_failed", "Assistant session response is invalid", true);
23743
- }
23744
- const interactions = value.endpoints.interactions;
23745
- const apps = value.endpoints.apps;
23746
- const sandbox = value.endpoints.sandbox;
23747
- if (typeof value.token !== "string" || typeof value.expiresAt !== "string" || typeof value.endpoints.turns !== "string" || typeof value.endpoints.toolConfirmations !== "string" || interactions !== void 0 && typeof interactions !== "string" || apps !== void 0 && typeof apps !== "string" || sandbox !== void 0 && typeof sandbox !== "string") {
23748
- throw clientError("session_failed", "Assistant session response is invalid", true);
23749
- }
23750
- return {
23751
- token: value.token,
23752
- expiresAt: value.expiresAt,
23753
- endpoints: {
23754
- turns: value.endpoints.turns,
23755
- toolConfirmations: value.endpoints.toolConfirmations,
23756
- ...typeof interactions === "string" ? { interactions } : {},
23757
- ...typeof apps === "string" ? { apps } : {},
23758
- ...typeof sandbox === "string" ? { sandbox } : {}
23759
- },
23760
- ...isRecord4(value.configuration) ? { configuration: value.configuration } : {}
23761
- };
23762
- }
23763
- function isRecord4(value) {
23764
- return typeof value === "object" && value !== null && !Array.isArray(value);
23765
- }
23766
- async function readStableErrorCode(response) {
23767
- let value;
23768
- try {
23769
- value = await response.json();
23770
- } catch {
23771
- return void 0;
23772
- }
23773
- if (!isRecord4(value) || typeof value.code !== "string") return void 0;
23774
- return /^[A-Za-z0-9_.-]{1,64}$/.test(value.code) ? value.code : void 0;
23775
- }
23776
- function clientError(code, message, retryable, status, options, serviceCode) {
23777
- return new AssistantClientError(
23778
- {
23779
- code,
23780
- ...status === void 0 ? {} : { status },
23781
- retryable,
23782
- ...serviceCode === void 0 ? {} : { serviceCode }
23783
- },
23784
- message,
23785
- options
23786
- );
23787
- }
23788
23840
  // Annotate the CommonJS export names for ESM import in node:
23789
23841
  0 && (module.exports = {
23790
23842
  AssistantClientError,