@blocksdiy/blocks-client-sdk 1.0.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 +1 -0
- package/dist/Action.d.ts +142 -0
- package/dist/Action.d.ts.map +1 -0
- package/dist/Action.js +143 -0
- package/dist/Action.js.map +1 -0
- package/dist/AgentChat.d.ts +42 -0
- package/dist/AgentChat.d.ts.map +1 -0
- package/dist/AgentChat.js +34 -0
- package/dist/AgentChat.js.map +1 -0
- package/dist/ClientSdk.d.ts +309 -0
- package/dist/ClientSdk.d.ts.map +1 -0
- package/dist/ClientSdk.js +396 -0
- package/dist/ClientSdk.js.map +1 -0
- package/dist/Entity.d.ts +299 -0
- package/dist/Entity.d.ts.map +1 -0
- package/dist/Entity.js +329 -0
- package/dist/Entity.js.map +1 -0
- package/dist/Page.d.ts +56 -0
- package/dist/Page.d.ts.map +1 -0
- package/dist/Page.js +52 -0
- package/dist/Page.js.map +1 -0
- package/dist/ReactClientSdk.d.ts +886 -0
- package/dist/ReactClientSdk.d.ts.map +1 -0
- package/dist/ReactClientSdk.jsx +1238 -0
- package/dist/ReactClientSdk.jsx.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# blocks-client-sdk.
|
package/dist/Action.d.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for defining an action
|
|
3
|
+
*
|
|
4
|
+
* This interface is used to define the structure of an action, including
|
|
5
|
+
* its input parameters and output format.
|
|
6
|
+
*
|
|
7
|
+
* @interface ActionConfig
|
|
8
|
+
* @template IT - Type defining the structure of the action's input
|
|
9
|
+
* @template OT - Type defining the structure of the action's output
|
|
10
|
+
* @property {string} actionBlockId - Unique identifier for the action workflow
|
|
11
|
+
* @property {string} toolSetId - Unique identifier for the tool set
|
|
12
|
+
* @property {string} toolId - Unique identifier for the tool
|
|
13
|
+
* @property {IT} inputInstanceType - Type definition object for the action's input parameters
|
|
14
|
+
* @property {OT} outputInstanceType - Type definition object for the action's output structure
|
|
15
|
+
*/
|
|
16
|
+
export interface ActionConfig<IT extends Record<string, unknown> = {}, OT extends Record<string, unknown> = {}> {
|
|
17
|
+
actionBlockId: string;
|
|
18
|
+
toolSetId?: string;
|
|
19
|
+
toolId?: string;
|
|
20
|
+
inputInstanceType: IT;
|
|
21
|
+
outputInstanceType: OT;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Action class for executing server-side workflows
|
|
25
|
+
*
|
|
26
|
+
* This class provides methods to execute various server-side operations defined as actions.
|
|
27
|
+
* Actions can perform any type of server-side logic, such as data processing, integrations
|
|
28
|
+
* with external services, business logic, and AI operations.
|
|
29
|
+
*
|
|
30
|
+
* @class Action
|
|
31
|
+
* @template AC - Action configuration type
|
|
32
|
+
*/
|
|
33
|
+
export declare class Action<AC extends ActionConfig = ActionConfig> {
|
|
34
|
+
private actionBlockId;
|
|
35
|
+
private appId;
|
|
36
|
+
private toolSetId?;
|
|
37
|
+
private toolId?;
|
|
38
|
+
private onError?;
|
|
39
|
+
private token?;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new Action instance
|
|
42
|
+
* @param {AC} config - Configuration for the action
|
|
43
|
+
*/
|
|
44
|
+
constructor(config: AC, { appId, onError, token }: {
|
|
45
|
+
appId: string;
|
|
46
|
+
onError?: (error: Error) => void;
|
|
47
|
+
token?: string;
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Executes the action with the provided input
|
|
51
|
+
*
|
|
52
|
+
* Sends the input to the server-side workflow and returns the result.
|
|
53
|
+
* Supports streaming responses through the onChunk callback.
|
|
54
|
+
*
|
|
55
|
+
* @param {AC["inputInstanceType"]} input - Input parameters for the action
|
|
56
|
+
* @param {Object} options - Execution options
|
|
57
|
+
* @param {Function} [options.onChunk] - Optional callback for handling streaming chunks
|
|
58
|
+
* @returns {Promise<AC["outputInstanceType"]>} The action result
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* // Example 1: Data processing action
|
|
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
|
+
* };
|
|
75
|
+
*
|
|
76
|
+
* const orderAction = new Action(processOrderConfig);
|
|
77
|
+
* const result = await orderAction.execute({
|
|
78
|
+
* orderId: 'order-123',
|
|
79
|
+
* userId: 'user-456',
|
|
80
|
+
* items: [{ productId: 'prod-789', quantity: 2 }]
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* console.log(`Order processed: ${result.orderNumber}`);
|
|
84
|
+
*
|
|
85
|
+
* // Example 2: Integration with external service
|
|
86
|
+
* const sendEmailConfig = {
|
|
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
|
+
* };
|
|
100
|
+
*
|
|
101
|
+
* const emailAction = new Action(sendEmailConfig);
|
|
102
|
+
* const emailResult = await emailAction.execute({
|
|
103
|
+
* to: 'user@example.com',
|
|
104
|
+
* subject: 'Welcome to our platform',
|
|
105
|
+
* body: 'Thank you for signing up!'
|
|
106
|
+
* });
|
|
107
|
+
*
|
|
108
|
+
* // Example 3: Action with streaming response
|
|
109
|
+
* const generateReportConfig = {
|
|
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
|
+
* };
|
|
121
|
+
*
|
|
122
|
+
* const reportAction = new Action(generateReportConfig);
|
|
123
|
+
* const reportResult = await reportAction.execute(
|
|
124
|
+
* {
|
|
125
|
+
* type: 'sales',
|
|
126
|
+
* period: 'monthly',
|
|
127
|
+
* filters: { region: 'north-america' }
|
|
128
|
+
* },
|
|
129
|
+
* {
|
|
130
|
+
* onChunk: (chunk) => {
|
|
131
|
+
* // Display progress updates to the user
|
|
132
|
+
* console.log(`Report generation: ${chunk.progress}%`);
|
|
133
|
+
* }
|
|
134
|
+
* }
|
|
135
|
+
* );
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
execute(input: AC["inputInstanceType"], { onChunk }?: {
|
|
139
|
+
onChunk?: (chunk: any) => void;
|
|
140
|
+
}): Promise<AC["outputInstanceType"]>;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=Action.d.ts.map
|
|
@@ -0,0 +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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwFG;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
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { WorkflowRequest } from "@blockscom/blocks-client-api/workflowService";
|
|
2
|
+
/**
|
|
3
|
+
* Action class for executing server-side workflows
|
|
4
|
+
*
|
|
5
|
+
* This class provides methods to execute various server-side operations defined as actions.
|
|
6
|
+
* Actions can perform any type of server-side logic, such as data processing, integrations
|
|
7
|
+
* with external services, business logic, and AI operations.
|
|
8
|
+
*
|
|
9
|
+
* @class Action
|
|
10
|
+
* @template AC - Action configuration type
|
|
11
|
+
*/
|
|
12
|
+
export class Action {
|
|
13
|
+
actionBlockId;
|
|
14
|
+
appId;
|
|
15
|
+
toolSetId;
|
|
16
|
+
toolId;
|
|
17
|
+
onError;
|
|
18
|
+
token;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new Action instance
|
|
21
|
+
* @param {AC} config - Configuration for the action
|
|
22
|
+
*/
|
|
23
|
+
constructor(config, { appId, onError, token }) {
|
|
24
|
+
this.actionBlockId = config.actionBlockId;
|
|
25
|
+
this.appId = appId;
|
|
26
|
+
this.toolSetId = config.toolSetId;
|
|
27
|
+
this.toolId = config.toolId;
|
|
28
|
+
this.onError = onError;
|
|
29
|
+
this.token = token;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Executes the action with the provided input
|
|
33
|
+
*
|
|
34
|
+
* Sends the input to the server-side workflow and returns the result.
|
|
35
|
+
* Supports streaming responses through the onChunk callback.
|
|
36
|
+
*
|
|
37
|
+
* @param {AC["inputInstanceType"]} input - Input parameters for the action
|
|
38
|
+
* @param {Object} options - Execution options
|
|
39
|
+
* @param {Function} [options.onChunk] - Optional callback for handling streaming chunks
|
|
40
|
+
* @returns {Promise<AC["outputInstanceType"]>} The action result
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* // Example 1: Data processing action
|
|
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
|
+
* };
|
|
57
|
+
*
|
|
58
|
+
* const orderAction = new Action(processOrderConfig);
|
|
59
|
+
* const result = await orderAction.execute({
|
|
60
|
+
* orderId: 'order-123',
|
|
61
|
+
* userId: 'user-456',
|
|
62
|
+
* items: [{ productId: 'prod-789', quantity: 2 }]
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* console.log(`Order processed: ${result.orderNumber}`);
|
|
66
|
+
*
|
|
67
|
+
* // Example 2: Integration with external service
|
|
68
|
+
* const sendEmailConfig = {
|
|
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
|
+
* };
|
|
82
|
+
*
|
|
83
|
+
* const emailAction = new Action(sendEmailConfig);
|
|
84
|
+
* const emailResult = await emailAction.execute({
|
|
85
|
+
* to: 'user@example.com',
|
|
86
|
+
* subject: 'Welcome to our platform',
|
|
87
|
+
* body: 'Thank you for signing up!'
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* // Example 3: Action with streaming response
|
|
91
|
+
* const generateReportConfig = {
|
|
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
|
+
* };
|
|
103
|
+
*
|
|
104
|
+
* const reportAction = new Action(generateReportConfig);
|
|
105
|
+
* const reportResult = await reportAction.execute(
|
|
106
|
+
* {
|
|
107
|
+
* type: 'sales',
|
|
108
|
+
* period: 'monthly',
|
|
109
|
+
* filters: { region: 'north-america' }
|
|
110
|
+
* },
|
|
111
|
+
* {
|
|
112
|
+
* onChunk: (chunk) => {
|
|
113
|
+
* // Display progress updates to the user
|
|
114
|
+
* console.log(`Report generation: ${chunk.progress}%`);
|
|
115
|
+
* }
|
|
116
|
+
* }
|
|
117
|
+
* );
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
async execute(input, { onChunk } = {}) {
|
|
121
|
+
const result = await WorkflowRequest.run({
|
|
122
|
+
workflowBlockId: this.actionBlockId,
|
|
123
|
+
appId: this.appId,
|
|
124
|
+
token: this.token,
|
|
125
|
+
input: {
|
|
126
|
+
...input,
|
|
127
|
+
toolId: this.toolId,
|
|
128
|
+
},
|
|
129
|
+
context: {
|
|
130
|
+
appId: this.appId,
|
|
131
|
+
toolSetId: this.toolSetId,
|
|
132
|
+
},
|
|
133
|
+
onChunk: (data) => {
|
|
134
|
+
onChunk?.(data);
|
|
135
|
+
},
|
|
136
|
+
onFailed: (error) => {
|
|
137
|
+
this.onError?.(error);
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=Action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Action.js","sourceRoot":"","sources":["../src/Action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAyB/E;;;;;;;;;GASG;AACH,MAAM,OAAO,MAAM;IACT,aAAa,CAAS;IACtB,KAAK,CAAS;IACd,SAAS,CAAU;IACnB,MAAM,CAAU;IAChB,OAAO,CAA0B;IACjC,KAAK,CAAU;IACvB;;;OAGG;IACH,YACE,MAAU,EACV,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAuE;QAE9F,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwFG;IACH,KAAK,CAAC,OAAO,CAAC,KAA8B,EAAE,EAAE,OAAO,KAAyC,EAAE;QAChG,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,GAAG,CAAC;YACvC,eAAe,EAAE,IAAI,CAAC,aAAa;YACnC,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK,EAAE;gBACL,GAAG,KAAK;gBACR,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB;YACD,OAAO,EAAE;gBACP,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,SAAS,EAAE,IAAI,CAAC,SAAS;aAC1B;YACD,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBAChB,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;YAClB,CAAC;YACD,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;gBAClB,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;YACxB,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,MAAkC,CAAC;IAC5C,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for defining an agent chat
|
|
3
|
+
*
|
|
4
|
+
* This interface is used to define the structure of an agent chat.
|
|
5
|
+
*
|
|
6
|
+
* @interface AgentChatConfig
|
|
7
|
+
* @property {string} agentChatId - Unique identifier for the agent chat
|
|
8
|
+
*/
|
|
9
|
+
export interface AgentChatConfig {
|
|
10
|
+
agentChatId: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* AgentChat class for interacting with the agent chat
|
|
14
|
+
*
|
|
15
|
+
* This class provides methods to interact with the agent chat.
|
|
16
|
+
*
|
|
17
|
+
* @class AgentChat
|
|
18
|
+
* @template ACC - AgentChat configuration type
|
|
19
|
+
*/
|
|
20
|
+
export declare class AgentChat<ACC extends AgentChatConfig = AgentChatConfig> {
|
|
21
|
+
private agentChatId;
|
|
22
|
+
private appId;
|
|
23
|
+
private token?;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new AgentChat instance
|
|
26
|
+
* @param {ACC} config - Configuration for the agent chat
|
|
27
|
+
*/
|
|
28
|
+
constructor(config: ACC, { appId, token }: {
|
|
29
|
+
appId: string;
|
|
30
|
+
token?: string;
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Get the props for the AgentChat component
|
|
34
|
+
* @returns {Object} - The props for the AgentChat component
|
|
35
|
+
*/
|
|
36
|
+
getAgentChatComponentProps(): {
|
|
37
|
+
agentChatId: string;
|
|
38
|
+
appId: string;
|
|
39
|
+
token: string | undefined;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=AgentChat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentChat.d.ts","sourceRoot":"","sources":["../src/AgentChat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,qBAAa,SAAS,CAAC,GAAG,SAAS,eAAe,GAAG,eAAe;IAClE,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB;;;OAGG;gBACS,MAAM,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAM5E;;;OAGG;IACH,0BAA0B;;;;;CAO3B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentChat class for interacting with the agent chat
|
|
3
|
+
*
|
|
4
|
+
* This class provides methods to interact with the agent chat.
|
|
5
|
+
*
|
|
6
|
+
* @class AgentChat
|
|
7
|
+
* @template ACC - AgentChat configuration type
|
|
8
|
+
*/
|
|
9
|
+
export class AgentChat {
|
|
10
|
+
agentChatId;
|
|
11
|
+
appId;
|
|
12
|
+
token;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new AgentChat instance
|
|
15
|
+
* @param {ACC} config - Configuration for the agent chat
|
|
16
|
+
*/
|
|
17
|
+
constructor(config, { appId, token }) {
|
|
18
|
+
this.agentChatId = config.agentChatId;
|
|
19
|
+
this.appId = appId;
|
|
20
|
+
this.token = token;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the props for the AgentChat component
|
|
24
|
+
* @returns {Object} - The props for the AgentChat component
|
|
25
|
+
*/
|
|
26
|
+
getAgentChatComponentProps() {
|
|
27
|
+
return {
|
|
28
|
+
agentChatId: this.agentChatId,
|
|
29
|
+
appId: this.appId,
|
|
30
|
+
token: this.token,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=AgentChat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentChat.js","sourceRoot":"","sources":["../src/AgentChat.ts"],"names":[],"mappings":"AAYA;;;;;;;GAOG;AACH,MAAM,OAAO,SAAS;IACZ,WAAW,CAAS;IACpB,KAAK,CAAS;IACd,KAAK,CAAU;IACvB;;;OAGG;IACH,YAAY,MAAW,EAAE,EAAE,KAAK,EAAE,KAAK,EAAqC;QAC1E,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,0BAA0B;QACxB,OAAO;YACL,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { Action, type ActionConfig } from "./Action.js";
|
|
2
|
+
import { AgentChat, AgentChatConfig } from "./AgentChat.js";
|
|
3
|
+
import { Entity, type EntityConfig } from "./Entity.js";
|
|
4
|
+
import { Page, type PageConfig } from "./Page.js";
|
|
5
|
+
/**
|
|
6
|
+
* Represents a user's data
|
|
7
|
+
* @interface User
|
|
8
|
+
* @property {string} [id] - The user's ID (optional, must exist if user is authenticated)
|
|
9
|
+
* @property {string} [email] - The user's email (optional, must exist if user is authenticated)
|
|
10
|
+
* @property {string} [name] - The user's name (optional, must exist if user is authenticated)
|
|
11
|
+
* @property {string} [profileImageUrl] - The user's profile image URL (optional)
|
|
12
|
+
* @property {string} [firstName] - The user's first name (optional)
|
|
13
|
+
* @property {string} [lastName] - The user's last name (optional)
|
|
14
|
+
* @property {string} [role] - The user's role name (optional)
|
|
15
|
+
* @property {string} [permission] - The user's permission level: 'build' (can modify app) or 'use' (read-only) (optional)
|
|
16
|
+
* @property {boolean} [isAuthenticated] - Whether the user is authenticated
|
|
17
|
+
*/
|
|
18
|
+
export interface User {
|
|
19
|
+
id?: string;
|
|
20
|
+
email?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
profileImageUrl?: string;
|
|
23
|
+
firstName?: string;
|
|
24
|
+
lastName?: string;
|
|
25
|
+
role?: string;
|
|
26
|
+
permission?: "build" | "use";
|
|
27
|
+
isAuthenticated: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface UpdateUserOptions {
|
|
30
|
+
clientOnly?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Configuration options for initializing a ClientSdk instance
|
|
34
|
+
* @interface ClientConfig
|
|
35
|
+
* @property {string} appId - The unique identifier for the application
|
|
36
|
+
* @property {string} token - The token for the application
|
|
37
|
+
*/
|
|
38
|
+
export interface ClientConfig {
|
|
39
|
+
appId: string;
|
|
40
|
+
token?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Main client SDK for interacting with entities, actions, and pages
|
|
44
|
+
*
|
|
45
|
+
* This SDK provides a unified interface for working with:
|
|
46
|
+
* - Entities: Data objects stored in tables (CRUD operations)
|
|
47
|
+
* - Actions: Executable workflows that perform operations (any server-side logic)
|
|
48
|
+
* - Pages: Application pages with URL and parameter handling
|
|
49
|
+
* - AgentChat: Interact with the agent chat
|
|
50
|
+
* - User: The user's data
|
|
51
|
+
*
|
|
52
|
+
* @class ClientSdk
|
|
53
|
+
*/
|
|
54
|
+
export declare class ClientSdk {
|
|
55
|
+
readonly appId: string;
|
|
56
|
+
private user;
|
|
57
|
+
readonly token?: string;
|
|
58
|
+
private readonly entities;
|
|
59
|
+
private readonly actions;
|
|
60
|
+
private readonly pages;
|
|
61
|
+
private readonly agentChats;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new ClientSdk instance
|
|
64
|
+
* @param {ClientConfig} config - Configuration options
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const client = new ClientSdk({ appId: 'my-application-id' });
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
constructor(config: ClientConfig);
|
|
71
|
+
authenticate(): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Gets or creates an Entity instance for the specified entity configuration
|
|
74
|
+
*
|
|
75
|
+
* An Entity represents a data object stored in a table with CRUD operations.
|
|
76
|
+
* EntityConfig requires:
|
|
77
|
+
* - tableBlockId: Unique identifier for the table
|
|
78
|
+
* - instanceType: TypeScript type defining the entity's structure
|
|
79
|
+
*
|
|
80
|
+
* @template EC - Entity configuration type
|
|
81
|
+
* @param {EC} entityConfig - Configuration for the entity
|
|
82
|
+
* @returns {Entity<EC>} An Entity instance for the given configuration
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* // Define a User entity configuration
|
|
86
|
+
* const userEntityConfig = {
|
|
87
|
+
* tableBlockId: 'users-table-id',
|
|
88
|
+
* instanceType: {} as {
|
|
89
|
+
* name: string;
|
|
90
|
+
* email: string;
|
|
91
|
+
* role: 'admin' | 'user';
|
|
92
|
+
* }
|
|
93
|
+
* };
|
|
94
|
+
*
|
|
95
|
+
* // Get the entity instance
|
|
96
|
+
* const userEntity = client.entity(userEntityConfig);
|
|
97
|
+
*
|
|
98
|
+
* // Use it for CRUD operations
|
|
99
|
+
* const users = await userEntity.findMany();
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
entity<EC extends EntityConfig = EntityConfig>(entityConfig: EC): Entity<EC>;
|
|
103
|
+
/**
|
|
104
|
+
* Gets or creates an Action instance for the specified action configuration
|
|
105
|
+
*
|
|
106
|
+
* An Action represents an executable workflow that performs server-side operations
|
|
107
|
+
* of any kind. Actions can handle data processing, business logic, integrations
|
|
108
|
+
* with external services, AI operations, and any other server-side functionality.
|
|
109
|
+
* Actions are particularly powerful for implementing AI capabilities.
|
|
110
|
+
*
|
|
111
|
+
* ActionConfig requires:
|
|
112
|
+
* - actionBlockId: Unique identifier for the action workflow
|
|
113
|
+
* - inputInstanceType: TypeScript type defining the action's input parameters
|
|
114
|
+
* - outputInstanceType: TypeScript type defining the action's output structure
|
|
115
|
+
*
|
|
116
|
+
* @template AC - Action configuration type
|
|
117
|
+
* @param {AC} actionConfig - Configuration for the action
|
|
118
|
+
* @returns {Action<AC>} An Action instance for the given configuration
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* // Example 1: Data processing action
|
|
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
|
+
* };
|
|
135
|
+
*
|
|
136
|
+
* const processOrderAction = client.action(processOrderConfig);
|
|
137
|
+
* const result = await processOrderAction.execute({
|
|
138
|
+
* orderId: 'order-123',
|
|
139
|
+
* userId: 'user-456',
|
|
140
|
+
* items: [{ productId: 'prod-789', quantity: 2 }]
|
|
141
|
+
* });
|
|
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
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
action<AC extends ActionConfig = ActionConfig>(actionConfig: AC): Action<AC>;
|
|
165
|
+
/**
|
|
166
|
+
* Gets or creates a Page instance for the specified page configuration
|
|
167
|
+
*
|
|
168
|
+
* A Page represents an application page with URL and parameter handling.
|
|
169
|
+
* PageConfig requires:
|
|
170
|
+
* - pageBlockId: Unique identifier for the page
|
|
171
|
+
* - pageName: Name of the page
|
|
172
|
+
*
|
|
173
|
+
* @template PC - Page configuration type
|
|
174
|
+
* @param {PC} pageConfig - Configuration for the page
|
|
175
|
+
* @returns {Page<PC>} A Page instance for the given configuration
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* // Define a product page configuration
|
|
179
|
+
* const productPageConfig = {
|
|
180
|
+
* pageBlockId: 'product-page-id'
|
|
181
|
+
* pageName: 'product-page'
|
|
182
|
+
* };
|
|
183
|
+
*
|
|
184
|
+
* // Get the page instance
|
|
185
|
+
* const productPage = client.page(productPageConfig);
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
page<PC extends PageConfig = PageConfig>(pageConfig: PC): Page<PC>;
|
|
189
|
+
/**
|
|
190
|
+
* Gets or creates an AgentChat instance for the specified agent chat configuration
|
|
191
|
+
*
|
|
192
|
+
* An AgentChat represents an agent chat with the user.
|
|
193
|
+
* AgentChatConfig requires:
|
|
194
|
+
* - agentChatId: Unique identifier for the agent chat
|
|
195
|
+
*
|
|
196
|
+
* @template ACC - AgentChat configuration type
|
|
197
|
+
* @param {ACC} agentChatConfig - Configuration for the agent chat
|
|
198
|
+
* @returns {AgentChat<ACC>} An AgentChat instance for the given configuration
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* // Define a agent chat configuration
|
|
202
|
+
* const agentChatConfig = {
|
|
203
|
+
* agentChatId: 'agent-chat-id'
|
|
204
|
+
* };
|
|
205
|
+
*
|
|
206
|
+
* // Get the agent chat instance
|
|
207
|
+
* const agentChat = client.agentChat(agentChatConfig);
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
agentChat<ACC extends AgentChatConfig = AgentChatConfig>(agentChatConfig: ACC): AgentChat<ACC>;
|
|
211
|
+
private getUploadUrl;
|
|
212
|
+
upload(file: File, { onProgress }: {
|
|
213
|
+
onProgress: (percentage: number) => void;
|
|
214
|
+
}): Promise<string>;
|
|
215
|
+
/**
|
|
216
|
+
* Returns the current user information
|
|
217
|
+
*
|
|
218
|
+
* This method provides access to the user's data
|
|
219
|
+
* that was provided during SDK initialization.
|
|
220
|
+
*
|
|
221
|
+
* @returns {User} The current user object
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* // Get the current user information
|
|
225
|
+
* const user = client.getUser();
|
|
226
|
+
* console.log(`Logged in as: ${user.username}`);
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
getUser(): User;
|
|
230
|
+
/**
|
|
231
|
+
* Changes a user's role
|
|
232
|
+
* @param userId - The user ID to change the role for
|
|
233
|
+
* @param role - The new role to set for the user
|
|
234
|
+
* @param options - Options for the change
|
|
235
|
+
* @returns {Promise<void>} A promise that resolves when the role change is complete
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* await client.changeUserRole('123', 'admin');
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
changeUserRole(userId: string, role: string, options?: UpdateUserOptions): Promise<void>;
|
|
242
|
+
/**
|
|
243
|
+
* Sends a passwordless login link (magic link) to the user's email
|
|
244
|
+
*
|
|
245
|
+
* This method sends an email containing a one-time login link that allows users
|
|
246
|
+
* to authenticate without entering a password. When the user clicks the link in
|
|
247
|
+
* their email, they will be automatically logged into the application.
|
|
248
|
+
*
|
|
249
|
+
* @param {Object} params - Parameters for sending the login link
|
|
250
|
+
* @param {string} params.email - The email address to send the login link to
|
|
251
|
+
* @returns {Promise<void>} A promise that resolves when the login link is sent successfully
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* // Send a login link to a user
|
|
255
|
+
* const result = await client.sendLoginLink({
|
|
256
|
+
* email: 'user@example.com'
|
|
257
|
+
* });
|
|
258
|
+
*
|
|
259
|
+
* // Typically used in a login form
|
|
260
|
+
* async function handlePasswordlessLogin(email: string) {
|
|
261
|
+
* try {
|
|
262
|
+
* await client.sendLoginLink({ email });
|
|
263
|
+
* alert('Check your email for a login link!');
|
|
264
|
+
* } catch (error) {
|
|
265
|
+
* console.error('Failed to send login link:', error);
|
|
266
|
+
* }
|
|
267
|
+
* }
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
sendLoginLink({ email }: {
|
|
271
|
+
email: string;
|
|
272
|
+
}): Promise<void>;
|
|
273
|
+
/**
|
|
274
|
+
* Gets the Google OAuth login URL for authentication
|
|
275
|
+
*
|
|
276
|
+
* This method generates a URL that initiates the Google OAuth login flow.
|
|
277
|
+
* When users navigate to this URL, they will be redirected to Google's
|
|
278
|
+
* authentication page. After successful authentication with Google, they
|
|
279
|
+
* will be redirected back to the application and automatically logged in.
|
|
280
|
+
*
|
|
281
|
+
* @returns {string} The Google OAuth login URL
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* // Get the Google login URL
|
|
285
|
+
* const googleUrl = client.getGoogleLoginUrl();
|
|
286
|
+
*
|
|
287
|
+
* // Redirect user to Google login
|
|
288
|
+
* window.location.href = googleUrl;
|
|
289
|
+
*
|
|
290
|
+
* // Use in a button with onClick
|
|
291
|
+
* function GoogleLoginButton() {
|
|
292
|
+
* const handleGoogleLogin = () => {
|
|
293
|
+
* const url = client.getGoogleLoginUrl();
|
|
294
|
+
* window.location.href = url;
|
|
295
|
+
* };
|
|
296
|
+
*
|
|
297
|
+
* return <Button onClick={handleGoogleLogin}>Sign in with Google</Button>;
|
|
298
|
+
* }
|
|
299
|
+
*
|
|
300
|
+
* // Use in a Link component
|
|
301
|
+
* function GoogleLoginLink() {
|
|
302
|
+
* const googleUrl = client.getGoogleLoginUrl();
|
|
303
|
+
* return <Link to={googleUrl}>Sign in with Google</Link>;
|
|
304
|
+
* }
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
getGoogleLoginUrl(): string;
|
|
308
|
+
}
|
|
309
|
+
//# sourceMappingURL=ClientSdk.d.ts.map
|