@adcp/client 0.2.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/LICENSE +21 -0
- package/README.md +166 -0
- package/dist/lib/agents/index.generated.d.ts +147 -0
- package/dist/lib/agents/index.generated.d.ts.map +1 -0
- package/dist/lib/agents/index.generated.js +218 -0
- package/dist/lib/agents/index.generated.js.map +1 -0
- package/dist/lib/auth/index.d.ts +22 -0
- package/dist/lib/auth/index.d.ts.map +1 -0
- package/dist/lib/auth/index.js +73 -0
- package/dist/lib/auth/index.js.map +1 -0
- package/dist/lib/core/ADCPClient.d.ts +233 -0
- package/dist/lib/core/ADCPClient.d.ts.map +1 -0
- package/dist/lib/core/ADCPClient.js +287 -0
- package/dist/lib/core/ADCPClient.js.map +1 -0
- package/dist/lib/core/ADCPMultiAgentClient.d.ts +308 -0
- package/dist/lib/core/ADCPMultiAgentClient.d.ts.map +1 -0
- package/dist/lib/core/ADCPMultiAgentClient.js +468 -0
- package/dist/lib/core/ADCPMultiAgentClient.js.map +1 -0
- package/dist/lib/core/AgentClient.d.ts +124 -0
- package/dist/lib/core/AgentClient.d.ts.map +1 -0
- package/dist/lib/core/AgentClient.js +242 -0
- package/dist/lib/core/AgentClient.js.map +1 -0
- package/dist/lib/core/ConfigurationManager.d.ts +79 -0
- package/dist/lib/core/ConfigurationManager.d.ts.map +1 -0
- package/dist/lib/core/ConfigurationManager.js +254 -0
- package/dist/lib/core/ConfigurationManager.js.map +1 -0
- package/dist/lib/core/ConversationTypes.d.ts +242 -0
- package/dist/lib/core/ConversationTypes.d.ts.map +1 -0
- package/dist/lib/core/ConversationTypes.js +5 -0
- package/dist/lib/core/ConversationTypes.js.map +1 -0
- package/dist/lib/core/ProtocolResponseParser.d.ts +45 -0
- package/dist/lib/core/ProtocolResponseParser.d.ts.map +1 -0
- package/dist/lib/core/ProtocolResponseParser.js +82 -0
- package/dist/lib/core/ProtocolResponseParser.js.map +1 -0
- package/dist/lib/core/TaskExecutor.d.ts +108 -0
- package/dist/lib/core/TaskExecutor.d.ts.map +1 -0
- package/dist/lib/core/TaskExecutor.js +422 -0
- package/dist/lib/core/TaskExecutor.js.map +1 -0
- package/dist/lib/errors/index.d.ts +125 -0
- package/dist/lib/errors/index.d.ts.map +1 -0
- package/dist/lib/errors/index.js +211 -0
- package/dist/lib/errors/index.js.map +1 -0
- package/dist/lib/handlers/types.d.ts +119 -0
- package/dist/lib/handlers/types.d.ts.map +1 -0
- package/dist/lib/handlers/types.js +239 -0
- package/dist/lib/handlers/types.js.map +1 -0
- package/dist/lib/index.d.ts +51 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +122 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/protocols/a2a.d.ts +2 -0
- package/dist/lib/protocols/a2a.d.ts.map +1 -0
- package/dist/lib/protocols/a2a.js +70 -0
- package/dist/lib/protocols/a2a.js.map +1 -0
- package/dist/lib/protocols/index.d.ts +22 -0
- package/dist/lib/protocols/index.d.ts.map +1 -0
- package/dist/lib/protocols/index.js +47 -0
- package/dist/lib/protocols/index.js.map +1 -0
- package/dist/lib/protocols/mcp.d.ts +2 -0
- package/dist/lib/protocols/mcp.d.ts.map +1 -0
- package/dist/lib/protocols/mcp.js +127 -0
- package/dist/lib/protocols/mcp.js.map +1 -0
- package/dist/lib/storage/MemoryStorage.d.ts +93 -0
- package/dist/lib/storage/MemoryStorage.d.ts.map +1 -0
- package/dist/lib/storage/MemoryStorage.js +219 -0
- package/dist/lib/storage/MemoryStorage.js.map +1 -0
- package/dist/lib/storage/interfaces.d.ts +195 -0
- package/dist/lib/storage/interfaces.d.ts.map +1 -0
- package/dist/lib/storage/interfaces.js +5 -0
- package/dist/lib/storage/interfaces.js.map +1 -0
- package/dist/lib/types/adcp.d.ts +407 -0
- package/dist/lib/types/adcp.d.ts.map +1 -0
- package/dist/lib/types/adcp.js +5 -0
- package/dist/lib/types/adcp.js.map +1 -0
- package/dist/lib/types/core.generated.d.ts +469 -0
- package/dist/lib/types/core.generated.d.ts.map +1 -0
- package/dist/lib/types/core.generated.js +5 -0
- package/dist/lib/types/core.generated.js.map +1 -0
- package/dist/lib/types/index.d.ts +3 -0
- package/dist/lib/types/index.d.ts.map +1 -0
- package/dist/lib/types/index.js +19 -0
- package/dist/lib/types/index.js.map +1 -0
- package/dist/lib/types/tools.generated.d.ts +1674 -0
- package/dist/lib/types/tools.generated.d.ts.map +1 -0
- package/dist/lib/types/tools.generated.js +8 -0
- package/dist/lib/types/tools.generated.js.map +1 -0
- package/dist/lib/utils/index.d.ts +25 -0
- package/dist/lib/utils/index.d.ts.map +1 -0
- package/dist/lib/utils/index.js +109 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/validation/index.d.ts +29 -0
- package/dist/lib/validation/index.d.ts.map +1 -0
- package/dist/lib/validation/index.js +186 -0
- package/dist/lib/validation/index.js.map +1 -0
- package/dist/lib/version.d.ts +22 -0
- package/dist/lib/version.d.ts.map +1 -0
- package/dist/lib/version.js +32 -0
- package/dist/lib/version.js.map +1 -0
- package/package.json +108 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// AdCP Client Library - Main Exports
|
|
3
|
+
// A comprehensive type-safe client library for the AdContext Protocol
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.AdCPClient = exports.AgentCollection = exports.Agent = exports.getStandardFormats = exports.InputRequiredError = exports.extractErrorInfo = exports.isErrorOfType = exports.isADCPError = exports.ConfigurationError = exports.InvalidContextError = exports.MissingInputHandlerError = exports.ADCPValidationError = exports.ProtocolError = exports.UnsupportedTaskError = exports.AgentNotFoundError = exports.TaskAbortedError = exports.DeferredTaskError = exports.MaxClarificationError = exports.TaskTimeoutError = exports.ADCPError = exports.createMemoryStorageConfig = exports.createMemoryStorage = exports.MemoryStorage = exports.ADCP_STATUS = exports.responseParser = exports.ProtocolResponseParser = exports.TaskExecutor = exports.ConfigurationManager = exports.createADCPMultiAgentClient = exports.NewAgentCollection = exports.ADCPMultiAgentClient = exports.AgentClient = exports.createADCPClient = exports.ADCPClient = void 0;
|
|
20
|
+
exports.createAdCPClient = createAdCPClient;
|
|
21
|
+
exports.createAdCPClientFromEnv = createAdCPClientFromEnv;
|
|
22
|
+
// ====== CORE CONVERSATION-AWARE CLIENTS ======
|
|
23
|
+
// New conversation-aware clients with input handler pattern
|
|
24
|
+
var ADCPClient_1 = require("./core/ADCPClient");
|
|
25
|
+
Object.defineProperty(exports, "ADCPClient", { enumerable: true, get: function () { return ADCPClient_1.ADCPClient; } });
|
|
26
|
+
Object.defineProperty(exports, "createADCPClient", { enumerable: true, get: function () { return ADCPClient_1.createADCPClient; } });
|
|
27
|
+
var AgentClient_1 = require("./core/AgentClient");
|
|
28
|
+
Object.defineProperty(exports, "AgentClient", { enumerable: true, get: function () { return AgentClient_1.AgentClient; } });
|
|
29
|
+
var ADCPMultiAgentClient_1 = require("./core/ADCPMultiAgentClient");
|
|
30
|
+
Object.defineProperty(exports, "ADCPMultiAgentClient", { enumerable: true, get: function () { return ADCPMultiAgentClient_1.ADCPMultiAgentClient; } });
|
|
31
|
+
Object.defineProperty(exports, "NewAgentCollection", { enumerable: true, get: function () { return ADCPMultiAgentClient_1.AgentCollection; } });
|
|
32
|
+
Object.defineProperty(exports, "createADCPMultiAgentClient", { enumerable: true, get: function () { return ADCPMultiAgentClient_1.createADCPMultiAgentClient; } });
|
|
33
|
+
var ConfigurationManager_1 = require("./core/ConfigurationManager");
|
|
34
|
+
Object.defineProperty(exports, "ConfigurationManager", { enumerable: true, get: function () { return ConfigurationManager_1.ConfigurationManager; } });
|
|
35
|
+
var TaskExecutor_1 = require("./core/TaskExecutor");
|
|
36
|
+
Object.defineProperty(exports, "TaskExecutor", { enumerable: true, get: function () { return TaskExecutor_1.TaskExecutor; } });
|
|
37
|
+
var ProtocolResponseParser_1 = require("./core/ProtocolResponseParser");
|
|
38
|
+
Object.defineProperty(exports, "ProtocolResponseParser", { enumerable: true, get: function () { return ProtocolResponseParser_1.ProtocolResponseParser; } });
|
|
39
|
+
Object.defineProperty(exports, "responseParser", { enumerable: true, get: function () { return ProtocolResponseParser_1.responseParser; } });
|
|
40
|
+
Object.defineProperty(exports, "ADCP_STATUS", { enumerable: true, get: function () { return ProtocolResponseParser_1.ADCP_STATUS; } });
|
|
41
|
+
// ====== INPUT HANDLERS ======
|
|
42
|
+
__exportStar(require("./handlers/types"), exports);
|
|
43
|
+
var MemoryStorage_1 = require("./storage/MemoryStorage");
|
|
44
|
+
Object.defineProperty(exports, "MemoryStorage", { enumerable: true, get: function () { return MemoryStorage_1.MemoryStorage; } });
|
|
45
|
+
Object.defineProperty(exports, "createMemoryStorage", { enumerable: true, get: function () { return MemoryStorage_1.createMemoryStorage; } });
|
|
46
|
+
Object.defineProperty(exports, "createMemoryStorageConfig", { enumerable: true, get: function () { return MemoryStorage_1.createMemoryStorageConfig; } });
|
|
47
|
+
// ====== ERROR CLASSES ======
|
|
48
|
+
var errors_1 = require("./errors");
|
|
49
|
+
Object.defineProperty(exports, "ADCPError", { enumerable: true, get: function () { return errors_1.ADCPError; } });
|
|
50
|
+
Object.defineProperty(exports, "TaskTimeoutError", { enumerable: true, get: function () { return errors_1.TaskTimeoutError; } });
|
|
51
|
+
Object.defineProperty(exports, "MaxClarificationError", { enumerable: true, get: function () { return errors_1.MaxClarificationError; } });
|
|
52
|
+
Object.defineProperty(exports, "DeferredTaskError", { enumerable: true, get: function () { return errors_1.DeferredTaskError; } });
|
|
53
|
+
Object.defineProperty(exports, "TaskAbortedError", { enumerable: true, get: function () { return errors_1.TaskAbortedError; } });
|
|
54
|
+
Object.defineProperty(exports, "AgentNotFoundError", { enumerable: true, get: function () { return errors_1.AgentNotFoundError; } });
|
|
55
|
+
Object.defineProperty(exports, "UnsupportedTaskError", { enumerable: true, get: function () { return errors_1.UnsupportedTaskError; } });
|
|
56
|
+
Object.defineProperty(exports, "ProtocolError", { enumerable: true, get: function () { return errors_1.ProtocolError; } });
|
|
57
|
+
Object.defineProperty(exports, "ADCPValidationError", { enumerable: true, get: function () { return errors_1.ValidationError; } });
|
|
58
|
+
Object.defineProperty(exports, "MissingInputHandlerError", { enumerable: true, get: function () { return errors_1.MissingInputHandlerError; } });
|
|
59
|
+
Object.defineProperty(exports, "InvalidContextError", { enumerable: true, get: function () { return errors_1.InvalidContextError; } });
|
|
60
|
+
Object.defineProperty(exports, "ConfigurationError", { enumerable: true, get: function () { return errors_1.ConfigurationError; } });
|
|
61
|
+
Object.defineProperty(exports, "isADCPError", { enumerable: true, get: function () { return errors_1.isADCPError; } });
|
|
62
|
+
Object.defineProperty(exports, "isErrorOfType", { enumerable: true, get: function () { return errors_1.isErrorOfType; } });
|
|
63
|
+
Object.defineProperty(exports, "extractErrorInfo", { enumerable: true, get: function () { return errors_1.extractErrorInfo; } });
|
|
64
|
+
var TaskExecutor_2 = require("./core/TaskExecutor");
|
|
65
|
+
Object.defineProperty(exports, "InputRequiredError", { enumerable: true, get: function () { return TaskExecutor_2.InputRequiredError; } });
|
|
66
|
+
// ====== CORE TYPES ======
|
|
67
|
+
__exportStar(require("./types"), exports);
|
|
68
|
+
// ====== PROTOCOL CLIENTS ======
|
|
69
|
+
__exportStar(require("./protocols"), exports);
|
|
70
|
+
// ====== AUTHENTICATION ======
|
|
71
|
+
__exportStar(require("./auth"), exports);
|
|
72
|
+
// ====== VALIDATION ======
|
|
73
|
+
__exportStar(require("./validation"), exports);
|
|
74
|
+
// ====== UTILITIES ======
|
|
75
|
+
__exportStar(require("./utils"), exports);
|
|
76
|
+
var utils_1 = require("./utils");
|
|
77
|
+
Object.defineProperty(exports, "getStandardFormats", { enumerable: true, get: function () { return utils_1.getStandardFormats; } });
|
|
78
|
+
// ====== LEGACY AGENT CLASSES ======
|
|
79
|
+
// Keep existing generated agent classes for backward compatibility
|
|
80
|
+
var index_generated_1 = require("./agents/index.generated");
|
|
81
|
+
Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return index_generated_1.Agent; } });
|
|
82
|
+
Object.defineProperty(exports, "AgentCollection", { enumerable: true, get: function () { return index_generated_1.AgentCollection; } });
|
|
83
|
+
const ADCPMultiAgentClient_2 = require("./core/ADCPMultiAgentClient");
|
|
84
|
+
/**
|
|
85
|
+
* Legacy AdCPClient for backward compatibility - now redirects to ADCPMultiAgentClient
|
|
86
|
+
* @deprecated Use ADCPMultiAgentClient instead for new code
|
|
87
|
+
*/
|
|
88
|
+
class AdCPClient {
|
|
89
|
+
multiClient;
|
|
90
|
+
constructor(agents) {
|
|
91
|
+
this.multiClient = new ADCPMultiAgentClient_2.ADCPMultiAgentClient(agents || []);
|
|
92
|
+
}
|
|
93
|
+
agent(id) { return this.multiClient.agent(id); }
|
|
94
|
+
agents(ids) { return this.multiClient.agents(ids); }
|
|
95
|
+
allAgents() { return this.multiClient.allAgents(); }
|
|
96
|
+
addAgent(agent) { this.multiClient.addAgent(agent); }
|
|
97
|
+
getAgents() { return this.multiClient.getAgentConfigs(); }
|
|
98
|
+
get agentCount() { return this.multiClient.agentCount; }
|
|
99
|
+
get agentIds() { return this.multiClient.getAgentIds(); }
|
|
100
|
+
getStandardFormats() {
|
|
101
|
+
const { getStandardFormats } = require('./utils');
|
|
102
|
+
return getStandardFormats();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.AdCPClient = AdCPClient;
|
|
106
|
+
// Legacy configuration manager maintained for backward compatibility
|
|
107
|
+
// The enhanced ConfigurationManager is exported above
|
|
108
|
+
/**
|
|
109
|
+
* Legacy createAdCPClient function for backward compatibility
|
|
110
|
+
* @deprecated Use new ADCPMultiAgentClient constructor instead
|
|
111
|
+
*/
|
|
112
|
+
function createAdCPClient(agents) {
|
|
113
|
+
return new AdCPClient(agents);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Load agents from environment and create multi-agent client
|
|
117
|
+
* @deprecated Use ADCPMultiAgentClient.fromEnv() instead
|
|
118
|
+
*/
|
|
119
|
+
function createAdCPClientFromEnv() {
|
|
120
|
+
return ADCPMultiAgentClient_2.ADCPMultiAgentClient.fromEnv();
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";AAAA,qCAAqC;AACrC,sEAAsE;;;;;;;;;;;;;;;;;AAuItE,4CAEC;AAMD,0DAEC;AA/ID,gDAAgD;AAChD,4DAA4D;AAC5D,gDAAiE;AAAxD,wGAAA,UAAU,OAAA;AAAE,8GAAA,gBAAgB,OAAA;AAErC,kDAAiD;AAAxC,0GAAA,WAAW,OAAA;AACpB,oEAAsI;AAA7H,4HAAA,oBAAoB,OAAA;AAAE,0HAAA,eAAe,OAAsB;AAAE,kIAAA,0BAA0B,OAAA;AAChG,oEAAmE;AAA1D,4HAAA,oBAAoB,OAAA;AAC7B,oDAAmD;AAA1C,4GAAA,YAAY,OAAA;AACrB,wEAAqH;AAA5G,gIAAA,sBAAsB,OAAA;AAAE,wHAAA,cAAc,OAAA;AAAE,qHAAA,WA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|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callA2ATool = callA2ATool;
|
|
4
|
+
// Official A2A client implementation - NO FALLBACKS
|
|
5
|
+
const clientModule = require('@a2a-js/sdk/client');
|
|
6
|
+
const A2AClient = clientModule.A2AClient;
|
|
7
|
+
if (!A2AClient) {
|
|
8
|
+
throw new Error('A2A SDK client is required. Please install @a2a-js/sdk');
|
|
9
|
+
}
|
|
10
|
+
async function callA2ATool(agentUrl, toolName, parameters, authToken, debugLogs = []) {
|
|
11
|
+
// Create authenticated fetch if needed
|
|
12
|
+
const fetchImpl = authToken ?
|
|
13
|
+
async (url, options) => {
|
|
14
|
+
return fetch(url, {
|
|
15
|
+
...options,
|
|
16
|
+
headers: {
|
|
17
|
+
'Authorization': `Bearer ${authToken}`,
|
|
18
|
+
...(options?.headers || {})
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
} : undefined;
|
|
22
|
+
// Create A2A client using the recommended fromCardUrl method
|
|
23
|
+
// Ensure the URL points to the agent card endpoint
|
|
24
|
+
const cardUrl = agentUrl.endsWith('/.well-known/agent-card.json')
|
|
25
|
+
? agentUrl
|
|
26
|
+
: agentUrl.replace(/\/$/, '') + '/.well-known/agent-card.json';
|
|
27
|
+
const a2aClient = await A2AClient.fromCardUrl(cardUrl, {
|
|
28
|
+
fetchImpl
|
|
29
|
+
});
|
|
30
|
+
// Build request payload following AdCP A2A spec
|
|
31
|
+
const requestPayload = {
|
|
32
|
+
message: {
|
|
33
|
+
messageId: `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
34
|
+
role: "user",
|
|
35
|
+
parts: [{
|
|
36
|
+
kind: "data", // A2A spec uses "kind", not "type"
|
|
37
|
+
data: {
|
|
38
|
+
skill: toolName,
|
|
39
|
+
parameters
|
|
40
|
+
}
|
|
41
|
+
}]
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
// Add debug log for A2A call
|
|
45
|
+
const payloadSize = JSON.stringify(requestPayload).length;
|
|
46
|
+
debugLogs.push({
|
|
47
|
+
type: 'info',
|
|
48
|
+
message: `A2A: Calling skill ${toolName} with parameters: ${JSON.stringify(parameters)}. Payload size: ${payloadSize} bytes`,
|
|
49
|
+
timestamp: new Date().toISOString(),
|
|
50
|
+
payloadSize,
|
|
51
|
+
actualPayload: requestPayload
|
|
52
|
+
});
|
|
53
|
+
// Send message using A2A protocol
|
|
54
|
+
const messageResponse = await a2aClient.sendMessage(requestPayload);
|
|
55
|
+
// Add debug log for A2A response
|
|
56
|
+
debugLogs.push({
|
|
57
|
+
type: messageResponse?.error ? 'error' : 'success',
|
|
58
|
+
message: `A2A: Response received (${messageResponse?.error ? 'error' : 'success'})`,
|
|
59
|
+
timestamp: new Date().toISOString(),
|
|
60
|
+
response: messageResponse
|
|
61
|
+
});
|
|
62
|
+
// Check for JSON-RPC error in response
|
|
63
|
+
if (messageResponse?.error || messageResponse?.result?.error) {
|
|
64
|
+
const errorObj = messageResponse.error || messageResponse.result?.error;
|
|
65
|
+
const errorMessage = errorObj.message || JSON.stringify(errorObj);
|
|
66
|
+
throw new Error(`A2A agent returned error: ${errorMessage}`);
|
|
67
|
+
}
|
|
68
|
+
return messageResponse;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=a2a.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a2a.js","sourceRoot":"","sources":["../../../src/lib/protocols/a2a.ts"],"names":[],"mappings":";;AAQA,kCAyEC;AAjFD,oDAAoD;AACpD,MAAM,YAAY,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACnD,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC;AAEzC,IAAI,CAAC,SAAS,EAAE,CAAC;IACf,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;AAC5E,CAAC;AAEM,KAAK,UAAU,WAAW,CAC/B,QAAgB,EAChB,QAAgB,EAChB,UAA+B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EAAE,sBAAsB,QAAQ,qBAAqB,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,mBAAmB,WAAW,QAAQ;QAC5H,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,WAAW;QACX,aAAa,EAAE,cAAc;KAC9B,CAAC,CAAC;IAEH,kCAAkC;IAClC,MAAM,eAAe,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IAEpE,iCAAiC;IACjC,SAAS,CAAC,IAAI,CAAC;QACb,IAAI,EAAE,eAAe,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;QAClD,OAAO,EAAE,2BAA2B,eAAe,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,GAAG;QACnF,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,QAAQ,EAAE,eAAe;KAC1B,CAAC,CAAC;IAEH,uCAAuC;IACvC,IAAI,eAAe,EAAE,KAAK,IAAI,eAAe,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAC7D,MAAM,QAAQ,GAAG,eAAe,CAAC,KAAK,IAAI,eAAe,CAAC,MAAM,EAAE,KAAK,CAAC;QACxE,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAClE,MAAM,IAAI,KAAK,CAAC,6BAA6B,YAAY,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { callMCPTool } from './mcp';
|
|
2
|
+
export { callA2ATool } from './a2a';
|
|
3
|
+
import type { AgentConfig } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Universal protocol client - automatically routes to the correct protocol implementation
|
|
6
|
+
*/
|
|
7
|
+
export declare class ProtocolClient {
|
|
8
|
+
/**
|
|
9
|
+
* Call a tool on an agent using the appropriate protocol
|
|
10
|
+
*/
|
|
11
|
+
static callTool(agent: AgentConfig, toolName: string, args: Record<string, any>, debugLogs?: any[]): Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Simple factory functions for protocol-specific clients
|
|
15
|
+
*/
|
|
16
|
+
export declare const createMCPClient: (agentUrl: string, authToken?: string) => {
|
|
17
|
+
callTool: (toolName: string, args: Record<string, any>, debugLogs?: any[]) => Promise<any>;
|
|
18
|
+
};
|
|
19
|
+
export declare const createA2AClient: (agentUrl: string, authToken?: string) => {
|
|
20
|
+
callTool: (toolName: string, parameters: Record<string, any>, debugLogs?: any[]) => Promise<any>;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/protocols/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAIpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAI5C;;GAEG;AACH,qBAAa,cAAc;IACzB;;OAEG;WACU,QAAQ,CACnB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,SAAS,GAAE,GAAG,EAAO,GACpB,OAAO,CAAC,GAAG,CAAC;CAyBhB;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,YAAY,MAAM;yBAC7C,MAAM,QAAQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,cAAc,GAAG,EAAE;CAEzE,CAAC;AAEH,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,YAAY,MAAM;yBAC7C,MAAM,cAAc,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,cAAc,GAAG,EAAE;CAE/E,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createA2AClient = exports.createMCPClient = exports.ProtocolClient = exports.callA2ATool = exports.callMCPTool = void 0;
|
|
4
|
+
// Unified Protocol Interface for AdCP
|
|
5
|
+
var mcp_1 = require("./mcp");
|
|
6
|
+
Object.defineProperty(exports, "callMCPTool", { enumerable: true, get: function () { return mcp_1.callMCPTool; } });
|
|
7
|
+
var a2a_1 = require("./a2a");
|
|
8
|
+
Object.defineProperty(exports, "callA2ATool", { enumerable: true, get: function () { return a2a_1.callA2ATool; } });
|
|
9
|
+
const mcp_2 = require("./mcp");
|
|
10
|
+
const a2a_2 = require("./a2a");
|
|
11
|
+
const auth_1 = require("../auth");
|
|
12
|
+
const validation_1 = require("../validation");
|
|
13
|
+
/**
|
|
14
|
+
* Universal protocol client - automatically routes to the correct protocol implementation
|
|
15
|
+
*/
|
|
16
|
+
class ProtocolClient {
|
|
17
|
+
/**
|
|
18
|
+
* Call a tool on an agent using the appropriate protocol
|
|
19
|
+
*/
|
|
20
|
+
static async callTool(agent, toolName, args, debugLogs = []) {
|
|
21
|
+
(0, validation_1.validateAgentUrl)(agent.agent_uri);
|
|
22
|
+
const authToken = (0, auth_1.getAuthToken)(agent);
|
|
23
|
+
if (agent.protocol === 'mcp') {
|
|
24
|
+
return (0, mcp_2.callMCPTool)(agent.agent_uri, toolName, args, authToken, debugLogs);
|
|
25
|
+
}
|
|
26
|
+
else if (agent.protocol === 'a2a') {
|
|
27
|
+
return (0, a2a_2.callA2ATool)(agent.agent_uri, toolName, args, // This maps to 'parameters' in callA2ATool
|
|
28
|
+
authToken, debugLogs);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
throw new Error(`Unsupported protocol: ${agent.protocol}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ProtocolClient = ProtocolClient;
|
|
36
|
+
/**
|
|
37
|
+
* Simple factory functions for protocol-specific clients
|
|
38
|
+
*/
|
|
39
|
+
const createMCPClient = (agentUrl, authToken) => ({
|
|
40
|
+
callTool: (toolName, args, debugLogs) => (0, mcp_2.callMCPTool)(agentUrl, toolName, args, authToken, debugLogs)
|
|
41
|
+
});
|
|
42
|
+
exports.createMCPClient = createMCPClient;
|
|
43
|
+
const createA2AClient = (agentUrl, authToken) => ({
|
|
44
|
+
callTool: (toolName, parameters, debugLogs) => (0, a2a_2.callA2ATool)(agentUrl, toolName, parameters, authToken, debugLogs)
|
|
45
|
+
});
|
|
46
|
+
exports.createA2AClient = createA2AClient;
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/protocols/index.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACtC,6BAAoC;AAA3B,kGAAA,WAAW,OAAA;AACpB,6BAAoC;AAA3B,kGAAA,WAAW,OAAA;AAEpB,+BAAoC;AACpC,+BAAoC;AAEpC,kCAAuC;AACvC,8CAAiD;AAEjD;;GAEG;AACH,MAAa,cAAc;IACzB;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,QAAQ,CACnB,KAAkB,EAClB,QAAgB,EAChB,IAAyB,EACzB,YAAmB,EAAE;QAErB,IAAA,6BAAgB,EAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAElC,MAAM,SAAS,GAAG,IAAA,mBAAY,EAAC,KAAK,CAAC,CAAC;QAEtC,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;YAC7B,OAAO,IAAA,iBAAW,EAChB,KAAK,CAAC,SAAS,EACf,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,SAAS,CACV,CAAC;QACJ,CAAC;aAAM,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;YACpC,OAAO,IAAA,iBAAW,EAChB,KAAK,CAAC,SAAS,EACf,QAAQ,EACR,IAAI,EAAE,2CAA2C;YACjD,SAAS,EACT,SAAS,CACV,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,yBAAyB,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;CACF;AAlCD,wCAkCC;AAED;;GAEG;AACI,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAE,SAAkB,EAAE,EAAE,CAAC,CAAC;IACxE,QAAQ,EAAE,CAAC,QAAgB,EAAE,IAAyB,EAAE,SAAiB,EAAE,EAAE,CAC3E,IAAA,iBAAW,EAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC;CAC9D,CAAC,CAAC;AAHU,QAAA,eAAe,mBAGzB;AAEI,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAE,SAAkB,EAAE,EAAE,CAAC,CAAC;IACxE,QAAQ,EAAE,CAAC,QAAgB,EAAE,UAA+B,EAAE,SAAiB,EAAE,EAAE,CACjF,IAAA,iBAAW,EAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,CAAC;CACpE,CAAC,CAAC;AAHU,QAAA,eAAe,mBAGzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../../src/lib/protocols/mcp.ts"],"names":[],"mappings":"AAMA,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,GAAG,EACT,SAAS,CAAC,EAAE,MAAM,EAClB,SAAS,GAAE,GAAG,EAAO,GACpB,OAAO,CAAC,GAAG,CAAC,CAgId"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callMCPTool = callMCPTool;
|
|
4
|
+
// Official MCP client implementation using HTTP streaming transport with SSE fallback
|
|
5
|
+
const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
|
|
6
|
+
const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
7
|
+
const sse_js_1 = require("@modelcontextprotocol/sdk/client/sse.js");
|
|
8
|
+
const auth_1 = require("../auth");
|
|
9
|
+
async function callMCPTool(agentUrl, toolName, args, authToken, debugLogs = []) {
|
|
10
|
+
let mcpClient = undefined;
|
|
11
|
+
const baseUrl = new URL(agentUrl);
|
|
12
|
+
// Prepare auth headers for StreamableHTTP transport
|
|
13
|
+
const requestInit = {};
|
|
14
|
+
if (authToken) {
|
|
15
|
+
requestInit.headers = (0, auth_1.createMCPAuthHeaders)(authToken);
|
|
16
|
+
// Add to debug logs
|
|
17
|
+
debugLogs.push({
|
|
18
|
+
type: 'info',
|
|
19
|
+
message: `MCP: Auth token provided (${authToken.substring(0, 10)}...)`,
|
|
20
|
+
timestamp: new Date().toISOString()
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
// First, try to connect using StreamableHTTPClientTransport
|
|
25
|
+
debugLogs.push({
|
|
26
|
+
type: 'info',
|
|
27
|
+
message: `MCP: Attempting StreamableHTTP connection to ${baseUrl}`,
|
|
28
|
+
timestamp: new Date().toISOString()
|
|
29
|
+
});
|
|
30
|
+
mcpClient = new index_js_1.Client({
|
|
31
|
+
name: 'AdCP-Testing-Framework',
|
|
32
|
+
version: '1.0.0'
|
|
33
|
+
});
|
|
34
|
+
// Use the SDK with proper header authentication
|
|
35
|
+
const transport = new streamableHttp_js_1.StreamableHTTPClientTransport(baseUrl, {
|
|
36
|
+
requestInit
|
|
37
|
+
});
|
|
38
|
+
await mcpClient.connect(transport);
|
|
39
|
+
debugLogs.push({
|
|
40
|
+
type: 'success',
|
|
41
|
+
message: 'MCP: Connected using StreamableHTTP transport',
|
|
42
|
+
timestamp: new Date().toISOString()
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
// Capture the connection error
|
|
47
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
48
|
+
debugLogs.push({
|
|
49
|
+
type: 'error',
|
|
50
|
+
message: `MCP: StreamableHTTP connection failed: ${errorMessage}`,
|
|
51
|
+
timestamp: new Date().toISOString(),
|
|
52
|
+
error: error
|
|
53
|
+
});
|
|
54
|
+
// If StreamableHTTP fails, fall back to SSE transport
|
|
55
|
+
debugLogs.push({
|
|
56
|
+
type: 'info',
|
|
57
|
+
message: 'MCP: Falling back to SSE transport',
|
|
58
|
+
timestamp: new Date().toISOString()
|
|
59
|
+
});
|
|
60
|
+
mcpClient = new index_js_1.Client({
|
|
61
|
+
name: 'AdCP-Testing-Framework',
|
|
62
|
+
version: '1.0.0'
|
|
63
|
+
});
|
|
64
|
+
// For SSE fallback, add auth to URL (if SSE transport supports it)
|
|
65
|
+
if (authToken) {
|
|
66
|
+
baseUrl.searchParams.set('auth', authToken);
|
|
67
|
+
}
|
|
68
|
+
const sseTransport = new sse_js_1.SSEClientTransport(baseUrl);
|
|
69
|
+
await mcpClient.connect(sseTransport);
|
|
70
|
+
debugLogs.push({
|
|
71
|
+
type: 'success',
|
|
72
|
+
message: 'MCP: Connected using SSE transport',
|
|
73
|
+
timestamp: new Date().toISOString()
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
// Call the tool using official MCP client
|
|
78
|
+
debugLogs.push({
|
|
79
|
+
type: 'info',
|
|
80
|
+
message: `MCP: Calling tool ${toolName} with args: ${JSON.stringify(args)}`,
|
|
81
|
+
timestamp: new Date().toISOString()
|
|
82
|
+
});
|
|
83
|
+
const response = await mcpClient.callTool({
|
|
84
|
+
name: toolName,
|
|
85
|
+
arguments: args
|
|
86
|
+
});
|
|
87
|
+
debugLogs.push({
|
|
88
|
+
type: response?.isError ? 'error' : 'success',
|
|
89
|
+
message: `MCP: Tool response received (${response?.isError ? 'error' : 'success'})`,
|
|
90
|
+
timestamp: new Date().toISOString(),
|
|
91
|
+
response: response
|
|
92
|
+
});
|
|
93
|
+
return response;
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
// Capture tool call errors (including timeouts)
|
|
97
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
98
|
+
debugLogs.push({
|
|
99
|
+
type: 'error',
|
|
100
|
+
message: `MCP: Tool call failed: ${errorMessage}`,
|
|
101
|
+
timestamp: new Date().toISOString(),
|
|
102
|
+
error: error
|
|
103
|
+
});
|
|
104
|
+
throw error; // Re-throw to maintain error handling
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
// Always close the client properly
|
|
108
|
+
if (mcpClient) {
|
|
109
|
+
try {
|
|
110
|
+
await mcpClient.close();
|
|
111
|
+
debugLogs.push({
|
|
112
|
+
type: 'info',
|
|
113
|
+
message: 'MCP: Client connection closed',
|
|
114
|
+
timestamp: new Date().toISOString()
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
catch (closeError) {
|
|
118
|
+
debugLogs.push({
|
|
119
|
+
type: 'warning',
|
|
120
|
+
message: `MCP: Error closing client: ${closeError}`,
|
|
121
|
+
timestamp: new Date().toISOString()
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../../src/lib/protocols/mcp.ts"],"names":[],"mappings":";;AAMA,kCAsIC;AA5ID,sFAAsF;AACtF,wEAAgF;AAChF,0FAAmG;AACnG,oEAA6E;AAC7E,kCAA+C;AAExC,KAAK,UAAU,WAAW,CAC/B,QAAgB,EAChB,QAAgB,EAChB,IAAS,EACT,SAAkB,EAClB,YAAmB,EAAE;IAErB,IAAI,SAAS,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EAAE;iBACpC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Storage, BatchStorage, PatternStorage } from './interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* In-memory storage implementation with TTL support
|
|
4
|
+
*
|
|
5
|
+
* This is the default storage used when no external storage is configured.
|
|
6
|
+
* Features:
|
|
7
|
+
* - TTL support with automatic cleanup
|
|
8
|
+
* - Pattern matching
|
|
9
|
+
* - Batch operations
|
|
10
|
+
* - Memory-efficient (garbage collection of expired items)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const storage = new MemoryStorage<string>();
|
|
15
|
+
* await storage.set('key', 'value', 60); // TTL of 60 seconds
|
|
16
|
+
* const value = await storage.get('key');
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare class MemoryStorage<T> implements Storage<T>, BatchStorage<T>, PatternStorage<T> {
|
|
20
|
+
private options;
|
|
21
|
+
private store;
|
|
22
|
+
private cleanupInterval?;
|
|
23
|
+
private lastCleanup;
|
|
24
|
+
constructor(options?: {
|
|
25
|
+
/** How often to clean up expired items (ms), default 5 minutes */
|
|
26
|
+
cleanupIntervalMs?: number;
|
|
27
|
+
/** Maximum items to store before forcing cleanup, default 10000 */
|
|
28
|
+
maxItems?: number;
|
|
29
|
+
/** Whether to enable automatic cleanup, default true */
|
|
30
|
+
autoCleanup?: boolean;
|
|
31
|
+
});
|
|
32
|
+
get(key: string): Promise<T | undefined>;
|
|
33
|
+
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
34
|
+
delete(key: string): Promise<void>;
|
|
35
|
+
has(key: string): Promise<boolean>;
|
|
36
|
+
clear(): Promise<void>;
|
|
37
|
+
keys(): Promise<string[]>;
|
|
38
|
+
size(): Promise<number>;
|
|
39
|
+
mget(keys: string[]): Promise<(T | undefined)[]>;
|
|
40
|
+
mset(entries: Array<{
|
|
41
|
+
key: string;
|
|
42
|
+
value: T;
|
|
43
|
+
ttl?: number;
|
|
44
|
+
}>): Promise<void>;
|
|
45
|
+
mdel(keys: string[]): Promise<number>;
|
|
46
|
+
scan(pattern: string): Promise<string[]>;
|
|
47
|
+
deletePattern(pattern: string): Promise<number>;
|
|
48
|
+
/**
|
|
49
|
+
* Manually trigger cleanup of expired items
|
|
50
|
+
*/
|
|
51
|
+
cleanupExpired(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Get storage statistics
|
|
54
|
+
*/
|
|
55
|
+
getStats(): {
|
|
56
|
+
totalItems: number;
|
|
57
|
+
expiredItems: number;
|
|
58
|
+
memoryUsage: number;
|
|
59
|
+
lastCleanup: number;
|
|
60
|
+
oldestItem?: number;
|
|
61
|
+
newestItem?: number;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Estimate memory usage (rough approximation)
|
|
65
|
+
*/
|
|
66
|
+
private estimateMemoryUsage;
|
|
67
|
+
/**
|
|
68
|
+
* Convert glob-style pattern to regex
|
|
69
|
+
*/
|
|
70
|
+
private patternToRegex;
|
|
71
|
+
/**
|
|
72
|
+
* Destroy the storage and cleanup resources
|
|
73
|
+
*/
|
|
74
|
+
destroy(): void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Factory function to create a memory storage instance
|
|
78
|
+
*/
|
|
79
|
+
export declare function createMemoryStorage<T>(options?: {
|
|
80
|
+
cleanupIntervalMs?: number;
|
|
81
|
+
maxItems?: number;
|
|
82
|
+
autoCleanup?: boolean;
|
|
83
|
+
}): MemoryStorage<T>;
|
|
84
|
+
/**
|
|
85
|
+
* Create a complete storage configuration using memory storage
|
|
86
|
+
*/
|
|
87
|
+
export declare function createMemoryStorageConfig(): {
|
|
88
|
+
capabilities: MemoryStorage<any>;
|
|
89
|
+
conversations: MemoryStorage<any>;
|
|
90
|
+
tokens: MemoryStorage<any>;
|
|
91
|
+
debugLogs: MemoryStorage<any>;
|
|
92
|
+
};
|
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