@yak-io/javascript 0.8.0 → 0.10.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 +131 -107
- package/dist/client.d.ts +9 -47
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +15 -71
- package/dist/embed.d.ts +15 -0
- package/dist/embed.d.ts.map +1 -1
- package/dist/embed.js +9 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/toolset.d.ts +45 -0
- package/dist/toolset.d.ts.map +1 -0
- package/dist/toolset.js +119 -0
- package/dist/types/config.d.ts +3 -5
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/messaging.d.ts +1 -17
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/types/tools.d.ts +35 -42
- package/dist/types/tools.d.ts.map +1 -1
- package/dist/voice-machine.d.ts +16 -0
- package/dist/voice-machine.d.ts.map +1 -1
- package/dist/voice-machine.js +5 -0
- package/dist/voice-session.d.ts +12 -14
- package/dist/voice-session.d.ts.map +1 -1
- package/dist/voice-session.js +33 -45
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -1,80 +1,152 @@
|
|
|
1
1
|
# @yak-io/javascript
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> 📚 **Full documentation:** https://docs.yak.io/docs/sdks/javascript
|
|
4
|
+
>
|
|
5
|
+
> 🤖 **For LLMs / AI agents:** https://docs.yak.io/llms.txt
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
Framework-agnostic core SDK for [Yak](https://docs.yak.io) — an embeddable AI assistant (text chat **and** push-to-talk voice) for web apps. This package is the low-level runtime that every framework SDK (`@yak-io/react`, `@yak-io/vue`, …) is built on. It owns iframe messaging, the WebRTC voice session, DOM rendering of the trigger pill + chat panel, and an optional server handler.
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
- You are building a new framework adapter
|
|
9
|
-
- You need the server-side handler utilities (`./server` export) outside Next.js
|
|
10
|
-
|
|
11
|
-
## Installation
|
|
9
|
+
**Use this package directly when** you're on vanilla JS/TS, building a new framework adapter, or need the server handler (`@yak-io/javascript/server`) outside Next.js. On a supported framework, prefer that framework's package instead.
|
|
12
10
|
|
|
13
11
|
```bash
|
|
14
12
|
pnpm add @yak-io/javascript
|
|
15
13
|
```
|
|
16
14
|
|
|
17
|
-
##
|
|
15
|
+
## Exports
|
|
16
|
+
|
|
17
|
+
| Export | Kind | Purpose |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| `YakEmbed` | class | Drop-in widget: trigger pill + chat panel + voice, all wired. Start here. |
|
|
20
|
+
| `YakClient` | class | Headless chat-only iframe client (no DOM). Advanced. |
|
|
21
|
+
| `YakVoiceSession` | class | Headless WebRTC voice session. Advanced. |
|
|
22
|
+
| `createYakToolset` | fn | Compose tool adapters (GraphQL, REST, tRPC, custom) into one merged manifest + one routed `onToolCall`. |
|
|
23
|
+
| `createYakServerAdapter` | fn | Wrap a server handler endpoint (`createYakHandler`) as a `ToolAdapter` for `createYakToolset`. |
|
|
24
|
+
| `enableYakLogging` / `disableYakLogging` / `isYakLoggingEnabled` | fn | Toggle verbose SDK logging. |
|
|
25
|
+
| `EMBED_PROTOCOL_VERSION` | const | Host ↔ iframe protocol version. |
|
|
26
|
+
| Types | — | `YakEmbedConfig`, `YakClientConfig`, `Theme`, `WidgetMode`, `VoiceState`, `VoiceMachine`, `ToolCallEvent`, `ChatConfig`, and more (see [Types](#types)). |
|
|
27
|
+
| `@yak-io/javascript/server` | subpath | `createYakHandler` + route/tool source types (see [Server](#server-side-handler)). |
|
|
28
|
+
|
|
29
|
+
## Quickstart
|
|
18
30
|
|
|
19
31
|
```ts
|
|
20
32
|
import { YakEmbed } from "@yak-io/javascript";
|
|
21
33
|
|
|
22
34
|
const embed = new YakEmbed({
|
|
23
35
|
appId: "your-app-id",
|
|
36
|
+
mode: "both", // "chat" | "voice" | "both" — default "chat"
|
|
37
|
+
trigger: true, // render the floating launcher pill
|
|
24
38
|
theme: { position: "bottom-right", colorMode: "system" },
|
|
25
|
-
|
|
26
|
-
getConfig: async () =>
|
|
27
|
-
|
|
28
|
-
|
|
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}`);
|
|
39
|
+
// Routes + tools the assistant may use. Usually fetched from your server.
|
|
40
|
+
getConfig: async () => {
|
|
41
|
+
const res = await fetch("/api/yak");
|
|
42
|
+
return res.json(); // ChatConfig: { routes, tools? }
|
|
51
43
|
},
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
// Execute a tool the assistant decides to call.
|
|
45
|
+
onToolCall: async (name, args) => {
|
|
46
|
+
const res = await fetch("/api/yak", {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: { "Content-Type": "application/json" },
|
|
49
|
+
body: JSON.stringify({ name, args }),
|
|
50
|
+
});
|
|
51
|
+
const data = await res.json();
|
|
52
|
+
if (!data.ok) throw new Error(data.error);
|
|
53
|
+
return data.result;
|
|
54
54
|
},
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
embed.mount();
|
|
57
|
+
embed.mount(); // inject into the DOM
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Programmatic control
|
|
61
|
+
|
|
62
|
+
Every method works whether or not the trigger pill is shown — pass `trigger: false` to drive a fully custom UI.
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
// Chat
|
|
66
|
+
embed.open();
|
|
67
|
+
embed.close();
|
|
68
|
+
embed.toggle();
|
|
69
|
+
embed.openWithPrompt("How do I export my data?");
|
|
70
|
+
|
|
71
|
+
// Voice (requires mode "voice" or "both"; must be called from a user gesture)
|
|
72
|
+
await embed.voiceStart();
|
|
73
|
+
await embed.voiceStop();
|
|
74
|
+
await embed.voiceToggle();
|
|
75
|
+
|
|
76
|
+
// State
|
|
77
|
+
embed.getState(); // { isOpen, isReady, isLoading, isExpanded }
|
|
78
|
+
const stop = embed.onStateChange((s) => console.log(s.isLoading));
|
|
79
|
+
const stopVoice = embed.onVoiceStateChange((m) => console.log(m.state));
|
|
58
80
|
```
|
|
59
81
|
|
|
60
|
-
|
|
82
|
+
`isLoading` is `isOpen && !isReady` — true from the moment the panel opens until the iframe handshakes ready. Drive a custom loading spinner off it instead of re-deriving the condition. For voice, the equivalent "still spinning up" check is `getVoiceState().state === "connecting"`.
|
|
61
83
|
|
|
62
|
-
|
|
84
|
+
## API reference
|
|
85
|
+
|
|
86
|
+
### `new YakEmbed(config)`
|
|
87
|
+
|
|
88
|
+
**Config** (`YakEmbedConfig`):
|
|
89
|
+
|
|
90
|
+
| Option | Type | Default | Description |
|
|
91
|
+
| --- | --- | --- | --- |
|
|
92
|
+
| `appId` | `string` | — | Your Yak app ID (required). |
|
|
93
|
+
| `mode` | `"chat" \| "voice" \| "both"` | `"chat"` | Which surfaces the widget exposes. |
|
|
94
|
+
| `trigger` | `boolean \| TriggerButtonConfig` | `true` | Show the floating pill. `false` = headless. `TriggerButtonConfig` recolors it. |
|
|
95
|
+
| `theme` | `Theme` | — | Position, color mode, and colors. |
|
|
96
|
+
| `getConfig` | `ChatConfigProvider` | — | Async provider of `{ routes, tools? }`. Called on open and on each voice start. |
|
|
97
|
+
| `onToolCall` | `ToolCallHandler` | — | Executes a tool the assistant calls. Compose adapters with `createYakToolset`. |
|
|
98
|
+
| `onRedirect` | `(path: string) => void` | `window.location.assign` | Handle navigation requested by the assistant. |
|
|
99
|
+
| `onToolCallComplete` | `(event: ToolCallEvent) => void` | — | Fires after every tool call (use for cache invalidation). |
|
|
100
|
+
| `user` | `UserIdentity` | — | Signed end-user identity for server-side conversation persistence. See [end-user identity](https://docs.yak.io/docs/customization/end-user-identity). |
|
|
101
|
+
| `target` | `HTMLElement` | `document.body` | Where to mount the widget DOM. |
|
|
102
|
+
| `options.disableRestartButton` | `boolean` | `false` | Hide the restart-session button in the header. |
|
|
103
|
+
|
|
104
|
+
**Methods:** `mount()`, `destroy()`, `open()`, `close()`, `toggle()`, `openWithPrompt(prompt)`, `getState()`, `onStateChange(fn)`, `voiceStart()`, `voiceStop()`, `voiceToggle()`, `getVoiceState()`, `onVoiceStateChange(fn)`, `getClient()`, `getVoiceSession()`, `getMode()`.
|
|
105
|
+
|
|
106
|
+
### `Theme`
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
type Theme = {
|
|
110
|
+
position?: WidgetPosition; // default "bottom-left"
|
|
111
|
+
colorMode?: "light" | "dark" | "system";
|
|
112
|
+
displayMode?: "chatbox" | "drawer"; // floating panel vs full-height side drawer
|
|
113
|
+
fullscreen?: boolean;
|
|
114
|
+
light?: ThemeColors; // { background?, border?, messageBackground?, ... }
|
|
115
|
+
dark?: ThemeColors;
|
|
116
|
+
};
|
|
117
|
+
// WidgetPosition: top-left | top-center | top-right | left-center | right-center
|
|
118
|
+
// | bottom-left | bottom-center | bottom-right
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### `VoiceState` / `VoiceMachine`
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
type VoiceState = "idle" | "connecting" | "listening" | "thinking" | "speaking" | "error";
|
|
125
|
+
interface VoiceMachine { state: VoiceState; errorMessage?: string }
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### `YakClient` / `YakVoiceSession`
|
|
129
|
+
|
|
130
|
+
Headless building blocks used internally by `YakEmbed`. Reach for them only when composing a bespoke integration — most apps should use `YakEmbed`.
|
|
131
|
+
|
|
132
|
+
## Server-side handler
|
|
133
|
+
|
|
134
|
+
`@yak-io/javascript/server` builds a framework-agnostic `Request`/`Response` handler (Remix, Fastify, Hono, plain Node, …):
|
|
63
135
|
|
|
64
136
|
```ts
|
|
65
137
|
import { createYakHandler } from "@yak-io/javascript/server";
|
|
66
138
|
|
|
67
|
-
|
|
68
|
-
|
|
139
|
+
export const { GET, POST } = createYakHandler({
|
|
140
|
+
// GET returns the route + tool manifest the assistant sees.
|
|
69
141
|
routes: [
|
|
70
142
|
{ path: "/", title: "Home" },
|
|
71
143
|
{ path: "/tasks", title: "Tasks" },
|
|
72
144
|
],
|
|
145
|
+
// POST executes a tool call.
|
|
73
146
|
tools: {
|
|
74
147
|
getTools: async () => [
|
|
75
148
|
{
|
|
76
149
|
name: "tasks.list",
|
|
77
|
-
displayName: "List Tasks",
|
|
78
150
|
description: "Return all tasks",
|
|
79
151
|
inputSchema: { type: "object", properties: {} },
|
|
80
152
|
},
|
|
@@ -87,61 +159,17 @@ const { GET, POST } = createYakHandler({
|
|
|
87
159
|
});
|
|
88
160
|
```
|
|
89
161
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
### `YakEmbed`
|
|
93
|
-
|
|
94
|
-
High-level class that handles DOM rendering (panel, iframe, trigger button) and client wiring.
|
|
162
|
+
`routes` and `tools` each accept a single source or an array of sources, so you can compose filesystem routes with adapters like [`@yak-io/trpc`](https://docs.yak.io/docs/tool-adapters/trpc) or [`@yak-io/prismic`](https://docs.yak.io/docs/sdks/prismic).
|
|
95
163
|
|
|
96
|
-
|
|
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
|
|
164
|
+
## Logging
|
|
135
165
|
|
|
136
166
|
```ts
|
|
137
167
|
import { enableYakLogging, disableYakLogging, isYakLoggingEnabled } from "@yak-io/javascript";
|
|
138
168
|
|
|
139
|
-
enableYakLogging();
|
|
140
|
-
disableYakLogging(); // Turn off SDK logging
|
|
141
|
-
isYakLoggingEnabled(); // Returns current state
|
|
169
|
+
enableYakLogging(); // verbose SDK logs
|
|
142
170
|
```
|
|
143
171
|
|
|
144
|
-
|
|
172
|
+
To point the widget at a non-production chat UI (for example one running on `localhost`), pass the `origin` option: `new YakEmbed({ appId, origin: "http://localhost:3001" })`.
|
|
145
173
|
|
|
146
174
|
## Types
|
|
147
175
|
|
|
@@ -149,6 +177,16 @@ All types are exported from the package root:
|
|
|
149
177
|
|
|
150
178
|
```ts
|
|
151
179
|
import type {
|
|
180
|
+
YakEmbedConfig,
|
|
181
|
+
YakEmbedState,
|
|
182
|
+
YakClientConfig,
|
|
183
|
+
WidgetMode,
|
|
184
|
+
Theme,
|
|
185
|
+
ThemeColors,
|
|
186
|
+
WidgetPosition,
|
|
187
|
+
TriggerButtonConfig,
|
|
188
|
+
VoiceState,
|
|
189
|
+
VoiceMachine,
|
|
152
190
|
ChatConfig,
|
|
153
191
|
ChatConfigProvider,
|
|
154
192
|
RouteManifest,
|
|
@@ -157,25 +195,11 @@ import type {
|
|
|
157
195
|
ToolDefinition,
|
|
158
196
|
ToolCallHandler,
|
|
159
197
|
ToolCallEvent,
|
|
160
|
-
|
|
161
|
-
|
|
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,
|
|
198
|
+
ToolAdapter,
|
|
199
|
+
YakToolset,
|
|
176
200
|
} from "@yak-io/javascript";
|
|
177
201
|
```
|
|
178
202
|
|
|
179
203
|
## License
|
|
180
204
|
|
|
181
|
-
Proprietary — see LICENSE
|
|
205
|
+
Proprietary — see [LICENSE](./LICENSE).
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ChatConfig } from "./types/config.js";
|
|
2
2
|
import type { Theme, UserIdentity } from "./types/messaging.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ToolCallEventListener, ToolCallHandler } from "./types/tools.js";
|
|
4
4
|
declare global {
|
|
5
5
|
interface Window {
|
|
6
6
|
__YAK_INTERNAL_DEV__?: boolean;
|
|
@@ -9,6 +9,12 @@ declare global {
|
|
|
9
9
|
}
|
|
10
10
|
export interface YakClientConfig {
|
|
11
11
|
appId: string;
|
|
12
|
+
/**
|
|
13
|
+
* Override the origin the chat widget iframe loads from. Defaults to
|
|
14
|
+
* `https://chat.yak.io`. Most integrators never set this — it exists for
|
|
15
|
+
* non-production environments (e.g. a chat UI running on localhost).
|
|
16
|
+
*/
|
|
17
|
+
origin?: string;
|
|
12
18
|
/**
|
|
13
19
|
* Handler for tool calls from the chat widget.
|
|
14
20
|
* The consuming platform decides how to execute (browser, server fetch, etc.)
|
|
@@ -38,48 +44,6 @@ export interface YakClientConfig {
|
|
|
38
44
|
* ```
|
|
39
45
|
*/
|
|
40
46
|
onToolCall?: ToolCallHandler;
|
|
41
|
-
/**
|
|
42
|
-
* Handler for GraphQL schema-based tool calls.
|
|
43
|
-
* Called when the LLM generates a GraphQL request based on a provided schema.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* onGraphQLSchemaCall: async (schemaName, request) => {
|
|
48
|
-
* const res = await fetch("/graphql", {
|
|
49
|
-
* method: "POST",
|
|
50
|
-
* headers: { "Content-Type": "application/json" },
|
|
51
|
-
* body: JSON.stringify({
|
|
52
|
-
* query: request.query,
|
|
53
|
-
* variables: request.variables,
|
|
54
|
-
* }),
|
|
55
|
-
* });
|
|
56
|
-
* return res.json();
|
|
57
|
-
* }
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
onGraphQLSchemaCall?: GraphQLSchemaHandler;
|
|
61
|
-
/**
|
|
62
|
-
* Handler for REST/OpenAPI schema-based tool calls.
|
|
63
|
-
* Called when the LLM generates a REST request based on a provided schema.
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* onRESTSchemaCall: async (schemaName, request) => {
|
|
68
|
-
* const url = new URL(`https://api.example.com${request.path}`);
|
|
69
|
-
* if (request.query) {
|
|
70
|
-
* for (const [key, value] of Object.entries(request.query)) {
|
|
71
|
-
* url.searchParams.set(key, value);
|
|
72
|
-
* }
|
|
73
|
-
* }
|
|
74
|
-
* const res = await fetch(url.toString(), {
|
|
75
|
-
* method: request.method,
|
|
76
|
-
* body: request.body ? JSON.stringify(request.body) : undefined,
|
|
77
|
-
* });
|
|
78
|
-
* return res.json();
|
|
79
|
-
* }
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
onRESTSchemaCall?: RESTSchemaHandler;
|
|
83
47
|
theme?: Theme;
|
|
84
48
|
chatConfig?: ChatConfig;
|
|
85
49
|
onRedirect?: (path: string) => void;
|
|
@@ -139,8 +103,8 @@ export declare class YakClient {
|
|
|
139
103
|
constructor(config: YakClientConfig);
|
|
140
104
|
updateConfig(newConfig: Partial<YakClientConfig>): void;
|
|
141
105
|
/**
|
|
142
|
-
* Get the iframe origin URL (base URL for the chat widget)
|
|
143
|
-
*
|
|
106
|
+
* Get the iframe origin URL (base URL for the chat widget). Recomputed on
|
|
107
|
+
* each call so environment-dependent defaults resolve correctly.
|
|
144
108
|
*/
|
|
145
109
|
getIframeOrigin(): string;
|
|
146
110
|
/**
|
|
@@ -198,8 +162,6 @@ export declare class YakClient {
|
|
|
198
162
|
private sendConfigToIframe;
|
|
199
163
|
private sendPageContext;
|
|
200
164
|
private handleToolCall;
|
|
201
|
-
private handleGraphQLSchemaCall;
|
|
202
|
-
private handleRESTSchemaCall;
|
|
203
165
|
private sendToolResultToIframe;
|
|
204
166
|
/**
|
|
205
167
|
* Convert a value to a serializable form by stripping functions and other non-cloneable values.
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAGV,KAAK,EACL,YAAY,EACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAGV,KAAK,EACL,YAAY,EACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AA2D/E,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,oBAAoB,CAAC,EAAE,OAAO,CAAC;QAC/B,uBAAuB,CAAC,EAAE,OAAO,CAAC;KACnC;CACF;AAkBD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,M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C1B,OAAO,CAAC,eAAe;YAoBT,cAAc;IA4B5B,OAAO,CAAC,sBAAsB;IAuB9B;;;OAGG;IACH,OAAO,CAAC,cAAc;IAatB,OAAO,CAAC,mBAAmB;IAU3B;;;OAGG;IACH,OAAO,CAAC,iBAAiB;CAsB1B"}
|
package/dist/client.js
CHANGED
|
@@ -56,29 +56,20 @@ function clearStoredConversationPointer(appId) {
|
|
|
56
56
|
// localStorage can throw in private-browsing modes; silently ignore.
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
/** Production chat origin — where the widget iframe loads from by default. */
|
|
60
|
+
const DEFAULT_CHAT_ORIGIN = "https://chat.yak.io";
|
|
59
61
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* - Everything else (including external developers on localhost) -> https://chat.yak.io
|
|
62
|
+
* Resolves the iframe origin when no explicit `origin` is configured. Points at
|
|
63
|
+
* a local chat UI during yak's own local development; production otherwise.
|
|
64
|
+
* Integrators override the result with the `origin` config option.
|
|
64
65
|
*/
|
|
65
|
-
function
|
|
66
|
-
if (typeof window !== "undefined"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// Internal development only: localhost when running on a yak domain locally
|
|
73
|
-
// This is detected by checking if we're on localhost AND the referrer/opener is a yak domain
|
|
74
|
-
// For simplicity, we check if running on localhost with a specific dev flag
|
|
75
|
-
if ((hostname === "localhost" || hostname === "127.0.0.1") &&
|
|
76
|
-
typeof window.__YAK_INTERNAL_DEV__ !== "undefined") {
|
|
77
|
-
return "http://localhost:3001";
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// Default to production - external developers on localhost will connect to prod
|
|
81
|
-
return "https://chat.yak.io";
|
|
66
|
+
function getDefaultIframeOrigin() {
|
|
67
|
+
if (typeof window !== "undefined" &&
|
|
68
|
+
(window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") &&
|
|
69
|
+
typeof window.__YAK_INTERNAL_DEV__ !== "undefined") {
|
|
70
|
+
return "http://localhost:3001";
|
|
71
|
+
}
|
|
72
|
+
return DEFAULT_CHAT_ORIGIN;
|
|
82
73
|
}
|
|
83
74
|
export class YakClient {
|
|
84
75
|
config;
|
|
@@ -106,11 +97,11 @@ export class YakClient {
|
|
|
106
97
|
}
|
|
107
98
|
}
|
|
108
99
|
/**
|
|
109
|
-
* Get the iframe origin URL (base URL for the chat widget)
|
|
110
|
-
*
|
|
100
|
+
* Get the iframe origin URL (base URL for the chat widget). Recomputed on
|
|
101
|
+
* each call so environment-dependent defaults resolve correctly.
|
|
111
102
|
*/
|
|
112
103
|
getIframeOrigin() {
|
|
113
|
-
return
|
|
104
|
+
return this.config.origin ?? getDefaultIframeOrigin();
|
|
114
105
|
}
|
|
115
106
|
/**
|
|
116
107
|
* Get the full iframe embed URL for the chatbot
|
|
@@ -336,16 +327,6 @@ export class YakClient {
|
|
|
336
327
|
void this.handleToolCall(id, name, args);
|
|
337
328
|
break;
|
|
338
329
|
}
|
|
339
|
-
case "yak:graphql_schema_call": {
|
|
340
|
-
const { id, schemaName, request } = message.payload;
|
|
341
|
-
void this.handleGraphQLSchemaCall(id, schemaName, request);
|
|
342
|
-
break;
|
|
343
|
-
}
|
|
344
|
-
case "yak:rest_schema_call": {
|
|
345
|
-
const { id, schemaName, request } = message.payload;
|
|
346
|
-
void this.handleRESTSchemaCall(id, schemaName, request);
|
|
347
|
-
break;
|
|
348
|
-
}
|
|
349
330
|
case "yak:redirect": {
|
|
350
331
|
const { path } = message.payload;
|
|
351
332
|
logger.debug("Redirect request received:", path);
|
|
@@ -404,7 +385,6 @@ export class YakClient {
|
|
|
404
385
|
theme: this.config.theme,
|
|
405
386
|
toolManifest: this.config.chatConfig?.tools ?? undefined,
|
|
406
387
|
routeManifest: this.config.chatConfig?.routes ?? undefined,
|
|
407
|
-
schemaSources: this.config.chatConfig?.schemaSources ?? undefined,
|
|
408
388
|
options: this.config.options,
|
|
409
389
|
loggingEnabled,
|
|
410
390
|
user: this.config.user,
|
|
@@ -418,8 +398,6 @@ export class YakClient {
|
|
|
418
398
|
hasToolManifest: Boolean(this.config.chatConfig?.tools),
|
|
419
399
|
toolCount: this.config.chatConfig?.tools?.tools.length ?? 0,
|
|
420
400
|
hasRouteManifest: Boolean(this.config.chatConfig?.routes),
|
|
421
|
-
hasSchemaSources: Boolean(this.config.chatConfig?.schemaSources),
|
|
422
|
-
schemaCount: this.config.chatConfig?.schemaSources?.length ?? 0,
|
|
423
401
|
});
|
|
424
402
|
targetWindow.postMessage(configMessage, targetOrigin);
|
|
425
403
|
}
|
|
@@ -469,40 +447,6 @@ export class YakClient {
|
|
|
469
447
|
this.config.onToolCallComplete?.({ name, args, ok: false, error: errorMessage });
|
|
470
448
|
}
|
|
471
449
|
}
|
|
472
|
-
async handleGraphQLSchemaCall(id, schemaName, request) {
|
|
473
|
-
logger.debug(`GraphQL schema call received: ${schemaName}`, { id, request });
|
|
474
|
-
if (!this.config.onGraphQLSchemaCall) {
|
|
475
|
-
logger.error("GraphQL schema call received but no onGraphQLSchemaCall handler configured");
|
|
476
|
-
this.sendToolResultToIframe(id, false, undefined, "No GraphQL schema handler configured");
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
try {
|
|
480
|
-
const result = await this.config.onGraphQLSchemaCall(schemaName, request);
|
|
481
|
-
logger.debug(`GraphQL schema call succeeded: ${schemaName}`, { id });
|
|
482
|
-
this.sendToolResultToIframe(id, true, result);
|
|
483
|
-
}
|
|
484
|
-
catch (error) {
|
|
485
|
-
logger.error(`GraphQL schema call failed: ${schemaName}`, { id, error });
|
|
486
|
-
this.sendToolResultToIframe(id, false, undefined, this.extractErrorMessage(error));
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
async handleRESTSchemaCall(id, schemaName, request) {
|
|
490
|
-
logger.debug(`REST schema call received: ${schemaName}`, { id, request });
|
|
491
|
-
if (!this.config.onRESTSchemaCall) {
|
|
492
|
-
logger.error("REST schema call received but no onRESTSchemaCall handler configured");
|
|
493
|
-
this.sendToolResultToIframe(id, false, undefined, "No REST schema handler configured");
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
try {
|
|
497
|
-
const result = await this.config.onRESTSchemaCall(schemaName, request);
|
|
498
|
-
logger.debug(`REST schema call succeeded: ${schemaName}`, { id });
|
|
499
|
-
this.sendToolResultToIframe(id, true, result);
|
|
500
|
-
}
|
|
501
|
-
catch (error) {
|
|
502
|
-
logger.error(`REST schema call failed: ${schemaName}`, { id, error });
|
|
503
|
-
this.sendToolResultToIframe(id, false, undefined, this.extractErrorMessage(error));
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
450
|
sendToolResultToIframe(id, ok, result, error) {
|
|
507
451
|
if (!this.iframeWindow)
|
|
508
452
|
return;
|
package/dist/embed.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ import { YakClient, type YakClientConfig } from "./client.js";
|
|
|
2
2
|
import type { ChatConfigProvider } from "./types/config.js";
|
|
3
3
|
import { type VoiceMachine } from "./voice-machine.js";
|
|
4
4
|
import { type VoiceStateListener, YakVoiceSession } from "./voice-session.js";
|
|
5
|
+
/**
|
|
6
|
+
* Which experiences the widget exposes:
|
|
7
|
+
* - `chat` — chat icon only (opens the chat iframe panel). The default.
|
|
8
|
+
* - `voice` — voice icon only (starts a WebRTC voice session).
|
|
9
|
+
* - `both` — both icons, sharing one trigger pill.
|
|
10
|
+
*/
|
|
5
11
|
export type WidgetMode = "chat" | "voice" | "both";
|
|
6
12
|
export type TriggerButtonConfig = {
|
|
7
13
|
/** Custom color overrides for light mode */
|
|
@@ -38,8 +44,17 @@ export type YakEmbedConfig = YakClientConfig & {
|
|
|
38
44
|
getConfig?: ChatConfigProvider;
|
|
39
45
|
};
|
|
40
46
|
export type YakEmbedState = {
|
|
47
|
+
/** Whether the chat panel is open. */
|
|
41
48
|
isOpen: boolean;
|
|
49
|
+
/** Whether the chat iframe has handshaked and can receive messages. */
|
|
42
50
|
isReady: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Whether the chat is opening but not yet interactive — `isOpen && !isReady`.
|
|
53
|
+
* Stays true from the moment the panel opens until the iframe reports ready,
|
|
54
|
+
* so custom triggers can show a spinner without re-deriving it.
|
|
55
|
+
*/
|
|
56
|
+
isLoading: boolean;
|
|
57
|
+
/** Whether the panel is expanded to (near) full-screen. */
|
|
43
58
|
isExpanded: boolean;
|
|
44
59
|
};
|
|
45
60
|
export type YakEmbedStateListener = (state: YakEmbedState) => void;
|
package/dist/embed.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAyB,KAAK,YAAY,EAAmB,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EACL,KAAK,kBAAkB,EACvB,eAAe,EAEhB,MAAM,oBAAoB,CAAC;AAI5B,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAOnD,MAAM,MAAM,mBAAmB,GAAG;IAChC,4CAA4C;IAC5C,WAAW,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACvE,2CAA2C;IAC3C,UAAU,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACvE,CAAC;AAIF,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG;IAC7C,wEAAwE;IACxE,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,s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W,GAAG,IAAI;IA+CxC,mDAAmD;IAC5C,OAAO,IAAI,IAAI;IA6CtB,2EAA2E;IACpE,IAAI,IAAI,IAAI;IAkBnB,gFAAgF;IACzE,KAAK,IAAI,IAAI;IAQpB,0CAA0C;IACnC,MAAM,IAAI,IAAI;IAQrB,mDAAmD;IAC5C,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAM3C,oCAAoC;IAC7B,QAAQ,IAAI,aAAa;IAShC,mEAAmE;IAC5D,aAAa,CAAC,QAAQ,EAAE,qBAAqB,GAAG,MAAM,IAAI;IASjE,kEAAkE;IAC3D,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC,sCAAsC;IAC/B,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC,mDAAmD;IACtC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAUzC,sCAAsC;IAC/B,aAAa,IAAI,YAAY;IAIpC,wCAAwC;IACjC,kBAAkB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM,IAAI;IASnE,OAAO,CAAC,WAAW;IA4CnB,OAAO,CAAC,aAAa;IAsDrB,OAAO,CAAC,mBAAmB;IAuB3B,OAAO,CAAC,wBAAwB;IA2BhC,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,qBAAqB;IAa7B,OAAO,CAAC,sBAAsB;IAS9B,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,sBAAsB;IAS9B,OAAO,CAAC,eAAe;CAUxB"}
|
package/dist/embed.js
CHANGED
|
@@ -331,11 +331,12 @@ export class YakEmbed {
|
|
|
331
331
|
if (this.mode !== "chat") {
|
|
332
332
|
const voiceConfig = {
|
|
333
333
|
appId: config.appId,
|
|
334
|
+
// A single `origin` on the embed drives both surfaces: chat (iframe)
|
|
335
|
+
// and voice (mint endpoint).
|
|
336
|
+
apiOrigin: config.origin,
|
|
334
337
|
getConfig: config.getConfig,
|
|
335
338
|
chatConfig: config.chatConfig,
|
|
336
339
|
onToolCall: config.onToolCall,
|
|
337
|
-
onGraphQLSchemaCall: config.onGraphQLSchemaCall,
|
|
338
|
-
onRESTSchemaCall: config.onRESTSchemaCall,
|
|
339
340
|
onRedirect: config.onRedirect,
|
|
340
341
|
};
|
|
341
342
|
this.voice = new YakVoiceSession(voiceConfig);
|
|
@@ -483,7 +484,12 @@ export class YakEmbed {
|
|
|
483
484
|
}
|
|
484
485
|
/** Get the current widget state. */
|
|
485
486
|
getState() {
|
|
486
|
-
return {
|
|
487
|
+
return {
|
|
488
|
+
isOpen: this.isOpen,
|
|
489
|
+
isReady: this.isReady,
|
|
490
|
+
isLoading: this.isOpen && !this.isReady,
|
|
491
|
+
isExpanded: this.isExpanded,
|
|
492
|
+
};
|
|
487
493
|
}
|
|
488
494
|
/** Subscribe to state changes. Returns an unsubscribe function. */
|
|
489
495
|
onStateChange(listener) {
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export { YakClient } from "./client.js";
|
|
|
3
3
|
export type { TriggerButtonConfig, WidgetMode, YakEmbedConfig, YakEmbedState, YakEmbedStateListener, } from "./embed.js";
|
|
4
4
|
export { YakEmbed } from "./embed.js";
|
|
5
5
|
export { disableYakLogging, enableYakLogging, isYakLoggingEnabled, logger } from "./logger.js";
|
|
6
|
+
export type { YakServerAdapterConfig } from "./toolset.js";
|
|
7
|
+
export { createYakServerAdapter, createYakToolset } from "./toolset.js";
|
|
6
8
|
export * from "./types/config.js";
|
|
7
9
|
export * from "./types/messaging.js";
|
|
8
10
|
export * from "./types/routes.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,SAAS,EA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AAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { YakClient } from "./client.js";
|
|
|
5
5
|
export { YakEmbed } from "./embed.js";
|
|
6
6
|
// Logging utilities
|
|
7
7
|
export { disableYakLogging, enableYakLogging, isYakLoggingEnabled, logger } from "./logger.js";
|
|
8
|
+
export { createYakServerAdapter, createYakToolset } from "./toolset.js";
|
|
8
9
|
export * from "./types/config.js";
|
|
9
10
|
export * from "./types/messaging.js";
|
|
10
11
|
export * from "./types/routes.js";
|