@crewx/sdk 0.8.0-rc.73 → 0.8.0-rc.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +380 -818
- package/dist/adapter/context-builder.d.ts +35 -0
- package/dist/adapter/context-builder.js +87 -0
- package/dist/adapter/index.d.ts +5 -0
- package/dist/{core/remote → adapter}/index.js +3 -2
- package/dist/adapter/plugin-helper.d.ts +19 -0
- package/dist/adapter/plugin-helper.js +45 -0
- package/dist/adapter/scoped-store.d.ts +12 -0
- package/dist/adapter/scoped-store.js +43 -0
- package/dist/adapter/types.d.ts +264 -0
- package/dist/adapter/types.js +23 -0
- package/dist/agent/resolver.d.ts +18 -0
- package/dist/agent/resolver.js +46 -0
- package/dist/boxing/box-storage.interface.d.ts +12 -0
- package/dist/boxing/box-storage.interface.js +3 -0
- package/dist/boxing/box.service.d.ts +4 -0
- package/dist/boxing/box.service.js +5 -1
- package/dist/boxing/box.types.d.ts +4 -0
- package/dist/boxing/box.types.js +3 -0
- package/dist/boxing/context-builder.d.ts +6 -7
- package/dist/boxing/context-builder.js +3 -0
- package/dist/client/CrewxClient.d.ts +65 -0
- package/dist/client/CrewxClient.js +86 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +6 -0
- package/dist/config/loader.browser.d.ts +14 -0
- package/dist/config/loader.browser.js +59 -0
- package/dist/config/loader.d.ts +19 -0
- package/dist/config/loader.js +95 -0
- package/dist/conversation/index.d.ts +5 -3
- package/dist/conversation/index.js +8 -3
- package/dist/conversation/sqlite-provider.d.ts +21 -0
- package/dist/conversation/sqlite-provider.js +178 -0
- package/dist/conversation/to-task-reader.d.ts +14 -0
- package/dist/conversation/to-task-reader.js +28 -0
- package/dist/conversation/to-template-messages.d.ts +15 -0
- package/dist/conversation/to-template-messages.js +34 -0
- package/dist/conversation/types.d.ts +101 -0
- package/dist/conversation/types.js +10 -0
- package/dist/esm/agent/resolver.js +41 -0
- package/dist/esm/boxing/box-storage.interface.js +5 -0
- package/dist/esm/boxing/box.service.js +69 -0
- package/dist/esm/boxing/box.types.js +5 -0
- package/dist/esm/boxing/context-builder.js +76 -0
- package/dist/esm/client/CrewxClient.js +82 -0
- package/dist/esm/client/index.js +2 -0
- package/dist/esm/config/loader.browser.js +54 -0
- package/dist/esm/config/loader.js +77 -0
- package/dist/esm/events/TypedEventEmitter.js +61 -0
- package/dist/esm/events/types.js +8 -0
- package/dist/esm/facade/Crewx.browser.js +310 -0
- package/dist/esm/facade/Crewx.js +941 -0
- package/dist/esm/hooks/define.js +10 -0
- package/dist/esm/hooks/dispatch.js +76 -0
- package/dist/esm/hooks/index.js +6 -0
- package/dist/esm/hooks/observer.js +56 -0
- package/dist/esm/hooks/plugin.js +12 -0
- package/dist/esm/hooks/types.js +9 -0
- package/dist/esm/index.browser.js +15 -0
- package/dist/esm/index.js +60 -0
- package/dist/esm/layout/loader.js +268 -0
- package/dist/esm/layout/props-validator.js +297 -0
- package/dist/esm/layout/renderer.js +180 -0
- package/dist/esm/layout/types.js +31 -0
- package/dist/esm/parallel/agent-runtime.js +21 -0
- package/dist/esm/parallel/helpers.js +214 -0
- package/dist/esm/parallel/index.js +5 -0
- package/dist/esm/parallel/parallel-runner.js +221 -0
- package/dist/esm/parallel/types.js +5 -0
- package/dist/esm/parsers/agent-call.util.js +15 -0
- package/dist/esm/parsers/claude.parser.js +64 -0
- package/dist/esm/parsers/codex.parser.js +97 -0
- package/dist/esm/parsers/copilot.parser.js +63 -0
- package/dist/esm/parsers/gemini.parser.js +43 -0
- package/dist/esm/parsers/opencode.parser.js +73 -0
- package/dist/esm/parsers/router.js +53 -0
- package/dist/esm/platform/BrowserFsAdapter.js +80 -0
- package/dist/esm/platform/IFsAdapter.js +2 -0
- package/dist/esm/platform/NodeFsAdapter.js +34 -0
- package/dist/esm/plugin/plugin-provider.js +202 -0
- package/dist/esm/plugin/types.js +8 -0
- package/dist/esm/plugin.js +25 -0
- package/dist/esm/provider/bridge.browser.js +43 -0
- package/dist/esm/provider/bridge.js +373 -0
- package/dist/esm/provider/parse-usage.js +80 -0
- package/dist/esm/provider/register-api.js +21 -0
- package/dist/esm/provider/vercel-runtime.js +310 -0
- package/dist/esm/remote/index.js +10 -0
- package/dist/esm/remote/remote-agent-manager.js +194 -0
- package/dist/esm/remote/remote-provider.js +98 -0
- package/dist/esm/remote/remote-transport.js +79 -0
- package/dist/esm/remote/types.js +8 -0
- package/dist/esm/server/auth.js +31 -0
- package/dist/esm/server/handler.js +72 -0
- package/dist/esm/server/index.js +5 -0
- package/dist/esm/server/tool-adapter.js +92 -0
- package/dist/esm/template/engine.js +100 -0
- package/dist/esm/template/helpers/exec.browser.js +31 -0
- package/dist/esm/template/helpers/exec.js +220 -0
- package/dist/esm/template/helpers/fenced_code.js +17 -0
- package/dist/esm/template/helpers/include.js +20 -0
- package/dist/esm/template/helpers/p1p2.js +83 -0
- package/dist/esm/template/loader/DocumentLoader.js +124 -0
- package/dist/esm/template/types.js +5 -0
- package/dist/esm/tools/delegate.js +57 -0
- package/dist/esm/tools/index.js +5 -0
- package/dist/esm/tools/node/builtin.js +541 -0
- package/dist/esm/tools/node/index.js +54 -0
- package/dist/esm/types/index.js +27 -0
- package/dist/esm/types/task-log.types.js +5 -0
- package/dist/esm/utils/env-defaults.js +23 -0
- package/dist/esm/utils/glob-match.js +38 -0
- package/dist/esm/utils/id.js +46 -0
- package/dist/esm/utils/workspace.js +21 -0
- package/dist/events/TypedEventEmitter.d.ts +31 -0
- package/dist/events/TypedEventEmitter.js +65 -0
- package/dist/events/types.d.ts +139 -0
- package/dist/events/types.js +9 -0
- package/dist/facade/Crewx.browser.d.ts +73 -0
- package/dist/facade/Crewx.browser.js +314 -0
- package/dist/facade/Crewx.d.ts +267 -0
- package/dist/facade/Crewx.js +1299 -0
- package/dist/hooks/define.d.ts +10 -0
- package/dist/hooks/define.js +13 -0
- package/dist/hooks/dispatch.d.ts +61 -0
- package/dist/hooks/dispatch.js +147 -0
- package/dist/hooks/index.d.ts +13 -0
- package/dist/hooks/index.js +24 -0
- package/dist/hooks/observer.d.ts +20 -0
- package/dist/hooks/observer.js +60 -0
- package/dist/hooks/plugin.d.ts +19 -0
- package/dist/hooks/plugin.js +17 -0
- package/dist/hooks/tool-normalize.d.ts +29 -0
- package/dist/hooks/tool-normalize.js +110 -0
- package/dist/hooks/types.d.ts +79 -0
- package/dist/hooks/types.js +12 -0
- package/dist/hooks/yaml-plugin.d.ts +29 -0
- package/dist/hooks/yaml-plugin.js +356 -0
- package/dist/index.browser.d.ts +15 -0
- package/dist/index.browser.js +25 -0
- package/dist/index.d.ts +70 -58
- package/dist/index.js +144 -133
- package/dist/{services/layout-loader.service.d.ts → layout/loader.d.ts} +24 -4
- package/dist/{services/layout-loader.service.js → layout/loader.js} +103 -73
- package/dist/{services/props-validator.service.d.ts → layout/props-validator.d.ts} +7 -1
- package/dist/{services/props-validator.service.js → layout/props-validator.js} +28 -59
- package/dist/{services/layout-renderer.service.d.ts → layout/renderer.d.ts} +28 -14
- package/dist/layout/renderer.js +193 -0
- package/dist/{types/layout.types.d.ts → layout/types.d.ts} +47 -1
- package/dist/{types/layout.types.js → layout/types.js} +15 -1
- package/dist/parallel/agent-runtime.d.ts +31 -0
- package/dist/parallel/agent-runtime.js +25 -0
- package/dist/{core/parallel → parallel}/helpers.d.ts +2 -1
- package/dist/{core/parallel → parallel}/helpers.js +55 -88
- package/dist/parallel/index.d.ts +8 -0
- package/dist/{core/parallel → parallel}/index.js +5 -3
- package/dist/{core/parallel → parallel}/parallel-runner.d.ts +8 -1
- package/dist/{core/parallel → parallel}/parallel-runner.js +53 -57
- package/dist/parallel/types.d.ts +65 -0
- package/dist/parallel/types.js +6 -0
- package/dist/parsers/agent-call.util.d.ts +3 -0
- package/dist/parsers/agent-call.util.js +2 -0
- package/dist/parsers/api.parser.d.ts +10 -0
- package/dist/parsers/api.parser.js +26 -0
- package/dist/parsers/claude.parser.d.ts +8 -0
- package/dist/parsers/claude.parser.js +22 -1
- package/dist/parsers/codex.parser.d.ts +8 -0
- package/dist/parsers/codex.parser.js +11 -0
- package/dist/parsers/copilot.parser.d.ts +9 -0
- package/dist/parsers/copilot.parser.js +8 -0
- package/dist/parsers/gemini.parser.d.ts +10 -0
- package/dist/parsers/gemini.parser.js +10 -0
- package/dist/parsers/opencode.parser.d.ts +12 -0
- package/dist/parsers/opencode.parser.js +76 -0
- package/dist/parsers/router.d.ts +7 -0
- package/dist/parsers/router.js +56 -0
- package/dist/platform/BrowserFsAdapter.d.ts +37 -0
- package/dist/platform/BrowserFsAdapter.js +84 -0
- package/dist/platform/IFsAdapter.d.ts +29 -0
- package/dist/{core/remote/types.js → platform/IFsAdapter.js} +1 -1
- package/dist/platform/NodeFsAdapter.d.ts +16 -0
- package/dist/platform/NodeFsAdapter.js +38 -0
- package/dist/plugin/plugin-provider.d.ts +33 -0
- package/dist/plugin/plugin-provider.js +207 -0
- package/dist/plugin/types.d.ts +53 -0
- package/dist/plugin/types.js +9 -0
- package/dist/plugin.d.ts +33 -0
- package/dist/plugin.js +29 -0
- package/dist/plugins/conversation.d.ts +18 -0
- package/dist/plugins/conversation.js +59 -0
- package/dist/plugins/file-logger.d.ts +29 -0
- package/dist/plugins/file-logger.js +87 -0
- package/dist/plugins/index.d.ts +16 -0
- package/dist/plugins/index.js +19 -0
- package/dist/plugins/sqlite-tracing.d.ts +29 -0
- package/dist/plugins/sqlite-tracing.js +112 -0
- package/dist/provider/bridge.browser.d.ts +49 -0
- package/dist/provider/bridge.browser.js +49 -0
- package/dist/provider/bridge.d.ts +106 -0
- package/dist/provider/bridge.js +380 -0
- package/dist/provider/mastra-runtime.d.ts +45 -0
- package/dist/provider/mastra-runtime.js +208 -0
- package/dist/provider/parse-usage.d.ts +20 -0
- package/dist/provider/parse-usage.js +83 -0
- package/dist/provider/register-api.d.ts +14 -0
- package/dist/provider/register-api.js +24 -0
- package/dist/provider/vercel-runtime.d.ts +54 -0
- package/dist/provider/vercel-runtime.js +347 -0
- package/dist/remote/index.d.ts +13 -0
- package/dist/remote/index.js +32 -0
- package/dist/remote/remote-agent-manager.d.ts +54 -0
- package/dist/{core/remote → remote}/remote-agent-manager.js +100 -97
- package/dist/remote/remote-provider.d.ts +47 -0
- package/dist/remote/remote-provider.js +141 -0
- package/dist/remote/remote-transport.d.ts +32 -0
- package/dist/remote/remote-transport.js +83 -0
- package/dist/remote/types.d.ts +147 -0
- package/dist/remote/types.js +9 -0
- package/dist/server/auth.d.ts +21 -0
- package/dist/server/auth.js +35 -0
- package/dist/server/handler.d.ts +24 -0
- package/dist/server/handler.js +75 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.js +9 -0
- package/dist/server/tool-adapter.d.ts +19 -0
- package/dist/server/tool-adapter.js +95 -0
- package/dist/template/engine.d.ts +28 -0
- package/dist/template/engine.js +137 -0
- package/dist/template/helpers/exec.browser.d.ts +22 -0
- package/dist/template/helpers/exec.browser.js +41 -0
- package/dist/template/helpers/exec.d.ts +60 -0
- package/dist/template/helpers/exec.js +230 -0
- package/dist/template/helpers/fenced_code.d.ts +22 -0
- package/dist/template/helpers/fenced_code.js +20 -0
- package/dist/template/helpers/format-conversation.d.ts +30 -0
- package/dist/template/helpers/format-conversation.js +53 -0
- package/dist/template/helpers/include.d.ts +16 -0
- package/dist/template/helpers/include.js +23 -0
- package/dist/template/helpers/p1p2.d.ts +37 -0
- package/dist/template/helpers/p1p2.js +90 -0
- package/dist/template/loader/DocumentLoader.d.ts +48 -0
- package/dist/template/loader/DocumentLoader.js +128 -0
- package/dist/template/types.d.ts +51 -0
- package/dist/template/types.js +6 -0
- package/dist/testing/index.d.ts +12 -0
- package/dist/testing/index.js +16 -0
- package/dist/testing/mock-audit.d.ts +10 -0
- package/dist/testing/mock-audit.js +13 -0
- package/dist/testing/mock-context.d.ts +27 -0
- package/dist/testing/mock-context.js +68 -0
- package/dist/testing/mock-logger.d.ts +15 -0
- package/dist/testing/mock-logger.js +27 -0
- package/dist/testing/mock-router.d.ts +16 -0
- package/dist/testing/mock-router.js +67 -0
- package/dist/testing/mock-storage.d.ts +9 -0
- package/dist/testing/mock-storage.js +21 -0
- package/dist/testing/mock-store.d.ts +3 -0
- package/dist/testing/mock-store.js +8 -0
- package/dist/tools/delegate.d.ts +10 -0
- package/dist/tools/delegate.js +60 -0
- package/dist/tools/index.d.ts +5 -12
- package/dist/tools/index.js +6 -37
- package/dist/tools/node/builtin.d.ts +23 -0
- package/dist/tools/node/builtin.js +547 -0
- package/dist/tools/node/index.d.ts +23 -0
- package/dist/tools/node/index.js +59 -0
- package/dist/types/index.d.ts +804 -6
- package/dist/types/index.js +29 -20
- package/dist/types/task-log.types.d.ts +4 -0
- package/dist/types/task-log.types.js +3 -0
- package/dist/utils/env-defaults.d.ts +18 -0
- package/dist/utils/env-defaults.js +27 -0
- package/dist/utils/glob-match.d.ts +18 -0
- package/dist/utils/glob-match.js +42 -0
- package/dist/{core → utils}/id.d.ts +15 -0
- package/dist/utils/id.js +50 -0
- package/dist/utils/timestamp.d.ts +2 -0
- package/dist/utils/timestamp.js +13 -0
- package/dist/{core → utils}/workspace.d.ts +4 -0
- package/dist/{core → utils}/workspace.js +3 -0
- package/package.json +68 -103
- package/src/schemas/hooks.schema.json +59 -0
- package/templates/agents/default.yaml +490 -0
- package/templates/agents/minimal.yaml +16 -0
- package/LICENSE +0 -201
- package/dist/adapters/MastraToolAdapter.d.ts +0 -9
- package/dist/adapters/MastraToolAdapter.js +0 -66
- package/dist/adapters/MastraToolAdapter.js.map +0 -1
- package/dist/api/index.d.ts +0 -2
- package/dist/api/index.js +0 -8
- package/dist/api/index.js.map +0 -1
- package/dist/boxing/box-storage.interface.js.map +0 -1
- package/dist/boxing/box.service.js.map +0 -1
- package/dist/boxing/box.types.js.map +0 -1
- package/dist/boxing/context-builder.js.map +0 -1
- package/dist/boxing/index.d.ts +0 -6
- package/dist/boxing/index.js +0 -11
- package/dist/boxing/index.js.map +0 -1
- package/dist/boxing/tokenizer.d.ts +0 -3
- package/dist/boxing/tokenizer.js +0 -11
- package/dist/boxing/tokenizer.js.map +0 -1
- package/dist/config/api-provider-parser.d.ts +0 -58
- package/dist/config/api-provider-parser.js +0 -212
- package/dist/config/api-provider-parser.js.map +0 -1
- package/dist/config/index.d.ts +0 -3
- package/dist/config/index.js +0 -20
- package/dist/config/index.js.map +0 -1
- package/dist/config/log.config.d.ts +0 -7
- package/dist/config/log.config.js +0 -20
- package/dist/config/log.config.js.map +0 -1
- package/dist/config/pricing.d.ts +0 -11
- package/dist/config/pricing.js +0 -53
- package/dist/config/pricing.js.map +0 -1
- package/dist/config/timeout.config.d.ts +0 -14
- package/dist/config/timeout.config.js +0 -34
- package/dist/config/timeout.config.js.map +0 -1
- package/dist/config/yaml-loader.d.ts +0 -8
- package/dist/config/yaml-loader.js +0 -155
- package/dist/config/yaml-loader.js.map +0 -1
- package/dist/constants/index.d.ts +0 -4
- package/dist/constants/index.js +0 -8
- package/dist/constants/index.js.map +0 -1
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -18
- package/dist/constants.js.map +0 -1
- package/dist/conversation/conversation-config.d.ts +0 -9
- package/dist/conversation/conversation-config.js +0 -22
- package/dist/conversation/conversation-config.js.map +0 -1
- package/dist/conversation/conversation-history.interface.d.ts +0 -36
- package/dist/conversation/conversation-history.interface.js +0 -3
- package/dist/conversation/conversation-history.interface.js.map +0 -1
- package/dist/conversation/conversation-storage.service.d.ts +0 -16
- package/dist/conversation/conversation-storage.service.js +0 -213
- package/dist/conversation/conversation-storage.service.js.map +0 -1
- package/dist/conversation/index.js.map +0 -1
- package/dist/core/__tests__/id.test.d.ts +0 -1
- package/dist/core/__tests__/id.test.js +0 -115
- package/dist/core/__tests__/id.test.js.map +0 -1
- package/dist/core/agent/agent-factory.d.ts +0 -37
- package/dist/core/agent/agent-factory.js +0 -68
- package/dist/core/agent/agent-factory.js.map +0 -1
- package/dist/core/agent/agent-runtime.d.ts +0 -52
- package/dist/core/agent/agent-runtime.js +0 -206
- package/dist/core/agent/agent-runtime.js.map +0 -1
- package/dist/core/agent/event-bus.d.ts +0 -44
- package/dist/core/agent/event-bus.js +0 -43
- package/dist/core/agent/event-bus.js.map +0 -1
- package/dist/core/agent/index.d.ts +0 -3
- package/dist/core/agent/index.js +0 -13
- package/dist/core/agent/index.js.map +0 -1
- package/dist/core/env-defaults.d.ts +0 -1
- package/dist/core/env-defaults.js +0 -7
- package/dist/core/env-defaults.js.map +0 -1
- package/dist/core/id.js +0 -27
- package/dist/core/id.js.map +0 -1
- package/dist/core/parallel/helpers.js.map +0 -1
- package/dist/core/parallel/index.d.ts +0 -4
- package/dist/core/parallel/index.js.map +0 -1
- package/dist/core/parallel/parallel-runner.js.map +0 -1
- package/dist/core/parallel/types.d.ts +0 -41
- package/dist/core/parallel/types.js +0 -3
- package/dist/core/parallel/types.js.map +0 -1
- package/dist/core/providers/MastraAPIProvider.d.ts +0 -31
- package/dist/core/providers/MastraAPIProvider.js +0 -365
- package/dist/core/providers/MastraAPIProvider.js.map +0 -1
- package/dist/core/providers/ai-provider.interface.d.ts +0 -79
- package/dist/core/providers/ai-provider.interface.js +0 -23
- package/dist/core/providers/ai-provider.interface.js.map +0 -1
- package/dist/core/providers/base-ai.provider.d.ts +0 -84
- package/dist/core/providers/base-ai.provider.js +0 -1237
- package/dist/core/providers/base-ai.provider.js.map +0 -1
- package/dist/core/providers/base-ai.types.d.ts +0 -26
- package/dist/core/providers/base-ai.types.js +0 -3
- package/dist/core/providers/base-ai.types.js.map +0 -1
- package/dist/core/providers/claude.provider.d.ts +0 -19
- package/dist/core/providers/claude.provider.js +0 -170
- package/dist/core/providers/claude.provider.js.map +0 -1
- package/dist/core/providers/codex.provider.d.ts +0 -21
- package/dist/core/providers/codex.provider.js +0 -134
- package/dist/core/providers/codex.provider.js.map +0 -1
- package/dist/core/providers/copilot.provider.d.ts +0 -25
- package/dist/core/providers/copilot.provider.js +0 -146
- package/dist/core/providers/copilot.provider.js.map +0 -1
- package/dist/core/providers/dynamic-provider.factory.d.ts +0 -74
- package/dist/core/providers/dynamic-provider.factory.js +0 -645
- package/dist/core/providers/dynamic-provider.factory.js.map +0 -1
- package/dist/core/providers/gemini.provider.d.ts +0 -16
- package/dist/core/providers/gemini.provider.js +0 -101
- package/dist/core/providers/gemini.provider.js.map +0 -1
- package/dist/core/providers/index.d.ts +0 -8
- package/dist/core/providers/index.js +0 -20
- package/dist/core/providers/index.js.map +0 -1
- package/dist/core/providers/mock.provider.d.ts +0 -13
- package/dist/core/providers/mock.provider.js +0 -55
- package/dist/core/providers/mock.provider.js.map +0 -1
- package/dist/core/providers/provider-factory.d.ts +0 -3
- package/dist/core/providers/provider-factory.js +0 -65
- package/dist/core/providers/provider-factory.js.map +0 -1
- package/dist/core/providers/tool-call.types.d.ts +0 -39
- package/dist/core/providers/tool-call.types.js +0 -3
- package/dist/core/providers/tool-call.types.js.map +0 -1
- package/dist/core/remote/index.d.ts +0 -3
- package/dist/core/remote/index.js.map +0 -1
- package/dist/core/remote/remote-agent-manager.d.ts +0 -24
- package/dist/core/remote/remote-agent-manager.js.map +0 -1
- package/dist/core/remote/remote-transport.d.ts +0 -15
- package/dist/core/remote/remote-transport.js +0 -70
- package/dist/core/remote/remote-transport.js.map +0 -1
- package/dist/core/remote/types.d.ts +0 -79
- package/dist/core/remote/types.js.map +0 -1
- package/dist/core/workspace.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/internal/index.d.ts +0 -1
- package/dist/internal/index.js +0 -6
- package/dist/internal/index.js.map +0 -1
- package/dist/knowledge/DocumentManager.d.ts +0 -4
- package/dist/knowledge/DocumentManager.js +0 -119
- package/dist/knowledge/DocumentManager.js.map +0 -1
- package/dist/knowledge/index.d.ts +0 -1
- package/dist/knowledge/index.js +0 -18
- package/dist/knowledge/index.js.map +0 -1
- package/dist/parsers/agent-call.util.js.map +0 -1
- package/dist/parsers/claude.parser.js.map +0 -1
- package/dist/parsers/codex.parser.js.map +0 -1
- package/dist/parsers/copilot.parser.js.map +0 -1
- package/dist/parsers/gemini.parser.js.map +0 -1
- package/dist/parsers/index.d.ts +0 -7
- package/dist/parsers/index.js +0 -45
- package/dist/parsers/index.js.map +0 -1
- package/dist/schema/skills-parser.d.ts +0 -8
- package/dist/schema/skills-parser.js +0 -438
- package/dist/schema/skills-parser.js.map +0 -1
- package/dist/schema/skills.types.d.ts +0 -158
- package/dist/schema/skills.types.js +0 -41
- package/dist/schema/skills.types.js.map +0 -1
- package/dist/schemas/api-provider.schema.d.ts +0 -432
- package/dist/schemas/api-provider.schema.js +0 -50
- package/dist/schemas/api-provider.schema.js.map +0 -1
- package/dist/services/index.d.ts +0 -2
- package/dist/services/index.js +0 -19
- package/dist/services/index.js.map +0 -1
- package/dist/services/layout-loader.service.js.map +0 -1
- package/dist/services/layout-renderer.service.js +0 -325
- package/dist/services/layout-renderer.service.js.map +0 -1
- package/dist/services/props-validator.service.js.map +0 -1
- package/dist/skills/adapter/claude-skill-adapter.d.ts +0 -11
- package/dist/skills/adapter/claude-skill-adapter.js +0 -222
- package/dist/skills/adapter/claude-skill-adapter.js.map +0 -1
- package/dist/skills/index.d.ts +0 -6
- package/dist/skills/index.js +0 -31
- package/dist/skills/index.js.map +0 -1
- package/dist/skills/runtime/progressive-loader.d.ts +0 -27
- package/dist/skills/runtime/progressive-loader.js +0 -186
- package/dist/skills/runtime/progressive-loader.js.map +0 -1
- package/dist/skills/runtime/runtime-requirements-validator.d.ts +0 -23
- package/dist/skills/runtime/runtime-requirements-validator.js +0 -248
- package/dist/skills/runtime/runtime-requirements-validator.js.map +0 -1
- package/dist/skills/runtime/skill-runtime.service.d.ts +0 -42
- package/dist/skills/runtime/skill-runtime.service.js +0 -434
- package/dist/skills/runtime/skill-runtime.service.js.map +0 -1
- package/dist/tools/file-system.service.d.ts +0 -10
- package/dist/tools/file-system.service.js +0 -33
- package/dist/tools/file-system.service.js.map +0 -1
- package/dist/tools/find.tool.d.ts +0 -21
- package/dist/tools/find.tool.js +0 -139
- package/dist/tools/find.tool.js.map +0 -1
- package/dist/tools/glob.tool.d.ts +0 -24
- package/dist/tools/glob.tool.js +0 -153
- package/dist/tools/glob.tool.js.map +0 -1
- package/dist/tools/grep.tool.d.ts +0 -1
- package/dist/tools/grep.tool.js +0 -137
- package/dist/tools/grep.tool.js.map +0 -1
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/ls.tool.d.ts +0 -1
- package/dist/tools/ls.tool.js +0 -94
- package/dist/tools/ls.tool.js.map +0 -1
- package/dist/tools/read-file.tool.d.ts +0 -1
- package/dist/tools/read-file.tool.js +0 -69
- package/dist/tools/read-file.tool.js.map +0 -1
- package/dist/tools/replace.tool.d.ts +0 -1
- package/dist/tools/replace.tool.js +0 -68
- package/dist/tools/replace.tool.js.map +0 -1
- package/dist/tools/run-shell-command.tool.d.ts +0 -1
- package/dist/tools/run-shell-command.tool.js +0 -64
- package/dist/tools/run-shell-command.tool.js.map +0 -1
- package/dist/tools/tree.tool.d.ts +0 -1
- package/dist/tools/tree.tool.js +0 -109
- package/dist/tools/tree.tool.js.map +0 -1
- package/dist/tools/types.d.ts +0 -42
- package/dist/tools/types.js +0 -13
- package/dist/tools/types.js.map +0 -1
- package/dist/tools/utils/file-utils.d.ts +0 -5
- package/dist/tools/utils/file-utils.js +0 -221
- package/dist/tools/utils/file-utils.js.map +0 -1
- package/dist/tools/write-file.tool.d.ts +0 -1
- package/dist/tools/write-file.tool.js +0 -55
- package/dist/tools/write-file.tool.js.map +0 -1
- package/dist/types/agent.types.d.ts +0 -134
- package/dist/types/agent.types.js +0 -16
- package/dist/types/agent.types.js.map +0 -1
- package/dist/types/api-provider.types.d.ts +0 -85
- package/dist/types/api-provider.types.js +0 -65
- package/dist/types/api-provider.types.js.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/layout.types.js.map +0 -1
- package/dist/types/provider.types.d.ts +0 -12
- package/dist/types/provider.types.js +0 -3
- package/dist/types/provider.types.js.map +0 -1
- package/dist/types/skill-runtime.types.d.ts +0 -244
- package/dist/types/skill-runtime.types.js +0 -44
- package/dist/types/skill-runtime.types.js.map +0 -1
- package/dist/types/structured-payload.types.d.ts +0 -46
- package/dist/types/structured-payload.types.js +0 -65
- package/dist/types/structured-payload.types.js.map +0 -1
- package/dist/types/task-log.types.js.map +0 -1
- package/dist/types/template.types.d.ts +0 -38
- package/dist/types/template.types.js +0 -3
- package/dist/types/template.types.js.map +0 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -18
- package/dist/types.js.map +0 -1
- package/dist/utils/api-provider-normalizer.d.ts +0 -16
- package/dist/utils/api-provider-normalizer.js +0 -135
- package/dist/utils/api-provider-normalizer.js.map +0 -1
- package/dist/utils/base-message-formatter.d.ts +0 -32
- package/dist/utils/base-message-formatter.js +0 -170
- package/dist/utils/base-message-formatter.js.map +0 -1
- package/dist/utils/error-utils.d.ts +0 -3
- package/dist/utils/error-utils.js +0 -27
- package/dist/utils/error-utils.js.map +0 -1
- package/dist/utils/index.d.ts +0 -4
- package/dist/utils/index.js +0 -21
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/math-utils.d.ts +0 -3
- package/dist/utils/math-utils.js +0 -10
- package/dist/utils/math-utils.js.map +0 -1
- package/dist/utils/mention-parser.d.ts +0 -18
- package/dist/utils/mention-parser.js +0 -136
- package/dist/utils/mention-parser.js.map +0 -1
- package/dist/utils/string-utils.d.ts +0 -1
- package/dist/utils/string-utils.js +0 -10
- package/dist/utils/string-utils.js.map +0 -1
- package/dist/utils.d.ts +0 -3
- package/dist/utils.js +0 -20
- package/dist/utils.js.map +0 -1
- package/schema/api-provider-config.json +0 -138
- package/schema/crewx-config.json +0 -224
- package/schema/skills-config.json +0 -306
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Provider bridge: creates a runtime that can invoke AI providers.
|
|
4
|
+
*
|
|
5
|
+
* Supports a registry pattern — built-in cli/* providers are registered by default,
|
|
6
|
+
* and additional namespaces (e.g. api/*, webllm/*) can be added via registerProviderFactory().
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ClientToolCallRequiredError = exports.ProviderError = void 0;
|
|
10
|
+
exports.parseStreamJsonOutput = parseStreamJsonOutput;
|
|
11
|
+
exports.parseResultEventUsage = parseResultEventUsage;
|
|
12
|
+
exports.registerProviderFactory = registerProviderFactory;
|
|
13
|
+
exports.createProvider = createProvider;
|
|
14
|
+
const child_process_1 = require("child_process");
|
|
15
|
+
const parse_usage_js_1 = require("./parse-usage.js");
|
|
16
|
+
function parseStreamJsonOutput(raw) {
|
|
17
|
+
const lines = raw.split('\n').filter(l => l.trim());
|
|
18
|
+
const assistantTexts = [];
|
|
19
|
+
const geminiDeltaTokens = [];
|
|
20
|
+
const copilotTexts = [];
|
|
21
|
+
const codexTexts = [];
|
|
22
|
+
const opencodeTexts = [];
|
|
23
|
+
let resultText = null;
|
|
24
|
+
for (const line of lines) {
|
|
25
|
+
try {
|
|
26
|
+
const parsed = JSON.parse(line);
|
|
27
|
+
// Claude format: { type: 'assistant', message: { content: [...] } }
|
|
28
|
+
if (parsed.type === 'assistant' && Array.isArray(parsed.message?.content)) {
|
|
29
|
+
for (const block of parsed.message.content) {
|
|
30
|
+
if (block.type === 'text' && typeof block.text === 'string' && block.text.trim()) {
|
|
31
|
+
assistantTexts.push(block.text.trim());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Gemini format: { type: 'message', role: 'assistant', delta: true, content: '...' }
|
|
36
|
+
if (parsed.type === 'message' &&
|
|
37
|
+
parsed.role === 'assistant' &&
|
|
38
|
+
parsed.delta === true &&
|
|
39
|
+
typeof parsed.content === 'string') {
|
|
40
|
+
geminiDeltaTokens.push(parsed.content);
|
|
41
|
+
}
|
|
42
|
+
// Copilot format: { type: 'assistant.message', data: { content: '...' } }
|
|
43
|
+
if (parsed.type === 'assistant.message' &&
|
|
44
|
+
typeof parsed.data?.content === 'string') {
|
|
45
|
+
const content = parsed.data.content;
|
|
46
|
+
if (content.trim())
|
|
47
|
+
copilotTexts.push(content.trim());
|
|
48
|
+
}
|
|
49
|
+
// Codex format: { type: 'item.completed', item: { type: 'message'|'agent_message', text: '...' } }
|
|
50
|
+
// codex-specific: both 'message' and 'agent_message' item types are accepted
|
|
51
|
+
if (parsed.type === 'item.completed' &&
|
|
52
|
+
(parsed.item?.type === 'message' || parsed.item?.type === 'agent_message') &&
|
|
53
|
+
typeof parsed.item?.text === 'string') {
|
|
54
|
+
const text = parsed.item.text;
|
|
55
|
+
if (text.trim())
|
|
56
|
+
codexTexts.push(text.trim());
|
|
57
|
+
}
|
|
58
|
+
// OpenCode format: { type: 'text', part: { text: '...' } }
|
|
59
|
+
if (parsed.type === 'text' && typeof parsed.part?.text === 'string') {
|
|
60
|
+
const text = parsed.part.text;
|
|
61
|
+
if (text.trim())
|
|
62
|
+
opencodeTexts.push(text.trim());
|
|
63
|
+
}
|
|
64
|
+
if (parsed.type === 'result' && typeof parsed.result === 'string') {
|
|
65
|
+
resultText = parsed.result;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Not valid JSON line — skip
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (assistantTexts.length > 0)
|
|
73
|
+
return assistantTexts.join('\n\n');
|
|
74
|
+
if (geminiDeltaTokens.length > 0)
|
|
75
|
+
return geminiDeltaTokens.join('');
|
|
76
|
+
if (copilotTexts.length > 0)
|
|
77
|
+
return copilotTexts.join('\n\n');
|
|
78
|
+
if (codexTexts.length > 0)
|
|
79
|
+
return codexTexts.join('\n\n');
|
|
80
|
+
if (opencodeTexts.length > 0)
|
|
81
|
+
return opencodeTexts.join('');
|
|
82
|
+
if (resultText)
|
|
83
|
+
return resultText;
|
|
84
|
+
return raw.trim();
|
|
85
|
+
}
|
|
86
|
+
function parseResultEventUsage(raw) {
|
|
87
|
+
const parsed = (0, parse_usage_js_1.parseUsage)(raw);
|
|
88
|
+
if (!parsed)
|
|
89
|
+
return null;
|
|
90
|
+
return {
|
|
91
|
+
inputTokens: parsed.inputTokens,
|
|
92
|
+
outputTokens: parsed.outputTokens,
|
|
93
|
+
cachedInputTokens: parsed.cachedInputTokens,
|
|
94
|
+
costUsd: 0,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
class ProviderError extends Error {
|
|
98
|
+
providerStr;
|
|
99
|
+
constructor(message, providerStr) {
|
|
100
|
+
super(message);
|
|
101
|
+
this.providerStr = providerStr;
|
|
102
|
+
this.name = 'ProviderError';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.ProviderError = ProviderError;
|
|
106
|
+
/**
|
|
107
|
+
* Thrown by VercelProviderRuntime when generateText() encounters a tool without
|
|
108
|
+
* an execute function (client tool). The caller should return requires_action
|
|
109
|
+
* to the client, collect the tool result, and call continueWithToolResults().
|
|
110
|
+
*/
|
|
111
|
+
class ClientToolCallRequiredError extends Error {
|
|
112
|
+
toolCall;
|
|
113
|
+
continuationState;
|
|
114
|
+
name = 'ClientToolCallRequiredError';
|
|
115
|
+
constructor(toolCall, continuationState) {
|
|
116
|
+
super(`Client tool call required: ${toolCall.toolName}`);
|
|
117
|
+
this.toolCall = toolCall;
|
|
118
|
+
this.continuationState = continuationState;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.ClientToolCallRequiredError = ClientToolCallRequiredError;
|
|
122
|
+
// ── Provider factory registry ───────────────────────────────────────────────
|
|
123
|
+
const _providerFactories = new Map();
|
|
124
|
+
/**
|
|
125
|
+
* Register a provider factory for a given namespace.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* // Register an API-based provider namespace
|
|
129
|
+
* registerProviderFactory('api', (id, providerStr) => new MyApiProvider(id));
|
|
130
|
+
*
|
|
131
|
+
* // Now createProvider('api/claude') works
|
|
132
|
+
* const provider = createProvider('api/claude');
|
|
133
|
+
*/
|
|
134
|
+
function registerProviderFactory(namespace, factory) {
|
|
135
|
+
_providerFactories.set(namespace, factory);
|
|
136
|
+
}
|
|
137
|
+
// CLI command mapping for each supported provider id
|
|
138
|
+
const CLI_COMMANDS = {
|
|
139
|
+
claude: 'claude',
|
|
140
|
+
gemini: 'gemini',
|
|
141
|
+
copilot: 'copilot', // GitHub Copilot CLI (standalone binary)
|
|
142
|
+
codex: 'codex',
|
|
143
|
+
opencode: 'opencode', // OpenCode CLI (--format json stream)
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Create a provider runtime for the given provider string.
|
|
147
|
+
*
|
|
148
|
+
* Looks up the namespace in the provider registry first.
|
|
149
|
+
* Falls back to built-in cli/* providers for backward compatibility.
|
|
150
|
+
*
|
|
151
|
+
* @param providerStr - Provider string in namespace/id format (e.g., 'cli/claude', 'api/claude')
|
|
152
|
+
* @throws ProviderError for unknown or unsupported providers
|
|
153
|
+
*/
|
|
154
|
+
function createProvider(providerStr) {
|
|
155
|
+
const parts = providerStr.split('/');
|
|
156
|
+
if (parts.length !== 2) {
|
|
157
|
+
throw new ProviderError(`Invalid provider format: "${providerStr}". Expected namespace/id (e.g., cli/claude)`, providerStr);
|
|
158
|
+
}
|
|
159
|
+
const [namespace, id] = parts;
|
|
160
|
+
// Check registry first (covers both user-registered and built-in cli namespace)
|
|
161
|
+
const factory = _providerFactories.get(namespace);
|
|
162
|
+
if (factory) {
|
|
163
|
+
return factory(id, providerStr);
|
|
164
|
+
}
|
|
165
|
+
// Built-in cli/* fallback (for backward compatibility when cli factory is not explicitly registered)
|
|
166
|
+
if (namespace === 'cli') {
|
|
167
|
+
const cliCommand = CLI_COMMANDS[id];
|
|
168
|
+
if (!cliCommand) {
|
|
169
|
+
throw new ProviderError(`Unknown CLI provider id: "${id}". Supported: ${Object.keys(CLI_COMMANDS).join(', ')}`, providerStr);
|
|
170
|
+
}
|
|
171
|
+
return new CliProviderRuntime(id, cliCommand, providerStr);
|
|
172
|
+
}
|
|
173
|
+
throw new ProviderError(`Unsupported provider namespace: "${namespace}". Register a factory with registerProviderFactory('${namespace}', factory).`, providerStr);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Provider runtime that spawns a CLI process and collects its output.
|
|
177
|
+
*/
|
|
178
|
+
class CliProviderRuntime {
|
|
179
|
+
providerId;
|
|
180
|
+
cliCommand;
|
|
181
|
+
providerStr;
|
|
182
|
+
constructor(providerId, cliCommand, providerStr) {
|
|
183
|
+
this.providerId = providerId;
|
|
184
|
+
this.cliCommand = cliCommand;
|
|
185
|
+
this.providerStr = providerStr;
|
|
186
|
+
}
|
|
187
|
+
async execute(message, options) {
|
|
188
|
+
const { args, stdinMessage } = this.buildArgs(message, options, true);
|
|
189
|
+
options?.onCommand?.(`${this.cliCommand} ${args.join(' ')}`);
|
|
190
|
+
return this.runProcess(args, options, stdinMessage);
|
|
191
|
+
}
|
|
192
|
+
async query(message, options) {
|
|
193
|
+
const { args, stdinMessage } = this.buildArgs(message, options);
|
|
194
|
+
options?.onCommand?.(`${this.cliCommand} ${args.join(' ')}`);
|
|
195
|
+
return this.runProcess(args, options, stdinMessage);
|
|
196
|
+
}
|
|
197
|
+
runProcess(args, options, stdinMessage) {
|
|
198
|
+
return new Promise((resolve, reject) => {
|
|
199
|
+
const proc = (0, child_process_1.spawn)(this.cliCommand, args, {
|
|
200
|
+
env: { ...process.env, ...(options?.env ?? {}) },
|
|
201
|
+
cwd: options?.cwd,
|
|
202
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
203
|
+
});
|
|
204
|
+
// Write message to stdin for providers that read prompt from stdin (e.g. codex)
|
|
205
|
+
// Always close stdin afterwards — some CLIs (e.g. opencode) hang waiting for
|
|
206
|
+
// input otherwise, even when the prompt was passed via argv.
|
|
207
|
+
if (stdinMessage !== undefined) {
|
|
208
|
+
proc.stdin.write(stdinMessage);
|
|
209
|
+
}
|
|
210
|
+
proc.stdin.end();
|
|
211
|
+
// Report child PID immediately after spawn
|
|
212
|
+
if (proc.pid !== undefined) {
|
|
213
|
+
options?.onPid?.(proc.pid);
|
|
214
|
+
}
|
|
215
|
+
let stdout = '';
|
|
216
|
+
let stderr = '';
|
|
217
|
+
let stdoutBuf = '';
|
|
218
|
+
let stderrBuf = '';
|
|
219
|
+
proc.stdout.on('data', (chunk) => {
|
|
220
|
+
const str = chunk.toString();
|
|
221
|
+
stdout += str;
|
|
222
|
+
stdoutBuf += str;
|
|
223
|
+
const lines = stdoutBuf.split('\n');
|
|
224
|
+
stdoutBuf = lines.pop() ?? '';
|
|
225
|
+
for (const line of lines) {
|
|
226
|
+
if (line.trim())
|
|
227
|
+
options?.onOutput?.(line, 'stdout');
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
proc.stderr.on('data', (chunk) => {
|
|
231
|
+
const str = chunk.toString();
|
|
232
|
+
stderr += str;
|
|
233
|
+
stderrBuf += str;
|
|
234
|
+
const lines = stderrBuf.split('\n');
|
|
235
|
+
stderrBuf = lines.pop() ?? '';
|
|
236
|
+
for (const line of lines) {
|
|
237
|
+
if (line.trim())
|
|
238
|
+
options?.onOutput?.(line, 'stderr');
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
proc.on('error', (err) => {
|
|
242
|
+
if (err.code === 'ENOENT') {
|
|
243
|
+
reject(new ProviderError(`CLI command "${this.cliCommand}" not found. Is ${this.providerStr} installed?`, this.providerStr));
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
reject(new ProviderError(`Spawn error: ${err.message}`, this.providerStr));
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
proc.on('close', (code) => {
|
|
250
|
+
// Flush any residual buffered content (no trailing newline)
|
|
251
|
+
if (stdoutBuf.trim())
|
|
252
|
+
options?.onOutput?.(stdoutBuf, 'stdout');
|
|
253
|
+
if (stderrBuf.trim())
|
|
254
|
+
options?.onOutput?.(stderrBuf, 'stderr');
|
|
255
|
+
const exitCode = code ?? 0;
|
|
256
|
+
options?.onExitCode?.(exitCode);
|
|
257
|
+
if (code !== 0) {
|
|
258
|
+
reject(new ProviderError(`Process exited with code ${code}: ${stderr.slice(0, 500)}`, this.providerStr));
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
// Extract usage and model from stream-json result event before resolving
|
|
262
|
+
const { usage, model } = this.parseResultEvent(stdout);
|
|
263
|
+
if (usage && options?.onUsage) {
|
|
264
|
+
options.onUsage(usage);
|
|
265
|
+
}
|
|
266
|
+
// OpenCode stream doesn't emit model info in events; fall back to configured model
|
|
267
|
+
const effectiveModel = model ?? (this.providerId === 'opencode' ? (options?.model ?? null) : null);
|
|
268
|
+
if (effectiveModel && options?.onModel) {
|
|
269
|
+
options.onModel(effectiveModel);
|
|
270
|
+
}
|
|
271
|
+
const parsed = this.parseOutput(stdout);
|
|
272
|
+
resolve(parsed);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
buildArgs(message, options, isExecute = false) {
|
|
277
|
+
// HOTFIX: compose systemPrompt into the outgoing message for all CLI providers.
|
|
278
|
+
// CLI providers don't have a common --system-prompt flag, and agent-rendered
|
|
279
|
+
// prompts (persona, rules, inline.prompt, builtin_tools, skills) were being
|
|
280
|
+
// dropped entirely before this fix. Provider-native system-prompt flags
|
|
281
|
+
// (e.g. claude --append-system-prompt) should be adopted per-provider later
|
|
282
|
+
// for proper system/user separation + prompt caching.
|
|
283
|
+
const effectiveMessage = options?.systemPrompt
|
|
284
|
+
? `${options.systemPrompt}\n\n---\n\n${message}`
|
|
285
|
+
: message;
|
|
286
|
+
// Copilot uses standalone `copilot` binary with prompt via stdin
|
|
287
|
+
// (matching pre-refactoring CopilotProvider behavior)
|
|
288
|
+
if (this.providerId === 'copilot') {
|
|
289
|
+
const args = options?.additionalArgs ? [...options.additionalArgs] : [];
|
|
290
|
+
if (options?.model)
|
|
291
|
+
args.push('--model', options.model);
|
|
292
|
+
return { args, stdinMessage: effectiveMessage };
|
|
293
|
+
}
|
|
294
|
+
// OpenCode: prompt is a positional arg appended last; --format json is system-forced.
|
|
295
|
+
// Security flags (e.g. --dangerously-skip-permissions) come from options.additionalArgs
|
|
296
|
+
// so operators can control them via crewx.yaml.
|
|
297
|
+
if (this.providerId === 'opencode') {
|
|
298
|
+
const additionalArgs = options?.additionalArgs;
|
|
299
|
+
const args = additionalArgs !== undefined ? [...additionalArgs] : ['run'];
|
|
300
|
+
// System guarantee: --format json must be present for stream-json parsing
|
|
301
|
+
if (!args.includes('--format')) {
|
|
302
|
+
args.push('--format', 'json');
|
|
303
|
+
}
|
|
304
|
+
if (options?.model)
|
|
305
|
+
args.push('--model', options.model);
|
|
306
|
+
args.push(effectiveMessage);
|
|
307
|
+
return { args };
|
|
308
|
+
}
|
|
309
|
+
// If agent config provides explicit CLI options, use them directly
|
|
310
|
+
if (options?.additionalArgs !== undefined) {
|
|
311
|
+
const args = [...options.additionalArgs];
|
|
312
|
+
const pIdx = args.indexOf('-p');
|
|
313
|
+
if (pIdx !== -1) {
|
|
314
|
+
// -p flag present: insert message as its value
|
|
315
|
+
args.splice(pIdx + 1, 0, effectiveMessage);
|
|
316
|
+
if (options.model)
|
|
317
|
+
args.push('--model', options.model);
|
|
318
|
+
return { args };
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
// No -p flag: provider reads prompt from stdin (e.g. codex)
|
|
322
|
+
// codex-specific safety net: ensure a JSON output flag is present.
|
|
323
|
+
// Accept both --json (older) and --experimental-json (newer) as equivalent.
|
|
324
|
+
if (this.providerId === 'codex' && !args.includes('--json') && !args.includes('--experimental-json')) {
|
|
325
|
+
args.push('--json');
|
|
326
|
+
}
|
|
327
|
+
if (options.model)
|
|
328
|
+
args.push('--model', options.model);
|
|
329
|
+
return { args, stdinMessage: effectiveMessage };
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
// Default fallback: claude/gemini stream-json format
|
|
333
|
+
const args = ['-p', effectiveMessage, '--output-format', 'stream-json', '--verbose'];
|
|
334
|
+
if (isExecute) {
|
|
335
|
+
args.push('--dangerously-skip-permissions');
|
|
336
|
+
}
|
|
337
|
+
if (options?.model) {
|
|
338
|
+
args.push('--model', options.model);
|
|
339
|
+
}
|
|
340
|
+
return { args };
|
|
341
|
+
}
|
|
342
|
+
parseOutput(raw) {
|
|
343
|
+
return parseStreamJsonOutput(raw);
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Extract token usage, cost, and model from the stream-json result event.
|
|
347
|
+
* Claude CLI emits: { type: "result", usage: {...}, total_cost_usd: ..., modelUsage: {...} }
|
|
348
|
+
* OpenCode CLI emits: { type: "step_finish", part: { tokens: { input, output, cache: { read, write } }, cost: 0 } }
|
|
349
|
+
*/
|
|
350
|
+
parseResultEvent(raw) {
|
|
351
|
+
const baseUsage = parseResultEventUsage(raw);
|
|
352
|
+
const lines = raw.split('\n');
|
|
353
|
+
for (const line of lines) {
|
|
354
|
+
if (!line.trim())
|
|
355
|
+
continue;
|
|
356
|
+
try {
|
|
357
|
+
const parsed = JSON.parse(line);
|
|
358
|
+
if (parsed.type === 'result') {
|
|
359
|
+
const usageRaw = parsed.usage;
|
|
360
|
+
const usage = usageRaw
|
|
361
|
+
? {
|
|
362
|
+
inputTokens: Number(usageRaw['input_tokens'] ?? 0),
|
|
363
|
+
outputTokens: Number(usageRaw['output_tokens'] ?? 0),
|
|
364
|
+
cachedInputTokens: Number(usageRaw['cache_read_input_tokens'] ?? 0),
|
|
365
|
+
costUsd: Number(parsed['total_cost_usd'] ?? 0),
|
|
366
|
+
}
|
|
367
|
+
: baseUsage;
|
|
368
|
+
const modelUsage = parsed.modelUsage;
|
|
369
|
+
const model = modelUsage ? Object.keys(modelUsage)[0] ?? null : null;
|
|
370
|
+
return { usage, model };
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
// Not JSON — skip
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return { usage: baseUsage, model: null };
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
//# sourceMappingURL=bridge.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MastraProviderRuntime — API 프로바이더를 위한 ProviderRuntime 구현.
|
|
3
|
+
*
|
|
4
|
+
* Mastra Agent를 래핑하여 tool calling loop를 자동 처리한다.
|
|
5
|
+
* Vercel AI SDK 기반 모델 인스턴스를 생성하여 OpenRouter, OpenAI, Anthropic, Google 지원.
|
|
6
|
+
*/
|
|
7
|
+
import type { ProviderRuntime, ProviderQueryOptions } from './bridge';
|
|
8
|
+
export interface MastraProviderConfig {
|
|
9
|
+
/** Provider string (e.g. 'api/openrouter', 'api/anthropic'). */
|
|
10
|
+
provider: string;
|
|
11
|
+
/** Model identifier (e.g. 'anthropic/claude-sonnet-4-20250514'). */
|
|
12
|
+
model: string;
|
|
13
|
+
/** API key — falls back to environment variable if not set. */
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
/** Custom base URL (e.g. OpenRouter endpoint). */
|
|
16
|
+
baseURL?: string;
|
|
17
|
+
/** Sampling temperature. */
|
|
18
|
+
temperature?: number;
|
|
19
|
+
/** Max output tokens. */
|
|
20
|
+
maxTokens?: number;
|
|
21
|
+
/** Default max steps for tool loop. */
|
|
22
|
+
maxSteps?: number;
|
|
23
|
+
}
|
|
24
|
+
export declare class MastraProviderRuntime implements ProviderRuntime {
|
|
25
|
+
private config;
|
|
26
|
+
constructor(config: MastraProviderConfig);
|
|
27
|
+
query(message: string, options?: ProviderQueryOptions): Promise<string>;
|
|
28
|
+
execute(message: string, options?: ProviderQueryOptions): Promise<string>;
|
|
29
|
+
private _run;
|
|
30
|
+
/**
|
|
31
|
+
* CrewX ToolDefinition[] → Mastra tool Record 변환.
|
|
32
|
+
* JSON Schema → Zod 간이 변환 포함.
|
|
33
|
+
*/
|
|
34
|
+
private convertTools;
|
|
35
|
+
/**
|
|
36
|
+
* JSON Schema → Zod 간이 변환.
|
|
37
|
+
*/
|
|
38
|
+
private jsonSchemaToZod;
|
|
39
|
+
/**
|
|
40
|
+
* Vercel AI SDK model 인스턴스 생성.
|
|
41
|
+
* provider string에 따라 적절한 SDK 팩토리 사용.
|
|
42
|
+
*/
|
|
43
|
+
private createModel;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=mastra-runtime.d.ts.map
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MastraProviderRuntime — API 프로바이더를 위한 ProviderRuntime 구현.
|
|
4
|
+
*
|
|
5
|
+
* Mastra Agent를 래핑하여 tool calling loop를 자동 처리한다.
|
|
6
|
+
* Vercel AI SDK 기반 모델 인스턴스를 생성하여 OpenRouter, OpenAI, Anthropic, Google 지원.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.MastraProviderRuntime = void 0;
|
|
43
|
+
const bridge_1 = require("./bridge");
|
|
44
|
+
const DEFAULT_MAX_STEPS = 10;
|
|
45
|
+
const MAX_STEPS_LIMIT = 50;
|
|
46
|
+
class MastraProviderRuntime {
|
|
47
|
+
config;
|
|
48
|
+
constructor(config) {
|
|
49
|
+
this.config = config;
|
|
50
|
+
}
|
|
51
|
+
async query(message, options) {
|
|
52
|
+
return this._run(message, 'query', options);
|
|
53
|
+
}
|
|
54
|
+
async execute(message, options) {
|
|
55
|
+
return this._run(message, 'execute', options);
|
|
56
|
+
}
|
|
57
|
+
async _run(message, _mode, options) {
|
|
58
|
+
// 1. Mastra tools 변환
|
|
59
|
+
const mastraTools = this.convertTools(options?.tools ?? []);
|
|
60
|
+
// 2. Model 인스턴스 생성 (Vercel AI SDK)
|
|
61
|
+
const model = this.createModel(options?.model);
|
|
62
|
+
// 3. Mastra Agent 생성 (매 호출 fresh — stateless)
|
|
63
|
+
const { Agent } = await Promise.resolve().then(() => __importStar(require('@mastra/core/agent')));
|
|
64
|
+
const agent = new Agent({
|
|
65
|
+
name: this.config.provider,
|
|
66
|
+
model,
|
|
67
|
+
instructions: options?.systemPrompt ?? '',
|
|
68
|
+
tools: mastraTools,
|
|
69
|
+
});
|
|
70
|
+
// 4. generate() — tool loop 자동 실행
|
|
71
|
+
const maxSteps = Math.min(options?.maxSteps ?? this.config.maxSteps ?? DEFAULT_MAX_STEPS, MAX_STEPS_LIMIT);
|
|
72
|
+
try {
|
|
73
|
+
const result = await agent.generate(message, { maxSteps });
|
|
74
|
+
// 5. Usage 콜백
|
|
75
|
+
if (options?.onUsage && result.usage) {
|
|
76
|
+
const usage = {
|
|
77
|
+
inputTokens: result.usage.promptTokens ?? 0,
|
|
78
|
+
outputTokens: result.usage.completionTokens ?? 0,
|
|
79
|
+
cachedInputTokens: 0,
|
|
80
|
+
costUsd: 0,
|
|
81
|
+
};
|
|
82
|
+
options.onUsage(usage);
|
|
83
|
+
}
|
|
84
|
+
// 6. Model 콜백
|
|
85
|
+
if (options?.onModel) {
|
|
86
|
+
options.onModel(options.model ?? this.config.model);
|
|
87
|
+
}
|
|
88
|
+
// 7. 스트리밍 콜백 (Phase 1: generate 완료 후 전체 텍스트)
|
|
89
|
+
if (options?.onOutput && result.text) {
|
|
90
|
+
options.onOutput(result.text, 'stdout');
|
|
91
|
+
}
|
|
92
|
+
return result.text ?? '';
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (error.status === 401) {
|
|
96
|
+
throw new bridge_1.ProviderError(`Authentication failed for ${this.config.provider}. Check your API key.`, this.config.provider);
|
|
97
|
+
}
|
|
98
|
+
if (error.status === 429) {
|
|
99
|
+
throw new bridge_1.ProviderError(`Rate limit exceeded for ${this.config.provider}.`, this.config.provider);
|
|
100
|
+
}
|
|
101
|
+
throw new bridge_1.ProviderError(`Provider error: ${error.message}`, this.config.provider);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* CrewX ToolDefinition[] → Mastra tool Record 변환.
|
|
106
|
+
* JSON Schema → Zod 간이 변환 포함.
|
|
107
|
+
*/
|
|
108
|
+
convertTools(tools) {
|
|
109
|
+
let createTool;
|
|
110
|
+
try {
|
|
111
|
+
createTool = require('@mastra/core/tools').createTool;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return {};
|
|
115
|
+
}
|
|
116
|
+
const { z } = require('zod');
|
|
117
|
+
const mastraTools = {};
|
|
118
|
+
for (const tool of tools) {
|
|
119
|
+
mastraTools[tool.name] = createTool({
|
|
120
|
+
id: tool.name,
|
|
121
|
+
description: tool.description,
|
|
122
|
+
inputSchema: this.jsonSchemaToZod(tool.parameters ?? {}, z),
|
|
123
|
+
execute: async ({ context }) => {
|
|
124
|
+
return tool.execute(context);
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return mastraTools;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* JSON Schema → Zod 간이 변환.
|
|
132
|
+
*/
|
|
133
|
+
jsonSchemaToZod(schema, z) {
|
|
134
|
+
if (!schema || !schema.properties)
|
|
135
|
+
return z.object({});
|
|
136
|
+
const shape = {};
|
|
137
|
+
const props = schema.properties;
|
|
138
|
+
const required = schema.required ?? [];
|
|
139
|
+
for (const [key, prop] of Object.entries(props)) {
|
|
140
|
+
let field;
|
|
141
|
+
switch (prop.type) {
|
|
142
|
+
case 'string':
|
|
143
|
+
field = z.string();
|
|
144
|
+
break;
|
|
145
|
+
case 'number':
|
|
146
|
+
field = z.number();
|
|
147
|
+
break;
|
|
148
|
+
case 'integer':
|
|
149
|
+
field = z.number().int();
|
|
150
|
+
break;
|
|
151
|
+
case 'boolean':
|
|
152
|
+
field = z.boolean();
|
|
153
|
+
break;
|
|
154
|
+
case 'array':
|
|
155
|
+
field = z.array(z.any());
|
|
156
|
+
break;
|
|
157
|
+
default: field = z.any();
|
|
158
|
+
}
|
|
159
|
+
if (prop.description)
|
|
160
|
+
field = field.describe(prop.description);
|
|
161
|
+
if (!required.includes(key))
|
|
162
|
+
field = field.optional();
|
|
163
|
+
shape[key] = field;
|
|
164
|
+
}
|
|
165
|
+
return z.object(shape);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Vercel AI SDK model 인스턴스 생성.
|
|
169
|
+
* provider string에 따라 적절한 SDK 팩토리 사용.
|
|
170
|
+
*/
|
|
171
|
+
createModel(modelOverride) {
|
|
172
|
+
const { provider, apiKey, baseURL } = this.config;
|
|
173
|
+
const model = modelOverride || this.config.model;
|
|
174
|
+
switch (provider) {
|
|
175
|
+
case 'api/openrouter': {
|
|
176
|
+
const { createOpenAI } = require('@ai-sdk/openai');
|
|
177
|
+
return createOpenAI({
|
|
178
|
+
apiKey: apiKey || process.env.OPENROUTER_API_KEY,
|
|
179
|
+
baseURL: baseURL || 'https://openrouter.ai/api/v1',
|
|
180
|
+
})(model);
|
|
181
|
+
}
|
|
182
|
+
case 'api/openai': {
|
|
183
|
+
const { createOpenAI } = require('@ai-sdk/openai');
|
|
184
|
+
return createOpenAI({
|
|
185
|
+
apiKey: apiKey || process.env.OPENAI_API_KEY,
|
|
186
|
+
...(baseURL && { baseURL }),
|
|
187
|
+
})(model);
|
|
188
|
+
}
|
|
189
|
+
case 'api/anthropic': {
|
|
190
|
+
const { createAnthropic } = require('@ai-sdk/anthropic');
|
|
191
|
+
return createAnthropic({
|
|
192
|
+
apiKey: apiKey || process.env.ANTHROPIC_API_KEY,
|
|
193
|
+
...(baseURL && { baseURL }),
|
|
194
|
+
})(model);
|
|
195
|
+
}
|
|
196
|
+
case 'api/google': {
|
|
197
|
+
const { createGoogleGenerativeAI } = require('@ai-sdk/google');
|
|
198
|
+
return createGoogleGenerativeAI({
|
|
199
|
+
apiKey: apiKey || process.env.GOOGLE_API_KEY,
|
|
200
|
+
})(model);
|
|
201
|
+
}
|
|
202
|
+
default:
|
|
203
|
+
throw new bridge_1.ProviderError(`Unsupported API provider: ${provider}`, provider);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.MastraProviderRuntime = MastraProviderRuntime;
|
|
208
|
+
//# sourceMappingURL=mastra-runtime.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure function to extract token usage from provider CLI stdout.
|
|
3
|
+
* Supports Claude / Codex / Gemini / Copilot / OpenCode JSONL formats.
|
|
4
|
+
* Uses last-match semantics: if multiple usage events are found, the last one wins.
|
|
5
|
+
*/
|
|
6
|
+
export interface ParsedUsage {
|
|
7
|
+
inputTokens: number;
|
|
8
|
+
outputTokens: number;
|
|
9
|
+
/** Cached tokens (read from cache). */
|
|
10
|
+
cachedInputTokens: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Parse token usage from a provider CLI stdout string.
|
|
14
|
+
*
|
|
15
|
+
* Accepts JSONL (one JSON object per line) or a single JSON document.
|
|
16
|
+
* Returns the **last** usage found (last-match semantics).
|
|
17
|
+
* Returns `undefined` if no usage data is present.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseUsage(stdout: string): ParsedUsage | undefined;
|
|
20
|
+
//# sourceMappingURL=parse-usage.d.ts.map
|