@yak-io/vue 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/composables.d.ts +64 -0
- package/dist/composables.d.ts.map +1 -0
- package/dist/composables.js +142 -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/package.json +53 -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
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
isOpen: DeepReadonly<Ref<boolean>>;
|
|
17
|
+
isReady: DeepReadonly<Ref<boolean>>;
|
|
18
|
+
open: () => void;
|
|
19
|
+
close: () => void;
|
|
20
|
+
openWithPrompt: (prompt: string) => void;
|
|
21
|
+
subscribeToToolEvents: (handler: ToolCallEventHandler) => () => void;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Sets up the yak chat widget and provides it to descendant components.
|
|
25
|
+
* Call this once in a root/layout component.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // App.vue <script setup>
|
|
30
|
+
* import { createYakProvider } from "@yak-io/vue";
|
|
31
|
+
*
|
|
32
|
+
* createYakProvider({
|
|
33
|
+
* appId: "my-app",
|
|
34
|
+
* trigger: { label: "Ask with AI" },
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function createYakProvider(options: YakProviderOptions): YakApi;
|
|
39
|
+
/**
|
|
40
|
+
* Access the yak chat widget API.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const { open, isOpen, openWithPrompt } = useYak();
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @throws {Error} if used outside a component tree with createYakProvider
|
|
48
|
+
*/
|
|
49
|
+
export declare function useYak(): YakApi;
|
|
50
|
+
/**
|
|
51
|
+
* Subscribe to tool call completion events.
|
|
52
|
+
* Automatically cleans up on component unmount.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* useYakToolEvent((event) => {
|
|
57
|
+
* if (event.ok && event.name.startsWith("task.")) {
|
|
58
|
+
* refreshTasks();
|
|
59
|
+
* }
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function useYakToolEvent(handler: ToolCallEventHandler): void;
|
|
64
|
+
//# sourceMappingURL=composables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composables.d.ts","sourceRoot":"","sources":["../src/composables.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,KAAK,CAAC;AACb,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,kBA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G,IAAI,CAUnE"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { ref, readonly, onMounted, onUnmounted, inject, provide, } from "vue";
|
|
2
|
+
import { YakEmbed, } from "@yak-io/javascript";
|
|
3
|
+
import { logger } from "./internal/logger.js";
|
|
4
|
+
// ── Injection key ───────────────────────────────────────────────────────────
|
|
5
|
+
const YAK_KEY = Symbol("yak");
|
|
6
|
+
// ── Provider composable ─────────────────────────────────────────────────────
|
|
7
|
+
/**
|
|
8
|
+
* Sets up the yak chat widget and provides it to descendant components.
|
|
9
|
+
* Call this once in a root/layout component.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // App.vue <script setup>
|
|
14
|
+
* import { createYakProvider } from "@yak-io/vue";
|
|
15
|
+
*
|
|
16
|
+
* createYakProvider({
|
|
17
|
+
* appId: "my-app",
|
|
18
|
+
* trigger: { label: "Ask with AI" },
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function createYakProvider(options) {
|
|
23
|
+
const isOpen = ref(false);
|
|
24
|
+
const isReady = ref(false);
|
|
25
|
+
const toolEventSubscribers = new Set();
|
|
26
|
+
const handleToolCallComplete = (event) => {
|
|
27
|
+
logger.debug("Tool call completed, notifying subscribers:", {
|
|
28
|
+
name: event.name,
|
|
29
|
+
ok: event.ok,
|
|
30
|
+
subscriberCount: toolEventSubscribers.size,
|
|
31
|
+
});
|
|
32
|
+
for (const handler of toolEventSubscribers) {
|
|
33
|
+
try {
|
|
34
|
+
handler(event);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
logger.warn("Error in tool event subscriber:", err);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const resolvedRedirect = options.onRedirect ??
|
|
42
|
+
(typeof window !== "undefined" ? (path) => window.location.assign(path) : undefined);
|
|
43
|
+
const embed = new YakEmbed({
|
|
44
|
+
appId: options.appId,
|
|
45
|
+
theme: options.theme,
|
|
46
|
+
trigger: options.trigger ?? false,
|
|
47
|
+
onToolCall: options.onToolCall,
|
|
48
|
+
onGraphQLSchemaCall: options.onGraphQLSchemaCall,
|
|
49
|
+
onRESTSchemaCall: options.onRESTSchemaCall,
|
|
50
|
+
onRedirect: resolvedRedirect,
|
|
51
|
+
options: { disableRestartButton: options.disableRestartButton },
|
|
52
|
+
onToolCallComplete: handleToolCallComplete,
|
|
53
|
+
});
|
|
54
|
+
// Subscribe to state changes
|
|
55
|
+
embed.onStateChange((state) => {
|
|
56
|
+
isOpen.value = state.isOpen;
|
|
57
|
+
isReady.value = state.isReady;
|
|
58
|
+
});
|
|
59
|
+
// Mount/unmount with component lifecycle
|
|
60
|
+
onMounted(() => {
|
|
61
|
+
embed.mount();
|
|
62
|
+
});
|
|
63
|
+
onUnmounted(() => {
|
|
64
|
+
embed.destroy();
|
|
65
|
+
});
|
|
66
|
+
// Fetch chat config when widget opens
|
|
67
|
+
if (options.getConfig) {
|
|
68
|
+
const getConfig = options.getConfig;
|
|
69
|
+
let configFetched = false;
|
|
70
|
+
embed.onStateChange((state) => {
|
|
71
|
+
if (state.isOpen && !configFetched) {
|
|
72
|
+
configFetched = true;
|
|
73
|
+
logger.debug("Getting chat config");
|
|
74
|
+
Promise.resolve(getConfig())
|
|
75
|
+
.then((config) => {
|
|
76
|
+
logger.debug(`Chat config loaded with ${config.tools?.tools.length ?? 0} tools and ${config.routes?.routes.length ?? 0} routes`);
|
|
77
|
+
embed.getClient().updateConfig({ chatConfig: config });
|
|
78
|
+
})
|
|
79
|
+
.catch((err) => {
|
|
80
|
+
logger.warn("Error getting chat config:", err);
|
|
81
|
+
configFetched = false;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const api = {
|
|
87
|
+
isOpen: readonly(isOpen),
|
|
88
|
+
isReady: readonly(isReady),
|
|
89
|
+
open: () => embed.open(),
|
|
90
|
+
close: () => embed.close(),
|
|
91
|
+
openWithPrompt: (prompt) => embed.openWithPrompt(prompt),
|
|
92
|
+
subscribeToToolEvents: (handler) => {
|
|
93
|
+
toolEventSubscribers.add(handler);
|
|
94
|
+
return () => {
|
|
95
|
+
toolEventSubscribers.delete(handler);
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
provide(YAK_KEY, api);
|
|
100
|
+
return api;
|
|
101
|
+
}
|
|
102
|
+
// ── Consumer composables ────────────────────────────────────────────────────
|
|
103
|
+
/**
|
|
104
|
+
* Access the yak chat widget API.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* const { open, isOpen, openWithPrompt } = useYak();
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @throws {Error} if used outside a component tree with createYakProvider
|
|
112
|
+
*/
|
|
113
|
+
export function useYak() {
|
|
114
|
+
const api = inject(YAK_KEY);
|
|
115
|
+
if (!api) {
|
|
116
|
+
throw new Error("useYak() requires createYakProvider() in an ancestor component");
|
|
117
|
+
}
|
|
118
|
+
return api;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Subscribe to tool call completion events.
|
|
122
|
+
* Automatically cleans up on component unmount.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* useYakToolEvent((event) => {
|
|
127
|
+
* if (event.ok && event.name.startsWith("task.")) {
|
|
128
|
+
* refreshTasks();
|
|
129
|
+
* }
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export function useYakToolEvent(handler) {
|
|
134
|
+
const api = inject(YAK_KEY);
|
|
135
|
+
if (!api) {
|
|
136
|
+
throw new Error("useYakToolEvent() requires createYakProvider() in an ancestor component");
|
|
137
|
+
}
|
|
138
|
+
onMounted(() => {
|
|
139
|
+
const unsubscribe = api.subscribeToToolEvents(handler);
|
|
140
|
+
onUnmounted(unsubscribe);
|
|
141
|
+
});
|
|
142
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { useYak, useYakToolEvent, createYakProvider } from "./composables.js";
|
|
2
|
+
export type { YakProviderOptions, YakApi, ToolCallEventHandler } from "./composables.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,MAAM,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,YAAY,EAAE,kBAAkB,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGzF,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/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yak-io/vue",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vue SDK 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/vue"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"keywords": ["yak", "chatbot", "ai", "widget", "chat", "vue"],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
20
|
+
"files": ["dist", "LICENSE"],
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc",
|
|
35
|
+
"check-types": "tsc --noEmit",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"lint": "biome lint ./src --fix",
|
|
38
|
+
"format": "biome format ./src --write",
|
|
39
|
+
"prepare": "pnpm build"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@yak-io/javascript": "workspace:*"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"vue": "^3.3.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@repo/typescript-config": "workspace:*",
|
|
49
|
+
"@types/node": "^24.10.4",
|
|
50
|
+
"typescript": "^5.3.0",
|
|
51
|
+
"vue": "^3.5.16"
|
|
52
|
+
}
|
|
53
|
+
}
|