@letta-ai/letta-agent-sdk 0.7.8 → 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 +59 -7
- package/dist/client-entry.js.map +5 -5
- package/dist/cloud-management.d.ts +3 -2
- package/dist/cloud-management.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -11
- package/dist/index.js.map +6 -6
- 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/index.ts +2 -0
- package/src/management-types.ts +58 -1
- package/src/management.ts +28 -1
|
@@ -2,7 +2,7 @@ import type { AgentListParams, AgentState, AgentUpdateParams } from "@letta-ai/l
|
|
|
2
2
|
import type { Message } from "@letta-ai/letta-client/resources/agents/messages";
|
|
3
3
|
import type { Conversation, ConversationCreateParams, ConversationForkParams, ConversationListParams, ConversationUpdateParams } from "@letta-ai/letta-client/resources/conversations/conversations";
|
|
4
4
|
import type { MessageListParams } from "@letta-ai/letta-client/resources/conversations/messages";
|
|
5
|
-
import type { ListMessagesResult, ListModelsResult } from "./types.js";
|
|
5
|
+
import type { ListMessagesResult, ListModelsResult, PermissionMode, SendMessage } from "./types.js";
|
|
6
6
|
/** Agent state returned by either the Cloud API or Letta Code app-server. */
|
|
7
7
|
export type LettaAgent = AgentState;
|
|
8
8
|
/** Conversation state returned by either the Cloud API or Letta Code app-server. */
|
|
@@ -77,6 +77,32 @@ export interface ConversationMessagesOptions {
|
|
|
77
77
|
limit?: Present<MessageListParams["limit"]>;
|
|
78
78
|
}
|
|
79
79
|
export type ConversationMessagesResult = ListMessagesResult;
|
|
80
|
+
export interface EnqueueMessageOptions {
|
|
81
|
+
/**
|
|
82
|
+
* Required when `conversationId` is `"default"`; identifies the agent whose
|
|
83
|
+
* default conversation receives the message. Ignored otherwise.
|
|
84
|
+
*/
|
|
85
|
+
agentId?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Correlation id for this message. Reuse the same value when retrying an
|
|
88
|
+
* enqueue so the listener can deduplicate delivery; the SDK generates one
|
|
89
|
+
* when omitted. Matches the `otid` contract of `session.send()`.
|
|
90
|
+
*/
|
|
91
|
+
clientMessageId?: string;
|
|
92
|
+
/** Permission mode the listener applies before the turn when the runtime is cold. */
|
|
93
|
+
permissionMode?: PermissionMode;
|
|
94
|
+
/** Working directory for the runtime; `null` resets to the listener boot cwd. */
|
|
95
|
+
workingDirectory?: string | null;
|
|
96
|
+
}
|
|
97
|
+
/** The Cloud API's 202 acceptance of an enqueued message. */
|
|
98
|
+
export interface EnqueueMessageResult {
|
|
99
|
+
/** The correlation id the message was accepted under (caller-supplied or SDK-generated). */
|
|
100
|
+
clientMessageId: string;
|
|
101
|
+
/** Temporal workflow id of the conversation queue that owns delivery. */
|
|
102
|
+
workflowId: string;
|
|
103
|
+
/** Super run id tracking the message from queue through delivery and completion. */
|
|
104
|
+
superRunId: string;
|
|
105
|
+
}
|
|
80
106
|
export type AgentRepositoryPermissions = "read" | "read_write";
|
|
81
107
|
export type AgentRepositoryRecompileTarget = "default" | false;
|
|
82
108
|
/** A repository relationship persisted on an agent. */
|
|
@@ -141,6 +167,26 @@ export interface ConversationsClient {
|
|
|
141
167
|
*/
|
|
142
168
|
fork(sourceConversationId: string, options?: ForkConversationOptions): Promise<LettaConversation>;
|
|
143
169
|
listMessages(conversationId: string, options?: ConversationMessagesOptions): Promise<ConversationMessagesResult>;
|
|
170
|
+
/**
|
|
171
|
+
* Hand a user message to the server for delivery instead of sending it over
|
|
172
|
+
* a session. Cloud backend only.
|
|
173
|
+
*
|
|
174
|
+
* The returned promise resolves once the Cloud API has durably accepted the
|
|
175
|
+
* message (HTTP 202): from that point the server owns delivery. It ensures
|
|
176
|
+
* or resumes the conversation's sandbox, delivers the message to the
|
|
177
|
+
* listener with acknowledgement and retries, and tracks the whole lifecycle
|
|
178
|
+
* as a super run. The caller may exit immediately; the turn runs
|
|
179
|
+
* server-side. This is the send path chat.letta.com uses.
|
|
180
|
+
*
|
|
181
|
+
* Use `enqueue()` when you cannot hold a connection open for the length of
|
|
182
|
+
* a turn, such as serverless webhook handlers. Use a session's `send()` and
|
|
183
|
+
* `stream()` when you want to stream the turn's output; a session delivers
|
|
184
|
+
* input over its open socket and does not survive the caller.
|
|
185
|
+
*
|
|
186
|
+
* Pass `"default"` as `conversationId` with `options.agentId` to target an
|
|
187
|
+
* agent's default conversation.
|
|
188
|
+
*/
|
|
189
|
+
enqueue(conversationId: string, message: SendMessage, options?: EnqueueMessageOptions): Promise<EnqueueMessageResult>;
|
|
144
190
|
}
|
|
145
191
|
export {};
|
|
146
192
|
//# sourceMappingURL=management-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"management-types.d.ts","sourceRoot":"","sources":["../src/management-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACV,iBAAiB,EAClB,MAAM,gDAAgD,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kDAAkD,CAAC;AAChF,OAAO,KAAK,EACV,YAAY,EACZ,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,8DAA8D,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yDAAyD,CAAC;AACjG,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"management-types.d.ts","sourceRoot":"","sources":["../src/management-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACV,iBAAiB,EAClB,MAAM,gDAAgD,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kDA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AY,CACV,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,2BAA2B,GACpC,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACvC;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CACL,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAClC"}
|
package/dist/management.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AgentListParams, AgentUpdateParams } from "@letta-ai/letta-client/resources/agents/agents";
|
|
2
2
|
import type { ConversationCreateParams, ConversationForkParams, ConversationListParams, ConversationUpdateParams } from "@letta-ai/letta-client/resources/conversations/conversations";
|
|
3
3
|
import type { MessageListParams } from "@letta-ai/letta-client/resources/conversations/messages";
|
|
4
|
-
import type { AgentRepositoriesClient, AgentsClient, ConversationsClient, ConversationMessagesResult, LettaAgent, LettaConversation, ModelsClient } from "./management-types.js";
|
|
5
|
-
import type { ListModelsResult } from "./types.js";
|
|
4
|
+
import type { AgentRepositoriesClient, AgentsClient, ConversationsClient, ConversationMessagesResult, EnqueueMessageOptions, EnqueueMessageResult, LettaAgent, LettaConversation, ModelsClient } from "./management-types.js";
|
|
5
|
+
import type { ListModelsResult, SendMessage } from "./types.js";
|
|
6
6
|
export interface ManagementTransport {
|
|
7
7
|
listAgents(query: AgentListParams): Promise<LettaAgent[]>;
|
|
8
8
|
retrieveAgent(agentId: string): Promise<LettaAgent>;
|
|
@@ -15,6 +15,8 @@ export interface ManagementTransport {
|
|
|
15
15
|
updateConversation(conversationId: string, body: ConversationUpdateParams): Promise<LettaConversation>;
|
|
16
16
|
forkConversation(conversationId: string, query: ConversationForkParams): Promise<LettaConversation>;
|
|
17
17
|
listConversationMessages(conversationId: string, query: MessageListParams): Promise<ConversationMessagesResult>;
|
|
18
|
+
/** Cloud only. Non-cloud transports reject with a backend error. */
|
|
19
|
+
enqueueConversationMessage(conversationId: string, message: SendMessage, options: EnqueueMessageOptions): Promise<EnqueueMessageResult>;
|
|
18
20
|
}
|
|
19
21
|
type TransportProvider = () => ManagementTransport;
|
|
20
22
|
export declare function createAgentsClient(transport: TransportProvider, repositories: () => AgentRepositoriesClient): AgentsClient;
|
package/dist/management.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"management.d.ts","sourceRoot":"","sources":["../src/management.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,gDAAgD,CAAC;AACxD,OAAO,KAAK,EACV,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,8DAA8D,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yDAAyD,CAAC;AACjG,OAAO,KAAK,EACV,uBAAuB,EACvB,YAAY,EACZ,mBAAmB,EACnB,0BAA0B,
|
|
1
|
+
{"version":3,"file":"management.d.ts","sourceRoot":"","sources":["../src/management.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,gDAAgD,CAAC;AACxD,OAAO,KAAK,EACV,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,8DAA8D,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yDAAyD,CAAC;AACjG,OAAO,KAAK,EACV,uBAAuB,EACvB,YAAY,EACZ,mBAAmB,EACnB,0BAA0B,EAE1B,qBAAqB,EACrB,oBAAoB,EAEpB,UAAU,EACV,iBAAiB,EAGjB,YAAY,EAIb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEhE,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,EAAE,C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,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,iBAAiB,GAC3B,mBAAmB,CAgDrB"}
|
package/package.json
CHANGED
|
@@ -242,6 +242,14 @@ export class AppServerManagementTransport
|
|
|
242
242
|
return { messages: response.messages };
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
enqueueConversationMessage(): Promise<never> {
|
|
246
|
+
return Promise.reject(
|
|
247
|
+
new Error(
|
|
248
|
+
'conversations.enqueue() is only available with backend: "cloud". App-server backends deliver messages through a session\'s send().',
|
|
249
|
+
),
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
245
253
|
private async request<TResponse extends { type: string }>(
|
|
246
254
|
type: string,
|
|
247
255
|
body: Record<string, unknown>,
|
package/src/cloud-management.ts
CHANGED
|
@@ -16,12 +16,15 @@ import type {
|
|
|
16
16
|
AgentRepository,
|
|
17
17
|
AgentRepositoryPermissions,
|
|
18
18
|
ConversationMessagesResult,
|
|
19
|
+
EnqueueMessageOptions,
|
|
20
|
+
EnqueueMessageResult,
|
|
19
21
|
LettaAgent,
|
|
20
22
|
LettaConversation,
|
|
21
23
|
} from "./management-types.js";
|
|
22
24
|
import type {
|
|
23
25
|
LettaCodeModelEntry,
|
|
24
26
|
ListModelsResult,
|
|
27
|
+
SendMessage,
|
|
25
28
|
} from "./types.js";
|
|
26
29
|
|
|
27
30
|
function asAgentRepository(body: unknown, action: string): AgentRepository {
|
|
@@ -75,6 +78,27 @@ function isNotFound(error: unknown): boolean {
|
|
|
75
78
|
return error instanceof APIError && error.status === 404;
|
|
76
79
|
}
|
|
77
80
|
|
|
81
|
+
function asEnqueueMessageResult(body: unknown): EnqueueMessageResult {
|
|
82
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
83
|
+
throw new Error("Cloud enqueue message response was not an object.");
|
|
84
|
+
}
|
|
85
|
+
const response = body as Record<string, unknown>;
|
|
86
|
+
if (
|
|
87
|
+
typeof response.client_message_id !== "string" ||
|
|
88
|
+
typeof response.workflow_id !== "string" ||
|
|
89
|
+
typeof response.super_run_id !== "string"
|
|
90
|
+
) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
"Cloud enqueue message response did not include client_message_id, workflow_id, and super_run_id.",
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
clientMessageId: response.client_message_id,
|
|
97
|
+
workflowId: response.workflow_id,
|
|
98
|
+
superRunId: response.super_run_id,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
78
102
|
/**
|
|
79
103
|
* The SDK cursor contract is chronological: `before` always means older and
|
|
80
104
|
* `after` always means newer. The Cloud REST API interprets cursors relative
|
|
@@ -235,4 +259,40 @@ export class CloudManagementTransport implements ManagementTransport {
|
|
|
235
259
|
);
|
|
236
260
|
return { messages: page.items };
|
|
237
261
|
}
|
|
262
|
+
|
|
263
|
+
async enqueueConversationMessage(
|
|
264
|
+
conversationId: string,
|
|
265
|
+
message: SendMessage,
|
|
266
|
+
options: EnqueueMessageOptions,
|
|
267
|
+
): Promise<EnqueueMessageResult> {
|
|
268
|
+
const clientMessageId = options.clientMessageId ?? crypto.randomUUID();
|
|
269
|
+
const settings = {
|
|
270
|
+
...(options.workingDirectory !== undefined
|
|
271
|
+
? { working_directory: options.workingDirectory }
|
|
272
|
+
: {}),
|
|
273
|
+
...(options.permissionMode !== undefined
|
|
274
|
+
? { permission_mode: options.permissionMode }
|
|
275
|
+
: {}),
|
|
276
|
+
};
|
|
277
|
+
const body = await this.client.post<unknown>(
|
|
278
|
+
`/v1/conversations/${encodeURIComponent(conversationId)}/messages/enqueue`,
|
|
279
|
+
{
|
|
280
|
+
body: {
|
|
281
|
+
...(options.agentId !== undefined
|
|
282
|
+
? { agent_id: options.agentId }
|
|
283
|
+
: {}),
|
|
284
|
+
messages: [
|
|
285
|
+
{
|
|
286
|
+
role: "user",
|
|
287
|
+
content: message,
|
|
288
|
+
client_message_id: clientMessageId,
|
|
289
|
+
},
|
|
290
|
+
],
|
|
291
|
+
client_message_id: clientMessageId,
|
|
292
|
+
...(Object.keys(settings).length > 0 ? { settings } : {}),
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
);
|
|
296
|
+
return asEnqueueMessageResult(body);
|
|
297
|
+
}
|
|
238
298
|
}
|
package/src/index.ts
CHANGED
|
@@ -174,6 +174,8 @@ export type {
|
|
|
174
174
|
ConversationMessagesResult,
|
|
175
175
|
DetachAgentRepositoryOptions,
|
|
176
176
|
AgentRepositoryPermissions,
|
|
177
|
+
EnqueueMessageOptions,
|
|
178
|
+
EnqueueMessageResult,
|
|
177
179
|
} from "./management-types.js";
|
|
178
180
|
|
|
179
181
|
export { RepositoriesClient } from "./repositories.js";
|
package/src/management-types.ts
CHANGED
|
@@ -12,7 +12,12 @@ import type {
|
|
|
12
12
|
ConversationUpdateParams,
|
|
13
13
|
} from "@letta-ai/letta-client/resources/conversations/conversations";
|
|
14
14
|
import type { MessageListParams } from "@letta-ai/letta-client/resources/conversations/messages";
|
|
15
|
-
import type {
|
|
15
|
+
import type {
|
|
16
|
+
ListMessagesResult,
|
|
17
|
+
ListModelsResult,
|
|
18
|
+
PermissionMode,
|
|
19
|
+
SendMessage,
|
|
20
|
+
} from "./types.js";
|
|
16
21
|
|
|
17
22
|
/** Agent state returned by either the Cloud API or Letta Code app-server. */
|
|
18
23
|
export type LettaAgent = AgentState;
|
|
@@ -100,6 +105,34 @@ export interface ConversationMessagesOptions {
|
|
|
100
105
|
|
|
101
106
|
export type ConversationMessagesResult = ListMessagesResult;
|
|
102
107
|
|
|
108
|
+
export interface EnqueueMessageOptions {
|
|
109
|
+
/**
|
|
110
|
+
* Required when `conversationId` is `"default"`; identifies the agent whose
|
|
111
|
+
* default conversation receives the message. Ignored otherwise.
|
|
112
|
+
*/
|
|
113
|
+
agentId?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Correlation id for this message. Reuse the same value when retrying an
|
|
116
|
+
* enqueue so the listener can deduplicate delivery; the SDK generates one
|
|
117
|
+
* when omitted. Matches the `otid` contract of `session.send()`.
|
|
118
|
+
*/
|
|
119
|
+
clientMessageId?: string;
|
|
120
|
+
/** Permission mode the listener applies before the turn when the runtime is cold. */
|
|
121
|
+
permissionMode?: PermissionMode;
|
|
122
|
+
/** Working directory for the runtime; `null` resets to the listener boot cwd. */
|
|
123
|
+
workingDirectory?: string | null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The Cloud API's 202 acceptance of an enqueued message. */
|
|
127
|
+
export interface EnqueueMessageResult {
|
|
128
|
+
/** The correlation id the message was accepted under (caller-supplied or SDK-generated). */
|
|
129
|
+
clientMessageId: string;
|
|
130
|
+
/** Temporal workflow id of the conversation queue that owns delivery. */
|
|
131
|
+
workflowId: string;
|
|
132
|
+
/** Super run id tracking the message from queue through delivery and completion. */
|
|
133
|
+
superRunId: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
103
136
|
export type AgentRepositoryPermissions = "read" | "read_write";
|
|
104
137
|
export type AgentRepositoryRecompileTarget = "default" | false;
|
|
105
138
|
|
|
@@ -193,4 +226,28 @@ export interface ConversationsClient {
|
|
|
193
226
|
conversationId: string,
|
|
194
227
|
options?: ConversationMessagesOptions,
|
|
195
228
|
): Promise<ConversationMessagesResult>;
|
|
229
|
+
/**
|
|
230
|
+
* Hand a user message to the server for delivery instead of sending it over
|
|
231
|
+
* a session. Cloud backend only.
|
|
232
|
+
*
|
|
233
|
+
* The returned promise resolves once the Cloud API has durably accepted the
|
|
234
|
+
* message (HTTP 202): from that point the server owns delivery. It ensures
|
|
235
|
+
* or resumes the conversation's sandbox, delivers the message to the
|
|
236
|
+
* listener with acknowledgement and retries, and tracks the whole lifecycle
|
|
237
|
+
* as a super run. The caller may exit immediately; the turn runs
|
|
238
|
+
* server-side. This is the send path chat.letta.com uses.
|
|
239
|
+
*
|
|
240
|
+
* Use `enqueue()` when you cannot hold a connection open for the length of
|
|
241
|
+
* a turn, such as serverless webhook handlers. Use a session's `send()` and
|
|
242
|
+
* `stream()` when you want to stream the turn's output; a session delivers
|
|
243
|
+
* input over its open socket and does not survive the caller.
|
|
244
|
+
*
|
|
245
|
+
* Pass `"default"` as `conversationId` with `options.agentId` to target an
|
|
246
|
+
* agent's default conversation.
|
|
247
|
+
*/
|
|
248
|
+
enqueue(
|
|
249
|
+
conversationId: string,
|
|
250
|
+
message: SendMessage,
|
|
251
|
+
options?: EnqueueMessageOptions,
|
|
252
|
+
): Promise<EnqueueMessageResult>;
|
|
196
253
|
}
|
package/src/management.ts
CHANGED
|
@@ -15,6 +15,8 @@ import type {
|
|
|
15
15
|
ConversationsClient,
|
|
16
16
|
ConversationMessagesResult,
|
|
17
17
|
CreateConversationOptions,
|
|
18
|
+
EnqueueMessageOptions,
|
|
19
|
+
EnqueueMessageResult,
|
|
18
20
|
ForkConversationOptions,
|
|
19
21
|
LettaAgent,
|
|
20
22
|
LettaConversation,
|
|
@@ -25,7 +27,7 @@ import type {
|
|
|
25
27
|
UpdateConversationOptions,
|
|
26
28
|
ConversationMessagesOptions,
|
|
27
29
|
} from "./management-types.js";
|
|
28
|
-
import type { ListModelsResult } from "./types.js";
|
|
30
|
+
import type { ListModelsResult, SendMessage } from "./types.js";
|
|
29
31
|
|
|
30
32
|
export interface ManagementTransport {
|
|
31
33
|
listAgents(query: AgentListParams): Promise<LettaAgent[]>;
|
|
@@ -57,6 +59,12 @@ export interface ManagementTransport {
|
|
|
57
59
|
conversationId: string,
|
|
58
60
|
query: MessageListParams,
|
|
59
61
|
): Promise<ConversationMessagesResult>;
|
|
62
|
+
/** Cloud only. Non-cloud transports reject with a backend error. */
|
|
63
|
+
enqueueConversationMessage(
|
|
64
|
+
conversationId: string,
|
|
65
|
+
message: SendMessage,
|
|
66
|
+
options: EnqueueMessageOptions,
|
|
67
|
+
): Promise<EnqueueMessageResult>;
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
type TransportProvider = () => ManagementTransport;
|
|
@@ -227,5 +235,24 @@ export function createConversationsClient(
|
|
|
227
235
|
conversationId,
|
|
228
236
|
conversationMessagesQuery(options),
|
|
229
237
|
),
|
|
238
|
+
enqueue: async (conversationId, message, options = {}) => {
|
|
239
|
+
assertNonEmptyId(conversationId, "conversation id");
|
|
240
|
+
if (conversationId.trim() === "default" && !options.agentId) {
|
|
241
|
+
throw new Error(
|
|
242
|
+
'enqueue("default", ...) requires options.agentId to identify the agent.',
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
if (options.agentId !== undefined) {
|
|
246
|
+
assertNonEmptyId(options.agentId, "agent id");
|
|
247
|
+
}
|
|
248
|
+
if (options.clientMessageId !== undefined) {
|
|
249
|
+
assertNonEmptyId(options.clientMessageId, "client message id");
|
|
250
|
+
}
|
|
251
|
+
return await transport().enqueueConversationMessage(
|
|
252
|
+
conversationId,
|
|
253
|
+
message,
|
|
254
|
+
options,
|
|
255
|
+
);
|
|
256
|
+
},
|
|
230
257
|
};
|
|
231
258
|
}
|