@dainprotocol/service-sdk 2.0.77 → 2.0.79
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/client/api-sdk.d.ts +5 -42
- package/dist/client/api-sdk.js +130 -261
- package/dist/client/api-sdk.js.map +1 -1
- package/dist/client/client-auth.d.ts +1 -69
- package/dist/client/client-auth.js +26 -105
- package/dist/client/client-auth.js.map +1 -1
- package/dist/client/client.d.ts +25 -116
- package/dist/client/client.js +157 -758
- package/dist/client/client.js.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.js +9 -14
- package/dist/client/types.js.map +1 -1
- package/dist/extensions/telegram-oauth.d.ts +6 -2
- package/dist/extensions/telegram-oauth.js +30 -57
- package/dist/extensions/telegram-oauth.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -26
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +2 -0
- package/dist/lib/convertToVercelTool.d.ts +11 -3
- package/dist/lib/convertToVercelTool.js +0 -1
- package/dist/lib/convertToVercelTool.js.map +1 -1
- package/dist/lib/payments/index.d.ts +14 -23
- package/dist/lib/payments/index.js +33 -47
- package/dist/lib/payments/index.js.map +1 -1
- package/dist/lib/schemaConversion.d.ts +0 -14
- package/dist/lib/schemaConversion.js +26 -56
- package/dist/lib/schemaConversion.js.map +1 -1
- package/dist/lib/schemaStructure.d.ts +1 -7
- package/dist/lib/schemaStructure.js +26 -57
- package/dist/lib/schemaStructure.js.map +1 -1
- package/dist/plugins/base.d.ts +1 -29
- package/dist/plugins/base.js +1 -33
- package/dist/plugins/base.js.map +1 -1
- package/dist/plugins/citations-plugin.d.ts +6 -81
- package/dist/plugins/citations-plugin.js +46 -161
- package/dist/plugins/citations-plugin.js.map +1 -1
- package/dist/plugins/crypto-plugin.d.ts +18 -123
- package/dist/plugins/crypto-plugin.js +41 -248
- package/dist/plugins/crypto-plugin.js.map +1 -1
- package/dist/plugins/time-plugin.d.ts +8 -90
- package/dist/plugins/time-plugin.js +24 -131
- package/dist/plugins/time-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +5 -36
- package/dist/service/auth.d.ts +1 -49
- package/dist/service/auth.js +21 -99
- package/dist/service/auth.js.map +1 -1
- package/dist/service/cloudflareService.js +5 -6
- package/dist/service/cloudflareService.js.map +1 -1
- package/dist/service/core.js +23 -54
- package/dist/service/core.js.map +1 -1
- package/dist/service/denoService.js +14 -18
- package/dist/service/denoService.js.map +1 -1
- package/dist/service/nextService.d.ts +7 -10
- package/dist/service/nextService.js +18 -65
- package/dist/service/nextService.js.map +1 -1
- package/dist/service/nodeService.d.ts +1 -1
- package/dist/service/nodeService.js +17 -29
- package/dist/service/nodeService.js.map +1 -1
- package/dist/service/processes.d.ts +34 -36
- package/dist/service/processes.js +133 -285
- package/dist/service/processes.js.map +1 -1
- package/dist/service/server.d.ts +2 -9
- package/dist/service/server.js +162 -408
- package/dist/service/server.js.map +1 -1
- package/dist/service/webhooks.d.ts +15 -172
- package/dist/service/webhooks.js +52 -184
- package/dist/service/webhooks.js.map +1 -1
- package/package.json +15 -14
|
@@ -3,10 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CitationsPlugin = void 0;
|
|
4
4
|
const base_1 = require("./base");
|
|
5
5
|
/**
|
|
6
|
-
* CitationsPlugin
|
|
7
|
-
*
|
|
8
|
-
* This plugin automatically extracts citations from tool responses that contain
|
|
9
|
-
* citation data, making them easily accessible for clients to display or process.
|
|
6
|
+
* CitationsPlugin extracts and manages citations from tool results,
|
|
7
|
+
* making them easily accessible for clients to display or process.
|
|
10
8
|
*/
|
|
11
9
|
class CitationsPlugin extends base_1.BaseDainPlugin {
|
|
12
10
|
id = 'citations-plugin';
|
|
@@ -15,176 +13,83 @@ class CitationsPlugin extends base_1.BaseDainPlugin {
|
|
|
15
13
|
description = 'Extracts and manages citations from tool results';
|
|
16
14
|
type = 'both';
|
|
17
15
|
config;
|
|
18
|
-
/**
|
|
19
|
-
* Create a new CitationsPlugin instance
|
|
20
|
-
* @param config Plugin configuration (optional)
|
|
21
|
-
*/
|
|
22
16
|
constructor(config = {}) {
|
|
23
17
|
super();
|
|
24
18
|
this.config = config;
|
|
25
19
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Get plugin input data from a tool context with proper typing
|
|
28
|
-
*/
|
|
29
20
|
getInputData(context) {
|
|
30
21
|
return super.getInputData(context);
|
|
31
22
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Get plugin output data from a response with proper typing
|
|
34
|
-
*/
|
|
35
23
|
getResponseData(response) {
|
|
36
24
|
return super.getResponseData(response);
|
|
37
25
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Create a standardized response for this plugin with proper typing
|
|
40
|
-
*/
|
|
41
26
|
createResponse(data) {
|
|
42
27
|
return super.createResponse(data);
|
|
43
28
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* @param data Any data structure that might contain citations
|
|
47
|
-
* @returns Array of citations found
|
|
48
|
-
*/
|
|
49
|
-
extractCitations(data) {
|
|
50
|
-
const citations = [];
|
|
51
|
-
if (!data)
|
|
52
|
-
return citations;
|
|
53
|
-
// Helper function to recursively search for citations
|
|
54
|
-
const searchForCitations = (obj, visited = new Set()) => {
|
|
55
|
-
// Prevent infinite recursion
|
|
56
|
-
if (!obj || typeof obj !== 'object' || visited.has(obj)) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
visited.add(obj);
|
|
60
|
-
// Check if this object is a citation
|
|
61
|
-
if (this.isCitation(obj)) {
|
|
62
|
-
citations.push(obj);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
// Check if this object has a citation property
|
|
66
|
-
if (obj.citation && this.isCitation(obj.citation)) {
|
|
67
|
-
citations.push(obj.citation);
|
|
68
|
-
}
|
|
69
|
-
// Recursively search arrays and objects
|
|
70
|
-
if (Array.isArray(obj)) {
|
|
71
|
-
obj.forEach(item => searchForCitations(item, visited));
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
Object.values(obj).forEach(value => searchForCitations(value, visited));
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
searchForCitations(data);
|
|
78
|
-
// Remove duplicates based on citation ID
|
|
79
|
-
const uniqueCitations = citations.filter((citation, index, self) => index === self.findIndex(c => c.id === citation.id));
|
|
80
|
-
return uniqueCitations;
|
|
29
|
+
isCitation(obj) {
|
|
30
|
+
return obj && typeof obj === 'object' && typeof obj.id === 'string' && obj.ui !== undefined;
|
|
81
31
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
32
|
+
isContentWithCitation(obj) {
|
|
33
|
+
return (obj &&
|
|
34
|
+
typeof obj === 'object' &&
|
|
35
|
+
typeof obj.content === 'string' &&
|
|
36
|
+
typeof obj.id === 'string' &&
|
|
37
|
+
this.isCitation(obj.citation));
|
|
38
|
+
}
|
|
39
|
+
recursiveSearch(data, predicate, checkNested) {
|
|
40
|
+
const results = [];
|
|
89
41
|
if (!data)
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
// Prevent infinite recursion
|
|
94
|
-
if (!obj || typeof obj !== 'object' || visited.has(obj)) {
|
|
42
|
+
return results;
|
|
43
|
+
const search = (obj, visited = new Set()) => {
|
|
44
|
+
if (!obj || typeof obj !== 'object' || visited.has(obj))
|
|
95
45
|
return;
|
|
96
|
-
}
|
|
97
46
|
visited.add(obj);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
contentWithCitations.push(obj);
|
|
47
|
+
if (predicate(obj)) {
|
|
48
|
+
results.push(obj);
|
|
101
49
|
return;
|
|
102
50
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
else {
|
|
108
|
-
Object.values(obj).forEach(value => searchForContent(value, visited));
|
|
51
|
+
if (checkNested) {
|
|
52
|
+
const nested = checkNested(obj);
|
|
53
|
+
if (nested)
|
|
54
|
+
results.push(nested);
|
|
109
55
|
}
|
|
56
|
+
const values = Array.isArray(obj) ? obj : Object.values(obj);
|
|
57
|
+
values.forEach(value => search(value, visited));
|
|
110
58
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
59
|
+
search(data);
|
|
60
|
+
const seen = new Set();
|
|
61
|
+
return results.filter(item => {
|
|
62
|
+
const id = item.id;
|
|
63
|
+
if (seen.has(id))
|
|
64
|
+
return false;
|
|
65
|
+
seen.add(id);
|
|
66
|
+
return true;
|
|
67
|
+
});
|
|
115
68
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
* @param obj Object to check
|
|
119
|
-
* @returns True if the object is a valid citation
|
|
120
|
-
*/
|
|
121
|
-
isCitation(obj) {
|
|
122
|
-
return obj &&
|
|
123
|
-
typeof obj === 'object' &&
|
|
124
|
-
typeof obj.id === 'string' &&
|
|
125
|
-
obj.ui !== undefined;
|
|
69
|
+
extractCitations(data) {
|
|
70
|
+
return this.recursiveSearch(data, (obj) => this.isCitation(obj), (obj) => this.isCitation(obj.citation) ? obj.citation : undefined);
|
|
126
71
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
* @param obj Object to check
|
|
130
|
-
* @returns True if the object is content with citation
|
|
131
|
-
*/
|
|
132
|
-
isContentWithCitation(obj) {
|
|
133
|
-
return obj &&
|
|
134
|
-
typeof obj === 'object' &&
|
|
135
|
-
typeof obj.content === 'string' &&
|
|
136
|
-
typeof obj.id === 'string' &&
|
|
137
|
-
this.isCitation(obj.citation);
|
|
72
|
+
extractContentWithCitations(data) {
|
|
73
|
+
return this.recursiveSearch(data, (obj) => this.isContentWithCitation(obj));
|
|
138
74
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Get citations from a tool response
|
|
141
|
-
* @param response Tool response
|
|
142
|
-
* @returns Array of citations found in the response
|
|
143
|
-
*/
|
|
144
75
|
getCitationsFromResponse(response) {
|
|
145
|
-
// First try to get from plugin data
|
|
146
76
|
const pluginData = this.getResponseData(response);
|
|
147
|
-
if (pluginData?.citations)
|
|
77
|
+
if (pluginData?.citations)
|
|
148
78
|
return pluginData.citations;
|
|
149
|
-
}
|
|
150
|
-
// If not found in plugin data, extract from the entire response
|
|
151
79
|
return this.extractCitations(response);
|
|
152
80
|
}
|
|
153
|
-
/**
|
|
154
|
-
* Get content with citations from a tool response
|
|
155
|
-
* @param response Tool response
|
|
156
|
-
* @returns Array of content with citations found in the response
|
|
157
|
-
*/
|
|
158
81
|
getContentWithCitationsFromResponse(response) {
|
|
159
|
-
// First try to get from plugin data
|
|
160
82
|
const pluginData = this.getResponseData(response);
|
|
161
|
-
if (pluginData?.contentWithCitations)
|
|
83
|
+
if (pluginData?.contentWithCitations)
|
|
162
84
|
return pluginData.contentWithCitations;
|
|
163
|
-
}
|
|
164
|
-
// If not found in plugin data, extract from the entire response
|
|
165
85
|
return this.extractContentWithCitations(response);
|
|
166
86
|
}
|
|
167
|
-
/**
|
|
168
|
-
* Get a specific citation by ID from a response
|
|
169
|
-
* @param response Tool response
|
|
170
|
-
* @param id Citation ID to find
|
|
171
|
-
* @returns Citation or undefined if not found
|
|
172
|
-
*/
|
|
173
87
|
getCitationById(response, id) {
|
|
174
|
-
|
|
175
|
-
return citations.find(citation => citation.id === id);
|
|
88
|
+
return this.getCitationsFromResponse(response).find(c => c.id === id);
|
|
176
89
|
}
|
|
177
|
-
|
|
178
|
-
* Process client input before sending to service
|
|
179
|
-
* No input processing needed for citations plugin
|
|
180
|
-
*/
|
|
181
|
-
async processInputClient(input) {
|
|
90
|
+
async processInputClient(_input) {
|
|
182
91
|
return {};
|
|
183
92
|
}
|
|
184
|
-
/**
|
|
185
|
-
* Process service output before sending to client
|
|
186
|
-
* Extract citations from the response data
|
|
187
|
-
*/
|
|
188
93
|
async processOutputService(output) {
|
|
189
94
|
const citations = this.extractCitations(output);
|
|
190
95
|
const contentWithCitations = this.extractContentWithCitations(output);
|
|
@@ -194,32 +99,18 @@ class CitationsPlugin extends base_1.BaseDainPlugin {
|
|
|
194
99
|
contentWithCitations: contentWithCitations.length > 0 ? contentWithCitations : undefined
|
|
195
100
|
};
|
|
196
101
|
}
|
|
197
|
-
/**
|
|
198
|
-
* Process client output after receiving service response
|
|
199
|
-
* Ensure citations are properly formatted
|
|
200
|
-
*/
|
|
201
102
|
async processOutputClient(output) {
|
|
202
|
-
// Validate and clean up citations in the plugin data
|
|
203
103
|
if (output?.plugins?.[this.id]?.citations) {
|
|
204
|
-
output.plugins[this.id].citations = output.plugins[this.id].citations.filter((
|
|
104
|
+
output.plugins[this.id].citations = output.plugins[this.id].citations.filter((c) => this.isCitation(c));
|
|
205
105
|
}
|
|
206
106
|
if (output?.plugins?.[this.id]?.contentWithCitations) {
|
|
207
|
-
output.plugins[this.id].contentWithCitations = output.plugins[this.id].contentWithCitations.filter((
|
|
107
|
+
output.plugins[this.id].contentWithCitations = output.plugins[this.id].contentWithCitations.filter((c) => this.isContentWithCitation(c));
|
|
208
108
|
}
|
|
209
109
|
return output;
|
|
210
110
|
}
|
|
211
|
-
/**
|
|
212
|
-
* Process service input before handling the request
|
|
213
|
-
*/
|
|
214
111
|
async processInputService(input) {
|
|
215
|
-
// No modifications needed for service input processing
|
|
216
112
|
return input;
|
|
217
113
|
}
|
|
218
|
-
/**
|
|
219
|
-
* Helper method to format citations for display
|
|
220
|
-
* @param citations Array of citations to format
|
|
221
|
-
* @returns Formatted citation strings
|
|
222
|
-
*/
|
|
223
114
|
formatCitations(citations) {
|
|
224
115
|
return citations.map(citation => {
|
|
225
116
|
const parts = [];
|
|
@@ -236,20 +127,14 @@ class CitationsPlugin extends base_1.BaseDainPlugin {
|
|
|
236
127
|
return parts.join(' ');
|
|
237
128
|
});
|
|
238
129
|
}
|
|
239
|
-
/**
|
|
240
|
-
* Helper method to group citations by type
|
|
241
|
-
* @param citations Array of citations to group
|
|
242
|
-
* @returns Object with citations grouped by type
|
|
243
|
-
*/
|
|
244
130
|
groupCitationsByType(citations) {
|
|
245
131
|
const grouped = {};
|
|
246
|
-
|
|
132
|
+
for (const citation of citations) {
|
|
247
133
|
const type = citation.type || 'other';
|
|
248
|
-
if (!grouped[type])
|
|
134
|
+
if (!grouped[type])
|
|
249
135
|
grouped[type] = [];
|
|
250
|
-
}
|
|
251
136
|
grouped[type].push(citation);
|
|
252
|
-
}
|
|
137
|
+
}
|
|
253
138
|
return grouped;
|
|
254
139
|
}
|
|
255
140
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"citations-plugin.js","sourceRoot":"","sources":["../../src/plugins/citations-plugin.ts"],"names":[],"mappings":";;;AAAA,iCAAwC;
|
|
1
|
+
{"version":3,"file":"citations-plugin.js","sourceRoot":"","sources":["../../src/plugins/citations-plugin.ts"],"names":[],"mappings":";;;AAAA,iCAAwC;AAsBxC;;;GAGG;AACH,MAAa,eAAgB,SAAQ,qBAAkF;IACrH,EAAE,GAAG,kBAAkB,CAAC;IACxB,IAAI,GAAG,kBAAkB,CAAC;IAC1B,OAAO,GAAG,OAAO,CAAC;IAClB,WAAW,GAAG,kDAAkD,CAAC;IACjE,IAAI,GAAG,MAAe,CAAC;IACvB,MAAM,CAAwB;IAE9B,YAAY,SAAgC,EAAE;QAC5C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEQ,YAAY,CAAC,OAAY;QAChC,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,CAAqC,CAAC;IACzE,CAAC;IAEQ,eAAe,CAAC,QAAa;QACpC,OAAO,KAAK,CAAC,eAAe,CAAC,QAAQ,CAAsC,CAAC;IAC9E,CAAC;IAEQ,cAAc,CAAC,IAAoC;QAC1D,OAAO,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAEO,UAAU,CAAC,GAAQ;QACzB,OAAO,GAAG,IAAI,OAAO,GAAG,KAAK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AI,SAAS,EAAE,CAAC;YACjC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC;YACtC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;gBAAE,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACvC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AArKD,0CAqKC"}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { BaseDainPlugin } from './base';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Supported blockchain networks:
|
|
4
|
+
* - Layer 1: sol (Solana), eth (Ethereum), btc (Bitcoin)
|
|
5
|
+
* - EVM L2/Sidechains: arb (Arbitrum), base (Base), bsc (BSC), polygon (Polygon POS)
|
|
6
|
+
* - App-specific: hyperEvm (HyperLiquid EVM)
|
|
7
|
+
*/
|
|
8
|
+
export type BlockchainNetwork = 'eth' | 'sol' | 'arb' | 'base' | 'hyperEvm' | 'bsc' | 'btc' | 'polygon';
|
|
3
9
|
export interface WalletInfo {
|
|
4
10
|
chain: BlockchainNetwork;
|
|
5
11
|
address: string;
|
|
@@ -9,14 +15,14 @@ export interface UnsignedTransaction {
|
|
|
9
15
|
encodedTx: string;
|
|
10
16
|
chain: BlockchainNetwork;
|
|
11
17
|
signer: string;
|
|
12
|
-
metadata?: Record<string,
|
|
13
|
-
ui?:
|
|
18
|
+
metadata?: Record<string, unknown>;
|
|
19
|
+
ui?: unknown;
|
|
14
20
|
}
|
|
15
21
|
export interface TransactionSignatureRequest {
|
|
16
22
|
txs: UnsignedTransaction[];
|
|
17
23
|
executeSimultaneously?: boolean;
|
|
18
24
|
toolsShouldWaitForConfirmation?: boolean;
|
|
19
|
-
ui?:
|
|
25
|
+
ui?: unknown;
|
|
20
26
|
}
|
|
21
27
|
export interface CryptoPluginConfig {
|
|
22
28
|
supportedChains?: BlockchainNetwork[];
|
|
@@ -29,11 +35,8 @@ export interface CryptoPluginOutput {
|
|
|
29
35
|
signatureRequests?: TransactionSignatureRequest[];
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
|
-
* CryptoPlugin
|
|
33
|
-
*
|
|
34
|
-
* This plugin allows services to request transaction signatures from clients
|
|
35
|
-
* by sending back unsigned transactions. Clients can provide their wallet
|
|
36
|
-
* addresses which tools can access and use to create appropriate transactions.
|
|
38
|
+
* CryptoPlugin handles cryptocurrency wallet information and transaction signing requests.
|
|
39
|
+
* Services can request transaction signatures by sending unsigned transactions to clients.
|
|
37
40
|
*/
|
|
38
41
|
export declare class CryptoPlugin extends BaseDainPlugin<CryptoPluginConfig, CryptoPluginInput, CryptoPluginOutput> {
|
|
39
42
|
id: string;
|
|
@@ -43,142 +46,34 @@ export declare class CryptoPlugin extends BaseDainPlugin<CryptoPluginConfig, Cry
|
|
|
43
46
|
type: "both";
|
|
44
47
|
config: CryptoPluginConfig;
|
|
45
48
|
private wallets;
|
|
46
|
-
/**
|
|
47
|
-
* Create a new CryptoPlugin instance
|
|
48
|
-
* @param config Plugin configuration or array of wallet information
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* // Initialize with wallet information directly
|
|
52
|
-
* const cryptoPlugin = new CryptoPlugin([
|
|
53
|
-
* { chain: 'eth', address: '0x1234...' },
|
|
54
|
-
* { chain: 'sol', address: 'Sol456...' }
|
|
55
|
-
* ]);
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* // Initialize with full configuration
|
|
59
|
-
* const cryptoPlugin = new CryptoPlugin({
|
|
60
|
-
* supportedChains: ['eth', 'sol'],
|
|
61
|
-
* wallets: [
|
|
62
|
-
* { chain: 'eth', address: '0x1234...' },
|
|
63
|
-
* { chain: 'sol', address: 'Sol456...' }
|
|
64
|
-
* ]
|
|
65
|
-
* });
|
|
66
|
-
*/
|
|
67
49
|
constructor(configOrWallets?: CryptoPluginConfig | WalletInfo[]);
|
|
68
|
-
/**
|
|
69
|
-
* Set or update wallet information
|
|
70
|
-
* @param wallets Array of wallet information
|
|
71
|
-
*/
|
|
72
50
|
setWallets(wallets: WalletInfo[]): void;
|
|
73
|
-
/**
|
|
74
|
-
* Add a single wallet
|
|
75
|
-
* @param wallet Wallet information to add
|
|
76
|
-
*/
|
|
77
51
|
addWallet(wallet: WalletInfo): void;
|
|
78
|
-
/**
|
|
79
|
-
* Get all configured wallets
|
|
80
|
-
* @returns Array of wallet information
|
|
81
|
-
*/
|
|
82
52
|
getWallets(): WalletInfo[];
|
|
83
|
-
/**
|
|
84
|
-
* Get plugin input data from a tool context with proper typing
|
|
85
|
-
*/
|
|
86
53
|
getInputData(context: any): CryptoPluginInput | undefined;
|
|
87
|
-
/**
|
|
88
|
-
* Get plugin output data from a response with proper typing
|
|
89
|
-
*/
|
|
90
54
|
getResponseData(response: any): CryptoPluginOutput | undefined;
|
|
91
|
-
/**
|
|
92
|
-
* Create a standardized response for this plugin with proper typing
|
|
93
|
-
*/
|
|
94
55
|
createResponse(data: Partial<CryptoPluginOutput>): CryptoPluginOutput;
|
|
95
56
|
/**
|
|
96
|
-
* Get user wallets from
|
|
97
|
-
*
|
|
98
|
-
* @returns Array of wallet information or empty array if none found
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* // In a tool handler
|
|
102
|
-
* const wallets = cryptoPlugin.getUserWallets(context);
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* // In a context handler
|
|
106
|
-
* const wallets = cryptoPlugin.getUserWallets(context);
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* // In a datasource handler
|
|
110
|
-
* const wallets = cryptoPlugin.getUserWallets(context);
|
|
57
|
+
* Get user wallets from tool context, context/datasource context, or direct input.
|
|
58
|
+
* Checks multiple paths: extraData.plugins, plugins, and getInputData result.
|
|
111
59
|
*/
|
|
112
60
|
getUserWallets(input: any): WalletInfo[];
|
|
113
|
-
/**
|
|
114
|
-
* Get wallet address for a specific chain
|
|
115
|
-
* @param input Tool context or context parameter from context/datasource handlers
|
|
116
|
-
* @param chain Blockchain network
|
|
117
|
-
* @returns Wallet address or undefined if not found
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* // In a tool handler
|
|
121
|
-
* const ethAddress = cryptoPlugin.getUserWalletForChain(context, "eth");
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* // In a context handler
|
|
125
|
-
* const solAddress = cryptoPlugin.getUserWalletForChain(context, "sol");
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* // In a datasource handler
|
|
129
|
-
* const arbAddress = cryptoPlugin.getUserWalletForChain(context, "arb");
|
|
130
|
-
*/
|
|
131
61
|
getUserWalletForChain(input: any, chain: BlockchainNetwork): string | undefined;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
* @param transactions Array of unsigned transactions
|
|
135
|
-
* @param options Optional configuration for the transaction request
|
|
136
|
-
* @param options.executeSimultaneously Whether to execute all transactions simultaneously
|
|
137
|
-
* @param options.toolsShouldWaitForConfirmation Whether to wait for transaction confirmation before completing
|
|
138
|
-
* @param options.ui Optional UI component for the entire transaction request
|
|
139
|
-
* @returns Properly formatted transaction signature request
|
|
140
|
-
*/
|
|
62
|
+
private ensureTransactionIds;
|
|
63
|
+
private normalizeSignatureRequest;
|
|
141
64
|
createTransactionRequest(transactions: UnsignedTransaction[], options?: {
|
|
142
65
|
executeSimultaneously?: boolean;
|
|
143
66
|
toolsShouldWaitForConfirmation?: boolean;
|
|
144
|
-
ui?:
|
|
67
|
+
ui?: unknown;
|
|
145
68
|
}): TransactionSignatureRequest;
|
|
146
|
-
/**
|
|
147
|
-
* Create a single transaction with a unique ID
|
|
148
|
-
* @param transaction Transaction data, ID will be generated if not provided
|
|
149
|
-
* @returns Transaction with a guaranteed unique ID
|
|
150
|
-
*/
|
|
151
69
|
createTransaction(transaction: Omit<UnsignedTransaction, 'id'> & {
|
|
152
70
|
id?: string;
|
|
153
71
|
}): UnsignedTransaction;
|
|
154
|
-
/**
|
|
155
|
-
* Get requested transaction signatures from a response
|
|
156
|
-
* @param response Tool response
|
|
157
|
-
* @returns Array of transaction signature requests or empty array if none
|
|
158
|
-
*/
|
|
159
72
|
getRequestedCryptoSignatures(response: any): TransactionSignatureRequest[];
|
|
160
|
-
/**
|
|
161
|
-
* Get a specific transaction by ID from all signature requests
|
|
162
|
-
* @param response Tool response
|
|
163
|
-
* @param id Transaction ID to find
|
|
164
|
-
* @returns Transaction or undefined if not found
|
|
165
|
-
*/
|
|
166
73
|
getTransactionById(response: any, id: string): UnsignedTransaction | undefined;
|
|
167
|
-
/**
|
|
168
|
-
* Process client input before sending to service
|
|
169
|
-
* Automatically adds wallet information to the request
|
|
170
|
-
*/
|
|
171
74
|
processInputClient(input: any): Promise<CryptoPluginInput>;
|
|
172
|
-
|
|
173
|
-
* Process service output before sending to client
|
|
174
|
-
*/
|
|
75
|
+
private extractSignatureRequests;
|
|
175
76
|
processOutputService(output: any): Promise<CryptoPluginOutput>;
|
|
176
|
-
/**
|
|
177
|
-
* Process client output after receiving service response
|
|
178
|
-
*/
|
|
179
77
|
processOutputClient(output: any): Promise<any>;
|
|
180
|
-
/**
|
|
181
|
-
* Process service input before handling the request
|
|
182
|
-
*/
|
|
183
78
|
processInputService(input: any): Promise<any>;
|
|
184
79
|
}
|