@yak-io/nuxt 0.1.1 → 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 +155 -0
- package/dist/plugin.js +1 -1
- package/package.json +5 -5
- package/dist/internal/logger.d.ts +0 -2
- package/dist/internal/logger.d.ts.map +0 -1
- package/dist/internal/logger.js +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# @yak-io/nuxt
|
|
2
|
+
|
|
3
|
+
Nuxt 3 integration for the Yak embeddable chat widget. Provides a plugin-compatible factory that auto-mounts on `app:mounted` and provides the widget API via Nuxt's plugin system.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @yak-io/nuxt
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
### 1. Create a Nuxt plugin
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// plugins/yak.client.ts
|
|
17
|
+
import { defineNuxtPlugin } from "#app";
|
|
18
|
+
import { createYakProvider, enableYakLogging, disableYakLogging, isYakLoggingEnabled } from "@yak-io/nuxt";
|
|
19
|
+
|
|
20
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
21
|
+
const runtimeConfig = useRuntimeConfig();
|
|
22
|
+
|
|
23
|
+
const yak = createYakProvider({
|
|
24
|
+
appId: runtimeConfig.public.yakAppId,
|
|
25
|
+
theme: { position: "bottom-right", colorMode: "system" },
|
|
26
|
+
trigger: { label: "Ask with AI" },
|
|
27
|
+
getConfig: async () => {
|
|
28
|
+
const res = await fetch("/api/yak");
|
|
29
|
+
return res.json();
|
|
30
|
+
},
|
|
31
|
+
onToolCall: async (name, args) => {
|
|
32
|
+
const res = await fetch("/api/yak", {
|
|
33
|
+
method: "POST",
|
|
34
|
+
headers: { "Content-Type": "application/json" },
|
|
35
|
+
body: JSON.stringify({ name, args }),
|
|
36
|
+
});
|
|
37
|
+
const data = await res.json();
|
|
38
|
+
if (!data.ok) throw new Error(data.error);
|
|
39
|
+
return data.result;
|
|
40
|
+
},
|
|
41
|
+
onRedirect: (path) => {
|
|
42
|
+
navigateTo(path);
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Mount on client, clean up on HMR
|
|
47
|
+
nuxtApp.hook("app:mounted", () => yak.mount());
|
|
48
|
+
if (import.meta.hot) {
|
|
49
|
+
import.meta.hot.dispose(() => yak.destroy());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
provide: {
|
|
54
|
+
yak,
|
|
55
|
+
yakLogging: { enableYakLogging, disableYakLogging, isYakLoggingEnabled },
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 2. Access in components
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
// Any component <script setup>
|
|
65
|
+
const { $yak } = useNuxtApp();
|
|
66
|
+
const { open, openWithPrompt, isOpen, isReady } = $yak;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`isOpen` and `isReady` are Vue `readonly` refs:
|
|
70
|
+
|
|
71
|
+
```html
|
|
72
|
+
<template>
|
|
73
|
+
<button @click="open">Open Chat</button>
|
|
74
|
+
<span v-if="isOpen">Chat is open</span>
|
|
75
|
+
</template>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 3. Subscribe to tool events
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const { $yak } = useNuxtApp();
|
|
82
|
+
|
|
83
|
+
$yak.subscribeToToolEvents((event) => {
|
|
84
|
+
if (event.ok && event.name.startsWith("tasks.")) {
|
|
85
|
+
refreshTasks();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## API Reference
|
|
91
|
+
|
|
92
|
+
### `createYakProvider(options)`
|
|
93
|
+
|
|
94
|
+
Creates a Yak widget instance. Returns a `YakApi` with Vue-reactive refs for reactive state.
|
|
95
|
+
|
|
96
|
+
You must call `yak.mount()` on the client side (e.g., in the `app:mounted` hook) and `yak.destroy()` when cleaning up.
|
|
97
|
+
|
|
98
|
+
**Options:**
|
|
99
|
+
|
|
100
|
+
| Option | Type | Description |
|
|
101
|
+
|--------|------|-------------|
|
|
102
|
+
| `appId` | `string` | Your Yak app ID |
|
|
103
|
+
| `getConfig` | `ChatConfigProvider` | Async function returning routes + tools. Called on first open. |
|
|
104
|
+
| `onToolCall` | `ToolCallHandler` | Handle tool invocations from the assistant |
|
|
105
|
+
| `onGraphQLSchemaCall` | `GraphQLSchemaHandler` | Handle GraphQL schema tool calls |
|
|
106
|
+
| `onRESTSchemaCall` | `RESTSchemaHandler` | Handle REST/OpenAPI schema tool calls |
|
|
107
|
+
| `theme` | `Theme` | Position, color mode, and custom colors |
|
|
108
|
+
| `onRedirect` | `(path: string) => void` | Navigation handler (defaults to `window.location.assign`) |
|
|
109
|
+
| `disableRestartButton` | `boolean` | Hide the restart session button |
|
|
110
|
+
| `trigger` | `boolean \| TriggerButtonConfig` | Built-in trigger button |
|
|
111
|
+
|
|
112
|
+
### `YakApi`
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
type YakApi = {
|
|
116
|
+
isOpen: DeepReadonly<Ref<boolean>>; // Vue readonly ref
|
|
117
|
+
isReady: DeepReadonly<Ref<boolean>>; // Vue readonly ref
|
|
118
|
+
open: () => void;
|
|
119
|
+
close: () => void;
|
|
120
|
+
openWithPrompt: (prompt: string) => void;
|
|
121
|
+
subscribeToToolEvents: (handler: ToolCallEventHandler) => () => void;
|
|
122
|
+
mount: () => void; // Call in app:mounted hook
|
|
123
|
+
destroy: () => void; // Call on HMR dispose / cleanup
|
|
124
|
+
};
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Logging
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { enableYakLogging, disableYakLogging, isYakLoggingEnabled } from "@yak-io/nuxt";
|
|
131
|
+
|
|
132
|
+
enableYakLogging(); // Enable verbose SDK logs
|
|
133
|
+
disableYakLogging(); // Disable SDK logs
|
|
134
|
+
isYakLoggingEnabled(); // → boolean
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Types
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import type {
|
|
141
|
+
YakProviderOptions,
|
|
142
|
+
YakApi,
|
|
143
|
+
ToolCallEventHandler,
|
|
144
|
+
ChatConfigProvider,
|
|
145
|
+
ToolCallHandler,
|
|
146
|
+
ToolCallEvent,
|
|
147
|
+
Theme,
|
|
148
|
+
TriggerButtonConfig,
|
|
149
|
+
WidgetPosition,
|
|
150
|
+
} from "@yak-io/nuxt";
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
Proprietary — see LICENSE file.
|
package/dist/plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ref, readonly } from "vue";
|
|
2
2
|
import { YakEmbed, } from "@yak-io/javascript";
|
|
3
|
-
import { logger } from "
|
|
3
|
+
import { logger } from "@yak-io/javascript";
|
|
4
4
|
// ── Provider factory ────────────────────────────────────────────────────────
|
|
5
5
|
/**
|
|
6
6
|
* Creates a yak chat widget instance for Nuxt.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yak-io/nuxt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Nuxt 3 module for embedding yak chatbot",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
"./package.json": "./package.json"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@yak-io/javascript": "0.
|
|
44
|
+
"@yak-io/javascript": "0.7.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"
|
|
48
|
-
"
|
|
47
|
+
"nuxt": "^3.0.0",
|
|
48
|
+
"vue": "^3.3.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@types/node": "^24.
|
|
51
|
+
"@types/node": "^24.12.0",
|
|
52
52
|
"typescript": "^5.3.0",
|
|
53
53
|
"vue": "^3.5.16",
|
|
54
54
|
"@repo/typescript-config": "0.0.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/internal/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/internal/logger.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { logger } from "@yak-io/javascript";
|