@yak-io/vue 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 +151 -0
- package/dist/composables.js +1 -1
- package/package.json +3 -3
- 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,151 @@
|
|
|
1
|
+
# @yak-io/vue
|
|
2
|
+
|
|
3
|
+
Vue 3 integration for the Yak embeddable chat widget. Uses Vue's Composition API with reactive refs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @yak-io/vue
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
### 1. Initialize in your root component
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// App.vue <script setup>
|
|
17
|
+
import { createYakProvider } from "@yak-io/vue";
|
|
18
|
+
|
|
19
|
+
createYakProvider({
|
|
20
|
+
appId: import.meta.env.VITE_YAK_APP_ID,
|
|
21
|
+
theme: { position: "bottom-right", colorMode: "system" },
|
|
22
|
+
trigger: { label: "Ask with AI" },
|
|
23
|
+
getConfig: async () => {
|
|
24
|
+
const res = await fetch("/api/yak");
|
|
25
|
+
return res.json();
|
|
26
|
+
},
|
|
27
|
+
onToolCall: async (name, args) => {
|
|
28
|
+
const res = await fetch("/api/yak", {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: { "Content-Type": "application/json" },
|
|
31
|
+
body: JSON.stringify({ name, args }),
|
|
32
|
+
});
|
|
33
|
+
const data = await res.json();
|
|
34
|
+
if (!data.ok) throw new Error(data.error);
|
|
35
|
+
return data.result;
|
|
36
|
+
},
|
|
37
|
+
onRedirect: (path) => {
|
|
38
|
+
router.push(path);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`createYakProvider` calls `onMounted` and `onUnmounted` internally — no manual lifecycle management needed.
|
|
44
|
+
|
|
45
|
+
### 2. Use in descendant components
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
// MyComponent.vue <script setup>
|
|
49
|
+
import { useYak } from "@yak-io/vue";
|
|
50
|
+
|
|
51
|
+
const { open, openWithPrompt, isOpen, isReady } = useYak();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`isOpen` and `isReady` are `readonly` Vue refs — use them like any other ref:
|
|
55
|
+
|
|
56
|
+
```html
|
|
57
|
+
<template>
|
|
58
|
+
<div>
|
|
59
|
+
<button @click="open">Open Chat</button>
|
|
60
|
+
<p v-if="isOpen">Chat is open</p>
|
|
61
|
+
<p v-if="!isReady && isOpen">Loading…</p>
|
|
62
|
+
</div>
|
|
63
|
+
</template>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 3. Subscribe to tool events
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { useYakToolEvent } from "@yak-io/vue";
|
|
70
|
+
|
|
71
|
+
useYakToolEvent((event) => {
|
|
72
|
+
if (event.ok && event.name.startsWith("tasks.")) {
|
|
73
|
+
refreshTasks();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Automatically unsubscribes when the component unmounts.
|
|
79
|
+
|
|
80
|
+
## API Reference
|
|
81
|
+
|
|
82
|
+
### `createYakProvider(options)`
|
|
83
|
+
|
|
84
|
+
Call once in your root/layout component. Sets up the widget, registers lifecycle hooks, and provides the API to all descendant components via Vue's `provide/inject`.
|
|
85
|
+
|
|
86
|
+
Returns a `YakApi` object (same as `useYak()`).
|
|
87
|
+
|
|
88
|
+
**Options:**
|
|
89
|
+
|
|
90
|
+
| Option | Type | Description |
|
|
91
|
+
|--------|------|-------------|
|
|
92
|
+
| `appId` | `string` | Your Yak app ID |
|
|
93
|
+
| `getConfig` | `ChatConfigProvider` | Async function returning routes + tools. Called on first open. |
|
|
94
|
+
| `onToolCall` | `ToolCallHandler` | Handle tool invocations from the assistant |
|
|
95
|
+
| `onGraphQLSchemaCall` | `GraphQLSchemaHandler` | Handle GraphQL schema tool calls |
|
|
96
|
+
| `onRESTSchemaCall` | `RESTSchemaHandler` | Handle REST/OpenAPI schema tool calls |
|
|
97
|
+
| `theme` | `Theme` | Position, color mode, and custom colors |
|
|
98
|
+
| `onRedirect` | `(path: string) => void` | Navigation handler (defaults to `window.location.assign`) |
|
|
99
|
+
| `disableRestartButton` | `boolean` | Hide the restart session button |
|
|
100
|
+
| `trigger` | `boolean \| TriggerButtonConfig` | Built-in trigger button |
|
|
101
|
+
|
|
102
|
+
### `useYak()`
|
|
103
|
+
|
|
104
|
+
Inject the widget API in any descendant component.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
const {
|
|
108
|
+
isOpen, // DeepReadonly<Ref<boolean>>
|
|
109
|
+
isReady, // DeepReadonly<Ref<boolean>>
|
|
110
|
+
open, // () => void
|
|
111
|
+
close, // () => void
|
|
112
|
+
openWithPrompt, // (prompt: string) => void
|
|
113
|
+
subscribeToToolEvents, // (handler) => () => void
|
|
114
|
+
} = useYak();
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Throws if called outside a component tree where `createYakProvider` was used.
|
|
118
|
+
|
|
119
|
+
### `useYakToolEvent(handler)`
|
|
120
|
+
|
|
121
|
+
Subscribe to tool call completion events. Unsubscribes automatically on component unmount.
|
|
122
|
+
|
|
123
|
+
## Logging
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { enableYakLogging, disableYakLogging, isYakLoggingEnabled } from "@yak-io/vue";
|
|
127
|
+
|
|
128
|
+
enableYakLogging(); // Enable verbose SDK logs
|
|
129
|
+
disableYakLogging(); // Disable SDK logs
|
|
130
|
+
isYakLoggingEnabled(); // → boolean
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Types
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import type {
|
|
137
|
+
YakProviderOptions,
|
|
138
|
+
YakApi,
|
|
139
|
+
ToolCallEventHandler,
|
|
140
|
+
ChatConfigProvider,
|
|
141
|
+
ToolCallHandler,
|
|
142
|
+
ToolCallEvent,
|
|
143
|
+
Theme,
|
|
144
|
+
TriggerButtonConfig,
|
|
145
|
+
WidgetPosition,
|
|
146
|
+
} from "@yak-io/vue";
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
Proprietary — see LICENSE file.
|
package/dist/composables.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ref, readonly, onMounted, onUnmounted, inject, provide, } from "vue";
|
|
2
2
|
import { YakEmbed, } from "@yak-io/javascript";
|
|
3
|
-
import { logger } from "
|
|
3
|
+
import { logger } from "@yak-io/javascript";
|
|
4
4
|
// ── Injection key ───────────────────────────────────────────────────────────
|
|
5
5
|
const YAK_KEY = Symbol("yak");
|
|
6
6
|
// ── Provider composable ─────────────────────────────────────────────────────
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yak-io/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Vue SDK for embedding yak chatbot",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -41,13 +41,13 @@
|
|
|
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
47
|
"vue": "^3.3.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@types/node": "^24.
|
|
50
|
+
"@types/node": "^24.12.0",
|
|
51
51
|
"typescript": "^5.3.0",
|
|
52
52
|
"vue": "^3.5.16",
|
|
53
53
|
"@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";
|