@agentprojectcontext/apx 1.15.6 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/package.json +46 -5
  2. package/src/cli/commands/log.js +113 -0
  3. package/src/cli/commands/overlay.js +253 -0
  4. package/src/cli/commands/sys.js +88 -16
  5. package/src/cli/index.js +23 -1
  6. package/src/cli/terminal-chat/renderer.js +71 -56
  7. package/src/cli-ts/commands/agent.ts +173 -0
  8. package/src/cli-ts/commands/chat.ts +119 -0
  9. package/src/cli-ts/commands/daemon.ts +112 -0
  10. package/src/cli-ts/commands/exec.ts +109 -0
  11. package/src/cli-ts/commands/mcp.ts +235 -0
  12. package/src/cli-ts/commands/session.ts +224 -0
  13. package/src/cli-ts/commands/status.ts +61 -0
  14. package/src/cli-ts/http.ts +36 -0
  15. package/src/cli-ts/index.ts +73 -0
  16. package/src/cli-ts/ui.ts +107 -0
  17. package/src/core/logging.js +81 -0
  18. package/src/daemon/api.js +58 -0
  19. package/src/daemon/engines/anthropic.js +60 -1
  20. package/src/daemon/engines/index.js +2 -1
  21. package/src/daemon/engines/ollama.js +70 -3
  22. package/src/daemon/index.js +58 -0
  23. package/src/daemon/overlay-ws.js +40 -0
  24. package/src/daemon/plugins/index.js +2 -1
  25. package/src/daemon/plugins/overlay.js +177 -0
  26. package/src/daemon/plugins/telegram.js +15 -3
  27. package/src/daemon/super-agent-langchain.js +296 -0
  28. package/src/daemon/super-agent.js +115 -19
  29. package/src/daemon/transcription.js +262 -59
  30. package/src/daemon/whisper-server.py +57 -6
  31. package/src/overlay/index.html +44 -0
  32. package/src/overlay/main.js +480 -0
  33. package/src/overlay/package.json +3 -0
  34. package/src/overlay/preload.js +34 -0
  35. package/src/overlay/renderer.js +371 -0
  36. package/src/overlay/style.css +250 -0
  37. package/src/tui/_shims/cli-error.ts +6 -0
  38. package/src/tui/_shims/cli-logo.ts +18 -0
  39. package/src/tui/_shims/cli-ui.ts +1 -0
  40. package/src/tui/_shims/config-console-state.ts +7 -0
  41. package/src/tui/_shims/core-any.ts +30 -0
  42. package/src/tui/_shims/core-binary.ts +13 -0
  43. package/src/tui/_shims/core-flag.ts +3 -0
  44. package/src/tui/_shims/core-log.ts +14 -0
  45. package/src/tui/_shims/lsp-language.ts +1 -0
  46. package/src/tui/_shims/opencode-any.ts +135 -0
  47. package/src/tui/_shims/opencode-sdk-v2.ts +48 -0
  48. package/src/tui/_shims/plugin-tui.ts +13 -0
  49. package/src/tui/_shims/provider-provider.ts +10 -0
  50. package/src/tui/_shims/session-retry.ts +1 -0
  51. package/src/tui/_shims/session-schema.ts +15 -0
  52. package/src/tui/_shims/session-session.ts +3 -0
  53. package/src/tui/_shims/snapshot.ts +4 -0
  54. package/src/tui/_shims/tool-any.ts +18 -0
  55. package/src/tui/_shims/util-error.ts +7 -0
  56. package/src/tui/_shims/util-filesystem.ts +79 -0
  57. package/src/tui/_shims/util-format.ts +7 -0
  58. package/src/tui/_shims/util-iife.ts +3 -0
  59. package/src/tui/_shims/util-locale.ts +10 -0
  60. package/src/tui/_shims/util-process.ts +38 -0
  61. package/src/tui/app.tsx +783 -0
  62. package/src/tui/asset/charge.wav +0 -0
  63. package/src/tui/asset/pulse-a.wav +0 -0
  64. package/src/tui/asset/pulse-b.wav +0 -0
  65. package/src/tui/asset/pulse-c.wav +0 -0
  66. package/src/tui/attach.ts +100 -0
  67. package/src/tui/component/bg-pulse-render.ts +436 -0
  68. package/src/tui/component/bg-pulse.tsx +99 -0
  69. package/src/tui/component/border.tsx +21 -0
  70. package/src/tui/component/dialog-agent.tsx +31 -0
  71. package/src/tui/component/dialog-console-org.tsx +103 -0
  72. package/src/tui/component/dialog-mcp.tsx +85 -0
  73. package/src/tui/component/dialog-model.tsx +175 -0
  74. package/src/tui/component/dialog-provider.tsx +456 -0
  75. package/src/tui/component/dialog-retry-action.tsx +160 -0
  76. package/src/tui/component/dialog-session-delete-failed.tsx +99 -0
  77. package/src/tui/component/dialog-session-list.tsx +323 -0
  78. package/src/tui/component/dialog-session-rename.tsx +31 -0
  79. package/src/tui/component/dialog-skill.tsx +36 -0
  80. package/src/tui/component/dialog-stash.tsx +87 -0
  81. package/src/tui/component/dialog-status.tsx +168 -0
  82. package/src/tui/component/dialog-tag.tsx +44 -0
  83. package/src/tui/component/dialog-theme-list.tsx +50 -0
  84. package/src/tui/component/dialog-variant.tsx +39 -0
  85. package/src/tui/component/dialog-workspace-create.tsx +302 -0
  86. package/src/tui/component/dialog-workspace-file-changes.tsx +138 -0
  87. package/src/tui/component/dialog-workspace-unavailable.tsx +69 -0
  88. package/src/tui/component/error-component.tsx +92 -0
  89. package/src/tui/component/logo.tsx +896 -0
  90. package/src/tui/component/plugin-route-missing.tsx +14 -0
  91. package/src/tui/component/prompt/autocomplete.tsx +869 -0
  92. package/src/tui/component/prompt/cwd.ts +0 -0
  93. package/src/tui/component/prompt/frecency.tsx +90 -0
  94. package/src/tui/component/prompt/history.tsx +108 -0
  95. package/src/tui/component/prompt/index.tsx +1809 -0
  96. package/src/tui/component/prompt/part.ts +16 -0
  97. package/src/tui/component/prompt/stash.tsx +101 -0
  98. package/src/tui/component/prompt/traits.ts +35 -0
  99. package/src/tui/component/spinner.tsx +24 -0
  100. package/src/tui/component/startup-loading.tsx +63 -0
  101. package/src/tui/component/todo-item.tsx +32 -0
  102. package/src/tui/component/use-connected.tsx +9 -0
  103. package/src/tui/component/workspace-label.tsx +19 -0
  104. package/src/tui/config/cwd.ts +5 -0
  105. package/src/tui/config/keybind.ts +432 -0
  106. package/src/tui/config/tui-migrate.ts +154 -0
  107. package/src/tui/config/tui-schema.ts +34 -0
  108. package/src/tui/config/tui.ts +46 -0
  109. package/src/tui/context/aggregate-failures.ts +34 -0
  110. package/src/tui/context/args.tsx +15 -0
  111. package/src/tui/context/command-palette.tsx +163 -0
  112. package/src/tui/context/directory.ts +15 -0
  113. package/src/tui/context/editor-zed.ts +283 -0
  114. package/src/tui/context/editor.ts +468 -0
  115. package/src/tui/context/event-apx.ts +22 -0
  116. package/src/tui/context/event.ts +6 -0
  117. package/src/tui/context/exit.tsx +60 -0
  118. package/src/tui/context/helper.tsx +25 -0
  119. package/src/tui/context/kv.tsx +81 -0
  120. package/src/tui/context/local.tsx +608 -0
  121. package/src/tui/context/path-format.tsx +39 -0
  122. package/src/tui/context/project-apx.tsx +48 -0
  123. package/src/tui/context/project.tsx +7 -0
  124. package/src/tui/context/prompt.tsx +18 -0
  125. package/src/tui/context/route.tsx +52 -0
  126. package/src/tui/context/sdk-apx.tsx +185 -0
  127. package/src/tui/context/sdk.tsx +6 -0
  128. package/src/tui/context/sync-apx.tsx +178 -0
  129. package/src/tui/context/sync-v2.tsx +16 -0
  130. package/src/tui/context/sync.tsx +118 -0
  131. package/src/tui/context/theme/aura.json +69 -0
  132. package/src/tui/context/theme/ayu.json +80 -0
  133. package/src/tui/context/theme/carbonfox.json +248 -0
  134. package/src/tui/context/theme/catppuccin-frappe.json +230 -0
  135. package/src/tui/context/theme/catppuccin-macchiato.json +230 -0
  136. package/src/tui/context/theme/catppuccin.json +112 -0
  137. package/src/tui/context/theme/cobalt2.json +225 -0
  138. package/src/tui/context/theme/cursor.json +249 -0
  139. package/src/tui/context/theme/dracula.json +219 -0
  140. package/src/tui/context/theme/everforest.json +241 -0
  141. package/src/tui/context/theme/flexoki.json +237 -0
  142. package/src/tui/context/theme/github.json +233 -0
  143. package/src/tui/context/theme/gruvbox.json +242 -0
  144. package/src/tui/context/theme/kanagawa.json +77 -0
  145. package/src/tui/context/theme/lucent-orng.json +234 -0
  146. package/src/tui/context/theme/material.json +235 -0
  147. package/src/tui/context/theme/matrix.json +77 -0
  148. package/src/tui/context/theme/mercury.json +252 -0
  149. package/src/tui/context/theme/monokai.json +221 -0
  150. package/src/tui/context/theme/nightowl.json +221 -0
  151. package/src/tui/context/theme/nord.json +223 -0
  152. package/src/tui/context/theme/one-dark.json +84 -0
  153. package/src/tui/context/theme/opencode.json +245 -0
  154. package/src/tui/context/theme/orng.json +249 -0
  155. package/src/tui/context/theme/osaka-jade.json +93 -0
  156. package/src/tui/context/theme/palenight.json +222 -0
  157. package/src/tui/context/theme/rosepine.json +234 -0
  158. package/src/tui/context/theme/solarized.json +223 -0
  159. package/src/tui/context/theme/synthwave84.json +226 -0
  160. package/src/tui/context/theme/tokyonight.json +243 -0
  161. package/src/tui/context/theme/vercel.json +245 -0
  162. package/src/tui/context/theme/vesper.json +218 -0
  163. package/src/tui/context/theme/zenburn.json +223 -0
  164. package/src/tui/context/theme.tsx +1247 -0
  165. package/src/tui/context/tui-config.tsx +9 -0
  166. package/src/tui/event.ts +16 -0
  167. package/src/tui/feature-plugins/home/footer.tsx +94 -0
  168. package/src/tui/feature-plugins/home/tips-view.tsx +166 -0
  169. package/src/tui/feature-plugins/home/tips.tsx +59 -0
  170. package/src/tui/feature-plugins/sidebar/context.tsx +65 -0
  171. package/src/tui/feature-plugins/sidebar/files.tsx +63 -0
  172. package/src/tui/feature-plugins/sidebar/footer.tsx +94 -0
  173. package/src/tui/feature-plugins/sidebar/lsp.tsx +65 -0
  174. package/src/tui/feature-plugins/sidebar/mcp.tsx +97 -0
  175. package/src/tui/feature-plugins/sidebar/todo.tsx +49 -0
  176. package/src/tui/feature-plugins/system/plugins.tsx +269 -0
  177. package/src/tui/feature-plugins/system/session-v2.tsx +1143 -0
  178. package/src/tui/feature-plugins/system/which-key.tsx +608 -0
  179. package/src/tui/keymap.tsx +166 -0
  180. package/src/tui/layer.ts +6 -0
  181. package/src/tui/plugin/api.tsx +381 -0
  182. package/src/tui/plugin/command-shim.ts +109 -0
  183. package/src/tui/plugin/internal.ts +33 -0
  184. package/src/tui/plugin/runtime.ts +1069 -0
  185. package/src/tui/plugin/slots.tsx +60 -0
  186. package/src/tui/routes/home.tsx +96 -0
  187. package/src/tui/routes/session/dialog-fork-from-timeline.tsx +76 -0
  188. package/src/tui/routes/session/dialog-message.tsx +108 -0
  189. package/src/tui/routes/session/dialog-subagent.tsx +26 -0
  190. package/src/tui/routes/session/dialog-timeline.tsx +47 -0
  191. package/src/tui/routes/session/footer.tsx +91 -0
  192. package/src/tui/routes/session/index.tsx +188 -0
  193. package/src/tui/routes/session/permission.tsx +722 -0
  194. package/src/tui/routes/session/question.tsx +490 -0
  195. package/src/tui/routes/session/sidebar.tsx +102 -0
  196. package/src/tui/routes/session/subagent-footer.tsx +133 -0
  197. package/src/tui/run.ts +84 -0
  198. package/src/tui/thread.ts +261 -0
  199. package/src/tui/tsconfig.json +40 -0
  200. package/src/tui/ui/dialog-alert.tsx +66 -0
  201. package/src/tui/ui/dialog-confirm.tsx +108 -0
  202. package/src/tui/ui/dialog-export-options.tsx +217 -0
  203. package/src/tui/ui/dialog-help.tsx +40 -0
  204. package/src/tui/ui/dialog-prompt.tsx +101 -0
  205. package/src/tui/ui/dialog-select.tsx +553 -0
  206. package/src/tui/ui/dialog.tsx +211 -0
  207. package/src/tui/ui/link.tsx +34 -0
  208. package/src/tui/ui/spinner.ts +368 -0
  209. package/src/tui/ui/toast.tsx +111 -0
  210. package/src/tui/util/clipboard.ts +217 -0
  211. package/src/tui/util/editor.ts +37 -0
  212. package/src/tui/util/model.ts +23 -0
  213. package/src/tui/util/provider-origin.ts +7 -0
  214. package/src/tui/util/revert-diff.ts +18 -0
  215. package/src/tui/util/scroll.ts +25 -0
  216. package/src/tui/util/selection.ts +65 -0
  217. package/src/tui/util/signal.ts +41 -0
  218. package/src/tui/util/sound.ts +156 -0
  219. package/src/tui/util/transcript.ts +112 -0
  220. package/src/tui/validate-session.ts +29 -0
  221. package/src/tui/win32.ts +130 -0
  222. package/src/tui/worker.ts +104 -0
