@gooddata/sdk-ui-gen-ai 11.66.0-alpha.1 → 11.66.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.
Files changed (34) hide show
  1. package/NOTICE +262 -343
  2. package/README.md +44 -0
  3. package/esm/components/GenAIChatDialogConnected.d.ts +4 -1
  4. package/esm/components/GenAIChatDialogConnected.d.ts.map +1 -1
  5. package/esm/components/GenAIChatDialogConnected.js +4 -1
  6. package/esm/copilot/CopilotHandler.d.ts +57 -0
  7. package/esm/copilot/CopilotHandler.d.ts.map +1 -0
  8. package/esm/copilot/CopilotHandler.js +165 -0
  9. package/esm/copilot/selectors.d.ts +10 -0
  10. package/esm/copilot/selectors.d.ts.map +1 -0
  11. package/esm/copilot/selectors.js +39 -0
  12. package/esm/copilot/transitions.d.ts +6 -0
  13. package/esm/copilot/transitions.d.ts.map +1 -0
  14. package/esm/copilot/transitions.js +424 -0
  15. package/esm/copilot/types.d.ts +170 -0
  16. package/esm/copilot/types.d.ts.map +1 -0
  17. package/esm/copilot/types.js +6 -0
  18. package/esm/copilot/useCopilotSnapshot.d.ts +15 -0
  19. package/esm/copilot/useCopilotSnapshot.d.ts.map +1 -0
  20. package/esm/copilot/useCopilotSnapshot.js +16 -0
  21. package/esm/copilot.d.ts +11 -0
  22. package/esm/copilot.d.ts.map +1 -0
  23. package/esm/copilot.js +12 -0
  24. package/esm/sdk-ui-gen-ai.d.ts +59 -3
  25. package/esm/store/chatWindow/chatWindowSlice.d.ts +3 -2
  26. package/esm/store/chatWindow/chatWindowSlice.d.ts.map +1 -1
  27. package/esm/store/events.d.ts +59 -4
  28. package/esm/store/events.d.ts.map +1 -1
  29. package/esm/store/sideEffects/onDefinitionReceivedTrigger.d.ts.map +1 -1
  30. package/esm/store/sideEffects/onDefinitionReceivedTrigger.js +11 -1
  31. package/esm/store/sideEffects/onEvent.d.ts +5 -1
  32. package/esm/store/sideEffects/onEvent.d.ts.map +1 -1
  33. package/esm/store/sideEffects/onEvent.js +23 -8
  34. package/package.json +24 -23
