@moxt-ai/mobius-sdk 0.0.9 → 0.0.11

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 (48) hide show
  1. package/README.md +21 -17
  2. package/dist/channel.d.ts +1 -1
  3. package/dist/channel.d.ts.map +1 -1
  4. package/dist/channel.js.map +1 -1
  5. package/dist/client.d.ts +7 -0
  6. package/dist/client.d.ts.map +1 -1
  7. package/dist/client.js +127 -1
  8. package/dist/client.js.map +1 -1
  9. package/dist/index.d.ts +1 -4
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +0 -3
  12. package/dist/index.js.map +1 -1
  13. package/dist/platform.d.ts +0 -28
  14. package/dist/platform.d.ts.map +1 -1
  15. package/dist/platform.js +0 -56
  16. package/dist/platform.js.map +1 -1
  17. package/dist/project-authentication.d.ts.map +1 -1
  18. package/dist/project-authentication.js +0 -9
  19. package/dist/project-authentication.js.map +1 -1
  20. package/dist/resources.d.ts +1 -2
  21. package/dist/resources.d.ts.map +1 -1
  22. package/dist/resources.js +3 -9
  23. package/dist/resources.js.map +1 -1
  24. package/dist/server.d.ts +0 -3
  25. package/dist/server.d.ts.map +1 -1
  26. package/dist/server.js +0 -3
  27. package/dist/server.js.map +1 -1
  28. package/dist/service-client.d.ts +16 -13
  29. package/dist/service-client.d.ts.map +1 -1
  30. package/dist/service-client.js +71 -67
  31. package/dist/service-client.js.map +1 -1
  32. package/package.json +2 -6
  33. package/dist/bot-owner-resources.d.ts +0 -272
  34. package/dist/bot-owner-resources.d.ts.map +0 -1
  35. package/dist/bot-owner-resources.js +0 -749
  36. package/dist/bot-owner-resources.js.map +0 -1
  37. package/dist/bot-resources.d.ts +0 -151
  38. package/dist/bot-resources.d.ts.map +0 -1
  39. package/dist/bot-resources.js +0 -466
  40. package/dist/bot-resources.js.map +0 -1
  41. package/dist/bot-service-client.d.ts +0 -232
  42. package/dist/bot-service-client.d.ts.map +0 -1
  43. package/dist/bot-service-client.js +0 -670
  44. package/dist/bot-service-client.js.map +0 -1
  45. package/dist/browser.d.ts +0 -173
  46. package/dist/browser.d.ts.map +0 -1
  47. package/dist/browser.js +0 -396
  48. package/dist/browser.js.map +0 -1
