@codemation/host 0.8.0 → 0.9.0

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.
Files changed (148) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/{ApiPaths-Dv1dcHu_.js → ApiPaths-DCvrlIjg.js} +12 -1
  3. package/dist/{ApiPaths-Dv1dcHu_.js.map → ApiPaths-DCvrlIjg.js.map} +1 -1
  4. package/dist/{AppConfigFactory-Cx4qQvRk.js → AppConfigFactory-D4LL1aOR.js} +77 -297
  5. package/dist/AppConfigFactory-D4LL1aOR.js.map +1 -0
  6. package/dist/{AppConfigFactory-BT0y0LVC.d.ts → AppConfigFactory-DncmwCD1.d.ts} +2918 -199
  7. package/dist/{AppContainerFactory-DRTjG7nG.js → AppContainerFactory-jpYXGZGe.js} +1724 -474
  8. package/dist/AppContainerFactory-jpYXGZGe.js.map +1 -0
  9. package/dist/{CodemationAppContext-CGFYVcSb.d.ts → CodemationAppContext-K51b7oXe.d.ts} +3 -3
  10. package/dist/{CodemationAuthoring.types-DiKKogum.d.ts → CodemationAuthoring.types-BXlXIl4K.d.ts} +4 -4
  11. package/dist/{CodemationConfigNormalizer-48f-T66P.d.ts → CodemationConfigNormalizer-B4rDYC9h.d.ts} +3 -3
  12. package/dist/{CodemationConsumerConfigLoader-_PIYqwVx.d.ts → CodemationConsumerConfigLoader-Dt4jyLx6.d.ts} +2 -2
  13. package/dist/{CodemationPluginListMerger-DP7djJ9S.d.ts → CodemationPluginListMerger-DS6I3Xe0.d.ts} +24 -12
  14. package/dist/{persistenceServer-C-hH4z6l.js → CodemationPostgresPrismaClientFactory-C7156Fe-.js} +2 -2
  15. package/dist/CodemationPostgresPrismaClientFactory-C7156Fe-.js.map +1 -0
  16. package/dist/CodemationPostgresPrismaClientFactory-CTNTPnDr.d.ts +9 -0
  17. package/dist/{CredentialContractsRegistry-Bq2bq28t.d.ts → CredentialContractsRegistry-Dgu-rEXi.d.ts} +16 -3
  18. package/dist/{CredentialServices-BLloBztI.d.ts → CredentialServices-B3wPyp2y.d.ts} +4 -4
  19. package/dist/{CredentialServices-Dk8yypeL.js → CredentialServices-Bios0dM8.js} +10 -4
  20. package/dist/CredentialServices-Bios0dM8.js.map +1 -0
  21. package/dist/{InternalHonoApiRouteRegistrar-c7t3KnV_.d.ts → InternalHonoApiRouteRegistrar-Ce1yxpnO.d.ts} +1 -1
  22. package/dist/{InternalPingRegistrar-DY3kSfxP.js → InternalPingRegistrar-BavAAnvk.js} +19 -16
  23. package/dist/InternalPingRegistrar-BavAAnvk.js.map +1 -0
  24. package/dist/{ItemsInputNormalizer-_RwIfRIQ.d.ts → ItemsInputNormalizer-CFkfNMLt.d.ts} +1434 -1225
  25. package/dist/PrismaMigrationDeployer-DdEcXXVi.d.ts +14 -0
  26. package/dist/{PublicFrontendBootstrapFactory-Dv04tJ-6.d.ts → PublicFrontendBootstrapFactory-ClEjZP74.d.ts} +2 -2
  27. package/dist/{PublicFrontendBootstrapJsonCodec-CXG9Dxft.d.ts → PublicFrontendBootstrapJsonCodec-HNItQ7ol.d.ts} +6 -1
  28. package/dist/{TelemetryContracts-BtDx84Cp.d.ts → TelemetryContracts-DpZEODQM.d.ts} +2 -2
  29. package/dist/{WorkflowPolicyUiPresentationFactory-6MyjCvBO.d.ts → WorkflowPolicyUiPresentationFactory-BNn2fvR_.d.ts} +2 -2
  30. package/dist/{WorkflowPolicyUiPresentationFactory-Bb-ae_Zh.js → WorkflowPolicyUiPresentationFactory-DfvD2VHk.js} +1 -1
  31. package/dist/{WorkflowPolicyUiPresentationFactory-Bb-ae_Zh.js.map → WorkflowPolicyUiPresentationFactory-DfvD2VHk.js.map} +1 -1
  32. package/dist/authoring.d.ts +4 -4
  33. package/dist/client.d.ts +1 -1
  34. package/dist/client.js +1 -1
  35. package/dist/consumer.d.ts +5 -5
  36. package/dist/credentials.d.ts +5 -5
  37. package/dist/credentials.js +1 -1
  38. package/dist/devServerSidecar.d.ts +2 -2
  39. package/dist/dto.d.ts +5 -5
  40. package/dist/{index-DilAYwnH.d.ts → index-ChIfeWzk.d.ts} +71 -28
  41. package/dist/index.d.ts +17 -16
  42. package/dist/index.js +8 -8
  43. package/dist/infrastructure/persistence/PrismaMigrationOperations.d.ts +44 -0
  44. package/dist/infrastructure/persistence/PrismaMigrationOperations.js +302 -0
  45. package/dist/infrastructure/persistence/PrismaMigrationOperations.js.map +1 -0
  46. package/dist/mapping.d.ts +2 -2
  47. package/dist/mapping.js +1 -1
  48. package/dist/nextServer.d.ts +15 -13
  49. package/dist/nextServer.js +6 -6
  50. package/dist/pairing.d.ts +28 -9
  51. package/dist/pairing.js +19 -3
  52. package/dist/pairing.js.map +1 -0
  53. package/dist/{pairing.types-snfZ_OzB.d.ts → pairing.types-D9Bjn98U.d.ts} +1 -1
  54. package/dist/persistenceServer.d.ts +31 -7
  55. package/dist/persistenceServer.js +2 -2
  56. package/dist/{server-09PKasWR.d.ts → server-B5trn7y4.d.ts} +5 -5
  57. package/dist/{server-vtRCPgRJ.js → server-BlG9qV5S.js} +4 -4
  58. package/dist/{server-vtRCPgRJ.js.map → server-BlG9qV5S.js.map} +1 -1
  59. package/dist/server.d.ts +10 -10
  60. package/dist/server.js +8 -8
  61. package/package.json +10 -9
  62. package/playwright.config.ts +8 -2
  63. package/playwright.scaffolded-dev.config.ts +8 -2
  64. package/prisma/migrations/20260526120000_credential_material_pointer/migration.sql +18 -0
  65. package/prisma/migrations/20260527120000_add_human_task/migration.sql +32 -0
  66. package/prisma/migrations/20260527130000_add_hitl_state_json/migration.sql +6 -0
  67. package/prisma/migrations/20260527130000_add_hmac_nonce/migration.sql +12 -0
  68. package/prisma/migrations.sqlite/20260526120000_credential_material_pointer/migration.sql +13 -0
  69. package/prisma/migrations.sqlite/20260527120000_add_human_task/migration.sql +30 -0
  70. package/prisma/migrations.sqlite/20260527130000_add_hitl_state_json/migration.sql +6 -0
  71. package/prisma/migrations.sqlite/20260527130000_add_hmac_nonce/migration.sql +9 -0
  72. package/prisma/schema.postgresql.prisma +48 -0
  73. package/prisma/schema.sqlite.prisma +48 -0
  74. package/prisma-generated/prisma-postgresql-client/edge.js +40 -6
  75. package/prisma-generated/prisma-postgresql-client/index-browser.js +36 -2
  76. package/prisma-generated/prisma-postgresql-client/index.d.ts +3179 -163
  77. package/prisma-generated/prisma-postgresql-client/index.js +40 -6
  78. package/prisma-generated/prisma-postgresql-client/package.json +1 -1
  79. package/prisma-generated/prisma-postgresql-client/schema.prisma +48 -0
  80. package/prisma-generated/prisma-sqlite-client/edge.js +40 -6
  81. package/prisma-generated/prisma-sqlite-client/index-browser.js +36 -2
  82. package/prisma-generated/prisma-sqlite-client/index.d.ts +3175 -163
  83. package/prisma-generated/prisma-sqlite-client/index.js +40 -6
  84. package/prisma-generated/prisma-sqlite-client/package.json +1 -1
  85. package/prisma-generated/prisma-sqlite-client/schema.prisma +48 -0
  86. package/src/application/contracts/CredentialContractsRegistry.ts +15 -0
  87. package/src/application/credentials/AppGalleryProjector.ts +69 -0
  88. package/src/application/hitl/DecideHumanTaskCommandHandler.ts +149 -0
  89. package/src/application/hitl/DecisionSchemaValidator.ts +22 -0
  90. package/src/application/hitl/HitlCallbackHandler.ts +96 -0
  91. package/src/application/mapping/WorkflowDefinitionMapper.ts +1 -3
  92. package/src/application/queries/CredentialQueryHandlers.ts +2 -0
  93. package/src/application/queries/GetCredentialAppsQuery.ts +4 -0
  94. package/src/application/queries/GetCredentialAppsQueryHandler.ts +27 -0
  95. package/src/application/telemetry/ResumeTelemetryContextForRun.ts +53 -0
  96. package/src/application/telemetry/TelemetryRetentionTimestampFactory.ts +9 -8
  97. package/src/applicationTokens.ts +11 -1
  98. package/src/auth/managed/ManagedCorsMiddleware.ts +20 -5
  99. package/src/bootstrap/AppContainerFactory.ts +100 -0
  100. package/src/credentials/CachingCredentialMaterialProvider.ts +96 -0
  101. package/src/credentials/CompositeCredentialMaterialProvider.ts +47 -0
  102. package/src/credentials/ControlPlaneCatalogFetcher.ts +4 -24
  103. package/src/credentials/ControlPlaneCredentialMaterialProvider.ts +79 -0
  104. package/src/credentials/CredentialOAuth2MaterialReader.ts +2 -7
  105. package/src/credentials/InternalCredentialsBindingRegistrar.ts +83 -0
  106. package/src/credentials/LocalCredentialMaterialProvider.ts +92 -0
  107. package/src/domain/credentials/CredentialInstanceService.ts +5 -1
  108. package/src/domain/credentials/CredentialTypeRegistryImpl.ts +18 -4
  109. package/src/domain/workflows/WorkflowActivationPreflightRules.ts +7 -4
  110. package/src/dto.ts +2 -0
  111. package/src/hitl/ControlPlaneInboxChannel.ts +102 -0
  112. package/src/hitl/HitlResumeTokenSigner.ts +80 -0
  113. package/src/hitl/HitlTimeoutJobScheduler.ts +77 -0
  114. package/src/hitl/HitlTimeoutWorker.ts +138 -0
  115. package/src/hitl/InboxChannelResolver.ts +49 -0
  116. package/src/hitl/LocalInboxChannel.ts +37 -0
  117. package/src/infrastructure/persistence/PrismaCredentialStore.ts +10 -0
  118. package/src/infrastructure/persistence/PrismaHmacNonceStore.ts +29 -0
  119. package/src/infrastructure/persistence/PrismaHumanTaskStore.ts +156 -0
  120. package/src/infrastructure/persistence/PrismaMigrationDeployer.ts +53 -383
  121. package/src/infrastructure/persistence/PrismaMigrationOperations.ts +401 -0
  122. package/src/infrastructure/persistence/PrismaWorkflowRunRepository.ts +39 -0
  123. package/src/mcp/AgentMcpIntegrationImpl.ts +5 -1
  124. package/src/pairing/HmacNonceStore.ts +14 -0
  125. package/src/pairing/HmacNonceStoreToken.ts +4 -0
  126. package/src/pairing/HmacRequestSigner.ts +10 -1
  127. package/src/pairing/InMemoryHmacNonceStore.ts +24 -0
  128. package/src/pairing/IncomingHmacVerifier.ts +28 -12
  129. package/src/pairing/InternalHmacAuthMiddleware.ts +1 -1
  130. package/src/pairing/index.ts +3 -0
  131. package/src/presentation/http/ApiPaths.ts +14 -0
  132. package/src/presentation/http/hono/HonoHttpAnonymousRoutePolicyRegistry.ts +4 -0
  133. package/src/presentation/http/hono/registrars/CredentialHonoApiRouteRegistrar.ts +1 -0
  134. package/src/presentation/http/hono/registrars/HitlDecideHonoApiRouteRegistrar.ts +54 -0
  135. package/src/presentation/http/hono/registrars/HitlInternalCallbackHonoApiRouteRegistrar.ts +33 -0
  136. package/src/presentation/http/hono/registrars/HitlResumeHonoApiRouteRegistrar.ts +43 -0
  137. package/src/presentation/http/routeHandlers/CredentialHttpRouteHandler.ts +9 -0
  138. package/src/presentation/http/routeHandlers/OAuth2HttpRouteHandlerFactory.ts +1 -1
  139. package/src/server.ts +7 -2
  140. package/src/workflows/InternalWorkflowTestRunRegistrar.ts +9 -0
  141. package/tsconfig.json +1 -0
  142. package/dist/AppConfigFactory-Cx4qQvRk.js.map +0 -1
  143. package/dist/AppContainerFactory-DRTjG7nG.js.map +0 -1
  144. package/dist/CredentialServices-Dk8yypeL.js.map +0 -1
  145. package/dist/InternalPingRegistrar-DY3kSfxP.js.map +0 -1
  146. package/dist/persistenceServer-B71RGvSj.d.ts +0 -30
  147. package/dist/persistenceServer-C-hH4z6l.js.map +0 -1
  148. package/src/credentials/catalogTypes.ts +0 -4
