@blocksdiy/blocks-client-sdk 1.7.0 → 1.8.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/dist/Action.d.ts +6 -43
- package/dist/Action.d.ts.map +1 -1
- package/dist/Action.js +6 -43
- package/dist/Agent.d.ts +43 -0
- package/dist/Agent.d.ts.map +1 -0
- package/dist/Agent.js +37 -0
- package/dist/ClientSdk.d.ts +17 -59
- package/dist/ClientSdk.d.ts.map +1 -1
- package/dist/ClientSdk.js +23 -59
- package/dist/Entity.d.ts +14 -79
- package/dist/Entity.d.ts.map +1 -1
- package/dist/Entity.js +14 -79
- package/dist/ReactClientSdk.d.ts +43 -99
- package/dist/ReactClientSdk.d.ts.map +1 -1
- package/dist/ReactClientSdk.jsx +45 -99
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +2 -2
package/dist/Action.d.ts
CHANGED
|
@@ -58,22 +58,9 @@ export declare class Action<AC extends ActionConfig = ActionConfig> {
|
|
|
58
58
|
* @returns {Promise<AC["outputInstanceType"]>} The action result
|
|
59
59
|
* @example
|
|
60
60
|
* ```ts
|
|
61
|
-
*
|
|
62
|
-
* const processOrderConfig = {
|
|
63
|
-
* actionBlockId: 'process-order-id',
|
|
64
|
-
* inputInstanceType: {} as {
|
|
65
|
-
* orderId: string;
|
|
66
|
-
* userId: string;
|
|
67
|
-
* items: Array<{ productId: string; quantity: number }>;
|
|
68
|
-
* },
|
|
69
|
-
* outputInstanceType: {} as {
|
|
70
|
-
* success: boolean;
|
|
71
|
-
* orderNumber: string;
|
|
72
|
-
* estimatedDelivery: string;
|
|
73
|
-
* }
|
|
74
|
-
* };
|
|
61
|
+
* import { ProcessOrderAction } from '@/product-types';
|
|
75
62
|
*
|
|
76
|
-
* const orderAction = new Action(
|
|
63
|
+
* const orderAction = new Action(ProcessOrderAction);
|
|
77
64
|
* const result = await orderAction.execute({
|
|
78
65
|
* orderId: 'order-123',
|
|
79
66
|
* userId: 'user-456',
|
|
@@ -83,22 +70,9 @@ export declare class Action<AC extends ActionConfig = ActionConfig> {
|
|
|
83
70
|
* console.log(`Order processed: ${result.orderNumber}`);
|
|
84
71
|
*
|
|
85
72
|
* // Example 2: Integration with external service
|
|
86
|
-
*
|
|
87
|
-
* actionBlockId: 'send-email-id',
|
|
88
|
-
* inputInstanceType: {} as {
|
|
89
|
-
* to: string;
|
|
90
|
-
* subject: string;
|
|
91
|
-
* body: string;
|
|
92
|
-
* attachments?: Array<{ name: string; url: string }>;
|
|
93
|
-
* },
|
|
94
|
-
* outputInstanceType: {} as {
|
|
95
|
-
* sent: boolean;
|
|
96
|
-
* messageId?: string;
|
|
97
|
-
* error?: string;
|
|
98
|
-
* }
|
|
99
|
-
* };
|
|
73
|
+
* import { SendEmailAction } from '@/product-types';
|
|
100
74
|
*
|
|
101
|
-
* const emailAction = new Action(
|
|
75
|
+
* const emailAction = new Action(SendEmailAction);
|
|
102
76
|
* const emailResult = await emailAction.execute({
|
|
103
77
|
* to: 'user@example.com',
|
|
104
78
|
* subject: 'Welcome to our platform',
|
|
@@ -106,20 +80,9 @@ export declare class Action<AC extends ActionConfig = ActionConfig> {
|
|
|
106
80
|
* });
|
|
107
81
|
*
|
|
108
82
|
* // Example 3: Action with streaming response
|
|
109
|
-
*
|
|
110
|
-
* actionBlockId: 'generate-report-id',
|
|
111
|
-
* inputInstanceType: {} as {
|
|
112
|
-
* type: 'sales' | 'inventory';
|
|
113
|
-
* period: 'daily' | 'weekly' | 'monthly';
|
|
114
|
-
* filters: Record<string, any>;
|
|
115
|
-
* },
|
|
116
|
-
* outputInstanceType: {} as {
|
|
117
|
-
* reportUrl: string;
|
|
118
|
-
* summary: string;
|
|
119
|
-
* }
|
|
120
|
-
* };
|
|
83
|
+
* import { GenerateReportAction } from '@/product-types';
|
|
121
84
|
*
|
|
122
|
-
* const reportAction = new Action(
|
|
85
|
+
* const reportAction = new Action(GenerateReportAction);
|
|
123
86
|
* const reportResult = await reportAction.execute(
|
|
124
87
|
* {
|
|
125
88
|
* type: 'sales',
|
package/dist/Action.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Action.d.ts","sourceRoot":"","sources":["../src/Action.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,YAAY,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE;IAC5G,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,EAAE,CAAC;IACtB,kBAAkB,EAAE,EAAE,CAAC;CACxB;AAED;;;;;;;;;GASG;AACH,qBAAa,MAAM,CAAC,EAAE,SAAS,YAAY,GAAG,YAAY;IACxD,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAC,CAAyB;IACzC,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB;;;OAGG;gBAED,MAAM,EAAE,EAAE,EACV,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAUhG
|
|
1
|
+
{"version":3,"file":"Action.d.ts","sourceRoot":"","sources":["../src/Action.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,YAAY,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE;IAC5G,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,EAAE,CAAC;IACtB,kBAAkB,EAAE,EAAE,CAAC;CACxB;AAED;;;;;;;;;GASG;AACH,qBAAa,MAAM,CAAC,EAAE,SAAS,YAAY,GAAG,YAAY;IACxD,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAC,CAAyB;IACzC,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB;;;OAGG;gBAED,MAAM,EAAE,EAAE,EACV,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAUhG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmDG;IACG,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,mBAAmB,CAAC,EAAE,EAAE,OAAO,EAAE,GAAE;QAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAA;KAAO;CAuBnG"}
|
package/dist/Action.js
CHANGED
|
@@ -40,22 +40,9 @@ export class Action {
|
|
|
40
40
|
* @returns {Promise<AC["outputInstanceType"]>} The action result
|
|
41
41
|
* @example
|
|
42
42
|
* ```ts
|
|
43
|
-
*
|
|
44
|
-
* const processOrderConfig = {
|
|
45
|
-
* actionBlockId: 'process-order-id',
|
|
46
|
-
* inputInstanceType: {} as {
|
|
47
|
-
* orderId: string;
|
|
48
|
-
* userId: string;
|
|
49
|
-
* items: Array<{ productId: string; quantity: number }>;
|
|
50
|
-
* },
|
|
51
|
-
* outputInstanceType: {} as {
|
|
52
|
-
* success: boolean;
|
|
53
|
-
* orderNumber: string;
|
|
54
|
-
* estimatedDelivery: string;
|
|
55
|
-
* }
|
|
56
|
-
* };
|
|
43
|
+
* import { ProcessOrderAction } from '@/product-types';
|
|
57
44
|
*
|
|
58
|
-
* const orderAction = new Action(
|
|
45
|
+
* const orderAction = new Action(ProcessOrderAction);
|
|
59
46
|
* const result = await orderAction.execute({
|
|
60
47
|
* orderId: 'order-123',
|
|
61
48
|
* userId: 'user-456',
|
|
@@ -65,22 +52,9 @@ export class Action {
|
|
|
65
52
|
* console.log(`Order processed: ${result.orderNumber}`);
|
|
66
53
|
*
|
|
67
54
|
* // Example 2: Integration with external service
|
|
68
|
-
*
|
|
69
|
-
* actionBlockId: 'send-email-id',
|
|
70
|
-
* inputInstanceType: {} as {
|
|
71
|
-
* to: string;
|
|
72
|
-
* subject: string;
|
|
73
|
-
* body: string;
|
|
74
|
-
* attachments?: Array<{ name: string; url: string }>;
|
|
75
|
-
* },
|
|
76
|
-
* outputInstanceType: {} as {
|
|
77
|
-
* sent: boolean;
|
|
78
|
-
* messageId?: string;
|
|
79
|
-
* error?: string;
|
|
80
|
-
* }
|
|
81
|
-
* };
|
|
55
|
+
* import { SendEmailAction } from '@/product-types';
|
|
82
56
|
*
|
|
83
|
-
* const emailAction = new Action(
|
|
57
|
+
* const emailAction = new Action(SendEmailAction);
|
|
84
58
|
* const emailResult = await emailAction.execute({
|
|
85
59
|
* to: 'user@example.com',
|
|
86
60
|
* subject: 'Welcome to our platform',
|
|
@@ -88,20 +62,9 @@ export class Action {
|
|
|
88
62
|
* });
|
|
89
63
|
*
|
|
90
64
|
* // Example 3: Action with streaming response
|
|
91
|
-
*
|
|
92
|
-
* actionBlockId: 'generate-report-id',
|
|
93
|
-
* inputInstanceType: {} as {
|
|
94
|
-
* type: 'sales' | 'inventory';
|
|
95
|
-
* period: 'daily' | 'weekly' | 'monthly';
|
|
96
|
-
* filters: Record<string, any>;
|
|
97
|
-
* },
|
|
98
|
-
* outputInstanceType: {} as {
|
|
99
|
-
* reportUrl: string;
|
|
100
|
-
* summary: string;
|
|
101
|
-
* }
|
|
102
|
-
* };
|
|
65
|
+
* import { GenerateReportAction } from '@/product-types';
|
|
103
66
|
*
|
|
104
|
-
* const reportAction = new Action(
|
|
67
|
+
* const reportAction = new Action(GenerateReportAction);
|
|
105
68
|
* const reportResult = await reportAction.execute(
|
|
106
69
|
* {
|
|
107
70
|
* type: 'sales',
|
package/dist/Agent.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for defining an agent.
|
|
3
|
+
*
|
|
4
|
+
* This interface is used to define the structure of an app agent generated from product-types.
|
|
5
|
+
*/
|
|
6
|
+
export interface AgentConfig {
|
|
7
|
+
id: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
harness?: string;
|
|
11
|
+
photoUrl?: string;
|
|
12
|
+
avatarUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Agent class for referencing an app agent.
|
|
16
|
+
*
|
|
17
|
+
* This class provides typed access to an agent's generated metadata.
|
|
18
|
+
*/
|
|
19
|
+
export declare class Agent<AC extends AgentConfig = AgentConfig> {
|
|
20
|
+
private id;
|
|
21
|
+
private name?;
|
|
22
|
+
private title?;
|
|
23
|
+
private harness?;
|
|
24
|
+
private photoUrl?;
|
|
25
|
+
private avatarUrl?;
|
|
26
|
+
private appId;
|
|
27
|
+
private token?;
|
|
28
|
+
constructor(config: AC, { appId, token }: {
|
|
29
|
+
appId: string;
|
|
30
|
+
token?: string;
|
|
31
|
+
});
|
|
32
|
+
getAgentProps(): {
|
|
33
|
+
id: string;
|
|
34
|
+
name: string | undefined;
|
|
35
|
+
title: string | undefined;
|
|
36
|
+
harness: string | undefined;
|
|
37
|
+
photoUrl: string | undefined;
|
|
38
|
+
avatarUrl: string | undefined;
|
|
39
|
+
appId: string;
|
|
40
|
+
token: string | undefined;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=Agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Agent.d.ts","sourceRoot":"","sources":["../src/Agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,qBAAa,KAAK,CAAC,EAAE,SAAS,WAAW,GAAG,WAAW;IACrD,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,IAAI,CAAC,CAAS;IACtB,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAC,CAAS;IAC1B,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,KAAK,CAAC,CAAS;gBAEX,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAW3E,aAAa;;;;;;;;;;CAYd"}
|
package/dist/Agent.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent class for referencing an app agent.
|
|
3
|
+
*
|
|
4
|
+
* This class provides typed access to an agent's generated metadata.
|
|
5
|
+
*/
|
|
6
|
+
export class Agent {
|
|
7
|
+
id;
|
|
8
|
+
name;
|
|
9
|
+
title;
|
|
10
|
+
harness;
|
|
11
|
+
photoUrl;
|
|
12
|
+
avatarUrl;
|
|
13
|
+
appId;
|
|
14
|
+
token;
|
|
15
|
+
constructor(config, { appId, token }) {
|
|
16
|
+
this.id = config.id;
|
|
17
|
+
this.name = config.name;
|
|
18
|
+
this.title = config.title;
|
|
19
|
+
this.harness = config.harness;
|
|
20
|
+
this.photoUrl = config.photoUrl;
|
|
21
|
+
this.avatarUrl = config.avatarUrl;
|
|
22
|
+
this.appId = appId;
|
|
23
|
+
this.token = token;
|
|
24
|
+
}
|
|
25
|
+
getAgentProps() {
|
|
26
|
+
return {
|
|
27
|
+
id: this.id,
|
|
28
|
+
name: this.name,
|
|
29
|
+
title: this.title,
|
|
30
|
+
harness: this.harness,
|
|
31
|
+
photoUrl: this.photoUrl,
|
|
32
|
+
avatarUrl: this.avatarUrl,
|
|
33
|
+
appId: this.appId,
|
|
34
|
+
token: this.token,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
package/dist/ClientSdk.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Action, type ActionConfig } from "./Action.js";
|
|
2
|
+
import { Agent, type AgentConfig } from "./Agent.js";
|
|
2
3
|
import { AgentChat, AgentChatConfig } from "./AgentChat.js";
|
|
3
4
|
import { Entity, type EntityConfig } from "./Entity.js";
|
|
4
5
|
import { Page, type PageConfig } from "./Page.js";
|
|
@@ -46,6 +47,7 @@ export interface ClientConfig {
|
|
|
46
47
|
* - Entities: Data objects stored in tables (CRUD operations)
|
|
47
48
|
* - Actions: Executable workflows that perform operations (any server-side logic)
|
|
48
49
|
* - Pages: Application pages with URL and parameter handling
|
|
50
|
+
* - Agents: App agents generated from product-types
|
|
49
51
|
* - AgentChat: Interact with the agent chat
|
|
50
52
|
* - User: The user's data
|
|
51
53
|
*
|
|
@@ -58,6 +60,7 @@ export declare class ClientSdk {
|
|
|
58
60
|
private readonly entities;
|
|
59
61
|
private readonly actions;
|
|
60
62
|
private readonly pages;
|
|
63
|
+
private readonly agentsMap;
|
|
61
64
|
private readonly agentChats;
|
|
62
65
|
/**
|
|
63
66
|
* Creates a new ClientSdk instance
|
|
@@ -82,18 +85,9 @@ export declare class ClientSdk {
|
|
|
82
85
|
* @returns {Entity<EC>} An Entity instance for the given configuration
|
|
83
86
|
* @example
|
|
84
87
|
* ```ts
|
|
85
|
-
*
|
|
86
|
-
* const userEntityConfig = {
|
|
87
|
-
* tableBlockId: 'users-table-id',
|
|
88
|
-
* instanceType: {} as {
|
|
89
|
-
* name: string;
|
|
90
|
-
* email: string;
|
|
91
|
-
* role: 'admin' | 'user';
|
|
92
|
-
* }
|
|
93
|
-
* };
|
|
88
|
+
* import { UserEntity } from '@/product-types';
|
|
94
89
|
*
|
|
95
|
-
*
|
|
96
|
-
* const userEntity = client.entity(userEntityConfig);
|
|
90
|
+
* const userEntity = client.entity(UserEntity);
|
|
97
91
|
*
|
|
98
92
|
* // Use it for CRUD operations
|
|
99
93
|
* const users = await userEntity.findMany();
|
|
@@ -118,47 +112,14 @@ export declare class ClientSdk {
|
|
|
118
112
|
* @returns {Action<AC>} An Action instance for the given configuration
|
|
119
113
|
* @example
|
|
120
114
|
* ```ts
|
|
121
|
-
*
|
|
122
|
-
* const processOrderConfig = {
|
|
123
|
-
* actionBlockId: 'process-order-id',
|
|
124
|
-
* inputInstanceType: {} as {
|
|
125
|
-
* orderId: string;
|
|
126
|
-
* userId: string;
|
|
127
|
-
* items: Array<{ productId: string; quantity: number }>;
|
|
128
|
-
* },
|
|
129
|
-
* outputInstanceType: {} as {
|
|
130
|
-
* success: boolean;
|
|
131
|
-
* orderNumber: string;
|
|
132
|
-
* estimatedDelivery: string;
|
|
133
|
-
* }
|
|
134
|
-
* };
|
|
115
|
+
* import { ProcessOrderAction } from '@/product-types';
|
|
135
116
|
*
|
|
136
|
-
* const processOrderAction = client.action(
|
|
117
|
+
* const processOrderAction = client.action(ProcessOrderAction);
|
|
137
118
|
* const result = await processOrderAction.execute({
|
|
138
119
|
* orderId: 'order-123',
|
|
139
120
|
* userId: 'user-456',
|
|
140
121
|
* items: [{ productId: 'prod-789', quantity: 2 }]
|
|
141
122
|
* });
|
|
142
|
-
*
|
|
143
|
-
* // Example 2: Authentication action
|
|
144
|
-
* const loginUserConfig = {
|
|
145
|
-
* actionBlockId: 'login-user-id',
|
|
146
|
-
* inputInstanceType: {} as {
|
|
147
|
-
* email: string;
|
|
148
|
-
* password: string;
|
|
149
|
-
* },
|
|
150
|
-
* outputInstanceType: {} as {
|
|
151
|
-
* success: boolean;
|
|
152
|
-
* token?: string;
|
|
153
|
-
* error?: string;
|
|
154
|
-
* }
|
|
155
|
-
* };
|
|
156
|
-
*
|
|
157
|
-
* const loginAction = client.action(loginUserConfig);
|
|
158
|
-
* const loginResult = await loginAction.execute({
|
|
159
|
-
* email: 'user@example.com',
|
|
160
|
-
* password: 'password123'
|
|
161
|
-
* });
|
|
162
123
|
* ```
|
|
163
124
|
*/
|
|
164
125
|
action<AC extends ActionConfig = ActionConfig>(actionConfig: AC): Action<AC>;
|
|
@@ -175,17 +136,18 @@ export declare class ClientSdk {
|
|
|
175
136
|
* @returns {Page<PC>} A Page instance for the given configuration
|
|
176
137
|
* @example
|
|
177
138
|
* ```ts
|
|
178
|
-
*
|
|
179
|
-
* const productPageConfig = {
|
|
180
|
-
* pageBlockId: 'product-page-id'
|
|
181
|
-
* pageName: 'product-page'
|
|
182
|
-
* };
|
|
139
|
+
* import { ProductPage } from '@/product-types';
|
|
183
140
|
*
|
|
184
|
-
*
|
|
185
|
-
* const productPage = client.page(productPageConfig);
|
|
141
|
+
* const productPage = client.page(ProductPage);
|
|
186
142
|
* ```
|
|
187
143
|
*/
|
|
188
144
|
page<PC extends PageConfig = PageConfig>(pageConfig: PC): Page<PC>;
|
|
145
|
+
/**
|
|
146
|
+
* Gets or creates an Agent instance for the specified agent configuration.
|
|
147
|
+
*
|
|
148
|
+
* An Agent represents an app agent generated from product-types.
|
|
149
|
+
*/
|
|
150
|
+
agent<AC extends AgentConfig = AgentConfig>(agentConfig: AC): Agent<AC>;
|
|
189
151
|
/**
|
|
190
152
|
* Gets or creates an AgentChat instance for the specified agent chat configuration
|
|
191
153
|
*
|
|
@@ -198,13 +160,9 @@ export declare class ClientSdk {
|
|
|
198
160
|
* @returns {AgentChat<ACC>} An AgentChat instance for the given configuration
|
|
199
161
|
* @example
|
|
200
162
|
* ```ts
|
|
201
|
-
*
|
|
202
|
-
* const agentChatConfig = {
|
|
203
|
-
* agentChatId: 'agent-chat-id'
|
|
204
|
-
* };
|
|
163
|
+
* import { CustomerSupportChatAgent } from '@/product-types';
|
|
205
164
|
*
|
|
206
|
-
*
|
|
207
|
-
* const agentChat = client.agentChat(agentChatConfig);
|
|
165
|
+
* const agentChat = client.agentChat(CustomerSupportChatAgent);
|
|
208
166
|
* ```
|
|
209
167
|
*/
|
|
210
168
|
agentChat<ACC extends AgentChatConfig = AgentChatConfig>(agentChatConfig: ACC): AgentChat<ACC>;
|
package/dist/ClientSdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientSdk.d.ts","sourceRoot":"","sources":["../src/ClientSdk.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE/C;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,IAAI;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MA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G,eAAe,EAAE,eAAe,EAAE,GAAG,GAQhB,SAAS,CAAC,GAAG,CAAC;YAG7D,YAAY;IAiCpB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAyCvG;;;;;;;;;;;;;OAaG;IACH,OAAO;IAIP;;;;;;;;;;OAUG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB;IAoBlF;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,aAAa,CAAC,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE;IAmBhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,iBAAiB;CAGlB"}
|
package/dist/ClientSdk.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AppVersionService } from "@blocksdiy/blocks-client-api/appVersionService";
|
|
2
2
|
import { getGoogleBaseUrl, getHost } from "@blocksdiy/blocks-client-api/envService";
|
|
3
3
|
import { Action } from "./Action.js";
|
|
4
|
+
import { Agent } from "./Agent.js";
|
|
4
5
|
import { AgentChat } from "./AgentChat.js";
|
|
5
6
|
import { Entity } from "./Entity.js";
|
|
6
7
|
import { Page } from "./Page.js";
|
|
@@ -11,6 +12,7 @@ import { Page } from "./Page.js";
|
|
|
11
12
|
* - Entities: Data objects stored in tables (CRUD operations)
|
|
12
13
|
* - Actions: Executable workflows that perform operations (any server-side logic)
|
|
13
14
|
* - Pages: Application pages with URL and parameter handling
|
|
15
|
+
* - Agents: App agents generated from product-types
|
|
14
16
|
* - AgentChat: Interact with the agent chat
|
|
15
17
|
* - User: The user's data
|
|
16
18
|
*
|
|
@@ -23,6 +25,7 @@ export class ClientSdk {
|
|
|
23
25
|
entities;
|
|
24
26
|
actions;
|
|
25
27
|
pages;
|
|
28
|
+
agentsMap;
|
|
26
29
|
agentChats;
|
|
27
30
|
/**
|
|
28
31
|
* Creates a new ClientSdk instance
|
|
@@ -38,6 +41,7 @@ export class ClientSdk {
|
|
|
38
41
|
this.entities = new Map();
|
|
39
42
|
this.actions = new Map();
|
|
40
43
|
this.pages = new Map();
|
|
44
|
+
this.agentsMap = new Map();
|
|
41
45
|
this.agentChats = new Map();
|
|
42
46
|
}
|
|
43
47
|
async authenticate() {
|
|
@@ -66,18 +70,9 @@ export class ClientSdk {
|
|
|
66
70
|
* @returns {Entity<EC>} An Entity instance for the given configuration
|
|
67
71
|
* @example
|
|
68
72
|
* ```ts
|
|
69
|
-
*
|
|
70
|
-
* const userEntityConfig = {
|
|
71
|
-
* tableBlockId: 'users-table-id',
|
|
72
|
-
* instanceType: {} as {
|
|
73
|
-
* name: string;
|
|
74
|
-
* email: string;
|
|
75
|
-
* role: 'admin' | 'user';
|
|
76
|
-
* }
|
|
77
|
-
* };
|
|
73
|
+
* import { UserEntity } from '@/product-types';
|
|
78
74
|
*
|
|
79
|
-
*
|
|
80
|
-
* const userEntity = client.entity(userEntityConfig);
|
|
75
|
+
* const userEntity = client.entity(UserEntity);
|
|
81
76
|
*
|
|
82
77
|
* // Use it for CRUD operations
|
|
83
78
|
* const users = await userEntity.findMany();
|
|
@@ -107,47 +102,14 @@ export class ClientSdk {
|
|
|
107
102
|
* @returns {Action<AC>} An Action instance for the given configuration
|
|
108
103
|
* @example
|
|
109
104
|
* ```ts
|
|
110
|
-
*
|
|
111
|
-
* const processOrderConfig = {
|
|
112
|
-
* actionBlockId: 'process-order-id',
|
|
113
|
-
* inputInstanceType: {} as {
|
|
114
|
-
* orderId: string;
|
|
115
|
-
* userId: string;
|
|
116
|
-
* items: Array<{ productId: string; quantity: number }>;
|
|
117
|
-
* },
|
|
118
|
-
* outputInstanceType: {} as {
|
|
119
|
-
* success: boolean;
|
|
120
|
-
* orderNumber: string;
|
|
121
|
-
* estimatedDelivery: string;
|
|
122
|
-
* }
|
|
123
|
-
* };
|
|
105
|
+
* import { ProcessOrderAction } from '@/product-types';
|
|
124
106
|
*
|
|
125
|
-
* const processOrderAction = client.action(
|
|
107
|
+
* const processOrderAction = client.action(ProcessOrderAction);
|
|
126
108
|
* const result = await processOrderAction.execute({
|
|
127
109
|
* orderId: 'order-123',
|
|
128
110
|
* userId: 'user-456',
|
|
129
111
|
* items: [{ productId: 'prod-789', quantity: 2 }]
|
|
130
112
|
* });
|
|
131
|
-
*
|
|
132
|
-
* // Example 2: Authentication action
|
|
133
|
-
* const loginUserConfig = {
|
|
134
|
-
* actionBlockId: 'login-user-id',
|
|
135
|
-
* inputInstanceType: {} as {
|
|
136
|
-
* email: string;
|
|
137
|
-
* password: string;
|
|
138
|
-
* },
|
|
139
|
-
* outputInstanceType: {} as {
|
|
140
|
-
* success: boolean;
|
|
141
|
-
* token?: string;
|
|
142
|
-
* error?: string;
|
|
143
|
-
* }
|
|
144
|
-
* };
|
|
145
|
-
*
|
|
146
|
-
* const loginAction = client.action(loginUserConfig);
|
|
147
|
-
* const loginResult = await loginAction.execute({
|
|
148
|
-
* email: 'user@example.com',
|
|
149
|
-
* password: 'password123'
|
|
150
|
-
* });
|
|
151
113
|
* ```
|
|
152
114
|
*/
|
|
153
115
|
action(actionConfig) {
|
|
@@ -172,14 +134,9 @@ export class ClientSdk {
|
|
|
172
134
|
* @returns {Page<PC>} A Page instance for the given configuration
|
|
173
135
|
* @example
|
|
174
136
|
* ```ts
|
|
175
|
-
*
|
|
176
|
-
* const productPageConfig = {
|
|
177
|
-
* pageBlockId: 'product-page-id'
|
|
178
|
-
* pageName: 'product-page'
|
|
179
|
-
* };
|
|
137
|
+
* import { ProductPage } from '@/product-types';
|
|
180
138
|
*
|
|
181
|
-
*
|
|
182
|
-
* const productPage = client.page(productPageConfig);
|
|
139
|
+
* const productPage = client.page(ProductPage);
|
|
183
140
|
* ```
|
|
184
141
|
*/
|
|
185
142
|
page(pageConfig) {
|
|
@@ -188,6 +145,17 @@ export class ClientSdk {
|
|
|
188
145
|
}
|
|
189
146
|
return this.pages.get(pageConfig.pageBlockId);
|
|
190
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Gets or creates an Agent instance for the specified agent configuration.
|
|
150
|
+
*
|
|
151
|
+
* An Agent represents an app agent generated from product-types.
|
|
152
|
+
*/
|
|
153
|
+
agent(agentConfig) {
|
|
154
|
+
if (!this.agentsMap.has(agentConfig.id)) {
|
|
155
|
+
this.agentsMap.set(agentConfig.id, new Agent(agentConfig, { appId: this.appId, token: this.token }));
|
|
156
|
+
}
|
|
157
|
+
return this.agentsMap.get(agentConfig.id);
|
|
158
|
+
}
|
|
191
159
|
/**
|
|
192
160
|
* Gets or creates an AgentChat instance for the specified agent chat configuration
|
|
193
161
|
*
|
|
@@ -200,13 +168,9 @@ export class ClientSdk {
|
|
|
200
168
|
* @returns {AgentChat<ACC>} An AgentChat instance for the given configuration
|
|
201
169
|
* @example
|
|
202
170
|
* ```ts
|
|
203
|
-
*
|
|
204
|
-
* const agentChatConfig = {
|
|
205
|
-
* agentChatId: 'agent-chat-id'
|
|
206
|
-
* };
|
|
171
|
+
* import { CustomerSupportChatAgent } from '@/product-types';
|
|
207
172
|
*
|
|
208
|
-
*
|
|
209
|
-
* const agentChat = client.agentChat(agentChatConfig);
|
|
173
|
+
* const agentChat = client.agentChat(CustomerSupportChatAgent);
|
|
210
174
|
* ```
|
|
211
175
|
*/
|
|
212
176
|
agentChat(agentChatConfig) {
|