@zyro-sec/server 1.0.2 → 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 +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
package/src/event-feed.ts
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
export * as EventFeed from "./event-feed"
|
|
2
|
-
|
|
3
|
-
import { Bus } from "@zyro-sec/core/bus"
|
|
4
|
-
import { Event } from "@zyro-sec/schema/event"
|
|
5
|
-
import { isOpenCodeEvent, type OpenCodeEvent } from "@zyro-sec/protocol/groups/event"
|
|
6
|
-
import { Cause, Context, Effect, Layer, Queue, Schema, Scope, Stream } from "effect"
|
|
7
|
-
|
|
8
|
-
export const SubscriberCapacity = 4_096
|
|
9
|
-
|
|
10
|
-
export class SubscriberOverflowError extends Schema.TaggedError<SubscriberOverflowError>()(
|
|
11
|
-
"EventFeed.SubscriberOverflow",
|
|
12
|
-
{ capacity: Schema.Int },
|
|
13
|
-
) {}
|
|
14
|
-
|
|
15
|
-
export class EncodingError extends Schema.TaggedError<EncodingError>()("EventFeed.EncodingError", {
|
|
16
|
-
eventID: Event.ID,
|
|
17
|
-
eventType: Schema.String,
|
|
18
|
-
cause: Schema.Defect(),
|
|
19
|
-
}) {}
|
|
20
|
-
|
|
21
|
-
export type Error = SubscriberOverflowError | EncodingError
|
|
22
|
-
|
|
23
|
-
export interface Interface {
|
|
24
|
-
readonly subscribe: (types?: ReadonlyArray<string>) => Effect.Effect<Stream.Stream<string, Error>, never, Scope.Scope>
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class Service extends Context.Service<Service, Interface>()("@zyro-sec/server/EventFeed") {}
|
|
28
|
-
|
|
29
|
-
export function frame(event: OpenCodeEvent) {
|
|
30
|
-
return `data: ${JSON.stringify(event)}\n\n`
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const make = Effect.fn("EventFeed.make")(function* (
|
|
34
|
-
observe: (subscriber: Bus.Subscriber) => Effect.Effect<Bus.Unsubscribe>,
|
|
35
|
-
options?: { readonly capacity?: number; readonly encode?: (event: OpenCodeEvent) => string },
|
|
36
|
-
) {
|
|
37
|
-
const capacity = options?.capacity ?? SubscriberCapacity
|
|
38
|
-
const render = options?.encode ?? frame
|
|
39
|
-
const subscribers = new Map<Queue.Queue<string, Error>, ReadonlySet<string> | undefined>()
|
|
40
|
-
|
|
41
|
-
const fail = (error: Error) =>
|
|
42
|
-
Effect.sync(() => {
|
|
43
|
-
const current = Array.from(subscribers.keys())
|
|
44
|
-
subscribers.clear()
|
|
45
|
-
for (const subscriber of current) Queue.failCauseUnsafe(subscriber, Cause.fail(error))
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
const publish = Effect.fnUntraced(function* (event: Event.Payload) {
|
|
49
|
-
if (!isOpenCodeEvent(event)) return
|
|
50
|
-
let encoded: string | undefined
|
|
51
|
-
for (const [subscriber, types] of subscribers) {
|
|
52
|
-
if (types && !types.has(event.type)) continue
|
|
53
|
-
encoded ??= yield* Effect.try({
|
|
54
|
-
try: () => render(event),
|
|
55
|
-
catch: (cause) => new EncodingError({ eventID: event.id, eventType: event.type, cause }),
|
|
56
|
-
}).pipe(
|
|
57
|
-
Effect.catch((error) =>
|
|
58
|
-
Effect.logError("Failed to encode public event", {
|
|
59
|
-
eventID: error.eventID,
|
|
60
|
-
eventType: error.eventType,
|
|
61
|
-
cause: error.cause,
|
|
62
|
-
}).pipe(Effect.andThen(fail(error)), Effect.as(undefined)),
|
|
63
|
-
),
|
|
64
|
-
)
|
|
65
|
-
if (encoded === undefined) return
|
|
66
|
-
if (Queue.offerUnsafe(subscriber, encoded)) continue
|
|
67
|
-
subscribers.delete(subscriber)
|
|
68
|
-
Queue.failCauseUnsafe(subscriber, Cause.fail(new SubscriberOverflowError({ capacity })))
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
const unsubscribe = yield* observe(publish)
|
|
73
|
-
yield* Effect.addFinalizer(() => unsubscribe)
|
|
74
|
-
|
|
75
|
-
return Service.of({
|
|
76
|
-
subscribe: (types) =>
|
|
77
|
-
Effect.acquireRelease(
|
|
78
|
-
Queue.dropping<string, Error>(capacity).pipe(
|
|
79
|
-
Effect.tap((queue) => Effect.sync(() => subscribers.set(queue, types?.length ? new Set(types) : undefined))),
|
|
80
|
-
),
|
|
81
|
-
(queue) =>
|
|
82
|
-
Effect.sync(() => subscribers.delete(queue)).pipe(Effect.andThen(Queue.shutdown(queue)), Effect.asVoid),
|
|
83
|
-
).pipe(Effect.map(Stream.fromQueue)),
|
|
84
|
-
})
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
export const layer = Layer.effect(
|
|
88
|
-
Service,
|
|
89
|
-
Effect.gen(function* () {
|
|
90
|
-
const bus = yield* Bus.Service
|
|
91
|
-
return yield* make(bus.listen)
|
|
92
|
-
}),
|
|
93
|
-
)
|
|
1
|
+
export * as EventFeed from "./event-feed"
|
|
2
|
+
|
|
3
|
+
import { Bus } from "@zyro-sec/core/bus"
|
|
4
|
+
import { Event } from "@zyro-sec/schema/event"
|
|
5
|
+
import { isOpenCodeEvent, type OpenCodeEvent } from "@zyro-sec/protocol/groups/event"
|
|
6
|
+
import { Cause, Context, Effect, Layer, Queue, Schema, Scope, Stream } from "effect"
|
|
7
|
+
|
|
8
|
+
export const SubscriberCapacity = 4_096
|
|
9
|
+
|
|
10
|
+
export class SubscriberOverflowError extends Schema.TaggedError<SubscriberOverflowError>()(
|
|
11
|
+
"EventFeed.SubscriberOverflow",
|
|
12
|
+
{ capacity: Schema.Int },
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
export class EncodingError extends Schema.TaggedError<EncodingError>()("EventFeed.EncodingError", {
|
|
16
|
+
eventID: Event.ID,
|
|
17
|
+
eventType: Schema.String,
|
|
18
|
+
cause: Schema.Defect(),
|
|
19
|
+
}) {}
|
|
20
|
+
|
|
21
|
+
export type Error = SubscriberOverflowError | EncodingError
|
|
22
|
+
|
|
23
|
+
export interface Interface {
|
|
24
|
+
readonly subscribe: (types?: ReadonlyArray<string>) => Effect.Effect<Stream.Stream<string, Error>, never, Scope.Scope>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class Service extends Context.Service<Service, Interface>()("@zyro-sec/server/EventFeed") {}
|
|
28
|
+
|
|
29
|
+
export function frame(event: OpenCodeEvent) {
|
|
30
|
+
return `data: ${JSON.stringify(event)}\n\n`
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const make = Effect.fn("EventFeed.make")(function* (
|
|
34
|
+
observe: (subscriber: Bus.Subscriber) => Effect.Effect<Bus.Unsubscribe>,
|
|
35
|
+
options?: { readonly capacity?: number; readonly encode?: (event: OpenCodeEvent) => string },
|
|
36
|
+
) {
|
|
37
|
+
const capacity = options?.capacity ?? SubscriberCapacity
|
|
38
|
+
const render = options?.encode ?? frame
|
|
39
|
+
const subscribers = new Map<Queue.Queue<string, Error>, ReadonlySet<string> | undefined>()
|
|
40
|
+
|
|
41
|
+
const fail = (error: Error) =>
|
|
42
|
+
Effect.sync(() => {
|
|
43
|
+
const current = Array.from(subscribers.keys())
|
|
44
|
+
subscribers.clear()
|
|
45
|
+
for (const subscriber of current) Queue.failCauseUnsafe(subscriber, Cause.fail(error))
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const publish = Effect.fnUntraced(function* (event: Event.Payload) {
|
|
49
|
+
if (!isOpenCodeEvent(event)) return
|
|
50
|
+
let encoded: string | undefined
|
|
51
|
+
for (const [subscriber, types] of subscribers) {
|
|
52
|
+
if (types && !types.has(event.type)) continue
|
|
53
|
+
encoded ??= yield* Effect.try({
|
|
54
|
+
try: () => render(event),
|
|
55
|
+
catch: (cause) => new EncodingError({ eventID: event.id, eventType: event.type, cause }),
|
|
56
|
+
}).pipe(
|
|
57
|
+
Effect.catch((error) =>
|
|
58
|
+
Effect.logError("Failed to encode public event", {
|
|
59
|
+
eventID: error.eventID,
|
|
60
|
+
eventType: error.eventType,
|
|
61
|
+
cause: error.cause,
|
|
62
|
+
}).pipe(Effect.andThen(fail(error)), Effect.as(undefined)),
|
|
63
|
+
),
|
|
64
|
+
)
|
|
65
|
+
if (encoded === undefined) return
|
|
66
|
+
if (Queue.offerUnsafe(subscriber, encoded)) continue
|
|
67
|
+
subscribers.delete(subscriber)
|
|
68
|
+
Queue.failCauseUnsafe(subscriber, Cause.fail(new SubscriberOverflowError({ capacity })))
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const unsubscribe = yield* observe(publish)
|
|
73
|
+
yield* Effect.addFinalizer(() => unsubscribe)
|
|
74
|
+
|
|
75
|
+
return Service.of({
|
|
76
|
+
subscribe: (types) =>
|
|
77
|
+
Effect.acquireRelease(
|
|
78
|
+
Queue.dropping<string, Error>(capacity).pipe(
|
|
79
|
+
Effect.tap((queue) => Effect.sync(() => subscribers.set(queue, types?.length ? new Set(types) : undefined))),
|
|
80
|
+
),
|
|
81
|
+
(queue) =>
|
|
82
|
+
Effect.sync(() => subscribers.delete(queue)).pipe(Effect.andThen(Queue.shutdown(queue)), Effect.asVoid),
|
|
83
|
+
).pipe(Effect.map(Stream.fromQueue)),
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
export const layer = Layer.effect(
|
|
88
|
+
Service,
|
|
89
|
+
Effect.gen(function* () {
|
|
90
|
+
const bus = yield* Bus.Service
|
|
91
|
+
return yield* make(bus.listen)
|
|
92
|
+
}),
|
|
93
|
+
)
|
package/src/fetch.ts
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
export * as ServerFetch from "./fetch"
|
|
2
|
-
|
|
3
|
-
import { Context, Effect, Layer } from "effect"
|
|
4
|
-
import { HttpEffect, HttpMiddleware, HttpRouter, HttpServer } from "effect/http"
|
|
5
|
-
import { SessionRestart } from "@zyro-sec/core/session/execution/restart"
|
|
6
|
-
import type { LayerNode } from "@zyro-sec/util/effect/layer-node"
|
|
7
|
-
import { isAllowedCorsOrigin } from "./cors"
|
|
8
|
-
import { RequestSite } from "./request-site"
|
|
9
|
-
import { withoutParentSpan } from "./request-tracing"
|
|
10
|
-
import { createRoutes } from "./routes"
|
|
11
|
-
import type { ServerOptions } from "./options"
|
|
12
|
-
|
|
13
|
-
export interface BootOptions {
|
|
14
|
-
/**
|
|
15
|
-
* Runtime-profile service replacements, applied after the standard set so later entries
|
|
16
|
-
* win — swaps services the standard graph assumes are local. See `ServerWorkerd.replacements`.
|
|
17
|
-
*/
|
|
18
|
-
readonly overrides?: LayerNode.Replacements
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Internal entry for runtime profiles (such as `ServerWorkerd.create`) that also need the built service context. */
|
|
22
|
-
export const makeWithContext = Effect.fn("ServerFetch.makeWithContext")(function* (
|
|
23
|
-
options: ServerOptions = {},
|
|
24
|
-
boot: BootOptions = {},
|
|
25
|
-
) {
|
|
26
|
-
// Handlers capture the build context; without the caller's span, each request is its own trace.
|
|
27
|
-
const context = yield* Layer.build(
|
|
28
|
-
createRoutes(options, () => [], boot.overrides ?? []).pipe(Layer.provide(HttpServer.layerServices)),
|
|
29
|
-
).pipe(withoutParentSpan)
|
|
30
|
-
// Forked so the returned handler is never delayed; resumed drains are already
|
|
31
|
-
// logged and durably recorded by the execution layer.
|
|
32
|
-
yield* Effect.forkDetach(Context.get(context, SessionRestart.Service).resumeSuspendedSessions)
|
|
33
|
-
const handler = Context.get(context, HttpRouter.HttpRouter)
|
|
34
|
-
.asHttpEffect()
|
|
35
|
-
.pipe(
|
|
36
|
-
RequestSite.middleware(options),
|
|
37
|
-
HttpMiddleware.cors({ allowedOrigins: (origin) => isAllowedCorsOrigin(origin, options), maxAge: 86_400 }),
|
|
38
|
-
HttpEffect.toWebHandlerWith(context),
|
|
39
|
-
)
|
|
40
|
-
return { handler, context }
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Builds a web-standard fetch handler — `(request: Request) => Promise<Response>` — serving the
|
|
45
|
-
* same HttpApi routes as the Node server process without binding a port, owning a listener, or
|
|
46
|
-
* installing signal handlers. This is the entry for runtimes that hand requests to the embedder
|
|
47
|
-
* instead of letting it listen: workerd (Workers and Durable Objects), Deno.serve, Bun.serve, or
|
|
48
|
-
* a test harness.
|
|
49
|
-
*
|
|
50
|
-
* The application layer builds EAGERLY, inside the caller's `Scope`, before the handler is
|
|
51
|
-
* returned. Do not convert this to a lazy first-request build: on workerd, a first request that
|
|
52
|
-
* aborts mid-build interrupts the layer construction and wedges every subsequent request
|
|
53
|
-
* (Effect-TS/effect#6319 class). The embedder owns the lifecycle — closing the scope releases
|
|
54
|
-
* the application layer.
|
|
55
|
-
*
|
|
56
|
-
* Auth follows `createRoutes` semantics: `options.password` enforces Basic auth; omitting it
|
|
57
|
-
* serves unauthenticated, so an embedder without a password must front the handler with its own
|
|
58
|
-
* access control.
|
|
59
|
-
*
|
|
60
|
-
* Sessions whose execution claim was never released resume once the layer is built, exactly as
|
|
61
|
-
* the Node server process does: a runtime that dies without teardown — an evicted Durable
|
|
62
|
-
* Object leaves the same durable signature as a killed process — replays orphaned turns on the
|
|
63
|
-
* next boot, and the sweep is a no-op when nothing is suspended.
|
|
64
|
-
*/
|
|
65
|
-
export const make = Effect.fn("ServerFetch.make")(function* (options: ServerOptions = {}, boot: BootOptions = {}) {
|
|
66
|
-
return (yield* makeWithContext(options, boot)).handler
|
|
67
|
-
})
|
|
1
|
+
export * as ServerFetch from "./fetch"
|
|
2
|
+
|
|
3
|
+
import { Context, Effect, Layer } from "effect"
|
|
4
|
+
import { HttpEffect, HttpMiddleware, HttpRouter, HttpServer } from "effect/http"
|
|
5
|
+
import { SessionRestart } from "@zyro-sec/core/session/execution/restart"
|
|
6
|
+
import type { LayerNode } from "@zyro-sec/util/effect/layer-node"
|
|
7
|
+
import { isAllowedCorsOrigin } from "./cors"
|
|
8
|
+
import { RequestSite } from "./request-site"
|
|
9
|
+
import { withoutParentSpan } from "./request-tracing"
|
|
10
|
+
import { createRoutes } from "./routes"
|
|
11
|
+
import type { ServerOptions } from "./options"
|
|
12
|
+
|
|
13
|
+
export interface BootOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Runtime-profile service replacements, applied after the standard set so later entries
|
|
16
|
+
* win — swaps services the standard graph assumes are local. See `ServerWorkerd.replacements`.
|
|
17
|
+
*/
|
|
18
|
+
readonly overrides?: LayerNode.Replacements
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Internal entry for runtime profiles (such as `ServerWorkerd.create`) that also need the built service context. */
|
|
22
|
+
export const makeWithContext = Effect.fn("ServerFetch.makeWithContext")(function* (
|
|
23
|
+
options: ServerOptions = {},
|
|
24
|
+
boot: BootOptions = {},
|
|
25
|
+
) {
|
|
26
|
+
// Handlers capture the build context; without the caller's span, each request is its own trace.
|
|
27
|
+
const context = yield* Layer.build(
|
|
28
|
+
createRoutes(options, () => [], boot.overrides ?? []).pipe(Layer.provide(HttpServer.layerServices)),
|
|
29
|
+
).pipe(withoutParentSpan)
|
|
30
|
+
// Forked so the returned handler is never delayed; resumed drains are already
|
|
31
|
+
// logged and durably recorded by the execution layer.
|
|
32
|
+
yield* Effect.forkDetach(Context.get(context, SessionRestart.Service).resumeSuspendedSessions)
|
|
33
|
+
const handler = Context.get(context, HttpRouter.HttpRouter)
|
|
34
|
+
.asHttpEffect()
|
|
35
|
+
.pipe(
|
|
36
|
+
RequestSite.middleware(options),
|
|
37
|
+
HttpMiddleware.cors({ allowedOrigins: (origin) => isAllowedCorsOrigin(origin, options), maxAge: 86_400 }),
|
|
38
|
+
HttpEffect.toWebHandlerWith(context),
|
|
39
|
+
)
|
|
40
|
+
return { handler, context }
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Builds a web-standard fetch handler — `(request: Request) => Promise<Response>` — serving the
|
|
45
|
+
* same HttpApi routes as the Node server process without binding a port, owning a listener, or
|
|
46
|
+
* installing signal handlers. This is the entry for runtimes that hand requests to the embedder
|
|
47
|
+
* instead of letting it listen: workerd (Workers and Durable Objects), Deno.serve, Bun.serve, or
|
|
48
|
+
* a test harness.
|
|
49
|
+
*
|
|
50
|
+
* The application layer builds EAGERLY, inside the caller's `Scope`, before the handler is
|
|
51
|
+
* returned. Do not convert this to a lazy first-request build: on workerd, a first request that
|
|
52
|
+
* aborts mid-build interrupts the layer construction and wedges every subsequent request
|
|
53
|
+
* (Effect-TS/effect#6319 class). The embedder owns the lifecycle — closing the scope releases
|
|
54
|
+
* the application layer.
|
|
55
|
+
*
|
|
56
|
+
* Auth follows `createRoutes` semantics: `options.password` enforces Basic auth; omitting it
|
|
57
|
+
* serves unauthenticated, so an embedder without a password must front the handler with its own
|
|
58
|
+
* access control.
|
|
59
|
+
*
|
|
60
|
+
* Sessions whose execution claim was never released resume once the layer is built, exactly as
|
|
61
|
+
* the Node server process does: a runtime that dies without teardown — an evicted Durable
|
|
62
|
+
* Object leaves the same durable signature as a killed process — replays orphaned turns on the
|
|
63
|
+
* next boot, and the sweep is a no-op when nothing is suspended.
|
|
64
|
+
*/
|
|
65
|
+
export const make = Effect.fn("ServerFetch.make")(function* (options: ServerOptions = {}, boot: BootOptions = {}) {
|
|
66
|
+
return (yield* makeWithContext(options, boot)).handler
|
|
67
|
+
})
|
package/src/handlers/agent.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { Agent } from "@zyro-sec/core/agent"
|
|
2
|
-
import { Effect } from "effect"
|
|
3
|
-
import { HttpApiBuilder } from "effect/http-api"
|
|
4
|
-
import { Api } from "../api"
|
|
5
|
-
import { response } from "../location"
|
|
6
|
-
import { AgentNotFoundError } from "@zyro-sec/protocol/errors"
|
|
7
|
-
|
|
8
|
-
export const AgentHandler = HttpApiBuilder.group(Api, "server.agent", (handlers) =>
|
|
9
|
-
handlers
|
|
10
|
-
.handle("agent.list", () => response(Agent.Service.use((agent) => agent.list())))
|
|
11
|
-
.handle(
|
|
12
|
-
"agent.get",
|
|
13
|
-
Effect.fn(function* (ctx) {
|
|
14
|
-
const agent = yield* Agent.Service.use((service) => service.get(ctx.params.agentID))
|
|
15
|
-
if (!agent)
|
|
16
|
-
return yield* new AgentNotFoundError({
|
|
17
|
-
agentID: ctx.params.agentID,
|
|
18
|
-
message: `Agent not found: ${ctx.params.agentID}`,
|
|
19
|
-
})
|
|
20
|
-
return yield* response(Effect.succeed(agent))
|
|
21
|
-
}),
|
|
22
|
-
),
|
|
23
|
-
)
|
|
1
|
+
import { Agent } from "@zyro-sec/core/agent"
|
|
2
|
+
import { Effect } from "effect"
|
|
3
|
+
import { HttpApiBuilder } from "effect/http-api"
|
|
4
|
+
import { Api } from "../api"
|
|
5
|
+
import { response } from "../location"
|
|
6
|
+
import { AgentNotFoundError } from "@zyro-sec/protocol/errors"
|
|
7
|
+
|
|
8
|
+
export const AgentHandler = HttpApiBuilder.group(Api, "server.agent", (handlers) =>
|
|
9
|
+
handlers
|
|
10
|
+
.handle("agent.list", () => response(Agent.Service.use((agent) => agent.list())))
|
|
11
|
+
.handle(
|
|
12
|
+
"agent.get",
|
|
13
|
+
Effect.fn(function* (ctx) {
|
|
14
|
+
const agent = yield* Agent.Service.use((service) => service.get(ctx.params.agentID))
|
|
15
|
+
if (!agent)
|
|
16
|
+
return yield* new AgentNotFoundError({
|
|
17
|
+
agentID: ctx.params.agentID,
|
|
18
|
+
message: `Agent not found: ${ctx.params.agentID}`,
|
|
19
|
+
})
|
|
20
|
+
return yield* response(Effect.succeed(agent))
|
|
21
|
+
}),
|
|
22
|
+
),
|
|
23
|
+
)
|