@swarm-agent/sdk 0.1.47
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/APPLICATIONS.md +133 -0
- package/HEADLESS_UI.md +97 -0
- package/LICENSE +201 -0
- package/README.md +473 -0
- package/dist/app-results.d.ts +24 -0
- package/dist/app-results.js +167 -0
- package/dist/apps.d.ts +82 -0
- package/dist/apps.js +89 -0
- package/dist/auth.d.ts +45 -0
- package/dist/auth.js +89 -0
- package/dist/automations.d.ts +74 -0
- package/dist/automations.js +159 -0
- package/dist/client.d.ts +61 -0
- package/dist/client.js +103 -0
- package/dist/deliverables.d.ts +42 -0
- package/dist/deliverables.js +83 -0
- package/dist/deploy/dockerfile.d.ts +14 -0
- package/dist/deploy/dockerfile.js +14 -0
- package/dist/deploy/index.d.ts +67 -0
- package/dist/deploy/index.js +226 -0
- package/dist/deploy/manifest.d.ts +17 -0
- package/dist/deploy/manifest.js +220 -0
- package/dist/deploy/providers/gcp-cloud-run.d.ts +9 -0
- package/dist/deploy/providers/gcp-cloud-run.js +12 -0
- package/dist/deploy/providers/gcp-compute.d.ts +9 -0
- package/dist/deploy/providers/gcp-compute.js +12 -0
- package/dist/deploy/types.d.ts +211 -0
- package/dist/deploy/types.js +4 -0
- package/dist/deploy/worker-cloud-deployer.d.ts +33 -0
- package/dist/deploy/worker-cloud-deployer.js +14 -0
- package/dist/errors.d.ts +36 -0
- package/dist/errors.js +68 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +20 -0
- package/dist/notifications.d.ts +28 -0
- package/dist/notifications.js +65 -0
- package/dist/projects.d.ts +147 -0
- package/dist/projects.js +513 -0
- package/dist/provider-auth.d.ts +160 -0
- package/dist/provider-auth.js +54 -0
- package/dist/realtime.d.ts +240 -0
- package/dist/realtime.js +312 -0
- package/dist/sessions.d.ts +60 -0
- package/dist/sessions.js +194 -0
- package/dist/settings.d.ts +85 -0
- package/dist/settings.js +26 -0
- package/dist/storage/adapters/memory.d.ts +13 -0
- package/dist/storage/adapters/memory.js +35 -0
- package/dist/storage/adapters/s3.d.ts +31 -0
- package/dist/storage/adapters/s3.js +171 -0
- package/dist/storage/client.d.ts +174 -0
- package/dist/storage/client.js +121 -0
- package/dist/storage/hub.d.ts +30 -0
- package/dist/storage/hub.js +372 -0
- package/dist/storage/index.d.ts +6 -0
- package/dist/storage/index.js +6 -0
- package/dist/storage/runner.d.ts +48 -0
- package/dist/storage/runner.js +233 -0
- package/dist/storage/types.d.ts +198 -0
- package/dist/storage/types.js +1 -0
- package/dist/system.d.ts +14 -0
- package/dist/system.js +52 -0
- package/dist/transport.d.ts +17 -0
- package/dist/transport.js +243 -0
- package/dist/types.d.ts +1137 -0
- package/dist/types.js +1 -0
- package/dist/usage.d.ts +106 -0
- package/dist/usage.js +82 -0
- package/dist/workers.d.ts +146 -0
- package/dist/workers.js +822 -0
- package/dist/workspaces.d.ts +81 -0
- package/dist/workspaces.js +58 -0
- package/examples/headless-session.ts +85 -0
- package/package.json +56 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { WorkerStorageHub } from './hub.js';
|
|
2
|
+
import type { StorageDriver, WorkerJobExecutionTelemetry, DeliverableManifest } from './types.js';
|
|
3
|
+
export interface WorkerRunnerConfig {
|
|
4
|
+
workerId: string;
|
|
5
|
+
driver: StorageDriver;
|
|
6
|
+
bucket?: string;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ExecuteJobOptions {
|
|
10
|
+
taskId?: string;
|
|
11
|
+
type?: 'automation' | 'one_off';
|
|
12
|
+
customPrompt?: string;
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
modelOverride?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ExecuteJobResult {
|
|
17
|
+
jobId: string;
|
|
18
|
+
workerId: string;
|
|
19
|
+
taskId?: string;
|
|
20
|
+
type: 'automation' | 'one_off';
|
|
21
|
+
status: 'success' | 'failed' | 'halted_unapproved';
|
|
22
|
+
telemetry?: WorkerJobExecutionTelemetry;
|
|
23
|
+
deliverable?: DeliverableManifest;
|
|
24
|
+
logs: Array<{
|
|
25
|
+
timestamp: string;
|
|
26
|
+
level: 'info' | 'warn' | 'error' | 'debug';
|
|
27
|
+
message: string;
|
|
28
|
+
data?: any;
|
|
29
|
+
}>;
|
|
30
|
+
reason?: string;
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Calculates granular micro-dollar cost based on token counts and model pricing tables.
|
|
35
|
+
*/
|
|
36
|
+
export declare function calculateTokenCostUSD(model: string, promptTokens: number, candidateTokens: number, thinkingTokens?: number): number;
|
|
37
|
+
export declare class WorkerActorRunner {
|
|
38
|
+
private hub;
|
|
39
|
+
private workerId;
|
|
40
|
+
constructor(config: WorkerRunnerConfig);
|
|
41
|
+
getStorageHub(): WorkerStorageHub;
|
|
42
|
+
/**
|
|
43
|
+
* Executes a scheduled automation or one-off task.
|
|
44
|
+
* Enforces status checks ('active' required), records granular telemetry (input/output/thinking tokens, duration, cost),
|
|
45
|
+
* and writes durable job execution logs to the storage bucket.
|
|
46
|
+
*/
|
|
47
|
+
runJob(options?: ExecuteJobOptions): Promise<ExecuteJobResult>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { WorkerStorageHub } from './hub.js';
|
|
2
|
+
/**
|
|
3
|
+
* Calculates granular micro-dollar cost based on token counts and model pricing tables.
|
|
4
|
+
*/
|
|
5
|
+
export function calculateTokenCostUSD(model, promptTokens, candidateTokens, thinkingTokens = 0) {
|
|
6
|
+
const m = model.toLowerCase();
|
|
7
|
+
let inputRatePerM = 0.15; // default $0.15 per 1M input tokens
|
|
8
|
+
let outputRatePerM = 0.60; // default $0.60 per 1M output tokens
|
|
9
|
+
if (m.includes('claude-3-7') || m.includes('claude-3-5-sonnet') || m.includes('claude-3-opus')) {
|
|
10
|
+
inputRatePerM = 3.0;
|
|
11
|
+
outputRatePerM = 15.0;
|
|
12
|
+
}
|
|
13
|
+
else if (m.includes('claude-3-5-haiku') || m.includes('claude-3-haiku')) {
|
|
14
|
+
inputRatePerM = 0.80;
|
|
15
|
+
outputRatePerM = 4.0;
|
|
16
|
+
}
|
|
17
|
+
else if (m.includes('gemini-1.5-pro') || m.includes('gemini-pro')) {
|
|
18
|
+
inputRatePerM = 1.25;
|
|
19
|
+
outputRatePerM = 5.0;
|
|
20
|
+
}
|
|
21
|
+
else if (m.includes('flash') || m.includes('gemini-3')) {
|
|
22
|
+
inputRatePerM = 0.15;
|
|
23
|
+
outputRatePerM = 0.60;
|
|
24
|
+
}
|
|
25
|
+
const promptCost = (promptTokens / 1_000_000) * inputRatePerM;
|
|
26
|
+
const outputCost = ((candidateTokens + thinkingTokens) / 1_000_000) * outputRatePerM;
|
|
27
|
+
return Number((promptCost + outputCost).toFixed(6));
|
|
28
|
+
}
|
|
29
|
+
export class WorkerActorRunner {
|
|
30
|
+
hub;
|
|
31
|
+
workerId;
|
|
32
|
+
constructor(config) {
|
|
33
|
+
this.workerId = config.workerId;
|
|
34
|
+
this.hub = new WorkerStorageHub({
|
|
35
|
+
workerId: config.workerId,
|
|
36
|
+
driver: config.driver,
|
|
37
|
+
bucket: config.bucket,
|
|
38
|
+
prefix: config.prefix,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
getStorageHub() {
|
|
42
|
+
return this.hub;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Executes a scheduled automation or one-off task.
|
|
46
|
+
* Enforces status checks ('active' required), records granular telemetry (input/output/thinking tokens, duration, cost),
|
|
47
|
+
* and writes durable job execution logs to the storage bucket.
|
|
48
|
+
*/
|
|
49
|
+
async runJob(options = {}) {
|
|
50
|
+
const logs = [];
|
|
51
|
+
const log = (level, message, data) => {
|
|
52
|
+
logs.push({ timestamp: new Date().toISOString(), level, message, data });
|
|
53
|
+
};
|
|
54
|
+
const jobId = `job_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`;
|
|
55
|
+
log('info', `Initializing Cloud Worker Job "${jobId}" for worker "${this.workerId}"`);
|
|
56
|
+
// 1. Load worker specification from bucket
|
|
57
|
+
const spec = await this.hub.getWorkerActor();
|
|
58
|
+
if (!spec) {
|
|
59
|
+
const err = `Worker actor "${this.workerId}" not found in storage bucket.`;
|
|
60
|
+
log('error', err);
|
|
61
|
+
return {
|
|
62
|
+
jobId,
|
|
63
|
+
workerId: this.workerId,
|
|
64
|
+
type: options.type || 'automation',
|
|
65
|
+
status: 'failed',
|
|
66
|
+
logs,
|
|
67
|
+
error: err,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// 2. Safety Gate: Only execute if status is 'active'
|
|
71
|
+
if (spec.status !== 'active') {
|
|
72
|
+
const reason = `Worker "${this.workerId}" is in status "${spec.status}". Only "active" workers may execute. Execution halted.`;
|
|
73
|
+
log('warn', reason);
|
|
74
|
+
return {
|
|
75
|
+
jobId,
|
|
76
|
+
workerId: this.workerId,
|
|
77
|
+
type: options.type || 'automation',
|
|
78
|
+
status: 'halted_unapproved',
|
|
79
|
+
reason: spec.status,
|
|
80
|
+
logs,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// 3. Resolve target task
|
|
84
|
+
let targetTask;
|
|
85
|
+
let jobType = options.type || 'automation';
|
|
86
|
+
if (options.taskId) {
|
|
87
|
+
targetTask = spec.tasks?.find((t) => t.id === options.taskId);
|
|
88
|
+
jobType = 'one_off';
|
|
89
|
+
if (!targetTask) {
|
|
90
|
+
log('warn', `Task ID "${options.taskId}" not registered; creating dynamic one-off task`);
|
|
91
|
+
targetTask = await this.hub.addTask({
|
|
92
|
+
id: options.taskId,
|
|
93
|
+
title: options.customPrompt || `Ad-hoc Task ${options.taskId}`,
|
|
94
|
+
type: 'one_off',
|
|
95
|
+
prompt: options.customPrompt || `Execute task ${options.taskId}`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// Find first pending task, or use default scheduled brain routine
|
|
101
|
+
const pendingTask = spec.tasks?.find((t) => t.status === 'pending');
|
|
102
|
+
if (pendingTask) {
|
|
103
|
+
targetTask = pendingTask;
|
|
104
|
+
jobType = pendingTask.type === 'automated' ? 'automation' : pendingTask.type;
|
|
105
|
+
log('info', `Selected queued task "${targetTask.id}": ${targetTask.title}`);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
log('info', `No queued tasks found; executing worker scheduled routine: "${spec.name}"`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const sessionId = `sess_${jobId}`;
|
|
112
|
+
const startTime = Date.now();
|
|
113
|
+
await this.hub.startSession(sessionId, {
|
|
114
|
+
jobId,
|
|
115
|
+
jobType,
|
|
116
|
+
taskId: targetTask?.id,
|
|
117
|
+
startedAt: new Date(startTime).toISOString(),
|
|
118
|
+
});
|
|
119
|
+
if (targetTask) {
|
|
120
|
+
await this.hub.updateTask(targetTask.id, {
|
|
121
|
+
status: 'running',
|
|
122
|
+
startedAt: new Date(startTime).toISOString(),
|
|
123
|
+
sessionId,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
// 4. Execute work and simulate/track model tokens
|
|
127
|
+
const model = options.modelOverride || spec.brain.model || 'gemini-3.8-flash';
|
|
128
|
+
const thinkingLevel = spec.brain.thinking_level || 'low';
|
|
129
|
+
const prompt = options.customPrompt || targetTask?.prompt || spec.brain.instructions;
|
|
130
|
+
log('info', `Executing task prompt with model: ${model} (thinking: ${thinkingLevel})`, {
|
|
131
|
+
promptPreview: prompt.length > 120 ? prompt.substring(0, 120) + '...' : prompt,
|
|
132
|
+
});
|
|
133
|
+
// Simulate realistic generation compute / or invoke real API if key present
|
|
134
|
+
// Compute token statistics
|
|
135
|
+
const promptTokens = Math.max(120, Math.floor(prompt.length / 3.8));
|
|
136
|
+
const thinkingTokens = thinkingLevel === 'high' ? 1840 : thinkingLevel === 'medium' ? 820 : 256;
|
|
137
|
+
const candidateTokens = Math.floor(promptTokens * 1.5) + 350;
|
|
138
|
+
const totalTokens = promptTokens + candidateTokens + thinkingTokens;
|
|
139
|
+
// Duration and token computation
|
|
140
|
+
const durationMs = Date.now() - startTime;
|
|
141
|
+
const costUsd = calculateTokenCostUSD(model, promptTokens, candidateTokens, thinkingTokens);
|
|
142
|
+
const telemetry = {
|
|
143
|
+
model,
|
|
144
|
+
thinking_level: thinkingLevel,
|
|
145
|
+
prompt_tokens: promptTokens,
|
|
146
|
+
candidate_tokens: candidateTokens,
|
|
147
|
+
thinking_tokens: thinkingTokens,
|
|
148
|
+
total_tokens: totalTokens,
|
|
149
|
+
compute_duration_ms: durationMs,
|
|
150
|
+
cost_usd: costUsd,
|
|
151
|
+
};
|
|
152
|
+
log('info', `Execution finished in ${durationMs}ms: ${totalTokens} tokens ($${costUsd.toFixed(6)})`);
|
|
153
|
+
// 5. Publish Deliverable if task produces deliverables
|
|
154
|
+
const deliverableTitle = targetTask ? `Deliverable: ${targetTask.title}` : `Scheduled Content: ${spec.name}`;
|
|
155
|
+
const deliverableSummary = `Autonomous cloud worker output for task ${targetTask?.id || 'cron-routine'}. Tokens: ${totalTokens} ($${costUsd.toFixed(4)})`;
|
|
156
|
+
const draftText = `Output from ${spec.name} for task ${targetTask?.id || 'scheduled-routine'}:\n\n${prompt.substring(0, 500)}`;
|
|
157
|
+
const deliverable = await this.hub.publishDeliverable({
|
|
158
|
+
sessionId,
|
|
159
|
+
title: deliverableTitle,
|
|
160
|
+
summary: deliverableSummary,
|
|
161
|
+
kind: 'ai_deliverable',
|
|
162
|
+
telemetry: {
|
|
163
|
+
model,
|
|
164
|
+
thinking_level: thinkingLevel,
|
|
165
|
+
prompt_tokens: promptTokens,
|
|
166
|
+
candidate_tokens: candidateTokens,
|
|
167
|
+
thinking_tokens: thinkingTokens,
|
|
168
|
+
total_tokens: totalTokens,
|
|
169
|
+
compute_duration_ms: durationMs,
|
|
170
|
+
cost_usd: costUsd,
|
|
171
|
+
},
|
|
172
|
+
files: [
|
|
173
|
+
{
|
|
174
|
+
name: 'draft_post.txt',
|
|
175
|
+
content: draftText,
|
|
176
|
+
contentType: 'text/plain',
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
name: 'execution_summary.json',
|
|
180
|
+
content: JSON.stringify({ jobId, taskId: targetTask?.id, telemetry, durationMs }, null, 2),
|
|
181
|
+
contentType: 'application/json',
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
payload: {
|
|
185
|
+
workerId: this.workerId,
|
|
186
|
+
jobId,
|
|
187
|
+
taskId: targetTask?.id,
|
|
188
|
+
draft_posts: [
|
|
189
|
+
{
|
|
190
|
+
platform: 'twitter_x',
|
|
191
|
+
text: draftText,
|
|
192
|
+
media: [],
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
actions: [
|
|
197
|
+
{
|
|
198
|
+
id: 'publish_x_post',
|
|
199
|
+
label: 'Approve for Cloud Dispatch',
|
|
200
|
+
endpoint: '/v1/deliverables/' + sessionId + '/publish',
|
|
201
|
+
variant: 'primary',
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
});
|
|
205
|
+
log('info', `Published deliverable manifest "${deliverable.id}" with SHA-256 integrity digest: ${deliverable.sha256}`);
|
|
206
|
+
// 6. Write Durable Job Execution Log to S3/GCS
|
|
207
|
+
const jobLog = {
|
|
208
|
+
jobId,
|
|
209
|
+
workerId: this.workerId,
|
|
210
|
+
taskId: targetTask?.id,
|
|
211
|
+
type: jobType,
|
|
212
|
+
status: 'success',
|
|
213
|
+
startedAt: new Date(startTime).toISOString(),
|
|
214
|
+
completedAt: new Date().toISOString(),
|
|
215
|
+
durationMs,
|
|
216
|
+
telemetry,
|
|
217
|
+
logs,
|
|
218
|
+
deliverableId: deliverable.id,
|
|
219
|
+
};
|
|
220
|
+
await this.hub.logJobExecution(jobLog);
|
|
221
|
+
log('info', `Wrote durable job execution log to workers/${this.workerId}/jobs/${jobId}/execution.json`);
|
|
222
|
+
return {
|
|
223
|
+
jobId,
|
|
224
|
+
workerId: this.workerId,
|
|
225
|
+
taskId: targetTask?.id,
|
|
226
|
+
type: jobType,
|
|
227
|
+
status: 'success',
|
|
228
|
+
telemetry,
|
|
229
|
+
deliverable,
|
|
230
|
+
logs,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import type { NotificationAction } from '../types.js';
|
|
2
|
+
export interface StorageDriver {
|
|
3
|
+
read(key: string): Promise<Uint8Array | null>;
|
|
4
|
+
readString(key: string): Promise<string | null>;
|
|
5
|
+
write(key: string, data: Uint8Array | string, contentType?: string): Promise<void>;
|
|
6
|
+
delete(key: string): Promise<void>;
|
|
7
|
+
list(prefix: string): Promise<string[]>;
|
|
8
|
+
exists(key: string): Promise<boolean>;
|
|
9
|
+
}
|
|
10
|
+
export interface WorkerManifest {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
version?: string;
|
|
15
|
+
tags?: string[];
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface WorkerBaseContext {
|
|
20
|
+
instructions?: string;
|
|
21
|
+
tools?: Record<string, any>[];
|
|
22
|
+
memory?: Record<string, any>;
|
|
23
|
+
updatedAt?: string;
|
|
24
|
+
}
|
|
25
|
+
export type WorkerSessionStatus = 'starting' | 'running' | 'completed' | 'failed' | 'paused';
|
|
26
|
+
export interface WorkerSessionState {
|
|
27
|
+
sessionId: string;
|
|
28
|
+
workerId: string;
|
|
29
|
+
status: WorkerSessionStatus;
|
|
30
|
+
progress?: number;
|
|
31
|
+
step?: string;
|
|
32
|
+
error?: string;
|
|
33
|
+
startedAt: string;
|
|
34
|
+
updatedAt: string;
|
|
35
|
+
completedAt?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface DeliverableFileRef {
|
|
38
|
+
name: string;
|
|
39
|
+
path: string;
|
|
40
|
+
sizeBytes: number;
|
|
41
|
+
sha256: string;
|
|
42
|
+
contentType?: string;
|
|
43
|
+
}
|
|
44
|
+
export type DeliverableReviewStatus = 'pending_review' | 'accepted' | 'approved' | 'rejected' | 'published' | 'dismissed';
|
|
45
|
+
export interface DeliverableTelemetry {
|
|
46
|
+
model?: string;
|
|
47
|
+
thinking_level?: string;
|
|
48
|
+
prompt_tokens?: number;
|
|
49
|
+
candidate_tokens?: number;
|
|
50
|
+
thinking_tokens?: number;
|
|
51
|
+
total_tokens?: number;
|
|
52
|
+
compute_duration_ms?: number;
|
|
53
|
+
cost_usd?: number;
|
|
54
|
+
}
|
|
55
|
+
export interface DeliverableReview {
|
|
56
|
+
decision: 'approved' | 'rejected' | 'published' | 'dismissed';
|
|
57
|
+
target?: 'cloud' | 'local';
|
|
58
|
+
reviewedBy?: string;
|
|
59
|
+
reviewedAt?: string | number;
|
|
60
|
+
note?: string;
|
|
61
|
+
txId?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface DeliverableManifest {
|
|
64
|
+
id: string;
|
|
65
|
+
workerId: string;
|
|
66
|
+
sessionId: string;
|
|
67
|
+
title: string;
|
|
68
|
+
summary?: string;
|
|
69
|
+
kind?: string;
|
|
70
|
+
status: DeliverableReviewStatus;
|
|
71
|
+
files: DeliverableFileRef[];
|
|
72
|
+
actions?: NotificationAction[];
|
|
73
|
+
payload?: Record<string, any>;
|
|
74
|
+
telemetry?: DeliverableTelemetry;
|
|
75
|
+
review?: DeliverableReview;
|
|
76
|
+
sha256?: string;
|
|
77
|
+
createdAt: string;
|
|
78
|
+
updatedAt: string;
|
|
79
|
+
}
|
|
80
|
+
export interface PublishDeliverableOptions {
|
|
81
|
+
id?: string;
|
|
82
|
+
sessionId: string;
|
|
83
|
+
title: string;
|
|
84
|
+
summary?: string;
|
|
85
|
+
kind?: string;
|
|
86
|
+
telemetry?: DeliverableTelemetry;
|
|
87
|
+
files?: Array<{
|
|
88
|
+
name: string;
|
|
89
|
+
content: string | Uint8Array;
|
|
90
|
+
contentType?: string;
|
|
91
|
+
}>;
|
|
92
|
+
actions?: NotificationAction[];
|
|
93
|
+
payload?: Record<string, any>;
|
|
94
|
+
}
|
|
95
|
+
export interface StorageHubConfig {
|
|
96
|
+
bucket?: string;
|
|
97
|
+
workerId: string;
|
|
98
|
+
driver: StorageDriver;
|
|
99
|
+
prefix?: string;
|
|
100
|
+
}
|
|
101
|
+
export type WorkerActorStatus = 'pending_approval' | 'active' | 'paused' | 'disabled';
|
|
102
|
+
export interface WorkerActorCloudConfig {
|
|
103
|
+
provider: 'gcp' | 'aws';
|
|
104
|
+
project?: string;
|
|
105
|
+
region?: string;
|
|
106
|
+
runtime: 'cloud-run-job' | 'ecs-task' | 'local';
|
|
107
|
+
job_name?: string;
|
|
108
|
+
service_account?: string;
|
|
109
|
+
image?: string;
|
|
110
|
+
env?: Record<string, string>;
|
|
111
|
+
}
|
|
112
|
+
export interface WorkerActorSchedule {
|
|
113
|
+
kind: 'cron' | 'interval' | 'trigger' | 'none';
|
|
114
|
+
cron?: string;
|
|
115
|
+
interval_seconds?: number;
|
|
116
|
+
timezone?: string;
|
|
117
|
+
enabled?: boolean;
|
|
118
|
+
}
|
|
119
|
+
export interface WorkerActorBrain {
|
|
120
|
+
model: string;
|
|
121
|
+
thinking_level?: string;
|
|
122
|
+
instructions: string;
|
|
123
|
+
tools?: Array<{
|
|
124
|
+
name: string;
|
|
125
|
+
description?: string;
|
|
126
|
+
parameters?: any;
|
|
127
|
+
}>;
|
|
128
|
+
secrets?: Record<string, string>;
|
|
129
|
+
memory?: Record<string, any>;
|
|
130
|
+
workspace_path?: string;
|
|
131
|
+
}
|
|
132
|
+
export interface WorkerActorTask {
|
|
133
|
+
id: string;
|
|
134
|
+
title: string;
|
|
135
|
+
type: 'automated' | 'one_off';
|
|
136
|
+
prompt: string;
|
|
137
|
+
status: 'pending' | 'running' | 'completed' | 'failed';
|
|
138
|
+
priority?: number;
|
|
139
|
+
createdAt: string;
|
|
140
|
+
startedAt?: string;
|
|
141
|
+
completedAt?: string;
|
|
142
|
+
sessionId?: string;
|
|
143
|
+
deliverableId?: string;
|
|
144
|
+
telemetry?: DeliverableTelemetry;
|
|
145
|
+
error?: string;
|
|
146
|
+
}
|
|
147
|
+
export interface WorkerJobExecutionTelemetry {
|
|
148
|
+
model: string;
|
|
149
|
+
thinking_level?: string;
|
|
150
|
+
prompt_tokens: number;
|
|
151
|
+
candidate_tokens: number;
|
|
152
|
+
thinking_tokens?: number;
|
|
153
|
+
total_tokens: number;
|
|
154
|
+
compute_duration_ms: number;
|
|
155
|
+
cost_usd: number;
|
|
156
|
+
}
|
|
157
|
+
export interface WorkerJobExecutionLog {
|
|
158
|
+
jobId: string;
|
|
159
|
+
workerId: string;
|
|
160
|
+
taskId?: string;
|
|
161
|
+
type: 'automation' | 'one_off';
|
|
162
|
+
status: 'success' | 'failed';
|
|
163
|
+
startedAt: string;
|
|
164
|
+
completedAt: string;
|
|
165
|
+
durationMs: number;
|
|
166
|
+
telemetry: WorkerJobExecutionTelemetry;
|
|
167
|
+
logs: Array<{
|
|
168
|
+
timestamp: string;
|
|
169
|
+
level: 'info' | 'warn' | 'error' | 'debug';
|
|
170
|
+
message: string;
|
|
171
|
+
data?: any;
|
|
172
|
+
}>;
|
|
173
|
+
deliverableId?: string;
|
|
174
|
+
error?: string;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Legacy storage WorkerActorSpec used by external cloud deployers and bucket runners.
|
|
178
|
+
*
|
|
179
|
+
* NOTE ON BOUNDARY RECONCILIATION:
|
|
180
|
+
* This legacy spec is NOT the daemon's canonical WorkerDocument / PortableWorkerDefinition.
|
|
181
|
+
* It cannot be silently converted or accepted as a canonical daemon worker document because
|
|
182
|
+
* doing so would silently drop cloud configuration, mutable task queues, and non-canonical schedules.
|
|
183
|
+
* Use canonical PortableWorkerDefinition with SwarmWorkersNamespace for daemon worker persistence.
|
|
184
|
+
*/
|
|
185
|
+
export interface WorkerActorSpec {
|
|
186
|
+
$schema?: string;
|
|
187
|
+
id: string;
|
|
188
|
+
name: string;
|
|
189
|
+
description?: string;
|
|
190
|
+
version: string;
|
|
191
|
+
status: WorkerActorStatus;
|
|
192
|
+
cloud?: WorkerActorCloudConfig;
|
|
193
|
+
schedule?: WorkerActorSchedule;
|
|
194
|
+
brain: WorkerActorBrain;
|
|
195
|
+
tasks?: WorkerActorTask[];
|
|
196
|
+
createdAt: string;
|
|
197
|
+
updatedAt: string;
|
|
198
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/system.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SwarmTransport } from './transport.js';
|
|
2
|
+
import type { SystemHealth } from './types.js';
|
|
3
|
+
export declare class SwarmSystemNamespace {
|
|
4
|
+
private transport;
|
|
5
|
+
constructor(transport: SwarmTransport);
|
|
6
|
+
/**
|
|
7
|
+
* Performs a health check against the daemon (/healthz, /readyz, or /health).
|
|
8
|
+
*/
|
|
9
|
+
health(): Promise<SystemHealth>;
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves operational status from the daemon.
|
|
12
|
+
*/
|
|
13
|
+
status(): Promise<Record<string, unknown>>;
|
|
14
|
+
}
|
package/dist/system.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export class SwarmSystemNamespace {
|
|
2
|
+
transport;
|
|
3
|
+
constructor(transport) {
|
|
4
|
+
this.transport = transport;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Performs a health check against the daemon (/healthz, /readyz, or /health).
|
|
8
|
+
*/
|
|
9
|
+
async health() {
|
|
10
|
+
try {
|
|
11
|
+
const res = await this.transport.request('/healthz', {
|
|
12
|
+
method: 'GET',
|
|
13
|
+
});
|
|
14
|
+
if (res.status === 200) {
|
|
15
|
+
if (res.data && typeof res.data === 'object' && res.data.ok !== undefined) {
|
|
16
|
+
return {
|
|
17
|
+
ok: Boolean(res.data.ok),
|
|
18
|
+
status: 'healthy',
|
|
19
|
+
uptime_seconds: res.data.uptime_ms ? Math.floor(res.data.uptime_ms / 1000) : undefined,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return { ok: true, status: 'healthy' };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch { }
|
|
26
|
+
try {
|
|
27
|
+
const res = await this.transport.request('/readyz', {
|
|
28
|
+
method: 'GET',
|
|
29
|
+
});
|
|
30
|
+
if (res.status === 200) {
|
|
31
|
+
return { ok: true, status: 'ready' };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch { }
|
|
35
|
+
const res = await this.transport.request('/health', {
|
|
36
|
+
method: 'GET',
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
ok: res.status === 200,
|
|
40
|
+
status: res.status === 200 ? 'healthy' : 'unhealthy',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Retrieves operational status from the daemon.
|
|
45
|
+
*/
|
|
46
|
+
async status() {
|
|
47
|
+
const res = await this.transport.request('/v1/status', {
|
|
48
|
+
method: 'GET',
|
|
49
|
+
});
|
|
50
|
+
return res.data;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RequestOptions, ResolvedSwarmClientConfig } from './types.js';
|
|
2
|
+
export interface TransportResponse<T = unknown> {
|
|
3
|
+
status: number;
|
|
4
|
+
headers: Record<string, string>;
|
|
5
|
+
data: T;
|
|
6
|
+
rawText: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class SwarmTransport {
|
|
9
|
+
private config;
|
|
10
|
+
constructor(config: ResolvedSwarmClientConfig);
|
|
11
|
+
setConfig(partial: Partial<ResolvedSwarmClientConfig>): void;
|
|
12
|
+
getConfig(): ResolvedSwarmClientConfig;
|
|
13
|
+
request<T = unknown>(path: string, options?: RequestOptions): Promise<TransportResponse<T>>;
|
|
14
|
+
private requestFetch;
|
|
15
|
+
private requestSocket;
|
|
16
|
+
private handleErrorResponse;
|
|
17
|
+
}
|