@letta-ai/letta-agent-sdk 0.3.0 → 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
@@ -67,6 +67,29 @@ await session.recoverPendingApprovals();
67
67
  `changeDeviceState()` currently confirms command transport only because the
68
68
  underlying protocol does not acknowledge that mutation.
69
69
 
70
+ The read side of the device state is exposed as a one-shot getter and a
71
+ subscription — enough to restore permission-mode UI and re-surface pending
72
+ approvals when a mobile or web client returns to the foreground:
73
+
74
+ ```ts
75
+ const status = await session.getDeviceStatus();
76
+ // status.permissionMode, status.workingDirectory, status.isOnline,
77
+ // status.isProcessing, status.pendingControlRequests, status.raw
78
+
79
+ const unsubscribe = session.onDeviceStatus((status) => {
80
+ // Called for every device-status update pushed by the runtime.
81
+ });
82
+ unsubscribe();
83
+ ```
84
+
85
+ `getDeviceStatus()` always sends a lightweight, request-correlated `sync`
86
+ (`recover_approvals: false`, `force_device_status: true`) and resolves only
87
+ after the runtime acknowledges it and replays a fresh status. This makes the
88
+ getter safe for foreground reconciliation instead of returning a snapshot
89
+ cached before the app was backgrounded. Pending approval request IDs are for
90
+ correlation; decisions continue through `recoverPendingApprovals()` and the
91
+ session's `canUseTool` callback.
92
+
70
93
  ## Deployment options
71
94
 
72
95
  | Backend | Agent state | Tool execution |
@@ -115,7 +138,7 @@ For authenticated Remote App Servers in React Native, pass the platform WebSocke
115
138
 
116
139
  ## Management APIs
117
140
 
118
- The client exposes agent, conversation, and Cloud repository management alongside active sessions:
141
+ The client exposes agent, conversation, model, and Cloud repository management alongside active sessions:
119
142
 
