@zyro-sec/protocol 0.0.0-stage → 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/openapi.json +33222 -0
- package/package.json +33 -4
- 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/README.md +0 -3
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Session } from "@zyro-sec/schema/session"
|
|
2
|
+
import { SessionMessage } from "@zyro-sec/schema/session-message"
|
|
3
|
+
import { Location } from "@zyro-sec/schema/location"
|
|
4
|
+
import { Schema, Struct } from "effect"
|
|
5
|
+
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
|
|
6
|
+
import { InvalidCursorError, SessionNotFoundError, UnknownError } from "../errors.js"
|
|
7
|
+
|
|
8
|
+
// Keyed by message type so a new message type cannot be left out of the filter.
|
|
9
|
+
const MessageTypes = {
|
|
10
|
+
"agent-switched": true,
|
|
11
|
+
"model-switched": true,
|
|
12
|
+
"location-switched": true,
|
|
13
|
+
user: true,
|
|
14
|
+
synthetic: true,
|
|
15
|
+
system: true,
|
|
16
|
+
skill: true,
|
|
17
|
+
shell: true,
|
|
18
|
+
assistant: true,
|
|
19
|
+
compaction: true,
|
|
20
|
+
idle: true,
|
|
21
|
+
} satisfies Record<SessionMessage.Type, true>
|
|
22
|
+
|
|
23
|
+
export const SessionMessagesQuery = Schema.Struct({
|
|
24
|
+
limit: Schema.optional(
|
|
25
|
+
Schema.NumberFromString.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(1), Schema.isLessThanOrEqualTo(200)),
|
|
26
|
+
).annotate({
|
|
27
|
+
description: "Maximum number of messages to return. When omitted, the endpoint returns its default page size.",
|
|
28
|
+
}),
|
|
29
|
+
order: Schema.optional(Schema.Union([Schema.Literal("asc"), Schema.Literal("desc")])).annotate({
|
|
30
|
+
description: "Message order for the first page. Use desc for newest first or asc for oldest first.",
|
|
31
|
+
}),
|
|
32
|
+
cursor: Schema.optional(
|
|
33
|
+
Schema.String.annotate({
|
|
34
|
+
description:
|
|
35
|
+
"Opaque pagination cursor returned as cursor.previous or cursor.next in the previous response. Do not combine with order.",
|
|
36
|
+
}),
|
|
37
|
+
),
|
|
38
|
+
type: Schema.optional(Schema.Literals(Object.keys(MessageTypes) as ReadonlyArray<SessionMessage.Type>)).annotate({
|
|
39
|
+
description:
|
|
40
|
+
"Filter by message type before pagination. When omitted, all message types are returned. Pass the same type when following cursors.",
|
|
41
|
+
}),
|
|
42
|
+
}).annotate({ identifier: "SessionMessagesQuery" })
|
|
43
|
+
|
|
44
|
+
const PublicLocationSwitched = Schema.Struct({
|
|
45
|
+
...Struct.omit(SessionMessage.LocationSwitched.fields, ["location", "previous"]),
|
|
46
|
+
location: Location.PublicRef,
|
|
47
|
+
previous: Schema.Struct({
|
|
48
|
+
location: Location.PublicRef,
|
|
49
|
+
projectID: SessionMessage.LocationSwitched.fields.projectID,
|
|
50
|
+
subpath: SessionMessage.LocationSwitched.fields.subpath,
|
|
51
|
+
}).pipe(Schema.optional),
|
|
52
|
+
}).annotate({ identifier: "Session.Message.LocationSwitched" })
|
|
53
|
+
|
|
54
|
+
export const PublicSessionMessage = Schema.Union([
|
|
55
|
+
SessionMessage.AgentSelected,
|
|
56
|
+
SessionMessage.ModelSelected,
|
|
57
|
+
PublicLocationSwitched,
|
|
58
|
+
SessionMessage.User,
|
|
59
|
+
SessionMessage.Synthetic,
|
|
60
|
+
SessionMessage.System,
|
|
61
|
+
SessionMessage.Skill,
|
|
62
|
+
SessionMessage.Shell,
|
|
63
|
+
SessionMessage.Assistant,
|
|
64
|
+
SessionMessage.Compaction,
|
|
65
|
+
SessionMessage.Idle,
|
|
66
|
+
]).annotate({ identifier: "Session.Message.Info" })
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Experimental: {@link PublicSessionMessage} as sent to clients that opt in with `X-OpenCode-Capabilities:
|
|
70
|
+
* experimental-media-uri` while `experimental.media_blob` is on. User files stored in `blob` stay `media:` refs.
|
|
71
|
+
*/
|
|
72
|
+
export const PublicMediaSessionMessage = Schema.Union([
|
|
73
|
+
SessionMessage.AgentSelected,
|
|
74
|
+
SessionMessage.ModelSelected,
|
|
75
|
+
PublicLocationSwitched,
|
|
76
|
+
SessionMessage.MediaUser,
|
|
77
|
+
SessionMessage.Synthetic,
|
|
78
|
+
SessionMessage.System,
|
|
79
|
+
SessionMessage.Skill,
|
|
80
|
+
SessionMessage.Shell,
|
|
81
|
+
SessionMessage.Assistant,
|
|
82
|
+
SessionMessage.Compaction,
|
|
83
|
+
SessionMessage.Idle,
|
|
84
|
+
]).annotate({ identifier: "Session.Message.MediaInfo" })
|
|
85
|
+
|
|
86
|
+
const MessagesCursor = Schema.Struct({
|
|
87
|
+
previous: Schema.String.pipe(Schema.optional),
|
|
88
|
+
next: Schema.String.pipe(Schema.optional),
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
/** Experimental: the `session.messages` response for clients that opt into `experimental-media-uri`. */
|
|
92
|
+
export const SessionMediaMessagesResponse = Schema.Struct({
|
|
93
|
+
data: Schema.Array(PublicMediaSessionMessage),
|
|
94
|
+
cursor: MessagesCursor,
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
/** Experimental: the `session.message` response for clients that opt into `experimental-media-uri`. */
|
|
98
|
+
export const SessionMediaMessageResponse = Schema.Struct({ data: PublicMediaSessionMessage })
|
|
99
|
+
|
|
100
|
+
export const MessageGroup = HttpApiGroup.make("server.message")
|
|
101
|
+
.add(
|
|
102
|
+
HttpApiEndpoint.get("session.messages", "/api/session/:sessionID/message", {
|
|
103
|
+
params: { sessionID: Session.ID },
|
|
104
|
+
query: SessionMessagesQuery,
|
|
105
|
+
success: Schema.Struct({
|
|
106
|
+
data: Schema.Array(PublicSessionMessage),
|
|
107
|
+
cursor: MessagesCursor,
|
|
108
|
+
}).annotate({ identifier: "SessionMessagesResponse" }),
|
|
109
|
+
error: [InvalidCursorError, SessionNotFoundError, UnknownError],
|
|
110
|
+
}).annotateMerge(
|
|
111
|
+
OpenApi.annotations({
|
|
112
|
+
identifier: "session.message.list",
|
|
113
|
+
summary: "Get session messages",
|
|
114
|
+
description:
|
|
115
|
+
"List a session's messages, optionally filtered by type. Follow cursor.next or cursor.previous with the same type filter. Items still in the inbox aren't included.",
|
|
116
|
+
}),
|
|
117
|
+
),
|
|
118
|
+
)
|
|
119
|
+
.annotateMerge(
|
|
120
|
+
OpenApi.annotations({
|
|
121
|
+
title: "session",
|
|
122
|
+
description: "Experimental message routes.",
|
|
123
|
+
}),
|
|
124
|
+
)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
|
|
3
|
+
|
|
4
|
+
const V1MigrationProgress = Schema.Struct({
|
|
5
|
+
label: Schema.String,
|
|
6
|
+
numerator: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
|
|
7
|
+
denominator: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export const V1MigrationStatus = Schema.Union([
|
|
11
|
+
Schema.Struct({ status: Schema.Literals(["required", "completed"]) }),
|
|
12
|
+
Schema.Struct({ status: Schema.Literal("running"), progress: V1MigrationProgress }),
|
|
13
|
+
Schema.Struct({ status: Schema.Literal("error"), error: Schema.String }),
|
|
14
|
+
])
|
|
15
|
+
|
|
16
|
+
export const MigrationGroup = HttpApiGroup.make("server.migration")
|
|
17
|
+
.add(
|
|
18
|
+
HttpApiEndpoint.get("migration.v1.status", "/api/experimental/migration/v1", {
|
|
19
|
+
success: V1MigrationStatus,
|
|
20
|
+
}).annotateMerge(
|
|
21
|
+
OpenApi.annotations({
|
|
22
|
+
identifier: "experimental.migration.v1.status",
|
|
23
|
+
summary: "Get V1 migration status",
|
|
24
|
+
description: "Return the progress of the V1 to V2 session history migration.",
|
|
25
|
+
}),
|
|
26
|
+
),
|
|
27
|
+
)
|
|
28
|
+
.annotateMerge(OpenApi.annotations({ title: "migration" }))
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Model } from "@zyro-sec/schema/model"
|
|
2
|
+
import { Location } from "@zyro-sec/schema/location"
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
|
|
5
|
+
import { ServiceUnavailableError } from "../errors.js"
|
|
6
|
+
import { LocationQuery, locationQueryOpenApi } from "./location.js"
|
|
7
|
+
|
|
8
|
+
const ListQuery = Schema.Struct({
|
|
9
|
+
...LocationQuery.fields,
|
|
10
|
+
types: Schema.optional(Schema.ArrayEnsure(Model.Type)).annotate({
|
|
11
|
+
description: "Only list models of these types. Defaults to chat, the only type offered for sessions.",
|
|
12
|
+
}),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export const ModelGroup = HttpApiGroup.make("server.model")
|
|
16
|
+
.add(
|
|
17
|
+
HttpApiEndpoint.get("model.list", "/api/model", {
|
|
18
|
+
query: ListQuery,
|
|
19
|
+
success: Location.response(Schema.Array(Model.Info)),
|
|
20
|
+
error: ServiceUnavailableError,
|
|
21
|
+
})
|
|
22
|
+
.annotateMerge(locationQueryOpenApi)
|
|
23
|
+
.annotateMerge(
|
|
24
|
+
OpenApi.annotations({
|
|
25
|
+
identifier: "model.list",
|
|
26
|
+
summary: "List models",
|
|
27
|
+
description:
|
|
28
|
+
"Retrieve the current snapshot of available models of the requested types, chat by default, ordered by release date within each type. The snapshot may precede initial plugin settlement.",
|
|
29
|
+
}),
|
|
30
|
+
),
|
|
31
|
+
)
|
|
32
|
+
.add(
|
|
33
|
+
HttpApiEndpoint.get("model.default", "/api/model/default", {
|
|
34
|
+
query: LocationQuery,
|
|
35
|
+
success: Location.response(Schema.UndefinedOr(Model.Info)),
|
|
36
|
+
error: ServiceUnavailableError,
|
|
37
|
+
})
|
|
38
|
+
.annotateMerge(locationQueryOpenApi)
|
|
39
|
+
.annotateMerge(
|
|
40
|
+
OpenApi.annotations({
|
|
41
|
+
identifier: "model.default",
|
|
42
|
+
summary: "Get default model",
|
|
43
|
+
description: "Retrieve the model used when a session has no explicit model selection.",
|
|
44
|
+
}),
|
|
45
|
+
),
|
|
46
|
+
)
|
|
47
|
+
.annotateMerge(
|
|
48
|
+
OpenApi.annotations({
|
|
49
|
+
title: "model",
|
|
50
|
+
description: "Experimental model routes.",
|
|
51
|
+
}),
|
|
52
|
+
)
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Agent } from "@zyro-sec/schema/agent"
|
|
2
|
+
import { Location } from "@zyro-sec/schema/location"
|
|
3
|
+
import { Permission } from "@zyro-sec/schema/permission"
|
|
4
|
+
import { PermissionSaved } from "@zyro-sec/schema/permission-saved"
|
|
5
|
+
import { Project } from "@zyro-sec/schema/project"
|
|
6
|
+
import { Session } from "@zyro-sec/schema/session"
|
|
7
|
+
import { Context, Schema } from "effect"
|
|
8
|
+
import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSchema, OpenApi } from "effect/http-api"
|
|
9
|
+
import {
|
|
10
|
+
ConflictError,
|
|
11
|
+
LocationNotFoundError,
|
|
12
|
+
PermissionNotFoundError,
|
|
13
|
+
PermissionSavedNotFoundError,
|
|
14
|
+
SessionNotFoundError,
|
|
15
|
+
} from "../errors.js"
|
|
16
|
+
import { LocationQuery, locationQueryOpenApi } from "./location.js"
|
|
17
|
+
|
|
18
|
+
export const makePermissionGroup = <
|
|
19
|
+
LocationId extends HttpApiMiddleware.AnyId,
|
|
20
|
+
LocationService,
|
|
21
|
+
SessionLocationId extends HttpApiMiddleware.AnyId,
|
|
22
|
+
SessionLocationService,
|
|
23
|
+
>(
|
|
24
|
+
locationMiddleware: Context.Key<LocationId, LocationService>,
|
|
25
|
+
sessionLocationMiddleware: Context.Key<SessionLocationId, SessionLocationService>,
|
|
26
|
+
) =>
|
|
27
|
+
HttpApiGroup.make("server.permission")
|
|
28
|
+
.add(
|
|
29
|
+
HttpApiEndpoint.get("permission.request.list", "/api/permission/request", {
|
|
30
|
+
query: LocationQuery,
|
|
31
|
+
success: Location.response(Schema.Array(Permission.Request)),
|
|
32
|
+
})
|
|
33
|
+
.middleware(locationMiddleware)
|
|
34
|
+
.annotateMerge(locationQueryOpenApi)
|
|
35
|
+
.annotateMerge(
|
|
36
|
+
OpenApi.annotations({
|
|
37
|
+
identifier: "permission.request.list",
|
|
38
|
+
summary: "List pending permission requests",
|
|
39
|
+
description: "Retrieve pending permission requests for a location.",
|
|
40
|
+
}),
|
|
41
|
+
),
|
|
42
|
+
)
|
|
43
|
+
.add(
|
|
44
|
+
HttpApiEndpoint.get("permission.saved.list", "/api/permission/saved", {
|
|
45
|
+
query: Schema.Struct({
|
|
46
|
+
projectID: Project.ID.pipe(Schema.optional).annotateKey({
|
|
47
|
+
description: "Project whose saved permissions to list. Defaults to the project of the requested location.",
|
|
48
|
+
}),
|
|
49
|
+
}),
|
|
50
|
+
success: Schema.Struct({ data: Schema.Array(PermissionSaved.Info) }),
|
|
51
|
+
})
|
|
52
|
+
.middleware(locationMiddleware)
|
|
53
|
+
.annotateMerge(
|
|
54
|
+
OpenApi.annotations({
|
|
55
|
+
identifier: "permission.saved.list",
|
|
56
|
+
summary: "List saved permissions",
|
|
57
|
+
description: "Retrieve saved permissions, optionally filtered by project.",
|
|
58
|
+
}),
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
.add(
|
|
62
|
+
HttpApiEndpoint.patch("permission.saved.update", "/api/permission/saved/:id", {
|
|
63
|
+
params: { id: PermissionSaved.ID },
|
|
64
|
+
payload: Schema.Struct({
|
|
65
|
+
action: Schema.String.pipe(Schema.optional),
|
|
66
|
+
resource: Schema.String.pipe(Schema.optional),
|
|
67
|
+
}),
|
|
68
|
+
success: Schema.Struct({ data: PermissionSaved.Info }),
|
|
69
|
+
error: [PermissionSavedNotFoundError, ConflictError],
|
|
70
|
+
}).annotateMerge(
|
|
71
|
+
OpenApi.annotations({
|
|
72
|
+
identifier: "permission.saved.update",
|
|
73
|
+
summary: "Update saved permission",
|
|
74
|
+
description:
|
|
75
|
+
"Change the action or resource of a saved permission. Fails with a conflict when the project already has a saved permission with the same action and resource.",
|
|
76
|
+
}),
|
|
77
|
+
),
|
|
78
|
+
)
|
|
79
|
+
.add(
|
|
80
|
+
HttpApiEndpoint.delete("permission.saved.remove", "/api/permission/saved/:id", {
|
|
81
|
+
params: { id: PermissionSaved.ID },
|
|
82
|
+
success: HttpApiSchema.NoContent,
|
|
83
|
+
}).annotateMerge(
|
|
84
|
+
OpenApi.annotations({
|
|
85
|
+
identifier: "permission.saved.remove",
|
|
86
|
+
summary: "Remove saved permission",
|
|
87
|
+
description: "Remove a saved permission by ID.",
|
|
88
|
+
}),
|
|
89
|
+
),
|
|
90
|
+
)
|
|
91
|
+
.add(
|
|
92
|
+
HttpApiEndpoint.post("session.permission.create", "/api/session/:sessionID/permission", {
|
|
93
|
+
params: { sessionID: Session.ID },
|
|
94
|
+
payload: Schema.Struct({
|
|
95
|
+
id: Permission.ID.pipe(Schema.optional),
|
|
96
|
+
action: Permission.Request.fields.action,
|
|
97
|
+
resources: Permission.Request.fields.resources,
|
|
98
|
+
save: Permission.Request.fields.save,
|
|
99
|
+
metadata: Permission.Request.fields.metadata,
|
|
100
|
+
source: Permission.Request.fields.source,
|
|
101
|
+
agent: Agent.ID.pipe(Schema.optional),
|
|
102
|
+
}),
|
|
103
|
+
success: Schema.Struct({
|
|
104
|
+
data: Schema.Struct({ id: Permission.ID, effect: Permission.Effect }),
|
|
105
|
+
}),
|
|
106
|
+
error: SessionNotFoundError,
|
|
107
|
+
})
|
|
108
|
+
.middleware(sessionLocationMiddleware)
|
|
109
|
+
.annotateMerge(
|
|
110
|
+
OpenApi.annotations({
|
|
111
|
+
identifier: "session.permission.create",
|
|
112
|
+
summary: "Create permission request",
|
|
113
|
+
description: "Evaluate and, when approval is required, create a permission request for a session.",
|
|
114
|
+
}),
|
|
115
|
+
),
|
|
116
|
+
)
|
|
117
|
+
.add(
|
|
118
|
+
HttpApiEndpoint.get("session.permission.list", "/api/session/:sessionID/permission", {
|
|
119
|
+
params: { sessionID: Session.ID },
|
|
120
|
+
success: Schema.Struct({ data: Schema.Array(Permission.Request) }),
|
|
121
|
+
error: [SessionNotFoundError, LocationNotFoundError],
|
|
122
|
+
}).annotateMerge(
|
|
123
|
+
OpenApi.annotations({
|
|
124
|
+
identifier: "session.permission.list",
|
|
125
|
+
summary: "List session permission requests",
|
|
126
|
+
description: "Retrieve pending permission requests owned by a session.",
|
|
127
|
+
}),
|
|
128
|
+
),
|
|
129
|
+
)
|
|
130
|
+
.add(
|
|
131
|
+
HttpApiEndpoint.get("session.permission.get", "/api/session/:sessionID/permission/:requestID", {
|
|
132
|
+
params: { sessionID: Session.ID, requestID: Permission.ID },
|
|
133
|
+
success: Schema.Struct({ data: Permission.Request }),
|
|
134
|
+
error: [SessionNotFoundError, PermissionNotFoundError],
|
|
135
|
+
})
|
|
136
|
+
.middleware(sessionLocationMiddleware)
|
|
137
|
+
.annotateMerge(
|
|
138
|
+
OpenApi.annotations({
|
|
139
|
+
identifier: "session.permission.get",
|
|
140
|
+
summary: "Get permission request",
|
|
141
|
+
description: "Retrieve a pending permission request owned by a session.",
|
|
142
|
+
}),
|
|
143
|
+
),
|
|
144
|
+
)
|
|
145
|
+
.add(
|
|
146
|
+
HttpApiEndpoint.post("session.permission.reply", "/api/session/:sessionID/permission/:requestID/reply", {
|
|
147
|
+
params: { sessionID: Session.ID, requestID: Permission.ID },
|
|
148
|
+
payload: Schema.Struct({
|
|
149
|
+
decision: Permission.Reply,
|
|
150
|
+
message: Schema.String.pipe(Schema.optional),
|
|
151
|
+
}),
|
|
152
|
+
success: HttpApiSchema.NoContent,
|
|
153
|
+
error: [SessionNotFoundError, PermissionNotFoundError],
|
|
154
|
+
})
|
|
155
|
+
.middleware(sessionLocationMiddleware)
|
|
156
|
+
.annotateMerge(
|
|
157
|
+
OpenApi.annotations({
|
|
158
|
+
identifier: "session.permission.reply",
|
|
159
|
+
summary: "Reply to pending permission request",
|
|
160
|
+
description: "Respond to a pending permission request owned by a session.",
|
|
161
|
+
}),
|
|
162
|
+
),
|
|
163
|
+
)
|
|
164
|
+
.annotateMerge(OpenApi.annotations({ title: "permission", description: "Experimental permission routes." }))
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { PersistentPty } from "@zyro-sec/schema/persistent-pty"
|
|
2
|
+
import { Pty } from "@zyro-sec/schema/pty"
|
|
3
|
+
import { PtyTicket } from "@zyro-sec/schema/pty-ticket"
|
|
4
|
+
import { Session } from "@zyro-sec/schema/session"
|
|
5
|
+
import { Schema } from "effect"
|
|
6
|
+
import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/http-api"
|
|
7
|
+
import {
|
|
8
|
+
ForbiddenError,
|
|
9
|
+
InvalidRequestError,
|
|
10
|
+
PtyFeatureUnsupportedError,
|
|
11
|
+
PtyNotFoundError,
|
|
12
|
+
ServiceUnavailableError,
|
|
13
|
+
} from "../errors.js"
|
|
14
|
+
import { PTY_CONNECT_TICKET_QUERY, PTY_CONNECT_TOKEN_HEADER, PTY_CONNECT_TOKEN_HEADER_VALUE } from "./pty.js"
|
|
15
|
+
|
|
16
|
+
export { PTY_CONNECT_TICKET_QUERY, PTY_CONNECT_TOKEN_HEADER, PTY_CONNECT_TOKEN_HEADER_VALUE }
|
|
17
|
+
|
|
18
|
+
export const PERSISTENT_PTY_CONNECT_PATH = "/api/experimental/persistent-pty/:ptyID/connect"
|
|
19
|
+
|
|
20
|
+
const PERSISTENT_PTY_CONNECT_URL = /^\/api\/experimental\/persistent-pty\/[^/]+\/connect$/
|
|
21
|
+
|
|
22
|
+
export function hasPersistentPtyConnectTicketURL(url: URL) {
|
|
23
|
+
return PERSISTENT_PTY_CONNECT_URL.test(url.pathname) && !!url.searchParams.get(PTY_CONNECT_TICKET_QUERY)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const errors = [InvalidRequestError, ServiceUnavailableError] as const
|
|
27
|
+
const terminalErrors = [PtyNotFoundError, ServiceUnavailableError] as const
|
|
28
|
+
|
|
29
|
+
export const PersistentPtyGroup = HttpApiGroup.make("server.experimental")
|
|
30
|
+
.add(
|
|
31
|
+
HttpApiEndpoint.get("persistentPty.read", "/api/experimental/session/:sessionID/terminal/read", {
|
|
32
|
+
params: { sessionID: Session.ID },
|
|
33
|
+
query: {
|
|
34
|
+
lines: Schema.NumberFromString.pipe(Schema.decodeTo(PersistentPty.ReadLines), Schema.optional).annotateKey({
|
|
35
|
+
description:
|
|
36
|
+
"Number of trailing rows to read, up to 65535. Defaults to the live terminal height; larger counts include retained history.",
|
|
37
|
+
}),
|
|
38
|
+
},
|
|
39
|
+
success: Schema.Struct({ data: Schema.NullOr(PersistentPty.ReadResult) }),
|
|
40
|
+
error: [ServiceUnavailableError],
|
|
41
|
+
}).annotateMerge(
|
|
42
|
+
OpenApi.annotations({
|
|
43
|
+
identifier: "experimental.persistentPty.read",
|
|
44
|
+
summary: "Read the session's most recently controlled terminal",
|
|
45
|
+
description:
|
|
46
|
+
"Read the last physical rows without changing selection or taking control. Omitted lines uses the live terminal height; larger counts include retained history. Blank rows are preserved. Screen dimensions and cursor remain relative to the live screen. Returns null when no current terminal exists. Selection is server-local and resets on restart. Experimental: may change without compatibility guarantees.",
|
|
47
|
+
}),
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
.add(
|
|
51
|
+
HttpApiEndpoint.get("persistentPty.list", "/api/experimental/session/:sessionID/terminal", {
|
|
52
|
+
params: { sessionID: Session.ID },
|
|
53
|
+
success: Schema.Struct({ data: Schema.Array(PersistentPty.Info) }),
|
|
54
|
+
error: errors,
|
|
55
|
+
}).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.list" })),
|
|
56
|
+
)
|
|
57
|
+
.add(
|
|
58
|
+
HttpApiEndpoint.post("persistentPty.create", "/api/experimental/session/:sessionID/terminal", {
|
|
59
|
+
params: { sessionID: Session.ID },
|
|
60
|
+
payload: PersistentPty.CreateInput,
|
|
61
|
+
success: Schema.Struct({ data: PersistentPty.Info }),
|
|
62
|
+
error: errors,
|
|
63
|
+
}).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.create" })),
|
|
64
|
+
)
|
|
65
|
+
.add(
|
|
66
|
+
HttpApiEndpoint.post("persistentPty.shutdown", "/api/experimental/persistent-pty/shutdown", {
|
|
67
|
+
success: HttpApiSchema.NoContent,
|
|
68
|
+
error: [ServiceUnavailableError],
|
|
69
|
+
}).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.shutdown" })),
|
|
70
|
+
)
|
|
71
|
+
.add(
|
|
72
|
+
HttpApiEndpoint.post("persistentPty.handoff", "/api/experimental/persistent-pty/handoff", {
|
|
73
|
+
success: Schema.Struct({ handoff: Schema.NullOr(PersistentPty.Handoff) }),
|
|
74
|
+
error: [ServiceUnavailableError],
|
|
75
|
+
}).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.handoff" })),
|
|
76
|
+
)
|
|
77
|
+
.add(
|
|
78
|
+
HttpApiEndpoint.get("persistentPty.get", "/api/experimental/persistent-pty/:ptyID", {
|
|
79
|
+
params: { ptyID: Pty.ID },
|
|
80
|
+
success: Schema.Struct({ data: PersistentPty.Info }),
|
|
81
|
+
error: terminalErrors,
|
|
82
|
+
}).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.get" })),
|
|
83
|
+
)
|
|
84
|
+
.add(
|
|
85
|
+
HttpApiEndpoint.put("persistentPty.update", "/api/experimental/persistent-pty/:ptyID", {
|
|
86
|
+
params: { ptyID: Pty.ID },
|
|
87
|
+
payload: PersistentPty.UpdateInput,
|
|
88
|
+
success: Schema.Struct({ data: PersistentPty.Info }),
|
|
89
|
+
error: [...terminalErrors, PtyFeatureUnsupportedError],
|
|
90
|
+
}).annotateMerge(
|
|
91
|
+
OpenApi.annotations({
|
|
92
|
+
identifier: "experimental.persistentPty.update",
|
|
93
|
+
description:
|
|
94
|
+
"Resize when size is present and rename when title is present; a null title clears the user title so the shell's title shows again. Renaming fails with 501 while the terminal service predates renaming.",
|
|
95
|
+
}),
|
|
96
|
+
),
|
|
97
|
+
)
|
|
98
|
+
.add(
|
|
99
|
+
HttpApiEndpoint.get("persistentPty.snapshot", "/api/experimental/persistent-pty/:ptyID/snapshot", {
|
|
100
|
+
params: { ptyID: Pty.ID },
|
|
101
|
+
success: Schema.Struct({ data: PersistentPty.Snapshot }),
|
|
102
|
+
error: terminalErrors,
|
|
103
|
+
}).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.snapshot" })),
|
|
104
|
+
)
|
|
105
|
+
.add(
|
|
106
|
+
HttpApiEndpoint.delete("persistentPty.remove", "/api/experimental/persistent-pty/:ptyID", {
|
|
107
|
+
params: { ptyID: Pty.ID },
|
|
108
|
+
success: HttpApiSchema.NoContent,
|
|
109
|
+
error: terminalErrors,
|
|
110
|
+
}).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.remove" })),
|
|
111
|
+
)
|
|
112
|
+
.add(
|
|
113
|
+
HttpApiEndpoint.post("persistentPty.connectToken", "/api/experimental/persistent-pty/:ptyID/connect-token", {
|
|
114
|
+
params: { ptyID: Pty.ID },
|
|
115
|
+
headers: Schema.Struct({
|
|
116
|
+
[PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String).annotateKey({
|
|
117
|
+
description: `Must be ${PTY_CONNECT_TOKEN_HEADER_VALUE}; requests without it are refused.`,
|
|
118
|
+
}),
|
|
119
|
+
}),
|
|
120
|
+
success: Schema.Struct({ data: PtyTicket.ConnectToken }),
|
|
121
|
+
error: [ForbiddenError, PtyNotFoundError, ServiceUnavailableError],
|
|
122
|
+
}).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.connectToken" })),
|
|
123
|
+
)
|
|
124
|
+
.add(
|
|
125
|
+
HttpApiEndpoint.get("persistentPty.connect", PERSISTENT_PTY_CONNECT_PATH, {
|
|
126
|
+
params: { ptyID: Pty.ID },
|
|
127
|
+
success: Schema.Boolean,
|
|
128
|
+
error: [ForbiddenError, PtyNotFoundError, ServiceUnavailableError],
|
|
129
|
+
}).annotateMerge(
|
|
130
|
+
OpenApi.annotations({
|
|
131
|
+
identifier: "experimental.persistentPty.connect",
|
|
132
|
+
summary: "Connect to a persistent PTY",
|
|
133
|
+
description: "Stream persistent PTY output through the OpenCode server.",
|
|
134
|
+
transform: (operation) => ({
|
|
135
|
+
...operation,
|
|
136
|
+
"x-websocket": true,
|
|
137
|
+
parameters: [
|
|
138
|
+
...(operation.parameters ?? []),
|
|
139
|
+
{ in: "query", name: "attachment_id", schema: { type: "string" } },
|
|
140
|
+
...Object.entries({
|
|
141
|
+
cursor: "Output offset to replay from. Defaults to 0.",
|
|
142
|
+
role: "Attach as controller (the default) or observer.",
|
|
143
|
+
takeover: "Set to true to take over control of the terminal.",
|
|
144
|
+
input_protocol: "Set to 1 to send framed input messages instead of raw terminal input.",
|
|
145
|
+
[PTY_CONNECT_TICKET_QUERY]:
|
|
146
|
+
"Single-use ticket from experimental.persistentPty.connectToken, which authorizes the connection without the usual credentials.",
|
|
147
|
+
}).map(([name, description]) => ({ in: "query", name, description, schema: { type: "string" } })),
|
|
148
|
+
],
|
|
149
|
+
}),
|
|
150
|
+
}),
|
|
151
|
+
),
|
|
152
|
+
)
|
|
153
|
+
.annotateMerge(OpenApi.annotations({ title: "persistentPty", description: "Prototype persistent PTY routes." }))
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Location } from "@zyro-sec/schema/location"
|
|
2
|
+
import { Plugin } from "@zyro-sec/schema/plugin"
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/http-api"
|
|
5
|
+
import { InvalidRequestError, PluginNotFoundError, ServiceUnavailableError } from "../errors.js"
|
|
6
|
+
import { LocationQuery, locationQueryOpenApi } from "./location.js"
|
|
7
|
+
|
|
8
|
+
export const PluginGroup = HttpApiGroup.make("server.plugin")
|
|
9
|
+
.add(
|
|
10
|
+
HttpApiEndpoint.get("plugin.list", "/api/plugin", {
|
|
11
|
+
query: LocationQuery,
|
|
12
|
+
success: Location.response(Schema.Array(Plugin.Info)),
|
|
13
|
+
})
|
|
14
|
+
.annotateMerge(locationQueryOpenApi)
|
|
15
|
+
.annotateMerge(
|
|
16
|
+
OpenApi.annotations({
|
|
17
|
+
identifier: "plugin.list",
|
|
18
|
+
summary: "List plugins",
|
|
19
|
+
description: "Retrieve enabled server plugins and their current status.",
|
|
20
|
+
}),
|
|
21
|
+
),
|
|
22
|
+
)
|
|
23
|
+
.add(
|
|
24
|
+
HttpApiEndpoint.get("plugin.gui", "/api/plugin/gui", {
|
|
25
|
+
query: Schema.Struct({
|
|
26
|
+
...LocationQuery.fields,
|
|
27
|
+
id: Plugin.ID,
|
|
28
|
+
}),
|
|
29
|
+
success: Location.response(Plugin.GuiBundle),
|
|
30
|
+
error: PluginNotFoundError,
|
|
31
|
+
})
|
|
32
|
+
.annotateMerge(locationQueryOpenApi)
|
|
33
|
+
.annotateMerge(
|
|
34
|
+
OpenApi.annotations({
|
|
35
|
+
identifier: "plugin.gui",
|
|
36
|
+
summary: "Read plugin GUI bundle",
|
|
37
|
+
description:
|
|
38
|
+
"Read an active plugin's prebuilt CommonJS `./gui-experimental` bundle. Desktop app windows run its default export; the desktop app's main process runs its `main` export. Fails with not found when no active plugin has the id or the plugin exports no `./gui-experimental`.",
|
|
39
|
+
}),
|
|
40
|
+
),
|
|
41
|
+
)
|
|
42
|
+
.add(
|
|
43
|
+
HttpApiEndpoint.post("plugin.check", "/api/plugin/check", {
|
|
44
|
+
query: LocationQuery,
|
|
45
|
+
payload: Schema.Struct({ target: Schema.String.pipe(Schema.optional) }),
|
|
46
|
+
success: Location.response(Schema.Array(Plugin.Info)),
|
|
47
|
+
error: InvalidRequestError,
|
|
48
|
+
})
|
|
49
|
+
.annotateMerge(locationQueryOpenApi)
|
|
50
|
+
.annotateMerge(
|
|
51
|
+
OpenApi.annotations({
|
|
52
|
+
identifier: "plugin.check",
|
|
53
|
+
summary: "Check plugin updates",
|
|
54
|
+
description: "Check one or all package plugins for available updates.",
|
|
55
|
+
}),
|
|
56
|
+
),
|
|
57
|
+
)
|
|
58
|
+
.add(
|
|
59
|
+
HttpApiEndpoint.post("plugin.update", "/api/plugin/update", {
|
|
60
|
+
query: LocationQuery,
|
|
61
|
+
payload: Schema.Struct({ targets: Schema.Array(Schema.String) }),
|
|
62
|
+
success: HttpApiSchema.NoContent,
|
|
63
|
+
error: [InvalidRequestError, ServiceUnavailableError],
|
|
64
|
+
})
|
|
65
|
+
.annotateMerge(locationQueryOpenApi)
|
|
66
|
+
.annotateMerge(
|
|
67
|
+
OpenApi.annotations({
|
|
68
|
+
identifier: "plugin.update",
|
|
69
|
+
summary: "Update plugins",
|
|
70
|
+
description:
|
|
71
|
+
"Update package plugins concurrently and notify active locations to reload them. Responds once every update has finished; fails when any update fails.",
|
|
72
|
+
}),
|
|
73
|
+
),
|
|
74
|
+
)
|
|
75
|
+
.annotateMerge(
|
|
76
|
+
OpenApi.annotations({
|
|
77
|
+
title: "plugin",
|
|
78
|
+
description: "Experimental plugin routes.",
|
|
79
|
+
}),
|
|
80
|
+
)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Project } from "@zyro-sec/schema/project"
|
|
2
|
+
import { Schema, SchemaGetter, Struct } from "effect"
|
|
3
|
+
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
|
|
4
|
+
import { ProjectNotFoundError } from "../errors.js"
|
|
5
|
+
|
|
6
|
+
const root = "/api/project"
|
|
7
|
+
const UpdatePayload = Schema.Struct(Struct.omit(Project.UpdateInput.fields, ["projectID"]))
|
|
8
|
+
const BooleanFromString = Schema.Literals(["true", "false"]).pipe(
|
|
9
|
+
Schema.decodeTo(Schema.Boolean, {
|
|
10
|
+
decode: SchemaGetter.transform((value) => value === "true"),
|
|
11
|
+
encode: SchemaGetter.transform((value): "true" | "false" => (value ? "true" : "false")),
|
|
12
|
+
}),
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
export const ProjectGroup = HttpApiGroup.make("server.project")
|
|
16
|
+
.add(
|
|
17
|
+
HttpApiEndpoint.get("project.list", root, {
|
|
18
|
+
query: Schema.Struct({
|
|
19
|
+
archived: BooleanFromString.pipe(Schema.optional).annotateKey({
|
|
20
|
+
description: "Set to true to include archived projects.",
|
|
21
|
+
}),
|
|
22
|
+
}),
|
|
23
|
+
success: Schema.Array(Project.Info),
|
|
24
|
+
}).annotateMerge(
|
|
25
|
+
OpenApi.annotations({
|
|
26
|
+
identifier: "project.list",
|
|
27
|
+
summary: "List projects",
|
|
28
|
+
description: "List known projects. Archived projects are excluded unless archived=true.",
|
|
29
|
+
}),
|
|
30
|
+
),
|
|
31
|
+
)
|
|
32
|
+
.add(
|
|
33
|
+
HttpApiEndpoint.patch("project.update", `${root}/:projectID`, {
|
|
34
|
+
params: { projectID: Project.ID },
|
|
35
|
+
payload: UpdatePayload,
|
|
36
|
+
success: Project.Info,
|
|
37
|
+
error: ProjectNotFoundError,
|
|
38
|
+
}).annotateMerge(
|
|
39
|
+
OpenApi.annotations({
|
|
40
|
+
identifier: "project.update",
|
|
41
|
+
summary: "Update project",
|
|
42
|
+
description: "Update the project canonical directory, display metadata, and workspace commands.",
|
|
43
|
+
}),
|
|
44
|
+
),
|
|
45
|
+
)
|
|
46
|
+
.annotateMerge(
|
|
47
|
+
OpenApi.annotations({
|
|
48
|
+
title: "project",
|
|
49
|
+
description: "Project routes.",
|
|
50
|
+
}),
|
|
51
|
+
)
|