@letta-ai/letta-code 0.34.48 → 0.34.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/app-server-client.cjs +32 -4
  2. package/dist/app-server-client.cjs.map +4 -4
  3. package/dist/app-server-client.js +32 -4
  4. package/dist/app-server-client.js.map +4 -4
  5. package/dist/mcp-client.js +2 -2
  6. package/dist/mcp-client.js.map +1 -1
  7. package/dist/mcp-oauth.js +2 -2
  8. package/dist/mcp-oauth.js.map +1 -1
  9. package/dist/types/agent/subagents/ephemeral-subagent.d.ts +56 -0
  10. package/dist/types/agent/subagents/ephemeral-subagent.d.ts.map +1 -0
  11. package/dist/types/agent/subagents/manager.d.ts +3 -3
  12. package/dist/types/agent/subagents/manager.d.ts.map +1 -1
  13. package/dist/types/agent/subagents/subagent-reminders.d.ts +9 -0
  14. package/dist/types/agent/subagents/subagent-reminders.d.ts.map +1 -0
  15. package/dist/types/app-server-client.d.ts.map +1 -1
  16. package/dist/types/backend/api/ephemeral-conversations.d.ts +4 -0
  17. package/dist/types/backend/api/ephemeral-conversations.d.ts.map +1 -1
  18. package/dist/types/mcp-scope.d.ts +5 -0
  19. package/dist/types/mcp-scope.d.ts.map +1 -1
  20. package/dist/types/runtime-context.d.ts +2 -0
  21. package/dist/types/runtime-context.d.ts.map +1 -1
  22. package/dist/types/tools/client-tool-background.d.ts +16 -0
  23. package/dist/types/tools/client-tool-background.d.ts.map +1 -0
  24. package/dist/types/tools/external-tool-background.d.ts +4 -1
  25. package/dist/types/tools/external-tool-background.d.ts.map +1 -1
  26. package/dist/types/tools/external-tool-execution.d.ts +9 -0
  27. package/dist/types/tools/external-tool-execution.d.ts.map +1 -0
  28. package/dist/types/tools/external-tool-types.d.ts +4 -0
  29. package/dist/types/tools/external-tool-types.d.ts.map +1 -1
  30. package/dist/types/tools/foreground-yield.d.ts +12 -0
  31. package/dist/types/tools/foreground-yield.d.ts.map +1 -0
  32. package/dist/types/tools/impl/bash.d.ts.map +1 -1
  33. package/dist/types/tools/impl/code-mode.d.ts.map +1 -1
  34. package/dist/types/tools/impl/exec-command.d.ts.map +1 -1
  35. package/dist/types/tools/impl/external-llm-trace-session.d.ts +1 -0
  36. package/dist/types/tools/impl/external-llm-trace-session.d.ts.map +1 -1
  37. package/dist/types/tools/impl/github-pull-request-cloud.d.ts +75 -0
  38. package/dist/types/tools/impl/github-pull-request-cloud.d.ts.map +1 -0
  39. package/dist/types/tools/impl/kill-bash.d.ts.map +1 -1
  40. package/dist/types/tools/impl/process_manager.d.ts +7 -1
  41. package/dist/types/tools/impl/process_manager.d.ts.map +1 -1
  42. package/dist/types/tools/impl/remote-external-coding-agent.d.ts.map +1 -1
  43. package/dist/types/tools/impl/send-agent-message.d.ts +6 -0
  44. package/dist/types/tools/impl/send-agent-message.d.ts.map +1 -1
  45. package/dist/types/tools/impl/shell-env.d.ts.map +1 -1
  46. package/dist/types/tools/impl/task-stop.d.ts +2 -0
  47. package/dist/types/tools/impl/task-stop.d.ts.map +1 -1
  48. package/dist/types/tools/impl/task.d.ts.map +1 -1
  49. package/dist/types/tools/impl/watch-pr.d.ts.map +1 -1
  50. package/dist/types/tools/impl/workflow.d.ts +1 -0
  51. package/dist/types/tools/impl/workflow.d.ts.map +1 -1
  52. package/dist/types/tools/manager.d.ts +1 -0
  53. package/dist/types/tools/manager.d.ts.map +1 -1
  54. package/dist/types/tools/remote-external-tool-background.d.ts +15 -0
  55. package/dist/types/tools/remote-external-tool-background.d.ts.map +1 -0
  56. package/dist/types/tools/toolset-catalog.d.ts +1 -1
  57. package/dist/types/tools/toolset.d.ts +3 -0
  58. package/dist/types/tools/toolset.d.ts.map +1 -1
  59. package/dist/types/tools/workflow/format-stats.d.ts +4 -0
  60. package/dist/types/tools/workflow/format-stats.d.ts.map +1 -1
  61. package/dist/types/tools/workflow/sdk-spawner.d.ts +7 -0
  62. package/dist/types/tools/workflow/sdk-spawner.d.ts.map +1 -1
  63. package/dist/types/tools/workflow/types.d.ts +19 -2
  64. package/dist/types/tools/workflow/types.d.ts.map +1 -1
  65. package/dist/types/tools/workflow/workflow-engine.d.ts.map +1 -1
  66. package/dist/types/types/app-server-info.d.ts +2 -0
  67. package/dist/types/types/app-server-info.d.ts.map +1 -1
  68. package/dist/types/types/external-tool-protocol.d.ts +15 -0
  69. package/dist/types/types/external-tool-protocol.d.ts.map +1 -1
  70. package/dist/types/types/protocol_v2.d.ts +2 -2
  71. package/dist/types/types/protocol_v2.d.ts.map +1 -1
  72. package/dist/types/utils/process-liveness.d.ts +7 -1
  73. package/dist/types/utils/process-liveness.d.ts.map +1 -1
  74. package/dist/types/utils/secrets-store.d.ts +6 -0
  75. package/dist/types/utils/secrets-store.d.ts.map +1 -1
  76. package/dist/types/websocket/listener/durable-file-lock.d.ts.map +1 -1
  77. package/letta.js +29465 -28574
  78. package/npm-shrinkwrap.json +140 -140
  79. package/package.json +2 -2
  80. package/scripts/source-file-size-baseline.json +2 -2
  81. package/skills/using-mcp-tools/SKILL.md +89 -1
  82. package/skills/using-mcp-tools/scripts/manage-managed-events.mjs +380 -0
  83. package/skills/workflow-authoring/SKILL.md +9 -0
