@usabledev/usable-chat 1.168.2 → 1.168.4
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/cli.js +66 -9
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -160107,23 +160107,28 @@ var init_bridge = __esm({
|
|
|
160107
160107
|
// src/integrations/mcp/schema-adapter.ts
|
|
160108
160108
|
function isOpenAICompatModel(modelId) {
|
|
160109
160109
|
const isClaude = modelId.startsWith("anthropic/") || modelId.includes("claude");
|
|
160110
|
-
const isGemini = modelId
|
|
160110
|
+
const isGemini = isGeminiModel(modelId);
|
|
160111
160111
|
return !isClaude && !isGemini;
|
|
160112
160112
|
}
|
|
160113
|
+
function isGeminiModel(modelId) {
|
|
160114
|
+
return modelId.startsWith("google/gemini");
|
|
160115
|
+
}
|
|
160113
160116
|
function adaptToolSchemasForProvider(tools, modelId) {
|
|
160114
|
-
if (!tools
|
|
160117
|
+
if (!tools) return tools;
|
|
160118
|
+
const adapter = isGeminiModel(modelId) ? "gemini" : isOpenAICompatModel(modelId) ? "openai" : null;
|
|
160119
|
+
if (!adapter) return tools;
|
|
160115
160120
|
const toolCount = Array.isArray(tools) ? tools.length : Object.keys(tools).length;
|
|
160116
160121
|
logger.debug("schema-adapter", `adapting ${toolCount} tools for model ${modelId}`);
|
|
160117
160122
|
if (Array.isArray(tools)) {
|
|
160118
|
-
return tools.map((tool2) => adaptTool(tool2));
|
|
160123
|
+
return tools.map((tool2) => adaptTool(tool2, adapter));
|
|
160119
160124
|
}
|
|
160120
160125
|
const adapted = {};
|
|
160121
160126
|
for (const [key, tool2] of Object.entries(tools)) {
|
|
160122
|
-
adapted[key] = adaptTool(tool2);
|
|
160127
|
+
adapted[key] = adaptTool(tool2, adapter);
|
|
160123
160128
|
}
|
|
160124
160129
|
return adapted;
|
|
160125
160130
|
}
|
|
160126
|
-
function adaptTool(tool2) {
|
|
160131
|
+
function adaptTool(tool2, adapter) {
|
|
160127
160132
|
const t14 = tool2;
|
|
160128
160133
|
if (t14.type === "function" && t14.function && typeof t14.function === "object") {
|
|
160129
160134
|
const fn4 = t14.function;
|
|
@@ -160132,7 +160137,7 @@ function adaptTool(tool2) {
|
|
|
160132
160137
|
...t14,
|
|
160133
160138
|
function: {
|
|
160134
160139
|
...fn4,
|
|
160135
|
-
parameters:
|
|
160140
|
+
parameters: adaptSchema({ ...fn4.parameters }, adapter)
|
|
160136
160141
|
}
|
|
160137
160142
|
};
|
|
160138
160143
|
}
|
|
@@ -160141,11 +160146,49 @@ function adaptTool(tool2) {
|
|
|
160141
160146
|
if (t14.parameters && typeof t14.parameters === "object") {
|
|
160142
160147
|
return {
|
|
160143
160148
|
...t14,
|
|
160144
|
-
parameters:
|
|
160149
|
+
parameters: adaptSchema({ ...t14.parameters }, adapter)
|
|
160145
160150
|
};
|
|
160146
160151
|
}
|
|
160147
160152
|
return tool2;
|
|
160148
160153
|
}
|
|
160154
|
+
function adaptSchema(schema, adapter) {
|
|
160155
|
+
if (adapter === "gemini") return adaptSchemaForGemini(schema);
|
|
160156
|
+
return adaptSchemaForOpenAI(schema);
|
|
160157
|
+
}
|
|
160158
|
+
function adaptSchemaForGemini(schema) {
|
|
160159
|
+
const cloned = JSON.parse(JSON.stringify(schema));
|
|
160160
|
+
normalizeSchemaForGemini(cloned);
|
|
160161
|
+
return cloned;
|
|
160162
|
+
}
|
|
160163
|
+
function normalizeSchemaForGemini(schema) {
|
|
160164
|
+
const properties = isJsonSchemaRecord(schema.properties) ? schema.properties : void 0;
|
|
160165
|
+
if (Array.isArray(schema.enum)) {
|
|
160166
|
+
schema.enum = schema.enum.map((enumValue) => String(enumValue));
|
|
160167
|
+
}
|
|
160168
|
+
if (Array.isArray(schema.required)) {
|
|
160169
|
+
schema.required = properties ? schema.required.filter(
|
|
160170
|
+
(name18) => typeof name18 === "string" && Object.prototype.hasOwnProperty.call(properties, name18)
|
|
160171
|
+
) : [];
|
|
160172
|
+
}
|
|
160173
|
+
if (properties) {
|
|
160174
|
+
for (const propSchema of Object.values(properties)) {
|
|
160175
|
+
if (isJsonSchemaRecord(propSchema)) normalizeSchemaForGemini(propSchema);
|
|
160176
|
+
}
|
|
160177
|
+
}
|
|
160178
|
+
if (isJsonSchemaRecord(schema.items)) {
|
|
160179
|
+
normalizeSchemaForGemini(schema.items);
|
|
160180
|
+
}
|
|
160181
|
+
for (const key of ["anyOf", "oneOf", "allOf"]) {
|
|
160182
|
+
const schemas = schema[key];
|
|
160183
|
+
if (!Array.isArray(schemas)) continue;
|
|
160184
|
+
for (const childSchema of schemas) {
|
|
160185
|
+
if (isJsonSchemaRecord(childSchema)) normalizeSchemaForGemini(childSchema);
|
|
160186
|
+
}
|
|
160187
|
+
}
|
|
160188
|
+
}
|
|
160189
|
+
function isJsonSchemaRecord(value) {
|
|
160190
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
160191
|
+
}
|
|
160149
160192
|
function adaptSchemaForOpenAI(schema) {
|
|
160150
160193
|
const properties = schema.properties;
|
|
160151
160194
|
if (!properties || Object.keys(properties).length === 0) return schema;
|
|
@@ -199361,7 +199404,11 @@ function sanitizeSchemaForGemini(schema) {
|
|
|
199361
199404
|
const sanitized = {};
|
|
199362
199405
|
for (const [key, value] of Object.entries(inputSchema)) {
|
|
199363
199406
|
if (key === "const") {
|
|
199364
|
-
sanitized.enum = [value];
|
|
199407
|
+
sanitized.enum = [String(value)];
|
|
199408
|
+
continue;
|
|
199409
|
+
}
|
|
199410
|
+
if (key === "enum" && Array.isArray(value)) {
|
|
199411
|
+
sanitized.enum = value.map((enumValue) => String(enumValue));
|
|
199365
199412
|
continue;
|
|
199366
199413
|
}
|
|
199367
199414
|
if (key === "anyOf" || key === "oneOf") {
|
|
@@ -199427,8 +199474,18 @@ function sanitizeSchemaForGemini(schema) {
|
|
|
199427
199474
|
if (sanitized.type === "array" && !sanitized.items) {
|
|
199428
199475
|
sanitized.items = { type: "string" };
|
|
199429
199476
|
}
|
|
199477
|
+
pruneRequiredFieldsForGemini(sanitized);
|
|
199430
199478
|
return sanitized;
|
|
199431
199479
|
}
|
|
199480
|
+
function pruneRequiredFieldsForGemini(schema) {
|
|
199481
|
+
if (!Array.isArray(schema.required)) return;
|
|
199482
|
+
if (!schema.properties) {
|
|
199483
|
+
schema.required = [];
|
|
199484
|
+
return;
|
|
199485
|
+
}
|
|
199486
|
+
const propertyNames = new Set(Object.keys(schema.properties));
|
|
199487
|
+
schema.required = schema.required.filter((name18) => propertyNames.has(name18));
|
|
199488
|
+
}
|
|
199432
199489
|
function convertToolsToFunctionDeclarations(aiTools) {
|
|
199433
199490
|
const declarations = [];
|
|
199434
199491
|
for (const [name18, tool2] of Object.entries(aiTools)) {
|
|
@@ -309040,7 +309097,7 @@ init_tui_select();
|
|
|
309040
309097
|
init_model_registry();
|
|
309041
309098
|
|
|
309042
309099
|
// package.json
|
|
309043
|
-
var version2 = "1.168.
|
|
309100
|
+
var version2 = "1.168.4";
|
|
309044
309101
|
|
|
309045
309102
|
// src/adapters/cli/model-catalog.ts
|
|
309046
309103
|
init_codex_auth();
|