@undefineds.co/xpod 0.3.48 → 0.3.49
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/bin/xpod.js +0 -0
- package/dist/api/chatkit/pod-store.d.ts +16 -17
- package/dist/api/chatkit/pod-store.js +299 -231
- package/dist/api/chatkit/pod-store.js.map +1 -1
- package/dist/api/chatkit/schema.d.ts +1 -1
- package/dist/api/chatkit/service.js +13 -11
- package/dist/api/chatkit/service.js.map +1 -1
- package/dist/api/chatkit/store.d.ts +1 -0
- package/dist/api/chatkit/store.js +23 -11
- package/dist/api/chatkit/store.js.map +1 -1
- package/dist/api/chatkit/types.d.ts +17 -10
- package/dist/api/chatkit/types.js +97 -14
- package/dist/api/chatkit/types.js.map +1 -1
- package/dist/api/container/common.js +16 -2
- package/dist/api/container/common.js.map +1 -1
- package/dist/api/container/routes.js +3 -0
- package/dist/api/container/routes.js.map +1 -1
- package/dist/api/container/types.d.ts +3 -0
- package/dist/api/container/types.js.map +1 -1
- package/dist/api/handlers/ChatKitV1Handler.js +1 -2
- package/dist/api/handlers/ChatKitV1Handler.js.map +1 -1
- package/dist/api/handlers/CoordinationHandler.d.ts +6 -0
- package/dist/api/handlers/CoordinationHandler.js +115 -0
- package/dist/api/handlers/CoordinationHandler.js.map +1 -0
- package/dist/api/handlers/MatrixHandler.d.ts +11 -0
- package/dist/api/handlers/MatrixHandler.js +120 -2
- package/dist/api/handlers/MatrixHandler.js.map +1 -1
- package/dist/api/handlers/RunHandler.js +33 -15
- package/dist/api/handlers/RunHandler.js.map +1 -1
- package/dist/api/handlers/index.d.ts +1 -0
- package/dist/api/handlers/index.js +1 -0
- package/dist/api/handlers/index.js.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/matrix/PodMatrixStore.d.ts +25 -1
- package/dist/api/matrix/PodMatrixStore.js +243 -38
- package/dist/api/matrix/PodMatrixStore.js.map +1 -1
- package/dist/api/matrix/index.d.ts +1 -1
- package/dist/api/matrix/index.js.map +1 -1
- package/dist/api/matrix/types.d.ts +23 -2
- package/dist/api/matrix/types.js.map +1 -1
- package/dist/api/protocol-metadata.d.ts +4 -0
- package/dist/api/protocol-metadata.js +54 -0
- package/dist/api/protocol-metadata.js.map +1 -0
- package/dist/api/reconciler/ClientReconcilerCoordinator.d.ts +42 -0
- package/dist/api/reconciler/ClientReconcilerCoordinator.js +250 -0
- package/dist/api/reconciler/ClientReconcilerCoordinator.js.map +1 -0
- package/dist/api/reconciler/ClientReconcilerCoordinator.jsonld +186 -0
- package/dist/api/reconciler/ServerGroupReconcilerService.d.ts +39 -0
- package/dist/api/reconciler/ServerGroupReconcilerService.js +91 -0
- package/dist/api/reconciler/ServerGroupReconcilerService.js.map +1 -0
- package/dist/api/reconciler/ServerGroupReconcilerService.jsonld +146 -0
- package/dist/api/reconciler/WakeAgentQueue.d.ts +23 -0
- package/dist/api/reconciler/WakeAgentQueue.js +123 -0
- package/dist/api/reconciler/WakeAgentQueue.js.map +1 -0
- package/dist/api/reconciler/WakeAgentQueue.jsonld +91 -0
- package/dist/api/reconciler/coordination.d.ts +61 -0
- package/dist/api/reconciler/coordination.js +109 -0
- package/dist/api/reconciler/coordination.js.map +1 -0
- package/dist/api/reconciler/coordination.jsonld +186 -0
- package/dist/api/reconciler/index.d.ts +4 -0
- package/dist/api/reconciler/index.js +21 -0
- package/dist/api/reconciler/index.js.map +1 -0
- package/dist/api/runs/ManagedRunWorker.js +0 -5
- package/dist/api/runs/ManagedRunWorker.js.map +1 -1
- package/dist/api/runs/RunStateCenter.d.ts +1 -1
- package/dist/api/runs/RunStateCenter.js +12 -28
- package/dist/api/runs/RunStateCenter.js.map +1 -1
- package/dist/api/runs/store.d.ts +12 -15
- package/dist/api/runs/store.js +24 -15
- package/dist/api/runs/store.js.map +1 -1
- package/dist/api/tasks/TaskMaterializer.d.ts +1 -0
- package/dist/api/tasks/TaskMaterializer.js +10 -13
- package/dist/api/tasks/TaskMaterializer.js.map +1 -1
- package/dist/api/tasks/TaskService.d.ts +0 -2
- package/dist/api/tasks/TaskService.js +6 -16
- package/dist/api/tasks/TaskService.js.map +1 -1
- package/dist/api/tasks/store.d.ts +0 -2
- package/dist/api/tasks/store.js.map +1 -1
- package/dist/cli/commands/auth.d.ts +1 -1
- package/dist/cli/commands/auth.js +4 -5
- package/dist/cli/commands/auth.js.map +1 -1
- package/dist/cli/commands/backup.js +1 -1
- package/dist/cli/commands/backup.js.map +1 -1
- package/dist/cli/commands/login.js +1 -1
- package/dist/cli/commands/login.js.map +1 -1
- package/dist/cli/commands/pod.js +1 -1
- package/dist/cli/commands/pod.js.map +1 -1
- package/dist/cli/lib/auth-helper.d.ts +5 -3
- package/dist/cli/lib/auth-helper.js +5 -3
- package/dist/cli/lib/auth-helper.js.map +1 -1
- package/dist/cli/lib/credentials-store.d.ts +22 -4
- package/dist/cli/lib/credentials-store.js +68 -51
- package/dist/cli/lib/credentials-store.js.map +1 -1
- package/dist/components/components.jsonld +5 -1
- package/dist/components/context.jsonld +103 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -1
- package/dist/provision/LocalPodProvisioningService.d.ts +1 -0
- package/dist/provision/LocalPodProvisioningService.js +9 -0
- package/dist/provision/LocalPodProvisioningService.js.map +1 -1
- package/dist/provision/LocalPodProvisioningService.jsonld +4 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RunHandler.js","sourceRoot":"","sources":["../../../src/api/handlers/RunHandler.ts"],"names":[],"mappings":";;AAsBA,8CA2EC;AAhGD,iEAAqD;AAErD,qDAA6D;AAC7D,4CAA4D;AAG5D,2CAA4E;AAC5E,yCAOuB;AACvB,8CAAoD;AAMpD,SAAgB,iBAAiB,CAAC,MAAiB,EAAE,OAA0B;IAC7E,MAAM,MAAM,GAAG,IAAA,oCAAY,EAAC,YAAY,CAAC,CAAC;IAC1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AC;IACD,OAAO,IAAA,qBAAa,EAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAa;IACtC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAC3B,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;QACd,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;QAChB,MAAM,cAAc,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACxD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;YAC9C,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,GAAG,CAAC,QAAQ,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC;QACvE,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,QAAwB,EAAE,MAAc,EAAE,IAAa;IACvE,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;IACvD,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import type { ServerResponse } from 'node:http';\nimport { getLoggerFor } from 'global-logger-factory';\nimport type { ApiServer } from '../ApiServer';\nimport { getAccountId, getWebId } from '../auth/AuthContext';\nimport { generateId, nowTimestamp } from '../chatkit/types';\nimport type { StoreContext } from '../chatkit/store';\nimport type { AuthenticatedRequest } from '../middleware/AuthMiddleware';\nimport { RunStatus, RunStepType, type RunStatusType } from '../runs/schema';\nimport {\n generateRunStepResourceId,\n resolveDataResource,\n resolveRunUrn,\n type RunListOptions,\n type RunRecordData,\n type RunStore,\n} from '../runs/store';\nimport { isWorkspaceRef } from '../workspace/types';\n\nexport interface RunHandlerOptions {\n runStore: RunStore<StoreContext>;\n}\n\nexport function registerRunRoutes(server: ApiServer, options: RunHandlerOptions): void {\n const logger = getLoggerFor('RunHandler');\n const { runStore } = options;\n\n server.get('/v1/runs', async (request, response) => {\n try {\n const url = new URL(request.url ?? '', `http://${request.headers.host ?? 'localhost'}`);\n const runs = await runStore.listRuns(parseRunListOptions(url), buildStoreContext(request));\n sendJson(response, 200, { runs });\n } catch (error) {\n logger.error(`Failed to list runs: ${error}`);\n sendJson(response, 400, { error: formatError(error) });\n }\n });\n\n server.get('/v1/runs/:runId', async (request, response, params) => {\n try {\n const run = await runStore.loadRun(decodeURIComponent(params.runId), buildStoreContext(request));\n sendJson(response, 200, { run });\n } catch (error) {\n logger.error(`Failed to load run: ${error}`);\n sendJson(response, 404, { error: formatError(error) });\n }\n });\n\n server.get('/v1/runs/:runId/steps', async (request, response, params) => {\n try {\n const steps = await runStore.loadRunSteps(decodeURIComponent(params.runId), buildStoreContext(request));\n sendJson(response, 200, { steps });\n } catch (error) {\n logger.error(`Failed to load run steps: ${error}`);\n sendJson(response, 404, { error: formatError(error) });\n }\n });\n\n server.post('/v1/runs/:runId/cancel', async (request, response, params) => {\n try {\n const context = buildStoreContext(request);\n const run = await runStore.loadRun(decodeURIComponent(params.runId), context);\n const now = nowTimestamp();\n run.cancelRequestedAt = run.cancelRequestedAt ?? now;\n run.updatedAt = now;\n\n if (run.status === RunStatus.QUEUED) {\n run.status = RunStatus.CANCELLED;\n run.completedAt = now;\n run.leaseOwner = undefined;\n run.leaseExpiresAt = undefined;\n }\n\n await runStore.saveRun(run, context);\n await runStore.appendRunStep({\n id: generateRunStepResourceId({\n key: generateId('run-step'),\n runId: run.id,\n commandKind: run.commandKind,\n surfaceId: run.surfaceId,\n createdAt: now,\n }),\n commandKind: run.commandKind,\n surfaceId: run.surfaceId,\n runId: run.id,\n run: resolveRunResource(run, context),\n type: RunStepType.CANCEL_REQUESTED,\n message: 'Run cancellation requested',\n data: { status: run.status },\n createdAt: now,\n }, context);\n\n sendJson(response, 200, { run });\n } catch (error) {\n logger.error(`Failed to cancel run: ${error}`);\n sendJson(response, 404, { error: formatError(error) });\n }\n });\n}\n\nfunction parseRunListOptions(url: URL): RunListOptions {\n const workspace = url.searchParams.get('workspace') ?? undefined;\n if (workspace && !isWorkspaceRef(workspace)) {\n throw new Error('workspace must be an http(s):// or file:// workspace reference');\n }\n\n return {\n task: url.searchParams.get('task') ?? undefined,\n thread: url.searchParams.get('thread') ?? undefined,\n workspace,\n commandKind: parseCommandKind(url.searchParams.get('commandKind')),\n status: parseRunStatus(url.searchParams.get('status')),\n limit: parseOptionalNumber(url.searchParams.get('limit')),\n };\n}\n\nfunction parseCommandKind(value: string | null): RunListOptions['commandKind'] {\n if (!value) {\n return undefined;\n }\n if (value === 'chat' || value === 'task') {\n return value;\n }\n throw new Error('commandKind must be chat or task');\n}\n\nfunction parseRunStatus(value: string | null): RunStatusType | undefined {\n if (!value) {\n return undefined;\n }\n if (\n value === RunStatus.QUEUED\n || value === RunStatus.RUNNING\n || value === RunStatus.WAITING_INPUT\n || value === RunStatus.WAITING_RUNNER\n || value === RunStatus.COMPLETED\n || value === RunStatus.FAILED\n || value === RunStatus.CANCELLED\n ) {\n return value;\n }\n throw new Error(`Unknown run status: ${value}`);\n}\n\nfunction parseOptionalNumber(value: string | null): number | undefined {\n if (!value) {\n return undefined;\n }\n const parsed = Number(value);\n return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;\n}\n\nfunction buildStoreContext(request: AuthenticatedRequest): StoreContext {\n const auth = request.auth;\n const userId = auth ? getWebId(auth) ?? getAccountId(auth) ?? 'anonymous' : 'anonymous';\n return {\n userId,\n auth,\n };\n}\n\nfunction resolveRunResource(run: RunRecordData, context: StoreContext): string {\n const auth = context.auth as { webId?: unknown } | undefined;\n const webId = typeof auth?.webId === 'string' ? auth.webId : undefined;\n const podBaseUrl = webId ? resolvePodBaseUrl(webId) : undefined;\n if (podBaseUrl) {\n return resolveDataResource(podBaseUrl, run.id);\n }\n return resolveRunUrn(run.id);\n}\n\nfunction resolvePodBaseUrl(webId: string): string | undefined {\n try {\n const url = new URL(webId);\n url.hash = '';\n url.search = '';\n const normalizedPath = url.pathname.replace(/\\/+$/, '');\n if (!normalizedPath.endsWith('/profile/card')) {\n return undefined;\n }\n url.pathname = normalizedPath.slice(0, -'/profile/card'.length) || '/';\n return url.toString().replace(/\\/$/, '');\n } catch {\n return undefined;\n }\n}\n\nfunction sendJson(response: ServerResponse, status: number, data: unknown): void {\n response.statusCode = status;\n response.setHeader('Content-Type', 'application/json');\n response.end(JSON.stringify(data));\n}\n\nfunction formatError(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"RunHandler.js","sourceRoot":"","sources":["../../../src/api/handlers/RunHandler.ts"],"names":[],"mappings":";;AAyBA,8CAkFC;AA1GD,iEAAqD;AAErD,qDAA6D;AAC7D,4CAA4D;AAG5D,2CAA4E;AAC5E,yCAUuB;AACvB,8CAAoD;AAMpD,SAAgB,iBAAiB,CAAC,MAAiB,EAAE,OAA0B;IAC7E,MAAM,MAAM,GAAG,IAAA,oCAAY,EAAC,YAAY,CAAC,CAAC;IAC1C,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE7B,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;QACjD,IAAI,CAAC;YACH,MAAM,GAAG,G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,CAAC,IAAI,GAAG,CAAC;QACvE,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,QAAwB,EAAE,MAAc,EAAE,IAAa;IACvE,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;IACvD,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import type { ServerResponse } from 'node:http';\nimport { getLoggerFor } from 'global-logger-factory';\nimport type { ApiServer } from '../ApiServer';\nimport { getAccountId, getWebId } from '../auth/AuthContext';\nimport { generateId, nowTimestamp } from '../chatkit/types';\nimport type { StoreContext } from '../chatkit/store';\nimport type { AuthenticatedRequest } from '../middleware/AuthMiddleware';\nimport { RunStatus, RunStepType, type RunStatusType } from '../runs/schema';\nimport {\n deriveRunCommandProjection,\n generateRunStepResourceId,\n resolveDataResource,\n resolveRunUrn,\n type RunCommandKind,\n type RunListOptions,\n type RunRecordData,\n type RunStepRecordData,\n type RunStore,\n} from '../runs/store';\nimport { isWorkspaceRef } from '../workspace/types';\n\nexport interface RunHandlerOptions {\n runStore: RunStore<StoreContext>;\n}\n\nexport function registerRunRoutes(server: ApiServer, options: RunHandlerOptions): void {\n const logger = getLoggerFor('RunHandler');\n const { runStore } = options;\n\n server.get('/v1/runs', async (request, response) => {\n try {\n const url = new URL(request.url ?? '', `http://${request.headers.host ?? 'localhost'}`);\n const { storeOptions, commandKind } = parseRunListRequest(url);\n const requestedLimit = storeOptions.limit;\n let runs = await runStore.listRuns(\n commandKind ? { ...storeOptions, limit: undefined } : storeOptions,\n buildStoreContext(request),\n );\n if (commandKind) {\n runs = runs.filter((run) => deriveRunCommandProjection(run.id)?.commandKind === commandKind);\n }\n if (requestedLimit) {\n runs = runs.slice(0, requestedLimit);\n }\n sendJson(response, 200, { runs: runs.map(projectRunForApi) });\n } catch (error) {\n logger.error(`Failed to list runs: ${error}`);\n sendJson(response, 400, { error: formatError(error) });\n }\n });\n\n server.get('/v1/runs/:runId', async (request, response, params) => {\n try {\n const run = await runStore.loadRun(decodeURIComponent(params.runId), buildStoreContext(request));\n sendJson(response, 200, { run: projectRunForApi(run) });\n } catch (error) {\n logger.error(`Failed to load run: ${error}`);\n sendJson(response, 404, { error: formatError(error) });\n }\n });\n\n server.get('/v1/runs/:runId/steps', async (request, response, params) => {\n try {\n const steps = await runStore.loadRunSteps(decodeURIComponent(params.runId), buildStoreContext(request));\n sendJson(response, 200, { steps: steps.map(projectRunStepForApi) });\n } catch (error) {\n logger.error(`Failed to load run steps: ${error}`);\n sendJson(response, 404, { error: formatError(error) });\n }\n });\n\n server.post('/v1/runs/:runId/cancel', async (request, response, params) => {\n try {\n const context = buildStoreContext(request);\n const run = await runStore.loadRun(decodeURIComponent(params.runId), context);\n const now = nowTimestamp();\n run.cancelRequestedAt = run.cancelRequestedAt ?? now;\n run.updatedAt = now;\n\n if (run.status === RunStatus.QUEUED) {\n run.status = RunStatus.CANCELLED;\n run.completedAt = now;\n run.leaseOwner = undefined;\n run.leaseExpiresAt = undefined;\n }\n\n await runStore.saveRun(run, context);\n await runStore.appendRunStep({\n id: generateRunStepResourceId({\n key: generateId('run-step'),\n runId: run.id,\n createdAt: now,\n }),\n runId: run.id,\n run: resolveRunResource(run, context),\n type: RunStepType.CANCEL_REQUESTED,\n message: 'Run cancellation requested',\n data: { status: run.status },\n createdAt: now,\n }, context);\n\n sendJson(response, 200, { run: projectRunForApi(run) });\n } catch (error) {\n logger.error(`Failed to cancel run: ${error}`);\n sendJson(response, 404, { error: formatError(error) });\n }\n });\n}\n\ntype RunCommandProjectionData = {\n commandKind?: RunCommandKind;\n surfaceId?: string;\n};\n\ntype RunApiData = RunRecordData & RunCommandProjectionData;\ntype RunStepApiData = RunStepRecordData & RunCommandProjectionData;\n\nfunction projectRunForApi(run: RunRecordData): RunApiData {\n return {\n ...run,\n ...deriveRunCommandProjection(run.id),\n };\n}\n\nfunction projectRunStepForApi(step: RunStepRecordData): RunStepApiData {\n return {\n ...step,\n ...deriveRunCommandProjection(step.runId || step.id),\n };\n}\n\nfunction parseRunListRequest(url: URL): { storeOptions: RunListOptions; commandKind?: RunCommandKind } {\n const workspace = url.searchParams.get('workspace') ?? undefined;\n if (workspace && !isWorkspaceRef(workspace)) {\n throw new Error('workspace must be an http(s):// or file:// workspace reference');\n }\n\n return {\n storeOptions: {\n task: url.searchParams.get('task') ?? undefined,\n thread: url.searchParams.get('thread') ?? undefined,\n workspace,\n status: parseRunStatus(url.searchParams.get('status')),\n limit: parseOptionalNumber(url.searchParams.get('limit')),\n },\n commandKind: parseCommandKind(url.searchParams.get('commandKind')),\n };\n}\n\nfunction parseCommandKind(value: string | null): RunCommandKind | undefined {\n if (!value) {\n return undefined;\n }\n if (value === 'chat' || value === 'task') {\n return value;\n }\n throw new Error('commandKind must be chat or task');\n}\n\nfunction parseRunStatus(value: string | null): RunStatusType | undefined {\n if (!value) {\n return undefined;\n }\n if (\n value === RunStatus.QUEUED\n || value === RunStatus.RUNNING\n || value === RunStatus.WAITING_INPUT\n || value === RunStatus.WAITING_RUNNER\n || value === RunStatus.COMPLETED\n || value === RunStatus.FAILED\n || value === RunStatus.CANCELLED\n ) {\n return value;\n }\n throw new Error(`Unknown run status: ${value}`);\n}\n\nfunction parseOptionalNumber(value: string | null): number | undefined {\n if (!value) {\n return undefined;\n }\n const parsed = Number(value);\n return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;\n}\n\nfunction buildStoreContext(request: AuthenticatedRequest): StoreContext {\n const auth = request.auth;\n const userId = auth ? getWebId(auth) ?? getAccountId(auth) ?? 'anonymous' : 'anonymous';\n return {\n userId,\n auth,\n };\n}\n\nfunction resolveRunResource(run: RunRecordData, context: StoreContext): string {\n const auth = context.auth as { webId?: unknown } | undefined;\n const webId = typeof auth?.webId === 'string' ? auth.webId : undefined;\n const podBaseUrl = webId ? resolvePodBaseUrl(webId) : undefined;\n if (podBaseUrl) {\n return resolveDataResource(podBaseUrl, run.id);\n }\n return resolveRunUrn(run.id);\n}\n\nfunction resolvePodBaseUrl(webId: string): string | undefined {\n try {\n const url = new URL(webId);\n url.hash = '';\n url.search = '';\n const normalizedPath = url.pathname.replace(/\\/+$/, '');\n if (!normalizedPath.endsWith('/profile/card')) {\n return undefined;\n }\n url.pathname = normalizedPath.slice(0, -'/profile/card'.length) || '/';\n return url.toString().replace(/\\/$/, '');\n } catch {\n return undefined;\n }\n}\n\nfunction sendJson(response: ServerResponse, status: number, data: unknown): void {\n response.statusCode = status;\n response.setHeader('Content-Type', 'application/json');\n response.end(JSON.stringify(data));\n}\n\nfunction formatError(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"]}
|
|
@@ -28,4 +28,5 @@ __exportStar(require("./MatrixHandler"), exports);
|
|
|
28
28
|
__exportStar(require("./RunHandler"), exports);
|
|
29
29
|
__exportStar(require("./ProvisionHandler"), exports);
|
|
30
30
|
__exportStar(require("./PodManagementHandler"), exports);
|
|
31
|
+
__exportStar(require("./CoordinationHandler"), exports);
|
|
31
32
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/handlers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,iDAA+B;AAC/B,gDAA8B;AAC9B,gDAA8B;AAC9B,kDAAgC;AAChC,uDAAqC;AACrC,8DAA4C;AAC5C,qDAAmC;AACnC,2DAAyC;AACzC,mDAAiC;AACjC,kDAAgC;AAChC,+CAA6B;AAC7B,qDAAmC;AACnC,yDAAuC","sourcesContent":["export * from './EdgeNodeSignalHandler';\nexport * from './QuotaHandler';\nexport * from './NodeHandler';\nexport * from './ChatHandler';\nexport * from './VectorHandler';\nexport * from './VectorStoreHandler';\nexport * from './VectorStoreWebhookHandler';\nexport * from './SubdomainHandler';\nexport * from './SubdomainClientHandler';\nexport * from './ChatKitHandler';\nexport * from './MatrixHandler';\nexport * from './RunHandler';\nexport * from './ProvisionHandler';\nexport * from './PodManagementHandler';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/handlers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,iDAA+B;AAC/B,gDAA8B;AAC9B,gDAA8B;AAC9B,kDAAgC;AAChC,uDAAqC;AACrC,8DAA4C;AAC5C,qDAAmC;AACnC,2DAAyC;AACzC,mDAAiC;AACjC,kDAAgC;AAChC,+CAA6B;AAC7B,qDAAmC;AACnC,yDAAuC;AACvC,wDAAsC","sourcesContent":["export * from './EdgeNodeSignalHandler';\nexport * from './QuotaHandler';\nexport * from './NodeHandler';\nexport * from './ChatHandler';\nexport * from './VectorHandler';\nexport * from './VectorStoreHandler';\nexport * from './VectorStoreWebhookHandler';\nexport * from './SubdomainHandler';\nexport * from './SubdomainClientHandler';\nexport * from './ChatKitHandler';\nexport * from './MatrixHandler';\nexport * from './RunHandler';\nexport * from './ProvisionHandler';\nexport * from './PodManagementHandler';\nexport * from './CoordinationHandler';\n"]}
|
package/dist/api/index.d.ts
CHANGED
package/dist/api/index.js
CHANGED
|
@@ -26,4 +26,5 @@ __exportStar(require("./auth"), exports);
|
|
|
26
26
|
__exportStar(require("./middleware"), exports);
|
|
27
27
|
__exportStar(require("./handlers"), exports);
|
|
28
28
|
__exportStar(require("./ApiServer"), exports);
|
|
29
|
+
__exportStar(require("./reconciler"), exports);
|
|
29
30
|
//# sourceMappingURL=index.js.map
|
package/dist/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;AAEH,yCAAuB;AACvB,+CAA6B;AAC7B,6CAA2B;AAC3B,8CAA4B","sourcesContent":["/**\n * API Service - Standalone HTTP server for management APIs\n *\n * Separated from CSS main process for stability and security isolation.\n * Supports multiple authentication methods:\n * - Solid Token (DPoP) - for frontend users\n * - Client Credentials (Basic Auth) - for third-party apps and internal services\n */\n\nexport * from './auth';\nexport * from './middleware';\nexport * from './handlers';\nexport * from './ApiServer';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;AAEH,yCAAuB;AACvB,+CAA6B;AAC7B,6CAA2B;AAC3B,8CAA4B;AAC5B,+CAA6B","sourcesContent":["/**\n * API Service - Standalone HTTP server for management APIs\n *\n * Separated from CSS main process for stability and security isolation.\n * Supports multiple authentication methods:\n * - Solid Token (DPoP) - for frontend users\n * - Client Credentials (Basic Auth) - for third-party apps and internal services\n */\n\nexport * from './auth';\nexport * from './middleware';\nexport * from './handlers';\nexport * from './ApiServer';\nexport * from './reconciler';\n"]}
|
|
@@ -1,16 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type ServerGroupReconcilerService } from '../reconciler';
|
|
2
|
+
import type { MatrixAccountInfo, MatrixClientEvent, MatrixCreateRoomRequest, MatrixEventRecord, MatrixRoomRecord, MatrixSendEventRequest, MatrixStoreContext, MatrixSyncResponse } from './types';
|
|
2
3
|
export interface PodMatrixStoreOptions {
|
|
3
4
|
serverName?: string;
|
|
5
|
+
serverGroupReconcilerService?: ServerGroupReconcilerService;
|
|
4
6
|
}
|
|
5
7
|
export declare class PodMatrixStore {
|
|
8
|
+
private readonly logger;
|
|
6
9
|
private readonly serverName?;
|
|
10
|
+
private readonly serverGroupReconcilerService?;
|
|
7
11
|
constructor(options: PodMatrixStoreOptions);
|
|
12
|
+
getAccount(context: MatrixStoreContext): Promise<MatrixAccountInfo>;
|
|
8
13
|
createRoom(input: MatrixCreateRoomRequest, context: MatrixStoreContext): Promise<MatrixRoomRecord>;
|
|
14
|
+
joinRoom(roomIdOrAlias: string, context: MatrixStoreContext): Promise<{
|
|
15
|
+
roomId: string;
|
|
16
|
+
}>;
|
|
17
|
+
inviteUser(roomId: string, userId: string, context: MatrixStoreContext): Promise<void>;
|
|
18
|
+
leaveRoom(roomId: string, context: MatrixStoreContext): Promise<void>;
|
|
9
19
|
sendEvent(roomId: string, eventType: string, txnId: string, content: MatrixSendEventRequest, context: MatrixStoreContext): Promise<MatrixEventRecord>;
|
|
20
|
+
setState(roomId: string, eventType: string, stateKey: string, content: Record<string, unknown>, context: MatrixStoreContext): Promise<MatrixEventRecord>;
|
|
10
21
|
sync(context: MatrixStoreContext, options?: {
|
|
11
22
|
since?: string;
|
|
12
23
|
limit?: number;
|
|
13
24
|
}): Promise<MatrixSyncResponse>;
|
|
25
|
+
listJoinedRooms(context: MatrixStoreContext): Promise<string[]>;
|
|
26
|
+
getMembers(roomId: string, context: MatrixStoreContext): Promise<MatrixClientEvent[]>;
|
|
14
27
|
listMessages(roomId: string, context: MatrixStoreContext, options?: {
|
|
15
28
|
limit?: number;
|
|
16
29
|
dir?: 'b' | 'f';
|
|
@@ -26,7 +39,10 @@ export declare class PodMatrixStore {
|
|
|
26
39
|
private createAccessTokenFetch;
|
|
27
40
|
private ensureRoomExists;
|
|
28
41
|
private appendEvent;
|
|
42
|
+
private appendMembershipEvent;
|
|
29
43
|
private listRooms;
|
|
44
|
+
private listJoinedRoomRecords;
|
|
45
|
+
private resolveRoomId;
|
|
30
46
|
private listEvents;
|
|
31
47
|
private findEventByTxnId;
|
|
32
48
|
private findEventById;
|
|
@@ -38,18 +54,26 @@ export declare class PodMatrixStore {
|
|
|
38
54
|
private parseJsonObject;
|
|
39
55
|
private stringValue;
|
|
40
56
|
private numberValue;
|
|
57
|
+
private getRoomContext;
|
|
58
|
+
private reconcilerOwnerFromRoomMetadata;
|
|
59
|
+
private reconcileGroupUserMessage;
|
|
41
60
|
private messageContentFromMatrixEvent;
|
|
61
|
+
private mentionsFromMatrixContent;
|
|
62
|
+
private routeTargetAgentFromMatrixContent;
|
|
42
63
|
private getMatrixUserId;
|
|
43
64
|
private getServerName;
|
|
44
65
|
private localpartFromUserId;
|
|
45
66
|
private displayNameFromUserId;
|
|
46
67
|
private generateRoomId;
|
|
47
68
|
private generateEventId;
|
|
69
|
+
private deviceIdFromUserId;
|
|
48
70
|
private randomId;
|
|
49
71
|
private slug;
|
|
50
72
|
private surfaceIdFromRoomId;
|
|
51
73
|
private chatResourceIdFromRoomId;
|
|
74
|
+
private messageParentResourceIdFromRoomId;
|
|
52
75
|
private threadResourceIdFromRoomId;
|
|
76
|
+
private chatParentRefFromRoomId;
|
|
53
77
|
private messageResourceIdFromEvent;
|
|
54
78
|
private resolveDataResourceUriFromId;
|
|
55
79
|
private derivePodBaseUrl;
|