@iqai/adk 0.2.2 → 0.2.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/CHANGELOG.md +14 -0
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +22 -13
- package/dist/index.mjs +22 -13
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @iqai/adk
|
|
2
2
|
|
|
3
|
+
## 0.2.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- dc2c3eb: Fix database session service to use consistent state prefixes with in-memory service
|
|
8
|
+
|
|
9
|
+
The database session service was using hardcoded prefix strings ("app*", "user*", "temp\_") instead of the proper State constants (State.APP_PREFIX, State.USER_PREFIX, State.TEMP_PREFIX) that are used by the in-memory session service. This inconsistency could cause state handling issues when switching between session service implementations.
|
|
10
|
+
|
|
11
|
+
## 0.2.3
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 298edf1: `convertMcpToolToBaseTool` now takes in a optional toolHandler for more modularity
|
|
16
|
+
|
|
3
17
|
## 0.2.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ import { LanguageModel } from 'ai';
|
|
|
4
4
|
import * as zod from 'zod';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
7
|
-
import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
+
import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
8
8
|
import { Kysely, Generated } from 'kysely';
|
|
9
9
|
import { StorageOptions } from '@google-cloud/storage';
|
|
10
10
|
import { Tracer } from '@opentelemetry/api';
|
|
@@ -2079,7 +2079,12 @@ declare class McpClientService {
|
|
|
2079
2079
|
removeSamplingHandler(): void;
|
|
2080
2080
|
}
|
|
2081
2081
|
|
|
2082
|
-
|
|
2082
|
+
type ConvertMcpToolTooBaseToolParams = {
|
|
2083
|
+
mcpTool: Tool;
|
|
2084
|
+
client?: Client;
|
|
2085
|
+
toolHandler?: (name: string, args: unknown) => Promise<CallToolResult>;
|
|
2086
|
+
};
|
|
2087
|
+
declare function convertMcpToolToBaseTool(params: ConvertMcpToolTooBaseToolParams): Promise<BaseTool>;
|
|
2083
2088
|
|
|
2084
2089
|
/**
|
|
2085
2090
|
* Converts an ADK-style BaseTool to an MCP tool format
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { LanguageModel } from 'ai';
|
|
|
4
4
|
import * as zod from 'zod';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
7
|
-
import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
+
import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
8
8
|
import { Kysely, Generated } from 'kysely';
|
|
9
9
|
import { StorageOptions } from '@google-cloud/storage';
|
|
10
10
|
import { Tracer } from '@opentelemetry/api';
|
|
@@ -2079,7 +2079,12 @@ declare class McpClientService {
|
|
|
2079
2079
|
removeSamplingHandler(): void;
|
|
2080
2080
|
}
|
|
2081
2081
|
|
|
2082
|
-
|
|
2082
|
+
type ConvertMcpToolTooBaseToolParams = {
|
|
2083
|
+
mcpTool: Tool;
|
|
2084
|
+
client?: Client;
|
|
2085
|
+
toolHandler?: (name: string, args: unknown) => Promise<CallToolResult>;
|
|
2086
|
+
};
|
|
2087
|
+
declare function convertMcpToolToBaseTool(params: ConvertMcpToolTooBaseToolParams): Promise<BaseTool>;
|
|
2083
2088
|
|
|
2084
2089
|
/**
|
|
2085
2090
|
* Converts an ADK-style BaseTool to an MCP tool format
|
package/dist/index.js
CHANGED
|
@@ -5816,9 +5816,13 @@ function mcpSchemaToParameters(mcpTool) {
|
|
|
5816
5816
|
}
|
|
5817
5817
|
|
|
5818
5818
|
// src/tools/mcp/create-tool.ts
|
|
5819
|
-
async function convertMcpToolToBaseTool(
|
|
5819
|
+
async function convertMcpToolToBaseTool(params) {
|
|
5820
5820
|
try {
|
|
5821
|
-
return new McpToolAdapter(
|
|
5821
|
+
return new McpToolAdapter(
|
|
5822
|
+
params.mcpTool,
|
|
5823
|
+
params.client,
|
|
5824
|
+
params.toolHandler
|
|
5825
|
+
);
|
|
5822
5826
|
} catch (error) {
|
|
5823
5827
|
if (!(error instanceof McpError)) {
|
|
5824
5828
|
throw new McpError(
|
|
@@ -5834,8 +5838,9 @@ var McpToolAdapter = (_class23 = class extends BaseTool {
|
|
|
5834
5838
|
|
|
5835
5839
|
|
|
5836
5840
|
__init37() {this.clientService = null}
|
|
5841
|
+
|
|
5837
5842
|
__init38() {this.logger = new Logger({ name: "McpToolAdapter" })}
|
|
5838
|
-
constructor(mcpTool, client) {
|
|
5843
|
+
constructor(mcpTool, client, handler) {
|
|
5839
5844
|
const metadata = mcpTool.metadata || {};
|
|
5840
5845
|
super({
|
|
5841
5846
|
name: mcpTool.name || `mcp_${Date.now()}`,
|
|
@@ -5846,6 +5851,7 @@ var McpToolAdapter = (_class23 = class extends BaseTool {
|
|
|
5846
5851
|
});_class23.prototype.__init37.call(this);_class23.prototype.__init38.call(this);;
|
|
5847
5852
|
this.mcpTool = mcpTool;
|
|
5848
5853
|
this.client = client;
|
|
5854
|
+
this.toolHandler = handler;
|
|
5849
5855
|
if (client && client.reinitialize && typeof client.reinitialize === "function") {
|
|
5850
5856
|
this.clientService = client;
|
|
5851
5857
|
}
|
|
@@ -5900,6 +5906,9 @@ var McpToolAdapter = (_class23 = class extends BaseTool {
|
|
|
5900
5906
|
});
|
|
5901
5907
|
return result;
|
|
5902
5908
|
}
|
|
5909
|
+
if (this.toolHandler) {
|
|
5910
|
+
return await this.toolHandler(this.name, args);
|
|
5911
|
+
}
|
|
5903
5912
|
throw new McpError(
|
|
5904
5913
|
`Cannot execute MCP tool ${this.name}: No execution method found`,
|
|
5905
5914
|
"tool_execution_error" /* TOOL_EXECUTION_ERROR */
|
|
@@ -6158,10 +6167,10 @@ var McpToolset = (_class24 = class {
|
|
|
6158
6167
|
for (const mcpTool of toolsResponse.tools) {
|
|
6159
6168
|
if (this.isSelected(mcpTool, context4)) {
|
|
6160
6169
|
try {
|
|
6161
|
-
const tool = await convertMcpToolToBaseTool(
|
|
6170
|
+
const tool = await convertMcpToolToBaseTool({
|
|
6162
6171
|
mcpTool,
|
|
6163
6172
|
client
|
|
6164
|
-
);
|
|
6173
|
+
});
|
|
6165
6174
|
tools.push(tool);
|
|
6166
6175
|
} catch (toolError) {
|
|
6167
6176
|
console.error(
|
|
@@ -11510,11 +11519,11 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
11510
11519
|
const sessionStateDelta = {};
|
|
11511
11520
|
if (state) {
|
|
11512
11521
|
for (const [key, value] of Object.entries(state)) {
|
|
11513
|
-
if (key.startsWith(
|
|
11514
|
-
appStateDelta[key.substring(
|
|
11515
|
-
} else if (key.startsWith(
|
|
11516
|
-
userStateDelta[key.substring(
|
|
11517
|
-
} else if (!key.startsWith(
|
|
11522
|
+
if (key.startsWith(State.APP_PREFIX)) {
|
|
11523
|
+
appStateDelta[key.substring(State.APP_PREFIX.length)] = value;
|
|
11524
|
+
} else if (key.startsWith(State.USER_PREFIX)) {
|
|
11525
|
+
userStateDelta[key.substring(State.USER_PREFIX.length)] = value;
|
|
11526
|
+
} else if (!key.startsWith(State.TEMP_PREFIX)) {
|
|
11518
11527
|
sessionStateDelta[key] = value;
|
|
11519
11528
|
}
|
|
11520
11529
|
}
|
|
@@ -11527,10 +11536,10 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
11527
11536
|
mergeState(appState, userState, sessionState) {
|
|
11528
11537
|
const mergedState = { ...sessionState };
|
|
11529
11538
|
for (const [key, value] of Object.entries(appState)) {
|
|
11530
|
-
mergedState[
|
|
11539
|
+
mergedState[`${State.APP_PREFIX}${key}`] = value;
|
|
11531
11540
|
}
|
|
11532
11541
|
for (const [key, value] of Object.entries(userState)) {
|
|
11533
|
-
mergedState[
|
|
11542
|
+
mergedState[`${State.USER_PREFIX}${key}`] = value;
|
|
11534
11543
|
}
|
|
11535
11544
|
return mergedState;
|
|
11536
11545
|
}
|
|
@@ -11612,7 +11621,7 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
11612
11621
|
return;
|
|
11613
11622
|
}
|
|
11614
11623
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
11615
|
-
if (!key.startsWith(
|
|
11624
|
+
if (!key.startsWith(State.TEMP_PREFIX)) {
|
|
11616
11625
|
session.state[key] = value;
|
|
11617
11626
|
}
|
|
11618
11627
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -5816,9 +5816,13 @@ function mcpSchemaToParameters(mcpTool) {
|
|
|
5816
5816
|
}
|
|
5817
5817
|
|
|
5818
5818
|
// src/tools/mcp/create-tool.ts
|
|
5819
|
-
async function convertMcpToolToBaseTool(
|
|
5819
|
+
async function convertMcpToolToBaseTool(params) {
|
|
5820
5820
|
try {
|
|
5821
|
-
return new McpToolAdapter(
|
|
5821
|
+
return new McpToolAdapter(
|
|
5822
|
+
params.mcpTool,
|
|
5823
|
+
params.client,
|
|
5824
|
+
params.toolHandler
|
|
5825
|
+
);
|
|
5822
5826
|
} catch (error) {
|
|
5823
5827
|
if (!(error instanceof McpError)) {
|
|
5824
5828
|
throw new McpError(
|
|
@@ -5834,8 +5838,9 @@ var McpToolAdapter = class extends BaseTool {
|
|
|
5834
5838
|
mcpTool;
|
|
5835
5839
|
client;
|
|
5836
5840
|
clientService = null;
|
|
5841
|
+
toolHandler;
|
|
5837
5842
|
logger = new Logger({ name: "McpToolAdapter" });
|
|
5838
|
-
constructor(mcpTool, client) {
|
|
5843
|
+
constructor(mcpTool, client, handler) {
|
|
5839
5844
|
const metadata = mcpTool.metadata || {};
|
|
5840
5845
|
super({
|
|
5841
5846
|
name: mcpTool.name || `mcp_${Date.now()}`,
|
|
@@ -5846,6 +5851,7 @@ var McpToolAdapter = class extends BaseTool {
|
|
|
5846
5851
|
});
|
|
5847
5852
|
this.mcpTool = mcpTool;
|
|
5848
5853
|
this.client = client;
|
|
5854
|
+
this.toolHandler = handler;
|
|
5849
5855
|
if (client && client.reinitialize && typeof client.reinitialize === "function") {
|
|
5850
5856
|
this.clientService = client;
|
|
5851
5857
|
}
|
|
@@ -5900,6 +5906,9 @@ var McpToolAdapter = class extends BaseTool {
|
|
|
5900
5906
|
});
|
|
5901
5907
|
return result;
|
|
5902
5908
|
}
|
|
5909
|
+
if (this.toolHandler) {
|
|
5910
|
+
return await this.toolHandler(this.name, args);
|
|
5911
|
+
}
|
|
5903
5912
|
throw new McpError(
|
|
5904
5913
|
`Cannot execute MCP tool ${this.name}: No execution method found`,
|
|
5905
5914
|
"tool_execution_error" /* TOOL_EXECUTION_ERROR */
|
|
@@ -6158,10 +6167,10 @@ var McpToolset = class {
|
|
|
6158
6167
|
for (const mcpTool of toolsResponse.tools) {
|
|
6159
6168
|
if (this.isSelected(mcpTool, context4)) {
|
|
6160
6169
|
try {
|
|
6161
|
-
const tool = await convertMcpToolToBaseTool(
|
|
6170
|
+
const tool = await convertMcpToolToBaseTool({
|
|
6162
6171
|
mcpTool,
|
|
6163
6172
|
client
|
|
6164
|
-
);
|
|
6173
|
+
});
|
|
6165
6174
|
tools.push(tool);
|
|
6166
6175
|
} catch (toolError) {
|
|
6167
6176
|
console.error(
|
|
@@ -11510,11 +11519,11 @@ var DatabaseSessionService = class extends BaseSessionService {
|
|
|
11510
11519
|
const sessionStateDelta = {};
|
|
11511
11520
|
if (state) {
|
|
11512
11521
|
for (const [key, value] of Object.entries(state)) {
|
|
11513
|
-
if (key.startsWith(
|
|
11514
|
-
appStateDelta[key.substring(
|
|
11515
|
-
} else if (key.startsWith(
|
|
11516
|
-
userStateDelta[key.substring(
|
|
11517
|
-
} else if (!key.startsWith(
|
|
11522
|
+
if (key.startsWith(State.APP_PREFIX)) {
|
|
11523
|
+
appStateDelta[key.substring(State.APP_PREFIX.length)] = value;
|
|
11524
|
+
} else if (key.startsWith(State.USER_PREFIX)) {
|
|
11525
|
+
userStateDelta[key.substring(State.USER_PREFIX.length)] = value;
|
|
11526
|
+
} else if (!key.startsWith(State.TEMP_PREFIX)) {
|
|
11518
11527
|
sessionStateDelta[key] = value;
|
|
11519
11528
|
}
|
|
11520
11529
|
}
|
|
@@ -11527,10 +11536,10 @@ var DatabaseSessionService = class extends BaseSessionService {
|
|
|
11527
11536
|
mergeState(appState, userState, sessionState) {
|
|
11528
11537
|
const mergedState = { ...sessionState };
|
|
11529
11538
|
for (const [key, value] of Object.entries(appState)) {
|
|
11530
|
-
mergedState[
|
|
11539
|
+
mergedState[`${State.APP_PREFIX}${key}`] = value;
|
|
11531
11540
|
}
|
|
11532
11541
|
for (const [key, value] of Object.entries(userState)) {
|
|
11533
|
-
mergedState[
|
|
11542
|
+
mergedState[`${State.USER_PREFIX}${key}`] = value;
|
|
11534
11543
|
}
|
|
11535
11544
|
return mergedState;
|
|
11536
11545
|
}
|
|
@@ -11612,7 +11621,7 @@ var DatabaseSessionService = class extends BaseSessionService {
|
|
|
11612
11621
|
return;
|
|
11613
11622
|
}
|
|
11614
11623
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
11615
|
-
if (!key.startsWith(
|
|
11624
|
+
if (!key.startsWith(State.TEMP_PREFIX)) {
|
|
11616
11625
|
session.state[key] = value;
|
|
11617
11626
|
}
|
|
11618
11627
|
}
|