@abelxiaoxing/cadence 2.1.1 → 2.1.2
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/package.json +1 -1
- package/src/native-build.ts +1 -1
- package/src/service/contracts/workbench.ts +82 -0
- package/src/service-host.mjs +172 -83
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +28 -28
- package/web/dist/manifest.json +7 -7
package/package.json
CHANGED
package/src/native-build.ts
CHANGED
|
@@ -143,8 +143,21 @@ export type WorkbenchRead =
|
|
|
143
143
|
| { kind: "conversation-tree"; id: string; leaf: string | null }
|
|
144
144
|
| { kind: "files"; path: string; location?: ConversationLocation }
|
|
145
145
|
| { kind: "file"; path: string; location?: ConversationLocation }
|
|
146
|
+
| {
|
|
147
|
+
/** One part of a file's exact bytes, for a download; `offset` is a
|
|
148
|
+
* multiple of `FILE_PART_BYTES`. */
|
|
149
|
+
kind: "file-part";
|
|
150
|
+
path: string;
|
|
151
|
+
offset: number;
|
|
152
|
+
location?: ConversationLocation;
|
|
153
|
+
}
|
|
146
154
|
| { kind: "directories"; path: string }
|
|
147
155
|
| { kind: "projects" };
|
|
156
|
+
/** Bytes of one `file-part` reply: their base64 is 256KiB, so a part always
|
|
157
|
+
* fits one read reply. */
|
|
158
|
+
export const FILE_PART_BYTES = 192 * 1024;
|
|
159
|
+
/** The largest file a download reads; a larger one is refused as oversize. */
|
|
160
|
+
export const FILE_DOWNLOAD_BYTES = 64 * 1024 * 1024;
|
|
148
161
|
/** Maximum UTF-8 bytes of one explicit conversation Send. */
|
|
149
162
|
export const CONVERSATION_SEND_BYTES = 16 * 1024;
|
|
150
163
|
/** Code points of a conversation name: as many as a listed title shows. */
|
|
@@ -383,6 +396,15 @@ export interface ChatContext {
|
|
|
383
396
|
provider: string;
|
|
384
397
|
model: string;
|
|
385
398
|
}
|
|
399
|
+
/** A session's input tokens by how the provider's prompt cache took them:
|
|
400
|
+
* sent uncached, read from the cache and written to it. They are summed as
|
|
401
|
+
* Pi's own session statistics sum them, over every usage record in the
|
|
402
|
+
* session file, whichever branch it is on. */
|
|
403
|
+
export interface ChatCache {
|
|
404
|
+
input: number;
|
|
405
|
+
read: number;
|
|
406
|
+
write: number;
|
|
407
|
+
}
|
|
386
408
|
/** A browser message that left nothing in the session, shown after the branch
|
|
387
409
|
* it was sent from: a refusal before any model call, a Cadence control reply,
|
|
388
410
|
* or a message sent into a reply that ended before delivering it. */
|
|
@@ -566,6 +588,9 @@ export type WorkbenchResult =
|
|
|
566
588
|
* when no model response is within the reader's walk of the branch end,
|
|
567
589
|
* or the service predates it. */
|
|
568
590
|
context?: ChatContext;
|
|
591
|
+
/** The whole session's input tokens by cache use. Absent when its file
|
|
592
|
+
* records none, or the service predates it. */
|
|
593
|
+
cache?: ChatCache;
|
|
569
594
|
/** Messages sent into the reply in progress that have not been
|
|
570
595
|
* delivered, oldest first; one Pi does not hold yet can be withdrawn.
|
|
571
596
|
* Absent when there are none. */
|
|
@@ -609,6 +634,18 @@ export type WorkbenchResult =
|
|
|
609
634
|
limited: boolean;
|
|
610
635
|
}
|
|
611
636
|
| { kind: "file"; path: string; text: string; limited: boolean }
|
|
637
|
+
| {
|
|
638
|
+
kind: "file-part";
|
|
639
|
+
path: string;
|
|
640
|
+
/** The whole file's size and its identity as this part was read: parts
|
|
641
|
+
* that disagree on either are not parts of one file. */
|
|
642
|
+
size: number;
|
|
643
|
+
version: string;
|
|
644
|
+
/** Base64 of at most `FILE_PART_BYTES` bytes from the offset asked for. */
|
|
645
|
+
data: string;
|
|
646
|
+
/** Where the next part starts; null after the last one. */
|
|
647
|
+
next: number | null;
|
|
648
|
+
}
|
|
612
649
|
| { kind: "projects"; entries: { path: string; current: boolean }[] }
|
|
613
650
|
| { kind: "accepted"; commandId: string }
|
|
614
651
|
| { kind: "project"; commandId: string; path: string; link: string };
|
|
@@ -756,6 +793,24 @@ export function decodeWorkbenchRead(v: unknown): WorkbenchRead {
|
|
|
756
793
|
known: nullable(o.known, decodeEntryId),
|
|
757
794
|
};
|
|
758
795
|
}
|
|
796
|
+
case "file-part": {
|
|
797
|
+
const scoped = Object.hasOwn(v ?? {}, "location");
|
|
798
|
+
const o = closed(v, [
|
|
799
|
+
"kind",
|
|
800
|
+
"path",
|
|
801
|
+
"offset",
|
|
802
|
+
...(scoped ? ["location"] : []),
|
|
803
|
+
]);
|
|
804
|
+
const offset = integer(o.offset, 0);
|
|
805
|
+
if (offset % FILE_PART_BYTES || offset >= FILE_DOWNLOAD_BYTES)
|
|
806
|
+
throw new ContractError("invalid");
|
|
807
|
+
return {
|
|
808
|
+
kind,
|
|
809
|
+
path: text(o.path, 4096),
|
|
810
|
+
offset,
|
|
811
|
+
...(scoped ? { location: decodeConversationLocation(o.location) } : {}),
|
|
812
|
+
};
|
|
813
|
+
}
|
|
759
814
|
default: {
|
|
760
815
|
const scoped =
|
|
761
816
|
(kind === "file" || kind === "files") &&
|
|
@@ -1241,6 +1296,14 @@ function decodeChatContext(v: unknown): ChatContext {
|
|
|
1241
1296
|
model: text(o.model, 256),
|
|
1242
1297
|
};
|
|
1243
1298
|
}
|
|
1299
|
+
function decodeChatCache(v: unknown): ChatCache {
|
|
1300
|
+
const o = closed(v, ["input", "read", "write"]);
|
|
1301
|
+
return {
|
|
1302
|
+
input: integer(o.input, 0),
|
|
1303
|
+
read: integer(o.read, 0),
|
|
1304
|
+
write: integer(o.write, 0),
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1244
1307
|
function decodeChatTreeNode(v: unknown): ChatTreeNode {
|
|
1245
1308
|
const o = closed(v, ["id", "parent", "text", "at", "leaf", "current"]);
|
|
1246
1309
|
return {
|
|
@@ -1401,6 +1464,7 @@ export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
|
|
|
1401
1464
|
"attempt",
|
|
1402
1465
|
...(Object.hasOwn(v ?? {}, "commands") ? ["commands"] : []),
|
|
1403
1466
|
...(Object.hasOwn(v ?? {}, "context") ? ["context"] : []),
|
|
1467
|
+
...(Object.hasOwn(v ?? {}, "cache") ? ["cache"] : []),
|
|
1404
1468
|
...(Object.hasOwn(v ?? {}, "pending") ? ["pending"] : []),
|
|
1405
1469
|
...(Object.hasOwn(v ?? {}, "undelivered") ? ["undelivered"] : []),
|
|
1406
1470
|
]);
|
|
@@ -1415,6 +1479,7 @@ export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
|
|
|
1415
1479
|
...(o.context === undefined
|
|
1416
1480
|
? {}
|
|
1417
1481
|
: { context: decodeChatContext(o.context) }),
|
|
1482
|
+
...(o.cache === undefined ? {} : { cache: decodeChatCache(o.cache) }),
|
|
1418
1483
|
...(o.pending === undefined
|
|
1419
1484
|
? {}
|
|
1420
1485
|
: { pending: list(o.pending, WAITING_INPUTS, decodeChatPending) }),
|
|
@@ -1512,6 +1577,23 @@ export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
|
|
|
1512
1577
|
limited: bool(o.limited),
|
|
1513
1578
|
};
|
|
1514
1579
|
}
|
|
1580
|
+
if (kind === "file-part") {
|
|
1581
|
+
const o = closed(v, ["kind", "path", "size", "version", "data", "next"]);
|
|
1582
|
+
const size = integer(o.size, 0),
|
|
1583
|
+
data = text(o.data, (FILE_PART_BYTES / 3) * 4),
|
|
1584
|
+
next = nullable(o.next, (n) => integer(n, 1)),
|
|
1585
|
+
version = text(o.version, 32, true);
|
|
1586
|
+
if (
|
|
1587
|
+
size > FILE_DOWNLOAD_BYTES ||
|
|
1588
|
+
!/^[a-f0-9]{32}$/.test(version) ||
|
|
1589
|
+
!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(
|
|
1590
|
+
data,
|
|
1591
|
+
) ||
|
|
1592
|
+
(next !== null && (next % FILE_PART_BYTES !== 0 || next >= size))
|
|
1593
|
+
)
|
|
1594
|
+
throw new ContractError("invalid");
|
|
1595
|
+
return { kind, path: text(o.path, 4096), size, version, data, next };
|
|
1596
|
+
}
|
|
1515
1597
|
if (kind === "projects") {
|
|
1516
1598
|
const o = closed(v, ["kind", "entries"]);
|
|
1517
1599
|
return {
|