@google/adk 0.6.0 → 0.6.1
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/cjs/a2a/a2a_remote_agent.js +18 -13
- package/dist/cjs/a2a/a2a_remote_agent_run_processor.js +7 -0
- package/dist/cjs/index.js +16 -16
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/utils/gemini_schema_util.js +54 -12
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +18 -13
- package/dist/esm/a2a/a2a_remote_agent_run_processor.js +7 -0
- package/dist/esm/index.js +15 -15
- package/dist/esm/index.js.map +3 -3
- package/dist/esm/utils/gemini_schema_util.js +54 -12
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +7 -3
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_remote_agent.js +15 -24
- package/dist/web/a2a/a2a_remote_agent_run_processor.js +7 -0
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +1 -1
- package/dist/web/utils/gemini_schema_util.js +85 -12
- package/dist/web/version.js +1 -1
- package/package.json +2 -2
|
@@ -55,22 +55,50 @@ function toGeminiType(mcpType) {
|
|
|
55
55
|
return import_genai.Type.ARRAY;
|
|
56
56
|
case "object":
|
|
57
57
|
return import_genai.Type.OBJECT;
|
|
58
|
+
case "null":
|
|
59
|
+
return import_genai.Type.NULL;
|
|
58
60
|
default:
|
|
59
61
|
return import_genai.Type.TYPE_UNSPECIFIED;
|
|
60
62
|
}
|
|
61
63
|
}
|
|
64
|
+
const getTypeFromArrayItem = (mcpType) => {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
if (typeof mcpType === "string") {
|
|
67
|
+
return mcpType.toLowerCase();
|
|
68
|
+
}
|
|
69
|
+
return (_b = (_a = mcpType == null ? void 0 : mcpType.type) == null ? void 0 : _a.toLowerCase) == null ? void 0 : _b.call(_a);
|
|
70
|
+
};
|
|
62
71
|
function toGeminiSchema(mcpSchema) {
|
|
63
72
|
if (!mcpSchema) {
|
|
64
73
|
return void 0;
|
|
65
74
|
}
|
|
66
75
|
function recursiveConvert(mcp) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
var _a;
|
|
77
|
+
const sourceType = (_a = mcp.anyOf) != null ? _a : mcp.type;
|
|
78
|
+
let isNullable = false;
|
|
79
|
+
let nonNullTypes;
|
|
80
|
+
if (Array.isArray(sourceType)) {
|
|
81
|
+
nonNullTypes = sourceType.filter(
|
|
82
|
+
(t) => getTypeFromArrayItem(t) !== "null"
|
|
83
|
+
);
|
|
84
|
+
isNullable = sourceType.some(
|
|
85
|
+
(t) => getTypeFromArrayItem(t) === "null"
|
|
86
|
+
);
|
|
87
|
+
if (nonNullTypes.length === 1) {
|
|
88
|
+
const nonNullType = nonNullTypes[0];
|
|
89
|
+
if (typeof nonNullType === "object") {
|
|
90
|
+
mcp = nonNullType;
|
|
91
|
+
} else {
|
|
92
|
+
const { type: _removed, anyOf: _removedAnyOf, ...rest } = mcp;
|
|
93
|
+
mcp = { ...rest, type: nonNullType };
|
|
94
|
+
}
|
|
95
|
+
} else if (nonNullTypes.length === 0 && isNullable) {
|
|
96
|
+
const { type: _removed, anyOf: _removedAnyOf, ...rest } = mcp;
|
|
97
|
+
mcp = { ...rest, type: "null" };
|
|
98
|
+
} else if (typeof mcp.anyOf === "undefined") {
|
|
99
|
+
const anyOfItems = mcp.type.map((t) => ({ type: t }));
|
|
100
|
+
const { type: _removed, ...rest } = mcp;
|
|
101
|
+
mcp = { ...rest, anyOf: anyOfItems };
|
|
74
102
|
}
|
|
75
103
|
}
|
|
76
104
|
if (!mcp.type) {
|
|
@@ -78,13 +106,25 @@ function toGeminiSchema(mcpSchema) {
|
|
|
78
106
|
mcp.type = "object";
|
|
79
107
|
} else if (mcp.items) {
|
|
80
108
|
mcp.type = "array";
|
|
109
|
+
} else if (isNullable) {
|
|
110
|
+
mcp.type = "null";
|
|
81
111
|
}
|
|
82
112
|
}
|
|
83
113
|
const geminiType = toGeminiType(mcp.type);
|
|
84
|
-
const geminiSchema = {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
114
|
+
const geminiSchema = {};
|
|
115
|
+
if (mcp.anyOf) {
|
|
116
|
+
geminiSchema.anyOf = mcp.anyOf.map(
|
|
117
|
+
(item) => recursiveConvert(item)
|
|
118
|
+
);
|
|
119
|
+
} else {
|
|
120
|
+
geminiSchema.type = geminiType;
|
|
121
|
+
}
|
|
122
|
+
if (mcp.description) {
|
|
123
|
+
geminiSchema.description = mcp.description;
|
|
124
|
+
}
|
|
125
|
+
if (isNullable && mcp.type !== "null") {
|
|
126
|
+
geminiSchema.nullable = true;
|
|
127
|
+
}
|
|
88
128
|
if (geminiType === import_genai.Type.OBJECT) {
|
|
89
129
|
geminiSchema.properties = {};
|
|
90
130
|
if (mcp.properties) {
|
|
@@ -94,7 +134,9 @@ function toGeminiSchema(mcpSchema) {
|
|
|
94
134
|
);
|
|
95
135
|
}
|
|
96
136
|
}
|
|
97
|
-
|
|
137
|
+
if (mcp.required) {
|
|
138
|
+
geminiSchema.required = mcp.required;
|
|
139
|
+
}
|
|
98
140
|
} else if (geminiType === import_genai.Type.ARRAY) {
|
|
99
141
|
if (mcp.items) {
|
|
100
142
|
geminiSchema.items = recursiveConvert(mcp.items);
|
package/dist/cjs/version.js
CHANGED
|
@@ -32,7 +32,7 @@ module.exports = __toCommonJS(version_exports);
|
|
|
32
32
|
* Copyright 2025 Google LLC
|
|
33
33
|
* SPDX-License-Identifier: Apache-2.0
|
|
34
34
|
*/
|
|
35
|
-
const version = "0.6.
|
|
35
|
+
const version = "0.6.1";
|
|
36
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
37
|
0 && (module.exports = {
|
|
38
38
|
version
|
|
@@ -26,17 +26,24 @@ class RemoteA2AAgent extends BaseAgent {
|
|
|
26
26
|
super(a2aConfig);
|
|
27
27
|
this.a2aConfig = a2aConfig;
|
|
28
28
|
this.isInitialized = false;
|
|
29
|
-
if (!a2aConfig.agentCard) {
|
|
30
|
-
throw new Error("AgentCard must be provided");
|
|
29
|
+
if (!a2aConfig.agentCard && !a2aConfig.client) {
|
|
30
|
+
throw new Error("Either AgentCard or Client must be provided");
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
async init() {
|
|
34
34
|
if (this.isInitialized) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
if (this.a2aConfig.client) {
|
|
38
|
+
this.client = this.a2aConfig.client;
|
|
39
|
+
}
|
|
40
|
+
if (this.a2aConfig.agentCard) {
|
|
41
|
+
this.card = await resolveAgentCard(this.a2aConfig.agentCard);
|
|
42
|
+
if (!this.client) {
|
|
43
|
+
const factory = this.a2aConfig.clientFactory || new ClientFactory();
|
|
44
|
+
this.client = await factory.createFromAgentCard(this.card);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
40
47
|
this.isInitialized = true;
|
|
41
48
|
}
|
|
42
49
|
async *runAsyncImpl(context) {
|
|
@@ -72,13 +79,11 @@ class RemoteA2AAgent extends BaseAgent {
|
|
|
72
79
|
messageId: randomUUID(),
|
|
73
80
|
role: MessageRole.USER,
|
|
74
81
|
parts,
|
|
75
|
-
metadata: {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
+
metadata: getA2ASessionMetadata({
|
|
83
|
+
appName: context.session.appName,
|
|
84
|
+
userId: context.session.userId,
|
|
85
|
+
sessionId: context.session.id
|
|
86
|
+
})
|
|
82
87
|
};
|
|
83
88
|
if (taskId) message.taskId = taskId;
|
|
84
89
|
if (contextId) message.contextId = contextId;
|
|
@@ -92,7 +97,7 @@ class RemoteA2AAgent extends BaseAgent {
|
|
|
92
97
|
await callback(context, params);
|
|
93
98
|
}
|
|
94
99
|
}
|
|
95
|
-
const useStreaming = ((_b = this.card.capabilities) == null ? void 0 : _b.streaming) !== false;
|
|
100
|
+
const useStreaming = this.card ? ((_b = this.card.capabilities) == null ? void 0 : _b.streaming) !== false : true;
|
|
96
101
|
if (useStreaming) {
|
|
97
102
|
for await (const chunk of this.client.sendMessageStream(params)) {
|
|
98
103
|
if (this.a2aConfig.afterRequestCallbacks) {
|
|
@@ -157,6 +157,13 @@ class A2ARemoteAgentRunProcessor {
|
|
|
157
157
|
}
|
|
158
158
|
if (response) {
|
|
159
159
|
toAdd["response"] = response;
|
|
160
|
+
if (isTask(response)) {
|
|
161
|
+
if (response.id) toAdd["task_id"] = response.id;
|
|
162
|
+
if (response.contextId) toAdd["context_id"] = response.contextId;
|
|
163
|
+
} else if (response.taskId) {
|
|
164
|
+
toAdd["task_id"] = response.taskId;
|
|
165
|
+
if (response.contextId) toAdd["context_id"] = response.contextId;
|
|
166
|
+
}
|
|
160
167
|
}
|
|
161
168
|
if (Object.keys(toAdd).length === 0) {
|
|
162
169
|
return;
|