@iqai/adk 0.3.1 → 0.3.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/CHANGELOG.md +34 -0
- package/dist/index.d.mts +4 -7
- package/dist/index.d.ts +4 -7
- package/dist/index.js +188 -174
- package/dist/index.mjs +71 -57
- package/package.json +34 -35
package/dist/index.mjs
CHANGED
|
@@ -82,7 +82,8 @@ var init_logger = __esm({
|
|
|
82
82
|
title: `${icon} ${this.capitalize(level)} @ ${time} (${this.name})`,
|
|
83
83
|
description: message,
|
|
84
84
|
lines,
|
|
85
|
-
color
|
|
85
|
+
color,
|
|
86
|
+
wrap: true
|
|
86
87
|
});
|
|
87
88
|
method(box);
|
|
88
89
|
} else {
|
|
@@ -109,7 +110,7 @@ var init_logger = __esm({
|
|
|
109
110
|
}
|
|
110
111
|
formatArgs(args, includeStack = false) {
|
|
111
112
|
const lines = [];
|
|
112
|
-
const maxFrames = Number(process.env.ADK_ERROR_STACK_FRAMES
|
|
113
|
+
const maxFrames = process.env.ADK_ERROR_STACK_FRAMES !== void 0 ? Number(process.env.ADK_ERROR_STACK_FRAMES) : Number.POSITIVE_INFINITY;
|
|
113
114
|
for (const arg of args) {
|
|
114
115
|
if (!arg) continue;
|
|
115
116
|
if (arg instanceof Error) {
|
|
@@ -161,7 +162,8 @@ var init_logger = __esm({
|
|
|
161
162
|
maxWidthPct = 0.9,
|
|
162
163
|
color = chalk.yellow,
|
|
163
164
|
pad = 1,
|
|
164
|
-
borderChar = "\u2500"
|
|
165
|
+
borderChar = "\u2500",
|
|
166
|
+
wrap = false
|
|
165
167
|
} = params;
|
|
166
168
|
const isProd = process.env.NODE_ENV === "production";
|
|
167
169
|
const forceBoxes = process.env.ADK_FORCE_BOXES === "true";
|
|
@@ -181,20 +183,41 @@ var init_logger = __esm({
|
|
|
181
183
|
const top = `\u250C${horizontal}\u2510`;
|
|
182
184
|
const separator = `\u251C${horizontal}\u2524`;
|
|
183
185
|
const bottom = `\u2514${horizontal}\u2518`;
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
const maxContent = innerWidth - pad * 2;
|
|
187
|
+
const wrapText = (text) => {
|
|
188
|
+
if (!wrap) {
|
|
189
|
+
const truncated = text.length > maxContent ? `${text.slice(0, maxContent - 1)}\u2026` : text;
|
|
190
|
+
const padded = " ".repeat(pad) + truncated;
|
|
191
|
+
return [padded + " ".repeat(innerWidth - padded.length)];
|
|
192
|
+
}
|
|
193
|
+
const out = [];
|
|
194
|
+
let remaining = text;
|
|
195
|
+
while (remaining.length > 0) {
|
|
196
|
+
if (remaining.length <= maxContent) {
|
|
197
|
+
const padded2 = " ".repeat(pad) + remaining;
|
|
198
|
+
out.push(padded2 + " ".repeat(innerWidth - padded2.length));
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
let sliceEnd = maxContent;
|
|
202
|
+
const slice = remaining.slice(0, maxContent + 1);
|
|
203
|
+
const lastSpace = slice.lastIndexOf(" ");
|
|
204
|
+
if (lastSpace > -1 && lastSpace >= Math.floor(maxContent * 0.6)) {
|
|
205
|
+
sliceEnd = lastSpace;
|
|
206
|
+
}
|
|
207
|
+
const chunk = remaining.slice(0, sliceEnd).trimEnd();
|
|
208
|
+
const padded = " ".repeat(pad) + chunk;
|
|
209
|
+
out.push(padded + " ".repeat(innerWidth - padded.length));
|
|
210
|
+
remaining = remaining.slice(sliceEnd).trimStart();
|
|
211
|
+
}
|
|
212
|
+
return out;
|
|
189
213
|
};
|
|
190
|
-
const content = [
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
];
|
|
214
|
+
const content = [top];
|
|
215
|
+
for (const l of wrapText(title)) content.push(`\u2502 ${l} \u2502`);
|
|
216
|
+
content.push(separator);
|
|
217
|
+
for (const l of wrapText(description)) content.push(`\u2502 ${l} \u2502`);
|
|
218
|
+
for (const line of lines)
|
|
219
|
+
for (const l of wrapText(line)) content.push(`\u2502 ${l} \u2502`);
|
|
220
|
+
content.push(bottom);
|
|
198
221
|
return `
|
|
199
222
|
${content.map((line) => color(line)).join("\n")}`;
|
|
200
223
|
}
|
|
@@ -1520,7 +1543,11 @@ var AiSdkLlm = class extends BaseLlm {
|
|
|
1520
1543
|
* @param model - Pre-configured LanguageModel from provider(modelName)
|
|
1521
1544
|
*/
|
|
1522
1545
|
constructor(modelInstance) {
|
|
1523
|
-
|
|
1546
|
+
let modelId = "ai-sdk-model";
|
|
1547
|
+
if (typeof modelInstance !== "string") {
|
|
1548
|
+
modelId = modelInstance.modelId;
|
|
1549
|
+
}
|
|
1550
|
+
super(modelId);
|
|
1524
1551
|
this.modelInstance = modelInstance;
|
|
1525
1552
|
}
|
|
1526
1553
|
/**
|
|
@@ -1567,7 +1594,7 @@ var AiSdkLlm = class extends BaseLlm {
|
|
|
1567
1594
|
functionCall: {
|
|
1568
1595
|
id: toolCall.toolCallId,
|
|
1569
1596
|
name: toolCall.toolName,
|
|
1570
|
-
args: toolCall.
|
|
1597
|
+
args: toolCall.input
|
|
1571
1598
|
}
|
|
1572
1599
|
});
|
|
1573
1600
|
}
|
|
@@ -1580,8 +1607,8 @@ var AiSdkLlm = class extends BaseLlm {
|
|
|
1580
1607
|
parts: parts.length > 0 ? parts : [{ text: "" }]
|
|
1581
1608
|
},
|
|
1582
1609
|
usageMetadata: finalUsage ? {
|
|
1583
|
-
promptTokenCount: finalUsage.
|
|
1584
|
-
candidatesTokenCount: finalUsage.
|
|
1610
|
+
promptTokenCount: finalUsage.inputTokens,
|
|
1611
|
+
candidatesTokenCount: finalUsage.outputTokens,
|
|
1585
1612
|
totalTokenCount: finalUsage.totalTokens
|
|
1586
1613
|
} : void 0,
|
|
1587
1614
|
finishReason: this.mapFinishReason(finishReason),
|
|
@@ -1599,7 +1626,7 @@ var AiSdkLlm = class extends BaseLlm {
|
|
|
1599
1626
|
functionCall: {
|
|
1600
1627
|
id: toolCall.toolCallId,
|
|
1601
1628
|
name: toolCall.toolName,
|
|
1602
|
-
args: toolCall.
|
|
1629
|
+
args: toolCall.input
|
|
1603
1630
|
}
|
|
1604
1631
|
});
|
|
1605
1632
|
}
|
|
@@ -1610,8 +1637,8 @@ var AiSdkLlm = class extends BaseLlm {
|
|
|
1610
1637
|
parts: parts.length > 0 ? parts : [{ text: "" }]
|
|
1611
1638
|
},
|
|
1612
1639
|
usageMetadata: result.usage ? {
|
|
1613
|
-
promptTokenCount: result.usage.
|
|
1614
|
-
candidatesTokenCount: result.usage.
|
|
1640
|
+
promptTokenCount: result.usage.inputTokens,
|
|
1641
|
+
candidatesTokenCount: result.usage.outputTokens,
|
|
1615
1642
|
totalTokenCount: result.usage.totalTokens
|
|
1616
1643
|
} : void 0,
|
|
1617
1644
|
finishReason: this.mapFinishReason(result.finishReason),
|
|
@@ -1687,7 +1714,7 @@ var AiSdkLlm = class extends BaseLlm {
|
|
|
1687
1714
|
for (const funcDecl of toolConfig.functionDeclarations) {
|
|
1688
1715
|
tools[funcDecl.name] = {
|
|
1689
1716
|
description: funcDecl.description,
|
|
1690
|
-
|
|
1717
|
+
inputSchema: jsonSchema(
|
|
1691
1718
|
this.transformSchemaForAiSdk(funcDecl.parameters || {})
|
|
1692
1719
|
)
|
|
1693
1720
|
};
|
|
@@ -1733,7 +1760,7 @@ var AiSdkLlm = class extends BaseLlm {
|
|
|
1733
1760
|
type: "tool-call",
|
|
1734
1761
|
toolCallId: funcPart.functionCall.id,
|
|
1735
1762
|
toolName: funcPart.functionCall.name,
|
|
1736
|
-
|
|
1763
|
+
input: funcPart.functionCall.args
|
|
1737
1764
|
});
|
|
1738
1765
|
}
|
|
1739
1766
|
}
|
|
@@ -1746,12 +1773,14 @@ var AiSdkLlm = class extends BaseLlm {
|
|
|
1746
1773
|
const functionResponses = content.parts.filter(
|
|
1747
1774
|
(part) => part.functionResponse
|
|
1748
1775
|
);
|
|
1749
|
-
const contentParts2 = functionResponses.map((part) =>
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1776
|
+
const contentParts2 = functionResponses.map((part) => {
|
|
1777
|
+
return {
|
|
1778
|
+
type: "tool-result",
|
|
1779
|
+
toolCallId: part.functionResponse.id,
|
|
1780
|
+
toolName: part.functionResponse.name || "unknown",
|
|
1781
|
+
output: part.functionResponse.response
|
|
1782
|
+
};
|
|
1783
|
+
});
|
|
1755
1784
|
return {
|
|
1756
1785
|
role: "tool",
|
|
1757
1786
|
content: contentParts2
|
|
@@ -2201,16 +2230,6 @@ var GoogleLlm = class extends BaseLlm {
|
|
|
2201
2230
|
dataObj.displayName = null;
|
|
2202
2231
|
}
|
|
2203
2232
|
}
|
|
2204
|
-
/**
|
|
2205
|
-
* Builds function declaration log string.
|
|
2206
|
-
*/
|
|
2207
|
-
buildFunctionDeclarationLog(funcDecl) {
|
|
2208
|
-
let paramStr = "{}";
|
|
2209
|
-
if (funcDecl.parameters?.properties) {
|
|
2210
|
-
paramStr = JSON.stringify(funcDecl.parameters.properties);
|
|
2211
|
-
}
|
|
2212
|
-
return `${funcDecl.name}: ${paramStr}`;
|
|
2213
|
-
}
|
|
2214
2233
|
/**
|
|
2215
2234
|
* Provides the api client.
|
|
2216
2235
|
*/
|
|
@@ -4085,7 +4104,6 @@ init_base_tool();
|
|
|
4085
4104
|
// src/tools/base/create-tool.ts
|
|
4086
4105
|
init_base_tool();
|
|
4087
4106
|
import * as z from "zod";
|
|
4088
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
4089
4107
|
var CreatedTool = class extends BaseTool {
|
|
4090
4108
|
func;
|
|
4091
4109
|
schema;
|
|
@@ -4131,10 +4149,7 @@ var CreatedTool = class extends BaseTool {
|
|
|
4131
4149
|
* Builds the function declaration from the Zod schema
|
|
4132
4150
|
*/
|
|
4133
4151
|
buildDeclaration() {
|
|
4134
|
-
const rawParameters =
|
|
4135
|
-
target: "jsonSchema7",
|
|
4136
|
-
$refStrategy: "none"
|
|
4137
|
-
});
|
|
4152
|
+
const rawParameters = z.toJSONSchema(this.schema);
|
|
4138
4153
|
const { $schema, ...parameters } = rawParameters;
|
|
4139
4154
|
return {
|
|
4140
4155
|
name: this.name,
|
|
@@ -8340,7 +8355,7 @@ var IdentityLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8340
8355
|
var requestProcessor5 = new IdentityLlmRequestProcessor();
|
|
8341
8356
|
|
|
8342
8357
|
// src/flows/llm-flows/instructions.ts
|
|
8343
|
-
import
|
|
8358
|
+
import z2 from "zod";
|
|
8344
8359
|
|
|
8345
8360
|
// src/utils/instructions-utils.ts
|
|
8346
8361
|
async function injectSessionState(template, readonlyContext) {
|
|
@@ -8458,10 +8473,7 @@ var InstructionsLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8458
8473
|
}
|
|
8459
8474
|
if (agent.outputSchema) {
|
|
8460
8475
|
try {
|
|
8461
|
-
const raw =
|
|
8462
|
-
target: "jsonSchema7",
|
|
8463
|
-
$refStrategy: "none"
|
|
8464
|
-
});
|
|
8476
|
+
const raw = z2.toJSONSchema(agent.outputSchema);
|
|
8465
8477
|
const { $schema, ...json } = raw || {};
|
|
8466
8478
|
llmRequest.appendInstructions([
|
|
8467
8479
|
"You must respond with application/json that validates against this JSON Schema (do NOT wrap the output in markdown or code fences):",
|
|
@@ -11209,12 +11221,14 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
11209
11221
|
try {
|
|
11210
11222
|
return outputSchema.parse(combinedResponse);
|
|
11211
11223
|
} catch (validationError) {
|
|
11212
|
-
|
|
11213
|
-
|
|
11214
|
-
|
|
11215
|
-
|
|
11216
|
-
|
|
11217
|
-
|
|
11224
|
+
const message2 = `\u{1F6A8} Failed to parse and validate LLM output against the schema.
|
|
11225
|
+
|
|
11226
|
+
\u2139\uFE0F JSON parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}
|
|
11227
|
+
|
|
11228
|
+
\u{1F6A7} Zod validation error: ${validationError instanceof Error ? validationError.message : String(validationError)}
|
|
11229
|
+
|
|
11230
|
+
\u{1F4C4} Raw output: ${combinedResponse}`;
|
|
11231
|
+
throw new Error(message2);
|
|
11218
11232
|
}
|
|
11219
11233
|
}
|
|
11220
11234
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iqai/adk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Agent Development Kit for TypeScript with multi-provider LLM support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,38 +23,37 @@
|
|
|
23
23
|
"author": "IQAI",
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@anthropic-ai/sdk": "^0.
|
|
26
|
+
"@anthropic-ai/sdk": "^0.61.0",
|
|
27
27
|
"@clack/prompts": "^0.11.0",
|
|
28
|
-
"@electric-sql/pglite": "^0.3.
|
|
29
|
-
"@google-cloud/storage": "^7.
|
|
30
|
-
"@google-cloud/vertexai": "^
|
|
31
|
-
"@google/genai": "^1.
|
|
32
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
28
|
+
"@electric-sql/pglite": "^0.3.8",
|
|
29
|
+
"@google-cloud/storage": "^7.17.0",
|
|
30
|
+
"@google-cloud/vertexai": "^1.10.0",
|
|
31
|
+
"@google/genai": "^1.19.0",
|
|
32
|
+
"@modelcontextprotocol/sdk": "^1.17.5",
|
|
33
33
|
"@opentelemetry/api": "^1.9.0",
|
|
34
|
-
"@opentelemetry/auto-instrumentations-node": "^0.
|
|
35
|
-
"@opentelemetry/exporter-trace-otlp-http": "^0.
|
|
36
|
-
"@opentelemetry/resources": "^2.0
|
|
37
|
-
"@opentelemetry/sdk-node": "^0.
|
|
38
|
-
"@opentelemetry/sdk-trace-base": "^2.0
|
|
39
|
-
"@opentelemetry/sdk-trace-node": "^2.0
|
|
40
|
-
"@opentelemetry/semantic-conventions": "^1.
|
|
34
|
+
"@opentelemetry/auto-instrumentations-node": "^0.63.0",
|
|
35
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.204.0",
|
|
36
|
+
"@opentelemetry/resources": "^2.1.0",
|
|
37
|
+
"@opentelemetry/sdk-node": "^0.204.0",
|
|
38
|
+
"@opentelemetry/sdk-trace-base": "^2.1.0",
|
|
39
|
+
"@opentelemetry/sdk-trace-node": "^2.1.0",
|
|
40
|
+
"@opentelemetry/semantic-conventions": "^1.37.0",
|
|
41
41
|
"@types/cors": "^2.8.19",
|
|
42
|
-
"ai": "^
|
|
43
|
-
"axios": "^1.
|
|
44
|
-
"chalk": "^5.
|
|
42
|
+
"ai": "^5.0.39",
|
|
43
|
+
"axios": "^1.11.0",
|
|
44
|
+
"chalk": "^5.6.2",
|
|
45
45
|
"cors": "^2.8.5",
|
|
46
|
-
"dedent": "^1.
|
|
47
|
-
"dockerode": "^4.0.
|
|
48
|
-
"dotenv": "^
|
|
49
|
-
"drizzle-orm": "^0.
|
|
50
|
-
"
|
|
51
|
-
"
|
|
46
|
+
"dedent": "^1.7.0",
|
|
47
|
+
"dockerode": "^4.0.8",
|
|
48
|
+
"dotenv": "^17.2.2",
|
|
49
|
+
"drizzle-orm": "^0.44.5",
|
|
50
|
+
"jsonrepair": "^3.13.0",
|
|
51
|
+
"kysely": "^0.28.5",
|
|
52
|
+
"openai": "^5.20.0",
|
|
52
53
|
"socket.io": "^4.8.1",
|
|
53
54
|
"ts-node": "^10.9.2",
|
|
54
|
-
"uuid": "^
|
|
55
|
-
"zod": "^
|
|
56
|
-
"jsonrepair": "^3.13.0",
|
|
57
|
-
"zod-to-json-schema": "^3.24.6"
|
|
55
|
+
"uuid": "^13.0.0",
|
|
56
|
+
"zod": "^4.1.5"
|
|
58
57
|
},
|
|
59
58
|
"peerDependencies": {
|
|
60
59
|
"better-sqlite3": "^11.10.0",
|
|
@@ -74,14 +73,14 @@
|
|
|
74
73
|
},
|
|
75
74
|
"devDependencies": {
|
|
76
75
|
"@types/better-sqlite3": "^7.6.13",
|
|
77
|
-
"@types/dockerode": "^3.3.
|
|
78
|
-
"@types/node": "^
|
|
79
|
-
"better-sqlite3": "^
|
|
80
|
-
"mysql2": "^3.14.
|
|
81
|
-
"pg": "^8.16.
|
|
82
|
-
"tsup": "^8.
|
|
83
|
-
"typescript": "^5.
|
|
84
|
-
"vitest": "^3.
|
|
76
|
+
"@types/dockerode": "^3.3.43",
|
|
77
|
+
"@types/node": "^24.3.1",
|
|
78
|
+
"better-sqlite3": "^12.2.0",
|
|
79
|
+
"mysql2": "^3.14.5",
|
|
80
|
+
"pg": "^8.16.3",
|
|
81
|
+
"tsup": "^8.5.0",
|
|
82
|
+
"typescript": "^5.9.2",
|
|
83
|
+
"vitest": "^3.2.4",
|
|
85
84
|
"@iqai/tsconfig": "0.0.1"
|
|
86
85
|
},
|
|
87
86
|
"packageManager": "pnpm@9.0.0",
|