@@ -1 +1 @@
1
- {"version":3,"file":"server-vtRCPgRJ.js","names":["config: CodemationConfig","consumerRoot: string","configSource?: string","workflowSources: ReadonlyArray<string>","env?: Readonly<NodeJS.ProcessEnv>","consumerConfigLoader: CodemationConsumerConfigLoader","appConfigFactory: AppConfigFactory","discoveredPackages: CodemationDiscoveredPluginPackage[]","resolvedPackages: CodemationResolvedPluginPackage[]","packageRoots: string[]"],"sources":["../src/presentation/http/CodemationServerGatewayFactory.ts","../src/presentation/server/AppConfigLoader.ts","../src/presentation/server/CodemationPluginDiscovery.ts"],"sourcesContent":["import { accessSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type { QueryBus } from \"../../application/bus/QueryBus\";\nimport type { WorkflowDto, WorkflowSummary } from \"../../application/contracts/WorkflowViewContracts\";\nimport { WorkflowDefinitionMapper } from \"../../application/mapping/WorkflowDefinitionMapper\";\nimport { GetWorkflowDetailQuery } from \"../../application/queries/GetWorkflowDetailQuery\";\nimport { GetWorkflowSummariesQuery } from \"../../application/queries/GetWorkflowSummariesQuery\";\nimport { ApplicationTokens } from \"../../applicationTokens\";\nimport { AppContainerFactory } from \"../../bootstrap/AppContainerFactory\";\nimport { AppContainerLifecycle } from \"../../bootstrap/AppContainerLifecycle\";\nimport { FrontendRuntime } from \"../../bootstrap/runtime/FrontendRuntime\";\nimport { AppConfigFactory } from \"../../bootstrap/runtime/AppConfigFactory\";\nimport type { CodemationConfig } from \"../config/CodemationConfig\";\nimport { CodemationConfigNormalizer } from \"../config/CodemationConfigNormalizer\";\nimport { CodemationHonoApiApp } from \"./hono/CodemationHonoApiAppFactory\";\n\ntype ServerGatewayContext = Readonly<{\n container: import(\"@codemation/core\").Container;\n httpApi: CodemationHonoApiApp;\n queryBus: QueryBus;\n workflowDefinitionMapper: WorkflowDefinitionMapper;\n}>;\n\nexport class CodemationServerGateway {\n private static readonly contextsByConfig = new WeakMap<object, Promise<ServerGatewayContext>>();\n\n constructor(\n private readonly config: CodemationConfig,\n private readonly consumerRoot: string,\n private readonly configSource?: string,\n private readonly workflowSources: ReadonlyArray<string> = [],\n private readonly env?: Readonly<NodeJS.ProcessEnv>,\n ) {}\n\n async dispatch(request: Request): Promise<Response> {\n return await (await this.getContext()).httpApi.fetch(request);\n }\n\n async prepare(): Promise<void> {\n await this.getContext();\n }\n\n async close(): Promise<void> {\n const cachedContext = CodemationServerGateway.contextsByConfig.get(this.config as object);\n if (!cachedContext) {\n return;\n }\n CodemationServerGateway.contextsByConfig.delete(this.config as object);\n await (await cachedContext).container.resolve(AppContainerLifecycle).stop();\n }\n\n async loadWorkflowSummaries(): Promise<ReadonlyArray<WorkflowSummary>> {\n const context = await this.getContext();\n const workflows = await context.queryBus.execute(new GetWorkflowSummariesQuery());\n return workflows.map((workflow) => context.workflowDefinitionMapper.toSummary(workflow));\n }\n\n async loadWorkflowDetail(workflowId: string): Promise<WorkflowDto> {\n const context = await this.getContext();\n const workflow = await context.queryBus.execute(new GetWorkflowDetailQuery(workflowId));\n if (!workflow) {\n throw new Error(`Unknown workflowId: ${workflowId}`);\n }\n return await context.workflowDefinitionMapper.map(workflow);\n }\n\n private getContext(): Promise<ServerGatewayContext> {\n const cachedContext = CodemationServerGateway.contextsByConfig.get(this.config as object);\n if (cachedContext) {\n return cachedContext;\n }\n const nextContext = this.createContext();\n CodemationServerGateway.contextsByConfig.set(this.config as object, nextContext);\n return nextContext;\n }\n\n private async createContext(): Promise<ServerGatewayContext> {\n const repoRoot = this.detectWorkspaceRoot(this.consumerRoot);\n // This gateway is the config/env boundary that materializes AppConfig from raw inputs.\n // eslint-disable-next-line no-restricted-properties\n const env = this.env ?? process.env;\n const appConfig = new AppConfigFactory().create({\n repoRoot,\n consumerRoot: this.consumerRoot,\n env,\n config: new CodemationConfigNormalizer().normalize(this.config),\n workflowSources: this.resolveWorkflowSources(),\n });\n const container = await new AppContainerFactory().create({\n appConfig,\n sharedWorkflowWebsocketServer: null,\n });\n await container.resolve(FrontendRuntime).start();\n return {\n container,\n httpApi: container.resolve(CodemationHonoApiApp),\n queryBus: container.resolve(ApplicationTokens.QueryBus),\n workflowDefinitionMapper: container.resolve(WorkflowDefinitionMapper),\n };\n }\n\n private resolveWorkflowSources(): ReadonlyArray<string> {\n if (this.workflowSources.length > 0) {\n return [...this.workflowSources];\n }\n if (!this.configSource || !this.config.workflows || this.config.workflows.length === 0) {\n return [];\n }\n return [this.configSource];\n }\n private detectWorkspaceRoot(startDirectory: string): string {\n let currentDirectory = path.resolve(startDirectory);\n while (true) {\n try {\n accessSync(path.resolve(currentDirectory, \"pnpm-workspace.yaml\"));\n return currentDirectory;\n } catch {\n const parentDirectory = path.dirname(currentDirectory);\n if (parentDirectory === currentDirectory) {\n return startDirectory;\n }\n currentDirectory = parentDirectory;\n }\n }\n }\n}\n","import type { AppConfig } from \"../config/AppConfig\";\nimport { CodemationConsumerConfigLoader } from \"./CodemationConsumerConfigLoader\";\nimport { AppConfigFactory } from \"../../bootstrap/runtime/AppConfigFactory\";\n\nexport type AppConfigLoadResult = Readonly<{\n appConfig: AppConfig;\n bootstrapSource: string | null;\n}>;\n\nexport class AppConfigLoader {\n constructor(\n private readonly consumerConfigLoader: CodemationConsumerConfigLoader = new CodemationConsumerConfigLoader(),\n private readonly appConfigFactory: AppConfigFactory = new AppConfigFactory(),\n ) {}\n\n async load(\n args: Readonly<{\n consumerRoot: string;\n repoRoot: string;\n env: NodeJS.ProcessEnv;\n configPathOverride?: string;\n }>,\n ): Promise<AppConfigLoadResult> {\n const resolution = await this.consumerConfigLoader.load({\n consumerRoot: args.consumerRoot,\n configPathOverride: args.configPathOverride,\n });\n return {\n appConfig: this.appConfigFactory.create({\n repoRoot: args.repoRoot,\n consumerRoot: args.consumerRoot,\n env: args.env,\n config: resolution.config,\n workflowSources: resolution.workflowSources,\n }),\n bootstrapSource: resolution.bootstrapSource,\n };\n }\n}\n","import type { CodemationPackageManifest } from \"../config/CodemationPackageManifest\";\nimport { CodemationPluginPackageMetadata, type CodemationPlugin } from \"../config/CodemationPlugin\";\nimport { readFile, readdir } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nexport type CodemationDiscoveredPluginPackage = Readonly<{\n packageName: string;\n packageRoot: string;\n pluginEntry: string;\n developmentEntry?: string;\n}>;\n\nexport type CodemationResolvedPluginPackage = Readonly<\n CodemationDiscoveredPluginPackage & {\n plugin: CodemationPlugin;\n }\n>;\n\ntype PackageJsonShape = Readonly<{\n codemation?: CodemationPackageManifest;\n name?: string;\n exports?: Readonly<Record<string, unknown>>;\n}>;\n\nexport class CodemationPluginDiscovery {\n private readonly pluginPackageMetadata = new CodemationPluginPackageMetadata();\n\n async discover(consumerRoot: string): Promise<ReadonlyArray<CodemationDiscoveredPluginPackage>> {\n const nodeModulesRoot = path.resolve(consumerRoot, \"node_modules\");\n const packageRoots = await this.collectPackageRoots(nodeModulesRoot);\n const discoveredPackages: CodemationDiscoveredPluginPackage[] = [];\n for (const packageRoot of packageRoots) {\n const packageJson = await this.readPackageJson(path.resolve(packageRoot, \"package.json\"));\n const pluginManifest = packageJson.codemation?.plugin;\n if (!packageJson.name || typeof pluginManifest !== \"string\" || pluginManifest.trim().length === 0) {\n continue;\n }\n discoveredPackages.push({\n packageName: packageJson.name,\n packageRoot,\n pluginEntry: pluginManifest,\n developmentEntry: await this.resolveDevelopmentPluginEntry(packageRoot),\n });\n }\n return discoveredPackages.sort((left, right) => left.packageName.localeCompare(right.packageName));\n }\n\n async resolvePlugins(consumerRoot: string): Promise<ReadonlyArray<CodemationResolvedPluginPackage>> {\n const discoveredPackages = await this.discover(consumerRoot);\n return await this.resolveDiscoveredPackages(discoveredPackages);\n }\n\n async resolveDiscoveredPackages(\n discoveredPackages: ReadonlyArray<CodemationDiscoveredPluginPackage>,\n ): Promise<ReadonlyArray<CodemationResolvedPluginPackage>> {\n const resolvedPackages: CodemationResolvedPluginPackage[] = [];\n for (const discoveredPackage of discoveredPackages) {\n resolvedPackages.push({\n ...discoveredPackage,\n plugin: await this.loadPlugin(discoveredPackage),\n });\n }\n return resolvedPackages;\n }\n\n private async collectPackageRoots(nodeModulesRoot: string): Promise<ReadonlyArray<string>> {\n try {\n const entries = await readdir(nodeModulesRoot, { withFileTypes: true });\n const packageRoots: string[] = [];\n for (const entry of entries) {\n if (!entry.isDirectory() && !entry.isSymbolicLink()) {\n continue;\n }\n if (entry.name.startsWith(\"@\")) {\n const scopedEntries = await readdir(path.resolve(nodeModulesRoot, entry.name), { withFileTypes: true });\n for (const scopedEntry of scopedEntries) {\n if (scopedEntry.isDirectory() || scopedEntry.isSymbolicLink()) {\n packageRoots.push(path.resolve(nodeModulesRoot, entry.name, scopedEntry.name));\n }\n }\n continue;\n }\n packageRoots.push(path.resolve(nodeModulesRoot, entry.name));\n }\n return packageRoots;\n } catch {\n return [];\n }\n }\n\n private async readPackageJson(packageJsonPath: string): Promise<PackageJsonShape> {\n try {\n const rawPackageJson = await readFile(packageJsonPath, \"utf8\");\n return JSON.parse(rawPackageJson) as PackageJsonShape;\n } catch {\n return {};\n }\n }\n\n private async loadPlugin(discoveredPackage: CodemationDiscoveredPluginPackage): Promise<CodemationPlugin> {\n const pluginModulePath = path.resolve(discoveredPackage.packageRoot, this.resolvePluginEntry(discoveredPackage));\n const importedModule = (await import(\n /* webpackIgnore: true */ this.resolvePluginModuleSpecifier(pluginModulePath)\n )) as Record<string, unknown>;\n const exportedValue = importedModule.default;\n const plugin = this.resolvePluginValue(exportedValue);\n if (!plugin) {\n throw new Error(`Plugin package \"${discoveredPackage.packageName}\" did not default-export a Codemation plugin.`);\n }\n return this.pluginPackageMetadata.attachPackageName(plugin, discoveredPackage.packageName);\n }\n\n private resolvePluginValue(value: unknown): CodemationPlugin | null {\n if (this.isPluginConfig(value)) {\n return value;\n }\n return null;\n }\n\n private isPluginConfig(value: unknown): value is CodemationPlugin {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return false;\n }\n const pluginValue = value as {\n credentialTypes?: unknown;\n mcpServers?: unknown;\n register?: unknown;\n sandbox?: unknown;\n };\n if (pluginValue.register !== undefined && typeof pluginValue.register !== \"function\") {\n return false;\n }\n if (pluginValue.credentialTypes !== undefined && !Array.isArray(pluginValue.credentialTypes)) {\n return false;\n }\n if (pluginValue.mcpServers !== undefined && !Array.isArray(pluginValue.mcpServers)) {\n return false;\n }\n return (\n pluginValue.register !== undefined ||\n pluginValue.credentialTypes !== undefined ||\n pluginValue.mcpServers !== undefined ||\n pluginValue.sandbox !== undefined ||\n Object.keys(pluginValue).length === 0\n );\n }\n\n private resolvePluginEntry(discoveredPackage: CodemationDiscoveredPluginPackage): string {\n const preferSource =\n process.env.CODEMATION_PREFER_PLUGIN_SOURCE_ENTRY === \"true\" &&\n typeof discoveredPackage.developmentEntry === \"string\" &&\n discoveredPackage.developmentEntry.trim().length > 0;\n const selectedEntry = preferSource ? discoveredPackage.developmentEntry : discoveredPackage.pluginEntry;\n return selectedEntry;\n }\n\n private async resolveDevelopmentPluginEntry(packageRoot: string): Promise<string | undefined> {\n const candidates = [\n path.resolve(packageRoot, \"codemation.plugin.ts\"),\n path.resolve(packageRoot, \"codemation.plugin.js\"),\n path.resolve(packageRoot, \"src\", \"codemation.plugin.ts\"),\n path.resolve(packageRoot, \"src\", \"codemation.plugin.js\"),\n ];\n for (const candidate of candidates) {\n if (await this.exists(candidate)) {\n return path.relative(packageRoot, candidate);\n }\n }\n return undefined;\n }\n\n private async exists(filePath: string): Promise<boolean> {\n try {\n await readFile(filePath, \"utf8\");\n return true;\n } catch {\n return false;\n }\n }\n\n private resolvePluginModuleSpecifier(pluginModulePath: string): string {\n return pathToFileURL(pluginModulePath).href;\n }\n}\n"],"mappings":";;;;;;;;;;AAuBA,IAAa,0BAAb,MAAa,wBAAwB;CACnC,OAAwB,mCAAmB,IAAI,SAAgD;CAE/F,YACE,AAAiBA,QACjB,AAAiBC,cACjB,AAAiBC,cACjB,AAAiBC,kBAAyC,EAAE,EAC5D,AAAiBC,KACjB;EALiB;EACA;EACA;EACA;EACA;;CAGnB,MAAM,SAAS,SAAqC;AAClD,SAAO,OAAO,MAAM,KAAK,YAAY,EAAE,QAAQ,MAAM,QAAQ;;CAG/D,MAAM,UAAyB;AAC7B,QAAM,KAAK,YAAY;;CAGzB,MAAM,QAAuB;EAC3B,MAAM,gBAAgB,wBAAwB,iBAAiB,IAAI,KAAK,OAAiB;AACzF,MAAI,CAAC,cACH;AAEF,0BAAwB,iBAAiB,OAAO,KAAK,OAAiB;AACtE,SAAO,MAAM,eAAe,UAAU,QAAQ,sBAAsB,CAAC,MAAM;;CAG7E,MAAM,wBAAiE;EACrE,MAAM,UAAU,MAAM,KAAK,YAAY;AAEvC,UADkB,MAAM,QAAQ,SAAS,QAAQ,IAAI,2BAA2B,CAAC,EAChE,KAAK,aAAa,QAAQ,yBAAyB,UAAU,SAAS,CAAC;;CAG1F,MAAM,mBAAmB,YAA0C;EACjE,MAAM,UAAU,M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AQ,6BAA6B,kBAAkC;AACrE,SAAO,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"server-BlG9qV5S.js","names":["config: CodemationConfig","consumerRoot: string","configSource?: string","workflowSources: ReadonlyArray<string>","env?: Readonly<NodeJS.ProcessEnv>","consumerConfigLoader: CodemationConsumerConfigLoader","appConfigFactory: AppConfigFactory","discoveredPackages: CodemationDiscoveredPluginPackage[]","resolvedPackages: CodemationResolvedPluginPackage[]","packageRoots: string[]"],"sources":["../src/presentation/http/CodemationServerGatewayFactory.ts","../src/presentation/server/AppConfigLoader.ts","../src/presentation/server/CodemationPluginDiscovery.ts"],"sourcesContent":["import { accessSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type { QueryBus } from \"../../application/bus/QueryBus\";\nimport type { WorkflowDto, WorkflowSummary } from \"../../application/contracts/WorkflowViewContracts\";\nimport { WorkflowDefinitionMapper } from \"../../application/mapping/WorkflowDefinitionMapper\";\nimport { GetWorkflowDetailQuery } from \"../../application/queries/GetWorkflowDetailQuery\";\nimport { GetWorkflowSummariesQuery } from \"../../application/queries/GetWorkflowSummariesQuery\";\nimport { ApplicationTokens } from \"../../applicationTokens\";\nimport { AppContainerFactory } from \"../../bootstrap/AppContainerFactory\";\nimport { AppContainerLifecycle } from \"../../bootstrap/AppContainerLifecycle\";\nimport { FrontendRuntime } from \"../../bootstrap/runtime/FrontendRuntime\";\nimport { AppConfigFactory } from \"../../bootstrap/runtime/AppConfigFactory\";\nimport type { CodemationConfig } from \"../config/CodemationConfig\";\nimport { CodemationConfigNormalizer } from \"../config/CodemationConfigNormalizer\";\nimport { CodemationHonoApiApp } from \"./hono/CodemationHonoApiAppFactory\";\n\ntype ServerGatewayContext = Readonly<{\n container: import(\"@codemation/core\").Container;\n httpApi: CodemationHonoApiApp;\n queryBus: QueryBus;\n workflowDefinitionMapper: WorkflowDefinitionMapper;\n}>;\n\nexport class CodemationServerGateway {\n private static readonly contextsByConfig = new WeakMap<object, Promise<ServerGatewayContext>>();\n\n constructor(\n private readonly config: CodemationConfig,\n private readonly consumerRoot: string,\n private readonly configSource?: string,\n private readonly workflowSources: ReadonlyArray<string> = [],\n private readonly env?: Readonly<NodeJS.ProcessEnv>,\n ) {}\n\n async dispatch(request: Request): Promise<Response> {\n return await (await this.getContext()).httpApi.fetch(request);\n }\n\n async prepare(): Promise<void> {\n await this.getContext();\n }\n\n async close(): Promise<void> {\n const cachedContext = CodemationServerGateway.contextsByConfig.get(this.config as object);\n if (!cachedContext) {\n return;\n }\n CodemationServerGateway.contextsByConfig.delete(this.config as object);\n await (await cachedContext).container.resolve(AppContainerLifecycle).stop();\n }\n\n async loadWorkflowSummaries(): Promise<ReadonlyArray<WorkflowSummary>> {\n const context = await this.getContext();\n const workflows = await context.queryBus.execute(new GetWorkflowSummariesQuery());\n return workflows.map((workflow) => context.workflowDefinitionMapper.toSummary(workflow));\n }\n\n async loadWorkflowDetail(workflowId: string): Promise<WorkflowDto> {\n const context = await this.getContext();\n const workflow = await context.queryBus.execute(new GetWorkflowDetailQuery(workflowId));\n if (!workflow) {\n throw new Error(`Unknown workflowId: ${workflowId}`);\n }\n return await context.workflowDefinitionMapper.map(workflow);\n }\n\n private getContext(): Promise<ServerGatewayContext> {\n const cachedContext = CodemationServerGateway.contextsByConfig.get(this.config as object);\n if (cachedContext) {\n return cachedContext;\n }\n const nextContext = this.createContext();\n CodemationServerGateway.contextsByConfig.set(this.config as object, nextContext);\n return nextContext;\n }\n\n private async createContext(): Promise<ServerGatewayContext> {\n const repoRoot = this.detectWorkspaceRoot(this.consumerRoot);\n // This gateway is the config/env boundary that materializes AppConfig from raw inputs.\n // eslint-disable-next-line no-restricted-properties\n const env = this.env ?? process.env;\n const appConfig = new AppConfigFactory().create({\n repoRoot,\n consumerRoot: this.consumerRoot,\n env,\n config: new CodemationConfigNormalizer().normalize(this.config),\n workflowSources: this.resolveWorkflowSources(),\n });\n const container = await new AppContainerFactory().create({\n appConfig,\n sharedWorkflowWebsocketServer: null,\n });\n await container.resolve(FrontendRuntime).start();\n return {\n container,\n httpApi: container.resolve(CodemationHonoApiApp),\n queryBus: container.resolve(ApplicationTokens.QueryBus),\n workflowDefinitionMapper: container.resolve(WorkflowDefinitionMapper),\n };\n }\n\n private resolveWorkflowSources(): ReadonlyArray<string> {\n if (this.workflowSources.length > 0) {\n return [...this.workflowSources];\n }\n if (!this.configSource || !this.config.workflows || this.config.workflows.length === 0) {\n return [];\n }\n return [this.configSource];\n }\n private detectWorkspaceRoot(startDirectory: string): string {\n let currentDirectory = path.resolve(startDirectory);\n while (true) {\n try {\n accessSync(path.resolve(currentDirectory, \"pnpm-workspace.yaml\"));\n return currentDirectory;\n } catch {\n const parentDirectory = path.dirname(currentDirectory);\n if (parentDirectory === currentDirectory) {\n return startDirectory;\n }\n currentDirectory = parentDirectory;\n }\n }\n }\n}\n","import type { AppConfig } from \"../config/AppConfig\";\nimport { CodemationConsumerConfigLoader } from \"./CodemationConsumerConfigLoader\";\nimport { AppConfigFactory } from \"../../bootstrap/runtime/AppConfigFactory\";\n\nexport type AppConfigLoadResult = Readonly<{\n appConfig: AppConfig;\n bootstrapSource: string | null;\n}>;\n\nexport class AppConfigLoader {\n constructor(\n private readonly consumerConfigLoader: CodemationConsumerConfigLoader = new CodemationConsumerConfigLoader(),\n private readonly appConfigFactory: AppConfigFactory = new AppConfigFactory(),\n ) {}\n\n async load(\n args: Readonly<{\n consumerRoot: string;\n repoRoot: string;\n env: NodeJS.ProcessEnv;\n configPathOverride?: string;\n }>,\n ): Promise<AppConfigLoadResult> {\n const resolution = await this.consumerConfigLoader.load({\n consumerRoot: args.consumerRoot,\n configPathOverride: args.configPathOverride,\n });\n return {\n appConfig: this.appConfigFactory.create({\n repoRoot: args.repoRoot,\n consumerRoot: args.consumerRoot,\n env: args.env,\n config: resolution.config,\n workflowSources: resolution.workflowSources,\n }),\n bootstrapSource: resolution.bootstrapSource,\n };\n }\n}\n","import type { CodemationPackageManifest } from \"../config/CodemationPackageManifest\";\nimport { CodemationPluginPackageMetadata, type CodemationPlugin } from \"../config/CodemationPlugin\";\nimport { readFile, readdir } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nexport type CodemationDiscoveredPluginPackage = Readonly<{\n packageName: string;\n packageRoot: string;\n pluginEntry: string;\n developmentEntry?: string;\n}>;\n\nexport type CodemationResolvedPluginPackage = Readonly<\n CodemationDiscoveredPluginPackage & {\n plugin: CodemationPlugin;\n }\n>;\n\ntype PackageJsonShape = Readonly<{\n codemation?: CodemationPackageManifest;\n name?: string;\n exports?: Readonly<Record<string, unknown>>;\n}>;\n\nexport class CodemationPluginDiscovery {\n private readonly pluginPackageMetadata = new CodemationPluginPackageMetadata();\n\n async discover(consumerRoot: string): Promise<ReadonlyArray<CodemationDiscoveredPluginPackage>> {\n const nodeModulesRoot = path.resolve(consumerRoot, \"node_modules\");\n const packageRoots = await this.collectPackageRoots(nodeModulesRoot);\n const discoveredPackages: CodemationDiscoveredPluginPackage[] = [];\n for (const packageRoot of packageRoots) {\n const packageJson = await this.readPackageJson(path.resolve(packageRoot, \"package.json\"));\n const pluginManifest = packageJson.codemation?.plugin;\n if (!packageJson.name || typeof pluginManifest !== \"string\" || pluginManifest.trim().length === 0) {\n continue;\n }\n discoveredPackages.push({\n packageName: packageJson.name,\n packageRoot,\n pluginEntry: pluginManifest,\n developmentEntry: await this.resolveDevelopmentPluginEntry(packageRoot),\n });\n }\n return discoveredPackages.sort((left, right) => left.packageName.localeCompare(right.packageName));\n }\n\n async resolvePlugins(consumerRoot: string): Promise<ReadonlyArray<CodemationResolvedPluginPackage>> {\n const discoveredPackages = await this.discover(consumerRoot);\n return await this.resolveDiscoveredPackages(discoveredPackages);\n }\n\n async resolveDiscoveredPackages(\n discoveredPackages: ReadonlyArray<CodemationDiscoveredPluginPackage>,\n ): Promise<ReadonlyArray<CodemationResolvedPluginPackage>> {\n const resolvedPackages: CodemationResolvedPluginPackage[] = [];\n for (const discoveredPackage of discoveredPackages) {\n resolvedPackages.push({\n ...discoveredPackage,\n plugin: await this.loadPlugin(discoveredPackage),\n });\n }\n return resolvedPackages;\n }\n\n private async collectPackageRoots(nodeModulesRoot: string): Promise<ReadonlyArray<string>> {\n try {\n const entries = await readdir(nodeModulesRoot, { withFileTypes: true });\n const packageRoots: string[] = [];\n for (const entry of entries) {\n if (!entry.isDirectory() && !entry.isSymbolicLink()) {\n continue;\n }\n if (entry.name.startsWith(\"@\")) {\n const scopedEntries = await readdir(path.resolve(nodeModulesRoot, entry.name), { withFileTypes: true });\n for (const scopedEntry of scopedEntries) {\n if (scopedEntry.isDirectory() || scopedEntry.isSymbolicLink()) {\n packageRoots.push(path.resolve(nodeModulesRoot, entry.name, scopedEntry.name));\n }\n }\n continue;\n }\n packageRoots.push(path.resolve(nodeModulesRoot, entry.name));\n }\n return packageRoots;\n } catch {\n return [];\n }\n }\n\n private async readPackageJson(packageJsonPath: string): Promise<PackageJsonShape> {\n try {\n const rawPackageJson = await readFile(packageJsonPath, \"utf8\");\n return JSON.parse(rawPackageJson) as PackageJsonShape;\n } catch {\n return {};\n }\n }\n\n private async loadPlugin(discoveredPackage: CodemationDiscoveredPluginPackage): Promise<CodemationPlugin> {\n const pluginModulePath = path.resolve(discoveredPackage.packageRoot, this.resolvePluginEntry(discoveredPackage));\n const importedModule = (await import(\n /* webpackIgnore: true */ this.resolvePluginModuleSpecifier(pluginModulePath)\n )) as Record<string, unknown>;\n const exportedValue = importedModule.default;\n const plugin = this.resolvePluginValue(exportedValue);\n if (!plugin) {\n throw new Error(`Plugin package \"${discoveredPackage.packageName}\" did not default-export a Codemation plugin.`);\n }\n return this.pluginPackageMetadata.attachPackageName(plugin, discoveredPackage.packageName);\n }\n\n private resolvePluginValue(value: unknown): CodemationPlugin | null {\n if (this.isPluginConfig(value)) {\n return value;\n }\n return null;\n }\n\n private isPluginConfig(value: unknown): value is CodemationPlugin {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return false;\n }\n const pluginValue = value as {\n credentialTypes?: unknown;\n mcpServers?: unknown;\n register?: unknown;\n sandbox?: unknown;\n };\n if (pluginValue.register !== undefined && typeof pluginValue.register !== \"function\") {\n return false;\n }\n if (pluginValue.credentialTypes !== undefined && !Array.isArray(pluginValue.credentialTypes)) {\n return false;\n }\n if (pluginValue.mcpServers !== undefined && !Array.isArray(pluginValue.mcpServers)) {\n return false;\n }\n return (\n pluginValue.register !== undefined ||\n pluginValue.credentialTypes !== undefined ||\n pluginValue.mcpServers !== undefined ||\n pluginValue.sandbox !== undefined ||\n Object.keys(pluginValue).length === 0\n );\n }\n\n private resolvePluginEntry(discoveredPackage: CodemationDiscoveredPluginPackage): string {\n const preferSource =\n process.env.CODEMATION_PREFER_PLUGIN_SOURCE_ENTRY === \"true\" &&\n typeof discoveredPackage.developmentEntry === \"string\" &&\n discoveredPackage.developmentEntry.trim().length > 0;\n const selectedEntry = preferSource ? discoveredPackage.developmentEntry : discoveredPackage.pluginEntry;\n return selectedEntry;\n }\n\n private async resolveDevelopmentPluginEntry(packageRoot: string): Promise<string | undefined> {\n const candidates = [\n path.resolve(packageRoot, \"codemation.plugin.ts\"),\n path.resolve(packageRoot, \"codemation.plugin.js\"),\n path.resolve(packageRoot, \"src\", \"codemation.plugin.ts\"),\n path.resolve(packageRoot, \"src\", \"codemation.plugin.js\"),\n ];\n for (const candidate of candidates) {\n if (await this.exists(candidate)) {\n return path.relative(packageRoot, candidate);\n }\n }\n return undefined;\n }\n\n private async exists(filePath: string): Promise<boolean> {\n try {\n await readFile(filePath, \"utf8\");\n return true;\n } catch {\n return false;\n }\n }\n\n private resolvePluginModuleSpecifier(pluginModulePath: string): string {\n return pathToFileURL(pluginModulePath).href;\n }\n}\n"],"mappings":";;;;;;;;;;AAuBA,IAAa,0BAAb,MAAa,wBAAwB;CACnC,OAAwB,mCAAmB,IAAI,SAAgD;CAE/F,YACE,AAAiBA,QACjB,AAAiBC,cACjB,AAAiBC,cACjB,AAAiBC,kBAAyC,EAAE,EAC5D,AAAi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,YAAY,CAAC,WAAW;;CAIxC,AAAQ,mBAAmB,mBAA8D;AAMvF,SAJE,QAAQ,IAAI,0CAA0C,UACtD,OAAO,kBAAkB,qBAAqB,YAC9C,kBAAkB,iBAAiB,MAAM,CAAC,SAAS,IAChB,kBAAkB,mBAAmB,kBAAkB;;CAI9F,MAAc,8BAA8B,aAAkD;EAC5F,MAAM,aAAa;GACjB,KAAK,QAAQ,aAAa,uBAAuB;GACjD,KAAK,QAAQ,aAAa,uBAAuB;GACjD,KAAK,QAAQ,aAAa,OAAO,uBAAuB;GACxD,KAAK,QAAQ,aAAa,OAAO,uBAAuB;GACzD;AACD,OAAK,MAAM,aAAa,WACtB,KAAI,MAAM,KAAK,OAAO,UAAU,CAC9B,QAAO,KAAK,SAAS,aAAa,UAAU;;CAMlD,MAAc,OAAO,UAAoC;AACvD,MAAI;AACF,SAAM,SAAS,UAAU,OAAO;AAChC,UAAO;UACD;AACN,UAAO;;;CAIX,AAAQ,6BAA6B,kBAAkC;AACrE,SAAO,cAAc,iBAAiB,CAAC"}
package/dist/server.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import "./index-DilAYwnH.js";
2
- import "./ItemsInputNormalizer-_RwIfRIQ.js";
3
- import "./CodemationAppContext-CGFYVcSb.js";
1
+ import "./index-ChIfeWzk.js";
2
+ import "./ItemsInputNormalizer-CFkfNMLt.js";
3
+ import "./CodemationAppContext-K51b7oXe.js";
4
4
  import "./CodemationWhitelabelConfig-Ca2mCUeC.js";
