@eum-agent/session-todo 0.0.0-stage → 1.0.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/index.js ADDED
@@ -0,0 +1,306 @@
1
+ import { existsSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+ import { z } from "zod";
4
+ //#region src/tool-names.ts
5
+ /** Canonical names shared by tool registration and browser presentation. */
6
+ const TOOL_NAMES = ["todo_write"];
7
+ //#endregion
8
+ //#region src/guidance.ts
9
+ const GUIDANCE = {
10
+ title: "Task list",
11
+ entries: [{
12
+ tools: ["todo_write"],
13
+ text: "`todo_write` keeps your task list for work with several distinct steps: write it when you start, mark each item done as soon as it is, keep exactly one in progress, and skip it for a task of one or two steps."
14
+ }]
15
+ };
16
+ //#endregion
17
+ //#region src/todo/render.ts
18
+ /** The label the paragraph opens with. English, like every other injected
19
+ * line; the item text is whatever language the model wrote. */
20
+ const HEADING = "Current todo list:";
21
+ /** One character per status, inside a GFM checkbox. `>` for in-progress is
22
+ * the one that is not standard GFM, and it is the one that matters: it is
23
+ * what makes the list answer "where am I" rather than "how many are left". */
24
+ const MARKS = {
25
+ completed: "x",
26
+ "in-progress": ">",
27
+ pending: " "
28
+ };
29
+ /**
30
+ * The paragraph, or nothing at all.
31
+ *
32
+ * An empty list contributes **zero characters** — not a heading with nothing
33
+ * under it and not a sentence saying the list is empty. A session that never
34
+ * wrote one is then byte-identical to a request assembled with this member
35
+ * absent.
36
+ *
37
+ * It states rather than instructs: "the list is this" and never "do this".
38
+ * The same text reaches the model every step, and written as an instruction
39
+ * it would be a nag repeated once per step, competing with the `system` slot
40
+ * for the job of saying what to do.
41
+ */
42
+ function renderTodoList(items) {
43
+ if (items.length === 0) return void 0;
44
+ const lines = items.map((item) => `- [${MARKS[item.status]}] ${item.content}`);
45
+ return [HEADING, ...lines].join("\n");
46
+ }
47
+ /**
48
+ * The one line the tool answers with: how many were recorded and how they
49
+ * break down, and **not one item of text**.
50
+ *
51
+ * The transcript is history, and a copy of a "right now" fact taken at
52
+ * writing time is a record that contradicts the one at the end of the next
53
+ * request — with nothing to tell the model which is current. So the only
54
+ * authoritative copy stays in `volatile`.
55
+ *
56
+ * Counts are stated in a fixed order and a zero is left out: "1 in-progress,
57
+ * 3 pending" says more than the same line with ", 0 completed" on the end.
58
+ */
59
+ function describeTodoList(items) {
60
+ if (items.length === 0) return "cleared the todo list";
61
+ const counted = [
62
+ "in-progress",
63
+ "pending",
64
+ "completed"
65
+ ].map((status) => ({
66
+ status,
67
+ count: items.filter((item) => item.status === status).length
68
+ })).filter(({ count }) => count > 0).map(({ status, count }) => `${count} ${status}`);
69
+ return `recorded ${items.length} todo${items.length === 1 ? "" : "s"}: ${counted.join(", ")}`;
70
+ }
71
+ //#endregion
72
+ //#region src/todo/contribute.ts
73
+ /** Sorted within the slot by `id`, so `time` comes before `todos` — a
74
+ * lexicographic result rather than a rule written somewhere else. */
75
+ const CONTRIBUTOR_ID = "todos";
76
+ function todosContributor(store) {
77
+ return {
78
+ slot: "volatile",
79
+ id: CONTRIBUTOR_ID,
80
+ contribute(view) {
81
+ const text = renderTodoList(store.list(view.state.sessionId));
82
+ return Promise.resolve(text === void 0 ? {} : { volatile: [text] });
83
+ }
84
+ };
85
+ }
86
+ /**
87
+ * Three values, not two and not four.
88
+ *
89
+ * `in-progress` is the reason this list exists: re-injected every step, it
90
+ * has to answer "where am I", and done/not-done makes a ten-item list read
91
+ * as "six left" rather than "I am on the fifth". There is no `cancelled`
92
+ * (whole-list replacement expresses that by not writing the line) and no
93
+ * `blocked` (it would need a reference to what blocks it, which is item
94
+ * dependencies — out of scope).
95
+ */
96
+ const TodoStatus = z.enum([
97
+ "pending",
98
+ "in-progress",
99
+ "completed"
100
+ ]);
101
+ /** The wire and storage shape: what `listTodos` answers with, what the frame
102
+ * carries, and what a row's JSON holds. */
103
+ const TodoItem = z.strictObject({
104
+ content: z.string(),
105
+ status: TodoStatus
106
+ });
107
+ /** The same shape with the sentences the model reads. It is declared apart
108
+ * from `TodoItem` because a `describe` is for the model and a wire shape is
109
+ * for a client — they happen to agree on the fields and not on what has to
110
+ * be said about them. */
111
+ const TodoItemInput = z.strictObject({
112
+ content: z.string().min(1).refine((text) => [...text].length <= 200, { message: `at most 200 characters` }).describe(`One task, in a few words. Not a paragraph. At most 200 characters.`),
113
+ status: TodoStatus.describe("pending: not started. in-progress: being worked on right now. completed: done.")
114
+ });
115
+ //#endregion
116
+ //#region src/todo/store.ts
117
+ /** The local half of the table name. `tableName` turns it into
118
+ * `plugin__eum_agent_session_todo__todos`; the prefix is the package's and cannot
119
+ * be chosen here, which is what keeps the core's own tables out of reach of
120
+ * this file's DDL. */
121
+ const LOCAL_TABLE = "todos";
122
+ function createTableSql(table) {
123
+ return `CREATE TABLE IF NOT EXISTS ${table} (
124
+ session_id TEXT NOT NULL,
125
+ items TEXT NOT NULL,
126
+ updated_at INTEGER NOT NULL,
127
+ PRIMARY KEY (session_id)
128
+ ) STRICT`;
129
+ }
130
+ function selectSql(table) {
131
+ return `SELECT items FROM ${table} WHERE session_id = ?`;
132
+ }
133
+ function upsertSql(table) {
134
+ return `INSERT INTO ${table} (session_id, items, updated_at) VALUES (?, ?, ?)
135
+ ON CONFLICT (session_id) DO UPDATE SET items = excluded.items, updated_at = excluded.updated_at`;
136
+ }
137
+ /**
138
+ * Whatever that column holds, read as a list — or as an empty one.
139
+ *
140
+ * Storage does no schema checking of its own: validation happened before the
141
+ * write, in the tool's zod. So text that was hand-edited, or written by
142
+ * another version, degrades here rather than throwing: **a panel that will
143
+ * not open is worse than a list that reads as empty**, and this list is
144
+ * derived state rather than a source of truth. The degradation leaves a line
145
+ * in the log, because an emptied list and a genuinely empty one look
146
+ * identical everywhere else.
147
+ */
148
+ function itemsFrom(raw) {
149
+ if (typeof raw !== "string") return void 0;
150
+ let parsed;
151
+ try {
152
+ parsed = JSON.parse(raw);
153
+ } catch {
154
+ return;
155
+ }
156
+ const read = TodoItem.array().safeParse(parsed);
157
+ return read.success ? read.data : void 0;
158
+ }
159
+ function openTodoStore(ctx) {
160
+ const storage = ctx.storage.open();
161
+ const table = storage.tableName(LOCAL_TABLE);
162
+ storage.db.exec(createTableSql(table));
163
+ return {
164
+ list(sessionId) {
165
+ const row = storage.db.prepare(selectSql(table)).get(sessionId);
166
+ if (row === void 0) return [];
167
+ const items = itemsFrom(row.items);
168
+ if (items !== void 0) return items;
169
+ ctx.log.error(`todo list for session ${sessionId} could not be read; treating it as empty`);
170
+ return [];
171
+ },
172
+ replace(sessionId, items) {
173
+ storage.db.prepare(upsertSql(table)).run(sessionId, JSON.stringify(items), Date.now());
174
+ return items;
175
+ }
176
+ };
177
+ }
178
+ //#endregion
179
+ //#region src/todo/write.ts
180
+ const WriteTodosInput = z.strictObject({ todos: z.array(TodoItemInput).max(20).describe("The whole list, in reading order. It replaces whatever was recorded before.") });
181
+ /**
182
+ * Everything the model is told about this tool.
183
+ *
184
+ * The description is the only guidance there is — this product has no
185
+ * per-session tool policy and no way to require a call — so what would
186
+ * otherwise be documentation is written here instead.
187
+ */
188
+ const DESCRIPTION = `Record the plan for a task that spans several steps, and keep it current. Write the list down before you start, and rewrite it the moment a step is done. It is a whole-list replacement: hand over the complete list every time, and any item you leave out is gone — there is no way to edit one item. Keep at most one item in-progress at a time. The list you record is shown to you again at the end of every later request, so do not copy it into your reply. At most 20 items, each at most 200 characters.`;
189
+ /** Told to the model when the store itself refuses. Fixed wording rather
190
+ * than the raw exception: `tool-call.ts` hands `error.message` straight to
191
+ * the model, and SQLite's text can carry the database file's path. */
192
+ const WRITE_FAILED = "todo store write failed";
193
+ function writeTodosTool(store, announce) {
194
+ return {
195
+ name: "todo_write",
196
+ description: DESCRIPTION,
197
+ inputSchema: WriteTodosInput,
198
+ async execute(input, ctx) {
199
+ let stored;
200
+ try {
201
+ stored = store.replace(ctx.sessionId, input.todos);
202
+ } catch (error) {
203
+ return {
204
+ content: `${WRITE_FAILED}: ${error instanceof Error ? error.message : String(error)}`,
205
+ isError: true
206
+ };
207
+ }
208
+ announce(ctx.sessionId, stored);
209
+ return { content: describeTodoList(stored) };
210
+ }
211
+ };
212
+ }
213
+ //#endregion
214
+ //#region src/todo/index.ts
215
+ /** The session whose list is wanted. `ClientCallContext` carries no session
216
+ * — a call arrives from a connection, and a connection is not in a session
217
+ * — so the caller names it; in the browser that is the `sessionId` the host
218
+ * hands the panel. */
219
+ const ListTodosParams = z.strictObject({ sessionId: z.string().min(1) });
220
+ /** The answer carries the session back although the caller just sent it: by
221
+ * the time an async call returns, the panel may be showing another session,
222
+ * and comparing this is its only way to know whether the answer is still
223
+ * the one it wants. */
224
+ const ListTodosResult = z.strictObject({
225
+ sessionId: z.string(),
226
+ todos: z.array(TodoItem)
227
+ });
228
+ /** The frame carries the whole list rather than a signal to re-read. It is
229
+ * delivered to the connections watching that one session, so the content
230
+ * does not leak to a connection looking at something else, and its `seq`
231
+ * comes from the session's own stream — which is what makes "the later one
232
+ * is the newer one" free. */
233
+ const TodosChangedPayload = z.strictObject({ todos: z.array(TodoItem) });
234
+ const LIST_TODOS_DESCRIPTION = "The todo list recorded for one session, in the order the model wrote it. A session that has never recorded one answers with an empty list.";
235
+ /** Registers this member's tool, contributor, method and frame over one
236
+ * store, all of them owned by the plugin `ctx` belongs to. The package's
237
+ * `apply` calls this exactly where `todo_write` is on. */
238
+ function registerTodoTools(ctx, register) {
239
+ const store = openTodoStore(ctx);
240
+ const changed = ctx.client.registerFrame({
241
+ name: "todosChanged",
242
+ delivery: "session",
243
+ payload: TodosChangedPayload
244
+ });
245
+ register(writeTodosTool(store, (sessionId, todos) => {
246
+ changed.emit(sessionId, { todos: [...todos] });
247
+ }));
248
+ ctx.context.contribute(todosContributor(store));
249
+ ctx.client.registerMethod({
250
+ name: "listTodos",
251
+ description: LIST_TODOS_DESCRIPTION,
252
+ params: ListTodosParams,
253
+ result: ListTodosResult,
254
+ handle({ sessionId }) {
255
+ return {
256
+ sessionId,
257
+ todos: [...store.list(sessionId)]
258
+ };
259
+ }
260
+ });
261
+ }
262
+ //#endregion
263
+ //#region src/index.ts
264
+ /**
265
+ * `@eum-agent/session-todo` — the session's task list, as one plugin: the `todo_write`
266
+ * tool, the `todos` volatile contributor that shows the list to the model on
267
+ * every step, the `listTodos` method and `todosChanged` frame the page reads
268
+ * it through, and the browser module that draws it beside the run.
269
+ *
270
+ * The member lives in `src/todo/`; this file is the only plugin, and it is
271
+ * what a person's `config.json` names, what `plugin list` prints, and what the
272
+ * loader imports.
273
+ *
274
+ * `@eum-agent/plugin` is the only workspace package any file here imports,
275
+ * and only its types: everything reached at runtime arrived through `ctx`.
276
+ */
277
+ /**
278
+ * This plugin's slice of `config.json`. Strict and enumerated: a misspelled
279
+ * tool name is a load failure naming the field, not a line that quietly does
280
+ * nothing.
281
+ */
282
+ const TodoConfig = z.strictObject({ disabled: z.array(z.enum(TOOL_NAMES)).default([]) }).default({ disabled: [] });
283
+ /**
284
+ * Where this package's browser module is, or nothing when it has not been
285
+ * built. Computed in this entry because `new URL(…, import.meta.url)` is
286
+ * carried into the bundle verbatim, and this file is one directory below the
287
+ * package root in source and in the output alike.
288
+ */
289
+ function browserModule() {
290
+ const path = fileURLToPath(new URL("../ui/ui.js", import.meta.url));
291
+ return existsSync(path) ? path : void 0;
292
+ }
293
+ const todoPlugin = {
294
+ name: "@eum-agent/session-todo",
295
+ configSchema: TodoConfig,
296
+ apply(ctx, config) {
297
+ if (config.disabled.includes("todo_write")) return;
298
+ const register = (tool) => ctx.tools.register(tool);
299
+ registerTodoTools(ctx, register);
300
+ ctx.tools.guide(GUIDANCE);
301
+ const uiModule = browserModule();
302
+ if (uiModule !== void 0) ctx.client.registerUi({ module: uiModule });
303
+ }
304
+ };
305
+ //#endregion
306
+ export { TOOL_NAMES, TodoConfig, todoPlugin as default, todoPlugin, registerTodoTools };
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@eum-agent/session-todo",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "displayName": {
4
+ "en-US": "Session Todo List",
5
+ "zh-CN": "会话待办清单"
6
+ },
7
+ "version": "1.0.0",
8
+ "type": "module",
9
+ "description": "Todo items and progress maintained within a conversation",
10
+ "license": "MIT",
11
+ "exports": {
12
+ ".": {
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "ui"
19
+ ],
20
+ "dependencies": {
21
+ "zod": "^4.4.3"
22
+ },
23
+ "devDependencies": {
24
+ "@eum-agent/container": "1.0.0",
25
+ "@eum-agent/kernel": "1.0.0",
26
+ "@eum-agent/plugin": "1.0.0",
27
+ "@types/react": "^19.2.18",
28
+ "@types/react-dom": "^19.2.5",
29
+ "react": "^19.2.0",
30
+ "react-dom": "^19.2.0",
31
+ "vite": "^8.2.2"
32
+ },
33
+ "yaoguang": {
34
+ "description": {
35
+ "en-US": "Todo items and progress maintained within a conversation",
36
+ "zh-CN": "在对话中维护待办事项与任务进度"
37
+ },
38
+ "dependencies": {},
39
+ "kind": "extension",
40
+ "foundationDependencies": {
41
+ "@eum-agent/infra-local": "1.0.0",
42
+ "@eum-agent/storage-sqlite": "1.0.0"
43
+ }
44
+ },
45
+ "scripts": {
46
+ "build": "tsdown && vite build",
47
+ "test": "vitest run",
48
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.ui.json"
49
+ }
6
50
  }
