feat(core): session.pending.list API with pending-only session_pending storage (#36126)

This commit is contained in:
Kit Langton 2026-07-09 17:25:40 -04:00 committed by GitHub
commit a72992e00f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 986 additions and 649 deletions

View file

@ -20,7 +20,7 @@ export { Provider } from "./provider.js"
export { Reference } from "./reference.js"
export { Session } from "./session.js"
export { Vcs } from "./vcs.js"
export { SessionInput } from "./session-input.js"
export { SessionPending } from "./session-pending.js"
export { SessionError } from "./session-error.js"
export { SessionMessage } from "./session-message.js"
export { Snapshot } from "./snapshot.js"

View file

@ -19,7 +19,7 @@ import { Skill as SkillSchema } from "./skill.js"
import { Money } from "./money.js"
import { Snapshot } from "./snapshot.js"
import { TokenUsage } from "./token-usage.js"
import { SessionInput } from "./session-input.js"
import { SessionPending } from "./session-pending.js"
export { FileAttachment }
@ -130,7 +130,7 @@ export const InputAdmitted = Event.durable({
schema: {
...Base,
inputID: SessionMessage.ID,
input: SessionInput.Message,
input: SessionPending.Message,
},
})
export type InputAdmitted = typeof InputAdmitted.Type

View file

@ -1,4 +1,4 @@
export * as SessionInput from "./session-input.js"
export * as SessionPending from "./session-pending.js"
import { Schema } from "effect"
import { optional } from "./schema.js"
@ -15,32 +15,32 @@ export interface UserData extends Schema.Schema.Type<typeof UserData> {}
export const UserData = Schema.Struct({
...Prompt.fields,
metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
}).annotate({ identifier: "SessionInput.UserData" })
}).annotate({ identifier: "SessionPending.UserData" })
export interface SyntheticData extends Schema.Schema.Type<typeof SyntheticData> {}
export const SyntheticData = Schema.Struct({
text: Schema.String,
description: Schema.String.pipe(optional),
metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
}).annotate({ identifier: "SessionInput.SyntheticData" })
}).annotate({ identifier: "SessionPending.SyntheticData" })
export interface UserMessage extends Schema.Schema.Type<typeof UserMessage> {}
export const UserMessage = Schema.Struct({
type: Schema.tag("user"),
data: UserData,
delivery: Delivery,
}).annotate({ identifier: "SessionInput.UserMessage" })
}).annotate({ identifier: "SessionPending.UserMessage" })
export interface SyntheticMessage extends Schema.Schema.Type<typeof SyntheticMessage> {}
export const SyntheticMessage = Schema.Struct({
type: Schema.tag("synthetic"),
data: SyntheticData,
delivery: Delivery,
}).annotate({ identifier: "SessionInput.SyntheticMessage" })
}).annotate({ identifier: "SessionPending.SyntheticMessage" })
export const Message = Schema.Union([UserMessage, SyntheticMessage]).pipe(
Schema.toTaggedUnion("type"),
Schema.annotate({ identifier: "SessionInput.Message" }),
Schema.annotate({ identifier: "SessionPending.Message" }),
)
export type Message = typeof Message.Type
@ -50,32 +50,27 @@ const Admitted = {
sessionID: SessionID,
timeCreated: DateTimeUtcFromMillis,
}
const MessageLifecycle = {
...Admitted,
promotedSeq: NonNegativeInt.pipe(optional),
}
export interface User extends Schema.Schema.Type<typeof User> {}
export const User = Schema.Struct({
...MessageLifecycle,
...Admitted,
...UserMessage.fields,
}).annotate({ identifier: "SessionInput.User" })
}).annotate({ identifier: "SessionPending.User" })
export interface Synthetic extends Schema.Schema.Type<typeof Synthetic> {}
export const Synthetic = Schema.Struct({
...MessageLifecycle,
...Admitted,
...SyntheticMessage.fields,
}).annotate({ identifier: "SessionInput.Synthetic" })
}).annotate({ identifier: "SessionPending.Synthetic" })
export interface Compaction extends Schema.Schema.Type<typeof Compaction> {}
export const Compaction = Schema.Struct({
...Admitted,
type: Schema.tag("compaction"),
handledSeq: NonNegativeInt.pipe(optional),
}).annotate({ identifier: "SessionInput.Compaction" })
}).annotate({ identifier: "SessionPending.Compaction" })
export const Info = Schema.Union([User, Synthetic, Compaction]).pipe(
Schema.toTaggedUnion("type"),
Schema.annotate({ identifier: "SessionInput.Info" }),
Schema.annotate({ identifier: "SessionPending.Info" }),
)
export type Info = typeof Info.Type

View file

@ -10,7 +10,7 @@ import { Pty } from "../src/pty.js"
import { Question } from "../src/question.js"
import { Session } from "../src/session.js"
import { SessionMessage } from "../src/session-message.js"
import { SessionInput } from "../src/session-input.js"
import { SessionPending } from "../src/session-pending.js"
import { FileDiff } from "../src/file-diff.js"
import { Money } from "../src/money.js"
import { Skill } from "../src/skill.js"
@ -39,7 +39,7 @@ describe("contract hygiene", () => {
expect(Schema.encodeSync(Value)({ value: 1 })).toEqual({ value: "1" })
expect(Schema.encodeSync(Value)({ value: undefined })).toEqual({})
expect(
Schema.encodeSync(SessionInput.SyntheticData)({
Schema.encodeSync(SessionPending.SyntheticData)({
text: "completed",
description: undefined,
metadata: undefined,
@ -89,10 +89,10 @@ describe("contract hygiene", () => {
Pty.Info,
Session.ListAnchor,
Session.Revert,
SessionInput.UserData,
SessionInput.SyntheticData,
SessionInput.User,
SessionInput.Synthetic,
SessionPending.UserData,
SessionPending.SyntheticData,
SessionPending.User,
SessionPending.Synthetic,
].map((schema) => schema.ast.annotations?.identifier)
expect(identifiers.every((identifier) => typeof identifier === "string")).toBe(true)
@ -134,7 +134,7 @@ describe("contract hygiene", () => {
test("reviewed session contracts use their canonical current shapes", () => {
expect(SessionMessage.Info.ast.annotations?.identifier).toBe("Session.Message.Info")
expect(SessionInput.Info.ast.annotations?.identifier).toBe("SessionInput.Info")
expect(SessionPending.Info.ast.annotations?.identifier).toBe("SessionPending.Info")
expect(Money.USD).not.toBe(Money.USDPerMillionTokens)
expect(
FileDiff.Info.make({ file: "src/index.ts", patch: "@@", additions: 1, deletions: 0, status: "modified" }),