@codemation/host 0.8.0 → 0.9.1

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 +59 -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-CHCXP2rn.js} +1735 -474
  8. package/dist/AppContainerFactory-CHCXP2rn.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-CNj_y0QO.js} +4 -4
  58. package/dist/{server-vtRCPgRJ.js.map → server-CNj_y0QO.js.map} +1 -1
  59. package/dist/server.d.ts +10 -10
  60. package/dist/server.js +8 -8
  61. package/package.json +11 -10
  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 +89 -0
  114. package/src/hitl/HitlTimeoutWorker.ts +143 -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
@@ -0,0 +1,54 @@
1
+ import { inject, injectable } from "@codemation/core";
2
+ import type { JsonValue } from "@codemation/core";
3
+ import { Hono } from "hono";
4
+ import { DecideHumanTaskCommandHandler } from "../../../../application/hitl/DecideHumanTaskCommandHandler";
5
+ import { HttpRequestJsonBodyReader } from "../../HttpRequestJsonBodyReader";
6
+ import { ServerHttpErrorResponseFactory } from "../../ServerHttpErrorResponseFactory";
7
+ import type { HonoApiRouteRegistrar } from "../HonoApiRouteRegistrar";
8
+ import { PairingConfigToken } from "../../../../pairing/PairingConfigToken";
9
+ import type { PairingConfig } from "../../../../pairing/pairing.types";
10
+
11
+ /**
12
+ * Session-authenticated endpoint: `POST /api/hitl/tasks/:taskId/decide`
13
+ *
14
+ * Registered ONLY in non-managed mode. Used by the local /dev/inbox UI.
15
+ *
16
+ * In managed mode (`PairingConfig !== null`) the route is intentionally NOT mounted —
17
+ * decisions must arrive via the HMAC-signed `POST /internal/hitl/tasks/:taskId/callback`
18
+ * receiver from the control plane. This prevents a compromised user session
19
+ * from deciding arbitrary pending tasks.
20
+ *
21
+ * The session middleware is already applied on the /api sub-app by CodemationHonoApiAppFactory.
22
+ */
23
+ @injectable()
24
+ export class HitlDecideHonoApiRouteRegistrar implements HonoApiRouteRegistrar {
25
+ constructor(
26
+ @inject(DecideHumanTaskCommandHandler) private readonly handler: DecideHumanTaskCommandHandler,
27
+ @inject(PairingConfigToken, { isOptional: true })
28
+ private readonly pairingConfig: PairingConfig | null = null,
29
+ ) {}
30
+
31
+ register(app: Hono): void {
32
+ if (this.pairingConfig !== null) {
33
+ // Managed mode — decisions only via HMAC callback. Do not mount the session-auth route.
34
+ return;
35
+ }
36
+ app.post("/hitl/tasks/:taskId/decide", async (c) => {
37
+ try {
38
+ const taskId = c.req.param("taskId");
39
+ const body = await HttpRequestJsonBodyReader.readJsonBody<{
40
+ decision: JsonValue;
41
+ decidedBy?: { actorId: string; displayName?: string };
42
+ }>(c.req.raw);
43
+ const result = await this.handler.decide({
44
+ taskId,
45
+ decision: body.decision,
46
+ decidedBy: body.decidedBy ?? { actorId: "session-user" },
47
+ });
48
+ return c.json(result);
49
+ } catch (error) {
50
+ return ServerHttpErrorResponseFactory.fromUnknown(error);
51
+ }
52
+ });
53
+ }
54
+ }
@@ -0,0 +1,33 @@
1
+ import { inject, injectable } from "@codemation/core";
2
+ import type { Hono } from "hono";
3
+ import { InternalHmacAuthMiddleware } from "../../../../pairing/InternalHmacAuthMiddleware";
4
+ import { HitlCallbackHandler } from "../../../../application/hitl/HitlCallbackHandler";
5
+ import type { InternalHonoApiRouteRegistrar } from "../InternalHonoApiRouteRegistrar";
6
+
7
+ /**
8
+ * Registers `POST /internal/hitl/tasks/:taskId/callback` — HMAC-verified endpoint
9
+ * that receives decision callbacks from the control plane and forwards them to
10
+ * `HitlCallbackHandler`.
11
+ *
12
+ * The HMAC middleware verifies the request is signed by the paired CP.
13
+ * `HitlCallbackHandler` additionally asserts the task's workspace matches the
14
+ * pairing config workspace.
15
+ */
16
+ @injectable()
17
+ export class HitlInternalCallbackHonoApiRouteRegistrar implements InternalHonoApiRouteRegistrar {
18
+ constructor(
19
+ @inject(InternalHmacAuthMiddleware) private readonly hmacMiddleware: InternalHmacAuthMiddleware,
20
+ @inject(HitlCallbackHandler) private readonly callbackHandler: HitlCallbackHandler,
21
+ ) {}
22
+
23
+ register(app: Hono): void {
24
+ app.post("/internal/hitl/tasks/:taskId/callback", this.hmacMiddleware.handle(), async (c) => {
25
+ const taskId = c.req.param("taskId");
26
+ const rawBody = c.get("body" as never) as string | undefined;
27
+ const body = rawBody ? JSON.parse(rawBody) : await c.req.json();
28
+
29
+ const result = await this.callbackHandler.handle(taskId, body);
30
+ return c.json(result.body, result.status);
31
+ });
32
+ }
33
+ }
@@ -0,0 +1,43 @@
1
+ import { inject, injectable } from "@codemation/core";
2
+ import type { JsonValue } from "@codemation/core";
3
+ import { Hono } from "hono";
4
+ import { DecideHumanTaskCommandHandler } from "../../../../application/hitl/DecideHumanTaskCommandHandler";
5
+ import { HttpRequestJsonBodyReader } from "../../HttpRequestJsonBodyReader";
6
+ import { ServerHttpErrorResponseFactory } from "../../ServerHttpErrorResponseFactory";
7
+ import type { HonoApiRouteRegistrar } from "../HonoApiRouteRegistrar";
8
+
9
+ /**
10
+ * Token-authenticated (unauthenticated session) endpoint:
11
+ * `POST /api/hitl/tasks/:taskId/resume?token=<signed>`
12
+ *
13
+ * This endpoint is declared as an anonymous route in `HonoHttpAnonymousRoutePolicyRegistry`
14
+ * so the session middleware is bypassed. The HMAC-signed token is the auth mechanism.
15
+ *
16
+ * Used by local inbox and future magic-link channels (Slack, email).
17
+ */
18
+ @injectable()
19
+ export class HitlResumeHonoApiRouteRegistrar implements HonoApiRouteRegistrar {
20
+ constructor(@inject(DecideHumanTaskCommandHandler) private readonly handler: DecideHumanTaskCommandHandler) {}
21
+
22
+ register(app: Hono): void {
23
+ app.post("/hitl/tasks/:taskId/resume", async (c) => {
24
+ try {
25
+ const taskId = c.req.param("taskId");
26
+ const token = c.req.query("token") ?? "";
27
+
28
+ // Validate the signed token (replaces session auth for this endpoint)
29
+ await this.handler.validateResumeToken({ taskId, token });
30
+
31
+ const body = await HttpRequestJsonBodyReader.readJsonBody<{ decision: JsonValue }>(c.req.raw);
32
+ const result = await this.handler.decide({
33
+ taskId,
34
+ decision: body.decision,
35
+ decidedBy: { actorId: "token-bearer" },
36
+ });
37
+ return c.json(result);
38
+ } catch (error) {
39
+ return ServerHttpErrorResponseFactory.fromUnknown(error);
40
+ }
41
+ });
42
+ }
43
+ }
@@ -16,6 +16,7 @@ import type {
16
16
  UpsertCredentialBindingRequest,
17
17
  } from "../../../application/contracts/CredentialContractsRegistry";
