@insforge/sdk 1.1.5 → 1.1.6
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.d.mts
CHANGED
|
@@ -24,6 +24,13 @@ interface InsForgeConfig {
|
|
|
24
24
|
* This token will be used for all authenticated requests
|
|
25
25
|
*/
|
|
26
26
|
edgeFunctionToken?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Direct URL to Deno Subhosting functions (optional)
|
|
29
|
+
* When provided, SDK will try this URL first for function invocations.
|
|
30
|
+
* Falls back to proxy URL if subhosting returns 404.
|
|
31
|
+
* @example "https://{appKey}.functions.insforge.app"
|
|
32
|
+
*/
|
|
33
|
+
functionsUrl?: string;
|
|
27
34
|
/**
|
|
28
35
|
* Custom fetch implementation (useful for Node.js environments)
|
|
29
36
|
*/
|
|
@@ -655,9 +662,21 @@ interface FunctionInvokeOptions {
|
|
|
655
662
|
*/
|
|
656
663
|
declare class Functions {
|
|
657
664
|
private http;
|
|
658
|
-
|
|
665
|
+
private functionsUrl;
|
|
666
|
+
constructor(http: HttpClient, functionsUrl?: string);
|
|
667
|
+
/**
|
|
668
|
+
* Derive the subhosting URL from the base URL.
|
|
669
|
+
* Base URL pattern: https://{appKey}.{region}.insforge.app
|
|
670
|
+
* Functions URL: https://{appKey}.functions.insforge.app
|
|
671
|
+
* Only applies to .insforge.app domains.
|
|
672
|
+
*/
|
|
673
|
+
private static deriveSubhostingUrl;
|
|
659
674
|
/**
|
|
660
675
|
* Invokes an Edge Function
|
|
676
|
+
*
|
|
677
|
+
* If functionsUrl is configured, tries direct subhosting first.
|
|
678
|
+
* Falls back to proxy URL if subhosting returns 404.
|
|
679
|
+
*
|
|
661
680
|
* @param slug The function slug to invoke
|
|
662
681
|
* @param options Request options
|
|
663
682
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,13 @@ interface InsForgeConfig {
|
|
|
24
24
|
* This token will be used for all authenticated requests
|
|
25
25
|
*/
|
|
26
26
|
edgeFunctionToken?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Direct URL to Deno Subhosting functions (optional)
|
|
29
|
+
* When provided, SDK will try this URL first for function invocations.
|
|
30
|
+
* Falls back to proxy URL if subhosting returns 404.
|
|
31
|
+
* @example "https://{appKey}.functions.insforge.app"
|
|
32
|
+
*/
|
|
33
|
+
functionsUrl?: string;
|
|
27
34
|
/**
|
|
28
35
|
* Custom fetch implementation (useful for Node.js environments)
|
|
29
36
|
*/
|
|
@@ -655,9 +662,21 @@ interface FunctionInvokeOptions {
|
|
|
655
662
|
*/
|
|
656
663
|
declare class Functions {
|
|
657
664
|
private http;
|
|
658
|
-
|
|
665
|
+
private functionsUrl;
|
|
666
|
+
constructor(http: HttpClient, functionsUrl?: string);
|
|
667
|
+
/**
|
|
668
|
+
* Derive the subhosting URL from the base URL.
|
|
669
|
+
* Base URL pattern: https://{appKey}.{region}.insforge.app
|
|
670
|
+
* Functions URL: https://{appKey}.functions.insforge.app
|
|
671
|
+
* Only applies to .insforge.app domains.
|
|
672
|
+
*/
|
|
673
|
+
private static deriveSubhostingUrl;
|
|
659
674
|
/**
|
|
660
675
|
* Invokes an Edge Function
|
|
676
|
+
*
|
|
677
|
+
* If functionsUrl is configured, tries direct subhosting first.
|
|
678
|
+
* Falls back to proxy URL if subhosting returns 404.
|
|
679
|
+
*
|
|
661
680
|
* @param slug The function slug to invoke
|
|
662
681
|
* @param options Request options
|
|
663
682
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1318,7 +1318,11 @@ var ChatCompletions = class {
|
|
|
1318
1318
|
// New plugin options
|
|
1319
1319
|
webSearch: params.webSearch,
|
|
1320
1320
|
fileParser: params.fileParser,
|
|
1321
|
-
thinking: params.thinking
|
|
1321
|
+
thinking: params.thinking,
|
|
1322
|
+
// Tool calling options
|
|
1323
|
+
tools: params.tools,
|
|
1324
|
+
toolChoice: params.toolChoice,
|
|
1325
|
+
parallelToolCalls: params.parallelToolCalls
|
|
1322
1326
|
};
|
|
1323
1327
|
if (params.stream) {
|
|
1324
1328
|
const headers = this.http.getHeaders();
|
|
@@ -1353,10 +1357,12 @@ var ChatCompletions = class {
|
|
|
1353
1357
|
message: {
|
|
1354
1358
|
role: "assistant",
|
|
1355
1359
|
content,
|
|
1360
|
+
// Include tool_calls if present (from tool calling)
|
|
1361
|
+
...response.tool_calls?.length && { tool_calls: response.tool_calls },
|
|
1356
1362
|
// Include annotations if present (from web search or file parsing)
|
|
1357
|
-
...response.annotations && { annotations: response.annotations }
|
|
1363
|
+
...response.annotations?.length && { annotations: response.annotations }
|
|
1358
1364
|
},
|
|
1359
|
-
finish_reason: "stop"
|
|
1365
|
+
finish_reason: response.tool_calls?.length ? "tool_calls" : "stop"
|
|
1360
1366
|
}
|
|
1361
1367
|
],
|
|
1362
1368
|
usage: response.metadata?.usage || {
|
|
@@ -1398,7 +1404,24 @@ var ChatCompletions = class {
|
|
|
1398
1404
|
delta: {
|
|
1399
1405
|
content: data.chunk || data.content
|
|
1400
1406
|
},
|
|
1401
|
-
finish_reason:
|
|
1407
|
+
finish_reason: null
|
|
1408
|
+
}
|
|
1409
|
+
]
|
|
1410
|
+
};
|
|
1411
|
+
}
|
|
1412
|
+
if (data.tool_calls?.length) {
|
|
1413
|
+
yield {
|
|
1414
|
+
id: `chatcmpl-${Date.now()}`,
|
|
1415
|
+
object: "chat.completion.chunk",
|
|
1416
|
+
created: Math.floor(Date.now() / 1e3),
|
|
1417
|
+
model,
|
|
1418
|
+
choices: [
|
|
1419
|
+
{
|
|
1420
|
+
index: 0,
|
|
1421
|
+
delta: {
|
|
1422
|
+
tool_calls: data.tool_calls
|
|
1423
|
+
},
|
|
1424
|
+
finish_reason: "tool_calls"
|
|
1402
1425
|
}
|
|
1403
1426
|
]
|
|
1404
1427
|
};
|
|
@@ -1535,31 +1558,58 @@ var Images = class {
|
|
|
1535
1558
|
};
|
|
1536
1559
|
|
|
1537
1560
|
// src/modules/functions.ts
|
|
1538
|
-
var Functions = class {
|
|
1539
|
-
constructor(http) {
|
|
1561
|
+
var Functions = class _Functions {
|
|
1562
|
+
constructor(http, functionsUrl) {
|
|
1540
1563
|
this.http = http;
|
|
1564
|
+
this.functionsUrl = functionsUrl || _Functions.deriveSubhostingUrl(http.baseUrl);
|
|
1565
|
+
}
|
|
1566
|
+
/**
|
|
1567
|
+
* Derive the subhosting URL from the base URL.
|
|
1568
|
+
* Base URL pattern: https://{appKey}.{region}.insforge.app
|
|
1569
|
+
* Functions URL: https://{appKey}.functions.insforge.app
|
|
1570
|
+
* Only applies to .insforge.app domains.
|
|
1571
|
+
*/
|
|
1572
|
+
static deriveSubhostingUrl(baseUrl) {
|
|
1573
|
+
try {
|
|
1574
|
+
const { hostname } = new URL(baseUrl);
|
|
1575
|
+
if (!hostname.endsWith(".insforge.app")) return void 0;
|
|
1576
|
+
const appKey = hostname.split(".")[0];
|
|
1577
|
+
return `https://${appKey}.functions.insforge.app`;
|
|
1578
|
+
} catch {
|
|
1579
|
+
return void 0;
|
|
1580
|
+
}
|
|
1541
1581
|
}
|
|
1542
1582
|
/**
|
|
1543
1583
|
* Invokes an Edge Function
|
|
1584
|
+
*
|
|
1585
|
+
* If functionsUrl is configured, tries direct subhosting first.
|
|
1586
|
+
* Falls back to proxy URL if subhosting returns 404.
|
|
1587
|
+
*
|
|
1544
1588
|
* @param slug The function slug to invoke
|
|
1545
1589
|
* @param options Request options
|
|
1546
1590
|
*/
|
|
1547
1591
|
async invoke(slug, options = {}) {
|
|
1592
|
+
const { method = "POST", body, headers = {} } = options;
|
|
1593
|
+
if (this.functionsUrl) {
|
|
1594
|
+
try {
|
|
1595
|
+
const data = await this.http.request(method, `${this.functionsUrl}/${slug}`, {
|
|
1596
|
+
body,
|
|
1597
|
+
headers
|
|
1598
|
+
});
|
|
1599
|
+
return { data, error: null };
|
|
1600
|
+
} catch (error) {
|
|
1601
|
+
if (error?.statusCode === 404) {
|
|
1602
|
+
} else {
|
|
1603
|
+
return { data: null, error };
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1548
1607
|
try {
|
|
1549
|
-
const { method = "POST", body, headers = {} } = options;
|
|
1550
1608
|
const path = `/functions/${slug}`;
|
|
1551
|
-
const data = await this.http.request(
|
|
1552
|
-
method,
|
|
1553
|
-
path,
|
|
1554
|
-
{ body, headers }
|
|
1555
|
-
);
|
|
1609
|
+
const data = await this.http.request(method, path, { body, headers });
|
|
1556
1610
|
return { data, error: null };
|
|
1557
1611
|
} catch (error) {
|
|
1558
|
-
return {
|
|
1559
|
-
data: null,
|
|
1560
|
-
error
|
|
1561
|
-
// Pass through the full error object with all properties
|
|
1562
|
-
};
|
|
1612
|
+
return { data: null, error };
|
|
1563
1613
|
}
|
|
1564
1614
|
}
|
|
1565
1615
|
};
|
|
@@ -1857,7 +1907,7 @@ var InsForgeClient = class {
|
|
|
1857
1907
|
this.database = new Database(this.http, this.tokenManager);
|
|
1858
1908
|
this.storage = new Storage(this.http);
|
|
1859
1909
|
this.ai = new AI(this.http);
|
|
1860
|
-
this.functions = new Functions(this.http);
|
|
1910
|
+
this.functions = new Functions(this.http, config.functionsUrl);
|
|
1861
1911
|
this.realtime = new Realtime(this.http.baseUrl, this.tokenManager, config.anonKey);
|
|
1862
1912
|
this.emails = new Emails(this.http);
|
|
1863
1913
|
}
|