mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-28 19:14:53 +00:00
79 lines
2.6 KiB
TypeScript
79 lines
2.6 KiB
TypeScript
export * as Job from "./job.js"
|
|
|
|
import { Schema } from "effect"
|
|
import { ephemeral, inventory } from "./event.js"
|
|
import { optional } from "./schema.js"
|
|
import { SessionID } from "./session-id.js"
|
|
|
|
export const Kind = Schema.Literals(["shell", "subagent", "image", "video", "codemode"]).annotate({
|
|
identifier: "Job.Kind",
|
|
})
|
|
export type Kind = typeof Kind.Type
|
|
|
|
export const Status = Schema.Literals(["running", "completed", "error", "cancelled"]).annotate({
|
|
identifier: "Job.Status",
|
|
})
|
|
export type Status = typeof Status.Type
|
|
|
|
export interface Time extends Schema.Schema.Type<typeof Time> {}
|
|
export const Time = Schema.Struct({
|
|
started: Schema.Finite.annotate({ description: "Start time in milliseconds since the Unix epoch" }),
|
|
completed: optional(Schema.Finite).annotate({
|
|
description: "Completion time in milliseconds since the Unix epoch",
|
|
}),
|
|
}).annotate({ identifier: "Job.Time" })
|
|
|
|
const Base = {
|
|
id: Schema.String,
|
|
sessionID: SessionID,
|
|
status: Status,
|
|
title: optional(Schema.String),
|
|
time: Time,
|
|
}
|
|
|
|
export interface Shell extends Schema.Schema.Type<typeof Shell> {}
|
|
export const Shell = Schema.Struct({
|
|
kind: Schema.tag("shell"),
|
|
...Base,
|
|
shellID: Schema.String,
|
|
command: Schema.String,
|
|
}).annotate({ identifier: "Job.Shell" })
|
|
|
|
export interface Subagent extends Schema.Schema.Type<typeof Subagent> {}
|
|
export const Subagent = Schema.Struct({
|
|
kind: Schema.tag("subagent"),
|
|
...Base,
|
|
childSessionID: SessionID,
|
|
agent: Schema.String,
|
|
description: Schema.String,
|
|
}).annotate({ identifier: "Job.Subagent" })
|
|
|
|
export interface Image extends Schema.Schema.Type<typeof Image> {}
|
|
export const Image = Schema.Struct({
|
|
kind: Schema.tag("image"),
|
|
...Base,
|
|
path: Schema.String,
|
|
model: Schema.String,
|
|
}).annotate({ identifier: "Job.Image" })
|
|
|
|
export interface Video extends Schema.Schema.Type<typeof Video> {}
|
|
export const Video = Schema.Struct({
|
|
kind: Schema.tag("video"),
|
|
...Base,
|
|
path: Schema.String,
|
|
}).annotate({ identifier: "Job.Video" })
|
|
|
|
export interface CodeMode extends Schema.Schema.Type<typeof CodeMode> {}
|
|
export const CodeMode = Schema.Struct({ kind: Schema.tag("codemode"), ...Base }).annotate({
|
|
identifier: "Job.CodeMode",
|
|
})
|
|
|
|
export const Info = Schema.Union([Shell, Subagent, Image, Video, CodeMode]).pipe(
|
|
Schema.toTaggedUnion("kind"),
|
|
Schema.annotate({ identifier: "Job.Info" }),
|
|
)
|
|
export type Info = typeof Info.Type
|
|
|
|
/** A background job started, moved to the background, or ended. Experimental: may change without compatibility guarantees. */
|
|
const Updated = ephemeral({ type: "experimental.job.updated", schema: { info: Info } })
|
|
export const Event = { Updated, Definitions: inventory(Updated) }
|