@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
|
@@ -1,43 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client Authentication for DAIN Services
|
|
3
|
-
*
|
|
4
|
-
* Supports two authentication modes:
|
|
5
|
-
* 1. JWT - For end users (browser-side), NO keypairs/orgId/agentId
|
|
6
|
-
* 2. API Key - For server-to-server auth (Node.js server-side only)
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* JWT Authentication Config (End Users - Browser)
|
|
10
|
-
*/
|
|
11
1
|
export interface DainClientAuthConfigJWT {
|
|
12
|
-
/** JWT access token from DAIN ID OAuth */
|
|
13
2
|
jwt: string;
|
|
14
|
-
/** Smart Account ID (optional, will be extracted from JWT if not provided) */
|
|
15
3
|
smartAccountId?: string;
|
|
16
|
-
/** Smart Account PDA on Solana (optional) */
|
|
17
4
|
smartAccountPDA?: string;
|
|
18
|
-
/** Webhook URL for async operations (optional) */
|
|
19
5
|
webhookUrl?: string;
|
|
20
6
|
}
|
|
21
|
-
/**
|
|
22
|
-
* API Key Authentication Config (Server-to-Server - Node.js only)
|
|
23
|
-
*/
|
|
24
7
|
export interface DainClientAuthConfigAPIKey {
|
|
25
|
-
/** API Key for server-side authentication */
|
|
26
8
|
apiKey: string;
|
|
27
|
-
/** Smart Account PDA on Solana (optional) */
|
|
28
9
|
smartAccountPDA?: string;
|
|
29
|
-
/** Webhook URL for async operations (optional) */
|
|
30
10
|
webhookUrl?: string;
|
|
31
11
|
}
|
|
32
12
|
export type DainClientAuthConfig = DainClientAuthConfigJWT | DainClientAuthConfigAPIKey;
|
|
33
|
-
/**
|
|
34
|
-
* DainClientAuth - JWT-only authentication for users
|
|
35
|
-
*
|
|
36
|
-
* This class is for CLIENT-SIDE use only (e.g., butterfly-web).
|
|
37
|
-
* Users authenticate with JWT tokens - NO keypairs, NO orgId, NO agentId.
|
|
38
|
-
*
|
|
39
|
-
* For SERVICE-SIDE authentication with keypairs, use the service SDK's built-in auth.
|
|
40
|
-
*/
|
|
41
13
|
export declare class DainClientAuth {
|
|
42
14
|
private jwt?;
|
|
43
15
|
private apiKey?;
|
|
@@ -45,58 +17,18 @@ export declare class DainClientAuth {
|
|
|
45
17
|
private smartAccountPDA?;
|
|
46
18
|
private webhookUrl?;
|
|
47
19
|
constructor(config: DainClientAuthConfig);
|
|
48
|
-
|
|
49
|
-
* Decode JWT payload (without verification)
|
|
50
|
-
* @private
|
|
51
|
-
*/
|
|
20
|
+
private extractSmartAccountId;
|
|
52
21
|
private decodeJWTPayload;
|
|
53
|
-
/**
|
|
54
|
-
* Get headers for HTTP requests
|
|
55
|
-
*/
|
|
56
22
|
getHeaders(): Record<string, string>;
|
|
57
|
-
/**
|
|
58
|
-
* Check if using JWT authentication
|
|
59
|
-
*/
|
|
60
23
|
isJWT(): boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Check if using API Key authentication
|
|
63
|
-
*/
|
|
64
24
|
isAPIKey(): boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Get JWT token
|
|
67
|
-
*/
|
|
68
25
|
getJWT(): string | undefined;
|
|
69
|
-
/**
|
|
70
|
-
* Get API Key
|
|
71
|
-
*/
|
|
72
26
|
getAPIKey(): string | undefined;
|
|
73
|
-
/**
|
|
74
|
-
* Get smart account ID
|
|
75
|
-
*/
|
|
76
27
|
getSmartAccountId(): string | undefined;
|
|
77
|
-
/**
|
|
78
|
-
* Get smart account PDA
|
|
79
|
-
*/
|
|
80
28
|
getSmartAccountPDA(): string | undefined;
|
|
81
|
-
/**
|
|
82
|
-
* Get webhook URL
|
|
83
|
-
*/
|
|
84
29
|
getWebhookUrl(): string | undefined;
|
|
85
|
-
/**
|
|
86
|
-
* Update JWT token (for token refresh scenarios)
|
|
87
|
-
*/
|
|
88
30
|
updateJWT(newJWT: string): void;
|
|
89
|
-
/**
|
|
90
|
-
* Verify SSE event signature from service
|
|
91
|
-
* (Services sign their event responses, users verify them)
|
|
92
|
-
*/
|
|
93
31
|
verifyEventSignature(data: string, signature: string, timestamp: string, publicKeyBase58: string): boolean;
|
|
94
|
-
/**
|
|
95
|
-
* Serialize auth config
|
|
96
|
-
*/
|
|
97
32
|
serialize(): string;
|
|
98
|
-
/**
|
|
99
|
-
* Deserialize auth config
|
|
100
|
-
*/
|
|
101
33
|
static deserialize(serialized: string): DainClientAuth;
|
|
102
34
|
}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//File: src/client/client-auth.ts
|
|
3
|
-
/**
|
|
4
|
-
* Client Authentication for DAIN Services
|
|
5
|
-
*
|
|
6
|
-
* Supports two authentication modes:
|
|
7
|
-
* 1. JWT - For end users (browser-side), NO keypairs/orgId/agentId
|
|
8
|
-
* 2. API Key - For server-to-server auth (Node.js server-side only)
|
|
9
|
-
*/
|
|
10
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
3
|
exports.DainClientAuth = void 0;
|
|
12
4
|
function isJWTConfig(config) {
|
|
@@ -15,14 +7,6 @@ function isJWTConfig(config) {
|
|
|
15
7
|
function isAPIKeyConfig(config) {
|
|
16
8
|
return 'apiKey' in config;
|
|
17
9
|
}
|
|
18
|
-
/**
|
|
19
|
-
* DainClientAuth - JWT-only authentication for users
|
|
20
|
-
*
|
|
21
|
-
* This class is for CLIENT-SIDE use only (e.g., butterfly-web).
|
|
22
|
-
* Users authenticate with JWT tokens - NO keypairs, NO orgId, NO agentId.
|
|
23
|
-
*
|
|
24
|
-
* For SERVICE-SIDE authentication with keypairs, use the service SDK's built-in auth.
|
|
25
|
-
*/
|
|
26
10
|
class DainClientAuth {
|
|
27
11
|
jwt;
|
|
28
12
|
apiKey;
|
|
@@ -31,21 +15,12 @@ class DainClientAuth {
|
|
|
31
15
|
webhookUrl;
|
|
32
16
|
constructor(config) {
|
|
33
17
|
if (isJWTConfig(config)) {
|
|
34
|
-
// JWT Authentication (End Users)
|
|
35
18
|
this.jwt = config.jwt;
|
|
36
|
-
|
|
37
|
-
if (config.smartAccountId) {
|
|
38
|
-
this.smartAccountId = config.smartAccountId;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
const payload = this.decodeJWTPayload(config.jwt);
|
|
42
|
-
this.smartAccountId = payload.smart_account_id || payload.sub;
|
|
43
|
-
}
|
|
19
|
+
this.smartAccountId = config.smartAccountId ?? this.extractSmartAccountId(config.jwt);
|
|
44
20
|
this.smartAccountPDA = config.smartAccountPDA;
|
|
45
21
|
this.webhookUrl = config.webhookUrl;
|
|
46
22
|
}
|
|
47
23
|
else if (isAPIKeyConfig(config)) {
|
|
48
|
-
// API Key Authentication (Server-to-Server)
|
|
49
24
|
this.apiKey = config.apiKey;
|
|
50
25
|
this.smartAccountPDA = config.smartAccountPDA;
|
|
51
26
|
this.webhookUrl = config.webhookUrl;
|
|
@@ -54,10 +29,10 @@ class DainClientAuth {
|
|
|
54
29
|
throw new Error('Invalid authentication config - must provide either jwt or apiKey');
|
|
55
30
|
}
|
|
56
31
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
32
|
+
extractSmartAccountId(jwt) {
|
|
33
|
+
const payload = this.decodeJWTPayload(jwt);
|
|
34
|
+
return payload.smart_account_id || payload.sub || '';
|
|
35
|
+
}
|
|
61
36
|
decodeJWTPayload(jwt) {
|
|
62
37
|
const parts = jwt.split('.');
|
|
63
38
|
if (parts.length !== 3) {
|
|
@@ -66,17 +41,12 @@ class DainClientAuth {
|
|
|
66
41
|
const payload = Buffer.from(parts[1], 'base64').toString('utf-8');
|
|
67
42
|
return JSON.parse(payload);
|
|
68
43
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Get headers for HTTP requests
|
|
71
|
-
*/
|
|
72
44
|
getHeaders() {
|
|
73
45
|
const headers = {};
|
|
74
46
|
if (this.jwt) {
|
|
75
|
-
// JWT Authentication
|
|
76
47
|
headers["Authorization"] = `Bearer ${this.jwt}`;
|
|
77
48
|
}
|
|
78
49
|
else if (this.apiKey) {
|
|
79
|
-
// API Key Authentication
|
|
80
50
|
headers["X-DAIN-API-KEY"] = this.apiKey;
|
|
81
51
|
}
|
|
82
52
|
if (this.smartAccountPDA) {
|
|
@@ -87,69 +57,36 @@ class DainClientAuth {
|
|
|
87
57
|
}
|
|
88
58
|
return headers;
|
|
89
59
|
}
|
|
90
|
-
// ===== Getter Methods =====
|
|
91
|
-
/**
|
|
92
|
-
* Check if using JWT authentication
|
|
93
|
-
*/
|
|
94
60
|
isJWT() {
|
|
95
61
|
return !!this.jwt;
|
|
96
62
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Check if using API Key authentication
|
|
99
|
-
*/
|
|
100
63
|
isAPIKey() {
|
|
101
64
|
return !!this.apiKey;
|
|
102
65
|
}
|
|
103
|
-
/**
|
|
104
|
-
* Get JWT token
|
|
105
|
-
*/
|
|
106
66
|
getJWT() {
|
|
107
67
|
return this.jwt;
|
|
108
68
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Get API Key
|
|
111
|
-
*/
|
|
112
69
|
getAPIKey() {
|
|
113
70
|
return this.apiKey;
|
|
114
71
|
}
|
|
115
|
-
/**
|
|
116
|
-
* Get smart account ID
|
|
117
|
-
*/
|
|
118
72
|
getSmartAccountId() {
|
|
119
73
|
return this.smartAccountId;
|
|
120
74
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Get smart account PDA
|
|
123
|
-
*/
|
|
124
75
|
getSmartAccountPDA() {
|
|
125
76
|
return this.smartAccountPDA;
|
|
126
77
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Get webhook URL
|
|
129
|
-
*/
|
|
130
78
|
getWebhookUrl() {
|
|
131
79
|
return this.webhookUrl;
|
|
132
80
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Update JWT token (for token refresh scenarios)
|
|
135
|
-
*/
|
|
136
81
|
updateJWT(newJWT) {
|
|
137
82
|
if (!this.jwt) {
|
|
138
83
|
throw new Error('Cannot update JWT - instance is using API Key authentication');
|
|
139
84
|
}
|
|
140
85
|
this.jwt = newJWT;
|
|
141
|
-
|
|
142
|
-
const payload = this.decodeJWTPayload(newJWT);
|
|
143
|
-
this.smartAccountId = payload.smart_account_id || payload.sub;
|
|
86
|
+
this.smartAccountId = this.extractSmartAccountId(newJWT);
|
|
144
87
|
}
|
|
145
|
-
/**
|
|
146
|
-
* Verify SSE event signature from service
|
|
147
|
-
* (Services sign their event responses, users verify them)
|
|
148
|
-
*/
|
|
149
88
|
verifyEventSignature(data, signature, timestamp, publicKeyBase58) {
|
|
150
89
|
try {
|
|
151
|
-
// This is for verifying SERVICE signatures, not user signatures
|
|
152
|
-
// Import crypto libs only when needed
|
|
153
90
|
const { ed25519 } = require("@noble/curves/ed25519");
|
|
154
91
|
const { sha256 } = require("@noble/hashes/sha256");
|
|
155
92
|
const bs58 = require("bs58");
|
|
@@ -163,60 +100,44 @@ class DainClientAuth {
|
|
|
163
100
|
return false;
|
|
164
101
|
}
|
|
165
102
|
}
|
|
166
|
-
// ===== Serialization =====
|
|
167
|
-
/**
|
|
168
|
-
* Serialize auth config
|
|
169
|
-
*/
|
|
170
103
|
serialize() {
|
|
171
104
|
if (this.jwt) {
|
|
172
|
-
|
|
105
|
+
return Buffer.from(JSON.stringify({
|
|
173
106
|
authMethod: 'jwt',
|
|
174
107
|
jwt: this.jwt,
|
|
175
108
|
smartAccountId: this.smartAccountId,
|
|
176
109
|
smartAccountPDA: this.smartAccountPDA,
|
|
177
110
|
webhookUrl: this.webhookUrl
|
|
178
|
-
};
|
|
179
|
-
return Buffer.from(JSON.stringify(data)).toString('base64');
|
|
111
|
+
})).toString('base64');
|
|
180
112
|
}
|
|
181
|
-
|
|
182
|
-
|
|
113
|
+
if (this.apiKey) {
|
|
114
|
+
return Buffer.from(JSON.stringify({
|
|
183
115
|
authMethod: 'apiKey',
|
|
184
116
|
apiKey: this.apiKey,
|
|
185
117
|
smartAccountPDA: this.smartAccountPDA,
|
|
186
118
|
webhookUrl: this.webhookUrl
|
|
187
|
-
};
|
|
188
|
-
return Buffer.from(JSON.stringify(data)).toString('base64');
|
|
119
|
+
})).toString('base64');
|
|
189
120
|
}
|
|
190
121
|
throw new Error('No authentication method available');
|
|
191
122
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Deserialize auth config
|
|
194
|
-
*/
|
|
195
123
|
static deserialize(serialized) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
else if (data.authMethod === 'apiKey') {
|
|
207
|
-
return new DainClientAuth({
|
|
208
|
-
apiKey: data.apiKey,
|
|
209
|
-
smartAccountPDA: data.smartAccountPDA,
|
|
210
|
-
webhookUrl: data.webhookUrl
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
throw new Error('Invalid auth method - must be jwt or apiKey');
|
|
215
|
-
}
|
|
124
|
+
const data = JSON.parse(Buffer.from(serialized, 'base64').toString());
|
|
125
|
+
if (data.authMethod === 'jwt') {
|
|
126
|
+
return new DainClientAuth({
|
|
127
|
+
jwt: data.jwt,
|
|
128
|
+
smartAccountId: data.smartAccountId,
|
|
129
|
+
smartAccountPDA: data.smartAccountPDA,
|
|
130
|
+
webhookUrl: data.webhookUrl
|
|
131
|
+
});
|
|
216
132
|
}
|
|
217
|
-
|
|
218
|
-
|
|
133
|
+
if (data.authMethod === 'apiKey') {
|
|
134
|
+
return new DainClientAuth({
|
|
135
|
+
apiKey: data.apiKey,
|
|
136
|
+
smartAccountPDA: data.smartAccountPDA,
|
|
137
|
+
webhookUrl: data.webhookUrl
|
|
138
|
+
});
|
|
219
139
|
}
|
|
140
|
+
throw new Error('Invalid auth method - must be jwt or apiKey');
|
|
220
141
|
}
|
|
221
142
|
}
|
|
222
143
|
exports.DainClientAuth = DainClientAuth;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-auth.js","sourceRoot":"","sources":["../../src/client/client-auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client-auth.js","sourceRoot":"","sources":["../../src/client/client-auth.ts"],"names":[],"mappings":";;;AAeA,SAAS,WAAW,CAAC,MAA4B;IAC/C,OAAO,KAAK,IAAI,MAAM,CAAC;AACzB,CAAC;AAED,SAAS,cAAc,CAAC,MAA4B;IAClD,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED,MAAa,cAAc;IACjB,GAAG,CAAU;IACb,MAAM,CAAU;IAChB,cAAc,CAAU;IACxB,eAAe,CAAU;IACzB,UAAU,CAAU;IAE5B,YAAY,MAA4B;QACtC,IAAI,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;YACxB,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;YACtB,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,IAAI,CAAC,qBAAqB,CA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AAoC,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,UAAkB;QACnC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEtE,IAAI,IAAI,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;YAC9B,OAAO,IAAI,cAAc,CAAC;gBACxB,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,cAAc,EAAE,IAAI,CAAC,cAAc;gBACnC,eAAe,EAAE,IAAI,CAAC,eAAe;gBACrC,UAAU,EAAE,IAAI,CAAC,UAAU;aAC5B,CAAC,CAAC;QACL,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;YACjC,OAAO,IAAI,cAAc,CAAC;gBACxB,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,eAAe,EAAE,IAAI,CAAC,eAAe;gBACrC,UAAU,EAAE,IAAI,CAAC,UAAU;aAC5B,CAAC,CAAC;QACL,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;CACF;AA1JD,wCA0JC"}
|
package/dist/client/client.d.ts
CHANGED
|
@@ -4,6 +4,16 @@ import { DainPlugin } from "../plugins/types";
|
|
|
4
4
|
import { ToolInterfaceType } from "../interfaces";
|
|
5
5
|
import { ServiceMetadata, ServiceConfig, ToolboxConfig, ToolConfig, ServiceContext, ServiceContextWithData, ToolWithJsonSchema, ServiceWidgetWithData, OAuth2ProviderInfo, ProviderInfo, DirectAuthStatus, ExampleQueries, HumanActionStep, ServiceDatasource, ServiceDatasourceWithData, ServiceAgent } from "./types";
|
|
6
6
|
export type { ServiceMetadata, ServiceConfig, ToolboxConfig, ToolConfig, ServiceAgent };
|
|
7
|
+
interface ToolCallOptions {
|
|
8
|
+
onUIUpdate?: (update: {
|
|
9
|
+
ui: unknown;
|
|
10
|
+
}) => void;
|
|
11
|
+
onProcess?: (processId: string) => void;
|
|
12
|
+
onProgress?: (update: {
|
|
13
|
+
text: string;
|
|
14
|
+
data?: unknown;
|
|
15
|
+
}) => void;
|
|
16
|
+
}
|
|
7
17
|
export declare class DainServiceConnection {
|
|
8
18
|
private baseUrl;
|
|
9
19
|
private clientAuth;
|
|
@@ -14,12 +24,12 @@ export declare class DainServiceConnection {
|
|
|
14
24
|
plugins?: DainPlugin[];
|
|
15
25
|
enableStreaming?: boolean;
|
|
16
26
|
});
|
|
17
|
-
/**
|
|
18
|
-
* Returns the base URL of the connected service
|
|
19
|
-
* @returns The service's base URL as a string
|
|
20
|
-
*/
|
|
21
27
|
getURI(): string;
|
|
22
|
-
|
|
28
|
+
private processPluginInput;
|
|
29
|
+
private processPluginOutput;
|
|
30
|
+
private extractDataFromPluginResponse;
|
|
31
|
+
private extractSingleFromPluginResponse;
|
|
32
|
+
makeRequest(method: string, path: string, body?: Record<string, unknown>): Promise<unknown>;
|
|
23
33
|
getMetadata(): Promise<ServiceMetadata>;
|
|
24
34
|
getExampleQueries(): Promise<ExampleQueries>;
|
|
25
35
|
getServices(): Promise<ServiceConfig[]>;
|
|
@@ -28,84 +38,26 @@ export declare class DainServiceConnection {
|
|
|
28
38
|
getTools(): Promise<ToolConfig[]>;
|
|
29
39
|
getTool(toolId: string): Promise<ToolConfig>;
|
|
30
40
|
getContexts(): Promise<ServiceContext[]>;
|
|
31
|
-
/**
|
|
32
|
-
* List contexts using POST to send plugins data in request body
|
|
33
|
-
* This is the primary method to get context data, especially when using plugins
|
|
34
|
-
*/
|
|
35
41
|
listContexts(): Promise<ServiceContext[]>;
|
|
36
|
-
/**
|
|
37
|
-
* Get all context data using POST to send plugins data in request body
|
|
38
|
-
* This is the primary method to get all context data, especially when using plugins
|
|
39
|
-
*/
|
|
40
42
|
postAllContexts(): Promise<ServiceContextWithData[]>;
|
|
41
|
-
/**
|
|
42
|
-
* Get context data using POST to send plugins data in request body
|
|
43
|
-
* This is the primary method to get context data, especially when using plugins
|
|
44
|
-
*/
|
|
45
43
|
getContext(contextId: string): Promise<ServiceContextWithData>;
|
|
46
44
|
getAllContexts(): Promise<ServiceContextWithData[]>;
|
|
47
|
-
/**
|
|
48
|
-
* Get widget IDs for the current user using POST to send plugins data in request body
|
|
49
|
-
* This is the primary method to get widget IDs, especially when using plugins
|
|
50
|
-
*/
|
|
51
45
|
getWidgets(): Promise<string[]>;
|
|
52
|
-
/**
|
|
53
|
-
* Get widget data using POST to send plugins data in request body
|
|
54
|
-
* This is the primary method to get widget data, especially when using plugins
|
|
55
|
-
*/
|
|
56
46
|
getWidget(widgetId: string): Promise<ServiceWidgetWithData>;
|
|
57
|
-
/**
|
|
58
|
-
* Get all widgets with data using POST to send plugins data in request body
|
|
59
|
-
* This is the primary method to get all widgets with data, especially when using plugins
|
|
60
|
-
*/
|
|
61
47
|
getAllWidgets(): Promise<ServiceWidgetWithData[]>;
|
|
62
|
-
/**
|
|
63
|
-
* Get all widgets with their data using POST to send plugins data in request body
|
|
64
|
-
* This is the primary method to get widget data, especially when using plugins
|
|
65
|
-
*/
|
|
66
48
|
postAllWidgets(): Promise<ServiceWidgetWithData[]>;
|
|
67
|
-
/**
|
|
68
|
-
* Get the home UI widget ID for the current user
|
|
69
|
-
* Returns null if no home UI is configured
|
|
70
|
-
*/
|
|
71
49
|
getHomeUI(): Promise<string | null>;
|
|
72
|
-
/**
|
|
73
|
-
* Get all tools as JSON schema using POST to send plugins data in request body
|
|
74
|
-
* This is the primary method to get all tools as JSON schema, especially when using plugins
|
|
75
|
-
*/
|
|
76
50
|
getAllToolsAsJsonSchema(): Promise<{
|
|
77
51
|
tools: ToolWithJsonSchema[];
|
|
78
52
|
reccomendedPrompts: string[];
|
|
79
53
|
}>;
|
|
80
54
|
loadToolbox(toolboxId: string, execute?: boolean): Promise<Record<string, Tool>>;
|
|
81
55
|
createVercelAITool(toolInfo: ToolConfig): Tool;
|
|
82
|
-
callTool(toolId: string, params:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}) => void;
|
|
86
|
-
onProcess?: (processId: string) => void;
|
|
87
|
-
onProgress?: (update: {
|
|
88
|
-
text: string;
|
|
89
|
-
data?: any;
|
|
90
|
-
}) => void;
|
|
91
|
-
}): Promise<any>;
|
|
92
|
-
callToolAndGetNewContext(toolId: string, params: any, options?: {
|
|
93
|
-
onUIUpdate?: (update: {
|
|
94
|
-
ui: any;
|
|
95
|
-
}) => void;
|
|
96
|
-
onProcess?: (processId: string) => void;
|
|
97
|
-
onProgress?: (update: {
|
|
98
|
-
text: string;
|
|
99
|
-
data?: any;
|
|
100
|
-
}) => void;
|
|
101
|
-
}): Promise<{
|
|
102
|
-
toolResult: any;
|
|
56
|
+
callTool(toolId: string, params: Record<string, unknown>, options?: ToolCallOptions): Promise<unknown>;
|
|
57
|
+
callToolAndGetNewContext(toolId: string, params: Record<string, unknown>, options?: ToolCallOptions): Promise<{
|
|
58
|
+
toolResult: unknown;
|
|
103
59
|
context: ServiceContextWithData[];
|
|
104
60
|
}>;
|
|
105
|
-
/**
|
|
106
|
-
* Shared implementation for streaming tool calls
|
|
107
|
-
* @private
|
|
108
|
-
*/
|
|
109
61
|
private _callToolWithStreaming;
|
|
110
62
|
createVercelAIToolWithoutExecute(toolInfo: ToolConfig): Tool;
|
|
111
63
|
getProcessStatus(processId: string): Promise<{
|
|
@@ -118,24 +70,13 @@ export declare class DainServiceConnection {
|
|
|
118
70
|
}[];
|
|
119
71
|
results: {
|
|
120
72
|
text: string;
|
|
121
|
-
data:
|
|
122
|
-
ui?:
|
|
73
|
+
data: unknown;
|
|
74
|
+
ui?: unknown;
|
|
123
75
|
}[];
|
|
124
76
|
} | null>;
|
|
125
77
|
getOAuth2Providers(): Promise<OAuth2ProviderInfo[]>;
|
|
126
|
-
/**
|
|
127
|
-
* Get all authentication providers (OAuth2 + Direct)
|
|
128
|
-
* Returns unified provider information with type discrimination
|
|
129
|
-
*/
|
|
130
78
|
getAuthenticationProviders(): Promise<ProviderInfo[]>;
|
|
131
79
|
getOAuth2ConnectUrl(provider: string): Promise<string>;
|
|
132
|
-
/**
|
|
133
|
-
* Get direct auth setup status for a provider (RFC 8628 Device Authorization Grant)
|
|
134
|
-
* Used to poll for completion when user completes auth on external device (e.g., Telegram)
|
|
135
|
-
*
|
|
136
|
-
* @param provider - Provider name (e.g., 'telegram')
|
|
137
|
-
* @returns Setup status with completion info or pending state
|
|
138
|
-
*/
|
|
139
80
|
getDirectAuthStatus(provider: string): Promise<DirectAuthStatus>;
|
|
140
81
|
getProcessHumanActions(processId: string): Promise<HumanActionStep[]>;
|
|
141
82
|
getHumanAction(processId: string, stepId: string): Promise<{
|
|
@@ -143,56 +84,24 @@ export declare class DainServiceConnection {
|
|
|
143
84
|
response?: {
|
|
144
85
|
actionId: string;
|
|
145
86
|
responseText?: string;
|
|
146
|
-
data?:
|
|
87
|
+
data?: unknown;
|
|
147
88
|
};
|
|
148
89
|
}>;
|
|
149
|
-
respondToHumanAction(processId: string, stepId: string, actionId: string, responseText?: string, data?:
|
|
90
|
+
respondToHumanAction(processId: string, stepId: string, actionId: string, responseText?: string, data?: unknown): Promise<{
|
|
150
91
|
success: boolean;
|
|
151
92
|
}>;
|
|
152
|
-
getToolConfirmation(toolId: string, input:
|
|
93
|
+
getToolConfirmation(toolId: string, input: Record<string, unknown>): Promise<{
|
|
153
94
|
success: boolean;
|
|
154
|
-
ui?:
|
|
95
|
+
ui?: unknown;
|
|
155
96
|
}>;
|
|
156
|
-
/**
|
|
157
|
-
* List datasources using POST to send plugins data in request body
|
|
158
|
-
* This is the primary method to get datasource data, especially when using plugins
|
|
159
|
-
*/
|
|
160
97
|
listDatasources(): Promise<ServiceDatasource[]>;
|
|
161
|
-
|
|
162
|
-
* Get data from a datasource using POST to send params and plugin data
|
|
163
|
-
* This is the primary method for accessing datasources
|
|
164
|
-
*/
|
|
165
|
-
getDatasource(datasourceId: string, params: any): Promise<ServiceDatasourceWithData>;
|
|
166
|
-
/**
|
|
167
|
-
* Get all datasources with POST to send plugins data in request body
|
|
168
|
-
* This is the primary method to get all datasources, especially when using plugins
|
|
169
|
-
*/
|
|
98
|
+
getDatasource(datasourceId: string, params: Record<string, unknown>): Promise<ServiceDatasourceWithData>;
|
|
170
99
|
postAllDatasources(): Promise<ServiceDatasource[]>;
|
|
171
|
-
/**
|
|
172
|
-
* Get all tools that implement a specific interface
|
|
173
|
-
*/
|
|
174
100
|
getToolsByInterface(interfaceType: ToolInterfaceType): Promise<ToolConfig[]>;
|
|
175
|
-
/**
|
|
176
|
-
* Get available interfaces from tools
|
|
177
|
-
*/
|
|
178
101
|
getAvailableInterfaces(): Promise<ToolInterfaceType[]>;
|
|
179
|
-
/**
|
|
180
|
-
* Get all agents defined by the service
|
|
181
|
-
*/
|
|
182
102
|
getAgents(): Promise<ServiceAgent[]>;
|
|
183
|
-
/**
|
|
184
|
-
* List agents using POST to send plugins data in request body
|
|
185
|
-
* This is the primary method to get agents, especially when using plugins
|
|
186
|
-
*/
|
|
187
103
|
listAgents(): Promise<ServiceAgent[]>;
|
|
188
|
-
/**
|
|
189
|
-
* Get a specific agent by ID
|
|
190
|
-
*/
|
|
191
104
|
getAgent(agentId: string): Promise<ServiceAgent>;
|
|
192
|
-
/**
|
|
193
|
-
* Get specific agent using POST to send plugins data in request body
|
|
194
|
-
* This is the primary method to get agent data, especially when using plugins
|
|
195
|
-
*/
|
|
196
105
|
postAgent(agentId: string): Promise<ServiceAgent>;
|
|
197
106
|
private sanitizeToolResponse;
|
|
198
107
|
}
|