5
- import { a as ApiPaths, i as CodemationFrontendAuthSnapshotJsonCodec, n as InternalAuthBootstrapJsonCodec, r as FrontendAppConfigJsonCodec, t as PublicFrontendBootstrapJsonCodec } from "./PublicFrontendBootstrapJsonCodec-CXG9Dxft.js";
5
+ import { a as ApiPaths, i as CodemationFrontendAuthSnapshotJsonCodec, n as InternalAuthBootstrapJsonCodec, r as FrontendAppConfigJsonCodec, t as PublicFrontendBootstrapJsonCodec } from "./PublicFrontendBootstrapJsonCodec-HNItQ7ol.js";
6
6
  import { n as InternalAuthBootstrap, r as FrontendAppConfig, t as PublicFrontendBootstrap } from "./PublicFrontendBootstrap-Cev3qK46.js";
7
- import "./CodemationConfigNormalizer-48f-T66P.js";
8
- import { i as CodemationConsumerAppResolver, n as CodemationConsumerConfigResolution, r as CodemationConsumerApp, t as CodemationConsumerConfigLoader } from "./CodemationConsumerConfigLoader-_PIYqwVx.js";
7
+ import "./CodemationConfigNormalizer-B4rDYC9h.js";
8
+ import { i as CodemationConsumerAppResolver, n as CodemationConsumerConfigResolution, r as CodemationConsumerApp, t as CodemationConsumerConfigLoader } from "./CodemationConsumerConfigLoader-Dt4jyLx6.js";
9
9
  import "./WorkflowViewContracts-B7aFQcIw.js";
