@sylphx/sdk 0.20.1 → 0.21.0
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 +19 -3
- package/dist/index.d.ts +454 -21
- package/dist/index.mjs +414 -12
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs/index.mjs +31 -25
- package/dist/nextjs/index.mjs.map +1 -1
- package/dist/react/index.mjs +21 -6
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.d.ts +36 -7
- package/dist/server/index.mjs +31 -29
- package/dist/server/index.mjs.map +1 -1
- package/dist/tasks.d.ts +15 -2
- package/dist/tasks.mjs +12 -0
- package/dist/tasks.mjs.map +1 -1
- package/package.json +6 -5
package/dist/index.mjs
CHANGED
|
@@ -171,10 +171,11 @@ function getErrorDetails2(error, fallbackMessage = "An unknown error occurred")
|
|
|
171
171
|
}
|
|
172
172
|
function getSafeErrorMessage(error, fallback = "Something went wrong. Please try again.") {
|
|
173
173
|
const errorCode = getSafeErrorKey(error);
|
|
174
|
-
if (errorCode && SAFE_ERROR_MESSAGES
|
|
174
|
+
if (errorCode && Object.hasOwn(SAFE_ERROR_MESSAGES, errorCode))
|
|
175
|
+
return SAFE_ERROR_MESSAGES[errorCode];
|
|
175
176
|
if (error && typeof error === "object") {
|
|
176
177
|
const coded = error;
|
|
177
|
-
if (coded.data?.code && SAFE_ERROR_MESSAGES
|
|
178
|
+
if (coded.data?.code && Object.hasOwn(SAFE_ERROR_MESSAGES, coded.data.code)) {
|
|
178
179
|
return SAFE_ERROR_MESSAGES[coded.data.code];
|
|
179
180
|
}
|
|
180
181
|
}
|
|
@@ -1449,6 +1450,16 @@ async function reclaimWorkspace(config, workspaceId, input = {}) {
|
|
|
1449
1450
|
}
|
|
1450
1451
|
);
|
|
1451
1452
|
}
|
|
1453
|
+
async function reclaimWorkspaceSubpath(config, workspaceId, input) {
|
|
1454
|
+
return callApi(
|
|
1455
|
+
config,
|
|
1456
|
+
`/workspaces/${encodeURIComponent(workspaceId)}/subpath-reclaims`,
|
|
1457
|
+
{
|
|
1458
|
+
method: "POST",
|
|
1459
|
+
body: input
|
|
1460
|
+
}
|
|
1461
|
+
);
|
|
1462
|
+
}
|
|
1452
1463
|
async function deleteWorkspace(config, workspaceId) {
|
|
1453
1464
|
await callApi(config, `/workspaces/${encodeURIComponent(workspaceId)}`, {
|
|
1454
1465
|
method: "DELETE"
|
|
@@ -1550,8 +1561,8 @@ var COMPUTE_VCPU_ACTIVE_RATE_MICRODOLLARS = 400;
|
|
|
1550
1561
|
var COMPUTE_VCPU_IDLE_RATE_MICRODOLLARS = 50;
|
|
1551
1562
|
var COMPUTE_RAM_RATE_MICRODOLLARS = 167;
|
|
1552
1563
|
var BUILD_MINUTE_PRICES = {
|
|
1553
|
-
standard:
|
|
1554
|
-
// $0.
|
|
1564
|
+
standard: 6e3,
|
|
1565
|
+
// $0.006/min — ADR-2571 (GitHub 2026 floor)
|
|
1555
1566
|
large: 3e4,
|
|
1556
1567
|
// $0.030/min
|
|
1557
1568
|
xlarge: 126e3,
|
|
@@ -1619,7 +1630,7 @@ var INSTANCE_TYPE_ALIASES = {
|
|
|
1619
1630
|
"performance-xl": "2xl"
|
|
1620
1631
|
};
|
|
1621
1632
|
function resolveCanonicalInstanceType(id) {
|
|
1622
|
-
return INSTANCE_TYPE_ALIASES[id]
|
|
1633
|
+
return Object.hasOwn(INSTANCE_TYPE_ALIASES, id) ? INSTANCE_TYPE_ALIASES[id] : id;
|
|
1623
1634
|
}
|
|
1624
1635
|
var INSTANCE_TYPES = {
|
|
1625
1636
|
// ---- Canonical T-shirt sizes (ADR-034) ----
|
|
@@ -1872,7 +1883,7 @@ function resolveMaxInstances(id) {
|
|
|
1872
1883
|
}
|
|
1873
1884
|
var DEFAULT_MAX_INSTANCES = 10;
|
|
1874
1885
|
function isValidInstanceType(id) {
|
|
1875
|
-
return id
|
|
1886
|
+
return Object.hasOwn(INSTANCE_TYPES, id);
|
|
1876
1887
|
}
|
|
1877
1888
|
function validateInstanceTypeForPlan(id, plan) {
|
|
1878
1889
|
const canonicalId = resolveCanonicalInstanceType(id);
|
|
@@ -5086,6 +5097,24 @@ async function putWithRetry(url, body, headers, signal, onProgress) {
|
|
|
5086
5097
|
}
|
|
5087
5098
|
throw lastErr;
|
|
5088
5099
|
}
|
|
5100
|
+
function fileFromCompletion(completion, options, blob) {
|
|
5101
|
+
const now = /* @__PURE__ */ new Date();
|
|
5102
|
+
return {
|
|
5103
|
+
id: completion.fileId,
|
|
5104
|
+
filename: options.filename ?? (isFile(blob) ? blob.name : void 0) ?? "upload.bin",
|
|
5105
|
+
contentType: options.contentType ?? (blob.type || "application/octet-stream"),
|
|
5106
|
+
size: completion.size,
|
|
5107
|
+
checksumSha256: completion.checksumSha256,
|
|
5108
|
+
etag: completion.etag,
|
|
5109
|
+
visibility: options.visibility ?? "private",
|
|
5110
|
+
folder: options.folder ?? null,
|
|
5111
|
+
metadata: options.metadata ?? {},
|
|
5112
|
+
url: completion.url,
|
|
5113
|
+
isDeleted: false,
|
|
5114
|
+
createdAt: now,
|
|
5115
|
+
updatedAt: now
|
|
5116
|
+
};
|
|
5117
|
+
}
|
|
5089
5118
|
async function uploadsCreate(config, blob, options) {
|
|
5090
5119
|
const signal = options.signal;
|
|
5091
5120
|
if (signal?.aborted) throw toAbortError();
|
|
@@ -5152,7 +5181,7 @@ async function runSinglePart(config, blob, session, options, idempotencyKey) {
|
|
|
5152
5181
|
}
|
|
5153
5182
|
);
|
|
5154
5183
|
clearResume(String(session.uploadId));
|
|
5155
|
-
return
|
|
5184
|
+
return fileFromCompletion(completion, options, blob);
|
|
5156
5185
|
}
|
|
5157
5186
|
async function runMultipart(config, blob, session, options, idempotencyKey) {
|
|
5158
5187
|
const { onProgress, signal } = options;
|
|
@@ -5197,10 +5226,7 @@ async function runMultipart(config, blob, session, options, idempotencyKey) {
|
|
|
5197
5226
|
}
|
|
5198
5227
|
);
|
|
5199
5228
|
clearResume(String(session.uploadId));
|
|
5200
|
-
return
|
|
5201
|
-
}
|
|
5202
|
-
async function fetchFile(config, fileId) {
|
|
5203
|
-
return callApi(config, PATHS.file(fileId), { method: "GET" });
|
|
5229
|
+
return fileFromCompletion(completion, options, blob);
|
|
5204
5230
|
}
|
|
5205
5231
|
async function uploadsAbort(config, uploadId) {
|
|
5206
5232
|
await withRetry(() => callApi(config, PATHS.upload(uploadId), { method: "DELETE" }), {
|
|
@@ -7768,6 +7794,100 @@ var SandboxClient = class _SandboxClient {
|
|
|
7768
7794
|
}
|
|
7769
7795
|
};
|
|
7770
7796
|
|
|
7797
|
+
// src/artifacts.ts
|
|
7798
|
+
var ArtifactClient = {
|
|
7799
|
+
/**
|
|
7800
|
+
* Publish a self-contained HTML document to a safe, shareable URL. Returns a
|
|
7801
|
+
* signed expiring link by default (`access: 'signed-link'`) — click-to-view, no
|
|
7802
|
+
* login, leaked links decay; `public` for a durable URL. On success returns
|
|
7803
|
+
* `{ id, url, expiresAt?, version }`; on failure a structured `error` with a
|
|
7804
|
+
* `code` (e.g. `blocked_unsafe`) and `diagnostics`.
|
|
7805
|
+
*
|
|
7806
|
+
* **Update in place (ADR-2564 v2):** pass `artifactId` (the `id` from a prior
|
|
7807
|
+
* publish) to REVISE that artifact — the id and the shareable URL are preserved
|
|
7808
|
+
* and `version` increments. The caller must own the artifact (`forbidden`
|
|
7809
|
+
* otherwise), it must still exist (`not_found`), and it must be a versioned
|
|
7810
|
+
* artifact (`conflict` for pre-versioning artifacts). Omit `artifactId` to
|
|
7811
|
+
* create a fresh artifact.
|
|
7812
|
+
*/
|
|
7813
|
+
async publish(config, request) {
|
|
7814
|
+
return callApi(config, "/artifacts", { method: "POST", body: request });
|
|
7815
|
+
},
|
|
7816
|
+
/**
|
|
7817
|
+
* List the calling project's published artifacts, newest-first. Returns
|
|
7818
|
+
* metadata only — `{ artifacts: [{ id, title?, access, currentVersion,
|
|
7819
|
+
* createdAt, updatedAt, expiresAt? }] }`.
|
|
7820
|
+
*
|
|
7821
|
+
* Excludes soft-deleted artifacts by default. Pass `{ includeDeleted: true }`
|
|
7822
|
+
* to ALSO list tombstoned ones (each carrying `deleted: true` + `deletedAt`),
|
|
7823
|
+
* so you can find a soft-deleted artifact's id and {@link ArtifactClient.restore}
|
|
7824
|
+
* it before the grace-window cleanup erases it.
|
|
7825
|
+
*/
|
|
7826
|
+
async list(config, options = {}) {
|
|
7827
|
+
return callApi(config, "/artifacts", {
|
|
7828
|
+
method: "GET",
|
|
7829
|
+
...options.includeDeleted ? { query: { include_deleted: "true" } } : {}
|
|
7830
|
+
});
|
|
7831
|
+
},
|
|
7832
|
+
/**
|
|
7833
|
+
* Get one artifact's metadata and its immutable version history. Throws
|
|
7834
|
+
* `NOT_FOUND` if the artifact does not exist (or is soft-deleted), `FORBIDDEN`
|
|
7835
|
+
* if it belongs to another project.
|
|
7836
|
+
*/
|
|
7837
|
+
async get(config, id) {
|
|
7838
|
+
return callApi(config, `/artifacts/${encodeURIComponent(id)}`, {
|
|
7839
|
+
method: "GET"
|
|
7840
|
+
});
|
|
7841
|
+
},
|
|
7842
|
+
/**
|
|
7843
|
+
* Get an artifact's CURRENT HTML source so you can EDIT it, then re-{@link
|
|
7844
|
+
* ArtifactClient.publish} with `artifactId` to update it in place — instead of
|
|
7845
|
+
* rewriting it blind from a fresh session. Returns `{ id, version, html }`.
|
|
7846
|
+
* Throws `NOT_FOUND` if it does not exist (or is soft-deleted), `FORBIDDEN` if
|
|
7847
|
+
* it belongs to another project. `get` returns metadata only; this returns the
|
|
7848
|
+
* bytes.
|
|
7849
|
+
*/
|
|
7850
|
+
async getContent(config, id) {
|
|
7851
|
+
return callApi(config, `/artifacts/${encodeURIComponent(id)}/content`, {
|
|
7852
|
+
method: "GET"
|
|
7853
|
+
});
|
|
7854
|
+
},
|
|
7855
|
+
/**
|
|
7856
|
+
* Soft-delete an artifact (reversible). The shareable URL begins returning
|
|
7857
|
+
* `410 Gone`; the bytes are retained until a later grace-window cleanup, so
|
|
7858
|
+
* {@link ArtifactClient.restore} can bring it back. Throws `NOT_FOUND` /
|
|
7859
|
+
* `FORBIDDEN` as for {@link ArtifactClient.get}.
|
|
7860
|
+
*/
|
|
7861
|
+
async delete(config, id) {
|
|
7862
|
+
return callApi(config, `/artifacts/${encodeURIComponent(id)}`, {
|
|
7863
|
+
method: "DELETE"
|
|
7864
|
+
});
|
|
7865
|
+
},
|
|
7866
|
+
/**
|
|
7867
|
+
* Restore a soft-deleted artifact. Pass `version` to roll a prior version
|
|
7868
|
+
* FORWARD as a new current version (history is never rewritten) — the returned
|
|
7869
|
+
* `version` is then the new current. Omit it to simply clear the tombstone.
|
|
7870
|
+
*/
|
|
7871
|
+
async restore(config, id, options = {}) {
|
|
7872
|
+
return callApi(config, `/artifacts/${encodeURIComponent(id)}/restore`, {
|
|
7873
|
+
method: "POST",
|
|
7874
|
+
body: options.version !== void 0 ? { version: options.version } : {}
|
|
7875
|
+
});
|
|
7876
|
+
},
|
|
7877
|
+
/**
|
|
7878
|
+
* Re-mint a fresh signed share link (a new capability URL + TTL) for an
|
|
7879
|
+
* artifact — e.g. to extend or rotate a link. Returns `{ url, expiresAt? }`.
|
|
7880
|
+
* For a `public` artifact the durable URL is returned as-is. Pass `ttlSeconds`
|
|
7881
|
+
* to set the new link's lifetime (clamped to the allowed window).
|
|
7882
|
+
*/
|
|
7883
|
+
async reshare(config, id, options = {}) {
|
|
7884
|
+
return callApi(config, `/artifacts/${encodeURIComponent(id)}/reshare`, {
|
|
7885
|
+
method: "POST",
|
|
7886
|
+
body: options.ttlSeconds !== void 0 ? { ttlSeconds: options.ttlSeconds } : {}
|
|
7887
|
+
});
|
|
7888
|
+
}
|
|
7889
|
+
};
|
|
7890
|
+
|
|
7771
7891
|
// src/render.ts
|
|
7772
7892
|
var RenderClient = {
|
|
7773
7893
|
/**
|
|
@@ -7781,7 +7901,117 @@ var RenderClient = {
|
|
|
7781
7901
|
}
|
|
7782
7902
|
};
|
|
7783
7903
|
|
|
7904
|
+
// src/wallet.ts
|
|
7905
|
+
var WalletClient = {
|
|
7906
|
+
/** Mint a grant block of credits for an end user. */
|
|
7907
|
+
async grant(config, request) {
|
|
7908
|
+
return callApi(config, "/wallet/grants", { method: "POST", body: request });
|
|
7909
|
+
},
|
|
7910
|
+
/** Get an end user's derived balance (`available = posted − reserved`). */
|
|
7911
|
+
async getBalance(config, request) {
|
|
7912
|
+
return callApi(config, "/wallet/balance", { method: "POST", body: request });
|
|
7913
|
+
},
|
|
7914
|
+
/** Reserve credits (two-phase hold with a mandatory TTL). */
|
|
7915
|
+
async reserve(config, request) {
|
|
7916
|
+
return callApi(config, "/wallet/reservations", { method: "POST", body: request });
|
|
7917
|
+
},
|
|
7918
|
+
/** Capture a reservation (≤ reserved; releases the remainder). */
|
|
7919
|
+
async consume(config, request) {
|
|
7920
|
+
return callApi(config, "/wallet/reservations/consume", {
|
|
7921
|
+
method: "POST",
|
|
7922
|
+
body: request
|
|
7923
|
+
});
|
|
7924
|
+
},
|
|
7925
|
+
/** Release a reservation (return the held credits). */
|
|
7926
|
+
async release(config, request) {
|
|
7927
|
+
return callApi(config, "/wallet/reservations/release", {
|
|
7928
|
+
method: "POST",
|
|
7929
|
+
body: request
|
|
7930
|
+
});
|
|
7931
|
+
},
|
|
7932
|
+
/** Void/claw back a specific grant block (audited ledger entry). */
|
|
7933
|
+
async voidGrant(config, request) {
|
|
7934
|
+
return callApi(config, "/wallet/grants/void", { method: "POST", body: request });
|
|
7935
|
+
}
|
|
7936
|
+
};
|
|
7937
|
+
|
|
7938
|
+
// src/device-sessions.ts
|
|
7939
|
+
var projectSessionsPath = (projectId) => `/projects/${encodeURIComponent(projectId)}/device-sessions`;
|
|
7940
|
+
var sessionPath = (sessionId, suffix = "") => `/device-sessions/${encodeURIComponent(sessionId)}${suffix}`;
|
|
7941
|
+
var DeviceSessionClient = {
|
|
7942
|
+
/** Boot a long-lived interactive device session in a project (poll to `ready`). */
|
|
7943
|
+
async create(config, projectId, body) {
|
|
7944
|
+
return callApi(config, projectSessionsPath(projectId), {
|
|
7945
|
+
method: "POST",
|
|
7946
|
+
body
|
|
7947
|
+
});
|
|
7948
|
+
},
|
|
7949
|
+
/** List interactive device sessions for a project. */
|
|
7950
|
+
async list(config, projectId, query) {
|
|
7951
|
+
return callApi(config, projectSessionsPath(projectId), {
|
|
7952
|
+
query: query ? { environmentId: query.environmentId, status: query.status, limit: query.limit } : void 0
|
|
7953
|
+
});
|
|
7954
|
+
},
|
|
7955
|
+
/** Get one device session by id — poll for `booting` → `ready`. */
|
|
7956
|
+
async get(config, sessionId) {
|
|
7957
|
+
return callApi(config, sessionPath(sessionId));
|
|
7958
|
+
},
|
|
7959
|
+
/** Install an APK handle (`http(s)://`, `s3://`, or a storage key) onto the device. */
|
|
7960
|
+
async install(config, sessionId, body) {
|
|
7961
|
+
return callApi(config, sessionPath(sessionId, "/install"), {
|
|
7962
|
+
method: "POST",
|
|
7963
|
+
body
|
|
7964
|
+
});
|
|
7965
|
+
},
|
|
7966
|
+
/** Send an input event (tap / swipe / key / text) — how the agent acts on the device. */
|
|
7967
|
+
async input(config, sessionId, body) {
|
|
7968
|
+
return callApi(config, sessionPath(sessionId, "/input"), {
|
|
7969
|
+
method: "POST",
|
|
7970
|
+
body
|
|
7971
|
+
});
|
|
7972
|
+
},
|
|
7973
|
+
/** Launch an installed app (defaults to the most-recently installed package). */
|
|
7974
|
+
async launch(config, sessionId, body = {}) {
|
|
7975
|
+
return callApi(config, sessionPath(sessionId, "/launch"), {
|
|
7976
|
+
method: "POST",
|
|
7977
|
+
body
|
|
7978
|
+
});
|
|
7979
|
+
},
|
|
7980
|
+
/** Capture a PNG screenshot — how the agent "sees" the device (base64 always present). */
|
|
7981
|
+
async screenshot(config, sessionId) {
|
|
7982
|
+
return callApi(config, sessionPath(sessionId, "/screenshot"));
|
|
7983
|
+
},
|
|
7984
|
+
/** Read recent logcat output from the device session. */
|
|
7985
|
+
async logcat(config, sessionId, query) {
|
|
7986
|
+
return callApi(config, sessionPath(sessionId, "/logcat"), {
|
|
7987
|
+
query: query ? { lines: query.lines } : void 0
|
|
7988
|
+
});
|
|
7989
|
+
},
|
|
7990
|
+
/**
|
|
7991
|
+
* Mint a short-lived signed descriptor for a browser to join the session's live
|
|
7992
|
+
* WebRTC view (ADR-2566). Requires the session to be booted stream-capable
|
|
7993
|
+
* (`create` with `stream: true`).
|
|
7994
|
+
*/
|
|
7995
|
+
async streamConnect(config, sessionId, body = {}) {
|
|
7996
|
+
return callApi(config, sessionPath(sessionId, "/stream"), {
|
|
7997
|
+
method: "POST",
|
|
7998
|
+
body
|
|
7999
|
+
});
|
|
8000
|
+
},
|
|
8001
|
+
/** Terminate a device session and release its device. */
|
|
8002
|
+
async delete(config, sessionId) {
|
|
8003
|
+
return callApi(config, sessionPath(sessionId), { method: "DELETE" });
|
|
8004
|
+
}
|
|
8005
|
+
};
|
|
8006
|
+
|
|
7784
8007
|
// src/workers.ts
|
|
8008
|
+
var TERMINAL_AGGREGATE_STATUSES = /* @__PURE__ */ new Set([
|
|
8009
|
+
"succeeded",
|
|
8010
|
+
"failed",
|
|
8011
|
+
"partial",
|
|
8012
|
+
"cancelled",
|
|
8013
|
+
"timed_out"
|
|
8014
|
+
]);
|
|
7785
8015
|
var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
7786
8016
|
"succeeded",
|
|
7787
8017
|
"failed",
|
|
@@ -7790,6 +8020,9 @@ var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
|
7790
8020
|
]);
|
|
7791
8021
|
var DEFAULT_POLL_INTERVAL_MS = 3e3;
|
|
7792
8022
|
var DEFAULT_WAIT_TIMEOUT_MS = 72e5;
|
|
8023
|
+
function runImageSourceBody(options) {
|
|
8024
|
+
return options.image !== void 0 ? { image: options.image } : { imageFromService: options.imageFromService };
|
|
8025
|
+
}
|
|
7793
8026
|
var RunHandle = class {
|
|
7794
8027
|
id;
|
|
7795
8028
|
config;
|
|
@@ -7882,6 +8115,98 @@ var RunHandle = class {
|
|
|
7882
8115
|
await callApi(this.config, `/workers/${this.id}`, { method: "DELETE" });
|
|
7883
8116
|
}
|
|
7884
8117
|
};
|
|
8118
|
+
var DistributedRunHandle = class {
|
|
8119
|
+
id;
|
|
8120
|
+
/** Submitted shard count — used to request + render the N-shard aggregate. */
|
|
8121
|
+
parallelism;
|
|
8122
|
+
config;
|
|
8123
|
+
completionMode;
|
|
8124
|
+
constructor(id, config, parallelism, completionMode) {
|
|
8125
|
+
this.id = id;
|
|
8126
|
+
this.config = config;
|
|
8127
|
+
this.parallelism = parallelism;
|
|
8128
|
+
this.completionMode = completionMode;
|
|
8129
|
+
}
|
|
8130
|
+
// --------------------------------------------------------------------------
|
|
8131
|
+
// Status (aggregate)
|
|
8132
|
+
// --------------------------------------------------------------------------
|
|
8133
|
+
/**
|
|
8134
|
+
* Get the current aggregate status + per-shard drill-down for this run.
|
|
8135
|
+
*
|
|
8136
|
+
* Hits `GET /runs/:id?view=distributed` — the additive superset of the
|
|
8137
|
+
* single-shard read model — passing the submitted `parallelism` so the platform
|
|
8138
|
+
* lays the observed status out across the N indexed shards.
|
|
8139
|
+
*/
|
|
8140
|
+
async status() {
|
|
8141
|
+
const run = await callApi(this.config, `/workers/${this.id}`, {
|
|
8142
|
+
method: "GET",
|
|
8143
|
+
query: {
|
|
8144
|
+
view: "distributed",
|
|
8145
|
+
parallelism: this.parallelism,
|
|
8146
|
+
completionMode: this.completionMode
|
|
8147
|
+
}
|
|
8148
|
+
});
|
|
8149
|
+
return run.distributed;
|
|
8150
|
+
}
|
|
8151
|
+
// --------------------------------------------------------------------------
|
|
8152
|
+
// Shards (per-shard drill-down)
|
|
8153
|
+
// --------------------------------------------------------------------------
|
|
8154
|
+
/** Get the per-shard status list (index, status, exitCode, timings). */
|
|
8155
|
+
async shards() {
|
|
8156
|
+
const distributed = await this.status();
|
|
8157
|
+
return [...distributed.shards];
|
|
8158
|
+
}
|
|
8159
|
+
// --------------------------------------------------------------------------
|
|
8160
|
+
// Wait (poll to aggregate terminal)
|
|
8161
|
+
// --------------------------------------------------------------------------
|
|
8162
|
+
/**
|
|
8163
|
+
* Poll until the aggregate reaches a terminal state (succeeded, failed,
|
|
8164
|
+
* partial, cancelled, timed_out) and return the final {@link DistributedRun}.
|
|
8165
|
+
*
|
|
8166
|
+
* @param options.pollIntervalMs - How often to poll in ms (default: 3000)
|
|
8167
|
+
* @param options.timeoutMs - Max time to wait before throwing (default: 2h)
|
|
8168
|
+
* @throws Error if the wait timeout is exceeded
|
|
8169
|
+
*/
|
|
8170
|
+
async wait(options) {
|
|
8171
|
+
const pollMs = options?.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
8172
|
+
const maxWaitMs = options?.timeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS;
|
|
8173
|
+
const deadline = Date.now() + maxWaitMs;
|
|
8174
|
+
while (true) {
|
|
8175
|
+
const distributed = await this.status();
|
|
8176
|
+
if (TERMINAL_AGGREGATE_STATUSES.has(distributed.status)) {
|
|
8177
|
+
return distributed;
|
|
8178
|
+
}
|
|
8179
|
+
if (Date.now() >= deadline) {
|
|
8180
|
+
throw new Error(
|
|
8181
|
+
`Distributed run ${this.id} did not complete within ${maxWaitMs}ms (current status: ${distributed.status})`
|
|
8182
|
+
);
|
|
8183
|
+
}
|
|
8184
|
+
await sleep2(pollMs);
|
|
8185
|
+
}
|
|
8186
|
+
}
|
|
8187
|
+
// --------------------------------------------------------------------------
|
|
8188
|
+
// Logs (per-shard)
|
|
8189
|
+
// --------------------------------------------------------------------------
|
|
8190
|
+
/**
|
|
8191
|
+
* Fetch captured logs for one shard (default: shard 0).
|
|
8192
|
+
*
|
|
8193
|
+
* @param options.shard - Shard index (0..parallelism-1). Defaults to 0.
|
|
8194
|
+
*/
|
|
8195
|
+
async logs(options) {
|
|
8196
|
+
const shard = options?.shard ?? 0;
|
|
8197
|
+
return callApi(this.config, `/workers/${this.id}/logs`, {
|
|
8198
|
+
method: "GET",
|
|
8199
|
+
query: { shard, parallelism: this.parallelism }
|
|
8200
|
+
});
|
|
8201
|
+
}
|
|
8202
|
+
// --------------------------------------------------------------------------
|
|
8203
|
+
// Cancel (whole set)
|
|
8204
|
+
// --------------------------------------------------------------------------
|
|
8205
|
+
/** Cancel the whole run (all shards). */
|
|
8206
|
+
async cancel() {
|
|
8207
|
+
await callApi(this.config, `/workers/${this.id}`, { method: "DELETE" });
|
|
8208
|
+
}
|
|
8209
|
+
};
|
|
7885
8210
|
var RunsClient = {
|
|
7886
8211
|
// --------------------------------------------------------------------------
|
|
7887
8212
|
// Run
|
|
@@ -7907,7 +8232,7 @@ var RunsClient = {
|
|
|
7907
8232
|
const run = await callApi(config, "/runs", {
|
|
7908
8233
|
method: "POST",
|
|
7909
8234
|
body: {
|
|
7910
|
-
|
|
8235
|
+
...runImageSourceBody(options),
|
|
7911
8236
|
command: options.command,
|
|
7912
8237
|
env: options.env,
|
|
7913
8238
|
machine: options.machine ?? "standard",
|
|
@@ -7918,6 +8243,78 @@ var RunsClient = {
|
|
|
7918
8243
|
return new RunHandle(run.id, config);
|
|
7919
8244
|
},
|
|
7920
8245
|
// --------------------------------------------------------------------------
|
|
8246
|
+
// Run distributed (multi-shard fan-out)
|
|
8247
|
+
// --------------------------------------------------------------------------
|
|
8248
|
+
/**
|
|
8249
|
+
* Spawn a Distributed Run — one logical job fanned out to N indexed shards —
|
|
8250
|
+
* and return a {@link DistributedRunHandle} (ADR distributed-batch-compute).
|
|
8251
|
+
*
|
|
8252
|
+
* The platform owns sharding, gang start (all shards admitted together or
|
|
8253
|
+
* none), the per-org concurrency budget, and the aggregate/per-shard rollup.
|
|
8254
|
+
* Each shard self-selects its partition from the injected
|
|
8255
|
+
* `SYLPHX_SHARD_INDEX` (0..parallelism-1) + `SYLPHX_SHARD_COUNT` env vars — no
|
|
8256
|
+
* coordinator code for the embarrassingly-parallel case.
|
|
8257
|
+
*
|
|
8258
|
+
* `parallelism: 1` is equivalent to {@link RunsClient.run} (the single-shard
|
|
8259
|
+
* N=1 case); the single-shard `run()` ergonomic path is unchanged.
|
|
8260
|
+
*
|
|
8261
|
+
* @example
|
|
8262
|
+
* ```typescript
|
|
8263
|
+
* const run = await RunsClient.runDistributed(config, {
|
|
8264
|
+
* image: 'ghcr.io/acme/trainer:sha-abc123',
|
|
8265
|
+
* command: ['python', 'train.py'],
|
|
8266
|
+
* parallelism: 16,
|
|
8267
|
+
* machine: 'large',
|
|
8268
|
+
* })
|
|
8269
|
+
* const result = await run.wait()
|
|
8270
|
+
* if (result.status !== 'succeeded') {
|
|
8271
|
+
* const failed = result.shards.filter((s) => s.status === 'failed')
|
|
8272
|
+
* throw new Error(`${failed.length}/${run.parallelism} shards failed`)
|
|
8273
|
+
* }
|
|
8274
|
+
* ```
|
|
8275
|
+
*/
|
|
8276
|
+
async runDistributed(config, options) {
|
|
8277
|
+
const sharded = options.parallelism > 1;
|
|
8278
|
+
const completionMode = options.completionMode ?? "Indexed";
|
|
8279
|
+
const run = await callApi(config, "/runs", {
|
|
8280
|
+
method: "POST",
|
|
8281
|
+
body: {
|
|
8282
|
+
...runImageSourceBody(options),
|
|
8283
|
+
command: options.command,
|
|
8284
|
+
env: options.env,
|
|
8285
|
+
machine: options.machine ?? "standard",
|
|
8286
|
+
timeoutSeconds: options.timeoutSeconds ?? 3600,
|
|
8287
|
+
volumeMounts: options.volumeMounts,
|
|
8288
|
+
parallelism: options.parallelism,
|
|
8289
|
+
...sharded ? {
|
|
8290
|
+
completionMode,
|
|
8291
|
+
gangScheduling: options.gangScheduling ?? true,
|
|
8292
|
+
...options.backoffLimitPerIndex === void 0 ? {} : { backoffLimitPerIndex: options.backoffLimitPerIndex }
|
|
8293
|
+
} : {}
|
|
8294
|
+
}
|
|
8295
|
+
});
|
|
8296
|
+
return new DistributedRunHandle(run.id, config, options.parallelism, completionMode);
|
|
8297
|
+
},
|
|
8298
|
+
// --------------------------------------------------------------------------
|
|
8299
|
+
// Get (distributed)
|
|
8300
|
+
// --------------------------------------------------------------------------
|
|
8301
|
+
/**
|
|
8302
|
+
* Get a {@link DistributedRunHandle} for an existing distributed run by ID.
|
|
8303
|
+
*
|
|
8304
|
+
* Pass the `parallelism` the run was created with so the handle requests +
|
|
8305
|
+
* renders the correct N-shard aggregate. Useful for resuming monitoring (e.g.
|
|
8306
|
+
* a CLI `runs get <id> --parallelism N`) across processes.
|
|
8307
|
+
*
|
|
8308
|
+
* @example
|
|
8309
|
+
* ```typescript
|
|
8310
|
+
* const handle = RunsClient.runDistributedFromId(config, storedRunId, 16)
|
|
8311
|
+
* const result = await handle.wait()
|
|
8312
|
+
* ```
|
|
8313
|
+
*/
|
|
8314
|
+
runDistributedFromId(config, runId, parallelism, completionMode = "Indexed") {
|
|
8315
|
+
return new DistributedRunHandle(runId, config, parallelism, completionMode);
|
|
8316
|
+
},
|
|
8317
|
+
// --------------------------------------------------------------------------
|
|
7921
8318
|
// Get
|
|
7922
8319
|
// --------------------------------------------------------------------------
|
|
7923
8320
|
/**
|
|
@@ -8290,6 +8687,7 @@ var functions = {
|
|
|
8290
8687
|
};
|
|
8291
8688
|
export {
|
|
8292
8689
|
ACHIEVEMENT_TIER_CONFIG,
|
|
8690
|
+
ArtifactClient,
|
|
8293
8691
|
AuthenticationError,
|
|
8294
8692
|
AuthorizationError,
|
|
8295
8693
|
BILLING_ALLOWED_ROLES,
|
|
@@ -8318,6 +8716,8 @@ export {
|
|
|
8318
8716
|
DEFAULT_POINTS_REWARD,
|
|
8319
8717
|
DISCOUNT_DURATION_MONTHS,
|
|
8320
8718
|
DISCOUNT_PERCENT,
|
|
8719
|
+
DeviceSessionClient,
|
|
8720
|
+
DistributedRunHandle,
|
|
8321
8721
|
ERROR_CODE_STATUS,
|
|
8322
8722
|
FREE_COMPUTE_HOURS,
|
|
8323
8723
|
FREE_STORAGE_GB,
|
|
@@ -8365,6 +8765,7 @@ export {
|
|
|
8365
8765
|
TimeoutError,
|
|
8366
8766
|
TriggersClient,
|
|
8367
8767
|
ValidationError,
|
|
8768
|
+
WalletClient,
|
|
8368
8769
|
RunHandle as WorkerHandle,
|
|
8369
8770
|
WorkersClient,
|
|
8370
8771
|
acceptAllConsents,
|
|
@@ -8617,6 +9018,7 @@ export {
|
|
|
8617
9018
|
realtime,
|
|
8618
9019
|
realtimeEmit,
|
|
8619
9020
|
reclaimWorkspace,
|
|
9021
|
+
reclaimWorkspaceSubpath,
|
|
8620
9022
|
recordStreakActivity,
|
|
8621
9023
|
recoverStreak,
|
|
8622
9024
|
redeemPromo,
|