@zyro-sec/protocol 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/openapi.json +33222 -0
- package/package.json +7 -10
- package/script/build.ts +9 -0
- package/script/generate-openapi.ts +25 -0
- package/script/openapi-parameters.ts +30 -0
- package/script/openapi-stabilize.ts +102 -0
- package/script/pack.ts +5 -0
- package/src/api.ts +264 -0
- package/src/client.ts +127 -0
- package/src/errors.ts +398 -0
- package/src/groups/agent.ts +39 -0
- package/src/groups/artifact.ts +103 -0
- package/src/groups/automation.ts +75 -0
- package/src/groups/blob.ts +20 -0
- package/src/groups/command.ts +27 -0
- package/src/groups/config.ts +46 -0
- package/src/groups/credential.ts +72 -0
- package/src/groups/debug.ts +68 -0
- package/src/groups/event.ts +86 -0
- package/src/groups/experimental.ts +19 -0
- package/src/groups/form.ts +26 -0
- package/src/groups/fs.ts +136 -0
- package/src/groups/generate.ts +120 -0
- package/src/groups/integration.ts +230 -0
- package/src/groups/job.ts +57 -0
- package/src/groups/location.ts +66 -0
- package/src/groups/machine.ts +120 -0
- package/src/groups/mcp.ts +167 -0
- package/src/groups/media.ts +23 -0
- package/src/groups/message.ts +124 -0
- package/src/groups/migration.ts +28 -0
- package/src/groups/model.ts +52 -0
- package/src/groups/permission.ts +164 -0
- package/src/groups/persistent-pty.ts +153 -0
- package/src/groups/plugin.ts +80 -0
- package/src/groups/project.ts +51 -0
- package/src/groups/provider.ts +45 -0
- package/src/groups/pty.ts +153 -0
- package/src/groups/push.ts +94 -0
- package/src/groups/reference.ts +42 -0
- package/src/groups/rpc.ts +30 -0
- package/src/groups/server.ts +80 -0
- package/src/groups/session.ts +918 -0
- package/src/groups/shell.ts +88 -0
- package/src/groups/skill.ts +46 -0
- package/src/groups/usage.ts +30 -0
- package/src/groups/vcs.ts +131 -0
- package/src/groups/voice.ts +96 -0
- package/src/groups/websearch.ts +46 -0
- package/src/groups/worktree.ts +78 -0
- package/src/middleware/authorization.ts +6 -0
- package/src/middleware/schema-error.ts +7 -0
- package/src/simulation.ts +691 -0
- package/test/event.test.ts +34 -0
- package/test/experimental-identifiers.test.ts +24 -0
- package/test/openapi-parameters.test.ts +43 -0
- package/test/openapi-patterns.test.ts +28 -0
- package/test/openapi-stabilize.test.ts +161 -0
- package/test/session-cursor.test.ts +7 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +14 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@zyro-sec/protocol",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -12,9 +12,6 @@
|
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
|
-
"files": [
|
|
16
|
-
"dist"
|
|
17
|
-
],
|
|
18
15
|
"exports": {
|
|
19
16
|
"./simulation": "./src/simulation.ts",
|
|
20
17
|
"./*": "./src/*.ts"
|
|
@@ -29,14 +26,14 @@
|
|
|
29
26
|
"typecheck:tsc": "tsc --noEmit"
|
|
30
27
|
},
|
|
31
28
|
"dependencies": {
|
|
32
|
-
"@zyro-sec/schema": "^1.0.
|
|
33
|
-
"effect": "
|
|
29
|
+
"@zyro-sec/schema": "^1.0.2",
|
|
30
|
+
"effect": "4.1.0"
|
|
34
31
|
},
|
|
35
32
|
"devDependencies": {
|
|
36
|
-
"@tsconfig/bun": "
|
|
37
|
-
"@types/bun": "
|
|
38
|
-
"@typescript/native": "
|
|
33
|
+
"@tsconfig/bun": "1.0.9",
|
|
34
|
+
"@types/bun": "1.4.3",
|
|
35
|
+
"@typescript/native": "npm:typescript@7.1.0-beta",
|
|
39
36
|
"prettier": "3.6.2",
|
|
40
|
-
"typescript": "
|
|
37
|
+
"typescript": "npm:@typescript/typescript6@6.0.2"
|
|
41
38
|
}
|
|
42
39
|
}
|
package/script/build.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { OpenApi } from "effect/http-api"
|
|
2
|
+
import { format } from "prettier"
|
|
3
|
+
import { fileURLToPath } from "url"
|
|
4
|
+
import { ClientApi } from "../src/client.js"
|
|
5
|
+
import { liftParameterDescriptions } from "./openapi-parameters.js"
|
|
6
|
+
import { stabilizeOpenApi } from "./openapi-stabilize.js"
|
|
7
|
+
|
|
8
|
+
const document = await format(
|
|
9
|
+
JSON.stringify(liftParameterDescriptions(stabilizeOpenApi(OpenApi.fromApi(ClientApi))), null, 2),
|
|
10
|
+
{
|
|
11
|
+
parser: "json",
|
|
12
|
+
printWidth: 120,
|
|
13
|
+
},
|
|
14
|
+
)
|
|
15
|
+
const target = fileURLToPath(new URL("../openapi.json", import.meta.url))
|
|
16
|
+
|
|
17
|
+
if (process.argv.includes("--check")) {
|
|
18
|
+
if ((await Bun.file(target).text()) !== document) {
|
|
19
|
+
console.error("Generated OpenAPI document is stale. Run `bun run generate` from packages/protocol.")
|
|
20
|
+
process.exit(1)
|
|
21
|
+
}
|
|
22
|
+
process.exit(0)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
await Bun.write(target, document)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type Schema = { description?: string; allOf?: Array<Record<string, unknown>>; [key: string]: unknown }
|
|
2
|
+
type Parameter = { description?: string; schema?: Schema; [key: string]: unknown }
|
|
3
|
+
type Document = { paths?: Record<string, Record<string, { parameters?: Array<Parameter> }>> }
|
|
4
|
+
|
|
5
|
+
// Effect writes a parameter's description into its schema: `.annotate` sets `schema.description`, and `.annotateKey`
|
|
6
|
+
// (used where annotating would rename a shared component) adds a `{ description }` member to `schema.allOf`. OpenAPI
|
|
7
|
+
// documents parameters by `parameters[].description`, so move it there.
|
|
8
|
+
export function liftParameterDescriptions<T extends object>(document: T): T {
|
|
9
|
+
for (const operations of Object.values((document as Document).paths ?? {}))
|
|
10
|
+
for (const operation of Object.values(operations))
|
|
11
|
+
operation.parameters = operation.parameters?.map((parameter) => {
|
|
12
|
+
if (parameter.schema === undefined || parameter.description !== undefined) return parameter
|
|
13
|
+
const description = parameter.schema.allOf?.find(isDescription)?.description ?? parameter.schema.description
|
|
14
|
+
if (description === undefined) return parameter
|
|
15
|
+
return { ...parameter, description, schema: withoutDescription(parameter.schema) }
|
|
16
|
+
})
|
|
17
|
+
return document
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isDescription(member: Record<string, unknown>): member is { description: string } {
|
|
21
|
+
return Object.keys(member).length === 1 && typeof member.description === "string"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function withoutDescription(schema: Schema): Schema {
|
|
25
|
+
const rest = Object.fromEntries(Object.entries(schema).filter(([key]) => key !== "description" && key !== "allOf"))
|
|
26
|
+
const allOf = schema.allOf?.filter((member) => !isDescription(member)) ?? []
|
|
27
|
+
if (allOf.length === 0) return rest
|
|
28
|
+
if (allOf.length === 1 && Object.keys(rest).length === 0) return allOf[0]
|
|
29
|
+
return { ...rest, allOf }
|
|
30
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
type Document = { components: { schemas: Record<string, unknown> } }
|
|
2
|
+
|
|
3
|
+
const prefix = "#/components/schemas/"
|
|
4
|
+
const byKey = ([left]: [string, unknown], [right]: [string, unknown]) => (left < right ? -1 : left > right ? 1 : 0)
|
|
5
|
+
const refName = (value: unknown) =>
|
|
6
|
+
typeof value === "string" && value.startsWith(prefix) ? value.slice(prefix.length) : undefined
|
|
7
|
+
|
|
8
|
+
const renameRefs = (node: unknown, rename: (name: string) => string): unknown => {
|
|
9
|
+
if (Array.isArray(node)) return node.map((item) => renameRefs(item, rename))
|
|
10
|
+
if (typeof node !== "object" || node === null) return node
|
|
11
|
+
return Object.fromEntries(
|
|
12
|
+
Object.entries(node).map(([key, value]) => {
|
|
13
|
+
const name = key === "$ref" ? refName(value) : undefined
|
|
14
|
+
return [key, name === undefined ? renameRefs(value, rename) : prefix + rename(name)]
|
|
15
|
+
}),
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Sorted keys, with references to `inline` components replaced by their canonical content.
|
|
20
|
+
const canonical = (
|
|
21
|
+
node: unknown,
|
|
22
|
+
inline: ReadonlyMap<string, unknown> = new Map(),
|
|
23
|
+
seen = new Set<string>(),
|
|
24
|
+
): unknown => {
|
|
25
|
+
if (Array.isArray(node)) return node.map((item) => canonical(item, inline, seen))
|
|
26
|
+
if (typeof node !== "object" || node === null) return node
|
|
27
|
+
return Object.fromEntries(
|
|
28
|
+
Object.entries(node)
|
|
29
|
+
.sort(byKey)
|
|
30
|
+
.map(([key, value]) => {
|
|
31
|
+
const name = key === "$ref" ? refName(value) : undefined
|
|
32
|
+
if (name === undefined || !inline.has(name)) return [key, canonical(value, inline, seen)]
|
|
33
|
+
if (seen.has(name)) throw new Error(`Recursive anonymous OpenAPI component: ${name}`)
|
|
34
|
+
return [key, canonical(inline.get(name), inline, new Set([...seen, name]))]
|
|
35
|
+
}),
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
const shape = (node: unknown, inline?: ReadonlyMap<string, unknown>) => JSON.stringify(canonical(node, inline))
|
|
39
|
+
|
|
40
|
+
// Effect gives shared anonymous schemas encounter-order names (`Union_3`), and does the same for the encoded side of a
|
|
41
|
+
// named schema when it differs between uses (`Event.VersionEncoded_37`). Replace those names with a hash of their
|
|
42
|
+
// canonical shape and sort components so unrelated additions stay local.
|
|
43
|
+
export function stabilizeOpenApi(source: object) {
|
|
44
|
+
const schemas = (source as Document).components.schemas
|
|
45
|
+
const families = ["Union_", "Objects_", "Arrays_"].filter((name) => name in schemas)
|
|
46
|
+
const encoded = new Set(Object.keys(schemas).flatMap((name) => /^(.+Encoded)_\d+$/.exec(name)?.[1] ?? []))
|
|
47
|
+
const anonymous = new Map(
|
|
48
|
+
Object.entries(schemas).filter(
|
|
49
|
+
([name]) => families.includes(name.replace(/\d+$/, "")) || encoded.has(name.replace(/_\d+$/, "")),
|
|
50
|
+
),
|
|
51
|
+
)
|
|
52
|
+
const renames = new Map(
|
|
53
|
+
[...anonymous].map(([name, schema]) => {
|
|
54
|
+
const hash = new Bun.CryptoHasher("sha256").update(shape(schema, anonymous)).digest("hex").slice(0, 12)
|
|
55
|
+
return [name, `${name.replace(/_\d*$/, "")}_${hash}`] as const
|
|
56
|
+
}),
|
|
57
|
+
)
|
|
58
|
+
const result = renameRefs(source, (name) => renames.get(name) ?? name) as Document
|
|
59
|
+
const stable = new Map<string, unknown>()
|
|
60
|
+
for (const [name, schema] of Object.entries(result.components.schemas)) {
|
|
61
|
+
const target = renames.get(name) ?? name
|
|
62
|
+
const previous = stable.get(target)
|
|
63
|
+
if (previous !== undefined && shape(previous) !== shape(schema)) {
|
|
64
|
+
throw new Error(`Content-addressed OpenAPI component collision: ${target}`)
|
|
65
|
+
}
|
|
66
|
+
stable.set(target, schema)
|
|
67
|
+
}
|
|
68
|
+
result.components.schemas = Object.fromEntries([...stable].sort(byKey))
|
|
69
|
+
return collapseCopies(result)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Effect names a second AST copy of an identified schema `<Name>_<N>`; event streams reach their schemas without the
|
|
73
|
+
// JSON codec that REST bodies get. Fold a copy into `<Name>` only when the two are deeply equal, treating a reference
|
|
74
|
+
// to a copy as a reference to its original only while that copy still folds. Any real difference keeps its own name.
|
|
75
|
+
function collapseCopies(document: Document) {
|
|
76
|
+
const schemas = document.components.schemas
|
|
77
|
+
const copies = new Map<string, string>()
|
|
78
|
+
for (const name of Object.keys(schemas)) {
|
|
79
|
+
const original = /^(.+)_\d+$/.exec(name)?.[1]
|
|
80
|
+
if (original !== undefined && Object.hasOwn(schemas, original)) copies.set(name, original)
|
|
81
|
+
}
|
|
82
|
+
const resolve = (name: string): string => {
|
|
83
|
+
const original = copies.get(name)
|
|
84
|
+
return original === undefined ? name : resolve(original)
|
|
85
|
+
}
|
|
86
|
+
const folded = (name: string) => shape(renameRefs(schemas[name], resolve))
|
|
87
|
+
let changed = true
|
|
88
|
+
while (changed) {
|
|
89
|
+
changed = false
|
|
90
|
+
for (const [copy, original] of copies) {
|
|
91
|
+
if (folded(copy) === folded(original)) continue
|
|
92
|
+
copies.delete(copy)
|
|
93
|
+
changed = true
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (copies.size === 0) return document
|
|
97
|
+
const result = renameRefs(document, resolve) as Document
|
|
98
|
+
result.components.schemas = Object.fromEntries(
|
|
99
|
+
Object.entries(result.components.schemas).filter(([name]) => !copies.has(name)),
|
|
100
|
+
)
|
|
101
|
+
return result
|
|
102
|
+
}
|
package/script/pack.ts
ADDED
package/src/api.ts
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { Context } from "effect"
|
|
2
|
+
import { HttpApi, HttpApiGroup, HttpApiMiddleware, OpenApi } from "effect/http-api"
|
|
3
|
+
import { SchemaErrorMiddleware } from "./middleware/schema-error.js"
|
|
4
|
+
import { GenerateGroup } from "./groups/generate.js"
|
|
5
|
+
import { ExperimentalGroup } from "./groups/experimental.js"
|
|
6
|
+
import { VoiceGroup } from "./groups/voice.js"
|
|
7
|
+
import { MessageGroup } from "./groups/message.js"
|
|
8
|
+
import { ModelGroup } from "./groups/model.js"
|
|
9
|
+
import { ProviderGroup } from "./groups/provider.js"
|
|
10
|
+
import { makeSessionGroup } from "./groups/session.js"
|
|
11
|
+
import { makePermissionGroup } from "./groups/permission.js"
|
|
12
|
+
import { FileSystemGroup } from "./groups/fs.js"
|
|
13
|
+
import { makeFormGroup } from "./groups/form.js"
|
|
14
|
+
import { CommandGroup } from "./groups/command.js"
|
|
15
|
+
import { SkillGroup } from "./groups/skill.js"
|
|
16
|
+
import { RpcGroup } from "./groups/rpc.js"
|
|
17
|
+
import { EventGroup, makeEventGroup } from "./groups/event.js"
|
|
18
|
+
import type { Definition } from "@zyro-sec/schema/event"
|
|
19
|
+
import { AgentGroup } from "./groups/agent.js"
|
|
20
|
+
import { PluginGroup } from "./groups/plugin.js"
|
|
21
|
+
import { ServerGroup } from "./groups/server.js"
|
|
22
|
+
import { DebugGroup } from "./groups/debug.js"
|
|
23
|
+
import { makePtyGroup } from "./groups/pty.js"
|
|
24
|
+
import { ShellGroup } from "./groups/shell.js"
|
|
25
|
+
import { ReferenceGroup } from "./groups/reference.js"
|
|
26
|
+
import { Authorization } from "./middleware/authorization.js"
|
|
27
|
+
import { makeLocationGroup } from "./groups/location.js"
|
|
28
|
+
import { IntegrationGroup } from "./groups/integration.js"
|
|
29
|
+
import { WebSearchGroup } from "./groups/websearch.js"
|
|
30
|
+
import { UsageGroup } from "./groups/usage.js"
|
|
31
|
+
import { makeMcpGroup } from "./groups/mcp.js"
|
|
32
|
+
import { CredentialGroup } from "./groups/credential.js"
|
|
33
|
+
import { ProjectGroup } from "./groups/project.js"
|
|
34
|
+
import { WorktreeGroup } from "./groups/worktree.js"
|
|
35
|
+
import { VcsGroup } from "./groups/vcs.js"
|
|
36
|
+
import { MigrationGroup } from "./groups/migration.js"
|
|
37
|
+
import { ConfigGroup } from "./groups/config.js"
|
|
38
|
+
|
|
39
|
+
type LocationGroups<LocationId extends HttpApiMiddleware.AnyId> =
|
|
40
|
+
| HttpApiGroup.AddMiddleware<typeof AgentGroup, LocationId>
|
|
41
|
+
| HttpApiGroup.AddMiddleware<typeof PluginGroup, LocationId>
|
|
42
|
+
| HttpApiGroup.AddMiddleware<typeof ModelGroup, LocationId>
|
|
43
|
+
| HttpApiGroup.AddMiddleware<typeof ProviderGroup, LocationId>
|
|
44
|
+
| HttpApiGroup.AddMiddleware<typeof IntegrationGroup, LocationId>
|
|
45
|
+
| HttpApiGroup.AddMiddleware<typeof WebSearchGroup, LocationId>
|
|
46
|
+
| HttpApiGroup.AddMiddleware<typeof UsageGroup, LocationId>
|
|
47
|
+
| HttpApiGroup.AddMiddleware<typeof FileSystemGroup, LocationId>
|
|
48
|
+
| HttpApiGroup.AddMiddleware<typeof CommandGroup, LocationId>
|
|
49
|
+
| HttpApiGroup.AddMiddleware<typeof SkillGroup, LocationId>
|
|
50
|
+
| HttpApiGroup.AddMiddleware<typeof RpcGroup, LocationId>
|
|
51
|
+
| HttpApiGroup.AddMiddleware<typeof ShellGroup, LocationId>
|
|
52
|
+
| HttpApiGroup.AddMiddleware<typeof ReferenceGroup, LocationId>
|
|
53
|
+
| HttpApiGroup.AddMiddleware<typeof VcsGroup, LocationId>
|
|
54
|
+
| HttpApiGroup.AddMiddleware<typeof ConfigGroup, LocationId>
|
|
55
|
+
|
|
56
|
+
type PtyGroups<LocationId extends HttpApiMiddleware.AnyId, LocationService> = ReturnType<
|
|
57
|
+
typeof makePtyGroup<LocationId, LocationService>
|
|
58
|
+
>
|
|
59
|
+
|
|
60
|
+
type McpGroups<LocationId extends HttpApiMiddleware.AnyId, LocationService> = ReturnType<
|
|
61
|
+
typeof makeMcpGroup<LocationId, LocationService>
|
|
62
|
+
>
|
|
63
|
+
|
|
64
|
+
type SessionGroups<
|
|
65
|
+
SessionLocationId extends HttpApiMiddleware.AnyId,
|
|
66
|
+
SessionLocationService,
|
|
67
|
+
FormLocationId extends HttpApiMiddleware.AnyId,
|
|
68
|
+
FormLocationService,
|
|
69
|
+
> =
|
|
70
|
+
| ReturnType<typeof makeSessionGroup<SessionLocationId, SessionLocationService, FormLocationId, FormLocationService>>
|
|
71
|
+
| typeof MessageGroup
|
|
72
|
+
|
|
73
|
+
type FormGroups<LocationId extends HttpApiMiddleware.AnyId, LocationService> = ReturnType<
|
|
74
|
+
typeof makeFormGroup<LocationId, LocationService>
|
|
75
|
+
>
|
|
76
|
+
|
|
77
|
+
type LocationGroup<LocationId extends HttpApiMiddleware.AnyId, LocationService> = ReturnType<
|
|
78
|
+
typeof makeLocationGroup<LocationId, LocationService>
|
|
79
|
+
>
|
|
80
|
+
|
|
81
|
+
type MixedMiddlewareGroups<
|
|
82
|
+
LocationId extends HttpApiMiddleware.AnyId,
|
|
83
|
+
LocationService,
|
|
84
|
+
SessionLocationId extends HttpApiMiddleware.AnyId,
|
|
85
|
+
SessionLocationService,
|
|
86
|
+
> = ReturnType<typeof makePermissionGroup<LocationId, LocationService, SessionLocationId, SessionLocationService>>
|
|
87
|
+
|
|
88
|
+
type ApiGroups<
|
|
89
|
+
LocationId extends HttpApiMiddleware.AnyId,
|
|
90
|
+
LocationService,
|
|
91
|
+
FormLocationId extends HttpApiMiddleware.AnyId,
|
|
92
|
+
FormLocationService,
|
|
93
|
+
SessionLocationId extends HttpApiMiddleware.AnyId,
|
|
94
|
+
SessionLocationService,
|
|
95
|
+
Event extends HttpApiGroup.Constraint,
|
|
96
|
+
> =
|
|
97
|
+
| typeof ServerGroup
|
|
98
|
+
| typeof DebugGroup
|
|
99
|
+
| typeof MigrationGroup
|
|
100
|
+
| typeof WorktreeGroup
|
|
101
|
+
| typeof GenerateGroup
|
|
102
|
+
| typeof VoiceGroup
|
|
103
|
+
| typeof ExperimentalGroup
|
|
104
|
+
| typeof CredentialGroup
|
|
105
|
+
| typeof ProjectGroup
|
|
106
|
+
| LocationGroups<LocationId>
|
|
107
|
+
| LocationGroup<LocationId, LocationService>
|
|
108
|
+
| PtyGroups<LocationId, LocationService>
|
|
109
|
+
| McpGroups<LocationId, LocationService>
|
|
110
|
+
| FormGroups<LocationId, LocationService>
|
|
111
|
+
| SessionGroups<SessionLocationId, SessionLocationService, FormLocationId, FormLocationService>
|
|
112
|
+
| MixedMiddlewareGroups<LocationId, LocationService, SessionLocationId, SessionLocationService>
|
|
113
|
+
| Event
|
|
114
|
+
|
|
115
|
+
type EventGroupFor<Definitions extends ReadonlyArray<Definition>> = ReturnType<typeof makeEventGroup<Definitions>>
|
|
116
|
+
|
|
117
|
+
export type Api<
|
|
118
|
+
LocationId extends HttpApiMiddleware.AnyId,
|
|
119
|
+
LocationService,
|
|
120
|
+
FormLocationId extends HttpApiMiddleware.AnyId,
|
|
121
|
+
FormLocationService,
|
|
122
|
+
SessionLocationId extends HttpApiMiddleware.AnyId,
|
|
123
|
+
SessionLocationService,
|
|
124
|
+
Event extends HttpApiGroup.Constraint,
|
|
125
|
+
> = HttpApi.HttpApi<
|
|
126
|
+
"server",
|
|
127
|
+
HttpApiGroup.AddMiddleware<
|
|
128
|
+
HttpApiGroup.AddMiddleware<
|
|
129
|
+
ApiGroups<
|
|
130
|
+
LocationId,
|
|
131
|
+
LocationService,
|
|
132
|
+
FormLocationId,
|
|
133
|
+
FormLocationService,
|
|
134
|
+
SessionLocationId,
|
|
135
|
+
SessionLocationService,
|
|
136
|
+
Event
|
|
137
|
+
>,
|
|
138
|
+
Authorization
|
|
139
|
+
>,
|
|
140
|
+
SchemaErrorMiddleware
|
|
141
|
+
>
|
|
142
|
+
>
|
|
143
|
+
|
|
144
|
+
// Protocol owns middleware placement, while Server injects concrete keys so Core service identities stay downstream.
|
|
145
|
+
const makeApiFromGroup = <
|
|
146
|
+
const Group extends HttpApiGroup.Constraint,
|
|
147
|
+
LocationId extends HttpApiMiddleware.AnyId,
|
|
148
|
+
LocationService,
|
|
149
|
+
FormLocationId extends HttpApiMiddleware.AnyId,
|
|
150
|
+
FormLocationService,
|
|
151
|
+
SessionLocationId extends HttpApiMiddleware.AnyId,
|
|
152
|
+
SessionLocationService,
|
|
153
|
+
>(
|
|
154
|
+
eventGroup: Group,
|
|
155
|
+
locationMiddleware: Context.Key<LocationId, LocationService>,
|
|
156
|
+
formLocationMiddleware: Context.Key<FormLocationId, FormLocationService>,
|
|
157
|
+
sessionLocationMiddleware: Context.Key<SessionLocationId, SessionLocationService>,
|
|
158
|
+
): Api<
|
|
159
|
+
LocationId,
|
|
160
|
+
LocationService,
|
|
161
|
+
FormLocationId,
|
|
162
|
+
FormLocationService,
|
|
163
|
+
SessionLocationId,
|
|
164
|
+
SessionLocationService,
|
|
165
|
+
Group
|
|
166
|
+
> =>
|
|
167
|
+
HttpApi.make("server")
|
|
168
|
+
.add(ServerGroup)
|
|
169
|
+
.add(makeLocationGroup(locationMiddleware))
|
|
170
|
+
.add(AgentGroup.middleware(locationMiddleware))
|
|
171
|
+
.add(PluginGroup.middleware(locationMiddleware))
|
|
172
|
+
.add(makeSessionGroup(sessionLocationMiddleware, formLocationMiddleware))
|
|
173
|
+
.add(MessageGroup)
|
|
174
|
+
.add(ModelGroup.middleware(locationMiddleware))
|
|
175
|
+
.add(GenerateGroup)
|
|
176
|
+
.add(VoiceGroup)
|
|
177
|
+
.add(ProviderGroup.middleware(locationMiddleware))
|
|
178
|
+
.add(IntegrationGroup.middleware(locationMiddleware))
|
|
179
|
+
.add(makeMcpGroup(locationMiddleware))
|
|
180
|
+
.add(CredentialGroup)
|
|
181
|
+
.add(ProjectGroup)
|
|
182
|
+
.add(makeFormGroup(locationMiddleware))
|
|
183
|
+
.add(makePermissionGroup(locationMiddleware, sessionLocationMiddleware))
|
|
184
|
+
.add(FileSystemGroup.middleware(locationMiddleware))
|
|
185
|
+
.add(CommandGroup.middleware(locationMiddleware))
|
|
186
|
+
.add(SkillGroup.middleware(locationMiddleware))
|
|
187
|
+
.add(RpcGroup.middleware(locationMiddleware))
|
|
188
|
+
.add(eventGroup)
|
|
189
|
+
.add(makePtyGroup(locationMiddleware))
|
|
190
|
+
.add(ExperimentalGroup)
|
|
191
|
+
.add(ShellGroup.middleware(locationMiddleware))
|
|
192
|
+
.add(ReferenceGroup.middleware(locationMiddleware))
|
|
193
|
+
.add(WorktreeGroup)
|
|
194
|
+
.add(VcsGroup.middleware(locationMiddleware))
|
|
195
|
+
.add(DebugGroup)
|
|
196
|
+
.add(MigrationGroup)
|
|
197
|
+
.add(WebSearchGroup.middleware(locationMiddleware))
|
|
198
|
+
.add(UsageGroup.middleware(locationMiddleware))
|
|
199
|
+
.add(ConfigGroup.middleware(locationMiddleware))
|
|
200
|
+
.annotateMerge(
|
|
201
|
+
OpenApi.annotations({
|
|
202
|
+
title: "opencode HttpApi",
|
|
203
|
+
version: "0.0.1",
|
|
204
|
+
description: "Experimental HttpApi surface for selected instance routes.",
|
|
205
|
+
}),
|
|
206
|
+
)
|
|
207
|
+
.middleware(Authorization)
|
|
208
|
+
.middleware(SchemaErrorMiddleware)
|
|
209
|
+
|
|
210
|
+
export const makeApi = <
|
|
211
|
+
const Definitions extends ReadonlyArray<Definition>,
|
|
212
|
+
LocationId extends HttpApiMiddleware.AnyId,
|
|
213
|
+
LocationService,
|
|
214
|
+
FormLocationId extends HttpApiMiddleware.AnyId,
|
|
215
|
+
FormLocationService,
|
|
216
|
+
SessionLocationId extends HttpApiMiddleware.AnyId,
|
|
217
|
+
SessionLocationService,
|
|
218
|
+
>(options: {
|
|
219
|
+
readonly definitions: Definitions
|
|
220
|
+
readonly locationMiddleware: Context.Key<LocationId, LocationService>
|
|
221
|
+
readonly formLocationMiddleware: Context.Key<FormLocationId, FormLocationService>
|
|
222
|
+
readonly sessionLocationMiddleware: Context.Key<SessionLocationId, SessionLocationService>
|
|
223
|
+
}): Api<
|
|
224
|
+
LocationId,
|
|
225
|
+
LocationService,
|
|
226
|
+
FormLocationId,
|
|
227
|
+
FormLocationService,
|
|
228
|
+
SessionLocationId,
|
|
229
|
+
SessionLocationService,
|
|
230
|
+
EventGroupFor<Definitions>
|
|
231
|
+
> =>
|
|
232
|
+
makeApiFromGroup(
|
|
233
|
+
makeEventGroup(options.definitions),
|
|
234
|
+
options.locationMiddleware,
|
|
235
|
+
options.formLocationMiddleware,
|
|
236
|
+
options.sessionLocationMiddleware,
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
export const makeDefaultApi = <
|
|
240
|
+
LocationId extends HttpApiMiddleware.AnyId,
|
|
241
|
+
LocationService,
|
|
242
|
+
FormLocationId extends HttpApiMiddleware.AnyId,
|
|
243
|
+
FormLocationService,
|
|
244
|
+
SessionLocationId extends HttpApiMiddleware.AnyId,
|
|
245
|
+
SessionLocationService,
|
|
246
|
+
>(options: {
|
|
247
|
+
readonly locationMiddleware: Context.Key<LocationId, LocationService>
|
|
248
|
+
readonly formLocationMiddleware: Context.Key<FormLocationId, FormLocationService>
|
|
249
|
+
readonly sessionLocationMiddleware: Context.Key<SessionLocationId, SessionLocationService>
|
|
250
|
+
}): Api<
|
|
251
|
+
LocationId,
|
|
252
|
+
LocationService,
|
|
253
|
+
FormLocationId,
|
|
254
|
+
FormLocationService,
|
|
255
|
+
SessionLocationId,
|
|
256
|
+
SessionLocationService,
|
|
257
|
+
typeof EventGroup
|
|
258
|
+
> =>
|
|
259
|
+
makeApiFromGroup(
|
|
260
|
+
EventGroup,
|
|
261
|
+
options.locationMiddleware,
|
|
262
|
+
options.formLocationMiddleware,
|
|
263
|
+
options.sessionLocationMiddleware,
|
|
264
|
+
)
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { LocationNotFoundError, InvalidRequestError, SessionNotFoundError } from "./errors.js"
|
|
2
|
+
import { makeDefaultApi } from "./api.js"
|
|
3
|
+
import type { Api } from "./api.js"
|
|
4
|
+
import type { Context } from "effect"
|
|
5
|
+
import { HttpApiMiddleware } from "effect/http-api"
|
|
6
|
+
import type { EventGroup } from "./groups/event.js"
|
|
7
|
+
|
|
8
|
+
class LocationMiddleware extends HttpApiMiddleware.Service<LocationMiddleware>()(
|
|
9
|
+
"@zyro-sec/client/LocationMiddleware",
|
|
10
|
+
{ error: [LocationNotFoundError] },
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
class SessionLocationMiddleware extends HttpApiMiddleware.Service<SessionLocationMiddleware>()(
|
|
14
|
+
"@zyro-sec/client/SessionLocationMiddleware",
|
|
15
|
+
{ error: [InvalidRequestError, SessionNotFoundError, LocationNotFoundError] },
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
type ClientApiShape = Api<
|
|
19
|
+
Context.Service.Identifier<typeof LocationMiddleware>,
|
|
20
|
+
Context.Service.Shape<typeof LocationMiddleware>,
|
|
21
|
+
Context.Service.Identifier<typeof SessionLocationMiddleware>,
|
|
22
|
+
Context.Service.Shape<typeof SessionLocationMiddleware>,
|
|
23
|
+
Context.Service.Identifier<typeof SessionLocationMiddleware>,
|
|
24
|
+
Context.Service.Shape<typeof SessionLocationMiddleware>,
|
|
25
|
+
typeof EventGroup
|
|
26
|
+
>
|
|
27
|
+
|
|
28
|
+
export const ClientApi: ClientApiShape = makeDefaultApi({
|
|
29
|
+
locationMiddleware: LocationMiddleware,
|
|
30
|
+
// The real server uses a form-specific middleware with an undocumented `global` sentinel branch.
|
|
31
|
+
// The generated client only needs a middleware identity for API typing.
|
|
32
|
+
formLocationMiddleware: SessionLocationMiddleware,
|
|
33
|
+
sessionLocationMiddleware: SessionLocationMiddleware,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export const groupNames = {
|
|
37
|
+
"server.server": "server",
|
|
38
|
+
"server.debug": "debug",
|
|
39
|
+
"server.migration": "migration",
|
|
40
|
+
"server.location": "location",
|
|
41
|
+
"server.agent": "agent",
|
|
42
|
+
"server.plugin": "plugin",
|
|
43
|
+
"server.session": "session",
|
|
44
|
+
"server.message": "message",
|
|
45
|
+
"server.model": "model",
|
|
46
|
+
"server.generate": "generate",
|
|
47
|
+
"server.voice": "voice",
|
|
48
|
+
"server.provider": "provider",
|
|
49
|
+
"server.integration": "integration",
|
|
50
|
+
"server.websearch": "websearch",
|
|
51
|
+
"server.usage": "usage",
|
|
52
|
+
"server.credential": "credential",
|
|
53
|
+
"server.form": "form",
|
|
54
|
+
"server.permission": "permission",
|
|
55
|
+
"server.fs": "file",
|
|
56
|
+
"server.command": "command",
|
|
57
|
+
"server.skill": "skill",
|
|
58
|
+
"server.rpc": "rpc",
|
|
59
|
+
"server.event": "event",
|
|
60
|
+
"server.pty": "pty",
|
|
61
|
+
"server.experimental": "experimental",
|
|
62
|
+
"server.shell": "shell",
|
|
63
|
+
"server.mcp": "mcp",
|
|
64
|
+
"server.reference": "reference",
|
|
65
|
+
"server.project": "project",
|
|
66
|
+
"server.worktree": "worktree",
|
|
67
|
+
"server.vcs": "vcs",
|
|
68
|
+
"server.config": "config",
|
|
69
|
+
} as const
|
|
70
|
+
|
|
71
|
+
// Experimental routes carry no compatibility promise, so the generated clients nest them under
|
|
72
|
+
// `client.experimental` instead of beside stable methods. The URL decides rather than the OpenAPI
|
|
73
|
+
// id, because the URL is what callers depend on and an id can miss its `experimental.` prefix.
|
|
74
|
+
export const clientNamespace = (endpoint: { readonly path: string }) =>
|
|
75
|
+
endpoint.path === "/api/experimental" || endpoint.path.startsWith("/api/experimental/") ? "experimental" : undefined
|
|
76
|
+
|
|
77
|
+
// The client paths that shipped before experimental methods moved under `client.experimental`. Each keeps a
|
|
78
|
+
// deprecated alias until the next minor. Frozen: endpoints added since never had another path.
|
|
79
|
+
export const deprecatedClientPaths = new Set([
|
|
80
|
+
"config.update",
|
|
81
|
+
"file.unwatch",
|
|
82
|
+
"file.watch",
|
|
83
|
+
"file.write",
|
|
84
|
+
"generate.decisions",
|
|
85
|
+
"generate.image",
|
|
86
|
+
"generate.text",
|
|
87
|
+
"integration.wellknown.add",
|
|
88
|
+
"mcp.add",
|
|
89
|
+
"mcp.client.token",
|
|
90
|
+
"mcp.connect",
|
|
91
|
+
"mcp.disconnect",
|
|
92
|
+
"mcp.remove",
|
|
93
|
+
"migration.v1.status",
|
|
94
|
+
"session.export",
|
|
95
|
+
"session.import",
|
|
96
|
+
"session.instructions.entry.list",
|
|
97
|
+
"session.instructions.entry.put",
|
|
98
|
+
"session.instructions.entry.remove",
|
|
99
|
+
"session.log",
|
|
100
|
+
"session.skill",
|
|
101
|
+
"session.stats",
|
|
102
|
+
"session.wait",
|
|
103
|
+
"usage.limits",
|
|
104
|
+
"voice.models",
|
|
105
|
+
"voice.session",
|
|
106
|
+
])
|
|
107
|
+
|
|
108
|
+
export const promiseOmitEndpoints = new Set([
|
|
109
|
+
"pty.connect",
|
|
110
|
+
"persistentPty.connect",
|
|
111
|
+
"mcp.client",
|
|
112
|
+
"machine.link",
|
|
113
|
+
"generate.textLegacy",
|
|
114
|
+
])
|
|
115
|
+
export const effectOmitEndpoints = new Set([
|
|
116
|
+
"fs.read",
|
|
117
|
+
"fs.write",
|
|
118
|
+
"media.get",
|
|
119
|
+
"blob.get",
|
|
120
|
+
"artifacts.view",
|
|
121
|
+
"skill.file",
|
|
122
|
+
"pty.connect",
|
|
123
|
+
"persistentPty.connect",
|
|
124
|
+
"mcp.client",
|
|
125
|
+
"machine.link",
|
|
126
|
+
"generate.textLegacy",
|
|
127
|
+
])
|