mindoodb-app-sdk 0.0.71 → 0.0.73
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 +99 -1
- package/dist/{chunk-GTNDGA7P.js → chunk-FKTNDDWB.js} +728 -40
- package/dist/index.d.ts +3 -55
- package/dist/index.js +57 -1
- package/dist/testing/index.d.ts +129 -2
- package/dist/testing/index.js +425 -17
- package/dist/{types-Dff-SyIx.d.ts → types-CbH_R16h.d.ts} +599 -5
- package/package.json +1 -1
package/dist/testing/index.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MINDOODB_APP_VALUE_TAG,
|
|
3
|
+
MindooDBAppEmbedValidationError,
|
|
3
4
|
assertValidMindooDBCreateIds,
|
|
4
5
|
mindooDBAppComponentFieldsMatch,
|
|
6
|
+
mindooDBAppComponentSupports,
|
|
7
|
+
mindooDBAppExportFile,
|
|
8
|
+
mindooDBAppExportPayload,
|
|
9
|
+
normalizeMindooDBAppEmbedExportRequest,
|
|
10
|
+
normalizeMindooDBAppEmbedVariables,
|
|
11
|
+
normalizeMindooDBAppInspectAnchor,
|
|
12
|
+
normalizeMindooDBAppInspectRequest,
|
|
13
|
+
normalizeMindooDBAppInspection,
|
|
14
|
+
normalizeMindooDBAppIssues,
|
|
5
15
|
pageUsers,
|
|
16
|
+
performMindooDBAppEmbeddingSave,
|
|
6
17
|
releaseMindooDBAppBridgeSessions,
|
|
18
|
+
resolveMindooDBAppEmbedValidation,
|
|
7
19
|
validateMindooDBAppDefinition
|
|
8
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-FKTNDDWB.js";
|
|
9
21
|
|
|
10
22
|
// src/testing/index.ts
|
|
11
23
|
import * as Automerge from "@automerge/automerge";
|
|
@@ -470,6 +482,16 @@ function createMockEmbedHost(options, getDatabase, listDatabaseIds = () => []) {
|
|
|
470
482
|
let nextSaveError = null;
|
|
471
483
|
let embeddingDirty;
|
|
472
484
|
let saveRequestHandler = null;
|
|
485
|
+
let inspectionProvider = null;
|
|
486
|
+
let showIssuesHandler = null;
|
|
487
|
+
let revealHandler = null;
|
|
488
|
+
let exportProvider = null;
|
|
489
|
+
let embeddingVariables = normalizeMindooDBAppEmbedVariables(options.embeddingVariables ?? []);
|
|
490
|
+
const variableListeners = /* @__PURE__ */ new Set();
|
|
491
|
+
const embeddingValidations = [];
|
|
492
|
+
let embeddingSaveCount = 0;
|
|
493
|
+
const beforeSaveHandlers = /* @__PURE__ */ new Map();
|
|
494
|
+
const savedListeners = /* @__PURE__ */ new Set();
|
|
473
495
|
let embedCounter = 0;
|
|
474
496
|
let embeddingFinish = null;
|
|
475
497
|
const accessRequests = [];
|
|
@@ -519,6 +541,18 @@ function createMockEmbedHost(options, getDatabase, listDatabaseIds = () => []) {
|
|
|
519
541
|
if (!mindooDBAppComponentFieldsMatch(component.match, document2.data)) {
|
|
520
542
|
throw new Error(`Document ${input.docId} is not a "${component.label}" document.`);
|
|
521
543
|
}
|
|
544
|
+
let template;
|
|
545
|
+
if (input.template) {
|
|
546
|
+
const databaseId = input.template.databaseId ?? input.databaseId;
|
|
547
|
+
const source = await getDatabase(databaseId).documents.get(input.template.docId);
|
|
548
|
+
if (!source || !mindooDBAppComponentFieldsMatch(component.match, source.data)) {
|
|
549
|
+
throw new Error(`Template ${input.template.docId} is not a "${component.label}" document.`);
|
|
550
|
+
}
|
|
551
|
+
if (!(component.supports ?? []).includes("template")) {
|
|
552
|
+
throw Object.assign(new Error(`Component "${component.label}" cannot start from a template.`), { name: "unsupported" });
|
|
553
|
+
}
|
|
554
|
+
template = { databaseId, docId: input.template.docId };
|
|
555
|
+
}
|
|
522
556
|
embedCounter += 1;
|
|
523
557
|
const embedId = `mock-embed-${embedCounter}`;
|
|
524
558
|
embeds.set(embedId, {
|
|
@@ -530,7 +564,12 @@ function createMockEmbedHost(options, getDatabase, listDatabaseIds = () => []) {
|
|
|
530
564
|
rect: mockRect(input),
|
|
531
565
|
visible: input.visible !== false,
|
|
532
566
|
active: false,
|
|
533
|
-
agentTools: null
|
|
567
|
+
agentTools: null,
|
|
568
|
+
supports: [...component.supports ?? []],
|
|
569
|
+
beforeSave: null,
|
|
570
|
+
requests: [],
|
|
571
|
+
variables: normalizeMindooDBAppEmbedVariables(input.variables ?? []),
|
|
572
|
+
...template ? { template } : {}
|
|
534
573
|
});
|
|
535
574
|
setActive(embedId);
|
|
536
575
|
return embedId;
|
|
@@ -583,6 +622,7 @@ function createMockEmbedHost(options, getDatabase, listDatabaseIds = () => []) {
|
|
|
583
622
|
handles.get(embedId)?.settle(event);
|
|
584
623
|
handles.delete(embedId);
|
|
585
624
|
toolNames.delete(embedId);
|
|
625
|
+
beforeSaveHandlers.delete(embedId);
|
|
586
626
|
closedListeners.forEach((listener) => listener(event));
|
|
587
627
|
notifyChange();
|
|
588
628
|
}
|
|
@@ -605,6 +645,46 @@ function createMockEmbedHost(options, getDatabase, listDatabaseIds = () => []) {
|
|
|
605
645
|
closed;
|
|
606
646
|
dirty = void 0;
|
|
607
647
|
dirtyListeners = /* @__PURE__ */ new Set();
|
|
648
|
+
savedListeners = /* @__PURE__ */ new Set();
|
|
649
|
+
get supports() {
|
|
650
|
+
return embeds.get(this.embedId)?.supports ?? [];
|
|
651
|
+
}
|
|
652
|
+
async inspect(request) {
|
|
653
|
+
return await inspectEmbed(this.embedId, request);
|
|
654
|
+
}
|
|
655
|
+
onBeforeSave(handler, options2) {
|
|
656
|
+
setBeforeSave(this.embedId, handler, options2?.inspect);
|
|
657
|
+
return () => {
|
|
658
|
+
if (beforeSaveHandlers.get(this.embedId) === handler) {
|
|
659
|
+
setBeforeSave(this.embedId, null);
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
onAfterSave(listener) {
|
|
664
|
+
this.savedListeners.add(listener);
|
|
665
|
+
return () => {
|
|
666
|
+
this.savedListeners.delete(listener);
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
notifySaved() {
|
|
670
|
+
const event = { embedId: this.embedId };
|
|
671
|
+
this.savedListeners.forEach((listener) => listener(event));
|
|
672
|
+
}
|
|
673
|
+
async showIssues(issues) {
|
|
674
|
+
await showEmbedIssues(this.embedId, issues);
|
|
675
|
+
}
|
|
676
|
+
async reveal(anchor) {
|
|
677
|
+
await revealInEmbed(this.embedId, anchor);
|
|
678
|
+
}
|
|
679
|
+
async callTool(name, input) {
|
|
680
|
+
return await callEmbedTool(this.embedId, name, input ?? {});
|
|
681
|
+
}
|
|
682
|
+
async setVariables(variables) {
|
|
683
|
+
setEmbedVariables(this.embedId, variables);
|
|
684
|
+
}
|
|
685
|
+
async export(request) {
|
|
686
|
+
return mindooDBAppExportFile(await exportEmbed(this.embedId, request));
|
|
687
|
+
}
|
|
608
688
|
onDirtyChange(listener) {
|
|
609
689
|
this.dirtyListeners.add(listener);
|
|
610
690
|
return () => {
|
|
@@ -704,7 +784,8 @@ function createMockEmbedHost(options, getDatabase, listDatabaseIds = () => []) {
|
|
|
704
784
|
notifyChange();
|
|
705
785
|
}
|
|
706
786
|
async function saveEmbed(embedId) {
|
|
707
|
-
|
|
787
|
+
const entry = embeds.get(embedId);
|
|
788
|
+
if (!entry) {
|
|
708
789
|
throw new Error("Unknown embed.");
|
|
709
790
|
}
|
|
710
791
|
const error = nextSaveError;
|
|
@@ -712,7 +793,130 @@ function createMockEmbedHost(options, getDatabase, listDatabaseIds = () => []) {
|
|
|
712
793
|
if (error) {
|
|
713
794
|
throw new Error(error);
|
|
714
795
|
}
|
|
796
|
+
if (mindooDBAppComponentSupports(entry.supports, "validate")) {
|
|
797
|
+
const validation = await validateEmbed(embedId);
|
|
798
|
+
if (!validation.ok) {
|
|
799
|
+
throw new MindooDBAppEmbedValidationError(validation.issues);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
715
802
|
setEmbedDirty(embedId, false);
|
|
803
|
+
notifyEmbedSaved(embedId);
|
|
804
|
+
}
|
|
805
|
+
function entryOf(embedId) {
|
|
806
|
+
const entry = embeds.get(embedId);
|
|
807
|
+
if (!entry) {
|
|
808
|
+
throw new Error("Unknown embed.");
|
|
809
|
+
}
|
|
810
|
+
return entry;
|
|
811
|
+
}
|
|
812
|
+
function unsupported(message) {
|
|
813
|
+
return Object.assign(new Error(message), { name: "unsupported" });
|
|
814
|
+
}
|
|
815
|
+
async function inspectEmbed(embedId, request) {
|
|
816
|
+
const entry = entryOf(embedId);
|
|
817
|
+
const inspect = normalizeMindooDBAppInspectRequest(request);
|
|
818
|
+
entry.requests.push({ request: "inspect", inspect });
|
|
819
|
+
if (!options.embedInspection || !mindooDBAppComponentSupports(entry.supports, "inspect")) {
|
|
820
|
+
throw unsupported("The component cannot describe its document.");
|
|
821
|
+
}
|
|
822
|
+
return normalizeMindooDBAppInspection(await options.embedInspection(structuredClone(entry), inspect));
|
|
823
|
+
}
|
|
824
|
+
function setBeforeSave(embedId, handler, inspect) {
|
|
825
|
+
const entry = entryOf(embedId);
|
|
826
|
+
if (handler) {
|
|
827
|
+
beforeSaveHandlers.set(embedId, handler);
|
|
828
|
+
entry.beforeSave = { inspect: normalizeMindooDBAppInspectRequest(inspect) };
|
|
829
|
+
} else {
|
|
830
|
+
beforeSaveHandlers.delete(embedId);
|
|
831
|
+
entry.beforeSave = null;
|
|
832
|
+
}
|
|
833
|
+
notifyChange();
|
|
834
|
+
}
|
|
835
|
+
async function validateEmbed(embedId, validateOptions = {}) {
|
|
836
|
+
const entry = entryOf(embedId);
|
|
837
|
+
const handler = beforeSaveHandlers.get(embedId);
|
|
838
|
+
if (!handler) {
|
|
839
|
+
return { ok: true, issues: [] };
|
|
840
|
+
}
|
|
841
|
+
let inspection = null;
|
|
842
|
+
if (options.embedInspection && mindooDBAppComponentSupports(entry.supports, "inspect")) {
|
|
843
|
+
inspection = normalizeMindooDBAppInspection(
|
|
844
|
+
await options.embedInspection(structuredClone(entry), entry.beforeSave?.inspect ?? {})
|
|
845
|
+
);
|
|
846
|
+
}
|
|
847
|
+
const root = await getDatabase(entry.databaseId).documents.get(entry.docId);
|
|
848
|
+
const answer = await handler({
|
|
849
|
+
embedId,
|
|
850
|
+
inspection,
|
|
851
|
+
root: root ? JSON.parse(JSON.stringify(root.data)) : null
|
|
852
|
+
});
|
|
853
|
+
return await resolveMindooDBAppEmbedValidation(
|
|
854
|
+
normalizeMindooDBAppIssues(answer?.issues),
|
|
855
|
+
validateOptions.interactive !== false,
|
|
856
|
+
options.confirmSaveWarnings ?? (() => true)
|
|
857
|
+
);
|
|
858
|
+
}
|
|
859
|
+
function notifyEmbedSaved(embedId) {
|
|
860
|
+
if (!embeds.has(embedId)) {
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
handles.get(embedId)?.notifySaved();
|
|
864
|
+
savedListeners.forEach((listener) => listener({ embedId }));
|
|
865
|
+
}
|
|
866
|
+
async function showEmbedIssues(embedId, issues) {
|
|
867
|
+
const entry = entryOf(embedId);
|
|
868
|
+
entry.requests.push({ request: "showIssues", issues: normalizeMindooDBAppIssues(issues) });
|
|
869
|
+
if (!mindooDBAppComponentSupports(entry.supports, "issues")) {
|
|
870
|
+
throw unsupported("The component cannot show issues.");
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
async function revealInEmbed(embedId, anchor) {
|
|
874
|
+
const entry = entryOf(embedId);
|
|
875
|
+
const normalized = normalizeMindooDBAppInspectAnchor(anchor);
|
|
876
|
+
if (!normalized) {
|
|
877
|
+
throw new Error("Invalid anchor.");
|
|
878
|
+
}
|
|
879
|
+
entry.requests.push({ request: "reveal", anchor: normalized });
|
|
880
|
+
if (!mindooDBAppComponentSupports(entry.supports, "reveal")) {
|
|
881
|
+
throw unsupported("The component cannot reveal places.");
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
async function callEmbedTool(embedId, name, input) {
|
|
885
|
+
const entry = entryOf(embedId);
|
|
886
|
+
const prefix = `${toolPrefix(entry.component)}_`;
|
|
887
|
+
const bare = name.startsWith(prefix) ? name.slice(prefix.length) : name;
|
|
888
|
+
entry.requests.push({ request: "callTool", name: bare, input: structuredClone(input) });
|
|
889
|
+
if (!options.embedTools) {
|
|
890
|
+
throw unsupported(`The component has no tool "${bare}".`);
|
|
891
|
+
}
|
|
892
|
+
return structuredClone(await options.embedTools(structuredClone(entry), bare, structuredClone(input)));
|
|
893
|
+
}
|
|
894
|
+
async function validateEmbedding(validateOptions = {}) {
|
|
895
|
+
const interactive = validateOptions.interactive !== false;
|
|
896
|
+
const raw = await options.embeddingValidation?.({ interactive }) ?? { ok: true, issues: [] };
|
|
897
|
+
const result = {
|
|
898
|
+
ok: raw.ok !== false,
|
|
899
|
+
issues: normalizeMindooDBAppIssues(raw.issues),
|
|
900
|
+
...raw.timedOut ? { timedOut: true } : {}
|
|
901
|
+
};
|
|
902
|
+
embeddingValidations.push({ interactive, result: structuredClone(result) });
|
|
903
|
+
return result;
|
|
904
|
+
}
|
|
905
|
+
function setEmbedVariables(embedId, variables) {
|
|
906
|
+
entryOf(embedId).variables = normalizeMindooDBAppEmbedVariables(variables);
|
|
907
|
+
notifyChange();
|
|
908
|
+
}
|
|
909
|
+
async function exportEmbed(embedId, request) {
|
|
910
|
+
const entry = entryOf(embedId);
|
|
911
|
+
const normalized = normalizeMindooDBAppEmbedExportRequest(request);
|
|
912
|
+
entry.requests.push({ request: "export", export: normalized });
|
|
913
|
+
if (!options.embedExport || !mindooDBAppComponentSupports(entry.supports, `export:${normalized.format}`)) {
|
|
914
|
+
throw unsupported(`The component cannot export ${normalized.format}.`);
|
|
915
|
+
}
|
|
916
|
+
return await mindooDBAppExportPayload(await options.embedExport(structuredClone(entry), normalized), normalized);
|
|
917
|
+
}
|
|
918
|
+
function unsupportedHandler() {
|
|
919
|
+
throw unsupported("unsupported");
|
|
716
920
|
}
|
|
717
921
|
function setVisible(embedId, visible) {
|
|
718
922
|
const entry = embeds.get(embedId);
|
|
@@ -724,7 +928,7 @@ function createMockEmbedHost(options, getDatabase, listDatabaseIds = () => []) {
|
|
|
724
928
|
return {
|
|
725
929
|
components: {
|
|
726
930
|
async list(query) {
|
|
727
|
-
return components.filter((entry) => !query?.intent || entry.intents.includes(query.intent)).filter((entry) => !query?.document || mindooDBAppComponentFieldsMatch(entry.match, query.document)).map((entry) => structuredClone(entry));
|
|
931
|
+
return components.filter((entry) => !query?.intent || entry.intents.includes(query.intent)).filter((entry) => (query?.requires ?? []).every((requirement) => mindooDBAppComponentSupports(entry.supports, requirement))).filter((entry) => !query?.document || mindooDBAppComponentFieldsMatch(entry.match, query.document)).map((entry) => structuredClone(entry));
|
|
728
932
|
}
|
|
729
933
|
},
|
|
730
934
|
embeds: {
|
|
@@ -759,6 +963,51 @@ function createMockEmbedHost(options, getDatabase, listDatabaseIds = () => []) {
|
|
|
759
963
|
saveRequestHandler = null;
|
|
760
964
|
}
|
|
761
965
|
};
|
|
966
|
+
},
|
|
967
|
+
provideInspection(provider) {
|
|
968
|
+
inspectionProvider = provider;
|
|
969
|
+
return () => {
|
|
970
|
+
if (inspectionProvider === provider) inspectionProvider = null;
|
|
971
|
+
};
|
|
972
|
+
},
|
|
973
|
+
onShowIssues(handler) {
|
|
974
|
+
showIssuesHandler = handler;
|
|
975
|
+
return () => {
|
|
976
|
+
if (showIssuesHandler === handler) showIssuesHandler = null;
|
|
977
|
+
};
|
|
978
|
+
},
|
|
979
|
+
onReveal(handler) {
|
|
980
|
+
revealHandler = handler;
|
|
981
|
+
return () => {
|
|
982
|
+
if (revealHandler === handler) revealHandler = null;
|
|
983
|
+
};
|
|
984
|
+
},
|
|
985
|
+
validate: validateEmbedding,
|
|
986
|
+
async getVariables() {
|
|
987
|
+
return embeddingVariables.map((variable) => ({ ...variable }));
|
|
988
|
+
},
|
|
989
|
+
onVariablesChange(listener) {
|
|
990
|
+
variableListeners.add(listener);
|
|
991
|
+
return () => {
|
|
992
|
+
variableListeners.delete(listener);
|
|
993
|
+
};
|
|
994
|
+
},
|
|
995
|
+
provideExport(provider) {
|
|
996
|
+
exportProvider = provider;
|
|
997
|
+
return () => {
|
|
998
|
+
if (exportProvider === provider) exportProvider = null;
|
|
999
|
+
};
|
|
1000
|
+
},
|
|
1001
|
+
async save(flush, saveOptions) {
|
|
1002
|
+
return await performMindooDBAppEmbeddingSave({
|
|
1003
|
+
validate: () => validateEmbedding(saveOptions),
|
|
1004
|
+
provider: inspectionProvider,
|
|
1005
|
+
showIssues: showIssuesHandler,
|
|
1006
|
+
flush,
|
|
1007
|
+
saved: () => {
|
|
1008
|
+
embeddingSaveCount += 1;
|
|
1009
|
+
}
|
|
1010
|
+
});
|
|
762
1011
|
}
|
|
763
1012
|
},
|
|
764
1013
|
openEmbed,
|
|
@@ -822,6 +1071,58 @@ function createMockEmbedHost(options, getDatabase, listDatabaseIds = () => []) {
|
|
|
822
1071
|
},
|
|
823
1072
|
setSaveRequestHandler(handler) {
|
|
824
1073
|
saveRequestHandler = handler;
|
|
1074
|
+
},
|
|
1075
|
+
inspectEmbed,
|
|
1076
|
+
setBeforeSave,
|
|
1077
|
+
validateEmbed,
|
|
1078
|
+
notifyEmbedSaved,
|
|
1079
|
+
onSaved(listener) {
|
|
1080
|
+
savedListeners.add(listener);
|
|
1081
|
+
return () => {
|
|
1082
|
+
savedListeners.delete(listener);
|
|
1083
|
+
};
|
|
1084
|
+
},
|
|
1085
|
+
showEmbedIssues,
|
|
1086
|
+
revealInEmbed,
|
|
1087
|
+
callEmbedTool,
|
|
1088
|
+
getEmbedRequests(embedId) {
|
|
1089
|
+
return structuredClone(embeds.get(embedId)?.requests ?? []);
|
|
1090
|
+
},
|
|
1091
|
+
async requestEmbeddingInspection(request) {
|
|
1092
|
+
if (!inspectionProvider) unsupportedHandler();
|
|
1093
|
+
return normalizeMindooDBAppInspection(await inspectionProvider(normalizeMindooDBAppInspectRequest(request)));
|
|
1094
|
+
},
|
|
1095
|
+
async requestEmbeddingShowIssues(issues) {
|
|
1096
|
+
if (!showIssuesHandler) unsupportedHandler();
|
|
1097
|
+
await showIssuesHandler(normalizeMindooDBAppIssues(issues));
|
|
1098
|
+
},
|
|
1099
|
+
async requestEmbeddingReveal(anchor) {
|
|
1100
|
+
if (!revealHandler) unsupportedHandler();
|
|
1101
|
+
await revealHandler(anchor);
|
|
1102
|
+
},
|
|
1103
|
+
getEmbeddingValidations() {
|
|
1104
|
+
return structuredClone(embeddingValidations);
|
|
1105
|
+
},
|
|
1106
|
+
getEmbeddingSaveCount() {
|
|
1107
|
+
return embeddingSaveCount;
|
|
1108
|
+
},
|
|
1109
|
+
validateEmbedding,
|
|
1110
|
+
recordEmbeddingSaved() {
|
|
1111
|
+
embeddingSaveCount += 1;
|
|
1112
|
+
},
|
|
1113
|
+
setEmbedVariables,
|
|
1114
|
+
exportEmbed,
|
|
1115
|
+
async requestEmbeddingVariables(variables) {
|
|
1116
|
+
embeddingVariables = normalizeMindooDBAppEmbedVariables(variables);
|
|
1117
|
+
variableListeners.forEach((listener) => listener(embeddingVariables.map((variable) => ({ ...variable }))));
|
|
1118
|
+
},
|
|
1119
|
+
getEmbeddingVariables() {
|
|
1120
|
+
return embeddingVariables.map((variable) => ({ ...variable }));
|
|
1121
|
+
},
|
|
1122
|
+
async requestEmbeddingExport(request) {
|
|
1123
|
+
if (!exportProvider) unsupportedHandler();
|
|
1124
|
+
const normalized = normalizeMindooDBAppEmbedExportRequest(request);
|
|
1125
|
+
return mindooDBAppExportFile(await mindooDBAppExportPayload(await exportProvider(normalized), normalized));
|
|
825
1126
|
}
|
|
826
1127
|
};
|
|
827
1128
|
}
|
|
@@ -6030,7 +6331,17 @@ function createMockMindooDBAppSession(options = {}) {
|
|
|
6030
6331
|
setEmbedAgentTools: (embedId, names, toolOptions) => state.embedHost.setEmbedAgentTools(embedId, names, toolOptions),
|
|
6031
6332
|
failNextEmbedSave: (message) => state.embedHost.failNextSave(message),
|
|
6032
6333
|
getEmbeddingDirty: () => state.embedHost.getEmbeddingDirty(),
|
|
6033
|
-
requestEmbeddingSave: () => state.embedHost.requestEmbeddingSave()
|
|
6334
|
+
requestEmbeddingSave: () => state.embedHost.requestEmbeddingSave(),
|
|
6335
|
+
validateEmbed: (embedId, validateOptions) => state.embedHost.validateEmbed(embedId, validateOptions),
|
|
6336
|
+
notifyEmbedSaved: (embedId) => state.embedHost.notifyEmbedSaved(embedId),
|
|
6337
|
+
getEmbedRequests: (embedId) => state.embedHost.getEmbedRequests(embedId),
|
|
6338
|
+
requestEmbeddingInspection: (request) => state.embedHost.requestEmbeddingInspection(request),
|
|
6339
|
+
requestEmbeddingShowIssues: (issues) => state.embedHost.requestEmbeddingShowIssues(issues),
|
|
6340
|
+
requestEmbeddingReveal: (anchor) => state.embedHost.requestEmbeddingReveal(anchor),
|
|
6341
|
+
getEmbeddingValidations: () => state.embedHost.getEmbeddingValidations(),
|
|
6342
|
+
getEmbeddingSaveCount: () => state.embedHost.getEmbeddingSaveCount(),
|
|
6343
|
+
requestEmbeddingVariables: (variables) => state.embedHost.requestEmbeddingVariables(variables),
|
|
6344
|
+
requestEmbeddingExport: (request) => state.embedHost.requestEmbeddingExport(request)
|
|
6034
6345
|
};
|
|
6035
6346
|
replicaStates.set(controller, state);
|
|
6036
6347
|
return controller;
|
|
@@ -6076,8 +6387,25 @@ function createFakeBridgeHost(options = {}) {
|
|
|
6076
6387
|
(port) => port.postMessage({ protocol: PROTOCOL, kind: "embed-event", event: { type: "agentTools", ...event } })
|
|
6077
6388
|
);
|
|
6078
6389
|
});
|
|
6390
|
+
state.embedHost.onSaved((event) => {
|
|
6391
|
+
connectedPorts.forEach(
|
|
6392
|
+
(port) => port.postMessage({ protocol: PROTOCOL, kind: "embed-event", event: { type: "saved", ...event } })
|
|
6393
|
+
);
|
|
6394
|
+
});
|
|
6079
6395
|
const embeddingRequests = /* @__PURE__ */ new Map();
|
|
6080
6396
|
let embeddingRequestCounter = 0;
|
|
6397
|
+
function pushEmbeddingRequest(request, params) {
|
|
6398
|
+
embeddingRequestCounter += 1;
|
|
6399
|
+
const requestId = `embedding-request-${embeddingRequestCounter}`;
|
|
6400
|
+
return new Promise((resolve, reject) => {
|
|
6401
|
+
embeddingRequests.set(requestId, { resolve, reject });
|
|
6402
|
+
connectedPorts.forEach(
|
|
6403
|
+
(port) => port.postMessage({ protocol: PROTOCOL, kind: "embedding-request", requestId, request, ...params ? { params } : {} })
|
|
6404
|
+
);
|
|
6405
|
+
});
|
|
6406
|
+
}
|
|
6407
|
+
const embedRequests = /* @__PURE__ */ new Map();
|
|
6408
|
+
let embedRequestCounter = 0;
|
|
6081
6409
|
const beforeCloseWaiters = /* @__PURE__ */ new Map();
|
|
6082
6410
|
let beforeCloseCounter = 0;
|
|
6083
6411
|
const viewSessions = /* @__PURE__ */ new Map();
|
|
@@ -6314,8 +6642,73 @@ function createFakeBridgeHost(options = {}) {
|
|
|
6314
6642
|
case "embeds.open": {
|
|
6315
6643
|
const input = params.input;
|
|
6316
6644
|
const embedId = await state.embedHost.openEmbed(input);
|
|
6317
|
-
|
|
6645
|
+
const supports = state.embedHost.listEmbeds().find((entry) => entry.embedId === embedId)?.supports ?? [];
|
|
6646
|
+
return {
|
|
6647
|
+
embedId,
|
|
6648
|
+
...input.placement === "frame" && options.embedFrameUrl ? { frame: { url: options.embedFrameUrl } } : {},
|
|
6649
|
+
...supports.length ? { supports } : {}
|
|
6650
|
+
};
|
|
6651
|
+
}
|
|
6652
|
+
case "embeds.inspect":
|
|
6653
|
+
return await state.embedHost.inspectEmbed(
|
|
6654
|
+
String(params.embedId),
|
|
6655
|
+
params.request
|
|
6656
|
+
);
|
|
6657
|
+
case "embeds.setBeforeSave": {
|
|
6658
|
+
const embedId = String(params.embedId);
|
|
6659
|
+
state.embedHost.setBeforeSave(
|
|
6660
|
+
embedId,
|
|
6661
|
+
params.enabled === true ? (input) => {
|
|
6662
|
+
embedRequestCounter += 1;
|
|
6663
|
+
const requestId = `embed-request-${embedRequestCounter}`;
|
|
6664
|
+
return new Promise((resolve) => {
|
|
6665
|
+
embedRequests.set(requestId, (result) => resolve(result));
|
|
6666
|
+
connectedPorts.forEach(
|
|
6667
|
+
(port) => port.postMessage({
|
|
6668
|
+
protocol: PROTOCOL,
|
|
6669
|
+
kind: "embed-request",
|
|
6670
|
+
requestId,
|
|
6671
|
+
embedId,
|
|
6672
|
+
request: "beforeSave",
|
|
6673
|
+
params: { inspection: input.inspection, root: input.root }
|
|
6674
|
+
})
|
|
6675
|
+
);
|
|
6676
|
+
});
|
|
6677
|
+
} : null,
|
|
6678
|
+
params.inspect
|
|
6679
|
+
);
|
|
6680
|
+
return { ok: true };
|
|
6681
|
+
}
|
|
6682
|
+
case "embeds.respond": {
|
|
6683
|
+
const resolve = embedRequests.get(String(params.requestId));
|
|
6684
|
+
embedRequests.delete(String(params.requestId));
|
|
6685
|
+
resolve?.(params.ok === true ? params.result : { issues: [] });
|
|
6686
|
+
return { ok: true };
|
|
6318
6687
|
}
|
|
6688
|
+
case "embeds.showIssues":
|
|
6689
|
+
await state.embedHost.showEmbedIssues(String(params.embedId), params.issues);
|
|
6690
|
+
return { ok: true };
|
|
6691
|
+
case "embeds.reveal":
|
|
6692
|
+
await state.embedHost.revealInEmbed(String(params.embedId), params.anchor);
|
|
6693
|
+
return { ok: true };
|
|
6694
|
+
case "embeds.callTool":
|
|
6695
|
+
return await state.embedHost.callEmbedTool(
|
|
6696
|
+
String(params.embedId),
|
|
6697
|
+
String(params.name),
|
|
6698
|
+
params.input ?? {}
|
|
6699
|
+
);
|
|
6700
|
+
case "embeds.setVariables":
|
|
6701
|
+
state.embedHost.setEmbedVariables(String(params.embedId), params.variables);
|
|
6702
|
+
return { ok: true };
|
|
6703
|
+
case "embeds.export":
|
|
6704
|
+
return await state.embedHost.exportEmbed(String(params.embedId), params.request);
|
|
6705
|
+
case "embedding.getVariables":
|
|
6706
|
+
return { variables: state.embedHost.getEmbeddingVariables() };
|
|
6707
|
+
case "embedding.validate":
|
|
6708
|
+
return await state.embedHost.validateEmbedding({ interactive: params.interactive !== false });
|
|
6709
|
+
case "embedding.saved":
|
|
6710
|
+
state.embedHost.recordEmbeddingSaved();
|
|
6711
|
+
return { ok: true };
|
|
6319
6712
|
case "embeds.requestAccess":
|
|
6320
6713
|
return await state.embedHost.embeds.requestAccess(
|
|
6321
6714
|
params.input ?? { components: [] }
|
|
@@ -6348,9 +6741,10 @@ function createFakeBridgeHost(options = {}) {
|
|
|
6348
6741
|
const pending = embeddingRequests.get(String(params.requestId));
|
|
6349
6742
|
embeddingRequests.delete(String(params.requestId));
|
|
6350
6743
|
if (params.ok === true) {
|
|
6351
|
-
pending?.resolve();
|
|
6744
|
+
pending?.resolve(params.result);
|
|
6352
6745
|
} else {
|
|
6353
|
-
|
|
6746
|
+
const message = typeof params.error === "string" ? params.error : "Save failed.";
|
|
6747
|
+
pending?.reject(Object.assign(new Error(message), message === "unsupported" ? { name: "unsupported" } : {}));
|
|
6354
6748
|
}
|
|
6355
6749
|
return { ok: true };
|
|
6356
6750
|
}
|
|
@@ -6988,15 +7382,29 @@ function createFakeBridgeHost(options = {}) {
|
|
|
6988
7382
|
setEmbedAgentTools: (embedId, names, toolOptions) => state.embedHost.setEmbedAgentTools(embedId, names, toolOptions),
|
|
6989
7383
|
failNextEmbedSave: (message) => state.embedHost.failNextSave(message),
|
|
6990
7384
|
getEmbeddingDirty: () => state.embedHost.getEmbeddingDirty(),
|
|
6991
|
-
requestEmbeddingSave() {
|
|
6992
|
-
|
|
6993
|
-
|
|
6994
|
-
|
|
6995
|
-
|
|
6996
|
-
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7385
|
+
async requestEmbeddingSave() {
|
|
7386
|
+
await pushEmbeddingRequest("save");
|
|
7387
|
+
},
|
|
7388
|
+
validateEmbed: (embedId, validateOptions) => state.embedHost.validateEmbed(embedId, validateOptions),
|
|
7389
|
+
notifyEmbedSaved: (embedId) => state.embedHost.notifyEmbedSaved(embedId),
|
|
7390
|
+
getEmbedRequests: (embedId) => state.embedHost.getEmbedRequests(embedId),
|
|
7391
|
+
async requestEmbeddingInspection(request) {
|
|
7392
|
+
return await pushEmbeddingRequest("inspect", { request: request ?? {} });
|
|
7393
|
+
},
|
|
7394
|
+
async requestEmbeddingShowIssues(issues) {
|
|
7395
|
+
await pushEmbeddingRequest("showIssues", { issues });
|
|
7396
|
+
},
|
|
7397
|
+
async requestEmbeddingReveal(anchor) {
|
|
7398
|
+
await pushEmbeddingRequest("reveal", { anchor });
|
|
7399
|
+
},
|
|
7400
|
+
getEmbeddingValidations: () => state.embedHost.getEmbeddingValidations(),
|
|
7401
|
+
getEmbeddingSaveCount: () => state.embedHost.getEmbeddingSaveCount(),
|
|
7402
|
+
async requestEmbeddingVariables(variables) {
|
|
7403
|
+
await state.embedHost.requestEmbeddingVariables(variables);
|
|
7404
|
+
await pushEmbeddingRequest("variables", { variables: state.embedHost.getEmbeddingVariables() });
|
|
7405
|
+
},
|
|
7406
|
+
async requestEmbeddingExport(request) {
|
|
7407
|
+
return mindooDBAppExportFile(await pushEmbeddingRequest("export", { request }));
|
|
7000
7408
|
},
|
|
7001
7409
|
dispose() {
|
|
7002
7410
|
restoreWindow();
|