@joai/sdk 0.2.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.
@@ -0,0 +1,577 @@
1
+ //#region ../../node_modules/@joai/warps/dist/index.d.ts
2
+ type WarpLocale = 'en' | 'es' | 'fr' | 'de' | 'it' | 'pt' | 'ru' | 'zh' | 'ja' | 'ko' | 'ar' | 'hi' | 'nl' | 'sv' | 'da' | 'no' | 'fi' | 'pl' | 'tr' | 'el' | 'he' | 'th' | 'vi' | 'id' | 'ms' | 'tl' | string;
3
+ type BuiltInWarpWalletProvider = 'mnemonic' | 'privateKey' | 'coinbase' | 'privy' | 'gaupa';
4
+ type WarpWalletProvider = BuiltInWarpWalletProvider | (string & {});
5
+ declare enum WarpChainName {
6
+ Multiversx = "multiversx",
7
+ Claws = "claws",
8
+ Sui = "sui",
9
+ Ethereum = "ethereum",
10
+ Base = "base",
11
+ Arbitrum = "arbitrum",
12
+ Polygon = "polygon",
13
+ Somnia = "somnia",
14
+ Tempo = "tempo",
15
+ Fastset = "fastset",
16
+ Solana = "solana",
17
+ Near = "near"
18
+ }
19
+ //#endregion
20
+ //#region ../core/dist/index.d.mts
21
+ //#endregion
22
+ //#region src/config/types.d.ts
23
+ type AppEnv = 'mainnet' | 'testnet' | 'devnet' | 'local'; //#endregion
24
+ //#region src/config/urls.d.ts
25
+ //#endregion
26
+ //#region src/http/types.d.ts
27
+ interface IHttpService {
28
+ readonly baseUrl: string;
29
+ readonly authToken: string | null;
30
+ onNetworkError: (error: Error) => void;
31
+ onUnauthorized: (response: IAppResponse<any>) => void;
32
+ onSuccessfulResponse: (response: IAppResponse<any>) => void;
33
+ onMaintenanceMode: (response: IAppResponse<any>) => void;
34
+ get: <T>(url: string, options?: IRequestOptions) => Promise<IAppResponse<T>>;
35
+ post: <T>(url: string, data?: any, options?: IRequestOptions) => Promise<IAppResponse<T>>;
36
+ put: <T>(url: string, data?: any, options?: IRequestOptions) => Promise<IAppResponse<T>>;
37
+ delete: <T>(url: string, options?: IRequestOptions) => Promise<IAppResponse<T>>;
38
+ }
39
+ interface IAppResponse<T> {
40
+ data: T;
41
+ meta?: any;
42
+ body: any;
43
+ errors: any;
44
+ ok: boolean;
45
+ paymentRequired: boolean;
46
+ noContent: boolean;
47
+ original: Response;
48
+ }
49
+ interface IRequestOptions {
50
+ isJson?: boolean;
51
+ headers?: {
52
+ [name: string]: string;
53
+ };
54
+ } //#endregion
55
+ //#region src/http/service.d.ts
56
+ //#endregion
57
+ //#region src/ingestion/types.d.ts
58
+ type IngestionSourceType = 'note' | 'meeting' | 'article' | 'email' | 'chat' | 'post' | 'webhook';
59
+ type IngestionStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'dead_lettered';
60
+ type AppIngestion = {
61
+ id: string;
62
+ shareToken: string | null;
63
+ sourceUrl: string | null;
64
+ viewCount: number;
65
+ signupCount: number;
66
+ status: IngestionStatus;
67
+ sourceType: IngestionSourceType | null;
68
+ sourceProvider: string | null;
69
+ title: string | null;
70
+ name: string | null;
71
+ summary: string | null;
72
+ hook: string | null;
73
+ primitivesCreated: Record<string, number>;
74
+ failureReason: string | null;
75
+ lastError: string | null;
76
+ processedAt: string | null;
77
+ createdAt: string;
78
+ }; //#endregion
79
+ //#region src/character/types.d.ts
80
+ type Character = {
81
+ id: string;
82
+ name: string;
83
+ system: string;
84
+ bio: string;
85
+ }; //#endregion
86
+ //#region src/blueprint/types.d.ts
87
+ type BlueprintTeam = {
88
+ slug: string;
89
+ name: string;
90
+ logo: string | null;
91
+ };
92
+ type Blueprint = {
93
+ slug: string;
94
+ team: BlueprintTeam;
95
+ name: string;
96
+ description: string | null;
97
+ avatar: string | null;
98
+ settings: BlueprintSettings;
99
+ verified: boolean;
100
+ public: boolean;
101
+ createdAt: string;
102
+ locales: WarpLocale[];
103
+ price: number | null;
104
+ purchased: boolean;
105
+ };
106
+ type BlueprintSettings = {
107
+ wallets: WarpChainName[];
108
+ character: Character | null;
109
+ tasks: BlueprintTask[];
110
+ shortcuts: BlueprintShortcut[];
111
+ 'messages.initial': string | null;
112
+ 'messages.general': string[];
113
+ onboarding: BlueprintOnboardingStep[];
114
+ redirect: BlueprintRedirect;
115
+ };
116
+ type BlueprintOnboardingStep = 'wallet' | 'fund';
117
+ type BlueprintRedirect = 'interact' | null;
118
+ type BlueprintTask = {
119
+ warp: string;
120
+ cronExpression: string;
121
+ active: boolean;
122
+ };
123
+ type BlueprintShortcut = {
124
+ name: string;
125
+ description: string | null;
126
+ warp: string;
127
+ chat: boolean;
128
+ }; //#endregion
129
+ //#region src/helpers/string.d.ts
130
+ type MediaLibraryAttributes = {
131
+ uuid: string;
132
+ order: number;
133
+ name: string;
134
+ custom_properties: {
135
+ [key: string]: any;
136
+ };
137
+ preview_url: null | string;
138
+ original_url: null | string;
139
+ extension?: string;
140
+ size?: number;
141
+ };
142
+ type MediaMime = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp' | 'video/mp4' | 'video/webm' | 'video/quicktime' | 'video/x-msvideo' | 'audio/mpeg' | 'audio/mp3' | 'audio/ogg' | 'audio/wav' | 'audio/webm' | 'audio/aac' | 'audio/m4a' | 'audio/m4b' | 'audio/m4p' | 'audio/m4v';
143
+ type Media = {
144
+ id: string;
145
+ name: string;
146
+ mime: MediaMime;
147
+ url: string;
148
+ library: MediaLibraryAttributes;
149
+ }; //#endregion
150
+ //#region src/integration/types.d.ts
151
+ type IntegrationType = 'none' | 'webhook' | 'api-token' | 'telegram' | 'slack' | 'whatsapp' | 'twilio' | 'n8n' | 'ai-nexus' | 'apple-health' | 'mcp' | 'x' | 'email' | 'calendar' | 'embed' | 'discord' | 'github' | 'sentry' | 'readwise';
152
+ type IntegrationDetails = {
153
+ type: IntegrationType;
154
+ name: string;
155
+ description?: string;
156
+ logoUrl?: string;
157
+ logoUrlDark?: string;
158
+ slug?: string;
159
+ category?: string;
160
+ [key: string]: unknown;
161
+ };
162
+ type Integration = {
163
+ id: string;
164
+ type: IntegrationType;
165
+ name: string;
166
+ active: boolean;
167
+ createdAt: string;
168
+ details?: IntegrationDetails;
169
+ };
170
+ type RoomKind = 'default' | 'phone' | 'meeting';
171
+ type Room = {
172
+ id: string;
173
+ name: string;
174
+ description: string | null;
175
+ public: boolean;
176
+ default: boolean;
177
+ kind?: RoomKind | null;
178
+ archivedAt?: string | null;
179
+ secKey: string | null;
180
+ createdAt: string | null;
181
+ agent: AgentSimple;
182
+ integration: Integration | null;
183
+ }; //#endregion
184
+ //#region src/wallet/types.d.ts
185
+ type Wallet = {
186
+ chain: WarpChainName;
187
+ active: boolean;
188
+ provider: WarpWalletProvider;
189
+ address: string;
190
+ privateKey?: string;
191
+ mnemonic?: string;
192
+ };
193
+ //#endregion
194
+ //#region src/agent/types.d.ts
195
+ type AgentMpp = {
196
+ price: number;
197
+ currency?: string;
198
+ chain?: string;
199
+ };
200
+ type AgentPrivate = {
201
+ uuid: string;
202
+ name: string;
203
+ description: string;
204
+ avatar: string;
205
+ wallets: Wallet[];
206
+ settings: AgentSettings;
207
+ mpp?: AgentMpp | null;
208
+ password: string | null;
209
+ authKey: string | null;
210
+ secKey: string;
211
+ emailAddress: string | null;
212
+ phoneNumber: string | null;
213
+ room: Room;
214
+ role: string | null;
215
+ blueprint: Blueprint | null;
216
+ justCreated?: boolean;
217
+ team: string;
218
+ };
219
+ type AgentSimple = {
220
+ uuid: string;
221
+ name: string;
222
+ };
223
+ type AgentEngine = 'cortex' | 'openclaw';
224
+ type AgentGender = 'male' | 'female' | 'neutral';
225
+ type AgentSettings = {
226
+ auto: boolean;
227
+ 'model.url': string;
228
+ 'voice.output': boolean;
229
+ 'voice.id': string;
230
+ 'agent.gender'?: AgentGender;
231
+ 'proactivity.enabled': boolean;
232
+ 'proactivity.quietHoursStart'?: number;
233
+ 'proactivity.quietHoursEnd'?: number;
234
+ 'proactivity.maxMessagesPerDay'?: number;
235
+ 'proactivity.timezone'?: string;
236
+ 'proactivity.blockedBehaviors'?: string[];
237
+ engine: AgentEngine;
238
+ 'training.url'?: string | null;
239
+ 'training.status'?: 'idle' | 'training' | 'completed' | 'failed' | null;
240
+ 'training.recrawlInterval'?: number | null;
241
+ };
242
+ //#endregion
243
+ //#region src/flow/types.d.ts
244
+ type FlowCategory = 'none' | 'defi' | 'nft' | 'social' | 'devtools' | 'productivity' | 'trading' | 'portfolio';
245
+ type FlowStatus = 'draft' | 'published';
246
+ type Flow = {
247
+ slug: string;
248
+ team: Team;
249
+ name: string;
250
+ description: string | null;
251
+ category: FlowCategory;
252
+ status: FlowStatus;
253
+ publishedAt: string | null;
254
+ createdAt: string;
255
+ updatedAt: string;
256
+ steps: FlowStep[];
257
+ locales: WarpLocale[];
258
+ price: number | null;
259
+ purchased: boolean;
260
+ };
261
+ type FlowStep = {
262
+ stepId: string;
263
+ order: number;
264
+ type: 'warp' | 'condition' | 'delay';
265
+ warpIdentifier: string | null;
266
+ dependsOn: string[] | null;
267
+ inputMappings: FlowInputMapping[] | null;
268
+ staticInputs: Record<string, any> | null;
269
+ condition: Record<string, any> | null;
270
+ };
271
+ type FlowInputMapping = {
272
+ sourceStepId: string;
273
+ sourceKey: string;
274
+ targetInput: string;
275
+ transform?: string;
276
+ }; //#endregion
277
+ //#region src/user/types.d.ts
278
+ type Team = {
279
+ slug: string;
280
+ name: string;
281
+ personal: boolean;
282
+ description: string | null;
283
+ locale: WarpLocale;
284
+ timezone: string;
285
+ logo: string | null;
286
+ public: boolean;
287
+ createdAt: string;
288
+ blueprints?: Blueprint[];
289
+ flows?: Flow[];
290
+ };
291
+ //#endregion
292
+ //#region src/contact/types.d.ts
293
+ type Contact = {
294
+ id: string;
295
+ name: string;
296
+ wallets: Wallet[];
297
+ email: string | null;
298
+ phone: string | null;
299
+ company: string | null;
300
+ title: string | null;
301
+ birthday: string | null;
302
+ website: string | null;
303
+ socials: Record<string, string> | null;
304
+ notes: string | null;
305
+ tags: string[] | null;
306
+ };
307
+ type ContactFormData = {
308
+ name?: string;
309
+ email?: string | null;
310
+ phone?: string | null;
311
+ company?: string | null;
312
+ title?: string | null;
313
+ birthday?: string | null;
314
+ website?: string | null;
315
+ socials?: Record<string, string> | null;
316
+ notes?: string | null;
317
+ tags?: string[] | null;
318
+ }; //#endregion
319
+ //#region src/contract/types.d.ts
320
+ //#endregion
321
+ //#region src/document/types.d.ts
322
+ type Document = {
323
+ id: string;
324
+ name: string;
325
+ content: string | null;
326
+ documentUrl: string | null;
327
+ createdAt: string;
328
+ }; //#endregion
329
+ //#region src/experience/types.d.ts
330
+ //#endregion
331
+ //#region src/goal/types.d.ts
332
+ type GoalStatus = 'active' | 'paused' | 'completed' | 'archived';
333
+ type GoalPriority = 'normal' | 'high' | 'critical';
334
+ type Goal = {
335
+ id: string;
336
+ title: string;
337
+ description: string | null;
338
+ status: GoalStatus;
339
+ priority: GoalPriority;
340
+ progress: number;
341
+ createdAt: string;
342
+ updatedAt: string;
343
+ };
344
+ type GoalCreatePayload = {
345
+ title: string;
346
+ description?: string;
347
+ priority?: GoalPriority;
348
+ }; //#endregion
349
+ //#region src/hint/types.d.ts
350
+ //#endregion
351
+ //#region src/item/types.d.ts
352
+ type ItemStatus = 'backlog' | 'active' | 'review' | 'done' | 'archived';
353
+ type ItemPriority = 'normal' | 'high' | 'critical';
354
+ type ItemExecutionStatus = 'running' | 'completed' | 'failed' | 'requires_input' | 'blocked' | 'timeout';
355
+ type Item = {
356
+ id: string;
357
+ title: string;
358
+ description: string | null;
359
+ status: ItemStatus;
360
+ priority: ItemPriority;
361
+ tags: string[];
362
+ dueDate: string | null;
363
+ source: string | null;
364
+ goalId: string | null;
365
+ order: number | null;
366
+ assignedAgents: string[];
367
+ executionStatus: ItemExecutionStatus | null;
368
+ createdAt: string;
369
+ updatedAt: string;
370
+ };
371
+ type ItemCreatePayload = {
372
+ title: string;
373
+ description?: string;
374
+ priority?: ItemPriority;
375
+ tags?: string[];
376
+ dueDate?: string;
377
+ goalId?: string;
378
+ status?: ItemStatus;
379
+ }; //#endregion
380
+ //#region src/marketing/types.d.ts
381
+ //#endregion
382
+ //#region src/memory/types.d.ts
383
+ type Memory = {
384
+ id: string;
385
+ name: string;
386
+ content: string;
387
+ createdAt: string;
388
+ }; //#endregion
389
+ //#region src/peerme/types.d.ts
390
+ type ChatClientAction = 'AGENT_DELEGATE' | 'WARP_EXECUTE' | 'WARP_VIEW' | 'WARP_CREATE' | 'WARP_TEST' | 'WARP_INPUT' | 'WARP_APPROVE' | 'WARP_SELECT' | 'WARP_BATCH' | 'WARP_BULK' | 'ENTITY_PROPOSE' | 'ENTITY_SIGN' | 'SECRET_SET' | 'SECRET_AUTHORIZE' | 'HEALTH_QUERY' | 'HEALTH_WRITE' | 'ITEM_VIEW' | 'BOARD_SUMMARY' | 'GOAL_PROGRESS' | 'CONTACT_VIEW' | 'MARKETPLACE_PURCHASE' | 'WARP_CLOUD_EXECUTE' | 'MISSION_VIEW' | 'ACTIVITY' | 'PERSONA_QUESTION' | 'twilio.call' | 'twilio.sms';
391
+ type Message = {
392
+ id: string;
393
+ room: string;
394
+ role: MessageRole;
395
+ source: string;
396
+ agent: string | null;
397
+ content: string;
398
+ action: ChatClientAction | null;
399
+ credits: number;
400
+ createdAt: string;
401
+ audio: string | null;
402
+ media: Media[];
403
+ meta: {
404
+ tx?: string;
405
+ warp?: string;
406
+ inputs?: string[];
407
+ output?: Record<string, unknown>;
408
+ timeSavedSeconds?: number;
409
+ actionResponded?: boolean;
410
+ reactions?: Record<string, string[]>;
411
+ };
412
+ };
413
+ type MessageRole = 'user' | 'agent' | 'external'; //#endregion
414
+ //#region src/mission/types.d.ts
415
+ //#endregion
416
+ //#region src/reminder/types.d.ts
417
+ type Reminder = {
418
+ id: string;
419
+ text: string;
420
+ scheduledAt: string;
421
+ dispatchedAt?: string | null;
422
+ createdAt: string;
423
+ }; //#endregion
424
+ //#region src/shortcut/types.d.ts
425
+ //#endregion
426
+ //#region src/resources/agents.d.ts
427
+ declare class AgentsResource {
428
+ private readonly http;
429
+ constructor(http: IHttpService);
430
+ list(): Promise<IAppResponse<AgentPrivate[]>>;
431
+ execute(agentUuid: string, payload: {
432
+ room: string;
433
+ message?: string;
434
+ }): Promise<IAppResponse<unknown>>;
435
+ }
436
+ //#endregion
437
+ //#region src/resources/blueprints.d.ts
438
+ declare class BlueprintsResource {
439
+ private readonly http;
440
+ constructor(http: IHttpService);
441
+ get(slug: string, locale?: string): Promise<IAppResponse<Blueprint>>;
442
+ }
443
+ //#endregion
444
+ //#region src/resources/contacts.d.ts
445
+ declare class ContactsResource {
446
+ private readonly http;
447
+ constructor(http: IHttpService);
448
+ list(params?: {
449
+ search?: string;
450
+ }): Promise<IAppResponse<{
451
+ data: Contact[];
452
+ }>>;
453
+ get(id: string): Promise<IAppResponse<Contact>>;
454
+ create(payload: ContactFormData & {
455
+ name: string;
456
+ }): Promise<IAppResponse<Contact>>;
457
+ update(id: string, data: ContactFormData): Promise<IAppResponse<Contact>>;
458
+ delete(id: string): Promise<IAppResponse<unknown>>;
459
+ }
460
+ //#endregion
461
+ //#region src/resources/documents.d.ts
462
+ declare class DocumentsResource {
463
+ private readonly http;
464
+ constructor(http: IHttpService);
465
+ ingest(payload: {
466
+ title: string;
467
+ content: string;
468
+ }): Promise<IAppResponse<Document>>;
469
+ }
470
+ //#endregion
471
+ //#region src/resources/goals.d.ts
472
+ declare class GoalsResource {
473
+ private readonly http;
474
+ constructor(http: IHttpService);
475
+ list(): Promise<IAppResponse<{
476
+ data: Goal[];
477
+ }>>;
478
+ create(payload: {
479
+ agentId: string;
480
+ } & GoalCreatePayload): Promise<IAppResponse<Goal>>;
481
+ update(id: string, data: Partial<Goal>): Promise<IAppResponse<Goal>>;
482
+ }
483
+ //#endregion
484
+ //#region src/resources/ingestions.d.ts
485
+ declare class IngestionsResource {
486
+ private readonly http;
487
+ constructor(http: IHttpService);
488
+ getShared(shareToken: string): Promise<IAppResponse<AppIngestion>>;
489
+ }
490
+ //#endregion
491
+ //#region src/resources/items.d.ts
492
+ declare class ItemsResource {
493
+ private readonly http;
494
+ constructor(http: IHttpService);
495
+ list(params?: {
496
+ status?: string;
497
+ }): Promise<IAppResponse<{
498
+ data: Item[];
499
+ }>>;
500
+ get(id: string): Promise<IAppResponse<Item>>;
501
+ create(payload: ItemCreatePayload): Promise<IAppResponse<Item>>;
502
+ update(id: string, data: Partial<Item>): Promise<IAppResponse<Item>>;
503
+ delete(id: string): Promise<IAppResponse<unknown>>;
504
+ }
505
+ //#endregion
506
+ //#region src/resources/memories.d.ts
507
+ declare class MemoriesResource {
508
+ private readonly http;
509
+ constructor(http: IHttpService);
510
+ list(params?: {
511
+ search?: string;
512
+ }): Promise<IAppResponse<{
513
+ data: Memory[];
514
+ }>>;
515
+ add(payload: {
516
+ agentId: string;
517
+ content: string;
518
+ }): Promise<IAppResponse<Memory>>;
519
+ delete(id: string): Promise<IAppResponse<unknown>>;
520
+ }
521
+ //#endregion
522
+ //#region src/resources/reminders.d.ts
523
+ declare class RemindersResource {
524
+ private readonly http;
525
+ constructor(http: IHttpService);
526
+ list(): Promise<IAppResponse<{
527
+ data: Reminder[];
528
+ }>>;
529
+ add(payload: {
530
+ agentId: string;
531
+ text: string;
532
+ scheduledAt: string;
533
+ }): Promise<IAppResponse<Reminder>>;
534
+ delete(id: string): Promise<IAppResponse<unknown>>;
535
+ }
536
+ //#endregion
537
+ //#region src/resources/rooms.d.ts
538
+ declare class RoomsResource {
539
+ private readonly http;
540
+ constructor(http: IHttpService);
541
+ list(): Promise<IAppResponse<Room[]>>;
542
+ messages(roomId: string, params?: {
543
+ perPage?: number;
544
+ }): Promise<IAppResponse<Message[]>>;
545
+ }
546
+ //#endregion
547
+ //#region src/resources/teams.d.ts
548
+ declare class TeamsResource {
549
+ private readonly http;
550
+ constructor(http: IHttpService);
551
+ list(): Promise<IAppResponse<Team[]>>;
552
+ }
553
+ //#endregion
554
+ //#region src/client.d.ts
555
+ interface JoAiClientConfig {
556
+ apiToken?: string;
557
+ team?: string;
558
+ env?: AppEnv;
559
+ }
560
+ declare class JoAiClient {
561
+ readonly http: IHttpService;
562
+ readonly teams: TeamsResource;
563
+ readonly agents: AgentsResource;
564
+ readonly blueprints: BlueprintsResource;
565
+ readonly ingestions: IngestionsResource;
566
+ readonly rooms: RoomsResource;
567
+ readonly contacts: ContactsResource;
568
+ readonly items: ItemsResource;
569
+ readonly memories: MemoriesResource;
570
+ readonly goals: GoalsResource;
571
+ readonly reminders: RemindersResource;
572
+ readonly documents: DocumentsResource;
573
+ constructor(config: JoAiClientConfig);
574
+ }
575
+ declare function createClient(config: JoAiClientConfig): JoAiClient;
576
+ //#endregion
577
+ export { BlueprintsResource, IngestionsResource, JoAiClient, type JoAiClientConfig, createClient };
package/dist/index.mjs ADDED
@@ -0,0 +1,302 @@
1
+ //#region ../core/dist/index.mjs
2
+ const toSubdomainBaseUrl = (env, subdomain) => {
3
+ if (env === "local") return `http://${subdomain}.joai--api.test`;
4
+ if (env === "devnet") return `https://devnet-${subdomain}.joai.ai`;
5
+ if (env === "testnet") return `https://testnet-${subdomain}.joai.ai`;
6
+ return `https://${subdomain}.joai.ai`;
7
+ };
8
+ const getApiBaseUrl = (env) => toSubdomainBaseUrl(env, "api");
9
+ var HttpService = class {
10
+ constructor(baseUrl, cookies, authToken, options) {
11
+ this.get = async (url, options) => await this.request("GET", url, void 0, options);
12
+ this.post = async (url, data, options) => await this.request("POST", url, data, options);
13
+ this.put = async (url, data, options) => await this.request("PUT", url, data, options);
14
+ this.delete = async (url, options) => await this.request("DELETE", url, void 0, options);
15
+ this.getCsrfToken = () => {
16
+ if (typeof document === "undefined") return null;
17
+ const match = document.cookie.match(/(?:^|;\s*)XSRF-TOKEN=([^;]*)/);
18
+ return match ? decodeURIComponent(match[1]) : null;
19
+ };
20
+ this.request = async (httpMethod, url, data, options, isRetry) => {
21
+ const requestUrl = url.startsWith("http") ? url : `${this.baseUrl}/${url}`;
22
+ const requestInfo = this.getRequestInfo(httpMethod, data, options);
23
+ const response = await this.convertResponse(this.fetchFn(requestUrl, requestInfo));
24
+ if (response.original.status === 419 && !isRetry) {
25
+ await this.refreshCsrfToken();
26
+ return this.request(httpMethod, url, data, options, true);
27
+ }
28
+ if (response.original.status === 401) this.onUnauthorized(response);
29
+ if (response.original.status === 429) {
30
+ console.warn(`[HTTP 429] ${httpMethod} ${requestUrl}`);
31
+ this.onTooManyRequests(response);
32
+ }
33
+ if (response.original.status === 503) this.onMaintenanceMode(response);
34
+ if (response.ok) this.onSuccessfulResponse(response);
35
+ return response;
36
+ };
37
+ this.refreshCsrfToken = async () => {
38
+ await this.fetchFn(`${this.baseUrl}/sanctum/csrf-cookie`, {
39
+ method: "GET",
40
+ credentials: "include",
41
+ headers: {
42
+ Accept: "application/json",
43
+ ...this.headers
44
+ }
45
+ });
46
+ };
47
+ this.convertResponse = async (apiRes) => {
48
+ try {
49
+ const response = await apiRes;
50
+ const body = response.status === 204 ? {} : await response.json();
51
+ return {
52
+ data: body.data || null,
53
+ meta: body.meta,
54
+ body,
55
+ errors: body.errors || [],
56
+ ok: response.ok && !(body.errors && body.errors.length > 0),
57
+ noContent: response.status === 204,
58
+ paymentRequired: response.status === 402,
59
+ original: response
60
+ };
61
+ } catch (error) {
62
+ this.onNetworkError(error);
63
+ const anyError = error;
64
+ return {
65
+ data: {},
66
+ errors: anyError.response && (anyError.response.data || {}).errors,
67
+ body: {},
68
+ ok: false,
69
+ noContent: false,
70
+ paymentRequired: false,
71
+ original: anyError
72
+ };
73
+ }
74
+ };
75
+ this.getRequestInfo = (httpMethod = "GET", data, options) => {
76
+ const isJson = options?.isJson !== false;
77
+ const isFormData = data instanceof FormData;
78
+ const situationalHeaders = options?.headers || {};
79
+ const csrfToken = httpMethod !== "GET" ? this.getCsrfToken() : null;
80
+ const headers = {
81
+ Accept: "application/json",
82
+ ...this.authToken ? { Authorization: `Bearer ${this.authToken}` } : {},
83
+ ...csrfToken ? { "X-XSRF-TOKEN": csrfToken } : {},
84
+ ...situationalHeaders,
85
+ ...this.headers
86
+ };
87
+ if (isJson && !isFormData) headers["Content-Type"] = "application/json";
88
+ return {
89
+ method: httpMethod,
90
+ credentials: "include",
91
+ headers,
92
+ body: httpMethod !== "GET" ? isJson && !isFormData ? JSON.stringify(data || {}) : data : void 0
93
+ };
94
+ };
95
+ this.baseUrl = baseUrl;
96
+ this.authToken = authToken || null;
97
+ this.fetchFn = options?.customFetch ?? globalThis.fetch.bind(globalThis);
98
+ this.onNetworkError = () => {};
99
+ this.onSuccessfulResponse = () => {};
100
+ this.onUnauthorized = () => {};
101
+ this.onMaintenanceMode = () => {};
102
+ this.onTooManyRequests = () => {};
103
+ this.headers = {
104
+ ...options?.refererUrl ? { Referer: options.refererUrl } : {},
105
+ ...cookies ? { Cookie: cookies } : {},
106
+ ...options?.headers ?? {}
107
+ };
108
+ }
109
+ };
110
+ //#endregion
111
+ //#region src/resources/agents.ts
112
+ var AgentsResource = class {
113
+ constructor(http) {
114
+ this.http = http;
115
+ }
116
+ list() {
117
+ return this.http.get("agents");
118
+ }
119
+ execute(agentUuid, payload) {
120
+ return this.http.post(`agents/${agentUuid}/execute`, payload);
121
+ }
122
+ };
123
+ //#endregion
124
+ //#region src/resources/blueprints.ts
125
+ var BlueprintsResource = class {
126
+ constructor(http) {
127
+ this.http = http;
128
+ }
129
+ get(slug, locale = "en") {
130
+ return this.http.get(`blueprints/${slug}?locale=${locale}`);
131
+ }
132
+ };
133
+ //#endregion
134
+ //#region src/resources/contacts.ts
135
+ var ContactsResource = class {
136
+ constructor(http) {
137
+ this.http = http;
138
+ }
139
+ list(params) {
140
+ const query = new URLSearchParams();
141
+ if (params?.search) query.set("search", params.search);
142
+ const qs = query.toString();
143
+ return this.http.get(`contacts${qs ? "?" + qs : ""}`);
144
+ }
145
+ get(id) {
146
+ return this.http.get(`contacts/${id}`);
147
+ }
148
+ create(payload) {
149
+ return this.http.post("contacts", payload);
150
+ }
151
+ update(id, data) {
152
+ return this.http.put(`contacts/${id}`, data);
153
+ }
154
+ delete(id) {
155
+ return this.http.delete(`contacts/${id}`);
156
+ }
157
+ };
158
+ //#endregion
159
+ //#region src/resources/documents.ts
160
+ var DocumentsResource = class {
161
+ constructor(http) {
162
+ this.http = http;
163
+ }
164
+ ingest(payload) {
165
+ return this.http.post("documents", payload);
166
+ }
167
+ };
168
+ //#endregion
169
+ //#region src/resources/goals.ts
170
+ var GoalsResource = class {
171
+ constructor(http) {
172
+ this.http = http;
173
+ }
174
+ list() {
175
+ return this.http.get("goals");
176
+ }
177
+ create(payload) {
178
+ return this.http.post("goals", payload);
179
+ }
180
+ update(id, data) {
181
+ return this.http.put(`goals/${id}`, data);
182
+ }
183
+ };
184
+ //#endregion
185
+ //#region src/resources/ingestions.ts
186
+ var IngestionsResource = class {
187
+ constructor(http) {
188
+ this.http = http;
189
+ }
190
+ getShared(shareToken) {
191
+ return this.http.get(`ingestions/${shareToken}`);
192
+ }
193
+ };
194
+ //#endregion
195
+ //#region src/resources/items.ts
196
+ var ItemsResource = class {
197
+ constructor(http) {
198
+ this.http = http;
199
+ }
200
+ list(params) {
201
+ const query = new URLSearchParams();
202
+ if (params?.status) query.set("status", params.status);
203
+ const qs = query.toString();
204
+ return this.http.get(`items${qs ? "?" + qs : ""}`);
205
+ }
206
+ get(id) {
207
+ return this.http.get(`items/${id}`);
208
+ }
209
+ create(payload) {
210
+ return this.http.post("items", payload);
211
+ }
212
+ update(id, data) {
213
+ return this.http.put(`items/${id}`, data);
214
+ }
215
+ delete(id) {
216
+ return this.http.delete(`items/${id}`);
217
+ }
218
+ };
219
+ //#endregion
220
+ //#region src/resources/memories.ts
221
+ var MemoriesResource = class {
222
+ constructor(http) {
223
+ this.http = http;
224
+ }
225
+ list(params) {
226
+ const query = new URLSearchParams();
227
+ if (params?.search) query.set("search", params.search);
228
+ const qs = query.toString();
229
+ return this.http.get(`memories${qs ? "?" + qs : ""}`);
230
+ }
231
+ add(payload) {
232
+ return this.http.post("memories", payload);
233
+ }
234
+ delete(id) {
235
+ return this.http.delete(`memories/${id}`);
236
+ }
237
+ };
238
+ //#endregion
239
+ //#region src/resources/reminders.ts
240
+ var RemindersResource = class {
241
+ constructor(http) {
242
+ this.http = http;
243
+ }
244
+ list() {
245
+ return this.http.get("reminders");
246
+ }
247
+ add(payload) {
248
+ return this.http.post("reminders", payload);
249
+ }
250
+ delete(id) {
251
+ return this.http.delete(`reminders/${id}`);
252
+ }
253
+ };
254
+ //#endregion
255
+ //#region src/resources/rooms.ts
256
+ var RoomsResource = class {
257
+ constructor(http) {
258
+ this.http = http;
259
+ }
260
+ list() {
261
+ return this.http.get("rooms");
262
+ }
263
+ messages(roomId, params) {
264
+ const query = new URLSearchParams();
265
+ if (params?.perPage) query.set("perPage", String(params.perPage));
266
+ const qs = query.toString();
267
+ return this.http.get(`rooms/${roomId}/messages${qs ? "?" + qs : ""}`);
268
+ }
269
+ };
270
+ //#endregion
271
+ //#region src/resources/teams.ts
272
+ var TeamsResource = class {
273
+ constructor(http) {
274
+ this.http = http;
275
+ }
276
+ list() {
277
+ return this.http.get("teams");
278
+ }
279
+ };
280
+ //#endregion
281
+ //#region src/client.ts
282
+ var JoAiClient = class {
283
+ constructor(config) {
284
+ this.http = new HttpService(`${getApiBaseUrl(config.env ?? "mainnet")}/v1`, void 0, config.apiToken, { headers: config.team ? { "X-Team": config.team } : void 0 });
285
+ this.teams = new TeamsResource(this.http);
286
+ this.agents = new AgentsResource(this.http);
287
+ this.blueprints = new BlueprintsResource(this.http);
288
+ this.ingestions = new IngestionsResource(this.http);
289
+ this.rooms = new RoomsResource(this.http);
290
+ this.contacts = new ContactsResource(this.http);
291
+ this.items = new ItemsResource(this.http);
292
+ this.memories = new MemoriesResource(this.http);
293
+ this.goals = new GoalsResource(this.http);
294
+ this.reminders = new RemindersResource(this.http);
295
+ this.documents = new DocumentsResource(this.http);
296
+ }
297
+ };
298
+ function createClient(config) {
299
+ return new JoAiClient(config);
300
+ }
301
+ //#endregion
302
+ export { BlueprintsResource, IngestionsResource, JoAiClient, createClient };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@joai/sdk",
3
+ "version": "0.2.0",
4
+ "description": "JoAi public API SDK — build with your AI agents",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.mjs",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "types": "./dist/index.d.mts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "engines": {
18
+ "node": ">=20.0.0"
19
+ },
20
+ "keywords": [
21
+ "joai",
22
+ "ai",
23
+ "agents",
24
+ "sdk",
25
+ "api"
26
+ ],
27
+ "homepage": "https://joai.com",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/JoAiHQ/sdk"
31
+ },
32
+ "scripts": {
33
+ "build": "tsdown",
34
+ "dev": "tsdown --watch"
35
+ },
36
+ "devDependencies": {
37
+ "@joai/core": "*",
38
+ "tsdown": "^0.21.0",
39
+ "typescript": "^5.9.3"
40
+ }
41
+ }