@crewx/sdk 0.8.0-rc.73 → 0.8.0-rc.74
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 +67 -102
- 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,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* toTemplateMessages — maps ConversationThread messages to TemplateMessage[]
|
|
3
|
+
* for consumption by the formatConversation block helper.
|
|
4
|
+
*
|
|
5
|
+
* Includes SEC-M1 sanitization at the provider boundary:
|
|
6
|
+
* <, > are entity-escaped to prevent XML structure tag injection in the
|
|
7
|
+
* <conversation_history> block.
|
|
8
|
+
*/
|
|
9
|
+
import type { ConversationThread, TemplateMessage } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Convert a ConversationThread to a TemplateMessage array suitable for
|
|
12
|
+
* formatConversation block helper consumption.
|
|
13
|
+
*/
|
|
14
|
+
export declare function toTemplateMessages(thread: ConversationThread): TemplateMessage[];
|
|
15
|
+
//# sourceMappingURL=to-template-messages.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* toTemplateMessages — maps ConversationThread messages to TemplateMessage[]
|
|
4
|
+
* for consumption by the formatConversation block helper.
|
|
5
|
+
*
|
|
6
|
+
* Includes SEC-M1 sanitization at the provider boundary:
|
|
7
|
+
* <, > are entity-escaped to prevent XML structure tag injection in the
|
|
8
|
+
* <conversation_history> block.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.toTemplateMessages = toTemplateMessages;
|
|
12
|
+
/**
|
|
13
|
+
* SEC-M1: sanitize message text to prevent conversation_history XML block pollution.
|
|
14
|
+
* User input containing </conversation_history> or <system_prompt> could be
|
|
15
|
+
* misinterpreted by the LLM as breaking out of the structured block.
|
|
16
|
+
*/
|
|
17
|
+
function sanitizeMessageText(text) {
|
|
18
|
+
if (typeof text !== 'string')
|
|
19
|
+
return '';
|
|
20
|
+
return text.replace(/</g, '<').replace(/>/g, '>');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Convert a ConversationThread to a TemplateMessage array suitable for
|
|
24
|
+
* formatConversation block helper consumption.
|
|
25
|
+
*/
|
|
26
|
+
function toTemplateMessages(thread) {
|
|
27
|
+
return thread.messages.map(m => ({
|
|
28
|
+
text: sanitizeMessageText(m.text),
|
|
29
|
+
isAssistant: m.isAssistant,
|
|
30
|
+
metadata: m.metadata,
|
|
31
|
+
files: undefined,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=to-template-messages.js.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversation history types — SDK public API for reading/writing thread history.
|
|
3
|
+
*
|
|
4
|
+
* **Security (SEC-3):** history content is untrusted user input.
|
|
5
|
+
* Consumers (e.g. Phase 2 CLI wiring) MUST delimit history from system prompts
|
|
6
|
+
* using structured blocks (e.g. `[HISTORY START]...[HISTORY END]`).
|
|
7
|
+
*/
|
|
8
|
+
export interface ConversationMessage {
|
|
9
|
+
id: string;
|
|
10
|
+
userId?: string;
|
|
11
|
+
text: string;
|
|
12
|
+
isAssistant: boolean;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
metadata?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
export type Platform = 'cli' | 'web' | 'api' | `channel/${string}`;
|
|
17
|
+
export interface ConversationThread {
|
|
18
|
+
threadId: string;
|
|
19
|
+
/** Immutable after ensureThread — reusing a 'cli' thread as 'channel/slack' is forbidden (P1-6). */
|
|
20
|
+
platform: Platform;
|
|
21
|
+
messages: ConversationMessage[];
|
|
22
|
+
metadata?: {
|
|
23
|
+
title?: string;
|
|
24
|
+
firstMessage?: string;
|
|
25
|
+
lastMessage?: string;
|
|
26
|
+
messageCount?: number;
|
|
27
|
+
updatedAt?: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Template-friendly message shape consumed by formatConversation block helper.
|
|
32
|
+
* Matches default.yaml L292~303 expected structure.
|
|
33
|
+
*/
|
|
34
|
+
export interface TemplateMessage {
|
|
35
|
+
text: string;
|
|
36
|
+
isAssistant: boolean;
|
|
37
|
+
metadata?: Record<string, unknown>;
|
|
38
|
+
files?: Array<{
|
|
39
|
+
name: string;
|
|
40
|
+
size?: number;
|
|
41
|
+
localPath?: string;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
export interface FetchHistoryOptions {
|
|
45
|
+
limit?: number;
|
|
46
|
+
maxContextLength?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Trace ID of the currently running task — excluded from history
|
|
49
|
+
* to avoid including in-progress turns (SQ2).
|
|
50
|
+
*/
|
|
51
|
+
currentTraceId?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Provider interface for reading/writing conversation history.
|
|
55
|
+
*
|
|
56
|
+
* **Security (SEC-3):** history content is untrusted user input.
|
|
57
|
+
* Consumers (Phase 2 CLI wiring) MUST delimit history from system prompts
|
|
58
|
+
* using structured blocks (e.g. `[HISTORY START]...[HISTORY END]`).
|
|
59
|
+
*/
|
|
60
|
+
export interface IConversationHistoryProvider {
|
|
61
|
+
/**
|
|
62
|
+
* Ensure a thread row exists in the threads table.
|
|
63
|
+
* @param threadId - Recommended: unguessable value (UUID/nanoid).
|
|
64
|
+
* WI-C2 Slack environments MUST enforce userId/channelId-based namespace
|
|
65
|
+
* isolation in threadId generation policy.
|
|
66
|
+
*/
|
|
67
|
+
ensureThread(threadId: string, platform: Platform, workspaceId?: string): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Fetch conversation history from the tasks table.
|
|
70
|
+
*
|
|
71
|
+
* Filter rules (SQ2, aligned with server thread.service.ts:373):
|
|
72
|
+
* - WHERE thread_id = ?
|
|
73
|
+
* - AND parent_task_id IS NULL (exclude chain child tasks)
|
|
74
|
+
* - AND (status IN ('done','completed') OR status IS NULL) (exclude failed/running)
|
|
75
|
+
* - AND (if options.currentTraceId) trace_id != currentTraceId
|
|
76
|
+
* - ORDER BY started_at ASC
|
|
77
|
+
* - LIMIT options.limit ?? 100
|
|
78
|
+
*/
|
|
79
|
+
fetchHistory(threadId: string, options?: FetchHistoryOptions): Promise<ConversationThread>;
|
|
80
|
+
/**
|
|
81
|
+
* Phase 1: update threads metadata only (updated_at, last_message, message_count).
|
|
82
|
+
* User content is written by SqliteTracingPlugin to tasks.prompt.
|
|
83
|
+
* userId parameter is a WI-C2 (Slack) extension point.
|
|
84
|
+
*
|
|
85
|
+
* **⛔ (SEC-5)** Do NOT pass credentials, env vars, or API keys in metadata —
|
|
86
|
+
* this data is persisted as JSON in the threads table.
|
|
87
|
+
*/
|
|
88
|
+
saveUserMessage(threadId: string, text: string, userId?: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Phase 1: update threads metadata only.
|
|
91
|
+
* Assistant content is written by SqliteTracingPlugin to tasks.result.
|
|
92
|
+
* agentId parameter enriches threads metadata only.
|
|
93
|
+
*
|
|
94
|
+
* **⛔ (SEC-5)** Do NOT pass credentials, env vars, or API keys in metadata —
|
|
95
|
+
* this data is persisted as JSON in the threads table.
|
|
96
|
+
*/
|
|
97
|
+
saveAssistantMessage(threadId: string, text: string, agentId: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
98
|
+
/** Optional — prevent connection leaks in long-running server/test environments. */
|
|
99
|
+
close?(): void;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Conversation history types — SDK public API for reading/writing thread history.
|
|
4
|
+
*
|
|
5
|
+
* **Security (SEC-3):** history content is untrusted user input.
|
|
6
|
+
* Consumers (e.g. Phase 2 CLI wiring) MUST delimit history from system prompts
|
|
7
|
+
* using structured blocks (e.g. `[HISTORY START]...[HISTORY END]`).
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent resolver: looks up an agent from a list by ref.
|
|
3
|
+
* Supports both bare id ('claude') and @mention format ('@claude').
|
|
4
|
+
* Falls back to built-in provider shorthands (claude, gemini, copilot, codex).
|
|
5
|
+
*/
|
|
6
|
+
export class AgentNotFoundError extends Error {
|
|
7
|
+
constructor(agentRef, availableIds) {
|
|
8
|
+
const available = availableIds.length > 0
|
|
9
|
+
? ` Available: ${availableIds.join(', ')}`
|
|
10
|
+
: '';
|
|
11
|
+
super(`Agent not found: "${agentRef}".${available}`);
|
|
12
|
+
this.name = 'AgentNotFoundError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Built-in provider shorthands that can be used without a crewx.yaml entry. */
|
|
16
|
+
const BUILTIN_PROVIDERS = {
|
|
17
|
+
claude: { id: 'claude', provider: 'cli/claude' },
|
|
18
|
+
gemini: { id: 'gemini', provider: 'cli/gemini' },
|
|
19
|
+
copilot: { id: 'copilot', provider: 'cli/copilot' },
|
|
20
|
+
codex: { id: 'codex', provider: 'cli/codex' },
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Resolve an agent by reference.
|
|
24
|
+
* @param agentRef - Agent reference: '@claude', 'claude', '@my_agent', etc.
|
|
25
|
+
* @param agents - List of available agent configs.
|
|
26
|
+
* @returns The matching AgentConfig.
|
|
27
|
+
* @throws AgentNotFoundError when no match is found.
|
|
28
|
+
*/
|
|
29
|
+
export function resolveAgent(agentRef, agents) {
|
|
30
|
+
const agentId = agentRef.startsWith('@') ? agentRef.slice(1) : agentRef;
|
|
31
|
+
// 1. Look in YAML-defined agents first
|
|
32
|
+
const agent = agents.find(a => a.id === agentId);
|
|
33
|
+
if (agent)
|
|
34
|
+
return agent;
|
|
35
|
+
// 2. Fall back to built-in provider shorthands
|
|
36
|
+
const builtin = BUILTIN_PROVIDERS[agentId];
|
|
37
|
+
if (builtin)
|
|
38
|
+
return builtin;
|
|
39
|
+
throw new AgentNotFoundError(agentRef, agents.map(a => a.id));
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=resolver.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SdkBoxService — manages box creation, retrieval, and listing.
|
|
3
|
+
*/
|
|
4
|
+
import { generateId } from '../utils/id';
|
|
5
|
+
const ID_PATTERN = /^[a-zA-Z0-9._-]+$/;
|
|
6
|
+
export class SdkBoxService {
|
|
7
|
+
storage;
|
|
8
|
+
constructor(storage) {
|
|
9
|
+
this.storage = storage;
|
|
10
|
+
}
|
|
11
|
+
listBoxes(threadId) {
|
|
12
|
+
this.validateId(threadId);
|
|
13
|
+
const rows = this.storage.listBoxes(threadId);
|
|
14
|
+
const boxes = rows.map((row) => this.toBoxResponse(row));
|
|
15
|
+
return { boxes, total: boxes.length };
|
|
16
|
+
}
|
|
17
|
+
getBox(threadId, boxId) {
|
|
18
|
+
this.validateId(threadId);
|
|
19
|
+
this.validateId(boxId);
|
|
20
|
+
const row = this.storage.findBox(threadId, boxId);
|
|
21
|
+
if (!row)
|
|
22
|
+
return null;
|
|
23
|
+
return this.toBoxResponse(row);
|
|
24
|
+
}
|
|
25
|
+
createBox(threadId, params) {
|
|
26
|
+
this.validateId(threadId);
|
|
27
|
+
const id = this.generateBoxId();
|
|
28
|
+
const createdAt = new Date().toISOString();
|
|
29
|
+
const row = this.storage.insertBox(threadId, {
|
|
30
|
+
id,
|
|
31
|
+
seq: params.seq,
|
|
32
|
+
firstTaskId: params.firstTaskId,
|
|
33
|
+
midTaskId: params.midTaskId,
|
|
34
|
+
lastTaskId: params.lastTaskId,
|
|
35
|
+
taskCount: params.taskCount,
|
|
36
|
+
summary: params.summary ?? null,
|
|
37
|
+
sourceTokens: params.sourceTokens,
|
|
38
|
+
summaryTokens: params.summaryTokens ?? null,
|
|
39
|
+
createdAt,
|
|
40
|
+
});
|
|
41
|
+
return this.toBoxResponse(row);
|
|
42
|
+
}
|
|
43
|
+
toBoxResponse(row) {
|
|
44
|
+
return {
|
|
45
|
+
id: row.id,
|
|
46
|
+
threadId: row.thread_id,
|
|
47
|
+
seq: row.seq,
|
|
48
|
+
firstTaskId: row.first_task_id,
|
|
49
|
+
lastTaskId: row.last_task_id,
|
|
50
|
+
taskCount: row.task_count,
|
|
51
|
+
sourceTokens: row.source_tokens,
|
|
52
|
+
summaryTokens: row.summary_tokens,
|
|
53
|
+
summary: row.summary,
|
|
54
|
+
previewFirst: this.storage.getTaskPreview(row.first_task_id, 200),
|
|
55
|
+
previewMid: this.storage.getTaskPreview(row.mid_task_id, 200),
|
|
56
|
+
previewLast: this.storage.getTaskPreview(row.last_task_id, 200),
|
|
57
|
+
createdAt: row.created_at,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
validateId(id) {
|
|
61
|
+
if (!ID_PATTERN.test(id)) {
|
|
62
|
+
throw new Error(`Invalid ID format: ${id}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
generateBoxId() {
|
|
66
|
+
return generateId('box');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=box.service.js.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* buildContext() — builds hot/warm context windows from thread messages and box summaries.
|
|
3
|
+
*/
|
|
4
|
+
export function buildContext(threadId, taskReader, boxService, params, tokenizer) {
|
|
5
|
+
const { maxTokens, hotzoneRatio, warmzoneRatio } = params;
|
|
6
|
+
const hotBudget = maxTokens * hotzoneRatio;
|
|
7
|
+
const warmBudget = maxTokens * warmzoneRatio;
|
|
8
|
+
const totalBudget = hotBudget + warmBudget;
|
|
9
|
+
const tasks = taskReader.getThreadMessages(threadId);
|
|
10
|
+
const hotMessages = [];
|
|
11
|
+
let hotTokens = 0;
|
|
12
|
+
let hotOverflow = false;
|
|
13
|
+
const taskPairs = [];
|
|
14
|
+
for (let i = 0; i < tasks.length; i += 2) {
|
|
15
|
+
const userMsg = tasks[i];
|
|
16
|
+
const assistantMsg = tasks[i + 1];
|
|
17
|
+
const prompt = userMsg?.content || '';
|
|
18
|
+
const result = assistantMsg?.content || '';
|
|
19
|
+
const tokens = tokenizer.countTokens(prompt + result);
|
|
20
|
+
const msgs = [];
|
|
21
|
+
if (userMsg)
|
|
22
|
+
msgs.push(userMsg);
|
|
23
|
+
if (assistantMsg)
|
|
24
|
+
msgs.push(assistantMsg);
|
|
25
|
+
taskPairs.push({ messages: msgs, tokens });
|
|
26
|
+
}
|
|
27
|
+
for (let i = taskPairs.length - 1; i >= 0; i--) {
|
|
28
|
+
const pair = taskPairs[i];
|
|
29
|
+
if (hotTokens + pair.tokens > hotBudget) {
|
|
30
|
+
hotOverflow = true;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
hotTokens += pair.tokens;
|
|
34
|
+
hotMessages.unshift(...pair.messages);
|
|
35
|
+
}
|
|
36
|
+
const warmBoxes = [];
|
|
37
|
+
let warmTokens = 0;
|
|
38
|
+
if (hotOverflow && warmBudget > 0) {
|
|
39
|
+
try {
|
|
40
|
+
const { boxes } = boxService.listBoxes(threadId);
|
|
41
|
+
for (let i = boxes.length - 1; i >= 0; i--) {
|
|
42
|
+
const box = boxes[i];
|
|
43
|
+
const tokens = box.summaryTokens ?? box.sourceTokens;
|
|
44
|
+
if (warmTokens + tokens > warmBudget)
|
|
45
|
+
break;
|
|
46
|
+
warmTokens += tokens;
|
|
47
|
+
warmBoxes.unshift({
|
|
48
|
+
boxId: box.id,
|
|
49
|
+
seq: box.seq,
|
|
50
|
+
taskCount: box.taskCount,
|
|
51
|
+
sourceTokens: box.sourceTokens,
|
|
52
|
+
summary: box.summary,
|
|
53
|
+
previewFirst: box.previewFirst,
|
|
54
|
+
previewMid: box.previewMid,
|
|
55
|
+
previewLast: box.previewLast,
|
|
56
|
+
createdAt: box.createdAt,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error instanceof Error && !/not found/i.test(error.message)) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
hot: hotMessages,
|
|
68
|
+
warm: warmBoxes,
|
|
69
|
+
hotTokens,
|
|
70
|
+
warmTokens,
|
|
71
|
+
hotOverflow,
|
|
72
|
+
totalBudget,
|
|
73
|
+
config: { maxTokens, hotzoneRatio, warmzoneRatio },
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=context-builder.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CrewxClient — Browser client for CrewX SDK.
|
|
3
|
+
*
|
|
4
|
+
* Communicates with a server running CrewX SDK via HTTP.
|
|
5
|
+
* Handles the Client-Intercept pattern automatically:
|
|
6
|
+
* registerTool() + query() — that's it.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { CrewxClient } from '@crewx/sdk/client';
|
|
11
|
+
*
|
|
12
|
+
* const crewx = new CrewxClient('http://localhost:3000');
|
|
13
|
+
* crewx.registerTool('browser_storage_read', {
|
|
14
|
+
* execute: async ({ key }) => localStorage.getItem(key),
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const result = await crewx.query('assistant', 'read my settings');
|
|
18
|
+
* console.log(result.data);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export class CrewxClient {
|
|
22
|
+
baseUrl;
|
|
23
|
+
tools = new Map();
|
|
24
|
+
constructor(baseUrl) {
|
|
25
|
+
this.baseUrl = baseUrl.replace(/\/$/, '');
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Register a browser-side tool.
|
|
29
|
+
* When the server agent calls a tool with this name (and no server-side execute),
|
|
30
|
+
* CrewxClient automatically runs it locally and sends the result back.
|
|
31
|
+
*/
|
|
32
|
+
registerTool(name, definition) {
|
|
33
|
+
this.tools.set(name, definition);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Send a message to an agent.
|
|
37
|
+
* The requires_action loop is handled automatically — if the agent calls a
|
|
38
|
+
* client tool, CrewxClient executes it locally and continues the conversation.
|
|
39
|
+
*/
|
|
40
|
+
async query(agent, message, callbacks) {
|
|
41
|
+
let response = await this._post('/api/chat', { agent, message });
|
|
42
|
+
while (response.status === 'requires_action') {
|
|
43
|
+
const { toolCall, threadId } = response;
|
|
44
|
+
if (!toolCall)
|
|
45
|
+
break;
|
|
46
|
+
const tool = this.tools.get(toolCall.toolName);
|
|
47
|
+
if (callbacks?.onToolCall) {
|
|
48
|
+
callbacks.onToolCall(toolCall);
|
|
49
|
+
}
|
|
50
|
+
let toolResult;
|
|
51
|
+
if (tool?.execute) {
|
|
52
|
+
try {
|
|
53
|
+
const raw = await tool.execute(toolCall.args);
|
|
54
|
+
toolResult = typeof raw === 'string' ? raw : JSON.stringify(raw);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
toolResult = `Error: ${err.message}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
toolResult = `Error: No client handler for tool "${toolCall.toolName}"`;
|
|
62
|
+
}
|
|
63
|
+
response = await this._post('/api/chat/continue', {
|
|
64
|
+
threadId,
|
|
65
|
+
toolCallId: toolCall.toolCallId,
|
|
66
|
+
result: toolResult,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return response;
|
|
70
|
+
}
|
|
71
|
+
async _post(path, body) {
|
|
72
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: { 'Content-Type': 'application/json' },
|
|
75
|
+
body: JSON.stringify(body),
|
|
76
|
+
});
|
|
77
|
+
if (!res.ok)
|
|
78
|
+
throw new Error(`HTTP ${res.status}`);
|
|
79
|
+
return res.json();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=CrewxClient.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe YAML config loader.
|
|
3
|
+
* Only parseYamlContent — no file I/O.
|
|
4
|
+
*/
|
|
5
|
+
import { load as loadYaml } from 'js-yaml';
|
|
6
|
+
import { CrewxProjectConfigSchema } from '../types/index.js';
|
|
7
|
+
export class ConfigLoadError extends Error {
|
|
8
|
+
cause;
|
|
9
|
+
constructor(message, cause) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.cause = cause;
|
|
12
|
+
this.name = 'ConfigLoadError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Parse YAML string into a validated CrewxProjectConfig.
|
|
17
|
+
*/
|
|
18
|
+
export function parseYamlContent(yamlString) {
|
|
19
|
+
if (!yamlString || typeof yamlString !== 'string' || !yamlString.trim()) {
|
|
20
|
+
throw new ConfigLoadError('YAML content must be a non-empty string');
|
|
21
|
+
}
|
|
22
|
+
let raw;
|
|
23
|
+
try {
|
|
24
|
+
raw = loadYaml(yamlString);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
throw new ConfigLoadError(`YAML parse error: ${err.message}`, err);
|
|
28
|
+
}
|
|
29
|
+
const normalized = normalizeRaw(raw);
|
|
30
|
+
const result = CrewxProjectConfigSchema.safeParse(normalized);
|
|
31
|
+
if (!result.success) {
|
|
32
|
+
throw new ConfigLoadError(`Config validation error: ${result.error.message}`);
|
|
33
|
+
}
|
|
34
|
+
return result.data;
|
|
35
|
+
}
|
|
36
|
+
function normalizeRaw(raw) {
|
|
37
|
+
if (!raw || typeof raw !== 'object') {
|
|
38
|
+
return { agents: [] };
|
|
39
|
+
}
|
|
40
|
+
const obj = raw;
|
|
41
|
+
if (obj.agents && typeof obj.agents === 'object' && !Array.isArray(obj.agents)) {
|
|
42
|
+
const agentsMap = obj.agents;
|
|
43
|
+
const agentsArray = Object.entries(agentsMap).map(([id, cfg]) => {
|
|
44
|
+
const agentCfg = (cfg && typeof cfg === 'object' ? cfg : {});
|
|
45
|
+
return { id, ...agentCfg };
|
|
46
|
+
});
|
|
47
|
+
return { ...obj, agents: agentsArray };
|
|
48
|
+
}
|
|
49
|
+
if (!obj.agents) {
|
|
50
|
+
return { ...obj, agents: [] };
|
|
51
|
+
}
|
|
52
|
+
return obj;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=loader.browser.js.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML configuration loader for CrewX projects.
|
|
3
|
+
* Reads crewx.yaml and validates it with Zod schema.
|
|
4
|
+
*/
|
|
5
|
+
import { load as loadYaml } from 'js-yaml';
|
|
6
|
+
import { readFileSync } from 'fs';
|
|
7
|
+
import { CrewxProjectConfigSchema } from '../types';
|
|
8
|
+
export class ConfigLoadError extends Error {
|
|
9
|
+
cause;
|
|
10
|
+
constructor(message, cause) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.cause = cause;
|
|
13
|
+
this.name = 'ConfigLoadError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parse YAML string into a validated CrewxProjectConfig.
|
|
18
|
+
* Converts the agents record (keyed by id) into an array.
|
|
19
|
+
*/
|
|
20
|
+
export function parseYamlContent(yamlString) {
|
|
21
|
+
if (!yamlString || typeof yamlString !== 'string' || !yamlString.trim()) {
|
|
22
|
+
throw new ConfigLoadError('YAML content must be a non-empty string');
|
|
23
|
+
}
|
|
24
|
+
let raw;
|
|
25
|
+
try {
|
|
26
|
+
raw = loadYaml(yamlString);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
throw new ConfigLoadError(`YAML parse error: ${err.message}`, err);
|
|
30
|
+
}
|
|
31
|
+
// Normalize agents: YAML has agents as a map (Record<id, config>),
|
|
32
|
+
// but our type uses an array with 'id' field.
|
|
33
|
+
const normalized = normalizeRaw(raw);
|
|
34
|
+
const result = CrewxProjectConfigSchema.safeParse(normalized);
|
|
35
|
+
if (!result.success) {
|
|
36
|
+
throw new ConfigLoadError(`Config validation error: ${result.error.message}`);
|
|
37
|
+
}
|
|
38
|
+
return result.data;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Load and parse crewx.yaml from a file path.
|
|
42
|
+
*/
|
|
43
|
+
export function loadYamlFile(filePath) {
|
|
44
|
+
let content;
|
|
45
|
+
try {
|
|
46
|
+
content = readFileSync(filePath, 'utf-8');
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
throw new ConfigLoadError(`Cannot read file: ${filePath}`, err);
|
|
50
|
+
}
|
|
51
|
+
return parseYamlContent(content);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Normalize raw YAML output:
|
|
55
|
+
* - agents map (Record<id, agentConfig>) → agents array ([{ id, ...agentConfig }])
|
|
56
|
+
*/
|
|
57
|
+
function normalizeRaw(raw) {
|
|
58
|
+
if (!raw || typeof raw !== 'object') {
|
|
59
|
+
return { agents: [] };
|
|
60
|
+
}
|
|
61
|
+
const obj = raw;
|
|
62
|
+
// Convert agents map to array
|
|
63
|
+
if (obj.agents && typeof obj.agents === 'object' && !Array.isArray(obj.agents)) {
|
|
64
|
+
const agentsMap = obj.agents;
|
|
65
|
+
const agentsArray = Object.entries(agentsMap).map(([id, cfg]) => {
|
|
66
|
+
const agentCfg = (cfg && typeof cfg === 'object' ? cfg : {});
|
|
67
|
+
return { id, ...agentCfg };
|
|
68
|
+
});
|
|
69
|
+
return { ...obj, agents: agentsArray };
|
|
70
|
+
}
|
|
71
|
+
// agents already array or absent
|
|
72
|
+
if (!obj.agents) {
|
|
73
|
+
return { ...obj, agents: [] };
|
|
74
|
+
}
|
|
75
|
+
return obj;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypedEventEmitter — typed wrapper around Node's EventEmitter.
|
|
3
|
+
*
|
|
4
|
+
* Design:
|
|
5
|
+
* - `on` / `once` are public (callers subscribe)
|
|
6
|
+
* - `emit` is protected (only subclasses like Crewx can emit)
|
|
7
|
+
* - Async listeners are supported (fire-and-forget, errors isolated)
|
|
8
|
+
* - Returns an UnsubscribeFn from on/once for easy cleanup
|
|
9
|
+
*/
|
|
10
|
+
import { EventEmitter } from 'events';
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a listener to isolate errors and support async fire-and-forget.
|
|
13
|
+
*/
|
|
14
|
+
function makeSafeListener(event, listener) {
|
|
15
|
+
return (payload) => {
|
|
16
|
+
try {
|
|
17
|
+
const result = listener(payload);
|
|
18
|
+
if (result instanceof Promise) {
|
|
19
|
+
result.catch((err) => {
|
|
20
|
+
// Fire-and-forget: isolate async listener errors
|
|
21
|
+
console.error(`[crewx] event listener error (${event}): ${err instanceof Error ? err.message : String(err)}`);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
// Synchronous listener error — log and continue
|
|
27
|
+
console.error(`[crewx] event listener error (${event}): ${err instanceof Error ? err.message : String(err)}`);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export class TypedEventEmitter {
|
|
32
|
+
_emitter = new EventEmitter();
|
|
33
|
+
/**
|
|
34
|
+
* Subscribe to an event. Returns an unsubscribe function.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const unsub = crewx.on('task:start', (e) => console.log(e.agentRef));
|
|
38
|
+
* // later:
|
|
39
|
+
* unsub();
|
|
40
|
+
*/
|
|
41
|
+
on(event, listener) {
|
|
42
|
+
const safeListener = makeSafeListener(event, listener);
|
|
43
|
+
this._emitter.on(event, safeListener);
|
|
44
|
+
return () => this._emitter.off(event, safeListener);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Subscribe to an event exactly once.
|
|
48
|
+
*/
|
|
49
|
+
once(event, listener) {
|
|
50
|
+
const safeListener = makeSafeListener(event, listener);
|
|
51
|
+
this._emitter.once(event, safeListener);
|
|
52
|
+
return () => this._emitter.off(event, safeListener);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Emit an event with payload. Only accessible to subclasses.
|
|
56
|
+
*/
|
|
57
|
+
emit(event, payload) {
|
|
58
|
+
this._emitter.emit(event, payload);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=TypedEventEmitter.js.map
|