@yak-io/prismic 0.1.2 → 0.2.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/README.md +25 -19
- package/dist/graphql-adapter.d.ts +13 -0
- package/dist/graphql-adapter.d.ts.map +1 -0
- package/dist/{schema-source.js → graphql-adapter.js} +47 -9
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types.d.ts +15 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -3
- package/dist/schema-source.d.ts +0 -4
- package/dist/schema-source.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @yak-io/prismic
|
|
2
2
|
|
|
3
|
-
> 📚 **Full documentation:** https://docs.yak.io/docs/
|
|
3
|
+
> 📚 **Full documentation:** https://docs.yak.io/docs/sdks/prismic
|
|
4
4
|
>
|
|
5
5
|
> 🤖 **For LLMs / AI agents:** https://docs.yak.io/llms.txt
|
|
6
6
|
|
|
7
|
-
Prismic CMS adapter for [Yak](https://docs.yak.io). It turns Prismic documents into Yak **routes** (so the assistant knows your pages), **tools** (so it can fetch content), and a **
|
|
7
|
+
Prismic CMS adapter for [Yak](https://docs.yak.io). It turns Prismic documents into Yak **routes** (so the assistant knows your pages), **tools** (so it can fetch content), and a **GraphQL adapter** (so it can query your content model). Plugs into `@yak-io/javascript`'s `createYakHandler` or `@yak-io/nextjs`'s `createNextYakHandler`.
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
pnpm add @yak-io/prismic @yak-io/javascript @prismicio/client
|
|
@@ -18,7 +18,7 @@ pnpm add @yak-io/prismic @yak-io/javascript @prismicio/client
|
|
|
18
18
|
| --- | --- | --- |
|
|
19
19
|
| `createPrismicRouteAdapter(config)` | `RouteSource` | Routes from Prismic documents — when pages live in Prismic. |
|
|
20
20
|
| `createPrismicToolAdapter(config)` | `ToolSource` | Exposes `prismic.getByUID`, `prismic.getAllByType`, `prismic.search` as tools. |
|
|
21
|
-
| `
|
|
21
|
+
| `createPrismicGraphQLToolAdapter(config)` | `Promise<ToolAdapter>` | Introspects your repo's GraphQL schema and returns a browser-executed `graphql_prismic` tool. |
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
@@ -61,17 +61,19 @@ export const { GET, POST } = createNextYakHandler({
|
|
|
61
61
|
|
|
62
62
|
Both return standard `RouteSource` / `ToolSource` shapes, so you can compose them with filesystem routes, tRPC tools, or any other source by passing arrays.
|
|
63
63
|
|
|
64
|
-
### 3. Optionally expose the content model (client `getConfig`)
|
|
64
|
+
### 3. Optionally expose the content model (client `getConfig` + `onToolCall`)
|
|
65
65
|
|
|
66
66
|
```ts
|
|
67
|
-
import {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
import { createYakServerAdapter, createYakToolset } from "@yak-io/react";
|
|
68
|
+
import { createPrismicGraphQLToolAdapter } from "@yak-io/prismic";
|
|
69
|
+
|
|
70
|
+
const toolset = createYakToolset([
|
|
71
|
+
createYakServerAdapter({ endpoint: "/api/yak" }),
|
|
72
|
+
await createPrismicGraphQLToolAdapter({ client }),
|
|
73
|
+
]);
|
|
74
|
+
|
|
75
|
+
const getConfig = async () => ({ routes, ...(await toolset.getConfig()) });
|
|
76
|
+
const onToolCall = toolset.onToolCall;
|
|
75
77
|
```
|
|
76
78
|
|
|
77
79
|
## API reference
|
|
@@ -95,14 +97,18 @@ const getConfig = async () => {
|
|
|
95
97
|
| `fields` | `Record<string, string[]>` | — | Per-type field allowlist returned to the assistant. |
|
|
96
98
|
| `id` | `string` | `"prismic"` | Source id. |
|
|
97
99
|
|
|
98
|
-
### `
|
|
100
|
+
### `createPrismicGraphQLToolAdapter(config)`
|
|
101
|
+
|
|
102
|
+
Introspects the repo's `/graphql` endpoint once and returns a browser-executed `ToolAdapter`
|
|
103
|
+
exposing a `graphql_<name>` tool. Compose it with `createYakToolset`.
|
|
99
104
|
|
|
100
105
|
| Option | Type | Default | Description |
|
|
101
106
|
| --- | --- | --- | --- |
|
|
102
107
|
| `client` | `Client` | — | Prismic client (required). |
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
105
|
-
| `
|
|
108
|
+
| `name` | `string` | `"prismic"` | Tool name suffix — exposed as `graphql_<name>`. |
|
|
109
|
+
| `endpoint` | `string` | derived `/graphql` URL | Override the GraphQL endpoint. |
|
|
110
|
+
| `headers` | `HeadersInit \| (() => HeadersInit \| Promise<HeadersInit>)` | — | Execution headers (e.g. `Prismic-ref`). |
|
|
111
|
+
| `fetchFn` | `typeof fetch` | global `fetch` | Custom fetch for the one-time introspection. |
|
|
106
112
|
|
|
107
113
|
## Security
|
|
108
114
|
|
|
@@ -111,14 +117,14 @@ const getConfig = async () => {
|
|
|
111
117
|
|
|
112
118
|
## Types
|
|
113
119
|
|
|
114
|
-
Route
|
|
120
|
+
Route, tool, and adapter types are re-exported for convenience:
|
|
115
121
|
|
|
116
122
|
```ts
|
|
117
|
-
import type { RouteSource, ToolSource,
|
|
123
|
+
import type { RouteSource, ToolSource, ToolAdapter } from "@yak-io/prismic";
|
|
118
124
|
import type {
|
|
119
125
|
PrismicRouteAdapterConfig,
|
|
120
126
|
PrismicToolAdapterConfig,
|
|
121
|
-
|
|
127
|
+
PrismicGraphQLToolAdapterConfig,
|
|
122
128
|
} from "@yak-io/prismic";
|
|
123
129
|
```
|
|
124
130
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ToolAdapter } from "@yak-io/javascript";
|
|
2
|
+
import type { PrismicGraphQLToolAdapterConfig } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Introspect a Prismic repository's GraphQL schema and return a browser-executed
|
|
5
|
+
* GraphQL {@link ToolAdapter} (built on `@yak-io/graphql`). Compose it into a
|
|
6
|
+
* {@link createYakToolset}; the LLM authors queries from the introspected SDL and
|
|
7
|
+
* the adapter executes them against the repo's GraphQL endpoint.
|
|
8
|
+
*
|
|
9
|
+
* Prismic's GraphQL endpoint requires a `Prismic-ref` header at execution time —
|
|
10
|
+
* supply it via `headers` (it may be async to fetch the master ref per call).
|
|
11
|
+
*/
|
|
12
|
+
export declare function createPrismicGraphQLToolAdapter(config: PrismicGraphQLToolAdapterConfig): Promise<ToolAdapter>;
|
|
13
|
+
//# sourceMappingURL=graphql-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-adapter.d.ts","sourceRoot":"","sources":["../src/graphql-adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,YAAY,CAAC;AAyGlE;;;;;;;;GAQG;AACH,wBAAsB,+BAA+B,CACnD,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,WAAW,CAAC,CAsDtB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createGraphQLToolAdapter } from "@yak-io/graphql";
|
|
1
2
|
const INTROSPECTION_QUERY = `query IntrospectionQuery {
|
|
2
3
|
__schema {
|
|
3
4
|
queryType { name }
|
|
@@ -75,20 +76,36 @@ function deriveGraphQLEndpoint(restEndpoint) {
|
|
|
75
76
|
const trimmed = restEndpoint.replace(/\/api\/v\d+\/?$/, "");
|
|
76
77
|
return `${trimmed}/graphql`;
|
|
77
78
|
}
|
|
79
|
+
async function buildHeaders(source, base) {
|
|
80
|
+
const headers = new Headers(base);
|
|
81
|
+
const resolved = typeof source === "function" ? await source() : source;
|
|
82
|
+
if (resolved) {
|
|
83
|
+
for (const [key, value] of new Headers(resolved)) {
|
|
84
|
+
headers.set(key, value);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return headers;
|
|
88
|
+
}
|
|
78
89
|
async function loadGraphQLModule() {
|
|
79
90
|
try {
|
|
80
91
|
return await import("graphql");
|
|
81
92
|
}
|
|
82
93
|
catch {
|
|
83
|
-
throw new Error("
|
|
94
|
+
throw new Error("createPrismicGraphQLToolAdapter requires the 'graphql' package. Install it as a peer dependency: pnpm add graphql");
|
|
84
95
|
}
|
|
85
96
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Introspect a Prismic repository's GraphQL schema and return a browser-executed
|
|
99
|
+
* GraphQL {@link ToolAdapter} (built on `@yak-io/graphql`). Compose it into a
|
|
100
|
+
* {@link createYakToolset}; the LLM authors queries from the introspected SDL and
|
|
101
|
+
* the adapter executes them against the repo's GraphQL endpoint.
|
|
102
|
+
*
|
|
103
|
+
* Prismic's GraphQL endpoint requires a `Prismic-ref` header at execution time —
|
|
104
|
+
* supply it via `headers` (it may be async to fetch the master ref per call).
|
|
105
|
+
*/
|
|
106
|
+
export async function createPrismicGraphQLToolAdapter(config) {
|
|
90
107
|
const fetchFn = config.fetchFn ?? fetch;
|
|
91
|
-
const endpoint = deriveGraphQLEndpoint(config.client.endpoint);
|
|
108
|
+
const endpoint = config.endpoint ?? deriveGraphQLEndpoint(config.client.endpoint);
|
|
92
109
|
const response = await fetchFn(endpoint, {
|
|
93
110
|
method: "POST",
|
|
94
111
|
headers: { "Content-Type": "application/json" },
|
|
@@ -104,9 +121,30 @@ export async function createPrismicSchemaSource(config) {
|
|
|
104
121
|
const { buildClientSchema, printSchema } = await loadGraphQLModule();
|
|
105
122
|
const schema = buildClientSchema(payload.data);
|
|
106
123
|
const sdl = printSchema(schema);
|
|
107
|
-
return {
|
|
124
|
+
return createGraphQLToolAdapter({
|
|
108
125
|
name: config.name ?? "prismic",
|
|
109
|
-
type: "graphql",
|
|
110
126
|
schema: sdl,
|
|
111
|
-
|
|
127
|
+
id: config.id,
|
|
128
|
+
// Prismic owns its own transport: POST the model-authored query to the repo's GraphQL
|
|
129
|
+
// endpoint with the caller-supplied headers (typically the required `Prismic-ref`).
|
|
130
|
+
execute: async (request) => {
|
|
131
|
+
const res = await fetchFn(endpoint, {
|
|
132
|
+
method: "POST",
|
|
133
|
+
headers: await buildHeaders(config.headers, { "Content-Type": "application/json" }),
|
|
134
|
+
body: JSON.stringify({
|
|
135
|
+
query: request.query,
|
|
136
|
+
variables: request.variables,
|
|
137
|
+
operationName: request.operationName,
|
|
138
|
+
}),
|
|
139
|
+
});
|
|
140
|
+
if (!res.ok) {
|
|
141
|
+
throw new Error(`Prismic GraphQL request failed (${res.status})`);
|
|
142
|
+
}
|
|
143
|
+
const payload = (await res.json());
|
|
144
|
+
if (payload.errors?.length) {
|
|
145
|
+
throw new Error(payload.errors[0]?.message ?? "Prismic GraphQL request returned errors");
|
|
146
|
+
}
|
|
147
|
+
return payload.data;
|
|
148
|
+
},
|
|
149
|
+
});
|
|
112
150
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
export { createPrismicGraphQLToolAdapter } from "./graphql-adapter.js";
|
|
1
2
|
export { createPrismicRouteAdapter } from "./route-adapter.js";
|
|
2
3
|
export { createPrismicToolAdapter } from "./tool-adapter.js";
|
|
3
|
-
export {
|
|
4
|
-
export type { PrismicRouteAdapterConfig, PrismicToolAdapterConfig, PrismicSchemaSourceConfig, PrismicGraphQLSchemaSourceConfig, } from "./types.js";
|
|
4
|
+
export type { PrismicGraphQLToolAdapterConfig, PrismicRouteAdapterConfig, PrismicToolAdapterConfig, } from "./types.js";
|
|
5
5
|
export type { RouteInfo, RouteSource, ToolDefinition, ToolExecutor, ToolManifest, ToolSource, } from "@yak-io/javascript/server";
|
|
6
|
-
export type {
|
|
6
|
+
export type { ToolAdapter } from "@yak-io/javascript";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,YAAY,EACV,+BAA+B,EAC/B,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,SAAS,EACT,WAAW,EACX,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,UAAU,GACX,MAAM,2BAA2B,CAAC;AAEnC,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -13,11 +13,23 @@ export type PrismicToolAdapterConfig = {
|
|
|
13
13
|
allowedTypes: string[];
|
|
14
14
|
fields?: Record<string, string[]>;
|
|
15
15
|
};
|
|
16
|
-
export type
|
|
16
|
+
export type PrismicGraphQLToolAdapterConfig = {
|
|
17
17
|
client: Client;
|
|
18
|
-
|
|
18
|
+
/** Tool name suffix — the tool is exposed as `graphql_<name>`. Defaults to "prismic". */
|
|
19
19
|
name?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Override the GraphQL endpoint used for execution. Defaults to the repo's
|
|
22
|
+
* derived `/graphql` URL (from the client's REST endpoint).
|
|
23
|
+
*/
|
|
24
|
+
endpoint?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Extra headers (e.g. `Prismic-ref`, `Authorization`) applied to query
|
|
27
|
+
* execution. May be async to fetch the master ref per call.
|
|
28
|
+
*/
|
|
29
|
+
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
30
|
+
/** Custom fetch used for the one-time schema introspection (useful in tests). */
|
|
20
31
|
fetchFn?: typeof fetch;
|
|
32
|
+
/** Stable adapter id for diagnostics. */
|
|
33
|
+
id?: string;
|
|
21
34
|
};
|
|
22
|
-
export type PrismicSchemaSourceConfig = PrismicGraphQLSchemaSourceConfig;
|
|
23
35
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,SAAS,GAAG,IAAI,CAAC;IACzD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,SAAS,GAAG,IAAI,CAAC;IACzD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,yFAAyF;IACzF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,iFAAiF;IACjF,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACvB,yCAAyC;IACzC,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yak-io/prismic",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Prismic CMS adapter for yak chatbot - exposes Prismic documents as routes, tools, and schema sources",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"./package.json": "./package.json"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@yak-io/
|
|
44
|
+
"@yak-io/graphql": "0.1.2",
|
|
45
|
+
"@yak-io/javascript": "0.10.0"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"@prismicio/client": "^7.0.0",
|
|
@@ -59,7 +60,7 @@
|
|
|
59
60
|
"typescript": "^5.3.0",
|
|
60
61
|
"@repo/typescript-config": "0.0.0"
|
|
61
62
|
},
|
|
62
|
-
"homepage": "https://docs.yak.io/docs/
|
|
63
|
+
"homepage": "https://docs.yak.io/docs/sdks/prismic",
|
|
63
64
|
"scripts": {
|
|
64
65
|
"build": "tsc",
|
|
65
66
|
"check-types": "tsc --noEmit",
|
package/dist/schema-source.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { GraphQLSchemaSource } from "@yak-io/javascript";
|
|
2
|
-
import type { PrismicSchemaSourceConfig } from "./types.js";
|
|
3
|
-
export declare function createPrismicSchemaSource(config: PrismicSchemaSourceConfig): Promise<GraphQLSchemaSource>;
|
|
4
|
-
//# sourceMappingURL=schema-source.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-source.d.ts","sourceRoot":"","sources":["../src/schema-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AA2F5D,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,mBAAmB,CAAC,CAkC9B"}
|