@lotiai/composer 0.2.0 → 0.2.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 (189) hide show
  1. package/dist/build-config/index.d.ts +52 -0
  2. package/dist/build-config/index.d.ts.map +1 -0
  3. package/dist/build-config/index.js +66 -0
  4. package/dist/build-config/index.js.map +1 -0
  5. package/dist/build-config/loader.d.ts +80 -0
  6. package/dist/build-config/loader.d.ts.map +1 -0
  7. package/dist/build-config/loader.js +238 -0
  8. package/dist/build-config/loader.js.map +1 -0
  9. package/dist/build-config/schema.d.ts +101 -0
  10. package/dist/build-config/schema.d.ts.map +1 -0
  11. package/dist/build-config/schema.js +94 -0
  12. package/dist/build-config/schema.js.map +1 -0
  13. package/dist/cli/commands/dev-temporal.d.ts +15 -0
  14. package/dist/cli/commands/dev-temporal.d.ts.map +1 -0
  15. package/dist/cli/commands/dev-temporal.js +68 -0
  16. package/dist/cli/commands/dev-temporal.js.map +1 -0
  17. package/dist/cli/commands/dev.d.ts +21 -0
  18. package/dist/cli/commands/dev.d.ts.map +1 -0
  19. package/dist/cli/commands/dev.js +421 -0
  20. package/dist/cli/commands/dev.js.map +1 -0
  21. package/dist/cli/commands/profiles.d.ts +15 -0
  22. package/dist/cli/commands/profiles.d.ts.map +1 -0
  23. package/dist/cli/commands/profiles.js +69 -0
  24. package/dist/cli/commands/profiles.js.map +1 -0
  25. package/dist/cli/index.d.ts +21 -0
  26. package/dist/cli/index.d.ts.map +1 -0
  27. package/dist/cli/index.js +44 -0
  28. package/dist/cli/index.js.map +1 -0
  29. package/dist/index.d.ts +15 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +57 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/internal/async/build/workflow-factory.d.ts +212 -0
  34. package/dist/internal/async/build/workflow-factory.d.ts.map +1 -0
  35. package/dist/internal/async/build/workflow-factory.js +533 -0
  36. package/dist/internal/async/build/workflow-factory.js.map +1 -0
  37. package/dist/internal/async/build-scripts/utils/common.d.ts +28 -0
  38. package/dist/internal/async/build-scripts/utils/common.d.ts.map +1 -0
  39. package/dist/internal/async/build-scripts/utils/common.js +50 -0
  40. package/dist/internal/async/build-scripts/utils/common.js.map +1 -0
  41. package/dist/internal/async/build-scripts/utils/import-module.d.ts +19 -0
  42. package/dist/internal/async/build-scripts/utils/import-module.d.ts.map +1 -0
  43. package/dist/internal/async/build-scripts/utils/import-module.js +80 -0
  44. package/dist/internal/async/build-scripts/utils/import-module.js.map +1 -0
  45. package/dist/internal/async/build-scripts/utils/type-guards.d.ts +123 -0
  46. package/dist/internal/async/build-scripts/utils/type-guards.d.ts.map +1 -0
  47. package/dist/internal/async/build-scripts/utils/type-guards.js +145 -0
  48. package/dist/internal/async/build-scripts/utils/type-guards.js.map +1 -0
  49. package/dist/internal/async/config/cleanup-policy.d.ts +50 -0
  50. package/dist/internal/async/config/cleanup-policy.d.ts.map +1 -0
  51. package/dist/internal/async/config/cleanup-policy.js +20 -0
  52. package/dist/internal/async/config/cleanup-policy.js.map +1 -0
  53. package/dist/internal/async/config/worker-profiles.d.ts +172 -0
  54. package/dist/internal/async/config/worker-profiles.d.ts.map +1 -0
  55. package/dist/internal/async/config/worker-profiles.js +275 -0
  56. package/dist/internal/async/config/worker-profiles.js.map +1 -0
  57. package/dist/internal/async/execute/temporal-client.d.ts +182 -0
  58. package/dist/internal/async/execute/temporal-client.d.ts.map +1 -0
  59. package/dist/internal/async/execute/temporal-client.js +190 -0
  60. package/dist/internal/async/execute/temporal-client.js.map +1 -0
  61. package/dist/internal/async/execute/workflow-execution.d.ts +98 -0
  62. package/dist/internal/async/execute/workflow-execution.d.ts.map +1 -0
  63. package/dist/internal/async/execute/workflow-execution.js +191 -0
  64. package/dist/internal/async/execute/workflow-execution.js.map +1 -0
  65. package/dist/internal/async/metrics/task-queue-metrics.d.ts +74 -0
  66. package/dist/internal/async/metrics/task-queue-metrics.d.ts.map +1 -0
  67. package/dist/internal/async/metrics/task-queue-metrics.js +155 -0
  68. package/dist/internal/async/metrics/task-queue-metrics.js.map +1 -0
  69. package/dist/internal/async/register/activity-worker.d.ts +123 -0
  70. package/dist/internal/async/register/activity-worker.d.ts.map +1 -0
  71. package/dist/internal/async/register/activity-worker.js +355 -0
  72. package/dist/internal/async/register/activity-worker.js.map +1 -0
  73. package/dist/internal/async/register/generate-workflow-source.d.ts +43 -0
  74. package/dist/internal/async/register/generate-workflow-source.d.ts.map +1 -0
  75. package/dist/internal/async/register/generate-workflow-source.js +193 -0
  76. package/dist/internal/async/register/generate-workflow-source.js.map +1 -0
  77. package/dist/internal/async/register/workflow-worker.d.ts +125 -0
  78. package/dist/internal/async/register/workflow-worker.d.ts.map +1 -0
  79. package/dist/internal/async/register/workflow-worker.js +215 -0
  80. package/dist/internal/async/register/workflow-worker.js.map +1 -0
  81. package/dist/internal/async/register-scripts/start-activity-worker.d.ts +70 -0
  82. package/dist/internal/async/register-scripts/start-activity-worker.d.ts.map +1 -0
  83. package/dist/internal/async/register-scripts/start-activity-worker.js +75 -0
  84. package/dist/internal/async/register-scripts/start-activity-worker.js.map +1 -0
  85. package/dist/internal/async/register-scripts/start-all-workers.d.ts +81 -0
  86. package/dist/internal/async/register-scripts/start-all-workers.d.ts.map +1 -0
  87. package/dist/internal/async/register-scripts/start-all-workers.js +84 -0
  88. package/dist/internal/async/register-scripts/start-all-workers.js.map +1 -0
  89. package/dist/internal/async/register-scripts/start-workflow-worker.d.ts +69 -0
  90. package/dist/internal/async/register-scripts/start-workflow-worker.d.ts.map +1 -0
  91. package/dist/internal/async/register-scripts/start-workflow-worker.js +74 -0
  92. package/dist/internal/async/register-scripts/start-workflow-worker.js.map +1 -0
  93. package/dist/internal/async/register-scripts/sync-schedules-cli.d.ts +28 -0
  94. package/dist/internal/async/register-scripts/sync-schedules-cli.d.ts.map +1 -0
  95. package/dist/internal/async/register-scripts/sync-schedules-cli.js +124 -0
  96. package/dist/internal/async/register-scripts/sync-schedules-cli.js.map +1 -0
  97. package/dist/internal/async/register-scripts/sync-schedules-via-lambda.d.ts +55 -0
  98. package/dist/internal/async/register-scripts/sync-schedules-via-lambda.d.ts.map +1 -0
  99. package/dist/internal/async/register-scripts/sync-schedules-via-lambda.js +146 -0
  100. package/dist/internal/async/register-scripts/sync-schedules-via-lambda.js.map +1 -0
  101. package/dist/internal/async/register-scripts/sync-schedules.d.ts +68 -0
  102. package/dist/internal/async/register-scripts/sync-schedules.d.ts.map +1 -0
  103. package/dist/internal/async/register-scripts/sync-schedules.js +83 -0
  104. package/dist/internal/async/register-scripts/sync-schedules.js.map +1 -0
  105. package/dist/internal/async/schedule/constants.d.ts +10 -0
  106. package/dist/internal/async/schedule/constants.d.ts.map +1 -0
  107. package/dist/internal/async/schedule/constants.js +13 -0
  108. package/dist/internal/async/schedule/constants.js.map +1 -0
  109. package/dist/internal/async/schedule/define-schedule.d.ts +192 -0
  110. package/dist/internal/async/schedule/define-schedule.d.ts.map +1 -0
  111. package/dist/internal/async/schedule/define-schedule.js +79 -0
  112. package/dist/internal/async/schedule/define-schedule.js.map +1 -0
  113. package/dist/internal/async/schedule/index.d.ts +3 -0
  114. package/dist/internal/async/schedule/index.d.ts.map +1 -0
  115. package/dist/internal/async/schedule/index.js +9 -0
  116. package/dist/internal/async/schedule/index.js.map +1 -0
  117. package/dist/internal/async/schedule/schedule-definition-schema.d.ts +64 -0
  118. package/dist/internal/async/schedule/schedule-definition-schema.d.ts.map +1 -0
  119. package/dist/internal/async/schedule/schedule-definition-schema.js +77 -0
  120. package/dist/internal/async/schedule/schedule-definition-schema.js.map +1 -0
  121. package/dist/internal/async/schedule/sync-schedules.d.ts +71 -0
  122. package/dist/internal/async/schedule/sync-schedules.d.ts.map +1 -0
  123. package/dist/internal/async/schedule/sync-schedules.js +231 -0
  124. package/dist/internal/async/schedule/sync-schedules.js.map +1 -0
  125. package/dist/internal/async/utils/ensure-namespace.d.ts +16 -0
  126. package/dist/internal/async/utils/ensure-namespace.d.ts.map +1 -0
  127. package/dist/internal/async/utils/ensure-namespace.js +64 -0
  128. package/dist/internal/async/utils/ensure-namespace.js.map +1 -0
  129. package/dist/internal/async/utils/find-package-root.d.ts +9 -0
  130. package/dist/internal/async/utils/find-package-root.d.ts.map +1 -0
  131. package/dist/internal/async/utils/find-package-root.js +28 -0
  132. package/dist/internal/async/utils/find-package-root.js.map +1 -0
  133. package/dist/internal/async/utils/is-composer-error.d.ts +14 -0
  134. package/dist/internal/async/utils/is-composer-error.d.ts.map +1 -0
  135. package/dist/internal/async/utils/is-composer-error.js +17 -0
  136. package/dist/internal/async/utils/is-composer-error.js.map +1 -0
  137. package/dist/internal/context-provider.d.ts +316 -0
  138. package/dist/internal/context-provider.d.ts.map +1 -0
  139. package/dist/internal/context-provider.js +12 -0
  140. package/dist/internal/context-provider.js.map +1 -0
  141. package/dist/internal/create-composer.d.ts +57 -0
  142. package/dist/internal/create-composer.d.ts.map +1 -0
  143. package/dist/internal/create-composer.js +125 -0
  144. package/dist/internal/create-composer.js.map +1 -0
  145. package/dist/internal/dag-sync-fanout.d.ts +79 -0
  146. package/dist/internal/dag-sync-fanout.d.ts.map +1 -0
  147. package/dist/internal/dag-sync-fanout.js +59 -0
  148. package/dist/internal/dag-sync-fanout.js.map +1 -0
  149. package/dist/internal/dag-sync-step.d.ts +230 -0
  150. package/dist/internal/dag-sync-step.d.ts.map +1 -0
  151. package/dist/internal/dag-sync-step.js +159 -0
  152. package/dist/internal/dag-sync-step.js.map +1 -0
  153. package/dist/internal/dag-sync-workflow.d.ts +535 -0
  154. package/dist/internal/dag-sync-workflow.d.ts.map +1 -0
  155. package/dist/internal/dag-sync-workflow.js +843 -0
  156. package/dist/internal/dag-sync-workflow.js.map +1 -0
  157. package/dist/internal/defaults.d.ts +24 -0
  158. package/dist/internal/defaults.d.ts.map +1 -0
  159. package/dist/internal/defaults.js +102 -0
  160. package/dist/internal/defaults.js.map +1 -0
  161. package/dist/internal/errors.d.ts +109 -0
  162. package/dist/internal/errors.d.ts.map +1 -0
  163. package/dist/internal/errors.js +212 -0
  164. package/dist/internal/errors.js.map +1 -0
  165. package/dist/internal/index.d.ts +9 -0
  166. package/dist/internal/index.d.ts.map +1 -0
  167. package/dist/internal/index.js +22 -0
  168. package/dist/internal/index.js.map +1 -0
  169. package/dist/internal/observability.d.ts +63 -0
  170. package/dist/internal/observability.d.ts.map +1 -0
  171. package/dist/internal/observability.js +323 -0
  172. package/dist/internal/observability.js.map +1 -0
  173. package/dist/internal/types.d.ts +80 -0
  174. package/dist/internal/types.d.ts.map +1 -0
  175. package/dist/internal/types.js +9 -0
  176. package/dist/internal/types.js.map +1 -0
  177. package/dist/internal/workflow-planning.d.ts +107 -0
  178. package/dist/internal/workflow-planning.d.ts.map +1 -0
  179. package/dist/internal/workflow-planning.js +216 -0
  180. package/dist/internal/workflow-planning.js.map +1 -0
  181. package/dist/schedule-sync.d.ts +17 -0
  182. package/dist/schedule-sync.d.ts.map +1 -0
  183. package/dist/schedule-sync.js +22 -0
  184. package/dist/schedule-sync.js.map +1 -0
  185. package/dist/temporal-naming.d.ts +27 -0
  186. package/dist/temporal-naming.d.ts.map +1 -0
  187. package/dist/temporal-naming.js +33 -0
  188. package/dist/temporal-naming.js.map +1 -0
  189. package/package.json +16 -17
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ /**
3
+ * Worker Profile Definitions for Temporal Activity Workers
4
+ *
5
+ * This module defines worker profiles that map step performance characteristics
6
+ * to appropriate infrastructure resources.
7
+ *
8
+ * ## Profiles
9
+ *
10
+ * - **standard**: General business logic (API calls, DB queries, content acquisition).
11
+ * 0.5 vCPU / 2GB per container, 15 concurrent activities, scales 2-10.
12
+ * - **heavy**: CPU-intensive or long-running work (zone ingestion, large data processing).
13
+ * 2 vCPU / 4GB per container, 5 concurrent activities, starts at 3 containers and scales 1-3 by default.
14
+ *
15
+ * Each profile maps to a dedicated Temporal task queue and ECS service.
16
+ *
17
+ * ## Configuration
18
+ *
19
+ * Defaults are defined here. Users can override via `composer.build-config.ts`:
20
+ * ```typescript
21
+ * workerProfiles: {
22
+ * standard: { cpu: 1024, memory: 4096 } // Override just what you need
23
+ * }
24
+ * ```
25
+ */
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.DEFAULT_WORKER_PROFILE = exports.WORKER_PROFILES = void 0;
28
+ exports.getTaskQueueForProfile = getTaskQueueForProfile;
29
+ exports.isValidWorkerProfile = isValidWorkerProfile;
30
+ exports.getAllTaskQueues = getAllTaskQueues;
31
+ exports.getEffectiveResources = getEffectiveResources;
32
+ exports.getEffectiveProfileConfig = getEffectiveProfileConfig;
33
+ exports.resolveProfilesForEnvironment = resolveProfilesForEnvironment;
34
+ exports.resolveActivityWorkerRuntimeConfig = resolveActivityWorkerRuntimeConfig;
35
+ exports.loadAndResolveActivityWorkerRuntimeConfig = loadAndResolveActivityWorkerRuntimeConfig;
36
+ exports.loadAndResolveCombinedWorkerConfigForLocalDev = loadAndResolveCombinedWorkerConfigForLocalDev;
37
+ const loader_1 = require("../../../build-config/loader");
38
+ /**
39
+ * Default worker profile configuration defining resource characteristics and task queues.
40
+ *
41
+ * These defaults are referenced by:
42
+ * - Step definitions (via `workerProfile` field - currently all use "standard")
43
+ * - Activity workers (to register on the "standard-tasks" queue)
44
+ * - Infrastructure as Code (to create appropriately sized ECS tasks)
45
+ *
46
+ * Users can override these defaults via `composer.build-config.ts`.
47
+ */
48
+ exports.WORKER_PROFILES = {
49
+ standard: {
50
+ name: "Standard",
51
+ taskQueue: "standard-tasks",
52
+ description: "General business logic: API calls, database queries, content acquisition, moderate computation",
53
+ resources: {
54
+ cpu: 512, // 0.5 vCPU (1024 = 1 vCPU)
55
+ memory: 2048, // 2 GB in MB
56
+ maxConcurrentActivities: 15,
57
+ minCount: 2,
58
+ maxConcurrentWorkflows: 100,
59
+ initialCount: 2,
60
+ maxCount: 10,
61
+ },
62
+ },
63
+ heavy: {
64
+ name: "Heavy",
65
+ taskQueue: "heavy-tasks",
66
+ description: "CPU-intensive or long-running work: zone file ingestion (gunzip + metaphone), large data processing",
67
+ resources: {
68
+ cpu: 2048, // 2 vCPU
69
+ memory: 4096, // 4 GB
70
+ maxConcurrentActivities: 5,
71
+ minCount: 1,
72
+ maxConcurrentWorkflows: 100,
73
+ initialCount: 3,
74
+ maxCount: 3,
75
+ },
76
+ },
77
+ };
78
+ /**
79
+ * Default worker profile for steps that don't explicitly declare one.
80
+ *
81
+ * Using "standard" as the default provides reasonable performance for
82
+ * typical business logic without over-provisioning resources.
83
+ */
84
+ exports.DEFAULT_WORKER_PROFILE = "standard";
85
+ /**
86
+ * Gets the task queue name for a given worker profile.
87
+ *
88
+ * @param profile - The worker profile
89
+ * @returns Temporal task queue name
90
+ */
91
+ function getTaskQueueForProfile(profile) {
92
+ return exports.WORKER_PROFILES[profile].taskQueue;
93
+ }
94
+ /**
95
+ * Validates that a profile string is a valid WorkerProfile.
96
+ *
97
+ * @param profile - The profile string to validate
98
+ * @returns true if valid, false otherwise
99
+ */
100
+ function isValidWorkerProfile(profile) {
101
+ return profile in exports.WORKER_PROFILES;
102
+ }
103
+ /**
104
+ * Gets all task queue names (useful for workers that listen to multiple queues).
105
+ *
106
+ * @returns Array of all task queue names
107
+ */
108
+ function getAllTaskQueues() {
109
+ return Object.values(exports.WORKER_PROFILES).map((config) => config.taskQueue);
110
+ }
111
+ /**
112
+ * Gets the effective resources for a worker profile, merging config overrides with defaults.
113
+ *
114
+ * @param profile - The worker profile name
115
+ * @param configOverrides - Optional overrides from composer.build-config.ts
116
+ * @returns The merged resource configuration
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * // With no overrides, returns defaults
121
+ * getEffectiveResources("standard");
122
+ * // { cpu: 512, memory: 2048, maxConcurrentActivities: 15, minCount: 2, initialCount: 2, maxCount: 10 }
123
+ *
124
+ * // With overrides, merges them
125
+ * getEffectiveResources("standard", { cpu: 1024 });
126
+ * // { cpu: 1024, memory: 2048, maxConcurrentActivities: 15, minCount: 2, initialCount: 2, maxCount: 10 }
127
+ * ```
128
+ */
129
+ function getEffectiveResources(profile, configOverrides) {
130
+ const defaults = exports.WORKER_PROFILES[profile].resources;
131
+ if (!configOverrides) {
132
+ return defaults;
133
+ }
134
+ // Only merge resource fields; configOverrides may include non-resource keys
135
+ // such as envExclusiveOptIn used for deployment topology decisions.
136
+ return {
137
+ cpu: configOverrides.cpu ?? defaults.cpu,
138
+ memory: configOverrides.memory ?? defaults.memory,
139
+ maxConcurrentActivities: configOverrides.maxConcurrentActivities ?? defaults.maxConcurrentActivities,
140
+ minCount: configOverrides.minCount ?? defaults.minCount,
141
+ maxConcurrentWorkflows: configOverrides.maxConcurrentWorkflows ?? defaults.maxConcurrentWorkflows,
142
+ initialCount: configOverrides.initialCount ?? defaults.initialCount,
143
+ maxCount: configOverrides.maxCount ?? defaults.maxCount,
144
+ };
145
+ }
146
+ /**
147
+ * Gets the effective worker profile config, merging config overrides with defaults.
148
+ *
149
+ * @param profile - The worker profile name
150
+ * @param config - Optional composer config containing workerProfiles overrides
151
+ * @returns The full profile config with merged resources
152
+ */
153
+ function getEffectiveProfileConfig(profile, config) {
154
+ const baseConfig = exports.WORKER_PROFILES[profile];
155
+ const overrides = config?.workerProfiles?.[profile];
156
+ return {
157
+ ...baseConfig,
158
+ resources: getEffectiveResources(profile, overrides),
159
+ };
160
+ }
161
+ /**
162
+ * Resolves which worker profiles are deployed for an environment and which task
163
+ * queues should be absorbed by fallback profiles.
164
+ *
165
+ * Profiles with no envExclusiveOptIn are always dedicated.
166
+ * Profiles with envExclusiveOptIn deploy only when environment is listed.
167
+ */
168
+ function resolveProfilesForEnvironment(environment, config) {
169
+ const dedicatedProfiles = {};
170
+ const fallbackQueues = {};
171
+ const fallbackSources = {};
172
+ for (const profile of Object.keys(exports.WORKER_PROFILES)) {
173
+ const overrides = config?.workerProfiles?.[profile];
174
+ const envExclusiveOptIn = overrides?.envExclusiveOptIn;
175
+ const isDedicated = !envExclusiveOptIn || envExclusiveOptIn.environments.includes(environment);
176
+ if (isDedicated) {
177
+ dedicatedProfiles[profile] = getEffectiveProfileConfig(profile, config);
178
+ continue;
179
+ }
180
+ const fallbackProfile = envExclusiveOptIn.fallbackProfile;
181
+ if (!isValidWorkerProfile(fallbackProfile)) {
182
+ throw new Error(`Invalid envExclusiveOptIn.fallbackProfile "${fallbackProfile}" for profile "${profile}".`);
183
+ }
184
+ const taskQueue = getTaskQueueForProfile(profile);
185
+ const existingQueues = fallbackQueues[fallbackProfile] ?? [];
186
+ if (!existingQueues.includes(taskQueue)) {
187
+ existingQueues.push(taskQueue);
188
+ }
189
+ fallbackQueues[fallbackProfile] = existingQueues;
190
+ const sources = fallbackSources[fallbackProfile] ?? [];
191
+ sources.push(profile);
192
+ fallbackSources[fallbackProfile] = sources;
193
+ }
194
+ for (const fallbackProfile of Object.keys(fallbackQueues)) {
195
+ if (!dedicatedProfiles[fallbackProfile]) {
196
+ const sourceProfiles = fallbackSources[fallbackProfile]?.join(", ") ?? "unknown";
197
+ throw new Error(`Profiles [${sourceProfiles}] fall back to "${fallbackProfile}" in environment "${environment}", but "${fallbackProfile}" is not deployed as a dedicated profile.`);
198
+ }
199
+ }
200
+ return {
201
+ dedicatedProfiles,
202
+ fallbackQueues,
203
+ };
204
+ }
205
+ /**
206
+ * Resolves runtime configuration for a single activity worker process.
207
+ *
208
+ * Validates the given profile, resolves the environment topology, and returns
209
+ * the task queues this worker should listen on plus the profile-derived
210
+ * max concurrent activities.
211
+ */
212
+ function resolveActivityWorkerRuntimeConfig(options) {
213
+ const { environment, workerProfile: rawProfile, config } = options;
214
+ if (!isValidWorkerProfile(rawProfile)) {
215
+ throw new Error(`Invalid worker profile: "${rawProfile}".`);
216
+ }
217
+ const workerProfile = rawProfile;
218
+ // Dedicated profiles are profiles that are deployed in the environment. They run activities
219
+ // from their own task queues. Fallback profiles are profiles that are not deployed in the environment.
220
+ // Activities that would normally go to that profile (i.e. heavy) are run on the fallback queue.
221
+ // i.e. In non-prod environments, heavy activities are run on the standard resource activity worker.
222
+ const { dedicatedProfiles, fallbackQueues } = resolveProfilesForEnvironment(environment, config);
223
+ const profileConfig = dedicatedProfiles[workerProfile];
224
+ if (!profileConfig) {
225
+ throw new Error(`Worker profile "${workerProfile}" is not configured as dedicated in environment "${environment}".`);
226
+ }
227
+ const primaryQueue = getTaskQueueForProfile(workerProfile);
228
+ const absorbedQueues = fallbackQueues[workerProfile] ?? [];
229
+ const taskQueues = [primaryQueue, ...absorbedQueues];
230
+ const maxConcurrentActivityTaskExecutions = profileConfig.resources.maxConcurrentActivities;
231
+ return {
232
+ workerProfile,
233
+ taskQueues,
234
+ maxConcurrentActivityTaskExecutions,
235
+ };
236
+ }
237
+ /**
238
+ * Convenience wrapper that loads build config from disk and then resolves
239
+ * activity worker runtime configuration.
240
+ */
241
+ async function loadAndResolveActivityWorkerRuntimeConfig(options) {
242
+ const { environment, workerProfile, buildConfigDir } = options;
243
+ const { config } = await (0, loader_1.loadBuildConfig)(buildConfigDir ? { searchDir: buildConfigDir } : undefined);
244
+ return resolveActivityWorkerRuntimeConfig({
245
+ environment,
246
+ workerProfile,
247
+ config,
248
+ });
249
+ }
250
+ /**
251
+ * Loads build config and resolves combined worker configuration
252
+ * across all dedicated profiles for the given environment.
253
+ *
254
+ * Designed for local development where a single process handles all
255
+ * task queues. Collects every dedicated profile's primary queue
256
+ * plus any absorbed fallback queues, sums maxConcurrentActivities,
257
+ * and takes the max of maxConcurrentWorkflows across profiles
258
+ * (since there is only one workflow worker regardless of activity profiles).
259
+ */
260
+ async function loadAndResolveCombinedWorkerConfigForLocalDev(options) {
261
+ const { environment, buildConfigDir } = options;
262
+ const { config } = await (0, loader_1.loadBuildConfig)(buildConfigDir ? { searchDir: buildConfigDir } : undefined);
263
+ const { dedicatedProfiles, fallbackQueues } = resolveProfilesForEnvironment(environment, config);
264
+ const taskQueues = [];
265
+ let maxConcurrentActivityTaskExecutions = 0;
266
+ let maxConcurrentWorkflowTaskExecutions = 0;
267
+ for (const profile of Object.keys(dedicatedProfiles)) {
268
+ const profileConfig = dedicatedProfiles[profile];
269
+ taskQueues.push(getTaskQueueForProfile(profile), ...(fallbackQueues[profile] ?? []));
270
+ maxConcurrentActivityTaskExecutions += profileConfig.resources.maxConcurrentActivities;
271
+ maxConcurrentWorkflowTaskExecutions = Math.max(maxConcurrentWorkflowTaskExecutions, profileConfig.resources.maxConcurrentWorkflows);
272
+ }
273
+ return { taskQueues, maxConcurrentActivityTaskExecutions, maxConcurrentWorkflowTaskExecutions };
274
+ }
275
+ //# sourceMappingURL=worker-profiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-profiles.js","sourceRoot":"","sources":["../../../../src/internal/async/config/worker-profiles.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;AA4FH,wDAEC;AAQD,oDAEC;AAOD,4CAEC;AAoBD,sDAsBC;AASD,8DAUC;AAcD,sEAkDC;AAqBD,gFAgCC;AAYD,8FAYC;AAwBD,sGAwBC;AApWD,yDAA+D;AA4B/D;;;;;;;;;GASG;AACU,QAAA,eAAe,GAA+C;IACzE,QAAQ,EAAE;QACR,IAAI,EAAE,UAAU;QAChB,SAAS,EAAE,gBAAgB;QAC3B,WAAW,EACT,gGAAgG;QAClG,SAAS,EAAE;YACT,GAAG,EAAE,GAAG,EAAE,2BAA2B;YACrC,MAAM,EAAE,IAAI,EAAE,aAAa;YAC3B,uBAAuB,EAAE,EAAE;YAC3B,QAAQ,EAAE,CAAC;YACX,sBAAsB,EAAE,GAAG;YAC3B,YAAY,EAAE,CAAC;YACf,QAAQ,EAAE,EAAE;SACb;KACF;IACD,KAAK,EAAE;QACL,IAAI,EAAE,OAAO;QACb,SAAS,EAAE,aAAa;QACxB,WAAW,EACT,qGAAqG;QACvG,SAAS,EAAE;YACT,GAAG,EAAE,IAAI,EAAE,SAAS;YACpB,MAAM,EAAE,IAAI,EAAE,OAAO;YACrB,uBAAuB,EAAE,CAAC;YAC1B,QAAQ,EAAE,CAAC;YACX,sBAAsB,EAAE,GA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EAAE,GAAG,6BAA6B,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAEjG,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,IAAI,mCAAmC,GAAG,CAAC,CAAC;IAC5C,IAAI,mCAAmC,GAAG,CAAC,CAAC;IAE5C,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAoB,EAAE,CAAC;QACxE,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAO,CAAE,CAAC;QAClD,UAAU,CAAC,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACrF,mCAAmC,IAAI,aAAa,CAAC,SAAS,CAAC,uBAAuB,CAAC;QACvF,mCAAmC,GAAG,IAAI,CAAC,GAAG,CAC5C,mCAAmC,EACnC,aAAa,CAAC,SAAS,CAAC,sBAAsB,CAC/C,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,mCAAmC,EAAE,mCAAmC,EAAE,CAAC;AAClG,CAAC"}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Temporal Client for Workflow Execution
3
+ *
4
+ * This module provides the client-side API for starting and managing
5
+ * Temporal workflows. Use this from your application code (API handlers,
6
+ * cron jobs, etc.) to initiate workflow executions.
7
+ *
8
+ * ## Usage:
9
+ *
10
+ * ```typescript
11
+ * import { executeWorkflow } from "@lotiai/composer/internal/async/execute/temporal-client";
12
+ *
13
+ * // Start a workflow
14
+ * const handle = await executeWorkflow({
15
+ * workflowName: "api-prompt-025b323f", // Versioned name from workflow-bundle
16
+ * input: {
17
+ * initialData: { promptText: "Hello" },
18
+ * workflowId: "prompt-123",
19
+ * correlationId: "req-456",
20
+ * },
21
+ * taskQueue: "workflow-tasks",
22
+ * });
23
+ *
24
+ * // Wait for result
25
+ * const result = await handle.result();
26
+ * ```
27
+ *
28
+ * @module temporal-client
29
+ */
30
+ import type { WorkflowHandle } from "@temporalio/client";
31
+ import { Client } from "@temporalio/client";
32
+ import type { VersioningOverride } from "@temporalio/common";
33
+ import type { UUIDV7 } from "../../types";
34
+ import type { WorkflowInput } from "../build/workflow-factory";
35
+ /**
36
+ * Configuration for connecting to Temporal Server.
37
+ */
38
+ export interface TemporalClientConfig {
39
+ /**
40
+ * Temporal Server address
41
+ */
42
+ address: string;
43
+ /**
44
+ * Temporal namespace
45
+ */
46
+ namespace: string;
47
+ }
48
+ /**
49
+ * Options for starting a workflow execution.
50
+ */
51
+ export interface ExecuteWorkflowOptions {
52
+ /**
53
+ * Workflow name (e.g., "api-prompt")
54
+ */
55
+ workflowName: string;
56
+ /**
57
+ * Unique workflow execution ID.
58
+ * Should be a meaningful business identifier or a generated UUID.
59
+ * This ID is used for idempotency and workflow reconnection.
60
+ */
61
+ workflowId: UUIDV7;
62
+ /**
63
+ * Input data for the workflow
64
+ */
65
+ input: WorkflowInput;
66
+ /**
67
+ * Task queue to execute workflow on
68
+ * @default "workflow-tasks"
69
+ */
70
+ taskQueue?: string;
71
+ /**
72
+ * Versioning override for Worker Versioning. When set, pins the workflow
73
+ * to a specific deployment version (buildId + deploymentName).
74
+ */
75
+ versioningOverride?: VersioningOverride;
76
+ /**
77
+ * Override Temporal client config for this execution
78
+ */
79
+ clientConfig: TemporalClientConfig;
80
+ }
81
+ /**
82
+ * Creates or returns a cached Temporal client connection.
83
+ * Caches the connection Promise (not the resolved client) so concurrent
84
+ * callers with the same config share a single in-flight connection attempt
85
+ * instead of racing and leaking extra gRPC connections.
86
+ *
87
+ * @param config - Client configuration
88
+ * @returns Temporal Client instance
89
+ */
90
+ export declare function createTemporalClient(config: TemporalClientConfig): Promise<Client>;
91
+ /**
92
+ * Starts a Temporal workflow execution.
93
+ *
94
+ * This is the primary function for executing workflows asynchronously.
95
+ * It returns a handle that can be used to query status, wait for results,
96
+ * cancel the workflow, etc.
97
+ *
98
+ * ## Example:
99
+ *
100
+ * ```typescript
101
+ * const handle = await executeWorkflow({
102
+ * workflowName: "api-prompt-025b323f",
103
+ * input: {
104
+ * initialData: { promptText: "Hello", identitiesInput: [...] },
105
+ * workflowId: "prompt-abc123",
106
+ * correlationId: "req-xyz789",
107
+ * environment: "production",
108
+ * },
109
+ * });
110
+ *
111
+ * // Option 1: Fire and forget
112
+ * console.log(`Workflow started: ${handle.workflowId}`);
113
+ *
114
+ * // Option 2: Wait for result
115
+ * const result = await handle.result();
116
+ * console.log("Workflow completed:", result);
117
+ * ```
118
+ *
119
+ * @param options - Workflow execution options
120
+ * @returns WorkflowHandle for the started workflow
121
+ */
122
+ export declare function executeWorkflow(options: ExecuteWorkflowOptions): Promise<WorkflowHandle<any>>;
123
+ /**
124
+ * Gets a handle to an existing workflow execution.
125
+ *
126
+ * Use this to reconnect to a workflow that was started previously,
127
+ * allowing you to query its status, wait for completion, or send signals.
128
+ *
129
+ * @param workflowId - The workflow execution ID
130
+ * @param config - Optional client configuration
131
+ * @returns WorkflowHandle for the existing workflow
132
+ */
133
+ export declare function getWorkflowHandle(workflowId: UUIDV7, config: TemporalClientConfig): Promise<WorkflowHandle<any>>;
134
+ /**
135
+ * Executes a workflow and waits for its result.
136
+ *
137
+ * This is a convenience function that combines starting a workflow
138
+ * and waiting for its completion. Use this when you need the result
139
+ * synchronously (e.g., in an API handler that must return the result).
140
+ *
141
+ * **Warning:** This will block until the workflow completes, which could
142
+ * be seconds or minutes depending on the workflow. Consider using
143
+ * `executeWorkflow` with fire-and-forget for long-running workflows.
144
+ *
145
+ * @param options - Workflow execution options
146
+ * @returns The workflow result
147
+ */
148
+ export declare function executeWorkflowAndWait<T = any>(options: ExecuteWorkflowOptions): Promise<T>;
149
+ /**
150
+ * Cancels a running workflow execution.
151
+ *
152
+ * @param workflowId - The workflow execution ID
153
+ * @param config - Optional client configuration
154
+ */
155
+ export declare function cancelWorkflow(workflowId: UUIDV7, config: TemporalClientConfig): Promise<void>;
156
+ /**
157
+ * Queries a workflow's status without affecting its execution.
158
+ *
159
+ * **Note:** Workflow queries require the workflow to define query handlers.
160
+ * This is not currently implemented in our workflow-factory, but can be
161
+ * added in the future.
162
+ *
163
+ * @param workflowId - The workflow execution ID
164
+ * @param queryName - The query to execute
165
+ * @param config - Optional client configuration
166
+ * @returns The query result
167
+ */
168
+ export declare function queryWorkflow<T = any>(workflowId: UUIDV7, queryName: string, config: TemporalClientConfig): Promise<T>;
169
+ /**
170
+ * Sends a signal to a running workflow.
171
+ *
172
+ * **Note:** Workflow signals require the workflow to define signal handlers.
173
+ * This is not currently implemented in our workflow-factory, but can be
174
+ * added in the future for interactive workflows.
175
+ *
176
+ * @param workflowId - The workflow execution ID
177
+ * @param signalName - The signal to send
178
+ * @param data - Signal payload
179
+ * @param config - Optional client configuration
180
+ */
181
+ export declare function signalWorkflow(workflowId: UUIDV7, signalName: string, data: any, config: TemporalClientConfig): Promise<void>;
182
+ //# sourceMappingURL=temporal-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"temporal-client.d.ts","sourceRoot":"","sources":["../../../../src/internal/async/execute/temporal-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAc,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IAC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AC,CAGf"}
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ /**
3
+ * Temporal Client for Workflow Execution
4
+ *
5
+ * This module provides the client-side API for starting and managing
6
+ * Temporal workflows. Use this from your application code (API handlers,
7
+ * cron jobs, etc.) to initiate workflow executions.
8
+ *
9
+ * ## Usage:
10
+ *
11
+ * ```typescript
12
+ * import { executeWorkflow } from "@lotiai/composer/internal/async/execute/temporal-client";
13
+ *
14
+ * // Start a workflow
15
+ * const handle = await executeWorkflow({
16
+ * workflowName: "api-prompt-025b323f", // Versioned name from workflow-bundle
17
+ * input: {
18
+ * initialData: { promptText: "Hello" },
19
+ * workflowId: "prompt-123",
20
+ * correlationId: "req-456",
21
+ * },
22
+ * taskQueue: "workflow-tasks",
23
+ * });
24
+ *
25
+ * // Wait for result
26
+ * const result = await handle.result();
27
+ * ```
28
+ *
29
+ * @module temporal-client
30
+ */
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.createTemporalClient = createTemporalClient;
33
+ exports.executeWorkflow = executeWorkflow;
34
+ exports.getWorkflowHandle = getWorkflowHandle;
35
+ exports.executeWorkflowAndWait = executeWorkflowAndWait;
36
+ exports.cancelWorkflow = cancelWorkflow;
37
+ exports.queryWorkflow = queryWorkflow;
38
+ exports.signalWorkflow = signalWorkflow;
39
+ const client_1 = require("@temporalio/client");
40
+ const cachedClients = new Map();
41
+ /**
42
+ * Creates or returns a cached Temporal client connection.
43
+ * Caches the connection Promise (not the resolved client) so concurrent
44
+ * callers with the same config share a single in-flight connection attempt
45
+ * instead of racing and leaking extra gRPC connections.
46
+ *
47
+ * @param config - Client configuration
48
+ * @returns Temporal Client instance
49
+ */
50
+ function createTemporalClient(config) {
51
+ const cacheKey = `${config.address}:${config.namespace}`;
52
+ const existing = cachedClients.get(cacheKey);
53
+ if (existing) {
54
+ return existing;
55
+ }
56
+ const clientPromise = (async () => {
57
+ const connection = await client_1.Connection.connect({
58
+ address: config.address,
59
+ });
60
+ // TODO: Add OpenTelemetry interceptor for trace context propagation
61
+ // Once @temporalio/interceptors-opentelemetry is installed, add:
62
+ // import { OpenTelemetryWorkflowClientCallsInterceptor } from "@temporalio/interceptors-opentelemetry";
63
+ // Then add to Client options: interceptors: { workflow: [() => new OpenTelemetryWorkflowClientCallsInterceptor()] }
64
+ return new client_1.Client({
65
+ connection,
66
+ namespace: config.namespace,
67
+ });
68
+ })();
69
+ cachedClients.set(cacheKey, clientPromise);
70
+ clientPromise.catch(() => {
71
+ cachedClients.delete(cacheKey);
72
+ });
73
+ return clientPromise;
74
+ }
75
+ /**
76
+ * Starts a Temporal workflow execution.
77
+ *
78
+ * This is the primary function for executing workflows asynchronously.
79
+ * It returns a handle that can be used to query status, wait for results,
80
+ * cancel the workflow, etc.
81
+ *
82
+ * ## Example:
83
+ *
84
+ * ```typescript
85
+ * const handle = await executeWorkflow({
86
+ * workflowName: "api-prompt-025b323f",
87
+ * input: {
88
+ * initialData: { promptText: "Hello", identitiesInput: [...] },
89
+ * workflowId: "prompt-abc123",
90
+ * correlationId: "req-xyz789",
91
+ * environment: "production",
92
+ * },
93
+ * });
94
+ *
95
+ * // Option 1: Fire and forget
96
+ * console.log(`Workflow started: ${handle.workflowId}`);
97
+ *
98
+ * // Option 2: Wait for result
99
+ * const result = await handle.result();
100
+ * console.log("Workflow completed:", result);
101
+ * ```
102
+ *
103
+ * @param options - Workflow execution options
104
+ * @returns WorkflowHandle for the started workflow
105
+ */
106
+ async function executeWorkflow(options) {
107
+ const client = await createTemporalClient(options.clientConfig);
108
+ const handle = await client.workflow.start(options.workflowName, {
109
+ taskQueue: options.taskQueue ?? "workflow-tasks",
110
+ workflowId: options.workflowId,
111
+ args: [options.input],
112
+ ...(options.versioningOverride ? { versioningOverride: options.versioningOverride } : {}),
113
+ });
114
+ return handle;
115
+ }
116
+ /**
117
+ * Gets a handle to an existing workflow execution.
118
+ *
119
+ * Use this to reconnect to a workflow that was started previously,
120
+ * allowing you to query its status, wait for completion, or send signals.
121
+ *
122
+ * @param workflowId - The workflow execution ID
123
+ * @param config - Optional client configuration
124
+ * @returns WorkflowHandle for the existing workflow
125
+ */
126
+ async function getWorkflowHandle(workflowId, config) {
127
+ const client = await createTemporalClient(config);
128
+ return client.workflow.getHandle(workflowId);
129
+ }
130
+ /**
131
+ * Executes a workflow and waits for its result.
132
+ *
133
+ * This is a convenience function that combines starting a workflow
134
+ * and waiting for its completion. Use this when you need the result
135
+ * synchronously (e.g., in an API handler that must return the result).
136
+ *
137
+ * **Warning:** This will block until the workflow completes, which could
138
+ * be seconds or minutes depending on the workflow. Consider using
139
+ * `executeWorkflow` with fire-and-forget for long-running workflows.
140
+ *
141
+ * @param options - Workflow execution options
142
+ * @returns The workflow result
143
+ */
144
+ async function executeWorkflowAndWait(options) {
145
+ const handle = await executeWorkflow(options);
146
+ return (await handle.result());
147
+ }
148
+ /**
149
+ * Cancels a running workflow execution.
150
+ *
151
+ * @param workflowId - The workflow execution ID
152
+ * @param config - Optional client configuration
153
+ */
154
+ async function cancelWorkflow(workflowId, config) {
155
+ const handle = await getWorkflowHandle(workflowId, config);
156
+ await handle.cancel();
157
+ }
158
+ /**
159
+ * Queries a workflow's status without affecting its execution.
160
+ *
161
+ * **Note:** Workflow queries require the workflow to define query handlers.
162
+ * This is not currently implemented in our workflow-factory, but can be
163
+ * added in the future.
164
+ *
165
+ * @param workflowId - The workflow execution ID
166
+ * @param queryName - The query to execute
167
+ * @param config - Optional client configuration
168
+ * @returns The query result
169
+ */
170
+ async function queryWorkflow(workflowId, queryName, config) {
171
+ const handle = await getWorkflowHandle(workflowId, config);
172
+ return await handle.query(queryName);
173
+ }
174
+ /**
175
+ * Sends a signal to a running workflow.
176
+ *
177
+ * **Note:** Workflow signals require the workflow to define signal handlers.
178
+ * This is not currently implemented in our workflow-factory, but can be
179
+ * added in the future for interactive workflows.
180
+ *
181
+ * @param workflowId - The workflow execution ID
182
+ * @param signalName - The signal to send
183
+ * @param data - Signal payload
184
+ * @param config - Optional client configuration
185
+ */
186
+ async function signalWorkflow(workflowId, signalName, data, config) {
187
+ const handle = await getWorkflowHandle(workflowId, config);
188
+ await handle.signal(signalName, data);
189
+ }
190
+ //# sourceMappingURL=temporal-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"temporal-client.js","sourceRoot":"","sources":["../../../../src/internal/async/execute/temporal-client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;AAyEH,oDA+BC;AAiCD,0CAaC;AAYD,8CAMC;AAgBD,wDAGC;AAQD,wCAMC;AAcD,sCAOC;AAcD,wCAQC;AAjPD,+CAAwD;AA2DxD,MAAM,aAAa,GAAG,IAAI,GAAG,EAA2B,CAAC;AAEzD;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CAAC,MAA4B;IAC/D,MAAM,QAAQ,GAAG,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;IAEzD,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,aAAa,GAAG,CAAC,KAAK,IAAI,EAAE;QAChC,MAAM,UAAU,GAAG,MAAM,mBAAU,CAAC,OAAO,CAAC;YAC1C,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC,CAAC;QAEH,oEAAoE;QACpE,iEAAiE;QACjE,wGAAwG;QACxG,oHAAoH;QAEpH,OAAO,IAAI,eAAM,CAAC;YAChB,UAAU;YACV,SAAS,EAAE,MAAM,CAAC,SAAS;SAC5B,CAAC,CAAC;IACL,CAAC,CAAC,EAAE,CAAC;IAEL,aAAa,CAAC,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IAE3C,aAAa,CAAC,KAAK,CAAC,GAAG,EAAE;QACvB,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;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