@zyro-sec/schema 1.0.0 → 1.0.1
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 -15
- 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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export * as Credential from "./credential.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { optional } from "./schema.js"
|
|
5
|
+
import { ephemeral, inventory } from "./event.js"
|
|
6
|
+
import { IntegrationID, IntegrationMethodID } from "./integration-id.js"
|
|
7
|
+
import { ascending } from "./identifier.js"
|
|
8
|
+
import { NonNegativeInt, statics } from "./schema.js"
|
|
9
|
+
|
|
10
|
+
export const ID = Schema.String.pipe(
|
|
11
|
+
Schema.brand("Credential.ID"),
|
|
12
|
+
Schema.annotate({ identifier: "Credential.ID" }),
|
|
13
|
+
statics((schema) => ({ create: () => schema.make("cred_" + ascending()) })),
|
|
14
|
+
)
|
|
15
|
+
export type ID = typeof ID.Type
|
|
16
|
+
|
|
17
|
+
// A login was added, renamed or removed. Every change is to exactly one credential.
|
|
18
|
+
const Updated = ephemeral({
|
|
19
|
+
type: "credential.updated",
|
|
20
|
+
schema: { integrationID: IntegrationID, credentialID: ID },
|
|
21
|
+
})
|
|
22
|
+
const Switched = ephemeral({
|
|
23
|
+
type: "credential.switched",
|
|
24
|
+
schema: { integrationID: IntegrationID, credentialID: Schema.NullOr(ID) },
|
|
25
|
+
})
|
|
26
|
+
export const Event = {
|
|
27
|
+
Updated,
|
|
28
|
+
Switched,
|
|
29
|
+
Definitions: inventory(Updated, Switched),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface OAuth extends Schema.Schema.Type<typeof OAuth> {}
|
|
33
|
+
export const OAuth = Schema.Struct({
|
|
34
|
+
type: Schema.Literal("oauth"),
|
|
35
|
+
methodID: IntegrationMethodID,
|
|
36
|
+
refresh: Schema.String,
|
|
37
|
+
access: Schema.String,
|
|
38
|
+
expires: NonNegativeInt,
|
|
39
|
+
metadata: optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
40
|
+
}).annotate({ identifier: "Credential.OAuth" })
|
|
41
|
+
|
|
42
|
+
export interface Key extends Schema.Schema.Type<typeof Key> {}
|
|
43
|
+
export const Key = Schema.Struct({
|
|
44
|
+
type: Schema.Literal("key"),
|
|
45
|
+
key: Schema.String,
|
|
46
|
+
metadata: optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
47
|
+
}).annotate({ identifier: "Credential.Key" })
|
|
48
|
+
|
|
49
|
+
/** References a credential source whose secrets and renewal are managed outside the credential store. */
|
|
50
|
+
export interface External extends Schema.Schema.Type<typeof External> {}
|
|
51
|
+
export const External = Schema.Struct({
|
|
52
|
+
type: Schema.Literal("external"),
|
|
53
|
+
methodID: IntegrationMethodID,
|
|
54
|
+
metadata: optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
55
|
+
}).annotate({ identifier: "Credential.External" })
|
|
56
|
+
|
|
57
|
+
export const Value = Schema.Union([OAuth, Key, External])
|
|
58
|
+
.pipe(Schema.toTaggedUnion("type"))
|
|
59
|
+
.annotate({ identifier: "Credential.Value" })
|
|
60
|
+
export type Value = Schema.Schema.Type<typeof Value>
|
|
61
|
+
|
|
62
|
+
export interface Entry extends Schema.Schema.Type<typeof Entry> {}
|
|
63
|
+
export const Entry = Schema.Struct({
|
|
64
|
+
id: ID,
|
|
65
|
+
integrationID: IntegrationID,
|
|
66
|
+
label: Schema.String,
|
|
67
|
+
active: Schema.Boolean,
|
|
68
|
+
value: Value,
|
|
69
|
+
}).annotate({ identifier: "Credential.Entry" })
|
|
70
|
+
|
|
71
|
+
export interface CreateInput extends Schema.Schema.Type<typeof CreateInput> {}
|
|
72
|
+
export const CreateInput = Schema.Struct({
|
|
73
|
+
id: optional(ID),
|
|
74
|
+
integrationID: IntegrationID,
|
|
75
|
+
label: optional(Schema.String),
|
|
76
|
+
value: Value,
|
|
77
|
+
activate: optional(Schema.Boolean),
|
|
78
|
+
}).annotate({ identifier: "Credential.CreateInput" })
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * as DurableEventManifest from "./durable-event-manifest.js"
|
|
2
|
+
|
|
3
|
+
import { Event } from "./event.js"
|
|
4
|
+
import { Worktree } from "./worktree.js"
|
|
5
|
+
import { SessionEvent } from "./session-event.js"
|
|
6
|
+
|
|
7
|
+
export const Durable = Event.durableMap([...SessionEvent.DurableDefinitions, Worktree.Event.Resolved])
|
package/src/event-log.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export * as EventLog from "./event-log.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { Event } from "./event.js"
|
|
5
|
+
import { optional } from "./schema.js"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Replay-to-live boundary marker for a durable log read. The reader now holds
|
|
9
|
+
* every event committed at or below this watermark; `seq` is absent when the
|
|
10
|
+
* captured watermark is empty. Emitted once for the captured watermark.
|
|
11
|
+
*/
|
|
12
|
+
export const Synced = Schema.Struct({
|
|
13
|
+
type: Schema.Literal("log.synced"),
|
|
14
|
+
aggregateID: Schema.String,
|
|
15
|
+
seq: optional(Event.Seq),
|
|
16
|
+
}).annotate({
|
|
17
|
+
identifier: "EventLog.Synced",
|
|
18
|
+
description:
|
|
19
|
+
"Marker emitted once when a log read reaches its captured watermark. The reader holds every event committed at or below seq.",
|
|
20
|
+
})
|
|
21
|
+
export interface Synced extends Schema.Schema.Type<typeof Synced> {}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export * as EventManifest from "./event-manifest.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { Agent } from "./agent.js"
|
|
5
|
+
import { Artifact } from "./artifact.js"
|
|
6
|
+
import { Command } from "./command.js"
|
|
7
|
+
import { Config } from "./config.js"
|
|
8
|
+
import { Credential } from "./credential.js"
|
|
9
|
+
import { Durable } from "./durable-event-manifest.js"
|
|
10
|
+
import { Event } from "./event.js"
|
|
11
|
+
import { FileSystem } from "./filesystem.js"
|
|
12
|
+
import { FileSystemV1 } from "./filesystem-v1.js"
|
|
13
|
+
import { Form } from "./form.js"
|
|
14
|
+
import { InstallationEvent } from "./installation-event.js"
|
|
15
|
+
import { Job } from "./job.js"
|
|
16
|
+
import { Integration } from "./integration.js"
|
|
17
|
+
import { LegacyEventV1 } from "./legacy-event.js"
|
|
18
|
+
import { LspEvent } from "./lsp-event.js"
|
|
19
|
+
import { LocationEvent } from "./location-event.js"
|
|
20
|
+
import { McpEvent } from "./mcp-event.js"
|
|
21
|
+
import { Model } from "./model.js"
|
|
22
|
+
import { ModelsDev } from "./models-dev.js"
|
|
23
|
+
import { Permission } from "./permission.js"
|
|
24
|
+
import { PersistentPty } from "./persistent-pty.js"
|
|
25
|
+
import { Plugin } from "./plugin.js"
|
|
26
|
+
import { Project } from "./project.js"
|
|
27
|
+
import { Provider } from "./provider.js"
|
|
28
|
+
import { Worktree } from "./worktree.js"
|
|
29
|
+
import { Pty } from "./pty.js"
|
|
30
|
+
import { Reference } from "./reference.js"
|
|
31
|
+
import { ServerEvent } from "./server-event.js"
|
|
32
|
+
import { Shell } from "./shell.js"
|
|
33
|
+
import { Skill } from "./skill.js"
|
|
34
|
+
import { SessionEvent } from "./session-event.js"
|
|
35
|
+
import { SessionStatusEvent } from "./session-status-event.js"
|
|
36
|
+
import { TuiEvent } from "./tui-event.js"
|
|
37
|
+
import { VcsEvent } from "./vcs-event.js"
|
|
38
|
+
import { WorkspaceEvent } from "./workspace-event.js"
|
|
39
|
+
import { WorktreeEvent } from "./worktree-event.js"
|
|
40
|
+
import { WebSearch } from "./websearch.js"
|
|
41
|
+
import { Push } from "./push.js"
|
|
42
|
+
|
|
43
|
+
const coreDefinitions = Event.inventory(...SessionEvent.Definitions)
|
|
44
|
+
|
|
45
|
+
const foundationDefinitions = Event.inventory(
|
|
46
|
+
...LocationEvent.Definitions,
|
|
47
|
+
...ModelsDev.Event.Definitions,
|
|
48
|
+
...Credential.Event.Definitions,
|
|
49
|
+
...Integration.Event.Definitions,
|
|
50
|
+
...Provider.Event.Definitions,
|
|
51
|
+
...Model.Event.Definitions,
|
|
52
|
+
...Agent.Event.Definitions,
|
|
53
|
+
...coreDefinitions,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
const featureDefinitions = Event.inventory(
|
|
57
|
+
...FileSystem.Event.Definitions,
|
|
58
|
+
...Reference.Event.Definitions,
|
|
59
|
+
...Permission.Event.Definitions,
|
|
60
|
+
...Plugin.Event.Definitions,
|
|
61
|
+
...Project.Event.Definitions,
|
|
62
|
+
...Worktree.Event.Definitions,
|
|
63
|
+
...Command.Event.Definitions,
|
|
64
|
+
...Config.Event.Definitions,
|
|
65
|
+
...Skill.Event.Definitions,
|
|
66
|
+
...Pty.Event.Definitions,
|
|
67
|
+
...PersistentPty.Event.Definitions,
|
|
68
|
+
...Shell.Event.Definitions,
|
|
69
|
+
...Job.Event.Definitions,
|
|
70
|
+
...Form.Event.Definitions,
|
|
71
|
+
...WebSearch.Event.Definitions,
|
|
72
|
+
...Push.Event.Definitions,
|
|
73
|
+
...Artifact.Event.Definitions,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
export const ServerDefinitions = Event.inventory(
|
|
77
|
+
...foundationDefinitions,
|
|
78
|
+
...featureDefinitions,
|
|
79
|
+
// Current events the TUI consumes from the public stream.
|
|
80
|
+
...SessionStatusEvent.Definitions,
|
|
81
|
+
...TuiEvent.Definitions,
|
|
82
|
+
...InstallationEvent.Definitions,
|
|
83
|
+
...VcsEvent.Definitions,
|
|
84
|
+
McpEvent.StatusChanged,
|
|
85
|
+
McpEvent.ResourcesChanged,
|
|
86
|
+
McpEvent.ExperimentalEvent,
|
|
87
|
+
)
|
|
88
|
+
export const Server = Event.latest(ServerDefinitions)
|
|
89
|
+
export type ServerEvent = Schema.Schema.Type<(typeof ServerDefinitions)[number]>
|
|
90
|
+
export const isServer = (event: { readonly type: string }): event is ServerEvent => Server.has(event.type)
|
|
91
|
+
|
|
92
|
+
export const Definitions = Event.inventory(
|
|
93
|
+
...foundationDefinitions,
|
|
94
|
+
...InstallationEvent.Definitions,
|
|
95
|
+
...featureDefinitions,
|
|
96
|
+
...LspEvent.Definitions,
|
|
97
|
+
...TuiEvent.Definitions,
|
|
98
|
+
...McpEvent.Definitions,
|
|
99
|
+
...LegacyEventV1.Definitions,
|
|
100
|
+
...FileSystemV1.Event.Definitions,
|
|
101
|
+
...SessionStatusEvent.Definitions,
|
|
102
|
+
...VcsEvent.Definitions,
|
|
103
|
+
...WorkspaceEvent.Definitions,
|
|
104
|
+
...WorktreeEvent.Definitions,
|
|
105
|
+
...ServerEvent.Definitions,
|
|
106
|
+
)
|
|
107
|
+
export const Latest = Event.latest(Definitions)
|
|
108
|
+
export { Durable }
|
package/src/event.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
export * as Event from "./event.js"
|
|
2
|
+
|
|
3
|
+
import { Schema, SchemaTransformation } from "effect"
|
|
4
|
+
import { optional } from "./schema.js"
|
|
5
|
+
import { ascending } from "./identifier.js"
|
|
6
|
+
import { Location } from "./location.js"
|
|
7
|
+
import { statics } from "./schema.js"
|
|
8
|
+
|
|
9
|
+
export const ID = Schema.String.check(Schema.isStartingWith("evt_")).pipe(
|
|
10
|
+
Schema.brand("Event.ID"),
|
|
11
|
+
Schema.annotate({ identifier: "Event.ID" }),
|
|
12
|
+
statics((schema) => ({ create: () => schema.make("evt_" + ascending()) })),
|
|
13
|
+
)
|
|
14
|
+
export type ID = typeof ID.Type
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Position in one aggregate's durable log. Values originate from the durable
|
|
18
|
+
* event envelope and synced markers;
|
|
19
|
+
* `after` cursors accept only values that came from those sources.
|
|
20
|
+
*/
|
|
21
|
+
export const Seq = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)).pipe(
|
|
22
|
+
Schema.brand("Event.Seq"),
|
|
23
|
+
Schema.annotate({ identifier: "Event.Seq" }),
|
|
24
|
+
)
|
|
25
|
+
export type Seq = typeof Seq.Type
|
|
26
|
+
|
|
27
|
+
/** Durable schema version of one event type, from the event definition that committed it. */
|
|
28
|
+
export const Version = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)).pipe(
|
|
29
|
+
Schema.brand("Event.Version"),
|
|
30
|
+
Schema.annotate({ identifier: "Event.Version" }),
|
|
31
|
+
)
|
|
32
|
+
export type Version = typeof Version.Type
|
|
33
|
+
|
|
34
|
+
const DurableEnvelope = Schema.Struct({ aggregateID: Schema.String, seq: Seq, version: Version })
|
|
35
|
+
export type DurableEnvelope = typeof DurableEnvelope.Type
|
|
36
|
+
|
|
37
|
+
export type DurableDefinition<
|
|
38
|
+
Type extends string = string,
|
|
39
|
+
DataSchema extends Schema.Codec<unknown, unknown> = Schema.Codec<unknown, unknown>,
|
|
40
|
+
> = Schema.Top & {
|
|
41
|
+
readonly type: Type
|
|
42
|
+
readonly durability: "durable"
|
|
43
|
+
readonly durable: {
|
|
44
|
+
readonly version: number
|
|
45
|
+
readonly aggregate: string
|
|
46
|
+
}
|
|
47
|
+
readonly data: DataSchema
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type EphemeralDefinition<
|
|
51
|
+
Type extends string = string,
|
|
52
|
+
DataSchema extends Schema.Codec<unknown, unknown> = Schema.Codec<unknown, unknown>,
|
|
53
|
+
> = Schema.Top & {
|
|
54
|
+
readonly type: Type
|
|
55
|
+
readonly durability: "ephemeral"
|
|
56
|
+
readonly durable?: never
|
|
57
|
+
readonly data: DataSchema
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type Definition<
|
|
61
|
+
Type extends string = string,
|
|
62
|
+
DataSchema extends Schema.Codec<unknown, unknown> = Schema.Codec<unknown, unknown>,
|
|
63
|
+
> = DurableDefinition<Type, DataSchema> | EphemeralDefinition<Type, DataSchema>
|
|
64
|
+
|
|
65
|
+
export type Data<D extends Definition> = Schema.Schema.Type<D["data"]>
|
|
66
|
+
|
|
67
|
+
type PayloadBase<D extends Definition> = {
|
|
68
|
+
readonly id: ID
|
|
69
|
+
readonly type: D["type"]
|
|
70
|
+
readonly created: number
|
|
71
|
+
readonly data: Data<D>
|
|
72
|
+
readonly location?: Location.Ref
|
|
73
|
+
readonly metadata?: Record<string, unknown>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type Payload<D extends Definition = Definition> = D extends DurableDefinition
|
|
77
|
+
? PayloadBase<D> & { readonly durable: DurableEnvelope }
|
|
78
|
+
: PayloadBase<D> & { readonly durable?: never }
|
|
79
|
+
|
|
80
|
+
type Input<Type extends string, Fields extends Readonly<Record<PropertyKey, Schema.Codec<unknown, unknown>>>> = {
|
|
81
|
+
readonly type: Type
|
|
82
|
+
readonly identifier?: string
|
|
83
|
+
readonly durable?: {
|
|
84
|
+
readonly version: number
|
|
85
|
+
readonly aggregate: string
|
|
86
|
+
}
|
|
87
|
+
readonly schema: Fields
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function durable<
|
|
91
|
+
const Type extends string,
|
|
92
|
+
const Fields extends Readonly<Record<PropertyKey, Schema.Codec<unknown, unknown>>>,
|
|
93
|
+
>(input: Input<Type, Fields> & { readonly durable: NonNullable<Input<Type, Fields>["durable"]> }) {
|
|
94
|
+
const data = Schema.Struct(input.schema)
|
|
95
|
+
const durable = Schema.Struct({
|
|
96
|
+
aggregateID: DurableEnvelope.fields.aggregateID,
|
|
97
|
+
seq: DurableEnvelope.fields.seq,
|
|
98
|
+
version: Schema.Literal(input.durable.version).pipe(
|
|
99
|
+
Schema.decodeTo(
|
|
100
|
+
Schema.toType(Version),
|
|
101
|
+
SchemaTransformation.transform({
|
|
102
|
+
decode: () => Version.make(input.durable.version),
|
|
103
|
+
encode: () => input.durable.version,
|
|
104
|
+
}),
|
|
105
|
+
),
|
|
106
|
+
),
|
|
107
|
+
})
|
|
108
|
+
return Schema.Struct({
|
|
109
|
+
id: ID,
|
|
110
|
+
created: Schema.Finite,
|
|
111
|
+
metadata: optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
112
|
+
type: Schema.Literal(input.type),
|
|
113
|
+
durable,
|
|
114
|
+
location: optional(Location.Ref),
|
|
115
|
+
data,
|
|
116
|
+
})
|
|
117
|
+
.annotate({ identifier: input.identifier ?? input.type })
|
|
118
|
+
.pipe(
|
|
119
|
+
statics(() => ({
|
|
120
|
+
type: input.type,
|
|
121
|
+
durability: "durable" as const,
|
|
122
|
+
durable: input.durable,
|
|
123
|
+
data,
|
|
124
|
+
})),
|
|
125
|
+
) satisfies DurableDefinition<Type, typeof data>
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function ephemeral<
|
|
129
|
+
const Type extends string,
|
|
130
|
+
const Fields extends Readonly<Record<PropertyKey, Schema.Codec<unknown, unknown>>>,
|
|
131
|
+
>(input: Omit<Input<Type, Fields>, "durable">) {
|
|
132
|
+
const data = Schema.Struct(input.schema)
|
|
133
|
+
return Schema.Struct({
|
|
134
|
+
id: ID,
|
|
135
|
+
created: Schema.Finite,
|
|
136
|
+
metadata: optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
137
|
+
type: Schema.Literal(input.type),
|
|
138
|
+
location: optional(Location.Ref),
|
|
139
|
+
data,
|
|
140
|
+
})
|
|
141
|
+
.annotate({ identifier: input.identifier ?? input.type })
|
|
142
|
+
.pipe(
|
|
143
|
+
statics(() => ({
|
|
144
|
+
type: input.type,
|
|
145
|
+
durability: "ephemeral" as const,
|
|
146
|
+
durable: undefined,
|
|
147
|
+
data,
|
|
148
|
+
})),
|
|
149
|
+
) satisfies EphemeralDefinition<Type, typeof data>
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function inventory<const Definitions extends ReadonlyArray<Definition>>(...definitions: Definitions) {
|
|
153
|
+
return Object.freeze(definitions)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function latest(definitions: ReadonlyArray<Definition>) {
|
|
157
|
+
return readonlyMap(
|
|
158
|
+
definitions.reduce((result, definition) => {
|
|
159
|
+
const existing = result.get(definition.type)
|
|
160
|
+
if (!existing) {
|
|
161
|
+
result.set(definition.type, definition)
|
|
162
|
+
return result
|
|
163
|
+
}
|
|
164
|
+
if (definition.durable && existing.durable && definition.durable.version !== existing.durable.version) {
|
|
165
|
+
if (definition.durable.version > existing.durable.version) result.set(definition.type, definition)
|
|
166
|
+
return result
|
|
167
|
+
}
|
|
168
|
+
if (definition !== existing) throw new Error(`Duplicate latest event definition for ${definition.type}`)
|
|
169
|
+
return result
|
|
170
|
+
}, new Map<string, Definition>()),
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function versionedType(type: string, version: number) {
|
|
175
|
+
return `${type}.${version}`
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function durableMap<const Definitions extends ReadonlyArray<Definition>>(definitions: Definitions) {
|
|
179
|
+
return readonlyMap(
|
|
180
|
+
definitions.reduce((result, definition) => {
|
|
181
|
+
if (definition.durability !== "durable") return result
|
|
182
|
+
const key = versionedType(definition.type, definition.durable.version)
|
|
183
|
+
if (result.has(key)) throw new Error(`Duplicate durable event definition for ${key}`)
|
|
184
|
+
result.set(key, definition)
|
|
185
|
+
return result
|
|
186
|
+
}, new Map<string, DurableDefinition>()),
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function readonlyMap<Key, Value>(map: Map<Key, Value>): ReadonlyMap<Key, Value> {
|
|
191
|
+
const result: ReadonlyMap<Key, Value> = Object.freeze({
|
|
192
|
+
get size() {
|
|
193
|
+
return map.size
|
|
194
|
+
},
|
|
195
|
+
entries: () => map.entries(),
|
|
196
|
+
forEach: (callback: (value: Value, key: Key, map: ReadonlyMap<Key, Value>) => void, thisArg?: unknown) =>
|
|
197
|
+
map.forEach((value, key) => callback.call(thisArg, value, key, result)),
|
|
198
|
+
get: (key: Key) => map.get(key),
|
|
199
|
+
has: (key: Key) => map.has(key),
|
|
200
|
+
keys: () => map.keys(),
|
|
201
|
+
values: () => map.values(),
|
|
202
|
+
[Symbol.iterator]: () => map[Symbol.iterator](),
|
|
203
|
+
})
|
|
204
|
+
return result
|
|
205
|
+
}
|
package/src/file-diff.ts
ADDED
|
@@ -0,0 +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> {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./v1/filesystem.js"
|
|
@@ -0,0 +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" })
|
package/src/form.ts
ADDED
|
@@ -0,0 +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) }
|