@@ -0,0 +1,97 @@
1
+ import type { TuiPlugin, TuiPluginApi } from "@opencode-ai/plugin/tui"
2
+ import type { InternalTuiPlugin } from "../../plugin/internal"
3
+ import { createMemo, For, Match, Show, Switch, createSignal } from "solid-js"
4
+
5
+ const id = "internal:sidebar-mcp"
6
+
7
+ function View(props: { api: TuiPluginApi }) {
8
+ const [open, setOpen] = createSignal(true)
9
+ const theme = () => props.api.theme.current
10
+ const list = createMemo(() => props.api.state.mcp())
11
+ const on = createMemo(() => list().filter((item) => item.status === "connected").length)
12
+ const bad = createMemo(
13
+ () =>
14
+ list().filter(
15
+ (item) =>
16
+ item.status === "failed" || item.status === "needs_auth" || item.status === "needs_client_registration",
17
+ ).length,
18
+ )
19
+
20
+ const dot = (status: string) => {
21
+ if (status === "connected") return theme().success
22
+ if (status === "failed") return theme().error
23
+ if (status === "disabled") return theme().textMuted
24
+ if (status === "needs_auth") return theme().warning
25
+ if (status === "needs_client_registration") return theme().error
26
+ return theme().textMuted
27
+ }
28
+
29
+ return (
30
+ <Show when={list().length > 0}>
31
+ <box>
32
+ <box flexDirection="row" gap={1} onMouseDown={() => list().length > 2 && setOpen((x) => !x)}>
33
+ <Show when={list().length > 2}>
34
+ <text fg={theme().text}>{open() ? "▼" : "▶"}</text>
35
+ </Show>
36
+ <text fg={theme().text}>
37
+ <b>MCP</b>
38
+ <Show when={!open()}>
39
+ <span style={{ fg: theme().textMuted }}>
40
+ {" "}
41
+ ({on()} active{bad() > 0 ? `, ${bad()} error${bad() > 1 ? "s" : ""}` : ""})
42
+ </span>
43
+ </Show>
44
+ </text>
45
+ </box>
46
+ <Show when={list().length <= 2 || open()}>
47
+ <For each={list()}>
48
+ {(item) => (
49
+ <box flexDirection="row" gap={1}>
50
+ <text
51
+ flexShrink={0}
52
+ style={{
53
+ fg: dot(item.status),
54
+ }}
55
+ >
56
+
57
+ </text>
58
+ <text fg={theme().text} wrapMode="word">
59
+ {item.name}{" "}
60
+ <span style={{ fg: theme().textMuted }}>
61
+ <Switch fallback={item.status}>
62
+ <Match when={item.status === "connected"}>Connected</Match>
63
+ <Match when={item.status === "failed"}>
64
+ <i>{item.error}</i>
65
+ </Match>
66
+ <Match when={item.status === "disabled"}>Disabled</Match>
67
+ <Match when={item.status === "needs_auth"}>Needs auth</Match>
68
+ <Match when={item.status === "needs_client_registration"}>Needs client ID</Match>
69
+ </Switch>
70
+ </span>
71
+ </text>
72
+ </box>
73
+ )}
74
+ </For>
75
+ </Show>
76
+ </box>
77
+ </Show>
78
+ )
79
+ }
80
+
81
+ const tui: TuiPlugin = async (api) => {
82
+ api.slots.register({
83
+ order: 200,
84
+ slots: {
85
+ sidebar_content() {
86
+ return <View api={api} />
87
+ },
88
+ },
89
+ })
90
+ }
91
+
92
+ const plugin: InternalTuiPlugin = {
93
+ id,
94
+ tui,
95
+ }
96
+
97
+ export default plugin
@@ -0,0 +1,49 @@
1
+ import type { TuiPlugin, TuiPluginApi } from "@opencode-ai/plugin/tui"
2
+ import type { InternalTuiPlugin } from "../../plugin/internal"
3
+ import { createMemo, For, Show, createSignal } from "solid-js"
4
+ import { TodoItem } from "../../component/todo-item"
5
+
6
+ const id = "internal:sidebar-todo"
7
+
8
+ function View(props: { api: TuiPluginApi; session_id: string }) {
9
+ const [open, setOpen] = createSignal(true)
10
+ const theme = () => props.api.theme.current
11
+ const list = createMemo(() => props.api.state.session.todo(props.session_id))
12
+ const show = createMemo(() => list().length > 0 && list().some((item) => item.status !== "completed"))
13
+
14
+ return (
15
+ <Show when={show()}>
16
+ <box>
17
+ <box flexDirection="row" gap={1} onMouseDown={() => list().length > 2 && setOpen((x) => !x)}>
18
+ <Show when={list().length > 2}>
19
+ <text fg={theme().text}>{open() ? "▼" : "▶"}</text>
20
+ </Show>
21
+ <text fg={theme().text}>
22
+ <b>Todo</b>
23
+ </text>
24
+ </box>
25
+ <Show when={list().length <= 2 || open()}>
26
+ <For each={list()}>{(item) => <TodoItem status={item.status} content={item.content} />}</For>
27
+ </Show>
28
+ </box>
29
+ </Show>
30
+ )
31
+ }
32
+
33
+ const tui: TuiPlugin = async (api) => {
34
+ api.slots.register({
35
+ order: 400,
36
+ slots: {
37
+ sidebar_content(_ctx, props) {
38
+ return <View api={api} session_id={props.session_id} />
39
+ },
40
+ },
41
+ })
42
+ }
43
+
44
+ const plugin: InternalTuiPlugin = {
45
+ id,
46
+ tui,
47
+ }
48
+
49
+ export default plugin
@@ -0,0 +1,269 @@
1
+ import type { TuiPlugin, TuiPluginApi, TuiPluginStatus } from "@opencode-ai/plugin/tui"
2
+ import type { InternalTuiPlugin } from "../../plugin/internal"
3
+ import { useTerminalDimensions } from "@opentui/solid"
4
+ import { fileURLToPath } from "url"
5
+ import { DialogSelect, type DialogSelectOption } from "@tui/ui/dialog-select"
6
+ import { Show, createEffect, createMemo, createSignal } from "solid-js"
7
+ import { useBindings } from "../../keymap"
8
+
9
+ const id = "internal:plugin-manager"
10
+
11
+ function state(api: TuiPluginApi, item: TuiPluginStatus) {
12
+ if (!item.enabled) {
13
+ return <span style={{ fg: api.theme.current.textMuted }}>disabled</span>
14
+ }
15
+
16
+ return (
17
+ <span style={{ fg: item.active ? api.theme.current.success : api.theme.current.error }}>
18
+ {item.active ? "active" : "inactive"}
19
+ </span>
20
+ )
21
+ }
22
+
23
+ function source(spec: string) {
24
+ if (!spec.startsWith("file://")) return
25
+ return fileURLToPath(spec)
26
+ }
27
+
28
+ function meta(item: TuiPluginStatus, width: number) {
29
+ if (item.source === "internal") {
30
+ if (width >= 120) return "Built-in plugin"
31
+ return "Built-in"
32
+ }
33
+ const next = source(item.spec)
34
+ if (next) return next
35
+ return item.spec
36
+ }
37
+
38
+ function Install(props: { api: TuiPluginApi }) {
39
+ const [global, setGlobal] = createSignal(false)
40
+ const [busy, setBusy] = createSignal(false)
41
+
42
+ useBindings(() => ({
43
+ enabled: !busy(),
44
+ bindings: [{ key: "tab", desc: "Toggle install scope", group: "Plugins", cmd: () => setGlobal((value) => !value) }],
45
+ }))
46
+
47
+ return (
48
+ <props.api.ui.DialogPrompt
49
+ title="Install plugin"
50
+ placeholder="npm package name"
51
+ busy={busy()}
52
+ busyText="Installing plugin..."
53
+ description={() => (
54
+ <box flexDirection="row" gap={1}>
55
+ <text fg={props.api.theme.current.textMuted}>scope:</text>
56
+ <text fg={busy() ? props.api.theme.current.textMuted : props.api.theme.current.text}>
57
+ {global() ? "global" : "local"}
58
+ </text>
59
+ <Show when={!busy()}>
60
+ <text fg={props.api.theme.current.textMuted}>(tab toggle)</text>
61
+ </Show>
62
+ </box>
63
+ )}
64
+ onConfirm={(raw) => {
65
+ if (busy()) return
66
+ const mod = raw.trim()
67
+ if (!mod) {
68
+ props.api.ui.toast({
69
+ variant: "error",
70
+ message: "Plugin package name is required",
71
+ })
72
+ return
73
+ }
74
+
75
+ setBusy(true)
76
+ void props.api.plugins
77
+ .install(mod, { global: global() })
78
+ .then((out) => {
79
+ if (!out.ok) {
80
+ props.api.ui.toast({
81
+ variant: "error",
82
+ message: out.message,
83
+ })
84
+ if (out.missing) {
85
+ props.api.ui.toast({
86
+ variant: "info",
87
+ message: "Check npm registry/auth settings and try again.",
88
+ })
89
+ }
90
+ show(props.api)
91
+ return
92
+ }
93
+
94
+ props.api.ui.toast({
95
+ variant: "success",
96
+ message: `Installed ${mod} (${global() ? "global" : "local"}: ${out.dir})`,
97
+ })
98
+ if (!out.tui) {
99
+ props.api.ui.toast({
100
+ variant: "info",
101
+ message: "Package has no TUI target to load in this app.",
102
+ })
103
+ show(props.api)
104
+ return
105
+ }
106
+
107
+ return props.api.plugins.add(mod).then((ok) => {
108
+ if (!ok) {
109
+ props.api.ui.toast({
110
+ variant: "warning",
111
+ message: "Installed plugin, but runtime load failed. See console/logs; restart TUI to retry.",
112
+ })
113
+ show(props.api)
114
+ return
115
+ }
116
+
117
+ props.api.ui.toast({
118
+ variant: "success",
119
+ message: `Loaded ${mod} in current session.`,
120
+ })
121
+ show(props.api)
122
+ })
123
+ })
124
+ .finally(() => {
125
+ setBusy(false)
126
+ })
127
+ }}
128
+ onCancel={() => {
129
+ show(props.api)
130
+ }}
131
+ />
132
+ )
133
+ }
134
+
135
+ function row(api: TuiPluginApi, item: TuiPluginStatus, width: number): DialogSelectOption<string> {
136
+ return {
137
+ title: item.id,
138
+ value: item.id,
139
+ category: item.source === "internal" ? "Internal" : "External",
140
+ description: meta(item, width),
141
+ footer: state(api, item),
142
+ disabled: item.id === id,
143
+ }
144
+ }
145
+
146
+ function showInstall(api: TuiPluginApi) {
147
+ api.ui.dialog.replace(() => <Install api={api} />)
148
+ }
149
+
150
+ function View(props: { api: TuiPluginApi }) {
151
+ const size = useTerminalDimensions()
152
+ const [list, setList] = createSignal(props.api.plugins.list())
153
+ const [cur, setCur] = createSignal<string | undefined>()
154
+ const [lock, setLock] = createSignal(false)
155
+
156
+ createEffect(() => {
157
+ const width = size().width
158
+ if (width >= 128) {
159
+ props.api.ui.dialog.setSize("xlarge")
160
+ return
161
+ }
162
+ if (width >= 96) {
163
+ props.api.ui.dialog.setSize("large")
164
+ return
165
+ }
166
+ props.api.ui.dialog.setSize("medium")
167
+ })
168
+
169
+ const rows = createMemo(() =>
170
+ [...list()]
171
+ .sort((a, b) => {
172
+ const x = a.source === "internal" ? 1 : 0
173
+ const y = b.source === "internal" ? 1 : 0
174
+ if (x !== y) return x - y
175
+ return a.id.localeCompare(b.id)
176
+ })
177
+ .map((item) => row(props.api, item, size().width)),
178
+ )
179
+
180
+ const flip = (x: string) => {
181
+ if (lock()) return
182
+ const item = list().find((entry) => entry.id === x)
183
+ if (!item) return
184
+ setLock(true)
185
+ const task = item.active ? props.api.plugins.deactivate(x) : props.api.plugins.activate(x)
186
+ void task
187
+ .then((ok) => {
188
+ if (!ok) {
189
+ props.api.ui.toast({
190
+ variant: "error",
191
+ message: `Failed to update plugin ${item.id}`,
192
+ })
193
+ }
194
+ setList(props.api.plugins.list())
195
+ })
196
+ .finally(() => {
197
+ setLock(false)
198
+ })
199
+ }
200
+
201
+ return (
202
+ <DialogSelect
203
+ title="Plugins"
204
+ options={rows()}
205
+ current={cur()}
206
+ onMove={(item) => setCur(item.value)}
207
+ actions={[
208
+ {
209
+ title: "toggle",
210
+ command: "plugins.toggle",
211
+ disabled: lock(),
212
+ onTrigger: (item) => {
213
+ setCur(item.value)
214
+ flip(item.value)
215
+ },
216
+ },
217
+ {
218
+ title: "install",
219
+ command: "dialog.plugins.install",
220
+ disabled: lock(),
221
+ onTrigger: () => {
222
+ showInstall(props.api)
223
+ },
224
+ },
225
+ ]}
226
+ onSelect={(item) => {
227
+ setCur(item.value)
228
+ flip(item.value)
229
+ }}
230
+ />
231
+ )
232
+ }
233
+
234
+ function show(api: TuiPluginApi) {
235
+ api.ui.dialog.replace(() => <View api={api} />)
236
+ }
237
+
238
+ const tui: TuiPlugin = async (api) => {
239
+ api.keymap.registerLayer({
240
+ commands: [
241
+ {
242
+ name: "plugins.list",
243
+ title: "Plugins",
244
+ category: "System",
245
+ namespace: "palette",
246
+ run() {
247
+ show(api)
248
+ },
249
+ },
250
+ {
251
+ name: "plugins.install",
252
+ title: "Install plugin",
253
+ category: "System",
254
+ namespace: "palette",
255
+ run() {
256
+ showInstall(api)
257
+ },
258
+ },
259
+ ],
260
+ bindings: api.tuiConfig.keybinds.gather("plugins.palette", ["plugins.list", "plugins.install"]),
261
+ })
262
+ }
263
+
264
+ const plugin: InternalTuiPlugin = {
265
+ id,
266
+ tui,
267
+ }
268
+
269
+ export default plugin