openwork-server 0.18.63 → 0.18.64
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.md +2 -2
- package/dist/opencode-plugin-deps-1.18.33.tgz +0 -0
- package/dist/opencode-plugins/approval-loopback-fetch.js +18 -0
- package/dist/opencode-plugins/drive-file-tools.js +2 -2
- package/dist/opencode-plugins/managed-policy-next.js +11 -5
- package/dist/opencode-plugins/openwork-agent-permissions-v2.js +140 -11
- package/dist/opencode-plugins/openwork-auto-route-v2.js +19657 -0
- package/dist/opencode-plugins/openwork-capabilities-knowledge.js +5 -3
- package/dist/opencode-plugins/openwork-chrome-devtools.js +17498 -5
- package/dist/opencode-plugins/openwork-cloud-skills-v2.js +54 -31
- package/dist/opencode-plugins/openwork-computer-use.js +17509 -18
- package/dist/opencode-plugins/openwork-context-v2.js +17624 -54
- package/dist/opencode-plugins/openwork-extensions-preview.js +928 -175
- package/dist/opencode-plugins/openwork-gateway-quota-v2.js +15 -0
- package/dist/opencode-plugins/openwork-gateway-quota.js +15 -0
- package/dist/opencode-plugins/openwork-provider-adapters.js +65 -6
- package/dist/opencode-plugins/openwork-provider-sync-v2.js +459 -139
- package/dist/opencode-plugins/openwork-session-groups.js +5 -4
- package/dist/opencode-plugins/openwork-ui-bridge.js +6 -3
- package/dist/opencode-plugins/session-read-detail.js +475 -0
- package/dist/openwork-server.mjs +8932 -5281
- package/package.json +1 -1
- package/web/assets/{abnfDiagram-VCTEODGH-BSIb81ug.js → abnfDiagram-VCTEODGH-j_pTDiqz.js} +1 -1
- package/web/assets/{app-DZr96oX3.js → app-Bzky4OVl.js} +443 -443
- package/web/assets/app-C32roy8y.css +32 -0
- package/web/assets/{arc-BTCnV0Ha.js → arc-CaQNh7ZT.js} +1 -1
- package/web/assets/{architectureDiagram-5GKGNRK7-3IgeX1_6.js → architectureDiagram-5GKGNRK7-wMx5wEbF.js} +1 -1
- package/web/assets/{artifact-code-view-ZP8nVuQx.js → artifact-code-view-DCMMpJxD.js} +1 -1
- package/web/assets/{artifact-spreadsheet-editor-BW94PK45.js → artifact-spreadsheet-editor-DNHOxqPc.js} +1 -1
- package/web/assets/{artifact-text-editor-BhIcTcNi.js → artifact-text-editor-o6WCLEmo.js} +1 -1
- package/web/assets/{blockDiagram-OSKFZWR5-d1pNUfi4.js → blockDiagram-OSKFZWR5-BYAM-sb8.js} +1 -1
- package/web/assets/{c4Diagram-7LVT6UL2-BTVoP_gs.js → c4Diagram-7LVT6UL2-pOXGVuIa.js} +1 -1
- package/web/assets/channel-DR4AKESO.js +1 -0
- package/web/assets/{chunk-2Q5K7J3B-BIy8BDgC.js → chunk-2Q5K7J3B-A7RWrtFk.js} +1 -1
- package/web/assets/{chunk-5VM5RSS4-BDvSSuPz.js → chunk-5VM5RSS4-BbhM53lO.js} +1 -1
- package/web/assets/{chunk-F27PBJKO-CqT02j1I.js → chunk-F27PBJKO-Aoti2mfN.js} +1 -1
- package/web/assets/{chunk-HLEWEB6X-DOSYJ6qO.js → chunk-HLEWEB6X-h1a1fijx.js} +1 -1
- package/web/assets/{chunk-JWPE2WC7-BLJ5TLJ6.js → chunk-JWPE2WC7-CtyBiDJt.js} +1 -1
- package/web/assets/{chunk-POPQ4Y6H-TRvB63--.js → chunk-POPQ4Y6H-d6pjL5RD.js} +1 -1
- package/web/assets/{chunk-SVP7TREG-Bz6HrnA2.js → chunk-SVP7TREG-DnzaR7AG.js} +1 -1
- package/web/assets/{chunk-XXDRQBXY-wBuvw6SP.js → chunk-XXDRQBXY-B9hkBiar.js} +1 -1
- package/web/assets/{chunk-ZLD2IHE6-CsK6m1Sk.js → chunk-ZLD2IHE6-DzJ1_fxy.js} +1 -1
- package/web/assets/classDiagram-CYGNFDIV-B0y8HxEN.js +1 -0
- package/web/assets/classDiagram-v2-TLXNO2FR-B0y8HxEN.js +1 -0
- package/web/assets/{cose-bilkent-JH36ORCC-CISbKtKO.js → cose-bilkent-JH36ORCC-BhvTRFRe.js} +1 -1
- package/web/assets/{cynefin-OW5HDTMX-Dk7vIkhw.js → cynefin-OW5HDTMX-fGckFsSU.js} +1 -1
- package/web/assets/{cynefinDiagram-5FMLGOSQ-C3bIjcy0.js → cynefinDiagram-5FMLGOSQ-BzW--hKZ.js} +1 -1
- package/web/assets/{dagre-OS7QT2EB-BsP75gf5.js → dagre-OS7QT2EB-BnhLgL07.js} +1 -1
- package/web/assets/{diagram-S7CK7UJ4-B4K-iSz7.js → diagram-S7CK7UJ4-Cu-md7dS.js} +1 -1
- package/web/assets/{diagram-UQ7AKVKN-bly7AwhV.js → diagram-UQ7AKVKN-DXQdcUqJ.js} +1 -1
- package/web/assets/{diagram-VSXAHHWV-DObKajM9.js → diagram-VSXAHHWV-C0TNG60H.js} +1 -1
- package/web/assets/{diagram-VX7I27RA-SQp5kc6I.js → diagram-VX7I27RA-z9AkHrlD.js} +1 -1
- package/web/assets/{diagram-Z3DM3KII-BmaqS6Rw.js → diagram-Z3DM3KII-CB0wN1mx.js} +1 -1
- package/web/assets/{ebnfDiagram-PWID7BFC-BOhK-9Al.js → ebnfDiagram-PWID7BFC-k6ofa2S7.js} +1 -1
- package/web/assets/{erDiagram-2YWLMYGG-DP0d4SRU.js → erDiagram-2YWLMYGG-DH0LRcXA.js} +1 -1
- package/web/assets/{flowDiagram-T62WH6J4-CJLvattq.js → flowDiagram-T62WH6J4-BRVNnCPG.js} +1 -1
- package/web/assets/{ganttDiagram-EL5Y4UJY-Dzi8suyh.js → ganttDiagram-EL5Y4UJY-BnEWMV5l.js} +1 -1
- package/web/assets/{gitGraphDiagram-WWUBYQGX-D-xOZUu9.js → gitGraphDiagram-WWUBYQGX-COrkPeQK.js} +1 -1
- package/web/assets/{infoDiagram-FKFFQAWI-CTR7Ei2k.js → infoDiagram-FKFFQAWI-DZuH1fmc.js} +1 -1
- package/web/assets/{ishikawaDiagram-5VMMS53U-CBf51Qea.js → ishikawaDiagram-5VMMS53U-CaJUJ6Ff.js} +1 -1
- package/web/assets/{journeyDiagram-EYS64GPL-ZumMGF2u.js → journeyDiagram-EYS64GPL-BE6Fv_rV.js} +1 -1
- package/web/assets/{kanban-definition-UXKFOSKX-81Fni8Sl.js → kanban-definition-UXKFOSKX-B4bPGzK6.js} +1 -1
- package/web/assets/{layout-D-HFg0Gy.js → layout-or_42uvc.js} +1 -1
- package/web/assets/{linear-lAHomfjd.js → linear-5PXMsdhe.js} +1 -1
- package/web/assets/{mermaid.core-sRbhnZ3C.js → mermaid.core-DW6D3RPJ.js} +6 -6
- package/web/assets/{mindmap-definition-THT77NOG-t_uxFNYx.js → mindmap-definition-THT77NOG-CyTLW_BU.js} +1 -1
- package/web/assets/{pegDiagram-XKGWAZYB-B4FryuiE.js → pegDiagram-XKGWAZYB-7JUI9VKo.js} +1 -1
- package/web/assets/{pieDiagram-E7YTZNPT-DrIgLewj.js → pieDiagram-E7YTZNPT-Bp-lNUXy.js} +1 -1
- package/web/assets/{quadrantDiagram-AXDQQJYC-DifmQS8L.js → quadrantDiagram-AXDQQJYC-BHzbyOLv.js} +1 -1
- package/web/assets/{railroadDiagram-O6MQD6OU-C76a1ZKv.js → railroadDiagram-O6MQD6OU-DUbwyc8J.js} +1 -1
- package/web/assets/{requirementDiagram-IS5BZ75X-CT_K8F_V.js → requirementDiagram-IS5BZ75X-C6vHvRXL.js} +1 -1
- package/web/assets/{sankeyDiagram-P5KCCOFB-DWQLcVQR.js → sankeyDiagram-P5KCCOFB-rhUrZHvo.js} +1 -1
- package/web/assets/{sequenceDiagram-WJ2MYXX4-aTZD72z2.js → sequenceDiagram-WJ2MYXX4-CbKw45qx.js} +1 -1
- package/web/assets/{sizeCapture-INFHLROL-BzVHqyuK.js → sizeCapture-INFHLROL-BzYRidKe.js} +1 -1
- package/web/assets/{stateDiagram-XQSTLZYL-D9BpFjx0.js → stateDiagram-XQSTLZYL-CY_NqfCu.js} +1 -1
- package/web/assets/stateDiagram-v2-IH3M54BS-ZplxpnyH.js +1 -0
- package/web/assets/{swimlanes-V6O3JKXN-DiN46HW4.js → swimlanes-V6O3JKXN-DsuNS06S.js} +1 -1
- package/web/assets/swimlanesDiagram-JKAHXJPX-BgYXaTmf.js +8 -0
- package/web/assets/{timeline-definition-24CTP7MA-CJZAuVpz.js → timeline-definition-24CTP7MA-Bw7piZjw.js} +1 -1
- package/web/assets/{vennDiagram-4TSXK5OY-d5RgWEF0.js → vennDiagram-4TSXK5OY-3QO9enN9.js} +1 -1
- package/web/assets/{wardleyDiagram-VM6X3IG4-DP1nzuP1.js → wardleyDiagram-VM6X3IG4-u2wsdzR8.js} +1 -1
- package/web/assets/{workspace-file-tree-iodkCqW9.js → workspace-file-tree-B0RW5c5J.js} +1 -1
- package/web/assets/{xychartDiagram-S5SC5T6Z-Bh1aCFiI.js → xychartDiagram-S5SC5T6Z-YVqX-MzU.js} +1 -1
- package/web/index.html +2 -2
- package/web/assets/app-Bx1ym5U0.css +0 -32
- package/web/assets/channel-DqkU7DUB.js +0 -1
- package/web/assets/classDiagram-CYGNFDIV-C-Tb50QW.js +0 -1
- package/web/assets/classDiagram-v2-TLXNO2FR-C-Tb50QW.js +0 -1
- package/web/assets/stateDiagram-v2-IH3M54BS-B7xLeFMx.js +0 -1
- package/web/assets/swimlanesDiagram-JKAHXJPX-C1vbqhAp.js +0 -8
|
@@ -486,7 +486,7 @@ var init_auth = __esm(() => {
|
|
|
486
486
|
function emptyJournal() {
|
|
487
487
|
return { version: 1, commands: [], requests: [] };
|
|
488
488
|
}
|
|
489
|
-
var MAX_COMMAND_ENTRIES = 256, MAX_REQUEST_ENTRIES = 256, REQUEST_RESULT_MAX_BYTES, DEFAULT_OPERATION_TIMEOUT_MS = 15000, SessionRunnerError;
|
|
489
|
+
var TRANSCRIPT_PARTS_MAX = 200, TRANSCRIPT_TOOL_FIELD_MAX = 2000, TRANSCRIPT_TEXT_PART_MAX = 20000, TRANSCRIPT_REASONING_PART_MAX = 4000, MAX_COMMAND_ENTRIES = 256, MAX_REQUEST_ENTRIES = 256, REQUEST_RESULT_MAX_BYTES, DEFAULT_OPERATION_TIMEOUT_MS = 15000, SessionRunnerError;
|
|
490
490
|
var init_types = __esm(() => {
|
|
491
491
|
REQUEST_RESULT_MAX_BYTES = 256 * 1024;
|
|
492
492
|
SessionRunnerError = class SessionRunnerError extends Error {
|
|
@@ -592,6 +592,62 @@ function model(value) {
|
|
|
592
592
|
...v.variant === undefined ? {} : { variant: nullable(v.variant, (value2) => text(value2, 60)) }
|
|
593
593
|
};
|
|
594
594
|
}
|
|
595
|
+
function pendingQuestion(value) {
|
|
596
|
+
const v = object(value);
|
|
597
|
+
keys(v, ["header", "question", "options", "multiple", "custom"]);
|
|
598
|
+
return {
|
|
599
|
+
header: text(v.header, 240, 0),
|
|
600
|
+
question: text(v.question, 2000, 0),
|
|
601
|
+
options: array(v.options, PENDING_OPTIONS_MAX, (value2) => {
|
|
602
|
+
const o = object(value2);
|
|
603
|
+
keys(o, ["label", "description"]);
|
|
604
|
+
return { label: text(o.label, 240), description: text(o.description, 1000, 0) };
|
|
605
|
+
}),
|
|
606
|
+
multiple: boolean(v.multiple),
|
|
607
|
+
custom: boolean(v.custom)
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
function parsePending(value) {
|
|
611
|
+
const v = object(value);
|
|
612
|
+
if (v.kind === "question") {
|
|
613
|
+
keys(v, ["kind", "requestId", "questions"]);
|
|
614
|
+
const questions = array(v.questions, PENDING_QUESTIONS_MAX, pendingQuestion);
|
|
615
|
+
if (questions.length === 0)
|
|
616
|
+
return invalid();
|
|
617
|
+
return { kind: "question", requestId: text(v.requestId, 240), questions };
|
|
618
|
+
}
|
|
619
|
+
if (v.kind !== "permission")
|
|
620
|
+
return invalid();
|
|
621
|
+
keys(v, ["kind", "requestId", "title", "detail", "command"]);
|
|
622
|
+
return {
|
|
623
|
+
kind: "permission",
|
|
624
|
+
requestId: text(v.requestId, 240),
|
|
625
|
+
title: text(v.title, 240),
|
|
626
|
+
detail: text(v.detail, 2000, 0),
|
|
627
|
+
...v.command === undefined ? {} : { command: text(v.command, 2000) }
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
function parseAnswerInput(value) {
|
|
631
|
+
const v = object(value);
|
|
632
|
+
if (v.kind === "question") {
|
|
633
|
+
keys(v, ["kind", "requestId", "answers"]);
|
|
634
|
+
const answers = array(v.answers, PENDING_QUESTIONS_MAX, (value2) => array(value2, PENDING_OPTIONS_MAX, (value3) => text(value3, 2000)));
|
|
635
|
+
if (answers.length === 0)
|
|
636
|
+
return invalid();
|
|
637
|
+
return { kind: "question", requestId: text(v.requestId, 240), answers };
|
|
638
|
+
}
|
|
639
|
+
if (v.kind !== "permission")
|
|
640
|
+
return invalid();
|
|
641
|
+
keys(v, ["kind", "requestId", "decision"]);
|
|
642
|
+
if (v.decision !== "once" && v.decision !== "reject")
|
|
643
|
+
return invalid();
|
|
644
|
+
return { kind: "permission", requestId: text(v.requestId, 240), decision: v.decision };
|
|
645
|
+
}
|
|
646
|
+
function parseAnswerResult(value) {
|
|
647
|
+
const v = object(value);
|
|
648
|
+
keys(v, ["requestId", "alreadyAnswered"]);
|
|
649
|
+
return { requestId: text(v.requestId, 240), alreadyAnswered: boolean(v.alreadyAnswered) };
|
|
650
|
+
}
|
|
595
651
|
function parseCommand(value) {
|
|
596
652
|
const v = object(value);
|
|
597
653
|
keys(v, ["commandId", "kind", "title", "prompt", "model", "expiresAt", "workspaceId"]);
|
|
@@ -617,7 +673,7 @@ function parseReceipt(value) {
|
|
|
617
673
|
}
|
|
618
674
|
function parseProgress(value) {
|
|
619
675
|
const v = object(value);
|
|
620
|
-
keys(v, ["status", "waitingFor", "engine", "model", "finalText", "error", "messageCount", "observedAt"]);
|
|
676
|
+
keys(v, ["status", "waitingFor", "engine", "model", "finalText", "error", "messageCount", "latestStep", "pending", "observedAt"]);
|
|
621
677
|
return {
|
|
622
678
|
status: status(v.status),
|
|
623
679
|
observedAt: integer(v.observedAt),
|
|
@@ -626,7 +682,9 @@ function parseProgress(value) {
|
|
|
626
682
|
...v.model === undefined ? {} : { model: nullable(v.model, model) },
|
|
627
683
|
...v.finalText === undefined ? {} : { finalText: text(v.finalText, 20000, 0) },
|
|
628
684
|
...v.error === undefined ? {} : { error: nullable(v.error, parseError) },
|
|
629
|
-
...v.messageCount === undefined ? {} : { messageCount: integer(v.messageCount) }
|
|
685
|
+
...v.messageCount === undefined ? {} : { messageCount: integer(v.messageCount) },
|
|
686
|
+
...v.latestStep === undefined ? {} : { latestStep: nullable(v.latestStep, (step) => text(step, 240, 1)) },
|
|
687
|
+
...v.pending === undefined ? {} : { pending: nullable(v.pending, parsePending) }
|
|
630
688
|
};
|
|
631
689
|
}
|
|
632
690
|
function parseComplete(value) {
|
|
@@ -679,6 +737,8 @@ function parseRequest(value) {
|
|
|
679
737
|
model: nullable(input.model, model)
|
|
680
738
|
} };
|
|
681
739
|
}
|
|
740
|
+
if (v.action === "answer")
|
|
741
|
+
return { ...base, action: "answer", input: parseAnswerInput(input) };
|
|
682
742
|
if (v.action !== "stop")
|
|
683
743
|
return invalid();
|
|
684
744
|
keys(input, ["messageId"]);
|
|
@@ -697,9 +757,41 @@ function toolCall(value) {
|
|
|
697
757
|
truncated: boolean(v.truncated)
|
|
698
758
|
};
|
|
699
759
|
}
|
|
760
|
+
function transcriptPart(value) {
|
|
761
|
+
const v = object(value);
|
|
762
|
+
if (v.type === "text") {
|
|
763
|
+
keys(v, ["type", "text"]);
|
|
764
|
+
return { type: "text", text: rawText(v.text, TRANSCRIPT_TEXT_PART_MAX, 0) };
|
|
765
|
+
}
|
|
766
|
+
if (v.type === "reasoning") {
|
|
767
|
+
keys(v, ["type", "text", "durationMs"]);
|
|
768
|
+
return {
|
|
769
|
+
type: "reasoning",
|
|
770
|
+
text: rawText(v.text, TRANSCRIPT_REASONING_PART_MAX, 0),
|
|
771
|
+
...v.durationMs === undefined ? {} : { durationMs: integer(v.durationMs) }
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
if (v.type !== "tool")
|
|
775
|
+
return invalid();
|
|
776
|
+
keys(v, ["type", "id", "name", "status", "title", "input", "output", "error", "truncated", "startedAt", "endedAt"]);
|
|
777
|
+
const field = (value2) => nullable(value2, (value3) => rawText(value3, TRANSCRIPT_TOOL_FIELD_MAX, 0));
|
|
778
|
+
return {
|
|
779
|
+
type: "tool",
|
|
780
|
+
id: text(v.id, 240, 0),
|
|
781
|
+
name: text(v.name, 240, 0),
|
|
782
|
+
status: nullable(v.status, (value2) => text(value2, 60, 0)),
|
|
783
|
+
...v.title === undefined ? {} : { title: text(v.title, 240, 0) },
|
|
784
|
+
input: field(v.input),
|
|
785
|
+
output: field(v.output),
|
|
786
|
+
error: field(v.error),
|
|
787
|
+
truncated: boolean(v.truncated),
|
|
788
|
+
...v.startedAt === undefined ? {} : { startedAt: integer(v.startedAt) },
|
|
789
|
+
...v.endedAt === undefined ? {} : { endedAt: integer(v.endedAt) }
|
|
790
|
+
};
|
|
791
|
+
}
|
|
700
792
|
function message(value) {
|
|
701
793
|
const v = object(value);
|
|
702
|
-
keys(v, ["id", "role", "createdAt", "text", "truncated", "toolCalls", "error"]);
|
|
794
|
+
keys(v, ["id", "role", "createdAt", "text", "truncated", "toolCalls", "error", "parts", "completedAt"]);
|
|
703
795
|
if (v.role !== "user" && v.role !== "assistant")
|
|
704
796
|
return invalid();
|
|
705
797
|
return {
|
|
@@ -709,12 +801,14 @@ function message(value) {
|
|
|
709
801
|
text: text(v.text, 20000, 0),
|
|
710
802
|
truncated: boolean(v.truncated),
|
|
711
803
|
toolCalls: array(v.toolCalls, 200, toolCall),
|
|
712
|
-
error: nullable(v.error, parseError)
|
|
804
|
+
error: nullable(v.error, parseError),
|
|
805
|
+
...v.parts === undefined ? {} : { parts: array(v.parts, TRANSCRIPT_PARTS_MAX, transcriptPart) },
|
|
806
|
+
...v.completedAt === undefined ? {} : { completedAt: nullable(v.completedAt, integer) }
|
|
713
807
|
};
|
|
714
808
|
}
|
|
715
809
|
function parseReadResult(value) {
|
|
716
810
|
const v = object(value);
|
|
717
|
-
keys(v, ["title", "status", "waitingFor", "lastError", "messageCount", "from", "messages", "nextCursor", "historyScope"]);
|
|
811
|
+
keys(v, ["title", "status", "waitingFor", "lastError", "messageCount", "from", "messages", "nextCursor", "historyScope", "pending"]);
|
|
718
812
|
if (v.historyScope !== undefined && v.historyScope !== "context" && v.historyScope !== "full")
|
|
719
813
|
return invalid();
|
|
720
814
|
return {
|
|
@@ -726,7 +820,8 @@ function parseReadResult(value) {
|
|
|
726
820
|
from: direction(v.from),
|
|
727
821
|
messages: array(v.messages, 100, message),
|
|
728
822
|
nextCursor: nullable(v.nextCursor, (value2) => text(value2, 160, 0)),
|
|
729
|
-
...v.historyScope === undefined ? {} : { historyScope: v.historyScope }
|
|
823
|
+
...v.historyScope === undefined ? {} : { historyScope: v.historyScope },
|
|
824
|
+
...v.pending === undefined ? {} : { pending: nullable(v.pending, parsePending) }
|
|
730
825
|
};
|
|
731
826
|
}
|
|
732
827
|
function parseSendResult(value) {
|
|
@@ -760,6 +855,8 @@ function parseRequestComplete(value) {
|
|
|
760
855
|
return { status: "done", outcome: { action: "send", result: parseSendResult(outcome.result) } };
|
|
761
856
|
if (outcome.action === "stop")
|
|
762
857
|
return { status: "done", outcome: { action: "stop", result: parseStopResult(outcome.result) } };
|
|
858
|
+
if (outcome.action === "answer")
|
|
859
|
+
return { status: "done", outcome: { action: "answer", result: parseAnswerResult(outcome.result) } };
|
|
763
860
|
return invalid();
|
|
764
861
|
}
|
|
765
862
|
function parseInventory2(value) {
|
|
@@ -900,6 +997,8 @@ function parseJournal(value) {
|
|
|
900
997
|
return invalid();
|
|
901
998
|
if (request.action === "stop" && request.input.messageId !== null && id !== request.input.messageId)
|
|
902
999
|
return invalid();
|
|
1000
|
+
if (request.action === "answer" && id !== null && id !== request.input.requestId)
|
|
1001
|
+
return invalid();
|
|
903
1002
|
return { request, sendReplay, messageId: id, turn, completion, completionAcknowledged: acknowledged };
|
|
904
1003
|
})
|
|
905
1004
|
};
|
|
@@ -920,8 +1019,38 @@ function parseJournal(value) {
|
|
|
920
1019
|
}
|
|
921
1020
|
return journal;
|
|
922
1021
|
}
|
|
1022
|
+
function words(value) {
|
|
1023
|
+
const spaced = value.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_\-.]+/g, " ").trim().toLowerCase();
|
|
1024
|
+
return spaced ? `${spaced[0]?.toUpperCase()}${spaced.slice(1)}` : "Use a tool";
|
|
1025
|
+
}
|
|
1026
|
+
function pendingPermission(input) {
|
|
1027
|
+
const metadata = isObject(input.metadata) ? input.metadata : {};
|
|
1028
|
+
const described = typeof metadata.description === "string" ? metadata.description.trim() : "";
|
|
1029
|
+
const command = typeof metadata.command === "string" && metadata.command.trim() ? metadata.command.trim() : input.action === "bash" && input.resources[0]?.trim() ? input.resources[0].trim() : undefined;
|
|
1030
|
+
const title = (PERMISSION_TITLES[input.action] ?? words(input.action)).slice(0, 240);
|
|
1031
|
+
const detail = (described || input.resources.filter((item) => item !== command).join(", ")).slice(0, 2000);
|
|
1032
|
+
return parsePending({
|
|
1033
|
+
kind: "permission",
|
|
1034
|
+
requestId: input.requestId.slice(0, 240),
|
|
1035
|
+
title,
|
|
1036
|
+
detail,
|
|
1037
|
+
...command ? { command: command.slice(0, 2000) } : {}
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
var PENDING_QUESTIONS_MAX = 10, PENDING_OPTIONS_MAX = 50, PERMISSION_TITLES;
|
|
923
1041
|
var init_protocol = __esm(() => {
|
|
924
1042
|
init_types();
|
|
1043
|
+
PERMISSION_TITLES = {
|
|
1044
|
+
bash: "Run a command",
|
|
1045
|
+
edit: "Edit files",
|
|
1046
|
+
write: "Write files",
|
|
1047
|
+
read: "Read files",
|
|
1048
|
+
webfetch: "Fetch a web page",
|
|
1049
|
+
websearch: "Search the web",
|
|
1050
|
+
external_directory: "Use a folder outside the workspace",
|
|
1051
|
+
task: "Start a helper",
|
|
1052
|
+
doom_loop: "Keep repeating the same step"
|
|
1053
|
+
};
|
|
925
1054
|
});
|
|
926
1055
|
|
|
927
1056
|
// ../../packages/remote-sessions/src/timeout.ts
|
|
@@ -972,6 +1101,12 @@ function definitive(error) {
|
|
|
972
1101
|
return null;
|
|
973
1102
|
return parseError({ code: error.code, message: error.message });
|
|
974
1103
|
}
|
|
1104
|
+
function ambiguousAnswer() {
|
|
1105
|
+
return failure("ambiguous_answer", "The answer may already have reached the session. Check it on that computer before answering again; it will not be sent again automatically.");
|
|
1106
|
+
}
|
|
1107
|
+
function staleRequest(error) {
|
|
1108
|
+
return error instanceof SessionRunnerError && error.code === "stale_request";
|
|
1109
|
+
}
|
|
975
1110
|
function same(a, b) {
|
|
976
1111
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
977
1112
|
}
|
|
@@ -1209,7 +1344,7 @@ function createSessionRunner(options) {
|
|
|
1209
1344
|
completion = { status: "failed", error: ambiguousSend(e.request) };
|
|
1210
1345
|
applyTurn = true;
|
|
1211
1346
|
} else if (e.request.expiresAt <= now()) {
|
|
1212
|
-
completion = { status: "failed", error: failure("expired", "The request expired before its next native effect.") };
|
|
1347
|
+
completion = { status: "failed", error: e.request.action === "answer" && e.messageId !== null ? ambiguousAnswer() : failure("expired", "The request expired before its next native effect.") };
|
|
1213
1348
|
applyTurn = e.turn !== null;
|
|
1214
1349
|
} else if (!c?.receipt)
|
|
1215
1350
|
completion = { status: "failed", error: failure("unknown_receipt", "Only a session delivered by this account's local journal can be controlled.") };
|
|
@@ -1245,6 +1380,27 @@ function createSessionRunner(options) {
|
|
|
1245
1380
|
throw new SessionRunnerError("invalid_data", "The adapter returned a different stable message ID.");
|
|
1246
1381
|
completion = { status: "done", outcome: { action: "send", result } };
|
|
1247
1382
|
applyTurn = true;
|
|
1383
|
+
} else if (e.request.action === "answer") {
|
|
1384
|
+
const input = e.request.input;
|
|
1385
|
+
const answer = adapter.answer;
|
|
1386
|
+
if (!answer) {
|
|
1387
|
+
completion = { status: "failed", error: failure("answer_unsupported", "This computer can't take answers from here. Answer it on that computer.") };
|
|
1388
|
+
} else {
|
|
1389
|
+
const replay = e.messageId !== null;
|
|
1390
|
+
if (!replay) {
|
|
1391
|
+
await saveRequest({ ...e, messageId: input.requestId });
|
|
1392
|
+
e = request(id);
|
|
1393
|
+
}
|
|
1394
|
+
throwIfAborted(signal);
|
|
1395
|
+
try {
|
|
1396
|
+
await local(signal, (s) => answer.call(adapter, structuredClone(c.receipt), structuredClone(input), s));
|
|
1397
|
+
completion = { status: "done", outcome: { action: "answer", result: { requestId: input.requestId, alreadyAnswered: false } } };
|
|
1398
|
+
} catch (error) {
|
|
1399
|
+
if (!replay || !staleRequest(error))
|
|
1400
|
+
throw error;
|
|
1401
|
+
completion = { status: "done", outcome: { action: "answer", result: { requestId: input.requestId, alreadyAnswered: true } } };
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1248
1404
|
} else if (e.request.input.messageId === null && e.messageId !== null && c.lastMessageId !== e.messageId) {
|
|
1249
1405
|
completion = { status: "done", outcome: { action: "stop", result: { stopped: false, reason: "different_turn" } } };
|
|
1250
1406
|
} else if (e.messageId === null) {
|
|
@@ -1383,6 +1539,11 @@ function createSessionRunner(options) {
|
|
|
1383
1539
|
throw new SessionRunnerError("journal_full", "Prune acknowledged requests before accepting more work.");
|
|
1384
1540
|
const c = state().commands.find((c2) => c2.command.commandId === value.commandId && c2.phase === "delivered" && c2.receipt?.sessionId === value.sessionId && c2.receipt.workspaceId === value.workspaceId);
|
|
1385
1541
|
let completion2 = !c ? { status: "failed", error: failure("unknown_receipt", "Only a session delivered by this account's local journal can be controlled.") } : null;
|
|
1542
|
+
if (c && value.action === "answer") {
|
|
1543
|
+
const prior = state().requests.find((r) => r.request.commandId === value.commandId && r.request.action === "answer" && r.request.input.requestId === value.input.requestId && r.completion?.status === "done");
|
|
1544
|
+
if (prior)
|
|
1545
|
+
completion2 = { status: "done", outcome: { action: "answer", result: { requestId: value.input.requestId, alreadyAnswered: true } } };
|
|
1546
|
+
}
|
|
1386
1547
|
const id = value.action === "send" ? value.input.messageId ?? stableMessageId(value.requestId) : value.action === "stop" ? value.input.messageId ?? c?.lastMessageId ?? null : null;
|
|
1387
1548
|
if (c && value.action === "send") {
|
|
1388
1549
|
const prior = state().requests.find((r) => r.request.commandId === value.commandId && r.messageId === id && r.request.action === "send");
|
|
@@ -1623,7 +1784,7 @@ var init_src = __esm(() => {
|
|
|
1623
1784
|
});
|
|
1624
1785
|
|
|
1625
1786
|
// ../../packages/opencode-plugin/src/native-opencode.ts
|
|
1626
|
-
import { createHash as
|
|
1787
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
1627
1788
|
import { realpath } from "node:fs/promises";
|
|
1628
1789
|
import { basename } from "node:path";
|
|
1629
1790
|
function hasNativeSessionHost(ctx) {
|
|
@@ -1636,7 +1797,7 @@ function remoteModel(model2) {
|
|
|
1636
1797
|
return model2 ? { providerId: model2.providerID, modelId: model2.id, variant: model2.variant ?? null } : null;
|
|
1637
1798
|
}
|
|
1638
1799
|
function digest2(value) {
|
|
1639
|
-
return
|
|
1800
|
+
return createHash5("sha256").update(value).digest("hex").slice(0, 24);
|
|
1640
1801
|
}
|
|
1641
1802
|
function clipped(value, max) {
|
|
1642
1803
|
return value.slice(0, max);
|
|
@@ -1678,6 +1839,8 @@ async function nativeWorkspace(ctx, workspaceId, signal) {
|
|
|
1678
1839
|
function createNativeOpenCodeAdapter(input) {
|
|
1679
1840
|
const { ctx, directory, workspaceId } = input;
|
|
1680
1841
|
const now = input.now ?? Date.now;
|
|
1842
|
+
const reply = ctx.permission.reply;
|
|
1843
|
+
const answers = typeof reply === "function";
|
|
1681
1844
|
const markerKey = (sessionId) => `${input.storagePrefix}/native/${digest2(sessionId)}`;
|
|
1682
1845
|
const load = async (receipt) => admission(await ctx.storage.get(markerKey(receipt.sessionId)));
|
|
1683
1846
|
const save = (receipt, value) => ctx.storage.set(markerKey(receipt.sessionId), { ...value });
|
|
@@ -1713,6 +1876,8 @@ function createNativeOpenCodeAdapter(input) {
|
|
|
1713
1876
|
const assistant = assistantIndex > turnBoundary ? messages[assistantIndex] : undefined;
|
|
1714
1877
|
const nativeError = assistant?.type === "assistant" ? errorOf(assistant.error) : null;
|
|
1715
1878
|
const status2 = waitingFor ? "waiting" : running ? "running" : info.outcome === "failed" ? "error" : "idle";
|
|
1879
|
+
const first = permissions[0];
|
|
1880
|
+
const waitingOn = waitingFor === "permission" && first && answers ? pendingPermission({ requestId: first.id, action: first.action ?? "permission", resources: first.resources ?? [], metadata: first.metadata }) : null;
|
|
1716
1881
|
const finalText = !running && !waitingFor && assistant?.type === "assistant" ? clipped(assistant.content.filter((part) => part.type === "text").map((part) => part.text).join(`
|
|
1717
1882
|
`), 20000) : "";
|
|
1718
1883
|
const progress = {
|
|
@@ -1723,6 +1888,7 @@ function createNativeOpenCodeAdapter(input) {
|
|
|
1723
1888
|
finalText,
|
|
1724
1889
|
error: status2 === "error" ? nativeError ?? { code: "native_error", message: "OpenCode's last execution failed." } : null,
|
|
1725
1890
|
messageCount: messages.length,
|
|
1891
|
+
...answers ? { pending: waitingOn } : {},
|
|
1726
1892
|
observedAt: now()
|
|
1727
1893
|
};
|
|
1728
1894
|
return { info, messages, latestUser, progress };
|
|
@@ -1823,11 +1989,28 @@ function createNativeOpenCodeAdapter(input) {
|
|
|
1823
1989
|
messageCount: transcript.length,
|
|
1824
1990
|
from: page.from,
|
|
1825
1991
|
messages: selected,
|
|
1826
|
-
nextCursor: more && anchor ? `oc2:${page.from}:${epoch}:${digest2(anchor.id)}` : null
|
|
1992
|
+
nextCursor: more && anchor ? `oc2:${page.from}:${epoch}:${digest2(anchor.id)}` : null,
|
|
1993
|
+
...progress.pending === undefined ? {} : { pending: progress.pending }
|
|
1827
1994
|
};
|
|
1828
1995
|
}
|
|
1829
1996
|
};
|
|
1830
|
-
|
|
1997
|
+
if (!reply)
|
|
1998
|
+
return adapter;
|
|
1999
|
+
return {
|
|
2000
|
+
...adapter,
|
|
2001
|
+
async answer(receipt, answer, signal) {
|
|
2002
|
+
if (answer.kind !== "permission") {
|
|
2003
|
+
throw new SessionRunnerError("answer_unsupported", "OpenCode can't take answers to its questions from here yet. Answer it on that computer.");
|
|
2004
|
+
}
|
|
2005
|
+
await owned(receipt, signal);
|
|
2006
|
+
const permissions = await ctx.permission.list({ sessionID: receipt.sessionId }, { signal });
|
|
2007
|
+
signal.throwIfAborted();
|
|
2008
|
+
if (!permissions.some((permission) => permission.id === answer.requestId && permission.sessionID === receipt.sessionId)) {
|
|
2009
|
+
throw new SessionRunnerError("stale_request", "That permission is no longer pending. Read the task again.");
|
|
2010
|
+
}
|
|
2011
|
+
await reply.call(ctx.permission, { sessionID: receipt.sessionId, requestID: answer.requestId, decision: answer.decision }, { signal });
|
|
2012
|
+
}
|
|
2013
|
+
};
|
|
1831
2014
|
}
|
|
1832
2015
|
function toolCall2(part) {
|
|
1833
2016
|
const state = part.state;
|
|
@@ -1844,6 +2027,33 @@ function toolCall2(part) {
|
|
|
1844
2027
|
truncated: rawInput.length > 2000 || (rawOutput?.length ?? 0) > 2000 || (rawError?.length ?? 0) > 2000
|
|
1845
2028
|
};
|
|
1846
2029
|
}
|
|
2030
|
+
function transcriptParts(content) {
|
|
2031
|
+
let chars = 20000;
|
|
2032
|
+
const prose = (text2, cap) => {
|
|
2033
|
+
const kept = text2.slice(0, Math.min(cap, chars));
|
|
2034
|
+
chars -= kept.length;
|
|
2035
|
+
return kept;
|
|
2036
|
+
};
|
|
2037
|
+
return content.filter((part) => part.type === "tool" || part.text.trim()).slice(0, 200).map((part) => {
|
|
2038
|
+
if (part.type === "text")
|
|
2039
|
+
return { type: "text", text: prose(part.text, 20000) };
|
|
2040
|
+
if (part.type === "reasoning")
|
|
2041
|
+
return { type: "reasoning", text: prose(part.text, 4000) };
|
|
2042
|
+
const { id, name, status: status2, input, output, error, truncated } = toolCall2(part);
|
|
2043
|
+
const text2 = "content" in part.state && part.state.content ? part.state.content.flatMap((item) => isRecord(item) && item.type === "text" && typeof item.text === "string" ? [item.text] : []).join(`
|
|
2044
|
+
`) : "";
|
|
2045
|
+
return {
|
|
2046
|
+
type: "tool",
|
|
2047
|
+
id,
|
|
2048
|
+
name,
|
|
2049
|
+
status: status2,
|
|
2050
|
+
input,
|
|
2051
|
+
output: text2 ? clipped(text2, 2000) : output,
|
|
2052
|
+
error,
|
|
2053
|
+
truncated: truncated || text2.length > 2000
|
|
2054
|
+
};
|
|
2055
|
+
});
|
|
2056
|
+
}
|
|
1847
2057
|
function transcriptMessage(message2) {
|
|
1848
2058
|
const text2 = message2.type === "user" ? message2.text : message2.type === "assistant" ? message2.content.filter((part) => part.type === "text").map((part) => part.text).join(`
|
|
1849
2059
|
`) : "";
|
|
@@ -1855,7 +2065,9 @@ function transcriptMessage(message2) {
|
|
|
1855
2065
|
text: clipped(text2, 20000),
|
|
1856
2066
|
truncated: text2.length > 20000 || tools.length > 200,
|
|
1857
2067
|
toolCalls: tools.slice(0, 200),
|
|
1858
|
-
error: message2.type === "assistant" ? errorOf(message2.error) : null
|
|
2068
|
+
error: message2.type === "assistant" ? errorOf(message2.error) : null,
|
|
2069
|
+
...message2.type === "assistant" ? { parts: transcriptParts(message2.content) } : {},
|
|
2070
|
+
...message2.type === "assistant" && message2.time.completed !== undefined ? { completedAt: message2.time.completed } : {}
|
|
1859
2071
|
};
|
|
1860
2072
|
}
|
|
1861
2073
|
function boundTranscript(messages) {
|
|
@@ -1872,7 +2084,7 @@ function boundTranscript(messages) {
|
|
|
1872
2084
|
message2.truncated = true;
|
|
1873
2085
|
reduced = true;
|
|
1874
2086
|
}
|
|
1875
|
-
for (const tool of message2.toolCalls) {
|
|
2087
|
+
for (const tool of [...message2.toolCalls, ...(message2.parts ?? []).flatMap((part) => part.type === "tool" ? [part] : [])]) {
|
|
1876
2088
|
for (const key of ["input", "output", "error"]) {
|
|
1877
2089
|
const value = tool[key];
|
|
1878
2090
|
if (value && value.length > 256) {
|
|
@@ -1882,6 +2094,18 @@ function boundTranscript(messages) {
|
|
|
1882
2094
|
}
|
|
1883
2095
|
}
|
|
1884
2096
|
}
|
|
2097
|
+
if (message2.parts && message2.parts.length > 4) {
|
|
2098
|
+
message2.parts = message2.parts.slice(0, Math.ceil(message2.parts.length / 2));
|
|
2099
|
+
message2.truncated = true;
|
|
2100
|
+
reduced = true;
|
|
2101
|
+
}
|
|
2102
|
+
for (const part of message2.parts ?? []) {
|
|
2103
|
+
if (part.type !== "tool" && part.text.length > 256) {
|
|
2104
|
+
part.text = part.text.slice(0, Math.floor(part.text.length / 2));
|
|
2105
|
+
message2.truncated = true;
|
|
2106
|
+
reduced = true;
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
1885
2109
|
}
|
|
1886
2110
|
if (!reduced)
|
|
1887
2111
|
throw new SessionRunnerError("transcript_too_large", "The bounded recent context page is still too large. Request fewer messages.");
|
|
@@ -1893,7 +2117,7 @@ var init_native_opencode = __esm(() => {
|
|
|
1893
2117
|
});
|
|
1894
2118
|
|
|
1895
2119
|
// ../../packages/opencode-plugin/src/runner-ownership.ts
|
|
1896
|
-
import { createHash as
|
|
2120
|
+
import { createHash as createHash6, randomUUID } from "node:crypto";
|
|
1897
2121
|
import { mkdir, readdir, readFile, rmdir, unlink, writeFile } from "node:fs/promises";
|
|
1898
2122
|
import { homedir } from "node:os";
|
|
1899
2123
|
import { join } from "node:path";
|
|
@@ -1906,7 +2130,7 @@ function alive(pid) {
|
|
|
1906
2130
|
}
|
|
1907
2131
|
}
|
|
1908
2132
|
async function acquireRunnerOwnership(directory, root = join(homedir(), ".local", "share", "opencode", "openwork-session-runner-locks")) {
|
|
1909
|
-
const key =
|
|
2133
|
+
const key = createHash6("sha256").update(directory).digest("hex");
|
|
1910
2134
|
const owners = globalThis.__openworkNativeRunnerOwners ??= new Map;
|
|
1911
2135
|
if (owners.has(key))
|
|
1912
2136
|
return null;
|
|
@@ -1976,11 +2200,11 @@ __export(exports_remote_runner, {
|
|
|
1976
2200
|
hasNativeSessionHost: () => hasNativeSessionHost,
|
|
1977
2201
|
createRemoteRunnerController: () => createRemoteRunnerController
|
|
1978
2202
|
});
|
|
1979
|
-
import { createHash as
|
|
2203
|
+
import { createHash as createHash7, randomUUID as randomUUID2 } from "node:crypto";
|
|
1980
2204
|
import { realpath as realpath2 } from "node:fs/promises";
|
|
1981
2205
|
import { hostname } from "node:os";
|
|
1982
2206
|
function hash(value) {
|
|
1983
|
-
return
|
|
2207
|
+
return createHash7("sha256").update(value).digest("hex").slice(0, 32);
|
|
1984
2208
|
}
|
|
1985
2209
|
function hostRead(read, signal) {
|
|
1986
2210
|
const bounded2 = AbortSignal.any([signal, AbortSignal.timeout(1e4)]);
|
|
@@ -2117,19 +2341,27 @@ function createRemoteRunnerController(input) {
|
|
|
2117
2341
|
return state;
|
|
2118
2342
|
}
|
|
2119
2343
|
async function register(state, signal) {
|
|
2120
|
-
const
|
|
2344
|
+
const mint = (capabilities) => hostRead(() => denRequest(fetcher, state.account.session, "/v1/session-runners/token", {
|
|
2121
2345
|
method: "POST",
|
|
2122
2346
|
signal,
|
|
2123
2347
|
body: {
|
|
2124
2348
|
runnerId: state.runnerId,
|
|
2125
2349
|
protocolVersion: 1,
|
|
2126
2350
|
supportedExecutionTargets: ["desktop"],
|
|
2127
|
-
capabilities
|
|
2351
|
+
capabilities,
|
|
2128
2352
|
platform: platform(),
|
|
2129
2353
|
appVersion: ctx.app.version,
|
|
2130
2354
|
concurrency: 1
|
|
2131
2355
|
}
|
|
2132
2356
|
}), signal);
|
|
2357
|
+
let response;
|
|
2358
|
+
try {
|
|
2359
|
+
response = await mint(ANSWER_CAPABILITIES);
|
|
2360
|
+
} catch (error) {
|
|
2361
|
+
if (!(error instanceof DenRequestError) || error.status !== 400)
|
|
2362
|
+
throw error;
|
|
2363
|
+
response = await mint(CAPABILITIES);
|
|
2364
|
+
}
|
|
2133
2365
|
signal.throwIfAborted();
|
|
2134
2366
|
if (!isRecord(response) || typeof response.token !== "string" || response.token.length < 32 || response.token.length > 512 || /[\r\n]/.test(response.token) || typeof response.expiresAt !== "number" || !Number.isFinite(response.expiresAt) || response.expiresAt <= now()) {
|
|
2135
2367
|
throw new Error("OpenWork returned an invalid session-runner registration.");
|
|
@@ -2292,7 +2524,7 @@ function createRemoteRunnerController(input) {
|
|
|
2292
2524
|
}
|
|
2293
2525
|
};
|
|
2294
2526
|
}
|
|
2295
|
-
var CAPABILITIES, RENEW_MS, INVENTORY_MS = 60000, POLL_MS = 3000;
|
|
2527
|
+
var CAPABILITIES, ANSWER_CAPABILITIES, RENEW_MS, INVENTORY_MS = 60000, POLL_MS = 3000;
|
|
2296
2528
|
var init_remote_runner = __esm(() => {
|
|
2297
2529
|
init_src();
|
|
2298
2530
|
init_auth();
|
|
@@ -2301,14 +2533,15 @@ var init_remote_runner = __esm(() => {
|
|
|
2301
2533
|
init_native_opencode();
|
|
2302
2534
|
init_runner_ownership();
|
|
2303
2535
|
CAPABILITIES = ["remote_session_v1", "remote_session_control_v1", "remote_session_only_v1", "remote_session_recovery_v1"];
|
|
2536
|
+
ANSWER_CAPABILITIES = [...CAPABILITIES, "remote_session_answer_v1"];
|
|
2304
2537
|
RENEW_MS = 30 * 60000;
|
|
2305
2538
|
});
|
|
2306
2539
|
|
|
2307
2540
|
// ../../packages/opencode-plugin/src/plugin.ts
|
|
2308
|
-
import { createHash as
|
|
2541
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
2309
2542
|
|
|
2310
2543
|
// ../../packages/opencode-plugin/src/desktop.ts
|
|
2311
|
-
import { createHash as
|
|
2544
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
2312
2545
|
|
|
2313
2546
|
// ../../packages/opencode-plugin/src/desktop-credential-channel.ts
|
|
2314
2547
|
import { createRequire } from "node:module";
|
|
@@ -2333,13 +2566,95 @@ async function fetchDesktopInventory(fetcher, endpoint, path, identity, signal)
|
|
|
2333
2566
|
// ../../packages/opencode-plugin/src/desktop.ts
|
|
2334
2567
|
init_den();
|
|
2335
2568
|
|
|
2569
|
+
// ../../packages/opencode-plugin/src/desktop-session-poll.ts
|
|
2570
|
+
import { createHash } from "node:crypto";
|
|
2571
|
+
var UNKNOWN = { kind: "unknown" };
|
|
2572
|
+
function createSessionPollHub() {
|
|
2573
|
+
const shared = new Map;
|
|
2574
|
+
const run = (entry) => {
|
|
2575
|
+
if (entry.inflight)
|
|
2576
|
+
return entry.inflight;
|
|
2577
|
+
let owner;
|
|
2578
|
+
for (const listener of entry.listeners.values())
|
|
2579
|
+
if (!listener.signal.aborted) {
|
|
2580
|
+
owner = listener;
|
|
2581
|
+
break;
|
|
2582
|
+
}
|
|
2583
|
+
if (!owner)
|
|
2584
|
+
return Promise.resolve(UNKNOWN);
|
|
2585
|
+
const result = owner.check(entry.controller.signal).catch(() => UNKNOWN).then((check) => {
|
|
2586
|
+
entry.inflight = null;
|
|
2587
|
+
for (const listener of entry.listeners.values()) {
|
|
2588
|
+
if (!listener.signal.aborted) {
|
|
2589
|
+
try {
|
|
2590
|
+
listener.receive(check);
|
|
2591
|
+
} catch {}
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
return check;
|
|
2595
|
+
});
|
|
2596
|
+
entry.inflight = result;
|
|
2597
|
+
return result;
|
|
2598
|
+
};
|
|
2599
|
+
const schedule = (entry) => {
|
|
2600
|
+
if (entry.timer)
|
|
2601
|
+
clearInterval(entry.timer);
|
|
2602
|
+
entry.timer = setInterval(() => {
|
|
2603
|
+
run(entry);
|
|
2604
|
+
}, entry.intervalMs);
|
|
2605
|
+
entry.timer.unref?.();
|
|
2606
|
+
};
|
|
2607
|
+
const join = (endpoint, capability, listener) => {
|
|
2608
|
+
if (listener.signal.aborted)
|
|
2609
|
+
return () => Promise.resolve(UNKNOWN);
|
|
2610
|
+
const key = createHash("sha256").update(JSON.stringify([endpoint, capability ?? null])).digest("hex");
|
|
2611
|
+
let entry = shared.get(key);
|
|
2612
|
+
if (!entry) {
|
|
2613
|
+
entry = { controller: new AbortController, listeners: new Map, inflight: null, intervalMs: listener.intervalMs, timer: null };
|
|
2614
|
+
shared.set(key, entry);
|
|
2615
|
+
schedule(entry);
|
|
2616
|
+
} else if (listener.intervalMs < entry.intervalMs) {
|
|
2617
|
+
entry.intervalMs = listener.intervalMs;
|
|
2618
|
+
schedule(entry);
|
|
2619
|
+
}
|
|
2620
|
+
const current = entry;
|
|
2621
|
+
const id = Symbol();
|
|
2622
|
+
current.listeners.set(id, listener);
|
|
2623
|
+
listener.signal.addEventListener("abort", () => {
|
|
2624
|
+
current.listeners.delete(id);
|
|
2625
|
+
if (current.listeners.size)
|
|
2626
|
+
return;
|
|
2627
|
+
if (shared.get(key) === current)
|
|
2628
|
+
shared.delete(key);
|
|
2629
|
+
if (current.timer)
|
|
2630
|
+
clearInterval(current.timer);
|
|
2631
|
+
current.controller.abort();
|
|
2632
|
+
}, { once: true });
|
|
2633
|
+
return () => listener.signal.aborted ? Promise.resolve(UNKNOWN) : run(current);
|
|
2634
|
+
};
|
|
2635
|
+
return Object.freeze({ join: Object.freeze(join) });
|
|
2636
|
+
}
|
|
2637
|
+
function joinDesktopSessionPoll(endpoint, capability, listener) {
|
|
2638
|
+
let hub = globalThis.__openworkDesktopSessionPolls;
|
|
2639
|
+
if (!hub) {
|
|
2640
|
+
hub = createSessionPollHub();
|
|
2641
|
+
Object.defineProperty(globalThis, "__openworkDesktopSessionPolls", {
|
|
2642
|
+
value: hub,
|
|
2643
|
+
writable: false,
|
|
2644
|
+
configurable: false,
|
|
2645
|
+
enumerable: false
|
|
2646
|
+
});
|
|
2647
|
+
}
|
|
2648
|
+
return hub.join(endpoint, capability, listener);
|
|
2649
|
+
}
|
|
2650
|
+
|
|
2336
2651
|
// ../../packages/opencode-plugin/src/inventory-events.ts
|
|
2337
2652
|
init_den();
|
|
2338
2653
|
import { setTimeout as delay } from "node:timers/promises";
|
|
2339
|
-
import { createHash } from "node:crypto";
|
|
2654
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
2340
2655
|
var INVENTORY_EVENTS_PATH = "/v1/inference-providers/inventory/events";
|
|
2341
2656
|
function inventorySessionKey(session) {
|
|
2342
|
-
return
|
|
2657
|
+
return createHash2("sha256").update(JSON.stringify([normalizeBaseUrl(session.apiBaseUrl), session.orgId, session.token])).digest("hex");
|
|
2343
2658
|
}
|
|
2344
2659
|
function joinSharedInventory(shared, options) {
|
|
2345
2660
|
if (options.signal.aborted)
|
|
@@ -3027,7 +3342,7 @@ function fetchSharedGatewayInventory(request) {
|
|
|
3027
3342
|
|
|
3028
3343
|
// ../../packages/opencode-plugin/src/desktop.ts
|
|
3029
3344
|
var CACHE_KEY = "desktop/provider-inventory";
|
|
3030
|
-
var digest = (value) =>
|
|
3345
|
+
var digest = (value) => createHash3("sha256").update(JSON.stringify(value)).digest("hex");
|
|
3031
3346
|
function isDesktopSessionEndpoint(value) {
|
|
3032
3347
|
if (typeof value !== "string")
|
|
3033
3348
|
return false;
|
|
@@ -3041,34 +3356,47 @@ function isDesktopSessionEndpoint(value) {
|
|
|
3041
3356
|
function inventorySession(value) {
|
|
3042
3357
|
return { apiBaseUrl: value.apiBaseUrl, token: value.identity, orgId: value.orgId };
|
|
3043
3358
|
}
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
const response = await fetcher(endpoint, {
|
|
3048
|
-
headers: { accept: "application/json", authorization: `Bearer ${capability}` },
|
|
3049
|
-
redirect: "error",
|
|
3050
|
-
signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(1500)]) : AbortSignal.timeout(1500)
|
|
3051
|
-
});
|
|
3052
|
-
return parseDesktopSession(response, endpoint);
|
|
3053
|
-
}
|
|
3054
|
-
async function parseDesktopSession(response, endpoint) {
|
|
3359
|
+
var UNKNOWN2 = { kind: "unknown" };
|
|
3360
|
+
var SIGNED_OUT = { kind: "signed_out" };
|
|
3361
|
+
async function classifyDesktopSession(response, endpoint) {
|
|
3055
3362
|
if (!response)
|
|
3056
|
-
return
|
|
3057
|
-
if (!response.ok)
|
|
3058
|
-
|
|
3059
|
-
|
|
3363
|
+
return UNKNOWN2;
|
|
3364
|
+
if (!response.ok) {
|
|
3365
|
+
await response.body?.cancel().catch(() => {});
|
|
3366
|
+
return UNKNOWN2;
|
|
3367
|
+
}
|
|
3368
|
+
let value;
|
|
3369
|
+
try {
|
|
3370
|
+
value = await response.json();
|
|
3371
|
+
} catch {
|
|
3372
|
+
return UNKNOWN2;
|
|
3373
|
+
}
|
|
3060
3374
|
if (value === null)
|
|
3061
|
-
return
|
|
3375
|
+
return SIGNED_OUT;
|
|
3062
3376
|
if (!isRecord(value) || typeof value.apiBaseUrl !== "string" || !isAllowedApiBaseUrl(value.apiBaseUrl) || "token" in value || typeof value.identity !== "string" || !/^[a-f0-9]{64}$/.test(value.identity) || !(value.orgId === null || typeof value.orgId === "string") || typeof value.inferenceOrigin !== "string" || value.inferenceOrigin !== new URL(endpoint).origin || typeof value.inferenceKey !== "string" || !/^ow_local_[a-f0-9]{64}$/.test(value.inferenceKey)) {
|
|
3063
|
-
|
|
3377
|
+
return UNKNOWN2;
|
|
3064
3378
|
}
|
|
3065
|
-
return {
|
|
3379
|
+
return { kind: "session", value: {
|
|
3066
3380
|
apiBaseUrl: normalizeBaseUrl(value.apiBaseUrl),
|
|
3067
3381
|
identity: value.identity,
|
|
3068
3382
|
orgId: value.orgId,
|
|
3069
3383
|
inferenceOrigin: value.inferenceOrigin,
|
|
3070
3384
|
inferenceKey: value.inferenceKey
|
|
3071
|
-
};
|
|
3385
|
+
} };
|
|
3386
|
+
}
|
|
3387
|
+
async function checkDesktopSession(fetcher, endpoint, capability, signal) {
|
|
3388
|
+
if (!isDesktopSessionEndpoint(endpoint))
|
|
3389
|
+
return UNKNOWN2;
|
|
3390
|
+
try {
|
|
3391
|
+
const response = capability ? await fetcher(endpoint, {
|
|
3392
|
+
headers: { accept: "application/json", authorization: `Bearer ${capability}` },
|
|
3393
|
+
redirect: "error",
|
|
3394
|
+
signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(1500)]) : AbortSignal.timeout(1500)
|
|
3395
|
+
}) : await fetchDesktopSession(fetcher, endpoint, signal);
|
|
3396
|
+
return await classifyDesktopSession(response, endpoint);
|
|
3397
|
+
} catch {
|
|
3398
|
+
return UNKNOWN2;
|
|
3399
|
+
}
|
|
3072
3400
|
}
|
|
3073
3401
|
function createDesktopProviderPlugin(deps = {}) {
|
|
3074
3402
|
const fetcher = deps.fetch ?? fetch;
|
|
@@ -3076,8 +3404,6 @@ function createDesktopProviderPlugin(deps = {}) {
|
|
|
3076
3404
|
return {
|
|
3077
3405
|
id: "openwork",
|
|
3078
3406
|
async setup(ctx) {
|
|
3079
|
-
if (ctx.options.liveProviderSync !== true)
|
|
3080
|
-
return;
|
|
3081
3407
|
const endpoint = ctx.options.desktopSession;
|
|
3082
3408
|
const capability = deps.capability?.();
|
|
3083
3409
|
if (!isDesktopSessionEndpoint(endpoint))
|
|
@@ -3114,7 +3440,6 @@ function createDesktopProviderPlugin(deps = {}) {
|
|
|
3114
3440
|
let refreshController = new AbortController;
|
|
3115
3441
|
let providers = [];
|
|
3116
3442
|
let applied = digest(providers);
|
|
3117
|
-
let polling = false;
|
|
3118
3443
|
let running = null;
|
|
3119
3444
|
let queued = false;
|
|
3120
3445
|
let inventory = null;
|
|
@@ -3218,77 +3543,93 @@ function createDesktopProviderPlugin(deps = {}) {
|
|
|
3218
3543
|
});
|
|
3219
3544
|
return running;
|
|
3220
3545
|
};
|
|
3221
|
-
const
|
|
3222
|
-
if (
|
|
3546
|
+
const applySession = async (check) => {
|
|
3547
|
+
if (lifetime.signal.aborted || check.kind === "unknown")
|
|
3223
3548
|
return;
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
if (
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3549
|
+
const next = check.kind === "session" ? check.value : null;
|
|
3550
|
+
const nextKey = next ? digest({ apiBaseUrl: next.apiBaseUrl, identity: next.identity, orgId: next.orgId }) : "";
|
|
3551
|
+
if (nextKey === key) {
|
|
3552
|
+
if (session)
|
|
3553
|
+
session = next;
|
|
3554
|
+
await publish(records(inventory)).catch(() => {});
|
|
3555
|
+
return;
|
|
3556
|
+
}
|
|
3557
|
+
epoch++;
|
|
3558
|
+
retry.reset();
|
|
3559
|
+
refreshController.abort();
|
|
3560
|
+
refreshController = new AbortController;
|
|
3561
|
+
stream?.abort();
|
|
3562
|
+
stream = null;
|
|
3563
|
+
session = next;
|
|
3564
|
+
key = nextKey;
|
|
3565
|
+
inventory = null;
|
|
3566
|
+
await publish([]).catch(() => {});
|
|
3567
|
+
if (!next) {
|
|
3568
|
+
await ctx.storage.remove(CACHE_KEY).catch(() => {});
|
|
3569
|
+
return;
|
|
3570
|
+
}
|
|
3571
|
+
const cached = parseInventory(await ctx.storage.get(CACHE_KEY).catch(() => {
|
|
3572
|
+
return;
|
|
3573
|
+
}));
|
|
3574
|
+
if (cached?.connectionKey === key && cached.gateway?.apiKey === "ow_local_catalog" && !lifetime.signal.aborted) {
|
|
3575
|
+
inventory = cached;
|
|
3576
|
+
await publish(records(cached)).catch(() => {});
|
|
3577
|
+
}
|
|
3578
|
+
if (lifetime.signal.aborted)
|
|
3579
|
+
return;
|
|
3580
|
+
const controller = new AbortController;
|
|
3581
|
+
stream = controller;
|
|
3582
|
+
subscribeSharedInventory({
|
|
3583
|
+
identity: inventorySession(next),
|
|
3584
|
+
unauthorized,
|
|
3585
|
+
revoked,
|
|
3586
|
+
fetch: inventoryFetch(next),
|
|
3587
|
+
signal: AbortSignal.any([lifetime.signal, controller.signal]),
|
|
3588
|
+
session: async () => {
|
|
3589
|
+
await pollSession();
|
|
3590
|
+
return controller.signal.aborted || !session ? null : inventorySession(session);
|
|
3591
|
+
},
|
|
3592
|
+
changed: () => {
|
|
3593
|
+
refresh();
|
|
3249
3594
|
}
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3595
|
+
});
|
|
3596
|
+
refresh();
|
|
3597
|
+
};
|
|
3598
|
+
let pending = null;
|
|
3599
|
+
let applying = null;
|
|
3600
|
+
const receive = (check) => {
|
|
3601
|
+
if (lifetime.signal.aborted)
|
|
3602
|
+
return;
|
|
3603
|
+
pending = check;
|
|
3604
|
+
applying ??= (async () => {
|
|
3605
|
+
while (pending && !lifetime.signal.aborted) {
|
|
3606
|
+
const current = pending;
|
|
3607
|
+
pending = null;
|
|
3608
|
+
await applySession(current);
|
|
3256
3609
|
}
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
refresh();
|
|
3273
|
-
}
|
|
3274
|
-
});
|
|
3275
|
-
refresh();
|
|
3276
|
-
} finally {
|
|
3277
|
-
polling = false;
|
|
3278
|
-
}
|
|
3610
|
+
})().catch(() => {}).finally(() => {
|
|
3611
|
+
applying = null;
|
|
3612
|
+
if (pending)
|
|
3613
|
+
receive(pending);
|
|
3614
|
+
});
|
|
3615
|
+
};
|
|
3616
|
+
const checkNow = joinDesktopSessionPoll(endpoint, capability, {
|
|
3617
|
+
check: (signal) => checkDesktopSession(fetcher, endpoint, capability, signal),
|
|
3618
|
+
receive,
|
|
3619
|
+
intervalMs: deps.sessionIntervalMs ?? 1000,
|
|
3620
|
+
signal: lifetime.signal
|
|
3621
|
+
});
|
|
3622
|
+
const pollSession = async () => {
|
|
3623
|
+
await checkNow();
|
|
3624
|
+
await applying;
|
|
3279
3625
|
};
|
|
3280
3626
|
pollSession();
|
|
3281
|
-
const timer = setInterval(() => {
|
|
3282
|
-
pollSession().catch(() => {});
|
|
3283
|
-
}, deps.sessionIntervalMs ?? 1000);
|
|
3284
|
-
timer.unref?.();
|
|
3285
3627
|
return () => {
|
|
3286
3628
|
epoch++;
|
|
3287
3629
|
retry.reset();
|
|
3288
3630
|
lifetime.abort();
|
|
3289
3631
|
refreshController.abort();
|
|
3290
3632
|
stream?.abort();
|
|
3291
|
-
clearInterval(timer);
|
|
3292
3633
|
};
|
|
3293
3634
|
}
|
|
3294
3635
|
};
|
|
@@ -3301,7 +3642,7 @@ init_den();
|
|
|
3301
3642
|
|
|
3302
3643
|
// ../../packages/opencode-plugin/src/mcp.ts
|
|
3303
3644
|
init_den();
|
|
3304
|
-
import { createHash as
|
|
3645
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
3305
3646
|
var CLOUD_SERVER_NAME = "openwork-cloud";
|
|
3306
3647
|
var DIRECT_SERVER_PREFIX = "openwork-direct-";
|
|
3307
3648
|
var SERVER_INDEX_URI = "openwork://connect/mcp-servers/index.json";
|
|
@@ -3326,7 +3667,7 @@ function agentUrl(apiBaseUrl) {
|
|
|
3326
3667
|
}
|
|
3327
3668
|
function directServerName(server) {
|
|
3328
3669
|
const slug = server.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40);
|
|
3329
|
-
const digest2 =
|
|
3670
|
+
const digest2 = createHash4("sha256").update(server.connectionId).digest("hex").slice(0, 6);
|
|
3330
3671
|
return `${DIRECT_SERVER_PREFIX}${slug ? `${slug}-` : ""}${digest2}`;
|
|
3331
3672
|
}
|
|
3332
3673
|
function mcpServerEntries(input) {
|
|
@@ -3517,7 +3858,7 @@ function toJson(value) {
|
|
|
3517
3858
|
return JSON.parse(JSON.stringify(value));
|
|
3518
3859
|
}
|
|
3519
3860
|
function hash2(value) {
|
|
3520
|
-
return
|
|
3861
|
+
return createHash8("sha256").update(value).digest("hex").slice(0, 16);
|
|
3521
3862
|
}
|
|
3522
3863
|
function connectionId(connection) {
|
|
3523
3864
|
return connection.type === "credential" ? connection.id : connection.name;
|
|
@@ -3672,18 +4013,9 @@ function createPlugin(deps = {}) {
|
|
|
3672
4013
|
ctx.storage.remove(INVENTORY_KEY).catch(() => {});
|
|
3673
4014
|
publish(EMPTY).catch(() => {});
|
|
3674
4015
|
};
|
|
3675
|
-
const
|
|
3676
|
-
try {
|
|
3677
|
-
const body = await denRequest(fetcher, session, "/v1/org");
|
|
3678
|
-
return isRecord(body) && isRecord(body.features) ? body.features.liveProviderSync === true : null;
|
|
3679
|
-
} catch {
|
|
3680
|
-
return null;
|
|
3681
|
-
}
|
|
3682
|
-
};
|
|
3683
|
-
const featureEnabled = async (session) => await authorizedFeatureState(session) === true;
|
|
3684
|
-
const syncStream = (session, enabled) => {
|
|
4016
|
+
const syncStream = (session) => {
|
|
3685
4017
|
const key = fingerprint(session);
|
|
3686
|
-
if (!
|
|
4018
|
+
if (!options.providers) {
|
|
3687
4019
|
stopStream();
|
|
3688
4020
|
return;
|
|
3689
4021
|
}
|
|
@@ -3786,17 +4118,9 @@ function createPlugin(deps = {}) {
|
|
|
3786
4118
|
return;
|
|
3787
4119
|
}
|
|
3788
4120
|
if (identity === revokedIdentity) {
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
if (feature === false) {
|
|
3793
|
-
revokedIdentity = "";
|
|
3794
|
-
stopStream();
|
|
3795
|
-
} else {
|
|
3796
|
-
syncStream(session, true);
|
|
3797
|
-
await publish(EMPTY);
|
|
3798
|
-
return;
|
|
3799
|
-
}
|
|
4121
|
+
syncStream(session);
|
|
4122
|
+
await publish(EMPTY);
|
|
4123
|
+
return;
|
|
3800
4124
|
}
|
|
3801
4125
|
if (revokedIdentity !== identity)
|
|
3802
4126
|
revokedIdentity = "";
|
|
@@ -3817,15 +4141,12 @@ function createPlugin(deps = {}) {
|
|
|
3817
4141
|
if (!current())
|
|
3818
4142
|
return;
|
|
3819
4143
|
if (!force && sameAccount && now() - sameAccount.fetchedAt < FRESH_MS) {
|
|
3820
|
-
syncStream(session
|
|
4144
|
+
syncStream(session);
|
|
3821
4145
|
await publish(snapshotFrom(sameAccount, options, connection));
|
|
3822
4146
|
return;
|
|
3823
4147
|
}
|
|
3824
4148
|
try {
|
|
3825
|
-
|
|
3826
|
-
if (!current())
|
|
3827
|
-
return;
|
|
3828
|
-
syncStream(session, liveProviderSync);
|
|
4149
|
+
syncStream(session);
|
|
3829
4150
|
const [gateway, mcp] = await Promise.all([
|
|
3830
4151
|
options.providers ? fetchSharedGatewayInventory({ fetch: fetcher, session, scope: "den", ticket, signal: refreshController.signal }).then((inventory2) => ({ providers: inventory2.providers, apiKey: inventory2.apiKey })) : Promise.resolve(null),
|
|
3831
4152
|
options.mcp ? (async () => {
|
|
@@ -3842,7 +4163,6 @@ function createPlugin(deps = {}) {
|
|
|
3842
4163
|
return;
|
|
3843
4164
|
const inventory = {
|
|
3844
4165
|
version: 1,
|
|
3845
|
-
liveProviderSync,
|
|
3846
4166
|
connectionKey: key,
|
|
3847
4167
|
apiBaseUrl: session.apiBaseUrl,
|
|
3848
4168
|
fetchedAt: now(),
|