@tonyclaw/agent-inspector 2.0.0
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/.output/cli.js +1611 -0
- package/.output/nitro.json +17 -0
- package/.output/public/assets/CompareDrawer-CU5ZrWcL.js +1 -0
- package/.output/public/assets/ProxyViewerContainer-pEBqVp1d.js +101 -0
- package/.output/public/assets/ReplayDialog-F58yNg5j.js +1 -0
- package/.output/public/assets/RequestAnatomy-C9lT0qE_.js +1 -0
- package/.output/public/assets/ResponseView-DHJq6bnz.js +1 -0
- package/.output/public/assets/StreamingChunkSequence-BTgfpFUT.js +1 -0
- package/.output/public/assets/_sessionId-DsNRbnNm.js +1 -0
- package/.output/public/assets/alibaba-TTwafVwX.svg +1 -0
- package/.output/public/assets/index-CpWG2hFn.css +1 -0
- package/.output/public/assets/index-DmBV8Gve.js +1 -0
- package/.output/public/assets/json-viewer-CZVYLR8j.js +14 -0
- package/.output/public/assets/main-DHs7FBK3.js +18 -0
- package/.output/public/assets/minimax-BPMzvuL-.jpeg +0 -0
- package/.output/public/assets/qwen-CONDcHqt.png +0 -0
- package/.output/public/assets/zhipuai-BPNAnxo-.svg +219 -0
- package/.output/server/_chunks/ssr-renderer.mjs +22 -0
- package/.output/server/_libs/@radix-ui/react-accessible-icon+[...].mjs +1 -0
- package/.output/server/_libs/@radix-ui/react-dismissable-layer+[...].mjs +210 -0
- package/.output/server/_libs/@radix-ui/react-navigation-menu+[...].mjs +2 -0
- package/.output/server/_libs/@radix-ui/react-one-time-password-field+[...].mjs +2 -0
- package/.output/server/_libs/@radix-ui/react-password-toggle-field+[...].mjs +2 -0
- package/.output/server/_libs/@radix-ui/react-use-callback-ref+[...].mjs +11 -0
- package/.output/server/_libs/@radix-ui/react-use-controllable-state+[...].mjs +69 -0
- package/.output/server/_libs/@radix-ui/react-use-effect-event+[...].mjs +1 -0
- package/.output/server/_libs/@radix-ui/react-use-escape-keydown+[...].mjs +17 -0
- package/.output/server/_libs/@radix-ui/react-use-is-hydrated+[...].mjs +1 -0
- package/.output/server/_libs/@radix-ui/react-use-layout-effect+[...].mjs +6 -0
- package/.output/server/_libs/@radix-ui/react-visually-hidden+[...].mjs +34 -0
- package/.output/server/_libs/ajv-formats.mjs +330 -0
- package/.output/server/_libs/ajv.mjs +11444 -0
- package/.output/server/_libs/aria-hidden.mjs +122 -0
- package/.output/server/_libs/atomically.mjs +152 -0
- package/.output/server/_libs/bail.mjs +8 -0
- package/.output/server/_libs/cfworker__json-schema.mjs +1 -0
- package/.output/server/_libs/character-entities.mjs +2130 -0
- package/.output/server/_libs/class-variance-authority.mjs +44 -0
- package/.output/server/_libs/clsx.mjs +16 -0
- package/.output/server/_libs/comma-separated-tokens.mjs +10 -0
- package/.output/server/_libs/conf.mjs +635 -0
- package/.output/server/_libs/cookie-es.mjs +58 -0
- package/.output/server/_libs/core-util-is.mjs +75 -0
- package/.output/server/_libs/croner.mjs +1 -0
- package/.output/server/_libs/crossws.mjs +1 -0
- package/.output/server/_libs/debounce-fn.mjs +69 -0
- package/.output/server/_libs/decode-named-character-reference+[...].mjs +8 -0
- package/.output/server/_libs/dequal.mjs +27 -0
- package/.output/server/_libs/detect-node-es.mjs +1 -0
- package/.output/server/_libs/devlop.mjs +8 -0
- package/.output/server/_libs/diff.mjs +320 -0
- package/.output/server/_libs/dot-prop.mjs +265 -0
- package/.output/server/_libs/env-paths.mjs +57 -0
- package/.output/server/_libs/estree-util-is-identifier-name.mjs +11 -0
- package/.output/server/_libs/extend.mjs +97 -0
- package/.output/server/_libs/fast-deep-equal.mjs +38 -0
- package/.output/server/_libs/fast-uri.mjs +812 -0
- package/.output/server/_libs/floating-ui__core.mjs +725 -0
- package/.output/server/_libs/floating-ui__dom.mjs +622 -0
- package/.output/server/_libs/floating-ui__react-dom.mjs +292 -0
- package/.output/server/_libs/floating-ui__utils.mjs +320 -0
- package/.output/server/_libs/get-nonce.mjs +9 -0
- package/.output/server/_libs/h3-v2.mjs +276 -0
- package/.output/server/_libs/h3.mjs +408 -0
- package/.output/server/_libs/hast-util-to-jsx-runtime.mjs +388 -0
- package/.output/server/_libs/hast-util-whitespace.mjs +10 -0
- package/.output/server/_libs/hookable.mjs +1 -0
- package/.output/server/_libs/html-url-attributes.mjs +26 -0
- package/.output/server/_libs/immediate.mjs +74 -0
- package/.output/server/_libs/inherits.mjs +50 -0
- package/.output/server/_libs/inline-style-parser.mjs +142 -0
- package/.output/server/_libs/is-plain-obj.mjs +10 -0
- package/.output/server/_libs/isarray.mjs +14 -0
- package/.output/server/_libs/isbot.mjs +20 -0
- package/.output/server/_libs/json-schema-traverse.mjs +180 -0
- package/.output/server/_libs/jszip.mjs +3051 -0
- package/.output/server/_libs/lie.mjs +273 -0
- package/.output/server/_libs/lucide-react.mjs +492 -0
- package/.output/server/_libs/mdast-util-from-markdown.mjs +717 -0
- package/.output/server/_libs/mdast-util-to-hast.mjs +710 -0
- package/.output/server/_libs/mdast-util-to-string.mjs +38 -0
- package/.output/server/_libs/micromark-core-commonmark.mjs +2259 -0
- package/.output/server/_libs/micromark-factory-destination.mjs +94 -0
- package/.output/server/_libs/micromark-factory-label.mjs +63 -0
- package/.output/server/_libs/micromark-factory-space.mjs +24 -0
- package/.output/server/_libs/micromark-factory-title.mjs +65 -0
- package/.output/server/_libs/micromark-factory-whitespace.mjs +22 -0
- package/.output/server/_libs/micromark-util-character.mjs +44 -0
- package/.output/server/_libs/micromark-util-chunked.mjs +36 -0
- package/.output/server/_libs/micromark-util-classify-character+[...].mjs +12 -0
- package/.output/server/_libs/micromark-util-combine-extensions+[...].mjs +41 -0
- package/.output/server/_libs/micromark-util-decode-numeric-character-reference+[...].mjs +19 -0
- package/.output/server/_libs/micromark-util-decode-string.mjs +21 -0
- package/.output/server/_libs/micromark-util-encode.mjs +1 -0
- package/.output/server/_libs/micromark-util-html-tag-name.mjs +69 -0
- package/.output/server/_libs/micromark-util-normalize-identifier+[...].mjs +6 -0
- package/.output/server/_libs/micromark-util-resolve-all.mjs +15 -0
- package/.output/server/_libs/micromark-util-sanitize-uri.mjs +41 -0
- package/.output/server/_libs/micromark-util-subtokenize.mjs +346 -0
- package/.output/server/_libs/micromark.mjs +906 -0
- package/.output/server/_libs/mimic-function.mjs +47 -0
- package/.output/server/_libs/modelcontextprotocol__server.mjs +9738 -0
- package/.output/server/_libs/ocache.mjs +1 -0
- package/.output/server/_libs/ohash.mjs +1 -0
- package/.output/server/_libs/pako.mjs +4223 -0
- package/.output/server/_libs/process-nextick-args.mjs +48 -0
- package/.output/server/_libs/property-information.mjs +1209 -0
- package/.output/server/_libs/radix-ui.mjs +1 -0
- package/.output/server/_libs/radix-ui__number.mjs +6 -0
- package/.output/server/_libs/radix-ui__primitive.mjs +11 -0
- package/.output/server/_libs/radix-ui__react-accordion.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-alert-dialog.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-arrow.mjs +23 -0
- package/.output/server/_libs/radix-ui__react-aspect-ratio.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-avatar.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-checkbox.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-collapsible.mjs +144 -0
- package/.output/server/_libs/radix-ui__react-collection.mjs +69 -0
- package/.output/server/_libs/radix-ui__react-compose-refs.mjs +39 -0
- package/.output/server/_libs/radix-ui__react-context-menu.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-context.mjs +78 -0
- package/.output/server/_libs/radix-ui__react-dialog.mjs +325 -0
- package/.output/server/_libs/radix-ui__react-direction.mjs +9 -0
- package/.output/server/_libs/radix-ui__react-dropdown-menu.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-focus-guards.mjs +29 -0
- package/.output/server/_libs/radix-ui__react-focus-scope.mjs +206 -0
- package/.output/server/_libs/radix-ui__react-form.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-hover-card.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-id.mjs +14 -0
- package/.output/server/_libs/radix-ui__react-label.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-menu.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-menubar.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-popover.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-popper.mjs +286 -0
- package/.output/server/_libs/radix-ui__react-portal.mjs +16 -0
- package/.output/server/_libs/radix-ui__react-presence.mjs +128 -0
- package/.output/server/_libs/radix-ui__react-primitive.mjs +42 -0
- package/.output/server/_libs/radix-ui__react-progress.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-radio-group.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-roving-focus.mjs +224 -0
- package/.output/server/_libs/radix-ui__react-scroll-area.mjs +721 -0
- package/.output/server/_libs/radix-ui__react-select.mjs +1163 -0
- package/.output/server/_libs/radix-ui__react-separator.mjs +28 -0
- package/.output/server/_libs/radix-ui__react-slider.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-slot.mjs +99 -0
- package/.output/server/_libs/radix-ui__react-switch.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-tabs.mjs +189 -0
- package/.output/server/_libs/radix-ui__react-toast.mjs +2 -0
- package/.output/server/_libs/radix-ui__react-toggle-group.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-toggle.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-toolbar.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-tooltip.mjs +495 -0
- package/.output/server/_libs/radix-ui__react-use-previous.mjs +14 -0
- package/.output/server/_libs/radix-ui__react-use-size.mjs +39 -0
- package/.output/server/_libs/react-dom.mjs +10781 -0
- package/.output/server/_libs/react-markdown.mjs +147 -0
- package/.output/server/_libs/react-remove-scroll-bar.mjs +82 -0
- package/.output/server/_libs/react-remove-scroll.mjs +328 -0
- package/.output/server/_libs/react-style-singleton.mjs +69 -0
- package/.output/server/_libs/react.mjs +515 -0
- package/.output/server/_libs/readable-stream.mjs +1518 -0
- package/.output/server/_libs/remark-parse.mjs +19 -0
- package/.output/server/_libs/remark-rehype.mjs +21 -0
- package/.output/server/_libs/rou3.mjs +14 -0
- package/.output/server/_libs/safe-buffer.mjs +64 -0
- package/.output/server/_libs/semver.mjs +1938 -0
- package/.output/server/_libs/seroval-plugins.mjs +58 -0
- package/.output/server/_libs/seroval.mjs +1765 -0
- package/.output/server/_libs/setimmediate.mjs +152 -0
- package/.output/server/_libs/space-separated-tokens.mjs +6 -0
- package/.output/server/_libs/srvx.mjs +1029 -0
- package/.output/server/_libs/stubborn-fs.mjs +91 -0
- package/.output/server/_libs/stubborn-utils.mjs +66 -0
- package/.output/server/_libs/style-to-js.mjs +72 -0
- package/.output/server/_libs/style-to-object.mjs +38 -0
- package/.output/server/_libs/swr.mjs +939 -0
- package/.output/server/_libs/tailwind-merge.mjs +3010 -0
- package/.output/server/_libs/tanstack__history.mjs +217 -0
- package/.output/server/_libs/tanstack__react-router.mjs +1480 -0
- package/.output/server/_libs/tanstack__react-store.mjs +1 -0
- package/.output/server/_libs/tanstack__react-virtual.mjs +44 -0
- package/.output/server/_libs/tanstack__router-core.mjs +4827 -0
- package/.output/server/_libs/tanstack__store.mjs +1 -0
- package/.output/server/_libs/tanstack__virtual-core.mjs +1225 -0
- package/.output/server/_libs/tiny-invariant.mjs +12 -0
- package/.output/server/_libs/tiny-warning.mjs +5 -0
- package/.output/server/_libs/trim-lines.mjs +41 -0
- package/.output/server/_libs/trough.mjs +85 -0
- package/.output/server/_libs/tslib.mjs +1 -0
- package/.output/server/_libs/ufo.mjs +54 -0
- package/.output/server/_libs/uint8array-extras.mjs +69 -0
- package/.output/server/_libs/ungap__structured-clone.mjs +212 -0
- package/.output/server/_libs/unified.mjs +661 -0
- package/.output/server/_libs/unist-util-is.mjs +100 -0
- package/.output/server/_libs/unist-util-position.mjs +27 -0
- package/.output/server/_libs/unist-util-stringify-position.mjs +27 -0
- package/.output/server/_libs/unist-util-visit-parents.mjs +82 -0
- package/.output/server/_libs/unist-util-visit.mjs +24 -0
- package/.output/server/_libs/unstorage.mjs +1 -0
- package/.output/server/_libs/use-callback-ref.mjs +66 -0
- package/.output/server/_libs/use-sidecar.mjs +106 -0
- package/.output/server/_libs/use-sync-external-store.mjs +64 -0
- package/.output/server/_libs/util-deprecate.mjs +12 -0
- package/.output/server/_libs/vfile-message.mjs +138 -0
- package/.output/server/_libs/vfile.mjs +467 -0
- package/.output/server/_libs/when-exit.mjs +53 -0
- package/.output/server/_libs/zod.mjs +4524 -0
- package/.output/server/_sessionId-wMLPvC5g.mjs +123 -0
- package/.output/server/_ssr/CompareDrawer-BU4V0uVf.mjs +1041 -0
- package/.output/server/_ssr/ProxyViewerContainer-BnRwFEnn.mjs +5972 -0
- package/.output/server/_ssr/ReplayDialog-C7dn9pd_.mjs +322 -0
- package/.output/server/_ssr/RequestAnatomy-C1rWpe9-.mjs +353 -0
- package/.output/server/_ssr/ResponseView-hGpPaYsf.mjs +602 -0
- package/.output/server/_ssr/StreamingChunkSequence-BRWI1r_G.mjs +302 -0
- package/.output/server/_ssr/index-BKURLVPz.mjs +118 -0
- package/.output/server/_ssr/index.mjs +1184 -0
- package/.output/server/_ssr/json-viewer-BBd2DtQP.mjs +515 -0
- package/.output/server/_ssr/router-BcZ0D6AB.mjs +6317 -0
- package/.output/server/_ssr/start-HYkvq4Ni.mjs +4 -0
- package/.output/server/_tanstack-start-manifest_v-1y8ZVxRI.mjs +4 -0
- package/.output/server/index.mjs +436 -0
- package/.output/server/node_modules/tslib/modules/index.js +70 -0
- package/.output/server/node_modules/tslib/modules/package.json +3 -0
- package/.output/server/node_modules/tslib/package.json +47 -0
- package/.output/server/node_modules/tslib/tslib.js +484 -0
- package/.output/server/package.json +9 -0
- package/LICENSE +21 -0
- package/README.md +52 -0
- package/package.json +110 -0
- package/src/assets/favicon.svg +31 -0
- package/src/assets/logos/alibaba.svg +1 -0
- package/src/assets/logos/anthropic.svg +1 -0
- package/src/assets/logos/claude-code.svg +4 -0
- package/src/assets/logos/deepseek.svg +1 -0
- package/src/assets/logos/mcp.png +0 -0
- package/src/assets/logos/minimax.jpeg +0 -0
- package/src/assets/logos/openai.svg +1 -0
- package/src/assets/logos/opencode.svg +4 -0
- package/src/assets/logos/qwen.png +0 -0
- package/src/assets/logos/zhipuai.svg +219 -0
- package/src/cli/detect-tools.ts +147 -0
- package/src/cli/doctor.ts +521 -0
- package/src/cli/onboard.ts +224 -0
- package/src/cli/templates/command-onboard.ts +17 -0
- package/src/cli/templates/skill-onboard.ts +547 -0
- package/src/cli.ts +345 -0
- package/src/components/OnboardingBanner.tsx +67 -0
- package/src/components/ProxyViewer.tsx +545 -0
- package/src/components/ProxyViewerContainer.tsx +363 -0
- package/src/components/providers/ImportWizardDialog.tsx +349 -0
- package/src/components/providers/ProviderCard.tsx +474 -0
- package/src/components/providers/ProviderForm.tsx +494 -0
- package/src/components/providers/ProviderLogo.tsx +117 -0
- package/src/components/providers/ProvidersPanel.tsx +619 -0
- package/src/components/providers/SettingsDialog.tsx +202 -0
- package/src/components/proxy-viewer/CompareDrawer.tsx +893 -0
- package/src/components/proxy-viewer/ConversationGroup.tsx +107 -0
- package/src/components/proxy-viewer/ConversationHeader.tsx +300 -0
- package/src/components/proxy-viewer/LogEntry.tsx +543 -0
- package/src/components/proxy-viewer/LogEntryHeader.tsx +501 -0
- package/src/components/proxy-viewer/ReplayDialog.tsx +218 -0
- package/src/components/proxy-viewer/ResponseView.tsx +171 -0
- package/src/components/proxy-viewer/StreamingChunkSequence.tsx +188 -0
- package/src/components/proxy-viewer/ThreadConnector.tsx +136 -0
- package/src/components/proxy-viewer/TurnGroup.tsx +337 -0
- package/src/components/proxy-viewer/anatomy/RequestAnatomy.tsx +98 -0
- package/src/components/proxy-viewer/anatomy/SegmentBar.tsx +196 -0
- package/src/components/proxy-viewer/anatomy/tokenEstimate.ts +53 -0
- package/src/components/proxy-viewer/anatomy/types.ts +39 -0
- package/src/components/proxy-viewer/anatomy/useAnatomyJump.ts +114 -0
- package/src/components/proxy-viewer/cacheTrend.ts +50 -0
- package/src/components/proxy-viewer/diff/DiffView.tsx +321 -0
- package/src/components/proxy-viewer/diff/computeDiff.ts +178 -0
- package/src/components/proxy-viewer/diff/index.ts +3 -0
- package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +157 -0
- package/src/components/proxy-viewer/formats/anthropic/ResponseView.tsx +66 -0
- package/src/components/proxy-viewer/formats/anthropic/thinkingExtract.ts +21 -0
- package/src/components/proxy-viewer/formats/index.tsx +33 -0
- package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +170 -0
- package/src/components/proxy-viewer/index.ts +9 -0
- package/src/components/proxy-viewer/lazy.ts +37 -0
- package/src/components/proxy-viewer/log-formats/anthropic.ts +194 -0
- package/src/components/proxy-viewer/log-formats/index.ts +23 -0
- package/src/components/proxy-viewer/log-formats/openai.ts +167 -0
- package/src/components/proxy-viewer/log-formats/types.ts +40 -0
- package/src/components/proxy-viewer/log-formats/unknown.ts +18 -0
- package/src/components/proxy-viewer/logEntryVisibility.ts +39 -0
- package/src/components/proxy-viewer/requestDiff.ts +277 -0
- package/src/components/proxy-viewer/useCopyFeedback.ts +36 -0
- package/src/components/proxy-viewer/useKeyboardNavigation.ts +190 -0
- package/src/components/proxy-viewer/viewerState.ts +66 -0
- package/src/components/ui/badge.tsx +47 -0
- package/src/components/ui/button.tsx +47 -0
- package/src/components/ui/collapsible.tsx +21 -0
- package/src/components/ui/confirm-dialog.tsx +51 -0
- package/src/components/ui/crab-logo.tsx +95 -0
- package/src/components/ui/crab-variants.tsx +467 -0
- package/src/components/ui/dialog.tsx +129 -0
- package/src/components/ui/json-expansion-button.tsx +56 -0
- package/src/components/ui/json-viewer-bulk.ts +97 -0
- package/src/components/ui/json-viewer.tsx +494 -0
- package/src/components/ui/mcp-logo.tsx +20 -0
- package/src/components/ui/scroll-area.tsx +54 -0
- package/src/components/ui/select.tsx +178 -0
- package/src/components/ui/separator.tsx +28 -0
- package/src/components/ui/tabs.tsx +88 -0
- package/src/components/ui/tooltip.tsx +51 -0
- package/src/index.css +11 -0
- package/src/knowledge/candidateStore.ts +63 -0
- package/src/knowledge/distiller.ts +98 -0
- package/src/knowledge/openclawClient.ts +118 -0
- package/src/knowledge/redactor.ts +80 -0
- package/src/knowledge/types.ts +84 -0
- package/src/lib/apiClient.ts +49 -0
- package/src/lib/export-logs.ts +51 -0
- package/src/lib/mask.ts +4 -0
- package/src/lib/objectUtils.ts +22 -0
- package/src/lib/providerContract.ts +26 -0
- package/src/lib/providerTestContract.ts +107 -0
- package/src/lib/runtimeConfig.ts +25 -0
- package/src/lib/serverPort.ts +41 -0
- package/src/lib/sessionUrl.ts +44 -0
- package/src/lib/stopReason.ts +58 -0
- package/src/lib/useOnboarding.ts +80 -0
- package/src/lib/useProviders.ts +30 -0
- package/src/lib/useStripConfig.ts +108 -0
- package/src/lib/utils.ts +21 -0
- package/src/mcp/loopback.ts +76 -0
- package/src/mcp/previewExtractor.ts +166 -0
- package/src/mcp/server.ts +396 -0
- package/src/mcp/toolHandlers.ts +341 -0
- package/src/proxy/chunkStorage.ts +112 -0
- package/src/proxy/claudeCodeStrip.ts +99 -0
- package/src/proxy/config.ts +172 -0
- package/src/proxy/constants.ts +47 -0
- package/src/proxy/dataDir.ts +86 -0
- package/src/proxy/formats/anthropic/anthropicProvider.ts +75 -0
- package/src/proxy/formats/anthropic/handler.ts +71 -0
- package/src/proxy/formats/anthropic/index.ts +14 -0
- package/src/proxy/formats/anthropic/register.ts +4 -0
- package/src/proxy/formats/anthropic/schemas.ts +237 -0
- package/src/proxy/formats/anthropic/stream.ts +205 -0
- package/src/proxy/formats/handler.ts +46 -0
- package/src/proxy/formats/index.ts +12 -0
- package/src/proxy/formats/jsonSchema.ts +36 -0
- package/src/proxy/formats/openai/alibabaProvider.ts +38 -0
- package/src/proxy/formats/openai/handler.ts +96 -0
- package/src/proxy/formats/openai/index.ts +25 -0
- package/src/proxy/formats/openai/provider.ts +50 -0
- package/src/proxy/formats/openai/register.ts +4 -0
- package/src/proxy/formats/openai/schemas.ts +187 -0
- package/src/proxy/formats/openai/stream.ts +206 -0
- package/src/proxy/formats/protocol.ts +50 -0
- package/src/proxy/formats/providerRegistry.ts +51 -0
- package/src/proxy/formats/providers/index.ts +3 -0
- package/src/proxy/formats/registry.ts +66 -0
- package/src/proxy/handler.ts +334 -0
- package/src/proxy/logFinalizer.ts +305 -0
- package/src/proxy/logFinalizer.worker.ts +24 -0
- package/src/proxy/logIndex.ts +268 -0
- package/src/proxy/logger.ts +179 -0
- package/src/proxy/openaiOrphanToolStrip.ts +142 -0
- package/src/proxy/providerImporters.ts +491 -0
- package/src/proxy/providers.ts +613 -0
- package/src/proxy/schemas.ts +209 -0
- package/src/proxy/sessionProcess.ts +140 -0
- package/src/proxy/sessionRuntime.ts +85 -0
- package/src/proxy/sessionSupervisor.ts +283 -0
- package/src/proxy/sessionWorkerEntry.ts +26 -0
- package/src/proxy/socketTracker.ts +255 -0
- package/src/proxy/store.ts +412 -0
- package/src/proxy/upstream.ts +90 -0
- package/src/router.tsx +16 -0
- package/src/routes/__root.tsx +45 -0
- package/src/routes/api/config.paths.ts +14 -0
- package/src/routes/api/config.ts +53 -0
- package/src/routes/api/health.ts +15 -0
- package/src/routes/api/knowledge.candidates.$candidateId.promote.ts +32 -0
- package/src/routes/api/knowledge.candidates.ts +10 -0
- package/src/routes/api/knowledge.project-context.ts +18 -0
- package/src/routes/api/knowledge.search.ts +31 -0
- package/src/routes/api/knowledge.sessions.$sessionId.candidates.ts +16 -0
- package/src/routes/api/logs.$id.chunks.ts +36 -0
- package/src/routes/api/logs.$id.replay.ts +191 -0
- package/src/routes/api/logs.$id.ts +22 -0
- package/src/routes/api/logs.stream.ts +74 -0
- package/src/routes/api/logs.ts +59 -0
- package/src/routes/api/mcp.ts +25 -0
- package/src/routes/api/models.ts +10 -0
- package/src/routes/api/providers.$providerId.test.log.ts +293 -0
- package/src/routes/api/providers.$providerId.ts +50 -0
- package/src/routes/api/providers.export.ts +26 -0
- package/src/routes/api/providers.import.ts +47 -0
- package/src/routes/api/providers.scan.ts +23 -0
- package/src/routes/api/providers.ts +45 -0
- package/src/routes/api/sessions.ts +17 -0
- package/src/routes/index.tsx +6 -0
- package/src/routes/proxy/$.ts +15 -0
- package/src/routes/session/$sessionId.tsx +23 -0
- package/styles/globals.css +188 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { type JSX, memo, useMemo } from "react";
|
|
2
|
+
import { cn, formatTokens } from "../../../lib/utils";
|
|
3
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../../ui/tooltip";
|
|
4
|
+
import type { AnatomyRole, AnatomySegment } from "./types";
|
|
5
|
+
|
|
6
|
+
const ROLE_COLOR_CLASSES: Record<AnatomyRole, string> = {
|
|
7
|
+
system: "bg-sky-500/70",
|
|
8
|
+
user: "bg-emerald-500/70",
|
|
9
|
+
assistant: "bg-violet-500/70",
|
|
10
|
+
tool: "bg-amber-500/70",
|
|
11
|
+
tools: "bg-slate-500/70",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const ROLE_FOCUS_RING: Record<AnatomyRole, string> = {
|
|
15
|
+
system: "focus-visible:ring-sky-300",
|
|
16
|
+
user: "focus-visible:ring-emerald-300",
|
|
17
|
+
assistant: "focus-visible:ring-violet-300",
|
|
18
|
+
tool: "focus-visible:ring-amber-300",
|
|
19
|
+
tools: "focus-visible:ring-slate-300",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const MAX_VISIBLE_SEGMENTS = 12;
|
|
23
|
+
const MIN_SEGMENT_PERCENT = 1;
|
|
24
|
+
|
|
25
|
+
const TOOLTIP_PREVIEW_LIMIT = 80;
|
|
26
|
+
const LABEL_TRUNCATE_LIMIT = 24;
|
|
27
|
+
|
|
28
|
+
function truncateLabel(label: string): string {
|
|
29
|
+
if (label.length <= LABEL_TRUNCATE_LIMIT) return label;
|
|
30
|
+
return `${label.slice(0, LABEL_TRUNCATE_LIMIT - 1)}…`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function truncatePreview(text: string): string {
|
|
34
|
+
const singleLine = text.replace(/\s+/g, " ").trim();
|
|
35
|
+
if (singleLine.length <= TOOLTIP_PREVIEW_LIMIT) return singleLine;
|
|
36
|
+
return `${singleLine.slice(0, TOOLTIP_PREVIEW_LIMIT)}…`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type SegmentBarProps = {
|
|
40
|
+
segments: ReadonlyArray<AnatomySegment>;
|
|
41
|
+
totalTokens: number;
|
|
42
|
+
onActivate?: (segment: AnatomySegment) => void;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Render a horizontal stacked bar showing the relative size of each
|
|
47
|
+
* request segment, with role-based color, per-segment labels, and
|
|
48
|
+
* an overflow pill that aggregates any segments beyond the visible
|
|
49
|
+
* cap. Click or keyboard activation (Enter / Space) calls `onActivate`.
|
|
50
|
+
*/
|
|
51
|
+
export const SegmentBar = memo(function SegmentBar({
|
|
52
|
+
segments,
|
|
53
|
+
totalTokens,
|
|
54
|
+
onActivate,
|
|
55
|
+
}: SegmentBarProps): JSX.Element {
|
|
56
|
+
const total = useMemo(() => {
|
|
57
|
+
if (totalTokens > 0) return totalTokens;
|
|
58
|
+
return segments.reduce((sum, s) => sum + s.size, 0);
|
|
59
|
+
}, [segments, totalTokens]);
|
|
60
|
+
|
|
61
|
+
const visibleSegments = segments.slice(0, MAX_VISIBLE_SEGMENTS);
|
|
62
|
+
const overflowSegments = segments.slice(MAX_VISIBLE_SEGMENTS);
|
|
63
|
+
const overflowSize = overflowSegments.reduce((sum, s) => sum + s.size, 0);
|
|
64
|
+
const overflowCount = overflowSegments.length;
|
|
65
|
+
const overflowStartIndex = MAX_VISIBLE_SEGMENTS;
|
|
66
|
+
const overflowEndIndex = overflowStartIndex + overflowCount - 1;
|
|
67
|
+
const hasOverflow = overflowCount > 0;
|
|
68
|
+
|
|
69
|
+
const visibleTotal = useMemo(
|
|
70
|
+
() => visibleSegments.reduce((sum, s) => sum + s.size, 0),
|
|
71
|
+
[visibleSegments],
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const ariaLabel = useMemo(
|
|
75
|
+
() =>
|
|
76
|
+
`Request anatomy: ~${formatTokens(total)} tokens across ${segments.length} segment${segments.length === 1 ? "" : "s"}`,
|
|
77
|
+
[segments.length, total],
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
if (segments.length === 0 || total <= 0) {
|
|
81
|
+
return <div role="img" aria-label={ariaLabel} className="h-6" />;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<TooltipProvider delayDuration={150}>
|
|
86
|
+
<div role="img" aria-label={ariaLabel} className="flex flex-col gap-1.5">
|
|
87
|
+
<div
|
|
88
|
+
className="relative flex h-6 w-full overflow-hidden rounded border border-border/40 bg-muted/30"
|
|
89
|
+
data-testid="anatomy-segment-bar"
|
|
90
|
+
>
|
|
91
|
+
{visibleSegments.map((segment, index) => {
|
|
92
|
+
const rawPercent = total > 0 ? (segment.size / total) * 100 : 0;
|
|
93
|
+
const percent = Math.max(MIN_SEGMENT_PERCENT, rawPercent);
|
|
94
|
+
return (
|
|
95
|
+
<Tooltip key={`${segment.path}-${index}`}>
|
|
96
|
+
<TooltipTrigger asChild>
|
|
97
|
+
<button
|
|
98
|
+
type="button"
|
|
99
|
+
role="button"
|
|
100
|
+
tabIndex={0}
|
|
101
|
+
onClick={() => onActivate?.(segment)}
|
|
102
|
+
onKeyDown={(e) => {
|
|
103
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
onActivate?.(segment);
|
|
106
|
+
}
|
|
107
|
+
}}
|
|
108
|
+
data-anatomy-path={segment.path}
|
|
109
|
+
aria-label={`${segment.label}, ~${formatTokens(segment.size)} tokens`}
|
|
110
|
+
className={cn(
|
|
111
|
+
"h-full border-r border-background/80 last:border-r-0",
|
|
112
|
+
"opacity-90 hover:opacity-100 focus:opacity-100",
|
|
113
|
+
"focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-offset-background",
|
|
114
|
+
ROLE_COLOR_CLASSES[segment.role],
|
|
115
|
+
ROLE_FOCUS_RING[segment.role],
|
|
116
|
+
)}
|
|
117
|
+
style={{ width: `${percent}%` }}
|
|
118
|
+
/>
|
|
119
|
+
</TooltipTrigger>
|
|
120
|
+
<TooltipContent side="bottom" className="max-w-sm text-xs p-2 space-y-0.5">
|
|
121
|
+
<div className="font-semibold">
|
|
122
|
+
{segment.label} · ~{formatTokens(segment.size)} tokens
|
|
123
|
+
</div>
|
|
124
|
+
<div className="text-muted-foreground">
|
|
125
|
+
{segment.characters.toLocaleString()} chars
|
|
126
|
+
</div>
|
|
127
|
+
{segment.text.length > 0 && (
|
|
128
|
+
<div className="text-muted-foreground/90 break-words whitespace-pre-wrap">
|
|
129
|
+
{truncatePreview(segment.text)}
|
|
130
|
+
</div>
|
|
131
|
+
)}
|
|
132
|
+
</TooltipContent>
|
|
133
|
+
</Tooltip>
|
|
134
|
+
);
|
|
135
|
+
})}
|
|
136
|
+
{hasOverflow && (
|
|
137
|
+
<Tooltip>
|
|
138
|
+
<TooltipTrigger asChild>
|
|
139
|
+
<div
|
|
140
|
+
role="img"
|
|
141
|
+
aria-label={`${overflowCount} additional segments`}
|
|
142
|
+
className="flex h-full items-center justify-center bg-muted-foreground/30 px-1.5 text-[10px] font-mono text-background"
|
|
143
|
+
style={{
|
|
144
|
+
width: `${Math.max(MIN_SEGMENT_PERCENT, (overflowSize / total) * 100)}%`,
|
|
145
|
+
}}
|
|
146
|
+
>
|
|
147
|
+
… +{overflowCount}
|
|
148
|
+
</div>
|
|
149
|
+
</TooltipTrigger>
|
|
150
|
+
<TooltipContent side="bottom" className="text-xs">
|
|
151
|
+
{overflowCount} more segment{overflowCount === 1 ? "" : "s"} (indices{" "}
|
|
152
|
+
{overflowStartIndex}–{overflowEndIndex})
|
|
153
|
+
</TooltipContent>
|
|
154
|
+
</Tooltip>
|
|
155
|
+
)}
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
<div className="flex w-full gap-1 text-[10px] text-muted-foreground">
|
|
159
|
+
{visibleSegments.map((segment, index) => {
|
|
160
|
+
const rawPercent = total > 0 ? (segment.size / total) * 100 : 0;
|
|
161
|
+
const percent = Math.max(MIN_SEGMENT_PERCENT, rawPercent);
|
|
162
|
+
return (
|
|
163
|
+
<div
|
|
164
|
+
key={`label-${segment.path}-${index}`}
|
|
165
|
+
className="flex flex-col gap-0.5 truncate"
|
|
166
|
+
style={{ width: `${percent}%` }}
|
|
167
|
+
title={`${segment.label} · ~${formatTokens(segment.size)} tokens`}
|
|
168
|
+
>
|
|
169
|
+
<span className="truncate font-mono text-foreground/80">
|
|
170
|
+
{truncateLabel(segment.label)}
|
|
171
|
+
</span>
|
|
172
|
+
<span className="truncate font-mono text-muted-foreground/70">
|
|
173
|
+
~{formatTokens(segment.size)}
|
|
174
|
+
</span>
|
|
175
|
+
</div>
|
|
176
|
+
);
|
|
177
|
+
})}
|
|
178
|
+
{hasOverflow && (
|
|
179
|
+
<div
|
|
180
|
+
className="flex flex-col gap-0.5 truncate text-muted-foreground"
|
|
181
|
+
style={{ width: `${Math.max(MIN_SEGMENT_PERCENT, (overflowSize / total) * 100)}%` }}
|
|
182
|
+
>
|
|
183
|
+
<span className="truncate font-mono text-foreground/60">… +{overflowCount}</span>
|
|
184
|
+
<span className="truncate font-mono text-muted-foreground/60">
|
|
185
|
+
~{formatTokens(overflowSize)}
|
|
186
|
+
</span>
|
|
187
|
+
</div>
|
|
188
|
+
)}
|
|
189
|
+
</div>
|
|
190
|
+
|
|
191
|
+
{/* Spacer to maintain minimum bar height for tiny segments */}
|
|
192
|
+
{visibleTotal < total * 0.1 && <div className="h-0" />}
|
|
193
|
+
</div>
|
|
194
|
+
</TooltipProvider>
|
|
195
|
+
);
|
|
196
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blended 4-chars-per-token heuristic with CJK / emoji adjustment.
|
|
3
|
+
*
|
|
4
|
+
* Rationale: Anthropic and OpenAI both document ~4 chars/token for
|
|
5
|
+
* English / Latin / punctuation. CJK characters, Hangul, kana, fullwidth
|
|
6
|
+
* forms, and emoji tokenize roughly 1:1 in practice. We use a simple
|
|
7
|
+
* two-bucket counter rather than a full BPE tokenizer to keep the
|
|
8
|
+
* estimate cheap and synchronous — the result is shown with a leading
|
|
9
|
+
* `~` so the user is never misled about precision.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** A single Unicode code-point character from `text`. */
|
|
13
|
+
function forEachCodePoint(text: string, visit: (ch: string) => void): void {
|
|
14
|
+
// `Array.from` iterates by code point, so surrogate pairs and
|
|
15
|
+
// combining marks stay together.
|
|
16
|
+
for (const ch of Array.from(text)) {
|
|
17
|
+
visit(ch);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const CJK_REGEX = /[\u3000-\u9FFF\uAC00-\uD7FF\uF900-\uFAFF\uFF00-\uFFEF\u{1F300}-\u{1FAFF}]/u;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Estimate the token count of a piece of text.
|
|
25
|
+
*
|
|
26
|
+
* - CJK / Hangul / kana / fullwidth / emoji → 1 token per character
|
|
27
|
+
* - Everything else → 1 token per 4 characters, rounded up
|
|
28
|
+
*
|
|
29
|
+
* Returns 0 for the empty string.
|
|
30
|
+
*/
|
|
31
|
+
export function estimateTokens(text: string): number {
|
|
32
|
+
if (text.length === 0) return 0;
|
|
33
|
+
let cjk = 0;
|
|
34
|
+
let other = 0;
|
|
35
|
+
forEachCodePoint(text, (ch) => {
|
|
36
|
+
if (CJK_REGEX.test(ch)) {
|
|
37
|
+
cjk += 1;
|
|
38
|
+
} else {
|
|
39
|
+
other += 1;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return Math.ceil(cjk * 1) + Math.ceil(other / 4);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Count Unicode code points in a string (graphemes ≈ characters for our purposes). */
|
|
46
|
+
export function countCharacters(text: string): number {
|
|
47
|
+
if (text.length === 0) return 0;
|
|
48
|
+
let n = 0;
|
|
49
|
+
forEachCodePoint(text, () => {
|
|
50
|
+
n += 1;
|
|
51
|
+
});
|
|
52
|
+
return n;
|
|
53
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Role of a request segment. Drives the segment's color in the anatomy bar.
|
|
3
|
+
*
|
|
4
|
+
* - `system`: the system prompt (Anthropic `system`, or leading system-role message in OpenAI)
|
|
5
|
+
* - `user`: a user-role message
|
|
6
|
+
* - `assistant`: an assistant-role message
|
|
7
|
+
* - `tool`: a tool-role message (OpenAI only — Anthropic uses tool_result blocks inside user messages)
|
|
8
|
+
* - `tools`: the synthetic "tool definitions" segment that aggregates the `tools` array
|
|
9
|
+
*/
|
|
10
|
+
export type AnatomyRole = "system" | "user" | "assistant" | "tool" | "tools";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A single segment of a request as visualized in the Anatomy tab.
|
|
14
|
+
*
|
|
15
|
+
* `path` is a JSON-pointer-style path into the parsed body
|
|
16
|
+
* (e.g. `/system`, `/messages/0`, `/tools`). The path is opaque to
|
|
17
|
+
* consumers — it is matched against the same path emitted by the
|
|
18
|
+
* request analyzer, and is used to drive click-to-jump in the
|
|
19
|
+
* `JsonViewer`. A `null` path is allowed for the synthetic `tools`
|
|
20
|
+
* segment in the rare case where the tools array cannot be located.
|
|
21
|
+
*/
|
|
22
|
+
export type AnatomySegment = {
|
|
23
|
+
/** Stable role used for color and label prefix. */
|
|
24
|
+
role: AnatomyRole;
|
|
25
|
+
/** Human-readable short label shown below the segment (e.g. "system", "[3] user", "tools"). */
|
|
26
|
+
label: string;
|
|
27
|
+
/** Estimated token count for this segment. Drives bar width. */
|
|
28
|
+
size: number;
|
|
29
|
+
/** Character count for this segment (raw text length). Used in the tooltip. */
|
|
30
|
+
characters: number;
|
|
31
|
+
/** Raw text of the segment used to compute `size`. Used in the tooltip preview. */
|
|
32
|
+
text: string;
|
|
33
|
+
/**
|
|
34
|
+
* JSON-pointer-style path into the parsed body (e.g. `/messages/3`).
|
|
35
|
+
* `null` when the segment does not correspond to a single node
|
|
36
|
+
* (e.g. the synthetic `tools` segment that aggregates the array).
|
|
37
|
+
*/
|
|
38
|
+
path: string;
|
|
39
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { type RefObject, useCallback, useRef } from "react";
|
|
2
|
+
import type { AnatomySegment } from "./types";
|
|
3
|
+
|
|
4
|
+
const HIGHLIGHT_DURATION_MS = 1200;
|
|
5
|
+
/**
|
|
6
|
+
* Cap on the number of animation frames we are willing to wait
|
|
7
|
+
* before giving up on finding the target row. Each frame is
|
|
8
|
+
* ~16ms at 60Hz, so 12 frames gives ~200ms — enough headroom for
|
|
9
|
+
* the cascade of `useEffect` -> `setExpanded` calls that fires
|
|
10
|
+
* for each ancestor on the way down to the target.
|
|
11
|
+
*/
|
|
12
|
+
const MAX_HIGHLIGHT_ATTEMPTS = 12;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Build a `jumpToSegment` callback that:
|
|
16
|
+
*
|
|
17
|
+
* 1. Optionally switches the active tab to the Request tab (so the
|
|
18
|
+
* target row is in the DOM and visible).
|
|
19
|
+
* 2. Asks the JSON viewer to expand the path's ancestors via the
|
|
20
|
+
* `expandToPath` prop (which is reset to `null` shortly after).
|
|
21
|
+
* 3. Polls via `requestAnimationFrame` for the target row to appear
|
|
22
|
+
* (the cascade of `useEffect` -> `setExpanded` calls needs
|
|
23
|
+
* multiple frames for deep paths), then scrolls the matching
|
|
24
|
+
* row into view and applies a 1.2 s primary-color ring
|
|
25
|
+
* highlight via a temporary class toggle.
|
|
26
|
+
*/
|
|
27
|
+
export function useAnatomyJump(options: {
|
|
28
|
+
/** Ref to the DOM root that contains the JSON tree rows. */
|
|
29
|
+
containerRef: RefObject<HTMLElement | null>;
|
|
30
|
+
/** Setter for the `JsonViewer`'s `expandToPath` prop. */
|
|
31
|
+
setExpandToPath: (path: string | null) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Optional hook called before the DOM lookup so the caller can
|
|
34
|
+
* make the Request tab active. The hook should be synchronous
|
|
35
|
+
* (it triggers a React state update which is flushed by the
|
|
36
|
+
* subsequent `requestAnimationFrame`).
|
|
37
|
+
*/
|
|
38
|
+
ensureTabActive?: () => void;
|
|
39
|
+
highlightMs?: number;
|
|
40
|
+
}): (segment: AnatomySegment) => void {
|
|
41
|
+
const { containerRef, setExpandToPath, ensureTabActive, highlightMs } = options;
|
|
42
|
+
const highlightTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
43
|
+
|
|
44
|
+
return useCallback(
|
|
45
|
+
(segment: AnatomySegment) => {
|
|
46
|
+
ensureTabActive?.();
|
|
47
|
+
|
|
48
|
+
// Trigger the JSON viewer to expand ancestors of this path.
|
|
49
|
+
// We pass the same path; the JsonViewer resets the prop via
|
|
50
|
+
// the caller clearing the state after the scroll lands.
|
|
51
|
+
setExpandToPath(segment.path);
|
|
52
|
+
|
|
53
|
+
const applyHighlight = (target: HTMLElement): void => {
|
|
54
|
+
target.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
55
|
+
target.classList.add(
|
|
56
|
+
"ring-2",
|
|
57
|
+
"ring-primary/60",
|
|
58
|
+
"ring-offset-1",
|
|
59
|
+
"ring-offset-background",
|
|
60
|
+
"rounded-sm",
|
|
61
|
+
"transition-shadow",
|
|
62
|
+
);
|
|
63
|
+
if (highlightTimer.current !== null) clearTimeout(highlightTimer.current);
|
|
64
|
+
highlightTimer.current = setTimeout(() => {
|
|
65
|
+
target.classList.remove(
|
|
66
|
+
"ring-2",
|
|
67
|
+
"ring-primary/60",
|
|
68
|
+
"ring-offset-1",
|
|
69
|
+
"ring-offset-background",
|
|
70
|
+
"rounded-sm",
|
|
71
|
+
"transition-shadow",
|
|
72
|
+
);
|
|
73
|
+
// Clear the expand signal AFTER the highlight fades so the
|
|
74
|
+
// user sees the tree in its final (expanded) state, not
|
|
75
|
+
// suddenly collapsing the moment we release control.
|
|
76
|
+
setExpandToPath(null);
|
|
77
|
+
}, highlightMs ?? HIGHLIGHT_DURATION_MS);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const escape = (value: string): string => {
|
|
81
|
+
if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
|
|
82
|
+
return CSS.escape(value);
|
|
83
|
+
}
|
|
84
|
+
return value.replace(/(["'\\[\](){}])/g, "\\$1");
|
|
85
|
+
};
|
|
86
|
+
const selector = `[data-anatomy-path="${escape(segment.path)}"]`;
|
|
87
|
+
|
|
88
|
+
const tryFindTarget = (attemptsLeft: number): void => {
|
|
89
|
+
const container = containerRef.current;
|
|
90
|
+
if (container !== null) {
|
|
91
|
+
const target = container.querySelector<HTMLElement>(selector);
|
|
92
|
+
if (target !== null) {
|
|
93
|
+
applyHighlight(target);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (attemptsLeft > 0) {
|
|
98
|
+
window.requestAnimationFrame(() => tryFindTarget(attemptsLeft - 1));
|
|
99
|
+
} else {
|
|
100
|
+
// Path not in the DOM after a generous wait — reset state
|
|
101
|
+
// and bail. This is the right behavior for malformed paths
|
|
102
|
+
// (e.g. when the format adapter returns a path that does
|
|
103
|
+
// not exist in the current request body).
|
|
104
|
+
setExpandToPath(null);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// Wait one frame for the tab-switch / expandToPath state
|
|
109
|
+
// update to commit before we start probing the DOM.
|
|
110
|
+
window.requestAnimationFrame(() => tryFindTarget(MAX_HIGHLIGHT_ATTEMPTS));
|
|
111
|
+
},
|
|
112
|
+
[containerRef, ensureTabActive, highlightMs, setExpandToPath],
|
|
113
|
+
);
|
|
114
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ConversationGroupData } from "./ConversationHeader";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Trend direction for a single cache token field, comparing the current log
|
|
5
|
+
* to the previous log in the same conversation group.
|
|
6
|
+
*/
|
|
7
|
+
export type CacheTrend = { direction: "up" | "down"; delta: number };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Per-log trend entry. `creation` covers `cacheCreationInputTokens`,
|
|
11
|
+
* `read` covers `cacheReadInputTokens`. Each field is `null` when there is
|
|
12
|
+
* no previous log to compare against, when the current log has no value for
|
|
13
|
+
* the field, or when the values are equal (no visual change).
|
|
14
|
+
*/
|
|
15
|
+
export type CacheTrendEntry = { creation: CacheTrend | null; read: CacheTrend | null };
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Build a `logId -> CacheTrendEntry` map for every log that has a previous
|
|
19
|
+
* log in its conversation group. Pure: does not mutate `groups`. Walks each
|
|
20
|
+
* group in array order (which is the timestamp-sorted order produced by
|
|
21
|
+
* `groupLogsByConversation`), so "previous log" is the adjacent entry in
|
|
22
|
+
* that order.
|
|
23
|
+
*/
|
|
24
|
+
export function computeCacheTrends(groups: ConversationGroupData[]): Map<number, CacheTrendEntry> {
|
|
25
|
+
const result = new Map<number, CacheTrendEntry>();
|
|
26
|
+
|
|
27
|
+
for (const group of groups) {
|
|
28
|
+
const logs = group.logs;
|
|
29
|
+
for (let i = 1; i < logs.length; i++) {
|
|
30
|
+
const prev = logs[i - 1];
|
|
31
|
+
const curr = logs[i];
|
|
32
|
+
if (prev === undefined || curr === undefined) continue;
|
|
33
|
+
|
|
34
|
+
result.set(curr.id, {
|
|
35
|
+
creation: compareField(prev.cacheCreationInputTokens, curr.cacheCreationInputTokens),
|
|
36
|
+
read: compareField(prev.cacheReadInputTokens, curr.cacheReadInputTokens),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function compareField(previous: number | null, current: number | null): CacheTrend | null {
|
|
45
|
+
if (current === null) return null;
|
|
46
|
+
if (previous === null) return null;
|
|
47
|
+
if (current > previous) return { direction: "up", delta: current - previous };
|
|
48
|
+
if (current < previous) return { direction: "down", delta: previous - current };
|
|
49
|
+
return null;
|
|
50
|
+
}
|