@treeseed/agent 0.8.5

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 (138) hide show
  1. package/Dockerfile +7 -0
  2. package/README.md +198 -0
  3. package/dist/agent-runtime.d.ts +17 -0
  4. package/dist/agent-runtime.js +117 -0
  5. package/dist/agents/adapters/execution.d.ts +41 -0
  6. package/dist/agents/adapters/execution.js +73 -0
  7. package/dist/agents/adapters/mutations.d.ts +22 -0
  8. package/dist/agents/adapters/mutations.js +30 -0
  9. package/dist/agents/adapters/notification.d.ts +26 -0
  10. package/dist/agents/adapters/notification.js +46 -0
  11. package/dist/agents/adapters/repository.d.ts +28 -0
  12. package/dist/agents/adapters/repository.js +61 -0
  13. package/dist/agents/adapters/research.d.ts +26 -0
  14. package/dist/agents/adapters/research.js +59 -0
  15. package/dist/agents/adapters/verification.d.ts +36 -0
  16. package/dist/agents/adapters/verification.js +62 -0
  17. package/dist/agents/cli-tools.d.ts +1 -0
  18. package/dist/agents/cli-tools.js +5 -0
  19. package/dist/agents/cli.d.ts +15 -0
  20. package/dist/agents/cli.js +109 -0
  21. package/dist/agents/contracts/messages.d.ts +88 -0
  22. package/dist/agents/contracts/messages.js +138 -0
  23. package/dist/agents/contracts/run.d.ts +21 -0
  24. package/dist/agents/contracts/run.js +0 -0
  25. package/dist/agents/index.d.ts +1 -0
  26. package/dist/agents/index.js +5 -0
  27. package/dist/agents/kernel/agent-kernel.d.ts +63 -0
  28. package/dist/agents/kernel/agent-kernel.js +291 -0
  29. package/dist/agents/kernel/trigger-resolver.d.ts +19 -0
  30. package/dist/agents/kernel/trigger-resolver.js +157 -0
  31. package/dist/agents/registry-helper.d.ts +4 -0
  32. package/dist/agents/registry-helper.js +14 -0
  33. package/dist/agents/registry.d.ts +6 -0
  34. package/dist/agents/registry.js +98 -0
  35. package/dist/agents/runtime-types.d.ts +118 -0
  36. package/dist/agents/runtime-types.js +0 -0
  37. package/dist/agents/spec-loader.d.ts +18 -0
  38. package/dist/agents/spec-loader.js +54 -0
  39. package/dist/agents/spec-normalizer.d.ts +2 -0
  40. package/dist/agents/spec-normalizer.js +327 -0
  41. package/dist/agents/spec-types.d.ts +64 -0
  42. package/dist/agents/spec-types.js +0 -0
  43. package/dist/agents/testing/agents-smoke.d.ts +1 -0
  44. package/dist/agents/testing/agents-smoke.js +32 -0
  45. package/dist/agents/testing/e2e-harness.d.ts +44 -0
  46. package/dist/agents/testing/e2e-harness.js +503 -0
  47. package/dist/api/agent-routes.d.ts +13 -0
  48. package/dist/api/agent-routes.js +327 -0
  49. package/dist/api/app.d.ts +8 -0
  50. package/dist/api/app.js +444 -0
  51. package/dist/api/auth/d1-database.d.ts +3 -0
  52. package/dist/api/auth/d1-database.js +20 -0
  53. package/dist/api/auth/d1-provider.d.ts +79 -0
  54. package/dist/api/auth/d1-provider.js +92 -0
  55. package/dist/api/auth/d1-store.d.ts +114 -0
  56. package/dist/api/auth/d1-store.js +895 -0
  57. package/dist/api/auth/memory-provider.d.ts +77 -0
  58. package/dist/api/auth/memory-provider.js +249 -0
  59. package/dist/api/auth/rbac.d.ts +22 -0
  60. package/dist/api/auth/rbac.js +162 -0
  61. package/dist/api/auth/tokens.d.ts +18 -0
  62. package/dist/api/auth/tokens.js +56 -0
  63. package/dist/api/capabilities.d.ts +9 -0
  64. package/dist/api/capabilities.js +33 -0
  65. package/dist/api/config.d.ts +2 -0
  66. package/dist/api/config.js +77 -0
  67. package/dist/api/http.d.ts +28 -0
  68. package/dist/api/http.js +51 -0
  69. package/dist/api/index.d.ts +9 -0
  70. package/dist/api/index.js +20 -0
  71. package/dist/api/operations-routes.d.ts +11 -0
  72. package/dist/api/operations-routes.js +87 -0
  73. package/dist/api/operations.d.ts +3 -0
  74. package/dist/api/operations.js +26 -0
  75. package/dist/api/project-routes.d.ts +8 -0
  76. package/dist/api/project-routes.js +585 -0
  77. package/dist/api/providers.d.ts +2 -0
  78. package/dist/api/providers.js +62 -0
  79. package/dist/api/railway.d.ts +51 -0
  80. package/dist/api/railway.js +71 -0
  81. package/dist/api/sdk-dispatch.d.ts +5 -0
  82. package/dist/api/sdk-dispatch.js +13 -0
  83. package/dist/api/sdk-routes.d.ts +11 -0
  84. package/dist/api/sdk-routes.js +29 -0
  85. package/dist/api/server.d.ts +2 -0
  86. package/dist/api/server.js +10 -0
  87. package/dist/api/templates.d.ts +3 -0
  88. package/dist/api/templates.js +31 -0
  89. package/dist/api/types.d.ts +237 -0
  90. package/dist/api/types.js +0 -0
  91. package/dist/env.yaml +957 -0
  92. package/dist/index.d.ts +14 -0
  93. package/dist/index.js +41 -0
  94. package/dist/scripts/assert-release-tag-version.d.ts +1 -0
  95. package/dist/scripts/assert-release-tag-version.js +20 -0
  96. package/dist/scripts/build-dist.d.ts +1 -0
  97. package/dist/scripts/build-dist.js +106 -0
  98. package/dist/scripts/package-tools.d.ts +1 -0
  99. package/dist/scripts/package-tools.js +7 -0
  100. package/dist/scripts/publish-package.d.ts +1 -0
  101. package/dist/scripts/publish-package.js +24 -0
  102. package/dist/scripts/release-verify.d.ts +1 -0
  103. package/dist/scripts/release-verify.js +152 -0
  104. package/dist/scripts/test-smoke.d.ts +1 -0
  105. package/dist/scripts/test-smoke.js +23 -0
  106. package/dist/scripts/treeseed-agent-api.d.ts +2 -0
  107. package/dist/scripts/treeseed-agent-api.js +25 -0
  108. package/dist/scripts/treeseed-agent-service.d.ts +2 -0
  109. package/dist/scripts/treeseed-agent-service.js +36 -0
  110. package/dist/scripts/treeseed-agents.d.ts +2 -0
  111. package/dist/scripts/treeseed-agents.js +13 -0
  112. package/dist/services/agents.d.ts +17 -0
  113. package/dist/services/agents.js +48 -0
  114. package/dist/services/common.d.ts +66 -0
  115. package/dist/services/common.js +212 -0
  116. package/dist/services/index.d.ts +6 -0
  117. package/dist/services/index.js +19 -0
  118. package/dist/services/manager.d.ts +333 -0
  119. package/dist/services/manager.js +1368 -0
  120. package/dist/services/remote-runner.d.ts +30 -0
  121. package/dist/services/remote-runner.js +230 -0
  122. package/dist/services/workday-content.d.ts +53 -0
  123. package/dist/services/workday-content.js +190 -0
  124. package/dist/services/workday-manager.d.ts +391 -0
  125. package/dist/services/workday-manager.js +163 -0
  126. package/dist/services/workday-report.d.ts +238 -0
  127. package/dist/services/workday-report.js +17 -0
  128. package/dist/services/workday-start.d.ts +238 -0
  129. package/dist/services/workday-start.js +17 -0
  130. package/dist/services/worker-capacity.d.ts +58 -0
  131. package/dist/services/worker-capacity.js +208 -0
  132. package/dist/services/worker-pool-scaler.d.ts +27 -0
  133. package/dist/services/worker-pool-scaler.js +127 -0
  134. package/dist/services/worker.d.ts +19 -0
  135. package/dist/services/worker.js +436 -0
  136. package/dist/templates/github/deploy-processing.workflow.yml +119 -0
  137. package/package.json +136 -0
  138. package/templates/github/deploy-processing.workflow.yml +119 -0
