@a1hvdy/cc-openclaw 0.30.0 → 0.31.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/dist/src/channels/telegram-mirror/card-renderer.js +9 -5
- package/dist/src/channels/telegram-mirror/commands.js +0 -8
- package/dist/src/channels/telegram-mirror/status-line.js +32 -2
- package/dist/src/constants.js +16 -2
- package/dist/src/lib/config.js +40 -0
- package/dist/src/openai-compat/non-streaming-handler.js +2 -2
- package/dist/src/openai-compat/streaming-handler.js +2 -2
- package/package.json +3 -2
- package/dist/src/channels/adapter.d.ts +0 -103
- package/dist/src/channels/telegram-mirror/askuser.d.ts +0 -107
- package/dist/src/channels/telegram-mirror/burst-accumulator.d.ts +0 -96
- package/dist/src/channels/telegram-mirror/callback-mapping.d.ts +0 -61
- package/dist/src/channels/telegram-mirror/card-renderer.d.ts +0 -68
- package/dist/src/channels/telegram-mirror/card-state.d.ts +0 -83
- package/dist/src/channels/telegram-mirror/commands.d.ts +0 -183
- package/dist/src/channels/telegram-mirror/compose-buffer.d.ts +0 -71
- package/dist/src/channels/telegram-mirror/cost-views.d.ts +0 -58
- package/dist/src/channels/telegram-mirror/failure/callback-data-overflow.d.ts +0 -21
- package/dist/src/channels/telegram-mirror/failure/gateway-down.d.ts +0 -15
- package/dist/src/channels/telegram-mirror/failure/in-flight-conflict.d.ts +0 -15
- package/dist/src/channels/telegram-mirror/failure/index.d.ts +0 -23
- package/dist/src/channels/telegram-mirror/failure/model-5xx.d.ts +0 -16
- package/dist/src/channels/telegram-mirror/failure/network-blip.d.ts +0 -17
- package/dist/src/channels/telegram-mirror/failure/pool-exhausted-fallback.d.ts +0 -15
- package/dist/src/channels/telegram-mirror/failure/rate-limit.d.ts +0 -16
- package/dist/src/channels/telegram-mirror/failure/returning-after-24h.d.ts +0 -14
- package/dist/src/channels/telegram-mirror/failure/types.d.ts +0 -30
- package/dist/src/channels/telegram-mirror/inbound-handler.d.ts +0 -73
- package/dist/src/channels/telegram-mirror/index.d.ts +0 -32
- package/dist/src/channels/telegram-mirror/plan-attachment.d.ts +0 -120
- package/dist/src/channels/telegram-mirror/quota-reader.d.ts +0 -42
- package/dist/src/channels/telegram-mirror/sessions-keyboard.d.ts +0 -84
- package/dist/src/channels/telegram-mirror/soak-log.d.ts +0 -99
- package/dist/src/channels/telegram-mirror/state-machine.d.ts +0 -113
- package/dist/src/channels/telegram-mirror/status-line.d.ts +0 -51
- package/dist/src/channels/telegram-mirror/sync-commands.d.ts +0 -100
- package/dist/src/channels/telegram-mirror/threshold-watcher.d.ts +0 -54
- package/dist/src/channels/telegram-mirror/turn-bridge.d.ts +0 -125
- package/dist/src/cli/checks/bridge-wiring.d.ts +0 -14
- package/dist/src/cli/checks/config-schema.d.ts +0 -11
- package/dist/src/cli/checks/critical-openclaw-json-keys.d.ts +0 -21
- package/dist/src/cli/checks/install-path.d.ts +0 -11
- package/dist/src/cli/checks/patch-scaffold.d.ts +0 -17
- package/dist/src/cli/doctor.d.ts +0 -20
- package/dist/src/cli/index.d.ts +0 -8
- package/dist/src/cli/migrate.d.ts +0 -29
- package/dist/src/command-router/cc-handler.d.ts +0 -67
- package/dist/src/command-router/index.d.ts +0 -2
- package/dist/src/command-router/launch-policy.d.ts +0 -92
- package/dist/src/command-router/resume-policy.d.ts +0 -18
- package/dist/src/command-router/turn-formatter.d.ts +0 -19
- package/dist/src/config/loader.d.ts +0 -8
- package/dist/src/config/schema.d.ts +0 -192
- package/dist/src/constants.d.ts +0 -191
- package/dist/src/council/build-agent-prompt.d.ts +0 -11
- package/dist/src/council/cleanup-worktrees.d.ts +0 -10
- package/dist/src/council/consensus.d.ts +0 -20
- package/dist/src/council/council.d.ts +0 -67
- package/dist/src/council/index.d.ts +0 -2
- package/dist/src/council/system-prompt.d.ts +0 -16
- package/dist/src/council/write-worktree-claude-md.d.ts +0 -10
- package/dist/src/engines/base-oneshot-session.d.ts +0 -87
- package/dist/src/engines/heartbeat-guard.d.ts +0 -93
- package/dist/src/engines/index.d.ts +0 -8
- package/dist/src/engines/persistent-codex-session.d.ts +0 -16
- package/dist/src/engines/persistent-cursor-session.d.ts +0 -21
- package/dist/src/engines/persistent-custom-session.d.ts +0 -78
- package/dist/src/engines/persistent-gemini-session.d.ts +0 -21
- package/dist/src/engines/persistent-session.d.ts +0 -95
- package/dist/src/engines/resolve-bin.d.ts +0 -14
- package/dist/src/engines/subprocess-pool.d.ts +0 -78
- package/dist/src/health/handler.d.ts +0 -39
- package/dist/src/health/index.d.ts +0 -1
- package/dist/src/health/metrics.d.ts +0 -52
- package/dist/src/index.d.ts +0 -57
- package/dist/src/lib/auto-recovery.d.ts +0 -43
- package/dist/src/lib/cache-parity-decide.d.ts +0 -64
- package/dist/src/lib/cache-parity.d.ts +0 -38
- package/dist/src/lib/cc-cli-scan.d.ts +0 -52
- package/dist/src/lib/circuit-breaker.d.ts +0 -21
- package/dist/src/lib/config-service.d.ts +0 -106
- package/dist/src/lib/config.d.ts +0 -136
- package/dist/src/lib/cost-rollup.d.ts +0 -36
- package/dist/src/lib/debounce.d.ts +0 -12
- package/dist/src/lib/debug-tap.d.ts +0 -13
- package/dist/src/lib/domain-error.d.ts +0 -59
- package/dist/src/lib/drift-detector.d.ts +0 -46
- package/dist/src/lib/env-overrides.d.ts +0 -47
- package/dist/src/lib/error-formatter.d.ts +0 -91
- package/dist/src/lib/error-renderer.d.ts +0 -20
- package/dist/src/lib/heartbeat-config.d.ts +0 -34
- package/dist/src/lib/heartbeat-workaround.d.ts +0 -44
- package/dist/src/lib/html-render.d.ts +0 -50
- package/dist/src/lib/http-agent.d.ts +0 -47
- package/dist/src/lib/index.d.ts +0 -7
- package/dist/src/lib/index.js +0 -10
- package/dist/src/lib/json-array.d.ts +0 -10
- package/dist/src/lib/markdown-to-mdv2.d.ts +0 -53
- package/dist/src/lib/markdown-v2.d.ts +0 -27
- package/dist/src/lib/perf/async-compact.d.ts +0 -26
- package/dist/src/lib/perf/direct-sdk.d.ts +0 -26
- package/dist/src/lib/perf/haiku-route.d.ts +0 -19
- package/dist/src/lib/perf/predictive-continuation.d.ts +0 -18
- package/dist/src/lib/perf/read-batch.d.ts +0 -33
- package/dist/src/lib/perf/skill-list-collapse.d.ts +0 -22
- package/dist/src/lib/perf/speculative-bubble.d.ts +0 -27
- package/dist/src/lib/perf/typing-prefetch.d.ts +0 -25
- package/dist/src/lib/probes.d.ts +0 -50
- package/dist/src/lib/register-guard.d.ts +0 -56
- package/dist/src/lib/req-shape-log.d.ts +0 -31
- package/dist/src/lib/safe-upstream-probes.d.ts +0 -25
- package/dist/src/lib/session-registry.d.ts +0 -66
- package/dist/src/lib/spawn-async.d.ts +0 -18
- package/dist/src/lib/status-tee-reader.d.ts +0 -29
- package/dist/src/lib/sysprompt-strip.d.ts +0 -53
- package/dist/src/lib/telegram-bot-api.d.ts +0 -146
- package/dist/src/lib/telemetry.d.ts +0 -38
- package/dist/src/lib/test-mode.d.ts +0 -26
- package/dist/src/lib/trajectory.d.ts +0 -44
- package/dist/src/lib/vendor-paths.d.ts +0 -12
- package/dist/src/lifecycle/boot.d.ts +0 -48
- package/dist/src/lifecycle/patch-manifest.d.ts +0 -82
- package/dist/src/lifecycle/phase-import-upstream.d.ts +0 -12
- package/dist/src/lifecycle/phase-install-patches.d.ts +0 -12
- package/dist/src/lifecycle/phase-schedule-jobs.d.ts +0 -12
- package/dist/src/lifecycle/phase-start-server.d.ts +0 -11
- package/dist/src/lifecycle/phase-validate-config.d.ts +0 -9
- package/dist/src/lifecycle/phase-validate-upstream.d.ts +0 -11
- package/dist/src/lifecycle/phase-wire-handlers.d.ts +0 -12
- package/dist/src/lifecycle/safe-restart.d.ts +0 -99
- package/dist/src/logger.d.ts +0 -14
- package/dist/src/mcp/bridge.d.ts +0 -21
- package/dist/src/mcp/index.d.ts +0 -2
- package/dist/src/models.d.ts +0 -68
- package/dist/src/observability/event-bus.d.ts +0 -86
- package/dist/src/observability/get-event-bus.d.ts +0 -25
- package/dist/src/observability/observability-service.d.ts +0 -19
- package/dist/src/observability/perf-telemetry.d.ts +0 -65
- package/dist/src/observability/subscribers/metrics.d.ts +0 -11
- package/dist/src/observability/subscribers/session-capture.d.ts +0 -15
- package/dist/src/openai-compat/autonomy-rule.d.ts +0 -26
- package/dist/src/openai-compat/bridges/allowlist.d.ts +0 -19
- package/dist/src/openai-compat/bridges/factory.d.ts +0 -30
- package/dist/src/openai-compat/bridges/media-bridge.d.ts +0 -34
- package/dist/src/openai-compat/bridges/openclaw-api-shim.d.ts +0 -54
- package/dist/src/openai-compat/bridges/openclaw-native-tools.d.ts +0 -61
- package/dist/src/openai-compat/bridges/openclaw-tool-registry.d.ts +0 -26
- package/dist/src/openai-compat/bridges/tts-media-bridge.d.ts +0 -19
- package/dist/src/openai-compat/chat-cwd.d.ts +0 -22
- package/dist/src/openai-compat/cli-stream-parser.d.ts +0 -134
- package/dist/src/openai-compat/index.d.ts +0 -1
- package/dist/src/openai-compat/message-extractor.d.ts +0 -84
- package/dist/src/openai-compat/mode-flags.d.ts +0 -34
- package/dist/src/openai-compat/non-streaming-handler.d.ts +0 -29
- package/dist/src/openai-compat/openai-chunk-types.d.ts +0 -35
- package/dist/src/openai-compat/openai-compat.d.ts +0 -49
- package/dist/src/openai-compat/openai-types.d.ts +0 -71
- package/dist/src/openai-compat/parse-route-body.d.ts +0 -24
- package/dist/src/openai-compat/prompts.d.ts +0 -47
- package/dist/src/openai-compat/request-coalescer.d.ts +0 -77
- package/dist/src/openai-compat/response-formatter.d.ts +0 -33
- package/dist/src/openai-compat/session-key-resolver.d.ts +0 -41
- package/dist/src/openai-compat/skill-resolver.d.ts +0 -59
- package/dist/src/openai-compat/sse-translator.d.ts +0 -51
- package/dist/src/openai-compat/status-reporter.d.ts +0 -30
- package/dist/src/openai-compat/streaming-handler.d.ts +0 -52
- package/dist/src/openai-compat/tool-calls-parser.d.ts +0 -34
- package/dist/src/openai-compat/tool-results-serializer.d.ts +0 -60
- package/dist/src/openai-compat/tts-rule.d.ts +0 -20
- package/dist/src/openai-compat/voice-recovery.d.ts +0 -56
- package/dist/src/patches/cache-parity-registry.d.ts +0 -103
- package/dist/src/patches/claude-md-injection.d.ts +0 -10
- package/dist/src/patches/cwd-redirect.d.ts +0 -10
- package/dist/src/patches/embedded-server-route.d.ts +0 -23
- package/dist/src/patches/pricing-overrides.d.ts +0 -10
- package/dist/src/patches/resume-registry-restore.d.ts +0 -11
- package/dist/src/patches/session-pid-tracking.d.ts +0 -10
- package/dist/src/patches/sysprompt-strip.d.ts +0 -46
- package/dist/src/patches/tools-restoration.d.ts +0 -12
- package/dist/src/persistence/migration-v0.d.ts +0 -24
- package/dist/src/persistence/session-registry.d.ts +0 -58
- package/dist/src/proxy/anthropic-adapter.d.ts +0 -136
- package/dist/src/proxy/handler.d.ts +0 -39
- package/dist/src/proxy/index.d.ts +0 -4
- package/dist/src/proxy/schema-cleaner.d.ts +0 -11
- package/dist/src/proxy/thought-cache.d.ts +0 -19
- package/dist/src/session/embedded-server.d.ts +0 -25
- package/dist/src/session/inbox-manager.d.ts +0 -38
- package/dist/src/session/index.d.ts +0 -3
- package/dist/src/session/persisted-sessions.d.ts +0 -50
- package/dist/src/session/session-manager.d.ts +0 -247
- package/dist/src/session/watchdogs.d.ts +0 -92
- package/dist/src/session-bootstrap/boot-self-heal.d.ts +0 -32
- package/dist/src/session-bootstrap/cwd-patch.d.ts +0 -50
- package/dist/src/session-bootstrap/index.d.ts +0 -3
- package/dist/src/session-bootstrap/resume-registry.d.ts +0 -27
- package/dist/src/session-bootstrap/session-hygiene.d.ts +0 -23
- package/dist/src/session-bootstrap/sysprompt-strip.d.ts +0 -24
- package/dist/src/session-bootstrap/think-conflict-resolver.d.ts +0 -32
- package/dist/src/types/route.d.ts +0 -11
- package/dist/src/types/runtime-config.d.ts +0 -208
- package/dist/src/types/sse.d.ts +0 -29
- package/dist/src/types/tool-bridge.d.ts +0 -82
- package/dist/src/types/upstream.d.ts +0 -580
- package/dist/src/types.d.ts +0 -498
- package/dist/src/validation.d.ts +0 -31
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* factory.ts — Bridge factory: reads env flags and returns the active IToolBridge.
|
|
3
|
-
*
|
|
4
|
-
* Mode precedence (highest wins):
|
|
5
|
-
* CC_OPENCLAW_NATIVE_TOOLS=1 → OpenClawNative (v0.11.0, default OFF)
|
|
6
|
-
* CC_OPENCLAW_TOOL_STREAM=1 → NativeStream
|
|
7
|
-
* OPENAI_COMPAT_TOOLS_PER_MESSAGE=1 → PerMessage
|
|
8
|
-
* (default) → Embedded
|
|
9
|
-
*
|
|
10
|
-
* The three existing modes (Embedded, PerMessage, NativeStream) are NOT
|
|
11
|
-
* implemented as full IToolBridge classes in this PR — their logic lives
|
|
12
|
-
* inside openai-compat.ts. The factory stubs them as thin wrappers that
|
|
13
|
-
* satisfy IToolBridge so callers can type-check against the interface.
|
|
14
|
-
* Only OpenClawNativeBridge is a real implementation here.
|
|
15
|
-
*
|
|
16
|
-
* Coexistence rule: existing flag readers (`isToolsPerMessageModeEnabled`,
|
|
17
|
-
* `isToolStreamMode`) are not touched — factory reads them via the same
|
|
18
|
-
* env vars, not via those helpers, to avoid coupling factory → mode-flags.
|
|
19
|
-
*/
|
|
20
|
-
import type { IToolBridge } from '../../types/tool-bridge.js';
|
|
21
|
-
import { ToolMode } from '../../types/tool-bridge.js';
|
|
22
|
-
/**
|
|
23
|
-
* Return the active IToolBridge based on env flags.
|
|
24
|
-
*
|
|
25
|
-
* Call once per request — bridges are lightweight and stateless (except
|
|
26
|
-
* OpenClawNativeToolsBridge which caches the gateway config read).
|
|
27
|
-
*/
|
|
28
|
-
export declare function makeToolBridge(): IToolBridge;
|
|
29
|
-
/** Read the active mode without constructing a bridge. Useful for logging. */
|
|
30
|
-
export declare function activeToolMode(): ToolMode;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* media-bridge.ts — Shared contract for media delivery bridges.
|
|
3
|
-
*
|
|
4
|
-
* `MediaBridge` is the interface all media-type sub-bridges implement.
|
|
5
|
-
* `TtsMediaBridge` (tts-media-bridge.ts) is the v0.11.0 concrete impl.
|
|
6
|
-
* Future: `ImageMediaBridge`, `FileMediaBridge` for v0.12.0.
|
|
7
|
-
*/
|
|
8
|
-
/** Structured result from a media bridge execution. */
|
|
9
|
-
export interface MediaBridgeResult {
|
|
10
|
-
/** Text to inject into the SSE stream in place of the tool_call. */
|
|
11
|
-
readonly text: string;
|
|
12
|
-
/** Whether the bridge produced output via the native channel. */
|
|
13
|
-
readonly delivered: boolean;
|
|
14
|
-
/** Delivery channel used. Informational — not load-bearing. */
|
|
15
|
-
readonly via: string;
|
|
16
|
-
}
|
|
17
|
-
/** Every media sub-bridge must satisfy this contract. */
|
|
18
|
-
export interface MediaBridge {
|
|
19
|
-
/** Canonical tool name this bridge handles (e.g. `message.voice`). */
|
|
20
|
-
readonly toolName: string;
|
|
21
|
-
/**
|
|
22
|
-
* Execute the media delivery. `args` is the raw JSON-parsed tool arguments
|
|
23
|
-
* from the model's tool_call. Returns a `MediaBridgeResult` — never throws;
|
|
24
|
-
* fallback text is always produced on error.
|
|
25
|
-
*/
|
|
26
|
-
execute(args: Record<string, unknown>): Promise<MediaBridgeResult>;
|
|
27
|
-
}
|
|
28
|
-
/** Thrown by bridge internals for structured error propagation.
|
|
29
|
-
* Caught at the `OpenClawNativeToolsBridge` boundary — never escapes to callers. */
|
|
30
|
-
export declare class MediaBridgeError extends Error {
|
|
31
|
-
readonly toolName: string;
|
|
32
|
-
readonly cause?: unknown | undefined;
|
|
33
|
-
constructor(message: string, toolName: string, cause?: unknown | undefined);
|
|
34
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenClawApiShim — typed subset of the OpenClaw plugin API surface.
|
|
3
|
-
*
|
|
4
|
-
* Q2 resolution: the upstream OpenClaw plugin API has no semver contract.
|
|
5
|
-
* Rather than depend on it directly, all native-tool calls go through this
|
|
6
|
-
* shim which exposes only the methods cc-openclaw needs.
|
|
7
|
-
*
|
|
8
|
-
* `validateShape(api)` runs at boot phase 3 (`validate-upstream`) and is
|
|
9
|
-
* registered as a `PatchSpec.expectedShape` probe. Failure → `DriftError`
|
|
10
|
-
* and boot refuses (per PatchManifest atomic-install contract).
|
|
11
|
-
*
|
|
12
|
-
* Phase D: types + probe shipped; `dispatch` stubbed and throws
|
|
13
|
-
* `NotImplemented` until Phase E wires the live OpenClaw `api.tool.dispatch`.
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Inbound dispatch types for the v1.0.0 ToolBridge strategy. These are
|
|
17
|
-
* complementary to the existing `IToolBridge` at `src/types/tool-bridge.ts`
|
|
18
|
-
* (which handles outbound tools-to-CLI wiring). Phase E consolidates the
|
|
19
|
-
* two interfaces if a clean merge is possible.
|
|
20
|
-
*/
|
|
21
|
-
export interface ToolUseCall {
|
|
22
|
-
readonly id: string;
|
|
23
|
-
readonly name: string;
|
|
24
|
-
readonly input: unknown;
|
|
25
|
-
}
|
|
26
|
-
export interface ToolUseResult {
|
|
27
|
-
readonly toolUseId: string;
|
|
28
|
-
readonly content: string;
|
|
29
|
-
readonly isError?: boolean;
|
|
30
|
-
}
|
|
31
|
-
/** Minimum surface area the shim requires from `openclaw.PluginApi`. */
|
|
32
|
-
export interface OpenClawApiSurface {
|
|
33
|
-
readonly tool: {
|
|
34
|
-
readonly dispatch: (name: string, input: unknown) => Promise<unknown>;
|
|
35
|
-
readonly list: () => ReadonlyArray<{
|
|
36
|
-
readonly name: string;
|
|
37
|
-
}>;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
export declare class OpenClawApiShim {
|
|
41
|
-
private readonly api;
|
|
42
|
-
constructor(api: OpenClawApiSurface);
|
|
43
|
-
/**
|
|
44
|
-
* Phase 3 probe — returns true when `api.tool.dispatch` and `api.tool.list`
|
|
45
|
-
* exist as callable methods. Used as a `PatchSpec.expectedShape` probe.
|
|
46
|
-
*/
|
|
47
|
-
static validateShape(api: unknown): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Dispatch a Claude `tool_use` event to OpenClaw's plugin API. Phase D stub.
|
|
50
|
-
*/
|
|
51
|
-
dispatch(_call: ToolUseCall): Promise<ToolUseResult>;
|
|
52
|
-
/** Phase D helper — exposes the underlying surface for tests. */
|
|
53
|
-
getApi(): OpenClawApiSurface;
|
|
54
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* openclaw-native-tools.ts — IToolBridge impl for ToolMode.OpenClawNative.
|
|
3
|
-
*
|
|
4
|
-
* v0.11.0 investigation result: OpenClaw DOES expose `/tools/invoke` at
|
|
5
|
-
* `http://127.0.0.1:18790` with Bearer token auth (confirmed in
|
|
6
|
-
* extensions/cc-openclaw/openclaw-mcp-bridge.cjs). However, the gateway's
|
|
7
|
-
* `tools.allow` list in openclaw.json only includes `claude_session_*` and
|
|
8
|
-
* council/ultraplan commands — `message.voice` is NOT there. Invoking
|
|
9
|
-
* `/tools/invoke` for voice would 404/401 at runtime.
|
|
10
|
-
*
|
|
11
|
-
* Decision: Path B (internal marker translation) for v0.11.0. `executeNative`
|
|
12
|
-
* routes `message.voice` through TtsMediaBridge → `[[tts:text]]` markers.
|
|
13
|
-
* OpenClaw's existing `maybeApplyTtsToPayload` picks them up downstream.
|
|
14
|
-
* This is identical to the voice-recovery.ts rescue path — the difference is
|
|
15
|
-
* the call site: here the model emits a proper tool_call, not raw text XML.
|
|
16
|
-
*
|
|
17
|
-
* Path A (real HTTP POST to `/tools/invoke`) is fully wired in `executeHttp`
|
|
18
|
-
* and ready to activate in v0.12.0 when A1 adds `message.voice` to
|
|
19
|
-
* `gateway.tools.allow` in openclaw.json.
|
|
20
|
-
*/
|
|
21
|
-
import type { IToolBridge, ToolDefinition, TranslatedToolUseDelta } from '../../types/tool-bridge.js';
|
|
22
|
-
import { ToolMode } from '../../types/tool-bridge.js';
|
|
23
|
-
interface GatewayConfig {
|
|
24
|
-
url: string;
|
|
25
|
-
token: string;
|
|
26
|
-
}
|
|
27
|
-
export declare class OpenClawNativeToolsBridge implements IToolBridge {
|
|
28
|
-
readonly mode = ToolMode.OpenClawNative;
|
|
29
|
-
private readonly _gwConfig;
|
|
30
|
-
constructor(gwConfig?: GatewayConfig);
|
|
31
|
-
/**
|
|
32
|
-
* Build a minimal tool preamble listing only the tools the bridge can
|
|
33
|
-
* actually handle (allowlisted + registered). The full schema is omitted —
|
|
34
|
-
* the caller's system prompt already advertises it. This is a safety marker
|
|
35
|
-
* so Savvy knows the bridge is active.
|
|
36
|
-
*/
|
|
37
|
-
buildToolPreamble(tools: ReadonlyArray<ToolDefinition> | undefined): string;
|
|
38
|
-
/**
|
|
39
|
-
* Translate a tool_use event from the Claude stream into an OpenAI delta.
|
|
40
|
-
* This bridge does NOT intercept mid-stream events — tool execution happens
|
|
41
|
-
* in `executeNative` after the full turn completes. Return null always.
|
|
42
|
-
*/
|
|
43
|
-
translateToolUse(_event: unknown): TranslatedToolUseDelta;
|
|
44
|
-
/** Serialize a tool result back as XML for the next turn's user message. */
|
|
45
|
-
serializeToolResult(call: import('../../types/route.js').OpenAIToolCall, result: string): string;
|
|
46
|
-
/**
|
|
47
|
-
* Execute a `message.voice` (or other allowlisted) tool call.
|
|
48
|
-
*
|
|
49
|
-
* v0.11.0: routes through TtsMediaBridge (Path B — marker translation).
|
|
50
|
-
* Returns the TTS marker text to inject into the SSE stream.
|
|
51
|
-
*
|
|
52
|
-
* When `CC_OPENCLAW_NATIVE_TOOLS_HTTP=1` is set, falls through to Path A
|
|
53
|
-
* (real HTTP POST). Reserved for v0.12.0 activation.
|
|
54
|
-
*/
|
|
55
|
-
executeNative(toolName: string, args: Record<string, unknown>): Promise<{
|
|
56
|
-
text: string;
|
|
57
|
-
delivered: boolean;
|
|
58
|
-
via: string;
|
|
59
|
-
}>;
|
|
60
|
-
}
|
|
61
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* openclaw-tool-registry.ts — Registry that maps allowed tool names to their
|
|
3
|
-
* MediaBridge implementations.
|
|
4
|
-
*
|
|
5
|
-
* v0.11.0 only registers `message.voice` → TtsMediaBridge. The registry is
|
|
6
|
-
* lazy-constructed per-request (stateless) so future parallel agents can add
|
|
7
|
-
* bridges without contention.
|
|
8
|
-
*/
|
|
9
|
-
import type { MediaBridge } from './media-bridge.js';
|
|
10
|
-
/** Resolved bridge for a given tool name, or null when not in allowlist. */
|
|
11
|
-
export interface ResolvedBridge {
|
|
12
|
-
readonly bridge: MediaBridge;
|
|
13
|
-
readonly toolName: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Look up the MediaBridge for `toolName`.
|
|
17
|
-
* Returns null when the tool is not in the v0.11.0 allowlist OR has no
|
|
18
|
-
* registered implementation.
|
|
19
|
-
*/
|
|
20
|
-
export declare function resolveToolBridge(toolName: string): ResolvedBridge | null;
|
|
21
|
-
/**
|
|
22
|
-
* Return every tool name currently in the registry (i.e. allowed + implemented).
|
|
23
|
-
* Used by `OpenClawNativeToolsBridge.buildToolPreamble` to filter the caller's
|
|
24
|
-
* tool list down to what the bridge can actually handle.
|
|
25
|
-
*/
|
|
26
|
-
export declare function registeredToolNames(): ReadonlySet<string>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* tts-media-bridge.ts — MediaBridge impl for `message.voice`.
|
|
3
|
-
*
|
|
4
|
-
* v0.11.0 Path B strategy: instead of POSTing to a TTS HTTP endpoint, this
|
|
5
|
-
* bridge converts `message.voice` tool args into `[[tts:text]]` markers that
|
|
6
|
-
* OpenClaw's existing `maybeApplyTtsToPayload` downstream picks up — the same
|
|
7
|
-
* channel voice-recovery.ts uses. This gives the tool-boundary UX (Savvy sees
|
|
8
|
-
* a proper tool interface; callers see tool_call deltas) without requiring a
|
|
9
|
-
* new OpenClaw endpoint.
|
|
10
|
-
*
|
|
11
|
-
* The bridge imports from voice-recovery.ts and reuses its marker constants
|
|
12
|
-
* and truncation logic. No logic is duplicated.
|
|
13
|
-
*/
|
|
14
|
-
import type { MediaBridge, MediaBridgeResult } from './media-bridge.js';
|
|
15
|
-
export declare const TTS_TOOL_NAME = "message.voice";
|
|
16
|
-
export declare class TtsMediaBridge implements MediaBridge {
|
|
17
|
-
readonly toolName = "message.voice";
|
|
18
|
-
execute(args: Record<string, unknown>): Promise<MediaBridgeResult>;
|
|
19
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* resolveChatCwd — working directory for an openai-compat (Telegram chat) session.
|
|
3
|
-
*
|
|
4
|
-
* Default: a neutral per-session tmpdir, so the claude CLI does NOT load
|
|
5
|
-
* CLAUDE.md / git state / project context (keeps chat turns cheap and clean —
|
|
6
|
-
* this is the deliberate v0.x choice).
|
|
7
|
-
*
|
|
8
|
-
* Opt-in (v0.27.12): set CC_OPENCLAW_CHAT_CWD to an existing directory and chat
|
|
9
|
-
* sessions run there — the CLI then loads that project's CLAUDE.md + git context
|
|
10
|
-
* like the terminal CLI does, and the CLI's "cwd reset" lands on the project dir
|
|
11
|
-
* instead of a tmpdir. This closes the chat-vs-terminal project-context parity
|
|
12
|
-
* gap as an explicit, per-deployment opt-in, so the default stays zero-token-
|
|
13
|
-
* overhead. A blank/unset/nonexistent value falls back to the tmpdir, so a
|
|
14
|
-
* misconfigured path can never break session creation.
|
|
15
|
-
*
|
|
16
|
-
* Pure (deps injectable) for unit-testing.
|
|
17
|
-
*/
|
|
18
|
-
export declare function resolveChatCwd(sessionName: string, opts?: {
|
|
19
|
-
cwdOverride?: string;
|
|
20
|
-
dirExists?: (p: string) => boolean;
|
|
21
|
-
tmpDir?: string;
|
|
22
|
-
}): string;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Claude CLI streaming output parser.
|
|
3
|
-
*
|
|
4
|
-
* Reads NDJSON from `claude --output-format=stream-json --include-partial-messages`
|
|
5
|
-
* and emits typed events. The CLI's stream-json wraps Anthropic Messages API
|
|
6
|
-
* stream events inside an envelope:
|
|
7
|
-
*
|
|
8
|
-
* {"type":"stream_event","event":{<anthropic_event>},...}
|
|
9
|
-
*
|
|
10
|
-
* Other envelope types include `system`, `assistant`, `rate_limit_event`,
|
|
11
|
-
* `result`, plus hook lifecycle events.
|
|
12
|
-
*
|
|
13
|
-
* This module unwraps `stream_event` envelopes and emits the inner Anthropic
|
|
14
|
-
* Messages API events directly. Other envelope types pass through with their
|
|
15
|
-
* own ParsedEvent variants so downstream consumers can react (e.g. the budget
|
|
16
|
-
* guard listens to `rate_limit_event` and `result`).
|
|
17
|
-
*
|
|
18
|
-
* Captured against Claude CLI v2.1.119. Fixture corpus lives at
|
|
19
|
-
* tests/streaming/fixtures/*.ndjson.
|
|
20
|
-
*/
|
|
21
|
-
export type AnthropicEvent = {
|
|
22
|
-
type: 'message_start';
|
|
23
|
-
message: AnthropicMessage;
|
|
24
|
-
} | {
|
|
25
|
-
type: 'content_block_start';
|
|
26
|
-
index: number;
|
|
27
|
-
content_block: ContentBlockStart;
|
|
28
|
-
} | {
|
|
29
|
-
type: 'content_block_delta';
|
|
30
|
-
index: number;
|
|
31
|
-
delta: ContentBlockDelta;
|
|
32
|
-
} | {
|
|
33
|
-
type: 'content_block_stop';
|
|
34
|
-
index: number;
|
|
35
|
-
} | {
|
|
36
|
-
type: 'message_delta';
|
|
37
|
-
delta: MessageDeltaBody;
|
|
38
|
-
usage?: MessageUsage;
|
|
39
|
-
} | {
|
|
40
|
-
type: 'message_stop';
|
|
41
|
-
} | {
|
|
42
|
-
type: 'error';
|
|
43
|
-
error: {
|
|
44
|
-
type: string;
|
|
45
|
-
message: string;
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
export interface AnthropicMessage {
|
|
49
|
-
id: string;
|
|
50
|
-
model: string;
|
|
51
|
-
role?: string;
|
|
52
|
-
content?: unknown[];
|
|
53
|
-
stop_reason?: string | null;
|
|
54
|
-
stop_sequence?: string | null;
|
|
55
|
-
usage?: MessageUsage;
|
|
56
|
-
}
|
|
57
|
-
export interface MessageUsage {
|
|
58
|
-
input_tokens?: number;
|
|
59
|
-
output_tokens?: number;
|
|
60
|
-
cache_creation_input_tokens?: number;
|
|
61
|
-
cache_read_input_tokens?: number;
|
|
62
|
-
}
|
|
63
|
-
export interface MessageDeltaBody {
|
|
64
|
-
stop_reason?: string;
|
|
65
|
-
stop_sequence?: string | null;
|
|
66
|
-
stop_details?: unknown;
|
|
67
|
-
}
|
|
68
|
-
export type ContentBlockStart = {
|
|
69
|
-
type: 'text';
|
|
70
|
-
text: string;
|
|
71
|
-
} | {
|
|
72
|
-
type: 'tool_use';
|
|
73
|
-
id: string;
|
|
74
|
-
name: string;
|
|
75
|
-
input: Record<string, unknown>;
|
|
76
|
-
caller?: unknown;
|
|
77
|
-
} | {
|
|
78
|
-
type: 'thinking';
|
|
79
|
-
thinking: string;
|
|
80
|
-
signature: string;
|
|
81
|
-
};
|
|
82
|
-
export type ContentBlockDelta = {
|
|
83
|
-
type: 'text_delta';
|
|
84
|
-
text: string;
|
|
85
|
-
} | {
|
|
86
|
-
type: 'input_json_delta';
|
|
87
|
-
partial_json: string;
|
|
88
|
-
} | {
|
|
89
|
-
type: 'thinking_delta';
|
|
90
|
-
thinking: string;
|
|
91
|
-
} | {
|
|
92
|
-
type: 'signature_delta';
|
|
93
|
-
signature: string;
|
|
94
|
-
};
|
|
95
|
-
export type ParsedEvent = AnthropicEvent | {
|
|
96
|
-
type: 'system';
|
|
97
|
-
subtype: string;
|
|
98
|
-
raw: Record<string, unknown>;
|
|
99
|
-
} | {
|
|
100
|
-
type: 'assistant';
|
|
101
|
-
message: AnthropicMessage;
|
|
102
|
-
sessionId?: string;
|
|
103
|
-
parentToolUseId?: string | null;
|
|
104
|
-
} | {
|
|
105
|
-
type: 'rate_limit_event';
|
|
106
|
-
rateLimitInfo: Record<string, unknown>;
|
|
107
|
-
} | {
|
|
108
|
-
type: 'result';
|
|
109
|
-
subtype: string;
|
|
110
|
-
isError: boolean;
|
|
111
|
-
result?: string;
|
|
112
|
-
durationMs?: number;
|
|
113
|
-
usage?: MessageUsage;
|
|
114
|
-
totalCostUsd?: number;
|
|
115
|
-
raw: Record<string, unknown>;
|
|
116
|
-
} | {
|
|
117
|
-
type: 'unknown';
|
|
118
|
-
raw: unknown;
|
|
119
|
-
} | {
|
|
120
|
-
type: 'parse_error';
|
|
121
|
-
error: {
|
|
122
|
-
type: string;
|
|
123
|
-
message: string;
|
|
124
|
-
};
|
|
125
|
-
rawLine?: string;
|
|
126
|
-
};
|
|
127
|
-
export interface CliStreamParser {
|
|
128
|
-
/** Push a chunk of stdout. Returns events derivable from any complete lines.
|
|
129
|
-
* Incomplete trailing line stays in the buffer for the next call. */
|
|
130
|
-
push(chunk: string): ParsedEvent[];
|
|
131
|
-
/** Flush any remaining buffered partial line. Returns final events (or empty). */
|
|
132
|
-
flush(): ParsedEvent[];
|
|
133
|
-
}
|
|
134
|
-
export declare function createCliStreamParser(): CliStreamParser;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './openai-compat.js';
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cluster B — Message extractor.
|
|
3
|
-
*
|
|
4
|
-
* Extracted verbatim from `openai-compat.ts:177-301` (Phase 4 Cluster B
|
|
5
|
-
* Module D). Single function that converts an OpenAI `messages[]` array
|
|
6
|
-
* into the inputs Claude CLI's bridge expects:
|
|
7
|
-
*
|
|
8
|
-
* - systemPrompt — joined `role:system` content, undefined if none
|
|
9
|
-
* - userMessage — last user message (with skill-inline applied)
|
|
10
|
-
* OR XML-wrapped tool-result block when the
|
|
11
|
-
* last non-system message is `role:tool`
|
|
12
|
-
* - userMessageBlocks — tool-stream mode only: native Anthropic
|
|
13
|
-
* content blocks (tool_result + text) for the
|
|
14
|
-
* stream-json input path
|
|
15
|
-
* - isNewConversation — drives session-create vs session-append
|
|
16
|
-
*
|
|
17
|
-
* Single call site in the orchestrator (handleChatCompletion line 482).
|
|
18
|
-
* The two types `UserMessageBlock` and `ExtractedMessage` are also re-
|
|
19
|
-
* exported from openai-compat.ts for callers across the orchestrator
|
|
20
|
-
* (formatCompletionResponse + helpers all consume them as parameters).
|
|
21
|
-
*
|
|
22
|
-
* Session-reset semantics:
|
|
23
|
-
* - X-Session-Reset: 1|true → always treated as new conversation
|
|
24
|
-
* - OPENAI_COMPAT_NEW_CONVO_HEURISTIC=1 (env) → legacy
|
|
25
|
-
* "system + single user ⇒ new conversation" rule, opt-in for
|
|
26
|
-
* callers that re-send the full transcript every turn
|
|
27
|
-
* - Default (env unset) → only the explicit header creates a new
|
|
28
|
-
* conversation; persistent CLI sessions survive across turns and
|
|
29
|
-
* benefit from Anthropic prompt caching (PR #40)
|
|
30
|
-
*/
|
|
31
|
-
import type { OpenAIChatMessage } from './openai-compat.js';
|
|
32
|
-
import { type AnthropicToolResultBlock } from './tool-results-serializer.js';
|
|
33
|
-
/**
|
|
34
|
-
* Phase 2 R4 wire-up: optional structured content for tool-stream mode.
|
|
35
|
-
* When set, consumers should send this array to the subprocess instead of
|
|
36
|
-
* the legacy XML-wrapped `userMessage` string. Each element is either a
|
|
37
|
-
* native Anthropic `tool_result` block (for prior tool outputs) or a
|
|
38
|
-
* `text` block (for the user's follow-up message).
|
|
39
|
-
*/
|
|
40
|
-
export type UserMessageBlock = AnthropicToolResultBlock | {
|
|
41
|
-
type: 'text';
|
|
42
|
-
text: string;
|
|
43
|
-
};
|
|
44
|
-
export interface ExtractedMessage {
|
|
45
|
-
systemPrompt: string | undefined;
|
|
46
|
-
userMessage: string;
|
|
47
|
-
/**
|
|
48
|
-
* Populated only in tool-stream mode when the last non-system message
|
|
49
|
-
* is a tool-role result. Carries native Anthropic tool_result blocks
|
|
50
|
-
* + optional follow-up text. When undefined, consumers fall back to
|
|
51
|
-
* the string `userMessage` (legacy XML-wrapped path).
|
|
52
|
-
*/
|
|
53
|
-
userMessageBlocks?: UserMessageBlock[];
|
|
54
|
-
isNewConversation: boolean;
|
|
55
|
-
/** v0.19.1 M3 — slash command detected at message start, for live-card pill. */
|
|
56
|
-
slashCommand?: {
|
|
57
|
-
cmd: string;
|
|
58
|
-
mode?: string;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Extract the relevant parts from an OpenAI messages array.
|
|
63
|
-
*
|
|
64
|
-
* Sessions are stateful — we only need the last user message. The tricky
|
|
65
|
-
* question is whether to start a fresh session or append to the existing one.
|
|
66
|
-
*
|
|
67
|
-
* Default mode (no env var): only honor an explicit `X-Session-Reset: 1`
|
|
68
|
-
* header. This is correct for clients that maintain their own conversation
|
|
69
|
-
* transcript and forward only the latest user turn (OpenClaw main agent
|
|
70
|
-
* loop, cron jobs, subagents). The previous heuristic
|
|
71
|
-
* (`nonSystemMessages.length <= 1`) fired on every such request, killing the
|
|
72
|
-
* persistent CLI every turn and preventing Anthropic prompt caching from
|
|
73
|
-
* ever warming. Originally diagnosed in PR #40 by @megayounus786.
|
|
74
|
-
*
|
|
75
|
-
* Legacy mode (`OPENAI_COMPAT_NEW_CONVO_HEURISTIC=1`): restore the old
|
|
76
|
-
* `system + single user ⇒ new conversation` rule, for clients that re-send
|
|
77
|
-
* the full transcript on every turn (ChatGPT-Next-Web, Open WebUI, data
|
|
78
|
-
* labeling tools, etc). They use the transcript shape itself as their only
|
|
79
|
-
* "start a new conversation" signal.
|
|
80
|
-
*
|
|
81
|
-
* The env var is read on every call so ops can flip it via launchctl setenv
|
|
82
|
-
* without restarting the server.
|
|
83
|
-
*/
|
|
84
|
-
export declare function extractUserMessage(messages: OpenAIChatMessage[], headers?: Record<string, string | string[] | undefined>): ExtractedMessage;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cluster B beachhead — tool-mode flag predicates.
|
|
3
|
-
*
|
|
4
|
-
* Extracted from `openai-compat.ts` so that `session-key-resolver.ts`
|
|
5
|
-
* (and future Cluster B modules) can read these flags without creating
|
|
6
|
-
* a circular import back into the orchestrator.
|
|
7
|
-
*
|
|
8
|
-
* Behavior preserved bit-for-bit from the original definitions in
|
|
9
|
-
* `openai-compat.ts:126-142`. openai-compat.ts re-exports both
|
|
10
|
-
* functions for any external caller that previously imported them
|
|
11
|
-
* from there (none exist today, but the re-export is cheap insurance).
|
|
12
|
-
*
|
|
13
|
-
* Cluster B follow-on will fold these into the `IToolBridge` strategy
|
|
14
|
-
* pattern (PRP §5 Cluster B `bridges/factory.ts`); for now they
|
|
15
|
-
* remain free-function predicates.
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Legacy mode: when set, tool definitions are prepended to every user
|
|
19
|
-
* message instead of being baked into the session system prompt. Defeats
|
|
20
|
-
* prompt caching but allows mutating the tool list mid-session.
|
|
21
|
-
*
|
|
22
|
-
* Truthy values: '1', 'true', 'yes' (case-insensitive, trimmed).
|
|
23
|
-
*/
|
|
24
|
-
export declare function isToolsPerMessageModeEnabled(): boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Phase 2 R5: tool-stream mode flag. When `CC_OPENCLAW_TOOL_STREAM=1`
|
|
27
|
-
* AND the caller provides `tools[]`, cc-openclaw skips the defensive
|
|
28
|
-
* "no tools" system prompt and does NOT clear `sessionConfig.tools`,
|
|
29
|
-
* allowing Claude CLI's native tool_use events to flow through the
|
|
30
|
-
* parser+translator pipeline.
|
|
31
|
-
*
|
|
32
|
-
* Strict opt-in: only true when env value is exactly `'1'`.
|
|
33
|
-
*/
|
|
34
|
-
export declare function isToolStreamMode(): boolean;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cluster B Phase 2 — Non-streaming HTTP handler.
|
|
3
|
-
*
|
|
4
|
-
* Extracted verbatim from `openai-compat.ts:508-615` (Module G).
|
|
5
|
-
* Handles the response path when the caller did NOT request `stream:true` —
|
|
6
|
-
* a single buffered Claude CLI session call, then one JSON object back to
|
|
7
|
-
* the client.
|
|
8
|
-
*
|
|
9
|
-
* Lifecycle:
|
|
10
|
-
* 1. reportStatus('thinking') → SessionManager.sendMessage(...)
|
|
11
|
-
* 2. On each tool_use event → push a status update + emit trajectory
|
|
12
|
-
* 3. On each tool_result event → emit trajectory only (no status)
|
|
13
|
-
* 4. v0.7.1: accumulate thinking-block content when surfaceThinking is on
|
|
14
|
-
* 5. On completion → read token stats, format response, write back
|
|
15
|
-
* 6. On error → reportStatus('idle','Request failed') + 500 with
|
|
16
|
-
* structured `formatError` telemetry
|
|
17
|
-
*
|
|
18
|
-
* Parameterized fully — no closure capture from openai-compat.ts. All
|
|
19
|
-
* dependencies are imported from their dedicated Cluster B modules
|
|
20
|
-
* (response-formatter, tool-calls-parser, status-reporter,
|
|
21
|
-
* message-extractor for types) or from lib/.
|
|
22
|
-
*/
|
|
23
|
-
import type * as http from 'node:http';
|
|
24
|
-
import type { SessionManagerLike } from './openai-compat.js';
|
|
25
|
-
import type { UserMessageBlock } from './message-extractor.js';
|
|
26
|
-
export declare function handleNonStreaming(manager: SessionManagerLike, sessionName: string, model: string, userMessage: string | UserMessageBlock[], completionId: string, res: http.ServerResponse, hasTools: boolean, slashCommand?: {
|
|
27
|
-
cmd: string;
|
|
28
|
-
mode?: string;
|
|
29
|
-
}): Promise<void>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAI streaming chunk types.
|
|
3
|
-
*
|
|
4
|
-
* Extracted from `openai-compat.ts` 2026-05-13 to push that file under the
|
|
5
|
-
* 500-LOC ceiling. Single source of truth for the SSE chunk shape; also
|
|
6
|
-
* imported by `response-formatter.ts`, `types/route.ts`, `types/sse.ts`.
|
|
7
|
-
*/
|
|
8
|
-
export interface OpenAIChatCompletionChunk {
|
|
9
|
-
id: string;
|
|
10
|
-
object: 'chat.completion.chunk';
|
|
11
|
-
created: number;
|
|
12
|
-
model: string;
|
|
13
|
-
choices: Array<{
|
|
14
|
-
index: number;
|
|
15
|
-
delta: {
|
|
16
|
-
role?: string;
|
|
17
|
-
content?: string | null;
|
|
18
|
-
tool_calls?: Array<{
|
|
19
|
-
index: number;
|
|
20
|
-
id?: string;
|
|
21
|
-
type?: 'function';
|
|
22
|
-
function?: {
|
|
23
|
-
name?: string;
|
|
24
|
-
arguments?: string;
|
|
25
|
-
};
|
|
26
|
-
}>;
|
|
27
|
-
};
|
|
28
|
-
finish_reason: string | null;
|
|
29
|
-
}>;
|
|
30
|
-
usage?: {
|
|
31
|
-
prompt_tokens: number;
|
|
32
|
-
completion_tokens: number;
|
|
33
|
-
total_tokens: number;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAI-compatible /v1/chat/completions endpoint.
|
|
3
|
-
*
|
|
4
|
-
* Bridges OpenAI API format to persistent Claude Code sessions, enabling
|
|
5
|
-
* webchat frontends (ChatGPT-Next-Web, Open WebUI, etc.) to use the plugin
|
|
6
|
-
* as a drop-in backend. Stateful sessions maximize Anthropic prompt caching.
|
|
7
|
-
*/
|
|
8
|
-
import * as http from 'node:http';
|
|
9
|
-
import { type UserMessageBlock } from './message-extractor.js';
|
|
10
|
-
export { isToolsPerMessageModeEnabled, isToolStreamMode } from './mode-flags.js';
|
|
11
|
-
export { resolveSessionKey, sessionNameFromKey } from './session-key-resolver.js';
|
|
12
|
-
export { noToolsSystemPrompt, buildSessionSystemPrompt, buildToolPromptBlock } from './prompts.js';
|
|
13
|
-
export { parseToolCallsFromText, type ParsedToolCalls } from './tool-calls-parser.js';
|
|
14
|
-
export { serializeToolResults, serializeToolResultsAsBlocks, type AnthropicToolResultBlock, } from './tool-results-serializer.js';
|
|
15
|
-
export { extractUserMessage, type UserMessageBlock, type ExtractedMessage, } from './message-extractor.js';
|
|
16
|
-
export { formatCompletionResponse, formatCompletionChunk } from './response-formatter.js';
|
|
17
|
-
export { reportStatus, getToolDescription } from './status-reporter.js';
|
|
18
|
-
export { handleNonStreaming } from './non-streaming-handler.js';
|
|
19
|
-
export { handleStreaming } from './streaming-handler.js';
|
|
20
|
-
import type { OpenAIChatCompletionRequest as OpenAIChatCompletionRequestType } from './openai-types.js';
|
|
21
|
-
export type { OpenAIChatMessage, OpenAIChatCompletionRequest, OpenAIToolCall, OpenAIChatCompletionResponse, } from './openai-types.js';
|
|
22
|
-
export type { OpenAIChatCompletionChunk } from './openai-chunk-types.js';
|
|
23
|
-
/** SessionManager-like interface to avoid circular imports. Exported so
|
|
24
|
-
* the extracted handlers (non-streaming-handler.ts, streaming-handler.ts)
|
|
25
|
-
* can type their `manager` parameter from a single canonical definition. */
|
|
26
|
-
export interface SessionManagerLike {
|
|
27
|
-
startSession(config: Record<string, unknown>): Promise<{
|
|
28
|
-
name: string;
|
|
29
|
-
}>;
|
|
30
|
-
sendMessage(name: string, message: string | UserMessageBlock[], options?: Record<string, unknown>): Promise<{
|
|
31
|
-
output: string;
|
|
32
|
-
sessionId?: string;
|
|
33
|
-
events: unknown[];
|
|
34
|
-
}>;
|
|
35
|
-
stopSession(name: string): Promise<void>;
|
|
36
|
-
listSessions(): Array<{
|
|
37
|
-
name: string;
|
|
38
|
-
}>;
|
|
39
|
-
getStatus(name: string): {
|
|
40
|
-
stats: {
|
|
41
|
-
tokensIn: number;
|
|
42
|
-
tokensOut: number;
|
|
43
|
-
contextPercent: number;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
compactSession(name: string): Promise<unknown>;
|
|
47
|
-
}
|
|
48
|
-
export declare function applyDefaultPathPerfHooks(request: OpenAIChatCompletionRequestType): void;
|
|
49
|
-
export declare function handleChatCompletion(manager: SessionManagerLike, body: Record<string, unknown>, headers: http.IncomingHttpHeaders, res: http.ServerResponse): Promise<void>;
|