@parlor/server 0.4.2 → 0.4.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/dist/build.d.ts +7 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +11 -0
- package/dist/build.js.map +1 -0
- package/dist/create-server.d.ts.map +1 -1
- package/dist/create-server.js +16 -1
- package/dist/create-server.js.map +1 -1
- package/package.json +5 -5
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which build of the app answers: the one `parlor build` stamps into `PARLOR_BUILD_ID`, else
|
|
3
|
+
* one per process, as a dev server restarts with new code. Read on first use, since a Worker
|
|
4
|
+
* may not draw random numbers while its modules load.
|
|
5
|
+
*/
|
|
6
|
+
export declare function serverBuild(): string;
|
|
7
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAGpC"}
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
let build;
|
|
2
|
+
/**
|
|
3
|
+
* Which build of the app answers: the one `parlor build` stamps into `PARLOR_BUILD_ID`, else
|
|
4
|
+
* one per process, as a dev server restarts with new code. Read on first use, since a Worker
|
|
5
|
+
* may not draw random numbers while its modules load.
|
|
6
|
+
*/
|
|
7
|
+
export function serverBuild() {
|
|
8
|
+
build ??= process.env.PARLOR_BUILD_ID || crypto.randomUUID();
|
|
9
|
+
return build;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,IAAI,KAAyB,CAAC;AAE9B;;;;GAIG;AACH,MAAM,UAAU,WAAW;IACzB,KAAK,KAAK,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;IAC7D,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["let build: string | undefined;\n\n/**\n * Which build of the app answers: the one `parlor build` stamps into `PARLOR_BUILD_ID`, else\n * one per process, as a dev server restarts with new code. Read on first use, since a Worker\n * may not draw random numbers while its modules load.\n */\nexport function serverBuild(): string {\n build ??= process.env.PARLOR_BUILD_ID || crypto.randomUUID();\n return build;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-server.d.ts","sourceRoot":"","sources":["../src/create-server.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EAInB,KAAK,gBAAgB,EACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAGL,KAAK,SAAS,EAEd,KAAK,kBAAkB,EACvB,KAAK,YAAY,EAIlB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,qBAAqB,CAAC;AAK7B,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"create-server.d.ts","sourceRoot":"","sources":["../src/create-server.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EAInB,KAAK,gBAAgB,EACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAGL,KAAK,SAAS,EAEd,KAAK,kBAAkB,EACvB,KAAK,YAAY,EAIlB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,qBAAqB,CAAC;AAK7B,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAS3D,OAAO,EAAE,KAAK,UAAU,EAAkB,MAAM,W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ACH,QAAQ,CAAC,YAAY,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IACvD;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;CACjD;AAKD,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC9E,QAAQ,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxD,QAAQ,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AAoND,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,EAC9C,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GACxB,eAAe,CAgUjB"}
|
package/dist/create-server.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { pagePattern, UNROUTED_HEADER } from "@parlor/agent-ui";
|
|
2
2
|
import { createAgentUi, registerAgentUiRoutes, } from "@parlor/agent-ui/server";
|
|
3
3
|
import { ActionError, ANONYMOUS, decodeReadRequests, hasUser, REFRESH_HEADER, } from "@parlor/core";
|
|
4
|
+
import { BUILD_HEADER } from "@parlor/sync";
|
|
4
5
|
import { ensureSyncTables, recordSyncEvent, registerSyncRoutes, SyncHub, } from "@parlor/sync/server";
|
|
5
6
|
import { H3, readBody } from "h3";
|
|
6
7
|
import { admits, requireAccess, requireSurface } from "./access.js";
|
|
7
8
|
import { createActionRunner } from "./actions.js";
|
|
8
9
|
import { AuthFailure } from "./auth.js";
|
|
10
|
+
import { serverBuild } from "./build.js";
|
|
9
11
|
import { clientOf, createCallerResolver, sourceOf, } from "./caller.js";
|
|
10
12
|
import { corsMiddleware } from "./cors.js";
|
|
11
13
|
import { devAuth } from "./dev-auth.js";
|
|
@@ -411,6 +413,7 @@ export function createServer(options) {
|
|
|
411
413
|
},
|
|
412
414
|
transport: syncOptions?.transport,
|
|
413
415
|
pollIntervalMs: syncOptions?.pollIntervalMs,
|
|
416
|
+
build: serverBuild,
|
|
414
417
|
channels: [
|
|
415
418
|
...(agentUi ? [agentUi.channel] : []),
|
|
416
419
|
...runtimes.flatMap((entry) => entry.runtime.channel ? [gatedChannel(entry, entry.runtime.channel)] : []),
|
|
@@ -438,7 +441,7 @@ export function createServer(options) {
|
|
|
438
441
|
agentUi?.install(source);
|
|
439
442
|
},
|
|
440
443
|
fetch: (request) => {
|
|
441
|
-
const response = Promise.resolve(app.fetch(request));
|
|
444
|
+
const response = Promise.resolve(app.fetch(request)).then(stampBuild);
|
|
442
445
|
const settled = () => void inflight.delete(response);
|
|
443
446
|
inflight.add(response);
|
|
444
447
|
response.then(settled, settled);
|
|
@@ -452,4 +455,16 @@ export function createServer(options) {
|
|
|
452
455
|
})()),
|
|
453
456
|
};
|
|
454
457
|
}
|
|
458
|
+
/** Names the build on a response, copying one whose headers cannot change, such as a proxied fetch's. */
|
|
459
|
+
function stampBuild(response) {
|
|
460
|
+
try {
|
|
461
|
+
response.headers.set(BUILD_HEADER, serverBuild());
|
|
462
|
+
return response;
|
|
463
|
+
}
|
|
464
|
+
catch {
|
|
465
|
+
const copy = new Response(response.body, response);
|
|
466
|
+
copy.headers.set(BUILD_HEADER, serverBuild());
|
|
467
|
+
return copy;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
455
470
|
//# sourceMappingURL=create-server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-server.js","sourceRoot":"","sources":["../src/create-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAEL,aAAa,EACb,qBAAqB,GAGtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,WAAW,EAGX,SAAS,EAGT,kBAAkB,EAClB,OAAO,EACP,cAA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{ pagePattern, UNROUTED_HEADER } from \"@parlor/agent-ui\";\nimport {\n type AgentUiOptions,\n createAgentUi,\n registerAgentUiRoutes,\n type UiManifestInput,\n type UiManifestSource,\n} from \"@parlor/agent-ui/server\";\nimport {\n ActionError,\n type ActionErrorCode,\n type ActionMap,\n ANONYMOUS,\n type ConfirmationPolicy,\n type DataProvider,\n decodeReadRequests,\n hasUser,\n REFRESH_HEADER,\n} from \"@parlor/core\";\nimport type { ActionRegistry } from \"@parlor/core/registry\";\nimport type { ServerChannel } from \"@parlor/sync\";\nimport {\n ensureSyncTables,\n recordSyncEvent,\n registerSyncRoutes,\n type SyncDatabase,\n SyncHub,\n type SyncTransport,\n} from \"@parlor/sync/server\";\nimport { H3, type H3Event, readBody } from \"h3\";\n\nimport { admits, requireAccess, requireSurface, type Surface } from \"./access.js\";\nimport { type ActionRunner, createActionRunner } from \"./actions.js\";\nimport { AuthFailure, type AuthProvider } from \"./auth.js\";\nimport {\n type Caller,\n type CallerResolver,\n clientOf,\n createCallerResolver,\n sourceOf,\n} from \"./caller.js\";\nimport { type CorsConfig, corsMiddleware } from \"./cors.js\";\nimport { devAuth } from \"./dev-auth.js\";\nimport { createMcpHandler } from \"./mcp.js\";\nimport { applyMigrations, checkMigrations } from \"./migrations.js\";\nimport type {\n ActionAudit,\n AnyPluginRoute,\n PluginCaller,\n PluginHost,\n PluginRuntime,\n ServerPlugin,\n} from \"./plugin.js\";\nimport { DEFAULT_BASE_PATH, type Manifest, PROTOCOL_VERSION } from \"./protocol.js\";\nimport { refreshReads } from \"./refresh.js\";\nimport { defaultScope, type ScopeResolver } from \"./scope.js\";\nimport {\n type ActionVisibility,\n createRegistryResolver,\n type RegistryResolver,\n} from \"./visibility.js\";\n\nexport interface SyncOptions {\n readonly transport?: SyncTransport | undefined;\n readonly pollIntervalMs?: number | undefined;\n}\n\nexport interface ServerOptions<T extends ActionMap> {\n readonly actions: ActionRegistry<T>;\n readonly scope?: ScopeResolver | undefined;\n /**\n * Without it every caller is anonymous, the action source is the `x-parlor-source`\n * header, and confirmations are a UX guard.\n */\n readonly auth?: AuthProvider | undefined;\n /** Framework features with their own tables and routes, installed after `auth`. */\n readonly plugins?: readonly ServerPlugin[] | undefined;\n readonly basePath?: string | undefined;\n readonly cors?: CorsConfig | false | undefined;\n readonly database?: DataProvider | undefined;\n readonly mcp?:\n | { readonly name?: string | undefined; readonly version?: string | undefined }\n | false\n | undefined;\n readonly sync?: SyncOptions | false | undefined;\n readonly agentUi?: AgentUiOptions | false | undefined;\n /**\n * Decides, for each call, whether the user approves it in the app first (`ask`), it runs\n * (`proceed`) or it fails with `confirmation_unavailable` (`refuse`). Defaults to\n * `defaultConfirmationPolicy`: agents are asked about `confirm: true` actions and keys are\n * refused them.\n */\n readonly confirmation?: ConfirmationPolicy | undefined;\n /**\n * Which of `actions` each caller may see and call, decided once per request. A hidden\n * action is left out of the manifest and MCP `tools/list`, and a call to it answers\n * `not_found` like an action that does not exist. Plugins' actions are never filtered.\n * Absent, every action is visible.\n */\n readonly visible?: ActionVisibility | undefined;\n}\n\ntype ManifestSummary = Pick<Manifest, \"protocol\" | \"app\">;\ntype ManifestReply = Manifest | ManifestSummary | Response;\n\nexport interface FrameworkServer {\n /**\n * Hands the server the app's page routes, called by the host before the first request.\n * Throws when a page route would take a document request meant for an absolute route.\n */\n readonly installUiManifest?: ((source: UiManifestSource) => void) | undefined;\n readonly fetch: (request: Request) => Promise<Response>;\n readonly close: () => Promise<void>;\n}\n\nconst STATUS_BY_CODE = {\n not_found: 404,\n invalid_input: 400,\n declined: 403,\n confirmation_timeout: 504,\n confirmation_unavailable: 503,\n unauthenticated: 401,\n forbidden: 403,\n internal: 500,\n} as const satisfies Record<ActionErrorCode, number>;\n\nconst isAbort = (error: unknown) => error instanceof Error && error.name === \"AbortError\";\n\nfunction toActionError(error: unknown): ActionError {\n if (error instanceof ActionError) return error;\n if (error instanceof AuthFailure)\n return new ActionError(\"unauthenticated\", error.message);\n if (!isAbort(error)) console.error(\"[parlor] action failed:\", error);\n return new ActionError(\"internal\", \"Internal error\", { cause: error });\n}\n\nfunction errorBody(event: H3Event, error: unknown) {\n const actionError = toActionError(error);\n event.res.status = STATUS_BY_CODE[actionError.code];\n return actionError.toBody();\n}\n\nfunction errorResponse(error: unknown): Response {\n const actionError = toActionError(error);\n return Response.json(actionError.toBody(), {\n status: STATUS_BY_CODE[actionError.code],\n });\n}\n\nconst PLUGIN_NAME = /^[a-z][a-z0-9-]*$/;\nconst RESERVED_NAMES: ReadonlySet<string> = new Set([\n \"actions\",\n \"manifest\",\n \"mcp\",\n \"sync\",\n \"ui\",\n]);\n\nfunction checkPlugins(\n plugins: readonly ServerPlugin[],\n database: DataProvider | undefined,\n): void {\n const names = new Set<string>();\n for (const plugin of plugins) {\n if (!PLUGIN_NAME.test(plugin.name) || RESERVED_NAMES.has(plugin.name)) {\n throw new Error(`\"${plugin.name}\" cannot name a plugin.`);\n }\n if (names.has(plugin.name))\n throw new Error(`Two plugins are named \"${plugin.name}\".`);\n names.add(plugin.name);\n checkMigrations(plugin);\n if (plugin.migrations?.length && !database) {\n throw new Error(`The \"${plugin.name}\" plugin needs a database.`);\n }\n }\n}\n\ninterface MountedRoute {\n readonly plugin: string;\n readonly route: AnyPluginRoute;\n readonly path: string;\n}\n\nconst isAbsolute = (route: AnyPluginRoute) =>\n route.absolute === true || route.path.startsWith(\"/.well-known/\");\n\nfunction mountRoutes(\n runtimes: readonly { readonly plugin: ServerPlugin; readonly runtime: PluginRuntime }[],\n basePath: string,\n): MountedRoute[] {\n const mounted: MountedRoute[] = [];\n const owners = new Map<string, string>();\n for (const { plugin, runtime } of runtimes) {\n for (const route of runtime.routes ?? []) {\n if (!isAbsolute(route)) {\n mounted.push({\n plugin: plugin.name,\n route,\n path: `${basePath}/${plugin.name}${route.path}`,\n });\n continue;\n }\n const { method, path } = route;\n if (route.absolute && /[:*]/.test(path)) {\n throw new Error(\n `The \"${plugin.name}\" plugin's absolute route ${method} ${path} must be a static path.`,\n );\n }\n if (path === basePath || path.startsWith(`${basePath}/`)) {\n throw new Error(\n `The \"${plugin.name}\" plugin's absolute route ${method} ${path} is under ${basePath}, which the framework serves.`,\n );\n }\n const key = `${method} ${path}`;\n const owner = owners.get(key);\n if (owner !== undefined) {\n throw new Error(\n owner === plugin.name\n ? `The \"${owner}\" plugin serves ${key} twice.`\n : `The \"${owner}\" and \"${plugin.name}\" plugins both serve ${key}.`,\n );\n }\n owners.set(key, plugin.name);\n mounted.push({ plugin: plugin.name, route, path });\n }\n }\n return mounted;\n}\n\nfunction refuseShadowedRoutes(\n manifest: UiManifestInput | undefined,\n routes: readonly MountedRoute[],\n): void {\n if (!manifest) return;\n const pages = manifest.routes.map((page) => ({\n page,\n pattern: pagePattern(page.path),\n }));\n for (const { plugin, route } of routes) {\n if (!route.absolute || route.method !== \"GET\") continue;\n const shadow = pages.find(({ pattern }) => pattern.test(route.path));\n if (shadow) {\n throw new Error(\n `The \"${plugin}\" plugin's absolute route GET ${route.path} is also matched by the page route ${shadow.page.path}, so a browser opening it would get the page. Move one of them.`,\n );\n }\n }\n}\n\nfunction auditAll(\n runtimes: readonly PluginRuntime[],\n): ((record: ActionAudit) => void) | undefined {\n const hooks = runtimes.filter((runtime) => runtime.audit);\n if (hooks.length === 0) return undefined;\n return (record) => {\n for (const runtime of hooks) runtime.audit?.(record);\n };\n}\n\ninterface Installed {\n readonly plugin: ServerPlugin;\n readonly runtime: PluginRuntime;\n}\n\nasync function allowedBy({ runtime }: Installed, caller: PluginCaller): Promise<boolean> {\n return !runtime.allows || (await runtime.allows(caller));\n}\n\nfunction admitterOf(installed: Installed) {\n return async (caller: PluginCaller): Promise<void> => {\n if (await allowedBy(installed, caller)) return;\n throw new ActionError(\n \"forbidden\",\n `This account cannot use ${installed.plugin.name}.`,\n );\n };\n}\n\n/** Joins a connection to `channel` only once the plugin admits its holder. */\nfunction gatedChannel(installed: Installed, channel: ServerChannel): ServerChannel {\n if (!installed.runtime.allows) return channel;\n return {\n event: channel.event,\n hosts: channel.hosts,\n connect(connection) {\n let detach: (() => void) | undefined;\n let left = false;\n allowedBy(installed, {\n principal: connection.principal ?? ANONYMOUS,\n scope: connection.scope,\n }).then(\n (allowed) => {\n if (allowed && !left && !connection.closed?.aborted) {\n detach = channel.connect(connection);\n }\n },\n (error: unknown) => {\n console.error(`[parlor] ${installed.plugin.name}: access check failed:`, error);\n },\n );\n return () => {\n left = true;\n detach?.();\n };\n },\n };\n}\n\nfunction guard(callers: CallerResolver, surface: Surface) {\n return async (request: Request): Promise<Caller> =>\n requireSurface(await callers(request), surface, callers.enforcing);\n}\n\nfunction refuseUnless(callers: CallerResolver, surface: Surface) {\n const check = guard(callers, surface);\n return async (event: H3Event): Promise<Response | undefined> => {\n try {\n await check(event.req);\n return undefined;\n } catch (error) {\n return errorResponse(error);\n }\n };\n}\n\nexport function createServer<T extends ActionMap>(\n options: ServerOptions<T>,\n): FrameworkServer {\n const {\n actions,\n scope = defaultScope,\n plugins = [],\n basePath = DEFAULT_BASE_PATH,\n cors = {},\n database,\n mcp = {},\n sync = {},\n agentUi: agentUiOptions = {},\n confirmation,\n } = options;\n const auth = options.auth ?? (process.env.PARLOR_DEV === \"1\" ? devAuth() : undefined);\n const app = new H3();\n const appName = process.env.PARLOR_APP_NAME || undefined;\n const syncOptions = sync === false ? undefined : sync;\n const syncEnabled = syncOptions !== undefined && database !== undefined;\n const installed = [...(auth ? [auth] : []), ...plugins];\n checkPlugins(installed, database);\n let prepared: Promise<void> | undefined;\n const ready = () =>\n (prepared ??= (async () => {\n if (database) {\n await database.prepare?.();\n if (syncEnabled) await ensureSyncTables(database.read() as SyncDatabase);\n await applyMigrations(database, installed);\n }\n for (const { runtime } of runtimes) runtime.start?.();\n })());\n const callers = createCallerResolver(auth, scope, ready);\n const registryFor = createRegistryResolver(actions, options.visible, callers);\n const host: PluginHost = {\n basePath,\n database,\n ...(auth ? { auth } : {}),\n authMisconfigured: \"auth\" in options && auth === undefined,\n callerOf: callers,\n allows: async (name, caller) => {\n const entry = runtimes.find(({ plugin }) => plugin.name === name);\n return entry === undefined || (await allowedBy(entry, caller));\n },\n ready,\n announce: async (target, tags, within) => {\n if (!syncEnabled || !database || tags.length === 0) return;\n if (within !== undefined) {\n await recordSyncEvent(within as SyncDatabase, { scope: target, tags });\n return;\n }\n await ready();\n await database.transaction((tx) =>\n recordSyncEvent(tx as SyncDatabase, { scope: target, tags }),\n );\n },\n };\n const runtimes: Installed[] = installed.map((plugin) => ({\n plugin,\n runtime: plugin.setup(host),\n }));\n const routes = mountRoutes(runtimes, basePath);\n const audit = auditAll(runtimes.map(({ runtime }) => runtime));\n const agentUi =\n agentUiOptions === false\n ? undefined\n : createAgentUi({\n ...agentUiOptions,\n audience: async (request) => (await callers(request)).audience,\n });\n const runnerFor = (\n registry: ActionRegistry,\n admit?: (caller: Caller) => Promise<void>,\n registryOf?: RegistryResolver,\n ): ActionRunner =>\n createActionRunner({\n actions: registry,\n scope,\n callers,\n database,\n sync: syncEnabled,\n onClient: agentUi?.touch,\n confirm: agentUi?.confirm,\n confirmation,\n audit,\n admit,\n registryFor: registryOf,\n ready,\n });\n const runner = runnerFor(actions, undefined, registryFor);\n const hub = database ? new SyncHub(database) : undefined;\n const inflight = new Set<Promise<unknown>>();\n let closing: Promise<void> | undefined;\n\n if (cors !== false) app.use(corsMiddleware(cors));\n\n app.get(`${basePath}/manifest`, async (event): Promise<ManifestReply> => {\n let caller: Caller;\n try {\n caller = await callers(event.req);\n } catch (error) {\n return errorResponse(error);\n }\n const summary: ManifestSummary = {\n protocol: PROTOCOL_VERSION,\n ...(appName ? { app: { name: appName } } : {}),\n };\n if (!admits(\"manifest\", caller, callers.enforcing)) return summary;\n const ui = agentUi?.manifest();\n let visible: ActionRegistry;\n try {\n visible = await registryFor(event.req);\n } catch (error) {\n return errorResponse(error);\n }\n return { ...summary, actions: visible.describe(), ...(ui ? { ui } : {}) };\n });\n\n app.post(`${basePath}/actions/:name`, async (event) => {\n const name = event.context.params?.name ?? \"\";\n try {\n const input = await readBody(event).catch(() => {\n throw new ActionError(\"invalid_input\", \"Request body must be JSON\");\n });\n const source = sourceOf(event.req);\n const run = (action: string, actionInput: unknown) =>\n runner.run(action, actionInput, event.req, source, {\n surface: \"actions\",\n cursor: true,\n });\n const result = await run(name, input);\n const answer = { data: result.data, tags: result.reads, cursor: result.cursor };\n const reads = decodeReadRequests(event.req.headers.get(REFRESH_HEADER));\n if (!reads) return answer;\n const refreshed = await refreshReads(\n await registryFor(event.req),\n reads,\n result.writes,\n async (action, actionInput) => {\n const read = await run(action, actionInput);\n return { data: read.data, tags: read.reads, cursor: read.cursor };\n },\n (error) => toActionError(error).toBody(),\n );\n return { ...answer, writes: result.writes, refreshed };\n } catch (error) {\n return errorBody(event, error);\n }\n });\n\n const handleRoute = async (\n route: AnyPluginRoute,\n request: Request,\n admit: (caller: PluginCaller) => Promise<void>,\n ) => {\n if (route.access === \"public\") return route.handle(request);\n const caller = requireAccess(await callers(request), route.access, callers.enforcing);\n await admit(caller);\n return route.handle(request, caller);\n };\n\n const admitters = new Map(\n runtimes.map((entry) => [entry.plugin.name, admitterOf(entry)]),\n );\n for (const entry of runtimes) {\n const { plugin, runtime } = entry;\n if (runtime.actions) {\n const admit = admitters.get(plugin.name)!;\n const pluginRunner = runnerFor(runtime.actions, runtime.allows ? admit : undefined);\n app.post(`${basePath}/${plugin.name}/actions/:name`, async (event) => {\n const name = event.context.params?.name ?? \"\";\n try {\n const input = await readBody(event).catch(() => {\n throw new ActionError(\"invalid_input\", \"Request body must be JSON\");\n });\n const result = await pluginRunner.run(\n name,\n input,\n event.req,\n sourceOf(event.req),\n { surface: \"pluginActions\", cursor: true },\n );\n return { data: result.data, tags: result.reads, cursor: result.cursor };\n } catch (error) {\n return errorBody(event, error);\n }\n });\n }\n }\n for (const { plugin, route, path } of routes) {\n const admit = admitters.get(plugin)!;\n app.on(route.method, path, async (event) => {\n try {\n await ready();\n return await handleRoute(route, event.req, admit);\n } catch (error) {\n return errorResponse(error);\n }\n });\n }\n\n if (mcp !== false) {\n const mcpApp = appName\n ? {\n name: appName,\n ...(process.env.PARLOR_APP_DESCRIPTION\n ? { description: process.env.PARLOR_APP_DESCRIPTION }\n : {}),\n }\n : undefined;\n const handler = createMcpHandler({\n actions,\n runner,\n agentUi,\n callers,\n confirmation,\n registryFor,\n app: mcpApp,\n ...mcp,\n });\n const guardMcp = guard(callers, \"mcp\");\n app.all(`${basePath}/mcp`, async (event) => {\n try {\n await guardMcp(event.req);\n } catch (error) {\n const refusal = toActionError(error);\n const signInHelps = !(error instanceof AuthFailure) || error.challenge;\n const challenged =\n (refusal.code === \"unauthenticated\" && signInHelps) ||\n (await callers(event.req).then(\n ({ principal }) => principal.kind === \"host\",\n () => false,\n ));\n return challenged && auth ? auth.challenge(event.req) : errorResponse(refusal);\n }\n try {\n await registryFor(event.req);\n } catch (error) {\n return errorResponse(error);\n }\n return handler.fetch(event.req);\n });\n }\n\n if (syncEnabled && database && hub) {\n app.use(`${basePath}/sync/**`, refuseUnless(callers, \"sync\"));\n app.use(`${basePath}/sync/**`, async () => {\n await ready();\n });\n registerSyncRoutes(app, {\n basePath,\n data: database,\n hub,\n scope: async (request) => (await callers(request)).scope,\n audience: async (request) => (await callers(request)).audience,\n account: async (request) => (await callers(request)).account,\n authority: async (request) => {\n const caller = await callers(request);\n const { principal } = caller;\n return {\n principal,\n channels: admits(\"channels\", caller, callers.enforcing)\n ? true\n : (channel: ServerChannel) =>\n principal.kind === \"host\" && channel.hosts === true,\n ...(auth && hasUser(principal) ? { revoked: auth.revoked(principal) } : {}),\n };\n },\n transport: syncOptions?.transport,\n pollIntervalMs: syncOptions?.pollIntervalMs,\n channels: [\n ...(agentUi ? [agentUi.channel] : []),\n ...runtimes.flatMap((entry): ServerChannel[] =>\n entry.runtime.channel ? [gatedChannel(entry, entry.runtime.channel)] : [],\n ),\n ],\n clientId: clientOf,\n });\n }\n\n if (agentUi) {\n app.use(`${basePath}/ui`, refuseUnless(callers, \"ui\"));\n registerAgentUiRoutes(app, {\n basePath,\n agentUi,\n audience: async (request) => (await callers(request)).audience,\n clientId: clientOf,\n });\n }\n\n app.all(\"/**\", (event) => {\n const response = errorResponse(\n new ActionError(\n \"not_found\",\n `No route for ${event.req.method} ${event.url.pathname}`,\n ),\n );\n response.headers.set(UNROUTED_HEADER, \"1\");\n return response;\n });\n\n return {\n installUiManifest: (source) => {\n refuseShadowedRoutes(source(), routes);\n agentUi?.install(source);\n },\n fetch: (request) => {\n const response = Promise.resolve(app.fetch(request));\n const settled = () => void inflight.delete(response);\n inflight.add(response);\n response.then(settled, settled);\n return response;\n },\n close: () =>\n (closing ??= (async () => {\n agentUi?.close();\n await Promise.allSettled(runtimes.map(({ runtime }) => runtime.close?.()));\n await Promise.all([hub?.stop(), Promise.allSettled([...inflight])]);\n await database?.close?.();\n })()),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"create-server.js","sourceRoot":"","sources":["../src/create-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAEL,aAAa,EACb,qBAAqB,GAGtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,WAAW,EAGX,SAAS,EAGT,kBAAkB,EAClB,OAAO,EACP,cAAc,GACf,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,YAAY,EAAsB,MAAM,cAAc,CAAC;AAChE,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAElB,OAAO,GAER,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,EAAE,EAAgB,QAAQ,EAAE,MAAM,IAAI,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAgB,MAAM,aAAa,CAAC;AAClF,OAAO,EAAqB,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,WAAW,EAAqB,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,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,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,WAAW,EAAE,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { pagePattern, UNROUTED_HEADER } from \"@parlor/agent-ui\";\nimport {\n type AgentUiOptions,\n createAgentUi,\n registerAgentUiRoutes,\n type UiManifestInput,\n type UiManifestSource,\n} from \"@parlor/agent-ui/server\";\nimport {\n ActionError,\n type ActionErrorCode,\n type ActionMap,\n ANONYMOUS,\n type ConfirmationPolicy,\n type DataProvider,\n decodeReadRequests,\n hasUser,\n REFRESH_HEADER,\n} from \"@parlor/core\";\nimport type { ActionRegistry } from \"@parlor/core/registry\";\nimport { BUILD_HEADER, type ServerChannel } from \"@parlor/sync\";\nimport {\n ensureSyncTables,\n recordSyncEvent,\n registerSyncRoutes,\n type SyncDatabase,\n SyncHub,\n type SyncTransport,\n} from \"@parlor/sync/server\";\nimport { H3, type H3Event, readBody } from \"h3\";\n\nimport { admits, requireAccess, requireSurface, type Surface } from \"./access.js\";\nimport { type ActionRunner, createActionRunner } from \"./actions.js\";\nimport { AuthFailure, type AuthProvider } from \"./auth.js\";\nimport { serverBuild } from \"./build.js\";\nimport {\n type Caller,\n type CallerResolver,\n clientOf,\n createCallerResolver,\n sourceOf,\n} from \"./caller.js\";\nimport { type CorsConfig, corsMiddleware } from \"./cors.js\";\nimport { devAuth } from \"./dev-auth.js\";\nimport { createMcpHandler } from \"./mcp.js\";\nimport { applyMigrations, checkMigrations } from \"./migrations.js\";\nimport type {\n ActionAudit,\n AnyPluginRoute,\n PluginCaller,\n PluginHost,\n PluginRuntime,\n ServerPlugin,\n} from \"./plugin.js\";\nimport { DEFAULT_BASE_PATH, type Manifest, PROTOCOL_VERSION } from \"./protocol.js\";\nimport { refreshReads } from \"./refresh.js\";\nimport { defaultScope, type ScopeResolver } from \"./scope.js\";\nimport {\n type ActionVisibility,\n createRegistryResolver,\n type RegistryResolver,\n} from \"./visibility.js\";\n\nexport interface SyncOptions {\n readonly transport?: SyncTransport | undefined;\n readonly pollIntervalMs?: number | undefined;\n}\n\nexport interface ServerOptions<T extends ActionMap> {\n readonly actions: ActionRegistry<T>;\n readonly scope?: ScopeResolver | undefined;\n /**\n * Without it every caller is anonymous, the action source is the `x-parlor-source`\n * header, and confirmations are a UX guard.\n */\n readonly auth?: AuthProvider | undefined;\n /** Framework features with their own tables and routes, installed after `auth`. */\n readonly plugins?: readonly ServerPlugin[] | undefined;\n readonly basePath?: string | undefined;\n readonly cors?: CorsConfig | false | undefined;\n readonly database?: DataProvider | undefined;\n readonly mcp?:\n | { readonly name?: string | undefined; readonly version?: string | undefined }\n | false\n | undefined;\n readonly sync?: SyncOptions | false | undefined;\n readonly agentUi?: AgentUiOptions | false | undefined;\n /**\n * Decides, for each call, whether the user approves it in the app first (`ask`), it runs\n * (`proceed`) or it fails with `confirmation_unavailable` (`refuse`). Defaults to\n * `defaultConfirmationPolicy`: agents are asked about `confirm: true` actions and keys are\n * refused them.\n */\n readonly confirmation?: ConfirmationPolicy | undefined;\n /**\n * Which of `actions` each caller may see and call, decided once per request. A hidden\n * action is left out of the manifest and MCP `tools/list`, and a call to it answers\n * `not_found` like an action that does not exist. Plugins' actions are never filtered.\n * Absent, every action is visible.\n */\n readonly visible?: ActionVisibility | undefined;\n}\n\ntype ManifestSummary = Pick<Manifest, \"protocol\" | \"app\">;\ntype ManifestReply = Manifest | ManifestSummary | Response;\n\nexport interface FrameworkServer {\n /**\n * Hands the server the app's page routes, called by the host before the first request.\n * Throws when a page route would take a document request meant for an absolute route.\n */\n readonly installUiManifest?: ((source: UiManifestSource) => void) | undefined;\n readonly fetch: (request: Request) => Promise<Response>;\n readonly close: () => Promise<void>;\n}\n\nconst STATUS_BY_CODE = {\n not_found: 404,\n invalid_input: 400,\n declined: 403,\n confirmation_timeout: 504,\n confirmation_unavailable: 503,\n unauthenticated: 401,\n forbidden: 403,\n internal: 500,\n} as const satisfies Record<ActionErrorCode, number>;\n\nconst isAbort = (error: unknown) => error instanceof Error && error.name === \"AbortError\";\n\nfunction toActionError(error: unknown): ActionError {\n if (error instanceof ActionError) return error;\n if (error instanceof AuthFailure)\n return new ActionError(\"unauthenticated\", error.message);\n if (!isAbort(error)) console.error(\"[parlor] action failed:\", error);\n return new ActionError(\"internal\", \"Internal error\", { cause: error });\n}\n\nfunction errorBody(event: H3Event, error: unknown) {\n const actionError = toActionError(error);\n event.res.status = STATUS_BY_CODE[actionError.code];\n return actionError.toBody();\n}\n\nfunction errorResponse(error: unknown): Response {\n const actionError = toActionError(error);\n return Response.json(actionError.toBody(), {\n status: STATUS_BY_CODE[actionError.code],\n });\n}\n\nconst PLUGIN_NAME = /^[a-z][a-z0-9-]*$/;\nconst RESERVED_NAMES: ReadonlySet<string> = new Set([\n \"actions\",\n \"manifest\",\n \"mcp\",\n \"sync\",\n \"ui\",\n]);\n\nfunction checkPlugins(\n plugins: readonly ServerPlugin[],\n database: DataProvider | undefined,\n): void {\n const names = new Set<string>();\n for (const plugin of plugins) {\n if (!PLUGIN_NAME.test(plugin.name) || RESERVED_NAMES.has(plugin.name)) {\n throw new Error(`\"${plugin.name}\" cannot name a plugin.`);\n }\n if (names.has(plugin.name))\n throw new Error(`Two plugins are named \"${plugin.name}\".`);\n names.add(plugin.name);\n checkMigrations(plugin);\n if (plugin.migrations?.length && !database) {\n throw new Error(`The \"${plugin.name}\" plugin needs a database.`);\n }\n }\n}\n\ninterface MountedRoute {\n readonly plugin: string;\n readonly route: AnyPluginRoute;\n readonly path: string;\n}\n\nconst isAbsolute = (route: AnyPluginRoute) =>\n route.absolute === true || route.path.startsWith(\"/.well-known/\");\n\nfunction mountRoutes(\n runtimes: readonly { readonly plugin: ServerPlugin; readonly runtime: PluginRuntime }[],\n basePath: string,\n): MountedRoute[] {\n const mounted: MountedRoute[] = [];\n const owners = new Map<string, string>();\n for (const { plugin, runtime } of runtimes) {\n for (const route of runtime.routes ?? []) {\n if (!isAbsolute(route)) {\n mounted.push({\n plugin: plugin.name,\n route,\n path: `${basePath}/${plugin.name}${route.path}`,\n });\n continue;\n }\n const { method, path } = route;\n if (route.absolute && /[:*]/.test(path)) {\n throw new Error(\n `The \"${plugin.name}\" plugin's absolute route ${method} ${path} must be a static path.`,\n );\n }\n if (path === basePath || path.startsWith(`${basePath}/`)) {\n throw new Error(\n `The \"${plugin.name}\" plugin's absolute route ${method} ${path} is under ${basePath}, which the framework serves.`,\n );\n }\n const key = `${method} ${path}`;\n const owner = owners.get(key);\n if (owner !== undefined) {\n throw new Error(\n owner === plugin.name\n ? `The \"${owner}\" plugin serves ${key} twice.`\n : `The \"${owner}\" and \"${plugin.name}\" plugins both serve ${key}.`,\n );\n }\n owners.set(key, plugin.name);\n mounted.push({ plugin: plugin.name, route, path });\n }\n }\n return mounted;\n}\n\nfunction refuseShadowedRoutes(\n manifest: UiManifestInput | undefined,\n routes: readonly MountedRoute[],\n): void {\n if (!manifest) return;\n const pages = manifest.routes.map((page) => ({\n page,\n pattern: pagePattern(page.path),\n }));\n for (const { plugin, route } of routes) {\n if (!route.absolute || route.method !== \"GET\") continue;\n const shadow = pages.find(({ pattern }) => pattern.test(route.path));\n if (shadow) {\n throw new Error(\n `The \"${plugin}\" plugin's absolute route GET ${route.path} is also matched by the page route ${shadow.page.path}, so a browser opening it would get the page. Move one of them.`,\n );\n }\n }\n}\n\nfunction auditAll(\n runtimes: readonly PluginRuntime[],\n): ((record: ActionAudit) => void) | undefined {\n const hooks = runtimes.filter((runtime) => runtime.audit);\n if (hooks.length === 0) return undefined;\n return (record) => {\n for (const runtime of hooks) runtime.audit?.(record);\n };\n}\n\ninterface Installed {\n readonly plugin: ServerPlugin;\n readonly runtime: PluginRuntime;\n}\n\nasync function allowedBy({ runtime }: Installed, caller: PluginCaller): Promise<boolean> {\n return !runtime.allows || (await runtime.allows(caller));\n}\n\nfunction admitterOf(installed: Installed) {\n return async (caller: PluginCaller): Promise<void> => {\n if (await allowedBy(installed, caller)) return;\n throw new ActionError(\n \"forbidden\",\n `This account cannot use ${installed.plugin.name}.`,\n );\n };\n}\n\n/** Joins a connection to `channel` only once the plugin admits its holder. */\nfunction gatedChannel(installed: Installed, channel: ServerChannel): ServerChannel {\n if (!installed.runtime.allows) return channel;\n return {\n event: channel.event,\n hosts: channel.hosts,\n connect(connection) {\n let detach: (() => void) | undefined;\n let left = false;\n allowedBy(installed, {\n principal: connection.principal ?? ANONYMOUS,\n scope: connection.scope,\n }).then(\n (allowed) => {\n if (allowed && !left && !connection.closed?.aborted) {\n detach = channel.connect(connection);\n }\n },\n (error: unknown) => {\n console.error(`[parlor] ${installed.plugin.name}: access check failed:`, error);\n },\n );\n return () => {\n left = true;\n detach?.();\n };\n },\n };\n}\n\nfunction guard(callers: CallerResolver, surface: Surface) {\n return async (request: Request): Promise<Caller> =>\n requireSurface(await callers(request), surface, callers.enforcing);\n}\n\nfunction refuseUnless(callers: CallerResolver, surface: Surface) {\n const check = guard(callers, surface);\n return async (event: H3Event): Promise<Response | undefined> => {\n try {\n await check(event.req);\n return undefined;\n } catch (error) {\n return errorResponse(error);\n }\n };\n}\n\nexport function createServer<T extends ActionMap>(\n options: ServerOptions<T>,\n): FrameworkServer {\n const {\n actions,\n scope = defaultScope,\n plugins = [],\n basePath = DEFAULT_BASE_PATH,\n cors = {},\n database,\n mcp = {},\n sync = {},\n agentUi: agentUiOptions = {},\n confirmation,\n } = options;\n const auth = options.auth ?? (process.env.PARLOR_DEV === \"1\" ? devAuth() : undefined);\n const app = new H3();\n const appName = process.env.PARLOR_APP_NAME || undefined;\n const syncOptions = sync === false ? undefined : sync;\n const syncEnabled = syncOptions !== undefined && database !== undefined;\n const installed = [...(auth ? [auth] : []), ...plugins];\n checkPlugins(installed, database);\n let prepared: Promise<void> | undefined;\n const ready = () =>\n (prepared ??= (async () => {\n if (database) {\n await database.prepare?.();\n if (syncEnabled) await ensureSyncTables(database.read() as SyncDatabase);\n await applyMigrations(database, installed);\n }\n for (const { runtime } of runtimes) runtime.start?.();\n })());\n const callers = createCallerResolver(auth, scope, ready);\n const registryFor = createRegistryResolver(actions, options.visible, callers);\n const host: PluginHost = {\n basePath,\n database,\n ...(auth ? { auth } : {}),\n authMisconfigured: \"auth\" in options && auth === undefined,\n callerOf: callers,\n allows: async (name, caller) => {\n const entry = runtimes.find(({ plugin }) => plugin.name === name);\n return entry === undefined || (await allowedBy(entry, caller));\n },\n ready,\n announce: async (target, tags, within) => {\n if (!syncEnabled || !database || tags.length === 0) return;\n if (within !== undefined) {\n await recordSyncEvent(within as SyncDatabase, { scope: target, tags });\n return;\n }\n await ready();\n await database.transaction((tx) =>\n recordSyncEvent(tx as SyncDatabase, { scope: target, tags }),\n );\n },\n };\n const runtimes: Installed[] = installed.map((plugin) => ({\n plugin,\n runtime: plugin.setup(host),\n }));\n const routes = mountRoutes(runtimes, basePath);\n const audit = auditAll(runtimes.map(({ runtime }) => runtime));\n const agentUi =\n agentUiOptions === false\n ? undefined\n : createAgentUi({\n ...agentUiOptions,\n audience: async (request) => (await callers(request)).audience,\n });\n const runnerFor = (\n registry: ActionRegistry,\n admit?: (caller: Caller) => Promise<void>,\n registryOf?: RegistryResolver,\n ): ActionRunner =>\n createActionRunner({\n actions: registry,\n scope,\n callers,\n database,\n sync: syncEnabled,\n onClient: agentUi?.touch,\n confirm: agentUi?.confirm,\n confirmation,\n audit,\n admit,\n registryFor: registryOf,\n ready,\n });\n const runner = runnerFor(actions, undefined, registryFor);\n const hub = database ? new SyncHub(database) : undefined;\n const inflight = new Set<Promise<unknown>>();\n let closing: Promise<void> | undefined;\n\n if (cors !== false) app.use(corsMiddleware(cors));\n\n app.get(`${basePath}/manifest`, async (event): Promise<ManifestReply> => {\n let caller: Caller;\n try {\n caller = await callers(event.req);\n } catch (error) {\n return errorResponse(error);\n }\n const summary: ManifestSummary = {\n protocol: PROTOCOL_VERSION,\n ...(appName ? { app: { name: appName } } : {}),\n };\n if (!admits(\"manifest\", caller, callers.enforcing)) return summary;\n const ui = agentUi?.manifest();\n let visible: ActionRegistry;\n try {\n visible = await registryFor(event.req);\n } catch (error) {\n return errorResponse(error);\n }\n return { ...summary, actions: visible.describe(), ...(ui ? { ui } : {}) };\n });\n\n app.post(`${basePath}/actions/:name`, async (event) => {\n const name = event.context.params?.name ?? \"\";\n try {\n const input = await readBody(event).catch(() => {\n throw new ActionError(\"invalid_input\", \"Request body must be JSON\");\n });\n const source = sourceOf(event.req);\n const run = (action: string, actionInput: unknown) =>\n runner.run(action, actionInput, event.req, source, {\n surface: \"actions\",\n cursor: true,\n });\n const result = await run(name, input);\n const answer = { data: result.data, tags: result.reads, cursor: result.cursor };\n const reads = decodeReadRequests(event.req.headers.get(REFRESH_HEADER));\n if (!reads) return answer;\n const refreshed = await refreshReads(\n await registryFor(event.req),\n reads,\n result.writes,\n async (action, actionInput) => {\n const read = await run(action, actionInput);\n return { data: read.data, tags: read.reads, cursor: read.cursor };\n },\n (error) => toActionError(error).toBody(),\n );\n return { ...answer, writes: result.writes, refreshed };\n } catch (error) {\n return errorBody(event, error);\n }\n });\n\n const handleRoute = async (\n route: AnyPluginRoute,\n request: Request,\n admit: (caller: PluginCaller) => Promise<void>,\n ) => {\n if (route.access === \"public\") return route.handle(request);\n const caller = requireAccess(await callers(request), route.access, callers.enforcing);\n await admit(caller);\n return route.handle(request, caller);\n };\n\n const admitters = new Map(\n runtimes.map((entry) => [entry.plugin.name, admitterOf(entry)]),\n );\n for (const entry of runtimes) {\n const { plugin, runtime } = entry;\n if (runtime.actions) {\n const admit = admitters.get(plugin.name)!;\n const pluginRunner = runnerFor(runtime.actions, runtime.allows ? admit : undefined);\n app.post(`${basePath}/${plugin.name}/actions/:name`, async (event) => {\n const name = event.context.params?.name ?? \"\";\n try {\n const input = await readBody(event).catch(() => {\n throw new ActionError(\"invalid_input\", \"Request body must be JSON\");\n });\n const result = await pluginRunner.run(\n name,\n input,\n event.req,\n sourceOf(event.req),\n { surface: \"pluginActions\", cursor: true },\n );\n return { data: result.data, tags: result.reads, cursor: result.cursor };\n } catch (error) {\n return errorBody(event, error);\n }\n });\n }\n }\n for (const { plugin, route, path } of routes) {\n const admit = admitters.get(plugin)!;\n app.on(route.method, path, async (event) => {\n try {\n await ready();\n return await handleRoute(route, event.req, admit);\n } catch (error) {\n return errorResponse(error);\n }\n });\n }\n\n if (mcp !== false) {\n const mcpApp = appName\n ? {\n name: appName,\n ...(process.env.PARLOR_APP_DESCRIPTION\n ? { description: process.env.PARLOR_APP_DESCRIPTION }\n : {}),\n }\n : undefined;\n const handler = createMcpHandler({\n actions,\n runner,\n agentUi,\n callers,\n confirmation,\n registryFor,\n app: mcpApp,\n ...mcp,\n });\n const guardMcp = guard(callers, \"mcp\");\n app.all(`${basePath}/mcp`, async (event) => {\n try {\n await guardMcp(event.req);\n } catch (error) {\n const refusal = toActionError(error);\n const signInHelps = !(error instanceof AuthFailure) || error.challenge;\n const challenged =\n (refusal.code === \"unauthenticated\" && signInHelps) ||\n (await callers(event.req).then(\n ({ principal }) => principal.kind === \"host\",\n () => false,\n ));\n return challenged && auth ? auth.challenge(event.req) : errorResponse(refusal);\n }\n try {\n await registryFor(event.req);\n } catch (error) {\n return errorResponse(error);\n }\n return handler.fetch(event.req);\n });\n }\n\n if (syncEnabled && database && hub) {\n app.use(`${basePath}/sync/**`, refuseUnless(callers, \"sync\"));\n app.use(`${basePath}/sync/**`, async () => {\n await ready();\n });\n registerSyncRoutes(app, {\n basePath,\n data: database,\n hub,\n scope: async (request) => (await callers(request)).scope,\n audience: async (request) => (await callers(request)).audience,\n account: async (request) => (await callers(request)).account,\n authority: async (request) => {\n const caller = await callers(request);\n const { principal } = caller;\n return {\n principal,\n channels: admits(\"channels\", caller, callers.enforcing)\n ? true\n : (channel: ServerChannel) =>\n principal.kind === \"host\" && channel.hosts === true,\n ...(auth && hasUser(principal) ? { revoked: auth.revoked(principal) } : {}),\n };\n },\n transport: syncOptions?.transport,\n pollIntervalMs: syncOptions?.pollIntervalMs,\n build: serverBuild,\n channels: [\n ...(agentUi ? [agentUi.channel] : []),\n ...runtimes.flatMap((entry): ServerChannel[] =>\n entry.runtime.channel ? [gatedChannel(entry, entry.runtime.channel)] : [],\n ),\n ],\n clientId: clientOf,\n });\n }\n\n if (agentUi) {\n app.use(`${basePath}/ui`, refuseUnless(callers, \"ui\"));\n registerAgentUiRoutes(app, {\n basePath,\n agentUi,\n audience: async (request) => (await callers(request)).audience,\n clientId: clientOf,\n });\n }\n\n app.all(\"/**\", (event) => {\n const response = errorResponse(\n new ActionError(\n \"not_found\",\n `No route for ${event.req.method} ${event.url.pathname}`,\n ),\n );\n response.headers.set(UNROUTED_HEADER, \"1\");\n return response;\n });\n\n return {\n installUiManifest: (source) => {\n refuseShadowedRoutes(source(), routes);\n agentUi?.install(source);\n },\n fetch: (request) => {\n const response = Promise.resolve(app.fetch(request)).then(stampBuild);\n const settled = () => void inflight.delete(response);\n inflight.add(response);\n response.then(settled, settled);\n return response;\n },\n close: () =>\n (closing ??= (async () => {\n agentUi?.close();\n await Promise.allSettled(runtimes.map(({ runtime }) => runtime.close?.()));\n await Promise.all([hub?.stop(), Promise.allSettled([...inflight])]);\n await database?.close?.();\n })()),\n };\n}\n\n/** Names the build on a response, copying one whose headers cannot change, such as a proxied fetch's. */\nfunction stampBuild(response: Response): Response {\n try {\n response.headers.set(BUILD_HEADER, serverBuild());\n return response;\n } catch {\n const copy = new Response(response.body, response);\n copy.headers.set(BUILD_HEADER, serverBuild());\n return copy;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parlor/server",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"homepage": "https://cychien.github.io/parlor",
|
|
5
5
|
"bugs": "https://github.com/cychien/parlor/issues",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"drizzle-orm": "^0.45.4",
|
|
25
25
|
"h3": "^2.0.1",
|
|
26
26
|
"zod": "^4.6.5",
|
|
27
|
-
"@parlor/
|
|
28
|
-
"@parlor/sync": "0.4.
|
|
29
|
-
"@parlor/
|
|
27
|
+
"@parlor/agent-ui": "0.4.4",
|
|
28
|
+
"@parlor/sync": "0.4.4",
|
|
29
|
+
"@parlor/core": "0.4.4"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@modelcontextprotocol/client": "^2.3.1",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"srvx": "^1.0.5",
|
|
35
35
|
"typescript": "^7.0.2",
|
|
36
36
|
"vitest": "^5.0.3",
|
|
37
|
-
"@parlor/data": "0.4.
|
|
37
|
+
"@parlor/data": "0.4.4"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsc -p tsconfig.json",
|