@@ -0,0 +1,424 @@
1
+ // (C) 2026 GoodData Corporation
2
+ /** Create an independent, empty workflow state. @alpha */
3
+ export function createCopilotState() {
4
+ return {
5
+ context: {},
6
+ interaction: emptyInteraction(),
7
+ requests: [],
8
+ applications: [],
9
+ sources: [],
10
+ revision: 0,
11
+ };
12
+ }
13
+ function emptyInteraction() {
14
+ return { waitingForUserInput: false, pendingClarificationIds: [] };
15
+ }
16
+ function sameInteraction(a, b) {
17
+ return (a.conversationId === b.conversationId &&
18
+ a.threadId === b.threadId &&
19
+ a.reasoningTitle === b.reasoningTitle &&
20
+ a.waitingForUserInput === b.waitingForUserInput &&
21
+ a.build?.type === b.build?.type &&
22
+ a.build?.intent === b.build?.intent &&
23
+ a.pendingClarificationIds.length === b.pendingClarificationIds.length &&
24
+ a.pendingClarificationIds.every((id, index) => id === b.pendingClarificationIds[index]));
25
+ }
26
+ function matchingRequestIndex(requests, threadId, origin) {
27
+ return requests.reduce((index, request, i) => (matches(request, threadId, origin) ? i : index), -1);
28
+ }
29
+ function sameTarget(a, b) {
30
+ return a.type === b.type && a.objectId === b.objectId;
31
+ }
32
+ function matches(request, threadId, conversationId) {
33
+ if (conversationId && request.conversationId === conversationId) {
34
+ return true;
35
+ }
36
+ return threadId
37
+ ? request.threadId === threadId || request.conversationId === threadId
38
+ : !conversationId && !request.threadId && !request.conversationId;
39
+ }
40
+ function conversationId(event) {
41
+ if (event.type === "chatConversationChanged") {
42
+ return event.conversation.localId;
43
+ }
44
+ return event.type === "chatUserMessage" || event.type === "chatUserAnswers"
45
+ ? event.conversationId
46
+ : undefined;
47
+ }
48
+ function failedResponse(event) {
49
+ return !!(event.cancelled || event.useCase === "INVALID");
50
+ }
51
+ function finishedResponse(event) {
52
+ return ((event.type === "chatAssistantMessage" && (event.responseCompleted || failedResponse(event))) ||
53
+ (event.type === "chatClarificationQuestions" && event.responses === null));
54
+ }
55
+ function clarificationIds(ids, event) {
56
+ return event.responses === undefined
57
+ ? ids.includes(event.interactionId)
58
+ ? ids
59
+ : [...ids, event.interactionId]
60
+ : ids.filter((id) => id !== event.interactionId);
61
+ }
62
+ function transitionRequestClarification(pending, event) {
63
+ const ids = pending.pendingClarificationIds ?? [];
64
+ const pendingClarificationIds = clarificationIds(ids, event);
65
+ return pending.awaitingClarification !== pendingClarificationIds.length > 0 ||
66
+ pendingClarificationIds !== ids
67
+ ? {
68
+ ...pending,
69
+ awaitingClarification: pendingClarificationIds.length > 0,
70
+ pendingClarificationIds,
71
+ }
72
+ : pending;
73
+ }
74
+ function transitionPendingRequest(state, pending, event, registration) {
75
+ if (event.type === "chatConversationChanged" && event.threadId && event.threadId !== pending.threadId) {
76
+ return { ...pending, threadId: event.threadId };
77
+ }
78
+ if (event.type === "chatClarificationQuestions") {
79
+ return transitionRequestClarification(pending, event);
80
+ }
81
+ if (registration && !pending.type) {
82
+ return {
83
+ ...pending,
84
+ threadId: event.threadId,
85
+ type: registration.type,
86
+ objectId: state.context.type === registration.type ? state.context.objectId : undefined,
87
+ };
88
+ }
89
+ return pending;
90
+ }
91
+ function transitionRequests(state, event, index, registration) {
92
+ const requests = state.requests;
93
+ const pending = requests[index];
94
+ if (event.type === "chatUserMessage" || event.type === "chatUserAnswers") {
95
+ // An old acknowledgement must not replace a newer request still applying a definition.
96
+ const retained = pending?.applicationIds.length ? [pending] : [];
97
+ return [
98
+ ...requests.filter((_, i) => i !== index),
99
+ ...retained,
100
+ {
101
+ revision: state.revision + 1,
102
+ conversationId: conversationId(event),
103
+ threadId: event.threadId,
104
+ applicationIds: [],
105
+ },
106
+ ];
107
+ }
108
+ if (!pending || event.type === "chatReset") {
109
+ return requests;
110
+ }
111
+ if (finishedResponse(event)) {
112
+ return pending.applicationIds.length
113
+ ? requests.map((request, i) => (i === index ? { ...pending, responseFinished: true } : request))
114
+ : requests.filter((_, i) => i !== index);
115
+ }
116
+ const updated = transitionPendingRequest(state, pending, event, registration);
117
+ return updated === pending ? requests : requests.map((request, i) => (i === index ? updated : request));
118
+ }
119
+ function transitionConversation(state, event, foreground) {
120
+ const interaction = state.interaction;
121
+ const origin = conversationId(event);
122
+ const initialAssignment = !!origin &&
123
+ state.requests.some((request) => request.conversationId === origin) &&
124
+ (!interaction.threadId || foreground) &&
125
+ (!interaction.conversationId || interaction.conversationId === origin);
126
+ return {
127
+ ...(initialAssignment ? interaction : emptyInteraction()),
128
+ conversationId: origin,
129
+ threadId: event.threadId,
130
+ };
131
+ }
132
+ function transitionInteraction(state, event, foreground) {
133
+ const interaction = state.interaction;
134
+ switch (event.type) {
135
+ case "chatReasoning":
136
+ return foreground && interaction.reasoningTitle !== event.title
137
+ ? { ...interaction, reasoningTitle: event.title }
138
+ : interaction;
139
+ case "chatUserMessage":
140
+ return {
141
+ ...interaction,
142
+ conversationId: conversationId(event),
143
+ threadId: event.threadId,
144
+ reasoningTitle: undefined,
145
+ waitingForUserInput: false,
146
+ };
147
+ case "chatUserAnswers":
148
+ return foreground
149
+ ? {
150
+ ...interaction,
151
+ waitingForUserInput: false,
152
+ pendingClarificationIds: interaction.pendingClarificationIds.filter((id) => id !== event.interactionId),
153
+ }
154
+ : interaction;
155
+ case "chatReset":
156
+ return emptyInteraction();
157
+ case "chatConversationChanged":
158
+ return transitionConversation(state, event, foreground);
159
+ default:
160
+ return interaction;
161
+ }
162
+ }
163
+ function transitionAssistant(state, event, registration) {
164
+ let interaction = state.interaction;
165
+ let generation = state.generation;
166
+ if (failedResponse(event)) {
167
+ generation = undefined;
168
+ interaction = emptyInteraction();
169
+ }
170
+ else if (registration) {
171
+ interaction = {
172
+ ...interaction,
173
+ build: {
174
+ type: registration.type,
175
+ intent: (interaction.build?.type === registration.type ? interaction.build.intent : undefined) ??
176
+ (generation === registration.type ? "create" : "edit"),
177
+ },
178
+ waitingForUserInput: interaction.waitingForUserInput ||
179
+ !!(event.responseCompleted && !interaction.pendingClarificationIds.length),
180
+ };
181
+ generation = undefined;
182
+ }
183
+ else if (event.responseCompleted &&
184
+ !interaction.pendingClarificationIds.length &&
185
+ (generation || interaction.build)) {
186
+ interaction = { ...interaction, waitingForUserInput: true };
187
+ }
188
+ return { interaction, generation };
189
+ }
190
+ function transitionClarification(state, event) {
191
+ if (event.responses === null) {
192
+ return { generation: undefined, interaction: emptyInteraction() };
193
+ }
194
+ const interaction = state.interaction;
195
+ return {
196
+ generation: state.generation,
197
+ interaction: {
198
+ ...interaction,
199
+ waitingForUserInput: event.responses === undefined ? interaction.waitingForUserInput : false,
200
+ pendingClarificationIds: clarificationIds(interaction.pendingClarificationIds, event),
201
+ },
202
+ };
203
+ }
204
+ function isForegroundResponse(state, event, pending, foreground) {
205
+ return (foreground ||
206
+ (!event.threadId &&
207
+ !state.interaction.threadId &&
208
+ (!!pending || state.generation !== undefined || !!state.interaction.build)));
209
+ }
210
+ function transitionForegroundEvent(state, event, pending, registration) {
211
+ const foreground = !!event.threadId && event.threadId === state.interaction.threadId;
212
+ const foregroundResponse = isForegroundResponse(state, event, pending, foreground);
213
+ if (event.type === "chatAssistantMessage" && foregroundResponse) {
214
+ return transitionAssistant(state, event, registration);
215
+ }
216
+ if (event.type === "chatClarificationQuestions" && foregroundResponse) {
217
+ return transitionClarification(state, event);
218
+ }
219
+ return {
220
+ interaction: transitionInteraction(state, event, foreground),
221
+ generation: state.generation,
222
+ };
223
+ }
224
+ function transitionEvent(state, event, configuration) {
225
+ if (event.type === "chatUserAnswers" && event.threadId !== state.interaction.threadId) {
226
+ return state;
227
+ }
228
+ const index = matchingRequestIndex(state.requests, event.threadId, conversationId(event));
229
+ const pending = state.requests[index];
230
+ const registration = event.type === "chatAssistantMessage"
231
+ ? configuration.registrations.find((entry) => event.skills?.some((skill) => entry.skills.includes(skill.name)))
232
+ : undefined;
233
+ const requests = transitionRequests(state, event, index, registration);
234
+ const foregroundState = transitionForegroundEvent(state, event, pending, registration);
235
+ let interaction = foregroundState.interaction;
236
+ const generation = foregroundState.generation;
237
+ if (sameInteraction(interaction, state.interaction)) {
238
+ interaction = state.interaction;
239
+ }
240
+ return requests === state.requests && interaction === state.interaction && generation === state.generation
241
+ ? state
242
+ : {
243
+ ...state,
244
+ requests,
245
+ interaction,
246
+ generation,
247
+ revision: event.type === "chatUserMessage" || event.type === "chatUserAnswers"
248
+ ? state.revision + 1
249
+ : state.revision,
250
+ };
251
+ }
252
+ function transitionContext(state, context) {
253
+ const a = state.context;
254
+ const b = context;
255
+ return a.type === b.type &&
256
+ a.objectId === b.objectId &&
257
+ a.isEditing === b.isEditing &&
258
+ (a.builderTarget === b.builderTarget ||
259
+ (!!a.builderTarget && !!b.builderTarget && sameTarget(a.builderTarget, b.builderTarget)))
260
+ ? state
261
+ : {
262
+ ...state,
263
+ context: { ...b, builderTarget: b.builderTarget ? { ...b.builderTarget } : undefined },
264
+ };
265
+ }
266
+ function requestsAfterTargetReset(requests, target) {
267
+ return requests.some((request) => request.applicationIds.length &&
268
+ request.type === target.type &&
269
+ (request.objectId === undefined || request.objectId === target.objectId))
270
+ ? requests
271
+ : requests.filter((request) => request.type !== undefined &&
272
+ (request.type !== target.type ||
273
+ (request.objectId !== undefined && request.objectId !== target.objectId)));
274
+ }
275
+ function transitionTargetReset(state, target) {
276
+ const next = {
277
+ ...state,
278
+ interaction: {
279
+ ...state.interaction,
280
+ threadId: undefined,
281
+ reasoningTitle: undefined,
282
+ waitingForUserInput: false,
283
+ },
284
+ requests: requestsAfterTargetReset(state.requests, target),
285
+ };
286
+ return next.requests.length === state.requests.length &&
287
+ sameInteraction(next.interaction, state.interaction)
288
+ ? state
289
+ : next;
290
+ }
291
+ function transitionApplicationStarted(state, input) {
292
+ if (state.applications.some((application) => application.id === input.id)) {
293
+ return state;
294
+ }
295
+ const { source } = input;
296
+ const index = matchingRequestIndex(state.requests, source.threadId, source.conversationId);
297
+ const pending = state.requests[index];
298
+ const request = {
299
+ ...pending,
300
+ revision: pending?.revision ?? state.revision + 1,
301
+ type: source.target.type,
302
+ objectId: source.target.objectId,
303
+ conversationId: source.conversationId ?? pending?.conversationId,
304
+ threadId: source.threadId ?? pending?.threadId,
305
+ awaitingClarification: false,
306
+ applicationIds: [...(pending?.applicationIds ?? []), input.id],
307
+ };
308
+ return {
309
+ ...state,
310
+ revision: state.revision + 1,
311
+ applications: [
312
+ ...state.applications,
313
+ {
314
+ ...source,
315
+ target: { ...source.target },
316
+ id: input.id,
317
+ revision: state.revision + 1,
318
+ requestRevision: request.revision,
319
+ },
320
+ ],
321
+ requests: [...state.requests.filter((_, i) => i !== index), request],
322
+ };
323
+ }
324
+ function requestsAfterApplicationFinished(requests, input) {
325
+ return requests.flatMap((request) => {
326
+ if (!request.applicationIds.includes(input.id)) {
327
+ return [request];
328
+ }
329
+ const applicationIds = request.applicationIds.filter((id) => id !== input.id);
330
+ return !applicationIds.length && (input.kind === "applicationApplied" || request.responseFinished)
331
+ ? []
332
+ : [{ ...request, applicationIds }];
333
+ });
334
+ }
335
+ function sourcesAfterApplicationApplied(sources, application, target) {
336
+ const previous = sources.find((entry) => sameTarget(entry.target, target));
337
+ return previous && previous.revision > application.revision
338
+ ? sources
339
+ : [
340
+ ...sources.filter((entry) => entry !== previous),
341
+ {
342
+ target: { ...target },
343
+ revision: application.revision,
344
+ source: application.conversationId
345
+ ? {
346
+ conversationId: application.conversationId,
347
+ threadId: application.threadId,
348
+ }
349
+ : undefined,
350
+ },
351
+ ];
352
+ }
353
+ function isForegroundApplication(state, application) {
354
+ return (matches(state.interaction, application.threadId, application.conversationId) ||
355
+ (!state.interaction.threadId &&
356
+ !state.interaction.conversationId &&
357
+ (state.generation === application.target.type ||
358
+ state.interaction.build?.type === application.target.type)));
359
+ }
360
+ function hasNewerApplicationWork(state, application, applications, requests) {
361
+ return (applications.some((entry) => entry.revision > application.revision &&
362
+ matches(entry, application.threadId, application.conversationId)) ||
363
+ requests.some((request) => request.revision > application.requestRevision &&
364
+ matches(request, application.threadId, application.conversationId)) ||
365
+ (state.generationRevision ?? 0) > application.revision);
366
+ }
367
+ function transitionApplicationFinished(state, input) {
368
+ const application = state.applications.find((entry) => entry.id === input.id);
369
+ if (!application) {
370
+ return state;
371
+ }
372
+ if (input.kind === "applicationApplied" && input.target.type !== application.target.type) {
373
+ return state;
374
+ }
375
+ const applications = state.applications.filter((entry) => entry !== application);
376
+ const requests = requestsAfterApplicationFinished(state.requests, input);
377
+ if (input.kind === "applicationInterrupted") {
378
+ return { ...state, applications, requests };
379
+ }
380
+ const sources = sourcesAfterApplicationApplied(state.sources, application, input.target);
381
+ const isForeground = isForegroundApplication(state, application);
382
+ const hasNewer = hasNewerApplicationWork(state, application, applications, requests);
383
+ return {
384
+ ...state,
385
+ applications,
386
+ requests,
387
+ sources,
388
+ ...(isForeground && !hasNewer
389
+ ? { generation: undefined, interaction: emptyInteraction() }
390
+ : {}),
391
+ };
392
+ }
393
+ /** Deterministic immutable transition; never allocates IDs, invokes effects, or performs I/O. @alpha */
394
+ export function transitionCopilot(state, input, configuration) {
395
+ switch (input.kind) {
396
+ case "event":
397
+ return transitionEvent(state, input.event, configuration);
398
+ case "context":
399
+ return transitionContext(state, input.context);
400
+ case "startGeneration":
401
+ return {
402
+ ...state,
403
+ generation: input.type,
404
+ generationRevision: state.revision + 1,
405
+ revision: state.revision + 1,
406
+ interaction: emptyInteraction(),
407
+ };
408
+ case "cancelGeneration":
409
+ return state.generation === input.type || state.interaction.build?.type === input.type
410
+ ? { ...state, generation: undefined, interaction: emptyInteraction() }
411
+ : state;
412
+ case "resetInteraction":
413
+ return sameInteraction(state.interaction, emptyInteraction())
414
+ ? state
415
+ : { ...state, interaction: emptyInteraction() };
416
+ case "resetTarget":
417
+ return transitionTargetReset(state, input.target);
418
+ case "applicationStarted":
419
+ return transitionApplicationStarted(state, input);
420
+ case "applicationApplied":
421
+ case "applicationInterrupted":
422
+ return transitionApplicationFinished(state, input);
423
+ }
424
+ }
@@ -0,0 +1,170 @@
1
+ import { type AgentCustomSkill } from "@gooddata/sdk-model";
2
+ import { type ChatClarificationQuestionsEvent, type ChatDefinitionReceivedEvent, type ChatEvent } from "../store/events.js";
3
+ /** Built-in copilot workflows. Applications may supply their own string enum. @alpha */
4
+ export declare enum CopilotBuildType {
5
+ Dashboard = "dashboard"
6
+ }
7
+ /** Derived workflow progress, independent of host presentation. @alpha */
8
+ export type CopilotStatus = "idle" | "generating" | "building" | "waiting";
9
+ /** An object managed by a registered workflow. @alpha */
10
+ export interface ICopilotTarget<TBuild extends string = CopilotBuildType> {
11
+ /** Registered workflow type. */
12
+ readonly type: TBuild;
13
+ /** Host object identifier. */
14
+ readonly objectId: string;
15
+ }
16
+ /** Host facts used to resolve events, never application services. @alpha */
17
+ export interface ICopilotContext<TBuild extends string = CopilotBuildType> {
18
+ /** Currently displayed workflow. */
19
+ readonly type?: TBuild;
20
+ /** Currently displayed object. */
21
+ readonly objectId?: string;
22
+ /** Whether the host allows edits to the displayed object. */
23
+ readonly isEditing?: boolean;
24
+ /** Object being displayed in a builder, if any. */
25
+ readonly builderTarget?: ICopilotTarget<TBuild>;
26
+ }
27
+ /** Scope of a progress query. @alpha */
28
+ export interface ICopilotScope<TBuild extends string = CopilotBuildType> {
29
+ /** Workflow to query. */
30
+ readonly type: TBuild;
31
+ /** Restrict edit requests to this object. */
32
+ readonly objectId?: string;
33
+ /** Include activated edit requests. */
34
+ readonly isEditing?: boolean;
35
+ /** Include an existing foreground edit build. */
36
+ readonly isBuilder?: boolean;
37
+ }
38
+ /** Conversation that supplied an applied definition. @alpha */
39
+ export interface ICopilotSource {
40
+ /** Local conversation identifier, distinct from the backend thread. */
41
+ readonly conversationId: string;
42
+ /** Backend thread, when already assigned. */
43
+ readonly threadId?: string;
44
+ }
45
+ /** Origin and intended target of a host definition application. @alpha */
46
+ export interface ICopilotApplicationSource<TBuild extends string = CopilotBuildType> {
47
+ /** Intended object. The acknowledgement may supply its final identifier. */
48
+ readonly target: ICopilotTarget<TBuild>;
49
+ /** Originating local conversation, if known. */
50
+ readonly conversationId?: string;
51
+ /** Originating backend thread, if known. */
52
+ readonly threadId?: string;
53
+ }
54
+ /** Foreground interaction; background requests are tracked independently. @alpha */
55
+ export interface ICopilotInteraction<TBuild extends string = CopilotBuildType> {
56
+ /** Local conversation. */
57
+ readonly conversationId?: string;
58
+ /** Backend thread. */
59
+ readonly threadId?: string;
60
+ /** Current reasoning heading. */
61
+ readonly reasoningTitle?: string;
62
+ /** Response ended and needs another user message. */
63
+ readonly waitingForUserInput: boolean;
64
+ /** Unanswered clarification item identifiers, not conversation identifiers. */
65
+ readonly pendingClarificationIds: readonly string[];
66
+ /** Skill-activated workflow. */
67
+ readonly build?: {
68
+ readonly type: TBuild;
69
+ readonly intent: "create" | "edit";
70
+ };
71
+ }
72
+ /** A potentially editing response, including provisional requests without a skill. @alpha */
73
+ export interface ICopilotRequest<TBuild extends string = CopilotBuildType> {
74
+ /** Monotonic request revision, distinguishing follow-ups in the same conversation. */
75
+ readonly revision: number;
76
+ /** Originating local conversation. */
77
+ readonly conversationId?: string;
78
+ /** Backend thread assigned to the request. */
79
+ readonly threadId?: string;
80
+ /** Resolved skill's workflow; absent until activation. */
81
+ readonly type?: TBuild;
82
+ /** Resolved object identifier. */
83
+ readonly objectId?: string;
84
+ /** Whether this response awaits clarification. */
85
+ readonly awaitingClarification?: boolean;
86
+ /** Unanswered clarification item identifiers for this response. */
87
+ readonly pendingClarificationIds?: readonly string[];
88
+ /** Response ended while its definitions were being applied. */
89
+ readonly responseFinished?: boolean;
90
+ /** In-progress host applications. */
91
+ readonly applicationIds: readonly string[];
92
+ }
93
+ /** An application awaiting an explicit host acknowledgement. @alpha */
94
+ export interface ICopilotApplication<TBuild extends string = CopilotBuildType> extends ICopilotApplicationSource<TBuild> {
95
+ /** Facade-allocated correlation identifier. */
96
+ readonly id: string;
97
+ /** Monotonic revision used to ignore out-of-order source attribution. */
98
+ readonly revision: number;
99
+ /** Request revision captured when installation started. */
100
+ readonly requestRevision: number;
101
+ }
102
+ /** Read-only workflow state shared by headless and React consumers. @alpha */
103
+ export interface ICopilotSnapshot<TBuild extends string = CopilotBuildType> {
104
+ /** Last host facts. */
105
+ readonly context: ICopilotContext<TBuild>;
106
+ /** Requested creation, before skill activation. */
107
+ readonly generation?: TBuild;
108
+ /** Creation revision protecting a newer intent from older application acknowledgements. */
109
+ readonly generationRevision?: number;
110
+ /** Foreground chat interaction. */
111
+ readonly interaction: ICopilotInteraction<TBuild>;
112
+ /** Outstanding responses across conversations. */
113
+ readonly requests: readonly ICopilotRequest<TBuild>[];
114
+ /** In-progress host installations. */
115
+ readonly applications: readonly ICopilotApplication<TBuild>[];
116
+ /** Last applied origin for each object, including unknown-origin tombstones. */
117
+ readonly sources: readonly {
118
+ readonly target: ICopilotTarget<TBuild>;
119
+ readonly source?: ICopilotSource;
120
+ readonly revision: number;
121
+ }[];
122
+ /** Monotonic lifecycle revision, not an allocated identifier. */
123
+ readonly revision: number;
124
+ }
125
+ /** Pure matching policy and host effect for one workflow. @alpha */
126
+ export interface ICopilotRegistration<TBuild extends string = CopilotBuildType> {
127
+ /** Workflow activated by these skills. */
128
+ readonly type: TBuild;
129
+ /** Skills that activate this workflow. */
130
+ readonly skills: readonly AgentCustomSkill[];
131
+ /** Pure acceptance policy; return undefined to reject a definition. */
132
+ readonly resolveDefinition: (event: ChatDefinitionReceivedEvent, context: ICopilotContext<TBuild>, snapshot: ICopilotSnapshot<TBuild>) => ICopilotTarget<TBuild> | undefined;
133
+ /** Apply the accepted definition, then explicitly acknowledge its application ID. */
134
+ readonly onApplyDefinition: (event: ChatDefinitionReceivedEvent, applicationId: string, target: ICopilotTarget<TBuild>) => void;
135
+ }
136
+ /** Configuration of an isolated copilot instance. @alpha */
137
+ export interface ICopilotConfiguration<TBuild extends string = CopilotBuildType> {
138
+ /** Workflow registrations, in matching order. */
139
+ readonly registrations: readonly ICopilotRegistration<TBuild>[];
140
+ /** Show newly presented clarification after its state has been published. */
141
+ readonly onClarificationQuestions?: (event: ChatClarificationQuestionsEvent) => void;
142
+ }
143
+ /** Explicit, deterministic input to the workflow engine. @alpha */
144
+ export type CopilotInput<TBuild extends string = CopilotBuildType> = {
145
+ readonly kind: "event";
146
+ readonly event: ChatEvent;
147
+ } | {
148
+ readonly kind: "context";
149
+ readonly context: ICopilotContext<TBuild>;
150
+ } | {
151
+ readonly kind: "startGeneration" | "cancelGeneration";
152
+ readonly type: TBuild;
153
+ } | {
154
+ readonly kind: "resetInteraction";
155
+ } | {
156
+ readonly kind: "resetTarget";
157
+ readonly target: ICopilotTarget<TBuild>;
158
+ } | {
159
+ readonly kind: "applicationStarted";
160
+ readonly id: string;
161
+ readonly source: ICopilotApplicationSource<TBuild>;
162
+ } | {
163
+ readonly kind: "applicationApplied";
164
+ readonly id: string;
165
+ readonly target: ICopilotTarget<TBuild>;
166
+ } | {
167
+ readonly kind: "applicationInterrupted";
168
+ readonly id: string;
169
+ };
170
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/copilot/types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EACH,KAAK,+BAA+B,EACpC,KAAK,2BAA2B,EAChC,KAAK,SAAS,EACjB,MAAM,oBAAoB,CAAC;AAE5B,wFAAwF;AACxF,oBAAY,gBAAgB;IACxB,SAAS,cAAc;CAC1B;AAED,0EAA0E;AAC1E,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,GAAG,SAAS,CAAC;AAE3E,yDAAyD;AACzD,MAAM,WAAW,cAAc,CAAC,MAAM,SAAS,MAAM,GAAG,gBAAgB;IACpE,gCAAgC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC7B;AAED,4EAA4E;AAC5E,MAAM,WAAW,eAAe,CAAC,MAAM,SAAS,MAAM,GAAG,gBAAgB;IACrE,oCAAoC;IACpC,Q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,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAC;CACtD,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,CAAA;CAAE,GACrG;IAAE,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ // (C) 2026 GoodData Corporation
2
+ /** Built-in copilot workflows. Applications may supply their own string enum. @alpha */
3
+ export var CopilotBuildType;
4
+ (function (CopilotBuildType) {
5
+ CopilotBuildType["Dashboard"] = "dashboard";
6
+ })(CopilotBuildType || (CopilotBuildType = {}));
@@ -0,0 +1,15 @@
1
+ import { type CopilotHandler } from "./CopilotHandler.js";
2
+ import { type CopilotBuildType, type ICopilotSnapshot } from "./types.js";
3
+ /**
4
+ * Subscribes a React component to a copilot handler's snapshot.
5
+ *
6
+ * @remarks
7
+ * This optional React adapter does not own the handler. Unmounting or switching handlers
8
+ * unsubscribes the component without disposing the handler.
9
+ *
10
+ * @param handler - Copilot instance to observe.
11
+ * @returns The handler's current, referentially stable snapshot.
12
+ * @alpha
13
+ */
14
+ export declare function useCopilotSnapshot<TBuild extends string = CopilotBuildType>(handler: CopilotHandler<TBuild>): ICopilotSnapshot<TBuild>;
15
+ //# sourceMappingURL=useCopilotSnapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCopilotSnapshot.d.ts","sourceRoot":"","sources":["../../src/copilot/useCopilotSnapshot.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,MAAM,GAAG,gBAAgB,EACvE,OAAO,EAAE,cAAc,CAAC,MAAM,CAAC,GAChC,gBAAgB,CAAC,MAAM,CAAC,CAE1B"}
@@ -0,0 +1,16 @@
1
+ // (C) 2026 GoodData Corporation
2
+ import { useSyncExternalStore } from "react";
3
+ /**
4
+ * Subscribes a React component to a copilot handler's snapshot.
5
+ *
6
+ * @remarks
7
+ * This optional React adapter does not own the handler. Unmounting or switching handlers
8
+ * unsubscribes the component without disposing the handler.
9
+ *
10
+ * @param handler - Copilot instance to observe.
11
+ * @returns The handler's current, referentially stable snapshot.
12
+ * @alpha
13
+ */
14
+ export function useCopilotSnapshot(handler) {
15
+ return useSyncExternalStore(handler.subscribe, handler.getSnapshot, handler.getSnapshot);
16
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Reusable copilot workflows with plain immutable state and optional React integration.
3
+ * @packageDocumentation
4
+ * @alpha
5
+ */
6
+ export { CopilotHandler } from "./copilot/CopilotHandler.js";
7
+ export { useCopilotSnapshot } from "./copilot/useCopilotSnapshot.js";
8
+ export { createCopilotState, transitionCopilot } from "./copilot/transitions.js";
9
+ export { selectCopilotGenerationPending, selectCopilotStatus, selectCopilotReasoningTitle, selectCopilotSource, } from "./copilot/selectors.js";
10
+ export { CopilotBuildType, type CopilotStatus, type CopilotInput, type ICopilotTarget, type ICopilotContext, type ICopilotScope, type ICopilotSource, type ICopilotApplicationSource, type ICopilotInteraction, type ICopilotRequest, type ICopilotApplication, type ICopilotSnapshot, type ICopilotRegistration, type ICopilotConfiguration, } from "./copilot/types.js";
11
+ //# sourceMappingURL=copilot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot.d.ts","sourceRoot":"","sources":["../src/copilot.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,EACH,8BAA8B,EAC9B,mBAAmB,EACnB,2BAA2B,EAC3B,mBAAmB,GACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACH,gBAAgB,EAChB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,yBAAyB,EAC9B,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,GAC7B,MAAM,oBAAoB,CAAC"}