@harnessio/ui3-ai-chat 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat-constants.d.ts +14 -0
- package/dist/chat-constants.d.ts.map +1 -0
- package/dist/chat-constants.js +13 -0
- package/dist/chat-drawer-layout.d.ts +10 -0
- package/dist/chat-drawer-layout.d.ts.map +1 -0
- package/dist/chat-drawer-layout.js +66 -0
- package/dist/chat-header.d.ts +13 -0
- package/dist/chat-header.d.ts.map +1 -0
- package/dist/chat-header.js +45 -0
- package/dist/chat-history.d.ts +6 -0
- package/dist/chat-history.d.ts.map +1 -0
- package/dist/chat-history.js +119 -0
- package/dist/chat-homepage-body.d.ts +5 -0
- package/dist/chat-homepage-body.d.ts.map +1 -0
- package/dist/chat-homepage-body.js +17 -0
- package/dist/chat-input-plus-menu.d.ts +2 -0
- package/dist/chat-input-plus-menu.d.ts.map +1 -0
- package/dist/chat-input-plus-menu.js +15 -0
- package/dist/chat-input.d.ts +2 -0
- package/dist/chat-input.d.ts.map +1 -0
- package/dist/chat-input.js +65 -0
- package/dist/chat-layout.d.ts +14 -0
- package/dist/chat-layout.d.ts.map +1 -0
- package/dist/chat-layout.js +16 -0
- package/dist/chat-message-list.d.ts +13 -0
- package/dist/chat-message-list.d.ts.map +1 -0
- package/dist/chat-message-list.js +13 -0
- package/dist/chat-panel-body.d.ts +5 -0
- package/dist/chat-panel-body.d.ts.map +1 -0
- package/dist/chat-panel-body.js +17 -0
- package/dist/chat-scroll-fade.d.ts +9 -0
- package/dist/chat-scroll-fade.d.ts.map +1 -0
- package/dist/chat-scroll-fade.js +22 -0
- package/dist/chat-speech-button.d.ts +7 -0
- package/dist/chat-speech-button.d.ts.map +1 -0
- package/dist/chat-speech-button.js +12 -0
- package/dist/chat.d.ts +5 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +18 -0
- package/dist/context/chat-event-context.d.ts +10 -0
- package/dist/context/chat-event-context.d.ts.map +1 -0
- package/dist/context/chat-event-context.js +9 -0
- package/dist/context/chat-host-context.d.ts +22 -0
- package/dist/context/chat-host-context.d.ts.map +1 -0
- package/dist/context/chat-host-context.js +27 -0
- package/dist/context/chat-position-context.d.ts +14 -0
- package/dist/context/chat-position-context.d.ts.map +1 -0
- package/dist/context/chat-position-context.js +17 -0
- package/dist/default-chat-welcome.d.ts +7 -0
- package/dist/default-chat-welcome.d.ts.map +1 -0
- package/dist/default-chat-welcome.js +37 -0
- package/dist/error-boundaries/chat-error-boundary.d.ts +15 -0
- package/dist/error-boundaries/chat-error-boundary.d.ts.map +1 -0
- package/dist/error-boundaries/chat-error-boundary.js +18 -0
- package/dist/error-boundaries/index.d.ts +3 -0
- package/dist/error-boundaries/index.d.ts.map +1 -0
- package/dist/error-boundaries/index.js +2 -0
- package/dist/error-boundaries/message-error-boundary.d.ts +15 -0
- package/dist/error-boundaries/message-error-boundary.d.ts.map +1 -0
- package/dist/error-boundaries/message-error-boundary.js +18 -0
- package/dist/harness-loader/harness-loader-blades.d.ts +21 -0
- package/dist/harness-loader/harness-loader-blades.d.ts.map +1 -0
- package/dist/harness-loader/harness-loader-blades.js +25 -0
- package/dist/harness-loader/harness-loader.css +335 -0
- package/dist/harness-loader/harness-loader.d.ts +8 -0
- package/dist/harness-loader/harness-loader.d.ts.map +1 -0
- package/dist/harness-loader/harness-loader.js +9 -0
- package/dist/hooks/use-chat-content-state.d.ts +23 -0
- package/dist/hooks/use-chat-content-state.d.ts.map +1 -0
- package/dist/hooks/use-chat-content-state.js +97 -0
- package/dist/hooks/use-chat-mcp-connectors.d.ts +4 -0
- package/dist/hooks/use-chat-mcp-connectors.d.ts.map +1 -0
- package/dist/hooks/use-chat-mcp-connectors.js +5 -0
- package/dist/hooks/use-chat-tracking.d.ts +19 -0
- package/dist/hooks/use-chat-tracking.d.ts.map +1 -0
- package/dist/hooks/use-chat-tracking.js +84 -0
- package/dist/hooks/use-idle-session-prompt.d.ts +13 -0
- package/dist/hooks/use-idle-session-prompt.d.ts.map +1 -0
- package/dist/hooks/use-idle-session-prompt.js +147 -0
- package/dist/hooks/use-speech-to-text.d.ts +49 -0
- package/dist/hooks/use-speech-to-text.d.ts.map +1 -0
- package/dist/hooks/use-speech-to-text.js +117 -0
- package/dist/idle-session-banner.d.ts +6 -0
- package/dist/idle-session-banner.d.ts.map +1 -0
- package/dist/idle-session-banner.js +13 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/plugins/core-plugin.d.ts +3 -0
- package/dist/plugins/core-plugin.d.ts.map +1 -0
- package/dist/plugins/core-plugin.js +47 -0
- package/dist/providers/chat-runtime-provider.d.ts +10 -0
- package/dist/providers/chat-runtime-provider.d.ts.map +1 -0
- package/dist/providers/chat-runtime-provider.js +15 -0
- package/dist/renderers/elicitation/confirm-renderer.d.ts +4 -0
- package/dist/renderers/elicitation/confirm-renderer.d.ts.map +1 -0
- package/dist/renderers/elicitation/confirm-renderer.js +16 -0
- package/dist/renderers/elicitation/free-text-renderer.d.ts +4 -0
- package/dist/renderers/elicitation/free-text-renderer.d.ts.map +1 -0
- package/dist/renderers/elicitation/free-text-renderer.js +25 -0
- package/dist/renderers/elicitation/index.d.ts +5 -0
- package/dist/renderers/elicitation/index.d.ts.map +1 -0
- package/dist/renderers/elicitation/index.js +4 -0
- package/dist/renderers/elicitation/multi-select-renderer.d.ts +4 -0
- package/dist/renderers/elicitation/multi-select-renderer.d.ts.map +1 -0
- package/dist/renderers/elicitation/multi-select-renderer.js +47 -0
- package/dist/renderers/elicitation/select-renderer.d.ts +4 -0
- package/dist/renderers/elicitation/select-renderer.d.ts.map +1 -0
- package/dist/renderers/elicitation/select-renderer.js +32 -0
- package/dist/renderers/elicitation/shared.d.ts +146 -0
- package/dist/renderers/elicitation/shared.d.ts.map +1 -0
- package/dist/renderers/elicitation/shared.js +237 -0
- package/dist/renderers/error-renderer.d.ts +3 -0
- package/dist/renderers/error-renderer.d.ts.map +1 -0
- package/dist/renderers/error-renderer.js +11 -0
- package/dist/renderers/file-renderer.d.ts +12 -0
- package/dist/renderers/file-renderer.d.ts.map +1 -0
- package/dist/renderers/file-renderer.js +35 -0
- package/dist/renderers/follow-up-prompts-renderer.d.ts +3 -0
- package/dist/renderers/follow-up-prompts-renderer.d.ts.map +1 -0
- package/dist/renderers/follow-up-prompts-renderer.js +55 -0
- package/dist/renderers/prompts-renderer.d.ts +14 -0
- package/dist/renderers/prompts-renderer.d.ts.map +1 -0
- package/dist/renderers/prompts-renderer.js +5 -0
- package/dist/renderers/suggestions-renderer.d.ts +3 -0
- package/dist/renderers/suggestions-renderer.d.ts.map +1 -0
- package/dist/renderers/suggestions-renderer.js +24 -0
- package/dist/renderers/table-renderer.d.ts +22 -0
- package/dist/renderers/table-renderer.d.ts.map +1 -0
- package/dist/renderers/table-renderer.js +49 -0
- package/dist/renderers/text-renderer.d.ts +10 -0
- package/dist/renderers/text-renderer.d.ts.map +1 -0
- package/dist/renderers/text-renderer.js +10 -0
- package/dist/renderers/thought-process.d.ts +10 -0
- package/dist/renderers/thought-process.d.ts.map +1 -0
- package/dist/renderers/thought-process.js +8 -0
- package/dist/renderers/tool-call-renderer.d.ts +12 -0
- package/dist/renderers/tool-call-renderer.d.ts.map +1 -0
- package/dist/renderers/tool-call-renderer.js +37 -0
- package/dist/stores/chat-input-options-store.d.ts +9 -0
- package/dist/stores/chat-input-options-store.d.ts.map +1 -0
- package/dist/stores/chat-input-options-store.js +6 -0
- package/dist/stores/chat-settings-store.d.ts +11 -0
- package/dist/stores/chat-settings-store.d.ts.map +1 -0
- package/dist/stores/chat-settings-store.js +8 -0
- package/dist/stores/idle-session-prompt-store.d.ts +21 -0
- package/dist/stores/idle-session-prompt-store.d.ts.map +1 -0
- package/dist/stores/idle-session-prompt-store.js +34 -0
- package/dist/styles.css +129 -0
- package/dist/thread-actions-menu.d.ts +11 -0
- package/dist/thread-actions-menu.d.ts.map +1 -0
- package/dist/thread-actions-menu.js +55 -0
- package/dist/truncated-chip-label.d.ts +12 -0
- package/dist/truncated-chip-label.d.ts.map +1 -0
- package/dist/truncated-chip-label.js +11 -0
- package/dist/types/chat-events.d.ts +18 -0
- package/dist/types/chat-events.d.ts.map +1 -0
- package/dist/types/chat-events.js +1 -0
- package/dist/types/chat-layout.d.ts +9 -0
- package/dist/types/chat-layout.d.ts.map +1 -0
- package/dist/types/chat-layout.js +8 -0
- package/dist/utils/sentence-case.d.ts +2 -0
- package/dist/utils/sentence-case.d.ts.map +1 -0
- package/dist/utils/sentence-case.js +14 -0
- package/dist/utils/time-utils.d.ts +7 -0
- package/dist/utils/time-utils.d.ts.map +1 -0
- package/dist/utils/time-utils.js +27 -0
- package/package.json +51 -3
- package/README.md +0 -3
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
3
|
+
import { Button, Card, Checkbox, Layout, Text } from '@harnessio/ui/components';
|
|
4
|
+
import { ElicitationCard, useElicitationAction } from './shared';
|
|
5
|
+
function MultiSelectInlineRenderer({ message, content }) {
|
|
6
|
+
const data = content.data;
|
|
7
|
+
const { state, actingId, submittedValues, handleAction } = useElicitationAction(data, message);
|
|
8
|
+
const items = data?.content.items || [];
|
|
9
|
+
const question = data?.content.question || data?.title || '';
|
|
10
|
+
const disabled = state !== 'pending';
|
|
11
|
+
const [selectedIds, setSelectedIds] = useState(new Set());
|
|
12
|
+
const handleToggle = useCallback((itemId) => {
|
|
13
|
+
if (disabled)
|
|
14
|
+
return;
|
|
15
|
+
setSelectedIds(prev => {
|
|
16
|
+
const next = new Set(prev);
|
|
17
|
+
if (next.has(itemId))
|
|
18
|
+
next.delete(itemId);
|
|
19
|
+
else
|
|
20
|
+
next.add(itemId);
|
|
21
|
+
return next;
|
|
22
|
+
});
|
|
23
|
+
}, [disabled]);
|
|
24
|
+
const handleSubmit = useCallback(() => {
|
|
25
|
+
if (selectedIds.size === 0)
|
|
26
|
+
return;
|
|
27
|
+
const selectedLabels = items.filter(item => selectedIds.has(item.id)).map(item => item.label);
|
|
28
|
+
handleAction('respond', { selection: selectedLabels.join(', '), selections: selectedLabels });
|
|
29
|
+
}, [selectedIds, items, handleAction]);
|
|
30
|
+
if (!data)
|
|
31
|
+
return null;
|
|
32
|
+
return (_jsxs(ElicitationCard, { data: data, icon: "list", state: state, actingId: actingId, submittedValues: submittedValues, children: [question && question !== data.title && (_jsx(Text, { variant: "body-normal", color: "foreground-1", children: question })), state === 'pending' && (_jsx(Text, { variant: "caption-normal", color: "foreground-3", children: "Select one or more options, then click Submit" })), _jsx(Layout.Vertical, { gap: "xs", children: items.map(item => {
|
|
33
|
+
const isSelected = selectedIds.has(item.id);
|
|
34
|
+
return (_jsx(Card.Root, { size: "sm", className: disabled
|
|
35
|
+
? isSelected
|
|
36
|
+
? 'border-cn-blue-border'
|
|
37
|
+
: 'opacity-50'
|
|
38
|
+
: isSelected
|
|
39
|
+
? 'border-cn-blue-border cursor-pointer'
|
|
40
|
+
: 'hover:border-cn-blue-border cursor-pointer transition-colors', onClick: () => handleToggle(item.id), children: _jsx(Card.Content, { className: "py-cn-xs", children: _jsxs(Layout.Horizontal, { align: "center", gap: "xs", children: [_jsx(Checkbox, { checked: isSelected, className: "pointer-events-none shrink-0" }), _jsxs(Layout.Vertical, { gap: "none", children: [_jsx(Text, { variant: "body-normal", color: disabled && !isSelected ? 'foreground-3' : 'foreground-1', children: item.label }), item.description && (_jsx(Text, { variant: "caption-normal", color: "foreground-3", children: item.description }))] })] }) }) }, item.id));
|
|
41
|
+
}) }), state === 'pending' && (_jsxs(Button, { variant: "outline", size: "sm", disabled: selectedIds.size === 0, onClick: handleSubmit, children: ["Submit (", selectedIds.size, " selected)"] }))] }));
|
|
42
|
+
}
|
|
43
|
+
export const multiSelectRenderer = {
|
|
44
|
+
type: 'elicitation_multi_select',
|
|
45
|
+
component: MultiSelectInlineRenderer,
|
|
46
|
+
priority: 2
|
|
47
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-renderer.d.ts","sourceRoot":"","sources":["../../../src/renderers/elicitation/select-renderer.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAW,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAGlE,OAAO,EAAkC,kBAAkB,EAAyC,MAAM,UAAU,CAAA;AA6FpH,eAAO,MAAM,cAAc,EAAE,eAAe,CAAC,kBAAkB,CAI9D,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { Button, Card, IconV2, Layout, Text } from '@harnessio/ui/components';
|
|
4
|
+
import { ActionButtons, ElicitationCard, useElicitationAction } from './shared';
|
|
5
|
+
function SelectInlineRenderer({ message, content }) {
|
|
6
|
+
const data = content.data;
|
|
7
|
+
const { state, actingId, submittedValues, handleAction } = useElicitationAction(data, message);
|
|
8
|
+
const items = data?.content.items || [];
|
|
9
|
+
const question = data?.content.question || data?.title || '';
|
|
10
|
+
const disabled = state !== 'pending';
|
|
11
|
+
const handleSelect = useCallback((itemId) => {
|
|
12
|
+
if (disabled || !data)
|
|
13
|
+
return;
|
|
14
|
+
const selected = items.find(item => item.id === itemId);
|
|
15
|
+
handleAction('respond', { selection: selected?.label || itemId });
|
|
16
|
+
}, [disabled, data, items, handleAction]);
|
|
17
|
+
if (!data)
|
|
18
|
+
return null;
|
|
19
|
+
const usePills = items.length <= 4;
|
|
20
|
+
return (_jsxs(ElicitationCard, { data: data, icon: "list", state: state, actingId: actingId, submittedValues: submittedValues, children: [question && question !== data.title && (_jsx(Text, { variant: "body-normal", color: "foreground-1", children: question })), usePills ? (_jsx(Layout.Horizontal, { gap: "xs", className: "flex-wrap", children: items.map(item => (_jsxs(Button, { variant: actingId === item.id ? 'secondary' : 'outline', size: "sm", disabled: disabled, loading: state === 'acting' && actingId === item.id, onClick: () => handleSelect(item.id), children: [actingId === item.id && _jsx(IconV2, { name: "check", size: "xs" }), item.label] }, item.id))) })) : (_jsxs(_Fragment, { children: [_jsx(Layout.Vertical, { gap: "xs", children: items.map(item => (_jsx(Card.Root, { size: "sm", className: disabled
|
|
21
|
+
? actingId === item.id
|
|
22
|
+
? 'border-cn-blue-border'
|
|
23
|
+
: 'opacity-50'
|
|
24
|
+
: actingId === item.id
|
|
25
|
+
? 'border-cn-blue-border cursor-pointer'
|
|
26
|
+
: 'hover:border-cn-blue-border cursor-pointer transition-colors', onClick: () => handleSelect(item.id), children: _jsx(Card.Content, { className: "py-cn-xs", children: _jsxs(Layout.Horizontal, { align: "center", gap: "xs", children: [actingId === item.id && _jsx(IconV2, { name: "check", size: "xs", color: "success" }), _jsxs(Layout.Vertical, { gap: "none", children: [_jsx(Text, { variant: "body-normal", color: disabled && actingId !== item.id ? 'foreground-3' : 'foreground-1', children: item.label }), item.description && (_jsx(Text, { variant: "caption-normal", color: "foreground-3", children: item.description }))] })] }) }) }, item.id))) }), _jsx(ActionButtons, { actions: data.actions, state: state, actingId: actingId, onAction: id => handleSelect(id) })] }))] }));
|
|
27
|
+
}
|
|
28
|
+
export const selectRenderer = {
|
|
29
|
+
type: 'elicitation_select',
|
|
30
|
+
component: SelectInlineRenderer,
|
|
31
|
+
priority: 2
|
|
32
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Message, MessageContent } from '@harnessio/ai-chat-core';
|
|
2
|
+
import { type IconV2NamesType } from '@harnessio/ui/components';
|
|
3
|
+
export interface ElicitationAction {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
variant?: 'primary' | 'ghost' | 'destructive' | 'outline';
|
|
7
|
+
sends?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface SelectionItem {
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
preview?: string;
|
|
14
|
+
cost?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface FormField<Props = Record<string, unknown>> {
|
|
17
|
+
key: string;
|
|
18
|
+
label: string;
|
|
19
|
+
header?: string;
|
|
20
|
+
type: 'text' | 'select' | 'multi_select' | 'toggle' | 'number' | 'connector' | 'secret' | 'user_groups' | 'pipeline' | 'org' | 'project';
|
|
21
|
+
value?: unknown;
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
options?: Array<{
|
|
24
|
+
label: string;
|
|
25
|
+
value: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
}>;
|
|
28
|
+
required?: boolean;
|
|
29
|
+
validation?: {
|
|
30
|
+
minLength?: number;
|
|
31
|
+
maxLength?: number;
|
|
32
|
+
pattern?: string;
|
|
33
|
+
min?: number;
|
|
34
|
+
max?: number;
|
|
35
|
+
};
|
|
36
|
+
/** Optional connector type filter (additive; from present_form). */
|
|
37
|
+
connector_types?: string[];
|
|
38
|
+
/** Optional secret type filter (additive; from present_form). */
|
|
39
|
+
secret_type?: string;
|
|
40
|
+
/** Arbitrary key-value props for field renderers (e.g. org_identifier/project_identifier for pipeline field). */
|
|
41
|
+
props?: Props;
|
|
42
|
+
/**
|
|
43
|
+
* Agent-declared dependencies: `{ <prop name>: <key of another field in this form> }`.
|
|
44
|
+
* The prop takes that field's live value (overriding `props`), the picker stays disabled until
|
|
45
|
+
* every source has a value, and the field is cleared whenever a source changes.
|
|
46
|
+
*/
|
|
47
|
+
props_from?: Record<string, string>;
|
|
48
|
+
}
|
|
49
|
+
export interface ReviewDetail {
|
|
50
|
+
label: string;
|
|
51
|
+
value: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ResolvedElicitation {
|
|
54
|
+
event_type: string;
|
|
55
|
+
action_id: string;
|
|
56
|
+
result?: Record<string, unknown>;
|
|
57
|
+
resolved_at?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface ElicitationData {
|
|
60
|
+
review_id: string;
|
|
61
|
+
source?: 'llm' | 'mcp' | 'agent';
|
|
62
|
+
title: string;
|
|
63
|
+
subtitle?: string;
|
|
64
|
+
content: {
|
|
65
|
+
question?: string;
|
|
66
|
+
items?: SelectionItem[];
|
|
67
|
+
allow_multiple?: boolean;
|
|
68
|
+
placeholder?: string;
|
|
69
|
+
max_length?: number;
|
|
70
|
+
fields?: FormField[];
|
|
71
|
+
summary?: string;
|
|
72
|
+
details?: ReviewDetail[];
|
|
73
|
+
yaml?: string;
|
|
74
|
+
original_yaml?: string;
|
|
75
|
+
language?: string;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Optional renderer hint sent by the backend to choose between alternate
|
|
79
|
+
* presentations of the same elicitation type (e.g. variant: 'dbops_changeset'
|
|
80
|
+
* for the Liquibase changeset drawer experience).
|
|
81
|
+
*/
|
|
82
|
+
renderer?: {
|
|
83
|
+
type?: string;
|
|
84
|
+
variant?: string;
|
|
85
|
+
};
|
|
86
|
+
entity_info?: Record<string, unknown>;
|
|
87
|
+
tool_input?: Record<string, unknown>;
|
|
88
|
+
actions: ElicitationAction[];
|
|
89
|
+
editable?: boolean;
|
|
90
|
+
resolved?: ResolvedElicitation;
|
|
91
|
+
status?: 'open' | 'superseded' | 'expired';
|
|
92
|
+
expires_at?: string;
|
|
93
|
+
}
|
|
94
|
+
export interface ElicitationContent<T extends ElicitationData = ElicitationData> extends MessageContent<T> {
|
|
95
|
+
type: string;
|
|
96
|
+
}
|
|
97
|
+
export type ReviewState = 'pending' | 'acting' | 'completed' | 'cancelled' | 'superseded' | 'expired';
|
|
98
|
+
/**
|
|
99
|
+
* Derive the card's lifecycle state:
|
|
100
|
+
* - resolved payload -> completed / cancelled
|
|
101
|
+
* - live status=superseded -> superseded (user sent a new message)
|
|
102
|
+
* - expires_at in the past -> expired
|
|
103
|
+
* - otherwise -> pending (actionable, including from history)
|
|
104
|
+
*/
|
|
105
|
+
export declare function deriveElicitationState(data: ElicitationData | undefined): ReviewState;
|
|
106
|
+
export declare function ResolvedCard({ title, actionId, submittedValues }: {
|
|
107
|
+
title: string;
|
|
108
|
+
actionId: string;
|
|
109
|
+
submittedValues?: Record<string, unknown>;
|
|
110
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
111
|
+
export declare function TerminalCard({ title, subtitle, icon }: {
|
|
112
|
+
title: string;
|
|
113
|
+
subtitle: string;
|
|
114
|
+
icon?: IconV2NamesType;
|
|
115
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
116
|
+
export declare function SupersededCard({ title }: {
|
|
117
|
+
title: string;
|
|
118
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
119
|
+
export declare function ExpiredCard({ title }: {
|
|
120
|
+
title: string;
|
|
121
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
122
|
+
export declare function ActionButtons({ actions, state, actingId, onAction }: {
|
|
123
|
+
actions: ElicitationAction[];
|
|
124
|
+
state: ReviewState;
|
|
125
|
+
actingId: string | null;
|
|
126
|
+
onAction: (actionId: string) => void;
|
|
127
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
128
|
+
export declare function SourceBadge({ source }: {
|
|
129
|
+
source?: string;
|
|
130
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
131
|
+
export declare function useElicitationAction(data: ElicitationData | undefined, message: Message): {
|
|
132
|
+
state: ReviewState;
|
|
133
|
+
actingId: string | null;
|
|
134
|
+
submittedValues: Record<string, unknown>;
|
|
135
|
+
handleAction: (actionId: string, result?: Record<string, unknown>) => void;
|
|
136
|
+
};
|
|
137
|
+
export declare function ElicitationCard({ data, state, actingId, submittedValues, headerActions, children }: {
|
|
138
|
+
data: ElicitationData;
|
|
139
|
+
icon: IconV2NamesType;
|
|
140
|
+
state: ReviewState;
|
|
141
|
+
actingId: string | null;
|
|
142
|
+
submittedValues?: Record<string, unknown>;
|
|
143
|
+
headerActions?: React.ReactNode;
|
|
144
|
+
children: React.ReactNode;
|
|
145
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
146
|
+
//# sourceMappingURL=shared.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 +1,237 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useCurrentThread } from '@harnessio/ai-chat-core';
|
|
4
|
+
import { Accordion, Button, Card, IconV2, Layout, Text, Tooltip } from '@harnessio/ui/components';
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// Resolved helpers
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
/**
|
|
9
|
+
* Given a resolved elicitation payload, derive the compact display map that
|
|
10
|
+
* `ResolvedCard` expects in its expanded view. Mirrors the live handleAction
|
|
11
|
+
* logic so history cards render identically to freshly-resolved ones.
|
|
12
|
+
*/
|
|
13
|
+
function deriveSubmittedValuesFromResolved(resolved) {
|
|
14
|
+
const display = {};
|
|
15
|
+
const result = resolved.result;
|
|
16
|
+
if (!result)
|
|
17
|
+
return display;
|
|
18
|
+
// Use `!= null` so that legitimate falsy values (0, false, '') are preserved
|
|
19
|
+
// in the display map rather than silently dropped.
|
|
20
|
+
if (result.selection != null)
|
|
21
|
+
display['Selection'] = result.selection;
|
|
22
|
+
if (Array.isArray(result.selections))
|
|
23
|
+
display['Selections'] = result.selections.join(', ');
|
|
24
|
+
if (result.free_text != null)
|
|
25
|
+
display['Answer'] = result.free_text;
|
|
26
|
+
if (result.form_values && typeof result.form_values === 'object') {
|
|
27
|
+
Object.assign(display, result.form_values);
|
|
28
|
+
}
|
|
29
|
+
if (typeof result.yaml === 'string' && result.yaml.length > 0) {
|
|
30
|
+
display['YAML'] = result.yaml;
|
|
31
|
+
}
|
|
32
|
+
return display;
|
|
33
|
+
}
|
|
34
|
+
function isCancelEvent(resolved) {
|
|
35
|
+
return resolved.event_type === 'action_cancelled' || resolved.action_id === 'cancel' || resolved.action_id === 'deny';
|
|
36
|
+
}
|
|
37
|
+
function isExpired(data) {
|
|
38
|
+
if (!data?.expires_at)
|
|
39
|
+
return false;
|
|
40
|
+
const expiresAt = Date.parse(data.expires_at);
|
|
41
|
+
return !Number.isNaN(expiresAt) && Date.now() > expiresAt;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Derive the card's lifecycle state:
|
|
45
|
+
* - resolved payload -> completed / cancelled
|
|
46
|
+
* - live status=superseded -> superseded (user sent a new message)
|
|
47
|
+
* - expires_at in the past -> expired
|
|
48
|
+
* - otherwise -> pending (actionable, including from history)
|
|
49
|
+
*/
|
|
50
|
+
export function deriveElicitationState(data) {
|
|
51
|
+
const resolved = data?.resolved;
|
|
52
|
+
if (resolved)
|
|
53
|
+
return isCancelEvent(resolved) ? 'cancelled' : 'completed';
|
|
54
|
+
if (data?.status === 'superseded')
|
|
55
|
+
return 'superseded';
|
|
56
|
+
if (data?.status === 'expired' || isExpired(data))
|
|
57
|
+
return 'expired';
|
|
58
|
+
return 'pending';
|
|
59
|
+
}
|
|
60
|
+
function TruncatedWithTooltip({ text, variant, color, className }) {
|
|
61
|
+
return (_jsx(Tooltip, { content: text, children: _jsx(Text, { variant: variant, color: color, className: className, children: text }) }));
|
|
62
|
+
}
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
// Shared Components
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
function renderSubmittedValues(submittedValues) {
|
|
67
|
+
const entries = Object.entries(submittedValues ?? {});
|
|
68
|
+
if (entries.length === 0) {
|
|
69
|
+
return (_jsx(Text, { variant: "caption-normal", color: "foreground-4", children: "No details available" }));
|
|
70
|
+
}
|
|
71
|
+
return entries.map(([key, value]) => {
|
|
72
|
+
// AIPLAT-211: YAML gets a preformatted block so the accepted content is
|
|
73
|
+
// legible when a user reopens an older chat. Everything else stays on a
|
|
74
|
+
// compact label/value row.
|
|
75
|
+
if (key === 'YAML' && typeof value === 'string') {
|
|
76
|
+
return (_jsxs(Layout.Vertical, { gap: "xs", children: [_jsx(Text, { variant: "caption-normal", color: "foreground-3", children: key }), _jsx("pre", { className: "rounded-cn-sm text-cn-foreground-1 text-xs max-h-64 overflow-auto whitespace-pre-wrap bg-cn-2 p-cn-sm font-mono", children: value })] }, key));
|
|
77
|
+
}
|
|
78
|
+
return (_jsxs(Text, { variant: "body-normal", as: "div", children: [_jsxs(Text, { variant: "body-normal", color: "foreground-3", as: "span", children: [key, ":"] }), ' ', _jsx(Text, { variant: "body-normal", color: "foreground-1", as: "span", children: String(value ?? '—') })] }, key));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
export function ResolvedCard({ title, actionId, submittedValues }) {
|
|
82
|
+
const isCancelled = actionId === 'cancel' || actionId === 'deny';
|
|
83
|
+
const label = isCancelled ? 'Cancelled' : actionId === 'respond' ? 'Submitted' : 'Accepted';
|
|
84
|
+
const triggerPrefix = (_jsx(IconV2, { name: isCancelled ? 'xmark-circle' : 'check-circle', size: "xs", color: isCancelled ? 'neutral' : 'success', className: "mt-cn-3xs shrink-0" }));
|
|
85
|
+
const summary = (_jsxs(Text, { variant: "body-normal", color: isCancelled ? 'foreground-3' : 'foreground-1', children: [title, " \u2014 ", label] }));
|
|
86
|
+
return (_jsx(Layout.Vertical, { gap: "none", className: `overflow-hidden rounded-cn-3 border border-cn-2 ${isCancelled ? 'opacity-60' : ''}`, children: _jsx(Accordion.Root, { type: "single", collapsible: true, size: "sm", indicatorPosition: "right", children: _jsxs(Accordion.Item, { value: "details", className: "border-none", children: [_jsx(Accordion.Trigger, { prefix: triggerPrefix, className: "items-start !py-cn-xs px-cn-sm [&>.cn-accordion-trigger-indicator]:m-0 [&>.cn-accordion-trigger-indicator]:mt-cn-3xs [&>.cn-accordion-trigger-indicator]:self-start", children: summary }), _jsx(Accordion.Content, { className: "pb-0", children: _jsx(Layout.Vertical, { gap: "xs", className: "ml-cn-lg px-cn-sm pb-cn-sm", children: renderSubmittedValues(submittedValues) }) })] }) }) }));
|
|
87
|
+
}
|
|
88
|
+
// Compact, dimmed terminal card for elicitations that can no longer be acted
|
|
89
|
+
// on. `subtitle` explains why (no response recorded / superseded / expired).
|
|
90
|
+
export function TerminalCard({ title, subtitle, icon = 'clock' }) {
|
|
91
|
+
return (_jsxs(Layout.Horizontal, { align: "center", gap: "xs", className: "rounded-cn-3 border border-cn-2 px-cn-sm py-cn-xs opacity-60", children: [_jsx(IconV2, { name: icon, size: "xs", color: "neutral", className: "shrink-0" }), _jsx(TruncatedWithTooltip, { text: title, variant: "body-normal", color: "foreground-3", className: "min-w-0 truncate" }), _jsxs(Text, { variant: "caption-normal", color: "foreground-4", className: "shrink-0", children: ["\u00B7 ", subtitle] })] }));
|
|
92
|
+
}
|
|
93
|
+
// Rendered when the user moved on (sent a new message) before acting on this
|
|
94
|
+
// card, so it can no longer be answered in this thread.
|
|
95
|
+
export function SupersededCard({ title }) {
|
|
96
|
+
return _jsx(TerminalCard, { title: title, subtitle: "Superseded \u2014 you moved on" });
|
|
97
|
+
}
|
|
98
|
+
// Rendered when the pending-review TTL elapsed before the user responded.
|
|
99
|
+
export function ExpiredCard({ title }) {
|
|
100
|
+
return _jsx(TerminalCard, { title: title, subtitle: "Expired \u2014 no longer available" });
|
|
101
|
+
}
|
|
102
|
+
export function ActionButtons({ actions, state, actingId, onAction }) {
|
|
103
|
+
const disabled = state !== 'pending';
|
|
104
|
+
const orderedActions = [...actions].sort((a, b) => {
|
|
105
|
+
const rank = (variant) => variant === 'primary' || variant === 'destructive' ? 1 : 0;
|
|
106
|
+
return rank(a.variant) - rank(b.variant);
|
|
107
|
+
});
|
|
108
|
+
return (_jsx(Layout.Horizontal, { gap: "xs", justify: "end", className: "mt-cn-xs flex flex-wrap", children: orderedActions.map(action => (_jsx(Button, { variant: action.variant === 'primary'
|
|
109
|
+
? 'primary'
|
|
110
|
+
: action.variant === 'destructive'
|
|
111
|
+
? 'secondary'
|
|
112
|
+
: action.variant === 'ghost'
|
|
113
|
+
? 'ghost'
|
|
114
|
+
: 'outline', size: "sm", disabled: disabled, loading: state === 'acting' && actingId === action.id, className: action.variant === 'destructive' ? 'text-cn-danger-primary' : undefined, onClick: () => onAction(action.id), children: action.label }, action.id))) }));
|
|
115
|
+
}
|
|
116
|
+
export function SourceBadge({ source }) {
|
|
117
|
+
if (!source)
|
|
118
|
+
return null;
|
|
119
|
+
const label = source === 'llm' ? 'AI Chat' : source === 'mcp' ? 'MCP Server' : source === 'agent' ? 'Agent' : source;
|
|
120
|
+
return (_jsxs(Text, { variant: "caption-normal", color: "foreground-4", className: "text-[10px]", children: ["via ", label] }));
|
|
121
|
+
}
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
// Shared Hook
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
export function useElicitationAction(data, message) {
|
|
126
|
+
const thread = useCurrentThread();
|
|
127
|
+
// Derive initial state from the backend-owned lifecycle status (preferred)
|
|
128
|
+
// or, for legacy records, the persisted `resolved` payload.
|
|
129
|
+
//
|
|
130
|
+
// Lazy-initializer form of useState guarantees the derivation runs once,
|
|
131
|
+
// not on every render.
|
|
132
|
+
const [state, setState] = useState(() => deriveElicitationState(data));
|
|
133
|
+
const [actingId, setActingId] = useState(() => data?.resolved?.action_id ?? null);
|
|
134
|
+
const [submittedValues, setSubmittedValues] = useState(() => data?.resolved ? deriveSubmittedValuesFromResolved(data.resolved) : {});
|
|
135
|
+
const timerRef = useRef(null);
|
|
136
|
+
// Sync state when the backend-owned lifecycle changes underneath us (e.g. the
|
|
137
|
+
// runtime marks the card `superseded` via updateMessageContent, or a resolved
|
|
138
|
+
// payload arrives after a drawer remount). Never override an in-flight local
|
|
139
|
+
// action ('acting'); only advance from a non-terminal state.
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (state === 'acting' || state === 'completed' || state === 'cancelled')
|
|
142
|
+
return;
|
|
143
|
+
const nextState = deriveElicitationState(data);
|
|
144
|
+
if (nextState === state)
|
|
145
|
+
return;
|
|
146
|
+
setState(nextState);
|
|
147
|
+
if (data?.resolved) {
|
|
148
|
+
setActingId(data.resolved.action_id);
|
|
149
|
+
setSubmittedValues(deriveSubmittedValuesFromResolved(data.resolved));
|
|
150
|
+
}
|
|
151
|
+
}, [data, state]);
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
return () => {
|
|
154
|
+
if (timerRef.current)
|
|
155
|
+
clearTimeout(timerRef.current);
|
|
156
|
+
};
|
|
157
|
+
}, []);
|
|
158
|
+
const handleAction = useCallback((actionId, result) => {
|
|
159
|
+
if (state !== 'pending' || !data)
|
|
160
|
+
return;
|
|
161
|
+
const action = data.actions.find(a => a.id === actionId);
|
|
162
|
+
const eventType = action?.sends === 'action_cancelled' ? 'action_cancelled' : 'action_completed';
|
|
163
|
+
const isCancelled = eventType === 'action_cancelled';
|
|
164
|
+
setActingId(actionId);
|
|
165
|
+
setState('acting');
|
|
166
|
+
if (result && !isCancelled) {
|
|
167
|
+
const display = {};
|
|
168
|
+
if (result.selection != null)
|
|
169
|
+
display['Selection'] = result.selection;
|
|
170
|
+
if (result.selections)
|
|
171
|
+
display['Selections'] = result.selections.join(', ');
|
|
172
|
+
if (result.free_text != null)
|
|
173
|
+
display['Answer'] = result.free_text;
|
|
174
|
+
if (result.form_values && typeof result.form_values === 'object') {
|
|
175
|
+
Object.assign(display, result.form_values);
|
|
176
|
+
}
|
|
177
|
+
// Store the actual YAML string so the expanded ResolvedCard matches
|
|
178
|
+
// the history rendering (AIPLAT-211). Kept opaque on the compact row.
|
|
179
|
+
if (typeof result.yaml === 'string' && result.yaml.length > 0)
|
|
180
|
+
display['YAML'] = result.yaml;
|
|
181
|
+
if (Object.keys(display).length > 0)
|
|
182
|
+
setSubmittedValues(display);
|
|
183
|
+
}
|
|
184
|
+
const systemEvent = {
|
|
185
|
+
event_type: eventType,
|
|
186
|
+
capability_id: data.review_id,
|
|
187
|
+
result: {
|
|
188
|
+
success: !isCancelled,
|
|
189
|
+
action_id: actionId,
|
|
190
|
+
...result,
|
|
191
|
+
...(data.entity_info ? { entity_info: data.entity_info } : {}),
|
|
192
|
+
...(data.entity_info?.request_action ? { request_action: data.entity_info.request_action } : {}),
|
|
193
|
+
...(data.tool_input ? { tool_input: data.tool_input } : {})
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
// IMPORTANT: Update the message content in the thread runtime with the resolved field
|
|
197
|
+
// so that the state persists even if the component remounts (e.g., drawer close/reopen)
|
|
198
|
+
const resolved = {
|
|
199
|
+
event_type: eventType,
|
|
200
|
+
action_id: actionId,
|
|
201
|
+
result: systemEvent.result,
|
|
202
|
+
resolved_at: new Date().toISOString()
|
|
203
|
+
};
|
|
204
|
+
thread.updateMessageContent(message.id, content => content.map(item => {
|
|
205
|
+
if (item.type.startsWith('elicitation_') && item.data.review_id === data.review_id) {
|
|
206
|
+
return {
|
|
207
|
+
...item,
|
|
208
|
+
data: {
|
|
209
|
+
...item.data,
|
|
210
|
+
resolved
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return item;
|
|
215
|
+
}));
|
|
216
|
+
thread.sendSystemEvent(systemEvent);
|
|
217
|
+
timerRef.current = setTimeout(() => {
|
|
218
|
+
setState(isCancelled ? 'cancelled' : 'completed');
|
|
219
|
+
}, 500);
|
|
220
|
+
}, [thread, data, state, message.id]);
|
|
221
|
+
return { state, actingId, submittedValues, handleAction };
|
|
222
|
+
}
|
|
223
|
+
// ---------------------------------------------------------------------------
|
|
224
|
+
// Shared Card Wrapper
|
|
225
|
+
// ---------------------------------------------------------------------------
|
|
226
|
+
export function ElicitationCard({ data, state, actingId, submittedValues, headerActions, children }) {
|
|
227
|
+
if (state === 'completed' || state === 'cancelled') {
|
|
228
|
+
return _jsx(ResolvedCard, { title: data.title, actionId: actingId || '', submittedValues: submittedValues });
|
|
229
|
+
}
|
|
230
|
+
if (state === 'superseded') {
|
|
231
|
+
return _jsx(SupersededCard, { title: data.title });
|
|
232
|
+
}
|
|
233
|
+
if (state === 'expired') {
|
|
234
|
+
return _jsx(ExpiredCard, { title: data.title });
|
|
235
|
+
}
|
|
236
|
+
return (_jsx(Card.Root, { size: "sm", className: "min-w-0 overflow-hidden", children: _jsx(Card.Content, { children: _jsxs(Layout.Vertical, { gap: "sm", children: [_jsxs(Layout.Horizontal, { align: "center", justify: "between", gap: "sm", children: [_jsxs(Layout.Horizontal, { align: "start", gap: "sm", className: "min-w-0 flex-1", children: [_jsx(IconV2, { name: "loader", size: "xs", color: "neutral", className: "mt-cn-3xs shrink-0 animate-spin" }), _jsxs(Layout.Vertical, { gap: "none", className: "min-w-0", children: [_jsx(TruncatedWithTooltip, { text: data.title, variant: "body-strong", color: "foreground-1", className: "line-clamp-1" }), data.subtitle && state === 'pending' && (_jsx(TruncatedWithTooltip, { text: data.subtitle, variant: "caption-normal", color: "foreground-3", className: "line-clamp-2" }))] })] }), headerActions ? _jsx("div", { className: "shrink-0", children: headerActions }) : null] }), children] }) }) }));
|
|
237
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-renderer.d.ts","sourceRoot":"","sources":["../../src/renderers/error-renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAW,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAqBlE,eAAO,MAAM,aAAa,EAAE,eAI3B,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { MessageBubble, Text } from '@harnessio/ui/components';
|
|
3
|
+
const ErrorRendererComponent = ({ content }) => {
|
|
4
|
+
const errorContent = typeof content.data === 'string' ? content.data : JSON.stringify(content.data, null, 2);
|
|
5
|
+
return (_jsx(MessageBubble.Root, { className: "bg-cn-danger-background max-w-full", children: _jsx(MessageBubble.Content, { className: "max-w-full", children: _jsx(Text, { variant: "body-normal", color: "danger", children: errorContent }) }) }));
|
|
6
|
+
};
|
|
7
|
+
export const errorRenderer = {
|
|
8
|
+
type: 'error',
|
|
9
|
+
component: ErrorRendererComponent,
|
|
10
|
+
priority: 1
|
|
11
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MessageContent, MessageRenderer } from '@harnessio/ai-chat-core';
|
|
2
|
+
interface FileContentData {
|
|
3
|
+
type: 'file';
|
|
4
|
+
name: string;
|
|
5
|
+
content: string;
|
|
6
|
+
}
|
|
7
|
+
interface FileContent extends MessageContent<FileContentData> {
|
|
8
|
+
type: 'file';
|
|
9
|
+
}
|
|
10
|
+
export declare const fileRenderer: MessageRenderer<FileContent>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=file-renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-renderer.d.ts","sourceRoot":"","sources":["../../src/renderers/file-renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAGzE,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,UAAU,WAAY,SAAQ,cAAc,CAAC,eAAe,CAAC;IAC3D,IAAI,EAAE,MAAM,CAAA;CACb;AAuDD,eAAO,MAAM,YAAY,EAAE,eAAe,CAAC,WAAW,CAIrD,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Card, IconV2, Layout, Text } from '@harnessio/ui/components';
|
|
3
|
+
function downloadBase64JSONFile(base64Content, filename) {
|
|
4
|
+
try {
|
|
5
|
+
// Decode base64 to JSON string
|
|
6
|
+
const jsonString = atob(base64Content);
|
|
7
|
+
const jsonObject = JSON.parse(jsonString);
|
|
8
|
+
// Format with 2-space indentation
|
|
9
|
+
const formatted = JSON.stringify(jsonObject, null, 2);
|
|
10
|
+
// Create blob and download
|
|
11
|
+
const blob = new Blob([formatted], { type: 'application/json' });
|
|
12
|
+
const url = URL.createObjectURL(blob);
|
|
13
|
+
const a = document.createElement('a');
|
|
14
|
+
a.href = url;
|
|
15
|
+
a.download = filename;
|
|
16
|
+
a.click();
|
|
17
|
+
URL.revokeObjectURL(url);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
console.error('Failed to download file:', error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function FileInlineRenderer({ content }) {
|
|
24
|
+
const data = content.data;
|
|
25
|
+
const { name, content: base64Content } = data;
|
|
26
|
+
const handleDownload = () => {
|
|
27
|
+
downloadBase64JSONFile(base64Content, name);
|
|
28
|
+
};
|
|
29
|
+
return (_jsx(Card.Root, { size: "sm", children: _jsx(Card.Content, { children: _jsxs(Layout.Horizontal, { align: "center", justify: "between", children: [_jsxs(Layout.Horizontal, { align: "center", gap: "sm", children: [_jsx(IconV2, { name: "docs", size: "xs", color: "neutral" }), _jsx(Text, { variant: "body-normal", color: "foreground-1", lineClamp: 1, children: name })] }), _jsxs(Button, { variant: "ghost", size: "sm", onClick: handleDownload, children: [_jsx(IconV2, { name: "download", size: "xs" }), _jsx(Text, { variant: "body-normal", children: "Download" })] })] }) }) }));
|
|
30
|
+
}
|
|
31
|
+
export const fileRenderer = {
|
|
32
|
+
type: 'file',
|
|
33
|
+
component: FileInlineRenderer,
|
|
34
|
+
priority: 1
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"follow-up-prompts-renderer.d.ts","sourceRoot":"","sources":["../../src/renderers/follow-up-prompts-renderer.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAW,eAAe,EAAoB,MAAM,yBAAyB,CAAA;AAuGpF,eAAO,MAAM,uBAAuB,EAAE,eAIrC,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useCurrentThread } from '@harnessio/ai-chat-core';
|
|
4
|
+
import { Layout, ToggleGroup } from '@harnessio/ui/components';
|
|
5
|
+
const FollowUpPromptsRendererComponent = ({ content }) => {
|
|
6
|
+
const thread = useCurrentThread();
|
|
7
|
+
const prompts = content?.data?.prompts || [];
|
|
8
|
+
const createSuggestionFromPrompt = (prompt) => {
|
|
9
|
+
if (typeof prompt === 'string') {
|
|
10
|
+
return { id: prompt, text: prompt };
|
|
11
|
+
}
|
|
12
|
+
if (prompt.data) {
|
|
13
|
+
return {
|
|
14
|
+
id: prompt.text,
|
|
15
|
+
text: prompt.text,
|
|
16
|
+
action: prompt.action,
|
|
17
|
+
data: prompt.data
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return { id: prompt.text, text: prompt.text };
|
|
21
|
+
};
|
|
22
|
+
const [promptsContent, setPromptsContent] = useState(prompts.map(createSuggestionFromPrompt));
|
|
23
|
+
const isActionSuggestion = (suggestion) => {
|
|
24
|
+
return suggestion.action === 'OPEN_ENTITY_NEW_TAB' && !!suggestion.data;
|
|
25
|
+
};
|
|
26
|
+
const handleRedirection = (prompt) => {
|
|
27
|
+
if (prompt.action === 'OPEN_ENTITY_NEW_TAB' && prompt.data) {
|
|
28
|
+
// TODO: Implement proper routing when navigation context is available
|
|
29
|
+
// For now, just log the action
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const handlePromptClick = (prompt) => {
|
|
33
|
+
setPromptsContent(prev => prev.map(p => ({ ...p, active: p.id === prompt.id })));
|
|
34
|
+
if (isActionSuggestion(prompt)) {
|
|
35
|
+
handleRedirection(prompt);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
thread.send(prompt.text);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
if (!promptsContent || promptsContent.length === 0) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const activeId = promptsContent.find(p => p.active)?.id ?? '';
|
|
45
|
+
return (_jsx(Layout.Vertical, { gap: "xs", className: "w-full", children: _jsx(ToggleGroup.Root, { type: "single", value: activeId, onChange: (value) => {
|
|
46
|
+
const prompt = promptsContent.find(p => p.id === value);
|
|
47
|
+
if (prompt)
|
|
48
|
+
handlePromptClick(prompt);
|
|
49
|
+
}, className: "flex flex-wrap gap-cn-sm", children: promptsContent.map(prompt => (_jsx(ToggleGroup.Item, { value: prompt.id, text: prompt.text }, prompt.id))) }) }));
|
|
50
|
+
};
|
|
51
|
+
export const followUpPromptsRenderer = {
|
|
52
|
+
type: 'prompt',
|
|
53
|
+
component: FollowUpPromptsRendererComponent,
|
|
54
|
+
priority: 1
|
|
55
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface Prompt {
|
|
2
|
+
text: string;
|
|
3
|
+
}
|
|
4
|
+
interface PromptsContent {
|
|
5
|
+
data: {
|
|
6
|
+
title?: string;
|
|
7
|
+
prompts: Prompt[];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export declare const PromptsRenderer: ({ content }: {
|
|
11
|
+
content: PromptsContent;
|
|
12
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=prompts-renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts-renderer.d.ts","sourceRoot":"","sources":["../../src/renderers/prompts-renderer.tsx"],"names":[],"mappings":"AAEA,UAAU,MAAM;IACd,IAAI,EAAE,MAAM,CAAA;CACb;AAED,UAAU,cAAc;IACtB,IAAI,EAAE;QACJ,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,OAAO,EAAE,MAAM,EAAE,CAAA;KAClB,CAAA;CACF;AAED,eAAO,MAAM,eAAe,gBAAiB;IAAE,OAAO,EAAE,cAAc,CAAA;CAAE,4CAevE,CAAA"}
|