@adecore/agents-react 0.49.4 → 0.49.5
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/chat-references.d.ts +13 -1
- package/dist/chat/chat-references.js +13 -2
- package/dist/chat/ui/ReferenceChip.js +98 -77
- package/dist/chat/ui/ReferenceTrail.d.ts +11 -0
- package/dist/chat/ui/ReferenceTrail.js +65 -0
- package/dist/chat/ui/RunSettings.js +2 -2
- package/dist/chat/ui/SessionLine.js +1 -1
- package/dist/chat/ui/chips.d.ts +1 -0
- package/dist/chat/ui/chips.js +2 -0
- package/dist/chat/ui/composer/ComposerMenu.js +28 -22
- package/dist/chat/ui/composer/chips.d.ts +3 -2
- package/dist/chat/ui/composer/chips.js +21 -9
- package/dist/chat/ui/composer/use-prompt-menus.d.ts +1 -0
- package/dist/chat/ui/composer/use-prompt-menus.js +115 -121
- package/dist/chat/ui/reference-icons.js +3 -1
- package/dist/chat/ui/rows/MessageRows.js +21 -8
- package/dist/locales/en/agent-chat.d.ts +3 -0
- package/dist/locales/en/agent-chat.js +4 -1
- package/dist/locales/en/agent-usage.d.ts +0 -1
- package/dist/locales/en/agent-usage.js +0 -1
- package/dist/locales/nl/agent-chat.d.ts +3 -0
- package/dist/locales/nl/agent-chat.js +4 -1
- package/dist/locales/nl/agent-usage.d.ts +0 -1
- package/dist/locales/nl/agent-usage.js +0 -1
- package/dist/usage/LimitsList.d.ts +5 -2
- package/dist/usage/LimitsList.js +649 -231
- package/dist/usage/UsageBreakdown.js +1 -1
- package/dist/usage/UsageLimits.js +1 -1
- package/dist/usage/UsageLimitsCard.js +81 -54
- package/dist/usage/limit-groups.d.ts +4 -3
- package/dist/usage/limit-groups.js +21 -11
- package/package.json +8 -8
- package/src/chat/chat-references.ts +53 -4
- package/src/chat/ui/ReferenceChip.tsx +8 -2
- package/src/chat/ui/ReferenceTrail.tsx +29 -0
- package/src/chat/ui/RunSettings.tsx +2 -2
- package/src/chat/ui/SessionLine.tsx +1 -1
- package/src/chat/ui/chips.ts +3 -0
- package/src/chat/ui/composer/ComposerMenu.tsx +30 -11
- package/src/chat/ui/composer/chips.ts +29 -11
- package/src/chat/ui/composer/use-prompt-menus.ts +12 -7
- package/src/chat/ui/reference-icons.ts +18 -1
- package/src/chat/ui/rows/MessageRows.tsx +1 -0
- package/src/locales/en/agent-chat.ts +4 -1
- package/src/locales/en/agent-usage.ts +0 -1
- package/src/locales/nl/agent-chat.ts +4 -1
- package/src/locales/nl/agent-usage.ts +0 -1
- package/src/usage/LimitsList.tsx +183 -54
- package/src/usage/UsageBreakdown.tsx +1 -1
- package/src/usage/UsageLimits.tsx +1 -1
- package/src/usage/UsageLimitsCard.tsx +11 -7
- package/src/usage/limit-groups.ts +25 -8
|
@@ -428,7 +428,7 @@ function ProjectRow(t0) {
|
|
|
428
428
|
let t9;
|
|
429
429
|
if ($[16] !== t8) {
|
|
430
430
|
t9 = /*#__PURE__*/_jsx("span", {
|
|
431
|
-
className: "mt-1 flex h-[9px] w-32 shrink-0 overflow-hidden rounded-full bg-
|
|
431
|
+
className: "mt-1 flex h-[9px] w-32 shrink-0 overflow-hidden rounded-full bg-track",
|
|
432
432
|
children: t8
|
|
433
433
|
});
|
|
434
434
|
$[16] = t8;
|
|
@@ -178,7 +178,7 @@ function LimitCard(t0) {
|
|
|
178
178
|
let t8;
|
|
179
179
|
if ($[17] !== plan) {
|
|
180
180
|
t8 = plan && /*#__PURE__*/_jsxs("span", {
|
|
181
|
-
className: "shrink-0 font-normal text-text-muted",
|
|
181
|
+
className: "shrink-0 font-normal text-text-muted capitalize",
|
|
182
182
|
children: ["\xB7 ", plan]
|
|
183
183
|
});
|
|
184
184
|
$[17] = plan;
|
|
@@ -1,110 +1,137 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import i18next from 'i18next';
|
|
3
3
|
import { useState } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
import { AccountLimitsList, LimitsList } from './LimitsList.js';
|
|
4
|
+
import { AccountLimitsList } from './LimitsList.js';
|
|
6
5
|
import { useLimitGroups, useUsageLimits } from './limits.js';
|
|
7
6
|
import { useNow, PreviewCard } from '@adecore/ui';
|
|
8
7
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
8
|
const MINUTE_MS = 60_000;
|
|
10
9
|
/* Asking the CLIs starts a process each, so the question waits until the card is actually opened. */
|
|
11
|
-
function CardBody() {
|
|
12
|
-
const $ = _c(
|
|
10
|
+
function CardBody(t0) {
|
|
11
|
+
const $ = _c(7);
|
|
12
|
+
const {
|
|
13
|
+
folded,
|
|
14
|
+
onFoldedChange
|
|
15
|
+
} = t0;
|
|
13
16
|
const limits = useUsageLimits();
|
|
14
17
|
const groups = useLimitGroups(limits);
|
|
15
18
|
const now = useNow(MINUTE_MS);
|
|
16
19
|
if (limits === null) {
|
|
17
|
-
let
|
|
20
|
+
let t1;
|
|
18
21
|
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
19
|
-
|
|
20
|
-
className: "text-xs text-text-faint",
|
|
22
|
+
t1 = /*#__PURE__*/_jsx("p", {
|
|
23
|
+
className: "px-1.5 py-1 text-xs text-text-faint",
|
|
21
24
|
children: i18next.t("agent-usage:limits.loading")
|
|
22
25
|
});
|
|
23
|
-
$[0] =
|
|
26
|
+
$[0] = t1;
|
|
27
|
+
} else {
|
|
28
|
+
t1 = $[0];
|
|
29
|
+
}
|
|
30
|
+
return t1;
|
|
31
|
+
}
|
|
32
|
+
if (groups.length === 0) {
|
|
33
|
+
let t1;
|
|
34
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
35
|
+
t1 = /*#__PURE__*/_jsx("p", {
|
|
36
|
+
className: "px-1.5 py-1 text-xs text-text-faint",
|
|
37
|
+
children: i18next.t("agent-usage:limits.none")
|
|
38
|
+
});
|
|
39
|
+
$[1] = t1;
|
|
24
40
|
} else {
|
|
25
|
-
|
|
41
|
+
t1 = $[1];
|
|
26
42
|
}
|
|
27
|
-
return
|
|
43
|
+
return t1;
|
|
28
44
|
}
|
|
29
|
-
let
|
|
30
|
-
if ($[
|
|
31
|
-
|
|
45
|
+
let t1;
|
|
46
|
+
if ($[2] !== folded || $[3] !== groups || $[4] !== now || $[5] !== onFoldedChange) {
|
|
47
|
+
t1 = /*#__PURE__*/_jsx(AccountLimitsList, {
|
|
32
48
|
groups: groups,
|
|
33
|
-
now: now
|
|
34
|
-
}) : /*#__PURE__*/_jsx(LimitsList, {
|
|
35
|
-
limits: limits,
|
|
36
49
|
now: now,
|
|
37
|
-
|
|
50
|
+
folded: folded,
|
|
51
|
+
onFoldedChange: onFoldedChange
|
|
38
52
|
});
|
|
39
|
-
$[
|
|
40
|
-
$[
|
|
41
|
-
$[
|
|
42
|
-
$[
|
|
53
|
+
$[2] = folded;
|
|
54
|
+
$[3] = groups;
|
|
55
|
+
$[4] = now;
|
|
56
|
+
$[5] = onFoldedChange;
|
|
57
|
+
$[6] = t1;
|
|
43
58
|
} else {
|
|
44
|
-
|
|
59
|
+
t1 = $[6];
|
|
45
60
|
}
|
|
46
|
-
return
|
|
61
|
+
return t1;
|
|
47
62
|
}
|
|
48
63
|
/*
|
|
49
64
|
* What is left of each plan, without opening the usage dialog. A hover card rather than a tooltip:
|
|
50
65
|
* the bars take a moment to read, and it stays open while the pointer travels to it.
|
|
51
66
|
*/
|
|
52
67
|
export function UsageLimitsCard(t0) {
|
|
53
|
-
const $ = _c(
|
|
68
|
+
const $ = _c(12);
|
|
54
69
|
const {
|
|
55
70
|
children
|
|
56
71
|
} = t0;
|
|
57
72
|
const [opened, setOpened] = useState(false);
|
|
58
73
|
let t1;
|
|
59
74
|
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
60
|
-
t1 =
|
|
75
|
+
t1 = new Set();
|
|
61
76
|
$[0] = t1;
|
|
62
77
|
} else {
|
|
63
78
|
t1 = $[0];
|
|
64
79
|
}
|
|
80
|
+
const [folded, setFolded] = useState(t1);
|
|
65
81
|
let t2;
|
|
66
|
-
if ($[1]
|
|
67
|
-
t2 =
|
|
68
|
-
|
|
69
|
-
delay: 500
|
|
70
|
-
});
|
|
71
|
-
$[1] = children;
|
|
72
|
-
$[2] = t2;
|
|
82
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
83
|
+
t2 = open => open && setOpened(true);
|
|
84
|
+
$[1] = t2;
|
|
73
85
|
} else {
|
|
74
|
-
t2 = $[
|
|
86
|
+
t2 = $[1];
|
|
75
87
|
}
|
|
76
88
|
let t3;
|
|
77
|
-
if ($[
|
|
78
|
-
t3 =
|
|
79
|
-
|
|
80
|
-
|
|
89
|
+
if ($[2] !== children) {
|
|
90
|
+
t3 = /*#__PURE__*/_jsx(PreviewCard.Trigger, {
|
|
91
|
+
render: children,
|
|
92
|
+
delay: 500
|
|
93
|
+
});
|
|
94
|
+
$[2] = children;
|
|
95
|
+
$[3] = t3;
|
|
81
96
|
} else {
|
|
82
|
-
t3 = $[
|
|
97
|
+
t3 = $[3];
|
|
83
98
|
}
|
|
84
99
|
let t4;
|
|
85
|
-
if ($[5] !==
|
|
86
|
-
t4 = /*#__PURE__*/_jsx(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
className: "w-64 p-3",
|
|
90
|
-
children: t3
|
|
100
|
+
if ($[4] !== folded || $[5] !== opened) {
|
|
101
|
+
t4 = opened && /*#__PURE__*/_jsx(CardBody, {
|
|
102
|
+
folded: folded,
|
|
103
|
+
onFoldedChange: setFolded
|
|
91
104
|
});
|
|
92
|
-
$[
|
|
105
|
+
$[4] = folded;
|
|
106
|
+
$[5] = opened;
|
|
93
107
|
$[6] = t4;
|
|
94
108
|
} else {
|
|
95
109
|
t4 = $[6];
|
|
96
110
|
}
|
|
97
111
|
let t5;
|
|
98
|
-
if ($[7] !==
|
|
99
|
-
t5 = /*#__PURE__*/
|
|
100
|
-
|
|
101
|
-
|
|
112
|
+
if ($[7] !== t4) {
|
|
113
|
+
t5 = /*#__PURE__*/_jsx(PreviewCard.Popup, {
|
|
114
|
+
side: "top",
|
|
115
|
+
align: "end",
|
|
116
|
+
className: "w-85 p-2",
|
|
117
|
+
children: t4
|
|
118
|
+
});
|
|
119
|
+
$[7] = t4;
|
|
120
|
+
$[8] = t5;
|
|
121
|
+
} else {
|
|
122
|
+
t5 = $[8];
|
|
123
|
+
}
|
|
124
|
+
let t6;
|
|
125
|
+
if ($[9] !== t3 || $[10] !== t5) {
|
|
126
|
+
t6 = /*#__PURE__*/_jsxs(PreviewCard.Root, {
|
|
127
|
+
onOpenChange: t2,
|
|
128
|
+
children: [t3, t5]
|
|
102
129
|
});
|
|
103
|
-
$[
|
|
104
|
-
$[
|
|
105
|
-
$[
|
|
130
|
+
$[9] = t3;
|
|
131
|
+
$[10] = t5;
|
|
132
|
+
$[11] = t6;
|
|
106
133
|
} else {
|
|
107
|
-
|
|
134
|
+
t6 = $[11];
|
|
108
135
|
}
|
|
109
|
-
return
|
|
136
|
+
return t6;
|
|
110
137
|
}
|
|
@@ -15,9 +15,10 @@ export interface LimitGroup {
|
|
|
15
15
|
export declare function limitGroups(snapshot: UsageLimitsSnapshot, accounts: ProviderAccounts | null): LimitGroup[];
|
|
16
16
|
export declare function hasSeveralAccounts(groups: readonly LimitGroup[]): boolean;
|
|
17
17
|
export declare function isSignedOut(account: LimitAccount): boolean;
|
|
18
|
-
export declare function
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
export declare function limitAccountKey(account: LimitAccount): string;
|
|
19
|
+
export declare function noteIsWarning(account: LimitAccount): boolean;
|
|
20
|
+
export declare function emptyWindows(group: LimitGroup, account: LimitAccount): readonly UsageWindow[];
|
|
21
|
+
export declare function ringWindows(windows: readonly UsageWindow[]): readonly UsageWindow[];
|
|
21
22
|
export declare function paceText(window: UsageWindow, now: number): string;
|
|
22
23
|
export declare function checkedLabel(entry: UsageLimitsProvider, now: number): string | null;
|
|
23
24
|
export declare function explain(provider: UsageLimitsProvider): string | null;
|
|
@@ -61,18 +61,28 @@ export function hasSeveralAccounts(groups) {
|
|
|
61
61
|
export function isSignedOut(account) {
|
|
62
62
|
return account.status?.state === 'signed-out';
|
|
63
63
|
}
|
|
64
|
-
/*
|
|
65
|
-
export function
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
/* An account in a list across CLIs, where two CLIs may name an account alike. */
|
|
65
|
+
export function limitAccountKey(account) {
|
|
66
|
+
return `${account.kind}:${account.id}`;
|
|
67
|
+
}
|
|
68
|
+
/* Whether an account's words are a problem to solve, rather than how the account simply is. */
|
|
69
|
+
export function noteIsWarning(account) {
|
|
70
|
+
return isSignedOut(account) || account.entry?.unavailable?.reason === 'failed';
|
|
71
|
+
}
|
|
72
|
+
/* The windows a signed-in account with no numbers yet will have, as far as another account of its CLI shows them. */
|
|
73
|
+
export function emptyWindows(group, account) {
|
|
74
|
+
if (isSignedOut(account) || account.entry === null || account.entry.unavailable !== null || account.entry.windows.length > 0) {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
return group.accounts.find(other => (other.entry?.windows.length ?? 0) > 0)?.entry?.windows ?? [];
|
|
78
|
+
}
|
|
79
|
+
/* The windows a folded account draws a ring for. Three fit; past that the ones nearest their limit. */
|
|
80
|
+
export function ringWindows(windows) {
|
|
81
|
+
if (windows.length <= 3) {
|
|
82
|
+
return windows;
|
|
74
83
|
}
|
|
75
|
-
|
|
84
|
+
const fullest = [...windows].sort((a, b) => b.used - a.used).slice(0, 3);
|
|
85
|
+
return windows.filter(window => fullest.includes(window));
|
|
76
86
|
}
|
|
77
87
|
/* The bar as words for whoever cannot see the mark: how much is used and how that stands against an even pace. */
|
|
78
88
|
export function paceText(window, now) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adecore/agents-react",
|
|
3
|
-
"version": "0.49.
|
|
3
|
+
"version": "0.49.5",
|
|
4
4
|
"description": "React agent chat threads, composers, approvals, provider accounts and usage views.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -72,11 +72,11 @@
|
|
|
72
72
|
"test:visuals": "bun --config=integration.bunfig.toml --conditions=source test ./src/chat/visual-viewport.integration.test.ts"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@adecore/agent-contracts": "0.49.
|
|
76
|
-
"@adecore/editor": "0.49.
|
|
77
|
-
"@adecore/editor-react": "0.49.
|
|
78
|
-
"@adecore/intelligent-ui": "0.49.
|
|
79
|
-
"@adecore/merge": "0.49.
|
|
75
|
+
"@adecore/agent-contracts": "0.49.5",
|
|
76
|
+
"@adecore/editor": "0.49.5",
|
|
77
|
+
"@adecore/editor-react": "0.49.5",
|
|
78
|
+
"@adecore/intelligent-ui": "0.49.5",
|
|
79
|
+
"@adecore/merge": "0.49.5",
|
|
80
80
|
"@codemirror/commands": "^6.11.1",
|
|
81
81
|
"@codemirror/language": "^6.13.1",
|
|
82
82
|
"@codemirror/state": "^6.7.6",
|
|
@@ -100,14 +100,14 @@
|
|
|
100
100
|
"zustand": "^5.0.16"
|
|
101
101
|
},
|
|
102
102
|
"peerDependencies": {
|
|
103
|
-
"@adecore/ui": "^0.49.
|
|
103
|
+
"@adecore/ui": "^0.49.5",
|
|
104
104
|
"i18next": "^26.4.2",
|
|
105
105
|
"react": "^19.3.0",
|
|
106
106
|
"react-dom": "^19.3.0",
|
|
107
107
|
"react-i18next": "^17.0.15"
|
|
108
108
|
},
|
|
109
109
|
"devDependencies": {
|
|
110
|
-
"@adecore/ui": "0.49.
|
|
110
|
+
"@adecore/ui": "0.49.5",
|
|
111
111
|
"@types/bun": "^1.4.4",
|
|
112
112
|
"@types/react": "^19.3.0",
|
|
113
113
|
"@types/react-dom": "^19.3.0",
|
|
@@ -6,7 +6,35 @@ export interface ProjectChat {
|
|
|
6
6
|
title: string;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export type ReferableKind =
|
|
9
|
+
export type ReferableKind =
|
|
10
|
+
| 'project'
|
|
11
|
+
| 'canvas'
|
|
12
|
+
| 'design'
|
|
13
|
+
| 'chat'
|
|
14
|
+
| 'terminal'
|
|
15
|
+
| 'note'
|
|
16
|
+
| 'text'
|
|
17
|
+
| 'drawing'
|
|
18
|
+
| 'diagram'
|
|
19
|
+
| 'browser'
|
|
20
|
+
| 'device'
|
|
21
|
+
| 'file'
|
|
22
|
+
| 'database';
|
|
23
|
+
|
|
24
|
+
/* One place on the way to a reference, such as the project or the canvas it stands in. */
|
|
25
|
+
export interface ReferenceStep {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
kind: ReferableKind;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/* The heading a reference is offered under when a host offers more than one project. */
|
|
32
|
+
export interface ReferenceSection {
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
/* The project of the chat that asks, which comes first and says so. */
|
|
36
|
+
current?: boolean;
|
|
37
|
+
}
|
|
10
38
|
|
|
11
39
|
/* What a message may point at with `#`, under the name it has right now. */
|
|
12
40
|
export interface Referable {
|
|
@@ -17,6 +45,9 @@ export interface Referable {
|
|
|
17
45
|
detail?: string;
|
|
18
46
|
/* `canvas` for what stands on the canvas the chat is a node of, `views` for a view of the project. */
|
|
19
47
|
group: 'canvas' | 'views';
|
|
48
|
+
/* Where it stands, outermost first; its chip draws these in front of its name. */
|
|
49
|
+
trail?: readonly ReferenceStep[];
|
|
50
|
+
section?: ReferenceSection;
|
|
20
51
|
}
|
|
21
52
|
|
|
22
53
|
export interface Referables {
|
|
@@ -47,9 +78,27 @@ export function referenceTokens(ids: readonly string[], items: readonly Referabl
|
|
|
47
78
|
export function referenceSuggestions(referables: Referables, query: string, exclude: readonly string[], limit: number): Referable[] {
|
|
48
79
|
const needle = query.toLowerCase();
|
|
49
80
|
|
|
50
|
-
|
|
51
|
-
|
|
81
|
+
// A name on the way counts as well, so typing a project or a canvas finds what stands in it.
|
|
82
|
+
const found = referables.items.filter(
|
|
83
|
+
(item) =>
|
|
84
|
+
item.name !== '' &&
|
|
85
|
+
(!referables.chatsOnly || item.kind === 'chat') &&
|
|
86
|
+
!exclude.includes(item.id) &&
|
|
87
|
+
[item.name, ...(item.trail ?? []).map((step) => step.name)].some((name) => name.toLowerCase().includes(needle))
|
|
52
88
|
);
|
|
53
89
|
|
|
54
|
-
|
|
90
|
+
// A node never stands in the menu without its canvas above it, even a canvas that does not match or is picked.
|
|
91
|
+
const canvases = new Set(found.flatMap((item) => item.trail?.filter((step) => step.kind === 'canvas').map((step) => step.id) ?? []));
|
|
92
|
+
const matches = referables.items.filter((item) => found.includes(item) || canvases.has(item.id));
|
|
93
|
+
|
|
94
|
+
const taken = new Map<string, number>();
|
|
95
|
+
|
|
96
|
+
// Per section, or a large first project would keep every other one out of the menu.
|
|
97
|
+
return [...matches.filter((item) => item.group === 'canvas'), ...matches.filter((item) => item.group === 'views')].filter((item) => {
|
|
98
|
+
const section = item.section?.id ?? '';
|
|
99
|
+
const count = taken.get(section) ?? 0;
|
|
100
|
+
taken.set(section, count + 1);
|
|
101
|
+
|
|
102
|
+
return count < limit;
|
|
103
|
+
});
|
|
55
104
|
}
|
|
@@ -4,9 +4,10 @@ import { useTranslation } from 'react-i18next';
|
|
|
4
4
|
import { CircleOff } from 'lucide-react';
|
|
5
5
|
import { Icon } from '@adecore/ui';
|
|
6
6
|
import { useChatHost } from '../../host';
|
|
7
|
-
import { REFERENCE_GONE_TONE, REFERENCE_TONE, TOKEN_ICON, TOKEN_IN_MESSAGE } from './chips';
|
|
7
|
+
import { REFERENCE_GONE_TONE, REFERENCE_TONE, TOKEN_ICON, TOKEN_ICON_BOX, TOKEN_IN_MESSAGE } from './chips';
|
|
8
8
|
import { referenceGlyph } from './reference-icons';
|
|
9
9
|
import { ReferenceLookupContext } from './reference-lookup';
|
|
10
|
+
import { ReferenceTrail } from './ReferenceTrail';
|
|
10
11
|
|
|
11
12
|
interface TokenChipProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'children'> {
|
|
12
13
|
/* `gone` for a reference that stands for nothing any more, which a copy leaves as text. */
|
|
@@ -78,7 +79,12 @@ export function ReferenceChip({ id, lastName }: { id: string; lastName?: string
|
|
|
78
79
|
kind="reference"
|
|
79
80
|
value={item.id}
|
|
80
81
|
sigil="#"
|
|
81
|
-
icon={
|
|
82
|
+
icon={
|
|
83
|
+
<>
|
|
84
|
+
{item.trail !== undefined && <ReferenceTrail trail={item.trail} hostIcon={ReferenceIcon} size={14} iconClassName={TOKEN_ICON_BOX} />}
|
|
85
|
+
{referenceGlyph(ReferenceIcon, { id: item.id, kind: item.kind, size: 14, className: TOKEN_ICON })}
|
|
86
|
+
</>
|
|
87
|
+
}
|
|
82
88
|
label={item.name || t('references.untitled')}
|
|
83
89
|
tone={clsx(REFERENCE_TONE, open !== null && 'hover:bg-text/12')}
|
|
84
90
|
onOpen={open === null ? undefined : () => open(item.id)}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Fragment, type ComponentType } from 'react';
|
|
2
|
+
import { ChevronRight } from 'lucide-react';
|
|
3
|
+
import { Icon } from '@adecore/ui';
|
|
4
|
+
import type { ReferenceIconProps } from '../../host';
|
|
5
|
+
import type { ReferenceStep } from '../chat-references';
|
|
6
|
+
import { referenceGlyph } from './reference-icons';
|
|
7
|
+
|
|
8
|
+
interface ReferenceTrailProps {
|
|
9
|
+
trail: readonly ReferenceStep[];
|
|
10
|
+
hostIcon: ComponentType<ReferenceIconProps> | null | undefined;
|
|
11
|
+
size: number;
|
|
12
|
+
/* What sets a mark on the line, on a box around it, so it holds for whichever mark the host draws. */
|
|
13
|
+
iconClassName: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* Where a reference stands, in front of its own mark. Each place may shorten, so the name it leads to stays whole. */
|
|
17
|
+
export function ReferenceTrail({ trail, hostIcon, size, iconClassName }: ReferenceTrailProps) {
|
|
18
|
+
return (
|
|
19
|
+
<span className="font-normal text-text-muted">
|
|
20
|
+
{trail.map((step) => (
|
|
21
|
+
<Fragment key={step.id}>
|
|
22
|
+
<span className={iconClassName}>{referenceGlyph(hostIcon, { id: step.id, kind: step.kind, size })}</span>
|
|
23
|
+
<span className="inline-block max-w-40 truncate align-bottom">{step.name}</span>
|
|
24
|
+
<Icon icon={ChevronRight} size={12} className="mx-0.5 inline align-[calc(0.5cap-6px)]!" />
|
|
25
|
+
</Fragment>
|
|
26
|
+
))}
|
|
27
|
+
</span>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -562,7 +562,7 @@ function ContextRing({ usage }: { usage: ChatUsage }) {
|
|
|
562
562
|
|
|
563
563
|
return (
|
|
564
564
|
<svg width="14" height="14" viewBox="0 0 14 14" className={clsx('shrink-0', contextTone(fraction))} aria-hidden="true">
|
|
565
|
-
<circle cx="7" cy="7" r={RING_RADIUS} fill="none" strokeWidth="2" className="stroke-
|
|
565
|
+
<circle cx="7" cy="7" r={RING_RADIUS} fill="none" strokeWidth="2" className="stroke-track" />
|
|
566
566
|
<circle
|
|
567
567
|
cx="7"
|
|
568
568
|
cy="7"
|
|
@@ -603,7 +603,7 @@ function ContextUsage({ usage, disabled, onCompact }: { usage: ChatUsage; disabl
|
|
|
603
603
|
aria-valuemin={0}
|
|
604
604
|
aria-valuemax={100}
|
|
605
605
|
aria-label={t('contextMeter.aria', { percent })}
|
|
606
|
-
className="flex h-1.5 overflow-hidden rounded-full bg-
|
|
606
|
+
className="flex h-1.5 overflow-hidden rounded-full bg-track"
|
|
607
607
|
>
|
|
608
608
|
{segments ? (
|
|
609
609
|
segments.map((segment) => (
|
|
@@ -23,7 +23,7 @@ export function SessionLine({ window, now }: { window: UsageWindow; now: number
|
|
|
23
23
|
|
|
24
24
|
return (
|
|
25
25
|
<span className="flex items-center gap-2 text-xs text-text-faint tabular-nums">
|
|
26
|
-
<span aria-hidden className="relative h-1 w-14 shrink-0 rounded-full bg-
|
|
26
|
+
<span aria-hidden className="relative h-1 w-14 shrink-0 rounded-full bg-track">
|
|
27
27
|
<span className={clsx('absolute inset-y-0 left-0 rounded-full', tone.bar)} style={{ width: `${Math.min(100, percent)}%` }} />
|
|
28
28
|
{/* Where an even spread over the window would stand, as the usage bars mark it. */}
|
|
29
29
|
{mark !== null && (
|
package/src/chat/ui/chips.ts
CHANGED
|
@@ -26,6 +26,9 @@ export const TOKEN_IN_MESSAGE = 'box-decoration-clone rounded-md px-1.5 py-0.5 t
|
|
|
26
26
|
of the x-height `Icon` aligns on sits low next to a capital. */
|
|
27
27
|
export const TOKEN_ICON = 'mr-1 inline align-[calc(0.5cap-7px)]!';
|
|
28
28
|
|
|
29
|
+
/* The same for a box around a 14px mark, which has no baseline but its bottom edge. */
|
|
30
|
+
export const TOKEN_ICON_BOX = 'mr-1 inline-block align-[calc(0.5cap-7px)]';
|
|
31
|
+
|
|
29
32
|
/* The same middle for the 12px mark the composer draws, in a box whose bottom edge is its baseline. */
|
|
30
33
|
export const TOKEN_ICON_IN_EDITOR = 'mr-1 inline-block align-[calc(0.5cap-6px)]';
|
|
31
34
|
|
|
@@ -4,6 +4,7 @@ import clsx from 'clsx';
|
|
|
4
4
|
import { SquareSlash, Zap } from 'lucide-react';
|
|
5
5
|
import { FileIcon, Icon, Menu, MiddleTruncate } from '@adecore/ui';
|
|
6
6
|
import { useChatHost } from '../../../host';
|
|
7
|
+
import type { Referable } from '../../chat-references';
|
|
7
8
|
import { referenceGlyph } from '../reference-icons';
|
|
8
9
|
import type { ComposerMenus as Menus } from './use-composer-menus';
|
|
9
10
|
import { optionIdOf } from './menu-aria';
|
|
@@ -112,27 +113,45 @@ function ReferenceMenu({ menus }: { menus: Menus }) {
|
|
|
112
113
|
const { ReferenceIcon } = useChatHost();
|
|
113
114
|
const { listId, referenceMatches } = menus;
|
|
114
115
|
|
|
115
|
-
const groups =
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
const groups = new Map<string, Referable[]>();
|
|
117
|
+
|
|
118
|
+
for (const item of referenceMatches) {
|
|
119
|
+
const key = item.section?.id ?? item.group;
|
|
120
|
+
groups.set(key, [...(groups.get(key) ?? []), item]);
|
|
121
|
+
}
|
|
118
122
|
|
|
119
123
|
return (
|
|
120
|
-
<div className="border-b border-border px-1.5 py-1.5">
|
|
124
|
+
<div className="max-h-96 overflow-y-auto border-b border-border px-1.5 py-1.5">
|
|
121
125
|
{referenceMatches.length > 0 ? (
|
|
122
126
|
<div id={listId} role="listbox" aria-label={t('composer.menu.references')}>
|
|
123
|
-
{groups.map((
|
|
124
|
-
<div key={
|
|
125
|
-
<Menu.Label id={`${listId}-${
|
|
127
|
+
{[...groups].map(([key, items]) => (
|
|
128
|
+
<div key={key} role="group" aria-labelledby={`${listId}-${key}`}>
|
|
129
|
+
<Menu.Label id={`${listId}-${key}`} className="flex items-center gap-1.5">
|
|
130
|
+
{items[0]?.section === undefined ? (
|
|
131
|
+
t(`composer.references.${items[0]?.group ?? 'views'}`)
|
|
132
|
+
) : (
|
|
133
|
+
<>
|
|
134
|
+
{referenceGlyph(ReferenceIcon, { id: items[0].section.id, kind: 'project', size: 14, className: 'shrink-0' })}
|
|
135
|
+
<span className="truncate font-semibold text-text">{items[0].section.name}</span>
|
|
136
|
+
{items[0].section.current === true && (
|
|
137
|
+
<span className="ml-auto shrink-0 pl-2 font-normal">{t('composer.references.currentProject')}</span>
|
|
138
|
+
)}
|
|
139
|
+
</>
|
|
140
|
+
)}
|
|
141
|
+
</Menu.Label>
|
|
126
142
|
{items.map((item) => {
|
|
127
143
|
const index = referenceMatches.indexOf(item);
|
|
128
144
|
|
|
129
145
|
return (
|
|
130
|
-
<MenuOption
|
|
146
|
+
<MenuOption
|
|
147
|
+
key={item.id}
|
|
148
|
+
menus={menus}
|
|
149
|
+
index={index}
|
|
150
|
+
className={clsx('items-center', item.trail?.at(-1)?.kind === 'canvas' && 'pl-6')}
|
|
151
|
+
onPick={() => menus.chooseReference(item)}
|
|
152
|
+
>
|
|
131
153
|
{referenceGlyph(ReferenceIcon, { id: item.id, kind: item.kind, size: 14, className: 'shrink-0 text-text-faint' })}
|
|
132
154
|
<span className="truncate text-text">{item.name}</span>
|
|
133
|
-
<span className="ml-auto shrink-0 truncate pl-2 text-text-faint">
|
|
134
|
-
{item.detail ?? t(`composer.references.kinds.${item.kind}`)}
|
|
135
|
-
</span>
|
|
136
155
|
</MenuOption>
|
|
137
156
|
);
|
|
138
157
|
})}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { createElement, Fragment, type ComponentType } from 'react';
|
|
2
2
|
import { createRoot, type Root } from 'react-dom/client';
|
|
3
3
|
import { syntaxTree } from '@codemirror/language';
|
|
4
4
|
import { Facet, StateField, type EditorState, type Extension, type Range } from '@codemirror/state';
|
|
5
5
|
import { Decoration, EditorView, WidgetType, type DecorationSet } from '@codemirror/view';
|
|
6
6
|
import type { ReferenceIconProps } from '../../../host';
|
|
7
|
-
import type { ReferableKind } from '../../chat-references';
|
|
7
|
+
import type { ReferableKind, ReferenceStep } from '../../chat-references';
|
|
8
8
|
import { chipRanges, type ReferenceToken } from '../../mentions';
|
|
9
9
|
import { CHIP_IN_EDITOR, MENTION_TONE, REFERENCE_TONE, SKILL_TONE, TOKEN_ICON_IN_EDITOR } from '../chips';
|
|
10
10
|
import { referenceGlyph } from '../reference-icons';
|
|
11
|
+
import { ReferenceTrail } from '../ReferenceTrail';
|
|
11
12
|
import { codeRanges } from './editor';
|
|
12
13
|
|
|
13
14
|
export interface ChipChoices {
|
|
14
15
|
mentions: string[];
|
|
15
16
|
skills: string[];
|
|
16
17
|
/* Null for a kind the host no longer names, which draws the chip without its mark. */
|
|
17
|
-
references?: ReadonlyArray<ReferenceToken & { kind: ReferableKind | null }>;
|
|
18
|
+
references?: ReadonlyArray<ReferenceToken & { kind: ReferableKind | null; trail?: readonly ReferenceStep[] }>;
|
|
18
19
|
/* The host's mark of a reference, which the editor draws outside the host's provider. */
|
|
19
20
|
referenceIcon?: ComponentType<ReferenceIconProps> | null;
|
|
20
21
|
}
|
|
@@ -35,23 +36,38 @@ class ReferenceIcon extends WidgetType {
|
|
|
35
36
|
readonly id: string;
|
|
36
37
|
readonly kind: ReferableKind;
|
|
37
38
|
readonly hostIcon: ComponentType<ReferenceIconProps> | null;
|
|
39
|
+
readonly trail: readonly ReferenceStep[];
|
|
38
40
|
|
|
39
|
-
constructor(id: string, kind: ReferableKind, hostIcon: ComponentType<ReferenceIconProps> | null) {
|
|
41
|
+
constructor(id: string, kind: ReferableKind, hostIcon: ComponentType<ReferenceIconProps> | null, trail: readonly ReferenceStep[]) {
|
|
40
42
|
super();
|
|
41
43
|
this.id = id;
|
|
42
44
|
this.kind = kind;
|
|
43
45
|
this.hostIcon = hostIcon;
|
|
46
|
+
this.trail = trail;
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
override eq(other: ReferenceIcon): boolean {
|
|
47
|
-
return
|
|
50
|
+
return (
|
|
51
|
+
other.id === this.id && other.kind === this.kind && other.hostIcon === this.hostIcon && JSON.stringify(other.trail) === JSON.stringify(this.trail)
|
|
52
|
+
);
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
toDOM(): HTMLElement {
|
|
51
56
|
const holder = document.createElement('span');
|
|
52
|
-
holder.className = TOKEN_ICON_IN_EDITOR;
|
|
53
57
|
const root = createRoot(holder);
|
|
54
|
-
|
|
58
|
+
const glyph = referenceGlyph(this.hostIcon, { id: this.id, kind: this.kind, size: 12 });
|
|
59
|
+
|
|
60
|
+
holder.className = this.trail.length > 0 ? 'inline' : TOKEN_ICON_IN_EDITOR;
|
|
61
|
+
root.render(
|
|
62
|
+
this.trail.length > 0
|
|
63
|
+
? createElement(
|
|
64
|
+
Fragment,
|
|
65
|
+
null,
|
|
66
|
+
createElement(ReferenceTrail, { trail: this.trail, hostIcon: this.hostIcon, size: 12, iconClassName: TOKEN_ICON_IN_EDITOR }),
|
|
67
|
+
createElement('span', { className: TOKEN_ICON_IN_EDITOR }, glyph)
|
|
68
|
+
)
|
|
69
|
+
: glyph
|
|
70
|
+
);
|
|
55
71
|
roots.set(holder, root);
|
|
56
72
|
|
|
57
73
|
return holder;
|
|
@@ -67,7 +83,7 @@ class ReferenceIcon extends WidgetType {
|
|
|
67
83
|
|
|
68
84
|
function chipMarks(state: EditorState): DecorationSet {
|
|
69
85
|
const { mentions, skills, references = [], referenceIcon = null } = state.facet(choices);
|
|
70
|
-
const
|
|
86
|
+
const tokens = new Map(references.map((token) => [token.id, token]));
|
|
71
87
|
const marks: Range<Decoration>[] = [];
|
|
72
88
|
|
|
73
89
|
// `@a.ts` in backticks is code, not a mention.
|
|
@@ -79,10 +95,12 @@ function chipMarks(state: EditorState): DecorationSet {
|
|
|
79
95
|
}
|
|
80
96
|
|
|
81
97
|
marks.push(referenceMark.range(range.from, range.to));
|
|
82
|
-
const
|
|
98
|
+
const token = tokens.get(range.value);
|
|
83
99
|
|
|
84
|
-
if (kind !== undefined && kind !== null) {
|
|
85
|
-
marks.push(
|
|
100
|
+
if (token?.kind !== undefined && token.kind !== null) {
|
|
101
|
+
marks.push(
|
|
102
|
+
Decoration.replace({ widget: new ReferenceIcon(range.value, token.kind, referenceIcon, token.trail ?? []) }).range(range.from, range.from + 1)
|
|
103
|
+
);
|
|
86
104
|
}
|
|
87
105
|
}
|
|
88
106
|
|