@insforge/sdk 1.1.2 → 1.1.3-test.1
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/LICENSE +201 -201
- package/README.md +259 -259
- package/dist/index.d.mts +53 -1
- package/dist/index.d.ts +53 -1
- package/dist/index.js +120 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +120 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +68 -68
package/dist/index.mjs
CHANGED
|
@@ -383,7 +383,7 @@ var Auth = class {
|
|
|
383
383
|
* Handles token storage, CSRF token, and HTTP client auth header
|
|
384
384
|
*/
|
|
385
385
|
saveSessionFromResponse(response) {
|
|
386
|
-
if (
|
|
386
|
+
if (!response.accessToken || !response.user) {
|
|
387
387
|
return false;
|
|
388
388
|
}
|
|
389
389
|
const session = {
|
|
@@ -576,12 +576,10 @@ var Auth = class {
|
|
|
576
576
|
// ============================================================================
|
|
577
577
|
/**
|
|
578
578
|
* Get current session, automatically waits for pending OAuth callback
|
|
579
|
+
* @deprecated Use `getCurrentUser` instead
|
|
579
580
|
*/
|
|
580
581
|
async getCurrentSession() {
|
|
581
582
|
await this.authCallbackHandled;
|
|
582
|
-
if (isHostedAuthEnvironment()) {
|
|
583
|
-
return { data: { session: null }, error: null };
|
|
584
|
-
}
|
|
585
583
|
try {
|
|
586
584
|
const session = this.tokenManager.getSession();
|
|
587
585
|
if (session) {
|
|
@@ -632,6 +630,64 @@ var Auth = class {
|
|
|
632
630
|
};
|
|
633
631
|
}
|
|
634
632
|
}
|
|
633
|
+
/**
|
|
634
|
+
* Get current user, automatically waits for pending OAuth callback
|
|
635
|
+
*/
|
|
636
|
+
async getCurrentUser() {
|
|
637
|
+
await this.authCallbackHandled;
|
|
638
|
+
if (isHostedAuthEnvironment()) {
|
|
639
|
+
return { data: { user: null }, error: null };
|
|
640
|
+
}
|
|
641
|
+
try {
|
|
642
|
+
const session = this.tokenManager.getSession();
|
|
643
|
+
if (session) {
|
|
644
|
+
this.http.setAuthToken(session.accessToken);
|
|
645
|
+
return { data: { user: session.user }, error: null };
|
|
646
|
+
}
|
|
647
|
+
if (typeof window !== "undefined") {
|
|
648
|
+
try {
|
|
649
|
+
const csrfToken = getCsrfToken();
|
|
650
|
+
const response = await this.http.post("/api/auth/refresh", void 0, {
|
|
651
|
+
headers: csrfToken ? { "X-CSRF-Token": csrfToken } : {},
|
|
652
|
+
credentials: "include"
|
|
653
|
+
});
|
|
654
|
+
if (response.accessToken) {
|
|
655
|
+
this.tokenManager.setMemoryMode();
|
|
656
|
+
this.tokenManager.setAccessToken(response.accessToken);
|
|
657
|
+
this.http.setAuthToken(response.accessToken);
|
|
658
|
+
if (response.user) this.tokenManager.setUser(response.user);
|
|
659
|
+
if (response.csrfToken) setCsrfToken(response.csrfToken);
|
|
660
|
+
return { data: { user: response.user ?? null }, error: null };
|
|
661
|
+
}
|
|
662
|
+
} catch (error) {
|
|
663
|
+
if (error instanceof InsForgeError) {
|
|
664
|
+
if (error.statusCode === 404) {
|
|
665
|
+
this.tokenManager.setStorageMode();
|
|
666
|
+
const session2 = this.tokenManager.getSession();
|
|
667
|
+
if (session2?.accessToken) {
|
|
668
|
+
+this.http.setAuthToken(session2.accessToken);
|
|
669
|
+
}
|
|
670
|
+
return { data: { user: session2?.user ?? null }, error: null };
|
|
671
|
+
}
|
|
672
|
+
return { data: { user: null }, error };
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return { data: { user: null }, error: null };
|
|
677
|
+
} catch (error) {
|
|
678
|
+
if (error instanceof InsForgeError) {
|
|
679
|
+
return { data: { user: null }, error };
|
|
680
|
+
}
|
|
681
|
+
return {
|
|
682
|
+
data: { user: null },
|
|
683
|
+
error: new InsForgeError(
|
|
684
|
+
"An unexpected error occurred while getting user",
|
|
685
|
+
500,
|
|
686
|
+
"UNEXPECTED_ERROR"
|
|
687
|
+
)
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
}
|
|
635
691
|
// ============================================================================
|
|
636
692
|
// Profile Management
|
|
637
693
|
// ============================================================================
|
|
@@ -1110,6 +1166,7 @@ var AI = class {
|
|
|
1110
1166
|
this.http = http;
|
|
1111
1167
|
this.chat = new Chat(http);
|
|
1112
1168
|
this.images = new Images(http);
|
|
1169
|
+
this.embeddings = new Embeddings(http);
|
|
1113
1170
|
}
|
|
1114
1171
|
};
|
|
1115
1172
|
var Chat = class {
|
|
@@ -1299,6 +1356,65 @@ var ChatCompletions = class {
|
|
|
1299
1356
|
}
|
|
1300
1357
|
}
|
|
1301
1358
|
};
|
|
1359
|
+
var Embeddings = class {
|
|
1360
|
+
constructor(http) {
|
|
1361
|
+
this.http = http;
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Create embeddings for text input - OpenAI-like response format
|
|
1365
|
+
*
|
|
1366
|
+
* @example
|
|
1367
|
+
* ```typescript
|
|
1368
|
+
* // Single text input
|
|
1369
|
+
* const response = await client.ai.embeddings.create({
|
|
1370
|
+
* model: 'openai/text-embedding-3-small',
|
|
1371
|
+
* input: 'Hello world'
|
|
1372
|
+
* });
|
|
1373
|
+
* console.log(response.data[0].embedding); // number[]
|
|
1374
|
+
*
|
|
1375
|
+
* // Multiple text inputs
|
|
1376
|
+
* const response = await client.ai.embeddings.create({
|
|
1377
|
+
* model: 'openai/text-embedding-3-small',
|
|
1378
|
+
* input: ['Hello world', 'Goodbye world']
|
|
1379
|
+
* });
|
|
1380
|
+
* response.data.forEach((item, i) => {
|
|
1381
|
+
* console.log(`Embedding ${i}:`, item.embedding.slice(0, 5)); // First 5 dimensions
|
|
1382
|
+
* });
|
|
1383
|
+
*
|
|
1384
|
+
* // With custom dimensions (if supported by model)
|
|
1385
|
+
* const response = await client.ai.embeddings.create({
|
|
1386
|
+
* model: 'openai/text-embedding-3-small',
|
|
1387
|
+
* input: 'Hello world',
|
|
1388
|
+
* dimensions: 256
|
|
1389
|
+
* });
|
|
1390
|
+
*
|
|
1391
|
+
* // With base64 encoding format
|
|
1392
|
+
* const response = await client.ai.embeddings.create({
|
|
1393
|
+
* model: 'openai/text-embedding-3-small',
|
|
1394
|
+
* input: 'Hello world',
|
|
1395
|
+
* encoding_format: 'base64'
|
|
1396
|
+
* });
|
|
1397
|
+
* ```
|
|
1398
|
+
*/
|
|
1399
|
+
async create(params) {
|
|
1400
|
+
const response = await this.http.post(
|
|
1401
|
+
"/api/ai/embeddings",
|
|
1402
|
+
params
|
|
1403
|
+
);
|
|
1404
|
+
return {
|
|
1405
|
+
object: response.object,
|
|
1406
|
+
data: response.data,
|
|
1407
|
+
model: response.metadata?.model,
|
|
1408
|
+
usage: response.metadata?.usage ? {
|
|
1409
|
+
prompt_tokens: response.metadata.usage.promptTokens || 0,
|
|
1410
|
+
total_tokens: response.metadata.usage.totalTokens || 0
|
|
1411
|
+
} : {
|
|
1412
|
+
prompt_tokens: 0,
|
|
1413
|
+
total_tokens: 0
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1302
1418
|
var Images = class {
|
|
1303
1419
|
constructor(http) {
|
|
1304
1420
|
this.http = http;
|