18
18
  import {
19
+ GetCredentialAppsQuery,
19
20
  GetCredentialFieldEnvStatusQuery,
20
21
  GetCredentialInstanceQuery,
21
22
  GetCredentialInstanceWithSecretsQuery,
@@ -66,6 +67,14 @@ export class CredentialHttpRouteHandler {
66
67
  }
67
68
  }
68
69
 
70
+ async getCredentialApps(): Promise<Response> {
71
+ try {
72
+ return Response.json(await this.queryBus.execute(new GetCredentialAppsQuery()));
73
+ } catch (error) {
74
+ return ServerHttpErrorResponseFactory.fromUnknown(error);
75
+ }
76
+ }
77
+
69
78
  async getCredentialInstance(request: Request, params: ServerHttpRouteParams): Promise<Response> {
70
79
  try {
71
80
  const withSecrets = new URL(request.url).searchParams.get("withSecrets") === "1";
@@ -87,7 +87,7 @@ export class OAuth2HttpRouteHandler {
87
87
  const stateToken = url.searchParams.get("state")?.trim();
88
88
  if (!code || !stateToken) {
89
89
  return new Response(
90
- this.createPopupHtml({ kind: "oauth2.error", message: "Missing code or state parameter." }),
90
+ this.createPopupHtml({ kind: "oauth2.error", message: "Missing code and state parameters." }),
91
91
  {
92
92
  status: 400,
93
93
  headers: { "content-type": "text/html; charset=utf-8" },
package/src/server.ts CHANGED
@@ -1,5 +1,10 @@
1
- export { CodemationPostgresPrismaClientFactory } from "./persistenceServer";
2
- export type { PrismaClient } from "./persistenceServer";
1
+ // Direct re-export from source files, NOT via the persistenceServer barrel: that
2
+ // barrel also re-exports PrismaMigrationDeployer, whose createRequire + dynamic
3
+ // require.resolve trips the Turbopack module tracer ("whole project traced
4
+ // unintentionally") when this server barrel is transitively reached from a
5
+ // Next.js Server Component such as the dev/inbox page.
6
+ export { CodemationPostgresPrismaClientFactory } from "./infrastructure/persistence/CodemationPostgresPrismaClientFactory";
7
+ export type { PrismaDatabaseClient as PrismaClient } from "./infrastructure/persistence/PrismaDatabaseClient";
3
8
  export { ExecaProcessRunner } from "./process/ExecaProcessRunner";
4
9
  export type { ProcessRunner, ProcessRunOptions, ProcessRunResult } from "./process/ProcessRunner.types";
5
10
  export { ApiPaths } from "./presentation/http/ApiPaths";
@@ -79,6 +79,15 @@ export class InternalWorkflowTestRunRegistrar implements InternalHonoApiRouteReg
79
79
  });
80
80
  }
81
81
 
82
+ if (runResult.status === "halted") {
83
+ return c.json({
84
+ ok: false,
85
+ runId: runResult.runId,
86
+ error: `Run halted: ${runResult.reason}`,
87
+ durationMs: Date.now() - startMs,
88
+ });
89
+ }
90
+
82
91
  // completed
83
92
  return c.json({
84
93
  ok: true,
package/tsconfig.json CHANGED
@@ -28,6 +28,7 @@
28
28
  "@codemation/host/dev-server-sidecar": ["./src/devServerSidecar.ts"],
29
29
  "@codemation/host/persistence": ["./src/persistenceServer.ts"],
30
30
  "@codemation/canvas": ["../canvas/src/index.ts"],
31
+ "@codemation/canvas-core": ["../canvas-core/src/index.ts"],
31
32
  "@codemation/next-host/src/*": ["../next-host/src/*"],
32
33
  "@/*": ["../next-host/src/*"]
33
34
  }