@deepnoodle/mobius 0.0.20 → 0.0.22
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 +31 -45
- package/dist/api/index.d.ts +198 -240
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/schema.d.ts +5387 -7233
- package/dist/api/schema.d.ts.map +1 -1
- package/dist/client.d.ts +64 -152
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +164 -358
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/signing.d.ts +43 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +101 -0
- package/dist/signing.js.map +1 -0
- package/dist/webhook.d.ts +5 -17
- package/dist/webhook.d.ts.map +1 -1
- package/dist/webhook.js +38 -50
- package/dist/webhook.js.map +1 -1
- package/dist/worker.d.ts +40 -138
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +315 -456
- package/dist/worker.js.map +1 -1
- package/package.json +4 -4
package/dist/worker.d.ts
CHANGED
|
@@ -1,190 +1,92 @@
|
|
|
1
1
|
import { Client } from "./client.js";
|
|
2
2
|
export type InstanceIDSource = "configured" | "cloud_run_revision_instance" | "hostname" | "fly_machine_id" | "railway_replica_id" | "render_instance_id" | "system_hostname" | "generated_uuid";
|
|
3
|
-
/**
|
|
4
|
-
* Resolve a per-process `worker_instance_id` from the runtime
|
|
5
|
-
* environment. Order: explicit → Cloud Run K_REVISION + metadata →
|
|
6
|
-
* HOSTNAME env → FLY_MACHINE_ID → RAILWAY_REPLICA_ID →
|
|
7
|
-
* RENDER_INSTANCE_ID → `os.hostname()` suffixed with a per-boot
|
|
8
|
-
* random tag (laptops and bare metal) → generated UUID.
|
|
9
|
-
*
|
|
10
|
-
* The system_hostname rung carries a random suffix because
|
|
11
|
-
* `os.hostname()` identifies the host, not the process — two
|
|
12
|
-
* processes started on the same machine would otherwise auto-detect
|
|
13
|
-
* the same identifier and collide on the server's conflict detector.
|
|
14
|
-
* Set {@link WorkerConfig.workerInstanceId} explicitly only when a
|
|
15
|
-
* stable identity across restarts is desired (named singleton
|
|
16
|
-
* workers).
|
|
17
|
-
*
|
|
18
|
-
* The returned source is informational only — workers log it once at
|
|
19
|
-
* startup so operators can confirm the right platform was picked up.
|
|
20
|
-
*/
|
|
21
3
|
export declare function resolveInstanceID(explicit: string | undefined): Promise<{
|
|
22
4
|
id: string;
|
|
23
5
|
source: InstanceIDSource;
|
|
24
6
|
}>;
|
|
25
|
-
/**
|
|
26
|
-
* Logger interface used by Worker for status and error output. Compatible with
|
|
27
|
-
* the global `console` object, so `console` is a valid logger. Pass `null` to
|
|
28
|
-
* `WorkerConfig.logger` to silence all output.
|
|
29
|
-
*/
|
|
30
7
|
export interface Logger {
|
|
31
8
|
info(...args: unknown[]): void;
|
|
32
9
|
warn(...args: unknown[]): void;
|
|
33
10
|
error(...args: unknown[]): void;
|
|
34
11
|
}
|
|
12
|
+
export interface ModelCapability {
|
|
13
|
+
provider: string;
|
|
14
|
+
model: string;
|
|
15
|
+
}
|
|
35
16
|
export interface WorkerConfig {
|
|
36
|
-
/**
|
|
37
|
-
* Identifier for this worker process. Leave omitted for the
|
|
38
|
-
* common case: the SDK auto-detects an identifier that is unique
|
|
39
|
-
* per running process. Resolution prefers platform-native IDs
|
|
40
|
-
* that are unique-per-replica by design (Cloud Run revision
|
|
41
|
-
* instance, Kubernetes HOSTNAME, Fly machine, Railway replica,
|
|
42
|
-
* Render instance), then falls back to OS hostname plus a
|
|
43
|
-
* per-boot random suffix so two processes on the same host
|
|
44
|
-
* (back-to-back tests, parallel CI workers) cannot collide.
|
|
45
|
-
*
|
|
46
|
-
* Set this explicitly only when you want a stable identity
|
|
47
|
-
* across restarts of a named singleton worker. Two live
|
|
48
|
-
* processes using the same explicit value in the same project
|
|
49
|
-
* will collide and the second will fail with
|
|
50
|
-
* {@link WorkerInstanceConflictError}.
|
|
51
|
-
*/
|
|
52
17
|
workerInstanceId?: string;
|
|
53
|
-
/**
|
|
54
|
-
* Maximum number of jobs this worker holds in flight simultaneously.
|
|
55
|
-
* Defaults to 1; raise to claim several jobs from one worker process
|
|
56
|
-
* while still surfacing as a single row on the workers page.
|
|
57
|
-
*/
|
|
58
18
|
concurrency?: number;
|
|
59
|
-
/** Human-readable name reported to Mobius (e.g. "billing-worker"). */
|
|
60
19
|
name?: string;
|
|
61
|
-
/** Version string reported to Mobius (e.g. "1.0.0"). */
|
|
62
20
|
version?: string;
|
|
63
|
-
/**
|
|
64
|
-
* Queue names this worker subscribes to. Empty (or omitted) means claim
|
|
65
|
-
* jobs from any queue in the project. Runs default to the "default"
|
|
66
|
-
* queue.
|
|
67
|
-
*/
|
|
68
21
|
queues?: string[];
|
|
69
|
-
/**
|
|
70
|
-
* Optional filter of action names this worker will claim. When empty the
|
|
71
|
-
* worker will only claim jobs for actions it has registered.
|
|
72
|
-
*/
|
|
73
22
|
actions?: string[];
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Heartbeat interval in milliseconds. When unset, the SDK uses the interval
|
|
78
|
-
* advertised by the server in the claim response, falling back to 10_000.
|
|
79
|
-
*/
|
|
23
|
+
models?: ModelCapability[];
|
|
24
|
+
reconnectDelayMs?: number;
|
|
80
25
|
heartbeatIntervalMs?: number;
|
|
81
|
-
/**
|
|
82
|
-
* Logger for worker status and error output. Defaults to `console`. Pass
|
|
83
|
-
* `null` to silence all worker output, or supply a custom {@link Logger}
|
|
84
|
-
* (e.g. pino, winston) to route messages elsewhere.
|
|
85
|
-
*/
|
|
86
26
|
logger?: Logger | null;
|
|
87
|
-
/** Max buffered custom events per in-flight job before dropping oldest. */
|
|
88
|
-
eventQueueSize?: number;
|
|
89
|
-
/** Max custom events per HTTP batch. Defaults to 20. */
|
|
90
|
-
eventBatchSize?: number;
|
|
91
27
|
}
|
|
92
|
-
/**
|
|
93
|
-
* ActionFn implements a single Mobius action. Receives the JSON-decoded
|
|
94
|
-
* parameters delivered with the job claim and returns a JSON-serialisable
|
|
95
|
-
* result.
|
|
96
|
-
*/
|
|
97
|
-
export type ActionFn = (params: Record<string, unknown>, signal: AbortSignal, ctx: ActionContext) => Promise<unknown>;
|
|
98
28
|
export interface ActionContext {
|
|
99
29
|
jobId: string;
|
|
100
|
-
runId
|
|
30
|
+
runId?: string;
|
|
31
|
+
sessionId?: string;
|
|
32
|
+
agentTurnId?: string;
|
|
33
|
+
toolCallId?: string;
|
|
101
34
|
projectId?: string;
|
|
102
35
|
workerInstanceId: string;
|
|
103
36
|
attempt: number;
|
|
104
37
|
queue?: string;
|
|
105
|
-
|
|
106
|
-
stepName?: string;
|
|
38
|
+
stepId?: string;
|
|
107
39
|
action?: string;
|
|
108
40
|
emitEvent(type: string, payload: Record<string, unknown>): void;
|
|
109
41
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
42
|
+
export type ActionFn = (params: Record<string, unknown>, signal: AbortSignal, ctx: ActionContext) => Promise<unknown>;
|
|
43
|
+
export interface GenerationJob {
|
|
44
|
+
jobId: string;
|
|
45
|
+
runId?: string;
|
|
46
|
+
sessionId?: string;
|
|
47
|
+
agentTurnId?: string;
|
|
48
|
+
toolCallId?: string;
|
|
49
|
+
provider?: string;
|
|
50
|
+
model?: string;
|
|
51
|
+
spec: Record<string, unknown>;
|
|
52
|
+
}
|
|
53
|
+
export type GenerationEmitter = (delta: Record<string, unknown>) => void;
|
|
54
|
+
export type GenerationFn = (ctx: ActionContext, job: GenerationJob, emit: GenerationEmitter) => Promise<Record<string, unknown>>;
|
|
120
55
|
export declare class Worker {
|
|
121
56
|
private readonly client;
|
|
122
57
|
private readonly config;
|
|
123
58
|
private readonly logger;
|
|
124
59
|
private readonly actions;
|
|
125
|
-
private readonly
|
|
126
|
-
private
|
|
127
|
-
private
|
|
128
|
-
private
|
|
129
|
-
constructor(client: Client, config
|
|
130
|
-
/** Register an action function under the given name. */
|
|
60
|
+
private readonly generators;
|
|
61
|
+
private sessionToken;
|
|
62
|
+
private stopping;
|
|
63
|
+
private readonly stopController;
|
|
64
|
+
constructor(client: Client, config?: WorkerConfig, actions?: Map<string, ActionFn>);
|
|
131
65
|
register(name: string, fn: ActionFn): this;
|
|
132
|
-
|
|
133
|
-
* Start the claim loop. Returns a promise that resolves when the worker is
|
|
134
|
-
* stopped via {@link stop} or the given signal is aborted. Throws
|
|
135
|
-
* {@link AuthRevokedError} when the credential is revoked mid-flight
|
|
136
|
-
* and {@link WorkerInstanceConflictError} when another live process
|
|
137
|
-
* has already registered this worker_instance_id.
|
|
138
|
-
*
|
|
139
|
-
* Cancellation has two distinct shapes:
|
|
140
|
-
*
|
|
141
|
-
* - {@link stop} aborts the claim loop only — in-flight jobs continue
|
|
142
|
-
* to run to natural completion and the returned promise resolves
|
|
143
|
-
* once they all settle. This is graceful drain.
|
|
144
|
-
* - The caller's `signal`, when aborted, propagates into both the
|
|
145
|
-
* claim loop and every running action. This is the emergency-stop
|
|
146
|
-
* path (e.g. SIGTERM with a hard deadline).
|
|
147
|
-
*/
|
|
148
|
-
run(signal?: AbortSignal): Promise<void>;
|
|
149
|
-
/** Gracefully stop the worker after in-flight jobs complete. */
|
|
66
|
+
registerGenerator(provider: string, model: string, fn: GenerationFn): this;
|
|
150
67
|
stop(): void;
|
|
68
|
+
run(signal?: AbortSignal): Promise<void>;
|
|
69
|
+
private runSocket;
|
|
70
|
+
private registerFrame;
|
|
71
|
+
private claim;
|
|
72
|
+
private modelCapabilities;
|
|
151
73
|
private executeJob;
|
|
152
|
-
private
|
|
153
|
-
private
|
|
74
|
+
private generator;
|
|
75
|
+
private actionContext;
|
|
76
|
+
private report;
|
|
154
77
|
}
|
|
155
78
|
export interface WorkerPoolConfig extends Omit<WorkerConfig, "workerInstanceId"> {
|
|
156
|
-
/** Number of worker instances to run. Defaults to 1. */
|
|
157
79
|
count?: number;
|
|
158
|
-
/**
|
|
159
|
-
* Prefix used to derive child instance IDs as `<prefix>-<index>`.
|
|
160
|
-
* When omitted, the SDK generates a per-boot prefix; child workers
|
|
161
|
-
* each get their own session token, so a pool of N produces N rows
|
|
162
|
-
* on the workers page.
|
|
163
|
-
*/
|
|
164
80
|
workerInstanceIdPrefix?: string;
|
|
165
81
|
}
|
|
166
|
-
/**
|
|
167
|
-
* Runs multiple worker instances in one process. Most callers do not
|
|
168
|
-
* need a pool — to run several jobs from one process, set
|
|
169
|
-
* {@link WorkerConfig.concurrency} on a single {@link Worker} and the
|
|
170
|
-
* admin UI will show one row with a saturation bar. Reach for a pool
|
|
171
|
-
* only when each child should surface as its own row on the workers
|
|
172
|
-
* page (independent draining, in-flight isolation).
|
|
173
|
-
*/
|
|
174
82
|
export declare class WorkerPool {
|
|
175
83
|
private readonly client;
|
|
176
84
|
private readonly config;
|
|
177
85
|
private readonly actions;
|
|
178
|
-
private
|
|
86
|
+
private readonly generators;
|
|
179
87
|
constructor(client: Client, config: WorkerPoolConfig);
|
|
180
|
-
/** Register an action function under the given name for every pool worker. */
|
|
181
88
|
register(name: string, fn: ActionFn): this;
|
|
182
|
-
|
|
183
|
-
* Start all workers in the pool. Rejects with AuthRevokedError if any child
|
|
184
|
-
* worker sees credential revocation.
|
|
185
|
-
*/
|
|
89
|
+
registerGenerator(provider: string, model: string, fn: GenerationFn): this;
|
|
186
90
|
run(signal?: AbortSignal): Promise<void>;
|
|
187
|
-
/** Gracefully stop every worker in the pool after in-flight jobs complete. */
|
|
188
|
-
stop(): void;
|
|
189
91
|
}
|
|
190
92
|
//# sourceMappingURL=worker.d.ts.map
|
package/dist/worker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","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