@zyro-sec/server 1.0.2 → 1.0.4
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/package.json +8 -8
- package/script/build.ts +28 -28
- package/script/pack.ts +5 -5
- package/script/workerd-probe.ts +59 -59
- package/src/api.ts +12 -12
- package/src/auth.ts +70 -70
- package/src/content-headers.ts +32 -32
- package/src/cors.ts +34 -34
- package/src/event-feed.ts +93 -93
- package/src/fetch.ts +67 -67
- package/src/handlers/agent.ts +23 -23
- package/src/handlers/artifact.ts +242 -242
- package/src/handlers/automation.ts +63 -63
- package/src/handlers/blob.ts +55 -55
- package/src/handlers/command.ts +8 -8
- package/src/handlers/config.ts +26 -26
- package/src/handlers/credential.ts +87 -87
- package/src/handlers/debug.ts +57 -57
- package/src/handlers/event.ts +38 -38
- package/src/handlers/form.ts +15 -15
- package/src/handlers/fs.ts +180 -180
- package/src/handlers/generate.ts +117 -117
- package/src/handlers/integration.ts +310 -310
- package/src/handlers/job.ts +29 -29
- package/src/handlers/location.ts +33 -33
- package/src/handlers/machine.ts +336 -336
- package/src/handlers/mcp.ts +160 -160
- package/src/handlers/media.ts +44 -44
- package/src/handlers/message.ts +82 -82
- package/src/handlers/migration.ts +13 -13
- package/src/handlers/model.ts +25 -25
- package/src/handlers/permission.ts +131 -131
- package/src/handlers/persistent-pty.ts +285 -285
- package/src/handlers/plugin.ts +97 -97
- package/src/handlers/project.ts +23 -23
- package/src/handlers/provider.ts +32 -32
- package/src/handlers/pty-socket.ts +47 -47
- package/src/handlers/pty.ts +181 -181
- package/src/handlers/push.ts +67 -67
- package/src/handlers/reference.ts +8 -8
- package/src/handlers/rpc.ts +31 -31
- package/src/handlers/server.ts +58 -58
- package/src/handlers/session-error.ts +47 -47
- package/src/handlers/session.ts +722 -722
- package/src/handlers/shell.ts +72 -72
- package/src/handlers/skill.ts +34 -34
- package/src/handlers/usage.ts +23 -23
- package/src/handlers/vcs.ts +104 -104
- package/src/handlers/voice.ts +50 -50
- package/src/handlers/websearch.ts +50 -50
- package/src/handlers/worktree.ts +60 -60
- package/src/handlers.ts +69 -69
- package/src/location.ts +86 -86
- package/src/media-uri.ts +13 -13
- package/src/middleware/authorization.ts +111 -111
- package/src/middleware/defect-response.ts +39 -39
- package/src/middleware/form-location.ts +44 -44
- package/src/middleware/schema-error.ts +49 -49
- package/src/middleware/session-location.ts +30 -30
- package/src/options.ts +61 -61
- package/src/pairing.ts +36 -36
- package/src/process.ts +274 -274
- package/src/range.ts +16 -16
- package/src/request-site.ts +36 -36
- package/src/request-tracing.ts +9 -9
- package/src/routes.ts +261 -261
- package/src/server-info.ts +41 -41
- package/src/service-status.ts +30 -30
- package/src/workerd.ts +184 -184
- package/test/fixture/mcp-starts.cjs +20 -20
- package/test/fixture/routes.ts +37 -37
- package/test/fixture/server.ts +20 -20
- package/test/fixture/worktree-delegate/index.ts +13 -13
- package/test/fixture/worktree-plugin/index.ts +47 -47
- package/tsconfig.build.json +15 -15
- package/tsconfig.json +11 -11
- package/test/artifact.test.ts +0 -224
- package/test/auth.test.ts +0 -24
- package/test/automation.test.ts +0 -315
- package/test/client-mcp.test.ts +0 -369
- package/test/codemode-api.test.ts +0 -88
- package/test/config.test.ts +0 -104
- package/test/cors.test.ts +0 -24
- package/test/defect-response.test.ts +0 -83
- package/test/event-feed.test.ts +0 -201
- package/test/fetch-option.test.ts +0 -104
- package/test/fetch.test.ts +0 -698
- package/test/flag-channel.test.ts +0 -126
- package/test/fs.test.ts +0 -439
- package/test/generate.test.ts +0 -132
- package/test/handler-policy.test.ts +0 -43
- package/test/heap-dump.test.ts +0 -137
- package/test/integration-policy.test.ts +0 -93
- package/test/job.test.ts +0 -186
- package/test/machine-iroh.test.ts +0 -259
- package/test/machine-link.test.ts +0 -1234
- package/test/machine-routes.test.ts +0 -198
- package/test/media.test.ts +0 -343
- package/test/message.test.ts +0 -105
- package/test/model.test.ts +0 -62
- package/test/options.test.ts +0 -42
- package/test/permission-saved.test.ts +0 -73
- package/test/persistent-pty.test.ts +0 -1007
- package/test/process.test.ts +0 -261
- package/test/provider.test.ts +0 -88
- package/test/pty-socket.property.test.ts +0 -240
- package/test/pty-socket.test.ts +0 -89
- package/test/pty-transport.test.ts +0 -200
- package/test/push-routes.test.ts +0 -157
- package/test/request-site.test.ts +0 -71
- package/test/request-tracing.test.ts +0 -87
- package/test/rpc-handler-errors.test.ts +0 -76
- package/test/schema-error.test.ts +0 -68
- package/test/service-status.test.ts +0 -34
- package/test/session-admit-location.test.ts +0 -92
- package/test/session-create.test.ts +0 -65
- package/test/session-diff.test.ts +0 -100
- package/test/session-form.test.ts +0 -50
- package/test/session-import.test.ts +0 -152
- package/test/session-instances.test.ts +0 -335
- package/test/session-unarchive.test.ts +0 -73
- package/test/session-update.test.ts +0 -66
- package/test/skill.test.ts +0 -57
- package/test/sse-failure.test.ts +0 -71
- package/test/usage.test.ts +0 -88
- package/test/vcs.test.ts +0 -356
- package/test/video-generate.test.ts +0 -131
- package/test/voice.test.ts +0 -170
- package/test/workerd.test.ts +0 -227
- package/test/worktree.test.ts +0 -333
|
@@ -1,131 +1,131 @@
|
|
|
1
|
-
import { Instance } from "@zyro-sec/core/instance/service"
|
|
2
|
-
import { Location } from "@zyro-sec/core/location"
|
|
3
|
-
import { Permission } from "@zyro-sec/core/permission"
|
|
4
|
-
import { PermissionSaved } from "@zyro-sec/core/permission/saved"
|
|
5
|
-
import { Session } from "@zyro-sec/core/session"
|
|
6
|
-
import { Effect } from "effect"
|
|
7
|
-
import { HttpApiBuilder, HttpApiSchema } from "effect/http-api"
|
|
8
|
-
import { Api } from "../api"
|
|
9
|
-
import { ConflictError, PermissionNotFoundError, PermissionSavedNotFoundError } from "@zyro-sec/protocol/errors"
|
|
10
|
-
import { locationErrors, response, sessionInfo } from "../location"
|
|
11
|
-
import { missingSession } from "./session-error"
|
|
12
|
-
|
|
13
|
-
function missingRequest(id: Permission.ID) {
|
|
14
|
-
return new PermissionNotFoundError({ requestID: id, message: `Permission request not found: ${id}` })
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const PermissionHandler = HttpApiBuilder.group(Api, "server.permission", (handlers) =>
|
|
18
|
-
Effect.gen(function* () {
|
|
19
|
-
const instances = yield* Instance.Service
|
|
20
|
-
const sessions = yield* Session.Service
|
|
21
|
-
const requireOwnedRequest = Effect.fnUntraced(function* (
|
|
22
|
-
sessionID: Permission.Request["sessionID"],
|
|
23
|
-
requestID: Permission.ID,
|
|
24
|
-
) {
|
|
25
|
-
const permission = yield* Permission.Service
|
|
26
|
-
const request = yield* permission.get(requestID)
|
|
27
|
-
if (!request || request.sessionID !== sessionID) return yield* missingRequest(requestID)
|
|
28
|
-
return { permission, request }
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
return handlers
|
|
32
|
-
.handle(
|
|
33
|
-
"permission.request.list",
|
|
34
|
-
Effect.fn(function* () {
|
|
35
|
-
const permission = yield* Permission.Service
|
|
36
|
-
return yield* response(permission.list())
|
|
37
|
-
}),
|
|
38
|
-
)
|
|
39
|
-
.handle(
|
|
40
|
-
"session.permission.create",
|
|
41
|
-
Effect.fn(function* (ctx) {
|
|
42
|
-
const permission = yield* Permission.Service
|
|
43
|
-
return {
|
|
44
|
-
data: yield* permission
|
|
45
|
-
.ask({
|
|
46
|
-
id: ctx.payload.id,
|
|
47
|
-
sessionID: ctx.params.sessionID,
|
|
48
|
-
action: ctx.payload.action,
|
|
49
|
-
resources: ctx.payload.resources,
|
|
50
|
-
save: ctx.payload.save,
|
|
51
|
-
metadata: ctx.payload.metadata,
|
|
52
|
-
source: ctx.payload.source,
|
|
53
|
-
agent: ctx.payload.agent,
|
|
54
|
-
})
|
|
55
|
-
.pipe(Effect.catchTag("Session.NotFoundError", missingSession)),
|
|
56
|
-
}
|
|
57
|
-
}),
|
|
58
|
-
)
|
|
59
|
-
.handle(
|
|
60
|
-
"session.permission.list",
|
|
61
|
-
Effect.fn(function* (ctx) {
|
|
62
|
-
const session = yield* sessionInfo(sessions, ctx.params.sessionID)
|
|
63
|
-
const requests = yield* Permission.Service.use((permission) =>
|
|
64
|
-
permission.forSession(ctx.params.sessionID),
|
|
65
|
-
).pipe(instances.provide(session), locationErrors)
|
|
66
|
-
return { data: requests }
|
|
67
|
-
}),
|
|
68
|
-
)
|
|
69
|
-
.handle(
|
|
70
|
-
"session.permission.get",
|
|
71
|
-
Effect.fn(function* (ctx) {
|
|
72
|
-
const owned = yield* requireOwnedRequest(ctx.params.sessionID, ctx.params.requestID)
|
|
73
|
-
return { data: owned.request }
|
|
74
|
-
}),
|
|
75
|
-
)
|
|
76
|
-
.handle(
|
|
77
|
-
"session.permission.reply",
|
|
78
|
-
Effect.fn(function* (ctx) {
|
|
79
|
-
const owned = yield* requireOwnedRequest(ctx.params.sessionID, ctx.params.requestID)
|
|
80
|
-
yield* owned.permission
|
|
81
|
-
.reply({ requestID: ctx.params.requestID, reply: ctx.payload.decision, message: ctx.payload.message })
|
|
82
|
-
.pipe(Effect.catchTag("Permission.NotFoundError", () => missingRequest(ctx.params.requestID)))
|
|
83
|
-
return HttpApiSchema.NoContent.make()
|
|
84
|
-
}),
|
|
85
|
-
)
|
|
86
|
-
.handle(
|
|
87
|
-
"permission.saved.list",
|
|
88
|
-
Effect.fn(function* (ctx) {
|
|
89
|
-
const location = yield* Location.Service
|
|
90
|
-
const saved = yield* PermissionSaved.Service
|
|
91
|
-
return {
|
|
92
|
-
data: yield* saved.list({
|
|
93
|
-
projectID: ctx.query.projectID ?? location.project.id,
|
|
94
|
-
}),
|
|
95
|
-
}
|
|
96
|
-
}),
|
|
97
|
-
)
|
|
98
|
-
.handle(
|
|
99
|
-
"permission.saved.update",
|
|
100
|
-
Effect.fn(function* (ctx) {
|
|
101
|
-
const saved = yield* PermissionSaved.Service
|
|
102
|
-
return {
|
|
103
|
-
data: yield* saved
|
|
104
|
-
.update({ id: ctx.params.id, action: ctx.payload.action, resource: ctx.payload.resource })
|
|
105
|
-
.pipe(
|
|
106
|
-
Effect.catchTags({
|
|
107
|
-
"PermissionSaved.NotFoundError": (error) =>
|
|
108
|
-
new PermissionSavedNotFoundError({
|
|
109
|
-
id: error.id,
|
|
110
|
-
message: `Saved permission not found: ${error.id}`,
|
|
111
|
-
}),
|
|
112
|
-
"PermissionSaved.ConflictError": (error) =>
|
|
113
|
-
new ConflictError({
|
|
114
|
-
resource: error.id,
|
|
115
|
-
message: `A saved permission already allows ${error.action} for ${error.resource}`,
|
|
116
|
-
}),
|
|
117
|
-
}),
|
|
118
|
-
),
|
|
119
|
-
}
|
|
120
|
-
}),
|
|
121
|
-
)
|
|
122
|
-
.handle(
|
|
123
|
-
"permission.saved.remove",
|
|
124
|
-
Effect.fn(function* (ctx) {
|
|
125
|
-
const saved = yield* PermissionSaved.Service
|
|
126
|
-
yield* saved.remove(ctx.params.id)
|
|
127
|
-
return HttpApiSchema.NoContent.make()
|
|
128
|
-
}),
|
|
129
|
-
)
|
|
130
|
-
}),
|
|
131
|
-
)
|
|
1
|
+
import { Instance } from "@zyro-sec/core/instance/service"
|
|
2
|
+
import { Location } from "@zyro-sec/core/location"
|
|
3
|
+
import { Permission } from "@zyro-sec/core/permission"
|
|
4
|
+
import { PermissionSaved } from "@zyro-sec/core/permission/saved"
|
|
5
|
+
import { Session } from "@zyro-sec/core/session"
|
|
6
|
+
import { Effect } from "effect"
|
|
7
|
+
import { HttpApiBuilder, HttpApiSchema } from "effect/http-api"
|
|
8
|
+
import { Api } from "../api"
|
|
9
|
+
import { ConflictError, PermissionNotFoundError, PermissionSavedNotFoundError } from "@zyro-sec/protocol/errors"
|
|
10
|
+
import { locationErrors, response, sessionInfo } from "../location"
|
|
11
|
+
import { missingSession } from "./session-error"
|
|
12
|
+
|
|
13
|
+
function missingRequest(id: Permission.ID) {
|
|
14
|
+
return new PermissionNotFoundError({ requestID: id, message: `Permission request not found: ${id}` })
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const PermissionHandler = HttpApiBuilder.group(Api, "server.permission", (handlers) =>
|
|
18
|
+
Effect.gen(function* () {
|
|
19
|
+
const instances = yield* Instance.Service
|
|
20
|
+
const sessions = yield* Session.Service
|
|
21
|
+
const requireOwnedRequest = Effect.fnUntraced(function* (
|
|
22
|
+
sessionID: Permission.Request["sessionID"],
|
|
23
|
+
requestID: Permission.ID,
|
|
24
|
+
) {
|
|
25
|
+
const permission = yield* Permission.Service
|
|
26
|
+
const request = yield* permission.get(requestID)
|
|
27
|
+
if (!request || request.sessionID !== sessionID) return yield* missingRequest(requestID)
|
|
28
|
+
return { permission, request }
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return handlers
|
|
32
|
+
.handle(
|
|
33
|
+
"permission.request.list",
|
|
34
|
+
Effect.fn(function* () {
|
|
35
|
+
const permission = yield* Permission.Service
|
|
36
|
+
return yield* response(permission.list())
|
|
37
|
+
}),
|
|
38
|
+
)
|
|
39
|
+
.handle(
|
|
40
|
+
"session.permission.create",
|
|
41
|
+
Effect.fn(function* (ctx) {
|
|
42
|
+
const permission = yield* Permission.Service
|
|
43
|
+
return {
|
|
44
|
+
data: yield* permission
|
|
45
|
+
.ask({
|
|
46
|
+
id: ctx.payload.id,
|
|
47
|
+
sessionID: ctx.params.sessionID,
|
|
48
|
+
action: ctx.payload.action,
|
|
49
|
+
resources: ctx.payload.resources,
|
|
50
|
+
save: ctx.payload.save,
|
|
51
|
+
metadata: ctx.payload.metadata,
|
|
52
|
+
source: ctx.payload.source,
|
|
53
|
+
agent: ctx.payload.agent,
|
|
54
|
+
})
|
|
55
|
+
.pipe(Effect.catchTag("Session.NotFoundError", missingSession)),
|
|
56
|
+
}
|
|
57
|
+
}),
|
|
58
|
+
)
|
|
59
|
+
.handle(
|
|
60
|
+
"session.permission.list",
|
|
61
|
+
Effect.fn(function* (ctx) {
|
|
62
|
+
const session = yield* sessionInfo(sessions, ctx.params.sessionID)
|
|
63
|
+
const requests = yield* Permission.Service.use((permission) =>
|
|
64
|
+
permission.forSession(ctx.params.sessionID),
|
|
65
|
+
).pipe(instances.provide(session), locationErrors)
|
|
66
|
+
return { data: requests }
|
|
67
|
+
}),
|
|
68
|
+
)
|
|
69
|
+
.handle(
|
|
70
|
+
"session.permission.get",
|
|
71
|
+
Effect.fn(function* (ctx) {
|
|
72
|
+
const owned = yield* requireOwnedRequest(ctx.params.sessionID, ctx.params.requestID)
|
|
73
|
+
return { data: owned.request }
|
|
74
|
+
}),
|
|
75
|
+
)
|
|
76
|
+
.handle(
|
|
77
|
+
"session.permission.reply",
|
|
78
|
+
Effect.fn(function* (ctx) {
|
|
79
|
+
const owned = yield* requireOwnedRequest(ctx.params.sessionID, ctx.params.requestID)
|
|
80
|
+
yield* owned.permission
|
|
81
|
+
.reply({ requestID: ctx.params.requestID, reply: ctx.payload.decision, message: ctx.payload.message })
|
|
82
|
+
.pipe(Effect.catchTag("Permission.NotFoundError", () => missingRequest(ctx.params.requestID)))
|
|
83
|
+
return HttpApiSchema.NoContent.make()
|
|
84
|
+
}),
|
|
85
|
+
)
|
|
86
|
+
.handle(
|
|
87
|
+
"permission.saved.list",
|
|
88
|
+
Effect.fn(function* (ctx) {
|
|
89
|
+
const location = yield* Location.Service
|
|
90
|
+
const saved = yield* PermissionSaved.Service
|
|
91
|
+
return {
|
|
92
|
+
data: yield* saved.list({
|
|
93
|
+
projectID: ctx.query.projectID ?? location.project.id,
|
|
94
|
+
}),
|
|
95
|
+
}
|
|
96
|
+
}),
|
|
97
|
+
)
|
|
98
|
+
.handle(
|
|
99
|
+
"permission.saved.update",
|
|
100
|
+
Effect.fn(function* (ctx) {
|
|
101
|
+
const saved = yield* PermissionSaved.Service
|
|
102
|
+
return {
|
|
103
|
+
data: yield* saved
|
|
104
|
+
.update({ id: ctx.params.id, action: ctx.payload.action, resource: ctx.payload.resource })
|
|
105
|
+
.pipe(
|
|
106
|
+
Effect.catchTags({
|
|
107
|
+
"PermissionSaved.NotFoundError": (error) =>
|
|
108
|
+
new PermissionSavedNotFoundError({
|
|
109
|
+
id: error.id,
|
|
110
|
+
message: `Saved permission not found: ${error.id}`,
|
|
111
|
+
}),
|
|
112
|
+
"PermissionSaved.ConflictError": (error) =>
|
|
113
|
+
new ConflictError({
|
|
114
|
+
resource: error.id,
|
|
115
|
+
message: `A saved permission already allows ${error.action} for ${error.resource}`,
|
|
116
|
+
}),
|
|
117
|
+
}),
|
|
118
|
+
),
|
|
119
|
+
}
|
|
120
|
+
}),
|
|
121
|
+
)
|
|
122
|
+
.handle(
|
|
123
|
+
"permission.saved.remove",
|
|
124
|
+
Effect.fn(function* (ctx) {
|
|
125
|
+
const saved = yield* PermissionSaved.Service
|
|
126
|
+
yield* saved.remove(ctx.params.id)
|
|
127
|
+
return HttpApiSchema.NoContent.make()
|
|
128
|
+
}),
|
|
129
|
+
)
|
|
130
|
+
}),
|
|
131
|
+
)
|