@a1hvdy/cc-openclaw 0.30.0 → 0.32.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/engines/persistent-session.js +11 -0
- 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 +121 -9
- 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,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>;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Canonical OpenAI request/response type definitions.
|
|
3
|
-
*
|
|
4
|
-
* Extracted from `openai-compat.ts` 2026-05-13 to push that file under the
|
|
5
|
-
* 500-LOC ceiling and to give 4 downstream importers
|
|
6
|
-
* (`tool-results-serializer`, `session-key-resolver`, `message-extractor`,
|
|
7
|
-
* `tool-calls-parser`) a single canonical source instead of importing back
|
|
8
|
-
* through the godmodule.
|
|
9
|
-
*/
|
|
10
|
-
export interface OpenAIChatMessage {
|
|
11
|
-
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
12
|
-
content: string | Array<{
|
|
13
|
-
type?: string;
|
|
14
|
-
text?: string;
|
|
15
|
-
}> | null;
|
|
16
|
-
tool_calls?: Array<{
|
|
17
|
-
id: string;
|
|
18
|
-
type: 'function';
|
|
19
|
-
function: {
|
|
20
|
-
name: string;
|
|
21
|
-
arguments: string;
|
|
22
|
-
};
|
|
23
|
-
}>;
|
|
24
|
-
tool_call_id?: string;
|
|
25
|
-
}
|
|
26
|
-
export interface OpenAIChatCompletionRequest {
|
|
27
|
-
model?: string;
|
|
28
|
-
messages: OpenAIChatMessage[];
|
|
29
|
-
stream?: boolean;
|
|
30
|
-
temperature?: number;
|
|
31
|
-
max_tokens?: number;
|
|
32
|
-
max_completion_tokens?: number;
|
|
33
|
-
user?: string;
|
|
34
|
-
tools?: Array<{
|
|
35
|
-
type: 'function';
|
|
36
|
-
function: {
|
|
37
|
-
name: string;
|
|
38
|
-
description: string;
|
|
39
|
-
parameters: unknown;
|
|
40
|
-
};
|
|
41
|
-
}>;
|
|
42
|
-
}
|
|
43
|
-
export interface OpenAIToolCall {
|
|
44
|
-
id: string;
|
|
45
|
-
type: 'function';
|
|
46
|
-
function: {
|
|
47
|
-
name: string;
|
|
48
|
-
arguments: string;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
export interface OpenAIChatCompletionResponse {
|
|
52
|
-
id: string;
|
|
53
|
-
object: 'chat.completion';
|
|
54
|
-
created: number;
|
|
55
|
-
model: string;
|
|
56
|
-
choices: Array<{
|
|
57
|
-
index: number;
|
|
58
|
-
message: {
|
|
59
|
-
role: 'assistant';
|
|
60
|
-
content: string | null;
|
|
61
|
-
tool_calls?: OpenAIToolCall[];
|
|
62
|
-
reasoning?: string;
|
|
63
|
-
};
|
|
64
|
-
finish_reason: 'stop' | 'length' | 'tool_calls';
|
|
65
|
-
}>;
|
|
66
|
-
usage?: {
|
|
67
|
-
prompt_tokens: number;
|
|
68
|
-
completion_tokens: number;
|
|
69
|
-
total_tokens: number;
|
|
70
|
-
};
|
|
71
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `parseRouteBody` — typed boundary parser for openai-compat HTTP route.
|
|
3
|
-
*
|
|
4
|
-
* Replaces inline `as OpenAIChatMessage[]` casts with a discriminated-union
|
|
5
|
-
* returning either a fully-typed `OpenAIChatCompletionRequest` or an
|
|
6
|
-
* error-coded response. The type system enforces "validate before use."
|
|
7
|
-
*
|
|
8
|
-
* Extracted from `openai-compat.ts` 2026-05-13. Pure validation function —
|
|
9
|
-
* no I/O, no module state. Behavior preserved bit-for-bit per the existing
|
|
10
|
-
* `tests/openai-compat.test.ts` round-trip cases.
|
|
11
|
-
*
|
|
12
|
-
* Type imports cross-reference back to openai-compat.ts; TypeScript handles
|
|
13
|
-
* type-only circular imports cleanly without runtime cycle.
|
|
14
|
-
*/
|
|
15
|
-
import type { OpenAIChatCompletionRequest } from './openai-compat.js';
|
|
16
|
-
export type ParseRequestResult = {
|
|
17
|
-
readonly ok: true;
|
|
18
|
-
readonly request: OpenAIChatCompletionRequest;
|
|
19
|
-
} | {
|
|
20
|
-
readonly ok: false;
|
|
21
|
-
readonly status: number;
|
|
22
|
-
readonly error: string;
|
|
23
|
-
};
|
|
24
|
-
export declare function parseRouteBody(body: Record<string, unknown>): ParseRequestResult;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cluster B — Session system-prompt builders.
|
|
3
|
-
*
|
|
4
|
-
* Extracted verbatim from `openai-compat.ts:143-250` (Phase 4 Cluster B).
|
|
5
|
-
* Three tightly-coupled pure functions that compose the session-level
|
|
6
|
-
* system prompt sent to Claude CLI on session create:
|
|
7
|
-
*
|
|
8
|
-
* - `noToolsSystemPrompt(toolLocation)` — anti-hallucination preamble
|
|
9
|
-
* (varies by CC_OPENCLAW_ALLOW_BUILTINS env flag)
|
|
10
|
-
* - `buildToolPromptBlock(tools)` — `<available_tools>` XML block
|
|
11
|
-
* - `buildSessionSystemPrompt(...)` — orchestrator that combines
|
|
12
|
-
* the above with the caller-supplied prompt, honoring tool-stream
|
|
13
|
-
* and tools-per-message mode flags
|
|
14
|
-
*
|
|
15
|
-
* Behavior is preserved bit-for-bit. The orchestrator (`handleChatCompletion`
|
|
16
|
-
* in openai-compat.ts) calls `buildSessionSystemPrompt` exactly once per
|
|
17
|
-
* fresh session create; `buildToolPromptBlock` is also called directly when
|
|
18
|
-
* tools must be injected per-turn into the user message (legacy path).
|
|
19
|
-
*
|
|
20
|
-
* Type-only import of `OpenAIChatCompletionRequest` keeps the file in a
|
|
21
|
-
* one-way relationship with openai-compat.ts at runtime (ESM erases type
|
|
22
|
-
* imports), so this module can be loaded standalone.
|
|
23
|
-
*/
|
|
24
|
-
import type { OpenAIChatCompletionRequest } from './openai-compat.js';
|
|
25
|
-
/**
|
|
26
|
-
* Generate the "no built-in tools" system prompt preamble.
|
|
27
|
-
* The `toolLocation` parameter controls how the model is told where to find
|
|
28
|
-
* tool definitions — 'system' means "in the <available_tools> block below"
|
|
29
|
-
* (tools baked into system prompt), 'user' means "in <available_tools> tags
|
|
30
|
-
* in the user message" (legacy per-turn injection).
|
|
31
|
-
*/
|
|
32
|
-
export declare function noToolsSystemPrompt(toolLocation: 'system' | 'user'): string;
|
|
33
|
-
/**
|
|
34
|
-
* Convert OpenAI tool definitions into a structured prompt block.
|
|
35
|
-
* Injected into the user message so the CLI model sees tool definitions
|
|
36
|
-
* and responds with <tool_calls> tags when it wants to invoke a function.
|
|
37
|
-
*/
|
|
38
|
-
export declare function buildToolPromptBlock(tools: OpenAIChatCompletionRequest['tools']): string;
|
|
39
|
-
/**
|
|
40
|
-
* Build the full session system prompt for a Claude Code session with tools.
|
|
41
|
-
* Exported for testability — called from `handleChatCompletion`.
|
|
42
|
-
*
|
|
43
|
-
* - Default mode: tools are embedded in the system prompt (cacheable by Anthropic).
|
|
44
|
-
* - Legacy mode (OPENAI_COMPAT_TOOLS_PER_MESSAGE=1): tools are NOT embedded;
|
|
45
|
-
* they'll be injected per-turn in the user message instead.
|
|
46
|
-
*/
|
|
47
|
-
export declare function buildSessionSystemPrompt(tools: OpenAIChatCompletionRequest['tools'], callerSystemPrompt: string | undefined): string;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Single-flight request coalescer for the openai-compat streaming path (v0.27.5).
|
|
3
|
-
*
|
|
4
|
-
* THE PROBLEM (2026-05-22 incident)
|
|
5
|
-
* ─────────────────────────────────
|
|
6
|
-
* When a turn is OOM-killed mid-stream (exit 137) — or simply runs long enough
|
|
7
|
-
* that OpenClaw's HTTP client perceives the SSE stream as dead — OpenClaw fires
|
|
8
|
-
* a RETRY with a byte-identical request body. session-manager.sendMessage()
|
|
9
|
-
* *serializes* concurrent same-session sends via a per-session promise chain
|
|
10
|
-
* (session-manager.ts:437-453) rather than coalescing them, so the retry runs
|
|
11
|
-
* the FULL turn a second time and delivers a second, identical Telegram message
|
|
12
|
-
* (the "two identical messages" the user reported).
|
|
13
|
-
*
|
|
14
|
-
* THE FIX
|
|
15
|
-
* ───────
|
|
16
|
-
* Classic single-flight (a.k.a. request coalescing): the FIRST request for a
|
|
17
|
-
* given signature becomes the "leader" and runs the model once; any duplicate
|
|
18
|
-
* arriving within DEDUP_WINDOW_MS becomes a "follower" that AWAITS the leader's
|
|
19
|
-
* result and replays it — no second subprocess, no divergent second generation.
|
|
20
|
-
* In the common retry-after-perceived-death case, OpenClaw has already abandoned
|
|
21
|
-
* the leader's connection, so only the follower delivers → exactly one message.
|
|
22
|
-
*
|
|
23
|
-
* SAFETY: FAIL-OPEN BY CONSTRUCTION
|
|
24
|
-
* ─────────────────────────────────
|
|
25
|
-
* The caller wraps every coalescer interaction in try/catch and, on ANY error
|
|
26
|
-
* (or a leader that produced empty text, or a leader that exceeds the turn
|
|
27
|
-
* timeout), falls THROUGH to a normal dispatch. The worst case this can produce
|
|
28
|
-
* is the prior behavior (a possible duplicate) — it can NEVER drop a real reply.
|
|
29
|
-
* That property is the whole point: the user's deepest pain is missing messages,
|
|
30
|
-
* so the duplicate defense must not be able to cause a miss.
|
|
31
|
-
*/
|
|
32
|
-
import type * as http from 'node:http';
|
|
33
|
-
/** The leader's captured turn output, replayed verbatim to followers. */
|
|
34
|
-
export interface CoalescedResult {
|
|
35
|
-
text: string;
|
|
36
|
-
finishReason: 'stop' | 'tool_calls';
|
|
37
|
-
usage?: {
|
|
38
|
-
prompt_tokens: number;
|
|
39
|
-
completion_tokens: number;
|
|
40
|
-
total_tokens: number;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
interface InFlightEntry {
|
|
44
|
-
startedAt: number;
|
|
45
|
-
/** Resolves when the leader's turn completes. `null` ⇒ leader failed or
|
|
46
|
-
* produced no replayable text; followers must fail-open to a fresh run. */
|
|
47
|
-
resultPromise: Promise<CoalescedResult | null>;
|
|
48
|
-
}
|
|
49
|
-
/** Resolve the dedup window. CC_OPENCLAW_DEDUP_WINDOW_MS=0 disables coalescing
|
|
50
|
-
* entirely (the caller then never enters the leader/follower branches). */
|
|
51
|
-
export declare function getDedupWindowMs(): number;
|
|
52
|
-
/** Stable signature for "the same turn". Session-scoped so two chats sending
|
|
53
|
-
* identical text never collide. SHA-256 of sessionName + NUL + serialized
|
|
54
|
-
* input keeps the key bounded regardless of prompt size. */
|
|
55
|
-
export declare function computeSignature(sessionName: string, input: unknown): string;
|
|
56
|
-
/** Return a live (within-window) in-flight entry for `sig`, or undefined.
|
|
57
|
-
* Prunes a stale entry as a side effect so the map self-heals. */
|
|
58
|
-
export declare function findInFlight(sig: string, windowMs: number): InFlightEntry | undefined;
|
|
59
|
-
/** Register the current request as the leader for `sig`. Returns a `resolve`
|
|
60
|
-
* the caller MUST invoke in a finally block with the captured result (or
|
|
61
|
-
* `null` on failure) so followers never hang. The entry is retained for the
|
|
62
|
-
* window after resolution, then evicted. */
|
|
63
|
-
export declare function registerLeader(sig: string): {
|
|
64
|
-
resolve: (r: CoalescedResult | null) => void;
|
|
65
|
-
};
|
|
66
|
-
/** Await a leader's result with a hard cap so a wedged leader can't hang the
|
|
67
|
-
* follower forever. On timeout returns `null` ⇒ caller fails open. */
|
|
68
|
-
export declare function awaitLeader(entry: InFlightEntry, timeoutMs: number): Promise<CoalescedResult | null>;
|
|
69
|
-
/** Replay a leader's captured result to a follower's response as a complete,
|
|
70
|
-
* well-formed SSE stream (role chunk → content chunk → final chunk → [DONE]).
|
|
71
|
-
* Mirrors the shape handleStreaming emits so OpenClaw sees an ordinary, valid
|
|
72
|
-
* completion. Best-effort writes: a disconnected follower socket is harmless. */
|
|
73
|
-
export declare function replayCoalesced(res: http.ServerResponse, completionId: string, model: string, result: CoalescedResult): void;
|
|
74
|
-
/** Test-only helpers. */
|
|
75
|
-
export declare function _resetForTest(): void;
|
|
76
|
-
export declare function _size(): number;
|
|
77
|
-
export {};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cluster B — Response formatters.
|
|
3
|
-
*
|
|
4
|
-
* Extracted verbatim from `openai-compat.ts:178-241` (Phase 4 Cluster B
|
|
5
|
-
* Module E — the final Cluster B extraction). Two pure formatters that
|
|
6
|
-
* wrap the model's output in the OpenAI Chat-Completions envelope:
|
|
7
|
-
*
|
|
8
|
-
* - `formatCompletionResponse(...)` — non-streaming (single object).
|
|
9
|
-
* Carries `usage`, optional `tool_calls`, optional `reasoning` field,
|
|
10
|
-
* and a v0.7.2 "Done." text backstop when the model produced no
|
|
11
|
-
* visible text (the openclaw upstream classifier rejects payloads=0
|
|
12
|
-
* turns and burns a retry attempt; the directive in the system
|
|
13
|
-
* prompt is the primary fix, this is belt-and-suspenders).
|
|
14
|
-
*
|
|
15
|
-
* - `formatCompletionChunk(...)` — streaming SSE chunk. Called once
|
|
16
|
-
* per delta (start, content, tool_calls, finish_reason).
|
|
17
|
-
*
|
|
18
|
-
* Twelve+ call sites in the orchestrator (handleChatCompletion) — every
|
|
19
|
-
* place that writes back to the OpenAI-shaped HTTP response. Pulling
|
|
20
|
-
* these out keeps the orchestrator focused on session lifecycle and CLI
|
|
21
|
-
* IO; the OpenAI envelope details live alongside the types they shape.
|
|
22
|
-
*/
|
|
23
|
-
import type { OpenAIToolCall, OpenAIChatCompletionResponse, OpenAIChatCompletionChunk } from './openai-compat.js';
|
|
24
|
-
export declare function formatCompletionResponse(id: string, model: string, text: string, tokensIn: number, tokensOut: number, toolCalls?: OpenAIToolCall[],
|
|
25
|
-
/** v0.7.0: when present + non-empty, attached as `choices[0].message.reasoning`
|
|
26
|
-
* (mirrors OpenAI o1/o3 schema). Caller must already be gated on
|
|
27
|
-
* `getSurfaceThinkingEnabled()` from `lib/config.ts` — this function does
|
|
28
|
-
* not re-check the flag. Pass empty string or undefined to omit. */
|
|
29
|
-
reasoning?: string): OpenAIChatCompletionResponse;
|
|
30
|
-
export declare function formatCompletionChunk(id: string, model: string, delta: {
|
|
31
|
-
role?: string;
|
|
32
|
-
content?: string;
|
|
33
|
-
}, finishReason: string | null): OpenAIChatCompletionChunk;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cluster B beachhead — session key resolution.
|
|
3
|
-
*
|
|
4
|
-
* Extracted from `openai-compat.ts:224-270`. Pure functions, no side
|
|
5
|
-
* effects, no external state. The session key is the single most
|
|
6
|
-
* load-bearing concept in the cc-openclaw bridge: it determines whether
|
|
7
|
-
* two requests share a persistent Claude CLI session (and thus benefit
|
|
8
|
-
* from prompt caching) or land in separate sessions.
|
|
9
|
-
*
|
|
10
|
-
* Resolution priority chain (highest → lowest):
|
|
11
|
-
* 1. `X-Session-Id` header → caller-explicit override
|
|
12
|
-
* 2. `body.user` field → OpenAI standard convention
|
|
13
|
-
* 3. sha1(model + system messages + tools) → content-derived fingerprint
|
|
14
|
-
* 4. literal `'default'` → fallback when nothing distinguishes
|
|
15
|
-
*
|
|
16
|
-
* Tool fingerprint inclusion (point 3) is the v0.4.x fix for the
|
|
17
|
-
* "session reuse with stale tool list" bug — see openai-compat.ts:233-243
|
|
18
|
-
* comments for the original rationale.
|
|
19
|
-
*/
|
|
20
|
-
import * as http from 'node:http';
|
|
21
|
-
import type { OpenAIChatCompletionRequest } from './openai-compat.js';
|
|
22
|
-
/**
|
|
23
|
-
* Resolve a stable session key from a request. Behavior preserved
|
|
24
|
-
* verbatim from the original at openai-compat.ts:224.
|
|
25
|
-
*
|
|
26
|
-
* The `tools-per-message` mode opt-out (line 244) restores pre-fix
|
|
27
|
-
* behavior of keying sessions only by system prompt + model — needed
|
|
28
|
-
* for callers that mutate their tool list within one conversation
|
|
29
|
-
* and rely on continuing history across tool changes.
|
|
30
|
-
*/
|
|
31
|
-
export declare function resolveSessionKey(body: OpenAIChatCompletionRequest, headers: http.IncomingHttpHeaders): string;
|
|
32
|
-
/**
|
|
33
|
-
* Build the full session name from a key. Adds the `'openai-'` prefix
|
|
34
|
-
* that gates downstream behavior (CWD redirect, tools restoration,
|
|
35
|
-
* CLAUDE.md injection — all in cwd-patch.ts:489). The prefix is
|
|
36
|
-
* load-bearing; do not remove or modify without checking those gates.
|
|
37
|
-
*
|
|
38
|
-
* Cluster D `SessionRegistry` will introduce a branded `SessionName`
|
|
39
|
-
* type so this function returns a typed value rather than a raw string.
|
|
40
|
-
*/
|
|
41
|
-
export declare function sessionNameFromKey(key: string): string;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Workspace skill resolver — finds and reads
|
|
3
|
-
* ~/.openclaw/workspace/skills/*\/SKILL.md by slash command name (taken
|
|
4
|
-
* from each SKILL.md's frontmatter `name:` field).
|
|
5
|
-
*
|
|
6
|
-
* Used by openai-compat.ts to inline the SKILL.md body into the user
|
|
7
|
-
* prompt when the user invokes /<skillname>. This makes workspace
|
|
8
|
-
* skills work through the cc-openclaw bridge without requiring the
|
|
9
|
-
* model to use the Read tool (which the legacy code path intentionally
|
|
10
|
-
* disables — see the gated `sessionConfig.tools = ''` in openai-compat.ts,
|
|
11
|
-
* Phase 2 R5).
|
|
12
|
-
*
|
|
13
|
-
* Phase 2 R6 (2026-05-02): the resolver operates purely on user-message
|
|
14
|
-
* text — it never reads `request.tools` and never rejects requests that
|
|
15
|
-
* carry tool definitions. Tool-stream mode (CC_OPENCLAW_TOOL_STREAM=1)
|
|
16
|
-
* therefore coexists with skill auto-inline by construction: the user
|
|
17
|
-
* message text gets the SKILL.md body inlined, AND the tools[] allowlist
|
|
18
|
-
* gets forwarded to Claude CLI via sessionConfig.tools (R3). Both fire,
|
|
19
|
-
* neither blocks the other.
|
|
20
|
-
*
|
|
21
|
-
* v0.9.2 (2026-05-11): SKILL.md **bodies** are re-read from disk on
|
|
22
|
-
* every slash invocation; only the directory listing (filename →
|
|
23
|
-
* frontmatter `name:` mapping) is cached, keyed by directory mtime.
|
|
24
|
-
* Pre-v0.9.2 the body was also cached, which surfaced stale content
|
|
25
|
-
* when a user edited a SKILL.md file in place (the dir mtime stayed
|
|
26
|
-
* unchanged, so the cache wasn't refreshed). Analogous in spirit to
|
|
27
|
-
* the upstream OpenClaw 2026.5.7 "clear cached skills snapshots on
|
|
28
|
-
* /new" fix, but narrower. SKILL.md files are small (~few KB); a
|
|
29
|
-
* per-invocation read is ~1ms, well-bounded against rare slash usage.
|
|
30
|
-
*
|
|
31
|
-
* Override path with OPENCLAW_WORKSPACE_SKILLS_DIR env var.
|
|
32
|
-
*/
|
|
33
|
-
/**
|
|
34
|
-
* Public shape returned by `resolveSkillForSlash`. Caller (`maybeInlineSkill`)
|
|
35
|
-
* consumes `fullText` and `body`. Both are re-read fresh on every invocation
|
|
36
|
-
* from v0.9.2 onward — previously cached, now fresh-from-disk so in-place
|
|
37
|
-
* SKILL.md edits surface immediately.
|
|
38
|
-
*/
|
|
39
|
-
interface SkillEntry {
|
|
40
|
-
skillDir: string;
|
|
41
|
-
skillMd: string;
|
|
42
|
-
body: string;
|
|
43
|
-
fullText: string;
|
|
44
|
-
}
|
|
45
|
-
export declare function resolveSkillForSlash(name: string): SkillEntry | null;
|
|
46
|
-
/**
|
|
47
|
-
* v0.19.1 M3 — detect leading `/<slash>` (with optional `<system>` wrap)
|
|
48
|
-
* in raw user text, returning `{cmd, mode}` for the live-card pill.
|
|
49
|
-
*
|
|
50
|
-
* Decoupled from `maybeInlineSkill` because the pill should surface even
|
|
51
|
-
* when the slash has no matching SKILL.md (e.g. `/cc /custom-thing`).
|
|
52
|
-
* `mode` is the first whitespace-separated arg token if present.
|
|
53
|
-
*/
|
|
54
|
-
export declare function detectSlashCommand(userText: string): {
|
|
55
|
-
cmd: string;
|
|
56
|
-
mode?: string;
|
|
57
|
-
} | null;
|
|
58
|
-
export declare function maybeInlineSkill(userText: string): string | null;
|
|
59
|
-
export {};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Translates parsed Anthropic Messages stream events (from cli-stream-parser)
|
|
3
|
-
* into OpenAI-shaped Server-Sent Events for `/v1/chat/completions` streaming.
|
|
4
|
-
*
|
|
5
|
-
* Output format: each entry is a complete SSE wire chunk including the `data: `
|
|
6
|
-
* prefix and trailing `\n\n`. Caller writes them directly to the response
|
|
7
|
-
* stream.
|
|
8
|
-
*
|
|
9
|
-
* Anthropic content blocks (text vs tool_use vs thinking) become OpenAI
|
|
10
|
-
* `delta.content` (text) or `delta.tool_calls[N]` (tool_use). Thinking
|
|
11
|
-
* blocks are dropped by default; v0.7.0 added an opt-in `surfaceThinking`
|
|
12
|
-
* flag that accumulates thinking_delta text and exposes it as a `reasoning`
|
|
13
|
-
* field (mirroring OpenAI o1/o3 schema). Default OFF for privacy: thinking
|
|
14
|
-
* content can contain raw chain-of-thought, considered-but-rejected
|
|
15
|
-
* candidates, and PII. `signature_delta` is NEVER forwarded — it carries
|
|
16
|
-
* Anthropic's cryptographic block-integrity signature, internal-only.
|
|
17
|
-
*
|
|
18
|
-
* State: each translator instance tracks a per-content-block-index map of
|
|
19
|
-
* `tool_use` blocks to their assigned OpenAI tool_calls index, so
|
|
20
|
-
* `input_json_delta` events emit deltas at the correct tool_calls[N] slot.
|
|
21
|
-
* When `surfaceThinking` is on, additionally tracks `thinkingBuffer` and
|
|
22
|
-
* `thinkingIndex` to assemble the reasoning text across deltas.
|
|
23
|
-
*/
|
|
24
|
-
import type { ParsedEvent } from './cli-stream-parser.js';
|
|
25
|
-
export interface SseTranslator {
|
|
26
|
-
/** Translate a single ParsedEvent into zero or more SSE chunks. */
|
|
27
|
-
translate(event: ParsedEvent): string[];
|
|
28
|
-
/** Emit final `data: [DONE]\n\n` sentinel. Call once at end of stream. */
|
|
29
|
-
done(): string[];
|
|
30
|
-
/**
|
|
31
|
-
* v0.7.0: read accumulated thinking text after stream ends. Empty string
|
|
32
|
-
* when `surfaceThinking` was off or no thinking blocks fired. Used by
|
|
33
|
-
* non-streaming response builder to attach `choices[0].message.reasoning`.
|
|
34
|
-
*/
|
|
35
|
-
getReasoning(): string;
|
|
36
|
-
}
|
|
37
|
-
export interface CreateSseTranslatorParams {
|
|
38
|
-
completionId: string;
|
|
39
|
-
model: string;
|
|
40
|
-
/** When true, emits an OpenAI usage chunk on message_delta (default false). */
|
|
41
|
-
emitUsage?: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* v0.7.0: when true, accumulates `thinking_delta` text and emits synthetic
|
|
44
|
-
* SSE chunks with `delta.reasoning = <text>` (mirroring OpenAI o1/o3 streaming
|
|
45
|
-
* shape). Default false. Privacy-sensitive — opt-in only via env-flag-driven
|
|
46
|
-
* caller, typically `getSurfaceThinkingEnabled()` from `lib/config.ts`.
|
|
47
|
-
* `signature_delta` is NEVER forwarded regardless of this flag.
|
|
48
|
-
*/
|
|
49
|
-
surfaceThinking?: boolean;
|
|
50
|
-
}
|
|
51
|
-
export declare function createSseTranslator(params: CreateSseTranslatorParams): SseTranslator;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cluster B Phase 2 — Status reporting + tool-description helpers.
|
|
3
|
-
*
|
|
4
|
-
* Extracted verbatim from `openai-compat.ts:516-569` (Module F).
|
|
5
|
-
*
|
|
6
|
-
* - `reportStatus(state, activity, tool?)` — best-effort fire-and-forget
|
|
7
|
-
* HTTP POST to the OPENAI_COMPAT_STATUS_URL webhook. The receiving
|
|
8
|
-
* dashboard (e.g. a webchat status bar) gets real-time progress while
|
|
9
|
-
* the CLI agent runs tools. No-op when the env var is unset.
|
|
10
|
-
*
|
|
11
|
-
* - `getToolDescription(toolName, toolInput?)` — human-readable one-liner
|
|
12
|
-
* for a tool call. Used by handleNonStreaming + handleStreaming to
|
|
13
|
-
* populate the `tool` field of the status payload. Switch on tool name
|
|
14
|
-
* with sensible fallback ("Using tool: <name>") for unknown tools.
|
|
15
|
-
*
|
|
16
|
-
* Both functions are pure-ish: no shared mutable state, no closure
|
|
17
|
-
* capture from the orchestrator. `reportStatus` reads the URL env
|
|
18
|
-
* variable on every call so ops can flip it via launchctl/PM2 env
|
|
19
|
-
* without restarting the gateway.
|
|
20
|
-
*/
|
|
21
|
-
/**
|
|
22
|
-
* Optional status webhook — set `OPENAI_COMPAT_STATUS_URL` to an HTTP endpoint
|
|
23
|
-
* that accepts `POST { state, activity, tool }`. The bridge will fire-and-forget
|
|
24
|
-
* status updates when the CLI agent uses tools, so an external dashboard (e.g.
|
|
25
|
-
* a webchat status bar) can show real-time progress.
|
|
26
|
-
*
|
|
27
|
-
* Example: `OPENAI_COMPAT_STATUS_URL=http://127.0.0.1:18795/my-app/agent-status`
|
|
28
|
-
*/
|
|
29
|
-
export declare function reportStatus(state: string, activity: string, tool?: string): void;
|
|
30
|
-
export declare function getToolDescription(toolName: string, toolInput?: Record<string, unknown>): string;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cluster B Phase 2 — Streaming SSE HTTP handler.
|
|
3
|
-
*
|
|
4
|
-
* Extracted verbatim from `openai-compat.ts:514-775` (Module H).
|
|
5
|
-
* Handles the response path when the caller requested `stream:true`.
|
|
6
|
-
* Emits Server-Sent Events with intermediate `delta` chunks and a final
|
|
7
|
-
* chunk carrying `finish_reason` + token usage.
|
|
8
|
-
*
|
|
9
|
-
* Three dispatch paths (decided at runtime by `useToolStream + hasTools`):
|
|
10
|
-
*
|
|
11
|
-
* 1. **Tool-stream mode** (`isToolStreamMode() && hasTools`)
|
|
12
|
-
* Session-manager's pre-parsed `tool_use` events are bridged
|
|
13
|
-
* directly to OpenAI `tool_calls` SSE deltas — two chunks per
|
|
14
|
-
* tool use (start + arguments). Text deltas stream inline.
|
|
15
|
-
*
|
|
16
|
-
* 2. **Legacy tools mode** (`hasTools && !useToolStream`)
|
|
17
|
-
* Buffer the full response text, post-stream-parse `<tool_calls>`
|
|
18
|
-
* XML via `parseToolCallsFromText`, emit text + tool_call chunks
|
|
19
|
-
* with `finish_reason='tool_calls'`.
|
|
20
|
-
*
|
|
21
|
-
* 3. **No-tools** (`!hasTools`)
|
|
22
|
-
* Stream text deltas inline, emit final chunk with
|
|
23
|
-
* `finish_reason='stop'`.
|
|
24
|
-
*
|
|
25
|
-
* v0.7.2 backstop: if no visible payload was streamed (no text, no
|
|
26
|
-
* tool_calls), emit a minimal "Done." text chunk before finalizing so
|
|
27
|
-
* the upstream "incomplete terminal response" classifier sees content.
|
|
28
|
-
*
|
|
29
|
-
* Heartbeat: 30s SSE keepalive comment (`: keepalive`) prevents proxies
|
|
30
|
-
* from closing the connection during long Claude CLI thinking phases.
|
|
31
|
-
* Cleaned up in the `finally` block.
|
|
32
|
-
*
|
|
33
|
-
* Client disconnect: `res.on('close')` flips `clientDisconnected` so
|
|
34
|
-
* writes after disconnect short-circuit instead of throwing.
|
|
35
|
-
*
|
|
36
|
-
* Parameterized fully — no closure capture from openai-compat.ts.
|
|
37
|
-
*/
|
|
38
|
-
import type * as http from 'node:http';
|
|
39
|
-
import type { SessionManagerLike } from './openai-compat.js';
|
|
40
|
-
import type { UserMessageBlock } from './message-extractor.js';
|
|
41
|
-
export declare function handleStreaming(manager: SessionManagerLike, sessionName: string, model: string, userMessage: string | UserMessageBlock[], completionId: string, res: http.ServerResponse, hasTools: boolean, slashCommand?: {
|
|
42
|
-
cmd: string;
|
|
43
|
-
mode?: string;
|
|
44
|
-
}, onFinalText?: (result: {
|
|
45
|
-
text: string;
|
|
46
|
-
finishReason: 'stop' | 'tool_calls';
|
|
47
|
-
usage?: {
|
|
48
|
-
prompt_tokens: number;
|
|
49
|
-
completion_tokens: number;
|
|
50
|
-
total_tokens: number;
|
|
51
|
-
};
|
|
52
|
-
}) => void): Promise<void>;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cluster B — Tool-calls parser.
|
|
3
|
-
*
|
|
4
|
-
* Extracted verbatim from `openai-compat.ts:147-221` (Phase 4 Cluster B
|
|
5
|
-
* Module B). Reads model output text and pulls out any `<tool_calls>`
|
|
6
|
-
* XML blocks, converting them to OpenAI-compatible `OpenAIToolCall[]`.
|
|
7
|
-
*
|
|
8
|
-
* This is the response-side counterpart to `prompts.ts:buildToolPromptBlock`
|
|
9
|
-
* — the prompt tells the model "wrap your tool calls in `<tool_calls>`",
|
|
10
|
-
* and this parser is what reads those tool calls back out of the model's
|
|
11
|
-
* text response on the legacy (non-stream) tool path.
|
|
12
|
-
*
|
|
13
|
-
* Behavior preserved bit-for-bit. Two call sites in the orchestrator
|
|
14
|
-
* (handleChatCompletion lines 950 + 1181) — one on the buffered final
|
|
15
|
-
* output path, one on the streaming-buffered-text path.
|
|
16
|
-
*
|
|
17
|
-
* Robustness contract:
|
|
18
|
-
* - Multiple `<tool_calls>` blocks in one response → all merged
|
|
19
|
-
* - JSON parse fail on a block → that block kept as text content
|
|
20
|
-
* - `arguments` field as string or object → both normalized to string
|
|
21
|
-
* - `<tool_result>` echoes from the model → stripped from textContent
|
|
22
|
-
*/
|
|
23
|
-
import type { OpenAIToolCall } from './openai-compat.js';
|
|
24
|
-
export interface ParsedToolCalls {
|
|
25
|
-
textContent: string | null;
|
|
26
|
-
toolCalls: OpenAIToolCall[];
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Parse tool_calls from CLI text output.
|
|
30
|
-
*
|
|
31
|
-
* Looks for <tool_calls>[...]</tool_calls> tags in the response text.
|
|
32
|
-
* Returns both the extracted text content (before/after tags) and any tool calls found.
|
|
33
|
-
*/
|
|
34
|
-
export declare function parseToolCallsFromText(text: string): ParsedToolCalls;
|