@abelxiaoxing/cadence 2.1.2 → 2.1.3
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/docs/conversation-mode.md +6 -2
- package/docs/reuse-and-distribution.md +20 -12
- package/package.json +1 -1
- package/src/cadence-instructions.ts +3 -2
- package/src/cadence-mode.ts +13 -81
- package/src/coordinator-tools.mjs +106 -48
- package/src/model-preview.mjs +11 -2
- package/src/native-build.ts +1 -1
- package/src/sdk-worker.mjs +37 -4
- package/src/service/contracts/workflow.ts +386 -109
- package/src/service-cli.mjs +11 -2
- package/src/service-host.mjs +749 -446
- package/src/worker-model.mjs +35 -1
- package/src/worker-public.mjs +18 -2
- package/web/dist/assets/cadence.js +27 -27
- package/web/dist/manifest.json +5 -5
package/src/worker-model.mjs
CHANGED
|
@@ -18,6 +18,33 @@ export const WORKER_POLICY = Object.freeze({
|
|
|
18
18
|
httpIdleTimeoutMs: 0,
|
|
19
19
|
});
|
|
20
20
|
export const WORKER_SETTINGS_BYTES = 32768;
|
|
21
|
+
/** A worker the service runs unattended keeps asking a failing provider far
|
|
22
|
+
* longer than an interactive session would: nobody is there to press retry, and
|
|
23
|
+
* a rate limit or an outage of some minutes must not cost the work done so far.
|
|
24
|
+
* A floor under Pi's own retry settings (about half an hour of backoff at its
|
|
25
|
+
* default base delay), never applied when the user turned retries off. */
|
|
26
|
+
export const UNATTENDED_RETRY = Object.freeze({
|
|
27
|
+
maxRetries: 12,
|
|
28
|
+
maxAgentDelayMs: 300_000,
|
|
29
|
+
});
|
|
30
|
+
export function unattendedRuntime(runtime) {
|
|
31
|
+
const retry = runtime.settings.retry;
|
|
32
|
+
if (!retry.enabled) return runtime;
|
|
33
|
+
return decodeWorkerRuntime({
|
|
34
|
+
...runtime,
|
|
35
|
+
settings: {
|
|
36
|
+
...runtime.settings,
|
|
37
|
+
retry: {
|
|
38
|
+
...retry,
|
|
39
|
+
maxRetries: Math.max(retry.maxRetries, UNATTENDED_RETRY.maxRetries),
|
|
40
|
+
maxAgentDelayMs: Math.max(
|
|
41
|
+
retry.maxAgentDelayMs,
|
|
42
|
+
UNATTENDED_RETRY.maxAgentDelayMs,
|
|
43
|
+
),
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
21
48
|
|
|
22
49
|
/** Public SDK factories are the source of built-in/default tool identities. */
|
|
23
50
|
export function defaultWorkerTools(pi, cwd) {
|
|
@@ -220,9 +247,14 @@ export class WorkerModelState {
|
|
|
220
247
|
actualResponseStatus = "UNKNOWN";
|
|
221
248
|
retryAttempts = 0;
|
|
222
249
|
progress = null;
|
|
223
|
-
|
|
250
|
+
/** The provider's words for the last failed request, as `describe` kept them. */
|
|
251
|
+
reason = "";
|
|
252
|
+
/** `describe` turns provider text into what may leave the worker (redacted,
|
|
253
|
+
* bounded), or "" for nothing; without it no provider text is kept. */
|
|
254
|
+
constructor(emit, fail, describe = () => "") {
|
|
224
255
|
this.emit = emit;
|
|
225
256
|
this.fail = fail;
|
|
257
|
+
this.describe = describe;
|
|
226
258
|
}
|
|
227
259
|
publish(progress) {
|
|
228
260
|
this.progress = progress;
|
|
@@ -237,11 +269,13 @@ export class WorkerModelState {
|
|
|
237
269
|
const type = own(event, "type");
|
|
238
270
|
let pending;
|
|
239
271
|
if (type === "auto_retry_start") {
|
|
272
|
+
this.reason = this.describe(own(event, "errorMessage"));
|
|
240
273
|
const progress = decodeModelRetry({
|
|
241
274
|
phase: "waiting",
|
|
242
275
|
attempt: own(event, "attempt"),
|
|
243
276
|
maxAttempts: own(event, "maxAttempts"),
|
|
244
277
|
delayMs: own(event, "delayMs"),
|
|
278
|
+
...(this.reason ? { reason: this.reason } : {}),
|
|
245
279
|
});
|
|
246
280
|
this.retryAttempts = progress.attempt;
|
|
247
281
|
pending = this.publish(progress);
|
package/src/worker-public.mjs
CHANGED
|
@@ -31,6 +31,9 @@ export const LIMITS = Object.freeze({
|
|
|
31
31
|
predecessorBytes: 16 * 1024,
|
|
32
32
|
handoffBytes: 32 * 1024,
|
|
33
33
|
frameBytes: 64 * 1024,
|
|
34
|
+
// One coordinator tool call or its answer over the private bridge: a plan at
|
|
35
|
+
// its 256KiB bound, or every answer of a full research run, with its envelope.
|
|
36
|
+
coordinatorBytes: 384 * 1024,
|
|
34
37
|
chunkBytes: 8 * 1024,
|
|
35
38
|
detailBytes: 32 * 1024 * 1024,
|
|
36
39
|
dataFrames: 100_000,
|
|
@@ -1235,15 +1238,28 @@ function sourceId(v) {
|
|
|
1235
1238
|
if (!/^[a-zA-Z0-9_-]+$/.test(s)) invalid();
|
|
1236
1239
|
return s;
|
|
1237
1240
|
}
|
|
1238
|
-
/**
|
|
1241
|
+
/** Bytes of a provider's own words about a failed request that are kept. */
|
|
1242
|
+
export const MODEL_FAILURE_BYTES = 256;
|
|
1243
|
+
/** Credential-free progress, not a successful response or permission to replay.
|
|
1244
|
+
* `reason` is the provider's words for the failed request, redacted with the
|
|
1245
|
+
* worker's credentials and bounded before it leaves the worker. */
|
|
1239
1246
|
export function decodeModelRetry(v) {
|
|
1240
|
-
const o = closed(v, [
|
|
1247
|
+
const o = closed(v, [
|
|
1248
|
+
"phase",
|
|
1249
|
+
"attempt",
|
|
1250
|
+
"maxAttempts",
|
|
1251
|
+
"delayMs",
|
|
1252
|
+
...(Object.hasOwn(v ?? {}, "reason") ? ["reason"] : []),
|
|
1253
|
+
]);
|
|
1241
1254
|
const maxAttempts = integer(o.maxAttempts, 1);
|
|
1242
1255
|
const progress = {
|
|
1243
1256
|
phase: oneOf(o.phase, ["waiting", "requesting"]),
|
|
1244
1257
|
attempt: integer(o.attempt, 1, maxAttempts),
|
|
1245
1258
|
maxAttempts,
|
|
1246
1259
|
delayMs: integer(o.delayMs, 0, 2147483647),
|
|
1260
|
+
...(o.reason === undefined
|
|
1261
|
+
? {}
|
|
1262
|
+
: { reason: text(o.reason, MODEL_FAILURE_BYTES, true) }),
|
|
1247
1263
|
};
|
|
1248
1264
|
if (progress.phase === "requesting" && progress.delayMs !== 0)
|
|
1249
1265
|
throw new ContractError("invalid");
|