10
- import { r as PrismaDatabaseClient } from "./AppConfigFactory-BT0y0LVC.js";
11
- import { a as ProcessRunOptions, i as CodemationFrontendAuthSnapshotFactory, n as InternalAuthBootstrapFactory, o as ProcessRunResult, r as FrontendAppConfigFactory, s as ProcessRunner, t as PublicFrontendBootstrapFactory } from "./PublicFrontendBootstrapFactory-Dv04tJ-6.js";
12
- import { n as CodemationPostgresPrismaClientFactory } from "./persistenceServer-B71RGvSj.js";
13
- import { a as CodemationResolvedPluginPackage, c as CodemationServerGateway, i as CodemationPluginDiscovery, l as ExecaProcessRunner, n as WorkflowModulePathFinder, o as AppConfigLoadResult, r as CodemationDiscoveredPluginPackage, s as AppConfigLoader, t as WorkflowDiscoveryPathSegmentsComputer } from "./server-09PKasWR.js";
10
+ import { n as PrismaDatabaseClient } from "./AppConfigFactory-DncmwCD1.js";
11
+ import { a as ProcessRunOptions, i as CodemationFrontendAuthSnapshotFactory, n as InternalAuthBootstrapFactory, o as ProcessRunResult, r as FrontendAppConfigFactory, s as ProcessRunner, t as PublicFrontendBootstrapFactory } from "./PublicFrontendBootstrapFactory-ClEjZP74.js";
12
+ import { t as CodemationPostgresPrismaClientFactory } from "./CodemationPostgresPrismaClientFactory-CTNTPnDr.js";
13
+ import { a as CodemationResolvedPluginPackage, c as CodemationServerGateway, i as CodemationPluginDiscovery, l as ExecaProcessRunner, n as WorkflowModulePathFinder, o as AppConfigLoadResult, r as CodemationDiscoveredPluginPackage, s as AppConfigLoader, t as WorkflowDiscoveryPathSegmentsComputer } from "./server-B5trn7y4.js";
14
14
  export { ApiPaths, AppConfigLoadResult, AppConfigLoader, CodemationConsumerApp, CodemationConsumerAppResolver, CodemationConsumerConfigLoader, CodemationConsumerConfigResolution, CodemationDiscoveredPluginPackage, CodemationFrontendAuthSnapshotFactory, CodemationFrontendAuthSnapshotJsonCodec, CodemationPluginDiscovery, CodemationPostgresPrismaClientFactory, CodemationResolvedPluginPackage, CodemationServerGateway, ExecaProcessRunner, FrontendAppConfig, FrontendAppConfigFactory, FrontendAppConfigJsonCodec, InternalAuthBootstrap, InternalAuthBootstrapFactory, InternalAuthBootstrapJsonCodec, PrismaDatabaseClient as PrismaClient, ProcessRunOptions, ProcessRunResult, ProcessRunner, PublicFrontendBootstrap, PublicFrontendBootstrapFactory, PublicFrontendBootstrapJsonCodec, WorkflowDiscoveryPathSegmentsComputer, WorkflowModulePathFinder };
