@letta-ai/letta-agent-sdk 0.8.81 → 0.8.82

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.
@@ -15680,9 +15680,12 @@ function messageEventData(event) {
15680
15680
  }
15681
15681
  return null;
15682
15682
  }
15683
- function channelUrl(url, channel) {
15683
+ function channelUrl(url, channel, query = {}) {
15684
15684
  const parsed = new URL(url);
15685
15685
  parsed.searchParams.set("channel", channel);
15686
+ for (const [key, value] of Object.entries(query)) {
15687
+ parsed.searchParams.set(key, value);
15688
+ }
15686
15689
  return parsed.toString();
15687
15690
  }
15688
15691
 
@@ -15702,8 +15705,8 @@ class CloudStatusTransport {
15702
15705
  constructor(options) {
15703
15706
  this.options = options;
15704
15707
  const socketOptions = options.headers ? { headers: options.headers } : undefined;
15705
- this.controlSocket = new options.WebSocket(channelUrl(options.url, "control"), socketOptions);
15706
- this.streamSocket = new options.WebSocket(channelUrl(options.url, "stream"), socketOptions);
15708
+ this.controlSocket = new options.WebSocket(channelUrl(options.url, "control", options.channelQuery?.control), socketOptions);
15709
+ this.streamSocket = new options.WebSocket(channelUrl(options.url, "stream", options.channelQuery?.stream), socketOptions);
15707
15710
  this.bindSocket("control", this.controlSocket);
15708
15711
  this.bindSocket("stream", this.streamSocket);
15709
15712
  this.startPing();
@@ -16034,8 +16037,8 @@ function validateCloudClientOptions(options) {
16034
16037
  throw new Error("Letta Cloud clients cannot specify both registerComputer and sandbox options.");
16035
16038
  }
16036
16039
  }
16037
- if (options.webSocketAuth !== undefined && options.webSocketAuth !== "header" && options.webSocketAuth !== "query") {
16038
- throw new Error("Invalid webSocketAuth. Valid values: header, query.");
16040
+ if (options.webSocketAuth !== undefined && options.webSocketAuth !== "header" && options.webSocketAuth !== "ticket" && options.webSocketAuth !== "query") {
16041
+ throw new Error("Invalid webSocketAuth. Valid values: header, ticket, query.");
16039
16042
  }
16040
16043
  }
16041
16044
  function environmentToRemoteTarget(environment) {
@@ -16222,33 +16225,63 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
16222
16225
  throw error;
16223
16226
  }
16224
16227
  }
16225
- createCloudTransportClient(runtime, connectionId) {
16228
+ createCloudTransportClient(runtime, connectionId, channelTickets) {
16226
16229
  const apiKey = getCloudApiKey(this.cloudOptions);
16230
+ const authMode = this.cloudOptions.webSocketAuth ?? "header";
16227
16231
  const url = buildCloudStatusWebSocketUrl({
16228
16232
  apiBaseUrl: this.cloudOptions.apiBaseUrl,
16229
16233
  connectionId,
16230
16234
  agentId: runtime.agent_id,
16231
16235
  conversationId: runtime.conversation_id,
16232
16236
  apiKey,
16233
- authMode: this.cloudOptions.webSocketAuth ?? "header"
16237
+ authMode: authMode === "query" && !channelTickets ? "query" : "header"
16234
16238
  });
16235
16239
  return applyUniqueRequestIds(createAppServerClient({
16236
16240
  url,
16237
16241
  WebSocket: createCloudStatusTransportConstructor({
16238
16242
  url,
16239
16243
  WebSocket: getWebSocketConstructor(this.cloudOptions.WebSocket),
16240
- ...(this.cloudOptions.webSocketAuth ?? "header") === "header" ? { headers: cloudWebSocketHeaders(this.cloudOptions) } : {},
16244
+ ...authMode === "header" ? { headers: cloudWebSocketHeaders(this.cloudOptions) } : {},
16245
+ ...channelTickets ? { channelQuery: channelTickets } : {},
16241
16246
  pingIntervalMs: this.cloudOptions.pingIntervalMs ?? DEFAULT_PING_INTERVAL_MS,
16242
16247
  runtime
16243
16248
  }),
16244
16249
  requestTimeoutMs: this.cloudOptions.requestTimeoutMs ?? DEFAULT_TURN_TIMEOUT_MS
16245
16250
  }));
16246
16251
  }
16252
+ async issueStatusWebSocketTickets(connectionId) {
16253
+ const authMode = this.cloudOptions.webSocketAuth ?? "header";
16254
+ if (authMode !== "ticket" && authMode !== "query")
16255
+ return null;
16256
+ const path2 = `/v1/environments/${encodeURIComponent(connectionId)}/status/ws-ticket`;
16257
+ const issue = async () => {
16258
+ const body = await this.apiClient.post(path2, { body: {} });
16259
+ const ticket = body?.ticket;
16260
+ if (typeof ticket !== "string" || !ticket) {
16261
+ throw new Error("Cloud status WebSocket ticket response did not include a ticket.");
16262
+ }
16263
+ return ticket;
16264
+ };
16265
+ try {
16266
+ const [control, stream] = await Promise.all([issue(), issue()]);
16267
+ return { control: { ticket: control }, stream: { ticket: stream } };
16268
+ } catch (error) {
16269
+ if (authMode === "query" && isNotFound2(error)) {
16270
+ console.warn(JSON.stringify({
16271
+ event: "cloud_status_websocket_query_auth_fallback",
16272
+ connection_id: connectionId
16273
+ }));
16274
+ return null;
16275
+ }
16276
+ throw error;
16277
+ }
16278
+ }
16247
16279
  async connectCloudTransport(runtime, initialConnectionId) {
16248
16280
  let connectionId = initialConnectionId;
16249
16281
  let lastError;
16250
16282
  for (let attempt = 0;attempt < INITIAL_CLOUD_TRANSPORT_ATTEMPTS; attempt++) {
16251
- const client = this.createCloudTransportClient(runtime, connectionId);
16283
+ const channelTickets = await this.issueStatusWebSocketTickets(connectionId);
16284
+ const client = this.createCloudTransportClient(runtime, connectionId, channelTickets);
16252
16285
  this.installTransportHandlers(client);
16253
16286
  try {
16254
16287
  await client.connect();
@@ -18350,4 +18383,4 @@ export {
18350
18383
  CloudManagedSandboxExpiredError
18351
18384
  };
18352
18385
 
18353
- //# debugId=56DE4B3DCF03FA0964756E2164756E21
18386
+ //# debugId=184FD5599A36662B64756E2164756E21