@moxt-ai/mobius-sdk 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/dist/bot-owner-resources.d.ts +274 -0
- package/dist/bot-owner-resources.d.ts.map +1 -0
- package/dist/bot-owner-resources.js +748 -0
- package/dist/bot-owner-resources.js.map +1 -0
- package/dist/bot-resources.d.ts +152 -0
- package/dist/bot-resources.d.ts.map +1 -0
- package/dist/bot-resources.js +469 -0
- package/dist/bot-resources.js.map +1 -0
- package/dist/bot-service-client.d.ts +204 -0
- package/dist/bot-service-client.d.ts.map +1 -0
- package/dist/bot-service-client.js +587 -0
- package/dist/bot-service-client.js.map +1 -0
- package/dist/browser.d.ts +166 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +379 -0
- package/dist/browser.js.map +1 -0
- package/dist/channel.d.ts +3 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +3 -0
- package/dist/channel.js.map +1 -0
- package/dist/client.d.ts +116 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +624 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +24 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +47 -0
- package/dist/errors.js.map +1 -0
- package/dist/examples/browser.d.ts +13 -0
- package/dist/examples/browser.d.ts.map +1 -0
- package/dist/examples/browser.js +23 -0
- package/dist/examples/browser.js.map +1 -0
- package/dist/examples/moxt-server.d.ts +38 -0
- package/dist/examples/moxt-server.d.ts.map +1 -0
- package/dist/examples/moxt-server.js +81 -0
- package/dist/examples/moxt-server.js.map +1 -0
- package/dist/examples/node.d.ts +2 -0
- package/dist/examples/node.d.ts.map +1 -0
- package/dist/examples/node.js +20 -0
- package/dist/examples/node.js.map +1 -0
- package/dist/examples/platform-server.d.ts +2 -0
- package/dist/examples/platform-server.d.ts.map +1 -0
- package/dist/examples/platform-server.js +39 -0
- package/dist/examples/platform-server.js.map +1 -0
- package/dist/examples/workflow.d.ts +20 -0
- package/dist/examples/workflow.d.ts.map +1 -0
- package/dist/examples/workflow.js +76 -0
- package/dist/examples/workflow.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/platform.d.ts +184 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +434 -0
- package/dist/platform.js.map +1 -0
- package/dist/project-authentication.d.ts +239 -0
- package/dist/project-authentication.d.ts.map +1 -0
- package/dist/project-authentication.js +752 -0
- package/dist/project-authentication.js.map +1 -0
- package/dist/resources.d.ts +602 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +1411 -0
- package/dist/resources.js.map +1 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +7 -0
- package/dist/server.js.map +1 -0
- package/dist/service-client.d.ts +392 -0
- package/dist/service-client.d.ts.map +1 -0
- package/dist/service-client.js +1061 -0
- package/dist/service-client.js.map +1 -0
- package/package.json +92 -0
|
@@ -0,0 +1,1411 @@
|
|
|
1
|
+
import { AGENT_ACTIVITY_KIND, AGENT_MESSAGE_DELTA_KIND, decodeAttempt, decodeCommittedSessionEvent, decodeInteraction, decodePromptImagesValue, decodePromptResourcesValue, decodeRecordedSessionEvent, decodeTurn, MOBIUS_API_VERSION, MOBIUS_EVENT_FORMAT_VERSION, MOBIUS_SESSION_EVENT_STREAM_EVENT, MOBIUS_SESSION_EVENT_STREAM_MEDIA_TYPE, MOBIUS_SESSION_EVENT_STREAM_TRANSPORT, MOBIUS_SESSION_EXPORT_FORMAT_VERSION, SESSION_COMPLETED_KIND, SESSION_FAILED_KIND, SESSION_STARTED_KIND, sessionCapabilitiesSchema, } from "@moxt-ai/mobius-protocol";
|
|
2
|
+
import { MobiusProtocolError, MobiusValidationError } from "./errors.js";
|
|
3
|
+
const IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
4
|
+
const SESSION_CAPABILITY_FIELDS = [
|
|
5
|
+
"additionalDirectories",
|
|
6
|
+
"audioPrompt",
|
|
7
|
+
"closeSession",
|
|
8
|
+
"deleteSession",
|
|
9
|
+
"embeddedContextPrompt",
|
|
10
|
+
"imagePrompt",
|
|
11
|
+
"listSessions",
|
|
12
|
+
"loadSession",
|
|
13
|
+
"promptQueueing",
|
|
14
|
+
"resumeSession",
|
|
15
|
+
"steering",
|
|
16
|
+
"unstableForkSession",
|
|
17
|
+
];
|
|
18
|
+
function invalidResponse(message) {
|
|
19
|
+
return new MobiusProtocolError(message);
|
|
20
|
+
}
|
|
21
|
+
function isRecord(value) {
|
|
22
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23
|
+
}
|
|
24
|
+
function record(value, name) {
|
|
25
|
+
if (!isRecord(value)) {
|
|
26
|
+
throw invalidResponse(`The service returned an invalid ${name}`);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
function stringField(value, field, maximumLength = 8_500_000) {
|
|
31
|
+
const candidate = value[field];
|
|
32
|
+
if (typeof candidate !== "string" || candidate.length > maximumLength) {
|
|
33
|
+
throw invalidResponse(`The service returned an invalid ${field}`);
|
|
34
|
+
}
|
|
35
|
+
return candidate;
|
|
36
|
+
}
|
|
37
|
+
function identifierField(value, field) {
|
|
38
|
+
const candidate = stringField(value, field, 128);
|
|
39
|
+
if (!IDENTIFIER_PATTERN.test(candidate)) {
|
|
40
|
+
throw invalidResponse(`The service returned an invalid ${field}`);
|
|
41
|
+
}
|
|
42
|
+
return candidate;
|
|
43
|
+
}
|
|
44
|
+
function integerField(value, field) {
|
|
45
|
+
const candidate = value[field];
|
|
46
|
+
if (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0) {
|
|
47
|
+
throw invalidResponse(`The service returned an invalid ${field}`);
|
|
48
|
+
}
|
|
49
|
+
return candidate;
|
|
50
|
+
}
|
|
51
|
+
function booleanField(value, field) {
|
|
52
|
+
const candidate = value[field];
|
|
53
|
+
if (typeof candidate !== "boolean") {
|
|
54
|
+
throw invalidResponse(`The service returned an invalid ${field}`);
|
|
55
|
+
}
|
|
56
|
+
return candidate;
|
|
57
|
+
}
|
|
58
|
+
function arrayField(value, field, maximumLength = 10_000) {
|
|
59
|
+
const candidate = value[field];
|
|
60
|
+
if (!Array.isArray(candidate) || candidate.length > maximumLength) {
|
|
61
|
+
throw invalidResponse(`The service returned an invalid ${field}`);
|
|
62
|
+
}
|
|
63
|
+
return candidate;
|
|
64
|
+
}
|
|
65
|
+
function nullableCursor(value, field) {
|
|
66
|
+
const candidate = value[field];
|
|
67
|
+
if (candidate === null) {
|
|
68
|
+
return "";
|
|
69
|
+
}
|
|
70
|
+
if (typeof candidate !== "string" || candidate.length > 512) {
|
|
71
|
+
throw invalidResponse(`The service returned an invalid ${field}`);
|
|
72
|
+
}
|
|
73
|
+
return candidate;
|
|
74
|
+
}
|
|
75
|
+
function validateTimestamp(value, field) {
|
|
76
|
+
if (Number.isNaN(Date.parse(value))) {
|
|
77
|
+
throw invalidResponse(`The service returned an invalid ${field}`);
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
export class MobiusSessionEventCapabilities {
|
|
82
|
+
eventName;
|
|
83
|
+
formatVersion;
|
|
84
|
+
mediaType;
|
|
85
|
+
transport;
|
|
86
|
+
constructor(eventName, formatVersion, mediaType, transport) {
|
|
87
|
+
this.eventName = eventName;
|
|
88
|
+
this.formatVersion = formatVersion;
|
|
89
|
+
this.mediaType = mediaType;
|
|
90
|
+
this.transport = transport;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export class MobiusArtifactCapabilities {
|
|
94
|
+
downloadTransport;
|
|
95
|
+
uploadProtocol;
|
|
96
|
+
constructor(downloadTransport, uploadProtocol) {
|
|
97
|
+
this.downloadTransport = downloadTransport;
|
|
98
|
+
this.uploadProtocol = uploadProtocol;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export class MobiusAuthenticationCapabilities {
|
|
102
|
+
browserCredentials;
|
|
103
|
+
maximumBrowserCredentialLifetimeSeconds;
|
|
104
|
+
minimumBrowserCredentialLifetimeSeconds;
|
|
105
|
+
constructor(browserCredentials, maximumBrowserCredentialLifetimeSeconds, minimumBrowserCredentialLifetimeSeconds) {
|
|
106
|
+
this.browserCredentials = browserCredentials;
|
|
107
|
+
this.maximumBrowserCredentialLifetimeSeconds = maximumBrowserCredentialLifetimeSeconds;
|
|
108
|
+
this.minimumBrowserCredentialLifetimeSeconds = minimumBrowserCredentialLifetimeSeconds;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export class MobiusPortabilityCapabilities {
|
|
112
|
+
exportFormatVersion;
|
|
113
|
+
nativeContextImport;
|
|
114
|
+
targetBindingRequired;
|
|
115
|
+
constructor(exportFormatVersion, nativeContextImport, targetBindingRequired) {
|
|
116
|
+
this.exportFormatVersion = exportFormatVersion;
|
|
117
|
+
this.nativeContextImport = nativeContextImport;
|
|
118
|
+
this.targetBindingRequired = targetBindingRequired;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export class MobiusResourceCapabilities {
|
|
122
|
+
artifacts;
|
|
123
|
+
attempts;
|
|
124
|
+
browserCredentials;
|
|
125
|
+
events;
|
|
126
|
+
interactions;
|
|
127
|
+
messages;
|
|
128
|
+
portability;
|
|
129
|
+
runtimePairings;
|
|
130
|
+
runtimes;
|
|
131
|
+
sessions;
|
|
132
|
+
toolCalls;
|
|
133
|
+
turns;
|
|
134
|
+
constructor(resources) {
|
|
135
|
+
this.artifacts = booleanField(resources, "artifacts");
|
|
136
|
+
this.attempts = booleanField(resources, "attempts");
|
|
137
|
+
this.browserCredentials = booleanField(resources, "browserCredentials");
|
|
138
|
+
this.events = booleanField(resources, "events");
|
|
139
|
+
this.interactions = booleanField(resources, "interactions");
|
|
140
|
+
this.messages = booleanField(resources, "messages");
|
|
141
|
+
this.portability = booleanField(resources, "portability");
|
|
142
|
+
this.runtimePairings = booleanField(resources, "runtimePairings");
|
|
143
|
+
this.runtimes = booleanField(resources, "runtimes");
|
|
144
|
+
this.sessions = booleanField(resources, "sessions");
|
|
145
|
+
this.toolCalls = booleanField(resources, "toolCalls");
|
|
146
|
+
this.turns = booleanField(resources, "turns");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
export class MobiusServiceCapabilities {
|
|
150
|
+
apiVersion;
|
|
151
|
+
artifacts;
|
|
152
|
+
authentication;
|
|
153
|
+
portability;
|
|
154
|
+
resources;
|
|
155
|
+
sessionEvents;
|
|
156
|
+
constructor(apiVersion, artifacts, authentication, portability, resources, sessionEvents) {
|
|
157
|
+
this.apiVersion = apiVersion;
|
|
158
|
+
this.artifacts = artifacts;
|
|
159
|
+
this.authentication = authentication;
|
|
160
|
+
this.portability = portability;
|
|
161
|
+
this.resources = resources;
|
|
162
|
+
this.sessionEvents = sessionEvents;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
export function decodeMobiusServiceCapabilities(value) {
|
|
166
|
+
const capabilities = record(value, "service capabilities");
|
|
167
|
+
const resources = record(capabilities["resources"], "resource capabilities");
|
|
168
|
+
const artifacts = record(capabilities["artifacts"], "artifact capabilities");
|
|
169
|
+
const authentication = record(capabilities["authentication"], "authentication capabilities");
|
|
170
|
+
const portability = record(capabilities["portability"], "portability capabilities");
|
|
171
|
+
const sessionEvents = record(capabilities["sessionEvents"], "Session event capabilities");
|
|
172
|
+
const apiVersion = stringField(capabilities, "apiVersion", 32);
|
|
173
|
+
const eventName = stringField(sessionEvents, "eventName", 128);
|
|
174
|
+
const formatVersion = stringField(sessionEvents, "formatVersion", 32);
|
|
175
|
+
const mediaType = stringField(sessionEvents, "mediaType", 128);
|
|
176
|
+
const transport = stringField(sessionEvents, "transport", 32);
|
|
177
|
+
const downloadTransport = stringField(artifacts, "downloadTransport", 32);
|
|
178
|
+
const uploadProtocol = stringField(artifacts, "uploadProtocol", 32);
|
|
179
|
+
const exportFormatVersion = stringField(portability, "exportFormatVersion", 32);
|
|
180
|
+
if (apiVersion !== MOBIUS_API_VERSION ||
|
|
181
|
+
eventName !== MOBIUS_SESSION_EVENT_STREAM_EVENT ||
|
|
182
|
+
formatVersion !== MOBIUS_EVENT_FORMAT_VERSION ||
|
|
183
|
+
mediaType !== MOBIUS_SESSION_EVENT_STREAM_MEDIA_TYPE ||
|
|
184
|
+
transport !== MOBIUS_SESSION_EVENT_STREAM_TRANSPORT ||
|
|
185
|
+
downloadTransport !== "authorized-stream" ||
|
|
186
|
+
uploadProtocol !== "two-stage" ||
|
|
187
|
+
exportFormatVersion !== MOBIUS_SESSION_EXPORT_FORMAT_VERSION) {
|
|
188
|
+
throw invalidResponse("The service returned unsupported Mobius API capabilities");
|
|
189
|
+
}
|
|
190
|
+
return new MobiusServiceCapabilities(apiVersion, new MobiusArtifactCapabilities(downloadTransport, uploadProtocol), new MobiusAuthenticationCapabilities(booleanField(authentication, "browserCredentials"), integerField(authentication, "maximumBrowserCredentialLifetimeSeconds"), integerField(authentication, "minimumBrowserCredentialLifetimeSeconds")), new MobiusPortabilityCapabilities(exportFormatVersion, booleanField(portability, "nativeContextImport"), booleanField(portability, "targetBindingRequired")), new MobiusResourceCapabilities(resources), new MobiusSessionEventCapabilities(eventName, formatVersion, mediaType, transport));
|
|
191
|
+
}
|
|
192
|
+
export class MobiusRecordingPolicy {
|
|
193
|
+
contentLimitBytes;
|
|
194
|
+
hotEventLimit;
|
|
195
|
+
idempotencyRetentionMilliseconds;
|
|
196
|
+
level;
|
|
197
|
+
retentionMilliseconds;
|
|
198
|
+
constructor(level, retentionMilliseconds, hotEventLimit, contentLimitBytes, idempotencyRetentionMilliseconds = retentionMilliseconds) {
|
|
199
|
+
if ((level !== "full" && level !== "summary") ||
|
|
200
|
+
!Number.isSafeInteger(retentionMilliseconds) ||
|
|
201
|
+
retentionMilliseconds < 60_000 ||
|
|
202
|
+
!Number.isSafeInteger(hotEventLimit) ||
|
|
203
|
+
hotEventLimit < 10 ||
|
|
204
|
+
!Number.isSafeInteger(contentLimitBytes) ||
|
|
205
|
+
contentLimitBytes < 1_024 ||
|
|
206
|
+
!Number.isSafeInteger(idempotencyRetentionMilliseconds) ||
|
|
207
|
+
idempotencyRetentionMilliseconds < 60_000 ||
|
|
208
|
+
idempotencyRetentionMilliseconds > retentionMilliseconds) {
|
|
209
|
+
throw new MobiusValidationError("The Session recording policy is invalid");
|
|
210
|
+
}
|
|
211
|
+
this.contentLimitBytes = contentLimitBytes;
|
|
212
|
+
this.hotEventLimit = hotEventLimit;
|
|
213
|
+
this.idempotencyRetentionMilliseconds = idempotencyRetentionMilliseconds;
|
|
214
|
+
this.level = level;
|
|
215
|
+
this.retentionMilliseconds = retentionMilliseconds;
|
|
216
|
+
}
|
|
217
|
+
toJSON = () => new MobiusRecordingPolicyRequestPayload(this.level, this.retentionMilliseconds, this.hotEventLimit, this.contentLimitBytes, this.idempotencyRetentionMilliseconds);
|
|
218
|
+
}
|
|
219
|
+
class MobiusRecordingPolicyRequestPayload {
|
|
220
|
+
contentLimitBytes;
|
|
221
|
+
hotEventLimit;
|
|
222
|
+
idempotencyRetentionMilliseconds;
|
|
223
|
+
level;
|
|
224
|
+
retentionMilliseconds;
|
|
225
|
+
constructor(level, retentionMilliseconds, hotEventLimit, contentLimitBytes, idempotencyRetentionMilliseconds) {
|
|
226
|
+
this.contentLimitBytes = contentLimitBytes;
|
|
227
|
+
this.hotEventLimit = hotEventLimit;
|
|
228
|
+
this.idempotencyRetentionMilliseconds = idempotencyRetentionMilliseconds;
|
|
229
|
+
this.level = level;
|
|
230
|
+
this.retentionMilliseconds = retentionMilliseconds;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
export class MobiusSessionAccess {
|
|
234
|
+
credential;
|
|
235
|
+
credentialId;
|
|
236
|
+
projectId;
|
|
237
|
+
sessionId;
|
|
238
|
+
expiresAt;
|
|
239
|
+
constructor(value) {
|
|
240
|
+
const resource = record(value, "Session access");
|
|
241
|
+
this.credential = stringField(resource, "credential", 256);
|
|
242
|
+
if (!/^msession_[A-Za-z0-9_-]{22}_[A-Za-z0-9_-]{43}$/u.test(this.credential)) {
|
|
243
|
+
throw invalidResponse("The Session credential is invalid");
|
|
244
|
+
}
|
|
245
|
+
this.credentialId = identifierField(resource, "credentialId");
|
|
246
|
+
this.projectId = identifierField(resource, "projectId");
|
|
247
|
+
this.sessionId = identifierField(resource, "sessionId");
|
|
248
|
+
this.expiresAt = validateTimestamp(stringField(resource, "expiresAt", 128), "expiresAt");
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
export class MobiusSessionImportBinding {
|
|
252
|
+
agentRef;
|
|
253
|
+
bindingId;
|
|
254
|
+
configRevision;
|
|
255
|
+
runtimeId;
|
|
256
|
+
workspaceRef;
|
|
257
|
+
constructor(bindingId, runtimeId, agentRef, workspaceRef, configRevision = 1) {
|
|
258
|
+
this.agentRef = agentRef;
|
|
259
|
+
this.bindingId = bindingId;
|
|
260
|
+
this.configRevision = configRevision;
|
|
261
|
+
this.runtimeId = runtimeId;
|
|
262
|
+
this.workspaceRef = workspaceRef;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
export class MobiusBrowserCredentialRequest {
|
|
266
|
+
expiresInSeconds;
|
|
267
|
+
constructor(expiresInSeconds) {
|
|
268
|
+
if (!Number.isSafeInteger(expiresInSeconds) || expiresInSeconds < 60 || expiresInSeconds > 3_600) {
|
|
269
|
+
throw new MobiusValidationError("The browser credential lifetime is invalid");
|
|
270
|
+
}
|
|
271
|
+
this.expiresInSeconds = expiresInSeconds;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
export class MobiusRuntimePairingRequest {
|
|
275
|
+
idempotencyKey;
|
|
276
|
+
constructor(idempotencyKey) {
|
|
277
|
+
if (!IDENTIFIER_PATTERN.test(idempotencyKey)) {
|
|
278
|
+
throw new MobiusValidationError("The Runtime pairing idempotency key is invalid");
|
|
279
|
+
}
|
|
280
|
+
this.idempotencyKey = idempotencyKey;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
export class MobiusArtifactUploadRequest {
|
|
284
|
+
byteLength;
|
|
285
|
+
mediaType;
|
|
286
|
+
name;
|
|
287
|
+
sha256;
|
|
288
|
+
constructor(name, mediaType, byteLength, sha256) {
|
|
289
|
+
if (name.length < 1 ||
|
|
290
|
+
name.length > 500 ||
|
|
291
|
+
name.includes("\0") ||
|
|
292
|
+
mediaType.length < 1 ||
|
|
293
|
+
mediaType.length > 255 ||
|
|
294
|
+
mediaType.includes("\r") ||
|
|
295
|
+
mediaType.includes("\n") ||
|
|
296
|
+
!Number.isSafeInteger(byteLength) ||
|
|
297
|
+
byteLength < 1 ||
|
|
298
|
+
!/^[a-f0-9]{64}$/.test(sha256)) {
|
|
299
|
+
throw new MobiusValidationError("The artifact upload request is invalid");
|
|
300
|
+
}
|
|
301
|
+
this.byteLength = byteLength;
|
|
302
|
+
this.mediaType = mediaType;
|
|
303
|
+
this.name = name;
|
|
304
|
+
this.sha256 = sha256;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
export class MobiusArtifact {
|
|
308
|
+
artifactId;
|
|
309
|
+
byteLength;
|
|
310
|
+
createdAt;
|
|
311
|
+
mediaType;
|
|
312
|
+
name;
|
|
313
|
+
sessionId;
|
|
314
|
+
sha256;
|
|
315
|
+
constructor(sessionId, artifactId, name, mediaType, byteLength, sha256, createdAt) {
|
|
316
|
+
this.artifactId = artifactId;
|
|
317
|
+
this.byteLength = byteLength;
|
|
318
|
+
this.createdAt = createdAt;
|
|
319
|
+
this.mediaType = mediaType;
|
|
320
|
+
this.name = name;
|
|
321
|
+
this.sessionId = sessionId;
|
|
322
|
+
this.sha256 = sha256;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
export class MobiusUploadingArtifact extends MobiusArtifact {
|
|
326
|
+
expiresAt;
|
|
327
|
+
state = "uploading";
|
|
328
|
+
constructor(sessionId, artifactId, name, mediaType, byteLength, sha256, createdAt, expiresAt) {
|
|
329
|
+
super(sessionId, artifactId, name, mediaType, byteLength, sha256, createdAt);
|
|
330
|
+
this.expiresAt = expiresAt;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
export class MobiusArtifactUpload extends MobiusUploadingArtifact {
|
|
334
|
+
uploadToken;
|
|
335
|
+
constructor(artifact, uploadToken) {
|
|
336
|
+
super(artifact.sessionId, artifact.artifactId, artifact.name, artifact.mediaType, artifact.byteLength, artifact.sha256, artifact.createdAt, artifact.expiresAt);
|
|
337
|
+
this.uploadToken = uploadToken;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
export class MobiusAvailableArtifact extends MobiusArtifact {
|
|
341
|
+
availableAt;
|
|
342
|
+
state = "available";
|
|
343
|
+
constructor(sessionId, artifactId, name, mediaType, byteLength, sha256, createdAt, availableAt) {
|
|
344
|
+
super(sessionId, artifactId, name, mediaType, byteLength, sha256, createdAt);
|
|
345
|
+
this.availableAt = availableAt;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
export class MobiusExpiredArtifact extends MobiusArtifact {
|
|
349
|
+
expiredAt;
|
|
350
|
+
state = "expired";
|
|
351
|
+
constructor(sessionId, artifactId, name, mediaType, byteLength, sha256, createdAt, expiredAt) {
|
|
352
|
+
super(sessionId, artifactId, name, mediaType, byteLength, sha256, createdAt);
|
|
353
|
+
this.expiredAt = expiredAt;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
function artifactFields(value) {
|
|
357
|
+
const sha256 = stringField(value, "sha256", 64);
|
|
358
|
+
if (!/^[a-f0-9]{64}$/.test(sha256)) {
|
|
359
|
+
throw invalidResponse("The service returned an invalid artifact digest");
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
artifactId: identifierField(value, "artifactId"),
|
|
363
|
+
byteLength: integerField(value, "byteLength"),
|
|
364
|
+
createdAt: validateTimestamp(stringField(value, "createdAt", 128), "createdAt"),
|
|
365
|
+
mediaType: stringField(value, "mediaType", 255),
|
|
366
|
+
name: stringField(value, "name", 500),
|
|
367
|
+
sessionId: identifierField(value, "sessionId"),
|
|
368
|
+
sha256,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function uploadingArtifact(value) {
|
|
372
|
+
const fields = artifactFields(value);
|
|
373
|
+
return new MobiusUploadingArtifact(fields.sessionId, fields.artifactId, fields.name, fields.mediaType, fields.byteLength, fields.sha256, fields.createdAt, validateTimestamp(stringField(value, "expiresAt", 128), "expiresAt"));
|
|
374
|
+
}
|
|
375
|
+
export function decodeMobiusArtifactUpload(value) {
|
|
376
|
+
const artifact = record(value, "artifact upload authorization");
|
|
377
|
+
return new MobiusArtifactUpload(uploadingArtifact(artifact), stringField(artifact, "uploadToken", 256));
|
|
378
|
+
}
|
|
379
|
+
export function decodeMobiusArtifact(value) {
|
|
380
|
+
const artifact = record(value, "artifact");
|
|
381
|
+
const state = stringField(artifact, "state", 32);
|
|
382
|
+
if (state === "uploading") {
|
|
383
|
+
return uploadingArtifact(artifact);
|
|
384
|
+
}
|
|
385
|
+
const fields = artifactFields(artifact);
|
|
386
|
+
if (state === "available") {
|
|
387
|
+
return new MobiusAvailableArtifact(fields.sessionId, fields.artifactId, fields.name, fields.mediaType, fields.byteLength, fields.sha256, fields.createdAt, validateTimestamp(stringField(artifact, "availableAt", 128), "availableAt"));
|
|
388
|
+
}
|
|
389
|
+
if (state === "expired") {
|
|
390
|
+
return new MobiusExpiredArtifact(fields.sessionId, fields.artifactId, fields.name, fields.mediaType, fields.byteLength, fields.sha256, fields.createdAt, validateTimestamp(stringField(artifact, "expiredAt", 128), "expiredAt"));
|
|
391
|
+
}
|
|
392
|
+
throw invalidResponse("The service returned an invalid artifact state");
|
|
393
|
+
}
|
|
394
|
+
export function decodeMobiusAvailableArtifact(value) {
|
|
395
|
+
const artifact = decodeMobiusArtifact(value);
|
|
396
|
+
if (!(artifact instanceof MobiusAvailableArtifact)) {
|
|
397
|
+
throw invalidResponse("The service did not make the artifact available");
|
|
398
|
+
}
|
|
399
|
+
return artifact;
|
|
400
|
+
}
|
|
401
|
+
export class MobiusArtifactDownload {
|
|
402
|
+
artifact;
|
|
403
|
+
bytes;
|
|
404
|
+
constructor(artifact, bytes) {
|
|
405
|
+
this.artifact = artifact;
|
|
406
|
+
this.bytes = bytes;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
export class MobiusBrowserCredential {
|
|
410
|
+
credentialId;
|
|
411
|
+
expiresAt;
|
|
412
|
+
projectId;
|
|
413
|
+
token;
|
|
414
|
+
constructor(credentialId, expiresAt, projectId, token) {
|
|
415
|
+
this.credentialId = credentialId;
|
|
416
|
+
this.expiresAt = expiresAt;
|
|
417
|
+
this.projectId = projectId;
|
|
418
|
+
this.token = token;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
export function decodeMobiusBrowserCredential(value) {
|
|
422
|
+
const credential = record(value, "browser credential");
|
|
423
|
+
return new MobiusBrowserCredential(identifierField(credential, "credentialId"), validateTimestamp(stringField(credential, "expiresAt", 128), "expiresAt"), identifierField(credential, "projectId"), stringField(credential, "token", 256));
|
|
424
|
+
}
|
|
425
|
+
export class MobiusAgentDescriptor {
|
|
426
|
+
agentPath;
|
|
427
|
+
agentVersion;
|
|
428
|
+
capabilities;
|
|
429
|
+
id;
|
|
430
|
+
label;
|
|
431
|
+
constructor(agentPath, agentVersion, capabilities, id, label) {
|
|
432
|
+
this.agentPath = agentPath;
|
|
433
|
+
this.agentVersion = agentVersion;
|
|
434
|
+
this.capabilities = Object.freeze({ ...capabilities });
|
|
435
|
+
this.id = id;
|
|
436
|
+
this.label = label;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
export function decodeMobiusAgentCapabilities(value) {
|
|
440
|
+
const capabilities = record(value, "Agent capabilities");
|
|
441
|
+
if (Object.keys(capabilities).length !== SESSION_CAPABILITY_FIELDS.length ||
|
|
442
|
+
SESSION_CAPABILITY_FIELDS.some((field) => !Object.hasOwn(capabilities, field))) {
|
|
443
|
+
throw invalidResponse("The service returned invalid Agent capabilities");
|
|
444
|
+
}
|
|
445
|
+
const parsed = sessionCapabilitiesSchema.safeParse(capabilities);
|
|
446
|
+
if (!parsed.success) {
|
|
447
|
+
throw invalidResponse("The service returned invalid Agent capabilities");
|
|
448
|
+
}
|
|
449
|
+
return parsed.data;
|
|
450
|
+
}
|
|
451
|
+
function decodeAgentDescriptor(value) {
|
|
452
|
+
const agent = record(value, "Agent descriptor");
|
|
453
|
+
if (Object.keys(agent).length !== 5 ||
|
|
454
|
+
!Object.hasOwn(agent, "agentPath") ||
|
|
455
|
+
!Object.hasOwn(agent, "agentVersion") ||
|
|
456
|
+
!Object.hasOwn(agent, "capabilities") ||
|
|
457
|
+
!Object.hasOwn(agent, "id") ||
|
|
458
|
+
!Object.hasOwn(agent, "label")) {
|
|
459
|
+
throw invalidResponse("The service returned an invalid Agent descriptor");
|
|
460
|
+
}
|
|
461
|
+
const agentPath = stringField(agent, "agentPath", 4_096);
|
|
462
|
+
const agentVersion = stringField(agent, "agentVersion", 128);
|
|
463
|
+
const label = stringField(agent, "label", 80);
|
|
464
|
+
if (agentPath.trim().length === 0 || agentVersion.trim().length === 0 || label.trim().length === 0) {
|
|
465
|
+
throw invalidResponse("The service returned an invalid Agent descriptor");
|
|
466
|
+
}
|
|
467
|
+
return new MobiusAgentDescriptor(agentPath, agentVersion, decodeMobiusAgentCapabilities(agent["capabilities"]), identifierField(agent, "id"), label.trim());
|
|
468
|
+
}
|
|
469
|
+
export class MobiusInstallableAgentDescriptor {
|
|
470
|
+
id;
|
|
471
|
+
label;
|
|
472
|
+
constructor(id, label) {
|
|
473
|
+
this.id = id;
|
|
474
|
+
this.label = label;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
export class MobiusMissingAgentDescriptor extends MobiusInstallableAgentDescriptor {
|
|
478
|
+
status = "agent_not_installed";
|
|
479
|
+
// biome-ignore lint/complexity/noUselessConstructor: Exposes the protected base constructor publicly.
|
|
480
|
+
constructor(id, label) {
|
|
481
|
+
super(id, label);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
export class MobiusAgentIntegrationDescriptor extends MobiusInstallableAgentDescriptor {
|
|
485
|
+
agentPath;
|
|
486
|
+
agentVersion;
|
|
487
|
+
status = "integration_not_installed";
|
|
488
|
+
constructor(agentPath, agentVersion, id, label) {
|
|
489
|
+
super(id, label);
|
|
490
|
+
this.agentPath = agentPath;
|
|
491
|
+
this.agentVersion = agentVersion;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function decodeInstallableAgentDescriptor(value) {
|
|
495
|
+
const agent = record(value, "installable Agent descriptor");
|
|
496
|
+
const id = identifierField(agent, "id");
|
|
497
|
+
const label = stringField(agent, "label", 80);
|
|
498
|
+
if (label.trim().length === 0) {
|
|
499
|
+
throw invalidResponse("The service returned an invalid installable Agent descriptor");
|
|
500
|
+
}
|
|
501
|
+
if (agent["status"] === "agent_not_installed" &&
|
|
502
|
+
Object.keys(agent).length === 3 &&
|
|
503
|
+
Object.hasOwn(agent, "id") &&
|
|
504
|
+
Object.hasOwn(agent, "label") &&
|
|
505
|
+
Object.hasOwn(agent, "status")) {
|
|
506
|
+
return new MobiusMissingAgentDescriptor(id, label.trim());
|
|
507
|
+
}
|
|
508
|
+
if (agent["status"] === "integration_not_installed" &&
|
|
509
|
+
Object.keys(agent).length === 5 &&
|
|
510
|
+
Object.hasOwn(agent, "agentPath") &&
|
|
511
|
+
Object.hasOwn(agent, "agentVersion") &&
|
|
512
|
+
Object.hasOwn(agent, "id") &&
|
|
513
|
+
Object.hasOwn(agent, "label") &&
|
|
514
|
+
Object.hasOwn(agent, "status")) {
|
|
515
|
+
const agentPath = stringField(agent, "agentPath", 4_096);
|
|
516
|
+
const agentVersion = stringField(agent, "agentVersion", 128);
|
|
517
|
+
if (agentPath.trim().length === 0 || agentVersion.trim().length === 0) {
|
|
518
|
+
throw invalidResponse("The service returned an invalid installable Agent descriptor");
|
|
519
|
+
}
|
|
520
|
+
return new MobiusAgentIntegrationDescriptor(agentPath, agentVersion.trim(), id, label.trim());
|
|
521
|
+
}
|
|
522
|
+
throw invalidResponse("The service returned an invalid installable Agent descriptor");
|
|
523
|
+
}
|
|
524
|
+
export class MobiusRuntimeDescriptor {
|
|
525
|
+
agents;
|
|
526
|
+
channelId;
|
|
527
|
+
installableAgents;
|
|
528
|
+
machineName;
|
|
529
|
+
online;
|
|
530
|
+
projectId;
|
|
531
|
+
runtimeId;
|
|
532
|
+
workspaceName;
|
|
533
|
+
constructor(agents, channelId, installableAgents, machineName, online, projectId, runtimeId, workspaceName) {
|
|
534
|
+
this.agents = agents;
|
|
535
|
+
this.channelId = channelId;
|
|
536
|
+
this.installableAgents = installableAgents;
|
|
537
|
+
this.machineName = machineName;
|
|
538
|
+
this.online = online;
|
|
539
|
+
this.projectId = projectId;
|
|
540
|
+
this.runtimeId = runtimeId;
|
|
541
|
+
this.workspaceName = workspaceName;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
function decodeRuntimeDescriptor(value) {
|
|
545
|
+
const runtime = record(value, "Runtime descriptor");
|
|
546
|
+
return new MobiusRuntimeDescriptor(arrayField(runtime, "agents", 100).map(decodeAgentDescriptor), identifierField(runtime, "channelId"), arrayField(runtime, "installableAgents", 100).map(decodeInstallableAgentDescriptor), stringField(runtime, "machineName", 255), booleanField(runtime, "online"), identifierField(runtime, "projectId"), identifierField(runtime, "runtimeId"), stringField(runtime, "workspaceName", 255));
|
|
547
|
+
}
|
|
548
|
+
export function decodeMobiusRuntimeList(value) {
|
|
549
|
+
const response = record(value, "Runtime list");
|
|
550
|
+
return arrayField(response, "runtimes", 100).map(decodeRuntimeDescriptor);
|
|
551
|
+
}
|
|
552
|
+
export class MobiusRuntimePairing {
|
|
553
|
+
channelId;
|
|
554
|
+
expiresAt;
|
|
555
|
+
pairingCode;
|
|
556
|
+
pairingId;
|
|
557
|
+
pollToken;
|
|
558
|
+
projectId;
|
|
559
|
+
runtimeId;
|
|
560
|
+
constructor(channelId, expiresAt, pairingCode, pairingId, pollToken, projectId, runtimeId) {
|
|
561
|
+
this.channelId = channelId;
|
|
562
|
+
this.expiresAt = expiresAt;
|
|
563
|
+
this.pairingCode = pairingCode;
|
|
564
|
+
this.pairingId = pairingId;
|
|
565
|
+
this.pollToken = pollToken;
|
|
566
|
+
this.projectId = projectId;
|
|
567
|
+
this.runtimeId = runtimeId;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
export class MobiusRuntimePairingWaitOptions {
|
|
571
|
+
pollIntervalMilliseconds;
|
|
572
|
+
timeoutMilliseconds;
|
|
573
|
+
constructor(timeoutMilliseconds = 120_000, pollIntervalMilliseconds = 1_000) {
|
|
574
|
+
if (!Number.isSafeInteger(timeoutMilliseconds) ||
|
|
575
|
+
timeoutMilliseconds < 1 ||
|
|
576
|
+
timeoutMilliseconds > 30 * 60 * 1_000 ||
|
|
577
|
+
!Number.isSafeInteger(pollIntervalMilliseconds) ||
|
|
578
|
+
pollIntervalMilliseconds < 1 ||
|
|
579
|
+
pollIntervalMilliseconds > timeoutMilliseconds) {
|
|
580
|
+
throw new MobiusValidationError("The Runtime pairing wait bounds are invalid");
|
|
581
|
+
}
|
|
582
|
+
this.pollIntervalMilliseconds = pollIntervalMilliseconds;
|
|
583
|
+
this.timeoutMilliseconds = timeoutMilliseconds;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
export function decodeMobiusRuntimePairing(value) {
|
|
587
|
+
const pairing = record(value, "Runtime pairing");
|
|
588
|
+
const pairingCode = stringField(pairing, "pairingCode", 24);
|
|
589
|
+
const pollToken = stringField(pairing, "pollToken", 256);
|
|
590
|
+
if (!/^[A-HJ-NP-Z2-9]{4}(?:-[A-HJ-NP-Z2-9]{4}){4}$/.test(pairingCode) ||
|
|
591
|
+
!/^[a-zA-Z0-9_-]{32,256}$/.test(pollToken)) {
|
|
592
|
+
throw invalidResponse("The service returned invalid Runtime pairing credentials");
|
|
593
|
+
}
|
|
594
|
+
return new MobiusRuntimePairing(identifierField(pairing, "channelId"), validateTimestamp(stringField(pairing, "expiresAt", 128), "expiresAt"), pairingCode, identifierField(pairing, "pairingId"), pollToken, identifierField(pairing, "projectId"), identifierField(pairing, "runtimeId"));
|
|
595
|
+
}
|
|
596
|
+
export const MobiusRuntimePairingLifecycle = Object.freeze({
|
|
597
|
+
Expired: "expired",
|
|
598
|
+
Paired: "paired",
|
|
599
|
+
Pending: "pending",
|
|
600
|
+
Revoked: "revoked",
|
|
601
|
+
});
|
|
602
|
+
export class MobiusRuntimePairingStatus {
|
|
603
|
+
}
|
|
604
|
+
export class MobiusPendingRuntimePairingStatus extends MobiusRuntimePairingStatus {
|
|
605
|
+
expiresAt;
|
|
606
|
+
status = MobiusRuntimePairingLifecycle.Pending;
|
|
607
|
+
constructor(expiresAt) {
|
|
608
|
+
super();
|
|
609
|
+
this.expiresAt = expiresAt;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
export class MobiusExpiredRuntimePairingStatus extends MobiusRuntimePairingStatus {
|
|
613
|
+
status = MobiusRuntimePairingLifecycle.Expired;
|
|
614
|
+
}
|
|
615
|
+
export class MobiusPairedRuntimePairingStatus extends MobiusRuntimePairingStatus {
|
|
616
|
+
agents;
|
|
617
|
+
channelId;
|
|
618
|
+
installableAgents;
|
|
619
|
+
machineName;
|
|
620
|
+
projectId;
|
|
621
|
+
runtimeId;
|
|
622
|
+
status = MobiusRuntimePairingLifecycle.Paired;
|
|
623
|
+
workspaceName;
|
|
624
|
+
constructor(agents, channelId, installableAgents, machineName, projectId, runtimeId, workspaceName) {
|
|
625
|
+
super();
|
|
626
|
+
this.agents = agents;
|
|
627
|
+
this.channelId = channelId;
|
|
628
|
+
this.installableAgents = installableAgents;
|
|
629
|
+
this.machineName = machineName;
|
|
630
|
+
this.projectId = projectId;
|
|
631
|
+
this.runtimeId = runtimeId;
|
|
632
|
+
this.workspaceName = workspaceName;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
export class MobiusRevokedRuntimePairingStatus extends MobiusRuntimePairingStatus {
|
|
636
|
+
revokedAt;
|
|
637
|
+
status = MobiusRuntimePairingLifecycle.Revoked;
|
|
638
|
+
constructor(revokedAt) {
|
|
639
|
+
super();
|
|
640
|
+
this.revokedAt = revokedAt;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
export function decodeMobiusRuntimePairingStatus(value) {
|
|
644
|
+
const status = record(value, "Runtime pairing status");
|
|
645
|
+
const lifecycle = stringField(status, "status", 32);
|
|
646
|
+
if (lifecycle === MobiusRuntimePairingLifecycle.Pending) {
|
|
647
|
+
return new MobiusPendingRuntimePairingStatus(validateTimestamp(stringField(status, "expiresAt", 128), "expiresAt"));
|
|
648
|
+
}
|
|
649
|
+
if (lifecycle === MobiusRuntimePairingLifecycle.Expired) {
|
|
650
|
+
return new MobiusExpiredRuntimePairingStatus();
|
|
651
|
+
}
|
|
652
|
+
if (lifecycle === MobiusRuntimePairingLifecycle.Revoked) {
|
|
653
|
+
return new MobiusRevokedRuntimePairingStatus(validateTimestamp(stringField(status, "revokedAt", 128), "revokedAt"));
|
|
654
|
+
}
|
|
655
|
+
if (lifecycle === MobiusRuntimePairingLifecycle.Paired) {
|
|
656
|
+
return new MobiusPairedRuntimePairingStatus(arrayField(status, "agents", 100).map(decodeAgentDescriptor), identifierField(status, "channelId"), arrayField(status, "installableAgents", 100).map(decodeInstallableAgentDescriptor), stringField(status, "machineName", 255), identifierField(status, "projectId"), identifierField(status, "runtimeId"), stringField(status, "workspaceName", 255));
|
|
657
|
+
}
|
|
658
|
+
throw invalidResponse("The service returned an unsupported Runtime pairing status");
|
|
659
|
+
}
|
|
660
|
+
export class MobiusInteractionResponseRequest {
|
|
661
|
+
responderId;
|
|
662
|
+
constructor(responderId) {
|
|
663
|
+
this.responderId = responderId;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
export class MobiusPermissionResponseRequest extends MobiusInteractionResponseRequest {
|
|
667
|
+
kind = "permission";
|
|
668
|
+
optionId;
|
|
669
|
+
outcome;
|
|
670
|
+
constructor(responderId, outcome, optionId) {
|
|
671
|
+
super(responderId);
|
|
672
|
+
this.optionId = optionId;
|
|
673
|
+
this.outcome = outcome;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
export class MobiusElicitationResponseRequest extends MobiusInteractionResponseRequest {
|
|
677
|
+
action;
|
|
678
|
+
content;
|
|
679
|
+
kind = "elicitation";
|
|
680
|
+
constructor(responderId, action, content) {
|
|
681
|
+
super(responderId);
|
|
682
|
+
this.action = action;
|
|
683
|
+
this.content = content;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
export function decodeMobiusInteraction(value) {
|
|
687
|
+
try {
|
|
688
|
+
return decodeInteraction(value);
|
|
689
|
+
}
|
|
690
|
+
catch (cause) {
|
|
691
|
+
throw new MobiusProtocolError("The service returned an invalid Interaction", { cause });
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
export function decodeMobiusInteractionList(value) {
|
|
695
|
+
const response = record(value, "Interaction list");
|
|
696
|
+
return arrayField(response, "interactions", 100).map(decodeMobiusInteraction);
|
|
697
|
+
}
|
|
698
|
+
export class MobiusPageRequest {
|
|
699
|
+
cursor;
|
|
700
|
+
limit;
|
|
701
|
+
constructor(limit, cursor) {
|
|
702
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100 || cursor.length > 512) {
|
|
703
|
+
throw new MobiusValidationError("The page request is invalid");
|
|
704
|
+
}
|
|
705
|
+
this.cursor = cursor;
|
|
706
|
+
this.limit = limit;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
export class MobiusSessionBinding {
|
|
710
|
+
agentRef;
|
|
711
|
+
bindingId;
|
|
712
|
+
configRevision;
|
|
713
|
+
createdAt;
|
|
714
|
+
runtimeId;
|
|
715
|
+
sessionId;
|
|
716
|
+
workspaceRef;
|
|
717
|
+
constructor(agentRef, bindingId, configRevision, createdAt, runtimeId, sessionId, workspaceRef) {
|
|
718
|
+
this.agentRef = agentRef;
|
|
719
|
+
this.bindingId = bindingId;
|
|
720
|
+
this.configRevision = configRevision;
|
|
721
|
+
this.createdAt = createdAt;
|
|
722
|
+
this.runtimeId = runtimeId;
|
|
723
|
+
this.sessionId = sessionId;
|
|
724
|
+
this.workspaceRef = workspaceRef;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
export class MobiusSessionState {
|
|
728
|
+
}
|
|
729
|
+
export class MobiusReadySessionState extends MobiusSessionState {
|
|
730
|
+
kind = "ready";
|
|
731
|
+
}
|
|
732
|
+
export class MobiusDeletingSessionState extends MobiusSessionState {
|
|
733
|
+
kind = "deleting";
|
|
734
|
+
requestedAt;
|
|
735
|
+
constructor(requestedAt) {
|
|
736
|
+
super();
|
|
737
|
+
this.requestedAt = requestedAt;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
export class MobiusDeletedSessionState extends MobiusSessionState {
|
|
741
|
+
completedAt;
|
|
742
|
+
kind = "deleted";
|
|
743
|
+
constructor(completedAt) {
|
|
744
|
+
super();
|
|
745
|
+
this.completedAt = completedAt;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
export class MobiusSession {
|
|
749
|
+
agentId;
|
|
750
|
+
createdAt;
|
|
751
|
+
createdBy;
|
|
752
|
+
defaultBinding;
|
|
753
|
+
hasNativeHistory;
|
|
754
|
+
lastCommittedSequence;
|
|
755
|
+
policy;
|
|
756
|
+
projectId;
|
|
757
|
+
runtimeId;
|
|
758
|
+
sessionId;
|
|
759
|
+
state;
|
|
760
|
+
title;
|
|
761
|
+
updatedAt;
|
|
762
|
+
constructor(agentId, createdAt, createdBy, defaultBinding, hasNativeHistory, lastCommittedSequence, policy, projectId, runtimeId, sessionId, state, title, updatedAt) {
|
|
763
|
+
this.agentId = agentId;
|
|
764
|
+
this.createdAt = createdAt;
|
|
765
|
+
this.createdBy = createdBy;
|
|
766
|
+
this.defaultBinding = defaultBinding;
|
|
767
|
+
this.hasNativeHistory = hasNativeHistory;
|
|
768
|
+
this.lastCommittedSequence = lastCommittedSequence;
|
|
769
|
+
this.policy = policy;
|
|
770
|
+
this.projectId = projectId;
|
|
771
|
+
this.runtimeId = runtimeId;
|
|
772
|
+
this.sessionId = sessionId;
|
|
773
|
+
this.state = state;
|
|
774
|
+
this.title = title;
|
|
775
|
+
this.updatedAt = updatedAt;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
export function decodeMobiusSessionState(value) {
|
|
779
|
+
const state = record(value, "Session lifecycle");
|
|
780
|
+
const kind = stringField(state, "kind", 32);
|
|
781
|
+
if (kind === "ready") {
|
|
782
|
+
return new MobiusReadySessionState();
|
|
783
|
+
}
|
|
784
|
+
if (kind === "deleting") {
|
|
785
|
+
return new MobiusDeletingSessionState(validateTimestamp(stringField(state, "requestedAt", 128), "requestedAt"));
|
|
786
|
+
}
|
|
787
|
+
if (kind === "deleted") {
|
|
788
|
+
return new MobiusDeletedSessionState(validateTimestamp(stringField(state, "completedAt", 128), "completedAt"));
|
|
789
|
+
}
|
|
790
|
+
throw invalidResponse("The service returned an unsupported Session lifecycle");
|
|
791
|
+
}
|
|
792
|
+
function decodeBinding(value) {
|
|
793
|
+
const binding = record(value, "Session binding");
|
|
794
|
+
return new MobiusSessionBinding(identifierField(binding, "agentRef"), identifierField(binding, "bindingId"), integerField(binding, "configRevision"), validateTimestamp(stringField(binding, "createdAt", 128), "createdAt"), identifierField(binding, "runtimeId"), identifierField(binding, "sessionId"), identifierField(binding, "workspaceRef"));
|
|
795
|
+
}
|
|
796
|
+
function decodeRecordingPolicy(value) {
|
|
797
|
+
const policy = record(value, "Session recording policy");
|
|
798
|
+
return new MobiusRecordingPolicy(stringField(policy, "level", 32), integerField(policy, "retentionMilliseconds"), integerField(policy, "hotEventLimit"), integerField(policy, "contentLimitBytes"), integerField(policy, "idempotencyRetentionMilliseconds"));
|
|
799
|
+
}
|
|
800
|
+
export function decodeMobiusSession(value) {
|
|
801
|
+
const session = record(value, "Session");
|
|
802
|
+
const sequence = stringField(session, "lastCommittedSeq", 40);
|
|
803
|
+
if (!/^(?:0|[1-9][0-9]*)$/.test(sequence)) {
|
|
804
|
+
throw invalidResponse("The service returned an invalid event sequence");
|
|
805
|
+
}
|
|
806
|
+
return new MobiusSession(identifierField(session, "agentId"), validateTimestamp(stringField(session, "createdAt", 128), "createdAt"), identifierField(session, "createdBy"), decodeBinding(session["defaultBinding"]), booleanField(session, "hasNativeHistory"), sequence, decodeRecordingPolicy(session["policy"]), identifierField(session, "projectId"), identifierField(session, "runtimeId"), identifierField(session, "sessionId"), decodeMobiusSessionState(session["lifecycle"]), stringField(session, "title", 500), validateTimestamp(stringField(session, "updatedAt", 128), "updatedAt"));
|
|
807
|
+
}
|
|
808
|
+
export class MobiusSessionPage {
|
|
809
|
+
nextCursor;
|
|
810
|
+
sessions;
|
|
811
|
+
constructor(sessions, nextCursor) {
|
|
812
|
+
this.nextCursor = nextCursor;
|
|
813
|
+
this.sessions = sessions;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
export function decodeMobiusSessionPage(value) {
|
|
817
|
+
const page = record(value, "Session page");
|
|
818
|
+
return new MobiusSessionPage(arrayField(page, "sessions", 100).map(decodeMobiusSession), nullableCursor(page, "nextCursor"));
|
|
819
|
+
}
|
|
820
|
+
export class MobiusTurnState {
|
|
821
|
+
}
|
|
822
|
+
export class MobiusQueuedTurnState extends MobiusTurnState {
|
|
823
|
+
kind = "queued";
|
|
824
|
+
}
|
|
825
|
+
export class MobiusRunningTurnState extends MobiusTurnState {
|
|
826
|
+
kind = "running";
|
|
827
|
+
startedAt;
|
|
828
|
+
constructor(startedAt) {
|
|
829
|
+
super();
|
|
830
|
+
this.startedAt = startedAt;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
export class MobiusSucceededTurnState extends MobiusTurnState {
|
|
834
|
+
completedAt;
|
|
835
|
+
kind = "succeeded";
|
|
836
|
+
stopReason;
|
|
837
|
+
constructor(completedAt, stopReason) {
|
|
838
|
+
super();
|
|
839
|
+
this.completedAt = completedAt;
|
|
840
|
+
this.stopReason = stopReason;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
export class MobiusFailedTurnState extends MobiusTurnState {
|
|
844
|
+
code;
|
|
845
|
+
failedAt;
|
|
846
|
+
kind = "failed";
|
|
847
|
+
message;
|
|
848
|
+
retryable;
|
|
849
|
+
constructor(failedAt, code, message, retryable) {
|
|
850
|
+
super();
|
|
851
|
+
this.code = code;
|
|
852
|
+
this.failedAt = failedAt;
|
|
853
|
+
this.message = message;
|
|
854
|
+
this.retryable = retryable;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
export class MobiusCancelledTurnState extends MobiusTurnState {
|
|
858
|
+
cancelledAt;
|
|
859
|
+
kind = "cancelled";
|
|
860
|
+
constructor(cancelledAt) {
|
|
861
|
+
super();
|
|
862
|
+
this.cancelledAt = cancelledAt;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
export class MobiusIndeterminateTurnState extends MobiusTurnState {
|
|
866
|
+
detectedAt;
|
|
867
|
+
kind = "indeterminate";
|
|
868
|
+
reason;
|
|
869
|
+
constructor(detectedAt, reason) {
|
|
870
|
+
super();
|
|
871
|
+
this.detectedAt = detectedAt;
|
|
872
|
+
this.reason = reason;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
export class MobiusTurn {
|
|
876
|
+
acceptedAt;
|
|
877
|
+
bindingId;
|
|
878
|
+
content;
|
|
879
|
+
idempotencyKey;
|
|
880
|
+
sessionId;
|
|
881
|
+
state;
|
|
882
|
+
turnId;
|
|
883
|
+
constructor(acceptedAt, bindingId, content, idempotencyKey, sessionId, state, turnId) {
|
|
884
|
+
this.acceptedAt = acceptedAt;
|
|
885
|
+
this.bindingId = bindingId;
|
|
886
|
+
this.content = content;
|
|
887
|
+
this.idempotencyKey = idempotencyKey;
|
|
888
|
+
this.sessionId = sessionId;
|
|
889
|
+
this.state = state;
|
|
890
|
+
this.turnId = turnId;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
export function decodeMobiusTurn(value) {
|
|
894
|
+
const turn = decodeTurn(value);
|
|
895
|
+
let state;
|
|
896
|
+
switch (turn.state.kind) {
|
|
897
|
+
case "queued":
|
|
898
|
+
state = new MobiusQueuedTurnState();
|
|
899
|
+
break;
|
|
900
|
+
case "running":
|
|
901
|
+
state = new MobiusRunningTurnState(turn.state.startedAt);
|
|
902
|
+
break;
|
|
903
|
+
case "succeeded":
|
|
904
|
+
state = new MobiusSucceededTurnState(turn.state.completedAt, turn.state.result.stopReason);
|
|
905
|
+
break;
|
|
906
|
+
case "failed":
|
|
907
|
+
state = new MobiusFailedTurnState(turn.state.failedAt, turn.state.error.code, turn.state.error.message, turn.state.error.retryable);
|
|
908
|
+
break;
|
|
909
|
+
case "cancelled":
|
|
910
|
+
state = new MobiusCancelledTurnState(turn.state.cancelledAt);
|
|
911
|
+
break;
|
|
912
|
+
case "indeterminate":
|
|
913
|
+
state = new MobiusIndeterminateTurnState(turn.state.reconciliation.detectedAt, turn.state.reconciliation.reason);
|
|
914
|
+
break;
|
|
915
|
+
}
|
|
916
|
+
return new MobiusTurn(turn.acceptedAt, turn.bindingId, turn.request.content, turn.idempotencyKey, turn.sessionId, state, turn.turnId);
|
|
917
|
+
}
|
|
918
|
+
export function decodeMobiusAttempt(value) {
|
|
919
|
+
try {
|
|
920
|
+
return decodeAttempt(value);
|
|
921
|
+
}
|
|
922
|
+
catch (cause) {
|
|
923
|
+
throw new MobiusProtocolError("The service returned an invalid Attempt", {
|
|
924
|
+
cause,
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
export class MobiusAttemptSummary {
|
|
929
|
+
}
|
|
930
|
+
export class MobiusNoAttemptSummary extends MobiusAttemptSummary {
|
|
931
|
+
kind = "none";
|
|
932
|
+
}
|
|
933
|
+
export class MobiusPresentAttemptSummary extends MobiusAttemptSummary {
|
|
934
|
+
attemptId;
|
|
935
|
+
constructor(attemptId) {
|
|
936
|
+
super();
|
|
937
|
+
this.attemptId = attemptId;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
export class MobiusDispatchingAttemptSummary extends MobiusPresentAttemptSummary {
|
|
941
|
+
dispatchedAt;
|
|
942
|
+
kind = "dispatching";
|
|
943
|
+
constructor(attemptId, dispatchedAt) {
|
|
944
|
+
super(attemptId);
|
|
945
|
+
this.dispatchedAt = dispatchedAt;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
export class MobiusRunningAttemptSummary extends MobiusPresentAttemptSummary {
|
|
949
|
+
kind = "running";
|
|
950
|
+
startedAt;
|
|
951
|
+
constructor(attemptId, startedAt) {
|
|
952
|
+
super(attemptId);
|
|
953
|
+
this.startedAt = startedAt;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
export class MobiusSucceededAttemptSummary extends MobiusPresentAttemptSummary {
|
|
957
|
+
completedAt;
|
|
958
|
+
kind = "succeeded";
|
|
959
|
+
startedAt;
|
|
960
|
+
stopReason;
|
|
961
|
+
constructor(attemptId, startedAt, completedAt, stopReason) {
|
|
962
|
+
super(attemptId);
|
|
963
|
+
this.completedAt = completedAt;
|
|
964
|
+
this.startedAt = startedAt;
|
|
965
|
+
this.stopReason = stopReason;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
export class MobiusCancelledAttemptSummary extends MobiusPresentAttemptSummary {
|
|
969
|
+
cancelledAt;
|
|
970
|
+
kind = "cancelled";
|
|
971
|
+
startedAt;
|
|
972
|
+
constructor(attemptId, startedAt, cancelledAt) {
|
|
973
|
+
super(attemptId);
|
|
974
|
+
this.cancelledAt = cancelledAt;
|
|
975
|
+
this.startedAt = startedAt;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
export class MobiusWaitingInputAttemptSummary extends MobiusPresentAttemptSummary {
|
|
979
|
+
interactionIds;
|
|
980
|
+
kind = "waiting_input";
|
|
981
|
+
startedAt;
|
|
982
|
+
constructor(attemptId, startedAt, interactionIds) {
|
|
983
|
+
super(attemptId);
|
|
984
|
+
this.interactionIds = interactionIds;
|
|
985
|
+
this.startedAt = startedAt;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
export class MobiusFailedBeforeStartAttemptSummary extends MobiusAttemptSummary {
|
|
989
|
+
code;
|
|
990
|
+
failedAt;
|
|
991
|
+
kind = "failed";
|
|
992
|
+
message;
|
|
993
|
+
constructor(code, message, failedAt) {
|
|
994
|
+
super();
|
|
995
|
+
this.code = code;
|
|
996
|
+
this.failedAt = failedAt;
|
|
997
|
+
this.message = message;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
export class MobiusFailedAttemptSummary extends MobiusPresentAttemptSummary {
|
|
1001
|
+
code;
|
|
1002
|
+
failedAt;
|
|
1003
|
+
kind = "failed";
|
|
1004
|
+
message;
|
|
1005
|
+
startedAt;
|
|
1006
|
+
constructor(attemptId, startedAt, code, message, failedAt) {
|
|
1007
|
+
super(attemptId);
|
|
1008
|
+
this.code = code;
|
|
1009
|
+
this.failedAt = failedAt;
|
|
1010
|
+
this.message = message;
|
|
1011
|
+
this.startedAt = startedAt;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
export class MobiusIndeterminateAttemptSummary extends MobiusPresentAttemptSummary {
|
|
1015
|
+
detectedAt;
|
|
1016
|
+
kind = "indeterminate";
|
|
1017
|
+
startedAt;
|
|
1018
|
+
constructor(attemptId, startedAt, detectedAt) {
|
|
1019
|
+
super(attemptId);
|
|
1020
|
+
this.detectedAt = detectedAt;
|
|
1021
|
+
this.startedAt = startedAt;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
export function decodeMobiusAttemptSummary(value) {
|
|
1025
|
+
if (value === null) {
|
|
1026
|
+
return new MobiusNoAttemptSummary();
|
|
1027
|
+
}
|
|
1028
|
+
const attempt = record(value, "Attempt summary");
|
|
1029
|
+
const kind = stringField(attempt, "kind", 32);
|
|
1030
|
+
if (kind === "failed") {
|
|
1031
|
+
const attemptId = attempt["attemptId"];
|
|
1032
|
+
const startedAt = attempt["startedAt"];
|
|
1033
|
+
const code = identifierField(attempt, "code");
|
|
1034
|
+
const message = stringField(attempt, "message", 2_000);
|
|
1035
|
+
const failedAt = validateTimestamp(stringField(attempt, "failedAt", 128), "failedAt");
|
|
1036
|
+
if (attemptId === null && startedAt === null) {
|
|
1037
|
+
return new MobiusFailedBeforeStartAttemptSummary(code, message, failedAt);
|
|
1038
|
+
}
|
|
1039
|
+
if (typeof attemptId !== "string" || typeof startedAt !== "string") {
|
|
1040
|
+
throw invalidResponse("The service returned an invalid failed Attempt");
|
|
1041
|
+
}
|
|
1042
|
+
return new MobiusFailedAttemptSummary(attemptId, validateTimestamp(startedAt, "startedAt"), code, message, failedAt);
|
|
1043
|
+
}
|
|
1044
|
+
const attemptId = identifierField(attempt, "attemptId");
|
|
1045
|
+
if (kind === "dispatching") {
|
|
1046
|
+
return new MobiusDispatchingAttemptSummary(attemptId, validateTimestamp(stringField(attempt, "dispatchedAt", 128), "dispatchedAt"));
|
|
1047
|
+
}
|
|
1048
|
+
const startedAt = validateTimestamp(stringField(attempt, "startedAt", 128), "startedAt");
|
|
1049
|
+
if (kind === "running") {
|
|
1050
|
+
return new MobiusRunningAttemptSummary(attemptId, startedAt);
|
|
1051
|
+
}
|
|
1052
|
+
if (kind === "succeeded") {
|
|
1053
|
+
return new MobiusSucceededAttemptSummary(attemptId, startedAt, validateTimestamp(stringField(attempt, "completedAt", 128), "completedAt"), stringField(attempt, "stopReason", 128));
|
|
1054
|
+
}
|
|
1055
|
+
if (kind === "cancelled") {
|
|
1056
|
+
return new MobiusCancelledAttemptSummary(attemptId, startedAt, validateTimestamp(stringField(attempt, "cancelledAt", 128), "cancelledAt"));
|
|
1057
|
+
}
|
|
1058
|
+
if (kind === "waiting_input") {
|
|
1059
|
+
return new MobiusWaitingInputAttemptSummary(attemptId, startedAt, arrayField(attempt, "interactionIds", 100).map((interactionId) => {
|
|
1060
|
+
if (typeof interactionId !== "string") {
|
|
1061
|
+
throw invalidResponse("The service returned an invalid interaction identifier");
|
|
1062
|
+
}
|
|
1063
|
+
return identifierField({ interactionId }, "interactionId");
|
|
1064
|
+
}));
|
|
1065
|
+
}
|
|
1066
|
+
if (kind === "indeterminate") {
|
|
1067
|
+
return new MobiusIndeterminateAttemptSummary(attemptId, startedAt, validateTimestamp(stringField(attempt, "detectedAt", 128), "detectedAt"));
|
|
1068
|
+
}
|
|
1069
|
+
throw invalidResponse("The service returned an unsupported Attempt state");
|
|
1070
|
+
}
|
|
1071
|
+
export class MobiusActivitySummary {
|
|
1072
|
+
activityId;
|
|
1073
|
+
attemptId;
|
|
1074
|
+
activityType;
|
|
1075
|
+
detailAvailability;
|
|
1076
|
+
input;
|
|
1077
|
+
locations;
|
|
1078
|
+
name;
|
|
1079
|
+
output;
|
|
1080
|
+
sequence;
|
|
1081
|
+
status;
|
|
1082
|
+
title;
|
|
1083
|
+
toolCallId;
|
|
1084
|
+
toolKind;
|
|
1085
|
+
constructor(activityId, attemptId, activityType, detailAvailability, input, locations, name, output, sequence, status, title, toolCallId, toolKind) {
|
|
1086
|
+
this.activityId = activityId;
|
|
1087
|
+
this.attemptId = attemptId;
|
|
1088
|
+
this.activityType = activityType;
|
|
1089
|
+
this.detailAvailability = detailAvailability;
|
|
1090
|
+
this.input = input;
|
|
1091
|
+
this.locations = locations;
|
|
1092
|
+
this.name = name;
|
|
1093
|
+
this.output = output;
|
|
1094
|
+
this.sequence = sequence;
|
|
1095
|
+
this.status = status;
|
|
1096
|
+
this.title = title;
|
|
1097
|
+
this.toolCallId = toolCallId;
|
|
1098
|
+
this.toolKind = toolKind;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
export function decodeMobiusActivitySummary(value) {
|
|
1102
|
+
const activity = record(value, "Activity summary");
|
|
1103
|
+
return new MobiusActivitySummary(identifierField(activity, "activityId"), identifierField(activity, "attemptId"), stringField(activity, "activityType", 128), stringField(activity, "detailAvailability", 32), stringField(activity, "input", 100_000), arrayField(activity, "locations", 100).map((location) => {
|
|
1104
|
+
if (typeof location !== "string" || location.length > 2_048) {
|
|
1105
|
+
throw invalidResponse("The service returned an invalid Activity location");
|
|
1106
|
+
}
|
|
1107
|
+
return location;
|
|
1108
|
+
}), stringField(activity, "name", 128), stringField(activity, "output", 100_000), integerField(activity, "sequence"), stringField(activity, "status", 64), stringField(activity, "title", 500), identifierField(activity, "toolCallId"), stringField(activity, "toolKind", 128));
|
|
1109
|
+
}
|
|
1110
|
+
export class MobiusMessage {
|
|
1111
|
+
activities;
|
|
1112
|
+
additionalDirectoryIds;
|
|
1113
|
+
agentId;
|
|
1114
|
+
attempt;
|
|
1115
|
+
commandId;
|
|
1116
|
+
createdAt;
|
|
1117
|
+
disposition;
|
|
1118
|
+
images;
|
|
1119
|
+
messageId;
|
|
1120
|
+
prompt;
|
|
1121
|
+
resources;
|
|
1122
|
+
response;
|
|
1123
|
+
sessionId;
|
|
1124
|
+
targetCommandId;
|
|
1125
|
+
constructor(activities, additionalDirectoryIds, agentId, attempt, commandId, createdAt, disposition, images, messageId, prompt, resources, response, sessionId, targetCommandId) {
|
|
1126
|
+
this.activities = activities;
|
|
1127
|
+
this.additionalDirectoryIds = additionalDirectoryIds;
|
|
1128
|
+
this.agentId = agentId;
|
|
1129
|
+
this.attempt = attempt;
|
|
1130
|
+
this.commandId = commandId;
|
|
1131
|
+
this.createdAt = createdAt;
|
|
1132
|
+
this.disposition = disposition;
|
|
1133
|
+
this.images = images;
|
|
1134
|
+
this.messageId = messageId;
|
|
1135
|
+
this.prompt = prompt;
|
|
1136
|
+
this.resources = resources;
|
|
1137
|
+
this.response = response;
|
|
1138
|
+
this.sessionId = sessionId;
|
|
1139
|
+
this.targetCommandId = targetCommandId;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
function decodeMobiusMessage(value) {
|
|
1143
|
+
const message = record(value, "Session message");
|
|
1144
|
+
return new MobiusMessage(arrayField(message, "activities", 10_000).map(decodeMobiusActivitySummary), arrayField(message, "additionalDirectoryIds", 100).map((directoryId) => {
|
|
1145
|
+
if (typeof directoryId !== "string") {
|
|
1146
|
+
throw invalidResponse("The service returned an invalid additional directory identifier");
|
|
1147
|
+
}
|
|
1148
|
+
return identifierField({ directoryId }, "directoryId");
|
|
1149
|
+
}), identifierField(message, "agentId"), decodeMobiusAttemptSummary(message["attempt"]), identifierField(message, "commandId"), validateTimestamp(stringField(message, "createdAt", 128), "createdAt"), stringField(message, "disposition", 16), decodePromptImagesValue(message["images"]), stringField(message, "messageId", 255), stringField(message, "prompt", 100_000), decodePromptResourcesValue(message["resources"]), stringField(message, "response", 8_500_000), identifierField(message, "sessionId"), stringField(message, "targetCommandId", 128));
|
|
1150
|
+
}
|
|
1151
|
+
export class MobiusMessagePage {
|
|
1152
|
+
lastCommittedSequence;
|
|
1153
|
+
messages;
|
|
1154
|
+
nextCursor;
|
|
1155
|
+
constructor(lastCommittedSequence, messages, nextCursor) {
|
|
1156
|
+
this.lastCommittedSequence = lastCommittedSequence;
|
|
1157
|
+
this.messages = messages;
|
|
1158
|
+
this.nextCursor = nextCursor;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
export function decodeMobiusMessagePage(value) {
|
|
1162
|
+
const page = record(value, "Session message page");
|
|
1163
|
+
const sequence = stringField(page, "lastCommittedSeq", 40);
|
|
1164
|
+
if (!/^(?:0|[1-9][0-9]*)$/.test(sequence)) {
|
|
1165
|
+
throw invalidResponse("The service returned an invalid event sequence");
|
|
1166
|
+
}
|
|
1167
|
+
return new MobiusMessagePage(sequence, arrayField(page, "messages", 100).map(decodeMobiusMessage), nullableCursor(page, "nextCursor"));
|
|
1168
|
+
}
|
|
1169
|
+
export class MobiusToolCallDetail {
|
|
1170
|
+
}
|
|
1171
|
+
export class MobiusAvailableToolCallDetail extends MobiusToolCallDetail {
|
|
1172
|
+
artifactId;
|
|
1173
|
+
content;
|
|
1174
|
+
input;
|
|
1175
|
+
kind = "available";
|
|
1176
|
+
output;
|
|
1177
|
+
storage;
|
|
1178
|
+
constructor(artifactId, content, input, output, storage) {
|
|
1179
|
+
super();
|
|
1180
|
+
this.artifactId = artifactId;
|
|
1181
|
+
this.content = content;
|
|
1182
|
+
this.input = input;
|
|
1183
|
+
this.output = output;
|
|
1184
|
+
this.storage = storage;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
export class MobiusTruncatedToolCallDetail extends MobiusToolCallDetail {
|
|
1188
|
+
capturedBytes;
|
|
1189
|
+
kind = "truncated";
|
|
1190
|
+
originalBytes;
|
|
1191
|
+
constructor(capturedBytes, originalBytes) {
|
|
1192
|
+
super();
|
|
1193
|
+
this.capturedBytes = capturedBytes;
|
|
1194
|
+
this.originalBytes = originalBytes;
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
export class MobiusUnrecordedToolCallDetail extends MobiusToolCallDetail {
|
|
1198
|
+
kind = "unrecorded";
|
|
1199
|
+
}
|
|
1200
|
+
export class MobiusDeletedToolCallDetail extends MobiusToolCallDetail {
|
|
1201
|
+
deletedAt;
|
|
1202
|
+
kind = "deleted";
|
|
1203
|
+
constructor(deletedAt) {
|
|
1204
|
+
super();
|
|
1205
|
+
this.deletedAt = deletedAt;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
export function decodeMobiusToolCallDetail(value) {
|
|
1209
|
+
const detail = record(value, "ToolCall detail");
|
|
1210
|
+
const kind = stringField(detail, "kind", 32);
|
|
1211
|
+
if (kind === "available") {
|
|
1212
|
+
const storage = stringField(detail, "storage", 32);
|
|
1213
|
+
if (storage !== "archive" && storage !== "hot") {
|
|
1214
|
+
throw invalidResponse("The service returned an invalid ToolCall storage state");
|
|
1215
|
+
}
|
|
1216
|
+
return new MobiusAvailableToolCallDetail(identifierField(detail, "artifactId"), arrayField(detail, "content", 100_000), stringField(detail, "input"), stringField(detail, "output"), storage);
|
|
1217
|
+
}
|
|
1218
|
+
if (kind === "truncated") {
|
|
1219
|
+
return new MobiusTruncatedToolCallDetail(integerField(detail, "capturedBytes"), integerField(detail, "originalBytes"));
|
|
1220
|
+
}
|
|
1221
|
+
if (kind === "unrecorded") {
|
|
1222
|
+
return new MobiusUnrecordedToolCallDetail();
|
|
1223
|
+
}
|
|
1224
|
+
if (kind === "deleted") {
|
|
1225
|
+
return new MobiusDeletedToolCallDetail(validateTimestamp(stringField(detail, "deletedAt", 128), "deletedAt"));
|
|
1226
|
+
}
|
|
1227
|
+
throw invalidResponse("The service returned an invalid ToolCall detail");
|
|
1228
|
+
}
|
|
1229
|
+
export class MobiusEventPage {
|
|
1230
|
+
cursor;
|
|
1231
|
+
events;
|
|
1232
|
+
hasMore;
|
|
1233
|
+
constructor(cursor, events, hasMore) {
|
|
1234
|
+
this.cursor = cursor;
|
|
1235
|
+
this.events = events;
|
|
1236
|
+
this.hasMore = hasMore;
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
export function decodeMobiusEventPage(value) {
|
|
1240
|
+
const page = record(value, "Session event page");
|
|
1241
|
+
return new MobiusEventPage(stringField(page, "cursor", 512), arrayField(page, "events", 100).map(decodeMobiusSessionEvent), booleanField(page, "hasMore"));
|
|
1242
|
+
}
|
|
1243
|
+
export class MobiusSessionExport {
|
|
1244
|
+
formatVersion;
|
|
1245
|
+
session;
|
|
1246
|
+
constructor(formatVersion, session) {
|
|
1247
|
+
this.formatVersion = formatVersion;
|
|
1248
|
+
this.session = session;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
export function decodeMobiusSessionExport(value) {
|
|
1252
|
+
const exported = record(value, "Session export");
|
|
1253
|
+
const formatVersion = stringField(exported, "formatVersion", 32);
|
|
1254
|
+
if (formatVersion !== MOBIUS_SESSION_EXPORT_FORMAT_VERSION) {
|
|
1255
|
+
throw invalidResponse("The service returned an unsupported Session export");
|
|
1256
|
+
}
|
|
1257
|
+
return new MobiusSessionExport(formatVersion, record(exported["session"], "Session export payload"));
|
|
1258
|
+
}
|
|
1259
|
+
export class MobiusEventSource {
|
|
1260
|
+
sourceSequence;
|
|
1261
|
+
constructor(sourceSequence) {
|
|
1262
|
+
this.sourceSequence = sourceSequence;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
export class MobiusRuntimeEventSource extends MobiusEventSource {
|
|
1266
|
+
kind = "runtime";
|
|
1267
|
+
}
|
|
1268
|
+
export class MobiusAttemptEventSource extends MobiusEventSource {
|
|
1269
|
+
attemptId;
|
|
1270
|
+
kind = "attempt";
|
|
1271
|
+
constructor(attemptId, sourceSequence) {
|
|
1272
|
+
super(sourceSequence);
|
|
1273
|
+
this.attemptId = attemptId;
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
export class MobiusRecordedEvent {
|
|
1277
|
+
sessionId;
|
|
1278
|
+
constructor(sessionId) {
|
|
1279
|
+
this.sessionId = sessionId;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
export class MobiusTurnStartedEvent extends MobiusRecordedEvent {
|
|
1283
|
+
attemptId;
|
|
1284
|
+
commandId;
|
|
1285
|
+
kind = SESSION_STARTED_KIND;
|
|
1286
|
+
constructor(sessionId, commandId, attemptId) {
|
|
1287
|
+
super(sessionId);
|
|
1288
|
+
this.attemptId = attemptId;
|
|
1289
|
+
this.commandId = commandId;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
export class MobiusAgentMessageEvent extends MobiusRecordedEvent {
|
|
1293
|
+
commandId;
|
|
1294
|
+
kind = AGENT_MESSAGE_DELTA_KIND;
|
|
1295
|
+
text;
|
|
1296
|
+
constructor(sessionId, commandId, text) {
|
|
1297
|
+
super(sessionId);
|
|
1298
|
+
this.commandId = commandId;
|
|
1299
|
+
this.text = text;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
export class MobiusAgentActivityEvent extends MobiusRecordedEvent {
|
|
1303
|
+
activityId;
|
|
1304
|
+
activityType;
|
|
1305
|
+
commandId;
|
|
1306
|
+
content;
|
|
1307
|
+
detail;
|
|
1308
|
+
input;
|
|
1309
|
+
kind = AGENT_ACTIVITY_KIND;
|
|
1310
|
+
locations;
|
|
1311
|
+
name;
|
|
1312
|
+
output;
|
|
1313
|
+
sequence;
|
|
1314
|
+
status;
|
|
1315
|
+
title;
|
|
1316
|
+
toolKind;
|
|
1317
|
+
constructor(event) {
|
|
1318
|
+
super(event.sessionId);
|
|
1319
|
+
this.activityId = event.activityId;
|
|
1320
|
+
this.activityType = event.activityType;
|
|
1321
|
+
this.commandId = event.commandId;
|
|
1322
|
+
this.content = event.content;
|
|
1323
|
+
this.detail = event.detail;
|
|
1324
|
+
this.input = event.input;
|
|
1325
|
+
this.locations = event.locations;
|
|
1326
|
+
this.name = event.name;
|
|
1327
|
+
this.output = event.output;
|
|
1328
|
+
this.sequence = event.sequence;
|
|
1329
|
+
this.status = event.status;
|
|
1330
|
+
this.title = event.title;
|
|
1331
|
+
this.toolKind = event.toolKind;
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
export class MobiusTurnCompletedEvent extends MobiusRecordedEvent {
|
|
1335
|
+
commandId;
|
|
1336
|
+
kind = SESSION_COMPLETED_KIND;
|
|
1337
|
+
stopReason;
|
|
1338
|
+
constructor(sessionId, commandId, stopReason) {
|
|
1339
|
+
super(sessionId);
|
|
1340
|
+
this.commandId = commandId;
|
|
1341
|
+
this.stopReason = stopReason;
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
export class MobiusTurnFailedEvent extends MobiusRecordedEvent {
|
|
1345
|
+
code;
|
|
1346
|
+
commandId;
|
|
1347
|
+
kind = SESSION_FAILED_KIND;
|
|
1348
|
+
message;
|
|
1349
|
+
constructor(sessionId, commandId, code, message) {
|
|
1350
|
+
super(sessionId);
|
|
1351
|
+
this.code = code;
|
|
1352
|
+
this.commandId = commandId;
|
|
1353
|
+
this.message = message;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
export class MobiusControlEvent extends MobiusRecordedEvent {
|
|
1357
|
+
encodedPayload;
|
|
1358
|
+
kind;
|
|
1359
|
+
constructor(sessionId, kind, encodedPayload) {
|
|
1360
|
+
super(sessionId);
|
|
1361
|
+
this.encodedPayload = encodedPayload;
|
|
1362
|
+
this.kind = kind;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
function decodeRecordedEvent(encoded) {
|
|
1366
|
+
const event = decodeRecordedSessionEvent(encoded);
|
|
1367
|
+
switch (event.kind) {
|
|
1368
|
+
case SESSION_STARTED_KIND:
|
|
1369
|
+
return new MobiusTurnStartedEvent(event.sessionId, event.commandId, event.attemptId);
|
|
1370
|
+
case AGENT_MESSAGE_DELTA_KIND:
|
|
1371
|
+
return new MobiusAgentMessageEvent(event.sessionId, event.commandId, event.text);
|
|
1372
|
+
case AGENT_ACTIVITY_KIND:
|
|
1373
|
+
return new MobiusAgentActivityEvent(event);
|
|
1374
|
+
case SESSION_COMPLETED_KIND:
|
|
1375
|
+
return new MobiusTurnCompletedEvent(event.sessionId, event.commandId, event.stopReason);
|
|
1376
|
+
case SESSION_FAILED_KIND:
|
|
1377
|
+
return new MobiusTurnFailedEvent(event.sessionId, event.commandId, event.code, event.message);
|
|
1378
|
+
default:
|
|
1379
|
+
return new MobiusControlEvent(event.sessionId, event.kind, encoded);
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
export class MobiusSessionEvent {
|
|
1383
|
+
cursor;
|
|
1384
|
+
eventId;
|
|
1385
|
+
payload;
|
|
1386
|
+
recordedAt;
|
|
1387
|
+
sequence;
|
|
1388
|
+
sessionId;
|
|
1389
|
+
source;
|
|
1390
|
+
constructor(cursor, eventId, payload, recordedAt, sequence, sessionId, source) {
|
|
1391
|
+
this.cursor = cursor;
|
|
1392
|
+
this.eventId = eventId;
|
|
1393
|
+
this.payload = payload;
|
|
1394
|
+
this.recordedAt = recordedAt;
|
|
1395
|
+
this.sequence = sequence;
|
|
1396
|
+
this.sessionId = sessionId;
|
|
1397
|
+
this.source = source;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
export function decodeMobiusSessionEvent(value) {
|
|
1401
|
+
const encoded = JSON.stringify(value);
|
|
1402
|
+
if (typeof encoded !== "string") {
|
|
1403
|
+
throw invalidResponse("The service returned an invalid Session event");
|
|
1404
|
+
}
|
|
1405
|
+
const event = decodeCommittedSessionEvent(encoded);
|
|
1406
|
+
const source = event.source.kind === "attempt"
|
|
1407
|
+
? new MobiusAttemptEventSource(event.source.attemptId, event.source.sourceSeq)
|
|
1408
|
+
: new MobiusRuntimeEventSource(event.source.sourceSeq);
|
|
1409
|
+
return new MobiusSessionEvent(event.cursor, event.eventId, decodeRecordedEvent(event.payload), event.recordedAt, event.sequence, event.sessionId, source);
|
|
1410
|
+
}
|
|
1411
|
+
//# sourceMappingURL=resources.js.map
|