@powerhousedao/reactor-browser 6.2.3-dev.61 → 6.2.3-dev.63
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/dist/{attachment-service-DG6UkyMv.d.ts → attachment-service-CQ3JygJd.d.ts} +3 -3
- package/dist/{attachment-service-DG6UkyMv.d.ts.map → attachment-service-CQ3JygJd.d.ts.map} +1 -1
- package/dist/{client-Cq5avLW5.js → client-Bwiji4R6.js} +6 -2
- package/dist/client-Bwiji4R6.js.map +1 -0
- package/dist/{dispatch-C1VVTn5S.js → dispatch-BmdzdTwb.js} +15 -11
- package/dist/dispatch-BmdzdTwb.js.map +1 -0
- package/dist/{document-by-id-BRDkvmpn.js → document-by-id-BqNuTx4S.js} +2 -2
- package/dist/{document-by-id-BRDkvmpn.js.map → document-by-id-BqNuTx4S.js.map} +1 -1
- package/dist/{document-model-modules-Gsh1Xr7j.js → document-model-modules-Wjh92XAb.js} +192 -157
- package/dist/document-model-modules-Wjh92XAb.js.map +1 -0
- package/dist/{document-operations-BSzcF0mu.js → document-operations--Z0AOyyy.js} +74 -27
- package/dist/document-operations--Z0AOyyy.js.map +1 -0
- package/dist/{global-BuSwbbY0.d.ts → global-CPJA8ePb.d.ts} +56 -4
- package/dist/global-CPJA8ePb.d.ts.map +1 -0
- package/dist/{index-ewIc3pEO.d.ts → index-DRCTps7m.d.ts} +2 -2
- package/dist/{index-ewIc3pEO.d.ts.map → index-DRCTps7m.d.ts.map} +1 -1
- package/dist/index.d.ts +244 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +305 -37
- package/dist/index.js.map +1 -1
- package/dist/make-ph-event-functions-C1JTfEw1.js +251 -0
- package/dist/make-ph-event-functions-C1JTfEw1.js.map +1 -0
- package/dist/navigation-B4fHR-Tm.js +315 -0
- package/dist/navigation-B4fHR-Tm.js.map +1 -0
- package/dist/{relational-DxHuX41f.js → relational-DZuyKp2y.js} +2 -2
- package/dist/{relational-DxHuX41f.js.map → relational-DZuyKp2y.js.map} +1 -1
- package/dist/{renown-D05wkobG.js → renown-CGQYQsvH.js} +2 -2
- package/dist/{renown-D05wkobG.js.map → renown-CGQYQsvH.js.map} +1 -1
- package/dist/{renown-CPAeJt5L.js → renown-DlkS61Dp.js} +28 -22
- package/dist/{renown-CPAeJt5L.js.map → renown-DlkS61Dp.js.map} +1 -1
- package/dist/src/ai/index.d.ts.map +1 -1
- package/dist/src/ai/index.js +3 -3
- package/dist/src/analytics/index.js +3 -3
- package/dist/src/graphql-client/entry.d.ts +2 -2
- package/dist/src/graphql-client/entry.js +3 -3
- package/dist/src/relational/index.js +1 -1
- package/dist/src/renown/index.d.ts +1 -1
- package/dist/src/renown/index.js +2 -2
- package/dist/src/rpc/index.d.ts +3 -1
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/rpc/index.js +1 -3
- package/dist/src/rpc/index.js.map +1 -1
- package/dist/{switchboard-3vHbIV5W.js → switchboard-DAvOdf_g.js} +8 -6
- package/dist/switchboard-DAvOdf_g.js.map +1 -0
- package/package.json +10 -10
- package/dist/client-Cq5avLW5.js.map +0 -1
- package/dist/dispatch-C1VVTn5S.js.map +0 -1
- package/dist/document-model-modules-Gsh1Xr7j.js.map +0 -1
- package/dist/document-operations-BSzcF0mu.js.map +0 -1
- package/dist/global-BuSwbbY0.d.ts.map +0 -1
- package/dist/make-ph-event-functions-CdsvEl5t.js +0 -55
- package/dist/make-ph-event-functions-CdsvEl5t.js.map +0 -1
- package/dist/switchboard-3vHbIV5W.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"global-BuSwbbY0.d.ts","names":[],"sources":["../src/types/documents.ts","../src/types/reactor-browser-client.ts","../src/types/config.ts","../src/types/modals.ts","../src/types/package-discovery.ts","../src/types/timeline.ts","../src/types/toast.ts","../src/types/vetra.ts","../src/hooks/node-drag-and-drop.ts","../src/types/global.ts"],"mappings":";;;;;;;;;;;;;KAOY,iBAAiB,gBAA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;EAC3C,oBAAoB;EACpB,iBAAiB;;;;;;;EAOjB;IAA6B;IAAc;;EAC3C,kBACE,cACA,eAAe,kBACf;;;;KCzBQ;EACV;EACA;;cAMW;iBAiDG,YAAY;EAC1B;EACA;;;;eAFc;aAAA;;iBA6EA,YAAY;;;;;;;;;UC1HX,6BAA6B;EAC5C,IAAI;;UAEW,mCAAmC;EAClD;EACA,eAAe;;KAKL,sBAAsB;UACjB,kCAAkC;EACjD;EACA,eAAe;EACf,aAAa;EACb,WAAW;;;;;;EAMX,mBAAmB,SAAS,0BAA0B;;KAG5C;KAEA,WAAW;EACrB;EACA,sBAAsB,6BAA6B;EACnD,gBAAgB;;EAEhB,oBAAoB;EACpB,oBAAoB;EACpB,uBAAuB;EACvB,SAAS,UAAU;EACnB,sBAAsB;EACtB,SAAS;EACT,gBAAgB;EAChB;EACA;EACA,eAAe;EACf,QAAQ;EACR;EACA;EACA,uBAAuB;EACvB,0BAA0B;EAC1B,WAAW;EACX,QAAQ;;KAGE,oBAAoB;KACpB,gBAAgB,SAAS;KAEzB,iBAAiB,eAAe,uBACxC;KAGQ,iBAAiB,eAAe,kBAC1C,OAAO;KAGG;KAEA,6BAA6B,OACvC,aACA;KAGU,SAAS,aAAa,eAAe,eAC9C,OAAO,OAAO,SAAS;QAGlB;YACI;IACR,KAAK;;YAEG,uBAAuB"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { capitalCase } from "change-case";
|
|
2
|
-
import { useSyncExternalStore } from "react";
|
|
3
|
-
//#region src/hooks/make-ph-event-functions.ts
|
|
4
|
-
const isServer = typeof window === "undefined";
|
|
5
|
-
function makePHEventFunctions(key) {
|
|
6
|
-
const setEventName = `ph:set${capitalCase(key)}`;
|
|
7
|
-
const updateEventName = `ph:${key}Updated`;
|
|
8
|
-
function setValue(value) {
|
|
9
|
-
if (isServer) return;
|
|
10
|
-
const event = new CustomEvent(setEventName, { detail: { [key]: value } });
|
|
11
|
-
window.dispatchEvent(event);
|
|
12
|
-
}
|
|
13
|
-
function dispatchUpdatedEvent() {
|
|
14
|
-
if (isServer) return;
|
|
15
|
-
const event = new CustomEvent(updateEventName);
|
|
16
|
-
window.dispatchEvent(event);
|
|
17
|
-
}
|
|
18
|
-
function handleSetValueEvent(event) {
|
|
19
|
-
if (isServer) return;
|
|
20
|
-
const value = event.detail[key];
|
|
21
|
-
if (!window.ph) window.ph = {};
|
|
22
|
-
window.ph[key] = value;
|
|
23
|
-
dispatchUpdatedEvent();
|
|
24
|
-
}
|
|
25
|
-
function addEventHandler() {
|
|
26
|
-
if (isServer) return;
|
|
27
|
-
window.addEventListener(setEventName, handleSetValueEvent);
|
|
28
|
-
}
|
|
29
|
-
function subscribeToValue(onStoreChange) {
|
|
30
|
-
if (isServer) return () => {};
|
|
31
|
-
window.addEventListener(updateEventName, onStoreChange);
|
|
32
|
-
return () => {
|
|
33
|
-
window.removeEventListener(updateEventName, onStoreChange);
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function getSnapshot() {
|
|
37
|
-
if (isServer) return;
|
|
38
|
-
return window.ph?.[key];
|
|
39
|
-
}
|
|
40
|
-
function getServerSnapshot() {}
|
|
41
|
-
function useValue() {
|
|
42
|
-
return useSyncExternalStore(subscribeToValue, getSnapshot, getServerSnapshot);
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
useValue,
|
|
46
|
-
setValue,
|
|
47
|
-
addEventHandler,
|
|
48
|
-
subscribeToValue,
|
|
49
|
-
getSnapshot
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
//#endregion
|
|
53
|
-
export { makePHEventFunctions as t };
|
|
54
|
-
|
|
55
|
-
//# sourceMappingURL=make-ph-event-functions-CdsvEl5t.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"make-ph-event-functions-CdsvEl5t.js","names":[],"sources":["../src/hooks/make-ph-event-functions.ts"],"sourcesContent":["import type {\n PHGlobal,\n PHGlobalKey,\n SetEvent,\n} from \"@powerhousedao/reactor-browser\";\nimport { capitalCase } from \"change-case\";\nimport { useSyncExternalStore } from \"react\";\n\n// guard condition for server side rendering\nconst isServer = typeof window === \"undefined\";\n\nexport function makePHEventFunctions<TKey extends PHGlobalKey>(key: TKey) {\n const setEventName = `ph:set${capitalCase(key)}` as const;\n const updateEventName = `ph:${key}Updated` as const;\n\n function setValue(value: PHGlobal[TKey] | undefined) {\n if (isServer) {\n return;\n }\n const event = new CustomEvent(setEventName, {\n detail: { [key]: value },\n });\n window.dispatchEvent(event);\n }\n\n function dispatchUpdatedEvent() {\n if (isServer) {\n return;\n }\n const event = new CustomEvent(updateEventName);\n window.dispatchEvent(event);\n }\n\n function handleSetValueEvent(event: SetEvent<TKey>) {\n if (isServer) {\n return;\n }\n const value = event.detail[key];\n if (!window.ph) {\n window.ph = {};\n }\n window.ph[key] = value;\n dispatchUpdatedEvent();\n }\n\n function addEventHandler() {\n if (isServer) {\n return;\n }\n window.addEventListener(setEventName, handleSetValueEvent as EventListener);\n }\n\n function subscribeToValue(onStoreChange: () => void) {\n if (isServer) return () => {};\n window.addEventListener(updateEventName, onStoreChange);\n return () => {\n window.removeEventListener(updateEventName, onStoreChange);\n };\n }\n\n function getSnapshot() {\n if (isServer) {\n return undefined;\n }\n // The store is legitimately read before the first `setValue` (subscribers\n // mount before init runs), so an uninitialized store is expected, not an\n // error — return `undefined` quietly rather than warning on every render.\n return window.ph?.[key];\n }\n\n function getServerSnapshot() {\n return undefined;\n }\n\n function useValue() {\n return useSyncExternalStore(\n subscribeToValue,\n getSnapshot,\n getServerSnapshot,\n );\n }\n\n return {\n useValue,\n setValue,\n addEventHandler,\n // Non-react access: plain code (e.g. the worker wiring in Connect's boot)\n // subscribes to value updates and reads the current snapshot without a\n // render loop.\n subscribeToValue,\n getSnapshot,\n };\n}\n"],"mappings":";;;AASA,MAAM,WAAW,OAAO,WAAW;AAEnC,SAAgB,qBAA+C,KAAW;CACxE,MAAM,eAAe,SAAS,YAAY,GAAG;CAC7C,MAAM,kBAAkB,MAAM,IAAI;CAElC,SAAS,SAAS,OAAmC;EACnD,IAAI,UACF;EAEF,MAAM,QAAQ,IAAI,YAAY,cAAc,EAC1C,QAAQ,GAAG,MAAM,MAAM,EACzB,CAAC;EACD,OAAO,cAAc,KAAK;CAC5B;CAEA,SAAS,uBAAuB;EAC9B,IAAI,UACF;EAEF,MAAM,QAAQ,IAAI,YAAY,eAAe;EAC7C,OAAO,cAAc,KAAK;CAC5B;CAEA,SAAS,oBAAoB,OAAuB;EAClD,IAAI,UACF;EAEF,MAAM,QAAQ,MAAM,OAAO;EAC3B,IAAI,CAAC,OAAO,IACV,OAAO,KAAK,CAAC;EAEf,OAAO,GAAG,OAAO;EACjB,qBAAqB;CACvB;CAEA,SAAS,kBAAkB;EACzB,IAAI,UACF;EAEF,OAAO,iBAAiB,cAAc,mBAAoC;CAC5E;CAEA,SAAS,iBAAiB,eAA2B;EACnD,IAAI,UAAU,aAAa,CAAC;EAC5B,OAAO,iBAAiB,iBAAiB,aAAa;EACtD,aAAa;GACX,OAAO,oBAAoB,iBAAiB,aAAa;EAC3D;CACF;CAEA,SAAS,cAAc;EACrB,IAAI,UACF;EAKF,OAAO,OAAO,KAAK;CACrB;CAEA,SAAS,oBAAoB,CAE7B;CAEA,SAAS,WAAW;EAClB,OAAO,qBACL,kBACA,aACA,iBACF;CACF;CAEA,OAAO;EACL;EACA;EACA;EAIA;EACA;CACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"switchboard-3vHbIV5W.js","names":[],"sources":["../src/utils/nodes.ts","../src/hooks/items-in-selected-drive.ts","../src/hooks/selected-node.ts","../src/hooks/document-of-type.ts","../src/hooks/selected-document.ts","../src/ai/switchboard.ts"],"sourcesContent":["import type {\n FileNode,\n FolderNode,\n Node,\n} from \"@powerhousedao/shared/document-drive\";\n\n/** Sorts nodes by name. */\nexport function sortNodesByName<T extends Node>(nodes: T[]) {\n return nodes.toSorted((a, b) => a.name.localeCompare(b.name));\n}\n\n/** Returns whether a node is a file. */\nexport function isFileNodeKind(\n node: Node | null | undefined,\n): node is FileNode {\n if (!node) return false;\n return node.kind.toUpperCase() === \"FILE\";\n}\n\n/** Returns whether a node is a folder. */\nexport function isFolderNodeKind(\n node: Node | null | undefined,\n): node is FolderNode {\n if (!node) return false;\n return node.kind.toUpperCase() === \"FOLDER\";\n}\n","import type {\n FileNode,\n FolderNode,\n} from \"@powerhousedao/shared/document-drive\";\nimport type {\n DocumentModelDocument,\n PHDocument,\n} from \"@powerhousedao/shared/document-model\";\nimport { isFileNodeKind, isFolderNodeKind } from \"../utils/nodes.js\";\nimport { useDocumentsByIds } from \"./document-by-id.js\";\nimport { useSelectedDriveSafe } from \"./selected-drive.js\";\n\n/** Returns the nodes in the selected drive. */\nexport function useNodesInSelectedDrive() {\n const [selectedDrive] = useSelectedDriveSafe();\n return selectedDrive?.state.global.nodes;\n}\n\n/** Returns the file nodes in the selected drive. */\nexport function useFileNodesInSelectedDrive(): FileNode[] | undefined {\n const nodes = useNodesInSelectedDrive();\n return nodes?.filter((n) => isFileNodeKind(n));\n}\n\n/** Returns the folder nodes in the selected drive. */\nexport function useFolderNodesInSelectedDrive(): FolderNode[] | undefined {\n const nodes = useNodesInSelectedDrive();\n return nodes?.filter((n) => isFolderNodeKind(n));\n}\n\n/** Returns the documents in the selected drive. */\nexport function useDocumentsInSelectedDrive(): PHDocument[] | undefined {\n const fileNodes = useFileNodesInSelectedDrive();\n const fileNodeIds = fileNodes?.map((node) => node.id);\n return useDocumentsByIds(fileNodeIds);\n}\n\n/** Returns the document types supported by the selected drive, as defined by the document model documents present in the drive */\nexport function useDocumentTypesInSelectedDrive() {\n const documentsInSelectedDrive = useDocumentsInSelectedDrive();\n const documentModelDocumentsInSelectedDrive =\n documentsInSelectedDrive?.filter(isDocumentModelDocument);\n const documentTypesFromDocumentModelDocuments =\n documentModelDocumentsInSelectedDrive?.map((doc) => doc.state.global.id);\n return documentTypesFromDocumentModelDocuments;\n}\n\nfunction isDocumentModelDocument(\n document: PHDocument,\n): document is DocumentModelDocument {\n return document.header.documentType === \"powerhouse/document-model\";\n}\n","import type { Node } from \"@powerhousedao/shared/document-drive\";\nimport { useNodesInSelectedDrive } from \"./items-in-selected-drive.js\";\nimport { useSelectedNodeId } from \"./set-selected-node.js\";\n\nexport {\n addResetSelectedNodeEventHandler,\n addSelectedNodeIdEventHandler,\n addSetSelectedNodeOnPopStateEventHandler,\n setSelectedNode,\n} from \"./set-selected-node.js\";\n\n/** Returns the selected node. */\nexport function useSelectedNode(): Node | undefined {\n const selectedNodeId = useSelectedNodeId();\n const nodes = useNodesInSelectedDrive();\n return nodes?.find((n) => n.id === selectedNodeId);\n}\n","import { ModuleNotFoundError } from \"@powerhousedao/reactor\";\nimport type { DocumentDispatch } from \"@powerhousedao/reactor-browser\";\nimport type { Action, PHDocument } from \"@powerhousedao/shared/document-model\";\nimport { DocumentTypeMismatchError } from \"../errors.js\";\nimport { useDocumentById } from \"./document-by-id.js\";\nimport { useDocumentModelModuleById } from \"./document-model-modules.js\";\n\n/** Returns a document of a specific type, throws an error if the found document has a different type */\nexport function useDocumentOfType<\n TDocument extends PHDocument,\n TAction extends Action,\n>(\n documentId: string | null | undefined,\n documentType: string | null | undefined,\n) {\n const [document, dispatch] = useDocumentById(documentId);\n const documentModelModule = useDocumentModelModuleById(documentType);\n\n if (!documentId || !documentType) return [];\n\n if (!document) {\n throw new Error(`Document not found: ${documentId}`);\n }\n if (!documentModelModule) {\n throw new ModuleNotFoundError(documentType);\n }\n\n if (document.header.documentType !== documentType) {\n throw new DocumentTypeMismatchError(\n documentId,\n documentType,\n document.header.documentType,\n );\n }\n\n return [document, dispatch] as [TDocument, DocumentDispatch<TAction>];\n}\n","import type { DocumentDispatch } from \"@powerhousedao/reactor-browser\";\nimport { isFileNode } from \"@powerhousedao/shared/document-drive\";\nimport type { Action, PHDocument } from \"@powerhousedao/shared/document-model\";\nimport { NoSelectedDocumentError } from \"../errors.js\";\nimport type { DispatchFn, UseDispatchResult } from \"./dispatch.js\";\nimport { useDocumentById } from \"./document-by-id.js\";\nimport { useDocumentOfType } from \"./document-of-type.js\";\nimport { useSelectedNode } from \"./selected-node.js\";\n\n/** Returns the selected document id */\nexport function useSelectedDocumentId(): string | undefined {\n const selectedNode = useSelectedNode();\n return selectedNode && isFileNode(selectedNode) ? selectedNode.id : undefined;\n}\n\n/** Returns the selected document. */\nexport function useSelectedDocument(): readonly [\n PHDocument,\n DispatchFn<Action>,\n] {\n const selectedDocumentId = useSelectedDocumentId();\n const [document, dispatch] = useDocumentById(selectedDocumentId);\n if (!document) {\n throw new NoSelectedDocumentError();\n }\n return [document, dispatch] as const;\n}\n\n/** Returns the selected document. */\nexport function useSelectedDocumentSafe(): UseDispatchResult<\n PHDocument,\n Action\n> {\n const selectedDocumentId = useSelectedDocumentId();\n return useDocumentById(selectedDocumentId);\n}\n\n/** Returns the selected document of a specific type, throws an error if the found document has a different type */\nexport function useSelectedDocumentOfType(\n documentType: null | undefined,\n): never[];\nexport function useSelectedDocumentOfType<\n TDocument extends PHDocument,\n TAction extends Action,\n>(documentType: string): [TDocument, DocumentDispatch<TAction>];\nexport function useSelectedDocumentOfType<\n TDocument extends PHDocument,\n TAction extends Action,\n>(\n documentType: string | null | undefined,\n): never[] | [TDocument, DocumentDispatch<TAction>] {\n const documentId = useSelectedDocumentId();\n\n if (!documentType) {\n return [];\n }\n if (!documentId) {\n throw new NoSelectedDocumentError();\n }\n return useDocumentOfType<TDocument, TAction>(documentId, documentType);\n}\n","import { DriveCollectionId, type ISyncManager } from \"@powerhousedao/reactor\";\nimport { z } from \"zod\";\nimport { ambientRenownTokenProvider } from \"../graphql-client/auth.js\";\nimport type { AiToolDescriptor } from \"./types.js\";\n\n/**\n * The switchboard serving a remote drive: the base URL the browser talks to\n * and its GraphQL supergraph endpoint.\n */\nexport interface DriveSwitchboard {\n /** Switchboard base URL (e.g. `http://localhost:4001`). */\n switchboardUrl: string;\n /** GraphQL supergraph endpoint (`<base>/graphql`). */\n graphqlUrl: string;\n}\n\n/**\n * Reads the tab-side sync manager from the browser global. Returns\n * `undefined` in non-browser environments or before the reactor client\n * module is initialized.\n */\nexport function getBrowserSyncManager(): ISyncManager | undefined {\n if (typeof window === \"undefined\") {\n return undefined;\n }\n return window.ph?.reactorClientModule?.reactorModule?.syncModule?.syncManager;\n}\n\n/** Suffix of the per-drive GraphQL channel endpoint the switchboard serves. */\nexport const GQL_CHANNEL_SUFFIX = \"/graphql/r\";\n\n/**\n * Resolves the switchboard that serves a drive, if any.\n *\n * Every remote drive stores its switchboard's exact GraphQL channel\n * endpoint in its sync remote — `channelConfig = { type: \"gql\",\n * parameters: { url: \"<origin>/graphql/r\" } }` — and the switchboard base\n * is that URL minus the `/graphql/r` suffix. Deriving it per drive (rather\n * than from a global setting) is what keeps multi-switchboard deployments\n * correct. Drives that are not synced to a remote switchboard (local\n * drives, other channel types, unexpected shapes) return `undefined`.\n */\nexport function resolveDriveSwitchboard(\n driveId: string | undefined,\n syncManager?: ISyncManager,\n): DriveSwitchboard | undefined {\n const manager = syncManager ?? getBrowserSyncManager();\n if (!driveId || !manager) {\n return undefined;\n }\n const collectionId = DriveCollectionId.forDrive(driveId);\n const remote = manager\n .list()\n .find((r) => r.meta.collectionId.equals(collectionId));\n if (!remote) {\n return undefined;\n }\n const { channelConfig } = remote.meta;\n if (channelConfig.type !== \"gql\") {\n return undefined;\n }\n const url = channelConfig.parameters.url;\n if (typeof url !== \"string\" || !url.endsWith(GQL_CHANNEL_SUFFIX)) {\n return undefined;\n }\n const switchboardUrl = url.slice(0, -GQL_CHANNEL_SUFFIX.length);\n return { switchboardUrl, graphqlUrl: `${switchboardUrl}/graphql` };\n}\n\n/** A bounded introspected GraphQL type reference (see the query below). */\ntype IntrospectedTypeRef = {\n kind: string;\n name: string | null;\n ofType?: IntrospectedTypeRef | null;\n};\n\ntype IntrospectedField = {\n name: string;\n description: string | null;\n args: Array<{ name: string; type: IntrospectedTypeRef }>;\n type: IntrospectedTypeRef;\n};\n\ntype IntrospectedRootType = {\n fields: IntrospectedField[] | null;\n} | null;\n\ntype IntrospectedSchema = {\n queryType?: IntrospectedRootType;\n mutationType?: IntrospectedRootType;\n};\n\n/**\n * Introspection over the switchboard supergraph's root query and mutation\n * fields. Types are requested with three levels of `ofType` nesting so\n * that common shapes like `[X!]!` (LIST(NON_NULL(LIST(X)))) render fully.\n */\nexport const SWITCHBOARD_INTROSPECTION_QUERY: string = /* GraphQL */ `\n query SwitchboardIntrospection {\n __schema {\n queryType {\n fields {\n name\n description\n args {\n name\n type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n mutationType {\n fields {\n name\n description\n args {\n name\n type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n }\n`;\n\n/**\n * Renders an introspected type reference as a GraphQL type string.\n * Recursion is bounded by the `ofType` nesting of the query, so it always\n * terminates.\n */\nfunction renderTypeRef(type: IntrospectedTypeRef | null | undefined): string {\n if (!type) {\n return \"Unknown\";\n }\n switch (type.kind) {\n case \"NON_NULL\":\n return `${renderTypeRef(type.ofType)}!`;\n case \"LIST\":\n return `[${renderTypeRef(type.ofType)}]`;\n default:\n return type.name ?? \"Unknown\";\n }\n}\n\n/** One root query or mutation field, reduced to a prompt-friendly line. */\nexport type SchemaFieldSummary = {\n name: string;\n description?: string;\n args: string;\n returns: string;\n};\n\n/** Cap on the number of fields reported per root type. */\nconst MAX_FIELDS_PER_ROOT = 200;\n\nfunction summarizeFields(fields: IntrospectedField[] | null | undefined): {\n fields: SchemaFieldSummary[];\n truncated: boolean;\n} {\n const list = fields ?? [];\n return {\n fields: list.slice(0, MAX_FIELDS_PER_ROOT).map((field) => ({\n name: field.name,\n ...(field.description ? { description: field.description } : {}),\n args: field.args\n .map((arg) => `${arg.name}: ${renderTypeRef(arg.type)}`)\n .join(\", \"),\n returns: renderTypeRef(field.type),\n })),\n truncated: list.length > MAX_FIELDS_PER_ROOT,\n };\n}\n\n/**\n * Reduces a GraphQL `__schema` introspection payload (the `data.__schema`\n * object) to a compact summary of its root query and mutation fields.\n * Accepts `unknown` because the payload arrives over the wire.\n */\nexport function summarizeIntrospectionSchema(schema: unknown): {\n queries: SchemaFieldSummary[];\n mutations: SchemaFieldSummary[];\n truncated: boolean;\n} {\n const introspection = (schema ?? {}) as IntrospectedSchema;\n const queries = summarizeFields(introspection.queryType?.fields);\n const mutations = summarizeFields(introspection.mutationType?.fields);\n return {\n queries: queries.fields,\n mutations: mutations.fields,\n truncated: queries.truncated || mutations.truncated,\n };\n}\n\nexport const SWITCHBOARD_SCHEMA_TOOL_NAME = \"getSwitchboardSchema\";\n\n/** Test seams for {@link createSwitchboardSchemaTool}. */\nexport interface SwitchboardToolDeps {\n getSyncManager?: () => ISyncManager | undefined;\n getSelectedDriveId?: () => string | undefined;\n tokenProvider?: () => Promise<string | undefined>;\n fetchImpl?: typeof fetch;\n timeoutMs?: number;\n}\n\n/**\n * Creates the read-only `getSwitchboardSchema` tool: it introspects the\n * GraphQL supergraph of the switchboard serving a drive and returns a\n * summary of its root queries and mutations. It reads the schema only and\n * never modifies data.\n */\nexport function createSwitchboardSchemaTool(\n deps?: SwitchboardToolDeps,\n): AiToolDescriptor {\n const getSyncManager = deps?.getSyncManager ?? getBrowserSyncManager;\n const getSelectedDriveId =\n deps?.getSelectedDriveId ??\n ((): string | undefined =>\n typeof window === \"undefined\" ? undefined : window.ph?.selectedDriveId);\n const tokenProvider = deps?.tokenProvider ?? ambientRenownTokenProvider;\n const fetchImpl = deps?.fetchImpl ?? fetch;\n const timeoutMs = deps?.timeoutMs ?? 10_000;\n\n return {\n name: SWITCHBOARD_SCHEMA_TOOL_NAME,\n description:\n \"Introspect the GraphQL endpoint of the switchboard serving a drive and list the queries and mutations it exposes (reactor operations, document-model read models, package subgraphs). Read-only: it reads the schema only and never modifies data. Omit driveId to introspect the currently selected drive.\",\n inputSchema: {\n driveId: z\n .string()\n .describe(\n \"Drive to introspect. Omit to use the currently selected drive.\",\n )\n .optional(),\n },\n annotations: { readOnlyHint: true },\n callback: async (input: { driveId?: string } | undefined) => {\n const driveId = input?.driveId ?? getSelectedDriveId();\n const sb = resolveDriveSwitchboard(driveId, getSyncManager());\n if (!sb) {\n throw new Error(\n driveId\n ? `Drive \"${driveId}\" has no switchboard: it is not synced to a remote switchboard.`\n : \"No drive is currently selected and no driveId was given.\",\n );\n }\n\n const token = await tokenProvider();\n let response: Response;\n try {\n response = await fetchImpl(sb.graphqlUrl, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n ...(token ? { authorization: `Bearer ${token}` } : {}),\n },\n body: JSON.stringify({ query: SWITCHBOARD_INTROSPECTION_QUERY }),\n signal: AbortSignal.timeout(timeoutMs),\n });\n } catch (error) {\n throw new Error(\n `Switchboard at ${sb.graphqlUrl} is not reachable: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { cause: error },\n );\n }\n\n if (response.status === 401 || response.status === 403) {\n throw new Error(\n `Switchboard at ${sb.graphqlUrl} refused the request (HTTP ${response.status}). Sign in to the switchboard (Renown) and try again.`,\n );\n }\n if (!response.ok) {\n throw new Error(\n `Switchboard introspection failed: HTTP ${response.status} ${response.statusText} from ${sb.graphqlUrl}`,\n );\n }\n\n const body = (await response.json()) as {\n errors?: Array<{ message?: string }>;\n data?: { __schema?: unknown } | null;\n } | null;\n const schemaErrors = body?.errors;\n if (schemaErrors && schemaErrors.length > 0) {\n throw new Error(\n schemaErrors.map((e) => e.message ?? \"unknown error\").join(\"; \"),\n );\n }\n const schema = body?.data?.__schema as\n | IntrospectedSchema\n | null\n | undefined;\n if (!schema?.queryType) {\n throw new Error(\n `Switchboard at ${sb.graphqlUrl} did not return a GraphQL schema.`,\n );\n }\n\n const summary = summarizeIntrospectionSchema(schema);\n return {\n switchboardUrl: sb.switchboardUrl,\n graphqlUrl: sb.graphqlUrl,\n ...summary,\n };\n },\n };\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,gBAAgC,OAAY;CAC1D,OAAO,MAAM,UAAU,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC;AAC9D;;AAGA,SAAgB,eACd,MACkB;CAClB,IAAI,CAAC,MAAM,OAAO;CAClB,OAAO,KAAK,KAAK,YAAY,MAAM;AACrC;;AAGA,SAAgB,iBACd,MACoB;CACpB,IAAI,CAAC,MAAM,OAAO;CAClB,OAAO,KAAK,KAAK,YAAY,MAAM;AACrC;;;;ACZA,SAAgB,0BAA0B;CACxC,MAAM,CAAC,iBAAiB,qBAAqB;CAC7C,OAAO,eAAe,MAAM,OAAO;AACrC;;AAGA,SAAgB,8BAAsD;CAEpE,OADc,wBACH,CAAC,EAAE,QAAQ,MAAM,eAAe,CAAC,CAAC;AAC/C;;AAGA,SAAgB,gCAA0D;CAExE,OADc,wBACH,CAAC,EAAE,QAAQ,MAAM,iBAAiB,CAAC,CAAC;AACjD;;AAGA,SAAgB,8BAAwD;CAEtE,MAAM,cADY,4BACU,CAAC,EAAE,KAAK,SAAS,KAAK,EAAE;CACpD,OAAO,kBAAkB,WAAW;AACtC;;AAGA,SAAgB,kCAAkC;CAMhD,QALiC,4BAER,CAAC,EAAE,OAAO,uBAAuB,EAAA,EAEjB,KAAK,QAAQ,IAAI,MAAM,OAAO,EAAE;AAE3E;AAEA,SAAS,wBACP,UACmC;CACnC,OAAO,SAAS,OAAO,iBAAiB;AAC1C;;;;ACvCA,SAAgB,kBAAoC;CAClD,MAAM,iBAAiB,kBAAkB;CAEzC,OADc,wBACH,CAAC,EAAE,MAAM,MAAM,EAAE,OAAO,cAAc;AACnD;;;;ACRA,SAAgB,kBAId,YACA,cACA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