@@ -1,670 +0,0 @@
1
- import { decodeAgentExecutionConfiguration, decodePromptImagesValue, decodePromptResourcesValue, decodeSessionConfigOptions, MOBIUS_API_PREFIX, } from "@moxt-ai/mobius-protocol";
2
- import { decodeMobiusBot, decodeMobiusBotBehavior, decodeMobiusOwnerBotConversation, MobiusBotBehaviorDirectory, MobiusBotBindingDirectory, MobiusBotBindingRequestAcceptance, MobiusBotCompletionPolicy, MobiusBotConnectionDirectory, MobiusBotConnectionGrant, MobiusBotConversationDirectory, MobiusBotDirectory, MobiusBotProfileRevision, MobiusNoBotCompletionPolicy, MobiusProjectConversation, MobiusRequiredBotCompletionPolicy, } from "./bot-owner-resources.js";
3
- import { MobiusBotConnectionCredential, MobiusBotConnectionCredentialRotation, MobiusBotConversationEventPage, MobiusBotConversationMessagePage, MobiusBotDeliveryAcknowledgement, MobiusBotDeliveryTarget, MobiusBotOutboundEventPage, MobiusBotTurnAcceptance, MobiusBotTurnCancellationAcceptance, MobiusBotTurnSteeringAcceptance, MobiusConnectedBotConversation, MobiusDisabledBotDeliveryTarget, MobiusRevokedBotConnection, } from "./bot-resources.js";
4
- import { MobiusApiError, MobiusCancellationError, MobiusConnectionError, MobiusError, MobiusProtocolError, MobiusTimeoutError, MobiusValidationError, } from "./errors.js";
5
- import { decodeMobiusToolCallDetail, decodeMobiusTurn, } from "./resources.js";
6
- export const MOBIUS_BOT_API_VERSION = "v1";
7
- const DEFAULT_OPERATION_TIMEOUT_MILLISECONDS = 20_000;
8
- const MAX_RESPONSE_LENGTH = 8 * 1024 * 1024;
9
- const IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
10
- const TOKEN_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
11
- export class MobiusProjectConversationTurnAcceptance {
12
- duplicate;
13
- eventCursor;
14
- executionId;
15
- turn;
16
- turnId;
17
- constructor(value) {
18
- const resource = responseRecord(value);
19
- if (typeof resource["duplicate"] !== "boolean") {
20
- throw new MobiusProtocolError("The Project Conversation turn acceptance is invalid");
21
- }
22
- this.duplicate = resource["duplicate"];
23
- this.eventCursor = boundedText(resource["eventCursor"], "Conversation event cursor", 512, true);
24
- this.executionId = identifier(resource["executionId"], "Conversation execution");
25
- this.turn = decodeMobiusTurn(resource["turn"]);
26
- this.turnId = identifier(resource["turnId"], "Conversation turn");
27
- if (this.turn.turnId !== this.turnId) {
28
- throw new MobiusProtocolError("The Project Conversation turn acceptance is inconsistent");
29
- }
30
- }
31
- }
32
- export class MobiusConversationConfigurationAcceptance {
33
- duplicate;
34
- requestId;
35
- status = "accepted";
36
- constructor(value) {
37
- const resource = responseRecord(value);
38
- if (typeof resource["duplicate"] !== "boolean" || resource["status"] !== "accepted") {
39
- throw new MobiusProtocolError("The Conversation configuration acceptance is invalid");
40
- }
41
- this.duplicate = resource["duplicate"];
42
- this.requestId = identifier(resource["requestId"], "Conversation configuration request");
43
- }
44
- }
45
- /**
46
- * @deprecated Use Runtime Agent settings discovery instead of the Bot-scoped snapshot.
47
- */
48
- export class MobiusBotAgentConfiguration {
49
- options;
50
- constructor(value) {
51
- const resource = responseRecord(value);
52
- if (Object.keys(resource).length !== 1 || !Object.hasOwn(resource, "options")) {
53
- throw new MobiusProtocolError("The Bot Agent configuration response is invalid");
54
- }
55
- try {
56
- this.options = decodeSessionConfigOptions(resource["options"]);
57
- }
58
- catch (cause) {
59
- throw new MobiusProtocolError("The Bot Agent configuration response is invalid", { cause });
60
- }
61
- }
62
- }
63
- function isRecord(value) {
64
- return typeof value === "object" && value !== null && !Array.isArray(value);
65
- }
66
- function requestRecord(value, fields, name) {
67
- if (!isRecord(value)) {
68
- throw new MobiusValidationError(`The ${name} is invalid`);
69
- }
70
- const keys = Object.keys(value);
71
- if (keys.length !== fields.length || keys.some((key) => !fields.includes(key))) {
72
- throw new MobiusValidationError(`The ${name} fields are invalid`);
73
- }
74
- return value;
75
- }
76
- function executionConfiguration(value) {
77
- try {
78
- return decodeAgentExecutionConfiguration(value);
79
- }
80
- catch (cause) {
81
- throw new MobiusValidationError("The Agent execution configuration is invalid", { cause });
82
- }
83
- }
84
- function identifier(value, name) {
85
- if (typeof value !== "string" || !IDENTIFIER_PATTERN.test(value)) {
86
- throw new MobiusValidationError(`The ${name} identifier is invalid`);
87
- }
88
- return value;
89
- }
90
- function boundedText(value, name, maximum, allowEmpty = false) {
91
- if (typeof value !== "string" || value.length > maximum || (!allowEmpty && value.trim().length === 0)) {
92
- throw new MobiusValidationError(`The ${name} is invalid`);
93
- }
94
- return value;
95
- }
96
- function hasControlCharacters(value) {
97
- for (const character of value) {
98
- const codePoint = character.codePointAt(0) ?? 0;
99
- if (codePoint <= 31 || codePoint === 127) {
100
- return true;
101
- }
102
- }
103
- return false;
104
- }
105
- function auditActorReference(value) {
106
- if (value === undefined) {
107
- return "";
108
- }
109
- if (typeof value !== "string" || value.length > 200 || hasControlCharacters(value)) {
110
- throw new MobiusValidationError("The Mobius actor reference is invalid");
111
- }
112
- return value;
113
- }
114
- function token(value, name) {
115
- if (typeof value !== "string" || !TOKEN_PATTERN.test(value)) {
116
- throw new MobiusValidationError(`The ${name} is invalid`);
117
- }
118
- return value;
119
- }
120
- function identifiers(value, name, maximum) {
121
- if (!Array.isArray(value) || value.length > maximum) {
122
- throw new MobiusValidationError(`The ${name} is invalid`);
123
- }
124
- const normalized = [];
125
- const unique = new Set();
126
- for (const candidate of value) {
127
- const validated = identifier(candidate, name);
128
- if (unique.has(validated)) {
129
- throw new MobiusValidationError(`The ${name} contains a duplicate`);
130
- }
131
- unique.add(validated);
132
- normalized.push(validated);
133
- }
134
- return Object.freeze(normalized);
135
- }
136
- function boundedInteger(value, name, minimum, maximum) {
137
- if (typeof value !== "number" || !Number.isSafeInteger(value) || value < minimum || value > maximum) {
138
- throw new MobiusValidationError(`The ${name} is invalid`);
139
- }
140
- return value;
141
- }
142
- function normalizeEndpoint(value) {
143
- let endpoint;
144
- try {
145
- endpoint = new URL(value);
146
- }
147
- catch (cause) {
148
- throw new MobiusValidationError("The Mobius Bot API endpoint is invalid", { cause });
149
- }
150
- if ((endpoint.protocol !== "http:" && endpoint.protocol !== "https:") ||
151
- endpoint.username.length > 0 ||
152
- endpoint.password.length > 0 ||
153
- endpoint.search.length > 0 ||
154
- endpoint.hash.length > 0) {
155
- throw new MobiusValidationError("The Mobius Bot API endpoint is invalid");
156
- }
157
- if (endpoint.pathname === "/") {
158
- endpoint.pathname = `${MOBIUS_API_PREFIX}/`;
159
- }
160
- else if (!endpoint.pathname.endsWith("/")) {
161
- endpoint.pathname = `${endpoint.pathname}/`;
162
- }
163
- return endpoint;
164
- }
165
- function responseRecord(value) {
166
- if (!isRecord(value)) {
167
- throw new MobiusProtocolError("The Bot API returned an invalid error response");
168
- }
169
- return value;
170
- }
171
- class BotRequestAuthentication {
172
- }
173
- class AnonymousBotRequestAuthentication extends BotRequestAuthentication {
174
- apply = async (_headers, signal) => {
175
- signal.throwIfAborted();
176
- };
177
- }
178
- class CredentialBotRequestAuthentication extends BotRequestAuthentication {
179
- #provider;
180
- constructor(provider) {
181
- super();
182
- this.#provider = provider;
183
- }
184
- apply = async (headers, signal) => {
185
- headers.set("authorization", `Bearer ${token(await this.#provider.credential(signal), "Mobius credential")}`);
186
- };
187
- }
188
- class PlatformMobiusBotTransport {
189
- fetch = async (request) => await globalThis.fetch(request);
190
- }
191
- class BotRequestDeadline {
192
- #controller = new AbortController();
193
- #requestSignal;
194
- #timeoutId;
195
- #timedOut = false;
196
- constructor(requestSignal, timeoutMilliseconds) {
197
- this.#requestSignal = requestSignal;
198
- if (requestSignal.aborted) {
199
- this.#controller.abort(requestSignal.reason);
200
- }
201
- else {
202
- requestSignal.addEventListener("abort", this.abortFromRequest, { once: true });
203
- }
204
- this.#timeoutId = globalThis.setTimeout(this.abortFromTimeout, timeoutMilliseconds);
205
- }
206
- get signal() {
207
- return this.#controller.signal;
208
- }
209
- finish = () => {
210
- globalThis.clearTimeout(this.#timeoutId);
211
- this.#requestSignal.removeEventListener("abort", this.abortFromRequest);
212
- };
213
- translate = (cause) => {
214
- if (this.#requestSignal.aborted) {
215
- throw new MobiusCancellationError({ cause });
216
- }
217
- if (this.#timedOut) {
218
- throw new MobiusTimeoutError({ cause });
219
- }
220
- if (cause instanceof MobiusError) {
221
- throw cause;
222
- }
223
- throw new MobiusConnectionError("The Mobius Bot API could not be reached", { cause });
224
- };
225
- abortFromRequest = () => this.#controller.abort(this.#requestSignal.reason);
226
- abortFromTimeout = () => {
227
- this.#timedOut = true;
228
- this.#controller.abort(new Error("The Mobius Bot API operation timed out"));
229
- };
230
- }
231
- class BotRequestExecutor {
232
- #actorReference;
233
- #authentication;
234
- #endpoint;
235
- #operationTimeoutMilliseconds;
236
- #observeResponse;
237
- #transport;
238
- constructor(options, authentication, actorReference) {
239
- this.#actorReference = actorReference;
240
- this.#authentication = authentication;
241
- this.#endpoint = normalizeEndpoint(options.endpoint);
242
- this.#operationTimeoutMilliseconds = boundedInteger(options.operationTimeoutMilliseconds ?? DEFAULT_OPERATION_TIMEOUT_MILLISECONDS, "operation timeout", 1, 300_000);
243
- this.#observeResponse = options.observeResponse;
244
- this.#transport = options.transport ?? new PlatformMobiusBotTransport();
245
- }
246
- get = async (path, signal) => await this.request(path, "GET", "", false, signal);
247
- post = async (path, body, signal) => {
248
- const encoded = JSON.stringify(body);
249
- if (typeof encoded !== "string") {
250
- throw new MobiusValidationError("The Mobius Bot API request is invalid");
251
- }
252
- return await this.request(path, "POST", encoded, true, signal);
253
- };
254
- put = async (path, body, signal) => {
255
- const encoded = JSON.stringify(body);
256
- if (typeof encoded !== "string") {
257
- throw new MobiusValidationError("The Mobius Bot API request is invalid");
258
- }
259
- return await this.request(path, "PUT", encoded, true, signal);
260
- };
261
- request = async (path, method, encodedBody, includesBody, signal) => {
262
- const deadline = new BotRequestDeadline(signal, this.#operationTimeoutMilliseconds);
263
- try {
264
- const headers = new Headers({ accept: "application/json" });
265
- if (includesBody) {
266
- headers.set("content-type", "application/json");
267
- }
268
- if (this.#actorReference.length > 0) {
269
- headers.set("x-mobius-actor-ref", this.#actorReference);
270
- }
271
- await this.#authentication.apply(headers, deadline.signal);
272
- const url = new URL(path, this.#endpoint);
273
- const request = includesBody
274
- ? new Request(url, { body: encodedBody, headers, method, signal: deadline.signal })
275
- : new Request(url, { headers, method, signal: deadline.signal });
276
- const response = await this.#transport.fetch(request);
277
- deadline.signal.throwIfAborted();
278
- this.#observeResponse?.({
279
- serverTiming: response.headers.get("server-timing"),
280
- status: response.status,
281
- });
282
- const encoded = await response.text();
283
- if (encoded.length === 0 || encoded.length > MAX_RESPONSE_LENGTH) {
284
- throw new MobiusProtocolError("The Mobius Bot API returned an invalid response");
285
- }
286
- let value;
287
- try {
288
- value = JSON.parse(encoded);
289
- }
290
- catch (cause) {
291
- throw new MobiusProtocolError("The Mobius Bot API returned invalid JSON", { cause });
292
- }
293
- if (!response.ok) {
294
- const error = responseRecord(responseRecord(value)["error"]);
295
- const code = error["code"];
296
- const message = error["message"];
297
- if (typeof code !== "string" || typeof message !== "string") {
298
- throw new MobiusProtocolError("The Mobius Bot API returned an invalid error response");
299
- }
300
- throw new MobiusApiError(code, message, response.status);
301
- }
302
- return value;
303
- }
304
- catch (cause) {
305
- return deadline.translate(cause);
306
- }
307
- finally {
308
- deadline.finish();
309
- }
310
- };
311
- }
312
- function projectBotPath(projectId, botId, resource) {
313
- const base = `${projectBotsPath(projectId)}/${encodeURIComponent(identifier(botId, "Bot"))}`;
314
- return resource.length === 0 ? base : `${base}/${resource}`;
315
- }
316
- function projectBotsPath(projectId) {
317
- return `${MOBIUS_BOT_API_VERSION}/projects/${encodeURIComponent(identifier(projectId, "project"))}/bots`;
318
- }
319
- function projectConversationsPath(projectId) {
320
- return `${MOBIUS_BOT_API_VERSION}/projects/${encodeURIComponent(identifier(projectId, "project"))}/conversations`;
321
- }
322
- function conversationPath(projectId, conversationId, resource) {
323
- const base = `${projectConversationsPath(projectId)}/${encodeURIComponent(identifier(conversationId, "conversation"))}`;
324
- return resource.length === 0 ? base : `${base}/${resource}`;
325
- }
326
- function serializedConversationConfiguration(request) {
327
- const value = requestRecord(request, ["additionalDirectoryIds", "booleanValue", "configId", "idempotencyKey", "value", "valueType"], "Conversation configuration request");
328
- if (typeof value["booleanValue"] !== "boolean") {
329
- throw new MobiusValidationError("The Conversation configuration boolean value is invalid");
330
- }
331
- return {
332
- additionalDirectoryIds: identifiers(value["additionalDirectoryIds"], "additional directory", 16),
333
- booleanValue: value["booleanValue"],
334
- configId: identifier(value["configId"], "configuration"),
335
- idempotencyKey: identifier(value["idempotencyKey"], "configuration idempotency key"),
336
- value: boundedText(value["value"], "configuration value", 500, true),
337
- valueType: boundedText(value["valueType"], "configuration value type", 32),
338
- };
339
- }
340
- function serializedInitialConversationConfiguration(request) {
341
- const value = requestRecord(request, ["additionalDirectoryIds", "booleanValue", "configId", "value", "valueType"], "initial Conversation configuration request");
342
- if (typeof value["booleanValue"] !== "boolean") {
343
- throw new MobiusValidationError("The initial Conversation configuration boolean value is invalid");
344
- }
345
- return {
346
- additionalDirectoryIds: identifiers(value["additionalDirectoryIds"], "additional directory", 16),
347
- booleanValue: value["booleanValue"],
348
- configId: identifier(value["configId"], "configuration"),
349
- value: boundedText(value["value"], "configuration value", 500, true),
350
- valueType: boundedText(value["valueType"], "configuration value type", 32),
351
- };
352
- }
353
- function serializedCompletionPolicy(policy) {
354
- if (policy instanceof MobiusNoBotCompletionPolicy) {
355
- return { kind: "none" };
356
- }
357
- if (policy instanceof MobiusRequiredBotCompletionPolicy) {
358
- return {
359
- deliveryTargetId: identifier(policy.deliveryTargetId, "delivery target"),
360
- kind: "required",
361
- messageTemplate: boundedText(policy.messageTemplate, "completion message template", 10_000),
362
- };
363
- }
364
- throw new MobiusValidationError("The Bot completion policy is invalid");
365
- }
366
- export class MobiusBotOwnerClient {
367
- #executor;
368
- #projectId;
369
- constructor(options) {
370
- this.#projectId = identifier(options.projectId, "project");
371
- this.#executor = new BotRequestExecutor(options, new CredentialBotRequestAuthentication(options.credentialProvider), auditActorReference(options.actorReference));
372
- }
373
- listBots = async (signal) => new MobiusBotDirectory(await this.#executor.get(projectBotsPath(this.#projectId), signal));
374
- createBot = async (request, signal) => {
375
- const value = requestRecord(request, ["avatarRef", "description", "displayName"], "Bot creation request");
376
- return decodeMobiusBot(await this.#executor.post(projectBotsPath(this.#projectId), {
377
- avatarRef: boundedText(value["avatarRef"], "Bot avatar reference", 4_096, true),
378
- description: boundedText(value["description"], "Bot description", 2_000, true),
379
- displayName: boundedText(value["displayName"], "Bot display name", 80),
380
- }, signal));
381
- };
382
- readBot = async (botId, signal) => decodeMobiusBot(await this.#executor.get(projectBotPath(this.#projectId, botId, ""), signal));
383
- reviseProfile = async (botId, request, signal) => {
384
- const value = requestRecord(request, ["avatarRef", "description", "displayName", "expectedRevision"], "Bot profile revision request");
385
- return new MobiusBotProfileRevision(await this.#executor.post(projectBotPath(this.#projectId, botId, "profile-revisions"), {
386
- avatarRef: boundedText(value["avatarRef"], "Bot avatar reference", 4_096, true),
387
- description: boundedText(value["description"], "Bot description", 2_000, true),
388
- displayName: boundedText(value["displayName"], "Bot display name", 80),
389
- expectedRevision: boundedInteger(value["expectedRevision"], "Bot lifecycle revision", 1, Number.MAX_SAFE_INTEGER),
390
- }, signal));
391
- };
392
- listBehaviors = async (botId, signal) => new MobiusBotBehaviorDirectory(await this.#executor.get(projectBotPath(this.#projectId, botId, "behavior-revisions"), signal));
393
- createBehavior = async (botId, request, signal) => {
394
- const value = requestRecord(request, ["agentConfiguration", "expectedRevision", "instructions", "requiredCapabilities"], "Bot behavior request");
395
- const configuration = value["agentConfiguration"];
396
- if (!isRecord(configuration)) {
397
- throw new MobiusValidationError("The Bot Agent configuration is invalid");
398
- }
399
- return decodeMobiusBotBehavior(await this.#executor.post(projectBotPath(this.#projectId, botId, "behavior-revisions"), {
400
- agentConfiguration: Object.freeze(Object.fromEntries(Object.entries(configuration))),
401
- expectedRevision: boundedInteger(value["expectedRevision"], "Bot behavior revision", 0, Number.MAX_SAFE_INTEGER),
402
- instructions: boundedText(value["instructions"], "Bot behavior instructions", 100_000, true),
403
- requiredCapabilities: identifiers(value["requiredCapabilities"], "Bot behavior capability", 32),
404
- }, signal));
405
- };
406
- listBindings = async (botId, signal) => new MobiusBotBindingDirectory(await this.#executor.get(projectBotPath(this.#projectId, botId, "execution-bindings"), signal));
407
- /**
408
- * @deprecated Use `client.runtimes.discoverAgentSettings(...)` instead.
409
- */
410
- readAgentConfiguration = async (botId, signal) => new MobiusBotAgentConfiguration(await this.#executor.post(projectBotPath(this.#projectId, botId, "agent-configuration"), {}, signal));
411
- createBinding = async (botId, request, signal) => {
412
- const value = requestRecord(request, [
413
- "agentConfigRevision",
414
- "agentRef",
415
- "allowedDeliveryTargetIds",
416
- "behaviorRevisionId",
417
- "completionPolicy",
418
- "executionConfiguration",
419
- "expectedRevision",
420
- "runtimeId",
421
- "workspaceRef",
422
- ], "Bot binding request");
423
- const policy = value["completionPolicy"];
424
- if (!(policy instanceof MobiusBotCompletionPolicy)) {
425
- throw new MobiusValidationError("The Bot completion policy is invalid");
426
- }
427
- return new MobiusBotBindingRequestAcceptance(await this.#executor.post(projectBotPath(this.#projectId, botId, "execution-bindings"), {
428
- agentConfigRevision: boundedInteger(value["agentConfigRevision"], "Agent configuration revision", 1, Number.MAX_SAFE_INTEGER),
429
- agentRef: identifier(value["agentRef"], "Agent"),
430
- allowedDeliveryTargetIds: identifiers(value["allowedDeliveryTargetIds"], "delivery target", 64),
431
- behaviorRevisionId: identifier(value["behaviorRevisionId"], "Bot behavior"),
432
- completionPolicy: serializedCompletionPolicy(policy),
433
- executionConfiguration: executionConfiguration(value["executionConfiguration"]),
434
- expectedRevision: boundedInteger(value["expectedRevision"], "Bot lifecycle revision", 1, Number.MAX_SAFE_INTEGER),
435
- runtimeId: identifier(value["runtimeId"], "Runtime"),
436
- workspaceRef: boundedText(value["workspaceRef"], "Bot workspace", 2_048),
437
- }, signal));
438
- };
439
- suspendBot = async (botId, expectedRevision, signal) => await this.transitionBot(botId, "suspend", expectedRevision, signal);
440
- resumeBot = async (botId, expectedRevision, signal) => await this.transitionBot(botId, "resume", expectedRevision, signal);
441
- archiveBot = async (botId, expectedRevision, signal) => await this.transitionBot(botId, "archive", expectedRevision, signal);
442
- listConversations = async (botId, signal) => new MobiusBotConversationDirectory(await this.#executor.get(projectBotPath(this.#projectId, botId, "conversations"), signal));
443
- createConversation = async (botId, request, signal) => {
444
- const value = requestRecord(request, ["clientConversationKey"], "owner Bot conversation request");
445
- return decodeMobiusOwnerBotConversation(await this.#executor.post(projectBotPath(this.#projectId, botId, "conversations"), {
446
- clientConversationKey: identifier(value["clientConversationKey"], "client conversation"),
447
- }, signal));
448
- };
449
- createProjectConversation = async (request, signal) => {
450
- const hasConfiguration = request.configuration !== undefined;
451
- const value = requestRecord(request, hasConfiguration
452
- ? ["botId", "clientReference", "configuration", "idempotencyKey", "title"]
453
- : ["botId", "clientReference", "idempotencyKey", "title"], "Project Conversation request");
454
- const configuration = value["configuration"];
455
- if (configuration !== undefined && !isRecord(configuration)) {
456
- throw new MobiusValidationError("The initial Conversation configuration is invalid");
457
- }
458
- return new MobiusProjectConversation(await this.#executor.post(projectConversationsPath(this.#projectId), {
459
- botId: identifier(value["botId"], "Bot"),
460
- clientReference: identifier(value["clientReference"], "client reference"),
461
- ...(configuration === undefined
462
- ? {}
463
- : { configuration: serializedInitialConversationConfiguration(configuration) }),
464
- idempotencyKey: identifier(value["idempotencyKey"], "Conversation idempotency key"),
465
- title: boundedText(value["title"], "Conversation title", 500, true),
466
- }, signal));
467
- };
468
- readProjectConversation = async (conversationId, signal) => new MobiusProjectConversation(await this.#executor.get(conversationPath(this.#projectId, conversationId, ""), signal));
469
- submitProjectConversationTurn = async (conversationId, request, signal) => {
470
- const value = requestRecord(request, ["additionalDirectoryIds", "artifactIds", "content", "idempotencyKey", "images", "resources"], "Project Conversation turn request");
471
- return new MobiusProjectConversationTurnAcceptance(await this.#executor.post(conversationPath(this.#projectId, conversationId, "turns"), {
472
- additionalDirectoryIds: identifiers(value["additionalDirectoryIds"], "additional directory", 16),
473
- artifactIds: identifiers(value["artifactIds"], "artifact", 16),
474
- content: boundedText(value["content"], "Conversation Turn content", 100_000, true),
475
- idempotencyKey: identifier(value["idempotencyKey"], "Turn idempotency key"),
476
- images: decodePromptImagesValue(value["images"]),
477
- resources: decodePromptResourcesValue(value["resources"]),
478
- }, signal));
479
- };
480
- queueProjectConversationTurn = async (conversationId, request, signal) => await this.submitProjectConversationFollowUp(conversationId, request, "queue", signal);
481
- steerProjectConversationTurn = async (conversationId, request, signal) => await this.submitProjectConversationFollowUp(conversationId, request, "steer", signal);
482
- promoteProjectConversationTurnToSteering = async (conversationId, turnId, signal) => new MobiusBotTurnSteeringAcceptance(await this.#executor.put(conversationPath(this.#projectId, conversationId, `turns/${encodeURIComponent(identifier(turnId, "turn"))}/disposition`), { disposition: "steer" }, signal));
483
- createConversationConfigurationRevision = async (conversationId, request, signal) => new MobiusConversationConfigurationAcceptance(await this.#executor.post(conversationPath(this.#projectId, conversationId, "configuration-revisions"), serializedConversationConfiguration(request), signal));
484
- submitProjectConversationFollowUp = async (conversationId, request, disposition, signal) => {
485
- const value = requestRecord(request, [
486
- "additionalDirectoryIds",
487
- "artifactIds",
488
- "content",
489
- "idempotencyKey",
490
- "images",
491
- "resources",
492
- "targetTurnId",
493
- ], "Project Conversation follow-up request");
494
- return new MobiusProjectConversationTurnAcceptance(await this.#executor.post(conversationPath(this.#projectId, conversationId, "turns"), {
495
- additionalDirectoryIds: identifiers(value["additionalDirectoryIds"], "additional directory", 16),
496
- artifactIds: identifiers(value["artifactIds"], "artifact", 16),
497
- content: boundedText(value["content"], "Conversation Turn content", 100_000, true),
498
- disposition,
499
- idempotencyKey: identifier(value["idempotencyKey"], "Turn idempotency key"),
500
- images: decodePromptImagesValue(value["images"]),
501
- resources: decodePromptResourcesValue(value["resources"]),
502
- targetTurnId: identifier(value["targetTurnId"], "target Turn"),
503
- }, signal));
504
- };
505
- submitMessage = async (botId, conversationId, request, signal) => {
506
- const value = requestRecord(request, ["actorRef", "artifactIds", "clientMessageId", "text"], "owner Bot message request");
507
- return new MobiusBotTurnAcceptance(await this.#executor.post(projectBotPath(this.#projectId, botId, `conversations/${encodeURIComponent(identifier(conversationId, "conversation"))}/messages`), {
508
- actorRef: boundedText(value["actorRef"], "Bot actor reference", 500),
509
- artifactIds: identifiers(value["artifactIds"], "artifact", 16),
510
- clientMessageId: identifier(value["clientMessageId"], "client message"),
511
- text: boundedText(value["text"], "Bot message text", 100_000, true),
512
- }, signal));
513
- };
514
- readConversationEvents = async (botId, conversationId, after, signal) => {
515
- const path = new URL(projectBotPath(this.#projectId, botId, `conversations/${encodeURIComponent(identifier(conversationId, "conversation"))}/events`), "https://mobius.invalid/");
516
- if (after.length > 0) {
517
- path.searchParams.set("after", boundedText(after, "Bot event cursor", 512));
518
- }
519
- return new MobiusBotConversationEventPage(await this.#executor.get(`${path.pathname.slice(1)}${path.search}`, signal));
520
- };
521
- waitForConversationEvents = async (botId, conversationId, after, waitMilliseconds, signal) => {
522
- const path = new URL(projectBotPath(this.#projectId, botId, `conversations/${encodeURIComponent(identifier(conversationId, "conversation"))}/events`), "https://mobius.invalid/");
523
- if (after.length > 0) {
524
- path.searchParams.set("after", boundedText(after, "Bot event cursor", 512));
525
- }
526
- path.searchParams.set("wait", boundedInteger(waitMilliseconds, "Bot event wait", 1, 10_000).toString());
527
- return new MobiusBotConversationEventPage(await this.#executor.get(`${path.pathname.slice(1)}${path.search}`, signal));
528
- };
529
- readConversationMessages = async (botId, conversationId, page, signal) => {
530
- const path = new URL(projectBotPath(this.#projectId, botId, `conversations/${encodeURIComponent(identifier(conversationId, "conversation"))}/messages`), "https://mobius.invalid/");
531
- path.searchParams.set("limit", boundedInteger(page.limit, "message page limit", 1, 100).toString());
532
- if (page.cursor.length > 0) {
533
- path.searchParams.set("cursor", boundedText(page.cursor, "message cursor", 512));
534
- }
535
- return new MobiusBotConversationMessagePage(await this.#executor.get(`${path.pathname.slice(1)}${path.search}`, signal));
536
- };
537
- readConversationToolCallDetail = async (botId, conversationId, attemptId, toolCallId, signal) => decodeMobiusToolCallDetail(await this.#executor.get(projectBotPath(this.#projectId, botId, `conversations/${encodeURIComponent(identifier(conversationId, "conversation"))}/attempts/${encodeURIComponent(identifier(attemptId, "attempt"))}/tool-calls/${encodeURIComponent(identifier(toolCallId, "tool call"))}`), signal));
538
- cancelTurn = async (botId, turnId, idempotencyKey, signal) => new MobiusBotTurnCancellationAcceptance(await this.#executor.post(projectBotPath(this.#projectId, botId, `turns/${encodeURIComponent(identifier(turnId, "turn"))}/cancel`), { idempotencyKey: identifier(idempotencyKey, "cancellation idempotency key") }, signal));
539
- listConnections = async (botId, signal) => new MobiusBotConnectionDirectory(await this.#executor.get(projectBotPath(this.#projectId, botId, "connections"), signal));
540
- createConnectionGrant = async (botId, request, signal) => {
541
- const value = requestRecord(request, ["audience", "expiresInSeconds", "label", "scopes"], "Bot connection grant request");
542
- return new MobiusBotConnectionGrant(await this.#executor.post(projectBotPath(this.#projectId, botId, "connection-grants"), {
543
- audience: identifier(value["audience"], "connector audience"),
544
- expiresInSeconds: boundedInteger(value["expiresInSeconds"], "connection grant lifetime", 60, 3_600),
545
- label: boundedText(value["label"], "connection label", 200),
546
- scopes: identifiers(value["scopes"], "Bot connection scope", 32),
547
- }, signal));
548
- };
549
- approveDeliveryTarget = async (botId, deliveryTargetId, expectedPolicyRevision, signal) => {
550
- await this.#executor.post(projectBotPath(this.#projectId, botId, `delivery-targets/${encodeURIComponent(identifier(deliveryTargetId, "delivery target"))}/approve`), {
551
- expectedPolicyRevision: boundedInteger(expectedPolicyRevision, "delivery target policy revision", 0, Number.MAX_SAFE_INTEGER),
552
- }, signal);
553
- };
554
- revokeConnection = async (botId, connectionId, expectedRevision, signal) => new MobiusRevokedBotConnection(await this.#executor.post(projectBotPath(this.#projectId, botId, `connections/${encodeURIComponent(identifier(connectionId, "connection"))}/revoke`), {
555
- expectedRevision: boundedInteger(expectedRevision, "Bot connection revision", 1, Number.MAX_SAFE_INTEGER),
556
- }, signal));
557
- transitionBot = async (botId, action, expectedRevision, signal) => decodeMobiusBot(await this.#executor.post(projectBotPath(this.#projectId, botId, action), {
558
- expectedRevision: boundedInteger(expectedRevision, "Bot lifecycle revision", 1, Number.MAX_SAFE_INTEGER),
559
- }, signal));
560
- }
561
- function connectionPath(connectionId, resource) {
562
- return `${MOBIUS_BOT_API_VERSION}/bot-connections/${encodeURIComponent(identifier(connectionId, "connection"))}/${resource}`;
563
- }
564
- export class MobiusBotConnectionResources {
565
- #connectionId;
566
- #executor;
567
- constructor(executor, connectionId) {
568
- this.#executor = executor;
569
- this.#connectionId = connectionId;
570
- }
571
- rotateCredential = async (signal) => new MobiusBotConnectionCredentialRotation(await this.#executor.post(connectionPath(this.#connectionId, "credentials/rotate"), {}, signal));
572
- revoke = async (signal) => new MobiusRevokedBotConnection(await this.#executor.post(connectionPath(this.#connectionId, "revoke"), {}, signal));
573
- }
574
- export class MobiusBotDeliveryTargetResources {
575
- #connectionId;
576
- #executor;
577
- constructor(executor, connectionId) {
578
- this.#executor = executor;
579
- this.#connectionId = connectionId;
580
- }
581
- create = async (request, signal) => {
582
- const value = requestRecord(request, ["alias"], "Bot delivery target request");
583
- return new MobiusBotDeliveryTarget(await this.#executor.post(connectionPath(this.#connectionId, "delivery-targets"), { alias: identifier(value["alias"], "delivery target alias") }, signal));
584
- };
585
- disable = async (deliveryTargetId, signal) => new MobiusDisabledBotDeliveryTarget(await this.#executor.post(connectionPath(this.#connectionId, `delivery-targets/${encodeURIComponent(identifier(deliveryTargetId, "delivery target"))}/disable`), {}, signal));
586
- }
587
- export class MobiusBotConversationResources {
588
- #executor;
589
- #projectId;
590
- constructor(executor, projectId) {
591
- this.#executor = executor;
592
- this.#projectId = projectId;
593
- }
594
- create = async (botId, request, signal) => {
595
- const value = requestRecord(request, ["clientConversationKey", "replyDeliveryTargetId", "title"], "connected Bot conversation request");
596
- return new MobiusConnectedBotConversation(await this.#executor.post(projectBotPath(this.#projectId, botId, "conversations"), {
597
- clientConversationKey: identifier(value["clientConversationKey"], "client conversation"),
598
- replyDeliveryTargetId: identifier(value["replyDeliveryTargetId"], "reply delivery target"),
599
- title: boundedText(value["title"], "Bot conversation title", 500, true),
600
- }, signal));
601
- };
602
- submitMessage = async (botId, conversationId, request, signal) => {
603
- const value = requestRecord(request, ["actorRef", "clientMessageId", "resourceRefs", "text"], "Bot message request");
604
- return new MobiusBotTurnAcceptance(await this.#executor.post(projectBotPath(this.#projectId, botId, `conversations/${encodeURIComponent(identifier(conversationId, "conversation"))}/messages`), {
605
- actorRef: boundedText(value["actorRef"], "external actor reference", 500),
606
- clientMessageId: identifier(value["clientMessageId"], "client message"),
607
- resourceRefs: identifiers(value["resourceRefs"], "resource reference", 16),
608
- text: boundedText(value["text"], "Bot message text", 100_000),
609
- }, signal));
610
- };
611
- readEvents = async (botId, conversationId, after, signal) => {
612
- const path = new URL(projectBotPath(this.#projectId, botId, `conversations/${encodeURIComponent(identifier(conversationId, "conversation"))}/events`), "https://mobius.invalid/");
613
- if (after.length > 0) {
614
- path.searchParams.set("after", boundedText(after, "Bot event cursor", 512));
615
- }
616
- return new MobiusBotConversationEventPage(await this.#executor.get(`${path.pathname.slice(1)}${path.search}`, signal));
617
- };
618
- cancelTurn = async (botId, turnId, idempotencyKey, signal) => new MobiusBotTurnCancellationAcceptance(await this.#executor.post(projectBotPath(this.#projectId, botId, `turns/${encodeURIComponent(identifier(turnId, "turn"))}/cancel`), { idempotencyKey: identifier(idempotencyKey, "cancellation idempotency key") }, signal));
619
- }
620
- export class MobiusBotOutboundMessageResources {
621
- #connectionId;
622
- #executor;
623
- constructor(executor, connectionId) {
624
- this.#executor = executor;
625
- this.#connectionId = connectionId;
626
- }
627
- read = async (after, limit, signal) => {
628
- const path = new URL(connectionPath(this.#connectionId, "outbound-events"), "https://mobius.invalid/");
629
- path.searchParams.set("after", boundedInteger(after, "outbound cursor", 0, Number.MAX_SAFE_INTEGER).toString());
630
- path.searchParams.set("limit", boundedInteger(limit, "outbound page limit", 1, 100).toString());
631
- return new MobiusBotOutboundEventPage(await this.#executor.get(`${path.pathname.slice(1)}${path.search}`, signal));
632
- };
633
- delivered = async (outboundMessageId, claimId, signal) => await this.acknowledge(outboundMessageId, "delivered", { claimId: identifier(claimId, "claim") }, signal);
634
- retryableFailure = async (outboundMessageId, claimId, code, retryAfterSeconds, signal) => await this.acknowledge(outboundMessageId, "retryable-failure", {
635
- claimId: identifier(claimId, "claim"),
636
- code: identifier(code, "failure code"),
637
- retryAfterSeconds: boundedInteger(retryAfterSeconds, "retry delay", 1, 3_600),
638
- }, signal);
639
- terminalFailure = async (outboundMessageId, claimId, code, signal) => await this.acknowledge(outboundMessageId, "terminal-failure", { claimId: identifier(claimId, "claim"), code: identifier(code, "failure code") }, signal);
640
- acknowledge = async (outboundMessageId, outcome, body, signal) => new MobiusBotDeliveryAcknowledgement(await this.#executor.post(connectionPath(this.#connectionId, `outbound-messages/${encodeURIComponent(identifier(outboundMessageId, "outbound message"))}/${outcome}`), body, signal));
641
- }
642
- export class MobiusBotConnectorClient {
643
- connection;
644
- conversations;
645
- deliveryTargets;
646
- outboundMessages;
647
- constructor(options) {
648
- const connectionId = identifier(options.connectionId, "connection");
649
- const projectId = identifier(options.projectId, "project");
650
- const executor = new BotRequestExecutor(options, new CredentialBotRequestAuthentication(options.credentialProvider), "");
651
- this.connection = new MobiusBotConnectionResources(executor, connectionId);
652
- this.conversations = new MobiusBotConversationResources(executor, projectId);
653
- this.deliveryTargets = new MobiusBotDeliveryTargetResources(executor, connectionId);
654
- this.outboundMessages = new MobiusBotOutboundMessageResources(executor, connectionId);
655
- }
656
- }
657
- export function createMobiusBotConnectorClient(options) {
658
- return new MobiusBotConnectorClient(options);
659
- }
660
- export async function redeemMobiusBotConnectionGrant(options, request, signal) {
661
- const value = requestRecord(request, ["audience", "connectorPrincipalId", "grantId", "grantSecret"], "Bot connection grant redemption");
662
- const executor = new BotRequestExecutor(options, new AnonymousBotRequestAuthentication(), "");
663
- return new MobiusBotConnectionCredential(await executor.post(`${MOBIUS_BOT_API_VERSION}/bot-connection-grants/redeem`, {
664
- audience: identifier(value["audience"], "connector audience"),
665
- connectorPrincipalId: boundedText(value["connectorPrincipalId"], "connector principal", 500),
666
- grantId: identifier(value["grantId"], "connection grant"),
667
- grantSecret: token(value["grantSecret"], "connection grant secret"),
668
- }, signal));
669
- }
670
- //# sourceMappingURL=bot-service-client.js.map