@codemation/host 0.0.5 → 0.0.7

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 (109) hide show
  1. package/README.md +3 -3
  2. package/dist/{PrismaMigrationDeployer-B7cHGrXP.js → AppConfigFactory-DWIz2hy-.js} +104 -58
  3. package/dist/AppConfigFactory-DWIz2hy-.js.map +1 -0
  4. package/dist/{client-Yh7-CQud.d.ts → AppConfigFactory-DmHOpg8O.d.ts} +52 -31
  5. package/dist/{CodemationFrontendBootstrapRequest-CNEk-C4D.js → AppContainerFactory-B5eRpvAa.js} +3269 -3374
  6. package/dist/AppContainerFactory-B5eRpvAa.js.map +1 -0
  7. package/dist/{CodemationWhitelabelConfig-DgbjgtrR.d.ts → CodemationAuthConfig-Bh2cCNCI.d.ts} +32 -2
  8. package/dist/{CodemationConfig-XCkSV2dj.d.ts → CodemationConfig-D2ULNkec.d.ts} +53 -49
  9. package/dist/CodemationConfigNormalizer-CBLxXaRV.d.ts +9 -0
  10. package/dist/{CodemationConsumerConfigLoader-scS_RQMy.js → CodemationConsumerConfigLoader-BBzAr6L_.js} +128 -3
  11. package/dist/CodemationConsumerConfigLoader-BBzAr6L_.js.map +1 -0
  12. package/dist/{CodemationConsumerConfigLoader-Dmm2TzAA.d.ts → CodemationConsumerConfigLoader-BLvzcfb7.d.ts} +4 -4
  13. package/dist/CodemationPluginListMerger-B0-e4CJ6.d.ts +391 -0
  14. package/dist/{CodemationPluginListMerger-BNmaoXQL.js → CodemationPluginListMerger-DrVOw9KP.js} +18 -10
  15. package/dist/CodemationPluginListMerger-DrVOw9KP.js.map +1 -0
  16. package/dist/{CredentialServices-DpDpm8mL.d.ts → CredentialServices-BeuMtqYA.d.ts} +3 -3
  17. package/dist/{CredentialServices-BKBGe7l3.js → CredentialServices-DNb3CZwW.js} +3 -3
  18. package/dist/CredentialServices-DNb3CZwW.js.map +1 -0
  19. package/dist/FrontendAppConfig-D50wjj_n.d.ts +27 -0
  20. package/dist/{WorkflowViewContracts-DCLpTn25.d.ts → FrontendAppConfigFactory-Bj-DZNlt.d.ts} +29 -2
  21. package/dist/FrontendAppConfigJsonCodec-1_L7H_Qo.d.ts +20 -0
  22. package/dist/FrontendAppConfigJsonCodec-nOCQI0ag.js +84 -0
  23. package/dist/FrontendAppConfigJsonCodec-nOCQI0ag.js.map +1 -0
  24. package/dist/{LogLevelPolicy-4cq9z0TI.d.ts → LogLevelPolicy-BS_NlAOg.d.ts} +2 -2
  25. package/dist/{ServerLoggerFactory-BRHxIDS7.js → ServerLoggerFactory-BltIIDfQ.js} +4 -129
  26. package/dist/ServerLoggerFactory-BltIIDfQ.js.map +1 -0
  27. package/dist/client.d.ts +5 -3
  28. package/dist/client.js +2 -1
  29. package/dist/client.js.map +1 -1
  30. package/dist/consumer.d.ts +5 -4
  31. package/dist/consumer.js +4 -4
  32. package/dist/credentials.d.ts +4 -4
  33. package/dist/credentials.js +3 -3
  34. package/dist/devServerSidecar.d.ts +1 -1
  35. package/dist/{index-Bs4F1IsC.d.ts → index-CkiptHb-.d.ts} +19 -20
  36. package/dist/index.d.ts +14 -19
  37. package/dist/index.js +12 -11
  38. package/dist/nextServer.d.ts +244 -9
  39. package/dist/nextServer.js +8 -8
  40. package/dist/persistenceServer-CaehMh3M.d.ts +9 -0
  41. package/dist/{persistenceServer-8tcM2S48.js → persistenceServer-DVeWUbc3.js} +2 -2
  42. package/dist/{persistenceServer-8tcM2S48.js.map → persistenceServer-DVeWUbc3.js.map} +1 -1
  43. package/dist/persistenceServer.d.ts +7 -6
  44. package/dist/persistenceServer.js +4 -4
  45. package/dist/{server-Dd65rNm6.js → server-C65z_kqm.js} +47 -17
  46. package/dist/server-C65z_kqm.js.map +1 -0
  47. package/dist/{server-BBdsATju.d.ts → server-Dyo8qh4k.d.ts} +23 -4
  48. package/dist/server.d.ts +12 -9
  49. package/dist/server.js +11 -10
  50. package/package.json +6 -6
  51. package/src/application/commands/WorkflowCommandHandlers.ts +9 -0
  52. package/src/application/dev/BootRuntimeSnapshotHolder.ts +2 -2
  53. package/src/application/dev/BootRuntimeSummary.types.ts +2 -2
  54. package/src/application/queries/WorkflowQueryHandlers.ts +7 -0
  55. package/src/applicationTokens.ts +1 -1
  56. package/src/bootstrap/AppContainerFactory.ts +584 -0
  57. package/src/bootstrap/{PreparedCodemationRuntime.ts → AppContainerLifecycle.ts} +3 -8
  58. package/src/bootstrap/runtime/AppConfigFactory.ts +155 -30
  59. package/src/bootstrap/runtime/DatabaseMigrations.ts +18 -0
  60. package/src/bootstrap/runtime/FrontendRuntime.ts +44 -0
  61. package/src/bootstrap/runtime/WorkerRuntime.ts +55 -0
  62. package/src/client.ts +7 -0
  63. package/src/index.ts +15 -5
  64. package/src/infrastructure/persistence/PrismaMigrationDeployer.ts +2 -2
  65. package/src/infrastructure/persistence/SchedulerPersistenceCompatibilityValidator.ts +2 -2
  66. package/src/infrastructure/scheduler/WorkerRuntimeScheduler.ts +16 -0
  67. package/src/infrastructure/scheduler/bullmq/BullmqNodeExecutionScheduler.ts +47 -0
  68. package/src/infrastructure/scheduler/bullmq/BullmqScheduler.ts +33 -0
  69. package/src/infrastructure/scheduler/bullmq/BullmqWorker.ts +48 -0
  70. package/src/infrastructure/scheduler/bullmq/RedisConnectionOptionsFactory.ts +48 -0
  71. package/src/nextServer.ts +12 -3
  72. package/src/persistenceServer.ts +2 -2
  73. package/src/presentation/config/AppConfig.ts +25 -1
  74. package/src/presentation/frontend/CodemationFrontendAuthSnapshot.ts +14 -0
  75. package/src/presentation/frontend/CodemationFrontendAuthSnapshotFactory.ts +84 -0
  76. package/src/presentation/frontend/CodemationFrontendAuthSnapshotJsonCodec.ts +58 -0
  77. package/src/presentation/frontend/FrontendAppConfig.ts +10 -0
  78. package/src/presentation/frontend/FrontendAppConfigFactory.ts +26 -0
  79. package/src/presentation/frontend/FrontendAppConfigJsonCodec.ts +58 -0
  80. package/src/presentation/http/CodemationServerGatewayFactory.ts +22 -16
  81. package/src/presentation/server/AppConfigLoader.ts +39 -0
  82. package/src/presentation/server/CodemationConsumerAppResolver.ts +2 -2
  83. package/src/presentation/server/CodemationConsumerConfigLoader.ts +3 -2
  84. package/src/server.ts +7 -0
  85. package/vitest.shared.ts +0 -4
  86. package/dist/CodemationConsumerConfigLoader-scS_RQMy.js.map +0 -1
  87. package/dist/CodemationFrontendBootstrapRequest-CNEk-C4D.js.map +0 -1
  88. package/dist/CodemationPluginListMerger-BNmaoXQL.js.map +0 -1
  89. package/dist/CodemationPluginListMerger-BRYqEk0y.d.ts +0 -793
  90. package/dist/CredentialServices-BKBGe7l3.js.map +0 -1
  91. package/dist/PrismaMigrationDeployer-B7cHGrXP.js.map +0 -1
  92. package/dist/ServerLoggerFactory-BRHxIDS7.js.map +0 -1
  93. package/dist/persistenceServer-DPSj_-oU.d.ts +0 -37
  94. package/dist/server-Dd65rNm6.js.map +0 -1
  95. package/src/bootstrap/CodemationContainerFactory.ts +0 -310
  96. package/src/bootstrap/CodemationFrontendBootstrapRequest.ts +0 -16
  97. package/src/bootstrap/CodemationWorkerBootstrapRequest.ts +0 -19
  98. package/src/bootstrap/PreparedCodemationRuntimeFactory.ts +0 -308
  99. package/src/bootstrap/boot/CliRuntimeBootService.ts +0 -27
  100. package/src/bootstrap/boot/FrontendRuntimeBootService.ts +0 -86
  101. package/src/bootstrap/boot/WorkerRuntimeBootService.ts +0 -64
  102. package/src/bootstrap/runtime/ResolvedImplementationSelectionFactory.ts +0 -118
  103. package/src/codemationApplication.ts +0 -311
  104. package/src/infrastructure/credentials/FrameworkBuiltinCredentialTypesRegistrar.ts +0 -21
  105. package/src/infrastructure/persistence/DatabasePersistenceResolver.ts +0 -91
  106. package/src/infrastructure/runtime/WorkerRuntimeScheduler.ts +0 -35
  107. package/src/presentation/config/CodemationApplicationFacade.ts +0 -5
  108. /package/dist/{decorate-B-N_5S4p.js → decorate-B0PP651O.js} +0 -0
  109. /package/dist/{decorateParam-BTcc3KNk.js → decorateParam-DrsXNPuw.js} +0 -0
