@hcu-lab.me/mcp-device 1.0.9 → 1.0.12
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/PRIVACY.md +21 -0
- package/README.md +58 -3
- package/SECURITY.md +67 -0
- package/config/revoked-approvals.json +1 -0
- package/control-plane/config/mcp-servers.example.toml +52 -0
- package/control-plane/config/mcp-servers.toml +52 -0
- package/control-plane/contracts/device-public-contract-v1.json +733 -0
- package/control-plane/scripts/GATEWAY-LICENSE.txt +7 -0
- package/control-plane/scripts/account-http.mjs +220 -0
- package/control-plane/scripts/account-store.mjs +368 -0
- package/control-plane/scripts/admin.mjs +68 -0
- package/control-plane/scripts/auth-session.mjs +411 -0
- package/control-plane/scripts/authenticated-mcp-wrapper.mjs +1281 -0
- package/control-plane/scripts/benchmark-command.mjs +9 -0
- package/control-plane/scripts/benchmark-mcp-catalog.mjs +174 -0
- package/control-plane/scripts/catalog-budget.mjs +87 -0
- package/control-plane/scripts/check-device-public-contract.mjs +20 -0
- package/control-plane/scripts/custom-tools/index.mjs +221 -0
- package/control-plane/scripts/custom-tools/path-utils.mjs +117 -0
- package/control-plane/scripts/custom-tools/response-utils.mjs +34 -0
- package/control-plane/scripts/dashboard-http.mjs +598 -0
- package/control-plane/scripts/device-access-policy.mjs +205 -0
- package/control-plane/scripts/device-admin.mjs +43 -0
- package/control-plane/scripts/device-audit.mjs +63 -0
- package/control-plane/scripts/device-broker.mjs +1461 -0
- package/control-plane/scripts/device-execution-tool-definitions.mjs +217 -0
- package/control-plane/scripts/device-inventory.mjs +128 -0
- package/control-plane/scripts/device-pairing-http.mjs +109 -0
- package/control-plane/scripts/device-pairing-store.mjs +245 -0
- package/control-plane/scripts/device-public-contract.mjs +165 -0
- package/control-plane/scripts/device-release.mjs +95 -0
- package/control-plane/scripts/device-secure-transport.mjs +128 -0
- package/control-plane/scripts/device-store.mjs +283 -0
- package/control-plane/scripts/device-usage.mjs +657 -0
- package/control-plane/scripts/embedded-device.mjs +149 -0
- package/control-plane/scripts/enduser-ui.mjs +45 -0
- package/control-plane/scripts/external-tool-broker.mjs +179 -0
- package/control-plane/scripts/oauth-authorization-server.mjs +589 -0
- package/control-plane/scripts/operator-dashboard-http.mjs +81 -0
- package/control-plane/scripts/project-inspection.mjs +227 -0
- package/control-plane/scripts/projects/project-id.mjs +69 -0
- package/control-plane/scripts/projects/trusted-roots-projects.mjs +375 -0
- package/control-plane/scripts/prompts/index.mjs +60 -0
- package/control-plane/scripts/remote-process-sessions.mjs +78 -0
- package/control-plane/scripts/remote-tool-result.mjs +9 -0
- package/control-plane/scripts/resources/index.mjs +166 -0
- package/control-plane/scripts/runtime-profile.mjs +54 -0
- package/control-plane/scripts/shell-tool-descriptor.mjs +17 -0
- package/control-plane/scripts/skill-source-safety.mjs +46 -0
- package/control-plane/scripts/skills/README.md +70 -0
- package/control-plane/scripts/skills/_upstream_licenses/anthropic-THIRD_PARTY_NOTICES.md +405 -0
- package/control-plane/scripts/skills/_upstream_licenses/hallmark-LICENSE.txt +21 -0
- package/control-plane/scripts/skills/_upstream_licenses/ponytail-LICENSE.txt +21 -0
- package/control-plane/scripts/skills/_upstream_licenses/stitch-skills-LICENSE.txt +201 -0
- package/control-plane/scripts/skills/_upstream_licenses/superpowers-LICENSE.txt +21 -0
- package/control-plane/scripts/skills/algorithmic-art/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/algorithmic-art/SKILL.md +405 -0
- package/control-plane/scripts/skills/algorithmic-art/templates/generator_template.js +223 -0
- package/control-plane/scripts/skills/algorithmic-art/templates/viewer.html +599 -0
- package/control-plane/scripts/skills/brainstorming/SKILL.md +285 -0
- package/control-plane/scripts/skills/brainstorming/scripts/frame-template.html +213 -0
- package/control-plane/scripts/skills/brainstorming/scripts/helper.js +167 -0
- package/control-plane/scripts/skills/brainstorming/scripts/server.cjs +723 -0
- package/control-plane/scripts/skills/brainstorming/scripts/start-server.sh +209 -0
- package/control-plane/scripts/skills/brainstorming/scripts/stop-server.sh +120 -0
- package/control-plane/scripts/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/control-plane/scripts/skills/brainstorming/visual-companion.md +299 -0
- package/control-plane/scripts/skills/brand-guidelines/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/brand-guidelines/SKILL.md +73 -0
- package/control-plane/scripts/skills/claude-api/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/claude-api/SKILL.md +570 -0
- package/control-plane/scripts/skills/claude-api/csharp/claude-api/README.md +362 -0
- package/control-plane/scripts/skills/claude-api/csharp/claude-api/batches.md +14 -0
- package/control-plane/scripts/skills/claude-api/csharp/claude-api/files-api.md +25 -0
- package/control-plane/scripts/skills/claude-api/csharp/claude-api/streaming.md +28 -0
- package/control-plane/scripts/skills/claude-api/csharp/claude-api/tool-use.md +164 -0
- package/control-plane/scripts/skills/claude-api/curl/examples.md +256 -0
- package/control-plane/scripts/skills/claude-api/curl/managed-agents.md +371 -0
- package/control-plane/scripts/skills/claude-api/go/claude-api/README.md +188 -0
- package/control-plane/scripts/skills/claude-api/go/claude-api/files-api.md +23 -0
- package/control-plane/scripts/skills/claude-api/go/claude-api/streaming.md +43 -0
- package/control-plane/scripts/skills/claude-api/go/claude-api/tool-use.md +220 -0
- package/control-plane/scripts/skills/claude-api/go/managed-agents/README.md +564 -0
- package/control-plane/scripts/skills/claude-api/java/claude-api/README.md +238 -0
- package/control-plane/scripts/skills/claude-api/java/claude-api/files-api.md +27 -0
- package/control-plane/scripts/skills/claude-api/java/claude-api/streaming.md +24 -0
- package/control-plane/scripts/skills/claude-api/java/claude-api/tool-use.md +228 -0
- package/control-plane/scripts/skills/claude-api/java/managed-agents/README.md +443 -0
- package/control-plane/scripts/skills/claude-api/php/claude-api/README.md +174 -0
- package/control-plane/scripts/skills/claude-api/php/claude-api/batches.md +15 -0
- package/control-plane/scripts/skills/claude-api/php/claude-api/files-api.md +13 -0
- package/control-plane/scripts/skills/claude-api/php/claude-api/streaming.md +27 -0
- package/control-plane/scripts/skills/claude-api/php/claude-api/tool-use.md +253 -0
- package/control-plane/scripts/skills/claude-api/php/managed-agents/README.md +443 -0
- package/control-plane/scripts/skills/claude-api/python/claude-api/README.md +565 -0
- package/control-plane/scripts/skills/claude-api/python/claude-api/batches.md +198 -0
- package/control-plane/scripts/skills/claude-api/python/claude-api/files-api.md +170 -0
- package/control-plane/scripts/skills/claude-api/python/claude-api/sdk-upgrade.md +286 -0
- package/control-plane/scripts/skills/claude-api/python/claude-api/streaming.md +179 -0
- package/control-plane/scripts/skills/claude-api/python/claude-api/tool-use.md +627 -0
- package/control-plane/scripts/skills/claude-api/python/managed-agents/README.md +335 -0
- package/control-plane/scripts/skills/claude-api/ruby/claude-api/README.md +134 -0
- package/control-plane/scripts/skills/claude-api/ruby/claude-api/streaming.md +16 -0
- package/control-plane/scripts/skills/claude-api/ruby/claude-api/tool-use.md +41 -0
- package/control-plane/scripts/skills/claude-api/ruby/managed-agents/README.md +394 -0
- package/control-plane/scripts/skills/claude-api/shared/admin-api.md +179 -0
- package/control-plane/scripts/skills/claude-api/shared/agent-design.md +101 -0
- package/control-plane/scripts/skills/claude-api/shared/anthropic-cli.md +269 -0
- package/control-plane/scripts/skills/claude-api/shared/claude-platform-on-aws.md +59 -0
- package/control-plane/scripts/skills/claude-api/shared/cost-optimization.md +233 -0
- package/control-plane/scripts/skills/claude-api/shared/error-codes.md +262 -0
- package/control-plane/scripts/skills/claude-api/shared/live-sources.md +166 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-api-reference.md +455 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-client-patterns.md +220 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-core.md +359 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-environments.md +226 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-events.md +290 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-memory.md +201 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-multiagent.md +260 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-onboarding.md +82 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-outcomes.md +108 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-overview.md +77 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-scheduled-deployments.md +156 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-self-hosted-sandboxes.md +282 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-tools.md +504 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-webhooks.md +143 -0
- package/control-plane/scripts/skills/claude-api/shared/model-migration.md +1872 -0
- package/control-plane/scripts/skills/claude-api/shared/models.md +142 -0
- package/control-plane/scripts/skills/claude-api/shared/platform-availability.md +52 -0
- package/control-plane/scripts/skills/claude-api/shared/prompt-audit.md +223 -0
- package/control-plane/scripts/skills/claude-api/shared/prompt-caching.md +292 -0
- package/control-plane/scripts/skills/claude-api/shared/token-counting.md +56 -0
- package/control-plane/scripts/skills/claude-api/shared/tool-use-concepts.md +526 -0
- package/control-plane/scripts/skills/claude-api/typescript/claude-api/README.md +405 -0
- package/control-plane/scripts/skills/claude-api/typescript/claude-api/batches.md +106 -0
- package/control-plane/scripts/skills/claude-api/typescript/claude-api/files-api.md +98 -0
- package/control-plane/scripts/skills/claude-api/typescript/claude-api/streaming.md +178 -0
- package/control-plane/scripts/skills/claude-api/typescript/claude-api/tool-use.md +586 -0
- package/control-plane/scripts/skills/claude-api/typescript/managed-agents/README.md +359 -0
- package/control-plane/scripts/skills/dispatching-parallel-agents/SKILL.md +167 -0
- package/control-plane/scripts/skills/enhance-prompt/README.md +34 -0
- package/control-plane/scripts/skills/enhance-prompt/SKILL.md +204 -0
- package/control-plane/scripts/skills/enhance-prompt/references/KEYWORDS.md +114 -0
- package/control-plane/scripts/skills/executing-plans/SKILL.md +371 -0
- package/control-plane/scripts/skills/executing-plans/scripts/task-done +52 -0
- package/control-plane/scripts/skills/executing-plans/scripts/task-start +28 -0
- package/control-plane/scripts/skills/extract-design-md/SKILL.md +358 -0
- package/control-plane/scripts/skills/extract-design-md/examples/DESIGN.md +210 -0
- package/control-plane/scripts/skills/extract-design-md/references/angular.md +122 -0
- package/control-plane/scripts/skills/extract-design-md/references/plain-css.md +161 -0
- package/control-plane/scripts/skills/extract-design-md/references/react-tailwind.md +157 -0
- package/control-plane/scripts/skills/extract-design-md/references/svelte.md +101 -0
- package/control-plane/scripts/skills/extract-design-md/references/vue.md +107 -0
- package/control-plane/scripts/skills/finishing-a-development-branch/SKILL.md +225 -0
- package/control-plane/scripts/skills/frontend-design/LICENSE.txt +177 -0
- package/control-plane/scripts/skills/frontend-design/SKILL.md +71 -0
- package/control-plane/scripts/skills/hallmark/SKILL.md +558 -0
- package/control-plane/scripts/skills/hallmark/references/anti-patterns.md +418 -0
- package/control-plane/scripts/skills/hallmark/references/assets.md +406 -0
- package/control-plane/scripts/skills/hallmark/references/color.md +95 -0
- package/control-plane/scripts/skills/hallmark/references/component-cookbook.md +263 -0
- package/control-plane/scripts/skills/hallmark/references/components/c1-outlined-chip.md +12 -0
- package/control-plane/scripts/skills/hallmark/references/components/c2-inline-form-as-cta.md +16 -0
- package/control-plane/scripts/skills/hallmark/references/components/c3-typographic-link.md +8 -0
- package/control-plane/scripts/skills/hallmark/references/components/c4-sticky-bottom-bar.md +16 -0
- package/control-plane/scripts/skills/hallmark/references/components/f1-bento-grid.md +20 -0
- package/control-plane/scripts/skills/hallmark/references/components/f2-sticky-scroll-stack.md +20 -0
- package/control-plane/scripts/skills/hallmark/references/components/f3-tabular-spec-sheet.md +11 -0
- package/control-plane/scripts/skills/hallmark/references/components/f4-step-sequence.md +11 -0
- package/control-plane/scripts/skills/hallmark/references/components/f5-annotated-screenshot.md +11 -0
- package/control-plane/scripts/skills/hallmark/references/components/f6-product-card-grid.md +41 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft1-mast-headed.md +13 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft2-inline-rule-single-line.md +10 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft3-index-style-category-list.md +12 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft4-dense-typographic.md +10 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft5-statement.md +21 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft6-letter-close.md +19 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft7-newsletter-first.md +27 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft8-marquee-scroll.md +25 -0
- package/control-plane/scripts/skills/hallmark/references/components/h1-marquee.md +15 -0
- package/control-plane/scripts/skills/hallmark/references/components/h2-split-diptych.md +15 -0
- package/control-plane/scripts/skills/hallmark/references/components/h3-quote-led.md +11 -0
- package/control-plane/scripts/skills/hallmark/references/components/h4-stat-led.md +14 -0
- package/control-plane/scripts/skills/hallmark/references/components/h5-letter-hero.md +11 -0
- package/control-plane/scripts/skills/hallmark/references/components/h6-photographic-fold.md +16 -0
- package/control-plane/scripts/skills/hallmark/references/components/h7-demo-video-clipped-by-viewport-edge.md +27 -0
- package/control-plane/scripts/skills/hallmark/references/components/h8-mockup-split-browser-framed.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/components/h9-custom-illustration-centerpiece.md +27 -0
- package/control-plane/scripts/skills/hallmark/references/components/n1-wordmark-2-links.md +12 -0
- package/control-plane/scripts/skills/hallmark/references/components/n10-floating-on-scroll-morph.md +19 -0
- package/control-plane/scripts/skills/hallmark/references/components/n11-mega-menu.md +40 -0
- package/control-plane/scripts/skills/hallmark/references/components/n12-banner-retract.md +34 -0
- package/control-plane/scripts/skills/hallmark/references/components/n13-inline-cmdk-pill.md +39 -0
- package/control-plane/scripts/skills/hallmark/references/components/n1b-saas-three-section.md +35 -0
- package/control-plane/scripts/skills/hallmark/references/components/n2-floating-chip.md +14 -0
- package/control-plane/scripts/skills/hallmark/references/components/n3-side-rail.md +14 -0
- package/control-plane/scripts/skills/hallmark/references/components/n4-hidden-behind-k.md +9 -0
- package/control-plane/scripts/skills/hallmark/references/components/n5-floating-pill.md +28 -0
- package/control-plane/scripts/skills/hallmark/references/components/n6-newspaper-masthead.md +24 -0
- package/control-plane/scripts/skills/hallmark/references/components/n7-brutal-slab.md +22 -0
- package/control-plane/scripts/skills/hallmark/references/components/n8-terminal-command.md +21 -0
- package/control-plane/scripts/skills/hallmark/references/components/n9-edge-aligned-minimal.md +17 -0
- package/control-plane/scripts/skills/hallmark/references/components/s1-left-margin-numbered.md +15 -0
- package/control-plane/scripts/skills/hallmark/references/components/s2-hanging.md +13 -0
- package/control-plane/scripts/skills/hallmark/references/components/s3-sticky-pinned.md +19 -0
- package/control-plane/scripts/skills/hallmark/references/components/s4-inline-no-break.md +11 -0
- package/control-plane/scripts/skills/hallmark/references/components/s5-bottom-anchored.md +13 -0
- package/control-plane/scripts/skills/hallmark/references/components/t1-pull-quote-with-marginalia.md +12 -0
- package/control-plane/scripts/skills/hallmark/references/components/t2-logo-wall-hairline.md +19 -0
- package/control-plane/scripts/skills/hallmark/references/components/t3-single-huge-quote.md +11 -0
- package/control-plane/scripts/skills/hallmark/references/components/t4-numbered-stat-strip.md +14 -0
- package/control-plane/scripts/skills/hallmark/references/contract.md +25 -0
- package/control-plane/scripts/skills/hallmark/references/copy.md +182 -0
- package/control-plane/scripts/skills/hallmark/references/custom-craft.md +626 -0
- package/control-plane/scripts/skills/hallmark/references/custom-theme.md +367 -0
- package/control-plane/scripts/skills/hallmark/references/design-md.md +116 -0
- package/control-plane/scripts/skills/hallmark/references/export-formats.md +329 -0
- package/control-plane/scripts/skills/hallmark/references/floating-nav.md +89 -0
- package/control-plane/scripts/skills/hallmark/references/genres/atmospheric.md +69 -0
- package/control-plane/scripts/skills/hallmark/references/genres/editorial.md +72 -0
- package/control-plane/scripts/skills/hallmark/references/genres/modern-minimal.md +71 -0
- package/control-plane/scripts/skills/hallmark/references/genres/playful.md +70 -0
- package/control-plane/scripts/skills/hallmark/references/hero-enrichment.md +475 -0
- package/control-plane/scripts/skills/hallmark/references/imagery-kit.md +170 -0
- package/control-plane/scripts/skills/hallmark/references/interaction-and-states.md +208 -0
- package/control-plane/scripts/skills/hallmark/references/layout-and-space.md +112 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/01-bento-grid.md +35 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/02-long-document.md +34 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/03-marquee-hero.md +31 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/04-stat-led.md +34 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/05-workbench.md +32 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/06-conversational-faq.md +33 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/07-manifesto.md +32 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/08-photographic.md +34 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/09-quote-led.md +32 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/10-specimen.md +32 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/11-catalogue.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/12-letter.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/13-index-first.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/14-narrative-workflow.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/15-split-studio.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/16-feature-stack.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/17-type-specimen.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/18-portfolio-grid.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/19-map-diagram.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/20-ecosystem-index.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/21-component-playground.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures.md +89 -0
- package/control-plane/scripts/skills/hallmark/references/microinteractions.md +258 -0
- package/control-plane/scripts/skills/hallmark/references/motion.md +109 -0
- package/control-plane/scripts/skills/hallmark/references/preview-examples.md +49 -0
- package/control-plane/scripts/skills/hallmark/references/responsive.md +138 -0
- package/control-plane/scripts/skills/hallmark/references/slop-test.md +192 -0
- package/control-plane/scripts/skills/hallmark/references/structure.md +160 -0
- package/control-plane/scripts/skills/hallmark/references/study.md +509 -0
- package/control-plane/scripts/skills/hallmark/references/themes/carnival.md +301 -0
- package/control-plane/scripts/skills/hallmark/references/themes/cobalt.md +146 -0
- package/control-plane/scripts/skills/hallmark/references/themes/grid.md +161 -0
- package/control-plane/scripts/skills/hallmark/references/themes/hum.md +403 -0
- package/control-plane/scripts/skills/hallmark/references/themes/lumen.md +478 -0
- package/control-plane/scripts/skills/hallmark/references/typography.md +243 -0
- package/control-plane/scripts/skills/hallmark/references/upstream/recipes.md +186 -0
- package/control-plane/scripts/skills/hallmark/references/upstream/study-examples.md +176 -0
- package/control-plane/scripts/skills/hallmark/references/upstream/tokens.css +1221 -0
- package/control-plane/scripts/skills/hallmark/references/verbs/audit.md +25 -0
- package/control-plane/scripts/skills/hallmark/references/verbs/redesign.md +269 -0
- package/control-plane/scripts/skills/human-comms/SKILL.md +29 -0
- package/control-plane/scripts/skills/index.mjs +432 -0
- package/control-plane/scripts/skills/internal-comms/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/internal-comms/SKILL.md +32 -0
- package/control-plane/scripts/skills/internal-comms/examples/3p-updates.md +47 -0
- package/control-plane/scripts/skills/internal-comms/examples/company-newsletter.md +65 -0
- package/control-plane/scripts/skills/internal-comms/examples/faq-answers.md +30 -0
- package/control-plane/scripts/skills/internal-comms/examples/general-comms.md +16 -0
- package/control-plane/scripts/skills/mcp-adapter.mjs +94 -0
- package/control-plane/scripts/skills/mcp-builder/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/mcp-builder/SKILL.md +236 -0
- package/control-plane/scripts/skills/mcp-builder/reference/evaluation.md +602 -0
- package/control-plane/scripts/skills/mcp-builder/reference/mcp_best_practices.md +249 -0
- package/control-plane/scripts/skills/mcp-builder/reference/node_mcp_server.md +970 -0
- package/control-plane/scripts/skills/mcp-builder/reference/python_mcp_server.md +719 -0
- package/control-plane/scripts/skills/mcp-builder/scripts/connections.py +151 -0
- package/control-plane/scripts/skills/mcp-builder/scripts/evaluation.py +373 -0
- package/control-plane/scripts/skills/mcp-builder/scripts/example_evaluation.xml +22 -0
- package/control-plane/scripts/skills/mcp-builder/scripts/requirements.txt +2 -0
- package/control-plane/scripts/skills/ponytail/SKILL.md +120 -0
- package/control-plane/scripts/skills/ponytail-audit/SKILL.md +41 -0
- package/control-plane/scripts/skills/ponytail-debt/SKILL.md +44 -0
- package/control-plane/scripts/skills/ponytail-gain/SKILL.md +50 -0
- package/control-plane/scripts/skills/ponytail-help/SKILL.md +71 -0
- package/control-plane/scripts/skills/ponytail-review/SKILL.md +57 -0
- package/control-plane/scripts/skills/receiving-code-review/SKILL.md +205 -0
- package/control-plane/scripts/skills/requesting-code-review/SKILL.md +95 -0
- package/control-plane/scripts/skills/requesting-code-review/code-reviewer.md +198 -0
- package/control-plane/scripts/skills/skill-creator/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/skill-creator/SKILL.md +485 -0
- package/control-plane/scripts/skills/skill-creator/agents/analyzer.md +274 -0
- package/control-plane/scripts/skills/skill-creator/agents/comparator.md +202 -0
- package/control-plane/scripts/skills/skill-creator/agents/grader.md +223 -0
- package/control-plane/scripts/skills/skill-creator/assets/eval_review.html +146 -0
- package/control-plane/scripts/skills/skill-creator/eval-viewer/generate_review.py +471 -0
- package/control-plane/scripts/skills/skill-creator/eval-viewer/viewer.html +1325 -0
- package/control-plane/scripts/skills/skill-creator/references/schemas.md +430 -0
- package/control-plane/scripts/skills/skill-creator/scripts/__init__.py +0 -0
- package/control-plane/scripts/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
- package/control-plane/scripts/skills/skill-creator/scripts/generate_report.py +326 -0
- package/control-plane/scripts/skills/skill-creator/scripts/improve_description.py +247 -0
- package/control-plane/scripts/skills/skill-creator/scripts/package_skill.py +136 -0
- package/control-plane/scripts/skills/skill-creator/scripts/quick_validate.py +103 -0
- package/control-plane/scripts/skills/skill-creator/scripts/run_eval.py +310 -0
- package/control-plane/scripts/skills/skill-creator/scripts/run_loop.py +328 -0
- package/control-plane/scripts/skills/skill-creator/scripts/utils.py +47 -0
- package/control-plane/scripts/skills/slack-gif-creator/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/slack-gif-creator/SKILL.md +254 -0
- package/control-plane/scripts/skills/slack-gif-creator/core/easing.py +234 -0
- package/control-plane/scripts/skills/slack-gif-creator/core/frame_composer.py +176 -0
- package/control-plane/scripts/skills/slack-gif-creator/core/gif_builder.py +269 -0
- package/control-plane/scripts/skills/slack-gif-creator/core/validators.py +136 -0
- package/control-plane/scripts/skills/slack-gif-creator/requirements.txt +4 -0
- package/control-plane/scripts/skills/sources.json +401 -0
- package/control-plane/scripts/skills/sources.lock.json +416 -0
- package/control-plane/scripts/skills/subagent-driven-development/SKILL.md +570 -0
- package/control-plane/scripts/skills/subagent-driven-development/implementer-prompt.md +154 -0
- package/control-plane/scripts/skills/subagent-driven-development/re-review-prompt.md +115 -0
- package/control-plane/scripts/skills/subagent-driven-development/scripts/review-package +53 -0
- package/control-plane/scripts/skills/subagent-driven-development/scripts/sdd-workspace +82 -0
- package/control-plane/scripts/skills/subagent-driven-development/scripts/task-brief +43 -0
- package/control-plane/scripts/skills/subagent-driven-development/task-reviewer-prompt.md +207 -0
- package/control-plane/scripts/skills/systematic-debugging/CREATION-LOG.md +119 -0
- package/control-plane/scripts/skills/systematic-debugging/SKILL.md +283 -0
- package/control-plane/scripts/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/control-plane/scripts/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/control-plane/scripts/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/control-plane/scripts/skills/systematic-debugging/find-polluter.sh +72 -0
- package/control-plane/scripts/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/control-plane/scripts/skills/systematic-debugging/test-academic.md +14 -0
- package/control-plane/scripts/skills/systematic-debugging/test-pressure-1.md +58 -0
- package/control-plane/scripts/skills/systematic-debugging/test-pressure-2.md +68 -0
- package/control-plane/scripts/skills/systematic-debugging/test-pressure-3.md +69 -0
- package/control-plane/scripts/skills/test-driven-development/SKILL.md +330 -0
- package/control-plane/scripts/skills/test-driven-development/writing-good-tests.md +198 -0
- package/control-plane/scripts/skills/theme-factory/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/theme-factory/SKILL.md +59 -0
- package/control-plane/scripts/skills/theme-factory/theme-showcase.pdf +0 -0
- package/control-plane/scripts/skills/theme-factory/themes/arctic-frost.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/botanical-garden.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/desert-rose.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/forest-canopy.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/golden-hour.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/midnight-galaxy.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/modern-minimalist.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/ocean-depths.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/sunset-boulevard.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/tech-innovation.md +19 -0
- package/control-plane/scripts/skills/using-git-worktrees/SKILL.md +167 -0
- package/control-plane/scripts/skills/verification-before-completion/SKILL.md +120 -0
- package/control-plane/scripts/skills/web-artifacts-builder/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/web-artifacts-builder/SKILL.md +74 -0
- package/control-plane/scripts/skills/web-artifacts-builder/scripts/bundle-artifact.sh +54 -0
- package/control-plane/scripts/skills/web-artifacts-builder/scripts/init-artifact.sh +322 -0
- package/control-plane/scripts/skills/web-artifacts-builder/scripts/shadcn-components.tar.gz +0 -0
- package/control-plane/scripts/skills/webapp-testing/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/webapp-testing/SKILL.md +96 -0
- package/control-plane/scripts/skills/webapp-testing/examples/console_logging.py +35 -0
- package/control-plane/scripts/skills/webapp-testing/examples/element_discovery.py +40 -0
- package/control-plane/scripts/skills/webapp-testing/examples/static_html_automation.py +33 -0
- package/control-plane/scripts/skills/webapp-testing/scripts/with_server.py +106 -0
- package/control-plane/scripts/skills/writing-plans/SKILL.md +192 -0
- package/control-plane/scripts/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
- package/control-plane/scripts/skills/writing-skills/SKILL.md +681 -0
- package/control-plane/scripts/skills/writing-skills/anthropic-best-practices.md +1150 -0
- package/control-plane/scripts/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +189 -0
- package/control-plane/scripts/skills/writing-skills/graphviz-conventions.dot +172 -0
- package/control-plane/scripts/skills/writing-skills/persuasion-principles.md +187 -0
- package/control-plane/scripts/skills/writing-skills/render-graphs.js +169 -0
- package/control-plane/scripts/skills/writing-skills/testing-skills-with-subagents.md +384 -0
- package/control-plane/scripts/smoke-mcp-schemas.mjs +30 -0
- package/control-plane/scripts/surface-config.mjs +45 -0
- package/control-plane/scripts/sync-skills.mjs +370 -0
- package/control-plane/scripts/tool-metrics.mjs +74 -0
- package/control-plane/scripts/tool-risk.mjs +156 -0
- package/control-plane/scripts/tool-surface-stability.mjs +38 -0
- package/control-plane/scripts/upstreams/catalog-cache.mjs +28 -0
- package/control-plane/scripts/upstreams/config.mjs +158 -0
- package/control-plane/scripts/upstreams/diagnostics.mjs +21 -0
- package/control-plane/scripts/upstreams/http-client.mjs +67 -0
- package/control-plane/scripts/upstreams/manager.mjs +535 -0
- package/control-plane/scripts/upstreams/names.mjs +55 -0
- package/control-plane/scripts/upstreams/presets.mjs +60 -0
- package/control-plane/scripts/upstreams/resource-uri.mjs +29 -0
- package/control-plane/scripts/upstreams/stdio-client.mjs +73 -0
- package/control-plane/scripts/workspace-registry.mjs +147 -0
- package/dist/context/authorization.d.ts +5 -0
- package/dist/context/authorization.js +70 -0
- package/dist/context/capture.d.ts +46 -0
- package/dist/context/capture.js +187 -0
- package/dist/context/cli.d.ts +47 -0
- package/dist/context/cli.js +287 -0
- package/dist/context/device-adapter.d.ts +102 -0
- package/dist/context/device-adapter.js +79 -0
- package/dist/context/gateway.d.ts +354 -0
- package/dist/context/gateway.js +50 -0
- package/dist/context/graph.d.ts +63 -0
- package/dist/context/graph.js +214 -0
- package/dist/context/importer.d.ts +8 -0
- package/dist/context/importer.js +69 -0
- package/dist/context/indexer.d.ts +14 -0
- package/dist/context/indexer.js +57 -0
- package/dist/context/migrations/index.d.ts +4 -0
- package/dist/context/migrations/index.js +87 -0
- package/dist/context/redact.d.ts +15 -0
- package/dist/context/redact.js +43 -0
- package/dist/context/repositories.d.ts +9 -0
- package/dist/context/repositories.js +45 -0
- package/dist/context/search.d.ts +63 -0
- package/dist/context/search.js +207 -0
- package/dist/context/service.d.ts +278 -0
- package/dist/context/service.js +160 -0
- package/dist/context/store.d.ts +134 -0
- package/dist/context/store.js +722 -0
- package/dist/context/text.d.ts +4 -0
- package/dist/context/text.js +14 -0
- package/dist/context/tool-contract.d.ts +534 -0
- package/dist/context/tool-contract.js +45 -0
- package/dist/device/core.d.ts +29 -0
- package/dist/device/core.js +66 -0
- package/dist/device/device.d.ts +5 -0
- package/dist/device/device.js +94 -37
- package/dist/device/gateway-channel.d.ts +8 -1
- package/dist/device/gateway-channel.js +51 -3
- package/dist/device/gateway-tool-adapter.d.ts +11 -3
- package/dist/device/gateway-tool-adapter.js +141 -98
- package/dist/device/official-trust.d.ts +12 -0
- package/dist/device/official-trust.js +25 -1
- package/dist/device/runtime-owner.js +9 -1
- package/dist/distribution.d.ts +4 -0
- package/dist/distribution.js +8 -0
- package/dist/handlers/filesystem-handlers.js +53 -37
- package/dist/handlers/search-handlers.d.ts +1 -0
- package/dist/handlers/search-handlers.js +51 -1
- package/dist/log-palace/cli.d.ts +7 -0
- package/dist/log-palace/cli.js +89 -0
- package/dist/log-palace/formats.d.ts +26 -0
- package/dist/log-palace/formats.js +126 -0
- package/dist/log-palace/store.d.ts +129 -0
- package/dist/log-palace/store.js +856 -0
- package/dist/mcp-device.d.ts +1 -1
- package/dist/mcp-device.js +28 -6
- package/dist/npm-scripts/remote.js +1 -0
- package/dist/platform/activity-journal.d.ts +16 -0
- package/dist/platform/activity-journal.js +68 -0
- package/dist/platform/cli.d.ts +1 -0
- package/dist/platform/cli.js +300 -0
- package/dist/platform/coordination-lock.d.ts +45 -0
- package/dist/platform/coordination-lock.js +233 -0
- package/dist/platform/device-runtime.d.ts +16 -0
- package/dist/platform/device-runtime.js +83 -0
- package/dist/platform/knowledge-contract.d.ts +46 -0
- package/dist/platform/knowledge-contract.js +1 -0
- package/dist/platform/knowledge-mcp.d.ts +29 -0
- package/dist/platform/knowledge-mcp.js +95 -0
- package/dist/platform/knowledge-router.d.ts +64 -0
- package/dist/platform/knowledge-router.js +320 -0
- package/dist/platform/plugin-child.d.ts +1 -0
- package/dist/platform/plugin-child.js +115 -0
- package/dist/platform/plugin-contract.d.ts +76 -0
- package/dist/platform/plugin-contract.js +53 -0
- package/dist/platform/plugin-driver.d.ts +8 -0
- package/dist/platform/plugin-driver.js +443 -0
- package/dist/platform/plugin-host.d.ts +88 -0
- package/dist/platform/plugin-host.js +817 -0
- package/dist/platform/plugin-policy.d.ts +3 -0
- package/dist/platform/plugin-policy.js +29 -0
- package/dist/platform/plugin-services.d.ts +14 -0
- package/dist/platform/plugin-services.js +32 -0
- package/dist/platform/process-identity.d.ts +9 -0
- package/dist/platform/process-identity.js +68 -0
- package/dist/platform/runtime-lease.d.ts +4 -0
- package/dist/platform/runtime-lease.js +58 -0
- package/dist/platform/runtime-root.d.ts +9 -0
- package/dist/platform/runtime-root.js +61 -0
- package/dist/platform/state-backup.d.ts +92 -0
- package/dist/platform/state-backup.js +399 -0
- package/dist/plugins/reference/plugin.d.ts +3 -0
- package/dist/plugins/reference/plugin.js +13 -0
- package/dist/search-manager.d.ts +6 -0
- package/dist/search-manager.js +123 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.js +7 -3
- package/dist/terminal-manager.d.ts +16 -0
- package/dist/terminal-manager.js +137 -42
- package/dist/tool-dispatcher.d.ts +11 -0
- package/dist/tool-dispatcher.js +228 -0
- package/dist/tools/edit.js +72 -1
- package/dist/tools/filesystem.d.ts +1 -1
- package/dist/tools/filesystem.js +2 -2
- package/dist/tools/improved-process-tools.js +91 -108
- package/dist/tools/schemas.d.ts +94 -2
- package/dist/tools/schemas.js +20 -6
- package/dist/types.d.ts +8 -0
- package/dist/utils/output-budget.d.ts +6 -0
- package/dist/utils/output-budget.js +15 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +29 -6
- package/skills/mcp-device-context/SKILL.md +40 -0
|
@@ -0,0 +1,657 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
4
|
+
|
|
5
|
+
const DEVICE_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
6
|
+
const TOKEN_ESTIMATION_METHOD = 'utf8_bytes_div_4_estimate';
|
|
7
|
+
|
|
8
|
+
function normalizeDeviceId(value) {
|
|
9
|
+
const deviceId = String(value || '').trim();
|
|
10
|
+
if (!DEVICE_ID_PATTERN.test(deviceId)) throw new Error('Invalid device_id.');
|
|
11
|
+
return deviceId;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function boundedText(value, max = 128, { required = false } = {}) {
|
|
15
|
+
const text = String(value || '').trim();
|
|
16
|
+
if (required && !text) throw new Error('Required usage identifier is missing.');
|
|
17
|
+
return text ? text.slice(0, max) : null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function bytes(value) {
|
|
21
|
+
const number = Number(value ?? 0);
|
|
22
|
+
if (!Number.isInteger(number) || number < 0 || number > 64 * 1024 * 1024) throw new Error('Usage byte count must be a bounded non-negative integer.');
|
|
23
|
+
return number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function duration(value) {
|
|
27
|
+
const number = Math.max(0, Math.floor(Number(value) || 0));
|
|
28
|
+
if (number > 24 * 60 * 60 * 1000) throw new Error('Usage duration is outside the bounded range.');
|
|
29
|
+
return number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function sinceMs(value) {
|
|
33
|
+
const number = Number(value ?? 0);
|
|
34
|
+
return Number.isFinite(number) && number > 0 ? Math.floor(number) : 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function timestampMs(value, fallback) {
|
|
38
|
+
if (typeof value === 'number' && Number.isFinite(value)) return Math.max(0, Math.floor(value));
|
|
39
|
+
if (value) {
|
|
40
|
+
const parsed = Date.parse(String(value));
|
|
41
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
42
|
+
}
|
|
43
|
+
return Number(fallback());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function rowToUsage(row) {
|
|
47
|
+
if (!row) {
|
|
48
|
+
return {
|
|
49
|
+
connections: 0,
|
|
50
|
+
reconnects: 0,
|
|
51
|
+
toolCallsStarted: 0,
|
|
52
|
+
toolCallsSucceeded: 0,
|
|
53
|
+
toolCallsFailed: 0,
|
|
54
|
+
requestBytes: 0,
|
|
55
|
+
responseBytes: 0,
|
|
56
|
+
lastSeenAt: null,
|
|
57
|
+
lastErrorCode: null
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
connections: Number(row.connections),
|
|
62
|
+
reconnects: Number(row.reconnects),
|
|
63
|
+
toolCallsStarted: Number(row.tool_calls_started),
|
|
64
|
+
toolCallsSucceeded: Number(row.tool_calls_succeeded),
|
|
65
|
+
toolCallsFailed: Number(row.tool_calls_failed),
|
|
66
|
+
requestBytes: Number(row.request_bytes),
|
|
67
|
+
responseBytes: Number(row.response_bytes),
|
|
68
|
+
lastSeenAt: Number(row.last_seen_at),
|
|
69
|
+
lastErrorCode: row.last_error_code || null
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function rowToActivity(row) {
|
|
74
|
+
if (!row) return null;
|
|
75
|
+
return {
|
|
76
|
+
activitySessionId: row.activity_session_id,
|
|
77
|
+
accountId: row.account_id,
|
|
78
|
+
clientId: row.client_id || null,
|
|
79
|
+
displayName: row.display_name || null,
|
|
80
|
+
startedAt: Number(row.started_at),
|
|
81
|
+
lastSeenAt: Number(row.last_seen_at),
|
|
82
|
+
endedAt: row.ended_at === null ? null : Number(row.ended_at)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function rowToSchema(row) {
|
|
87
|
+
if (!row) return { toolCount: 0, schemaBytes: 0, estimatedTokens: 0, estimationMethod: TOKEN_ESTIMATION_METHOD, updatedAt: null };
|
|
88
|
+
return {
|
|
89
|
+
toolCount: Number(row.tool_count),
|
|
90
|
+
schemaBytes: Number(row.schema_bytes),
|
|
91
|
+
estimatedTokens: Number(row.estimated_tokens),
|
|
92
|
+
estimationMethod: row.estimation_method,
|
|
93
|
+
updatedAt: Number(row.updated_at)
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function createDeviceUsageStore({ dbPath, now = () => Date.now() } = {}) {
|
|
98
|
+
if (!dbPath) throw new Error('dbPath is required for device usage store.');
|
|
99
|
+
const resolved = path.resolve(dbPath);
|
|
100
|
+
fs.mkdirSync(path.dirname(resolved), { recursive: true });
|
|
101
|
+
const db = new DatabaseSync(resolved);
|
|
102
|
+
db.exec(`
|
|
103
|
+
PRAGMA journal_mode = WAL;
|
|
104
|
+
PRAGMA synchronous = NORMAL;
|
|
105
|
+
PRAGMA busy_timeout = 5000;
|
|
106
|
+
CREATE TABLE IF NOT EXISTS device_usage (
|
|
107
|
+
device_id TEXT PRIMARY KEY,
|
|
108
|
+
connections INTEGER NOT NULL DEFAULT 0,
|
|
109
|
+
reconnects INTEGER NOT NULL DEFAULT 0,
|
|
110
|
+
tool_calls_started INTEGER NOT NULL DEFAULT 0,
|
|
111
|
+
tool_calls_succeeded INTEGER NOT NULL DEFAULT 0,
|
|
112
|
+
tool_calls_failed INTEGER NOT NULL DEFAULT 0,
|
|
113
|
+
request_bytes INTEGER NOT NULL DEFAULT 0,
|
|
114
|
+
response_bytes INTEGER NOT NULL DEFAULT 0,
|
|
115
|
+
last_seen_at INTEGER NOT NULL,
|
|
116
|
+
last_error_code TEXT
|
|
117
|
+
);
|
|
118
|
+
CREATE TABLE IF NOT EXISTS tool_call_events (
|
|
119
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
120
|
+
event_at INTEGER NOT NULL,
|
|
121
|
+
account_id TEXT,
|
|
122
|
+
activity_session_id TEXT,
|
|
123
|
+
device_id TEXT,
|
|
124
|
+
tool TEXT NOT NULL,
|
|
125
|
+
duration_ms INTEGER NOT NULL,
|
|
126
|
+
status TEXT NOT NULL CHECK(status IN ('success','error')),
|
|
127
|
+
error_code TEXT,
|
|
128
|
+
input_bytes INTEGER NOT NULL,
|
|
129
|
+
output_bytes INTEGER NOT NULL,
|
|
130
|
+
truncated INTEGER NOT NULL DEFAULT 0,
|
|
131
|
+
spill INTEGER NOT NULL DEFAULT 0,
|
|
132
|
+
caller_category TEXT,
|
|
133
|
+
upstream TEXT
|
|
134
|
+
);
|
|
135
|
+
CREATE INDEX IF NOT EXISTS tool_call_events_account_time_idx ON tool_call_events(account_id, event_at DESC, id DESC);
|
|
136
|
+
CREATE INDEX IF NOT EXISTS tool_call_events_account_device_time_idx ON tool_call_events(account_id, device_id, event_at DESC, id DESC);
|
|
137
|
+
CREATE INDEX IF NOT EXISTS tool_call_events_activity_idx ON tool_call_events(activity_session_id, event_at DESC, id DESC);
|
|
138
|
+
CREATE INDEX IF NOT EXISTS tool_call_events_account_tool_idx ON tool_call_events(account_id, tool);
|
|
139
|
+
CREATE TABLE IF NOT EXISTS skill_load_events (
|
|
140
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
141
|
+
event_at INTEGER NOT NULL,
|
|
142
|
+
account_id TEXT,
|
|
143
|
+
activity_session_id TEXT,
|
|
144
|
+
skill_name TEXT NOT NULL,
|
|
145
|
+
status TEXT NOT NULL CHECK(status IN ('success','error')),
|
|
146
|
+
error_code TEXT,
|
|
147
|
+
output_bytes INTEGER NOT NULL,
|
|
148
|
+
estimated_tokens INTEGER NOT NULL,
|
|
149
|
+
estimation_method TEXT NOT NULL
|
|
150
|
+
);
|
|
151
|
+
CREATE INDEX IF NOT EXISTS skill_load_events_account_time_idx ON skill_load_events(account_id, event_at DESC, id DESC);
|
|
152
|
+
CREATE TABLE IF NOT EXISTS activity_sessions (
|
|
153
|
+
activity_session_id TEXT PRIMARY KEY,
|
|
154
|
+
account_id TEXT NOT NULL,
|
|
155
|
+
client_id TEXT,
|
|
156
|
+
display_name TEXT,
|
|
157
|
+
started_at INTEGER NOT NULL,
|
|
158
|
+
last_seen_at INTEGER NOT NULL,
|
|
159
|
+
ended_at INTEGER
|
|
160
|
+
);
|
|
161
|
+
CREATE INDEX IF NOT EXISTS activity_sessions_account_idx ON activity_sessions(account_id, started_at DESC);
|
|
162
|
+
CREATE TABLE IF NOT EXISTS catalog_events (
|
|
163
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
164
|
+
event_at INTEGER NOT NULL,
|
|
165
|
+
account_id TEXT,
|
|
166
|
+
activity_session_id TEXT,
|
|
167
|
+
tool_count INTEGER NOT NULL,
|
|
168
|
+
schema_bytes INTEGER NOT NULL,
|
|
169
|
+
estimated_tokens INTEGER NOT NULL,
|
|
170
|
+
estimation_method TEXT NOT NULL
|
|
171
|
+
);
|
|
172
|
+
CREATE INDEX IF NOT EXISTS catalog_events_account_time_idx ON catalog_events(account_id, event_at DESC, id DESC);
|
|
173
|
+
CREATE TABLE IF NOT EXISTS gateway_schema_snapshot (
|
|
174
|
+
singleton INTEGER PRIMARY KEY CHECK(singleton = 1),
|
|
175
|
+
tool_count INTEGER NOT NULL,
|
|
176
|
+
schema_bytes INTEGER NOT NULL,
|
|
177
|
+
estimated_tokens INTEGER NOT NULL,
|
|
178
|
+
estimation_method TEXT NOT NULL,
|
|
179
|
+
updated_at INTEGER NOT NULL
|
|
180
|
+
);
|
|
181
|
+
CREATE TABLE IF NOT EXISTS device_status_events (
|
|
182
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
183
|
+
event_at INTEGER NOT NULL,
|
|
184
|
+
account_id TEXT,
|
|
185
|
+
device_id TEXT NOT NULL,
|
|
186
|
+
status TEXT NOT NULL CHECK(status IN ('online','offline','revoked')),
|
|
187
|
+
connection_epoch INTEGER NOT NULL DEFAULT 0,
|
|
188
|
+
agent_version TEXT
|
|
189
|
+
);
|
|
190
|
+
CREATE INDEX IF NOT EXISTS device_status_events_account_time_idx ON device_status_events(account_id, event_at DESC, id DESC);
|
|
191
|
+
`);
|
|
192
|
+
const activityColumns = db.prepare('PRAGMA table_info(activity_sessions)').all();
|
|
193
|
+
if (!activityColumns.some(column => column.name === 'display_name')) {
|
|
194
|
+
db.exec('ALTER TABLE activity_sessions ADD COLUMN display_name TEXT');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const devicesTablePresent = Boolean(db.prepare(`
|
|
198
|
+
SELECT 1 AS present FROM sqlite_master WHERE type = 'table' AND name = 'devices'
|
|
199
|
+
`).get());
|
|
200
|
+
const activeDeviceStatement = devicesTablePresent
|
|
201
|
+
? db.prepare('SELECT 1 AS present FROM devices WHERE device_id = ?')
|
|
202
|
+
: null;
|
|
203
|
+
const deviceIsActive = deviceId => !activeDeviceStatement || Boolean(activeDeviceStatement.get(normalizeDeviceId(deviceId)));
|
|
204
|
+
|
|
205
|
+
const getStatement = db.prepare('SELECT * FROM device_usage WHERE device_id = ?');
|
|
206
|
+
const connectionStatement = db.prepare(`
|
|
207
|
+
INSERT INTO device_usage (device_id, connections, reconnects, last_seen_at)
|
|
208
|
+
VALUES (?, 1, ?, ?)
|
|
209
|
+
ON CONFLICT(device_id) DO UPDATE SET
|
|
210
|
+
connections = connections + 1,
|
|
211
|
+
reconnects = reconnects + excluded.reconnects,
|
|
212
|
+
last_seen_at = excluded.last_seen_at
|
|
213
|
+
`);
|
|
214
|
+
const startedStatement = db.prepare(`
|
|
215
|
+
INSERT INTO device_usage (device_id, tool_calls_started, request_bytes, last_seen_at)
|
|
216
|
+
VALUES (?, 1, ?, ?)
|
|
217
|
+
ON CONFLICT(device_id) DO UPDATE SET
|
|
218
|
+
tool_calls_started = tool_calls_started + 1,
|
|
219
|
+
request_bytes = request_bytes + excluded.request_bytes,
|
|
220
|
+
last_seen_at = excluded.last_seen_at
|
|
221
|
+
`);
|
|
222
|
+
const succeededStatement = db.prepare(`
|
|
223
|
+
INSERT INTO device_usage (device_id, tool_calls_succeeded, response_bytes, last_seen_at)
|
|
224
|
+
VALUES (?, 1, ?, ?)
|
|
225
|
+
ON CONFLICT(device_id) DO UPDATE SET
|
|
226
|
+
tool_calls_succeeded = tool_calls_succeeded + 1,
|
|
227
|
+
response_bytes = response_bytes + excluded.response_bytes,
|
|
228
|
+
last_seen_at = excluded.last_seen_at,
|
|
229
|
+
last_error_code = NULL
|
|
230
|
+
`);
|
|
231
|
+
const failedStatement = db.prepare(`
|
|
232
|
+
INSERT INTO device_usage (device_id, tool_calls_failed, response_bytes, last_seen_at, last_error_code)
|
|
233
|
+
VALUES (?, 1, ?, ?, ?)
|
|
234
|
+
ON CONFLICT(device_id) DO UPDATE SET
|
|
235
|
+
tool_calls_failed = tool_calls_failed + 1,
|
|
236
|
+
response_bytes = response_bytes + excluded.response_bytes,
|
|
237
|
+
last_seen_at = excluded.last_seen_at,
|
|
238
|
+
last_error_code = excluded.last_error_code
|
|
239
|
+
`);
|
|
240
|
+
const touchStatement = db.prepare(`
|
|
241
|
+
INSERT INTO device_usage (device_id, last_seen_at)
|
|
242
|
+
VALUES (?, ?)
|
|
243
|
+
ON CONFLICT(device_id) DO UPDATE SET last_seen_at = excluded.last_seen_at
|
|
244
|
+
`);
|
|
245
|
+
|
|
246
|
+
const insertToolCall = db.prepare(`
|
|
247
|
+
INSERT INTO tool_call_events (
|
|
248
|
+
event_at, account_id, activity_session_id, device_id, tool, duration_ms, status, error_code,
|
|
249
|
+
input_bytes, output_bytes, truncated, spill, caller_category, upstream
|
|
250
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
251
|
+
`);
|
|
252
|
+
const insertSkillLoad = db.prepare(`
|
|
253
|
+
INSERT INTO skill_load_events (
|
|
254
|
+
event_at, account_id, activity_session_id, skill_name, status, error_code,
|
|
255
|
+
output_bytes, estimated_tokens, estimation_method
|
|
256
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
257
|
+
`);
|
|
258
|
+
const insertActivity = db.prepare(`
|
|
259
|
+
INSERT INTO activity_sessions (activity_session_id, account_id, client_id, started_at, last_seen_at, ended_at)
|
|
260
|
+
VALUES (?, ?, ?, ?, ?, NULL)
|
|
261
|
+
`);
|
|
262
|
+
const getActivity = db.prepare('SELECT * FROM activity_sessions WHERE activity_session_id = ?');
|
|
263
|
+
const touchActivity = db.prepare(`
|
|
264
|
+
UPDATE activity_sessions SET last_seen_at = ?
|
|
265
|
+
WHERE activity_session_id = ? AND account_id = ? AND ended_at IS NULL
|
|
266
|
+
`);
|
|
267
|
+
const endActivity = db.prepare(`
|
|
268
|
+
UPDATE activity_sessions SET ended_at = ?, last_seen_at = ?
|
|
269
|
+
WHERE activity_session_id = ? AND account_id = ? AND ended_at IS NULL
|
|
270
|
+
`);
|
|
271
|
+
const renameActivity = db.prepare(`
|
|
272
|
+
UPDATE activity_sessions SET display_name = ?
|
|
273
|
+
WHERE activity_session_id = ? AND account_id = ?
|
|
274
|
+
`);
|
|
275
|
+
const listActivities = db.prepare(`
|
|
276
|
+
SELECT * FROM activity_sessions WHERE account_id = ?
|
|
277
|
+
ORDER BY started_at DESC, activity_session_id DESC LIMIT ?
|
|
278
|
+
`);
|
|
279
|
+
const listActiveActivities = db.prepare(`
|
|
280
|
+
SELECT * FROM activity_sessions WHERE account_id = ? AND ended_at IS NULL
|
|
281
|
+
ORDER BY started_at DESC, activity_session_id DESC LIMIT ?
|
|
282
|
+
`);
|
|
283
|
+
const insertCatalog = db.prepare(`
|
|
284
|
+
INSERT INTO catalog_events (event_at, account_id, activity_session_id, tool_count, schema_bytes, estimated_tokens, estimation_method)
|
|
285
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
286
|
+
`);
|
|
287
|
+
const setSchema = db.prepare(`
|
|
288
|
+
INSERT INTO gateway_schema_snapshot (singleton, tool_count, schema_bytes, estimated_tokens, estimation_method, updated_at)
|
|
289
|
+
VALUES (1, ?, ?, ?, ?, ?)
|
|
290
|
+
ON CONFLICT(singleton) DO UPDATE SET
|
|
291
|
+
tool_count = excluded.tool_count,
|
|
292
|
+
schema_bytes = excluded.schema_bytes,
|
|
293
|
+
estimated_tokens = excluded.estimated_tokens,
|
|
294
|
+
estimation_method = excluded.estimation_method,
|
|
295
|
+
updated_at = excluded.updated_at
|
|
296
|
+
`);
|
|
297
|
+
const getSchema = db.prepare('SELECT * FROM gateway_schema_snapshot WHERE singleton = 1');
|
|
298
|
+
const insertDeviceStatus = db.prepare(`
|
|
299
|
+
INSERT INTO device_status_events (event_at, account_id, device_id, status, connection_epoch, agent_version)
|
|
300
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
301
|
+
`);
|
|
302
|
+
|
|
303
|
+
const totalsForAccount = db.prepare(`
|
|
304
|
+
SELECT COUNT(*) AS tool_calls,
|
|
305
|
+
COALESCE(SUM(CASE WHEN status='success' THEN 1 ELSE 0 END),0) AS succeeded,
|
|
306
|
+
COALESCE(SUM(CASE WHEN status='error' THEN 1 ELSE 0 END),0) AS failed,
|
|
307
|
+
COALESCE(SUM(input_bytes),0) AS input_bytes,
|
|
308
|
+
COALESCE(SUM(output_bytes),0) AS output_bytes
|
|
309
|
+
FROM tool_call_events WHERE account_id = ? AND event_at >= ?
|
|
310
|
+
`);
|
|
311
|
+
const topToolsForAccount = db.prepare(`
|
|
312
|
+
SELECT tool, COUNT(*) AS calls,
|
|
313
|
+
COALESCE(SUM(CASE WHEN status='error' THEN 1 ELSE 0 END),0) AS failures,
|
|
314
|
+
COALESCE(SUM(input_bytes),0) AS input_bytes,
|
|
315
|
+
COALESCE(SUM(output_bytes),0) AS output_bytes
|
|
316
|
+
FROM tool_call_events WHERE account_id = ? AND event_at >= ?
|
|
317
|
+
GROUP BY tool ORDER BY calls DESC, tool ASC LIMIT 10
|
|
318
|
+
`);
|
|
319
|
+
const deviceUsageForAccount = db.prepare(`
|
|
320
|
+
SELECT device_id, COUNT(*) AS tool_calls,
|
|
321
|
+
MAX(event_at) AS last_seen_at,
|
|
322
|
+
COALESCE(SUM(CASE WHEN status='success' THEN 1 ELSE 0 END),0) AS succeeded,
|
|
323
|
+
COALESCE(SUM(CASE WHEN status='error' THEN 1 ELSE 0 END),0) AS failed,
|
|
324
|
+
COALESCE(SUM(input_bytes),0) AS input_bytes,
|
|
325
|
+
COALESCE(SUM(output_bytes),0) AS output_bytes
|
|
326
|
+
FROM tool_call_events
|
|
327
|
+
WHERE account_id = ? AND device_id IS NOT NULL AND event_at >= ?
|
|
328
|
+
GROUP BY device_id ORDER BY device_id ASC
|
|
329
|
+
`);
|
|
330
|
+
const deviceToolUsageForAccount = db.prepare(`
|
|
331
|
+
SELECT tool, COUNT(*) AS calls,
|
|
332
|
+
COALESCE(SUM(CASE WHEN status='error' THEN 1 ELSE 0 END),0) AS failures,
|
|
333
|
+
COALESCE(SUM(input_bytes),0) AS input_bytes,
|
|
334
|
+
COALESCE(SUM(output_bytes),0) AS output_bytes
|
|
335
|
+
FROM tool_call_events
|
|
336
|
+
WHERE account_id = ? AND device_id = ? AND event_at >= ?
|
|
337
|
+
GROUP BY tool ORDER BY calls DESC, tool ASC
|
|
338
|
+
`);
|
|
339
|
+
const recentErrorsForAccount = db.prepare(`
|
|
340
|
+
SELECT event_at, device_id, tool, error_code
|
|
341
|
+
FROM tool_call_events WHERE account_id = ? AND status='error' AND event_at >= ?
|
|
342
|
+
ORDER BY event_at DESC, id DESC LIMIT 20
|
|
343
|
+
`);
|
|
344
|
+
const activityDevicesForAccountSession = db.prepare(`
|
|
345
|
+
SELECT device_id
|
|
346
|
+
FROM tool_call_events
|
|
347
|
+
WHERE account_id = ? AND activity_session_id = ? AND device_id IS NOT NULL
|
|
348
|
+
GROUP BY device_id
|
|
349
|
+
ORDER BY MAX(event_at) DESC, device_id ASC
|
|
350
|
+
LIMIT ?
|
|
351
|
+
`);
|
|
352
|
+
const recentDeviceCallsForAccount = db.prepare(`
|
|
353
|
+
SELECT e.event_at, e.activity_session_id, e.tool, e.duration_ms, e.status, e.error_code,
|
|
354
|
+
e.input_bytes, e.output_bytes, a.client_id
|
|
355
|
+
FROM tool_call_events e
|
|
356
|
+
LEFT JOIN activity_sessions a
|
|
357
|
+
ON a.activity_session_id = e.activity_session_id AND a.account_id = e.account_id
|
|
358
|
+
WHERE e.account_id = ? AND e.device_id = ? AND e.event_at >= ?
|
|
359
|
+
ORDER BY e.event_at DESC, e.id DESC
|
|
360
|
+
LIMIT ?
|
|
361
|
+
`);
|
|
362
|
+
const skillLoadsForAccount = db.prepare(`
|
|
363
|
+
SELECT skill_name, COUNT(*) AS loads,
|
|
364
|
+
COALESCE(SUM(CASE WHEN status='error' THEN 1 ELSE 0 END),0) AS failures,
|
|
365
|
+
COALESCE(SUM(output_bytes),0) AS output_bytes,
|
|
366
|
+
COALESCE(SUM(estimated_tokens),0) AS estimated_tokens,
|
|
367
|
+
MAX(estimation_method) AS estimation_method
|
|
368
|
+
FROM skill_load_events WHERE account_id = ? AND event_at >= ?
|
|
369
|
+
GROUP BY skill_name ORDER BY loads DESC, skill_name ASC LIMIT 20
|
|
370
|
+
`);
|
|
371
|
+
const catalogCountForAccount = db.prepare('SELECT COUNT(*) AS calls FROM catalog_events WHERE account_id = ? AND event_at >= ?');
|
|
372
|
+
const latestCatalogForAccount = db.prepare(`
|
|
373
|
+
SELECT tool_count, schema_bytes, estimated_tokens, estimation_method, event_at
|
|
374
|
+
FROM catalog_events WHERE account_id = ? AND event_at >= ? ORDER BY event_at DESC, id DESC LIMIT 1
|
|
375
|
+
`);
|
|
376
|
+
const deviceStatusForAccount = db.prepare(`
|
|
377
|
+
SELECT event_at, device_id, status, connection_epoch, agent_version
|
|
378
|
+
FROM device_status_events WHERE account_id = ? ORDER BY event_at DESC, id DESC LIMIT 50
|
|
379
|
+
`);
|
|
380
|
+
|
|
381
|
+
function get(deviceId) {
|
|
382
|
+
return rowToUsage(getStatement.get(normalizeDeviceId(deviceId)));
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function recordConnection(deviceId, { reconnect = false } = {}) {
|
|
386
|
+
if (!deviceIsActive(deviceId)) return get(deviceId);
|
|
387
|
+
connectionStatement.run(normalizeDeviceId(deviceId), reconnect ? 1 : 0, Number(now()));
|
|
388
|
+
return get(deviceId);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function recordToolStarted(deviceId, requestBytes = 0) {
|
|
392
|
+
if (!deviceIsActive(deviceId)) return get(deviceId);
|
|
393
|
+
startedStatement.run(normalizeDeviceId(deviceId), bytes(requestBytes), Number(now()));
|
|
394
|
+
return get(deviceId);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function recordToolSucceeded(deviceId, responseBytes = 0) {
|
|
398
|
+
if (!deviceIsActive(deviceId)) return get(deviceId);
|
|
399
|
+
succeededStatement.run(normalizeDeviceId(deviceId), bytes(responseBytes), Number(now()));
|
|
400
|
+
return get(deviceId);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function recordToolFailed(deviceId, responseBytes = 0, errorCode = 'REMOTE_DEVICE_ERROR') {
|
|
404
|
+
if (!deviceIsActive(deviceId)) return get(deviceId);
|
|
405
|
+
const code = String(errorCode || 'REMOTE_DEVICE_ERROR').slice(0, 64);
|
|
406
|
+
failedStatement.run(normalizeDeviceId(deviceId), bytes(responseBytes), Number(now()), code);
|
|
407
|
+
return get(deviceId);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function touch(deviceId) {
|
|
411
|
+
if (!deviceIsActive(deviceId)) return get(deviceId);
|
|
412
|
+
touchStatement.run(normalizeDeviceId(deviceId), Number(now()));
|
|
413
|
+
return get(deviceId);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function recordToolCall(metric = {}) {
|
|
417
|
+
const eventAt = timestampMs(metric.timestamp, now);
|
|
418
|
+
const accountId = boundedText(metric.accountId, 128);
|
|
419
|
+
const activitySessionId = boundedText(metric.activitySessionId, 128);
|
|
420
|
+
const deviceId = metric.deviceId ? normalizeDeviceId(metric.deviceId) : null;
|
|
421
|
+
if (deviceId && !deviceIsActive(deviceId)) return false;
|
|
422
|
+
const tool = boundedText(metric.tool, 128, { required: true });
|
|
423
|
+
const success = metric.success === true;
|
|
424
|
+
const errorCode = success ? null : boundedText(metric.errorCode || metric.error || 'TOOL_ERROR', 64);
|
|
425
|
+
const inputBytes = bytes(metric.inputBytes);
|
|
426
|
+
const outputBytes = bytes(metric.outputBytes);
|
|
427
|
+
insertToolCall.run(
|
|
428
|
+
eventAt, accountId, activitySessionId, deviceId, tool, duration(metric.durationMs), success ? 'success' : 'error', errorCode,
|
|
429
|
+
inputBytes, outputBytes, metric.truncated ? 1 : 0, metric.spill ? 1 : 0,
|
|
430
|
+
boundedText(metric.callerCategory, 32), boundedText(metric.upstream, 128)
|
|
431
|
+
);
|
|
432
|
+
const skillName = tool === 'load_skill' ? boundedText(metric.skillName, 128) : null;
|
|
433
|
+
if (skillName) {
|
|
434
|
+
insertSkillLoad.run(
|
|
435
|
+
eventAt, accountId, activitySessionId, skillName, success ? 'success' : 'error', errorCode,
|
|
436
|
+
outputBytes, Math.ceil(outputBytes / 4), TOKEN_ESTIMATION_METHOD
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function openActivitySession({ activitySessionId, accountId, clientId = null } = {}) {
|
|
443
|
+
const id = boundedText(activitySessionId, 128, { required: true });
|
|
444
|
+
const owner = boundedText(accountId, 128, { required: true });
|
|
445
|
+
const client = boundedText(clientId, 256);
|
|
446
|
+
const current = getActivity.get(id);
|
|
447
|
+
if (current) {
|
|
448
|
+
if (current.account_id !== owner) throw new Error('Activity session is owned by another account.');
|
|
449
|
+
if (current.ended_at !== null) throw new Error('Activity session has ended.');
|
|
450
|
+
return rowToActivity(current);
|
|
451
|
+
}
|
|
452
|
+
const time = Number(now());
|
|
453
|
+
insertActivity.run(id, owner, client, time, time);
|
|
454
|
+
return rowToActivity(getActivity.get(id));
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function touchActivitySession({ activitySessionId, accountId } = {}) {
|
|
458
|
+
const id = boundedText(activitySessionId, 128, { required: true });
|
|
459
|
+
const owner = boundedText(accountId, 128, { required: true });
|
|
460
|
+
const current = getActivity.get(id);
|
|
461
|
+
if (!current || current.account_id !== owner) throw new Error('Activity session not found for this account.');
|
|
462
|
+
if (current.ended_at !== null) throw new Error('Activity session has ended and is inactive.');
|
|
463
|
+
touchActivity.run(Number(now()), id, owner);
|
|
464
|
+
return rowToActivity(getActivity.get(id));
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function endActivitySession({ activitySessionId, accountId } = {}) {
|
|
468
|
+
const id = boundedText(activitySessionId, 128, { required: true });
|
|
469
|
+
const owner = boundedText(accountId, 128, { required: true });
|
|
470
|
+
const current = getActivity.get(id);
|
|
471
|
+
if (!current || current.account_id !== owner) throw new Error('Activity session not found for this account.');
|
|
472
|
+
if (current.ended_at === null) {
|
|
473
|
+
const time = Number(now());
|
|
474
|
+
endActivity.run(time, time, id, owner);
|
|
475
|
+
}
|
|
476
|
+
return rowToActivity(getActivity.get(id));
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function renameActivitySession({ activitySessionId, accountId, displayName } = {}) {
|
|
480
|
+
const id = boundedText(activitySessionId, 128, { required: true });
|
|
481
|
+
const owner = boundedText(accountId, 128, { required: true });
|
|
482
|
+
const current = getActivity.get(id);
|
|
483
|
+
if (!current || current.account_id !== owner) throw new Error('Activity session not found for this account.');
|
|
484
|
+
const name = boundedText(displayName, 128, { required: true });
|
|
485
|
+
renameActivity.run(name, id, owner);
|
|
486
|
+
return rowToActivity(getActivity.get(id));
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function listActivitySessions(accountId, { limit = 50, activeOnly = false } = {}) {
|
|
490
|
+
const owner = boundedText(accountId, 128, { required: true });
|
|
491
|
+
const boundedLimit = Math.max(1, Math.min(200, Number.isInteger(Number(limit)) ? Number(limit) : 50));
|
|
492
|
+
const statement = activeOnly ? listActiveActivities : listActivities;
|
|
493
|
+
return statement.all(owner, boundedLimit).map(rowToActivity);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function recordCatalogList({ accountId = null, activitySessionId = null, toolCount = 0, schemaBytes = 0, estimatedTokens, estimationMethod = TOKEN_ESTIMATION_METHOD } = {}) {
|
|
497
|
+
const count = Math.max(0, Math.floor(Number(toolCount) || 0));
|
|
498
|
+
const size = bytes(schemaBytes);
|
|
499
|
+
const estimate = estimatedTokens === undefined ? Math.ceil(size / 4) : Math.max(0, Math.floor(Number(estimatedTokens) || 0));
|
|
500
|
+
insertCatalog.run(
|
|
501
|
+
Number(now()), boundedText(accountId, 128), boundedText(activitySessionId, 128), count, size, estimate,
|
|
502
|
+
boundedText(estimationMethod, 64, { required: true })
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function setSchemaSnapshot({ toolCount = 0, schemaBytes = 0, estimatedTokens, estimationMethod = TOKEN_ESTIMATION_METHOD } = {}) {
|
|
507
|
+
const count = Math.max(0, Math.floor(Number(toolCount) || 0));
|
|
508
|
+
const size = bytes(schemaBytes);
|
|
509
|
+
const estimate = estimatedTokens === undefined ? Math.ceil(size / 4) : Math.max(0, Math.floor(Number(estimatedTokens) || 0));
|
|
510
|
+
const method = boundedText(estimationMethod, 64, { required: true });
|
|
511
|
+
setSchema.run(count, size, estimate, method, Number(now()));
|
|
512
|
+
return getSchemaSnapshot();
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function getSchemaSnapshot() {
|
|
516
|
+
return rowToSchema(getSchema.get());
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function recordDeviceStatus(deviceId, { accountId = null, status, connectionEpoch = 0, agentVersion = null } = {}) {
|
|
520
|
+
if (!deviceIsActive(deviceId)) return false;
|
|
521
|
+
const state = String(status || '').trim();
|
|
522
|
+
if (!['online', 'offline', 'revoked'].includes(state)) throw new Error('Invalid device status event.');
|
|
523
|
+
const epoch = Math.max(0, Math.floor(Number(connectionEpoch) || 0));
|
|
524
|
+
insertDeviceStatus.run(
|
|
525
|
+
Number(now()), boundedText(accountId, 128), normalizeDeviceId(deviceId), state, epoch, boundedText(agentVersion, 64)
|
|
526
|
+
);
|
|
527
|
+
return true;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function getDeviceUsageForAccount(accountId, { since = 0 } = {}) {
|
|
531
|
+
const owner = boundedText(accountId, 128, { required: true });
|
|
532
|
+
const from = sinceMs(since);
|
|
533
|
+
return deviceUsageForAccount.all(owner, from).map(row => {
|
|
534
|
+
const inputBytes = Number(row.input_bytes);
|
|
535
|
+
const outputBytes = Number(row.output_bytes);
|
|
536
|
+
return {
|
|
537
|
+
deviceId: row.device_id,
|
|
538
|
+
lastSeenAt: row.last_seen_at === null ? null : Number(row.last_seen_at),
|
|
539
|
+
toolCalls: Number(row.tool_calls),
|
|
540
|
+
succeeded: Number(row.succeeded),
|
|
541
|
+
failed: Number(row.failed),
|
|
542
|
+
inputBytes,
|
|
543
|
+
outputBytes,
|
|
544
|
+
estimatedIoTokens: Math.ceil((inputBytes + outputBytes) / 4),
|
|
545
|
+
estimationMethod: TOKEN_ESTIMATION_METHOD
|
|
546
|
+
};
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function getDeviceToolUsage(accountId, deviceId, { since = 0 } = {}) {
|
|
551
|
+
const owner = boundedText(accountId, 128, { required: true });
|
|
552
|
+
const normalizedDeviceId = normalizeDeviceId(deviceId);
|
|
553
|
+
const from = sinceMs(since);
|
|
554
|
+
return deviceToolUsageForAccount.all(owner, normalizedDeviceId, from).map(row => ({
|
|
555
|
+
tool: row.tool,
|
|
556
|
+
calls: Number(row.calls),
|
|
557
|
+
failures: Number(row.failures),
|
|
558
|
+
inputBytes: Number(row.input_bytes),
|
|
559
|
+
outputBytes: Number(row.output_bytes)
|
|
560
|
+
}));
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function getActivitySessionDeviceIds(accountId, activitySessionId, { limit = 20 } = {}) {
|
|
564
|
+
const owner = boundedText(accountId, 128, { required: true });
|
|
565
|
+
const sessionId = boundedText(activitySessionId, 128, { required: true });
|
|
566
|
+
const boundedLimit = Math.max(1, Math.min(20, Number.isInteger(Number(limit)) ? Number(limit) : 20));
|
|
567
|
+
return activityDevicesForAccountSession.all(owner, sessionId, boundedLimit).map(row => row.device_id);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function getDeviceRecentToolCalls(accountId, deviceId, { limit = 20, since = 0 } = {}) {
|
|
571
|
+
const owner = boundedText(accountId, 128, { required: true });
|
|
572
|
+
const normalizedDeviceId = normalizeDeviceId(deviceId);
|
|
573
|
+
const boundedLimit = Math.max(1, Math.min(20, Number.isInteger(Number(limit)) ? Number(limit) : 20));
|
|
574
|
+
const from = sinceMs(since);
|
|
575
|
+
return recentDeviceCallsForAccount.all(owner, normalizedDeviceId, from, boundedLimit).map(row => ({
|
|
576
|
+
eventAt: Number(row.event_at),
|
|
577
|
+
activitySessionId: row.activity_session_id || null,
|
|
578
|
+
clientId: row.client_id || null,
|
|
579
|
+
tool: row.tool,
|
|
580
|
+
success: row.status === 'success',
|
|
581
|
+
durationMs: Number(row.duration_ms),
|
|
582
|
+
inputBytes: Number(row.input_bytes),
|
|
583
|
+
outputBytes: Number(row.output_bytes),
|
|
584
|
+
errorCode: row.error_code || null
|
|
585
|
+
}));
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function getAccountUsage(accountId, { since = 0 } = {}) {
|
|
589
|
+
const owner = boundedText(accountId, 128, { required: true });
|
|
590
|
+
const from = sinceMs(since);
|
|
591
|
+
const totalsRow = totalsForAccount.get(owner, from);
|
|
592
|
+
const latestCatalog = latestCatalogForAccount.get(owner, from);
|
|
593
|
+
return {
|
|
594
|
+
totals: {
|
|
595
|
+
toolCalls: Number(totalsRow.tool_calls),
|
|
596
|
+
succeeded: Number(totalsRow.succeeded),
|
|
597
|
+
failed: Number(totalsRow.failed),
|
|
598
|
+
inputBytes: Number(totalsRow.input_bytes),
|
|
599
|
+
outputBytes: Number(totalsRow.output_bytes)
|
|
600
|
+
},
|
|
601
|
+
topTools: topToolsForAccount.all(owner, from).map(row => ({
|
|
602
|
+
tool: row.tool, calls: Number(row.calls), failures: Number(row.failures),
|
|
603
|
+
inputBytes: Number(row.input_bytes), outputBytes: Number(row.output_bytes)
|
|
604
|
+
})),
|
|
605
|
+
recentErrors: recentErrorsForAccount.all(owner, from).map(row => ({
|
|
606
|
+
eventAt: Number(row.event_at), deviceId: row.device_id || null, tool: row.tool, errorCode: row.error_code || null
|
|
607
|
+
})),
|
|
608
|
+
skillLoads: skillLoadsForAccount.all(owner, from).map(row => ({
|
|
609
|
+
skillName: row.skill_name, loads: Number(row.loads), failures: Number(row.failures),
|
|
610
|
+
outputBytes: Number(row.output_bytes), estimatedTokens: Number(row.estimated_tokens), estimationMethod: row.estimation_method
|
|
611
|
+
})),
|
|
612
|
+
catalog: {
|
|
613
|
+
listCalls: Number(catalogCountForAccount.get(owner, from).calls),
|
|
614
|
+
lastToolCount: latestCatalog ? Number(latestCatalog.tool_count) : null,
|
|
615
|
+
lastSchemaBytes: latestCatalog ? Number(latestCatalog.schema_bytes) : null,
|
|
616
|
+
estimatedTokens: latestCatalog ? Number(latestCatalog.estimated_tokens) : null,
|
|
617
|
+
estimationMethod: latestCatalog?.estimation_method || null,
|
|
618
|
+
lastSeenAt: latestCatalog ? Number(latestCatalog.event_at) : null
|
|
619
|
+
},
|
|
620
|
+
schema: getSchemaSnapshot(),
|
|
621
|
+
activitySessions: listActivitySessions(owner, { activeOnly: true }),
|
|
622
|
+
deviceStatusEvents: deviceStatusForAccount.all(owner).map(row => ({
|
|
623
|
+
eventAt: Number(row.event_at), deviceId: row.device_id, status: row.status,
|
|
624
|
+
connectionEpoch: Number(row.connection_epoch), agentVersion: row.agent_version || null
|
|
625
|
+
}))
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
function close() {
|
|
630
|
+
db.close();
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
return {
|
|
634
|
+
get,
|
|
635
|
+
recordConnection,
|
|
636
|
+
recordToolStarted,
|
|
637
|
+
recordToolSucceeded,
|
|
638
|
+
recordToolFailed,
|
|
639
|
+
touch,
|
|
640
|
+
recordToolCall,
|
|
641
|
+
openActivitySession,
|
|
642
|
+
touchActivitySession,
|
|
643
|
+
endActivitySession,
|
|
644
|
+
renameActivitySession,
|
|
645
|
+
listActivitySessions,
|
|
646
|
+
recordCatalogList,
|
|
647
|
+
setSchemaSnapshot,
|
|
648
|
+
getSchemaSnapshot,
|
|
649
|
+
recordDeviceStatus,
|
|
650
|
+
getDeviceUsageForAccount,
|
|
651
|
+
getDeviceToolUsage,
|
|
652
|
+
getActivitySessionDeviceIds,
|
|
653
|
+
getDeviceRecentToolCalls,
|
|
654
|
+
getAccountUsage,
|
|
655
|
+
close
|
|
656
|
+
};
|
|
657
|
+
}
|