@yak-io/rest 0.1.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 +36 -0
- package/README.md +32 -0
- package/dist/adapters.d.ts +38 -0
- package/dist/adapters.d.ts.map +1 -0
- package/dist/adapters.js +68 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Yak Proprietary License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yak. All rights reserved.
|
|
4
|
+
|
|
5
|
+
This software and associated documentation files (the "Software") are the
|
|
6
|
+
proprietary property of Yak and are protected by copyright law.
|
|
7
|
+
|
|
8
|
+
GRANT OF LICENSE:
|
|
9
|
+
Subject to the terms of this license and your valid subscription or agreement
|
|
10
|
+
with Yak, you are granted a limited, non-exclusive, non-transferable license
|
|
11
|
+
to use the Software solely for integrating the Yak chatbot widget into your
|
|
12
|
+
applications as intended and documented.
|
|
13
|
+
|
|
14
|
+
RESTRICTIONS:
|
|
15
|
+
You may NOT:
|
|
16
|
+
- Modify, adapt, alter, translate, or create derivative works of the Software
|
|
17
|
+
- Reverse engineer, disassemble, decompile, or otherwise attempt to derive
|
|
18
|
+
the source code of the Software
|
|
19
|
+
- Redistribute, sublicense, lease, rent, or lend the Software to third parties
|
|
20
|
+
- Remove or alter any proprietary notices, labels, or marks on the Software
|
|
21
|
+
- Use the Software for any purpose other than as expressly permitted herein
|
|
22
|
+
|
|
23
|
+
NO WARRANTY:
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL YAK
|
|
27
|
+
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
28
|
+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
29
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
30
|
+
|
|
31
|
+
TERMINATION:
|
|
32
|
+
This license is effective until terminated. Your rights under this license
|
|
33
|
+
will terminate automatically without notice if you fail to comply with any
|
|
34
|
+
of its terms.
|
|
35
|
+
|
|
36
|
+
For licensing inquiries, contact: support@yak.io
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @yak-io/rest
|
|
2
|
+
|
|
3
|
+
REST / OpenAPI adapter for the [yak](https://yak.io) chatbot. Exposes a REST API to the
|
|
4
|
+
assistant as a single `rest_<name>` tool: the model authors a request (method, path, query,
|
|
5
|
+
body) from the OpenAPI spec you provide, and the adapter hands it to your client to execute — Yak never owns the transport.
|
|
6
|
+
|
|
7
|
+
Adapters compose into a single tool manifest + `onToolCall` funnel via `createYakToolset`,
|
|
8
|
+
so REST calls flow through the same path as every other tool — including
|
|
9
|
+
`onToolCallComplete` / `useYakToolEvent`.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { createYakToolset } from "@yak-io/javascript";
|
|
13
|
+
import { createRESTToolAdapter } from "@yak-io/rest";
|
|
14
|
+
import { openapiSpec } from "@/lib/openapi";
|
|
15
|
+
|
|
16
|
+
const toolset = createYakToolset([
|
|
17
|
+
createRESTToolAdapter({
|
|
18
|
+
name: "billing",
|
|
19
|
+
spec: openapiSpec,
|
|
20
|
+
// Run the model-authored request with your own client — Yak never owns the transport.
|
|
21
|
+
execute: (req) => myApiClient(req.method, req.path, { query: req.query, body: req.body }),
|
|
22
|
+
}),
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
<YakProvider
|
|
26
|
+
appId={APP_ID}
|
|
27
|
+
getConfig={async () => ({ routes, ...(await toolset.getConfig()) })}
|
|
28
|
+
onToolCall={toolset.onToolCall}
|
|
29
|
+
/>;
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
See the [docs](https://docs.yak.io/docs/tool-adapters/rest) for full configuration.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { RESTRequest, ToolAdapter } from "@yak-io/javascript";
|
|
2
|
+
/** Config for {@link createRESTToolAdapter}. */
|
|
3
|
+
export type RESTToolAdapterConfig = {
|
|
4
|
+
/** Spec name — the tool is exposed to the LLM as `rest_<name>`. */
|
|
5
|
+
name: string;
|
|
6
|
+
/** OpenAPI spec (object or string). Embedded in the tool description so the LLM can author requests. */
|
|
7
|
+
spec: Record<string, unknown> | string;
|
|
8
|
+
/**
|
|
9
|
+
* Execute the LLM-authored REST request with YOUR client. Yak builds the tool and the request
|
|
10
|
+
* shape (method / path / query / body) but never makes the call itself — your client owns the
|
|
11
|
+
* base URL, auth, transport, and error handling. Use whatever you already have (a configured
|
|
12
|
+
* `fetch` wrapper, axios, your app's API client, …). Return the result the assistant should
|
|
13
|
+
* see; throw to surface an error to the model.
|
|
14
|
+
*/
|
|
15
|
+
execute: (request: RESTRequest) => unknown | Promise<unknown>;
|
|
16
|
+
/** Stable id for diagnostics. Defaults to the tool name. */
|
|
17
|
+
id?: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Create a REST {@link ToolAdapter}. Compose it into a {@link createYakToolset} so the generated
|
|
21
|
+
* `rest_<name>` tool joins the single merged manifest + `onToolCall` funnel (and therefore
|
|
22
|
+
* surfaces through `onToolCallComplete` / `useYakToolEvent`).
|
|
23
|
+
*
|
|
24
|
+
* The model authors a request from the OpenAPI spec you provide; the adapter hands it to your
|
|
25
|
+
* `execute` callback, which runs it with whatever client you already use. Yak never constructs
|
|
26
|
+
* the HTTP call — your client owns the base URL, auth, and transport.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const billing = createRESTToolAdapter({
|
|
31
|
+
* name: "billing",
|
|
32
|
+
* spec: openapiSpec,
|
|
33
|
+
* execute: (req) => myApiClient(req.method, req.path, { query: req.query, body: req.body }),
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function createRESTToolAdapter(config: RESTToolAdapterConfig): ToolAdapter;
|
|
38
|
+
//# sourceMappingURL=adapters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../src/adapters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,WAAW,EAAE,WAAW,EAAkB,MAAM,oBAAoB,CAAC;AAE/F,gDAAgD;AAChD,MAAM,MAAM,qBAAqB,GAAG;IAClC,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,wGAAwG;IACxG,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;IACvC;;;;;;OAMG;IACH,OAAO,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9D,4DAA4D;IAC5D,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AA2BF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,WAAW,CA6BhF"}
|
package/dist/adapters.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic input schema for a REST tool. The LLM authors method/path/query/body;
|
|
3
|
+
* the adapter hands them to your `execute` client. Do NOT inject `_reason` here — the
|
|
4
|
+
* chat-ui / voice runtimes inject it when registering the tool with the model.
|
|
5
|
+
*/
|
|
6
|
+
const REST_INPUT_SCHEMA = {
|
|
7
|
+
type: "object",
|
|
8
|
+
properties: {
|
|
9
|
+
method: {
|
|
10
|
+
type: "string",
|
|
11
|
+
enum: ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
|
12
|
+
description: "HTTP method for the request.",
|
|
13
|
+
},
|
|
14
|
+
path: { type: "string", description: "API path (e.g., '/users/123')." },
|
|
15
|
+
query: {
|
|
16
|
+
type: "object",
|
|
17
|
+
description: "Query parameters as key-value pairs.",
|
|
18
|
+
additionalProperties: { type: "string" },
|
|
19
|
+
},
|
|
20
|
+
body: { description: "Request body for POST/PUT/PATCH requests." },
|
|
21
|
+
},
|
|
22
|
+
required: ["method", "path"],
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Create a REST {@link ToolAdapter}. Compose it into a {@link createYakToolset} so the generated
|
|
27
|
+
* `rest_<name>` tool joins the single merged manifest + `onToolCall` funnel (and therefore
|
|
28
|
+
* surfaces through `onToolCallComplete` / `useYakToolEvent`).
|
|
29
|
+
*
|
|
30
|
+
* The model authors a request from the OpenAPI spec you provide; the adapter hands it to your
|
|
31
|
+
* `execute` callback, which runs it with whatever client you already use. Yak never constructs
|
|
32
|
+
* the HTTP call — your client owns the base URL, auth, and transport.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const billing = createRESTToolAdapter({
|
|
37
|
+
* name: "billing",
|
|
38
|
+
* spec: openapiSpec,
|
|
39
|
+
* execute: (req) => myApiClient(req.method, req.path, { query: req.query, body: req.body }),
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function createRESTToolAdapter(config) {
|
|
44
|
+
const toolName = `rest_${config.name}`;
|
|
45
|
+
const specStr = typeof config.spec === "string" ? config.spec : JSON.stringify(config.spec, null, 2);
|
|
46
|
+
const tool = {
|
|
47
|
+
name: toolName,
|
|
48
|
+
description: `Make a REST API call to the ${config.name} API. Based on the OpenAPI spec below, ` +
|
|
49
|
+
"generate the appropriate request with method, path, query params, and body." +
|
|
50
|
+
`\n\nOpenAPI spec:\n\`\`\`json\n${specStr}\n\`\`\``,
|
|
51
|
+
inputSchema: REST_INPUT_SCHEMA,
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
id: config.id ?? toolName,
|
|
55
|
+
getTools: () => [tool],
|
|
56
|
+
ownsTool: (name) => name === toolName,
|
|
57
|
+
execute: async (_name, args) => {
|
|
58
|
+
const request = (args ?? {});
|
|
59
|
+
// Hand a clean request to the caller's client — never forward the runtime-injected `_reason`.
|
|
60
|
+
return config.execute({
|
|
61
|
+
method: request.method,
|
|
62
|
+
path: request.path,
|
|
63
|
+
query: request.query,
|
|
64
|
+
body: request.body,
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAG3D,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yak-io/rest",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "REST/OpenAPI adapter for yak chatbot - exposes a REST API as a chatbot tool",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
7
|
+
"author": "Yak <support@yak.io>",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/388-labs/yak.git",
|
|
11
|
+
"directory": "packages/rest"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"yak",
|
|
18
|
+
"chatbot",
|
|
19
|
+
"ai",
|
|
20
|
+
"rest",
|
|
21
|
+
"openapi",
|
|
22
|
+
"tools"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"README.md",
|
|
29
|
+
"dist",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"module": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"import": "./dist/index.js",
|
|
40
|
+
"default": "./dist/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./package.json": "./package.json"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc",
|
|
46
|
+
"check-types": "tsc --noEmit",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"lint": "biome lint ./src --fix",
|
|
49
|
+
"format": "biome format ./src --write",
|
|
50
|
+
"prepare": "pnpm build"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@yak-io/javascript": "workspace:*"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@repo/typescript-config": "workspace:*",
|
|
57
|
+
"@types/node": "^24.12.4",
|
|
58
|
+
"typescript": "^5.3.0"
|
|
59
|
+
},
|
|
60
|
+
"homepage": "https://docs.yak.io/docs/tool-adapters/rest"
|
|
61
|
+
}
|