@dainprotocol/service-sdk 2.0.78 → 2.0.80
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 +31 -333
- 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 +18 -30
- 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 +164 -430
- 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 +1 -1
|
@@ -3,12 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CryptoPlugin = void 0;
|
|
4
4
|
const base_1 = require("./base");
|
|
5
5
|
const cuid2_1 = require("@paralleldrive/cuid2");
|
|
6
|
+
const DEFAULT_CHAINS = ['eth', 'sol', 'arb', 'base', 'hyperEvm', 'bsc', 'btc', 'polygon'];
|
|
6
7
|
/**
|
|
7
|
-
* CryptoPlugin
|
|
8
|
-
*
|
|
9
|
-
* This plugin allows services to request transaction signatures from clients
|
|
10
|
-
* by sending back unsigned transactions. Clients can provide their wallet
|
|
11
|
-
* addresses which tools can access and use to create appropriate transactions.
|
|
8
|
+
* CryptoPlugin handles cryptocurrency wallet information and transaction signing requests.
|
|
9
|
+
* Services can request transaction signatures by sending unsigned transactions to clients.
|
|
12
10
|
*/
|
|
13
11
|
class CryptoPlugin extends base_1.BaseDainPlugin {
|
|
14
12
|
id = 'crypto-plugin';
|
|
@@ -18,348 +16,143 @@ class CryptoPlugin extends base_1.BaseDainPlugin {
|
|
|
18
16
|
type = 'both';
|
|
19
17
|
config;
|
|
20
18
|
wallets;
|
|
21
|
-
/**
|
|
22
|
-
* Create a new CryptoPlugin instance
|
|
23
|
-
* @param config Plugin configuration or array of wallet information
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* // Initialize with wallet information directly
|
|
27
|
-
* const cryptoPlugin = new CryptoPlugin([
|
|
28
|
-
* { chain: 'eth', address: '0x1234...' },
|
|
29
|
-
* { chain: 'sol', address: 'Sol456...' }
|
|
30
|
-
* ]);
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* // Initialize with full configuration
|
|
34
|
-
* const cryptoPlugin = new CryptoPlugin({
|
|
35
|
-
* supportedChains: ['eth', 'sol'],
|
|
36
|
-
* wallets: [
|
|
37
|
-
* { chain: 'eth', address: '0x1234...' },
|
|
38
|
-
* { chain: 'sol', address: 'Sol456...' }
|
|
39
|
-
* ]
|
|
40
|
-
* });
|
|
41
|
-
*/
|
|
42
19
|
constructor(configOrWallets = {}) {
|
|
43
20
|
super();
|
|
44
|
-
// Handle the case where an array of wallets is passed directly
|
|
45
21
|
if (Array.isArray(configOrWallets)) {
|
|
46
|
-
this.config = { supportedChains:
|
|
22
|
+
this.config = { supportedChains: DEFAULT_CHAINS };
|
|
47
23
|
this.wallets = [...configOrWallets];
|
|
48
24
|
}
|
|
49
25
|
else {
|
|
50
|
-
// Set default supported chains if not provided
|
|
51
26
|
this.config = {
|
|
52
|
-
supportedChains: configOrWallets.supportedChains ||
|
|
27
|
+
supportedChains: configOrWallets.supportedChains || DEFAULT_CHAINS,
|
|
53
28
|
wallets: configOrWallets.wallets
|
|
54
29
|
};
|
|
55
30
|
this.wallets = configOrWallets.wallets || [];
|
|
56
31
|
}
|
|
57
32
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Set or update wallet information
|
|
60
|
-
* @param wallets Array of wallet information
|
|
61
|
-
*/
|
|
62
33
|
setWallets(wallets) {
|
|
63
34
|
this.wallets = [...wallets];
|
|
64
|
-
// Update config as well for consistency
|
|
65
35
|
this.config.wallets = [...wallets];
|
|
66
36
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Add a single wallet
|
|
69
|
-
* @param wallet Wallet information to add
|
|
70
|
-
*/
|
|
71
37
|
addWallet(wallet) {
|
|
72
|
-
// Remove any existing wallet for the same chain
|
|
73
38
|
this.wallets = this.wallets.filter(w => w.chain !== wallet.chain);
|
|
74
|
-
// Add the new wallet
|
|
75
39
|
this.wallets.push(wallet);
|
|
76
|
-
// Update config as well
|
|
77
40
|
this.config.wallets = [...this.wallets];
|
|
78
41
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Get all configured wallets
|
|
81
|
-
* @returns Array of wallet information
|
|
82
|
-
*/
|
|
83
42
|
getWallets() {
|
|
84
43
|
return [...this.wallets];
|
|
85
44
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Get plugin input data from a tool context with proper typing
|
|
88
|
-
*/
|
|
89
45
|
getInputData(context) {
|
|
90
46
|
return super.getInputData(context);
|
|
91
47
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Get plugin output data from a response with proper typing
|
|
94
|
-
*/
|
|
95
48
|
getResponseData(response) {
|
|
96
49
|
return super.getResponseData(response);
|
|
97
50
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Create a standardized response for this plugin with proper typing
|
|
100
|
-
*/
|
|
101
51
|
createResponse(data) {
|
|
102
52
|
return super.createResponse(data);
|
|
103
53
|
}
|
|
104
54
|
/**
|
|
105
|
-
* Get user wallets from
|
|
106
|
-
*
|
|
107
|
-
* @returns Array of wallet information or empty array if none found
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* // In a tool handler
|
|
111
|
-
* const wallets = cryptoPlugin.getUserWallets(context);
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* // In a context handler
|
|
115
|
-
* const wallets = cryptoPlugin.getUserWallets(context);
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* // In a datasource handler
|
|
119
|
-
* const wallets = cryptoPlugin.getUserWallets(context);
|
|
55
|
+
* Get user wallets from tool context, context/datasource context, or direct input.
|
|
56
|
+
* Checks multiple paths: extraData.plugins, plugins, and getInputData result.
|
|
120
57
|
*/
|
|
121
58
|
getUserWallets(input) {
|
|
122
|
-
// Handle different input types
|
|
123
|
-
// Case 1: Tool context with extraData.plugins structure
|
|
124
59
|
if (input?.extraData?.plugins?.[this.id]?.wallets) {
|
|
125
60
|
return input.extraData.plugins[this.id].wallets;
|
|
126
61
|
}
|
|
127
|
-
// Case 2: Context/datasource context with plugins structure
|
|
128
62
|
if (input?.plugins?.[this.id]?.wallets) {
|
|
129
63
|
return input.plugins[this.id].wallets;
|
|
130
64
|
}
|
|
131
|
-
// Case 3: Direct input from getInputData() result
|
|
132
65
|
const pluginData = this.getInputData(input);
|
|
133
66
|
if (pluginData?.wallets) {
|
|
134
67
|
return pluginData.wallets;
|
|
135
68
|
}
|
|
136
|
-
// Default: empty array
|
|
137
69
|
return [];
|
|
138
70
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Get wallet address for a specific chain
|
|
141
|
-
* @param input Tool context or context parameter from context/datasource handlers
|
|
142
|
-
* @param chain Blockchain network
|
|
143
|
-
* @returns Wallet address or undefined if not found
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
* // In a tool handler
|
|
147
|
-
* const ethAddress = cryptoPlugin.getUserWalletForChain(context, "eth");
|
|
148
|
-
*
|
|
149
|
-
* @example
|
|
150
|
-
* // In a context handler
|
|
151
|
-
* const solAddress = cryptoPlugin.getUserWalletForChain(context, "sol");
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* // In a datasource handler
|
|
155
|
-
* const arbAddress = cryptoPlugin.getUserWalletForChain(context, "arb");
|
|
156
|
-
*/
|
|
157
71
|
getUserWalletForChain(input, chain) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
72
|
+
return this.getUserWallets(input).find(w => w.chain === chain)?.address;
|
|
73
|
+
}
|
|
74
|
+
ensureTransactionIds(txs) {
|
|
75
|
+
return txs.map(tx => tx.id ? tx : { ...tx, id: (0, cuid2_1.createId)() });
|
|
76
|
+
}
|
|
77
|
+
normalizeSignatureRequest(req) {
|
|
78
|
+
return {
|
|
79
|
+
txs: this.ensureTransactionIds(req.txs),
|
|
80
|
+
executeSimultaneously: req.executeSimultaneously,
|
|
81
|
+
toolsShouldWaitForConfirmation: req.toolsShouldWaitForConfirmation,
|
|
82
|
+
ui: req.ui
|
|
83
|
+
};
|
|
161
84
|
}
|
|
162
|
-
/**
|
|
163
|
-
* Helper to create a transaction signature request
|
|
164
|
-
* @param transactions Array of unsigned transactions
|
|
165
|
-
* @param options Optional configuration for the transaction request
|
|
166
|
-
* @param options.executeSimultaneously Whether to execute all transactions simultaneously
|
|
167
|
-
* @param options.toolsShouldWaitForConfirmation Whether to wait for transaction confirmation before completing
|
|
168
|
-
* @param options.ui Optional UI component for the entire transaction request
|
|
169
|
-
* @returns Properly formatted transaction signature request
|
|
170
|
-
*/
|
|
171
85
|
createTransactionRequest(transactions, options) {
|
|
172
|
-
// Ensure each transaction has a unique ID
|
|
173
|
-
const txsWithIds = transactions.map(tx => {
|
|
174
|
-
if (!tx.id) {
|
|
175
|
-
return {
|
|
176
|
-
...tx,
|
|
177
|
-
id: (0, cuid2_1.createId)()
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
return tx;
|
|
181
|
-
});
|
|
182
86
|
return {
|
|
183
|
-
txs:
|
|
87
|
+
txs: this.ensureTransactionIds(transactions),
|
|
184
88
|
executeSimultaneously: options?.executeSimultaneously,
|
|
185
89
|
toolsShouldWaitForConfirmation: options?.toolsShouldWaitForConfirmation,
|
|
186
90
|
ui: options?.ui
|
|
187
91
|
};
|
|
188
92
|
}
|
|
189
|
-
/**
|
|
190
|
-
* Create a single transaction with a unique ID
|
|
191
|
-
* @param transaction Transaction data, ID will be generated if not provided
|
|
192
|
-
* @returns Transaction with a guaranteed unique ID
|
|
193
|
-
*/
|
|
194
93
|
createTransaction(transaction) {
|
|
195
94
|
return {
|
|
196
95
|
...transaction,
|
|
197
|
-
id: transaction.id || (0, cuid2_1.createId)()
|
|
198
|
-
ui: transaction.ui // Preserve UI if provided
|
|
96
|
+
id: transaction.id || (0, cuid2_1.createId)()
|
|
199
97
|
};
|
|
200
98
|
}
|
|
201
|
-
/**
|
|
202
|
-
* Get requested transaction signatures from a response
|
|
203
|
-
* @param response Tool response
|
|
204
|
-
* @returns Array of transaction signature requests or empty array if none
|
|
205
|
-
*/
|
|
206
99
|
getRequestedCryptoSignatures(response) {
|
|
207
100
|
const pluginData = this.getResponseData(response);
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return [];
|
|
101
|
+
if (pluginData?.signatureRequests) {
|
|
102
|
+
return pluginData.signatureRequests;
|
|
103
|
+
}
|
|
104
|
+
if (response?.data?.signatureRequests) {
|
|
105
|
+
return response.data.signatureRequests;
|
|
214
106
|
}
|
|
215
|
-
return
|
|
107
|
+
return [];
|
|
216
108
|
}
|
|
217
|
-
/**
|
|
218
|
-
* Get a specific transaction by ID from all signature requests
|
|
219
|
-
* @param response Tool response
|
|
220
|
-
* @param id Transaction ID to find
|
|
221
|
-
* @returns Transaction or undefined if not found
|
|
222
|
-
*/
|
|
223
109
|
getTransactionById(response, id) {
|
|
224
|
-
const
|
|
225
|
-
for (const request of requests) {
|
|
110
|
+
for (const request of this.getRequestedCryptoSignatures(response)) {
|
|
226
111
|
const tx = request.txs.find(tx => tx.id === id);
|
|
227
112
|
if (tx)
|
|
228
113
|
return tx;
|
|
229
114
|
}
|
|
230
115
|
return undefined;
|
|
231
116
|
}
|
|
232
|
-
/**
|
|
233
|
-
* Process client input before sending to service
|
|
234
|
-
* Automatically adds wallet information to the request
|
|
235
|
-
*/
|
|
236
117
|
async processInputClient(input) {
|
|
237
|
-
|
|
238
|
-
const inputWallets = input.wallets || [];
|
|
239
|
-
// Create a map of chains to addresses for quick lookup
|
|
118
|
+
const inputWallets = input?.wallets || [];
|
|
240
119
|
const walletMap = new Map();
|
|
241
|
-
// Add the explicitly provided wallets first
|
|
242
120
|
for (const wallet of inputWallets) {
|
|
243
121
|
walletMap.set(wallet.chain, wallet.address);
|
|
244
122
|
}
|
|
245
|
-
// Add the configured wallets where there isn't already a wallet for that chain
|
|
246
123
|
for (const wallet of this.wallets) {
|
|
247
124
|
if (!walletMap.has(wallet.chain)) {
|
|
248
125
|
walletMap.set(wallet.chain, wallet.address);
|
|
249
126
|
}
|
|
250
127
|
}
|
|
251
|
-
// Convert back to array
|
|
252
128
|
const combinedWallets = Array.from(walletMap.entries()).map(([chain, address]) => ({ chain: chain, address }));
|
|
253
|
-
return {
|
|
254
|
-
|
|
255
|
-
|
|
129
|
+
return { wallets: combinedWallets };
|
|
130
|
+
}
|
|
131
|
+
extractSignatureRequests(obj) {
|
|
132
|
+
const requests = obj?.signatureRequests;
|
|
133
|
+
if (!requests)
|
|
134
|
+
return [];
|
|
135
|
+
return requests.map((req) => this.normalizeSignatureRequest(req));
|
|
256
136
|
}
|
|
257
|
-
/**
|
|
258
|
-
* Process service output before sending to client
|
|
259
|
-
*/
|
|
260
137
|
async processOutputService(output) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if (output?.data?.signatureRequests) {
|
|
265
|
-
signatureRequests = output.data.signatureRequests.map((req) => {
|
|
266
|
-
// Ensure all transactions have IDs
|
|
267
|
-
const txsWithIds = req.txs.map(tx => {
|
|
268
|
-
if (!tx.id) {
|
|
269
|
-
return {
|
|
270
|
-
...tx,
|
|
271
|
-
id: (0, cuid2_1.createId)()
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
return tx;
|
|
275
|
-
});
|
|
276
|
-
return {
|
|
277
|
-
txs: txsWithIds,
|
|
278
|
-
executeSimultaneously: req.executeSimultaneously,
|
|
279
|
-
toolsShouldWaitForConfirmation: req.toolsShouldWaitForConfirmation,
|
|
280
|
-
ui: req.ui // Preserve UI if present
|
|
281
|
-
};
|
|
282
|
-
});
|
|
138
|
+
let signatureRequests = this.extractSignatureRequests(output?.data);
|
|
139
|
+
if (signatureRequests.length === 0) {
|
|
140
|
+
signatureRequests = this.extractSignatureRequests(output?.toolResult?.data);
|
|
283
141
|
}
|
|
284
|
-
// Also check if it's a context response where toolResult contains the data
|
|
285
|
-
if (output?.toolResult?.data?.signatureRequests) {
|
|
286
|
-
signatureRequests = output.toolResult.data.signatureRequests.map((req) => {
|
|
287
|
-
// Ensure all transactions have IDs
|
|
288
|
-
const txsWithIds = req.txs.map(tx => {
|
|
289
|
-
if (!tx.id) {
|
|
290
|
-
return {
|
|
291
|
-
...tx,
|
|
292
|
-
id: (0, cuid2_1.createId)()
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
return tx;
|
|
296
|
-
});
|
|
297
|
-
return {
|
|
298
|
-
txs: txsWithIds,
|
|
299
|
-
executeSimultaneously: req.executeSimultaneously,
|
|
300
|
-
toolsShouldWaitForConfirmation: req.toolsShouldWaitForConfirmation,
|
|
301
|
-
ui: req.ui // Preserve UI if present
|
|
302
|
-
};
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
// Return the extracted signatureRequests
|
|
306
142
|
return {
|
|
307
143
|
signatureRequests: signatureRequests.length > 0 ? signatureRequests : undefined
|
|
308
144
|
};
|
|
309
145
|
}
|
|
310
|
-
/**
|
|
311
|
-
* Process client output after receiving service response
|
|
312
|
-
*/
|
|
313
146
|
async processOutputClient(output) {
|
|
314
|
-
// Ensure all transactions in the response have IDs
|
|
315
147
|
if (output?.plugins?.[this.id]?.signatureRequests) {
|
|
316
|
-
output.plugins[this.id].signatureRequests = output.plugins[this.id].signatureRequests.map((req) =>
|
|
317
|
-
// Ensure all transactions have IDs
|
|
318
|
-
const txsWithIds = req.txs.map(tx => {
|
|
319
|
-
if (!tx.id) {
|
|
320
|
-
return {
|
|
321
|
-
...tx,
|
|
322
|
-
id: (0, cuid2_1.createId)()
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
return tx;
|
|
326
|
-
});
|
|
327
|
-
return {
|
|
328
|
-
txs: txsWithIds,
|
|
329
|
-
executeSimultaneously: req.executeSimultaneously,
|
|
330
|
-
toolsShouldWaitForConfirmation: req.toolsShouldWaitForConfirmation,
|
|
331
|
-
ui: req.ui // Preserve UI if present
|
|
332
|
-
};
|
|
333
|
-
});
|
|
148
|
+
output.plugins[this.id].signatureRequests = output.plugins[this.id].signatureRequests.map((req) => this.normalizeSignatureRequest(req));
|
|
334
149
|
}
|
|
335
|
-
// Also check data object for signatureRequests
|
|
336
150
|
if (output?.data?.signatureRequests) {
|
|
337
|
-
output.data.signatureRequests = output.data.signatureRequests.map((req) =>
|
|
338
|
-
// Ensure all transactions have IDs
|
|
339
|
-
const txsWithIds = req.txs.map(tx => {
|
|
340
|
-
if (!tx.id) {
|
|
341
|
-
return {
|
|
342
|
-
...tx,
|
|
343
|
-
id: (0, cuid2_1.createId)()
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
return tx;
|
|
347
|
-
});
|
|
348
|
-
return {
|
|
349
|
-
txs: txsWithIds,
|
|
350
|
-
executeSimultaneously: req.executeSimultaneously,
|
|
351
|
-
toolsShouldWaitForConfirmation: req.toolsShouldWaitForConfirmation,
|
|
352
|
-
ui: req.ui // Preserve UI if present
|
|
353
|
-
};
|
|
354
|
-
});
|
|
151
|
+
output.data.signatureRequests = output.data.signatureRequests.map((req) => this.normalizeSignatureRequest(req));
|
|
355
152
|
}
|
|
356
153
|
return output;
|
|
357
154
|
}
|
|
358
|
-
/**
|
|
359
|
-
* Process service input before handling the request
|
|
360
|
-
*/
|
|
361
155
|
async processInputService(input) {
|
|
362
|
-
// No modifications needed for service input processing
|
|
363
156
|
return input;
|
|
364
157
|
}
|
|
365
158
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-plugin.js","sourceRoot":"","sources":["../../src/plugins/crypto-plugin.ts"],"names":[],"mappings":";;;AAAA,iCAAwC;AACxC,gDAAgD;
|
|
1
|
+
{"version":3,"file":"crypto-plugin.js","sourceRoot":"","sources":["../../src/plugins/crypto-plugin.ts"],"names":[],"mappings":";;;AAAA,iCAAwC;AACxC,gDAAgD;AA4ChD,MAAM,cAAc,GAAwB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AAE/G;;;GAGG;AACH,MAAa,YAAa,SAAQ,qBAAyE;IACzG,EAAE,GAAG,eAAe,CAAC;IACrB,IAAI,GAAG,eAAe,CAAC;IACvB,OAAO,GAAG,OAAO,CAAC;IAClB,WAAW,GAAG,4EAA4E,CAAC;IAC3F,IAAI,GAAG,MAAe,CAAC;IACvB,MAAM,CAAqB;IACnB,OAAO,CAAe;IAE9B,YAAY,kBAAqD,EAAE;QACjE,KAAK,EAAE,CAAC;QAER,IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,MAAM,GAAG,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC;YAClD,IAAI,CAAC,OAAO,GAAG,CAAC,GAAG,eAAe,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,GAAG;gBACZ,eAAe,EAAE,eAAe,CAAC,eAAe,IAAI,cAAc;gBAClE,OAAO,EAAE,eAAe,CAAC,OAAO;aACjC,CAAC;YACF,IAAI,CAAC,OAAO,GAAG,eAAe,CAAC,OAAO,IAAI,EAAE,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,UAAU,CAAC,OAAqB;QAC9B,IAAI,CAAC,OAAO,G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iB,CAAC,GAAG,CACvF,CAAC,GAAgC,EAAE,EAAE,CAAC,IAAI,CAAC,yBAAyB,CAAC,GAAG,CAAC,CAC1E,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;YACpC,MAAM,CAAC,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAC/D,CAAC,GAAgC,EAAE,EAAE,CAAC,IAAI,CAAC,yBAAyB,CAAC,GAAG,CAAC,CAC1E,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,KAAU;QAClC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAhMD,oCAgMC"}
|
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
import { BaseDainPlugin } from './base';
|
|
2
|
-
interface TimePluginConfig {
|
|
2
|
+
export interface TimePluginConfig {
|
|
3
3
|
includeTimezone?: boolean;
|
|
4
4
|
}
|
|
5
|
-
interface TimePluginInput {
|
|
5
|
+
export interface TimePluginInput {
|
|
6
6
|
clientTimestamp: number;
|
|
7
7
|
timezone?: string;
|
|
8
8
|
}
|
|
9
|
-
interface TimePluginOutput {
|
|
9
|
+
export interface TimePluginOutput {
|
|
10
10
|
clientTimestamp: number;
|
|
11
11
|
serviceTimestamp: number;
|
|
12
12
|
roundtripTime?: number;
|
|
13
13
|
timezone?: string;
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Performance measurement options for createTimingResponse
|
|
17
|
-
*/
|
|
18
15
|
export interface TimingOptions {
|
|
19
|
-
/** Include timezone information */
|
|
20
16
|
includeTimezone?: boolean;
|
|
21
|
-
/** Add a custom operation type label */
|
|
22
17
|
operationType?: string;
|
|
23
|
-
/** Additional custom metadata */
|
|
24
18
|
metadata?: Record<string, any>;
|
|
25
19
|
}
|
|
26
20
|
/**
|
|
27
|
-
*
|
|
21
|
+
* TimePlugin adds timing information to requests and responses for performance measurement.
|
|
28
22
|
*/
|
|
29
23
|
export declare class TimePlugin extends BaseDainPlugin<TimePluginConfig, TimePluginInput, TimePluginOutput> {
|
|
30
24
|
config: TimePluginConfig;
|
|
@@ -34,101 +28,25 @@ export declare class TimePlugin extends BaseDainPlugin<TimePluginConfig, TimePlu
|
|
|
34
28
|
description: string;
|
|
35
29
|
type: "both";
|
|
36
30
|
constructor(config?: TimePluginConfig);
|
|
37
|
-
/**
|
|
38
|
-
* Get plugin input data from a tool context with proper typing
|
|
39
|
-
* Makes it easy for tools to access plugin data
|
|
40
|
-
*/
|
|
41
31
|
getInputData(context: any): TimePluginInput | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Get plugin output data from a response with proper typing
|
|
44
|
-
*/
|
|
45
32
|
getResponseData(response: any): TimePluginOutput | undefined;
|
|
46
|
-
/**
|
|
47
|
-
* Create a standardized response for this plugin with proper typing
|
|
48
|
-
*/
|
|
49
33
|
createResponse(data: Partial<TimePluginOutput>): TimePluginOutput;
|
|
50
|
-
/**
|
|
51
|
-
* Helper method to get and validate plugin data from a tool context
|
|
52
|
-
* Returns a default value if plugin data is not found
|
|
53
|
-
*/
|
|
54
34
|
getTimeDataFromContext(context: any): TimePluginInput;
|
|
55
|
-
/**
|
|
56
|
-
* Helper method to create a response with current timestamps
|
|
57
|
-
*/
|
|
58
35
|
createTimestampResponse(pluginInput?: TimePluginInput): TimePluginOutput;
|
|
59
|
-
/**
|
|
60
|
-
* Calculates the elapsed time between two timestamps
|
|
61
|
-
*/
|
|
62
36
|
calculateElapsedTime(startTime: number, endTime?: number): number;
|
|
63
|
-
/**
|
|
64
|
-
* Formats a timestamp in ISO format
|
|
65
|
-
*/
|
|
66
37
|
formatTimestamp(timestamp: number): string;
|
|
67
|
-
/**
|
|
68
|
-
* Helper method to extract client timezone
|
|
69
|
-
*/
|
|
70
38
|
getClientTimezone(context: any): string | undefined;
|
|
71
|
-
processInputClient(
|
|
39
|
+
processInputClient(_input: any): Promise<TimePluginInput>;
|
|
72
40
|
processInputService(input: any): Promise<any>;
|
|
41
|
+
private findPluginInput;
|
|
73
42
|
processOutputService(output: any): Promise<TimePluginOutput>;
|
|
74
43
|
processOutputClient(output: any): Promise<any>;
|
|
75
44
|
/**
|
|
76
|
-
*
|
|
77
|
-
* This shows real-world usage of createResponse in a service operation.
|
|
78
|
-
*
|
|
79
|
-
* @param startTimestamp When the operation started (usually from client)
|
|
80
|
-
* @param options Additional timing options
|
|
81
|
-
* @returns A properly formatted time plugin response
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* // In a service operation:
|
|
85
|
-
* async function processRequest(req) {
|
|
86
|
-
* const startTime = Date.now();
|
|
87
|
-
*
|
|
88
|
-
* // Do some work...
|
|
89
|
-
* const result = await doExpensiveOperation();
|
|
90
|
-
*
|
|
91
|
-
* // Measure timing and include in response
|
|
92
|
-
* const timing = timePlugin.createTimingResponse(startTime, {
|
|
93
|
-
* operationType: 'database-query',
|
|
94
|
-
* metadata: { rowsProcessed: 1500 }
|
|
95
|
-
* });
|
|
96
|
-
*
|
|
97
|
-
* return {
|
|
98
|
-
* data: result,
|
|
99
|
-
* plugins: {
|
|
100
|
-
* 'time-plugin': timing
|
|
101
|
-
* }
|
|
102
|
-
* };
|
|
103
|
-
* }
|
|
45
|
+
* Measures performance of service operations and returns timing data.
|
|
104
46
|
*/
|
|
105
47
|
createTimingResponse(startTimestamp: number, options?: TimingOptions): TimePluginOutput;
|
|
106
48
|
/**
|
|
107
|
-
* Creates
|
|
108
|
-
* and adds timing information to the response.
|
|
109
|
-
*
|
|
110
|
-
* @param options Timing options for the middleware
|
|
111
|
-
* @returns A middleware function that can wrap tool handlers
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* // Create a timed middleware
|
|
115
|
-
* const timedMiddleware = timePlugin.createTimedMiddleware({
|
|
116
|
-
* includeTimezone: true
|
|
117
|
-
* });
|
|
118
|
-
*
|
|
119
|
-
* // Create a tool with automatic timing
|
|
120
|
-
* const myTool = createTool({
|
|
121
|
-
* id: "my-timed-tool",
|
|
122
|
-
* // ... other tool properties
|
|
123
|
-
* handler: timedMiddleware(async (params, agentInfo, context) => {
|
|
124
|
-
* // Your tool logic here
|
|
125
|
-
* return {
|
|
126
|
-
* text: "Result",
|
|
127
|
-
* data: { ... }
|
|
128
|
-
* };
|
|
129
|
-
* })
|
|
130
|
-
* });
|
|
49
|
+
* Creates middleware that automatically times tool executions.
|
|
131
50
|
*/
|
|
132
51
|
createTimedMiddleware(options?: TimingOptions): (handler: Function) => (...args: any[]) => Promise<any>;
|
|
133
52
|
}
|
|
134
|
-
export {};
|