@zyro-sec/server 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -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
package/test/model.test.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises"
|
|
2
|
-
import path from "node:path"
|
|
3
|
-
import { expect } from "bun:test"
|
|
4
|
-
import { Effect } from "effect"
|
|
5
|
-
import { tmpdir } from "../../core/test/fixture/tmpdir"
|
|
6
|
-
import { it } from "../../core/test/lib/effect"
|
|
7
|
-
import { serveRoutes } from "./fixture/routes"
|
|
8
|
-
|
|
9
|
-
it.live("lists configured models filtered by type", () =>
|
|
10
|
-
Effect.gen(function* () {
|
|
11
|
-
const tmp = yield* Effect.acquireDisposable(Effect.promise(() => tmpdir("opencode-model-endpoint-")))
|
|
12
|
-
yield* Effect.promise(() =>
|
|
13
|
-
fs.writeFile(
|
|
14
|
-
path.join(tmp.path, "opencode.json"),
|
|
15
|
-
JSON.stringify({
|
|
16
|
-
providers: {
|
|
17
|
-
custom: {
|
|
18
|
-
package: "aisdk:@ai-sdk/openai-compatible",
|
|
19
|
-
settings: { apiKey: "secret" },
|
|
20
|
-
models: { chat: {} },
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
}),
|
|
24
|
-
),
|
|
25
|
-
)
|
|
26
|
-
const server = yield* serveRoutes({
|
|
27
|
-
database: { path: ":memory:" },
|
|
28
|
-
config: { directory: tmp.path },
|
|
29
|
-
fs: { filewatcher: false },
|
|
30
|
-
models: { fetch: false },
|
|
31
|
-
})
|
|
32
|
-
yield* server.pluginsLoaded(tmp.path)
|
|
33
|
-
const url = new URL("/api/model", "http://opencode.local")
|
|
34
|
-
url.searchParams.set("location[directory]", tmp.path)
|
|
35
|
-
const response = yield* Effect.promise(() => server.fetch(url))
|
|
36
|
-
|
|
37
|
-
expect(response.status).toBe(200)
|
|
38
|
-
const body: unknown = yield* Effect.promise(() => response.json())
|
|
39
|
-
if (!isRecord(body) || !Array.isArray(body["data"])) throw new Error("Expected a model list response")
|
|
40
|
-
expect(
|
|
41
|
-
body["data"].some((model) => isRecord(model) && model["providerID"] === "custom" && model["id"] === "chat"),
|
|
42
|
-
).toBeTrue()
|
|
43
|
-
|
|
44
|
-
url.searchParams.set("types", "image")
|
|
45
|
-
const images = yield* Effect.promise(() => server.fetch(url))
|
|
46
|
-
expect(images.status).toBe(200)
|
|
47
|
-
const imageBody: unknown = yield* Effect.promise(() => images.json())
|
|
48
|
-
if (!isRecord(imageBody) || !Array.isArray(imageBody["data"])) throw new Error("Expected a model list response")
|
|
49
|
-
expect(imageBody["data"].some((model) => isRecord(model) && model["providerID"] === "custom")).toBeFalse()
|
|
50
|
-
|
|
51
|
-
url.searchParams.append("types", "chat")
|
|
52
|
-
const both = yield* Effect.promise(() => server.fetch(url))
|
|
53
|
-
expect(both.status).toBe(200)
|
|
54
|
-
const bothBody: unknown = yield* Effect.promise(() => both.json())
|
|
55
|
-
if (!isRecord(bothBody) || !Array.isArray(bothBody["data"])) throw new Error("Expected a model list response")
|
|
56
|
-
expect(bothBody["data"].some((model) => isRecord(model) && model["id"] === "chat")).toBeTrue()
|
|
57
|
-
}),
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
61
|
-
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
62
|
-
}
|
package/test/options.test.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test"
|
|
2
|
-
import { ServerOptions } from "@zyro-sec/server/options"
|
|
3
|
-
import { Option, Schema } from "effect"
|
|
4
|
-
|
|
5
|
-
const decode = Schema.decodeUnknownOption(ServerOptions)
|
|
6
|
-
|
|
7
|
-
test("accepts ephemeral port zero", () => {
|
|
8
|
-
expect(Option.isSome(decode({ port: 0 }))).toBe(true)
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
test("rejects ports outside the valid range", () => {
|
|
12
|
-
expect(Option.isNone(decode({ port: -1 }))).toBe(true)
|
|
13
|
-
expect(Option.isNone(decode({ port: 65_536 }))).toBe(true)
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
test("accepts optional app metadata", () => {
|
|
17
|
-
expect(Option.getOrThrow(decode({ app: { name: "sdk", version: "1.2.3", channel: "beta" } })).app).toEqual({
|
|
18
|
-
name: "sdk",
|
|
19
|
-
version: "1.2.3",
|
|
20
|
-
channel: "beta",
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
test("accepts durable event persistence configuration", () => {
|
|
25
|
-
expect(Option.getOrThrow(decode({ events: { persist: true } })).events).toEqual({ persist: true })
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
test("accepts an optional CORS allowlist", () => {
|
|
29
|
-
expect(Option.getOrThrow(decode({})).cors).toBeUndefined()
|
|
30
|
-
expect(Option.getOrThrow(decode({ cors: [] })).cors).toEqual([])
|
|
31
|
-
expect(Option.getOrThrow(decode({ cors: ["http://192.168.1.10:3001", "https://example.com"] })).cors).toEqual([
|
|
32
|
-
"http://192.168.1.10:3001",
|
|
33
|
-
"https://example.com",
|
|
34
|
-
])
|
|
35
|
-
expect(Option.isNone(decode({ cors: "http://192.168.1.10:3001" }))).toBe(true)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
test("accepts an embedder fetch and rejects other values", () => {
|
|
39
|
-
const fetch = () => Promise.resolve(new Response())
|
|
40
|
-
expect(Option.getOrThrow(decode({ fetch })).fetch).toBe(fetch)
|
|
41
|
-
expect(Option.isNone(decode({ fetch: "https://example.com" }))).toBe(true)
|
|
42
|
-
})
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { expect } from "bun:test"
|
|
2
|
-
import { PermissionSaved } from "@zyro-sec/schema/permission-saved"
|
|
3
|
-
import { Session } from "@zyro-sec/schema/session"
|
|
4
|
-
import { Effect, Schema } from "effect"
|
|
5
|
-
import { it } from "../../core/test/lib/effect"
|
|
6
|
-
import { ServerFetch } from "../src/fetch"
|
|
7
|
-
|
|
8
|
-
const SessionResponse = Schema.Struct({ data: Schema.toEncoded(Session.Info) })
|
|
9
|
-
const AskResponse = Schema.Struct({ data: Schema.Struct({ id: Schema.String, effect: Schema.String }) })
|
|
10
|
-
const SavedList = Schema.Struct({ data: Schema.Array(Schema.toEncoded(PermissionSaved.Info)) })
|
|
11
|
-
const SavedResponse = Schema.Struct({ data: Schema.toEncoded(PermissionSaved.Info) })
|
|
12
|
-
|
|
13
|
-
it.live("edits saved permissions through PATCH", () =>
|
|
14
|
-
Effect.gen(function* () {
|
|
15
|
-
const handler = yield* ServerFetch.make({
|
|
16
|
-
app: { version: "test" },
|
|
17
|
-
database: { path: ":memory:" },
|
|
18
|
-
fs: { filewatcher: false },
|
|
19
|
-
models: { fetch: false },
|
|
20
|
-
})
|
|
21
|
-
const request = (path: string, method: string, body?: unknown) =>
|
|
22
|
-
Effect.promise(async () => {
|
|
23
|
-
const response = await handler(
|
|
24
|
-
new Request(`http://opencode.local${path}`, {
|
|
25
|
-
method,
|
|
26
|
-
headers: { "content-type": "application/json" },
|
|
27
|
-
body: body === undefined ? undefined : JSON.stringify(body),
|
|
28
|
-
}),
|
|
29
|
-
)
|
|
30
|
-
return { status: response.status, body: response.status === 204 ? undefined : await response.json() }
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const session = Schema.decodeUnknownSync(SessionResponse)(
|
|
34
|
-
(yield* request("/api/session", "POST", {
|
|
35
|
-
permissions: [{ action: "deploy", resource: "*", effect: "ask" }],
|
|
36
|
-
})).body,
|
|
37
|
-
)
|
|
38
|
-
// Saved permissions are only created by answering "always", so save two through the real request flow.
|
|
39
|
-
for (const resource of ["src/*", "docs/*"]) {
|
|
40
|
-
const asked = Schema.decodeUnknownSync(AskResponse)(
|
|
41
|
-
(yield* request(`/api/session/${session.data.id}/permission`, "POST", {
|
|
42
|
-
action: "deploy",
|
|
43
|
-
resources: [resource],
|
|
44
|
-
save: [resource],
|
|
45
|
-
})).body,
|
|
46
|
-
)
|
|
47
|
-
expect(asked.data.effect).toBe("ask")
|
|
48
|
-
expect(
|
|
49
|
-
(yield* request(`/api/session/${session.data.id}/permission/${asked.data.id}/reply`, "POST", {
|
|
50
|
-
decision: "always",
|
|
51
|
-
})).status,
|
|
52
|
-
).toBe(204)
|
|
53
|
-
}
|
|
54
|
-
const saved = Schema.decodeUnknownSync(SavedList)((yield* request("/api/permission/saved", "GET")).body)
|
|
55
|
-
const src = saved.data.find((item) => item.resource === "src/*")!
|
|
56
|
-
|
|
57
|
-
const updated = yield* request(`/api/permission/saved/${src.id}`, "PATCH", { resource: "src/allowed.ts" })
|
|
58
|
-
expect(updated.status).toBe(200)
|
|
59
|
-
expect(Schema.decodeUnknownSync(SavedResponse)(updated.body).data).toMatchObject({
|
|
60
|
-
id: src.id,
|
|
61
|
-
action: "deploy",
|
|
62
|
-
resource: "src/allowed.ts",
|
|
63
|
-
})
|
|
64
|
-
expect(
|
|
65
|
-
Schema.decodeUnknownSync(SavedList)((yield* request("/api/permission/saved", "GET")).body)
|
|
66
|
-
.data.map((item) => item.resource)
|
|
67
|
-
.toSorted(),
|
|
68
|
-
).toEqual(["docs/*", "src/allowed.ts"])
|
|
69
|
-
|
|
70
|
-
expect((yield* request(`/api/permission/saved/${src.id}`, "PATCH", { resource: "docs/*" })).status).toBe(409)
|
|
71
|
-
expect((yield* request("/api/permission/saved/psv_missing", "PATCH", { resource: "x" })).status).toBe(404)
|
|
72
|
-
}).pipe(Effect.scoped),
|
|
73
|
-
)
|