@@ -0,0 +1,380 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { open } from "node:fs/promises";
4
+ import { pathToFileURL } from "node:url";
5
+
6
+ const COMMANDS = new Set([
7
+ "cancel",
8
+ "connections",
9
+ "list",
10
+ "subscribe",
11
+ "types",
12
+ ]);
13
+ const BOOLEAN_OPTIONS = new Set(["confirm"]);
14
+ const MAX_BODY_BYTES = 1024 * 1024;
15
+
16
+ function usage() {
17
+ console.error(`Usage:
18
+ node manage-managed-events.mjs connections
19
+ node manage-managed-events.mjs types --service-id <service> --server-id <id> [--cursor <cursor>] [--limit <1-50>]
20
+ node manage-managed-events.mjs list --service-id <service> --server-id <id> [--cursor <cursor>] [--limit <1-50>]
21
+ node manage-managed-events.mjs subscribe --service-id <service> --server-id <id> --trigger-slug <slug> --webhook-id <id> [--config-file <path>] --confirm
22
+ node manage-managed-events.mjs cancel --service-id <service> --server-id <id> --trigger-id <id> --confirm
23
+
24
+ Environment:
25
+ LETTA_API_KEY Required Cloud API credential from the active runtime
26
+ LETTA_BASE_URL Active server supplied by the runtime
27
+ AGENT_ID Required current agent; cannot be overridden
28
+ `);
29
+ process.exit(2);
30
+ }
31
+
32
+ const COMMAND_OPTIONS = new Map([
33
+ ["connections", new Set()],
34
+ ["types", new Set(["cursor", "limit", "server-id", "service-id"])],
35
+ ["list", new Set(["cursor", "limit", "server-id", "service-id"])],
36
+ [
37
+ "subscribe",
38
+ new Set([
39
+ "config-file",
40
+ "confirm",
41
+ "server-id",
42
+ "service-id",
43
+ "trigger-slug",
44
+ "webhook-id",
45
+ ]),
46
+ ],
47
+ ["cancel", new Set(["confirm", "server-id", "service-id", "trigger-id"])],
48
+ ]);
49
+
50
+ export function parseManagedEventArgs(argv) {
51
+ const [command = "", ...rest] = argv;
52
+ if (!COMMANDS.has(command)) usage();
53
+ const allowed = COMMAND_OPTIONS.get(command);
54
+ if (!allowed) throw new Error(`Unsupported command: ${command}`);
55
+ const args = {};
56
+ for (let index = 0; index < rest.length; index += 1) {
57
+ const option = rest[index];
58
+ if (option === "--help" || option === "-h") usage();
59
+ if (!option?.startsWith("--")) {
60
+ throw new Error(`Unexpected positional argument: ${option ?? ""}`);
61
+ }
62
+ const key = option.slice(2);
63
+ if (!allowed.has(key)) {
64
+ throw new Error(`Unsupported option --${key} for ${command}`);
65
+ }
66
+ if (Object.hasOwn(args, key)) {
67
+ throw new Error(`Duplicate option --${key}`);
68
+ }
69
+ if (BOOLEAN_OPTIONS.has(key)) {
70
+ args[key] = true;
71
+ continue;
72
+ }
73
+ const value = rest[++index];
74
+ if (!value || value.startsWith("--")) {
75
+ throw new Error(`Missing value for --${key}`);
76
+ }
77
+ args[key] = value;
78
+ }
79
+ return { args, command };
80
+ }
81
+
82
+ function requiredString(value, message) {
83
+ if (typeof value !== "string" || !value.trim()) throw new Error(message);
84
+ return value.trim();
85
+ }
86
+
87
+ function normalizedBaseUrl(value) {
88
+ const parsed = new URL(
89
+ requiredString(value, "LETTA_BASE_URL is required from the active runtime"),
90
+ );
91
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
92
+ throw new Error("LETTA_BASE_URL must use http or https");
93
+ }
94
+ const loopback = new Set(["localhost", "127.0.0.1", "[::1]"]);
95
+ if (parsed.protocol === "http:" && !loopback.has(parsed.hostname)) {
96
+ throw new Error("Plaintext LETTA_BASE_URL is allowed only on loopback");
97
+ }
98
+ parsed.pathname = parsed.pathname.replace(/\/$/, "");
99
+ parsed.search = "";
100
+ parsed.hash = "";
101
+ parsed.username = "";
102
+ parsed.password = "";
103
+ return parsed.toString().replace(/\/$/, "");
104
+ }
105
+
106
+ function positiveLimit(value) {
107
+ if (value === undefined) return undefined;
108
+ if (!/^\d+$/.test(value)) throw new Error("--limit must be an integer");
109
+ const limit = Number(value);
110
+ if (limit < 1 || limit > 50) {
111
+ throw new Error("--limit must be between 1 and 50");
112
+ }
113
+ return limit;
114
+ }
115
+
116
+ async function readBoundedJsonObject(path) {
117
+ const file = await open(path, "r");
118
+ try {
119
+ const stat = await file.stat();
120
+ if (stat.size > MAX_BODY_BYTES) {
121
+ throw new Error("Trigger configuration exceeds 1 MiB");
122
+ }
123
+ const text = await file.readFile("utf8");
124
+ const value = JSON.parse(text);
125
+ if (!value || Array.isArray(value) || typeof value !== "object") {
126
+ throw new Error("Trigger configuration must be a JSON object");
127
+ }
128
+ return value;
129
+ } finally {
130
+ await file.close();
131
+ }
132
+ }
133
+
134
+ async function readBoundedBody(response) {
135
+ const declared = Number(response.headers.get("content-length"));
136
+ if (Number.isFinite(declared) && declared > MAX_BODY_BYTES) {
137
+ throw new Error("Cloud API response exceeds 1 MiB");
138
+ }
139
+ if (!response.body) return null;
140
+ const chunks = [];
141
+ let total = 0;
142
+ const reader = response.body.getReader();
143
+ while (true) {
144
+ const { done, value } = await reader.read();
145
+ if (done) break;
146
+ total += value.byteLength;
147
+ if (total > MAX_BODY_BYTES) {
148
+ await reader.cancel();
149
+ throw new Error("Cloud API response exceeds 1 MiB");
150
+ }
151
+ chunks.push(Buffer.from(value));
152
+ }
153
+ const text = Buffer.concat(chunks).toString("utf8");
154
+ if (!text) return null;
155
+ try {
156
+ return JSON.parse(text);
157
+ } catch {
158
+ throw new Error("Cloud API returned invalid JSON");
159
+ }
160
+ }
161
+
162
+ function isRecord(value) {
163
+ return Boolean(value && typeof value === "object" && !Array.isArray(value));
164
+ }
165
+
166
+ function safeError(body, status) {
167
+ return {
168
+ status,
169
+ error_code:
170
+ isRecord(body) && typeof body.error_code === "string"
171
+ ? body.error_code
172
+ : "managed_event_request_failed",
173
+ message:
174
+ isRecord(body) && typeof body.message === "string"
175
+ ? body.message
176
+ : "Managed event request failed",
177
+ };
178
+ }
179
+
180
+ function mutationAmbiguous(command, status, reason) {
181
+ return {
182
+ operation: command,
183
+ status: "accepted_unconfirmed",
184
+ ...(status ? { http_status: status } : {}),
185
+ reason,
186
+ guidance:
187
+ command === "subscribe"
188
+ ? "List subscriptions and reconcile the trigger slug, configuration, and webhook before retrying."
189
+ : "List subscriptions and reconcile the trigger ID before retrying.",
190
+ };
191
+ }
192
+
193
+ function managedPath(agentId, args, suffix) {
194
+ const serviceId = requiredString(
195
+ args["service-id"],
196
+ "--service-id is required",
197
+ );
198
+ const serverId = requiredString(args["server-id"], "--server-id is required");
199
+ return `/v1/agents/${encodeURIComponent(agentId)}/managed-mcp-connections/${encodeURIComponent(serviceId)}/${encodeURIComponent(serverId)}/${suffix}`;
200
+ }
201
+
202
+ function pageQuery(args) {
203
+ const query = new URLSearchParams();
204
+ const limit = positiveLimit(args.limit);
205
+ if (limit) query.set("limit", String(limit));
206
+ if (args.cursor)
207
+ query.set(
208
+ "cursor",
209
+ requiredString(args.cursor, "--cursor must be non-empty"),
210
+ );
211
+ const encoded = query.toString();
212
+ return encoded ? `?${encoded}` : "";
213
+ }
214
+
215
+ export async function runManagedEventCommand(parsed, dependencies = {}) {
216
+ const env = dependencies.env ?? process.env;
217
+ const fetchImpl = dependencies.fetch ?? fetch;
218
+ const agentId = requiredString(
219
+ env.AGENT_ID ?? env.LETTA_AGENT_ID,
220
+ "AGENT_ID is required; this helper only manages the current agent",
221
+ );
222
+ const apiKey = requiredString(env.LETTA_API_KEY, "LETTA_API_KEY is required");
223
+ const baseUrl = normalizedBaseUrl(env.LETTA_BASE_URL);
224
+ const { args, command } = parsed;
225
+ let path;
226
+ let method = "GET";
227
+ let body;
228
+
229
+ if (command === "connections") {
230
+ path = `/v1/agents/${encodeURIComponent(agentId)}/connections`;
231
+ } else if (command === "types") {
232
+ path = `${managedPath(agentId, args, "trigger-types")}${pageQuery(args)}`;
233
+ } else if (command === "list") {
234
+ path = `${managedPath(agentId, args, "trigger-subscriptions")}${pageQuery(args)}`;
235
+ } else if (command === "subscribe") {
236
+ if (!args.confirm) throw new Error("subscribe requires --confirm");
237
+ method = "POST";
238
+ path = managedPath(agentId, args, "trigger-subscriptions");
239
+ body = {
240
+ trigger_slug: requiredString(
241
+ args["trigger-slug"],
242
+ "--trigger-slug is required",
243
+ ),
244
+ webhook_id: requiredString(
245
+ args["webhook-id"],
246
+ "--webhook-id is required",
247
+ ),
248
+ ...(args["config-file"]
249
+ ? { trigger_config: await readBoundedJsonObject(args["config-file"]) }
250
+ : {}),
251
+ };
252
+ } else {
253
+ if (!args.confirm) throw new Error("cancel requires --confirm");
254
+ method = "DELETE";
255
+ const triggerId = requiredString(
256
+ args["trigger-id"],
257
+ "--trigger-id is required",
258
+ );
259
+ path = managedPath(
260
+ agentId,
261
+ args,
262
+ `trigger-subscriptions/${encodeURIComponent(triggerId)}`,
263
+ );
264
+ }
265
+
266
+ let response;
267
+ try {
268
+ response = await fetchImpl(`${baseUrl}${path}`, {
269
+ method,
270
+ redirect: "error",
271
+ headers: {
272
+ authorization: `Bearer ${apiKey}`,
273
+ ...(body ? { "content-type": "application/json" } : {}),
274
+ },
275
+ ...(body ? { body: JSON.stringify(body) } : {}),
276
+ signal: AbortSignal.timeout(10_000),
277
+ });
278
+ } catch (error) {
279
+ if (method !== "GET") {
280
+ return mutationAmbiguous(
281
+ command,
282
+ undefined,
283
+ error instanceof Error ? error.message : "transport failure",
284
+ );
285
+ }
286
+ throw error;
287
+ }
288
+
289
+ if (command === "cancel" && response.status === 204) {
290
+ return { cancelled: true, trigger_id: args["trigger-id"] };
291
+ }
292
+
293
+ let responseBody;
294
+ try {
295
+ responseBody = await readBoundedBody(response);
296
+ } catch (error) {
297
+ if (method !== "GET" && response.ok) {
298
+ return mutationAmbiguous(
299
+ command,
300
+ response.status,
301
+ error instanceof Error ? error.message : "unreadable response",
302
+ );
303
+ }
304
+ throw error;
305
+ }
306
+
307
+ if (!response.ok) {
308
+ if (method !== "GET" && [408, 429].includes(response.status)) {
309
+ return mutationAmbiguous(
310
+ command,
311
+ response.status,
312
+ "non-definitive response",
313
+ );
314
+ }
315
+ if (method !== "GET" && response.status >= 500) {
316
+ return mutationAmbiguous(
317
+ command,
318
+ response.status,
319
+ "provider result is unknown",
320
+ );
321
+ }
322
+ const error = safeError(responseBody, response.status);
323
+ throw Object.assign(new Error(error.message), { details: error });
324
+ }
325
+
326
+ if (!isRecord(responseBody)) {
327
+ if (method !== "GET") {
328
+ return mutationAmbiguous(
329
+ command,
330
+ response.status,
331
+ "invalid success response",
332
+ );
333
+ }
334
+ throw new Error("Cloud API returned an invalid response");
335
+ }
336
+ if (command === "connections") {
337
+ const connections = Array.isArray(responseBody.connections)
338
+ ? responseBody.connections
339
+ : [];
340
+ return {
341
+ connections: connections.flatMap((connection) =>
342
+ isRecord(connection) &&
343
+ typeof connection.service === "string" &&
344
+ typeof connection.mcp_server_id === "string"
345
+ ? [
346
+ {
347
+ display_name:
348
+ typeof connection.display_name === "string"
349
+ ? connection.display_name
350
+ : connection.service,
351
+ service_id: connection.service,
352
+ mcp_server_id: connection.mcp_server_id,
353
+ },
354
+ ]
355
+ : [],
356
+ ),
357
+ };
358
+ }
359
+ return responseBody;
360
+ }
361
+
362
+ async function main() {
363
+ try {
364
+ const result = await runManagedEventCommand(
365
+ parseManagedEventArgs(process.argv.slice(2)),
366
+ );
367
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
368
+ } catch (error) {
369
+ const details =
370
+ isRecord(error) && isRecord(error.details) ? error.details : null;
371
+ process.stderr.write(
372
+ `${JSON.stringify(details ?? { error: { message: error instanceof Error ? error.message : String(error) } }, null, 2)}\n`,
373
+ );
374
+ process.exitCode = 1;
375
+ }
376
+ }
377
+
378
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
379
+ await main();
380
+ }
@@ -100,6 +100,15 @@ Cloud decisions service.
100
100
  - `phase(title)` — start a new phase; subsequent agent() calls are grouped
101
101
  under this title in progress output.
102
102
  - `log(message)` — emit a progress message to the user.
103
+ - `budget` — live run cost in USD: `budget.spent`, `budget.limit`, and
104
+ `budget.remaining` (limit and remaining are `null` without a `maxCostUsd`;
105
+ spent and remaining are `null` once any usage had no cost estimate).
106
+ With a budget, reaching it stops the run: pending and new calls reject with
107
+ `code: "budget_exceeded"` and running subagents are interrupted (a model
108
+ request already in flight finishes first, so the final spend can exceed the
109
+ limit by that much). Check `budget.remaining` between stages to skip
110
+ optional work (an extra verification pass) instead of hitting the limit
111
+ mid-stage.
103
112
  - `decide(state, questions, opts?)` → Promise; not a subagent call. Ask a
104
113
  calibrated Jev model (chosen internally — no model option) questions about
105
114
  `state`. `questions` is a non-empty OBJECT keyed by question id — never an