@zyro-sec/schema 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +95 -95
- package/package.json +5 -1
- package/script/build.ts +9 -9
- package/script/config-schema.ts +86 -86
- package/script/config-v1.json +1311 -1311
- package/script/pack.ts +5 -5
- package/src/agent.ts +68 -68
- package/src/artifact.ts +81 -81
- package/src/automation.ts +224 -224
- package/src/blob-store.ts +25 -25
- package/src/command.ts +18 -18
- package/src/config/agent.ts +26 -26
- package/src/config/command.ts +14 -14
- package/src/config/compaction.ts +27 -27
- package/src/config/experimental.ts +72 -72
- package/src/config/flag.ts +39 -39
- package/src/config/formatter.ts +13 -13
- package/src/config/lsp.ts +19 -19
- package/src/config/mcp.ts +22 -22
- package/src/config/media.ts +15 -15
- package/src/config/model.ts +37 -37
- package/src/config/plugin.ts +14 -14
- package/src/config/policy.ts +57 -57
- package/src/config/provider.ts +122 -122
- package/src/config/reference.ts +23 -23
- package/src/config/shell.ts +10 -10
- package/src/config/tool-output.ts +9 -9
- package/src/config/warming.ts +21 -21
- package/src/config/watcher.ts +8 -8
- package/src/config/websearch.ts +17 -17
- package/src/config/worktree.ts +10 -10
- package/src/config.ts +149 -149
- package/src/connection.ts +38 -38
- package/src/credential-legacy.ts +29 -29
- package/src/credential.ts +78 -78
- package/src/durable-event-manifest.ts +7 -7
- package/src/event-log.ts +21 -21
- package/src/event-manifest.ts +108 -108
- package/src/event.ts +205 -205
- package/src/file-diff.ts +25 -25
- package/src/filesystem-v1.ts +1 -1
- package/src/filesystem.ts +48 -48
- package/src/form.ts +177 -177
- package/src/generate.ts +292 -292
- package/src/goal.ts +46 -46
- package/src/identifier.ts +32 -32
- package/src/index.ts +51 -51
- package/src/installation-event.ts +20 -20
- package/src/instruction-entry.ts +40 -40
- package/src/instruction.ts +25 -25
- package/src/integration-id.ts +13 -13
- package/src/integration.ts +129 -129
- package/src/job.ts +79 -79
- package/src/legacy-event.ts +1 -1
- package/src/llm.ts +6 -6
- package/src/location-event.ts +8 -8
- package/src/location.ts +36 -36
- package/src/lsp-event.ts +7 -7
- package/src/mcp-event.ts +63 -63
- package/src/mcp.ts +171 -171
- package/src/model-compatibility.ts +55 -55
- package/src/model.ts +176 -176
- package/src/models-dev.ts +9 -9
- package/src/money.ts +18 -18
- package/src/permission-saved.ts +25 -25
- package/src/permission-v1.ts +1 -1
- package/src/permission.ts +67 -67
- package/src/persistent-pty.ts +73 -73
- package/src/plugin.ts +62 -62
- package/src/project-id.ts +9 -9
- package/src/project.ts +62 -62
- package/src/prompt-input.ts +33 -33
- package/src/prompt.ts +117 -117
- package/src/provider.ts +136 -136
- package/src/pty-ticket.ts +10 -10
- package/src/pty.ts +61 -61
- package/src/push.ts +86 -86
- package/src/question.ts +22 -22
- package/src/reference.ts +40 -40
- package/src/rpc.ts +167 -167
- package/src/schema.ts +41 -41
- package/src/server-event.ts +8 -8
- package/src/session-error.ts +14 -14
- package/src/session-event.ts +739 -739
- package/src/session-fork.ts +10 -10
- package/src/session-id.ts +12 -12
- package/src/session-inbox.ts +102 -102
- package/src/session-legacy.ts +117 -117
- package/src/session-message.ts +352 -352
- package/src/session-metadata.ts +11 -11
- package/src/session-revert.ts +86 -86
- package/src/session-stats.ts +68 -68
- package/src/session-status-event.ts +53 -53
- package/src/session-transfer.ts +11 -11
- package/src/session-v1.ts +1 -1
- package/src/session.ts +147 -147
- package/src/shell.ts +90 -90
- package/src/skill.ts +68 -68
- package/src/snapshot.ts +6 -6
- package/src/token-usage.ts +18 -18
- package/src/tool.ts +143 -143
- package/src/tui-event.ts +59 -59
- package/src/usage-limits.ts +76 -76
- package/src/v1/filesystem.ts +11 -11
- package/src/v1/legacy-event.ts +18 -18
- package/src/v1/permission.ts +66 -66
- package/src/v1/session.ts +667 -667
- package/src/vcs-event.ts +14 -14
- package/src/vcs.ts +41 -41
- package/src/websearch.ts +44 -44
- package/src/workspace-event.ts +32 -32
- package/src/workspace-id.ts +19 -19
- package/src/workspace.ts +20 -20
- package/src/worktree-event.ts +22 -22
- package/src/worktree.ts +109 -109
- package/tsconfig.build.json +11 -11
- package/tsconfig.json +14 -14
- package/test/agent.test.ts +0 -10
- package/test/automation.test.ts +0 -48
- package/test/compatibility.test.ts +0 -10
- package/test/config.test.ts +0 -194
- package/test/contract-hygiene.test.ts +0 -352
- package/test/credential-legacy.test.ts +0 -55
- package/test/event-manifest.test.ts +0 -228
- package/test/event.test.ts +0 -52
- package/test/legacy-event.test.ts +0 -46
- package/test/mcp.test.ts +0 -37
- package/test/model.test.ts +0 -104
- package/test/session-cursor.test.ts +0 -16
- package/test/session-error.test.ts +0 -51
- package/test/session-legacy.test.ts +0 -178
- package/test/session-terminal.test.ts +0 -50
- package/test/token-usage.test.ts +0 -18
- package/test/v1-isolation.test.ts +0 -26
- package/test/vcs.test.ts +0 -23
- package/test/worktree.test.ts +0 -45
package/src/session-fork.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * as SessionFork from "./session-fork.js"
|
|
2
|
-
|
|
3
|
-
import { Schema } from "effect"
|
|
4
|
-
import { SessionMessage } from "./session-message.js"
|
|
5
|
-
|
|
6
|
-
export const Boundary = Schema.Union([
|
|
7
|
-
Schema.Struct({ type: Schema.Literal("before"), messageID: SessionMessage.ID }),
|
|
8
|
-
Schema.Struct({ type: Schema.Literal("through"), messageID: SessionMessage.ID }),
|
|
9
|
-
]).annotate({ identifier: "Session.ForkBoundary" })
|
|
10
|
-
export type Boundary = typeof Boundary.Type
|
|
1
|
+
export * as SessionFork from "./session-fork.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { SessionMessage } from "./session-message.js"
|
|
5
|
+
|
|
6
|
+
export const Boundary = Schema.Union([
|
|
7
|
+
Schema.Struct({ type: Schema.Literal("before"), messageID: SessionMessage.ID }),
|
|
8
|
+
Schema.Struct({ type: Schema.Literal("through"), messageID: SessionMessage.ID }),
|
|
9
|
+
]).annotate({ identifier: "Session.ForkBoundary" })
|
|
10
|
+
export type Boundary = typeof Boundary.Type
|
package/src/session-id.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Schema } from "effect"
|
|
2
|
-
import { descending } from "./identifier.js"
|
|
3
|
-
import { statics } from "./schema.js"
|
|
4
|
-
|
|
5
|
-
export const SessionID = Schema.String.check(Schema.isStartingWith("ses")).pipe(
|
|
6
|
-
Schema.brand("SessionID"),
|
|
7
|
-
Schema.annotate({ identifier: "Session.ID" }),
|
|
8
|
-
statics((schema) => ({
|
|
9
|
-
create: () => schema.make("ses_" + descending()),
|
|
10
|
-
})),
|
|
11
|
-
)
|
|
12
|
-
export type SessionID = typeof SessionID.Type
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
import { descending } from "./identifier.js"
|
|
3
|
+
import { statics } from "./schema.js"
|
|
4
|
+
|
|
5
|
+
export const SessionID = Schema.String.check(Schema.isStartingWith("ses")).pipe(
|
|
6
|
+
Schema.brand("SessionID"),
|
|
7
|
+
Schema.annotate({ identifier: "Session.ID" }),
|
|
8
|
+
statics((schema) => ({
|
|
9
|
+
create: () => schema.make("ses_" + descending()),
|
|
10
|
+
})),
|
|
11
|
+
)
|
|
12
|
+
export type SessionID = typeof SessionID.Type
|
package/src/session-inbox.ts
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
export * as SessionInbox from "./session-inbox.js"
|
|
2
|
-
|
|
3
|
-
import { Schema } from "effect"
|
|
4
|
-
import { Location } from "./location.js"
|
|
5
|
-
import { Project } from "./project.js"
|
|
6
|
-
import { Attachment, Prompt } from "./prompt.js"
|
|
7
|
-
import { DateTimeUtcFromMillis, optional, RelativePath } from "./schema.js"
|
|
8
|
-
import { SessionID } from "./session-id.js"
|
|
9
|
-
import { SessionMessage } from "./session-message.js"
|
|
10
|
-
|
|
11
|
-
export const Delivery = Schema.Literals(["steer", "queue"]).annotate({
|
|
12
|
-
identifier: "Session.Inbox.Delivery",
|
|
13
|
-
description:
|
|
14
|
-
"steer delivers before the agent's next model call, even mid-work. queue waits until the agent finishes its current work, then delivers one queued item at a time. Sending defaults to steer.",
|
|
15
|
-
})
|
|
16
|
-
export type Delivery = typeof Delivery.Type
|
|
17
|
-
|
|
18
|
-
export interface UserPayload extends Schema.Schema.Type<typeof UserPayload> {}
|
|
19
|
-
export const UserPayload = Schema.Struct({
|
|
20
|
-
...Prompt.fields,
|
|
21
|
-
metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
|
|
22
|
-
}).annotate({ identifier: "Session.Inbox.UserPayload" })
|
|
23
|
-
|
|
24
|
-
/** A {@link UserPayload} whose files may stay on the server, for clients that opt into `experimental-media-uri`. */
|
|
25
|
-
export interface MediaUserPayload extends Schema.Schema.Type<typeof MediaUserPayload> {}
|
|
26
|
-
export const MediaUserPayload = Schema.Struct({
|
|
27
|
-
...UserPayload.fields,
|
|
28
|
-
files: Schema.Array(Attachment).pipe(optional),
|
|
29
|
-
}).annotate({ identifier: "Session.Inbox.MediaUserPayload" })
|
|
30
|
-
|
|
31
|
-
export interface SyntheticPayload extends Schema.Schema.Type<typeof SyntheticPayload> {}
|
|
32
|
-
export const SyntheticPayload = Schema.Struct({
|
|
33
|
-
text: Schema.String,
|
|
34
|
-
description: Schema.String.pipe(optional),
|
|
35
|
-
metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
|
|
36
|
-
}).annotate({ identifier: "Session.Inbox.SyntheticPayload" })
|
|
37
|
-
|
|
38
|
-
export interface CompactionPayload extends Schema.Schema.Type<typeof CompactionPayload> {}
|
|
39
|
-
export const CompactionPayload = Schema.Struct({}).annotate({ identifier: "Session.Inbox.CompactionPayload" })
|
|
40
|
-
|
|
41
|
-
export interface MovePayload extends Schema.Schema.Type<typeof MovePayload> {}
|
|
42
|
-
export const MovePayload = Schema.Struct({
|
|
43
|
-
location: Location.Ref,
|
|
44
|
-
projectID: Project.ID,
|
|
45
|
-
subpath: RelativePath.pipe(optional),
|
|
46
|
-
}).annotate({ identifier: "Session.Inbox.MovePayload" })
|
|
47
|
-
|
|
48
|
-
const UserItem = Schema.Struct({ type: Schema.tag("user"), payload: UserPayload, delivery: Delivery })
|
|
49
|
-
const SyntheticItem = Schema.Struct({ type: Schema.tag("synthetic"), payload: SyntheticPayload, delivery: Delivery })
|
|
50
|
-
const CompactionItem = Schema.Struct({
|
|
51
|
-
type: Schema.tag("compaction"),
|
|
52
|
-
payload: CompactionPayload,
|
|
53
|
-
delivery: Delivery,
|
|
54
|
-
})
|
|
55
|
-
const MoveItem = Schema.Struct({ type: Schema.tag("move"), payload: MovePayload, delivery: Delivery })
|
|
56
|
-
|
|
57
|
-
export const Item = Schema.Union([UserItem, SyntheticItem, CompactionItem, MoveItem]).pipe(
|
|
58
|
-
Schema.toTaggedUnion("type"),
|
|
59
|
-
Schema.annotate({ identifier: "Session.Inbox.Item" }),
|
|
60
|
-
)
|
|
61
|
-
export type Item = typeof Item.Type
|
|
62
|
-
|
|
63
|
-
const Enqueued = {
|
|
64
|
-
id: SessionMessage.ID,
|
|
65
|
-
sessionID: SessionID,
|
|
66
|
-
time: Schema.Struct({ created: DateTimeUtcFromMillis }),
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface User extends Schema.Schema.Type<typeof User> {}
|
|
70
|
-
export const User = Schema.Struct({ ...Enqueued, ...UserItem.fields }).annotate({ identifier: "Session.Inbox.User" })
|
|
71
|
-
|
|
72
|
-
/** A {@link User} whose files may stay on the server, for clients that opt into `experimental-media-uri`. */
|
|
73
|
-
export interface MediaUser extends Schema.Schema.Type<typeof MediaUser> {}
|
|
74
|
-
export const MediaUser = Schema.Struct({ ...User.fields, payload: MediaUserPayload }).annotate({
|
|
75
|
-
identifier: "Session.Inbox.MediaUser",
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
export interface Synthetic extends Schema.Schema.Type<typeof Synthetic> {}
|
|
79
|
-
export const Synthetic = Schema.Struct({ ...Enqueued, ...SyntheticItem.fields }).annotate({
|
|
80
|
-
identifier: "Session.Inbox.Synthetic",
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
export interface Compaction extends Schema.Schema.Type<typeof Compaction> {}
|
|
84
|
-
export const Compaction = Schema.Struct({ ...Enqueued, ...CompactionItem.fields }).annotate({
|
|
85
|
-
identifier: "Session.Inbox.Compaction",
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
export interface Move extends Schema.Schema.Type<typeof Move> {}
|
|
89
|
-
export const Move = Schema.Struct({ ...Enqueued, ...MoveItem.fields }).annotate({ identifier: "Session.Inbox.Move" })
|
|
90
|
-
|
|
91
|
-
export const Info = Schema.Union([User, Synthetic, Compaction, Move]).pipe(
|
|
92
|
-
Schema.toTaggedUnion("type"),
|
|
93
|
-
Schema.annotate({ identifier: "Session.Inbox.Info" }),
|
|
94
|
-
)
|
|
95
|
-
export type Info = typeof Info.Type
|
|
96
|
-
|
|
97
|
-
/** {@link Info} with {@link MediaUser} for clients that opt into `experimental-media-uri`. */
|
|
98
|
-
export const MediaInfo = Schema.Union([MediaUser, Synthetic, Compaction, Move]).pipe(
|
|
99
|
-
Schema.toTaggedUnion("type"),
|
|
100
|
-
Schema.annotate({ identifier: "Session.Inbox.MediaInfo" }),
|
|
101
|
-
)
|
|
102
|
-
export type MediaInfo = typeof MediaInfo.Type
|
|
1
|
+
export * as SessionInbox from "./session-inbox.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { Location } from "./location.js"
|
|
5
|
+
import { Project } from "./project.js"
|
|
6
|
+
import { Attachment, Prompt } from "./prompt.js"
|
|
7
|
+
import { DateTimeUtcFromMillis, optional, RelativePath } from "./schema.js"
|
|
8
|
+
import { SessionID } from "./session-id.js"
|
|
9
|
+
import { SessionMessage } from "./session-message.js"
|
|
10
|
+
|
|
11
|
+
export const Delivery = Schema.Literals(["steer", "queue"]).annotate({
|
|
12
|
+
identifier: "Session.Inbox.Delivery",
|
|
13
|
+
description:
|
|
14
|
+
"steer delivers before the agent's next model call, even mid-work. queue waits until the agent finishes its current work, then delivers one queued item at a time. Sending defaults to steer.",
|
|
15
|
+
})
|
|
16
|
+
export type Delivery = typeof Delivery.Type
|
|
17
|
+
|
|
18
|
+
export interface UserPayload extends Schema.Schema.Type<typeof UserPayload> {}
|
|
19
|
+
export const UserPayload = Schema.Struct({
|
|
20
|
+
...Prompt.fields,
|
|
21
|
+
metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
|
|
22
|
+
}).annotate({ identifier: "Session.Inbox.UserPayload" })
|
|
23
|
+
|
|
24
|
+
/** A {@link UserPayload} whose files may stay on the server, for clients that opt into `experimental-media-uri`. */
|
|
25
|
+
export interface MediaUserPayload extends Schema.Schema.Type<typeof MediaUserPayload> {}
|
|
26
|
+
export const MediaUserPayload = Schema.Struct({
|
|
27
|
+
...UserPayload.fields,
|
|
28
|
+
files: Schema.Array(Attachment).pipe(optional),
|
|
29
|
+
}).annotate({ identifier: "Session.Inbox.MediaUserPayload" })
|
|
30
|
+
|
|
31
|
+
export interface SyntheticPayload extends Schema.Schema.Type<typeof SyntheticPayload> {}
|
|
32
|
+
export const SyntheticPayload = Schema.Struct({
|
|
33
|
+
text: Schema.String,
|
|
34
|
+
description: Schema.String.pipe(optional),
|
|
35
|
+
metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
|
|
36
|
+
}).annotate({ identifier: "Session.Inbox.SyntheticPayload" })
|
|
37
|
+
|
|
38
|
+
export interface CompactionPayload extends Schema.Schema.Type<typeof CompactionPayload> {}
|
|
39
|
+
export const CompactionPayload = Schema.Struct({}).annotate({ identifier: "Session.Inbox.CompactionPayload" })
|
|
40
|
+
|
|
41
|
+
export interface MovePayload extends Schema.Schema.Type<typeof MovePayload> {}
|
|
42
|
+
export const MovePayload = Schema.Struct({
|
|
43
|
+
location: Location.Ref,
|
|
44
|
+
projectID: Project.ID,
|
|
45
|
+
subpath: RelativePath.pipe(optional),
|
|
46
|
+
}).annotate({ identifier: "Session.Inbox.MovePayload" })
|
|
47
|
+
|
|
48
|
+
const UserItem = Schema.Struct({ type: Schema.tag("user"), payload: UserPayload, delivery: Delivery })
|
|
49
|
+
const SyntheticItem = Schema.Struct({ type: Schema.tag("synthetic"), payload: SyntheticPayload, delivery: Delivery })
|
|
50
|
+
const CompactionItem = Schema.Struct({
|
|
51
|
+
type: Schema.tag("compaction"),
|
|
52
|
+
payload: CompactionPayload,
|
|
53
|
+
delivery: Delivery,
|
|
54
|
+
})
|
|
55
|
+
const MoveItem = Schema.Struct({ type: Schema.tag("move"), payload: MovePayload, delivery: Delivery })
|
|
56
|
+
|
|
57
|
+
export const Item = Schema.Union([UserItem, SyntheticItem, CompactionItem, MoveItem]).pipe(
|
|
58
|
+
Schema.toTaggedUnion("type"),
|
|
59
|
+
Schema.annotate({ identifier: "Session.Inbox.Item" }),
|
|
60
|
+
)
|
|
61
|
+
export type Item = typeof Item.Type
|
|
62
|
+
|
|
63
|
+
const Enqueued = {
|
|
64
|
+
id: SessionMessage.ID,
|
|
65
|
+
sessionID: SessionID,
|
|
66
|
+
time: Schema.Struct({ created: DateTimeUtcFromMillis }),
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface User extends Schema.Schema.Type<typeof User> {}
|
|
70
|
+
export const User = Schema.Struct({ ...Enqueued, ...UserItem.fields }).annotate({ identifier: "Session.Inbox.User" })
|
|
71
|
+
|
|
72
|
+
/** A {@link User} whose files may stay on the server, for clients that opt into `experimental-media-uri`. */
|
|
73
|
+
export interface MediaUser extends Schema.Schema.Type<typeof MediaUser> {}
|
|
74
|
+
export const MediaUser = Schema.Struct({ ...User.fields, payload: MediaUserPayload }).annotate({
|
|
75
|
+
identifier: "Session.Inbox.MediaUser",
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
export interface Synthetic extends Schema.Schema.Type<typeof Synthetic> {}
|
|
79
|
+
export const Synthetic = Schema.Struct({ ...Enqueued, ...SyntheticItem.fields }).annotate({
|
|
80
|
+
identifier: "Session.Inbox.Synthetic",
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
export interface Compaction extends Schema.Schema.Type<typeof Compaction> {}
|
|
84
|
+
export const Compaction = Schema.Struct({ ...Enqueued, ...CompactionItem.fields }).annotate({
|
|
85
|
+
identifier: "Session.Inbox.Compaction",
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
export interface Move extends Schema.Schema.Type<typeof Move> {}
|
|
89
|
+
export const Move = Schema.Struct({ ...Enqueued, ...MoveItem.fields }).annotate({ identifier: "Session.Inbox.Move" })
|
|
90
|
+
|
|
91
|
+
export const Info = Schema.Union([User, Synthetic, Compaction, Move]).pipe(
|
|
92
|
+
Schema.toTaggedUnion("type"),
|
|
93
|
+
Schema.annotate({ identifier: "Session.Inbox.Info" }),
|
|
94
|
+
)
|
|
95
|
+
export type Info = typeof Info.Type
|
|
96
|
+
|
|
97
|
+
/** {@link Info} with {@link MediaUser} for clients that opt into `experimental-media-uri`. */
|
|
98
|
+
export const MediaInfo = Schema.Union([MediaUser, Synthetic, Compaction, Move]).pipe(
|
|
99
|
+
Schema.toTaggedUnion("type"),
|
|
100
|
+
Schema.annotate({ identifier: "Session.Inbox.MediaInfo" }),
|
|
101
|
+
)
|
|
102
|
+
export type MediaInfo = typeof MediaInfo.Type
|
package/src/session-legacy.ts
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
export * as SessionLegacy from "./session-legacy.js"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Storage and wire compatibility for current-architecture data written before v2.1 (not V1 contracts). Native data
|
|
5
|
-
* was then named `state` or `providerState`, a tool's result native data `resultState` or `providerResultState`,
|
|
6
|
-
* summary compactions stored the text of the messages they kept in `recent`, and provider compactions stored their
|
|
7
|
-
* replacement window in `providerContext`. Stored events, projected messages, and exported transcripts keep whichever
|
|
8
|
-
* shape they were written with, so these upgrade them before decoding.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const renames: Record<string, readonly [string, string]> = {
|
|
12
|
-
"session.text.ended": ["state", "native"],
|
|
13
|
-
"session.reasoning.started": ["state", "native"],
|
|
14
|
-
"session.reasoning.ended": ["state", "native"],
|
|
15
|
-
"session.tool.called": ["state", "native"],
|
|
16
|
-
"session.step.ended": ["providerState", "native"],
|
|
17
|
-
"session.step.failed": ["providerState", "native"],
|
|
18
|
-
"session.tool.success": ["resultState", "native"],
|
|
19
|
-
"session.tool.failed": ["resultState", "native"],
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Upgrades a durable event payload by event type. */
|
|
23
|
-
export function event(type: string, data: unknown) {
|
|
24
|
-
if (!isRecord(data)) return data
|
|
25
|
-
if (type === "session.message.content.updated") return content(data)
|
|
26
|
-
// Messages carry a legacy compaction's kept text; its events have no reader for it.
|
|
27
|
-
if (type === "session.compaction.started") return omit(data, "recent")
|
|
28
|
-
if (type === "session.compaction.ended")
|
|
29
|
-
return providerContext(omit(rename(data, "providerState", "native"), "recent"))
|
|
30
|
-
const entry = renames[type]
|
|
31
|
-
return entry ? rename(data, entry[0], entry[1]) : data
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Upgrades a projected message's data by message type. */
|
|
35
|
-
export function message(type: unknown, data: Record<string, unknown>) {
|
|
36
|
-
if (type === "assistant") return content(rename(data, "providerState", "native"))
|
|
37
|
-
if (type === "compaction") return providerContext(recent(rename(data, "providerState", "native")))
|
|
38
|
-
return data
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Upgrades complete messages, such as those in an exported session, before decoding. */
|
|
42
|
-
export function messages(values: ReadonlyArray<unknown>) {
|
|
43
|
-
return values.map((value) => (isRecord(value) ? message(value.type, value) : value))
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function content(data: Record<string, unknown>) {
|
|
47
|
-
if (!Array.isArray(data.content)) return data
|
|
48
|
-
return { ...data, content: data.content.map(part) }
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Upgrades an assistant content part written before v2.1. */
|
|
52
|
-
export function part(value: unknown) {
|
|
53
|
-
if (!isRecord(value)) return value
|
|
54
|
-
if (value.type === "text" || value.type === "reasoning") return rename(value, "state", "native")
|
|
55
|
-
// A tool part's own `state` is its lifecycle status, not native data.
|
|
56
|
-
if (value.type === "tool") return toolResult(rename(value, "providerState", "native"))
|
|
57
|
-
return value
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Kept text a summary compaction stored before it referenced `metadata.keepID`; replay still reads it. */
|
|
61
|
-
function recent(data: Record<string, unknown>) {
|
|
62
|
-
const text = data.recent
|
|
63
|
-
const rest = omit(data, "recent")
|
|
64
|
-
if (typeof text !== "string" || !text) return rest
|
|
65
|
-
const metadata = isRecord(rest.metadata) ? rest.metadata : {}
|
|
66
|
-
return { ...rest, metadata: { recent: text, ...metadata } }
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** The window moves to `native.messages`; the `native` stored beside it was never replayed. */
|
|
70
|
-
function providerContext(data: Record<string, unknown>) {
|
|
71
|
-
const context = data.providerContext
|
|
72
|
-
const rest = omit(data, "providerContext")
|
|
73
|
-
if (!isRecord(context)) return rest
|
|
74
|
-
return {
|
|
75
|
-
...rest,
|
|
76
|
-
native: { messages: Array.isArray(context.messages) ? context.messages.map(media) : context.messages },
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** Before 2.0.15, window media parts stored `mediaType` and base64 `data` directly. */
|
|
81
|
-
function media(message: unknown) {
|
|
82
|
-
if (!isRecord(message) || !Array.isArray(message.content)) return message
|
|
83
|
-
return {
|
|
84
|
-
...message,
|
|
85
|
-
content: message.content.map((part: unknown) => {
|
|
86
|
-
if (!isRecord(part) || part.type !== "media" || part.media !== undefined || typeof part.data !== "string")
|
|
87
|
-
return part
|
|
88
|
-
const { mediaType, data, ...rest } = part
|
|
89
|
-
return { ...rest, media: { source: { type: "base64", data, mediaType } } }
|
|
90
|
-
}),
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function omit(value: Record<string, unknown>, key: string) {
|
|
95
|
-
if (!(key in value)) return value
|
|
96
|
-
const { [key]: _, ...rest } = value
|
|
97
|
-
return rest
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Result data now merges into the tool's single `native`, as projection does for current result events.
|
|
101
|
-
function toolResult(value: Record<string, unknown>) {
|
|
102
|
-
if (!("providerResultState" in value)) return value
|
|
103
|
-
const { providerResultState, ...rest } = value
|
|
104
|
-
if (!isRecord(providerResultState)) return rest
|
|
105
|
-
return { ...rest, native: { ...(isRecord(rest.native) ? rest.native : {}), ...providerResultState } }
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// The current name wins when a payload carries both.
|
|
109
|
-
function rename(value: Record<string, unknown>, from: string, to: string) {
|
|
110
|
-
if (!(from in value)) return value
|
|
111
|
-
const { [from]: moved, ...rest } = value
|
|
112
|
-
return to in rest ? rest : { ...rest, [to]: moved }
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
116
|
-
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
117
|
-
}
|
|
1
|
+
export * as SessionLegacy from "./session-legacy.js"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Storage and wire compatibility for current-architecture data written before v2.1 (not V1 contracts). Native data
|
|
5
|
+
* was then named `state` or `providerState`, a tool's result native data `resultState` or `providerResultState`,
|
|
6
|
+
* summary compactions stored the text of the messages they kept in `recent`, and provider compactions stored their
|
|
7
|
+
* replacement window in `providerContext`. Stored events, projected messages, and exported transcripts keep whichever
|
|
8
|
+
* shape they were written with, so these upgrade them before decoding.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const renames: Record<string, readonly [string, string]> = {
|
|
12
|
+
"session.text.ended": ["state", "native"],
|
|
13
|
+
"session.reasoning.started": ["state", "native"],
|
|
14
|
+
"session.reasoning.ended": ["state", "native"],
|
|
15
|
+
"session.tool.called": ["state", "native"],
|
|
16
|
+
"session.step.ended": ["providerState", "native"],
|
|
17
|
+
"session.step.failed": ["providerState", "native"],
|
|
18
|
+
"session.tool.success": ["resultState", "native"],
|
|
19
|
+
"session.tool.failed": ["resultState", "native"],
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Upgrades a durable event payload by event type. */
|
|
23
|
+
export function event(type: string, data: unknown) {
|
|
24
|
+
if (!isRecord(data)) return data
|
|
25
|
+
if (type === "session.message.content.updated") return content(data)
|
|
26
|
+
// Messages carry a legacy compaction's kept text; its events have no reader for it.
|
|
27
|
+
if (type === "session.compaction.started") return omit(data, "recent")
|
|
28
|
+
if (type === "session.compaction.ended")
|
|
29
|
+
return providerContext(omit(rename(data, "providerState", "native"), "recent"))
|
|
30
|
+
const entry = renames[type]
|
|
31
|
+
return entry ? rename(data, entry[0], entry[1]) : data
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Upgrades a projected message's data by message type. */
|
|
35
|
+
export function message(type: unknown, data: Record<string, unknown>) {
|
|
36
|
+
if (type === "assistant") return content(rename(data, "providerState", "native"))
|
|
37
|
+
if (type === "compaction") return providerContext(recent(rename(data, "providerState", "native")))
|
|
38
|
+
return data
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Upgrades complete messages, such as those in an exported session, before decoding. */
|
|
42
|
+
export function messages(values: ReadonlyArray<unknown>) {
|
|
43
|
+
return values.map((value) => (isRecord(value) ? message(value.type, value) : value))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function content(data: Record<string, unknown>) {
|
|
47
|
+
if (!Array.isArray(data.content)) return data
|
|
48
|
+
return { ...data, content: data.content.map(part) }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Upgrades an assistant content part written before v2.1. */
|
|
52
|
+
export function part(value: unknown) {
|
|
53
|
+
if (!isRecord(value)) return value
|
|
54
|
+
if (value.type === "text" || value.type === "reasoning") return rename(value, "state", "native")
|
|
55
|
+
// A tool part's own `state` is its lifecycle status, not native data.
|
|
56
|
+
if (value.type === "tool") return toolResult(rename(value, "providerState", "native"))
|
|
57
|
+
return value
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Kept text a summary compaction stored before it referenced `metadata.keepID`; replay still reads it. */
|
|
61
|
+
function recent(data: Record<string, unknown>) {
|
|
62
|
+
const text = data.recent
|
|
63
|
+
const rest = omit(data, "recent")
|
|
64
|
+
if (typeof text !== "string" || !text) return rest
|
|
65
|
+
const metadata = isRecord(rest.metadata) ? rest.metadata : {}
|
|
66
|
+
return { ...rest, metadata: { recent: text, ...metadata } }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The window moves to `native.messages`; the `native` stored beside it was never replayed. */
|
|
70
|
+
function providerContext(data: Record<string, unknown>) {
|
|
71
|
+
const context = data.providerContext
|
|
72
|
+
const rest = omit(data, "providerContext")
|
|
73
|
+
if (!isRecord(context)) return rest
|
|
74
|
+
return {
|
|
75
|
+
...rest,
|
|
76
|
+
native: { messages: Array.isArray(context.messages) ? context.messages.map(media) : context.messages },
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Before 2.0.15, window media parts stored `mediaType` and base64 `data` directly. */
|
|
81
|
+
function media(message: unknown) {
|
|
82
|
+
if (!isRecord(message) || !Array.isArray(message.content)) return message
|
|
83
|
+
return {
|
|
84
|
+
...message,
|
|
85
|
+
content: message.content.map((part: unknown) => {
|
|
86
|
+
if (!isRecord(part) || part.type !== "media" || part.media !== undefined || typeof part.data !== "string")
|
|
87
|
+
return part
|
|
88
|
+
const { mediaType, data, ...rest } = part
|
|
89
|
+
return { ...rest, media: { source: { type: "base64", data, mediaType } } }
|
|
90
|
+
}),
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function omit(value: Record<string, unknown>, key: string) {
|
|
95
|
+
if (!(key in value)) return value
|
|
96
|
+
const { [key]: _, ...rest } = value
|
|
97
|
+
return rest
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Result data now merges into the tool's single `native`, as projection does for current result events.
|
|
101
|
+
function toolResult(value: Record<string, unknown>) {
|
|
102
|
+
if (!("providerResultState" in value)) return value
|
|
103
|
+
const { providerResultState, ...rest } = value
|
|
104
|
+
if (!isRecord(providerResultState)) return rest
|
|
105
|
+
return { ...rest, native: { ...(isRecord(rest.native) ? rest.native : {}), ...providerResultState } }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// The current name wins when a payload carries both.
|
|
109
|
+
function rename(value: Record<string, unknown>, from: string, to: string) {
|
|
110
|
+
if (!(from in value)) return value
|
|
111
|
+
const { [from]: moved, ...rest } = value
|
|
112
|
+
return to in rest ? rest : { ...rest, [to]: moved }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
116
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
117
|
+
}
|