@kortix/sdk 0.13.54 → 0.13.55
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 +34 -9
- package/dist/browser/stores/sync-store.d.ts +20 -0
- package/dist/browser/stores/sync-store.d.ts.map +1 -1
- package/dist/browser/stores/sync-store.js +65 -23
- package/dist/browser/stores/sync-store.js.map +1 -1
- package/dist/core/auth/app-viewer.d.ts +1 -1
- package/dist/core/auth/app-viewer.js +1 -1
- package/dist/core/client/kortix.d.ts +3 -0
- package/dist/core/client/kortix.d.ts.map +1 -1
- package/dist/core/client/kortix.js +3 -0
- package/dist/core/client/kortix.js.map +1 -1
- package/dist/core/client/project-access-resources.d.ts +1 -1
- package/dist/core/client/project-access-resources.d.ts.map +1 -1
- package/dist/core/client/project-access-resources.js +1 -1
- package/dist/core/client/project-access-resources.js.map +1 -1
- package/dist/core/client/project-core.d.ts.map +1 -1
- package/dist/core/rest/platform-client/client-policy.d.ts +21 -0
- package/dist/core/rest/platform-client/client-policy.d.ts.map +1 -0
- package/dist/core/rest/platform-client/client-policy.js +49 -0
- package/dist/core/rest/platform-client/client-policy.js.map +1 -0
- package/dist/core/rest/platform-client/index.d.ts +1 -0
- package/dist/core/rest/platform-client/index.d.ts.map +1 -1
- package/dist/core/rest/platform-client/index.js +1 -0
- package/dist/core/rest/platform-client/index.js.map +1 -1
- package/dist/core/rest/projects-client/apps-fleet.js +1 -1
- package/dist/core/rest/projects-client/apps.d.ts +18 -2
- package/dist/core/rest/projects-client/apps.d.ts.map +1 -1
- package/dist/core/rest/projects-client/apps.js.map +1 -1
- package/dist/core/rest/projects-client/projects.d.ts +6 -1
- package/dist/core/rest/projects-client/projects.d.ts.map +1 -1
- package/dist/core/rest/projects-client/projects.js +3 -0
- package/dist/core/rest/projects-client/projects.js.map +1 -1
- package/dist/core/session/control-stream.d.ts +12 -0
- package/dist/core/session/control-stream.d.ts.map +1 -1
- package/dist/core/session/control-stream.js +22 -1
- package/dist/core/session/control-stream.js.map +1 -1
- package/dist/core/session-log/guard.d.ts +18 -0
- package/dist/core/session-log/guard.d.ts.map +1 -0
- package/dist/core/session-log/guard.js +114 -0
- package/dist/core/session-log/guard.js.map +1 -0
- package/dist/core/session-log/index.d.ts +16 -0
- package/dist/core/session-log/index.d.ts.map +1 -0
- package/dist/core/session-log/index.js +15 -0
- package/dist/core/session-log/index.js.map +1 -0
- package/dist/core/session-log/saved-log.d.ts +23 -0
- package/dist/core/session-log/saved-log.d.ts.map +1 -0
- package/dist/core/session-log/saved-log.js +34 -0
- package/dist/core/session-log/saved-log.js.map +1 -0
- package/dist/core/session-log/source.d.ts +36 -0
- package/dist/core/session-log/source.d.ts.map +1 -0
- package/dist/core/session-log/source.js +52 -0
- package/dist/core/session-log/source.js.map +1 -0
- package/dist/core/session-log/store.d.ts +25 -0
- package/dist/core/session-log/store.d.ts.map +1 -0
- package/dist/core/session-log/store.js +170 -0
- package/dist/core/session-log/store.js.map +1 -0
- package/dist/core/session-log/types.d.ts +371 -0
- package/dist/core/session-log/types.d.ts.map +1 -0
- package/dist/core/session-log/types.js +24 -0
- package/dist/core/session-log/types.js.map +1 -0
- package/dist/core/session-log/v1-view.d.ts +30 -0
- package/dist/core/session-log/v1-view.d.ts.map +1 -0
- package/dist/core/session-log/v1-view.js +106 -0
- package/dist/core/session-log/v1-view.js.map +1 -0
- package/dist/core/session-log/v1.d.ts +107 -0
- package/dist/core/session-log/v1.d.ts.map +1 -0
- package/dist/core/session-log/v1.js +495 -0
- package/dist/core/session-log/v1.js.map +1 -0
- package/dist/core/session-sync/copy-store-types.d.ts +29 -0
- package/dist/core/session-sync/copy-store-types.d.ts.map +1 -0
- package/dist/core/session-sync/copy-store-types.js +2 -0
- package/dist/core/session-sync/copy-store-types.js.map +1 -0
- package/dist/core/session-sync/saved-copy-store.d.ts +5 -0
- package/dist/core/session-sync/saved-copy-store.d.ts.map +1 -1
- package/dist/core/session-sync/saved-copy-store.js +30 -4
- package/dist/core/session-sync/saved-copy-store.js.map +1 -1
- package/dist/core/turns/segments/index.d.ts +1 -0
- package/dist/core/turns/segments/index.d.ts.map +1 -1
- package/dist/core/turns/segments/index.js +1 -0
- package/dist/core/turns/segments/index.js.map +1 -1
- package/dist/core/turns/segments/work-split.d.ts +16 -0
- package/dist/core/turns/segments/work-split.d.ts.map +1 -0
- package/dist/core/turns/segments/work-split.js +59 -0
- package/dist/core/turns/segments/work-split.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/kortix.esm.min.js +33 -33
- package/dist/kortix.global.js +34 -34
- package/dist/react/opencode.d.ts +1 -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/session-transcript-subscription.d.ts +5 -1
- package/dist/react/session-transcript-subscription.d.ts.map +1 -1
- package/dist/react/session-transcript-subscription.js +8 -2
- package/dist/react/session-transcript-subscription.js.map +1 -1
- package/dist/react/sign-in-with-kortix.d.ts +1 -1
- package/dist/react/use-opencode-events/handle-event.d.ts +6 -0
- package/dist/react/use-opencode-events/handle-event.d.ts.map +1 -1
- package/dist/react/use-opencode-events/handle-event.js +5 -0
- package/dist/react/use-opencode-events/handle-event.js.map +1 -1
- package/dist/react/use-opencode-events/index.d.ts.map +1 -1
- package/dist/react/use-opencode-events/index.js +1 -0
- package/dist/react/use-opencode-events/index.js.map +1 -1
- package/dist/react/use-session-log.d.ts +52 -0
- package/dist/react/use-session-log.d.ts.map +1 -0
- package/dist/react/use-session-log.js +166 -0
- package/dist/react/use-session-log.js.map +1 -0
- package/dist/react/use-session.d.ts.map +1 -1
- package/dist/react/use-session.js +4 -0
- package/dist/react/use-session.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ One connector as a handle: `run` returns the output itself and throws
|
|
|
84
84
|
`upstreamStatus`, `retryAfterSeconds`) or `ConnectorApprovalPendingError`;
|
|
85
85
|
`paginate` follows a cursor and throws `ConnectorPageLimitError` (with
|
|
86
86
|
`nextArgs`) past `maxPages`; `useConnectorQuery` (`@kortix/sdk/react`) caches a
|
|
87
|
-
read. Guide: `/docs/
|
|
87
|
+
read. Guide: `/docs/connect/connectors#call-connectors-from-code`; runnable: `examples/13-connectors-as-code.ts`.
|
|
88
88
|
|
|
89
89
|
```ts
|
|
90
90
|
const linear = kortix.project(projectId).connector('linear');
|
|
@@ -154,7 +154,7 @@ The browser path needs the App's viewer scope set to `api`
|
|
|
154
154
|
`403 insufficient_scope`. A service account answers `403` until a person
|
|
155
155
|
grants it a project role (`kortix access grant --service-account <id> --role
|
|
156
156
|
member --project <id>`). Never put a provider API key in an App or a Convex
|
|
157
|
-
deployment when a connector exists. Guide: `/docs/
|
|
157
|
+
deployment when a connector exists. Guide: `/docs/connect/connectors#call-connectors-from-code`.
|
|
158
158
|
|
|
159
159
|
### Upload prompt attachments before Send
|
|
160
160
|
|
|
@@ -402,7 +402,7 @@ both the pool list and the session's provider-specific query cache.
|
|
|
402
402
|
|
|
403
403
|
### Apps
|
|
404
404
|
|
|
405
|
-
`kortix.project(projectId).apps` deploys immutable App releases behind one stable URL
|
|
405
|
+
`kortix.project(projectId).apps` deploys immutable App releases behind one stable URL: releases, machines per process group, persistent volumes. New Apps use `private` access. Apps is an experimental project feature, so API operations return `404` until a project manager enables it.
|
|
406
406
|
|
|
407
407
|
```ts
|
|
408
408
|
const apps = kortix.project(projectId).apps;
|
|
@@ -429,7 +429,7 @@ Branch on `app.capabilities` (`machines`, `scale`, `exec`, `volumes`, `snapshots
|
|
|
429
429
|
```ts
|
|
430
430
|
await apps.deployments.create(api.app_id, {
|
|
431
431
|
artifact_id, source: { kind: 'oci_image', image, command: ['node', 'server.js'] },
|
|
432
|
-
config: { // the release config (kortix.yaml apps.<name>
|
|
432
|
+
config: { // the release config (kortix.yaml apps.<name>)
|
|
433
433
|
processes: { app: '', worker: 'node worker.js' },
|
|
434
434
|
http_service: { internal_port: 3000, access: 'app', processes: ['app'] },
|
|
435
435
|
mounts: [{ source: 'data', destination: '/data', initial_size_gb: 10, processes: ['app'] }],
|
|
@@ -442,6 +442,7 @@ const [data] = await apps.volumes.list(api.app_id);
|
|
|
442
442
|
const snap = await apps.volumes.snapshot(api.app_id, data.volume_id);
|
|
443
443
|
await apps.volumes.restore(api.app_id, data.volume_id, snap.snapshot_id); // project.app.admin
|
|
444
444
|
await apps.update(site.app_id, { uses: ['api'], labels: ['frontend'] }); // the site may mint api tokens and bind to it
|
|
445
|
+
await apps.update(api.app_id, { display: { preview: 'none' } }); // its Apps-tab card shows an icon, not a live thumbnail
|
|
445
446
|
```
|
|
446
447
|
|
|
447
448
|
`@kortix/sdk/react` adds `useAppMachines`, `useAppVolumes`, and `useAppVolumeSnapshots`.
|
|
@@ -570,6 +571,7 @@ exhaustive — see `API-MAP.md` for the full per-domain surface:
|
|
|
570
571
|
| `kortix.github` | account-scoped GitHub App installs and repo linking: `getInstallation` · `listInstallations` · `listLinkableInstallations` (each entry carries `linked_to_other_accounts`, a count and never a tenant name) · `listRepositories` · `listRepositoryBranches` · `linkInstallation` · `saveInstallation` · `deleteInstallation` · `linkRepository` (`source: 'managed'` imports a repository the instance backend holds — self-host operator only, and mutually exclusive with `installation_id`) · `replaceProjectRepository` (changes an existing project's repository with an expected old URL; accepts a repository-scoped PAT or a temporary GitHub user proof for a repository-scoped App grant; can atomically copy selected shared runtime secrets from another project in the same account) |
|
|
571
572
|
| `kortix.gitBackend` | the instance git backend ("Kortix managed", one per deployment, never an account connection): `get()` → `{configured, kind: 'app'|'pat'|null, owner}` (any authenticated user) · `repositories({search?, limit?})` (self-host operator only; 403 otherwise) |
|
|
572
573
|
| `kortix.notifications` | the caller's notifications, across accounts: `list({ limit?, before? })` (inbox page + `unread_count`) · `markRead({ ids } \| { all: true } \| { sessionId })` · `preferences` · `updatePreferences({ kinds })` (push and email per kind) · `webPushPublicKey` · `registerWebPushSubscription` · `unregisterWebPushSubscription` · `registerDeviceToken` · `unregisterDeviceToken` (native Expo push). Muting one session is `session(pid, sid).setWatch(false)`. Hooks: `useNotificationInbox`, `useNotificationPreferences`, `useSessionWatch`. Inbox rows, Web Push, email, and session watch are served only for projects with the `notification_center` flag on, off by default; with it off, the session creator's phone still gets the push |
|
|
574
|
+
| `kortix.mobileClientPolicy()` | the operator's mobile release policy, `GET /v1/clients/mobile`, **no token needed** (read before login): resolves `{ minimum_version, store_url_ios, store_url_android }`, each a string or `null`; a non-200 answer throws `ApiError`. A mobile host compares its app version to `minimum_version` with `compareSemver(a, b)` (`-1 \| 0 \| 1`, or `null` when either side does not parse; ignores a leading `v` and `-pre`/`+build` suffixes) and fails open on `null`. Also exported standalone as `getMobileClientPolicy` and the `MobileClientPolicy` type. The operator sets `MOBILE_MIN_VERSION`, `MOBILE_STORE_URL_IOS`, `MOBILE_STORE_URL_ANDROID` on the API |
|
|
573
575
|
| `kortix.validateToken()` | pasted-API-key validation helper — `GET /accounts/me`, never throws, resolves `{valid, identity?, error?}` |
|
|
574
576
|
| `kortix.connectors` | Connector data plane for an agent-minted session token: `catalog` · `tools` · `search` · `describe` · `call` (`{ account }`) · `accounts` · `uploadAttachment` |
|
|
575
577
|
| `kortix.project(id)` | id-bound handle: `.apps` (stable App URLs, access, artifacts, deployments, logs, rollback, start/stop, machines (`machines.list/start/stop/restart/destroy`, `scale`, `exec`), volumes (`volumes.list/create/update/destroy/snapshots/snapshot/restore/fork`), and `token`) · `.secrets` · `.access` · `.connectors` (data plane + configuration + Connections) · `.policies` · `.triggers` (cron / webhook / monitor / event; `.eventTypes({ connector })` lists a connector's app events) · `.files` · `.git` · `.changeRequests` (incl. `requestChanges`) · `.sessions` · `.tokens` (project-scoped CLI PATs — the `KORTIX_TOKEN` shape) · `.marketplace` / `.registry` (install/update/remove catalog items) · `.setupLinks.{requestSecret,requestConnector}` (agent-minted secret-entry / connector links) · `.validateManifest` · `.gitToken` · `.setDefaultAgent(name)` · `.session(sid)` (+ more namespaces: `.review`, `.approvals`, `.gateway` (incl. `.routing` and `.playground`), `.channels`, `.modelDefaults`, `.sandbox`) |
|
|
@@ -680,6 +682,29 @@ events it replaced.
|
|
|
680
682
|
`@kortix/sdk/react`'s `useRuntimeEventStream` uses the exact same primitive
|
|
681
683
|
under the hood — it just also writes into the React Query cache.
|
|
682
684
|
|
|
685
|
+
## Session log types
|
|
686
|
+
|
|
687
|
+
The root entry exports the types of the Kortix session log, `kortix.session/2`
|
|
688
|
+
minor 1: `SessionLog`, `SessionLogThread`, `SessionLogMessage` and
|
|
689
|
+
`SessionLogBlock`, the block variants `TextBlock`, `ReasoningBlock`,
|
|
690
|
+
`AttachmentBlock`, `ToolCallBlock`, `CompactionBlock`, `SubtaskBlock`,
|
|
691
|
+
`StepBlock` and `HarnessBlock`, the grade types (`RestoreGrade`, `GradeCounts`),
|
|
692
|
+
and the constants `SESSION_LOG_SCHEMA`, `SESSION_LOG_MINOR` and
|
|
693
|
+
`KNOWN_TOOL_KINDS`. They are types and constants only: this package has no
|
|
694
|
+
`zod` dependency. The validators (`SessionLogSchema` and the rest) stay in the
|
|
695
|
+
private `@kortix/api-contract` package. The types are a copy of the api-contract
|
|
696
|
+
session-log types, and a test fails when the two differ. See the
|
|
697
|
+
[reference](https://kortix.com/docs/sdk/reference#session-log-types).
|
|
698
|
+
|
|
699
|
+
`@kortix/sdk/react` adds `useSessionLog(session)` and
|
|
700
|
+
`useSessionLogThread(session, threadId?)`: the log of a session `useSession`
|
|
701
|
+
owns, or `null` while the session reads v1. A session reads the log only when
|
|
702
|
+
the runtime lists `session.log.v2`, the project flag `session_log` is on, and
|
|
703
|
+
the API holds a log for an OpenCode session; every other session reads v1. The v1
|
|
704
|
+
hooks (`useSessionMessages`, `useSession().messages`) return the same rows
|
|
705
|
+
either way. See the
|
|
706
|
+
[reference](https://kortix.com/docs/sdk/react#read-the-session-log).
|
|
707
|
+
|
|
683
708
|
## Kortix as a Backend (server-side)
|
|
684
709
|
|
|
685
710
|
`createKortix()` stores its config — crucially, the bearer-token getter — in a
|
|
@@ -1007,7 +1032,7 @@ const client = createKortix(auth.clientConfig()); // talks to Kortix through /p
|
|
|
1007
1032
|
```
|
|
1008
1033
|
|
|
1009
1034
|
`@kortix/sdk/react` adds `useKortixViewer()` and `<SignInWithKortix />`.
|
|
1010
|
-
Full guide: `/docs/sdk/sign-in`. Example: `examples/11-sign-in-with-kortix.ts`.
|
|
1035
|
+
Full guide: `/docs/sdk/auth#sign-in-with-kortix`. Example: `examples/11-sign-in-with-kortix.ts`.
|
|
1011
1036
|
|
|
1012
1037
|
### A Kortix-hosted App is already signed in
|
|
1013
1038
|
|
|
@@ -1025,13 +1050,13 @@ the API refused (after an access-policy change) and replays the call once.
|
|
|
1025
1050
|
In the browser, `backendUrl` is `/_kortix/api/v1`: the gate on the App's own
|
|
1026
1051
|
origin forwards to the Kortix API as the viewer (`viewer_token_scope: 'api'`).
|
|
1027
1052
|
A direct call to `https://api.kortix.com/v1` from an App origin fails CORS.
|
|
1028
|
-
Guide: `/docs/
|
|
1053
|
+
Guide: `/docs/apps#build-on-apps-from-typescript`.
|
|
1029
1054
|
|
|
1030
1055
|
### One member on every runtime: sign-in tokens, groups, roles
|
|
1031
1056
|
|
|
1032
1057
|
```ts
|
|
1033
|
-
const
|
|
1034
|
-
convex = new ConvexReactClient(
|
|
1058
|
+
const backend = kortixBinding('backend'); // an App this App uses, same origin
|
|
1059
|
+
convex = new ConvexReactClient(backend.url); convex.setAuth(backend.token); // its client, signed in as the viewer
|
|
1035
1060
|
const token = await kortixToken()(); // a token for this App itself
|
|
1036
1061
|
const me = requireKortixMember(await ctx.auth.getUserIdentity(), { groups: ['Finance'] }); // a server function
|
|
1037
1062
|
const caller = await verifyKortixToken(bearer); // a server App (Kortix injects KORTIX_AUTH_*)
|
|
@@ -1052,7 +1077,7 @@ header, sign-in token) into one `KortixMember`: `userId`, `email`, `name`,
|
|
|
1052
1077
|
`forbidden`). In React, read the member with a `members:me` query (`readKortixMember(await ctx.auth.getUserIdentity())` in `convex/members.ts`, then `useQuery(api.members.me)`: `undefined` loading, `null` signed out). Never call `useConvexAuth()`: it throws under a plain `ConvexProvider`. Kortix injects `KORTIX_AUTH_ISSUER`, `KORTIX_AUTH_AUDIENCE` (the App's own id) and `KORTIX_AUTH_JWKS` into every server App, so do not set `KORTIX_AUTH_*` in its `env`. `verifyKortixToken` takes the key set inline or as an https URL
|
|
1053
1078
|
(`auth.jwks_uri`), and refuses every token when no audience is set (option or
|
|
1054
1079
|
`KORTIX_AUTH_AUDIENCE`): one project key signs every App's tokens, so `aud` is
|
|
1055
|
-
the only thing that keeps another App's token out. `audience: false` opts out. WebCrypto only; no dependency. Guide: `/docs/
|
|
1080
|
+
the only thing that keeps another App's token out. `audience: false` opts out. WebCrypto only; no dependency. Guide: `/docs/apps#build-on-apps-from-typescript`.
|
|
1056
1081
|
|
|
1057
1082
|
### Headless sign-in (your users, straight through the API)
|
|
1058
1083
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Message, Event as RuntimeEvent, Part, SessionStatus, Todo } from "../../core/runtime/runtime-types.js";
|
|
2
|
+
import type { SessionLogPage } from "../../core/session-log/source.js";
|
|
3
|
+
import { type SessionLogEventInput, type SessionLogState } from "../../core/session-log/store.js";
|
|
2
4
|
import { ascendingId } from "./sync-store/ascending-id.js";
|
|
3
5
|
import { Binary } from "./sync-store/binary.js";
|
|
4
6
|
import type { FileDiff, MessageError, MessageWithParts, SessionRewindState } from "./sync-store/types.js";
|
|
@@ -106,7 +108,25 @@ interface SyncState {
|
|
|
106
108
|
* `clearSessionRevertNeedsTailReconcile` once a consumer has acted on it.
|
|
107
109
|
*/
|
|
108
110
|
sessionRevertNeedsTailReconcile: Record<string, boolean>;
|
|
111
|
+
/**
|
|
112
|
+
* The session log (`kortix.session/2`) of each session that negotiated v2, keyed
|
|
113
|
+
* by the KORTIX session id (`core/session-log/store.ts` has the shape and the
|
|
114
|
+
* merge rules). Empty for every v1 session. When it holds a thread, the v1
|
|
115
|
+
* hooks read that thread through `toV1` (`selectSessionRows`).
|
|
116
|
+
*/
|
|
117
|
+
sessionLogs: Record<string, SessionLogState>;
|
|
118
|
+
/**
|
|
119
|
+
* The v1 frames. A session log's `log.*` frames do not come through here:
|
|
120
|
+
* they name no Kortix session, so the stream that carries them (it knows its
|
|
121
|
+
* session) calls `applySessionLogEvent`.
|
|
122
|
+
*/
|
|
109
123
|
applyEvent: (event: RuntimeEvent) => void;
|
|
124
|
+
/** Merge one page of the session log (`GET …/log`) into session `sessionId`'s log. */
|
|
125
|
+
applySessionLogPage: (sessionId: string, page: SessionLogPage) => void;
|
|
126
|
+
/** Apply one `log.*` frame to session `sessionId`'s log, creating it when absent. */
|
|
127
|
+
applySessionLogEvent: (sessionId: string, event: SessionLogEventInput) => void;
|
|
128
|
+
/** Forget session `sessionId`'s log: its v1 hooks read the v1 store again. */
|
|
129
|
+
dropSessionLog: (sessionId: string) => void;
|
|
110
130
|
upsertMessage: (sessionID: string, message: Message) => void;
|
|
111
131
|
removeMessage: (sessionID: string, messageID: string) => void;
|
|
112
132
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-store.d.ts","sourceRoot":"","sources":["../../../src/browser/stores/sync-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,OAAO,EACP,KAAK,IAAI,YAAY,EACrB,IAAI,EAEJ,aAAa,EAEb,IAAI,EACJ,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"sync-store.d.ts","sourceRoot":"","sources":["../../../src/browser/stores/sync-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,OAAO,EACP,KAAK,IAAI,YAAY,EACrB,IAAI,EAEJ,aAAa,EAEb,IAAI,EACJ,MAAM,kCAAkC,CAAC;AAQ1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAIN,KAAK,oB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M,KAAK,MAAM,IAAI,CAAC;IACjD;;;;;;;;;;;;;;;;;OAiBG;IACH,oBAAoB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;IACrD;;;;;;;;;;;;;;OAcG;IACH,oBAAoB,EAAE,CACrB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,OAAO,EAAE,GAAG,SAAS,EAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,KACzB,gBAAgB,EAAE,CAAC;IACxB,OAAO,EAAE,CACR,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,IAAI,EAAE,CAAA;KAAE,CAAC;IAC7C;;;;;OAKG;IACH,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KAAE,KACnC,IAAI,CAAC;IACV,KAAK,EAAE,MAAM,IAAI,CAAC;IAGlB,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,gBAAgB,EAAE,CAAC;IAIvD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CACxC;AAoDD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAMtE;AA0pBD,eAAO,MAAM,YAAY,wEA0kDtB,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { create } from "zustand";
|
|
3
3
|
import { commitSessionRewind, isWithinRewindWindow, stageSessionRewind, } from "../../core/session/rewind.js";
|
|
4
|
+
import { EMPTY_SESSION_LOG_STATE, applySessionLogEvent, applySessionLogPage, } from "../../core/session-log/store.js";
|
|
4
5
|
import { isRetryableTurnError } from "../../core/turns/open-turn.js";
|
|
5
6
|
import { ascendingId } from "./sync-store/ascending-id.js";
|
|
6
7
|
import { Binary } from "./sync-store/binary.js";
|
|
@@ -729,6 +730,53 @@ function pruneDetachedSessions(messages) {
|
|
|
729
730
|
return evicted;
|
|
730
731
|
}
|
|
731
732
|
// ============================================================================
|
|
733
|
+
/**
|
|
734
|
+
* Record that the delta event `id` for `tailKey` (`message:part:field`) is
|
|
735
|
+
* applied. False when it already was: a duplicate delivery, see
|
|
736
|
+
* `deltaEventTails`. Call it only once the delta has a target.
|
|
737
|
+
*/
|
|
738
|
+
function takeDeltaEventId(sessionID, tailKey, id) {
|
|
739
|
+
let sessionTails = deltaEventTails.get(sessionID);
|
|
740
|
+
if (!sessionTails) {
|
|
741
|
+
sessionTails = new Map();
|
|
742
|
+
deltaEventTails.set(sessionID, sessionTails);
|
|
743
|
+
}
|
|
744
|
+
let appliedIds = sessionTails.get(tailKey);
|
|
745
|
+
if (appliedIds?.has(id))
|
|
746
|
+
return false;
|
|
747
|
+
if (!appliedIds) {
|
|
748
|
+
appliedIds = new Set();
|
|
749
|
+
sessionTails.set(tailKey, appliedIds);
|
|
750
|
+
}
|
|
751
|
+
appliedIds.add(id);
|
|
752
|
+
// Bounded window: a Set iterates in insertion order, so the first key is
|
|
753
|
+
// the oldest applied id.
|
|
754
|
+
if (appliedIds.size > DELTA_EVENT_TAIL_LIMIT) {
|
|
755
|
+
const oldest = appliedIds.values().next().value;
|
|
756
|
+
if (oldest !== undefined)
|
|
757
|
+
appliedIds.delete(oldest);
|
|
758
|
+
}
|
|
759
|
+
return true;
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* One `log.*` frame into `sessionId`'s log. `log.block.delta` shares the v1
|
|
763
|
+
* delta path's duplicate-delivery check (keyed by thread, the runtime session
|
|
764
|
+
* id) and counts as runtime activity, as `message.part.delta` does.
|
|
765
|
+
*/
|
|
766
|
+
function applySessionLogFrame(sessionId, event) {
|
|
767
|
+
const state = useSyncStore.getState();
|
|
768
|
+
const current = state.sessionLogs[sessionId] ?? EMPTY_SESSION_LOG_STATE;
|
|
769
|
+
const next = applySessionLogEvent(current, event);
|
|
770
|
+
if (next === current)
|
|
771
|
+
return;
|
|
772
|
+
if (event.type === "log.block.delta") {
|
|
773
|
+
const p = event.properties;
|
|
774
|
+
if (event.id && !takeDeltaEventId(p.thread_id, `${p.message_id}:${p.block_id}:log`, event.id))
|
|
775
|
+
return;
|
|
776
|
+
state.noteSessionActivity(p.thread_id);
|
|
777
|
+
}
|
|
778
|
+
useSyncStore.setState((s) => ({ sessionLogs: { ...s.sessionLogs, [sessionId]: next } }));
|
|
779
|
+
}
|
|
732
780
|
/**
|
|
733
781
|
* Append wire deltas to one part field in ONE store update. `applyPartDelta`
|
|
734
782
|
* passes one; a coalesced `message.part.delta` passes the run it stands for.
|
|
@@ -757,29 +805,8 @@ function appendPartDeltas(sessionID, messageID, partID, field, pieces) {
|
|
|
757
805
|
// later LEGITIMATE redelivery of that same event once the part
|
|
758
806
|
// did exist. See "a delta that finds no target part does not
|
|
759
807
|
// consume the event id" in the test file.
|
|
760
|
-
if (piece.id
|
|
761
|
-
|
|
762
|
-
let sessionTails = deltaEventTails.get(sessionID);
|
|
763
|
-
if (!sessionTails) {
|
|
764
|
-
sessionTails = new Map();
|
|
765
|
-
deltaEventTails.set(sessionID, sessionTails);
|
|
766
|
-
}
|
|
767
|
-
let appliedIds = sessionTails.get(tailKey);
|
|
768
|
-
if (appliedIds?.has(piece.id))
|
|
769
|
-
continue;
|
|
770
|
-
if (!appliedIds) {
|
|
771
|
-
appliedIds = new Set();
|
|
772
|
-
sessionTails.set(tailKey, appliedIds);
|
|
773
|
-
}
|
|
774
|
-
appliedIds.add(piece.id);
|
|
775
|
-
// Bounded window: a Set iterates in insertion order, so the
|
|
776
|
-
// first key is the oldest applied id.
|
|
777
|
-
if (appliedIds.size > DELTA_EVENT_TAIL_LIMIT) {
|
|
778
|
-
const oldest = appliedIds.values().next().value;
|
|
779
|
-
if (oldest !== undefined)
|
|
780
|
-
appliedIds.delete(oldest);
|
|
781
|
-
}
|
|
782
|
-
}
|
|
808
|
+
if (piece.id && !takeDeltaEventId(sessionID, `${messageID}:${partID}:${field}`, piece.id))
|
|
809
|
+
continue;
|
|
783
810
|
delta += piece.delta;
|
|
784
811
|
applied = true;
|
|
785
812
|
}
|
|
@@ -810,6 +837,7 @@ export const useSyncStore = create()((set, get) => ({
|
|
|
810
837
|
todos: {},
|
|
811
838
|
sessionRevert: {},
|
|
812
839
|
sessionRevertNeedsTailReconcile: {},
|
|
840
|
+
sessionLogs: {},
|
|
813
841
|
// Compat alias
|
|
814
842
|
get statuses() {
|
|
815
843
|
return get().sessionStatus;
|
|
@@ -1818,8 +1846,22 @@ export const useSyncStore = create()((set, get) => ({
|
|
|
1818
1846
|
todos: {},
|
|
1819
1847
|
sessionRevert: {},
|
|
1820
1848
|
sessionRevertNeedsTailReconcile: {},
|
|
1849
|
+
sessionLogs: {},
|
|
1821
1850
|
});
|
|
1822
1851
|
},
|
|
1852
|
+
applySessionLogPage: (sessionId, page) => set((s) => {
|
|
1853
|
+
const current = s.sessionLogs[sessionId] ?? EMPTY_SESSION_LOG_STATE;
|
|
1854
|
+
// A page's session record is a patch; the id it was read for is its `session_id`.
|
|
1855
|
+
const next = applySessionLogPage(current, { ...page, session: { session_id: sessionId, ...page.session } });
|
|
1856
|
+
return next === current ? s : { sessionLogs: { ...s.sessionLogs, [sessionId]: next } };
|
|
1857
|
+
}),
|
|
1858
|
+
applySessionLogEvent: (sessionId, event) => applySessionLogFrame(sessionId, event),
|
|
1859
|
+
dropSessionLog: (sessionId) => set((s) => {
|
|
1860
|
+
if (!(sessionId in s.sessionLogs))
|
|
1861
|
+
return s;
|
|
1862
|
+
const { [sessionId]: _dropped, ...rest } = s.sessionLogs;
|
|
1863
|
+
return { sessionLogs: rest };
|
|
1864
|
+
}),
|
|
1823
1865
|
// ---- Selector: join messages + parts into MessageWithParts[] ----
|
|
1824
1866
|
hasOptimisticMessages: (sessionID) => {
|
|
1825
1867
|
const list = get().messages[sessionID];
|