@yak-io/javascript 0.6.0 → 0.7.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 +181 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# @yak-io/javascript
|
|
2
|
+
|
|
3
|
+
Framework-agnostic core SDK for embedding the Yak chat widget. This package provides the low-level client and DOM rendering layer. Most developers should use a framework-specific package (`@yak-io/react`, `@yak-io/vue`, etc.) instead.
|
|
4
|
+
|
|
5
|
+
## When to use this package directly
|
|
6
|
+
|
|
7
|
+
- You are building a vanilla JS / TypeScript app
|
|
8
|
+
- You are building a new framework adapter
|
|
9
|
+
- You need the server-side handler utilities (`./server` export) outside Next.js
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @yak-io/javascript
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quickstart — Vanilla JS
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { YakEmbed } from "@yak-io/javascript";
|
|
21
|
+
|
|
22
|
+
const embed = new YakEmbed({
|
|
23
|
+
appId: "your-app-id",
|
|
24
|
+
theme: { position: "bottom-right", colorMode: "system" },
|
|
25
|
+
trigger: { label: "Ask with AI" },
|
|
26
|
+
getConfig: async () => ({
|
|
27
|
+
routes: {
|
|
28
|
+
routes: [
|
|
29
|
+
{ path: "/", title: "Home", description: "Landing page" },
|
|
30
|
+
{ path: "/docs", title: "Docs", description: "Documentation" },
|
|
31
|
+
],
|
|
32
|
+
generated_at: new Date().toISOString(),
|
|
33
|
+
},
|
|
34
|
+
tools: {
|
|
35
|
+
tools: [
|
|
36
|
+
{
|
|
37
|
+
name: "tasks.list",
|
|
38
|
+
displayName: "List Tasks",
|
|
39
|
+
description: "Return all tasks",
|
|
40
|
+
inputSchema: { type: "object", properties: {} },
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
generated_at: new Date().toISOString(),
|
|
44
|
+
},
|
|
45
|
+
}),
|
|
46
|
+
onToolCall: async (name, args) => {
|
|
47
|
+
if (name === "tasks.list") {
|
|
48
|
+
return { tasks: [] };
|
|
49
|
+
}
|
|
50
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
51
|
+
},
|
|
52
|
+
onRedirect: (path) => {
|
|
53
|
+
window.location.assign(path);
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
embed.mount();
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Server-side utilities
|
|
61
|
+
|
|
62
|
+
Use `@yak-io/javascript/server` to build framework-agnostic API handlers:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { createYakHandler } from "@yak-io/javascript/server";
|
|
66
|
+
|
|
67
|
+
// Works with any Request/Response runtime (Remix, Fastify, etc.)
|
|
68
|
+
const { GET, POST } = createYakHandler({
|
|
69
|
+
routes: [
|
|
70
|
+
{ path: "/", title: "Home" },
|
|
71
|
+
{ path: "/tasks", title: "Tasks" },
|
|
72
|
+
],
|
|
73
|
+
tools: {
|
|
74
|
+
getTools: async () => [
|
|
75
|
+
{
|
|
76
|
+
name: "tasks.list",
|
|
77
|
+
displayName: "List Tasks",
|
|
78
|
+
description: "Return all tasks",
|
|
79
|
+
inputSchema: { type: "object", properties: {} },
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
executeTool: async (name, args) => {
|
|
83
|
+
if (name === "tasks.list") return { tasks: [] };
|
|
84
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## API Reference
|
|
91
|
+
|
|
92
|
+
### `YakEmbed`
|
|
93
|
+
|
|
94
|
+
High-level class that handles DOM rendering (panel, iframe, trigger button) and client wiring.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
new YakEmbed(config: YakEmbedConfig)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Key methods:**
|
|
101
|
+
|
|
102
|
+
| Method | Description |
|
|
103
|
+
|--------|-------------|
|
|
104
|
+
| `mount()` | Injects the widget into the DOM |
|
|
105
|
+
| `destroy()` | Removes the widget from the DOM |
|
|
106
|
+
| `open()` | Open the chat panel |
|
|
107
|
+
| `close()` | Close the chat panel |
|
|
108
|
+
| `toggle()` | Toggle open/close |
|
|
109
|
+
| `openWithPrompt(prompt)` | Open and pre-fill a prompt |
|
|
110
|
+
| `getState()` | Get current `{ isOpen, isReady }` state |
|
|
111
|
+
| `onStateChange(fn)` | Subscribe to state changes, returns unsubscribe |
|
|
112
|
+
| `getClient()` | Access the underlying `YakClient` |
|
|
113
|
+
|
|
114
|
+
**Configuration (`YakEmbedConfig`):**
|
|
115
|
+
|
|
116
|
+
| Option | Type | Description |
|
|
117
|
+
|--------|------|-------------|
|
|
118
|
+
| `appId` | `string` | Your Yak app ID |
|
|
119
|
+
| `theme` | `Theme` | Position, color mode, and widget colors |
|
|
120
|
+
| `trigger` | `boolean \| TriggerButtonConfig` | Show built-in trigger button |
|
|
121
|
+
| `getConfig` | `ChatConfigProvider` | Async function returning routes + tools config |
|
|
122
|
+
| `chatConfig` | `ChatConfig` | Static config (alternative to `getConfig`) |
|
|
123
|
+
| `onToolCall` | `ToolCallHandler` | Handle tool calls from the assistant |
|
|
124
|
+
| `onGraphQLSchemaCall` | `GraphQLSchemaHandler` | Handle GraphQL schema tool calls |
|
|
125
|
+
| `onRESTSchemaCall` | `RESTSchemaHandler` | Handle REST/OpenAPI schema tool calls |
|
|
126
|
+
| `onRedirect` | `(path: string) => void` | Handle navigation requests |
|
|
127
|
+
| `onToolCallComplete` | `(event: ToolCallEvent) => void` | Called after each tool call |
|
|
128
|
+
| `options.disableRestartButton` | `boolean` | Hide the restart session button |
|
|
129
|
+
|
|
130
|
+
### `YakClient`
|
|
131
|
+
|
|
132
|
+
Low-level iframe communication client. Use `YakEmbed` for most cases.
|
|
133
|
+
|
|
134
|
+
### Logging utilities
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
import { enableYakLogging, disableYakLogging, isYakLoggingEnabled } from "@yak-io/javascript";
|
|
138
|
+
|
|
139
|
+
enableYakLogging(); // Turn on verbose SDK logging
|
|
140
|
+
disableYakLogging(); // Turn off SDK logging
|
|
141
|
+
isYakLoggingEnabled(); // Returns current state
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
In development, set `window.__YAK_INTERNAL_DEV__ = true` before mounting to connect to a locally running chat UI.
|
|
145
|
+
|
|
146
|
+
## Types
|
|
147
|
+
|
|
148
|
+
All types are exported from the package root:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import type {
|
|
152
|
+
ChatConfig,
|
|
153
|
+
ChatConfigProvider,
|
|
154
|
+
RouteManifest,
|
|
155
|
+
RouteInfo,
|
|
156
|
+
ToolManifest,
|
|
157
|
+
ToolDefinition,
|
|
158
|
+
ToolCallHandler,
|
|
159
|
+
ToolCallEvent,
|
|
160
|
+
ToolCallPayload,
|
|
161
|
+
ToolCallResult,
|
|
162
|
+
GraphQLSchemaHandler,
|
|
163
|
+
RESTSchemaHandler,
|
|
164
|
+
GraphQLRequest,
|
|
165
|
+
RESTRequest,
|
|
166
|
+
SchemaSource,
|
|
167
|
+
GraphQLSchemaSource,
|
|
168
|
+
OpenAPISchemaSource,
|
|
169
|
+
Theme,
|
|
170
|
+
ThemeColors,
|
|
171
|
+
TriggerButtonConfig,
|
|
172
|
+
WidgetPosition,
|
|
173
|
+
YakClientConfig,
|
|
174
|
+
YakEmbedConfig,
|
|
175
|
+
YakEmbedState,
|
|
176
|
+
} from "@yak-io/javascript";
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
Proprietary — see LICENSE file.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yak-io/javascript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Core JavaScript SDK for embedding yak chatbot",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
}
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@types/node": "^24.
|
|
59
|
+
"@types/node": "^24.12.0",
|
|
60
60
|
"typescript": "^5.3.0",
|
|
61
61
|
"@repo/typescript-config": "0.0.0"
|
|
62
62
|
},
|