claudish 4.4.2 → 4.4.3
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/index.js +80 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -36225,19 +36225,98 @@ var init_native_handler = __esm(() => {
|
|
|
36225
36225
|
init_logger();
|
|
36226
36226
|
});
|
|
36227
36227
|
|
|
36228
|
+
// src/adapters/tool-name-utils.ts
|
|
36229
|
+
function hashToolName(name) {
|
|
36230
|
+
let h1 = 3735928559;
|
|
36231
|
+
let h2 = 1103547991;
|
|
36232
|
+
for (let i = 0;i < name.length; i++) {
|
|
36233
|
+
const ch = name.charCodeAt(i);
|
|
36234
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
36235
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
36236
|
+
}
|
|
36237
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507);
|
|
36238
|
+
h1 ^= Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
36239
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507);
|
|
36240
|
+
h2 ^= Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
36241
|
+
const combined = 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
36242
|
+
return combined.toString(16).padStart(8, "0").slice(0, 8);
|
|
36243
|
+
}
|
|
36244
|
+
function truncateToolName(name, maxLength) {
|
|
36245
|
+
if (name.length <= maxLength)
|
|
36246
|
+
return name;
|
|
36247
|
+
const prefixLen = maxLength - 9;
|
|
36248
|
+
const prefix = name.slice(0, prefixLen);
|
|
36249
|
+
const hash2 = hashToolName(name);
|
|
36250
|
+
const truncated = `${prefix}_${hash2}`;
|
|
36251
|
+
log(`[ToolName] Truncated: "${name}" -> "${truncated}" (${name.length} -> ${truncated.length} chars)`);
|
|
36252
|
+
return truncated;
|
|
36253
|
+
}
|
|
36254
|
+
var init_tool_name_utils = __esm(() => {
|
|
36255
|
+
init_logger();
|
|
36256
|
+
});
|
|
36257
|
+
|
|
36228
36258
|
// src/adapters/base-adapter.ts
|
|
36229
36259
|
class BaseModelAdapter {
|
|
36230
36260
|
modelId;
|
|
36261
|
+
toolNameMap = new Map;
|
|
36231
36262
|
constructor(modelId) {
|
|
36232
36263
|
this.modelId = modelId;
|
|
36233
36264
|
}
|
|
36265
|
+
getToolNameLimit() {
|
|
36266
|
+
return null;
|
|
36267
|
+
}
|
|
36268
|
+
getToolNameMap() {
|
|
36269
|
+
return this.toolNameMap;
|
|
36270
|
+
}
|
|
36271
|
+
restoreToolName(name) {
|
|
36272
|
+
return this.toolNameMap.get(name) || name;
|
|
36273
|
+
}
|
|
36234
36274
|
prepareRequest(request, originalRequest) {
|
|
36235
36275
|
return request;
|
|
36236
36276
|
}
|
|
36237
|
-
reset() {
|
|
36277
|
+
reset() {
|
|
36278
|
+
this.toolNameMap.clear();
|
|
36279
|
+
}
|
|
36280
|
+
truncateToolNames(request) {
|
|
36281
|
+
const limit = this.getToolNameLimit();
|
|
36282
|
+
if (!limit || !request.tools)
|
|
36283
|
+
return;
|
|
36284
|
+
for (const tool of request.tools) {
|
|
36285
|
+
const originalName = tool.function?.name || tool.name;
|
|
36286
|
+
if (originalName && originalName.length > limit) {
|
|
36287
|
+
const truncated = truncateToolName(originalName, limit);
|
|
36288
|
+
this.toolNameMap.set(truncated, originalName);
|
|
36289
|
+
if (tool.function?.name) {
|
|
36290
|
+
tool.function.name = truncated;
|
|
36291
|
+
} else if (tool.name) {
|
|
36292
|
+
tool.name = truncated;
|
|
36293
|
+
}
|
|
36294
|
+
}
|
|
36295
|
+
}
|
|
36296
|
+
}
|
|
36297
|
+
truncateToolNamesInMessages(messages) {
|
|
36298
|
+
const limit = this.getToolNameLimit();
|
|
36299
|
+
if (!limit)
|
|
36300
|
+
return;
|
|
36301
|
+
for (const msg of messages) {
|
|
36302
|
+
if (msg.role === "assistant" && Array.isArray(msg.tool_calls)) {
|
|
36303
|
+
for (const tc of msg.tool_calls) {
|
|
36304
|
+
const name = tc.function?.name;
|
|
36305
|
+
if (name && name.length > limit) {
|
|
36306
|
+
const truncated = truncateToolName(name, limit);
|
|
36307
|
+
tc.function.name = truncated;
|
|
36308
|
+
if (!this.toolNameMap.has(truncated)) {
|
|
36309
|
+
this.toolNameMap.set(truncated, name);
|
|
36310
|
+
}
|
|
36311
|
+
}
|
|
36312
|
+
}
|
|
36313
|
+
}
|
|
36314
|
+
}
|
|
36315
|
+
}
|
|
36238
36316
|
}
|
|
36239
36317
|
var DefaultAdapter;
|
|
36240
36318
|
var init_base_adapter = __esm(() => {
|
|
36319
|
+
init_tool_name_utils();
|
|
36241
36320
|
DefaultAdapter = class DefaultAdapter extends BaseModelAdapter {
|
|
36242
36321
|
processTextContent(textContent, accumulatedText) {
|
|
36243
36322
|
return {
|