@agimon-ai/po-session 0.0.0-alpha.2 → 0.0.0-alpha.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/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/extensions/server.cjs +97 -61
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts +1 -1
- package/dist/extensions/server.mjs +97 -60
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/index.cjs +6 -4
- package/dist/index.d.mts +131 -94
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/{sessionDelivery-DpLWlaum.mjs → sessionDelivery-CROSMn_N.mjs} +393 -240
- package/dist/sessionDelivery-CROSMn_N.mjs.map +1 -0
- package/dist/{sessionDelivery-CkuX6jlw.cjs → sessionDelivery-D7PFBTSg.cjs} +423 -246
- package/dist/sessionDelivery-D7PFBTSg.cjs.map +1 -0
- package/package.json +9 -9
- package/dist/sessionDelivery-CkuX6jlw.cjs.map +0 -1
- package/dist/sessionDelivery-DpLWlaum.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.mjs","names":["rootSession","apiRoute"],"sources":["../../src/services/peerInbox/index.ts","../../src/extensions/workspaces/sessions/(backend)/root.server.ts","../../src/services/peerInboxApi/index.ts","../../src/extensions/(backend)/api/session-peer/route.server.ts","../../generated/server.ts"],"sourcesContent":["import type { DoomSessionDeliveryInboxState } from '../sessionDelivery';\n\nexport type SessionPeerInbox = (\n sourceKey: string,\n type: string,\n payload: unknown,\n) => DoomSessionDeliveryInboxState | undefined;\n\nconst inboxes = new Map<string, SessionPeerInbox>();\n\n/** Registers one live session-owned peer inbox. This registry is reachable only by the Session route. */\nexport function registerSessionPeerInbox(sessionId: string, inbox: SessionPeerInbox): () => void {\n if (inboxes.has(sessionId)) throw new Error(`Session peer inbox '${sessionId}' is already registered.`);\n inboxes.set(sessionId, inbox);\n return () => {\n if (inboxes.get(sessionId) === inbox) inboxes.delete(sessionId);\n };\n}\n\nexport function deliverSessionPeerEnvelope(\n targetSessionId: string,\n sourceKey: string,\n type: string,\n payload: unknown,\n): DoomSessionDeliveryInboxState | undefined {\n return inboxes.get(targetSessionId)?.(sourceKey, type, payload);\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { defineRoot } from '@agimon-ai/po-core/extensionFile';\nimport { poHomeDirectory } from '@agimon-ai/po-core/piSettings';\nimport type { DoomServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport { provideBackgroundWorkService } from '../../../../services/backgroundWorkService';\nimport { registerSessionPeerInbox } from '../../../../services/peerInbox';\nimport {\n createPeerCommunication,\n parseRemoteSessionReference,\n peerSessionReference,\n readSessionPeerConfig,\n} from '../../../../services/peerTransport';\nimport { provideSessionDeliveryService } from '../../../../services/sessionDelivery';\nimport { createSessionDirectory } from '../../../../services/sessionDirectory';\nimport { createSessionGroupStore } from '../../../../services/sessionGroups';\nimport {\n DOOM_SESSION_INTERCOM_SERVICE,\n createSessionGroupDeliveryAuthorizer,\n createSessionIntercom,\n} from '../../../../services/sessionIntercom';\n\nexport default defineRoot((pluginContext: DoomServerPluginContext) => ({\n value: undefined,\n services: [\n provideBackgroundWorkService,\n (context) => {\n const agent = pluginContext.agent;\n const session = agent?.context.session;\n const communication = pluginContext.host.context.sessionCommunication;\n const homeDirectory = pluginContext.host.context.homeDirectory;\n const sessionService = pluginContext.host.context.sessionService;\n if (!agent || !session?.admitPrompt || !communication || !homeDirectory || !sessionService?.canCommunicate) {\n throw new Error(\n 'Session delivery requires the headless agent, authenticated session communication, host home directory, and communication policy.',\n );\n }\n const sessionDirectory = path.join(poHomeDirectory(homeDirectory), 'session');\n const deliveryDirectory = path.join(sessionDirectory, 'delivery');\n fs.mkdirSync(deliveryDirectory, { recursive: true, mode: 0o700 });\n const peerCommunication = createPeerCommunication({ local: communication, homeDirectory });\n const peerConfig = readSessionPeerConfig(homeDirectory);\n const remotePeerIsGranted = (peerKey: string): boolean => {\n const peer = parseRemoteSessionReference(peerKey);\n return (\n peer !== undefined &&\n peerConfig?.peers.some(\n (candidate) =>\n candidate.hostId === peer.hostId && candidate.allowedSessionIds.includes(agent.context.sessionId),\n ) === true\n );\n };\n const fallbackAuthorization = (peerKey: string): boolean =>\n sessionService.canCommunicate?.(agent.context.sessionId, peerKey) === true || remotePeerIsGranted(peerKey);\n const groups = peerConfig\n ? createSessionGroupStore({ databasePath: path.join(sessionDirectory, 'groups.sqlite') })\n : undefined;\n const localHostId = peerConfig?.hostId;\n const selfReference = localHostId ? peerSessionReference(localHostId, agent.context.sessionId) : undefined;\n const groupAuthorization =\n groups && selfReference && localHostId\n ? createSessionGroupDeliveryAuthorizer({\n selfReference,\n groups,\n peerReference: (peerKey) =>\n parseRemoteSessionReference(peerKey) === undefined\n ? peerSessionReference(localHostId, peerKey)\n : peerKey,\n fallback: fallbackAuthorization,\n })\n : undefined;\n const { service, close: closeDelivery } = provideSessionDeliveryService(context, {\n databasePath: path.join(deliveryDirectory, `${agent.context.sessionId}.sqlite`),\n recipientKey: agent.context.sessionId,\n communication: peerCommunication,\n authorizePeer: (peerKey, metadata) => groupAuthorization?.(peerKey, metadata) ?? fallbackAuthorization(peerKey),\n admitPrompt: (prompt, delivery) => session.admitPrompt!(prompt, delivery),\n });\n const unprovide: (() => void)[] = [];\n if (groups && selfReference && peerConfig) {\n const directory = createSessionDirectory({\n authorizeDiscovery: (caller, subject) => {\n const reference = peerSessionReference(subject.hostId, subject.sessionId);\n const permitted = groups.groupsFor(caller).some((group) => group.members.includes(reference));\n return permitted ? { capabilities: ['message'] } : undefined;\n },\n });\n for (const peer of peerConfig.peers)\n for (const sessionId of peer.allowedSessionIds)\n directory.observe({\n hostId: peer.hostId,\n sessionId,\n hostIncarnation: 'unknown',\n sessionIncarnation: 'unknown',\n sequence: 0,\n observedAt: 0,\n staleAfterMs: 0,\n deliveryTarget: peerSessionReference(peer.hostId, sessionId),\n reachability: 'unknown',\n runtime: 'unknown',\n activity: 'unknown',\n voice: { eligible: 'unknown', readiness: 'unknown' },\n });\n unprovide.push(\n context.provide(\n DOOM_SESSION_INTERCOM_SERVICE,\n createSessionIntercom({ selfReference, directory, groups, delivery: service }),\n ),\n );\n }\n const unregister = registerSessionPeerInbox(agent.context.sessionId, (sourceKey, kind, payload) =>\n service.receive?.(sourceKey, kind, payload),\n );\n return async () => {\n unregister();\n for (const release of unprovide.reverse()) release();\n await closeDelivery();\n groups?.close();\n };\n },\n ],\n}));\n","import type { DoomApi, DoomApiHandler } from '@agimon-ai/po-core/packageApi';\n\nimport { deliverSessionPeerEnvelope } from '../peerInbox';\nimport {\n createPeerReplayGuard,\n parseSessionPeerEnvelope,\n peerSessionReference,\n readSessionPeerConfig,\n verifyPeerRequest,\n} from '../peerTransport';\n\nconst MAX_BODY_BYTES = 64 * 1024;\nconst DELIVERY_TYPES = new Set(['doom/session-delivery/envelope', 'doom/session-delivery/ack']);\n\nfunction response(status: number, error: string): Response {\n return Response.json({ error }, { status });\n}\n\n/** Narrow HMAC-authenticated endpoint that a trusted tunnel may forward without device authentication. */\nexport const peerInboxApi: DoomApi = {\n basePath: 'session-peer',\n start(context): DoomApiHandler {\n const config = context.homeDirectory === undefined ? undefined : readSessionPeerConfig(context.homeDirectory);\n const replay = context.homeDirectory === undefined ? undefined : createPeerReplayGuard(context.homeDirectory);\n return {\n async fetch(request) {\n if (request.method !== 'POST' || new URL(request.url).pathname !== '/inbox') return response(404, 'Not found.');\n if (!config) return response(503, 'Paired Session delivery is not configured.');\n const length = request.headers.get('content-length');\n if (length !== null && (!/^\\d+$/u.test(length) || Number(length) > MAX_BODY_BYTES))\n return response(413, 'Request body is too large.');\n const body = await request.text();\n if (Buffer.byteLength(body) > MAX_BODY_BYTES) return response(413, 'Request body is too large.');\n const peer = verifyPeerRequest(config, request, body);\n if (!peer) return response(401, 'Paired Session request is unauthorized.');\n if (!replay?.admit(request)) return response(409, 'Paired Session request was already received.');\n let parsed: unknown;\n try {\n parsed = JSON.parse(body) as unknown;\n } catch {\n return response(400, 'Paired Session request is malformed.');\n }\n const envelope = parseSessionPeerEnvelope(parsed);\n if (!envelope || !DELIVERY_TYPES.has(envelope.type))\n return response(400, 'Paired Session envelope is invalid.');\n if (!peer.allowedSessionIds.includes(envelope.targetSessionId))\n return response(403, 'Peer is not granted this session.');\n const state = deliverSessionPeerEnvelope(\n envelope.targetSessionId,\n peerSessionReference(peer.hostId, envelope.sourceSessionId),\n envelope.type,\n envelope.payload,\n );\n return state === undefined\n ? response(404, 'Target Session is unavailable.')\n : Response.json({ accepted: true, state }, { status: 202 });\n },\n close: () => replay?.close(),\n };\n },\n};\n","import { defineRoute } from '@agimon-ai/po-core/extensionFile';\n\nimport { peerInboxApi } from '../../../../services/peerInboxApi';\n\nexport default defineRoute(peerInboxApi);\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineServerPlugin, type DoomServerSessionPlugin } from '@agimon-ai/po-core/serverFacet';\nimport { composeServerProviderOverrides } from '@agimon-ai/po-core/serverFacet';\nimport { composeRootHooks } from '@agimon-ai/po-core/extensionFile';\n\nimport rootSession from '../src/extensions/workspaces/sessions/(backend)/root.server';\nimport apiRoute from '../src/extensions/(backend)/api/session-peer/route.server';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\n\nexport const facet = defineServerPlugin({\n name: '@agimon-ai/po-session',\n providerOverrides: composeServerProviderOverrides(rootSession),\n global: (context) => ({\n get api(): DoomServerSessionPlugin['api'] { return [at(apiRoute, context)]; },\n }),\n workspace: (context) => ({\n get api(): DoomServerSessionPlugin['api'] { return [at(apiRoute, context)]; },\n }),\n session: async (context) => {\n const scopeSession = await rootSession(context);\n return {\n ...composeRootHooks(scopeSession),\n get api(): DoomServerSessionPlugin['api'] { return [at(apiRoute, context)]; },\n services: [...(scopeSession.services ?? [])],\n get activities(): DoomServerSessionPlugin['activities'] { return [...(scopeSession.activities ?? [])]; },\n };\n },\n});\n\nexport default facet;\n"],"mappings":";;;;;;;AAQA,MAAM,0BAAU,IAAI,IAA8B;;AAGlD,SAAgB,yBAAyB,WAAmB,OAAqC;CAC/F,IAAI,QAAQ,IAAI,SAAS,GAAG,MAAM,IAAI,MAAM,uBAAuB,UAAU,yBAAyB;CACtG,QAAQ,IAAI,WAAW,KAAK;CAC5B,aAAa;EACX,IAAI,QAAQ,IAAI,SAAS,MAAM,OAAO,QAAQ,OAAO,SAAS;CAChE;AACF;AAEA,SAAgB,2BACd,iBACA,WACA,MACA,SAC2C;CAC3C,OAAO,QAAQ,IAAI,eAAe,CAAC,GAAG,WAAW,MAAM,OAAO;AAChE;;;ACFA,IAAA,sBAAe,YAAY,mBAA4C;CACrE,OAAO,KAAA;CACP,UAAU,CACR,+BACC,YAAY;EACX,MAAM,QAAQ,cAAc;EAC5B,MAAM,UAAU,OAAO,QAAQ;EAC/B,MAAM,gBAAgB,cAAc,KAAK,QAAQ;EACjD,MAAM,gBAAgB,cAAc,KAAK,QAAQ;EACjD,MAAM,iBAAiB,cAAc,KAAK,QAAQ;EAClD,IAAI,CAAC,SAAS,CAAC,SAAS,eAAe,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,gBAAgB,gBAC1F,MAAM,IAAI,MACR,mIACF;EAEF,MAAM,mBAAmB,KAAK,KAAK,gBAAgB,aAAa,GAAG,SAAS;EAC5E,MAAM,oBAAoB,KAAK,KAAK,kBAAkB,UAAU;EAChE,GAAG,UAAU,mBAAmB;GAAE,WAAW;GAAM,MAAM;EAAM,CAAC;EAChE,MAAM,oBAAoB,wBAAwB;GAAE,OAAO;GAAe;EAAc,CAAC;EACzF,MAAM,aAAa,sBAAsB,aAAa;EACtD,MAAM,uBAAuB,YAA6B;GACxD,MAAM,OAAO,4BAA4B,OAAO;GAChD,OACE,SAAS,KAAA,KACT,YAAY,MAAM,MACf,cACC,UAAU,WAA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,GAAGA,sBAAU,OAAO,CAAC;CAAG,EAC9E;CACA,SAAS,OAAO,YAAY;EAC1B,MAAM,eAAe,MAAMD,oBAAY,OAAO;EAC9C,OAAO;GACL,GAAG,iBAAiB,YAAY;GAChC,IAAI,MAAsC;IAAE,OAAO,CAAC,GAAGC,sBAAU,OAAO,CAAC;GAAG;GAC5E,UAAU,CAAC,GAAI,aAAa,YAAY,CAAC,CAAE;GAC3C,IAAI,aAAoD;IAAE,OAAO,CAAC,GAAI,aAAa,cAAc,CAAC,CAAE;GAAG;EACzG;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"server.mjs","names":["rootSession","apiRoute"],"sources":["../../src/services/peerInbox/index.ts","../../src/extensions/workspaces/sessions/(backend)/root.server.ts","../../src/services/peerInboxApi/index.ts","../../src/extensions/(backend)/api/session-peer/route.server.ts","../../generated/server.ts"],"sourcesContent":["import type { PoSessionDeliveryInboxState } from '../sessionDelivery';\n\nexport type SessionPeerInbox = (\n sourceKey: string,\n type: string,\n payload: unknown,\n) => Promise<PoSessionDeliveryInboxState | undefined> | undefined;\n\nconst inboxes = new Map<string, SessionPeerInbox>();\n\n/**\n * Registers one live session-owned peer inbox. This registry is reachable only by the Session route.\n * The newest registration wins: a Durable Object evicted without disposal leaves its entry in the\n * isolate's module state, and the restarted session must replace it. The hub still rejects two live\n * sessions with one id, and an older unregister cannot remove a newer inbox.\n */\nexport function registerSessionPeerInbox(sessionId: string, inbox: SessionPeerInbox): () => void {\n inboxes.set(sessionId, inbox);\n return () => {\n if (inboxes.get(sessionId) === inbox) inboxes.delete(sessionId);\n };\n}\n\nexport async function deliverSessionPeerEnvelope(\n targetSessionId: string,\n sourceKey: string,\n type: string,\n payload: unknown,\n): Promise<PoSessionDeliveryInboxState | undefined> {\n return inboxes.get(targetSessionId)?.(sourceKey, type, payload);\n}\n","import path from 'node:path';\n\nimport { defineRoot } from '@agimon-ai/po-core/extensionFile';\nimport { poHomeDirectory } from '@agimon-ai/po-core/piSettings';\nimport { BACKGROUND_CONTEXT, requirePoFs, requirePoSqlite } from '@agimon-ai/po-core/platform';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport { provideBackgroundWorkService } from '../../../../services/backgroundWorkService';\nimport { registerSessionPeerInbox } from '../../../../services/peerInbox';\nimport {\n createPeerCommunication,\n ensurePrivateDirectory,\n parseRemoteSessionReference,\n peerSessionReference,\n readSessionPeerConfigAsync,\n} from '../../../../services/peerTransport';\nimport { provideSessionDeliveryService } from '../../../../services/sessionDelivery';\nimport { createSessionDirectory } from '../../../../services/sessionDirectory';\nimport { createSessionGroupStore } from '../../../../services/sessionGroups';\nimport {\n PO_SESSION_INTERCOM_SERVICE,\n createSessionGroupDeliveryAuthorizer,\n createSessionIntercom,\n} from '../../../../services/sessionIntercom';\n\nexport default defineRoot((pluginContext: PoServerPluginContext) => ({\n value: undefined,\n services: [\n provideBackgroundWorkService,\n async (context) => {\n const agent = pluginContext.agent;\n const session = agent?.context.session;\n const communication = pluginContext.host.context.sessionCommunication;\n const homeDirectory = pluginContext.host.context.homeDirectory;\n const sessionService = pluginContext.host.context.sessionService;\n if (!agent || !session?.admitPrompt || !communication || !homeDirectory || !sessionService?.canCommunicate) {\n throw new Error(\n 'Session delivery requires the headless agent, authenticated session communication, host home directory, and communication policy.',\n );\n }\n const fs = requirePoFs(pluginContext.context);\n const sqlite = requirePoSqlite(pluginContext.context);\n const io = BACKGROUND_CONTEXT;\n const sessionDirectory = path.join(poHomeDirectory(homeDirectory), 'session');\n const deliveryDirectory = path.join(sessionDirectory, 'delivery');\n await ensurePrivateDirectory(fs, deliveryDirectory, io);\n const peerConfig = await readSessionPeerConfigAsync(fs, homeDirectory, io);\n const peerCommunication = createPeerCommunication({ local: communication, config: peerConfig });\n const remotePeerIsGranted = (peerKey: string): boolean => {\n const peer = parseRemoteSessionReference(peerKey);\n return (\n peer !== undefined &&\n peerConfig?.peers.some(\n (candidate) =>\n candidate.hostId === peer.hostId && candidate.allowedSessionIds.includes(agent.context.sessionId),\n ) === true\n );\n };\n const fallbackAuthorization = (peerKey: string): boolean =>\n sessionService.canCommunicate?.(agent.context.sessionId, peerKey) === true || remotePeerIsGranted(peerKey);\n const groups = peerConfig\n ? await createSessionGroupStore({\n database: await sqlite.open(path.join(sessionDirectory, 'groups.sqlite'), io),\n })\n : undefined;\n const localHostId = peerConfig?.hostId;\n const selfReference = localHostId ? peerSessionReference(localHostId, agent.context.sessionId) : undefined;\n const groupAuthorization =\n groups && selfReference && localHostId\n ? createSessionGroupDeliveryAuthorizer({\n selfReference,\n groups,\n peerReference: (peerKey) =>\n parseRemoteSessionReference(peerKey) === undefined\n ? peerSessionReference(localHostId, peerKey)\n : peerKey,\n fallback: fallbackAuthorization,\n })\n : undefined;\n let delivery: Awaited<ReturnType<typeof provideSessionDeliveryService>>;\n try {\n delivery = await provideSessionDeliveryService(context, {\n database: await sqlite.open(path.join(deliveryDirectory, `${agent.context.sessionId}.sqlite`), io),\n recipientKey: agent.context.sessionId,\n communication: peerCommunication,\n authorizePeer: (peerKey, metadata) =>\n groupAuthorization ? groupAuthorization(peerKey, metadata) : fallbackAuthorization(peerKey),\n admitPrompt: (prompt, admission) => session.admitPrompt!(prompt, admission),\n });\n } catch (error) {\n await groups?.close();\n throw error;\n }\n const { service, close: closeDelivery } = delivery;\n const unprovide: (() => void)[] = [];\n if (groups && selfReference && peerConfig) {\n const directory = createSessionDirectory({\n authorizeDiscovery: async (caller, subject) => {\n const reference = peerSessionReference(subject.hostId, subject.sessionId);\n const permitted = (await groups.groupsFor(caller)).some((group) => group.members.includes(reference));\n return permitted ? { capabilities: ['message'] } : undefined;\n },\n });\n for (const peer of peerConfig.peers)\n for (const sessionId of peer.allowedSessionIds)\n directory.observe({\n hostId: peer.hostId,\n sessionId,\n hostIncarnation: 'unknown',\n sessionIncarnation: 'unknown',\n sequence: 0,\n observedAt: 0,\n staleAfterMs: 0,\n deliveryTarget: peerSessionReference(peer.hostId, sessionId),\n reachability: 'unknown',\n runtime: 'unknown',\n activity: 'unknown',\n voice: { eligible: 'unknown', readiness: 'unknown' },\n });\n unprovide.push(\n context.provide(\n PO_SESSION_INTERCOM_SERVICE,\n createSessionIntercom({ selfReference, directory, groups, delivery: service }),\n ),\n );\n }\n const unregister = registerSessionPeerInbox(agent.context.sessionId, (sourceKey, kind, payload) =>\n service.receive?.(sourceKey, kind, payload),\n );\n return async () => {\n unregister();\n for (const release of unprovide.reverse()) release();\n await closeDelivery();\n await groups?.close();\n };\n },\n ],\n}));\n","import path from 'node:path';\n\nimport type { PoApi, PoApiHandler } from '@agimon-ai/po-core/packageApi';\nimport { BACKGROUND_CONTEXT, type PoSqliteService, type FileSystem } from '@agimon-ai/po-core/platform';\n\nimport { deliverSessionPeerEnvelope } from '../peerInbox';\nimport {\n PEER_REPLAY_DATABASE_FILE,\n createPeerReplayGuardAsync,\n ensurePrivateDirectory,\n parseSessionPeerEnvelope,\n peerSessionReference,\n readSessionPeerConfigAsync,\n sessionPeerConfigPath,\n verifyPeerRequest,\n type SessionPeerConfig,\n type SessionPeerReplayGuardAsync,\n} from '../peerTransport';\n\nconst MAX_BODY_BYTES = 64 * 1024;\nconst DELIVERY_TYPES = new Set(['po/session-delivery/envelope', 'po/session-delivery/ack']);\n\nfunction response(status: number, error: string): Response {\n return Response.json({ error }, { status });\n}\n\ninterface PeerInboxState {\n readonly config: SessionPeerConfig | undefined;\n readonly replay: SessionPeerReplayGuardAsync | undefined;\n}\n\n/** Narrow HMAC-authenticated endpoint that a trusted tunnel may forward without device authentication. */\nexport function createPeerInboxApi(platform: { readonly fs: FileSystem; readonly sqlite: PoSqliteService }): PoApi {\n return {\n basePath: 'session-peer',\n start(context): PoApiHandler {\n const homeDirectory = context.homeDirectory;\n // Opened once on first use: the handler starts synchronously, the platform services are async.\n let opened: Promise<PeerInboxState> | undefined;\n const open = (): Promise<PeerInboxState> =>\n (opened ??= (async () => {\n if (homeDirectory === undefined) return { config: undefined, replay: undefined };\n const config = await readSessionPeerConfigAsync(platform.fs, homeDirectory, BACKGROUND_CONTEXT);\n const file = path.join(path.dirname(sessionPeerConfigPath(homeDirectory)), PEER_REPLAY_DATABASE_FILE);\n await ensurePrivateDirectory(platform.fs, path.dirname(file), BACKGROUND_CONTEXT);\n const replay = await createPeerReplayGuardAsync(await platform.sqlite.open(file, BACKGROUND_CONTEXT));\n return { config, replay };\n })().catch((error: unknown) => {\n // A failed open is retried by the next request rather than cached.\n opened = undefined;\n throw error;\n }));\n return {\n async fetch(request) {\n if (request.method !== 'POST' || new URL(request.url).pathname !== '/inbox')\n return response(404, 'Not found.');\n const { config, replay } = await open();\n if (!config) return response(503, 'Paired Session delivery is not configured.');\n const length = request.headers.get('content-length');\n if (length !== null && (!/^\\d+$/u.test(length) || Number(length) > MAX_BODY_BYTES))\n return response(413, 'Request body is too large.');\n const body = await request.text();\n if (Buffer.byteLength(body) > MAX_BODY_BYTES) return response(413, 'Request body is too large.');\n const peer = verifyPeerRequest(config, request, body);\n if (!peer) return response(401, 'Paired Session request is unauthorized.');\n if (!(await replay?.admit(request))) return response(409, 'Paired Session request was already received.');\n let parsed: unknown;\n try {\n parsed = JSON.parse(body) as unknown;\n } catch {\n return response(400, 'Paired Session request is malformed.');\n }\n const envelope = parseSessionPeerEnvelope(parsed);\n if (!envelope || !DELIVERY_TYPES.has(envelope.type))\n return response(400, 'Paired Session envelope is invalid.');\n if (!peer.allowedSessionIds.includes(envelope.targetSessionId))\n return response(403, 'Peer is not granted this session.');\n const state = await deliverSessionPeerEnvelope(\n envelope.targetSessionId,\n peerSessionReference(peer.hostId, envelope.sourceSessionId),\n envelope.type,\n envelope.payload,\n );\n return state === undefined\n ? response(404, 'Target Session is unavailable.')\n : Response.json({ accepted: true, state }, { status: 202 });\n },\n async close() {\n const state = await opened?.catch(() => undefined);\n await state?.replay?.close();\n },\n };\n },\n };\n}\n","import { defineRoute } from '@agimon-ai/po-core/extensionFile';\nimport { requirePoFs, requirePoSqlite } from '@agimon-ai/po-core/platform';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport { createPeerInboxApi } from '../../../../services/peerInboxApi';\n\nexport default defineRoute(({ context }: PoServerPluginContext) =>\n createPeerInboxApi({ fs: requirePoFs(context), sqlite: requirePoSqlite(context) }),\n);\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineServerPlugin, type PoServerSessionPlugin } from '@agimon-ai/po-core/serverFacet';\nimport { composeServerProviderOverrides } from '@agimon-ai/po-core/serverFacet';\nimport { composeRootHooks } from '@agimon-ai/po-core/extensionFile';\n\nimport rootSession from '../src/extensions/workspaces/sessions/(backend)/root.server';\nimport apiRoute from '../src/extensions/(backend)/api/session-peer/route.server';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\n\nexport const facet = defineServerPlugin({\n name: '@agimon-ai/po-session',\n providerOverrides: composeServerProviderOverrides(rootSession),\n global: (context) => ({\n get api(): PoServerSessionPlugin['api'] { return [at(apiRoute, context)]; },\n }),\n workspace: (context) => ({\n get api(): PoServerSessionPlugin['api'] { return [at(apiRoute, context)]; },\n }),\n session: async (context) => {\n const scopeSession = await rootSession(context);\n return {\n ...composeRootHooks(scopeSession),\n get api(): PoServerSessionPlugin['api'] { return [at(apiRoute, context)]; },\n services: [...(scopeSession.services ?? [])],\n get activities(): PoServerSessionPlugin['activities'] { return [...(scopeSession.activities ?? [])]; },\n };\n },\n});\n\nexport default facet;\n"],"mappings":";;;;;;;AAQA,MAAM,0BAAU,IAAI,IAA8B;;;;;;;AAQlD,SAAgB,yBAAyB,WAAmB,OAAqC;CAC/F,QAAQ,IAAI,WAAW,KAAK;CAC5B,aAAa;EACX,IAAI,QAAQ,IAAI,SAAS,MAAM,OAAO,QAAQ,OAAO,SAAS;CAChE;AACF;AAEA,eAAsB,2BACpB,iBACA,WACA,MACA,SACkD;CAClD,OAAO,QAAQ,IAAI,eAAe,CAAC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KAAA,CAAS,EAAA,EACpC,QAAQ,MAAM;IAC7B;GACF;EACF;CACF;AACF;;;ACxFA,IAAA,uBAAe,aAAa,EAAE,cAC5B,mBAAmB;CAAE,IAAI,YAAY,OAAO;CAAG,QAAQ,gBAAgB,OAAO;AAAE,CAAC,CACnF;;;ACCA,MAAM,MAAY,OAA0B,YAC1C,OAAO,UAAU,aAAc,MAAwB,OAAO,IAAI;AAEpE,MAAa,QAAQ,mBAAmB;CACtC,MAAM;CACN,mBAAmB,+BAA+BA,mBAAW;CAC7D,SAAS,aAAa,EACpB,IAAI,MAAoC;EAAE,OAAO,CAAC,GAAGC,sBAAU,OAAO,CAAC;CAAG,EAC5E;CACA,YAAY,aAAa,EACvB,IAAI,MAAoC;EAAE,OAAO,CAAC,GAAGA,sBAAU,OAAO,CAAC;CAAG,EAC5E;CACA,SAAS,OAAO,YAAY;EAC1B,MAAM,eAAe,MAAMD,oBAAY,OAAO;EAC9C,OAAO;GACL,GAAG,iBAAiB,YAAY;GAChC,IAAI,MAAoC;IAAE,OAAO,CAAC,GAAGC,sBAAU,OAAO,CAAC;GAAG;GAC1E,UAAU,CAAC,GAAI,aAAa,YAAY,CAAC,CAAE;GAC3C,IAAI,aAAkD;IAAE,OAAO,CAAC,GAAI,aAAa,cAAc,CAAC,CAAE;GAAG;EACvG;CACF;AACF,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_sessionDelivery = require("./sessionDelivery-
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
2
|
+
const require_sessionDelivery = require("./sessionDelivery-D7PFBTSg.cjs");
|
|
3
|
+
exports.PO_SESSION_DELIVERY_SERVICE = require_sessionDelivery.PO_SESSION_DELIVERY_SERVICE;
|
|
4
|
+
exports.PO_SESSION_INTERCOM_SERVICE = require_sessionDelivery.PO_SESSION_INTERCOM_SERVICE;
|
|
5
5
|
exports.SessionGroupRevisionError = require_sessionDelivery.SessionGroupRevisionError;
|
|
6
6
|
exports.createBackgroundWorkService = require_sessionDelivery.createBackgroundWorkService;
|
|
7
7
|
exports.createPeerCommunication = require_sessionDelivery.createPeerCommunication;
|
|
8
8
|
exports.createPeerReplayGuard = require_sessionDelivery.createPeerReplayGuard;
|
|
9
|
+
exports.createPeerReplayGuardAsync = require_sessionDelivery.createPeerReplayGuardAsync;
|
|
9
10
|
exports.createSessionDeliveryService = require_sessionDelivery.createSessionDeliveryService;
|
|
10
11
|
exports.createSessionDirectory = require_sessionDelivery.createSessionDirectory;
|
|
11
12
|
exports.createSessionGroupDeliveryAuthorizer = require_sessionDelivery.createSessionGroupDeliveryAuthorizer;
|
|
@@ -16,9 +17,10 @@ exports.peerRequestHeaders = require_sessionDelivery.peerRequestHeaders;
|
|
|
16
17
|
exports.peerSessionReference = require_sessionDelivery.peerSessionReference;
|
|
17
18
|
exports.provideBackgroundWorkService = require_sessionDelivery.provideBackgroundWorkService;
|
|
18
19
|
exports.provideSessionDeliveryService = require_sessionDelivery.provideSessionDeliveryService;
|
|
19
|
-
exports.
|
|
20
|
+
exports.readPoSessionDelivery = require_sessionDelivery.readPoSessionDelivery;
|
|
20
21
|
exports.readSessionIntercom = require_sessionDelivery.readSessionIntercom;
|
|
21
22
|
exports.readSessionPeerConfig = require_sessionDelivery.readSessionPeerConfig;
|
|
23
|
+
exports.readSessionPeerConfigAsync = require_sessionDelivery.readSessionPeerConfigAsync;
|
|
22
24
|
exports.requireSessionIntercom = require_sessionDelivery.requireSessionIntercom;
|
|
23
25
|
exports.sessionPeerConfigPath = require_sessionDelivery.sessionPeerConfigPath;
|
|
24
26
|
exports.verifyPeerRequest = require_sessionDelivery.verifyPeerRequest;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,51 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PoBackgroundWorkService } from "@agimon-ai/po-core/backgroundWork";
|
|
2
|
+
import { FileSystem, PoSqliteService } from "@agimon-ai/po-core/platform";
|
|
2
3
|
import { Context } from "@deepseek-ai/cordis";
|
|
3
|
-
import {
|
|
4
|
+
import { PoSessionCommunicationEndpoint } from "@agimon-ai/po-core/hubChannel";
|
|
4
5
|
//#region src/services/backgroundWorkService/index.d.ts
|
|
5
6
|
/** Creates the generation-bound, pull-based coordinator shared by session extensions. */
|
|
6
|
-
export declare function createBackgroundWorkService(ctx: Context):
|
|
7
|
+
export declare function createBackgroundWorkService(ctx: Context): PoBackgroundWorkService;
|
|
7
8
|
/** Installs one coordinator in the current session service context. */
|
|
8
9
|
export declare function provideBackgroundWorkService(context: Context): void;
|
|
9
10
|
//#endregion
|
|
10
|
-
//#region src/services/
|
|
11
|
+
//#region src/services/sessionGroups/type.d.ts
|
|
12
|
+
/** pi-durable `SqliteDatabase`, reached through po-core so this package needs no direct dependency. */
|
|
13
|
+
type SessionSqliteDatabase = Awaited<ReturnType<PoSqliteService['open']>>;
|
|
14
|
+
interface SessionCommunicationGroup {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly ownerAuthority: string;
|
|
17
|
+
readonly revision: number;
|
|
18
|
+
readonly members: readonly string[];
|
|
19
|
+
}
|
|
20
|
+
interface SessionGroupMutation {
|
|
21
|
+
readonly groupId: string;
|
|
22
|
+
readonly authority: string;
|
|
23
|
+
readonly expectedRevision: number;
|
|
24
|
+
readonly add?: readonly string[];
|
|
25
|
+
readonly remove?: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
interface SessionGroupStoreOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Taken over by the store and closed by `close()`. On the edge every open returns the Durable
|
|
30
|
+
* Object's one shared database, so the store's table names must stay unique across that database.
|
|
31
|
+
*/
|
|
32
|
+
readonly database: SessionSqliteDatabase;
|
|
33
|
+
readonly authorizeManagement?: (authority: string, group: SessionCommunicationGroup) => boolean;
|
|
34
|
+
readonly validateEnrollment?: (groupId: string, memberReference: string) => boolean;
|
|
35
|
+
}
|
|
36
|
+
interface SessionGroupStore {
|
|
37
|
+
create(groupId: string, ownerAuthority: string, members: readonly string[]): Promise<SessionCommunicationGroup>;
|
|
38
|
+
mutate(mutation: SessionGroupMutation): Promise<SessionCommunicationGroup>;
|
|
39
|
+
get(groupId: string): Promise<SessionCommunicationGroup | undefined>;
|
|
40
|
+
groupsFor(memberReference: string): Promise<readonly SessionCommunicationGroup[]>;
|
|
41
|
+
canMessage(groupId: string, sourceReference: string, targetReference: string): Promise<boolean>;
|
|
42
|
+
close(): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
export declare class SessionGroupRevisionError extends Error {
|
|
45
|
+
constructor(groupId: string, expected: number, actual: number);
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/services/peerTransport/config.d.ts
|
|
11
49
|
declare const PEER_CONFIG_VERSION = 1;
|
|
12
50
|
interface SessionPeer {
|
|
13
51
|
readonly hostId: string;
|
|
@@ -23,6 +61,33 @@ interface SessionPeerConfig {
|
|
|
23
61
|
readonly hostId: string;
|
|
24
62
|
readonly peers: readonly SessionPeer[];
|
|
25
63
|
}
|
|
64
|
+
interface SessionPeerReplayGuard {
|
|
65
|
+
admit(request: Request, now?: number): boolean;
|
|
66
|
+
close(): void;
|
|
67
|
+
}
|
|
68
|
+
interface SessionPeerReplayGuardAsync {
|
|
69
|
+
admit(request: Request, now?: number): Promise<boolean>;
|
|
70
|
+
close(): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
export declare function sessionPeerConfigPath(homeDirectory: string): string;
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/services/peerTransport/sync.d.ts
|
|
75
|
+
/**
|
|
76
|
+
* Reads operator-provisioned peers. Invalid or unreadable config fails closed.
|
|
77
|
+
*
|
|
78
|
+
* @deprecated Node-only sync shim; use readSessionPeerConfigAsync. Removed in M2.
|
|
79
|
+
*/
|
|
80
|
+
export declare function readSessionPeerConfig(homeDirectory: string): SessionPeerConfig | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Persists accepted peer signatures so a valid request cannot be replayed within its clock-skew window.
|
|
83
|
+
*
|
|
84
|
+
* @deprecated Node-only sync shim; use createPeerReplayGuardAsync. Removed in M2.
|
|
85
|
+
*/
|
|
86
|
+
export declare function createPeerReplayGuard(homeDirectory: string): SessionPeerReplayGuard;
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/services/peerTransport/index.d.ts
|
|
89
|
+
/** chord IO context, reached through po-core so this package needs no direct dependency. */
|
|
90
|
+
type IoContext = Parameters<FileSystem['readTextFile']>[1];
|
|
26
91
|
interface RemoteSessionReference {
|
|
27
92
|
readonly hostId: string;
|
|
28
93
|
readonly sessionId: string;
|
|
@@ -33,26 +98,25 @@ interface SessionPeerEnvelope {
|
|
|
33
98
|
readonly type: string;
|
|
34
99
|
readonly payload: unknown;
|
|
35
100
|
}
|
|
36
|
-
interface SessionPeerReplayGuard {
|
|
37
|
-
admit(request: Request, now?: number): boolean;
|
|
38
|
-
close(): void;
|
|
39
|
-
}
|
|
40
|
-
export declare function sessionPeerConfigPath(homeDirectory: string): string;
|
|
41
101
|
/** Reads operator-provisioned peers. Invalid or unreadable config fails closed. */
|
|
42
|
-
export declare function
|
|
102
|
+
export declare function readSessionPeerConfigAsync(fs: FileSystem, homeDirectory: string, context: IoContext): Promise<SessionPeerConfig | undefined>;
|
|
43
103
|
/** `peer/<host-id>/<session-id>` is the only remote target spelling. */
|
|
44
104
|
export declare function parseRemoteSessionReference(value: string): RemoteSessionReference | undefined;
|
|
45
105
|
export declare function peerSessionReference(hostId: string, sessionId: string): string;
|
|
46
106
|
export declare function peerRequestHeaders(sourceHostId: string, peer: SessionPeer, method: string, pathname: string, body: string, now?: number): Headers;
|
|
47
|
-
/**
|
|
48
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Persists accepted peer signatures so a valid request cannot be replayed within its clock-skew window.
|
|
109
|
+
* Takes over the database and closes it in `close()`.
|
|
110
|
+
*/
|
|
111
|
+
export declare function createPeerReplayGuardAsync(database: SessionSqliteDatabase): Promise<SessionPeerReplayGuardAsync>;
|
|
49
112
|
export declare function verifyPeerRequest(config: SessionPeerConfig, request: Request, body: string, now?: number): SessionPeer | undefined;
|
|
50
113
|
/** Adds asynchronous tunnel publication to a host-bound local communication endpoint. */
|
|
51
114
|
export declare function createPeerCommunication(options: {
|
|
52
|
-
readonly local:
|
|
53
|
-
|
|
115
|
+
readonly local: PoSessionCommunicationEndpoint;
|
|
116
|
+
/** Read once by the caller, for example with readSessionPeerConfigAsync. */
|
|
117
|
+
readonly config: SessionPeerConfig | undefined;
|
|
54
118
|
readonly fetch?: typeof fetch;
|
|
55
|
-
}):
|
|
119
|
+
}): PoSessionCommunicationEndpoint;
|
|
56
120
|
//#endregion
|
|
57
121
|
//#region src/services/sessionDirectory/type.d.ts
|
|
58
122
|
type SessionHostReachability = 'reachable' | 'unreachable' | 'unknown';
|
|
@@ -96,14 +160,14 @@ interface DiscoveredSession extends SessionPresenceFacts {
|
|
|
96
160
|
}
|
|
97
161
|
interface SessionDirectoryOptions {
|
|
98
162
|
readonly now?: () => number;
|
|
99
|
-
readonly authorizeDiscovery: (callerReference: string, subject: Readonly<Pick<SessionPresenceObservation, 'hostId' | 'sessionId' | 'label'>>) => SessionDiscoveryGrant | undefined
|
|
163
|
+
readonly authorizeDiscovery: (callerReference: string, subject: Readonly<Pick<SessionPresenceObservation, 'hostId' | 'sessionId' | 'label'>>) => SessionDiscoveryGrant | undefined | Promise<SessionDiscoveryGrant | undefined>;
|
|
100
164
|
}
|
|
101
165
|
interface SessionDirectory {
|
|
102
166
|
observe(observation: SessionPresenceObservation): boolean;
|
|
103
167
|
replaceHostSnapshot(hostId: string, hostIncarnation: string, observations: readonly SessionPresenceObservation[]): void;
|
|
104
168
|
hostDisconnected(hostId: string): void;
|
|
105
|
-
discover(callerReference: string, allowedReferences?: ReadonlySet<string>): readonly DiscoveredSession[]
|
|
106
|
-
resolveDeliveryTarget(callerReference: string, reference: string): string | undefined
|
|
169
|
+
discover(callerReference: string, allowedReferences?: ReadonlySet<string>): Promise<readonly DiscoveredSession[]>;
|
|
170
|
+
resolveDeliveryTarget(callerReference: string, reference: string): Promise<string | undefined>;
|
|
107
171
|
subscribe(callerReference: string, listener: (sessions: readonly DiscoveredSession[]) => void): () => void;
|
|
108
172
|
}
|
|
109
173
|
//#endregion
|
|
@@ -111,114 +175,87 @@ interface SessionDirectory {
|
|
|
111
175
|
/** In-memory authenticated presence cache. Restart deliberately forgets every observation. */
|
|
112
176
|
export declare function createSessionDirectory(options: SessionDirectoryOptions): SessionDirectory;
|
|
113
177
|
//#endregion
|
|
114
|
-
//#region src/services/sessionGroups/type.d.ts
|
|
115
|
-
interface SessionCommunicationGroup {
|
|
116
|
-
readonly id: string;
|
|
117
|
-
readonly ownerAuthority: string;
|
|
118
|
-
readonly revision: number;
|
|
119
|
-
readonly members: readonly string[];
|
|
120
|
-
}
|
|
121
|
-
interface SessionGroupMutation {
|
|
122
|
-
readonly groupId: string;
|
|
123
|
-
readonly authority: string;
|
|
124
|
-
readonly expectedRevision: number;
|
|
125
|
-
readonly add?: readonly string[];
|
|
126
|
-
readonly remove?: readonly string[];
|
|
127
|
-
}
|
|
128
|
-
interface SessionGroupStoreOptions {
|
|
129
|
-
readonly databasePath: string;
|
|
130
|
-
readonly authorizeManagement?: (authority: string, group: SessionCommunicationGroup) => boolean;
|
|
131
|
-
readonly validateEnrollment?: (groupId: string, memberReference: string) => boolean;
|
|
132
|
-
}
|
|
133
|
-
interface SessionGroupStore {
|
|
134
|
-
create(groupId: string, ownerAuthority: string, members: readonly string[]): SessionCommunicationGroup;
|
|
135
|
-
mutate(mutation: SessionGroupMutation): SessionCommunicationGroup;
|
|
136
|
-
get(groupId: string): SessionCommunicationGroup | undefined;
|
|
137
|
-
groupsFor(memberReference: string): readonly SessionCommunicationGroup[];
|
|
138
|
-
canMessage(groupId: string, sourceReference: string, targetReference: string): boolean;
|
|
139
|
-
close(): void;
|
|
140
|
-
}
|
|
141
|
-
export declare class SessionGroupRevisionError extends Error {
|
|
142
|
-
constructor(groupId: string, expected: number, actual: number);
|
|
143
|
-
}
|
|
144
|
-
//#endregion
|
|
145
178
|
//#region src/services/sessionGroups/index.d.ts
|
|
146
179
|
/** Opens a revisioned SQLite registry for communication-only group membership. */
|
|
147
|
-
export declare function createSessionGroupStore(options: SessionGroupStoreOptions): SessionGroupStore
|
|
180
|
+
export declare function createSessionGroupStore(options: SessionGroupStoreOptions): Promise<SessionGroupStore>;
|
|
148
181
|
//#endregion
|
|
149
182
|
//#region src/services/sessionDelivery/type.d.ts
|
|
150
|
-
export declare const
|
|
151
|
-
type
|
|
152
|
-
type
|
|
153
|
-
interface
|
|
183
|
+
export declare const PO_SESSION_DELIVERY_SERVICE = "po/session-delivery";
|
|
184
|
+
type PoSessionDeliveryInboxState = 'accepted' | 'admitting' | 'admitted' | 'recovery_required';
|
|
185
|
+
type PoSessionDeliveryMode = 'prompt' | 'steer' | 'followUp';
|
|
186
|
+
interface PoSessionDeliveryMetadata extends Readonly<Record<string, string | undefined>> {
|
|
154
187
|
readonly worktreeId?: string;
|
|
155
188
|
readonly fromRole?: string;
|
|
156
189
|
}
|
|
157
|
-
interface
|
|
190
|
+
interface PoSessionDeliveryRequest {
|
|
158
191
|
readonly deliveryId?: string;
|
|
159
192
|
readonly recipientKey: string;
|
|
160
193
|
readonly kind: string;
|
|
161
194
|
readonly prompt: string;
|
|
162
|
-
readonly delivery?:
|
|
163
|
-
readonly metadata?:
|
|
195
|
+
readonly delivery?: PoSessionDeliveryMode;
|
|
196
|
+
readonly metadata?: PoSessionDeliveryMetadata;
|
|
164
197
|
}
|
|
165
|
-
interface
|
|
198
|
+
interface PoSessionInboxQuery {
|
|
166
199
|
readonly kind?: string;
|
|
167
|
-
readonly metadata?:
|
|
168
|
-
readonly state?:
|
|
200
|
+
readonly metadata?: PoSessionDeliveryMetadata;
|
|
201
|
+
readonly state?: PoSessionDeliveryInboxState;
|
|
169
202
|
readonly consumed?: boolean;
|
|
170
203
|
}
|
|
171
|
-
interface
|
|
204
|
+
interface PoSessionInboxEntry {
|
|
172
205
|
readonly deliveryId: string;
|
|
173
206
|
readonly senderKey: string;
|
|
174
207
|
readonly recipientKey: string;
|
|
175
208
|
readonly kind: string;
|
|
176
209
|
readonly prompt: string;
|
|
177
|
-
readonly delivery:
|
|
178
|
-
readonly metadata:
|
|
179
|
-
readonly state:
|
|
210
|
+
readonly delivery: PoSessionDeliveryMode;
|
|
211
|
+
readonly metadata: PoSessionDeliveryMetadata;
|
|
212
|
+
readonly state: PoSessionDeliveryInboxState;
|
|
180
213
|
readonly consumed: boolean;
|
|
181
214
|
}
|
|
182
|
-
interface
|
|
215
|
+
interface PoSessionOutboxEntry {
|
|
183
216
|
readonly deliveryId: string;
|
|
184
217
|
readonly recipientKey: string;
|
|
185
218
|
readonly kind: string;
|
|
186
|
-
readonly metadata:
|
|
219
|
+
readonly metadata: PoSessionDeliveryMetadata;
|
|
187
220
|
readonly state: 'queued' | 'acknowledged';
|
|
188
|
-
readonly recipientState?:
|
|
221
|
+
readonly recipientState?: PoSessionDeliveryInboxState;
|
|
189
222
|
}
|
|
190
|
-
interface
|
|
223
|
+
interface PoSessionDeliveryService {
|
|
191
224
|
readonly recipientKey: string;
|
|
192
|
-
deliver(request:
|
|
225
|
+
deliver(request: PoSessionDeliveryRequest): Promise<{
|
|
193
226
|
deliveryId: string;
|
|
194
227
|
}>;
|
|
195
|
-
waitForAdmission(deliveryId: string, timeoutMs?: number): Promise<
|
|
196
|
-
inbox(query?:
|
|
228
|
+
waitForAdmission(deliveryId: string, timeoutMs?: number): Promise<PoSessionDeliveryInboxState | undefined>;
|
|
229
|
+
inbox(query?: PoSessionInboxQuery): Promise<readonly PoSessionInboxEntry[]>;
|
|
197
230
|
/** Optional host-routed peer envelope admission. Local-only consumers need no transport receiver. */
|
|
198
|
-
receive?(senderKey: string, kind: string, payload: unknown):
|
|
199
|
-
consume(deliveryId: string): boolean
|
|
200
|
-
outbox(deliveryId: string):
|
|
231
|
+
receive?(senderKey: string, kind: string, payload: unknown): Promise<PoSessionDeliveryInboxState | undefined>;
|
|
232
|
+
consume(deliveryId: string): Promise<boolean>;
|
|
233
|
+
outbox(deliveryId: string): Promise<PoSessionOutboxEntry | undefined>;
|
|
201
234
|
close(): Promise<void>;
|
|
202
235
|
}
|
|
203
236
|
interface SessionDeliveryServiceOptions {
|
|
204
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Taken over by the service and closed by `close()`. On the edge every open returns the Durable
|
|
239
|
+
* Object's one shared database, so the service's table names must stay unique across that database.
|
|
240
|
+
*/
|
|
241
|
+
readonly database: SessionSqliteDatabase;
|
|
205
242
|
readonly recipientKey: string;
|
|
206
|
-
readonly communication:
|
|
243
|
+
readonly communication: PoSessionCommunicationEndpoint;
|
|
207
244
|
/** Host-owned relationship check applied before sends, retries, and recipient acceptance. */
|
|
208
|
-
readonly authorizePeer: (peerKey: string, metadata?:
|
|
209
|
-
readonly admitPrompt: (prompt: string, delivery?:
|
|
245
|
+
readonly authorizePeer: (peerKey: string, metadata?: PoSessionDeliveryMetadata) => boolean | Promise<boolean>;
|
|
246
|
+
readonly admitPrompt: (prompt: string, delivery?: PoSessionDeliveryMode) => Promise<void>;
|
|
210
247
|
}
|
|
211
248
|
declare module '@deepseek-ai/cordis' {
|
|
212
249
|
interface Context {
|
|
213
|
-
'
|
|
250
|
+
'po/session-delivery': PoSessionDeliveryService;
|
|
214
251
|
}
|
|
215
252
|
}
|
|
216
253
|
/** Reads the currently active provider each time, without retaining a stale binding. */
|
|
217
|
-
export declare function
|
|
254
|
+
export declare function readPoSessionDelivery(context: Context): PoSessionDeliveryService | undefined;
|
|
218
255
|
//#endregion
|
|
219
256
|
//#region src/services/sessionDelivery/index.d.ts
|
|
220
257
|
/** Opens and starts one durable delivery endpoint. */
|
|
221
|
-
export declare function createSessionDeliveryService(options: SessionDeliveryServiceOptions):
|
|
258
|
+
export declare function createSessionDeliveryService(options: SessionDeliveryServiceOptions): Promise<PoSessionDeliveryService>;
|
|
222
259
|
/**
|
|
223
260
|
* Installs a provider-owned endpoint in the current Cordis context.
|
|
224
261
|
*
|
|
@@ -226,13 +263,13 @@ export declare function createSessionDeliveryService(options: SessionDeliverySer
|
|
|
226
263
|
* `ctx.get` is strict and hides an implementation while its providing fiber is
|
|
227
264
|
* LOADING, which is the whole of that fiber's own callback.
|
|
228
265
|
*/
|
|
229
|
-
export declare function provideSessionDeliveryService(context: Context, options: SessionDeliveryServiceOptions): {
|
|
230
|
-
readonly service:
|
|
266
|
+
export declare function provideSessionDeliveryService(context: Context, options: SessionDeliveryServiceOptions): Promise<{
|
|
267
|
+
readonly service: PoSessionDeliveryService;
|
|
231
268
|
readonly close: () => Promise<void>;
|
|
232
|
-
}
|
|
269
|
+
}>;
|
|
233
270
|
//#endregion
|
|
234
271
|
//#region src/services/sessionIntercom/type.d.ts
|
|
235
|
-
export declare const
|
|
272
|
+
export declare const PO_SESSION_INTERCOM_SERVICE = "po/session-intercom";
|
|
236
273
|
type SessionReportStatus = 'done' | 'blocked' | 'failed';
|
|
237
274
|
interface SessionIntercomMessage {
|
|
238
275
|
readonly deliveryId: string;
|
|
@@ -242,7 +279,7 @@ interface SessionIntercomMessage {
|
|
|
242
279
|
readonly correlationId?: string;
|
|
243
280
|
readonly text: string;
|
|
244
281
|
readonly reportStatus?: SessionReportStatus;
|
|
245
|
-
readonly state:
|
|
282
|
+
readonly state: PoSessionInboxEntry['state'];
|
|
246
283
|
readonly consumed: boolean;
|
|
247
284
|
}
|
|
248
285
|
interface SessionIntercomSendRequest {
|
|
@@ -256,10 +293,10 @@ interface SessionIntercomOptions {
|
|
|
256
293
|
readonly selfReference: string;
|
|
257
294
|
readonly directory: SessionDirectory;
|
|
258
295
|
readonly groups: SessionGroupStore;
|
|
259
|
-
readonly delivery:
|
|
296
|
+
readonly delivery: PoSessionDeliveryService;
|
|
260
297
|
}
|
|
261
298
|
interface SessionIntercom {
|
|
262
|
-
discover(): readonly DiscoveredSession[]
|
|
299
|
+
discover(): Promise<readonly DiscoveredSession[]>;
|
|
263
300
|
send(request: SessionIntercomSendRequest): Promise<{
|
|
264
301
|
deliveryId: string;
|
|
265
302
|
}>;
|
|
@@ -268,18 +305,18 @@ interface SessionIntercom {
|
|
|
268
305
|
}): Promise<{
|
|
269
306
|
deliveryId: string;
|
|
270
307
|
}>;
|
|
271
|
-
messages(): readonly SessionIntercomMessage[]
|
|
272
|
-
delivery(deliveryId: string):
|
|
308
|
+
messages(): Promise<readonly SessionIntercomMessage[]>;
|
|
309
|
+
delivery(deliveryId: string): Promise<PoSessionOutboxEntry | undefined>;
|
|
273
310
|
}
|
|
274
311
|
interface SessionGroupDeliveryAuthorizationOptions {
|
|
275
312
|
readonly selfReference: string;
|
|
276
313
|
readonly groups: SessionGroupStore;
|
|
277
314
|
readonly peerReference: (peerKey: string) => string | undefined;
|
|
278
|
-
readonly fallback?: (peerKey: string, metadata:
|
|
315
|
+
readonly fallback?: (peerKey: string, metadata: PoSessionDeliveryMetadata | undefined) => boolean | Promise<boolean>;
|
|
279
316
|
}
|
|
280
317
|
declare module '@deepseek-ai/cordis' {
|
|
281
318
|
interface Context {
|
|
282
|
-
'
|
|
319
|
+
'po/session-intercom': SessionIntercom;
|
|
283
320
|
}
|
|
284
321
|
}
|
|
285
322
|
export declare function readSessionIntercom(context: Context): SessionIntercom | undefined;
|
|
@@ -289,7 +326,7 @@ export declare function requireSessionIntercom(context: Context): SessionInterco
|
|
|
289
326
|
/** Agent-facing intercom operations. A composition may acquire this service without gaining session controls. */
|
|
290
327
|
export declare function createSessionIntercom(options: SessionIntercomOptions): SessionIntercom;
|
|
291
328
|
/** Builds the dynamic delivery check used before every send, retry, and recipient acceptance. */
|
|
292
|
-
export declare function createSessionGroupDeliveryAuthorizer(options: SessionGroupDeliveryAuthorizationOptions): (peerKey: string, metadata:
|
|
329
|
+
export declare function createSessionGroupDeliveryAuthorizer(options: SessionGroupDeliveryAuthorizationOptions): (peerKey: string, metadata: PoSessionDeliveryMetadata | undefined) => Promise<boolean>;
|
|
293
330
|
//#endregion
|
|
294
|
-
export type { DiscoveredSession,
|
|
331
|
+
export type { DiscoveredSession, PoSessionDeliveryInboxState, PoSessionDeliveryMetadata, PoSessionDeliveryMode, PoSessionDeliveryRequest, PoSessionDeliveryService, PoSessionInboxEntry, PoSessionInboxQuery, PoSessionOutboxEntry, RemoteSessionReference, SessionActivityState, SessionCommunicationGroup, SessionDeliveryServiceOptions, SessionDirectory, SessionDirectoryOptions, SessionDiscoveryGrant, SessionGroupDeliveryAuthorizationOptions, SessionGroupMutation, SessionGroupStore, SessionGroupStoreOptions, SessionHostReachability, SessionIntercom, SessionIntercomMessage, SessionIntercomOptions, SessionIntercomSendRequest, SessionPeer, SessionPeerConfig, SessionPeerEnvelope, SessionPeerReplayGuard, SessionPeerReplayGuardAsync, SessionPresenceFacts, SessionPresenceObservation, SessionReportStatus, SessionRuntimeState, SessionVoiceReadiness };
|
|
295
332
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":["_0"],"sources":["../src/services/backgroundWorkService/index.ts","../src/services/peerTransport/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["_0"],"sources":["../src/services/backgroundWorkService/index.ts","../src/services/sessionGroups/type.ts","../src/services/peerTransport/config.ts","../src/services/peerTransport/sync.ts","../src/services/peerTransport/index.ts","../src/services/sessionDirectory/type.ts","../src/services/sessionDirectory/index.ts","../src/services/sessionGroups/index.ts","../src/services/sessionDelivery/type.ts","../src/services/sessionDelivery/index.ts","../src/services/sessionIntercom/type.ts","../src/services/sessionIntercom/index.ts"],"mappings":";;;;;;wBAmBgB,4BAA4B,KAAK,UAAU;;wBAoE3C,6BAA6B,SAAS;;;;KCpF1C,wBAAwB,QAAQ,WAAW;UAEtC;WACN;WACA;WACA;WACA;;UAGM;WACN;WACA;WACA;WACA;WACA;;UAGM;;;;;WAKN,UAAU;WACV,uBAA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,SAAS;aAAwC,QAAQ;MACxD;IAAU;;EACb,YAAY,iBAAiB;EAC7B,SAAS,qBAAqB,QAAQ;;UAGvB;WACN;WACA,QAAQ;WACR,gBAAgB;WAChB,YAAY,iBAAiB,UAAU,oDAAoD;;;YAI1F;IACR,uBAAuB;;;wBAIX,oBAAoB,SAAS,UAAU;wBAIvC,uBAAuB,SAAS,UAAU;;;;wBCxB1C,sBAAsB,SAAS,yBAAyB;;wBA6ExD,qCACd,SAAS,4CACP,iBAAiB,UAAU,0CAA0C"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { DOOM_SESSION_DELIVERY_SERVICE, DOOM_SESSION_INTERCOM_SERVICE, SessionGroupRevisionError, createBackgroundWorkService, createPeerCommunication, createPeerReplayGuard, createSessionDeliveryService, createSessionDirectory, createSessionGroupDeliveryAuthorizer, createSessionGroupStore, createSessionIntercom, parseRemoteSessionReference, peerRequestHeaders, peerSessionReference, provideBackgroundWorkService, provideSessionDeliveryService, readDoomSessionDelivery, readSessionIntercom, readSessionPeerConfig, requireSessionIntercom, sessionPeerConfigPath, verifyPeerRequest };
|
|
1
|
+
export { r as PO_SESSION_DELIVERY_SERVICE, s as PO_SESSION_INTERCOM_SERVICE, d as SessionGroupRevisionError, E as createBackgroundWorkService, p as createPeerCommunication, S as createPeerReplayGuard, m as createPeerReplayGuardAsync, t as createSessionDeliveryService, f as createSessionDirectory, a as createSessionGroupDeliveryAuthorizer, u as createSessionGroupStore, o as createSessionIntercom, g as parseRemoteSessionReference, v as peerRequestHeaders, y as peerSessionReference, D as provideBackgroundWorkService, n as provideSessionDeliveryService, i as readPoSessionDelivery, c as readSessionIntercom, C as readSessionPeerConfig, b as readSessionPeerConfigAsync, l as requireSessionIntercom, T as sessionPeerConfigPath, x as verifyPeerRequest } from "./sessionDelivery-CROSMn_N.mjs";
|