@moxt-ai/mobius 0.0.337 → 0.0.339

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/cli.js CHANGED
@@ -2086,7 +2086,7 @@ var init_package = __esm({
2086
2086
  "package.json"() {
2087
2087
  package_default = {
2088
2088
  name: "@moxt-ai/mobius",
2089
- version: "0.0.337",
2089
+ version: "0.0.339",
2090
2090
  description: "Mobius CLI for pairing and running local AI agent services.",
2091
2091
  type: "module",
2092
2092
  bin: {
@@ -68539,16 +68539,20 @@ var init_acp_agent = __esm({
68539
68539
  }, message.tool_use_id !== void 0)
68540
68540
  });
68541
68541
  }
68542
- backgroundTasks.delete(message.task_id);
68543
68542
  if (message.skip_transcript) {
68543
+ backgroundTasks.delete(message.task_id);
68544
68544
  awaitingBackgroundResults.delete(message.task_id);
68545
- } else {
68545
+ } else if (backgroundTasks.delete(message.task_id)) {
68546
68546
  awaitingBackgroundResults.add(message.task_id);
68547
68547
  }
68548
68548
  reportBackgroundActivity();
68549
68549
  session.liveBackgroundTasks.delete(message.task_id);
68550
68550
  break;
68551
68551
  case "task_updated":
68552
+ if (!hasBackgroundLevel && message.patch.is_backgrounded === true) {
68553
+ backgroundTasks.add(message.task_id);
68554
+ reportBackgroundActivity();
68555
+ }
68552
68556
  if (message.patch.status === "completed" || message.patch.status === "failed" || message.patch.status === "killed") {
68553
68557
  session.liveBackgroundTasks.delete(message.task_id);
68554
68558
  if (backgroundTasks.delete(message.task_id)) {
@@ -74489,154 +74493,6 @@ var init_title = __esm({
74489
74493
  }
74490
74494
  });
74491
74495
 
74492
- // ../mobius-sdk/src/protocol/session/files/index.ts
74493
- function binaryBytes(value) {
74494
- if (value instanceof ArrayBuffer) {
74495
- return new Uint8Array(value);
74496
- }
74497
- if (ArrayBuffer.isView(value)) {
74498
- return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
74499
- }
74500
- throw new Error("Content chunk must be a binary WebSocket frame");
74501
- }
74502
- function encodeContentChunkFrame(frame) {
74503
- if (!isIdentifier(frame.requestId)) {
74504
- throw new Error("Content chunk request identifier is invalid");
74505
- }
74506
- if (!Number.isSafeInteger(frame.sequence) || frame.sequence < 0 || frame.sequence > 4294967295) {
74507
- throw new Error("Content chunk sequence is invalid");
74508
- }
74509
- if (frame.bytes.byteLength < 1 || frame.bytes.byteLength > CONTENT_CHUNK_MAX_BYTES) {
74510
- throw new Error("Content chunk size is invalid");
74511
- }
74512
- const requestId = new TextEncoder().encode(frame.requestId);
74513
- if (requestId.byteLength > 255) {
74514
- throw new Error("Content chunk request identifier is too long");
74515
- }
74516
- const encoded = new Uint8Array(CONTENT_CHUNK_HEADER_BYTES + requestId.byteLength + frame.bytes.byteLength);
74517
- encoded.set(CONTENT_CHUNK_MAGIC, 0);
74518
- encoded[CONTENT_CHUNK_MAGIC.byteLength] = requestId.byteLength;
74519
- new DataView(encoded.buffer).setUint32(CONTENT_CHUNK_MAGIC.byteLength + 1, frame.sequence);
74520
- encoded.set(requestId, CONTENT_CHUNK_HEADER_BYTES);
74521
- encoded.set(frame.bytes, CONTENT_CHUNK_HEADER_BYTES + requestId.byteLength);
74522
- return encoded;
74523
- }
74524
- function decodeContentChunkFrame(value) {
74525
- const encoded = binaryBytes(value);
74526
- if (encoded.byteLength <= CONTENT_CHUNK_HEADER_BYTES || !CONTENT_CHUNK_MAGIC.every((byte, index2) => encoded[index2] === byte)) {
74527
- throw new Error("Content chunk frame header is invalid");
74528
- }
74529
- const requestIdLength = encoded[CONTENT_CHUNK_MAGIC.byteLength] ?? 0;
74530
- const payloadOffset = CONTENT_CHUNK_HEADER_BYTES + requestIdLength;
74531
- if (requestIdLength < 1 || payloadOffset >= encoded.byteLength) {
74532
- throw new Error("Content chunk frame length is invalid");
74533
- }
74534
- const requestId = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(
74535
- encoded.subarray(CONTENT_CHUNK_HEADER_BYTES, payloadOffset)
74536
- );
74537
- const bytes = encoded.slice(payloadOffset);
74538
- const sequence = new DataView(encoded.buffer, encoded.byteOffset, encoded.byteLength).getUint32(
74539
- CONTENT_CHUNK_MAGIC.byteLength + 1
74540
- );
74541
- if (!isIdentifier(requestId) || bytes.byteLength > CONTENT_CHUNK_MAX_BYTES) {
74542
- throw new Error("Content chunk frame is invalid");
74543
- }
74544
- return { bytes, requestId, sequence };
74545
- }
74546
- var FILE_READ_KIND, FILE_BEGIN_KIND, FILE_END_KIND, FILE_FAILED_KIND, CONTENT_WRITE_KIND, CONTENT_COMMIT_KIND, CONTENT_READY_KIND, CONTENT_AVAILABLE_KIND, CONTENT_CHUNK_MAX_BYTES, CONTENT_WRITE_MAX_BYTES, PROMPT_IMAGE_MAX_BYTES, CONTENT_CHUNK_MAGIC, CONTENT_CHUNK_HEADER_BYTES, fileReadCommandSchema, fileBeginEventSchema, contentWriteCommandSchema, contentCommitCommandSchema, contentReadyEventSchema, contentAvailableEventSchema, fileEndEventSchema, fileFailedEventSchema, decodeFileReadCommand, encodeFileReadCommand, decodeFileBeginEvent, encodeFileBeginEvent, decodeFileEndEvent, encodeFileEndEvent, decodeFileFailedEvent, encodeFileFailedEvent, decodeContentWriteCommand, encodeContentWriteCommand, decodeContentCommitCommand, encodeContentCommitCommand, decodeContentReadyEvent, encodeContentReadyEvent, decodeContentAvailableEvent, encodeContentAvailableEvent;
74547
- var init_files = __esm({
74548
- "../mobius-sdk/src/protocol/session/files/index.ts"() {
74549
- "use strict";
74550
- init_zod();
74551
- init_identifier();
74552
- init_message_codec();
74553
- FILE_READ_KIND = "file.read";
74554
- FILE_BEGIN_KIND = "file.begin";
74555
- FILE_END_KIND = "file.end";
74556
- FILE_FAILED_KIND = "file.failed";
74557
- CONTENT_WRITE_KIND = "content.write";
74558
- CONTENT_COMMIT_KIND = "content.commit";
74559
- CONTENT_READY_KIND = "content.ready";
74560
- CONTENT_AVAILABLE_KIND = "content.available";
74561
- CONTENT_CHUNK_MAX_BYTES = 192 * 1024;
74562
- CONTENT_WRITE_MAX_BYTES = 32 * 1024 * 1024;
74563
- PROMPT_IMAGE_MAX_BYTES = 5e6;
74564
- CONTENT_CHUNK_MAGIC = new Uint8Array([77, 66, 67, 49]);
74565
- CONTENT_CHUNK_HEADER_BYTES = CONTENT_CHUNK_MAGIC.byteLength + 1 + 4;
74566
- fileReadCommandSchema = external_exports.object({
74567
- kind: external_exports.literal(FILE_READ_KIND),
74568
- maxBytes: external_exports.number().int().positive().max(128 * 1024 * 1024),
74569
- requestId: identifierStringSchema,
74570
- sessionId: identifierStringSchema,
74571
- path: external_exports.string().min(1).max(4096)
74572
- }).readonly();
74573
- fileBeginEventSchema = external_exports.object({
74574
- byteLength: external_exports.number().int().positive().max(128 * 1024 * 1024),
74575
- kind: external_exports.literal(FILE_BEGIN_KIND),
74576
- mediaType: external_exports.string().min(1).max(255),
74577
- modifiedAt: external_exports.iso.datetime({ offset: true }),
74578
- name: external_exports.string().min(1).max(500),
74579
- requestId: identifierStringSchema,
74580
- sessionId: identifierStringSchema
74581
- }).readonly();
74582
- contentWriteCommandSchema = external_exports.object({
74583
- byteLength: external_exports.number().int().positive().max(CONTENT_WRITE_MAX_BYTES),
74584
- contentKey: external_exports.string().regex(/^[a-f0-9]{64}$/u),
74585
- contentKind: external_exports.enum(["image", "resource"]),
74586
- kind: external_exports.literal(CONTENT_WRITE_KIND),
74587
- mediaType: external_exports.string().min(1).max(255),
74588
- name: external_exports.string().min(1).max(500),
74589
- requestId: identifierStringSchema,
74590
- sessionId: identifierStringSchema
74591
- }).readonly();
74592
- contentCommitCommandSchema = external_exports.object({
74593
- kind: external_exports.literal(CONTENT_COMMIT_KIND),
74594
- requestId: identifierStringSchema,
74595
- sessionId: identifierStringSchema
74596
- }).readonly();
74597
- contentReadyEventSchema = external_exports.object({
74598
- kind: external_exports.literal(CONTENT_READY_KIND),
74599
- requestId: identifierStringSchema,
74600
- sessionId: identifierStringSchema
74601
- }).readonly();
74602
- contentAvailableEventSchema = external_exports.object({
74603
- byteLength: external_exports.number().int().positive().max(CONTENT_WRITE_MAX_BYTES),
74604
- contentKey: external_exports.string().regex(/^[a-f0-9]{64}$/u),
74605
- kind: external_exports.literal(CONTENT_AVAILABLE_KIND),
74606
- requestId: identifierStringSchema,
74607
- sessionId: identifierStringSchema
74608
- }).readonly();
74609
- fileEndEventSchema = external_exports.object({
74610
- kind: external_exports.literal(FILE_END_KIND),
74611
- requestId: identifierStringSchema,
74612
- sessionId: identifierStringSchema
74613
- }).readonly();
74614
- fileFailedEventSchema = external_exports.object({
74615
- code: identifierStringSchema,
74616
- kind: external_exports.literal(FILE_FAILED_KIND),
74617
- message: external_exports.string().min(1).max(500),
74618
- requestId: identifierStringSchema,
74619
- sessionId: identifierStringSchema
74620
- }).readonly();
74621
- decodeFileReadCommand = (encoded) => decodeZodMessage(encoded, fileReadCommandSchema);
74622
- encodeFileReadCommand = (message) => encodeZodMessage(message, fileReadCommandSchema);
74623
- decodeFileBeginEvent = (encoded) => decodeZodMessage(encoded, fileBeginEventSchema);
74624
- encodeFileBeginEvent = (message) => encodeZodMessage(message, fileBeginEventSchema);
74625
- decodeFileEndEvent = (encoded) => decodeZodMessage(encoded, fileEndEventSchema);
74626
- encodeFileEndEvent = (message) => encodeZodMessage(message, fileEndEventSchema);
74627
- decodeFileFailedEvent = (encoded) => decodeZodMessage(encoded, fileFailedEventSchema);
74628
- encodeFileFailedEvent = (message) => encodeZodMessage(message, fileFailedEventSchema);
74629
- decodeContentWriteCommand = (encoded) => decodeZodMessage(encoded, contentWriteCommandSchema);
74630
- encodeContentWriteCommand = (message) => encodeZodMessage(message, contentWriteCommandSchema);
74631
- decodeContentCommitCommand = (encoded) => decodeZodMessage(encoded, contentCommitCommandSchema);
74632
- encodeContentCommitCommand = (message) => encodeZodMessage(message, contentCommitCommandSchema);
74633
- decodeContentReadyEvent = (encoded) => decodeZodMessage(encoded, contentReadyEventSchema);
74634
- encodeContentReadyEvent = (message) => encodeZodMessage(message, contentReadyEventSchema);
74635
- decodeContentAvailableEvent = (encoded) => decodeZodMessage(encoded, contentAvailableEventSchema);
74636
- encodeContentAvailableEvent = (message) => encodeZodMessage(message, contentAvailableEventSchema);
74637
- }
74638
- });
74639
-
74640
74496
  // ../mobius-sdk/src/protocol/shared/tool-input.ts
74641
74497
  function boundedJsonIssue(value, depth = 0) {
74642
74498
  if (depth > MAX_JSON_DEPTH) {
@@ -74811,211 +74667,827 @@ var init_interactions = __esm({
74811
74667
  }
74812
74668
  });
74813
74669
 
74814
- // ../mobius-sdk/src/protocol/session/interactions/model.ts
74815
- var timestampSchema, permissionRequestSchema, elicitationRequestSchema, interactionRequestSchema, interactionResponseSchema, interactionStateSchema, interactionSchema;
74816
- var init_model = __esm({
74817
- "../mobius-sdk/src/protocol/session/interactions/model.ts"() {
74818
- "use strict";
74819
- init_zod();
74820
- init_identifier();
74821
- init_interactions();
74822
- timestampSchema = external_exports.string().datetime({ offset: true });
74823
- permissionRequestSchema = external_exports.object({
74824
- kind: external_exports.literal("permission"),
74825
- options: external_exports.array(permissionOptionSchema).min(1).max(20).readonly(),
74826
- title: external_exports.string().min(1).max(500),
74827
- toolCallId: external_exports.string().min(1).max(255),
74828
- toolKind: external_exports.string().max(64)
74829
- }).readonly();
74830
- elicitationRequestSchema = external_exports.object({
74831
- elicitationId: external_exports.string().max(255),
74832
- fields: external_exports.array(elicitationFieldSchema).max(100).readonly(),
74833
- kind: external_exports.literal("elicitation"),
74834
- message: external_exports.string().min(1).max(2e3),
74835
- mode: external_exports.enum(["form", "url"]),
74836
- url: external_exports.string().max(4096)
74837
- }).readonly();
74838
- interactionRequestSchema = external_exports.discriminatedUnion("kind", [permissionRequestSchema, elicitationRequestSchema]);
74839
- interactionResponseSchema = external_exports.object({
74840
- content: external_exports.string().max(1e5),
74841
- kind: external_exports.enum(["permission", "elicitation"])
74842
- }).readonly();
74843
- interactionStateSchema = external_exports.discriminatedUnion("kind", [
74844
- external_exports.object({ kind: external_exports.literal("pending") }).readonly(),
74845
- external_exports.object({
74846
- kind: external_exports.literal("responded"),
74847
- respondedAt: timestampSchema,
74848
- responderId: identifierSchema,
74849
- response: interactionResponseSchema
74850
- }).readonly(),
74851
- external_exports.object({
74852
- kind: external_exports.literal("resolved"),
74853
- resolution: external_exports.discriminatedUnion("kind", [
74854
- external_exports.object({ kind: external_exports.literal("without_response") }).readonly(),
74855
- external_exports.object({
74856
- kind: external_exports.literal("response_applied"),
74857
- respondedAt: timestampSchema,
74858
- responderId: identifierSchema,
74859
- response: interactionResponseSchema
74860
- }).readonly()
74861
- ]),
74862
- resolvedAt: timestampSchema
74863
- }).readonly(),
74864
- external_exports.object({ expiredAt: timestampSchema, kind: external_exports.literal("expired") }).readonly(),
74865
- external_exports.object({
74866
- cancelledAt: timestampSchema,
74867
- kind: external_exports.literal("cancelled")
74868
- }).readonly()
74869
- ]);
74870
- interactionSchema = external_exports.object({
74871
- attemptId: identifierSchema,
74872
- interactionId: identifierSchema,
74873
- request: interactionRequestSchema,
74874
- sessionId: identifierSchema,
74875
- state: interactionStateSchema,
74876
- turnId: identifierSchema
74877
- }).readonly();
74670
+ // ../mobius-sdk/src/protocol/session/events/index.ts
74671
+ function isRecord4(value) {
74672
+ return typeof value === "object" && value !== null && !Array.isArray(value);
74673
+ }
74674
+ function inputValue(value) {
74675
+ if (typeof value !== "string") {
74676
+ return value;
74878
74677
  }
74879
- });
74880
-
74881
- // ../mobius-sdk/src/protocol/session/lifecycle/index.ts
74882
- var SESSION_PREPARE_KIND, SESSION_READY_KIND, SESSION_LIST_KIND, SESSION_LISTED_KIND, SESSION_QUERY_KIND, SESSION_QUERIED_KIND, SESSION_RESTORE_KIND, SESSION_RESTORED_KIND, SESSION_CLOSE_KIND, SESSION_CLOSED_KIND, SESSION_CLOSE_NOTICE_KIND, SESSION_CLOSED_ERROR_CODE, SESSION_STATUS_CHANGED_KIND, SESSION_COMMANDS_UPDATED_KIND, SESSION_INFO_UPDATED_KIND, SESSION_OPERATION_FAILED_KIND, sessionStatusChangedEventSchema, sessionMetadataSchema, sessionListCommandSchema, sessionsListedEventSchema, sessionQueryCommandSchema, sessionsQueriedEventSchema, sessionRestoreCommandSchema, sessionCloseCommandSchema, sessionPrepareCommandSchema, runtimeTimingsSchema, sessionReadyEventSchema, sessionRestoredEventSchema, sessionClosedEventSchema, sessionCloseNoticeEventSchema, sessionCommandsUpdatedEventSchema, sessionInfoUpdatedEventSchema, sessionOperationFailedEventSchema, decodeSessionListCommand, encodeSessionListCommand, decodeSessionsListedEvent, encodeSessionsListedEvent, decodeSessionQueryCommand, encodeSessionQueryCommand, decodeSessionsQueriedEvent, encodeSessionsQueriedEvent, decodeSessionRestoreCommand, encodeSessionRestoreCommand, decodeSessionRestoredEvent, encodeSessionRestoredEvent, decodeSessionCloseCommand, encodeSessionCloseCommand, decodeSessionClosedEvent, encodeSessionClosedEvent, decodeSessionCloseNoticeEvent, encodeSessionCloseNoticeEvent, decodeSessionStatusChangedEvent, encodeSessionStatusChangedEvent, decodeSessionPrepareCommand, encodeSessionPrepareCommand, decodeSessionReadyEvent, encodeSessionReadyEvent, decodeSessionInfoUpdatedEvent, encodeSessionInfoUpdatedEvent, decodeSessionOperationFailedEvent, encodeSessionOperationFailedEvent;
74883
- var init_lifecycle = __esm({
74884
- "../mobius-sdk/src/protocol/session/lifecycle/index.ts"() {
74678
+ try {
74679
+ return JSON.parse(value);
74680
+ } catch (cause) {
74681
+ throw new ProtocolMessageError("Session Event Log V2 message is not valid JSON", { cause });
74682
+ }
74683
+ }
74684
+ function decode3(value, schema) {
74685
+ const result = schema.safeParse(inputValue(value));
74686
+ if (!result.success) {
74687
+ throw new ProtocolMessageError("Session Event Log V2 message does not match its schema", {
74688
+ cause: result.error
74689
+ });
74690
+ }
74691
+ return result.data;
74692
+ }
74693
+ function encode3(value, schema) {
74694
+ return JSON.stringify(decode3(value, schema));
74695
+ }
74696
+ function decodedEntries(value, schema, maximum) {
74697
+ return Array.isArray(value) && value.length <= maximum ? value.flatMap((entry) => {
74698
+ const decoded = schema.safeParse(entry);
74699
+ return decoded.success ? [decoded.data] : [];
74700
+ }) : value;
74701
+ }
74702
+ function sanitizeConsumableNativeSessionEvents(value) {
74703
+ const input2 = inputValue(value);
74704
+ if (!isRecord4(input2)) {
74705
+ return input2;
74706
+ }
74707
+ const page = input2["events"];
74708
+ const queuedPromptRequests = input2["queuedPromptRequests"];
74709
+ return {
74710
+ ...input2,
74711
+ events: isRecord4(page) ? { ...page, events: decodedEntries(page["events"], sessionEventSchema, MAX_EVENT_COUNT) } : page,
74712
+ queuedPromptRequests: decodedEntries(
74713
+ queuedPromptRequests,
74714
+ queuedPromptRequestEventLogSchema,
74715
+ MAX_COLLECTION_SIZE2
74716
+ )
74717
+ };
74718
+ }
74719
+ var MAX_EVENT_COUNT, MAX_COLLECTION_SIZE2, MAX_CONTENT_LENGTH2, SESSION_EVENT_KIND, SESSION_EVENT_BATCH_MAX_SIZE, boundedString2, shortString, externalContentKeySchema, annotationsSchema, contentFields, textContentSchema, imageContentSchema, audioContentSchema, externalImageContentSchema, externalAudioContentSchema, externalResourceContentSchema, resourceLinkSchema, textResourceSchema, blobResourceSchema, embeddedResourceSchema, contentBlockSchema, toolCallContentSchema, toolKindSchema, toolStatusSchema, backgroundTaskSchema, toolPatchFields, planEntrySchema, planContentSchema, commandSchema, configSelectOptionSchema, configSelectGroupSchema, configBaseFields, sessionConfigOptionSchema2, contentChunkFields, acpSessionUpdateSchema, lifecycleBase, promptExecutionContextSchema, lifecycleMetadataSchema, sessionEventPayloadSchema, positionSchema, sharedSessionEventFields, sessionLiveEventFields, sessionEventSchema, sessionLiveEventSchema, wireLifecyclePayloadSchema, wireEventFields, sessionWireEventSchema, sessionWireEnvelopeSchema, sessionEventBatchSchema, sessionLiveEventBatchSchema, sessionExportSchema, mobiusSessionExportSchema, sessionEventEnvelopeSchema, sessionEventLogPageSchema, sessionEventOmissionSchema, nativeEventPageRequestSchema, queuedPromptRequestEventLogSchema, nativeSessionEventsSchema, knownSessionLiveEventBatchSchema, decodeSessionEvent, decodeKnownSessionEventPayload, decodeSessionEventEnvelope, encodeSessionEventEnvelope, decodeAcpSessionUpdate, decodeKnownNativeSessionEvents;
74720
+ var init_events = __esm({
74721
+ "../mobius-sdk/src/protocol/session/events/index.ts"() {
74885
74722
  "use strict";
74886
74723
  init_zod();
74887
74724
  init_directory();
74725
+ init_tool_input();
74726
+ init_tool_input();
74888
74727
  init_identifier();
74889
74728
  init_message_codec();
74890
- init_configuration();
74891
- init_shared2();
74892
- SESSION_PREPARE_KIND = "session.prepare";
74893
- SESSION_READY_KIND = "session.ready";
74894
- SESSION_LIST_KIND = "session.list";
74895
- SESSION_LISTED_KIND = "session.listed";
74896
- SESSION_QUERY_KIND = "session.query";
74897
- SESSION_QUERIED_KIND = "session.queried";
74898
- SESSION_RESTORE_KIND = "session.restore";
74899
- SESSION_RESTORED_KIND = "session.restored";
74900
- SESSION_CLOSE_KIND = "session.close";
74901
- SESSION_CLOSED_KIND = "session.closed";
74902
- SESSION_CLOSE_NOTICE_KIND = "session.close.notice";
74903
- SESSION_CLOSED_ERROR_CODE = "session_closed";
74904
- SESSION_STATUS_CHANGED_KIND = "session.status.changed";
74905
- SESSION_COMMANDS_UPDATED_KIND = "session.commands.updated";
74906
- SESSION_INFO_UPDATED_KIND = "session.info.updated";
74907
- SESSION_OPERATION_FAILED_KIND = "session.operation.failed";
74908
- sessionStatusChangedEventSchema = external_exports.object({
74909
- kind: external_exports.literal(SESSION_STATUS_CHANGED_KIND),
74910
- sessionId: identifierStringSchema,
74911
- status: sessionStatusSchema
74729
+ init_interactions();
74730
+ MAX_EVENT_COUNT = 1e4;
74731
+ MAX_COLLECTION_SIZE2 = 1e3;
74732
+ MAX_CONTENT_LENGTH2 = 1e6;
74733
+ SESSION_EVENT_KIND = "session.event.v2";
74734
+ SESSION_EVENT_BATCH_MAX_SIZE = 1e3;
74735
+ boundedString2 = external_exports.string().max(MAX_CONTENT_LENGTH2);
74736
+ shortString = external_exports.string().max(2048);
74737
+ externalContentKeySchema = external_exports.string().regex(/^[a-f0-9]{64}$/u);
74738
+ annotationsSchema = external_exports.object({
74739
+ audience: external_exports.array(external_exports.enum(["assistant", "user"])).max(2).readonly().nullable().optional(),
74740
+ lastModified: shortString.nullable().optional(),
74741
+ priority: external_exports.number().finite().nullable().optional()
74912
74742
  }).readonly();
74913
- sessionMetadataSchema = external_exports.object({
74914
- additionalDirectories: external_exports.array(workspaceEntrySchema).max(16).readonly(),
74915
- agentId: identifierStringSchema,
74916
- directoryId: DIRECTORY_IDENTIFIER,
74917
- directoryLabel: external_exports.string().min(1).max(MAX_WORKSPACE_PATH_LENGTH),
74918
- prompted: external_exports.boolean(),
74919
- sessionId: identifierStringSchema,
74920
- status: sessionStatusSchema.default({ kind: "idle" }),
74921
- title: external_exports.string().max(500),
74922
- updatedAt: external_exports.iso.datetime({ offset: true })
74743
+ contentFields = { annotations: annotationsSchema.nullable().optional() };
74744
+ textContentSchema = external_exports.object({ ...contentFields, text: boundedString2, type: external_exports.literal("text") }).readonly();
74745
+ imageContentSchema = external_exports.object({
74746
+ ...contentFields,
74747
+ data: external_exports.string(),
74748
+ mimeType: shortString,
74749
+ type: external_exports.literal("image"),
74750
+ uri: boundedString2.nullable().optional()
74923
74751
  }).readonly();
74924
- sessionListCommandSchema = external_exports.object({
74925
- kind: external_exports.literal(SESSION_LIST_KIND),
74926
- limit: external_exports.number().int().positive().max(500),
74927
- requestId: identifierStringSchema
74752
+ audioContentSchema = external_exports.object({ ...contentFields, data: external_exports.string(), mimeType: shortString, type: external_exports.literal("audio") }).readonly();
74753
+ externalImageContentSchema = external_exports.object({
74754
+ ...contentFields,
74755
+ byteLength: external_exports.number().int().positive().safe(),
74756
+ imageKey: externalContentKeySchema,
74757
+ mimeType: shortString,
74758
+ type: external_exports.literal("external_image"),
74759
+ uri: boundedString2.nullable().optional()
74928
74760
  }).readonly();
74929
- sessionsListedEventSchema = external_exports.object({
74930
- entries: external_exports.array(sessionMetadataSchema).max(500).readonly(),
74931
- kind: external_exports.literal(SESSION_LISTED_KIND),
74932
- requestId: identifierStringSchema
74761
+ externalAudioContentSchema = external_exports.object({
74762
+ ...contentFields,
74763
+ audioKey: externalContentKeySchema,
74764
+ byteLength: external_exports.number().int().positive().safe(),
74765
+ mimeType: shortString,
74766
+ type: external_exports.literal("external_audio")
74933
74767
  }).readonly();
74934
- sessionQueryCommandSchema = external_exports.object({
74935
- kind: external_exports.literal(SESSION_QUERY_KIND),
74936
- requestId: identifierStringSchema,
74937
- sessionIds: external_exports.array(identifierStringSchema).min(1).max(500).readonly()
74768
+ externalResourceContentSchema = external_exports.object({
74769
+ ...contentFields,
74770
+ byteLength: external_exports.number().int().positive().safe(),
74771
+ encoding: external_exports.enum(["binary", "text"]),
74772
+ mimeType: shortString.nullable().optional(),
74773
+ resourceKey: externalContentKeySchema,
74774
+ type: external_exports.literal("external_resource"),
74775
+ uri: boundedString2
74938
74776
  }).readonly();
74939
- sessionsQueriedEventSchema = external_exports.object({
74940
- entries: external_exports.array(sessionMetadataSchema).max(500).readonly(),
74941
- kind: external_exports.literal(SESSION_QUERIED_KIND),
74942
- requestId: identifierStringSchema
74777
+ resourceLinkSchema = external_exports.object({
74778
+ ...contentFields,
74779
+ description: boundedString2.nullable().optional(),
74780
+ mimeType: shortString.nullable().optional(),
74781
+ name: shortString,
74782
+ size: external_exports.number().int().nonnegative().safe().nullable().optional(),
74783
+ title: shortString.nullable().optional(),
74784
+ type: external_exports.literal("resource_link"),
74785
+ uri: boundedString2
74943
74786
  }).readonly();
74944
- sessionRestoreCommandSchema = external_exports.object({
74945
- kind: external_exports.literal(SESSION_RESTORE_KIND),
74946
- requestId: identifierStringSchema,
74947
- sessionId: identifierStringSchema
74787
+ textResourceSchema = external_exports.object({
74788
+ mimeType: shortString.nullable().optional(),
74789
+ text: boundedString2,
74790
+ uri: boundedString2
74948
74791
  }).readonly();
74949
- sessionCloseCommandSchema = external_exports.object({
74950
- kind: external_exports.literal(SESSION_CLOSE_KIND),
74951
- requestId: identifierStringSchema,
74952
- sessionId: identifierStringSchema
74792
+ blobResourceSchema = external_exports.object({
74793
+ blob: external_exports.string(),
74794
+ mimeType: shortString.nullable().optional(),
74795
+ uri: boundedString2
74953
74796
  }).readonly();
74954
- sessionPrepareCommandSchema = external_exports.object({
74955
- ...sessionIdentityFields,
74956
- configuration: external_exports.object({
74957
- booleanValue: external_exports.boolean(),
74958
- configId: external_exports.string().min(1).max(128),
74959
- value: external_exports.string().max(500),
74960
- valueType: external_exports.enum(["boolean", "select"])
74961
- }).readonly().optional(),
74962
- kind: external_exports.literal(SESSION_PREPARE_KIND),
74963
- requestId: identifierStringSchema,
74964
- sessionState: external_exports.literal("provisioned").optional(),
74965
- /** Marks an inspection-only Session preparation. */
74966
- transient: external_exports.boolean().optional()
74967
- }).superRefine((command, context) => {
74968
- if (command.transient === true && command.sessionState === "provisioned") {
74969
- context.addIssue({
74970
- code: "custom",
74971
- message: "A transient Session cannot already be provisioned",
74972
- path: ["sessionState"]
74973
- });
74974
- }
74797
+ embeddedResourceSchema = external_exports.object({
74798
+ ...contentFields,
74799
+ resource: external_exports.union([textResourceSchema, blobResourceSchema]),
74800
+ type: external_exports.literal("resource")
74975
74801
  }).readonly();
74976
- runtimeTimingsSchema = external_exports.array(
74802
+ contentBlockSchema = external_exports.discriminatedUnion("type", [
74803
+ textContentSchema,
74804
+ imageContentSchema,
74805
+ audioContentSchema,
74806
+ resourceLinkSchema,
74807
+ embeddedResourceSchema,
74808
+ externalImageContentSchema,
74809
+ externalAudioContentSchema,
74810
+ externalResourceContentSchema
74811
+ ]);
74812
+ toolCallContentSchema = external_exports.discriminatedUnion("type", [
74813
+ external_exports.object({ content: contentBlockSchema, type: external_exports.literal("content") }).readonly(),
74977
74814
  external_exports.object({
74978
- durationMilliseconds: external_exports.number().finite().nonnegative().max(12e4),
74979
- name: external_exports.string().regex(/^[a-z][a-z0-9-]{0,63}$/)
74980
- }).readonly()
74981
- ).max(16).readonly();
74982
- sessionReadyEventSchema = external_exports.object({
74983
- additionalDirectories: external_exports.array(workspaceEntrySchema).max(16).readonly(),
74984
- agentId: identifierStringSchema,
74985
- agentName: external_exports.string().max(255),
74986
- agentVersion: external_exports.string().max(128),
74987
- capabilities: sessionCapabilitiesSchema,
74988
- commands: external_exports.array(sessionCommandSchema).max(500).readonly(),
74989
- configOptions: sessionConfigOptionsSchema,
74990
- configurationRevision: identifierStringSchema.optional(),
74991
- directoryId: DIRECTORY_IDENTIFIER,
74992
- directoryLabel: external_exports.string().min(1).max(MAX_WORKSPACE_PATH_LENGTH),
74993
- kind: external_exports.literal(SESSION_READY_KIND),
74994
- requestId: identifierStringSchema,
74995
- restored: external_exports.boolean(),
74996
- runtimeTimings: runtimeTimingsSchema.optional(),
74997
- sessionId: identifierStringSchema
74815
+ newText: boundedString2,
74816
+ oldText: boundedString2.nullable().optional(),
74817
+ path: boundedString2,
74818
+ type: external_exports.literal("diff")
74819
+ }).readonly(),
74820
+ external_exports.object({ terminalId: shortString, type: external_exports.literal("terminal") }).readonly()
74821
+ ]);
74822
+ toolKindSchema = external_exports.enum([
74823
+ "read",
74824
+ "edit",
74825
+ "delete",
74826
+ "move",
74827
+ "search",
74828
+ "execute",
74829
+ "think",
74830
+ "fetch",
74831
+ "switch_mode",
74832
+ "other"
74833
+ ]);
74834
+ toolStatusSchema = external_exports.enum(["pending", "in_progress", "completed", "failed"]);
74835
+ backgroundTaskSchema = external_exports.object({
74836
+ id: shortString,
74837
+ status: external_exports.enum(["running", "completed", "failed", "stopped", "unknown"])
74998
74838
  }).readonly();
74999
- sessionRestoredEventSchema = external_exports.object({
75000
- entry: sessionMetadataSchema,
75001
- kind: external_exports.literal(SESSION_RESTORED_KIND),
75002
- ready: sessionReadyEventSchema,
75003
- requestId: identifierStringSchema
74839
+ toolPatchFields = {
74840
+ backgroundTask: backgroundTaskSchema.optional(),
74841
+ content: external_exports.array(toolCallContentSchema).max(MAX_COLLECTION_SIZE2).readonly().nullable().optional(),
74842
+ kind: toolKindSchema.nullable().optional(),
74843
+ locations: external_exports.array(toolCallLocationSchema).max(MAX_COLLECTION_SIZE2).readonly().nullable().optional(),
74844
+ name: shortString.nullable().optional(),
74845
+ rawInput: boundedJsonSchema.optional(),
74846
+ rawOutput: boundedJsonSchema.optional(),
74847
+ status: toolStatusSchema.nullable().optional(),
74848
+ title: boundedString2.nullable().optional()
74849
+ };
74850
+ planEntrySchema = external_exports.object({
74851
+ content: boundedString2,
74852
+ priority: external_exports.enum(["high", "medium", "low"]),
74853
+ status: external_exports.enum(["pending", "in_progress", "completed"])
75004
74854
  }).readonly();
75005
- sessionClosedEventSchema = external_exports.object({
75006
- kind: external_exports.literal(SESSION_CLOSED_KIND),
75007
- requestId: identifierStringSchema,
75008
- sessionId: identifierStringSchema
74855
+ planContentSchema = external_exports.discriminatedUnion("type", [
74856
+ external_exports.object({
74857
+ entries: external_exports.array(planEntrySchema).max(MAX_COLLECTION_SIZE2).readonly(),
74858
+ planId: shortString,
74859
+ type: external_exports.literal("items")
74860
+ }).readonly(),
74861
+ external_exports.object({ planId: shortString, type: external_exports.literal("file"), uri: boundedString2 }).readonly(),
74862
+ external_exports.object({
74863
+ content: boundedString2,
74864
+ planId: shortString,
74865
+ type: external_exports.literal("markdown")
74866
+ }).readonly()
74867
+ ]);
74868
+ commandSchema = external_exports.object({
74869
+ description: boundedString2,
74870
+ input: external_exports.object({ hint: boundedString2 }).readonly().nullable().optional(),
74871
+ name: shortString
75009
74872
  }).readonly();
75010
- sessionCloseNoticeEventSchema = external_exports.object({
75011
- kind: external_exports.literal(SESSION_CLOSE_NOTICE_KIND),
75012
- reason: external_exports.string().min(1).max(500),
75013
- sessionId: identifierStringSchema
74873
+ configSelectOptionSchema = external_exports.object({
74874
+ description: boundedString2.nullable().optional(),
74875
+ name: shortString,
74876
+ value: shortString
75014
74877
  }).readonly();
75015
- sessionCommandsUpdatedEventSchema = external_exports.object({
75016
- commands: external_exports.array(sessionCommandSchema).max(500).readonly(),
75017
- kind: external_exports.literal(SESSION_COMMANDS_UPDATED_KIND),
75018
- sessionId: identifierStringSchema
74878
+ configSelectGroupSchema = external_exports.object({
74879
+ group: shortString,
74880
+ name: shortString,
74881
+ options: external_exports.array(configSelectOptionSchema).max(MAX_COLLECTION_SIZE2).readonly()
74882
+ }).readonly();
74883
+ configBaseFields = {
74884
+ category: shortString.nullable().optional(),
74885
+ description: boundedString2.nullable().optional(),
74886
+ id: shortString,
74887
+ name: shortString
74888
+ };
74889
+ sessionConfigOptionSchema2 = external_exports.discriminatedUnion("type", [
74890
+ external_exports.object({
74891
+ ...configBaseFields,
74892
+ currentValue: shortString,
74893
+ options: external_exports.union([
74894
+ external_exports.array(configSelectOptionSchema).max(MAX_COLLECTION_SIZE2).readonly(),
74895
+ external_exports.array(configSelectGroupSchema).max(MAX_COLLECTION_SIZE2).readonly()
74896
+ ]),
74897
+ type: external_exports.literal("select")
74898
+ }).readonly(),
74899
+ external_exports.object({ ...configBaseFields, currentValue: external_exports.boolean(), type: external_exports.literal("boolean") }).readonly()
74900
+ ]);
74901
+ contentChunkFields = {
74902
+ content: contentBlockSchema,
74903
+ messageId: shortString.nullable().optional()
74904
+ };
74905
+ acpSessionUpdateSchema = external_exports.discriminatedUnion("sessionUpdate", [
74906
+ external_exports.object({ ...contentChunkFields, sessionUpdate: external_exports.literal("user_message_chunk") }).readonly(),
74907
+ external_exports.object({ ...contentChunkFields, sessionUpdate: external_exports.literal("agent_message_chunk") }).readonly(),
74908
+ external_exports.object({
74909
+ ...contentChunkFields,
74910
+ meta: external_exports.object({ truncated: external_exports.boolean().optional() }).readonly().optional(),
74911
+ sessionUpdate: external_exports.literal("agent_thought_chunk")
74912
+ }).readonly(),
74913
+ external_exports.object({
74914
+ backgroundTask: backgroundTaskSchema.optional(),
74915
+ content: external_exports.array(toolCallContentSchema).max(MAX_COLLECTION_SIZE2).readonly().optional(),
74916
+ kind: toolKindSchema.optional(),
74917
+ locations: external_exports.array(toolCallLocationSchema).max(MAX_COLLECTION_SIZE2).readonly().optional(),
74918
+ name: shortString.nullable().optional(),
74919
+ rawInput: boundedJsonSchema.optional(),
74920
+ rawOutput: boundedJsonSchema.optional(),
74921
+ sessionUpdate: external_exports.literal("tool_call"),
74922
+ status: toolStatusSchema.optional(),
74923
+ title: boundedString2,
74924
+ toolCallId: shortString
74925
+ }).readonly(),
74926
+ external_exports.object({ ...toolPatchFields, sessionUpdate: external_exports.literal("tool_call_update"), toolCallId: shortString }).readonly(),
74927
+ external_exports.object({
74928
+ entries: external_exports.array(planEntrySchema).max(MAX_COLLECTION_SIZE2).readonly(),
74929
+ sessionUpdate: external_exports.literal("plan")
74930
+ }).readonly(),
74931
+ external_exports.object({ plan: planContentSchema, sessionUpdate: external_exports.literal("plan_update") }).readonly(),
74932
+ external_exports.object({ planId: shortString, sessionUpdate: external_exports.literal("plan_removed") }).readonly(),
74933
+ external_exports.object({
74934
+ availableCommands: external_exports.array(commandSchema).max(MAX_COLLECTION_SIZE2).readonly(),
74935
+ sessionUpdate: external_exports.literal("available_commands_update")
74936
+ }).readonly(),
74937
+ external_exports.object({
74938
+ currentModeId: shortString,
74939
+ sessionUpdate: external_exports.literal("current_mode_update")
74940
+ }).readonly(),
74941
+ external_exports.object({
74942
+ configOptions: external_exports.array(sessionConfigOptionSchema2).max(MAX_COLLECTION_SIZE2).readonly(),
74943
+ sessionUpdate: external_exports.literal("config_option_update")
74944
+ }).readonly(),
74945
+ external_exports.object({
74946
+ sessionUpdate: external_exports.literal("session_info_update"),
74947
+ title: boundedString2.nullable().optional(),
74948
+ updatedAt: shortString.nullable().optional()
74949
+ }).readonly(),
74950
+ external_exports.object({
74951
+ cost: external_exports.object({ amount: external_exports.number().finite(), currency: external_exports.string().max(16) }).readonly().nullable().optional(),
74952
+ sessionUpdate: external_exports.literal("usage_update"),
74953
+ size: external_exports.number().int().nonnegative().safe(),
74954
+ used: external_exports.number().int().nonnegative().safe()
74955
+ }).readonly(),
74956
+ external_exports.object({
74957
+ compactionId: shortString,
74958
+ error: boundedString2.nullable().optional(),
74959
+ sessionUpdate: external_exports.literal("compaction_update"),
74960
+ status: shortString,
74961
+ summary: external_exports.array(contentBlockSchema).max(MAX_COLLECTION_SIZE2).readonly().nullable().optional()
74962
+ }).readonly(),
74963
+ external_exports.object({
74964
+ compactionId: shortString,
74965
+ content: contentBlockSchema,
74966
+ sessionUpdate: external_exports.literal("compaction_summary_chunk")
74967
+ }).readonly()
74968
+ ]);
74969
+ lifecycleBase = { commandId: identifierStringSchema };
74970
+ promptExecutionContextSchema = external_exports.object({
74971
+ agentId: identifierStringSchema,
74972
+ directoryId: DIRECTORY_IDENTIFIER,
74973
+ additionalDirectoryIds: external_exports.array(DIRECTORY_IDENTIFIER).max(16).readonly()
74974
+ }).readonly();
74975
+ lifecycleMetadataSchema = external_exports.discriminatedUnion("kind", [
74976
+ external_exports.object({ kind: external_exports.literal("session.queue.changed") }).readonly(),
74977
+ external_exports.object({ event: sessionPermissionRequestedEventSchema, kind: external_exports.literal("session.permission.requested") }).readonly(),
74978
+ external_exports.object({ event: sessionPermissionResolvedEventSchema, kind: external_exports.literal("session.permission.resolved") }).readonly(),
74979
+ external_exports.object({ event: sessionElicitationRequestedEventSchema, kind: external_exports.literal("session.elicitation.requested") }).readonly(),
74980
+ external_exports.object({ event: sessionElicitationResolvedEventSchema, kind: external_exports.literal("session.elicitation.resolved") }).readonly(),
74981
+ external_exports.object({
74982
+ ...lifecycleBase,
74983
+ content: external_exports.array(contentBlockSchema).min(1).max(100).readonly(),
74984
+ disposition: shortString.optional(),
74985
+ kind: external_exports.literal("prompt.requested"),
74986
+ context: promptExecutionContextSchema.optional(),
74987
+ targetCommandId: identifierStringSchema.optional()
74988
+ }).readonly(),
74989
+ external_exports.object({ ...lifecycleBase, attemptId: identifierStringSchema, epoch: identifierStringSchema, kind: external_exports.literal("prompt.started") }).readonly(),
74990
+ external_exports.object({
74991
+ ...lifecycleBase,
74992
+ kind: external_exports.literal("prompt.completed"),
74993
+ stopReason: shortString
74994
+ }).readonly(),
74995
+ external_exports.object({
74996
+ ...lifecycleBase,
74997
+ code: identifierStringSchema,
74998
+ kind: external_exports.literal("prompt.failed-before-start"),
74999
+ message: external_exports.string().min(1).max(500)
75000
+ }).readonly(),
75001
+ external_exports.object({
75002
+ ...lifecycleBase,
75003
+ attemptId: identifierStringSchema,
75004
+ code: identifierStringSchema,
75005
+ kind: external_exports.literal("prompt.failed"),
75006
+ message: external_exports.string().min(1).max(500)
75007
+ }).readonly()
75008
+ ]);
75009
+ sessionEventPayloadSchema = external_exports.discriminatedUnion("type", [
75010
+ external_exports.object({ payload: acpSessionUpdateSchema, type: external_exports.literal("acp") }).readonly(),
75011
+ external_exports.object({ payload: lifecycleMetadataSchema, type: external_exports.literal("lifecycle-metadata") }).readonly()
75012
+ ]);
75013
+ positionSchema = external_exports.string().regex(/^(0|[1-9][0-9]*)$/);
75014
+ sharedSessionEventFields = {
75015
+ eventId: identifierStringSchema,
75016
+ mobiusMetadata: external_exports.object({ omitted: external_exports.literal(true).optional() }).readonly().optional(),
75017
+ recordedAt: external_exports.iso.datetime({ offset: true }),
75018
+ sessionGenerationId: identifierStringSchema,
75019
+ sessionId: identifierStringSchema
75020
+ };
75021
+ sessionLiveEventFields = { ...sharedSessionEventFields, position: positionSchema };
75022
+ sessionEventSchema = external_exports.object({ ...sharedSessionEventFields, payload: acpSessionUpdateSchema, type: external_exports.literal("acp") }).readonly();
75023
+ sessionLiveEventSchema = external_exports.discriminatedUnion("type", [
75024
+ external_exports.object({ ...sessionLiveEventFields, payload: acpSessionUpdateSchema, type: external_exports.literal("acp") }).readonly(),
75025
+ external_exports.object({
75026
+ ...sessionLiveEventFields,
75027
+ payload: lifecycleMetadataSchema,
75028
+ type: external_exports.literal("lifecycle-metadata")
75029
+ }).readonly()
75030
+ ]);
75031
+ wireLifecyclePayloadSchema = external_exports.object({
75032
+ kind: identifierStringSchema,
75033
+ commandId: identifierStringSchema.optional(),
75034
+ context: promptExecutionContextSchema.unwrap().passthrough().readonly().optional(),
75035
+ event: external_exports.object({ interactionId: identifierStringSchema.optional() }).passthrough().readonly().optional()
75036
+ }).passthrough().readonly();
75037
+ wireEventFields = {
75038
+ ...sessionLiveEventFields,
75039
+ mobiusMetadata: external_exports.object({ omitted: external_exports.literal(true).optional() }).passthrough().readonly().optional()
75040
+ };
75041
+ sessionWireEventSchema = external_exports.union([
75042
+ external_exports.object({
75043
+ ...wireEventFields,
75044
+ type: external_exports.literal("acp"),
75045
+ payload: external_exports.object({ sessionUpdate: identifierStringSchema }).passthrough().readonly()
75046
+ }).passthrough().readonly(),
75047
+ external_exports.object({
75048
+ ...wireEventFields,
75049
+ type: external_exports.literal("lifecycle-metadata"),
75050
+ payload: wireLifecyclePayloadSchema
75051
+ }).passthrough().readonly(),
75052
+ external_exports.object({
75053
+ ...wireEventFields,
75054
+ type: identifierStringSchema.refine((type) => type !== "acp" && type !== "lifecycle-metadata"),
75055
+ payload: external_exports.record(external_exports.string(), external_exports.unknown()).readonly()
75056
+ }).passthrough().readonly()
75057
+ ]);
75058
+ sessionWireEnvelopeSchema = external_exports.object({
75059
+ kind: external_exports.literal(SESSION_EVENT_KIND),
75060
+ events: external_exports.array(sessionWireEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly()
75061
+ }).passthrough().readonly();
75062
+ sessionEventBatchSchema = external_exports.array(sessionEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly();
75063
+ sessionLiveEventBatchSchema = external_exports.array(sessionLiveEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly();
75064
+ sessionExportSchema = external_exports.object({
75065
+ binding: external_exports.object({
75066
+ bindingId: identifierStringSchema,
75067
+ runtimeId: identifierStringSchema
75068
+ }).readonly(),
75069
+ events: external_exports.array(sessionEventSchema).max(MAX_EVENT_COUNT).readonly(),
75070
+ sessionId: identifierStringSchema,
75071
+ truncated: external_exports.boolean()
75072
+ }).readonly().superRefine((session, context) => {
75073
+ const eventIds = /* @__PURE__ */ new Set();
75074
+ for (const [index2, event] of session.events.entries()) {
75075
+ if (event.sessionId !== session.sessionId) {
75076
+ context.addIssue({
75077
+ code: "custom",
75078
+ message: "Exported event belongs to a different Session",
75079
+ path: ["events", index2, "sessionId"]
75080
+ });
75081
+ }
75082
+ if (eventIds.has(event.eventId)) {
75083
+ context.addIssue({
75084
+ code: "custom",
75085
+ message: "Exported event identities are not unique",
75086
+ path: ["events", index2, "eventId"]
75087
+ });
75088
+ }
75089
+ eventIds.add(event.eventId);
75090
+ }
75091
+ });
75092
+ mobiusSessionExportSchema = external_exports.object({
75093
+ formatVersion: external_exports.literal("2"),
75094
+ session: sessionExportSchema
75095
+ }).readonly();
75096
+ sessionEventEnvelopeSchema = external_exports.object({ events: sessionLiveEventBatchSchema, kind: external_exports.literal(SESSION_EVENT_KIND) }).readonly();
75097
+ sessionEventLogPageSchema = external_exports.object({
75098
+ events: external_exports.array(sessionEventSchema).max(MAX_EVENT_COUNT).readonly(),
75099
+ nextCursor: external_exports.string().min(1).max(512).nullable(),
75100
+ sessionGenerationId: identifierStringSchema,
75101
+ tailCursor: external_exports.string().max(512),
75102
+ // The generation-scoped live position covered by this snapshot, including
75103
+ // coalesced and omitted events. Absent only on older Runtime versions.
75104
+ throughPosition: positionSchema.optional(),
75105
+ truncated: external_exports.boolean(),
75106
+ version: external_exports.literal(2)
75107
+ }).readonly();
75108
+ sessionEventOmissionSchema = external_exports.literal("agent-reasoning");
75109
+ nativeEventPageRequestSchema = external_exports.object({
75110
+ cursor: external_exports.string().min(1).max(512).nullable(),
75111
+ eventLimit: external_exports.number().int().min(1).max(1e4),
75112
+ // Legacy callers may still send this option; readers must ignore it.
75113
+ omit: external_exports.array(sessionEventOmissionSchema).max(1).readonly().optional()
75114
+ }).readonly();
75115
+ queuedPromptRequestEventLogSchema = external_exports.object({
75116
+ commandId: identifierStringSchema,
75117
+ content: external_exports.array(contentBlockSchema).min(1).max(100).readonly(),
75118
+ disposition: shortString.optional(),
75119
+ targetCommandId: identifierStringSchema.optional()
75120
+ }).readonly();
75121
+ nativeSessionEventsSchema = external_exports.object({
75122
+ events: sessionEventLogPageSchema,
75123
+ queuedPromptRequests: external_exports.array(queuedPromptRequestEventLogSchema).max(MAX_COLLECTION_SIZE2).readonly()
75124
+ }).readonly();
75125
+ knownSessionLiveEventBatchSchema = external_exports.array(sessionLiveEventSchema).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly();
75126
+ decodeSessionEvent = (value) => decode3(value, sessionEventSchema);
75127
+ decodeKnownSessionEventPayload = (value) => {
75128
+ const decoded = sessionEventPayloadSchema.safeParse(inputValue(value));
75129
+ return decoded.success ? decoded.data : null;
75130
+ };
75131
+ decodeSessionEventEnvelope = (value) => decode3(value, sessionEventEnvelopeSchema);
75132
+ encodeSessionEventEnvelope = (value) => encode3(value, sessionEventEnvelopeSchema);
75133
+ decodeAcpSessionUpdate = (value) => decode3(value, acpSessionUpdateSchema);
75134
+ decodeKnownNativeSessionEvents = (value) => decode3(sanitizeConsumableNativeSessionEvents(value), nativeSessionEventsSchema);
75135
+ }
75136
+ });
75137
+
75138
+ // ../mobius-sdk/src/protocol/session/files/index.ts
75139
+ function binaryBytes(value) {
75140
+ if (value instanceof ArrayBuffer) {
75141
+ return new Uint8Array(value);
75142
+ }
75143
+ if (ArrayBuffer.isView(value)) {
75144
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
75145
+ }
75146
+ throw new Error("Content chunk must be a binary WebSocket frame");
75147
+ }
75148
+ function encodeContentChunkFrame(frame) {
75149
+ if (!isIdentifier(frame.requestId)) {
75150
+ throw new Error("Content chunk request identifier is invalid");
75151
+ }
75152
+ if (!Number.isSafeInteger(frame.sequence) || frame.sequence < 0 || frame.sequence > 4294967295) {
75153
+ throw new Error("Content chunk sequence is invalid");
75154
+ }
75155
+ if (frame.bytes.byteLength < 1 || frame.bytes.byteLength > CONTENT_CHUNK_MAX_BYTES) {
75156
+ throw new Error("Content chunk size is invalid");
75157
+ }
75158
+ const requestId = new TextEncoder().encode(frame.requestId);
75159
+ if (requestId.byteLength > 255) {
75160
+ throw new Error("Content chunk request identifier is too long");
75161
+ }
75162
+ const encoded = new Uint8Array(CONTENT_CHUNK_HEADER_BYTES + requestId.byteLength + frame.bytes.byteLength);
75163
+ encoded.set(CONTENT_CHUNK_MAGIC, 0);
75164
+ encoded[CONTENT_CHUNK_MAGIC.byteLength] = requestId.byteLength;
75165
+ new DataView(encoded.buffer).setUint32(CONTENT_CHUNK_MAGIC.byteLength + 1, frame.sequence);
75166
+ encoded.set(requestId, CONTENT_CHUNK_HEADER_BYTES);
75167
+ encoded.set(frame.bytes, CONTENT_CHUNK_HEADER_BYTES + requestId.byteLength);
75168
+ return encoded;
75169
+ }
75170
+ function decodeContentChunkFrame(value) {
75171
+ const encoded = binaryBytes(value);
75172
+ if (encoded.byteLength <= CONTENT_CHUNK_HEADER_BYTES || !CONTENT_CHUNK_MAGIC.every((byte, index2) => encoded[index2] === byte)) {
75173
+ throw new Error("Content chunk frame header is invalid");
75174
+ }
75175
+ const requestIdLength = encoded[CONTENT_CHUNK_MAGIC.byteLength] ?? 0;
75176
+ const payloadOffset = CONTENT_CHUNK_HEADER_BYTES + requestIdLength;
75177
+ if (requestIdLength < 1 || payloadOffset >= encoded.byteLength) {
75178
+ throw new Error("Content chunk frame length is invalid");
75179
+ }
75180
+ const requestId = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(
75181
+ encoded.subarray(CONTENT_CHUNK_HEADER_BYTES, payloadOffset)
75182
+ );
75183
+ const bytes = encoded.slice(payloadOffset);
75184
+ const sequence = new DataView(encoded.buffer, encoded.byteOffset, encoded.byteLength).getUint32(
75185
+ CONTENT_CHUNK_MAGIC.byteLength + 1
75186
+ );
75187
+ if (!isIdentifier(requestId) || bytes.byteLength > CONTENT_CHUNK_MAX_BYTES) {
75188
+ throw new Error("Content chunk frame is invalid");
75189
+ }
75190
+ return { bytes, requestId, sequence };
75191
+ }
75192
+ var FILE_READ_KIND, FILE_BEGIN_KIND, FILE_END_KIND, FILE_FAILED_KIND, CONTENT_WRITE_KIND, CONTENT_COMMIT_KIND, CONTENT_READY_KIND, CONTENT_AVAILABLE_KIND, CONTENT_CHUNK_MAX_BYTES, CONTENT_WRITE_MAX_BYTES, PROMPT_IMAGE_MAX_BYTES, CONTENT_CHUNK_MAGIC, CONTENT_CHUNK_HEADER_BYTES, fileReadCommandSchema, fileBeginEventSchema, contentWriteCommandSchema, contentCommitCommandSchema, contentReadyEventSchema, contentAvailableEventSchema, fileEndEventSchema, fileFailedEventSchema, decodeFileReadCommand, encodeFileReadCommand, decodeFileBeginEvent, encodeFileBeginEvent, decodeFileEndEvent, encodeFileEndEvent, decodeFileFailedEvent, encodeFileFailedEvent, decodeContentWriteCommand, encodeContentWriteCommand, decodeContentCommitCommand, encodeContentCommitCommand, decodeContentReadyEvent, encodeContentReadyEvent, decodeContentAvailableEvent, encodeContentAvailableEvent;
75193
+ var init_files = __esm({
75194
+ "../mobius-sdk/src/protocol/session/files/index.ts"() {
75195
+ "use strict";
75196
+ init_zod();
75197
+ init_identifier();
75198
+ init_message_codec();
75199
+ FILE_READ_KIND = "file.read";
75200
+ FILE_BEGIN_KIND = "file.begin";
75201
+ FILE_END_KIND = "file.end";
75202
+ FILE_FAILED_KIND = "file.failed";
75203
+ CONTENT_WRITE_KIND = "content.write";
75204
+ CONTENT_COMMIT_KIND = "content.commit";
75205
+ CONTENT_READY_KIND = "content.ready";
75206
+ CONTENT_AVAILABLE_KIND = "content.available";
75207
+ CONTENT_CHUNK_MAX_BYTES = 192 * 1024;
75208
+ CONTENT_WRITE_MAX_BYTES = 32 * 1024 * 1024;
75209
+ PROMPT_IMAGE_MAX_BYTES = 5e6;
75210
+ CONTENT_CHUNK_MAGIC = new Uint8Array([77, 66, 67, 49]);
75211
+ CONTENT_CHUNK_HEADER_BYTES = CONTENT_CHUNK_MAGIC.byteLength + 1 + 4;
75212
+ fileReadCommandSchema = external_exports.object({
75213
+ kind: external_exports.literal(FILE_READ_KIND),
75214
+ maxBytes: external_exports.number().int().positive().max(128 * 1024 * 1024),
75215
+ requestId: identifierStringSchema,
75216
+ sessionId: identifierStringSchema,
75217
+ path: external_exports.string().min(1).max(4096)
75218
+ }).readonly();
75219
+ fileBeginEventSchema = external_exports.object({
75220
+ byteLength: external_exports.number().int().positive().max(128 * 1024 * 1024),
75221
+ kind: external_exports.literal(FILE_BEGIN_KIND),
75222
+ mediaType: external_exports.string().min(1).max(255),
75223
+ modifiedAt: external_exports.iso.datetime({ offset: true }),
75224
+ name: external_exports.string().min(1).max(500),
75225
+ requestId: identifierStringSchema,
75226
+ sessionId: identifierStringSchema
75227
+ }).readonly();
75228
+ contentWriteCommandSchema = external_exports.object({
75229
+ byteLength: external_exports.number().int().positive().max(CONTENT_WRITE_MAX_BYTES),
75230
+ contentKey: external_exports.string().regex(/^[a-f0-9]{64}$/u),
75231
+ contentKind: external_exports.enum(["image", "resource"]),
75232
+ kind: external_exports.literal(CONTENT_WRITE_KIND),
75233
+ mediaType: external_exports.string().min(1).max(255),
75234
+ name: external_exports.string().min(1).max(500),
75235
+ requestId: identifierStringSchema,
75236
+ sessionId: identifierStringSchema
75237
+ }).readonly();
75238
+ contentCommitCommandSchema = external_exports.object({
75239
+ kind: external_exports.literal(CONTENT_COMMIT_KIND),
75240
+ requestId: identifierStringSchema,
75241
+ sessionId: identifierStringSchema
75242
+ }).readonly();
75243
+ contentReadyEventSchema = external_exports.object({
75244
+ kind: external_exports.literal(CONTENT_READY_KIND),
75245
+ requestId: identifierStringSchema,
75246
+ sessionId: identifierStringSchema
75247
+ }).readonly();
75248
+ contentAvailableEventSchema = external_exports.object({
75249
+ byteLength: external_exports.number().int().positive().max(CONTENT_WRITE_MAX_BYTES),
75250
+ contentKey: external_exports.string().regex(/^[a-f0-9]{64}$/u),
75251
+ kind: external_exports.literal(CONTENT_AVAILABLE_KIND),
75252
+ requestId: identifierStringSchema,
75253
+ sessionId: identifierStringSchema
75254
+ }).readonly();
75255
+ fileEndEventSchema = external_exports.object({
75256
+ kind: external_exports.literal(FILE_END_KIND),
75257
+ requestId: identifierStringSchema,
75258
+ sessionId: identifierStringSchema
75259
+ }).readonly();
75260
+ fileFailedEventSchema = external_exports.object({
75261
+ code: identifierStringSchema,
75262
+ kind: external_exports.literal(FILE_FAILED_KIND),
75263
+ message: external_exports.string().min(1).max(500),
75264
+ requestId: identifierStringSchema,
75265
+ sessionId: identifierStringSchema
75266
+ }).readonly();
75267
+ decodeFileReadCommand = (encoded) => decodeZodMessage(encoded, fileReadCommandSchema);
75268
+ encodeFileReadCommand = (message) => encodeZodMessage(message, fileReadCommandSchema);
75269
+ decodeFileBeginEvent = (encoded) => decodeZodMessage(encoded, fileBeginEventSchema);
75270
+ encodeFileBeginEvent = (message) => encodeZodMessage(message, fileBeginEventSchema);
75271
+ decodeFileEndEvent = (encoded) => decodeZodMessage(encoded, fileEndEventSchema);
75272
+ encodeFileEndEvent = (message) => encodeZodMessage(message, fileEndEventSchema);
75273
+ decodeFileFailedEvent = (encoded) => decodeZodMessage(encoded, fileFailedEventSchema);
75274
+ encodeFileFailedEvent = (message) => encodeZodMessage(message, fileFailedEventSchema);
75275
+ decodeContentWriteCommand = (encoded) => decodeZodMessage(encoded, contentWriteCommandSchema);
75276
+ encodeContentWriteCommand = (message) => encodeZodMessage(message, contentWriteCommandSchema);
75277
+ decodeContentCommitCommand = (encoded) => decodeZodMessage(encoded, contentCommitCommandSchema);
75278
+ encodeContentCommitCommand = (message) => encodeZodMessage(message, contentCommitCommandSchema);
75279
+ decodeContentReadyEvent = (encoded) => decodeZodMessage(encoded, contentReadyEventSchema);
75280
+ encodeContentReadyEvent = (message) => encodeZodMessage(message, contentReadyEventSchema);
75281
+ decodeContentAvailableEvent = (encoded) => decodeZodMessage(encoded, contentAvailableEventSchema);
75282
+ encodeContentAvailableEvent = (message) => encodeZodMessage(message, contentAvailableEventSchema);
75283
+ }
75284
+ });
75285
+
75286
+ // ../mobius-sdk/src/protocol/session/interactions/model.ts
75287
+ var timestampSchema, permissionRequestSchema, elicitationRequestSchema, interactionRequestSchema, interactionResponseSchema, interactionStateSchema, interactionSchema;
75288
+ var init_model = __esm({
75289
+ "../mobius-sdk/src/protocol/session/interactions/model.ts"() {
75290
+ "use strict";
75291
+ init_zod();
75292
+ init_identifier();
75293
+ init_interactions();
75294
+ timestampSchema = external_exports.string().datetime({ offset: true });
75295
+ permissionRequestSchema = external_exports.object({
75296
+ kind: external_exports.literal("permission"),
75297
+ options: external_exports.array(permissionOptionSchema).min(1).max(20).readonly(),
75298
+ title: external_exports.string().min(1).max(500),
75299
+ toolCallId: external_exports.string().min(1).max(255),
75300
+ toolKind: external_exports.string().max(64)
75301
+ }).readonly();
75302
+ elicitationRequestSchema = external_exports.object({
75303
+ elicitationId: external_exports.string().max(255),
75304
+ fields: external_exports.array(elicitationFieldSchema).max(100).readonly(),
75305
+ kind: external_exports.literal("elicitation"),
75306
+ message: external_exports.string().min(1).max(2e3),
75307
+ mode: external_exports.enum(["form", "url"]),
75308
+ url: external_exports.string().max(4096)
75309
+ }).readonly();
75310
+ interactionRequestSchema = external_exports.discriminatedUnion("kind", [permissionRequestSchema, elicitationRequestSchema]);
75311
+ interactionResponseSchema = external_exports.object({
75312
+ content: external_exports.string().max(1e5),
75313
+ kind: external_exports.enum(["permission", "elicitation"])
75314
+ }).readonly();
75315
+ interactionStateSchema = external_exports.discriminatedUnion("kind", [
75316
+ external_exports.object({ kind: external_exports.literal("pending") }).readonly(),
75317
+ external_exports.object({
75318
+ kind: external_exports.literal("responded"),
75319
+ respondedAt: timestampSchema,
75320
+ responderId: identifierSchema,
75321
+ response: interactionResponseSchema
75322
+ }).readonly(),
75323
+ external_exports.object({
75324
+ kind: external_exports.literal("resolved"),
75325
+ resolution: external_exports.discriminatedUnion("kind", [
75326
+ external_exports.object({ kind: external_exports.literal("without_response") }).readonly(),
75327
+ external_exports.object({
75328
+ kind: external_exports.literal("response_applied"),
75329
+ respondedAt: timestampSchema,
75330
+ responderId: identifierSchema,
75331
+ response: interactionResponseSchema
75332
+ }).readonly()
75333
+ ]),
75334
+ resolvedAt: timestampSchema
75335
+ }).readonly(),
75336
+ external_exports.object({ expiredAt: timestampSchema, kind: external_exports.literal("expired") }).readonly(),
75337
+ external_exports.object({
75338
+ cancelledAt: timestampSchema,
75339
+ kind: external_exports.literal("cancelled")
75340
+ }).readonly()
75341
+ ]);
75342
+ interactionSchema = external_exports.object({
75343
+ attemptId: identifierSchema,
75344
+ interactionId: identifierSchema,
75345
+ request: interactionRequestSchema,
75346
+ sessionId: identifierSchema,
75347
+ state: interactionStateSchema,
75348
+ turnId: identifierSchema
75349
+ }).readonly();
75350
+ }
75351
+ });
75352
+
75353
+ // ../mobius-sdk/src/protocol/session/lifecycle/index.ts
75354
+ var SESSION_PREPARE_KIND, SESSION_READY_KIND, SESSION_LIST_KIND, SESSION_LISTED_KIND, SESSION_QUERY_KIND, SESSION_QUERIED_KIND, SESSION_RESTORE_KIND, SESSION_RESTORED_KIND, SESSION_CLOSE_KIND, SESSION_CLOSED_KIND, SESSION_CLOSE_NOTICE_KIND, SESSION_CLOSED_ERROR_CODE, SESSION_STATUS_CHANGED_KIND, SESSION_COMMANDS_UPDATED_KIND, SESSION_INFO_UPDATED_KIND, SESSION_OPERATION_FAILED_KIND, sessionStatusChangedEventSchema, sessionMetadataSchema, sessionListCommandSchema, sessionsListedEventSchema, sessionQueryCommandSchema, sessionsQueriedEventSchema, sessionRestoreCommandSchema, sessionCloseCommandSchema, sessionPrepareCommandSchema, runtimeTimingsSchema, sessionReadyEventSchema, sessionRestoredEventSchema, sessionClosedEventSchema, sessionCloseNoticeEventSchema, sessionCommandsUpdatedEventSchema, sessionInfoUpdatedEventSchema, sessionOperationFailedEventSchema, decodeSessionListCommand, encodeSessionListCommand, decodeSessionsListedEvent, encodeSessionsListedEvent, decodeSessionQueryCommand, encodeSessionQueryCommand, decodeSessionsQueriedEvent, encodeSessionsQueriedEvent, decodeSessionRestoreCommand, encodeSessionRestoreCommand, decodeSessionRestoredEvent, encodeSessionRestoredEvent, decodeSessionCloseCommand, encodeSessionCloseCommand, decodeSessionClosedEvent, encodeSessionClosedEvent, decodeSessionCloseNoticeEvent, encodeSessionCloseNoticeEvent, decodeSessionStatusChangedEvent, encodeSessionStatusChangedEvent, decodeSessionPrepareCommand, encodeSessionPrepareCommand, decodeSessionReadyEvent, encodeSessionReadyEvent, decodeSessionInfoUpdatedEvent, encodeSessionInfoUpdatedEvent, decodeSessionOperationFailedEvent, encodeSessionOperationFailedEvent;
75355
+ var init_lifecycle = __esm({
75356
+ "../mobius-sdk/src/protocol/session/lifecycle/index.ts"() {
75357
+ "use strict";
75358
+ init_zod();
75359
+ init_directory();
75360
+ init_identifier();
75361
+ init_message_codec();
75362
+ init_configuration();
75363
+ init_shared2();
75364
+ SESSION_PREPARE_KIND = "session.prepare";
75365
+ SESSION_READY_KIND = "session.ready";
75366
+ SESSION_LIST_KIND = "session.list";
75367
+ SESSION_LISTED_KIND = "session.listed";
75368
+ SESSION_QUERY_KIND = "session.query";
75369
+ SESSION_QUERIED_KIND = "session.queried";
75370
+ SESSION_RESTORE_KIND = "session.restore";
75371
+ SESSION_RESTORED_KIND = "session.restored";
75372
+ SESSION_CLOSE_KIND = "session.close";
75373
+ SESSION_CLOSED_KIND = "session.closed";
75374
+ SESSION_CLOSE_NOTICE_KIND = "session.close.notice";
75375
+ SESSION_CLOSED_ERROR_CODE = "session_closed";
75376
+ SESSION_STATUS_CHANGED_KIND = "session.status.changed";
75377
+ SESSION_COMMANDS_UPDATED_KIND = "session.commands.updated";
75378
+ SESSION_INFO_UPDATED_KIND = "session.info.updated";
75379
+ SESSION_OPERATION_FAILED_KIND = "session.operation.failed";
75380
+ sessionStatusChangedEventSchema = external_exports.object({
75381
+ kind: external_exports.literal(SESSION_STATUS_CHANGED_KIND),
75382
+ sessionId: identifierStringSchema,
75383
+ status: sessionStatusSchema
75384
+ }).readonly();
75385
+ sessionMetadataSchema = external_exports.object({
75386
+ additionalDirectories: external_exports.array(workspaceEntrySchema).max(16).readonly(),
75387
+ agentId: identifierStringSchema,
75388
+ directoryId: DIRECTORY_IDENTIFIER,
75389
+ directoryLabel: external_exports.string().min(1).max(MAX_WORKSPACE_PATH_LENGTH),
75390
+ prompted: external_exports.boolean(),
75391
+ sessionId: identifierStringSchema,
75392
+ status: sessionStatusSchema.default({ kind: "idle" }),
75393
+ title: external_exports.string().max(500),
75394
+ updatedAt: external_exports.iso.datetime({ offset: true })
75395
+ }).readonly();
75396
+ sessionListCommandSchema = external_exports.object({
75397
+ kind: external_exports.literal(SESSION_LIST_KIND),
75398
+ limit: external_exports.number().int().positive().max(500),
75399
+ requestId: identifierStringSchema
75400
+ }).readonly();
75401
+ sessionsListedEventSchema = external_exports.object({
75402
+ entries: external_exports.array(sessionMetadataSchema).max(500).readonly(),
75403
+ kind: external_exports.literal(SESSION_LISTED_KIND),
75404
+ requestId: identifierStringSchema
75405
+ }).readonly();
75406
+ sessionQueryCommandSchema = external_exports.object({
75407
+ kind: external_exports.literal(SESSION_QUERY_KIND),
75408
+ requestId: identifierStringSchema,
75409
+ sessionIds: external_exports.array(identifierStringSchema).min(1).max(500).readonly()
75410
+ }).readonly();
75411
+ sessionsQueriedEventSchema = external_exports.object({
75412
+ entries: external_exports.array(sessionMetadataSchema).max(500).readonly(),
75413
+ kind: external_exports.literal(SESSION_QUERIED_KIND),
75414
+ requestId: identifierStringSchema
75415
+ }).readonly();
75416
+ sessionRestoreCommandSchema = external_exports.object({
75417
+ kind: external_exports.literal(SESSION_RESTORE_KIND),
75418
+ requestId: identifierStringSchema,
75419
+ sessionId: identifierStringSchema
75420
+ }).readonly();
75421
+ sessionCloseCommandSchema = external_exports.object({
75422
+ kind: external_exports.literal(SESSION_CLOSE_KIND),
75423
+ requestId: identifierStringSchema,
75424
+ sessionId: identifierStringSchema
75425
+ }).readonly();
75426
+ sessionPrepareCommandSchema = external_exports.object({
75427
+ ...sessionIdentityFields,
75428
+ configuration: external_exports.object({
75429
+ booleanValue: external_exports.boolean(),
75430
+ configId: external_exports.string().min(1).max(128),
75431
+ value: external_exports.string().max(500),
75432
+ valueType: external_exports.enum(["boolean", "select"])
75433
+ }).readonly().optional(),
75434
+ kind: external_exports.literal(SESSION_PREPARE_KIND),
75435
+ requestId: identifierStringSchema,
75436
+ sessionState: external_exports.literal("provisioned").optional(),
75437
+ /** Marks an inspection-only Session preparation. */
75438
+ transient: external_exports.boolean().optional()
75439
+ }).superRefine((command, context) => {
75440
+ if (command.transient === true && command.sessionState === "provisioned") {
75441
+ context.addIssue({
75442
+ code: "custom",
75443
+ message: "A transient Session cannot already be provisioned",
75444
+ path: ["sessionState"]
75445
+ });
75446
+ }
75447
+ }).readonly();
75448
+ runtimeTimingsSchema = external_exports.array(
75449
+ external_exports.object({
75450
+ durationMilliseconds: external_exports.number().finite().nonnegative().max(12e4),
75451
+ name: external_exports.string().regex(/^[a-z][a-z0-9-]{0,63}$/)
75452
+ }).readonly()
75453
+ ).max(16).readonly();
75454
+ sessionReadyEventSchema = external_exports.object({
75455
+ additionalDirectories: external_exports.array(workspaceEntrySchema).max(16).readonly(),
75456
+ agentId: identifierStringSchema,
75457
+ agentName: external_exports.string().max(255),
75458
+ agentVersion: external_exports.string().max(128),
75459
+ capabilities: sessionCapabilitiesSchema,
75460
+ commands: external_exports.array(sessionCommandSchema).max(500).readonly(),
75461
+ configOptions: sessionConfigOptionsSchema,
75462
+ configurationRevision: identifierStringSchema.optional(),
75463
+ directoryId: DIRECTORY_IDENTIFIER,
75464
+ directoryLabel: external_exports.string().min(1).max(MAX_WORKSPACE_PATH_LENGTH),
75465
+ kind: external_exports.literal(SESSION_READY_KIND),
75466
+ requestId: identifierStringSchema,
75467
+ restored: external_exports.boolean(),
75468
+ runtimeTimings: runtimeTimingsSchema.optional(),
75469
+ sessionId: identifierStringSchema
75470
+ }).readonly();
75471
+ sessionRestoredEventSchema = external_exports.object({
75472
+ entry: sessionMetadataSchema,
75473
+ kind: external_exports.literal(SESSION_RESTORED_KIND),
75474
+ ready: sessionReadyEventSchema,
75475
+ requestId: identifierStringSchema
75476
+ }).readonly();
75477
+ sessionClosedEventSchema = external_exports.object({
75478
+ kind: external_exports.literal(SESSION_CLOSED_KIND),
75479
+ requestId: identifierStringSchema,
75480
+ sessionId: identifierStringSchema
75481
+ }).readonly();
75482
+ sessionCloseNoticeEventSchema = external_exports.object({
75483
+ kind: external_exports.literal(SESSION_CLOSE_NOTICE_KIND),
75484
+ reason: external_exports.string().min(1).max(500),
75485
+ sessionId: identifierStringSchema
75486
+ }).readonly();
75487
+ sessionCommandsUpdatedEventSchema = external_exports.object({
75488
+ commands: external_exports.array(sessionCommandSchema).max(500).readonly(),
75489
+ kind: external_exports.literal(SESSION_COMMANDS_UPDATED_KIND),
75490
+ sessionId: identifierStringSchema
75019
75491
  }).readonly();
75020
75492
  sessionInfoUpdatedEventSchema = external_exports.object({
75021
75493
  kind: external_exports.literal(SESSION_INFO_UPDATED_KIND),
@@ -75124,795 +75596,219 @@ function decodeSessionPromptCommand(encoded) {
75124
75596
  prompt,
75125
75597
  ...hasSessionConfigurations ? { sessionConfigurations } : {},
75126
75598
  sessionId: readIdentifier(value, "sessionId"),
75127
- targetCommandId
75128
- };
75129
- }
75130
- function readHistoryPolicy(value) {
75131
- const field = value["historyPolicy"];
75132
- if (field === SessionHistoryPolicy.Eager || field === SessionHistoryPolicy.ExecutionOnly) {
75133
- return field;
75134
- }
75135
- throw new ProtocolMessageError("Invalid value field: historyPolicy");
75136
- }
75137
- function decodeSessionCancelCommand(encoded) {
75138
- const value = parseJson(encoded);
75139
- assertKind(value, SESSION_CANCEL_KIND);
75140
- return {
75141
- commandId: readIdentifier(value, "commandId"),
75142
- kind: SESSION_CANCEL_KIND,
75143
- sessionId: readIdentifier(value, "sessionId")
75144
- };
75145
- }
75146
- function decodeSessionPromptDispositionCommand(encoded) {
75147
- const value = parseJson(encoded);
75148
- assertKind(value, SESSION_PROMPT_DISPOSITION_KIND);
75149
- if (readPromptDisposition(value) !== SessionPromptDisposition.Steer) {
75150
- throw new ProtocolMessageError("Only queued prompts can be steered");
75151
- }
75152
- return {
75153
- commandId: readIdentifier(value, "commandId"),
75154
- disposition: SessionPromptDisposition.Steer,
75155
- kind: SESSION_PROMPT_DISPOSITION_KIND,
75156
- sessionId: readIdentifier(value, "sessionId")
75157
- };
75158
- }
75159
- function encodeSessionPromptCommand(message) {
75160
- const command = decodeSessionPromptCommand(JSON.stringify(message));
75161
- return JSON.stringify({
75162
- ...command,
75163
- // Keep text prompts compatible with the previous Runtime release while
75164
- // attachments move to the content-key protocol. Older Runtimes ignore
75165
- // `attachments` and require both legacy arrays to be present.
75166
- images: [],
75167
- resources: []
75168
- });
75169
- }
75170
- function encodeSessionCancelCommand(message) {
75171
- return JSON.stringify(decodeSessionCancelCommand(JSON.stringify(message)));
75172
- }
75173
- function encodeSessionPromptDispositionCommand(message) {
75174
- return JSON.stringify(decodeSessionPromptDispositionCommand(JSON.stringify(message)));
75175
- }
75176
- var SESSION_PROMPT_KIND, SESSION_PROMPT_DISPOSITION_KIND, SESSION_CANCEL_KIND, SESSION_CANCEL_BEFORE_START_KIND, SessionPromptDisposition, SessionHistoryPolicy, MAX_PROMPT_LENGTH, MAX_PROMPT_ATTACHMENT_BYTES, encodeSessionCancelBeforeStartCommand, promptAttachmentSchema, decodePromptAttachmentsValue;
75177
- var init_commands = __esm({
75178
- "../mobius-sdk/src/protocol/session/prompt/commands.ts"() {
75179
- "use strict";
75180
- init_zod();
75181
- init_identifier();
75182
- init_message_codec();
75183
- init_configuration();
75184
- SESSION_PROMPT_KIND = "session.prompt";
75185
- SESSION_PROMPT_DISPOSITION_KIND = "session.prompt.disposition";
75186
- SESSION_CANCEL_KIND = "session.cancel";
75187
- SESSION_CANCEL_BEFORE_START_KIND = "session.cancel-before-start";
75188
- SessionPromptDisposition = Object.freeze({
75189
- Queue: "queue",
75190
- Reject: "reject",
75191
- Steer: "steer"
75192
- });
75193
- SessionHistoryPolicy = Object.freeze({
75194
- Eager: "eager",
75195
- ExecutionOnly: "execution-only"
75196
- });
75197
- MAX_PROMPT_LENGTH = 1e5;
75198
- MAX_PROMPT_ATTACHMENT_BYTES = 32 * 1024 * 1024;
75199
- encodeSessionCancelBeforeStartCommand = (message) => JSON.stringify(decodeSessionCancelBeforeStartCommand(JSON.stringify(message)));
75200
- promptAttachmentSchema = external_exports.object({
75201
- byteLength: external_exports.number().int().positive().max(MAX_PROMPT_ATTACHMENT_BYTES),
75202
- contentKey: external_exports.string().regex(/^[a-f0-9]{64}$/u),
75203
- kind: external_exports.enum(["image", "resource"]),
75204
- mimeType: external_exports.string().min(1).max(255),
75205
- name: external_exports.string().min(1).max(500),
75206
- uri: external_exports.string().min(1).max(4096)
75207
- }).readonly();
75208
- decodePromptAttachmentsValue = (value) => decodeZodValue(value, external_exports.array(promptAttachmentSchema).max(16).readonly());
75209
- }
75210
- });
75211
-
75212
- // ../mobius-sdk/src/protocol/session/native/index.ts
75213
- function decode3(schema, encoded) {
75214
- try {
75215
- const value = JSON.parse(encoded);
75216
- return schema.parse(value);
75217
- } catch (cause) {
75218
- throw new ProtocolMessageError("Invalid native session message", { cause });
75219
- }
75220
- }
75221
- var NATIVE_SESSION_REQUEST_KIND, NATIVE_SESSION_RESULT_KIND, NATIVE_SESSION_CANCEL_KIND, envelope, activeTurnSnapshotSchema, identity, nativeSessionRequestSchema, nativeSessionCommandSchema, nativeSessionEntrySchema, resultEnvelope, nativeSessionResultSchema, nativeSessionCancelSchema, decodeNativeSessionCommand, encodeNativeSessionCommand, decodeNativeSessionResult, encodeNativeSessionResult, decodeNativeSessionCancel, encodeNativeSessionCancel;
75222
- var init_native = __esm({
75223
- "../mobius-sdk/src/protocol/session/native/index.ts"() {
75224
- "use strict";
75225
- init_zod();
75226
- init_directory();
75227
- init_identifier();
75228
- init_message_codec();
75229
- init_interactions();
75230
- init_lifecycle();
75231
- init_commands();
75232
- init_shared2();
75233
- NATIVE_SESSION_REQUEST_KIND = "native.session.request";
75234
- NATIVE_SESSION_RESULT_KIND = "native.session.result";
75235
- NATIVE_SESSION_CANCEL_KIND = "native.session.cancel";
75236
- envelope = {
75237
- requestId: identifierStringSchema,
75238
- sessionId: identifierStringSchema
75239
- };
75240
- activeTurnSnapshotSchema = external_exports.object({
75241
- commandId: identifierStringSchema,
75242
- epoch: identifierStringSchema,
75243
- interaction: external_exports.discriminatedUnion("kind", [sessionPermissionRequestedEventSchema, sessionElicitationRequestedEventSchema]).nullable(),
75244
- sequence: external_exports.number().int().nonnegative(),
75245
- state: external_exports.literal("running")
75246
- }).readonly();
75247
- identity = {
75248
- ...envelope,
75249
- kind: external_exports.literal(NATIVE_SESSION_REQUEST_KIND),
75250
- additionalDirectoryIds: external_exports.array(DIRECTORY_IDENTIFIER).max(16).readonly(),
75251
- agentId: identifierStringSchema,
75252
- bindingId: identifierStringSchema,
75253
- directoryId: DIRECTORY_IDENTIFIER
75254
- };
75255
- nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
75256
- external_exports.object({ ...identity, action: external_exports.literal("active-turn"), targetSessionId: identifierStringSchema }).readonly(),
75257
- external_exports.object({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifierStringSchema }).readonly(),
75258
- external_exports.object({
75259
- ...identity,
75260
- action: external_exports.literal("list"),
75261
- cursor: identifierStringSchema.nullable()
75262
- }).readonly(),
75263
- external_exports.object({
75264
- ...identity,
75265
- action: external_exports.enum(["import", "fork"]),
75266
- entryId: identifierStringSchema,
75267
- targetSessionId: identifierStringSchema
75268
- }).readonly()
75269
- ]);
75270
- nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
75271
- external_exports.object({ ...identity, action: external_exports.literal("active-turn"), targetSessionId: identifierStringSchema }).readonly(),
75272
- external_exports.object({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifierStringSchema }).readonly(),
75273
- external_exports.object({
75274
- ...identity,
75275
- action: external_exports.literal("list"),
75276
- cursor: identifierStringSchema.nullable()
75277
- }).readonly(),
75278
- external_exports.object({
75279
- ...identity,
75280
- action: external_exports.enum(["import", "fork"]),
75281
- entryId: identifierStringSchema,
75282
- targetSessionId: identifierStringSchema
75283
- }).readonly()
75284
- ]);
75285
- nativeSessionEntrySchema = external_exports.object({
75286
- entryId: identifierStringSchema,
75287
- mobiusSessionIds: external_exports.array(identifierStringSchema).max(500).readonly(),
75288
- nativeSessionId: identifierStringSchema,
75289
- title: external_exports.string().max(500),
75290
- directoryId: DIRECTORY_IDENTIFIER,
75291
- directoryLabel: external_exports.string().min(1).max(MAX_WORKSPACE_PATH_LENGTH),
75292
- updatedAt: external_exports.iso.datetime({ offset: true }).nullable(),
75293
- additionalDirectories: external_exports.array(external_exports.object({ directoryId: DIRECTORY_IDENTIFIER, name: external_exports.string().min(1).max(255) }).readonly()).max(16).readonly()
75294
- }).readonly();
75295
- resultEnvelope = {
75296
- ...envelope,
75297
- kind: external_exports.literal(NATIVE_SESSION_RESULT_KIND)
75298
- };
75299
- nativeSessionResultSchema = external_exports.discriminatedUnion("action", [
75300
- external_exports.object({
75301
- ...resultEnvelope,
75302
- action: external_exports.literal("active-turn"),
75303
- targetSessionId: identifierStringSchema,
75304
- queued: external_exports.array(
75305
- external_exports.object({
75306
- commandId: identifierStringSchema,
75307
- prompt: external_exports.string().max(1e5),
75308
- attachments: external_exports.array(promptAttachmentSchema).max(16).readonly()
75309
- }).readonly()
75310
- ).readonly(),
75311
- turn: activeTurnSnapshotSchema.nullable()
75312
- }).readonly(),
75313
- external_exports.object({
75314
- ...resultEnvelope,
75315
- action: external_exports.literal("find"),
75316
- entry: nativeSessionEntrySchema
75317
- }).readonly(),
75318
- external_exports.object({
75319
- ...resultEnvelope,
75320
- action: external_exports.literal("list"),
75321
- capabilities: sessionCapabilitiesSchema,
75322
- entries: external_exports.array(nativeSessionEntrySchema).max(500).readonly(),
75323
- nextCursor: identifierStringSchema.nullable()
75324
- }).readonly(),
75325
- external_exports.object({
75326
- ...resultEnvelope,
75327
- action: external_exports.enum(["import", "fork"]),
75328
- targetSessionId: identifierStringSchema,
75329
- ready: sessionReadyEventSchema,
75330
- title: external_exports.string().max(500)
75331
- }).readonly()
75332
- ]);
75333
- nativeSessionCancelSchema = external_exports.object({ ...envelope, kind: external_exports.literal(NATIVE_SESSION_CANCEL_KIND) }).readonly();
75334
- decodeNativeSessionCommand = (encoded) => decode3(nativeSessionCommandSchema, encoded);
75335
- encodeNativeSessionCommand = (value) => JSON.stringify(nativeSessionCommandSchema.parse(value));
75336
- decodeNativeSessionResult = (encoded) => decode3(nativeSessionResultSchema, encoded);
75337
- encodeNativeSessionResult = (value) => JSON.stringify(nativeSessionResultSchema.parse(value));
75338
- decodeNativeSessionCancel = (encoded) => decode3(nativeSessionCancelSchema, encoded);
75339
- encodeNativeSessionCancel = (value) => JSON.stringify(nativeSessionCancelSchema.parse(value));
75340
- }
75341
- });
75342
-
75343
- // ../mobius-sdk/src/protocol/session/observability/event-log.ts
75344
- function isRecord4(value) {
75345
- return typeof value === "object" && value !== null && !Array.isArray(value);
75346
- }
75347
- function hasUnknownDiscriminator(value, key, known) {
75348
- if (!isRecord4(value)) {
75349
- return false;
75350
- }
75351
- const variant = value[key];
75352
- return typeof variant === "string" && !known.has(variant);
75353
- }
75354
- function containsUnknownContentBlock(value) {
75355
- return hasUnknownDiscriminator(value, "type", knownContentBlockTypes);
75356
- }
75357
- function containsUnknownToolCallContent(value) {
75358
- if (hasUnknownDiscriminator(value, "type", knownToolCallContentTypes)) {
75359
- return true;
75360
- }
75361
- return isRecord4(value) && value["type"] === "content" && containsUnknownContentBlock(value["content"]);
75362
- }
75363
- function arrayContainsUnknown(value, predicate) {
75364
- return Array.isArray(value) && value.some(predicate);
75365
- }
75366
- function containsUnknownAcpVariant(payload) {
75367
- const update = payload["sessionUpdate"];
75368
- if (typeof update !== "string") {
75369
- return false;
75370
- }
75371
- if (!knownSessionUpdates.has(update)) {
75372
- return true;
75373
- }
75374
- if (["user_message_chunk", "agent_message_chunk", "agent_thought_chunk", "compaction_summary_chunk"].includes(
75375
- update
75376
- )) {
75377
- return containsUnknownContentBlock(payload["content"]);
75378
- }
75379
- if (update === "tool_call" || update === "tool_call_update") {
75380
- return arrayContainsUnknown(payload["content"], containsUnknownToolCallContent);
75381
- }
75382
- if (update === "plan_update") {
75383
- return hasUnknownDiscriminator(payload["plan"], "type", knownPlanTypes);
75384
- }
75385
- if (update === "config_option_update") {
75386
- return arrayContainsUnknown(
75387
- payload["configOptions"],
75388
- (option) => hasUnknownDiscriminator(option, "type", knownConfigOptionTypes)
75389
- );
75390
- }
75391
- if (update === "compaction_update") {
75392
- return arrayContainsUnknown(payload["summary"], containsUnknownContentBlock);
75393
- }
75394
- return false;
75395
- }
75396
- function isKnownSessionEventVariant(value) {
75397
- if (!isRecord4(value)) {
75398
- return true;
75399
- }
75400
- const type = value["type"];
75401
- if (typeof type !== "string") {
75402
- return true;
75403
- }
75404
- if (type === "acp") {
75405
- const payload = value["payload"];
75406
- return !isRecord4(payload) || !containsUnknownAcpVariant(payload);
75407
- }
75408
- if (type === "lifecycle-metadata") {
75409
- const payload = value["payload"];
75410
- if (!isRecord4(payload)) {
75411
- return true;
75412
- }
75413
- const kind = payload["kind"];
75414
- if (typeof kind === "string" && !knownLifecycleKinds.has(kind)) {
75415
- return false;
75416
- }
75417
- return kind !== "prompt.requested" || !arrayContainsUnknown(payload["content"], containsUnknownContentBlock);
75418
- }
75419
- return false;
75420
- }
75421
- function filterKnownSessionEventVariants(events) {
75422
- return Array.isArray(events) ? events.filter(isKnownSessionEventVariant) : events;
75423
- }
75424
- function inputValue(value) {
75425
- if (typeof value !== "string") {
75426
- return value;
75427
- }
75428
- try {
75429
- return JSON.parse(value);
75430
- } catch (cause) {
75431
- throw new ProtocolMessageError("Session Event Log V2 message is not valid JSON", { cause });
75432
- }
75433
- }
75434
- function decode4(value, schema) {
75435
- const result = schema.safeParse(inputValue(value));
75436
- if (!result.success) {
75437
- throw new ProtocolMessageError("Session Event Log V2 message does not match its schema", {
75438
- cause: result.error
75439
- });
75440
- }
75441
- return result.data;
75442
- }
75443
- function encode3(value, schema) {
75444
- return JSON.stringify(decode4(value, schema));
75445
- }
75446
- function sanitizeKnownNativeSessionEvents(value) {
75447
- const input2 = inputValue(value);
75448
- if (!isRecord4(input2)) {
75449
- return input2;
75450
- }
75451
- const page = input2["events"];
75452
- const queuedPromptRequests = input2["queuedPromptRequests"];
75453
- return {
75454
- ...input2,
75455
- events: isRecord4(page) ? { ...page, events: filterKnownSessionEventVariants(page["events"]) } : page,
75456
- queuedPromptRequests: Array.isArray(queuedPromptRequests) ? queuedPromptRequests.filter(
75457
- (prompt) => !isRecord4(prompt) || !arrayContainsUnknown(prompt["content"], containsUnknownContentBlock)
75458
- ) : queuedPromptRequests
75459
- };
75460
- }
75461
- var MAX_EVENT_COUNT, MAX_COLLECTION_SIZE2, MAX_CONTENT_LENGTH2, SESSION_EVENT_KIND, SESSION_EVENT_BATCH_MAX_SIZE, boundedString2, shortString, externalContentKeySchema, annotationsSchema, contentFields, textContentSchema, imageContentSchema, audioContentSchema, externalImageContentSchema, externalAudioContentSchema, externalResourceContentSchema, resourceLinkSchema, textResourceSchema, blobResourceSchema, embeddedResourceSchema, contentBlockSchema, toolCallContentSchema, toolKindSchema, toolStatusSchema, backgroundTaskSchema, toolPatchFields, planEntrySchema, planContentSchema, commandSchema, configSelectOptionSchema, configSelectGroupSchema, configBaseFields, sessionConfigOptionSchema2, contentChunkFields, acpSessionUpdateSchema, lifecycleBase, promptExecutionContextSchema, lifecycleMetadataSchema, sessionEventPayloadSchema, positionSchema, sharedSessionEventFields, sessionLiveEventFields, sessionEventSchema, sessionLiveEventSchema, wireLifecyclePayloadSchema, wireEventFields, sessionWireEventSchema, sessionWireEnvelopeSchema, knownContentBlockTypes, knownToolCallContentTypes, knownPlanTypes, knownConfigOptionTypes, knownSessionUpdates, knownLifecycleKinds, sessionEventBatchSchema, sessionLiveEventBatchSchema, sessionExportSchema, mobiusSessionExportSchema, sessionEventEnvelopeSchema, sessionEventLogPageSchema, sessionEventOmissionSchema, nativeEventPageRequestSchema, queuedPromptRequestEventLogSchema, nativeSessionEventsSchema, knownSessionLiveEventBatchSchema, decodeSessionEvent, decodeKnownSessionEventPayload, decodeSessionEventEnvelope, encodeSessionEventEnvelope, decodeAcpSessionUpdate, decodeKnownNativeSessionEvents;
75462
- var init_event_log = __esm({
75463
- "../mobius-sdk/src/protocol/session/observability/event-log.ts"() {
75464
- "use strict";
75465
- init_zod();
75466
- init_directory();
75467
- init_tool_input();
75468
- init_tool_input();
75469
- init_identifier();
75470
- init_message_codec();
75471
- init_interactions();
75472
- MAX_EVENT_COUNT = 1e4;
75473
- MAX_COLLECTION_SIZE2 = 1e3;
75474
- MAX_CONTENT_LENGTH2 = 1e6;
75475
- SESSION_EVENT_KIND = "session.event.v2";
75476
- SESSION_EVENT_BATCH_MAX_SIZE = 1e3;
75477
- boundedString2 = external_exports.string().max(MAX_CONTENT_LENGTH2);
75478
- shortString = external_exports.string().max(2048);
75479
- externalContentKeySchema = external_exports.string().regex(/^[a-f0-9]{64}$/u);
75480
- annotationsSchema = external_exports.object({
75481
- audience: external_exports.array(external_exports.enum(["assistant", "user"])).max(2).readonly().nullable().optional(),
75482
- lastModified: shortString.nullable().optional(),
75483
- priority: external_exports.number().finite().nullable().optional()
75484
- }).readonly();
75485
- contentFields = { annotations: annotationsSchema.nullable().optional() };
75486
- textContentSchema = external_exports.object({ ...contentFields, text: boundedString2, type: external_exports.literal("text") }).readonly();
75487
- imageContentSchema = external_exports.object({
75488
- ...contentFields,
75489
- data: external_exports.string(),
75490
- mimeType: shortString,
75491
- type: external_exports.literal("image"),
75492
- uri: boundedString2.nullable().optional()
75493
- }).readonly();
75494
- audioContentSchema = external_exports.object({ ...contentFields, data: external_exports.string(), mimeType: shortString, type: external_exports.literal("audio") }).readonly();
75495
- externalImageContentSchema = external_exports.object({
75496
- ...contentFields,
75497
- byteLength: external_exports.number().int().positive().safe(),
75498
- imageKey: externalContentKeySchema,
75499
- mimeType: shortString,
75500
- type: external_exports.literal("external_image"),
75501
- uri: boundedString2.nullable().optional()
75502
- }).readonly();
75503
- externalAudioContentSchema = external_exports.object({
75504
- ...contentFields,
75505
- audioKey: externalContentKeySchema,
75506
- byteLength: external_exports.number().int().positive().safe(),
75507
- mimeType: shortString,
75508
- type: external_exports.literal("external_audio")
75509
- }).readonly();
75510
- externalResourceContentSchema = external_exports.object({
75511
- ...contentFields,
75512
- byteLength: external_exports.number().int().positive().safe(),
75513
- encoding: external_exports.enum(["binary", "text"]),
75514
- mimeType: shortString.nullable().optional(),
75515
- resourceKey: externalContentKeySchema,
75516
- type: external_exports.literal("external_resource"),
75517
- uri: boundedString2
75518
- }).readonly();
75519
- resourceLinkSchema = external_exports.object({
75520
- ...contentFields,
75521
- description: boundedString2.nullable().optional(),
75522
- mimeType: shortString.nullable().optional(),
75523
- name: shortString,
75524
- size: external_exports.number().int().nonnegative().safe().nullable().optional(),
75525
- title: shortString.nullable().optional(),
75526
- type: external_exports.literal("resource_link"),
75527
- uri: boundedString2
75528
- }).readonly();
75529
- textResourceSchema = external_exports.object({
75530
- mimeType: shortString.nullable().optional(),
75531
- text: boundedString2,
75532
- uri: boundedString2
75533
- }).readonly();
75534
- blobResourceSchema = external_exports.object({
75535
- blob: external_exports.string(),
75536
- mimeType: shortString.nullable().optional(),
75537
- uri: boundedString2
75538
- }).readonly();
75539
- embeddedResourceSchema = external_exports.object({
75540
- ...contentFields,
75541
- resource: external_exports.union([textResourceSchema, blobResourceSchema]),
75542
- type: external_exports.literal("resource")
75543
- }).readonly();
75544
- contentBlockSchema = external_exports.discriminatedUnion("type", [
75545
- textContentSchema,
75546
- imageContentSchema,
75547
- audioContentSchema,
75548
- resourceLinkSchema,
75549
- embeddedResourceSchema,
75550
- externalImageContentSchema,
75551
- externalAudioContentSchema,
75552
- externalResourceContentSchema
75553
- ]);
75554
- toolCallContentSchema = external_exports.discriminatedUnion("type", [
75555
- external_exports.object({ content: contentBlockSchema, type: external_exports.literal("content") }).readonly(),
75556
- external_exports.object({
75557
- newText: boundedString2,
75558
- oldText: boundedString2.nullable().optional(),
75559
- path: boundedString2,
75560
- type: external_exports.literal("diff")
75561
- }).readonly(),
75562
- external_exports.object({ terminalId: shortString, type: external_exports.literal("terminal") }).readonly()
75563
- ]);
75564
- toolKindSchema = external_exports.enum([
75565
- "read",
75566
- "edit",
75567
- "delete",
75568
- "move",
75569
- "search",
75570
- "execute",
75571
- "think",
75572
- "fetch",
75573
- "switch_mode",
75574
- "other"
75575
- ]);
75576
- toolStatusSchema = external_exports.enum(["pending", "in_progress", "completed", "failed"]);
75577
- backgroundTaskSchema = external_exports.object({
75578
- id: shortString,
75579
- status: external_exports.enum(["running", "completed", "failed", "stopped", "unknown"])
75599
+ targetCommandId
75600
+ };
75601
+ }
75602
+ function readHistoryPolicy(value) {
75603
+ const field = value["historyPolicy"];
75604
+ if (field === SessionHistoryPolicy.Eager || field === SessionHistoryPolicy.ExecutionOnly) {
75605
+ return field;
75606
+ }
75607
+ throw new ProtocolMessageError("Invalid value field: historyPolicy");
75608
+ }
75609
+ function decodeSessionCancelCommand(encoded) {
75610
+ const value = parseJson(encoded);
75611
+ assertKind(value, SESSION_CANCEL_KIND);
75612
+ return {
75613
+ commandId: readIdentifier(value, "commandId"),
75614
+ kind: SESSION_CANCEL_KIND,
75615
+ sessionId: readIdentifier(value, "sessionId")
75616
+ };
75617
+ }
75618
+ function decodeSessionPromptDispositionCommand(encoded) {
75619
+ const value = parseJson(encoded);
75620
+ assertKind(value, SESSION_PROMPT_DISPOSITION_KIND);
75621
+ if (readPromptDisposition(value) !== SessionPromptDisposition.Steer) {
75622
+ throw new ProtocolMessageError("Only queued prompts can be steered");
75623
+ }
75624
+ return {
75625
+ commandId: readIdentifier(value, "commandId"),
75626
+ disposition: SessionPromptDisposition.Steer,
75627
+ kind: SESSION_PROMPT_DISPOSITION_KIND,
75628
+ sessionId: readIdentifier(value, "sessionId")
75629
+ };
75630
+ }
75631
+ function encodeSessionPromptCommand(message) {
75632
+ const command = decodeSessionPromptCommand(JSON.stringify(message));
75633
+ return JSON.stringify({
75634
+ ...command,
75635
+ // Keep text prompts compatible with the previous Runtime release while
75636
+ // attachments move to the content-key protocol. Older Runtimes ignore
75637
+ // `attachments` and require both legacy arrays to be present.
75638
+ images: [],
75639
+ resources: []
75640
+ });
75641
+ }
75642
+ function encodeSessionCancelCommand(message) {
75643
+ return JSON.stringify(decodeSessionCancelCommand(JSON.stringify(message)));
75644
+ }
75645
+ function encodeSessionPromptDispositionCommand(message) {
75646
+ return JSON.stringify(decodeSessionPromptDispositionCommand(JSON.stringify(message)));
75647
+ }
75648
+ var SESSION_PROMPT_KIND, SESSION_PROMPT_DISPOSITION_KIND, SESSION_CANCEL_KIND, SESSION_CANCEL_BEFORE_START_KIND, SessionPromptDisposition, SessionHistoryPolicy, MAX_PROMPT_LENGTH, MAX_PROMPT_ATTACHMENT_BYTES, encodeSessionCancelBeforeStartCommand, promptAttachmentSchema, decodePromptAttachmentsValue;
75649
+ var init_commands = __esm({
75650
+ "../mobius-sdk/src/protocol/session/prompt/commands.ts"() {
75651
+ "use strict";
75652
+ init_zod();
75653
+ init_identifier();
75654
+ init_message_codec();
75655
+ init_configuration();
75656
+ SESSION_PROMPT_KIND = "session.prompt";
75657
+ SESSION_PROMPT_DISPOSITION_KIND = "session.prompt.disposition";
75658
+ SESSION_CANCEL_KIND = "session.cancel";
75659
+ SESSION_CANCEL_BEFORE_START_KIND = "session.cancel-before-start";
75660
+ SessionPromptDisposition = Object.freeze({
75661
+ Queue: "queue",
75662
+ Reject: "reject",
75663
+ Steer: "steer"
75664
+ });
75665
+ SessionHistoryPolicy = Object.freeze({
75666
+ Eager: "eager",
75667
+ ExecutionOnly: "execution-only"
75668
+ });
75669
+ MAX_PROMPT_LENGTH = 1e5;
75670
+ MAX_PROMPT_ATTACHMENT_BYTES = 32 * 1024 * 1024;
75671
+ encodeSessionCancelBeforeStartCommand = (message) => JSON.stringify(decodeSessionCancelBeforeStartCommand(JSON.stringify(message)));
75672
+ promptAttachmentSchema = external_exports.object({
75673
+ byteLength: external_exports.number().int().positive().max(MAX_PROMPT_ATTACHMENT_BYTES),
75674
+ contentKey: external_exports.string().regex(/^[a-f0-9]{64}$/u),
75675
+ kind: external_exports.enum(["image", "resource"]),
75676
+ mimeType: external_exports.string().min(1).max(255),
75677
+ name: external_exports.string().min(1).max(500),
75678
+ uri: external_exports.string().min(1).max(4096)
75580
75679
  }).readonly();
75581
- toolPatchFields = {
75582
- backgroundTask: backgroundTaskSchema.optional(),
75583
- content: external_exports.array(toolCallContentSchema).max(MAX_COLLECTION_SIZE2).readonly().nullable().optional(),
75584
- kind: toolKindSchema.nullable().optional(),
75585
- locations: external_exports.array(toolCallLocationSchema).max(MAX_COLLECTION_SIZE2).readonly().nullable().optional(),
75586
- name: shortString.nullable().optional(),
75587
- rawInput: boundedJsonSchema.optional(),
75588
- rawOutput: boundedJsonSchema.optional(),
75589
- status: toolStatusSchema.nullable().optional(),
75590
- title: boundedString2.nullable().optional()
75680
+ decodePromptAttachmentsValue = (value) => decodeZodValue(value, external_exports.array(promptAttachmentSchema).max(16).readonly());
75681
+ }
75682
+ });
75683
+
75684
+ // ../mobius-sdk/src/protocol/session/native/index.ts
75685
+ function decode4(schema, encoded) {
75686
+ try {
75687
+ const value = JSON.parse(encoded);
75688
+ return schema.parse(value);
75689
+ } catch (cause) {
75690
+ throw new ProtocolMessageError("Invalid native session message", { cause });
75691
+ }
75692
+ }
75693
+ var NATIVE_SESSION_REQUEST_KIND, NATIVE_SESSION_RESULT_KIND, NATIVE_SESSION_CANCEL_KIND, envelope, activeTurnSnapshotSchema, identity, nativeSessionRequestSchema, nativeSessionCommandSchema, nativeSessionEntrySchema, resultEnvelope, nativeSessionResultSchema, nativeSessionCancelSchema, decodeNativeSessionCommand, encodeNativeSessionCommand, decodeNativeSessionResult, encodeNativeSessionResult, decodeNativeSessionCancel, encodeNativeSessionCancel;
75694
+ var init_native = __esm({
75695
+ "../mobius-sdk/src/protocol/session/native/index.ts"() {
75696
+ "use strict";
75697
+ init_zod();
75698
+ init_directory();
75699
+ init_identifier();
75700
+ init_message_codec();
75701
+ init_interactions();
75702
+ init_lifecycle();
75703
+ init_commands();
75704
+ init_shared2();
75705
+ NATIVE_SESSION_REQUEST_KIND = "native.session.request";
75706
+ NATIVE_SESSION_RESULT_KIND = "native.session.result";
75707
+ NATIVE_SESSION_CANCEL_KIND = "native.session.cancel";
75708
+ envelope = {
75709
+ requestId: identifierStringSchema,
75710
+ sessionId: identifierStringSchema
75591
75711
  };
75592
- planEntrySchema = external_exports.object({
75593
- content: boundedString2,
75594
- priority: external_exports.enum(["high", "medium", "low"]),
75595
- status: external_exports.enum(["pending", "in_progress", "completed"])
75712
+ activeTurnSnapshotSchema = external_exports.object({
75713
+ commandId: identifierStringSchema,
75714
+ epoch: identifierStringSchema,
75715
+ interaction: external_exports.discriminatedUnion("kind", [sessionPermissionRequestedEventSchema, sessionElicitationRequestedEventSchema]).nullable(),
75716
+ sequence: external_exports.number().int().nonnegative(),
75717
+ state: external_exports.literal("running")
75596
75718
  }).readonly();
75597
- planContentSchema = external_exports.discriminatedUnion("type", [
75719
+ identity = {
75720
+ ...envelope,
75721
+ kind: external_exports.literal(NATIVE_SESSION_REQUEST_KIND),
75722
+ additionalDirectoryIds: external_exports.array(DIRECTORY_IDENTIFIER).max(16).readonly(),
75723
+ agentId: identifierStringSchema,
75724
+ bindingId: identifierStringSchema,
75725
+ directoryId: DIRECTORY_IDENTIFIER
75726
+ };
75727
+ nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
75728
+ external_exports.object({ ...identity, action: external_exports.literal("active-turn"), targetSessionId: identifierStringSchema }).readonly(),
75729
+ external_exports.object({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifierStringSchema }).readonly(),
75598
75730
  external_exports.object({
75599
- entries: external_exports.array(planEntrySchema).max(MAX_COLLECTION_SIZE2).readonly(),
75600
- planId: shortString,
75601
- type: external_exports.literal("items")
75731
+ ...identity,
75732
+ action: external_exports.literal("list"),
75733
+ cursor: identifierStringSchema.nullable()
75602
75734
  }).readonly(),
75603
- external_exports.object({ planId: shortString, type: external_exports.literal("file"), uri: boundedString2 }).readonly(),
75604
75735
  external_exports.object({
75605
- content: boundedString2,
75606
- planId: shortString,
75607
- type: external_exports.literal("markdown")
75736
+ ...identity,
75737
+ action: external_exports.enum(["import", "fork"]),
75738
+ entryId: identifierStringSchema,
75739
+ targetSessionId: identifierStringSchema
75608
75740
  }).readonly()
75609
75741
  ]);
75610
- commandSchema = external_exports.object({
75611
- description: boundedString2,
75612
- input: external_exports.object({ hint: boundedString2 }).readonly().nullable().optional(),
75613
- name: shortString
75614
- }).readonly();
75615
- configSelectOptionSchema = external_exports.object({
75616
- description: boundedString2.nullable().optional(),
75617
- name: shortString,
75618
- value: shortString
75619
- }).readonly();
75620
- configSelectGroupSchema = external_exports.object({
75621
- group: shortString,
75622
- name: shortString,
75623
- options: external_exports.array(configSelectOptionSchema).max(MAX_COLLECTION_SIZE2).readonly()
75624
- }).readonly();
75625
- configBaseFields = {
75626
- category: shortString.nullable().optional(),
75627
- description: boundedString2.nullable().optional(),
75628
- id: shortString,
75629
- name: shortString
75630
- };
75631
- sessionConfigOptionSchema2 = external_exports.discriminatedUnion("type", [
75632
- external_exports.object({
75633
- ...configBaseFields,
75634
- currentValue: shortString,
75635
- options: external_exports.union([
75636
- external_exports.array(configSelectOptionSchema).max(MAX_COLLECTION_SIZE2).readonly(),
75637
- external_exports.array(configSelectGroupSchema).max(MAX_COLLECTION_SIZE2).readonly()
75638
- ]),
75639
- type: external_exports.literal("select")
75640
- }).readonly(),
75641
- external_exports.object({ ...configBaseFields, currentValue: external_exports.boolean(), type: external_exports.literal("boolean") }).readonly()
75642
- ]);
75643
- contentChunkFields = {
75644
- content: contentBlockSchema,
75645
- messageId: shortString.nullable().optional()
75646
- };
75647
- acpSessionUpdateSchema = external_exports.discriminatedUnion("sessionUpdate", [
75648
- external_exports.object({ ...contentChunkFields, sessionUpdate: external_exports.literal("user_message_chunk") }).readonly(),
75649
- external_exports.object({ ...contentChunkFields, sessionUpdate: external_exports.literal("agent_message_chunk") }).readonly(),
75650
- external_exports.object({
75651
- ...contentChunkFields,
75652
- meta: external_exports.object({ truncated: external_exports.boolean().optional() }).readonly().optional(),
75653
- sessionUpdate: external_exports.literal("agent_thought_chunk")
75654
- }).readonly(),
75655
- external_exports.object({
75656
- backgroundTask: backgroundTaskSchema.optional(),
75657
- content: external_exports.array(toolCallContentSchema).max(MAX_COLLECTION_SIZE2).readonly().optional(),
75658
- kind: toolKindSchema.optional(),
75659
- locations: external_exports.array(toolCallLocationSchema).max(MAX_COLLECTION_SIZE2).readonly().optional(),
75660
- name: shortString.nullable().optional(),
75661
- rawInput: boundedJsonSchema.optional(),
75662
- rawOutput: boundedJsonSchema.optional(),
75663
- sessionUpdate: external_exports.literal("tool_call"),
75664
- status: toolStatusSchema.optional(),
75665
- title: boundedString2,
75666
- toolCallId: shortString
75667
- }).readonly(),
75668
- external_exports.object({ ...toolPatchFields, sessionUpdate: external_exports.literal("tool_call_update"), toolCallId: shortString }).readonly(),
75669
- external_exports.object({
75670
- entries: external_exports.array(planEntrySchema).max(MAX_COLLECTION_SIZE2).readonly(),
75671
- sessionUpdate: external_exports.literal("plan")
75672
- }).readonly(),
75673
- external_exports.object({ plan: planContentSchema, sessionUpdate: external_exports.literal("plan_update") }).readonly(),
75674
- external_exports.object({ planId: shortString, sessionUpdate: external_exports.literal("plan_removed") }).readonly(),
75675
- external_exports.object({
75676
- availableCommands: external_exports.array(commandSchema).max(MAX_COLLECTION_SIZE2).readonly(),
75677
- sessionUpdate: external_exports.literal("available_commands_update")
75678
- }).readonly(),
75679
- external_exports.object({
75680
- currentModeId: shortString,
75681
- sessionUpdate: external_exports.literal("current_mode_update")
75682
- }).readonly(),
75683
- external_exports.object({
75684
- configOptions: external_exports.array(sessionConfigOptionSchema2).max(MAX_COLLECTION_SIZE2).readonly(),
75685
- sessionUpdate: external_exports.literal("config_option_update")
75686
- }).readonly(),
75687
- external_exports.object({
75688
- sessionUpdate: external_exports.literal("session_info_update"),
75689
- title: boundedString2.nullable().optional(),
75690
- updatedAt: shortString.nullable().optional()
75691
- }).readonly(),
75692
- external_exports.object({
75693
- cost: external_exports.object({ amount: external_exports.number().finite(), currency: external_exports.string().max(16) }).readonly().nullable().optional(),
75694
- sessionUpdate: external_exports.literal("usage_update"),
75695
- size: external_exports.number().int().nonnegative().safe(),
75696
- used: external_exports.number().int().nonnegative().safe()
75697
- }).readonly(),
75742
+ nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
75743
+ external_exports.object({ ...identity, action: external_exports.literal("active-turn"), targetSessionId: identifierStringSchema }).readonly(),
75744
+ external_exports.object({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifierStringSchema }).readonly(),
75698
75745
  external_exports.object({
75699
- compactionId: shortString,
75700
- error: boundedString2.nullable().optional(),
75701
- sessionUpdate: external_exports.literal("compaction_update"),
75702
- status: shortString,
75703
- summary: external_exports.array(contentBlockSchema).max(MAX_COLLECTION_SIZE2).readonly().nullable().optional()
75746
+ ...identity,
75747
+ action: external_exports.literal("list"),
75748
+ cursor: identifierStringSchema.nullable()
75704
75749
  }).readonly(),
75705
75750
  external_exports.object({
75706
- compactionId: shortString,
75707
- content: contentBlockSchema,
75708
- sessionUpdate: external_exports.literal("compaction_summary_chunk")
75751
+ ...identity,
75752
+ action: external_exports.enum(["import", "fork"]),
75753
+ entryId: identifierStringSchema,
75754
+ targetSessionId: identifierStringSchema
75709
75755
  }).readonly()
75710
75756
  ]);
75711
- lifecycleBase = { commandId: identifierStringSchema };
75712
- promptExecutionContextSchema = external_exports.object({
75713
- agentId: identifierStringSchema,
75757
+ nativeSessionEntrySchema = external_exports.object({
75758
+ entryId: identifierStringSchema,
75759
+ mobiusSessionIds: external_exports.array(identifierStringSchema).max(500).readonly(),
75760
+ nativeSessionId: identifierStringSchema,
75761
+ title: external_exports.string().max(500),
75714
75762
  directoryId: DIRECTORY_IDENTIFIER,
75715
- additionalDirectoryIds: external_exports.array(DIRECTORY_IDENTIFIER).max(16).readonly()
75763
+ directoryLabel: external_exports.string().min(1).max(MAX_WORKSPACE_PATH_LENGTH),
75764
+ updatedAt: external_exports.iso.datetime({ offset: true }).nullable(),
75765
+ additionalDirectories: external_exports.array(external_exports.object({ directoryId: DIRECTORY_IDENTIFIER, name: external_exports.string().min(1).max(255) }).readonly()).max(16).readonly()
75716
75766
  }).readonly();
75717
- lifecycleMetadataSchema = external_exports.discriminatedUnion("kind", [
75718
- external_exports.object({ kind: external_exports.literal("session.queue.changed") }).readonly(),
75719
- external_exports.object({ event: sessionPermissionRequestedEventSchema, kind: external_exports.literal("session.permission.requested") }).readonly(),
75720
- external_exports.object({ event: sessionPermissionResolvedEventSchema, kind: external_exports.literal("session.permission.resolved") }).readonly(),
75721
- external_exports.object({ event: sessionElicitationRequestedEventSchema, kind: external_exports.literal("session.elicitation.requested") }).readonly(),
75722
- external_exports.object({ event: sessionElicitationResolvedEventSchema, kind: external_exports.literal("session.elicitation.resolved") }).readonly(),
75767
+ resultEnvelope = {
75768
+ ...envelope,
75769
+ kind: external_exports.literal(NATIVE_SESSION_RESULT_KIND)
75770
+ };
75771
+ nativeSessionResultSchema = external_exports.discriminatedUnion("action", [
75723
75772
  external_exports.object({
75724
- ...lifecycleBase,
75725
- content: external_exports.array(contentBlockSchema).min(1).max(100).readonly(),
75726
- disposition: shortString.optional(),
75727
- kind: external_exports.literal("prompt.requested"),
75728
- context: promptExecutionContextSchema.optional(),
75729
- targetCommandId: identifierStringSchema.optional()
75773
+ ...resultEnvelope,
75774
+ action: external_exports.literal("active-turn"),
75775
+ targetSessionId: identifierStringSchema,
75776
+ queued: external_exports.array(
75777
+ external_exports.object({
75778
+ commandId: identifierStringSchema,
75779
+ prompt: external_exports.string().max(1e5),
75780
+ attachments: external_exports.array(promptAttachmentSchema).max(16).readonly()
75781
+ }).readonly()
75782
+ ).readonly(),
75783
+ turn: activeTurnSnapshotSchema.nullable()
75730
75784
  }).readonly(),
75731
- external_exports.object({ ...lifecycleBase, attemptId: identifierStringSchema, epoch: identifierStringSchema, kind: external_exports.literal("prompt.started") }).readonly(),
75732
75785
  external_exports.object({
75733
- ...lifecycleBase,
75734
- kind: external_exports.literal("prompt.completed"),
75735
- stopReason: shortString
75786
+ ...resultEnvelope,
75787
+ action: external_exports.literal("find"),
75788
+ entry: nativeSessionEntrySchema
75736
75789
  }).readonly(),
75737
75790
  external_exports.object({
75738
- ...lifecycleBase,
75739
- code: identifierStringSchema,
75740
- kind: external_exports.literal("prompt.failed-before-start"),
75741
- message: external_exports.string().min(1).max(500)
75791
+ ...resultEnvelope,
75792
+ action: external_exports.literal("list"),
75793
+ capabilities: sessionCapabilitiesSchema,
75794
+ entries: external_exports.array(nativeSessionEntrySchema).max(500).readonly(),
75795
+ nextCursor: identifierStringSchema.nullable()
75742
75796
  }).readonly(),
75743
75797
  external_exports.object({
75744
- ...lifecycleBase,
75745
- attemptId: identifierStringSchema,
75746
- code: identifierStringSchema,
75747
- kind: external_exports.literal("prompt.failed"),
75748
- message: external_exports.string().min(1).max(500)
75749
- }).readonly()
75750
- ]);
75751
- sessionEventPayloadSchema = external_exports.discriminatedUnion("type", [
75752
- external_exports.object({ payload: acpSessionUpdateSchema, type: external_exports.literal("acp") }).readonly(),
75753
- external_exports.object({ payload: lifecycleMetadataSchema, type: external_exports.literal("lifecycle-metadata") }).readonly()
75754
- ]);
75755
- positionSchema = external_exports.string().regex(/^(0|[1-9][0-9]*)$/);
75756
- sharedSessionEventFields = {
75757
- eventId: identifierStringSchema,
75758
- mobiusMetadata: external_exports.object({ omitted: external_exports.literal(true).optional() }).readonly().optional(),
75759
- recordedAt: external_exports.iso.datetime({ offset: true }),
75760
- sessionGenerationId: identifierStringSchema,
75761
- sessionId: identifierStringSchema
75762
- };
75763
- sessionLiveEventFields = { ...sharedSessionEventFields, position: positionSchema };
75764
- sessionEventSchema = external_exports.object({ ...sharedSessionEventFields, payload: acpSessionUpdateSchema, type: external_exports.literal("acp") }).readonly();
75765
- sessionLiveEventSchema = external_exports.discriminatedUnion("type", [
75766
- external_exports.object({ ...sessionLiveEventFields, payload: acpSessionUpdateSchema, type: external_exports.literal("acp") }).readonly(),
75767
- external_exports.object({
75768
- ...sessionLiveEventFields,
75769
- payload: lifecycleMetadataSchema,
75770
- type: external_exports.literal("lifecycle-metadata")
75798
+ ...resultEnvelope,
75799
+ action: external_exports.enum(["import", "fork"]),
75800
+ targetSessionId: identifierStringSchema,
75801
+ ready: sessionReadyEventSchema,
75802
+ title: external_exports.string().max(500)
75771
75803
  }).readonly()
75772
75804
  ]);
75773
- wireLifecyclePayloadSchema = external_exports.object({
75774
- kind: identifierStringSchema,
75775
- commandId: identifierStringSchema.optional(),
75776
- context: promptExecutionContextSchema.unwrap().passthrough().readonly().optional(),
75777
- event: external_exports.object({ interactionId: identifierStringSchema.optional() }).passthrough().readonly().optional()
75778
- }).passthrough().readonly();
75779
- wireEventFields = {
75780
- ...sessionLiveEventFields,
75781
- mobiusMetadata: external_exports.object({ omitted: external_exports.literal(true).optional() }).passthrough().readonly().optional()
75782
- };
75783
- sessionWireEventSchema = external_exports.union([
75784
- external_exports.object({
75785
- ...wireEventFields,
75786
- type: external_exports.literal("acp"),
75787
- payload: external_exports.object({ sessionUpdate: identifierStringSchema }).passthrough().readonly()
75788
- }).passthrough().readonly(),
75789
- external_exports.object({
75790
- ...wireEventFields,
75791
- type: external_exports.literal("lifecycle-metadata"),
75792
- payload: wireLifecyclePayloadSchema
75793
- }).passthrough().readonly(),
75794
- external_exports.object({
75795
- ...wireEventFields,
75796
- type: identifierStringSchema.refine((type) => type !== "acp" && type !== "lifecycle-metadata"),
75797
- payload: external_exports.record(external_exports.string(), external_exports.unknown()).readonly()
75798
- }).passthrough().readonly()
75799
- ]);
75800
- sessionWireEnvelopeSchema = external_exports.object({
75801
- kind: external_exports.literal(SESSION_EVENT_KIND),
75802
- events: external_exports.array(sessionWireEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly()
75803
- }).passthrough().readonly();
75804
- knownContentBlockTypes = /* @__PURE__ */ new Set([
75805
- "text",
75806
- "image",
75807
- "audio",
75808
- "resource_link",
75809
- "resource",
75810
- "external_image",
75811
- "external_audio",
75812
- "external_resource"
75813
- ]);
75814
- knownToolCallContentTypes = /* @__PURE__ */ new Set(["content", "diff", "terminal"]);
75815
- knownPlanTypes = /* @__PURE__ */ new Set(["items", "file", "markdown"]);
75816
- knownConfigOptionTypes = /* @__PURE__ */ new Set(["select", "boolean"]);
75817
- knownSessionUpdates = /* @__PURE__ */ new Set([
75818
- "user_message_chunk",
75819
- "agent_message_chunk",
75820
- "agent_thought_chunk",
75821
- "tool_call",
75822
- "tool_call_update",
75823
- "plan",
75824
- "plan_update",
75825
- "plan_removed",
75826
- "available_commands_update",
75827
- "current_mode_update",
75828
- "config_option_update",
75829
- "session_info_update",
75830
- "usage_update",
75831
- "compaction_update",
75832
- "compaction_summary_chunk"
75833
- ]);
75834
- knownLifecycleKinds = /* @__PURE__ */ new Set([
75835
- "session.queue.changed",
75836
- "session.permission.requested",
75837
- "session.permission.resolved",
75838
- "session.elicitation.requested",
75839
- "session.elicitation.resolved",
75840
- "prompt.requested",
75841
- "prompt.started",
75842
- "prompt.completed",
75843
- "prompt.failed-before-start",
75844
- "prompt.failed"
75845
- ]);
75846
- sessionEventBatchSchema = external_exports.array(sessionEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly();
75847
- sessionLiveEventBatchSchema = external_exports.array(sessionLiveEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly();
75848
- sessionExportSchema = external_exports.object({
75849
- binding: external_exports.object({
75850
- bindingId: identifierStringSchema,
75851
- runtimeId: identifierStringSchema
75852
- }).readonly(),
75853
- events: external_exports.array(sessionEventSchema).max(MAX_EVENT_COUNT).readonly(),
75854
- sessionId: identifierStringSchema,
75855
- truncated: external_exports.boolean()
75856
- }).readonly().superRefine((session, context) => {
75857
- const eventIds = /* @__PURE__ */ new Set();
75858
- for (const [index2, event] of session.events.entries()) {
75859
- if (event.sessionId !== session.sessionId) {
75860
- context.addIssue({
75861
- code: "custom",
75862
- message: "Exported event belongs to a different Session",
75863
- path: ["events", index2, "sessionId"]
75864
- });
75865
- }
75866
- if (eventIds.has(event.eventId)) {
75867
- context.addIssue({
75868
- code: "custom",
75869
- message: "Exported event identities are not unique",
75870
- path: ["events", index2, "eventId"]
75871
- });
75872
- }
75873
- eventIds.add(event.eventId);
75874
- }
75875
- });
75876
- mobiusSessionExportSchema = external_exports.object({
75877
- formatVersion: external_exports.literal("2"),
75878
- session: sessionExportSchema
75879
- }).readonly();
75880
- sessionEventEnvelopeSchema = external_exports.object({ events: sessionLiveEventBatchSchema, kind: external_exports.literal(SESSION_EVENT_KIND) }).readonly();
75881
- sessionEventLogPageSchema = external_exports.object({
75882
- events: external_exports.array(sessionEventSchema).max(MAX_EVENT_COUNT).readonly(),
75883
- nextCursor: external_exports.string().min(1).max(512).nullable(),
75884
- sessionGenerationId: identifierStringSchema,
75885
- tailCursor: external_exports.string().max(512),
75886
- // The generation-scoped live position covered by this snapshot, including
75887
- // coalesced and omitted events. Absent only on older Runtime versions.
75888
- throughPosition: positionSchema.optional(),
75889
- truncated: external_exports.boolean(),
75890
- version: external_exports.literal(2)
75891
- }).readonly();
75892
- sessionEventOmissionSchema = external_exports.literal("agent-reasoning");
75893
- nativeEventPageRequestSchema = external_exports.object({
75894
- cursor: external_exports.string().min(1).max(512).nullable(),
75895
- eventLimit: external_exports.number().int().min(1).max(1e4),
75896
- // Legacy callers may still send this option; readers must ignore it.
75897
- omit: external_exports.array(sessionEventOmissionSchema).max(1).readonly().optional()
75898
- }).readonly();
75899
- queuedPromptRequestEventLogSchema = external_exports.object({
75900
- commandId: identifierStringSchema,
75901
- content: external_exports.array(contentBlockSchema).min(1).max(100).readonly(),
75902
- disposition: shortString.optional(),
75903
- targetCommandId: identifierStringSchema.optional()
75904
- }).readonly();
75905
- nativeSessionEventsSchema = external_exports.object({
75906
- events: sessionEventLogPageSchema,
75907
- queuedPromptRequests: external_exports.array(queuedPromptRequestEventLogSchema).max(MAX_COLLECTION_SIZE2).readonly()
75908
- }).readonly();
75909
- knownSessionLiveEventBatchSchema = external_exports.array(sessionLiveEventSchema).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly();
75910
- decodeSessionEvent = (value) => decode4(value, sessionEventSchema);
75911
- decodeKnownSessionEventPayload = (value) => isKnownSessionEventVariant(value) ? decode4(value, sessionEventPayloadSchema) : null;
75912
- decodeSessionEventEnvelope = (value) => decode4(value, sessionEventEnvelopeSchema);
75913
- encodeSessionEventEnvelope = (value) => encode3(value, sessionEventEnvelopeSchema);
75914
- decodeAcpSessionUpdate = (value) => decode4(value, acpSessionUpdateSchema);
75915
- decodeKnownNativeSessionEvents = (value) => decode4(sanitizeKnownNativeSessionEvents(value), nativeSessionEventsSchema);
75805
+ nativeSessionCancelSchema = external_exports.object({ ...envelope, kind: external_exports.literal(NATIVE_SESSION_CANCEL_KIND) }).readonly();
75806
+ decodeNativeSessionCommand = (encoded) => decode4(nativeSessionCommandSchema, encoded);
75807
+ encodeNativeSessionCommand = (value) => JSON.stringify(nativeSessionCommandSchema.parse(value));
75808
+ decodeNativeSessionResult = (encoded) => decode4(nativeSessionResultSchema, encoded);
75809
+ encodeNativeSessionResult = (value) => JSON.stringify(nativeSessionResultSchema.parse(value));
75810
+ decodeNativeSessionCancel = (encoded) => decode4(nativeSessionCancelSchema, encoded);
75811
+ encodeNativeSessionCancel = (value) => JSON.stringify(nativeSessionCancelSchema.parse(value));
75916
75812
  }
75917
75813
  });
75918
75814
 
@@ -75944,7 +75840,7 @@ var init_history2 = __esm({
75944
75840
  init_directory();
75945
75841
  init_identifier();
75946
75842
  init_message_codec();
75947
- init_event_log();
75843
+ init_events();
75948
75844
  SESSION_HISTORY_PAGE_LOAD_KIND = "session.live-history.v2.page.load";
75949
75845
  SESSION_HISTORY_PAGE_LOADED_KIND = "session.live-history.v2.page.loaded";
75950
75846
  SESSION_PREVIEW_HISTORY_PAGE_LOAD_KIND = "session.preview-history.page.load";
@@ -76101,7 +75997,7 @@ var init_recording = __esm({
76101
75997
  init_zod();
76102
75998
  init_directory();
76103
75999
  init_identifier();
76104
- init_event_log();
76000
+ init_events();
76105
76001
  sessionRecordingWriteSchema = external_exports.object({
76106
76002
  envelope: sessionEventEnvelopeSchema,
76107
76003
  projectId: identifierStringSchema,
@@ -76150,14 +76046,14 @@ var init_recording = __esm({
76150
76046
  });
76151
76047
 
76152
76048
  // ../mobius-sdk/src/protocol/session/recording/turn-history.ts
76153
- var SESSION_RECORDING_TURN_PAGE_DECODE_MAX_ELEMENTS, SESSION_RECORDING_TURN_ITEM_ID_MAX_LENGTH, isoTimestamp, shortText, itemText, turnCursorSchema, turnItemCursorSchema, attemptTiming, promptSucceededOutcome, promptCancelledOutcome, promptFailedOutcome, sessionRecordingTurnAttemptSchema, turnItemBase, textItemFields, sessionRecordingToolDetailSchema, sessionRecordingTurnItemSchema, sessionRecordingTurnPromptSchema, sessionRecordingTurnPrecedingSchema, sessionRecordingTurnSchema, sessionRecordingInteractionSchema, SESSION_RECORDING_EXECUTION_COMMAND_MAX_LIMIT, recordingActiveCommandsSchema, sessionRecordingExecutionSchema, sessionRecordingTurnPageSchema, sessionRecordingTurnItemPageSchema, sessionRecordingTurnItemDetailSchema;
76049
+ var SESSION_RECORDING_TURN_PAGE_DECODE_MAX_ELEMENTS, SESSION_RECORDING_TURN_ITEM_ID_MAX_LENGTH, isoTimestamp, shortText, itemText, turnCursorSchema, turnItemCursorSchema, attemptTiming, promptSucceededOutcome, promptCancelledOutcome, promptFailedOutcome, sessionRecordingTurnAttemptSchema, turnItemBase, textItemFields, sessionRecordingToolDetailSchema, sessionRecordingTurnItemSchema, sessionRecordingTurnPromptSchema, sessionRecordingTurnPrecedingSchema, sessionRecordingTurnSchema, sessionRecordingInteractionSchema, SESSION_RECORDING_EXECUTION_COMMAND_MAX_LIMIT, recordingActiveCommandsSchema, sessionRecordingExecutionCommandSchema, sessionRecordingExecutionSchema, sessionRecordingTurnPageSchema, sessionRecordingTurnItemPageSchema, sessionRecordingTurnItemDetailSchema;
76154
76050
  var init_turn_history = __esm({
76155
76051
  "../mobius-sdk/src/protocol/session/recording/turn-history.ts"() {
76156
76052
  "use strict";
76157
76053
  init_zod();
76158
76054
  init_identifier();
76055
+ init_events();
76159
76056
  init_interactions();
76160
- init_event_log();
76161
76057
  init_recording();
76162
76058
  SESSION_RECORDING_TURN_PAGE_DECODE_MAX_ELEMENTS = 1e4;
76163
76059
  SESSION_RECORDING_TURN_ITEM_ID_MAX_LENGTH = 4200;
@@ -76282,15 +76178,14 @@ var init_turn_history = __esm({
76282
76178
  commandIds: external_exports.array(identifierStringSchema).max(1e3).readonly(),
76283
76179
  generationId: identifierStringSchema
76284
76180
  }).readonly().nullable();
76181
+ sessionRecordingExecutionCommandSchema = external_exports.object({
76182
+ attempt: sessionRecordingTurnAttemptSchema,
76183
+ commandId: identifierStringSchema,
76184
+ generationId: identifierStringSchema
76185
+ }).readonly();
76285
76186
  sessionRecordingExecutionSchema = external_exports.object({
76286
76187
  activeCommands: recordingActiveCommandsSchema,
76287
- commands: external_exports.array(
76288
- external_exports.object({
76289
- attempt: sessionRecordingTurnAttemptSchema,
76290
- commandId: identifierStringSchema,
76291
- generationId: identifierStringSchema
76292
- }).readonly()
76293
- ).max(SESSION_RECORDING_EXECUTION_COMMAND_MAX_LIMIT).readonly(),
76188
+ commands: external_exports.array(sessionRecordingExecutionCommandSchema).max(SESSION_RECORDING_EXECUTION_COMMAND_MAX_LIMIT).readonly(),
76294
76189
  sessionId: identifierStringSchema,
76295
76190
  tailCursor: recordingCursorSchema,
76296
76191
  version: external_exports.literal(1)
@@ -76496,32 +76391,22 @@ function defineMessageSignature(kind, encoder, decoder) {
76496
76391
  schema
76497
76392
  };
76498
76393
  }
76499
- function isRecord5(value) {
76500
- return typeof value === "object" && value !== null && !Array.isArray(value);
76501
- }
76502
- function hasUnknownDiscriminator2(value, key, known) {
76503
- if (!isRecord5(value)) {
76504
- return false;
76505
- }
76506
- const variant = value[key];
76507
- return typeof variant === "string" && !known.has(variant);
76508
- }
76509
- function hasUnknownServiceVariant(kind, value) {
76510
- return kind === NATIVE_SESSION_REQUEST_KIND && hasUnknownDiscriminator2(value, "action", knownNativeActions);
76511
- }
76512
76394
  function decodeKnownServiceToDaemonMessage(encoded) {
76513
76395
  const kind = decodeMessageKind(encoded);
76514
76396
  const signature = serviceToDaemonRegistry[kind];
76515
76397
  if (signature === void 0) {
76516
76398
  return null;
76517
76399
  }
76518
- const value = parseJson(encoded);
76519
- return hasUnknownServiceVariant(kind, value) ? null : signature.decoder(encoded);
76400
+ try {
76401
+ return signature.decoder(encoded);
76402
+ } catch {
76403
+ return null;
76404
+ }
76520
76405
  }
76521
76406
  function encodeDaemonToServiceMessage(message) {
76522
76407
  return daemonToServiceSignatures[message.kind].encoder(message);
76523
76408
  }
76524
- var serviceToDaemonSignatures, serviceToDaemonRegistry, knownNativeActions, daemonToServiceSignatures;
76409
+ var serviceToDaemonSignatures, serviceToDaemonRegistry, daemonToServiceSignatures;
76525
76410
  var init_daemon_transport = __esm({
76526
76411
  "../mobius-sdk/src/protocol/transport/daemon-transport.ts"() {
76527
76412
  "use strict";
@@ -76532,11 +76417,11 @@ var init_daemon_transport = __esm({
76532
76417
  init_settings2();
76533
76418
  init_configuration();
76534
76419
  init_title();
76420
+ init_events();
76535
76421
  init_files();
76536
76422
  init_interactions();
76537
76423
  init_lifecycle();
76538
76424
  init_native();
76539
- init_event_log();
76540
76425
  init_history2();
76541
76426
  init_commands();
76542
76427
  init_workspace();
@@ -76672,7 +76557,6 @@ var init_daemon_transport = __esm({
76672
76557
  )
76673
76558
  };
76674
76559
  serviceToDaemonRegistry = serviceToDaemonSignatures;
76675
- knownNativeActions = /* @__PURE__ */ new Set(["active-turn", "find", "list", "import", "fork"]);
76676
76560
  daemonToServiceSignatures = {
76677
76561
  [SESSION_CLOSED_KIND]: defineMessageSignature(
76678
76562
  SESSION_CLOSED_KIND,
@@ -76818,12 +76702,12 @@ var init_protocol = __esm({
76818
76702
  init_settings2();
76819
76703
  init_configuration();
76820
76704
  init_title();
76705
+ init_events();
76821
76706
  init_files();
76822
76707
  init_interactions();
76823
76708
  init_model();
76824
76709
  init_lifecycle();
76825
76710
  init_native();
76826
- init_event_log();
76827
76711
  init_history2();
76828
76712
  init_commands();
76829
76713
  init_usage();
@@ -82652,7 +82536,7 @@ var init_native_session = __esm({
82652
82536
 
82653
82537
  // src/acp/protocol/session-config-protocol.ts
82654
82538
  import { methods as methods9 } from "@agentclientprotocol/sdk";
82655
- function isRecord6(value) {
82539
+ function isRecord5(value) {
82656
82540
  return typeof value === "object" && value !== null && !Array.isArray(value);
82657
82541
  }
82658
82542
  function readString3(value, fallback = "") {
@@ -82683,7 +82567,7 @@ function normalizeConfigValues(value) {
82683
82567
  }
82684
82568
  const normalized = [];
82685
82569
  for (const entry of value) {
82686
- if (!isRecord6(entry)) {
82570
+ if (!isRecord5(entry)) {
82687
82571
  continue;
82688
82572
  }
82689
82573
  const groupedOptions = entry["options"];
@@ -82691,7 +82575,7 @@ function normalizeConfigValues(value) {
82691
82575
  const groupId = readString3(entry["group"]);
82692
82576
  const groupName = readString3(entry["name"]);
82693
82577
  for (const groupedOption of groupedOptions) {
82694
- if (isRecord6(groupedOption)) {
82578
+ if (isRecord5(groupedOption)) {
82695
82579
  const normalizedValue = normalizeConfigValue(groupedOption, groupId, groupName);
82696
82580
  if (normalizedValue !== void 0) {
82697
82581
  normalized.push(normalizedValue);
@@ -82716,7 +82600,7 @@ function normalizeConfigOptions(value, modes) {
82716
82600
  const normalized = [];
82717
82601
  if (Array.isArray(value)) {
82718
82602
  for (const option of value) {
82719
- if (!isRecord6(option)) {
82603
+ if (!isRecord5(option)) {
82720
82604
  continue;
82721
82605
  }
82722
82606
  const id = truncate3(readString3(option["id"]), 128);
@@ -82756,12 +82640,12 @@ function normalizeConfigOptions(value, modes) {
82756
82640
  }
82757
82641
  }
82758
82642
  }
82759
- if (isRecord6(modes)) {
82643
+ if (isRecord5(modes)) {
82760
82644
  const values = [];
82761
82645
  const availableModes = modes["availableModes"];
82762
82646
  if (Array.isArray(availableModes)) {
82763
82647
  for (const mode of availableModes) {
82764
- if (!isRecord6(mode)) {
82648
+ if (!isRecord5(mode)) {
82765
82649
  continue;
82766
82650
  }
82767
82651
  const id = truncate3(readString3(mode["id"]), 500);
@@ -82794,7 +82678,7 @@ function normalizeConfigOptions(value, modes) {
82794
82678
  return normalized.slice(0, MAXIMUM_CONFIG_OPTIONS);
82795
82679
  }
82796
82680
  function normalizeStandardLifecycle(response) {
82797
- const lifecycle = isRecord6(response) ? response : {};
82681
+ const lifecycle = isRecord5(response) ? response : {};
82798
82682
  return normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
82799
82683
  }
82800
82684
  function replaceStandardConfigOptions(current, value) {
@@ -82851,7 +82735,7 @@ var init_session_config_protocol = __esm({
82851
82735
  "ACP agent exited while changing session configuration",
82852
82736
  change.signal
82853
82737
  );
82854
- if (!isRecord6(response) || !Array.isArray(response["configOptions"])) {
82738
+ if (!isRecord5(response) || !Array.isArray(response["configOptions"])) {
82855
82739
  throw new SessionConfigProtocolError("The Agent returned an invalid session configuration response");
82856
82740
  }
82857
82741
  return replaceStandardConfigOptions(current, response["configOptions"]);
@@ -90690,7 +90574,7 @@ function decodeBase64(data) {
90690
90574
  }
90691
90575
  return bytes;
90692
90576
  }
90693
- function isRecord7(value) {
90577
+ function isRecord6(value) {
90694
90578
  return typeof value === "object" && value !== null && !Array.isArray(value);
90695
90579
  }
90696
90580
  var MAXIMUM_ENCODED_CONTENT_CHARACTERS, embeddedImageSchema, inlineImageUrlSchema, toolImageSchema, AcpContentExternalizer;
@@ -90827,13 +90711,13 @@ var init_content_externalizer = __esm({
90827
90711
  }
90828
90712
  return result2;
90829
90713
  }
90830
- if (!isRecord7(value)) {
90714
+ if (!isRecord6(value)) {
90831
90715
  return value;
90832
90716
  }
90833
90717
  const image = toolImageSchema.safeParse(value);
90834
90718
  if (image.success && image.data.data.length > 0) {
90835
90719
  const prepared = await this.#content(sessionId, image.data, signal);
90836
- if (isRecord7(prepared.event) && typeof prepared.event["imageKey"] === "string") {
90720
+ if (isRecord6(prepared.event) && typeof prepared.event["imageKey"] === "string") {
90837
90721
  images.set(prepared.event["imageKey"], prepared);
90838
90722
  } else {
90839
90723
  images.set(`unavailable:${images.size}`, prepared);
@@ -90864,7 +90748,7 @@ var init_content_externalizer = __esm({
90864
90748
  const prepared = await this.#content(sessionId, content, signal);
90865
90749
  agentContent.push({ ...item, content: prepared.agent });
90866
90750
  eventContent.push({ ...item, content: prepared.event });
90867
- if (isRecord7(prepared.event) && typeof prepared.event["imageKey"] === "string") {
90751
+ if (isRecord6(prepared.event) && typeof prepared.event["imageKey"] === "string") {
90868
90752
  images.delete(prepared.event["imageKey"]);
90869
90753
  }
90870
90754
  }
@@ -91025,7 +90909,7 @@ var init_relay_authentication = __esm({
91025
90909
 
91026
90910
  // src/runtime/catalog/publish-agent-catalog.ts
91027
90911
  import { fetch as fetch2 } from "undici";
91028
- function isRecord8(value) {
90912
+ function isRecord7(value) {
91029
90913
  return typeof value === "object" && value !== null && !Array.isArray(value);
91030
90914
  }
91031
90915
  function isSafeRelayErrorMessage(value) {
@@ -91038,7 +90922,7 @@ async function rejectedCatalogError(response) {
91038
90922
  } catch {
91039
90923
  return new AgentCatalogPublishError("The Relay rejected the Agent catalog update");
91040
90924
  }
91041
- if (!isRecord8(value) || !isRecord8(value["error"])) {
90925
+ if (!isRecord7(value) || !isRecord7(value["error"])) {
91042
90926
  return new AgentCatalogPublishError("The Relay rejected the Agent catalog update");
91043
90927
  }
91044
90928
  const code = value["error"]["code"];
@@ -91387,7 +91271,7 @@ var init_runtime_connection = __esm({
91387
91271
  // src/runtime/connection/runtime-installation-store.ts
91388
91272
  import { randomUUID as randomUUID13 } from "node:crypto";
91389
91273
  import { resolve as resolve15 } from "node:path";
91390
- function isRecord9(value) {
91274
+ function isRecord8(value) {
91391
91275
  return typeof value === "object" && value !== null && !Array.isArray(value);
91392
91276
  }
91393
91277
  function hasExactKeys(value, expectedKeys) {
@@ -91454,7 +91338,7 @@ function installationId() {
91454
91338
  return `min_${randomUUID13().replaceAll("-", "")}`;
91455
91339
  }
91456
91340
  function decodeInstallationPointer(value) {
91457
- if (!isRecord9(value) || !hasExactKeys(value, INSTALLATION_POINTER_KEYS) || value["version"] !== 1) {
91341
+ if (!isRecord8(value) || !hasExactKeys(value, INSTALLATION_POINTER_KEYS) || value["version"] !== 1) {
91458
91342
  throw new RuntimeInstallationStoreError("invalid_installation", "The local installation record is invalid");
91459
91343
  }
91460
91344
  const storedInstallationId = value["installationId"];
@@ -91464,7 +91348,7 @@ function decodeInstallationPointer(value) {
91464
91348
  return { installationId: validateInstallationId(storedInstallationId) };
91465
91349
  }
91466
91350
  function decodeChannelIndex(value) {
91467
- if (!isRecord9(value) || !hasExactKeys(value, CHANNEL_INDEX_KEYS) || value["version"] !== 1) {
91351
+ if (!isRecord8(value) || !hasExactKeys(value, CHANNEL_INDEX_KEYS) || value["version"] !== 1) {
91468
91352
  throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
91469
91353
  }
91470
91354
  const applicationId = value["applicationId"];
@@ -91514,7 +91398,7 @@ function decodeVerifiedConnection(value) {
91514
91398
  );
91515
91399
  }
91516
91400
  function decodeConnection(value) {
91517
- if (!isRecord9(value)) {
91401
+ if (!isRecord8(value)) {
91518
91402
  throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
91519
91403
  }
91520
91404
  return decodeVerifiedConnection(value);
@@ -95044,22 +94928,19 @@ var init_session_interactions = __esm({
95044
94928
  });
95045
94929
 
95046
94930
  // src/session/live/session-configurations.ts
95047
- var storedSessionConfigurationsSchema, decodeStoredSessionConfigurations, SessionConfigurations;
94931
+ var storedSessionConfigurationSchema, decodeStoredSessionConfigurations, SessionConfigurations;
95048
94932
  var init_session_configurations = __esm({
95049
94933
  "src/session/live/session-configurations.ts"() {
95050
94934
  "use strict";
95051
94935
  init_zod();
95052
- storedSessionConfigurationsSchema = external_exports.array(
95053
- external_exports.discriminatedUnion("type", [
95054
- external_exports.object({ booleanValue: external_exports.boolean(), configId: external_exports.string().max(128), type: external_exports.literal("boolean") }),
95055
- external_exports.object({ configId: external_exports.string().max(128), type: external_exports.literal("select"), value: external_exports.string().max(500) })
95056
- ])
95057
- ).max(100);
95058
- decodeStoredSessionConfigurations = (value) => storedSessionConfigurationsSchema.parse(
95059
- Array.isArray(value) ? value.filter(
95060
- (configuration) => typeof configuration !== "object" || configuration === null || !("type" in configuration) || typeof configuration.type !== "string" || configuration.type === "boolean" || configuration.type === "select"
95061
- ) : value
95062
- );
94936
+ storedSessionConfigurationSchema = external_exports.discriminatedUnion("type", [
94937
+ external_exports.object({ booleanValue: external_exports.boolean(), configId: external_exports.string().max(128), type: external_exports.literal("boolean") }),
94938
+ external_exports.object({ configId: external_exports.string().max(128), type: external_exports.literal("select"), value: external_exports.string().max(500) })
94939
+ ]);
94940
+ decodeStoredSessionConfigurations = (value) => external_exports.array(external_exports.unknown()).max(100).parse(value).flatMap((configuration) => {
94941
+ const decoded = storedSessionConfigurationSchema.safeParse(configuration);
94942
+ return decoded.success ? [decoded.data] : [];
94943
+ });
95063
94944
  SessionConfigurations = class {
95064
94945
  #selected = [];
95065
94946
  stored = () => this.#selected;
@@ -97830,56 +97711,82 @@ var init_runtime_turn_activity = __esm({
97830
97711
  RuntimeTurnActivity = class {
97831
97712
  #turns = /* @__PURE__ */ new Set();
97832
97713
  #backgroundSources = /* @__PURE__ */ new Set();
97833
- #admission = { kind: "open" };
97834
- acceptsPrompts = () => this.#admission.kind !== "reserved";
97714
+ #idleWaiters = /* @__PURE__ */ new Set();
97715
+ // When work last started or stopped; the quiet period is measured from here.
97716
+ #changedAt = Date.now();
97717
+ #reserved = false;
97718
+ acceptsPrompts = () => !this.#reserved;
97835
97719
  count = () => this.#turns.size + this.#backgroundSources.size;
97720
+ describe = () => ({
97721
+ turns: this.#turns.size,
97722
+ backgroundSources: this.#backgroundSources.size
97723
+ });
97836
97724
  setBackgroundActivity = (source, active) => {
97725
+ if (active === this.#backgroundSources.has(source)) {
97726
+ return;
97727
+ }
97837
97728
  if (active) {
97838
97729
  this.#backgroundSources.add(source);
97839
97730
  } else {
97840
97731
  this.#backgroundSources.delete(source);
97841
97732
  }
97842
- this.#reserveIfIdle();
97733
+ this.#changed();
97843
97734
  };
97844
- #reserveIfIdle() {
97845
- if (this.count() === 0 && this.#admission.kind === "waiting") {
97846
- this.#admission.reserve();
97847
- }
97848
- }
97849
97735
  start = (turn) => {
97850
97736
  this.#turns.add(turn);
97737
+ this.#changed();
97851
97738
  };
97852
97739
  finish = (turn) => {
97853
97740
  this.#turns.delete(turn);
97854
- this.#reserveIfIdle();
97741
+ this.#changed();
97855
97742
  };
97856
- reserveWhenIdle = (signal) => {
97743
+ #changed() {
97744
+ this.#changedAt = Date.now();
97745
+ if (this.count() === 0) {
97746
+ for (const resolve21 of this.#idleWaiters) {
97747
+ resolve21();
97748
+ }
97749
+ this.#idleWaiters.clear();
97750
+ }
97751
+ }
97752
+ whenIdle = (signal) => {
97857
97753
  signal.throwIfAborted();
97858
- if (this.#admission.kind !== "open") {
97859
- throw new Error("A daemon upgrade already owns admission");
97754
+ if (this.count() === 0) {
97755
+ return Promise.resolve();
97860
97756
  }
97861
97757
  return new Promise((resolve21, reject2) => {
97862
97758
  const abort = () => {
97863
- this.#admission = { kind: "open" };
97864
- signal.removeEventListener("abort", abort);
97759
+ this.#idleWaiters.delete(idle);
97865
97760
  reject2(signal.reason);
97866
97761
  };
97867
- const reserve = () => {
97868
- this.#admission = { kind: "reserved" };
97762
+ const idle = () => {
97869
97763
  signal.removeEventListener("abort", abort);
97870
- resolve21({
97871
- [Symbol.dispose]: () => {
97872
- this.#admission = { kind: "open" };
97873
- }
97874
- });
97764
+ resolve21();
97875
97765
  };
97876
- this.#admission = { kind: "waiting", reserve };
97766
+ this.#idleWaiters.add(idle);
97877
97767
  signal.addEventListener("abort", abort, { once: true });
97878
- if (this.count() === 0) {
97879
- reserve();
97880
- }
97881
97768
  });
97882
97769
  };
97770
+ /**
97771
+ * Close admission only after the Runtime has had no work for `quietMilliseconds`.
97772
+ * The moment a reply finishes is when a user is most likely to continue, so idle
97773
+ * alone is not an upgrade window. Checking and reserving happen synchronously, so
97774
+ * no prompt can be admitted between them.
97775
+ */
97776
+ reserveIfQuiet = (quietMilliseconds) => {
97777
+ if (this.#reserved) {
97778
+ throw new Error("A daemon upgrade already owns admission");
97779
+ }
97780
+ if (this.count() > 0 || Date.now() - this.#changedAt < quietMilliseconds) {
97781
+ return null;
97782
+ }
97783
+ this.#reserved = true;
97784
+ return {
97785
+ [Symbol.dispose]: () => {
97786
+ this.#reserved = false;
97787
+ }
97788
+ };
97789
+ };
97883
97790
  };
97884
97791
  }
97885
97792
  });
@@ -102857,6 +102764,21 @@ async function awaitDaemonReleaseSwitch(stateDirectory, id, signal) {
102857
102764
  }
102858
102765
  return outcome;
102859
102766
  }
102767
+ async function reserveWhenQuiet(activity, signal) {
102768
+ for (; ; ) {
102769
+ await activity.whenIdle(signal);
102770
+ for await (const _tick of setInterval2(UPGRADE_QUIET_CHECK_MILLISECONDS, void 0, { signal })) {
102771
+ const reservation = activity.reserveIfQuiet(UPGRADE_QUIET_MILLISECONDS);
102772
+ if (reservation !== null) {
102773
+ return reservation;
102774
+ }
102775
+ if (activity.count() > 0) {
102776
+ break;
102777
+ }
102778
+ }
102779
+ signal.throwIfAborted();
102780
+ }
102781
+ }
102860
102782
  async function checkDaemonReleaseUpgrade(signal, activity) {
102861
102783
  var _stack = [];
102862
102784
  try {
@@ -102870,17 +102792,20 @@ async function checkDaemonReleaseUpgrade(signal, activity) {
102870
102792
  return;
102871
102793
  }
102872
102794
  const launch = await installDaemonReleaseVersion(version2, signal);
102873
- if (activity.count() > 0) {
102795
+ let reservation = activity.reserveIfQuiet(UPGRADE_QUIET_MILLISECONDS);
102796
+ if (reservation === null) {
102874
102797
  new RuntimeDiagnosticLog(control.stateDirectory).record(
102875
102798
  `Mobius daemon diagnostic ${JSON.stringify({
102876
102799
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
102877
102800
  event: "daemon_upgrade_deferred",
102878
102801
  version: version2,
102879
- activeWork: activity.count()
102802
+ activeWork: activity.count(),
102803
+ ...activity.describe()
102880
102804
  })}`
102881
102805
  );
102806
+ reservation = await reserveWhenQuiet(activity, signal);
102882
102807
  }
102883
- const _reservation = __using(_stack, await activity.reserveWhenIdle(signal));
102808
+ const _reservation = __using(_stack, reservation);
102884
102809
  signal.throwIfAborted();
102885
102810
  await requestInstalledDaemonReleaseSwitch(control.stateDirectory, launch, signal);
102886
102811
  await new Promise((resolve21) => {
@@ -102896,7 +102821,7 @@ async function checkDaemonReleaseUpgrade(signal, activity) {
102896
102821
  __callDispose(_stack, _error, _hasError);
102897
102822
  }
102898
102823
  }
102899
- var SWITCH_COMPLETION_MILLISECONDS, SWITCH_POLL_MILLISECONDS;
102824
+ var SWITCH_COMPLETION_MILLISECONDS, SWITCH_POLL_MILLISECONDS, UPGRADE_QUIET_MILLISECONDS, UPGRADE_QUIET_CHECK_MILLISECONDS;
102900
102825
  var init_upgrade2 = __esm({
102901
102826
  "src/daemon/upgrades/upgrade.ts"() {
102902
102827
  "use strict";
@@ -102911,6 +102836,8 @@ var init_upgrade2 = __esm({
102911
102836
  init_package2();
102912
102837
  SWITCH_COMPLETION_MILLISECONDS = 3e5;
102913
102838
  SWITCH_POLL_MILLISECONDS = 200;
102839
+ UPGRADE_QUIET_MILLISECONDS = 30 * 6e4;
102840
+ UPGRADE_QUIET_CHECK_MILLISECONDS = 6e4;
102914
102841
  }
102915
102842
  });
102916
102843