@abelxiaoxing/cadence 2.1.2 → 2.1.4
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/agents/implementation-worker.md +7 -2
- package/docs/conversation-mode.md +12 -4
- package/docs/reuse-and-distribution.md +20 -12
- package/package.json +1 -1
- package/src/agent-panel-cadence.ts +7 -3
- package/src/agent-panel-model.ts +26 -7
- package/src/cadence-instructions.ts +3 -2
- package/src/cadence-mode.ts +13 -81
- package/src/coordinator-tools.mjs +123 -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 +417 -112
- package/src/service-cli.mjs +11 -2
- package/src/service-host.mjs +848 -483
- package/src/worker-model.mjs +35 -1
- package/src/worker-public.mjs +18 -2
- package/src/worker-toolkit.mjs +3 -2
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +27 -27
- package/web/dist/manifest.json +7 -7
package/src/model-preview.mjs
CHANGED
|
@@ -31,6 +31,7 @@ var LIMITS = Object.freeze({
|
|
|
31
31
|
predecessorBytes: 16 * 1024,
|
|
32
32
|
handoffBytes: 32 * 1024,
|
|
33
33
|
frameBytes: 64 * 1024,
|
|
34
|
+
coordinatorBytes: 384 * 1024,
|
|
34
35
|
chunkBytes: 8 * 1024,
|
|
35
36
|
detailBytes: 32 * 1024 * 1024,
|
|
36
37
|
dataFrames: 1e5,
|
|
@@ -718,14 +719,22 @@ function sourceId(v) {
|
|
|
718
719
|
invalid();
|
|
719
720
|
return s;
|
|
720
721
|
}
|
|
722
|
+
var MODEL_FAILURE_BYTES = 256;
|
|
721
723
|
function decodeModelRetry(v) {
|
|
722
|
-
const o = closed(v, [
|
|
724
|
+
const o = closed(v, [
|
|
725
|
+
"phase",
|
|
726
|
+
"attempt",
|
|
727
|
+
"maxAttempts",
|
|
728
|
+
"delayMs",
|
|
729
|
+
...Object.hasOwn(v ?? {}, "reason") ? ["reason"] : []
|
|
730
|
+
]);
|
|
723
731
|
const maxAttempts = integer(o.maxAttempts, 1);
|
|
724
732
|
const progress = {
|
|
725
733
|
phase: oneOf(o.phase, ["waiting", "requesting"]),
|
|
726
734
|
attempt: integer(o.attempt, 1, maxAttempts),
|
|
727
735
|
maxAttempts,
|
|
728
|
-
delayMs: integer(o.delayMs, 0, 2147483647)
|
|
736
|
+
delayMs: integer(o.delayMs, 0, 2147483647),
|
|
737
|
+
...o.reason === undefined ? {} : { reason: text(o.reason, MODEL_FAILURE_BYTES, true) }
|
|
729
738
|
};
|
|
730
739
|
if (progress.phase === "requesting" && progress.delayMs !== 0)
|
|
731
740
|
throw new ContractError("invalid");
|
package/src/native-build.ts
CHANGED
package/src/sdk-worker.mjs
CHANGED
|
@@ -40,9 +40,10 @@ import {
|
|
|
40
40
|
closed,
|
|
41
41
|
decodeWorkerPublicRequest,
|
|
42
42
|
LIMITS,
|
|
43
|
+
MODEL_FAILURE_BYTES,
|
|
43
44
|
parseWireJson,
|
|
44
45
|
} from "./worker-public.mjs";
|
|
45
|
-
import { own } from "./worker-redaction.mjs";
|
|
46
|
+
import { own, sanitizeText } from "./worker-redaction.mjs";
|
|
46
47
|
import { createWorkerToolkit } from "./worker-toolkit.mjs";
|
|
47
48
|
import { ToolIngress } from "./worker-tools.mjs";
|
|
48
49
|
import { bindWorkerWorkspace } from "./worker-workspace.mjs";
|
|
@@ -84,6 +85,9 @@ let modelOutputBytes = 0;
|
|
|
84
85
|
let stage = "guards";
|
|
85
86
|
let failure;
|
|
86
87
|
let terminalStopReason = "UNKNOWN";
|
|
88
|
+
// The provider's words for the failed model request this worker ends on.
|
|
89
|
+
let providerReason = "";
|
|
90
|
+
let describeProvider = () => "";
|
|
87
91
|
let preflight = "UNKNOWN";
|
|
88
92
|
let cleanupFailures = 0; // Bit flags: unsubscribe=1, abort=2, session/tool dispose=4, owned close=8.
|
|
89
93
|
let pendingAbort;
|
|
@@ -189,8 +193,10 @@ const openConversation = (target, cwd, model, thinkingLevel) => {
|
|
|
189
193
|
return manager;
|
|
190
194
|
};
|
|
191
195
|
const emitFailure = () => {
|
|
192
|
-
//
|
|
193
|
-
//
|
|
196
|
+
// Fixed labels and primitives, plus one piece of provider text: its reason
|
|
197
|
+
// for the failed model request, already redacted with this worker's
|
|
198
|
+
// credentials and bounded. Never exception text, response headers, payloads,
|
|
199
|
+
// usage or tool contents.
|
|
194
200
|
const line = `${JSON.stringify({
|
|
195
201
|
...failure,
|
|
196
202
|
outcome: "failed",
|
|
@@ -203,6 +209,10 @@ const emitFailure = () => {
|
|
|
203
209
|
requestPrepared: modelState?.requestPrepared ?? false,
|
|
204
210
|
actualResponseStatus: modelState?.actualResponseStatus ?? "UNKNOWN",
|
|
205
211
|
retryAttempts: modelState?.retryAttempts ?? 0,
|
|
212
|
+
...(failure?.class === "model-request-failed" &&
|
|
213
|
+
(providerReason || modelState?.reason)
|
|
214
|
+
? { error: providerReason || modelState.reason }
|
|
215
|
+
: {}),
|
|
206
216
|
cleanupFailures,
|
|
207
217
|
cleanupSettled,
|
|
208
218
|
})}\n`;
|
|
@@ -211,7 +221,7 @@ const emitFailure = () => {
|
|
|
211
221
|
bytes += Buffer.byteLength(text);
|
|
212
222
|
process.stderr.write(text);
|
|
213
223
|
};
|
|
214
|
-
if (Buffer.byteLength(line) <=
|
|
224
|
+
if (Buffer.byteLength(line) <= 1024) write(line);
|
|
215
225
|
if (cleanupSettled)
|
|
216
226
|
write("SDK worker failed or returned an incomplete result.\n");
|
|
217
227
|
};
|
|
@@ -562,9 +572,28 @@ try {
|
|
|
562
572
|
toolkit.sessionOptions.tools.some((name) => !activeTools.includes(name))
|
|
563
573
|
)
|
|
564
574
|
refuse("session", "tool-substitution");
|
|
575
|
+
// What a provider said about a failed request, as it may leave this worker:
|
|
576
|
+
// one line, without this worker's credentials, within its bound. Failing to
|
|
577
|
+
// keep it is never a failure of the worker.
|
|
578
|
+
const providerWords = (value) => {
|
|
579
|
+
if (typeof value !== "string") return "";
|
|
580
|
+
try {
|
|
581
|
+
const line = sanitizeText(value.slice(0, 4096), secrets)
|
|
582
|
+
.replace(/[\p{Cc}\p{Zl}\p{Zp}]+/gu, " ")
|
|
583
|
+
.trim();
|
|
584
|
+
return Buffer.from(line)
|
|
585
|
+
.subarray(0, MODEL_FAILURE_BYTES)
|
|
586
|
+
.toString("utf8")
|
|
587
|
+
.replace(/\ufffd+$/u, "");
|
|
588
|
+
} catch {
|
|
589
|
+
return "";
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
describeProvider = providerWords;
|
|
565
593
|
modelState = new WorkerModelState(
|
|
566
594
|
(event) => emitter.emit(event),
|
|
567
595
|
captureFailure,
|
|
596
|
+
providerWords,
|
|
568
597
|
);
|
|
569
598
|
unsubscribeRetry = session.subscribe((event) => modelState.event(event));
|
|
570
599
|
// AgentSession alone retries a failed model response. No provider retries,
|
|
@@ -684,6 +713,10 @@ try {
|
|
|
684
713
|
}
|
|
685
714
|
if (own(message, "role") === "assistant") {
|
|
686
715
|
const reason = own(message, "stopReason");
|
|
716
|
+
providerReason =
|
|
717
|
+
reason === "error"
|
|
718
|
+
? describeProvider(own(message, "errorMessage"))
|
|
719
|
+
: "";
|
|
687
720
|
terminalStopReason = [
|
|
688
721
|
"pending",
|
|
689
722
|
"stop",
|