@yak-io/angular 0.1.1 → 0.2.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 +188 -0
- package/dist/service.js +1 -1
- package/package.json +4 -4
- package/dist/internal/logger.d.ts +0 -2
- package/dist/internal/logger.d.ts.map +0 -1
- package/dist/internal/logger.js +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# @yak-io/angular
|
|
2
|
+
|
|
3
|
+
Angular integration for the Yak embeddable chat widget. Uses a factory function compatible with Angular's component and service patterns.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @yak-io/angular
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
### 1. Initialize in your root component
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// app.component.ts
|
|
17
|
+
import { Component, OnInit, OnDestroy, inject } from "@angular/core";
|
|
18
|
+
import { Router } from "@angular/router";
|
|
19
|
+
import { createYakProvider, type YakApi } from "@yak-io/angular";
|
|
20
|
+
import { environment } from "../environments/environment";
|
|
21
|
+
|
|
22
|
+
@Component({
|
|
23
|
+
selector: "app-root",
|
|
24
|
+
standalone: true,
|
|
25
|
+
template: "<router-outlet />",
|
|
26
|
+
})
|
|
27
|
+
export class AppComponent implements OnInit, OnDestroy {
|
|
28
|
+
private router = inject(Router);
|
|
29
|
+
private yak: YakApi;
|
|
30
|
+
|
|
31
|
+
constructor() {
|
|
32
|
+
this.yak = createYakProvider({
|
|
33
|
+
appId: environment.yakAppId,
|
|
34
|
+
theme: { position: "bottom-right", colorMode: "system" },
|
|
35
|
+
trigger: { label: "Ask with AI" },
|
|
36
|
+
getConfig: async () => {
|
|
37
|
+
const res = await fetch("/api/yak");
|
|
38
|
+
return res.json();
|
|
39
|
+
},
|
|
40
|
+
onToolCall: async (name, args) => {
|
|
41
|
+
const res = await fetch("/api/yak", {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: { "Content-Type": "application/json" },
|
|
44
|
+
body: JSON.stringify({ name, args }),
|
|
45
|
+
});
|
|
46
|
+
const data = await res.json();
|
|
47
|
+
if (!data.ok) throw new Error(data.error);
|
|
48
|
+
return data.result;
|
|
49
|
+
},
|
|
50
|
+
onRedirect: (path) => {
|
|
51
|
+
this.router.navigateByUrl(path);
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
ngOnInit() {
|
|
57
|
+
this.yak.mount();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
ngOnDestroy() {
|
|
61
|
+
this.yak.destroy();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 2. Share via an Angular service
|
|
67
|
+
|
|
68
|
+
Create a service to share the widget API across components:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
// yak.service.ts
|
|
72
|
+
import { Injectable, signal } from "@angular/core";
|
|
73
|
+
import type { YakApi } from "@yak-io/angular";
|
|
74
|
+
|
|
75
|
+
@Injectable({ providedIn: "root" })
|
|
76
|
+
export class YakService {
|
|
77
|
+
private yak: YakApi | null = null;
|
|
78
|
+
readonly isOpen = signal(false);
|
|
79
|
+
readonly isReady = signal(false);
|
|
80
|
+
|
|
81
|
+
setYak(yak: YakApi) {
|
|
82
|
+
this.yak = yak;
|
|
83
|
+
yak.subscribeToState(({ isOpen, isReady }) => {
|
|
84
|
+
this.isOpen.set(isOpen);
|
|
85
|
+
this.isReady.set(isReady);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
open() { this.yak?.open(); }
|
|
90
|
+
close() { this.yak?.close(); }
|
|
91
|
+
openWithPrompt(prompt: string) { this.yak?.openWithPrompt(prompt); }
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 3. Use in components
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
// any.component.ts
|
|
99
|
+
import { Component, inject } from "@angular/core";
|
|
100
|
+
import { YakService } from "./yak.service";
|
|
101
|
+
|
|
102
|
+
@Component({
|
|
103
|
+
template: `
|
|
104
|
+
<button (click)="yakService.open()">Open Chat</button>
|
|
105
|
+
<p *ngIf="yakService.isOpen()">Chat is open</p>
|
|
106
|
+
`,
|
|
107
|
+
})
|
|
108
|
+
export class AnyComponent {
|
|
109
|
+
yakService = inject(YakService);
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## API Reference
|
|
114
|
+
|
|
115
|
+
### `createYakProvider(options)`
|
|
116
|
+
|
|
117
|
+
Creates a Yak widget instance. Returns a `YakApi` object.
|
|
118
|
+
|
|
119
|
+
Call `yak.mount()` in `ngOnInit()` and `yak.destroy()` in `ngOnDestroy()`.
|
|
120
|
+
|
|
121
|
+
**Options:**
|
|
122
|
+
|
|
123
|
+
| Option | Type | Description |
|
|
124
|
+
|--------|------|-------------|
|
|
125
|
+
| `appId` | `string` | Your Yak app ID |
|
|
126
|
+
| `getConfig` | `ChatConfigProvider` | Async function returning routes + tools. Called on first open. |
|
|
127
|
+
| `onToolCall` | `ToolCallHandler` | Handle tool invocations from the assistant |
|
|
128
|
+
| `onGraphQLSchemaCall` | `GraphQLSchemaHandler` | Handle GraphQL schema tool calls |
|
|
129
|
+
| `onRESTSchemaCall` | `RESTSchemaHandler` | Handle REST/OpenAPI schema tool calls |
|
|
130
|
+
| `theme` | `Theme` | Position, color mode, and custom colors |
|
|
131
|
+
| `onRedirect` | `(path: string) => void` | Navigation handler (defaults to `window.location.assign`) |
|
|
132
|
+
| `disableRestartButton` | `boolean` | Hide the restart session button |
|
|
133
|
+
| `trigger` | `boolean \| TriggerButtonConfig` | Built-in trigger button |
|
|
134
|
+
|
|
135
|
+
### `YakApi`
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
type YakApi = {
|
|
139
|
+
readonly isOpen: boolean; // Plain boolean (use subscribeToState for reactivity)
|
|
140
|
+
readonly isReady: boolean; // Plain boolean
|
|
141
|
+
open: () => void;
|
|
142
|
+
close: () => void;
|
|
143
|
+
openWithPrompt: (prompt: string) => void;
|
|
144
|
+
subscribeToToolEvents: (handler: ToolCallEventHandler) => () => void;
|
|
145
|
+
subscribeToState: (handler: (state: { isOpen: boolean; isReady: boolean }) => void) => () => void;
|
|
146
|
+
mount: () => void; // Call in ngOnInit() or ngAfterViewInit()
|
|
147
|
+
destroy: () => void; // Call in ngOnDestroy()
|
|
148
|
+
};
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Use `subscribeToState` to react to state changes — wire it to Angular signals, `BehaviorSubject`s, or change detection:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
yak.subscribeToState(({ isOpen, isReady }) => {
|
|
155
|
+
this.isOpen.set(isOpen);
|
|
156
|
+
this.changeDetector.markForCheck();
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Logging
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
import { enableYakLogging, disableYakLogging, isYakLoggingEnabled } from "@yak-io/angular";
|
|
164
|
+
|
|
165
|
+
enableYakLogging(); // Enable verbose SDK logs
|
|
166
|
+
disableYakLogging(); // Disable SDK logs
|
|
167
|
+
isYakLoggingEnabled(); // → boolean
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Types
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
import type {
|
|
174
|
+
YakProviderOptions,
|
|
175
|
+
YakApi,
|
|
176
|
+
ToolCallEventHandler,
|
|
177
|
+
ChatConfigProvider,
|
|
178
|
+
ToolCallHandler,
|
|
179
|
+
ToolCallEvent,
|
|
180
|
+
Theme,
|
|
181
|
+
TriggerButtonConfig,
|
|
182
|
+
WidgetPosition,
|
|
183
|
+
} from "@yak-io/angular";
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## License
|
|
187
|
+
|
|
188
|
+
Proprietary — see LICENSE file.
|
package/dist/service.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { YakEmbed, } from "@yak-io/javascript";
|
|
2
|
-
import { logger } from "
|
|
2
|
+
import { logger } from "@yak-io/javascript";
|
|
3
3
|
// ── Provider factory ────────────────────────────────────────────────────────
|
|
4
4
|
/**
|
|
5
5
|
* Creates a yak chat widget instance for Angular.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yak-io/angular",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Angular SDK for embedding yak chatbot",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -41,13 +41,13 @@
|
|
|
41
41
|
"./package.json": "./package.json"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@yak-io/javascript": "0.
|
|
44
|
+
"@yak-io/javascript": "0.7.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@angular/core": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
47
|
+
"@angular/core": "^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@types/node": "^24.
|
|
50
|
+
"@types/node": "^24.12.0",
|
|
51
51
|
"typescript": "^5.3.0",
|
|
52
52
|
"@repo/typescript-config": "0.0.0"
|
|
53
53
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/internal/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/internal/logger.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { logger } from "@yak-io/javascript";
|