@moxt-ai/mobius-sdk 0.0.28 → 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/resources.js CHANGED
@@ -1,5 +1,10 @@
1
- import { sessionCapabilitiesSchema } from "@moxt-ai/mobius-protocol";
1
+ import { AGENT_ACTIVITY_DETAIL_LIMIT, AGENT_ACTIVITY_KIND, AGENT_ACTIVITY_NARRATION_KIND, AGENT_MESSAGE_DELTA_KIND, decodeAgentDisplayContentValue, decodeAttempt, decodeCommittedSessionEvent, decodeInteraction, decodePromptImagesValue, decodePromptResourcesValue, decodeRecordedSessionEvent, decodeTurn, MOBIUS_API_VERSION, SESSION_COMPLETED_KIND, SESSION_FAILED_KIND, SESSION_STARTED_KIND, sessionCapabilitiesSchema, } from "@moxt-ai/mobius-protocol";
2
2
  import { MobiusProtocolError, MobiusValidationError } from "./errors.js";
3
+ const MOBIUS_EVENT_FORMAT_VERSION = "1";
4
+ const MOBIUS_SESSION_EVENT_STREAM_EVENT = "mobius.session-event.v1";
5
+ const MOBIUS_SESSION_EVENT_STREAM_MEDIA_TYPE = "text/event-stream";
6
+ const MOBIUS_SESSION_EVENT_STREAM_TRANSPORT = "sse";
7
+ const MOBIUS_SESSION_EXPORT_FORMAT_VERSION = "1";
3
8
  const IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
4
9
  const SESSION_CAPABILITY_FIELDS = [
5
10
  "additionalDirectories",
@@ -41,7 +46,7 @@ function identifierField(value, field) {
41
46
  }
42
47
  return candidate;
43
48
  }
