@gooddata/sdk-ui-gen-ai 11.66.0-alpha.0 → 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.
- package/NOTICE +262 -343
- package/README.md +44 -0
- package/esm/components/GenAIChatDialogConnected.d.ts +4 -1
- package/esm/components/GenAIChatDialogConnected.d.ts.map +1 -1
- package/esm/components/GenAIChatDialogConnected.js +4 -1
- package/esm/copilot/CopilotHandler.d.ts +57 -0
- package/esm/copilot/CopilotHandler.d.ts.map +1 -0
- package/esm/copilot/CopilotHandler.js +165 -0
- package/esm/copilot/selectors.d.ts +10 -0
- package/esm/copilot/selectors.d.ts.map +1 -0
- package/esm/copilot/selectors.js +39 -0
- package/esm/copilot/transitions.d.ts +6 -0
- package/esm/copilot/transitions.d.ts.map +1 -0
- package/esm/copilot/transitions.js +424 -0
- package/esm/copilot/types.d.ts +170 -0
- package/esm/copilot/types.d.ts.map +1 -0
- package/esm/copilot/types.js +6 -0
- package/esm/copilot/useCopilotSnapshot.d.ts +15 -0
- package/esm/copilot/useCopilotSnapshot.d.ts.map +1 -0
- package/esm/copilot/useCopilotSnapshot.js +16 -0
- package/esm/copilot.d.ts +11 -0
- package/esm/copilot.d.ts.map +1 -0
- package/esm/copilot.js +12 -0
- package/esm/sdk-ui-gen-ai.d.ts +59 -3
- package/esm/store/chatWindow/chatWindowSlice.d.ts +3 -2
- package/esm/store/chatWindow/chatWindowSlice.d.ts.map +1 -1
- package/esm/store/events.d.ts +59 -4
- package/esm/store/events.d.ts.map +1 -1
- package/esm/store/sideEffects/onDefinitionReceivedTrigger.d.ts.map +1 -1
- package/esm/store/sideEffects/onDefinitionReceivedTrigger.js +11 -1
- package/esm/store/sideEffects/onEvent.d.ts +5 -1
- package/esm/store/sideEffects/onEvent.d.ts.map +1 -1
- package/esm/store/sideEffects/onEvent.js +23 -8
- package/package.json +24 -23
package/README.md
CHANGED
|
@@ -20,6 +20,50 @@ const App = () => {
|
|
|
20
20
|
};
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
+
## Headless copilot workflow (alpha)
|
|
24
|
+
|
|
25
|
+
`CopilotHandler` owns plain immutable workflow state; it requires no Redux setup.
|
|
26
|
+
Register each build type with its reacting skills, pure definition acceptance policy,
|
|
27
|
+
and host application callback. Create one instance per editor/runtime, not a singleton.
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { CopilotBuildType, CopilotHandler } from "@gooddata/sdk-ui-gen-ai/copilot";
|
|
31
|
+
|
|
32
|
+
const copilot = new CopilotHandler({
|
|
33
|
+
registrations: [
|
|
34
|
+
{
|
|
35
|
+
type: CopilotBuildType.Dashboard,
|
|
36
|
+
skills: ["dashboard_builder", "dashboard_editor"],
|
|
37
|
+
resolveDefinition: (event) =>
|
|
38
|
+
event.definitionType === "dashboard" && event.dashboard
|
|
39
|
+
? { type: CopilotBuildType.Dashboard, objectId: event.dashboard.identifier }
|
|
40
|
+
: undefined,
|
|
41
|
+
onApplyDefinition: (event, applicationId, target) => {
|
|
42
|
+
// Install in the host. Dispatching a host action is not completion.
|
|
43
|
+
installDefinition(event).then(
|
|
44
|
+
() => copilot.definitionApplied(applicationId, target),
|
|
45
|
+
() => copilot.definitionApplicationInterrupted(applicationId),
|
|
46
|
+
);
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const unsubscribe = copilot.subscribe(() => {
|
|
53
|
+
renderProgress(copilot.getStatus({ type: CopilotBuildType.Dashboard }));
|
|
54
|
+
});
|
|
55
|
+
copilot.startGeneration(CopilotBuildType.Dashboard);
|
|
56
|
+
// Forward each existing ChatEvent once: copilot.handleEvent(event).
|
|
57
|
+
// On teardown:
|
|
58
|
+
unsubscribe();
|
|
59
|
+
copilot.dispose();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`installDefinition` and `renderProgress` above are application functions. Pure consumers can use
|
|
63
|
+
`transitionCopilot` and the exported selectors directly. React consumers may subscribe with
|
|
64
|
+
`useCopilotSnapshot(copilot)`; the hook adds no workflow owner. Application-owned string enums
|
|
65
|
+
can replace the built-in `CopilotBuildType` without changing the lifecycle algorithm.
|
|
66
|
+
|
|
23
67
|
## License
|
|
24
68
|
|
|
25
69
|
(C) 2017-2026 GoodData Corporation
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type RefObject } from "react";
|
|
2
2
|
import { type IAnalyticalBackend, type IUserWorkspaceSettings } from "@gooddata/sdk-backend-spi";
|
|
3
3
|
import type { GenAIChatEffort, GenAIObjectType, IColorPalette, IGenAIUserContext } from "@gooddata/sdk-model";
|
|
4
|
-
import { type ChatAssistantMessageEvent, type ChatClarificationQuestionsEvent, type ChatClosedEvent, type ChatConversationChangedEvent, type ChatCopyToClipboardEvent, type ChatDefinitionReceivedEvent, type ChatEvent, type ChatFeedbackErrorEvent, type ChatFeedbackEvent, type ChatModeChangeEvent, type ChatOpenedEvent, type ChatReasoningEvent, type ChatResetEvent, type ChatSaveVisualizationErrorEvent, type ChatSaveVisualizationSuccessEvent, type ChatUserMessageEvent } from "../store/events.js";
|
|
4
|
+
import { type ChatAssistantMessageEvent, type ChatClarificationQuestionsEvent, type ChatClosedEvent, type ChatConversationChangedEvent, type ChatCopyToClipboardEvent, type ChatDefinitionReceivedEvent, type ChatEvent, type ChatFeedbackErrorEvent, type ChatFeedbackEvent, type ChatModeChangeEvent, type ChatOpenedEvent, type ChatReasoningEvent, type ChatResetEvent, type ChatSaveVisualizationErrorEvent, type ChatSaveVisualizationSuccessEvent, type ChatUserAnswersEvent, type ChatUserMessageEvent } from "../store/events.js";
|
|
5
5
|
import { type GenAIAssistantDisplayMode, type LinkHandlerEvent } from "./ConfigContext.js";
|
|
6
6
|
import { type GenAIChatDialogProps } from "./GenAIChatDialog.js";
|
|
7
7
|
import { type IDashboardSaved } from "./hooks/useDashboardSavedSync.js";
|
|
@@ -31,6 +31,9 @@ export type GenAIChatConnectedEvent = {
|
|
|
31
31
|
} | {
|
|
32
32
|
name: "user-message";
|
|
33
33
|
payload: ChatUserMessageEvent;
|
|
34
|
+
} | {
|
|
35
|
+
name: "user-answers";
|
|
36
|
+
payload: ChatUserAnswersEvent;
|
|
34
37
|
} | {
|
|
35
38
|
name: "assistant-message";
|
|
36
39
|
payload: ChatAssistantMessageEvent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenAIChatDialogConnected.d.ts","sourceRoot":"","sources":["../../src/components/GenAIChatDialogConnected.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAqD,MAAM,OAAO,CAAC;AAE1F,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACjG,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQ9G,OAAO,EACH,KAAK,yBAAyB,EAC9B,KAAK,+BAA+B,EACpC,KAAK,eAAe,EACpB,KAAK,4BAA4B,EACjC,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,SAAS,EACd,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,+BAA+B,EACpC,KAAK,iCAAiC,EACtC,KAAK,oBAAoB,
|
|
1
|
+
{"version":3,"file":"GenAIChatDialogConnected.d.ts","sourceRoot":"","sources":["../../src/components/GenAIChatDialogConnected.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAqD,MAAM,OAAO,CAAC;AAE1F,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACjG,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,C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AW,EAAE,mBAAmB,EAChC,OAAO,EACP,UAAU,EACV,cAAc,EACd,SAAS,EACT,YAAY,EACZ,gBAAuB,EACvB,WAAW,EACX,aAAa,GAChB,EAAE,8BAA8B,2CAgJhC"}
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { makeUserItem } from "../model.js";
|
|
5
5
|
import { setAmbientUserContextAction, setHistoryAction, setUserContextAction, } from "../store/chatWindow/chatWindowSlice.js";
|
|
6
|
-
import { isChatAssistantMessageEvent, isChatClarificationQuestionsEvent, isChatClosedEvent, isChatConversationChangedEvent, isChatCopyToClipboardEvent, isChatDefinitionReceivedEvent, isChatFeedbackErrorEvent, isChatFeedbackEvent, isChatModeChangeEvent, isChatOpenedEvent, isChatReasoningEvent, isChatResetEvent, isChatSaveVisualizationErrorEvent, isChatSaveVisualizationSuccessEvent, isChatUserMessageEvent, } from "../store/events.js";
|
|
6
|
+
import { isChatAssistantMessageEvent, isChatClarificationQuestionsEvent, isChatClosedEvent, isChatConversationChangedEvent, isChatCopyToClipboardEvent, isChatDefinitionReceivedEvent, isChatFeedbackErrorEvent, isChatFeedbackEvent, isChatModeChangeEvent, isChatOpenedEvent, isChatReasoningEvent, isChatResetEvent, isChatSaveVisualizationErrorEvent, isChatSaveVisualizationSuccessEvent, isChatUserAnswersEvent, isChatUserMessageEvent, } from "../store/events.js";
|
|
7
7
|
import { activateConversationAction, clearThreadAction, newMessageAction, setSelectedAgentAction, setSelectedEffortAction, } from "../store/messages/messagesSlice.js";
|
|
8
8
|
import { GenAIChatDialog } from "./GenAIChatDialog.js";
|
|
9
9
|
import { useDashboardSavedSync } from "./hooks/useDashboardSavedSync.js";
|
|
@@ -25,6 +25,9 @@ export function toGenAIChatConnectedEvent(event) {
|
|
|
25
25
|
else if (isChatUserMessageEvent(event)) {
|
|
26
26
|
return { name: "user-message", payload: event };
|
|
27
27
|
}
|
|
28
|
+
else if (isChatUserAnswersEvent(event)) {
|
|
29
|
+
return { name: "user-answers", payload: event };
|
|
30
|
+
}
|
|
28
31
|
else if (isChatAssistantMessageEvent(event)) {
|
|
29
32
|
return { name: "assistant-message", payload: event };
|
|
30
33
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type ChatEvent } from "../store/events.js";
|
|
2
|
+
import { type CopilotBuildType, type CopilotStatus, type ICopilotApplicationSource, type ICopilotConfiguration, type ICopilotContext, type ICopilotScope, type ICopilotSnapshot, type ICopilotSource, type ICopilotTarget } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Isolated headless workflow owner backed by pure transitions and immutable snapshots.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Create one instance per mounted editor/runtime and dispose it on teardown. Host callbacks run
|
|
8
|
+
* after subscribers observe the committed state; application callbacks require an explicit
|
|
9
|
+
* success or interruption acknowledgement. No application store or React setup is required.
|
|
10
|
+
*
|
|
11
|
+
* @alpha
|
|
12
|
+
*/
|
|
13
|
+
export declare class CopilotHandler<TBuild extends string = CopilotBuildType> {
|
|
14
|
+
private state;
|
|
15
|
+
private readonly listeners;
|
|
16
|
+
private readonly configuration;
|
|
17
|
+
private disposed;
|
|
18
|
+
/** Register pure event policies and host callbacks once for this instance. */
|
|
19
|
+
constructor(configuration: ICopilotConfiguration<TBuild>);
|
|
20
|
+
/** Consume one existing chat event. Ignored after disposal. */
|
|
21
|
+
handleEvent: (event: ChatEvent) => void;
|
|
22
|
+
/** Update host facts without reading routes or application state. */
|
|
23
|
+
setContext: (context: ICopilotContext<TBuild>) => void;
|
|
24
|
+
/** Record an explicit creation intent before seeding the chat. */
|
|
25
|
+
startGeneration: (type: TBuild) => void;
|
|
26
|
+
/** Clear a matching foreground generation intent or build. */
|
|
27
|
+
cancelGeneration: (type: TBuild) => void;
|
|
28
|
+
/** Clear foreground chat progress, preserving background requests and generation intent. */
|
|
29
|
+
resetInteraction: () => void;
|
|
30
|
+
/** Apply a host navigation/reset boundary, preserving applications in progress. */
|
|
31
|
+
resetTarget: (target: ICopilotTarget<TBuild>) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Track a host-initiated application, including an explicit draft-link open.
|
|
34
|
+
* Returns its correlation ID, or an empty string after disposal.
|
|
35
|
+
*/
|
|
36
|
+
definitionApplicationStarted: (source: ICopilotApplicationSource<TBuild>) => string;
|
|
37
|
+
/** Acknowledge installation, using the final applied object identifier. Stale IDs are ignored. */
|
|
38
|
+
definitionApplied: (applicationId: string, target: ICopilotTarget<TBuild>) => void;
|
|
39
|
+
/** Release an interrupted application without cancelling a still-running response. */
|
|
40
|
+
definitionApplicationInterrupted: (applicationId: string) => void;
|
|
41
|
+
/** Read the stable, recursively frozen snapshot. */
|
|
42
|
+
getSnapshot: () => ICopilotSnapshot<TBuild>;
|
|
43
|
+
/** Subscribe directly to changes. The returned function removes this subscription. */
|
|
44
|
+
subscribe: (listener: () => void) => (() => void);
|
|
45
|
+
/** Query the same pure scoped progress selector used by headless consumers. */
|
|
46
|
+
getStatus: (scope: ICopilotScope<TBuild>) => CopilotStatus;
|
|
47
|
+
/** Whether a creation intent or skill-activated creation is still pending. */
|
|
48
|
+
isGenerationPending: (type: TBuild) => boolean;
|
|
49
|
+
/** Read the foreground reasoning heading. */
|
|
50
|
+
getReasoningTitle: () => string | undefined;
|
|
51
|
+
/** Read the origin associated with the applied object, not the selected chat. */
|
|
52
|
+
getAppliedSource: (target: ICopilotTarget<TBuild>) => ICopilotSource | undefined;
|
|
53
|
+
/** Permanently stop processing and release all listeners. Idempotent. */
|
|
54
|
+
dispose: () => void;
|
|
55
|
+
private update;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=CopilotHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CopilotHandler.d.ts","sourceRoot":"","sources":["../../src/copilot/CopilotHandler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,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IAEhE,sFAAsF;IAC/E,SAAS,aAAc,MAAM,IAAI,KAAG,CAAC,MAAM,IAAI,CAAC,CAQrD;IAEF,+EAA+E;IACxE,SAAS,UAAW,aAAa,CAAC,MAAM,CAAC,KAAG,aAAa,CACrB;IAE3C,8EAA8E;IACvE,mBAAmB,SAAU,MAAM,KAAG,OAAO,CAAqD;IAEzG,6CAA6C;IACtC,iBAAiB,QAAO,MAAM,GAAG,SAAS,CAA4C;IAE7F,iFAAiF;IAC1E,gBAAgB,WAAY,cAAc,CAAC,MAAM,CAAC,KAAG,cAAc,GAAG,SAAS,CAC1C;IAE5C,yEAAyE;IAClE,OAAO,QAAO,IAAI,CAGvB;IAEF,OAAO,CAAC,MAAM;CAgBjB"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// (C) 2026 GoodData Corporation
|
|
2
|
+
import { v4 as uuid } from "uuid";
|
|
3
|
+
import { selectCopilotGenerationPending, selectCopilotReasoningTitle, selectCopilotSource, selectCopilotStatus, } from "./selectors.js";
|
|
4
|
+
import { createCopilotState, transitionCopilot } from "./transitions.js";
|
|
5
|
+
function freeze(value) {
|
|
6
|
+
if (value && typeof value === "object" && !Object.isFrozen(value)) {
|
|
7
|
+
Object.values(value).forEach(freeze);
|
|
8
|
+
Object.freeze(value);
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Isolated headless workflow owner backed by pure transitions and immutable snapshots.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Create one instance per mounted editor/runtime and dispose it on teardown. Host callbacks run
|
|
17
|
+
* after subscribers observe the committed state; application callbacks require an explicit
|
|
18
|
+
* success or interruption acknowledgement. No application store or React setup is required.
|
|
19
|
+
*
|
|
20
|
+
* @alpha
|
|
21
|
+
*/
|
|
22
|
+
export class CopilotHandler {
|
|
23
|
+
state = freeze(createCopilotState());
|
|
24
|
+
listeners = new Set();
|
|
25
|
+
configuration;
|
|
26
|
+
disposed = false;
|
|
27
|
+
/** Register pure event policies and host callbacks once for this instance. */
|
|
28
|
+
constructor(configuration) {
|
|
29
|
+
this.configuration = {
|
|
30
|
+
...configuration,
|
|
31
|
+
registrations: configuration.registrations.map((entry) => ({
|
|
32
|
+
...entry,
|
|
33
|
+
skills: [...entry.skills],
|
|
34
|
+
})),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Consume one existing chat event. Ignored after disposal. */
|
|
38
|
+
handleEvent = (event) => {
|
|
39
|
+
if (this.disposed) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (event.type === "onDefinitionReceived") {
|
|
43
|
+
for (const registration of this.configuration.registrations) {
|
|
44
|
+
const target = registration.resolveDefinition(event, this.state.context, this.state);
|
|
45
|
+
if (!target || target.type !== registration.type) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const applicationId = this.definitionApplicationStarted({
|
|
49
|
+
target,
|
|
50
|
+
conversationId: event.conversationId,
|
|
51
|
+
threadId: event.threadId,
|
|
52
|
+
});
|
|
53
|
+
if (this.disposed || !this.state.applications.some((entry) => entry.id === applicationId)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
registration.onApplyDefinition(event, applicationId, target);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
this.definitionApplicationInterrupted(applicationId);
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const previous = this.state;
|
|
68
|
+
this.update({ kind: "event", event });
|
|
69
|
+
if (!this.disposed &&
|
|
70
|
+
event.type === "chatClarificationQuestions" &&
|
|
71
|
+
event.responses === undefined &&
|
|
72
|
+
event.questions.length > 0 &&
|
|
73
|
+
!previous.interaction.pendingClarificationIds.includes(event.interactionId) &&
|
|
74
|
+
!previous.requests.some((request) => request.pendingClarificationIds?.includes(event.interactionId)) &&
|
|
75
|
+
this.configuration.registrations.some(({ type }) => this.getStatus({
|
|
76
|
+
type,
|
|
77
|
+
objectId: this.state.context.objectId,
|
|
78
|
+
isEditing: this.state.context.isEditing,
|
|
79
|
+
isBuilder: !!this.state.context.builderTarget,
|
|
80
|
+
}) !== "idle")) {
|
|
81
|
+
this.configuration.onClarificationQuestions?.(event);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
/** Update host facts without reading routes or application state. */
|
|
85
|
+
setContext = (context) => {
|
|
86
|
+
this.update({ kind: "context", context });
|
|
87
|
+
};
|
|
88
|
+
/** Record an explicit creation intent before seeding the chat. */
|
|
89
|
+
startGeneration = (type) => {
|
|
90
|
+
this.update({ kind: "startGeneration", type });
|
|
91
|
+
};
|
|
92
|
+
/** Clear a matching foreground generation intent or build. */
|
|
93
|
+
cancelGeneration = (type) => {
|
|
94
|
+
this.update({ kind: "cancelGeneration", type });
|
|
95
|
+
};
|
|
96
|
+
/** Clear foreground chat progress, preserving background requests and generation intent. */
|
|
97
|
+
resetInteraction = () => {
|
|
98
|
+
this.update({ kind: "resetInteraction" });
|
|
99
|
+
};
|
|
100
|
+
/** Apply a host navigation/reset boundary, preserving applications in progress. */
|
|
101
|
+
resetTarget = (target) => {
|
|
102
|
+
this.update({ kind: "resetTarget", target });
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Track a host-initiated application, including an explicit draft-link open.
|
|
106
|
+
* Returns its correlation ID, or an empty string after disposal.
|
|
107
|
+
*/
|
|
108
|
+
definitionApplicationStarted = (source) => {
|
|
109
|
+
if (this.disposed) {
|
|
110
|
+
return "";
|
|
111
|
+
}
|
|
112
|
+
const id = uuid();
|
|
113
|
+
this.update({ kind: "applicationStarted", id, source });
|
|
114
|
+
return id;
|
|
115
|
+
};
|
|
116
|
+
/** Acknowledge installation, using the final applied object identifier. Stale IDs are ignored. */
|
|
117
|
+
definitionApplied = (applicationId, target) => {
|
|
118
|
+
this.update({ kind: "applicationApplied", id: applicationId, target });
|
|
119
|
+
};
|
|
120
|
+
/** Release an interrupted application without cancelling a still-running response. */
|
|
121
|
+
definitionApplicationInterrupted = (applicationId) => {
|
|
122
|
+
this.update({ kind: "applicationInterrupted", id: applicationId });
|
|
123
|
+
};
|
|
124
|
+
/** Read the stable, recursively frozen snapshot. */
|
|
125
|
+
getSnapshot = () => this.state;
|
|
126
|
+
/** Subscribe directly to changes. The returned function removes this subscription. */
|
|
127
|
+
subscribe = (listener) => {
|
|
128
|
+
if (this.disposed) {
|
|
129
|
+
return () => { };
|
|
130
|
+
}
|
|
131
|
+
this.listeners.add(listener);
|
|
132
|
+
return () => {
|
|
133
|
+
this.listeners.delete(listener);
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
/** Query the same pure scoped progress selector used by headless consumers. */
|
|
137
|
+
getStatus = (scope) => selectCopilotStatus(this.state, scope);
|
|
138
|
+
/** Whether a creation intent or skill-activated creation is still pending. */
|
|
139
|
+
isGenerationPending = (type) => selectCopilotGenerationPending(this.state, type);
|
|
140
|
+
/** Read the foreground reasoning heading. */
|
|
141
|
+
getReasoningTitle = () => selectCopilotReasoningTitle(this.state);
|
|
142
|
+
/** Read the origin associated with the applied object, not the selected chat. */
|
|
143
|
+
getAppliedSource = (target) => selectCopilotSource(this.state, target);
|
|
144
|
+
/** Permanently stop processing and release all listeners. Idempotent. */
|
|
145
|
+
dispose = () => {
|
|
146
|
+
this.disposed = true;
|
|
147
|
+
this.listeners.clear();
|
|
148
|
+
};
|
|
149
|
+
update(input) {
|
|
150
|
+
if (this.disposed) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const next = transitionCopilot(this.state, input, this.configuration);
|
|
154
|
+
if (next === this.state) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.state = freeze(next);
|
|
158
|
+
const listeners = Array.from(this.listeners);
|
|
159
|
+
for (const listener of listeners) {
|
|
160
|
+
if (!this.disposed && this.listeners.has(listener)) {
|
|
161
|
+
listener();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CopilotBuildType, type CopilotStatus, type ICopilotScope, type ICopilotSnapshot, type ICopilotSource, type ICopilotTarget } from "./types.js";
|
|
2
|
+
/** Whether creation is pending, including an activated creation build. @alpha */
|
|
3
|
+
export declare function selectCopilotGenerationPending<TBuild extends string = CopilotBuildType>(state: ICopilotSnapshot<TBuild>, type: TBuild): boolean;
|
|
4
|
+
/** Calculate progress without host presentation rules or side effects. @alpha */
|
|
5
|
+
export declare function selectCopilotStatus<TBuild extends string = CopilotBuildType>(state: ICopilotSnapshot<TBuild>, scope: ICopilotScope<TBuild>): CopilotStatus;
|
|
6
|
+
/** Query the originating conversation of an applied object. @alpha */
|
|
7
|
+
export declare function selectCopilotSource<TBuild extends string = CopilotBuildType>(state: ICopilotSnapshot<TBuild>, target: ICopilotTarget<TBuild>): ICopilotSource | undefined;
|
|
8
|
+
/** Query the current foreground reasoning heading. @alpha */
|
|
9
|
+
export declare function selectCopilotReasoningTitle<TBuild extends string = CopilotBuildType>(state: ICopilotSnapshot<TBuild>): string | undefined;
|
|
10
|
+
//# sourceMappingURL=selectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/copilot/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,cAAc,EACtB,MAAM,YAAY,CAAC;AAEpB,iFAAiF;AACjF,wBAAgB,8BAA8B,CAAC,MAAM,SAAS,MAAM,GAAG,gBAAgB,EACnF,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAC/B,IAAI,EAAE,MAAM,GACb,OAAO,CAKT;AAED,iFAAiF;AACjF,wBAAgB,mBAAmB,CAAC,MAAM,SAAS,MAAM,GAAG,gBAAgB,EACxE,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAC/B,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,GAC7B,aAAa,CAmCf;AAED,sEAAsE;AACtE,wBAAgB,mBAAmB,CAAC,MAAM,SAAS,MAAM,GAAG,gBAAgB,EACxE,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAC/B,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,GAC/B,cAAc,GAAG,SAAS,CAI5B;AAED,6DAA6D;AAC7D,wBAAgB,2BAA2B,CAAC,MAAM,SAAS,MAAM,GAAG,gBAAgB,EAChF,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAChC,MAAM,GAAG,SAAS,CAEpB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// (C) 2026 GoodData Corporation
|
|
2
|
+
/** Whether creation is pending, including an activated creation build. @alpha */
|
|
3
|
+
export function selectCopilotGenerationPending(state, type) {
|
|
4
|
+
return (state.generation === type ||
|
|
5
|
+
(state.interaction.build?.type === type && state.interaction.build.intent === "create"));
|
|
6
|
+
}
|
|
7
|
+
/** Calculate progress without host presentation rules or side effects. @alpha */
|
|
8
|
+
export function selectCopilotStatus(state, scope) {
|
|
9
|
+
if (state.applications.some(({ target }) => target.type === scope.type &&
|
|
10
|
+
(scope.objectId === undefined || target.objectId === scope.objectId))) {
|
|
11
|
+
return "building";
|
|
12
|
+
}
|
|
13
|
+
if (scope.isEditing) {
|
|
14
|
+
const requests = state.requests.filter((request) => request.type === scope.type &&
|
|
15
|
+
(scope.objectId === undefined || request.objectId === scope.objectId));
|
|
16
|
+
if (requests.length) {
|
|
17
|
+
return requests.every((request) => request.awaitingClarification && !request.applicationIds.length)
|
|
18
|
+
? "waiting"
|
|
19
|
+
: "building";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const interaction = state.interaction;
|
|
23
|
+
if (selectCopilotGenerationPending(state, scope.type) ||
|
|
24
|
+
(scope.isBuilder && interaction.build?.type === scope.type)) {
|
|
25
|
+
if (interaction.waitingForUserInput || interaction.pendingClarificationIds.length) {
|
|
26
|
+
return "waiting";
|
|
27
|
+
}
|
|
28
|
+
return interaction.build ? "building" : "generating";
|
|
29
|
+
}
|
|
30
|
+
return "idle";
|
|
31
|
+
}
|
|
32
|
+
/** Query the originating conversation of an applied object. @alpha */
|
|
33
|
+
export function selectCopilotSource(state, target) {
|
|
34
|
+
return state.sources.find((entry) => entry.target.type === target.type && entry.target.objectId === target.objectId)?.source;
|
|
35
|
+
}
|
|
36
|
+
/** Query the current foreground reasoning heading. @alpha */
|
|
37
|
+
export function selectCopilotReasoningTitle(state) {
|
|
38
|
+
return state.interaction.reasoningTitle;
|
|
39
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type CopilotBuildType, type CopilotInput, type ICopilotConfiguration, type ICopilotSnapshot } from "./types.js";
|
|
2
|
+
/** Create an independent, empty workflow state. @alpha */
|
|
3
|
+
export declare function createCopilotState<TBuild extends string = CopilotBuildType>(): ICopilotSnapshot<TBuild>;
|
|
4
|
+
/** Deterministic immutable transition; never allocates IDs, invokes effects, or performs I/O. @alpha */
|
|
5
|
+
export declare function transitionCopilot<TBuild extends string = CopilotBuildType>(state: ICopilotSnapshot<TBuild>, input: CopilotInput<TBuild>, configuration: ICopilotConfiguration<TBuild>): ICopilotSnapshot<TBuild>;
|
|
6
|
+
//# sourceMappingURL=transitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transitions.d.ts","sourceRoot":"","sources":["../../src/copilot/transitions.ts"],"names":[],"mappings":"AASA,OAAO,EACH,KAAK,gBAAgB,EACrB,KAAK,YAAY,EAEjB,KAAK,qBAAqB,EAK1B,KAAK,gBAAgB,EAExB,MAAM,YAAY,CAAC;AAEpB,0DAA0D;AAC1D,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,MAAM,GAAG,gBAAgB,KAAK,gBAAgB,CAAC,MAAM,CAAC,CASvG;AA4gBD,wGAAwG;AACxG,wBAAgB,iBAAiB,CAAC,MAAM,SAAS,MAAM,GAAG,gBAAgB,EACtE,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAC/B,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,EAC3B,aAAa,EAAE,qBAAqB,CAAC,MAAM,CAAC,GAC7C,gBAAgB,CAAC,MAAM,CAAC,CA8B1B"}
|