@yak-io/nuxt 0.1.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/LICENSE +36 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/internal/logger.d.ts +2 -0
- package/dist/internal/logger.d.ts.map +1 -0
- package/dist/internal/logger.js +1 -0
- package/dist/plugin.d.ts +59 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +102 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Yak Proprietary License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yak. All rights reserved.
|
|
4
|
+
|
|
5
|
+
This software and associated documentation files (the "Software") are the
|
|
6
|
+
proprietary property of Yak and are protected by copyright law.
|
|
7
|
+
|
|
8
|
+
GRANT OF LICENSE:
|
|
9
|
+
Subject to the terms of this license and your valid subscription or agreement
|
|
10
|
+
with Yak, you are granted a limited, non-exclusive, non-transferable license
|
|
11
|
+
to use the Software solely for integrating the Yak chatbot widget into your
|
|
12
|
+
applications as intended and documented.
|
|
13
|
+
|
|
14
|
+
RESTRICTIONS:
|
|
15
|
+
You may NOT:
|
|
16
|
+
- Modify, adapt, alter, translate, or create derivative works of the Software
|
|
17
|
+
- Reverse engineer, disassemble, decompile, or otherwise attempt to derive
|
|
18
|
+
the source code of the Software
|
|
19
|
+
- Redistribute, sublicense, lease, rent, or lend the Software to third parties
|
|
20
|
+
- Remove or alter any proprietary notices, labels, or marks on the Software
|
|
21
|
+
- Use the Software for any purpose other than as expressly permitted herein
|
|
22
|
+
|
|
23
|
+
NO WARRANTY:
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL YAK
|
|
27
|
+
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
28
|
+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
29
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
30
|
+
|
|
31
|
+
TERMINATION:
|
|
32
|
+
This license is effective until terminated. Your rights under this license
|
|
33
|
+
will terminate automatically without notice if you fail to comply with any
|
|
34
|
+
of its terms.
|
|
35
|
+
|
|
36
|
+
For licensing inquiries, contact: support@yak.io
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createYakProvider } from "./plugin.js";
|
|
2
|
+
export type { YakProviderOptions, YakApi, ToolCallEventHandler } from "./plugin.js";
|
|
3
|
+
export { enableYakLogging, disableYakLogging, isYakLoggingEnabled } from "@yak-io/javascript";
|
|
4
|
+
export type { GraphQLSchemaHandler, RESTSchemaHandler, GraphQLRequest, RESTRequest, ToolCallHandler, ToolCallEvent, SchemaSource, GraphQLSchemaSource, OpenAPISchemaSource, Theme, ThemeColors, TriggerButtonConfig, WidgetPosition, ChatConfigProvider, } from "@yak-io/javascript";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EAAE,kBAAkB,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGpF,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAG9F,YAAY,EACV,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,eAAe,EACf,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,KAAK,EACL,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,kBAAkB,GACnB,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/internal/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { logger } from "@yak-io/javascript";
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type Ref, type DeepReadonly } from "vue";
|
|
2
|
+
import { type TriggerButtonConfig, type ChatConfigProvider, type ToolCallHandler, type ToolCallEvent, type GraphQLSchemaHandler, type RESTSchemaHandler, type Theme } from "@yak-io/javascript";
|
|
3
|
+
export type ToolCallEventHandler = (event: ToolCallEvent) => void;
|
|
4
|
+
export type YakProviderOptions = {
|
|
5
|
+
appId: string;
|
|
6
|
+
getConfig?: ChatConfigProvider;
|
|
7
|
+
onToolCall?: ToolCallHandler;
|
|
8
|
+
onGraphQLSchemaCall?: GraphQLSchemaHandler;
|
|
9
|
+
onRESTSchemaCall?: RESTSchemaHandler;
|
|
10
|
+
theme?: Theme;
|
|
11
|
+
onRedirect?: (path: string) => void;
|
|
12
|
+
disableRestartButton?: boolean;
|
|
13
|
+
trigger?: boolean | TriggerButtonConfig;
|
|
14
|
+
};
|
|
15
|
+
export type YakApi = {
|
|
16
|
+
/** Readonly ref — whether the chat widget is open */
|
|
17
|
+
isOpen: DeepReadonly<Ref<boolean>>;
|
|
18
|
+
/** Readonly ref — whether the iframe is ready */
|
|
19
|
+
isReady: DeepReadonly<Ref<boolean>>;
|
|
20
|
+
/** Open the chat widget */
|
|
21
|
+
open: () => void;
|
|
22
|
+
/** Close the chat widget */
|
|
23
|
+
close: () => void;
|
|
24
|
+
/** Open the chat widget and send a prompt */
|
|
25
|
+
openWithPrompt: (prompt: string) => void;
|
|
26
|
+
/** Subscribe to tool call completion events. Returns an unsubscribe function. */
|
|
27
|
+
subscribeToToolEvents: (handler: ToolCallEventHandler) => () => void;
|
|
28
|
+
/** Mount the widget DOM — call only on client side */
|
|
29
|
+
mount: () => void;
|
|
30
|
+
/** Destroy the widget DOM */
|
|
31
|
+
destroy: () => void;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Creates a yak chat widget instance for Nuxt.
|
|
35
|
+
* SSR-safe: call `mount()` only on the client side (e.g. in a plugin with `nuxtApp.hook("app:mounted")`
|
|
36
|
+
* or inside `onMounted`).
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* // plugins/yak.client.ts
|
|
41
|
+
* import { createYakProvider } from "@yak-io/nuxt";
|
|
42
|
+
*
|
|
43
|
+
* export default defineNuxtPlugin((nuxtApp) => {
|
|
44
|
+
* const yak = createYakProvider({ appId: "my-app" });
|
|
45
|
+
*
|
|
46
|
+
* nuxtApp.hook("app:mounted", () => yak.mount());
|
|
47
|
+
* nuxtApp.hook("app:beforeMount", () => {});
|
|
48
|
+
*
|
|
49
|
+
* nuxtApp.provide("yak", yak);
|
|
50
|
+
*
|
|
51
|
+
* // Cleanup on HMR
|
|
52
|
+
* if (import.meta.hot) {
|
|
53
|
+
* import.meta.hot.dispose(() => yak.destroy());
|
|
54
|
+
* }
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function createYakProvider(options: YakProviderOptions): YakApi;
|
|
59
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,GAAG,EAAE,KAAK,YAAY,EAAE,MAAM,KAAK,CAA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AC;CACrB,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAkFrE"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ref, readonly } from "vue";
|
|
2
|
+
import { YakEmbed, } from "@yak-io/javascript";
|
|
3
|
+
import { logger } from "./internal/logger.js";
|
|
4
|
+
// ── Provider factory ────────────────────────────────────────────────────────
|
|
5
|
+
/**
|
|
6
|
+
* Creates a yak chat widget instance for Nuxt.
|
|
7
|
+
* SSR-safe: call `mount()` only on the client side (e.g. in a plugin with `nuxtApp.hook("app:mounted")`
|
|
8
|
+
* or inside `onMounted`).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // plugins/yak.client.ts
|
|
13
|
+
* import { createYakProvider } from "@yak-io/nuxt";
|
|
14
|
+
*
|
|
15
|
+
* export default defineNuxtPlugin((nuxtApp) => {
|
|
16
|
+
* const yak = createYakProvider({ appId: "my-app" });
|
|
17
|
+
*
|
|
18
|
+
* nuxtApp.hook("app:mounted", () => yak.mount());
|
|
19
|
+
* nuxtApp.hook("app:beforeMount", () => {});
|
|
20
|
+
*
|
|
21
|
+
* nuxtApp.provide("yak", yak);
|
|
22
|
+
*
|
|
23
|
+
* // Cleanup on HMR
|
|
24
|
+
* if (import.meta.hot) {
|
|
25
|
+
* import.meta.hot.dispose(() => yak.destroy());
|
|
26
|
+
* }
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function createYakProvider(options) {
|
|
31
|
+
const isOpen = ref(false);
|
|
32
|
+
const isReady = ref(false);
|
|
33
|
+
const toolEventSubscribers = new Set();
|
|
34
|
+
const handleToolCallComplete = (event) => {
|
|
35
|
+
logger.debug("Tool call completed, notifying subscribers:", {
|
|
36
|
+
name: event.name,
|
|
37
|
+
ok: event.ok,
|
|
38
|
+
subscriberCount: toolEventSubscribers.size,
|
|
39
|
+
});
|
|
40
|
+
for (const handler of toolEventSubscribers) {
|
|
41
|
+
try {
|
|
42
|
+
handler(event);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
logger.warn("Error in tool event subscriber:", err);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const resolvedRedirect = options.onRedirect ??
|
|
50
|
+
(typeof window !== "undefined" ? (path) => window.location.assign(path) : undefined);
|
|
51
|
+
const embed = new YakEmbed({
|
|
52
|
+
appId: options.appId,
|
|
53
|
+
theme: options.theme,
|
|
54
|
+
trigger: options.trigger ?? false,
|
|
55
|
+
onToolCall: options.onToolCall,
|
|
56
|
+
onGraphQLSchemaCall: options.onGraphQLSchemaCall,
|
|
57
|
+
onRESTSchemaCall: options.onRESTSchemaCall,
|
|
58
|
+
onRedirect: resolvedRedirect,
|
|
59
|
+
options: { disableRestartButton: options.disableRestartButton },
|
|
60
|
+
onToolCallComplete: handleToolCallComplete,
|
|
61
|
+
});
|
|
62
|
+
// Sync embed state → refs
|
|
63
|
+
embed.onStateChange((state) => {
|
|
64
|
+
isOpen.value = state.isOpen;
|
|
65
|
+
isReady.value = state.isReady;
|
|
66
|
+
});
|
|
67
|
+
// Fetch chat config on first open
|
|
68
|
+
if (options.getConfig) {
|
|
69
|
+
const getConfig = options.getConfig;
|
|
70
|
+
let configFetched = false;
|
|
71
|
+
embed.onStateChange((state) => {
|
|
72
|
+
if (state.isOpen && !configFetched) {
|
|
73
|
+
configFetched = true;
|
|
74
|
+
logger.debug("Getting chat config");
|
|
75
|
+
Promise.resolve(getConfig())
|
|
76
|
+
.then((config) => {
|
|
77
|
+
logger.debug(`Chat config loaded with ${config.tools?.tools.length ?? 0} tools and ${config.routes?.routes.length ?? 0} routes`);
|
|
78
|
+
embed.getClient().updateConfig({ chatConfig: config });
|
|
79
|
+
})
|
|
80
|
+
.catch((err) => {
|
|
81
|
+
logger.warn("Error getting chat config:", err);
|
|
82
|
+
configFetched = false;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
isOpen: readonly(isOpen),
|
|
89
|
+
isReady: readonly(isReady),
|
|
90
|
+
open: () => embed.open(),
|
|
91
|
+
close: () => embed.close(),
|
|
92
|
+
openWithPrompt: (prompt) => embed.openWithPrompt(prompt),
|
|
93
|
+
subscribeToToolEvents: (handler) => {
|
|
94
|
+
toolEventSubscribers.add(handler);
|
|
95
|
+
return () => {
|
|
96
|
+
toolEventSubscribers.delete(handler);
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
mount: () => embed.mount(),
|
|
100
|
+
destroy: () => embed.destroy(),
|
|
101
|
+
};
|
|
102
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yak-io/nuxt",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Nuxt 3 module for embedding yak chatbot",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
7
|
+
"author": "Yak <support@yak.io>",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/388-labs/yak.git",
|
|
11
|
+
"directory": "packages/nuxt"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"yak",
|
|
18
|
+
"chatbot",
|
|
19
|
+
"ai",
|
|
20
|
+
"widget",
|
|
21
|
+
"chat",
|
|
22
|
+
"nuxt"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"module": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.js",
|
|
39
|
+
"default": "./dist/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc",
|
|
45
|
+
"check-types": "tsc --noEmit",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"lint": "biome lint ./src --fix",
|
|
48
|
+
"format": "biome format ./src --write",
|
|
49
|
+
"prepare": "pnpm build"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@yak-io/javascript": "workspace:*"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"vue": "^3.3.0",
|
|
56
|
+
"nuxt": "^3.0.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@repo/typescript-config": "workspace:*",
|
|
60
|
+
"@types/node": "^24.10.4",
|
|
61
|
+
"typescript": "^5.3.0",
|
|
62
|
+
"vue": "^3.5.16"
|
|
63
|
+
}
|
|
64
|
+
}
|