@undefineds.co/xpod 0.3.69 → 0.3.71-rc.2
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/config/cloud.json +3 -28
- package/config/local.json +3 -0
- package/config/resolver.json +7 -0
- package/config/xpod.base.json +20 -0
- package/dist/agents/ClaudeExecutor.js +1 -1
- package/dist/agents/ClaudeExecutor.js.map +1 -1
- package/dist/agents/types.d.ts +5 -5
- package/dist/agents/types.js.map +1 -1
- package/dist/api/ai-gateway/AiGatewayService.d.ts +5 -16
- package/dist/api/ai-gateway/AiGatewayService.js +13 -35
- package/dist/api/ai-gateway/AiGatewayService.js.map +1 -1
- package/dist/api/ai-gateway/auth/AiConnectionInvocationKeyIssuer.d.ts +3 -2
- package/dist/api/ai-gateway/auth/AiConnectionInvocationKeyIssuer.js +37 -12
- package/dist/api/ai-gateway/auth/AiConnectionInvocationKeyIssuer.js.map +1 -1
- package/dist/api/ai-gateway/auth/GatewayPrincipal.d.ts +2 -16
- package/dist/api/ai-gateway/auth/GatewayPrincipal.js +3 -33
- package/dist/api/ai-gateway/auth/GatewayPrincipal.js.map +1 -1
- package/dist/api/ai-gateway/auth/InvocationTokenAuthenticator.d.ts +23 -0
- package/dist/api/ai-gateway/auth/InvocationTokenAuthenticator.js +81 -0
- package/dist/api/ai-gateway/auth/InvocationTokenAuthenticator.js.map +1 -0
- package/dist/api/ai-gateway/auth/InvocationTokenCodec.d.ts +7 -4
- package/dist/api/ai-gateway/auth/InvocationTokenCodec.js.map +1 -1
- package/dist/api/ai-gateway/connect/index.d.ts +7 -26
- package/dist/api/ai-gateway/connect/index.js +40 -67
- package/dist/api/ai-gateway/connect/index.js.map +1 -1
- package/dist/api/ai-gateway/credentials/PlaintextCredentialPayload.d.ts +17 -0
- package/dist/api/ai-gateway/credentials/PlaintextCredentialPayload.js +65 -0
- package/dist/api/ai-gateway/credentials/PlaintextCredentialPayload.js.map +1 -0
- package/dist/api/ai-gateway/pod/HostedPodDataAccess.d.ts +24 -0
- package/dist/api/ai-gateway/pod/HostedPodDataAccess.js +149 -0
- package/dist/api/ai-gateway/pod/HostedPodDataAccess.js.map +1 -0
- package/dist/api/ai-gateway/quota/ProviderQuotaAdapter.d.ts +13 -5
- package/dist/api/ai-gateway/quota/ProviderQuotaAdapter.js +16 -19
- package/dist/api/ai-gateway/quota/ProviderQuotaAdapter.js.map +1 -1
- package/dist/api/ai-gateway/service-access/AiConnectionServiceAccess.d.ts +1 -1
- package/dist/api/ai-gateway/service-access/AiConnectionServiceAccess.js +0 -2
- package/dist/api/ai-gateway/service-access/AiConnectionServiceAccess.js.map +1 -1
- package/dist/api/auth/AuthContext.d.ts +1 -12
- package/dist/api/auth/AuthContext.js +0 -11
- package/dist/api/auth/AuthContext.js.map +1 -1
- package/dist/api/auth/ClientCredentialsAuthenticator.js +4 -11
- package/dist/api/auth/ClientCredentialsAuthenticator.js.map +1 -1
- package/dist/api/chatkit/default-agent.d.ts +2 -2
- package/dist/api/chatkit/default-agent.js +4 -4
- package/dist/api/chatkit/default-agent.js.map +1 -1
- package/dist/api/chatkit/runtime/AcpAgentRuntime.js +1 -1
- package/dist/api/chatkit/runtime/AcpAgentRuntime.js.map +1 -1
- package/dist/api/container/common.js +28 -69
- package/dist/api/container/common.js.map +1 -1
- package/dist/api/container/index.js +5 -6
- package/dist/api/container/index.js.map +1 -1
- package/dist/api/container/routes.js +2 -5
- package/dist/api/container/routes.js.map +1 -1
- package/dist/api/container/types.d.ts +8 -10
- package/dist/api/container/types.js.map +1 -1
- package/dist/api/handlers/AiClientConfigurationHandler.js +3 -3
- package/dist/api/handlers/AiClientConfigurationHandler.js.map +1 -1
- package/dist/api/handlers/AiGatewayHandler.js +2 -2
- package/dist/api/handlers/AiGatewayHandler.js.map +1 -1
- package/dist/api/handlers/AiGatewayManagementHandler.d.ts +2 -10
- package/dist/api/handlers/AiGatewayManagementHandler.js +4 -154
- package/dist/api/handlers/AiGatewayManagementHandler.js.map +1 -1
- package/dist/api/handlers/NetworkSettingsHandler.js +0 -3
- package/dist/api/handlers/NetworkSettingsHandler.js.map +1 -1
- package/dist/api/handlers/PodSettingsHandler.d.ts +5 -2
- package/dist/api/handlers/PodSettingsHandler.js +3 -3
- package/dist/api/handlers/PodSettingsHandler.js.map +1 -1
- package/dist/api/runs/AgentRuntimeTypes.d.ts +3 -3
- package/dist/api/runs/AgentRuntimeTypes.js +10 -10
- package/dist/api/runs/AgentRuntimeTypes.js.map +1 -1
- package/dist/api/runs/InngestRunExecutionBackend.d.ts +15 -9
- package/dist/api/runs/InngestRunExecutionBackend.js +25 -10
- package/dist/api/runs/InngestRunExecutionBackend.js.map +1 -1
- package/dist/api/runs/PiAgentRuntimeDriver.js +2 -2
- package/dist/api/runs/PiAgentRuntimeDriver.js.map +1 -1
- package/dist/api/runs/RunStateCenter.js +1 -1
- package/dist/api/runs/RunStateCenter.js.map +1 -1
- package/dist/api/service/AiClientConfigurationService.d.ts +2 -2
- package/dist/api/service/AiClientConfigurationService.js +11 -11
- package/dist/api/service/AiClientConfigurationService.js.map +1 -1
- package/dist/api/tasks/InngestTaskScheduler.d.ts +16 -10
- package/dist/api/tasks/InngestTaskScheduler.js +24 -12
- package/dist/api/tasks/InngestTaskScheduler.js.map +1 -1
- package/dist/cli/commands/start.js +7 -7
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/components/components.jsonld +1 -0
- package/dist/components/context.jsonld +42 -0
- package/dist/http/InternalPodDataHttpHandler.d.ts +32 -0
- package/dist/http/InternalPodDataHttpHandler.js +258 -0
- package/dist/http/InternalPodDataHttpHandler.js.map +1 -0
- package/dist/http/InternalPodDataHttpHandler.jsonld +201 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/main.js +13 -13
- package/dist/main.js.map +1 -1
- package/dist/runtime/GatewayAdminProxyAuth.d.ts +15 -1
- package/dist/runtime/GatewayAdminProxyAuth.js +57 -2
- package/dist/runtime/GatewayAdminProxyAuth.js.map +1 -1
- package/dist/runtime/bootstrap.js +3 -0
- package/dist/runtime/bootstrap.js.map +1 -1
- package/dist/runtime/css-process.d.ts +1 -1
- package/dist/runtime/css-process.js +4 -1
- package/dist/runtime/css-process.js.map +1 -1
- package/dist/runtime/runner/node/CommunitySolidServerCssRunner.d.ts +2 -0
- package/dist/runtime/runner/node/CommunitySolidServerCssRunner.js +50 -0
- package/dist/runtime/runner/node/CommunitySolidServerCssRunner.js.map +1 -1
- package/dist/storage/rdf/PostgresRdfEngine.js +2 -0
- package/dist/storage/rdf/PostgresRdfEngine.js.map +1 -1
- package/dist/storage/rdf/PostgresRdfVectorIndex.d.ts +1 -0
- package/dist/storage/rdf/PostgresRdfVectorIndex.js +1 -1
- package/dist/storage/rdf/PostgresRdfVectorIndex.js.map +1 -1
- package/dist/storage/rdf/PostgresRdfVectorIndex.jsonld +29 -0
- package/node_modules/@undefineds.co/ai-connection/dist/AiClientConfigurationSection.d.ts +5 -5
- package/node_modules/@undefineds.co/ai-connection/dist/AiClientConfigurationSection.js +7 -7
- package/node_modules/@undefineds.co/ai-connection/dist/AiConnectionMain.js +1 -1
- package/node_modules/@undefineds.co/ai-connection/dist/AiConnectionPanel.d.ts +3 -1
- package/node_modules/@undefineds.co/ai-connection/dist/AiConnectionPanel.js +74 -60
- package/node_modules/@undefineds.co/ai-connection/dist/ai-connection-client.d.ts +0 -21
- package/node_modules/@undefineds.co/ai-connection/dist/ai-connection-client.js +0 -41
- package/node_modules/@undefineds.co/ai-connection/dist/client-config/base-adapter.d.ts +1 -0
- package/node_modules/@undefineds.co/ai-connection/dist/client-config/base-adapter.js +7 -2
- package/node_modules/@undefineds.co/ai-connection/dist/client-config/codex.js +3 -3
- package/node_modules/@undefineds.co/ai-connection/dist/client-config/index.cjs +15 -9
- package/node_modules/@undefineds.co/ai-connection/dist/client-config/json-env-adapter.js +4 -4
- package/node_modules/@undefineds.co/ai-connection/dist/client-config/pi.js +3 -3
- package/node_modules/@undefineds.co/ai-connection/dist/client-config/types.d.ts +1 -1
- package/node_modules/@undefineds.co/ai-connection/dist/controller.d.ts +2 -1
- package/node_modules/@undefineds.co/ai-connection/dist/controller.js +1 -0
- package/node_modules/@undefineds.co/ai-connection/dist/service-access.js +0 -1
- package/node_modules/@undefineds.co/extension-sdk/dist/web.d.ts +22 -1
- package/package.json +3 -3
- package/static/app/assets/main.js +7 -7
- package/static/dashboard/assets/NetworkPage-CXjiUMR1.js +2 -0
- package/static/dashboard/assets/{PaneListHeader-57nvMwH6.js → PaneListHeader-BSipfl0W.js} +1 -1
- package/static/dashboard/assets/PodPage-Bd3Xhmp-.js +2 -0
- package/static/dashboard/assets/ServicesPage-CI3jWZGe.js +1 -0
- package/static/dashboard/assets/{card-B9Zjf_2p.js → card-z5BV5hTo.js} +1 -1
- package/static/dashboard/assets/{dashboard-8C6o666W.js → dashboard-CSrqAv2L.js} +2 -2
- package/static/dashboard/assets/{database-DPh9wDY9.js → database-Ct5ZPe6L.js} +1 -1
- package/static/dashboard/assets/{external-link-VbMQvVMz.js → external-link-B7wD1hkm.js} +1 -1
- package/static/dashboard/assets/index-tOBaUnM1.js +44 -0
- package/static/dashboard/assets/{refresh-cw-BxVxNxNr.js → refresh-cw-CFDZPaE8.js} +1 -1
- package/static/dashboard/assets/{services-status-context-DKmJ7ISr.js → services-status-context-DN1Icg4A.js} +1 -1
- package/static/dashboard/dashboard.html +1 -1
- package/static/settings/assets/ModelsPage-D87RrLB0.js +1 -0
- package/static/settings/assets/{PaneListHeader-Bgaze006.js → PaneListHeader-BtON8Z5Q.js} +1 -1
- package/static/settings/assets/PodPage-9LGuOloQ.js +2 -0
- package/static/settings/assets/ServicesPage-ZoT9-B_0.js +1 -0
- package/static/settings/assets/SettingsPage-Bj4lB3mq.js +41 -0
- package/static/settings/assets/{card-B_bXSIn-.js → card-CCGngjas.js} +1 -1
- package/static/settings/assets/{services-status-context-DiX-AbrP.js → services-status-context-CBfImxL_.js} +1 -1
- package/static/settings/assets/{settings-B30oMfZq.js → settings-yUyFIJxi.js} +2 -2
- package/static/settings/assets/{workspace-layout-Dv1Yn9Ci.js → workspace-layout-B0wJpPze.js} +1 -1
- package/static/settings/settings.html +1 -1
- package/dist/api/ai-gateway/auth/ClientCredentialsInternalPodAccessTokenProvider.d.ts +0 -25
- package/dist/api/ai-gateway/auth/ClientCredentialsInternalPodAccessTokenProvider.js +0 -91
- package/dist/api/ai-gateway/auth/ClientCredentialsInternalPodAccessTokenProvider.js.map +0 -1
- package/dist/api/ai-gateway/auth/GatewayApiKey.d.ts +0 -28
- package/dist/api/ai-gateway/auth/GatewayApiKey.js +0 -162
- package/dist/api/ai-gateway/auth/GatewayApiKey.js.map +0 -1
- package/dist/api/ai-gateway/auth/GatewayApiKeyAuthenticator.d.ts +0 -56
- package/dist/api/ai-gateway/auth/GatewayApiKeyAuthenticator.js +0 -143
- package/dist/api/ai-gateway/auth/GatewayApiKeyAuthenticator.js.map +0 -1
- package/dist/api/ai-gateway/auth/GatewayKeyLocatorCodec.d.ts +0 -26
- package/dist/api/ai-gateway/auth/GatewayKeyLocatorCodec.js +0 -97
- package/dist/api/ai-gateway/auth/GatewayKeyLocatorCodec.js.map +0 -1
- package/dist/api/ai-gateway/auth/PodGatewayAccessKeyRepository.d.ts +0 -54
- package/dist/api/ai-gateway/auth/PodGatewayAccessKeyRepository.js +0 -152
- package/dist/api/ai-gateway/auth/PodGatewayAccessKeyRepository.js.map +0 -1
- package/static/dashboard/assets/NetworkPage-Brt79fuQ.js +0 -2
- package/static/dashboard/assets/PodPage-CM6do1vB.js +0 -2
- package/static/dashboard/assets/ServicesPage-BUNxGJRz.js +0 -1
- package/static/dashboard/assets/index-RfiFckzb.js +0 -51
- package/static/settings/assets/ModelsPage-D_IH7AH3.js +0 -1
- package/static/settings/assets/PodPage-Cy1VNObw.js +0 -2
- package/static/settings/assets/ServicesPage-BsFaxVWC.js +0 -1
- package/static/settings/assets/SettingsPage-UafNWE_p.js +0 -48
|
@@ -1 +1 @@
|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AAC;QAC5B,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QAEpB,MAAM,QAAQ,GAAG,KAAK,EAAE,MAAc,EAAiB,EAAE;YACvD,OAAO,CAAC,GAAG,CAAC,cAAc,MAAM,oBAAoB,CAAC,CAAC;YACtD,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC;YAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC;QAEF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;QACjD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IACjD,CAAC;CACF,CAAC","sourcesContent":["import type { CommandModule } from 'yargs';\nimport path from 'path';\nimport fs from 'fs';\nimport { Supervisor } from '../../supervisor';\nimport { createGatewayAdminProxyAuthSecret, GatewayProxy, getFreePort, PACKAGE_ROOT } from '../../runtime';\nimport {\n buildApiChildEnv,\n buildCssArgs,\n buildCssChildEnv,\n createCssChildRuntimeConfig,\n} from '../../runtime/css-process';\nimport { resolveExternalOidcIssuer } from '../../runtime/oidc-issuer';\nimport { resolveAuthModeFromEnv } from '../../authorization/AuthMode';\n\ninterface StartArgs {\n mode?: string;\n config?: string;\n env?: string;\n port: number;\n host: string;\n foreground?: boolean;\n}\n\nconst childJsRuntime = typeof (globalThis as { Bun?: unknown }).Bun !== 'undefined'\n ? (process.env.XPOD_NODE_BINARY ?? 'node')\n : process.execPath;\n\nfunction loadEnvFile(envPath: string): void {\n if (!fs.existsSync(envPath)) {\n console.warn(`Env file not found: ${envPath}`);\n return;\n }\n const content = fs.readFileSync(envPath, 'utf-8');\n for (const line of content.split('\\n')) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith('#')) continue;\n const eqIndex = trimmed.indexOf('=');\n if (eqIndex === -1) continue;\n const key = trimmed.slice(0, eqIndex).trim();\n let value = trimmed.slice(eqIndex + 1).trim();\n if (\n (value.startsWith('\"') && value.endsWith('\"')) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\"))\n ) {\n value = value.slice(1, -1);\n }\n if (!process.env[key]) {\n process.env[key] = value;\n }\n }\n}\n\nexport const startCommand: CommandModule<object, StartArgs> = {\n command: 'start',\n describe: 'Start xpod services',\n builder: (yargs) =>\n yargs\n .option('mode', {\n alias: 'm',\n type: 'string',\n choices: ['local', 'cloud'],\n description: 'Run mode',\n })\n .option('config', {\n alias: 'c',\n type: 'string',\n description: 'Path to config file (overrides --mode)',\n })\n .option('env', {\n alias: 'e',\n type: 'string',\n description: 'Path to .env file',\n })\n .option('port', {\n alias: 'p',\n type: 'number',\n description: 'Gateway port',\n default: 3000,\n })\n .option('host', {\n type: 'string',\n description: 'Gateway host',\n default: 'localhost',\n })\n .option('foreground', {\n type: 'boolean',\n default: true,\n description: 'Run in the foreground',\n }),\n handler: async (argv) => {\n if (argv.env) {\n loadEnvFile(argv.env);\n }\n\n const mainPort =\n argv.port !== 3000\n ? argv.port\n : parseInt(process.env.XPOD_PORT ?? process.env.PORT ?? '3000', 10);\n\n let configPath: string;\n if (argv.config) {\n configPath = argv.config;\n } else if (argv.mode) {\n configPath = path.join(PACKAGE_ROOT, `config/${argv.mode}.json`);\n } else {\n configPath = path.join(PACKAGE_ROOT, 'config/local.json');\n }\n\n const cssPort = await getFreePort(mainPort + 1, argv.host);\n const apiPort = await getFreePort(cssPort + 1, argv.host);\n const runtimeRoot = path.join(process.cwd(), '.xpod/runtime/legacy-css');\n\n const baseUrl = process.env.CSS_BASE_URL || `http://${argv.host}:${mainPort}/`;\n const rdfIndexPath = process.env.CSS_RDF_INDEX_PATH || path.join(runtimeRoot, 'rdf-index.sqlite');\n process.env.CSS_RDF_INDEX_PATH = rdfIndexPath;\n\n // SP 模式:oidcIssuer 显式指定外部 IdP;Cloud API 地址不再隐式当作 issuer。\n const externalOidcIssuer = resolveExternalOidcIssuer(process.env);\n const authMode = resolveAuthModeFromEnv(process.env);\n\n console.log('Starting xpod...');\n console.log(` Gateway: ${baseUrl} (${argv.host}:${mainPort})`);\n console.log(` CSS (internal): http://localhost:${cssPort}`);\n console.log(` API (internal): http://localhost:${apiPort}`);\n if (externalOidcIssuer) {\n console.log(` SP mode: Cloud IdP = ${externalOidcIssuer}`);\n }\n console.log(` Authorization mode: ${authMode}`);\n\n const supervisor = new Supervisor();\n const cssBinary = require.resolve('@solid/community-server/bin/server.js');\n const cssRuntimeConfig = createCssChildRuntimeConfig({\n configPath,\n runtimeRoot,\n authMode,\n externalOidcIssuer,\n });\n const cssArgs = buildCssArgs({\n cssBinary,\n configPath: cssRuntimeConfig.configPath,\n cssModuleRoot: PACKAGE_ROOT,\n cssPort,\n baseUrl,\n externalOidcIssuer,\n });\n\n supervisor.register({\n name: 'css',\n command: childJsRuntime,\n args: cssArgs,\n cwd: cssRuntimeConfig.cwd,\n env: buildCssChildEnv(baseUrl, cssPort, externalOidcIssuer, authMode),\n });\n\n const isDevMode = __filename.endsWith('.ts');\n const apiArgs = isDevMode\n ? [\n '-r',\n require.resolve('ts-node/register/transpile-only'),\n path.resolve(__dirname, '..', '..', 'api', 'main.ts'),\n ]\n : [path.resolve(__dirname, '..', '..', 'api', 'main.js')];\n\n const gatewayAdminProxyAuthSecret = createGatewayAdminProxyAuthSecret();\n\n supervisor.register({\n name: 'api',\n command: childJsRuntime,\n args: apiArgs,\n env: buildApiChildEnv({\n apiPort,\n mainPort,\n cssPort,\n baseUrl,\n rdfIndexPath,\n authMode,\n externalOidcIssuer,\n gatewayAdminProxyAuthSecret,\n }),\n });\n\n const proxy = new GatewayProxy(mainPort, supervisor, '0.0.0.0', {\n exitOnStop: true,\n baseUrl,\n internalAdminAuthSecret: gatewayAdminProxyAuthSecret,\n });\n proxy.setTargets({\n css: `http://localhost:${cssPort}`,\n api: `http://localhost:${apiPort}`,\n });\n\n await supervisor.startAll();\n await proxy.start();\n\n const shutdown = async (signal: string): Promise<void> => {\n console.log(`\\nReceived ${signal}, shutting down...`);\n await supervisor.stopAll();\n process.exit(0);\n };\n\n process.on('SIGTERM', () => shutdown('SIGTERM'));\n process.on('SIGINT', () => shutdown('SIGINT'));\n },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../src/cli/commands/start.ts"],"names":[],"mappings":";;;;;;AACA,gDAAwB;AACxB,4CAAoB;AACpB,iDAA8C;AAC9C,2CAA2G;AAC3G,2DAKmC;AACnC,2DAAsE;AACtE,2DAAsE;AAWtE,MAAM,cAAc,GAAG,OAAQ,UAAgC,CAAC,GAAG,KAAK,WAAW;IACjF,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,MAAM,CAAC;IAC1C,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;AAErB,SAAS,WAAW,CAAC,OAAe;IAClC,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,IAAI,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAC;QAC/C,OAAO;IACT,CAAC;IACD,MAAM,OAAO,GAAG,YAAE,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClD,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,SAAS;QAClD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,OAAO,KAAK,CAAC,CAAC;YAAE,SAAS;QAC7B,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;QAC7C,IAAI,KAAK,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B,EAAE,2BAA2B;SACrD,CAAC,CAAC;QACH,KAAK,CAAC,UAAU,CAAC;YACf,GAAG,EAAE,oBAAoB,OAAO,EAAE;YAClC,GAAG,EAAE,oBAAoB,OAAO,EAAE;SACnC,CAAC,CAAC;QAEH,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC;QAC5B,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QAEpB,MAAM,QAAQ,GAAG,KAAK,EAAE,MAAc,EAAiB,EAAE;YACvD,OAAO,CAAC,GAAG,CAAC,cAAc,MAAM,oBAAoB,CAAC,CAAC;YACtD,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC;YAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC;QAEF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;QACjD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IACjD,CAAC;CACF,CAAC","sourcesContent":["import type { CommandModule } from 'yargs';\nimport path from 'path';\nimport fs from 'fs';\nimport { Supervisor } from '../../supervisor';\nimport { createGatewayAdminProxyAuthSecret, GatewayProxy, getFreePort, PACKAGE_ROOT } from '../../runtime';\nimport {\n buildApiChildEnv,\n buildCssArgs,\n buildCssChildEnv,\n createCssChildRuntimeConfig,\n} from '../../runtime/css-process';\nimport { resolveExternalOidcIssuer } from '../../runtime/oidc-issuer';\nimport { resolveAuthModeFromEnv } from '../../authorization/AuthMode';\n\ninterface StartArgs {\n mode?: string;\n config?: string;\n env?: string;\n port: number;\n host: string;\n foreground?: boolean;\n}\n\nconst childJsRuntime = typeof (globalThis as { Bun?: unknown }).Bun !== 'undefined'\n ? (process.env.XPOD_NODE_BINARY ?? 'node')\n : process.execPath;\n\nfunction loadEnvFile(envPath: string): void {\n if (!fs.existsSync(envPath)) {\n console.warn(`Env file not found: ${envPath}`);\n return;\n }\n const content = fs.readFileSync(envPath, 'utf-8');\n for (const line of content.split('\\n')) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith('#')) continue;\n const eqIndex = trimmed.indexOf('=');\n if (eqIndex === -1) continue;\n const key = trimmed.slice(0, eqIndex).trim();\n let value = trimmed.slice(eqIndex + 1).trim();\n if (\n (value.startsWith('\"') && value.endsWith('\"')) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\"))\n ) {\n value = value.slice(1, -1);\n }\n if (!process.env[key]) {\n process.env[key] = value;\n }\n }\n}\n\nexport const startCommand: CommandModule<object, StartArgs> = {\n command: 'start',\n describe: 'Start xpod services',\n builder: (yargs) =>\n yargs\n .option('mode', {\n alias: 'm',\n type: 'string',\n choices: ['local', 'cloud'],\n description: 'Run mode',\n })\n .option('config', {\n alias: 'c',\n type: 'string',\n description: 'Path to config file (overrides --mode)',\n })\n .option('env', {\n alias: 'e',\n type: 'string',\n description: 'Path to .env file',\n })\n .option('port', {\n alias: 'p',\n type: 'number',\n description: 'Gateway port',\n default: 3000,\n })\n .option('host', {\n type: 'string',\n description: 'Gateway host',\n default: 'localhost',\n })\n .option('foreground', {\n type: 'boolean',\n default: true,\n description: 'Run in the foreground',\n }),\n handler: async (argv) => {\n if (argv.env) {\n loadEnvFile(argv.env);\n }\n\n const mainPort =\n argv.port !== 3000\n ? argv.port\n : parseInt(process.env.XPOD_PORT ?? process.env.PORT ?? '3000', 10);\n\n let configPath: string;\n if (argv.config) {\n configPath = argv.config;\n } else if (argv.mode) {\n configPath = path.join(PACKAGE_ROOT, `config/${argv.mode}.json`);\n } else {\n configPath = path.join(PACKAGE_ROOT, 'config/local.json');\n }\n\n const cssPort = await getFreePort(mainPort + 1, argv.host);\n const apiPort = await getFreePort(cssPort + 1, argv.host);\n const runtimeRoot = path.join(process.cwd(), '.xpod/runtime/legacy-css');\n\n const baseUrl = process.env.CSS_BASE_URL || `http://${argv.host}:${mainPort}/`;\n const rdfIndexPath = process.env.CSS_RDF_INDEX_PATH || path.join(runtimeRoot, 'rdf-index.sqlite');\n process.env.CSS_RDF_INDEX_PATH = rdfIndexPath;\n\n // SP 模式:oidcIssuer 显式指定外部 IdP;Cloud API 地址不再隐式当作 issuer。\n const externalOidcIssuer = resolveExternalOidcIssuer(process.env);\n const authMode = resolveAuthModeFromEnv(process.env);\n\n console.log('Starting xpod...');\n console.log(` Gateway: ${baseUrl} (${argv.host}:${mainPort})`);\n console.log(` CSS (internal): http://localhost:${cssPort}`);\n console.log(` API (internal): http://localhost:${apiPort}`);\n if (externalOidcIssuer) {\n console.log(` SP mode: Cloud IdP = ${externalOidcIssuer}`);\n }\n console.log(` Authorization mode: ${authMode}`);\n\n const supervisor = new Supervisor();\n const cssBinary = require.resolve('@solid/community-server/bin/server.js');\n const cssRuntimeConfig = createCssChildRuntimeConfig({\n configPath,\n runtimeRoot,\n authMode,\n externalOidcIssuer,\n });\n const cssArgs = buildCssArgs({\n cssBinary,\n configPath: cssRuntimeConfig.configPath,\n cssModuleRoot: PACKAGE_ROOT,\n cssPort,\n baseUrl,\n externalOidcIssuer,\n });\n\n const isDevMode = __filename.endsWith('.ts');\n const apiArgs = isDevMode\n ? [\n '-r',\n require.resolve('ts-node/register/transpile-only'),\n path.resolve(__dirname, '..', '..', 'api', 'main.ts'),\n ]\n : [path.resolve(__dirname, '..', '..', 'api', 'main.js')];\n\n const gatewayAdminProxyAuthSecret = createGatewayAdminProxyAuthSecret();\n\n supervisor.register({\n name: 'css',\n command: childJsRuntime,\n args: cssArgs,\n cwd: cssRuntimeConfig.cwd,\n env: buildCssChildEnv(baseUrl, cssPort, externalOidcIssuer, authMode, process.env, gatewayAdminProxyAuthSecret),\n });\n\n supervisor.register({\n name: 'api',\n command: childJsRuntime,\n args: apiArgs,\n env: buildApiChildEnv({\n apiPort,\n mainPort,\n cssPort,\n baseUrl,\n rdfIndexPath,\n authMode,\n externalOidcIssuer,\n gatewayAdminProxyAuthSecret,\n }),\n });\n\n const proxy = new GatewayProxy(mainPort, supervisor, '0.0.0.0', {\n exitOnStop: true,\n baseUrl,\n internalAdminAuthSecret: gatewayAdminProxyAuthSecret,\n });\n proxy.setTargets({\n css: `http://localhost:${cssPort}`,\n api: `http://localhost:${apiPort}`,\n });\n\n await supervisor.startAll();\n await proxy.start();\n\n const shutdown = async (signal: string): Promise<void> => {\n console.log(`\\nReceived ${signal}, shutting down...`);\n await supervisor.stopAll();\n process.exit(0);\n };\n\n process.on('SIGTERM', () => shutdown('SIGTERM'));\n process.on('SIGINT', () => shutdown('SIGINT'));\n },\n};\n"]}
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"undefineds:dist/storage/SparqlUpdateResourceStore.jsonld",
|
|
35
35
|
"undefineds:dist/storage/sparql/CompatibilitySparqlEngine.jsonld",
|
|
36
36
|
"undefineds:dist/http/SubgraphSparqlHttpHandler.jsonld",
|
|
37
|
+
"undefineds:dist/http/InternalPodDataHttpHandler.jsonld",
|
|
37
38
|
"undefineds:dist/http/quota/QuotaAdminHttpHandler.jsonld",
|
|
38
39
|
"undefineds:dist/http/ClusterIngressRouter.jsonld",
|
|
39
40
|
"undefineds:dist/http/ClusterWebSocketConfigurator.jsonld",
|
|
@@ -555,6 +555,9 @@
|
|
|
555
555
|
"options_driver": {
|
|
556
556
|
"@id": "undefineds:dist/storage/rdf/PostgresRdfVectorIndex.jsonld#PostgresRdfVectorIndex_options_driver"
|
|
557
557
|
},
|
|
558
|
+
"options_backend": {
|
|
559
|
+
"@id": "undefineds:dist/storage/rdf/PostgresRdfVectorIndex.jsonld#PostgresRdfVectorIndex_options_backend"
|
|
560
|
+
},
|
|
558
561
|
"options_dataDir": {
|
|
559
562
|
"@id": "undefineds:dist/storage/rdf/PostgresRdfVectorIndex.jsonld#PostgresRdfVectorIndex_options_dataDir"
|
|
560
563
|
},
|
|
@@ -588,6 +591,9 @@
|
|
|
588
591
|
"driver": {
|
|
589
592
|
"@id": "undefineds:dist/storage/rdf/PostgresRdfVectorIndex.jsonld#PostgresRdfVectorIndex_options_driver"
|
|
590
593
|
},
|
|
594
|
+
"backend": {
|
|
595
|
+
"@id": "undefineds:dist/storage/rdf/PostgresRdfVectorIndex.jsonld#PostgresRdfVectorIndex_options_backend"
|
|
596
|
+
},
|
|
591
597
|
"dataDir": {
|
|
592
598
|
"@id": "undefineds:dist/storage/rdf/PostgresRdfVectorIndex.jsonld#PostgresRdfVectorIndex_options_dataDir"
|
|
593
599
|
},
|
|
@@ -1108,6 +1114,42 @@
|
|
|
1108
1114
|
}
|
|
1109
1115
|
}
|
|
1110
1116
|
},
|
|
1117
|
+
"InternalPodDataHttpHandler": {
|
|
1118
|
+
"@id": "undefineds:dist/http/InternalPodDataHttpHandler.jsonld#InternalPodDataHttpHandler",
|
|
1119
|
+
"@prefix": true,
|
|
1120
|
+
"@context": {
|
|
1121
|
+
"options_resourceStore": {
|
|
1122
|
+
"@id": "undefineds:dist/http/InternalPodDataHttpHandler.jsonld#InternalPodDataHttpHandler_options_resourceStore"
|
|
1123
|
+
},
|
|
1124
|
+
"options_gatewayAdminProxyAuthSecret": {
|
|
1125
|
+
"@id": "undefineds:dist/http/InternalPodDataHttpHandler.jsonld#InternalPodDataHttpHandler_options_gatewayAdminProxyAuthSecret"
|
|
1126
|
+
},
|
|
1127
|
+
"options_patchBodyParser": {
|
|
1128
|
+
"@id": "undefineds:dist/http/InternalPodDataHttpHandler.jsonld#InternalPodDataHttpHandler_options_patchBodyParser"
|
|
1129
|
+
},
|
|
1130
|
+
"options_baseUrl": {
|
|
1131
|
+
"@id": "undefineds:dist/http/InternalPodDataHttpHandler.jsonld#InternalPodDataHttpHandler_options_baseUrl"
|
|
1132
|
+
},
|
|
1133
|
+
"options_basePath": {
|
|
1134
|
+
"@id": "undefineds:dist/http/InternalPodDataHttpHandler.jsonld#InternalPodDataHttpHandler_options_basePath"
|
|
1135
|
+
},
|
|
1136
|
+
"resourceStore": {
|
|
1137
|
+
"@id": "undefineds:dist/http/InternalPodDataHttpHandler.jsonld#InternalPodDataHttpHandler_options_resourceStore"
|
|
1138
|
+
},
|
|
1139
|
+
"gatewayAdminProxyAuthSecret": {
|
|
1140
|
+
"@id": "undefineds:dist/http/InternalPodDataHttpHandler.jsonld#InternalPodDataHttpHandler_options_gatewayAdminProxyAuthSecret"
|
|
1141
|
+
},
|
|
1142
|
+
"patchBodyParser": {
|
|
1143
|
+
"@id": "undefineds:dist/http/InternalPodDataHttpHandler.jsonld#InternalPodDataHttpHandler_options_patchBodyParser"
|
|
1144
|
+
},
|
|
1145
|
+
"baseUrl": {
|
|
1146
|
+
"@id": "undefineds:dist/http/InternalPodDataHttpHandler.jsonld#InternalPodDataHttpHandler_options_baseUrl"
|
|
1147
|
+
},
|
|
1148
|
+
"basePath": {
|
|
1149
|
+
"@id": "undefineds:dist/http/InternalPodDataHttpHandler.jsonld#InternalPodDataHttpHandler_options_basePath"
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
},
|
|
1111
1153
|
"QuotaAdminHttpHandler": {
|
|
1112
1154
|
"@id": "undefineds:dist/http/quota/QuotaAdminHttpHandler.jsonld#QuotaAdminHttpHandler",
|
|
1113
1155
|
"@prefix": true,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { HttpHandler, type BodyParser, type HttpHandlerInput, type ResourceStore } from '@solid/community-server';
|
|
2
|
+
export interface InternalPodDataHttpHandlerOptions {
|
|
3
|
+
resourceStore: ResourceStore;
|
|
4
|
+
gatewayAdminProxyAuthSecret?: string;
|
|
5
|
+
patchBodyParser?: BodyParser;
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
basePath?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class InternalPodDataHttpHandler extends HttpHandler {
|
|
10
|
+
protected readonly logger: import("global-logger-factory").Logger<unknown>;
|
|
11
|
+
private readonly resourceStore;
|
|
12
|
+
private readonly gatewayAdminProxyAuthSecret?;
|
|
13
|
+
private readonly patchBodyParser?;
|
|
14
|
+
private readonly deploymentBaseUrl?;
|
|
15
|
+
private readonly basePath;
|
|
16
|
+
private readonly seenNonces;
|
|
17
|
+
constructor(options: InternalPodDataHttpHandlerOptions);
|
|
18
|
+
canHandle({ request }: HttpHandlerInput): Promise<void>;
|
|
19
|
+
handle({ request, response }: HttpHandlerInput): Promise<void>;
|
|
20
|
+
private verifyRequest;
|
|
21
|
+
private intentMatchesRequest;
|
|
22
|
+
private isHostedOwnerResource;
|
|
23
|
+
private isAllowedAiConnectionResource;
|
|
24
|
+
private delegate;
|
|
25
|
+
private createRepresentation;
|
|
26
|
+
private createPatch;
|
|
27
|
+
private pipeRepresentation;
|
|
28
|
+
private writeNotFound;
|
|
29
|
+
private parseUrl;
|
|
30
|
+
private parseOptionalUrl;
|
|
31
|
+
private isInsideDeployment;
|
|
32
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InternalPodDataHttpHandler = void 0;
|
|
4
|
+
const promises_1 = require("node:stream/promises");
|
|
5
|
+
const global_logger_factory_1 = require("global-logger-factory");
|
|
6
|
+
const community_server_1 = require("@solid/community-server");
|
|
7
|
+
const AiConnectionServiceAccess_1 = require("../api/ai-gateway/service-access/AiConnectionServiceAccess");
|
|
8
|
+
const GatewayAdminProxyAuth_1 = require("../runtime/GatewayAdminProxyAuth");
|
|
9
|
+
const ALLOWED_METHODS = new Set(['GET', 'PUT', 'PATCH', 'DELETE']);
|
|
10
|
+
const DEFAULT_NONCE_TTL_MS = 120_000;
|
|
11
|
+
const DEFAULT_NONCE_MAX_ENTRIES = 10_000;
|
|
12
|
+
class InternalPodDataHttpHandler extends community_server_1.HttpHandler {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super();
|
|
15
|
+
this.logger = (0, global_logger_factory_1.getLoggerFor)(this);
|
|
16
|
+
this.resourceStore = options.resourceStore;
|
|
17
|
+
this.gatewayAdminProxyAuthSecret = options.gatewayAdminProxyAuthSecret ?? process.env.XPOD_GATEWAY_ADMIN_PROXY_AUTH_SECRET;
|
|
18
|
+
this.patchBodyParser = options.patchBodyParser;
|
|
19
|
+
this.deploymentBaseUrl = this.parseOptionalUrl(options.baseUrl ?? process.env.CSS_BASE_URL);
|
|
20
|
+
this.basePath = options.basePath ?? '/.internal/pod-data';
|
|
21
|
+
const nonceOptions = options;
|
|
22
|
+
this.seenNonces = new BoundedTtlNonceCache({
|
|
23
|
+
ttlMs: nonceOptions.nonceTtlMs ?? DEFAULT_NONCE_TTL_MS,
|
|
24
|
+
maxEntries: nonceOptions.nonceMaxEntries ?? DEFAULT_NONCE_MAX_ENTRIES,
|
|
25
|
+
now: nonceOptions.now,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async canHandle({ request }) {
|
|
29
|
+
if (this.parseUrl(request).pathname !== this.basePath) {
|
|
30
|
+
throw new community_server_1.NotImplementedHttpError('Not an internal Pod data request.');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async handle({ request, response }) {
|
|
34
|
+
if (this.parseUrl(request).pathname !== this.basePath) {
|
|
35
|
+
throw new community_server_1.NotImplementedHttpError('Not an internal Pod data request.');
|
|
36
|
+
}
|
|
37
|
+
const intent = this.verifyRequest(request);
|
|
38
|
+
if (!intent) {
|
|
39
|
+
this.writeNotFound(response);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
await this.delegate(request, response, intent);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (isHttpNotFound(error)) {
|
|
47
|
+
this.writeNotFound(response);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
verifyRequest(request) {
|
|
54
|
+
const method = request.method?.toUpperCase();
|
|
55
|
+
if (!ALLOWED_METHODS.has(method ?? '')) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
if (!(0, GatewayAdminProxyAuth_1.isLoopbackRemoteAddress)(request.socket.remoteAddress)) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const verification = (0, GatewayAdminProxyAuth_1.verifyGatewayAdminProxyHeaders)({
|
|
62
|
+
headers: request.headers,
|
|
63
|
+
secret: this.gatewayAdminProxyAuthSecret,
|
|
64
|
+
method,
|
|
65
|
+
url: request.url,
|
|
66
|
+
});
|
|
67
|
+
if (!verification.valid || !verification.originalClientLoopback || !verification.intent || !verification.nonce) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
if (!this.intentMatchesRequest(verification.intent, method)) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
if (!this.isHostedOwnerResource(verification.intent)) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
if (!this.isAllowedAiConnectionResource(verification.intent)) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
if (!this.seenNonces.consume(verification.nonce)) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
return verification.intent;
|
|
83
|
+
}
|
|
84
|
+
intentMatchesRequest(intent, method) {
|
|
85
|
+
if (intent.method !== method) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
if (intent.scopes.length === 0) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
const requiredScope = method === 'GET' ? 'ai:credentials:read' : 'ai:credentials:write';
|
|
92
|
+
return intent.scopes.some((scope) => scope === requiredScope ||
|
|
93
|
+
scope === 'ai:credentials:*' ||
|
|
94
|
+
scope === 'ai:*');
|
|
95
|
+
}
|
|
96
|
+
isHostedOwnerResource(intent) {
|
|
97
|
+
if (!this.deploymentBaseUrl) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
let ownerUrl;
|
|
101
|
+
let resourceUrl;
|
|
102
|
+
try {
|
|
103
|
+
ownerUrl = new URL(intent.ownerWebId);
|
|
104
|
+
resourceUrl = new URL(intent.resourceUrl);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
if (!this.isInsideDeployment(ownerUrl) || !this.isInsideDeployment(resourceUrl)) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const podRoot = hostedPodRootFromOwner(ownerUrl);
|
|
113
|
+
return podRoot !== undefined &&
|
|
114
|
+
resourceUrl.origin === podRoot.origin &&
|
|
115
|
+
resourceUrl.pathname.startsWith(podRoot.pathname);
|
|
116
|
+
}
|
|
117
|
+
isAllowedAiConnectionResource(intent) {
|
|
118
|
+
let resourceUrl;
|
|
119
|
+
try {
|
|
120
|
+
resourceUrl = new URL(intent.resourceUrl);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
if (resourceUrl.hash || resourceUrl.search) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
const allowed = (0, AiConnectionServiceAccess_1.createAiConnectionServiceAccess)({
|
|
129
|
+
ownerWebId: intent.ownerWebId,
|
|
130
|
+
serviceWebId: intent.ownerWebId,
|
|
131
|
+
}).resources.map((resource) => resource.url);
|
|
132
|
+
return allowed.includes(resourceUrl.href);
|
|
133
|
+
}
|
|
134
|
+
async delegate(request, response, intent) {
|
|
135
|
+
const identifier = { path: intent.resourceUrl };
|
|
136
|
+
switch (intent.method) {
|
|
137
|
+
case 'GET': {
|
|
138
|
+
const representation = await this.resourceStore.getRepresentation(identifier, {
|
|
139
|
+
type: { 'text/turtle': 1, '*/*': 0.1 },
|
|
140
|
+
});
|
|
141
|
+
response.statusCode = 200;
|
|
142
|
+
response.setHeader('Content-Type', representation.metadata.contentType ?? 'text/turtle');
|
|
143
|
+
await this.pipeRepresentation(representation, response);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
case 'PUT': {
|
|
147
|
+
await this.resourceStore.setRepresentation(identifier, this.createRepresentation(request, intent.resourceUrl));
|
|
148
|
+
response.statusCode = 204;
|
|
149
|
+
response.end();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
case 'PATCH': {
|
|
153
|
+
await this.resourceStore.modifyResource(identifier, await this.createPatch(request, intent.resourceUrl));
|
|
154
|
+
response.statusCode = 204;
|
|
155
|
+
response.end();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
case 'DELETE': {
|
|
159
|
+
await this.resourceStore.deleteResource(identifier);
|
|
160
|
+
response.statusCode = 204;
|
|
161
|
+
response.end();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
createRepresentation(request, resourceUrl) {
|
|
166
|
+
const contentType = firstHeader(request.headers['content-type']) ?? 'text/turtle';
|
|
167
|
+
return new community_server_1.BasicRepresentation(request, new community_server_1.RepresentationMetadata({ path: resourceUrl }, contentType));
|
|
168
|
+
}
|
|
169
|
+
async createPatch(request, resourceUrl) {
|
|
170
|
+
if (!this.patchBodyParser) {
|
|
171
|
+
throw new community_server_1.NotImplementedHttpError('Internal Pod data PATCH requires a PatchBodyParser.');
|
|
172
|
+
}
|
|
173
|
+
const contentType = firstHeader(request.headers['content-type']) ?? 'application/sparql-update';
|
|
174
|
+
const metadata = new community_server_1.RepresentationMetadata({ path: resourceUrl }, contentType);
|
|
175
|
+
return this.patchBodyParser.handleSafe({ request, metadata });
|
|
176
|
+
}
|
|
177
|
+
async pipeRepresentation(representation, response) {
|
|
178
|
+
await (0, promises_1.pipeline)(representation.data, response);
|
|
179
|
+
}
|
|
180
|
+
writeNotFound(response) {
|
|
181
|
+
response.statusCode = 404;
|
|
182
|
+
response.setHeader('Cache-Control', 'no-store');
|
|
183
|
+
response.end('Not Found');
|
|
184
|
+
}
|
|
185
|
+
parseUrl(request) {
|
|
186
|
+
return new URL(request.url ?? '/', `http://${request.headers.host ?? 'localhost'}`);
|
|
187
|
+
}
|
|
188
|
+
parseOptionalUrl(value) {
|
|
189
|
+
if (!value) {
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
return new URL(ensureTrailingSlash(value));
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
isInsideDeployment(url) {
|
|
200
|
+
return this.deploymentBaseUrl !== undefined &&
|
|
201
|
+
url.origin === this.deploymentBaseUrl.origin &&
|
|
202
|
+
url.pathname.startsWith(this.deploymentBaseUrl.pathname);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
exports.InternalPodDataHttpHandler = InternalPodDataHttpHandler;
|
|
206
|
+
function isHttpNotFound(error) {
|
|
207
|
+
return typeof error === 'object' &&
|
|
208
|
+
error !== null &&
|
|
209
|
+
('statusCode' in error ? error.statusCode === 404 : error.name === 'NotFoundHttpError');
|
|
210
|
+
}
|
|
211
|
+
function firstHeader(value) {
|
|
212
|
+
return Array.isArray(value) ? value[0] : value;
|
|
213
|
+
}
|
|
214
|
+
function hostedPodRootFromOwner(ownerUrl) {
|
|
215
|
+
if (ownerUrl.hash !== '#me') {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
if (!ownerUrl.pathname.endsWith('/profile/card')) {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
const podPath = ownerUrl.pathname.slice(0, -'profile/card'.length);
|
|
222
|
+
if (!podPath || !podPath.endsWith('/')) {
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
return new URL(podPath, ownerUrl.origin);
|
|
226
|
+
}
|
|
227
|
+
function ensureTrailingSlash(value) {
|
|
228
|
+
return value.endsWith('/') ? value : `${value}/`;
|
|
229
|
+
}
|
|
230
|
+
class BoundedTtlNonceCache {
|
|
231
|
+
constructor(options) {
|
|
232
|
+
this.entries = new Map();
|
|
233
|
+
this.ttlMs = Math.max(1, options.ttlMs);
|
|
234
|
+
this.maxEntries = Math.max(1, options.maxEntries);
|
|
235
|
+
this.now = options.now ?? Date.now;
|
|
236
|
+
}
|
|
237
|
+
consume(nonce) {
|
|
238
|
+
const now = this.now();
|
|
239
|
+
this.pruneExpired(now);
|
|
240
|
+
if (this.entries.has(nonce)) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
if (this.entries.size >= this.maxEntries) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
this.entries.set(nonce, now + this.ttlMs);
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
pruneExpired(now) {
|
|
250
|
+
for (const [nonce, expiresAt] of this.entries) {
|
|
251
|
+
if (expiresAt > now) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
this.entries.delete(nonce);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=InternalPodDataHttpHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InternalPodDataHttpHandler.js","sourceRoot":"","sources":["../../src/http/InternalPodDataHttpHandler.ts"],"names":[],"mappings":";;;AACA,mDAAgD;AAChD,iEAAqD;AACrD,8DAYiC;AACjC,0GAA6G;AAC7G,4EAI0C;AAkB1C,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAE,CAAC,CAAC;AACrE,MAAM,oBAAoB,GAAG,OAAO,CAAC;AACrC,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAEzC,MAAa,0BAA2B,SAAQ,8BAAW;IASzD,YAAmB,OAA0C;QAC3D,KAAK,EAAE,CAAC;QATS,WAAM,GAAG,IAAA,oCAAY,EAAC,IAAI,CAAC,CAAC;QAU7C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,2BAA2B,GAAG,OAAO,CAAC,2BAA2B,IAAI,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAA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AAS;YACX,CAAC;YACD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;CAEF","sourcesContent":["import { Readable } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\nimport { getLoggerFor } from 'global-logger-factory';\nimport {\n BasicRepresentation,\n HttpHandler,\n NotImplementedHttpError,\n RepresentationMetadata,\n type BodyParser,\n type HttpHandlerInput,\n type HttpRequest,\n type HttpResponse,\n type Patch,\n type Representation,\n type ResourceStore,\n} from '@solid/community-server';\nimport { createAiConnectionServiceAccess } from '../api/ai-gateway/service-access/AiConnectionServiceAccess';\nimport {\n isLoopbackRemoteAddress,\n verifyGatewayAdminProxyHeaders,\n type GatewayAdminProxyIntent,\n} from '../runtime/GatewayAdminProxyAuth';\n\nexport interface InternalPodDataHttpHandlerOptions {\n resourceStore: ResourceStore;\n gatewayAdminProxyAuthSecret?: string;\n patchBodyParser?: BodyParser;\n baseUrl?: string;\n basePath?: string;\n}\n\ninterface InternalPodDataHttpHandlerNonceOptions {\n nonceTtlMs?: number;\n nonceMaxEntries?: number;\n now?: () => number;\n}\n\ntype InternalPodDataMethod = 'GET' | 'PUT' | 'PATCH' | 'DELETE';\n\nconst ALLOWED_METHODS = new Set([ 'GET', 'PUT', 'PATCH', 'DELETE' ]);\nconst DEFAULT_NONCE_TTL_MS = 120_000;\nconst DEFAULT_NONCE_MAX_ENTRIES = 10_000;\n\nexport class InternalPodDataHttpHandler extends HttpHandler {\n protected readonly logger = getLoggerFor(this);\n private readonly resourceStore: ResourceStore;\n private readonly gatewayAdminProxyAuthSecret?: string;\n private readonly patchBodyParser?: BodyParser;\n private readonly deploymentBaseUrl?: URL;\n private readonly basePath: string;\n private readonly seenNonces: BoundedTtlNonceCache;\n\n public constructor(options: InternalPodDataHttpHandlerOptions) {\n super();\n this.resourceStore = options.resourceStore;\n this.gatewayAdminProxyAuthSecret = options.gatewayAdminProxyAuthSecret ?? process.env.XPOD_GATEWAY_ADMIN_PROXY_AUTH_SECRET;\n this.patchBodyParser = options.patchBodyParser;\n this.deploymentBaseUrl = this.parseOptionalUrl(options.baseUrl ?? process.env.CSS_BASE_URL);\n this.basePath = options.basePath ?? '/.internal/pod-data';\n const nonceOptions = options as InternalPodDataHttpHandlerOptions & InternalPodDataHttpHandlerNonceOptions;\n this.seenNonces = new BoundedTtlNonceCache({\n ttlMs: nonceOptions.nonceTtlMs ?? DEFAULT_NONCE_TTL_MS,\n maxEntries: nonceOptions.nonceMaxEntries ?? DEFAULT_NONCE_MAX_ENTRIES,\n now: nonceOptions.now,\n });\n }\n\n public override async canHandle({ request }: HttpHandlerInput): Promise<void> {\n if (this.parseUrl(request).pathname !== this.basePath) {\n throw new NotImplementedHttpError('Not an internal Pod data request.');\n }\n }\n\n public override async handle({ request, response }: HttpHandlerInput): Promise<void> {\n if (this.parseUrl(request).pathname !== this.basePath) {\n throw new NotImplementedHttpError('Not an internal Pod data request.');\n }\n\n const intent = this.verifyRequest(request);\n if (!intent) {\n this.writeNotFound(response);\n return;\n }\n\n try {\n await this.delegate(request, response, intent);\n } catch (error: unknown) {\n if (isHttpNotFound(error)) {\n this.writeNotFound(response);\n return;\n }\n throw error;\n }\n }\n\n private verifyRequest(request: HttpRequest): GatewayAdminProxyIntent | undefined {\n const method = request.method?.toUpperCase();\n if (!ALLOWED_METHODS.has(method ?? '')) {\n return undefined;\n }\n if (!isLoopbackRemoteAddress(request.socket.remoteAddress)) {\n return undefined;\n }\n\n const verification = verifyGatewayAdminProxyHeaders({\n headers: request.headers,\n secret: this.gatewayAdminProxyAuthSecret,\n method,\n url: request.url,\n });\n if (!verification.valid || !verification.originalClientLoopback || !verification.intent || !verification.nonce) {\n return undefined;\n }\n if (!this.intentMatchesRequest(verification.intent, method as InternalPodDataMethod)) {\n return undefined;\n }\n if (!this.isHostedOwnerResource(verification.intent)) {\n return undefined;\n }\n if (!this.isAllowedAiConnectionResource(verification.intent)) {\n return undefined;\n }\n if (!this.seenNonces.consume(verification.nonce)) {\n return undefined;\n }\n return verification.intent;\n }\n\n private intentMatchesRequest(intent: GatewayAdminProxyIntent, method: InternalPodDataMethod): boolean {\n if (intent.method !== method) {\n return false;\n }\n if (intent.scopes.length === 0) {\n return false;\n }\n const requiredScope = method === 'GET' ? 'ai:credentials:read' : 'ai:credentials:write';\n return intent.scopes.some((scope) =>\n scope === requiredScope ||\n scope === 'ai:credentials:*' ||\n scope === 'ai:*',\n );\n }\n\n private isHostedOwnerResource(intent: GatewayAdminProxyIntent): boolean {\n if (!this.deploymentBaseUrl) {\n return false;\n }\n\n let ownerUrl: URL;\n let resourceUrl: URL;\n try {\n ownerUrl = new URL(intent.ownerWebId);\n resourceUrl = new URL(intent.resourceUrl);\n } catch {\n return false;\n }\n if (!this.isInsideDeployment(ownerUrl) || !this.isInsideDeployment(resourceUrl)) {\n return false;\n }\n\n const podRoot = hostedPodRootFromOwner(ownerUrl);\n return podRoot !== undefined &&\n resourceUrl.origin === podRoot.origin &&\n resourceUrl.pathname.startsWith(podRoot.pathname);\n }\n\n private isAllowedAiConnectionResource(intent: GatewayAdminProxyIntent): boolean {\n let resourceUrl: URL;\n try {\n resourceUrl = new URL(intent.resourceUrl);\n } catch {\n return false;\n }\n if (resourceUrl.hash || resourceUrl.search) {\n return false;\n }\n const allowed = createAiConnectionServiceAccess({\n ownerWebId: intent.ownerWebId,\n serviceWebId: intent.ownerWebId,\n }).resources.map((resource) => resource.url);\n return allowed.includes(resourceUrl.href);\n }\n\n private async delegate(\n request: HttpRequest,\n response: HttpResponse,\n intent: GatewayAdminProxyIntent,\n ): Promise<void> {\n const identifier = { path: intent.resourceUrl };\n switch (intent.method) {\n case 'GET': {\n const representation = await this.resourceStore.getRepresentation(identifier, {\n type: { 'text/turtle': 1, '*/*': 0.1 },\n });\n response.statusCode = 200;\n response.setHeader('Content-Type', representation.metadata.contentType ?? 'text/turtle');\n await this.pipeRepresentation(representation, response);\n return;\n }\n case 'PUT': {\n await this.resourceStore.setRepresentation(identifier, this.createRepresentation(request, intent.resourceUrl));\n response.statusCode = 204;\n response.end();\n return;\n }\n case 'PATCH': {\n await this.resourceStore.modifyResource(identifier, await this.createPatch(request, intent.resourceUrl));\n response.statusCode = 204;\n response.end();\n return;\n }\n case 'DELETE': {\n await this.resourceStore.deleteResource(identifier);\n response.statusCode = 204;\n response.end();\n }\n }\n }\n\n private createRepresentation(request: HttpRequest, resourceUrl: string): Representation {\n const contentType = firstHeader(request.headers['content-type']) ?? 'text/turtle';\n return new BasicRepresentation(\n request,\n new RepresentationMetadata({ path: resourceUrl }, contentType),\n );\n }\n\n private async createPatch(request: HttpRequest, resourceUrl: string): Promise<Patch> {\n if (!this.patchBodyParser) {\n throw new NotImplementedHttpError('Internal Pod data PATCH requires a PatchBodyParser.');\n }\n const contentType = firstHeader(request.headers['content-type']) ?? 'application/sparql-update';\n const metadata = new RepresentationMetadata({ path: resourceUrl }, contentType);\n return this.patchBodyParser.handleSafe({ request, metadata }) as Promise<Patch>;\n }\n\n private async pipeRepresentation(representation: Representation, response: HttpResponse): Promise<void> {\n await pipeline(representation.data as Readable, response);\n }\n\n private writeNotFound(response: HttpResponse): void {\n response.statusCode = 404;\n response.setHeader('Cache-Control', 'no-store');\n response.end('Not Found');\n }\n\n private parseUrl(request: HttpRequest): URL {\n return new URL(request.url ?? '/', `http://${request.headers.host ?? 'localhost'}`);\n }\n\n private parseOptionalUrl(value: string | undefined): URL | undefined {\n if (!value) {\n return undefined;\n }\n try {\n return new URL(ensureTrailingSlash(value));\n } catch {\n return undefined;\n }\n }\n\n private isInsideDeployment(url: URL): boolean {\n return this.deploymentBaseUrl !== undefined &&\n url.origin === this.deploymentBaseUrl.origin &&\n url.pathname.startsWith(this.deploymentBaseUrl.pathname);\n }\n}\n\nfunction isHttpNotFound(error: unknown): boolean {\n return typeof error === 'object' &&\n error !== null &&\n ('statusCode' in error ? error.statusCode === 404 : (error as { name?: string }).name === 'NotFoundHttpError');\n}\n\nfunction firstHeader(value: string | string[] | undefined): string | undefined {\n return Array.isArray(value) ? value[0] : value;\n}\n\nfunction hostedPodRootFromOwner(ownerUrl: URL): URL | undefined {\n if (ownerUrl.hash !== '#me') {\n return undefined;\n }\n if (!ownerUrl.pathname.endsWith('/profile/card')) {\n return undefined;\n }\n const podPath = ownerUrl.pathname.slice(0, -'profile/card'.length);\n if (!podPath || !podPath.endsWith('/')) {\n return undefined;\n }\n return new URL(podPath, ownerUrl.origin);\n}\n\nfunction ensureTrailingSlash(value: string): string {\n return value.endsWith('/') ? value : `${value}/`;\n}\n\nclass BoundedTtlNonceCache {\n private readonly ttlMs: number;\n private readonly maxEntries: number;\n private readonly now: () => number;\n private readonly entries = new Map<string, number>();\n\n public constructor(options: { ttlMs: number; maxEntries: number; now?: () => number }) {\n this.ttlMs = Math.max(1, options.ttlMs);\n this.maxEntries = Math.max(1, options.maxEntries);\n this.now = options.now ?? Date.now;\n }\n\n public consume(nonce: string): boolean {\n const now = this.now();\n this.pruneExpired(now);\n if (this.entries.has(nonce)) {\n return false;\n }\n if (this.entries.size >= this.maxEntries) {\n return false;\n }\n this.entries.set(nonce, now + this.ttlMs);\n return true;\n }\n\n private pruneExpired(now: number): void {\n for (const [nonce, expiresAt] of this.entries) {\n if (expiresAt > now) {\n continue;\n }\n this.entries.delete(nonce);\n }\n }\n\n}\n"]}
|