@@ -0,0 +1,208 @@
1
+ import { createWorkerPoolScaler } from "./worker-pool-scaler.js";
2
+ function integerFromEnv(name, fallback) {
3
+ const value = process.env[name];
4
+ if (!value) return fallback;
5
+ const parsed = Number.parseInt(value, 10);
6
+ return Number.isFinite(parsed) ? parsed : fallback;
7
+ }
8
+ function envValue(name) {
9
+ const value = process.env[name]?.trim();
10
+ return value ? value : "";
11
+ }
12
+ function parseJson(value, fallback) {
13
+ if (typeof value !== "string" || !value.trim()) {
14
+ return fallback;
15
+ }
16
+ try {
17
+ return JSON.parse(value);
18
+ } catch {
19
+ return fallback;
20
+ }
21
+ }
22
+ function readNumber(record, ...keys) {
23
+ for (const key of keys) {
24
+ const value = record[key];
25
+ if (typeof value === "number" && Number.isFinite(value)) {
26
+ return value;
27
+ }
28
+ if (typeof value === "string" && value.trim()) {
29
+ const parsed = Number.parseFloat(value);
30
+ if (Number.isFinite(parsed)) {
31
+ return parsed;
32
+ }
33
+ }
34
+ }
35
+ return null;
36
+ }
37
+ function asRecords(value) {
38
+ return Array.isArray(value) ? value : [];
39
+ }
40
+ function resolveAutoscalePolicyFromEnv() {
41
+ return {
42
+ minWorkers: integerFromEnv("TREESEED_AGENT_POOL_MIN_WORKERS", 0),
43
+ maxWorkers: integerFromEnv("TREESEED_AGENT_POOL_MAX_WORKERS", 1),
44
+ targetQueueDepth: Math.max(1, integerFromEnv("TREESEED_AGENT_POOL_TARGET_QUEUE_DEPTH", 1)),
45
+ cooldownSeconds: Math.max(0, integerFromEnv("TREESEED_AGENT_POOL_COOLDOWN_SECONDS", 60))
46
+ };
47
+ }
48
+ function resolveWorkerPoolIdentityFromEnv(projectId) {
49
+ const environment = envValue("TREESEED_DEPLOY_ENVIRONMENT") || (process.env.NODE_ENV === "production" ? "prod" : "local");
50
+ const resolvedProjectId = projectId?.trim() || envValue("TREESEED_PROJECT_ID") || "treeseed-market";
51
+ return {
52
+ projectId: resolvedProjectId,
53
+ environment,
54
+ poolName: envValue("TREESEED_AGENT_POOL_NAME") || `${resolvedProjectId}-${environment}`
55
+ };
56
+ }
57
+ function computeDesiredWorkerCount(autoscale, metrics) {
58
+ const { minWorkers, maxWorkers, targetQueueDepth } = autoscale;
59
+ if (metrics.queuedCount <= 0 && metrics.activeLeases <= 0) {
60
+ return minWorkers;
61
+ }
62
+ const requiredByQueue = Math.ceil(metrics.queuedCount / Math.max(1, targetQueueDepth));
63
+ const minimumActive = metrics.activeLeases > 0 ? 1 : 0;
64
+ return Math.max(minWorkers, Math.min(maxWorkers, Math.max(requiredByQueue, minimumActive)));
65
+ }
66
+ function applyScaleCooldown(autoscale, latestDecision, nextDesired, now) {
67
+ if (!latestDecision) {
68
+ return nextDesired;
69
+ }
70
+ if (nextDesired >= latestDecision.desiredWorkers) {
71
+ return nextDesired;
72
+ }
73
+ const cooldownMs = Math.max(0, autoscale.cooldownSeconds) * 1e3;
74
+ if (cooldownMs === 0) {
75
+ return nextDesired;
76
+ }
77
+ const lastChangedAt = new Date(latestDecision.createdAt);
78
+ if (!Number.isFinite(lastChangedAt.valueOf())) {
79
+ return nextDesired;
80
+ }
81
+ return now.valueOf() - lastChangedAt.valueOf() < cooldownMs ? latestDecision.desiredWorkers : nextDesired;
82
+ }
83
+ function applyInteractiveWakeUpOverride(options) {
84
+ if (options.priorityClass !== "interactive") {
85
+ return options.desiredWorkers;
86
+ }
87
+ if (options.queuedCount <= 0 || options.currentWorkers > 0 || options.desiredWorkers > 0) {
88
+ return options.desiredWorkers;
89
+ }
90
+ return 1;
91
+ }
92
+ async function collectTaskMetrics(sdk, workDayId) {
93
+ const [queuedEnvelope, activeEnvelope] = await Promise.all([
94
+ sdk.searchTasks({
95
+ workDayId: workDayId ?? void 0,
96
+ limit: 500,
97
+ state: ["pending", "queued"]
98
+ }),
99
+ sdk.searchTasks({
100
+ workDayId: workDayId ?? void 0,
101
+ limit: 500,
102
+ state: ["claimed", "running"]
103
+ })
104
+ ]);
105
+ const queuedTasks = asRecords(queuedEnvelope.payload);
106
+ const activeTasks = asRecords(activeEnvelope.payload);
107
+ const queuedCredits = queuedTasks.reduce((total, task) => {
108
+ const payload = parseJson(String(task.payloadJson ?? "{}"), {});
109
+ const credits = readNumber(payload, "estimatedCredits") ?? 1;
110
+ return total + credits;
111
+ }, 0);
112
+ return {
113
+ queuedTasks,
114
+ activeTasks,
115
+ queuedCount: queuedTasks.length,
116
+ activeLeases: activeTasks.length,
117
+ queuedCredits
118
+ };
119
+ }
120
+ async function enqueueTaskAndEnsureCapacity(sdk, request) {
121
+ await request.enqueueTask(sdk, {
122
+ taskId: request.taskId,
123
+ queueName: request.queueName,
124
+ deliveryDelaySeconds: request.deliveryDelaySeconds,
125
+ actor: request.actor
126
+ });
127
+ const now = request.now ?? /* @__PURE__ */ new Date();
128
+ const identity = request.identity ?? resolveWorkerPoolIdentityFromEnv(request.projectId);
129
+ const autoscale = request.autoscale ?? resolveAutoscalePolicyFromEnv();
130
+ const scaler = request.scaler ?? createWorkerPoolScaler();
131
+ const metrics = await collectTaskMetrics(sdk);
132
+ const latestScaleDecision = await sdk.getLatestScaleDecision(identity.projectId, identity.environment, identity.poolName);
133
+ const currentWorkers = Math.max(0, Number(latestScaleDecision.payload?.desiredWorkers ?? 0));
134
+ const rawDesiredWorkers = computeDesiredWorkerCount(autoscale, metrics);
135
+ const desiredAfterCooldown = applyScaleCooldown(autoscale, latestScaleDecision.payload, rawDesiredWorkers, now);
136
+ const desiredWorkers = applyInteractiveWakeUpOverride({
137
+ priorityClass: request.priorityClass ?? "background",
138
+ queuedCount: metrics.queuedCount,
139
+ currentWorkers,
140
+ desiredWorkers: desiredAfterCooldown
141
+ });
142
+ const coldStartTriggered = (request.priorityClass ?? "background") === "interactive" && currentWorkers <= 0 && desiredWorkers > 0;
143
+ const scaleReason = desiredWorkers !== desiredAfterCooldown ? "interactive_cold_start" : coldStartTriggered ? "interactive_cold_start" : desiredWorkers !== rawDesiredWorkers ? "cooldown_hold" : request.priorityClass === "interactive" ? "interactive_enqueue" : "enqueue";
144
+ const recordedScaleDecision = await sdk.recordScaleDecision({
145
+ projectId: identity.projectId,
146
+ environment: identity.environment,
147
+ poolName: identity.poolName,
148
+ workDayId: null,
149
+ desiredWorkers,
150
+ observedQueueDepth: metrics.queuedCount,
151
+ observedActiveLeases: metrics.activeLeases,
152
+ reason: scaleReason,
153
+ metadata: {
154
+ priorityClass: request.priorityClass ?? "background",
155
+ taskId: request.taskId
156
+ }
157
+ });
158
+ const scaleDecision = recordedScaleDecision.payload ?? {
159
+ projectId: identity.projectId,
160
+ environment: identity.environment,
161
+ poolName: identity.poolName,
162
+ workDayId: null,
163
+ desiredWorkers,
164
+ observedQueueDepth: metrics.queuedCount,
165
+ observedActiveLeases: metrics.activeLeases,
166
+ reason: scaleReason,
167
+ metadata: {
168
+ priorityClass: request.priorityClass ?? "background",
169
+ taskId: request.taskId
170
+ },
171
+ createdAt: now.toISOString()
172
+ };
173
+ let scaleResult;
174
+ try {
175
+ scaleResult = await scaler.scale(scaleDecision);
176
+ } catch (error) {
177
+ scaleResult = {
178
+ applied: false,
179
+ provider: "error",
180
+ desiredWorkers,
181
+ metadata: {
182
+ reason: "scale_failed",
183
+ error: error instanceof Error ? error.message : String(error)
184
+ }
185
+ };
186
+ }
187
+ return {
188
+ ok: true,
189
+ taskId: request.taskId,
190
+ queued: true,
191
+ workerState: currentWorkers > 0 ? "warm" : desiredWorkers > 0 ? "cold_starting" : "warm",
192
+ desiredWorkers,
193
+ scaleApplied: scaleResult.applied,
194
+ scaleReason,
195
+ scaleDecision,
196
+ scaleResult,
197
+ metrics
198
+ };
199
+ }
200
+ export {
201
+ applyInteractiveWakeUpOverride,
202
+ applyScaleCooldown,
203
+ collectTaskMetrics,
204
+ computeDesiredWorkerCount,
205
+ enqueueTaskAndEnsureCapacity,
206
+ resolveAutoscalePolicyFromEnv,
207
+ resolveWorkerPoolIdentityFromEnv
208
+ };
@@ -0,0 +1,27 @@
1
+ import type { ScaleDecision, WorkerPoolScaleResult, WorkerPoolScaler } from '@treeseed/sdk';
2
+ export type WorkerPoolScalerKind = 'noop' | 'railway';
3
+ export interface RailwayWorkerPoolScalerOptions {
4
+ apiToken?: string | null;
5
+ apiUrl?: string | null;
6
+ serviceId?: string | null;
7
+ environmentId?: string | null;
8
+ projectId?: string | null;
9
+ fetchImpl?: typeof fetch;
10
+ }
11
+ export declare class NoopWorkerPoolScaler implements WorkerPoolScaler {
12
+ scale(decision: ScaleDecision): Promise<WorkerPoolScaleResult>;
13
+ }
14
+ export declare class RailwayWorkerPoolScaler implements WorkerPoolScaler {
15
+ private readonly apiToken;
16
+ private readonly apiUrl;
17
+ private readonly serviceId;
18
+ private readonly environmentId;
19
+ private readonly projectId;
20
+ private readonly fetchImpl;
21
+ constructor(options?: RailwayWorkerPoolScalerOptions);
22
+ private railwayMutation;
23
+ private wakeRunner;
24
+ private sleepRunner;
25
+ scale(decision: ScaleDecision): Promise<WorkerPoolScaleResult>;
26
+ }
27
+ export declare function createWorkerPoolScaler(kind?: WorkerPoolScalerKind | null, options?: RailwayWorkerPoolScalerOptions): WorkerPoolScaler;
@@ -0,0 +1,127 @@
1
+ function envValue(name) {
2
+ const value = process.env[name]?.trim();
3
+ return value ? value : "";
4
+ }
5
+ class NoopWorkerPoolScaler {
6
+ async scale(decision) {
7
+ return {
8
+ applied: false,
9
+ provider: "noop",
10
+ desiredWorkers: decision.desiredWorkers,
11
+ metadata: {
12
+ reason: "scaler_unconfigured"
13
+ }
14
+ };
15
+ }
16
+ }
17
+ class RailwayWorkerPoolScaler {
18
+ apiToken;
19
+ apiUrl;
20
+ serviceId;
21
+ environmentId;
22
+ projectId;
23
+ fetchImpl;
24
+ constructor(options = {}) {
25
+ this.apiToken = options.apiToken?.trim() || envValue("RAILWAY_API_TOKEN") || null;
26
+ this.apiUrl = options.apiUrl?.trim() || envValue("TREESEED_RAILWAY_API_URL") || "https://backboard.railway.com/graphql/v2";
27
+ this.serviceId = options.serviceId?.trim() || envValue("TREESEED_RAILWAY_WORKER_SERVICE_ID") || envValue("TREESEED_WORKER_SERVICE_ID") || null;
28
+ this.environmentId = options.environmentId?.trim() || envValue("TREESEED_RAILWAY_ENVIRONMENT_ID") || null;
29
+ this.projectId = options.projectId?.trim() || envValue("TREESEED_RAILWAY_PROJECT_ID") || null;
30
+ this.fetchImpl = options.fetchImpl ?? fetch;
31
+ }
32
+ async railwayMutation(query, variables) {
33
+ if (!this.apiToken) {
34
+ throw new Error("Configure RAILWAY_API_TOKEN before waking Railway worker runners.");
35
+ }
36
+ const response = await this.fetchImpl(this.apiUrl, {
37
+ method: "POST",
38
+ headers: {
39
+ authorization: `Bearer ${this.apiToken}`,
40
+ "content-type": "application/json"
41
+ },
42
+ body: JSON.stringify({ query, variables })
43
+ });
44
+ const payload = await response.json().catch(() => ({}));
45
+ if (!response.ok || Array.isArray(payload.errors) && payload.errors.length > 0) {
46
+ throw new Error(payload.errors?.[0]?.message ?? `Railway runner request failed with ${response.status}.`);
47
+ }
48
+ return payload.data;
49
+ }
50
+ async wakeRunner() {
51
+ if (!this.serviceId || !this.environmentId) {
52
+ throw new Error("Railway runner wake requires serviceId and environmentId.");
53
+ }
54
+ const mutation = envValue("TREESEED_RAILWAY_RUNNER_WAKE_MUTATION") || `
55
+ mutation TreeseedRailwayRunnerWake($serviceId: String!, $environmentId: String!) {
56
+ serviceInstanceRedeploy(serviceId: $serviceId, environmentId: $environmentId)
57
+ }
58
+ `.trim();
59
+ return await this.railwayMutation(mutation, {
60
+ serviceId: this.serviceId,
61
+ environmentId: this.environmentId,
62
+ projectId: this.projectId
63
+ });
64
+ }
65
+ async sleepRunner() {
66
+ if (!this.serviceId || !this.environmentId) {
67
+ throw new Error("Railway runner sleep requires serviceId and environmentId.");
68
+ }
69
+ const mutation = envValue("TREESEED_RAILWAY_RUNNER_SLEEP_MUTATION") || `
70
+ mutation TreeseedRailwayRunnerSleep($serviceId: String!, $environmentId: String!) {
71
+ deploymentRemove(serviceId: $serviceId, environmentId: $environmentId)
72
+ }
73
+ `.trim();
74
+ return await this.railwayMutation(mutation, {
75
+ serviceId: this.serviceId,
76
+ environmentId: this.environmentId,
77
+ projectId: this.projectId
78
+ });
79
+ }
80
+ async scale(decision) {
81
+ const desiredWorkers = Math.max(0, Number(decision.desiredWorkers ?? 0));
82
+ const action = desiredWorkers > 0 ? "wake" : "sleep";
83
+ try {
84
+ const result = action === "wake" ? await this.wakeRunner() : await this.sleepRunner();
85
+ return {
86
+ applied: true,
87
+ provider: "railway",
88
+ desiredWorkers,
89
+ metadata: {
90
+ action,
91
+ projectId: this.projectId,
92
+ serviceId: this.serviceId,
93
+ environmentId: this.environmentId,
94
+ result
95
+ }
96
+ };
97
+ } catch (error) {
98
+ return {
99
+ applied: false,
100
+ provider: "railway",
101
+ desiredWorkers,
102
+ metadata: {
103
+ action,
104
+ reason: "named_runner_action_failed",
105
+ projectId: this.projectId,
106
+ serviceId: this.serviceId,
107
+ environmentId: this.environmentId,
108
+ error: error instanceof Error ? error.message : String(error)
109
+ }
110
+ };
111
+ }
112
+ }
113
+ }
114
+ function createWorkerPoolScaler(kind, options = {}) {
115
+ const configuredKind = envValue("TREESEED_WORKER_POOL_SCALER") || null;
116
+ const inferredKind = envValue("RAILWAY_API_TOKEN") && (envValue("TREESEED_RAILWAY_WORKER_SERVICE_ID") || envValue("TREESEED_WORKER_SERVICE_ID")) && envValue("TREESEED_RAILWAY_ENVIRONMENT_ID") ? "railway" : "noop";
117
+ const resolvedKind = kind ?? configuredKind ?? inferredKind;
118
+ if (resolvedKind === "railway") {
119
+ return new RailwayWorkerPoolScaler(options);
120
+ }
121
+ return new NoopWorkerPoolScaler();
122
+ }
123
+ export {
124
+ NoopWorkerPoolScaler,
125
+ RailwayWorkerPoolScaler,
126
+ createWorkerPoolScaler
127
+ };
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ export declare function runWorkerCycle(): Promise<{
3
+ ok: boolean;
4
+ processed: number;
5
+ idle: boolean;
6
+ reason: string;
7
+ } | {
8
+ ok: boolean;
9
+ processed: number;
10
+ idle?: undefined;
11
+ reason?: undefined;
12
+ }>;
13
+ export declare function shouldExitWorkerLoopAfterIdle(options: {
14
+ idleExitMs?: number | null;
15
+ idleSince: number | null;
16
+ now: number;
17
+ processed: number;
18
+ }): boolean;
19
+ export declare function startWorkerLoop(): Promise<void>;