feat(core): replace instruction checkpoints with value-delta sync (#36254)
This commit is contained in:
parent
768a69bbbd
commit
96a9731947
57 changed files with 2053 additions and 1278 deletions
|
|
@ -5,8 +5,8 @@ import { SessionEvent } from "./session-event.js"
|
|||
import { SessionV1 } from "./session-v1.js"
|
||||
|
||||
export const SessionDurable = {
|
||||
definitions: Event.durableMap(SessionEvent.Definitions),
|
||||
definitions: Event.durableMap(SessionEvent.DurableDefinitions),
|
||||
schema: SessionEvent.Durable,
|
||||
} as const
|
||||
|
||||
export const Durable = Event.durableMap([...SessionV1.Event.Definitions, ...SessionEvent.Definitions])
|
||||
export const Durable = Event.durableMap([...SessionV1.Event.Definitions, ...SessionEvent.DurableDefinitions])
|
||||
|
|
|
|||
|
|
@ -18,3 +18,15 @@ export const Info = Schema.Struct({
|
|||
value: Schema.Json.annotate({ description: "JSON value attached to the session's instructions" }),
|
||||
}).annotate({ identifier: "InstructionEntry.Info" })
|
||||
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
||||
|
||||
export const MaxValueBytes = 8 * 1024
|
||||
|
||||
export class ValueTooLargeError extends Schema.TaggedErrorClass<ValueTooLargeError>()(
|
||||
"InstructionEntryValueTooLargeError",
|
||||
{
|
||||
actualBytes: Schema.Int,
|
||||
maxBytes: Schema.Int,
|
||||
message: Schema.String,
|
||||
},
|
||||
{ httpApiStatus: 413 },
|
||||
) {}
|
||||
|
|
|
|||
21
packages/schema/src/instruction.ts
Normal file
21
packages/schema/src/instruction.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
export * as Instruction from "./instruction.js"
|
||||
|
||||
import { Schema } from "effect"
|
||||
|
||||
export const Key = Schema.String.check(Schema.isPattern(/^[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._/-]*$/)).pipe(
|
||||
Schema.brand("Instruction.Key"),
|
||||
)
|
||||
export type Key = typeof Key.Type
|
||||
|
||||
export const Hash = Schema.String.check(Schema.isPattern(/^[a-f0-9]{64}$/)).pipe(Schema.brand("Instruction.Hash"))
|
||||
export type Hash = typeof Hash.Type
|
||||
|
||||
export const Values = Schema.Record(Key, Hash)
|
||||
export type Values = Readonly<Record<string, Hash>>
|
||||
|
||||
export const Removed = Schema.Literal("removed")
|
||||
export type Removed = typeof Removed.Type
|
||||
export const removed = Removed.make("removed")
|
||||
|
||||
export const Delta = Schema.Record(Schema.String, Schema.Union([Hash, Removed]))
|
||||
export type Delta = typeof Delta.Type
|
||||
|
|
@ -14,6 +14,7 @@ import { SessionMessage } from "./session-message.js"
|
|||
import { Revert } from "./session-revert.js"
|
||||
import { Shell as ShellSchema } from "./shell.js"
|
||||
import { SessionError } from "./session-error.js"
|
||||
import { Instruction } from "./instruction.js"
|
||||
import { Agent } from "./agent.js"
|
||||
import { Skill as SkillSchema } from "./skill.js"
|
||||
import { Money } from "./money.js"
|
||||
|
|
@ -105,10 +106,14 @@ export type Deleted = typeof Deleted.Type
|
|||
|
||||
export const Forked = Event.durable({
|
||||
type: "session.forked",
|
||||
...options,
|
||||
durable: {
|
||||
aggregate: "sessionID",
|
||||
version: 2,
|
||||
},
|
||||
schema: {
|
||||
...Base,
|
||||
parentID: SessionID,
|
||||
parentSeq: Schema.Int.check(Schema.isGreaterThanOrEqualTo(-1)),
|
||||
from: SessionMessage.ID.pipe(optional),
|
||||
},
|
||||
})
|
||||
|
|
@ -159,10 +164,13 @@ export namespace Execution {
|
|||
|
||||
export const InstructionsUpdated = Event.durable({
|
||||
type: "session.instructions.updated",
|
||||
...options,
|
||||
durable: {
|
||||
aggregate: "sessionID",
|
||||
version: 2,
|
||||
},
|
||||
schema: {
|
||||
...Base,
|
||||
text: Schema.String,
|
||||
delta: Instruction.Delta,
|
||||
},
|
||||
})
|
||||
export type InstructionsUpdated = typeof InstructionsUpdated.Type
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue