@kortix/sdk 0.13.30 → 0.13.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -11
- package/dist/browser/session-sync/server-transcript-mirror.d.ts.map +1 -1
- package/dist/browser/session-sync/server-transcript-mirror.js +6 -1
- package/dist/browser/session-sync/server-transcript-mirror.js.map +1 -1
- package/dist/browser/stores/sync-store/delta-event-window.d.ts +10 -0
- package/dist/browser/stores/sync-store/delta-event-window.d.ts.map +1 -0
- package/dist/browser/stores/sync-store/delta-event-window.js +10 -0
- package/dist/browser/stores/sync-store/delta-event-window.js.map +1 -0
- package/dist/browser/stores/sync-store.d.ts.map +1 -1
- package/dist/browser/stores/sync-store.js +48 -5
- package/dist/browser/stores/sync-store.js.map +1 -1
- package/dist/core/auth/session.d.ts.map +1 -1
- package/dist/core/auth/session.js +56 -15
- package/dist/core/auth/session.js.map +1 -1
- package/dist/core/client/kortix.d.ts +8 -0
- package/dist/core/client/kortix.d.ts.map +1 -1
- package/dist/core/client/kortix.js +7 -0
- package/dist/core/client/kortix.js.map +1 -1
- package/dist/core/files/client.d.ts +30 -9
- package/dist/core/files/client.d.ts.map +1 -1
- package/dist/core/files/client.js +71 -29
- package/dist/core/files/client.js.map +1 -1
- package/dist/core/http/api/errors.d.ts +23 -8
- package/dist/core/http/api/errors.d.ts.map +1 -1
- package/dist/core/http/api/errors.js +44 -23
- package/dist/core/http/api/errors.js.map +1 -1
- package/dist/core/http/api-client.d.ts +9 -14
- package/dist/core/http/api-client.d.ts.map +1 -1
- package/dist/core/http/api-client.js +61 -88
- package/dist/core/http/api-client.js.map +1 -1
- package/dist/core/http/auth.d.ts +12 -15
- package/dist/core/http/auth.d.ts.map +1 -1
- package/dist/core/http/auth.js +24 -68
- package/dist/core/http/auth.js.map +1 -1
- package/dist/core/http/transport.d.ts +46 -0
- package/dist/core/http/transport.d.ts.map +1 -0
- package/dist/core/http/transport.js +135 -0
- package/dist/core/http/transport.js.map +1 -0
- package/dist/core/rest/platform-client/host-boundary.d.ts +60 -8
- package/dist/core/rest/platform-client/host-boundary.d.ts.map +1 -1
- package/dist/core/rest/platform-client/host-boundary.js.map +1 -1
- package/dist/core/rest/platform-client/instance-admin.d.ts +16 -9
- package/dist/core/rest/platform-client/instance-admin.d.ts.map +1 -1
- package/dist/core/rest/platform-client/instance-admin.js +21 -25
- package/dist/core/rest/platform-client/instance-admin.js.map +1 -1
- package/dist/core/rest/platform-client/invites.d.ts +11 -3
- package/dist/core/rest/platform-client/invites.d.ts.map +1 -1
- package/dist/core/rest/platform-client/invites.js +16 -18
- package/dist/core/rest/platform-client/invites.js.map +1 -1
- package/dist/core/rest/platform-client/shared.d.ts +0 -7
- package/dist/core/rest/platform-client/shared.d.ts.map +1 -1
- package/dist/core/rest/platform-client/shared.js +0 -49
- package/dist/core/rest/platform-client/shared.js.map +1 -1
- package/dist/core/rest/projects-client/audit.d.ts +5 -3
- package/dist/core/rest/projects-client/audit.d.ts.map +1 -1
- package/dist/core/rest/projects-client/audit.js.map +1 -1
- package/dist/core/rest/projects-client/channels.d.ts +32 -0
- package/dist/core/rest/projects-client/channels.d.ts.map +1 -1
- package/dist/core/rest/projects-client/channels.js +27 -0
- package/dist/core/rest/projects-client/channels.js.map +1 -1
- package/dist/core/rest/projects-client/connectors.d.ts +31 -0
- package/dist/core/rest/projects-client/connectors.d.ts.map +1 -1
- package/dist/core/rest/projects-client/connectors.js +15 -0
- package/dist/core/rest/projects-client/connectors.js.map +1 -1
- package/dist/core/rest/projects-client/iam.d.ts +23 -2
- package/dist/core/rest/projects-client/iam.d.ts.map +1 -1
- package/dist/core/rest/projects-client/iam.js +9 -0
- package/dist/core/rest/projects-client/iam.js.map +1 -1
- package/dist/core/rest/projects-client/presentations.d.ts +4 -2
- package/dist/core/rest/projects-client/presentations.d.ts.map +1 -1
- package/dist/core/rest/projects-client/presentations.js +14 -6
- package/dist/core/rest/projects-client/presentations.js.map +1 -1
- package/dist/core/rest/projects-client/projects.d.ts +8 -10
- package/dist/core/rest/projects-client/projects.d.ts.map +1 -1
- package/dist/core/rest/projects-client/projects.js +8 -8
- package/dist/core/rest/projects-client/projects.js.map +1 -1
- package/dist/core/rest/projects-client/referrals.d.ts +9 -3
- package/dist/core/rest/projects-client/referrals.d.ts.map +1 -1
- package/dist/core/rest/projects-client/referrals.js +20 -17
- package/dist/core/rest/projects-client/referrals.js.map +1 -1
- package/dist/core/rest/projects-client/secrets.d.ts +15 -0
- package/dist/core/rest/projects-client/secrets.d.ts.map +1 -1
- package/dist/core/rest/projects-client/secrets.js +1 -0
- package/dist/core/rest/projects-client/secrets.js.map +1 -1
- package/dist/core/rest/projects-client/session-attachments.d.ts +37 -0
- package/dist/core/rest/projects-client/session-attachments.d.ts.map +1 -1
- package/dist/core/rest/projects-client/session-attachments.js +134 -0
- package/dist/core/rest/projects-client/session-attachments.js.map +1 -1
- package/dist/core/rest/projects-client/session-sandbox.d.ts +4 -1
- package/dist/core/rest/projects-client/session-sandbox.d.ts.map +1 -1
- package/dist/core/rest/projects-client/session-sandbox.js.map +1 -1
- package/dist/core/rest/projects-client/sessions.d.ts +56 -0
- package/dist/core/rest/projects-client/sessions.d.ts.map +1 -1
- package/dist/core/rest/projects-client/sessions.js.map +1 -1
- package/dist/core/rest/projects-client/templates.d.ts +4 -4
- package/dist/core/rest/projects-client/templates.d.ts.map +1 -1
- package/dist/core/rest/projects-client/templates.js +11 -8
- package/dist/core/rest/projects-client/templates.js.map +1 -1
- package/dist/core/runtime/attachment-part.d.ts +1 -1
- package/dist/core/runtime/attachment-part.js +1 -1
- package/dist/core/session/connection.d.ts +1 -1
- package/dist/core/session/open-bundle.d.ts +6 -0
- package/dist/core/session/open-bundle.d.ts.map +1 -1
- package/dist/core/session/open-bundle.js +22 -2
- package/dist/core/session/open-bundle.js.map +1 -1
- package/dist/core/session/preview-auth.d.ts +3 -2
- package/dist/core/session/preview-auth.d.ts.map +1 -1
- package/dist/core/session/preview-auth.js +11 -3
- package/dist/core/session/preview-auth.js.map +1 -1
- package/dist/core/session/preview-config.d.ts +5 -0
- package/dist/core/session/preview-config.d.ts.map +1 -1
- package/dist/core/session/preview-config.js +7 -0
- package/dist/core/session/preview-config.js.map +1 -1
- package/dist/core/session/preview-origin-trust.d.ts +24 -0
- package/dist/core/session/preview-origin-trust.d.ts.map +1 -0
- package/dist/core/session/preview-origin-trust.js +100 -0
- package/dist/core/session/preview-origin-trust.js.map +1 -0
- package/dist/core/session/preview.d.ts +7 -1
- package/dist/core/session/preview.d.ts.map +1 -1
- package/dist/core/session/preview.js +10 -2
- package/dist/core/session/preview.js.map +1 -1
- package/dist/core/session/project-session-read.d.ts +24 -0
- package/dist/core/session/project-session-read.d.ts.map +1 -0
- package/dist/core/session/project-session-read.js +29 -0
- package/dist/core/session/project-session-read.js.map +1 -0
- package/dist/core/session/single-flight.d.ts +20 -0
- package/dist/core/session/single-flight.d.ts.map +1 -0
- package/dist/core/session/single-flight.js +39 -0
- package/dist/core/session/single-flight.js.map +1 -0
- package/dist/core/session/wake-escalation.d.ts +2 -2
- package/dist/core/session/wake-escalation.js +2 -2
- package/dist/core/session/wire-message-id.d.ts +73 -0
- package/dist/core/session/wire-message-id.d.ts.map +1 -0
- package/dist/core/session/wire-message-id.js +120 -0
- package/dist/core/session/wire-message-id.js.map +1 -0
- package/dist/core/session/working.d.ts +2 -2
- package/dist/core/session-sync/saved-transcript.d.ts +49 -0
- package/dist/core/session-sync/saved-transcript.d.ts.map +1 -0
- package/dist/core/session-sync/saved-transcript.js +40 -0
- package/dist/core/session-sync/saved-transcript.js.map +1 -0
- package/dist/core/session-sync/session-sync-controller.d.ts +21 -2
- package/dist/core/session-sync/session-sync-controller.d.ts.map +1 -1
- package/dist/core/session-sync/session-sync-controller.js +56 -7
- package/dist/core/session-sync/session-sync-controller.js.map +1 -1
- package/dist/core/stream/event-stream.d.ts +5 -4
- package/dist/core/stream/event-stream.d.ts.map +1 -1
- package/dist/core/stream/event-stream.js +34 -8
- package/dist/core/stream/event-stream.js.map +1 -1
- package/dist/core/turns/errors.d.ts +7 -0
- package/dist/core/turns/errors.d.ts.map +1 -1
- package/dist/core/turns/errors.js +58 -0
- package/dist/core/turns/errors.js.map +1 -1
- package/dist/core/turns/grouping.d.ts.map +1 -1
- package/dist/core/turns/grouping.js +46 -2
- package/dist/core/turns/grouping.js.map +1 -1
- package/dist/core/turns/state.d.ts +7 -1
- package/dist/core/turns/state.d.ts.map +1 -1
- package/dist/core/turns/state.js +16 -3
- package/dist/core/turns/state.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/kortix.esm.min.js +38 -36
- package/dist/kortix.global.js +38 -36
- package/dist/node/app-viewer.js +1 -1
- package/dist/node/auth.d.ts +8 -1
- package/dist/node/auth.d.ts.map +1 -1
- package/dist/node/auth.js +21 -3
- package/dist/node/auth.js.map +1 -1
- package/dist/platform/auth-core.d.ts +1 -6
- package/dist/platform/auth-core.d.ts.map +1 -1
- package/dist/platform/auth-core.js +1 -21
- package/dist/platform/auth-core.js.map +1 -1
- package/dist/react/bedrock-invokable.d.ts +2 -2
- package/dist/react/bedrock-invokable.js +2 -2
- package/dist/react/file-keys.d.ts +15 -7
- package/dist/react/file-keys.d.ts.map +1 -1
- package/dist/react/file-keys.js +15 -7
- package/dist/react/file-keys.js.map +1 -1
- package/dist/react/identity-reset-registry.d.ts +3 -0
- package/dist/react/identity-reset-registry.d.ts.map +1 -0
- package/dist/react/identity-reset-registry.js +22 -0
- package/dist/react/identity-reset-registry.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +6 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/opencode.d.ts +2 -0
- package/dist/react/opencode.d.ts.map +1 -1
- package/dist/react/opencode.js +2 -0
- package/dist/react/opencode.js.map +1 -1
- package/dist/react/prefetch-session-open.d.ts +20 -0
- package/dist/react/prefetch-session-open.d.ts.map +1 -0
- package/dist/react/prefetch-session-open.js +54 -0
- package/dist/react/prefetch-session-open.js.map +1 -0
- package/dist/react/provider-refresh.d.ts.map +1 -1
- package/dist/react/provider-refresh.js +24 -14
- package/dist/react/provider-refresh.js.map +1 -1
- package/dist/react/provider-selection.d.ts +4 -0
- package/dist/react/provider-selection.d.ts.map +1 -1
- package/dist/react/provider-selection.js +6 -2
- package/dist/react/provider-selection.js.map +1 -1
- package/dist/react/query-keys.d.ts +7 -5
- package/dist/react/query-keys.d.ts.map +1 -1
- package/dist/react/query-keys.js +9 -5
- package/dist/react/query-keys.js.map +1 -1
- package/dist/react/reset-identity-state.d.ts +19 -0
- package/dist/react/reset-identity-state.d.ts.map +1 -0
- package/dist/react/reset-identity-state.js +35 -0
- package/dist/react/reset-identity-state.js.map +1 -0
- package/dist/react/retired-endpoint.d.ts +10 -0
- package/dist/react/retired-endpoint.d.ts.map +1 -0
- package/dist/react/retired-endpoint.js +22 -0
- package/dist/react/retired-endpoint.js.map +1 -0
- package/dist/react/session-stop.d.ts +101 -0
- package/dist/react/session-stop.d.ts.map +1 -0
- package/dist/react/session-stop.js +162 -0
- package/dist/react/session-stop.js.map +1 -0
- package/dist/react/session-transcript-subscription.d.ts +29 -0
- package/dist/react/session-transcript-subscription.d.ts.map +1 -0
- package/dist/react/session-transcript-subscription.js +94 -0
- package/dist/react/session-transcript-subscription.js.map +1 -0
- package/dist/react/sign-in-with-kortix.d.ts +1 -1
- package/dist/react/use-admin-accounts.d.ts +1 -0
- package/dist/react/use-admin-accounts.d.ts.map +1 -1
- package/dist/react/use-admin-accounts.js +3 -10
- package/dist/react/use-admin-accounts.js.map +1 -1
- package/dist/react/use-admin-analytics.d.ts +36 -8
- package/dist/react/use-admin-analytics.d.ts.map +1 -1
- package/dist/react/use-admin-analytics.js +63 -458
- package/dist/react/use-admin-analytics.js.map +1 -1
- package/dist/react/use-admin-billing.d.ts +6 -2
- package/dist/react/use-admin-billing.d.ts.map +1 -1
- package/dist/react/use-admin-billing.js +15 -52
- package/dist/react/use-admin-billing.js.map +1 -1
- package/dist/react/use-admin-feedback.d.ts +10 -1
- package/dist/react/use-admin-feedback.d.ts.map +1 -1
- package/dist/react/use-admin-feedback.js +24 -111
- package/dist/react/use-admin-feedback.js.map +1 -1
- package/dist/react/use-admin-sandboxes.d.ts +13 -5
- package/dist/react/use-admin-sandboxes.d.ts.map +1 -1
- package/dist/react/use-admin-sandboxes.js +20 -104
- package/dist/react/use-admin-sandboxes.js.map +1 -1
- package/dist/react/use-authenticated-preview-url.d.ts.map +1 -1
- package/dist/react/use-authenticated-preview-url.js +7 -1
- package/dist/react/use-authenticated-preview-url.js.map +1 -1
- package/dist/react/use-canonical-opencode-session.d.ts +8 -0
- package/dist/react/use-canonical-opencode-session.d.ts.map +1 -1
- package/dist/react/use-canonical-opencode-session.js +1 -0
- package/dist/react/use-canonical-opencode-session.js.map +1 -1
- package/dist/react/use-model-store.d.ts +1 -1
- package/dist/react/use-model-store.d.ts.map +1 -1
- package/dist/react/use-model-store.js +16 -1
- package/dist/react/use-model-store.js.map +1 -1
- package/dist/react/use-opencode-events/handle-event.d.ts.map +1 -1
- package/dist/react/use-opencode-events/handle-event.js +43 -35
- package/dist/react/use-opencode-events/handle-event.js.map +1 -1
- package/dist/react/use-opencode-sessions/messages.d.ts +14 -3
- package/dist/react/use-opencode-sessions/messages.d.ts.map +1 -1
- package/dist/react/use-opencode-sessions/messages.js +92 -115
- package/dist/react/use-opencode-sessions/messages.js.map +1 -1
- package/dist/react/use-project-session.d.ts.map +1 -1
- package/dist/react/use-project-session.js +10 -2
- package/dist/react/use-project-session.js.map +1 -1
- package/dist/react/use-session-messages.d.ts +37 -0
- package/dist/react/use-session-messages.d.ts.map +1 -0
- package/dist/react/use-session-messages.js +83 -0
- package/dist/react/use-session-messages.js.map +1 -0
- package/dist/react/use-session-prompts.d.ts.map +1 -1
- package/dist/react/use-session-prompts.js +11 -2
- package/dist/react/use-session-prompts.js.map +1 -1
- package/dist/react/use-session-send.d.ts +1 -73
- package/dist/react/use-session-send.d.ts.map +1 -1
- package/dist/react/use-session-send.js +6 -146
- package/dist/react/use-session-send.js.map +1 -1
- package/dist/react/use-session-sync.d.ts +17 -0
- package/dist/react/use-session-sync.d.ts.map +1 -1
- package/dist/react/use-session-sync.js +37 -4
- package/dist/react/use-session-sync.js.map +1 -1
- package/dist/react/use-session-transcript-history.d.ts +3 -0
- package/dist/react/use-session-transcript-history.d.ts.map +1 -1
- package/dist/react/use-session-transcript-history.js +7 -1
- package/dist/react/use-session-transcript-history.js.map +1 -1
- package/dist/react/use-session-working.d.ts.map +1 -1
- package/dist/react/use-session-working.js +20 -10
- package/dist/react/use-session-working.js.map +1 -1
- package/dist/react/use-session.d.ts +36 -2
- package/dist/react/use-session.d.ts.map +1 -1
- package/dist/react/use-session.js +60 -35
- package/dist/react/use-session.js.map +1 -1
- package/dist/react/use-static-file-preview.d.ts.map +1 -1
- package/dist/react/use-static-file-preview.js +2 -1
- package/dist/react/use-static-file-preview.js.map +1 -1
- package/dist/react/use-system-status.d.ts +7 -3
- package/dist/react/use-system-status.d.ts.map +1 -1
- package/dist/react/use-system-status.js +14 -67
- package/dist/react/use-system-status.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-flight.js","sourceRoot":"","sources":["../../../src/core/session/single-flight.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AASH,MAAM,eAAe,GAAa,CAAC,QAAQ,EAAE,EAAE;IAC7C,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAM,UAAU,sBAAsB,CAAI,WAAqB,eAAe;IAC5E,MAAM,OAAO,GAAG,IAAI,GAAG,EAAqB,CAAC;IAC7C,OAAO,SAAS,GAAG,CAAC,GAAW,EAAE,IAAsB;QACrD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,OAAO,EAAE,QAAQ;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC;QAC9C,MAAM,MAAM,GAAc,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAC9D,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACzB,QAAQ,CAAC,GAAG,EAAE;YACZ,MAAM,CAAC,QAAQ,GAAG,KAAK,CAAC;QAC1B,CAAC,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,GAAG,EAAE;YAChB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,MAAM;gBAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACvD,CAAC,CAAC;QACF,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* "Couldn't start session <id> — The session runtime did not become
|
|
15
15
|
* reachable. Restart the session to try again."
|
|
16
16
|
*
|
|
17
|
-
* Measured on
|
|
17
|
+
* Measured on SampleCo (2026-08-26, box `inqwpv4a1cc1kynlg46k8`): that card
|
|
18
18
|
* painted while the box was SECONDS from ready — its daemon logged
|
|
19
19
|
* `opencode ready` at 06:10:02, right after the budget expired. The card is a
|
|
20
20
|
* dead end with no auto-recovery, and the human's fix is always the same one
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
*
|
|
45
45
|
* ## Why `runtimeReachable` is a separate input from `waking`
|
|
46
46
|
*
|
|
47
|
-
* The session row is NOT proof the runtime is up. Observed on
|
|
47
|
+
* The session row is NOT proof the runtime is up. Observed on SampleCo the same
|
|
48
48
|
* day: `POST …/start` answered 202 and the row stayed `running` for 5+ minutes
|
|
49
49
|
* while the E2B resume had silently failed — the provider reported the sandbox
|
|
50
50
|
* `stopped` and the daemon proxy answered `503 sandbox_not_ready`. A ladder that
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* "Couldn't start session <id> — The session runtime did not become
|
|
15
15
|
* reachable. Restart the session to try again."
|
|
16
16
|
*
|
|
17
|
-
* Measured on
|
|
17
|
+
* Measured on SampleCo (2026-08-26, box `inqwpv4a1cc1kynlg46k8`): that card
|
|
18
18
|
* painted while the box was SECONDS from ready — its daemon logged
|
|
19
19
|
* `opencode ready` at 06:10:02, right after the budget expired. The card is a
|
|
20
20
|
* dead end with no auto-recovery, and the human's fix is always the same one
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
*
|
|
45
45
|
* ## Why `runtimeReachable` is a separate input from `waking`
|
|
46
46
|
*
|
|
47
|
-
* The session row is NOT proof the runtime is up. Observed on
|
|
47
|
+
* The session row is NOT proof the runtime is up. Observed on SampleCo the same
|
|
48
48
|
* day: `POST …/start` answered 202 and the row stayed `running` for 5+ minutes
|
|
49
49
|
* while the E2B resume had silently failed — the provider reported the sandbox
|
|
50
50
|
* `stopped` and the daemon proxy answered `503 sandbox_not_ready`. A ladder that
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OpenCode wire message-id clock — framework-free.
|
|
3
|
+
*
|
|
4
|
+
* FORMAT. `msg_` + the LOW 48 bits of `Date.now() * 0x1000` as 12 lowercase
|
|
5
|
+
* hex chars + 14 random base62 chars. OpenCode's own `Identifier.ascending`
|
|
6
|
+
* keeps the low 6 bytes, so the clock wraps every 2^36 ms (~2.2 years); the
|
|
7
|
+
* last wrap was 2026-08-14 11:19:55 UTC.
|
|
8
|
+
*
|
|
9
|
+
* WHY IT MATTERS. A user message's id is its POSITION in the transcript:
|
|
10
|
+
* OpenCode ≤ 1.18.14 decides "has this prompt been answered?" by id order, and
|
|
11
|
+
* every host renders placed messages in id order (`compareMessagesForDisplay`).
|
|
12
|
+
* An id minted from the HIGH bits instead (`kortix sessions send` did this from
|
|
13
|
+
* 2026-08-22 until this module existed) lands ~40 days ahead of every id
|
|
14
|
+
* OpenCode mints itself and renders every later turn above it.
|
|
15
|
+
*
|
|
16
|
+
* The same contract lives in `apps/api/src/projects/wire-message-id.ts` (the
|
|
17
|
+
* API has no `@kortix/sdk` dependency). `tests/spec/wire-message-id.vectors.json`
|
|
18
|
+
* is asserted by both, so a divergence fails two suites.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* How far an id's clock may sit from the clock it is compared with and still
|
|
22
|
+
* count as placed by it: 1 hour. Every correct mint is within ~2 minutes of its
|
|
23
|
+
* own server timestamp (the backdate below); the high-bits bug put ids ~40 days
|
|
24
|
+
* out. Shared with the API's `MAX_WIRE_ID_CLOCK_CORRECTION`.
|
|
25
|
+
*/
|
|
26
|
+
export declare const WIRE_ID_CLOCK_TOLERANCE: bigint;
|
|
27
|
+
/**
|
|
28
|
+
* How far back a mint is dated before any transcript lift places it. Too EARLY
|
|
29
|
+
* is self-correcting (the lift raises it above what is on record); too LATE is
|
|
30
|
+
* undetectable downstream, because the next reply is minted from the box clock
|
|
31
|
+
* and would sort above its own prompt.
|
|
32
|
+
*/
|
|
33
|
+
export declare const WIRE_ID_BACKDATE_MS: number;
|
|
34
|
+
/** The 48-bit clock encoded in a wire id, or null when `id` is not one. */
|
|
35
|
+
export declare function wireIdClock(id: string | null | undefined): bigint | null;
|
|
36
|
+
/** The unmasked id clock of wall-clock instant `ms`. */
|
|
37
|
+
export declare function absoluteWireIdClockAt(ms: number): bigint;
|
|
38
|
+
/** The 48-bit id clock of wall-clock instant `ms`, as OpenCode writes it. */
|
|
39
|
+
export declare function wireIdClockAt(ms: number): bigint;
|
|
40
|
+
/**
|
|
41
|
+
* Undo the 48-bit wrap: the absolute clock congruent to `clock` that is
|
|
42
|
+
* nearest to `anchor` (an absolute clock). Two ids unwrapped against anchors
|
|
43
|
+
* within ~1.1 years of each other keep their true order across a wrap.
|
|
44
|
+
*/
|
|
45
|
+
export declare function unwrapWireIdClock(clock: bigint, anchor: bigint): bigint;
|
|
46
|
+
/**
|
|
47
|
+
* Whether `id` claims a clock more than {@link WIRE_ID_CLOCK_TOLERANCE} ahead
|
|
48
|
+
* of `nowMs`. Such an id cannot have been placed against any real transcript;
|
|
49
|
+
* a floor or a lift must skip it rather than let it veto every later mint.
|
|
50
|
+
*/
|
|
51
|
+
export declare function isWireIdAheadOf(id: string, nowMs: number): boolean;
|
|
52
|
+
/** Options for {@link mintWireMessageId}. */
|
|
53
|
+
export interface MintWireMessageIdOptions {
|
|
54
|
+
/** Wall clock to mint at, in ms since epoch. Default: `Date.now()`. */
|
|
55
|
+
nowMs?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Ids already in the transcript. The mint sorts strictly after the newest of
|
|
58
|
+
* them that is within one hour of the clock; ids further ahead than that are
|
|
59
|
+
* ignored, so one bad id cannot drag every later message forward.
|
|
60
|
+
*/
|
|
61
|
+
after?: Iterable<string | null | undefined>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Mint an OpenCode wire message id for a prompt.
|
|
65
|
+
*
|
|
66
|
+
* Use this — never a hand-rolled `Date.now()` encoding — for the `messageId`
|
|
67
|
+
* of `session.prompts.create()`. It is dated {@link WIRE_ID_BACKDATE_MS} back
|
|
68
|
+
* and lifted just above the newest id in `after`. A caller that cannot read the
|
|
69
|
+
* transcript should also pass `remintOnDelivery: true`, so the control plane
|
|
70
|
+
* places the id against the live transcript before delivery.
|
|
71
|
+
*/
|
|
72
|
+
export declare function mintWireMessageId(options?: MintWireMessageIdOptions): string;
|
|
73
|
+
//# sourceMappingURL=wire-message-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire-message-id.d.ts","sourceRoot":"","sources":["../../../src/core/session/wire-message-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AASH;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,QAA8C,CAAC;AAEnF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,QAAgB,CAAC;AAKjD,2EAA2E;AAC3E,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAGxE;AAED,wDAAwD;AACxD,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAMvE;AAYD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAIlE;AAED,6CAA6C;AAC7C,MAAM,WAAW,wBAAwB;IACvC,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;CAC7C;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,MAAM,CAehF"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OpenCode wire message-id clock — framework-free.
|
|
3
|
+
*
|
|
4
|
+
* FORMAT. `msg_` + the LOW 48 bits of `Date.now() * 0x1000` as 12 lowercase
|
|
5
|
+
* hex chars + 14 random base62 chars. OpenCode's own `Identifier.ascending`
|
|
6
|
+
* keeps the low 6 bytes, so the clock wraps every 2^36 ms (~2.2 years); the
|
|
7
|
+
* last wrap was 2026-08-14 11:19:55 UTC.
|
|
8
|
+
*
|
|
9
|
+
* WHY IT MATTERS. A user message's id is its POSITION in the transcript:
|
|
10
|
+
* OpenCode ≤ 1.18.14 decides "has this prompt been answered?" by id order, and
|
|
11
|
+
* every host renders placed messages in id order (`compareMessagesForDisplay`).
|
|
12
|
+
* An id minted from the HIGH bits instead (`kortix sessions send` did this from
|
|
13
|
+
* 2026-08-22 until this module existed) lands ~40 days ahead of every id
|
|
14
|
+
* OpenCode mints itself and renders every later turn above it.
|
|
15
|
+
*
|
|
16
|
+
* The same contract lives in `apps/api/src/projects/wire-message-id.ts` (the
|
|
17
|
+
* API has no `@kortix/sdk` dependency). `tests/spec/wire-message-id.vectors.json`
|
|
18
|
+
* is asserted by both, so a divergence fails two suites.
|
|
19
|
+
*/
|
|
20
|
+
// `BigInt(0x…)`, not `0x…n`: consumers typecheck this package under targets
|
|
21
|
+
// below ES2020, where BigInt literals are a compile error.
|
|
22
|
+
const WIRE_ID_TIME_SCALE = BigInt(0x1000);
|
|
23
|
+
const WIRE_ID_TIME_MASK = BigInt(0xffffffffffff);
|
|
24
|
+
const WIRE_ID_TIME_SPAN = WIRE_ID_TIME_MASK + BigInt(1);
|
|
25
|
+
const HALF_SPAN = WIRE_ID_TIME_SPAN / BigInt(2);
|
|
26
|
+
/**
|
|
27
|
+
* How far an id's clock may sit from the clock it is compared with and still
|
|
28
|
+
* count as placed by it: 1 hour. Every correct mint is within ~2 minutes of its
|
|
29
|
+
* own server timestamp (the backdate below); the high-bits bug put ids ~40 days
|
|
30
|
+
* out. Shared with the API's `MAX_WIRE_ID_CLOCK_CORRECTION`.
|
|
31
|
+
*/
|
|
32
|
+
export const WIRE_ID_CLOCK_TOLERANCE = BigInt(60 * 60 * 1000) * WIRE_ID_TIME_SCALE;
|
|
33
|
+
/**
|
|
34
|
+
* How far back a mint is dated before any transcript lift places it. Too EARLY
|
|
35
|
+
* is self-correcting (the lift raises it above what is on record); too LATE is
|
|
36
|
+
* undetectable downstream, because the next reply is minted from the box clock
|
|
37
|
+
* and would sort above its own prompt.
|
|
38
|
+
*/
|
|
39
|
+
export const WIRE_ID_BACKDATE_MS = 2 * 60 * 1000;
|
|
40
|
+
const WIRE_ID_CLOCK = /^msg_([0-9a-f]{12})/;
|
|
41
|
+
const BASE62 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
42
|
+
/** The 48-bit clock encoded in a wire id, or null when `id` is not one. */
|
|
43
|
+
export function wireIdClock(id) {
|
|
44
|
+
const match = WIRE_ID_CLOCK.exec(id ?? '');
|
|
45
|
+
return match ? BigInt(`0x${match[1]}`) : null;
|
|
46
|
+
}
|
|
47
|
+
/** The unmasked id clock of wall-clock instant `ms`. */
|
|
48
|
+
export function absoluteWireIdClockAt(ms) {
|
|
49
|
+
return BigInt(Math.trunc(ms)) * WIRE_ID_TIME_SCALE;
|
|
50
|
+
}
|
|
51
|
+
/** The 48-bit id clock of wall-clock instant `ms`, as OpenCode writes it. */
|
|
52
|
+
export function wireIdClockAt(ms) {
|
|
53
|
+
return absoluteWireIdClockAt(ms) & WIRE_ID_TIME_MASK;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Undo the 48-bit wrap: the absolute clock congruent to `clock` that is
|
|
57
|
+
* nearest to `anchor` (an absolute clock). Two ids unwrapped against anchors
|
|
58
|
+
* within ~1.1 years of each other keep their true order across a wrap.
|
|
59
|
+
*/
|
|
60
|
+
export function unwrapWireIdClock(clock, anchor) {
|
|
61
|
+
const base = anchor - (anchor & WIRE_ID_TIME_MASK);
|
|
62
|
+
let unwrapped = base + clock;
|
|
63
|
+
if (unwrapped - anchor > HALF_SPAN)
|
|
64
|
+
unwrapped -= WIRE_ID_TIME_SPAN;
|
|
65
|
+
else if (anchor - unwrapped > HALF_SPAN)
|
|
66
|
+
unwrapped += WIRE_ID_TIME_SPAN;
|
|
67
|
+
return unwrapped;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Signed distance from `reference` to `clock` on the 48-bit ring: positive
|
|
71
|
+
* when `clock` is ahead. Wrap-safe for distances under ~1.1 years.
|
|
72
|
+
*/
|
|
73
|
+
function ringDelta(clock, reference) {
|
|
74
|
+
let delta = (clock - reference) & WIRE_ID_TIME_MASK;
|
|
75
|
+
if (delta >= HALF_SPAN)
|
|
76
|
+
delta -= WIRE_ID_TIME_SPAN;
|
|
77
|
+
return delta;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Whether `id` claims a clock more than {@link WIRE_ID_CLOCK_TOLERANCE} ahead
|
|
81
|
+
* of `nowMs`. Such an id cannot have been placed against any real transcript;
|
|
82
|
+
* a floor or a lift must skip it rather than let it veto every later mint.
|
|
83
|
+
*/
|
|
84
|
+
export function isWireIdAheadOf(id, nowMs) {
|
|
85
|
+
const clock = wireIdClock(id);
|
|
86
|
+
if (clock === null)
|
|
87
|
+
return false;
|
|
88
|
+
return ringDelta(clock, wireIdClockAt(nowMs)) > WIRE_ID_CLOCK_TOLERANCE;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Mint an OpenCode wire message id for a prompt.
|
|
92
|
+
*
|
|
93
|
+
* Use this — never a hand-rolled `Date.now()` encoding — for the `messageId`
|
|
94
|
+
* of `session.prompts.create()`. It is dated {@link WIRE_ID_BACKDATE_MS} back
|
|
95
|
+
* and lifted just above the newest id in `after`. A caller that cannot read the
|
|
96
|
+
* transcript should also pass `remintOnDelivery: true`, so the control plane
|
|
97
|
+
* places the id against the live transcript before delivery.
|
|
98
|
+
*/
|
|
99
|
+
export function mintWireMessageId(options = {}) {
|
|
100
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
101
|
+
let encoded = wireIdClockAt(nowMs - WIRE_ID_BACKDATE_MS);
|
|
102
|
+
let newest = null;
|
|
103
|
+
for (const id of options.after ?? []) {
|
|
104
|
+
const clock = wireIdClock(id);
|
|
105
|
+
if (clock === null)
|
|
106
|
+
continue;
|
|
107
|
+
const ahead = ringDelta(clock, encoded);
|
|
108
|
+
if (ahead < BigInt(0) || ahead > WIRE_ID_CLOCK_TOLERANCE)
|
|
109
|
+
continue;
|
|
110
|
+
if (newest === null || ringDelta(clock, newest) > BigInt(0))
|
|
111
|
+
newest = clock;
|
|
112
|
+
}
|
|
113
|
+
if (newest !== null)
|
|
114
|
+
encoded = (newest + BigInt(1)) & WIRE_ID_TIME_MASK;
|
|
115
|
+
let tail = '';
|
|
116
|
+
for (let i = 0; i < 14; i++)
|
|
117
|
+
tail += BASE62[Math.floor(Math.random() * 62)];
|
|
118
|
+
return `msg_${encoded.toString(16).padStart(12, '0')}${tail}`;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=wire-message-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire-message-id.js","sourceRoot":"","sources":["../../../src/core/session/wire-message-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,4EAA4E;AAC5E,2DAA2D;AAC3D,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAC1C,MAAM,iBAAiB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AACjD,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACxD,MAAM,SAAS,GAAG,iBAAiB,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,kBAAkB,CAAC;AAEnF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAEjD,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAC5C,MAAM,MAAM,GAAG,gEAAgE,CAAC;AAEhF,2EAA2E;AAC3E,MAAM,UAAU,WAAW,CAAC,EAA6B;IACvD,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,OAAO,KAAK,CAAC,CAAC,CAAC,M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WorkingStreamInput {
|
|
|
224
224
|
* This one is not an observer. Content arriving is not a report that the
|
|
225
225
|
* runtime is working — it IS the runtime working, and no report outranks it.
|
|
226
226
|
*
|
|
227
|
-
* Reported with a screen recording (
|
|
227
|
+
* Reported with a screen recording (sampleco, 2026-08-23): a tool row with a
|
|
228
228
|
* live spinner and text growing on screen, and a composer showing its send
|
|
229
229
|
* arrow. Every observer had gone quiet; the only thing still speaking was the
|
|
230
230
|
* content, and nothing was listening to it.
|
|
@@ -233,7 +233,7 @@ export interface WorkingStreamInput {
|
|
|
233
233
|
* part off the SSE wire) and PULLED (a liveness-poll tail read whose hydrate
|
|
234
234
|
* shows the transcript moved with its tail still open — `sync-store.hydrate`).
|
|
235
235
|
* The pull path is what answers when the wire itself is the thing that died
|
|
236
|
-
* (
|
|
236
|
+
* (sampleco, 2026-08-26: stream black-holed mid-turn, stale idle frame vetoing
|
|
237
237
|
* the open turn row, transcript minutes behind).
|
|
238
238
|
*/
|
|
239
239
|
export interface WorkingActivityInput {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Can this session show its saved conversation before its computer wakes?
|
|
3
|
+
*
|
|
4
|
+
* The control plane keeps a copy of every session's transcript (the mirror,
|
|
5
|
+
* written at each turn end). It answers in one round trip; the computer takes
|
|
6
|
+
* 5-240 s to wake. A host that knows a saved copy is on its way shows the
|
|
7
|
+
* session with placeholder rows for that one round trip. A host that knows
|
|
8
|
+
* there is none shows its boot screen, because nothing can be read until the
|
|
9
|
+
* runtime is up. This decides which of the two is true, from what the session
|
|
10
|
+
* hook already tracks:
|
|
11
|
+
*
|
|
12
|
+
* `loading` — a saved copy may still paint: a read is in flight, or the
|
|
13
|
+
* OpenCode root it is keyed by is still resolving.
|
|
14
|
+
* `shown` — the store holds messages for this session (saved or live).
|
|
15
|
+
* `none` — nothing can paint before the runtime answers: the saved copy
|
|
16
|
+
* is absent or was refused, or no root is known and no
|
|
17
|
+
* control-plane read is left that could supply one.
|
|
18
|
+
*
|
|
19
|
+
* `none` is only ever an answer the server gave. A hook that has not started
|
|
20
|
+
* its reads yet (no signed-in user) says `loading`: an unknown is never
|
|
21
|
+
* rendered as a negative.
|
|
22
|
+
*/
|
|
23
|
+
export type SavedTranscript = 'loading' | 'shown' | 'none';
|
|
24
|
+
export interface SavedTranscriptInput {
|
|
25
|
+
/** The session hook is running its reads (it waits for a signed-in user). */
|
|
26
|
+
enabled: boolean;
|
|
27
|
+
/** The store holds at least one message for this session's root. */
|
|
28
|
+
hasMessages: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The saved-history read (`GET …/transcript?history=true`), which paints
|
|
31
|
+
* the copy when the project's `session_transcript_history` flag is on.
|
|
32
|
+
* `off` when the flag is off.
|
|
33
|
+
*/
|
|
34
|
+
history: 'off' | 'loading' | 'present' | 'absent';
|
|
35
|
+
/**
|
|
36
|
+
* The mirror paint in `useSessionSync`: `idle` until it can run (no root
|
|
37
|
+
* yet), `loading` while its read is in flight, `painted` once it hydrated,
|
|
38
|
+
* `absent` when the read answered with nothing it may paint.
|
|
39
|
+
*/
|
|
40
|
+
mirror: 'idle' | 'loading' | 'painted' | 'absent';
|
|
41
|
+
/**
|
|
42
|
+
* The OpenCode root the transcript is keyed by: `known`, `pending` while a
|
|
43
|
+
* control-plane read that can supply it is outstanding, or `unknown` when
|
|
44
|
+
* none is left (only the runtime can name it now).
|
|
45
|
+
*/
|
|
46
|
+
root: 'known' | 'pending' | 'unknown';
|
|
47
|
+
}
|
|
48
|
+
export declare function resolveSavedTranscript(input: SavedTranscriptInput): SavedTranscript;
|
|
49
|
+
//# sourceMappingURL=saved-transcript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saved-transcript.d.ts","sourceRoot":"","sources":["../../../src/core/session-sync/saved-transcript.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAE3D,MAAM,WAAW,oBAAoB;IACnC,6EAA6E;IAC7E,OAAO,EAAE,OAAO,CAAC;IACjB,oEAAoE;IACpE,WAAW,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,OAAO,EAAE,KAAK,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;IAClD;;;;OAIG;IACH,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;IAClD;;;;OAIG;IACH,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;CACvC;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,oBAAoB,GAAG,eAAe,CASnF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Can this session show its saved conversation before its computer wakes?
|
|
3
|
+
*
|
|
4
|
+
* The control plane keeps a copy of every session's transcript (the mirror,
|
|
5
|
+
* written at each turn end). It answers in one round trip; the computer takes
|
|
6
|
+
* 5-240 s to wake. A host that knows a saved copy is on its way shows the
|
|
7
|
+
* session with placeholder rows for that one round trip. A host that knows
|
|
8
|
+
* there is none shows its boot screen, because nothing can be read until the
|
|
9
|
+
* runtime is up. This decides which of the two is true, from what the session
|
|
10
|
+
* hook already tracks:
|
|
11
|
+
*
|
|
12
|
+
* `loading` — a saved copy may still paint: a read is in flight, or the
|
|
13
|
+
* OpenCode root it is keyed by is still resolving.
|
|
14
|
+
* `shown` — the store holds messages for this session (saved or live).
|
|
15
|
+
* `none` — nothing can paint before the runtime answers: the saved copy
|
|
16
|
+
* is absent or was refused, or no root is known and no
|
|
17
|
+
* control-plane read is left that could supply one.
|
|
18
|
+
*
|
|
19
|
+
* `none` is only ever an answer the server gave. A hook that has not started
|
|
20
|
+
* its reads yet (no signed-in user) says `loading`: an unknown is never
|
|
21
|
+
* rendered as a negative.
|
|
22
|
+
*/
|
|
23
|
+
export function resolveSavedTranscript(input) {
|
|
24
|
+
if (input.hasMessages)
|
|
25
|
+
return 'shown';
|
|
26
|
+
if (!input.enabled)
|
|
27
|
+
return 'loading';
|
|
28
|
+
if (input.history === 'absent')
|
|
29
|
+
return 'none';
|
|
30
|
+
if (input.history === 'loading')
|
|
31
|
+
return 'loading';
|
|
32
|
+
if (input.root === 'unknown')
|
|
33
|
+
return 'none';
|
|
34
|
+
if (input.root === 'pending')
|
|
35
|
+
return 'loading';
|
|
36
|
+
if (input.mirror === 'absent')
|
|
37
|
+
return 'none';
|
|
38
|
+
return 'loading';
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=saved-transcript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saved-transcript.js","sourceRoot":"","sources":["../../../src/core/session-sync/saved-transcript.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AA6BH,MAAM,UAAU,sBAAsB,CAAC,KAA2B;IAChE,IAAI,KAAK,CAAC,WAAW;QAAE,OAAO,OAAO,CAAC;IACtC,IAAI,CAAC,KAAK,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IACrC,IAAI,KAAK,CAAC,OAAO,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAClD,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IAC5C,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC/C,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IAC7C,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -4,7 +4,7 @@ export declare const SESSION_SYNC_PAGE_SIZE = 100;
|
|
|
4
4
|
* The FIRST page — the one the user waits on.
|
|
5
5
|
*
|
|
6
6
|
* Time to first paint is bytes, not messages. Measured on a heavy session
|
|
7
|
-
* (
|
|
7
|
+
* (sampleco, 2026-08-24, a run with hundreds of image reads whose parts carried
|
|
8
8
|
* base64 — BEFORE the attachment bytes were stripped from the list):
|
|
9
9
|
*
|
|
10
10
|
* message?limit=50 -> 8,228 kB 30.39 s
|
|
@@ -144,8 +144,19 @@ export interface SessionSyncControllerOptions {
|
|
|
144
144
|
* healthy stream the hydrate is a no-op.
|
|
145
145
|
*/
|
|
146
146
|
verifyIntervalMs?: number;
|
|
147
|
+
/**
|
|
148
|
+
* Max time one page read may take before it is abandoned. Default 120s.
|
|
149
|
+
*
|
|
150
|
+
* A read proxied to the sandbox can park forever: a wedged runtime or a
|
|
151
|
+
* stalled proxy hop accepts the request and never answers. Reads are
|
|
152
|
+
* single-flight, so without a bound that one read held the slot and every
|
|
153
|
+
* later repair — turn end, SSE gap, liveness poll — waited on it until the
|
|
154
|
+
* controller was destroyed. On expiry the read's signal is aborted, the slot
|
|
155
|
+
* is released, and the tail read is retried with backoff.
|
|
156
|
+
*/
|
|
157
|
+
readTimeoutMs?: number;
|
|
147
158
|
}
|
|
148
|
-
export interface HttpSessionSyncControllerOptions extends Pick<SessionSyncControllerOptions, 'sessionId' | 'hydrate' | 'markLoaded' | 'setStatus' | 'onTelemetry' | 'scheduler' | 'livenessIntervalMs' | 'verifyIntervalMs'> {
|
|
159
|
+
export interface HttpSessionSyncControllerOptions extends Pick<SessionSyncControllerOptions, 'sessionId' | 'hydrate' | 'markLoaded' | 'setStatus' | 'onTelemetry' | 'scheduler' | 'livenessIntervalMs' | 'verifyIntervalMs' | 'readTimeoutMs'> {
|
|
149
160
|
baseUrl: string;
|
|
150
161
|
getToken?: () => string | null | Promise<string | null>;
|
|
151
162
|
fetch?: SessionSyncFetch;
|
|
@@ -180,6 +191,7 @@ export declare class SessionSyncController {
|
|
|
180
191
|
private readonly scheduler;
|
|
181
192
|
private readonly livenessIntervalMs;
|
|
182
193
|
private readonly verifyIntervalMs;
|
|
194
|
+
private readonly readTimeoutMs;
|
|
183
195
|
/** When the last tail read was ISSUED — see `verifyIntervalMs`. */
|
|
184
196
|
private lastTailReadAt;
|
|
185
197
|
/** Consecutive failed tail reads, for the retry backoff. Reset by success. */
|
|
@@ -234,6 +246,13 @@ export declare class SessionSyncController {
|
|
|
234
246
|
*/
|
|
235
247
|
private scheduleTailRetry;
|
|
236
248
|
private loadPage;
|
|
249
|
+
/**
|
|
250
|
+
* Run one read under its own signal: aborted when the controller is
|
|
251
|
+
* destroyed, and when `readTimeoutMs` elapses. The timeout also rejects the
|
|
252
|
+
* returned promise directly, so a loader that ignores its signal still
|
|
253
|
+
* releases the single-flight slot.
|
|
254
|
+
*/
|
|
255
|
+
private boundedRead;
|
|
237
256
|
private loadCompleteOlderTurn;
|
|
238
257
|
private loadCompleteTurn;
|
|
239
258
|
private rememberUserMessages;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-sync-controller.d.ts","sourceRoot":"","sources":["../../../src/core/session-sync/session-sync-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"session-sync-controller.d.ts","sourceRoot":"","sources":["../../../src/core/session-sync/session-sync-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAmC/E,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAEpF,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,IAAI,EAA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C,MAAM,IAAI,CAAC,CAG9C;IAEF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtB,SAAS,CAAC,MAAM,GAAE,iBAA4B,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB9D,SAAS,QAAO,OAAO,CAAC,IAAI,CAAC,CAkB3B;IAEF,YAAY,IAAI,IAAI;IAOpB;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;IA0B9B,OAAO,IAAI,IAAI;YAgBD,QAAQ;IA8EtB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,iBAAiB;YAcX,QAAQ;IAsCtB;;;;;OAKG;IACH,OAAO,CAAC,WAAW;YAqBL,qBAAqB;YA4BrB,gBAAgB;IAgE9B,OAAO,CAAC,oBAAoB;YAQd,aAAa;IA4B3B,kFAAkF;IAClF,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,MAAM;CAYf"}
|
|
@@ -12,6 +12,19 @@ import { ApiError } from '../http/api/errors.js';
|
|
|
12
12
|
* instead of dragging its entire history over the sandbox proxy.
|
|
13
13
|
*/
|
|
14
14
|
/** First retry delay after a failed tail read. */
|
|
15
|
+
/**
|
|
16
|
+
* Default budget for one page read. A tail page can legitimately take 30-50 s
|
|
17
|
+
* (image-heavy parts, measured 2026-08-24), so this is a hang detector, not a
|
|
18
|
+
* latency target. It matches the SDK's default fetch timeout.
|
|
19
|
+
*/
|
|
20
|
+
const DEFAULT_READ_TIMEOUT_MS = 120_000;
|
|
21
|
+
/** A page read that outlived its budget. Retryable; never a fact about the session. */
|
|
22
|
+
class SessionSyncReadTimeoutError extends Error {
|
|
23
|
+
constructor(timeoutMs) {
|
|
24
|
+
super(`Session history read did not settle within ${timeoutMs}ms`);
|
|
25
|
+
this.name = 'SessionSyncReadTimeoutError';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
15
28
|
const TAIL_RETRY_BASE_MS = 1_000;
|
|
16
29
|
/** Ceiling for the retry backoff — a box that comes back is picked up within it. */
|
|
17
30
|
const TAIL_RETRY_MAX_MS = 15_000;
|
|
@@ -20,7 +33,7 @@ export const SESSION_SYNC_PAGE_SIZE = 100;
|
|
|
20
33
|
* The FIRST page — the one the user waits on.
|
|
21
34
|
*
|
|
22
35
|
* Time to first paint is bytes, not messages. Measured on a heavy session
|
|
23
|
-
* (
|
|
36
|
+
* (sampleco, 2026-08-24, a run with hundreds of image reads whose parts carried
|
|
24
37
|
* base64 — BEFORE the attachment bytes were stripped from the list):
|
|
25
38
|
*
|
|
26
39
|
* message?limit=50 -> 8,228 kB 30.39 s
|
|
@@ -163,6 +176,7 @@ export class SessionSyncController {
|
|
|
163
176
|
scheduler;
|
|
164
177
|
livenessIntervalMs;
|
|
165
178
|
verifyIntervalMs;
|
|
179
|
+
readTimeoutMs;
|
|
166
180
|
/** When the last tail read was ISSUED — see `verifyIntervalMs`. */
|
|
167
181
|
lastTailReadAt;
|
|
168
182
|
/** Consecutive failed tail reads, for the retry backoff. Reset by success. */
|
|
@@ -195,6 +209,7 @@ export class SessionSyncController {
|
|
|
195
209
|
this.scheduler = options.scheduler ?? defaultScheduler;
|
|
196
210
|
this.livenessIntervalMs = options.livenessIntervalMs ?? 10_000;
|
|
197
211
|
this.verifyIntervalMs = options.verifyIntervalMs ?? 30_000;
|
|
212
|
+
this.readTimeoutMs = options.readTimeoutMs ?? DEFAULT_READ_TIMEOUT_MS;
|
|
198
213
|
this.lastActivityAt = this.scheduler.now();
|
|
199
214
|
this.lastTailReadAt = this.scheduler.now();
|
|
200
215
|
}
|
|
@@ -316,7 +331,7 @@ export class SessionSyncController {
|
|
|
316
331
|
// message?limit=50&before=.. 200 25,125 kB 29.23 s
|
|
317
332
|
// -> 78,097 kB transferred, finish 3.8 min, NOTHING on screen
|
|
318
333
|
//
|
|
319
|
-
// (
|
|
334
|
+
// (sampleco, 2026-08-24, a run with hundreds of image reads: fifty
|
|
320
335
|
// messages weigh 8-25 MB because the parts carry the image bytes.)
|
|
321
336
|
//
|
|
322
337
|
// There used to be a backward WALK here that kept fetching pages until
|
|
@@ -359,14 +374,21 @@ export class SessionSyncController {
|
|
|
359
374
|
return;
|
|
360
375
|
// A superseded/cancelled read is not a failure and never hydrates — it
|
|
361
376
|
// must not paint an error over a live transcript, and it must not retry.
|
|
362
|
-
if (
|
|
377
|
+
if (this.abortController.signal.aborted)
|
|
378
|
+
return;
|
|
379
|
+
const timedOut = error instanceof SessionSyncReadTimeoutError;
|
|
380
|
+
if (!timedOut && isAbortError(error))
|
|
363
381
|
return;
|
|
364
382
|
// A sandbox that is still waking is a RETRYABLE, "loading" state, not a
|
|
365
383
|
// fault: the box may come up any second, so keep polling and keep the UI
|
|
366
384
|
// on its loader. Only a genuine failure earns `error`. NEVER an
|
|
367
385
|
// empty-`fresh` — `markLoaded` above ran only on success, so a failed
|
|
368
|
-
// read never records the session as an empty transcript.
|
|
369
|
-
|
|
386
|
+
// read never records the session as an empty transcript. A read that
|
|
387
|
+
// outlived its budget says nothing about the session either: keep the
|
|
388
|
+
// `loading`/`stale` state `reconcile` set and retry.
|
|
389
|
+
if (!timedOut) {
|
|
390
|
+
this.update({ freshness: isSandboxNotReadyError(error) ? 'loading' : 'error' });
|
|
391
|
+
}
|
|
370
392
|
if (error instanceof ApiError && (error.status === 404 || error.status === 410)) {
|
|
371
393
|
this.tailUnavailable = true;
|
|
372
394
|
this.cancelTimer(this.tailRetryTimer);
|
|
@@ -402,12 +424,12 @@ export class SessionSyncController {
|
|
|
402
424
|
async loadPage(operation, reason, before) {
|
|
403
425
|
const startedAt = this.scheduler.now();
|
|
404
426
|
try {
|
|
405
|
-
const page = await this.options.loadPage({
|
|
427
|
+
const page = await this.boundedRead((signal) => this.options.loadPage({
|
|
406
428
|
// The tail is what someone is waiting for; an older page is what they
|
|
407
429
|
// asked for. Different budgets — see SESSION_SYNC_TAIL_PAGE_SIZE.
|
|
408
430
|
limit: operation === 'tail' ? SESSION_SYNC_TAIL_PAGE_SIZE : SESSION_SYNC_PAGE_SIZE,
|
|
409
431
|
...(before ? { before } : {}),
|
|
410
|
-
},
|
|
432
|
+
}, signal));
|
|
411
433
|
this.options.onTelemetry?.({
|
|
412
434
|
operation,
|
|
413
435
|
reason,
|
|
@@ -428,6 +450,33 @@ export class SessionSyncController {
|
|
|
428
450
|
throw error;
|
|
429
451
|
}
|
|
430
452
|
}
|
|
453
|
+
/**
|
|
454
|
+
* Run one read under its own signal: aborted when the controller is
|
|
455
|
+
* destroyed, and when `readTimeoutMs` elapses. The timeout also rejects the
|
|
456
|
+
* returned promise directly, so a loader that ignores its signal still
|
|
457
|
+
* releases the single-flight slot.
|
|
458
|
+
*/
|
|
459
|
+
boundedRead(read) {
|
|
460
|
+
const lifetime = this.abortController.signal;
|
|
461
|
+
const controller = new AbortController();
|
|
462
|
+
const onLifetimeAbort = () => controller.abort(lifetime.reason);
|
|
463
|
+
if (lifetime.aborted)
|
|
464
|
+
controller.abort(lifetime.reason);
|
|
465
|
+
else
|
|
466
|
+
lifetime.addEventListener('abort', onLifetimeAbort, { once: true });
|
|
467
|
+
let timer;
|
|
468
|
+
const deadline = new Promise((_resolve, reject) => {
|
|
469
|
+
timer = this.startTimer(() => {
|
|
470
|
+
const error = new SessionSyncReadTimeoutError(this.readTimeoutMs);
|
|
471
|
+
reject(error);
|
|
472
|
+
controller.abort(error);
|
|
473
|
+
}, this.readTimeoutMs);
|
|
474
|
+
});
|
|
475
|
+
return Promise.race([read(controller.signal), deadline]).finally(() => {
|
|
476
|
+
this.cancelTimer(timer);
|
|
477
|
+
lifetime.removeEventListener('abort', onLifetimeAbort);
|
|
478
|
+
});
|
|
479
|
+
}
|
|
431
480
|
async loadCompleteOlderTurn(before) {
|
|
432
481
|
const firstPage = await this.loadPage('older', 'manual', before);
|
|
433
482
|
// Commit each page as it lands, including the page that fails. The walk
|