120
143
  ```ts
121
144
  const agents = await client.agents.list({ tags: ["support"] });
@@ -125,6 +148,11 @@ const conversations = await client.conversations.list({
125
148
  order: "desc",
126
149
  });
127
150
 
151
+ // No open session required — safe for model pickers and settings screens.
152
+ const { entries: models, availableHandles } = await client.models.list();
153
+
154
+ await client.agents.delete(agents[0].id);
155
+
128
156
  const repository = await client.repositories.create({ name: "inputs" });
129
157
  await client.repositories.files.create(repository.id, {
130
158
  path: "brief.md",
@@ -1,6 +1,6 @@
1
1
  import type { ManagementQuery, ManagementTransport } from "./management.js";
2
2
  import type { ConversationMessagesResult, LettaAgent, LettaConversation } from "./management-types.js";
3
- import type { LettaCodeRemoteClientOptions } from "./types.js";
3
+ import type { LettaCodeRemoteClientOptions, ListModelsResult } from "./types.js";
4
4
  type OwnedConnection = {
5
5
  url: string;
6
6
  close(): void;
@@ -15,6 +15,8 @@ export declare class AppServerManagementTransport implements ManagementTransport
15
15
  listAgents(query: ManagementQuery): Promise<LettaAgent[]>;
16
16
  retrieveAgent(agentId: string): Promise<LettaAgent>;
17
17
  updateAgent(agentId: string, body: Record<string, unknown>): Promise<LettaAgent>;
18
+ deleteAgent(agentId: string): Promise<void>;
19
+ listModels(): Promise<ListModelsResult>;
18
20
  listConversations(query: ManagementQuery): Promise<LettaConversation[]>;
19
21
  retrieveConversation(conversationId: string): Promise<LettaConversation>;
20
22
  createConversation(body: Record<string, unknown>): Promise<LettaConversation>;
@@ -1 +1 @@
1
- {"version":3,"file":"app-server-management.d.ts","sourceRoot":"","sources":["../src/app-server-management.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EACV,0BAA0B,EAC1B,UAAU,EACV,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAE/D,KAAK,eAAe,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,IAAI,IAAI,CAAA;CAAE,CAAC;AA4BtD,MAAM,MAAM,0BAA0B,GACpC,OAAO,CAAC,4BAA4B,CAAC,GAAG;IACtC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;CAC1C,CAAC;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from "@letta-ai/letta-code/app-server-client";
2
2
  import { RemoteClientSessionCore, type ProtocolMessage, type RemoteClientRuntimeController, type RuntimeSendTurnOptions, type RuntimeScope, type RuntimeSessionInit, type RuntimeSessionMode } from "./remote-client-session-core.js";
3
- import type { AnyAgentTool, CanUseToolResponse, CreateAgentOptions, LettaCodeRemoteClientOptions, LettaCodeClientSessionOptions, ListModelsResult, ListMessagesOptions, ListMessagesResult, RecoverPendingApprovalsOptions, RecoverPendingApprovalsResult, SendMessage, UpdateModelResult } from "./types.js";
3
+ import type { AnyAgentTool, CanUseToolContext, CanUseToolResponse, CreateAgentOptions, LettaCodeRemoteClientOptions, LettaCodeClientSessionOptions, ListModelsResult, ListMessagesOptions, ListMessagesResult, RecoverPendingApprovalsOptions, RecoverPendingApprovalsResult, SendMessage, UpdateModelResult } from "./types.js";
4
4
  type UpdateModelPayload = {
5
5
  model_id?: string;
6
6
  model_handle?: string;
@@ -17,8 +17,6 @@ export type AppServerSessionOptions = Partial<LettaCodeRemoteClientOptions> & {
17
17
  url: string;
18
18
  close(): void;
19
19
  }>;
20
- /** Whether create-agent runtime_start should pin the created agent globally. */
21
- pinGlobalAgent?: boolean;
22
20
  /** Whether SDK create-agent payloads should add the origin tag automatically. */
23
21
  includeSdkOriginTag?: boolean;
24
22
  };
@@ -39,7 +37,7 @@ type AppServerApprovalResponseDecision = {
39
37
  behavior: "deny";
40
38
  message: string;
41
39
  };
42
- export declare function resolveAppServerToolApproval(options: AppServerApprovalOptions, toolName: string, toolInput: Record<string, unknown>): Promise<CanUseToolResponse>;
40
+ export declare function resolveAppServerToolApproval(options: AppServerApprovalOptions, toolName: string, toolInput: Record<string, unknown>, context?: CanUseToolContext): Promise<CanUseToolResponse>;
43
41
  export declare function toAppServerApprovalDecision(decision: CanUseToolResponse): AppServerApprovalResponseDecision;
44
42
  export declare function registerAppServerControlRequestHandler(config: {
45
43
  client: AppServerClient;
@@ -1 +1 @@
1
- {"version":3,"file":"app-server-session.d.ts","sourceRoot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{ AgentsClient, ConversationsClient } from "./management-types.js";
3
+ import type { AgentsClient, ConversationsClient, ModelsClient } from "./management-types.js";
4
4
  import type { CreateAgentOptions, CreateSessionOptions, LettaCodeBackend, LettaCodeClientOptions, LettaCodeClientSessionOptions, LettaCodeEnvironment, LettaCodeSession, SDKResultMessage, SendMessage } from "./types.js";
5
5
  /**
6
6
  * Top-level Letta Agent SDK client.
@@ -17,6 +17,7 @@ export declare class LettaAgentClientBase {
17
17
  readonly environment: LettaCodeEnvironment | undefined;
18
18
  readonly agents: AgentsClient;
19
19
  readonly conversations: ConversationsClient;
20
+ readonly models: ModelsClient;
20
21
  protected readonly options: LettaCodeClientOptions;
21
22
  private repositoriesClient;
22
23
  private managementTransport;
@@ -1 +1 @@
1
- {"version":3,"file":"client-base.d.ts","sourceRoot":"","sources":["../src/client-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAavD,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,6BAA6B,EAC7B,oBAAoB,EAIpB,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACZ,MAAM,YAAY,CAAC;AAkDpB;;;;;;;;;GASG;AACH,qBAAa,oBAAoB;IAC/B,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,oBAAoB,GAAG,SAAS,CAAC;IACvD,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,mBAAmB,CAAC;IAC5C,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,sBAAsB,CAAC;IACnD,OAAO,CAAC,kBAAkB,CAAmC;IAC7D,OAAO,C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OAAO,CAAC,gBAAgB,CAAC;IAY5B,OAAO,CAAC,oBAAoB;IAsD5B,SAAS,CAAC,mBAAmB,IAAI,OAAO;IAIxC,SAAS,CAAC,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzE,SAAS,CAAC,kBAAkB,CAC1B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,QAAQ,EAAE,6BAA6B,EACvC,eAAe,EAAE,oBAAoB,GACpC,gBAAgB;IAInB,SAAS,CAAC,kBAAkB,CAC1B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,6BAA6B,EACvC,eAAe,EAAE,oBAAoB,GACpC,gBAAgB;IAInB,SAAS,CAAC,4BAA4B,IAAI,KAAK;IAM/C,SAAS,CAAC,8BAA8B,IAAI,mBAAmB;IAI/D,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,qBAAqB;IAQ7B,OAAO,CAAC,sBAAsB;IAgB9B,OAAO,CAAC,YAAY;CAMrB"}
@@ -689,6 +689,32 @@ function ensureResponse(response, value, fallback) {
689
689
  }
690
690
  return value;
691
691
  }
692
+ function modelEntries(value) {
693
+ if (!Array.isArray(value))
694
+ return [];
695
+ return value.flatMap((entry) => {
696
+ if (!entry || typeof entry !== "object" || Array.isArray(entry))
697
+ return [];
698
+ const record = entry;
699
+ if (typeof record.id !== "string" || typeof record.handle !== "string" || typeof record.label !== "string" || typeof record.description !== "string") {
700
+ return [];
701
+ }
702
+ return [{
703
+ ...record,
704
+ id: record.id,
705
+ handle: record.handle,
706
+ label: record.label,
707
+ description: record.description
708
+ }];
709
+ });
710
+ }
711
+ function stringRecord(value) {
712
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
713
+ return;
714
+ }
715
+ const entries = Object.entries(value).filter((entry) => typeof entry[1] === "string");
716
+ return entries.length > 0 ? Object.fromEntries(entries) : undefined;
717
+ }
692
718
 
693
719
  class AppServerManagementTransport {
694
720
  options;
@@ -710,6 +736,30 @@ class AppServerManagementTransport {
710
736
  const response = await this.request("agent_update", { agent_id: agentId, body }, "agent_update_response");
711
737
  return ensureResponse(response, response.agent, `Failed to update agent ${agentId}.`);
712
738
  }
739
+ async deleteAgent(agentId) {
740
+ const response = await this.request("agent_delete", { agent_id: agentId }, "agent_delete_response");
741
+ if (!response.success) {
742
+ throw new Error(response.error ?? `Failed to delete agent ${agentId}.`);
743
+ }
744
+ }
745
+ async listModels() {
746
+ const response = await this.request("list_models", {}, "list_models_response");
747
+ if (!response.success) {
748
+ throw new Error(response.error ?? "Failed to list models.");
749
+ }
750
+ const result = {
751
+ entries: modelEntries(response.entries)
752
+ };
753
+ if (response.available_handles === null) {
754
+ result.availableHandles = null;
755
+ } else if (Array.isArray(response.available_handles)) {
756
+ result.availableHandles = response.available_handles.filter((handle) => typeof handle === "string");
757
+ }
758
+ const aliases = stringRecord(response.byok_provider_aliases);
759
+ if (aliases)
760
+ result.byokProviderAliases = aliases;
761
+ return result;
762
+ }
713
763
  async listConversations(query) {
714
764
  const response = await this.request("conversation_list", { query }, "conversation_list_response");
715
765
  if (!response.success) {
@@ -5405,6 +5455,36 @@ function requiresRuntimeUserInput(toolName) {
5405
5455
  function isHeadlessAutoAllowTool(toolName) {
5406
5456
  return HEADLESS_AUTO_ALLOW_TOOLS.has(toolName);
5407
5457
  }
5458
+ function normalizePermissionSuggestions(value) {
5459
+ if (!Array.isArray(value))
5460
+ return;
5461
+ const suggestions = [];
5462
+ for (const entry of value) {
5463
+ if (!entry || typeof entry !== "object")
5464
+ continue;
5465
+ const record = entry;
5466
+ if (typeof record.id === "string" && typeof record.text === "string") {
5467
+ suggestions.push({ id: record.id, text: record.text });
5468
+ }
5469
+ }
5470
+ return suggestions;
5471
+ }
5472
+ function buildCanUseToolContext(request, requestId) {
5473
+ const context = {};
5474
+ if (typeof requestId === "string")
5475
+ context.requestId = requestId;
5476
+ if (typeof request.tool_call_id === "string")
5477
+ context.toolCallId = request.tool_call_id;
5478
+ const suggestions = normalizePermissionSuggestions(request.permission_suggestions);
5479
+ if (suggestions !== undefined)
5480
+ context.permissionSuggestions = suggestions;
5481
+ if (typeof request.blocked_path === "string" || request.blocked_path === null) {
5482
+ context.blockedPath = request.blocked_path;
5483
+ }
5484
+ if (Array.isArray(request.diffs))
5485
+ context.diffs = request.diffs;
5486
+ return context;
5487
+ }
5408
5488
 
5409
5489
  // src/remote-client-session-core.ts
5410
5490
  var FAILURE_STOP_REASONS = new Set([
@@ -5682,6 +5762,121 @@ function queueItems(message) {
5682
5762
  ];
5683
5763
  });
5684
5764
  }
5765
+ function deviceStatusRecord(message) {
5766
+ if (message.type !== "update_device_status")
5767
+ return null;
5768
+ const status = message.device_status;
5769
+ return status && typeof status === "object" && !Array.isArray(status) ? status : null;
5770
+ }
5771
+ function pendingControlRequests(status) {
5772
+ const pending = status.pending_control_requests;
5773
+ if (!Array.isArray(pending))
5774
+ return [];
5775
+ return pending.flatMap((item) => {
5776
+ if (!item || typeof item !== "object" || Array.isArray(item))
5777
+ return [];
5778
+ const record = item;
5779
+ if (typeof record.request_id !== "string")
5780
+ return [];
5781
+ const request = record.request && typeof record.request === "object" && !Array.isArray(record.request) ? record.request : null;
5782
+ if (!request || typeof request.tool_name !== "string")
5783
+ return [];
5784
+ const entry = {
5785
+ requestId: record.request_id,
5786
+ toolName: request.tool_name,
5787
+ permissionSuggestions: permissionSuggestions(request.permission_suggestions),
5788
+ blockedPath: typeof request.blocked_path === "string" || request.blocked_path === null ? request.blocked_path : null
5789
+ };
5790
+ if (typeof request.tool_call_id === "string")
5791
+ entry.toolCallId = request.tool_call_id;
5792
+ if (request.input && typeof request.input === "object" && !Array.isArray(request.input)) {
5793
+ entry.toolInput = request.input;
5794
+ }
5795
+ const previews = diffPreviews(request.diffs);
5796
+ if (previews !== undefined)
5797
+ entry.diffs = previews;
5798
+ return [entry];
5799
+ });
5800
+ }
5801
+ function permissionSuggestions(value) {
5802
+ if (!Array.isArray(value))
5803
+ return [];
5804
+ return value.flatMap((item) => {
5805
+ if (!item || typeof item !== "object" || Array.isArray(item))
5806
+ return [];
5807
+ const record = item;
5808
+ return typeof record.id === "string" && typeof record.text === "string" ? [{ id: record.id, text: record.text }] : [];
5809
+ });
5810
+ }
5811
+ function diffPreviews(value) {
5812
+ if (!Array.isArray(value))
5813
+ return;
5814
+ return value.flatMap((item) => {
5815
+ if (!item || typeof item !== "object" || Array.isArray(item))
5816
+ return [];
5817
+ const record = item;
5818
+ if (record.mode === "advanced" && typeof record.fileName === "string" && Array.isArray(record.hunks)) {
5819
+ return [{
5820
+ mode: "advanced",
5821
+ fileName: record.fileName,
5822
+ hunks: diffHunks(record.hunks)
5823
+ }];
5824
+ }
5825
+ if ((record.mode === "fallback" || record.mode === "unpreviewable") && typeof record.fileName === "string" && typeof record.reason === "string") {
5826
+ return [{
5827
+ mode: record.mode,
5828
+ fileName: record.fileName,
5829
+ reason: record.reason
5830
+ }];
5831
+ }
5832
+ return [];
5833
+ });
5834
+ }
5835
+ function diffHunks(value) {
5836
+ return value.flatMap((item) => {
5837
+ if (!item || typeof item !== "object" || Array.isArray(item))
5838
+ return [];
5839
+ const record = item;
5840
+ if (typeof record.oldStart !== "number" || typeof record.oldLines !== "number" || typeof record.newStart !== "number" || typeof record.newLines !== "number" || !Array.isArray(record.lines)) {
5841
+ return [];
5842
+ }
5843
+ const lines = [];
5844
+ for (const line of record.lines) {
5845
+ if (!line || typeof line !== "object" || Array.isArray(line))
5846
+ continue;
5847
+ const lineRecord = line;
5848
+ const type = lineRecord.type;
5849
+ if (type !== "context" && type !== "add" && type !== "remove" || typeof lineRecord.content !== "string") {
5850
+ continue;
5851
+ }
5852
+ lines.push({
5853
+ type,
5854
+ content: lineRecord.content
5855
+ });
5856
+ }
5857
+ return [{
5858
+ oldStart: record.oldStart,
5859
+ oldLines: record.oldLines,
5860
+ newStart: record.newStart,
5861
+ newLines: record.newLines,
5862
+ lines
5863
+ }];
5864
+ });
5865
+ }
5866
+ function toSessionDeviceStatus(status) {
5867
+ const permissionMode = normalizePermissionMode(status.current_permission_mode);
5868
+ if (typeof status.is_online !== "boolean" || typeof status.is_processing !== "boolean" || permissionMode === undefined || !(typeof status.current_working_directory === "string" || status.current_working_directory === null)) {
5869
+ return null;
5870
+ }
5871
+ return {
5872
+ isOnline: status.is_online,
5873
+ isProcessing: status.is_processing,
5874
+ permissionMode,
5875
+ workingDirectory: status.current_working_directory,
5876
+ pendingControlRequests: pendingControlRequests(status),
5877
+ raw: { ...status }
5878
+ };
5879
+ }
5685
5880
  function normalizeSendMessage(message) {
5686
5881
  return message;
5687
5882
  }
@@ -5709,6 +5904,8 @@ class RemoteClientSessionCore {
5709
5904
  messageCounter = 0;
5710
5905
  clientMessageCounter = 0;
5711
5906
  toolNames;
5907
+ deviceStatusListeners = new Set;
5908
+ deviceStatusRefreshCancels = new Set;
5712
5909
  constructor(mode, config) {
5713
5910
  this.mode = mode;
5714
5911
  this.label = config.label;
@@ -5899,6 +6096,86 @@ class RemoteClientSessionCore {
5899
6096
  removed: response.success
5900
6097
  };
5901
6098
  }
6099
+ async getDeviceStatus(options = {}) {
6100
+ if (!this.initialized) {
6101
+ await this.initialize();
6102
+ }
6103
+ if (!this.controller || !this.runtime) {
6104
+ throw new Error("Session is not initialized");
6105
+ }
6106
+ const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs ?? 30000;
6107
+ if (!Number.isInteger(timeoutMs) || timeoutMs <= 0) {
6108
+ throw new Error("Invalid device status timeout. Expected a positive integer.");
6109
+ }
6110
+ return this.refreshDeviceStatus(timeoutMs);
6111
+ }
6112
+ onDeviceStatus(listener) {
6113
+ if (typeof listener !== "function") {
6114
+ throw new Error("Invalid device status listener. Expected a function.");
6115
+ }
6116
+ this.deviceStatusListeners.add(listener);
6117
+ return () => {
6118
+ this.deviceStatusListeners.delete(listener);
6119
+ };
6120
+ }
6121
+ refreshDeviceStatus(timeoutMs) {
6122
+ const controller = this.controller;
6123
+ const runtime = this.runtime;
6124
+ if (!controller || !runtime) {
6125
+ return Promise.reject(new Error("Session is not initialized"));
6126
+ }
6127
+ return new Promise((resolve, reject) => {
6128
+ let status = null;
6129
+ let syncAcknowledged = false;
6130
+ let settled = false;
6131
+ const cleanup = () => {
6132
+ clearTimeout(timer);
6133
+ unsubscribe();
6134
+ this.deviceStatusRefreshCancels.delete(cancel);
6135
+ };
6136
+ const rejectOnce = (error) => {
6137
+ if (settled)
6138
+ return;
6139
+ settled = true;
6140
+ cleanup();
6141
+ reject(error);
6142
+ };
6143
+ const resolveIfComplete = () => {
6144
+ if (settled || !syncAcknowledged || !status)
6145
+ return;
6146
+ settled = true;
6147
+ cleanup();
6148
+ resolve(status);
6149
+ };
6150
+ const cancel = (error) => rejectOnce(error);
6151
+ const timer = setTimeout(() => {
6152
+ rejectOnce(new Error(`Timed out waiting for ${this.label} device status`));
6153
+ }, timeoutMs);
6154
+ timer.unref?.();
6155
+ const unsubscribe = this.onDeviceStatus((nextStatus) => {
6156
+ status = nextStatus;
6157
+ resolveIfComplete();
6158
+ });
6159
+ this.deviceStatusRefreshCancels.add(cancel);
6160
+ controller.request("sync", {
6161
+ runtime,
6162
+ recover_approvals: false,
6163
+ force_device_status: true
6164
+ }, {
6165
+ timeoutMs,
6166
+ predicate: (message) => message.type === "sync_response"
6167
+ }).then((response) => {
6168
+ if (response.success === false) {
6169
+ rejectOnce(new Error(typeof response.error === "string" ? response.error : `Failed to refresh ${this.label} device status`));
6170
+ return;
6171
+ }
6172
+ syncAcknowledged = true;
6173
+ resolveIfComplete();
6174
+ }, (error) => {
6175
+ rejectOnce(error instanceof Error ? error : new Error(String(error)));
6176
+ });
6177
+ });
6178
+ }
5902
6179
  async listMessages(options = {}) {
5903
6180
  if (!this.initialized) {
5904
6181
  await this.initialize();
@@ -5951,6 +6228,11 @@ class RemoteClientSessionCore {
5951
6228
  }
5952
6229
  this.activeTurn = null;
5953
6230
  this.pendingTurns.length = 0;
6231
+ for (const cancel of [...this.deviceStatusRefreshCancels]) {
6232
+ cancel(new Error(`Session closed while waiting for ${this.label} device status`));
6233
+ }
6234
+ this.deviceStatusRefreshCancels.clear();
6235
+ this.deviceStatusListeners.clear();
5954
6236
  this.controller?.close();
5955
6237
  this.controller = null;
5956
6238
  this.onCoreClose();
@@ -6188,6 +6470,18 @@ class RemoteClientSessionCore {
6188
6470
  handleProtocolMessage = (message) => {
6189
6471
  if (!this.runtime || !sameRuntime2(message, this.runtime))
6190
6472
  return;
6473
+ const deviceStatus = deviceStatusRecord(message);
6474
+ if (deviceStatus) {
6475
+ const status = toSessionDeviceStatus(deviceStatus);
6476
+ if (!status)
6477
+ return;
6478
+ for (const listener of [...this.deviceStatusListeners]) {
6479
+ try {
6480
+ listener(status);
6481
+ } catch {}
6482
+ }
6483
+ return;
6484
+ }
6191
6485
  if (message.type === "update_queue") {
6192
6486
  const sdkMessage2 = {
6193
6487
  type: "queue_update",
@@ -6617,7 +6911,7 @@ function createExternalToolCallHandler(externalTools) {
6617
6911
  };
6618
6912
  };
6619
6913
  }
6620
- async function resolveAppServerToolApproval(options, toolName, toolInput) {
6914
+ async function resolveAppServerToolApproval(options, toolName, toolInput, context) {
6621
6915
  const hasCallback = typeof options.canUseTool === "function";
6622
6916
  const toolNeedsRuntimeUserInput = requiresRuntimeUserInput(toolName);
6623
6917
  if (toolNeedsRuntimeUserInput && !hasCallback) {
@@ -6632,7 +6926,7 @@ async function resolveAppServerToolApproval(options, toolName, toolInput) {
6632
6926
  }
6633
6927
  if (hasCallback) {
6634
6928
  try {
6635
- const result = await options.canUseTool(toolName, toolInput);
6929
+ const result = await options.canUseTool(toolName, toolInput, context);
6636
6930
  if (result.behavior === "allow") {
6637
6931
  return {
6638
6932
  behavior: "allow",
@@ -6692,7 +6986,7 @@ function toAppServerApprovalDecision(decision) {
6692
6986
  selected_permission_suggestion_ids: selectedPermissionSuggestionIds
6693
6987
  };
6694
6988
  }
6695
- function stringRecord(value) {
6989
+ function stringRecord2(value) {
6696
6990
  if (!value || typeof value !== "object" || Array.isArray(value))
6697
6991
  return;
6698
6992
  const record = {};
@@ -6738,7 +7032,7 @@ function normalizeListModelsResponse(response) {
6738
7032
  } else if (Array.isArray(response.available_handles)) {
6739
7033
  result.availableHandles = response.available_handles.filter((handle) => typeof handle === "string");
6740
7034
  }
6741
- const aliases = stringRecord(response.byok_provider_aliases);
7035
+ const aliases = stringRecord2(response.byok_provider_aliases);
6742
7036
  if (aliases)
6743
7037
  result.byokProviderAliases = aliases;
6744
7038
  return result;
@@ -6793,7 +7087,7 @@ async function respondToAppServerControlRequest(config, message) {
6793
7087
  return;
6794
7088
  const toolName = typeof requestRecord.tool_name === "string" ? requestRecord.tool_name : "unknown";
6795
7089
  const toolInput = requestRecord.input && typeof requestRecord.input === "object" && !Array.isArray(requestRecord.input) ? requestRecord.input : {};
6796
- const decision = await resolveAppServerToolApproval(config.getOptions(), toolName, toolInput);
7090
+ const decision = await resolveAppServerToolApproval(config.getOptions(), toolName, toolInput, buildCanUseToolContext(requestRecord, requestId));
6797
7091
  config.client.input({
6798
7092
  runtime,
6799
7093
  payload: {
@@ -7136,6 +7430,19 @@ function asArray(body, action) {
7136
7430
  }
7137
7431
  return body;
7138
7432
  }
7433
+ function cloudModelEntry(raw) {
7434
+ if (typeof raw.handle !== "string" || raw.handle.length === 0) {
7435
+ return null;
7436
+ }
7437
+ const label = typeof raw.display_name === "string" ? raw.display_name : typeof raw.name === "string" ? raw.name : raw.handle;
7438
+ return {
7439
+ ...raw,
7440
+ id: typeof raw.id === "string" && raw.id.length > 0 ? raw.id : raw.handle,
7441
+ handle: raw.handle,
7442
+ label,
7443
+ description: typeof raw.description === "string" ? raw.description : ""
7444
+ };
7445
+ }
7139
7446
 
7140
7447
  class CloudManagementTransport {
7141
7448
  options;
@@ -7151,6 +7458,20 @@ class CloudManagementTransport {
7151
7458
  updateAgent(agentId, body) {
7152
7459
  return this.requestObject(`/v1/agents/${encodeURIComponent(agentId)}`, "PATCH", body, "Cloud update agent");
7153
7460
  }
7461
+ async deleteAgent(agentId) {
7462
+ await this.requestUrl(this.url(`/v1/agents/${encodeURIComponent(agentId)}`), "DELETE", undefined, "Cloud delete agent");
7463
+ }
7464
+ async listModels() {
7465
+ const entries = await this.getArray("/v1/models", {}, "Cloud list models");
7466
+ const normalized = entries.flatMap((entry) => {
7467
+ const model = cloudModelEntry(entry);
7468
+ return model ? [model] : [];
7469
+ });
7470
+ return {
7471
+ entries: normalized,
7472
+ availableHandles: normalized.map((entry) => entry.handle)
7473
+ };
7474
+ }
7154
7475
  listConversations(query) {
7155
7476
  return this.getArray("/v1/conversations/", query, "Cloud list conversations");
7156
7477
  }
@@ -8235,6 +8556,11 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
8235
8556
  function definedEntries(values) {
8236
8557
  return Object.fromEntries(Object.entries(values).filter(([, value]) => value !== undefined));
8237
8558
  }
8559
+ function assertNonEmptyId(value, name) {
8560
+ if (typeof value !== "string" || value.trim().length === 0) {
8561
+ throw new Error(`Invalid ${name}. Expected a non-empty string.`);
8562
+ }
8563
+ }
8238
8564
  function agentListQuery(options) {
8239
8565
  const orderBy = options.orderBy?.replace(/[A-Z]/g, (character) => `_${character.toLowerCase()}`);
8240
8566
  return {
@@ -8307,7 +8633,16 @@ function createAgentsClient(transport) {
8307
8633
  return {
8308
8634
  list: (options = {}) => transport().listAgents(agentListQuery(options)),
8309
8635
  retrieve: (agentId) => transport().retrieveAgent(agentId),
8310
- update: (agentId, options) => transport().updateAgent(agentId, agentUpdateBody(options))
8636
+ update: (agentId, options) => transport().updateAgent(agentId, agentUpdateBody(options)),
8637
+ delete: async (agentId) => {
8638
+ assertNonEmptyId(agentId, "agent id");
8639
+ await transport().deleteAgent(agentId);
8640
+ }
8641
+ };
8642
+ }
8643
+ function createModelsClient(transport) {
8644
+ return {
8645
+ list: () => transport().listModels()
8311
8646
  };
8312
8647
  }
8313
8648
  function createConversationsClient(transport) {
@@ -8478,6 +8813,7 @@ class LettaAgentClientBase {
8478
8813
  environment;
8479
8814
  agents;
8480
8815
  conversations;
8816
+ models;
8481
8817
  options;
8482
8818
  repositoriesClient = null;
8483
8819
  managementTransport = null;
@@ -8491,6 +8827,7 @@ class LettaAgentClientBase {
8491
8827
  this.options = options;
8492
8828
  this.agents = createAgentsClient(() => this.getManagementTransport());
8493
8829
  this.conversations = createConversationsClient(() => this.getManagementTransport());
8830
+ this.models = createModelsClient(() => this.getManagementTransport());
8494
8831
  if (this.backend === "local" && this.environment !== undefined) {
8495
8832
  throw new Error('LettaAgentClient environment is only valid with backend: "cloud".');
8496
8833
  }
@@ -8803,4 +9140,4 @@ export {
8803
9140
  CloudManagedSandboxExpiredError
8804
9141
  };
8805
9142
 
8806
- //# debugId=1456942A1FCDB34964756E2164756E21
9143
+ //# debugId=071CEF1290505F1D64756E2164756E21