@swarm-agent/sdk 0.1.52 → 0.1.53
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 +17 -5
- package/dist/activity.d.ts +33 -0
- package/dist/activity.js +83 -0
- package/dist/agents.d.ts +432 -17
- package/dist/agents.js +529 -37
- package/dist/auth.d.ts +18 -3
- package/dist/auth.js +30 -2
- package/dist/client.d.ts +11 -0
- package/dist/client.js +14 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/job-automations.d.ts +343 -0
- package/dist/job-automations.js +74 -0
- package/dist/limits.d.ts +16 -0
- package/dist/limits.js +12 -0
- package/dist/projects.d.ts +11 -1
- package/dist/projects.js +30 -0
- package/dist/sessions.js +9 -1
- package/dist/types.d.ts +158 -0
- package/dist/workers.js +2 -0
- package/package.json +3 -3
package/dist/projects.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SwarmTransport } from './transport.js';
|
|
2
|
-
import type { ApproveProjectTaskResult, ClearProjectContextResult, CompleteProjectTaskResult, CreateProjectParams, CreateProjectTaskParams, CreateProjectTaskResult, DeleteProjectMediaResult, DeleteProjectResult, DeleteProjectTaskResult, DeployProjectTaskProgramResult, GetProjectTaskProgramResult, GetProjectTaskResult, IntegrateProjectTaskOptions, IntegrateProjectTaskResult, IntegrateProjectTaskSelection, ListProjectsParams, PreviewProjectTaskParams, ProjectRecord, ProjectTaskApprovalGuards, ProjectTaskMediaRef, ProjectTaskModelPreviewResult, ProjectTaskPreviewResult, ProjectTaskRecord, RedeployProjectTaskJobResult, RefineProjectTaskParams, RefineProjectTaskResult, RejectProjectTaskResult, ReopenProjectTaskResult, RequestOptions, SessionRecord, SyncStreamParams, SyncStreamResult, UpdateProjectParams, UpdateProjectTaskParams } from './types.js';
|
|
2
|
+
import type { ApproveProjectTaskResult, CancelDesignJobResult, ClearProjectContextResult, CompleteProjectTaskResult, CreateDesignJobParams, CreateDesignJobResult, CreateProjectParams, CreateProjectTaskParams, CreateProjectTaskResult, DeleteProjectMediaResult, DeleteProjectResult, DeleteProjectTaskResult, DeployProjectTaskProgramResult, GetProjectTaskProgramResult, GetProjectTaskResult, IntegrateProjectTaskOptions, IntegrateProjectTaskResult, IntegrateProjectTaskSelection, ListProjectsParams, PreviewProjectTaskParams, ProjectRecord, ProjectTaskApprovalGuards, ProjectTaskMediaRef, ProjectTaskModelPreviewResult, ProjectTaskPreviewResult, ProjectTaskRecord, RedeployProjectTaskJobResult, RefineProjectTaskParams, RefineProjectTaskResult, RejectProjectTaskResult, ReopenProjectTaskResult, RequestOptions, SessionRecord, SyncStreamParams, SyncStreamResult, UpdateProjectParams, UpdateProjectTaskParams } from './types.js';
|
|
3
3
|
export declare class SwarmProjectsNamespace {
|
|
4
4
|
private readonly transport;
|
|
5
5
|
constructor(transport: SwarmTransport);
|
|
@@ -89,6 +89,16 @@ export declare class SwarmProjectsNamespace {
|
|
|
89
89
|
* Creates a new autonomous task inside a project.
|
|
90
90
|
*/
|
|
91
91
|
createTask(projectId: string, params: CreateProjectTaskParams, options?: RequestOptions): Promise<CreateProjectTaskResult>;
|
|
92
|
+
/**
|
|
93
|
+
* Starts a design job: count standalone HTML designs (or an edit of one
|
|
94
|
+
* existing .html file) written into the project folder. Returns the job's
|
|
95
|
+
* task at once; read progress with getTask (task.design).
|
|
96
|
+
*/
|
|
97
|
+
createDesignJob(projectId: string, params: CreateDesignJobParams, options?: RequestOptions): Promise<CreateDesignJobResult>;
|
|
98
|
+
/**
|
|
99
|
+
* Stops a running design job. Designs already written stay in the folder.
|
|
100
|
+
*/
|
|
101
|
+
cancelDesignJob(projectId: string, taskId: string, options?: RequestOptions): Promise<CancelDesignJobResult>;
|
|
92
102
|
/**
|
|
93
103
|
* Retrieves a single task by ID within a project, including model preview.
|
|
94
104
|
*/
|
package/dist/projects.js
CHANGED
|
@@ -272,6 +272,36 @@ export class SwarmProjectsNamespace {
|
|
|
272
272
|
}
|
|
273
273
|
throw new SwarmApiError('Malformed response: missing task record', { status: res.status, details: data });
|
|
274
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* Starts a design job: count standalone HTML designs (or an edit of one
|
|
277
|
+
* existing .html file) written into the project folder. Returns the job's
|
|
278
|
+
* task at once; read progress with getTask (task.design).
|
|
279
|
+
*/
|
|
280
|
+
async createDesignJob(projectId, params, options) {
|
|
281
|
+
const id = encodeURIComponent(projectId.trim());
|
|
282
|
+
const res = await this.transport.request(`/v3/projects/${id}/design-jobs`, {
|
|
283
|
+
method: 'POST',
|
|
284
|
+
body: params,
|
|
285
|
+
...options,
|
|
286
|
+
});
|
|
287
|
+
const data = res.data;
|
|
288
|
+
if (data && typeof data === 'object' && data.task && data.task.design) {
|
|
289
|
+
return { task: data.task };
|
|
290
|
+
}
|
|
291
|
+
throw new SwarmApiError('Malformed response: missing design job task', { status: res.status, details: data });
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Stops a running design job. Designs already written stay in the folder.
|
|
295
|
+
*/
|
|
296
|
+
async cancelDesignJob(projectId, taskId, options) {
|
|
297
|
+
const pId = encodeURIComponent(projectId.trim());
|
|
298
|
+
const tId = encodeURIComponent(taskId.trim());
|
|
299
|
+
const res = await this.transport.request(`/v3/projects/${pId}/design-jobs/${tId}/cancel`, { method: 'POST', body: {}, ...options });
|
|
300
|
+
if (res.data && typeof res.data === 'object' && typeof res.data.status === 'string') {
|
|
301
|
+
return res.data;
|
|
302
|
+
}
|
|
303
|
+
throw new SwarmApiError('Malformed response: missing design job cancel status', { status: res.status, details: res.data });
|
|
304
|
+
}
|
|
275
305
|
/**
|
|
276
306
|
* Retrieves a single task by ID within a project, including model preview.
|
|
277
307
|
*/
|
package/dist/sessions.js
CHANGED
|
@@ -28,11 +28,17 @@ export class SwarmSessionsNamespace {
|
|
|
28
28
|
workspace_path: params.workspace_path,
|
|
29
29
|
mode: params.mode ?? 'auto',
|
|
30
30
|
metadata: params.metadata,
|
|
31
|
+
...(params.end_user !== undefined ? { end_user: params.end_user } : {}),
|
|
32
|
+
...(params.labels !== undefined ? { labels: params.labels } : {}),
|
|
31
33
|
},
|
|
32
34
|
});
|
|
33
35
|
const data = res.data;
|
|
34
36
|
if (data && typeof data === 'object' && 'session' in data && data.session) {
|
|
35
|
-
return
|
|
37
|
+
return {
|
|
38
|
+
...data.session,
|
|
39
|
+
...(typeof data.end_user === 'string' ? { end_user: data.end_user } : {}),
|
|
40
|
+
...(data.labels && typeof data.labels === 'object' ? { labels: data.labels } : {}),
|
|
41
|
+
};
|
|
36
42
|
}
|
|
37
43
|
return data;
|
|
38
44
|
}
|
|
@@ -102,6 +108,8 @@ export class SwarmSessionsNamespace {
|
|
|
102
108
|
messages: data.messages,
|
|
103
109
|
last_run_id: sessionObj.last_run_id,
|
|
104
110
|
active_plan: data.active_plan,
|
|
111
|
+
...(typeof data.end_user === 'string' ? { end_user: data.end_user } : {}),
|
|
112
|
+
...(data.labels && typeof data.labels === 'object' ? { labels: data.labels } : {}),
|
|
105
113
|
raw: data,
|
|
106
114
|
};
|
|
107
115
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -36,17 +36,62 @@ export interface ScopedTokenRecord {
|
|
|
36
36
|
scopes: TokenScope[];
|
|
37
37
|
worker_id?: string;
|
|
38
38
|
worker_name?: string;
|
|
39
|
+
/** The fixed end date, when the key has one (milliseconds; 0 or absent: none). */
|
|
39
40
|
expires_at?: number;
|
|
41
|
+
/** ai, app, bot or internal (Swarm's own keys). */
|
|
42
|
+
key_kind?: KeyKind | 'internal';
|
|
43
|
+
/** An AI key's level (read, write, full); a bot key's gateway or operator; an app key's monitor or trigger. */
|
|
44
|
+
options?: string[];
|
|
45
|
+
/** active, expired or revoked. */
|
|
46
|
+
state?: 'active' | 'expired' | 'revoked';
|
|
47
|
+
/** When the key stops working on its own (milliseconds): 90 days after its last use, or its fixed end date if sooner. */
|
|
48
|
+
lapses_at?: number;
|
|
49
|
+
/** unused (90 days without use) or date (its fixed end date). */
|
|
50
|
+
lapse_reason?: 'unused' | 'date';
|
|
51
|
+
/** True when the key carries a fixed end date. */
|
|
52
|
+
fixed_date?: boolean;
|
|
53
|
+
/** True only for Swarm's internal keys, which last as long as the setup that made them. */
|
|
54
|
+
never_expires?: boolean;
|
|
40
55
|
last_used_at?: number;
|
|
56
|
+
/** Where the key was last used from: "this machine", "tailnet LOGIN" or a network such as 203.0.113.0/24. */
|
|
57
|
+
last_used_from?: string;
|
|
58
|
+
/** Every place the key has been used from (newest last, bounded). */
|
|
59
|
+
seen_from?: string[];
|
|
41
60
|
created_at: number;
|
|
42
61
|
revoked?: boolean;
|
|
43
62
|
revoked_at?: number;
|
|
44
63
|
}
|
|
64
|
+
/** The three kinds of key a person or their AI holds. */
|
|
65
|
+
export type KeyKind = 'ai' | 'app' | 'bot';
|
|
66
|
+
/**
|
|
67
|
+
* A key for createKey. Every key works while it is used and stops after 90
|
|
68
|
+
* days unused; expires_in_seconds adds an optional fixed end date (at most 365
|
|
69
|
+
* days). kind ai: access read, write or full. kind app: scopes, or monitor for
|
|
70
|
+
* a status-only key. kind bot: agent_name (a sealed agent), operator for the
|
|
71
|
+
* staff key, and its limits.
|
|
72
|
+
*/
|
|
73
|
+
export interface CreateKeyParams {
|
|
74
|
+
kind: KeyKind;
|
|
75
|
+
name: string;
|
|
76
|
+
access?: 'read' | 'write' | 'full';
|
|
77
|
+
scopes?: TokenScope[];
|
|
78
|
+
monitor?: boolean;
|
|
79
|
+
agent_name?: string;
|
|
80
|
+
operator?: boolean;
|
|
81
|
+
messages_per_minute?: number;
|
|
82
|
+
sessions_per_hour?: number;
|
|
83
|
+
max_concurrent_runs?: number;
|
|
84
|
+
end_user_messages_per_minute?: number;
|
|
85
|
+
end_user_sessions_per_hour?: number;
|
|
86
|
+
end_user_max_tokens_per_day?: number;
|
|
87
|
+
expires_in_seconds?: number;
|
|
88
|
+
}
|
|
45
89
|
export interface CreateScopedTokenParams {
|
|
46
90
|
name: string;
|
|
47
91
|
scopes: TokenScope[];
|
|
48
92
|
worker_id?: string;
|
|
49
93
|
worker_name?: string;
|
|
94
|
+
/** Optional fixed end date (at most 365 days). Without it the key works while used and stops after 90 days unused. */
|
|
50
95
|
expires_in_seconds?: number;
|
|
51
96
|
}
|
|
52
97
|
export interface CreateScopedTokenResult {
|
|
@@ -291,6 +336,9 @@ export interface SessionRecord {
|
|
|
291
336
|
archived?: boolean;
|
|
292
337
|
archived_at?: number;
|
|
293
338
|
last_run_id?: string;
|
|
339
|
+
/** Set when a gateway created the session for an end user. */
|
|
340
|
+
end_user?: string;
|
|
341
|
+
labels?: Record<string, string>;
|
|
294
342
|
}
|
|
295
343
|
export interface CreateSessionParams {
|
|
296
344
|
title?: string;
|
|
@@ -302,6 +350,14 @@ export interface CreateSessionParams {
|
|
|
302
350
|
mode?: 'auto' | 'plan';
|
|
303
351
|
client_request_id?: string;
|
|
304
352
|
metadata?: Record<string, unknown>;
|
|
353
|
+
/**
|
|
354
|
+
* Whose conversation this is (your customer or visitor id): 1-128 letters,
|
|
355
|
+
* digits and `. _ : @ + = -`. Only a gateway token may set it, once; the model
|
|
356
|
+
* never sees it, and per-end-user limits and usage use it.
|
|
357
|
+
*/
|
|
358
|
+
end_user?: string;
|
|
359
|
+
/** Up to 16 labels stored with the session (keys: lowercase identifiers; values: up to 256 characters). */
|
|
360
|
+
labels?: Record<string, string>;
|
|
305
361
|
}
|
|
306
362
|
export interface ListSessionsParams {
|
|
307
363
|
limit?: number;
|
|
@@ -331,6 +387,9 @@ export interface SessionDetail {
|
|
|
331
387
|
messages?: SessionMessage[];
|
|
332
388
|
last_run_id?: string;
|
|
333
389
|
active_plan?: unknown;
|
|
390
|
+
/** Set when a gateway created the session for an end user. */
|
|
391
|
+
end_user?: string;
|
|
392
|
+
labels?: Record<string, string>;
|
|
334
393
|
raw?: Record<string, unknown>;
|
|
335
394
|
}
|
|
336
395
|
export interface WorkspaceRecord {
|
|
@@ -633,9 +692,88 @@ export interface ProjectTaskRecord {
|
|
|
633
692
|
task_program?: any;
|
|
634
693
|
task_program_id?: string;
|
|
635
694
|
task_program_status?: any;
|
|
695
|
+
/** Present when the task is a design job (createDesignJob). */
|
|
696
|
+
design?: ProjectTaskDesignJob;
|
|
636
697
|
created_at: number;
|
|
637
698
|
updated_at: number;
|
|
638
699
|
}
|
|
700
|
+
/** One check finding kept on a design job item. */
|
|
701
|
+
export interface ProjectTaskDesignDiagnostic {
|
|
702
|
+
kind: string;
|
|
703
|
+
message?: string;
|
|
704
|
+
}
|
|
705
|
+
/** One design's durable outcome in a design job. */
|
|
706
|
+
export interface ProjectTaskDesignItem {
|
|
707
|
+
n: number;
|
|
708
|
+
path?: string;
|
|
709
|
+
sha256?: string;
|
|
710
|
+
status: 'passed' | 'repaired' | 'failed' | 'check_unavailable' | 'generation_failed' | 'skipped_budget' | 'cancelled' | 'stale_base' | 'edit_refused' | string;
|
|
711
|
+
error?: string;
|
|
712
|
+
variation?: string;
|
|
713
|
+
check?: string;
|
|
714
|
+
diagnostics?: ProjectTaskDesignDiagnostic[];
|
|
715
|
+
repair_edits?: number;
|
|
716
|
+
repair_refused?: string;
|
|
717
|
+
check_after_repair?: string;
|
|
718
|
+
diagnostics_after_repair?: ProjectTaskDesignDiagnostic[];
|
|
719
|
+
calls: number;
|
|
720
|
+
tokens: number;
|
|
721
|
+
/** Absent when the provider reported no usage or the model has no price. */
|
|
722
|
+
cost_usd?: number;
|
|
723
|
+
usage_complete: boolean;
|
|
724
|
+
duration_ms: number;
|
|
725
|
+
}
|
|
726
|
+
/** The request and outcome of a design job. */
|
|
727
|
+
export interface ProjectTaskDesignJob {
|
|
728
|
+
mode: 'create' | 'edit';
|
|
729
|
+
brief: string;
|
|
730
|
+
count: number;
|
|
731
|
+
style?: string;
|
|
732
|
+
variations?: string[];
|
|
733
|
+
batch_name?: string;
|
|
734
|
+
/** The job's own output folder, relative to the workspace (create). */
|
|
735
|
+
folder?: string;
|
|
736
|
+
results_path?: string;
|
|
737
|
+
edit_path?: string;
|
|
738
|
+
state: 'running' | 'completed' | 'failed' | 'cancelled';
|
|
739
|
+
error?: string;
|
|
740
|
+
provider?: string;
|
|
741
|
+
model?: string;
|
|
742
|
+
thinking?: string;
|
|
743
|
+
items?: ProjectTaskDesignItem[];
|
|
744
|
+
counts?: Record<string, number>;
|
|
745
|
+
calls: number;
|
|
746
|
+
tokens: number;
|
|
747
|
+
cost_usd: number;
|
|
748
|
+
cost_complete: boolean;
|
|
749
|
+
edit_base_sha256?: string;
|
|
750
|
+
edit_final_sha256?: string;
|
|
751
|
+
results_error?: string;
|
|
752
|
+
started_at: number;
|
|
753
|
+
finished_at?: number;
|
|
754
|
+
}
|
|
755
|
+
/** Body of createDesignJob: make count designs, or edit one HTML file. */
|
|
756
|
+
export interface CreateDesignJobParams {
|
|
757
|
+
/** Absolute folder of the project; required when the project has several. */
|
|
758
|
+
workspace?: string;
|
|
759
|
+
brief: string;
|
|
760
|
+
/** 1 to 50 (default 1); an edit is always 1. */
|
|
761
|
+
count?: number;
|
|
762
|
+
style?: string;
|
|
763
|
+
variations?: string[];
|
|
764
|
+
batch_name?: string;
|
|
765
|
+
/** Parent folder for batches, relative to the workspace (default designs). */
|
|
766
|
+
folder?: string;
|
|
767
|
+
/** Edit this existing .html file (relative to the workspace) instead. */
|
|
768
|
+
edit_path?: string;
|
|
769
|
+
}
|
|
770
|
+
export interface CreateDesignJobResult {
|
|
771
|
+
task: ProjectTaskRecord;
|
|
772
|
+
}
|
|
773
|
+
export interface CancelDesignJobResult {
|
|
774
|
+
task_id: string;
|
|
775
|
+
status: string;
|
|
776
|
+
}
|
|
639
777
|
export interface CreateProjectTaskParams {
|
|
640
778
|
id?: string;
|
|
641
779
|
title: string;
|
|
@@ -1035,7 +1173,25 @@ export interface WorkerRevisionRecord {
|
|
|
1035
1173
|
committed_by?: string;
|
|
1036
1174
|
change_summary?: string;
|
|
1037
1175
|
}
|
|
1176
|
+
export interface JobReview {
|
|
1177
|
+
verdict: 'ok' | 'block';
|
|
1178
|
+
head: string;
|
|
1179
|
+
reviewer_job_id: string;
|
|
1180
|
+
model: string;
|
|
1181
|
+
at: number;
|
|
1182
|
+
reason?: string;
|
|
1183
|
+
/** Set when a fixing reviewer committed on top of `head`: the verdict covers `head` only with those fixes. */
|
|
1184
|
+
fix_head?: string;
|
|
1185
|
+
stale: boolean;
|
|
1186
|
+
}
|
|
1038
1187
|
export interface WorkerRunRecord {
|
|
1188
|
+
review?: Partial<JobReview> & {
|
|
1189
|
+
state?: string;
|
|
1190
|
+
project_id?: string;
|
|
1191
|
+
task_id?: string;
|
|
1192
|
+
task_status?: string;
|
|
1193
|
+
next_action?: string;
|
|
1194
|
+
};
|
|
1039
1195
|
placement?: import('./worker-control.js').WorkerRunPlacement;
|
|
1040
1196
|
cancel_requested?: boolean;
|
|
1041
1197
|
id: string;
|
|
@@ -1185,6 +1341,8 @@ export interface SetWorkerAutomationEnabledParams {
|
|
|
1185
1341
|
expected_worker_revision: number;
|
|
1186
1342
|
}
|
|
1187
1343
|
export interface DirectWorkerRequestParams {
|
|
1344
|
+
/** Required for reviewer workers: worker/<worker>/<run> in the same project, with commits. */
|
|
1345
|
+
review_job?: string;
|
|
1188
1346
|
worker_id: string;
|
|
1189
1347
|
prompt?: string;
|
|
1190
1348
|
input?: Record<string, unknown>;
|
package/dist/workers.js
CHANGED
|
@@ -608,6 +608,8 @@ export class SwarmWorkersNamespace {
|
|
|
608
608
|
const body = {};
|
|
609
609
|
if (hasPrompt)
|
|
610
610
|
body.prompt = params.prompt.trim();
|
|
611
|
+
if (params.review_job !== undefined)
|
|
612
|
+
body.review_job = params.review_job.trim();
|
|
611
613
|
if (params.input)
|
|
612
614
|
body.input = params.input;
|
|
613
615
|
if (params.idempotency_key)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swarm-agent/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.53",
|
|
4
4
|
"description": "Official TypeScript SDK for Swarm local AI coding workspace",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"node": ">=22"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"ws": "8.
|
|
45
|
+
"ws": "8.22.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/node": "22.19.15",
|
|
49
49
|
"@types/ws": "^8.18.2",
|
|
50
|
-
"tsx": "4.
|
|
50
|
+
"tsx": "4.23.15",
|
|
51
51
|
"typescript": "5.9.3"
|
|
52
52
|
},
|
|
53
53
|
"keywords": [
|