@jingyi0605/codingns4dsh 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 +1114 -0
- package/assets/provider-icons/claude-code.png +0 -0
- package/assets/provider-icons/codex.png +0 -0
- package/assets/provider-icons/command-code.svg +5 -0
- package/assets/provider-icons/deepseek-harness.svg +9 -0
- package/assets/provider-icons/gemini.png +0 -0
- package/assets/provider-icons/grok.png +0 -0
- package/assets/provider-icons/kimi.png +0 -0
- package/assets/provider-icons/opencode.png +0 -0
- package/assets/provider-icons/pi.svg +7 -0
- package/data/build/dist/bootstrap/dsh-connection-adapter.d.ts +97 -0
- package/data/build/dist/bootstrap/dsh-connection-adapter.js +169 -0
- package/data/build/dist/bootstrap/index.d.ts +38 -0
- package/data/build/dist/bootstrap/index.js +44 -0
- package/data/build/dist/client/account-bar.d.ts +9 -0
- package/data/build/dist/client/account-bar.js +398 -0
- package/data/build/dist/client/bundle.js +26167 -0
- package/data/build/dist/client/cli-catalog.d.ts +24 -0
- package/data/build/dist/client/cli-catalog.js +108 -0
- package/data/build/dist/client/cli-slots.d.ts +38 -0
- package/data/build/dist/client/cli-slots.js +297 -0
- package/data/build/dist/client/debug/ui.d.ts +12 -0
- package/data/build/dist/client/debug/ui.js +451 -0
- package/data/build/dist/client/dsh-h5-bootstrap.d.ts +64 -0
- package/data/build/dist/client/dsh-h5-bootstrap.js +293 -0
- package/data/build/dist/client/dsh-runtime-version.d.ts +3 -0
- package/data/build/dist/client/dsh-runtime-version.js +11 -0
- package/data/build/dist/client/external-tool-stream.d.ts +24 -0
- package/data/build/dist/client/external-tool-stream.js +114 -0
- package/data/build/dist/client/features/cli-adapters.d.ts +7 -0
- package/data/build/dist/client/features/cli-adapters.js +215 -0
- package/data/build/dist/client/features/debug.d.ts +4 -0
- package/data/build/dist/client/features/debug.js +24 -0
- package/data/build/dist/client/features/index.d.ts +33 -0
- package/data/build/dist/client/features/index.js +44 -0
- package/data/build/dist/client/features/lan-access-panel.d.ts +5 -0
- package/data/build/dist/client/features/lan-access-panel.js +146 -0
- package/data/build/dist/client/features/lan-access.d.ts +9 -0
- package/data/build/dist/client/features/lan-access.js +30 -0
- package/data/build/dist/client/features/login-protection-panel.d.ts +5 -0
- package/data/build/dist/client/features/login-protection-panel.js +91 -0
- package/data/build/dist/client/features/login-protection-session.d.ts +6 -0
- package/data/build/dist/client/features/login-protection-session.js +25 -0
- package/data/build/dist/client/features/login-protection.d.ts +4 -0
- package/data/build/dist/client/features/login-protection.js +23 -0
- package/data/build/dist/client/features/reverse-proxy-panel.d.ts +9 -0
- package/data/build/dist/client/features/reverse-proxy-panel.js +159 -0
- package/data/build/dist/client/features/reverse-proxy.d.ts +12 -0
- package/data/build/dist/client/features/reverse-proxy.js +112 -0
- package/data/build/dist/client/features/terminal-enhancement-panel.d.ts +5 -0
- package/data/build/dist/client/features/terminal-enhancement-panel.js +160 -0
- package/data/build/dist/client/features/terminal-enhancement.d.ts +4 -0
- package/data/build/dist/client/features/terminal-enhancement.js +24 -0
- package/data/build/dist/client/features/types.d.ts +58 -0
- package/data/build/dist/client/features/types.js +2 -0
- package/data/build/dist/client/features/workspace-session-enhancement-panel.d.ts +5 -0
- package/data/build/dist/client/features/workspace-session-enhancement-panel.js +66 -0
- package/data/build/dist/client/features/workspace-session-enhancement.d.ts +4 -0
- package/data/build/dist/client/features/workspace-session-enhancement.js +101 -0
- package/data/build/dist/client/h5-bootstrap-entry.d.ts +2 -0
- package/data/build/dist/client/h5-bootstrap-entry.js +17 -0
- package/data/build/dist/client/index.d.ts +31 -0
- package/data/build/dist/client/index.js +98 -0
- package/data/build/dist/client/lan-access.d.ts +28 -0
- package/data/build/dist/client/lan-access.js +68 -0
- package/data/build/dist/client/locale.d.ts +20 -0
- package/data/build/dist/client/locale.js +393 -0
- package/data/build/dist/client/provider-icon-assets.d.ts +2 -0
- package/data/build/dist/client/provider-icon-assets.js +23 -0
- package/data/build/dist/client/provider-icons.d.ts +19 -0
- package/data/build/dist/client/provider-icons.js +39 -0
- package/data/build/dist/client/remote-web-context.d.ts +57 -0
- package/data/build/dist/client/remote-web-context.js +939 -0
- package/data/build/dist/client/session-adapter-cache.d.ts +18 -0
- package/data/build/dist/client/session-adapter-cache.js +84 -0
- package/data/build/dist/client/settings-bridge.d.ts +32 -0
- package/data/build/dist/client/settings-bridge.js +126 -0
- package/data/build/dist/client/settings-section.d.ts +30 -0
- package/data/build/dist/client/settings-section.js +93 -0
- package/data/build/dist/client/subscription-slot.d.ts +18 -0
- package/data/build/dist/client/subscription-slot.js +223 -0
- package/data/build/dist/client/terminal/index.d.ts +4 -0
- package/data/build/dist/client/terminal/index.js +3 -0
- package/data/build/dist/client/terminal/model.d.ts +116 -0
- package/data/build/dist/client/terminal/model.js +435 -0
- package/data/build/dist/client/terminal/styles.d.ts +21 -0
- package/data/build/dist/client/terminal/styles.js +51 -0
- package/data/build/dist/client/terminal/ui.d.ts +19 -0
- package/data/build/dist/client/terminal/ui.js +257 -0
- package/data/build/dist/client/terminal/xterm-view.d.ts +13 -0
- package/data/build/dist/client/terminal/xterm-view.js +213 -0
- package/data/build/dist/client/theme.d.ts +56 -0
- package/data/build/dist/client/theme.js +186 -0
- package/data/build/dist/client/workspace-session-archive-dom.d.ts +29 -0
- package/data/build/dist/client/workspace-session-archive-dom.js +525 -0
- package/data/build/dist/client/workspace-session-fiber.d.ts +3 -0
- package/data/build/dist/client/workspace-session-fiber.js +33 -0
- package/data/build/dist/client/workspace-session-logo-dom.d.ts +26 -0
- package/data/build/dist/client/workspace-session-logo-dom.js +128 -0
- package/data/build/dist/features/index.d.ts +3 -0
- package/data/build/dist/features/index.js +2 -0
- package/data/build/dist/features/registry.d.ts +74 -0
- package/data/build/dist/features/registry.js +382 -0
- package/data/build/dist/features/resource-scope/index.d.ts +39 -0
- package/data/build/dist/features/resource-scope/index.js +161 -0
- package/data/build/dist/host/auth-session.d.ts +42 -0
- package/data/build/dist/host/auth-session.js +186 -0
- package/data/build/dist/host/cli-adapters/claude-driver.d.ts +14 -0
- package/data/build/dist/host/cli-adapters/claude-driver.js +103 -0
- package/data/build/dist/host/cli-adapters/codex-driver.d.ts +45 -0
- package/data/build/dist/host/cli-adapters/codex-driver.js +534 -0
- package/data/build/dist/host/cli-adapters/command-code-driver.d.ts +38 -0
- package/data/build/dist/host/cli-adapters/command-code-driver.js +394 -0
- package/data/build/dist/host/cli-adapters/command-code-subscription.d.ts +19 -0
- package/data/build/dist/host/cli-adapters/command-code-subscription.js +126 -0
- package/data/build/dist/host/cli-adapters/driver.d.ts +41 -0
- package/data/build/dist/host/cli-adapters/driver.js +2 -0
- package/data/build/dist/host/cli-adapters/dsh-message-projector.d.ts +37 -0
- package/data/build/dist/host/cli-adapters/dsh-message-projector.js +180 -0
- package/data/build/dist/host/cli-adapters/dsh-tool-history.d.ts +48 -0
- package/data/build/dist/host/cli-adapters/dsh-tool-history.js +373 -0
- package/data/build/dist/host/cli-adapters/feature.d.ts +7 -0
- package/data/build/dist/host/cli-adapters/feature.js +335 -0
- package/data/build/dist/host/cli-adapters/gemini-driver.d.ts +24 -0
- package/data/build/dist/host/cli-adapters/gemini-driver.js +427 -0
- package/data/build/dist/host/cli-adapters/grok-driver.d.ts +38 -0
- package/data/build/dist/host/cli-adapters/grok-driver.js +372 -0
- package/data/build/dist/host/cli-adapters/http-sse-client.d.ts +22 -0
- package/data/build/dist/host/cli-adapters/http-sse-client.js +99 -0
- package/data/build/dist/host/cli-adapters/interaction-events.d.ts +11 -0
- package/data/build/dist/host/cli-adapters/interaction-events.js +80 -0
- package/data/build/dist/host/cli-adapters/json-rpc-process.d.ts +65 -0
- package/data/build/dist/host/cli-adapters/json-rpc-process.js +256 -0
- package/data/build/dist/host/cli-adapters/kimi-driver.d.ts +21 -0
- package/data/build/dist/host/cli-adapters/kimi-driver.js +382 -0
- package/data/build/dist/host/cli-adapters/model-catalog.d.ts +22 -0
- package/data/build/dist/host/cli-adapters/model-catalog.js +89 -0
- package/data/build/dist/host/cli-adapters/opencode-driver.d.ts +55 -0
- package/data/build/dist/host/cli-adapters/opencode-driver.js +728 -0
- package/data/build/dist/host/cli-adapters/pi-driver.d.ts +43 -0
- package/data/build/dist/host/cli-adapters/pi-driver.js +312 -0
- package/data/build/dist/host/cli-adapters/process-utils.d.ts +16 -0
- package/data/build/dist/host/cli-adapters/process-utils.js +27 -0
- package/data/build/dist/host/cli-adapters/provider-subscription.d.ts +82 -0
- package/data/build/dist/host/cli-adapters/provider-subscription.js +610 -0
- package/data/build/dist/host/cli-adapters/registry.d.ts +95 -0
- package/data/build/dist/host/cli-adapters/registry.js +659 -0
- package/data/build/dist/host/cli-adapters/rpc-driver-utils.d.ts +24 -0
- package/data/build/dist/host/cli-adapters/rpc-driver-utils.js +119 -0
- package/data/build/dist/host/cli-adapters/session-probe.d.ts +20 -0
- package/data/build/dist/host/cli-adapters/session-probe.js +139 -0
- package/data/build/dist/host/cli-adapters/session-store.d.ts +68 -0
- package/data/build/dist/host/cli-adapters/session-store.js +180 -0
- package/data/build/dist/host/cli-adapters/standard-stream-driver.d.ts +45 -0
- package/data/build/dist/host/cli-adapters/standard-stream-driver.js +205 -0
- package/data/build/dist/host/cli-adapters/stream-normalizer.d.ts +25 -0
- package/data/build/dist/host/cli-adapters/stream-normalizer.js +83 -0
- package/data/build/dist/host/cli-adapters/tool-observation.d.ts +9 -0
- package/data/build/dist/host/cli-adapters/tool-observation.js +39 -0
- package/data/build/dist/host/control-api-client.d.ts +84 -0
- package/data/build/dist/host/control-api-client.js +130 -0
- package/data/build/dist/host/credential-store.d.ts +54 -0
- package/data/build/dist/host/credential-store.js +114 -0
- package/data/build/dist/host/debug.d.ts +79 -0
- package/data/build/dist/host/debug.js +295 -0
- package/data/build/dist/host/dsh-device-runtime.d.ts +39 -0
- package/data/build/dist/host/dsh-device-runtime.js +118 -0
- package/data/build/dist/host/dsh-gateway-feature.d.ts +5 -0
- package/data/build/dist/host/dsh-gateway-feature.js +55 -0
- package/data/build/dist/host/dsh-runtime-version.d.ts +12 -0
- package/data/build/dist/host/dsh-runtime-version.js +69 -0
- package/data/build/dist/host/features/auth.d.ts +11 -0
- package/data/build/dist/host/features/auth.js +273 -0
- package/data/build/dist/host/features/debug.d.ts +5 -0
- package/data/build/dist/host/features/debug.js +90 -0
- package/data/build/dist/host/features/host-status.d.ts +12 -0
- package/data/build/dist/host/features/host-status.js +54 -0
- package/data/build/dist/host/features/index.d.ts +19 -0
- package/data/build/dist/host/features/index.js +29 -0
- package/data/build/dist/host/features/lan-access-dsh.d.ts +8 -0
- package/data/build/dist/host/features/lan-access-dsh.js +45 -0
- package/data/build/dist/host/features/terminal-process.d.ts +5 -0
- package/data/build/dist/host/features/terminal-process.js +110 -0
- package/data/build/dist/host/features/terminal-status.d.ts +18 -0
- package/data/build/dist/host/features/terminal-status.js +56 -0
- package/data/build/dist/host/features/types.d.ts +41 -0
- package/data/build/dist/host/features/types.js +2 -0
- package/data/build/dist/host/index.d.ts +43 -0
- package/data/build/dist/host/index.js +135 -0
- package/data/build/dist/host/lan-access-dsh.d.ts +83 -0
- package/data/build/dist/host/lan-access-dsh.js +831 -0
- package/data/build/dist/host/native-session-bridge.d.ts +130 -0
- package/data/build/dist/host/native-session-bridge.js +317 -0
- package/data/build/dist/host/relay-tunnel-runtime.d.ts +97 -0
- package/data/build/dist/host/relay-tunnel-runtime.js +361 -0
- package/data/build/dist/host/remote-web-runtime.d.ts +78 -0
- package/data/build/dist/host/remote-web-runtime.js +559 -0
- package/data/build/dist/host/rpc-table.d.ts +32 -0
- package/data/build/dist/host/rpc-table.js +47 -0
- package/data/build/dist/host/rpc.d.ts +18 -0
- package/data/build/dist/host/rpc.js +248 -0
- package/data/build/dist/host/settings.d.ts +19 -0
- package/data/build/dist/host/settings.js +80 -0
- package/data/build/dist/host/terminal/attachment-registry.d.ts +17 -0
- package/data/build/dist/host/terminal/attachment-registry.js +49 -0
- package/data/build/dist/host/terminal/backends/conpty-backend.d.ts +39 -0
- package/data/build/dist/host/terminal/backends/conpty-backend.js +160 -0
- package/data/build/dist/host/terminal/backends/local-pty-backend.d.ts +36 -0
- package/data/build/dist/host/terminal/backends/local-pty-backend.js +178 -0
- package/data/build/dist/host/terminal/backends/tmux-backend.d.ts +40 -0
- package/data/build/dist/host/terminal/backends/tmux-backend.js +191 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-client.d.ts +27 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-client.js +154 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-process.d.ts +10 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-process.js +147 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-protocol.d.ts +92 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-protocol.js +134 -0
- package/data/build/dist/host/terminal/controller-factory.d.ts +37 -0
- package/data/build/dist/host/terminal/controller-factory.js +82 -0
- package/data/build/dist/host/terminal/index.d.ts +17 -0
- package/data/build/dist/host/terminal/index.js +17 -0
- package/data/build/dist/host/terminal/runtime-adapter.d.ts +77 -0
- package/data/build/dist/host/terminal/runtime-adapter.js +18 -0
- package/data/build/dist/host/terminal/runtime-manager.d.ts +41 -0
- package/data/build/dist/host/terminal/runtime-manager.js +179 -0
- package/data/build/dist/host/terminal/shell-detection.d.ts +23 -0
- package/data/build/dist/host/terminal/shell-detection.js +105 -0
- package/data/build/dist/host/terminal/startup.d.ts +33 -0
- package/data/build/dist/host/terminal/startup.js +100 -0
- package/data/build/dist/host/terminal/terminal-controller.d.ts +78 -0
- package/data/build/dist/host/terminal/terminal-controller.js +324 -0
- package/data/build/dist/host/terminal/terminal-process-service.d.ts +30 -0
- package/data/build/dist/host/terminal/terminal-process-service.js +194 -0
- package/data/build/dist/host/terminal/terminal-process-store.d.ts +45 -0
- package/data/build/dist/host/terminal/terminal-process-store.js +183 -0
- package/data/build/dist/host/terminal/terminal-service.d.ts +87 -0
- package/data/build/dist/host/terminal/terminal-service.js +528 -0
- package/data/build/dist/host/terminal/terminal-store.d.ts +49 -0
- package/data/build/dist/host/terminal/terminal-store.js +242 -0
- package/data/build/dist/index.d.ts +37 -0
- package/data/build/dist/index.js +26 -0
- package/data/build/dist/shared/contracts/auth.d.ts +122 -0
- package/data/build/dist/shared/contracts/auth.js +8 -0
- package/data/build/dist/shared/contracts/cli-adapter.d.ts +192 -0
- package/data/build/dist/shared/contracts/cli-adapter.js +2 -0
- package/data/build/dist/shared/contracts/command-code.d.ts +5 -0
- package/data/build/dist/shared/contracts/command-code.js +2 -0
- package/data/build/dist/shared/contracts/config.d.ts +113 -0
- package/data/build/dist/shared/contracts/config.js +86 -0
- package/data/build/dist/shared/contracts/debug-config.d.ts +28 -0
- package/data/build/dist/shared/contracts/debug-config.js +78 -0
- package/data/build/dist/shared/contracts/debug.d.ts +75 -0
- package/data/build/dist/shared/contracts/debug.js +121 -0
- package/data/build/dist/shared/contracts/dsh-device.d.ts +72 -0
- package/data/build/dist/shared/contracts/dsh-device.js +2 -0
- package/data/build/dist/shared/contracts/errors.d.ts +33 -0
- package/data/build/dist/shared/contracts/errors.js +41 -0
- package/data/build/dist/shared/contracts/feature.d.ts +71 -0
- package/data/build/dist/shared/contracts/feature.js +2 -0
- package/data/build/dist/shared/contracts/host-status.d.ts +14 -0
- package/data/build/dist/shared/contracts/host-status.js +2 -0
- package/data/build/dist/shared/contracts/lan-access-dsh.d.ts +30 -0
- package/data/build/dist/shared/contracts/lan-access-dsh.js +2 -0
- package/data/build/dist/shared/contracts/peer-host.d.ts +37 -0
- package/data/build/dist/shared/contracts/peer-host.js +9 -0
- package/data/build/dist/shared/contracts/signaling.d.ts +67 -0
- package/data/build/dist/shared/contracts/signaling.js +2 -0
- package/data/build/dist/shared/contracts/subscription.d.ts +69 -0
- package/data/build/dist/shared/contracts/subscription.js +2 -0
- package/data/build/dist/shared/contracts/terminal-process.d.ts +65 -0
- package/data/build/dist/shared/contracts/terminal-process.js +2 -0
- package/data/build/dist/shared/contracts/terminal.d.ts +127 -0
- package/data/build/dist/shared/contracts/terminal.js +2 -0
- package/data/build/dist/shared/contracts/transport.d.ts +45 -0
- package/data/build/dist/shared/contracts/transport.js +3 -0
- package/data/build/dist/shared/contracts/version.d.ts +19 -0
- package/data/build/dist/shared/contracts/version.js +74 -0
- package/data/build/dist/shared/index.d.ts +22 -0
- package/data/build/dist/shared/index.js +9 -0
- package/data/build/dist/transport/carrier.d.ts +38 -0
- package/data/build/dist/transport/carrier.js +268 -0
- package/data/build/dist/transport/debug.d.ts +22 -0
- package/data/build/dist/transport/debug.js +57 -0
- package/data/build/dist/transport/dsh-envelope.d.ts +41 -0
- package/data/build/dist/transport/dsh-envelope.js +107 -0
- package/data/build/dist/transport/dsh-gateway.d.ts +64 -0
- package/data/build/dist/transport/dsh-gateway.js +254 -0
- package/data/build/dist/transport/dsh-session.d.ts +55 -0
- package/data/build/dist/transport/dsh-session.js +256 -0
- package/data/build/dist/transport/dsh-transport.d.ts +57 -0
- package/data/build/dist/transport/dsh-transport.js +125 -0
- package/data/build/dist/transport/frame.d.ts +132 -0
- package/data/build/dist/transport/frame.js +168 -0
- package/data/build/dist/transport/index.d.ts +11 -0
- package/data/build/dist/transport/index.js +11 -0
- package/data/build/dist/transport/multiplexer.d.ts +63 -0
- package/data/build/dist/transport/multiplexer.js +323 -0
- package/data/build/dist/transport/webrtc-client.d.ts +65 -0
- package/data/build/dist/transport/webrtc-client.js +255 -0
- package/data/build/dist/transport/webrtc-host.d.ts +58 -0
- package/data/build/dist/transport/webrtc-host.js +252 -0
- package/data/build/dist/typert.host.d.ts +25 -0
- package/data/build/dist/typert.host.js +150 -0
- package/dsh.bundle.patch +12 -0
- package/package.json +135 -0
- package/profile/README.md +27 -0
- package/profile/cordis.patch.yml +2 -0
- package/profile/package.json +20 -0
- package/profile/scripts/check-dsh-install.mjs +71 -0
- package/profile/version.json +5 -0
- package/scripts/check-dsh-install.mjs +88 -0
- package/version.json +6 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { homedir, tmpdir } from 'node:os';
|
|
3
|
+
import { basename, join } from 'node:path';
|
|
4
|
+
import { StandardStreamDriver, emptyCatalog } from './standard-stream-driver.js';
|
|
5
|
+
import { JsonRpcProcess } from './json-rpc-process.js';
|
|
6
|
+
import { isRecord, streamRpcRequest, textValue, usageChunk } from './rpc-driver-utils.js';
|
|
7
|
+
import { GEMINI_CATALOG, isProviderDefaultModel, resolveGeminiEfforts } from './model-catalog.js';
|
|
8
|
+
import { probeStoredSession, readFirstJsonRecord } from './session-probe.js';
|
|
9
|
+
import { firstToolText, isToolRecord, normalizeToolStatus, serializeToolValue } from './tool-observation.js';
|
|
10
|
+
/** Gemini 官方 ACP 优先;不支持 ACP 的旧 CLI 自动回退 headless stream-json。 */
|
|
11
|
+
export class GeminiCliDriver extends StandardStreamDriver {
|
|
12
|
+
sessionRoots;
|
|
13
|
+
interactions = new Map();
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
super({ id: 'gemini', name: 'Gemini CLI', protocol: 'acp', capabilities: ['models', 'stream', 'resume', 'interrupt', 'tool-events', 'reasoning', 'usage', 'permission'] }, { binaries: ['gemini'] }, options);
|
|
16
|
+
this.sessionRoots = options.sessionRoots ?? [join(process.env.GEMINI_CLI_HOME ?? join(homedir(), '.gemini'), 'tmp')];
|
|
17
|
+
}
|
|
18
|
+
async listModels() {
|
|
19
|
+
const command = (await this.detect()).command;
|
|
20
|
+
if (command === null)
|
|
21
|
+
return emptyCatalog();
|
|
22
|
+
const rpc = new JsonRpcProcess({ command, args: ['--acp'], spawn: this.runSpawn });
|
|
23
|
+
const controller = new AbortController();
|
|
24
|
+
const timer = setTimeout(() => controller.abort(), 12_000);
|
|
25
|
+
try {
|
|
26
|
+
await rpc.request('initialize', {
|
|
27
|
+
protocolVersion: 1,
|
|
28
|
+
clientInfo: { name: 'codingns4dsh', version: '0.1.0' },
|
|
29
|
+
clientCapabilities: {},
|
|
30
|
+
}, { signal: controller.signal });
|
|
31
|
+
const session = await rpc.request('session/new', {
|
|
32
|
+
cwd: process.cwd(),
|
|
33
|
+
mcpServers: [],
|
|
34
|
+
}, { signal: controller.signal });
|
|
35
|
+
const catalog = parseGeminiCatalog(session);
|
|
36
|
+
return catalog.groups.length > 0 ? catalog : GEMINI_CATALOG;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return GEMINI_CATALOG;
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
await rpc.disposeAndWait();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async probeSession(input) {
|
|
47
|
+
return probeStoredSession(input, {
|
|
48
|
+
roots: this.sessionRoots,
|
|
49
|
+
matches: (path, entry, id) => entry.isFile() && basename(path).endsWith('.jsonl') && basename(path).includes(id.split('-')[0] ?? id),
|
|
50
|
+
validate: async (path, id) => (await readFirstJsonRecord(path))?.sessionId === id,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
buildArgs(input) {
|
|
54
|
+
const args = ['-p', input.prompt, '--output-format', 'stream-json', '--yolo'];
|
|
55
|
+
if (input.providerSessionId)
|
|
56
|
+
args.push('--resume', input.providerSessionId);
|
|
57
|
+
if (input.modelId && !isProviderDefaultModel(input.modelId))
|
|
58
|
+
args.push('--model', input.modelId);
|
|
59
|
+
return args;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Gemini 的旧版 stream-json 会先回放一条 role=user 的消息。
|
|
63
|
+
* 这条记录只是输入回显,不能投影成 DSH 的 assistant 正文;result 还要按
|
|
64
|
+
* Gemini 自己的 status 和 stats 字段生成正确的终态与用量。
|
|
65
|
+
*/
|
|
66
|
+
parseEvent(value, input) {
|
|
67
|
+
const type = typeof value.type === 'string' ? value.type.toLowerCase() : '';
|
|
68
|
+
if (type === 'message') {
|
|
69
|
+
const role = typeof value.role === 'string' ? value.role.toLowerCase() : '';
|
|
70
|
+
if (role === 'user')
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
if (type === 'result')
|
|
74
|
+
return geminiStreamResultChunks(value, input.signal?.aborted ?? false);
|
|
75
|
+
return super.parseEvent(value, input);
|
|
76
|
+
}
|
|
77
|
+
respondPermission(sessionId, response) {
|
|
78
|
+
const state = this.interactions.get(sessionId);
|
|
79
|
+
const rpcId = state?.permissions.get(response.requestId);
|
|
80
|
+
if (state === undefined || rpcId === undefined)
|
|
81
|
+
throw new Error('Gemini 权限请求不存在');
|
|
82
|
+
state.permissions.delete(response.requestId);
|
|
83
|
+
state.rpc.respond(rpcId, { outcome: { outcome: 'selected', optionId: response.approved ? 'allow-once' : 'reject-once' } });
|
|
84
|
+
}
|
|
85
|
+
dispose() {
|
|
86
|
+
this.interactions.clear();
|
|
87
|
+
super.dispose();
|
|
88
|
+
}
|
|
89
|
+
async *executeTurn(input) {
|
|
90
|
+
try {
|
|
91
|
+
yield* this.executeAcpTurn(input);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
if (input.signal?.aborted) {
|
|
96
|
+
yield { type: 'finish', reason: 'cancel' };
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
for await (const chunk of super.executeTurn(input))
|
|
100
|
+
yield chunk;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async *executeAcpTurn(input) {
|
|
104
|
+
const detection = await this.detect();
|
|
105
|
+
const command = detection.command;
|
|
106
|
+
if (command === null)
|
|
107
|
+
throw new Error('Gemini CLI 未安装');
|
|
108
|
+
const runtimeSettings = await createGeminiRuntimeSettings(input.modelId, input.effortId);
|
|
109
|
+
const rpc = new JsonRpcProcess({
|
|
110
|
+
command,
|
|
111
|
+
args: ['--experimental-acp'],
|
|
112
|
+
cwd: input.cwd,
|
|
113
|
+
...(runtimeSettings === null ? {} : { env: runtimeSettings.env }),
|
|
114
|
+
spawn: this.runSpawn,
|
|
115
|
+
});
|
|
116
|
+
const interaction = {
|
|
117
|
+
rpc,
|
|
118
|
+
permissions: new Map(),
|
|
119
|
+
};
|
|
120
|
+
this.interactions.set(input.sessionId, interaction);
|
|
121
|
+
rpc.setServerRequestHandler((message) => {
|
|
122
|
+
const requestId = interactionRequestId(message);
|
|
123
|
+
if (requestId === null || message.id === undefined || message.id === null)
|
|
124
|
+
return { outcome: { outcome: 'cancelled' } };
|
|
125
|
+
interaction.permissions.set(requestId, message.id);
|
|
126
|
+
return new Promise(() => undefined);
|
|
127
|
+
});
|
|
128
|
+
try {
|
|
129
|
+
await rpc.request('initialize', {
|
|
130
|
+
protocolVersion: 1,
|
|
131
|
+
clientInfo: { name: 'codingns4dsh', version: '0.1.0' },
|
|
132
|
+
clientCapabilities: {},
|
|
133
|
+
}, { signal: input.signal });
|
|
134
|
+
rpc.notify('initialized', {});
|
|
135
|
+
const session = input.providerSessionId
|
|
136
|
+
? await rpc.request('session/load', { sessionId: input.providerSessionId, cwd: input.cwd ?? process.cwd(), mcpServers: [] }, { signal: input.signal })
|
|
137
|
+
: await rpc.request('session/new', { cwd: input.cwd ?? process.cwd(), mcpServers: [] }, { signal: input.signal });
|
|
138
|
+
const sessionId = readSessionId(session) ?? input.providerSessionId ?? input.sessionId;
|
|
139
|
+
yield { type: 'session-binding', providerSessionId: sessionId };
|
|
140
|
+
if (input.modelId && !isProviderDefaultModel(input.modelId)) {
|
|
141
|
+
await rpc.request('session/set_model', { sessionId, modelId: input.modelId }, { signal: input.signal });
|
|
142
|
+
}
|
|
143
|
+
let finished = false;
|
|
144
|
+
const stream = streamRpcRequest(rpc, 'session/prompt', {
|
|
145
|
+
sessionId,
|
|
146
|
+
prompt: [{ type: 'text', text: input.prompt }],
|
|
147
|
+
}, input.signal);
|
|
148
|
+
let promptResponse;
|
|
149
|
+
while (true) {
|
|
150
|
+
const item = await stream.next();
|
|
151
|
+
if (item.done) {
|
|
152
|
+
promptResponse = item.value;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
const chunk = geminiAcpMessageToChunk(item.value);
|
|
156
|
+
if (chunk?.type === 'finish')
|
|
157
|
+
finished = true;
|
|
158
|
+
if (chunk !== null)
|
|
159
|
+
yield chunk;
|
|
160
|
+
}
|
|
161
|
+
if (!finished)
|
|
162
|
+
yield { type: 'finish', reason: geminiPromptReason(promptResponse, input.signal) };
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
if (this.interactions.get(input.sessionId) === interaction)
|
|
166
|
+
this.interactions.delete(input.sessionId);
|
|
167
|
+
await rpc.disposeAndWait();
|
|
168
|
+
await runtimeSettings?.dispose();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function geminiPromptReason(value, signal) {
|
|
173
|
+
if (signal?.aborted)
|
|
174
|
+
return 'cancel';
|
|
175
|
+
if (!isRecord(value) || typeof value.stopReason !== 'string')
|
|
176
|
+
return 'stop';
|
|
177
|
+
const reason = value.stopReason.toLowerCase();
|
|
178
|
+
if (reason === 'cancelled')
|
|
179
|
+
return 'cancel';
|
|
180
|
+
if (reason === 'error' || reason === 'failed')
|
|
181
|
+
return 'error';
|
|
182
|
+
return 'stop';
|
|
183
|
+
}
|
|
184
|
+
function parseGeminiCatalog(value) {
|
|
185
|
+
if (!isRecord(value) || !isRecord(value.models) || !Array.isArray(value.models.availableModels))
|
|
186
|
+
return emptyCatalog();
|
|
187
|
+
const models = value.models.availableModels.flatMap((entry) => {
|
|
188
|
+
if (!isRecord(entry) || typeof entry.modelId !== 'string' || entry.modelId.trim() === '')
|
|
189
|
+
return [];
|
|
190
|
+
const id = entry.modelId.trim();
|
|
191
|
+
return [{
|
|
192
|
+
id,
|
|
193
|
+
name: typeof entry.name === 'string' && entry.name.trim() ? entry.name.trim() : id,
|
|
194
|
+
...(typeof entry.description === 'string' && entry.description.trim() ? { description: entry.description.trim() } : {}),
|
|
195
|
+
efforts: resolveGeminiEfforts(id),
|
|
196
|
+
}];
|
|
197
|
+
});
|
|
198
|
+
if (models.length === 0)
|
|
199
|
+
return emptyCatalog();
|
|
200
|
+
const currentModel = typeof value.models.currentModelId === 'string' && value.models.currentModelId.trim()
|
|
201
|
+
? value.models.currentModelId.trim()
|
|
202
|
+
: null;
|
|
203
|
+
return { groups: [{ id: 'gemini', name: 'Gemini', models }], currentModel, currentEffort: null };
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Gemini ACP 尚未实现 session/set_config_option。这里为单次 CLI 进程生成临时配置,
|
|
207
|
+
* 既不改写用户设置,也确保界面选择的思考档位真正进入 generateContent 配置。
|
|
208
|
+
*/
|
|
209
|
+
async function createGeminiRuntimeSettings(modelId, effortId) {
|
|
210
|
+
if (!modelId || !effortId || isProviderDefaultModel(modelId))
|
|
211
|
+
return null;
|
|
212
|
+
const efforts = resolveGeminiEfforts(modelId);
|
|
213
|
+
if (!efforts.includes(effortId))
|
|
214
|
+
return null;
|
|
215
|
+
const thinkingConfig = geminiThinkingConfig(modelId, effortId);
|
|
216
|
+
if (thinkingConfig === null)
|
|
217
|
+
return null;
|
|
218
|
+
const candidates = geminiSettingsCandidates();
|
|
219
|
+
let selected = null;
|
|
220
|
+
for (const candidate of candidates) {
|
|
221
|
+
const settings = await readSettingsFile(candidate.path);
|
|
222
|
+
if (settings.kind === 'invalid')
|
|
223
|
+
continue;
|
|
224
|
+
// 已存在的管理员级 System Settings 必须保留最终决定权,此时降级写入低优先级 defaults。
|
|
225
|
+
if (candidate.envName === 'GEMINI_CLI_SYSTEM_SETTINGS_PATH' && settings.kind === 'valid')
|
|
226
|
+
continue;
|
|
227
|
+
selected = { envName: candidate.envName, value: settings.value };
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
if (selected === null)
|
|
231
|
+
return null;
|
|
232
|
+
const modelConfigs = isRecord(selected.value.modelConfigs) ? selected.value.modelConfigs : {};
|
|
233
|
+
const customOverrides = Array.isArray(modelConfigs.customOverrides) ? modelConfigs.customOverrides : [];
|
|
234
|
+
const settings = {
|
|
235
|
+
...selected.value,
|
|
236
|
+
modelConfigs: {
|
|
237
|
+
...modelConfigs,
|
|
238
|
+
customOverrides: [
|
|
239
|
+
...customOverrides,
|
|
240
|
+
...geminiOverrideModels(modelId).map((model) => ({
|
|
241
|
+
match: { model },
|
|
242
|
+
modelConfig: { generateContentConfig: { thinkingConfig } },
|
|
243
|
+
})),
|
|
244
|
+
],
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
const directory = await mkdtemp(join(tmpdir(), 'codingns4dsh-gemini-'));
|
|
248
|
+
const settingsPath = join(directory, 'settings.json');
|
|
249
|
+
try {
|
|
250
|
+
await writeFile(settingsPath, `${JSON.stringify(settings)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
await rm(directory, { recursive: true, force: true });
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
env: { [selected.envName]: settingsPath },
|
|
258
|
+
dispose: async () => { await rm(directory, { recursive: true, force: true }); },
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function geminiThinkingConfig(modelId, effortId) {
|
|
262
|
+
if (modelId.toLowerCase().includes('2.5')) {
|
|
263
|
+
const highBudget = modelId.toLowerCase().includes('pro') ? 32_768 : 24_576;
|
|
264
|
+
const budgets = { low: 1_024, medium: 8_192, high: highBudget };
|
|
265
|
+
const thinkingBudget = budgets[effortId];
|
|
266
|
+
return thinkingBudget === undefined ? null : { thinkingBudget };
|
|
267
|
+
}
|
|
268
|
+
return { thinkingLevel: effortId.toUpperCase() };
|
|
269
|
+
}
|
|
270
|
+
function geminiOverrideModels(modelId) {
|
|
271
|
+
switch (modelId.toLowerCase()) {
|
|
272
|
+
case 'auto':
|
|
273
|
+
case 'auto-gemini-3':
|
|
274
|
+
return ['gemini-3.1-pro-preview-customtools', 'gemini-3.1-pro-preview', 'gemini-3-pro-preview', 'gemini-3-flash-preview'];
|
|
275
|
+
case 'auto-gemini-2.5':
|
|
276
|
+
return ['gemini-2.5-pro', 'gemini-2.5-flash'];
|
|
277
|
+
default:
|
|
278
|
+
return [modelId];
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function geminiSettingsCandidates() {
|
|
282
|
+
const systemDirectory = process.platform === 'darwin'
|
|
283
|
+
? '/Library/Application Support/GeminiCli'
|
|
284
|
+
: process.platform === 'win32'
|
|
285
|
+
? join(process.env.PROGRAMDATA ?? 'C:\\ProgramData', 'gemini-cli')
|
|
286
|
+
: '/etc/gemini-cli';
|
|
287
|
+
return [
|
|
288
|
+
{
|
|
289
|
+
envName: 'GEMINI_CLI_SYSTEM_SETTINGS_PATH',
|
|
290
|
+
path: process.env.GEMINI_CLI_SYSTEM_SETTINGS_PATH ?? join(systemDirectory, 'settings.json'),
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
envName: 'GEMINI_CLI_SYSTEM_DEFAULTS_PATH',
|
|
294
|
+
path: process.env.GEMINI_CLI_SYSTEM_DEFAULTS_PATH ?? join(systemDirectory, 'system-defaults.json'),
|
|
295
|
+
},
|
|
296
|
+
];
|
|
297
|
+
}
|
|
298
|
+
async function readSettingsFile(path) {
|
|
299
|
+
try {
|
|
300
|
+
const parsed = JSON.parse(await readFile(path, 'utf8'));
|
|
301
|
+
return isRecord(parsed) ? { kind: 'valid', value: parsed } : { kind: 'invalid' };
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
if (isRecord(error) && error.code === 'ENOENT')
|
|
305
|
+
return { kind: 'missing', value: {} };
|
|
306
|
+
return { kind: 'invalid' };
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function geminiAcpMessageToChunk(message) {
|
|
310
|
+
const params = isRecord(message.params) ? message.params : message;
|
|
311
|
+
const update = isRecord(params.update) ? params.update : params;
|
|
312
|
+
const method = typeof message.method === 'string' ? message.method.toLowerCase() : '';
|
|
313
|
+
const type = typeof update.sessionUpdate === 'string' ? update.sessionUpdate.toLowerCase() : typeof update.type === 'string' ? update.type.toLowerCase() : '';
|
|
314
|
+
const text = acpText(update.delta ?? update.text ?? update.content ?? update.message);
|
|
315
|
+
if (method.includes('permission') || type.includes('permission')) {
|
|
316
|
+
const requestId = interactionRequestId(message);
|
|
317
|
+
if (requestId)
|
|
318
|
+
return { type: 'permission-request', requestId, kind: firstString(update, ['kind', 'permission']) ?? 'unknown', ...(text ? { detail: text } : {}) };
|
|
319
|
+
}
|
|
320
|
+
if (type.includes('thought') || type.includes('reason') || method.includes('reason'))
|
|
321
|
+
return text ? { type: 'reasoning-delta', text } : null;
|
|
322
|
+
// ACP 可能回放用户消息;它不是模型正文。
|
|
323
|
+
if (type.includes('user') && type.includes('message'))
|
|
324
|
+
return null;
|
|
325
|
+
if (type.includes('agent_message') || type.includes('message') || type.includes('text') || method.includes('message'))
|
|
326
|
+
return text ? { type: 'text-delta', text } : null;
|
|
327
|
+
if (type.includes('tool') || type.includes('command')) {
|
|
328
|
+
const tool = isToolRecord(update.toolCall) ? update.toolCall : isToolRecord(update.tool_call) ? update.tool_call : update;
|
|
329
|
+
const name = firstToolText(tool.name, tool.toolName, tool.tool_name, tool.title, update.name, update.toolName, update.tool_name, update.title);
|
|
330
|
+
const callId = firstToolText(tool.callId, tool.call_id, tool.toolCallId, tool.tool_call_id, tool.toolUseId, tool.tool_use_id, tool.id, update.toolCallId, update.tool_call_id, update.toolUseId, update.tool_use_id, update.id);
|
|
331
|
+
if (name || callId) {
|
|
332
|
+
const input = serializeToolValue(tool.rawInput ?? tool.input ?? tool.arguments ?? tool.args ?? tool.parameters ?? update.rawInput);
|
|
333
|
+
const output = serializeToolValue(tool.rawOutput ?? tool.output ?? tool.result ?? update.rawOutput);
|
|
334
|
+
const error = serializeToolValue(tool.error ?? update.error);
|
|
335
|
+
const agentId = firstToolText(tool.agentId, tool.agent_id, update.agentId, update.agent_id);
|
|
336
|
+
const detail = serializeToolValue(tool.detail ?? update.detail ?? update.content);
|
|
337
|
+
const fallback = error !== undefined || type.includes('error') || type.includes('fail')
|
|
338
|
+
? 'failed'
|
|
339
|
+
: output !== undefined || type.includes('result') || type.includes('complete')
|
|
340
|
+
? 'completed'
|
|
341
|
+
: 'running';
|
|
342
|
+
return {
|
|
343
|
+
type: 'tool-event',
|
|
344
|
+
toolName: name ?? 'tool',
|
|
345
|
+
status: normalizeToolStatus(tool.status ?? tool.state ?? update.status, fallback),
|
|
346
|
+
...(callId ? { callId } : {}),
|
|
347
|
+
...(input !== undefined ? { input } : {}),
|
|
348
|
+
...(output !== undefined ? { output } : {}),
|
|
349
|
+
...(output !== undefined ? { outputMode: type.includes('delta') ? 'delta' : 'snapshot' } : {}),
|
|
350
|
+
...(error !== undefined ? { error } : {}),
|
|
351
|
+
...(agentId ? { agentId } : {}),
|
|
352
|
+
...(detail !== undefined ? { detail } : {}),
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
const usage = usageChunk(update);
|
|
357
|
+
if (usage)
|
|
358
|
+
return usage;
|
|
359
|
+
if (type.includes('turn_completed') || type.includes('turn_complete') || type.includes('completed') || type.includes('prompt_end') || type === 'done' || type === 'result')
|
|
360
|
+
return { type: 'finish', reason: 'stop' };
|
|
361
|
+
if (type.includes('error') || type.includes('failed'))
|
|
362
|
+
return { type: 'finish', reason: 'error' };
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
function interactionRequestId(message) {
|
|
366
|
+
const params = isRecord(message.params) ? message.params : message;
|
|
367
|
+
const update = isRecord(params.update) ? params.update : params;
|
|
368
|
+
const method = typeof message.method === 'string' ? message.method.toLowerCase() : '';
|
|
369
|
+
const type = typeof update.sessionUpdate === 'string'
|
|
370
|
+
? update.sessionUpdate.toLowerCase()
|
|
371
|
+
: typeof update.type === 'string'
|
|
372
|
+
? update.type.toLowerCase()
|
|
373
|
+
: '';
|
|
374
|
+
if (!method.includes('permission') && !type.includes('permission'))
|
|
375
|
+
return null;
|
|
376
|
+
const value = update.requestId ?? update.request_id ?? update.id ?? message.id;
|
|
377
|
+
return typeof value === 'string' || typeof value === 'number' ? String(value) : null;
|
|
378
|
+
}
|
|
379
|
+
function readSessionId(value) {
|
|
380
|
+
if (!isRecord(value))
|
|
381
|
+
return null;
|
|
382
|
+
if (typeof value.sessionId === 'string')
|
|
383
|
+
return value.sessionId;
|
|
384
|
+
if (typeof value.session_id === 'string')
|
|
385
|
+
return value.session_id;
|
|
386
|
+
if (isRecord(value.session) && typeof value.session.id === 'string')
|
|
387
|
+
return value.session.id;
|
|
388
|
+
return typeof value.id === 'string' ? value.id : null;
|
|
389
|
+
}
|
|
390
|
+
function firstString(value, keys) {
|
|
391
|
+
for (const key of keys)
|
|
392
|
+
if (typeof value[key] === 'string' && value[key].trim())
|
|
393
|
+
return value[key];
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
function acpText(value) {
|
|
397
|
+
const direct = textValue(value);
|
|
398
|
+
if (direct)
|
|
399
|
+
return direct;
|
|
400
|
+
if (Array.isArray(value)) {
|
|
401
|
+
const joined = value.map((item) => acpText(item) ?? '').join('');
|
|
402
|
+
return joined.trim() ? joined : null;
|
|
403
|
+
}
|
|
404
|
+
if (isRecord(value)) {
|
|
405
|
+
for (const key of ['text', 'delta', 'content', 'message']) {
|
|
406
|
+
const nested = acpText(value[key]);
|
|
407
|
+
if (nested)
|
|
408
|
+
return nested;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
function geminiStreamResultChunks(value, cancelled) {
|
|
414
|
+
const chunks = [];
|
|
415
|
+
const stats = isRecord(value.stats) ? value.stats : null;
|
|
416
|
+
if (stats !== null) {
|
|
417
|
+
const usage = usageChunk(stats);
|
|
418
|
+
if (usage)
|
|
419
|
+
chunks.push(usage);
|
|
420
|
+
}
|
|
421
|
+
const status = typeof value.status === 'string' ? value.status.toLowerCase() : '';
|
|
422
|
+
const reason = cancelled ? 'cancel' : status === 'error' || status === 'failed' ? 'error' : 'stop';
|
|
423
|
+
chunks.push({ type: 'finish', reason });
|
|
424
|
+
return chunks;
|
|
425
|
+
}
|
|
426
|
+
export { GeminiCliDriver as GeminiDriver };
|
|
427
|
+
//# sourceMappingURL=gemini-driver.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import type { CodingNsAgentEvent, CodingNsCliModelCatalog, CodingNsAgentPermissionResponse, CodingNsCliTurnInput } from '../../shared/contracts/cli-adapter.js';
|
|
3
|
+
import type { CodingNsCliDriver, CodingNsCliSessionProbeInput, CodingNsCliSessionProbeResult } from './driver.js';
|
|
4
|
+
export interface GrokBuildDriverOptions {
|
|
5
|
+
readonly binaries?: readonly string[];
|
|
6
|
+
readonly sessionRoots?: readonly string[];
|
|
7
|
+
readonly spawnSync?: typeof spawnSync;
|
|
8
|
+
readonly spawn?: typeof spawn;
|
|
9
|
+
}
|
|
10
|
+
/** Grok Build 的 ACP stdio 驱动。ACP 会话和权限细节只在 Host 进程内处理。 */
|
|
11
|
+
export declare class GrokBuildDriver implements CodingNsCliDriver {
|
|
12
|
+
readonly descriptor: {
|
|
13
|
+
readonly id: "grok";
|
|
14
|
+
readonly name: "Grok Build";
|
|
15
|
+
readonly protocol: "acp";
|
|
16
|
+
readonly capabilities: readonly ["models", "stream", "tool-events", "reasoning", "usage", "permission"];
|
|
17
|
+
};
|
|
18
|
+
private readonly binaries;
|
|
19
|
+
private readonly runSpawnSync;
|
|
20
|
+
private readonly runSpawn;
|
|
21
|
+
private readonly sessionRoots;
|
|
22
|
+
private cachedBinary;
|
|
23
|
+
private readonly processes;
|
|
24
|
+
private readonly sessions;
|
|
25
|
+
constructor(options?: GrokBuildDriverOptions);
|
|
26
|
+
detect(): Promise<{
|
|
27
|
+
installed: boolean;
|
|
28
|
+
version: string | null;
|
|
29
|
+
command: string | null;
|
|
30
|
+
}>;
|
|
31
|
+
listModels(): Promise<CodingNsCliModelCatalog>;
|
|
32
|
+
probeSession(input: CodingNsCliSessionProbeInput): Promise<CodingNsCliSessionProbeResult>;
|
|
33
|
+
executeTurn(input: CodingNsCliTurnInput): AsyncIterable<CodingNsAgentEvent>;
|
|
34
|
+
respondPermission(sessionId: string, response: CodingNsAgentPermissionResponse): void;
|
|
35
|
+
dispose(): void;
|
|
36
|
+
private getSession;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=grok-driver.d.ts.map
|