@insforge/sdk 1.1.4 → 1.1.6-dev.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.mjs CHANGED
@@ -571,6 +571,30 @@ var Auth = class {
571
571
  return wrapError(error, "An unexpected error occurred during OAuth code exchange");
572
572
  }
573
573
  }
574
+ /**
575
+ * Sign in with an ID token from a native SDK (Google One Tap, etc.)
576
+ * Use this for native mobile apps or Google One Tap on web.
577
+ *
578
+ * @param credentials.provider - The identity provider (currently only 'google' is supported)
579
+ * @param credentials.token - The ID token from the native SDK
580
+ */
581
+ async signInWithIdToken(credentials) {
582
+ try {
583
+ const { provider, token } = credentials;
584
+ const response = await this.http.post("/api/auth/id-token?client_type=mobile", { provider, token }, { credentials: "include" });
585
+ this.saveSessionFromResponse(response);
586
+ return {
587
+ data: {
588
+ accessToken: response.accessToken,
589
+ refreshToken: response.refreshToken,
590
+ user: response.user
591
+ },
592
+ error: null
593
+ };
594
+ } catch (error) {
595
+ return wrapError(error, "An unexpected error occurred during ID token sign in");
596
+ }
597
+ }
574
598
  // ============================================================================
575
599
  // Session Management
576
600
  // ============================================================================
@@ -642,19 +666,6 @@ var Auth = class {
642
666
  const session = this.tokenManager.getSession();
643
667
  if (session) {
644
668
  this.http.setAuthToken(session.accessToken);
645
- if (!session.user || Object.keys(session.user).length === 0) {
646
- try {
647
- const authResponse = await this.http.get(
648
- "/api/auth/sessions/current",
649
- { credentials: "include" }
650
- );
651
- if (authResponse.user) {
652
- session.user = authResponse.user;
653
- this.tokenManager.setUser(authResponse.user);
654
- }
655
- } catch {
656
- }
657
- }
658
669
  return { data: { user: session.user }, error: null };
659
670
  }
660
671
  if (typeof window !== "undefined") {
@@ -1268,7 +1279,11 @@ var ChatCompletions = class {
1268
1279
  // New plugin options
1269
1280
  webSearch: params.webSearch,
1270
1281
  fileParser: params.fileParser,
1271
- thinking: params.thinking
1282
+ thinking: params.thinking,
1283
+ // Tool calling options
1284
+ tools: params.tools,
1285
+ toolChoice: params.toolChoice,
1286
+ parallelToolCalls: params.parallelToolCalls
1272
1287
  };
1273
1288
  if (params.stream) {
1274
1289
  const headers = this.http.getHeaders();
@@ -1303,10 +1318,12 @@ var ChatCompletions = class {
1303
1318
  message: {
1304
1319
  role: "assistant",
1305
1320
  content,
1321
+ // Include tool_calls if present (from tool calling)
1322
+ ...response.tool_calls?.length && { tool_calls: response.tool_calls },
1306
1323
  // Include annotations if present (from web search or file parsing)
1307
- ...response.annotations && { annotations: response.annotations }
1324
+ ...response.annotations?.length && { annotations: response.annotations }
1308
1325
  },
1309
- finish_reason: "stop"
1326
+ finish_reason: response.tool_calls?.length ? "tool_calls" : "stop"
1310
1327
  }
1311
1328
  ],
1312
1329
  usage: response.metadata?.usage || {
@@ -1348,7 +1365,24 @@ var ChatCompletions = class {
1348
1365
  delta: {
1349
1366
  content: data.chunk || data.content
1350
1367
  },
1351
- finish_reason: data.done ? "stop" : null
1368
+ finish_reason: null
1369
+ }
1370
+ ]
1371
+ };
1372
+ }
1373
+ if (data.tool_calls?.length) {
1374
+ yield {
1375
+ id: `chatcmpl-${Date.now()}`,
1376
+ object: "chat.completion.chunk",
1377
+ created: Math.floor(Date.now() / 1e3),
1378
+ model,
1379
+ choices: [
1380
+ {
1381
+ index: 0,
1382
+ delta: {
1383
+ tool_calls: data.tool_calls
1384
+ },
1385
+ finish_reason: "tool_calls"
1352
1386
  }
1353
1387
  ]
1354
1388
  };
@@ -1485,31 +1519,58 @@ var Images = class {
1485
1519
  };
1486
1520
 
1487
1521
  // src/modules/functions.ts
1488
- var Functions = class {
1489
- constructor(http) {
1522
+ var Functions = class _Functions {
1523
+ constructor(http, functionsUrl) {
1490
1524
  this.http = http;
1525
+ this.functionsUrl = functionsUrl || _Functions.deriveSubhostingUrl(http.baseUrl);
1526
+ }
1527
+ /**
1528
+ * Derive the subhosting URL from the base URL.
1529
+ * Base URL pattern: https://{appKey}.{region}.insforge.app
1530
+ * Functions URL: https://{appKey}.functions.insforge.app
1531
+ * Only applies to .insforge.app domains.
1532
+ */
1533
+ static deriveSubhostingUrl(baseUrl) {
1534
+ try {
1535
+ const { hostname } = new URL(baseUrl);
1536
+ if (!hostname.endsWith(".insforge.app")) return void 0;
1537
+ const appKey = hostname.split(".")[0];
1538
+ return `https://${appKey}.functions.insforge.app`;
1539
+ } catch {
1540
+ return void 0;
1541
+ }
1491
1542
  }
1492
1543
  /**
1493
1544
  * Invokes an Edge Function
1545
+ *
1546
+ * If functionsUrl is configured, tries direct subhosting first.
1547
+ * Falls back to proxy URL if subhosting returns 404.
1548
+ *
1494
1549
  * @param slug The function slug to invoke
1495
1550
  * @param options Request options
1496
1551
  */
1497
1552
  async invoke(slug, options = {}) {
1553
+ const { method = "POST", body, headers = {} } = options;
1554
+ if (this.functionsUrl) {
1555
+ try {
1556
+ const data = await this.http.request(method, `${this.functionsUrl}/${slug}`, {
1557
+ body,
1558
+ headers
1559
+ });
1560
+ return { data, error: null };
1561
+ } catch (error) {
1562
+ if (error?.statusCode === 404) {
1563
+ } else {
1564
+ return { data: null, error };
1565
+ }
1566
+ }
1567
+ }
1498
1568
  try {
1499
- const { method = "POST", body, headers = {} } = options;
1500
1569
  const path = `/functions/${slug}`;
1501
- const data = await this.http.request(
1502
- method,
1503
- path,
1504
- { body, headers }
1505
- );
1570
+ const data = await this.http.request(method, path, { body, headers });
1506
1571
  return { data, error: null };
1507
1572
  } catch (error) {
1508
- return {
1509
- data: null,
1510
- error
1511
- // Pass through the full error object with all properties
1512
- };
1573
+ return { data: null, error };
1513
1574
  }
1514
1575
  }
1515
1576
  };
@@ -1807,7 +1868,7 @@ var InsForgeClient = class {
1807
1868
  this.database = new Database(this.http, this.tokenManager);
1808
1869
  this.storage = new Storage(this.http);
1809
1870
  this.ai = new AI(this.http);
1810
- this.functions = new Functions(this.http);
1871
+ this.functions = new Functions(this.http, config.functionsUrl);
1811
1872
  this.realtime = new Realtime(this.http.baseUrl, this.tokenManager, config.anonKey);
1812
1873
  this.emails = new Emails(this.http);
1813
1874
  }