opc-agent 4.1.2 → 4.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analytics/index.d.ts.map +1 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/channels/dingtalk.d.ts.map +1 -0
- package/dist/channels/dingtalk.js.map +1 -0
- package/dist/channels/discord.d.ts.map +1 -0
- package/dist/channels/discord.js.map +1 -0
- package/dist/channels/email.d.ts.map +1 -0
- package/dist/channels/email.js.map +1 -0
- package/dist/channels/feishu.d.ts.map +1 -0
- package/dist/channels/feishu.js.map +1 -0
- package/dist/channels/googlechat.d.ts.map +1 -0
- package/dist/channels/googlechat.js.map +1 -0
- package/dist/channels/imessage.d.ts.map +1 -0
- package/dist/channels/imessage.js.map +1 -0
- package/dist/channels/index.d.ts.map +1 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/channels/irc.d.ts.map +1 -0
- package/dist/channels/irc.js.map +1 -0
- package/dist/channels/line.d.ts.map +1 -0
- package/dist/channels/line.js.map +1 -0
- package/dist/channels/matrix.d.ts.map +1 -0
- package/dist/channels/matrix.js.map +1 -0
- package/dist/channels/mattermost.d.ts.map +1 -0
- package/dist/channels/mattermost.js.map +1 -0
- package/dist/channels/msteams.d.ts.map +1 -0
- package/dist/channels/msteams.js.map +1 -0
- package/dist/channels/nostr.d.ts.map +1 -0
- package/dist/channels/nostr.js.map +1 -0
- package/dist/channels/qq.d.ts.map +1 -0
- package/dist/channels/qq.js.map +1 -0
- package/dist/channels/signal.d.ts.map +1 -0
- package/dist/channels/signal.js.map +1 -0
- package/dist/channels/slack.d.ts.map +1 -0
- package/dist/channels/slack.js.map +1 -0
- package/dist/channels/sms.d.ts.map +1 -0
- package/dist/channels/sms.js.map +1 -0
- package/dist/channels/telegram.d.ts.map +1 -0
- package/dist/channels/telegram.js.map +1 -0
- package/dist/channels/twitch.d.ts.map +1 -0
- package/dist/channels/twitch.js.map +1 -0
- package/dist/channels/voice-call.d.ts.map +1 -0
- package/dist/channels/voice-call.js.map +1 -0
- package/dist/channels/voice.d.ts.map +1 -0
- package/dist/channels/voice.js.map +1 -0
- package/dist/channels/web.d.ts.map +1 -0
- package/dist/channels/web.js.map +1 -0
- package/dist/channels/webhook.d.ts.map +1 -0
- package/dist/channels/webhook.js.map +1 -0
- package/dist/channels/websocket.d.ts.map +1 -0
- package/dist/channels/websocket.js.map +1 -0
- package/dist/channels/wechat.d.ts.map +1 -0
- package/dist/channels/wechat.js.map +1 -0
- package/dist/channels/whatsapp.d.ts.map +1 -0
- package/dist/channels/whatsapp.js.map +1 -0
- package/dist/cli/chat.d.ts.map +1 -0
- package/dist/cli/chat.js.map +1 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +108 -11
- package/dist/cli.js.map +1 -0
- package/dist/core/a2a.d.ts.map +1 -0
- package/dist/core/a2a.js.map +1 -0
- package/dist/core/agent.d.ts.map +1 -0
- package/dist/core/agent.js.map +1 -0
- package/dist/core/analytics-engine.d.ts.map +1 -0
- package/dist/core/analytics-engine.js.map +1 -0
- package/dist/core/api-server.d.ts.map +1 -0
- package/dist/core/api-server.js.map +1 -0
- package/dist/core/audio.d.ts.map +1 -0
- package/dist/core/audio.js.map +1 -0
- package/dist/core/auth.d.ts.map +1 -0
- package/dist/core/auth.js.map +1 -0
- package/dist/core/cache.d.ts.map +1 -0
- package/dist/core/cache.js.map +1 -0
- package/dist/core/collaboration.d.ts.map +1 -0
- package/dist/core/collaboration.js.map +1 -0
- package/dist/core/compose.d.ts.map +1 -0
- package/dist/core/compose.js.map +1 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/context-discovery.d.ts.map +1 -0
- package/dist/core/context-discovery.js.map +1 -0
- package/dist/core/context-refs.d.ts.map +1 -0
- package/dist/core/context-refs.js.map +1 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/gateway.d.ts.map +1 -0
- package/dist/core/gateway.js.map +1 -0
- package/dist/core/heartbeat.d.ts.map +1 -0
- package/dist/core/heartbeat.js.map +1 -0
- package/dist/core/hitl.d.ts.map +1 -0
- package/dist/core/hitl.js.map +1 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/ide-bridge.d.ts.map +1 -0
- package/dist/core/ide-bridge.js.map +1 -0
- package/dist/core/knowledge.d.ts.map +1 -0
- package/dist/core/knowledge.js.map +1 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/model-recommender.d.ts +40 -0
- package/dist/core/model-recommender.d.ts.map +1 -0
- package/dist/core/model-recommender.js +186 -0
- package/dist/core/model-recommender.js.map +1 -0
- package/dist/core/node-network.d.ts.map +1 -0
- package/dist/core/node-network.js.map +1 -0
- package/dist/core/orchestrator.d.ts.map +1 -0
- package/dist/core/orchestrator.js.map +1 -0
- package/dist/core/performance.d.ts.map +1 -0
- package/dist/core/performance.js.map +1 -0
- package/dist/core/profiles.d.ts.map +1 -0
- package/dist/core/profiles.js.map +1 -0
- package/dist/core/rate-limiter.d.ts.map +1 -0
- package/dist/core/rate-limiter.js.map +1 -0
- package/dist/core/room.d.ts.map +1 -0
- package/dist/core/room.js.map +1 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/sandbox.d.ts.map +1 -0
- package/dist/core/sandbox.js.map +1 -0
- package/dist/core/scheduler.d.ts.map +1 -0
- package/dist/core/scheduler.js.map +1 -0
- package/dist/core/security.d.ts.map +1 -0
- package/dist/core/security.js.map +1 -0
- package/dist/core/session-manager.d.ts.map +1 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/streaming.d.ts.map +1 -0
- package/dist/core/streaming.js.map +1 -0
- package/dist/core/subagent.d.ts.map +1 -0
- package/dist/core/subagent.js.map +1 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/versioning.d.ts.map +1 -0
- package/dist/core/versioning.js.map +1 -0
- package/dist/core/vision.d.ts.map +1 -0
- package/dist/core/vision.js.map +1 -0
- package/dist/core/watch.d.ts.map +1 -0
- package/dist/core/watch.js.map +1 -0
- package/dist/core/workflow-graph.d.ts.map +1 -0
- package/dist/core/workflow-graph.js.map +1 -0
- package/dist/core/workflow.d.ts.map +1 -0
- package/dist/core/workflow.js.map +1 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js.map +1 -0
- package/dist/deploy/hermes.d.ts.map +1 -0
- package/dist/deploy/hermes.js.map +1 -0
- package/dist/deploy/index.d.ts.map +1 -0
- package/dist/deploy/index.js.map +1 -0
- package/dist/deploy/openclaw.d.ts.map +1 -0
- package/dist/deploy/openclaw.js.map +1 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js.map +1 -0
- package/dist/eval/index.d.ts.map +1 -0
- package/dist/eval/index.js.map +1 -0
- package/dist/hub/brain-seed.d.ts.map +1 -0
- package/dist/hub/brain-seed.js.map +1 -0
- package/dist/hub/client.d.ts.map +1 -0
- package/dist/hub/client.js.map +1 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -0
- package/dist/mcp/servers/calculator-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/calculator-mcp.js.map +1 -0
- package/dist/mcp/servers/crypto-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/crypto-mcp.js.map +1 -0
- package/dist/mcp/servers/database-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/database-mcp.js.map +1 -0
- package/dist/mcp/servers/datetime-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/datetime-mcp.js.map +1 -0
- package/dist/mcp/servers/filesystem.d.ts.map +1 -0
- package/dist/mcp/servers/filesystem.js.map +1 -0
- package/dist/mcp/servers/github-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/github-mcp.js.map +1 -0
- package/dist/mcp/servers/index.d.ts.map +1 -0
- package/dist/mcp/servers/index.js.map +1 -0
- package/dist/mcp/servers/json-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/json-mcp.js.map +1 -0
- package/dist/mcp/servers/memory-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/memory-mcp.js.map +1 -0
- package/dist/mcp/servers/regex-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/regex-mcp.js.map +1 -0
- package/dist/mcp/servers/web-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/web-mcp.js.map +1 -0
- package/dist/memory/context-compressor.d.ts.map +1 -0
- package/dist/memory/context-compressor.js.map +1 -0
- package/dist/memory/deepbrain.d.ts.map +1 -0
- package/dist/memory/deepbrain.js.map +1 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/seed-loader.d.ts.map +1 -0
- package/dist/memory/seed-loader.js.map +1 -0
- package/dist/memory/user-profiler.d.ts.map +1 -0
- package/dist/memory/user-profiler.js.map +1 -0
- package/dist/plugins/content-filter.d.ts.map +1 -0
- package/dist/plugins/content-filter.js.map +1 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/logger.d.ts.map +1 -0
- package/dist/plugins/logger.js.map +1 -0
- package/dist/plugins/rate-limiter.d.ts.map +1 -0
- package/dist/plugins/rate-limiter.js.map +1 -0
- package/dist/protocols/a2a/client.d.ts.map +1 -0
- package/dist/protocols/a2a/client.js.map +1 -0
- package/dist/protocols/a2a/index.d.ts.map +1 -0
- package/dist/protocols/a2a/index.js.map +1 -0
- package/dist/protocols/a2a/server.d.ts.map +1 -0
- package/dist/protocols/a2a/server.js.map +1 -0
- package/dist/protocols/a2a/types.d.ts.map +1 -0
- package/dist/protocols/a2a/types.js.map +1 -0
- package/dist/protocols/a2a/utils.d.ts.map +1 -0
- package/dist/protocols/a2a/utils.js.map +1 -0
- package/dist/protocols/agui/client.d.ts.map +1 -0
- package/dist/protocols/agui/client.js.map +1 -0
- package/dist/protocols/agui/index.d.ts.map +1 -0
- package/dist/protocols/agui/index.js.map +1 -0
- package/dist/protocols/agui/server.d.ts.map +1 -0
- package/dist/protocols/agui/server.js.map +1 -0
- package/dist/protocols/agui/types.d.ts.map +1 -0
- package/dist/protocols/agui/types.js.map +1 -0
- package/dist/protocols/index.d.ts.map +1 -0
- package/dist/protocols/index.js.map +1 -0
- package/dist/protocols/mcp/agent-tools.d.ts.map +1 -0
- package/dist/protocols/mcp/agent-tools.js.map +1 -0
- package/dist/protocols/mcp/index.d.ts.map +1 -0
- package/dist/protocols/mcp/index.js.map +1 -0
- package/dist/protocols/mcp/server.d.ts.map +1 -0
- package/dist/protocols/mcp/server.js.map +1 -0
- package/dist/protocols/mcp/types.d.ts.map +1 -0
- package/dist/protocols/mcp/types.js.map +1 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/publish/index.d.ts.map +1 -0
- package/dist/publish/index.js.map +1 -0
- package/dist/scheduler/cron-engine.d.ts.map +1 -0
- package/dist/scheduler/cron-engine.js.map +1 -0
- package/dist/scheduler/index.d.ts.map +1 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/schema/oad.d.ts.map +1 -0
- package/dist/schema/oad.js.map +1 -0
- package/dist/security/approval.d.ts.map +1 -0
- package/dist/security/approval.js.map +1 -0
- package/dist/security/approvals.d.ts.map +1 -0
- package/dist/security/approvals.js.map +1 -0
- package/dist/security/elevated.d.ts.map +1 -0
- package/dist/security/elevated.js.map +1 -0
- package/dist/security/guardrails.d.ts.map +1 -0
- package/dist/security/guardrails.js.map +1 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/keys.d.ts.map +1 -0
- package/dist/security/keys.js.map +1 -0
- package/dist/security/secrets.d.ts.map +1 -0
- package/dist/security/secrets.js.map +1 -0
- package/dist/skills/auto-learn.d.ts.map +1 -0
- package/dist/skills/auto-learn.js.map +1 -0
- package/dist/skills/base.d.ts.map +1 -0
- package/dist/skills/base.js.map +1 -0
- package/dist/skills/builtin/index.d.ts.map +1 -0
- package/dist/skills/builtin/index.js.map +1 -0
- package/dist/skills/document.d.ts.map +1 -0
- package/dist/skills/document.js.map +1 -0
- package/dist/skills/http.d.ts.map +1 -0
- package/dist/skills/http.js.map +1 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/marketplace.d.ts.map +1 -0
- package/dist/skills/marketplace.js.map +1 -0
- package/dist/skills/scheduler.d.ts.map +1 -0
- package/dist/skills/scheduler.js.map +1 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/skills/webhook-trigger.d.ts.map +1 -0
- package/dist/skills/webhook-trigger.js.map +1 -0
- package/dist/studio/server.d.ts.map +1 -0
- package/dist/studio/server.js.map +1 -0
- package/dist/studio/templates-data.d.ts.map +1 -0
- package/dist/studio/templates-data.js.map +1 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/templates/code-reviewer.d.ts.map +1 -0
- package/dist/templates/code-reviewer.js.map +1 -0
- package/dist/templates/content-writer.d.ts.map +1 -0
- package/dist/templates/content-writer.js.map +1 -0
- package/dist/templates/customer-service.d.ts.map +1 -0
- package/dist/templates/customer-service.js.map +1 -0
- package/dist/templates/data-analyst.d.ts.map +1 -0
- package/dist/templates/data-analyst.js.map +1 -0
- package/dist/templates/executive-assistant.d.ts.map +1 -0
- package/dist/templates/executive-assistant.js.map +1 -0
- package/dist/templates/financial-advisor.d.ts.map +1 -0
- package/dist/templates/financial-advisor.js.map +1 -0
- package/dist/templates/hr-recruiter.d.ts.map +1 -0
- package/dist/templates/hr-recruiter.js.map +1 -0
- package/dist/templates/knowledge-base.d.ts.map +1 -0
- package/dist/templates/knowledge-base.js.map +1 -0
- package/dist/templates/legal-assistant.d.ts.map +1 -0
- package/dist/templates/legal-assistant.js.map +1 -0
- package/dist/templates/project-manager.d.ts.map +1 -0
- package/dist/templates/project-manager.js.map +1 -0
- package/dist/templates/sales-assistant.d.ts.map +1 -0
- package/dist/templates/sales-assistant.js.map +1 -0
- package/dist/templates/teacher.d.ts.map +1 -0
- package/dist/templates/teacher.js.map +1 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tools/builtin/browser.d.ts.map +1 -0
- package/dist/tools/builtin/browser.js.map +1 -0
- package/dist/tools/builtin/datetime.d.ts.map +1 -0
- package/dist/tools/builtin/datetime.js.map +1 -0
- package/dist/tools/builtin/file.d.ts.map +1 -0
- package/dist/tools/builtin/file.js.map +1 -0
- package/dist/tools/builtin/home-assistant.d.ts.map +1 -0
- package/dist/tools/builtin/home-assistant.js.map +1 -0
- package/dist/tools/builtin/index.d.ts.map +1 -0
- package/dist/tools/builtin/index.js.map +1 -0
- package/dist/tools/builtin/rl-tools.d.ts.map +1 -0
- package/dist/tools/builtin/rl-tools.js.map +1 -0
- package/dist/tools/builtin/shell.d.ts.map +1 -0
- package/dist/tools/builtin/shell.js.map +1 -0
- package/dist/tools/builtin/vision.d.ts.map +1 -0
- package/dist/tools/builtin/vision.js.map +1 -0
- package/dist/tools/builtin/web-search.d.ts.map +1 -0
- package/dist/tools/builtin/web-search.js.map +1 -0
- package/dist/tools/builtin/web.d.ts.map +1 -0
- package/dist/tools/builtin/web.js.map +1 -0
- package/dist/tools/calculator.d.ts.map +1 -0
- package/dist/tools/calculator.js.map +1 -0
- package/dist/tools/datetime.d.ts.map +1 -0
- package/dist/tools/datetime.js.map +1 -0
- package/dist/tools/document-processor.d.ts.map +1 -0
- package/dist/tools/document-processor.js.map +1 -0
- package/dist/tools/gateway.d.ts.map +1 -0
- package/dist/tools/gateway.js.map +1 -0
- package/dist/tools/image-generator.d.ts.map +1 -0
- package/dist/tools/image-generator.js.map +1 -0
- package/dist/tools/integrations/calendar.d.ts.map +1 -0
- package/dist/tools/integrations/calendar.js.map +1 -0
- package/dist/tools/integrations/code-exec.d.ts.map +1 -0
- package/dist/tools/integrations/code-exec.js.map +1 -0
- package/dist/tools/integrations/csv-analyzer.d.ts.map +1 -0
- package/dist/tools/integrations/csv-analyzer.js.map +1 -0
- package/dist/tools/integrations/database.d.ts.map +1 -0
- package/dist/tools/integrations/database.js.map +1 -0
- package/dist/tools/integrations/email-send.d.ts.map +1 -0
- package/dist/tools/integrations/email-send.js.map +1 -0
- package/dist/tools/integrations/git-tool.d.ts.map +1 -0
- package/dist/tools/integrations/git-tool.js.map +1 -0
- package/dist/tools/integrations/github-tool.d.ts.map +1 -0
- package/dist/tools/integrations/github-tool.js.map +1 -0
- package/dist/tools/integrations/image-gen.d.ts.map +1 -0
- package/dist/tools/integrations/image-gen.js.map +1 -0
- package/dist/tools/integrations/index.d.ts.map +1 -0
- package/dist/tools/integrations/index.js.map +1 -0
- package/dist/tools/integrations/jira.d.ts.map +1 -0
- package/dist/tools/integrations/jira.js.map +1 -0
- package/dist/tools/integrations/notion.d.ts.map +1 -0
- package/dist/tools/integrations/notion.js.map +1 -0
- package/dist/tools/integrations/npm-tool.d.ts.map +1 -0
- package/dist/tools/integrations/npm-tool.js.map +1 -0
- package/dist/tools/integrations/pdf-reader.d.ts.map +1 -0
- package/dist/tools/integrations/pdf-reader.js.map +1 -0
- package/dist/tools/integrations/slack.d.ts.map +1 -0
- package/dist/tools/integrations/slack.js.map +1 -0
- package/dist/tools/integrations/summarizer.d.ts.map +1 -0
- package/dist/tools/integrations/summarizer.js.map +1 -0
- package/dist/tools/integrations/translator.d.ts.map +1 -0
- package/dist/tools/integrations/translator.js.map +1 -0
- package/dist/tools/integrations/trello.d.ts.map +1 -0
- package/dist/tools/integrations/trello.js.map +1 -0
- package/dist/tools/integrations/vector-search.d.ts.map +1 -0
- package/dist/tools/integrations/vector-search.js.map +1 -0
- package/dist/tools/integrations/web-scraper.d.ts.map +1 -0
- package/dist/tools/integrations/web-scraper.js.map +1 -0
- package/dist/tools/integrations/web-search.d.ts.map +1 -0
- package/dist/tools/integrations/web-search.js.map +1 -0
- package/dist/tools/integrations/webhook.d.ts.map +1 -0
- package/dist/tools/integrations/webhook.js.map +1 -0
- package/dist/tools/json-transform.d.ts.map +1 -0
- package/dist/tools/json-transform.js.map +1 -0
- package/dist/tools/mcp-client.d.ts.map +1 -0
- package/dist/tools/mcp-client.js.map +1 -0
- package/dist/tools/mcp.d.ts.map +1 -0
- package/dist/tools/mcp.js.map +1 -0
- package/dist/tools/text-analysis.d.ts.map +1 -0
- package/dist/tools/text-analysis.js.map +1 -0
- package/dist/tools/web-scraper.d.ts.map +1 -0
- package/dist/tools/web-scraper.js.map +1 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/traces/index.d.ts.map +1 -0
- package/dist/traces/index.js.map +1 -0
- package/dist/ui/components.d.ts.map +1 -0
- package/dist/ui/components.js.map +1 -0
- package/models.json +164 -0
- package/package.json +1 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -20
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -14
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -13
- package/.github/workflows/ci.yml +0 -24
- package/USABILITY-ISSUES.md +0 -73
- package/docs/.vitepress/config.ts +0 -103
- package/docs/api/cli.md +0 -48
- package/docs/api/oad-schema.md +0 -64
- package/docs/api/sdk.md +0 -80
- package/docs/guide/concepts.md +0 -51
- package/docs/guide/configuration.md +0 -79
- package/docs/guide/deployment.md +0 -42
- package/docs/guide/getting-started.md +0 -44
- package/docs/guide/templates.md +0 -28
- package/docs/guide/testing.md +0 -84
- package/docs/index.md +0 -27
- package/docs/zh/api/cli.md +0 -54
- package/docs/zh/api/oad-schema.md +0 -87
- package/docs/zh/api/sdk.md +0 -102
- package/docs/zh/guide/concepts.md +0 -104
- package/docs/zh/guide/configuration.md +0 -135
- package/docs/zh/guide/deployment.md +0 -81
- package/docs/zh/guide/getting-started.md +0 -82
- package/docs/zh/guide/templates.md +0 -84
- package/docs/zh/guide/testing.md +0 -88
- package/docs/zh/index.md +0 -27
- package/fix-sidebar.mjs +0 -188
- package/serve-studio.js +0 -13
- package/serve-test.js +0 -25
- package/src/analytics/index.ts +0 -66
- package/src/channels/dingtalk.ts +0 -46
- package/src/channels/discord.ts +0 -192
- package/src/channels/email.ts +0 -351
- package/src/channels/feishu.ts +0 -349
- package/src/channels/googlechat.ts +0 -42
- package/src/channels/imessage.ts +0 -32
- package/src/channels/index.ts +0 -15
- package/src/channels/irc.ts +0 -82
- package/src/channels/line.ts +0 -33
- package/src/channels/matrix.ts +0 -34
- package/src/channels/mattermost.ts +0 -57
- package/src/channels/msteams.ts +0 -33
- package/src/channels/nostr.ts +0 -33
- package/src/channels/qq.ts +0 -34
- package/src/channels/signal.ts +0 -33
- package/src/channels/slack.ts +0 -217
- package/src/channels/sms.ts +0 -34
- package/src/channels/telegram.ts +0 -616
- package/src/channels/twitch.ts +0 -65
- package/src/channels/voice-call.ts +0 -100
- package/src/channels/voice.ts +0 -471
- package/src/channels/web.ts +0 -638
- package/src/channels/webhook.ts +0 -199
- package/src/channels/websocket.ts +0 -399
- package/src/channels/wechat.ts +0 -329
- package/src/channels/whatsapp.ts +0 -33
- package/src/cli/chat.ts +0 -99
- package/src/cli/setup.ts +0 -314
- package/src/cli.ts +0 -2826
- package/src/core/a2a.ts +0 -203
- package/src/core/agent.ts +0 -476
- package/src/core/analytics-engine.ts +0 -186
- package/src/core/api-server.ts +0 -277
- package/src/core/audio.ts +0 -98
- package/src/core/auth.ts +0 -57
- package/src/core/cache.ts +0 -141
- package/src/core/collaboration.ts +0 -275
- package/src/core/compose.ts +0 -77
- package/src/core/config.ts +0 -14
- package/src/core/context-discovery.ts +0 -85
- package/src/core/context-refs.ts +0 -140
- package/src/core/errors.ts +0 -148
- package/src/core/gateway.ts +0 -106
- package/src/core/heartbeat.ts +0 -51
- package/src/core/hitl.ts +0 -138
- package/src/core/hooks.ts +0 -105
- package/src/core/ide-bridge.ts +0 -133
- package/src/core/knowledge.ts +0 -255
- package/src/core/logger.ts +0 -57
- package/src/core/node-network.ts +0 -86
- package/src/core/orchestrator.ts +0 -215
- package/src/core/performance.ts +0 -187
- package/src/core/profiles.ts +0 -122
- package/src/core/rate-limiter.ts +0 -128
- package/src/core/room.ts +0 -109
- package/src/core/runtime.ts +0 -435
- package/src/core/sandbox.ts +0 -344
- package/src/core/scheduler.ts +0 -187
- package/src/core/security.ts +0 -171
- package/src/core/session-manager.ts +0 -137
- package/src/core/streaming.ts +0 -195
- package/src/core/subagent.ts +0 -98
- package/src/core/types.ts +0 -68
- package/src/core/versioning.ts +0 -106
- package/src/core/vision.ts +0 -180
- package/src/core/watch.ts +0 -178
- package/src/core/workflow-graph.ts +0 -365
- package/src/core/workflow.ts +0 -235
- package/src/daemon.ts +0 -96
- package/src/deploy/hermes.ts +0 -156
- package/src/deploy/index.ts +0 -255
- package/src/deploy/openclaw.ts +0 -190
- package/src/doctor.ts +0 -243
- package/src/eval/index.ts +0 -211
- package/src/eval/suites/basic.json +0 -16
- package/src/eval/suites/memory.json +0 -12
- package/src/eval/suites/safety.json +0 -14
- package/src/hub/brain-seed.ts +0 -54
- package/src/hub/client.ts +0 -60
- package/src/i18n/index.ts +0 -216
- package/src/index.ts +0 -283
- package/src/mcp/servers/calculator-mcp.ts +0 -65
- package/src/mcp/servers/crypto-mcp.ts +0 -73
- package/src/mcp/servers/database-mcp.ts +0 -72
- package/src/mcp/servers/datetime-mcp.ts +0 -69
- package/src/mcp/servers/filesystem.ts +0 -66
- package/src/mcp/servers/github-mcp.ts +0 -58
- package/src/mcp/servers/index.ts +0 -63
- package/src/mcp/servers/json-mcp.ts +0 -102
- package/src/mcp/servers/memory-mcp.ts +0 -56
- package/src/mcp/servers/regex-mcp.ts +0 -53
- package/src/mcp/servers/web-mcp.ts +0 -49
- package/src/memory/context-compressor.ts +0 -189
- package/src/memory/deepbrain.ts +0 -202
- package/src/memory/index.ts +0 -41
- package/src/memory/seed-loader.ts +0 -212
- package/src/memory/user-profiler.ts +0 -215
- package/src/plugins/content-filter.ts +0 -23
- package/src/plugins/index.ts +0 -339
- package/src/plugins/logger.ts +0 -18
- package/src/plugins/rate-limiter.ts +0 -38
- package/src/protocols/a2a/client.ts +0 -132
- package/src/protocols/a2a/index.ts +0 -8
- package/src/protocols/a2a/server.ts +0 -333
- package/src/protocols/a2a/types.ts +0 -88
- package/src/protocols/a2a/utils.ts +0 -50
- package/src/protocols/agui/client.ts +0 -83
- package/src/protocols/agui/index.ts +0 -4
- package/src/protocols/agui/server.ts +0 -218
- package/src/protocols/agui/types.ts +0 -153
- package/src/protocols/index.ts +0 -2
- package/src/protocols/mcp/agent-tools.ts +0 -134
- package/src/protocols/mcp/index.ts +0 -8
- package/src/protocols/mcp/server.ts +0 -262
- package/src/protocols/mcp/types.ts +0 -69
- package/src/providers/index.ts +0 -632
- package/src/publish/index.ts +0 -376
- package/src/scheduler/cron-engine.ts +0 -191
- package/src/scheduler/index.ts +0 -2
- package/src/schema/oad.ts +0 -217
- package/src/security/approval.ts +0 -131
- package/src/security/approvals.ts +0 -143
- package/src/security/elevated.ts +0 -105
- package/src/security/guardrails.ts +0 -248
- package/src/security/index.ts +0 -9
- package/src/security/keys.ts +0 -87
- package/src/security/secrets.ts +0 -129
- package/src/skills/auto-learn.ts +0 -262
- package/src/skills/base.ts +0 -16
- package/src/skills/builtin/index.ts +0 -408
- package/src/skills/document.ts +0 -100
- package/src/skills/http.ts +0 -35
- package/src/skills/index.ts +0 -27
- package/src/skills/marketplace.ts +0 -113
- package/src/skills/scheduler.ts +0 -80
- package/src/skills/types.ts +0 -42
- package/src/skills/webhook-trigger.ts +0 -59
- package/src/studio/server.ts +0 -1791
- package/src/studio/templates-data.ts +0 -178
- package/src/studio-ui/index.html +0 -3076
- package/src/telemetry/index.ts +0 -324
- package/src/templates/code-reviewer.ts +0 -30
- package/src/templates/content-writer.ts +0 -58
- package/src/templates/customer-service.ts +0 -76
- package/src/templates/data-analyst.ts +0 -66
- package/src/templates/executive-assistant.ts +0 -71
- package/src/templates/financial-advisor.ts +0 -60
- package/src/templates/hr-recruiter.ts +0 -58
- package/src/templates/knowledge-base.ts +0 -27
- package/src/templates/legal-assistant.ts +0 -71
- package/src/templates/project-manager.ts +0 -58
- package/src/templates/sales-assistant.ts +0 -75
- package/src/templates/teacher.ts +0 -75
- package/src/testing/index.ts +0 -181
- package/src/tools/builtin/browser.ts +0 -299
- package/src/tools/builtin/datetime.ts +0 -41
- package/src/tools/builtin/file.ts +0 -107
- package/src/tools/builtin/home-assistant.ts +0 -116
- package/src/tools/builtin/index.ts +0 -37
- package/src/tools/builtin/rl-tools.ts +0 -243
- package/src/tools/builtin/shell.ts +0 -43
- package/src/tools/builtin/vision.ts +0 -64
- package/src/tools/builtin/web-search.ts +0 -126
- package/src/tools/builtin/web.ts +0 -35
- package/src/tools/calculator.ts +0 -73
- package/src/tools/datetime.ts +0 -149
- package/src/tools/document-processor.ts +0 -213
- package/src/tools/gateway.ts +0 -220
- package/src/tools/image-generator.ts +0 -150
- package/src/tools/integrations/calendar.ts +0 -73
- package/src/tools/integrations/code-exec.ts +0 -39
- package/src/tools/integrations/csv-analyzer.ts +0 -92
- package/src/tools/integrations/database.ts +0 -44
- package/src/tools/integrations/email-send.ts +0 -76
- package/src/tools/integrations/git-tool.ts +0 -42
- package/src/tools/integrations/github-tool.ts +0 -76
- package/src/tools/integrations/image-gen.ts +0 -56
- package/src/tools/integrations/index.ts +0 -92
- package/src/tools/integrations/jira.ts +0 -83
- package/src/tools/integrations/notion.ts +0 -71
- package/src/tools/integrations/npm-tool.ts +0 -48
- package/src/tools/integrations/pdf-reader.ts +0 -58
- package/src/tools/integrations/slack.ts +0 -65
- package/src/tools/integrations/summarizer.ts +0 -49
- package/src/tools/integrations/translator.ts +0 -48
- package/src/tools/integrations/trello.ts +0 -60
- package/src/tools/integrations/vector-search.ts +0 -42
- package/src/tools/integrations/web-scraper.ts +0 -47
- package/src/tools/integrations/web-search.ts +0 -58
- package/src/tools/integrations/webhook.ts +0 -38
- package/src/tools/json-transform.ts +0 -187
- package/src/tools/mcp-client.ts +0 -131
- package/src/tools/mcp.ts +0 -76
- package/src/tools/text-analysis.ts +0 -116
- package/src/tools/web-scraper.ts +0 -179
- package/src/tools/web-search.ts +0 -180
- package/src/traces/index.ts +0 -132
- package/src/types/agent-workstation.d.ts +0 -2
- package/src/ui/components.ts +0 -127
- package/srv-err.txt +0 -0
- package/srv-out.txt +0 -1
- package/test-agent/Dockerfile +0 -9
- package/test-agent/README.md +0 -50
- package/test-agent/agent.yaml +0 -23
- package/test-agent/docker-compose.yml +0 -11
- package/test-agent/oad.yaml +0 -31
- package/test-agent/package-lock.json +0 -1492
- package/test-agent/package.json +0 -18
- package/test-agent/src/index.ts +0 -24
- package/test-agent/src/skills/echo.ts +0 -15
- package/test-agent/tsconfig.json +0 -25
- package/test-full.js +0 -43
- package/test-sidebar.js +0 -22
- package/test-studio3.js +0 -75
- package/test-studio4.js +0 -41
- package/tests/a2a-protocol.test.ts +0 -285
- package/tests/a2a.test.ts +0 -66
- package/tests/agent.test.ts +0 -72
- package/tests/agui-protocol.test.ts +0 -246
- package/tests/analytics.test.ts +0 -50
- package/tests/api-server.test.ts +0 -148
- package/tests/approvals.test.ts +0 -89
- package/tests/audio.test.ts +0 -40
- package/tests/auto-learn.test.ts +0 -105
- package/tests/brain-seed-extended.test.ts +0 -490
- package/tests/brain-seed.test.ts +0 -239
- package/tests/browser.test.ts +0 -179
- package/tests/builtin-tools.test.ts +0 -83
- package/tests/channel.test.ts +0 -39
- package/tests/channels/discord.test.ts +0 -79
- package/tests/channels/email.test.ts +0 -148
- package/tests/channels/feishu.test.ts +0 -123
- package/tests/channels/telegram.test.ts +0 -129
- package/tests/channels/websocket.test.ts +0 -53
- package/tests/channels/wechat.test.ts +0 -170
- package/tests/channels-extra.test.ts +0 -45
- package/tests/chat-cli.test.ts +0 -160
- package/tests/cli.test.ts +0 -46
- package/tests/collaboration.test.ts +0 -319
- package/tests/context-compressor.test.ts +0 -172
- package/tests/context-refs.test.ts +0 -121
- package/tests/cron-engine.test.ts +0 -101
- package/tests/daemon.test.ts +0 -135
- package/tests/deepbrain-wire.test.ts +0 -234
- package/tests/deploy-and-dag.test.ts +0 -196
- package/tests/doctor.test.ts +0 -38
- package/tests/document-processor.test.ts +0 -69
- package/tests/e2e-nocode.test.ts +0 -442
- package/tests/e2e.test.ts +0 -134
- package/tests/elevated.test.ts +0 -69
- package/tests/errors.test.ts +0 -83
- package/tests/eval.test.ts +0 -173
- package/tests/gateway.test.ts +0 -63
- package/tests/guardrails.test.ts +0 -177
- package/tests/hitl.test.ts +0 -71
- package/tests/home-assistant.test.ts +0 -40
- package/tests/hooks.test.ts +0 -79
- package/tests/i18n.test.ts +0 -41
- package/tests/ide-bridge.test.ts +0 -38
- package/tests/image-generator.test.ts +0 -84
- package/tests/init-role.test.ts +0 -124
- package/tests/integrations.test.ts +0 -249
- package/tests/mcp-client.test.ts +0 -92
- package/tests/mcp-server.test.ts +0 -178
- package/tests/mcp-servers.test.ts +0 -260
- package/tests/mcp.test.ts +0 -54
- package/tests/node-network.test.ts +0 -74
- package/tests/oad.test.ts +0 -68
- package/tests/performance.test.ts +0 -115
- package/tests/plugin-a2a-enhanced.test.ts +0 -230
- package/tests/plugin.test.ts +0 -74
- package/tests/profiles.test.ts +0 -61
- package/tests/publish.test.ts +0 -231
- package/tests/rl-tools.test.ts +0 -93
- package/tests/room.test.ts +0 -106
- package/tests/runtime.test.ts +0 -42
- package/tests/sandbox-manager.test.ts +0 -46
- package/tests/sandbox.test.ts +0 -46
- package/tests/scheduler.test.ts +0 -200
- package/tests/secrets.test.ts +0 -107
- package/tests/security-enhanced.test.ts +0 -233
- package/tests/security.test.ts +0 -60
- package/tests/settings-api.test.ts +0 -148
- package/tests/setup.test.ts +0 -73
- package/tests/skill-learner.test.ts +0 -161
- package/tests/streaming.test.ts +0 -109
- package/tests/studio.test.ts +0 -402
- package/tests/subagent.test.ts +0 -193
- package/tests/telegram-discord.test.ts +0 -60
- package/tests/telemetry.test.ts +0 -186
- package/tests/templates.test.ts +0 -77
- package/tests/tools/builtin-extended.test.ts +0 -138
- package/tests/user-profiler.test.ts +0 -169
- package/tests/v070.test.ts +0 -76
- package/tests/v090-features.test.ts +0 -254
- package/tests/versioning.test.ts +0 -75
- package/tests/vision.test.ts +0 -61
- package/tests/voice-call.test.ts +0 -47
- package/tests/voice-enhanced.test.ts +0 -169
- package/tests/voice-interaction.test.ts +0 -38
- package/tests/voice.test.ts +0 -61
- package/tests/web-search.test.ts +0 -155
- package/tests/webhook.test.ts +0 -29
- package/tests/workflow-graph.test.ts +0 -279
- package/tests/workflow.test.ts +0 -143
- package/tmp-js-test.js +0 -1532
- package/tmp-sc.js +0 -1716
- package/tutorial/customer-service-agent/README.md +0 -612
- package/tutorial/customer-service-agent/SOUL.md +0 -26
- package/tutorial/customer-service-agent/agent.yaml +0 -63
- package/tutorial/customer-service-agent/package.json +0 -19
- package/tutorial/customer-service-agent/src/index.ts +0 -69
- package/tutorial/customer-service-agent/src/skills/faq.ts +0 -27
- package/tutorial/customer-service-agent/src/skills/ticket.ts +0 -22
- package/tutorial/customer-service-agent/tsconfig.json +0 -14
- package/vitest.config.ts +0 -9
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Analytics Engine - Persistent analytics with JSON file storage.
|
|
3
|
-
* Tracks every message, LLM call, tool use, and error with timestamps.
|
|
4
|
-
*/
|
|
5
|
-
import * as fs from 'fs';
|
|
6
|
-
import * as path from 'path';
|
|
7
|
-
|
|
8
|
-
export interface AnalyticsEvent {
|
|
9
|
-
type: 'message' | 'llm_call' | 'tool_use' | 'error';
|
|
10
|
-
timestamp: number;
|
|
11
|
-
data: Record<string, any>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface AnalyticsStats {
|
|
15
|
-
totalMessages: number;
|
|
16
|
-
totalLLMCalls: number;
|
|
17
|
-
totalToolUses: number;
|
|
18
|
-
totalErrors: number;
|
|
19
|
-
avgResponseTimeMs: number;
|
|
20
|
-
totalTokens: { input: number; output: number; total: number };
|
|
21
|
-
topSkills: { name: string; count: number }[];
|
|
22
|
-
topErrors: { message: string; count: number }[];
|
|
23
|
-
messagesPerDay: Record<string, number>;
|
|
24
|
-
period: { from: number; to: number };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class AnalyticsEngine {
|
|
28
|
-
private dataDir: string;
|
|
29
|
-
private eventsFile: string;
|
|
30
|
-
private events: AnalyticsEvent[] = [];
|
|
31
|
-
|
|
32
|
-
constructor(dataDir: string = '.') {
|
|
33
|
-
this.dataDir = path.resolve(dataDir, 'data');
|
|
34
|
-
this.eventsFile = path.join(this.dataDir, 'analytics.json');
|
|
35
|
-
this.load();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private load(): void {
|
|
39
|
-
try {
|
|
40
|
-
if (fs.existsSync(this.eventsFile)) {
|
|
41
|
-
const raw = fs.readFileSync(this.eventsFile, 'utf-8');
|
|
42
|
-
this.events = JSON.parse(raw);
|
|
43
|
-
}
|
|
44
|
-
} catch {
|
|
45
|
-
this.events = [];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private save(): void {
|
|
50
|
-
if (!fs.existsSync(this.dataDir)) {
|
|
51
|
-
fs.mkdirSync(this.dataDir, { recursive: true });
|
|
52
|
-
}
|
|
53
|
-
// Keep last 10000 events to prevent unbounded growth
|
|
54
|
-
if (this.events.length > 10000) {
|
|
55
|
-
this.events = this.events.slice(-10000);
|
|
56
|
-
}
|
|
57
|
-
fs.writeFileSync(this.eventsFile, JSON.stringify(this.events, null, 2));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
track(type: AnalyticsEvent['type'], data: Record<string, any>): void {
|
|
61
|
-
this.events.push({ type, timestamp: Date.now(), data });
|
|
62
|
-
this.save();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
trackMessage(userId: string, responseTimeMs: number, tokensIn: number, tokensOut: number): void {
|
|
66
|
-
this.track('message', { userId, responseTimeMs, tokensIn, tokensOut });
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
trackLLMCall(provider: string, model: string, tokensIn: number, tokensOut: number, latencyMs: number): void {
|
|
70
|
-
this.track('llm_call', { provider, model, tokensIn, tokensOut, latencyMs });
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
trackToolUse(toolName: string, success: boolean, latencyMs: number): void {
|
|
74
|
-
this.track('tool_use', { toolName, success, latencyMs });
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
trackError(error: string, context?: string): void {
|
|
78
|
-
this.track('error', { error, context });
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
getStats(fromTs?: number, toTs?: number): AnalyticsStats {
|
|
82
|
-
const now = Date.now();
|
|
83
|
-
const from = fromTs ?? 0;
|
|
84
|
-
const to = toTs ?? now;
|
|
85
|
-
const filtered = this.events.filter(e => e.timestamp >= from && e.timestamp <= to);
|
|
86
|
-
|
|
87
|
-
const messages = filtered.filter(e => e.type === 'message');
|
|
88
|
-
const llmCalls = filtered.filter(e => e.type === 'llm_call');
|
|
89
|
-
const toolUses = filtered.filter(e => e.type === 'tool_use');
|
|
90
|
-
const errors = filtered.filter(e => e.type === 'error');
|
|
91
|
-
|
|
92
|
-
// Avg response time
|
|
93
|
-
const totalResponseTime = messages.reduce((sum, e) => sum + (e.data.responseTimeMs ?? 0), 0);
|
|
94
|
-
const avgResponseTimeMs = messages.length > 0 ? Math.round(totalResponseTime / messages.length) : 0;
|
|
95
|
-
|
|
96
|
-
// Total tokens
|
|
97
|
-
const totalTokensIn = llmCalls.reduce((sum, e) => sum + (e.data.tokensIn ?? 0), 0);
|
|
98
|
-
const totalTokensOut = llmCalls.reduce((sum, e) => sum + (e.data.tokensOut ?? 0), 0);
|
|
99
|
-
|
|
100
|
-
// Top skills (from tool_use)
|
|
101
|
-
const skillCounts: Record<string, number> = {};
|
|
102
|
-
for (const e of toolUses) {
|
|
103
|
-
const name = e.data.toolName ?? 'unknown';
|
|
104
|
-
skillCounts[name] = (skillCounts[name] ?? 0) + 1;
|
|
105
|
-
}
|
|
106
|
-
const topSkills = Object.entries(skillCounts)
|
|
107
|
-
.sort((a, b) => b[1] - a[1])
|
|
108
|
-
.slice(0, 10)
|
|
109
|
-
.map(([name, count]) => ({ name, count }));
|
|
110
|
-
|
|
111
|
-
// Top errors
|
|
112
|
-
const errorCounts: Record<string, number> = {};
|
|
113
|
-
for (const e of errors) {
|
|
114
|
-
const msg = e.data.error ?? 'unknown';
|
|
115
|
-
errorCounts[msg] = (errorCounts[msg] ?? 0) + 1;
|
|
116
|
-
}
|
|
117
|
-
const topErrors = Object.entries(errorCounts)
|
|
118
|
-
.sort((a, b) => b[1] - a[1])
|
|
119
|
-
.slice(0, 10)
|
|
120
|
-
.map(([message, count]) => ({ message, count }));
|
|
121
|
-
|
|
122
|
-
// Messages per day
|
|
123
|
-
const messagesPerDay: Record<string, number> = {};
|
|
124
|
-
for (const e of messages) {
|
|
125
|
-
const day = new Date(e.timestamp).toISOString().slice(0, 10);
|
|
126
|
-
messagesPerDay[day] = (messagesPerDay[day] ?? 0) + 1;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
totalMessages: messages.length,
|
|
131
|
-
totalLLMCalls: llmCalls.length,
|
|
132
|
-
totalToolUses: toolUses.length,
|
|
133
|
-
totalErrors: errors.length,
|
|
134
|
-
avgResponseTimeMs,
|
|
135
|
-
totalTokens: { input: totalTokensIn, output: totalTokensOut, total: totalTokensIn + totalTokensOut },
|
|
136
|
-
topSkills,
|
|
137
|
-
topErrors,
|
|
138
|
-
messagesPerDay,
|
|
139
|
-
period: { from, to },
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
getRecentEvents(limit: number = 50): AnalyticsEvent[] {
|
|
144
|
-
return this.events.slice(-limit);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
clear(): void {
|
|
148
|
-
this.events = [];
|
|
149
|
-
this.save();
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Format stats for CLI display.
|
|
154
|
-
*/
|
|
155
|
-
static formatStats(stats: AnalyticsStats): string {
|
|
156
|
-
const lines: string[] = [];
|
|
157
|
-
lines.push('');
|
|
158
|
-
lines.push('══════════════════════════════════════════');
|
|
159
|
-
lines.push(' OPC Agent Analytics');
|
|
160
|
-
lines.push('══════════════════════════════════════════');
|
|
161
|
-
lines.push('');
|
|
162
|
-
lines.push(` 📨 Messages: ${stats.totalMessages}`);
|
|
163
|
-
lines.push(` 🤖 LLM Calls: ${stats.totalLLMCalls}`);
|
|
164
|
-
lines.push(` 🔧 Tool Uses: ${stats.totalToolUses}`);
|
|
165
|
-
lines.push(` ❌ Errors: ${stats.totalErrors}`);
|
|
166
|
-
lines.push(` ⏱ Avg Response: ${stats.avgResponseTimeMs}ms`);
|
|
167
|
-
lines.push(` 🪙 Tokens: ${stats.totalTokens.total} (in: ${stats.totalTokens.input}, out: ${stats.totalTokens.output})`);
|
|
168
|
-
lines.push('');
|
|
169
|
-
if (stats.topSkills.length > 0) {
|
|
170
|
-
lines.push(' Top Skills:');
|
|
171
|
-
for (const s of stats.topSkills.slice(0, 5)) {
|
|
172
|
-
lines.push(` • ${s.name}: ${s.count}`);
|
|
173
|
-
}
|
|
174
|
-
lines.push('');
|
|
175
|
-
}
|
|
176
|
-
if (stats.topErrors.length > 0) {
|
|
177
|
-
lines.push(' Top Errors:');
|
|
178
|
-
for (const e of stats.topErrors.slice(0, 3)) {
|
|
179
|
-
lines.push(` • ${e.message}: ${e.count}`);
|
|
180
|
-
}
|
|
181
|
-
lines.push('');
|
|
182
|
-
}
|
|
183
|
-
lines.push('──────────────────────────────────────────');
|
|
184
|
-
return lines.join('\n');
|
|
185
|
-
}
|
|
186
|
-
}
|
package/src/core/api-server.ts
DELETED
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
import * as http from 'http';
|
|
2
|
-
import { randomUUID } from 'crypto';
|
|
3
|
-
|
|
4
|
-
export interface APIServerConfig {
|
|
5
|
-
port: number;
|
|
6
|
-
host: string;
|
|
7
|
-
apiKey?: string;
|
|
8
|
-
agent: any;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface OpenAIError {
|
|
12
|
-
error: { message: string; type: string; code: string | number };
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function jsonError(message: string, type: string, code: string | number): OpenAIError {
|
|
16
|
-
return { error: { message, type, code } };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function corsHeaders(): Record<string, string> {
|
|
20
|
-
return {
|
|
21
|
-
'Access-Control-Allow-Origin': '*',
|
|
22
|
-
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
|
23
|
-
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function parseBody(req: http.IncomingMessage): Promise<string> {
|
|
28
|
-
return new Promise((resolve, reject) => {
|
|
29
|
-
const chunks: Buffer[] = [];
|
|
30
|
-
req.on('data', (c) => chunks.push(c));
|
|
31
|
-
req.on('end', () => resolve(Buffer.concat(chunks).toString()));
|
|
32
|
-
req.on('error', reject);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function sendJSON(res: http.ServerResponse, status: number, data: unknown): void {
|
|
37
|
-
const body = JSON.stringify(data);
|
|
38
|
-
res.writeHead(status, { ...corsHeaders(), 'Content-Type': 'application/json' });
|
|
39
|
-
res.end(body);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class APIServer {
|
|
43
|
-
private server: http.Server | null = null;
|
|
44
|
-
private config: APIServerConfig;
|
|
45
|
-
|
|
46
|
-
constructor(config: Partial<APIServerConfig> & { agent: any }) {
|
|
47
|
-
this.config = {
|
|
48
|
-
port: config.port ?? 8080,
|
|
49
|
-
host: config.host ?? '0.0.0.0',
|
|
50
|
-
apiKey: config.apiKey,
|
|
51
|
-
agent: config.agent,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private authenticate(req: http.IncomingMessage): boolean {
|
|
56
|
-
if (!this.config.apiKey) return true;
|
|
57
|
-
const auth = req.headers['authorization'] ?? '';
|
|
58
|
-
return auth === `Bearer ${this.config.apiKey}`;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async start(): Promise<void> {
|
|
62
|
-
return new Promise((resolve) => {
|
|
63
|
-
this.server = http.createServer((req, res) => this.handleRequest(req, res));
|
|
64
|
-
this.server.listen(this.config.port, this.config.host, () => resolve());
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async stop(): Promise<void> {
|
|
69
|
-
return new Promise((resolve) => {
|
|
70
|
-
if (this.server) this.server.close(() => resolve());
|
|
71
|
-
else resolve();
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
getPort(): number { return this.config.port; }
|
|
76
|
-
getHost(): string { return this.config.host; }
|
|
77
|
-
|
|
78
|
-
private async handleRequest(req: http.IncomingMessage, res: http.ServerResponse): Promise<void> {
|
|
79
|
-
const url = req.url ?? '/';
|
|
80
|
-
const method = req.method ?? 'GET';
|
|
81
|
-
|
|
82
|
-
// CORS preflight
|
|
83
|
-
if (method === 'OPTIONS') {
|
|
84
|
-
res.writeHead(204, corsHeaders());
|
|
85
|
-
res.end();
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Health check (no auth)
|
|
90
|
-
if (method === 'GET' && url === '/health') {
|
|
91
|
-
sendJSON(res, 200, { status: 'ok', timestamp: new Date().toISOString() });
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Auth check for all other endpoints
|
|
96
|
-
if (!this.authenticate(req)) {
|
|
97
|
-
sendJSON(res, 401, jsonError('Invalid API key', 'authentication_error', 401));
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
if (method === 'GET' && url === '/v1/models') {
|
|
103
|
-
return this.handleModels(res);
|
|
104
|
-
}
|
|
105
|
-
if (method === 'GET' && url === '/v1/agent/status') {
|
|
106
|
-
return this.handleAgentStatus(res);
|
|
107
|
-
}
|
|
108
|
-
if (method === 'POST' && url === '/v1/chat/completions') {
|
|
109
|
-
return await this.handleChatCompletions(req, res);
|
|
110
|
-
}
|
|
111
|
-
if (method === 'POST' && url === '/v1/embeddings') {
|
|
112
|
-
return await this.handleEmbeddings(req, res);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
sendJSON(res, 404, jsonError('Not found', 'not_found', 404));
|
|
116
|
-
} catch (err) {
|
|
117
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
118
|
-
sendJSON(res, 500, jsonError(msg, 'internal_error', 500));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
private handleModels(res: http.ServerResponse): void {
|
|
123
|
-
const agent = this.config.agent;
|
|
124
|
-
const modelId = agent?.config?.model ?? agent?.model ?? 'default';
|
|
125
|
-
sendJSON(res, 200, {
|
|
126
|
-
object: 'list',
|
|
127
|
-
data: [{ id: modelId, object: 'model', created: Math.floor(Date.now() / 1000), owned_by: 'opc-agent' }],
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
private handleAgentStatus(res: http.ServerResponse): void {
|
|
132
|
-
const agent = this.config.agent;
|
|
133
|
-
sendJSON(res, 200, {
|
|
134
|
-
name: agent?.name ?? agent?.config?.name ?? 'unknown',
|
|
135
|
-
state: agent?.state ?? 'unknown',
|
|
136
|
-
uptime: process.uptime(),
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private async handleChatCompletions(req: http.IncomingMessage, res: http.ServerResponse): Promise<void> {
|
|
141
|
-
let body: any;
|
|
142
|
-
try {
|
|
143
|
-
body = JSON.parse(await parseBody(req));
|
|
144
|
-
} catch {
|
|
145
|
-
sendJSON(res, 400, jsonError('Invalid JSON body', 'invalid_request_error', 400));
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const { model, messages, temperature, max_tokens, stream, tools } = body;
|
|
150
|
-
if (!messages || !Array.isArray(messages)) {
|
|
151
|
-
sendJSON(res, 400, jsonError('messages is required and must be an array', 'invalid_request_error', 400));
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const agent = this.config.agent;
|
|
156
|
-
const requestId = `chatcmpl-${randomUUID().replace(/-/g, '').slice(0, 24)}`;
|
|
157
|
-
const modelId = model ?? agent?.config?.model ?? agent?.model ?? 'default';
|
|
158
|
-
|
|
159
|
-
if (stream) {
|
|
160
|
-
// SSE streaming
|
|
161
|
-
res.writeHead(200, {
|
|
162
|
-
...corsHeaders(),
|
|
163
|
-
'Content-Type': 'text/event-stream',
|
|
164
|
-
'Cache-Control': 'no-cache',
|
|
165
|
-
'Connection': 'keep-alive',
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
try {
|
|
169
|
-
const responseText = await this.getAgentResponse(agent, messages, { temperature, max_tokens, tools });
|
|
170
|
-
// Stream in chunks
|
|
171
|
-
const chunkSize = 10;
|
|
172
|
-
for (let i = 0; i < responseText.length; i += chunkSize) {
|
|
173
|
-
const delta = responseText.slice(i, i + chunkSize);
|
|
174
|
-
const chunk = {
|
|
175
|
-
id: requestId,
|
|
176
|
-
object: 'chat.completion.chunk',
|
|
177
|
-
created: Math.floor(Date.now() / 1000),
|
|
178
|
-
model: modelId,
|
|
179
|
-
choices: [{ index: 0, delta: { content: delta }, finish_reason: null }],
|
|
180
|
-
};
|
|
181
|
-
res.write(`data: ${JSON.stringify(chunk)}\n\n`);
|
|
182
|
-
}
|
|
183
|
-
// Final chunk
|
|
184
|
-
const finalChunk = {
|
|
185
|
-
id: requestId,
|
|
186
|
-
object: 'chat.completion.chunk',
|
|
187
|
-
created: Math.floor(Date.now() / 1000),
|
|
188
|
-
model: modelId,
|
|
189
|
-
choices: [{ index: 0, delta: {}, finish_reason: 'stop' }],
|
|
190
|
-
};
|
|
191
|
-
res.write(`data: ${JSON.stringify(finalChunk)}\n\n`);
|
|
192
|
-
res.write('data: [DONE]\n\n');
|
|
193
|
-
} catch (err) {
|
|
194
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
195
|
-
res.write(`data: ${JSON.stringify({ error: { message: errMsg } })}\n\n`);
|
|
196
|
-
}
|
|
197
|
-
res.end();
|
|
198
|
-
} else {
|
|
199
|
-
// Non-streaming
|
|
200
|
-
const responseText = await this.getAgentResponse(agent, messages, { temperature, max_tokens, tools });
|
|
201
|
-
sendJSON(res, 200, {
|
|
202
|
-
id: requestId,
|
|
203
|
-
object: 'chat.completion',
|
|
204
|
-
created: Math.floor(Date.now() / 1000),
|
|
205
|
-
model: modelId,
|
|
206
|
-
choices: [{
|
|
207
|
-
index: 0,
|
|
208
|
-
message: { role: 'assistant', content: responseText },
|
|
209
|
-
finish_reason: 'stop',
|
|
210
|
-
}],
|
|
211
|
-
usage: {
|
|
212
|
-
prompt_tokens: messages.reduce((a: number, m: any) => a + (m.content?.length ?? 0), 0),
|
|
213
|
-
completion_tokens: responseText.length,
|
|
214
|
-
total_tokens: messages.reduce((a: number, m: any) => a + (m.content?.length ?? 0), 0) + responseText.length,
|
|
215
|
-
},
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
private async getAgentResponse(agent: any, messages: any[], options: any): Promise<string> {
|
|
221
|
-
// Try various agent interfaces
|
|
222
|
-
if (agent?.chat) {
|
|
223
|
-
const lastUserMsg = [...messages].reverse().find((m: any) => m.role === 'user');
|
|
224
|
-
return await agent.chat(lastUserMsg?.content ?? '', options);
|
|
225
|
-
}
|
|
226
|
-
if (agent?.processMessage) {
|
|
227
|
-
const lastUserMsg = [...messages].reverse().find((m: any) => m.role === 'user');
|
|
228
|
-
const result = await agent.processMessage({ id: 'api', role: 'user', content: lastUserMsg?.content ?? '', timestamp: Date.now() });
|
|
229
|
-
return result?.response ?? result?.content ?? String(result);
|
|
230
|
-
}
|
|
231
|
-
if (agent?.provider?.chat) {
|
|
232
|
-
const formatted = messages.map((m: any) => ({ id: 'x', role: m.role, content: m.content, timestamp: Date.now() }));
|
|
233
|
-
return await agent.provider.chat(formatted, agent.systemPrompt ?? '');
|
|
234
|
-
}
|
|
235
|
-
return 'Agent does not support chat interface';
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
private async handleEmbeddings(req: http.IncomingMessage, res: http.ServerResponse): Promise<void> {
|
|
239
|
-
let body: any;
|
|
240
|
-
try {
|
|
241
|
-
body = JSON.parse(await parseBody(req));
|
|
242
|
-
} catch {
|
|
243
|
-
sendJSON(res, 400, jsonError('Invalid JSON body', 'invalid_request_error', 400));
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const { input, model } = body;
|
|
248
|
-
if (!input) {
|
|
249
|
-
sendJSON(res, 400, jsonError('input is required', 'invalid_request_error', 400));
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const agent = this.config.agent;
|
|
254
|
-
const inputs = Array.isArray(input) ? input : [input];
|
|
255
|
-
|
|
256
|
-
try {
|
|
257
|
-
if (agent?.embed || agent?.provider?.embed) {
|
|
258
|
-
const embedFn = agent.embed?.bind(agent) ?? agent.provider.embed.bind(agent.provider);
|
|
259
|
-
const data = await Promise.all(inputs.map(async (text: string, i: number) => {
|
|
260
|
-
const embedding = await embedFn(text);
|
|
261
|
-
return { object: 'embedding', embedding, index: i };
|
|
262
|
-
}));
|
|
263
|
-
sendJSON(res, 200, {
|
|
264
|
-
object: 'list',
|
|
265
|
-
data,
|
|
266
|
-
model: model ?? 'default',
|
|
267
|
-
usage: { prompt_tokens: inputs.join('').length, total_tokens: inputs.join('').length },
|
|
268
|
-
});
|
|
269
|
-
} else {
|
|
270
|
-
sendJSON(res, 501, jsonError('Embedding provider not configured', 'not_implemented', 501));
|
|
271
|
-
}
|
|
272
|
-
} catch (err) {
|
|
273
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
274
|
-
sendJSON(res, 500, jsonError(msg, 'internal_error', 500));
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
package/src/core/audio.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Audio Processor - v1.0.0
|
|
3
|
-
* Audio transcription/synthesis wrappers with format detection, duration, split.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export type AudioFormat = 'wav' | 'mp3' | 'ogg' | 'flac' | 'webm' | 'aac' | 'unknown';
|
|
7
|
-
|
|
8
|
-
export interface TranscribeOptions {
|
|
9
|
-
language?: string;
|
|
10
|
-
model?: string;
|
|
11
|
-
provider?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface SynthesizeOptions {
|
|
15
|
-
voice?: string;
|
|
16
|
-
speed?: number;
|
|
17
|
-
format?: AudioFormat;
|
|
18
|
-
provider?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface TranscribeResult {
|
|
22
|
-
text: string;
|
|
23
|
-
language?: string;
|
|
24
|
-
duration?: number;
|
|
25
|
-
segments?: { start: number; end: number; text: string }[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface SynthesizeResult {
|
|
29
|
-
audio: Buffer;
|
|
30
|
-
format: AudioFormat;
|
|
31
|
-
duration?: number;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type TranscribeFunction = (audio: Buffer, options?: TranscribeOptions) => Promise<TranscribeResult>;
|
|
35
|
-
export type SynthesizeFunction = (text: string, options?: SynthesizeOptions) => Promise<SynthesizeResult>;
|
|
36
|
-
|
|
37
|
-
const FORMAT_SIGNATURES: [Buffer, AudioFormat][] = [
|
|
38
|
-
[Buffer.from('RIFF'), 'wav'],
|
|
39
|
-
[Buffer.from([0xff, 0xfb]), 'mp3'],
|
|
40
|
-
[Buffer.from([0xff, 0xf3]), 'mp3'],
|
|
41
|
-
[Buffer.from([0xff, 0xf2]), 'mp3'],
|
|
42
|
-
[Buffer.from([0x49, 0x44, 0x33]), 'mp3'], // ID3
|
|
43
|
-
[Buffer.from('OggS'), 'ogg'],
|
|
44
|
-
[Buffer.from('fLaC'), 'flac'],
|
|
45
|
-
[Buffer.from([0x1a, 0x45, 0xdf, 0xa3]), 'webm'],
|
|
46
|
-
];
|
|
47
|
-
|
|
48
|
-
export class AudioProcessor {
|
|
49
|
-
private transcribeFn?: TranscribeFunction;
|
|
50
|
-
private synthesizeFn?: SynthesizeFunction;
|
|
51
|
-
|
|
52
|
-
constructor(options?: { transcribe?: TranscribeFunction; synthesize?: SynthesizeFunction }) {
|
|
53
|
-
this.transcribeFn = options?.transcribe;
|
|
54
|
-
this.synthesizeFn = options?.synthesize;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Detect audio format from buffer header */
|
|
58
|
-
static detectFormat(audio: Buffer): AudioFormat {
|
|
59
|
-
for (const [sig, fmt] of FORMAT_SIGNATURES) {
|
|
60
|
-
if (audio.length >= sig.length && audio.subarray(0, sig.length).equals(sig)) return fmt;
|
|
61
|
-
}
|
|
62
|
-
return 'unknown';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Estimate duration in seconds for WAV files (for others returns undefined) */
|
|
66
|
-
static estimateDuration(audio: Buffer): number | undefined {
|
|
67
|
-
const fmt = AudioProcessor.detectFormat(audio);
|
|
68
|
-
if (fmt === 'wav' && audio.length >= 44) {
|
|
69
|
-
const sampleRate = audio.readUInt32LE(24);
|
|
70
|
-
const byteRate = audio.readUInt32LE(28);
|
|
71
|
-
if (byteRate > 0) {
|
|
72
|
-
const dataSize = audio.length - 44;
|
|
73
|
-
return dataSize / byteRate;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Split audio buffer into chunks of roughly `chunkBytes` size */
|
|
80
|
-
static split(audio: Buffer, chunkBytes: number): Buffer[] {
|
|
81
|
-
if (chunkBytes <= 0) throw new Error('chunkBytes must be positive');
|
|
82
|
-
const chunks: Buffer[] = [];
|
|
83
|
-
for (let i = 0; i < audio.length; i += chunkBytes) {
|
|
84
|
-
chunks.push(audio.subarray(i, Math.min(i + chunkBytes, audio.length)));
|
|
85
|
-
}
|
|
86
|
-
return chunks;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async transcribe(audio: Buffer, options?: TranscribeOptions): Promise<TranscribeResult> {
|
|
90
|
-
if (!this.transcribeFn) throw new Error('No transcribe provider configured');
|
|
91
|
-
return this.transcribeFn(audio, options);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async synthesize(text: string, options?: SynthesizeOptions): Promise<SynthesizeResult> {
|
|
95
|
-
if (!this.synthesizeFn) throw new Error('No synthesize provider configured');
|
|
96
|
-
return this.synthesizeFn(text, options);
|
|
97
|
-
}
|
|
98
|
-
}
|
package/src/core/auth.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { Request, Response, NextFunction } from 'express';
|
|
2
|
-
|
|
3
|
-
export interface AuthConfig {
|
|
4
|
-
apiKeys: string[];
|
|
5
|
-
sessionIsolation?: boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface AuthSession {
|
|
9
|
-
apiKey: string;
|
|
10
|
-
userId: string;
|
|
11
|
-
createdAt: number;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const sessions = new Map<string, AuthSession>();
|
|
15
|
-
|
|
16
|
-
export function createAuthMiddleware(config: AuthConfig) {
|
|
17
|
-
return (req: Request, res: Response, next: NextFunction): void => {
|
|
18
|
-
// Skip auth for non-API routes and health/metrics
|
|
19
|
-
if (!req.path.startsWith('/api/') || req.path === '/api/health' || req.path === '/api/metrics') {
|
|
20
|
-
next();
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const apiKey = req.headers['x-api-key'] as string
|
|
25
|
-
?? req.headers['authorization']?.replace(/^Bearer\s+/i, '')
|
|
26
|
-
?? (req.query as any).apiKey;
|
|
27
|
-
|
|
28
|
-
if (!apiKey || !config.apiKeys.includes(apiKey)) {
|
|
29
|
-
res.status(401).json({ error: 'Unauthorized. Provide a valid API key via X-API-Key header, Bearer token, or ?apiKey query.' });
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Derive userId from API key for session isolation
|
|
34
|
-
const userId = `user_${hashKey(apiKey)}`;
|
|
35
|
-
if (!sessions.has(apiKey)) {
|
|
36
|
-
sessions.set(apiKey, { apiKey, userId, createdAt: Date.now() });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Attach user info to request
|
|
40
|
-
(req as any).userId = userId;
|
|
41
|
-
(req as any).sessionPrefix = config.sessionIsolation ? `${userId}:` : '';
|
|
42
|
-
|
|
43
|
-
next();
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function hashKey(key: string): string {
|
|
48
|
-
let h = 0;
|
|
49
|
-
for (let i = 0; i < key.length; i++) {
|
|
50
|
-
h = ((h << 5) - h + key.charCodeAt(i)) | 0;
|
|
51
|
-
}
|
|
52
|
-
return Math.abs(h).toString(36);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function getActiveSessions(): AuthSession[] {
|
|
56
|
-
return Array.from(sessions.values());
|
|
57
|
-
}
|