@zyro-sec/schema 1.0.1 → 1.0.3
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 -95
- package/package.json +5 -1
- package/script/build.ts +9 -9
- package/script/config-schema.ts +86 -86
- package/script/config-v1.json +1311 -1311
- package/script/pack.ts +5 -5
- package/src/agent.ts +68 -68
- package/src/artifact.ts +81 -81
- package/src/automation.ts +224 -224
- package/src/blob-store.ts +25 -25
- package/src/command.ts +18 -18
- package/src/config/agent.ts +26 -26
- package/src/config/command.ts +14 -14
- package/src/config/compaction.ts +27 -27
- package/src/config/experimental.ts +72 -72
- package/src/config/flag.ts +39 -39
- package/src/config/formatter.ts +13 -13
- package/src/config/lsp.ts +19 -19
- package/src/config/mcp.ts +22 -22
- package/src/config/media.ts +15 -15
- package/src/config/model.ts +37 -37
- package/src/config/plugin.ts +14 -14
- package/src/config/policy.ts +57 -57
- package/src/config/provider.ts +122 -122
- package/src/config/reference.ts +23 -23
- package/src/config/shell.ts +10 -10
- package/src/config/tool-output.ts +9 -9
- package/src/config/warming.ts +21 -21
- package/src/config/watcher.ts +8 -8
- package/src/config/websearch.ts +17 -17
- package/src/config/worktree.ts +10 -10
- package/src/config.ts +149 -149
- package/src/connection.ts +38 -38
- package/src/credential-legacy.ts +29 -29
- package/src/credential.ts +78 -78
- package/src/durable-event-manifest.ts +7 -7
- package/src/event-log.ts +21 -21
- package/src/event-manifest.ts +108 -108
- package/src/event.ts +205 -205
- package/src/file-diff.ts +25 -25
- package/src/filesystem-v1.ts +1 -1
- package/src/filesystem.ts +48 -48
- package/src/form.ts +177 -177
- package/src/generate.ts +292 -292
- package/src/goal.ts +46 -46
- package/src/identifier.ts +32 -32
- package/src/index.ts +51 -51
- package/src/installation-event.ts +20 -20
- package/src/instruction-entry.ts +40 -40
- package/src/instruction.ts +25 -25
- package/src/integration-id.ts +13 -13
- package/src/integration.ts +129 -129
- package/src/job.ts +79 -79
- package/src/legacy-event.ts +1 -1
- package/src/llm.ts +6 -6
- package/src/location-event.ts +8 -8
- package/src/location.ts +36 -36
- package/src/lsp-event.ts +7 -7
- package/src/mcp-event.ts +63 -63
- package/src/mcp.ts +171 -171
- package/src/model-compatibility.ts +55 -55
- package/src/model.ts +176 -176
- package/src/models-dev.ts +9 -9
- package/src/money.ts +18 -18
- package/src/permission-saved.ts +25 -25
- package/src/permission-v1.ts +1 -1
- package/src/permission.ts +67 -67
- package/src/persistent-pty.ts +73 -73
- package/src/plugin.ts +62 -62
- package/src/project-id.ts +9 -9
- package/src/project.ts +62 -62
- package/src/prompt-input.ts +33 -33
- package/src/prompt.ts +117 -117
- package/src/provider.ts +136 -136
- package/src/pty-ticket.ts +10 -10
- package/src/pty.ts +61 -61
- package/src/push.ts +86 -86
- package/src/question.ts +22 -22
- package/src/reference.ts +40 -40
- package/src/rpc.ts +167 -167
- package/src/schema.ts +41 -41
- package/src/server-event.ts +8 -8
- package/src/session-error.ts +14 -14
- package/src/session-event.ts +739 -739
- package/src/session-fork.ts +10 -10
- package/src/session-id.ts +12 -12
- package/src/session-inbox.ts +102 -102
- package/src/session-legacy.ts +117 -117
- package/src/session-message.ts +352 -352
- package/src/session-metadata.ts +11 -11
- package/src/session-revert.ts +86 -86
- package/src/session-stats.ts +68 -68
- package/src/session-status-event.ts +53 -53
- package/src/session-transfer.ts +11 -11
- package/src/session-v1.ts +1 -1
- package/src/session.ts +147 -147
- package/src/shell.ts +90 -90
- package/src/skill.ts +68 -68
- package/src/snapshot.ts +6 -6
- package/src/token-usage.ts +18 -18
- package/src/tool.ts +143 -143
- package/src/tui-event.ts +59 -59
- package/src/usage-limits.ts +76 -76
- package/src/v1/filesystem.ts +11 -11
- package/src/v1/legacy-event.ts +18 -18
- package/src/v1/permission.ts +66 -66
- package/src/v1/session.ts +667 -667
- package/src/vcs-event.ts +14 -14
- package/src/vcs.ts +41 -41
- package/src/websearch.ts +44 -44
- package/src/workspace-event.ts +32 -32
- package/src/workspace-id.ts +19 -19
- package/src/workspace.ts +20 -20
- package/src/worktree-event.ts +22 -22
- package/src/worktree.ts +109 -109
- package/tsconfig.build.json +11 -11
- package/tsconfig.json +14 -14
- package/test/agent.test.ts +0 -10
- package/test/automation.test.ts +0 -48
- package/test/compatibility.test.ts +0 -10
- package/test/config.test.ts +0 -194
- package/test/contract-hygiene.test.ts +0 -352
- package/test/credential-legacy.test.ts +0 -55
- package/test/event-manifest.test.ts +0 -228
- package/test/event.test.ts +0 -52
- package/test/legacy-event.test.ts +0 -46
- package/test/mcp.test.ts +0 -37
- package/test/model.test.ts +0 -104
- package/test/session-cursor.test.ts +0 -16
- package/test/session-error.test.ts +0 -51
- package/test/session-legacy.test.ts +0 -178
- package/test/session-terminal.test.ts +0 -50
- package/test/token-usage.test.ts +0 -18
- package/test/v1-isolation.test.ts +0 -26
- package/test/vcs.test.ts +0 -23
- package/test/worktree.test.ts +0 -45
package/src/file-diff.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
export * as FileDiff from "./file-diff.js"
|
|
2
|
-
|
|
3
|
-
import { Schema } from "effect"
|
|
4
|
-
import { NonNegativeInt, optional } from "./schema.js"
|
|
5
|
-
|
|
6
|
-
export const Info = Schema.Struct({
|
|
7
|
-
file: Schema.String,
|
|
8
|
-
patch: Schema.String,
|
|
9
|
-
additions: NonNegativeInt,
|
|
10
|
-
deletions: NonNegativeInt,
|
|
11
|
-
status: Schema.Literals(["added", "deleted", "modified"]),
|
|
12
|
-
/** Marks the entry a folder listing adds for itself when it stopped before showing or checking every entry. */
|
|
13
|
-
more: Schema.Literal(true).pipe(optional),
|
|
14
|
-
}).annotate({ identifier: "FileDiff.Info" })
|
|
15
|
-
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
16
|
-
|
|
17
|
-
/** V1 snapshot and persisted session diff shape. */
|
|
18
|
-
export const LegacyInfo = Schema.Struct({
|
|
19
|
-
file: Schema.String.pipe(optional),
|
|
20
|
-
patch: Schema.String.pipe(optional),
|
|
21
|
-
additions: Schema.Finite,
|
|
22
|
-
deletions: Schema.Finite,
|
|
23
|
-
status: Schema.Literals(["added", "deleted", "modified"]).pipe(optional),
|
|
24
|
-
}).annotate({ identifier: "FileDiff.LegacyInfo" })
|
|
25
|
-
export interface LegacyInfo extends Schema.Schema.Type<typeof LegacyInfo> {}
|
|
1
|
+
export * as FileDiff from "./file-diff.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { NonNegativeInt, optional } from "./schema.js"
|
|
5
|
+
|
|
6
|
+
export const Info = Schema.Struct({
|
|
7
|
+
file: Schema.String,
|
|
8
|
+
patch: Schema.String,
|
|
9
|
+
additions: NonNegativeInt,
|
|
10
|
+
deletions: NonNegativeInt,
|
|
11
|
+
status: Schema.Literals(["added", "deleted", "modified"]),
|
|
12
|
+
/** Marks the entry a folder listing adds for itself when it stopped before showing or checking every entry. */
|
|
13
|
+
more: Schema.Literal(true).pipe(optional),
|
|
14
|
+
}).annotate({ identifier: "FileDiff.Info" })
|
|
15
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
16
|
+
|
|
17
|
+
/** V1 snapshot and persisted session diff shape. */
|
|
18
|
+
export const LegacyInfo = Schema.Struct({
|
|
19
|
+
file: Schema.String.pipe(optional),
|
|
20
|
+
patch: Schema.String.pipe(optional),
|
|
21
|
+
additions: Schema.Finite,
|
|
22
|
+
deletions: Schema.Finite,
|
|
23
|
+
status: Schema.Literals(["added", "deleted", "modified"]).pipe(optional),
|
|
24
|
+
}).annotate({ identifier: "FileDiff.LegacyInfo" })
|
|
25
|
+
export interface LegacyInfo extends Schema.Schema.Type<typeof LegacyInfo> {}
|
package/src/filesystem-v1.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./v1/filesystem.js"
|
|
1
|
+
export * from "./v1/filesystem.js"
|
package/src/filesystem.ts
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
export * as FileSystem from "./filesystem.js"
|
|
2
|
-
|
|
3
|
-
import { Schema } from "effect"
|
|
4
|
-
import { optional } from "./schema.js"
|
|
5
|
-
import { ephemeral, inventory } from "./event.js"
|
|
6
|
-
import { AbsolutePath, NonNegativeInt, PositiveInt, RelativePath } from "./schema.js"
|
|
7
|
-
|
|
8
|
-
const Changed = ephemeral({
|
|
9
|
-
type: "filesystem.changed",
|
|
10
|
-
schema: {
|
|
11
|
-
file: Schema.String,
|
|
12
|
-
event: Schema.Literals(["add", "change", "unlink"]),
|
|
13
|
-
},
|
|
14
|
-
})
|
|
15
|
-
export const Event = { Changed, Definitions: inventory(Changed) }
|
|
16
|
-
|
|
17
|
-
export interface Entry extends Schema.Schema.Type<typeof Entry> {}
|
|
18
|
-
export const Entry = Schema.Struct({
|
|
19
|
-
path: RelativePath,
|
|
20
|
-
type: Schema.Literals(["file", "directory"]),
|
|
21
|
-
}).annotate({ identifier: "FileSystem.Entry" })
|
|
22
|
-
|
|
23
|
-
export interface Submatch extends Schema.Schema.Type<typeof Submatch> {}
|
|
24
|
-
export const Submatch = Schema.Struct({
|
|
25
|
-
text: Schema.String,
|
|
26
|
-
start: NonNegativeInt,
|
|
27
|
-
end: NonNegativeInt,
|
|
28
|
-
}).annotate({ identifier: "FileSystem.Submatch" })
|
|
29
|
-
|
|
30
|
-
export interface Match extends Schema.Schema.Type<typeof Match> {}
|
|
31
|
-
export const Match = Schema.Struct({
|
|
32
|
-
entry: Entry,
|
|
33
|
-
line: PositiveInt,
|
|
34
|
-
offset: NonNegativeInt,
|
|
35
|
-
text: Schema.String,
|
|
36
|
-
submatches: Schema.Array(Submatch),
|
|
37
|
-
}).annotate({ identifier: "FileSystem.Match" })
|
|
38
|
-
|
|
39
|
-
export class FindInput extends Schema.Class<FindInput>("FileSystem.FindInput")({
|
|
40
|
-
query: Schema.String,
|
|
41
|
-
type: Schema.Literals(["file", "directory"]).pipe(optional),
|
|
42
|
-
limit: PositiveInt.pipe(optional),
|
|
43
|
-
}) {}
|
|
44
|
-
|
|
45
|
-
export interface Write extends Schema.Schema.Type<typeof Write> {}
|
|
46
|
-
export const Write = Schema.Struct({
|
|
47
|
-
path: AbsolutePath,
|
|
48
|
-
}).annotate({ identifier: "FileSystem.Write" })
|
|
1
|
+
export * as FileSystem from "./filesystem.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { optional } from "./schema.js"
|
|
5
|
+
import { ephemeral, inventory } from "./event.js"
|
|
6
|
+
import { AbsolutePath, NonNegativeInt, PositiveInt, RelativePath } from "./schema.js"
|
|
7
|
+
|
|
8
|
+
const Changed = ephemeral({
|
|
9
|
+
type: "filesystem.changed",
|
|
10
|
+
schema: {
|
|
11
|
+
file: Schema.String,
|
|
12
|
+
event: Schema.Literals(["add", "change", "unlink"]),
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
export const Event = { Changed, Definitions: inventory(Changed) }
|
|
16
|
+
|
|
17
|
+
export interface Entry extends Schema.Schema.Type<typeof Entry> {}
|
|
18
|
+
export const Entry = Schema.Struct({
|
|
19
|
+
path: RelativePath,
|
|
20
|
+
type: Schema.Literals(["file", "directory"]),
|
|
21
|
+
}).annotate({ identifier: "FileSystem.Entry" })
|
|
22
|
+
|
|
23
|
+
export interface Submatch extends Schema.Schema.Type<typeof Submatch> {}
|
|
24
|
+
export const Submatch = Schema.Struct({
|
|
25
|
+
text: Schema.String,
|
|
26
|
+
start: NonNegativeInt,
|
|
27
|
+
end: NonNegativeInt,
|
|
28
|
+
}).annotate({ identifier: "FileSystem.Submatch" })
|
|
29
|
+
|
|
30
|
+
export interface Match extends Schema.Schema.Type<typeof Match> {}
|
|
31
|
+
export const Match = Schema.Struct({
|
|
32
|
+
entry: Entry,
|
|
33
|
+
line: PositiveInt,
|
|
34
|
+
offset: NonNegativeInt,
|
|
35
|
+
text: Schema.String,
|
|
36
|
+
submatches: Schema.Array(Submatch),
|
|
37
|
+
}).annotate({ identifier: "FileSystem.Match" })
|
|
38
|
+
|
|
39
|
+
export class FindInput extends Schema.Class<FindInput>("FileSystem.FindInput")({
|
|
40
|
+
query: Schema.String,
|
|
41
|
+
type: Schema.Literals(["file", "directory"]).pipe(optional),
|
|
42
|
+
limit: PositiveInt.pipe(optional),
|
|
43
|
+
}) {}
|
|
44
|
+
|
|
45
|
+
export interface Write extends Schema.Schema.Type<typeof Write> {}
|
|
46
|
+
export const Write = Schema.Struct({
|
|
47
|
+
path: AbsolutePath,
|
|
48
|
+
}).annotate({ identifier: "FileSystem.Write" })
|
package/src/form.ts
CHANGED
|
@@ -1,177 +1,177 @@
|
|
|
1
|
-
export * as Form from "./form.js"
|
|
2
|
-
|
|
3
|
-
import { Schema } from "effect"
|
|
4
|
-
import { ephemeral, inventory } from "./event.js"
|
|
5
|
-
import { ascending } from "./identifier.js"
|
|
6
|
-
import { NonNegativeInt, optional, statics } from "./schema.js"
|
|
7
|
-
|
|
8
|
-
const IDSchema = Schema.String.check(Schema.isStartingWith("frm_")).pipe(
|
|
9
|
-
Schema.brand("Form.ID"),
|
|
10
|
-
Schema.annotate({ identifier: "Form.ID" }),
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
export const ID = IDSchema.pipe(
|
|
14
|
-
statics((schema: typeof IDSchema) => ({ create: (id?: string) => schema.make(id ?? "frm_" + ascending()) })),
|
|
15
|
-
)
|
|
16
|
-
export type ID = typeof ID.Type
|
|
17
|
-
|
|
18
|
-
export const Metadata = Schema.Record(Schema.String, Schema.Unknown).annotate({ identifier: "Form.Metadata" })
|
|
19
|
-
export type Metadata = typeof Metadata.Type
|
|
20
|
-
|
|
21
|
-
export const Option = Schema.Struct({
|
|
22
|
-
value: Schema.String,
|
|
23
|
-
label: Schema.String,
|
|
24
|
-
description: Schema.String.pipe(optional),
|
|
25
|
-
}).annotate({ identifier: "Form.Option" })
|
|
26
|
-
export interface Option extends Schema.Schema.Type<typeof Option> {}
|
|
27
|
-
|
|
28
|
-
// One visibility condition on a field. A field's `when` is a list of conditions that must all
|
|
29
|
-
// hold (AND) against the current answers for the field to be active. Semantics:
|
|
30
|
-
// - `value` must match the referenced field's type; against a multiselect answer, `eq` means
|
|
31
|
-
// "selection includes value" and `neq` means "selection does not include value".
|
|
32
|
-
// - An unanswered referenced field makes the condition false for both ops.
|
|
33
|
-
// - `key` must reference a field defined earlier in the form's field list.
|
|
34
|
-
// Inactive fields are neither required nor answerable.
|
|
35
|
-
export const When = Schema.Struct({
|
|
36
|
-
key: Schema.String,
|
|
37
|
-
op: Schema.Literals(["eq", "neq"]),
|
|
38
|
-
value: Schema.Union([Schema.String, Schema.Number, Schema.Boolean]),
|
|
39
|
-
}).annotate({ identifier: "Form.When" })
|
|
40
|
-
export interface When extends Schema.Schema.Type<typeof When> {}
|
|
41
|
-
|
|
42
|
-
const FieldBase = {
|
|
43
|
-
key: Schema.String,
|
|
44
|
-
title: Schema.String.pipe(optional),
|
|
45
|
-
description: Schema.String.pipe(optional),
|
|
46
|
-
required: Schema.Boolean.pipe(optional),
|
|
47
|
-
hidden: Schema.Boolean.pipe(optional).annotate({
|
|
48
|
-
description: "Skip the interactive authentication prompt and use the default unless an answer is supplied",
|
|
49
|
-
}),
|
|
50
|
-
when: Schema.Array(When).pipe(optional),
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const StringField = Schema.Struct({
|
|
54
|
-
...FieldBase,
|
|
55
|
-
type: Schema.Literal("string"),
|
|
56
|
-
format: Schema.Literals(["email", "uri", "date", "date-time"]).pipe(optional),
|
|
57
|
-
minLength: NonNegativeInt.pipe(optional),
|
|
58
|
-
maxLength: NonNegativeInt.pipe(optional),
|
|
59
|
-
pattern: Schema.String.pipe(optional),
|
|
60
|
-
placeholder: Schema.String.pipe(optional),
|
|
61
|
-
default: Schema.String.pipe(optional),
|
|
62
|
-
options: Schema.Array(Option).pipe(optional),
|
|
63
|
-
custom: Schema.Boolean.pipe(optional),
|
|
64
|
-
}).annotate({ identifier: "Form.StringField" })
|
|
65
|
-
export interface StringField extends Schema.Schema.Type<typeof StringField> {}
|
|
66
|
-
|
|
67
|
-
export const NumberField = Schema.Struct({
|
|
68
|
-
...FieldBase,
|
|
69
|
-
type: Schema.Literal("number"),
|
|
70
|
-
minimum: Schema.Number.pipe(optional),
|
|
71
|
-
maximum: Schema.Number.pipe(optional),
|
|
72
|
-
default: Schema.Number.pipe(optional),
|
|
73
|
-
}).annotate({ identifier: "Form.NumberField" })
|
|
74
|
-
export interface NumberField extends Schema.Schema.Type<typeof NumberField> {}
|
|
75
|
-
|
|
76
|
-
export const IntegerField = Schema.Struct({
|
|
77
|
-
...FieldBase,
|
|
78
|
-
type: Schema.Literal("integer"),
|
|
79
|
-
minimum: Schema.Number.pipe(optional),
|
|
80
|
-
maximum: Schema.Number.pipe(optional),
|
|
81
|
-
default: Schema.Number.pipe(optional),
|
|
82
|
-
}).annotate({ identifier: "Form.IntegerField" })
|
|
83
|
-
export interface IntegerField extends Schema.Schema.Type<typeof IntegerField> {}
|
|
84
|
-
|
|
85
|
-
export const BooleanField = Schema.Struct({
|
|
86
|
-
...FieldBase,
|
|
87
|
-
type: Schema.Literal("boolean"),
|
|
88
|
-
default: Schema.Boolean.pipe(optional),
|
|
89
|
-
}).annotate({ identifier: "Form.BooleanField" })
|
|
90
|
-
export interface BooleanField extends Schema.Schema.Type<typeof BooleanField> {}
|
|
91
|
-
|
|
92
|
-
export const MultiselectField = Schema.Struct({
|
|
93
|
-
...FieldBase,
|
|
94
|
-
type: Schema.Literal("multiselect"),
|
|
95
|
-
options: Schema.Array(Option),
|
|
96
|
-
minItems: NonNegativeInt.pipe(optional),
|
|
97
|
-
maxItems: NonNegativeInt.pipe(optional),
|
|
98
|
-
custom: Schema.Boolean.pipe(optional),
|
|
99
|
-
default: Schema.Array(Schema.String).pipe(optional),
|
|
100
|
-
}).annotate({ identifier: "Form.MultiselectField" })
|
|
101
|
-
export interface MultiselectField extends Schema.Schema.Type<typeof MultiselectField> {}
|
|
102
|
-
|
|
103
|
-
export const ExternalField = Schema.Struct({
|
|
104
|
-
key: Schema.String,
|
|
105
|
-
type: Schema.Literal("external"),
|
|
106
|
-
url: Schema.String,
|
|
107
|
-
title: Schema.String.pipe(optional),
|
|
108
|
-
description: Schema.String.pipe(optional),
|
|
109
|
-
}).annotate({ identifier: "Form.ExternalField" })
|
|
110
|
-
export interface ExternalField extends Schema.Schema.Type<typeof ExternalField> {}
|
|
111
|
-
|
|
112
|
-
export const Field = Schema.Union([
|
|
113
|
-
StringField,
|
|
114
|
-
NumberField,
|
|
115
|
-
IntegerField,
|
|
116
|
-
BooleanField,
|
|
117
|
-
MultiselectField,
|
|
118
|
-
ExternalField,
|
|
119
|
-
]).pipe(Schema.toTaggedUnion("type"), Schema.annotate({ identifier: "Form.Field" }))
|
|
120
|
-
export type Field = StringField | NumberField | IntegerField | BooleanField | MultiselectField | ExternalField
|
|
121
|
-
|
|
122
|
-
export const Fields = Schema.NonEmptyArray(Field).annotate({ identifier: "Form.Fields" })
|
|
123
|
-
export type Fields = typeof Fields.Type
|
|
124
|
-
|
|
125
|
-
const InfoBase = {
|
|
126
|
-
id: ID,
|
|
127
|
-
// This should be typed as SessionID. It is a plain string only because MCP elicitation
|
|
128
|
-
// temporarily needs the `"global"` sentinel owner, which is not a real session. Once
|
|
129
|
-
// elicitations can be attributed to real sessions, revert this to SessionID. Do not rely
|
|
130
|
-
// on non-session owners anywhere else.
|
|
131
|
-
sessionID: Schema.String,
|
|
132
|
-
title: Schema.String,
|
|
133
|
-
metadata: Metadata.pipe(optional),
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export const Info = Schema.Struct({
|
|
137
|
-
...InfoBase,
|
|
138
|
-
fields: Fields,
|
|
139
|
-
}).annotate({ identifier: "Form.Info" })
|
|
140
|
-
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
141
|
-
|
|
142
|
-
export const Value = Schema.Union([Schema.String, Schema.Number, Schema.Boolean, Schema.Array(Schema.String)]).annotate(
|
|
143
|
-
{
|
|
144
|
-
identifier: "Form.Value",
|
|
145
|
-
},
|
|
146
|
-
)
|
|
147
|
-
export type Value = typeof Value.Type
|
|
148
|
-
|
|
149
|
-
export const Answer = Schema.Record(Schema.String, Value).annotate({ identifier: "Form.Answer" })
|
|
150
|
-
export type Answer = typeof Answer.Type
|
|
151
|
-
|
|
152
|
-
export const State = Schema.Union([
|
|
153
|
-
Schema.Struct({ status: Schema.Literal("pending") }),
|
|
154
|
-
Schema.Struct({ status: Schema.Literal("answered"), answer: Answer }),
|
|
155
|
-
// A message tells the asker why nobody answered, e.g. a non-interactive client.
|
|
156
|
-
Schema.Struct({ status: Schema.Literal("cancelled"), message: Schema.String.pipe(optional) }),
|
|
157
|
-
])
|
|
158
|
-
.pipe(Schema.toTaggedUnion("status"))
|
|
159
|
-
.annotate({ identifier: "Form.State" })
|
|
160
|
-
export type State = typeof State.Type
|
|
161
|
-
|
|
162
|
-
export const Detail = Schema.Struct({
|
|
163
|
-
...Info.fields,
|
|
164
|
-
state: State,
|
|
165
|
-
}).annotate({ identifier: "Form.Detail" })
|
|
166
|
-
export interface Detail extends Schema.Schema.Type<typeof Detail> {}
|
|
167
|
-
|
|
168
|
-
export const Reply = Schema.Struct({
|
|
169
|
-
answer: Answer,
|
|
170
|
-
}).annotate({ identifier: "Form.Reply" })
|
|
171
|
-
export interface Reply extends Schema.Schema.Type<typeof Reply> {}
|
|
172
|
-
|
|
173
|
-
const Created = ephemeral({ type: "form.created", schema: { form: Info } })
|
|
174
|
-
const Replied = ephemeral({ type: "form.replied", schema: { id: ID, sessionID: Schema.String, answer: Answer } })
|
|
175
|
-
const Cancelled = ephemeral({ type: "form.cancelled", schema: { id: ID, sessionID: Schema.String } })
|
|
176
|
-
|
|
177
|
-
export const Event = { Created, Replied, Cancelled, Definitions: inventory(Created, Replied, Cancelled) }
|
|
1
|
+
export * as Form from "./form.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { ephemeral, inventory } from "./event.js"
|
|
5
|
+
import { ascending } from "./identifier.js"
|
|
6
|
+
import { NonNegativeInt, optional, statics } from "./schema.js"
|
|
7
|
+
|
|
8
|
+
const IDSchema = Schema.String.check(Schema.isStartingWith("frm_")).pipe(
|
|
9
|
+
Schema.brand("Form.ID"),
|
|
10
|
+
Schema.annotate({ identifier: "Form.ID" }),
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
export const ID = IDSchema.pipe(
|
|
14
|
+
statics((schema: typeof IDSchema) => ({ create: (id?: string) => schema.make(id ?? "frm_" + ascending()) })),
|
|
15
|
+
)
|
|
16
|
+
export type ID = typeof ID.Type
|
|
17
|
+
|
|
18
|
+
export const Metadata = Schema.Record(Schema.String, Schema.Unknown).annotate({ identifier: "Form.Metadata" })
|
|
19
|
+
export type Metadata = typeof Metadata.Type
|
|
20
|
+
|
|
21
|
+
export const Option = Schema.Struct({
|
|
22
|
+
value: Schema.String,
|
|
23
|
+
label: Schema.String,
|
|
24
|
+
description: Schema.String.pipe(optional),
|
|
25
|
+
}).annotate({ identifier: "Form.Option" })
|
|
26
|
+
export interface Option extends Schema.Schema.Type<typeof Option> {}
|
|
27
|
+
|
|
28
|
+
// One visibility condition on a field. A field's `when` is a list of conditions that must all
|
|
29
|
+
// hold (AND) against the current answers for the field to be active. Semantics:
|
|
30
|
+
// - `value` must match the referenced field's type; against a multiselect answer, `eq` means
|
|
31
|
+
// "selection includes value" and `neq` means "selection does not include value".
|
|
32
|
+
// - An unanswered referenced field makes the condition false for both ops.
|
|
33
|
+
// - `key` must reference a field defined earlier in the form's field list.
|
|
34
|
+
// Inactive fields are neither required nor answerable.
|
|
35
|
+
export const When = Schema.Struct({
|
|
36
|
+
key: Schema.String,
|
|
37
|
+
op: Schema.Literals(["eq", "neq"]),
|
|
38
|
+
value: Schema.Union([Schema.String, Schema.Number, Schema.Boolean]),
|
|
39
|
+
}).annotate({ identifier: "Form.When" })
|
|
40
|
+
export interface When extends Schema.Schema.Type<typeof When> {}
|
|
41
|
+
|
|
42
|
+
const FieldBase = {
|
|
43
|
+
key: Schema.String,
|
|
44
|
+
title: Schema.String.pipe(optional),
|
|
45
|
+
description: Schema.String.pipe(optional),
|
|
46
|
+
required: Schema.Boolean.pipe(optional),
|
|
47
|
+
hidden: Schema.Boolean.pipe(optional).annotate({
|
|
48
|
+
description: "Skip the interactive authentication prompt and use the default unless an answer is supplied",
|
|
49
|
+
}),
|
|
50
|
+
when: Schema.Array(When).pipe(optional),
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const StringField = Schema.Struct({
|
|
54
|
+
...FieldBase,
|
|
55
|
+
type: Schema.Literal("string"),
|
|
56
|
+
format: Schema.Literals(["email", "uri", "date", "date-time"]).pipe(optional),
|
|
57
|
+
minLength: NonNegativeInt.pipe(optional),
|
|
58
|
+
maxLength: NonNegativeInt.pipe(optional),
|
|
59
|
+
pattern: Schema.String.pipe(optional),
|
|
60
|
+
placeholder: Schema.String.pipe(optional),
|
|
61
|
+
default: Schema.String.pipe(optional),
|
|
62
|
+
options: Schema.Array(Option).pipe(optional),
|
|
63
|
+
custom: Schema.Boolean.pipe(optional),
|
|
64
|
+
}).annotate({ identifier: "Form.StringField" })
|
|
65
|
+
export interface StringField extends Schema.Schema.Type<typeof StringField> {}
|
|
66
|
+
|
|
67
|
+
export const NumberField = Schema.Struct({
|
|
68
|
+
...FieldBase,
|
|
69
|
+
type: Schema.Literal("number"),
|
|
70
|
+
minimum: Schema.Number.pipe(optional),
|
|
71
|
+
maximum: Schema.Number.pipe(optional),
|
|
72
|
+
default: Schema.Number.pipe(optional),
|
|
73
|
+
}).annotate({ identifier: "Form.NumberField" })
|
|
74
|
+
export interface NumberField extends Schema.Schema.Type<typeof NumberField> {}
|
|
75
|
+
|
|
76
|
+
export const IntegerField = Schema.Struct({
|
|
77
|
+
...FieldBase,
|
|
78
|
+
type: Schema.Literal("integer"),
|
|
79
|
+
minimum: Schema.Number.pipe(optional),
|
|
80
|
+
maximum: Schema.Number.pipe(optional),
|
|
81
|
+
default: Schema.Number.pipe(optional),
|
|
82
|
+
}).annotate({ identifier: "Form.IntegerField" })
|
|
83
|
+
export interface IntegerField extends Schema.Schema.Type<typeof IntegerField> {}
|
|
84
|
+
|
|
85
|
+
export const BooleanField = Schema.Struct({
|
|
86
|
+
...FieldBase,
|
|
87
|
+
type: Schema.Literal("boolean"),
|
|
88
|
+
default: Schema.Boolean.pipe(optional),
|
|
89
|
+
}).annotate({ identifier: "Form.BooleanField" })
|
|
90
|
+
export interface BooleanField extends Schema.Schema.Type<typeof BooleanField> {}
|
|
91
|
+
|
|
92
|
+
export const MultiselectField = Schema.Struct({
|
|
93
|
+
...FieldBase,
|
|
94
|
+
type: Schema.Literal("multiselect"),
|
|
95
|
+
options: Schema.Array(Option),
|
|
96
|
+
minItems: NonNegativeInt.pipe(optional),
|
|
97
|
+
maxItems: NonNegativeInt.pipe(optional),
|
|
98
|
+
custom: Schema.Boolean.pipe(optional),
|
|
99
|
+
default: Schema.Array(Schema.String).pipe(optional),
|
|
100
|
+
}).annotate({ identifier: "Form.MultiselectField" })
|
|
101
|
+
export interface MultiselectField extends Schema.Schema.Type<typeof MultiselectField> {}
|
|
102
|
+
|
|
103
|
+
export const ExternalField = Schema.Struct({
|
|
104
|
+
key: Schema.String,
|
|
105
|
+
type: Schema.Literal("external"),
|
|
106
|
+
url: Schema.String,
|
|
107
|
+
title: Schema.String.pipe(optional),
|
|
108
|
+
description: Schema.String.pipe(optional),
|
|
109
|
+
}).annotate({ identifier: "Form.ExternalField" })
|
|
110
|
+
export interface ExternalField extends Schema.Schema.Type<typeof ExternalField> {}
|
|
111
|
+
|
|
112
|
+
export const Field = Schema.Union([
|
|
113
|
+
StringField,
|
|
114
|
+
NumberField,
|
|
115
|
+
IntegerField,
|
|
116
|
+
BooleanField,
|
|
117
|
+
MultiselectField,
|
|
118
|
+
ExternalField,
|
|
119
|
+
]).pipe(Schema.toTaggedUnion("type"), Schema.annotate({ identifier: "Form.Field" }))
|
|
120
|
+
export type Field = StringField | NumberField | IntegerField | BooleanField | MultiselectField | ExternalField
|
|
121
|
+
|
|
122
|
+
export const Fields = Schema.NonEmptyArray(Field).annotate({ identifier: "Form.Fields" })
|
|
123
|
+
export type Fields = typeof Fields.Type
|
|
124
|
+
|
|
125
|
+
const InfoBase = {
|
|
126
|
+
id: ID,
|
|
127
|
+
// This should be typed as SessionID. It is a plain string only because MCP elicitation
|
|
128
|
+
// temporarily needs the `"global"` sentinel owner, which is not a real session. Once
|
|
129
|
+
// elicitations can be attributed to real sessions, revert this to SessionID. Do not rely
|
|
130
|
+
// on non-session owners anywhere else.
|
|
131
|
+
sessionID: Schema.String,
|
|
132
|
+
title: Schema.String,
|
|
133
|
+
metadata: Metadata.pipe(optional),
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export const Info = Schema.Struct({
|
|
137
|
+
...InfoBase,
|
|
138
|
+
fields: Fields,
|
|
139
|
+
}).annotate({ identifier: "Form.Info" })
|
|
140
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
141
|
+
|
|
142
|
+
export const Value = Schema.Union([Schema.String, Schema.Number, Schema.Boolean, Schema.Array(Schema.String)]).annotate(
|
|
143
|
+
{
|
|
144
|
+
identifier: "Form.Value",
|
|
145
|
+
},
|
|
146
|
+
)
|
|
147
|
+
export type Value = typeof Value.Type
|
|
148
|
+
|
|
149
|
+
export const Answer = Schema.Record(Schema.String, Value).annotate({ identifier: "Form.Answer" })
|
|
150
|
+
export type Answer = typeof Answer.Type
|
|
151
|
+
|
|
152
|
+
export const State = Schema.Union([
|
|
153
|
+
Schema.Struct({ status: Schema.Literal("pending") }),
|
|
154
|
+
Schema.Struct({ status: Schema.Literal("answered"), answer: Answer }),
|
|
155
|
+
// A message tells the asker why nobody answered, e.g. a non-interactive client.
|
|
156
|
+
Schema.Struct({ status: Schema.Literal("cancelled"), message: Schema.String.pipe(optional) }),
|
|
157
|
+
])
|
|
158
|
+
.pipe(Schema.toTaggedUnion("status"))
|
|
159
|
+
.annotate({ identifier: "Form.State" })
|
|
160
|
+
export type State = typeof State.Type
|
|
161
|
+
|
|
162
|
+
export const Detail = Schema.Struct({
|
|
163
|
+
...Info.fields,
|
|
164
|
+
state: State,
|
|
165
|
+
}).annotate({ identifier: "Form.Detail" })
|
|
166
|
+
export interface Detail extends Schema.Schema.Type<typeof Detail> {}
|
|
167
|
+
|
|
168
|
+
export const Reply = Schema.Struct({
|
|
169
|
+
answer: Answer,
|
|
170
|
+
}).annotate({ identifier: "Form.Reply" })
|
|
171
|
+
export interface Reply extends Schema.Schema.Type<typeof Reply> {}
|
|
172
|
+
|
|
173
|
+
const Created = ephemeral({ type: "form.created", schema: { form: Info } })
|
|
174
|
+
const Replied = ephemeral({ type: "form.replied", schema: { id: ID, sessionID: Schema.String, answer: Answer } })
|
|
175
|
+
const Cancelled = ephemeral({ type: "form.cancelled", schema: { id: ID, sessionID: Schema.String } })
|
|
176
|
+
|
|
177
|
+
export const Event = { Created, Replied, Cancelled, Definitions: inventory(Created, Replied, Cancelled) }
|