44
- function _integerField(value, field) {
49
+ function integerField(value, field) {
45
50
  const candidate = value[field];
46
51
  if (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0) {
47
52
  throw invalidResponse(`The service returned an invalid ${field}`);
@@ -55,6 +60,16 @@ function booleanField(value, field) {
55
60
  }
56
61
  return candidate;
57
62
  }
63
+ function busyStatusField(value, field) {
64
+ const candidate = value[field];
65
+ if (candidate === undefined || candidate === null) {
66
+ return undefined;
67
+ }
68
+ if (candidate !== "working" && candidate !== "failed") {
69
+ throw invalidResponse(`The service returned an invalid ${field}`);
70
+ }
71
+ return candidate;
72
+ }
58
73
  function arrayField(value, field, maximumLength = 10_000) {
59
74
  const candidate = value[field];
60
75
  if (!Array.isArray(candidate) || candidate.length > maximumLength) {
@@ -62,12 +77,189 @@ function arrayField(value, field, maximumLength = 10_000) {
62
77
  }
63
78
  return candidate;
64
79
  }
80
+ function nullableCursor(value, field) {
81
+ const candidate = value[field];
82
+ if (candidate === null) {
83
+ return "";
84
+ }
85
+ if (typeof candidate !== "string" || candidate.length > 512) {
86
+ throw invalidResponse(`The service returned an invalid ${field}`);
87
+ }
88
+ return candidate;
89
+ }
65
90
  function validateTimestamp(value, field) {
66
91
  if (Number.isNaN(Date.parse(value))) {
67
92
  throw invalidResponse(`The service returned an invalid ${field}`);
68
93
  }
69
94
  return value;
70
95
  }
96
+ export class MobiusSessionEventCapabilities {
97
+ eventName;
98
+ formatVersion;
99
+ mediaType;
100
+ transport;
101
+ constructor(eventName, formatVersion, mediaType, transport) {
102
+ this.eventName = eventName;
103
+ this.formatVersion = formatVersion;
104
+ this.mediaType = mediaType;
105
+ this.transport = transport;
106
+ }
107
+ }
108
+ export class MobiusAuthenticationCapabilities {
109
+ browserCredentials;
110
+ maximumBrowserCredentialLifetimeSeconds;
111
+ minimumBrowserCredentialLifetimeSeconds;
112
+ constructor(browserCredentials, maximumBrowserCredentialLifetimeSeconds, minimumBrowserCredentialLifetimeSeconds) {
113
+ this.browserCredentials = browserCredentials;
114
+ this.maximumBrowserCredentialLifetimeSeconds = maximumBrowserCredentialLifetimeSeconds;
115
+ this.minimumBrowserCredentialLifetimeSeconds = minimumBrowserCredentialLifetimeSeconds;
116
+ }
117
+ }
118
+ export class MobiusPortabilityCapabilities {
119
+ exportFormatVersion;
120
+ nativeContextImport;
121
+ targetBindingRequired;
122
+ constructor(exportFormatVersion, nativeContextImport, targetBindingRequired) {
123
+ this.exportFormatVersion = exportFormatVersion;
124
+ this.nativeContextImport = nativeContextImport;
125
+ this.targetBindingRequired = targetBindingRequired;
126
+ }
127
+ }
128
+ export class MobiusResourceCapabilities {
129
+ attempts;
130
+ browserCredentials;
131
+ events;
132
+ interactions;
133
+ messages;
134
+ portability;
135
+ runtimePairings;
136
+ runtimes;
137
+ sessions;
138
+ toolCalls;
139
+ turns;
140
+ constructor(resources) {
141
+ this.attempts = booleanField(resources, "attempts");
142
+ this.browserCredentials = booleanField(resources, "browserCredentials");
143
+ this.events = booleanField(resources, "events");
144
+ this.interactions = booleanField(resources, "interactions");
145
+ this.messages = booleanField(resources, "messages");
146
+ this.portability = booleanField(resources, "portability");
147
+ this.runtimePairings = booleanField(resources, "runtimePairings");
148
+ this.runtimes = booleanField(resources, "runtimes");
149
+ this.sessions = booleanField(resources, "sessions");
150
+ this.toolCalls = booleanField(resources, "toolCalls");
151
+ this.turns = booleanField(resources, "turns");
152
+ }
153
+ }
154
+ export class MobiusServiceCapabilities {
155
+ apiVersion;
156
+ authentication;
157
+ portability;
158
+ resources;
159
+ sessionEvents;
160
+ constructor(apiVersion, authentication, portability, resources, sessionEvents) {
161
+ this.apiVersion = apiVersion;
162
+ this.authentication = authentication;
163
+ this.portability = portability;
164
+ this.resources = resources;
165
+ this.sessionEvents = sessionEvents;
166
+ }
167
+ }
168
+ export function decodeMobiusServiceCapabilities(value) {
169
+ const capabilities = record(value, "service capabilities");
170
+ const resources = record(capabilities["resources"], "resource capabilities");
171
+ const authentication = record(capabilities["authentication"], "authentication capabilities");
172
+ const portability = record(capabilities["portability"], "portability capabilities");
173
+ const sessionEvents = record(capabilities["sessionEvents"], "Session event capabilities");
174
+ const apiVersion = stringField(capabilities, "apiVersion", 32);
175
+ const eventName = stringField(sessionEvents, "eventName", 128);
176
+ const formatVersion = stringField(sessionEvents, "formatVersion", 32);
177
+ const mediaType = stringField(sessionEvents, "mediaType", 128);
178
+ const transport = stringField(sessionEvents, "transport", 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
+ exportFormatVersion !== MOBIUS_SESSION_EXPORT_FORMAT_VERSION) {
186
+ throw invalidResponse("The service returned unsupported Mobius API capabilities");
187
+ }
188
+ return new MobiusServiceCapabilities(apiVersion, 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));
189
+ }
190
+ export class MobiusRecordingPolicy {
191
+ contentLimitBytes;
192
+ hotEventLimit;
193
+ idempotencyRetentionMilliseconds;
194
+ level;
195
+ retentionMilliseconds;
196
+ constructor(level, retentionMilliseconds, hotEventLimit, contentLimitBytes, idempotencyRetentionMilliseconds = retentionMilliseconds) {
197
+ if ((level !== "full" && level !== "summary") ||
198
+ !Number.isSafeInteger(retentionMilliseconds) ||
199
+ retentionMilliseconds < 60_000 ||
200
+ !Number.isSafeInteger(hotEventLimit) ||
201
+ hotEventLimit < 10 ||
202
+ !Number.isSafeInteger(contentLimitBytes) ||
203
+ contentLimitBytes < 1_024 ||
204
+ !Number.isSafeInteger(idempotencyRetentionMilliseconds) ||
205
+ idempotencyRetentionMilliseconds < 60_000 ||
206
+ idempotencyRetentionMilliseconds > retentionMilliseconds) {
207
+ throw new MobiusValidationError("The Session recording policy is invalid");
208
+ }
209
+ this.contentLimitBytes = contentLimitBytes;
210
+ this.hotEventLimit = hotEventLimit;
211
+ this.idempotencyRetentionMilliseconds = idempotencyRetentionMilliseconds;
212
+ this.level = level;
213
+ this.retentionMilliseconds = retentionMilliseconds;
214
+ }
215
+ toJSON = () => new MobiusRecordingPolicyRequestPayload(this.level, this.retentionMilliseconds, this.hotEventLimit, this.contentLimitBytes, this.idempotencyRetentionMilliseconds);
216
+ }
217
+ class MobiusRecordingPolicyRequestPayload {
218
+ contentLimitBytes;
219
+ hotEventLimit;
220
+ idempotencyRetentionMilliseconds;
221
+ level;
222
+ retentionMilliseconds;
223
+ constructor(level, retentionMilliseconds, hotEventLimit, contentLimitBytes, idempotencyRetentionMilliseconds) {
224
+ this.contentLimitBytes = contentLimitBytes;
225
+ this.hotEventLimit = hotEventLimit;
226
+ this.idempotencyRetentionMilliseconds = idempotencyRetentionMilliseconds;
227
+ this.level = level;
228
+ this.retentionMilliseconds = retentionMilliseconds;
229
+ }
230
+ }
231
+ export class MobiusSessionAccess {
232
+ credential;
233
+ credentialId;
234
+ projectId;
235
+ sessionId;
236
+ expiresAt;
237
+ constructor(value) {
238
+ const resource = record(value, "Session access");
239
+ this.credential = stringField(resource, "credential", 2_048);
240
+ if (!/^msession_[A-Za-z0-9_-]{22}_[A-Za-z0-9_-]+_[A-Za-z0-9_-]{43}$/u.test(this.credential)) {
241
+ throw invalidResponse("The Session credential is invalid");
242
+ }
243
+ this.credentialId = identifierField(resource, "credentialId");
244
+ this.projectId = identifierField(resource, "projectId");
245
+ this.sessionId = identifierField(resource, "sessionId");
246
+ this.expiresAt = validateTimestamp(stringField(resource, "expiresAt", 128), "expiresAt");
247
+ }
248
+ }
249
+ export class MobiusSessionImportBinding {
250
+ agentRef;
251
+ bindingId;
252
+ configRevision;
253
+ runtimeId;
254
+ workspaceRef;
255
+ constructor(bindingId, runtimeId, agentRef, workspaceRef, configRevision = 1) {
256
+ this.agentRef = agentRef;
257
+ this.bindingId = bindingId;
258
+ this.configRevision = configRevision;
259
+ this.runtimeId = runtimeId;
260
+ this.workspaceRef = workspaceRef;
261
+ }
262
+ }
71
263
  export class MobiusBrowserCredentialRequest {
72
264
  expiresInSeconds;
73
265
  constructor(expiresInSeconds) {
@@ -354,4 +546,825 @@ export function decodeMobiusRuntimePairingStatus(value) {
354
546
  }
355
547
  throw invalidResponse("The service returned an unsupported Runtime pairing status");
356
548
  }
549
+ export class MobiusInteractionResponseRequest {
550
+ responderId;
551
+ constructor(responderId) {
552
+ this.responderId = responderId;
553
+ }
554
+ }
555
+ export class MobiusPermissionResponseRequest extends MobiusInteractionResponseRequest {
556
+ kind = "permission";
557
+ optionId;
558
+ outcome;
559
+ constructor(responderId, outcome, optionId) {
560
+ super(responderId);
561
+ this.optionId = optionId;
562
+ this.outcome = outcome;
563
+ }
564
+ }
565
+ export class MobiusElicitationResponseRequest extends MobiusInteractionResponseRequest {
566
+ action;
567
+ content;
568
+ kind = "elicitation";
569
+ constructor(responderId, action, content) {
570
+ super(responderId);
571
+ this.action = action;
572
+ this.content = content;
573
+ }
574
+ }
575
+ export function decodeMobiusInteraction(value) {
576
+ try {
577
+ return decodeInteraction(value);
578
+ }
579
+ catch (cause) {
580
+ throw new MobiusProtocolError("The service returned an invalid Interaction", { cause });
581
+ }
582
+ }
583
+ export function decodeMobiusInteractionList(value) {
584
+ const response = record(value, "Interaction list");
585
+ return arrayField(response, "interactions", 100).map(decodeMobiusInteraction);
586
+ }
587
+ export class MobiusPageRequest {
588
+ cursor;
589
+ limit;
590
+ constructor(limit, cursor) {
591
+ if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100 || cursor.length > 512) {
592
+ throw new MobiusValidationError("The page request is invalid");
593
+ }
594
+ this.cursor = cursor;
595
+ this.limit = limit;
596
+ }
597
+ }
598
+ export class MobiusSessionBinding {
599
+ agentRef;
600
+ bindingId;
601
+ configRevision;
602
+ createdAt;
603
+ runtimeId;
604
+ sessionId;
605
+ workspaceRef;
606
+ constructor(agentRef, bindingId, configRevision, createdAt, runtimeId, sessionId, workspaceRef) {
607
+ this.agentRef = agentRef;
608
+ this.bindingId = bindingId;
609
+ this.configRevision = configRevision;
610
+ this.createdAt = createdAt;
611
+ this.runtimeId = runtimeId;
612
+ this.sessionId = sessionId;
613
+ this.workspaceRef = workspaceRef;
614
+ }
615
+ }
616
+ export class MobiusSessionState {
617
+ }
618
+ export class MobiusReadySessionState extends MobiusSessionState {
619
+ kind = "ready";
620
+ }
621
+ export class MobiusDeletingSessionState extends MobiusSessionState {
622
+ kind = "deleting";
623
+ requestedAt;
624
+ constructor(requestedAt) {
625
+ super();
626
+ this.requestedAt = requestedAt;
627
+ }
628
+ }
629
+ export class MobiusDeletedSessionState extends MobiusSessionState {
630
+ completedAt;
631
+ kind = "deleted";
632
+ constructor(completedAt) {
633
+ super();
634
+ this.completedAt = completedAt;
635
+ }
636
+ }
637
+ export class MobiusSession {
638
+ agentId;
639
+ createdAt;
640
+ createdBy;
641
+ defaultBinding;
642
+ hasNativeHistory;
643
+ lastCommittedSequence;
644
+ policy;
645
+ projectId;
646
+ runtimeId;
647
+ sessionId;
648
+ state;
649
+ title;
650
+ updatedAt;
651
+ constructor(agentId, createdAt, createdBy, defaultBinding, hasNativeHistory, lastCommittedSequence, policy, projectId, runtimeId, sessionId, state, title, updatedAt) {
652
+ this.agentId = agentId;
653
+ this.createdAt = createdAt;
654
+ this.createdBy = createdBy;
655
+ this.defaultBinding = defaultBinding;
656
+ this.hasNativeHistory = hasNativeHistory;
657
+ this.lastCommittedSequence = lastCommittedSequence;
658
+ this.policy = policy;
659
+ this.projectId = projectId;
660
+ this.runtimeId = runtimeId;
661
+ this.sessionId = sessionId;
662
+ this.state = state;
663
+ this.title = title;
664
+ this.updatedAt = updatedAt;
665
+ }
666
+ }
667
+ /** A Session returned by the listing endpoint, including its latest turn status. */
668
+ export class MobiusSessionListing extends MobiusSession {
669
+ busyStatus;
670
+ constructor(session, busyStatus) {
671
+ super(session.agentId, session.createdAt, session.createdBy, session.defaultBinding, session.hasNativeHistory, session.lastCommittedSequence, session.policy, session.projectId, session.runtimeId, session.sessionId, session.state, session.title, session.updatedAt);
672
+ this.busyStatus = busyStatus;
673
+ }
674
+ }
675
+ export function decodeMobiusSessionState(value) {
676
+ const state = record(value, "Session lifecycle");
677
+ const kind = stringField(state, "kind", 32);
678
+ if (kind === "ready") {
679
+ return new MobiusReadySessionState();
680
+ }
681
+ if (kind === "deleting") {
682
+ return new MobiusDeletingSessionState(validateTimestamp(stringField(state, "requestedAt", 128), "requestedAt"));
683
+ }
684
+ if (kind === "deleted") {
685
+ return new MobiusDeletedSessionState(validateTimestamp(stringField(state, "completedAt", 128), "completedAt"));
686
+ }
687
+ throw invalidResponse("The service returned an unsupported Session lifecycle");
688
+ }
689
+ function decodeBinding(value) {
690
+ const binding = record(value, "Session binding");
691
+ 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"));
692
+ }
693
+ function decodeRecordingPolicy(value) {
694
+ const policy = record(value, "Session recording policy");
695
+ return new MobiusRecordingPolicy(stringField(policy, "level", 32), integerField(policy, "retentionMilliseconds"), integerField(policy, "hotEventLimit"), integerField(policy, "contentLimitBytes"), integerField(policy, "idempotencyRetentionMilliseconds"));
696
+ }
697
+ export function decodeMobiusSession(value) {
698
+ const session = record(value, "Session");
699
+ const sequence = stringField(session, "lastCommittedSeq", 40);
700
+ if (!/^(?:0|[1-9][0-9]*)$/.test(sequence)) {
701
+ throw invalidResponse("The service returned an invalid event sequence");
702
+ }
703
+ 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"));
704
+ }
705
+ export function decodeMobiusSessionListing(value) {
706
+ const session = record(value, "Session");
707
+ return new MobiusSessionListing(decodeMobiusSession(session), busyStatusField(session, "busyStatus"));
708
+ }
709
+ export class MobiusSessionPage {
710
+ nextCursor;
711
+ sessions;
712
+ constructor(sessions, nextCursor) {
713
+ this.nextCursor = nextCursor;
714
+ this.sessions = sessions;
715
+ }
716
+ }
717
+ export function decodeMobiusSessionPage(value) {
718
+ const page = record(value, "Session page");
719
+ return new MobiusSessionPage(arrayField(page, "sessions", 100).map(decodeMobiusSessionListing), nullableCursor(page, "nextCursor"));
720
+ }
721
+ export class MobiusTurnState {
722
+ }
723
+ export class MobiusQueuedTurnState extends MobiusTurnState {
724
+ kind = "queued";
725
+ }
726
+ export class MobiusRunningTurnState extends MobiusTurnState {
727
+ kind = "running";
728
+ startedAt;
729
+ constructor(startedAt) {
730
+ super();
731
+ this.startedAt = startedAt;
732
+ }
733
+ }
734
+ export class MobiusSucceededTurnState extends MobiusTurnState {
735
+ completedAt;
736
+ kind = "succeeded";
737
+ stopReason;
738
+ constructor(completedAt, stopReason) {
739
+ super();
740
+ this.completedAt = completedAt;
741
+ this.stopReason = stopReason;
742
+ }
743
+ }
744
+ export class MobiusFailedTurnState extends MobiusTurnState {
745
+ code;
746
+ failedAt;
747
+ kind = "failed";
748
+ message;
749
+ retryable;
750
+ constructor(failedAt, code, message, retryable) {
751
+ super();
752
+ this.code = code;
753
+ this.failedAt = failedAt;
754
+ this.message = message;
755
+ this.retryable = retryable;
756
+ }
757
+ }
758
+ export class MobiusCancelledTurnState extends MobiusTurnState {
759
+ cancelledAt;
760
+ kind = "cancelled";
761
+ constructor(cancelledAt) {
762
+ super();
763
+ this.cancelledAt = cancelledAt;
764
+ }
765
+ }
766
+ export class MobiusIndeterminateTurnState extends MobiusTurnState {
767
+ detectedAt;
768
+ kind = "indeterminate";
769
+ reason;
770
+ constructor(detectedAt, reason) {
771
+ super();
772
+ this.detectedAt = detectedAt;
773
+ this.reason = reason;
774
+ }
775
+ }
776
+ export class MobiusTurn {
777
+ acceptedAt;
778
+ bindingId;
779
+ idempotencyKey;
780
+ request;
781
+ sessionId;
782
+ state;
783
+ turnId;
784
+ constructor(acceptedAt, bindingId, content, idempotencyKey, sessionId, sessionConfigurations, state, turnId, request = { content, kind: "prompt", sessionConfigurations }) {
785
+ this.acceptedAt = acceptedAt;
786
+ this.bindingId = bindingId;
787
+ this.idempotencyKey = idempotencyKey;
788
+ this.request = request;
789
+ this.sessionId = sessionId;
790
+ this.state = state;
791
+ this.turnId = turnId;
792
+ }
793
+ get content() {
794
+ return this.request.kind === "prompt" ? this.request.content : "";
795
+ }
796
+ get sessionConfigurations() {
797
+ return this.request.kind === "prompt" ? this.request.sessionConfigurations : [];
798
+ }
799
+ }
800
+ export function decodeMobiusTurn(value) {
801
+ const turn = decodeTurn(value);
802
+ let state;
803
+ switch (turn.state.kind) {
804
+ case "queued":
805
+ state = new MobiusQueuedTurnState();
806
+ break;
807
+ case "running":
808
+ state = new MobiusRunningTurnState(turn.state.startedAt);
809
+ break;
810
+ case "succeeded":
811
+ state = new MobiusSucceededTurnState(turn.state.completedAt, turn.state.result.stopReason);
812
+ break;
813
+ case "failed":
814
+ state = new MobiusFailedTurnState(turn.state.failedAt, turn.state.error.code, turn.state.error.message, turn.state.error.retryable);
815
+ break;
816
+ case "cancelled":
817
+ state = new MobiusCancelledTurnState(turn.state.cancelledAt);
818
+ break;
819
+ case "indeterminate":
820
+ state = new MobiusIndeterminateTurnState(turn.state.reconciliation.detectedAt, turn.state.reconciliation.reason);
821
+ break;
822
+ }
823
+ return new MobiusTurn(turn.acceptedAt, turn.bindingId, turn.request.kind === "prompt" ? turn.request.content : "", turn.idempotencyKey, turn.sessionId, turn.request.kind === "prompt" ? turn.request.sessionConfigurations : [], state, turn.turnId, turn.request);
824
+ }
825
+ export function decodeMobiusAttempt(value) {
826
+ try {
827
+ return decodeAttempt(value);
828
+ }
829
+ catch (cause) {
830
+ throw new MobiusProtocolError("The service returned an invalid Attempt", {
831
+ cause,
832
+ });
833
+ }
834
+ }
835
+ export class MobiusAttemptSummary {
836
+ }
837
+ export class MobiusNoAttemptSummary extends MobiusAttemptSummary {
838
+ kind = "none";
839
+ }
840
+ export class MobiusPresentAttemptSummary extends MobiusAttemptSummary {
841
+ attemptId;
842
+ constructor(attemptId) {
843
+ super();
844
+ this.attemptId = attemptId;
845
+ }
846
+ }
847
+ export class MobiusDispatchingAttemptSummary extends MobiusPresentAttemptSummary {
848
+ dispatchedAt;
849
+ kind = "dispatching";
850
+ constructor(attemptId, dispatchedAt) {
851
+ super(attemptId);
852
+ this.dispatchedAt = dispatchedAt;
853
+ }
854
+ }
855
+ export class MobiusRunningAttemptSummary extends MobiusPresentAttemptSummary {
856
+ kind = "running";
857
+ startedAt;
858
+ constructor(attemptId, startedAt) {
859
+ super(attemptId);
860
+ this.startedAt = startedAt;
861
+ }
862
+ }
863
+ export class MobiusSucceededAttemptSummary extends MobiusPresentAttemptSummary {
864
+ completedAt;
865
+ kind = "succeeded";
866
+ startedAt;
867
+ stopReason;
868
+ constructor(attemptId, startedAt, completedAt, stopReason) {
869
+ super(attemptId);
870
+ this.completedAt = completedAt;
871
+ this.startedAt = startedAt;
872
+ this.stopReason = stopReason;
873
+ }
874
+ }
875
+ export class MobiusCancelledAttemptSummary extends MobiusPresentAttemptSummary {
876
+ cancelledAt;
877
+ kind = "cancelled";
878
+ startedAt;
879
+ constructor(attemptId, startedAt, cancelledAt) {
880
+ super(attemptId);
881
+ this.cancelledAt = cancelledAt;
882
+ this.startedAt = startedAt;
883
+ }
884
+ }
885
+ export class MobiusWaitingInputAttemptSummary extends MobiusPresentAttemptSummary {
886
+ interactionIds;
887
+ kind = "waiting_input";
888
+ startedAt;
889
+ constructor(attemptId, startedAt, interactionIds) {
890
+ super(attemptId);
891
+ this.interactionIds = interactionIds;
892
+ this.startedAt = startedAt;
893
+ }
894
+ }
895
+ export class MobiusFailedBeforeStartAttemptSummary extends MobiusAttemptSummary {
896
+ code;
897
+ failedAt;
898
+ kind = "failed";
899
+ message;
900
+ constructor(code, message, failedAt) {
901
+ super();
902
+ this.code = code;
903
+ this.failedAt = failedAt;
904
+ this.message = message;
905
+ }
906
+ }
907
+ export class MobiusFailedAttemptSummary extends MobiusPresentAttemptSummary {
908
+ code;
909
+ failedAt;
910
+ kind = "failed";
911
+ message;
912
+ startedAt;
913
+ constructor(attemptId, startedAt, code, message, failedAt) {
914
+ super(attemptId);
915
+ this.code = code;
916
+ this.failedAt = failedAt;
917
+ this.message = message;
918
+ this.startedAt = startedAt;
919
+ }
920
+ }
921
+ export class MobiusIndeterminateAttemptSummary extends MobiusPresentAttemptSummary {
922
+ detectedAt;
923
+ kind = "indeterminate";
924
+ startedAt;
925
+ constructor(attemptId, startedAt, detectedAt) {
926
+ super(attemptId);
927
+ this.detectedAt = detectedAt;
928
+ this.startedAt = startedAt;
929
+ }
930
+ }
931
+ export function decodeMobiusAttemptSummary(value) {
932
+ if (value === null) {
933
+ return new MobiusNoAttemptSummary();
934
+ }
935
+ const attempt = record(value, "Attempt summary");
936
+ const kind = stringField(attempt, "kind", 32);
937
+ if (kind === "failed") {
938
+ const attemptId = attempt["attemptId"];
939
+ const startedAt = attempt["startedAt"];
940
+ const code = identifierField(attempt, "code");
941
+ const message = stringField(attempt, "message", 2_000);
942
+ const failedAt = validateTimestamp(stringField(attempt, "failedAt", 128), "failedAt");
943
+ if (attemptId === null && startedAt === null) {
944
+ return new MobiusFailedBeforeStartAttemptSummary(code, message, failedAt);
945
+ }
946
+ if (typeof attemptId !== "string" || typeof startedAt !== "string") {
947
+ throw invalidResponse("The service returned an invalid failed Attempt");
948
+ }
949
+ return new MobiusFailedAttemptSummary(attemptId, validateTimestamp(startedAt, "startedAt"), code, message, failedAt);
950
+ }
951
+ const attemptId = identifierField(attempt, "attemptId");
952
+ if (kind === "dispatching") {
953
+ return new MobiusDispatchingAttemptSummary(attemptId, validateTimestamp(stringField(attempt, "dispatchedAt", 128), "dispatchedAt"));
954
+ }
955
+ const startedAt = validateTimestamp(stringField(attempt, "startedAt", 128), "startedAt");
956
+ if (kind === "running") {
957
+ return new MobiusRunningAttemptSummary(attemptId, startedAt);
958
+ }
959
+ if (kind === "succeeded") {
960
+ return new MobiusSucceededAttemptSummary(attemptId, startedAt, validateTimestamp(stringField(attempt, "completedAt", 128), "completedAt"), stringField(attempt, "stopReason", 128));
961
+ }
962
+ if (kind === "cancelled") {
963
+ return new MobiusCancelledAttemptSummary(attemptId, startedAt, validateTimestamp(stringField(attempt, "cancelledAt", 128), "cancelledAt"));
964
+ }
965
+ if (kind === "waiting_input") {
966
+ return new MobiusWaitingInputAttemptSummary(attemptId, startedAt, arrayField(attempt, "interactionIds", 100).map((interactionId) => {
967
+ if (typeof interactionId !== "string") {
968
+ throw invalidResponse("The service returned an invalid interaction identifier");
969
+ }
970
+ return identifierField({ interactionId }, "interactionId");
971
+ }));
972
+ }
973
+ if (kind === "indeterminate") {
974
+ return new MobiusIndeterminateAttemptSummary(attemptId, startedAt, validateTimestamp(stringField(attempt, "detectedAt", 128), "detectedAt"));
975
+ }
976
+ throw invalidResponse("The service returned an unsupported Attempt state");
977
+ }
978
+ export class MobiusActivitySummary {
979
+ activityId;
980
+ attemptId;
981
+ activityType;
982
+ detailAvailability;
983
+ input;
984
+ locations;
985
+ name;
986
+ output;
987
+ sequence;
988
+ status;
989
+ title;
990
+ toolCallId;
991
+ toolKind;
992
+ constructor(activityId, attemptId, activityType, detailAvailability, input, locations, name, output, sequence, status, title, toolCallId, toolKind) {
993
+ this.activityId = activityId;
994
+ this.attemptId = attemptId;
995
+ this.activityType = activityType;
996
+ this.detailAvailability = detailAvailability;
997
+ this.input = input;
998
+ this.locations = locations;
999
+ this.name = name;
1000
+ this.output = output;
1001
+ this.sequence = sequence;
1002
+ this.status = status;
1003
+ this.title = title;
1004
+ this.toolCallId = toolCallId;
1005
+ this.toolKind = toolKind;
1006
+ }
1007
+ }
1008
+ export function decodeMobiusActivitySummary(value) {
1009
+ const activity = record(value, "Activity summary");
1010
+ return new MobiusActivitySummary(identifierField(activity, "activityId"), identifierField(activity, "attemptId"), stringField(activity, "activityType", 128), stringField(activity, "detailAvailability", 32), stringField(activity, "input", AGENT_ACTIVITY_DETAIL_LIMIT), arrayField(activity, "locations", 100).map((location) => {
1011
+ if (typeof location !== "string" || location.length > 2_048) {
1012
+ throw invalidResponse("The service returned an invalid Activity location");
1013
+ }
1014
+ return location;
1015
+ }), stringField(activity, "name", 128), stringField(activity, "output", AGENT_ACTIVITY_DETAIL_LIMIT), integerField(activity, "sequence"), stringField(activity, "status", 64), stringField(activity, "title", 500), identifierField(activity, "toolCallId"), stringField(activity, "toolKind", 128));
1016
+ }
1017
+ /**
1018
+ * A stored step whose recorded shape a later protocol revision can no longer decode must cost only that
1019
+ * step. Failing the whole page would hide every other Turn in the Session, so an unreadable summary is
1020
+ * dropped from the restored conversation instead.
1021
+ */
1022
+ function decodeMobiusActivitySummaries(values) {
1023
+ const activities = [];
1024
+ for (const value of values) {
1025
+ try {
1026
+ activities.push(decodeMobiusActivitySummary(value));
1027
+ }
1028
+ catch {
1029
+ // Skip the unreadable entry and keep the rest of the conversation.
1030
+ }
1031
+ }
1032
+ return activities;
1033
+ }
1034
+ export class MobiusMessageContent {
1035
+ activities;
1036
+ additionalDirectoryIds;
1037
+ attempt;
1038
+ createdAt;
1039
+ disposition;
1040
+ images;
1041
+ messageId;
1042
+ prompt;
1043
+ resources;
1044
+ response;
1045
+ constructor(activities, additionalDirectoryIds, attempt, createdAt, disposition, images, messageId, prompt, resources, response) {
1046
+ this.activities = activities;
1047
+ this.additionalDirectoryIds = additionalDirectoryIds;
1048
+ this.attempt = attempt;
1049
+ this.createdAt = createdAt;
1050
+ this.disposition = disposition;
1051
+ this.images = images;
1052
+ this.messageId = messageId;
1053
+ this.prompt = prompt;
1054
+ this.resources = resources;
1055
+ this.response = response;
1056
+ }
1057
+ }
1058
+ export class MobiusMessage extends MobiusMessageContent {
1059
+ agentId;
1060
+ commandId;
1061
+ contents;
1062
+ sessionId;
1063
+ targetCommandId;
1064
+ turnId;
1065
+ constructor(content, agentId, commandId, contents, sessionId, targetCommandId, turnId = "") {
1066
+ super(content.activities, content.additionalDirectoryIds, content.attempt, content.createdAt, content.disposition, content.images, content.messageId, content.prompt, content.resources, content.response);
1067
+ this.agentId = agentId;
1068
+ this.commandId = commandId;
1069
+ this.contents = contents;
1070
+ this.sessionId = sessionId;
1071
+ this.targetCommandId = targetCommandId;
1072
+ this.turnId = turnId;
1073
+ }
1074
+ }
1075
+ export function decodeMobiusMessageContent(message) {
1076
+ return new MobiusMessageContent(decodeMobiusActivitySummaries(arrayField(message, "activities", 10_000)), arrayField(message, "additionalDirectoryIds", 100).map((directoryId) => {
1077
+ if (typeof directoryId !== "string") {
1078
+ throw invalidResponse("The service returned an invalid additional directory identifier");
1079
+ }
1080
+ return identifierField({ directoryId }, "directoryId");
1081
+ }), decodeMobiusAttemptSummary(message["attempt"]), 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));
1082
+ }
1083
+ function decodeMobiusMessage(value) {
1084
+ const message = record(value, "Session message");
1085
+ return new MobiusMessage(decodeMobiusMessageContent(message), identifierField(message, "agentId"), identifierField(message, "commandId"), arrayField(message, "contents", 100).map(decodeAgentDisplayContentValue), identifierField(message, "sessionId"), stringField(message, "targetCommandId", 128), stringField(message, "turnId", 128));
1086
+ }
1087
+ export class MobiusMessagePage {
1088
+ lastCommittedSequence;
1089
+ messages;
1090
+ nextCursor;
1091
+ tailEventCursor;
1092
+ constructor(lastCommittedSequence, messages, nextCursor, tailEventCursor) {
1093
+ this.lastCommittedSequence = lastCommittedSequence;
1094
+ this.messages = messages;
1095
+ this.nextCursor = nextCursor;
1096
+ this.tailEventCursor = tailEventCursor;
1097
+ }
1098
+ }
1099
+ export function decodeMobiusMessagePage(value) {
1100
+ const page = record(value, "Session message page");
1101
+ const sequence = stringField(page, "lastCommittedSeq", 40);
1102
+ if (!/^(?:0|[1-9][0-9]*)$/.test(sequence)) {
1103
+ throw invalidResponse("The service returned an invalid event sequence");
1104
+ }
1105
+ const tailEventCursor = page["tailEventCursor"];
1106
+ if (tailEventCursor !== undefined && (typeof tailEventCursor !== "string" || tailEventCursor.length > 512)) {
1107
+ throw invalidResponse("The service returned an invalid tailEventCursor");
1108
+ }
1109
+ return new MobiusMessagePage(sequence, arrayField(page, "messages", 100).map(decodeMobiusMessage), nullableCursor(page, "nextCursor"), tailEventCursor ?? "");
1110
+ }
1111
+ export class MobiusToolCallDetail {
1112
+ }
1113
+ export class MobiusAvailableToolCallDetail extends MobiusToolCallDetail {
1114
+ artifactId;
1115
+ content;
1116
+ input;
1117
+ kind = "available";
1118
+ output;
1119
+ storage;
1120
+ constructor(artifactId, content, input, output, storage) {
1121
+ super();
1122
+ this.artifactId = artifactId;
1123
+ this.content = content;
1124
+ this.input = input;
1125
+ this.output = output;
1126
+ this.storage = storage;
1127
+ }
1128
+ }
1129
+ export class MobiusTruncatedToolCallDetail extends MobiusToolCallDetail {
1130
+ capturedBytes;
1131
+ kind = "truncated";
1132
+ originalBytes;
1133
+ constructor(capturedBytes, originalBytes) {
1134
+ super();
1135
+ this.capturedBytes = capturedBytes;
1136
+ this.originalBytes = originalBytes;
1137
+ }
1138
+ }
1139
+ export class MobiusUnrecordedToolCallDetail extends MobiusToolCallDetail {
1140
+ kind = "unrecorded";
1141
+ }
1142
+ export class MobiusDeletedToolCallDetail extends MobiusToolCallDetail {
1143
+ deletedAt;
1144
+ kind = "deleted";
1145
+ constructor(deletedAt) {
1146
+ super();
1147
+ this.deletedAt = deletedAt;
1148
+ }
1149
+ }
1150
+ export function decodeMobiusToolCallDetail(value) {
1151
+ const detail = record(value, "ToolCall detail");
1152
+ const kind = stringField(detail, "kind", 32);
1153
+ if (kind === "available") {
1154
+ const storage = stringField(detail, "storage", 32);
1155
+ if (storage !== "archive" && storage !== "hot") {
1156
+ throw invalidResponse("The service returned an invalid ToolCall storage state");
1157
+ }
1158
+ return new MobiusAvailableToolCallDetail(identifierField(detail, "artifactId"), arrayField(detail, "content", 100_000), stringField(detail, "input"), stringField(detail, "output"), storage);
1159
+ }
1160
+ if (kind === "truncated") {
1161
+ return new MobiusTruncatedToolCallDetail(integerField(detail, "capturedBytes"), integerField(detail, "originalBytes"));
1162
+ }
1163
+ if (kind === "unrecorded") {
1164
+ return new MobiusUnrecordedToolCallDetail();
1165
+ }
1166
+ if (kind === "deleted") {
1167
+ return new MobiusDeletedToolCallDetail(validateTimestamp(stringField(detail, "deletedAt", 128), "deletedAt"));
1168
+ }
1169
+ throw invalidResponse("The service returned an invalid ToolCall detail");
1170
+ }
1171
+ export class MobiusEventPage {
1172
+ cursor;
1173
+ events;
1174
+ hasMore;
1175
+ constructor(cursor, events, hasMore) {
1176
+ this.cursor = cursor;
1177
+ this.events = events;
1178
+ this.hasMore = hasMore;
1179
+ }
1180
+ }
1181
+ export function decodeMobiusEventPage(value) {
1182
+ const page = record(value, "Session event page");
1183
+ return new MobiusEventPage(stringField(page, "cursor", 512), arrayField(page, "events", 100).map(decodeMobiusSessionEvent), booleanField(page, "hasMore"));
1184
+ }
1185
+ export class MobiusSessionExport {
1186
+ formatVersion;
1187
+ session;
1188
+ constructor(formatVersion, session) {
1189
+ this.formatVersion = formatVersion;
1190
+ this.session = session;
1191
+ }
1192
+ }
1193
+ export function decodeMobiusSessionExport(value) {
1194
+ const exported = record(value, "Session export");
1195
+ const formatVersion = stringField(exported, "formatVersion", 32);
1196
+ if (formatVersion !== MOBIUS_SESSION_EXPORT_FORMAT_VERSION) {
1197
+ throw invalidResponse("The service returned an unsupported Session export");
1198
+ }
1199
+ return new MobiusSessionExport(formatVersion, record(exported["session"], "Session export payload"));
1200
+ }
1201
+ export class MobiusEventSource {
1202
+ sourceSequence;
1203
+ constructor(sourceSequence) {
1204
+ this.sourceSequence = sourceSequence;
1205
+ }
1206
+ }
1207
+ export class MobiusRuntimeEventSource extends MobiusEventSource {
1208
+ kind = "runtime";
1209
+ }
1210
+ export class MobiusAttemptEventSource extends MobiusEventSource {
1211
+ attemptId;
1212
+ kind = "attempt";
1213
+ constructor(attemptId, sourceSequence) {
1214
+ super(sourceSequence);
1215
+ this.attemptId = attemptId;
1216
+ }
1217
+ }
1218
+ export class MobiusRecordedEvent {
1219
+ sessionId;
1220
+ constructor(sessionId) {
1221
+ this.sessionId = sessionId;
1222
+ }
1223
+ }
1224
+ export class MobiusTurnStartedEvent extends MobiusRecordedEvent {
1225
+ attemptId;
1226
+ commandId;
1227
+ kind = SESSION_STARTED_KIND;
1228
+ constructor(sessionId, commandId, attemptId) {
1229
+ super(sessionId);
1230
+ this.attemptId = attemptId;
1231
+ this.commandId = commandId;
1232
+ }
1233
+ }
1234
+ export class MobiusAgentMessageEvent extends MobiusRecordedEvent {
1235
+ commandId;
1236
+ kind = AGENT_MESSAGE_DELTA_KIND;
1237
+ text;
1238
+ constructor(sessionId, commandId, text) {
1239
+ super(sessionId);
1240
+ this.commandId = commandId;
1241
+ this.text = text;
1242
+ }
1243
+ }
1244
+ export class MobiusAgentActivityEvent extends MobiusRecordedEvent {
1245
+ activityId;
1246
+ activityType;
1247
+ commandId;
1248
+ content;
1249
+ detail;
1250
+ input;
1251
+ kind = AGENT_ACTIVITY_KIND;
1252
+ locations;
1253
+ name;
1254
+ output;
1255
+ sequence;
1256
+ status;
1257
+ title;
1258
+ toolKind;
1259
+ constructor(event) {
1260
+ super(event.sessionId);
1261
+ this.activityId = event.activityId;
1262
+ this.activityType = event.activityType;
1263
+ this.commandId = event.commandId;
1264
+ this.content = event.content;
1265
+ this.detail = event.detail;
1266
+ this.input = event.input;
1267
+ this.locations = event.locations;
1268
+ this.name = event.name;
1269
+ this.output = event.output;
1270
+ this.sequence = event.sequence;
1271
+ this.status = event.status;
1272
+ this.title = event.title;
1273
+ this.toolKind = event.toolKind;
1274
+ }
1275
+ }
1276
+ /** One increment of a streamed narration activity, before it is folded into a snapshot. */
1277
+ export class MobiusAgentActivityNarrationEvent extends MobiusRecordedEvent {
1278
+ activityId;
1279
+ activityType;
1280
+ commandId;
1281
+ kind = AGENT_ACTIVITY_NARRATION_KIND;
1282
+ sequence;
1283
+ text;
1284
+ constructor(event) {
1285
+ super(event.sessionId);
1286
+ this.activityId = event.activityId;
1287
+ this.activityType = event.activityType;
1288
+ this.commandId = event.commandId;
1289
+ this.sequence = event.sequence;
1290
+ this.text = event.text;
1291
+ }
1292
+ }
1293
+ export class MobiusTurnCompletedEvent extends MobiusRecordedEvent {
1294
+ commandId;
1295
+ kind = SESSION_COMPLETED_KIND;
1296
+ stopReason;
1297
+ constructor(sessionId, commandId, stopReason) {
1298
+ super(sessionId);
1299
+ this.commandId = commandId;
1300
+ this.stopReason = stopReason;
1301
+ }
1302
+ }
1303
+ export class MobiusTurnFailedEvent extends MobiusRecordedEvent {
1304
+ code;
1305
+ commandId;
1306
+ kind = SESSION_FAILED_KIND;
1307
+ message;
1308
+ constructor(sessionId, commandId, code, message) {
1309
+ super(sessionId);
1310
+ this.code = code;
1311
+ this.commandId = commandId;
1312
+ this.message = message;
1313
+ }
1314
+ }
1315
+ export class MobiusControlEvent extends MobiusRecordedEvent {
1316
+ encodedPayload;
1317
+ kind;
1318
+ constructor(sessionId, kind, encodedPayload) {
1319
+ super(sessionId);
1320
+ this.encodedPayload = encodedPayload;
1321
+ this.kind = kind;
1322
+ }
1323
+ }
1324
+ function decodeRecordedEvent(encoded) {
1325
+ const event = decodeRecordedSessionEvent(encoded);
1326
+ switch (event.kind) {
1327
+ case SESSION_STARTED_KIND:
1328
+ return new MobiusTurnStartedEvent(event.sessionId, event.commandId, event.attemptId);
1329
+ case AGENT_MESSAGE_DELTA_KIND:
1330
+ return new MobiusAgentMessageEvent(event.sessionId, event.commandId, event.text);
1331
+ case AGENT_ACTIVITY_KIND:
1332
+ return new MobiusAgentActivityEvent(event);
1333
+ case AGENT_ACTIVITY_NARRATION_KIND:
1334
+ return new MobiusAgentActivityNarrationEvent(event);
1335
+ case SESSION_COMPLETED_KIND:
1336
+ return new MobiusTurnCompletedEvent(event.sessionId, event.commandId, event.stopReason);
1337
+ case SESSION_FAILED_KIND:
1338
+ return new MobiusTurnFailedEvent(event.sessionId, event.commandId, event.code, event.message);
1339
+ default:
1340
+ return new MobiusControlEvent(event.sessionId, event.kind, encoded);
1341
+ }
1342
+ }
1343
+ export class MobiusSessionEvent {
1344
+ cursor;
1345
+ eventId;
1346
+ payload;
1347
+ recordedAt;
1348
+ sequence;
1349
+ sessionId;
1350
+ source;
1351
+ constructor(cursor, eventId, payload, recordedAt, sequence, sessionId, source) {
1352
+ this.cursor = cursor;
1353
+ this.eventId = eventId;
1354
+ this.payload = payload;
1355
+ this.recordedAt = recordedAt;
1356
+ this.sequence = sequence;
1357
+ this.sessionId = sessionId;
1358
+ this.source = source;
1359
+ }
1360
+ }
1361
+ export function decodeMobiusSessionEvent(value) {
1362
+ const encoded = JSON.stringify(value);
1363
+ if (typeof encoded !== "string") {
1364
+ throw invalidResponse("The service returned an invalid Session event");
1365
+ }
1366
+ const event = decodeCommittedSessionEvent(encoded);
1367
+ const payload = decodeRecordedEvent(event.payload);
1368
+ return new MobiusSessionEvent("", "", payload, "", "", event.sessionId, new MobiusRuntimeEventSource(""));
1369
+ }
357
1370
  //# sourceMappingURL=resources.js.map