@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
package/README.md
CHANGED
|
@@ -1,1022 +1,584 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @crewx/sdk
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://www.npmjs.com/package/@crewx/sdk)
|
|
3
|
+
CrewX SDK — load `crewx.yaml` and run AI agents from TypeScript/JavaScript.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
> **Status**: `0.9.0-alpha` — Core API, Plugin system, and Event system are stable. Tool system coming soon.
|
|
7
6
|
|
|
8
|
-
##
|
|
7
|
+
## Table of Contents
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
1. [Quick Start](#1-quick-start)
|
|
10
|
+
2. [Core API](#2-core-api)
|
|
11
|
+
3. [crewx.yaml Structure](#3-crewxyaml-structure)
|
|
12
|
+
4. [Layout System](#4-layout-system)
|
|
13
|
+
5. [Template Helpers](#5-template-helpers)
|
|
14
|
+
6. [Provider Bridge](#6-provider-bridge)
|
|
15
|
+
7. [Plugin System](#7-plugin-system)
|
|
16
|
+
8. [Event System](#8-event-system)
|
|
17
|
+
9. [Type Reference](#9-type-reference)
|
|
11
18
|
|
|
12
|
-
|
|
13
|
-
- Implement conversation history management
|
|
14
|
-
- Create knowledge base utilities
|
|
15
|
-
- Develop agent orchestration systems
|
|
16
|
-
- Integrate with existing applications
|
|
17
|
-
|
|
18
|
-
## Installation
|
|
19
|
+
---
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
npm install @crewx/sdk
|
|
22
|
-
```
|
|
21
|
+
## 1. Quick Start
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
### Install
|
|
25
24
|
|
|
26
25
|
```bash
|
|
27
|
-
npm install @
|
|
26
|
+
npm install @crewx/sdk
|
|
28
27
|
```
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
### Basic Usage with createCrewxAgent (NEW)
|
|
33
|
-
|
|
34
|
-
The SDK provides a high-level `createCrewxAgent` factory function for simplified agent creation:
|
|
29
|
+
### Hello World
|
|
35
30
|
|
|
36
31
|
```typescript
|
|
37
|
-
import {
|
|
38
|
-
|
|
39
|
-
// Create an agent with configuration
|
|
40
|
-
const { agent, onEvent } = await createCrewxAgent({
|
|
41
|
-
provider: {
|
|
42
|
-
namespace: 'cli',
|
|
43
|
-
id: 'codex',
|
|
44
|
-
apiKey: process.env.CODEX_TOKEN,
|
|
45
|
-
},
|
|
46
|
-
enableCallStack: true,
|
|
47
|
-
defaultAgentId: 'my-agent',
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// Subscribe to agent events
|
|
51
|
-
onEvent('callStackUpdated', (stack) => {
|
|
52
|
-
console.log('Call stack:', stack.map(f => `${f.depth}: ${f.agentId}`));
|
|
53
|
-
});
|
|
32
|
+
import { Crewx } from '@crewx/sdk';
|
|
54
33
|
|
|
55
|
-
|
|
56
|
-
console.log(`Agent ${agentId} started in ${mode} mode`);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// Execute a query (read-only)
|
|
60
|
-
const queryResult = await agent.query({
|
|
61
|
-
prompt: 'What is the current status?',
|
|
62
|
-
context: 'Project: CrewX',
|
|
63
|
-
messages: [
|
|
64
|
-
{
|
|
65
|
-
id: 'msg-1',
|
|
66
|
-
text: 'Previous message',
|
|
67
|
-
timestamp: new Date().toISOString(),
|
|
68
|
-
isAssistant: false,
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
console.log(queryResult.content);
|
|
34
|
+
const crewx = await Crewx.loadYaml('./crewx.yaml');
|
|
74
35
|
|
|
75
|
-
|
|
76
|
-
const executeResult = await agent.execute({
|
|
77
|
-
prompt: 'Create a summary document',
|
|
78
|
-
context: 'Project root: /path/to/project',
|
|
79
|
-
});
|
|
36
|
+
const result = await crewx.query('assistant', 'Hello! What can you do?');
|
|
80
37
|
|
|
81
|
-
|
|
38
|
+
if (result.ok) {
|
|
39
|
+
console.log(result.data); // agent's response text
|
|
40
|
+
} else {
|
|
41
|
+
console.error(result.error?.message);
|
|
42
|
+
}
|
|
82
43
|
```
|
|
83
44
|
|
|
84
|
-
###
|
|
45
|
+
### Minimal `crewx.yaml`
|
|
85
46
|
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const parsed = parser.parse('@claude analyze this code');
|
|
97
|
-
|
|
98
|
-
console.log(parsed.mentions); // ['claude']
|
|
99
|
-
console.log(parsed.cleanedPrompt); // 'analyze this code'
|
|
47
|
+
```yaml
|
|
48
|
+
agents:
|
|
49
|
+
assistant:
|
|
50
|
+
name: Assistant
|
|
51
|
+
provider: cli/claude
|
|
52
|
+
inline:
|
|
53
|
+
model: claude-sonnet-4-6
|
|
54
|
+
prompt: |
|
|
55
|
+
You are a helpful assistant.
|
|
56
|
+
Answer concisely.
|
|
100
57
|
```
|
|
101
58
|
|
|
102
|
-
###
|
|
59
|
+
### Task Execution (with side effects)
|
|
103
60
|
|
|
104
61
|
```typescript
|
|
105
|
-
|
|
106
|
-
type ConversationMessage,
|
|
107
|
-
type ConversationThread,
|
|
108
|
-
type IConversationHistoryProvider,
|
|
109
|
-
getConversationConfig
|
|
110
|
-
} from '@crewx/sdk';
|
|
111
|
-
|
|
112
|
-
// Implement custom conversation storage
|
|
113
|
-
class MyConversationProvider implements IConversationHistoryProvider {
|
|
114
|
-
async fetchHistory(options) {
|
|
115
|
-
// Fetch from your database
|
|
116
|
-
return {
|
|
117
|
-
messages: [],
|
|
118
|
-
metadata: { platform: 'my-platform' }
|
|
119
|
-
};
|
|
120
|
-
}
|
|
62
|
+
const crewx = await Crewx.loadYaml('./crewx.yaml');
|
|
121
63
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
64
|
+
// execute() allows the agent to write files, run commands, etc.
|
|
65
|
+
const result = await crewx.execute('assistant', 'Refactor src/utils.ts');
|
|
125
66
|
|
|
126
|
-
|
|
127
|
-
|
|
67
|
+
console.log(`Done in ${result.meta.durationMs}ms`);
|
|
68
|
+
console.log(result.data);
|
|
128
69
|
```
|
|
129
70
|
|
|
130
|
-
###
|
|
71
|
+
### Plugin Setup (optional)
|
|
131
72
|
|
|
132
73
|
```typescript
|
|
133
|
-
import {
|
|
134
|
-
|
|
135
|
-
const docManager = new DocumentManager();
|
|
74
|
+
import { FileLoggerPlugin } from '@crewx/cli/plugins/file-logger';
|
|
75
|
+
import { SqliteTracingPlugin } from '@crewx/cli/plugins/sqlite-tracing';
|
|
136
76
|
|
|
137
|
-
//
|
|
138
|
-
await
|
|
139
|
-
|
|
140
|
-
//
|
|
141
|
-
const content = docManager.getDocument('./docs/api.md');
|
|
142
|
-
console.log(content);
|
|
77
|
+
await crewx.use(new FileLoggerPlugin()); // log files → .crewx/logs/
|
|
78
|
+
await crewx.use(new SqliteTracingPlugin()); // task records → ~/.crewx/crewx.db
|
|
79
|
+
// ... run tasks ...
|
|
80
|
+
await crewx.close(); // flush all plugins on exit
|
|
143
81
|
```
|
|
144
82
|
|
|
145
|
-
|
|
83
|
+
---
|
|
146
84
|
|
|
147
|
-
|
|
85
|
+
## 2. Core API
|
|
148
86
|
|
|
149
|
-
|
|
87
|
+
### `Crewx.loadYaml(path, options?)`
|
|
150
88
|
|
|
151
|
-
|
|
89
|
+
Load from a `crewx.yaml` file. Documents referenced in the config are loaded automatically.
|
|
152
90
|
|
|
153
91
|
```typescript
|
|
154
|
-
|
|
155
|
-
respond(
|
|
156
|
-
prompt: string,
|
|
157
|
-
options?: AIQueryOptions
|
|
158
|
-
): Promise<AIResponse>;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
interface AIQueryOptions {
|
|
162
|
-
messages?: ConversationMessage[];
|
|
163
|
-
pipedContext?: string;
|
|
164
|
-
model?: string;
|
|
165
|
-
// ... other options
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
interface AIResponse {
|
|
169
|
-
content: string;
|
|
170
|
-
metadata?: Record<string, unknown>;
|
|
171
|
-
}
|
|
172
|
-
```
|
|
92
|
+
const crewx = await Crewx.loadYaml('./crewx.yaml');
|
|
173
93
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
```typescript
|
|
179
|
-
interface IConversationHistoryProvider {
|
|
180
|
-
fetchHistory(options: FetchHistoryOptions): Promise<ConversationThread>;
|
|
181
|
-
saveMessage(message: ConversationMessage, threadId: string): Promise<void>;
|
|
182
|
-
createThread(threadId: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
183
|
-
listThreads(): Promise<Array<{ id: string; updatedAt: Date }>>;
|
|
184
|
-
}
|
|
94
|
+
// With options
|
|
95
|
+
const crewx = await Crewx.loadYaml('./crewx.yaml', {
|
|
96
|
+
execPolicy: { allow: ['git *', 'npm run *'], deny: ['rm *'] },
|
|
97
|
+
});
|
|
185
98
|
```
|
|
186
99
|
|
|
187
|
-
###
|
|
188
|
-
|
|
189
|
-
#### TimeoutConfig
|
|
100
|
+
### `Crewx.fromConfig(config, options?, projectRoot?)`
|
|
190
101
|
|
|
191
|
-
|
|
102
|
+
Create from an already-parsed config object. Useful when you load YAML yourself or build config programmatically.
|
|
192
103
|
|
|
193
104
|
```typescript
|
|
194
|
-
import {
|
|
105
|
+
import { Crewx, CrewxProjectConfig } from '@crewx/sdk';
|
|
195
106
|
|
|
196
|
-
|
|
197
|
-
|
|
107
|
+
const config: CrewxProjectConfig = {
|
|
108
|
+
agents: [
|
|
109
|
+
{ id: 'bot', provider: 'cli/claude', inline: { prompt: 'You are a bot.' } },
|
|
110
|
+
],
|
|
111
|
+
};
|
|
198
112
|
|
|
199
|
-
|
|
200
|
-
const defaults = getDefaultTimeoutConfig();
|
|
201
|
-
console.log(defaults.default); // 120000ms
|
|
202
|
-
console.log(defaults.query); // 60000ms
|
|
203
|
-
console.log(defaults.execute); // 300000ms
|
|
113
|
+
const crewx = await Crewx.fromConfig(config, {}, process.cwd());
|
|
204
114
|
```
|
|
205
115
|
|
|
206
|
-
|
|
116
|
+
### `crewx.query(agentRef, message, options?)`
|
|
207
117
|
|
|
208
|
-
|
|
118
|
+
Ask an agent a question. Read-only — the agent is expected to respond with text only.
|
|
209
119
|
|
|
210
120
|
```typescript
|
|
211
|
-
|
|
121
|
+
const result = await crewx.query('assistant', 'Summarize this PR');
|
|
212
122
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
123
|
+
// With options
|
|
124
|
+
const result = await crewx.query('assistant', 'Translate to Korean', {
|
|
125
|
+
model: 'claude-opus-4-6', // override model
|
|
126
|
+
provider: 'cli/claude', // override provider
|
|
127
|
+
context: 'Additional context', // prepended to the message
|
|
128
|
+
});
|
|
216
129
|
```
|
|
217
130
|
|
|
218
|
-
|
|
131
|
+
> **Note**: `'@assistant'` 형태도 동작합니다 (CLI 호환). SDK에서는 bare id가 권장됩니다.
|
|
219
132
|
|
|
220
|
-
|
|
133
|
+
**Returns**: [`QueryResult`](#queryresult)
|
|
221
134
|
|
|
222
|
-
|
|
135
|
+
### `crewx.execute(agentRef, message, options?)`
|
|
223
136
|
|
|
224
|
-
|
|
225
|
-
import { MentionParser, type ParsedMentions } from '@crewx/sdk';
|
|
226
|
-
|
|
227
|
-
const parser = new MentionParser();
|
|
228
|
-
|
|
229
|
-
// Parse single mention
|
|
230
|
-
const result = parser.parse('@claude help me');
|
|
231
|
-
// result.mentions: ['claude']
|
|
232
|
-
// result.cleanedPrompt: 'help me'
|
|
233
|
-
|
|
234
|
-
// Parse multiple mentions
|
|
235
|
-
const multi = parser.parse('@claude @gemini compare approaches');
|
|
236
|
-
// multi.mentions: ['claude', 'gemini']
|
|
237
|
-
|
|
238
|
-
// Override model
|
|
239
|
-
const withModel = parser.parse('@claude:opus analyze');
|
|
240
|
-
// Model override detected
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
#### Error Utilities
|
|
244
|
-
|
|
245
|
-
Handle errors consistently:
|
|
137
|
+
Run a task with an agent. The agent may write files, run shell commands, etc. Uses `--dangerously-skip-permissions` for `cli/claude`.
|
|
246
138
|
|
|
247
139
|
```typescript
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
} catch (err) {
|
|
253
|
-
if (isError(err)) {
|
|
254
|
-
console.error(getErrorMessage(err));
|
|
255
|
-
console.error(getErrorStack(err));
|
|
256
|
-
}
|
|
140
|
+
const result = await crewx.execute('coder', 'Fix the failing tests in src/');
|
|
141
|
+
|
|
142
|
+
if (!result.ok) {
|
|
143
|
+
console.error('Failed:', result.error?.code, result.error?.message);
|
|
257
144
|
}
|
|
258
145
|
```
|
|
259
146
|
|
|
260
|
-
|
|
147
|
+
**Returns**: [`ExecuteResult`](#executeresult)
|
|
261
148
|
|
|
262
|
-
|
|
149
|
+
### `crewx.renderAgentPromptFull(agentId, options?)`
|
|
263
150
|
|
|
264
|
-
|
|
151
|
+
Render the complete system prompt for an agent — layout + template expansion. Used to inspect what the agent actually receives, or to pass the prompt to another system.
|
|
265
152
|
|
|
266
153
|
```typescript
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
type CrewxAgentConfig,
|
|
270
|
-
type CrewxAgent,
|
|
271
|
-
type AgentQueryRequest,
|
|
272
|
-
type AgentExecuteRequest,
|
|
273
|
-
type CallStackFrame
|
|
274
|
-
} from '@crewx/sdk';
|
|
275
|
-
|
|
276
|
-
// Configuration interface
|
|
277
|
-
interface CrewxAgentConfig {
|
|
278
|
-
provider?: {
|
|
279
|
-
namespace: string;
|
|
280
|
-
id: string;
|
|
281
|
-
apiKey?: string;
|
|
282
|
-
model?: string;
|
|
283
|
-
};
|
|
284
|
-
knowledgeBase?: {
|
|
285
|
-
path?: string;
|
|
286
|
-
sources?: string[];
|
|
287
|
-
};
|
|
288
|
-
enableCallStack?: boolean;
|
|
289
|
-
defaultAgentId?: string;
|
|
290
|
-
}
|
|
154
|
+
const prompt = await crewx.renderAgentPromptFull('assistant');
|
|
155
|
+
console.log(prompt);
|
|
291
156
|
|
|
292
|
-
//
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
157
|
+
// With layout override
|
|
158
|
+
const prompt = await crewx.renderAgentPromptFull('assistant', {
|
|
159
|
+
layout: 'crewx/minimal',
|
|
160
|
+
session: { mode: 'execute', platform: 'api' },
|
|
296
161
|
});
|
|
297
|
-
|
|
298
|
-
// Agent interface
|
|
299
|
-
agent.query(request: AgentQueryRequest): Promise<AgentResult>
|
|
300
|
-
agent.execute(request: AgentExecuteRequest): Promise<AgentResult>
|
|
301
|
-
agent.getCallStack(): CallStackFrame[]
|
|
302
162
|
```
|
|
303
163
|
|
|
304
|
-
|
|
164
|
+
### `crewx.registerLayout(name, template)`
|
|
305
165
|
|
|
306
|
-
|
|
166
|
+
Register a custom layout at runtime. See [Layout System](#4-layout-system).
|
|
307
167
|
|
|
308
168
|
```typescript
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
// - 'callStackUpdated': CallStackFrame[]
|
|
316
|
-
// - 'agentStarted': { agentId: string, mode: 'query' | 'execute' }
|
|
317
|
-
// - 'agentCompleted': { agentId: string, success: boolean }
|
|
318
|
-
// - 'toolCallStarted': { toolName: string, args: any }
|
|
319
|
-
// - 'toolCallCompleted': { toolName: string, result: any }
|
|
320
|
-
|
|
321
|
-
// Unsubscribe when done
|
|
322
|
-
unsubscribe();
|
|
169
|
+
crewx.registerLayout('my-layout', `
|
|
170
|
+
# {{agent.name}}
|
|
171
|
+
{{agent.inline.prompt}}
|
|
172
|
+
---
|
|
173
|
+
Session: {{session.mode}}
|
|
174
|
+
`);
|
|
323
175
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
eventBus.clear(); // Remove all listeners
|
|
176
|
+
const prompt = await crewx.renderAgentPromptFull('assistant', {
|
|
177
|
+
layout: 'my-layout',
|
|
178
|
+
});
|
|
328
179
|
```
|
|
329
180
|
|
|
330
|
-
###
|
|
181
|
+
### `crewx.agents`
|
|
331
182
|
|
|
332
|
-
|
|
183
|
+
`ReadonlyMap<string, AgentConfig>` — all agents loaded from `crewx.yaml`.
|
|
333
184
|
|
|
334
185
|
```typescript
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
import { ExecutionMode, SecurityLevel } from '@crewx/sdk';
|
|
186
|
+
// List all agents
|
|
187
|
+
for (const [id, agent] of crewx.agents) {
|
|
188
|
+
console.log(id, agent.provider);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Check if an agent exists
|
|
192
|
+
if (crewx.agents.has('coder')) {
|
|
193
|
+
// ...
|
|
194
|
+
}
|
|
346
195
|
```
|
|
347
196
|
|
|
348
|
-
|
|
197
|
+
### `crewx.filterAgents(filters)`
|
|
349
198
|
|
|
350
|
-
|
|
199
|
+
Filter agents by role, team, or provider. Supports glob patterns.
|
|
351
200
|
|
|
352
201
|
```typescript
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
export class MyCustomProvider implements AIProvider {
|
|
356
|
-
async respond(
|
|
357
|
-
prompt: string,
|
|
358
|
-
options?: AIQueryOptions
|
|
359
|
-
): Promise<AIResponse> {
|
|
360
|
-
// Implement your AI provider logic
|
|
361
|
-
const result = await this.callMyAI(prompt, options);
|
|
362
|
-
|
|
363
|
-
return {
|
|
364
|
-
content: result.text,
|
|
365
|
-
metadata: {
|
|
366
|
-
model: result.model,
|
|
367
|
-
tokens: result.usage
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
}
|
|
202
|
+
// All agents on the 'backend' team
|
|
203
|
+
const agents = crewx.filterAgents({ team: 'backend' });
|
|
371
204
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
usage: { total: 100 }
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
}
|
|
205
|
+
// All Claude-based agents
|
|
206
|
+
const agents = crewx.filterAgents({ provider: 'cli/claude' });
|
|
207
|
+
|
|
208
|
+
// Wildcard: all cli/* providers
|
|
209
|
+
const agents = crewx.filterAgents({ provider: 'cli/*' });
|
|
381
210
|
```
|
|
382
211
|
|
|
383
|
-
|
|
212
|
+
---
|
|
384
213
|
|
|
385
|
-
|
|
386
|
-
import {
|
|
387
|
-
IConversationHistoryProvider,
|
|
388
|
-
ConversationMessage,
|
|
389
|
-
ConversationThread,
|
|
390
|
-
FetchHistoryOptions
|
|
391
|
-
} from '@crewx/sdk';
|
|
392
|
-
|
|
393
|
-
export class DatabaseConversationProvider implements IConversationHistoryProvider {
|
|
394
|
-
constructor(private db: MyDatabase) {}
|
|
395
|
-
|
|
396
|
-
async fetchHistory(options: FetchHistoryOptions): Promise<ConversationThread> {
|
|
397
|
-
const messages = await this.db.query(
|
|
398
|
-
'SELECT * FROM messages WHERE thread_id = ?',
|
|
399
|
-
[options.threadId]
|
|
400
|
-
);
|
|
401
|
-
|
|
402
|
-
return {
|
|
403
|
-
messages: messages.map(this.toMessage),
|
|
404
|
-
metadata: { platform: 'database' }
|
|
405
|
-
};
|
|
406
|
-
}
|
|
214
|
+
## 3. `crewx.yaml` Structure
|
|
407
215
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
216
|
+
```yaml
|
|
217
|
+
# ─── Agents ──────────────────────────────────────────────────
|
|
218
|
+
agents:
|
|
219
|
+
my_agent:
|
|
220
|
+
name: My Agent # Display name (optional)
|
|
221
|
+
role: Backend Developer # Role label (optional)
|
|
222
|
+
team: core # Team label (optional)
|
|
223
|
+
provider: cli/claude # Provider (required)
|
|
224
|
+
working_directory: . # Working dir for the agent
|
|
414
225
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
226
|
+
inline: # Inline agent definition
|
|
227
|
+
model: claude-sonnet-4-6 # Model override (optional)
|
|
228
|
+
prompt: | # System prompt (Handlebars template)
|
|
229
|
+
You are an expert {{agent.role}}.
|
|
230
|
+
Today's context: {{{documents.guidelines.content}}}
|
|
231
|
+
layout: crewx/minimal # Layout override for this agent (optional)
|
|
418
232
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
233
|
+
# ─── Layouts ─────────────────────────────────────────────────
|
|
234
|
+
layouts:
|
|
235
|
+
default: crewx/minimal # Project-level default layout
|
|
422
236
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
isAssistant: row.is_assistant,
|
|
430
|
-
metadata: row.metadata
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
}
|
|
237
|
+
# ─── Documents ───────────────────────────────────────────────
|
|
238
|
+
documents:
|
|
239
|
+
guidelines:
|
|
240
|
+
path: ./docs/guidelines.md # Loaded at startup, available as documents.guidelines
|
|
241
|
+
api_spec:
|
|
242
|
+
path: ./docs/api.md
|
|
434
243
|
```
|
|
435
244
|
|
|
436
|
-
|
|
245
|
+
### Multiple providers
|
|
437
246
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
247
|
+
```yaml
|
|
248
|
+
agents:
|
|
249
|
+
polyglot:
|
|
250
|
+
provider: # Array = first is primary, rest are fallbacks (future)
|
|
251
|
+
- cli/claude
|
|
252
|
+
- cli/gemini
|
|
253
|
+
```
|
|
441
254
|
|
|
442
|
-
|
|
255
|
+
---
|
|
443
256
|
|
|
444
|
-
|
|
257
|
+
## 4. Layout System
|
|
445
258
|
|
|
446
|
-
|
|
259
|
+
Layouts wrap the agent's raw prompt with structure — identity blocks, session info, available tools, etc.
|
|
447
260
|
|
|
448
|
-
|
|
449
|
-
import { BaseMessageFormatter, type StructuredMessage } from '@crewx/sdk';
|
|
261
|
+
### Built-in Layouts
|
|
450
262
|
|
|
451
|
-
|
|
263
|
+
| ID | Description |
|
|
264
|
+
|----|-------------|
|
|
265
|
+
| `crewx/default` | Full structured layout (identity + session + prompt) |
|
|
266
|
+
| `crewx/minimal` | Minimal wrapper — just the agent prompt |
|
|
452
267
|
|
|
453
|
-
|
|
454
|
-
const history = formatter.formatHistory(messages, {
|
|
455
|
-
includeUserId: true,
|
|
456
|
-
includeTimestamp: true,
|
|
457
|
-
timestampFormat: 'iso', // 'iso' | 'relative' | 'unix'
|
|
458
|
-
});
|
|
268
|
+
### Resolution Priority
|
|
459
269
|
|
|
460
|
-
|
|
461
|
-
// Output:
|
|
462
|
-
// [2025-10-17T10:00:00Z] user123: Hello!
|
|
463
|
-
// [2025-10-17T10:00:05Z] assistant: How can I help?
|
|
464
|
-
```
|
|
270
|
+
When calling `renderAgentPromptFull()`, the layout is resolved in this order (first match wins):
|
|
465
271
|
|
|
466
|
-
|
|
272
|
+
1. `options.layout` — call-site override
|
|
273
|
+
2. `agent.inline.layout` — per-agent definition in `crewx.yaml`
|
|
274
|
+
3. `config.layouts.default` — project-level default
|
|
275
|
+
4. `crewx/default` — SDK built-in fallback
|
|
467
276
|
|
|
468
|
-
|
|
277
|
+
### Custom Layout via `registerLayout()`
|
|
469
278
|
|
|
470
279
|
```typescript
|
|
471
|
-
|
|
280
|
+
crewx.registerLayout('compact', `
|
|
281
|
+
## {{agent.name}} ({{agent.role}})
|
|
282
|
+
{{agent.inline.prompt}}
|
|
283
|
+
`);
|
|
472
284
|
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
// Format for Slack with rich text support
|
|
476
|
-
const formatted = slackFormatter.formatForSlack(messages, {
|
|
477
|
-
includeTimestamp: true,
|
|
478
|
-
useThreading: true,
|
|
479
|
-
preserveMentions: true,
|
|
285
|
+
const prompt = await crewx.renderAgentPromptFull('assistant', {
|
|
286
|
+
layout: 'compact',
|
|
480
287
|
});
|
|
288
|
+
```
|
|
481
289
|
|
|
482
|
-
|
|
483
|
-
const response = slackFormatter.formatAgentResponse({
|
|
484
|
-
content: 'Task completed successfully!',
|
|
485
|
-
agentId: 'backend',
|
|
486
|
-
metadata: { status: 'success' }
|
|
487
|
-
});
|
|
290
|
+
### Inline Layout in `crewx.yaml`
|
|
488
291
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
292
|
+
```yaml
|
|
293
|
+
agents:
|
|
294
|
+
assistant:
|
|
295
|
+
provider: cli/claude
|
|
296
|
+
inline:
|
|
297
|
+
prompt: You are helpful.
|
|
298
|
+
layout:
|
|
299
|
+
id: crewx/default
|
|
300
|
+
props:
|
|
301
|
+
show_skills: false # Pass props to the layout template
|
|
495
302
|
```
|
|
496
303
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
For API responses or structured data:
|
|
304
|
+
### Inline Template String
|
|
500
305
|
|
|
501
306
|
```typescript
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
type ConversationMetadata
|
|
506
|
-
} from '@crewx/sdk';
|
|
507
|
-
|
|
508
|
-
class APIFormatter extends BaseMessageFormatter {
|
|
509
|
-
formatForAPI(messages: StructuredMessage[]): {
|
|
510
|
-
messages: Array<{
|
|
511
|
-
id: string;
|
|
512
|
-
author: { id: string; isBot: boolean };
|
|
513
|
-
content: string;
|
|
514
|
-
timestamp: string;
|
|
515
|
-
metadata?: Record<string, unknown>;
|
|
516
|
-
}>;
|
|
517
|
-
meta: ConversationMetadata;
|
|
518
|
-
} {
|
|
519
|
-
return {
|
|
520
|
-
messages: messages.map(msg => ({
|
|
521
|
-
id: msg.id,
|
|
522
|
-
author: {
|
|
523
|
-
id: msg.userId || 'unknown',
|
|
524
|
-
isBot: msg.isAssistant || false,
|
|
525
|
-
},
|
|
526
|
-
content: msg.text,
|
|
527
|
-
timestamp: msg.timestamp,
|
|
528
|
-
metadata: msg.metadata,
|
|
529
|
-
})),
|
|
530
|
-
meta: {
|
|
531
|
-
platform: 'api',
|
|
532
|
-
totalMessages: messages.length,
|
|
533
|
-
generatedAt: new Date().toISOString(),
|
|
534
|
-
},
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
const apiFormatter = new APIFormatter();
|
|
540
|
-
const response = apiFormatter.formatForAPI(messages);
|
|
541
|
-
|
|
542
|
-
// Return as JSON API response
|
|
543
|
-
res.json(response);
|
|
307
|
+
const prompt = await crewx.renderAgentPromptFull('assistant', {
|
|
308
|
+
layout: { template: 'SYSTEM: {{agent.inline.prompt}}' },
|
|
309
|
+
});
|
|
544
310
|
```
|
|
545
311
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
Create your own formatter for custom platforms:
|
|
549
|
-
|
|
550
|
-
```typescript
|
|
551
|
-
import {
|
|
552
|
-
BaseMessageFormatter,
|
|
553
|
-
StructuredMessage,
|
|
554
|
-
FormatterOptions
|
|
555
|
-
} from '@crewx/sdk';
|
|
312
|
+
---
|
|
556
313
|
|
|
557
|
-
|
|
558
|
-
formatMessage(msg: StructuredMessage, options: FormatterOptions): string {
|
|
559
|
-
const timestamp = options.includeTimestamp
|
|
560
|
-
? `<t:${Math.floor(new Date(msg.timestamp).getTime() / 1000)}:R> `
|
|
561
|
-
: '';
|
|
314
|
+
## 5. Template Helpers
|
|
562
315
|
|
|
563
|
-
|
|
316
|
+
The `inline.prompt` field in `crewx.yaml` is a **Handlebars template**. These helpers are available:
|
|
564
317
|
|
|
565
|
-
|
|
566
|
-
}
|
|
318
|
+
### P0 Helpers (Core)
|
|
567
319
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
embeds: [{
|
|
574
|
-
title: options.title || 'Agent Response',
|
|
575
|
-
description: message,
|
|
576
|
-
color: options.color || 0x5865F2,
|
|
577
|
-
timestamp: new Date().toISOString(),
|
|
578
|
-
}],
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
|
-
}
|
|
320
|
+
| Helper | Usage | Description |
|
|
321
|
+
|--------|-------|-------------|
|
|
322
|
+
| `exec` | `{{exec "git log --oneline -5"}}` | Run shell command and inline output |
|
|
323
|
+
| `include` | `{{include someVar}}` | Include a string variable as-is (no escaping) |
|
|
324
|
+
| `fenced_code` | `{{fenced_code content lang="ts"}}` | Wrap content in Markdown code block |
|
|
582
325
|
|
|
583
|
-
|
|
584
|
-
const embed = discordFormatter.formatForDiscordEmbed(
|
|
585
|
-
'Analysis complete!',
|
|
586
|
-
{ title: 'Backend Agent', color: 0x00FF00 }
|
|
587
|
-
);
|
|
326
|
+
### Condition Helpers
|
|
588
327
|
|
|
589
|
-
|
|
328
|
+
```handlebars
|
|
329
|
+
{{#if (eq agent.team "backend")}}Backend mode{{/if}}
|
|
330
|
+
{{#if (and featureA featureB)}}Both enabled{{/if}}
|
|
590
331
|
```
|
|
591
332
|
|
|
592
|
-
|
|
333
|
+
Available: `eq`, `ne`, `and`, `or`, `not`, `contains`
|
|
593
334
|
|
|
594
|
-
|
|
335
|
+
### Utility Helpers
|
|
595
336
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
const messages: StructuredMessage[] = [
|
|
604
|
-
{
|
|
605
|
-
id: 'msg-1',
|
|
606
|
-
userId: 'user123',
|
|
607
|
-
text: 'What is the status?',
|
|
608
|
-
timestamp: new Date().toISOString(),
|
|
609
|
-
isAssistant: false,
|
|
610
|
-
metadata: {
|
|
611
|
-
platform: 'slack',
|
|
612
|
-
channelId: 'C123456',
|
|
613
|
-
threadTs: '1234567890.123456',
|
|
614
|
-
userAgent: 'SlackBot/1.0',
|
|
615
|
-
},
|
|
616
|
-
},
|
|
617
|
-
{
|
|
618
|
-
id: 'msg-2',
|
|
619
|
-
userId: 'backend-agent',
|
|
620
|
-
text: 'All systems operational.',
|
|
621
|
-
timestamp: new Date().toISOString(),
|
|
622
|
-
isAssistant: true,
|
|
623
|
-
metadata: {
|
|
624
|
-
agentId: 'backend',
|
|
625
|
-
model: 'claude-3-5-sonnet',
|
|
626
|
-
processingTime: 1234,
|
|
627
|
-
tokenUsage: { input: 50, output: 100 },
|
|
628
|
-
},
|
|
629
|
-
},
|
|
630
|
-
];
|
|
337
|
+
| Helper | Description |
|
|
338
|
+
|--------|-------------|
|
|
339
|
+
| `truncate text len` | Truncate string to N chars |
|
|
340
|
+
| `length array` | Array/string length |
|
|
341
|
+
| `escapeHandlebars text` | Escape `{{` in content |
|
|
342
|
+
| `formatFileSize bytes` | `1048576` → `1 MB` |
|
|
343
|
+
| `formatTimestamp ms` | Unix ms → readable date |
|
|
631
344
|
|
|
632
|
-
|
|
345
|
+
### Document Access in Templates
|
|
633
346
|
|
|
634
|
-
|
|
635
|
-
const formatted = formatter.formatHistory(messages, {
|
|
636
|
-
includeUserId: true,
|
|
637
|
-
includeTimestamp: true,
|
|
638
|
-
extractMetadata: true,
|
|
639
|
-
});
|
|
640
|
-
|
|
641
|
-
// Access metadata
|
|
642
|
-
messages.forEach(msg => {
|
|
643
|
-
if (msg.metadata?.tokenUsage) {
|
|
644
|
-
console.log(`Tokens used: ${msg.metadata.tokenUsage.input + msg.metadata.tokenUsage.output}`);
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
```
|
|
347
|
+
Documents defined in `crewx.yaml` are automatically available:
|
|
648
348
|
|
|
649
|
-
|
|
349
|
+
```handlebars
|
|
350
|
+
# Inline the full document
|
|
351
|
+
{{{documents.guidelines.content}}}
|
|
650
352
|
|
|
651
|
-
|
|
353
|
+
# Access metadata
|
|
354
|
+
Path: {{documents.guidelines.path}}
|
|
355
|
+
```
|
|
652
356
|
|
|
653
|
-
|
|
654
|
-
```typescript
|
|
655
|
-
// This was CLI-only code
|
|
656
|
-
import { MessageFormatter } from '../cli/src/utils/message-formatter';
|
|
357
|
+
### `exec` Security Policy
|
|
657
358
|
|
|
658
|
-
|
|
659
|
-
const result = formatter.format(messages);
|
|
660
|
-
```
|
|
359
|
+
Control which shell commands are allowed in templates:
|
|
661
360
|
|
|
662
|
-
**After (SDK)**
|
|
663
361
|
```typescript
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
includeUserId: true,
|
|
670
|
-
includeTimestamp: true,
|
|
362
|
+
const crewx = await Crewx.loadYaml('./crewx.yaml', {
|
|
363
|
+
execPolicy: {
|
|
364
|
+
allow: ['git *', 'npm run *', 'cat *'],
|
|
365
|
+
deny: ['rm *', 'curl *'],
|
|
366
|
+
},
|
|
671
367
|
});
|
|
672
368
|
```
|
|
673
369
|
|
|
674
|
-
|
|
675
|
-
1. Import from `@crewx/sdk` instead of CLI internals
|
|
676
|
-
2. Use `formatHistory()` method instead of `format()`
|
|
677
|
-
3. Options are now explicitly passed as second parameter
|
|
678
|
-
4. Metadata handling is built-in with `extractMetadata` option
|
|
679
|
-
|
|
680
|
-
**Slack Migration**
|
|
681
|
-
```typescript
|
|
682
|
-
// Before (CLI)
|
|
683
|
-
import { SlackFormatter } from '../cli/src/slack/formatter';
|
|
684
|
-
|
|
685
|
-
// After (SDK)
|
|
686
|
-
import { SlackMessageFormatter } from '@crewx/sdk';
|
|
370
|
+
Or set it in `crewx.yaml`:
|
|
687
371
|
|
|
688
|
-
|
|
689
|
-
|
|
372
|
+
```yaml
|
|
373
|
+
settings:
|
|
374
|
+
template:
|
|
375
|
+
exec:
|
|
376
|
+
allow:
|
|
377
|
+
- "git *"
|
|
378
|
+
- "npm run *"
|
|
379
|
+
deny:
|
|
380
|
+
- "rm *"
|
|
690
381
|
```
|
|
691
382
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
If you're building a CLI tool and want to add Slack formatting support:
|
|
695
|
-
|
|
696
|
-
**Step 1: Install SDK**
|
|
697
|
-
```bash
|
|
698
|
-
npm install @crewx/sdk
|
|
699
|
-
```
|
|
383
|
+
Glob syntax: `*` matches within a segment, `**` matches across path segments.
|
|
700
384
|
|
|
701
|
-
|
|
702
|
-
```typescript
|
|
703
|
-
import { SlackMessageFormatter } from '@crewx/sdk';
|
|
704
|
-
import { WebClient } from '@slack/web-api';
|
|
385
|
+
---
|
|
705
386
|
|
|
706
|
-
|
|
707
|
-
const formatter = new SlackMessageFormatter();
|
|
708
|
-
```
|
|
387
|
+
## 6. Provider Bridge
|
|
709
388
|
|
|
710
|
-
|
|
711
|
-
```typescript
|
|
712
|
-
async function sendToSlack(
|
|
713
|
-
channelId: string,
|
|
714
|
-
content: string,
|
|
715
|
-
threadTs?: string
|
|
716
|
-
) {
|
|
717
|
-
// Format using SDK formatter
|
|
718
|
-
const formatted = formatter.formatAgentResponse({
|
|
719
|
-
content,
|
|
720
|
-
agentId: 'my-cli-agent',
|
|
721
|
-
metadata: {
|
|
722
|
-
source: 'cli',
|
|
723
|
-
timestamp: new Date().toISOString(),
|
|
724
|
-
},
|
|
725
|
-
});
|
|
726
|
-
|
|
727
|
-
// Send to Slack
|
|
728
|
-
await slackClient.chat.postMessage({
|
|
729
|
-
channel: channelId,
|
|
730
|
-
text: content, // Fallback text
|
|
731
|
-
blocks: formatted.blocks,
|
|
732
|
-
thread_ts: threadTs,
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
```
|
|
389
|
+
Each agent has a `provider` field that tells the SDK which AI backend to use.
|
|
736
390
|
|
|
737
|
-
|
|
738
|
-
```typescript
|
|
739
|
-
import {
|
|
740
|
-
SlackMessageFormatter,
|
|
741
|
-
type StructuredMessage
|
|
742
|
-
} from '@crewx/sdk';
|
|
743
|
-
|
|
744
|
-
async function formatSlackThread(threadTs: string) {
|
|
745
|
-
// Fetch Slack thread
|
|
746
|
-
const thread = await slackClient.conversations.replies({
|
|
747
|
-
channel: channelId,
|
|
748
|
-
ts: threadTs,
|
|
749
|
-
});
|
|
750
|
-
|
|
751
|
-
// Convert to StructuredMessage format
|
|
752
|
-
const messages: StructuredMessage[] = thread.messages.map(msg => ({
|
|
753
|
-
id: msg.ts,
|
|
754
|
-
userId: msg.user || 'bot',
|
|
755
|
-
text: msg.text || '',
|
|
756
|
-
timestamp: new Date(parseFloat(msg.ts) * 1000).toISOString(),
|
|
757
|
-
isAssistant: !!msg.bot_id,
|
|
758
|
-
metadata: {
|
|
759
|
-
platform: 'slack',
|
|
760
|
-
threadTs: msg.thread_ts,
|
|
761
|
-
},
|
|
762
|
-
}));
|
|
763
|
-
|
|
764
|
-
// Format for display or processing
|
|
765
|
-
const formatter = new SlackMessageFormatter();
|
|
766
|
-
const formatted = formatter.formatHistory(messages, {
|
|
767
|
-
includeTimestamp: true,
|
|
768
|
-
useThreading: true,
|
|
769
|
-
});
|
|
770
|
-
|
|
771
|
-
return formatted;
|
|
772
|
-
}
|
|
773
|
-
```
|
|
391
|
+
### Supported Providers
|
|
774
392
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
const errorMessage = formatter.formatAgentResponse({
|
|
782
|
-
content: `❌ Error: ${error.message}`,
|
|
783
|
-
agentId: 'cli-agent',
|
|
784
|
-
metadata: { status: 'error' },
|
|
785
|
-
});
|
|
786
|
-
|
|
787
|
-
await slackClient.chat.postMessage({
|
|
788
|
-
channel: channelId,
|
|
789
|
-
blocks: errorMessage.blocks,
|
|
790
|
-
});
|
|
791
|
-
}
|
|
792
|
-
```
|
|
393
|
+
| Provider | CLI Command | Notes |
|
|
394
|
+
|----------|-------------|-------|
|
|
395
|
+
| `cli/claude` | `claude` | Claude Code CLI |
|
|
396
|
+
| `cli/gemini` | `gemini` | Gemini CLI |
|
|
397
|
+
| `cli/copilot` | `gh copilot suggest` | GitHub Copilot |
|
|
398
|
+
| `cli/codex` | `codex` | OpenAI Codex CLI |
|
|
793
399
|
|
|
794
|
-
|
|
400
|
+
> **Coming Soon**: `api/claude`, `api/openai` — direct API providers without CLI dependency.
|
|
795
401
|
|
|
796
|
-
|
|
402
|
+
### Provider Override at Call Site
|
|
797
403
|
|
|
798
404
|
```typescript
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
CopilotProvider,
|
|
804
|
-
CodexProvider,
|
|
805
|
-
type LoggerLike,
|
|
806
|
-
type BaseAIProviderOptions
|
|
807
|
-
} from '@crewx/sdk';
|
|
808
|
-
|
|
809
|
-
// Use built-in provider
|
|
810
|
-
const claude = new ClaudeProvider({
|
|
811
|
-
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
812
|
-
logger: console,
|
|
813
|
-
enableToolUse: true,
|
|
814
|
-
model: 'claude-3-5-sonnet-20241022',
|
|
405
|
+
// Use a different provider for one call
|
|
406
|
+
const result = await crewx.query('assistant', 'Hello', {
|
|
407
|
+
provider: 'cli/gemini',
|
|
408
|
+
model: 'gemini-2.0-flash',
|
|
815
409
|
});
|
|
816
|
-
|
|
817
|
-
// Custom provider
|
|
818
|
-
class MyProvider extends BaseAIProvider {
|
|
819
|
-
constructor(options: BaseAIProviderOptions) {
|
|
820
|
-
super(options);
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
async query(prompt: string, options: AIQueryOptions): Promise<AIResponse> {
|
|
824
|
-
// Custom implementation
|
|
825
|
-
return { content: 'Response', metadata: {} };
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
410
|
```
|
|
829
411
|
|
|
830
|
-
###
|
|
412
|
+
### `query` vs `execute` Mode
|
|
831
413
|
|
|
832
|
-
|
|
414
|
+
| | `query()` | `execute()` |
|
|
415
|
+
|--|-----------|-------------|
|
|
416
|
+
| Intent | Read-only Q&A | Task with side effects |
|
|
417
|
+
| cli/claude flags | `-p --output-format stream-json --verbose` | + `--dangerously-skip-permissions` |
|
|
418
|
+
| Use when | Asking questions, generating text | Writing files, running commands |
|
|
833
419
|
|
|
834
|
-
|
|
835
|
-
import {
|
|
836
|
-
RemoteAgentManager,
|
|
837
|
-
FetchRemoteTransport,
|
|
838
|
-
MockRemoteTransport,
|
|
839
|
-
type RemoteAgentConfig
|
|
840
|
-
} from '@crewx/sdk';
|
|
841
|
-
|
|
842
|
-
// Production transport
|
|
843
|
-
const transport = new FetchRemoteTransport({
|
|
844
|
-
timeout: 30000,
|
|
845
|
-
headers: { 'Authorization': `Bearer ${token}` },
|
|
846
|
-
});
|
|
420
|
+
---
|
|
847
421
|
|
|
848
|
-
|
|
849
|
-
const mockTransport = new MockRemoteTransport({
|
|
850
|
-
'agent-1': { content: 'Mocked response', success: true },
|
|
851
|
-
});
|
|
422
|
+
## 7. Plugin System
|
|
852
423
|
|
|
853
|
-
|
|
854
|
-
transport,
|
|
855
|
-
enableLogging: true,
|
|
856
|
-
logger: console,
|
|
857
|
-
});
|
|
424
|
+
Plugins extend `CrewxPlugin` from `@crewx/sdk` and attach event listeners in `attach()`. Register with `crewx.use(plugin)` and release resources by calling `crewx.close()`.
|
|
858
425
|
|
|
859
|
-
|
|
860
|
-
await manager.loadAgent({
|
|
861
|
-
id: 'backend',
|
|
862
|
-
url: 'https://api.example.com/agent',
|
|
863
|
-
apiKey: process.env.REMOTE_API_KEY,
|
|
864
|
-
tools: ['search', 'analyze'],
|
|
865
|
-
});
|
|
426
|
+
### Lifecycle
|
|
866
427
|
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
428
|
+
```typescript
|
|
429
|
+
await crewx.use(plugin); // calls plugin.attach(crewx) — subscribe events, open DB, etc.
|
|
430
|
+
await crewx.close(); // calls plugin.detach(crewx) on all plugins in LIFO order
|
|
870
431
|
```
|
|
871
432
|
|
|
872
|
-
|
|
433
|
+
Same plugin instance registered twice is silently ignored.
|
|
873
434
|
|
|
874
|
-
###
|
|
875
|
-
|
|
876
|
-
Some internal APIs are available for advanced use cases:
|
|
877
|
-
|
|
878
|
-
```typescript
|
|
879
|
-
import { /* internal exports */ } from '@crewx/sdk/internal';
|
|
435
|
+
### Built-in Plugins (`@crewx/cli`)
|
|
880
436
|
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
437
|
+
| Plugin | Import path | Storage |
|
|
438
|
+
|--------|-------------|---------|
|
|
439
|
+
| `FileLoggerPlugin` | `@crewx/cli/plugins/file-logger` | `.crewx/logs/{ts}_{traceId}.log` (one file per task) |
|
|
440
|
+
| `SqliteTracingPlugin` | `@crewx/cli/plugins/sqlite-tracing` | `~/.crewx/crewx.db` — `tasks` table |
|
|
884
441
|
|
|
885
|
-
|
|
442
|
+
> The `crewx` CLI auto-attaches both plugins for every run. No setup needed when using the CLI directly.
|
|
886
443
|
|
|
887
|
-
|
|
444
|
+
### Custom Plugin
|
|
888
445
|
|
|
889
446
|
```typescript
|
|
890
|
-
import {
|
|
891
|
-
import {
|
|
447
|
+
import { CrewxPlugin } from '@crewx/sdk';
|
|
448
|
+
import type { Crewx } from '@crewx/sdk';
|
|
892
449
|
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
constructor(private readonly docManager: DocumentManager) {}
|
|
450
|
+
class CostTrackerPlugin extends CrewxPlugin {
|
|
451
|
+
readonly name = 'cost-tracker';
|
|
896
452
|
|
|
897
|
-
|
|
898
|
-
|
|
453
|
+
attach(crewx: Crewx) {
|
|
454
|
+
crewx.on('task:end', (e) => {
|
|
455
|
+
if (e.costUsd) console.log(`[cost] ${e.agentRef}: $${e.costUsd.toFixed(4)}`);
|
|
456
|
+
});
|
|
899
457
|
}
|
|
458
|
+
// detach() is optional — base class no-op is sufficient if no cleanup needed
|
|
900
459
|
}
|
|
901
|
-
```
|
|
902
460
|
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
```typescript
|
|
906
|
-
import {
|
|
907
|
-
SERVER_NAME,
|
|
908
|
-
PREFIX_TOOL_NAME,
|
|
909
|
-
DEFAULT_MAX_FILE_SIZE,
|
|
910
|
-
DEFAULT_MAX_FILES
|
|
911
|
-
} from '@crewx/sdk';
|
|
912
|
-
|
|
913
|
-
console.log(SERVER_NAME); // 'crewx'
|
|
914
|
-
console.log(PREFIX_TOOL_NAME); // 'crewx_'
|
|
461
|
+
await crewx.use(new CostTrackerPlugin());
|
|
915
462
|
```
|
|
916
463
|
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
The SDK provides the following export paths:
|
|
920
|
-
|
|
921
|
-
- `@crewx/sdk` - Main public API
|
|
922
|
-
- `@crewx/sdk/internal` - Internal utilities (use with caution)
|
|
923
|
-
- `@crewx/sdk/package.json` - Package metadata
|
|
464
|
+
---
|
|
924
465
|
|
|
925
|
-
##
|
|
466
|
+
## 8. Event System
|
|
926
467
|
|
|
927
|
-
The
|
|
468
|
+
The `Crewx` class extends `TypedEventEmitter`. Events are emitted automatically during `query()` and `execute()`.
|
|
928
469
|
|
|
929
|
-
|
|
930
|
-
import type { AIProvider, AgentConfig } from '@crewx/sdk';
|
|
470
|
+
### Event Catalog
|
|
931
471
|
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
};
|
|
938
|
-
```
|
|
472
|
+
| Event | When | Key Payload Fields |
|
|
473
|
+
|-------|------|--------------------|
|
|
474
|
+
| `task:start` | `query()`/`execute()` begins | `traceId`, `agentRef`, `mode`, `pid`, `model`, `provider`, `message`, `timestamp` |
|
|
475
|
+
| `task:end` | Call completes (success or failure) | `traceId`, `agentRef`, `durationMs`, `result`, `error`, `inputTokens`, `outputTokens`, `costUsd`, `model` |
|
|
476
|
+
| `task:output` | Each line of provider output | `traceId`, `agentRef`, `output`, `level` (`stdout`\|`stderr`\|`info`) |
|
|
939
477
|
|
|
940
|
-
|
|
478
|
+
All events share `traceId` (format: `tsk_XXXXXXXX`) and `timestamp` inherited from `BaseEvent`.
|
|
941
479
|
|
|
942
|
-
|
|
943
|
-
# Run unit tests
|
|
944
|
-
npm test
|
|
480
|
+
### `crewx.on(event, listener)` → `UnsubscribeFn`
|
|
945
481
|
|
|
946
|
-
|
|
947
|
-
|
|
482
|
+
```typescript
|
|
483
|
+
import type { TaskEndEvent } from '@crewx/sdk';
|
|
948
484
|
|
|
949
|
-
|
|
950
|
-
|
|
485
|
+
const unsub = crewx.on('task:end', (e: TaskEndEvent) => {
|
|
486
|
+
console.log(`${e.agentRef} finished in ${e.durationMs}ms | tokens: ${e.inputTokens}+${e.outputTokens}`);
|
|
487
|
+
});
|
|
951
488
|
|
|
952
|
-
|
|
953
|
-
|
|
489
|
+
// Remove listener when no longer needed
|
|
490
|
+
unsub();
|
|
954
491
|
```
|
|
955
492
|
|
|
956
|
-
|
|
493
|
+
`crewx.once(event, listener)` fires exactly once and auto-unsubscribes.
|
|
957
494
|
|
|
958
|
-
|
|
959
|
-
# Build the package
|
|
960
|
-
npm run build
|
|
495
|
+
> **Best practice**: Subscribe inside `Plugin.attach()` so listeners are automatically removed by `crewx.close()`. Direct `crewx.on()` calls are fine for one-off use but require manual `unsub()` calls.
|
|
961
496
|
|
|
962
|
-
|
|
963
|
-
```
|
|
497
|
+
---
|
|
964
498
|
|
|
965
|
-
##
|
|
499
|
+
## 9. Type Reference
|
|
966
500
|
|
|
967
|
-
|
|
501
|
+
### `CrewxOptions`
|
|
968
502
|
|
|
969
|
-
|
|
503
|
+
```typescript
|
|
504
|
+
interface CrewxOptions {
|
|
505
|
+
workspaceRoot?: string;
|
|
506
|
+
platform?: 'cli' | 'slack' | 'api';
|
|
507
|
+
execPolicy?: ExecPolicy; // Allowed/denied shell commands in {{exec}}
|
|
508
|
+
}
|
|
509
|
+
```
|
|
970
510
|
|
|
971
|
-
|
|
972
|
-
2. Create a feature branch
|
|
973
|
-
3. Make your changes
|
|
974
|
-
4. Add tests for new functionality
|
|
975
|
-
5. Run `npm test` and `npm run build`
|
|
976
|
-
6. Submit a pull request
|
|
511
|
+
### `QueryOptions` / `ExecuteOptions`
|
|
977
512
|
|
|
978
|
-
|
|
513
|
+
```typescript
|
|
514
|
+
interface QueryOptions {
|
|
515
|
+
model?: string; // Override model (e.g. 'claude-opus-4-6')
|
|
516
|
+
provider?: string; // Override provider (e.g. 'cli/gemini')
|
|
517
|
+
context?: string; // Extra context prepended to message
|
|
518
|
+
metadata?: Record<string, unknown>;
|
|
519
|
+
}
|
|
520
|
+
// ExecuteOptions has the same shape
|
|
521
|
+
```
|
|
979
522
|
|
|
980
|
-
|
|
523
|
+
### `QueryResult` / `ExecuteResult`
|
|
981
524
|
|
|
982
|
-
|
|
525
|
+
```typescript
|
|
526
|
+
interface QueryResult {
|
|
527
|
+
ok: boolean;
|
|
528
|
+
data: string; // Agent's response text
|
|
529
|
+
error?: {
|
|
530
|
+
code: string; // 'AGENT_NOT_FOUND' | 'PROVIDER_ERROR' | 'QUERY_FAILED'
|
|
531
|
+
message: string;
|
|
532
|
+
};
|
|
533
|
+
meta: {
|
|
534
|
+
agentId: string;
|
|
535
|
+
provider: string;
|
|
536
|
+
model?: string;
|
|
537
|
+
durationMs: number;
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
// ExecuteResult has the same shape
|
|
541
|
+
```
|
|
983
542
|
|
|
984
|
-
|
|
543
|
+
### `AgentConfig`
|
|
985
544
|
|
|
986
545
|
```typescript
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
model
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
},
|
|
1003
|
-
mode: 'query',
|
|
1004
|
-
platform: 'cli'
|
|
1005
|
-
};
|
|
546
|
+
interface AgentConfig {
|
|
547
|
+
id: string;
|
|
548
|
+
name?: string;
|
|
549
|
+
role?: string;
|
|
550
|
+
team?: string;
|
|
551
|
+
provider: string | string[];
|
|
552
|
+
working_directory?: string;
|
|
553
|
+
description?: string;
|
|
554
|
+
inline?: {
|
|
555
|
+
model?: string;
|
|
556
|
+
system_prompt?: string;
|
|
557
|
+
prompt?: string;
|
|
558
|
+
layout?: string | { id: string; props?: Record<string, unknown> };
|
|
559
|
+
};
|
|
560
|
+
}
|
|
1006
561
|
```
|
|
1007
562
|
|
|
1008
|
-
|
|
563
|
+
### `ExecPolicy`
|
|
1009
564
|
|
|
1010
|
-
|
|
565
|
+
```typescript
|
|
566
|
+
interface ExecPolicy {
|
|
567
|
+
allow: string[]; // Glob patterns for allowed commands
|
|
568
|
+
deny: string[]; // Glob patterns for denied commands (takes precedence)
|
|
569
|
+
}
|
|
570
|
+
```
|
|
1011
571
|
|
|
1012
|
-
|
|
1013
|
-
- [Documentation](../../docs/)
|
|
1014
|
-
- [Main README](../../README.md)
|
|
572
|
+
---
|
|
1015
573
|
|
|
1016
|
-
##
|
|
574
|
+
## Coming Soon
|
|
1017
575
|
|
|
1018
|
-
-
|
|
576
|
+
- **Tool System** — attach custom tools/functions to agents (§3 of design spec)
|
|
577
|
+
- **`api/*` Providers** — direct API calls without CLI dependency
|
|
1019
578
|
|
|
1020
579
|
---
|
|
1021
580
|
|
|
1022
|
-
|
|
581
|
+
## Requirements
|
|
582
|
+
|
|
583
|
+
- Node.js >= 20.19.0
|
|
584
|
+
- At least one CLI provider installed (e.g. `npm i -g @anthropic-ai/claude-code`)
|