package/ui/ui.js ADDED
@@ -0,0 +1,305 @@
1
+ import { LineState, failureText } from "@eum-agent/host/framework";
2
+ import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from "react";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ //#region src/tool-names.ts
5
+ /** Canonical names shared by tool registration and browser presentation. */
6
+ var TOOL_NAMES = ["todo_write"];
7
+ //#endregion
8
+ //#region src/ui/metadata.ts
9
+ var CATALOGUES$1 = {
10
+ "en-US": {
11
+ section: "Built-in plugins",
12
+ group: "To-dos",
13
+ todo_write: "Update tasks"
14
+ },
15
+ "zh-CN": {
16
+ section: "内置插件",
17
+ group: "待办",
18
+ todo_write: "更新待办"
19
+ }
20
+ };
21
+ var names = new Set(TOOL_NAMES);
22
+ /** Registers presentation facets with the same activation lifetime as the tools. */
23
+ function registerMetadata(ctx) {
24
+ ctx.i18n.register(CATALOGUES$1, "en-US");
25
+ ctx.i18n.contribute(Object.fromEntries(Object.entries(CATALOGUES$1).map(([language, catalogue]) => [language, Object.fromEntries([...names].map((tool) => [`transcript.actions.${tool}`, catalogue[tool] ?? tool]))])), "en-US");
26
+ ctx.slots.register("chat.tool.presentation", {
27
+ id: "tool-metadata",
28
+ describe: ({ call }) => {
29
+ if (!names.has(call.name)) return void 0;
30
+ const input = call.input !== null && typeof call.input === "object" ? call.input : {};
31
+ const summary = [
32
+ "path",
33
+ "url",
34
+ "query",
35
+ "command",
36
+ "skill",
37
+ "id",
38
+ "name",
39
+ "task",
40
+ "prompt"
41
+ ].flatMap((key) => typeof input[key] === "string" ? [input[key]] : []).slice(0, 2).join(" · ").replace(/\s+/g, " ").slice(0, 240);
42
+ return {
43
+ label: names.has(call.name) ? ctx.i18n.t(call.name) : call.name,
44
+ icon: "hammer",
45
+ summary
46
+ };
47
+ }
48
+ });
49
+ ctx.slots.register("shell.tools.group", {
50
+ id: "tool-groups",
51
+ describe: (tool) => {
52
+ if (tool.plugin !== ctx.plugin) return void 0;
53
+ return {
54
+ key: `plugin:${ctx.plugin}`,
55
+ label: ctx.i18n.t("group"),
56
+ source: ctx.plugin,
57
+ sectionLabel: ctx.i18n.t("section"),
58
+ sectionOrder: 1,
59
+ order: 5
60
+ };
61
+ }
62
+ });
63
+ }
64
+ //#endregion
65
+ //#region src/ui.tsx
66
+ /** The host compares this against its own before calling `register`, so a
67
+ * module built against an older host says so instead of failing inside
68
+ * itself. Typed from the contract rather than written as a bare `1`. */
69
+ var runtimeVersion = 5;
70
+ var CATALOGUES = {
71
+ "zh-CN": {
72
+ title: "待办事项",
73
+ offline: "已离线",
74
+ loading: "加载中…",
75
+ retry: "重试",
76
+ pending: "待办",
77
+ "in-progress": "进行中",
78
+ completed: "已完成"
79
+ },
80
+ "en-US": {
81
+ title: "TODO",
82
+ offline: "offline",
83
+ loading: "Loading…",
84
+ retry: "Retry",
85
+ pending: "Pending",
86
+ "in-progress": "In progress",
87
+ completed: "Completed"
88
+ }
89
+ };
90
+ /** What a key falls back to when the page is in a language this plugin has no
91
+ * catalogue for. Per plugin, merged by the host under every language. */
92
+ var FALLBACK = "en-US";
93
+ /**
94
+ * The plugin's own CSS, handed to the host as text.
95
+ *
96
+ * The host wraps it in `@layer plugins { @scope ([data-plugin="…"]) { … } }`,
97
+ * so these selectors reach this plugin's subtree and nothing else, and the
98
+ * whole segment leaves the page when the plugin is unloaded. Every colour and
99
+ * radius comes from the host's frozen tokens rather than a palette of this
100
+ * plugin's own; the one animation name carries the package's prefix, because
101
+ * `@keyframes` names are document-level and a collision silently plays the
102
+ * host's.
103
+ */
104
+ var CSS = `
105
+ .todo-loading { font-size: 0.75rem; line-height: 1rem; color: var(--muted-foreground); }
106
+ .todo-section { min-width: 0; }
107
+ .todo-items, .todo-board-items { min-width: 0; margin: 0.25rem 0 0; padding: 0; list-style: none; }
108
+ .todo-items { margin-inline-start: 7px; }
109
+ .todo-board { min-width: 0; }
110
+ .todo-heading { display: flex; align-items: center; gap: 0.5rem; margin: 0; padding-block: 0.125rem; font-size: 0.75rem; font-weight: 500; color: var(--muted-foreground); }
111
+ .todo-heading-icon { width: 0.875rem; height: 0.875rem; }
112
+ .todo-node { position: relative; min-width: 0; padding-block: 0.125rem; padding-inline-start: 1.25rem; }
113
+ .todo-node::before { content: ''; position: absolute; inset-inline-start: 0; top: 0; width: 0.875rem; height: 0.875rem; border-inline-start: 1px solid var(--border); border-bottom: 1px solid var(--border); border-end-start-radius: 0.375rem; }
114
+ .todo-node:not(:last-child)::after { content: ''; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; border-inline-start: 1px solid var(--border); }
115
+ .todo-row { display: flex; width: calc(100% + 1rem); min-width: 0; align-items: start; gap: 0.5rem; margin-inline: -0.5rem; padding: 0.25rem 0.5rem; border-radius: var(--radius-control); text-align: start; font-size: 0.75rem; line-height: 1rem; color: var(--muted-foreground); }
116
+ .todo-row:hover { background: color-mix(in srgb, var(--muted) 60%, transparent); color: var(--foreground); }
117
+ .todo-row:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
118
+ .todo-row > svg { margin-block-start: 1px; }
119
+ .todo-text { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
120
+ .todo-row[aria-expanded='true'] .todo-text { overflow: visible; text-overflow: clip; white-space: pre-wrap; overflow-wrap: anywhere; }
121
+ .card {
122
+ display: flex;
123
+ flex-direction: column;
124
+ gap: 0.375rem;
125
+ }
126
+ .list {
127
+ display: flex;
128
+ flex-direction: column;
129
+ gap: 0.375rem;
130
+ margin: 0;
131
+ padding: 0;
132
+ list-style: none;
133
+ }
134
+ .item {
135
+ display: flex;
136
+ align-items: start;
137
+ gap: 0.5rem;
138
+ font-size: 0.875rem;
139
+ line-height: 1.6;
140
+ overflow-wrap: anywhere;
141
+ }
142
+ .mark {
143
+ flex: none;
144
+ font-variant-numeric: tabular-nums;
145
+ color: var(--muted-foreground);
146
+ }
147
+ .item[data-status='completed'] .text {
148
+ color: var(--muted-foreground);
149
+ text-decoration: line-through;
150
+ }
151
+ .item[data-status='in-progress'] .mark {
152
+ color: var(--success);
153
+ animation: eum-todo-pulse 2s ease-in-out infinite;
154
+ }
155
+ @media (prefers-reduced-motion: reduce) {
156
+ .item[data-status='in-progress'] .mark { animation: none; }
157
+ }
158
+ @keyframes eum-todo-pulse {
159
+ 50% {
160
+ opacity: 0.45;
161
+ }
162
+ }
163
+ `;
164
+ /** What each status shows in the one-character column. The same three marks
165
+ * the model is shown in the injected text, so a person reading the list and
166
+ * a model reading its context are looking at one notation. */
167
+ /** A todo's STATE column. */
168
+ var TODO_STATES = {
169
+ pending: "pending",
170
+ "in-progress": "running",
171
+ completed: "success"
172
+ };
173
+ function todoSectionFor(ctx) {
174
+ return function TodoSection({ sessionId, where, phase, latest }) {
175
+ if (where === "process") return /* @__PURE__ */ jsx(TodoList, {
176
+ sessionId,
177
+ board: true
178
+ });
179
+ return phase === "running" && latest ? /* @__PURE__ */ jsx(TodoList, {
180
+ sessionId,
181
+ board: false
182
+ }) : null;
183
+ };
184
+ /** The session's list, read and followed for as long as it is shown. */
185
+ function TodoList({ sessionId, board }) {
186
+ const host = useSyncExternalStore(ctx.host.subscribe, ctx.host.get);
187
+ const [todos, setTodos] = useState(null);
188
+ const revision = useRef(0);
189
+ const reading = useRef(/* @__PURE__ */ new Map());
190
+ const [loading, setLoading] = useState(true);
191
+ const [error, setError] = useState(null);
192
+ const read = useCallback((forSession) => {
193
+ if (reading.current.get(forSession) === revision.current) return;
194
+ const requested = ++revision.current;
195
+ reading.current.set(forSession, requested);
196
+ setLoading(true);
197
+ setError(null);
198
+ ctx.invoke("listTodos", { sessionId: forSession }).then((answer) => {
199
+ if (revision.current === requested && answer.sessionId === forSession) {
200
+ setTodos(answer.todos);
201
+ setLoading(false);
202
+ }
203
+ }, (error) => {
204
+ if (revision.current === requested) {
205
+ setError(failureText(error, ctx.i18n.t));
206
+ setLoading(false);
207
+ }
208
+ }).finally(() => {
209
+ if (reading.current.get(forSession) === requested) reading.current.delete(forSession);
210
+ });
211
+ }, [ctx]);
212
+ useEffect(() => {
213
+ setTodos(null);
214
+ read(sessionId);
215
+ return () => {
216
+ revision.current++;
217
+ };
218
+ }, [sessionId, read]);
219
+ useEffect(() => {
220
+ return ctx.on("todosChanged", (event) => {
221
+ if (event.sessionId !== sessionId) return;
222
+ revision.current++;
223
+ const payload = event.payload;
224
+ setTodos(payload.todos);
225
+ setLoading(false);
226
+ setError(null);
227
+ });
228
+ }, [sessionId]);
229
+ const connection = host.connection;
230
+ const wasOnline = useRef(connection === "online");
231
+ useEffect(() => {
232
+ const online = connection === "online";
233
+ const cameBack = online && !wasOnline.current;
234
+ wasOnline.current = online;
235
+ if (cameBack) read(sessionId);
236
+ }, [
237
+ connection,
238
+ sessionId,
239
+ read
240
+ ]);
241
+ const open = todos?.filter((todo) => todo.status !== "completed").length ?? 0;
242
+ if (todos === null && loading) return /* @__PURE__ */ jsx("p", {
243
+ role: "status",
244
+ className: "todo-loading",
245
+ children: ctx.i18n.t("loading")
246
+ });
247
+ if (error) return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
248
+ role: "alert",
249
+ children: error
250
+ }), /* @__PURE__ */ jsx(ctx.ui.Button, {
251
+ onClick: () => read(sessionId),
252
+ disabled: loading,
253
+ loading,
254
+ children: ctx.i18n.t("retry")
255
+ })] });
256
+ if (todos === null || todos.length === 0 || !board && open === 0) return null;
257
+ return /* @__PURE__ */ jsxs("section", {
258
+ className: board ? "todo-board" : "todo-section",
259
+ "aria-label": ctx.i18n.t("title"),
260
+ children: [/* @__PURE__ */ jsxs("h3", {
261
+ className: "todo-heading",
262
+ children: [/* @__PURE__ */ jsx(ctx.ui.Icon, {
263
+ name: "list-todo",
264
+ className: "todo-heading-icon"
265
+ }), ctx.i18n.t("title")]
266
+ }), /* @__PURE__ */ jsx("ul", {
267
+ className: board ? "todo-board-items" : "todo-items",
268
+ children: todos.map((todo, index) => /* @__PURE__ */ jsx("li", {
269
+ className: board ? void 0 : "todo-node",
270
+ children: /* @__PURE__ */ jsx(TodoRow, { todo })
271
+ }, `${index}-${todo.content}`))
272
+ })]
273
+ });
274
+ }
275
+ /** Expands the row's single text copy without opening a separate detail panel. */
276
+ function TodoRow({ todo }) {
277
+ const [expanded, setExpanded] = useState(false);
278
+ return /* @__PURE__ */ jsxs(ctx.ui.Button, {
279
+ variant: "plain",
280
+ className: "todo-row",
281
+ "aria-expanded": expanded,
282
+ onClick: () => setExpanded((current) => !current),
283
+ children: [/* @__PURE__ */ jsx(LineState, {
284
+ state: TODO_STATES[todo.status],
285
+ label: ctx.i18n.t(todo.status)
286
+ }), /* @__PURE__ */ jsx("span", {
287
+ className: "todo-text",
288
+ children: todo.content
289
+ })]
290
+ });
291
+ }
292
+ }
293
+ var register = (ctx) => {
294
+ registerMetadata(ctx);
295
+ ctx.i18n.register(CATALOGUES, FALLBACK);
296
+ ctx.styles.add(CSS);
297
+ ctx.slots.register("chat.run.section", {
298
+ id: "todos",
299
+ order: 40,
300
+ component: todoSectionFor(ctx)
301
+ });
302
+ ctx.log.info("registered the todo section");
303
+ };
304
+ //#endregion
305
+ export { register, runtimeVersion };
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.