@abelxiaoxing/cadence 2.0.34 → 2.0.36
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.de.md +2 -2
- package/README.es.md +2 -2
- package/README.fr.md +2 -2
- package/README.ja.md +1 -2
- package/README.ko.md +2 -2
- package/README.md +5 -2
- package/README.pt-BR.md +2 -2
- package/README.ru.md +3 -2
- package/README.zh-CN.md +2 -2
- package/docs/conversation-mode.md +37 -0
- package/package.json +7 -11
- package/src/abort-scope.ts +47 -0
- package/src/cadence-instructions.ts +1 -0
- package/src/image-content.mjs +120 -0
- package/src/native-build.ts +1 -1
- package/src/sdk-worker.mjs +52 -0
- package/src/service/contracts/core.ts +1 -0
- package/src/service/contracts/models.ts +3 -0
- package/src/service/contracts/workbench.ts +168 -3
- package/src/service-cli.mjs +6 -1
- package/src/service-host.mjs +686 -96
- package/src/service-http-client.ts +55 -50
- package/src/worker-public.mjs +6 -1
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +19 -17
- package/web/dist/manifest.json +7 -7
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { abortScope } from "./abort-scope.ts";
|
|
1
2
|
import type {
|
|
2
3
|
WorkbenchCommand,
|
|
3
4
|
WorkbenchRead,
|
|
@@ -129,60 +130,64 @@ export class HttpServiceTransport implements ServiceTransport {
|
|
|
129
130
|
write = wire.method === "POST";
|
|
130
131
|
// No automatic session/preflight refresh, changed command ID, mutation retry,
|
|
131
132
|
// credential query or redirect follow after an uncertain HTTP outcome.
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
credentials: "same-origin",
|
|
138
|
-
redirect: "error",
|
|
139
|
-
signal:
|
|
140
|
-
this.options.requestTimeoutMs === undefined
|
|
141
|
-
? signal
|
|
142
|
-
: AbortSignal.any([
|
|
143
|
-
...(signal ? [signal] : []),
|
|
144
|
-
AbortSignal.timeout(this.options.requestTimeoutMs),
|
|
145
|
-
]),
|
|
146
|
-
...(write ? { body: wire.body } : {}),
|
|
147
|
-
},
|
|
148
|
-
);
|
|
149
|
-
// Keep a known allocation even if its original response body is lost or
|
|
150
|
-
// malformed. Without a validated CSRF challenge detach may remain blocked;
|
|
151
|
-
// never silently forget that slot and acquire 16 replacement sessions.
|
|
152
|
-
let sessionAttachment: string | undefined;
|
|
133
|
+
const scope =
|
|
134
|
+
this.options.requestTimeoutMs === undefined
|
|
135
|
+
? undefined
|
|
136
|
+
: abortScope([signal], this.options.requestTimeoutMs);
|
|
137
|
+
const requestSignal = scope?.signal ?? signal;
|
|
153
138
|
try {
|
|
154
|
-
if (
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
139
|
+
if (requestSignal?.aborted) throw requestSignal.reason;
|
|
140
|
+
const response = await this.fetcher(
|
|
141
|
+
`${this.origin}${this.options.project ? `/projects/${this.options.project}` : ""}${wire.path}`,
|
|
142
|
+
{
|
|
143
|
+
method: wire.method,
|
|
144
|
+
headers: this.headers(write),
|
|
145
|
+
credentials: "same-origin",
|
|
146
|
+
redirect: "error",
|
|
147
|
+
signal: requestSignal,
|
|
148
|
+
...(write ? { body: wire.body } : {}),
|
|
149
|
+
},
|
|
150
|
+
);
|
|
151
|
+
// Keep a known allocation even if its original response body is lost or
|
|
152
|
+
// malformed. Without a validated CSRF challenge detach may remain blocked;
|
|
153
|
+
// never silently forget that slot and acquire 16 replacement sessions.
|
|
154
|
+
let sessionAttachment: string | undefined;
|
|
155
|
+
try {
|
|
156
|
+
if (operation === "session" && response.ok) {
|
|
157
|
+
sessionAttachment = decodeId(
|
|
158
|
+
response.headers.get("x-cadence-attachment"),
|
|
159
|
+
);
|
|
160
|
+
this.attachment = sessionAttachment;
|
|
161
|
+
}
|
|
162
|
+
} catch (error) {
|
|
163
|
+
await response.body?.cancel().catch(() => {});
|
|
164
|
+
throw error;
|
|
159
165
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
sessionAttachment ??
|
|
181
|
-
decodeId(response.headers.get("x-cadence-attachment"));
|
|
182
|
-
this.csrf = reply.value.csrf;
|
|
166
|
+
const source = await boundedText(response, httpOutputLimit(operation)),
|
|
167
|
+
parsed = parseWireJson(source);
|
|
168
|
+
// Graph's category is known only after parsing. Count ORIGINAL wire bytes,
|
|
169
|
+
// not a canonical re-encoding which discards padding or alternate escapes.
|
|
170
|
+
if (utf8Bytes(source) > httpOutputLimit(operation, parsed))
|
|
171
|
+
throw new ContractError("oversize");
|
|
172
|
+
const result = decodeHttpOutput(operation, parsed);
|
|
173
|
+
if (operation === "session") {
|
|
174
|
+
const reply = decodeReply(result, decodeSessionBootstrap);
|
|
175
|
+
if (reply.kind === "ok") {
|
|
176
|
+
if (
|
|
177
|
+
(reply.value.authority === "local") !==
|
|
178
|
+
!!this.options.localCapability
|
|
179
|
+
)
|
|
180
|
+
throw new ContractError("forbidden");
|
|
181
|
+
this.attachment =
|
|
182
|
+
sessionAttachment ??
|
|
183
|
+
decodeId(response.headers.get("x-cadence-attachment"));
|
|
184
|
+
this.csrf = reply.value.csrf;
|
|
185
|
+
}
|
|
183
186
|
}
|
|
187
|
+
return result;
|
|
188
|
+
} finally {
|
|
189
|
+
scope?.dispose();
|
|
184
190
|
}
|
|
185
|
-
return result;
|
|
186
191
|
}
|
|
187
192
|
session(signal?: AbortSignal) {
|
|
188
193
|
return this.request("session", null, signal);
|
package/src/worker-public.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Public types live solely in worker-public.d.mts; the TS contract paths are re-export shims.
|
|
3
3
|
* Initially relocated mechanically from W1 core/domain/capture; not a generated build output. */
|
|
4
4
|
/** Portable service boundary. No SDK objects, credentials, filesystem paths as IDs, or execution owner. */
|
|
5
|
+
export const IMAGE_COUNT = 4;
|
|
5
6
|
export const SERVICE_PROTOCOL = 1;
|
|
6
7
|
export const WORKER_PROTOCOL = 2;
|
|
7
8
|
export const GRAPH_SCHEMA = "cadence-graph/2";
|
|
@@ -937,6 +938,7 @@ export function decodeWorkerPublicRequest(v) {
|
|
|
937
938
|
"context",
|
|
938
939
|
"instructions",
|
|
939
940
|
"prompt",
|
|
941
|
+
...(Object.hasOwn(v ?? {}, "imageCount") ? ["imageCount"] : []),
|
|
940
942
|
"handoff",
|
|
941
943
|
]);
|
|
942
944
|
const result = {
|
|
@@ -951,7 +953,10 @@ export function decodeWorkerPublicRequest(v) {
|
|
|
951
953
|
role: role(o.role),
|
|
952
954
|
context: text(o.context, 32768),
|
|
953
955
|
instructions: text(o.instructions, LIMITS.instructionsBytes, true),
|
|
954
|
-
prompt: text(o.prompt, 32768,
|
|
956
|
+
prompt: text(o.prompt, 32768, o.imageCount === undefined),
|
|
957
|
+
...(o.imageCount === undefined
|
|
958
|
+
? {}
|
|
959
|
+
: { imageCount: integer(o.imageCount, 1, IMAGE_COUNT) }),
|
|
955
960
|
handoff: decodeHandoff(o.handoff),
|
|
956
961
|
};
|
|
957
962
|
if (result.handoff.inputs.some((i) => i.assignmentId !== result.assignmentId))
|