@zyro-sec/schema 1.0.0 → 1.0.2
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 -11
- 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
package/src/generate.ts
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
export * as Generate from "./generate.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { BlobStore } from "./blob-store.js"
|
|
5
|
+
import { descending } from "./identifier.js"
|
|
6
|
+
import { Model } from "./model.js"
|
|
7
|
+
import { Money } from "./money.js"
|
|
8
|
+
import { Base64 } from "./prompt.js"
|
|
9
|
+
import { PositiveInt, optional, statics } from "./schema.js"
|
|
10
|
+
|
|
11
|
+
const description = (text: string) => ({ description: text })
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Shared
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
export interface File extends Schema.Schema.Type<typeof File> {}
|
|
18
|
+
export const File = Schema.Struct({
|
|
19
|
+
data: Base64,
|
|
20
|
+
mime: Schema.String,
|
|
21
|
+
name: Schema.String.pipe(optional),
|
|
22
|
+
}).annotate({ identifier: "Generate.File" })
|
|
23
|
+
|
|
24
|
+
export interface ImageFile extends Schema.Schema.Type<typeof ImageFile> {}
|
|
25
|
+
export const ImageFile = Schema.Struct({
|
|
26
|
+
...File.fields,
|
|
27
|
+
mime: Schema.String.check(Schema.isPattern(/^image\//iu)),
|
|
28
|
+
}).annotate({ identifier: "Generate.ImageFile" })
|
|
29
|
+
|
|
30
|
+
export interface Usage extends Schema.Schema.Type<typeof Usage> {}
|
|
31
|
+
export const Usage = Schema.Struct({
|
|
32
|
+
input: Schema.Finite.pipe(optional),
|
|
33
|
+
output: Schema.Finite.pipe(optional),
|
|
34
|
+
}).annotate({ identifier: "Generate.Usage", description: "Token counts, when the provider reports them" })
|
|
35
|
+
|
|
36
|
+
export const Native = Schema.Record(Schema.String, Schema.Unknown).annotate({
|
|
37
|
+
identifier: "Generate.Native",
|
|
38
|
+
description: "Provider-specific data the shared fields do not cover",
|
|
39
|
+
})
|
|
40
|
+
export type Native = typeof Native.Type
|
|
41
|
+
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
// Image
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
export type ImageAspect = `${number}:${number}`
|
|
47
|
+
// The template literal gives clients the type; the pattern also rejects signs and exponents it would allow.
|
|
48
|
+
export const ImageAspect: Schema.Codec<ImageAspect> = Schema.TemplateLiteral([Schema.Number, ":", Schema.Number])
|
|
49
|
+
.check(Schema.isPattern(/^\d+(?:\.\d+)?:\d+(?:\.\d+)?$/))
|
|
50
|
+
.annotate({ identifier: "Generate.ImageAspect", description: "Aspect ratio as width:height, for example 16:9" })
|
|
51
|
+
|
|
52
|
+
/** Open-ended: providers add size tiers beyond these. */
|
|
53
|
+
export type ImageResolution = "1K" | "2K" | "4K" | (string & {})
|
|
54
|
+
export const ImageResolution: Schema.Codec<ImageResolution> = Schema.Union([
|
|
55
|
+
Schema.Literals(["1K", "2K", "4K"]),
|
|
56
|
+
Schema.String,
|
|
57
|
+
]).annotate({
|
|
58
|
+
identifier: "Generate.ImageResolution",
|
|
59
|
+
description: "Size tier such as 1K, 2K or 4K; 1K is about as many pixels as 1024x1024 at the requested aspect",
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
export interface ImageRequest extends Schema.Schema.Type<typeof ImageRequest> {}
|
|
63
|
+
export const ImageRequest = Schema.Struct({
|
|
64
|
+
model: Model.Ref,
|
|
65
|
+
prompt: Schema.String,
|
|
66
|
+
images: Schema.Array(File)
|
|
67
|
+
.pipe(optional)
|
|
68
|
+
.annotate(description("Edit sources or style and subject references, in order")),
|
|
69
|
+
n: PositiveInt.pipe(optional).annotate(description("Number of images to generate; defaults to 1")),
|
|
70
|
+
aspect: ImageAspect.pipe(optional),
|
|
71
|
+
resolution: ImageResolution.pipe(optional),
|
|
72
|
+
}).annotate({ identifier: "Generate.ImageRequest" })
|
|
73
|
+
|
|
74
|
+
export interface ImageOutput extends Schema.Schema.Type<typeof ImageOutput> {}
|
|
75
|
+
export const ImageOutput = Schema.Struct({
|
|
76
|
+
type: Schema.Literal("image"),
|
|
77
|
+
...File.fields,
|
|
78
|
+
}).annotate({ identifier: "Generate.ImageOutput" })
|
|
79
|
+
|
|
80
|
+
export interface ImageResult extends Schema.Schema.Type<typeof ImageResult> {}
|
|
81
|
+
export const ImageResult = Schema.Struct({
|
|
82
|
+
images: Schema.Array(ImageOutput),
|
|
83
|
+
cost: Money.USD.pipe(optional),
|
|
84
|
+
tokens: Usage.pipe(optional),
|
|
85
|
+
native: Native.pipe(optional),
|
|
86
|
+
}).annotate({ identifier: "Generate.ImageResult" })
|
|
87
|
+
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
// Video
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
|
|
92
|
+
// Strict, because the server names files after it.
|
|
93
|
+
export const VideoID = Schema.String.check(Schema.isPattern(/^video_[0-9a-f]{12}[0-9A-Za-z]{14}$/u)).pipe(
|
|
94
|
+
Schema.brand("Generate.VideoID"),
|
|
95
|
+
Schema.annotate({ identifier: "Generate.VideoID" }),
|
|
96
|
+
statics((schema) => ({
|
|
97
|
+
create: () => schema.make("video_" + descending()),
|
|
98
|
+
})),
|
|
99
|
+
)
|
|
100
|
+
export type VideoID = typeof VideoID.Type
|
|
101
|
+
|
|
102
|
+
export type VideoAspect = `${number}:${number}` | "auto"
|
|
103
|
+
export const VideoAspect: Schema.Codec<VideoAspect> = Schema.Union([ImageAspect, Schema.Literal("auto")]).annotate({
|
|
104
|
+
identifier: "Generate.VideoAspect",
|
|
105
|
+
description: "Aspect ratio as width:height, or auto to follow the start image",
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
export type VideoResolution = "480p" | "720p" | "1080p" | "4k" | (string & {})
|
|
109
|
+
export const VideoResolution: Schema.Codec<VideoResolution> = Schema.Union([
|
|
110
|
+
Schema.Literals(["480p", "720p", "1080p", "4k"]),
|
|
111
|
+
Schema.String,
|
|
112
|
+
]).annotate({ identifier: "Generate.VideoResolution" })
|
|
113
|
+
|
|
114
|
+
export interface VideoRequest extends Schema.Schema.Type<typeof VideoRequest> {}
|
|
115
|
+
export const VideoRequest = Schema.Struct({
|
|
116
|
+
model: Model.Ref,
|
|
117
|
+
prompt: Schema.String,
|
|
118
|
+
start: ImageFile.pipe(optional).annotate(description("Image the video starts on exactly")),
|
|
119
|
+
end: ImageFile.pipe(optional).annotate(description("Image the video ends on exactly")),
|
|
120
|
+
references: Schema.Array(File)
|
|
121
|
+
.pipe(optional)
|
|
122
|
+
.annotate(description("Images, videos or audio that guide the subject or style without pinning a frame")),
|
|
123
|
+
duration: PositiveInt.pipe(optional).annotate(description("Length in seconds")),
|
|
124
|
+
aspect: VideoAspect.pipe(optional),
|
|
125
|
+
resolution: VideoResolution.pipe(optional),
|
|
126
|
+
sound: Schema.Boolean.pipe(optional).annotate(
|
|
127
|
+
description("Whether the video has a generated soundtrack; unset leaves the model's default"),
|
|
128
|
+
),
|
|
129
|
+
}).annotate({ identifier: "Generate.VideoRequest" })
|
|
130
|
+
|
|
131
|
+
export const VideoErrorReason = Schema.Literals(["failed", "cancelled", "expired", "unknown"]).annotate({
|
|
132
|
+
identifier: "Generate.VideoErrorReason",
|
|
133
|
+
description:
|
|
134
|
+
"failed: the provider failed the job. cancelled: the provider cancelled it. expired: the provider expired it. unknown: the provider gave no result in time",
|
|
135
|
+
})
|
|
136
|
+
export type VideoErrorReason = typeof VideoErrorReason.Type
|
|
137
|
+
|
|
138
|
+
export interface VideoRunning extends Schema.Schema.Type<typeof VideoRunning> {}
|
|
139
|
+
export const VideoRunning = Schema.Struct({
|
|
140
|
+
id: VideoID,
|
|
141
|
+
status: Schema.Literal("running"),
|
|
142
|
+
}).annotate({ identifier: "Generate.VideoRunning" })
|
|
143
|
+
|
|
144
|
+
export interface VideoCompleted extends Schema.Schema.Type<typeof VideoCompleted> {}
|
|
145
|
+
export const VideoCompleted = Schema.Struct({
|
|
146
|
+
id: VideoID,
|
|
147
|
+
status: Schema.Literal("completed"),
|
|
148
|
+
blobs: Schema.Array(BlobStore.Info).annotate(
|
|
149
|
+
description("The finished videos, usually one. Read each with GET /api/experimental/blob/:id"),
|
|
150
|
+
),
|
|
151
|
+
}).annotate({ identifier: "Generate.VideoCompleted" })
|
|
152
|
+
|
|
153
|
+
export interface VideoError extends Schema.Schema.Type<typeof VideoError> {}
|
|
154
|
+
export const VideoError = Schema.Struct({
|
|
155
|
+
id: VideoID,
|
|
156
|
+
status: Schema.Literal("error"),
|
|
157
|
+
error: Schema.String,
|
|
158
|
+
reason: VideoErrorReason,
|
|
159
|
+
}).annotate({ identifier: "Generate.VideoError" })
|
|
160
|
+
|
|
161
|
+
export type VideoJob = VideoRunning | VideoCompleted | VideoError
|
|
162
|
+
export const VideoJob = Schema.Union([VideoRunning, VideoCompleted, VideoError]).annotate({
|
|
163
|
+
identifier: "Generate.VideoJob",
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
// Decisions
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
|
|
170
|
+
export interface DecisionTextPart extends Schema.Schema.Type<typeof DecisionTextPart> {}
|
|
171
|
+
export const DecisionTextPart = Schema.Struct({ type: Schema.Literal("text"), text: Schema.String }).annotate({
|
|
172
|
+
identifier: "Generate.DecisionTextPart",
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
export interface DecisionJsonPart extends Schema.Schema.Type<typeof DecisionJsonPart> {}
|
|
176
|
+
export const DecisionJsonPart = Schema.Struct({ type: Schema.Literal("json"), value: Schema.Json }).annotate({
|
|
177
|
+
identifier: "Generate.DecisionJsonPart",
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
export interface DecisionFilePart extends Schema.Schema.Type<typeof DecisionFilePart> {}
|
|
181
|
+
export const DecisionFilePart = Schema.Struct({
|
|
182
|
+
type: Schema.Literal("file"),
|
|
183
|
+
...File.fields,
|
|
184
|
+
}).annotate({ identifier: "Generate.DecisionFilePart" })
|
|
185
|
+
|
|
186
|
+
export type DecisionPart = DecisionTextPart | DecisionJsonPart | DecisionFilePart
|
|
187
|
+
export const DecisionPart = Schema.Union([DecisionTextPart, DecisionJsonPart, DecisionFilePart]).annotate({
|
|
188
|
+
identifier: "Generate.DecisionPart",
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
export const ChoiceValue = Schema.Union([Schema.String, Schema.Boolean]).annotate({
|
|
192
|
+
identifier: "Generate.ChoiceValue",
|
|
193
|
+
description: 'Choice values are typed: true and "true" are different values',
|
|
194
|
+
})
|
|
195
|
+
export type ChoiceValue = typeof ChoiceValue.Type
|
|
196
|
+
|
|
197
|
+
const QuestionName = Schema.String.annotate(description("Unique within the request; echoed on the matching answer"))
|
|
198
|
+
|
|
199
|
+
export interface PredicateQuestion extends Schema.Schema.Type<typeof PredicateQuestion> {}
|
|
200
|
+
export const PredicateQuestion = Schema.Struct({
|
|
201
|
+
type: Schema.Literal("predicate"),
|
|
202
|
+
name: QuestionName,
|
|
203
|
+
instructions: Schema.String,
|
|
204
|
+
criteria: Schema.Struct({ true: Schema.String.pipe(optional), false: Schema.String.pipe(optional) })
|
|
205
|
+
.pipe(optional)
|
|
206
|
+
.annotate(description("What counts as true and as false, for statements the instructions alone leave ambiguous")),
|
|
207
|
+
}).annotate({ identifier: "Generate.PredicateQuestion", description: "The probability that a statement is true" })
|
|
208
|
+
|
|
209
|
+
export interface ChoiceQuestion extends Schema.Schema.Type<typeof ChoiceQuestion> {}
|
|
210
|
+
export const ChoiceQuestion = Schema.Struct({
|
|
211
|
+
type: Schema.Literal("choice"),
|
|
212
|
+
name: QuestionName,
|
|
213
|
+
instructions: Schema.String,
|
|
214
|
+
choices: Schema.Array(Schema.Struct({ value: ChoiceValue, description: Schema.String.pipe(optional) })).check(
|
|
215
|
+
Schema.isMinLength(1),
|
|
216
|
+
),
|
|
217
|
+
}).annotate({ identifier: "Generate.ChoiceQuestion", description: "Pick one value from a fixed set" })
|
|
218
|
+
|
|
219
|
+
export interface ScoreQuestion extends Schema.Schema.Type<typeof ScoreQuestion> {}
|
|
220
|
+
export const ScoreQuestion = Schema.Struct({
|
|
221
|
+
type: Schema.Literal("score"),
|
|
222
|
+
name: QuestionName,
|
|
223
|
+
instructions: Schema.String,
|
|
224
|
+
levels: Schema.Array(Schema.Struct({ label: Schema.String, description: Schema.String.pipe(optional) })).check(
|
|
225
|
+
Schema.isMinLength(1),
|
|
226
|
+
),
|
|
227
|
+
}).annotate({ identifier: "Generate.ScoreQuestion", description: "Place the input on ordered levels, lowest first" })
|
|
228
|
+
|
|
229
|
+
export type DecisionQuestion = PredicateQuestion | ChoiceQuestion | ScoreQuestion
|
|
230
|
+
export const DecisionQuestion = Schema.Union([PredicateQuestion, ChoiceQuestion, ScoreQuestion]).annotate({
|
|
231
|
+
identifier: "Generate.DecisionQuestion",
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
export interface DecisionRequest extends Schema.Schema.Type<typeof DecisionRequest> {}
|
|
235
|
+
export const DecisionRequest = Schema.Struct({
|
|
236
|
+
model: Model.Ref,
|
|
237
|
+
input: Schema.Array(DecisionPart).annotate(description("The evidence every question is asked about, in order")),
|
|
238
|
+
questions: Schema.Array(DecisionQuestion)
|
|
239
|
+
.check(Schema.isMinLength(1))
|
|
240
|
+
.annotate(description("Question names must be unique; duplicates fail with InvalidRequestError")),
|
|
241
|
+
}).annotate({ identifier: "Generate.DecisionRequest" })
|
|
242
|
+
|
|
243
|
+
const Probability = Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: 1 }))
|
|
244
|
+
|
|
245
|
+
export interface PredicateAnswer extends Schema.Schema.Type<typeof PredicateAnswer> {}
|
|
246
|
+
export const PredicateAnswer = Schema.Struct({
|
|
247
|
+
type: Schema.Literal("predicate"),
|
|
248
|
+
name: Schema.String,
|
|
249
|
+
probability: Probability,
|
|
250
|
+
}).annotate({ identifier: "Generate.PredicateAnswer" })
|
|
251
|
+
|
|
252
|
+
export interface ChoiceAnswer extends Schema.Schema.Type<typeof ChoiceAnswer> {}
|
|
253
|
+
export const ChoiceAnswer = Schema.Struct({
|
|
254
|
+
type: Schema.Literal("choice"),
|
|
255
|
+
name: Schema.String,
|
|
256
|
+
choice: ChoiceValue,
|
|
257
|
+
probabilities: Schema.Array(Schema.Struct({ value: ChoiceValue, probability: Probability })),
|
|
258
|
+
confidence: Probability,
|
|
259
|
+
}).annotate({ identifier: "Generate.ChoiceAnswer" })
|
|
260
|
+
|
|
261
|
+
export interface ScoreAnswer extends Schema.Schema.Type<typeof ScoreAnswer> {}
|
|
262
|
+
export const ScoreAnswer = Schema.Struct({
|
|
263
|
+
type: Schema.Literal("score"),
|
|
264
|
+
name: Schema.String,
|
|
265
|
+
score: Schema.Finite.annotate(description("Probability-weighted level index, so it can fall between levels")),
|
|
266
|
+
probabilities: Schema.Array(Schema.Struct({ value: Schema.Int, label: Schema.String, probability: Probability })),
|
|
267
|
+
confidence: Probability,
|
|
268
|
+
}).annotate({ identifier: "Generate.ScoreAnswer" })
|
|
269
|
+
|
|
270
|
+
export interface ErrorAnswer extends Schema.Schema.Type<typeof ErrorAnswer> {}
|
|
271
|
+
export const ErrorAnswer = Schema.Struct({
|
|
272
|
+
type: Schema.Literal("error"),
|
|
273
|
+
name: Schema.String,
|
|
274
|
+
reason: Schema.String.annotate(description("Why the question has no answer, for example refusal")),
|
|
275
|
+
message: Schema.String.pipe(optional),
|
|
276
|
+
}).annotate({
|
|
277
|
+
identifier: "Generate.ErrorAnswer",
|
|
278
|
+
description: "This one question has no answer; the other answers still came back",
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
export type DecisionAnswer = PredicateAnswer | ChoiceAnswer | ScoreAnswer | ErrorAnswer
|
|
282
|
+
export const DecisionAnswer = Schema.Union([PredicateAnswer, ChoiceAnswer, ScoreAnswer, ErrorAnswer]).annotate({
|
|
283
|
+
identifier: "Generate.DecisionAnswer",
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
export interface DecisionResult extends Schema.Schema.Type<typeof DecisionResult> {}
|
|
287
|
+
export const DecisionResult = Schema.Struct({
|
|
288
|
+
answers: Schema.Array(DecisionAnswer).annotate(description("One answer per question, in question order")),
|
|
289
|
+
cost: Money.USD.pipe(optional),
|
|
290
|
+
tokens: Usage.pipe(optional),
|
|
291
|
+
native: Native.pipe(optional),
|
|
292
|
+
}).annotate({ identifier: "Generate.DecisionResult" })
|
package/src/goal.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export * as Goal from "./goal.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { Rpc } from "./rpc.js"
|
|
5
|
+
import { optional } from "./schema.js"
|
|
6
|
+
|
|
7
|
+
export const Status = Schema.Literals(["active", "paused", "complete"])
|
|
8
|
+
export type Status = typeof Status.Type
|
|
9
|
+
|
|
10
|
+
export interface State extends Schema.Schema.Type<typeof State> {}
|
|
11
|
+
export const State = Schema.Struct({
|
|
12
|
+
id: Schema.String,
|
|
13
|
+
objective: Schema.String,
|
|
14
|
+
status: Status,
|
|
15
|
+
/** Why the goal last changed: the reviewer's reason, or what paused it. */
|
|
16
|
+
reason: optional(Schema.String),
|
|
17
|
+
/** Continuations sent since the goal was set or last resumed. */
|
|
18
|
+
rounds: Schema.Number,
|
|
19
|
+
/** A backstop for loops that stall detection misses. */
|
|
20
|
+
maxRounds: Schema.Number,
|
|
21
|
+
/** Rounds in a row without progress: no tool calls, or the same reason as the round before. */
|
|
22
|
+
stalls: optional(Schema.Number),
|
|
23
|
+
/** The server process that armed the goal. */
|
|
24
|
+
boot: Schema.String,
|
|
25
|
+
updatedAt: Schema.Number,
|
|
26
|
+
}).annotate({ identifier: "Goal.State" })
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The `/goal` plugin's RPC. Clients read a Session's goal with `get` and keep it current from `changed`, which the
|
|
30
|
+
* plugin publishes in the Session's Location on every write. A Session's goal is its own: children and forks start
|
|
31
|
+
* without one. The schemas are Standard Schemas too, so Promise clients can call it.
|
|
32
|
+
*/
|
|
33
|
+
export const Definition = Rpc.define({
|
|
34
|
+
id: "opencode.goal",
|
|
35
|
+
methods: {
|
|
36
|
+
get: {
|
|
37
|
+
input: Schema.toStandardSchemaV1(Schema.Struct({ sessionID: Schema.String })),
|
|
38
|
+
output: Schema.toStandardSchemaV1(Schema.NullOr(State)),
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
events: {
|
|
42
|
+
changed: {
|
|
43
|
+
schema: Schema.toStandardSchemaV1(Schema.Struct({ sessionID: Schema.String, goal: Schema.NullOr(State) })),
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export * as Identifier from "./identifier.js"
|
|
2
|
+
|
|
3
|
+
const length = 26
|
|
4
|
+
const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
|
5
|
+
let lastTimestamp = 0
|
|
6
|
+
let counter = 0
|
|
7
|
+
|
|
8
|
+
export function ascending() {
|
|
9
|
+
return create(false)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function descending() {
|
|
13
|
+
return create(true)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function create(descending: boolean, timestamp = Date.now()) {
|
|
17
|
+
if (timestamp !== lastTimestamp) {
|
|
18
|
+
lastTimestamp = timestamp
|
|
19
|
+
counter = 0
|
|
20
|
+
}
|
|
21
|
+
counter++
|
|
22
|
+
|
|
23
|
+
const current = BigInt(timestamp) * 0x1000n + BigInt(counter)
|
|
24
|
+
const value = descending ? ~current : current
|
|
25
|
+
const time = Array.from({ length: 6 }, (_, index) =>
|
|
26
|
+
Number((value >> BigInt(40 - 8 * index)) & 0xffn)
|
|
27
|
+
.toString(16)
|
|
28
|
+
.padStart(2, "0"),
|
|
29
|
+
).join("")
|
|
30
|
+
const bytes = crypto.getRandomValues(new Uint8Array(length - 12))
|
|
31
|
+
return time + Array.from(bytes, (byte) => chars[byte % 62]).join("")
|
|
32
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export { Agent } from "./agent.js"
|
|
2
|
+
export { Artifact } from "./artifact.js"
|
|
3
|
+
export { Command } from "./command.js"
|
|
4
|
+
export { Config } from "./config.js"
|
|
5
|
+
export { Connection } from "./connection.js"
|
|
6
|
+
export { Credential } from "./credential.js"
|
|
7
|
+
export { Event } from "./event.js"
|
|
8
|
+
export { FileSystem } from "./filesystem.js"
|
|
9
|
+
export { Form } from "./form.js"
|
|
10
|
+
export { Integration } from "./integration.js"
|
|
11
|
+
export { LLM } from "./llm.js"
|
|
12
|
+
export { Location } from "./location.js"
|
|
13
|
+
export { Mcp } from "./mcp.js"
|
|
14
|
+
export { Model } from "./model.js"
|
|
15
|
+
export { Money } from "./money.js"
|
|
16
|
+
export { Permission } from "./permission.js"
|
|
17
|
+
export { PermissionSaved } from "./permission-saved.js"
|
|
18
|
+
export { Project } from "./project.js"
|
|
19
|
+
export { Worktree } from "./worktree.js"
|
|
20
|
+
export { Provider } from "./provider.js"
|
|
21
|
+
export { Reference } from "./reference.js"
|
|
22
|
+
export { Rpc } from "./rpc.js"
|
|
23
|
+
export { WebSearch } from "./websearch.js"
|
|
24
|
+
export { Session } from "./session.js"
|
|
25
|
+
export { Vcs } from "./vcs.js"
|
|
26
|
+
export { SessionInbox } from "./session-inbox.js"
|
|
27
|
+
export { SessionError } from "./session-error.js"
|
|
28
|
+
export { SessionMessage } from "./session-message.js"
|
|
29
|
+
export { SessionStats } from "./session-stats.js"
|
|
30
|
+
export { SessionTransfer } from "./session-transfer.js"
|
|
31
|
+
export { Snapshot } from "./snapshot.js"
|
|
32
|
+
export { Shell } from "./shell.js"
|
|
33
|
+
export { Skill } from "./skill.js"
|
|
34
|
+
export { TokenUsage } from "./token-usage.js"
|
|
35
|
+
export { Pty } from "./pty.js"
|
|
36
|
+
export { PersistentPty } from "./persistent-pty.js"
|
|
37
|
+
export { PtyTicket } from "./pty-ticket.js"
|
|
38
|
+
export { Question } from "./question.js"
|
|
39
|
+
export { Workspace } from "./workspace.js"
|
|
40
|
+
export {
|
|
41
|
+
Prompt,
|
|
42
|
+
PromptMention,
|
|
43
|
+
FileSource,
|
|
44
|
+
FileAttachment,
|
|
45
|
+
MediaRef,
|
|
46
|
+
MediaFileAttachment,
|
|
47
|
+
Attachment,
|
|
48
|
+
AgentAttachment,
|
|
49
|
+
} from "./prompt.js"
|
|
50
|
+
export { PromptInput } from "./prompt-input.js"
|
|
51
|
+
export * from "./schema.js"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * as InstallationEvent from "./installation-event.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { Event } from "./event.js"
|
|
5
|
+
|
|
6
|
+
export const Updated = Event.ephemeral({
|
|
7
|
+
type: "installation.updated",
|
|
8
|
+
schema: {
|
|
9
|
+
version: Schema.String,
|
|
10
|
+
},
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export const UpdateAvailable = Event.ephemeral({
|
|
14
|
+
type: "installation.update-available",
|
|
15
|
+
schema: {
|
|
16
|
+
version: Schema.String,
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export const Definitions = Event.inventory(Updated, UpdateAvailable)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export * as InstructionEntry from "./instruction-entry.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Slash-free client-facing key for one API-managed instruction entry. The server
|
|
7
|
+
* derives the namespaced Instructions key as `api/<key>`, keeping the
|
|
8
|
+
* `api/*` namespace enforced by construction.
|
|
9
|
+
*/
|
|
10
|
+
export const Key = Schema.String.check(Schema.isPattern(/^[a-z0-9][a-z0-9._-]*$/u)).annotate({
|
|
11
|
+
identifier: "InstructionEntry.Key",
|
|
12
|
+
description: "Instruction entry key (lowercase alphanumerics plus . _ -)",
|
|
13
|
+
})
|
|
14
|
+
export type Key = typeof Key.Type
|
|
15
|
+
|
|
16
|
+
export const Info = Schema.Struct({
|
|
17
|
+
key: Key,
|
|
18
|
+
value: Schema.Json.annotate({ description: "JSON value attached to the session's instructions" }),
|
|
19
|
+
}).annotate({ identifier: "InstructionEntry.Info" })
|
|
20
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
21
|
+
|
|
22
|
+
export const Snapshot = Schema.Array(
|
|
23
|
+
Schema.Struct({
|
|
24
|
+
...Info.fields,
|
|
25
|
+
removed: Schema.Boolean,
|
|
26
|
+
}),
|
|
27
|
+
).annotate({ identifier: "InstructionEntry.Snapshot" })
|
|
28
|
+
export type Snapshot = typeof Snapshot.Type
|
|
29
|
+
|
|
30
|
+
export const MaxValueBytes = 256 * 1024
|
|
31
|
+
|
|
32
|
+
export class ValueTooLargeError extends Schema.TaggedError<ValueTooLargeError>()(
|
|
33
|
+
"InstructionEntryValueTooLargeError",
|
|
34
|
+
{
|
|
35
|
+
actualBytes: Schema.Int,
|
|
36
|
+
maxBytes: Schema.Int,
|
|
37
|
+
message: Schema.String,
|
|
38
|
+
},
|
|
39
|
+
{ httpApiStatus: 413 },
|
|
40
|
+
) {}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * as Instruction from "./instruction.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
|
|
5
|
+
export const Key = Schema.String.check(Schema.isPattern(/^[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._/-]*$/u)).pipe(
|
|
6
|
+
Schema.brand("Instruction.Key"),
|
|
7
|
+
Schema.annotate({ identifier: "Instruction.Key" }),
|
|
8
|
+
)
|
|
9
|
+
export type Key = typeof Key.Type
|
|
10
|
+
|
|
11
|
+
export const Hash = Schema.String.check(Schema.isPattern(/^[a-f0-9]{64}$/u)).pipe(
|
|
12
|
+
Schema.brand("Instruction.Hash"),
|
|
13
|
+
Schema.annotate({ identifier: "Instruction.Hash" }),
|
|
14
|
+
)
|
|
15
|
+
export type Hash = typeof Hash.Type
|
|
16
|
+
|
|
17
|
+
export const Values = Schema.Record(Key, Hash)
|
|
18
|
+
export type Values = Readonly<Record<string, Hash>>
|
|
19
|
+
|
|
20
|
+
export const Removed = Schema.Literal("removed")
|
|
21
|
+
export type Removed = typeof Removed.Type
|
|
22
|
+
export const removed = Removed.make("removed")
|
|
23
|
+
|
|
24
|
+
export const Delta = Schema.Record(Schema.String, Schema.Union([Hash, Removed]))
|
|
25
|
+
export type Delta = typeof Delta.Type
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
|
|
3
|
+
export const IntegrationID = Schema.String.pipe(
|
|
4
|
+
Schema.brand("Integration.ID"),
|
|
5
|
+
Schema.annotate({ identifier: "Integration.ID" }),
|
|
6
|
+
)
|
|
7
|
+
export type IntegrationID = typeof IntegrationID.Type
|
|
8
|
+
|
|
9
|
+
export const IntegrationMethodID = Schema.String.pipe(
|
|
10
|
+
Schema.brand("Integration.MethodID"),
|
|
11
|
+
Schema.annotate({ identifier: "Integration.MethodID" }),
|
|
12
|
+
)
|
|
13
|
+
export type IntegrationMethodID = typeof IntegrationMethodID.Type
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
export * as Integration from "./integration.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { optional } from "./schema.js"
|
|
5
|
+
import { ephemeral, inventory } from "./event.js"
|
|
6
|
+
import { Connection } from "./connection.js"
|
|
7
|
+
import { ascending } from "./identifier.js"
|
|
8
|
+
import { statics } from "./schema.js"
|
|
9
|
+
import { IntegrationID, IntegrationMethodID } from "./integration-id.js"
|
|
10
|
+
import { Form } from "./form.js"
|
|
11
|
+
|
|
12
|
+
export const ID = IntegrationID
|
|
13
|
+
export type ID = typeof ID.Type
|
|
14
|
+
|
|
15
|
+
export const MethodID = IntegrationMethodID
|
|
16
|
+
export type MethodID = typeof MethodID.Type
|
|
17
|
+
|
|
18
|
+
export interface OAuthMethod extends Schema.Schema.Type<typeof OAuthMethod> {}
|
|
19
|
+
export const OAuthMethod = Schema.Struct({
|
|
20
|
+
id: MethodID,
|
|
21
|
+
type: Schema.Literal("oauth"),
|
|
22
|
+
label: Schema.String,
|
|
23
|
+
form: optional(Form.Fields),
|
|
24
|
+
}).annotate({ identifier: "Integration.OAuthMethod" })
|
|
25
|
+
|
|
26
|
+
export interface CommandMethod extends Schema.Schema.Type<typeof CommandMethod> {}
|
|
27
|
+
export const CommandMethod = Schema.Struct({
|
|
28
|
+
id: MethodID,
|
|
29
|
+
type: Schema.Literal("command"),
|
|
30
|
+
label: Schema.String,
|
|
31
|
+
command: Schema.Array(Schema.String),
|
|
32
|
+
}).annotate({ identifier: "Integration.CommandMethod" })
|
|
33
|
+
|
|
34
|
+
export interface KeyMethod extends Schema.Schema.Type<typeof KeyMethod> {}
|
|
35
|
+
export const KeyMethod = Schema.Struct({
|
|
36
|
+
type: Schema.Literal("key"),
|
|
37
|
+
label: optional(Schema.String),
|
|
38
|
+
form: optional(Form.Fields),
|
|
39
|
+
}).annotate({ identifier: "Integration.KeyMethod" })
|
|
40
|
+
|
|
41
|
+
/** Saves a reference to credentials managed outside opencode, configured by the form answers. */
|
|
42
|
+
export interface ExternalMethod extends Schema.Schema.Type<typeof ExternalMethod> {}
|
|
43
|
+
export const ExternalMethod = Schema.Struct({
|
|
44
|
+
id: MethodID,
|
|
45
|
+
type: Schema.Literal("external"),
|
|
46
|
+
label: Schema.String,
|
|
47
|
+
form: optional(Form.Fields),
|
|
48
|
+
}).annotate({ identifier: "Integration.ExternalMethod" })
|
|
49
|
+
|
|
50
|
+
export interface EnvMethod extends Schema.Schema.Type<typeof EnvMethod> {}
|
|
51
|
+
export const EnvMethod = Schema.Struct({
|
|
52
|
+
type: Schema.Literal("env"),
|
|
53
|
+
names: Schema.Array(Schema.String),
|
|
54
|
+
}).annotate({ identifier: "Integration.EnvMethod" })
|
|
55
|
+
|
|
56
|
+
export const Method = Schema.Union([OAuthMethod, CommandMethod, KeyMethod, ExternalMethod, EnvMethod])
|
|
57
|
+
.pipe(Schema.toTaggedUnion("type"))
|
|
58
|
+
.annotate({ identifier: "Integration.Method" })
|
|
59
|
+
export type Method = typeof Method.Type
|
|
60
|
+
|
|
61
|
+
const Updated = ephemeral({
|
|
62
|
+
type: "integration.updated",
|
|
63
|
+
schema: {},
|
|
64
|
+
})
|
|
65
|
+
export const Event = { Updated, Definitions: inventory(Updated) }
|
|
66
|
+
|
|
67
|
+
export interface Ref extends Schema.Schema.Type<typeof Ref> {}
|
|
68
|
+
export const Ref = Schema.Struct({
|
|
69
|
+
id: ID,
|
|
70
|
+
name: Schema.String,
|
|
71
|
+
metadata: optional(Schema.Record(Schema.String, Schema.Any)),
|
|
72
|
+
}).annotate({ identifier: "Integration.Ref" })
|
|
73
|
+
|
|
74
|
+
export const Info = Schema.Struct({
|
|
75
|
+
id: ID,
|
|
76
|
+
name: Schema.String,
|
|
77
|
+
metadata: optional(Schema.Record(Schema.String, Schema.Any)),
|
|
78
|
+
methods: Schema.Array(Method),
|
|
79
|
+
connections: Schema.Array(Connection.Info),
|
|
80
|
+
}).annotate({ identifier: "Integration.Info" })
|
|
81
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
82
|
+
|
|
83
|
+
export const AttemptID = Schema.String.pipe(
|
|
84
|
+
Schema.brand("Integration.AttemptID"),
|
|
85
|
+
Schema.annotate({ identifier: "Integration.AttemptID" }),
|
|
86
|
+
statics((schema) => ({ create: () => schema.make("con_" + ascending()) })),
|
|
87
|
+
)
|
|
88
|
+
export type AttemptID = typeof AttemptID.Type
|
|
89
|
+
|
|
90
|
+
const AttemptTime = Schema.Struct({
|
|
91
|
+
created: Schema.Number,
|
|
92
|
+
expires: Schema.Number,
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
export class Attempt extends Schema.Class<Attempt>("Integration.Attempt")({
|
|
96
|
+
attemptID: AttemptID,
|
|
97
|
+
url: Schema.String,
|
|
98
|
+
instructions: Schema.String,
|
|
99
|
+
mode: Schema.Literals(["auto", "code"]),
|
|
100
|
+
/** An `auto` attempt also accepts the redirect URL pasted from the browser as its `code`. */
|
|
101
|
+
paste: Schema.optionalKey(Schema.Literal(true)),
|
|
102
|
+
time: AttemptTime,
|
|
103
|
+
}) {}
|
|
104
|
+
|
|
105
|
+
export const AttemptStatus = Schema.Union([
|
|
106
|
+
Schema.Struct({ status: Schema.Literal("pending"), time: AttemptTime }),
|
|
107
|
+
Schema.Struct({ status: Schema.Literal("complete"), time: AttemptTime }),
|
|
108
|
+
Schema.Struct({ status: Schema.Literal("failed"), message: Schema.String, time: AttemptTime }),
|
|
109
|
+
Schema.Struct({ status: Schema.Literal("expired"), time: AttemptTime }),
|
|
110
|
+
])
|
|
111
|
+
.pipe(Schema.toTaggedUnion("status"))
|
|
112
|
+
.annotate({ identifier: "Integration.AttemptStatus" })
|
|
113
|
+
export type AttemptStatus = typeof AttemptStatus.Type
|
|
114
|
+
|
|
115
|
+
export interface CommandAttempt extends Schema.Schema.Type<typeof CommandAttempt> {}
|
|
116
|
+
export const CommandAttempt = Schema.Struct({
|
|
117
|
+
attemptID: AttemptID,
|
|
118
|
+
time: AttemptTime,
|
|
119
|
+
}).annotate({ identifier: "Integration.CommandAttempt" })
|
|
120
|
+
|
|
121
|
+
export const CommandAttemptStatus = Schema.Union([
|
|
122
|
+
Schema.Struct({ status: Schema.Literal("pending"), message: optional(Schema.String), time: AttemptTime }),
|
|
123
|
+
Schema.Struct({ status: Schema.Literal("complete"), time: AttemptTime }),
|
|
124
|
+
Schema.Struct({ status: Schema.Literal("failed"), message: Schema.String, time: AttemptTime }),
|
|
125
|
+
Schema.Struct({ status: Schema.Literal("expired"), time: AttemptTime }),
|
|
126
|
+
])
|
|
127
|
+
.pipe(Schema.toTaggedUnion("status"))
|
|
128
|
+
.annotate({ identifier: "Integration.CommandAttemptStatus" })
|
|
129
|
+
export type CommandAttemptStatus = typeof CommandAttemptStatus.Type
|