@yak-io/javascript 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/client.d.ts +175 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +504 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.server.d.ts +2 -0
- package/dist/index.server.d.ts.map +1 -0
- package/dist/index.server.js +1 -0
- package/dist/logger.d.ts +12 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +44 -0
- package/dist/page-context.d.ts +10 -0
- package/dist/page-context.d.ts.map +1 -0
- package/dist/page-context.js +69 -0
- package/dist/schema-parser.d.ts +21 -0
- package/dist/schema-parser.d.ts.map +1 -0
- package/dist/schema-parser.js +341 -0
- package/dist/server/createYakHandler.d.ts +19 -0
- package/dist/server/createYakHandler.d.ts.map +1 -0
- package/dist/server/createYakHandler.js +185 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +2 -0
- package/dist/server/sources.d.ts +24 -0
- package/dist/server/sources.d.ts.map +1 -0
- package/dist/server/sources.js +116 -0
- package/dist/types/config.d.ts +19 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +1 -0
- package/dist/types/messaging.d.ts +153 -0
- package/dist/types/messaging.d.ts.map +1 -0
- package/dist/types/messaging.js +1 -0
- package/dist/types/routes.d.ts +26 -0
- package/dist/types/routes.d.ts.map +1 -0
- package/dist/types/routes.js +1 -0
- package/dist/types/tools.d.ts +137 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +1 -0
- package/dist/version.d.ts +23 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +18 -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
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type { ChatConfig } from "./types/config.js";
|
|
2
|
+
import type { Theme } from "./types/messaging.js";
|
|
3
|
+
import type { ToolCallHandler, GraphQLSchemaHandler, RESTSchemaHandler } from "./types/tools.js";
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
__YAK_INTERNAL_DEV__?: boolean;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export interface YakClientConfig {
|
|
10
|
+
appId: string;
|
|
11
|
+
/**
|
|
12
|
+
* Handler for tool calls from the chat widget.
|
|
13
|
+
* The consuming platform decides how to execute (browser, server fetch, etc.)
|
|
14
|
+
*
|
|
15
|
+
* @example Browser-only execution
|
|
16
|
+
* ```ts
|
|
17
|
+
* onToolCall: async (name, args) => {
|
|
18
|
+
* if (name === "ui.scrollTo") {
|
|
19
|
+
* document.getElementById(args.id)?.scrollIntoView();
|
|
20
|
+
* return { success: true };
|
|
21
|
+
* }
|
|
22
|
+
* throw new Error(`Unknown tool: ${name}`);
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example Server delegation
|
|
27
|
+
* ```ts
|
|
28
|
+
* onToolCall: async (name, args) => {
|
|
29
|
+
* const res = await fetch("/api/yak/tools", {
|
|
30
|
+
* method: "POST",
|
|
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
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
onToolCall?: ToolCallHandler;
|
|
40
|
+
/**
|
|
41
|
+
* Handler for GraphQL schema-based tool calls.
|
|
42
|
+
* Called when the LLM generates a GraphQL request based on a provided schema.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* onGraphQLSchemaCall: async (schemaName, request) => {
|
|
47
|
+
* const res = await fetch("/graphql", {
|
|
48
|
+
* method: "POST",
|
|
49
|
+
* headers: { "Content-Type": "application/json" },
|
|
50
|
+
* body: JSON.stringify({
|
|
51
|
+
* query: request.query,
|
|
52
|
+
* variables: request.variables,
|
|
53
|
+
* }),
|
|
54
|
+
* });
|
|
55
|
+
* return res.json();
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
onGraphQLSchemaCall?: GraphQLSchemaHandler;
|
|
60
|
+
/**
|
|
61
|
+
* Handler for REST/OpenAPI schema-based tool calls.
|
|
62
|
+
* Called when the LLM generates a REST request based on a provided schema.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* onRESTSchemaCall: async (schemaName, request) => {
|
|
67
|
+
* const url = new URL(`https://api.example.com${request.path}`);
|
|
68
|
+
* if (request.query) {
|
|
69
|
+
* for (const [key, value] of Object.entries(request.query)) {
|
|
70
|
+
* url.searchParams.set(key, value);
|
|
71
|
+
* }
|
|
72
|
+
* }
|
|
73
|
+
* const res = await fetch(url.toString(), {
|
|
74
|
+
* method: request.method,
|
|
75
|
+
* body: request.body ? JSON.stringify(request.body) : undefined,
|
|
76
|
+
* });
|
|
77
|
+
* return res.json();
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
onRESTSchemaCall?: RESTSchemaHandler;
|
|
82
|
+
theme?: Theme;
|
|
83
|
+
chatConfig?: ChatConfig;
|
|
84
|
+
onRedirect?: (path: string) => void;
|
|
85
|
+
onClose?: () => void;
|
|
86
|
+
onReady?: () => void;
|
|
87
|
+
/** Chat configuration options */
|
|
88
|
+
options?: {
|
|
89
|
+
/** Disable the restart session button in the header */
|
|
90
|
+
disableRestartButton?: boolean;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export declare class YakClient {
|
|
94
|
+
private config;
|
|
95
|
+
private iframeWindow;
|
|
96
|
+
private isWidgetOpen;
|
|
97
|
+
private readyTarget;
|
|
98
|
+
private unexpectedOriginLogged;
|
|
99
|
+
private lastUrl;
|
|
100
|
+
private debouncedSendContext;
|
|
101
|
+
private observer;
|
|
102
|
+
constructor(config: YakClientConfig);
|
|
103
|
+
updateConfig(newConfig: Partial<YakClientConfig>): void;
|
|
104
|
+
/**
|
|
105
|
+
* Get the iframe origin URL (base URL for the chat widget)
|
|
106
|
+
* This is computed each time to support setting __YAK_INTERNAL_DEV__ after page load.
|
|
107
|
+
*/
|
|
108
|
+
getIframeOrigin(): string;
|
|
109
|
+
/**
|
|
110
|
+
* Get the full iframe embed URL for the chatbot
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const client = new YakClient({ appId: "my-app" });
|
|
115
|
+
* const iframeSrc = client.getEmbedUrl();
|
|
116
|
+
* // Returns: "https://chat.yak.io/embed/v1/my-app"
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
getEmbedUrl(): string;
|
|
120
|
+
/**
|
|
121
|
+
* Get the app ID
|
|
122
|
+
*/
|
|
123
|
+
getAppId(): string;
|
|
124
|
+
/**
|
|
125
|
+
* Get the current theme configuration
|
|
126
|
+
*/
|
|
127
|
+
getTheme(): Theme | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* Send a prompt message to the chatbot iframe
|
|
130
|
+
* Note: The iframe must be ready to receive messages (onReady callback must have fired)
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* const client = new YakClient({ appId: "my-app", onReady: () => {
|
|
135
|
+
* client.sendPrompt("Help me with my order");
|
|
136
|
+
* }});
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
sendPrompt(prompt: string): void;
|
|
140
|
+
/**
|
|
141
|
+
* Send a focus request to the chatbot iframe
|
|
142
|
+
* This will focus the chat input field
|
|
143
|
+
*/
|
|
144
|
+
sendFocus(): void;
|
|
145
|
+
/**
|
|
146
|
+
* Check if the iframe is ready to receive messages
|
|
147
|
+
*/
|
|
148
|
+
isReady(): boolean;
|
|
149
|
+
setIframeWindow(window: Window | null): void;
|
|
150
|
+
setWidgetOpen(isOpen: boolean): void;
|
|
151
|
+
mount(): void;
|
|
152
|
+
unmount(): void;
|
|
153
|
+
private startObserving;
|
|
154
|
+
private stopObserving;
|
|
155
|
+
private handlePopState;
|
|
156
|
+
private handleMessage;
|
|
157
|
+
private sendConfigToIframe;
|
|
158
|
+
private sendPageContext;
|
|
159
|
+
private handleToolCall;
|
|
160
|
+
private handleGraphQLSchemaCall;
|
|
161
|
+
private handleRESTSchemaCall;
|
|
162
|
+
private sendToolResultToIframe;
|
|
163
|
+
/**
|
|
164
|
+
* Convert a value to a serializable form by stripping functions and other non-cloneable values.
|
|
165
|
+
* Uses JSON.parse(JSON.stringify()) which handles most cases.
|
|
166
|
+
*/
|
|
167
|
+
private toSerializable;
|
|
168
|
+
private extractErrorMessage;
|
|
169
|
+
/**
|
|
170
|
+
* Validates that a redirect path is safe (relative path or same-origin).
|
|
171
|
+
* Blocks absolute URLs to external domains to prevent open redirect attacks.
|
|
172
|
+
*/
|
|
173
|
+
private isAllowedRedirect;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAA8C,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EAGlB,MAAM,kBAAkB,CAAC;AAM1B,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,oBAAoB,CAAC,EAAE,OAAO,CAAC;KAChC;CACF;AA+BD,MAAM,WAAW,eAAe;IAC9B,KAAK,E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