@wildix/wilma-copilot-headless 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.
@@ -0,0 +1,80 @@
1
+ import { type WilmaAssistantClient } from '@wildix/wilma-assistant-client';
2
+ import { type CopilotAlert, type CopilotRelationshipHandle, type CopilotSessionStreamHandle, type CopilotSmartActionEntry, type CopilotUiState } from '@wildix/wilma-copilot-core';
3
+ import { type CopilotContextLookup, type CopilotSessionEvent, type CopilotSessionSummary, type WilmaCopilotSessionsClient } from '@wildix/wilma-copilot-sessions-client';
4
+ export interface CopilotDependencies {
5
+ copilotClient: WilmaCopilotSessionsClient;
6
+ onError?: (error: unknown) => void;
7
+ }
8
+ export interface UseCopilotRelationshipOptions extends CopilotDependencies {
9
+ lookup?: CopilotContextLookup;
10
+ enabled?: boolean;
11
+ sessionsLimit?: number;
12
+ }
13
+ export declare function useCopilotRelationship({ copilotClient, lookup, enabled, sessionsLimit, onError, }: UseCopilotRelationshipOptions): CopilotRelationshipHandle;
14
+ export type CopilotEventStream = (sessionId: string, startIndex: number, signal: AbortSignal) => AsyncIterable<CopilotSessionEvent>;
15
+ export interface UseCopilotSessionStreamOptions extends CopilotDependencies {
16
+ sessionId?: string;
17
+ live?: boolean;
18
+ streamEvents?: CopilotEventStream;
19
+ onRelationship?: (sessionId: string | undefined) => void;
20
+ }
21
+ export declare function useCopilotSessionStream({ copilotClient, sessionId, live, streamEvents, onRelationship, onError, }: UseCopilotSessionStreamOptions): CopilotSessionStreamHandle;
22
+ export interface UseCopilotAskOptions extends CopilotDependencies {
23
+ assistantClient: WilmaAssistantClient;
24
+ copilotSessionId?: string;
25
+ }
26
+ export declare function useCopilotAsk({ assistantClient, copilotClient, copilotSessionId, onError }: UseCopilotAskOptions): {
27
+ ask: (question: string) => Promise<string | undefined>;
28
+ isAsking: boolean;
29
+ };
30
+ export interface UseCopilotActionsOptions extends CopilotDependencies {
31
+ sessionId?: string;
32
+ /**
33
+ * Opens the URL of an `openUrl` smart action. Navigation belongs to the host, so the
34
+ * SDK reports the invocation and leaves the window to the app.
35
+ */
36
+ onOpenUrl?: (url: string, openInNewTab: boolean) => void;
37
+ }
38
+ export interface CopilotActionsHandle {
39
+ /** Keys of the smart actions this client already invoked, for the muted styling. */
40
+ usedKeys: ReadonlySet<string>;
41
+ runSmartAction: (entry: CopilotSmartActionEntry) => Promise<void>;
42
+ searchKnowledge: (questionId: string, question?: string) => Promise<void>;
43
+ }
44
+ /**
45
+ * The two members of `CopilotClientAction`. Both are accepted into the session mailbox,
46
+ * so the outcome arrives as an `action` event rather than from the call itself.
47
+ */
48
+ export declare function useCopilotActions({ copilotClient, sessionId, onOpenUrl, onError, }: UseCopilotActionsOptions): CopilotActionsHandle;
49
+ export interface UseCopilotAlertsOptions {
50
+ state: CopilotUiState;
51
+ /** True while recorded events are replaying. Those are history, and history never alerts. */
52
+ isLoading?: boolean;
53
+ /** Called once per batch of alerts that arrived live, oldest first. */
54
+ onAlert?: (alerts: CopilotAlert[]) => void;
55
+ }
56
+ export interface CopilotAlertsHandle {
57
+ /** Alerts seen since the last `clear`, oldest first. Drives an unread badge. */
58
+ unseen: CopilotAlert[];
59
+ clear: () => void;
60
+ }
61
+ /**
62
+ * Watches a session for the few things worth interrupting for (`collectCopilotAlerts`).
63
+ *
64
+ * The point of the hook is the baseline. A session is rehydrated by replaying its
65
+ * recorded events, so a panel opened next to a call that has been running for ten
66
+ * minutes sees every earlier detection arrive at once — and firing a notification for
67
+ * each would be both wrong and unbearable. Everything present when the stream settles
68
+ * is therefore marked seen without alerting, and only what arrives afterwards is news.
69
+ */
70
+ export declare function useCopilotAlerts({ state, isLoading, onAlert }: UseCopilotAlertsOptions): CopilotAlertsHandle;
71
+ export declare function useCopilotRecentSessions(options: CopilotDependencies & {
72
+ enabled?: boolean;
73
+ limit?: number;
74
+ }): {
75
+ sessions: CopilotSessionSummary[];
76
+ isLoading: boolean;
77
+ error?: Error;
78
+ refresh: () => void;
79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AuE;IACvE,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,mBAAmB;IAClC,gFAAgF;IAChF,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,EAAC,KAAK,EAAE,SAAiB,EAAE,OAAO,EAAC,EAAE,uBAAuB,GAAG,mBAAmB,CAsBlH;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,mBAAmB,GAAG;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAC,GAAG;IAC5G,QAAQ,EAAE,qBAAqB,EAAE,CAAC;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAgCA"}
package/dist/hooks.js ADDED
@@ -0,0 +1,257 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { StartSessionCommand } from '@wildix/wilma-assistant-client';
3
+ import { asRecord, collectCopilotAlerts, getCopilotEventIndex, getSmartActionType, initialCopilotUiState, reduceCopilotEvent, sortSessionsRecentFirst, } from '@wildix/wilma-copilot-core';
4
+ import { ActCommand, AskCommand, EnrichCommand, GetSessionEventsCommand, ListRelationshipSessionsCommand, ListSessionsCommand, OpenCommand, } from '@wildix/wilma-copilot-sessions-client';
5
+ const PAGE_LIMIT = 1000;
6
+ function lookupKey(lookup) {
7
+ return JSON.stringify(lookup ?? {});
8
+ }
9
+ export function useCopilotRelationship({ copilotClient, lookup, enabled = true, sessionsLimit = 50, onError, }) {
10
+ const [relationshipId, setRelationshipId] = useState();
11
+ const [defaultSessionId, setDefaultSessionId] = useState();
12
+ const [sessions, setSessions] = useState([]);
13
+ const [isLoading, setIsLoading] = useState(enabled);
14
+ const [error, setError] = useState();
15
+ const [attempt, setAttempt] = useState(0);
16
+ const relationshipRef = useRef(undefined);
17
+ const openedLookupRef = useRef(undefined);
18
+ relationshipRef.current = relationshipId;
19
+ const loadSessions = useCallback(async (id, signal) => {
20
+ const result = await copilotClient.send(new ListRelationshipSessionsCommand({ relationshipId: id, limit: sessionsLimit }), signal ? { abortSignal: signal } : undefined);
21
+ if (!signal?.aborted)
22
+ setSessions(sortSessionsRecentFirst(result.sessions ?? []));
23
+ }, [copilotClient, sessionsLimit]);
24
+ const refresh = useCallback(() => {
25
+ if (relationshipRef.current)
26
+ void loadSessions(relationshipRef.current).catch(onError);
27
+ }, [loadSessions, onError]);
28
+ const retry = useCallback(() => {
29
+ setError(undefined);
30
+ setAttempt((value) => value + 1);
31
+ }, []);
32
+ useEffect(() => {
33
+ if (!enabled)
34
+ return;
35
+ const abort = new AbortController();
36
+ setIsLoading(true);
37
+ void (async () => {
38
+ try {
39
+ const result = await copilotClient.send(new OpenCommand({ lookup }), { abortSignal: abort.signal });
40
+ if (abort.signal.aborted)
41
+ return;
42
+ openedLookupRef.current = lookupKey(lookup);
43
+ setRelationshipId(result.relationshipId);
44
+ setDefaultSessionId(result.session.id);
45
+ await loadSessions(result.relationshipId, abort.signal);
46
+ setError(undefined);
47
+ }
48
+ catch (cause) {
49
+ if (!abort.signal.aborted) {
50
+ const next = cause instanceof Error ? cause : new Error(String(cause));
51
+ setError(next);
52
+ onError?.(cause);
53
+ }
54
+ }
55
+ finally {
56
+ if (!abort.signal.aborted)
57
+ setIsLoading(false);
58
+ }
59
+ })();
60
+ return () => abort.abort();
61
+ }, [attempt, copilotClient, enabled, loadSessions, onError]);
62
+ const key = lookupKey(lookup);
63
+ useEffect(() => {
64
+ const currentId = relationshipRef.current;
65
+ if (!enabled || !currentId || openedLookupRef.current === undefined || openedLookupRef.current === key)
66
+ return;
67
+ openedLookupRef.current = key;
68
+ void copilotClient
69
+ .send(new EnrichCommand({ relationshipId: currentId, lookup: lookup }))
70
+ .then((result) => {
71
+ setRelationshipId(result.relationshipId);
72
+ setSessions(sortSessionsRecentFirst(result.related ?? []));
73
+ })
74
+ .catch(onError);
75
+ }, [copilotClient, enabled, key, lookup, onError]);
76
+ return { relationshipId, sessions, defaultSessionId, isLoading, error, retry, refresh };
77
+ }
78
+ export function useCopilotSessionStream({ copilotClient, sessionId, live = true, streamEvents, onRelationship, onError, }) {
79
+ const [state, setState] = useState(initialCopilotUiState);
80
+ const [isLoading, setIsLoading] = useState(Boolean(sessionId));
81
+ const [error, setError] = useState();
82
+ useEffect(() => {
83
+ if (!sessionId) {
84
+ setState(initialCopilotUiState);
85
+ setIsLoading(false);
86
+ return;
87
+ }
88
+ const abort = new AbortController();
89
+ let nextIndex = 0;
90
+ setState(initialCopilotUiState);
91
+ setIsLoading(true);
92
+ setError(undefined);
93
+ const apply = (event) => {
94
+ nextIndex = Math.max(nextIndex, getCopilotEventIndex(event) + 1);
95
+ if (event.relationship)
96
+ onRelationship?.(event.relationship.sessionId);
97
+ setState((current) => reduceCopilotEvent(current, event));
98
+ };
99
+ const replay = async (startIndex = 0) => {
100
+ const output = await copilotClient.send(new GetSessionEventsCommand({ sessionId, startIndex, limit: PAGE_LIMIT }), {
101
+ abortSignal: abort.signal,
102
+ });
103
+ for (const event of output.events ?? []) {
104
+ apply(event);
105
+ }
106
+ if (output.nextStartIndex != null && !abort.signal.aborted) {
107
+ await replay(output.nextStartIndex);
108
+ }
109
+ };
110
+ void (async () => {
111
+ try {
112
+ await replay();
113
+ setIsLoading(false);
114
+ if (live && streamEvents && !abort.signal.aborted) {
115
+ for await (const event of streamEvents(sessionId, nextIndex, abort.signal))
116
+ apply(event);
117
+ }
118
+ }
119
+ catch (cause) {
120
+ if (!abort.signal.aborted) {
121
+ setError(cause instanceof Error ? cause : new Error(String(cause)));
122
+ onError?.(cause);
123
+ }
124
+ }
125
+ finally {
126
+ if (!abort.signal.aborted)
127
+ setIsLoading(false);
128
+ }
129
+ })();
130
+ return () => abort.abort();
131
+ }, [copilotClient, live, onError, onRelationship, sessionId, streamEvents]);
132
+ return { state, isLoading, error };
133
+ }
134
+ export function useCopilotAsk({ assistantClient, copilotClient, copilotSessionId, onError }) {
135
+ const [isAsking, setIsAsking] = useState(false);
136
+ const ask = useCallback(async (question) => {
137
+ const message = question.trim();
138
+ if (!message || !copilotSessionId)
139
+ return undefined;
140
+ setIsAsking(true);
141
+ try {
142
+ const started = await assistantClient.send(new StartSessionCommand({
143
+ message,
144
+ visibility: 'hidden',
145
+ target: `copilot://sessions/${copilotSessionId}`,
146
+ }));
147
+ await copilotClient.send(new AskCommand({ sessionId: copilotSessionId, wilmaSessionId: started.sessionId }));
148
+ return started.sessionId;
149
+ }
150
+ catch (cause) {
151
+ onError?.(cause);
152
+ throw cause;
153
+ }
154
+ finally {
155
+ setIsAsking(false);
156
+ }
157
+ }, [assistantClient, copilotClient, copilotSessionId, onError]);
158
+ return { ask, isAsking };
159
+ }
160
+ /**
161
+ * The two members of `CopilotClientAction`. Both are accepted into the session mailbox,
162
+ * so the outcome arrives as an `action` event rather than from the call itself.
163
+ */
164
+ export function useCopilotActions({ copilotClient, sessionId, onOpenUrl, onError, }) {
165
+ const [usedKeys, setUsedKeys] = useState(new Set());
166
+ const runSmartAction = useCallback(async (entry) => {
167
+ const type = getSmartActionType(entry.action);
168
+ if (!type || !sessionId)
169
+ return;
170
+ setUsedKeys((current) => new Set(current).add(entry.key));
171
+ if (type === 'openUrl') {
172
+ const { url, openInNewTab } = asRecord(entry.action.openUrl);
173
+ if (typeof url === 'string' && url)
174
+ onOpenUrl?.(url, openInNewTab !== false);
175
+ }
176
+ try {
177
+ await copilotClient.send(new ActCommand({ sessionId, action: { smartAction: { assetId: entry.assetId, actionId: entry.itemId } } }));
178
+ }
179
+ catch (cause) {
180
+ onError?.(cause);
181
+ }
182
+ }, [copilotClient, onError, onOpenUrl, sessionId]);
183
+ const searchKnowledge = useCallback(async (questionId, question) => {
184
+ if (!sessionId)
185
+ return;
186
+ try {
187
+ await copilotClient.send(new ActCommand({ sessionId, action: { knowledgeSearch: { questionId, question } } }));
188
+ }
189
+ catch (cause) {
190
+ onError?.(cause);
191
+ }
192
+ }, [copilotClient, onError, sessionId]);
193
+ return { usedKeys, runSmartAction, searchKnowledge };
194
+ }
195
+ /**
196
+ * Watches a session for the few things worth interrupting for (`collectCopilotAlerts`).
197
+ *
198
+ * The point of the hook is the baseline. A session is rehydrated by replaying its
199
+ * recorded events, so a panel opened next to a call that has been running for ten
200
+ * minutes sees every earlier detection arrive at once — and firing a notification for
201
+ * each would be both wrong and unbearable. Everything present when the stream settles
202
+ * is therefore marked seen without alerting, and only what arrives afterwards is news.
203
+ */
204
+ export function useCopilotAlerts({ state, isLoading = false, onAlert }) {
205
+ const [unseen, setUnseen] = useState([]);
206
+ const alerts = useMemo(() => collectCopilotAlerts(state), [state]);
207
+ const seenRef = useRef(new Set());
208
+ const settledRef = useRef(false);
209
+ useEffect(() => {
210
+ const fresh = alerts.filter((alert) => !seenRef.current.has(alert.key));
211
+ for (const alert of fresh)
212
+ seenRef.current.add(alert.key);
213
+ if (!settledRef.current) {
214
+ settledRef.current = !isLoading;
215
+ return;
216
+ }
217
+ if (fresh.length === 0)
218
+ return;
219
+ setUnseen((current) => [...current, ...fresh]);
220
+ onAlert?.(fresh);
221
+ }, [alerts, isLoading, onAlert]);
222
+ return { unseen, clear: useCallback(() => setUnseen([]), []) };
223
+ }
224
+ export function useCopilotRecentSessions(options) {
225
+ const { copilotClient, enabled = true, limit = 20, onError } = options;
226
+ const [sessions, setSessions] = useState([]);
227
+ const [isLoading, setIsLoading] = useState(enabled);
228
+ const [error, setError] = useState();
229
+ const [nonce, setNonce] = useState(0);
230
+ useEffect(() => {
231
+ if (!enabled)
232
+ return;
233
+ let cancelled = false;
234
+ setIsLoading(true);
235
+ void copilotClient
236
+ .send(new ListSessionsCommand({ limit }))
237
+ .then((result) => {
238
+ if (!cancelled)
239
+ setSessions(sortSessionsRecentFirst(result.sessions ?? []));
240
+ })
241
+ .catch((cause) => {
242
+ if (!cancelled) {
243
+ setError(cause instanceof Error ? cause : new Error(String(cause)));
244
+ onError?.(cause);
245
+ }
246
+ })
247
+ .finally(() => {
248
+ if (!cancelled)
249
+ setIsLoading(false);
250
+ });
251
+ return () => {
252
+ cancelled = true;
253
+ };
254
+ }, [copilotClient, enabled, limit, nonce, onError]);
255
+ return { sessions, isLoading, error, refresh: () => setNonce((value) => value + 1) };
256
+ }
257
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAExE,OAAO,EAAC,mBAAmB,EAA4B,MAAM,gCAAgC,CAAC;AAC9F,OAAO,EACL,QAAQ,EACR,oBAAoB,EAMpB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,UAAU,EACV,UAAU,EAIV,aAAa,EACb,uBAAuB,EACvB,+BAA+B,EAC/B,mBAAmB,EACnB,WAAW,GAEZ,MAAM,uCAAuC,CAAC;AAE/C,MAAM,UAAU,GAAG,IAAI,CAAC;AAOxB,SAAS,SAAS,CAAC,MAAwC;IACzD,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;AACtC,CAAC;AAQD,MAAM,UAAU,sBAAsB,CAAC,EACrC,aAAa,EACb,MAAM,EACN,OAAO,GAAG,IAAI,EACd,aAAa,GAAG,EAAE,EAClB,OAAO,GACuB;IAC9B,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,EAAU,CAAC;IAC/D,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,EAAU,CAAC;IACnE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AAK,EAAC,CAAC,CAAC;aACtC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YACf,IAAI,CAAC,SAAS;gBAAE,WAAW,CAAC,uBAAuB,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC;QAC9E,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YACxB,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,QAAQ,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACpE,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;YACnB,CAAC;QACH,CAAC,CAAC;aACD,OAAO,CAAC,GAAG,EAAE;YACZ,IAAI,CAAC,SAAS;gBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEL,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;QACnB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;IAEpD,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,EAAC,CAAC;AACrF,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './hooks';
2
+ export * from '@wildix/wilma-copilot-core';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,4BAA4B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './hooks';
2
+ export * from '@wildix/wilma-copilot-core';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,4BAA4B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@wildix/wilma-copilot-headless",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "React hooks for Wilma Copilot relationships, session streams and asks with injected clients.",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "react-native": "./src/index.ts",
10
+ "files": [
11
+ "dist",
12
+ "src"
13
+ ],
14
+ "scripts": {
15
+ "build": "pnpm run clean && tsc --project tsconfig.build.json",
16
+ "clean": "rimraf --glob './dist' '*.tsbuildinfo'",
17
+ "lint": "eslint src --config ../wilma-core/.eslintrc.cjs --max-warnings 0",
18
+ "typecheck": "tsc --project tsconfig.build.json --noEmit",
19
+ "test": "vitest run --passWithNoTests"
20
+ },
21
+ "peerDependencies": {
22
+ "@wildix/wilma-assistant-client": ">=0.0.9 <1",
23
+ "@wildix/wilma-copilot-core": ">=0.1 <1",
24
+ "@wildix/wilma-copilot-sessions-client": ">=1.0.9 <2",
25
+ "react": "^19"
26
+ },
27
+ "devDependencies": {
28
+ "@types/react": "^19.1.9",
29
+ "@wildix/eslint-config-style-guide": "^1.2.2",
30
+ "@wildix/wilma-assistant-client": "0.0.9",
31
+ "@wildix/wilma-copilot-core": "workspace:*",
32
+ "@wildix/wilma-copilot-sessions-client": "1.0.10",
33
+ "eslint": "^8",
34
+ "react": "^19",
35
+ "rimraf": "^5.0.5",
36
+ "typescript": "^5.9.2",
37
+ "vitest": "^4.0.4"
38
+ },
39
+ "exports": {
40
+ ".": {
41
+ "types": "./dist/index.d.ts",
42
+ "react-native": "./src/index.ts",
43
+ "import": "./dist/index.js"
44
+ }
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ }
49
+ }
package/src/hooks.ts ADDED
@@ -0,0 +1,406 @@
1
+ import {useCallback, useEffect, useMemo, useRef, useState} from 'react';
2
+
3
+ import {StartSessionCommand, type WilmaAssistantClient} from '@wildix/wilma-assistant-client';
4
+ import {
5
+ asRecord,
6
+ collectCopilotAlerts,
7
+ type CopilotAlert,
8
+ type CopilotRelationshipHandle,
9
+ type CopilotSessionStreamHandle,
10
+ type CopilotSmartActionEntry,
11
+ type CopilotUiState,
12
+ getCopilotEventIndex,
13
+ getSmartActionType,
14
+ initialCopilotUiState,
15
+ reduceCopilotEvent,
16
+ sortSessionsRecentFirst,
17
+ } from '@wildix/wilma-copilot-core';
18
+ import {
19
+ ActCommand,
20
+ AskCommand,
21
+ type CopilotContextLookup,
22
+ type CopilotSessionEvent,
23
+ type CopilotSessionSummary,
24
+ EnrichCommand,
25
+ GetSessionEventsCommand,
26
+ ListRelationshipSessionsCommand,
27
+ ListSessionsCommand,
28
+ OpenCommand,
29
+ type WilmaCopilotSessionsClient,
30
+ } from '@wildix/wilma-copilot-sessions-client';
31
+
32
+ const PAGE_LIMIT = 1000;
33
+
34
+ export interface CopilotDependencies {
35
+ copilotClient: WilmaCopilotSessionsClient;
36
+ onError?: (error: unknown) => void;
37
+ }
38
+
39
+ function lookupKey(lookup: CopilotContextLookup | undefined): string {
40
+ return JSON.stringify(lookup ?? {});
41
+ }
42
+
43
+ export interface UseCopilotRelationshipOptions extends CopilotDependencies {
44
+ lookup?: CopilotContextLookup;
45
+ enabled?: boolean;
46
+ sessionsLimit?: number;
47
+ }
48
+
49
+ export function useCopilotRelationship({
50
+ copilotClient,
51
+ lookup,
52
+ enabled = true,
53
+ sessionsLimit = 50,
54
+ onError,
55
+ }: UseCopilotRelationshipOptions): CopilotRelationshipHandle {
56
+ const [relationshipId, setRelationshipId] = useState<string>();
57
+ const [defaultSessionId, setDefaultSessionId] = useState<string>();
58
+ const [sessions, setSessions] = useState<CopilotSessionSummary[]>([]);
59
+ const [isLoading, setIsLoading] = useState(enabled);
60
+ const [error, setError] = useState<Error>();
61
+ const [attempt, setAttempt] = useState(0);
62
+ const relationshipRef = useRef<string | undefined>(undefined);
63
+ const openedLookupRef = useRef<string | undefined>(undefined);
64
+
65
+ relationshipRef.current = relationshipId;
66
+
67
+ const loadSessions = useCallback(
68
+ async (id: string, signal?: AbortSignal) => {
69
+ const result = await copilotClient.send(
70
+ new ListRelationshipSessionsCommand({relationshipId: id, limit: sessionsLimit}),
71
+ signal ? {abortSignal: signal} : undefined,
72
+ );
73
+ if (!signal?.aborted) setSessions(sortSessionsRecentFirst(result.sessions ?? []));
74
+ },
75
+ [copilotClient, sessionsLimit],
76
+ );
77
+
78
+ const refresh = useCallback(() => {
79
+ if (relationshipRef.current) void loadSessions(relationshipRef.current).catch(onError);
80
+ }, [loadSessions, onError]);
81
+
82
+ const retry = useCallback(() => {
83
+ setError(undefined);
84
+ setAttempt((value) => value + 1);
85
+ }, []);
86
+
87
+ useEffect(() => {
88
+ if (!enabled) return;
89
+ const abort = new AbortController();
90
+ setIsLoading(true);
91
+
92
+ void (async () => {
93
+ try {
94
+ const result = await copilotClient.send(new OpenCommand({lookup}), {abortSignal: abort.signal});
95
+ if (abort.signal.aborted) return;
96
+ openedLookupRef.current = lookupKey(lookup);
97
+ setRelationshipId(result.relationshipId);
98
+ setDefaultSessionId(result.session.id);
99
+ await loadSessions(result.relationshipId, abort.signal);
100
+ setError(undefined);
101
+ } catch (cause) {
102
+ if (!abort.signal.aborted) {
103
+ const next = cause instanceof Error ? cause : new Error(String(cause));
104
+ setError(next);
105
+ onError?.(cause);
106
+ }
107
+ } finally {
108
+ if (!abort.signal.aborted) setIsLoading(false);
109
+ }
110
+ })();
111
+
112
+ return () => abort.abort();
113
+ }, [attempt, copilotClient, enabled, loadSessions, onError]);
114
+
115
+ const key = lookupKey(lookup);
116
+ useEffect(() => {
117
+ const currentId = relationshipRef.current;
118
+ if (!enabled || !currentId || openedLookupRef.current === undefined || openedLookupRef.current === key) return;
119
+ openedLookupRef.current = key;
120
+
121
+ void copilotClient
122
+ .send(new EnrichCommand({relationshipId: currentId, lookup: lookup as CopilotContextLookup}))
123
+ .then((result) => {
124
+ setRelationshipId(result.relationshipId);
125
+ setSessions(sortSessionsRecentFirst(result.related ?? []));
126
+ })
127
+ .catch(onError);
128
+ }, [copilotClient, enabled, key, lookup, onError]);
129
+
130
+ return {relationshipId, sessions, defaultSessionId, isLoading, error, retry, refresh};
131
+ }
132
+
133
+ export type CopilotEventStream = (
134
+ sessionId: string,
135
+ startIndex: number,
136
+ signal: AbortSignal,
137
+ ) => AsyncIterable<CopilotSessionEvent>;
138
+
139
+ export interface UseCopilotSessionStreamOptions extends CopilotDependencies {
140
+ sessionId?: string;
141
+ live?: boolean;
142
+ streamEvents?: CopilotEventStream;
143
+ onRelationship?: (sessionId: string | undefined) => void;
144
+ }
145
+
146
+ export function useCopilotSessionStream({
147
+ copilotClient,
148
+ sessionId,
149
+ live = true,
150
+ streamEvents,
151
+ onRelationship,
152
+ onError,
153
+ }: UseCopilotSessionStreamOptions): CopilotSessionStreamHandle {
154
+ const [state, setState] = useState(initialCopilotUiState);
155
+ const [isLoading, setIsLoading] = useState(Boolean(sessionId));
156
+ const [error, setError] = useState<Error>();
157
+
158
+ useEffect(() => {
159
+ if (!sessionId) {
160
+ setState(initialCopilotUiState);
161
+ setIsLoading(false);
162
+
163
+ return;
164
+ }
165
+
166
+ const abort = new AbortController();
167
+ let nextIndex = 0;
168
+ setState(initialCopilotUiState);
169
+ setIsLoading(true);
170
+ setError(undefined);
171
+
172
+ const apply = (event: CopilotSessionEvent) => {
173
+ nextIndex = Math.max(nextIndex, getCopilotEventIndex(event) + 1);
174
+ if (event.relationship) onRelationship?.(event.relationship.sessionId);
175
+ setState((current) => reduceCopilotEvent(current, event));
176
+ };
177
+
178
+ const replay = async (startIndex = 0): Promise<void> => {
179
+ const output = await copilotClient.send(new GetSessionEventsCommand({sessionId, startIndex, limit: PAGE_LIMIT}), {
180
+ abortSignal: abort.signal,
181
+ });
182
+
183
+ for (const event of output.events ?? []) {
184
+ apply(event);
185
+ }
186
+
187
+ if (output.nextStartIndex != null && !abort.signal.aborted) {
188
+ await replay(output.nextStartIndex);
189
+ }
190
+ };
191
+
192
+ void (async () => {
193
+ try {
194
+ await replay();
195
+ setIsLoading(false);
196
+
197
+ if (live && streamEvents && !abort.signal.aborted) {
198
+ for await (const event of streamEvents(sessionId, nextIndex, abort.signal)) apply(event);
199
+ }
200
+ } catch (cause) {
201
+ if (!abort.signal.aborted) {
202
+ setError(cause instanceof Error ? cause : new Error(String(cause)));
203
+ onError?.(cause);
204
+ }
205
+ } finally {
206
+ if (!abort.signal.aborted) setIsLoading(false);
207
+ }
208
+ })();
209
+
210
+ return () => abort.abort();
211
+ }, [copilotClient, live, onError, onRelationship, sessionId, streamEvents]);
212
+
213
+ return {state, isLoading, error};
214
+ }
215
+
216
+ export interface UseCopilotAskOptions extends CopilotDependencies {
217
+ assistantClient: WilmaAssistantClient;
218
+ copilotSessionId?: string;
219
+ }
220
+
221
+ export function useCopilotAsk({assistantClient, copilotClient, copilotSessionId, onError}: UseCopilotAskOptions): {
222
+ ask: (question: string) => Promise<string | undefined>;
223
+ isAsking: boolean;
224
+ } {
225
+ const [isAsking, setIsAsking] = useState(false);
226
+ const ask = useCallback(
227
+ async (question: string) => {
228
+ const message = question.trim();
229
+ if (!message || !copilotSessionId) return undefined;
230
+ setIsAsking(true);
231
+
232
+ try {
233
+ const started = await assistantClient.send(
234
+ new StartSessionCommand({
235
+ message,
236
+ visibility: 'hidden',
237
+ target: `copilot://sessions/${copilotSessionId}`,
238
+ }),
239
+ );
240
+ await copilotClient.send(new AskCommand({sessionId: copilotSessionId, wilmaSessionId: started.sessionId}));
241
+
242
+ return started.sessionId;
243
+ } catch (cause) {
244
+ onError?.(cause);
245
+ throw cause;
246
+ } finally {
247
+ setIsAsking(false);
248
+ }
249
+ },
250
+ [assistantClient, copilotClient, copilotSessionId, onError],
251
+ );
252
+
253
+ return {ask, isAsking};
254
+ }
255
+
256
+ export interface UseCopilotActionsOptions extends CopilotDependencies {
257
+ sessionId?: string;
258
+ /**
259
+ * Opens the URL of an `openUrl` smart action. Navigation belongs to the host, so the
260
+ * SDK reports the invocation and leaves the window to the app.
261
+ */
262
+ onOpenUrl?: (url: string, openInNewTab: boolean) => void;
263
+ }
264
+
265
+ export interface CopilotActionsHandle {
266
+ /** Keys of the smart actions this client already invoked, for the muted styling. */
267
+ usedKeys: ReadonlySet<string>;
268
+ runSmartAction: (entry: CopilotSmartActionEntry) => Promise<void>;
269
+ searchKnowledge: (questionId: string, question?: string) => Promise<void>;
270
+ }
271
+
272
+ /**
273
+ * The two members of `CopilotClientAction`. Both are accepted into the session mailbox,
274
+ * so the outcome arrives as an `action` event rather than from the call itself.
275
+ */
276
+ export function useCopilotActions({
277
+ copilotClient,
278
+ sessionId,
279
+ onOpenUrl,
280
+ onError,
281
+ }: UseCopilotActionsOptions): CopilotActionsHandle {
282
+ const [usedKeys, setUsedKeys] = useState<ReadonlySet<string>>(new Set());
283
+
284
+ const runSmartAction = useCallback(
285
+ async (entry: CopilotSmartActionEntry) => {
286
+ const type = getSmartActionType(entry.action);
287
+ if (!type || !sessionId) return;
288
+ setUsedKeys((current) => new Set(current).add(entry.key));
289
+
290
+ if (type === 'openUrl') {
291
+ const {url, openInNewTab} = asRecord(entry.action.openUrl);
292
+ if (typeof url === 'string' && url) onOpenUrl?.(url, openInNewTab !== false);
293
+ }
294
+
295
+ try {
296
+ await copilotClient.send(
297
+ new ActCommand({sessionId, action: {smartAction: {assetId: entry.assetId, actionId: entry.itemId}}}),
298
+ );
299
+ } catch (cause) {
300
+ onError?.(cause);
301
+ }
302
+ },
303
+ [copilotClient, onError, onOpenUrl, sessionId],
304
+ );
305
+
306
+ const searchKnowledge = useCallback(
307
+ async (questionId: string, question?: string) => {
308
+ if (!sessionId) return;
309
+
310
+ try {
311
+ await copilotClient.send(new ActCommand({sessionId, action: {knowledgeSearch: {questionId, question}}}));
312
+ } catch (cause) {
313
+ onError?.(cause);
314
+ }
315
+ },
316
+ [copilotClient, onError, sessionId],
317
+ );
318
+
319
+ return {usedKeys, runSmartAction, searchKnowledge};
320
+ }
321
+
322
+ export interface UseCopilotAlertsOptions {
323
+ state: CopilotUiState;
324
+ /** True while recorded events are replaying. Those are history, and history never alerts. */
325
+ isLoading?: boolean;
326
+ /** Called once per batch of alerts that arrived live, oldest first. */
327
+ onAlert?: (alerts: CopilotAlert[]) => void;
328
+ }
329
+
330
+ export interface CopilotAlertsHandle {
331
+ /** Alerts seen since the last `clear`, oldest first. Drives an unread badge. */
332
+ unseen: CopilotAlert[];
333
+ clear: () => void;
334
+ }
335
+
336
+ /**
337
+ * Watches a session for the few things worth interrupting for (`collectCopilotAlerts`).
338
+ *
339
+ * The point of the hook is the baseline. A session is rehydrated by replaying its
340
+ * recorded events, so a panel opened next to a call that has been running for ten
341
+ * minutes sees every earlier detection arrive at once — and firing a notification for
342
+ * each would be both wrong and unbearable. Everything present when the stream settles
343
+ * is therefore marked seen without alerting, and only what arrives afterwards is news.
344
+ */
345
+ export function useCopilotAlerts({state, isLoading = false, onAlert}: UseCopilotAlertsOptions): CopilotAlertsHandle {
346
+ const [unseen, setUnseen] = useState<CopilotAlert[]>([]);
347
+ const alerts = useMemo(() => collectCopilotAlerts(state), [state]);
348
+ const seenRef = useRef<Set<string>>(new Set());
349
+ const settledRef = useRef(false);
350
+
351
+ useEffect(() => {
352
+ const fresh = alerts.filter((alert) => !seenRef.current.has(alert.key));
353
+ for (const alert of fresh) seenRef.current.add(alert.key);
354
+
355
+ if (!settledRef.current) {
356
+ settledRef.current = !isLoading;
357
+
358
+ return;
359
+ }
360
+
361
+ if (fresh.length === 0) return;
362
+ setUnseen((current) => [...current, ...fresh]);
363
+ onAlert?.(fresh);
364
+ }, [alerts, isLoading, onAlert]);
365
+
366
+ return {unseen, clear: useCallback(() => setUnseen([]), [])};
367
+ }
368
+
369
+ export function useCopilotRecentSessions(options: CopilotDependencies & {enabled?: boolean; limit?: number}): {
370
+ sessions: CopilotSessionSummary[];
371
+ isLoading: boolean;
372
+ error?: Error;
373
+ refresh: () => void;
374
+ } {
375
+ const {copilotClient, enabled = true, limit = 20, onError} = options;
376
+ const [sessions, setSessions] = useState<CopilotSessionSummary[]>([]);
377
+ const [isLoading, setIsLoading] = useState(enabled);
378
+ const [error, setError] = useState<Error>();
379
+ const [nonce, setNonce] = useState(0);
380
+
381
+ useEffect(() => {
382
+ if (!enabled) return;
383
+ let cancelled = false;
384
+ setIsLoading(true);
385
+ void copilotClient
386
+ .send(new ListSessionsCommand({limit}))
387
+ .then((result) => {
388
+ if (!cancelled) setSessions(sortSessionsRecentFirst(result.sessions ?? []));
389
+ })
390
+ .catch((cause: unknown) => {
391
+ if (!cancelled) {
392
+ setError(cause instanceof Error ? cause : new Error(String(cause)));
393
+ onError?.(cause);
394
+ }
395
+ })
396
+ .finally(() => {
397
+ if (!cancelled) setIsLoading(false);
398
+ });
399
+
400
+ return () => {
401
+ cancelled = true;
402
+ };
403
+ }, [copilotClient, enabled, limit, nonce, onError]);
404
+
405
+ return {sessions, isLoading, error, refresh: () => setNonce((value) => value + 1)};
406
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './hooks';
2
+ export * from '@wildix/wilma-copilot-core';