@tianshu-ai/tianshu 0.3.0
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/LICENSE +200 -0
- package/README.md +284 -0
- package/README.zh-CN.md +136 -0
- package/bin/tianshu.mjs +32 -0
- package/package.json +60 -0
- package/packages/plugin-sdk/dist/agent-loop.d.ts +96 -0
- package/packages/plugin-sdk/dist/agent-loop.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/agent-loop.js +11 -0
- package/packages/plugin-sdk/dist/agent-loop.js.map +1 -0
- package/packages/plugin-sdk/dist/capabilities.d.ts +48 -0
- package/packages/plugin-sdk/dist/capabilities.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/capabilities.js +61 -0
- package/packages/plugin-sdk/dist/capabilities.js.map +1 -0
- package/packages/plugin-sdk/dist/catalog.d.ts +60 -0
- package/packages/plugin-sdk/dist/catalog.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/catalog.js +11 -0
- package/packages/plugin-sdk/dist/catalog.js.map +1 -0
- package/packages/plugin-sdk/dist/client.d.ts +171 -0
- package/packages/plugin-sdk/dist/client.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/client.js +96 -0
- package/packages/plugin-sdk/dist/client.js.map +1 -0
- package/packages/plugin-sdk/dist/index.d.ts +9 -0
- package/packages/plugin-sdk/dist/index.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/index.js +19 -0
- package/packages/plugin-sdk/dist/index.js.map +1 -0
- package/packages/plugin-sdk/dist/lsp.d.ts +32 -0
- package/packages/plugin-sdk/dist/lsp.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/lsp.js +19 -0
- package/packages/plugin-sdk/dist/lsp.js.map +1 -0
- package/packages/plugin-sdk/dist/manifest.d.ts +423 -0
- package/packages/plugin-sdk/dist/manifest.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/manifest.js +7 -0
- package/packages/plugin-sdk/dist/manifest.js.map +1 -0
- package/packages/plugin-sdk/dist/mcp-client.d.ts +74 -0
- package/packages/plugin-sdk/dist/mcp-client.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/mcp-client.js +226 -0
- package/packages/plugin-sdk/dist/mcp-client.js.map +1 -0
- package/packages/plugin-sdk/dist/mcp-fetch.d.ts +10 -0
- package/packages/plugin-sdk/dist/mcp-fetch.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/mcp-fetch.js +130 -0
- package/packages/plugin-sdk/dist/mcp-fetch.js.map +1 -0
- package/packages/plugin-sdk/dist/mcp-toolset.d.ts +128 -0
- package/packages/plugin-sdk/dist/mcp-toolset.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/mcp-toolset.js +246 -0
- package/packages/plugin-sdk/dist/mcp-toolset.js.map +1 -0
- package/packages/plugin-sdk/dist/server.d.ts +486 -0
- package/packages/plugin-sdk/dist/server.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/server.js +10 -0
- package/packages/plugin-sdk/dist/server.js.map +1 -0
- package/packages/plugin-sdk/dist/session-inbox.d.ts +56 -0
- package/packages/plugin-sdk/dist/session-inbox.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/session-inbox.js +12 -0
- package/packages/plugin-sdk/dist/session-inbox.js.map +1 -0
- package/packages/plugin-sdk/package.json +36 -0
- package/packages/server/builtinConfig/plugins/README.md +1 -0
- package/packages/server/builtinConfig/plugins/files/manifest.json +100 -0
- package/packages/server/builtinConfig/plugins/files/skills/files-workspace-layout.md +29 -0
- package/packages/server/builtinConfig/plugins/microsandbox/manifest.json +177 -0
- package/packages/server/builtinConfig/plugins/microsandbox/skills/microsandbox-browser-howto.md +155 -0
- package/packages/server/builtinConfig/plugins/microsandbox/skills/microsandbox-build-use.md +201 -0
- package/packages/server/builtinConfig/plugins/microsandbox/skills/microsandbox-config.md +38 -0
- package/packages/server/builtinConfig/plugins/microsandbox/skills/microsandbox-exec-howto.md +144 -0
- package/packages/server/builtinConfig/plugins/microsandbox/skills/microsandbox-libreoffice.md +159 -0
- package/packages/server/builtinConfig/plugins/microsandbox/skills/microsandbox-main-orchestration.md +75 -0
- package/packages/server/builtinConfig/plugins/microsandbox/templates/README.md +26 -0
- package/packages/server/builtinConfig/plugins/microsandbox/templates/browser.yaml +105 -0
- package/packages/server/builtinConfig/plugins/microsandbox/templates/task-runner-with-browser.yaml +80 -0
- package/packages/server/builtinConfig/plugins/microsandbox/templates/task-runner.yaml +80 -0
- package/packages/server/builtinConfig/plugins/web-search/manifest.json +65 -0
- package/packages/server/builtinConfig/plugins/web-search/skills/web-search-howto.md +69 -0
- package/packages/server/builtinConfig/plugins/workboard/agent-seeds/echo-demo/agent.json +7 -0
- package/packages/server/builtinConfig/plugins/workboard/agent-seeds/llm-default/SOUL.md +53 -0
- package/packages/server/builtinConfig/plugins/workboard/agent-seeds/llm-default/agent.json +7 -0
- package/packages/server/builtinConfig/plugins/workboard/manifest.json +180 -0
- package/packages/server/builtinConfig/plugins/workboard/skills/large-input-large-output.md +185 -0
- package/packages/server/builtinConfig/plugins/workboard/skills/workboard-howto.md +166 -0
- package/packages/server/builtinConfig/plugins/workboard/skills/worker-creator.md +267 -0
- package/packages/server/builtinConfig/plugins/workboard/skills/worker-fleet.md +431 -0
- package/packages/server/dist/catalog.d.ts +52 -0
- package/packages/server/dist/catalog.d.ts.map +1 -0
- package/packages/server/dist/catalog.js +189 -0
- package/packages/server/dist/catalog.js.map +1 -0
- package/packages/server/dist/chat/active-harnesses.d.ts +34 -0
- package/packages/server/dist/chat/active-harnesses.d.ts.map +1 -0
- package/packages/server/dist/chat/active-harnesses.js +118 -0
- package/packages/server/dist/chat/active-harnesses.js.map +1 -0
- package/packages/server/dist/chat/agent-loop.d.ts +64 -0
- package/packages/server/dist/chat/agent-loop.d.ts.map +1 -0
- package/packages/server/dist/chat/agent-loop.js +597 -0
- package/packages/server/dist/chat/agent-loop.js.map +1 -0
- package/packages/server/dist/chat/agent-tool-adapter.d.ts +33 -0
- package/packages/server/dist/chat/agent-tool-adapter.d.ts.map +1 -0
- package/packages/server/dist/chat/agent-tool-adapter.js +260 -0
- package/packages/server/dist/chat/agent-tool-adapter.js.map +1 -0
- package/packages/server/dist/chat/compact.d.ts +52 -0
- package/packages/server/dist/chat/compact.d.ts.map +1 -0
- package/packages/server/dist/chat/compact.js +248 -0
- package/packages/server/dist/chat/compact.js.map +1 -0
- package/packages/server/dist/chat/dump-system-prompt.d.ts +17 -0
- package/packages/server/dist/chat/dump-system-prompt.d.ts.map +1 -0
- package/packages/server/dist/chat/dump-system-prompt.js +58 -0
- package/packages/server/dist/chat/dump-system-prompt.js.map +1 -0
- package/packages/server/dist/chat/handler.d.ts +186 -0
- package/packages/server/dist/chat/handler.d.ts.map +1 -0
- package/packages/server/dist/chat/handler.js +1248 -0
- package/packages/server/dist/chat/handler.js.map +1 -0
- package/packages/server/dist/chat/image-fit.d.ts +34 -0
- package/packages/server/dist/chat/image-fit.d.ts.map +1 -0
- package/packages/server/dist/chat/image-fit.js +157 -0
- package/packages/server/dist/chat/image-fit.js.map +1 -0
- package/packages/server/dist/chat/messages.d.ts +118 -0
- package/packages/server/dist/chat/messages.d.ts.map +1 -0
- package/packages/server/dist/chat/messages.js +341 -0
- package/packages/server/dist/chat/messages.js.map +1 -0
- package/packages/server/dist/chat/session-inbox.d.ts +114 -0
- package/packages/server/dist/chat/session-inbox.d.ts.map +1 -0
- package/packages/server/dist/chat/session-inbox.js +418 -0
- package/packages/server/dist/chat/session-inbox.js.map +1 -0
- package/packages/server/dist/chat/sqlite-session-repo.d.ts +26 -0
- package/packages/server/dist/chat/sqlite-session-repo.d.ts.map +1 -0
- package/packages/server/dist/chat/sqlite-session-repo.js +132 -0
- package/packages/server/dist/chat/sqlite-session-repo.js.map +1 -0
- package/packages/server/dist/chat/sqlite-session-storage.d.ts +83 -0
- package/packages/server/dist/chat/sqlite-session-storage.d.ts.map +1 -0
- package/packages/server/dist/chat/sqlite-session-storage.js +418 -0
- package/packages/server/dist/chat/sqlite-session-storage.js.map +1 -0
- package/packages/server/dist/chat/stub-execution-env.d.ts +3 -0
- package/packages/server/dist/chat/stub-execution-env.d.ts.map +1 -0
- package/packages/server/dist/chat/stub-execution-env.js +87 -0
- package/packages/server/dist/chat/stub-execution-env.js.map +1 -0
- package/packages/server/dist/chat/token-estimate.d.ts +11 -0
- package/packages/server/dist/chat/token-estimate.d.ts.map +1 -0
- package/packages/server/dist/chat/token-estimate.js +67 -0
- package/packages/server/dist/chat/token-estimate.js.map +1 -0
- package/packages/server/dist/chat/ws-protocol.d.ts +244 -0
- package/packages/server/dist/chat/ws-protocol.d.ts.map +1 -0
- package/packages/server/dist/chat/ws-protocol.js +193 -0
- package/packages/server/dist/chat/ws-protocol.js.map +1 -0
- package/packages/server/dist/cli.d.ts +9 -0
- package/packages/server/dist/cli.d.ts.map +1 -0
- package/packages/server/dist/cli.js +329 -0
- package/packages/server/dist/cli.js.map +1 -0
- package/packages/server/dist/core/agent-seeds.d.ts +25 -0
- package/packages/server/dist/core/agent-seeds.d.ts.map +1 -0
- package/packages/server/dist/core/agent-seeds.js +69 -0
- package/packages/server/dist/core/agent-seeds.js.map +1 -0
- package/packages/server/dist/core/config.d.ts +172 -0
- package/packages/server/dist/core/config.d.ts.map +1 -0
- package/packages/server/dist/core/config.js +155 -0
- package/packages/server/dist/core/config.js.map +1 -0
- package/packages/server/dist/core/db-pool.d.ts +32 -0
- package/packages/server/dist/core/db-pool.d.ts.map +1 -0
- package/packages/server/dist/core/db-pool.js +108 -0
- package/packages/server/dist/core/db-pool.js.map +1 -0
- package/packages/server/dist/core/dev-mode.d.ts +13 -0
- package/packages/server/dist/core/dev-mode.d.ts.map +1 -0
- package/packages/server/dist/core/dev-mode.js +51 -0
- package/packages/server/dist/core/dev-mode.js.map +1 -0
- package/packages/server/dist/core/global-ops.d.ts +54 -0
- package/packages/server/dist/core/global-ops.d.ts.map +1 -0
- package/packages/server/dist/core/global-ops.js +143 -0
- package/packages/server/dist/core/global-ops.js.map +1 -0
- package/packages/server/dist/core/identity-resolvers.d.ts +102 -0
- package/packages/server/dist/core/identity-resolvers.d.ts.map +1 -0
- package/packages/server/dist/core/identity-resolvers.js +176 -0
- package/packages/server/dist/core/identity-resolvers.js.map +1 -0
- package/packages/server/dist/core/index.d.ts +13 -0
- package/packages/server/dist/core/index.d.ts.map +1 -0
- package/packages/server/dist/core/index.js +18 -0
- package/packages/server/dist/core/index.js.map +1 -0
- package/packages/server/dist/core/llm.d.ts +45 -0
- package/packages/server/dist/core/llm.d.ts.map +1 -0
- package/packages/server/dist/core/llm.js +140 -0
- package/packages/server/dist/core/llm.js.map +1 -0
- package/packages/server/dist/core/mcp-manager.d.ts +47 -0
- package/packages/server/dist/core/mcp-manager.d.ts.map +1 -0
- package/packages/server/dist/core/mcp-manager.js +129 -0
- package/packages/server/dist/core/mcp-manager.js.map +1 -0
- package/packages/server/dist/core/middleware.d.ts +31 -0
- package/packages/server/dist/core/middleware.d.ts.map +1 -0
- package/packages/server/dist/core/middleware.js +102 -0
- package/packages/server/dist/core/middleware.js.map +1 -0
- package/packages/server/dist/core/migrations/001-initial.d.ts +4 -0
- package/packages/server/dist/core/migrations/001-initial.d.ts.map +1 -0
- package/packages/server/dist/core/migrations/001-initial.js +66 -0
- package/packages/server/dist/core/migrations/001-initial.js.map +1 -0
- package/packages/server/dist/core/migrations/002-task-dependencies.d.ts +4 -0
- package/packages/server/dist/core/migrations/002-task-dependencies.d.ts.map +1 -0
- package/packages/server/dist/core/migrations/002-task-dependencies.js +20 -0
- package/packages/server/dist/core/migrations/002-task-dependencies.js.map +1 -0
- package/packages/server/dist/core/migrations/003-session-tree.d.ts +4 -0
- package/packages/server/dist/core/migrations/003-session-tree.d.ts.map +1 -0
- package/packages/server/dist/core/migrations/003-session-tree.js +96 -0
- package/packages/server/dist/core/migrations/003-session-tree.js.map +1 -0
- package/packages/server/dist/core/migrations/003-worker-agents.d.ts +4 -0
- package/packages/server/dist/core/migrations/003-worker-agents.d.ts.map +1 -0
- package/packages/server/dist/core/migrations/003-worker-agents.js +65 -0
- package/packages/server/dist/core/migrations/003-worker-agents.js.map +1 -0
- package/packages/server/dist/core/migrations/004-rebuild-message-chain.d.ts +4 -0
- package/packages/server/dist/core/migrations/004-rebuild-message-chain.d.ts.map +1 -0
- package/packages/server/dist/core/migrations/004-rebuild-message-chain.js +52 -0
- package/packages/server/dist/core/migrations/004-rebuild-message-chain.js.map +1 -0
- package/packages/server/dist/core/migrations/005-task-status-rename.d.ts +4 -0
- package/packages/server/dist/core/migrations/005-task-status-rename.d.ts.map +1 -0
- package/packages/server/dist/core/migrations/005-task-status-rename.js +64 -0
- package/packages/server/dist/core/migrations/005-task-status-rename.js.map +1 -0
- package/packages/server/dist/core/migrations/006-task-labels.d.ts +4 -0
- package/packages/server/dist/core/migrations/006-task-labels.d.ts.map +1 -0
- package/packages/server/dist/core/migrations/006-task-labels.js +43 -0
- package/packages/server/dist/core/migrations/006-task-labels.js.map +1 -0
- package/packages/server/dist/core/migrations/007-session-inbox.d.ts +4 -0
- package/packages/server/dist/core/migrations/007-session-inbox.d.ts.map +1 -0
- package/packages/server/dist/core/migrations/007-session-inbox.js +67 -0
- package/packages/server/dist/core/migrations/007-session-inbox.js.map +1 -0
- package/packages/server/dist/core/migrations/008-task-intervention.d.ts +4 -0
- package/packages/server/dist/core/migrations/008-task-intervention.d.ts.map +1 -0
- package/packages/server/dist/core/migrations/008-task-intervention.js +60 -0
- package/packages/server/dist/core/migrations/008-task-intervention.js.map +1 -0
- package/packages/server/dist/core/migrations/index.d.ts +12 -0
- package/packages/server/dist/core/migrations/index.d.ts.map +1 -0
- package/packages/server/dist/core/migrations/index.js +58 -0
- package/packages/server/dist/core/migrations/index.js.map +1 -0
- package/packages/server/dist/core/paths.d.ts +53 -0
- package/packages/server/dist/core/paths.d.ts.map +1 -0
- package/packages/server/dist/core/paths.js +125 -0
- package/packages/server/dist/core/paths.js.map +1 -0
- package/packages/server/dist/core/plugins/builtin-loader.d.ts +56 -0
- package/packages/server/dist/core/plugins/builtin-loader.d.ts.map +1 -0
- package/packages/server/dist/core/plugins/builtin-loader.js +153 -0
- package/packages/server/dist/core/plugins/builtin-loader.js.map +1 -0
- package/packages/server/dist/core/plugins/discovery.d.ts +28 -0
- package/packages/server/dist/core/plugins/discovery.d.ts.map +1 -0
- package/packages/server/dist/core/plugins/discovery.js +97 -0
- package/packages/server/dist/core/plugins/discovery.js.map +1 -0
- package/packages/server/dist/core/plugins/index.d.ts +6 -0
- package/packages/server/dist/core/plugins/index.d.ts.map +1 -0
- package/packages/server/dist/core/plugins/index.js +6 -0
- package/packages/server/dist/core/plugins/index.js.map +1 -0
- package/packages/server/dist/core/plugins/manifest.d.ts +9 -0
- package/packages/server/dist/core/plugins/manifest.d.ts.map +1 -0
- package/packages/server/dist/core/plugins/manifest.js +584 -0
- package/packages/server/dist/core/plugins/manifest.js.map +1 -0
- package/packages/server/dist/core/plugins/registry.d.ts +269 -0
- package/packages/server/dist/core/plugins/registry.d.ts.map +1 -0
- package/packages/server/dist/core/plugins/registry.js +1003 -0
- package/packages/server/dist/core/plugins/registry.js.map +1 -0
- package/packages/server/dist/core/plugins/secrets.d.ts +46 -0
- package/packages/server/dist/core/plugins/secrets.d.ts.map +1 -0
- package/packages/server/dist/core/plugins/secrets.js +174 -0
- package/packages/server/dist/core/plugins/secrets.js.map +1 -0
- package/packages/server/dist/core/plugins/skills.d.ts +131 -0
- package/packages/server/dist/core/plugins/skills.d.ts.map +1 -0
- package/packages/server/dist/core/plugins/skills.js +389 -0
- package/packages/server/dist/core/plugins/skills.js.map +1 -0
- package/packages/server/dist/core/templates.d.ts +28 -0
- package/packages/server/dist/core/templates.d.ts.map +1 -0
- package/packages/server/dist/core/templates.js +103 -0
- package/packages/server/dist/core/templates.js.map +1 -0
- package/packages/server/dist/core/tenant-context.d.ts +18 -0
- package/packages/server/dist/core/tenant-context.d.ts.map +1 -0
- package/packages/server/dist/core/tenant-context.js +42 -0
- package/packages/server/dist/core/tenant-context.js.map +1 -0
- package/packages/server/dist/core/tenant-id.d.ts +8 -0
- package/packages/server/dist/core/tenant-id.d.ts.map +1 -0
- package/packages/server/dist/core/tenant-id.js +53 -0
- package/packages/server/dist/core/tenant-id.js.map +1 -0
- package/packages/server/dist/core/tenant-skills.d.ts +29 -0
- package/packages/server/dist/core/tenant-skills.d.ts.map +1 -0
- package/packages/server/dist/core/tenant-skills.js +77 -0
- package/packages/server/dist/core/tenant-skills.js.map +1 -0
- package/packages/server/dist/core/worker-agents-fs.d.ts +44 -0
- package/packages/server/dist/core/worker-agents-fs.d.ts.map +1 -0
- package/packages/server/dist/core/worker-agents-fs.js +86 -0
- package/packages/server/dist/core/worker-agents-fs.js.map +1 -0
- package/packages/server/dist/core/worker-agents.d.ts +77 -0
- package/packages/server/dist/core/worker-agents.d.ts.map +1 -0
- package/packages/server/dist/core/worker-agents.js +191 -0
- package/packages/server/dist/core/worker-agents.js.map +1 -0
- package/packages/server/dist/index.d.ts +2 -0
- package/packages/server/dist/index.d.ts.map +1 -0
- package/packages/server/dist/index.js +623 -0
- package/packages/server/dist/index.js.map +1 -0
- package/packages/server/dist/lsp/client.d.ts +53 -0
- package/packages/server/dist/lsp/client.d.ts.map +1 -0
- package/packages/server/dist/lsp/client.js +258 -0
- package/packages/server/dist/lsp/client.js.map +1 -0
- package/packages/server/dist/lsp/format.d.ts +13 -0
- package/packages/server/dist/lsp/format.d.ts.map +1 -0
- package/packages/server/dist/lsp/format.js +55 -0
- package/packages/server/dist/lsp/format.js.map +1 -0
- package/packages/server/dist/lsp/index.d.ts +20 -0
- package/packages/server/dist/lsp/index.d.ts.map +1 -0
- package/packages/server/dist/lsp/index.js +32 -0
- package/packages/server/dist/lsp/index.js.map +1 -0
- package/packages/server/dist/lsp/language-registry.d.ts +29 -0
- package/packages/server/dist/lsp/language-registry.d.ts.map +1 -0
- package/packages/server/dist/lsp/language-registry.js +62 -0
- package/packages/server/dist/lsp/language-registry.js.map +1 -0
- package/packages/server/dist/lsp/manager.d.ts +77 -0
- package/packages/server/dist/lsp/manager.d.ts.map +1 -0
- package/packages/server/dist/lsp/manager.js +300 -0
- package/packages/server/dist/lsp/manager.js.map +1 -0
- package/packages/server/dist/plugins-routes.d.ts +96 -0
- package/packages/server/dist/plugins-routes.d.ts.map +1 -0
- package/packages/server/dist/plugins-routes.js +627 -0
- package/packages/server/dist/plugins-routes.js.map +1 -0
- package/packages/server/dist/setup/checks/config.d.ts +9 -0
- package/packages/server/dist/setup/checks/config.d.ts.map +1 -0
- package/packages/server/dist/setup/checks/config.js +66 -0
- package/packages/server/dist/setup/checks/config.js.map +1 -0
- package/packages/server/dist/setup/checks/db.d.ts +6 -0
- package/packages/server/dist/setup/checks/db.d.ts.map +1 -0
- package/packages/server/dist/setup/checks/db.js +79 -0
- package/packages/server/dist/setup/checks/db.js.map +1 -0
- package/packages/server/dist/setup/checks/known-models.d.ts +18 -0
- package/packages/server/dist/setup/checks/known-models.d.ts.map +1 -0
- package/packages/server/dist/setup/checks/known-models.js +119 -0
- package/packages/server/dist/setup/checks/known-models.js.map +1 -0
- package/packages/server/dist/setup/checks/network.d.ts +11 -0
- package/packages/server/dist/setup/checks/network.d.ts.map +1 -0
- package/packages/server/dist/setup/checks/network.js +176 -0
- package/packages/server/dist/setup/checks/network.js.map +1 -0
- package/packages/server/dist/setup/checks/plugins.d.ts +9 -0
- package/packages/server/dist/setup/checks/plugins.d.ts.map +1 -0
- package/packages/server/dist/setup/checks/plugins.js +194 -0
- package/packages/server/dist/setup/checks/plugins.js.map +1 -0
- package/packages/server/dist/setup/checks/providers.d.ts +12 -0
- package/packages/server/dist/setup/checks/providers.d.ts.map +1 -0
- package/packages/server/dist/setup/checks/providers.js +368 -0
- package/packages/server/dist/setup/checks/providers.js.map +1 -0
- package/packages/server/dist/setup/checks/runtime.d.ts +3 -0
- package/packages/server/dist/setup/checks/runtime.d.ts.map +1 -0
- package/packages/server/dist/setup/checks/runtime.js +44 -0
- package/packages/server/dist/setup/checks/runtime.js.map +1 -0
- package/packages/server/dist/setup/checks/sandbox.d.ts +9 -0
- package/packages/server/dist/setup/checks/sandbox.d.ts.map +1 -0
- package/packages/server/dist/setup/checks/sandbox.js +110 -0
- package/packages/server/dist/setup/checks/sandbox.js.map +1 -0
- package/packages/server/dist/setup/checks/tenants.d.ts +9 -0
- package/packages/server/dist/setup/checks/tenants.d.ts.map +1 -0
- package/packages/server/dist/setup/checks/tenants.js +509 -0
- package/packages/server/dist/setup/checks/tenants.js.map +1 -0
- package/packages/server/dist/setup/cli-agent.d.ts +39 -0
- package/packages/server/dist/setup/cli-agent.d.ts.map +1 -0
- package/packages/server/dist/setup/cli-agent.js +1353 -0
- package/packages/server/dist/setup/cli-agent.js.map +1 -0
- package/packages/server/dist/setup/doctor.d.ts +32 -0
- package/packages/server/dist/setup/doctor.d.ts.map +1 -0
- package/packages/server/dist/setup/doctor.js +80 -0
- package/packages/server/dist/setup/doctor.js.map +1 -0
- package/packages/server/dist/setup/launchd.d.ts +107 -0
- package/packages/server/dist/setup/launchd.d.ts.map +1 -0
- package/packages/server/dist/setup/launchd.js +309 -0
- package/packages/server/dist/setup/launchd.js.map +1 -0
- package/packages/server/dist/setup/load-env.d.ts +21 -0
- package/packages/server/dist/setup/load-env.d.ts.map +1 -0
- package/packages/server/dist/setup/load-env.js +88 -0
- package/packages/server/dist/setup/load-env.js.map +1 -0
- package/packages/server/dist/setup/probe-default-model.d.ts +28 -0
- package/packages/server/dist/setup/probe-default-model.d.ts.map +1 -0
- package/packages/server/dist/setup/probe-default-model.js +133 -0
- package/packages/server/dist/setup/probe-default-model.js.map +1 -0
- package/packages/server/dist/setup/render.d.ts +28 -0
- package/packages/server/dist/setup/render.d.ts.map +1 -0
- package/packages/server/dist/setup/render.js +60 -0
- package/packages/server/dist/setup/render.js.map +1 -0
- package/packages/server/dist/setup/repo-root.d.ts +3 -0
- package/packages/server/dist/setup/repo-root.d.ts.map +1 -0
- package/packages/server/dist/setup/repo-root.js +43 -0
- package/packages/server/dist/setup/repo-root.js.map +1 -0
- package/packages/server/dist/setup/service.d.ts +60 -0
- package/packages/server/dist/setup/service.d.ts.map +1 -0
- package/packages/server/dist/setup/service.js +345 -0
- package/packages/server/dist/setup/service.js.map +1 -0
- package/packages/server/dist/setup/start-server.d.ts +23 -0
- package/packages/server/dist/setup/start-server.d.ts.map +1 -0
- package/packages/server/dist/setup/start-server.js +465 -0
- package/packages/server/dist/setup/start-server.js.map +1 -0
- package/packages/server/dist/setup/wizard.d.ts +59 -0
- package/packages/server/dist/setup/wizard.d.ts.map +1 -0
- package/packages/server/dist/setup/wizard.js +556 -0
- package/packages/server/dist/setup/wizard.js.map +1 -0
- package/packages/server/dist/tools/edit-file.d.ts +13 -0
- package/packages/server/dist/tools/edit-file.d.ts.map +1 -0
- package/packages/server/dist/tools/edit-file.js +90 -0
- package/packages/server/dist/tools/edit-file.js.map +1 -0
- package/packages/server/dist/tools/glob.d.ts +12 -0
- package/packages/server/dist/tools/glob.d.ts.map +1 -0
- package/packages/server/dist/tools/glob.js +82 -0
- package/packages/server/dist/tools/glob.js.map +1 -0
- package/packages/server/dist/tools/index.d.ts +82 -0
- package/packages/server/dist/tools/index.d.ts.map +1 -0
- package/packages/server/dist/tools/index.js +72 -0
- package/packages/server/dist/tools/index.js.map +1 -0
- package/packages/server/dist/tools/list-dir.d.ts +24 -0
- package/packages/server/dist/tools/list-dir.d.ts.map +1 -0
- package/packages/server/dist/tools/list-dir.js +99 -0
- package/packages/server/dist/tools/list-dir.js.map +1 -0
- package/packages/server/dist/tools/path-helper.d.ts +15 -0
- package/packages/server/dist/tools/path-helper.d.ts.map +1 -0
- package/packages/server/dist/tools/path-helper.js +72 -0
- package/packages/server/dist/tools/path-helper.js.map +1 -0
- package/packages/server/dist/tools/read-file.d.ts +17 -0
- package/packages/server/dist/tools/read-file.d.ts.map +1 -0
- package/packages/server/dist/tools/read-file.js +94 -0
- package/packages/server/dist/tools/read-file.js.map +1 -0
- package/packages/server/dist/tools/sandbox.d.ts +57 -0
- package/packages/server/dist/tools/sandbox.d.ts.map +1 -0
- package/packages/server/dist/tools/sandbox.js +291 -0
- package/packages/server/dist/tools/sandbox.js.map +1 -0
- package/packages/server/dist/tools/write-file.d.ts +12 -0
- package/packages/server/dist/tools/write-file.d.ts.map +1 -0
- package/packages/server/dist/tools/write-file.js +67 -0
- package/packages/server/dist/tools/write-file.js.map +1 -0
- package/packages/server/dist/worker-agents-routes.d.ts +11 -0
- package/packages/server/dist/worker-agents-routes.d.ts.map +1 -0
- package/packages/server/dist/worker-agents-routes.js +253 -0
- package/packages/server/dist/worker-agents-routes.js.map +1 -0
- package/packages/server/package.json +41 -0
- package/packages/web/dist/assets/index-DH-gJ09_.js +60 -0
- package/packages/web/dist/assets/index-xU4lYYqY.css +2 -0
- package/packages/web/dist/index.html +14 -0
- package/packages/web/package.json +36 -0
- package/plugins/README.md +64 -0
- package/plugins/files/dist/client.d.ts +5 -0
- package/plugins/files/dist/client.d.ts.map +1 -0
- package/plugins/files/dist/client.js +354 -0
- package/plugins/files/dist/client.js.map +1 -0
- package/plugins/files/dist/server.d.ts +32 -0
- package/plugins/files/dist/server.d.ts.map +1 -0
- package/plugins/files/dist/server.js +514 -0
- package/plugins/files/dist/server.js.map +1 -0
- package/plugins/files/dist/tools/edit-file.d.ts +29 -0
- package/plugins/files/dist/tools/edit-file.d.ts.map +1 -0
- package/plugins/files/dist/tools/edit-file.js +230 -0
- package/plugins/files/dist/tools/edit-file.js.map +1 -0
- package/plugins/files/dist/tools/edit-file.prompt.md +36 -0
- package/plugins/files/dist/tools/glob.d.ts +12 -0
- package/plugins/files/dist/tools/glob.d.ts.map +1 -0
- package/plugins/files/dist/tools/glob.js +84 -0
- package/plugins/files/dist/tools/glob.js.map +1 -0
- package/plugins/files/dist/tools/index.d.ts +13 -0
- package/plugins/files/dist/tools/index.d.ts.map +1 -0
- package/plugins/files/dist/tools/index.js +158 -0
- package/plugins/files/dist/tools/index.js.map +1 -0
- package/plugins/files/dist/tools/list-dir.d.ts +24 -0
- package/plugins/files/dist/tools/list-dir.d.ts.map +1 -0
- package/plugins/files/dist/tools/list-dir.js +104 -0
- package/plugins/files/dist/tools/list-dir.js.map +1 -0
- package/plugins/files/dist/tools/load-prompt.d.ts +5 -0
- package/plugins/files/dist/tools/load-prompt.d.ts.map +1 -0
- package/plugins/files/dist/tools/load-prompt.js +39 -0
- package/plugins/files/dist/tools/load-prompt.js.map +1 -0
- package/plugins/files/dist/tools/path-helper.d.ts +32 -0
- package/plugins/files/dist/tools/path-helper.d.ts.map +1 -0
- package/plugins/files/dist/tools/path-helper.js +113 -0
- package/plugins/files/dist/tools/path-helper.js.map +1 -0
- package/plugins/files/dist/tools/read-file.d.ts +17 -0
- package/plugins/files/dist/tools/read-file.d.ts.map +1 -0
- package/plugins/files/dist/tools/read-file.js +109 -0
- package/plugins/files/dist/tools/read-file.js.map +1 -0
- package/plugins/files/dist/tools/read-tracker.d.ts +28 -0
- package/plugins/files/dist/tools/read-tracker.d.ts.map +1 -0
- package/plugins/files/dist/tools/read-tracker.js +135 -0
- package/plugins/files/dist/tools/read-tracker.js.map +1 -0
- package/plugins/files/dist/tools/replacers.d.ts +27 -0
- package/plugins/files/dist/tools/replacers.d.ts.map +1 -0
- package/plugins/files/dist/tools/replacers.js +221 -0
- package/plugins/files/dist/tools/replacers.js.map +1 -0
- package/plugins/files/dist/tools/tenant-config-delete.d.ts +12 -0
- package/plugins/files/dist/tools/tenant-config-delete.d.ts.map +1 -0
- package/plugins/files/dist/tools/tenant-config-delete.js +70 -0
- package/plugins/files/dist/tools/tenant-config-delete.js.map +1 -0
- package/plugins/files/dist/tools/tenant-config-edit.d.ts +25 -0
- package/plugins/files/dist/tools/tenant-config-edit.d.ts.map +1 -0
- package/plugins/files/dist/tools/tenant-config-edit.js +142 -0
- package/plugins/files/dist/tools/tenant-config-edit.js.map +1 -0
- package/plugins/files/dist/tools/tenant-config-glob.d.ts +12 -0
- package/plugins/files/dist/tools/tenant-config-glob.d.ts.map +1 -0
- package/plugins/files/dist/tools/tenant-config-glob.js +64 -0
- package/plugins/files/dist/tools/tenant-config-glob.js.map +1 -0
- package/plugins/files/dist/tools/tenant-config-helper.d.ts +64 -0
- package/plugins/files/dist/tools/tenant-config-helper.d.ts.map +1 -0
- package/plugins/files/dist/tools/tenant-config-helper.js +162 -0
- package/plugins/files/dist/tools/tenant-config-helper.js.map +1 -0
- package/plugins/files/dist/tools/tenant-config-list.d.ts +20 -0
- package/plugins/files/dist/tools/tenant-config-list.d.ts.map +1 -0
- package/plugins/files/dist/tools/tenant-config-list.js +95 -0
- package/plugins/files/dist/tools/tenant-config-list.js.map +1 -0
- package/plugins/files/dist/tools/tenant-config-read.d.ts +17 -0
- package/plugins/files/dist/tools/tenant-config-read.d.ts.map +1 -0
- package/plugins/files/dist/tools/tenant-config-read.js +87 -0
- package/plugins/files/dist/tools/tenant-config-read.js.map +1 -0
- package/plugins/files/dist/tools/tenant-config-write.d.ts +14 -0
- package/plugins/files/dist/tools/tenant-config-write.d.ts.map +1 -0
- package/plugins/files/dist/tools/tenant-config-write.js +78 -0
- package/plugins/files/dist/tools/tenant-config-write.js.map +1 -0
- package/plugins/files/dist/tools/text-shape.d.ts +20 -0
- package/plugins/files/dist/tools/text-shape.d.ts.map +1 -0
- package/plugins/files/dist/tools/text-shape.js +57 -0
- package/plugins/files/dist/tools/text-shape.js.map +1 -0
- package/plugins/files/dist/tools/write-file.d.ts +12 -0
- package/plugins/files/dist/tools/write-file.d.ts.map +1 -0
- package/plugins/files/dist/tools/write-file.js +89 -0
- package/plugins/files/dist/tools/write-file.js.map +1 -0
- package/plugins/files/dist/tools/write-file.prompt.md +14 -0
- package/plugins/files/manifest.json +100 -0
- package/plugins/files/package.json +39 -0
- package/plugins/files/skills/files-workspace-layout.md +29 -0
- package/plugins/microsandbox/dist/admin/browser-routes.d.ts +41 -0
- package/plugins/microsandbox/dist/admin/browser-routes.d.ts.map +1 -0
- package/plugins/microsandbox/dist/admin/browser-routes.js +208 -0
- package/plugins/microsandbox/dist/admin/browser-routes.js.map +1 -0
- package/plugins/microsandbox/dist/admin/preview-exec.d.ts +38 -0
- package/plugins/microsandbox/dist/admin/preview-exec.d.ts.map +1 -0
- package/plugins/microsandbox/dist/admin/preview-exec.js +185 -0
- package/plugins/microsandbox/dist/admin/preview-exec.js.map +1 -0
- package/plugins/microsandbox/dist/admin/routes.d.ts +35 -0
- package/plugins/microsandbox/dist/admin/routes.d.ts.map +1 -0
- package/plugins/microsandbox/dist/admin/routes.js +728 -0
- package/plugins/microsandbox/dist/admin/routes.js.map +1 -0
- package/plugins/microsandbox/dist/admin/sandboxfile-io.d.ts +11 -0
- package/plugins/microsandbox/dist/admin/sandboxfile-io.d.ts.map +1 -0
- package/plugins/microsandbox/dist/admin/sandboxfile-io.js +72 -0
- package/plugins/microsandbox/dist/admin/sandboxfile-io.js.map +1 -0
- package/plugins/microsandbox/dist/admin/templates.d.ts +16 -0
- package/plugins/microsandbox/dist/admin/templates.d.ts.map +1 -0
- package/plugins/microsandbox/dist/admin/templates.js +66 -0
- package/plugins/microsandbox/dist/admin/templates.js.map +1 -0
- package/plugins/microsandbox/dist/admin.d.ts +5 -0
- package/plugins/microsandbox/dist/admin.d.ts.map +1 -0
- package/plugins/microsandbox/dist/admin.js +256 -0
- package/plugins/microsandbox/dist/admin.js.map +1 -0
- package/plugins/microsandbox/dist/build/builder.d.ts +69 -0
- package/plugins/microsandbox/dist/build/builder.d.ts.map +1 -0
- package/plugins/microsandbox/dist/build/builder.js +257 -0
- package/plugins/microsandbox/dist/build/builder.js.map +1 -0
- package/plugins/microsandbox/dist/build/metadata.d.ts +27 -0
- package/plugins/microsandbox/dist/build/metadata.d.ts.map +1 -0
- package/plugins/microsandbox/dist/build/metadata.js +55 -0
- package/plugins/microsandbox/dist/build/metadata.js.map +1 -0
- package/plugins/microsandbox/dist/build/pointer.d.ts +51 -0
- package/plugins/microsandbox/dist/build/pointer.d.ts.map +1 -0
- package/plugins/microsandbox/dist/build/pointer.js +130 -0
- package/plugins/microsandbox/dist/build/pointer.js.map +1 -0
- package/plugins/microsandbox/dist/build/sandboxfile.d.ts +15 -0
- package/plugins/microsandbox/dist/build/sandboxfile.d.ts.map +1 -0
- package/plugins/microsandbox/dist/build/sandboxfile.js +176 -0
- package/plugins/microsandbox/dist/build/sandboxfile.js.map +1 -0
- package/plugins/microsandbox/dist/client.d.ts +5 -0
- package/plugins/microsandbox/dist/client.d.ts.map +1 -0
- package/plugins/microsandbox/dist/client.js +941 -0
- package/plugins/microsandbox/dist/client.js.map +1 -0
- package/plugins/microsandbox/dist/runner/browser.d.ts +50 -0
- package/plugins/microsandbox/dist/runner/browser.d.ts.map +1 -0
- package/plugins/microsandbox/dist/runner/browser.js +142 -0
- package/plugins/microsandbox/dist/runner/browser.js.map +1 -0
- package/plugins/microsandbox/dist/runner/free-port.d.ts +6 -0
- package/plugins/microsandbox/dist/runner/free-port.d.ts.map +1 -0
- package/plugins/microsandbox/dist/runner/free-port.js +53 -0
- package/plugins/microsandbox/dist/runner/free-port.js.map +1 -0
- package/plugins/microsandbox/dist/runner/index.d.ts +28 -0
- package/plugins/microsandbox/dist/runner/index.d.ts.map +1 -0
- package/plugins/microsandbox/dist/runner/index.js +72 -0
- package/plugins/microsandbox/dist/runner/index.js.map +1 -0
- package/plugins/microsandbox/dist/runner/microsandbox.d.ts +64 -0
- package/plugins/microsandbox/dist/runner/microsandbox.d.ts.map +1 -0
- package/plugins/microsandbox/dist/runner/microsandbox.js +668 -0
- package/plugins/microsandbox/dist/runner/microsandbox.js.map +1 -0
- package/plugins/microsandbox/dist/runner/nullable.d.ts +36 -0
- package/plugins/microsandbox/dist/runner/nullable.d.ts.map +1 -0
- package/plugins/microsandbox/dist/runner/nullable.js +82 -0
- package/plugins/microsandbox/dist/runner/nullable.js.map +1 -0
- package/plugins/microsandbox/dist/runner/pool.d.ts +97 -0
- package/plugins/microsandbox/dist/runner/pool.d.ts.map +1 -0
- package/plugins/microsandbox/dist/runner/pool.js +494 -0
- package/plugins/microsandbox/dist/runner/pool.js.map +1 -0
- package/plugins/microsandbox/dist/runner/types.d.ts +33 -0
- package/plugins/microsandbox/dist/runner/types.d.ts.map +1 -0
- package/plugins/microsandbox/dist/runner/types.js +79 -0
- package/plugins/microsandbox/dist/runner/types.js.map +1 -0
- package/plugins/microsandbox/dist/server.d.ts +7 -0
- package/plugins/microsandbox/dist/server.d.ts.map +1 -0
- package/plugins/microsandbox/dist/server.js +276 -0
- package/plugins/microsandbox/dist/server.js.map +1 -0
- package/plugins/microsandbox/dist/tools/browser.d.ts +25 -0
- package/plugins/microsandbox/dist/tools/browser.d.ts.map +1 -0
- package/plugins/microsandbox/dist/tools/browser.js +78 -0
- package/plugins/microsandbox/dist/tools/browser.js.map +1 -0
- package/plugins/microsandbox/dist/tools/build.d.ts +5 -0
- package/plugins/microsandbox/dist/tools/build.d.ts.map +1 -0
- package/plugins/microsandbox/dist/tools/build.js +243 -0
- package/plugins/microsandbox/dist/tools/build.js.map +1 -0
- package/plugins/microsandbox/dist/tools/index.d.ts +9 -0
- package/plugins/microsandbox/dist/tools/index.d.ts.map +1 -0
- package/plugins/microsandbox/dist/tools/index.js +430 -0
- package/plugins/microsandbox/dist/tools/index.js.map +1 -0
- package/plugins/microsandbox/dist/tools/mcp-client.d.ts +63 -0
- package/plugins/microsandbox/dist/tools/mcp-client.d.ts.map +1 -0
- package/plugins/microsandbox/dist/tools/mcp-client.js +226 -0
- package/plugins/microsandbox/dist/tools/mcp-client.js.map +1 -0
- package/plugins/microsandbox/manifest.json +177 -0
- package/plugins/microsandbox/package.json +38 -0
- package/plugins/microsandbox/skills/microsandbox-browser-howto.md +155 -0
- package/plugins/microsandbox/skills/microsandbox-build-use.md +201 -0
- package/plugins/microsandbox/skills/microsandbox-config.md +38 -0
- package/plugins/microsandbox/skills/microsandbox-exec-howto.md +144 -0
- package/plugins/microsandbox/skills/microsandbox-libreoffice.md +159 -0
- package/plugins/microsandbox/templates/README.md +26 -0
- package/plugins/web-search/dist/server.d.ts +4 -0
- package/plugins/web-search/dist/server.d.ts.map +1 -0
- package/plugins/web-search/dist/server.js +73 -0
- package/plugins/web-search/dist/server.js.map +1 -0
- package/plugins/web-search/dist/tools/health.d.ts +31 -0
- package/plugins/web-search/dist/tools/health.d.ts.map +1 -0
- package/plugins/web-search/dist/tools/health.js +59 -0
- package/plugins/web-search/dist/tools/health.js.map +1 -0
- package/plugins/web-search/dist/tools/index.d.ts +3 -0
- package/plugins/web-search/dist/tools/index.d.ts.map +1 -0
- package/plugins/web-search/dist/tools/index.js +2 -0
- package/plugins/web-search/dist/tools/index.js.map +1 -0
- package/plugins/web-search/dist/tools/providers.d.ts +43 -0
- package/plugins/web-search/dist/tools/providers.d.ts.map +1 -0
- package/plugins/web-search/dist/tools/providers.js +140 -0
- package/plugins/web-search/dist/tools/providers.js.map +1 -0
- package/plugins/web-search/dist/tools/web-search.d.ts +15 -0
- package/plugins/web-search/dist/tools/web-search.d.ts.map +1 -0
- package/plugins/web-search/dist/tools/web-search.js +244 -0
- package/plugins/web-search/dist/tools/web-search.js.map +1 -0
- package/plugins/web-search/manifest.json +65 -0
- package/plugins/web-search/node_modules/@esbuild/darwin-arm64/README.md +3 -0
- package/plugins/web-search/node_modules/@esbuild/darwin-arm64/package.json +20 -0
- package/plugins/web-search/node_modules/@vitest/expect/LICENSE +21 -0
- package/plugins/web-search/node_modules/@vitest/expect/README.md +21 -0
- package/plugins/web-search/node_modules/@vitest/expect/dist/index.d.ts +808 -0
- package/plugins/web-search/node_modules/@vitest/expect/dist/index.js +1799 -0
- package/plugins/web-search/node_modules/@vitest/expect/package.json +46 -0
- package/plugins/web-search/node_modules/@vitest/mocker/LICENSE +21 -0
- package/plugins/web-search/node_modules/@vitest/mocker/README.md +5 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/auto-register.d.ts +2 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/auto-register.js +9 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/browser.d.ts +53 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/browser.js +91 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/chunk-interceptor-native.js +15 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/chunk-mocker.js +1602 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/chunk-pathe.M-eThtNZ.js +174 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/chunk-registry.js +182 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/chunk-utils.js +16 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/index.d.ts +21 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/index.js +174 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/mocker.d-Ce9_ySj5.d.ts +83 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/node.d.ts +821 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/node.js +1306 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/redirect.d.ts +3 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/redirect.js +75 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/register.d.ts +9 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/register.js +41 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/registry.d-D765pazg.d.ts +87 -0
- package/plugins/web-search/node_modules/@vitest/mocker/dist/types.d-D_aRZRdy.d.ts +8 -0
- package/plugins/web-search/node_modules/@vitest/mocker/package.json +82 -0
- package/plugins/web-search/node_modules/@vitest/pretty-format/LICENSE +21 -0
- package/plugins/web-search/node_modules/@vitest/pretty-format/dist/index.d.ts +119 -0
- package/plugins/web-search/node_modules/@vitest/pretty-format/dist/index.js +1387 -0
- package/plugins/web-search/node_modules/@vitest/pretty-format/package.json +44 -0
- package/plugins/web-search/node_modules/@vitest/runner/LICENSE +21 -0
- package/plugins/web-search/node_modules/@vitest/runner/README.md +5 -0
- package/plugins/web-search/node_modules/@vitest/runner/dist/chunk-hooks.js +2254 -0
- package/plugins/web-search/node_modules/@vitest/runner/dist/index.d.ts +261 -0
- package/plugins/web-search/node_modules/@vitest/runner/dist/index.js +6 -0
- package/plugins/web-search/node_modules/@vitest/runner/dist/tasks.d-CkscK4of.d.ts +558 -0
- package/plugins/web-search/node_modules/@vitest/runner/dist/types.d.ts +163 -0
- package/plugins/web-search/node_modules/@vitest/runner/dist/types.js +1 -0
- package/plugins/web-search/node_modules/@vitest/runner/dist/utils.d.ts +47 -0
- package/plugins/web-search/node_modules/@vitest/runner/dist/utils.js +6 -0
- package/plugins/web-search/node_modules/@vitest/runner/package.json +49 -0
- package/plugins/web-search/node_modules/@vitest/snapshot/LICENSE +21 -0
- package/plugins/web-search/node_modules/@vitest/snapshot/README.md +84 -0
- package/plugins/web-search/node_modules/@vitest/snapshot/dist/environment.d-DHdQ1Csl.d.ts +22 -0
- package/plugins/web-search/node_modules/@vitest/snapshot/dist/environment.d.ts +16 -0
- package/plugins/web-search/node_modules/@vitest/snapshot/dist/environment.js +40 -0
- package/plugins/web-search/node_modules/@vitest/snapshot/dist/index.d.ts +137 -0
- package/plugins/web-search/node_modules/@vitest/snapshot/dist/index.js +2305 -0
- package/plugins/web-search/node_modules/@vitest/snapshot/dist/manager.d.ts +18 -0
- package/plugins/web-search/node_modules/@vitest/snapshot/dist/manager.js +73 -0
- package/plugins/web-search/node_modules/@vitest/snapshot/dist/rawSnapshot.d-lFsMJFUd.d.ts +61 -0
- package/plugins/web-search/node_modules/@vitest/snapshot/package.json +54 -0
- package/plugins/web-search/node_modules/@vitest/spy/LICENSE +21 -0
- package/plugins/web-search/node_modules/@vitest/spy/README.md +3 -0
- package/plugins/web-search/node_modules/@vitest/spy/dist/index.d.ts +356 -0
- package/plugins/web-search/node_modules/@vitest/spy/dist/index.js +191 -0
- package/plugins/web-search/node_modules/@vitest/spy/package.json +38 -0
- package/plugins/web-search/node_modules/@vitest/utils/LICENSE +21 -0
- package/plugins/web-search/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +158 -0
- package/plugins/web-search/node_modules/@vitest/utils/dist/diff.d.ts +104 -0
- package/plugins/web-search/node_modules/@vitest/utils/dist/diff.js +2185 -0
- package/plugins/web-search/node_modules/@vitest/utils/dist/error.d.ts +9 -0
- package/plugins/web-search/node_modules/@vitest/utils/dist/error.js +162 -0
- package/plugins/web-search/node_modules/@vitest/utils/dist/helpers.d.ts +56 -0
- package/plugins/web-search/node_modules/@vitest/utils/dist/helpers.js +251 -0
- package/plugins/web-search/node_modules/@vitest/utils/dist/index.d.ts +57 -0
- package/plugins/web-search/node_modules/@vitest/utils/dist/index.js +633 -0
- package/plugins/web-search/node_modules/@vitest/utils/dist/source-map.d.ts +139 -0
- package/plugins/web-search/node_modules/@vitest/utils/dist/source-map.js +996 -0
- package/plugins/web-search/node_modules/@vitest/utils/dist/types.d-BCElaP-c.d.ts +53 -0
- package/plugins/web-search/node_modules/@vitest/utils/dist/types.d.ts +53 -0
- package/plugins/web-search/node_modules/@vitest/utils/dist/types.js +1 -0
- package/plugins/web-search/node_modules/@vitest/utils/package.json +77 -0
- package/plugins/web-search/node_modules/chai/LICENSE +21 -0
- package/plugins/web-search/node_modules/chai/README.md +162 -0
- package/plugins/web-search/node_modules/chai/package.json +74 -0
- package/plugins/web-search/node_modules/esbuild/README.md +3 -0
- package/plugins/web-search/node_modules/esbuild/package.json +49 -0
- package/plugins/web-search/node_modules/std-env/README.md +118 -0
- package/plugins/web-search/node_modules/std-env/dist/index.cjs +1 -0
- package/plugins/web-search/node_modules/std-env/dist/index.d.cts +92 -0
- package/plugins/web-search/node_modules/std-env/dist/index.d.mts +92 -0
- package/plugins/web-search/node_modules/std-env/dist/index.d.ts +92 -0
- package/plugins/web-search/node_modules/std-env/dist/index.mjs +1 -0
- package/plugins/web-search/node_modules/std-env/package.json +46 -0
- package/plugins/web-search/node_modules/tinyexec/LICENSE +21 -0
- package/plugins/web-search/node_modules/tinyexec/README.md +256 -0
- package/plugins/web-search/node_modules/tinyexec/dist/main.cjs +575 -0
- package/plugins/web-search/node_modules/tinyexec/dist/main.d.cts +70 -0
- package/plugins/web-search/node_modules/tinyexec/dist/main.d.ts +70 -0
- package/plugins/web-search/node_modules/tinyexec/dist/main.js +578 -0
- package/plugins/web-search/node_modules/tinyexec/package.json +66 -0
- package/plugins/web-search/node_modules/tinyrainbow/README.md +28 -0
- package/plugins/web-search/node_modules/tinyrainbow/dist/browser.d.ts +8 -0
- package/plugins/web-search/node_modules/tinyrainbow/dist/browser.js +20 -0
- package/plugins/web-search/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.js +90 -0
- package/plugins/web-search/node_modules/tinyrainbow/dist/index-8b61d5bc.d.ts +59 -0
- package/plugins/web-search/node_modules/tinyrainbow/dist/node.d.ts +8 -0
- package/plugins/web-search/node_modules/tinyrainbow/dist/node.js +22 -0
- package/plugins/web-search/node_modules/tinyrainbow/package.json +37 -0
- package/plugins/web-search/node_modules/typescript/README.md +50 -0
- package/plugins/web-search/node_modules/typescript/package.json +120 -0
- package/plugins/web-search/node_modules/vite/README.md +20 -0
- package/plugins/web-search/node_modules/vite/dist/client/client.mjs +1106 -0
- package/plugins/web-search/node_modules/vite/dist/client/env.mjs +19 -0
- package/plugins/web-search/node_modules/vite/dist/node/chunks/build.js +4 -0
- package/plugins/web-search/node_modules/vite/dist/node/chunks/build2.js +5538 -0
- package/plugins/web-search/node_modules/vite/dist/node/chunks/chunk.js +48 -0
- package/plugins/web-search/node_modules/vite/dist/node/chunks/config.js +36065 -0
- package/plugins/web-search/node_modules/vite/dist/node/chunks/config2.js +4 -0
- package/plugins/web-search/node_modules/vite/dist/node/chunks/dist.js +6758 -0
- package/plugins/web-search/node_modules/vite/dist/node/chunks/lib.js +377 -0
- package/plugins/web-search/node_modules/vite/dist/node/chunks/logger.js +329 -0
- package/plugins/web-search/node_modules/vite/dist/node/chunks/moduleRunnerTransport.d.ts +96 -0
- package/plugins/web-search/node_modules/vite/dist/node/chunks/optimizer.js +4 -0
- package/plugins/web-search/node_modules/vite/dist/node/chunks/postcss-import.js +479 -0
- package/plugins/web-search/node_modules/vite/dist/node/chunks/preview.js +4 -0
- package/plugins/web-search/node_modules/vite/dist/node/chunks/server.js +4 -0
- package/plugins/web-search/node_modules/vite/dist/node/cli.js +698 -0
- package/plugins/web-search/node_modules/vite/dist/node/index.d.ts +3717 -0
- package/plugins/web-search/node_modules/vite/dist/node/index.js +30 -0
- package/plugins/web-search/node_modules/vite/dist/node/module-runner.d.ts +311 -0
- package/plugins/web-search/node_modules/vite/dist/node/module-runner.js +1160 -0
- package/plugins/web-search/node_modules/vite/package.json +199 -0
- package/plugins/web-search/node_modules/vite/types/package.json +4 -0
- package/plugins/web-search/node_modules/vitest/README.md +7 -0
- package/plugins/web-search/node_modules/vitest/dist/browser.d.ts +34 -0
- package/plugins/web-search/node_modules/vitest/dist/browser.js +8 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.js +7 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/base.DfmxU-tU.js +38 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/benchmark.CYdenmiT.js +37 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/benchmark.d.BwvBVTda.d.ts +24 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/cac.0BJqEUeA.js +1469 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/cli-api.DWGBtMmz.js +10660 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/config.d.BKdhh7Zx.d.ts +224 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/console.CtFJOzRO.js +153 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/constants.DnKduX2e.js +44 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/coverage.DVF1vEu8.js +25 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/coverage.DfSpMS-b.js +4350 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/coverage.d.S9RMNXIe.d.ts +35 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/creator.GK6I-cL4.js +640 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js +73 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/defaults.B7q_naMc.js +115 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/env.D4Lgay0q.js +8 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/environment.d.cL3nLXbE.d.ts +119 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/execute.B7h3T_Hc.js +708 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/git.BVQ8w_Sw.js +72 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/global.d.MAmajcmJ.d.ts +136 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/globals.DEHgCU4V.js +26 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/index.B521nVV-.js +157 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/index.BCWujgDG.js +231 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/index.CdQS2e2Q.js +37 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/index.CmSc2RE5.js +587 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/index.CwejwG0H.js +105 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/index.D3XRDfWc.js +213 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/index.VByaPkjc.js +2183 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/index.X0nbfr6-.js +6584 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/inspector.C914Efll.js +57 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/mocker.d.BE_2ls6u.d.ts +17 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/node.fjCdwEIl.js +15 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/reporters.d.BuRON0I0.d.ts +3168 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/rpc.-pEldfrD.js +83 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/runBaseTests.9Ij9_de-.js +129 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/setup-common.Dd054P77.js +60 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/suite.d.FvehnV49.d.ts +10 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/typechecker.DRKU1-1g.js +874 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/utils.CAioKnHs.js +61 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/utils.XdZDrNZV.js +65 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js +4015 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/vite.d.BnOPPc46.d.ts +25 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/vm.BThCzidc.js +756 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/worker.d.CUgIPz9V.d.ts +176 -0
- package/plugins/web-search/node_modules/vitest/dist/chunks/worker.d.uzWsCv9X.d.ts +8 -0
- package/plugins/web-search/node_modules/vitest/dist/cli.js +27 -0
- package/plugins/web-search/node_modules/vitest/dist/config.cjs +148 -0
- package/plugins/web-search/node_modules/vitest/dist/config.d.ts +100 -0
- package/plugins/web-search/node_modules/vitest/dist/config.js +21 -0
- package/plugins/web-search/node_modules/vitest/dist/coverage.d.ts +108 -0
- package/plugins/web-search/node_modules/vitest/dist/coverage.js +34 -0
- package/plugins/web-search/node_modules/vitest/dist/environments.d.ts +26 -0
- package/plugins/web-search/node_modules/vitest/dist/environments.js +2 -0
- package/plugins/web-search/node_modules/vitest/dist/execute.d.ts +150 -0
- package/plugins/web-search/node_modules/vitest/dist/execute.js +13 -0
- package/plugins/web-search/node_modules/vitest/dist/index.d.ts +651 -0
- package/plugins/web-search/node_modules/vitest/dist/index.js +18 -0
- package/plugins/web-search/node_modules/vitest/dist/mocker.d.ts +1 -0
- package/plugins/web-search/node_modules/vitest/dist/mocker.js +1 -0
- package/plugins/web-search/node_modules/vitest/dist/node.d.ts +158 -0
- package/plugins/web-search/node_modules/vitest/dist/node.js +105 -0
- package/plugins/web-search/node_modules/vitest/dist/path.js +7 -0
- package/plugins/web-search/node_modules/vitest/dist/reporters.d.ts +25 -0
- package/plugins/web-search/node_modules/vitest/dist/reporters.js +23 -0
- package/plugins/web-search/node_modules/vitest/dist/runners.d.ts +46 -0
- package/plugins/web-search/node_modules/vitest/dist/runners.js +235 -0
- package/plugins/web-search/node_modules/vitest/dist/snapshot.d.ts +9 -0
- package/plugins/web-search/node_modules/vitest/dist/snapshot.js +4 -0
- package/plugins/web-search/node_modules/vitest/dist/spy.js +1 -0
- package/plugins/web-search/node_modules/vitest/dist/suite.d.ts +5 -0
- package/plugins/web-search/node_modules/vitest/dist/suite.js +5 -0
- package/plugins/web-search/node_modules/vitest/dist/worker.js +124 -0
- package/plugins/web-search/node_modules/vitest/dist/workers/forks.js +43 -0
- package/plugins/web-search/node_modules/vitest/dist/workers/runVmTests.js +90 -0
- package/plugins/web-search/node_modules/vitest/dist/workers/threads.js +31 -0
- package/plugins/web-search/node_modules/vitest/dist/workers/vmForks.js +47 -0
- package/plugins/web-search/node_modules/vitest/dist/workers/vmThreads.js +37 -0
- package/plugins/web-search/node_modules/vitest/dist/workers.d.ts +40 -0
- package/plugins/web-search/node_modules/vitest/dist/workers.js +30 -0
- package/plugins/web-search/node_modules/vitest/package.json +207 -0
- package/plugins/web-search/package.json +30 -0
- package/plugins/web-search/skills/web-search-howto.md +69 -0
- package/plugins/workboard/agent-seeds/echo-demo/agent.json +7 -0
- package/plugins/workboard/agent-seeds/llm-default/SOUL.md +53 -0
- package/plugins/workboard/agent-seeds/llm-default/agent.json +7 -0
- package/plugins/workboard/dist/client.d.ts +5 -0
- package/plugins/workboard/dist/client.d.ts.map +1 -0
- package/plugins/workboard/dist/client.js +895 -0
- package/plugins/workboard/dist/client.js.map +1 -0
- package/plugins/workboard/dist/db/agents.d.ts +100 -0
- package/plugins/workboard/dist/db/agents.d.ts.map +1 -0
- package/plugins/workboard/dist/db/agents.js +280 -0
- package/plugins/workboard/dist/db/agents.js.map +1 -0
- package/plugins/workboard/dist/db/schema.d.ts +3 -0
- package/plugins/workboard/dist/db/schema.d.ts.map +1 -0
- package/plugins/workboard/dist/db/schema.js +31 -0
- package/plugins/workboard/dist/db/schema.js.map +1 -0
- package/plugins/workboard/dist/db/session-history.d.ts +28 -0
- package/plugins/workboard/dist/db/session-history.d.ts.map +1 -0
- package/plugins/workboard/dist/db/session-history.js +224 -0
- package/plugins/workboard/dist/db/session-history.js.map +1 -0
- package/plugins/workboard/dist/db/tasks.d.ts +260 -0
- package/plugins/workboard/dist/db/tasks.d.ts.map +1 -0
- package/plugins/workboard/dist/db/tasks.js +451 -0
- package/plugins/workboard/dist/db/tasks.js.map +1 -0
- package/plugins/workboard/dist/db/worker-agents.d.ts +16 -0
- package/plugins/workboard/dist/db/worker-agents.d.ts.map +1 -0
- package/plugins/workboard/dist/db/worker-agents.js +62 -0
- package/plugins/workboard/dist/db/worker-agents.js.map +1 -0
- package/plugins/workboard/dist/effective-skills.d.ts +13 -0
- package/plugins/workboard/dist/effective-skills.d.ts.map +1 -0
- package/plugins/workboard/dist/effective-skills.js +126 -0
- package/plugins/workboard/dist/effective-skills.js.map +1 -0
- package/plugins/workboard/dist/fs-worker-agents.d.ts +35 -0
- package/plugins/workboard/dist/fs-worker-agents.d.ts.map +1 -0
- package/plugins/workboard/dist/fs-worker-agents.js +199 -0
- package/plugins/workboard/dist/fs-worker-agents.js.map +1 -0
- package/plugins/workboard/dist/migrate-worker-agents.d.ts +11 -0
- package/plugins/workboard/dist/migrate-worker-agents.d.ts.map +1 -0
- package/plugins/workboard/dist/migrate-worker-agents.js +89 -0
- package/plugins/workboard/dist/migrate-worker-agents.js.map +1 -0
- package/plugins/workboard/dist/routes/handlers.d.ts +106 -0
- package/plugins/workboard/dist/routes/handlers.d.ts.map +1 -0
- package/plugins/workboard/dist/routes/handlers.js +668 -0
- package/plugins/workboard/dist/routes/handlers.js.map +1 -0
- package/plugins/workboard/dist/server.d.ts +6 -0
- package/plugins/workboard/dist/server.d.ts.map +1 -0
- package/plugins/workboard/dist/server.js +368 -0
- package/plugins/workboard/dist/server.js.map +1 -0
- package/plugins/workboard/dist/tools/index.d.ts +70 -0
- package/plugins/workboard/dist/tools/index.d.ts.map +1 -0
- package/plugins/workboard/dist/tools/index.js +963 -0
- package/plugins/workboard/dist/tools/index.js.map +1 -0
- package/plugins/workboard/dist/types.d.ts +27 -0
- package/plugins/workboard/dist/types.d.ts.map +1 -0
- package/plugins/workboard/dist/types.js +16 -0
- package/plugins/workboard/dist/types.js.map +1 -0
- package/plugins/workboard/dist/worker/pool.d.ts +220 -0
- package/plugins/workboard/dist/worker/pool.d.ts.map +1 -0
- package/plugins/workboard/dist/worker/pool.js +866 -0
- package/plugins/workboard/dist/worker/pool.js.map +1 -0
- package/plugins/workboard/dist/worker/tool-policy.d.ts +27 -0
- package/plugins/workboard/dist/worker/tool-policy.d.ts.map +1 -0
- package/plugins/workboard/dist/worker/tool-policy.js +76 -0
- package/plugins/workboard/dist/worker/tool-policy.js.map +1 -0
- package/plugins/workboard/dist/worker-agents-page.d.ts +4 -0
- package/plugins/workboard/dist/worker-agents-page.d.ts.map +1 -0
- package/plugins/workboard/dist/worker-agents-page.js +193 -0
- package/plugins/workboard/dist/worker-agents-page.js.map +1 -0
- package/plugins/workboard/manifest.json +180 -0
- package/plugins/workboard/package.json +37 -0
- package/plugins/workboard/skills/large-input-large-output.md +185 -0
- package/plugins/workboard/skills/workboard-howto.md +166 -0
- package/plugins/workboard/skills/worker-creator.md +267 -0
- package/plugins/workboard/skills/worker-fleet.md +431 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// Two-layer configuration: ~/.tianshu/config.json (global)
|
|
2
|
+
// + ~/.tianshu/tenants/<id>/config.json (tenant override).
|
|
3
|
+
//
|
|
4
|
+
// Tenant config can only override fields on a whitelist (ADR-0001 §7).
|
|
5
|
+
// Server-process knobs (port, log path) are global-only — a tenant must
|
|
6
|
+
// not be able to flip the listener port.
|
|
7
|
+
//
|
|
8
|
+
// We DO NOT use a heavy schema library for v0; a hand-written validator
|
|
9
|
+
// keeps the dependency footprint small and the behaviour obvious. As the
|
|
10
|
+
// config grows, swap to typebox.
|
|
11
|
+
import fs from "node:fs";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import { getGlobalConfigPath, getTenantConfigPath, getTianshuHome, } from "./paths.js";
|
|
14
|
+
// ─── Defaults ─────────────────────────────────────────────────────────
|
|
15
|
+
export const DEFAULTS = {
|
|
16
|
+
autoCreateDefault: true,
|
|
17
|
+
server: { port: 3110, corsOrigin: "http://localhost:5183" },
|
|
18
|
+
logging: { level: "info" },
|
|
19
|
+
};
|
|
20
|
+
// ─── Whitelist enforcement ────────────────────────────────────────────
|
|
21
|
+
/** Field names a tenant config is allowed to set. Reject any others. */
|
|
22
|
+
const TENANT_WHITELIST = new Set([
|
|
23
|
+
"defaultModel",
|
|
24
|
+
"models",
|
|
25
|
+
"worker",
|
|
26
|
+
"oauth",
|
|
27
|
+
"branding",
|
|
28
|
+
"apiKeys",
|
|
29
|
+
"plugins",
|
|
30
|
+
"mcp",
|
|
31
|
+
]);
|
|
32
|
+
export class TenantConfigForbiddenFieldError extends Error {
|
|
33
|
+
tenantId;
|
|
34
|
+
field;
|
|
35
|
+
code = "TENANT_CONFIG_FORBIDDEN_FIELD";
|
|
36
|
+
constructor(tenantId, field) {
|
|
37
|
+
super(`tenant "${tenantId}" config.json sets "${field}", which is not in the override whitelist`);
|
|
38
|
+
this.tenantId = tenantId;
|
|
39
|
+
this.field = field;
|
|
40
|
+
this.name = "TenantConfigForbiddenFieldError";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function assertOnlyOverridable(tenantId, raw) {
|
|
44
|
+
for (const key of Object.keys(raw)) {
|
|
45
|
+
if (!TENANT_WHITELIST.has(key)) {
|
|
46
|
+
throw new TenantConfigForbiddenFieldError(tenantId, key);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// ─── Read / merge ─────────────────────────────────────────────────────
|
|
51
|
+
function readJsonOrEmpty(filepath) {
|
|
52
|
+
try {
|
|
53
|
+
const buf = fs.readFileSync(filepath, "utf8");
|
|
54
|
+
const parsed = JSON.parse(buf);
|
|
55
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
56
|
+
throw new Error(`expected JSON object, got ${typeof parsed}`);
|
|
57
|
+
}
|
|
58
|
+
return parsed;
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
if (err.code === "ENOENT")
|
|
62
|
+
return {};
|
|
63
|
+
throw new Error(`failed to read config ${filepath}: ${err instanceof Error ? err.message : String(err)}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export function loadGlobalConfig(home = getTianshuHome()) {
|
|
67
|
+
const raw = readJsonOrEmpty(getGlobalConfigPath(home));
|
|
68
|
+
return raw;
|
|
69
|
+
}
|
|
70
|
+
export function loadTenantConfig(tenantId, home = getTianshuHome()) {
|
|
71
|
+
const raw = readJsonOrEmpty(getTenantConfigPath(tenantId, home));
|
|
72
|
+
assertOnlyOverridable(tenantId, raw);
|
|
73
|
+
return raw;
|
|
74
|
+
}
|
|
75
|
+
/** Compute the effective config for a tenant. */
|
|
76
|
+
export function resolveTenantConfig(tenantId, home = getTianshuHome()) {
|
|
77
|
+
const global = loadGlobalConfig(home);
|
|
78
|
+
const tenant = loadTenantConfig(tenantId, home);
|
|
79
|
+
return mergeConfigs(global, tenant);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Merge global and tenant configs. Tenant wins on overridable fields.
|
|
83
|
+
*
|
|
84
|
+
* - Scalars and arrays: tenant replaces global wholesale.
|
|
85
|
+
* - Objects (worker, branding, apiKeys): shallow-merge so tenant can override
|
|
86
|
+
* single keys without restating the whole object.
|
|
87
|
+
*/
|
|
88
|
+
export function mergeConfigs(global, tenant) {
|
|
89
|
+
// models is wholesale-replace, not deep-merge: tenants typically
|
|
90
|
+
// bring their own provider catalog (different SAP gateway, qwen
|
|
91
|
+
// dashscope, etc.) and don't want to inherit global's anthropic /
|
|
92
|
+
// openai entries that almost certainly use a different key. So
|
|
93
|
+
// when tenant.models is set, it replaces global.models entirely.
|
|
94
|
+
const models = tenant.models ?? global.models;
|
|
95
|
+
// defaultModel needs to follow models. If the tenant supplies its
|
|
96
|
+
// own catalog and DOESN'T set defaultModel, falling back to
|
|
97
|
+
// global.defaultModel points at a provider that no longer exists
|
|
98
|
+
// in the resolved catalog — every chat request then 500s with
|
|
99
|
+
// "unknown provider". Mismatch caught 2026-06-21 on a tenant
|
|
100
|
+
// that defined `qwen` only; defaultModel inherited as
|
|
101
|
+
// 'anthropic/claude-sonnet-4-6' from global.
|
|
102
|
+
//
|
|
103
|
+
// Resolution rule:
|
|
104
|
+
// 1. tenant.defaultModel wins outright if set
|
|
105
|
+
// 2. else, if tenant brought its own models, pick the first
|
|
106
|
+
// provider/model in that catalog (deterministic: tenant
|
|
107
|
+
// author has full control by ordering)
|
|
108
|
+
// 3. else, inherit global.defaultModel (the original behaviour
|
|
109
|
+
// for tenants that don't override models)
|
|
110
|
+
let defaultModel = tenant.defaultModel ?? global.defaultModel;
|
|
111
|
+
if (!tenant.defaultModel && tenant.models && models?.providers) {
|
|
112
|
+
const firstProviderId = Object.keys(models.providers)[0];
|
|
113
|
+
const firstProvider = firstProviderId
|
|
114
|
+
? models.providers[firstProviderId]
|
|
115
|
+
: undefined;
|
|
116
|
+
const firstModelId = firstProvider?.models?.[0]?.id;
|
|
117
|
+
if (firstProviderId && firstModelId) {
|
|
118
|
+
defaultModel = `${firstProviderId}/${firstModelId}`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
// global-only — never touched by tenant
|
|
123
|
+
server: global.server,
|
|
124
|
+
logging: global.logging,
|
|
125
|
+
autoCreateDefault: global.autoCreateDefault ?? DEFAULTS.autoCreateDefault,
|
|
126
|
+
builtinConfigDir: global.builtinConfigDir,
|
|
127
|
+
// overridable — tenant wins
|
|
128
|
+
defaultModel,
|
|
129
|
+
models,
|
|
130
|
+
worker: { ...global.worker, ...tenant.worker },
|
|
131
|
+
oauth: tenant.oauth ?? global.oauth,
|
|
132
|
+
branding: { ...global.branding, ...tenant.branding },
|
|
133
|
+
apiKeys: { ...global.apiKeys, ...tenant.apiKeys },
|
|
134
|
+
plugins: { ...global.plugins, ...tenant.plugins },
|
|
135
|
+
mcp: tenant.mcp ?? global.mcp,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/** Atomic write. Writes to a temp file first, then rename. */
|
|
139
|
+
export function writeTenantConfig(tenantId, cfg, home = getTianshuHome()) {
|
|
140
|
+
// Validate before writing so callers can't sneak forbidden fields in.
|
|
141
|
+
assertOnlyOverridable(tenantId, cfg);
|
|
142
|
+
const target = getTenantConfigPath(tenantId, home);
|
|
143
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
144
|
+
const tmp = `${target}.tmp.${process.pid}.${Date.now()}`;
|
|
145
|
+
fs.writeFileSync(tmp, JSON.stringify(cfg, null, 2) + "\n", { mode: 0o600 });
|
|
146
|
+
fs.renameSync(tmp, target);
|
|
147
|
+
}
|
|
148
|
+
export function writeGlobalConfig(cfg, home = getTianshuHome()) {
|
|
149
|
+
const target = getGlobalConfigPath(home);
|
|
150
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
151
|
+
const tmp = `${target}.tmp.${process.pid}.${Date.now()}`;
|
|
152
|
+
fs.writeFileSync(tmp, JSON.stringify(cfg, null, 2) + "\n", { mode: 0o600 });
|
|
153
|
+
fs.renameSync(tmp, target);
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,2DAA2D;AAC3D,EAAE;AACF,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GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5E,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,GAAiB,EAAE,OAAe,cAAc,EAAE;IAClF,MAAM,MAAM,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACzC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACxD,MAAM,GAAG,GAAG,GAAG,MAAM,QAAQ,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;IACzD,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5E,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Database as DB } from "better-sqlite3";
|
|
2
|
+
export interface DbPoolOptions {
|
|
3
|
+
/** Max number of concurrently-open tenant DBs. */
|
|
4
|
+
maxOpen?: number;
|
|
5
|
+
home?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The pool maintains insertion-order in a Map. On access, we delete +
|
|
9
|
+
* re-insert the entry so the most-recently-used is always at the tail.
|
|
10
|
+
* When size > max, we evict from the head.
|
|
11
|
+
*/
|
|
12
|
+
export declare class DbPool {
|
|
13
|
+
private readonly entries;
|
|
14
|
+
private readonly maxOpen;
|
|
15
|
+
private readonly home;
|
|
16
|
+
constructor(opts?: DbPoolOptions);
|
|
17
|
+
/** Open (or return cached) DB for a tenant, running pending migrations. */
|
|
18
|
+
get(tenantId: string): DB;
|
|
19
|
+
/** Close and forget a tenant's DB (e.g. on tenant delete). */
|
|
20
|
+
close(tenantId: string): void;
|
|
21
|
+
/** Close all open DBs. Call on shutdown. */
|
|
22
|
+
closeAll(): void;
|
|
23
|
+
/** For tests / introspection. */
|
|
24
|
+
get openCount(): number;
|
|
25
|
+
private open;
|
|
26
|
+
private evictIfNeeded;
|
|
27
|
+
}
|
|
28
|
+
/** Process-wide singleton, used by routes and middleware. Tests should use `new DbPool()`. */
|
|
29
|
+
export declare function getDefaultPool(): DbPool;
|
|
30
|
+
/** For tests: replace the default pool. */
|
|
31
|
+
export declare function __setDefaultPool(pool: DbPool | null): void;
|
|
32
|
+
//# sourceMappingURL=db-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-pool.d.ts","sourceRoot":"","sources":["../../src/core/db-pool.ts"],"names":[],"mappings":"AAMA,OAAiB,EAAE,KAAK,QAAQ,IAAI,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAM/D,MAAM,WAAW,aAAa;IAC5B,kDAAkD;IAClD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AASD;;;;GAIG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4B;IACpD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;gBAE9B,IAAI,GAAE,aAAkB;IAKpC,2EAA2E;IAC3E,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE;IAczB,8DAA8D;IAC9D,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAW7B,4CAA4C;IAC5C,QAAQ,IAAI,IAAI;IAWhB,iCAAiC;IACjC,IAAI,SAAS,IAAI,MAAM,CAEtB;IAID,OAAO,CAAC,IAAI;IAWZ,OAAO,CAAC,aAAa;CAetB;AAID,8FAA8F;AAC9F,wBAAgB,cAAc,IAAI,MAAM,CAGvC;AAED,2CAA2C;AAC3C,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAE1D"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Per-tenant SQLite connection pool with LRU eviction.
|
|
2
|
+
//
|
|
3
|
+
// better-sqlite3 is synchronous; each Database instance holds one fd. We
|
|
4
|
+
// don't want a 100-tenant deploy holding 100 fds, so we cap to N most-
|
|
5
|
+
// recently-used DBs and reopen on demand. Reopening is cheap with WAL.
|
|
6
|
+
import Database from "better-sqlite3";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { getTenantDbPath } from "./paths.js";
|
|
10
|
+
import { runMigrations } from "./migrations/index.js";
|
|
11
|
+
const DEFAULT_MAX_OPEN = 32;
|
|
12
|
+
/**
|
|
13
|
+
* The pool maintains insertion-order in a Map. On access, we delete +
|
|
14
|
+
* re-insert the entry so the most-recently-used is always at the tail.
|
|
15
|
+
* When size > max, we evict from the head.
|
|
16
|
+
*/
|
|
17
|
+
export class DbPool {
|
|
18
|
+
entries = new Map();
|
|
19
|
+
maxOpen;
|
|
20
|
+
home;
|
|
21
|
+
constructor(opts = {}) {
|
|
22
|
+
this.maxOpen = opts.maxOpen ?? DEFAULT_MAX_OPEN;
|
|
23
|
+
this.home = opts.home;
|
|
24
|
+
}
|
|
25
|
+
/** Open (or return cached) DB for a tenant, running pending migrations. */
|
|
26
|
+
get(tenantId) {
|
|
27
|
+
const cached = this.entries.get(tenantId);
|
|
28
|
+
if (cached) {
|
|
29
|
+
// bump to MRU
|
|
30
|
+
this.entries.delete(tenantId);
|
|
31
|
+
this.entries.set(tenantId, cached);
|
|
32
|
+
return cached.db;
|
|
33
|
+
}
|
|
34
|
+
const db = this.open(tenantId);
|
|
35
|
+
this.entries.set(tenantId, { tenantId, db });
|
|
36
|
+
this.evictIfNeeded();
|
|
37
|
+
return db;
|
|
38
|
+
}
|
|
39
|
+
/** Close and forget a tenant's DB (e.g. on tenant delete). */
|
|
40
|
+
close(tenantId) {
|
|
41
|
+
const entry = this.entries.get(tenantId);
|
|
42
|
+
if (!entry)
|
|
43
|
+
return;
|
|
44
|
+
try {
|
|
45
|
+
entry.db.close();
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
/* ignore */
|
|
49
|
+
}
|
|
50
|
+
this.entries.delete(tenantId);
|
|
51
|
+
}
|
|
52
|
+
/** Close all open DBs. Call on shutdown. */
|
|
53
|
+
closeAll() {
|
|
54
|
+
for (const entry of this.entries.values()) {
|
|
55
|
+
try {
|
|
56
|
+
entry.db.close();
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
/* ignore */
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
this.entries.clear();
|
|
63
|
+
}
|
|
64
|
+
/** For tests / introspection. */
|
|
65
|
+
get openCount() {
|
|
66
|
+
return this.entries.size;
|
|
67
|
+
}
|
|
68
|
+
// ─── internals ───────────────────────────────────────────────────
|
|
69
|
+
open(tenantId) {
|
|
70
|
+
const dbPath = getTenantDbPath(tenantId, this.home);
|
|
71
|
+
fs.mkdirSync(path.dirname(dbPath), { recursive: true });
|
|
72
|
+
const db = new Database(dbPath);
|
|
73
|
+
db.pragma("journal_mode = WAL");
|
|
74
|
+
db.pragma("foreign_keys = ON");
|
|
75
|
+
db.pragma("synchronous = NORMAL");
|
|
76
|
+
runMigrations(db);
|
|
77
|
+
return db;
|
|
78
|
+
}
|
|
79
|
+
evictIfNeeded() {
|
|
80
|
+
while (this.entries.size > this.maxOpen) {
|
|
81
|
+
const lru = this.entries.keys().next().value;
|
|
82
|
+
if (!lru)
|
|
83
|
+
break;
|
|
84
|
+
const entry = this.entries.get(lru);
|
|
85
|
+
this.entries.delete(lru);
|
|
86
|
+
if (entry) {
|
|
87
|
+
try {
|
|
88
|
+
entry.db.close();
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
/* ignore */
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
let defaultPool = null;
|
|
98
|
+
/** Process-wide singleton, used by routes and middleware. Tests should use `new DbPool()`. */
|
|
99
|
+
export function getDefaultPool() {
|
|
100
|
+
if (!defaultPool)
|
|
101
|
+
defaultPool = new DbPool();
|
|
102
|
+
return defaultPool;
|
|
103
|
+
}
|
|
104
|
+
/** For tests: replace the default pool. */
|
|
105
|
+
export function __setDefaultPool(pool) {
|
|
106
|
+
defaultPool = pool;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=db-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-pool.js","sourceRoot":"","sources":["../../src/core/db-pool.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,EAAE;AACF,yEAAyE;AACzE,uEAAuE;AACvE,uEAAuE;AAEvE,OAAO,QAAiC,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAQtD,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAO5B;;;;GAIG;AACH,MAAM,OAAO,MAAM;IACA,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAC;IACnC,OAAO,CAAS;IAChB,IAAI,CAAqB;IAE1C,YAAY,OAAsB,EAAE;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,gBAAgB,CAAC;QAChD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;IAED,2EAA2E;IAC3E,GAAG,CAAC,QAAgB;QAClB,MAAM,MAAM,GAAG,IAAI,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AC7C,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,2CAA2C;AAC3C,MAAM,UAAU,gBAAgB,CAAC,IAAmB;IAClD,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type GlobalConfig } from "./config.js";
|
|
2
|
+
import { GlobalOps } from "./global-ops.js";
|
|
3
|
+
export declare const DEV_TENANT_ID = "default";
|
|
4
|
+
export declare const DEV_USER_ID = "dev";
|
|
5
|
+
export declare const DEV_USER_EXTERNAL_ID = "dev@local";
|
|
6
|
+
export declare const DEV_USER_PROVIDER = "dev";
|
|
7
|
+
export interface BootstrapResult {
|
|
8
|
+
created: boolean;
|
|
9
|
+
tenantId: string | null;
|
|
10
|
+
userId: string | null;
|
|
11
|
+
}
|
|
12
|
+
export declare function bootstrapDevTenantIfNeeded(ops?: GlobalOps, cfg?: GlobalConfig): BootstrapResult;
|
|
13
|
+
//# sourceMappingURL=dev-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-mode.d.ts","sourceRoot":"","sources":["../../src/core/dev-mode.ts"],"names":[],"mappings":"AAWA,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,WAAW,QAAQ,CAAC;AACjC,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAChD,eAAO,MAAM,iBAAiB,QAAQ,CAAC;AAEvC,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,wBAAgB,0BAA0B,CACxC,GAAG,CAAC,EAAE,SAAS,EACf,GAAG,CAAC,EAAE,YAAY,GACjB,eAAe,CAwCjB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Dev-mode bootstrap.
|
|
2
|
+
//
|
|
3
|
+
// On first boot, if no tenants exist and the global config allows it, we
|
|
4
|
+
// auto-create a `default` tenant with a single dev user. This is what
|
|
5
|
+
// makes `git clone && npm run dev` work without any setup —
|
|
6
|
+
// the user opens http://localhost:5173, hits /api/health, and there's a
|
|
7
|
+
// real (if empty) tenant context backing them.
|
|
8
|
+
//
|
|
9
|
+
// The dev user has a fixed id `dev`. JWT-mode deployments must turn
|
|
10
|
+
// this off in global config (`autoCreateDefault: false`).
|
|
11
|
+
import { loadGlobalConfig, loadTenantConfig, writeTenantConfig, } from "./config.js";
|
|
12
|
+
import { GlobalOps } from "./global-ops.js";
|
|
13
|
+
import { getTianshuHome } from "./paths.js";
|
|
14
|
+
export const DEV_TENANT_ID = "default";
|
|
15
|
+
export const DEV_USER_ID = "dev";
|
|
16
|
+
export const DEV_USER_EXTERNAL_ID = "dev@local";
|
|
17
|
+
export const DEV_USER_PROVIDER = "dev";
|
|
18
|
+
export function bootstrapDevTenantIfNeeded(ops, cfg) {
|
|
19
|
+
const home = getTianshuHome();
|
|
20
|
+
const globalOps = ops ?? new GlobalOps({ home });
|
|
21
|
+
const config = cfg ?? loadGlobalConfig(home);
|
|
22
|
+
const allow = config.autoCreateDefault ?? true;
|
|
23
|
+
if (!allow)
|
|
24
|
+
return { created: false, tenantId: null, userId: null };
|
|
25
|
+
const existing = globalOps.list();
|
|
26
|
+
if (existing.length > 0) {
|
|
27
|
+
return { created: false, tenantId: null, userId: null };
|
|
28
|
+
}
|
|
29
|
+
const ctx = globalOps.create(DEV_TENANT_ID);
|
|
30
|
+
globalOps.ensureUser(ctx, {
|
|
31
|
+
userId: DEV_USER_ID,
|
|
32
|
+
provider: DEV_USER_PROVIDER,
|
|
33
|
+
externalId: DEV_USER_EXTERNAL_ID,
|
|
34
|
+
displayName: "Dev User",
|
|
35
|
+
});
|
|
36
|
+
// Pre-enable the `files` builtin plugin so a fresh dev tenant has
|
|
37
|
+
// the basic chat workflow (browse + attach files — the files
|
|
38
|
+
// plugin contributes both the right-side panel and the composer
|
|
39
|
+
// paperclip button) out of the box. Per ADR-0003 §11, the other
|
|
40
|
+
// builtin plugins ship opt-in (browser / task-board / ...).
|
|
41
|
+
const tenantConfig = loadTenantConfig(DEV_TENANT_ID, home);
|
|
42
|
+
writeTenantConfig(DEV_TENANT_ID, {
|
|
43
|
+
...tenantConfig,
|
|
44
|
+
plugins: {
|
|
45
|
+
...(tenantConfig.plugins ?? {}),
|
|
46
|
+
files: { enabled: true, ...(tenantConfig.plugins?.files ?? {}) },
|
|
47
|
+
},
|
|
48
|
+
}, home);
|
|
49
|
+
return { created: true, tenantId: DEV_TENANT_ID, userId: DEV_USER_ID };
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=dev-mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-mode.js","sourceRoot":"","sources":["../../src/core/dev-mode.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,EAAE;AACF,yEAAyE;AACzE,sEAAsE;AACtE,4DAA4D;AAC5D,wEAAwE;AACxE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,0DAA0D;AAE1D,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,GAElB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AACvC,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC;AACjC,MAAM,CAAC,MAAM,oBAAoB,GAAG,WAAW,CAAC;AAChD,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAQvC,MAAM,UAAU,0BAA0B,CACxC,GAAe,EACf,GAAkB;IAElB,MAAM,IAAI,GAAG,c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AAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DbPool } from "./db-pool.js";
|
|
2
|
+
import { TenantContext } from "./tenant-context.js";
|
|
3
|
+
import { InvalidTenantIdError } from "./tenant-id.js";
|
|
4
|
+
export declare class TenantNotFoundError extends Error {
|
|
5
|
+
readonly tenantId: string;
|
|
6
|
+
readonly code: "TENANT_NOT_FOUND";
|
|
7
|
+
constructor(tenantId: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class TenantAlreadyExistsError extends Error {
|
|
10
|
+
readonly tenantId: string;
|
|
11
|
+
readonly code: "TENANT_ALREADY_EXISTS";
|
|
12
|
+
constructor(tenantId: string);
|
|
13
|
+
}
|
|
14
|
+
export interface GlobalOpsOptions {
|
|
15
|
+
home?: string;
|
|
16
|
+
pool?: DbPool;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Tenant lifecycle. Holds a reference to the DbPool so opening a tenant
|
|
20
|
+
* always goes through the same connection cache.
|
|
21
|
+
*/
|
|
22
|
+
export declare class GlobalOps {
|
|
23
|
+
private readonly home;
|
|
24
|
+
private readonly pool;
|
|
25
|
+
constructor(opts?: GlobalOpsOptions);
|
|
26
|
+
/** List visible tenant ids (skips `*.deleted*` and dot-files). */
|
|
27
|
+
list(): string[];
|
|
28
|
+
/** True iff this tenant's directory exists and is not soft-deleted. */
|
|
29
|
+
exists(tenantId: string): boolean;
|
|
30
|
+
/** Open a TenantContext, throwing if the tenant doesn't exist. */
|
|
31
|
+
open(tenantId: string): TenantContext;
|
|
32
|
+
/** Create a brand-new tenant. Throws if one already exists. */
|
|
33
|
+
create(tenantId: string): TenantContext;
|
|
34
|
+
/** Idempotent: returns existing if present, creates otherwise. */
|
|
35
|
+
ensure(tenantId: string): TenantContext;
|
|
36
|
+
/**
|
|
37
|
+
* Soft-delete: rename to `<id>.deleted.<ts>`. Future scans skip it.
|
|
38
|
+
* The DB connection is closed before the rename.
|
|
39
|
+
*/
|
|
40
|
+
softDelete(tenantId: string): void;
|
|
41
|
+
/** Provision a new user under this tenant: seed workspace, ensure DB row exists. */
|
|
42
|
+
ensureUser(ctx: TenantContext, args: {
|
|
43
|
+
userId: string;
|
|
44
|
+
provider: string;
|
|
45
|
+
externalId: string;
|
|
46
|
+
displayName?: string;
|
|
47
|
+
}): void;
|
|
48
|
+
closePool(): void;
|
|
49
|
+
get poolRef(): DbPool;
|
|
50
|
+
/** Resolved TIANSHU_HOME this ops instance is rooted at. */
|
|
51
|
+
get homeDir(): string;
|
|
52
|
+
}
|
|
53
|
+
export { InvalidTenantIdError, };
|
|
54
|
+
//# sourceMappingURL=global-ops.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-ops.d.ts","sourceRoot":"","sources":["../../src/core/global-ops.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAWtC,OAAO,EAEL,aAAa,EACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAoB,MAAM,gBAAgB,CAAC;AAExE,qBAAa,mBAAoB,SAAQ,KAAK;aAEhB,QAAQ,EAAE,MAAM;IAD5C,QAAQ,CAAC,IAAI,EAAG,kBAAkB,CAAU;gBAChB,QAAQ,EAAE,MAAM;CAI7C;AAED,qBAAa,wBAAyB,SAAQ,KAAK;aAErB,QAAQ,EAAE,MAAM;IAD5C,QAAQ,CAAC,IAAI,EAAG,uBAAuB,CAAU;gBACrB,QAAQ,EAAE,MAAM;CAI7C;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;gBAElB,IAAI,GAAE,gBAAqB;IAKvC,kEAAkE;IAClE,IAAI,IAAI,MAAM,EAAE;IAehB,uEAAuE;IACvE,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAUjC,kEAAkE;IAClE,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa;IAOrC,+DAA+D;IAC/D,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa;IAoBvC,kEAAkE;IAClE,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa;IAIvC;;;OAGG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IASlC,oFAAoF;IACpF,UAAU,CACR,GAAG,EAAE,aAAa,EAClB,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GACnF,IAAI;IAgBP,SAAS,IAAI,IAAI;IAIjB,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,4DAA4D;IAC5D,IAAI,OAAO,IAAI,MAAM,CAEpB;CACF;AAED,OAAO,EACL,oBAAoB,GACrB,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// Tenant lifecycle and cross-tenant operations.
|
|
2
|
+
//
|
|
3
|
+
// Routes / middleware NEVER reach into tenants/ directly; everything goes
|
|
4
|
+
// through here. That keeps "find a tenant", "create a tenant", "delete a
|
|
5
|
+
// tenant" in one place where we can enforce naming, soft-delete, and
|
|
6
|
+
// scan-skipping for `*.deleted` directories.
|
|
7
|
+
//
|
|
8
|
+
// Per ADR-0001 §9 — soft delete = rename to `<id>.deleted.<ts>`. Hard
|
|
9
|
+
// delete (--purge) is a separate operation we don't implement in PR #20.
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { writeTenantConfig } from "./config.js";
|
|
13
|
+
import { DbPool } from "./db-pool.js";
|
|
14
|
+
import { getDeletedTenantPath, getTenantRoot, getTenantSecretsDir, getTenantsRoot, getTianshuHome, isSoftDeletedDirName, isSystemReserved, } from "./paths.js";
|
|
15
|
+
import { seedTenantWorkspace, seedUserWorkspace } from "./templates.js";
|
|
16
|
+
import { buildTenantContext, } from "./tenant-context.js";
|
|
17
|
+
import { InvalidTenantIdError, validateTenantId } from "./tenant-id.js";
|
|
18
|
+
export class TenantNotFoundError extends Error {
|
|
19
|
+
tenantId;
|
|
20
|
+
code = "TENANT_NOT_FOUND";
|
|
21
|
+
constructor(tenantId) {
|
|
22
|
+
super(`tenant "${tenantId}" not found`);
|
|
23
|
+
this.tenantId = tenantId;
|
|
24
|
+
this.name = "TenantNotFoundError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class TenantAlreadyExistsError extends Error {
|
|
28
|
+
tenantId;
|
|
29
|
+
code = "TENANT_ALREADY_EXISTS";
|
|
30
|
+
constructor(tenantId) {
|
|
31
|
+
super(`tenant "${tenantId}" already exists`);
|
|
32
|
+
this.tenantId = tenantId;
|
|
33
|
+
this.name = "TenantAlreadyExistsError";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Tenant lifecycle. Holds a reference to the DbPool so opening a tenant
|
|
38
|
+
* always goes through the same connection cache.
|
|
39
|
+
*/
|
|
40
|
+
export class GlobalOps {
|
|
41
|
+
home;
|
|
42
|
+
pool;
|
|
43
|
+
constructor(opts = {}) {
|
|
44
|
+
this.home = opts.home ?? getTianshuHome();
|
|
45
|
+
this.pool = opts.pool ?? new DbPool({ home: this.home });
|
|
46
|
+
}
|
|
47
|
+
/** List visible tenant ids (skips `*.deleted*` and dot-files). */
|
|
48
|
+
list() {
|
|
49
|
+
const root = getTenantsRoot(this.home);
|
|
50
|
+
if (!fs.existsSync(root))
|
|
51
|
+
return [];
|
|
52
|
+
const entries = fs.readdirSync(root, { withFileTypes: true });
|
|
53
|
+
const ids = [];
|
|
54
|
+
for (const e of entries) {
|
|
55
|
+
if (!e.isDirectory())
|
|
56
|
+
continue;
|
|
57
|
+
if (e.name.startsWith("."))
|
|
58
|
+
continue;
|
|
59
|
+
if (isSoftDeletedDirName(e.name))
|
|
60
|
+
continue;
|
|
61
|
+
if (isSystemReserved(e.name))
|
|
62
|
+
continue;
|
|
63
|
+
ids.push(e.name);
|
|
64
|
+
}
|
|
65
|
+
return ids.sort();
|
|
66
|
+
}
|
|
67
|
+
/** True iff this tenant's directory exists and is not soft-deleted. */
|
|
68
|
+
exists(tenantId) {
|
|
69
|
+
try {
|
|
70
|
+
validateTenantId(tenantId);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
const root = getTenantRoot(tenantId, this.home);
|
|
76
|
+
return fs.existsSync(root) && !isSoftDeletedDirName(path.basename(root));
|
|
77
|
+
}
|
|
78
|
+
/** Open a TenantContext, throwing if the tenant doesn't exist. */
|
|
79
|
+
open(tenantId) {
|
|
80
|
+
const id = validateTenantId(tenantId);
|
|
81
|
+
if (!this.exists(id))
|
|
82
|
+
throw new TenantNotFoundError(id);
|
|
83
|
+
const db = this.pool.get(id);
|
|
84
|
+
return buildTenantContext(id, db, this.home);
|
|
85
|
+
}
|
|
86
|
+
/** Create a brand-new tenant. Throws if one already exists. */
|
|
87
|
+
create(tenantId) {
|
|
88
|
+
const id = validateTenantId(tenantId);
|
|
89
|
+
if (this.exists(id))
|
|
90
|
+
throw new TenantAlreadyExistsError(id);
|
|
91
|
+
const root = getTenantRoot(id, this.home);
|
|
92
|
+
fs.mkdirSync(root, { recursive: true });
|
|
93
|
+
// secrets/ — mode 0700 so other local users can't read API keys
|
|
94
|
+
fs.mkdirSync(getTenantSecretsDir(id, this.home), { recursive: true, mode: 0o700 });
|
|
95
|
+
// workspace seed
|
|
96
|
+
seedTenantWorkspace(id, this.home);
|
|
97
|
+
// empty config.json (acts as a marker that a creator made it)
|
|
98
|
+
writeTenantConfig(id, {}, this.home);
|
|
99
|
+
// running this opens & migrates the DB
|
|
100
|
+
const db = this.pool.get(id);
|
|
101
|
+
return buildTenantContext(id, db, this.home);
|
|
102
|
+
}
|
|
103
|
+
/** Idempotent: returns existing if present, creates otherwise. */
|
|
104
|
+
ensure(tenantId) {
|
|
105
|
+
return this.exists(tenantId) ? this.open(tenantId) : this.create(tenantId);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Soft-delete: rename to `<id>.deleted.<ts>`. Future scans skip it.
|
|
109
|
+
* The DB connection is closed before the rename.
|
|
110
|
+
*/
|
|
111
|
+
softDelete(tenantId) {
|
|
112
|
+
const id = validateTenantId(tenantId);
|
|
113
|
+
if (!this.exists(id))
|
|
114
|
+
throw new TenantNotFoundError(id);
|
|
115
|
+
this.pool.close(id);
|
|
116
|
+
const src = getTenantRoot(id, this.home);
|
|
117
|
+
const dst = getDeletedTenantPath(id, Date.now(), this.home);
|
|
118
|
+
fs.renameSync(src, dst);
|
|
119
|
+
}
|
|
120
|
+
/** Provision a new user under this tenant: seed workspace, ensure DB row exists. */
|
|
121
|
+
ensureUser(ctx, args) {
|
|
122
|
+
seedUserWorkspace(ctx.tenantId, args.userId, this.home);
|
|
123
|
+
const now = Date.now();
|
|
124
|
+
ctx.db
|
|
125
|
+
.prepare(`INSERT INTO users (id, external_id, provider, display_name, created_at)
|
|
126
|
+
VALUES (?, ?, ?, ?, ?)
|
|
127
|
+
ON CONFLICT(provider, external_id) DO NOTHING`)
|
|
128
|
+
.run(args.userId, args.externalId, args.provider, args.displayName ?? null, now);
|
|
129
|
+
}
|
|
130
|
+
// For tests / shutdown.
|
|
131
|
+
closePool() {
|
|
132
|
+
this.pool.closeAll();
|
|
133
|
+
}
|
|
134
|
+
get poolRef() {
|
|
135
|
+
return this.pool;
|
|
136
|
+
}
|
|
137
|
+
/** Resolved TIANSHU_HOME this ops instance is rooted at. */
|
|
138
|
+
get homeDir() {
|
|
139
|
+
return this.home;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export { InvalidTenantIdError, };
|
|
143
|
+
//# sourceMappingURL=global-ops.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-ops.js","sourceRoot":"","sources":["../../src/core/global-ops.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,EAAE;AACF,0EAA0E;AAC1E,yEAAyE;AACzE,qEAAqE;AACrE,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,yEAAyE;AAEzE,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EACL,kBAAkB,GAEnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAExE,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAEhB;IADnB,IAAI,GAAG,kBAA2B,CAAC;IAC5C,YAA4B,QAAgB;QAC1C,KAAK,CAAC,WAAW,QAAQ,aAAa,CAAC,CAAC;QADd,aAAQ,GAAR,QAAQ,CAAQ;QAE1C,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAErB;IADnB,IAAI,GAAG,uBAAgC,CAAC;IACjD,YAA4B,QAAgB;QAC1C,KAAK,CAAC,WAAW,QAAQ,kBAAkB,CAAC,CAAC;QADnB,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