package/dist/server.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import "./LogLevelPolicyFactory-DCUzIN6G.js";
2
- import { t as ApiPaths } from "./ApiPaths-Dv1dcHu_.js";
2
+ import { t as ApiPaths } from "./ApiPaths-DCvrlIjg.js";
3
3
  import { i as CodemationFrontendAuthSnapshotJsonCodec, n as InternalAuthBootstrapJsonCodec, r as FrontendAppConfigJsonCodec, t as PublicFrontendBootstrapJsonCodec } from "./PublicFrontendBootstrapJsonCodec-CegIF_ne.js";
4
4
  import { i as CodemationConsumerAppResolver, n as WorkflowDiscoveryPathSegmentsComputer, r as WorkflowModulePathFinder, t as CodemationConsumerConfigLoader } from "./CodemationConsumerConfigLoader-By-6tuGc.js";
5
5
  import "./ServerLoggerFactory-Ckk52S3w.js";
6
6
  import "./decorateParam-BWxkAUSj.js";
7
7
  import "./decorate-CXWmflG_.js";
8
- import "./CredentialServices-Dk8yypeL.js";
8
+ import "./CredentialServices-Bios0dM8.js";
9
9
  import "./CodemationTsyringeTypeInfoRegistrar-Bj6FJYFz.js";
