@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
|
@@ -26,22 +26,50 @@ function toGeminiType(mcpType) {
|
|
|
26
26
|
return Type.ARRAY;
|
|
27
27
|
case "object":
|
|
28
28
|
return Type.OBJECT;
|
|
29
|
+
case "null":
|
|
30
|
+
return Type.NULL;
|
|
29
31
|
default:
|
|
30
32
|
return Type.TYPE_UNSPECIFIED;
|
|
31
33
|
}
|
|
32
34
|
}
|
|
35
|
+
const getTypeFromArrayItem = (mcpType) => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
if (typeof mcpType === "string") {
|
|
38
|
+
return mcpType.toLowerCase();
|
|
39
|
+
}
|
|
40
|
+
return (_b = (_a = mcpType == null ? void 0 : mcpType.type) == null ? void 0 : _a.toLowerCase) == null ? void 0 : _b.call(_a);
|
|
41
|
+
};
|
|
33
42
|
function toGeminiSchema(mcpSchema) {
|
|
34
43
|
if (!mcpSchema) {
|
|
35
44
|
return void 0;
|
|
36
45
|
}
|
|
37
46
|
function recursiveConvert(mcp) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
var _a;
|
|
48
|
+
const sourceType = (_a = mcp.anyOf) != null ? _a : mcp.type;
|
|
49
|
+
let isNullable = false;
|
|
50
|
+
let nonNullTypes;
|
|
51
|
+
if (Array.isArray(sourceType)) {
|
|
52
|
+
nonNullTypes = sourceType.filter(
|
|
53
|
+
(t) => getTypeFromArrayItem(t) !== "null"
|
|
54
|
+
);
|
|
55
|
+
isNullable = sourceType.some(
|
|
56
|
+
(t) => getTypeFromArrayItem(t) === "null"
|
|
57
|
+
);
|
|
58
|
+
if (nonNullTypes.length === 1) {
|
|
59
|
+
const nonNullType = nonNullTypes[0];
|
|
60
|
+
if (typeof nonNullType === "object") {
|
|
61
|
+
mcp = nonNullType;
|
|
62
|
+
} else {
|
|
63
|
+
const { type: _removed, anyOf: _removedAnyOf, ...rest } = mcp;
|
|
64
|
+
mcp = { ...rest, type: nonNullType };
|
|
65
|
+
}
|
|
66
|
+
} else if (nonNullTypes.length === 0 && isNullable) {
|
|
67
|
+
const { type: _removed, anyOf: _removedAnyOf, ...rest } = mcp;
|
|
68
|
+
mcp = { ...rest, type: "null" };
|
|
69
|
+
} else if (typeof mcp.anyOf === "undefined") {
|
|
70
|
+
const anyOfItems = mcp.type.map((t) => ({ type: t }));
|
|
71
|
+
const { type: _removed, ...rest } = mcp;
|
|
72
|
+
mcp = { ...rest, anyOf: anyOfItems };
|
|
45
73
|
}
|
|
46
74
|
}
|
|
47
75
|
if (!mcp.type) {
|
|
@@ -49,13 +77,25 @@ function toGeminiSchema(mcpSchema) {
|
|
|
49
77
|
mcp.type = "object";
|
|
50
78
|
} else if (mcp.items) {
|
|
51
79
|
mcp.type = "array";
|
|
80
|
+
} else if (isNullable) {
|
|
81
|
+
mcp.type = "null";
|
|
52
82
|
}
|
|
53
83
|
}
|
|
54
84
|
const geminiType = toGeminiType(mcp.type);
|
|
55
|
-
const geminiSchema = {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
85
|
+
const geminiSchema = {};
|
|
86
|
+
if (mcp.anyOf) {
|
|
87
|
+
geminiSchema.anyOf = mcp.anyOf.map(
|
|
88
|
+
(item) => recursiveConvert(item)
|
|
89
|
+
);
|
|
90
|
+
} else {
|
|
91
|
+
geminiSchema.type = geminiType;
|
|
92
|
+
}
|
|
93
|
+
if (mcp.description) {
|
|
94
|
+
geminiSchema.description = mcp.description;
|
|
95
|
+
}
|
|
96
|
+
if (isNullable && mcp.type !== "null") {
|
|
97
|
+
geminiSchema.nullable = true;
|
|
98
|
+
}
|
|
59
99
|
if (geminiType === Type.OBJECT) {
|
|
60
100
|
geminiSchema.properties = {};
|
|
61
101
|
if (mcp.properties) {
|
|
@@ -65,7 +105,9 @@ function toGeminiSchema(mcpSchema) {
|
|
|
65
105
|
);
|
|
66
106
|
}
|
|
67
107
|
}
|
|
68
|
-
|
|
108
|
+
if (mcp.required) {
|
|
109
|
+
geminiSchema.required = mcp.required;
|
|
110
|
+
}
|
|
69
111
|
} else if (geminiType === Type.ARRAY) {
|
|
70
112
|
if (mcp.items) {
|
|
71
113
|
geminiSchema.items = recursiveConvert(mcp.items);
|
package/dist/esm/version.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { AGENT_CARD_PATH, AgentCard, Message, MessageSendConfiguration, MessageSendParams, Task, TaskArtifactUpdateEvent, TaskStatusUpdateEvent } from '@a2a-js/sdk';
|
|
7
|
-
import { ClientFactory } from '@a2a-js/sdk/client';
|
|
7
|
+
import { Client, ClientFactory } from '@a2a-js/sdk/client';
|
|
8
8
|
import { BaseAgent, BaseAgentConfig } from '../agents/base_agent.js';
|
|
9
9
|
import { InvocationContext } from '../agents/invocation_context.js';
|
|
10
10
|
import { Event as AdkEvent } from '../events/event.js';
|
|
@@ -28,9 +28,13 @@ export type AfterA2ARequestCallback = (ctx: InvocationContext, resp: A2AStreamEv
|
|
|
28
28
|
*/
|
|
29
29
|
export interface RemoteA2AAgentConfig extends BaseAgentConfig {
|
|
30
30
|
/**
|
|
31
|
-
* Loaded AgentCard or URL to AgentCard
|
|
31
|
+
* Loaded AgentCard or URL to AgentCard.
|
|
32
32
|
*/
|
|
33
|
-
agentCard
|
|
33
|
+
agentCard?: AgentCard | string;
|
|
34
|
+
/**
|
|
35
|
+
* Optional pre-initialized Client for connection pooling.
|
|
36
|
+
*/
|
|
37
|
+
client?: Client;
|
|
34
38
|
/**
|
|
35
39
|
* Optional ClientFactory for creating the A2A Client.
|
|
36
40
|
*/
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
1
|
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __spreadValues = (a, b) => {
|
|
8
|
-
for (var prop in b || (b = {}))
|
|
9
|
-
if (__hasOwnProp.call(b, prop))
|
|
10
|
-
__defNormalProp(a, prop, b[prop]);
|
|
11
|
-
if (__getOwnPropSymbols)
|
|
12
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
13
|
-
if (__propIsEnum.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
}
|
|
16
|
-
return a;
|
|
17
|
-
};
|
|
18
2
|
var __await = function(promise, isYieldStar) {
|
|
19
3
|
this[0] = promise;
|
|
20
4
|
this[1] = isYieldStar;
|
|
@@ -59,17 +43,24 @@ class RemoteA2AAgent extends BaseAgent {
|
|
|
59
43
|
super(a2aConfig);
|
|
60
44
|
this.a2aConfig = a2aConfig;
|
|
61
45
|
this.isInitialized = false;
|
|
62
|
-
if (!a2aConfig.agentCard) {
|
|
63
|
-
throw new Error("AgentCard must be provided");
|
|
46
|
+
if (!a2aConfig.agentCard && !a2aConfig.client) {
|
|
47
|
+
throw new Error("Either AgentCard or Client must be provided");
|
|
64
48
|
}
|
|
65
49
|
}
|
|
66
50
|
async init() {
|
|
67
51
|
if (this.isInitialized) {
|
|
68
52
|
return;
|
|
69
53
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
if (this.a2aConfig.client) {
|
|
55
|
+
this.client = this.a2aConfig.client;
|
|
56
|
+
}
|
|
57
|
+
if (this.a2aConfig.agentCard) {
|
|
58
|
+
this.card = await resolveAgentCard(this.a2aConfig.agentCard);
|
|
59
|
+
if (!this.client) {
|
|
60
|
+
const factory = this.a2aConfig.clientFactory || new ClientFactory();
|
|
61
|
+
this.client = await factory.createFromAgentCard(this.card);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
73
64
|
this.isInitialized = true;
|
|
74
65
|
}
|
|
75
66
|
runAsyncImpl(context) {
|
|
@@ -106,11 +97,11 @@ class RemoteA2AAgent extends BaseAgent {
|
|
|
106
97
|
messageId: randomUUID(),
|
|
107
98
|
role: MessageRole.USER,
|
|
108
99
|
parts,
|
|
109
|
-
metadata:
|
|
100
|
+
metadata: getA2ASessionMetadata({
|
|
110
101
|
appName: context.session.appName,
|
|
111
102
|
userId: context.session.userId,
|
|
112
103
|
sessionId: context.session.id
|
|
113
|
-
})
|
|
104
|
+
})
|
|
114
105
|
};
|
|
115
106
|
if (taskId) message.taskId = taskId;
|
|
116
107
|
if (contextId) message.contextId = contextId;
|
|
@@ -124,7 +115,7 @@ class RemoteA2AAgent extends BaseAgent {
|
|
|
124
115
|
yield new __await(callback(context, params));
|
|
125
116
|
}
|
|
126
117
|
}
|
|
127
|
-
const useStreaming = ((_b = this.card.capabilities) == null ? void 0 : _b.streaming) !== false;
|
|
118
|
+
const useStreaming = this.card ? ((_b = this.card.capabilities) == null ? void 0 : _b.streaming) !== false : true;
|
|
128
119
|
if (useStreaming) {
|
|
129
120
|
try {
|
|
130
121
|
for (var iter = __forAwait(this.client.sendMessageStream(params)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
@@ -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;
|