@@ -1,311 +0,0 @@
1
- import "reflect-metadata";
2
-
3
- import type { Container, WorkflowDefinition } from "@codemation/core";
4
- import { CoreTokens } from "@codemation/core";
5
- import type { BootRuntimeSummary } from "./application/dev/BootRuntimeSummary.types";
6
- import "./application/commands/CopyRunToWorkflowDebuggerCommandHandler";
7
- import "./application/commands/CredentialCommandHandlers";
8
- import "./application/commands/HandleWebhookInvocationCommandHandler";
9
- import "./application/commands/ReplayWorkflowNodeCommandHandler";
10
- import "./application/commands/ReplaceMutableRunWorkflowSnapshotCommandHandler";
11
- import "./application/commands/ReplaceWorkflowDebuggerOverlayCommandHandler";
12
- import "./application/commands/SetPinnedNodeInputCommandHandler";
13
- import "./application/commands/SetWorkflowActivationCommandHandler";
14
- import "./application/commands/StartWorkflowRunCommandHandler";
15
- import "./application/commands/UploadOverlayPinnedBinaryCommandHandler";
16
- import "./application/commands/UserAccountCommandHandlers";
17
- import "./application/queries/CredentialQueryHandlers";
18
- import "./application/queries/GetRunBinaryAttachmentQueryHandler";
19
- import "./application/queries/GetRunStateQueryHandler";
20
- import "./application/queries/GetWorkflowDebuggerOverlayQueryHandler";
21
- import "./application/queries/GetWorkflowDetailQueryHandler";
22
- import "./application/queries/GetWorkflowOverlayBinaryAttachmentQueryHandler";
23
- import "./application/queries/GetWorkflowSummariesQueryHandler";
24
- import "./application/queries/ListWorkflowRunsQueryHandler";
25
- import "./application/queries/UserAccountQueryHandlers";
26
- import "./application/binary/OverlayPinnedBinaryUploadService";
27
- import "./presentation/http/hono/registrars/BinaryHonoApiRouteRegistrar";
28
- import "./presentation/http/hono/registrars/CredentialHonoApiRouteRegistrar";
29
- import "./presentation/http/hono/registrars/DevHonoApiRouteRegistrar";
30
- import "./presentation/http/hono/registrars/OAuth2HonoApiRouteRegistrar";
31
- import "./presentation/http/hono/registrars/RunHonoApiRouteRegistrar";
32
- import "./presentation/http/hono/registrars/UserHonoApiRouteRegistrar";
33
- import "./presentation/http/hono/registrars/WebhookHonoApiRouteRegistrar";
34
- import "./presentation/http/hono/registrars/WhitelabelHonoApiRouteRegistrar";
35
- import "./presentation/http/hono/registrars/WorkflowHonoApiRouteRegistrar";
36
- import "./presentation/http/routeHandlers/BinaryHttpRouteHandlerFactory";
37
- import "./presentation/http/routeHandlers/CredentialHttpRouteHandler";
38
- import "./presentation/http/routeHandlers/OAuth2HttpRouteHandlerFactory";
39
- import "./presentation/http/routeHandlers/RunHttpRouteHandler";
40
- import "./presentation/http/routeHandlers/UserHttpRouteHandlerFactory";
41
- import "./presentation/http/routeHandlers/WebhookHttpRouteHandler";
42
- import "./presentation/http/routeHandlers/WorkflowHttpRouteHandler";
43
- import { logLevelPolicyFactory } from "./infrastructure/logging/LogLevelPolicyFactory";
44
- import { FrameworkBuiltinCredentialTypesRegistrar } from "./infrastructure/credentials/FrameworkBuiltinCredentialTypesRegistrar";
45
- import { OpenAiApiKeyCredentialHealthTester } from "./infrastructure/credentials/OpenAiApiKeyCredentialHealthTester";
46
- import { OpenAiApiKeyCredentialTypeFactory } from "./infrastructure/credentials/OpenAiApiKeyCredentialTypeFactory";
47
- import { CodemationPluginRegistrar } from "./infrastructure/config/CodemationPluginRegistrar";
48
- import type { CredentialType } from "./domain/credentials/CredentialServices";
49
- import { CredentialTypeRegistryImpl } from "./domain/credentials/CredentialServices";
50
- import type { CodemationAuthConfig } from "./presentation/config/CodemationAuthConfig";
51
- import type { CodemationApplicationRuntimeConfig, CodemationConfig } from "./presentation/config/CodemationConfig";
52
- import type { NormalizedCodemationConfig } from "./presentation/config/CodemationConfigNormalizer";
53
- import { CodemationConfigNormalizer } from "./presentation/config/CodemationConfigNormalizer";
54
- import type { CodemationPlugin } from "./presentation/config/CodemationPlugin";
55
- import type { CodemationWhitelabelConfig } from "./presentation/config/CodemationWhitelabelConfig";
56
- import { WorkflowWebsocketServer } from "./presentation/websocket/WorkflowWebsocketServer";
57
- import { ApplicationTokens } from "./applicationTokens";
58
- import { CodemationBootstrapRequest } from "./bootstrap/CodemationBootstrapRequest";
59
- import type { CodemationContainerRegistration } from "./bootstrap/CodemationContainerRegistration";
60
- import { CodemationFrontendBootstrapRequest } from "./bootstrap/CodemationFrontendBootstrapRequest";
61
- import { PreparedCodemationRuntime } from "./bootstrap/PreparedCodemationRuntime";
62
- import { PreparedCodemationRuntimeFactory } from "./bootstrap/PreparedCodemationRuntimeFactory";
63
- import { CodemationContainerFactory } from "./bootstrap/CodemationContainerFactory";
64
- import { CodemationWorkerBootstrapRequest } from "./bootstrap/CodemationWorkerBootstrapRequest";
65
- import { AppConfigFactory } from "./bootstrap/runtime/AppConfigFactory";
66
- import { CliRuntimeBootService } from "./bootstrap/boot/CliRuntimeBootService";
67
- import { FrontendRuntimeBootService } from "./bootstrap/boot/FrontendRuntimeBootService";
68
- import { WorkerRuntimeBootService } from "./bootstrap/boot/WorkerRuntimeBootService";
69
-
70
- type StopHandle = Readonly<{ stop: () => Promise<void> }>;
71
-
72
- export type CodemationStopHandle = StopHandle;
73
-
74
- export type CodemationApplicationConfig = CodemationConfig;
75
-
76
- export class CodemationApplication {
77
- private readonly pluginRegistrar: CodemationPluginRegistrar;
78
- private readonly containerFactory: CodemationContainerFactory;
79
- private readonly preparedRuntimeFactory: PreparedCodemationRuntimeFactory;
80
- private readonly configNormalizer: CodemationConfigNormalizer;
81
- private readonly appConfigFactory: AppConfigFactory;
82
- private readonly cliRuntimeBootService: CliRuntimeBootService;
83
- private readonly frontendRuntimeBootService: FrontendRuntimeBootService;
84
- private readonly workerRuntimeBootService: WorkerRuntimeBootService;
85
-
86
- private configuredContainer: Container | null = null;
87
- private preparedRuntime: PreparedCodemationRuntime | null = null;
88
- private workflows: WorkflowDefinition[] = [];
89
- private runtimeConfig: CodemationApplicationRuntimeConfig = {};
90
- private containerRegistrations: ReadonlyArray<CodemationContainerRegistration<unknown>> = [];
91
- private hasConfiguredCredentialSessionServiceRegistration = false;
92
- private plugins: ReadonlyArray<CodemationPlugin> = [];
93
- private sharedWorkflowWebsocketServer: WorkflowWebsocketServer | null = null;
94
- private applicationAuthConfig: CodemationAuthConfig | undefined;
95
- private whitelabelConfig: CodemationWhitelabelConfig = {};
96
- private frameworkBuiltinCredentialTypesRegistered = false;
97
- private credentialTypes: Array<CredentialType<any, any, unknown>> = [];
98
-
99
- constructor(
100
- pluginRegistrar: CodemationPluginRegistrar = new CodemationPluginRegistrar(),
101
- containerFactory: CodemationContainerFactory = new CodemationContainerFactory(),
102
- preparedRuntimeFactory: PreparedCodemationRuntimeFactory = new PreparedCodemationRuntimeFactory(),
103
- configNormalizer: CodemationConfigNormalizer = new CodemationConfigNormalizer(),
104
- appConfigFactory: AppConfigFactory = new AppConfigFactory(),
105
- cliRuntimeBootService: CliRuntimeBootService = new CliRuntimeBootService(),
106
- frontendRuntimeBootService: FrontendRuntimeBootService = new FrontendRuntimeBootService(),
107
- workerRuntimeBootService: WorkerRuntimeBootService = new WorkerRuntimeBootService(),
108
- ) {
109
- this.pluginRegistrar = pluginRegistrar;
110
- this.containerFactory = containerFactory;
111
- this.preparedRuntimeFactory = preparedRuntimeFactory;
112
- this.configNormalizer = configNormalizer;
113
- this.appConfigFactory = appConfigFactory;
114
- this.cliRuntimeBootService = cliRuntimeBootService;
115
- this.frontendRuntimeBootService = frontendRuntimeBootService;
116
- this.workerRuntimeBootService = workerRuntimeBootService;
117
- }
118
-
119
- useConfig(config: CodemationApplicationConfig): this {
120
- const normalizedConfig: NormalizedCodemationConfig = this.configNormalizer.normalize(config);
121
- logLevelPolicyFactory.create().applyCodemationLogConfig(normalizedConfig.log);
122
- if (normalizedConfig.workflows) {
123
- this.useWorkflows(normalizedConfig.workflows);
124
- }
125
- this.useContainerRegistrations(normalizedConfig.containerRegistrations);
126
- if (!this.frameworkBuiltinCredentialTypesRegistered) {
127
- new FrameworkBuiltinCredentialTypesRegistrar(
128
- new OpenAiApiKeyCredentialTypeFactory(new OpenAiApiKeyCredentialHealthTester(globalThis.fetch)),
129
- ).register(this, normalizedConfig);
130
- this.frameworkBuiltinCredentialTypesRegistered = true;
131
- }
132
- if (normalizedConfig.credentialTypes) {
133
- for (const credentialType of normalizedConfig.credentialTypes) {
134
- this.registerCredentialType(credentialType);
135
- }
136
- }
137
- if (normalizedConfig.plugins) {
138
- this.usePlugins(normalizedConfig.plugins);
139
- }
140
- if (normalizedConfig.runtime) {
141
- this.useRuntimeConfig(normalizedConfig.runtime);
142
- }
143
- if (normalizedConfig.auth !== undefined) {
144
- this.applicationAuthConfig = normalizedConfig.auth;
145
- }
146
- this.whitelabelConfig = normalizedConfig.whitelabel ?? {};
147
- return this;
148
- }
149
-
150
- useWorkflows(workflows: ReadonlyArray<WorkflowDefinition>): this {
151
- this.workflows = [...workflows];
152
- this.invalidatePreparedState();
153
- return this;
154
- }
155
-
156
- useRuntimeConfig(runtimeConfig: CodemationApplicationRuntimeConfig): this {
157
- this.runtimeConfig = {
158
- ...this.runtimeConfig,
159
- ...runtimeConfig,
160
- ...(runtimeConfig.engineExecutionLimits !== undefined
161
- ? {
162
- engineExecutionLimits: {
163
- ...this.runtimeConfig.engineExecutionLimits,
164
- ...runtimeConfig.engineExecutionLimits,
165
- },
166
- }
167
- : {}),
168
- };
169
- this.invalidatePreparedState();
170
- return this;
171
- }
172
-
173
- private useContainerRegistrations(registrations: ReadonlyArray<CodemationContainerRegistration<unknown>>): this {
174
- this.containerRegistrations = [...registrations];
175
- this.hasConfiguredCredentialSessionServiceRegistration = registrations.some(
176
- (entry) => entry.token === CoreTokens.CredentialSessionService,
177
- );
178
- this.invalidatePreparedState();
179
- return this;
180
- }
181
-
182
- usePlugins(plugins: ReadonlyArray<CodemationPlugin>): this {
183
- this.plugins = [...plugins];
184
- return this;
185
- }
186
-
187
- useSharedWorkflowWebsocketServer(workflowWebsocketServer: WorkflowWebsocketServer): this {
188
- this.sharedWorkflowWebsocketServer = workflowWebsocketServer;
189
- if (this.configuredContainer) {
190
- this.configuredContainer.registerInstance(WorkflowWebsocketServer, workflowWebsocketServer);
191
- this.configuredContainer.registerInstance(ApplicationTokens.WorkflowWebsocketPublisher, workflowWebsocketServer);
192
- }
193
- return this;
194
- }
195
-
196
- getRuntimeConfig(): CodemationApplicationRuntimeConfig {
197
- return { ...this.runtimeConfig };
198
- }
199
-
200
- getWorkflows(): ReadonlyArray<WorkflowDefinition> {
201
- return [...this.workflows];
202
- }
203
-
204
- getContainer(): Container {
205
- return this.ensureConfiguredContainer();
206
- }
207
-
208
- getBootRuntimeSummary(): BootRuntimeSummary | null {
209
- return this.preparedRuntime?.runtimeSummary ?? null;
210
- }
211
-
212
- registerCredentialType(type: CredentialType<any, any, unknown>): void {
213
- if (this.credentialTypes.some((entry) => entry.definition.typeId === type.definition.typeId)) {
214
- return;
215
- }
216
- this.credentialTypes.push(type);
217
- if (this.configuredContainer) {
218
- this.configuredContainer.resolve(CredentialTypeRegistryImpl).register(type);
219
- }
220
- }
221
-
222
- async applyPlugins(request: CodemationBootstrapRequest): Promise<void> {
223
- const container = this.ensureConfiguredContainer();
224
- const env = request.resolveEnvironment();
225
- await this.pluginRegistrar.apply({
226
- plugins: this.plugins,
227
- container,
228
- appConfig: this.appConfigFactory.create({
229
- repoRoot: request.repoRoot,
230
- consumerRoot: request.consumerRoot,
231
- env,
232
- workflowSources: request.workflowSources,
233
- runtimeConfig: this.runtimeConfig,
234
- authConfig: this.applicationAuthConfig,
235
- whitelabelConfig: this.whitelabelConfig,
236
- }),
237
- registerCredentialType: (type) => this.registerCredentialType(type),
238
- loggerFactory: container.resolve(ApplicationTokens.LoggerFactory),
239
- });
240
- }
241
-
242
- async prepareContainer(request: CodemationBootstrapRequest): Promise<PreparedCodemationRuntime> {
243
- if (this.preparedRuntime) {
244
- return this.preparedRuntime;
245
- }
246
- const env = request.resolveEnvironment();
247
- this.preparedRuntime = await this.preparedRuntimeFactory.prepare({
248
- container: this.ensureConfiguredContainer(),
249
- repoRoot: request.repoRoot,
250
- consumerRoot: request.consumerRoot,
251
- env,
252
- workflowSources: request.workflowSources,
253
- runtimeConfig: this.runtimeConfig,
254
- applicationAuthConfig: this.applicationAuthConfig,
255
- whitelabelConfig: this.whitelabelConfig,
256
- hasConfiguredCredentialSessionServiceRegistration: this.hasConfiguredCredentialSessionServiceRegistration,
257
- });
258
- return this.preparedRuntime;
259
- }
260
-
261
- async bootCli(request: CodemationBootstrapRequest): Promise<PreparedCodemationRuntime> {
262
- const preparedRuntime = await this.prepareContainer(request);
263
- await this.cliRuntimeBootService.boot({ preparedRuntime });
264
- return preparedRuntime;
265
- }
266
-
267
- async bootFrontend(request: CodemationFrontendBootstrapRequest): Promise<PreparedCodemationRuntime> {
268
- const preparedRuntime = await this.prepareContainer(request.bootstrap);
269
- await this.frontendRuntimeBootService.boot({
270
- preparedRuntime,
271
- skipPresentationServers: request.skipPresentationServers,
272
- });
273
- return preparedRuntime;
274
- }
275
-
276
- async bootWorker(request: CodemationWorkerBootstrapRequest): Promise<CodemationStopHandle> {
277
- const preparedRuntime = await this.prepareContainer(request.bootstrap);
278
- void request.bootstrapSource;
279
- return await this.workerRuntimeBootService.boot({
280
- preparedRuntime,
281
- queues: request.queues,
282
- });
283
- }
284
-
285
- async stop(args?: Readonly<{ stopWebsocketServer?: boolean }>): Promise<void> {
286
- if (!this.preparedRuntime) {
287
- return;
288
- }
289
- await this.preparedRuntime.stop(args);
290
- }
291
-
292
- private ensureConfiguredContainer(): Container {
293
- if (this.configuredContainer) {
294
- return this.configuredContainer;
295
- }
296
- this.configuredContainer = this.containerFactory.create({
297
- application: this,
298
- registrations: this.containerRegistrations,
299
- runtimeConfig: this.runtimeConfig,
300
- workflows: this.workflows,
301
- credentialTypes: this.credentialTypes,
302
- sharedWorkflowWebsocketServer: this.sharedWorkflowWebsocketServer,
303
- });
304
- return this.configuredContainer;
305
- }
306
-
307
- private invalidatePreparedState(): void {
308
- this.configuredContainer = null;
309
- this.preparedRuntime = null;
310
- }
311
- }
@@ -1,21 +0,0 @@
1
- import type { CodemationApplication } from "../../codemationApplication";
2
- import type { CodemationConfig } from "../../presentation/config/CodemationConfig";
3
-
4
- import type { OpenAiApiKeyCredentialTypeFactory } from "./OpenAiApiKeyCredentialTypeFactory";
5
-
6
- /**
7
- * Registers framework-owned credential types that ship with the host (OpenAI-compatible API keys, etc.).
8
- */
9
- export class FrameworkBuiltinCredentialTypesRegistrar {
10
- constructor(private readonly openAiApiKeyCredentialTypeFactory: OpenAiApiKeyCredentialTypeFactory) {}
11
-
12
- register(application: CodemationApplication, config?: CodemationConfig): void {
13
- const openAiCredentialType = this.openAiApiKeyCredentialTypeFactory.createCredentialType();
14
- const openAiProvidedInConsumerConfig =
15
- config?.credentialTypes?.some((entry) => entry.definition.typeId === openAiCredentialType.definition.typeId) ??
16
- false;
17
- if (!openAiProvidedInConsumerConfig) {
18
- application.registerCredentialType(openAiCredentialType);
19
- }
20
- }
21
- }
@@ -1,91 +0,0 @@
1
- import path from "node:path";
2
- import type {
3
- CodemationApplicationRuntimeConfig,
4
- CodemationDatabaseConfig,
5
- CodemationDatabaseKind,
6
- } from "../../presentation/config/CodemationConfig";
7
-
8
- export type ResolvedDatabasePersistence =
9
- | Readonly<{ kind: "none" }>
10
- | Readonly<{ kind: "postgresql"; databaseUrl: string }>
11
- | Readonly<{ kind: "pglite"; dataDir: string }>;
12
-
13
- const DEFAULT_PGLITE_RELATIVE_DIR = ".codemation/pglite";
14
-
15
- /**
16
- * Resolves whether persistence uses TCP PostgreSQL, embedded PGlite, or in-memory stores.
17
- * Uses {@link CodemationConfig.runtime.database} as the source of truth; optional `CODEMATION_DATABASE_KIND`
18
- * and `CODEMATION_PGLITE_DATA_DIR` can override kind / PGlite directory. `DATABASE_URL` is not read here—put
19
- * connection strings in `runtime.database.url` (often sourced from `process.env` inside `codemation.config.ts`).
20
- */
21
- export class DatabasePersistenceResolver {
22
- resolve(
23
- args: Readonly<{ runtimeConfig: CodemationApplicationRuntimeConfig; env: NodeJS.ProcessEnv; consumerRoot: string }>,
24
- ): ResolvedDatabasePersistence {
25
- const db = args.runtimeConfig.database;
26
- if (!db) {
27
- return { kind: "none" };
28
- }
29
- const kind = this.resolveDatabaseKind(this.inferDatabaseKind(db), args.env);
30
- if (kind === "postgresql") {
31
- const url = db.url?.trim() ?? "";
32
- if (!url) {
33
- throw new Error('runtime.database.kind is "postgresql" but no database URL was set (runtime.database.url).');
34
- }
35
- if (!this.isPostgresUrl(url)) {
36
- throw new Error(
37
- `runtime.database.url must be a postgresql:// or postgres:// URL when kind is postgresql. Received: ${url}`,
38
- );
39
- }
40
- return { kind: "postgresql", databaseUrl: url };
41
- }
42
- const dataDir = this.resolvePgliteDataDirFromConfig(db, args.env, args.consumerRoot);
43
- return { kind: "pglite", dataDir };
44
- }
45
-
46
- resolveDatabaseKind(configured: CodemationDatabaseKind | undefined, env: NodeJS.ProcessEnv): CodemationDatabaseKind {
47
- const fromEnv = env.CODEMATION_DATABASE_KIND?.trim();
48
- if (fromEnv === "postgresql" || fromEnv === "pglite") {
49
- return fromEnv;
50
- }
51
- if (configured) {
52
- return configured;
53
- }
54
- return "pglite";
55
- }
56
-
57
- private inferDatabaseKind(db: CodemationDatabaseConfig): CodemationDatabaseKind {
58
- if (db.kind) {
59
- return db.kind;
60
- }
61
- const url = db.url?.trim();
62
- if (url && this.isPostgresUrl(url)) {
63
- return "postgresql";
64
- }
65
- return "pglite";
66
- }
67
-
68
- isPostgresUrl(value: string): boolean {
69
- return value.startsWith("postgresql://") || value.startsWith("postgres://");
70
- }
71
-
72
- isPgliteUrl(value: string): boolean {
73
- return value.startsWith("pglite:");
74
- }
75
-
76
- private resolvePgliteDataDirFromConfig(
77
- db: NonNullable<CodemationApplicationRuntimeConfig["database"]>,
78
- env: NodeJS.ProcessEnv,
79
- consumerRoot: string,
80
- ): string {
81
- const fromEnv = env.CODEMATION_PGLITE_DATA_DIR?.trim();
82
- if (fromEnv && fromEnv.length > 0) {
83
- return path.isAbsolute(fromEnv) ? fromEnv : path.resolve(consumerRoot, fromEnv);
84
- }
85
- const configured = db.pgliteDataDir?.trim();
86
- if (configured && configured.length > 0) {
87
- return path.isAbsolute(configured) ? configured : path.resolve(consumerRoot, configured);
88
- }
89
- return path.resolve(consumerRoot, DEFAULT_PGLITE_RELATIVE_DIR);
90
- }
91
- }
@@ -1,35 +0,0 @@
1
- import type {
2
- BinaryStorage,
3
- CredentialSessionService,
4
- EngineExecutionLimitsPolicy,
5
- NodeActivationContinuation,
6
- NodeExecutionScheduler,
7
- NodeResolver,
8
- WorkflowExecutionRepository,
9
- WorkflowDefinition,
10
- WorkflowId,
11
- } from "@codemation/core";
12
-
13
- export type WorkerRuntimeHandle = Readonly<{
14
- stop: () => Promise<void>;
15
- }>;
16
-
17
- export interface WorkerRuntimeScheduler extends NodeExecutionScheduler {
18
- createWorker(
19
- args: Readonly<{
20
- queues: ReadonlyArray<string>;
21
- workflowsById: ReadonlyMap<WorkflowId, WorkflowDefinition>;
22
- nodeResolver: NodeResolver;
23
- credentialSessions: CredentialSessionService;
24
- workflowExecutionRepository: WorkflowExecutionRepository;
25
- continuation: NodeActivationContinuation;
26
- binaryStorage?: BinaryStorage;
27
- workflows?: unknown;
28
- now?: () => Date;
29
- /** When set, must match the host engine policy so worker execution contexts use the same limits as `runtime.engineExecutionLimits`. */
30
- executionLimitsPolicy?: EngineExecutionLimitsPolicy;
31
- }>,
32
- ): WorkerRuntimeHandle;
33
-
34
- close(): Promise<void>;
35
- }
@@ -1,5 +0,0 @@
1
- import type { AnyCredentialType } from "@codemation/core";
2
-
3
- export interface CodemationApplicationFacade {
4
- registerCredentialType(type: AnyCredentialType): void;
5
- }