10
- import { D as FrontendAppConfigFactory, E as InternalAuthBootstrapFactory, O as CodemationFrontendAuthSnapshotFactory, T as PublicFrontendBootstrapFactory, g as ExecaProcessRunner } from "./AppContainerFactory-DRTjG7nG.js";
11
- import "./WorkflowPolicyUiPresentationFactory-Bb-ae_Zh.js";
12
- import "./InternalPingRegistrar-DY3kSfxP.js";
13
- import "./AppConfigFactory-Cx4qQvRk.js";
14
- import { t as CodemationPostgresPrismaClientFactory } from "./persistenceServer-C-hH4z6l.js";
15
- import { n as AppConfigLoader, r as CodemationServerGateway, t as CodemationPluginDiscovery } from "./server-vtRCPgRJ.js";
10
+ import { D as FrontendAppConfigFactory, E as InternalAuthBootstrapFactory, O as CodemationFrontendAuthSnapshotFactory, T as PublicFrontendBootstrapFactory, g as ExecaProcessRunner } from "./AppContainerFactory-jpYXGZGe.js";
11
+ import "./InternalPingRegistrar-BavAAnvk.js";
12
+ import "./WorkflowPolicyUiPresentationFactory-DfvD2VHk.js";
13
+ import "./AppConfigFactory-D4LL1aOR.js";
14
+ import { t as CodemationPostgresPrismaClientFactory } from "./CodemationPostgresPrismaClientFactory-C7156Fe-.js";
15
+ import { n as AppConfigLoader, r as CodemationServerGateway, t as CodemationPluginDiscovery } from "./server-BlG9qV5S.js";
16
16
 
17
17
  export { ApiPaths, AppConfigLoader, CodemationConsumerAppResolver, CodemationConsumerConfigLoader, CodemationFrontendAuthSnapshotFactory, CodemationFrontendAuthSnapshotJsonCodec, CodemationPluginDiscovery, CodemationPostgresPrismaClientFactory, CodemationServerGateway, ExecaProcessRunner, FrontendAppConfigFactory, FrontendAppConfigJsonCodec, InternalAuthBootstrapFactory, InternalAuthBootstrapJsonCodec, PublicFrontendBootstrapFactory, PublicFrontendBootstrapJsonCodec, WorkflowDiscoveryPathSegmentsComputer, WorkflowModulePathFinder };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemation/host",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -93,9 +93,12 @@
93
93
  "@prisma/client": "^7.0.0",
94
94
  "@prisma/client-runtime-utils": "^7.5.0",
95
95
  "ai": "^6.0.168",
96
+ "ajv": "^8.20.0",
96
97
  "bcryptjs": "^3.0.3",
97
98
  "better-auth": "^1.5.6",
98
99
  "bullmq": "^5.58.3",
100
+ "dotenv": "^17.3.1",
101
+ "execa": "^9.6.1",
99
102
  "hono": "^4.12.8",
100
103
  "jose": "^6.2.2",
101
104
  "pg": "^8.16.3",
@@ -103,13 +106,11 @@
103
106
  "reflect-metadata": "^0.2.2",
104
107
  "sanitize-filename": "^1.6.4",
105
108
  "serialize-javascript": "^7.0.4",
106
- "dotenv": "^17.3.1",
107
- "execa": "^9.6.1",
108
109
  "tsx": "^4.21.0",
109
110
  "ws": "^8.19.0",
110
- "@codemation/core-nodes": "0.8.1",
111
- "@codemation/eventbus-redis": "0.0.39",
112
- "@codemation/core": "0.11.1",
111
+ "@codemation/core": "0.12.0",
112
+ "@codemation/core-nodes": "0.9.0",
113
+ "@codemation/eventbus-redis": "0.0.40",
113
114
  "@codemation/managed-auth": "0.1.0"
