@autenai/sdk 0.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/dist/index.d.mts +308 -0
- package/dist/index.d.ts +308 -0
- package/dist/index.js +329 -0
- package/dist/index.mjs +297 -0
- package/package.json +39 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auten SDK — HTTP Client
|
|
3
|
+
* Fetch-based with retry, error mapping, and rate limit handling.
|
|
4
|
+
*/
|
|
5
|
+
interface ClientConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
timeout: number;
|
|
9
|
+
retries: number;
|
|
10
|
+
}
|
|
11
|
+
declare class HttpClient {
|
|
12
|
+
private config;
|
|
13
|
+
constructor(config: ClientConfig);
|
|
14
|
+
get<T>(path: string): Promise<T>;
|
|
15
|
+
post<T>(path: string, body?: unknown): Promise<T>;
|
|
16
|
+
del<T>(path: string): Promise<T | void>;
|
|
17
|
+
private request;
|
|
18
|
+
private sleep;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Auten SDK — Type Definitions
|
|
23
|
+
*/
|
|
24
|
+
interface AutenConfig {
|
|
25
|
+
/** Your Auten API key (starts with auten_live_ or auten_test_) */
|
|
26
|
+
apiKey: string;
|
|
27
|
+
/** Base URL for the API. Default: https://auten.ai */
|
|
28
|
+
baseUrl?: string;
|
|
29
|
+
/** Request timeout in ms. Default: 30000 */
|
|
30
|
+
timeout?: number;
|
|
31
|
+
/** Number of retries on failure. Default: 3 */
|
|
32
|
+
retries?: number;
|
|
33
|
+
}
|
|
34
|
+
interface Provider {
|
|
35
|
+
slug: string;
|
|
36
|
+
name: string;
|
|
37
|
+
category: string;
|
|
38
|
+
icon: string | null;
|
|
39
|
+
accountEmail: string | null;
|
|
40
|
+
isActive: boolean;
|
|
41
|
+
connectedAt: string;
|
|
42
|
+
}
|
|
43
|
+
interface ProviderCredentials {
|
|
44
|
+
provider: string;
|
|
45
|
+
accessToken: string;
|
|
46
|
+
}
|
|
47
|
+
interface ExecuteResult {
|
|
48
|
+
provider: string;
|
|
49
|
+
action: string;
|
|
50
|
+
result: any;
|
|
51
|
+
duration?: number;
|
|
52
|
+
}
|
|
53
|
+
interface AIExecuteResult {
|
|
54
|
+
provider: string;
|
|
55
|
+
task: string;
|
|
56
|
+
result: any;
|
|
57
|
+
duration?: number;
|
|
58
|
+
}
|
|
59
|
+
interface Agent {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
description: string | null;
|
|
63
|
+
status: string;
|
|
64
|
+
isPublished: boolean;
|
|
65
|
+
schedule: AgentSchedule | null;
|
|
66
|
+
createdAt: string;
|
|
67
|
+
updatedAt: string;
|
|
68
|
+
}
|
|
69
|
+
interface AgentDetail extends Agent {
|
|
70
|
+
tools: AgentTool[];
|
|
71
|
+
}
|
|
72
|
+
interface AgentTool {
|
|
73
|
+
name: string;
|
|
74
|
+
description: string;
|
|
75
|
+
}
|
|
76
|
+
interface AgentSchedule {
|
|
77
|
+
cron: string;
|
|
78
|
+
timezone: string;
|
|
79
|
+
enabled: boolean;
|
|
80
|
+
nextRunAt: string | null;
|
|
81
|
+
}
|
|
82
|
+
interface CreateAgentOptions {
|
|
83
|
+
name: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
tools?: Array<{
|
|
86
|
+
name: string;
|
|
87
|
+
code: string;
|
|
88
|
+
description?: string;
|
|
89
|
+
}>;
|
|
90
|
+
schedule?: {
|
|
91
|
+
cron: string;
|
|
92
|
+
timezone?: string;
|
|
93
|
+
enabled?: boolean;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
interface DeployAgentOptions {
|
|
97
|
+
tools: Array<{
|
|
98
|
+
name: string;
|
|
99
|
+
code: string;
|
|
100
|
+
description?: string;
|
|
101
|
+
}>;
|
|
102
|
+
schedule?: {
|
|
103
|
+
cron?: string;
|
|
104
|
+
timezone?: string;
|
|
105
|
+
enabled?: boolean;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
interface AgentRunResult {
|
|
109
|
+
executionId: string;
|
|
110
|
+
status: string;
|
|
111
|
+
}
|
|
112
|
+
interface CreateAgentResult {
|
|
113
|
+
id: string;
|
|
114
|
+
name: string;
|
|
115
|
+
scope: string;
|
|
116
|
+
status: string;
|
|
117
|
+
toolCount: number;
|
|
118
|
+
}
|
|
119
|
+
interface DeployResult {
|
|
120
|
+
id: string;
|
|
121
|
+
deployed: boolean;
|
|
122
|
+
tools: string[];
|
|
123
|
+
version: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Auten SDK — Provider Client
|
|
128
|
+
* Manages provider connections and executes actions.
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
declare class ProviderClient {
|
|
132
|
+
private client;
|
|
133
|
+
constructor(client: HttpClient);
|
|
134
|
+
/**
|
|
135
|
+
* List all connected providers for the authenticated user.
|
|
136
|
+
*/
|
|
137
|
+
list(): Promise<Provider[]>;
|
|
138
|
+
/**
|
|
139
|
+
* Execute an action on a provider.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* const result = await auten.providers.execute('google-gmail', 'listEmails', { query: 'is:unread' });
|
|
143
|
+
*/
|
|
144
|
+
execute(slug: string, action: string, params?: Record<string, any>): Promise<ExecuteResult>;
|
|
145
|
+
/**
|
|
146
|
+
* Get a valid access token for a provider.
|
|
147
|
+
* Token is automatically refreshed if expired.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* const { accessToken } = await auten.providers.getCredentials('google-gmail');
|
|
151
|
+
*/
|
|
152
|
+
getCredentials(slug: string): Promise<ProviderCredentials>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Auten SDK — Agent Client
|
|
157
|
+
* Create, deploy, run, and manage agents.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
declare class AgentClient {
|
|
161
|
+
private client;
|
|
162
|
+
constructor(client: HttpClient);
|
|
163
|
+
/**
|
|
164
|
+
* List all agents for the authenticated user.
|
|
165
|
+
*/
|
|
166
|
+
list(): Promise<Agent[]>;
|
|
167
|
+
/**
|
|
168
|
+
* Get agent details including tools and schedule.
|
|
169
|
+
*/
|
|
170
|
+
get(id: string): Promise<AgentDetail>;
|
|
171
|
+
/**
|
|
172
|
+
* Create a new agent.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* const agent = await auten.agents.create({
|
|
176
|
+
* name: 'Invoice Processor',
|
|
177
|
+
* tools: [{ name: 'process-invoice', code: '...' }],
|
|
178
|
+
* schedule: { cron: '0 9 * * *', timezone: 'Europe/Vilnius' },
|
|
179
|
+
* });
|
|
180
|
+
*/
|
|
181
|
+
create(options: CreateAgentOptions): Promise<CreateAgentResult>;
|
|
182
|
+
/**
|
|
183
|
+
* Deploy tools to an existing agent.
|
|
184
|
+
* Upserts tool code and updates the agent configuration.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* await auten.agents.deploy('agent-id', {
|
|
188
|
+
* tools: [{ name: 'fetch-data', code: '...' }],
|
|
189
|
+
* });
|
|
190
|
+
*/
|
|
191
|
+
deploy(id: string, options: DeployAgentOptions): Promise<DeployResult>;
|
|
192
|
+
/**
|
|
193
|
+
* Trigger an agent run.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* const { executionId } = await auten.agents.run('agent-id', { inputData: '...' });
|
|
197
|
+
*/
|
|
198
|
+
run(id: string, data?: Record<string, any>): Promise<AgentRunResult>;
|
|
199
|
+
/**
|
|
200
|
+
* Get agent status.
|
|
201
|
+
*/
|
|
202
|
+
status(id: string): Promise<{
|
|
203
|
+
status: string;
|
|
204
|
+
lastRunAt?: string;
|
|
205
|
+
}>;
|
|
206
|
+
/**
|
|
207
|
+
* Get agent run history.
|
|
208
|
+
*/
|
|
209
|
+
history(id: string): Promise<any[]>;
|
|
210
|
+
/**
|
|
211
|
+
* Delete an agent and all its knowledge/tools.
|
|
212
|
+
*/
|
|
213
|
+
delete(id: string): Promise<void>;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Auten SDK — AI Client
|
|
218
|
+
* AI-powered provider interactions using natural language.
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
declare class AIClient {
|
|
222
|
+
private client;
|
|
223
|
+
constructor(client: HttpClient);
|
|
224
|
+
/**
|
|
225
|
+
* Execute a task using AI to interpret and call the right provider APIs.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* const result = await auten.ai.execute(
|
|
229
|
+
* 'google-sheets',
|
|
230
|
+
* 'Find Q1 revenue totals and create a summary row'
|
|
231
|
+
* );
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* const result = await auten.ai.execute(
|
|
235
|
+
* 'zoho-crm',
|
|
236
|
+
* 'Find all deals closing this month worth over $10k',
|
|
237
|
+
* { currency: 'USD' }
|
|
238
|
+
* );
|
|
239
|
+
*/
|
|
240
|
+
execute(provider: string, task: string, context?: Record<string, any>): Promise<AIExecuteResult>;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Auten SDK — Error Classes
|
|
245
|
+
*/
|
|
246
|
+
declare class AutenError extends Error {
|
|
247
|
+
constructor(message: string);
|
|
248
|
+
}
|
|
249
|
+
declare class AutenApiError extends AutenError {
|
|
250
|
+
readonly code: string;
|
|
251
|
+
readonly statusCode: number;
|
|
252
|
+
readonly details: unknown;
|
|
253
|
+
constructor(code: string, message: string, statusCode: number, details?: unknown);
|
|
254
|
+
}
|
|
255
|
+
declare class AutenAuthError extends AutenApiError {
|
|
256
|
+
constructor(message: string, code?: string);
|
|
257
|
+
}
|
|
258
|
+
declare class AutenRateLimitError extends AutenApiError {
|
|
259
|
+
readonly retryAfter: number;
|
|
260
|
+
constructor(message: string, retryAfter: number);
|
|
261
|
+
}
|
|
262
|
+
declare class AutenNotFoundError extends AutenApiError {
|
|
263
|
+
constructor(message: string);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Auten.ai SDK
|
|
268
|
+
*
|
|
269
|
+
* AI-native integrations with managed OAuth.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```typescript
|
|
273
|
+
* import { Auten } from '@autenai/sdk';
|
|
274
|
+
*
|
|
275
|
+
* const auten = new Auten({ apiKey: 'auten_live_...' });
|
|
276
|
+
*
|
|
277
|
+
* // List connected providers
|
|
278
|
+
* const providers = await auten.providers.list();
|
|
279
|
+
*
|
|
280
|
+
* // Execute provider action
|
|
281
|
+
* const emails = await auten.providers.execute('google-gmail', 'listEmails', {
|
|
282
|
+
* query: 'is:unread',
|
|
283
|
+
* });
|
|
284
|
+
*
|
|
285
|
+
* // AI-powered execution
|
|
286
|
+
* const result = await auten.ai.execute(
|
|
287
|
+
* 'google-sheets',
|
|
288
|
+
* 'Find Q1 revenue totals'
|
|
289
|
+
* );
|
|
290
|
+
*
|
|
291
|
+
* // Manage agents
|
|
292
|
+
* const agents = await auten.agents.list();
|
|
293
|
+
* await auten.agents.run('agent-id');
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
|
|
297
|
+
declare class Auten {
|
|
298
|
+
/** Provider connections and execution */
|
|
299
|
+
readonly providers: ProviderClient;
|
|
300
|
+
/** Agent management */
|
|
301
|
+
readonly agents: AgentClient;
|
|
302
|
+
/** AI-powered execution */
|
|
303
|
+
readonly ai: AIClient;
|
|
304
|
+
private readonly client;
|
|
305
|
+
constructor(config: AutenConfig);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export { type AIExecuteResult, type Agent, type AgentDetail, type AgentRunResult, type AgentSchedule, type AgentTool, Auten, AutenApiError, AutenAuthError, type AutenConfig, AutenError, AutenNotFoundError, AutenRateLimitError, type CreateAgentOptions, type CreateAgentResult, type DeployAgentOptions, type DeployResult, type ExecuteResult, type Provider, type ProviderCredentials };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auten SDK — HTTP Client
|
|
3
|
+
* Fetch-based with retry, error mapping, and rate limit handling.
|
|
4
|
+
*/
|
|
5
|
+
interface ClientConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
timeout: number;
|
|
9
|
+
retries: number;
|
|
10
|
+
}
|
|
11
|
+
declare class HttpClient {
|
|
12
|
+
private config;
|
|
13
|
+
constructor(config: ClientConfig);
|
|
14
|
+
get<T>(path: string): Promise<T>;
|
|
15
|
+
post<T>(path: string, body?: unknown): Promise<T>;
|
|
16
|
+
del<T>(path: string): Promise<T | void>;
|
|
17
|
+
private request;
|
|
18
|
+
private sleep;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Auten SDK — Type Definitions
|
|
23
|
+
*/
|
|
24
|
+
interface AutenConfig {
|
|
25
|
+
/** Your Auten API key (starts with auten_live_ or auten_test_) */
|
|
26
|
+
apiKey: string;
|
|
27
|
+
/** Base URL for the API. Default: https://auten.ai */
|
|
28
|
+
baseUrl?: string;
|
|
29
|
+
/** Request timeout in ms. Default: 30000 */
|
|
30
|
+
timeout?: number;
|
|
31
|
+
/** Number of retries on failure. Default: 3 */
|
|
32
|
+
retries?: number;
|
|
33
|
+
}
|
|
34
|
+
interface Provider {
|
|
35
|
+
slug: string;
|
|
36
|
+
name: string;
|
|
37
|
+
category: string;
|
|
38
|
+
icon: string | null;
|
|
39
|
+
accountEmail: string | null;
|
|
40
|
+
isActive: boolean;
|
|
41
|
+
connectedAt: string;
|
|
42
|
+
}
|
|
43
|
+
interface ProviderCredentials {
|
|
44
|
+
provider: string;
|
|
45
|
+
accessToken: string;
|
|
46
|
+
}
|
|
47
|
+
interface ExecuteResult {
|
|
48
|
+
provider: string;
|
|
49
|
+
action: string;
|
|
50
|
+
result: any;
|
|
51
|
+
duration?: number;
|
|
52
|
+
}
|
|
53
|
+
interface AIExecuteResult {
|
|
54
|
+
provider: string;
|
|
55
|
+
task: string;
|
|
56
|
+
result: any;
|
|
57
|
+
duration?: number;
|
|
58
|
+
}
|
|
59
|
+
interface Agent {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
description: string | null;
|
|
63
|
+
status: string;
|
|
64
|
+
isPublished: boolean;
|
|
65
|
+
schedule: AgentSchedule | null;
|
|
66
|
+
createdAt: string;
|
|
67
|
+
updatedAt: string;
|
|
68
|
+
}
|
|
69
|
+
interface AgentDetail extends Agent {
|
|
70
|
+
tools: AgentTool[];
|
|
71
|
+
}
|
|
72
|
+
interface AgentTool {
|
|
73
|
+
name: string;
|
|
74
|
+
description: string;
|
|
75
|
+
}
|
|
76
|
+
interface AgentSchedule {
|
|
77
|
+
cron: string;
|
|
78
|
+
timezone: string;
|
|
79
|
+
enabled: boolean;
|
|
80
|
+
nextRunAt: string | null;
|
|
81
|
+
}
|
|
82
|
+
interface CreateAgentOptions {
|
|
83
|
+
name: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
tools?: Array<{
|
|
86
|
+
name: string;
|
|
87
|
+
code: string;
|
|
88
|
+
description?: string;
|
|
89
|
+
}>;
|
|
90
|
+
schedule?: {
|
|
91
|
+
cron: string;
|
|
92
|
+
timezone?: string;
|
|
93
|
+
enabled?: boolean;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
interface DeployAgentOptions {
|
|
97
|
+
tools: Array<{
|
|
98
|
+
name: string;
|
|
99
|
+
code: string;
|
|
100
|
+
description?: string;
|
|
101
|
+
}>;
|
|
102
|
+
schedule?: {
|
|
103
|
+
cron?: string;
|
|
104
|
+
timezone?: string;
|
|
105
|
+
enabled?: boolean;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
interface AgentRunResult {
|
|
109
|
+
executionId: string;
|
|
110
|
+
status: string;
|
|
111
|
+
}
|
|
112
|
+
interface CreateAgentResult {
|
|
113
|
+
id: string;
|
|
114
|
+
name: string;
|
|
115
|
+
scope: string;
|
|
116
|
+
status: string;
|
|
117
|
+
toolCount: number;
|
|
118
|
+
}
|
|
119
|
+
interface DeployResult {
|
|
120
|
+
id: string;
|
|
121
|
+
deployed: boolean;
|
|
122
|
+
tools: string[];
|
|
123
|
+
version: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Auten SDK — Provider Client
|
|
128
|
+
* Manages provider connections and executes actions.
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
declare class ProviderClient {
|
|
132
|
+
private client;
|
|
133
|
+
constructor(client: HttpClient);
|
|
134
|
+
/**
|
|
135
|
+
* List all connected providers for the authenticated user.
|
|
136
|
+
*/
|
|
137
|
+
list(): Promise<Provider[]>;
|
|
138
|
+
/**
|
|
139
|
+
* Execute an action on a provider.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* const result = await auten.providers.execute('google-gmail', 'listEmails', { query: 'is:unread' });
|
|
143
|
+
*/
|
|
144
|
+
execute(slug: string, action: string, params?: Record<string, any>): Promise<ExecuteResult>;
|
|
145
|
+
/**
|
|
146
|
+
* Get a valid access token for a provider.
|
|
147
|
+
* Token is automatically refreshed if expired.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* const { accessToken } = await auten.providers.getCredentials('google-gmail');
|
|
151
|
+
*/
|
|
152
|
+
getCredentials(slug: string): Promise<ProviderCredentials>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Auten SDK — Agent Client
|
|
157
|
+
* Create, deploy, run, and manage agents.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
declare class AgentClient {
|
|
161
|
+
private client;
|
|
162
|
+
constructor(client: HttpClient);
|
|
163
|
+
/**
|
|
164
|
+
* List all agents for the authenticated user.
|
|
165
|
+
*/
|
|
166
|
+
list(): Promise<Agent[]>;
|
|
167
|
+
/**
|
|
168
|
+
* Get agent details including tools and schedule.
|
|
169
|
+
*/
|
|
170
|
+
get(id: string): Promise<AgentDetail>;
|
|
171
|
+
/**
|
|
172
|
+
* Create a new agent.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* const agent = await auten.agents.create({
|
|
176
|
+
* name: 'Invoice Processor',
|
|
177
|
+
* tools: [{ name: 'process-invoice', code: '...' }],
|
|
178
|
+
* schedule: { cron: '0 9 * * *', timezone: 'Europe/Vilnius' },
|
|
179
|
+
* });
|
|
180
|
+
*/
|
|
181
|
+
create(options: CreateAgentOptions): Promise<CreateAgentResult>;
|
|
182
|
+
/**
|
|
183
|
+
* Deploy tools to an existing agent.
|
|
184
|
+
* Upserts tool code and updates the agent configuration.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* await auten.agents.deploy('agent-id', {
|
|
188
|
+
* tools: [{ name: 'fetch-data', code: '...' }],
|
|
189
|
+
* });
|
|
190
|
+
*/
|
|
191
|
+
deploy(id: string, options: DeployAgentOptions): Promise<DeployResult>;
|
|
192
|
+
/**
|
|
193
|
+
* Trigger an agent run.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* const { executionId } = await auten.agents.run('agent-id', { inputData: '...' });
|
|
197
|
+
*/
|
|
198
|
+
run(id: string, data?: Record<string, any>): Promise<AgentRunResult>;
|
|
199
|
+
/**
|
|
200
|
+
* Get agent status.
|
|
201
|
+
*/
|
|
202
|
+
status(id: string): Promise<{
|
|
203
|
+
status: string;
|
|
204
|
+
lastRunAt?: string;
|
|
205
|
+
}>;
|
|
206
|
+
/**
|
|
207
|
+
* Get agent run history.
|
|
208
|
+
*/
|
|
209
|
+
history(id: string): Promise<any[]>;
|
|
210
|
+
/**
|
|
211
|
+
* Delete an agent and all its knowledge/tools.
|
|
212
|
+
*/
|
|
213
|
+
delete(id: string): Promise<void>;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Auten SDK — AI Client
|
|
218
|
+
* AI-powered provider interactions using natural language.
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
declare class AIClient {
|
|
222
|
+
private client;
|
|
223
|
+
constructor(client: HttpClient);
|
|
224
|
+
/**
|
|
225
|
+
* Execute a task using AI to interpret and call the right provider APIs.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* const result = await auten.ai.execute(
|
|
229
|
+
* 'google-sheets',
|
|
230
|
+
* 'Find Q1 revenue totals and create a summary row'
|
|
231
|
+
* );
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* const result = await auten.ai.execute(
|
|
235
|
+
* 'zoho-crm',
|
|
236
|
+
* 'Find all deals closing this month worth over $10k',
|
|
237
|
+
* { currency: 'USD' }
|
|
238
|
+
* );
|
|
239
|
+
*/
|
|
240
|
+
execute(provider: string, task: string, context?: Record<string, any>): Promise<AIExecuteResult>;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Auten SDK — Error Classes
|
|
245
|
+
*/
|
|
246
|
+
declare class AutenError extends Error {
|
|
247
|
+
constructor(message: string);
|
|
248
|
+
}
|
|
249
|
+
declare class AutenApiError extends AutenError {
|
|
250
|
+
readonly code: string;
|
|
251
|
+
readonly statusCode: number;
|
|
252
|
+
readonly details: unknown;
|
|
253
|
+
constructor(code: string, message: string, statusCode: number, details?: unknown);
|
|
254
|
+
}
|
|
255
|
+
declare class AutenAuthError extends AutenApiError {
|
|
256
|
+
constructor(message: string, code?: string);
|
|
257
|
+
}
|
|
258
|
+
declare class AutenRateLimitError extends AutenApiError {
|
|
259
|
+
readonly retryAfter: number;
|
|
260
|
+
constructor(message: string, retryAfter: number);
|
|
261
|
+
}
|
|
262
|
+
declare class AutenNotFoundError extends AutenApiError {
|
|
263
|
+
constructor(message: string);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Auten.ai SDK
|
|
268
|
+
*
|
|
269
|
+
* AI-native integrations with managed OAuth.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```typescript
|
|
273
|
+
* import { Auten } from '@autenai/sdk';
|
|
274
|
+
*
|
|
275
|
+
* const auten = new Auten({ apiKey: 'auten_live_...' });
|
|
276
|
+
*
|
|
277
|
+
* // List connected providers
|
|
278
|
+
* const providers = await auten.providers.list();
|
|
279
|
+
*
|
|
280
|
+
* // Execute provider action
|
|
281
|
+
* const emails = await auten.providers.execute('google-gmail', 'listEmails', {
|
|
282
|
+
* query: 'is:unread',
|
|
283
|
+
* });
|
|
284
|
+
*
|
|
285
|
+
* // AI-powered execution
|
|
286
|
+
* const result = await auten.ai.execute(
|
|
287
|
+
* 'google-sheets',
|
|
288
|
+
* 'Find Q1 revenue totals'
|
|
289
|
+
* );
|
|
290
|
+
*
|
|
291
|
+
* // Manage agents
|
|
292
|
+
* const agents = await auten.agents.list();
|
|
293
|
+
* await auten.agents.run('agent-id');
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
|
|
297
|
+
declare class Auten {
|
|
298
|
+
/** Provider connections and execution */
|
|
299
|
+
readonly providers: ProviderClient;
|
|
300
|
+
/** Agent management */
|
|
301
|
+
readonly agents: AgentClient;
|
|
302
|
+
/** AI-powered execution */
|
|
303
|
+
readonly ai: AIClient;
|
|
304
|
+
private readonly client;
|
|
305
|
+
constructor(config: AutenConfig);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export { type AIExecuteResult, type Agent, type AgentDetail, type AgentRunResult, type AgentSchedule, type AgentTool, Auten, AutenApiError, AutenAuthError, type AutenConfig, AutenError, AutenNotFoundError, AutenRateLimitError, type CreateAgentOptions, type CreateAgentResult, type DeployAgentOptions, type DeployResult, type ExecuteResult, type Provider, type ProviderCredentials };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Auten: () => Auten,
|
|
24
|
+
AutenApiError: () => AutenApiError,
|
|
25
|
+
AutenAuthError: () => AutenAuthError,
|
|
26
|
+
AutenError: () => AutenError,
|
|
27
|
+
AutenNotFoundError: () => AutenNotFoundError,
|
|
28
|
+
AutenRateLimitError: () => AutenRateLimitError
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
|
|
32
|
+
// src/errors.ts
|
|
33
|
+
var AutenError = class extends Error {
|
|
34
|
+
constructor(message) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = "AutenError";
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var AutenApiError = class extends AutenError {
|
|
40
|
+
code;
|
|
41
|
+
statusCode;
|
|
42
|
+
details;
|
|
43
|
+
constructor(code, message, statusCode, details) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.name = "AutenApiError";
|
|
46
|
+
this.code = code;
|
|
47
|
+
this.statusCode = statusCode;
|
|
48
|
+
this.details = details;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var AutenAuthError = class extends AutenApiError {
|
|
52
|
+
constructor(message, code = "UNAUTHORIZED") {
|
|
53
|
+
super(code, message, 401);
|
|
54
|
+
this.name = "AutenAuthError";
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var AutenRateLimitError = class extends AutenApiError {
|
|
58
|
+
retryAfter;
|
|
59
|
+
constructor(message, retryAfter) {
|
|
60
|
+
super("RATE_LIMIT_EXCEEDED", message, 429, { retryAfter });
|
|
61
|
+
this.name = "AutenRateLimitError";
|
|
62
|
+
this.retryAfter = retryAfter;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var AutenNotFoundError = class extends AutenApiError {
|
|
66
|
+
constructor(message) {
|
|
67
|
+
super("RESOURCE_NOT_FOUND", message, 404);
|
|
68
|
+
this.name = "AutenNotFoundError";
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/client.ts
|
|
73
|
+
var HttpClient = class {
|
|
74
|
+
config;
|
|
75
|
+
constructor(config) {
|
|
76
|
+
this.config = config;
|
|
77
|
+
}
|
|
78
|
+
async get(path) {
|
|
79
|
+
return this.request("GET", path);
|
|
80
|
+
}
|
|
81
|
+
async post(path, body) {
|
|
82
|
+
return this.request("POST", path, body);
|
|
83
|
+
}
|
|
84
|
+
async del(path) {
|
|
85
|
+
return this.request("DELETE", path);
|
|
86
|
+
}
|
|
87
|
+
async request(method, path, body) {
|
|
88
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
89
|
+
let lastError = null;
|
|
90
|
+
for (let attempt = 0; attempt <= this.config.retries; attempt++) {
|
|
91
|
+
try {
|
|
92
|
+
const controller = new AbortController();
|
|
93
|
+
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
94
|
+
const response = await fetch(url, {
|
|
95
|
+
method,
|
|
96
|
+
headers: {
|
|
97
|
+
"Authorization": `Bearer ${this.config.apiKey}`,
|
|
98
|
+
"Content-Type": "application/json",
|
|
99
|
+
"User-Agent": "@auten/sdk"
|
|
100
|
+
},
|
|
101
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
102
|
+
signal: controller.signal
|
|
103
|
+
});
|
|
104
|
+
clearTimeout(timeoutId);
|
|
105
|
+
if (response.status === 204) {
|
|
106
|
+
return void 0;
|
|
107
|
+
}
|
|
108
|
+
const data = await response.json();
|
|
109
|
+
if (response.ok && data.success) {
|
|
110
|
+
return data.data;
|
|
111
|
+
}
|
|
112
|
+
const errorData = data;
|
|
113
|
+
const errorCode = errorData.error?.code || "UNKNOWN";
|
|
114
|
+
const errorMessage = errorData.error?.message || "Unknown error";
|
|
115
|
+
const errorDetails = errorData.error?.details;
|
|
116
|
+
if (response.status === 429) {
|
|
117
|
+
const retryAfter = errorDetails?.retryAfter || 5;
|
|
118
|
+
if (attempt < this.config.retries) {
|
|
119
|
+
await this.sleep(retryAfter * 1e3);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
throw new AutenRateLimitError(errorMessage, retryAfter);
|
|
123
|
+
}
|
|
124
|
+
if (response.status === 401) {
|
|
125
|
+
throw new AutenAuthError(errorMessage, errorCode);
|
|
126
|
+
}
|
|
127
|
+
if (response.status === 404) {
|
|
128
|
+
throw new AutenNotFoundError(errorMessage);
|
|
129
|
+
}
|
|
130
|
+
if (response.status >= 500 && attempt < this.config.retries) {
|
|
131
|
+
lastError = new AutenApiError(errorCode, errorMessage, response.status, errorDetails);
|
|
132
|
+
await this.sleep(Math.pow(2, attempt) * 1e3);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
throw new AutenApiError(errorCode, errorMessage, response.status, errorDetails);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
if (error instanceof AutenApiError) {
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
141
|
+
lastError = new AutenError(`Request timed out after ${this.config.timeout}ms`);
|
|
142
|
+
} else {
|
|
143
|
+
lastError = error;
|
|
144
|
+
}
|
|
145
|
+
if (attempt < this.config.retries) {
|
|
146
|
+
await this.sleep(Math.pow(2, attempt) * 1e3);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
throw lastError || new AutenError("Request failed after retries");
|
|
152
|
+
}
|
|
153
|
+
sleep(ms) {
|
|
154
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/providers.ts
|
|
159
|
+
var ProviderClient = class {
|
|
160
|
+
constructor(client) {
|
|
161
|
+
this.client = client;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* List all connected providers for the authenticated user.
|
|
165
|
+
*/
|
|
166
|
+
async list() {
|
|
167
|
+
return this.client.get("/api/v1/sdk/providers");
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Execute an action on a provider.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* const result = await auten.providers.execute('google-gmail', 'listEmails', { query: 'is:unread' });
|
|
174
|
+
*/
|
|
175
|
+
async execute(slug, action, params) {
|
|
176
|
+
return this.client.post(`/api/v1/sdk/providers/${slug}/execute`, {
|
|
177
|
+
action,
|
|
178
|
+
params
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Get a valid access token for a provider.
|
|
183
|
+
* Token is automatically refreshed if expired.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* const { accessToken } = await auten.providers.getCredentials('google-gmail');
|
|
187
|
+
*/
|
|
188
|
+
async getCredentials(slug) {
|
|
189
|
+
return this.client.get(`/api/v1/sdk/providers/${slug}/credentials`);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// src/agents.ts
|
|
194
|
+
var AgentClient = class {
|
|
195
|
+
constructor(client) {
|
|
196
|
+
this.client = client;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* List all agents for the authenticated user.
|
|
200
|
+
*/
|
|
201
|
+
async list() {
|
|
202
|
+
return this.client.get("/api/v1/sdk/agents");
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get agent details including tools and schedule.
|
|
206
|
+
*/
|
|
207
|
+
async get(id) {
|
|
208
|
+
return this.client.get(`/api/v1/sdk/agents/${id}`);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Create a new agent.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* const agent = await auten.agents.create({
|
|
215
|
+
* name: 'Invoice Processor',
|
|
216
|
+
* tools: [{ name: 'process-invoice', code: '...' }],
|
|
217
|
+
* schedule: { cron: '0 9 * * *', timezone: 'Europe/Vilnius' },
|
|
218
|
+
* });
|
|
219
|
+
*/
|
|
220
|
+
async create(options) {
|
|
221
|
+
return this.client.post("/api/v1/sdk/agents", options);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Deploy tools to an existing agent.
|
|
225
|
+
* Upserts tool code and updates the agent configuration.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* await auten.agents.deploy('agent-id', {
|
|
229
|
+
* tools: [{ name: 'fetch-data', code: '...' }],
|
|
230
|
+
* });
|
|
231
|
+
*/
|
|
232
|
+
async deploy(id, options) {
|
|
233
|
+
return this.client.post(`/api/v1/sdk/agents/${id}/deploy`, options);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Trigger an agent run.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* const { executionId } = await auten.agents.run('agent-id', { inputData: '...' });
|
|
240
|
+
*/
|
|
241
|
+
async run(id, data) {
|
|
242
|
+
return this.client.post(`/api/v1/agents/${id}/run`, data);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Get agent status.
|
|
246
|
+
*/
|
|
247
|
+
async status(id) {
|
|
248
|
+
return this.client.get(`/api/v1/agents/${id}/status`);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Get agent run history.
|
|
252
|
+
*/
|
|
253
|
+
async history(id) {
|
|
254
|
+
return this.client.get(`/api/v1/agents/${id}/history`);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Delete an agent and all its knowledge/tools.
|
|
258
|
+
*/
|
|
259
|
+
async delete(id) {
|
|
260
|
+
await this.client.del(`/api/v1/sdk/agents/${id}`);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// src/ai.ts
|
|
265
|
+
var AIClient = class {
|
|
266
|
+
constructor(client) {
|
|
267
|
+
this.client = client;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Execute a task using AI to interpret and call the right provider APIs.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* const result = await auten.ai.execute(
|
|
274
|
+
* 'google-sheets',
|
|
275
|
+
* 'Find Q1 revenue totals and create a summary row'
|
|
276
|
+
* );
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* const result = await auten.ai.execute(
|
|
280
|
+
* 'zoho-crm',
|
|
281
|
+
* 'Find all deals closing this month worth over $10k',
|
|
282
|
+
* { currency: 'USD' }
|
|
283
|
+
* );
|
|
284
|
+
*/
|
|
285
|
+
async execute(provider, task, context) {
|
|
286
|
+
return this.client.post("/api/v1/sdk/ai/execute", {
|
|
287
|
+
provider,
|
|
288
|
+
task,
|
|
289
|
+
context
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// src/index.ts
|
|
295
|
+
var DEFAULT_BASE_URL = "https://auten.ai";
|
|
296
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
297
|
+
var DEFAULT_RETRIES = 3;
|
|
298
|
+
var Auten = class {
|
|
299
|
+
/** Provider connections and execution */
|
|
300
|
+
providers;
|
|
301
|
+
/** Agent management */
|
|
302
|
+
agents;
|
|
303
|
+
/** AI-powered execution */
|
|
304
|
+
ai;
|
|
305
|
+
client;
|
|
306
|
+
constructor(config) {
|
|
307
|
+
if (!config.apiKey) {
|
|
308
|
+
throw new AutenError("apiKey is required. Get one at https://auten.ai/settings \u2192 API Keys");
|
|
309
|
+
}
|
|
310
|
+
this.client = new HttpClient({
|
|
311
|
+
apiKey: config.apiKey,
|
|
312
|
+
baseUrl: (config.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, ""),
|
|
313
|
+
timeout: config.timeout || DEFAULT_TIMEOUT,
|
|
314
|
+
retries: config.retries ?? DEFAULT_RETRIES
|
|
315
|
+
});
|
|
316
|
+
this.providers = new ProviderClient(this.client);
|
|
317
|
+
this.agents = new AgentClient(this.client);
|
|
318
|
+
this.ai = new AIClient(this.client);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
322
|
+
0 && (module.exports = {
|
|
323
|
+
Auten,
|
|
324
|
+
AutenApiError,
|
|
325
|
+
AutenAuthError,
|
|
326
|
+
AutenError,
|
|
327
|
+
AutenNotFoundError,
|
|
328
|
+
AutenRateLimitError
|
|
329
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var AutenError = class extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "AutenError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var AutenApiError = class extends AutenError {
|
|
9
|
+
code;
|
|
10
|
+
statusCode;
|
|
11
|
+
details;
|
|
12
|
+
constructor(code, message, statusCode, details) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "AutenApiError";
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.statusCode = statusCode;
|
|
17
|
+
this.details = details;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var AutenAuthError = class extends AutenApiError {
|
|
21
|
+
constructor(message, code = "UNAUTHORIZED") {
|
|
22
|
+
super(code, message, 401);
|
|
23
|
+
this.name = "AutenAuthError";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var AutenRateLimitError = class extends AutenApiError {
|
|
27
|
+
retryAfter;
|
|
28
|
+
constructor(message, retryAfter) {
|
|
29
|
+
super("RATE_LIMIT_EXCEEDED", message, 429, { retryAfter });
|
|
30
|
+
this.name = "AutenRateLimitError";
|
|
31
|
+
this.retryAfter = retryAfter;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var AutenNotFoundError = class extends AutenApiError {
|
|
35
|
+
constructor(message) {
|
|
36
|
+
super("RESOURCE_NOT_FOUND", message, 404);
|
|
37
|
+
this.name = "AutenNotFoundError";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/client.ts
|
|
42
|
+
var HttpClient = class {
|
|
43
|
+
config;
|
|
44
|
+
constructor(config) {
|
|
45
|
+
this.config = config;
|
|
46
|
+
}
|
|
47
|
+
async get(path) {
|
|
48
|
+
return this.request("GET", path);
|
|
49
|
+
}
|
|
50
|
+
async post(path, body) {
|
|
51
|
+
return this.request("POST", path, body);
|
|
52
|
+
}
|
|
53
|
+
async del(path) {
|
|
54
|
+
return this.request("DELETE", path);
|
|
55
|
+
}
|
|
56
|
+
async request(method, path, body) {
|
|
57
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
58
|
+
let lastError = null;
|
|
59
|
+
for (let attempt = 0; attempt <= this.config.retries; attempt++) {
|
|
60
|
+
try {
|
|
61
|
+
const controller = new AbortController();
|
|
62
|
+
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
63
|
+
const response = await fetch(url, {
|
|
64
|
+
method,
|
|
65
|
+
headers: {
|
|
66
|
+
"Authorization": `Bearer ${this.config.apiKey}`,
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
|
+
"User-Agent": "@auten/sdk"
|
|
69
|
+
},
|
|
70
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
71
|
+
signal: controller.signal
|
|
72
|
+
});
|
|
73
|
+
clearTimeout(timeoutId);
|
|
74
|
+
if (response.status === 204) {
|
|
75
|
+
return void 0;
|
|
76
|
+
}
|
|
77
|
+
const data = await response.json();
|
|
78
|
+
if (response.ok && data.success) {
|
|
79
|
+
return data.data;
|
|
80
|
+
}
|
|
81
|
+
const errorData = data;
|
|
82
|
+
const errorCode = errorData.error?.code || "UNKNOWN";
|
|
83
|
+
const errorMessage = errorData.error?.message || "Unknown error";
|
|
84
|
+
const errorDetails = errorData.error?.details;
|
|
85
|
+
if (response.status === 429) {
|
|
86
|
+
const retryAfter = errorDetails?.retryAfter || 5;
|
|
87
|
+
if (attempt < this.config.retries) {
|
|
88
|
+
await this.sleep(retryAfter * 1e3);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
throw new AutenRateLimitError(errorMessage, retryAfter);
|
|
92
|
+
}
|
|
93
|
+
if (response.status === 401) {
|
|
94
|
+
throw new AutenAuthError(errorMessage, errorCode);
|
|
95
|
+
}
|
|
96
|
+
if (response.status === 404) {
|
|
97
|
+
throw new AutenNotFoundError(errorMessage);
|
|
98
|
+
}
|
|
99
|
+
if (response.status >= 500 && attempt < this.config.retries) {
|
|
100
|
+
lastError = new AutenApiError(errorCode, errorMessage, response.status, errorDetails);
|
|
101
|
+
await this.sleep(Math.pow(2, attempt) * 1e3);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
throw new AutenApiError(errorCode, errorMessage, response.status, errorDetails);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
if (error instanceof AutenApiError) {
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
110
|
+
lastError = new AutenError(`Request timed out after ${this.config.timeout}ms`);
|
|
111
|
+
} else {
|
|
112
|
+
lastError = error;
|
|
113
|
+
}
|
|
114
|
+
if (attempt < this.config.retries) {
|
|
115
|
+
await this.sleep(Math.pow(2, attempt) * 1e3);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
throw lastError || new AutenError("Request failed after retries");
|
|
121
|
+
}
|
|
122
|
+
sleep(ms) {
|
|
123
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/providers.ts
|
|
128
|
+
var ProviderClient = class {
|
|
129
|
+
constructor(client) {
|
|
130
|
+
this.client = client;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* List all connected providers for the authenticated user.
|
|
134
|
+
*/
|
|
135
|
+
async list() {
|
|
136
|
+
return this.client.get("/api/v1/sdk/providers");
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Execute an action on a provider.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* const result = await auten.providers.execute('google-gmail', 'listEmails', { query: 'is:unread' });
|
|
143
|
+
*/
|
|
144
|
+
async execute(slug, action, params) {
|
|
145
|
+
return this.client.post(`/api/v1/sdk/providers/${slug}/execute`, {
|
|
146
|
+
action,
|
|
147
|
+
params
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get a valid access token for a provider.
|
|
152
|
+
* Token is automatically refreshed if expired.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* const { accessToken } = await auten.providers.getCredentials('google-gmail');
|
|
156
|
+
*/
|
|
157
|
+
async getCredentials(slug) {
|
|
158
|
+
return this.client.get(`/api/v1/sdk/providers/${slug}/credentials`);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// src/agents.ts
|
|
163
|
+
var AgentClient = class {
|
|
164
|
+
constructor(client) {
|
|
165
|
+
this.client = client;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* List all agents for the authenticated user.
|
|
169
|
+
*/
|
|
170
|
+
async list() {
|
|
171
|
+
return this.client.get("/api/v1/sdk/agents");
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get agent details including tools and schedule.
|
|
175
|
+
*/
|
|
176
|
+
async get(id) {
|
|
177
|
+
return this.client.get(`/api/v1/sdk/agents/${id}`);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Create a new agent.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* const agent = await auten.agents.create({
|
|
184
|
+
* name: 'Invoice Processor',
|
|
185
|
+
* tools: [{ name: 'process-invoice', code: '...' }],
|
|
186
|
+
* schedule: { cron: '0 9 * * *', timezone: 'Europe/Vilnius' },
|
|
187
|
+
* });
|
|
188
|
+
*/
|
|
189
|
+
async create(options) {
|
|
190
|
+
return this.client.post("/api/v1/sdk/agents", options);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Deploy tools to an existing agent.
|
|
194
|
+
* Upserts tool code and updates the agent configuration.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* await auten.agents.deploy('agent-id', {
|
|
198
|
+
* tools: [{ name: 'fetch-data', code: '...' }],
|
|
199
|
+
* });
|
|
200
|
+
*/
|
|
201
|
+
async deploy(id, options) {
|
|
202
|
+
return this.client.post(`/api/v1/sdk/agents/${id}/deploy`, options);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Trigger an agent run.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* const { executionId } = await auten.agents.run('agent-id', { inputData: '...' });
|
|
209
|
+
*/
|
|
210
|
+
async run(id, data) {
|
|
211
|
+
return this.client.post(`/api/v1/agents/${id}/run`, data);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Get agent status.
|
|
215
|
+
*/
|
|
216
|
+
async status(id) {
|
|
217
|
+
return this.client.get(`/api/v1/agents/${id}/status`);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get agent run history.
|
|
221
|
+
*/
|
|
222
|
+
async history(id) {
|
|
223
|
+
return this.client.get(`/api/v1/agents/${id}/history`);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Delete an agent and all its knowledge/tools.
|
|
227
|
+
*/
|
|
228
|
+
async delete(id) {
|
|
229
|
+
await this.client.del(`/api/v1/sdk/agents/${id}`);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// src/ai.ts
|
|
234
|
+
var AIClient = class {
|
|
235
|
+
constructor(client) {
|
|
236
|
+
this.client = client;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Execute a task using AI to interpret and call the right provider APIs.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* const result = await auten.ai.execute(
|
|
243
|
+
* 'google-sheets',
|
|
244
|
+
* 'Find Q1 revenue totals and create a summary row'
|
|
245
|
+
* );
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* const result = await auten.ai.execute(
|
|
249
|
+
* 'zoho-crm',
|
|
250
|
+
* 'Find all deals closing this month worth over $10k',
|
|
251
|
+
* { currency: 'USD' }
|
|
252
|
+
* );
|
|
253
|
+
*/
|
|
254
|
+
async execute(provider, task, context) {
|
|
255
|
+
return this.client.post("/api/v1/sdk/ai/execute", {
|
|
256
|
+
provider,
|
|
257
|
+
task,
|
|
258
|
+
context
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// src/index.ts
|
|
264
|
+
var DEFAULT_BASE_URL = "https://auten.ai";
|
|
265
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
266
|
+
var DEFAULT_RETRIES = 3;
|
|
267
|
+
var Auten = class {
|
|
268
|
+
/** Provider connections and execution */
|
|
269
|
+
providers;
|
|
270
|
+
/** Agent management */
|
|
271
|
+
agents;
|
|
272
|
+
/** AI-powered execution */
|
|
273
|
+
ai;
|
|
274
|
+
client;
|
|
275
|
+
constructor(config) {
|
|
276
|
+
if (!config.apiKey) {
|
|
277
|
+
throw new AutenError("apiKey is required. Get one at https://auten.ai/settings \u2192 API Keys");
|
|
278
|
+
}
|
|
279
|
+
this.client = new HttpClient({
|
|
280
|
+
apiKey: config.apiKey,
|
|
281
|
+
baseUrl: (config.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, ""),
|
|
282
|
+
timeout: config.timeout || DEFAULT_TIMEOUT,
|
|
283
|
+
retries: config.retries ?? DEFAULT_RETRIES
|
|
284
|
+
});
|
|
285
|
+
this.providers = new ProviderClient(this.client);
|
|
286
|
+
this.agents = new AgentClient(this.client);
|
|
287
|
+
this.ai = new AIClient(this.client);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
export {
|
|
291
|
+
Auten,
|
|
292
|
+
AutenApiError,
|
|
293
|
+
AutenAuthError,
|
|
294
|
+
AutenError,
|
|
295
|
+
AutenNotFoundError,
|
|
296
|
+
AutenRateLimitError
|
|
297
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@autenai/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Auten.ai SDK — AI-native integrations with managed OAuth",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
20
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"auten",
|
|
25
|
+
"ai",
|
|
26
|
+
"oauth",
|
|
27
|
+
"integrations",
|
|
28
|
+
"agents",
|
|
29
|
+
"automation"
|
|
30
|
+
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"tsup": "^8.0.0",
|
|
34
|
+
"typescript": "^5.3.0"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18.0.0"
|
|
38
|
+
}
|
|
39
|
+
}
|