qlogicagent 0.2.1 → 0.4.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/README.md +45 -45
- package/package.json +56 -42
- package/dist/agent/agent.d.ts +0 -43
- package/dist/agent/agent.js +0 -113
- package/dist/agent/tool-loop.d.ts +0 -64
- package/dist/agent/tool-loop.js +0 -575
- package/dist/agent/types.d.ts +0 -175
- package/dist/agent/types.js +0 -14
- package/dist/cli/main.d.ts +0 -11
- package/dist/cli/main.js +0 -23
- package/dist/cli/stdio-server.d.ts +0 -45
- package/dist/cli/stdio-server.js +0 -463
- package/dist/config/config.d.ts +0 -17
- package/dist/config/config.js +0 -21
- package/dist/contracts/hooks.d.ts +0 -120
- package/dist/contracts/hooks.js +0 -7
- package/dist/contracts/index.d.ts +0 -10
- package/dist/contracts/index.js +0 -10
- package/dist/contracts/planner.d.ts +0 -35
- package/dist/contracts/planner.js +0 -2
- package/dist/contracts/skill-candidate.d.ts +0 -63
- package/dist/contracts/skill-candidate.js +0 -195
- package/dist/contracts/todo.d.ts +0 -14
- package/dist/contracts/todo.js +0 -9
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -15
- package/dist/llm/builtin-providers.d.ts +0 -10
- package/dist/llm/builtin-providers.js +0 -531
- package/dist/llm/index.d.ts +0 -15
- package/dist/llm/index.js +0 -14
- package/dist/llm/llm-client.d.ts +0 -43
- package/dist/llm/llm-client.js +0 -67
- package/dist/llm/model-catalog.d.ts +0 -53
- package/dist/llm/model-catalog.js +0 -191
- package/dist/llm/provider-def.d.ts +0 -59
- package/dist/llm/provider-def.js +0 -12
- package/dist/llm/provider-registry.d.ts +0 -54
- package/dist/llm/provider-registry.js +0 -147
- package/dist/llm/transport.d.ts +0 -62
- package/dist/llm/transport.js +0 -27
- package/dist/llm/transports/anthropic-messages.d.ts +0 -31
- package/dist/llm/transports/anthropic-messages.js +0 -293
- package/dist/llm/transports/openai-chat.d.ts +0 -36
- package/dist/llm/transports/openai-chat.js +0 -165
- package/dist/orchestration/agent-registry.d.ts +0 -41
- package/dist/orchestration/agent-registry.js +0 -116
- package/dist/orchestration/approval-aware-tool-plan.d.ts +0 -32
- package/dist/orchestration/approval-aware-tool-plan.js +0 -87
- package/dist/orchestration/context-compression.d.ts +0 -220
- package/dist/orchestration/context-compression.js +0 -583
- package/dist/orchestration/conversation-repair.d.ts +0 -61
- package/dist/orchestration/conversation-repair.js +0 -429
- package/dist/orchestration/curator-scheduler.d.ts +0 -119
- package/dist/orchestration/curator-scheduler.js +0 -135
- package/dist/orchestration/embedded-failover-policy.d.ts +0 -110
- package/dist/orchestration/embedded-failover-policy.js +0 -168
- package/dist/orchestration/error-classification.d.ts +0 -12
- package/dist/orchestration/error-classification.js +0 -77
- package/dist/orchestration/failover-classification.d.ts +0 -8
- package/dist/orchestration/failover-classification.js +0 -381
- package/dist/orchestration/failover-error.d.ts +0 -33
- package/dist/orchestration/failover-error.js +0 -198
- package/dist/orchestration/fork-subagent.d.ts +0 -100
- package/dist/orchestration/fork-subagent.js +0 -98
- package/dist/orchestration/index.d.ts +0 -120
- package/dist/orchestration/index.js +0 -267
- package/dist/orchestration/memory-flush-policy.d.ts +0 -57
- package/dist/orchestration/memory-flush-policy.js +0 -85
- package/dist/orchestration/memory-provider.d.ts +0 -14
- package/dist/orchestration/memory-provider.js +0 -2
- package/dist/orchestration/parallel-tool-calls.d.ts +0 -41
- package/dist/orchestration/parallel-tool-calls.js +0 -59
- package/dist/orchestration/prompt-cache-strategy.d.ts +0 -126
- package/dist/orchestration/prompt-cache-strategy.js +0 -228
- package/dist/orchestration/reactive-compact.d.ts +0 -73
- package/dist/orchestration/reactive-compact.js +0 -78
- package/dist/orchestration/retry-loop.d.ts +0 -22
- package/dist/orchestration/retry-loop.js +0 -24
- package/dist/orchestration/skill-candidate.d.ts +0 -52
- package/dist/orchestration/skill-candidate.js +0 -141
- package/dist/orchestration/skill-consolidation.d.ts +0 -123
- package/dist/orchestration/skill-consolidation.js +0 -220
- package/dist/orchestration/skill-improvement.d.ts +0 -59
- package/dist/orchestration/skill-improvement.js +0 -66
- package/dist/orchestration/skill-similarity.d.ts +0 -98
- package/dist/orchestration/skill-similarity.js +0 -131
- package/dist/orchestration/streaming-tool-executor.d.ts +0 -73
- package/dist/orchestration/streaming-tool-executor.js +0 -96
- package/dist/orchestration/team-orchestration.d.ts +0 -195
- package/dist/orchestration/team-orchestration.js +0 -369
- package/dist/orchestration/team-tool-loop-wiring.d.ts +0 -92
- package/dist/orchestration/team-tool-loop-wiring.js +0 -147
- package/dist/orchestration/tool-choice-policy.d.ts +0 -54
- package/dist/orchestration/tool-choice-policy.js +0 -164
- package/dist/orchestration/tool-loop-state.d.ts +0 -50
- package/dist/orchestration/tool-loop-state.js +0 -133
- package/dist/orchestration/tool-schema.d.ts +0 -39
- package/dist/orchestration/tool-schema.js +0 -297
- package/dist/orchestration/transcript-repair.d.ts +0 -42
- package/dist/orchestration/transcript-repair.js +0 -426
- package/dist/orchestration/turn-loop-guard.d.ts +0 -86
- package/dist/orchestration/turn-loop-guard.js +0 -92
- package/dist/orchestration/web-browser-policy.d.ts +0 -17
- package/dist/orchestration/web-browser-policy.js +0 -39
- package/dist/runtime/context-compression.d.ts +0 -61
- package/dist/runtime/context-compression.js +0 -274
- package/dist/runtime/hook-registry.d.ts +0 -12
- package/dist/runtime/hook-registry.js +0 -53
- package/dist/runtime/memory-hooks.d.ts +0 -23
- package/dist/runtime/memory-hooks.js +0 -65
- package/dist/runtime/tool-eligibility.d.ts +0 -59
- package/dist/runtime/tool-eligibility.js +0 -111
- package/dist/skills/index.d.ts +0 -108
- package/dist/skills/index.js +0 -82
- package/dist/skills/memory-extractor.d.ts +0 -64
- package/dist/skills/memory-extractor.js +0 -173
- package/dist/skills/memory-query-tool.d.ts +0 -43
- package/dist/skills/memory-query-tool.js +0 -127
- package/dist/skills/memory-store.d.ts +0 -66
- package/dist/skills/memory-store.js +0 -228
- package/dist/skills/memory-tool.d.ts +0 -67
- package/dist/skills/memory-tool.js +0 -192
- package/dist/skills/portable-tool.d.ts +0 -71
- package/dist/skills/portable-tool.js +0 -14
- package/dist/skills/qmemory-adapter.d.ts +0 -52
- package/dist/skills/qmemory-adapter.js +0 -165
- package/dist/skills/skill-frontmatter.d.ts +0 -19
- package/dist/skills/skill-frontmatter.js +0 -344
- package/dist/skills/skill-guard.d.ts +0 -23
- package/dist/skills/skill-guard.js +0 -229
- package/dist/skills/skill-loader.d.ts +0 -16
- package/dist/skills/skill-loader.js +0 -303
- package/dist/skills/skill-source.d.ts +0 -119
- package/dist/skills/skill-source.js +0 -126
- package/dist/skills/skill-types.d.ts +0 -199
- package/dist/skills/skill-types.js +0 -6
- package/dist/skills/think-tool.d.ts +0 -16
- package/dist/skills/think-tool.js +0 -59
- package/dist/skills/todo-tool.d.ts +0 -63
- package/dist/skills/todo-tool.js +0 -114
- package/dist/skills/tools/agent-tool.d.ts +0 -91
- package/dist/skills/tools/agent-tool.js +0 -142
- package/dist/skills/tools/apply-patch-tool.d.ts +0 -29
- package/dist/skills/tools/apply-patch-tool.js +0 -184
- package/dist/skills/tools/ask-user-tool.d.ts +0 -80
- package/dist/skills/tools/ask-user-tool.js +0 -121
- package/dist/skills/tools/brief-tool.d.ts +0 -74
- package/dist/skills/tools/brief-tool.js +0 -95
- package/dist/skills/tools/browser-tool.d.ts +0 -114
- package/dist/skills/tools/browser-tool.js +0 -155
- package/dist/skills/tools/checkpoint-tool.d.ts +0 -66
- package/dist/skills/tools/checkpoint-tool.js +0 -102
- package/dist/skills/tools/config-tool.d.ts +0 -63
- package/dist/skills/tools/config-tool.js +0 -143
- package/dist/skills/tools/cron-tool.d.ts +0 -116
- package/dist/skills/tools/cron-tool.js +0 -175
- package/dist/skills/tools/edit-tool.d.ts +0 -43
- package/dist/skills/tools/edit-tool.js +0 -70
- package/dist/skills/tools/exec-tool.d.ts +0 -102
- package/dist/skills/tools/exec-tool.js +0 -133
- package/dist/skills/tools/image-generate-tool.d.ts +0 -62
- package/dist/skills/tools/image-generate-tool.js +0 -67
- package/dist/skills/tools/instructions-tool.d.ts +0 -103
- package/dist/skills/tools/instructions-tool.js +0 -187
- package/dist/skills/tools/lsp-tool.d.ts +0 -153
- package/dist/skills/tools/lsp-tool.js +0 -227
- package/dist/skills/tools/mcp-client-types.d.ts +0 -269
- package/dist/skills/tools/mcp-client-types.js +0 -53
- package/dist/skills/tools/mcp-tool.d.ts +0 -249
- package/dist/skills/tools/mcp-tool.js +0 -503
- package/dist/skills/tools/memory-tool.d.ts +0 -74
- package/dist/skills/tools/memory-tool.js +0 -88
- package/dist/skills/tools/monitor-tool.d.ts +0 -113
- package/dist/skills/tools/monitor-tool.js +0 -131
- package/dist/skills/tools/music-generate-tool.d.ts +0 -55
- package/dist/skills/tools/music-generate-tool.js +0 -62
- package/dist/skills/tools/notify-tool.d.ts +0 -53
- package/dist/skills/tools/notify-tool.js +0 -62
- package/dist/skills/tools/patch-tool.d.ts +0 -45
- package/dist/skills/tools/patch-tool.js +0 -505
- package/dist/skills/tools/pdf-tool.d.ts +0 -66
- package/dist/skills/tools/pdf-tool.js +0 -88
- package/dist/skills/tools/plan-mode-tool.d.ts +0 -59
- package/dist/skills/tools/plan-mode-tool.js +0 -122
- package/dist/skills/tools/read-tool.d.ts +0 -51
- package/dist/skills/tools/read-tool.js +0 -84
- package/dist/skills/tools/repl-tool.d.ts +0 -70
- package/dist/skills/tools/repl-tool.js +0 -69
- package/dist/skills/tools/search-tool.d.ts +0 -112
- package/dist/skills/tools/search-tool.js +0 -225
- package/dist/skills/tools/send-message-tool.d.ts +0 -51
- package/dist/skills/tools/send-message-tool.js +0 -76
- package/dist/skills/tools/skill-list-tool.d.ts +0 -33
- package/dist/skills/tools/skill-list-tool.js +0 -54
- package/dist/skills/tools/skill-manage-tool.d.ts +0 -73
- package/dist/skills/tools/skill-manage-tool.js +0 -153
- package/dist/skills/tools/skill-view-tool.d.ts +0 -37
- package/dist/skills/tools/skill-view-tool.js +0 -72
- package/dist/skills/tools/sleep-tool.d.ts +0 -49
- package/dist/skills/tools/sleep-tool.js +0 -81
- package/dist/skills/tools/structured-output-tool.d.ts +0 -116
- package/dist/skills/tools/structured-output-tool.js +0 -176
- package/dist/skills/tools/task-tool.d.ts +0 -104
- package/dist/skills/tools/task-tool.js +0 -161
- package/dist/skills/tools/team-tool.d.ts +0 -89
- package/dist/skills/tools/team-tool.js +0 -105
- package/dist/skills/tools/tool-search-tool.d.ts +0 -51
- package/dist/skills/tools/tool-search-tool.js +0 -110
- package/dist/skills/tools/tts-tool.d.ts +0 -38
- package/dist/skills/tools/tts-tool.js +0 -45
- package/dist/skills/tools/video-edit-tool.d.ts +0 -69
- package/dist/skills/tools/video-edit-tool.js +0 -74
- package/dist/skills/tools/video-generate-tool.d.ts +0 -62
- package/dist/skills/tools/video-generate-tool.js +0 -66
- package/dist/skills/tools/video-merge-tool.d.ts +0 -105
- package/dist/skills/tools/video-merge-tool.js +0 -92
- package/dist/skills/tools/video-upscale-tool.d.ts +0 -45
- package/dist/skills/tools/video-upscale-tool.js +0 -52
- package/dist/skills/tools/web-fetch-tool.d.ts +0 -78
- package/dist/skills/tools/web-fetch-tool.js +0 -92
- package/dist/skills/tools/web-search-tool.d.ts +0 -57
- package/dist/skills/tools/web-search-tool.js +0 -86
- package/dist/skills/tools/worktree-tool.d.ts +0 -69
- package/dist/skills/tools/worktree-tool.js +0 -147
- package/dist/skills/tools/write-tool.d.ts +0 -45
- package/dist/skills/tools/write-tool.js +0 -81
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
function extractEnumValues(schema) {
|
|
2
|
-
if (!schema || typeof schema !== "object") {
|
|
3
|
-
return undefined;
|
|
4
|
-
}
|
|
5
|
-
const record = schema;
|
|
6
|
-
if (Array.isArray(record.enum)) {
|
|
7
|
-
return record.enum;
|
|
8
|
-
}
|
|
9
|
-
if ("const" in record) {
|
|
10
|
-
return [record.const];
|
|
11
|
-
}
|
|
12
|
-
const variants = Array.isArray(record.anyOf)
|
|
13
|
-
? record.anyOf
|
|
14
|
-
: Array.isArray(record.oneOf)
|
|
15
|
-
? record.oneOf
|
|
16
|
-
: null;
|
|
17
|
-
if (!variants) {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
const values = variants.flatMap((variant) => extractEnumValues(variant) ?? []);
|
|
21
|
-
return values.length > 0 ? values : undefined;
|
|
22
|
-
}
|
|
23
|
-
function mergePropertySchemas(existing, incoming) {
|
|
24
|
-
if (!existing)
|
|
25
|
-
return incoming;
|
|
26
|
-
if (!incoming)
|
|
27
|
-
return existing;
|
|
28
|
-
const existingEnum = extractEnumValues(existing);
|
|
29
|
-
const incomingEnum = extractEnumValues(incoming);
|
|
30
|
-
if (!existingEnum && !incomingEnum) {
|
|
31
|
-
return existing;
|
|
32
|
-
}
|
|
33
|
-
const values = Array.from(new Set([...(existingEnum ?? []), ...(incomingEnum ?? [])]));
|
|
34
|
-
const merged = {};
|
|
35
|
-
for (const source of [existing, incoming]) {
|
|
36
|
-
if (!source || typeof source !== "object") {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
const record = source;
|
|
40
|
-
for (const key of ["title", "description", "default"]) {
|
|
41
|
-
if (!(key in merged) && key in record) {
|
|
42
|
-
merged[key] = record[key];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const types = new Set(values.map((value) => typeof value));
|
|
47
|
-
if (types.size === 1) {
|
|
48
|
-
merged.type = Array.from(types)[0];
|
|
49
|
-
}
|
|
50
|
-
merged.enum = values;
|
|
51
|
-
return merged;
|
|
52
|
-
}
|
|
53
|
-
const GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS = new Set([
|
|
54
|
-
"patternProperties",
|
|
55
|
-
"additionalProperties",
|
|
56
|
-
"$schema",
|
|
57
|
-
"$id",
|
|
58
|
-
"$ref",
|
|
59
|
-
"$defs",
|
|
60
|
-
"definitions",
|
|
61
|
-
"examples",
|
|
62
|
-
"minLength",
|
|
63
|
-
"maxLength",
|
|
64
|
-
"minimum",
|
|
65
|
-
"maximum",
|
|
66
|
-
"multipleOf",
|
|
67
|
-
"pattern",
|
|
68
|
-
"format",
|
|
69
|
-
"minItems",
|
|
70
|
-
"maxItems",
|
|
71
|
-
"uniqueItems",
|
|
72
|
-
"minProperties",
|
|
73
|
-
"maxProperties",
|
|
74
|
-
]);
|
|
75
|
-
const XAI_UNSUPPORTED_SCHEMA_KEYWORDS = new Set([
|
|
76
|
-
"minLength",
|
|
77
|
-
"maxLength",
|
|
78
|
-
"minItems",
|
|
79
|
-
"maxItems",
|
|
80
|
-
"minContains",
|
|
81
|
-
"maxContains",
|
|
82
|
-
]);
|
|
83
|
-
function cleanSchemaForGemini(schema) {
|
|
84
|
-
if (!schema || typeof schema !== "object") {
|
|
85
|
-
return schema;
|
|
86
|
-
}
|
|
87
|
-
if (Array.isArray(schema)) {
|
|
88
|
-
return schema.map((item) => cleanSchemaForGemini(item));
|
|
89
|
-
}
|
|
90
|
-
const record = schema;
|
|
91
|
-
const cleaned = {};
|
|
92
|
-
for (const [key, value] of Object.entries(record)) {
|
|
93
|
-
if (GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS.has(key)) {
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
if (key === "properties" && value && typeof value === "object" && !Array.isArray(value)) {
|
|
97
|
-
cleaned[key] = Object.fromEntries(Object.entries(value).map(([nestedKey, nestedValue]) => [nestedKey, cleanSchemaForGemini(nestedValue)]));
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
if ((key === "items" || key === "additionalProperties") && value && typeof value === "object") {
|
|
101
|
-
cleaned[key] = Array.isArray(value) ? value.map((item) => cleanSchemaForGemini(item)) : cleanSchemaForGemini(value);
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
if ((key === "anyOf" || key === "oneOf" || key === "allOf") && Array.isArray(value)) {
|
|
105
|
-
cleaned[key] = value.map((item) => cleanSchemaForGemini(item));
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
cleaned[key] = value;
|
|
109
|
-
}
|
|
110
|
-
return cleaned;
|
|
111
|
-
}
|
|
112
|
-
function stripXaiUnsupportedKeywords(schema) {
|
|
113
|
-
if (!schema || typeof schema !== "object") {
|
|
114
|
-
return schema;
|
|
115
|
-
}
|
|
116
|
-
if (Array.isArray(schema)) {
|
|
117
|
-
return schema.map((item) => stripXaiUnsupportedKeywords(item));
|
|
118
|
-
}
|
|
119
|
-
const record = schema;
|
|
120
|
-
const cleaned = {};
|
|
121
|
-
for (const [key, value] of Object.entries(record)) {
|
|
122
|
-
if (XAI_UNSUPPORTED_SCHEMA_KEYWORDS.has(key)) {
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
if (key === "properties" && value && typeof value === "object" && !Array.isArray(value)) {
|
|
126
|
-
cleaned[key] = Object.fromEntries(Object.entries(value).map(([nestedKey, nestedValue]) => [nestedKey, stripXaiUnsupportedKeywords(nestedValue)]));
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
if ((key === "items") && value && typeof value === "object") {
|
|
130
|
-
cleaned[key] = Array.isArray(value) ? value.map((item) => stripXaiUnsupportedKeywords(item)) : stripXaiUnsupportedKeywords(value);
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
if ((key === "anyOf" || key === "oneOf" || key === "allOf") && Array.isArray(value)) {
|
|
134
|
-
cleaned[key] = value.map((item) => stripXaiUnsupportedKeywords(item));
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
cleaned[key] = value;
|
|
138
|
-
}
|
|
139
|
-
return cleaned;
|
|
140
|
-
}
|
|
141
|
-
export function isXaiProvider(modelProvider, modelId) {
|
|
142
|
-
const provider = modelProvider?.toLowerCase() ?? "";
|
|
143
|
-
if (provider.includes("xai") || provider.includes("x-ai")) {
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
const lowerModelId = modelId?.toLowerCase() ?? "";
|
|
147
|
-
if (provider === "openrouter" && lowerModelId.startsWith("x-ai/")) {
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
if (provider === "venice" && lowerModelId.includes("grok")) {
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
export function normalizeFunctionToolParameters(parameters, options) {
|
|
156
|
-
const schema = parameters && typeof parameters === "object" ? parameters : { type: "object", properties: {}, additionalProperties: true };
|
|
157
|
-
const isGeminiProvider = options?.modelProvider?.toLowerCase().includes("google") || options?.modelProvider?.toLowerCase().includes("gemini");
|
|
158
|
-
const isAnthropicProvider = options?.modelProvider?.toLowerCase().includes("anthropic");
|
|
159
|
-
const isXai = isXaiProvider(options?.modelProvider, options?.modelId);
|
|
160
|
-
const applyProviderCleaning = (nextSchema) => {
|
|
161
|
-
if (isGeminiProvider && !isAnthropicProvider) {
|
|
162
|
-
return cleanSchemaForGemini(nextSchema);
|
|
163
|
-
}
|
|
164
|
-
if (isXai) {
|
|
165
|
-
return stripXaiUnsupportedKeywords(nextSchema);
|
|
166
|
-
}
|
|
167
|
-
return nextSchema;
|
|
168
|
-
};
|
|
169
|
-
if ("type" in schema && "properties" in schema && !Array.isArray(schema.anyOf)) {
|
|
170
|
-
return applyProviderCleaning(schema);
|
|
171
|
-
}
|
|
172
|
-
if (!("type" in schema)
|
|
173
|
-
&& (typeof schema.properties === "object" || Array.isArray(schema.required))
|
|
174
|
-
&& !Array.isArray(schema.anyOf)
|
|
175
|
-
&& !Array.isArray(schema.oneOf)) {
|
|
176
|
-
return applyProviderCleaning({ ...schema, type: "object" });
|
|
177
|
-
}
|
|
178
|
-
const variantKey = Array.isArray(schema.anyOf)
|
|
179
|
-
? "anyOf"
|
|
180
|
-
: Array.isArray(schema.oneOf)
|
|
181
|
-
? "oneOf"
|
|
182
|
-
: null;
|
|
183
|
-
if (!variantKey) {
|
|
184
|
-
return applyProviderCleaning(schema);
|
|
185
|
-
}
|
|
186
|
-
const variants = schema[variantKey];
|
|
187
|
-
const mergedProperties = {};
|
|
188
|
-
const requiredCounts = new Map();
|
|
189
|
-
let objectVariants = 0;
|
|
190
|
-
for (const entry of variants) {
|
|
191
|
-
if (!entry || typeof entry !== "object") {
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
const props = entry.properties;
|
|
195
|
-
if (!props || typeof props !== "object") {
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
objectVariants += 1;
|
|
199
|
-
for (const [key, value] of Object.entries(props)) {
|
|
200
|
-
mergedProperties[key] = key in mergedProperties ? mergePropertySchemas(mergedProperties[key], value) : value;
|
|
201
|
-
}
|
|
202
|
-
const required = Array.isArray(entry.required)
|
|
203
|
-
? entry.required
|
|
204
|
-
: [];
|
|
205
|
-
for (const key of required) {
|
|
206
|
-
if (typeof key === "string") {
|
|
207
|
-
requiredCounts.set(key, (requiredCounts.get(key) ?? 0) + 1);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
const baseRequired = Array.isArray(schema.required) ? schema.required.filter((key) => typeof key === "string") : undefined;
|
|
212
|
-
const mergedRequired = baseRequired && baseRequired.length > 0
|
|
213
|
-
? baseRequired
|
|
214
|
-
: objectVariants > 0
|
|
215
|
-
? Array.from(requiredCounts.entries()).filter(([, count]) => count === objectVariants).map(([key]) => key)
|
|
216
|
-
: undefined;
|
|
217
|
-
return applyProviderCleaning({
|
|
218
|
-
type: "object",
|
|
219
|
-
...(typeof schema.title === "string" ? { title: schema.title } : {}),
|
|
220
|
-
...(typeof schema.description === "string" ? { description: schema.description } : {}),
|
|
221
|
-
properties: Object.keys(mergedProperties).length > 0 ? mergedProperties : (schema.properties ?? {}),
|
|
222
|
-
...(mergedRequired && mergedRequired.length > 0 ? { required: mergedRequired } : {}),
|
|
223
|
-
additionalProperties: "additionalProperties" in schema ? schema.additionalProperties : true,
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
export function convertFunctionTools(tools, options) {
|
|
227
|
-
return tools.map((tool) => ({
|
|
228
|
-
type: "function",
|
|
229
|
-
function: {
|
|
230
|
-
name: tool.name,
|
|
231
|
-
...(typeof tool.description === "string" ? { description: tool.description } : {}),
|
|
232
|
-
parameters: normalizeFunctionToolParameters(tool.parameters, options),
|
|
233
|
-
},
|
|
234
|
-
}));
|
|
235
|
-
}
|
|
236
|
-
export function convertCapabilityToolManifestsToFunctionTools(tools) {
|
|
237
|
-
return convertFunctionTools(tools.map((tool) => ({
|
|
238
|
-
name: tool.name,
|
|
239
|
-
description: tool.description,
|
|
240
|
-
parameters: {
|
|
241
|
-
type: "object",
|
|
242
|
-
properties: Object.fromEntries((tool.requiredParameters ?? []).map((name) => [name, { type: "string" }])),
|
|
243
|
-
additionalProperties: true,
|
|
244
|
-
...((tool.requiredParameters?.length ?? 0) > 0 ? { required: tool.requiredParameters } : {}),
|
|
245
|
-
},
|
|
246
|
-
})));
|
|
247
|
-
}
|
|
248
|
-
export function normalizeMessageTextContent(content) {
|
|
249
|
-
if (typeof content === "string") {
|
|
250
|
-
return content;
|
|
251
|
-
}
|
|
252
|
-
if (!Array.isArray(content)) {
|
|
253
|
-
return "";
|
|
254
|
-
}
|
|
255
|
-
return content.map((entry) => {
|
|
256
|
-
if (typeof entry === "string") {
|
|
257
|
-
return entry;
|
|
258
|
-
}
|
|
259
|
-
if (entry && typeof entry === "object" && "text" in entry && typeof entry.text === "string") {
|
|
260
|
-
return entry.text;
|
|
261
|
-
}
|
|
262
|
-
return "";
|
|
263
|
-
}).filter(Boolean).join("\n");
|
|
264
|
-
}
|
|
265
|
-
export function parseOpenAiToolCallsFromChatResponse(responseBody) {
|
|
266
|
-
try {
|
|
267
|
-
const parsed = JSON.parse(responseBody);
|
|
268
|
-
const firstChoice = parsed.choices?.[0]?.message;
|
|
269
|
-
const toolCalls = Array.isArray(firstChoice?.tool_calls)
|
|
270
|
-
? firstChoice.tool_calls.filter((entry) => entry?.type === "function" && typeof entry.function?.name === "string")
|
|
271
|
-
: [];
|
|
272
|
-
return {
|
|
273
|
-
toolCalls,
|
|
274
|
-
responseText: normalizeMessageTextContent(firstChoice?.content),
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
catch {
|
|
278
|
-
return { toolCalls: [], responseText: "" };
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
export function buildAssistantToolCallMessage(toolCalls) {
|
|
282
|
-
return {
|
|
283
|
-
role: "assistant",
|
|
284
|
-
content: "",
|
|
285
|
-
tool_calls: toolCalls,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
export function buildToolResultMessage(callId, result) {
|
|
289
|
-
return {
|
|
290
|
-
role: "tool",
|
|
291
|
-
tool_call_id: callId,
|
|
292
|
-
content: JSON.stringify(result.ok ? { ok: true, payload: result.payload } : { ok: false, error: result.error ?? "Tool invoke failed" }),
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
export function cleanToolSchemaForGemini(schema) {
|
|
296
|
-
return cleanSchemaForGemini(schema);
|
|
297
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export type TranscriptMessageLike = {
|
|
2
|
-
role?: unknown;
|
|
3
|
-
content?: unknown;
|
|
4
|
-
stopReason?: unknown;
|
|
5
|
-
toolCallId?: unknown;
|
|
6
|
-
toolUseId?: unknown;
|
|
7
|
-
toolName?: unknown;
|
|
8
|
-
details?: unknown;
|
|
9
|
-
isError?: unknown;
|
|
10
|
-
timestamp?: unknown;
|
|
11
|
-
};
|
|
12
|
-
export type TranscriptToolCallLike = {
|
|
13
|
-
id: string;
|
|
14
|
-
name?: string;
|
|
15
|
-
};
|
|
16
|
-
export type ToolCallInputRepairReport<TMessage extends TranscriptMessageLike> = {
|
|
17
|
-
messages: TMessage[];
|
|
18
|
-
droppedToolCalls: number;
|
|
19
|
-
droppedAssistantMessages: number;
|
|
20
|
-
};
|
|
21
|
-
export type ToolUseRepairReport<TMessage extends TranscriptMessageLike> = {
|
|
22
|
-
messages: TMessage[];
|
|
23
|
-
added: TMessage[];
|
|
24
|
-
droppedDuplicateCount: number;
|
|
25
|
-
droppedOrphanCount: number;
|
|
26
|
-
moved: boolean;
|
|
27
|
-
};
|
|
28
|
-
export type ToolCallInputRepairOptions = {
|
|
29
|
-
allowedToolNames?: Iterable<string>;
|
|
30
|
-
};
|
|
31
|
-
export type ToolUseRepairOptions<TMessage extends TranscriptMessageLike> = {
|
|
32
|
-
createMissingToolResult?: (params: {
|
|
33
|
-
toolCallId: string;
|
|
34
|
-
toolName?: string;
|
|
35
|
-
}) => TMessage;
|
|
36
|
-
};
|
|
37
|
-
export declare function stripToolResultDetails<TMessage extends TranscriptMessageLike>(messages: readonly TMessage[]): TMessage[];
|
|
38
|
-
export declare function repairToolCallInputs<TMessage extends TranscriptMessageLike>(messages: readonly TMessage[], options?: ToolCallInputRepairOptions): ToolCallInputRepairReport<TMessage>;
|
|
39
|
-
export declare function sanitizeToolCallInputs<TMessage extends TranscriptMessageLike>(messages: readonly TMessage[], options?: ToolCallInputRepairOptions): TMessage[];
|
|
40
|
-
export declare function repairToolUseResultPairing<TMessage extends TranscriptMessageLike>(messages: readonly TMessage[], options?: ToolUseRepairOptions<TMessage>): ToolUseRepairReport<TMessage>;
|
|
41
|
-
export declare function sanitizeToolUseResultPairing<TMessage extends TranscriptMessageLike>(messages: readonly TMessage[], options?: ToolUseRepairOptions<TMessage>): TMessage[];
|
|
42
|
-
export declare function stripTransientErrorMessages<TMessage extends TranscriptMessageLike>(messages: readonly TMessage[]): TMessage[];
|