clawmoney 0.15.4 → 0.15.5
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/relay/provider.js +26 -2
- package/dist/relay/types.d.ts +6 -1
- package/package.json +1 -1
package/dist/relay/provider.js
CHANGED
|
@@ -134,8 +134,32 @@ function applyProxyFromConfig(config) {
|
|
|
134
134
|
logger.info(`[provider] using config.yaml proxy=${config.proxy}`);
|
|
135
135
|
}
|
|
136
136
|
// ── Request handler ──
|
|
137
|
+
// Flatten a Claude/OpenAI message `content` field into a plain string.
|
|
138
|
+
// Content may be either a string (OpenAI-style) or an array of content
|
|
139
|
+
// blocks (Claude Code / real Anthropic API shape: [{type:"text",text:"..."}]).
|
|
140
|
+
// String(array) would produce "[object Object],[object Object]" which the
|
|
141
|
+
// model then echoes back as garbage — hence the explicit block walk.
|
|
142
|
+
function extractMessageText(content) {
|
|
143
|
+
if (content == null)
|
|
144
|
+
return "";
|
|
145
|
+
if (typeof content === "string")
|
|
146
|
+
return content;
|
|
147
|
+
if (Array.isArray(content)) {
|
|
148
|
+
const parts = [];
|
|
149
|
+
for (const block of content) {
|
|
150
|
+
if (block && typeof block === "object") {
|
|
151
|
+
const b = block;
|
|
152
|
+
if (b.type === "text" && typeof b.text === "string" && b.text) {
|
|
153
|
+
parts.push(b.text);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return parts.join("\n");
|
|
158
|
+
}
|
|
159
|
+
return "";
|
|
160
|
+
}
|
|
137
161
|
function messagesToPrompt(messages) {
|
|
138
|
-
return messages.map((m) =>
|
|
162
|
+
return messages.map((m) => extractMessageText(m.content)).join("\n");
|
|
139
163
|
}
|
|
140
164
|
async function executeRelayRequest(request, config) {
|
|
141
165
|
const { request_id, max_budget_usd } = request;
|
|
@@ -148,7 +172,7 @@ async function executeRelayRequest(request, config) {
|
|
|
148
172
|
? messagesToPrompt(request.messages)
|
|
149
173
|
: request.prompt ?? "";
|
|
150
174
|
const lastUserMsg = request.messages
|
|
151
|
-
? [...request.messages].reverse().find((m) => m.role === "user")?.content
|
|
175
|
+
? extractMessageText([...request.messages].reverse().find((m) => m.role === "user")?.content)
|
|
152
176
|
: prompt;
|
|
153
177
|
const turns = request.messages
|
|
154
178
|
? request.messages.filter((m) => m.role === "user").length
|
package/dist/relay/types.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
export interface RelayContentBlock {
|
|
2
|
+
type: string;
|
|
3
|
+
text?: string;
|
|
4
|
+
}
|
|
5
|
+
export type RelayMessageContent = string | RelayContentBlock[] | null;
|
|
1
6
|
export interface RelayRequest {
|
|
2
7
|
event: "relay_request";
|
|
3
8
|
request_id: string;
|
|
4
9
|
prompt?: string;
|
|
5
10
|
messages?: Array<{
|
|
6
11
|
role: string;
|
|
7
|
-
content:
|
|
12
|
+
content: RelayMessageContent;
|
|
8
13
|
}>;
|
|
9
14
|
cli_type?: string;
|
|
10
15
|
session_id?: string;
|