@yak-io/nextjs 0.1.6 → 0.3.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 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 |
@@ -1,11 +1,6 @@
1
1
  /**
2
- * Simple logger utility - no-op by default
3
- * Can be replaced with proper logging later
2
+ * Re-export logger from @yak-io/javascript.
3
+ * All logging configuration is centralized there.
4
4
  */
5
- export declare const logger: {
6
- debug: (message: string, ...args: unknown[]) => void;
7
- info: (message: string, ...args: unknown[]) => void;
8
- warn: (message: string, ...args: unknown[]) => void;
9
- error: (message: string, ...args: unknown[]) => void;
10
- };
5
+ export { logger } from "@yak-io/javascript";
11
6
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/internal/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,MAAM;qBACA,MAAM,WAAW,OAAO,EAAE,KAAG,IAAI;oBAOlC,MAAM,WAAW,OAAO,EAAE,KAAG,IAAI;oBAMjC,MAAM,WAAW,OAAO,EAAE,KAAG,IAAI;qBAIhC,MAAM,WAAW,OAAO,EAAE,KAAG,IAAI;CAGnD,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/internal/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC"}
@@ -1,23 +1,5 @@
1
1
  /**
2
- * Simple logger utility - no-op by default
3
- * Can be replaced with proper logging later
2
+ * Re-export logger from @yak-io/javascript.
3
+ * All logging configuration is centralized there.
4
4
  */
5
- export const logger = {
6
- debug: (message, ...args) => {
7
- // No-op in production, could log in development
8
- if (process.env.NODE_ENV === "development") {
9
- console.debug(`[yak/nextjs] ${message}`, ...args);
10
- }
11
- },
12
- info: (message, ...args) => {
13
- if (process.env.NODE_ENV === "development") {
14
- console.info(`[yak/nextjs] ${message}`, ...args);
15
- }
16
- },
17
- warn: (message, ...args) => {
18
- console.warn(`[yak/nextjs] ${message}`, ...args);
19
- },
20
- error: (message, ...args) => {
21
- console.error(`[yak/nextjs] ${message}`, ...args);
22
- },
23
- };
5
+ export { logger } from "@yak-io/javascript";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yak-io/nextjs",
3
- "version": "0.1.6",
3
+ "version": "0.3.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,11 +60,11 @@
60
60
  "yak-nextjs": "./dist/cli/generate-manifest.js"
61
61
  },
62
62
  "dependencies": {
63
- "@yak-io/javascript": "0.1.1",
64
- "@yak-io/react": "0.1.1"
63
+ "@yak-io/javascript": "0.3.0",
64
+ "@yak-io/react": "0.3.0"
65
65
  },
66
66
  "peerDependencies": {
67
- "next": "^14.0.0 || ^15.0.0",
67
+ "next": "^14.0.0 || ^15.0.0 || ^16.0.0",
68
68
  "react": "^18.0.0 || ^19.0.0",
69
69
  "react-dom": "^18.0.0 || ^19.0.0"
70
70
  },