@yak-io/graphql 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 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/graphql
2
+
3
+ GraphQL adapter for the [yak](https://yak.io) chatbot. Exposes a GraphQL API to the
4
+ assistant as a single `graphql_<name>` tool: the model authors a query/mutation from the
5
+ SDL 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 GraphQL 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 { createGraphQLToolAdapter } from "@yak-io/graphql";
14
+ import { typeDefs } from "@/lib/schema";
15
+
16
+ const toolset = createYakToolset([
17
+ createGraphQLToolAdapter({
18
+ name: "shop",
19
+ schema: typeDefs,
20
+ // Run the model-authored request with your own client — Yak never owns the transport.
21
+ execute: (req) => myGraphQLClient.request(req.query, req.variables),
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/graphql) for full configuration.
@@ -0,0 +1,38 @@
1
+ import type { GraphQLRequest, ToolAdapter } from "@yak-io/javascript";
2
+ /** Config for {@link createGraphQLToolAdapter}. */
3
+ export type GraphQLToolAdapterConfig = {
4
+ /** Schema name — the tool is exposed to the LLM as `graphql_<name>`. */
5
+ name: string;
6
+ /** GraphQL schema in SDL format. Embedded in the tool description so the LLM can author queries. */
7
+ schema: string;
8
+ /**
9
+ * Execute the LLM-authored GraphQL request with YOUR client. Yak builds the tool and the
10
+ * request payload (query / variables / operationName) but never makes the call itself — your
11
+ * client owns transport, auth, retries, and error handling. Use whatever you already have
12
+ * (Apollo, urql, graphql-request, a signed `fetch`, …). Return the result the assistant should
13
+ * see (typically the `data` field); throw to surface an error to the model.
14
+ */
15
+ execute: (request: GraphQLRequest) => unknown | Promise<unknown>;
16
+ /** Stable id for diagnostics. Defaults to the tool name. */
17
+ id?: string;
18
+ };
19
+ /**
20
+ * Create a GraphQL {@link ToolAdapter}. Compose it into a {@link createYakToolset} so the
21
+ * generated `graphql_<name>` tool joins the single merged manifest + `onToolCall` funnel
22
+ * (and therefore surfaces through `onToolCallComplete` / `useYakToolEvent`).
23
+ *
24
+ * The model authors a query/mutation from the SDL you provide; the adapter hands the request
25
+ * to your `execute` callback, which runs it with whatever client you already use. Yak never
26
+ * constructs the HTTP call — your client owns the endpoint, auth, and transport.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const shop = createGraphQLToolAdapter({
31
+ * name: "shop",
32
+ * schema: typeDefs,
33
+ * execute: (req) => myGraphQLClient.request(req.query, req.variables),
34
+ * });
35
+ * ```
36
+ */
37
+ export declare function createGraphQLToolAdapter(config: GraphQLToolAdapterConfig): 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,EAAE,cAAc,EAAc,WAAW,EAAkB,MAAM,oBAAoB,CAAC;AAElG,mDAAmD;AACnD,MAAM,MAAM,wBAAwB,GAAG;IACrC,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,oGAAoG;IACpG,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;OAMG;IACH,OAAO,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACjE,4DAA4D;IAC5D,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AA6BF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,wBAAwB,GAAG,WAAW,CA2BtF"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Generic input schema for a GraphQL tool. The LLM authors the query + variables;
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 GRAPHQL_INPUT_SCHEMA = {
7
+ type: "object",
8
+ properties: {
9
+ query: {
10
+ type: "string",
11
+ description: "The GraphQL query or mutation string. Use $variableName syntax for all dynamic values.",
12
+ },
13
+ variables: {
14
+ type: "object",
15
+ description: "Variables object with values for all $variableName references in the query.",
16
+ additionalProperties: true,
17
+ },
18
+ operationName: {
19
+ type: "string",
20
+ description: "Optional operation name if the query contains multiple operations.",
21
+ },
22
+ },
23
+ required: ["query"],
24
+ additionalProperties: false,
25
+ };
26
+ /**
27
+ * Create a GraphQL {@link ToolAdapter}. Compose it into a {@link createYakToolset} so the
28
+ * generated `graphql_<name>` tool joins the single merged manifest + `onToolCall` funnel
29
+ * (and therefore surfaces through `onToolCallComplete` / `useYakToolEvent`).
30
+ *
31
+ * The model authors a query/mutation from the SDL you provide; the adapter hands the request
32
+ * to your `execute` callback, which runs it with whatever client you already use. Yak never
33
+ * constructs the HTTP call — your client owns the endpoint, auth, and transport.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const shop = createGraphQLToolAdapter({
38
+ * name: "shop",
39
+ * schema: typeDefs,
40
+ * execute: (req) => myGraphQLClient.request(req.query, req.variables),
41
+ * });
42
+ * ```
43
+ */
44
+ export function createGraphQLToolAdapter(config) {
45
+ const toolName = `graphql_${config.name}`;
46
+ const tool = {
47
+ name: toolName,
48
+ description: `Execute a GraphQL query or mutation against the ${config.name} API. ` +
49
+ "You MUST use GraphQL variables for all dynamic values — never hardcode values directly in " +
50
+ "the query string. Define variables with $variableName syntax and pass them in the variables " +
51
+ `object.\n\nSchema (SDL):\n\`\`\`graphql\n${config.schema}\n\`\`\``,
52
+ inputSchema: GRAPHQL_INPUT_SCHEMA,
53
+ };
54
+ return {
55
+ id: config.id ?? toolName,
56
+ getTools: () => [tool],
57
+ ownsTool: (name) => name === toolName,
58
+ execute: async (_name, args) => {
59
+ const request = (args ?? {});
60
+ // Hand a clean request to the caller's client — never forward the runtime-injected `_reason`.
61
+ return config.execute({
62
+ query: request.query,
63
+ variables: request.variables,
64
+ operationName: request.operationName,
65
+ });
66
+ },
67
+ };
68
+ }
@@ -0,0 +1,4 @@
1
+ export { createGraphQLToolAdapter } from "./adapters.js";
2
+ export type { GraphQLToolAdapterConfig } from "./adapters.js";
3
+ export type { GraphQLRequest, ToolAdapter, ToolDefinition } from "@yak-io/javascript";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,YAAY,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAG9D,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ // GraphQL tool adapter for the yak client toolset
2
+ export { createGraphQLToolAdapter } from "./adapters.js";
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@yak-io/graphql",
3
+ "version": "0.1.1",
4
+ "description": "GraphQL adapter for yak chatbot - exposes a GraphQL 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/graphql"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "keywords": [
17
+ "yak",
18
+ "chatbot",
19
+ "ai",
20
+ "graphql",
21
+ "tools"
22
+ ],
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "files": [
27
+ "README.md",
28
+ "dist",
29
+ "LICENSE"
30
+ ],
31
+ "sideEffects": false,
32
+ "main": "./dist/index.js",
33
+ "module": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "import": "./dist/index.js",
39
+ "default": "./dist/index.js"
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
43
+ "scripts": {
44
+ "build": "tsc",
45
+ "check-types": "tsc --noEmit",
46
+ "test": "vitest run",
47
+ "lint": "biome lint ./src --fix",
48
+ "format": "biome format ./src --write",
49
+ "prepare": "pnpm build"
50
+ },
51
+ "dependencies": {
52
+ "@yak-io/javascript": "workspace:*"
53
+ },
54
+ "devDependencies": {
55
+ "@repo/typescript-config": "workspace:*",
56
+ "@types/node": "^24.12.4",
57
+ "typescript": "^5.3.0"
58
+ },
59
+ "homepage": "https://docs.yak.io/docs/tool-adapters/graphql"
60
+ }