@sixb/cli 0.1.1 → 0.1.3
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 +5 -2
- package/dist/commands/api.d.ts.map +1 -1
- package/dist/commands/dev.d.ts +2 -0
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/worker-group.d.ts +2 -0
- package/dist/commands/worker-group.d.ts.map +1 -1
- package/dist/commands/worker.d.ts +2 -0
- package/dist/commands/worker.d.ts.map +1 -1
- package/dist/lib/agent-turn-timeout.d.ts +6 -0
- package/dist/lib/agent-turn-timeout.d.ts.map +1 -0
- package/dist/lib/health.d.ts +3 -3
- package/dist/lib/health.d.ts.map +1 -1
- package/dist/lib/loadSixb.d.ts +3 -48
- package/dist/lib/loadSixb.d.ts.map +1 -1
- package/dist/lib/production.d.ts +2 -2
- package/dist/lib/production.d.ts.map +1 -1
- package/dist/lib/runtime.d.ts +11 -8
- package/dist/lib/runtime.d.ts.map +1 -1
- package/dist/lib/shareable-providers.d.ts +3 -3
- package/dist/lib/shareable-providers.d.ts.map +1 -1
- package/dist/lib/storage-migration.d.ts +2 -2
- package/dist/lib/storage-migration.d.ts.map +1 -1
- package/dist/lib/worker-concurrency.d.ts +9 -0
- package/dist/lib/worker-concurrency.d.ts.map +1 -0
- package/dist/lib/worker-registry.d.ts +41 -4
- package/dist/lib/worker-registry.d.ts.map +1 -1
- package/dist/ui/index.d.ts +12 -16
- package/dist/ui/index.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/commands/api.tsx +9 -4
- package/src/commands/app.tsx +2 -2
- package/src/commands/atlas.tsx +2 -2
- package/src/commands/check.tsx +1 -1
- package/src/commands/dev.tsx +38 -16
- package/src/commands/orchestrator.tsx +2 -2
- package/src/commands/rules.tsx +2 -2
- package/src/commands/scheduler.tsx +2 -2
- package/src/commands/worker-group.tsx +18 -6
- package/src/commands/worker.tsx +20 -5
- package/src/index.tsx +19 -3
- package/src/lib/agent-turn-timeout.ts +40 -0
- package/src/lib/health.ts +8 -8
- package/src/lib/loadSixb.ts +70 -105
- package/src/lib/production.ts +2 -2
- package/src/lib/runtime.ts +59 -42
- package/src/lib/shareable-providers.ts +6 -6
- package/src/lib/storage-migration.ts +3 -3
- package/src/lib/worker-concurrency.ts +127 -0
- package/src/lib/worker-registry.ts +68 -27
- package/src/ui/index.tsx +35 -71
package/src/lib/loadSixb.ts
CHANGED
|
@@ -1,115 +1,33 @@
|
|
|
1
1
|
import { pathToFileURL } from "node:url"
|
|
2
|
-
import type {
|
|
3
|
-
ActionDefinition,
|
|
4
|
-
Broker,
|
|
5
|
-
ConnectorAdapter,
|
|
6
|
-
ConnectorClient,
|
|
7
|
-
ConnectorDefinition,
|
|
8
|
-
DatasetDefinition,
|
|
9
|
-
LinkProjectionDefinition,
|
|
10
|
-
ObjectProjectionDefinition,
|
|
11
|
-
OntologyMaintenanceHandle,
|
|
12
|
-
OntologyOperationalStatus,
|
|
13
|
-
PipelineDefinition,
|
|
14
|
-
ProjectionDefinition,
|
|
15
|
-
RuleDefinition,
|
|
16
|
-
ScheduleDefinition,
|
|
17
|
-
SixbReadiness,
|
|
18
|
-
SixbRuntimeContext,
|
|
19
|
-
SyncDefinition,
|
|
20
|
-
TelemetryProjectionDefinition,
|
|
21
|
-
} from "@sixb/core"
|
|
22
|
-
import type { AgentsRuntime } from "@sixb/core/internal/agents"
|
|
23
|
-
import type { AuthRuntime } from "@sixb/core/internal/auth"
|
|
24
|
-
import type { WorkflowsRuntime } from "@sixb/core/internal/workflows"
|
|
25
|
-
import type { ObjectRow } from "@sixb/core/storage"
|
|
2
|
+
import type { SixbHostView } from "@sixb/core"
|
|
26
3
|
|
|
27
|
-
export
|
|
28
|
-
readonly id: string
|
|
29
|
-
readonly broker: Broker
|
|
30
|
-
readonly auth: AuthRuntime
|
|
31
|
-
listObjectTypes(): readonly unknown[]
|
|
32
|
-
listActions(): readonly ActionDefinition[]
|
|
33
|
-
getActionById(actionId: string): ActionDefinition | null
|
|
34
|
-
listSyncs(): readonly SyncDefinition[]
|
|
35
|
-
listPipelines(): readonly PipelineDefinition[]
|
|
36
|
-
getPipelineById(pipelineId: string): PipelineDefinition | null
|
|
37
|
-
listSchedules(): readonly ScheduleDefinition[]
|
|
38
|
-
readonly workflows: WorkflowsRuntime
|
|
39
|
-
readonly agents: AgentsRuntime
|
|
40
|
-
listObjectProjections(): readonly ObjectProjectionDefinition[]
|
|
41
|
-
listLinkProjections(): readonly LinkProjectionDefinition[]
|
|
42
|
-
listTelemetryProjections(): readonly TelemetryProjectionDefinition[]
|
|
43
|
-
listDatasets(): readonly DatasetDefinition[]
|
|
44
|
-
listRules(): readonly RuleDefinition[]
|
|
45
|
-
getDatasetById(datasetId: string): DatasetDefinition | null
|
|
46
|
-
getProjectionById(projectionId: string): ProjectionDefinition | null
|
|
47
|
-
getSyncById(syncId: string): SyncDefinition | null
|
|
48
|
-
getRuleById(ruleId: string): RuleDefinition | null
|
|
49
|
-
listSubTypes(objectTypeId: string): string[]
|
|
50
|
-
connector<TAdapter extends ConnectorAdapter>(
|
|
51
|
-
definition: ConnectorDefinition<string, TAdapter>
|
|
52
|
-
): Promise<ConnectorClient<TAdapter>>
|
|
53
|
-
startScheduler(): Promise<void>
|
|
54
|
-
stopScheduler(): Promise<void>
|
|
55
|
-
startOntologyMaintenance(): Promise<OntologyMaintenanceHandle>
|
|
56
|
-
getOntologyOperationalStatus(): OntologyOperationalStatus
|
|
57
|
-
checkReadiness(): Promise<SixbReadiness>
|
|
58
|
-
disconnectConnectors(): Promise<void>
|
|
59
|
-
closeLogger(): Promise<void>
|
|
60
|
-
closeBroker(): Promise<void>
|
|
61
|
-
list(params: {
|
|
62
|
-
objectTypeIds?: readonly string[]
|
|
63
|
-
limit?: number
|
|
64
|
-
offset?: number
|
|
65
|
-
}): Promise<{ total: number; hasMore: boolean; objects: ObjectRow[] }>
|
|
66
|
-
}
|
|
4
|
+
export type LoadedSixbHost = SixbHostView
|
|
67
5
|
|
|
68
6
|
function isPromiseLike(value: unknown): value is PromiseLike<unknown> {
|
|
69
7
|
return !!value && typeof value === "object" && "then" in value
|
|
70
8
|
}
|
|
71
9
|
|
|
72
|
-
const
|
|
73
|
-
"
|
|
74
|
-
"actionRegistry",
|
|
10
|
+
const REQUIRED_HOST_PROPERTIES = [
|
|
11
|
+
"definitions",
|
|
75
12
|
"events",
|
|
13
|
+
"logging",
|
|
76
14
|
"broker",
|
|
77
15
|
"storage",
|
|
78
16
|
"lakeStorage",
|
|
79
17
|
"blobStorage",
|
|
80
18
|
"queues",
|
|
81
19
|
"auth",
|
|
82
|
-
"
|
|
83
|
-
] as const
|
|
84
|
-
|
|
85
|
-
const REQUIRED_DEFINITION_METHODS = [
|
|
86
|
-
"listObjectTypes",
|
|
87
|
-
"listSubTypes",
|
|
88
|
-
"listActions",
|
|
89
|
-
"getActionById",
|
|
90
|
-
"listSyncs",
|
|
91
|
-
"listPipelines",
|
|
92
|
-
"getPipelineById",
|
|
93
|
-
"listSchedules",
|
|
94
|
-
"listObjectProjections",
|
|
95
|
-
"listLinkProjections",
|
|
96
|
-
"listTelemetryProjections",
|
|
97
|
-
"listDatasets",
|
|
98
|
-
"listRules",
|
|
99
|
-
"getDatasetById",
|
|
100
|
-
"getProjectionById",
|
|
101
|
-
"getSyncById",
|
|
102
|
-
"getRuleById",
|
|
20
|
+
"scheduler",
|
|
103
21
|
] as const
|
|
104
22
|
|
|
105
23
|
const REQUIRED_LIFECYCLE_METHODS = [
|
|
106
|
-
"
|
|
107
|
-
"stopScheduler",
|
|
24
|
+
"withScope",
|
|
108
25
|
"startOntologyMaintenance",
|
|
109
26
|
"getOntologyOperationalStatus",
|
|
110
27
|
"checkReadiness",
|
|
111
|
-
"disconnectConnectors",
|
|
112
28
|
"closeLogger",
|
|
29
|
+
"closeConnectors",
|
|
30
|
+
"closeBlobs",
|
|
113
31
|
"closeBroker",
|
|
114
32
|
] as const
|
|
115
33
|
|
|
@@ -124,52 +42,99 @@ function hasProperties(
|
|
|
124
42
|
return properties.every((property) => property in value)
|
|
125
43
|
}
|
|
126
44
|
|
|
127
|
-
function hasMethods(value:
|
|
128
|
-
|
|
45
|
+
function hasMethods(value: unknown, methods: readonly PropertyKey[]): boolean {
|
|
46
|
+
if (!isRecord(value) && typeof value !== "function") return false
|
|
47
|
+
const candidate = value as Record<PropertyKey, unknown>
|
|
48
|
+
return methods.every((method) => typeof candidate[method] === "function")
|
|
129
49
|
}
|
|
130
50
|
|
|
131
|
-
function
|
|
132
|
-
|
|
51
|
+
function hasDefinitionCatalogs(value: Record<PropertyKey, unknown>): boolean {
|
|
52
|
+
if (!isRecord(value.definitions)) return false
|
|
53
|
+
const definitions = value.definitions
|
|
54
|
+
return (
|
|
55
|
+
isRecord(definitions.ontology) &&
|
|
56
|
+
hasMethods(definitions.ontology, ["listObjectTypes", "getObjectTypeById"]) &&
|
|
57
|
+
isRecord(definitions.actions) &&
|
|
58
|
+
hasMethods(definitions.actions, ["list", "getById", "listGlobal", "listForType"]) &&
|
|
59
|
+
isRecord(definitions.connectors) &&
|
|
60
|
+
hasMethods(definitions.connectors, ["list", "getById"]) &&
|
|
61
|
+
isRecord(definitions.datasets) &&
|
|
62
|
+
hasMethods(definitions.datasets, ["list", "getById"]) &&
|
|
63
|
+
isRecord(definitions.syncs) &&
|
|
64
|
+
hasMethods(definitions.syncs, ["list", "getById"]) &&
|
|
65
|
+
isRecord(definitions.pipelines) &&
|
|
66
|
+
hasMethods(definitions.pipelines, ["list", "getById"]) &&
|
|
67
|
+
isRecord(definitions.schedules) &&
|
|
68
|
+
hasMethods(definitions.schedules, ["list", "getById"]) &&
|
|
69
|
+
isRecord(definitions.rules) &&
|
|
70
|
+
hasMethods(definitions.rules, ["list", "getById"]) &&
|
|
71
|
+
isRecord(definitions.projections) &&
|
|
72
|
+
hasMethods(definitions.projections, [
|
|
73
|
+
"list",
|
|
74
|
+
"listObjects",
|
|
75
|
+
"listLinks",
|
|
76
|
+
"listTelemetry",
|
|
77
|
+
"getById",
|
|
78
|
+
]) &&
|
|
79
|
+
isRecord(definitions.workflows) &&
|
|
80
|
+
hasMethods(definitions.workflows, ["list", "getById"]) &&
|
|
81
|
+
isRecord(definitions.agents) &&
|
|
82
|
+
hasMethods(definitions.agents, ["list", "getById"]) &&
|
|
83
|
+
isRecord(definitions.security) &&
|
|
84
|
+
hasMethods(definitions.security, [
|
|
85
|
+
"listGroups",
|
|
86
|
+
"getGroupById",
|
|
87
|
+
"listRoles",
|
|
88
|
+
"getRoleById",
|
|
89
|
+
"listResolvedRoles",
|
|
90
|
+
"listMembershipPolicies",
|
|
91
|
+
"getMembershipPolicyById",
|
|
92
|
+
])
|
|
93
|
+
)
|
|
133
94
|
}
|
|
134
95
|
|
|
135
|
-
function
|
|
96
|
+
function isSixbHost(value: unknown): value is LoadedSixbHost {
|
|
136
97
|
if (!isRecord(value)) return false
|
|
137
98
|
|
|
138
99
|
return (
|
|
139
100
|
typeof value.id === "string" &&
|
|
140
101
|
typeof value.projectId === "string" &&
|
|
141
|
-
hasProperties(value,
|
|
142
|
-
hasMethods(value, REQUIRED_DEFINITION_METHODS) &&
|
|
102
|
+
hasProperties(value, REQUIRED_HOST_PROPERTIES) &&
|
|
143
103
|
hasMethods(value, REQUIRED_LIFECYCLE_METHODS) &&
|
|
144
|
-
|
|
145
|
-
|
|
104
|
+
hasDefinitionCatalogs(value) &&
|
|
105
|
+
isRecord(value.logging) &&
|
|
106
|
+
hasMethods(value.logging, ["startExecution", "read", "tail"]) &&
|
|
107
|
+
isRecord(value.blobStorage) &&
|
|
108
|
+
hasMethods(value.blobStorage, ["put", "open", "stat"]) &&
|
|
109
|
+
isRecord(value.scheduler) &&
|
|
110
|
+
hasMethods(value.scheduler, ["start", "stop"])
|
|
146
111
|
)
|
|
147
112
|
}
|
|
148
113
|
|
|
149
|
-
export async function loadSixbFromEntry(entry: string): Promise<
|
|
114
|
+
export async function loadSixbFromEntry(entry: string): Promise<LoadedSixbHost> {
|
|
150
115
|
const module = (await import(pathToFileURL(entry).href)) as Record<string, unknown>
|
|
151
116
|
const candidate = module.sixb ?? module.default
|
|
152
117
|
|
|
153
|
-
if (
|
|
118
|
+
if (isSixbHost(candidate)) {
|
|
154
119
|
return candidate
|
|
155
120
|
}
|
|
156
121
|
|
|
157
122
|
if (typeof candidate === "function") {
|
|
158
123
|
const created = (candidate as () => unknown)()
|
|
159
124
|
const resolved = isPromiseLike(created) ? await created : created
|
|
160
|
-
if (
|
|
125
|
+
if (isSixbHost(resolved)) {
|
|
161
126
|
return resolved
|
|
162
127
|
}
|
|
163
128
|
}
|
|
164
129
|
|
|
165
130
|
if (isPromiseLike(candidate)) {
|
|
166
131
|
const resolved = await candidate
|
|
167
|
-
if (
|
|
132
|
+
if (isSixbHost(resolved)) {
|
|
168
133
|
return resolved
|
|
169
134
|
}
|
|
170
135
|
}
|
|
171
136
|
|
|
172
137
|
throw new Error(
|
|
173
|
-
"Could not load Sixb
|
|
138
|
+
"Could not load a Sixb host from entry. Export `sixb` (or default) as a SixbHost or Promise<SixbHost>."
|
|
174
139
|
)
|
|
175
140
|
}
|
package/src/lib/production.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { stat } from "node:fs/promises"
|
|
2
2
|
import { basename, dirname, resolve, sep } from "node:path"
|
|
3
|
-
import { type
|
|
3
|
+
import { type LoadedSixbHost, loadSixbFromEntry } from "./loadSixb"
|
|
4
4
|
import type { ProductionRole } from "./production-roles"
|
|
5
5
|
import { assertShareableProviders } from "./shareable-providers"
|
|
6
6
|
|
|
@@ -36,7 +36,7 @@ export async function resolveRuntimeEntry(options: RuntimeEntryOptions = {}): Pr
|
|
|
36
36
|
|
|
37
37
|
export async function loadProductionSixb(
|
|
38
38
|
options: ProductionRuntimeOptions
|
|
39
|
-
): Promise<{ entry: string; sixb:
|
|
39
|
+
): Promise<{ entry: string; sixb: LoadedSixbHost; projectRoot: string; buildOutdir: string }> {
|
|
40
40
|
const entry = await resolveRuntimeEntry(options)
|
|
41
41
|
const sixb = await loadSixbFromEntry(entry)
|
|
42
42
|
assertShareableProviders(sixb, options.role)
|
package/src/lib/runtime.ts
CHANGED
|
@@ -3,8 +3,14 @@ import { ActionWorker } from "@sixb/action-worker"
|
|
|
3
3
|
import { AgentWorker } from "@sixb/agent-worker"
|
|
4
4
|
import { migrateStorage } from "@sixb/core"
|
|
5
5
|
import { flushSixbErrors } from "@sixb/core/internal/error-reporting"
|
|
6
|
-
import {
|
|
6
|
+
import { PipelineRunDispatcher } from "@sixb/core/internal/pipelines"
|
|
7
|
+
import {
|
|
8
|
+
getProjectionDispatchDescriptors,
|
|
9
|
+
ProjectionRunDispatcher,
|
|
10
|
+
} from "@sixb/core/internal/projections"
|
|
11
|
+
import { SyncRunDispatcher } from "@sixb/core/internal/syncs"
|
|
7
12
|
import type { Worker } from "@sixb/core/internal/workers"
|
|
13
|
+
import { WorkflowRunDispatcher } from "@sixb/core/internal/workflows"
|
|
8
14
|
import { assertLakeDatasetDefinitionsCompatible } from "@sixb/core/lake-storage"
|
|
9
15
|
import {
|
|
10
16
|
type CompileRoutesDiagnostic,
|
|
@@ -16,7 +22,8 @@ import { ProjectionWorker } from "@sixb/projection-worker"
|
|
|
16
22
|
import { RulesWorker } from "@sixb/rules-worker"
|
|
17
23
|
import { SyncWorker } from "@sixb/sync-worker"
|
|
18
24
|
import { WorkflowWorker } from "@sixb/workflow-worker"
|
|
19
|
-
import type {
|
|
25
|
+
import type { LoadedSixbHost } from "./loadSixb"
|
|
26
|
+
import type { WorkerConcurrency } from "./worker-registry"
|
|
20
27
|
|
|
21
28
|
export function waitForWorkerFailure(worker: Worker | null | undefined): Promise<never> {
|
|
22
29
|
return new Promise<never>((_resolve, reject) => {
|
|
@@ -50,6 +57,8 @@ export interface RunningSixbRuntime {
|
|
|
50
57
|
export interface StartSixbRuntimeOptions {
|
|
51
58
|
readonly cohostWorkers?: boolean
|
|
52
59
|
readonly agentApiBaseUrl?: string
|
|
60
|
+
readonly agentTurnTimeoutMs?: number
|
|
61
|
+
readonly workerConcurrency?: WorkerConcurrency
|
|
53
62
|
}
|
|
54
63
|
|
|
55
64
|
export interface RunningRulesRuntime {
|
|
@@ -67,20 +76,20 @@ export interface RunningOrchestratorRuntime {
|
|
|
67
76
|
stop(): Promise<void>
|
|
68
77
|
}
|
|
69
78
|
|
|
70
|
-
export async function migrateRuntimeStorage(sixb:
|
|
79
|
+
export async function migrateRuntimeStorage(sixb: LoadedSixbHost): Promise<void> {
|
|
71
80
|
await migrateStorage(sixb.storage)
|
|
72
81
|
}
|
|
73
82
|
|
|
74
|
-
export async function checkRuntimeLakeDefinitions(sixb:
|
|
83
|
+
export async function checkRuntimeLakeDefinitions(sixb: LoadedSixbHost): Promise<void> {
|
|
75
84
|
await assertLakeDatasetDefinitionsCompatible({
|
|
76
85
|
lakeStorage: sixb.lakeStorage,
|
|
77
|
-
definitions: sixb.
|
|
86
|
+
definitions: sixb.definitions.datasets.list(),
|
|
78
87
|
})
|
|
79
88
|
}
|
|
80
89
|
|
|
81
|
-
export async function stopSixbProviders(sixb:
|
|
90
|
+
export async function stopSixbProviders(sixb: LoadedSixbHost): Promise<void> {
|
|
82
91
|
await stopQuietly(() => flushSixbErrors(sixb))
|
|
83
|
-
await stopQuietly(() => sixb.
|
|
92
|
+
await stopQuietly(() => sixb.closeConnectors())
|
|
84
93
|
await stopQuietly(() => closeProvider(sixb.queues))
|
|
85
94
|
// Stop tracked outbox publication before closing the storage it claims from.
|
|
86
95
|
await stopQuietly(() => sixb.closeBroker())
|
|
@@ -88,14 +97,14 @@ export async function stopSixbProviders(sixb: LoadedSixb): Promise<void> {
|
|
|
88
97
|
await stopQuietly(() => flushSixbErrors(sixb))
|
|
89
98
|
await stopQuietly(() => closeProvider(sixb.storage))
|
|
90
99
|
await stopQuietly(() => closeProvider(sixb.lakeStorage))
|
|
91
|
-
await stopQuietly(() =>
|
|
100
|
+
await stopQuietly(() => sixb.closeBlobs())
|
|
92
101
|
await stopQuietly(() => sixb.closeLogger())
|
|
93
102
|
}
|
|
94
103
|
|
|
95
|
-
export async function startRulesRuntime(sixb:
|
|
104
|
+
export async function startRulesRuntime(sixb: LoadedSixbHost): Promise<RunningRulesRuntime> {
|
|
96
105
|
let rulesWorker: RulesWorker | null = null
|
|
97
106
|
|
|
98
|
-
if (sixb.
|
|
107
|
+
if (sixb.definitions.rules.list().length > 0) {
|
|
99
108
|
rulesWorker = new RulesWorker(sixb)
|
|
100
109
|
await rulesWorker.start()
|
|
101
110
|
}
|
|
@@ -108,47 +117,50 @@ export async function startRulesRuntime(sixb: LoadedSixb): Promise<RunningRulesR
|
|
|
108
117
|
}
|
|
109
118
|
}
|
|
110
119
|
|
|
111
|
-
export async function startSchedulerRuntime(
|
|
112
|
-
|
|
120
|
+
export async function startSchedulerRuntime(
|
|
121
|
+
sixb: LoadedSixbHost
|
|
122
|
+
): Promise<RunningSchedulerRuntime> {
|
|
123
|
+
await sixb.scheduler.start()
|
|
113
124
|
|
|
114
125
|
return {
|
|
115
126
|
async stop() {
|
|
116
|
-
await stopQuietly(() => sixb.
|
|
127
|
+
await stopQuietly(() => sixb.scheduler.stop())
|
|
117
128
|
},
|
|
118
129
|
}
|
|
119
130
|
}
|
|
120
131
|
|
|
121
132
|
export async function startOrchestratorRuntime(
|
|
122
|
-
sixb:
|
|
133
|
+
sixb: LoadedSixbHost
|
|
123
134
|
): Promise<RunningOrchestratorRuntime> {
|
|
124
135
|
const projections = getProjectionDispatchDescriptors(sixb)
|
|
125
136
|
const { routes, diagnostics } = compileRoutesWithDiagnostics({
|
|
126
|
-
schedules: sixb.
|
|
127
|
-
syncs: sixb.
|
|
128
|
-
pipelines: sixb.
|
|
137
|
+
schedules: sixb.definitions.schedules.list(),
|
|
138
|
+
syncs: sixb.definitions.syncs.list(),
|
|
139
|
+
pipelines: sixb.definitions.pipelines.list(),
|
|
129
140
|
projections,
|
|
130
|
-
workflows: sixb.workflows.list(),
|
|
141
|
+
workflows: sixb.definitions.workflows.list(),
|
|
131
142
|
})
|
|
132
143
|
const warnings = diagnostics.map(formatRouteDiagnosticWarning)
|
|
133
144
|
let orchestratorWorker: OrchestratorWorker | null = null
|
|
134
145
|
|
|
135
146
|
if (routes.size > 0) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
throw new Error(
|
|
139
|
-
"[SixbCLI] Projection dispatch requires storage.projectionRuns for durable reconciliation."
|
|
140
|
-
)
|
|
147
|
+
if (projections.length > 0 && !sixb.storage.projectionRuns) {
|
|
148
|
+
throw new Error("[SixbCLI] Projection dispatch requires storage.projectionRuns.")
|
|
141
149
|
}
|
|
142
|
-
const
|
|
143
|
-
projections.length > 0
|
|
144
|
-
? { lakeStorage: sixb.lakeStorage, projectionRuns }
|
|
145
|
-
: undefined
|
|
150
|
+
const projectionReconciliation =
|
|
151
|
+
projections.length > 0 ? { lakeStorage: sixb.lakeStorage } : undefined
|
|
146
152
|
orchestratorWorker = new OrchestratorWorker({
|
|
147
153
|
projectId: sixb.id,
|
|
148
154
|
events: sixb.events,
|
|
149
155
|
queues: sixb.queues,
|
|
150
156
|
routes,
|
|
151
|
-
|
|
157
|
+
dispatchers: {
|
|
158
|
+
syncs: new SyncRunDispatcher(sixb),
|
|
159
|
+
pipelines: new PipelineRunDispatcher(sixb),
|
|
160
|
+
projections: new ProjectionRunDispatcher(sixb),
|
|
161
|
+
workflows: new WorkflowRunDispatcher(sixb),
|
|
162
|
+
},
|
|
163
|
+
...(projectionReconciliation ? { projectionReconciliation } : {}),
|
|
152
164
|
})
|
|
153
165
|
await orchestratorWorker.start()
|
|
154
166
|
}
|
|
@@ -189,7 +201,7 @@ export async function startOrchestratorRuntime(
|
|
|
189
201
|
* 10. Runtime providers (connectors, broker)
|
|
190
202
|
*/
|
|
191
203
|
export async function startSixbRuntime(
|
|
192
|
-
sixb:
|
|
204
|
+
sixb: LoadedSixbHost,
|
|
193
205
|
options: StartSixbRuntimeOptions = {}
|
|
194
206
|
): Promise<RunningSixbRuntime> {
|
|
195
207
|
await migrateRuntimeStorage(sixb)
|
|
@@ -226,39 +238,44 @@ export async function startSixbRuntime(
|
|
|
226
238
|
rulesWorker = rulesRuntime.rulesWorker
|
|
227
239
|
|
|
228
240
|
if (options.cohostWorkers) {
|
|
229
|
-
if (sixb.
|
|
241
|
+
if (sixb.definitions.actions.list().length > 0) {
|
|
230
242
|
actionWorker = new ActionWorker(sixb)
|
|
231
243
|
await actionWorker.start()
|
|
232
244
|
}
|
|
233
245
|
|
|
234
|
-
if (sixb.agents.list().length > 0 && sixb.storage.agents) {
|
|
246
|
+
if (sixb.definitions.agents.list().length > 0 && sixb.storage.agents) {
|
|
235
247
|
agentWorker = new AgentWorker(sixb, {
|
|
236
248
|
apiBaseUrl: requireAgentApiBaseUrl(options.agentApiBaseUrl),
|
|
249
|
+
concurrency: options.workerConcurrency?.agent,
|
|
250
|
+
turnTimeoutMs: options.agentTurnTimeoutMs,
|
|
237
251
|
})
|
|
238
252
|
await agentWorker.start()
|
|
239
253
|
}
|
|
240
254
|
|
|
241
|
-
const projectionCount =
|
|
242
|
-
sixb.listObjectProjections().length +
|
|
243
|
-
sixb.listLinkProjections().length +
|
|
244
|
-
sixb.listTelemetryProjections().length
|
|
255
|
+
const projectionCount = sixb.definitions.projections.list().length
|
|
245
256
|
if (projectionCount > 0) {
|
|
246
|
-
projectionWorker = new ProjectionWorker(sixb
|
|
257
|
+
projectionWorker = new ProjectionWorker(sixb, {
|
|
258
|
+
concurrency: options.workerConcurrency?.projection,
|
|
259
|
+
})
|
|
247
260
|
await projectionWorker.start()
|
|
248
261
|
}
|
|
249
262
|
|
|
250
|
-
if (sixb.
|
|
251
|
-
pipelineWorker = new PipelineWorker(sixb
|
|
263
|
+
if (sixb.definitions.pipelines.list().length > 0) {
|
|
264
|
+
pipelineWorker = new PipelineWorker(sixb, {
|
|
265
|
+
concurrency: options.workerConcurrency?.pipeline,
|
|
266
|
+
})
|
|
252
267
|
await pipelineWorker.start()
|
|
253
268
|
}
|
|
254
269
|
|
|
255
|
-
if (sixb.workflows.list().length > 0) {
|
|
256
|
-
workflowWorker = new WorkflowWorker(sixb
|
|
270
|
+
if (sixb.definitions.workflows.list().length > 0) {
|
|
271
|
+
workflowWorker = new WorkflowWorker(sixb, {
|
|
272
|
+
concurrency: options.workerConcurrency?.workflow,
|
|
273
|
+
})
|
|
257
274
|
await workflowWorker.start()
|
|
258
275
|
}
|
|
259
276
|
|
|
260
|
-
if (sixb.
|
|
261
|
-
syncWorker = new SyncWorker(sixb)
|
|
277
|
+
if (sixb.definitions.syncs.list().length > 0) {
|
|
278
|
+
syncWorker = new SyncWorker(sixb, { concurrency: options.workerConcurrency?.sync })
|
|
262
279
|
await syncWorker.start()
|
|
263
280
|
}
|
|
264
281
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Broker, Queues } from "@sixb/core"
|
|
2
2
|
import { SixbCliError } from "./errors"
|
|
3
|
-
import type {
|
|
3
|
+
import type { LoadedSixbHost } from "./loadSixb"
|
|
4
4
|
import { type ProductionRole, productionRoleFacts } from "./production-roles"
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -13,17 +13,17 @@ import { type ProductionRole, productionRoleFacts } from "./production-roles"
|
|
|
13
13
|
const SLOTS = [
|
|
14
14
|
{
|
|
15
15
|
name: "queues",
|
|
16
|
-
get: (sixb:
|
|
16
|
+
get: (sixb: LoadedSixbHost): Broker | Queues => sixb.queues,
|
|
17
17
|
replacements: "@sixb/bullmq",
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
20
|
name: "broker",
|
|
21
|
-
get: (sixb:
|
|
21
|
+
get: (sixb: LoadedSixbHost): Broker | Queues => sixb.broker,
|
|
22
22
|
replacements: "@sixb/redis or @sixb/nats",
|
|
23
23
|
},
|
|
24
24
|
] as const
|
|
25
25
|
|
|
26
|
-
function isProcessLocal(slot: (typeof SLOTS)[number], sixb:
|
|
26
|
+
function isProcessLocal(slot: (typeof SLOTS)[number], sixb: LoadedSixbHost): boolean {
|
|
27
27
|
return slot.get(sixb).scope === "process"
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -36,7 +36,7 @@ export interface ProcessLocalProvider {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/** The same detection as {@link assertShareableProviders}, without the refusal. */
|
|
39
|
-
export function findProcessLocalProviders(sixb:
|
|
39
|
+
export function findProcessLocalProviders(sixb: LoadedSixbHost): readonly ProcessLocalProvider[] {
|
|
40
40
|
return SLOTS.filter((slot) => isProcessLocal(slot, sixb)).map((slot) => ({
|
|
41
41
|
slot: slot.name,
|
|
42
42
|
configured: slot.get(sixb).constructor?.name ?? "a process-local provider",
|
|
@@ -51,7 +51,7 @@ export function findProcessLocalProviders(sixb: LoadedSixb): readonly ProcessLoc
|
|
|
51
51
|
* the orchestrator enqueues, the worker polls an empty queue, and nothing reports a problem.
|
|
52
52
|
* Throws rather than warns, because an inert deployment is indistinguishable from an idle one.
|
|
53
53
|
*/
|
|
54
|
-
export function assertShareableProviders(sixb:
|
|
54
|
+
export function assertShareableProviders(sixb: LoadedSixbHost, role: ProductionRole): void {
|
|
55
55
|
if (!productionRoleFacts(role).onEventPlane) return
|
|
56
56
|
|
|
57
57
|
for (const offender of findProcessLocalProviders(sixb)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { migrateStorage } from "@sixb/core"
|
|
2
2
|
import { SixbCliError } from "./errors"
|
|
3
|
-
import type {
|
|
3
|
+
import type { LoadedSixbHost } from "./loadSixb"
|
|
4
4
|
import type { StorageSchemaRole } from "./production-roles"
|
|
5
5
|
|
|
6
6
|
/** Set to `1` to start a role without bringing the storage schema up to date. */
|
|
@@ -46,7 +46,7 @@ export interface RoleStorageMigration {
|
|
|
46
46
|
* passed through raw.
|
|
47
47
|
*/
|
|
48
48
|
export async function migrateStorageForRole(
|
|
49
|
-
sixb:
|
|
49
|
+
sixb: LoadedSixbHost,
|
|
50
50
|
options: RoleStorageMigrationOptions
|
|
51
51
|
): Promise<RoleStorageMigration> {
|
|
52
52
|
const { role } = options
|
|
@@ -84,7 +84,7 @@ export async function migrateStorageForRole(
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
async function runMigration(sixb:
|
|
87
|
+
async function runMigration(sixb: LoadedSixbHost, role: StorageSchemaRole) {
|
|
88
88
|
try {
|
|
89
89
|
return await migrateStorage(sixb.storage)
|
|
90
90
|
} catch (error) {
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ConfigurableWorkerType,
|
|
3
|
+
WORKER_CONCURRENCY_CONFIG,
|
|
4
|
+
WORKER_TYPES,
|
|
5
|
+
type WorkerConcurrency,
|
|
6
|
+
type WorkerType,
|
|
7
|
+
} from "./worker-registry"
|
|
8
|
+
|
|
9
|
+
/** Resolve the scalar concurrency accepted by `sixb worker <type>`. */
|
|
10
|
+
export function resolveSingleWorkerConcurrency(
|
|
11
|
+
workerType: WorkerType,
|
|
12
|
+
value: string | undefined
|
|
13
|
+
): WorkerConcurrency {
|
|
14
|
+
const definition = WORKER_CONCURRENCY_CONFIG[workerType]
|
|
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
|
|
23
|
+
const configured = value?.trim() ?? nonblank(process.env[environmentVariable])
|
|
24
|
+
if (configured === undefined) return {}
|
|
25
|
+
|
|
26
|
+
return { [workerType]: parseConcurrency(configured, `--concurrency or ${environmentVariable}`) }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Resolve repeatable `<type>=<count>` values for co-hosted workers. Per-type CLI values override
|
|
31
|
+
* their environment variables; repeated CLI values use the last occurrence.
|
|
32
|
+
*/
|
|
33
|
+
export function resolveWorkerConcurrency(values: readonly string[] = []): WorkerConcurrency {
|
|
34
|
+
const overrides = values.map(parseWorkerConcurrencyEntry)
|
|
35
|
+
const overriddenWorkerTypes = new Set(overrides.map((entry) => entry.workerType))
|
|
36
|
+
const resolved: Partial<Record<ConfigurableWorkerType, number>> = {}
|
|
37
|
+
|
|
38
|
+
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
|
+
if (overriddenWorkerTypes.has(workerType)) continue
|
|
47
|
+
|
|
48
|
+
const environmentVariable = definition.environmentVariable
|
|
49
|
+
const configured = nonblank(process.env[environmentVariable])
|
|
50
|
+
if (configured !== undefined) {
|
|
51
|
+
resolved[workerType] = parseConcurrency(configured, environmentVariable)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (const entry of overrides) {
|
|
56
|
+
resolved[entry.workerType] = entry.concurrency
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return resolved
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function parseWorkerConcurrencyEntry(value: string): {
|
|
63
|
+
readonly workerType: ConfigurableWorkerType
|
|
64
|
+
readonly concurrency: number
|
|
65
|
+
} {
|
|
66
|
+
const separator = value.indexOf("=")
|
|
67
|
+
if (separator <= 0 || separator !== value.lastIndexOf("=")) {
|
|
68
|
+
throw invalidWorkerConcurrencyEntry(value)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const workerType = value.slice(0, separator).trim()
|
|
72
|
+
const configured = value.slice(separator + 1).trim()
|
|
73
|
+
if (!isWorkerType(workerType)) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`[SixbCLI] Unknown worker concurrency type '${workerType || value}'. Available: ${WORKER_TYPES.filter(isConfigurableWorkerType).join(", ")}.`
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
if (!isConfigurableWorkerType(workerType)) {
|
|
79
|
+
throw fixedActionConcurrency()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
workerType,
|
|
84
|
+
concurrency: parseConcurrency(configured, `--concurrency ${workerType}=<count>`),
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function parseConcurrency(value: string, source: string): number {
|
|
89
|
+
if (!/^[1-9]\d*$/.test(value)) {
|
|
90
|
+
throw invalidConcurrency(value, source)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const concurrency = Number(value)
|
|
94
|
+
if (!Number.isSafeInteger(concurrency)) {
|
|
95
|
+
throw invalidConcurrency(value, source)
|
|
96
|
+
}
|
|
97
|
+
return concurrency
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function nonblank(value: string | undefined): string | undefined {
|
|
101
|
+
return value?.trim() || undefined
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function isWorkerType(value: string): value is WorkerType {
|
|
105
|
+
return WORKER_TYPES.some((workerType) => workerType === value)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function isConfigurableWorkerType(value: WorkerType): value is ConfigurableWorkerType {
|
|
109
|
+
return WORKER_CONCURRENCY_CONFIG[value].configurable
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function invalidConcurrency(value: string, source: string): Error {
|
|
113
|
+
return new Error(
|
|
114
|
+
`[SixbCLI] Invalid worker concurrency '${value}'. Use a positive integer with ${source}.`
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function invalidWorkerConcurrencyEntry(value: string): Error {
|
|
119
|
+
return new Error(
|
|
120
|
+
`[SixbCLI] Invalid worker concurrency '${value}'. Use a repeatable type=count value like ` +
|
|
121
|
+
"--concurrency agent=4 --concurrency sync=2."
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function fixedActionConcurrency(): Error {
|
|
126
|
+
return new Error("[SixbCLI] Action worker concurrency is fixed at 1 and cannot be configured.")
|
|
127
|
+
}
|