@dainprotocol/service-sdk 2.0.94 → 2.1.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/README.md +29 -0
- package/dist/client/api-sdk.d.ts +7 -1
- package/dist/client/api-sdk.js +2 -2
- package/dist/client/api-sdk.js.map +1 -1
- package/dist/client/client-auth.d.ts +38 -0
- package/dist/client/client-auth.js +131 -2
- package/dist/client/client-auth.js.map +1 -1
- package/dist/client/client.d.ts +1 -0
- package/dist/client/client.js +92 -25
- package/dist/client/client.js.map +1 -1
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.js +1 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +252 -0
- package/dist/client/types.js +159 -31
- package/dist/client/types.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/plugins/crypto-plugin.d.ts +26 -0
- package/dist/plugins/crypto-plugin.js +44 -4
- package/dist/plugins/crypto-plugin.js.map +1 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/index.js.map +1 -1
- package/dist/protocol/account.d.ts +91 -0
- package/dist/protocol/account.js +3 -0
- package/dist/protocol/account.js.map +1 -0
- package/dist/protocol/grants.d.ts +34 -0
- package/dist/protocol/grants.js +3 -0
- package/dist/protocol/grants.js.map +1 -0
- package/dist/protocol/index.d.ts +8 -0
- package/dist/protocol/index.js +12 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/payments.d.ts +53 -0
- package/dist/protocol/payments.js +3 -0
- package/dist/protocol/payments.js.map +1 -0
- package/dist/protocol/permissions.d.ts +21 -0
- package/dist/protocol/permissions.js +3 -0
- package/dist/protocol/permissions.js.map +1 -0
- package/dist/protocol/programs.d.ts +44 -0
- package/dist/protocol/programs.js +46 -0
- package/dist/protocol/programs.js.map +1 -0
- package/dist/protocol/registry.d.ts +43 -0
- package/dist/protocol/registry.js +3 -0
- package/dist/protocol/registry.js.map +1 -0
- package/dist/protocol/runtime.d.ts +15 -0
- package/dist/protocol/runtime.js +3 -0
- package/dist/protocol/runtime.js.map +1 -0
- package/dist/protocol/transactions.d.ts +63 -0
- package/dist/protocol/transactions.js +3 -0
- package/dist/protocol/transactions.js.map +1 -0
- package/dist/service/auth.d.ts +15 -1
- package/dist/service/auth.js +156 -35
- package/dist/service/auth.js.map +1 -1
- package/dist/service/core.js +9 -0
- package/dist/service/core.js.map +1 -1
- package/dist/service/index.d.ts +1 -0
- package/dist/service/index.js +1 -0
- package/dist/service/index.js.map +1 -1
- package/dist/service/nodeService.js +30 -2
- package/dist/service/nodeService.js.map +1 -1
- package/dist/service/server.js +733 -242
- package/dist/service/server.js.map +1 -1
- package/dist/service/service.js +6 -8
- package/dist/service/service.js.map +1 -1
- package/dist/service/types.d.ts +48 -34
- package/package.json +20 -7
package/dist/service/types.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { ServerType } from "@hono/node-server/.";
|
|
|
7
7
|
import { DainPlugin } from "../plugins/types";
|
|
8
8
|
import { StorageAdapter } from "@dainprotocol/oauth2-token-manager";
|
|
9
9
|
import { DirectAuthSetupManager } from "./direct-auth-setup";
|
|
10
|
+
import type { DainAccountContext, DainActionGrant, DainAuthContext, DainDataPermissionGrant, DainGroupContext, DainRuntimeContext, DainServiceRegistryPolicy } from "../protocol";
|
|
10
11
|
export interface SimpleOAuth2Client {
|
|
11
12
|
getAccessToken: (provider: string, email: string, options?: any) => Promise<string | null>;
|
|
12
13
|
getValidToken: (provider: string, email: string, options?: any) => Promise<any>;
|
|
@@ -19,9 +20,23 @@ export type AgentInfo = {
|
|
|
19
20
|
agentId: string;
|
|
20
21
|
address: string;
|
|
21
22
|
smartAccountPDA?: string;
|
|
23
|
+
dainAccountId?: string;
|
|
24
|
+
dainGroupId?: string;
|
|
25
|
+
account?: DainAccountContext;
|
|
26
|
+
group?: DainGroupContext;
|
|
27
|
+
auth?: DainAuthContext;
|
|
28
|
+
grants?: DainActionGrant[];
|
|
29
|
+
dataPermissions?: DainDataPermissionGrant[];
|
|
30
|
+
registryPolicy?: DainServiceRegistryPolicy;
|
|
22
31
|
id: string;
|
|
23
32
|
webhookUrl?: string;
|
|
24
33
|
};
|
|
34
|
+
export type ServiceExtraData = DainRuntimeContext & {
|
|
35
|
+
plugins?: Record<string, any>;
|
|
36
|
+
oauth2Client?: SimpleOAuth2Client;
|
|
37
|
+
app?: Hono;
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
};
|
|
25
40
|
/**
|
|
26
41
|
* Context for HITL action routing
|
|
27
42
|
* Contains user and platform information for action tracking
|
|
@@ -67,6 +82,7 @@ export type Metadata = {
|
|
|
67
82
|
contractVersion?: string;
|
|
68
83
|
capabilities?: ServiceCapabilities;
|
|
69
84
|
compatibility?: ContractCompatibility;
|
|
85
|
+
registryPolicy?: DainServiceRegistryPolicy;
|
|
70
86
|
};
|
|
71
87
|
export type ServiceCapabilities = {
|
|
72
88
|
tools?: boolean;
|
|
@@ -78,6 +94,12 @@ export type ServiceCapabilities = {
|
|
|
78
94
|
datasourcePolicy?: boolean;
|
|
79
95
|
widgetPolicy?: boolean;
|
|
80
96
|
toolSafety?: boolean;
|
|
97
|
+
dainAccount?: boolean;
|
|
98
|
+
registryDiscovery?: boolean;
|
|
99
|
+
dataPermissions?: boolean;
|
|
100
|
+
actionGrants?: boolean;
|
|
101
|
+
smartAccountTransactions?: boolean;
|
|
102
|
+
payments?: boolean;
|
|
81
103
|
[key: string]: unknown;
|
|
82
104
|
};
|
|
83
105
|
export type ContractCompatibility = {
|
|
@@ -97,7 +119,16 @@ export type Identity = {
|
|
|
97
119
|
export type ToolContext = {
|
|
98
120
|
app: Hono;
|
|
99
121
|
oauth2Client?: SimpleOAuth2Client;
|
|
100
|
-
extraData?:
|
|
122
|
+
extraData?: ServiceExtraData;
|
|
123
|
+
dainAccountId?: string;
|
|
124
|
+
dainGroupId?: string;
|
|
125
|
+
smartAccountPDA?: string;
|
|
126
|
+
account?: DainAccountContext;
|
|
127
|
+
group?: DainGroupContext;
|
|
128
|
+
auth?: DainAuthContext;
|
|
129
|
+
grants?: DainActionGrant[];
|
|
130
|
+
dataPermissions?: DainDataPermissionGrant[];
|
|
131
|
+
registryPolicy?: DainServiceRegistryPolicy;
|
|
101
132
|
updateUI?: (update: {
|
|
102
133
|
ui?: any;
|
|
103
134
|
type?: string;
|
|
@@ -236,7 +267,7 @@ export type ToolConfig<TInput extends z.ZodType = any, TOutput extends z.ZodType
|
|
|
236
267
|
type: "one-time" | "recurring";
|
|
237
268
|
}[];
|
|
238
269
|
}>;
|
|
239
|
-
handleInputError?: (error: ZodError, agentInfo: AgentInfo, extraData?:
|
|
270
|
+
handleInputError?: (error: ZodError, agentInfo: AgentInfo, extraData?: ToolContext) => Promise<{
|
|
240
271
|
success?: boolean;
|
|
241
272
|
text: string;
|
|
242
273
|
data: z.output<TOutput>;
|
|
@@ -266,11 +297,7 @@ export interface ServiceContext<TData = any> {
|
|
|
266
297
|
id: string;
|
|
267
298
|
name: string;
|
|
268
299
|
description: string;
|
|
269
|
-
getContextData: (agentInfo: AgentInfo, extraData?:
|
|
270
|
-
plugins?: Record<string, any>;
|
|
271
|
-
oauth2Client?: SimpleOAuth2Client;
|
|
272
|
-
[key: string]: any;
|
|
273
|
-
}) => Promise<TData>;
|
|
300
|
+
getContextData: (agentInfo: AgentInfo, extraData?: ServiceExtraData) => Promise<TData>;
|
|
274
301
|
}
|
|
275
302
|
export type DatasourceType = "metadata" | "data" | "config" | "file" | "state" | "crypto" | "json" | "csv" | "xml" | "text";
|
|
276
303
|
export type DatasourceTransport = "stream" | "poll" | "hybrid";
|
|
@@ -292,11 +319,7 @@ export interface ServiceDatasource<TInput extends z.ZodType = any, TData = any>
|
|
|
292
319
|
scope?: DatasourceScope;
|
|
293
320
|
dataClass?: string;
|
|
294
321
|
input: TInput;
|
|
295
|
-
getDatasource: (agentInfo: AgentInfo, params: z.infer<TInput>, extraData?:
|
|
296
|
-
plugins?: Record<string, any>;
|
|
297
|
-
oauth2Client?: SimpleOAuth2Client;
|
|
298
|
-
[key: string]: any;
|
|
299
|
-
}) => Promise<TData>;
|
|
322
|
+
getDatasource: (agentInfo: AgentInfo, params: z.infer<TInput>, extraData?: ServiceExtraData) => Promise<TData>;
|
|
300
323
|
}
|
|
301
324
|
export type ServiceWidget = {
|
|
302
325
|
id: string;
|
|
@@ -309,11 +332,7 @@ export type ServiceWidget = {
|
|
|
309
332
|
* UI runtimes clamp this interval to safe bounds.
|
|
310
333
|
*/
|
|
311
334
|
refreshIntervalMs?: number;
|
|
312
|
-
getWidget: (agentInfo: AgentInfo, extraData?: {
|
|
313
|
-
plugins?: Record<string, any>;
|
|
314
|
-
oauth2Client?: SimpleOAuth2Client;
|
|
315
|
-
[key: string]: any;
|
|
316
|
-
}) => Promise<{
|
|
335
|
+
getWidget: (agentInfo: AgentInfo, extraData?: ServiceExtraData) => Promise<{
|
|
317
336
|
text?: string;
|
|
318
337
|
data?: any;
|
|
319
338
|
ui?: any;
|
|
@@ -370,7 +389,7 @@ export interface ServiceAgent<TInput extends z.ZodType = any, TOutput extends z.
|
|
|
370
389
|
output: TOutput;
|
|
371
390
|
}
|
|
372
391
|
export type DAINServiceConfig = {
|
|
373
|
-
metadata: Omit<Metadata,
|
|
392
|
+
metadata: Omit<Metadata, "id" | "orgId" | "agentId"> & {
|
|
374
393
|
id?: string;
|
|
375
394
|
orgId?: string;
|
|
376
395
|
agentId?: string;
|
|
@@ -386,14 +405,8 @@ export type DAINServiceConfig = {
|
|
|
386
405
|
datasources?: ServiceDatasource[];
|
|
387
406
|
widgets?: ServiceWidget[];
|
|
388
407
|
agents?: ServiceAgent[];
|
|
389
|
-
getUserWidgets?: (agentInfo: AgentInfo, extraData?:
|
|
390
|
-
|
|
391
|
-
[key: string]: any;
|
|
392
|
-
}) => Promise<string[]>;
|
|
393
|
-
homeUI?: string | ((agentInfo: AgentInfo, extraData?: {
|
|
394
|
-
plugins?: Record<string, any>;
|
|
395
|
-
[key: string]: any;
|
|
396
|
-
}) => Promise<string>);
|
|
408
|
+
getUserWidgets?: (agentInfo: AgentInfo, extraData?: ServiceExtraData) => Promise<string[]>;
|
|
409
|
+
homeUI?: string | ((agentInfo: AgentInfo, extraData?: ServiceExtraData) => Promise<string>);
|
|
397
410
|
plugins?: DainPlugin[];
|
|
398
411
|
oauth2?: OAuth2Config & {
|
|
399
412
|
baseUrl: string;
|
|
@@ -415,8 +428,8 @@ export type DAINServiceConfig = {
|
|
|
415
428
|
dainIdUrl?: string;
|
|
416
429
|
jwtIssuer?: string;
|
|
417
430
|
platformBaseUrl?: string;
|
|
418
|
-
webhookTriggers?: import(
|
|
419
|
-
skills?: import(
|
|
431
|
+
webhookTriggers?: import("./webhooks").WebhookTriggerRegistry;
|
|
432
|
+
skills?: import("./skills").SkillRegistry;
|
|
420
433
|
hitl?: {
|
|
421
434
|
/** Enable HITL action webhook */
|
|
422
435
|
enabled: boolean;
|
|
@@ -493,9 +506,9 @@ export interface DirectProviderConfig {
|
|
|
493
506
|
* Allows type-safe handling of different authentication patterns
|
|
494
507
|
*/
|
|
495
508
|
export type AuthProviderConfig = (OAuth2ProviderConfig & {
|
|
496
|
-
type:
|
|
509
|
+
type: "oauth2";
|
|
497
510
|
}) | (DirectProviderConfig & {
|
|
498
|
-
type:
|
|
511
|
+
type: "direct";
|
|
499
512
|
});
|
|
500
513
|
/**
|
|
501
514
|
* Provider information returned to clients
|
|
@@ -503,7 +516,7 @@ export type AuthProviderConfig = (OAuth2ProviderConfig & {
|
|
|
503
516
|
*/
|
|
504
517
|
export interface ProviderInfo {
|
|
505
518
|
name: string;
|
|
506
|
-
type:
|
|
519
|
+
type: "oauth2" | "direct";
|
|
507
520
|
connected: boolean;
|
|
508
521
|
reason?: string;
|
|
509
522
|
requiredTools?: string[];
|
|
@@ -515,14 +528,14 @@ export interface ProviderInfo {
|
|
|
515
528
|
* OAuth2 authentication method details
|
|
516
529
|
*/
|
|
517
530
|
export interface OAuth2AuthMethod {
|
|
518
|
-
type:
|
|
531
|
+
type: "oauth2";
|
|
519
532
|
authUrl: string;
|
|
520
533
|
}
|
|
521
534
|
/**
|
|
522
535
|
* Direct configuration authentication method details
|
|
523
536
|
*/
|
|
524
537
|
export interface DirectAuthMethod {
|
|
525
|
-
type:
|
|
538
|
+
type: "direct";
|
|
526
539
|
onboardingTool: string;
|
|
527
540
|
}
|
|
528
541
|
export type OAuth2Config = {
|
|
@@ -545,7 +558,7 @@ declare module "hono" {
|
|
|
545
558
|
processes?: ProcessHandler;
|
|
546
559
|
}
|
|
547
560
|
interface ContextVariableMap {
|
|
548
|
-
authMethod?:
|
|
561
|
+
authMethod?: "jwt" | "apiKey";
|
|
549
562
|
smartAccountId?: string;
|
|
550
563
|
scope?: string[];
|
|
551
564
|
jwtPayload?: any;
|
|
@@ -553,5 +566,6 @@ declare module "hono" {
|
|
|
553
566
|
orgId?: string;
|
|
554
567
|
address?: string;
|
|
555
568
|
smartAccountPDA?: string;
|
|
569
|
+
dainRuntimeContext?: DainRuntimeContext;
|
|
556
570
|
}
|
|
557
571
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dainprotocol/service-sdk",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "DAIN Service SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"private": false,
|
|
8
|
+
"packageManager": "bun@1.3.13",
|
|
9
|
+
"engines": {
|
|
10
|
+
"bun": ">=1.3.13"
|
|
11
|
+
},
|
|
8
12
|
"publishConfig": {
|
|
9
13
|
"access": "public"
|
|
10
14
|
},
|
|
@@ -57,6 +61,10 @@
|
|
|
57
61
|
"types": "./dist/lib/payments/index.d.ts",
|
|
58
62
|
"default": "./dist/lib/payments/index.js"
|
|
59
63
|
},
|
|
64
|
+
"./protocol": {
|
|
65
|
+
"types": "./dist/protocol/index.d.ts",
|
|
66
|
+
"default": "./dist/protocol/index.js"
|
|
67
|
+
},
|
|
60
68
|
"./plugins": {
|
|
61
69
|
"types": "./dist/plugins/index.d.ts",
|
|
62
70
|
"default": "./dist/plugins/index.js"
|
|
@@ -103,16 +111,21 @@
|
|
|
103
111
|
],
|
|
104
112
|
"payments": [
|
|
105
113
|
"./dist/lib/payments/index.d.ts"
|
|
114
|
+
],
|
|
115
|
+
"protocol": [
|
|
116
|
+
"./dist/protocol/index.d.ts"
|
|
106
117
|
]
|
|
107
118
|
}
|
|
108
119
|
},
|
|
109
120
|
"scripts": {
|
|
110
|
-
"build": "tsc",
|
|
111
|
-
"build:types": "tsc --emitDeclarationOnly",
|
|
112
|
-
"test": "
|
|
113
|
-
"test:
|
|
114
|
-
"
|
|
115
|
-
"test:
|
|
121
|
+
"build": "bunx --bun tsc",
|
|
122
|
+
"build:types": "bunx --bun tsc --emitDeclarationOnly",
|
|
123
|
+
"test": "bun test --parallel=4",
|
|
124
|
+
"test:serial": "bun test --isolate",
|
|
125
|
+
"test:watch": "bun test --watch --isolate",
|
|
126
|
+
"test:jest": "jest --runInBand",
|
|
127
|
+
"prepublishOnly": "bun run build && bun run build:types",
|
|
128
|
+
"test:streaming": "bun test src/__tests__/streaming.test.ts --isolate"
|
|
116
129
|
},
|
|
117
130
|
"keywords": [
|
|
118
131
|
"dain",
|