@letta-ai/letta-agent-sdk 0.7.7 → 0.8.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.
- package/dist/app-server-management.d.ts +1 -0
- package/dist/app-server-management.d.ts.map +1 -1
- package/dist/client-entry.js +117 -29
- package/dist/client-entry.js.map +6 -6
- package/dist/cloud-management.d.ts +3 -2
- package/dist/cloud-management.d.ts.map +1 -1
- package/dist/cloud-session.d.ts +2 -0
- package/dist/cloud-session.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +121 -33
- package/dist/index.js.map +7 -7
- package/dist/management-types.d.ts +47 -1
- package/dist/management-types.d.ts.map +1 -1
- package/dist/management.d.ts +4 -2
- package/dist/management.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/app-server-management.ts +8 -0
- package/src/cloud-management.ts +60 -0
- package/src/cloud-session.ts +80 -25
- package/src/index.ts +2 -0
- package/src/management-types.ts +58 -1
- package/src/management.ts +28 -1
|
@@ -35,6 +35,7 @@ export declare class AppServerManagementTransport implements ManagementTransport
|
|
|
35
35
|
updateConversation(conversationId: string, body: ConversationUpdateParams): Promise<LettaConversation>;
|
|
36
36
|
forkConversation(conversationId: string, body: ConversationForkParams): Promise<LettaConversation>;
|
|
37
37
|
listConversationMessages(conversationId: string, query: MessageListParams): Promise<ConversationMessagesResult>;
|
|
38
|
+
enqueueConversationMessage(): Promise<never>;
|
|
38
39
|
private request;
|
|
39
40
|
private acquireConnection;
|
|
40
41
|
private openConnection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-server-management.d.ts","sourceRoot":"","sources":["../src/app-server-management.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,gDAAgD,CAAC;AACxD,OAAO,KAAK,EACV,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACzB,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20,13 @@ function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
|
20
20
|
|
|
21
21
|
// node_modules/@letta-ai/letta-client/internal/utils/uuid.mjs
|
|
22
22
|
var uuid4 = function() {
|
|
23
|
-
const { crypto } = globalThis;
|
|
24
|
-
if (
|
|
25
|
-
uuid4 =
|
|
26
|
-
return
|
|
23
|
+
const { crypto: crypto2 } = globalThis;
|
|
24
|
+
if (crypto2?.randomUUID) {
|
|
25
|
+
uuid4 = crypto2.randomUUID.bind(crypto2);
|
|
26
|
+
return crypto2.randomUUID();
|
|
27
27
|
}
|
|
28
28
|
const u8 = new Uint8Array(1);
|
|
29
|
-
const randomByte =
|
|
29
|
+
const randomByte = crypto2 ? () => crypto2.getRandomValues(u8)[0] : () => Math.random() * 255 & 255;
|
|
30
30
|
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) => (+c ^ randomByte() & 15 >> +c / 4).toString(16));
|
|
31
31
|
};
|
|
32
32
|
|
|
@@ -3535,6 +3535,9 @@ class AppServerManagementTransport {
|
|
|
3535
3535
|
}
|
|
3536
3536
|
return { messages: response.messages };
|
|
3537
3537
|
}
|
|
3538
|
+
enqueueConversationMessage() {
|
|
3539
|
+
return Promise.reject(new Error(`conversations.enqueue() is only available with backend: "cloud". App-server backends deliver messages through a session's send().`));
|
|
3540
|
+
}
|
|
3538
3541
|
async request(type, body, responseType) {
|
|
3539
3542
|
if (this.closingConnections.size > 0) {
|
|
3540
3543
|
await Promise.all([...this.closingConnections]);
|
|
@@ -10481,6 +10484,20 @@ function cloudModelEntry(raw) {
|
|
|
10481
10484
|
function isNotFound(error) {
|
|
10482
10485
|
return error instanceof APIError && error.status === 404;
|
|
10483
10486
|
}
|
|
10487
|
+
function asEnqueueMessageResult(body) {
|
|
10488
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
10489
|
+
throw new Error("Cloud enqueue message response was not an object.");
|
|
10490
|
+
}
|
|
10491
|
+
const response = body;
|
|
10492
|
+
if (typeof response.client_message_id !== "string" || typeof response.workflow_id !== "string" || typeof response.super_run_id !== "string") {
|
|
10493
|
+
throw new Error("Cloud enqueue message response did not include client_message_id, workflow_id, and super_run_id.");
|
|
10494
|
+
}
|
|
10495
|
+
return {
|
|
10496
|
+
clientMessageId: response.client_message_id,
|
|
10497
|
+
workflowId: response.workflow_id,
|
|
10498
|
+
superRunId: response.super_run_id
|
|
10499
|
+
};
|
|
10500
|
+
}
|
|
10484
10501
|
function toOrderRelativeCursors(query) {
|
|
10485
10502
|
if ((query.order ?? "desc") !== "desc")
|
|
10486
10503
|
return query;
|
|
@@ -10572,6 +10589,28 @@ class CloudManagementTransport {
|
|
|
10572
10589
|
const page = await this.client.conversations.messages.list(conversationId, toOrderRelativeCursors(query));
|
|
10573
10590
|
return { messages: page.items };
|
|
10574
10591
|
}
|
|
10592
|
+
async enqueueConversationMessage(conversationId, message, options) {
|
|
10593
|
+
const clientMessageId = options.clientMessageId ?? crypto.randomUUID();
|
|
10594
|
+
const settings = {
|
|
10595
|
+
...options.workingDirectory !== undefined ? { working_directory: options.workingDirectory } : {},
|
|
10596
|
+
...options.permissionMode !== undefined ? { permission_mode: options.permissionMode } : {}
|
|
10597
|
+
};
|
|
10598
|
+
const body = await this.client.post(`/v1/conversations/${encodeURIComponent(conversationId)}/messages/enqueue`, {
|
|
10599
|
+
body: {
|
|
10600
|
+
...options.agentId !== undefined ? { agent_id: options.agentId } : {},
|
|
10601
|
+
messages: [
|
|
10602
|
+
{
|
|
10603
|
+
role: "user",
|
|
10604
|
+
content: message,
|
|
10605
|
+
client_message_id: clientMessageId
|
|
10606
|
+
}
|
|
10607
|
+
],
|
|
10608
|
+
client_message_id: clientMessageId,
|
|
10609
|
+
...Object.keys(settings).length > 0 ? { settings } : {}
|
|
10610
|
+
}
|
|
10611
|
+
});
|
|
10612
|
+
return asEnqueueMessageResult(body);
|
|
10613
|
+
}
|
|
10575
10614
|
}
|
|
10576
10615
|
|
|
10577
10616
|
// src/remote.ts
|
|
@@ -11016,6 +11055,7 @@ var DEFAULT_SANDBOX_READY_TIMEOUT_MS = 120000;
|
|
|
11016
11055
|
var DEFAULT_SANDBOX_READY_POLL_INTERVAL_MS = 1000;
|
|
11017
11056
|
var DEFAULT_REPOSITORY_ATTACH_TIMEOUT_MS = 1e4;
|
|
11018
11057
|
var DEFAULT_REPOSITORY_ATTACH_POLL_INTERVAL_MS = 250;
|
|
11058
|
+
var INITIAL_CLOUD_TRANSPORT_ATTEMPTS = 2;
|
|
11019
11059
|
var SDK_AGENT_ORIGIN = "@letta-ai/letta-agent-sdk";
|
|
11020
11060
|
|
|
11021
11061
|
class CloudManagedSandboxOwnershipError extends Error {
|
|
@@ -11206,30 +11246,9 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
|
|
|
11206
11246
|
}
|
|
11207
11247
|
}
|
|
11208
11248
|
async openCloudTransport(runtime, connectionId) {
|
|
11209
|
-
const
|
|
11210
|
-
const url = buildCloudStatusWebSocketUrl({
|
|
11211
|
-
apiBaseUrl: this.cloudOptions.apiBaseUrl,
|
|
11212
|
-
connectionId,
|
|
11213
|
-
agentId: runtime.agent_id,
|
|
11214
|
-
conversationId: runtime.conversation_id,
|
|
11215
|
-
apiKey,
|
|
11216
|
-
authMode: this.cloudOptions.webSocketAuth ?? "header"
|
|
11217
|
-
});
|
|
11218
|
-
const client = applyUniqueRequestIds(createAppServerClient({
|
|
11219
|
-
url,
|
|
11220
|
-
WebSocket: createCloudStatusTransportConstructor({
|
|
11221
|
-
url,
|
|
11222
|
-
WebSocket: getWebSocketConstructor(this.cloudOptions.WebSocket),
|
|
11223
|
-
...(this.cloudOptions.webSocketAuth ?? "header") === "header" ? { headers: cloudWebSocketHeaders(this.cloudOptions) } : {},
|
|
11224
|
-
pingIntervalMs: this.cloudOptions.pingIntervalMs ?? DEFAULT_PING_INTERVAL_MS,
|
|
11225
|
-
runtime
|
|
11226
|
-
}),
|
|
11227
|
-
requestTimeoutMs: this.cloudOptions.requestTimeoutMs ?? DEFAULT_TURN_TIMEOUT_MS
|
|
11228
|
-
}));
|
|
11249
|
+
const client = await this.connectCloudTransport(runtime, connectionId);
|
|
11229
11250
|
const options = this.currentOptions();
|
|
11230
|
-
this.installTransportHandlers(client);
|
|
11231
11251
|
try {
|
|
11232
|
-
await client.connect();
|
|
11233
11252
|
const response = await this.startCloudRuntime(client, runtime);
|
|
11234
11253
|
if (!response.success || !response.runtime) {
|
|
11235
11254
|
throw new Error(response.error ?? "Failed to start Cloud status runtime");
|
|
@@ -11257,6 +11276,62 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
|
|
|
11257
11276
|
throw error;
|
|
11258
11277
|
}
|
|
11259
11278
|
}
|
|
11279
|
+
createCloudTransportClient(runtime, connectionId) {
|
|
11280
|
+
const apiKey = getCloudApiKey(this.cloudOptions);
|
|
11281
|
+
const url = buildCloudStatusWebSocketUrl({
|
|
11282
|
+
apiBaseUrl: this.cloudOptions.apiBaseUrl,
|
|
11283
|
+
connectionId,
|
|
11284
|
+
agentId: runtime.agent_id,
|
|
11285
|
+
conversationId: runtime.conversation_id,
|
|
11286
|
+
apiKey,
|
|
11287
|
+
authMode: this.cloudOptions.webSocketAuth ?? "header"
|
|
11288
|
+
});
|
|
11289
|
+
return applyUniqueRequestIds(createAppServerClient({
|
|
11290
|
+
url,
|
|
11291
|
+
WebSocket: createCloudStatusTransportConstructor({
|
|
11292
|
+
url,
|
|
11293
|
+
WebSocket: getWebSocketConstructor(this.cloudOptions.WebSocket),
|
|
11294
|
+
...(this.cloudOptions.webSocketAuth ?? "header") === "header" ? { headers: cloudWebSocketHeaders(this.cloudOptions) } : {},
|
|
11295
|
+
pingIntervalMs: this.cloudOptions.pingIntervalMs ?? DEFAULT_PING_INTERVAL_MS,
|
|
11296
|
+
runtime
|
|
11297
|
+
}),
|
|
11298
|
+
requestTimeoutMs: this.cloudOptions.requestTimeoutMs ?? DEFAULT_TURN_TIMEOUT_MS
|
|
11299
|
+
}));
|
|
11300
|
+
}
|
|
11301
|
+
async connectCloudTransport(runtime, initialConnectionId) {
|
|
11302
|
+
let connectionId = initialConnectionId;
|
|
11303
|
+
let lastError;
|
|
11304
|
+
for (let attempt = 0;attempt < INITIAL_CLOUD_TRANSPORT_ATTEMPTS; attempt++) {
|
|
11305
|
+
const client = this.createCloudTransportClient(runtime, connectionId);
|
|
11306
|
+
this.installTransportHandlers(client);
|
|
11307
|
+
try {
|
|
11308
|
+
await client.connect();
|
|
11309
|
+
this.connectionId = connectionId;
|
|
11310
|
+
return client;
|
|
11311
|
+
} catch (error) {
|
|
11312
|
+
lastError = error;
|
|
11313
|
+
console.warn(JSON.stringify({
|
|
11314
|
+
event: "cloud_status_transport_connection_failed",
|
|
11315
|
+
attempt: attempt + 1,
|
|
11316
|
+
max_attempts: INITIAL_CLOUD_TRANSPORT_ATTEMPTS,
|
|
11317
|
+
will_retry: attempt + 1 < INITIAL_CLOUD_TRANSPORT_ATTEMPTS,
|
|
11318
|
+
connection_id: connectionId,
|
|
11319
|
+
agent_id: runtime.agent_id,
|
|
11320
|
+
conversation_id: runtime.conversation_id,
|
|
11321
|
+
error_name: error instanceof Error ? error.name : null,
|
|
11322
|
+
error_message: error instanceof Error ? error.message : String(error)
|
|
11323
|
+
}));
|
|
11324
|
+
this.cleanupTransportHandlers();
|
|
11325
|
+
client.close();
|
|
11326
|
+
}
|
|
11327
|
+
if (attempt + 1 < INITIAL_CLOUD_TRANSPORT_ATTEMPTS) {
|
|
11328
|
+
const resolved = await this.resolveRecoveryConnection(runtime);
|
|
11329
|
+
connectionId = resolved.connectionId;
|
|
11330
|
+
}
|
|
11331
|
+
}
|
|
11332
|
+
const detail = lastError instanceof Error ? lastError.message : String(lastError);
|
|
11333
|
+
throw new Error(`Cloud status WebSocket failed to open for connection ${connectionId}: ${detail}`, { cause: lastError });
|
|
11334
|
+
}
|
|
11260
11335
|
installTransportHandlers(client) {
|
|
11261
11336
|
this.cleanupTransportHandlers();
|
|
11262
11337
|
this.removeControlRequestHandler = registerAppServerControlRequestHandler({
|
|
@@ -11809,7 +11884,20 @@ function createConversationsClient(transport) {
|
|
|
11809
11884
|
}
|
|
11810
11885
|
return await transport().forkConversation(sourceConversationId, conversationForkQuery(options));
|
|
11811
11886
|
},
|
|
11812
|
-
listMessages: (conversationId, options = {}) => transport().listConversationMessages(conversationId, conversationMessagesQuery(options))
|
|
11887
|
+
listMessages: (conversationId, options = {}) => transport().listConversationMessages(conversationId, conversationMessagesQuery(options)),
|
|
11888
|
+
enqueue: async (conversationId, message, options = {}) => {
|
|
11889
|
+
assertNonEmptyId2(conversationId, "conversation id");
|
|
11890
|
+
if (conversationId.trim() === "default" && !options.agentId) {
|
|
11891
|
+
throw new Error('enqueue("default", ...) requires options.agentId to identify the agent.');
|
|
11892
|
+
}
|
|
11893
|
+
if (options.agentId !== undefined) {
|
|
11894
|
+
assertNonEmptyId2(options.agentId, "agent id");
|
|
11895
|
+
}
|
|
11896
|
+
if (options.clientMessageId !== undefined) {
|
|
11897
|
+
assertNonEmptyId2(options.clientMessageId, "client message id");
|
|
11898
|
+
}
|
|
11899
|
+
return await transport().enqueueConversationMessage(conversationId, message, options);
|
|
11900
|
+
}
|
|
11813
11901
|
};
|
|
11814
11902
|
}
|
|
11815
11903
|
|
|
@@ -12858,4 +12946,4 @@ export {
|
|
|
12858
12946
|
CloudManagedSandboxExpiredError
|
|
12859
12947
|
};
|
|
12860
12948
|
|
|
12861
|
-
//# debugId=
|
|
12949
|
+
//# debugId=6DEC5A9A513E517464756E2164756E21
|