114
115
  },
115
116
  "devDependencies": {
@@ -152,13 +153,13 @@
152
153
  "vitest": "^4.0.18",
153
154
  "zod": "^4.3.6",
154
155
  "zxcvbn": "^4.4.2",
155
- "@codemation/core-nodes-gmail": "0.3.1"
156
+ "@codemation/core-nodes-gmail": "0.3.2"
156
157
  },
157
158
  "scripts": {
158
159
  "changeset:verify": "pnpm --workspace-root run changeset:verify",
159
160
  "prisma:generate": "node ./scripts/generate-prisma-clients.mjs && node ./scripts/ensure-prisma-runtime-sourcemaps.mjs",
160
- "build": "tsdown src/index.ts src/authoring.ts src/client.ts src/credentials.ts src/consumer.ts src/dto.ts src/mapping.ts src/nextServer.ts src/server.ts src/devServerSidecar.ts src/persistenceServer.ts src/pairing.ts --out-dir dist --sourcemap",
161
- "dev": "tsdown src/index.ts src/authoring.ts src/client.ts src/credentials.ts src/consumer.ts src/dto.ts src/mapping.ts src/nextServer.ts src/server.ts src/devServerSidecar.ts src/persistenceServer.ts src/pairing.ts --out-dir dist --sourcemap --watch",
161
+ "build": "tsdown src/index.ts src/authoring.ts src/client.ts src/credentials.ts src/consumer.ts src/dto.ts src/mapping.ts src/nextServer.ts src/server.ts src/devServerSidecar.ts src/persistenceServer.ts src/pairing.ts src/infrastructure/persistence/PrismaMigrationOperations.ts --out-dir dist --sourcemap",
162
+ "dev": "tsdown src/index.ts src/authoring.ts src/client.ts src/credentials.ts src/consumer.ts src/dto.ts src/mapping.ts src/nextServer.ts src/server.ts src/devServerSidecar.ts src/persistenceServer.ts src/pairing.ts src/infrastructure/persistence/PrismaMigrationOperations.ts --out-dir dist --sourcemap --watch",
162
163
  "typecheck": "tsc -p tsconfig.json --noEmit",
163
164
  "lint": "eslint .",
164
165
  "test": "pnpm -w exec concurrently -m 5 -c auto -n unit,integration,ui,browser,e2e \"pnpm run test:unit\" \"pnpm run test:integration\" \"pnpm run test:ui\" \"pnpm run test:browser\" \"pnpm run test:e2e\"",
@@ -55,12 +55,18 @@ export default defineConfig({
55
55
  /** Align with app URL and AUTH_URL so Auth.js cookies are not split across localhost vs 127.0.0.1. */
56
56
  baseURL: baseUrl,
57
57
  trace: "retain-on-failure",
58
- video: "retain-on-failure",
58
+ // Video is disabled: it requires Playwright's ffmpeg binary, and every
59
+ // cdn.playwright.dev download hangs on CI (delivers bytes then never closes the
60
+ // stream). trace + screenshot already cover on-failure debugging without ffmpeg.
61
+ video: "off",
59
62
  },
60
63
  projects: [
61
64
  {
62
65
  name: "chromium",
63
- use: { ...devices["Desktop Chrome"] },
66
+ // Use the runner's preinstalled Google Chrome (channel) instead of Playwright's
67
+ // bundled chromium: cdn.playwright.dev deterministically hangs after the binary
68
+ // download on CI, and the system Chrome is the same engine/version.
69
+ use: { ...devices["Desktop Chrome"], channel: "chrome" },
64
70
  },
65
71
  ],
66
72
  webServer: {
@@ -34,13 +34,19 @@ export default defineConfig({
34
34
  ],
35
35
  use: {
36
36
  trace: "retain-on-failure",
37
- video: "retain-on-failure",
37
+ // Video is disabled: it requires Playwright's ffmpeg binary, and every
38
+ // cdn.playwright.dev download hangs on CI (delivers bytes then never closes the
39
+ // stream). trace + screenshot already cover on-failure debugging without ffmpeg.
40
+ video: "off",
38
41
  screenshot: "only-on-failure",
39
42
  },
40
43
  projects: [
41
44
  {
42
45
  name: "chromium",
43
- use: { ...devices["Desktop Chrome"] },
46
+ // Use the runner's preinstalled Google Chrome (channel) instead of Playwright's
47
+ // bundled chromium: cdn.playwright.dev deterministically hangs after the binary
48
+ // download on CI, and the system Chrome is the same engine/version.
49
+ use: { ...devices["Desktop Chrome"], channel: "chrome" },
44
50
  },
45
51
  ],
46
52
  });
@@ -0,0 +1,18 @@
1
+ -- Migration: Credential material provider seam (credentials-vault sprint, story 01).
2
+ -- Adds the {material_source, material_ref} pointer on CredentialInstance.
3
+ -- See docs/design/credentials-oauth-unification.md "Material provider seam".
4
+ --
5
+ -- All existing rows are local-mode workspace rows; backfill the pointer to
6
+ -- {source: "local", ref: instance_id} so the bytes still resolve via the
7
+ -- existing PrismaCredentialStore tables (CredentialOAuth2Material /
8
+ -- CredentialSecretMaterial).
9
+
10
+ ALTER TABLE "CredentialInstance"
11
+ ADD COLUMN "material_source" TEXT NOT NULL DEFAULT 'local';
12
+
13
+ ALTER TABLE "CredentialInstance"
14
+ ADD COLUMN "material_ref" TEXT NOT NULL DEFAULT '';
15
+
16
+ UPDATE "CredentialInstance"
17
+ SET "material_ref" = "instance_id"
18
+ WHERE "material_ref" = '';
@@ -0,0 +1,32 @@
1
+ -- Create HumanTask table for HITL story 02: durable task record + signed resume token.
2
+ -- Indexed for efficient "pending tasks for workspace/workflow" queries (story 06, 09).
3
+
4
+ CREATE TABLE "human_task" (
5
+ "id" TEXT NOT NULL,
6
+ "run_id" TEXT NOT NULL,
7
+ "workflow_id" TEXT NOT NULL,
8
+ "workspace_id" TEXT,
9
+ "node_id" TEXT NOT NULL,
10
+ "activation_id" TEXT NOT NULL,
11
+ "item_index" INTEGER NOT NULL,
12
+ "status" TEXT NOT NULL,
13
+ "channel" TEXT NOT NULL,
14
+ "subject_json" TEXT NOT NULL,
15
+ "metadata_json" TEXT NOT NULL,
16
+ "decision_schema_json" TEXT NOT NULL,
17
+ "decision_schema_hash" TEXT NOT NULL,
18
+ "on_timeout" TEXT NOT NULL,
19
+ "delivery_ref_json" TEXT,
20
+ "decision_json" TEXT,
21
+ "decided_at" TIMESTAMP(3),
22
+ "decided_by_json" TEXT,
23
+ "resume_token_hash" TEXT NOT NULL,
24
+ "expires_at" TIMESTAMP(3) NOT NULL,
25
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
26
+
27
+ CONSTRAINT "human_task_pkey" PRIMARY KEY ("id")
28
+ );
29
+
30
+ CREATE INDEX "human_task_run_id_idx" ON "human_task"("run_id");
31
+ CREATE INDEX "human_task_workflow_id_status_idx" ON "human_task"("workflow_id", "status");
32
+ CREATE INDEX "human_task_workspace_id_status_expires_at_idx" ON "human_task"("workspace_id", "status", "expires_at");
@@ -0,0 +1,6 @@
1
+ -- Add dedicated hitl_state_json column to Run table.
2
+ -- Replaces the interim _hitl* key stash inside mutable_state_json (commit 63a6cfb3).
3
+ -- Old rows with _hitl* keys inside mutable_state_json are still handled by the
4
+ -- repository's legacy-fallback load path until re-saved with the new column.
5
+
6
+ ALTER TABLE "Run" ADD COLUMN "hitl_state_json" TEXT;
@@ -0,0 +1,12 @@
1
+ -- Migration: Durable HMAC nonce store for replay protection (T6 security fix).
2
+ -- Replaces the in-memory Map in IncomingHmacVerifier with a Prisma-backed store
3
+ -- so replay protection survives process restarts within the 300-second window.
4
+
5
+ CREATE TABLE "hmac_nonce" (
6
+ "nonce" TEXT NOT NULL,
7
+ "expires_at" TIMESTAMP(3) NOT NULL,
8
+
9
+ CONSTRAINT "hmac_nonce_pkey" PRIMARY KEY ("nonce")
10
+ );
11
+
12
+ CREATE INDEX "hmac_nonce_expires_at_idx" ON "hmac_nonce"("expires_at");
@@ -0,0 +1,13 @@
1
+ -- Migration: Credential material provider seam (credentials-vault sprint, story 01) - SQLite variant.
2
+ -- Adds the {material_source, material_ref} pointer on CredentialInstance.
3
+ -- See docs/design/credentials-oauth-unification.md "Material provider seam".
4
+
5
+ ALTER TABLE "CredentialInstance"
6
+ ADD COLUMN "material_source" TEXT NOT NULL DEFAULT 'local';
7
+
8
+ ALTER TABLE "CredentialInstance"
9
+ ADD COLUMN "material_ref" TEXT NOT NULL DEFAULT '';
10
+
11
+ UPDATE "CredentialInstance"
12
+ SET "material_ref" = "instance_id"
13
+ WHERE "material_ref" = '';
@@ -0,0 +1,30 @@
1
+ -- Create HumanTask table for HITL story 02 (SQLite variant).
2
+ -- Mirrors the PostgreSQL migration but uses TEXT for timestamp columns (SQLite has no native TIMESTAMP type).
3
+
4
+ CREATE TABLE "human_task" (
5
+ "id" TEXT NOT NULL PRIMARY KEY,
6
+ "run_id" TEXT NOT NULL,
7
+ "workflow_id" TEXT NOT NULL,
8
+ "workspace_id" TEXT,
9
+ "node_id" TEXT NOT NULL,
10
+ "activation_id" TEXT NOT NULL,
11
+ "item_index" INTEGER NOT NULL,
12
+ "status" TEXT NOT NULL,
13
+ "channel" TEXT NOT NULL,
14
+ "subject_json" TEXT NOT NULL,
15
+ "metadata_json" TEXT NOT NULL,
16
+ "decision_schema_json" TEXT NOT NULL,
17
+ "decision_schema_hash" TEXT NOT NULL,
18
+ "on_timeout" TEXT NOT NULL,
19
+ "delivery_ref_json" TEXT,
20
+ "decision_json" TEXT,
21
+ "decided_at" DATETIME,
22
+ "decided_by_json" TEXT,
23
+ "resume_token_hash" TEXT NOT NULL,
24
+ "expires_at" DATETIME NOT NULL,
25
+ "created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
26
+ );
27
+
28
+ CREATE INDEX "human_task_run_id_idx" ON "human_task"("run_id");
29
+ CREATE INDEX "human_task_workflow_id_status_idx" ON "human_task"("workflow_id", "status");
30
+ CREATE INDEX "human_task_workspace_id_status_expires_at_idx" ON "human_task"("workspace_id", "status", "expires_at");
@@ -0,0 +1,6 @@
1
+ -- Add dedicated hitl_state_json column to Run table (SQLite variant).
2
+ -- Replaces the interim _hitl* key stash inside mutable_state_json (commit 63a6cfb3).
3
+ -- Old rows with _hitl* keys inside mutable_state_json are still handled by the
4
+ -- repository's legacy-fallback load path until re-saved with the new column.
5
+
6
+ ALTER TABLE "Run" ADD COLUMN "hitl_state_json" TEXT;
@@ -0,0 +1,9 @@
1
+ -- Migration: Durable HMAC nonce store for replay protection (T6 security fix, SQLite variant).
2
+ -- Mirrors the PostgreSQL migration but uses TEXT for the timestamp column (SQLite has no native TIMESTAMP type).
3
+
4
+ CREATE TABLE "hmac_nonce" (
5
+ "nonce" TEXT NOT NULL PRIMARY KEY,
6
+ "expires_at" DATETIME NOT NULL
7
+ );
8
+
9
+ CREATE INDEX "hmac_nonce_expires_at_idx" ON "hmac_nonce"("expires_at");
@@ -22,6 +22,7 @@ model Run {
22
22
  policySnapshotJson String? @map("policy_snapshot_json")
23
23
  engineCountersJson String? @map("engine_counters_json")
24
24
  mutableStateJson String? @map("mutable_state_json")
25
+ hitlStateJson String? @map("hitl_state_json")
25
26
  outputsByNodeJson String @map("outputs_by_node_json")
26
27
  updatedAt String @map("updated_at")
27
28
  testSuiteRunId String? @map("test_suite_run_id")
@@ -344,6 +345,10 @@ model CredentialInstance {
344
345
  setupStatus String @map("setup_status")
345
346
  createdAt String @map("created_at")
346
347
  updatedAt String @map("updated_at")
348
+ // Material provider seam — see docs/design/credentials-oauth-unification.md.
349
+ // Pointer to where the bytes live (workspace DB vs control plane).
350
+ materialSource String @default("local") @map("material_source")
351
+ materialRef String @default("") @map("material_ref")
347
352
  }
348
353
 
349
354
  model CredentialSecretMaterial {
@@ -507,3 +512,46 @@ model WorkflowAuditLog {
507
512
  @@index([workflowId, occurredAt])
508
513
  @@map("workflow_audit_log")
509
514
  }
515
+
516
+ /// HMAC nonce store for replay protection (T6 security fix).
517
+ /// Nonces are persisted across process restarts so a replayed request within
518
+ /// the 300-second timestamp window is rejected even after a restart.
519
+ model HmacNonce {
520
+ nonce String @id @map("nonce")
521
+ expiresAt DateTime @map("expires_at")
522
+
523
+ @@index([expiresAt])
524
+ @@map("hmac_nonce")
525
+ }
526
+
527
+ model HumanTask {
528
+ id String @id @map("id")
529
+ runId String @map("run_id")
530
+ workflowId String @map("workflow_id")
531
+ workspaceId String? @map("workspace_id")
532
+ nodeId String @map("node_id")
533
+ activationId String @map("activation_id")
534
+ itemIndex Int @map("item_index")
535
+ /// pending | decided | timed_out | auto_accepted | cancelled
536
+ status String @map("status")
537
+ /// local | control-plane-inbox
538
+ channel String @map("channel")
539
+ subjectJson String @map("subject_json")
540
+ metadataJson String @map("metadata_json")
541
+ decisionSchemaJson String @map("decision_schema_json")
542
+ decisionSchemaHash String @map("decision_schema_hash")
543
+ /// halt | auto-accept
544
+ onTimeout String @map("on_timeout")
545
+ deliveryRefJson String? @map("delivery_ref_json")
546
+ decisionJson String? @map("decision_json")
547
+ decidedAt DateTime? @map("decided_at")
548
+ decidedByJson String? @map("decided_by_json")
549
+ resumeTokenHash String @map("resume_token_hash")
550
+ expiresAt DateTime @map("expires_at")
551
+ createdAt DateTime @default(now()) @map("created_at")
552
+
553
+ @@index([runId])
554
+ @@index([workflowId, status])
555
+ @@index([workspaceId, status, expiresAt])
556
+ @@map("human_task")
557
+ }
@@ -22,6 +22,7 @@ model Run {
22
22
  policySnapshotJson String? @map("policy_snapshot_json")
23
23
  engineCountersJson String? @map("engine_counters_json")
24
24
  mutableStateJson String? @map("mutable_state_json")
25
+ hitlStateJson String? @map("hitl_state_json")
25
26
  outputsByNodeJson String @map("outputs_by_node_json")
26
27
  updatedAt String @map("updated_at")
27
28
  testSuiteRunId String? @map("test_suite_run_id")
@@ -345,6 +346,10 @@ model CredentialInstance {
345
346
  setupStatus String @map("setup_status")
346
347
  createdAt String @map("created_at")
347
348
  updatedAt String @map("updated_at")
349
+ // Material provider seam — see docs/design/credentials-oauth-unification.md.
350
+ // Pointer to where the bytes live (workspace DB vs control plane).
351
+ materialSource String @default("local") @map("material_source")
352
+ materialRef String @default("") @map("material_ref")
348
353
  }
349
354
 
350
355
  model CredentialSecretMaterial {
@@ -507,3 +512,46 @@ model WorkflowAuditLog {
507
512
  @@index([workflowId, occurredAt])
508
513
  @@map("workflow_audit_log")
509
514
  }
515
+
516
+ /// HMAC nonce store for replay protection (T6 security fix).
517
+ /// Nonces are persisted across process restarts so a replayed request within
518
+ /// the 300-second timestamp window is rejected even after a restart.
519
+ model HmacNonce {
520
+ nonce String @id @map("nonce")
521
+ expiresAt DateTime @map("expires_at")
522
+
523
+ @@index([expiresAt])
524
+ @@map("hmac_nonce")
525
+ }
526
+
527
+ model HumanTask {
528
+ id String @id @map("id")
529
+ runId String @map("run_id")
530
+ workflowId String @map("workflow_id")
531
+ workspaceId String? @map("workspace_id")
532
+ nodeId String @map("node_id")
533
+ activationId String @map("activation_id")
534
+ itemIndex Int @map("item_index")
535
+ /// pending | decided | timed_out | auto_accepted | cancelled
536
+ status String @map("status")
537
+ /// local | control-plane-inbox
538
+ channel String @map("channel")
539
+ subjectJson String @map("subject_json")
540
+ metadataJson String @map("metadata_json")
541
+ decisionSchemaJson String @map("decision_schema_json")
542
+ decisionSchemaHash String @map("decision_schema_hash")
543
+ /// halt | auto-accept
544
+ onTimeout String @map("on_timeout")
545
+ deliveryRefJson String? @map("delivery_ref_json")
546
+ decisionJson String? @map("decision_json")
547
+ decidedAt DateTime? @map("decided_at")
548
+ decidedByJson String? @map("decided_by_json")
549
+ resumeTokenHash String @map("resume_token_hash")
550
+ expiresAt DateTime @map("expires_at")
551
+ createdAt DateTime @default(now()) @map("created_at")
552
+
553
+ @@index([runId])
554
+ @@index([workflowId, status])
555
+ @@index([workspaceId, status, expiresAt])
556
+ @@map("human_task")
557
+ }