@yak-io/angular 0.2.0 → 0.3.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/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/service.d.ts +15 -35
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +36 -32
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
export type { ChatConfigProvider, GraphQLRequest, GraphQLSchemaHandler, GraphQLSchemaSource, OpenAPISchemaSource, RESTRequest, RESTSchemaHandler, SchemaSource, Theme, ThemeColors, ToolCallEvent, ToolCallHandler, TriggerButtonConfig, VoiceMachine, VoiceState, WidgetMode, WidgetPosition, } from "@yak-io/javascript";
|
|
2
|
+
export { disableYakLogging, enableYakLogging, isYakLoggingEnabled } from "@yak-io/javascript";
|
|
3
|
+
export type { ToolCallEventHandler, YakApi, YakProviderOptions, YakState, } from "./service.js";
|
|
1
4
|
export { createYakProvider } from "./service.js";
|
|
2
|
-
export type { YakProviderOptions, YakApi, ToolCallEventHandler } from "./service.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
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,KAAK,EACL,WAAW,EACX,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,UAAU,EACV,UAAU,EACV,cAAc,GACf,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9F,YAAY,EACV,oBAAoB,EACpB,MAAM,EACN,kBAAkB,EAClB,QAAQ,GACT,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Public API
|
|
2
|
-
export { createYakProvider } from "./service.js";
|
|
3
2
|
// Re-export logging utilities
|
|
4
|
-
export {
|
|
3
|
+
export { disableYakLogging, enableYakLogging, isYakLoggingEnabled } from "@yak-io/javascript";
|
|
4
|
+
export { createYakProvider } from "./service.js";
|
package/dist/service.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ChatConfigProvider, type GraphQLSchemaHandler, type RESTSchemaHandler, type Theme, type ToolCallEvent, type ToolCallHandler, type TriggerButtonConfig, type VoiceMachine, type WidgetMode } from "@yak-io/javascript";
|
|
2
2
|
export type ToolCallEventHandler = (event: ToolCallEvent) => void;
|
|
3
3
|
export type YakProviderOptions = {
|
|
4
4
|
appId: string;
|
|
5
|
+
mode?: WidgetMode;
|
|
5
6
|
getConfig?: ChatConfigProvider;
|
|
6
7
|
onToolCall?: ToolCallHandler;
|
|
7
8
|
onGraphQLSchemaCall?: GraphQLSchemaHandler;
|
|
@@ -11,51 +12,30 @@ export type YakProviderOptions = {
|
|
|
11
12
|
disableRestartButton?: boolean;
|
|
12
13
|
trigger?: boolean | TriggerButtonConfig;
|
|
13
14
|
};
|
|
15
|
+
export type YakState = {
|
|
16
|
+
isOpen: boolean;
|
|
17
|
+
isReady: boolean;
|
|
18
|
+
voiceMachine: VoiceMachine;
|
|
19
|
+
};
|
|
14
20
|
export type YakApi = {
|
|
15
|
-
/** Whether the chat widget is open */
|
|
16
21
|
readonly isOpen: boolean;
|
|
17
|
-
/** Whether the iframe is ready */
|
|
18
22
|
readonly isReady: boolean;
|
|
19
|
-
|
|
23
|
+
readonly voiceMachine: VoiceMachine;
|
|
20
24
|
open: () => void;
|
|
21
|
-
/** Close the chat widget */
|
|
22
25
|
close: () => void;
|
|
23
|
-
/** Open the chat widget and send a prompt */
|
|
24
26
|
openWithPrompt: (prompt: string) => void;
|
|
25
|
-
|
|
27
|
+
voiceStart: () => Promise<void>;
|
|
28
|
+
voiceStop: () => Promise<void>;
|
|
29
|
+
voiceToggle: () => Promise<void>;
|
|
26
30
|
subscribeToToolEvents: (handler: ToolCallEventHandler) => () => void;
|
|
27
|
-
/** Subscribe to
|
|
28
|
-
subscribeToState: (handler: (state:
|
|
29
|
-
isOpen: boolean;
|
|
30
|
-
isReady: boolean;
|
|
31
|
-
}) => void) => () => void;
|
|
32
|
-
/** Mount the widget DOM — call in ngOnInit or ngAfterViewInit */
|
|
31
|
+
/** Subscribe to chat + voice state changes. */
|
|
32
|
+
subscribeToState: (handler: (state: YakState) => void) => () => void;
|
|
33
33
|
mount: () => void;
|
|
34
|
-
/** Destroy the widget DOM — call in ngOnDestroy */
|
|
35
34
|
destroy: () => void;
|
|
36
35
|
};
|
|
37
36
|
/**
|
|
38
|
-
* Creates a yak chat
|
|
39
|
-
*
|
|
40
|
-
* and `destroy()` in `ngOnDestroy`.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* import { Component, OnInit, OnDestroy } from "@angular/core";
|
|
45
|
-
* import { createYakProvider, type YakApi } from "@yak-io/angular";
|
|
46
|
-
*
|
|
47
|
-
* @Component({ selector: "app-root", template: `...` })
|
|
48
|
-
* export class AppComponent implements OnInit, OnDestroy {
|
|
49
|
-
* private yak: YakApi;
|
|
50
|
-
*
|
|
51
|
-
* constructor() {
|
|
52
|
-
* this.yak = createYakProvider({ appId: "my-app" });
|
|
53
|
-
* }
|
|
54
|
-
*
|
|
55
|
-
* ngOnInit() { this.yak.mount(); }
|
|
56
|
-
* ngOnDestroy() { this.yak.destroy(); }
|
|
57
|
-
* }
|
|
58
|
-
* ```
|
|
37
|
+
* Creates a yak widget (chat + voice) for Angular.
|
|
38
|
+
* Call `mount()` in `ngOnInit` and `destroy()` in `ngOnDestroy`.
|
|
59
39
|
*/
|
|
60
40
|
export declare function createYakProvider(options: YakProviderOptions): YakApi;
|
|
61
41
|
//# sourceMappingURL=service.d.ts.map
|
package/dist/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAGzB,KAAK,iBAAiB,EACtB,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,UAAU,EAEhB,MAAM,oBAAoB,CAAC;AAI5B,MAAM,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;AAElE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,mBAAmB,CAAC,EAAE,oBAAoB,CAAC;IAC3C,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;IACrC,KAAK,CAAC,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logger } from "@yak-io/javascript";
|
|
1
|
+
import { INITIAL_VOICE_MACHINE, logger, YakEmbed, } from "@yak-io/javascript";
|
|
3
2
|
// ── Provider factory ────────────────────────────────────────────────────────
|
|
4
3
|
/**
|
|
5
|
-
* Creates a yak chat
|
|
6
|
-
*
|
|
7
|
-
* and `destroy()` in `ngOnDestroy`.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { Component, OnInit, OnDestroy } from "@angular/core";
|
|
12
|
-
* import { createYakProvider, type YakApi } from "@yak-io/angular";
|
|
13
|
-
*
|
|
14
|
-
* @Component({ selector: "app-root", template: `...` })
|
|
15
|
-
* export class AppComponent implements OnInit, OnDestroy {
|
|
16
|
-
* private yak: YakApi;
|
|
17
|
-
*
|
|
18
|
-
* constructor() {
|
|
19
|
-
* this.yak = createYakProvider({ appId: "my-app" });
|
|
20
|
-
* }
|
|
21
|
-
*
|
|
22
|
-
* ngOnInit() { this.yak.mount(); }
|
|
23
|
-
* ngOnDestroy() { this.yak.destroy(); }
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
4
|
+
* Creates a yak widget (chat + voice) for Angular.
|
|
5
|
+
* Call `mount()` in `ngOnInit` and `destroy()` in `ngOnDestroy`.
|
|
26
6
|
*/
|
|
27
7
|
export function createYakProvider(options) {
|
|
28
8
|
let _isOpen = false;
|
|
29
9
|
let _isReady = false;
|
|
10
|
+
let _voiceMachine = INITIAL_VOICE_MACHINE;
|
|
30
11
|
const toolEventSubscribers = new Set();
|
|
31
12
|
const stateSubscribers = new Set();
|
|
13
|
+
const notifyState = () => {
|
|
14
|
+
const snap = { isOpen: _isOpen, isReady: _isReady, voiceMachine: _voiceMachine };
|
|
15
|
+
for (const subscriber of stateSubscribers) {
|
|
16
|
+
try {
|
|
17
|
+
subscriber(snap);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
logger.warn("Error in state subscriber:", err);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
32
24
|
const handleToolCallComplete = (event) => {
|
|
33
25
|
logger.debug("Tool call completed, notifying subscribers:", {
|
|
34
26
|
name: event.name,
|
|
@@ -48,8 +40,10 @@ export function createYakProvider(options) {
|
|
|
48
40
|
(typeof window !== "undefined" ? (path) => window.location.assign(path) : undefined);
|
|
49
41
|
const embed = new YakEmbed({
|
|
50
42
|
appId: options.appId,
|
|
43
|
+
mode: options.mode,
|
|
51
44
|
theme: options.theme,
|
|
52
45
|
trigger: options.trigger ?? false,
|
|
46
|
+
getConfig: options.getConfig,
|
|
53
47
|
onToolCall: options.onToolCall,
|
|
54
48
|
onGraphQLSchemaCall: options.onGraphQLSchemaCall,
|
|
55
49
|
onRESTSchemaCall: options.onRESTSchemaCall,
|
|
@@ -57,18 +51,14 @@ export function createYakProvider(options) {
|
|
|
57
51
|
options: { disableRestartButton: options.disableRestartButton },
|
|
58
52
|
onToolCallComplete: handleToolCallComplete,
|
|
59
53
|
});
|
|
60
|
-
// Sync embed state
|
|
61
54
|
embed.onStateChange((state) => {
|
|
62
55
|
_isOpen = state.isOpen;
|
|
63
56
|
_isReady = state.isReady;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
logger.warn("Error in state subscriber:", err);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
57
|
+
notifyState();
|
|
58
|
+
});
|
|
59
|
+
embed.onVoiceStateChange((m) => {
|
|
60
|
+
_voiceMachine = m;
|
|
61
|
+
notifyState();
|
|
72
62
|
});
|
|
73
63
|
// Fetch chat config on first open
|
|
74
64
|
if (options.getConfig) {
|
|
@@ -90,6 +80,14 @@ export function createYakProvider(options) {
|
|
|
90
80
|
}
|
|
91
81
|
});
|
|
92
82
|
}
|
|
83
|
+
const voiceStart = async () => {
|
|
84
|
+
try {
|
|
85
|
+
await embed.voiceStart();
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
logger.warn("Voice start failed", err);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
93
91
|
return {
|
|
94
92
|
get isOpen() {
|
|
95
93
|
return _isOpen;
|
|
@@ -97,9 +95,15 @@ export function createYakProvider(options) {
|
|
|
97
95
|
get isReady() {
|
|
98
96
|
return _isReady;
|
|
99
97
|
},
|
|
98
|
+
get voiceMachine() {
|
|
99
|
+
return _voiceMachine;
|
|
100
|
+
},
|
|
100
101
|
open: () => embed.open(),
|
|
101
102
|
close: () => embed.close(),
|
|
102
103
|
openWithPrompt: (prompt) => embed.openWithPrompt(prompt),
|
|
104
|
+
voiceStart,
|
|
105
|
+
voiceStop: () => embed.voiceStop(),
|
|
106
|
+
voiceToggle: () => embed.voiceToggle(),
|
|
103
107
|
subscribeToToolEvents: (handler) => {
|
|
104
108
|
toolEventSubscribers.add(handler);
|
|
105
109
|
return () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yak-io/angular",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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.8.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
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.12.
|
|
50
|
+
"@types/node": "^24.12.4",
|
|
51
51
|
"typescript": "^5.3.0",
|
|
52
52
|
"@repo/typescript-config": "0.0.0"
|
|
53
53
|
},
|