@linxin666/dsh-client-ui-task-board 0.4.12 → 0.4.14
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.i18n.yaml +2 -2
- package/README.md +9 -3
- package/README.zh.md +9 -3
- package/lib/client.js +1476 -478
- package/lib/client.js.map +1 -1
- package/lib/index.js +1280 -65
- package/lib/types/client/board/AttachmentField.d.ts +70 -0
- package/lib/types/client/board/model-options.d.ts +21 -1
- package/lib/types/client/board/source-group.d.ts +27 -0
- package/lib/types/client/host-api.d.ts +25 -0
- package/lib/types/client/locales.d.ts +17 -0
- package/lib/types/client/pending-verify.d.ts +47 -0
- package/lib/types/client/service.d.ts +4 -1
- package/lib/types/core/attachment.d.ts +132 -0
- package/lib/types/core/controller.d.ts +26 -2
- package/lib/types/core/extension.d.ts +82 -0
- package/lib/types/core/session-reuse.d.ts +7 -1
- package/lib/types/core/tasks.d.ts +38 -1
- package/lib/types/core/use-cases/task-update.d.ts +21 -0
- package/lib/types/core/wire-projection.d.ts +35 -0
- package/lib/types/host/attachments.d.ts +250 -0
- package/lib/types/host/extension-registry.d.ts +40 -0
- package/lib/types/host-ledger.d.ts +16 -0
- package/lib/types/host-routes.d.ts +14 -0
- package/lib/types/host-runner.d.ts +53 -1
- package/lib/types/host-service.d.ts +59 -0
- package/lib/types/index.d.ts +23 -0
- package/lib/types/protocol.d.ts +39 -6
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +6 -2
- package/src/client/TaskBoardSettingsCard.tsx +11 -1
- package/src/client/board/AttachmentField.tsx +383 -0
- package/src/client/board/EditTaskModal.tsx +63 -0
- package/src/client/board/NewTaskModal.tsx +76 -4
- package/src/client/board/TaskBoard.tsx +47 -10
- package/src/client/board/TaskDetail.tsx +30 -2
- package/src/client/board/model-options.ts +32 -2
- package/src/client/board/source-group.ts +94 -0
- package/src/client/board.module.css +83 -0
- package/src/client/host-api.ts +70 -0
- package/src/client/index.ts +11 -0
- package/src/client/locales.ts +34 -0
- package/src/client/pending-verify.ts +90 -0
- package/src/client/service.ts +24 -0
- package/src/core/attachment.ts +287 -0
- package/src/core/controller.ts +47 -1
- package/src/core/extension.ts +86 -0
- package/src/core/session-reuse.ts +7 -1
- package/src/core/store.ts +10 -1
- package/src/core/tasks.ts +49 -0
- package/src/core/use-cases/task-update.ts +27 -2
- package/src/core/wire-projection.ts +81 -0
- package/src/host/attachments.ts +650 -0
- package/src/host/extension-registry.ts +150 -5
- package/src/host-ledger.ts +32 -4
- package/src/host-routes.ts +168 -13
- package/src/host-runner.ts +124 -4
- package/src/host-service.ts +165 -12
- package/src/index.ts +47 -0
- package/src/protocol.ts +57 -9
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import z from "@deepseek-ai/schemastery";
|
|
2
|
-
import { chmodSync, closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { accessSync, chmodSync, closeSync, constants, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, isAbsolute, join, win32 } from "node:path";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { isAbsolute as isAbsolute$1, join as join$1 } from "node:path/posix";
|
|
@@ -213,10 +213,15 @@ function sessionPollMs(seconds) {
|
|
|
213
213
|
* @param task - the task about to run.
|
|
214
214
|
* @param idleSessionIds - ids the last roster saw as present and not running;
|
|
215
215
|
* undefined when that roster is unknown.
|
|
216
|
+
* @param options.force - continue the settled session regardless of the card's
|
|
217
|
+
* own `reuseSession` opt-in. A rework is exactly that case: the reviewer read
|
|
218
|
+
* the previous run's session and sent it back. Every condition above still
|
|
219
|
+
* applies — the force waives the opt-in, never the evidence.
|
|
216
220
|
* @returns the session id to continue in, or undefined for a fresh session.
|
|
217
221
|
*/
|
|
218
|
-
function reusableSessionId(task, idleSessionIds) {
|
|
219
|
-
if (
|
|
222
|
+
function reusableSessionId(task, idleSessionIds, options = {}) {
|
|
223
|
+
if (options.force !== true && task.reuseSession !== true) return void 0;
|
|
224
|
+
if (idleSessionIds === void 0) return void 0;
|
|
220
225
|
let last;
|
|
221
226
|
for (let index = task.executions.length - 1; index >= 0; index -= 1) {
|
|
222
227
|
const candidate = task.executions[index];
|
|
@@ -601,6 +606,13 @@ const TASK_BOARD_SERVICE_NAME = "taskBoard";
|
|
|
601
606
|
* channel.
|
|
602
607
|
*/
|
|
603
608
|
const TASK_BOARD_PAYLOAD_LIMIT_BYTES = 64 * 1024;
|
|
609
|
+
/**
|
|
610
|
+
* Largest accepted free text a provider pushes into an execution, in
|
|
611
|
+
* characters: one follow-up message, or one set of rework instructions. Both
|
|
612
|
+
* reach a model as user input, so the bound keeps a single provider call from
|
|
613
|
+
* becoming an unbounded context injection.
|
|
614
|
+
*/
|
|
615
|
+
const TASK_BOARD_MESSAGE_MAX_LENGTH = 4e3;
|
|
604
616
|
/** Depth beyond which a payload is refused instead of walked. */
|
|
605
617
|
const PAYLOAD_DEPTH_LIMIT = 64;
|
|
606
618
|
/** Whether a value is a plain JSON value (no undefined, function, symbol, bigint or cycle). */
|
|
@@ -665,6 +677,196 @@ function normalizeTaskIntegrations(value) {
|
|
|
665
677
|
}
|
|
666
678
|
return Object.keys(result).length === 0 ? void 0 : result;
|
|
667
679
|
}
|
|
680
|
+
/** Maximum byte length of one attachment (10 MiB). */
|
|
681
|
+
const TASK_ATTACHMENT_MAX_BYTES = 10 * 1024 * 1024;
|
|
682
|
+
/** Maximum byte length of all attachments of one card together (32 MiB). */
|
|
683
|
+
const TASK_ATTACHMENT_TOTAL_MAX_BYTES = 32 * 1024 * 1024;
|
|
684
|
+
/** Raster media types the official image path accepts. */
|
|
685
|
+
const TASK_ATTACHMENT_IMAGE_MEDIA_TYPES = [
|
|
686
|
+
"image/png",
|
|
687
|
+
"image/jpeg",
|
|
688
|
+
"image/webp",
|
|
689
|
+
"image/gif"
|
|
690
|
+
];
|
|
691
|
+
/** Longest accepted display name of an attachment. */
|
|
692
|
+
const ATTACHMENT_NAME_MAX_LENGTH = 255;
|
|
693
|
+
/** Longest accepted media type of an attachment. */
|
|
694
|
+
const ATTACHMENT_MEDIA_TYPE_MAX_LENGTH = 255;
|
|
695
|
+
/** Longest accepted storage identifier of an attachment. */
|
|
696
|
+
const ATTACHMENT_ID_MAX_LENGTH = 512;
|
|
697
|
+
const SHA256_PATTERN = /^[0-9a-f]{64}$/;
|
|
698
|
+
const MEDIA_TYPE_PATTERN = /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/;
|
|
699
|
+
/** Every key one attachment may carry. */
|
|
700
|
+
const ATTACHMENT_KEYS = [
|
|
701
|
+
"kind",
|
|
702
|
+
"attachmentId",
|
|
703
|
+
"name",
|
|
704
|
+
"bytes",
|
|
705
|
+
"mediaType",
|
|
706
|
+
"sha256",
|
|
707
|
+
"width",
|
|
708
|
+
"height"
|
|
709
|
+
];
|
|
710
|
+
function isPlainObject(value) {
|
|
711
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
712
|
+
}
|
|
713
|
+
/** Whether a value is a well-formed positive pixel count. */
|
|
714
|
+
function isPixelCount(value) {
|
|
715
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* The canonical display name of an attachment.
|
|
719
|
+
*
|
|
720
|
+
* A name reaches the ledger from two directions: the browser picks it, and an
|
|
721
|
+
* execution prompt reads it. Both make one form mandatory — the name must be
|
|
722
|
+
* a single line without any path part, so it can neither break out of the
|
|
723
|
+
* prompt line nor point at a directory.
|
|
724
|
+
*
|
|
725
|
+
* The canonical form is therefore: the LEAF of whatever path-like text was
|
|
726
|
+
* offered, every control character (a newline included) turned into a space,
|
|
727
|
+
* whitespace runs collapsed into one space, the result trimmed and bounded.
|
|
728
|
+
* An empty result becomes a fixed placeholder.
|
|
729
|
+
*
|
|
730
|
+
* The Host upload path canonicalizes the name BEFORE publishing it, and the
|
|
731
|
+
* wire gate accepts only a name that already IS canonical — so the name the
|
|
732
|
+
* ledger holds and the name the storage holds are the same string.
|
|
733
|
+
* @param value - the offered name.
|
|
734
|
+
* @returns the canonical name.
|
|
735
|
+
*/
|
|
736
|
+
function canonicalAttachmentName(value) {
|
|
737
|
+
const cleaned = ((typeof value === "string" ? value : "").split(/[\\/]/).pop() ?? "").replace(/[\u0000-\u001f\u007f]/g, " ").replace(/\s+/g, " ").trim();
|
|
738
|
+
if (cleaned === "") return "attachment";
|
|
739
|
+
return cleaned.slice(0, ATTACHMENT_NAME_MAX_LENGTH);
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Whether an unknown value is a well-formed attachment (the STRICT gate: the
|
|
743
|
+
* wire path uses it, so a hand-written payload cannot smuggle an extra field
|
|
744
|
+
* onto the ledger, a path-like name, or an image without its pixel size).
|
|
745
|
+
* @param value - the candidate attachment.
|
|
746
|
+
* @returns whether the value is a usable attachment.
|
|
747
|
+
*/
|
|
748
|
+
function isTaskAttachment(value) {
|
|
749
|
+
if (!isPlainObject(value)) return false;
|
|
750
|
+
if (Object.keys(value).some((key) => !ATTACHMENT_KEYS.includes(key))) return false;
|
|
751
|
+
if (value.kind !== "image" && value.kind !== "file") return false;
|
|
752
|
+
if (typeof value.attachmentId !== "string") return false;
|
|
753
|
+
const id = value.attachmentId;
|
|
754
|
+
if (id === "" || id.length > ATTACHMENT_ID_MAX_LENGTH) return false;
|
|
755
|
+
if (id.includes("/") || id.includes("\\") || id.includes("..")) return false;
|
|
756
|
+
if (typeof value.name !== "string") return false;
|
|
757
|
+
if (value.name !== canonicalAttachmentName(value.name)) return false;
|
|
758
|
+
if (typeof value.bytes !== "number" || !Number.isInteger(value.bytes) || value.bytes < 0) return false;
|
|
759
|
+
if (typeof value.mediaType !== "string" || value.mediaType.length > ATTACHMENT_MEDIA_TYPE_MAX_LENGTH) return false;
|
|
760
|
+
if (!MEDIA_TYPE_PATTERN.test(value.mediaType)) return false;
|
|
761
|
+
if (value.mediaType !== value.mediaType.toLowerCase()) return false;
|
|
762
|
+
if (typeof value.sha256 !== "string" || !SHA256_PATTERN.test(value.sha256)) return false;
|
|
763
|
+
if (value.kind === "image") {
|
|
764
|
+
if (!TASK_ATTACHMENT_IMAGE_MEDIA_TYPES.includes(value.mediaType.toLowerCase())) return false;
|
|
765
|
+
if (!isPixelCount(value.width) || !isPixelCount(value.height)) return false;
|
|
766
|
+
} else if (value.width !== void 0 || value.height !== void 0) return false;
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Repair one persisted attachment entry: canonicalize its name and keep the
|
|
771
|
+
* fields that are usable. An entry that cannot be repaired — an unknown kind,
|
|
772
|
+
* a malformed identifier, an image without its pixel size — is dropped.
|
|
773
|
+
* @param value - the persisted entry.
|
|
774
|
+
* @returns the repaired attachment, or undefined when it cannot be repaired.
|
|
775
|
+
*/
|
|
776
|
+
function repairAttachment(value) {
|
|
777
|
+
if (!isPlainObject(value)) return void 0;
|
|
778
|
+
if (value.kind !== "image" && value.kind !== "file") return void 0;
|
|
779
|
+
if (typeof value.attachmentId !== "string") return void 0;
|
|
780
|
+
const id = value.attachmentId;
|
|
781
|
+
if (id === "" || id.length > ATTACHMENT_ID_MAX_LENGTH) return void 0;
|
|
782
|
+
if (id.includes("/") || id.includes("\\") || id.includes("..")) return void 0;
|
|
783
|
+
if (typeof value.bytes !== "number" || !Number.isInteger(value.bytes) || value.bytes < 0) return void 0;
|
|
784
|
+
if (typeof value.mediaType !== "string" || !MEDIA_TYPE_PATTERN.test(value.mediaType)) return void 0;
|
|
785
|
+
if (typeof value.sha256 !== "string" || !SHA256_PATTERN.test(value.sha256)) return void 0;
|
|
786
|
+
const name = canonicalAttachmentName(value.name);
|
|
787
|
+
if (value.kind === "image") {
|
|
788
|
+
if (!TASK_ATTACHMENT_IMAGE_MEDIA_TYPES.includes(value.mediaType.toLowerCase())) return void 0;
|
|
789
|
+
if (!isPixelCount(value.width) || !isPixelCount(value.height)) return void 0;
|
|
790
|
+
return {
|
|
791
|
+
kind: "image",
|
|
792
|
+
attachmentId: id,
|
|
793
|
+
name,
|
|
794
|
+
bytes: value.bytes,
|
|
795
|
+
mediaType: value.mediaType.toLowerCase(),
|
|
796
|
+
sha256: value.sha256,
|
|
797
|
+
width: value.width,
|
|
798
|
+
height: value.height
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
if (value.width !== void 0 || value.height !== void 0) return void 0;
|
|
802
|
+
return {
|
|
803
|
+
kind: "file",
|
|
804
|
+
attachmentId: id,
|
|
805
|
+
name,
|
|
806
|
+
bytes: value.bytes,
|
|
807
|
+
mediaType: value.mediaType.toLowerCase(),
|
|
808
|
+
sha256: value.sha256
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Whether a list satisfies the card-wide attachment limits: the count, the
|
|
813
|
+
* per-item byte cap, and the total byte cap.
|
|
814
|
+
* @param attachments - the candidate list.
|
|
815
|
+
* @returns whether the list fits every limit.
|
|
816
|
+
*/
|
|
817
|
+
function attachmentsWithinLimits(attachments) {
|
|
818
|
+
if (attachments.length > 8) return false;
|
|
819
|
+
let total = 0;
|
|
820
|
+
for (const attachment of attachments) {
|
|
821
|
+
if (attachment.bytes > 10485760) return false;
|
|
822
|
+
total += attachment.bytes;
|
|
823
|
+
}
|
|
824
|
+
return total <= TASK_ATTACHMENT_TOTAL_MAX_BYTES;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Whether an unknown value is a well-formed attachment LIST (the strict wire
|
|
828
|
+
* gate). The list must be non-empty: clearing attachments is expressed by
|
|
829
|
+
* omitting the field (create) or by an explicit null (update), never by an
|
|
830
|
+
* empty array. A list that repeats one storage identifier is refused: one
|
|
831
|
+
* object cannot be claimed twice.
|
|
832
|
+
* @param value - the candidate list.
|
|
833
|
+
* @returns whether the list may reach the ledger.
|
|
834
|
+
*/
|
|
835
|
+
function isTaskAttachmentList(value) {
|
|
836
|
+
if (!Array.isArray(value)) return false;
|
|
837
|
+
if (value.length === 0 || value.length > 8) return false;
|
|
838
|
+
if (!value.every(isTaskAttachment)) return false;
|
|
839
|
+
const list = value;
|
|
840
|
+
if (new Set(list.map((attachment) => attachment.attachmentId)).size !== list.length) return false;
|
|
841
|
+
return attachmentsWithinLimits(list);
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Repair a persisted attachment list: canonicalize the names, drop the
|
|
845
|
+
* entries that cannot be repaired, deduplicate the storage identifiers, and
|
|
846
|
+
* cap the count and the byte totals. Returns undefined when nothing usable
|
|
847
|
+
* remains, so the caller clears the field instead of storing an empty list —
|
|
848
|
+
* the same policy the tag and schedule repairs follow.
|
|
849
|
+
* @param value - the persisted value.
|
|
850
|
+
* @returns the repaired list, or undefined when nothing survives.
|
|
851
|
+
*/
|
|
852
|
+
function normalizeAttachments(value) {
|
|
853
|
+
if (!Array.isArray(value)) return void 0;
|
|
854
|
+
const repaired = [];
|
|
855
|
+
const seen = /* @__PURE__ */ new Set();
|
|
856
|
+
let total = 0;
|
|
857
|
+
for (const entry of value) {
|
|
858
|
+
const attachment = repairAttachment(entry);
|
|
859
|
+
if (attachment === void 0) continue;
|
|
860
|
+
if (attachment.bytes > 10485760) continue;
|
|
861
|
+
if (total + attachment.bytes > 33554432) continue;
|
|
862
|
+
if (seen.has(attachment.attachmentId)) continue;
|
|
863
|
+
seen.add(attachment.attachmentId);
|
|
864
|
+
total += attachment.bytes;
|
|
865
|
+
repaired.push(attachment);
|
|
866
|
+
if (repaired.length >= 8) break;
|
|
867
|
+
}
|
|
868
|
+
return repaired.length === 0 ? void 0 : repaired;
|
|
869
|
+
}
|
|
668
870
|
//#endregion
|
|
669
871
|
//#region src/core/tasks.ts
|
|
670
872
|
/**
|
|
@@ -674,6 +876,17 @@ function normalizeTaskIntegrations(value) {
|
|
|
674
876
|
*/
|
|
675
877
|
const EXECUTION_SUMMARY_LIMIT = 4e3;
|
|
676
878
|
/**
|
|
879
|
+
* Repair a persisted rework block: only a non-blank instruction string
|
|
880
|
+
* survives, so a hand-edited ledger loses the block instead of the execution.
|
|
881
|
+
*/
|
|
882
|
+
function normalizeExecutionRework(value) {
|
|
883
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
884
|
+
const instructions = value.instructions;
|
|
885
|
+
if (typeof instructions !== "string") return void 0;
|
|
886
|
+
const trimmed = instructions.trim();
|
|
887
|
+
return trimmed === "" ? void 0 : { instructions: trimmed };
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
677
890
|
* Trim an execution list to at most {@link EXECUTION_HISTORY_LIMIT} records,
|
|
678
891
|
* most recent last. A running (unsettled) execution is never trimmed: the
|
|
679
892
|
* Host monitor and restart recovery depend on the active record, and a task
|
|
@@ -874,6 +1087,7 @@ function freezeOf(input, now) {
|
|
|
874
1087
|
function createTask(input, now, id) {
|
|
875
1088
|
const tags = normalizeTags(input.tags);
|
|
876
1089
|
const integrations = normalizeTaskIntegrations(input.integrations);
|
|
1090
|
+
const attachments = normalizeAttachments(input.attachments);
|
|
877
1091
|
return {
|
|
878
1092
|
id,
|
|
879
1093
|
title: input.title.trim(),
|
|
@@ -899,6 +1113,7 @@ function createTask(input, now, id) {
|
|
|
899
1113
|
} },
|
|
900
1114
|
...tags === void 0 ? {} : { tags },
|
|
901
1115
|
...integrations === void 0 ? {} : { integrations },
|
|
1116
|
+
...attachments === void 0 ? {} : { attachments },
|
|
902
1117
|
...input.hidden === true ? { hidden: true } : {}
|
|
903
1118
|
};
|
|
904
1119
|
}
|
|
@@ -962,8 +1177,10 @@ function withSchedule(task, patch, now) {
|
|
|
962
1177
|
* running execution record. Returns the new task and the new execution.
|
|
963
1178
|
* @param runGroupId - cascade run group, when this run also opened executions
|
|
964
1179
|
* for the task's subtasks (see `core/subtask.ts`).
|
|
1180
|
+
* @param rework - the reviewer's instructions, when this run is a rework of the
|
|
1181
|
+
* card's previous work; recorded on the execution it opens.
|
|
965
1182
|
*/
|
|
966
|
-
function startExecution(task, now, executionId, initiatedBy, runGroupId) {
|
|
1183
|
+
function startExecution(task, now, executionId, initiatedBy, runGroupId, rework) {
|
|
967
1184
|
const execution = {
|
|
968
1185
|
id: executionId,
|
|
969
1186
|
sessionId: void 0,
|
|
@@ -971,6 +1188,7 @@ function startExecution(task, now, executionId, initiatedBy, runGroupId) {
|
|
|
971
1188
|
endedAt: void 0,
|
|
972
1189
|
result: void 0,
|
|
973
1190
|
error: void 0,
|
|
1191
|
+
...rework === void 0 ? {} : { rework },
|
|
974
1192
|
...runGroupId === void 0 || runGroupId === "" ? {} : { runGroupId },
|
|
975
1193
|
...initiatedBy === void 0 || initiatedBy === "" ? {} : { initiatedBy },
|
|
976
1194
|
...task.freeze === void 0 ? {} : {
|
|
@@ -2594,6 +2812,7 @@ function isTaskRecordShape(value) {
|
|
|
2594
2812
|
if (record.permission !== void 0 && typeof record.permission !== "string") return false;
|
|
2595
2813
|
if (record.integrations !== void 0 && (typeof record.integrations !== "object" || record.integrations === null || Array.isArray(record.integrations))) return false;
|
|
2596
2814
|
if (record.hidden !== void 0 && typeof record.hidden !== "boolean") return false;
|
|
2815
|
+
if (record.attachments !== void 0 && !Array.isArray(record.attachments)) return false;
|
|
2597
2816
|
if (record.reuseSession !== void 0 && typeof record.reuseSession !== "boolean") return false;
|
|
2598
2817
|
if (record.goalRun !== void 0 && typeof record.goalRun !== "boolean") return false;
|
|
2599
2818
|
if (record.skipVerification !== void 0 && typeof record.skipVerification !== "boolean") return false;
|
|
@@ -2757,6 +2976,7 @@ function parseLedger(raw) {
|
|
|
2757
2976
|
ownError: typeof execution.ownError === "string" ? execution.ownError : void 0,
|
|
2758
2977
|
summary: normalizeExecutionSummary(execution.summary),
|
|
2759
2978
|
verification: normalizeVerification(execution.verification),
|
|
2979
|
+
rework: normalizeExecutionRework(execution.rework),
|
|
2760
2980
|
external: execution.external === true ? true : void 0
|
|
2761
2981
|
}));
|
|
2762
2982
|
task.workspaceId = normalizeTargetId(row.workspaceId);
|
|
@@ -2772,6 +2992,7 @@ function parseLedger(raw) {
|
|
|
2772
2992
|
task.tags = normalizeTags(row.tags);
|
|
2773
2993
|
task.permissionConfirmedAt = typeof row.permissionConfirmedAt === "number" && Number.isFinite(row.permissionConfirmedAt) ? row.permissionConfirmedAt : void 0;
|
|
2774
2994
|
task.integrations = normalizeTaskIntegrations(row.integrations);
|
|
2995
|
+
task.attachments = normalizeAttachments(row.attachments);
|
|
2775
2996
|
task.hidden = row.hidden === true ? true : void 0;
|
|
2776
2997
|
tasks.push(task);
|
|
2777
2998
|
}
|
|
@@ -3473,9 +3694,20 @@ const TASK_CONTENT_FIELDS = [
|
|
|
3473
3694
|
"description",
|
|
3474
3695
|
"prompt"
|
|
3475
3696
|
];
|
|
3697
|
+
/**
|
|
3698
|
+
* The fields that freeze with the card content: the text the card says AND
|
|
3699
|
+
* the attachments it carries.
|
|
3700
|
+
*
|
|
3701
|
+
* The attachments freeze with the content because they ARE part of what the
|
|
3702
|
+
* card hands to its execution: a card whose first run already consumed an
|
|
3703
|
+
* image keeps that image, and the record of what ran stays what it was. An
|
|
3704
|
+
* executed or archived card therefore refuses an attachment change exactly
|
|
3705
|
+
* as it refuses a prompt change.
|
|
3706
|
+
*/
|
|
3707
|
+
const TASK_FROZEN_FIELDS = [...TASK_CONTENT_FIELDS, "attachments"];
|
|
3476
3708
|
/** Whether an update patch touches any task-content field. */
|
|
3477
3709
|
function hasContentPatch(patch) {
|
|
3478
|
-
return
|
|
3710
|
+
return TASK_FROZEN_FIELDS.some((field) => field in patch);
|
|
3479
3711
|
}
|
|
3480
3712
|
/**
|
|
3481
3713
|
* Whether a task's content may still be edited: the task must be on-board
|
|
@@ -3503,7 +3735,7 @@ function normalizePermission(current, value) {
|
|
|
3503
3735
|
function applyUpdateTask(tasks, id, patch, now) {
|
|
3504
3736
|
return tasks.map((task) => {
|
|
3505
3737
|
if (task.id !== id) return task;
|
|
3506
|
-
const { freeze: freezePatch, handover: handoverPatch, tags: tagsPatch, ...rest } = patch;
|
|
3738
|
+
const { freeze: freezePatch, handover: handoverPatch, tags: tagsPatch, attachments: attachmentsPatch, ...rest } = patch;
|
|
3507
3739
|
const workspaceId = "workspaceId" in patch ? normalizeTargetId(patch.workspaceId) : void 0;
|
|
3508
3740
|
const mode = "mode" in patch ? normalizeTargetId(patch.mode) : void 0;
|
|
3509
3741
|
const permission = "permission" in patch ? normalizePermission(task.permission, patch.permission) : void 0;
|
|
@@ -3525,6 +3757,7 @@ function applyUpdateTask(tasks, id, patch, now) {
|
|
|
3525
3757
|
bundledAt: now
|
|
3526
3758
|
};
|
|
3527
3759
|
if ("tags" in patch) next.tags = tagsPatch == null ? void 0 : normalizeTags(tagsPatch);
|
|
3760
|
+
if ("attachments" in patch) next.attachments = attachmentsPatch == null ? void 0 : normalizeAttachments(attachmentsPatch);
|
|
3528
3761
|
if ("permission" in patch && patch.permission !== void 0 && patch.permission !== task.permission || "handover" in patch) next.permissionConfirmedAt = void 0;
|
|
3529
3762
|
if ("reuseSession" in patch) next.reuseSession = patch.reuseSession === true ? true : void 0;
|
|
3530
3763
|
if ("goalRun" in patch) next.goalRun = patch.goalRun === true ? true : void 0;
|
|
@@ -3539,11 +3772,13 @@ function applyUpdateTask(tasks, id, patch, now) {
|
|
|
3539
3772
|
}
|
|
3540
3773
|
/**
|
|
3541
3774
|
* Every older generation the loader migrates in place. v5 only added the
|
|
3542
|
-
* per-execution acceptance block
|
|
3543
|
-
* budget,
|
|
3544
|
-
* row; a document from any
|
|
3775
|
+
* per-execution acceptance block, v6 only added the scheduling mode and run
|
|
3776
|
+
* budget, and v7 only added the card attachment metadata, so the migration is
|
|
3777
|
+
* the normalization pass that re-validates each row; a document from any
|
|
3778
|
+
* listed generation upgrades losslessly.
|
|
3545
3779
|
*/
|
|
3546
3780
|
const TASK_BOARD_MIGRATABLE_SCHEMA_VERSIONS = [
|
|
3781
|
+
6,
|
|
3547
3782
|
5,
|
|
3548
3783
|
4,
|
|
3549
3784
|
3,
|
|
@@ -3621,6 +3856,7 @@ function validImportedKnownFields(value) {
|
|
|
3621
3856
|
if (value.tags !== void 0 && !isTaskTagList(value.tags)) return false;
|
|
3622
3857
|
if (value.model !== void 0 && typeof value.model !== "string") return false;
|
|
3623
3858
|
if (value.integrations !== void 0 && normalizeTaskIntegrations(value.integrations) === void 0) return false;
|
|
3859
|
+
if (value.attachments !== void 0) return false;
|
|
3624
3860
|
if (value.schedule !== void 0 && !validImportedSchedule(value.schedule)) return false;
|
|
3625
3861
|
if (value.executions !== void 0) {
|
|
3626
3862
|
if (!Array.isArray(value.executions)) return false;
|
|
@@ -3729,7 +3965,8 @@ function createInput(value) {
|
|
|
3729
3965
|
"goalRun",
|
|
3730
3966
|
"skipVerification",
|
|
3731
3967
|
"tags",
|
|
3732
|
-
"integrations"
|
|
3968
|
+
"integrations",
|
|
3969
|
+
"attachments"
|
|
3733
3970
|
])) return false;
|
|
3734
3971
|
if (input.parentId !== void 0 && (typeof input.parentId !== "string" || input.parentId.trim() === "")) return false;
|
|
3735
3972
|
if (typeof input.title !== "string" || typeof input.description !== "string" || typeof input.prompt !== "string") return false;
|
|
@@ -3741,6 +3978,7 @@ function createInput(value) {
|
|
|
3741
3978
|
if (input.permission !== void 0 && !isTaskPermission(input.permission)) return false;
|
|
3742
3979
|
if (input.tags !== void 0 && !isTaskTagList(input.tags)) return false;
|
|
3743
3980
|
if (input.integrations !== void 0 && normalizeTaskIntegrations(input.integrations) === void 0) return false;
|
|
3981
|
+
if (input.attachments !== void 0 && !isTaskAttachmentList(input.attachments)) return false;
|
|
3744
3982
|
if (input.freeze !== void 0 && freezePayload(input.freeze) === void 0) return false;
|
|
3745
3983
|
if (input.handover !== void 0 && handoverPayload(input.handover) === void 0) return false;
|
|
3746
3984
|
if (input.schedule !== void 0) {
|
|
@@ -3778,7 +4016,8 @@ function updatePatch(value) {
|
|
|
3778
4016
|
"reuseSession",
|
|
3779
4017
|
"goalRun",
|
|
3780
4018
|
"skipVerification",
|
|
3781
|
-
"tags"
|
|
4019
|
+
"tags",
|
|
4020
|
+
"attachments"
|
|
3782
4021
|
])) return false;
|
|
3783
4022
|
if (patch.reuseSession !== void 0 && patch.reuseSession !== null && typeof patch.reuseSession !== "boolean") return false;
|
|
3784
4023
|
if (patch.goalRun !== void 0 && patch.goalRun !== null && typeof patch.goalRun !== "boolean") return false;
|
|
@@ -3794,6 +4033,7 @@ function updatePatch(value) {
|
|
|
3794
4033
|
]) if (!optionalString(patch[key])) return false;
|
|
3795
4034
|
if (patch.permission !== void 0 && !isTaskPermission(patch.permission)) return false;
|
|
3796
4035
|
if (patch.tags !== void 0 && patch.tags !== null && !isTaskTagList(patch.tags)) return false;
|
|
4036
|
+
if (patch.attachments !== void 0 && patch.attachments !== null && !isTaskAttachmentList(patch.attachments)) return false;
|
|
3797
4037
|
if (patch.freeze !== void 0 && patch.freeze !== null && freezePayload(patch.freeze) === void 0) return false;
|
|
3798
4038
|
return patch.handover === void 0 || patch.handover === null || handoverPayload(patch.handover) !== void 0;
|
|
3799
4039
|
}
|
|
@@ -4019,6 +4259,24 @@ function parseEnvelopeAction(value) {
|
|
|
4019
4259
|
}
|
|
4020
4260
|
};
|
|
4021
4261
|
}
|
|
4262
|
+
case "rework": {
|
|
4263
|
+
if (!exactKeys(action, [
|
|
4264
|
+
"kind",
|
|
4265
|
+
"taskId",
|
|
4266
|
+
"instructions"
|
|
4267
|
+
])) return void 0;
|
|
4268
|
+
if (taskId === void 0 || typeof action.instructions !== "string") return void 0;
|
|
4269
|
+
const instructions = action.instructions.trim();
|
|
4270
|
+
if (instructions === "" || instructions.length > 4e3) return void 0;
|
|
4271
|
+
return {
|
|
4272
|
+
requestId: envelope.requestId,
|
|
4273
|
+
action: {
|
|
4274
|
+
kind: "rework",
|
|
4275
|
+
taskId,
|
|
4276
|
+
instructions
|
|
4277
|
+
}
|
|
4278
|
+
};
|
|
4279
|
+
}
|
|
4022
4280
|
case "confirm-permission":
|
|
4023
4281
|
case "delete":
|
|
4024
4282
|
case "archive":
|
|
@@ -5058,14 +5316,16 @@ var HostTaskLedger = class {
|
|
|
5058
5316
|
this.document.tasks = [...result.tasks];
|
|
5059
5317
|
break;
|
|
5060
5318
|
}
|
|
5319
|
+
case "rework":
|
|
5061
5320
|
case "rerun":
|
|
5062
5321
|
case "run": {
|
|
5063
5322
|
const task = this.document.tasks.find((item) => item.id === action.taskId);
|
|
5064
5323
|
if (task?.archivedAt !== void 0) throw new Error("archived task is read-only");
|
|
5065
5324
|
if (task === void 0 || hasOpenExecution(task)) throw new Error("task is already running or missing");
|
|
5325
|
+
const rework = action.kind === "rework" ? this.reworkInput(task, action.instructions) : void 0;
|
|
5066
5326
|
const refusal = this.bindingRefusal(task);
|
|
5067
5327
|
if (refusal !== void 0) throw new Error(bindingRefusalMessage(refusal, this.sessionDefaultPermission, "run"));
|
|
5068
|
-
runs = this.startRun(task, now, initiator, action.kind
|
|
5328
|
+
runs = this.startRun(task, now, initiator, action.kind !== "run", void 0, rework);
|
|
5069
5329
|
break;
|
|
5070
5330
|
}
|
|
5071
5331
|
default: throw new Error(`unknown task board action kind: ${String(action.kind)}`);
|
|
@@ -5107,6 +5367,24 @@ var HostTaskLedger = class {
|
|
|
5107
5367
|
title: root.title
|
|
5108
5368
|
};
|
|
5109
5369
|
}
|
|
5370
|
+
/**
|
|
5371
|
+
* The rework block a rework request opens its execution with, or the refusal
|
|
5372
|
+
* that names why there is nothing to rework.
|
|
5373
|
+
*
|
|
5374
|
+
* Read from the ledger alone: a card that never ran, and a card whose runs
|
|
5375
|
+
* recorded no session, have no conversation to send the reviewer's
|
|
5376
|
+
* instructions into. Minting one would hand those instructions to an agent
|
|
5377
|
+
* that never saw the work being sent back, which is the opposite of what a
|
|
5378
|
+
* rework asks for.
|
|
5379
|
+
* @param task - the card being reworked.
|
|
5380
|
+
* @param instructions - the reviewer's instructions, already validated.
|
|
5381
|
+
* @returns the block recorded on the opened execution.
|
|
5382
|
+
*/
|
|
5383
|
+
reworkInput(task, instructions) {
|
|
5384
|
+
if (task.executions.length === 0) throw new Error("task " + task.id + " has never executed; there is no run to rework");
|
|
5385
|
+
if ([...task.executions].reverse().find((entry) => entry.endedAt !== void 0 && entry.sessionId !== void 0)?.sessionId === void 0) throw new Error("task " + task.id + " records no execution session to continue");
|
|
5386
|
+
return { instructions };
|
|
5387
|
+
}
|
|
5110
5388
|
/** Whether a task or any of its subtasks still has an open execution. */
|
|
5111
5389
|
subtreeHasOpenExecution(id) {
|
|
5112
5390
|
return subtreeTasks(this.document.tasks, id, this.maxSubtaskDepth).some((task) => hasOpenExecution(task));
|
|
@@ -5133,14 +5411,16 @@ var HostTaskLedger = class {
|
|
|
5133
5411
|
* @param progress - when set, this run was a due occurrence and the root's
|
|
5134
5412
|
* rule is advanced (counter, next target, stop/skip record) in the same
|
|
5135
5413
|
* atomic commit that opened the execution.
|
|
5414
|
+
* @param rework - the reviewer's instructions, when this run redoes previous
|
|
5415
|
+
* work; recorded on the execution it opens.
|
|
5136
5416
|
*/
|
|
5137
|
-
startRun(root, now, initiator, rerun = false, progress) {
|
|
5417
|
+
startRun(root, now, initiator, rerun = false, progress, rework) {
|
|
5138
5418
|
const before = this.document.tasks;
|
|
5139
5419
|
const [participant] = cascadeTargets(before, root.id);
|
|
5140
5420
|
if (participant === void 0 || participant.archivedAt !== void 0) return [];
|
|
5141
5421
|
if (hasOpenExecution(participant)) return [];
|
|
5142
5422
|
const groupId = crypto.randomUUID();
|
|
5143
|
-
const opened = startExecution(rerun ? withStatus(participant, "todo", now) : participant, now, crypto.randomUUID(), initiator, groupId);
|
|
5423
|
+
const opened = startExecution(rerun ? withStatus(participant, "todo", now) : participant, now, crypto.randomUUID(), initiator, groupId, rework);
|
|
5144
5424
|
let tasks = before.map((task) => task.id === participant.id ? opened.task : task);
|
|
5145
5425
|
if (progress !== void 0) tasks = applyScheduleProgress(tasks, root.id, progress, now);
|
|
5146
5426
|
this.document.tasks = [...tasks];
|
|
@@ -5448,10 +5728,10 @@ var HostTaskLedger = class {
|
|
|
5448
5728
|
if (typeof parsed.schemaVersion === "number" && TASK_BOARD_MIGRATABLE_SCHEMA_VERSIONS.includes(parsed.schemaVersion)) try {
|
|
5449
5729
|
return this.migrateLegacyDocument(parsed);
|
|
5450
5730
|
} catch (error) {
|
|
5451
|
-
throw new Error(`ledger v${String(parsed.schemaVersion)} to
|
|
5731
|
+
throw new Error(`ledger v${String(parsed.schemaVersion)} to v7 migration failed; original file kept at ${this.file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
5452
5732
|
}
|
|
5453
5733
|
try {
|
|
5454
|
-
if (parsed.schemaVersion !==
|
|
5734
|
+
if (parsed.schemaVersion !== 7 || !Array.isArray(parsed.tasks)) throw new Error("unsupported ledger schema");
|
|
5455
5735
|
return this.normalizeDocument(parsed);
|
|
5456
5736
|
} catch (error) {
|
|
5457
5737
|
return this.recoverCorrupt(dir, existed, error);
|
|
@@ -5474,7 +5754,7 @@ var HostTaskLedger = class {
|
|
|
5474
5754
|
const sidecarLastTickAt = this.readSchedulerSidecar();
|
|
5475
5755
|
const lastTickAt = sidecarLastTickAt === void 0 || documentLastTickAt !== void 0 && documentLastTickAt >= sidecarLastTickAt ? documentLastTickAt : sidecarLastTickAt;
|
|
5476
5756
|
return {
|
|
5477
|
-
schemaVersion:
|
|
5757
|
+
schemaVersion: 7,
|
|
5478
5758
|
revision: Number.isSafeInteger(parsed.revision) && parsed.revision >= 0 ? parsed.revision : 0,
|
|
5479
5759
|
tasks,
|
|
5480
5760
|
scheduler: {
|
|
@@ -5500,7 +5780,7 @@ var HostTaskLedger = class {
|
|
|
5500
5780
|
if (existed) renameSync(this.file, `${this.file}.corrupt-${this.now()}-${process.pid}-${crypto.randomUUID()}`);
|
|
5501
5781
|
mkdirSync(dir, { recursive: true });
|
|
5502
5782
|
return {
|
|
5503
|
-
schemaVersion:
|
|
5783
|
+
schemaVersion: 7,
|
|
5504
5784
|
revision: 0,
|
|
5505
5785
|
tasks: [],
|
|
5506
5786
|
scheduler: {
|
|
@@ -5741,6 +6021,429 @@ function resolveReasoningEffort(requested, catalog, route) {
|
|
|
5741
6021
|
return declaredRoute(catalog, route)?.reasoning?.efforts.some((option) => option.id === effort) === true ? { effort } : { dropped: effort };
|
|
5742
6022
|
}
|
|
5743
6023
|
//#endregion
|
|
6024
|
+
//#region src/host/attachments.ts
|
|
6025
|
+
/**
|
|
6026
|
+
* Host-side attachment plumbing: the trusted upload path, the verification
|
|
6027
|
+
* against the official attachment storage, and the execution-time resolution
|
|
6028
|
+
* of a card's attachments into prompt parts.
|
|
6029
|
+
*
|
|
6030
|
+
* The board keeps METADATA in the ledger; the bytes live in the official
|
|
6031
|
+
* storage (`ctx.attachments`). This module is the only place that touches
|
|
6032
|
+
* both: it publishes bytes into the storage, proves a recorded claim against
|
|
6033
|
+
* it, and reads the objects back for an execution.
|
|
6034
|
+
*
|
|
6035
|
+
* The official storage has NO deletion API. Removing an attachment or deleting
|
|
6036
|
+
* a card therefore removes METADATA only: the stored object stays where it is.
|
|
6037
|
+
*/
|
|
6038
|
+
/**
|
|
6039
|
+
* One attachment failure, carrying the class the route maps to a status and a
|
|
6040
|
+
* message that never contains raw bytes or a host path.
|
|
6041
|
+
*/
|
|
6042
|
+
var TaskBoardAttachmentError = class extends Error {
|
|
6043
|
+
code;
|
|
6044
|
+
constructor(code, message, options) {
|
|
6045
|
+
super(message, options);
|
|
6046
|
+
this.code = code;
|
|
6047
|
+
this.name = "TaskBoardAttachmentError";
|
|
6048
|
+
}
|
|
6049
|
+
};
|
|
6050
|
+
/** The HTTP status one attachment failure class answers with. */
|
|
6051
|
+
function attachmentErrorStatus(code) {
|
|
6052
|
+
if (code === "invalid-request" || code === "invalid-image" || code === "unreadable") return 400;
|
|
6053
|
+
if (code === "unsupported-type") return 415;
|
|
6054
|
+
if (code === "too-large") return 413;
|
|
6055
|
+
if (code === "not-found") return 404;
|
|
6056
|
+
return 503;
|
|
6057
|
+
}
|
|
6058
|
+
/** Lowercase hex sha256 digest of the exact bytes. */
|
|
6059
|
+
function sha256Hex(bytes) {
|
|
6060
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
6061
|
+
}
|
|
6062
|
+
/** Whether a value names one of the raster media types the image path accepts. */
|
|
6063
|
+
function isImageMediaType(value) {
|
|
6064
|
+
return typeof value === "string" && TASK_ATTACHMENT_IMAGE_MEDIA_TYPES.includes(value.toLowerCase());
|
|
6065
|
+
}
|
|
6066
|
+
/**
|
|
6067
|
+
* Normalize a client-declared file media type: a well-formed type is kept
|
|
6068
|
+
* (lowercased), anything else falls back to the opaque binary type. The type
|
|
6069
|
+
* of a verbatim file is a declaration, not something the storage can prove.
|
|
6070
|
+
*/
|
|
6071
|
+
function normalizeFileMediaType(value) {
|
|
6072
|
+
if (typeof value !== "string") return "application/octet-stream";
|
|
6073
|
+
const trimmed = value.trim().toLowerCase();
|
|
6074
|
+
if (trimmed === "" || trimmed.length > 255) return "application/octet-stream";
|
|
6075
|
+
return /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/.test(trimmed) ? trimmed : "application/octet-stream";
|
|
6076
|
+
}
|
|
6077
|
+
/**
|
|
6078
|
+
* The canonical display name of an upload.
|
|
6079
|
+
*
|
|
6080
|
+
* The Host publishes the canonical name, and the ledger stores the same
|
|
6081
|
+
* string: the wire gate accepts only a name that already IS canonical, so a
|
|
6082
|
+
* client cannot rename an object into something the storage never saw. The
|
|
6083
|
+
* canonical form is single-line and free of any path part, which is what
|
|
6084
|
+
* makes it safe to place in an execution prompt.
|
|
6085
|
+
*/
|
|
6086
|
+
function sanitizeAttachmentName(value) {
|
|
6087
|
+
return canonicalAttachmentName(value);
|
|
6088
|
+
}
|
|
6089
|
+
/**
|
|
6090
|
+
* The per-image byte cap this deployment enforces: the board's own ceiling
|
|
6091
|
+
* lowered by the storage's own policy when that policy is stricter.
|
|
6092
|
+
*/
|
|
6093
|
+
function effectiveImageByteLimit(store) {
|
|
6094
|
+
const deployment = store?.imageLimits?.maxImageBytes;
|
|
6095
|
+
if (typeof deployment !== "number" || !Number.isFinite(deployment) || deployment <= 0) return TASK_ATTACHMENT_MAX_BYTES;
|
|
6096
|
+
return Math.min(TASK_ATTACHMENT_MAX_BYTES, deployment);
|
|
6097
|
+
}
|
|
6098
|
+
/**
|
|
6099
|
+
* Read a whole request body, refusing it the moment it grows past the cap.
|
|
6100
|
+
* The count is the ACTUAL byte length of the stream, not a declared length.
|
|
6101
|
+
*/
|
|
6102
|
+
async function readRequestBytes(req, limit) {
|
|
6103
|
+
const chunks = [];
|
|
6104
|
+
let size = 0;
|
|
6105
|
+
let overflow = false;
|
|
6106
|
+
for await (const chunk of req) {
|
|
6107
|
+
const buffer = chunk;
|
|
6108
|
+
size += buffer.length;
|
|
6109
|
+
if (size > limit) {
|
|
6110
|
+
overflow = true;
|
|
6111
|
+
chunks.length = 0;
|
|
6112
|
+
continue;
|
|
6113
|
+
}
|
|
6114
|
+
chunks.push(buffer);
|
|
6115
|
+
}
|
|
6116
|
+
if (overflow) throw new TaskBoardAttachmentError("too-large", `attachment exceeds the ${limit} byte limit`);
|
|
6117
|
+
return new Uint8Array(Buffer.concat(chunks));
|
|
6118
|
+
}
|
|
6119
|
+
/**
|
|
6120
|
+
* A byte stream that measures and digests what it yields.
|
|
6121
|
+
*
|
|
6122
|
+
* The file path streams the request straight into the official storage: the
|
|
6123
|
+
* bytes are never collected in memory, and the count and digest the board
|
|
6124
|
+
* records are the ones computed from the bytes that actually went in.
|
|
6125
|
+
*/
|
|
6126
|
+
var MeasuredStream = class {
|
|
6127
|
+
limit;
|
|
6128
|
+
hash = createHash("sha256");
|
|
6129
|
+
size = 0;
|
|
6130
|
+
finished = false;
|
|
6131
|
+
constructor(limit) {
|
|
6132
|
+
this.limit = limit;
|
|
6133
|
+
}
|
|
6134
|
+
/** The byte length seen so far. */
|
|
6135
|
+
get bytes() {
|
|
6136
|
+
return this.size;
|
|
6137
|
+
}
|
|
6138
|
+
/** The digest of the bytes seen so far; final once the stream ended. */
|
|
6139
|
+
digest() {
|
|
6140
|
+
return this.hash.digest("hex");
|
|
6141
|
+
}
|
|
6142
|
+
/** Whether the whole stream was consumed. */
|
|
6143
|
+
get complete() {
|
|
6144
|
+
return this.finished;
|
|
6145
|
+
}
|
|
6146
|
+
/** The chunks, refusing the stream the moment it grows past the cap. */
|
|
6147
|
+
async *chunks(source) {
|
|
6148
|
+
for await (const chunk of source) {
|
|
6149
|
+
this.size += chunk.byteLength;
|
|
6150
|
+
if (this.size > this.limit) throw new TaskBoardAttachmentError("too-large", `attachment exceeds the ${this.limit} byte limit`);
|
|
6151
|
+
this.hash.update(chunk);
|
|
6152
|
+
yield chunk;
|
|
6153
|
+
}
|
|
6154
|
+
this.finished = true;
|
|
6155
|
+
}
|
|
6156
|
+
};
|
|
6157
|
+
/**
|
|
6158
|
+
* The request body as a byte stream: the file path hands it straight to the
|
|
6159
|
+
* official storage, so the bytes are never collected in memory.
|
|
6160
|
+
*/
|
|
6161
|
+
function requestChunks(req) {
|
|
6162
|
+
return req;
|
|
6163
|
+
}
|
|
6164
|
+
/**
|
|
6165
|
+
* The image reference a recorded attachment stands for. The stored object is
|
|
6166
|
+
* addressed by its opaque identifier; the rest of the fields are the board's
|
|
6167
|
+
* own record of what the storage holds.
|
|
6168
|
+
*/
|
|
6169
|
+
function imageRefOf(attachment) {
|
|
6170
|
+
if (attachment.width === void 0 || attachment.height === void 0) throw new TaskBoardAttachmentError("unreadable", `attachment ${attachment.attachmentId} carries no image dimensions`);
|
|
6171
|
+
return {
|
|
6172
|
+
attachmentId: attachment.attachmentId,
|
|
6173
|
+
mediaType: attachment.mediaType,
|
|
6174
|
+
bytes: attachment.bytes,
|
|
6175
|
+
width: attachment.width,
|
|
6176
|
+
height: attachment.height,
|
|
6177
|
+
...attachment.name === "" ? {} : { name: attachment.name }
|
|
6178
|
+
};
|
|
6179
|
+
}
|
|
6180
|
+
/** The file reference a recorded attachment stands for. */
|
|
6181
|
+
function fileRefOf(attachment) {
|
|
6182
|
+
return {
|
|
6183
|
+
attachmentId: attachment.attachmentId,
|
|
6184
|
+
name: attachment.name,
|
|
6185
|
+
bytes: attachment.bytes
|
|
6186
|
+
};
|
|
6187
|
+
}
|
|
6188
|
+
/**
|
|
6189
|
+
* Publish one image into the official storage and describe it with
|
|
6190
|
+
* host-computed metadata.
|
|
6191
|
+
*
|
|
6192
|
+
* The image is validated before it is stored (the storage checks the decoded
|
|
6193
|
+
* bytes against the declared type), and the recorded digest is computed over
|
|
6194
|
+
* the NORMALIZED bytes the storage actually kept — not over what the client
|
|
6195
|
+
* sent — so the metadata and the object can never disagree.
|
|
6196
|
+
*/
|
|
6197
|
+
async function storeImage(store, data, name, mediaType) {
|
|
6198
|
+
if (!isImageMediaType(mediaType)) throw new TaskBoardAttachmentError("unsupported-type", `${mediaType} is not an accepted image type`);
|
|
6199
|
+
const limit = effectiveImageByteLimit(store);
|
|
6200
|
+
if (data.byteLength > limit) throw new TaskBoardAttachmentError("too-large", `image exceeds the ${limit} byte limit`);
|
|
6201
|
+
const type = mediaType.toLowerCase();
|
|
6202
|
+
try {
|
|
6203
|
+
await store.validateImage({
|
|
6204
|
+
data,
|
|
6205
|
+
mediaType: type,
|
|
6206
|
+
name
|
|
6207
|
+
});
|
|
6208
|
+
const ref = await store.saveImage({
|
|
6209
|
+
data,
|
|
6210
|
+
mediaType: type,
|
|
6211
|
+
name
|
|
6212
|
+
});
|
|
6213
|
+
const stored = await store.readImage(ref);
|
|
6214
|
+
return {
|
|
6215
|
+
kind: "image",
|
|
6216
|
+
attachmentId: String(ref.attachmentId),
|
|
6217
|
+
name: canonicalAttachmentName(stored.ref.name ?? name),
|
|
6218
|
+
bytes: stored.ref.bytes,
|
|
6219
|
+
mediaType: stored.ref.mediaType,
|
|
6220
|
+
sha256: sha256Hex(stored.data),
|
|
6221
|
+
width: stored.ref.width,
|
|
6222
|
+
height: stored.ref.height
|
|
6223
|
+
};
|
|
6224
|
+
} catch (error) {
|
|
6225
|
+
throw asAttachmentError(error);
|
|
6226
|
+
}
|
|
6227
|
+
}
|
|
6228
|
+
/**
|
|
6229
|
+
* Publish one file into the official storage and describe it with
|
|
6230
|
+
* host-computed metadata. The digest is computed from the streamed bytes, so
|
|
6231
|
+
* the record and the stored object agree by construction.
|
|
6232
|
+
*/
|
|
6233
|
+
async function storeFile(store, chunks, name, mediaType, signal) {
|
|
6234
|
+
const measured = new MeasuredStream(TASK_ATTACHMENT_MAX_BYTES);
|
|
6235
|
+
try {
|
|
6236
|
+
const ref = await store.saveFileStream({
|
|
6237
|
+
data: measured.chunks(chunks),
|
|
6238
|
+
...signal === void 0 ? {} : { signal },
|
|
6239
|
+
name
|
|
6240
|
+
});
|
|
6241
|
+
const sha256 = measured.digest();
|
|
6242
|
+
return {
|
|
6243
|
+
attachment: {
|
|
6244
|
+
kind: "file",
|
|
6245
|
+
attachmentId: String(ref.attachmentId),
|
|
6246
|
+
name: canonicalAttachmentName(ref.name || name),
|
|
6247
|
+
bytes: ref.bytes,
|
|
6248
|
+
mediaType: normalizeFileMediaType(mediaType),
|
|
6249
|
+
sha256
|
|
6250
|
+
},
|
|
6251
|
+
bytes: measured.bytes,
|
|
6252
|
+
sha256
|
|
6253
|
+
};
|
|
6254
|
+
} catch (error) {
|
|
6255
|
+
throw asAttachmentError(error);
|
|
6256
|
+
}
|
|
6257
|
+
}
|
|
6258
|
+
/**
|
|
6259
|
+
* Map an official attachment failure onto the board's own classes, so a
|
|
6260
|
+
* storage fault reads as "the storage is unavailable" and a rejected image
|
|
6261
|
+
* reads as "the image is not acceptable" — never as an internal error.
|
|
6262
|
+
*/
|
|
6263
|
+
function asAttachmentError(error) {
|
|
6264
|
+
if (error instanceof TaskBoardAttachmentError) return error;
|
|
6265
|
+
const code = error?.code;
|
|
6266
|
+
if (typeof code === "string") {
|
|
6267
|
+
if (code === "IMAGE_TOO_LARGE" || code === "IMAGES_TOO_LARGE") return new TaskBoardAttachmentError("too-large", "the attachment exceeds the deployment size limit", { cause: error });
|
|
6268
|
+
if (code === "TOO_MANY_IMAGES") return new TaskBoardAttachmentError("too-large", "the attachment exceeds the deployment image count limit", { cause: error });
|
|
6269
|
+
if (code === "UNSUPPORTED_IMAGE_TYPE" || code === "IMAGE_TYPE_MISMATCH") return new TaskBoardAttachmentError("unsupported-type", "the attachment is not an accepted image type", { cause: error });
|
|
6270
|
+
if (code === "INVALID_IMAGE" || code === "INVALID_IMAGE_BASE64" || code === "IMAGE_TOO_MANY_PIXELS" || code === "IMAGE_DIMENSION_TOO_LARGE") return new TaskBoardAttachmentError("invalid-image", "the attachment is not a readable image", { cause: error });
|
|
6271
|
+
if (code === "ATTACHMENT_NOT_FOUND") return new TaskBoardAttachmentError("not-found", "the attachment is not in the storage", { cause: error });
|
|
6272
|
+
if (code === "ATTACHMENT_READ_FAILED" || code === "ATTACHMENT_CORRUPT") return new TaskBoardAttachmentError("unreadable", "the stored attachment could not be read back", { cause: error });
|
|
6273
|
+
if (code === "ATTACHMENT_WRITE_FAILED" || code === "ATTACHMENT_FILES_UNSUPPORTED" || code === "ATTACHMENT_PROJECTION_UNSUPPORTED") return new TaskBoardAttachmentError("storage-unavailable", "the attachment storage refused the write", { cause: error });
|
|
6274
|
+
}
|
|
6275
|
+
return new TaskBoardAttachmentError("storage-unavailable", "the attachment storage is unavailable", { cause: error });
|
|
6276
|
+
}
|
|
6277
|
+
/**
|
|
6278
|
+
* Prove every recorded attachment against the official storage: an image is
|
|
6279
|
+
* read back and compared, a file is streamed and its digest recomputed.
|
|
6280
|
+
*
|
|
6281
|
+
* A reference the storage does not know, and a record whose metadata does not
|
|
6282
|
+
* match the stored bytes, are both a refusal: the action never reaches the
|
|
6283
|
+
* ledger, so a spoofed client claim can never become a stored fact.
|
|
6284
|
+
*/
|
|
6285
|
+
async function verifyAttachments(store, attachments) {
|
|
6286
|
+
assertImageBatchWithinLimits(store, attachments);
|
|
6287
|
+
for (const attachment of attachments) if (attachment.kind === "image") await verifyImage(store, attachment);
|
|
6288
|
+
else await verifyFile(store, attachment);
|
|
6289
|
+
}
|
|
6290
|
+
/**
|
|
6291
|
+
* The official image batch limits of a deployment: how many images one
|
|
6292
|
+
* message may carry and how many bytes they may add up to.
|
|
6293
|
+
*
|
|
6294
|
+
* The board's own caps (eight attachments, 10 MiB each, 32 MiB per card) stay
|
|
6295
|
+
* in force; the deployment's policy can only lower them, and it governs the
|
|
6296
|
+
* IMAGES of one card because that is what one prompt carries.
|
|
6297
|
+
*/
|
|
6298
|
+
function officialImageBatchLimits(store) {
|
|
6299
|
+
const limits = store?.imageLimits;
|
|
6300
|
+
const maxImages = typeof limits?.maxImagesPerMessage === "number" && limits.maxImagesPerMessage > 0 ? Math.min(8, limits.maxImagesPerMessage) : 8;
|
|
6301
|
+
const maxMessageImageBytes = typeof limits?.maxMessageImageBytes === "number" && limits.maxMessageImageBytes > 0 ? Math.min(TASK_ATTACHMENT_TOTAL_MAX_BYTES, limits.maxMessageImageBytes) : TASK_ATTACHMENT_TOTAL_MAX_BYTES;
|
|
6302
|
+
return {
|
|
6303
|
+
maxImages,
|
|
6304
|
+
maxImageBytes: effectiveImageByteLimit(store),
|
|
6305
|
+
maxMessageImageBytes
|
|
6306
|
+
};
|
|
6307
|
+
}
|
|
6308
|
+
/**
|
|
6309
|
+
* Refuse a card whose images exceed the deployment's per-message budget.
|
|
6310
|
+
*
|
|
6311
|
+
* The check counts only the images: plain files travel as paths and never
|
|
6312
|
+
* enter the prompt admission, so they are not part of that budget.
|
|
6313
|
+
* @param store - the official attachment storage.
|
|
6314
|
+
* @param attachments - the card's attachments.
|
|
6315
|
+
*/
|
|
6316
|
+
function assertImageBatchWithinLimits(store, attachments) {
|
|
6317
|
+
if (store === void 0) return;
|
|
6318
|
+
const limits = officialImageBatchLimits(store);
|
|
6319
|
+
const images = attachments.filter((attachment) => attachment.kind === "image");
|
|
6320
|
+
if (images.length > limits.maxImages) throw new TaskBoardAttachmentError("too-large", `the card carries ${images.length} images, the deployment admits ${limits.maxImages} per message`);
|
|
6321
|
+
const bytes = images.reduce((sum, attachment) => sum + attachment.bytes, 0);
|
|
6322
|
+
if (bytes > limits.maxMessageImageBytes) throw new TaskBoardAttachmentError("too-large", `the card's images total ${bytes} bytes, the deployment admits ${limits.maxMessageImageBytes} per message`);
|
|
6323
|
+
for (const image of images) if (image.bytes > limits.maxImageBytes) throw new TaskBoardAttachmentError("too-large", `an image exceeds the deployment limit of ${limits.maxImageBytes} bytes`);
|
|
6324
|
+
}
|
|
6325
|
+
/** Read one image back and compare it with the recorded metadata. */
|
|
6326
|
+
async function verifyImage(store, attachment) {
|
|
6327
|
+
let stored;
|
|
6328
|
+
try {
|
|
6329
|
+
stored = await store.readImage(imageRefOf(attachment));
|
|
6330
|
+
} catch (error) {
|
|
6331
|
+
throw asAttachmentError(error);
|
|
6332
|
+
}
|
|
6333
|
+
const digest = sha256Hex(stored.data);
|
|
6334
|
+
const storedName = stored.ref.name;
|
|
6335
|
+
if (stored.ref.bytes !== attachment.bytes || stored.ref.mediaType !== attachment.mediaType || digest !== attachment.sha256 || stored.ref.width !== attachment.width || stored.ref.height !== attachment.height || storedName !== void 0 && canonicalAttachmentName(storedName) !== attachment.name) throw new TaskBoardAttachmentError("unreadable", `attachment ${attachment.attachmentId} does not match the stored object`);
|
|
6336
|
+
}
|
|
6337
|
+
/** Stream one file back and recompute its digest. */
|
|
6338
|
+
async function verifyFile(store, attachment) {
|
|
6339
|
+
const hash = createHash("sha256");
|
|
6340
|
+
let bytes = 0;
|
|
6341
|
+
try {
|
|
6342
|
+
for await (const chunk of store.readFileStream(fileRefOf(attachment))) {
|
|
6343
|
+
bytes += chunk.byteLength;
|
|
6344
|
+
hash.update(chunk);
|
|
6345
|
+
}
|
|
6346
|
+
} catch (error) {
|
|
6347
|
+
throw asAttachmentError(error);
|
|
6348
|
+
}
|
|
6349
|
+
if (bytes !== attachment.bytes || hash.digest("hex") !== attachment.sha256) throw new TaskBoardAttachmentError("unreadable", `attachment ${attachment.attachmentId} does not match the stored object`);
|
|
6350
|
+
}
|
|
6351
|
+
/**
|
|
6352
|
+
* The limits the board publishes for its attachments: the board's own caps,
|
|
6353
|
+
* lowered by the deployment's image policy where that policy is stricter.
|
|
6354
|
+
*/
|
|
6355
|
+
function publishedAttachmentLimits(store) {
|
|
6356
|
+
const batch = officialImageBatchLimits(store);
|
|
6357
|
+
return {
|
|
6358
|
+
maxAttachments: 8,
|
|
6359
|
+
maxBytes: TASK_ATTACHMENT_MAX_BYTES,
|
|
6360
|
+
maxTotalBytes: TASK_ATTACHMENT_TOTAL_MAX_BYTES,
|
|
6361
|
+
maxImages: batch.maxImages,
|
|
6362
|
+
maxImageBytes: batch.maxImageBytes,
|
|
6363
|
+
maxMessageImageBytes: batch.maxMessageImageBytes
|
|
6364
|
+
};
|
|
6365
|
+
}
|
|
6366
|
+
/**
|
|
6367
|
+
* Resolve a card's attachments for one execution: images become prompt image
|
|
6368
|
+
* parts, files become readable host paths.
|
|
6369
|
+
*
|
|
6370
|
+
* Every execution resolves the attachments afresh — the recorded metadata is
|
|
6371
|
+
* never trusted on its own, and a file whose host path is missing or
|
|
6372
|
+
* unreadable fails the run instead of being silently dropped.
|
|
6373
|
+
*/
|
|
6374
|
+
async function resolveExecutionAttachments(store, attachments) {
|
|
6375
|
+
assertImageBatchWithinLimits(store, attachments);
|
|
6376
|
+
const images = [];
|
|
6377
|
+
const files = [];
|
|
6378
|
+
for (const attachment of attachments) {
|
|
6379
|
+
if (attachment.kind === "image") {
|
|
6380
|
+
let stored;
|
|
6381
|
+
try {
|
|
6382
|
+
stored = await store.readImage(imageRefOf(attachment));
|
|
6383
|
+
} catch (error) {
|
|
6384
|
+
throw asAttachmentError(error);
|
|
6385
|
+
}
|
|
6386
|
+
images.push({
|
|
6387
|
+
type: "image",
|
|
6388
|
+
mediaType: stored.ref.mediaType,
|
|
6389
|
+
data: Buffer.from(stored.data).toString("base64"),
|
|
6390
|
+
name: attachment.name
|
|
6391
|
+
});
|
|
6392
|
+
continue;
|
|
6393
|
+
}
|
|
6394
|
+
const ref = fileRefOf(attachment);
|
|
6395
|
+
let path;
|
|
6396
|
+
try {
|
|
6397
|
+
path = store.fileHostPath(ref);
|
|
6398
|
+
} catch (error) {
|
|
6399
|
+
throw asAttachmentError(error);
|
|
6400
|
+
}
|
|
6401
|
+
if (path === void 0 || path === "") throw new TaskBoardAttachmentError("unreadable", `attachment ${attachment.attachmentId} has no readable path in this deployment`);
|
|
6402
|
+
try {
|
|
6403
|
+
accessSync(path, constants.R_OK);
|
|
6404
|
+
} catch (error) {
|
|
6405
|
+
throw new TaskBoardAttachmentError("unreadable", `attachment ${attachment.name} is not readable in this deployment`, { cause: error });
|
|
6406
|
+
}
|
|
6407
|
+
files.push({
|
|
6408
|
+
name: attachment.name,
|
|
6409
|
+
path,
|
|
6410
|
+
bytes: attachment.bytes,
|
|
6411
|
+
mediaType: attachment.mediaType
|
|
6412
|
+
});
|
|
6413
|
+
}
|
|
6414
|
+
return {
|
|
6415
|
+
images,
|
|
6416
|
+
files
|
|
6417
|
+
};
|
|
6418
|
+
}
|
|
6419
|
+
/**
|
|
6420
|
+
* The attachment section of an execution prompt: the readable paths of the
|
|
6421
|
+
* card's files, marked read-only.
|
|
6422
|
+
*
|
|
6423
|
+
* It is a section of its own — never folded into the handover preamble — so
|
|
6424
|
+
* the two kinds of reference stay distinguishable to the reading agent.
|
|
6425
|
+
*/
|
|
6426
|
+
function attachmentPromptPreamble(files) {
|
|
6427
|
+
if (files.length === 0) return void 0;
|
|
6428
|
+
return `附件文件(任务看板附件,只读路径;请直接读取这些文件,不要修改或移动它们):
|
|
6429
|
+
${files.map((file) => `- ${file.name}(${file.path},${file.bytes} 字节,${file.mediaType})`).join("\n")}`;
|
|
6430
|
+
}
|
|
6431
|
+
/**
|
|
6432
|
+
* Refuse an execution whose route cannot read images.
|
|
6433
|
+
*
|
|
6434
|
+
* The check uses the ACTUAL route of the session the run is about to use and
|
|
6435
|
+
* the model's own declared input modalities. A route that declares no
|
|
6436
|
+
* modalities is UNKNOWN, and an unknown route is allowed: the official model
|
|
6437
|
+
* catalog publishes no modality information, so it cannot answer this
|
|
6438
|
+
* question, and refusing on its silence would block every image run.
|
|
6439
|
+
*/
|
|
6440
|
+
async function assertRouteAcceptsImages(resolveModelInfo, provider, model) {
|
|
6441
|
+
if (resolveModelInfo === void 0) return;
|
|
6442
|
+
const modalities = (await resolveModelInfo(provider, model))?.inputModalities;
|
|
6443
|
+
if (!Array.isArray(modalities)) return;
|
|
6444
|
+
if (!modalities.includes("image")) throw new Error(`the model route ${provider}/${model} does not accept image input`);
|
|
6445
|
+
}
|
|
6446
|
+
//#endregion
|
|
5744
6447
|
//#region src/host-runner.ts
|
|
5745
6448
|
/**
|
|
5746
6449
|
* Mint the in-process owner peer this plugin's Host calls speak for.
|
|
@@ -5832,7 +6535,7 @@ const SERVICE_UNAVAILABLE_BACKOFF_MS = 2e3;
|
|
|
5832
6535
|
*/
|
|
5833
6536
|
const HISTORY_PAGE_LIMIT = 100;
|
|
5834
6537
|
/** One-line text of a gateway or stream failure, for a decideable reason. */
|
|
5835
|
-
function failureText(error) {
|
|
6538
|
+
function failureText$1(error) {
|
|
5836
6539
|
return error instanceof Error ? error.message : String(error);
|
|
5837
6540
|
}
|
|
5838
6541
|
function delay(ms) {
|
|
@@ -5893,6 +6596,18 @@ function schedulePromptPreamble(context) {
|
|
|
5893
6596
|
return `本次执行由任务看板的定时规则自动触发:触发时间 ${stamp}(UTC),规则时区 ${schedule.timeZone},cron 表达式 ${schedule.cron}。需要判断「今天」「现在」或计算时间窗口时,以该时区的触发时间为准。`;
|
|
5894
6597
|
}
|
|
5895
6598
|
/**
|
|
6599
|
+
* The rework section: this execution continues the card's own conversation
|
|
6600
|
+
* because a reviewer sent the previous attempt back. It states both halves the
|
|
6601
|
+
* agent must not guess — that the earlier work is the starting point, and what
|
|
6602
|
+
* the reviewer actually wants changed — and marks the instruction block with a
|
|
6603
|
+
* delimiter pair, so reviewer text cannot pass for board text.
|
|
6604
|
+
*/
|
|
6605
|
+
function reworkPromptPreamble(context) {
|
|
6606
|
+
const rework = context.rework;
|
|
6607
|
+
if (rework === void 0) return void 0;
|
|
6608
|
+
return `本次执行是同一会话上的返工:上一轮的结果被人工审阅打回,请在已完成的工作上继续修改,不要从头重做。返工意见 开始\n${escapeProvenanceDelimiter(rework.instructions)}\n返工意见 结束`;
|
|
6609
|
+
}
|
|
6610
|
+
/**
|
|
5896
6611
|
* Build the execution prompt for one task.
|
|
5897
6612
|
* @param task - the task being launched.
|
|
5898
6613
|
* @param context - the run's other members, for the execution-shape section.
|
|
@@ -5904,9 +6619,11 @@ function promptText(task, context = {}) {
|
|
|
5904
6619
|
const handoverPreamble = handover === void 0 || handover.references.length === 0 ? void 0 : `交接包引用(来自任务看板续接卡片,冻结于 ${new Date(handover.bundledAt).toISOString()}):\n${handover.references.map((reference) => `- ${reference}`).join("\n")}`;
|
|
5905
6620
|
const preambles = [
|
|
5906
6621
|
tagPromptPreamble(task),
|
|
6622
|
+
context.files === void 0 ? void 0 : attachmentPromptPreamble(context.files),
|
|
5907
6623
|
handoverPreamble,
|
|
5908
6624
|
schedulePromptPreamble(context),
|
|
5909
|
-
dispatchPromptPreamble(context)
|
|
6625
|
+
dispatchPromptPreamble(context),
|
|
6626
|
+
reworkPromptPreamble(context)
|
|
5910
6627
|
].filter((part) => part !== void 0);
|
|
5911
6628
|
const preamble = preambles.length === 0 ? void 0 : preambles.join("\n\n");
|
|
5912
6629
|
const freeze = task.freeze;
|
|
@@ -5993,6 +6710,7 @@ var HostExecutionRunner = class HostExecutionRunner {
|
|
|
5993
6710
|
gateway;
|
|
5994
6711
|
commands;
|
|
5995
6712
|
workspaceRegistry;
|
|
6713
|
+
faces;
|
|
5996
6714
|
/**
|
|
5997
6715
|
* Newest event sequence per session whose COMPLETE history walk (reaching
|
|
5998
6716
|
* the execution boundary) found no matching execution end. A later walk may
|
|
@@ -6008,10 +6726,11 @@ var HostExecutionRunner = class HostExecutionRunner {
|
|
|
6008
6726
|
*/
|
|
6009
6727
|
ownerPeer;
|
|
6010
6728
|
unsupportedSessionListWarned = false;
|
|
6011
|
-
constructor(gateway, commands, workspaceRegistry, unavailableRetry, ownerPeer) {
|
|
6729
|
+
constructor(gateway, commands, workspaceRegistry, unavailableRetry, ownerPeer, faces = {}) {
|
|
6012
6730
|
this.gateway = gateway;
|
|
6013
6731
|
this.commands = commands;
|
|
6014
6732
|
this.workspaceRegistry = workspaceRegistry;
|
|
6733
|
+
this.faces = faces;
|
|
6015
6734
|
this.unavailableAttempts = unavailableRetry?.attempts ?? SERVICE_UNAVAILABLE_ATTEMPTS;
|
|
6016
6735
|
this.unavailableBackoffMs = unavailableRetry?.backoffMs ?? SERVICE_UNAVAILABLE_BACKOFF_MS;
|
|
6017
6736
|
this.ownerPeer = ownerPeer ?? createOwnerPeer(new Context());
|
|
@@ -6098,6 +6817,28 @@ var HostExecutionRunner = class HostExecutionRunner {
|
|
|
6098
6817
|
return sessionId;
|
|
6099
6818
|
}
|
|
6100
6819
|
/**
|
|
6820
|
+
* Queue one follow-up user message into an existing execution session.
|
|
6821
|
+
*
|
|
6822
|
+
* This is the same `session/prompt` call a launch makes, with none of the
|
|
6823
|
+
* launch pins: a follow-up continues a conversation the board already
|
|
6824
|
+
* composed, so it must not re-assert the permission, rename the session, or
|
|
6825
|
+
* switch the model. The message is queued behind whatever that session is
|
|
6826
|
+
* doing, which is what lets a caller reach a run that is still working.
|
|
6827
|
+
* @param sessionId - the session the card's execution recorded.
|
|
6828
|
+
* @param text - the message to deliver, already validated by the caller.
|
|
6829
|
+
*/
|
|
6830
|
+
async followUp(sessionId, text) {
|
|
6831
|
+
await this.invoke("session", "prompt", {
|
|
6832
|
+
sessionId,
|
|
6833
|
+
requestId: "task-board-follow-up-" + crypto.randomUUID(),
|
|
6834
|
+
mode: "queue",
|
|
6835
|
+
content: [{
|
|
6836
|
+
type: "text",
|
|
6837
|
+
text
|
|
6838
|
+
}]
|
|
6839
|
+
});
|
|
6840
|
+
}
|
|
6841
|
+
/**
|
|
6101
6842
|
* Fail closed when a reused session records a different Agent preset than
|
|
6102
6843
|
* the one this task pins.
|
|
6103
6844
|
*
|
|
@@ -6179,7 +6920,10 @@ var HostExecutionRunner = class HostExecutionRunner {
|
|
|
6179
6920
|
if (command.kind !== "success") throw new Error(command.text ?? "permission command failed");
|
|
6180
6921
|
}
|
|
6181
6922
|
const requestedEffort = normalizeReasoningEffort(task.reasoningEffort);
|
|
6182
|
-
const
|
|
6923
|
+
const pinned = HostExecutionRunner.pinnedRoute(task.model);
|
|
6924
|
+
const attachments = task.attachments ?? [];
|
|
6925
|
+
const carriesImages = attachments.some((attachment) => attachment.kind === "image");
|
|
6926
|
+
const route = pinned ?? (requestedEffort === void 0 && !carriesImages ? void 0 : await this.sessionRoute(sessionId, catalog));
|
|
6183
6927
|
if (route !== void 0) {
|
|
6184
6928
|
const routeLabel = `${route.provider === void 0 ? "" : route.provider + "/"}${route.model}`;
|
|
6185
6929
|
const decision = resolveReasoningEffort(requestedEffort, catalog, route);
|
|
@@ -6187,6 +6931,7 @@ var HostExecutionRunner = class HostExecutionRunner {
|
|
|
6187
6931
|
const declared = declaredRoute(catalog, route);
|
|
6188
6932
|
const provider = declared?.provider ?? route.provider;
|
|
6189
6933
|
const modelId = declared?.model ?? route.model;
|
|
6934
|
+
if (carriesImages && provider !== void 0 && modelId !== void 0) await assertRouteAcceptsImages(this.faces.llm?.(), provider, modelId);
|
|
6190
6935
|
try {
|
|
6191
6936
|
await this.invoke("session", "selectModel", {
|
|
6192
6937
|
sessionId,
|
|
@@ -6199,19 +6944,42 @@ var HostExecutionRunner = class HostExecutionRunner {
|
|
|
6199
6944
|
console.warn(`[dsh-task-board] failed to select model "${provider === void 0 ? modelId : provider + "/" + modelId}" for session ${sessionId}, falling back to default:`, modelError);
|
|
6200
6945
|
}
|
|
6201
6946
|
}
|
|
6947
|
+
const resolved = await this.resolveAttachments(attachments);
|
|
6948
|
+
const promptContext = resolved.files.length === 0 ? context : {
|
|
6949
|
+
...context,
|
|
6950
|
+
files: resolved.files
|
|
6951
|
+
};
|
|
6202
6952
|
await this.invoke("session", "prompt", {
|
|
6203
6953
|
sessionId,
|
|
6204
6954
|
requestId: "task-board-" + crypto.randomUUID(),
|
|
6205
6955
|
mode: "queue",
|
|
6206
6956
|
content: [{
|
|
6207
6957
|
type: "text",
|
|
6208
|
-
text: promptText(task,
|
|
6209
|
-
}]
|
|
6958
|
+
text: promptText(task, promptContext)
|
|
6959
|
+
}, ...resolved.images]
|
|
6210
6960
|
});
|
|
6211
|
-
const armed = await this.armGoal(sessionId, task,
|
|
6961
|
+
const armed = await this.armGoal(sessionId, task, promptContext, goalEnabled);
|
|
6212
6962
|
onGoalArmed?.(armed);
|
|
6213
6963
|
}
|
|
6214
6964
|
/**
|
|
6965
|
+
* Resolve a card's attachments for one execution.
|
|
6966
|
+
*
|
|
6967
|
+
* A card without attachments resolves to nothing, even in a deployment that
|
|
6968
|
+
* serves no attachment storage at all. A card WITH attachments cannot run
|
|
6969
|
+
* without the storage: the run fails with a readable reason instead of
|
|
6970
|
+
* silently dropping the attachment and running the card as if it carried
|
|
6971
|
+
* none.
|
|
6972
|
+
*/
|
|
6973
|
+
async resolveAttachments(attachments) {
|
|
6974
|
+
if (attachments.length === 0) return {
|
|
6975
|
+
images: [],
|
|
6976
|
+
files: []
|
|
6977
|
+
};
|
|
6978
|
+
const store = this.faces.attachments?.();
|
|
6979
|
+
if (store === void 0) throw new Error("this deployment serves no attachment storage");
|
|
6980
|
+
return await resolveExecutionAttachments(store, attachments);
|
|
6981
|
+
}
|
|
6982
|
+
/**
|
|
6215
6983
|
* Read the host's model catalog: the default route an unconfigured session
|
|
6216
6984
|
* starts at, and each provider's models with the reasoning metadata its
|
|
6217
6985
|
* adapter exposes. The acceptance settings card and the frozen contract both
|
|
@@ -6406,7 +7174,7 @@ var HostExecutionRunner = class HostExecutionRunner {
|
|
|
6406
7174
|
return {
|
|
6407
7175
|
outcome: "pending",
|
|
6408
7176
|
unreadable: true,
|
|
6409
|
-
reason: "session/follow failed: " + failureText(error)
|
|
7177
|
+
reason: "session/follow failed: " + failureText$1(error)
|
|
6410
7178
|
};
|
|
6411
7179
|
}
|
|
6412
7180
|
const openingEvents = opening.records.map((record) => ({ event: recordEvent(record) }));
|
|
@@ -6432,7 +7200,7 @@ var HostExecutionRunner = class HostExecutionRunner {
|
|
|
6432
7200
|
return {
|
|
6433
7201
|
outcome: "pending",
|
|
6434
7202
|
unreadable: true,
|
|
6435
|
-
reason: "session/page failed: " + failureText(error)
|
|
7203
|
+
reason: "session/page failed: " + failureText$1(error)
|
|
6436
7204
|
};
|
|
6437
7205
|
}
|
|
6438
7206
|
const pageEntries = pageEvents(history);
|
|
@@ -6778,6 +7546,71 @@ var PowerInhibitor = class {
|
|
|
6778
7546
|
}
|
|
6779
7547
|
};
|
|
6780
7548
|
//#endregion
|
|
7549
|
+
//#region src/core/wire-projection.ts
|
|
7550
|
+
/**
|
|
7551
|
+
* Keys stripped from an integration payload at every depth, as whole keys and
|
|
7552
|
+
* compared case-insensitively.
|
|
7553
|
+
*
|
|
7554
|
+
* `leaseToken` is the name `dsh-task-board-team` writes for its mirror-card
|
|
7555
|
+
* lease and `lease_token` the snake spelling, while the rest are the generic
|
|
7556
|
+
* names a bearer credential hides under. The match is the whole key rather than
|
|
7557
|
+
* a substring: a payload field that merely mentions one of these words while
|
|
7558
|
+
* holding something the provider's own UI renders is not a credential and must
|
|
7559
|
+
* keep travelling.
|
|
7560
|
+
*/
|
|
7561
|
+
const CREDENTIAL_KEYS = /* @__PURE__ */ new Set([
|
|
7562
|
+
"leasetoken",
|
|
7563
|
+
"lease_token",
|
|
7564
|
+
"token",
|
|
7565
|
+
"secret",
|
|
7566
|
+
"password",
|
|
7567
|
+
"apikey",
|
|
7568
|
+
"credential"
|
|
7569
|
+
]);
|
|
7570
|
+
/** Copy one JSON value with every credential-keyed entry removed, at any depth. */
|
|
7571
|
+
function withoutCredentials(value) {
|
|
7572
|
+
if (Array.isArray(value)) return value.map(withoutCredentials);
|
|
7573
|
+
if (value === null || typeof value !== "object") return value;
|
|
7574
|
+
const copy = {};
|
|
7575
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
7576
|
+
if (CREDENTIAL_KEYS.has(key.toLowerCase())) continue;
|
|
7577
|
+
copy[key] = withoutCredentials(entry);
|
|
7578
|
+
}
|
|
7579
|
+
return copy;
|
|
7580
|
+
}
|
|
7581
|
+
/**
|
|
7582
|
+
* The card as the wire may show it: the ledger record with its integration
|
|
7583
|
+
* entries copied and stripped.
|
|
7584
|
+
*
|
|
7585
|
+
* A card that carries no integrations is returned untouched, so a provider that
|
|
7586
|
+
* stores nothing sees exactly the record the board has always published.
|
|
7587
|
+
* @param task - the ledger record about to be serialized.
|
|
7588
|
+
* @returns the projected record; the ledger object is never mutated.
|
|
7589
|
+
*/
|
|
7590
|
+
function projectTaskForWire(task) {
|
|
7591
|
+
const stored = task.integrations;
|
|
7592
|
+
if (stored === void 0) return task;
|
|
7593
|
+
const integrations = {};
|
|
7594
|
+
for (const [id, payload] of Object.entries(stored)) integrations[id] = withoutCredentials(payload);
|
|
7595
|
+
return {
|
|
7596
|
+
...task,
|
|
7597
|
+
integrations
|
|
7598
|
+
};
|
|
7599
|
+
}
|
|
7600
|
+
/**
|
|
7601
|
+
* The snapshot as every read path serializes it: the HTTP `state` answer, the
|
|
7602
|
+
* HTTP `action` answer, and the remote bridge's `board.snapshot` all start from
|
|
7603
|
+
* the object this returns.
|
|
7604
|
+
* @param snapshot - the snapshot the Host service built from its live state.
|
|
7605
|
+
* @returns the same snapshot with each card projected through {@link projectTaskForWire}.
|
|
7606
|
+
*/
|
|
7607
|
+
function projectSnapshotForWire(snapshot) {
|
|
7608
|
+
return {
|
|
7609
|
+
...snapshot,
|
|
7610
|
+
tasks: snapshot.tasks.map(projectTaskForWire)
|
|
7611
|
+
};
|
|
7612
|
+
}
|
|
7613
|
+
//#endregion
|
|
6781
7614
|
//#region src/host/extension-registry.ts
|
|
6782
7615
|
/** Diagnosable refusal raised by the registry and the capability face. */
|
|
6783
7616
|
var TaskBoardExtensionError = class extends Error {
|
|
@@ -6836,10 +7669,50 @@ function mergePayload(current, patch) {
|
|
|
6836
7669
|
function readPayload(value) {
|
|
6837
7670
|
return isTaskBoardExtensionPayload(value) ? value : void 0;
|
|
6838
7671
|
}
|
|
7672
|
+
/** One-line text of a delivery failure, for a diagnosable refusal. */
|
|
7673
|
+
function failureText(error) {
|
|
7674
|
+
return error instanceof Error ? error.message : String(error);
|
|
7675
|
+
}
|
|
7676
|
+
/**
|
|
7677
|
+
* Validate one free text a provider pushes into an execution. Blank text would
|
|
7678
|
+
* queue an empty turn, and an unbounded one would let a single provider call
|
|
7679
|
+
* inject an arbitrarily large instruction, so both are refused here rather
|
|
7680
|
+
* than at the gateway.
|
|
7681
|
+
*/
|
|
7682
|
+
function extensionText(value, what) {
|
|
7683
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
7684
|
+
if (text === "") throw new TaskBoardExtensionError("invalid-text", `a ${what} must be a non-blank string`);
|
|
7685
|
+
if (text.length > 4e3) throw new TaskBoardExtensionError("invalid-text", `a ${what} is limited to ${TASK_BOARD_MESSAGE_MAX_LENGTH} characters`);
|
|
7686
|
+
return text;
|
|
7687
|
+
}
|
|
7688
|
+
/**
|
|
7689
|
+
* The session a follow-up message goes to, or the refusal that says why there
|
|
7690
|
+
* is none. The open execution owns the answer while one is running: delivering
|
|
7691
|
+
* into the previous conversation instead would answer a question the current
|
|
7692
|
+
* run never asked.
|
|
7693
|
+
*/
|
|
7694
|
+
function followUpTarget(task) {
|
|
7695
|
+
if (task.executions.length === 0) return {
|
|
7696
|
+
refusal: "not-executed",
|
|
7697
|
+
message: `task ${task.id} has never executed, so it has no session to deliver to`
|
|
7698
|
+
};
|
|
7699
|
+
const open = [...task.executions].reverse().find((record) => record.endedAt === void 0);
|
|
7700
|
+
if (open !== void 0) return open.sessionId === void 0 ? {
|
|
7701
|
+
refusal: "session-unreachable",
|
|
7702
|
+
message: `the current execution of task ${task.id} has not attached a session yet`
|
|
7703
|
+
} : { sessionId: open.sessionId };
|
|
7704
|
+
const settled = [...task.executions].reverse().find((record) => record.sessionId !== void 0);
|
|
7705
|
+
return settled?.sessionId === void 0 ? {
|
|
7706
|
+
refusal: "session-unreachable",
|
|
7707
|
+
message: `task ${task.id} records no execution session to deliver to`
|
|
7708
|
+
} : { sessionId: settled.sessionId };
|
|
7709
|
+
}
|
|
6839
7710
|
var TaskBoardExtensionRegistry = class {
|
|
6840
7711
|
entries = /* @__PURE__ */ new Map();
|
|
6841
7712
|
ledger;
|
|
6842
7713
|
applyAction;
|
|
7714
|
+
followUpDelivery;
|
|
7715
|
+
reworkApply;
|
|
6843
7716
|
now;
|
|
6844
7717
|
uuid;
|
|
6845
7718
|
logger;
|
|
@@ -6850,6 +7723,8 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6850
7723
|
constructor(options) {
|
|
6851
7724
|
this.ledger = options.ledger;
|
|
6852
7725
|
this.applyAction = options.apply;
|
|
7726
|
+
this.followUpDelivery = options.followUp;
|
|
7727
|
+
this.reworkApply = options.rework;
|
|
6853
7728
|
this.now = options.now ?? Date.now;
|
|
6854
7729
|
this.uuid = options.uuid ?? (() => crypto.randomUUID());
|
|
6855
7730
|
this.logger = options.logger ?? DEFAULT_LOGGER;
|
|
@@ -7053,8 +7928,14 @@ var TaskBoardExtensionRegistry = class {
|
|
|
7053
7928
|
create: (draft, options) => this.createTask(entry, draft, options),
|
|
7054
7929
|
patchContent: (taskId, patch) => this.patchContent(entry, taskId, patch),
|
|
7055
7930
|
setStatus: (taskId, status, initiator) => this.setStatus(entry, taskId, status, initiator),
|
|
7056
|
-
linked: () => this.linkedTasks(entry)
|
|
7931
|
+
linked: () => this.linkedTasks(entry),
|
|
7932
|
+
rework: (taskId, instructions, initiator) => {
|
|
7933
|
+
this.rework(entry, taskId, instructions, initiator);
|
|
7934
|
+
}
|
|
7057
7935
|
},
|
|
7936
|
+
sessions: { followUp: async (taskId, text) => {
|
|
7937
|
+
await this.followUp(entry, taskId, text);
|
|
7938
|
+
} },
|
|
7058
7939
|
integration: {
|
|
7059
7940
|
read: (taskId) => {
|
|
7060
7941
|
assertActive("read");
|
|
@@ -7095,6 +7976,9 @@ var TaskBoardExtensionRegistry = class {
|
|
|
7095
7976
|
...draft.status === void 0 ? {} : { status: draft.status },
|
|
7096
7977
|
...draft.parentId === void 0 ? {} : { parentId: draft.parentId },
|
|
7097
7978
|
...draft.workspaceId === void 0 ? {} : { workspaceId: draft.workspaceId },
|
|
7979
|
+
...draft.mode === void 0 ? {} : { mode: draft.mode },
|
|
7980
|
+
...draft.model === void 0 ? {} : { model: draft.model },
|
|
7981
|
+
...draft.reasoningEffort === void 0 ? {} : { reasoningEffort: draft.reasoningEffort },
|
|
7098
7982
|
...payload === void 0 ? {} : { integrations: { [entry.extension.id]: payload } },
|
|
7099
7983
|
...options?.hidden === true ? { hidden: true } : {}
|
|
7100
7984
|
}
|
|
@@ -7105,9 +7989,7 @@ var TaskBoardExtensionRegistry = class {
|
|
|
7105
7989
|
patchContent(entry, taskId, patch) {
|
|
7106
7990
|
this.assertActive(entry, "patch content");
|
|
7107
7991
|
if (this.applyAction === void 0) throw new TaskBoardExtensionError("unavailable", "this deployment serves no action applier");
|
|
7108
|
-
|
|
7109
|
-
if (task === void 0) throw new TaskBoardExtensionError("task-not-found", `no task with id ${taskId}`);
|
|
7110
|
-
if (!canEditTaskContent(task)) throw new TaskBoardExtensionError("content-frozen", `task ${taskId} has started executing; its content is read-only`);
|
|
7992
|
+
if (!canEditTaskContent(this.requireTask(taskId))) throw new TaskBoardExtensionError("content-frozen", `task ${taskId} has started executing; its content is read-only`);
|
|
7111
7993
|
if ([
|
|
7112
7994
|
"title",
|
|
7113
7995
|
"description",
|
|
@@ -7129,6 +8011,57 @@ var TaskBoardExtensionRegistry = class {
|
|
|
7129
8011
|
status
|
|
7130
8012
|
}, initiator);
|
|
7131
8013
|
}
|
|
8014
|
+
/**
|
|
8015
|
+
* Queue one follow-up message into the session of a card's current or most
|
|
8016
|
+
* recent execution.
|
|
8017
|
+
*
|
|
8018
|
+
* A running card is the point of the capability, so an open execution is not
|
|
8019
|
+
* a refusal: the message is queued behind the turn that is already going. What
|
|
8020
|
+
* IS refused is a card with no conversation to deliver into, and a session
|
|
8021
|
+
* this Host no longer reaches — the delivery refuses, and that refusal must
|
|
8022
|
+
* reach the provider as such instead of looking like a silent success.
|
|
8023
|
+
*/
|
|
8024
|
+
async followUp(entry, taskId, text) {
|
|
8025
|
+
this.assertActive(entry, "deliver a follow-up message");
|
|
8026
|
+
const task = this.requireTask(taskId);
|
|
8027
|
+
const message = extensionText(text, "follow-up message");
|
|
8028
|
+
if (task.archivedAt !== void 0) throw new TaskBoardExtensionError("task-archived", `task ${taskId} is archived; an archived card's execution is closed`);
|
|
8029
|
+
const target = followUpTarget(task);
|
|
8030
|
+
if ("refusal" in target) throw new TaskBoardExtensionError(target.refusal, target.message);
|
|
8031
|
+
if (this.followUpDelivery === void 0) throw new TaskBoardExtensionError("unavailable", "this deployment serves no session delivery");
|
|
8032
|
+
try {
|
|
8033
|
+
await this.followUpDelivery(target.sessionId, message);
|
|
8034
|
+
} catch (error) {
|
|
8035
|
+
throw new TaskBoardExtensionError("session-unreachable", `session ${target.sessionId} of task ${taskId} did not accept the message: ${failureText(error)}`);
|
|
8036
|
+
}
|
|
8037
|
+
}
|
|
8038
|
+
/**
|
|
8039
|
+
* Re-run an executed card in its own session with rework instructions.
|
|
8040
|
+
*
|
|
8041
|
+
* The registry decides only what it can read from the ledger — the card
|
|
8042
|
+
* exists, is not archived, is not running, and has a conversation to continue
|
|
8043
|
+
* — and then hands the request to the board's own run path, so the running
|
|
8044
|
+
* lock, the permission confirmation, the acceptance contract and the spend cap
|
|
8045
|
+
* keep judging it. A board refusal surfaces unchanged, exactly as it does for
|
|
8046
|
+
* {@link setStatus}, because those are the board's own words.
|
|
8047
|
+
*/
|
|
8048
|
+
rework(entry, taskId, instructions, initiator) {
|
|
8049
|
+
this.assertActive(entry, "rework a task");
|
|
8050
|
+
if (this.reworkApply === void 0) throw new TaskBoardExtensionError("unavailable", "this deployment serves no rework applier");
|
|
8051
|
+
const task = this.requireTask(taskId);
|
|
8052
|
+
const text = extensionText(instructions, "rework instructions");
|
|
8053
|
+
if (task.archivedAt !== void 0) throw new TaskBoardExtensionError("task-archived", `task ${taskId} is archived; an archived card is read-only`);
|
|
8054
|
+
if (task.executions.some((record) => record.endedAt === void 0)) throw new TaskBoardExtensionError("running", `task ${taskId} is still running; a card is reworked once its run settles`);
|
|
8055
|
+
if (task.executions.length === 0) throw new TaskBoardExtensionError("not-executed", `task ${taskId} has never executed, so there is no run to rework`);
|
|
8056
|
+
if (!task.executions.some((record) => record.sessionId !== void 0)) throw new TaskBoardExtensionError("session-unreachable", `task ${taskId} records no execution session to continue`);
|
|
8057
|
+
this.reworkApply(taskId, text, initiator);
|
|
8058
|
+
}
|
|
8059
|
+
/** One task by id, or the refusal that names the unknown id. */
|
|
8060
|
+
requireTask(taskId) {
|
|
8061
|
+
const task = this.ledger.getTask(taskId);
|
|
8062
|
+
if (task === void 0) throw new TaskBoardExtensionError("task-not-found", `no task with id ${taskId}`);
|
|
8063
|
+
return task;
|
|
8064
|
+
}
|
|
7132
8065
|
linkedTasks(entry) {
|
|
7133
8066
|
const id = entry.extension.id;
|
|
7134
8067
|
const result = [];
|
|
@@ -7145,8 +8078,7 @@ var TaskBoardExtensionRegistry = class {
|
|
|
7145
8078
|
writeIntegration(entry, taskId, payload) {
|
|
7146
8079
|
this.assertActive(entry, "write integration data");
|
|
7147
8080
|
if (!isTaskBoardExtensionPayload(payload)) throw new TaskBoardExtensionError("invalid-payload", "integration payload must be a pure JSON object within the size limit");
|
|
7148
|
-
const task = this.
|
|
7149
|
-
if (task === void 0) throw new TaskBoardExtensionError("task-not-found", `no task with id ${taskId}`);
|
|
8081
|
+
const task = this.requireTask(taskId);
|
|
7150
8082
|
const id = entry.extension.id;
|
|
7151
8083
|
const next = mergePayload(readPayload(task.integrations?.[id]), payload);
|
|
7152
8084
|
if (!isTaskBoardExtensionPayload(next)) throw new TaskBoardExtensionError("invalid-payload", `merged integration payload for ${id} exceeds ${taskBoardPayloadBytes(next) ?? "?"} bytes`);
|
|
@@ -7213,6 +8145,13 @@ const UNREADABLE_SETTLE_POLLS = 24;
|
|
|
7213
8145
|
*/
|
|
7214
8146
|
const ABANDONED_LAUNCH_REASON = "host stopped before this execution started";
|
|
7215
8147
|
/**
|
|
8148
|
+
* Why a rework could not launch: it redoes work in the card's own
|
|
8149
|
+
* conversation, so a session the Host cannot continue means there is nothing to
|
|
8150
|
+
* send the reviewer's instructions into. Starting a fresh conversation instead
|
|
8151
|
+
* would hand those instructions to an agent that never saw the work.
|
|
8152
|
+
*/
|
|
8153
|
+
const REWORK_SESSION_REASON = "rework: the card's previous execution session is not present and idle in the host session roster, so there is no conversation to send the rework instructions into";
|
|
8154
|
+
/**
|
|
7216
8155
|
* Why an enforced goal execution settled failed while its acceptance DID run:
|
|
7217
8156
|
* attempts were recorded and none of them passed. The judge answered about the
|
|
7218
8157
|
* work and the work did not pass.
|
|
@@ -7315,16 +8254,29 @@ const ACTION_KINDS = {
|
|
|
7315
8254
|
"set-schedule": true,
|
|
7316
8255
|
run: true,
|
|
7317
8256
|
rerun: true,
|
|
8257
|
+
rework: true,
|
|
7318
8258
|
"confirm-permission": true,
|
|
7319
8259
|
"set-parent": true,
|
|
7320
8260
|
"rename-tag": true,
|
|
7321
8261
|
"delete-tag": true,
|
|
7322
8262
|
"extension-action": true
|
|
7323
8263
|
};
|
|
8264
|
+
/**
|
|
8265
|
+
* The attachments an action carries, or undefined when it carries none.
|
|
8266
|
+
*
|
|
8267
|
+
* Only a create and an update can carry attachments: an import refuses them
|
|
8268
|
+
* outright, and every other action kind has no attachment surface at all.
|
|
8269
|
+
*/
|
|
8270
|
+
function attachmentsOfAction(action) {
|
|
8271
|
+
if (action.kind === "create") return action.input.attachments;
|
|
8272
|
+
if (action.kind === "update") return action.patch.attachments ?? void 0;
|
|
8273
|
+
}
|
|
7324
8274
|
var TaskBoardHostService = class {
|
|
7325
8275
|
ledger;
|
|
7326
8276
|
runner;
|
|
7327
8277
|
power;
|
|
8278
|
+
/** The official attachment storage, read live so a late mount is honoured. */
|
|
8279
|
+
attachmentStore;
|
|
7328
8280
|
listeners = /* @__PURE__ */ new Set();
|
|
7329
8281
|
/** The one recurring timer: the session-roster poll. */
|
|
7330
8282
|
pollTimer;
|
|
@@ -7392,7 +8344,11 @@ var TaskBoardHostService = class {
|
|
|
7392
8344
|
spendBudgetTokens: options.spendBudgetTokens,
|
|
7393
8345
|
spendUsedToday: options.spendUsedToday
|
|
7394
8346
|
});
|
|
7395
|
-
this.
|
|
8347
|
+
this.attachmentStore = options.attachments ?? (() => void 0);
|
|
8348
|
+
this.runner = new HostExecutionRunner(gateway, options.commandDispatcher, options.workspaceRegistry, void 0, options.ownerPeer, {
|
|
8349
|
+
attachments: this.attachmentStore,
|
|
8350
|
+
llm: options.modelInfo
|
|
8351
|
+
});
|
|
7396
8352
|
this.workspaceRegistry = options.workspaceRegistry;
|
|
7397
8353
|
this.timers = options.timers ?? PROCESS_TIMERS;
|
|
7398
8354
|
this.power = options.power ?? new PowerInhibitor();
|
|
@@ -7412,6 +8368,14 @@ var TaskBoardHostService = class {
|
|
|
7412
8368
|
this.extensions = new TaskBoardExtensionRegistry({
|
|
7413
8369
|
ledger: this.ledger,
|
|
7414
8370
|
apply: (action, initiator) => this.applyBoardAction(crypto.randomUUID(), action, initiator),
|
|
8371
|
+
followUp: (sessionId, text) => this.runner.followUp(sessionId, text),
|
|
8372
|
+
rework: (taskId, instructions, initiator) => {
|
|
8373
|
+
this.applyBoardAction(crypto.randomUUID(), {
|
|
8374
|
+
kind: "rework",
|
|
8375
|
+
taskId,
|
|
8376
|
+
instructions
|
|
8377
|
+
}, initiator);
|
|
8378
|
+
},
|
|
7415
8379
|
now: this.now
|
|
7416
8380
|
});
|
|
7417
8381
|
installStreamErrorGuards();
|
|
@@ -7476,12 +8440,21 @@ var TaskBoardHostService = class {
|
|
|
7476
8440
|
} else if (!active) this.clearScheduleTimer();
|
|
7477
8441
|
this.emit();
|
|
7478
8442
|
}
|
|
8443
|
+
/**
|
|
8444
|
+
* The board's published snapshot.
|
|
8445
|
+
*
|
|
8446
|
+
* Every read path serializes this object — the HTTP `state` answer, the
|
|
8447
|
+
* `action` answer through {@link apply}, and the remote bridge's
|
|
8448
|
+
* `board.snapshot` — so a provider's integration credentials are stripped
|
|
8449
|
+
* once, here, instead of at each exit. The ledger keeps them verbatim for the
|
|
8450
|
+
* provider's own in-process read.
|
|
8451
|
+
*/
|
|
7479
8452
|
snapshot() {
|
|
7480
8453
|
const state = this.ledger.state();
|
|
7481
8454
|
const published = this.extensions.published();
|
|
7482
8455
|
const cardDefaults = cardDefaultsOf(this.cardDefaults());
|
|
7483
|
-
return {
|
|
7484
|
-
schemaVersion:
|
|
8456
|
+
return projectSnapshotForWire({
|
|
8457
|
+
schemaVersion: 7,
|
|
7485
8458
|
revision: state.revision,
|
|
7486
8459
|
tasks: state.tasks,
|
|
7487
8460
|
scheduler: state.scheduler,
|
|
@@ -7490,8 +8463,9 @@ var TaskBoardHostService = class {
|
|
|
7490
8463
|
maxSubtaskDepth: this.ledger.maxSubtaskDepth,
|
|
7491
8464
|
goalRunEnabled: this.goalRunEnabled(),
|
|
7492
8465
|
...cardDefaults === void 0 ? {} : { cardDefaults },
|
|
8466
|
+
...this.attachmentStore() === void 0 ? {} : { attachmentLimits: publishedAttachmentLimits(this.attachmentStore()) },
|
|
7493
8467
|
...Object.keys(published).length === 0 ? {} : { extensions: published }
|
|
7494
|
-
};
|
|
8468
|
+
});
|
|
7495
8469
|
}
|
|
7496
8470
|
/**
|
|
7497
8471
|
* Admit one external provider. Idempotent by extension id; the returned
|
|
@@ -7565,28 +8539,59 @@ var TaskBoardHostService = class {
|
|
|
7565
8539
|
}
|
|
7566
8540
|
};
|
|
7567
8541
|
}
|
|
8542
|
+
/**
|
|
8543
|
+
* Apply an action whose attachments the Host proved against the official
|
|
8544
|
+
* storage first.
|
|
8545
|
+
*
|
|
8546
|
+
* This is the board's trust boundary for attachment metadata: the browser
|
|
8547
|
+
* asserts the size, the type and the digest of every object it uploaded, and
|
|
8548
|
+
* the Host reads the stored objects back (an image is compared, a file is
|
|
8549
|
+
* streamed and its digest recomputed) before the ledger commits the claim.
|
|
8550
|
+
* An attachment the storage cannot prove is refused, so a spoofed client
|
|
8551
|
+
* claim never becomes a stored fact.
|
|
8552
|
+
*/
|
|
8553
|
+
async applyVerified(requestId, action, initiator) {
|
|
8554
|
+
if (!this.active) throw new Error("task board is disabled");
|
|
8555
|
+
if (action.kind === "extension-action") return await this.apply(requestId, action, initiator);
|
|
8556
|
+
await this.verifyActionAttachments(action);
|
|
8557
|
+
return projectSnapshotForWire(this.applyBoardAction(requestId, action, initiator, true));
|
|
8558
|
+
}
|
|
8559
|
+
/**
|
|
8560
|
+
* Prove every attachment of an action against the official storage.
|
|
8561
|
+
*
|
|
8562
|
+
* An action without attachments is untouched: the board keeps working in a
|
|
8563
|
+
* deployment that serves no attachment storage at all.
|
|
8564
|
+
*/
|
|
8565
|
+
async verifyActionAttachments(action) {
|
|
8566
|
+
const attachments = attachmentsOfAction(action);
|
|
8567
|
+
if (attachments === void 0 || attachments.length === 0) return;
|
|
8568
|
+
const store = this.attachmentStore();
|
|
8569
|
+
if (store === void 0) throw new Error("this deployment serves no attachment storage");
|
|
8570
|
+
await verifyAttachments(store, attachments);
|
|
8571
|
+
}
|
|
7568
8572
|
apply(requestId, action, initiator) {
|
|
7569
8573
|
if (!this.active) throw new Error("task board is disabled");
|
|
7570
8574
|
const kind = action?.kind;
|
|
7571
8575
|
if (typeof kind !== "string" || !Object.hasOwn(ACTION_KINDS, kind)) throw new Error(`unknown task board action kind: ${String(kind)}`);
|
|
7572
8576
|
if (action.kind === "extension-action") return this.handleExtensionAction(action);
|
|
7573
|
-
return this.applyBoardAction(requestId, action, initiator);
|
|
8577
|
+
return projectSnapshotForWire(this.applyBoardAction(requestId, action, initiator));
|
|
7574
8578
|
}
|
|
7575
8579
|
/**
|
|
7576
8580
|
* Apply one board-owned action with every gate intact. Provider capability
|
|
7577
8581
|
* calls and the same-origin wire both land here, so the two surfaces can
|
|
7578
8582
|
* never disagree about a card.
|
|
7579
8583
|
*/
|
|
7580
|
-
applyBoardAction(requestId, action, initiator) {
|
|
8584
|
+
applyBoardAction(requestId, action, initiator, attachmentVerified = false) {
|
|
8585
|
+
if (!attachmentVerified && attachmentsOfAction(action) !== void 0) throw new Error("attachments must be applied through the verified attachment action route");
|
|
7581
8586
|
const before = this.statusMap();
|
|
7582
|
-
if (action.kind === "run" || action.kind === "rerun") this.assertSpendCap();
|
|
8587
|
+
if (action.kind === "run" || action.kind === "rerun" || action.kind === "rework") this.assertSpendCap();
|
|
7583
8588
|
const result = this.ledger.applyRequest(requestId, this.withInheritedWorkspace(action, initiator), initiator);
|
|
7584
8589
|
if (result.runs !== void 0) this.dispatchRuns(result.runs);
|
|
7585
8590
|
if (SCHEDULE_WRITE_ACTIONS.has(action.kind)) this.refreshSchedule();
|
|
7586
8591
|
this.emitStatusChanges(before, initiator);
|
|
7587
8592
|
if (action.kind === "delete") this.extensions.emitTaskDeleted({ taskId: action.taskId });
|
|
7588
8593
|
return {
|
|
7589
|
-
schemaVersion:
|
|
8594
|
+
schemaVersion: 7,
|
|
7590
8595
|
revision: result.state.revision,
|
|
7591
8596
|
tasks: result.state.tasks,
|
|
7592
8597
|
scheduler: result.state.scheduler,
|
|
@@ -7657,15 +8662,23 @@ var TaskBoardHostService = class {
|
|
|
7657
8662
|
try {
|
|
7658
8663
|
const forcedPreset = this.ledger.hasOutstandingDescendants(opened.task.id) ? LIANGSHEN_PRESET_ID : void 0;
|
|
7659
8664
|
const descendants = forcedPreset === void 0 ? [] : this.ledger.outstandingDescendants(opened.task.id);
|
|
7660
|
-
const
|
|
7661
|
-
|
|
8665
|
+
const rework = opened.execution.rework;
|
|
8666
|
+
let reuseSessionId;
|
|
8667
|
+
if (rework === void 0) reuseSessionId = forcedPreset === void 0 ? await this.reuseSessionFor(opened.task) : void 0;
|
|
8668
|
+
else {
|
|
8669
|
+
if (forcedPreset !== void 0) throw new Error(REWORK_SESSION_REASON);
|
|
8670
|
+
reuseSessionId = await this.reworkSessionFor(opened.task);
|
|
8671
|
+
}
|
|
8672
|
+
const contextParts = {
|
|
7662
8673
|
...descendants.length === 0 ? {} : { descendants: descendants.map((descendant) => ({
|
|
7663
8674
|
id: descendant.id,
|
|
7664
8675
|
title: descendant.title,
|
|
7665
8676
|
status: descendant.status
|
|
7666
8677
|
})) },
|
|
7667
|
-
...schedule === void 0 ? {} : { schedule }
|
|
8678
|
+
...schedule === void 0 ? {} : { schedule },
|
|
8679
|
+
...rework === void 0 ? {} : { rework }
|
|
7668
8680
|
};
|
|
8681
|
+
const promptContext = Object.keys(contextParts).length === 0 ? void 0 : contextParts;
|
|
7669
8682
|
const { settings, globalGoalEnabled, catalog } = await (freezeContract ?? (() => this.freezeRunContract()))();
|
|
7670
8683
|
const goalEnabled = globalGoalEnabled && opened.task.goalRun === true;
|
|
7671
8684
|
const skippedBy = opened.task.skipVerification === true ? "skipped" : "disabled";
|
|
@@ -7790,10 +8803,13 @@ var TaskBoardHostService = class {
|
|
|
7790
8803
|
* reads no roster at all, and a read that fails mints a fresh conversation
|
|
7791
8804
|
* exactly as an unknown roster always did.
|
|
7792
8805
|
* @param task - the task about to run.
|
|
8806
|
+
* @param force - continue the settled session regardless of the card's own
|
|
8807
|
+
* opt-in (a rework), which the reuse rule accepts without waiving any of its
|
|
8808
|
+
* evidence conditions.
|
|
7793
8809
|
* @returns the session id to continue in, or undefined for a fresh session.
|
|
7794
8810
|
*/
|
|
7795
|
-
async reuseSessionFor(task) {
|
|
7796
|
-
if (task.reuseSession !== true) return void 0;
|
|
8811
|
+
async reuseSessionFor(task, force) {
|
|
8812
|
+
if (task.reuseSession !== true && force !== true) return void 0;
|
|
7797
8813
|
let running;
|
|
7798
8814
|
try {
|
|
7799
8815
|
running = await this.runner.listRunning();
|
|
@@ -7803,7 +8819,24 @@ var TaskBoardHostService = class {
|
|
|
7803
8819
|
return;
|
|
7804
8820
|
}
|
|
7805
8821
|
if (!running.known) return void 0;
|
|
7806
|
-
return reusableSessionId(task, new Set(running.items.filter((item) => !item.running).map((item) => item.sessionId)));
|
|
8822
|
+
return reusableSessionId(task, new Set(running.items.filter((item) => !item.running).map((item) => item.sessionId)), force === true ? { force: true } : {});
|
|
8823
|
+
}
|
|
8824
|
+
/**
|
|
8825
|
+
* The session a rework continues, or the refusal that says why it cannot.
|
|
8826
|
+
*
|
|
8827
|
+
* A rework exists for one conversation — the one the reviewer read before
|
|
8828
|
+
* sending the work back — so the evidence that this Host still reaches it is
|
|
8829
|
+
* required, exactly as it is for a card that opted into reuse. What a rework
|
|
8830
|
+
* does NOT get is the fresh-conversation fallback: launching there would hand
|
|
8831
|
+
* the reviewer's instructions to an agent that never saw the work, so the run
|
|
8832
|
+
* fails with a readable reason instead.
|
|
8833
|
+
* @param task - the card being reworked.
|
|
8834
|
+
* @returns the session id this rework continues in.
|
|
8835
|
+
*/
|
|
8836
|
+
async reworkSessionFor(task) {
|
|
8837
|
+
const sessionId = await this.reuseSessionFor(task, true);
|
|
8838
|
+
if (sessionId === void 0) throw new Error(REWORK_SESSION_REASON);
|
|
8839
|
+
return sessionId;
|
|
7807
8840
|
}
|
|
7808
8841
|
/** Reuse the session list this poll already fetched: one list RPC per tick, not 1 + E. */
|
|
7809
8842
|
async reconcileExecutions(sessions, executions) {
|
|
@@ -9508,6 +10541,11 @@ function isForwardedLoopbackRequest(request) {
|
|
|
9508
10541
|
//#region src/host-routes.ts
|
|
9509
10542
|
const ACTION_LIMIT = 64 * 1024;
|
|
9510
10543
|
const IMPORT_LIMIT = 2 * 1024 * 1024;
|
|
10544
|
+
/**
|
|
10545
|
+
* Comment-frame cadence on the event stream. It keeps the connection alive
|
|
10546
|
+
* through intermediaries that would close an idle one; it is not a frame the
|
|
10547
|
+
* browser reports to the panel (an SSE comment is invisible to EventSource).
|
|
10548
|
+
*/
|
|
9511
10549
|
const HEARTBEAT_MS = 15e3;
|
|
9512
10550
|
/** Header replaced by an authenticated same-host reverse proxy. */
|
|
9513
10551
|
const TASK_BOARD_PROXY_TOKEN_HEADER = "x-dsh-task-board-proxy-token";
|
|
@@ -9656,6 +10694,17 @@ async function readBody(req) {
|
|
|
9656
10694
|
value: JSON.parse(raw)
|
|
9657
10695
|
};
|
|
9658
10696
|
}
|
|
10697
|
+
/**
|
|
10698
|
+
* The query parameters of one request, read against a fixed base so a
|
|
10699
|
+
* relative request target still parses.
|
|
10700
|
+
*/
|
|
10701
|
+
function requestQuery(req) {
|
|
10702
|
+
try {
|
|
10703
|
+
return new URL(req.url ?? "/", "http://localhost").searchParams;
|
|
10704
|
+
} catch {
|
|
10705
|
+
return new URLSearchParams();
|
|
10706
|
+
}
|
|
10707
|
+
}
|
|
9659
10708
|
function makeTaskBoardRoutes(service, access = {}, options = {}) {
|
|
9660
10709
|
const resolvedAccess = resolveAccess(access);
|
|
9661
10710
|
const guard = (req, res) => {
|
|
@@ -9703,9 +10752,17 @@ function makeTaskBoardRoutes(service, access = {}, options = {}) {
|
|
|
9703
10752
|
ok: false,
|
|
9704
10753
|
error: "body-too-large"
|
|
9705
10754
|
}, { "cache-control": "no-store" });
|
|
9706
|
-
writeJson(res, 200, await service.
|
|
10755
|
+
writeJson(res, 200, await service.applyVerified(parsed.requestId, parsed.action, parsed.initiator), { "cache-control": "no-store" });
|
|
9707
10756
|
} catch (error) {
|
|
9708
10757
|
const message = error instanceof Error ? error.message : String(error);
|
|
10758
|
+
if (error instanceof TaskBoardAttachmentError) {
|
|
10759
|
+
writeJson(res, attachmentErrorStatus(error.code), {
|
|
10760
|
+
ok: false,
|
|
10761
|
+
code: error.code,
|
|
10762
|
+
error: message
|
|
10763
|
+
}, { "cache-control": "no-store" });
|
|
10764
|
+
return;
|
|
10765
|
+
}
|
|
9709
10766
|
writeJson(res, message === "body-too-large" ? 413 : 400, {
|
|
9710
10767
|
ok: false,
|
|
9711
10768
|
error: message
|
|
@@ -9728,20 +10785,40 @@ function makeTaskBoardRoutes(service, access = {}, options = {}) {
|
|
|
9728
10785
|
"cache-control": "no-cache",
|
|
9729
10786
|
connection: "keep-alive"
|
|
9730
10787
|
});
|
|
10788
|
+
let heartbeat;
|
|
10789
|
+
let release;
|
|
10790
|
+
const stop = () => {
|
|
10791
|
+
if (heartbeat !== void 0) {
|
|
10792
|
+
clearInterval(heartbeat);
|
|
10793
|
+
heartbeat = void 0;
|
|
10794
|
+
}
|
|
10795
|
+
const unsubscribe = release;
|
|
10796
|
+
release = void 0;
|
|
10797
|
+
unsubscribe?.();
|
|
10798
|
+
};
|
|
10799
|
+
const drop = () => {
|
|
10800
|
+
if (release === void 0) return;
|
|
10801
|
+
stop();
|
|
10802
|
+
res.destroy();
|
|
10803
|
+
};
|
|
10804
|
+
const write = (chunk) => {
|
|
10805
|
+
if (release === void 0 || res.writableEnded || res.destroyed) return;
|
|
10806
|
+
res.write(chunk, (error) => {
|
|
10807
|
+
if (error !== null && error !== void 0) drop();
|
|
10808
|
+
});
|
|
10809
|
+
};
|
|
9731
10810
|
const push = () => {
|
|
9732
|
-
|
|
9733
|
-
res.write(`data: ${JSON.stringify(payload)}\n\n`);
|
|
10811
|
+
write(`data: ${JSON.stringify(service.eventPayload())}\n\n`);
|
|
9734
10812
|
};
|
|
9735
|
-
|
|
9736
|
-
|
|
9737
|
-
|
|
10813
|
+
release = service.subscribe(push);
|
|
10814
|
+
heartbeat = setInterval(() => {
|
|
10815
|
+
write(": ping\n\n");
|
|
9738
10816
|
}, HEARTBEAT_MS);
|
|
9739
|
-
|
|
9740
|
-
|
|
9741
|
-
|
|
9742
|
-
|
|
9743
|
-
|
|
9744
|
-
res.once("close", close);
|
|
10817
|
+
req.once("close", stop);
|
|
10818
|
+
res.once("close", stop);
|
|
10819
|
+
res.on("error", () => {
|
|
10820
|
+
drop();
|
|
10821
|
+
});
|
|
9745
10822
|
push();
|
|
9746
10823
|
}
|
|
9747
10824
|
},
|
|
@@ -9823,6 +10900,98 @@ function makeTaskBoardRoutes(service, access = {}, options = {}) {
|
|
|
9823
10900
|
}, { "cache-control": "no-store" });
|
|
9824
10901
|
}
|
|
9825
10902
|
}
|
|
10903
|
+
},
|
|
10904
|
+
{
|
|
10905
|
+
kind: "exact",
|
|
10906
|
+
path: `${TASK_BOARD_API_PREFIX}/attachments/upload`,
|
|
10907
|
+
handler: async (req, res) => {
|
|
10908
|
+
if (req.method !== "POST") return writeJson(res, 405, {
|
|
10909
|
+
ok: false,
|
|
10910
|
+
error: "method-not-allowed"
|
|
10911
|
+
}, { "cache-control": "no-store" });
|
|
10912
|
+
if (!guard(req, res)) return;
|
|
10913
|
+
const store = options.attachments?.();
|
|
10914
|
+
if (store === void 0) return writeJson(res, 503, {
|
|
10915
|
+
ok: false,
|
|
10916
|
+
code: "storage-unavailable",
|
|
10917
|
+
error: "this deployment serves no attachment storage"
|
|
10918
|
+
}, { "cache-control": "no-store" });
|
|
10919
|
+
const query = requestQuery(req);
|
|
10920
|
+
const kind = query.get("kind");
|
|
10921
|
+
if (kind !== "image" && kind !== "file") return writeJson(res, 400, {
|
|
10922
|
+
ok: false,
|
|
10923
|
+
code: "invalid-request",
|
|
10924
|
+
error: "the attachment kind must be image or file"
|
|
10925
|
+
}, { "cache-control": "no-store" });
|
|
10926
|
+
const name = sanitizeAttachmentName(query.get("name"));
|
|
10927
|
+
const mediaType = query.get("mediaType") ?? "";
|
|
10928
|
+
try {
|
|
10929
|
+
if (kind === "image") {
|
|
10930
|
+
if (mediaType === "") return writeJson(res, 400, {
|
|
10931
|
+
ok: false,
|
|
10932
|
+
code: "invalid-request",
|
|
10933
|
+
error: "an image upload must declare its media type"
|
|
10934
|
+
}, { "cache-control": "no-store" });
|
|
10935
|
+
writeJson(res, 200, {
|
|
10936
|
+
ok: true,
|
|
10937
|
+
attachment: await storeImage(store, await readRequestBytes(req, effectiveImageByteLimit(store)), name, mediaType)
|
|
10938
|
+
}, { "cache-control": "no-store" });
|
|
10939
|
+
return;
|
|
10940
|
+
}
|
|
10941
|
+
writeJson(res, 200, {
|
|
10942
|
+
ok: true,
|
|
10943
|
+
attachment: (await storeFile(store, requestChunks(req), name, mediaType)).attachment
|
|
10944
|
+
}, { "cache-control": "no-store" });
|
|
10945
|
+
} catch (error) {
|
|
10946
|
+
req.resume();
|
|
10947
|
+
const failure = error instanceof TaskBoardAttachmentError ? error : new TaskBoardAttachmentError("storage-unavailable", "the attachment storage is unavailable", { cause: error });
|
|
10948
|
+
writeJson(res, attachmentErrorStatus(failure.code), {
|
|
10949
|
+
ok: false,
|
|
10950
|
+
code: failure.code,
|
|
10951
|
+
error: failure.message
|
|
10952
|
+
}, { "cache-control": "no-store" });
|
|
10953
|
+
}
|
|
10954
|
+
}
|
|
10955
|
+
},
|
|
10956
|
+
{
|
|
10957
|
+
kind: "exact",
|
|
10958
|
+
path: `${TASK_BOARD_API_PREFIX}/attachments/image`,
|
|
10959
|
+
handler: async (req, res) => {
|
|
10960
|
+
if (req.method !== "GET") return writeJson(res, 405, {
|
|
10961
|
+
ok: false,
|
|
10962
|
+
error: "method-not-allowed"
|
|
10963
|
+
}, { "cache-control": "no-store" });
|
|
10964
|
+
if (!guard(req, res)) return;
|
|
10965
|
+
const store = options.attachments?.();
|
|
10966
|
+
if (store === void 0) return writeJson(res, 503, {
|
|
10967
|
+
ok: false,
|
|
10968
|
+
code: "storage-unavailable",
|
|
10969
|
+
error: "this deployment serves no attachment storage"
|
|
10970
|
+
}, { "cache-control": "no-store" });
|
|
10971
|
+
const id = requestQuery(req).get("id") ?? "";
|
|
10972
|
+
const referenced = service.ledger.allTasks().flatMap((task) => task.attachments ?? []).find((attachment) => attachment.kind === "image" && attachment.attachmentId === id);
|
|
10973
|
+
if (referenced === void 0) return writeJson(res, 404, {
|
|
10974
|
+
ok: false,
|
|
10975
|
+
code: "not-found",
|
|
10976
|
+
error: "no card references this attachment"
|
|
10977
|
+
}, { "cache-control": "no-store" });
|
|
10978
|
+
try {
|
|
10979
|
+
const stored = await store.readImage(imageRefOf(referenced));
|
|
10980
|
+
res.writeHead(200, {
|
|
10981
|
+
"content-type": stored.ref.mediaType,
|
|
10982
|
+
"content-length": String(stored.data.byteLength),
|
|
10983
|
+
"cache-control": "no-store"
|
|
10984
|
+
});
|
|
10985
|
+
res.end(Buffer.from(stored.data));
|
|
10986
|
+
} catch (error) {
|
|
10987
|
+
const failure = error instanceof TaskBoardAttachmentError ? error : new TaskBoardAttachmentError("unreadable", "the stored attachment could not be read back", { cause: error });
|
|
10988
|
+
writeJson(res, attachmentErrorStatus(failure.code), {
|
|
10989
|
+
ok: false,
|
|
10990
|
+
code: failure.code,
|
|
10991
|
+
error: failure.message
|
|
10992
|
+
}, { "cache-control": "no-store" });
|
|
10993
|
+
}
|
|
10994
|
+
}
|
|
9826
10995
|
}
|
|
9827
10996
|
];
|
|
9828
10997
|
}
|
|
@@ -11127,6 +12296,47 @@ function resolveLlmRuntime(ctx) {
|
|
|
11127
12296
|
}
|
|
11128
12297
|
}
|
|
11129
12298
|
/**
|
|
12299
|
+
* Resolve the optional attachment storage.
|
|
12300
|
+
*
|
|
12301
|
+
* The board does not inject the service: a deployment without one must still
|
|
12302
|
+
* mount the board, and every attachment surface then answers with a typed
|
|
12303
|
+
* "storage unavailable" failure instead of the plugin failing to load.
|
|
12304
|
+
* @param ctx - the plugin context.
|
|
12305
|
+
* @returns the attachment storage, or undefined when this deployment serves none.
|
|
12306
|
+
*/
|
|
12307
|
+
function resolveAttachmentStore(ctx) {
|
|
12308
|
+
try {
|
|
12309
|
+
const store = ctx.get("attachments");
|
|
12310
|
+
return store !== void 0 && typeof store.saveImage === "function" ? store : void 0;
|
|
12311
|
+
} catch {
|
|
12312
|
+
return;
|
|
12313
|
+
}
|
|
12314
|
+
}
|
|
12315
|
+
/**
|
|
12316
|
+
* The model-info reader the image preflight uses.
|
|
12317
|
+
*
|
|
12318
|
+
* It asks the OFFICIAL model service about one exact route. The model catalog
|
|
12319
|
+
* the board already publishes carries no modality information and must not be
|
|
12320
|
+
* used to answer that question: only the model's own declared input
|
|
12321
|
+
* modalities can refuse an image route, and a route whose modalities cannot be
|
|
12322
|
+
* read is UNKNOWN and therefore allowed.
|
|
12323
|
+
* @param ctx - the plugin context.
|
|
12324
|
+
* @returns the reader, or undefined when the deployment serves no model service.
|
|
12325
|
+
*/
|
|
12326
|
+
function resolveModelInfoReader(ctx) {
|
|
12327
|
+
return async (provider, model) => {
|
|
12328
|
+
const llm = resolveLlmRuntime(ctx);
|
|
12329
|
+
if (llm === void 0) return void 0;
|
|
12330
|
+
try {
|
|
12331
|
+
const info = await llm.resolveModelInfo(provider, model);
|
|
12332
|
+
return { ...info.inputModalities === void 0 ? {} : { inputModalities: info.inputModalities } };
|
|
12333
|
+
} catch (error) {
|
|
12334
|
+
console.warn("[dsh-task-board] could not resolve the model info of " + provider + "/" + model + "; the image preflight allows the route", error);
|
|
12335
|
+
return;
|
|
12336
|
+
}
|
|
12337
|
+
};
|
|
12338
|
+
}
|
|
12339
|
+
/**
|
|
11130
12340
|
* Resolve the optional `sessionController` service. Like the tool registry and
|
|
11131
12341
|
* the llm runtime, it is read dynamically so capture-only test contexts that do
|
|
11132
12342
|
* not mount the full session controller still activate the board.
|
|
@@ -11266,6 +12476,8 @@ function applyImpl(ctx, config) {
|
|
|
11266
12476
|
cardDefaults,
|
|
11267
12477
|
verificationSettings,
|
|
11268
12478
|
verificationCatalog,
|
|
12479
|
+
attachments: () => resolveAttachmentStore(ctx),
|
|
12480
|
+
modelInfo: () => resolveModelInfoReader(ctx),
|
|
11269
12481
|
timers: resolveHostTimers(ctx),
|
|
11270
12482
|
commandDispatcher: { async execute(sessionId, line, signal) {
|
|
11271
12483
|
const agent = await resolveExecutionAgent(ctx, sessionId);
|
|
@@ -11349,11 +12561,14 @@ function applyImpl(ctx, config) {
|
|
|
11349
12561
|
const routes = makeTaskBoardRoutes(host, {
|
|
11350
12562
|
...resolveProxyAccess(config),
|
|
11351
12563
|
connection: () => resolveConnectionTrust(ctx)
|
|
11352
|
-
}, {
|
|
11353
|
-
|
|
11354
|
-
|
|
11355
|
-
|
|
11356
|
-
|
|
12564
|
+
}, {
|
|
12565
|
+
attachments: () => resolveAttachmentStore(ctx),
|
|
12566
|
+
parseTask: async (request, signal) => {
|
|
12567
|
+
const llm = resolveLlmRuntime(ctx);
|
|
12568
|
+
if (llm === void 0) throw new TaskParseError("no-model", "this deployment serves no llm service");
|
|
12569
|
+
return await parseTaskDraft(llm, request, signal);
|
|
12570
|
+
}
|
|
12571
|
+
});
|
|
11357
12572
|
for (const route of routes) disposers.push(ctx.webServer.register(route));
|
|
11358
12573
|
} catch (error) {
|
|
11359
12574
|
setToolsEnabled(false);
|
|
@@ -11399,4 +12614,4 @@ function applyImpl(ctx, config) {
|
|
|
11399
12614
|
sync();
|
|
11400
12615
|
}
|
|
11401
12616
|
//#endregion
|
|
11402
|
-
export { Config, DEFAULT_GOAL_RUN, DEFAULT_GOAL_VERIFICATION, DEFAULT_PROXY_TOKEN_ENV, DEFAULT_TRUST_FORWARDED_PROXY, TASK_BOARD_GUIDANCE, apply, inject, readConfigField, resolveConnectionTrust, resolveExecutionAgent, resolveHostDefaultPermission, resolveHostTimers, resolveLlmRuntime, resolveProxyAccess, resolveSessionController, resolveToolRegistry };
|
|
12617
|
+
export { Config, DEFAULT_GOAL_RUN, DEFAULT_GOAL_VERIFICATION, DEFAULT_PROXY_TOKEN_ENV, DEFAULT_TRUST_FORWARDED_PROXY, TASK_BOARD_GUIDANCE, apply, inject, readConfigField, resolveAttachmentStore, resolveConnectionTrust, resolveExecutionAgent, resolveHostDefaultPermission, resolveHostTimers, resolveLlmRuntime, resolveModelInfoReader, resolveProxyAccess, resolveSessionController, resolveToolRegistry };
|