zerg-ztc 0.1.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/README.md +361 -0
- package/dist/App.d.ts +4 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/App.js +499 -0
- package/dist/App.js.map +1 -0
- package/dist/agent/agent.d.ts +54 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +347 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/backends/anthropic.d.ts +13 -0
- package/dist/agent/backends/anthropic.d.ts.map +1 -0
- package/dist/agent/backends/anthropic.js +54 -0
- package/dist/agent/backends/anthropic.js.map +1 -0
- package/dist/agent/backends/gemini.d.ts +13 -0
- package/dist/agent/backends/gemini.d.ts.map +1 -0
- package/dist/agent/backends/gemini.js +71 -0
- package/dist/agent/backends/gemini.js.map +1 -0
- package/dist/agent/backends/inception.d.ts +12 -0
- package/dist/agent/backends/inception.d.ts.map +1 -0
- package/dist/agent/backends/inception.js +15 -0
- package/dist/agent/backends/inception.js.map +1 -0
- package/dist/agent/backends/index.d.ts +7 -0
- package/dist/agent/backends/index.d.ts.map +1 -0
- package/dist/agent/backends/index.js +6 -0
- package/dist/agent/backends/index.js.map +1 -0
- package/dist/agent/backends/openai.d.ts +12 -0
- package/dist/agent/backends/openai.d.ts.map +1 -0
- package/dist/agent/backends/openai.js +15 -0
- package/dist/agent/backends/openai.js.map +1 -0
- package/dist/agent/backends/openai_compatible.d.ts +17 -0
- package/dist/agent/backends/openai_compatible.d.ts.map +1 -0
- package/dist/agent/backends/openai_compatible.js +95 -0
- package/dist/agent/backends/openai_compatible.js.map +1 -0
- package/dist/agent/backends/types.d.ts +49 -0
- package/dist/agent/backends/types.d.ts.map +1 -0
- package/dist/agent/backends/types.js +2 -0
- package/dist/agent/backends/types.js.map +1 -0
- package/dist/agent/commands/clipboard.d.ts +3 -0
- package/dist/agent/commands/clipboard.d.ts.map +1 -0
- package/dist/agent/commands/clipboard.js +72 -0
- package/dist/agent/commands/clipboard.js.map +1 -0
- package/dist/agent/commands/config.d.ts +3 -0
- package/dist/agent/commands/config.d.ts.map +1 -0
- package/dist/agent/commands/config.js +120 -0
- package/dist/agent/commands/config.js.map +1 -0
- package/dist/agent/commands/debug.d.ts +3 -0
- package/dist/agent/commands/debug.d.ts.map +1 -0
- package/dist/agent/commands/debug.js +23 -0
- package/dist/agent/commands/debug.js.map +1 -0
- package/dist/agent/commands/emulation.d.ts +3 -0
- package/dist/agent/commands/emulation.d.ts.map +1 -0
- package/dist/agent/commands/emulation.js +78 -0
- package/dist/agent/commands/emulation.js.map +1 -0
- package/dist/agent/commands/execution.d.ts +3 -0
- package/dist/agent/commands/execution.d.ts.map +1 -0
- package/dist/agent/commands/execution.js +8 -0
- package/dist/agent/commands/execution.js.map +1 -0
- package/dist/agent/commands/help.d.ts +3 -0
- package/dist/agent/commands/help.d.ts.map +1 -0
- package/dist/agent/commands/help.js +19 -0
- package/dist/agent/commands/help.js.map +1 -0
- package/dist/agent/commands/history.d.ts +3 -0
- package/dist/agent/commands/history.d.ts.map +1 -0
- package/dist/agent/commands/history.js +12 -0
- package/dist/agent/commands/history.js.map +1 -0
- package/dist/agent/commands/index.d.ts +4 -0
- package/dist/agent/commands/index.d.ts.map +1 -0
- package/dist/agent/commands/index.js +19 -0
- package/dist/agent/commands/index.js.map +1 -0
- package/dist/agent/commands/model.d.ts +3 -0
- package/dist/agent/commands/model.d.ts.map +1 -0
- package/dist/agent/commands/model.js +10 -0
- package/dist/agent/commands/model.js.map +1 -0
- package/dist/agent/commands/models.d.ts +3 -0
- package/dist/agent/commands/models.d.ts.map +1 -0
- package/dist/agent/commands/models.js +110 -0
- package/dist/agent/commands/models.js.map +1 -0
- package/dist/agent/commands/permissions.d.ts +3 -0
- package/dist/agent/commands/permissions.d.ts.map +1 -0
- package/dist/agent/commands/permissions.js +58 -0
- package/dist/agent/commands/permissions.js.map +1 -0
- package/dist/agent/commands/retry.d.ts +3 -0
- package/dist/agent/commands/retry.d.ts.map +1 -0
- package/dist/agent/commands/retry.js +8 -0
- package/dist/agent/commands/retry.js.map +1 -0
- package/dist/agent/commands/shell.d.ts +4 -0
- package/dist/agent/commands/shell.d.ts.map +1 -0
- package/dist/agent/commands/shell.js +66 -0
- package/dist/agent/commands/shell.js.map +1 -0
- package/dist/agent/commands/skills.d.ts +3 -0
- package/dist/agent/commands/skills.d.ts.map +1 -0
- package/dist/agent/commands/skills.js +50 -0
- package/dist/agent/commands/skills.js.map +1 -0
- package/dist/agent/commands/status.d.ts +3 -0
- package/dist/agent/commands/status.d.ts.map +1 -0
- package/dist/agent/commands/status.js +18 -0
- package/dist/agent/commands/status.js.map +1 -0
- package/dist/agent/commands/types.d.ts +70 -0
- package/dist/agent/commands/types.d.ts.map +1 -0
- package/dist/agent/commands/types.js +2 -0
- package/dist/agent/commands/types.js.map +1 -0
- package/dist/agent/factory.d.ts +13 -0
- package/dist/agent/factory.d.ts.map +1 -0
- package/dist/agent/factory.js +46 -0
- package/dist/agent/factory.js.map +1 -0
- package/dist/agent/index.d.ts +14 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +10 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/runtime/capabilities.d.ts +7 -0
- package/dist/agent/runtime/capabilities.d.ts.map +1 -0
- package/dist/agent/runtime/capabilities.js +8 -0
- package/dist/agent/runtime/capabilities.js.map +1 -0
- package/dist/agent/runtime/memory.d.ts +13 -0
- package/dist/agent/runtime/memory.d.ts.map +1 -0
- package/dist/agent/runtime/memory.js +13 -0
- package/dist/agent/runtime/memory.js.map +1 -0
- package/dist/agent/runtime/policy.d.ts +22 -0
- package/dist/agent/runtime/policy.d.ts.map +1 -0
- package/dist/agent/runtime/policy.js +29 -0
- package/dist/agent/runtime/policy.js.map +1 -0
- package/dist/agent/runtime/session.d.ts +11 -0
- package/dist/agent/runtime/session.d.ts.map +1 -0
- package/dist/agent/runtime/session.js +10 -0
- package/dist/agent/runtime/session.js.map +1 -0
- package/dist/agent/runtime/tracing.d.ts +13 -0
- package/dist/agent/runtime/tracing.d.ts.map +1 -0
- package/dist/agent/runtime/tracing.js +6 -0
- package/dist/agent/runtime/tracing.js.map +1 -0
- package/dist/agent/tools/file.d.ts +5 -0
- package/dist/agent/tools/file.d.ts.map +1 -0
- package/dist/agent/tools/file.js +162 -0
- package/dist/agent/tools/file.js.map +1 -0
- package/dist/agent/tools/index.d.ts +13 -0
- package/dist/agent/tools/index.d.ts.map +1 -0
- package/dist/agent/tools/index.js +34 -0
- package/dist/agent/tools/index.js.map +1 -0
- package/dist/agent/tools/search.d.ts +3 -0
- package/dist/agent/tools/search.d.ts.map +1 -0
- package/dist/agent/tools/search.js +124 -0
- package/dist/agent/tools/search.js.map +1 -0
- package/dist/agent/tools/shell.d.ts +3 -0
- package/dist/agent/tools/shell.d.ts.map +1 -0
- package/dist/agent/tools/shell.js +60 -0
- package/dist/agent/tools/shell.js.map +1 -0
- package/dist/agent/tools/skills.d.ts +3 -0
- package/dist/agent/tools/skills.d.ts.map +1 -0
- package/dist/agent/tools/skills.js +27 -0
- package/dist/agent/tools/skills.js.map +1 -0
- package/dist/agent/tools/types.d.ts +8 -0
- package/dist/agent/tools/types.d.ts.map +1 -0
- package/dist/agent/tools/types.js +2 -0
- package/dist/agent/tools/types.js.map +1 -0
- package/dist/agent/tools/zerg.d.ts +3 -0
- package/dist/agent/tools/zerg.d.ts.map +1 -0
- package/dist/agent/tools/zerg.js +47 -0
- package/dist/agent/tools/zerg.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +75 -0
- package/dist/cli.js.map +1 -0
- package/dist/components/FullScreen.d.ts +28 -0
- package/dist/components/FullScreen.d.ts.map +1 -0
- package/dist/components/FullScreen.js +40 -0
- package/dist/components/FullScreen.js.map +1 -0
- package/dist/components/Header.d.ts +10 -0
- package/dist/components/Header.d.ts.map +1 -0
- package/dist/components/Header.js +14 -0
- package/dist/components/Header.js.map +1 -0
- package/dist/components/InputArea.d.ts +24 -0
- package/dist/components/InputArea.d.ts.map +1 -0
- package/dist/components/InputArea.js +476 -0
- package/dist/components/InputArea.js.map +1 -0
- package/dist/components/MessageList.d.ts +12 -0
- package/dist/components/MessageList.d.ts.map +1 -0
- package/dist/components/MessageList.js +9 -0
- package/dist/components/MessageList.js.map +1 -0
- package/dist/components/StatusBar.d.ts +18 -0
- package/dist/components/StatusBar.d.ts.map +1 -0
- package/dist/components/StatusBar.js +21 -0
- package/dist/components/StatusBar.js.map +1 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +7 -0
- package/dist/components/index.js.map +1 -0
- package/dist/config/types.d.ts +12 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config.d.ts +28 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +155 -0
- package/dist/config.js.map +1 -0
- package/dist/debug/logger.d.ts +2 -0
- package/dist/debug/logger.d.ts.map +1 -0
- package/dist/debug/logger.js +15 -0
- package/dist/debug/logger.js.map +1 -0
- package/dist/emulation/catalog.d.ts +4 -0
- package/dist/emulation/catalog.d.ts.map +1 -0
- package/dist/emulation/catalog.js +68 -0
- package/dist/emulation/catalog.js.map +1 -0
- package/dist/emulation/trace_style.d.ts +3 -0
- package/dist/emulation/trace_style.d.ts.map +1 -0
- package/dist/emulation/trace_style.js +10 -0
- package/dist/emulation/trace_style.js.map +1 -0
- package/dist/emulation/types.d.ts +8 -0
- package/dist/emulation/types.d.ts.map +1 -0
- package/dist/emulation/types.js +2 -0
- package/dist/emulation/types.js.map +1 -0
- package/dist/skills/index.d.ts +5 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +36 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/loader.d.ts +3 -0
- package/dist/skills/loader.d.ts.map +1 -0
- package/dist/skills/loader.js +137 -0
- package/dist/skills/loader.js.map +1 -0
- package/dist/skills/registry.d.ts +3 -0
- package/dist/skills/registry.d.ts.map +1 -0
- package/dist/skills/registry.js +5 -0
- package/dist/skills/registry.js.map +1 -0
- package/dist/skills/types.d.ts +11 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js +2 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/types.d.ts +93 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/core/factory.d.ts +4 -0
- package/dist/ui/core/factory.d.ts.map +1 -0
- package/dist/ui/core/factory.js +7 -0
- package/dist/ui/core/factory.js.map +1 -0
- package/dist/ui/core/index.d.ts +5 -0
- package/dist/ui/core/index.d.ts.map +1 -0
- package/dist/ui/core/index.js +4 -0
- package/dist/ui/core/index.js.map +1 -0
- package/dist/ui/core/input.d.ts +22 -0
- package/dist/ui/core/input.d.ts.map +1 -0
- package/dist/ui/core/input.js +15 -0
- package/dist/ui/core/input.js.map +1 -0
- package/dist/ui/core/input_segments.d.ts +19 -0
- package/dist/ui/core/input_segments.d.ts.map +1 -0
- package/dist/ui/core/input_segments.js +367 -0
- package/dist/ui/core/input_segments.js.map +1 -0
- package/dist/ui/core/input_state.d.ts +24 -0
- package/dist/ui/core/input_state.d.ts.map +1 -0
- package/dist/ui/core/input_state.js +2 -0
- package/dist/ui/core/input_state.js.map +1 -0
- package/dist/ui/core/layout_yoga.d.ts +11 -0
- package/dist/ui/core/layout_yoga.d.ts.map +1 -0
- package/dist/ui/core/layout_yoga.js +102 -0
- package/dist/ui/core/layout_yoga.js.map +1 -0
- package/dist/ui/core/style.d.ts +3 -0
- package/dist/ui/core/style.d.ts.map +1 -0
- package/dist/ui/core/style.js +37 -0
- package/dist/ui/core/style.js.map +1 -0
- package/dist/ui/core/types.d.ts +50 -0
- package/dist/ui/core/types.d.ts.map +1 -0
- package/dist/ui/core/types.js +2 -0
- package/dist/ui/core/types.js.map +1 -0
- package/dist/ui/ink/index.d.ts +2 -0
- package/dist/ui/ink/index.d.ts.map +1 -0
- package/dist/ui/ink/index.js +2 -0
- package/dist/ui/ink/index.js.map +1 -0
- package/dist/ui/ink/render.d.ts +6 -0
- package/dist/ui/ink/render.d.ts.map +1 -0
- package/dist/ui/ink/render.js +14 -0
- package/dist/ui/ink/render.js.map +1 -0
- package/dist/ui/views/app.d.ts +28 -0
- package/dist/ui/views/app.d.ts.map +1 -0
- package/dist/ui/views/app.js +59 -0
- package/dist/ui/views/app.js.map +1 -0
- package/dist/ui/views/header.d.ts +11 -0
- package/dist/ui/views/header.d.ts.map +1 -0
- package/dist/ui/views/header.js +28 -0
- package/dist/ui/views/header.js.map +1 -0
- package/dist/ui/views/input_area.d.ts +45 -0
- package/dist/ui/views/input_area.d.ts.map +1 -0
- package/dist/ui/views/input_area.js +183 -0
- package/dist/ui/views/input_area.js.map +1 -0
- package/dist/ui/views/message_list.d.ts +12 -0
- package/dist/ui/views/message_list.d.ts.map +1 -0
- package/dist/ui/views/message_list.js +381 -0
- package/dist/ui/views/message_list.js.map +1 -0
- package/dist/ui/views/status_bar.d.ts +18 -0
- package/dist/ui/views/status_bar.d.ts.map +1 -0
- package/dist/ui/views/status_bar.js +72 -0
- package/dist/ui/views/status_bar.js.map +1 -0
- package/dist/ui/vue/index.d.ts +5 -0
- package/dist/ui/vue/index.d.ts.map +1 -0
- package/dist/ui/vue/index.js +50 -0
- package/dist/ui/vue/index.js.map +1 -0
- package/dist/utils/clipboard.d.ts +2 -0
- package/dist/utils/clipboard.d.ts.map +1 -0
- package/dist/utils/clipboard.js +39 -0
- package/dist/utils/clipboard.js.map +1 -0
- package/dist/utils/clipboard_image.d.ts +2 -0
- package/dist/utils/clipboard_image.d.ts.map +1 -0
- package/dist/utils/clipboard_image.js +37 -0
- package/dist/utils/clipboard_image.js.map +1 -0
- package/dist/utils/diff.d.ts +2 -0
- package/dist/utils/diff.d.ts.map +1 -0
- package/dist/utils/diff.js +49 -0
- package/dist/utils/diff.js.map +1 -0
- package/dist/utils/image_preview.d.ts +2 -0
- package/dist/utils/image_preview.d.ts.map +1 -0
- package/dist/utils/image_preview.js +37 -0
- package/dist/utils/image_preview.js.map +1 -0
- package/dist/utils/models.d.ts +8 -0
- package/dist/utils/models.d.ts.map +1 -0
- package/dist/utils/models.js +85 -0
- package/dist/utils/models.js.map +1 -0
- package/dist/utils/shell.d.ts +4 -0
- package/dist/utils/shell.d.ts.map +1 -0
- package/dist/utils/shell.js +57 -0
- package/dist/utils/shell.js.map +1 -0
- package/dist/utils/tool_summary.d.ts +3 -0
- package/dist/utils/tool_summary.d.ts.map +1 -0
- package/dist/utils/tool_summary.js +54 -0
- package/dist/utils/tool_summary.js.map +1 -0
- package/dist/utils/tool_trace.d.ts +9 -0
- package/dist/utils/tool_trace.d.ts.map +1 -0
- package/dist/utils/tool_trace.js +183 -0
- package/dist/utils/tool_trace.js.map +1 -0
- package/package.json +41 -0
- package/src/App.tsx +576 -0
- package/src/agent/agent.ts +407 -0
- package/src/agent/backends/anthropic.ts +76 -0
- package/src/agent/backends/gemini.ts +107 -0
- package/src/agent/backends/inception.ts +23 -0
- package/src/agent/backends/index.ts +16 -0
- package/src/agent/backends/openai.ts +23 -0
- package/src/agent/backends/openai_compatible.ts +131 -0
- package/src/agent/backends/types.ts +59 -0
- package/src/agent/commands/clipboard.ts +77 -0
- package/src/agent/commands/config.ts +130 -0
- package/src/agent/commands/debug.ts +23 -0
- package/src/agent/commands/emulation.ts +80 -0
- package/src/agent/commands/execution.ts +9 -0
- package/src/agent/commands/help.ts +20 -0
- package/src/agent/commands/history.ts +13 -0
- package/src/agent/commands/index.ts +40 -0
- package/src/agent/commands/model.ts +11 -0
- package/src/agent/commands/models.ts +116 -0
- package/src/agent/commands/permissions.ts +64 -0
- package/src/agent/commands/retry.ts +9 -0
- package/src/agent/commands/shell.ts +68 -0
- package/src/agent/commands/skills.ts +54 -0
- package/src/agent/commands/status.ts +19 -0
- package/src/agent/commands/types.ts +78 -0
- package/src/agent/factory.ts +60 -0
- package/src/agent/index.ts +20 -0
- package/src/agent/runtime/capabilities.ts +6 -0
- package/src/agent/runtime/memory.ts +23 -0
- package/src/agent/runtime/policy.ts +48 -0
- package/src/agent/runtime/session.ts +18 -0
- package/src/agent/runtime/tracing.ts +23 -0
- package/src/agent/tools/file.ts +173 -0
- package/src/agent/tools/index.ts +46 -0
- package/src/agent/tools/search.ts +137 -0
- package/src/agent/tools/shell.ts +65 -0
- package/src/agent/tools/skills.ts +28 -0
- package/src/agent/tools/types.ts +10 -0
- package/src/agent/tools/zerg.ts +50 -0
- package/src/cli.tsx +80 -0
- package/src/components/FullScreen.tsx +73 -0
- package/src/components/Header.tsx +27 -0
- package/src/components/InputArea.tsx +551 -0
- package/src/components/MessageList.tsx +25 -0
- package/src/components/StatusBar.tsx +49 -0
- package/src/components/index.tsx +6 -0
- package/src/config/types.ts +11 -0
- package/src/config.ts +178 -0
- package/src/debug/logger.ts +14 -0
- package/src/emulation/README.md +24 -0
- package/src/emulation/catalog.ts +82 -0
- package/src/emulation/trace_style.ts +8 -0
- package/src/emulation/types.ts +7 -0
- package/src/skills/index.ts +36 -0
- package/src/skills/loader.ts +135 -0
- package/src/skills/registry.ts +6 -0
- package/src/skills/types.ts +10 -0
- package/src/types.ts +83 -0
- package/src/ui/README.md +44 -0
- package/src/ui/core/factory.ts +9 -0
- package/src/ui/core/index.ts +4 -0
- package/src/ui/core/input.ts +38 -0
- package/src/ui/core/input_segments.ts +375 -0
- package/src/ui/core/input_state.ts +17 -0
- package/src/ui/core/layout_yoga.ts +122 -0
- package/src/ui/core/style.ts +38 -0
- package/src/ui/core/types.ts +53 -0
- package/src/ui/ink/index.tsx +1 -0
- package/src/ui/ink/render.tsx +49 -0
- package/src/ui/views/app.ts +99 -0
- package/src/ui/views/header.ts +42 -0
- package/src/ui/views/input_area.ts +244 -0
- package/src/ui/views/message_list.ts +427 -0
- package/src/ui/views/status_bar.ts +104 -0
- package/src/ui/vue/index.ts +53 -0
- package/src/utils/clipboard.ts +39 -0
- package/src/utils/clipboard_image.ts +40 -0
- package/src/utils/diff.ts +52 -0
- package/src/utils/image_preview.ts +36 -0
- package/src/utils/models.ts +98 -0
- package/src/utils/shell.ts +63 -0
- package/src/utils/tool_summary.ts +56 -0
- package/src/utils/tool_trace.ts +206 -0
- package/tsconfig.json +22 -0
- package/vite.config.ts +363 -0
package/vite.config.ts
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import react from '@vitejs/plugin-react';
|
|
3
|
+
import { resolve, join, basename } from 'path';
|
|
4
|
+
import { mkdir, writeFile } from 'fs/promises';
|
|
5
|
+
import { homedir } from 'os';
|
|
6
|
+
import { randomUUID } from 'crypto';
|
|
7
|
+
import { loadEmulationProfiles } from './src/emulation/catalog.js';
|
|
8
|
+
import { configStore } from './src/config.js';
|
|
9
|
+
import { runShellCommand, resolveWorkingDir } from './src/utils/shell.js';
|
|
10
|
+
import { createAgentFromConfig } from './src/agent/factory.js';
|
|
11
|
+
import { listModels } from './src/utils/models.js';
|
|
12
|
+
import { autoActivateSkills, buildSkillPrompt } from './src/skills/index.js';
|
|
13
|
+
import { getSkillRegistry } from './src/skills/registry.js';
|
|
14
|
+
|
|
15
|
+
export default defineConfig({
|
|
16
|
+
root: 'web/dev',
|
|
17
|
+
plugins: [
|
|
18
|
+
react(),
|
|
19
|
+
{
|
|
20
|
+
name: 'ztc-emulation',
|
|
21
|
+
configureServer(server) {
|
|
22
|
+
let skillCache: any[] | null = null;
|
|
23
|
+
const loadSkills = async () => {
|
|
24
|
+
if (skillCache) return skillCache;
|
|
25
|
+
skillCache = await getSkillRegistry();
|
|
26
|
+
return skillCache;
|
|
27
|
+
};
|
|
28
|
+
server.middlewares.use('/__emulation/list', (_req, res) => {
|
|
29
|
+
const payload = JSON.stringify(loadEmulationProfiles().map(profile => ({
|
|
30
|
+
id: profile.id,
|
|
31
|
+
name: profile.name,
|
|
32
|
+
description: profile.description,
|
|
33
|
+
systemPrompt: profile.systemPrompt,
|
|
34
|
+
tools: profile.tools
|
|
35
|
+
})));
|
|
36
|
+
res.statusCode = 200;
|
|
37
|
+
res.setHeader('Content-Type', 'application/json');
|
|
38
|
+
res.end(payload);
|
|
39
|
+
});
|
|
40
|
+
server.middlewares.use('/__config/get', async (_req, res) => {
|
|
41
|
+
await configStore.load(true);
|
|
42
|
+
const payload = JSON.stringify({
|
|
43
|
+
config: configStore.get(),
|
|
44
|
+
locationLabel: configStore.getConfigPath()
|
|
45
|
+
});
|
|
46
|
+
res.statusCode = 200;
|
|
47
|
+
res.setHeader('Content-Type', 'application/json');
|
|
48
|
+
res.end(payload);
|
|
49
|
+
});
|
|
50
|
+
server.middlewares.use('/__config/save', async (req, res) => {
|
|
51
|
+
const body = await new Promise<string>((resolve) => {
|
|
52
|
+
let data = '';
|
|
53
|
+
req.on('data', chunk => { data += chunk; });
|
|
54
|
+
req.on('end', () => resolve(data));
|
|
55
|
+
});
|
|
56
|
+
try {
|
|
57
|
+
const parsed = JSON.parse(body) as { config?: Record<string, unknown> };
|
|
58
|
+
if (parsed.config && typeof parsed.config === 'object') {
|
|
59
|
+
configStore.setAll(parsed.config);
|
|
60
|
+
await configStore.save();
|
|
61
|
+
}
|
|
62
|
+
} catch {
|
|
63
|
+
// ignore invalid payloads
|
|
64
|
+
}
|
|
65
|
+
const payload = JSON.stringify({
|
|
66
|
+
config: configStore.get(),
|
|
67
|
+
locationLabel: configStore.getConfigPath()
|
|
68
|
+
});
|
|
69
|
+
res.statusCode = 200;
|
|
70
|
+
res.setHeader('Content-Type', 'application/json');
|
|
71
|
+
res.end(payload);
|
|
72
|
+
});
|
|
73
|
+
server.middlewares.use('/__shell/cwd', (_req, res) => {
|
|
74
|
+
const payload = JSON.stringify({ cwd: process.cwd() });
|
|
75
|
+
res.statusCode = 200;
|
|
76
|
+
res.setHeader('Content-Type', 'application/json');
|
|
77
|
+
res.end(payload);
|
|
78
|
+
});
|
|
79
|
+
server.middlewares.use('/__shell/resolve', async (req, res) => {
|
|
80
|
+
const body = await new Promise<string>((resolve) => {
|
|
81
|
+
let data = '';
|
|
82
|
+
req.on('data', chunk => { data += chunk; });
|
|
83
|
+
req.on('end', () => resolve(data));
|
|
84
|
+
});
|
|
85
|
+
try {
|
|
86
|
+
const parsed = JSON.parse(body) as { cwd?: string; path?: string };
|
|
87
|
+
const base = parsed.cwd || process.cwd();
|
|
88
|
+
const next = await resolveWorkingDir(base, parsed.path || '');
|
|
89
|
+
const payload = JSON.stringify({ cwd: next });
|
|
90
|
+
res.statusCode = 200;
|
|
91
|
+
res.setHeader('Content-Type', 'application/json');
|
|
92
|
+
res.end(payload);
|
|
93
|
+
return;
|
|
94
|
+
} catch (err) {
|
|
95
|
+
res.statusCode = 400;
|
|
96
|
+
res.setHeader('Content-Type', 'application/json');
|
|
97
|
+
res.end(JSON.stringify({ error: 'Invalid path' }));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
server.middlewares.use('/__shell/run', async (req, res) => {
|
|
102
|
+
const body = await new Promise<string>((resolve) => {
|
|
103
|
+
let data = '';
|
|
104
|
+
req.on('data', chunk => { data += chunk; });
|
|
105
|
+
req.on('end', () => resolve(data));
|
|
106
|
+
});
|
|
107
|
+
try {
|
|
108
|
+
const parsed = JSON.parse(body) as { command?: string; cwd?: string };
|
|
109
|
+
const command = parsed.command || '';
|
|
110
|
+
const cwd = parsed.cwd || process.cwd();
|
|
111
|
+
const result = await runShellCommand(command, cwd);
|
|
112
|
+
const payload = JSON.stringify(result);
|
|
113
|
+
res.statusCode = 200;
|
|
114
|
+
res.setHeader('Content-Type', 'application/json');
|
|
115
|
+
res.end(payload);
|
|
116
|
+
return;
|
|
117
|
+
} catch (err) {
|
|
118
|
+
res.statusCode = 500;
|
|
119
|
+
res.setHeader('Content-Type', 'application/json');
|
|
120
|
+
res.end(JSON.stringify({ error: 'Command failed' }));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
server.middlewares.use('/__upload', async (req, res) => {
|
|
125
|
+
if (req.method !== 'POST') {
|
|
126
|
+
res.statusCode = 405;
|
|
127
|
+
res.end();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const buffer = await new Promise<Buffer>((resolve) => {
|
|
131
|
+
const chunks: Buffer[] = [];
|
|
132
|
+
req.on('data', chunk => { chunks.push(Buffer.from(chunk)); });
|
|
133
|
+
req.on('end', () => resolve(Buffer.concat(chunks)));
|
|
134
|
+
});
|
|
135
|
+
const headerName = req.headers['x-filename'];
|
|
136
|
+
const rawName = typeof headerName === 'string' && headerName.trim().length > 0 ? headerName : 'upload.bin';
|
|
137
|
+
const safeName = basename(rawName).replace(/[^a-zA-Z0-9._-]/g, '_');
|
|
138
|
+
const dir = join(homedir(), '.ztc', 'uploads');
|
|
139
|
+
await mkdir(dir, { recursive: true });
|
|
140
|
+
const filePath = join(dir, `${Date.now()}-${randomUUID().slice(0, 8)}-${safeName}`);
|
|
141
|
+
await writeFile(filePath, buffer);
|
|
142
|
+
res.statusCode = 200;
|
|
143
|
+
res.setHeader('Content-Type', 'application/json');
|
|
144
|
+
res.end(JSON.stringify({ path: filePath }));
|
|
145
|
+
});
|
|
146
|
+
server.middlewares.use('/__file', async (req, res) => {
|
|
147
|
+
const url = new URL(req.url || '', 'http://localhost');
|
|
148
|
+
const rawPath = url.searchParams.get('path');
|
|
149
|
+
if (!rawPath) {
|
|
150
|
+
res.statusCode = 400;
|
|
151
|
+
res.end();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const allowedRoots = [
|
|
155
|
+
join(homedir(), '.ztc', 'uploads'),
|
|
156
|
+
join(homedir(), '.ztc', 'clipboard')
|
|
157
|
+
];
|
|
158
|
+
const resolvedPath = resolve(rawPath);
|
|
159
|
+
const allowed = allowedRoots.some(root => resolvedPath.startsWith(resolve(root)));
|
|
160
|
+
if (!allowed) {
|
|
161
|
+
res.statusCode = 403;
|
|
162
|
+
res.end();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
const data = await (await import('fs/promises')).readFile(resolvedPath);
|
|
167
|
+
res.statusCode = 200;
|
|
168
|
+
res.setHeader('Content-Type', 'application/octet-stream');
|
|
169
|
+
res.end(data);
|
|
170
|
+
} catch {
|
|
171
|
+
res.statusCode = 404;
|
|
172
|
+
res.end();
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
server.middlewares.use('/__agent/run', async (req, res) => {
|
|
176
|
+
const body = await new Promise<string>((resolve) => {
|
|
177
|
+
let data = '';
|
|
178
|
+
req.on('data', chunk => { data += chunk; });
|
|
179
|
+
req.on('end', () => resolve(data));
|
|
180
|
+
});
|
|
181
|
+
try {
|
|
182
|
+
const parsed = JSON.parse(body) as { messages?: unknown[] };
|
|
183
|
+
const messages = Array.isArray(parsed.messages) ? parsed.messages : [];
|
|
184
|
+
const lastUser = [...messages].reverse().find(msg => msg && typeof msg === 'object' && (msg as any).role === 'user');
|
|
185
|
+
const text = lastUser && typeof (lastUser as any).content === 'string' ? (lastUser as any).content : '';
|
|
186
|
+
const skills = await loadSkills();
|
|
187
|
+
const activated = autoActivateSkills(text, skills);
|
|
188
|
+
const skillPrompt = buildSkillPrompt(activated);
|
|
189
|
+
await configStore.load();
|
|
190
|
+
const provider = configStore.getProvider();
|
|
191
|
+
const apiKey = configStore.getApiKey(provider);
|
|
192
|
+
const agent = createAgentFromConfig({
|
|
193
|
+
config: configStore.get(),
|
|
194
|
+
provider,
|
|
195
|
+
apiKey,
|
|
196
|
+
openaiCompatibleBaseUrl: configStore.getOpenAICompatibleBaseUrl(),
|
|
197
|
+
emulationId: configStore.getEmulationId(),
|
|
198
|
+
skillPrompt
|
|
199
|
+
});
|
|
200
|
+
if (!agent) {
|
|
201
|
+
res.statusCode = 400;
|
|
202
|
+
res.setHeader('Content-Type', 'application/json');
|
|
203
|
+
res.end(JSON.stringify({ error: 'No API key configured' }));
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const result = await agent.run(messages as any);
|
|
207
|
+
res.statusCode = 200;
|
|
208
|
+
res.setHeader('Content-Type', 'application/json');
|
|
209
|
+
res.end(JSON.stringify({
|
|
210
|
+
content: result.content,
|
|
211
|
+
toolCalls: result.toolCalls,
|
|
212
|
+
usage: result.usage
|
|
213
|
+
}));
|
|
214
|
+
return;
|
|
215
|
+
} catch (err) {
|
|
216
|
+
const message = err instanceof Error ? err.message : 'Agent error';
|
|
217
|
+
res.statusCode = 500;
|
|
218
|
+
res.setHeader('Content-Type', 'application/json');
|
|
219
|
+
res.end(JSON.stringify({ error: message }));
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
server.middlewares.use('/__agent/stream', async (req, res) => {
|
|
223
|
+
const body = await new Promise<string>((resolve) => {
|
|
224
|
+
let data = '';
|
|
225
|
+
req.on('data', chunk => { data += chunk; });
|
|
226
|
+
req.on('end', () => resolve(data));
|
|
227
|
+
});
|
|
228
|
+
res.writeHead(200, {
|
|
229
|
+
'Content-Type': 'text/event-stream',
|
|
230
|
+
'Cache-Control': 'no-cache',
|
|
231
|
+
Connection: 'keep-alive'
|
|
232
|
+
});
|
|
233
|
+
const send = (event: string, payload: unknown) => {
|
|
234
|
+
res.write(`event: ${event}\n`);
|
|
235
|
+
res.write(`data: ${JSON.stringify(payload)}\n\n`);
|
|
236
|
+
};
|
|
237
|
+
let cleanup: (() => void) | null = null;
|
|
238
|
+
try {
|
|
239
|
+
const parsed = JSON.parse(body) as { messages?: unknown[] };
|
|
240
|
+
const messages = Array.isArray(parsed.messages) ? parsed.messages : [];
|
|
241
|
+
const lastUser = [...messages].reverse().find(msg => msg && typeof msg === 'object' && (msg as any).role === 'user');
|
|
242
|
+
const text = lastUser && typeof (lastUser as any).content === 'string' ? (lastUser as any).content : '';
|
|
243
|
+
const skills = await loadSkills();
|
|
244
|
+
const activated = autoActivateSkills(text, skills);
|
|
245
|
+
const skillPrompt = buildSkillPrompt(activated);
|
|
246
|
+
if (activated.length > 0) {
|
|
247
|
+
send('skill_activated', { skills: activated.map(skill => ({ id: skill.id, name: skill.name })) });
|
|
248
|
+
}
|
|
249
|
+
await configStore.load();
|
|
250
|
+
const provider = configStore.getProvider();
|
|
251
|
+
const apiKey = configStore.getApiKey(provider);
|
|
252
|
+
const agent = createAgentFromConfig({
|
|
253
|
+
config: configStore.get(),
|
|
254
|
+
provider,
|
|
255
|
+
apiKey,
|
|
256
|
+
openaiCompatibleBaseUrl: configStore.getOpenAICompatibleBaseUrl(),
|
|
257
|
+
emulationId: configStore.getEmulationId(),
|
|
258
|
+
skillPrompt
|
|
259
|
+
});
|
|
260
|
+
if (!agent) {
|
|
261
|
+
send('error', { error: 'No API key configured' });
|
|
262
|
+
res.end();
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
cleanup = agent.on((event) => {
|
|
266
|
+
if (event.type === 'stream_start') {
|
|
267
|
+
send('stream_start', {});
|
|
268
|
+
} else if (event.type === 'stream_delta') {
|
|
269
|
+
send('stream_delta', { content: event.content });
|
|
270
|
+
} else if (event.type === 'stream_end') {
|
|
271
|
+
send('stream_end', {});
|
|
272
|
+
} else if (event.type === 'token_usage') {
|
|
273
|
+
send('token_usage', { usage: event.usage });
|
|
274
|
+
} else if (event.type === 'tool_start') {
|
|
275
|
+
send('tool_start', { tool: event.tool, args: event.args });
|
|
276
|
+
} else if (event.type === 'tool_end') {
|
|
277
|
+
send('tool_end', { tool: event.tool, result: event.result });
|
|
278
|
+
} else if (event.type === 'tool_error') {
|
|
279
|
+
send('tool_error', { tool: event.tool, error: event.error });
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
const result = await agent.run(messages as any);
|
|
283
|
+
send('result', {
|
|
284
|
+
content: result.content,
|
|
285
|
+
toolCalls: result.toolCalls,
|
|
286
|
+
usage: result.usage
|
|
287
|
+
});
|
|
288
|
+
res.end();
|
|
289
|
+
} catch (err) {
|
|
290
|
+
const message = err instanceof Error ? err.message : 'Agent error';
|
|
291
|
+
send('error', { error: message });
|
|
292
|
+
res.end();
|
|
293
|
+
} finally {
|
|
294
|
+
cleanup?.();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
server.middlewares.use('/__models/list', async (req, res) => {
|
|
298
|
+
try {
|
|
299
|
+
await configStore.load();
|
|
300
|
+
const url = new URL(req.url || '', 'http://localhost');
|
|
301
|
+
const provider = url.searchParams.get('provider') || configStore.getProvider();
|
|
302
|
+
const models = await listModels({
|
|
303
|
+
provider,
|
|
304
|
+
apiKey: configStore.getApiKey(provider),
|
|
305
|
+
baseUrl: configStore.getOpenAICompatibleBaseUrl()
|
|
306
|
+
});
|
|
307
|
+
res.statusCode = 200;
|
|
308
|
+
res.setHeader('Content-Type', 'application/json');
|
|
309
|
+
res.end(JSON.stringify({ models }));
|
|
310
|
+
} catch (err) {
|
|
311
|
+
const message = err instanceof Error ? err.message : 'Models error';
|
|
312
|
+
res.statusCode = 500;
|
|
313
|
+
res.setHeader('Content-Type', 'application/json');
|
|
314
|
+
res.end(JSON.stringify({ error: message }));
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
server.middlewares.use('/__skills/list', async (_req, res) => {
|
|
318
|
+
try {
|
|
319
|
+
const skills = await loadSkills();
|
|
320
|
+
res.statusCode = 200;
|
|
321
|
+
res.setHeader('Content-Type', 'application/json');
|
|
322
|
+
res.end(JSON.stringify({ skills }));
|
|
323
|
+
} catch (err) {
|
|
324
|
+
const message = err instanceof Error ? err.message : 'Skills error';
|
|
325
|
+
res.statusCode = 500;
|
|
326
|
+
res.setHeader('Content-Type', 'application/json');
|
|
327
|
+
res.end(JSON.stringify({ error: message }));
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
],
|
|
333
|
+
esbuild: {
|
|
334
|
+
target: 'esnext'
|
|
335
|
+
},
|
|
336
|
+
resolve: {
|
|
337
|
+
alias: [
|
|
338
|
+
{ find: '@src', replacement: resolve(__dirname, 'src') }
|
|
339
|
+
]
|
|
340
|
+
},
|
|
341
|
+
build: {
|
|
342
|
+
target: 'esnext',
|
|
343
|
+
outDir: '../../dist-web',
|
|
344
|
+
emptyOutDir: true
|
|
345
|
+
},
|
|
346
|
+
optimizeDeps: {
|
|
347
|
+
esbuildOptions: {
|
|
348
|
+
target: 'esnext'
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
ssr: {
|
|
352
|
+
target: 'esnext'
|
|
353
|
+
},
|
|
354
|
+
define: {
|
|
355
|
+
'import.meta.env.LEGACY': 'false'
|
|
356
|
+
},
|
|
357
|
+
server: {
|
|
358
|
+
port: 5175,
|
|
359
|
+
fs: {
|
|
360
|
+
allow: ['.']
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
});
|