@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/auth.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SwarmCredentialsNamespace, SwarmCodexAuthNamespace } from './provider-auth.js';
|
|
2
2
|
import type { SwarmTransport } from './transport.js';
|
|
3
|
-
import type { CreateScopedTokenParams, CreateScopedTokenResult, DesktopSessionBootstrap, ScopedTokenRecord } from './types.js';
|
|
3
|
+
import type { CreateKeyParams, CreateScopedTokenParams, CreateScopedTokenResult, DesktopSessionBootstrap, ScopedTokenRecord } from './types.js';
|
|
4
4
|
export declare class SwarmAuthNamespace {
|
|
5
5
|
readonly credentials: SwarmCredentialsNamespace;
|
|
6
6
|
readonly codex: SwarmCodexAuthNamespace;
|
|
@@ -18,6 +18,8 @@ export declare class SwarmAuthNamespace {
|
|
|
18
18
|
}): Promise<DesktopSessionBootstrap>;
|
|
19
19
|
/**
|
|
20
20
|
* Creates a new scoped deploy token with granular permission scopes.
|
|
21
|
+
* Every key works while it is used and stops after 90 days unused;
|
|
22
|
+
* `expires_in_seconds` adds an optional fixed end date (at most 365 days).
|
|
21
23
|
* Returns the plaintext token (prefixed with 'swk_') along with the token record.
|
|
22
24
|
* Store the token securely—it cannot be retrieved again in plaintext!
|
|
23
25
|
*/
|
|
@@ -29,8 +31,9 @@ export declare class SwarmAuthNamespace {
|
|
|
29
31
|
* their own browser); neither may approve tool calls or manage anything. `full`
|
|
30
32
|
* keys are for an AI the owner trusts to run the box: they also approve
|
|
31
33
|
* tool calls and manage models, workers, limits, custom agents and client app
|
|
32
|
-
* keys. Every level reaches only `/mcp`.
|
|
33
|
-
*
|
|
34
|
+
* keys. Every level reaches only `/mcp`. The key works while it is used and
|
|
35
|
+
* stops after 90 days unused; `expires_in_seconds` adds an optional fixed
|
|
36
|
+
* end date (at most 365 days). Owner only.
|
|
34
37
|
*/
|
|
35
38
|
createAIKey(params: {
|
|
36
39
|
name: string;
|
|
@@ -42,6 +45,18 @@ export declare class SwarmAuthNamespace {
|
|
|
42
45
|
* Secret hashes are masked; hints (e.g. 'swk_...abcd') are displayed.
|
|
43
46
|
*/
|
|
44
47
|
listScopedTokens(): Promise<ScopedTokenRecord[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Makes a key of one of the three kinds (see CreateKeyParams) and returns it
|
|
50
|
+
* once with its record (key_kind, lapses_at, lapse_reason). Owner only.
|
|
51
|
+
*/
|
|
52
|
+
createKey(params: CreateKeyParams): Promise<CreateScopedTokenResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Every key that reaches this box, with its kind, state, last use and where
|
|
55
|
+
* from, and when it stops working on its own. Owner only.
|
|
56
|
+
*/
|
|
57
|
+
listKeys(): Promise<ScopedTokenRecord[]>;
|
|
58
|
+
/** Stops a key working now, and every key made with it. Owner only. */
|
|
59
|
+
revokeKey(keyId: string): Promise<ScopedTokenRecord>;
|
|
45
60
|
/**
|
|
46
61
|
* Revokes a scoped token by ID.
|
|
47
62
|
* The token immediately ceases to authenticate requests.
|
package/dist/auth.js
CHANGED
|
@@ -38,6 +38,8 @@ export class SwarmAuthNamespace {
|
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* Creates a new scoped deploy token with granular permission scopes.
|
|
41
|
+
* Every key works while it is used and stops after 90 days unused;
|
|
42
|
+
* `expires_in_seconds` adds an optional fixed end date (at most 365 days).
|
|
41
43
|
* Returns the plaintext token (prefixed with 'swk_') along with the token record.
|
|
42
44
|
* Store the token securely—it cannot be retrieved again in plaintext!
|
|
43
45
|
*/
|
|
@@ -61,8 +63,9 @@ export class SwarmAuthNamespace {
|
|
|
61
63
|
* their own browser); neither may approve tool calls or manage anything. `full`
|
|
62
64
|
* keys are for an AI the owner trusts to run the box: they also approve
|
|
63
65
|
* tool calls and manage models, workers, limits, custom agents and client app
|
|
64
|
-
* keys. Every level reaches only `/mcp`.
|
|
65
|
-
*
|
|
66
|
+
* keys. Every level reaches only `/mcp`. The key works while it is used and
|
|
67
|
+
* stops after 90 days unused; `expires_in_seconds` adds an optional fixed
|
|
68
|
+
* end date (at most 365 days). Owner only.
|
|
66
69
|
*/
|
|
67
70
|
async createAIKey(params) {
|
|
68
71
|
const res = await this.transport.request('/v3/auth/tokens', {
|
|
@@ -81,6 +84,31 @@ export class SwarmAuthNamespace {
|
|
|
81
84
|
});
|
|
82
85
|
return res.data?.tokens ?? [];
|
|
83
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Makes a key of one of the three kinds (see CreateKeyParams) and returns it
|
|
89
|
+
* once with its record (key_kind, lapses_at, lapse_reason). Owner only.
|
|
90
|
+
*/
|
|
91
|
+
async createKey(params) {
|
|
92
|
+
const { kind, name, access, expires_in_seconds, ...rest } = params;
|
|
93
|
+
const body = { kind, name, ...rest };
|
|
94
|
+
if (kind === 'ai')
|
|
95
|
+
body.ai_access = access;
|
|
96
|
+
if (expires_in_seconds !== undefined)
|
|
97
|
+
body.expires_in_seconds = expires_in_seconds;
|
|
98
|
+
const res = await this.transport.request('/v3/auth/tokens', { method: 'POST', body });
|
|
99
|
+
return res.data;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Every key that reaches this box, with its kind, state, last use and where
|
|
103
|
+
* from, and when it stops working on its own. Owner only.
|
|
104
|
+
*/
|
|
105
|
+
async listKeys() {
|
|
106
|
+
return this.listScopedTokens();
|
|
107
|
+
}
|
|
108
|
+
/** Stops a key working now, and every key made with it. Owner only. */
|
|
109
|
+
async revokeKey(keyId) {
|
|
110
|
+
return this.revokeScopedToken(keyId);
|
|
111
|
+
}
|
|
84
112
|
/**
|
|
85
113
|
* Revokes a scoped token by ID.
|
|
86
114
|
* The token immediately ceases to authenticate requests.
|
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SwarmLimitsNamespace } from './limits.js';
|
|
1
2
|
import { SwarmAgentsNamespace } from './agents.js';
|
|
2
3
|
import { SwarmAppsNamespace } from './apps.js';
|
|
3
4
|
import { SwarmChatNamespace } from './chat.js';
|
|
@@ -13,6 +14,8 @@ import { SwarmDeliverablesNamespace } from './deliverables.js';
|
|
|
13
14
|
import { SwarmDeployNamespace } from './deploy/index.js';
|
|
14
15
|
import { SwarmNotificationsNamespace } from './notifications.js';
|
|
15
16
|
import { SwarmSignalsNamespace } from './signals.js';
|
|
17
|
+
import { SwarmJobAutomationsNamespace } from './job-automations.js';
|
|
18
|
+
import { SwarmActivityNamespace } from './activity.js';
|
|
16
19
|
import { SwarmBoxNamespace } from './box.js';
|
|
17
20
|
import { SwarmProjectsNamespace } from './projects.js';
|
|
18
21
|
import { SwarmRemoteNamespace } from './remote.js';
|
|
@@ -39,6 +42,7 @@ export declare class SwarmClient {
|
|
|
39
42
|
* revisions, attached automations, and portable import/export definitions over /v3/workers.
|
|
40
43
|
*/
|
|
41
44
|
readonly workers: SwarmWorkersNamespace;
|
|
45
|
+
readonly limits: SwarmLimitsNamespace;
|
|
42
46
|
readonly usage: SwarmUsageNamespace;
|
|
43
47
|
readonly deliverables: SwarmDeliverablesNamespace;
|
|
44
48
|
/** Convenient alias for deliverables namespace: mailbox */
|
|
@@ -58,6 +62,13 @@ export declare class SwarmClient {
|
|
|
58
62
|
readonly inbox: SwarmNotificationsNamespace;
|
|
59
63
|
/** Machine signal feed: blocked agents, failures, refused keys, reported events. */
|
|
60
64
|
readonly signals: SwarmSignalsNamespace;
|
|
65
|
+
/**
|
|
66
|
+
* Workflows: steps Swarm runs when a task of its own agents or a worker job
|
|
67
|
+
* ends (/v3/workflows, /v3/job-deliveries). Not the legacy `automations`
|
|
68
|
+
* namespace.
|
|
69
|
+
*/
|
|
70
|
+
readonly workflows: SwarmJobAutomationsNamespace;
|
|
71
|
+
readonly activity: SwarmActivityNamespace;
|
|
61
72
|
/** Machine state for monitors: sandbox, blocked sessions, failing workers, usage. */
|
|
62
73
|
readonly box: SwarmBoxNamespace;
|
|
63
74
|
readonly storage: SwarmStorageNamespace;
|
package/dist/client.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SwarmLimitsNamespace } from './limits.js';
|
|
1
2
|
import { SwarmAgentsNamespace } from './agents.js';
|
|
2
3
|
import { SwarmAppsNamespace } from './apps.js';
|
|
3
4
|
import { SwarmChatNamespace } from './chat.js';
|
|
@@ -13,6 +14,8 @@ import { SwarmDeliverablesNamespace } from './deliverables.js';
|
|
|
13
14
|
import { SwarmDeployNamespace } from './deploy/index.js';
|
|
14
15
|
import { SwarmNotificationsNamespace } from './notifications.js';
|
|
15
16
|
import { SwarmSignalsNamespace } from './signals.js';
|
|
17
|
+
import { SwarmJobAutomationsNamespace } from './job-automations.js';
|
|
18
|
+
import { SwarmActivityNamespace } from './activity.js';
|
|
16
19
|
import { SwarmBoxNamespace } from './box.js';
|
|
17
20
|
import { SwarmProjectsNamespace } from './projects.js';
|
|
18
21
|
import { SwarmRemoteNamespace } from './remote.js';
|
|
@@ -39,6 +42,7 @@ export class SwarmClient {
|
|
|
39
42
|
* revisions, attached automations, and portable import/export definitions over /v3/workers.
|
|
40
43
|
*/
|
|
41
44
|
workers;
|
|
45
|
+
limits;
|
|
42
46
|
usage;
|
|
43
47
|
deliverables;
|
|
44
48
|
/** Convenient alias for deliverables namespace: mailbox */
|
|
@@ -58,6 +62,13 @@ export class SwarmClient {
|
|
|
58
62
|
inbox;
|
|
59
63
|
/** Machine signal feed: blocked agents, failures, refused keys, reported events. */
|
|
60
64
|
signals;
|
|
65
|
+
/**
|
|
66
|
+
* Workflows: steps Swarm runs when a task of its own agents or a worker job
|
|
67
|
+
* ends (/v3/workflows, /v3/job-deliveries). Not the legacy `automations`
|
|
68
|
+
* namespace.
|
|
69
|
+
*/
|
|
70
|
+
workflows;
|
|
71
|
+
activity;
|
|
61
72
|
/** Machine state for monitors: sandbox, blocked sessions, failing workers, usage. */
|
|
62
73
|
box;
|
|
63
74
|
storage;
|
|
@@ -88,6 +99,7 @@ export class SwarmClient {
|
|
|
88
99
|
this.realtime = new SwarmRealtimeNamespace(this.transport);
|
|
89
100
|
this.automations = new SwarmAutomationsNamespace(this.transport);
|
|
90
101
|
this.workers = new SwarmWorkersNamespace(this.transport);
|
|
102
|
+
this.limits = new SwarmLimitsNamespace(this.transport);
|
|
91
103
|
this.usage = new SwarmUsageNamespace(this.transport);
|
|
92
104
|
this.deliverables = new SwarmDeliverablesNamespace(this.transport);
|
|
93
105
|
this.mailbox = this.deliverables;
|
|
@@ -102,6 +114,8 @@ export class SwarmClient {
|
|
|
102
114
|
this.notifications = new SwarmNotificationsNamespace(this.transport);
|
|
103
115
|
this.inbox = this.notifications;
|
|
104
116
|
this.signals = new SwarmSignalsNamespace(this.transport);
|
|
117
|
+
this.workflows = new SwarmJobAutomationsNamespace(this.transport);
|
|
118
|
+
this.activity = new SwarmActivityNamespace(this.transport);
|
|
105
119
|
this.box = new SwarmBoxNamespace(this.transport);
|
|
106
120
|
this.agents = new SwarmAgentsNamespace(this.transport);
|
|
107
121
|
this.storage = new SwarmStorageNamespace(this.transport);
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export * from './deliverables.js';
|
|
|
8
8
|
export * from './deploy/index.js';
|
|
9
9
|
export * from './notifications.js';
|
|
10
10
|
export * from './signals.js';
|
|
11
|
+
export * from './job-automations.js';
|
|
12
|
+
export * from './activity.js';
|
|
11
13
|
export * from './box.js';
|
|
12
14
|
export * from './sessions.js';
|
|
13
15
|
export * from './projects.js';
|
|
@@ -32,3 +34,5 @@ export * from './realtime.js';
|
|
|
32
34
|
export * from './websocket.js';
|
|
33
35
|
export * from './browser.js';
|
|
34
36
|
export type { ApplicationResults, ApplicationResultsOptions } from './app-results.js';
|
|
37
|
+
export { SwarmLimitsNamespace } from './limits.js';
|
|
38
|
+
export type { BoxLimits } from './limits.js';
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,8 @@ export * from './deliverables.js';
|
|
|
8
8
|
export * from './deploy/index.js';
|
|
9
9
|
export * from './notifications.js';
|
|
10
10
|
export * from './signals.js';
|
|
11
|
+
export * from './job-automations.js';
|
|
12
|
+
export * from './activity.js';
|
|
11
13
|
export * from './box.js';
|
|
12
14
|
export * from './sessions.js';
|
|
13
15
|
export * from './projects.js';
|
|
@@ -29,3 +31,4 @@ export * from './provider-auth.js';
|
|
|
29
31
|
export * from './realtime.js';
|
|
30
32
|
export * from './websocket.js';
|
|
31
33
|
export * from './browser.js';
|
|
34
|
+
export { SwarmLimitsNamespace } from './limits.js';
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import type { SwarmTransport } from './transport.js';
|
|
2
|
+
/**
|
|
3
|
+
* Job automations: the steps Swarm runs when a job ends. Swarm gives
|
|
4
|
+
* primitives, never a built-in path: with no automation a job ends with its
|
|
5
|
+
* branch and the person integrates it by hand. Reading needs
|
|
6
|
+
* `automations:read`; changing needs `automations:write`.
|
|
7
|
+
* See docs/automations.md.
|
|
8
|
+
*/
|
|
9
|
+
export type JobAutomationWhen = 'succeeded' | 'failed' | 'always';
|
|
10
|
+
export type JobAutomationStepType = 'run' | 'agent' | 'reopen' | 'deliver';
|
|
11
|
+
/**
|
|
12
|
+
* Where a deliver step hands deliverables over. `folder`: copied into `path`,
|
|
13
|
+
* a directory inside the folder (a different existing file is never
|
|
14
|
+
* overwritten). `merge`: the work's branch merged into the folder's branch.
|
|
15
|
+
* `publish`: a pull request through the folder's publish rule. `outbox`: the
|
|
16
|
+
* machine's bucket, with a manifest at
|
|
17
|
+
* `machines/<machine>/deliveries/<delivery>/<step>.json`.
|
|
18
|
+
*/
|
|
19
|
+
export type JobDeliverTarget = 'folder' | 'merge' | 'publish' | 'outbox';
|
|
20
|
+
/** What a deliverable is. */
|
|
21
|
+
export type JobDeliverableKind = 'branch' | 'file' | 'media' | 'report';
|
|
22
|
+
/**
|
|
23
|
+
* What a workflow's work must hand over: a file (`path`, relative to the
|
|
24
|
+
* folder) or media file, the report, or the branch. When the work did not
|
|
25
|
+
* produce it, an agent step with `produce: true` writes it.
|
|
26
|
+
*/
|
|
27
|
+
export interface JobResultSpec {
|
|
28
|
+
kind: JobDeliverableKind;
|
|
29
|
+
path?: string;
|
|
30
|
+
/** What it must be or contain, for the producing agent and the reviewer. */
|
|
31
|
+
describe?: string;
|
|
32
|
+
}
|
|
33
|
+
/** One thing a job (or a produce step) made that a deliver step can hand over. */
|
|
34
|
+
export interface JobDeliverable {
|
|
35
|
+
name: string;
|
|
36
|
+
kind: JobDeliverableKind;
|
|
37
|
+
path?: string;
|
|
38
|
+
branch?: string;
|
|
39
|
+
head?: string;
|
|
40
|
+
sha256?: string;
|
|
41
|
+
size?: number;
|
|
42
|
+
type?: string;
|
|
43
|
+
/** Where its content is read from: git (at head), folder, media or report. */
|
|
44
|
+
source?: 'git' | 'folder' | 'media' | 'report';
|
|
45
|
+
/** "job" for the work's own output, or the id of the step that produced it. */
|
|
46
|
+
from?: string;
|
|
47
|
+
}
|
|
48
|
+
export type JobDeliveryState = 'pending' | 'running' | 'succeeded' | 'failed' | 'skipped' | 'stopped' | 'blocked';
|
|
49
|
+
export type JobReviewVerdict = 'ok' | 'block';
|
|
50
|
+
/**
|
|
51
|
+
* An agent step's `fixes` option (reviewer workers only; the only value).
|
|
52
|
+
* The daemon refuses it for any other worker.
|
|
53
|
+
*/
|
|
54
|
+
export type JobReviewerFixes = 'security';
|
|
55
|
+
/**
|
|
56
|
+
* Where an agent step's agent works. `same`: a new session in the worktree of
|
|
57
|
+
* the job the step follows, read-only (a reviewer only). `new`: its own
|
|
58
|
+
* worktree at the job's head. `none`: the folder itself.
|
|
59
|
+
*/
|
|
60
|
+
export type JobAgentCheckout = 'same' | 'new' | 'none';
|
|
61
|
+
/** The most lines (added plus removed) a reviewer's fix commits may change. */
|
|
62
|
+
export declare const JOB_REVIEWER_FIX_MAX_LINES = 80;
|
|
63
|
+
/**
|
|
64
|
+
* One condition of a step's `if`, on an earlier step: its status, or (an
|
|
65
|
+
* agent step) the verdict of the review its job recorded. A missing verdict
|
|
66
|
+
* never matches.
|
|
67
|
+
*/
|
|
68
|
+
export type JobAutomationCondition = {
|
|
69
|
+
step: string;
|
|
70
|
+
status: 'succeeded' | 'failed';
|
|
71
|
+
verdict?: never;
|
|
72
|
+
} | {
|
|
73
|
+
step: string;
|
|
74
|
+
verdict: JobReviewVerdict;
|
|
75
|
+
status?: never;
|
|
76
|
+
};
|
|
77
|
+
/** Which task and job ends a workflow applies to. */
|
|
78
|
+
export interface JobAutomationScope {
|
|
79
|
+
/** Absolute path of the project folder. */
|
|
80
|
+
folder: string;
|
|
81
|
+
/** Only the tasks this one of Swarm's own agents finished in the folder. */
|
|
82
|
+
role?: 'swarm' | 'coder' | 'finder' | 'designer';
|
|
83
|
+
/** Only this worker's jobs (worker id). */
|
|
84
|
+
worker?: string;
|
|
85
|
+
/** Only this task or job (`task/<project>/<task>`, `worker/<worker>/<run>`, ...). */
|
|
86
|
+
job?: string;
|
|
87
|
+
/** Only the jobs of this schedule (schedule id). */
|
|
88
|
+
schedule?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface JobAutomationStep {
|
|
91
|
+
/** Lowercase id; default `step-N`. */
|
|
92
|
+
id?: string;
|
|
93
|
+
type: JobAutomationStepType;
|
|
94
|
+
/** 1 to 3600; default 600. */
|
|
95
|
+
timeout_seconds?: number;
|
|
96
|
+
/** Default false: a failed step stops the rest. */
|
|
97
|
+
continue_on_failure?: boolean;
|
|
98
|
+
/** Conditions that must all hold for the step to run; otherwise it is skipped and later steps still run. */
|
|
99
|
+
if?: JobAutomationCondition[];
|
|
100
|
+
/**
|
|
101
|
+
* run: the machine owner's script, as an absolute path or a path relative
|
|
102
|
+
* to the folder (e.g. `deliver/push.sh`). It runs on the host as the
|
|
103
|
+
* daemon's user, in the folder, with the machine's own credentials, and
|
|
104
|
+
* only if the file (symlinks resolved) is owned by root and not writable by
|
|
105
|
+
* group or others. A relative path must resolve to a singly linked file
|
|
106
|
+
* inside the folder; prefer an absolute path in a directory only root can
|
|
107
|
+
* write. A run step has no `secrets`: a step that sends them is refused.
|
|
108
|
+
* Only the machine's owner may save a run step: the local owner or a key
|
|
109
|
+
* with the `admin` scope; any other key gets 403 and nothing is stored.
|
|
110
|
+
*/
|
|
111
|
+
command?: string;
|
|
112
|
+
args?: string[];
|
|
113
|
+
/**
|
|
114
|
+
* agent: one of Swarm's own agents (`swarm`, `coder`, `finder`, `designer`),
|
|
115
|
+
* run as a task in the folder (a coder starts at the work's head); `reviewer`;
|
|
116
|
+
* or a worker id.
|
|
117
|
+
*/
|
|
118
|
+
worker?: string;
|
|
119
|
+
/** agent: the job's brief; the triggering job's result is attached (a reviewer also gets its brief, report, commands run and diff). */
|
|
120
|
+
brief?: string;
|
|
121
|
+
/**
|
|
122
|
+
* agent, reviewer worker only: `security` lets the reviewer commit small,
|
|
123
|
+
* security-only fixes on a branch at the reviewed head instead of blocking
|
|
124
|
+
* for them. Its commits move the delivery head only with an OK verdict and
|
|
125
|
+
* at most {@link JOB_REVIEWER_FIX_MAX_LINES} changed lines; more fails the
|
|
126
|
+
* step (`reviewer fixes too large`); an OK whose fixes cannot be read from
|
|
127
|
+
* the reviewer's checkout fails it (`reviewer fixes unreadable`). Without
|
|
128
|
+
* it a reviewer is read-only.
|
|
129
|
+
*/
|
|
130
|
+
fixes?: JobReviewerFixes;
|
|
131
|
+
/**
|
|
132
|
+
* agent: where the agent works; omit it for the agent's default. A reviewer
|
|
133
|
+
* reads the reviewed job's own worktree in place (`same`, read-only; it
|
|
134
|
+
* starts only at exactly the reviewed head with nothing uncommitted, and its
|
|
135
|
+
* verdict is a block if the worktree changes during the review) or gets its
|
|
136
|
+
* own checkout (`new`). A reviewer with `fixes`, the coder and any other
|
|
137
|
+
* worker use `new`; swarm, finder and designer work in the folder (`none`).
|
|
138
|
+
* The daemon refuses any other combination.
|
|
139
|
+
*/
|
|
140
|
+
checkout?: JobAgentCheckout;
|
|
141
|
+
/**
|
|
142
|
+
* reopen: the earlier agent step whose findings are sent into the triggering
|
|
143
|
+
* job's own session. Optional when `message` is set.
|
|
144
|
+
*/
|
|
145
|
+
from?: string;
|
|
146
|
+
/**
|
|
147
|
+
* reopen: text placed before the findings, or sent alone when `from`
|
|
148
|
+
* recorded none (an OK review) or is omitted. `{{steps.<id>.output}}` is
|
|
149
|
+
* replaced by that earlier step's recorded output line. A reopen needs
|
|
150
|
+
* `from`, `message` or both; with no findings and no message it fails.
|
|
151
|
+
*/
|
|
152
|
+
message?: string;
|
|
153
|
+
/** reopen: reopens allowed before the delivery ends `blocked` (`rounds_exhausted`); 1 to 5, default 2. */
|
|
154
|
+
max_rounds?: number;
|
|
155
|
+
/**
|
|
156
|
+
* agent: the agent writes the workflow's `result` file; Swarm checks it
|
|
157
|
+
* exists, records its sha256 and hands it over. Not for finder or reviewer.
|
|
158
|
+
* A reviewer started after it reviews the produced work.
|
|
159
|
+
*/
|
|
160
|
+
produce?: boolean;
|
|
161
|
+
/** deliver: where. */
|
|
162
|
+
to?: JobDeliverTarget;
|
|
163
|
+
/** deliver to a folder: the directory inside the folder. */
|
|
164
|
+
path?: string;
|
|
165
|
+
/** deliver: deliverables by name; default the workflow's result, else what fits the target. */
|
|
166
|
+
what?: string[];
|
|
167
|
+
}
|
|
168
|
+
export interface JobAutomation {
|
|
169
|
+
id: string;
|
|
170
|
+
name: string;
|
|
171
|
+
scope: JobAutomationScope;
|
|
172
|
+
when: JobAutomationWhen;
|
|
173
|
+
enabled: boolean;
|
|
174
|
+
/** Automatic retries of a failed step, 0 to 3. */
|
|
175
|
+
retries: number;
|
|
176
|
+
/** Ordered steps, with their defaults applied (id, timeout_seconds). */
|
|
177
|
+
steps: JobAutomationStep[];
|
|
178
|
+
/** What the work must hand over, when the workflow names it. */
|
|
179
|
+
result?: JobResultSpec;
|
|
180
|
+
/** Rises on every update; a delivery keeps the revision it started with. */
|
|
181
|
+
revision: number;
|
|
182
|
+
created_at: number;
|
|
183
|
+
updated_at: number;
|
|
184
|
+
latest_deliveries?: JobDelivery[];
|
|
185
|
+
}
|
|
186
|
+
export interface SetJobAutomationParams {
|
|
187
|
+
name: string;
|
|
188
|
+
scope: JobAutomationScope;
|
|
189
|
+
when?: JobAutomationWhen;
|
|
190
|
+
enabled?: boolean;
|
|
191
|
+
retries?: number;
|
|
192
|
+
steps: JobAutomationStep[];
|
|
193
|
+
result?: JobResultSpec;
|
|
194
|
+
}
|
|
195
|
+
export interface JobDeliveryStep {
|
|
196
|
+
id: string;
|
|
197
|
+
type: JobAutomationStepType;
|
|
198
|
+
state: JobDeliveryState;
|
|
199
|
+
attempts: number;
|
|
200
|
+
started_at?: number;
|
|
201
|
+
finished_at?: number;
|
|
202
|
+
next_attempt_at?: number;
|
|
203
|
+
exit_code?: number;
|
|
204
|
+
/** The last non-empty line the step printed (a run step), or the job id (an agent step). */
|
|
205
|
+
output?: string;
|
|
206
|
+
reason?: string;
|
|
207
|
+
/** The next allowed action after a failure, e.g. `rerun` or `fix the script`. */
|
|
208
|
+
next?: string;
|
|
209
|
+
/**
|
|
210
|
+
* An agent step's job: `job_id`, `status`, `head`, `report`, `review`, and
|
|
211
|
+
* `verdict`/`findings` when the job recorded a review (`moved_head` when it
|
|
212
|
+
* moved the delivery head); with `fixes`, the reviewer's `fix_commits`,
|
|
213
|
+
* `fix_lines`, `fixes_applied` and `fixes_reason`; a reopen step's
|
|
214
|
+
* `followup` and `round`.
|
|
215
|
+
*/
|
|
216
|
+
outcome?: Record<string, unknown>;
|
|
217
|
+
/** The last 64 KiB of a run step's output (single-delivery reads only). */
|
|
218
|
+
log_tail?: string;
|
|
219
|
+
}
|
|
220
|
+
/** One (job end, automation revision) pair; runs at most once. */
|
|
221
|
+
export interface JobDelivery {
|
|
222
|
+
delivery_id: string;
|
|
223
|
+
automation_id: string;
|
|
224
|
+
automation: string;
|
|
225
|
+
automation_revision: number;
|
|
226
|
+
job_id: string;
|
|
227
|
+
/** The follow-up this job end belongs to; absent for the job's first run. */
|
|
228
|
+
followup?: string;
|
|
229
|
+
/** Reopens that led to this job end: a follow-up a reopen step sent is the previous round + 1. */
|
|
230
|
+
round: number;
|
|
231
|
+
state: JobDeliveryState;
|
|
232
|
+
/** The commit the delivery delivers: the job's head, moved forward by an agent step that committed on top of it. */
|
|
233
|
+
head?: string;
|
|
234
|
+
/** Why the delivery ended `blocked`, e.g. `rounds_exhausted`. */
|
|
235
|
+
blocked_reason?: string;
|
|
236
|
+
/** The reviewer fix commits the delivery head was moved to (agent steps with `fixes`). */
|
|
237
|
+
fix_commits?: Array<{
|
|
238
|
+
sha: string;
|
|
239
|
+
subject: string;
|
|
240
|
+
}>;
|
|
241
|
+
steps: JobDeliveryStep[];
|
|
242
|
+
created_at: number;
|
|
243
|
+
started_at?: number;
|
|
244
|
+
finished_at?: number;
|
|
245
|
+
reruns?: number;
|
|
246
|
+
/** The job's result, on single-delivery reads. */
|
|
247
|
+
result?: JobResult;
|
|
248
|
+
}
|
|
249
|
+
/** The result record a job end produces; a run step gets it on stdin. */
|
|
250
|
+
export interface JobResult {
|
|
251
|
+
v: number;
|
|
252
|
+
job_id: string;
|
|
253
|
+
kind: 'task' | 'worker' | 'media' | 'design';
|
|
254
|
+
role?: string;
|
|
255
|
+
worker?: {
|
|
256
|
+
id: string;
|
|
257
|
+
name?: string;
|
|
258
|
+
};
|
|
259
|
+
run_id: string;
|
|
260
|
+
followup?: string;
|
|
261
|
+
project_id?: string;
|
|
262
|
+
folder?: string;
|
|
263
|
+
status: 'succeeded' | 'failed' | 'cancelled';
|
|
264
|
+
job_status?: string;
|
|
265
|
+
finished_at: number;
|
|
266
|
+
brief?: string;
|
|
267
|
+
report?: string;
|
|
268
|
+
error?: string;
|
|
269
|
+
request_source?: string;
|
|
270
|
+
schedule_id?: string;
|
|
271
|
+
git?: {
|
|
272
|
+
branch: string;
|
|
273
|
+
base_branch?: string;
|
|
274
|
+
base_commit: string;
|
|
275
|
+
head: string;
|
|
276
|
+
commits: Array<{
|
|
277
|
+
sha: string;
|
|
278
|
+
subject: string;
|
|
279
|
+
}>;
|
|
280
|
+
files: string[];
|
|
281
|
+
worktree?: string;
|
|
282
|
+
};
|
|
283
|
+
files?: Array<{
|
|
284
|
+
path: string;
|
|
285
|
+
sha256: string;
|
|
286
|
+
type: string;
|
|
287
|
+
size?: number;
|
|
288
|
+
}>;
|
|
289
|
+
cost?: {
|
|
290
|
+
tokens: number;
|
|
291
|
+
estimated_usd?: number;
|
|
292
|
+
model?: string;
|
|
293
|
+
};
|
|
294
|
+
review?: Record<string, unknown>;
|
|
295
|
+
/** Everything the job made that a deliver step can hand over. */
|
|
296
|
+
deliverables?: JobDeliverable[];
|
|
297
|
+
}
|
|
298
|
+
export interface JobAutomationStop {
|
|
299
|
+
stopped: boolean;
|
|
300
|
+
at?: number;
|
|
301
|
+
by?: string;
|
|
302
|
+
}
|
|
303
|
+
export interface ListJobDeliveriesParams {
|
|
304
|
+
jobId?: string;
|
|
305
|
+
automationId?: string;
|
|
306
|
+
state?: JobDeliveryState;
|
|
307
|
+
/** Default 50, at most 200. */
|
|
308
|
+
limit?: number;
|
|
309
|
+
}
|
|
310
|
+
/** Workflows and their deliveries (`/v3/workflows`, `/v3/job-deliveries`). */
|
|
311
|
+
export declare class SwarmJobAutomationsNamespace {
|
|
312
|
+
private readonly transport;
|
|
313
|
+
constructor(transport: SwarmTransport);
|
|
314
|
+
/** This account's automations, each with its latest deliveries. */
|
|
315
|
+
list(): Promise<{
|
|
316
|
+
automations: JobAutomation[];
|
|
317
|
+
stopped: boolean;
|
|
318
|
+
}>;
|
|
319
|
+
get(id: string): Promise<JobAutomation>;
|
|
320
|
+
/** Creates the automation, or updates the one with this name (its revision rises). */
|
|
321
|
+
set(params: SetJobAutomationParams): Promise<{
|
|
322
|
+
automation: JobAutomation;
|
|
323
|
+
created: boolean;
|
|
324
|
+
}>;
|
|
325
|
+
delete(id: string): Promise<void>;
|
|
326
|
+
/** The machine-wide stop switch. */
|
|
327
|
+
stopState(): Promise<JobAutomationStop>;
|
|
328
|
+
/** While stopped, no new step starts on the machine; running steps finish. */
|
|
329
|
+
setStopped(stopped: boolean): Promise<JobAutomationStop>;
|
|
330
|
+
/** Deliveries, newest first. */
|
|
331
|
+
deliveries(params?: ListJobDeliveriesParams): Promise<JobDelivery[]>;
|
|
332
|
+
/** One delivery with its steps' log tails and the job's result. */
|
|
333
|
+
delivery(id: string): Promise<JobDelivery>;
|
|
334
|
+
/**
|
|
335
|
+
* Re-runs only the delivery's failed or stopped steps (a blocked delivery
|
|
336
|
+
* runs again from its first step with a new round budget); `rerun` is false
|
|
337
|
+
* when there were none.
|
|
338
|
+
*/
|
|
339
|
+
rerun(id: string): Promise<{
|
|
340
|
+
rerun: boolean;
|
|
341
|
+
delivery: JobDelivery;
|
|
342
|
+
}>;
|
|
343
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** The most lines (added plus removed) a reviewer's fix commits may change. */
|
|
2
|
+
export const JOB_REVIEWER_FIX_MAX_LINES = 80;
|
|
3
|
+
/** Workflows and their deliveries (`/v3/workflows`, `/v3/job-deliveries`). */
|
|
4
|
+
export class SwarmJobAutomationsNamespace {
|
|
5
|
+
transport;
|
|
6
|
+
constructor(transport) {
|
|
7
|
+
this.transport = transport;
|
|
8
|
+
}
|
|
9
|
+
/** This account's automations, each with its latest deliveries. */
|
|
10
|
+
async list() {
|
|
11
|
+
const res = await this.transport.request('/v3/workflows', { method: 'GET' });
|
|
12
|
+
return { automations: res.data.automations ?? [], stopped: Boolean(res.data.stopped) };
|
|
13
|
+
}
|
|
14
|
+
async get(id) {
|
|
15
|
+
const res = await this.transport.request(`/v3/workflows/${encodeURIComponent(id)}`, { method: 'GET' });
|
|
16
|
+
return res.data.automation;
|
|
17
|
+
}
|
|
18
|
+
/** Creates the automation, or updates the one with this name (its revision rises). */
|
|
19
|
+
async set(params) {
|
|
20
|
+
const res = await this.transport.request('/v3/workflows', {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
body: params,
|
|
23
|
+
});
|
|
24
|
+
return { automation: res.data.automation, created: Boolean(res.data.created) };
|
|
25
|
+
}
|
|
26
|
+
async delete(id) {
|
|
27
|
+
await this.transport.request(`/v3/workflows/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
28
|
+
}
|
|
29
|
+
/** The machine-wide stop switch. */
|
|
30
|
+
async stopState() {
|
|
31
|
+
const res = await this.transport.request('/v3/workflows/stop', { method: 'GET' });
|
|
32
|
+
return res.data.stop;
|
|
33
|
+
}
|
|
34
|
+
/** While stopped, no new step starts on the machine; running steps finish. */
|
|
35
|
+
async setStopped(stopped) {
|
|
36
|
+
const res = await this.transport.request('/v3/workflows/stop', {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
body: { stopped },
|
|
39
|
+
});
|
|
40
|
+
return res.data.stop;
|
|
41
|
+
}
|
|
42
|
+
/** Deliveries, newest first. */
|
|
43
|
+
async deliveries(params = {}) {
|
|
44
|
+
const q = new URLSearchParams();
|
|
45
|
+
if (params.jobId)
|
|
46
|
+
q.set('job_id', params.jobId);
|
|
47
|
+
if (params.automationId)
|
|
48
|
+
q.set('automation_id', params.automationId);
|
|
49
|
+
if (params.state)
|
|
50
|
+
q.set('state', params.state);
|
|
51
|
+
if (typeof params.limit === 'number')
|
|
52
|
+
q.set('limit', String(params.limit));
|
|
53
|
+
const path = q.toString() ? `/v3/job-deliveries?${q.toString()}` : '/v3/job-deliveries';
|
|
54
|
+
const res = await this.transport.request(path, { method: 'GET' });
|
|
55
|
+
return res.data.deliveries ?? [];
|
|
56
|
+
}
|
|
57
|
+
/** One delivery with its steps' log tails and the job's result. */
|
|
58
|
+
async delivery(id) {
|
|
59
|
+
const res = await this.transport.request(`/v3/job-deliveries/${encodeURIComponent(id)}`, { method: 'GET' });
|
|
60
|
+
return res.data.delivery;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Re-runs only the delivery's failed or stopped steps (a blocked delivery
|
|
64
|
+
* runs again from its first step with a new round budget); `rerun` is false
|
|
65
|
+
* when there were none.
|
|
66
|
+
*/
|
|
67
|
+
async rerun(id) {
|
|
68
|
+
const res = await this.transport.request(`/v3/job-deliveries/${encodeURIComponent(id)}/rerun`, {
|
|
69
|
+
method: 'POST',
|
|
70
|
+
body: {},
|
|
71
|
+
});
|
|
72
|
+
return { rerun: Boolean(res.data.rerun), delivery: res.data.delivery };
|
|
73
|
+
}
|
|
74
|
+
}
|
package/dist/limits.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SwarmTransport } from './transport.js';
|
|
2
|
+
export interface BoxLimits {
|
|
3
|
+
revision: number;
|
|
4
|
+
worker_job_concurrency: number;
|
|
5
|
+
job_tokens: number;
|
|
6
|
+
job_cost_usd: number;
|
|
7
|
+
delegation_waves: number;
|
|
8
|
+
active_children: number;
|
|
9
|
+
swarm_children: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class SwarmLimitsNamespace {
|
|
12
|
+
private readonly transport;
|
|
13
|
+
constructor(transport: SwarmTransport);
|
|
14
|
+
get(): Promise<BoxLimits>;
|
|
15
|
+
set(expected_revision: number, limits: Omit<BoxLimits, 'revision'>): Promise<BoxLimits>;
|
|
16
|
+
}
|
package/dist/limits.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class SwarmLimitsNamespace {
|
|
2
|
+
transport;
|
|
3
|
+
constructor(transport) {
|
|
4
|
+
this.transport = transport;
|
|
5
|
+
}
|
|
6
|
+
async get() {
|
|
7
|
+
return (await this.transport.request('/v3/limits', { method: 'GET' })).data;
|
|
8
|
+
}
|
|
9
|
+
async set(expected_revision, limits) {
|
|
10
|
+
return (await this.transport.request('/v3/limits', { method: 'PUT', body: { expected_revision, limits } })).data;
|
|
11
|
+
}
|
|
12
|
+
}
|