@a1hvdy/cc-openclaw 0.6.0 → 0.7.1
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/engines/persistent-session.js +13 -0
- package/dist/src/engines/persistent-session.js.map +1 -1
- package/dist/src/lib/config.d.ts +2 -0
- package/dist/src/lib/config.js +19 -0
- package/dist/src/lib/config.js.map +1 -1
- package/dist/src/lib/trajectory.d.ts +1 -1
- package/dist/src/lib/trajectory.js.map +1 -1
- package/dist/src/lib/vendor-paths.d.ts +6 -4
- package/dist/src/lib/vendor-paths.js +21 -14
- package/dist/src/lib/vendor-paths.js.map +1 -1
- package/dist/src/openai-compat/openai-compat.d.ts +7 -1
- package/dist/src/openai-compat/openai-compat.js +35 -4
- package/dist/src/openai-compat/openai-compat.js.map +1 -1
- package/dist/src/openai-compat/sse-translator.d.ts +23 -3
- package/dist/src/openai-compat/sse-translator.js +45 -6
- package/dist/src/openai-compat/sse-translator.js.map +1 -1
- package/dist/src/types.d.ts +9 -0
- package/package.json +2 -3
- package/vendor/base-oneshot-session.d.ts +0 -87
- package/vendor/base-oneshot-session.js +0 -227
- package/vendor/base-oneshot-session.js.map +0 -1
- package/vendor/circuit-breaker.d.ts +0 -21
- package/vendor/circuit-breaker.js +0 -47
- package/vendor/circuit-breaker.js.map +0 -1
- package/vendor/consensus.d.ts +0 -20
- package/vendor/consensus.js +0 -52
- package/vendor/consensus.js.map +0 -1
- package/vendor/constants.d.ts +0 -130
- package/vendor/constants.js +0 -139
- package/vendor/constants.js.map +0 -1
- package/vendor/council.d.ts +0 -67
- package/vendor/council.js +0 -913
- package/vendor/council.js.map +0 -1
- package/vendor/embedded-server.d.ts +0 -25
- package/vendor/embedded-server.js +0 -373
- package/vendor/embedded-server.js.map +0 -1
- package/vendor/inbox-manager.d.ts +0 -38
- package/vendor/inbox-manager.js +0 -111
- package/vendor/inbox-manager.js.map +0 -1
- package/vendor/index.d.ts +0 -63
- package/vendor/index.js +0 -705
- package/vendor/index.js.map +0 -1
- package/vendor/logger.d.ts +0 -16
- package/vendor/logger.js +0 -44
- package/vendor/logger.js.map +0 -1
- package/vendor/models.d.ts +0 -69
- package/vendor/models.js +0 -289
- package/vendor/models.js.map +0 -1
- package/vendor/openai-compat.d.ts +0 -197
- package/vendor/openai-compat.js +0 -765
- package/vendor/openai-compat.js.map +0 -1
- package/vendor/persistent-codex-session.d.ts +0 -16
- package/vendor/persistent-codex-session.js +0 -105
- package/vendor/persistent-codex-session.js.map +0 -1
- package/vendor/persistent-cursor-session.d.ts +0 -21
- package/vendor/persistent-cursor-session.js +0 -241
- package/vendor/persistent-cursor-session.js.map +0 -1
- package/vendor/persistent-custom-session.d.ts +0 -78
- package/vendor/persistent-custom-session.js +0 -937
- package/vendor/persistent-custom-session.js.map +0 -1
- package/vendor/persistent-gemini-session.d.ts +0 -21
- package/vendor/persistent-gemini-session.js +0 -216
- package/vendor/persistent-gemini-session.js.map +0 -1
- package/vendor/persistent-session.d.ts +0 -74
- package/vendor/persistent-session.js +0 -698
- package/vendor/persistent-session.js.map +0 -1
- package/vendor/proxy/anthropic-adapter.d.ts +0 -136
- package/vendor/proxy/anthropic-adapter.js +0 -392
- package/vendor/proxy/anthropic-adapter.js.map +0 -1
- package/vendor/proxy/handler.d.ts +0 -39
- package/vendor/proxy/handler.js +0 -323
- package/vendor/proxy/handler.js.map +0 -1
- package/vendor/proxy/schema-cleaner.d.ts +0 -11
- package/vendor/proxy/schema-cleaner.js +0 -34
- package/vendor/proxy/schema-cleaner.js.map +0 -1
- package/vendor/proxy/thought-cache.d.ts +0 -19
- package/vendor/proxy/thought-cache.js +0 -53
- package/vendor/proxy/thought-cache.js.map +0 -1
- package/vendor/session-manager.d.ts +0 -211
- package/vendor/session-manager.js +0 -1345
- package/vendor/session-manager.js.map +0 -1
- package/vendor/skill-resolver.js +0 -107
- package/vendor/types.d.ts +0 -466
- package/vendor/types.js +0 -8
- package/vendor/types.js.map +0 -1
- package/vendor/validation.d.ts +0 -31
- package/vendor/validation.js +0 -104
- package/vendor/validation.js.map +0 -1
|
@@ -1,197 +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
|
-
export interface OpenAIChatMessage {
|
|
10
|
-
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
11
|
-
content: string | Array<{
|
|
12
|
-
type?: string;
|
|
13
|
-
text?: string;
|
|
14
|
-
}> | null;
|
|
15
|
-
tool_calls?: Array<{
|
|
16
|
-
id: string;
|
|
17
|
-
type: 'function';
|
|
18
|
-
function: {
|
|
19
|
-
name: string;
|
|
20
|
-
arguments: string;
|
|
21
|
-
};
|
|
22
|
-
}>;
|
|
23
|
-
tool_call_id?: string;
|
|
24
|
-
}
|
|
25
|
-
export interface OpenAIChatCompletionRequest {
|
|
26
|
-
model?: string;
|
|
27
|
-
messages: OpenAIChatMessage[];
|
|
28
|
-
stream?: boolean;
|
|
29
|
-
temperature?: number;
|
|
30
|
-
max_tokens?: number;
|
|
31
|
-
max_completion_tokens?: number;
|
|
32
|
-
user?: string;
|
|
33
|
-
tools?: Array<{
|
|
34
|
-
type: 'function';
|
|
35
|
-
function: {
|
|
36
|
-
name: string;
|
|
37
|
-
description: string;
|
|
38
|
-
parameters: unknown;
|
|
39
|
-
};
|
|
40
|
-
}>;
|
|
41
|
-
}
|
|
42
|
-
export interface OpenAIToolCall {
|
|
43
|
-
id: string;
|
|
44
|
-
type: 'function';
|
|
45
|
-
function: {
|
|
46
|
-
name: string;
|
|
47
|
-
arguments: string;
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
export interface OpenAIChatCompletionResponse {
|
|
51
|
-
id: string;
|
|
52
|
-
object: 'chat.completion';
|
|
53
|
-
created: number;
|
|
54
|
-
model: string;
|
|
55
|
-
choices: Array<{
|
|
56
|
-
index: number;
|
|
57
|
-
message: {
|
|
58
|
-
role: 'assistant';
|
|
59
|
-
content: string | null;
|
|
60
|
-
tool_calls?: OpenAIToolCall[];
|
|
61
|
-
};
|
|
62
|
-
finish_reason: 'stop' | 'length' | 'tool_calls';
|
|
63
|
-
}>;
|
|
64
|
-
usage: {
|
|
65
|
-
prompt_tokens: number;
|
|
66
|
-
completion_tokens: number;
|
|
67
|
-
total_tokens: number;
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
export interface OpenAIChatCompletionChunk {
|
|
71
|
-
id: string;
|
|
72
|
-
object: 'chat.completion.chunk';
|
|
73
|
-
created: number;
|
|
74
|
-
model: string;
|
|
75
|
-
choices: Array<{
|
|
76
|
-
index: number;
|
|
77
|
-
delta: {
|
|
78
|
-
role?: string;
|
|
79
|
-
content?: string | null;
|
|
80
|
-
tool_calls?: Array<{
|
|
81
|
-
index: number;
|
|
82
|
-
id?: string;
|
|
83
|
-
type?: 'function';
|
|
84
|
-
function?: {
|
|
85
|
-
name?: string;
|
|
86
|
-
arguments?: string;
|
|
87
|
-
};
|
|
88
|
-
}>;
|
|
89
|
-
};
|
|
90
|
-
finish_reason: string | null;
|
|
91
|
-
}>;
|
|
92
|
-
usage?: {
|
|
93
|
-
prompt_tokens: number;
|
|
94
|
-
completion_tokens: number;
|
|
95
|
-
total_tokens: number;
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Derive a session key from the request.
|
|
100
|
-
* Priority: X-Session-Id header > user field > sha1(model + systemPrompt) > "default"
|
|
101
|
-
*
|
|
102
|
-
* The system-prompt-hash fallback prevents the bug where every caller without
|
|
103
|
-
* X-Session-Id or `user` collapses onto a single shared "openai-default"
|
|
104
|
-
* plugin session. In multi-caller setups (OpenClaw routing the main agent,
|
|
105
|
-
* cron jobs, and subagents through the same gateway) that previously meant
|
|
106
|
-
* every request serialized against every other and frequently picked up the
|
|
107
|
-
* wrong session's appendSystemPrompt — also a privacy leak across callers.
|
|
108
|
-
*
|
|
109
|
-
* The model is mixed into the hash so that two callers with the same system
|
|
110
|
-
* prompt but different requested models don't collide and silently get
|
|
111
|
-
* responses from the wrong model. Originally diagnosed in PR #40 by
|
|
112
|
-
* @megayounus786.
|
|
113
|
-
*/
|
|
114
|
-
export declare function resolveSessionKey(body: OpenAIChatCompletionRequest, headers: http.IncomingHttpHeaders): string;
|
|
115
|
-
/** Build the full session name from a key */
|
|
116
|
-
export declare function sessionNameFromKey(key: string): string;
|
|
117
|
-
/**
|
|
118
|
-
* Convert OpenAI tool definitions into a structured prompt block.
|
|
119
|
-
* Injected into the user message so the CLI model sees tool definitions
|
|
120
|
-
* and responds with <tool_calls> tags when it wants to invoke a function.
|
|
121
|
-
*/
|
|
122
|
-
export declare function buildToolPromptBlock(tools: OpenAIChatCompletionRequest['tools']): string;
|
|
123
|
-
export interface ParsedToolCalls {
|
|
124
|
-
textContent: string | null;
|
|
125
|
-
toolCalls: OpenAIToolCall[];
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Parse tool_calls from CLI text output.
|
|
129
|
-
*
|
|
130
|
-
* Looks for <tool_calls>[...]</tool_calls> tags in the response text.
|
|
131
|
-
* Returns both the extracted text content (before/after tags) and any tool calls found.
|
|
132
|
-
*/
|
|
133
|
-
export declare function parseToolCallsFromText(text: string): ParsedToolCalls;
|
|
134
|
-
/**
|
|
135
|
-
* Serialize tool result messages into a text block for the CLI model.
|
|
136
|
-
* Converts OpenAI `tool` role messages into <tool_result> tags.
|
|
137
|
-
*/
|
|
138
|
-
export declare function serializeToolResults(messages: OpenAIChatMessage[]): string;
|
|
139
|
-
export interface ExtractedMessage {
|
|
140
|
-
systemPrompt: string | undefined;
|
|
141
|
-
userMessage: string;
|
|
142
|
-
isNewConversation: boolean;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Extract the relevant parts from an OpenAI messages array.
|
|
146
|
-
*
|
|
147
|
-
* Sessions are stateful — we only need the last user message. The tricky
|
|
148
|
-
* question is whether to start a fresh session or append to the existing one.
|
|
149
|
-
*
|
|
150
|
-
* Default mode (no env var): only honor an explicit `X-Session-Reset: 1`
|
|
151
|
-
* header. This is correct for clients that maintain their own conversation
|
|
152
|
-
* transcript and forward only the latest user turn (OpenClaw main agent
|
|
153
|
-
* loop, cron jobs, subagents). The previous heuristic
|
|
154
|
-
* (`nonSystemMessages.length <= 1`) fired on every such request, killing the
|
|
155
|
-
* persistent CLI every turn and preventing Anthropic prompt caching from
|
|
156
|
-
* ever warming. Originally diagnosed in PR #40 by @megayounus786.
|
|
157
|
-
*
|
|
158
|
-
* Legacy mode (`OPENAI_COMPAT_NEW_CONVO_HEURISTIC=1`): restore the old
|
|
159
|
-
* `system + single user ⇒ new conversation` rule, for clients that re-send
|
|
160
|
-
* the full transcript on every turn (ChatGPT-Next-Web, Open WebUI, data
|
|
161
|
-
* labeling tools, etc). They use the transcript shape itself as their only
|
|
162
|
-
* "start a new conversation" signal.
|
|
163
|
-
*
|
|
164
|
-
* The env var is read on every call so ops can flip it via launchctl setenv
|
|
165
|
-
* without restarting the server.
|
|
166
|
-
*/
|
|
167
|
-
export declare function extractUserMessage(messages: OpenAIChatMessage[], headers?: Record<string, string | string[] | undefined>): ExtractedMessage;
|
|
168
|
-
export declare function formatCompletionResponse(id: string, model: string, text: string, tokensIn: number, tokensOut: number, toolCalls?: OpenAIToolCall[]): OpenAIChatCompletionResponse;
|
|
169
|
-
export declare function formatCompletionChunk(id: string, model: string, delta: {
|
|
170
|
-
role?: string;
|
|
171
|
-
content?: string;
|
|
172
|
-
}, finishReason: string | null): OpenAIChatCompletionChunk;
|
|
173
|
-
/** SessionManager-like interface to avoid circular imports */
|
|
174
|
-
interface SessionManagerLike {
|
|
175
|
-
startSession(config: Record<string, unknown>): Promise<{
|
|
176
|
-
name: string;
|
|
177
|
-
}>;
|
|
178
|
-
sendMessage(name: string, message: string, options?: Record<string, unknown>): Promise<{
|
|
179
|
-
output: string;
|
|
180
|
-
sessionId?: string;
|
|
181
|
-
events: unknown[];
|
|
182
|
-
}>;
|
|
183
|
-
stopSession(name: string): Promise<void>;
|
|
184
|
-
listSessions(): Array<{
|
|
185
|
-
name: string;
|
|
186
|
-
}>;
|
|
187
|
-
getStatus(name: string): {
|
|
188
|
-
stats: {
|
|
189
|
-
tokensIn: number;
|
|
190
|
-
tokensOut: number;
|
|
191
|
-
contextPercent: number;
|
|
192
|
-
};
|
|
193
|
-
};
|
|
194
|
-
compactSession(name: string): Promise<unknown>;
|
|
195
|
-
}
|
|
196
|
-
export declare function handleChatCompletion(manager: SessionManagerLike, body: Record<string, unknown>, headers: http.IncomingHttpHeaders, res: http.ServerResponse): Promise<void>;
|
|
197
|
-
export {};
|