@sixb/cli 0.1.17 → 0.1.19
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.
- package/README.md +7 -4
- package/dist/commands/access-token-utils.d.ts +6 -0
- package/dist/commands/access-token-utils.d.ts.map +1 -1
- package/dist/commands/api.d.ts.map +1 -1
- package/dist/commands/app.d.ts.map +1 -1
- package/dist/commands/atlas.d.ts.map +1 -1
- package/dist/commands/dev-runner.d.ts.map +1 -1
- package/dist/commands/orchestrator.d.ts.map +1 -1
- package/dist/commands/rules.d.ts.map +1 -1
- package/dist/commands/scheduler.d.ts.map +1 -1
- package/dist/commands/service-account.d.ts.map +1 -1
- package/dist/commands/token.d.ts.map +1 -1
- package/dist/commands/worker-group.d.ts.map +1 -1
- package/dist/commands/worker.d.ts.map +1 -1
- package/dist/lib/command-line.d.ts.map +1 -1
- package/dist/lib/deploy-release.d.ts.map +1 -1
- package/dist/lib/dev-watch.d.ts +2 -0
- package/dist/lib/dev-watch.d.ts.map +1 -1
- package/dist/lib/profiles.d.ts +2 -1
- package/dist/lib/profiles.d.ts.map +1 -1
- package/dist/lib/public-origin.d.ts +0 -7
- package/dist/lib/public-origin.d.ts.map +1 -1
- package/dist/lib/role-lifecycle.d.ts +3 -0
- package/dist/lib/role-lifecycle.d.ts.map +1 -0
- package/dist/lib/role-view.d.ts +22 -0
- package/dist/lib/role-view.d.ts.map +1 -0
- package/dist/lib/runtime.d.ts +31 -20
- package/dist/lib/runtime.d.ts.map +1 -1
- package/dist/lib/worker-concurrency.d.ts.map +1 -1
- package/dist/lib/worker-registry.d.ts +2 -31
- package/dist/lib/worker-registry.d.ts.map +1 -1
- package/dist/ui/index.d.ts +18 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/package.json +15 -16
- package/src/commands/access-token-utils.ts +13 -0
- package/src/commands/api.tsx +2 -1
- package/src/commands/app.tsx +29 -29
- package/src/commands/atlas.tsx +23 -27
- package/src/commands/dev-runner.tsx +22 -19
- package/src/commands/orchestrator.tsx +1 -2
- package/src/commands/rules.tsx +1 -2
- package/src/commands/scheduler.tsx +1 -2
- package/src/commands/service-account.tsx +4 -1
- package/src/commands/token.tsx +4 -1
- package/src/commands/worker-group.tsx +2 -7
- package/src/commands/worker.tsx +2 -7
- package/src/index.tsx +8 -11
- package/src/lib/command-line.ts +7 -11
- package/src/lib/deploy-release.ts +21 -4
- package/src/lib/dev-watch.ts +6 -2
- package/src/lib/profiles.ts +3 -2
- package/src/lib/public-origin.ts +0 -13
- package/src/lib/role-lifecycle.ts +34 -0
- package/src/lib/role-view.ts +50 -0
- package/src/lib/runtime.ts +51 -60
- package/src/lib/worker-concurrency.ts +15 -38
- package/src/lib/worker-registry.ts +11 -35
- package/src/ui/index.tsx +46 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { RoleStartupPanel } from "../ui"
|
|
2
|
+
import { errorMessage, errorRemediation } from "./errors"
|
|
3
|
+
|
|
4
|
+
export interface RoleView {
|
|
5
|
+
startup(loading: {
|
|
6
|
+
readonly title: string
|
|
7
|
+
readonly subtitle: string
|
|
8
|
+
readonly status: string
|
|
9
|
+
}): RoleStartupPanel
|
|
10
|
+
error(error: unknown): Promise<void>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* How a long-running role reports itself: the Ink panels in a terminal, plain lines in a log.
|
|
15
|
+
*
|
|
16
|
+
* Ink's layout engine keeps about 45 MB for the life of the process once it is imported. `atlas`
|
|
17
|
+
* and `app` run under a supervisor and serve static files, so outside a terminal they never load
|
|
18
|
+
* it.
|
|
19
|
+
*
|
|
20
|
+
* Call this before the role sets NODE_ENV. Bun compiles JSX for the mode the process started in,
|
|
21
|
+
* and React loaded after the change cannot run it: the panels then render nothing, or throw. Ink
|
|
22
|
+
* stays out of logs for a second reason: its error panel could come out empty there.
|
|
23
|
+
*/
|
|
24
|
+
export async function loadRoleView(): Promise<RoleView> {
|
|
25
|
+
if (process.stdout.isTTY) {
|
|
26
|
+
const { renderCliError, renderRoleStartup } = await import("../ui")
|
|
27
|
+
return { startup: renderRoleStartup, error: renderCliError }
|
|
28
|
+
}
|
|
29
|
+
return { startup: printRoleStartup, error: printRoleError }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function printRoleStartup(loading: {
|
|
33
|
+
readonly title: string
|
|
34
|
+
readonly subtitle: string
|
|
35
|
+
}): RoleStartupPanel {
|
|
36
|
+
console.log(`${loading.title} (${loading.subtitle})`)
|
|
37
|
+
return {
|
|
38
|
+
started(view) {
|
|
39
|
+
const items = view.items.map((item) => `${item.label} ${item.value}`).join(", ")
|
|
40
|
+
console.log(`${view.title}: ${view.name}, ${view.serviceName} ${items}`)
|
|
41
|
+
},
|
|
42
|
+
unmount() {},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function printRoleError(error: unknown): Promise<void> {
|
|
47
|
+
console.error(errorMessage(error))
|
|
48
|
+
const remediation = errorRemediation(error)
|
|
49
|
+
if (remediation) console.error(remediation)
|
|
50
|
+
}
|
package/src/lib/runtime.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { appendFileSync } from "node:fs"
|
|
2
|
-
import { ActionWorker } from "@sixb/action-worker"
|
|
3
1
|
import { AgentWorker } from "@sixb/agent-worker"
|
|
4
2
|
import { migrateStorage } from "@sixb/core"
|
|
3
|
+
import { ACTION_RUN_DRAIN_TIMEOUT_MS, drainActionRuns } from "@sixb/core/internal/actions"
|
|
5
4
|
import { flushSixbErrors } from "@sixb/core/internal/error-reporting"
|
|
6
5
|
import { PipelineRunDispatcher } from "@sixb/core/internal/pipelines"
|
|
7
6
|
import {
|
|
8
7
|
getProjectionDispatchDescriptors,
|
|
9
8
|
ProjectionRunDispatcher,
|
|
10
9
|
} from "@sixb/core/internal/projections"
|
|
10
|
+
import { setApiPublicOrigin } from "@sixb/core/internal/runtime"
|
|
11
11
|
import { SyncRunDispatcher } from "@sixb/core/internal/syncs"
|
|
12
12
|
import type { Worker } from "@sixb/core/internal/workers"
|
|
13
13
|
import { WorkflowRunDispatcher } from "@sixb/core/internal/workflows"
|
|
@@ -23,6 +23,8 @@ import { RulesWorker } from "@sixb/rules-worker"
|
|
|
23
23
|
import { SyncWorker } from "@sixb/sync-worker"
|
|
24
24
|
import { WorkflowWorker } from "@sixb/workflow-worker"
|
|
25
25
|
import type { LoadedSixbHost } from "./loadSixb"
|
|
26
|
+
import { configuredOrigin } from "./public-origin"
|
|
27
|
+
import { stopQuietly } from "./role-lifecycle"
|
|
26
28
|
import type { WorkerConcurrency } from "./worker-registry"
|
|
27
29
|
import { agentRuntimeRequired, agentWorkerRequired } from "./worker-registry"
|
|
28
30
|
|
|
@@ -32,11 +34,6 @@ export function waitForWorkerFailure(worker: Worker | null | undefined): Promise
|
|
|
32
34
|
})
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
export async function stopQuietly(stopFn: (() => Promise<void>) | undefined | null): Promise<void> {
|
|
36
|
-
if (!stopFn) return
|
|
37
|
-
await stopFn().catch(() => {})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
37
|
async function closeProvider(provider: { close?(): void | Promise<void> }): Promise<void> {
|
|
41
38
|
await provider.close?.()
|
|
42
39
|
}
|
|
@@ -44,7 +41,6 @@ async function closeProvider(provider: { close?(): void | Promise<void> }): Prom
|
|
|
44
41
|
export interface RunningSixbRuntime {
|
|
45
42
|
readonly rulesWorker: RulesWorker | null
|
|
46
43
|
readonly syncWorker: SyncWorker | null
|
|
47
|
-
readonly actionWorker: ActionWorker | null
|
|
48
44
|
readonly agentWorker: AgentWorker | null
|
|
49
45
|
readonly projectionWorker: ProjectionWorker | null
|
|
50
46
|
readonly pipelineWorker: PipelineWorker | null
|
|
@@ -57,11 +53,21 @@ export interface RunningSixbRuntime {
|
|
|
57
53
|
|
|
58
54
|
export interface StartSixbRuntimeOptions {
|
|
59
55
|
readonly cohostWorkers?: boolean
|
|
56
|
+
/**
|
|
57
|
+
* The API this process serves. Agent turns call it from their sandbox, so a co-hosted agent
|
|
58
|
+
* worker starts only once it listens and stops before it closes.
|
|
59
|
+
*/
|
|
60
|
+
readonly api?: RuntimeApiServer
|
|
60
61
|
readonly agentApiBaseUrl?: string
|
|
61
62
|
readonly agentTurnTimeoutMs?: number
|
|
62
63
|
readonly workerConcurrency?: WorkerConcurrency
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
export interface RuntimeApiServer {
|
|
67
|
+
start(): Promise<void>
|
|
68
|
+
stop(): Promise<void>
|
|
69
|
+
}
|
|
70
|
+
|
|
65
71
|
export interface RunningRulesRuntime {
|
|
66
72
|
readonly rulesWorker: RulesWorker | null
|
|
67
73
|
stop(): Promise<void>
|
|
@@ -77,6 +83,16 @@ export interface RunningOrchestratorRuntime {
|
|
|
77
83
|
stop(): Promise<void>
|
|
78
84
|
}
|
|
79
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Tell a worker process's host where the API is reachable, so the code it runs can hand out URLs
|
|
88
|
+
* a third party will fetch (`blobs.createDownloadUrl()`). The API process needs no call: the
|
|
89
|
+
* server records the origin it serves. Without one, those calls fail and name the variable.
|
|
90
|
+
*/
|
|
91
|
+
export function recordApiPublicOrigin(sixb: LoadedSixbHost, value: string | undefined): void {
|
|
92
|
+
const origin = configuredOrigin(value, "SIXB_API_PUBLIC_ORIGIN", "API public origin")
|
|
93
|
+
if (origin) setApiPublicOrigin(sixb, origin)
|
|
94
|
+
}
|
|
95
|
+
|
|
80
96
|
export async function migrateRuntimeStorage(sixb: LoadedSixbHost): Promise<void> {
|
|
81
97
|
await migrateStorage(sixb.storage, {
|
|
82
98
|
projectId: sixb.id,
|
|
@@ -92,6 +108,11 @@ export async function checkRuntimeLakeDefinitions(sixb: LoadedSixbHost): Promise
|
|
|
92
108
|
}
|
|
93
109
|
|
|
94
110
|
export async function stopSixbProviders(sixb: LoadedSixbHost): Promise<void> {
|
|
111
|
+
// Actions run inside the request that asked for them, and a client that disconnects does not stop
|
|
112
|
+
// them: refuse new ones and give those in flight, and the effects they start, time to finish
|
|
113
|
+
// before closing what they use. A run is recorded only when it ends, so one cut short leaves no
|
|
114
|
+
// record, and a retry under the same run id runs it again.
|
|
115
|
+
await stopQuietly(() => drainActionRuns(sixb, ACTION_RUN_DRAIN_TIMEOUT_MS))
|
|
95
116
|
await stopQuietly(() => flushSixbErrors(sixb))
|
|
96
117
|
await stopQuietly(() => sixb.closeConnectors())
|
|
97
118
|
await stopQuietly(() => closeProvider(sixb.queues))
|
|
@@ -186,24 +207,24 @@ export async function startOrchestratorRuntime(
|
|
|
186
207
|
*
|
|
187
208
|
* Startup order (consumers before producers):
|
|
188
209
|
* 1. RulesWorker (subscribes to ontology events)
|
|
189
|
-
* 2.
|
|
190
|
-
* 3.
|
|
191
|
-
* 4.
|
|
192
|
-
* 5.
|
|
193
|
-
* 6.
|
|
194
|
-
* 7.
|
|
195
|
-
* 8.
|
|
196
|
-
* 9.
|
|
210
|
+
* 2. ProjectionWorker (claims from queues)
|
|
211
|
+
* 3. PipelineWorker (claims from queues)
|
|
212
|
+
* 4. WorkflowWorker (claims from queues)
|
|
213
|
+
* 5. SyncWorker (claims from queues)
|
|
214
|
+
* 6. Orchestrator (subscribes to events and enqueues jobs)
|
|
215
|
+
* 7. Scheduler (emits schedule.triggered)
|
|
216
|
+
* 8. API server, when this process serves it
|
|
217
|
+
* 9. AgentWorker (claims from queues; its turns call the API)
|
|
197
218
|
*
|
|
198
219
|
* Shutdown order (producers before consumers):
|
|
199
|
-
* 1.
|
|
200
|
-
* 2.
|
|
201
|
-
* 3.
|
|
202
|
-
* 4.
|
|
203
|
-
* 5.
|
|
204
|
-
* 6.
|
|
205
|
-
* 7.
|
|
206
|
-
* 8.
|
|
220
|
+
* 1. AgentWorker (ends its turns while the API still answers them)
|
|
221
|
+
* 2. API server
|
|
222
|
+
* 3. Scheduler
|
|
223
|
+
* 4. Orchestrator (drains pending dispatches)
|
|
224
|
+
* 5. SyncWorker
|
|
225
|
+
* 6. WorkflowWorker
|
|
226
|
+
* 7. PipelineWorker
|
|
227
|
+
* 8. ProjectionWorker
|
|
207
228
|
* 9. RulesWorker (drains pending evaluations)
|
|
208
229
|
* 10. Runtime providers (connectors, broker)
|
|
209
230
|
*/
|
|
@@ -216,7 +237,6 @@ export async function startSixbRuntime(
|
|
|
216
237
|
let orchestratorRuntime: RunningOrchestratorRuntime | null = null
|
|
217
238
|
let rulesWorker: RulesWorker | null = null
|
|
218
239
|
let syncWorker: SyncWorker | null = null
|
|
219
|
-
let actionWorker: ActionWorker | null = null
|
|
220
240
|
let agentWorker: AgentWorker | null = null
|
|
221
241
|
let pipelineWorker: PipelineWorker | null = null
|
|
222
242
|
let workflowWorker: WorkflowWorker | null = null
|
|
@@ -225,14 +245,14 @@ export async function startSixbRuntime(
|
|
|
225
245
|
const warnings: string[] = []
|
|
226
246
|
|
|
227
247
|
async function stop() {
|
|
248
|
+
await stopQuietly(() => agentWorker?.stop() ?? Promise.resolve())
|
|
249
|
+
await stopQuietly(() => options.api?.stop() ?? Promise.resolve())
|
|
228
250
|
await stopQuietly(() => schedulerRuntime?.stop() ?? Promise.resolve())
|
|
229
251
|
await stopQuietly(() => orchestratorRuntime?.stop() ?? Promise.resolve())
|
|
230
252
|
await stopQuietly(() => syncWorker?.stop() ?? Promise.resolve())
|
|
231
253
|
await stopQuietly(() => workflowWorker?.stop() ?? Promise.resolve())
|
|
232
254
|
await stopQuietly(() => pipelineWorker?.stop() ?? Promise.resolve())
|
|
233
255
|
await stopQuietly(() => projectionWorker?.stop() ?? Promise.resolve())
|
|
234
|
-
await stopQuietly(() => agentWorker?.stop() ?? Promise.resolve())
|
|
235
|
-
await stopQuietly(() => actionWorker?.stop() ?? Promise.resolve())
|
|
236
256
|
await stopQuietly(() => rulesRuntime?.stop() ?? Promise.resolve())
|
|
237
257
|
await stopSixbProviders(sixb)
|
|
238
258
|
}
|
|
@@ -245,11 +265,7 @@ export async function startSixbRuntime(
|
|
|
245
265
|
rulesWorker = rulesRuntime.rulesWorker
|
|
246
266
|
|
|
247
267
|
if (options.cohostWorkers) {
|
|
248
|
-
|
|
249
|
-
actionWorker = new ActionWorker(sixb)
|
|
250
|
-
await actionWorker.start()
|
|
251
|
-
}
|
|
252
|
-
|
|
268
|
+
// Constructed here so a configuration error stops startup early; started last, below.
|
|
253
269
|
if (agentWorkerRequired(sixb)) {
|
|
254
270
|
agentWorker = new AgentWorker(sixb, {
|
|
255
271
|
apiBaseUrl: agentRuntimeRequired(sixb.definitions)
|
|
@@ -258,7 +274,6 @@ export async function startSixbRuntime(
|
|
|
258
274
|
concurrency: options.workerConcurrency?.agent,
|
|
259
275
|
turnTimeoutMs: options.agentTurnTimeoutMs,
|
|
260
276
|
})
|
|
261
|
-
await agentWorker.start()
|
|
262
277
|
}
|
|
263
278
|
|
|
264
279
|
const projectionCount = sixb.definitions.projections.list().length
|
|
@@ -294,6 +309,9 @@ export async function startSixbRuntime(
|
|
|
294
309
|
|
|
295
310
|
schedulerRuntime = await startSchedulerRuntime(sixb)
|
|
296
311
|
}
|
|
312
|
+
|
|
313
|
+
await options.api?.start()
|
|
314
|
+
await agentWorker?.start()
|
|
297
315
|
} catch (error) {
|
|
298
316
|
await stop()
|
|
299
317
|
throw error
|
|
@@ -303,7 +321,6 @@ export async function startSixbRuntime(
|
|
|
303
321
|
const workers: Worker[] = []
|
|
304
322
|
if (rulesWorker) workers.push(rulesWorker)
|
|
305
323
|
if (syncWorker) workers.push(syncWorker)
|
|
306
|
-
if (actionWorker) workers.push(actionWorker)
|
|
307
324
|
if (agentWorker) workers.push(agentWorker)
|
|
308
325
|
if (projectionWorker) workers.push(projectionWorker)
|
|
309
326
|
if (pipelineWorker) workers.push(pipelineWorker)
|
|
@@ -315,7 +332,6 @@ export async function startSixbRuntime(
|
|
|
315
332
|
return {
|
|
316
333
|
rulesWorker,
|
|
317
334
|
syncWorker,
|
|
318
|
-
actionWorker,
|
|
319
335
|
agentWorker,
|
|
320
336
|
projectionWorker,
|
|
321
337
|
pipelineWorker,
|
|
@@ -345,28 +361,3 @@ function requireAgentApiBaseUrl(value: string | undefined): string {
|
|
|
345
361
|
}
|
|
346
362
|
return trimmed
|
|
347
363
|
}
|
|
348
|
-
|
|
349
|
-
export async function runUntilSignal(onShutdown: () => Promise<void>): Promise<void> {
|
|
350
|
-
// Test-only readiness hook: e2e tests detect that a long-running role finished
|
|
351
|
-
// starting by watching for this marker. It avoids depending on Ink's rendered
|
|
352
|
-
// output, which is suppressed when stdout is not a TTY (e.g. under CI). Unset in
|
|
353
|
-
// production, so this is a no-op there.
|
|
354
|
-
const readyLog = process.env.SIXB_CLI_TEST_READY_LOG
|
|
355
|
-
if (readyLog) {
|
|
356
|
-
appendFileSync(readyLog, `${JSON.stringify({ type: "role:ready" })}\n`, "utf-8")
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
await new Promise<void>((resolvePromise) => {
|
|
360
|
-
let shuttingDown = false
|
|
361
|
-
|
|
362
|
-
const shutdown = async () => {
|
|
363
|
-
if (shuttingDown) return
|
|
364
|
-
shuttingDown = true
|
|
365
|
-
await onShutdown()
|
|
366
|
-
resolvePromise()
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
process.once("SIGINT", shutdown)
|
|
370
|
-
process.once("SIGTERM", shutdown)
|
|
371
|
-
})
|
|
372
|
-
}
|
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { WORKER_TYPES, type WorkerConcurrency, type WorkerType } from "./worker-registry"
|
|
2
|
+
|
|
3
|
+
/** The environment variable that sets each worker type's concurrency. */
|
|
4
|
+
const ENVIRONMENT_VARIABLES = {
|
|
5
|
+
sync: "SIXB_SYNC_WORKER_CONCURRENCY",
|
|
6
|
+
agent: "SIXB_AGENT_WORKER_CONCURRENCY",
|
|
7
|
+
pipeline: "SIXB_PIPELINE_WORKER_CONCURRENCY",
|
|
8
|
+
projection: "SIXB_PROJECTION_WORKER_CONCURRENCY",
|
|
9
|
+
workflow: "SIXB_WORKFLOW_WORKER_CONCURRENCY",
|
|
10
|
+
} as const satisfies Record<WorkerType, string>
|
|
8
11
|
|
|
9
12
|
/** Resolve the scalar concurrency accepted by `sixb worker <type>`. */
|
|
10
13
|
export function resolveSingleWorkerConcurrency(
|
|
11
14
|
workerType: WorkerType,
|
|
12
15
|
value: string | undefined
|
|
13
16
|
): WorkerConcurrency {
|
|
14
|
-
const
|
|
15
|
-
if (!isConfigurableWorkerType(workerType)) {
|
|
16
|
-
if (value !== undefined || nonblank(process.env[definition.environmentVariable])) {
|
|
17
|
-
throw fixedActionConcurrency()
|
|
18
|
-
}
|
|
19
|
-
return {}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const environmentVariable = definition.environmentVariable
|
|
17
|
+
const environmentVariable = ENVIRONMENT_VARIABLES[workerType]
|
|
23
18
|
const configured = value?.trim() ?? nonblank(process.env[environmentVariable])
|
|
24
19
|
if (configured === undefined) return {}
|
|
25
20
|
|
|
@@ -33,19 +28,12 @@ export function resolveSingleWorkerConcurrency(
|
|
|
33
28
|
export function resolveWorkerConcurrency(values: readonly string[] = []): WorkerConcurrency {
|
|
34
29
|
const overrides = values.map(parseWorkerConcurrencyEntry)
|
|
35
30
|
const overriddenWorkerTypes = new Set(overrides.map((entry) => entry.workerType))
|
|
36
|
-
const resolved: Partial<Record<
|
|
31
|
+
const resolved: Partial<Record<WorkerType, number>> = {}
|
|
37
32
|
|
|
38
33
|
for (const workerType of WORKER_TYPES) {
|
|
39
|
-
const definition = WORKER_CONCURRENCY_CONFIG[workerType]
|
|
40
|
-
if (!isConfigurableWorkerType(workerType)) {
|
|
41
|
-
if (nonblank(process.env[definition.environmentVariable])) {
|
|
42
|
-
throw fixedActionConcurrency()
|
|
43
|
-
}
|
|
44
|
-
continue
|
|
45
|
-
}
|
|
46
34
|
if (overriddenWorkerTypes.has(workerType)) continue
|
|
47
35
|
|
|
48
|
-
const environmentVariable =
|
|
36
|
+
const environmentVariable = ENVIRONMENT_VARIABLES[workerType]
|
|
49
37
|
const configured = nonblank(process.env[environmentVariable])
|
|
50
38
|
if (configured !== undefined) {
|
|
51
39
|
resolved[workerType] = parseConcurrency(configured, environmentVariable)
|
|
@@ -60,7 +48,7 @@ export function resolveWorkerConcurrency(values: readonly string[] = []): Worker
|
|
|
60
48
|
}
|
|
61
49
|
|
|
62
50
|
function parseWorkerConcurrencyEntry(value: string): {
|
|
63
|
-
readonly workerType:
|
|
51
|
+
readonly workerType: WorkerType
|
|
64
52
|
readonly concurrency: number
|
|
65
53
|
} {
|
|
66
54
|
const separator = value.indexOf("=")
|
|
@@ -72,12 +60,9 @@ function parseWorkerConcurrencyEntry(value: string): {
|
|
|
72
60
|
const configured = value.slice(separator + 1).trim()
|
|
73
61
|
if (!isWorkerType(workerType)) {
|
|
74
62
|
throw new Error(
|
|
75
|
-
`[SixbCLI] Unknown worker concurrency type '${workerType || value}'. Available: ${WORKER_TYPES.
|
|
63
|
+
`[SixbCLI] Unknown worker concurrency type '${workerType || value}'. Available: ${WORKER_TYPES.join(", ")}.`
|
|
76
64
|
)
|
|
77
65
|
}
|
|
78
|
-
if (!isConfigurableWorkerType(workerType)) {
|
|
79
|
-
throw fixedActionConcurrency()
|
|
80
|
-
}
|
|
81
66
|
|
|
82
67
|
return {
|
|
83
68
|
workerType,
|
|
@@ -105,10 +90,6 @@ function isWorkerType(value: string): value is WorkerType {
|
|
|
105
90
|
return WORKER_TYPES.some((workerType) => workerType === value)
|
|
106
91
|
}
|
|
107
92
|
|
|
108
|
-
function isConfigurableWorkerType(value: WorkerType): value is ConfigurableWorkerType {
|
|
109
|
-
return WORKER_CONCURRENCY_CONFIG[value].configurable
|
|
110
|
-
}
|
|
111
|
-
|
|
112
93
|
function invalidConcurrency(value: string, source: string): Error {
|
|
113
94
|
return new Error(
|
|
114
95
|
`[SixbCLI] Invalid worker concurrency '${value}'. Use a positive integer with ${source}.`
|
|
@@ -121,7 +102,3 @@ function invalidWorkerConcurrencyEntry(value: string): Error {
|
|
|
121
102
|
"--concurrency agent=4 --concurrency sync=2."
|
|
122
103
|
)
|
|
123
104
|
}
|
|
124
|
-
|
|
125
|
-
function fixedActionConcurrency(): Error {
|
|
126
|
-
return new Error("[SixbCLI] Action worker concurrency is fixed at 1 and cannot be configured.")
|
|
127
|
-
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ActionWorker } from "@sixb/action-worker"
|
|
2
1
|
import { AgentWorker } from "@sixb/agent-worker"
|
|
3
2
|
import type { Worker } from "@sixb/core/internal/workers"
|
|
4
3
|
import { PipelineWorker } from "@sixb/pipeline-worker"
|
|
@@ -9,36 +8,11 @@ import { SixbCliError } from "./errors"
|
|
|
9
8
|
import type { LoadedSixbHost } from "./loadSixb"
|
|
10
9
|
import { configuredOrigin } from "./public-origin"
|
|
11
10
|
|
|
12
|
-
export const WORKER_TYPES = [
|
|
13
|
-
"sync",
|
|
14
|
-
"action",
|
|
15
|
-
"agent",
|
|
16
|
-
"pipeline",
|
|
17
|
-
"projection",
|
|
18
|
-
"workflow",
|
|
19
|
-
] as const
|
|
11
|
+
export const WORKER_TYPES = ["sync", "agent", "pipeline", "projection", "workflow"] as const
|
|
20
12
|
|
|
21
13
|
export type WorkerType = (typeof WORKER_TYPES)[number]
|
|
22
14
|
|
|
23
|
-
export
|
|
24
|
-
sync: { configurable: true, environmentVariable: "SIXB_SYNC_WORKER_CONCURRENCY" },
|
|
25
|
-
action: { configurable: false, environmentVariable: "SIXB_ACTION_WORKER_CONCURRENCY" },
|
|
26
|
-
agent: { configurable: true, environmentVariable: "SIXB_AGENT_WORKER_CONCURRENCY" },
|
|
27
|
-
pipeline: { configurable: true, environmentVariable: "SIXB_PIPELINE_WORKER_CONCURRENCY" },
|
|
28
|
-
projection: { configurable: true, environmentVariable: "SIXB_PROJECTION_WORKER_CONCURRENCY" },
|
|
29
|
-
workflow: { configurable: true, environmentVariable: "SIXB_WORKFLOW_WORKER_CONCURRENCY" },
|
|
30
|
-
} as const satisfies Record<
|
|
31
|
-
WorkerType,
|
|
32
|
-
{ readonly configurable: boolean; readonly environmentVariable: string }
|
|
33
|
-
>
|
|
34
|
-
|
|
35
|
-
export type ConfigurableWorkerType = {
|
|
36
|
-
[Type in WorkerType]: (typeof WORKER_CONCURRENCY_CONFIG)[Type]["configurable"] extends true
|
|
37
|
-
? Type
|
|
38
|
-
: never
|
|
39
|
-
}[WorkerType]
|
|
40
|
-
|
|
41
|
-
export type WorkerConcurrency = Readonly<Partial<Record<ConfigurableWorkerType, number>>>
|
|
15
|
+
export type WorkerConcurrency = Readonly<Partial<Record<WorkerType, number>>>
|
|
42
16
|
export type QueueWorkerProcess = Worker & { readonly concurrency: number }
|
|
43
17
|
|
|
44
18
|
export interface WorkerCreationOptions {
|
|
@@ -70,9 +44,6 @@ const workerFactories: Record<WorkerType, WorkerFactory> = {
|
|
|
70
44
|
create: (sixb, options) =>
|
|
71
45
|
new SyncWorker(sixb, { concurrency: options.workerConcurrency?.sync }),
|
|
72
46
|
},
|
|
73
|
-
action: {
|
|
74
|
-
create: (sixb) => new ActionWorker(sixb),
|
|
75
|
-
},
|
|
76
47
|
agent: {
|
|
77
48
|
create: (sixb, options) =>
|
|
78
49
|
new AgentWorker(sixb, {
|
|
@@ -117,6 +88,7 @@ export function resolveWorkerTypeToStart(requestedWorker?: string): WorkerType {
|
|
|
117
88
|
throw new Error(`[SixbWorker] Usage: sixb worker <${knownWorkers().replaceAll(", ", "|")}>`)
|
|
118
89
|
}
|
|
119
90
|
|
|
91
|
+
if (requestedWorker === "action") throw removedActionWorker()
|
|
120
92
|
if (!isWorkerType(requestedWorker)) {
|
|
121
93
|
throw new Error(
|
|
122
94
|
`[SixbWorker] Unknown worker '${requestedWorker}'. Available: ${knownWorkers()}`
|
|
@@ -126,6 +98,14 @@ export function resolveWorkerTypeToStart(requestedWorker?: string): WorkerType {
|
|
|
126
98
|
return requestedWorker
|
|
127
99
|
}
|
|
128
100
|
|
|
101
|
+
/** `action` was a worker type until Actions ran in the process that requests them. */
|
|
102
|
+
function removedActionWorker(): Error {
|
|
103
|
+
return new Error(
|
|
104
|
+
"[SixbWorker] 'action' is no longer a worker type: Actions run in the process that requests " +
|
|
105
|
+
"them (API, workflows, syncs). Remove it from the command."
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
129
109
|
/**
|
|
130
110
|
* Why this worker cannot be constructed with these options, or `null` when it can. Exported
|
|
131
111
|
* for `sixb worker`, which has to answer this before it migrates storage.
|
|
@@ -203,10 +183,6 @@ export function resolveRegisteredWorkerTypes(sixb: LoadedSixbHost): readonly Wor
|
|
|
203
183
|
workerTypes.push("projection")
|
|
204
184
|
}
|
|
205
185
|
|
|
206
|
-
if (sixb.definitions.actions.list().length > 0) {
|
|
207
|
-
workerTypes.push("action")
|
|
208
|
-
}
|
|
209
|
-
|
|
210
186
|
if (agentWorkerRequired(sixb)) {
|
|
211
187
|
workerTypes.push("agent")
|
|
212
188
|
}
|
package/src/ui/index.tsx
CHANGED
|
@@ -44,6 +44,52 @@ export async function renderCliError(
|
|
|
44
44
|
)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// The entrypoint and the browser roles render through these rather than JSX of their own: a module
|
|
48
|
+
// with JSX loads React as soon as it is evaluated, and `atlas` and `app` load neither React nor
|
|
49
|
+
// Ink outside a terminal.
|
|
50
|
+
|
|
51
|
+
export async function renderVersion(version: string): Promise<void> {
|
|
52
|
+
await renderStatic(<VersionView version={version} />)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Root or command help, after the usage error that led to it when there is one. */
|
|
56
|
+
export async function renderHelp(help: CliHelp, usageError?: string): Promise<void> {
|
|
57
|
+
await renderStatic(
|
|
58
|
+
help.path.length === 0 ? (
|
|
59
|
+
<HelpView errorMessage={usageError} />
|
|
60
|
+
) : (
|
|
61
|
+
<CommandHelpView help={help} errorMessage={usageError} />
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface RoleStartupPanel {
|
|
67
|
+
started(view: {
|
|
68
|
+
readonly title: string
|
|
69
|
+
readonly name: string
|
|
70
|
+
readonly serviceName: string
|
|
71
|
+
readonly items: KeyValueItem[]
|
|
72
|
+
}): void
|
|
73
|
+
unmount(): void
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A long-running role's loading panel, replaced by its started view. */
|
|
77
|
+
export function renderRoleStartup(loading: {
|
|
78
|
+
readonly title: string
|
|
79
|
+
readonly subtitle: string
|
|
80
|
+
readonly status: string
|
|
81
|
+
}): RoleStartupPanel {
|
|
82
|
+
const app = renderPersistent(<LoadingView {...loading} />)
|
|
83
|
+
return {
|
|
84
|
+
started(view) {
|
|
85
|
+
app.rerender(<RoleView {...view} />)
|
|
86
|
+
},
|
|
87
|
+
unmount() {
|
|
88
|
+
app.unmount()
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
47
93
|
function SectionTitle({ children }: { children: React.ReactNode }) {
|
|
48
94
|
return (
|
|
49
95
|
<Text color="cyan" bold>
|