@inferencesh/sdk 0.20.1 → 0.22.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/CHANGELOG.md +104 -0
- package/dist/agent/actions.js +1 -4
- package/dist/agent/api.d.ts +37 -6
- package/dist/agent/api.js +37 -3
- package/dist/agent/reducer.js +23 -7
- package/dist/agent/types.d.ts +30 -5
- package/dist/api/agents.d.ts +9 -3
- package/dist/api/agents.js +87 -65
- package/dist/api/api-keys.d.ts +2 -5
- package/dist/api/apps.d.ts +9 -2
- package/dist/api/apps.js +9 -1
- package/dist/api/chats.d.ts +13 -3
- package/dist/api/chats.js +13 -2
- package/dist/api/engines.d.ts +4 -2
- package/dist/api/engines.js +3 -2
- package/dist/api/flow-runs.d.ts +7 -2
- package/dist/api/flow-runs.js +7 -2
- package/dist/api/flows.d.ts +13 -2
- package/dist/api/flows.js +15 -1
- package/dist/api/knowledge.d.ts +7 -4
- package/dist/api/knowledge.js +6 -4
- package/dist/api/mcp-servers.d.ts +2 -1
- package/dist/api/projects.d.ts +5 -3
- package/dist/api/projects.js +3 -2
- package/dist/api/secrets.d.ts +2 -2
- package/dist/api/tasks.js +39 -60
- package/dist/api/teams.d.ts +4 -2
- package/dist/api/teams.js +3 -2
- package/dist/api/write-bodies.d.ts +110 -0
- package/dist/api/write-bodies.js +1 -0
- package/dist/http/client.d.ts +68 -7
- package/dist/http/client.js +138 -97
- package/dist/http/index.d.ts +2 -2
- package/dist/http/loopback.d.ts +8 -0
- package/dist/http/loopback.js +18 -0
- package/dist/http/stream-until-terminal.d.ts +55 -0
- package/dist/http/stream-until-terminal.js +88 -0
- package/dist/http/stream.d.ts +1 -0
- package/dist/http/stream.js +7 -3
- package/dist/http/streamable.d.ts +25 -5
- package/dist/http/streamable.js +28 -40
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -0
- package/dist/proxy/endpoints.json +156 -0
- package/dist/proxy/express.d.ts +5 -6
- package/dist/proxy/express.js +18 -2
- package/dist/proxy/hono.d.ts +5 -3
- package/dist/proxy/hono.js +4 -3
- package/dist/proxy/index.d.ts +165 -6
- package/dist/proxy/index.js +409 -25
- package/dist/proxy/nextjs.d.ts +29 -17
- package/dist/proxy/nextjs.js +72 -62
- package/dist/proxy/remix.d.ts +5 -3
- package/dist/proxy/remix.js +4 -3
- package/dist/proxy/svelte.d.ts +5 -4
- package/dist/proxy/svelte.js +4 -4
- package/dist/types.d.ts +591 -271
- package/dist/types.js +117 -252
- package/dist/version.d.ts +1 -0
- package/dist/version.js +7 -0
- package/package.json +2 -1
package/dist/proxy/nextjs.js
CHANGED
|
@@ -5,13 +5,14 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @example App Router (app/api/inference/proxy/route.ts)
|
|
7
7
|
* ```typescript
|
|
8
|
-
* import {
|
|
9
|
-
* export const { GET, POST
|
|
8
|
+
* import { createHandler } from "@inferencesh/sdk/proxy/nextjs";
|
|
9
|
+
* export const { GET, POST } = createHandler({ allowedEndpoints: ["my-team/*"] });
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
12
|
* @example Page Router (pages/api/inference/proxy.ts)
|
|
13
13
|
* ```typescript
|
|
14
|
-
*
|
|
14
|
+
* import { createPageHandler } from "@inferencesh/sdk/proxy/nextjs";
|
|
15
|
+
* export default createPageHandler({ allowedEndpoints: ["my-team/*"] });
|
|
15
16
|
* ```
|
|
16
17
|
*/
|
|
17
18
|
import { NextResponse } from "next/server";
|
|
@@ -33,78 +34,89 @@ export const PROXY_ROUTE = PROXY_PATH;
|
|
|
33
34
|
* @example
|
|
34
35
|
* ```typescript
|
|
35
36
|
* // pages/api/inference/proxy.ts
|
|
36
|
-
*
|
|
37
|
+
* import { createPageHandler } from "@inferencesh/sdk/proxy/nextjs";
|
|
38
|
+
* export default createPageHandler({ allowedEndpoints: ["my-team/*"] });
|
|
37
39
|
* ```
|
|
38
40
|
*/
|
|
39
|
-
export
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
41
|
+
export function createPageHandler(options) {
|
|
42
|
+
return async (request, response) => {
|
|
43
|
+
return processProxyRequest({
|
|
44
|
+
framework: "nextjs-pages",
|
|
45
|
+
request,
|
|
46
|
+
method: request.method || "POST",
|
|
47
|
+
body: async () => JSON.stringify(request.body),
|
|
48
|
+
headers: () => request.headers,
|
|
49
|
+
header: (name) => request.headers[name],
|
|
50
|
+
query: (name) => {
|
|
51
|
+
const value = request.query[name];
|
|
52
|
+
return Array.isArray(value) ? value[0] : value;
|
|
53
|
+
},
|
|
54
|
+
setHeader: (name, value) => response.setHeader(name, value),
|
|
55
|
+
error: (status, data) => response.status(status).json(data),
|
|
56
|
+
respond: async (res) => {
|
|
57
|
+
const contentType = res.headers.get("content-type") || "";
|
|
58
|
+
if (contentType.includes("application/json")) {
|
|
59
|
+
return response.status(res.status).json(await res.json());
|
|
60
|
+
}
|
|
61
|
+
return response.status(res.status).send(await res.text());
|
|
62
|
+
},
|
|
63
|
+
}, options);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** Page Router handler with the default options. */
|
|
67
|
+
export const pageHandler = createPageHandler();
|
|
61
68
|
// ============================================================================
|
|
62
69
|
// App Router Handler
|
|
63
70
|
// ============================================================================
|
|
64
71
|
/**
|
|
65
|
-
* Create
|
|
72
|
+
* Create App Router route handlers for the Inference.sh proxy.
|
|
66
73
|
* Supports full streaming passthrough for SSE responses.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* // app/api/inference/proxy/route.ts
|
|
78
|
+
* import { createHandler } from "@inferencesh/sdk/proxy/nextjs";
|
|
79
|
+
* export const { GET, POST } = createHandler({ allowedEndpoints: ["my-team/*"] });
|
|
80
|
+
* ```
|
|
67
81
|
*/
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
export function createHandler(options) {
|
|
83
|
+
const appHandler = async (request) => {
|
|
84
|
+
const responseHeaders = new Headers();
|
|
85
|
+
const url = new URL(request.url);
|
|
86
|
+
return processProxyRequest({
|
|
87
|
+
framework: "nextjs-app",
|
|
88
|
+
request,
|
|
89
|
+
method: request.method,
|
|
90
|
+
body: () => request.text(),
|
|
91
|
+
headers: () => headersToRecord(request.headers),
|
|
92
|
+
header: (name) => request.headers.get(name),
|
|
93
|
+
query: (name) => url.searchParams.get(name) ?? undefined,
|
|
94
|
+
setHeader: (name, value) => responseHeaders.set(name, value),
|
|
95
|
+
error: (status, data) => NextResponse.json(data, { status, headers: responseHeaders }),
|
|
96
|
+
respond: async (response) => {
|
|
97
|
+
// Return new Response with cleaned headers (content-encoding stripped)
|
|
98
|
+
return new Response(response.body, {
|
|
99
|
+
status: response.status,
|
|
100
|
+
statusText: response.statusText,
|
|
101
|
+
headers: responseHeaders,
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
}, options);
|
|
105
|
+
};
|
|
106
|
+
// GET and POST only: PROXY_ENDPOINTS forwards no other method.
|
|
107
|
+
return { GET: appHandler, POST: appHandler };
|
|
89
108
|
}
|
|
90
|
-
// ============================================================================
|
|
91
|
-
// Route Exports
|
|
92
|
-
// ============================================================================
|
|
93
109
|
/**
|
|
94
|
-
* App Router route handlers.
|
|
110
|
+
* App Router route handlers with the default options.
|
|
95
111
|
*
|
|
96
112
|
* @example
|
|
97
113
|
* ```typescript
|
|
98
114
|
* // app/api/inference/proxy/route.ts
|
|
99
115
|
* import { handlers } from "@inferencesh/sdk/proxy/nextjs";
|
|
100
|
-
* export const { GET, POST
|
|
116
|
+
* export const { GET, POST } = handlers;
|
|
101
117
|
* ```
|
|
102
118
|
*/
|
|
103
|
-
export const handlers =
|
|
104
|
-
GET: appHandler,
|
|
105
|
-
POST: appHandler,
|
|
106
|
-
PUT: appHandler,
|
|
107
|
-
};
|
|
119
|
+
export const handlers = createHandler();
|
|
108
120
|
// ============================================================================
|
|
109
121
|
// Legacy Exports (backwards compatibility)
|
|
110
122
|
// ============================================================================
|
|
@@ -112,8 +124,6 @@ export const handlers = {
|
|
|
112
124
|
export const handler = pageHandler;
|
|
113
125
|
/** @deprecated Use handlers */
|
|
114
126
|
export const route = {
|
|
115
|
-
handler:
|
|
116
|
-
|
|
117
|
-
POST: appHandler,
|
|
118
|
-
PUT: appHandler,
|
|
127
|
+
handler: handlers.GET,
|
|
128
|
+
...handlers,
|
|
119
129
|
};
|
package/dist/proxy/remix.d.ts
CHANGED
|
@@ -8,13 +8,15 @@
|
|
|
8
8
|
* // app/routes/api.inference.proxy.ts
|
|
9
9
|
* import { createHandler } from "@inferencesh/sdk/proxy/remix";
|
|
10
10
|
*
|
|
11
|
-
* const handler = createHandler();
|
|
11
|
+
* const handler = createHandler({ allowedEndpoints: ["my-team/*"] });
|
|
12
12
|
*
|
|
13
13
|
* export const loader = handler;
|
|
14
14
|
* export const action = handler;
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
import { type ProxyOptions } from "./index";
|
|
18
|
+
/** Proxy options; `isAuthenticated` receives the Request. */
|
|
19
|
+
export interface RemixProxyOptions extends ProxyOptions<Request> {
|
|
18
20
|
/** Custom function to resolve the API key */
|
|
19
21
|
resolveApiKey?: () => Promise<string | undefined>;
|
|
20
22
|
}
|
|
@@ -25,7 +27,7 @@ type RemixHandler = (args: {
|
|
|
25
27
|
* Creates a Remix request handler for the Inference.sh proxy.
|
|
26
28
|
* Use this as both a loader and action in your Remix route.
|
|
27
29
|
*/
|
|
28
|
-
export declare function createHandler({ resolveApiKey, }?: RemixProxyOptions): RemixHandler;
|
|
30
|
+
export declare function createHandler({ resolveApiKey, ...options }?: RemixProxyOptions): RemixHandler;
|
|
29
31
|
/** @deprecated Use createHandler */
|
|
30
32
|
export declare const createRequestHandler: typeof createHandler;
|
|
31
33
|
export {};
|
package/dist/proxy/remix.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* // app/routes/api.inference.proxy.ts
|
|
9
9
|
* import { createHandler } from "@inferencesh/sdk/proxy/remix";
|
|
10
10
|
*
|
|
11
|
-
* const handler = createHandler();
|
|
11
|
+
* const handler = createHandler({ allowedEndpoints: ["my-team/*"] });
|
|
12
12
|
*
|
|
13
13
|
* export const loader = handler;
|
|
14
14
|
* export const action = handler;
|
|
@@ -19,12 +19,13 @@ import { processProxyRequest, getEnvApiKey, passthrough, headersToRecord, } from
|
|
|
19
19
|
* Creates a Remix request handler for the Inference.sh proxy.
|
|
20
20
|
* Use this as both a loader and action in your Remix route.
|
|
21
21
|
*/
|
|
22
|
-
export function createHandler({ resolveApiKey = getEnvApiKey, } = {}) {
|
|
22
|
+
export function createHandler({ resolveApiKey = getEnvApiKey, ...options } = {}) {
|
|
23
23
|
return async ({ request }) => {
|
|
24
24
|
const responseHeaders = new Headers();
|
|
25
25
|
const url = new URL(request.url);
|
|
26
26
|
return processProxyRequest({
|
|
27
27
|
framework: "remix",
|
|
28
|
+
request,
|
|
28
29
|
method: request.method,
|
|
29
30
|
body: () => request.text(),
|
|
30
31
|
headers: () => headersToRecord(request.headers),
|
|
@@ -40,7 +41,7 @@ export function createHandler({ resolveApiKey = getEnvApiKey, } = {}) {
|
|
|
40
41
|
}),
|
|
41
42
|
respond: passthrough,
|
|
42
43
|
apiKey: resolveApiKey,
|
|
43
|
-
});
|
|
44
|
+
}, options);
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
47
|
/** @deprecated Use createHandler */
|
package/dist/proxy/svelte.d.ts
CHANGED
|
@@ -8,15 +8,16 @@
|
|
|
8
8
|
* // src/routes/api/inference/proxy/+server.ts
|
|
9
9
|
* import { createHandler } from "@inferencesh/sdk/proxy/svelte";
|
|
10
10
|
*
|
|
11
|
-
* const handler = createHandler();
|
|
11
|
+
* const handler = createHandler({ allowedEndpoints: ["my-team/*"] });
|
|
12
12
|
*
|
|
13
13
|
* export const GET = handler;
|
|
14
14
|
* export const POST = handler;
|
|
15
|
-
* export const PUT = handler;
|
|
16
15
|
* ```
|
|
17
16
|
*/
|
|
18
17
|
import type { RequestEvent } from "@sveltejs/kit";
|
|
19
|
-
|
|
18
|
+
import { type ProxyOptions } from "./index";
|
|
19
|
+
/** Proxy options; `isAuthenticated` receives the RequestEvent. */
|
|
20
|
+
export interface SvelteProxyOptions extends ProxyOptions<RequestEvent> {
|
|
20
21
|
/** Custom function to resolve the API key */
|
|
21
22
|
resolveApiKey?: () => Promise<string | undefined>;
|
|
22
23
|
}
|
|
@@ -27,7 +28,7 @@ type SvelteRequestHandler = (event: RequestEvent) => Promise<Response>;
|
|
|
27
28
|
* @param options - Proxy options
|
|
28
29
|
* @returns A SvelteKit request handler function
|
|
29
30
|
*/
|
|
30
|
-
export declare function createHandler({ resolveApiKey, }?: SvelteProxyOptions): SvelteRequestHandler;
|
|
31
|
+
export declare function createHandler({ resolveApiKey, ...options }?: SvelteProxyOptions): SvelteRequestHandler;
|
|
31
32
|
/** @deprecated Use createHandler */
|
|
32
33
|
export declare const createRequestHandler: typeof createHandler;
|
|
33
34
|
export {};
|
package/dist/proxy/svelte.js
CHANGED
|
@@ -8,11 +8,10 @@
|
|
|
8
8
|
* // src/routes/api/inference/proxy/+server.ts
|
|
9
9
|
* import { createHandler } from "@inferencesh/sdk/proxy/svelte";
|
|
10
10
|
*
|
|
11
|
-
* const handler = createHandler();
|
|
11
|
+
* const handler = createHandler({ allowedEndpoints: ["my-team/*"] });
|
|
12
12
|
*
|
|
13
13
|
* export const GET = handler;
|
|
14
14
|
* export const POST = handler;
|
|
15
|
-
* export const PUT = handler;
|
|
16
15
|
* ```
|
|
17
16
|
*/
|
|
18
17
|
import { processProxyRequest, getEnvApiKey, passthrough, headersToRecord, } from "./index";
|
|
@@ -22,13 +21,14 @@ import { processProxyRequest, getEnvApiKey, passthrough, headersToRecord, } from
|
|
|
22
21
|
* @param options - Proxy options
|
|
23
22
|
* @returns A SvelteKit request handler function
|
|
24
23
|
*/
|
|
25
|
-
export function createHandler({ resolveApiKey = getEnvApiKey, } = {}) {
|
|
24
|
+
export function createHandler({ resolveApiKey = getEnvApiKey, ...options } = {}) {
|
|
26
25
|
return async (event) => {
|
|
27
26
|
const request = event.request;
|
|
28
27
|
const url = new URL(request.url);
|
|
29
28
|
const responseHeaders = new Headers();
|
|
30
29
|
return processProxyRequest({
|
|
31
30
|
framework: "sveltekit",
|
|
31
|
+
request: event,
|
|
32
32
|
method: request.method,
|
|
33
33
|
body: () => request.text(),
|
|
34
34
|
headers: () => headersToRecord(request.headers),
|
|
@@ -44,7 +44,7 @@ export function createHandler({ resolveApiKey = getEnvApiKey, } = {}) {
|
|
|
44
44
|
}),
|
|
45
45
|
respond: passthrough,
|
|
46
46
|
apiKey: resolveApiKey,
|
|
47
|
-
});
|
|
47
|
+
}, options);
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
/** @deprecated Use createHandler */
|