@yak-io/nextjs 0.1.6 → 0.2.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/README.md +48 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -263,6 +263,54 @@ export const { GET, POST } = createNextYakHandler({
|
|
|
263
263
|
| `onRedirect` | `(path: string) => void` | Custom navigation handler |
|
|
264
264
|
| `disableRestartButton` | `boolean` | Hide the restart session button in the header |
|
|
265
265
|
|
|
266
|
+
## Hooks
|
|
267
|
+
|
|
268
|
+
### useYak
|
|
269
|
+
|
|
270
|
+
Access the widget API from any component:
|
|
271
|
+
|
|
272
|
+
```tsx
|
|
273
|
+
import { useYak } from "@yak-io/nextjs/client";
|
|
274
|
+
|
|
275
|
+
export function ChatButton() {
|
|
276
|
+
const { open, close, openWithPrompt, isOpen } = useYak();
|
|
277
|
+
return <button onClick={() => open()}>Open Chat</button>;
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### useYakToolEvent
|
|
282
|
+
|
|
283
|
+
Subscribe to tool call completion events for page-level cache invalidation:
|
|
284
|
+
|
|
285
|
+
```tsx
|
|
286
|
+
import { useYakToolEvent } from "@yak-io/nextjs/client";
|
|
287
|
+
import { trpc } from "@/utils/trpc";
|
|
288
|
+
|
|
289
|
+
function PlanPage({ planId }: { planId: string }) {
|
|
290
|
+
const utils = trpc.useUtils();
|
|
291
|
+
|
|
292
|
+
useYakToolEvent((event) => {
|
|
293
|
+
// Invalidate cache when plan-related tools are called
|
|
294
|
+
if (event.ok && event.name.startsWith("plan.")) {
|
|
295
|
+
utils.plan.get.invalidate({ id: planId });
|
|
296
|
+
utils.planItem.list.invalidate({ planId });
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// ... component rendering
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
The event object contains:
|
|
305
|
+
|
|
306
|
+
| Property | Type | Description |
|
|
307
|
+
| --- | --- | --- |
|
|
308
|
+
| `name` | `string` | The tool name that was called |
|
|
309
|
+
| `args` | `unknown` | The arguments passed to the tool |
|
|
310
|
+
| `ok` | `boolean` | Whether the call succeeded |
|
|
311
|
+
| `result` | `unknown` | The result (if `ok` is true) |
|
|
312
|
+
| `error` | `string` | The error message (if `ok` is false) |
|
|
313
|
+
|
|
266
314
|
`YakWidget` renders the launcher + iframe shell. It accepts:
|
|
267
315
|
|
|
268
316
|
| Prop | Type | Description |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yak-io/nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Next.js SDK for embedding yak chatbot with route manifest generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"yak-nextjs": "./dist/cli/generate-manifest.js"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@yak-io/javascript": "0.
|
|
64
|
-
"@yak-io/react": "0.
|
|
63
|
+
"@yak-io/javascript": "0.2.0",
|
|
64
|
+
"@yak-io/react": "0.2.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"next": "^14.0.0 || ^15.0.0",
|