@zyro-sec/schema 1.0.0 → 1.0.1
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 -0
- package/package.json +9 -15
- package/script/build.ts +9 -0
- package/script/config-schema.ts +86 -0
- package/script/config-v1.json +1312 -0
- package/script/pack.ts +5 -0
- package/src/agent.ts +68 -0
- package/src/artifact.ts +81 -0
- package/src/automation.ts +224 -0
- package/src/blob-store.ts +25 -0
- package/src/command.ts +18 -0
- package/src/config/agent.ts +26 -0
- package/src/config/command.ts +14 -0
- package/src/config/compaction.ts +27 -0
- package/src/config/experimental.ts +72 -0
- package/src/config/flag.ts +39 -0
- package/src/config/formatter.ts +13 -0
- package/src/config/lsp.ts +19 -0
- package/src/config/mcp.ts +22 -0
- package/src/config/media.ts +15 -0
- package/src/config/model.ts +37 -0
- package/src/config/plugin.ts +14 -0
- package/src/config/policy.ts +57 -0
- package/src/config/provider.ts +122 -0
- package/src/config/reference.ts +23 -0
- package/src/config/shell.ts +10 -0
- package/src/config/tool-output.ts +9 -0
- package/src/config/warming.ts +21 -0
- package/src/config/watcher.ts +8 -0
- package/src/config/websearch.ts +17 -0
- package/src/config/worktree.ts +10 -0
- package/src/config.ts +149 -0
- package/src/connection.ts +38 -0
- package/src/credential-legacy.ts +29 -0
- package/src/credential.ts +78 -0
- package/src/durable-event-manifest.ts +7 -0
- package/src/event-log.ts +21 -0
- package/src/event-manifest.ts +108 -0
- package/src/event.ts +205 -0
- package/src/file-diff.ts +25 -0
- package/src/filesystem-v1.ts +1 -0
- package/src/filesystem.ts +48 -0
- package/src/form.ts +177 -0
- package/src/generate.ts +292 -0
- package/src/goal.ts +46 -0
- package/src/identifier.ts +32 -0
- package/src/index.ts +51 -0
- package/src/installation-event.ts +20 -0
- package/src/instruction-entry.ts +40 -0
- package/src/instruction.ts +25 -0
- package/src/integration-id.ts +13 -0
- package/src/integration.ts +129 -0
- package/src/job.ts +79 -0
- package/src/legacy-event.ts +1 -0
- package/src/llm.ts +6 -0
- package/src/location-event.ts +8 -0
- package/src/location.ts +36 -0
- package/src/lsp-event.ts +7 -0
- package/src/mcp-event.ts +63 -0
- package/src/mcp.ts +171 -0
- package/src/model-compatibility.ts +55 -0
- package/src/model.ts +176 -0
- package/src/models-dev.ts +9 -0
- package/src/money.ts +18 -0
- package/src/permission-saved.ts +25 -0
- package/src/permission-v1.ts +1 -0
- package/src/permission.ts +67 -0
- package/src/persistent-pty.ts +73 -0
- package/src/plugin.ts +62 -0
- package/src/project-id.ts +9 -0
- package/src/project.ts +62 -0
- package/src/prompt-input.ts +33 -0
- package/src/prompt.ts +117 -0
- package/src/provider.ts +136 -0
- package/src/pty-ticket.ts +10 -0
- package/src/pty.ts +61 -0
- package/src/push.ts +86 -0
- package/src/question.ts +22 -0
- package/src/reference.ts +40 -0
- package/src/rpc.ts +167 -0
- package/src/schema.ts +41 -0
- package/src/server-event.ts +8 -0
- package/src/session-error.ts +14 -0
- package/src/session-event.ts +739 -0
- package/src/session-fork.ts +10 -0
- package/src/session-id.ts +12 -0
- package/src/session-inbox.ts +102 -0
- package/src/session-legacy.ts +117 -0
- package/src/session-message.ts +352 -0
- package/src/session-metadata.ts +11 -0
- package/src/session-revert.ts +86 -0
- package/src/session-stats.ts +68 -0
- package/src/session-status-event.ts +53 -0
- package/src/session-transfer.ts +11 -0
- package/src/session-v1.ts +1 -0
- package/src/session.ts +147 -0
- package/src/shell.ts +90 -0
- package/src/skill.ts +68 -0
- package/src/snapshot.ts +6 -0
- package/src/token-usage.ts +18 -0
- package/src/tool.ts +143 -0
- package/src/tui-event.ts +59 -0
- package/src/usage-limits.ts +76 -0
- package/src/v1/filesystem.ts +11 -0
- package/src/v1/legacy-event.ts +18 -0
- package/src/v1/permission.ts +66 -0
- package/src/v1/session.ts +667 -0
- package/src/vcs-event.ts +14 -0
- package/src/vcs.ts +41 -0
- package/src/websearch.ts +44 -0
- package/src/workspace-event.ts +32 -0
- package/src/workspace-id.ts +19 -0
- package/src/workspace.ts +20 -0
- package/src/worktree-event.ts +22 -0
- package/src/worktree.ts +109 -0
- package/test/agent.test.ts +10 -0
- package/test/automation.test.ts +48 -0
- package/test/compatibility.test.ts +10 -0
- package/test/config.test.ts +194 -0
- package/test/contract-hygiene.test.ts +352 -0
- package/test/credential-legacy.test.ts +55 -0
- package/test/event-manifest.test.ts +228 -0
- package/test/event.test.ts +52 -0
- package/test/legacy-event.test.ts +46 -0
- package/test/mcp.test.ts +37 -0
- package/test/model.test.ts +104 -0
- package/test/session-cursor.test.ts +16 -0
- package/test/session-error.test.ts +51 -0
- package/test/session-legacy.test.ts +178 -0
- package/test/session-terminal.test.ts +50 -0
- package/test/token-usage.test.ts +18 -0
- package/test/v1-isolation.test.ts +26 -0
- package/test/vcs.test.ts +23 -0
- package/test/worktree.test.ts +45 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +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
|
|
@@ -0,0 +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
|
|
@@ -0,0 +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
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
export * as SessionMessage from "./session-message.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { optional } from "./schema.js"
|
|
5
|
+
import { Content } from "./tool.js"
|
|
6
|
+
import { Location } from "./location.js"
|
|
7
|
+
import { Model } from "./model.js"
|
|
8
|
+
import { Project } from "./project.js"
|
|
9
|
+
import { Attachment, Prompt } from "./prompt.js"
|
|
10
|
+
import { DateTimeUtcFromMillis, PositiveInt, RelativePath, statics } from "./schema.js"
|
|
11
|
+
import { ascending } from "./identifier.js"
|
|
12
|
+
import { Shell as ShellSchema } from "./shell.js"
|
|
13
|
+
import { FinishReason } from "./llm.js"
|
|
14
|
+
import { SessionError } from "./session-error.js"
|
|
15
|
+
import { Agent } from "./agent.js"
|
|
16
|
+
import { Skill as SkillSchema } from "./skill.js"
|
|
17
|
+
import { Money } from "./money.js"
|
|
18
|
+
import { Snapshot } from "./snapshot.js"
|
|
19
|
+
import { TokenUsage } from "./token-usage.js"
|
|
20
|
+
|
|
21
|
+
export const ID = Schema.String.check(Schema.isStartingWith("msg_")).pipe(
|
|
22
|
+
Schema.brand("Session.Message.ID"),
|
|
23
|
+
Schema.annotate({ identifier: "Session.Message.ID" }),
|
|
24
|
+
statics((schema) => ({
|
|
25
|
+
create: () => schema.make("msg_" + ascending()),
|
|
26
|
+
fromEvent: (eventID: string) => schema.make(eventID.replace(/^evt_/, "msg_")),
|
|
27
|
+
})),
|
|
28
|
+
)
|
|
29
|
+
export type ID = typeof ID.Type
|
|
30
|
+
|
|
31
|
+
const Base = {
|
|
32
|
+
id: ID,
|
|
33
|
+
metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
|
|
34
|
+
time: Schema.Struct({ created: DateTimeUtcFromMillis }),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Provider-owned replay data, keyed by the producing provider's metadata fields and echoed back verbatim. A tool's
|
|
39
|
+
* result data is merged into its call data, so adapters must not reuse a key with a different value across the two.
|
|
40
|
+
*/
|
|
41
|
+
export const Native = Schema.Record(Schema.String, Schema.Unknown).annotate({
|
|
42
|
+
identifier: "Session.Message.Native",
|
|
43
|
+
})
|
|
44
|
+
export type Native = typeof Native.Type
|
|
45
|
+
|
|
46
|
+
export interface AgentSelected extends Schema.Schema.Type<typeof AgentSelected> {}
|
|
47
|
+
export const AgentSelected = Schema.Struct({
|
|
48
|
+
...Base,
|
|
49
|
+
type: Schema.tag("agent-switched"),
|
|
50
|
+
agent: Agent.ID,
|
|
51
|
+
previous: Agent.ID.pipe(optional),
|
|
52
|
+
}).annotate({ identifier: "Session.Message.AgentSelected" })
|
|
53
|
+
|
|
54
|
+
export interface ModelSelected extends Schema.Schema.Type<typeof ModelSelected> {}
|
|
55
|
+
export const ModelSelected = Schema.Struct({
|
|
56
|
+
...Base,
|
|
57
|
+
type: Schema.tag("model-switched"),
|
|
58
|
+
model: Model.Ref,
|
|
59
|
+
previous: Model.Ref.pipe(optional),
|
|
60
|
+
}).annotate({ identifier: "Session.Message.ModelSelected" })
|
|
61
|
+
|
|
62
|
+
export interface LocationSwitched extends Schema.Schema.Type<typeof LocationSwitched> {}
|
|
63
|
+
export const LocationSwitched = Schema.Struct({
|
|
64
|
+
...Base,
|
|
65
|
+
type: Schema.tag("location-switched"),
|
|
66
|
+
location: Location.Ref,
|
|
67
|
+
projectID: Project.ID.pipe(optional),
|
|
68
|
+
subpath: RelativePath.pipe(optional),
|
|
69
|
+
previous: Schema.Struct({
|
|
70
|
+
location: Location.Ref,
|
|
71
|
+
projectID: Project.ID.pipe(optional),
|
|
72
|
+
subpath: RelativePath.pipe(optional),
|
|
73
|
+
}).pipe(optional),
|
|
74
|
+
}).annotate({ identifier: "Session.Message.LocationSwitched" })
|
|
75
|
+
|
|
76
|
+
export interface User extends Schema.Schema.Type<typeof User> {}
|
|
77
|
+
export const User = Schema.Struct({
|
|
78
|
+
...Base,
|
|
79
|
+
/** Read by the session search index's SQL (`packages/core/src/session/search-index.ts`); a rename needs its `Version` bumped. */
|
|
80
|
+
text: Prompt.fields.text,
|
|
81
|
+
files: Prompt.fields.files,
|
|
82
|
+
agents: Prompt.fields.agents,
|
|
83
|
+
skills: Prompt.fields.skills,
|
|
84
|
+
type: Schema.tag("user"),
|
|
85
|
+
}).annotate({ identifier: "Session.Message.User" })
|
|
86
|
+
|
|
87
|
+
/** A {@link User} whose files may stay on the server, for clients that opt into `experimental-media-uri`. */
|
|
88
|
+
export interface MediaUser extends Schema.Schema.Type<typeof MediaUser> {}
|
|
89
|
+
export const MediaUser = Schema.Struct({
|
|
90
|
+
...User.fields,
|
|
91
|
+
files: Schema.Array(Attachment).pipe(optional),
|
|
92
|
+
}).annotate({ identifier: "Session.Message.MediaUser" })
|
|
93
|
+
|
|
94
|
+
export interface Synthetic extends Schema.Schema.Type<typeof Synthetic> {}
|
|
95
|
+
export const Synthetic = Schema.Struct({
|
|
96
|
+
...Base,
|
|
97
|
+
text: Schema.String,
|
|
98
|
+
description: Schema.String.pipe(optional),
|
|
99
|
+
type: Schema.tag("synthetic"),
|
|
100
|
+
}).annotate({ identifier: "Session.Message.Synthetic" })
|
|
101
|
+
|
|
102
|
+
export interface System extends Schema.Schema.Type<typeof System> {}
|
|
103
|
+
export const System = Schema.Struct({
|
|
104
|
+
...Base,
|
|
105
|
+
type: Schema.tag("system"),
|
|
106
|
+
/** The model-facing update text, frozen at emit time. */
|
|
107
|
+
text: Schema.String,
|
|
108
|
+
/** A short human-readable summary for transcript display. */
|
|
109
|
+
description: Schema.String.pipe(optional),
|
|
110
|
+
}).annotate({ identifier: "Session.Message.System" })
|
|
111
|
+
|
|
112
|
+
export interface Skill extends Schema.Schema.Type<typeof Skill> {}
|
|
113
|
+
export const Skill = Schema.Struct({
|
|
114
|
+
...Base,
|
|
115
|
+
type: Schema.tag("skill"),
|
|
116
|
+
skill: SkillSchema.ID,
|
|
117
|
+
name: SkillSchema.Name,
|
|
118
|
+
text: Schema.String,
|
|
119
|
+
}).annotate({ identifier: "Session.Message.Skill" })
|
|
120
|
+
|
|
121
|
+
export interface Shell extends Schema.Schema.Type<typeof Shell> {}
|
|
122
|
+
export const Shell = Schema.Struct({
|
|
123
|
+
...Base,
|
|
124
|
+
type: Schema.tag("shell"),
|
|
125
|
+
shellID: ShellSchema.ID,
|
|
126
|
+
command: Schema.String,
|
|
127
|
+
status: ShellSchema.Status,
|
|
128
|
+
exit: Schema.Number.pipe(optional),
|
|
129
|
+
output: ShellSchema.Output.pipe(optional),
|
|
130
|
+
time: Schema.Struct({
|
|
131
|
+
created: DateTimeUtcFromMillis,
|
|
132
|
+
completed: DateTimeUtcFromMillis.pipe(optional),
|
|
133
|
+
}),
|
|
134
|
+
}).annotate({ identifier: "Session.Message.Shell" })
|
|
135
|
+
|
|
136
|
+
export interface ToolStateStreaming extends Schema.Schema.Type<typeof ToolStateStreaming> {}
|
|
137
|
+
export const ToolStateStreaming = Schema.Struct({
|
|
138
|
+
status: Schema.tag("streaming"),
|
|
139
|
+
input: Schema.String,
|
|
140
|
+
}).annotate({ identifier: "Session.Message.ToolState.Streaming" })
|
|
141
|
+
|
|
142
|
+
export interface ToolStateRunning extends Schema.Schema.Type<typeof ToolStateRunning> {}
|
|
143
|
+
export const ToolStateRunning = Schema.Struct({
|
|
144
|
+
status: Schema.tag("running"),
|
|
145
|
+
input: Schema.Record(Schema.String, Schema.Unknown),
|
|
146
|
+
metadata: Schema.Record(Schema.String, Schema.Json),
|
|
147
|
+
}).annotate({ identifier: "Session.Message.ToolState.Running" })
|
|
148
|
+
|
|
149
|
+
export interface ToolStateCompleted extends Schema.Schema.Type<typeof ToolStateCompleted> {}
|
|
150
|
+
export const ToolStateCompleted = Schema.Struct({
|
|
151
|
+
status: Schema.tag("completed"),
|
|
152
|
+
input: Schema.Record(Schema.String, Schema.Unknown),
|
|
153
|
+
content: Schema.NonEmptyArray(Content),
|
|
154
|
+
metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
|
|
155
|
+
}).annotate({ identifier: "Session.Message.ToolState.Completed" })
|
|
156
|
+
|
|
157
|
+
export interface ToolStateError extends Schema.Schema.Type<typeof ToolStateError> {}
|
|
158
|
+
export const ToolStateError = Schema.Struct({
|
|
159
|
+
status: Schema.tag("error"),
|
|
160
|
+
input: Schema.Record(Schema.String, Schema.Unknown),
|
|
161
|
+
error: SessionError.Error,
|
|
162
|
+
content: Schema.NonEmptyArray(Content).pipe(optional),
|
|
163
|
+
metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
|
|
164
|
+
}).annotate({ identifier: "Session.Message.ToolState.Error" })
|
|
165
|
+
|
|
166
|
+
export const ToolState = Schema.Union([ToolStateStreaming, ToolStateRunning, ToolStateCompleted, ToolStateError]).pipe(
|
|
167
|
+
Schema.toTaggedUnion("status"),
|
|
168
|
+
)
|
|
169
|
+
export type ToolState = ToolStateStreaming | ToolStateRunning | ToolStateCompleted | ToolStateError
|
|
170
|
+
|
|
171
|
+
export interface AssistantTool extends Schema.Schema.Type<typeof AssistantTool> {}
|
|
172
|
+
export const AssistantTool = Schema.Struct({
|
|
173
|
+
type: Schema.tag("tool"),
|
|
174
|
+
id: Schema.String,
|
|
175
|
+
name: Schema.String,
|
|
176
|
+
executed: Schema.Boolean.pipe(optional),
|
|
177
|
+
native: Native.pipe(optional),
|
|
178
|
+
state: ToolState,
|
|
179
|
+
time: Schema.Struct({
|
|
180
|
+
created: DateTimeUtcFromMillis,
|
|
181
|
+
ran: DateTimeUtcFromMillis.pipe(optional),
|
|
182
|
+
completed: DateTimeUtcFromMillis.pipe(optional),
|
|
183
|
+
}),
|
|
184
|
+
}).annotate({ identifier: "Session.Message.Assistant.Tool" })
|
|
185
|
+
|
|
186
|
+
export interface AssistantText extends Schema.Schema.Type<typeof AssistantText> {}
|
|
187
|
+
export const AssistantText = Schema.Struct({
|
|
188
|
+
type: Schema.tag("text"),
|
|
189
|
+
/** Read by the session search index's SQL (`packages/core/src/session/search-index.ts`); a rename needs its `Version` bumped. */
|
|
190
|
+
text: Schema.String,
|
|
191
|
+
native: Native.pipe(optional),
|
|
192
|
+
}).annotate({ identifier: "Session.Message.Assistant.Text" })
|
|
193
|
+
|
|
194
|
+
export interface AssistantReasoning extends Schema.Schema.Type<typeof AssistantReasoning> {}
|
|
195
|
+
export const AssistantReasoning = Schema.Struct({
|
|
196
|
+
type: Schema.tag("reasoning"),
|
|
197
|
+
text: Schema.String,
|
|
198
|
+
native: Native.pipe(optional),
|
|
199
|
+
time: Schema.Struct({
|
|
200
|
+
created: DateTimeUtcFromMillis,
|
|
201
|
+
completed: DateTimeUtcFromMillis.pipe(optional),
|
|
202
|
+
}).pipe(optional),
|
|
203
|
+
}).annotate({ identifier: "Session.Message.Assistant.Reasoning" })
|
|
204
|
+
|
|
205
|
+
export const AssistantContent = Schema.Union([AssistantText, AssistantReasoning, AssistantTool]).pipe(
|
|
206
|
+
Schema.toTaggedUnion("type"),
|
|
207
|
+
)
|
|
208
|
+
export type AssistantContent = AssistantText | AssistantReasoning | AssistantTool
|
|
209
|
+
|
|
210
|
+
export const AssistantContentEncoded = Schema.toEncoded(AssistantContent).annotate({
|
|
211
|
+
identifier: "Session.Message.AssistantContent.Encoded",
|
|
212
|
+
})
|
|
213
|
+
export type AssistantContentEncoded = typeof AssistantContentEncoded.Type
|
|
214
|
+
|
|
215
|
+
export interface AssistantRetry extends Schema.Schema.Type<typeof AssistantRetry> {}
|
|
216
|
+
export const AssistantRetry = Schema.Struct({
|
|
217
|
+
attempt: PositiveInt,
|
|
218
|
+
at: DateTimeUtcFromMillis,
|
|
219
|
+
error: SessionError.Error,
|
|
220
|
+
}).annotate({ identifier: "Session.Message.Assistant.Retry" })
|
|
221
|
+
|
|
222
|
+
export interface Assistant extends Schema.Schema.Type<typeof Assistant> {}
|
|
223
|
+
export const Assistant = Schema.Struct({
|
|
224
|
+
...Base,
|
|
225
|
+
type: Schema.tag("assistant"),
|
|
226
|
+
agent: Agent.ID,
|
|
227
|
+
model: Model.Ref,
|
|
228
|
+
/** Read by the session search index's SQL (`packages/core/src/session/search-index.ts`); a rename needs its `Version` bumped. */
|
|
229
|
+
content: AssistantContent.pipe(Schema.Array),
|
|
230
|
+
snapshot: Schema.Struct({
|
|
231
|
+
start: Snapshot.ID.pipe(optional),
|
|
232
|
+
end: Snapshot.ID.pipe(optional),
|
|
233
|
+
files: Schema.Array(RelativePath).pipe(optional),
|
|
234
|
+
}).pipe(optional),
|
|
235
|
+
finish: FinishReason.pipe(optional),
|
|
236
|
+
rawFinish: Schema.String.pipe(optional),
|
|
237
|
+
/** Step-level native data, such as a provider's reason for blocking a response. */
|
|
238
|
+
native: Native.pipe(optional),
|
|
239
|
+
cost: Money.USD.pipe(optional),
|
|
240
|
+
tokens: TokenUsage.Info.pipe(optional),
|
|
241
|
+
error: SessionError.Error.pipe(optional),
|
|
242
|
+
retry: AssistantRetry.pipe(optional),
|
|
243
|
+
time: Schema.Struct({
|
|
244
|
+
created: DateTimeUtcFromMillis,
|
|
245
|
+
/** When the provider streamed the first output token, before the rest of the response. */
|
|
246
|
+
firstToken: DateTimeUtcFromMillis.pipe(optional),
|
|
247
|
+
/** When the provider response body ended, before tool settlement. */
|
|
248
|
+
streamed: DateTimeUtcFromMillis.pipe(optional),
|
|
249
|
+
/** The session search index waits for this before indexing the message (`search-index.ts`). */
|
|
250
|
+
completed: DateTimeUtcFromMillis.pipe(optional),
|
|
251
|
+
}),
|
|
252
|
+
}).annotate({ identifier: "Session.Message.Assistant" })
|
|
253
|
+
|
|
254
|
+
const CompactionBase = { type: Schema.tag("compaction"), ...Base }
|
|
255
|
+
|
|
256
|
+
/** Usage of the compaction request itself, not the size of the resulting context. */
|
|
257
|
+
const CompactionUsage = {
|
|
258
|
+
cost: Money.USD.pipe(optional),
|
|
259
|
+
tokens: TokenUsage.Info.pipe(optional),
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export interface CompactionRunning extends Schema.Schema.Type<typeof CompactionRunning> {}
|
|
263
|
+
export const CompactionRunning = Schema.Struct({
|
|
264
|
+
...CompactionBase,
|
|
265
|
+
status: Schema.tag("running"),
|
|
266
|
+
reason: Schema.Literals(["auto", "manual"]),
|
|
267
|
+
summary: Schema.String,
|
|
268
|
+
}).annotate({ identifier: "Session.Message.Compaction.Running" })
|
|
269
|
+
|
|
270
|
+
export interface CompactionCompleted extends Schema.Schema.Type<typeof CompactionCompleted> {}
|
|
271
|
+
export const CompactionCompleted = Schema.Struct({
|
|
272
|
+
...CompactionBase,
|
|
273
|
+
status: Schema.tag("completed"),
|
|
274
|
+
reason: Schema.Literals(["auto", "manual"]),
|
|
275
|
+
model: Model.Ref.pipe(optional),
|
|
276
|
+
/** A provider compaction stores its replacement window in `native.messages`, replayed instead of `summary`. */
|
|
277
|
+
native: Native.pipe(optional),
|
|
278
|
+
/** Read by the session search index's SQL (`packages/core/src/session/search-index.ts`); a rename needs its `Version` bumped. */
|
|
279
|
+
summary: Schema.String,
|
|
280
|
+
...CompactionUsage,
|
|
281
|
+
}).annotate({ identifier: "Session.Message.Compaction.Completed" })
|
|
282
|
+
|
|
283
|
+
export interface CompactionFailed extends Schema.Schema.Type<typeof CompactionFailed> {}
|
|
284
|
+
export const CompactionFailed = Schema.Struct({
|
|
285
|
+
...CompactionBase,
|
|
286
|
+
status: Schema.tag("failed"),
|
|
287
|
+
reason: Schema.Literals(["auto", "manual"]),
|
|
288
|
+
error: SessionError.Error,
|
|
289
|
+
...CompactionUsage,
|
|
290
|
+
}).annotate({ identifier: "Session.Message.Compaction.Failed" })
|
|
291
|
+
|
|
292
|
+
export const Compaction = Schema.Union([CompactionRunning, CompactionCompleted, CompactionFailed]).pipe(
|
|
293
|
+
Schema.toTaggedUnion("status"),
|
|
294
|
+
Schema.annotate({ identifier: "Session.Message.Compaction" }),
|
|
295
|
+
)
|
|
296
|
+
export type Compaction = CompactionRunning | CompactionCompleted | CompactionFailed
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Marks the Session going idle: every step since the previous marker belongs to
|
|
300
|
+
* one turn, including prompts steered in while it was busy. A shutdown does not
|
|
301
|
+
* record one, since the resumed execution continues the same turn.
|
|
302
|
+
*/
|
|
303
|
+
export interface Idle extends Schema.Schema.Type<typeof Idle> {}
|
|
304
|
+
export const Idle = Schema.Struct({
|
|
305
|
+
...Base,
|
|
306
|
+
type: Schema.tag("idle"),
|
|
307
|
+
outcome: Schema.Literals(["succeeded", "failed", "interrupted"]),
|
|
308
|
+
error: SessionError.Error.pipe(optional),
|
|
309
|
+
}).annotate({ identifier: "Session.Message.Idle" })
|
|
310
|
+
|
|
311
|
+
export const Info = Schema.Union([
|
|
312
|
+
AgentSelected,
|
|
313
|
+
ModelSelected,
|
|
314
|
+
LocationSwitched,
|
|
315
|
+
User,
|
|
316
|
+
Synthetic,
|
|
317
|
+
System,
|
|
318
|
+
Skill,
|
|
319
|
+
Shell,
|
|
320
|
+
Assistant,
|
|
321
|
+
Compaction,
|
|
322
|
+
Idle,
|
|
323
|
+
]).annotate({ identifier: "Session.Message.Info" })
|
|
324
|
+
export type Info =
|
|
325
|
+
| AgentSelected
|
|
326
|
+
| ModelSelected
|
|
327
|
+
| LocationSwitched
|
|
328
|
+
| User
|
|
329
|
+
| Synthetic
|
|
330
|
+
| System
|
|
331
|
+
| Skill
|
|
332
|
+
| Shell
|
|
333
|
+
| Assistant
|
|
334
|
+
| Compaction
|
|
335
|
+
| Idle
|
|
336
|
+
export type Type = Info["type"]
|
|
337
|
+
|
|
338
|
+
/** {@link Info} with {@link MediaUser} for clients that opt into `experimental-media-uri`. */
|
|
339
|
+
export const MediaInfo = Schema.Union([
|
|
340
|
+
AgentSelected,
|
|
341
|
+
ModelSelected,
|
|
342
|
+
LocationSwitched,
|
|
343
|
+
MediaUser,
|
|
344
|
+
Synthetic,
|
|
345
|
+
System,
|
|
346
|
+
Skill,
|
|
347
|
+
Shell,
|
|
348
|
+
Assistant,
|
|
349
|
+
Compaction,
|
|
350
|
+
Idle,
|
|
351
|
+
]).annotate({ identifier: "Session.Message.MediaInfo" })
|
|
352
|
+
export type MediaInfo = Exclude<Info, User> | MediaUser
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Host-supplied session annotations, durable and opaque to core. Keys are
|
|
5
|
+
* arbitrary; values must be JSON-serializable. Children and forks inherit
|
|
6
|
+
* the parent's current metadata unless the creator supplies its own.
|
|
7
|
+
*/
|
|
8
|
+
export const SessionMetadata = Schema.Record(Schema.String, Schema.Json).annotate({
|
|
9
|
+
identifier: "Session.Metadata",
|
|
10
|
+
})
|
|
11
|
+
export type SessionMetadata = typeof SessionMetadata.Type
|