@insforge/sdk 1.1.5 → 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.d.mts +20 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +68 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1279,7 +1279,11 @@ var ChatCompletions = class {
|
|
|
1279
1279
|
// New plugin options
|
|
1280
1280
|
webSearch: params.webSearch,
|
|
1281
1281
|
fileParser: params.fileParser,
|
|
1282
|
-
thinking: params.thinking
|
|
1282
|
+
thinking: params.thinking,
|
|
1283
|
+
// Tool calling options
|
|
1284
|
+
tools: params.tools,
|
|
1285
|
+
toolChoice: params.toolChoice,
|
|
1286
|
+
parallelToolCalls: params.parallelToolCalls
|
|
1283
1287
|
};
|
|
1284
1288
|
if (params.stream) {
|
|
1285
1289
|
const headers = this.http.getHeaders();
|
|
@@ -1314,10 +1318,12 @@ var ChatCompletions = class {
|
|
|
1314
1318
|
message: {
|
|
1315
1319
|
role: "assistant",
|
|
1316
1320
|
content,
|
|
1321
|
+
// Include tool_calls if present (from tool calling)
|
|
1322
|
+
...response.tool_calls?.length && { tool_calls: response.tool_calls },
|
|
1317
1323
|
// Include annotations if present (from web search or file parsing)
|
|
1318
|
-
...response.annotations && { annotations: response.annotations }
|
|
1324
|
+
...response.annotations?.length && { annotations: response.annotations }
|
|
1319
1325
|
},
|
|
1320
|
-
finish_reason: "stop"
|
|
1326
|
+
finish_reason: response.tool_calls?.length ? "tool_calls" : "stop"
|
|
1321
1327
|
}
|
|
1322
1328
|
],
|
|
1323
1329
|
usage: response.metadata?.usage || {
|
|
@@ -1359,7 +1365,24 @@ var ChatCompletions = class {
|
|
|
1359
1365
|
delta: {
|
|
1360
1366
|
content: data.chunk || data.content
|
|
1361
1367
|
},
|
|
1362
|
-
finish_reason:
|
|
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"
|
|
1363
1386
|
}
|
|
1364
1387
|
]
|
|
1365
1388
|
};
|
|
@@ -1496,31 +1519,58 @@ var Images = class {
|
|
|
1496
1519
|
};
|
|
1497
1520
|
|
|
1498
1521
|
// src/modules/functions.ts
|
|
1499
|
-
var Functions = class {
|
|
1500
|
-
constructor(http) {
|
|
1522
|
+
var Functions = class _Functions {
|
|
1523
|
+
constructor(http, functionsUrl) {
|
|
1501
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
|
+
}
|
|
1502
1542
|
}
|
|
1503
1543
|
/**
|
|
1504
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
|
+
*
|
|
1505
1549
|
* @param slug The function slug to invoke
|
|
1506
1550
|
* @param options Request options
|
|
1507
1551
|
*/
|
|
1508
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
|
+
}
|
|
1509
1568
|
try {
|
|
1510
|
-
const { method = "POST", body, headers = {} } = options;
|
|
1511
1569
|
const path = `/functions/${slug}`;
|
|
1512
|
-
const data = await this.http.request(
|
|
1513
|
-
method,
|
|
1514
|
-
path,
|
|
1515
|
-
{ body, headers }
|
|
1516
|
-
);
|
|
1570
|
+
const data = await this.http.request(method, path, { body, headers });
|
|
1517
1571
|
return { data, error: null };
|
|
1518
1572
|
} catch (error) {
|
|
1519
|
-
return {
|
|
1520
|
-
data: null,
|
|
1521
|
-
error
|
|
1522
|
-
// Pass through the full error object with all properties
|
|
1523
|
-
};
|
|
1573
|
+
return { data: null, error };
|
|
1524
1574
|
}
|
|
1525
1575
|
}
|
|
1526
1576
|
};
|
|
@@ -1818,7 +1868,7 @@ var InsForgeClient = class {
|
|
|
1818
1868
|
this.database = new Database(this.http, this.tokenManager);
|
|
1819
1869
|
this.storage = new Storage(this.http);
|
|
1820
1870
|
this.ai = new AI(this.http);
|
|
1821
|
-
this.functions = new Functions(this.http);
|
|
1871
|
+
this.functions = new Functions(this.http, config.functionsUrl);
|
|
1822
1872
|
this.realtime = new Realtime(this.http.baseUrl, this.tokenManager, config.anonKey);
|
|
1823
1873
|
this.emails = new Emails(this.http);
|
|
1824
1874
|
}
|