@lemonriver/core 0.4.0 → 0.5.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/README.md +14 -4
- package/dist/{build-Nl7EeJ6x.js → build-CS1goZxt.js} +1 -1
- package/dist/cli/bin.js +4 -4
- package/dist/{config-CpC0nM3r.js → config-BpbcCbUv.js} +3673 -2065
- package/dist/{dev-BB3THd5I.js → dev-BpYnfgLL.js} +2 -2
- package/dist/{preview-BGjgTg7H.js → preview-HSzPPkSs.js} +1 -1
- package/dist/{update-DsxZBtwv.js → update-CMRxtTc9.js} +18 -8
- package/dist/vite/index.js +1 -1
- package/package.json +2 -2
- package/src/agent/types.ts +14 -2
- package/src/app/components/agent/agent-panel.tsx +17 -5
- package/src/app/components/agent/connect-view.tsx +1 -1
- package/src/app/components/agent/provider-logo.tsx +10 -1
- package/src/app/lemonriver/agent/provider-marks.tsx +53 -0
- package/src/app/lemonriver/agent-providers/section.tsx +75 -0
- package/src/app/lemonriver/agent-providers/use-providers.ts +61 -0
- package/src/app/lemonriver/board/blocks/block-panel.tsx +666 -0
- package/src/app/lemonriver/board/blocks/cache.ts +28 -0
- package/src/app/lemonriver/board/blocks/change-list.tsx +189 -0
- package/src/app/lemonriver/board/blocks/classify.test.ts +204 -0
- package/src/app/lemonriver/board/blocks/classify.ts +125 -0
- package/src/app/lemonriver/board/blocks/snapshot.ts +86 -0
- package/src/app/lemonriver/board/board-canvas.tsx +627 -104
- package/src/app/lemonriver/board/board-page.tsx +1687 -91
- package/src/app/lemonriver/board/board.css +58 -7
- package/src/app/lemonriver/board/layout.test.ts +84 -0
- package/src/app/lemonriver/board/layout.ts +112 -11
- package/src/app/lemonriver/board/model/agent-tasks.test.ts +200 -0
- package/src/app/lemonriver/board/model/agent-tasks.ts +191 -0
- package/src/app/lemonriver/board/model/apply-prompt.test.ts +121 -0
- package/src/app/lemonriver/board/model/apply-prompt.ts +115 -0
- package/src/app/lemonriver/board/model/apply.ts +71 -0
- package/src/app/lemonriver/board/model/cards.test.ts +95 -2
- package/src/app/lemonriver/board/model/cards.ts +88 -20
- package/src/app/lemonriver/board/model/changes.test.ts +244 -0
- package/src/app/lemonriver/board/model/changes.ts +268 -0
- package/src/app/lemonriver/board/model/filter.test.ts +50 -0
- package/src/app/lemonriver/board/model/filter.ts +42 -0
- package/src/app/lemonriver/board/model/history.test.ts +71 -0
- package/src/app/lemonriver/board/model/history.ts +51 -0
- package/src/app/lemonriver/board/model/restructure.test.ts +205 -0
- package/src/app/lemonriver/board/model/restructure.ts +169 -0
- package/src/app/lemonriver/board/model/structure.test.ts +249 -0
- package/src/app/lemonriver/board/model/structure.ts +209 -0
- package/src/app/lemonriver/board/model/timing.test.ts +113 -0
- package/src/app/lemonriver/board/model/timing.ts +117 -0
- package/src/app/lemonriver/board/page-node.tsx +236 -55
- package/src/app/lemonriver/board/status-style.ts +25 -0
- package/src/app/lemonriver/board/use-board-apply.ts +206 -0
- package/src/app/lemonriver/board/use-board-cards.ts +108 -5
- package/src/app/lemonriver/board/use-board-changes.ts +108 -0
- package/src/app/lemonriver/board/use-board-columns.ts +37 -56
- package/src/app/lemonriver/board/use-board-comments.ts +36 -0
- package/src/app/lemonriver/board/use-board-restructures.ts +107 -0
- package/src/app/lemonriver/board/use-history.ts +86 -0
- package/src/app/lemonriver/board/use-page-order.ts +65 -38
- package/src/app/lemonriver/board/use-target-minutes.ts +47 -0
- package/src/app/lemonriver/board/views/block-readings.tsx +46 -0
- package/src/app/lemonriver/board/views/list-view.tsx +356 -0
- package/src/app/lemonriver/board/views/progress.tsx +32 -0
- package/src/app/lemonriver/board/views/timeline-view.tsx +341 -0
- package/src/app/lemonriver/outline/model.test.ts +39 -0
- package/src/app/lemonriver/outline/model.ts +12 -0
- package/src/app/lemonriver/outline/outline-page.tsx +34 -1
- package/src/app/lemonriver/settings/settings-page.tsx +3 -0
- package/src/app/lemonriver/slide-extensions.tsx +14 -2
- package/src/app/lemonriver/text/en.ts +171 -0
- package/src/app/lemonriver/text/es.ts +163 -0
- package/src/app/lemonriver/text/ja.ts +163 -0
- package/src/app/lemonriver/text/types.ts +170 -0
- package/src/app/lemonriver/text/zh-cn.ts +161 -0
- package/src/app/lemonriver/text/zh-tw.ts +161 -0
- package/src/app/lemonriver/theme/lemon-icon.tsx +6 -0
- package/src/app/lemonriver/theme/theme-menu.tsx +3 -2
- package/src/app/lemonriver/theme/use-theme.tsx +2 -2
- package/src/app/lib/agent/use-agent.ts +4 -3
- package/src/app/routes/slide.tsx +1 -1
- package/src/app/assets/open-slide.svg +0 -39
- package/src/app/favicon.ico +0 -0
- package/src/app/favicon.svg +0 -39
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { V as PKG_NAMES } from "./update-
|
|
1
|
+
import { V as PKG_NAMES } from "./update-CMRxtTc9.js";
|
|
2
2
|
import { a as printUrls, i as printShortcutsHint, n as formatError, o as shortcutsEnabled, r as printHeader, s as startupDuration, t as createCliLogger } from "./cli/bin.js";
|
|
3
|
-
import { n as DEV_SUPERVISED_ENV, t as createViteConfig } from "./config-
|
|
3
|
+
import { n as DEV_SUPERVISED_ENV, t as createViteConfig } from "./config-BpbcCbUv.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { fork } from "node:child_process";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as printUrls, i as printShortcutsHint, o as shortcutsEnabled, r as printHeader, s as startupDuration, t as createCliLogger } from "./cli/bin.js";
|
|
2
|
-
import { t as createViteConfig } from "./config-
|
|
2
|
+
import { t as createViteConfig } from "./config-BpbcCbUv.js";
|
|
3
3
|
import { mergeConfig, preview as preview$1 } from "vite";
|
|
4
4
|
//#region src/cli/preview.ts
|
|
5
5
|
async function preview(opts = {}) {
|
|
@@ -99,28 +99,37 @@ function declaredFrameworkSpecifier(userCwd) {
|
|
|
99
99
|
for (const name of PKG_NAMES) if (name in deps) return name;
|
|
100
100
|
return PKG_NAME;
|
|
101
101
|
}
|
|
102
|
-
function aliasTarget(value) {
|
|
103
|
-
if (
|
|
104
|
-
|
|
102
|
+
function aliasTarget(key, value) {
|
|
103
|
+
if (value.startsWith("npm:")) {
|
|
104
|
+
const rest = value.slice(4);
|
|
105
|
+
const at = rest.lastIndexOf("@");
|
|
106
|
+
return at > 0 ? rest.slice(0, at) : rest;
|
|
107
|
+
}
|
|
108
|
+
if (!value.startsWith("workspace:")) return null;
|
|
109
|
+
const rest = value.slice(10);
|
|
110
|
+
if (!rest.includes("@")) return null;
|
|
105
111
|
const at = rest.lastIndexOf("@");
|
|
106
|
-
|
|
112
|
+
const target = at > 0 ? rest.slice(0, at) : rest;
|
|
113
|
+
return target === key ? null : target;
|
|
107
114
|
}
|
|
108
115
|
function readFrameworkDependency(userCwd) {
|
|
109
116
|
const deps = readDeps(userCwd);
|
|
110
117
|
for (const name of PKG_NAMES) {
|
|
111
118
|
const value = deps[name];
|
|
112
119
|
if (value === void 0) continue;
|
|
113
|
-
const aliased = aliasTarget(value);
|
|
120
|
+
const aliased = aliasTarget(name, value);
|
|
114
121
|
return {
|
|
115
122
|
key: name,
|
|
116
123
|
pkg: aliased ?? name,
|
|
117
|
-
addTarget: aliased ? `${name}@npm:${aliased}@latest` : `${name}@latest
|
|
124
|
+
addTarget: aliased ? `${name}@npm:${aliased}@latest` : `${name}@latest`,
|
|
125
|
+
workspace: value.startsWith("workspace:")
|
|
118
126
|
};
|
|
119
127
|
}
|
|
120
128
|
return {
|
|
121
129
|
key: PKG_NAME,
|
|
122
130
|
pkg: PKG_NAME,
|
|
123
|
-
addTarget: `${PKG_NAME}@latest
|
|
131
|
+
addTarget: `${PKG_NAME}@latest`,
|
|
132
|
+
workspace: false
|
|
124
133
|
};
|
|
125
134
|
}
|
|
126
135
|
//#endregion
|
|
@@ -1063,7 +1072,8 @@ async function updatePackage(ctx) {
|
|
|
1063
1072
|
function registerUpdateRoutes(server, ctx) {
|
|
1064
1073
|
server.middlewares.use("/__update-check", async (req, res, next) => {
|
|
1065
1074
|
if ((req.method ?? "GET") !== "GET") return next();
|
|
1066
|
-
const
|
|
1075
|
+
const dependency = readFrameworkDependency(ctx.userCwd);
|
|
1076
|
+
const latest = dependency.workspace ? null : await fetchLatest(dependency.pkg, Date.now());
|
|
1067
1077
|
const result = {
|
|
1068
1078
|
current: ctx.coreVersion,
|
|
1069
1079
|
latest,
|
package/dist/vite/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createViteConfig } from "../config-
|
|
1
|
+
import { t as createViteConfig } from "../config-BpbcCbUv.js";
|
|
2
2
|
export { createViteConfig };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemonriver/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "The LemonRiver runtime: deck viewer, story board, present mode, agent panel and export.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
package/src/agent/types.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
export const AGENT_PROVIDER_IDS = ['claude', 'codex'] as const;
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// Extra providers this release adds. They stay out of the panel until the user
|
|
4
|
+
// switches them on in Settings, so a default workspace behaves as before.
|
|
5
|
+
export const LEMONRIVER_PROVIDER_IDS = ['workbuddy', 'dumate'] as const;
|
|
6
|
+
|
|
7
|
+
export type AgentProviderId =
|
|
8
|
+
| (typeof AGENT_PROVIDER_IDS)[number]
|
|
9
|
+
| (typeof LEMONRIVER_PROVIDER_IDS)[number];
|
|
4
10
|
|
|
5
11
|
export const AGENT_EFFORTS = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'] as const;
|
|
6
12
|
|
|
7
13
|
export type AgentEffort = (typeof AGENT_EFFORTS)[number];
|
|
8
14
|
|
|
9
15
|
export function isAgentProviderId(value: unknown): value is AgentProviderId {
|
|
10
|
-
return
|
|
16
|
+
return (
|
|
17
|
+
typeof value === 'string' &&
|
|
18
|
+
((AGENT_PROVIDER_IDS as readonly string[]).includes(value) ||
|
|
19
|
+
(LEMONRIVER_PROVIDER_IDS as readonly string[]).includes(value))
|
|
20
|
+
);
|
|
11
21
|
}
|
|
12
22
|
|
|
13
23
|
export function isAgentEffort(value: unknown): value is AgentEffort {
|
|
@@ -19,6 +29,8 @@ export type AgentModelOption = {
|
|
|
19
29
|
id: string;
|
|
20
30
|
label: string;
|
|
21
31
|
efforts: AgentEffort[];
|
|
32
|
+
// The effort that option's client is set to, for the follow-the-client row.
|
|
33
|
+
clientEffort?: AgentEffort | null;
|
|
22
34
|
};
|
|
23
35
|
|
|
24
36
|
export type AgentProviderStatus = {
|
|
@@ -49,6 +49,7 @@ import type {
|
|
|
49
49
|
} from '../../../agent/types';
|
|
50
50
|
import { PanelLemon } from '../../lemonriver/agent/lemon';
|
|
51
51
|
import { BuildTeam } from '../../lemonriver/outline/build-team';
|
|
52
|
+
import { useLrText } from '../../lemonriver/text';
|
|
52
53
|
import { Composer, ContextChip } from './composer';
|
|
53
54
|
import { ConnectView } from './connect-view';
|
|
54
55
|
import { HistoryView } from './history-view';
|
|
@@ -357,8 +358,8 @@ export function AgentPanel({
|
|
|
357
358
|
);
|
|
358
359
|
}
|
|
359
360
|
|
|
360
|
-
function modelLabel(model: AgentModelOption
|
|
361
|
-
return model.
|
|
361
|
+
function modelLabel(model: AgentModelOption): string {
|
|
362
|
+
return model.label;
|
|
362
363
|
}
|
|
363
364
|
|
|
364
365
|
function ModelMenu({
|
|
@@ -379,6 +380,7 @@ function ModelMenu({
|
|
|
379
380
|
onManage: () => void;
|
|
380
381
|
}) {
|
|
381
382
|
const t = useLocale();
|
|
383
|
+
const lr = useLrText();
|
|
382
384
|
const [open, setOpen] = useState(false);
|
|
383
385
|
const providers = status?.enabled ? status.providers : [];
|
|
384
386
|
const [tab, setTab] = useState<AgentProviderId | null>(providerId);
|
|
@@ -405,7 +407,7 @@ function ModelMenu({
|
|
|
405
407
|
) : (
|
|
406
408
|
<span aria-hidden className="size-1.5 rounded-full bg-muted-foreground/50" />
|
|
407
409
|
)}
|
|
408
|
-
<span className="truncate">{model ? modelLabel(model
|
|
410
|
+
<span className="truncate">{model ? modelLabel(model) : t.agent.title}</span>
|
|
409
411
|
{effort && (
|
|
410
412
|
<span className="shrink-0 font-normal text-muted-foreground">
|
|
411
413
|
{t.agent.efforts[effort]}
|
|
@@ -465,10 +467,15 @@ function ModelMenu({
|
|
|
465
467
|
key={m.id}
|
|
466
468
|
type="button"
|
|
467
469
|
aria-pressed={checked}
|
|
470
|
+
title={
|
|
471
|
+
m.id === ''
|
|
472
|
+
? format(lr.agentModel.followClientHint, { provider: shown.name })
|
|
473
|
+
: undefined
|
|
474
|
+
}
|
|
468
475
|
onClick={() =>
|
|
469
476
|
setModelChoice(shown.id, {
|
|
470
477
|
model: m.id,
|
|
471
|
-
effort: modelChoices[shown.id]?.effort ?? null,
|
|
478
|
+
effort: m.id ? (modelChoices[shown.id]?.effort ?? null) : null,
|
|
472
479
|
})
|
|
473
480
|
}
|
|
474
481
|
className={cn(
|
|
@@ -476,7 +483,12 @@ function ModelMenu({
|
|
|
476
483
|
checked && 'font-medium',
|
|
477
484
|
)}
|
|
478
485
|
>
|
|
479
|
-
<span className="truncate">{modelLabel(m
|
|
486
|
+
<span className="truncate">{modelLabel(m)}</span>
|
|
487
|
+
{m.id === '' && (
|
|
488
|
+
<span className="ml-auto shrink-0 text-[11px] font-normal text-muted-foreground">
|
|
489
|
+
{lr.agentModel.followClient}
|
|
490
|
+
</span>
|
|
491
|
+
)}
|
|
480
492
|
{checked && <Check className="size-3.5 shrink-0" aria-hidden />}
|
|
481
493
|
</button>
|
|
482
494
|
);
|
|
@@ -13,7 +13,7 @@ import { cn } from '@/lib/utils';
|
|
|
13
13
|
import type { AgentProviderId, AgentProviderStatus } from '../../../agent/types';
|
|
14
14
|
import { ProviderLogo } from './provider-logo';
|
|
15
15
|
|
|
16
|
-
const CLI_INSTALL: Record<AgentProviderId, string
|
|
16
|
+
const CLI_INSTALL: Partial<Record<AgentProviderId, string>> = {
|
|
17
17
|
claude: 'npm install -g @anthropic-ai/claude-code',
|
|
18
18
|
codex: 'npm install -g @openai/codex',
|
|
19
19
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SVGProps } from 'react';
|
|
2
2
|
import type { AgentProviderId } from '../../../agent/types';
|
|
3
|
+
import { ExtraProviderLogo } from '../../lemonriver/agent/provider-marks';
|
|
3
4
|
|
|
4
5
|
// Marks from svgl.app (claude-ai-icon, openai).
|
|
5
6
|
function ClaudeLogo(props: SVGProps<SVGSVGElement>) {
|
|
@@ -28,7 +29,15 @@ function OpenAILogo(props: SVGProps<SVGSVGElement>) {
|
|
|
28
29
|
|
|
29
30
|
export function ProviderLogo({
|
|
30
31
|
provider,
|
|
32
|
+
className,
|
|
31
33
|
...props
|
|
32
34
|
}: { provider: AgentProviderId } & SVGProps<SVGSVGElement>) {
|
|
33
|
-
|
|
35
|
+
if (provider !== 'claude' && provider !== 'codex') {
|
|
36
|
+
return <ExtraProviderLogo provider={provider} className={className} />;
|
|
37
|
+
}
|
|
38
|
+
return provider === 'claude' ? (
|
|
39
|
+
<ClaudeLogo className={className} {...props} />
|
|
40
|
+
) : (
|
|
41
|
+
<OpenAILogo className={className} {...props} />
|
|
42
|
+
);
|
|
34
43
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import type { AgentProviderId } from '../../../agent/types';
|
|
3
|
+
import { cn } from '../../lib/utils';
|
|
4
|
+
|
|
5
|
+
// These products pick their own app icon on the machine they are installed on,
|
|
6
|
+
// so the panel shows the real one and falls back to our initial in a circle
|
|
7
|
+
// when the app is missing. The image is never bundled with us; the dev server
|
|
8
|
+
// reads it off the installed app and caches it under node_modules.
|
|
9
|
+
const MARKS: Partial<Record<AgentProviderId, { letter: string; fill: string }>> = {
|
|
10
|
+
workbuddy: { letter: 'W', fill: '#1F8A5B' },
|
|
11
|
+
dumate: { letter: 'D', fill: '#3357CE' },
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function ExtraProviderLogo({
|
|
15
|
+
provider,
|
|
16
|
+
className,
|
|
17
|
+
}: {
|
|
18
|
+
provider: AgentProviderId;
|
|
19
|
+
className?: string;
|
|
20
|
+
}) {
|
|
21
|
+
const [unavailable, setUnavailable] = useState(false);
|
|
22
|
+
const mark = MARKS[provider];
|
|
23
|
+
|
|
24
|
+
if (mark && !unavailable) {
|
|
25
|
+
return (
|
|
26
|
+
<img
|
|
27
|
+
src={`/__lr/agent-providers/${provider}/icon`}
|
|
28
|
+
alt=""
|
|
29
|
+
aria-hidden="true"
|
|
30
|
+
className={cn('rounded-[3px] object-contain', className)}
|
|
31
|
+
onError={() => setUnavailable(true)}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const fallback = mark ?? { letter: '?', fill: '#6B7280' };
|
|
37
|
+
return (
|
|
38
|
+
<svg viewBox="0 0 24 24" aria-hidden="true" className={className}>
|
|
39
|
+
<circle cx="12" cy="12" r="12" fill={fallback.fill} />
|
|
40
|
+
<text
|
|
41
|
+
x="12"
|
|
42
|
+
y="16.4"
|
|
43
|
+
textAnchor="middle"
|
|
44
|
+
fontSize="13.5"
|
|
45
|
+
fontWeight="700"
|
|
46
|
+
fill="#ffffff"
|
|
47
|
+
fontFamily="-apple-system, BlinkMacSystemFont, Inter, sans-serif"
|
|
48
|
+
>
|
|
49
|
+
{fallback.letter}
|
|
50
|
+
</text>
|
|
51
|
+
</svg>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { toast } from 'sonner';
|
|
2
|
+
import { format } from '@/lib/use-locale';
|
|
3
|
+
import { cn } from '@/lib/utils';
|
|
4
|
+
import { ProviderLogo } from '../../components/agent/provider-logo';
|
|
5
|
+
import { useLrText } from '../text';
|
|
6
|
+
import { type AgentProviderRow, useAgentProviders } from './use-providers';
|
|
7
|
+
|
|
8
|
+
export function AgentProvidersSection() {
|
|
9
|
+
const lr = useLrText();
|
|
10
|
+
const { catalog, saving, setEnabled } = useAgentProviders();
|
|
11
|
+
if (!catalog) return null;
|
|
12
|
+
|
|
13
|
+
const on = new Set(catalog.enabled);
|
|
14
|
+
|
|
15
|
+
async function toggle(row: AgentProviderRow) {
|
|
16
|
+
const ok = await setEnabled(row.id, !on.has(row.id));
|
|
17
|
+
if (!ok) toast.error(lr.agents.saveFailed);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function hint(row: AgentProviderRow): string {
|
|
21
|
+
if (!row.detected) return lr.agents.missingHint;
|
|
22
|
+
if (row.connectable) return lr.agents.detected;
|
|
23
|
+
if (row.reason === 'desktop-only') return lr.agents.dumateReason;
|
|
24
|
+
return lr.agents.missingHint;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<section
|
|
29
|
+
data-lr-agent-providers
|
|
30
|
+
className="mt-5 rounded-[16px] border border-border bg-card px-6 py-5 shadow-[var(--lr-shadow-1)]"
|
|
31
|
+
>
|
|
32
|
+
<h2 className="text-[16px] font-semibold">{lr.agents.title}</h2>
|
|
33
|
+
<p className="mt-1 mb-2 text-[14px] text-muted-foreground">{lr.agents.hint}</p>
|
|
34
|
+
|
|
35
|
+
<ul className="divide-y divide-border border-t border-border">
|
|
36
|
+
{catalog.providers.map((row) => {
|
|
37
|
+
const checked = row.builtin || on.has(row.id);
|
|
38
|
+
const locked = row.builtin || !row.detected || !row.connectable;
|
|
39
|
+
return (
|
|
40
|
+
<li key={row.id} data-lr-agent-row={row.id} className="flex items-center gap-3 py-3">
|
|
41
|
+
<ProviderLogo provider={row.id} className="size-6 shrink-0" />
|
|
42
|
+
<div className="min-w-0 flex-1">
|
|
43
|
+
<p className="text-[14px] font-semibold">
|
|
44
|
+
{row.name}
|
|
45
|
+
{row.builtin && (
|
|
46
|
+
<span className="ml-2 text-[12px] font-normal text-muted-foreground">
|
|
47
|
+
{lr.agents.alwaysOn}
|
|
48
|
+
</span>
|
|
49
|
+
)}
|
|
50
|
+
</p>
|
|
51
|
+
<p data-lr-agent-state={row.id} className="text-[12px] text-muted-foreground">
|
|
52
|
+
{hint(row)}
|
|
53
|
+
</p>
|
|
54
|
+
</div>
|
|
55
|
+
<button
|
|
56
|
+
type="button"
|
|
57
|
+
role="switch"
|
|
58
|
+
data-lr-agent-switch={row.id}
|
|
59
|
+
aria-checked={checked}
|
|
60
|
+
aria-label={format(lr.agents.unlock, { name: row.name })}
|
|
61
|
+
aria-disabled={locked}
|
|
62
|
+
disabled={locked || saving === row.id}
|
|
63
|
+
onClick={() => void toggle(row)}
|
|
64
|
+
className={cn(
|
|
65
|
+
'lr-switch shrink-0 outline-none focus-visible:ring-2 focus-visible:ring-ring/40',
|
|
66
|
+
locked && 'cursor-not-allowed opacity-45',
|
|
67
|
+
)}
|
|
68
|
+
/>
|
|
69
|
+
</li>
|
|
70
|
+
);
|
|
71
|
+
})}
|
|
72
|
+
</ul>
|
|
73
|
+
</section>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { refreshStatus } from '@/lib/agent/use-agent';
|
|
3
|
+
import type { AgentProviderId } from '../../../agent/types';
|
|
4
|
+
|
|
5
|
+
export type AgentProviderRow = {
|
|
6
|
+
id: AgentProviderId;
|
|
7
|
+
name: string;
|
|
8
|
+
builtin: boolean;
|
|
9
|
+
detected: boolean;
|
|
10
|
+
connectable: boolean;
|
|
11
|
+
reason: string | null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type Catalog = { enabled: string[]; providers: AgentProviderRow[] };
|
|
15
|
+
|
|
16
|
+
export function useAgentProviders() {
|
|
17
|
+
const [catalog, setCatalog] = useState<Catalog | null>(null);
|
|
18
|
+
const [saving, setSaving] = useState<string | null>(null);
|
|
19
|
+
|
|
20
|
+
const load = useCallback(async () => {
|
|
21
|
+
try {
|
|
22
|
+
const res = await fetch('/__lr/agent-providers');
|
|
23
|
+
if (!res.ok) return;
|
|
24
|
+
setCatalog((await res.json()) as Catalog);
|
|
25
|
+
} catch {}
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!import.meta.env.DEV) return;
|
|
30
|
+
void load();
|
|
31
|
+
}, [load]);
|
|
32
|
+
|
|
33
|
+
const setEnabled = useCallback(
|
|
34
|
+
async (id: string, on: boolean): Promise<boolean> => {
|
|
35
|
+
if (!catalog) return false;
|
|
36
|
+
const next = on
|
|
37
|
+
? [...catalog.enabled.filter((x) => x !== id), id]
|
|
38
|
+
: catalog.enabled.filter((x) => x !== id);
|
|
39
|
+
setSaving(id);
|
|
40
|
+
try {
|
|
41
|
+
const res = await fetch('/__lr/agent-providers', {
|
|
42
|
+
method: 'PUT',
|
|
43
|
+
headers: { 'content-type': 'application/json' },
|
|
44
|
+
body: JSON.stringify({ enabled: next }),
|
|
45
|
+
});
|
|
46
|
+
if (!res.ok) return false;
|
|
47
|
+
const body = (await res.json()) as { enabled: string[] };
|
|
48
|
+
setCatalog({ ...catalog, enabled: body.enabled });
|
|
49
|
+
void refreshStatus();
|
|
50
|
+
return true;
|
|
51
|
+
} catch {
|
|
52
|
+
return false;
|
|
53
|
+
} finally {
|
|
54
|
+
setSaving(null);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
[catalog],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return { catalog, saving, setEnabled, reload: load };
|
|
61
|
+
}
|