@wonderwhy-er/desktop-commander 0.2.37 → 0.2.39
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 +290 -100
- package/dist/command-manager.js +6 -3
- package/dist/config-field-definitions.d.ts +41 -0
- package/dist/config-field-definitions.js +37 -0
- package/dist/config-manager.d.ts +2 -0
- package/dist/config-manager.js +22 -2
- package/dist/handlers/filesystem-handlers.d.ts +5 -0
- package/dist/handlers/filesystem-handlers.js +19 -12
- package/dist/remote-device/desktop-commander-integration.js +1 -1
- package/dist/remote-device/remote-channel.js +1 -1
- package/dist/search-manager.js +31 -38
- package/dist/server.js +11 -4
- package/dist/terminal-manager.js +4 -2
- package/dist/tools/config.d.ts +71 -0
- package/dist/tools/config.js +117 -2
- package/dist/tools/edit.js +34 -1
- package/dist/tools/filesystem.js +91 -3
- package/dist/tools/improved-process-tools.js +2 -1
- package/dist/tools/schemas.d.ts +3 -0
- package/dist/tools/schemas.js +1 -0
- package/dist/types.d.ts +0 -1
- package/dist/ui/config-editor/app.d.ts +43 -0
- package/dist/ui/config-editor/app.js +840 -0
- package/dist/ui/config-editor/array-modal.d.ts +19 -0
- package/dist/ui/config-editor/array-modal.js +185 -0
- package/dist/ui/config-editor/config-editor-runtime.js +150 -0
- package/dist/ui/config-editor/index.html +13 -0
- package/dist/ui/config-editor/main.js +2 -0
- package/dist/ui/config-editor/src/App.d.ts +43 -0
- package/dist/ui/config-editor/src/App.js +840 -0
- package/dist/ui/config-editor/src/array-modal.d.ts +19 -0
- package/dist/ui/config-editor/src/array-modal.js +185 -0
- package/dist/ui/config-editor/src/components/layout.d.ts +4 -0
- package/dist/ui/config-editor/src/components/layout.js +83 -0
- package/dist/ui/config-editor/src/components/toolbar.d.ts +1 -0
- package/dist/ui/config-editor/src/components/toolbar.js +21 -0
- package/dist/ui/config-editor/src/config-values.d.ts +6 -0
- package/dist/ui/config-editor/src/config-values.js +61 -0
- package/dist/ui/config-editor/src/contracts.d.ts +14 -0
- package/dist/ui/config-editor/src/contracts.js +3 -0
- package/dist/ui/config-editor/src/directory-browser.d.ts +6 -0
- package/dist/ui/config-editor/src/directory-browser.js +71 -0
- package/dist/ui/config-editor/src/layout.d.ts +5 -0
- package/dist/ui/config-editor/src/layout.js +90 -0
- package/dist/ui/config-editor/src/main.js +2 -0
- package/dist/ui/config-editor/src/parsing.d.ts +5 -0
- package/dist/ui/config-editor/src/parsing.js +50 -0
- package/dist/ui/config-editor/src/toolbar.d.ts +1 -0
- package/dist/ui/config-editor/src/toolbar.js +18 -0
- package/dist/ui/config-editor/src/types.d.ts +17 -0
- package/dist/ui/config-editor/src/types.js +3 -0
- package/dist/ui/config-editor/src/utils/config-values.d.ts +9 -0
- package/dist/ui/config-editor/src/utils/config-values.js +61 -0
- package/dist/ui/config-editor/src/utils/directory-browser.d.ts +31 -0
- package/dist/ui/config-editor/src/utils/directory-browser.js +201 -0
- package/dist/ui/config-editor/src/utils/parsing.d.ts +8 -0
- package/dist/ui/config-editor/src/utils/parsing.js +50 -0
- package/dist/ui/config-editor/styles.css +587 -0
- package/dist/ui/file-preview/app.d.ts +8 -0
- package/dist/ui/file-preview/app.js +2020 -0
- package/dist/ui/file-preview/components/code-viewer.d.ts +6 -0
- package/dist/ui/file-preview/components/code-viewer.js +73 -0
- package/dist/ui/file-preview/components/highlighting.d.ts +2 -0
- package/dist/ui/file-preview/components/highlighting.js +54 -0
- package/dist/ui/file-preview/components/html-renderer.d.ts +5 -0
- package/dist/ui/file-preview/components/html-renderer.js +47 -0
- package/dist/ui/file-preview/components/markdown-renderer.d.ts +1 -0
- package/dist/ui/file-preview/components/markdown-renderer.js +67 -0
- package/dist/ui/file-preview/components/toolbar.d.ts +6 -0
- package/dist/ui/file-preview/components/toolbar.js +75 -0
- package/dist/ui/file-preview/image-preview.d.ts +3 -0
- package/dist/ui/file-preview/image-preview.js +21 -0
- package/dist/ui/file-preview/main.js +5 -0
- package/dist/ui/file-preview/markdown/editor.d.ts +36 -0
- package/dist/ui/file-preview/markdown/editor.js +643 -0
- package/dist/ui/file-preview/markdown/linking.d.ts +9 -0
- package/dist/ui/file-preview/markdown/linking.js +210 -0
- package/dist/ui/file-preview/markdown/outline.d.ts +7 -0
- package/dist/ui/file-preview/markdown/outline.js +40 -0
- package/dist/ui/file-preview/markdown/preview.d.ts +8 -0
- package/dist/ui/file-preview/markdown/preview.js +33 -0
- package/dist/ui/file-preview/markdown/slugify.d.ts +3 -0
- package/dist/ui/file-preview/markdown/slugify.js +31 -0
- package/dist/ui/file-preview/markdown/toc.d.ts +11 -0
- package/dist/ui/file-preview/markdown/toc.js +75 -0
- package/dist/ui/file-preview/markdown/utils.d.ts +1 -0
- package/dist/ui/file-preview/markdown/utils.js +15 -0
- package/dist/ui/file-preview/markdown/workspace-controller.d.ts +25 -0
- package/dist/ui/file-preview/markdown/workspace-controller.js +40 -0
- package/dist/ui/file-preview/preview-runtime.js +399 -13969
- package/dist/ui/file-preview/shared/preview-file-types.d.ts +1 -1
- package/dist/ui/file-preview/shared/preview-file-types.js +3 -1
- package/dist/ui/file-preview/src/App.d.ts +4 -0
- package/dist/ui/file-preview/src/App.js +564 -0
- package/dist/ui/file-preview/src/components/CodeViewer.d.ts +6 -0
- package/dist/ui/file-preview/src/components/CodeViewer.js +60 -0
- package/dist/ui/file-preview/src/components/HtmlRenderer.d.ts +8 -0
- package/dist/ui/file-preview/src/components/HtmlRenderer.js +45 -0
- package/dist/ui/file-preview/src/components/MarkdownRenderer.d.ts +1 -0
- package/dist/ui/file-preview/src/components/MarkdownRenderer.js +15 -0
- package/dist/ui/file-preview/src/components/editor-toolbar.d.ts +15 -0
- package/dist/ui/file-preview/src/components/editor-toolbar.js +384 -0
- package/dist/ui/file-preview/src/components/html-renderer.d.ts +1 -5
- package/dist/ui/file-preview/src/components/html-renderer.js +11 -27
- package/dist/ui/file-preview/src/components/markdown-editor.d.ts +29 -0
- package/dist/ui/file-preview/src/components/markdown-editor.js +535 -0
- package/dist/ui/file-preview/src/components/markdown-renderer.js +47 -9
- package/dist/ui/file-preview/src/directory-controller.d.ts +8 -0
- package/dist/ui/file-preview/src/directory-controller.js +233 -0
- package/dist/ui/file-preview/src/document-layout.d.ts +20 -0
- package/dist/ui/file-preview/src/document-layout.js +109 -0
- package/dist/ui/file-preview/src/document-outline.d.ts +17 -0
- package/dist/ui/file-preview/src/document-outline.js +97 -0
- package/dist/ui/file-preview/src/document-workspace.d.ts +19 -0
- package/dist/ui/file-preview/src/document-workspace.js +33 -0
- package/dist/ui/file-preview/src/file-type-handlers.d.ts +10 -0
- package/dist/ui/file-preview/src/file-type-handlers.js +98 -0
- package/dist/ui/file-preview/src/host/external-actions.d.ts +19 -0
- package/dist/ui/file-preview/src/host/external-actions.js +94 -0
- package/dist/ui/file-preview/src/host/selection-context.d.ts +9 -0
- package/dist/ui/file-preview/src/host/selection-context.js +106 -0
- package/dist/ui/file-preview/src/markdown/block-merge.d.ts +25 -0
- package/dist/ui/file-preview/src/markdown/block-merge.js +86 -0
- package/dist/ui/file-preview/src/markdown/conflict-dialog.d.ts +40 -0
- package/dist/ui/file-preview/src/markdown/conflict-dialog.js +163 -0
- package/dist/ui/file-preview/src/markdown/controller.d.ts +38 -0
- package/dist/ui/file-preview/src/markdown/controller.js +921 -0
- package/dist/ui/file-preview/src/markdown/editor.d.ts +35 -0
- package/dist/ui/file-preview/src/markdown/editor.js +691 -0
- package/dist/ui/file-preview/src/markdown/link-modal.d.ts +13 -0
- package/dist/ui/file-preview/src/markdown/link-modal.js +213 -0
- package/dist/ui/file-preview/src/markdown/linking.d.ts +16 -0
- package/dist/ui/file-preview/src/markdown/linking.js +228 -0
- package/dist/ui/file-preview/src/markdown/outline.d.ts +2 -0
- package/dist/ui/file-preview/src/markdown/outline.js +16 -0
- package/dist/ui/file-preview/src/markdown/parser.d.ts +30 -0
- package/dist/ui/file-preview/src/markdown/parser.js +38 -0
- package/dist/ui/file-preview/src/markdown/preview.d.ts +1 -0
- package/dist/ui/file-preview/src/markdown/preview.js +20 -0
- package/dist/ui/file-preview/src/markdown/raw-editor.d.ts +8 -0
- package/dist/ui/file-preview/src/markdown/raw-editor.js +61 -0
- package/dist/ui/file-preview/src/markdown/selection-toolbar.d.ts +14 -0
- package/dist/ui/file-preview/src/markdown/selection-toolbar.js +128 -0
- package/dist/ui/file-preview/src/markdown/slugify.d.ts +3 -0
- package/dist/ui/file-preview/src/markdown/slugify.js +31 -0
- package/dist/ui/file-preview/src/markdown/toc.d.ts +11 -0
- package/dist/ui/file-preview/src/markdown/toc.js +75 -0
- package/dist/ui/file-preview/src/markdown/utils.d.ts +1 -0
- package/dist/ui/file-preview/src/markdown/utils.js +15 -0
- package/dist/ui/file-preview/src/markdown-workspace/editor.d.ts +36 -0
- package/dist/ui/file-preview/src/markdown-workspace/editor.js +643 -0
- package/dist/ui/file-preview/src/markdown-workspace/linking.d.ts +9 -0
- package/dist/ui/file-preview/src/markdown-workspace/linking.js +210 -0
- package/dist/ui/file-preview/src/markdown-workspace/outline.d.ts +7 -0
- package/dist/ui/file-preview/src/markdown-workspace/outline.js +40 -0
- package/dist/ui/file-preview/src/markdown-workspace/preview.d.ts +8 -0
- package/dist/ui/file-preview/src/markdown-workspace/preview.js +33 -0
- package/dist/ui/file-preview/src/markdown-workspace/slugify.d.ts +3 -0
- package/dist/ui/file-preview/src/markdown-workspace/slugify.js +31 -0
- package/dist/ui/file-preview/src/markdown-workspace/toc.d.ts +11 -0
- package/dist/ui/file-preview/src/markdown-workspace/toc.js +75 -0
- package/dist/ui/file-preview/src/markdown-workspace/utils.d.ts +1 -0
- package/dist/ui/file-preview/src/markdown-workspace/utils.js +15 -0
- package/dist/ui/file-preview/src/markdown-workspace/workspace-controller.d.ts +25 -0
- package/dist/ui/file-preview/src/markdown-workspace/workspace-controller.js +40 -0
- package/dist/ui/file-preview/src/model.d.ts +34 -0
- package/dist/ui/file-preview/src/panel-actions.d.ts +17 -0
- package/dist/ui/file-preview/src/panel-actions.js +182 -0
- package/dist/ui/file-preview/src/path-utils.d.ts +6 -0
- package/dist/ui/file-preview/src/path-utils.js +64 -0
- package/dist/ui/file-preview/src/payload-utils.d.ts +11 -0
- package/dist/ui/file-preview/src/payload-utils.js +94 -0
- package/dist/ui/file-preview/styles.css +1144 -277
- package/dist/ui/file-preview/types.d.ts +1 -0
- package/dist/ui/file-preview/types.js +1 -0
- package/dist/ui/resources.d.ts +7 -0
- package/dist/ui/resources.js +16 -2
- package/dist/ui/server-integration.d.ts +13 -0
- package/dist/ui/server-integration.js +31 -0
- package/dist/ui/shared/ToolHeader.d.ts +9 -0
- package/dist/ui/shared/ToolHeader.js +29 -0
- package/dist/ui/shared/app-bootstrap.d.ts +9 -0
- package/dist/ui/shared/app-bootstrap.js +15 -0
- package/dist/ui/shared/compact-row.d.ts +11 -0
- package/dist/ui/shared/compact-row.js +18 -0
- package/dist/ui/shared/guards.d.ts +1 -0
- package/dist/ui/shared/guards.js +3 -0
- package/dist/ui/shared/host-context.d.ts +15 -0
- package/dist/ui/shared/host-context.js +51 -0
- package/dist/ui/shared/host-lifecycle.d.ts +1 -0
- package/dist/ui/shared/host-lifecycle.js +8 -2
- package/dist/ui/shared/tool-bridge.d.ts +30 -0
- package/dist/ui/shared/tool-bridge.js +137 -0
- package/dist/ui/shared/tool-shell.d.ts +9 -0
- package/dist/ui/shared/tool-shell.js +46 -4
- package/dist/ui/shared/ui-event-tracker.d.ts +9 -0
- package/dist/ui/shared/ui-event-tracker.js +27 -0
- package/dist/ui/shared/widget-state.d.ts +6 -1
- package/dist/ui/shared/widget-state.js +102 -4
- package/dist/utils/capture.js +3 -3
- package/dist/utils/files/base.d.ts +2 -0
- package/dist/utils/open-browser.js +1 -1
- package/dist/utils/ui-call-context.d.ts +8 -0
- package/dist/utils/ui-call-context.js +72 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +13 -4
- package/dist/data/spec-kit-prompts.json +0 -123
- package/dist/handlers/node-handlers.d.ts +0 -6
- package/dist/handlers/node-handlers.js +0 -73
- package/dist/handlers/test-crash-handler.d.ts +0 -11
- package/dist/handlers/test-crash-handler.js +0 -26
- package/dist/http-index.d.ts +0 -45
- package/dist/http-index.js +0 -51
- package/dist/http-server-auto-tunnel.js +0 -667
- package/dist/http-server-named-tunnel.d.ts +0 -2
- package/dist/http-server-named-tunnel.js +0 -167
- package/dist/http-server-tunnel.d.ts +0 -2
- package/dist/http-server-tunnel.js +0 -111
- package/dist/http-server.d.ts +0 -2
- package/dist/http-server.js +0 -270
- package/dist/index-oauth.d.ts +0 -2
- package/dist/index-oauth.js +0 -201
- package/dist/oauth/auth-middleware.d.ts +0 -20
- package/dist/oauth/auth-middleware.js +0 -62
- package/dist/oauth/index.d.ts +0 -3
- package/dist/oauth/index.js +0 -3
- package/dist/oauth/oauth-manager.d.ts +0 -80
- package/dist/oauth/oauth-manager.js +0 -179
- package/dist/oauth/oauth-routes.d.ts +0 -3
- package/dist/oauth/oauth-routes.js +0 -377
- package/dist/oauth/provider.d.ts +0 -22
- package/dist/oauth/provider.js +0 -124
- package/dist/oauth/server.d.ts +0 -18
- package/dist/oauth/server.js +0 -160
- package/dist/oauth/types.d.ts +0 -54
- package/dist/oauth/types.js +0 -2
- package/dist/remote-device/templates/auth-success.d.ts +0 -1
- package/dist/remote-device/templates/auth-success.js +0 -30
- package/dist/setup.log +0 -275
- package/dist/test-setup.js +0 -14
- package/dist/tools/docx/builders/html-builder.d.ts +0 -17
- package/dist/tools/docx/builders/html-builder.js +0 -92
- package/dist/tools/docx/builders/image.d.ts +0 -14
- package/dist/tools/docx/builders/image.js +0 -84
- package/dist/tools/docx/builders/index.d.ts +0 -11
- package/dist/tools/docx/builders/index.js +0 -11
- package/dist/tools/docx/builders/markdown-builder.d.ts +0 -2
- package/dist/tools/docx/builders/markdown-builder.js +0 -260
- package/dist/tools/docx/builders/paragraph.d.ts +0 -12
- package/dist/tools/docx/builders/paragraph.js +0 -29
- package/dist/tools/docx/builders/table.d.ts +0 -10
- package/dist/tools/docx/builders/table.js +0 -138
- package/dist/tools/docx/builders/utils.d.ts +0 -5
- package/dist/tools/docx/builders/utils.js +0 -18
- package/dist/tools/docx/constants.d.ts +0 -32
- package/dist/tools/docx/constants.js +0 -61
- package/dist/tools/docx/converters/markdown-to-html.d.ts +0 -17
- package/dist/tools/docx/converters/markdown-to-html.js +0 -111
- package/dist/tools/docx/create.d.ts +0 -21
- package/dist/tools/docx/create.js +0 -386
- package/dist/tools/docx/dom.d.ts +0 -139
- package/dist/tools/docx/dom.js +0 -448
- package/dist/tools/docx/errors.d.ts +0 -28
- package/dist/tools/docx/errors.js +0 -48
- package/dist/tools/docx/extractors/images.d.ts +0 -14
- package/dist/tools/docx/extractors/images.js +0 -40
- package/dist/tools/docx/extractors/metadata.d.ts +0 -14
- package/dist/tools/docx/extractors/metadata.js +0 -64
- package/dist/tools/docx/extractors/sections.d.ts +0 -14
- package/dist/tools/docx/extractors/sections.js +0 -61
- package/dist/tools/docx/html.d.ts +0 -17
- package/dist/tools/docx/html.js +0 -111
- package/dist/tools/docx/index.d.ts +0 -10
- package/dist/tools/docx/index.js +0 -10
- package/dist/tools/docx/markdown.d.ts +0 -84
- package/dist/tools/docx/markdown.js +0 -507
- package/dist/tools/docx/modify.d.ts +0 -28
- package/dist/tools/docx/modify.js +0 -271
- package/dist/tools/docx/operations/handlers/index.d.ts +0 -39
- package/dist/tools/docx/operations/handlers/index.js +0 -152
- package/dist/tools/docx/operations/html-manipulator.d.ts +0 -24
- package/dist/tools/docx/operations/html-manipulator.js +0 -352
- package/dist/tools/docx/operations/index.d.ts +0 -14
- package/dist/tools/docx/operations/index.js +0 -61
- package/dist/tools/docx/operations/operation-handlers.d.ts +0 -3
- package/dist/tools/docx/operations/operation-handlers.js +0 -67
- package/dist/tools/docx/operations/preprocessor.d.ts +0 -14
- package/dist/tools/docx/operations/preprocessor.js +0 -44
- package/dist/tools/docx/operations/xml-replacer.d.ts +0 -9
- package/dist/tools/docx/operations/xml-replacer.js +0 -35
- package/dist/tools/docx/operations.d.ts +0 -13
- package/dist/tools/docx/operations.js +0 -13
- package/dist/tools/docx/ops/delete-paragraph-at-body-index.d.ts +0 -11
- package/dist/tools/docx/ops/delete-paragraph-at-body-index.js +0 -23
- package/dist/tools/docx/ops/header-replace-text-exact.d.ts +0 -13
- package/dist/tools/docx/ops/header-replace-text-exact.js +0 -55
- package/dist/tools/docx/ops/index.d.ts +0 -17
- package/dist/tools/docx/ops/index.js +0 -70
- package/dist/tools/docx/ops/insert-image-after-text.d.ts +0 -24
- package/dist/tools/docx/ops/insert-image-after-text.js +0 -128
- package/dist/tools/docx/ops/insert-paragraph-after-text.d.ts +0 -12
- package/dist/tools/docx/ops/insert-paragraph-after-text.js +0 -74
- package/dist/tools/docx/ops/insert-table-after-text.d.ts +0 -19
- package/dist/tools/docx/ops/insert-table-after-text.js +0 -57
- package/dist/tools/docx/ops/replace-hyperlink-url.d.ts +0 -12
- package/dist/tools/docx/ops/replace-hyperlink-url.js +0 -37
- package/dist/tools/docx/ops/replace-paragraph-at-body-index.d.ts +0 -9
- package/dist/tools/docx/ops/replace-paragraph-at-body-index.js +0 -25
- package/dist/tools/docx/ops/replace-paragraph-text-exact.d.ts +0 -21
- package/dist/tools/docx/ops/replace-paragraph-text-exact.js +0 -36
- package/dist/tools/docx/ops/replace-table-cell-text.d.ts +0 -25
- package/dist/tools/docx/ops/replace-table-cell-text.js +0 -85
- package/dist/tools/docx/ops/set-color-for-paragraph-exact.d.ts +0 -9
- package/dist/tools/docx/ops/set-color-for-paragraph-exact.js +0 -24
- package/dist/tools/docx/ops/set-color-for-style.d.ts +0 -13
- package/dist/tools/docx/ops/set-color-for-style.js +0 -31
- package/dist/tools/docx/ops/set-paragraph-style-at-body-index.d.ts +0 -8
- package/dist/tools/docx/ops/set-paragraph-style-at-body-index.js +0 -57
- package/dist/tools/docx/ops/table-set-cell-text.d.ts +0 -9
- package/dist/tools/docx/ops/table-set-cell-text.js +0 -40
- package/dist/tools/docx/parsers/image-extractor.d.ts +0 -18
- package/dist/tools/docx/parsers/image-extractor.js +0 -61
- package/dist/tools/docx/parsers/index.d.ts +0 -9
- package/dist/tools/docx/parsers/index.js +0 -9
- package/dist/tools/docx/parsers/paragraph-parser.d.ts +0 -2
- package/dist/tools/docx/parsers/paragraph-parser.js +0 -88
- package/dist/tools/docx/parsers/table-parser.d.ts +0 -9
- package/dist/tools/docx/parsers/table-parser.js +0 -72
- package/dist/tools/docx/parsers/xml-parser.d.ts +0 -25
- package/dist/tools/docx/parsers/xml-parser.js +0 -71
- package/dist/tools/docx/parsers/zip-reader.d.ts +0 -23
- package/dist/tools/docx/parsers/zip-reader.js +0 -52
- package/dist/tools/docx/read.d.ts +0 -27
- package/dist/tools/docx/read.js +0 -308
- package/dist/tools/docx/relationships.d.ts +0 -22
- package/dist/tools/docx/relationships.js +0 -76
- package/dist/tools/docx/structure.d.ts +0 -25
- package/dist/tools/docx/structure.js +0 -102
- package/dist/tools/docx/styled-html-parser.d.ts +0 -23
- package/dist/tools/docx/styled-html-parser.js +0 -1262
- package/dist/tools/docx/types.d.ts +0 -213
- package/dist/tools/docx/types.js +0 -5
- package/dist/tools/docx/utils/escaping.d.ts +0 -13
- package/dist/tools/docx/utils/escaping.js +0 -26
- package/dist/tools/docx/utils/images.d.ts +0 -9
- package/dist/tools/docx/utils/images.js +0 -26
- package/dist/tools/docx/utils/index.d.ts +0 -12
- package/dist/tools/docx/utils/index.js +0 -17
- package/dist/tools/docx/utils/markdown.d.ts +0 -13
- package/dist/tools/docx/utils/markdown.js +0 -32
- package/dist/tools/docx/utils/paths.d.ts +0 -15
- package/dist/tools/docx/utils/paths.js +0 -27
- package/dist/tools/docx/utils/versioning.d.ts +0 -25
- package/dist/tools/docx/utils/versioning.js +0 -55
- package/dist/tools/docx/utils.d.ts +0 -101
- package/dist/tools/docx/utils.js +0 -299
- package/dist/tools/docx/validate.d.ts +0 -33
- package/dist/tools/docx/validate.js +0 -49
- package/dist/tools/docx/validators.d.ts +0 -13
- package/dist/tools/docx/validators.js +0 -40
- package/dist/tools/docx/write.d.ts +0 -17
- package/dist/tools/docx/write.js +0 -88
- package/dist/tools/docx/xml-view-test.js +0 -63
- package/dist/tools/docx/xml-view.d.ts +0 -56
- package/dist/tools/docx/xml-view.js +0 -169
- package/dist/tools/docx/zip.d.ts +0 -21
- package/dist/tools/docx/zip.js +0 -35
- package/dist/tools/pdf-processor.js +0 -3
- package/dist/tools/search.d.ts +0 -32
- package/dist/tools/search.js +0 -202
- package/dist/ui/file-preview/src/app.d.ts +0 -4
- package/dist/ui/file-preview/src/app.js +0 -800
- package/dist/utils/crash-logger.d.ts +0 -18
- package/dist/utils/crash-logger.js +0 -44
- package/dist/utils/dedent.d.ts +0 -8
- package/dist/utils/dedent.js +0 -38
- /package/dist/{http-server-auto-tunnel.d.ts → ui/config-editor/main.d.ts} +0 -0
- /package/dist/{test-docx.d.ts → ui/config-editor/src/main.d.ts} +0 -0
- /package/dist/{tools/docx/xml-view-test.d.ts → ui/file-preview/main.d.ts} +0 -0
- /package/dist/ui/file-preview/src/components/{toolbar.d.ts → Toolbar.d.ts} +0 -0
- /package/dist/ui/file-preview/src/components/{toolbar.js → Toolbar.js} +0 -0
- /package/dist/{tools/pdf-processor.d.ts → ui/file-preview/src/model.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type HtmlPreviewMode = 'rendered' | 'source';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/ui/resources.d.ts
CHANGED
|
@@ -4,7 +4,14 @@ export declare const FILE_PREVIEW_RESOURCE: {
|
|
|
4
4
|
description: string;
|
|
5
5
|
mimeType: string;
|
|
6
6
|
};
|
|
7
|
+
export declare const CONFIG_EDITOR_RESOURCE: {
|
|
8
|
+
uri: string;
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
mimeType: string;
|
|
12
|
+
};
|
|
7
13
|
export declare function getFilePreviewResourceText(): Promise<string>;
|
|
14
|
+
export declare function getConfigEditorResourceText(): Promise<string>;
|
|
8
15
|
export declare function listUiResources(): {
|
|
9
16
|
uri: string;
|
|
10
17
|
name: string;
|
package/dist/ui/resources.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import fs from 'fs/promises';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { fileURLToPath } from 'url';
|
|
7
|
-
import { FILE_PREVIEW_RESOURCE_URI } from './contracts.js';
|
|
7
|
+
import { CONFIG_EDITOR_RESOURCE_URI, FILE_PREVIEW_RESOURCE_URI } from './contracts.js';
|
|
8
8
|
const UI_RESOURCE_MIME_TYPE = 'text/html;profile=mcp-app';
|
|
9
9
|
export const FILE_PREVIEW_RESOURCE = {
|
|
10
10
|
uri: FILE_PREVIEW_RESOURCE_URI,
|
|
@@ -12,9 +12,16 @@ export const FILE_PREVIEW_RESOURCE = {
|
|
|
12
12
|
description: 'Markdown-first preview surface for read_file structured content.',
|
|
13
13
|
mimeType: UI_RESOURCE_MIME_TYPE
|
|
14
14
|
};
|
|
15
|
+
export const CONFIG_EDITOR_RESOURCE = {
|
|
16
|
+
uri: CONFIG_EDITOR_RESOURCE_URI,
|
|
17
|
+
name: 'Desktop Commander Config Editor',
|
|
18
|
+
description: 'Interactive editor for Desktop Commander configuration values.',
|
|
19
|
+
mimeType: UI_RESOURCE_MIME_TYPE
|
|
20
|
+
};
|
|
15
21
|
const __filename = fileURLToPath(import.meta.url);
|
|
16
22
|
const __dirname = path.dirname(__filename);
|
|
17
23
|
const DIST_FILE_PREVIEW_DIR = path.resolve(__dirname, 'file-preview');
|
|
24
|
+
const DIST_CONFIG_EDITOR_DIR = path.resolve(__dirname, 'config-editor');
|
|
18
25
|
function replaceOrThrow(source, pattern, replacement, context) {
|
|
19
26
|
if (!pattern.test(source)) {
|
|
20
27
|
throw new Error(`UI template is missing expected ${context}`);
|
|
@@ -43,14 +50,21 @@ async function readInlinedResourceHtml(distDir, runtimeFileName) {
|
|
|
43
50
|
export async function getFilePreviewResourceText() {
|
|
44
51
|
return readInlinedResourceHtml(DIST_FILE_PREVIEW_DIR, 'preview-runtime.js');
|
|
45
52
|
}
|
|
53
|
+
export async function getConfigEditorResourceText() {
|
|
54
|
+
return readInlinedResourceHtml(DIST_CONFIG_EDITOR_DIR, 'config-editor-runtime.js');
|
|
55
|
+
}
|
|
46
56
|
const READABLE_UI_RESOURCES = {
|
|
47
57
|
[FILE_PREVIEW_RESOURCE_URI]: {
|
|
48
58
|
mimeType: FILE_PREVIEW_RESOURCE.mimeType,
|
|
49
59
|
getText: getFilePreviewResourceText
|
|
60
|
+
},
|
|
61
|
+
[CONFIG_EDITOR_RESOURCE_URI]: {
|
|
62
|
+
mimeType: CONFIG_EDITOR_RESOURCE.mimeType,
|
|
63
|
+
getText: getConfigEditorResourceText
|
|
50
64
|
}
|
|
51
65
|
};
|
|
52
66
|
export function listUiResources() {
|
|
53
|
-
return [FILE_PREVIEW_RESOURCE];
|
|
67
|
+
return [FILE_PREVIEW_RESOURCE, CONFIG_EDITOR_RESOURCE];
|
|
54
68
|
}
|
|
55
69
|
export async function readUiResource(uri) {
|
|
56
70
|
const resource = READABLE_UI_RESOURCES[uri];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function listUiResources(): {
|
|
2
|
+
uri: string;
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
mimeType: string;
|
|
6
|
+
}[];
|
|
7
|
+
export declare function readUiResource(uri: string): Promise<{
|
|
8
|
+
contents: {
|
|
9
|
+
uri: string;
|
|
10
|
+
mimeType: string;
|
|
11
|
+
text: string;
|
|
12
|
+
}[];
|
|
13
|
+
} | null>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CONFIG_EDITOR_RESOURCE, FILE_PREVIEW_RESOURCE, getConfigEditorResourceText, getFilePreviewResourceText, } from './resources.js';
|
|
2
|
+
import { CONFIG_EDITOR_RESOURCE_URI, FILE_PREVIEW_RESOURCE_URI } from './contracts.js';
|
|
3
|
+
const READABLE_UI_RESOURCES = {
|
|
4
|
+
[FILE_PREVIEW_RESOURCE_URI]: {
|
|
5
|
+
mimeType: FILE_PREVIEW_RESOURCE.mimeType,
|
|
6
|
+
getText: getFilePreviewResourceText,
|
|
7
|
+
},
|
|
8
|
+
[CONFIG_EDITOR_RESOURCE_URI]: {
|
|
9
|
+
mimeType: CONFIG_EDITOR_RESOURCE.mimeType,
|
|
10
|
+
getText: getConfigEditorResourceText,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
export function listUiResources() {
|
|
14
|
+
return [FILE_PREVIEW_RESOURCE, CONFIG_EDITOR_RESOURCE];
|
|
15
|
+
}
|
|
16
|
+
export async function readUiResource(uri) {
|
|
17
|
+
const resource = READABLE_UI_RESOURCES[uri];
|
|
18
|
+
if (!resource) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const resourceText = await resource.getText();
|
|
22
|
+
return {
|
|
23
|
+
contents: [
|
|
24
|
+
{
|
|
25
|
+
uri,
|
|
26
|
+
mimeType: resource.mimeType,
|
|
27
|
+
text: resourceText,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function escapeHtml(value) {
|
|
2
|
+
return value
|
|
3
|
+
.split('&').join('&')
|
|
4
|
+
.split('<').join('<')
|
|
5
|
+
.split('>').join('>')
|
|
6
|
+
.split('"').join('"')
|
|
7
|
+
.split("'").join(''');
|
|
8
|
+
}
|
|
9
|
+
export function renderToolHeader(config) {
|
|
10
|
+
return `
|
|
11
|
+
<header class="toolbar">
|
|
12
|
+
<div class="meta">
|
|
13
|
+
<div class="meta-main">
|
|
14
|
+
<span class="file-pill ${escapeHtml(config.pillClassName ?? '')}">${escapeHtml(config.pillLabel)}</span>
|
|
15
|
+
<div class="meta-text">
|
|
16
|
+
<span class="filename" title="${escapeHtml(config.title)}">${escapeHtml(config.title)}</span>
|
|
17
|
+
<span class="filepath" title="${escapeHtml(config.subtitle)}">${escapeHtml(config.subtitle)}</span>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
<div class="meta-badges">
|
|
21
|
+
${config.badges.map((badge) => `<span class="badge">${escapeHtml(badge)}</span>`).join('')}
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
<div class="actions">
|
|
25
|
+
${config.actionsHtml}
|
|
26
|
+
</div>
|
|
27
|
+
</header>
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { App } from '@modelcontextprotocol/ext-apps';
|
|
2
|
+
import { type UiChromeState } from './host-context.js';
|
|
3
|
+
export interface ConnectWithSharedHostContextOptions {
|
|
4
|
+
app: App;
|
|
5
|
+
chrome: UiChromeState;
|
|
6
|
+
onContextApplied?: () => void;
|
|
7
|
+
onConnected?: () => void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare function connectWithSharedHostContext(options: ConnectWithSharedHostContextOptions): Promise<void>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { applySharedHostContext } from './host-context.js';
|
|
2
|
+
export async function connectWithSharedHostContext(options) {
|
|
3
|
+
const { app, chrome, onContextApplied, onConnected } = options;
|
|
4
|
+
app.onhostcontextchanged = (context) => {
|
|
5
|
+
applySharedHostContext(context, chrome);
|
|
6
|
+
onContextApplied?.();
|
|
7
|
+
};
|
|
8
|
+
await app.connect();
|
|
9
|
+
const hostContext = app.getHostContext();
|
|
10
|
+
if (hostContext) {
|
|
11
|
+
applySharedHostContext(hostContext, chrome);
|
|
12
|
+
onContextApplied?.();
|
|
13
|
+
}
|
|
14
|
+
await onConnected?.();
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface RenderCompactRowOptions {
|
|
2
|
+
id?: string;
|
|
3
|
+
label: string;
|
|
4
|
+
filename?: string;
|
|
5
|
+
variant?: 'ready' | 'loading' | 'status';
|
|
6
|
+
expandable?: boolean;
|
|
7
|
+
expanded?: boolean;
|
|
8
|
+
interactive?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function renderCompactRow(options: RenderCompactRowOptions): string;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { escapeHtml } from './escape-html.js';
|
|
2
|
+
export function renderCompactRow(options) {
|
|
3
|
+
const variant = options.variant ?? 'ready';
|
|
4
|
+
const classNames = `compact-row compact-row--${variant}`;
|
|
5
|
+
const id = options.id ? ` id="${escapeHtml(options.id)}"` : '';
|
|
6
|
+
const interactive = options.interactive ?? variant === 'ready';
|
|
7
|
+
const role = interactive ? ' role="button" tabindex="0"' : '';
|
|
8
|
+
const ariaExpanded = typeof options.expanded === 'boolean'
|
|
9
|
+
? ` aria-expanded="${String(options.expanded)}"`
|
|
10
|
+
: '';
|
|
11
|
+
const chevron = options.expandable
|
|
12
|
+
? '<svg class="compact-chevron" viewBox="0 0 24 24" aria-hidden="true"><path d="M10 6l6 6-6 6z"/></svg>'
|
|
13
|
+
: '';
|
|
14
|
+
const filename = options.filename
|
|
15
|
+
? `<span class="compact-filename">${escapeHtml(options.filename)}</span>`
|
|
16
|
+
: '';
|
|
17
|
+
return `<div class="${classNames}"${id}${role}${ariaExpanded}>${chevron}<span class="compact-label">${escapeHtml(options.label)}</span>${filename}</div>`;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isObjectRecord(value: unknown): value is Record<string, unknown>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { App } from '@modelcontextprotocol/ext-apps';
|
|
2
|
+
export interface UiChromeState {
|
|
3
|
+
expanded: boolean;
|
|
4
|
+
hideSummaryRow: boolean;
|
|
5
|
+
compact?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface ConnectWithSharedHostContextOptions {
|
|
8
|
+
app: App;
|
|
9
|
+
chrome: UiChromeState;
|
|
10
|
+
onContextApplied?: () => void;
|
|
11
|
+
onConnected?: () => void | Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare function isObjectRecord(value: unknown): value is Record<string, unknown>;
|
|
14
|
+
export declare function applySharedHostContext(context: unknown, chrome: UiChromeState): void;
|
|
15
|
+
export declare function connectWithSharedHostContext(options: ConnectWithSharedHostContextOptions): Promise<void>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { applyDocumentTheme, applyHostFonts, applyHostStyleVariables } from '@modelcontextprotocol/ext-apps';
|
|
2
|
+
export function isObjectRecord(value) {
|
|
3
|
+
return typeof value === 'object' && value !== null;
|
|
4
|
+
}
|
|
5
|
+
export function applySharedHostContext(context, chrome) {
|
|
6
|
+
if (!isObjectRecord(context)) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (context.theme === 'light' || context.theme === 'dark') {
|
|
10
|
+
applyDocumentTheme(context.theme);
|
|
11
|
+
}
|
|
12
|
+
const styles = isObjectRecord(context.styles) ? context.styles : null;
|
|
13
|
+
const variables = isObjectRecord(styles?.variables) ? styles.variables : null;
|
|
14
|
+
const css = isObjectRecord(styles?.css) ? styles.css : null;
|
|
15
|
+
const fonts = typeof css?.fonts === 'string' ? css.fonts : null;
|
|
16
|
+
if (variables) {
|
|
17
|
+
applyHostStyleVariables(variables);
|
|
18
|
+
}
|
|
19
|
+
if (fonts) {
|
|
20
|
+
applyHostFonts(fonts);
|
|
21
|
+
}
|
|
22
|
+
if (typeof context.initiallyExpanded === 'boolean') {
|
|
23
|
+
chrome.expanded = context.initiallyExpanded;
|
|
24
|
+
}
|
|
25
|
+
if (typeof context.compact === 'boolean' && typeof chrome.compact === 'boolean') {
|
|
26
|
+
chrome.compact = context.compact;
|
|
27
|
+
}
|
|
28
|
+
if (typeof context.hideSummaryRow === 'boolean') {
|
|
29
|
+
chrome.hideSummaryRow = context.hideSummaryRow;
|
|
30
|
+
if (context.hideSummaryRow) {
|
|
31
|
+
chrome.expanded = true;
|
|
32
|
+
if (typeof chrome.compact === 'boolean') {
|
|
33
|
+
chrome.compact = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export async function connectWithSharedHostContext(options) {
|
|
39
|
+
const { app, chrome, onContextApplied, onConnected } = options;
|
|
40
|
+
app.onhostcontextchanged = (context) => {
|
|
41
|
+
applySharedHostContext(context, chrome);
|
|
42
|
+
onContextApplied?.();
|
|
43
|
+
};
|
|
44
|
+
await app.connect();
|
|
45
|
+
const hostContext = app.getHostContext();
|
|
46
|
+
if (hostContext) {
|
|
47
|
+
applySharedHostContext(hostContext, chrome);
|
|
48
|
+
onContextApplied?.();
|
|
49
|
+
}
|
|
50
|
+
await onConnected?.();
|
|
51
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function createUiHostLifecycle(rpcClient, options) {
|
|
2
|
-
const { appName, appVersion = '1.0.0', getRootElement } = options;
|
|
2
|
+
const { appName, appVersion = '1.0.0', getRootElement, onHostContext } = options;
|
|
3
3
|
const resolveRootElement = () => getRootElement?.() ?? (document.getElementById('app')?.firstElementChild ?? document.getElementById('app'));
|
|
4
4
|
const notifySizeChanged = () => {
|
|
5
5
|
const node = resolveRootElement();
|
|
@@ -23,7 +23,13 @@ export function createUiHostLifecycle(rpcClient, options) {
|
|
|
23
23
|
appInfo: { name: appName, version: appVersion },
|
|
24
24
|
appCapabilities: {},
|
|
25
25
|
protocolVersion: '2026-01-26',
|
|
26
|
-
}).then(() => {
|
|
26
|
+
}).then((response) => {
|
|
27
|
+
if (onHostContext && response !== null && typeof response === 'object') {
|
|
28
|
+
const hostContext = response.hostContext;
|
|
29
|
+
if (hostContext !== null && typeof hostContext === 'object') {
|
|
30
|
+
onHostContext(hostContext);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
27
33
|
rpcClient.notify('ui/notifications/initialized', {});
|
|
28
34
|
}).catch(() => {
|
|
29
35
|
// Initialization handshake failure should not break rendering.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type ToolArgs = Record<string, unknown>;
|
|
2
|
+
type ToolHelper = {
|
|
3
|
+
callTool: (name: string, args: ToolArgs) => Promise<unknown> | unknown;
|
|
4
|
+
};
|
|
5
|
+
type MessageEventLike = {
|
|
6
|
+
data: unknown;
|
|
7
|
+
origin?: string;
|
|
8
|
+
source?: unknown;
|
|
9
|
+
};
|
|
10
|
+
type MessageListener = (event: MessageEventLike) => void;
|
|
11
|
+
type MessageTarget = {
|
|
12
|
+
postMessage: (message: unknown, targetOrigin?: string) => void;
|
|
13
|
+
};
|
|
14
|
+
type BridgeHost = {
|
|
15
|
+
openai?: ToolHelper;
|
|
16
|
+
mcp?: ToolHelper;
|
|
17
|
+
parent?: MessageTarget;
|
|
18
|
+
addEventListener?: (type: 'message', listener: MessageListener) => void;
|
|
19
|
+
removeEventListener?: (type: 'message', listener: MessageListener) => void;
|
|
20
|
+
};
|
|
21
|
+
export interface ToolBridgeOptions {
|
|
22
|
+
host?: BridgeHost;
|
|
23
|
+
requestTimeoutMs?: number;
|
|
24
|
+
targetOrigin?: string;
|
|
25
|
+
idPrefix?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function createToolBridge(options?: ToolBridgeOptions): {
|
|
28
|
+
callTool: (name: string, args?: ToolArgs) => Promise<unknown>;
|
|
29
|
+
};
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const DEFAULT_TIMEOUT_MS = 5000;
|
|
2
|
+
function getDefaultTargetOrigin() {
|
|
3
|
+
if (typeof document === 'undefined') {
|
|
4
|
+
return '*';
|
|
5
|
+
}
|
|
6
|
+
const referrer = document.referrer;
|
|
7
|
+
if (typeof referrer !== 'string' || referrer.trim().length === 0) {
|
|
8
|
+
return '*';
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
return new URL(referrer).origin;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return '*';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function normalizeTargetOrigin(value) {
|
|
18
|
+
if (value === '*') {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
return new URL(value).origin;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
throw new Error(`Invalid targetOrigin: ${value}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function isObject(value) {
|
|
29
|
+
return typeof value === 'object' && value !== null;
|
|
30
|
+
}
|
|
31
|
+
function normalizeToolArgs(args) {
|
|
32
|
+
return args ?? {};
|
|
33
|
+
}
|
|
34
|
+
function extractErrorMessage(error) {
|
|
35
|
+
if (error instanceof Error && error.message) {
|
|
36
|
+
return error.message;
|
|
37
|
+
}
|
|
38
|
+
return String(error);
|
|
39
|
+
}
|
|
40
|
+
function isHelperUnavailableError(error) {
|
|
41
|
+
if (!isObject(error)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const code = typeof error.code === 'string' ? error.code.toLowerCase() : '';
|
|
45
|
+
if (code === 'not_implemented' || code === 'not_supported' || code === 'unavailable') {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
const message = extractErrorMessage(error).toLowerCase();
|
|
49
|
+
return message.includes('not implemented')
|
|
50
|
+
|| message.includes('not supported')
|
|
51
|
+
|| message.includes('unavailable')
|
|
52
|
+
|| message.includes('not available');
|
|
53
|
+
}
|
|
54
|
+
export function createToolBridge(options = {}) {
|
|
55
|
+
const host = options.host ?? globalThis;
|
|
56
|
+
const timeoutMs = options.requestTimeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
57
|
+
const targetOrigin = normalizeTargetOrigin(options.targetOrigin ?? getDefaultTargetOrigin());
|
|
58
|
+
const idPrefix = options.idPrefix ?? 'tool-bridge';
|
|
59
|
+
let requestCounter = 0;
|
|
60
|
+
async function callViaFallback(name, args) {
|
|
61
|
+
if (!host.parent || !host.addEventListener || !host.removeEventListener) {
|
|
62
|
+
throw new Error('JSON-RPC fallback is unavailable in this host environment.');
|
|
63
|
+
}
|
|
64
|
+
const parent = host.parent;
|
|
65
|
+
const addListener = (type, listener) => {
|
|
66
|
+
host.addEventListener?.(type, listener);
|
|
67
|
+
};
|
|
68
|
+
const removeListener = (type, listener) => {
|
|
69
|
+
host.removeEventListener?.(type, listener);
|
|
70
|
+
};
|
|
71
|
+
requestCounter += 1;
|
|
72
|
+
const requestId = `${idPrefix}:${requestCounter}`;
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
const timeoutHandle = setTimeout(() => {
|
|
75
|
+
removeListener('message', onMessage);
|
|
76
|
+
reject(new Error(`Tool call fallback timed out after ${timeoutMs}ms (request: ${requestId})`));
|
|
77
|
+
}, timeoutMs);
|
|
78
|
+
const onMessage = (event) => {
|
|
79
|
+
const payload = event.data;
|
|
80
|
+
if (event.source !== parent) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (targetOrigin !== '*' && event.origin !== targetOrigin) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (!isObject(payload) || payload.id !== requestId) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
clearTimeout(timeoutHandle);
|
|
90
|
+
removeListener('message', onMessage);
|
|
91
|
+
if (isObject(payload.error)) {
|
|
92
|
+
const rawMessage = payload.error.message;
|
|
93
|
+
const message = typeof rawMessage === 'string'
|
|
94
|
+
? rawMessage
|
|
95
|
+
: 'Unknown tools/call fallback error';
|
|
96
|
+
reject(new Error(`Tool call fallback failed: ${message}`));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
resolve(payload.result);
|
|
100
|
+
};
|
|
101
|
+
addListener('message', onMessage);
|
|
102
|
+
parent.postMessage({
|
|
103
|
+
jsonrpc: '2.0',
|
|
104
|
+
id: requestId,
|
|
105
|
+
method: 'tools/call',
|
|
106
|
+
params: {
|
|
107
|
+
name,
|
|
108
|
+
arguments: args,
|
|
109
|
+
},
|
|
110
|
+
}, targetOrigin);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
async function callTool(name, args) {
|
|
114
|
+
const normalizedArgs = normalizeToolArgs(args);
|
|
115
|
+
const helperCandidates = [host.openai, host.mcp].filter((candidate) => Boolean(candidate?.callTool));
|
|
116
|
+
for (const helper of helperCandidates) {
|
|
117
|
+
try {
|
|
118
|
+
return await helper.callTool(name, normalizedArgs);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
if (isHelperUnavailableError(error)) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
throw new Error(`Tool helper call failed: ${extractErrorMessage(error)}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
return await callViaFallback(name, normalizedArgs);
|
|
129
|
+
}
|
|
130
|
+
catch (fallbackError) {
|
|
131
|
+
throw fallbackError;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
callTool,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
@@ -12,5 +12,14 @@ interface CreateToolShellControllerOptions {
|
|
|
12
12
|
onScrollAfterExpand?: () => void;
|
|
13
13
|
onRender?: () => void;
|
|
14
14
|
}
|
|
15
|
+
interface CreateCompactRowShellControllerOptions {
|
|
16
|
+
shell: HTMLElement | null;
|
|
17
|
+
compactRow: HTMLElement | null;
|
|
18
|
+
initialExpanded: boolean;
|
|
19
|
+
onToggle?: (expanded: boolean) => void;
|
|
20
|
+
onScrollAfterExpand?: () => void;
|
|
21
|
+
onRender?: () => void;
|
|
22
|
+
}
|
|
15
23
|
export declare function createToolShellController(options: CreateToolShellControllerOptions): ToolShellController;
|
|
24
|
+
export declare function createCompactRowShellController(options: CreateCompactRowShellControllerOptions): ToolShellController;
|
|
16
25
|
export {};
|
|
@@ -23,6 +23,7 @@ export function createToolShellController(options) {
|
|
|
23
23
|
const { shell, toggleButton, initialExpanded, onToggle, onScrollAfterExpand, onRender } = options;
|
|
24
24
|
let isExpanded = initialExpanded;
|
|
25
25
|
let scrollTrackedForCurrentExpand = false;
|
|
26
|
+
const shouldTrackScroll = typeof onScrollAfterExpand === 'function';
|
|
26
27
|
const applyExpandedState = (nextExpanded) => {
|
|
27
28
|
const wasExpanded = isExpanded;
|
|
28
29
|
isExpanded = nextExpanded;
|
|
@@ -50,16 +51,57 @@ export function createToolShellController(options) {
|
|
|
50
51
|
};
|
|
51
52
|
applyExpandedState(isExpanded);
|
|
52
53
|
toggleButton?.addEventListener('click', toggle);
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
if (shouldTrackScroll) {
|
|
55
|
+
shell?.addEventListener('scroll', handleScroll, { passive: true });
|
|
56
|
+
document.addEventListener('scroll', handleScroll, { passive: true, capture: true });
|
|
57
|
+
}
|
|
55
58
|
return {
|
|
56
59
|
getExpanded: () => isExpanded,
|
|
57
60
|
setExpanded: applyExpandedState,
|
|
58
61
|
toggle,
|
|
59
62
|
dispose: () => {
|
|
60
63
|
toggleButton?.removeEventListener('click', toggle);
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
if (shouldTrackScroll) {
|
|
65
|
+
shell?.removeEventListener('scroll', handleScroll);
|
|
66
|
+
document.removeEventListener('scroll', handleScroll, true);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function createCompactRowShellController(options) {
|
|
72
|
+
const { shell, compactRow, initialExpanded, onToggle, onScrollAfterExpand, onRender } = options;
|
|
73
|
+
const controller = createToolShellController({
|
|
74
|
+
shell,
|
|
75
|
+
toggleButton: null,
|
|
76
|
+
initialExpanded,
|
|
77
|
+
onToggle: (expanded) => {
|
|
78
|
+
compactRow?.setAttribute('aria-expanded', String(expanded));
|
|
79
|
+
onToggle?.(expanded);
|
|
80
|
+
},
|
|
81
|
+
onScrollAfterExpand,
|
|
82
|
+
onRender,
|
|
83
|
+
});
|
|
84
|
+
compactRow?.setAttribute('aria-expanded', String(initialExpanded));
|
|
85
|
+
const handleCompactClick = () => {
|
|
86
|
+
controller.toggle();
|
|
87
|
+
};
|
|
88
|
+
const handleCompactKeydown = (event) => {
|
|
89
|
+
if (event.key !== 'Enter' && event.key !== ' ') {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
controller.toggle();
|
|
94
|
+
};
|
|
95
|
+
compactRow?.addEventListener('click', handleCompactClick);
|
|
96
|
+
compactRow?.addEventListener('keydown', handleCompactKeydown);
|
|
97
|
+
return {
|
|
98
|
+
getExpanded: controller.getExpanded,
|
|
99
|
+
setExpanded: controller.setExpanded,
|
|
100
|
+
toggle: controller.toggle,
|
|
101
|
+
dispose: () => {
|
|
102
|
+
compactRow?.removeEventListener('click', handleCompactClick);
|
|
103
|
+
compactRow?.removeEventListener('keydown', handleCompactKeydown);
|
|
104
|
+
controller.dispose();
|
|
63
105
|
},
|
|
64
106
|
};
|
|
65
107
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type UiEventParamValue = string | number | boolean | null;
|
|
2
|
+
export type UiEventParams = Record<string, UiEventParamValue>;
|
|
3
|
+
type ToolCaller = (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
4
|
+
export interface UiEventTrackerOptions {
|
|
5
|
+
component: string;
|
|
6
|
+
baseParams?: UiEventParams;
|
|
7
|
+
}
|
|
8
|
+
export declare function createUiEventTracker(callTool: ToolCaller, options: UiEventTrackerOptions): (event: string, params?: Record<string, unknown>) => void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function normalizeUiEventParams(params) {
|
|
2
|
+
const normalized = {};
|
|
3
|
+
if (!params) {
|
|
4
|
+
return normalized;
|
|
5
|
+
}
|
|
6
|
+
for (const [key, value] of Object.entries(params)) {
|
|
7
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' || value === null) {
|
|
8
|
+
normalized[key] = value;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return normalized;
|
|
12
|
+
}
|
|
13
|
+
export function createUiEventTracker(callTool, options) {
|
|
14
|
+
const baseParams = options.baseParams ?? {};
|
|
15
|
+
return (event, params = {}) => {
|
|
16
|
+
void callTool('track_ui_event', {
|
|
17
|
+
event,
|
|
18
|
+
component: options.component,
|
|
19
|
+
params: {
|
|
20
|
+
...baseParams,
|
|
21
|
+
...normalizeUiEventParams(params),
|
|
22
|
+
},
|
|
23
|
+
}).catch(() => {
|
|
24
|
+
// UI analytics should never block UI interactions.
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -23,6 +23,11 @@ export declare function isChatGPT(): boolean;
|
|
|
23
23
|
* Create a widget state storage adapter.
|
|
24
24
|
*
|
|
25
25
|
* On ChatGPT: Uses window.openai.widgetState for persistence
|
|
26
|
-
* On other hosts:
|
|
26
|
+
* On other hosts: Uses sessionStorage as a fallback so the preview can survive
|
|
27
|
+
* transient interruptions (page refresh on hosts that don't re-send tool_result,
|
|
28
|
+
* visibility/focus loss, etc.).
|
|
29
|
+
* The fallback cache key is scoped by app pathname and a per-frame widget id
|
|
30
|
+
* persisted in window.name, so different widgets in the same origin/session
|
|
31
|
+
* do not overwrite one another's cached state.
|
|
27
32
|
*/
|
|
28
33
|
export declare function createWidgetStateStorage<T>(validator?: (state: unknown) => boolean): WidgetStateStorage<T>;
|