@agentshouse/mdruntime 0.1.0-cf6d5f0a5c9c8 → 0.1.0-cfb0d45b48da0

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 (158) hide show
  1. package/AGENTS.md +146 -100
  2. package/README.md +11 -1
  3. package/dist/adapter.d.ts +41 -14
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/attempt.d.ts +16 -0
  6. package/dist/attempt.d.ts.map +1 -0
  7. package/dist/attempt.js +57 -0
  8. package/dist/binary.d.ts +23 -0
  9. package/dist/binary.d.ts.map +1 -0
  10. package/dist/binary.js +8 -0
  11. package/dist/bootstrap.d.ts.map +1 -1
  12. package/dist/bootstrap.js +5 -8
  13. package/dist/change-set.d.ts.map +1 -1
  14. package/dist/change-set.js +8 -7
  15. package/dist/change.d.ts +15 -0
  16. package/dist/change.d.ts.map +1 -1
  17. package/dist/change.js +26 -1
  18. package/dist/chat/acts.d.ts +34 -0
  19. package/dist/chat/acts.d.ts.map +1 -0
  20. package/dist/chat/acts.js +36 -0
  21. package/dist/chat/context.d.ts +3 -0
  22. package/dist/chat/context.d.ts.map +1 -0
  23. package/dist/chat/context.js +10 -0
  24. package/dist/chat/input.d.ts +9 -0
  25. package/dist/chat/input.d.ts.map +1 -0
  26. package/dist/chat/input.js +99 -0
  27. package/dist/chat/kit.d.ts +60 -0
  28. package/dist/chat/kit.d.ts.map +1 -0
  29. package/dist/chat/kit.js +123 -0
  30. package/dist/chat/lasting.d.ts +6 -0
  31. package/dist/chat/lasting.d.ts.map +1 -0
  32. package/dist/chat/lasting.js +19 -0
  33. package/dist/chat/list.d.ts +20 -0
  34. package/dist/chat/list.d.ts.map +1 -0
  35. package/dist/chat/list.js +59 -0
  36. package/dist/chat/markdown.d.ts +19 -0
  37. package/dist/chat/markdown.d.ts.map +1 -0
  38. package/dist/chat/markdown.js +187 -0
  39. package/dist/chat/message.d.ts +6 -0
  40. package/dist/chat/message.d.ts.map +1 -0
  41. package/dist/chat/message.js +192 -0
  42. package/dist/chat/messages.d.ts +21 -0
  43. package/dist/chat/messages.d.ts.map +1 -0
  44. package/dist/chat/messages.js +151 -0
  45. package/dist/chat/name.d.ts +6 -0
  46. package/dist/chat/name.d.ts.map +1 -0
  47. package/dist/chat/name.js +37 -0
  48. package/dist/chat/opened.d.ts +11 -0
  49. package/dist/chat/opened.d.ts.map +1 -0
  50. package/dist/chat/opened.js +17 -0
  51. package/dist/chat/overlay.d.ts +31 -0
  52. package/dist/chat/overlay.d.ts.map +1 -0
  53. package/dist/chat/overlay.js +97 -0
  54. package/dist/chat/parts.d.ts +57 -0
  55. package/dist/chat/parts.d.ts.map +1 -0
  56. package/dist/chat/parts.js +119 -0
  57. package/dist/chat/process.d.ts +20 -0
  58. package/dist/chat/process.d.ts.map +1 -0
  59. package/dist/chat/process.js +32 -0
  60. package/dist/chat/provider.d.ts +63 -0
  61. package/dist/chat/provider.d.ts.map +1 -0
  62. package/dist/chat/provider.js +645 -0
  63. package/dist/chat/question.d.ts +9 -0
  64. package/dist/chat/question.d.ts.map +1 -0
  65. package/dist/chat/question.js +80 -0
  66. package/dist/chat/questions.d.ts +31 -0
  67. package/dist/chat/questions.d.ts.map +1 -0
  68. package/dist/chat/questions.js +111 -0
  69. package/dist/chat/read.d.ts +5 -0
  70. package/dist/chat/read.d.ts.map +1 -0
  71. package/dist/chat/read.js +13 -0
  72. package/dist/chat/ready.d.ts +33 -0
  73. package/dist/chat/ready.d.ts.map +1 -0
  74. package/dist/chat/ready.js +91 -0
  75. package/dist/chat/style.d.ts +4 -0
  76. package/dist/chat/style.d.ts.map +1 -0
  77. package/dist/chat/style.js +302 -0
  78. package/dist/chat.d.ts +14 -0
  79. package/dist/chat.d.ts.map +1 -0
  80. package/dist/chat.js +8 -0
  81. package/dist/client.d.ts +12 -5
  82. package/dist/client.d.ts.map +1 -1
  83. package/dist/client.js +30 -15
  84. package/dist/connection.d.ts +19 -9
  85. package/dist/connection.d.ts.map +1 -1
  86. package/dist/connection.js +312 -96
  87. package/dist/conversation.d.ts +11 -3
  88. package/dist/conversation.d.ts.map +1 -1
  89. package/dist/conversation.js +47 -7
  90. package/dist/expectation.d.ts +21 -0
  91. package/dist/expectation.d.ts.map +1 -0
  92. package/dist/expectation.js +70 -0
  93. package/dist/failure.d.ts +13 -0
  94. package/dist/failure.d.ts.map +1 -0
  95. package/dist/failure.js +19 -0
  96. package/dist/host.d.ts +2 -2
  97. package/dist/host.d.ts.map +1 -1
  98. package/dist/host.js +12 -12
  99. package/dist/identity.d.ts +2 -0
  100. package/dist/identity.d.ts.map +1 -1
  101. package/dist/identity.js +6 -0
  102. package/dist/index.d.ts +9 -4
  103. package/dist/index.d.ts.map +1 -1
  104. package/dist/index.js +3 -0
  105. package/dist/memory.d.ts +3 -3
  106. package/dist/memory.d.ts.map +1 -1
  107. package/dist/memory.js +47 -16
  108. package/dist/model.d.ts +3 -2
  109. package/dist/model.d.ts.map +1 -1
  110. package/dist/open.d.ts +2 -0
  111. package/dist/open.d.ts.map +1 -0
  112. package/dist/open.js +1 -0
  113. package/dist/outcome.d.ts +28 -3
  114. package/dist/outcome.d.ts.map +1 -1
  115. package/dist/outcome.js +41 -1
  116. package/dist/overlay.d.ts +14 -3
  117. package/dist/overlay.d.ts.map +1 -1
  118. package/dist/overlay.js +75 -37
  119. package/dist/query.d.ts +4 -0
  120. package/dist/query.d.ts.map +1 -1
  121. package/dist/query.js +3 -0
  122. package/dist/reach.d.ts +2 -0
  123. package/dist/reach.d.ts.map +1 -1
  124. package/dist/reach.js +43 -19
  125. package/dist/react.d.ts +4 -2
  126. package/dist/react.d.ts.map +1 -1
  127. package/dist/react.js +3 -2
  128. package/dist/read-side.d.ts.map +1 -1
  129. package/dist/read-side.js +9 -2
  130. package/dist/refresh.d.ts.map +1 -1
  131. package/dist/refresh.js +12 -17
  132. package/dist/replica.d.ts +6 -3
  133. package/dist/replica.d.ts.map +1 -1
  134. package/dist/replica.js +46 -32
  135. package/dist/room-draft.d.ts +26 -9
  136. package/dist/room-draft.d.ts.map +1 -1
  137. package/dist/room-draft.js +131 -22
  138. package/dist/rows.d.ts +3 -1
  139. package/dist/rows.d.ts.map +1 -1
  140. package/dist/rows.js +3 -1
  141. package/dist/save.d.ts +27 -1
  142. package/dist/save.d.ts.map +1 -1
  143. package/dist/save.js +323 -22
  144. package/dist/search.d.ts +3 -2
  145. package/dist/search.d.ts.map +1 -1
  146. package/dist/status.d.ts +2 -2
  147. package/dist/status.d.ts.map +1 -1
  148. package/dist/status.js +0 -8
  149. package/dist/store.d.ts +16 -13
  150. package/dist/store.d.ts.map +1 -1
  151. package/dist/store.js +186 -156
  152. package/dist/wire.d.ts +6 -3
  153. package/dist/wire.d.ts.map +1 -1
  154. package/dist/wire.js +14 -2
  155. package/package.json +22 -14
  156. package/dist/attachment.d.ts +0 -3
  157. package/dist/attachment.d.ts.map +0 -1
  158. package/dist/attachment.js +0 -8
@@ -0,0 +1,123 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Children, createContext, useCallback, useContext, useEffect, useState, } from 'react';
3
+ import { Dialog, DropdownMenu } from 'radix-ui';
4
+ import { LucideProvider } from 'lucide-react/dist/esm/context.mjs';
5
+ import X from 'lucide-react/dist/esm/icons/x.mjs';
6
+ import { adopted } from './style.js';
7
+ export const Portal = createContext(null);
8
+ export function Within({ root, children, }) {
9
+ return (_jsx(Portal.Provider, { value: root, children: _jsx(LucideProvider, { size: 16, strokeWidth: 1.5, absoluteStrokeWidth: true, children: children }) }));
10
+ }
11
+ export function Scoped({ children }) {
12
+ const inside = useContext(Portal);
13
+ const [root, setRoot] = useState(null);
14
+ const attach = useCallback((element) => {
15
+ adopted(element);
16
+ setRoot(element);
17
+ }, []);
18
+ if (inside !== null)
19
+ return _jsx(_Fragment, { children: children });
20
+ return (_jsx("div", { ref: attach, className: "ahc ahc-scope", children: root === null ? null : _jsx(Within, { root: root, children: children }) }));
21
+ }
22
+ export function buttonClass(variant, compact, icon) {
23
+ return [
24
+ 'ahc-btn',
25
+ icon ? 'ahc-btn--icon' : null,
26
+ variant === 'quiet' ? null : `ahc-btn--${variant}`,
27
+ compact ? 'ahc-btn--compact' : null,
28
+ ]
29
+ .filter(Boolean)
30
+ .join(' ');
31
+ }
32
+ function labelled(children) {
33
+ const parts = [];
34
+ let said = '';
35
+ const flush = () => {
36
+ if (said !== '') {
37
+ parts.push(_jsx("span", { className: "ahc-name", children: said }, `text-${parts.length}`));
38
+ }
39
+ said = '';
40
+ };
41
+ for (const child of Children.toArray(children)) {
42
+ if (typeof child === 'string' || typeof child === 'number')
43
+ said += String(child);
44
+ else {
45
+ flush();
46
+ parts.push(child);
47
+ }
48
+ }
49
+ flush();
50
+ return parts;
51
+ }
52
+ export function Button({ variant = 'quiet', compact = false, type = 'button', children, ...rest }) {
53
+ return (_jsx("button", { type: type, className: buttonClass(variant, compact, false), ...rest, children: labelled(children) }));
54
+ }
55
+ export function IconButton({ label, variant = 'quiet', compact = false, type = 'button', ...rest }) {
56
+ return (_jsx("button", { type: type, "aria-label": label, className: buttonClass(variant, compact, true), ...rest }));
57
+ }
58
+ export function Name({ text, className }) {
59
+ return (_jsx("span", { className: className === undefined ? 'ahc-name' : `ahc-name ${className}`, title: text, children: text }));
60
+ }
61
+ export function Menu({ trigger, children, }) {
62
+ const container = useContext(Portal);
63
+ const [open, setOpen] = useState(false);
64
+ return (_jsxs(DropdownMenu.Root, { modal: false, open: open, onOpenChange: setOpen, children: [_jsx(DropdownMenu.Trigger, { asChild: true, children: trigger }), open ? (_jsx(DropdownMenu.Portal, { forceMount: true, container: container, children: _jsx(DropdownMenu.Content, { forceMount: true, className: "ahc-menu", align: "end", sideOffset: 4, collisionPadding: 8, children: children }) })) : null] }));
65
+ }
66
+ export function MenuGap() {
67
+ return _jsx(DropdownMenu.Separator, { className: "ahc-menu__gap" });
68
+ }
69
+ export function MenuItem({ icon, danger = false, onSelect, children, }) {
70
+ return (_jsxs(DropdownMenu.Item, { className: danger ? 'ahc-row ahc-row--danger' : 'ahc-row', onSelect: onSelect, children: [_jsx("span", { className: "ahc-row__icon", children: icon }), _jsx("span", { className: "ahc-row__label", children: _jsx("span", { className: "ahc-row__title", children: children }) })] }));
71
+ }
72
+ export function Confirm({ title, text, action, onConfirm, onClose, }) {
73
+ const container = useContext(Portal);
74
+ useEffect(() => {
75
+ const behind = container?.querySelector('.ahc-frame');
76
+ if (behind === null || behind === undefined)
77
+ return;
78
+ behind.inert = true;
79
+ return () => {
80
+ behind.inert = false;
81
+ };
82
+ }, [container]);
83
+ return (_jsx(Dialog.Root, { open: true, modal: false, onOpenChange: (open) => {
84
+ if (!open)
85
+ onClose();
86
+ }, children: _jsxs(Dialog.Portal, { container: container, children: [_jsx("div", { className: "ahc-scrim", onClick: onClose }), _jsxs(Dialog.Content, { className: "ahc-dialog", role: "alertdialog", "aria-describedby": undefined, "aria-modal": true, onInteractOutside: (event) => event.preventDefault(), children: [_jsxs("div", { className: "ahc-dialog__head", children: [_jsx(Dialog.Title, { className: "ahc-dialog__title", children: title }), _jsx(Dialog.Close, { asChild: true, children: _jsx(IconButton, { label: "Close", compact: true, children: _jsx(X, { size: 20, "aria-hidden": "true" }) }) })] }), _jsx("div", { className: "ahc-dialog__body", children: _jsx("p", { className: "ahc-dialog__text", children: text }) }), _jsxs("div", { className: "ahc-dialog__actions", children: [_jsx(Button, { onClick: onClose, children: "Cancel" }), _jsx(Button, { variant: "danger", onClick: () => {
87
+ onConfirm();
88
+ onClose();
89
+ }, children: action })] })] })] }) }));
90
+ }
91
+ export function ItemRow({ lead, title, sub, trailing, }) {
92
+ return (_jsxs("div", { className: "ahc-row ahc-row--two ahc-item", children: [_jsx("span", { className: "ahc-item__lead", children: lead }), _jsxs("span", { className: "ahc-row__label", children: [_jsx("span", { className: "ahc-row__title ahc-item__title", children: title }), _jsx("span", { className: "ahc-row__sub", children: sub })] }), trailing] }));
93
+ }
94
+ function elapsed(seconds) {
95
+ return seconds >= 60 ? `${Math.floor(seconds / 60)}m ${seconds % 60}s` : `${seconds}s`;
96
+ }
97
+ export function Working({ step }) {
98
+ const [from] = useState(() => Date.now());
99
+ const [now, setNow] = useState(from);
100
+ useEffect(() => {
101
+ // The elapsed time counts whole seconds, so it moves once a second.
102
+ const tick = setInterval(() => setNow(Date.now()), 1000);
103
+ return () => clearInterval(tick);
104
+ }, []);
105
+ return (_jsxs("div", { className: "ahc-toolline ahc-working", role: "status", children: [_jsx("span", { className: "ahc-shimmer", children: "Working" }), _jsx("span", { className: "ahc-figure", "aria-hidden": "true", children: elapsed(Math.floor((now - from) / 1000)) }), step === undefined ? null : _jsx("span", { children: step })] }));
106
+ }
107
+ const SAID = {
108
+ sending: 'Sending…',
109
+ offline: 'You are offline. Nothing was sent.',
110
+ };
111
+ const UNANSWERED = 'House did not answer.';
112
+ export function ChatNote({ outcome, again }) {
113
+ if (outcome === null)
114
+ return null;
115
+ const uncertain = outcome.state === 'failed' && outcome.result.kind === 'transport-uncertainty';
116
+ const said = outcome.state !== 'failed'
117
+ ? SAID[outcome.state]
118
+ : uncertain
119
+ ? 'House did not answer. Try again.'
120
+ : 'House refused this.';
121
+ const retried = again !== undefined && uncertain;
122
+ return (_jsxs("p", { className: "ahc-note", role: "status", "data-state": uncertain ? 'uncertain' : outcome.state, children: [retried ? UNANSWERED : said, retried ? (_jsxs(_Fragment, { children: [' ', _jsx("button", { type: "button", className: "ahc-again", onClick: again, children: "Try again" })] })) : null] }));
123
+ }
@@ -0,0 +1,6 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { ChatWork } from './parts.js';
3
+ export declare function StillRunning({ lasting }: {
4
+ lasting: readonly ChatWork[];
5
+ }): ReactElement;
6
+ //# sourceMappingURL=lasting.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lasting.d.ts","sourceRoot":"","sources":["../../src/chat/lasting.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAM1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAiB3C,wBAAgB,YAAY,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,SAAS,QAAQ,EAAE,CAAA;CAAE,GAAG,YAAY,CAyBxF"}
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import Bot from 'lucide-react/dist/esm/icons/bot.mjs';
3
+ import CalendarClock from 'lucide-react/dist/esm/icons/calendar-clock.mjs';
4
+ import RefreshCw from 'lucide-react/dist/esm/icons/refresh-cw.mjs';
5
+ import Terminal from 'lucide-react/dist/esm/icons/terminal.mjs';
6
+ import { ItemRow } from './kit.js';
7
+ const SUB = {
8
+ job: 'A background job',
9
+ schedule: 'A schedule',
10
+ subagent: 'A sub-agent',
11
+ };
12
+ function Icon({ kind }) {
13
+ if (kind === 'schedule')
14
+ return _jsx(CalendarClock, { size: 20, "aria-hidden": "true" });
15
+ return kind === 'subagent' ? (_jsx(Bot, { size: 20, "aria-hidden": "true" })) : (_jsx(Terminal, { size: 20, "aria-hidden": "true" }));
16
+ }
17
+ export function StillRunning({ lasting }) {
18
+ return (_jsxs("section", { "aria-label": "Still running", className: "ahc-lasting", children: [_jsxs("div", { className: "ahc-lasting__head", children: [_jsx("h2", { className: "ahc-lasting__title", children: "Still running" }), _jsx("span", { className: "ahc-secondary", children: "After this turn ended" })] }), lasting.map((one, at) => (_jsx(ItemRow, { lead: _jsx(Icon, { kind: one.kind }), title: one.title === '' ? SUB[one.kind] : one.title, sub: one.next === null ? SUB[one.kind] : `${SUB[one.kind]} · next run ${one.next}`, trailing: one.kind === 'schedule' ? null : (_jsxs("span", { className: "ahc-running", children: [_jsx(RefreshCw, { "aria-hidden": "true" }), "Running"] })) }, `${one.kind}:${one.title}:${at}`)))] }));
19
+ }
@@ -0,0 +1,20 @@
1
+ import { type ComponentType, type ReactElement, type ReactNode } from 'react';
2
+ export type AgentLook = {
3
+ readonly agentMark?: ((agent: string, size: number) => ReactNode) | undefined;
4
+ readonly agentDetail?: ((agent: string) => string) | undefined;
5
+ };
6
+ export declare const Described: import("react").Context<AgentLook>;
7
+ export type ChatMessageListProps = {
8
+ readonly components?: {
9
+ readonly UserMessage?: ComponentType;
10
+ readonly AssistantMessage?: ComponentType;
11
+ };
12
+ readonly onLink?: (href: string) => void;
13
+ readonly footer?: ReactNode;
14
+ readonly children?: ReactNode;
15
+ };
16
+ export declare function ChatMessageList({ components, onLink, footer, children, }: ChatMessageListProps): ReactElement;
17
+ export declare function ChatList({ onChoose }: {
18
+ onChoose: () => void;
19
+ }): ReactElement;
20
+ //# sourceMappingURL=list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/chat/list.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAYf,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,SAAS,CAAC,GAAG,SAAS,CAAC;IAC9E,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;CAChE,CAAC;AAEF,eAAO,MAAM,SAAS,oCAA+B,CAAC;AAmDtD,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE;QACpB,QAAQ,CAAC,WAAW,CAAC,EAAE,aAAa,CAAC;QACrC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,aAAa,CAAC;KAC3C,CAAC;IACF,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;CAC/B,CAAC;AAEF,wBAAgB,eAAe,CAAC,EAC9B,UAAe,EACf,MAAM,EACN,MAAM,EACN,QAAQ,GACT,EAAE,oBAAoB,GAAG,YAAY,CAmCrC;AAoBD,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,IAAI,CAAA;CAAE,GAAG,YAAY,CAkD7E"}
@@ -0,0 +1,59 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext, } from 'react';
3
+ import { ThreadPrimitive } from '@assistant-ui/react';
4
+ import Check from 'lucide-react/dist/esm/icons/check.mjs';
5
+ import MessageSquare from 'lucide-react/dist/esm/icons/message-square.mjs';
6
+ import SquarePen from 'lucide-react/dist/esm/icons/square-pen.mjs';
7
+ import { Name, Scoped } from './kit.js';
8
+ import { AssistantMessage, Linked, UserMessage } from './message.js';
9
+ import { ChatName } from './name.js';
10
+ import { useOpened } from './opened.js';
11
+ import { ChatQuestionCard } from './question.js';
12
+ export const Described = createContext({});
13
+ function Chip({ agent, name, on, start, }) {
14
+ const { agentMark, agentDetail } = useContext(Described);
15
+ return (_jsxs("button", { type: "button", className: "ahc-btn ahc-agent", "aria-pressed": on, onClick: () => start(agent), children: [agentMark?.(agent, 16), _jsx(Name, { text: name }), agentDetail === undefined ? null : _jsx(Name, { text: agentDetail(agent), className: "ahc-meta" })] }));
16
+ }
17
+ function Empty() {
18
+ const chat = useOpened();
19
+ return (_jsxs("div", { className: "ahc-empty", children: [_jsx("h2", { className: "ahc-empty__title", children: "What should we work on?" }), chat.conversation === null &&
20
+ (chat.agents.length > 1 || !chat.agents.some((one) => one.identity === chat.by)) ? (_jsx("div", { role: "group", "aria-label": "Agent", className: "ahc-agents", children: chat.agents.map((one) => (_jsx(Chip, { agent: one.identity, name: one.name, on: one.identity === chat.by, start: chat.start }, one.identity))) })) : null] }));
21
+ }
22
+ export function ChatMessageList({ components = {}, onLink, footer, children, }) {
23
+ const chat = useOpened();
24
+ const linked = useContext(Linked);
25
+ const User = components.UserMessage ?? UserMessage;
26
+ const Assistant = components.AssistantMessage ?? AssistantMessage;
27
+ const silent = chat.view === null
28
+ ? chat.conversation === null
29
+ : chat.view.messages.length === 0 && chat.view.turn === null;
30
+ return (_jsx(Scoped, { children: _jsx(Linked.Provider, { value: onLink ?? linked, children: _jsx(ThreadPrimitive.Root, { className: "ahc-thread", children: _jsxs(ThreadPrimitive.Viewport, { className: "ahc-viewport", children: [_jsxs("div", { className: "ahc-column ahc-messages", children: [silent ? _jsx(Empty, {}) : null, _jsx(ThreadPrimitive.Messages, { children: ({ message }) => (message.role === 'user' ? _jsx(User, {}) : _jsx(Assistant, {})) }), children === undefined
31
+ ? chat.questions.map((question) => (_jsx(ChatQuestionCard, { question: question }, question.interaction)))
32
+ : children] }), footer === undefined ? null : (_jsx(ThreadPrimitive.ViewportFooter, { className: "ahc-column ahc-footer", children: footer }))] }) }) }) }));
33
+ }
34
+ function stateOf(entry) {
35
+ if (entry.state === 'asking') {
36
+ return _jsx("span", { className: "ahc-chip ahc-chip--attention ahc-chip--small", children: "Waits for you" });
37
+ }
38
+ if (entry.state === 'working')
39
+ return _jsx("span", { className: "ahc-row__meta", children: "Working" });
40
+ if (entry.outcome === 'failed' && entry.finished === null) {
41
+ return _jsx("span", { className: "ahc-row__meta", children: "Failed" });
42
+ }
43
+ if (entry.finished !== null) {
44
+ return (_jsx("span", { className: "ahc-row__meta", role: "img", "aria-label": "Done", title: "Done", children: _jsx(Check, { "aria-hidden": "true" }) }));
45
+ }
46
+ return null;
47
+ }
48
+ export function ChatList({ onChoose }) {
49
+ const chat = useOpened();
50
+ const listed = [...chat.conversations].sort((left, right) => left.conversation < right.conversation ? 1 : -1);
51
+ const fresh = (chat.agents.find((one) => one.identity === chat.by) ?? chat.agents[0])?.identity;
52
+ return (_jsxs("nav", { "aria-label": "Chats", className: "ahc-list", children: [fresh === undefined ? null : (_jsxs("button", { type: "button", className: "ahc-row", "aria-current": chat.conversation === null ? 'page' : undefined, onClick: () => {
53
+ chat.start(fresh);
54
+ onChoose();
55
+ }, children: [_jsx("span", { className: "ahc-row__icon", children: _jsx(SquarePen, { "aria-hidden": "true" }) }), _jsx("span", { className: "ahc-row__label", children: _jsx("span", { className: "ahc-row__title", children: "New chat" }) })] })), listed.map((entry) => (_jsxs("button", { type: "button", className: "ahc-row", "aria-current": entry.conversation === chat.conversation ? 'page' : undefined, onClick: () => {
56
+ chat.open(entry.conversation);
57
+ onChoose();
58
+ }, children: [_jsx("span", { className: "ahc-row__icon", children: _jsx(MessageSquare, { "aria-hidden": "true" }) }), _jsx("span", { className: "ahc-row__label", children: _jsx("span", { className: "ahc-row__title", children: _jsx(ChatName, { name: entry.name }) }) }), stateOf(entry)] }, entry.conversation)))] }));
59
+ }
@@ -0,0 +1,19 @@
1
+ import { type ReactElement, type ReactNode } from 'react';
2
+ export interface FileReference {
3
+ readonly pattern: RegExp;
4
+ readonly draw: (reference: string, label: string) => ReactNode;
5
+ }
6
+ interface MarkdownOptions {
7
+ readonly className?: string;
8
+ readonly onLink?: (href: string) => void;
9
+ readonly file?: FileReference;
10
+ }
11
+ export declare function slugOf(text: string): string;
12
+ export declare function anchorOf(fragment: string): string;
13
+ export declare function plainText(text: string): string;
14
+ export type MarkdownProps = MarkdownOptions & {
15
+ readonly text: string;
16
+ };
17
+ export declare function Markdown({ text, className, ...options }: MarkdownProps): ReactElement;
18
+ export {};
19
+ //# sourceMappingURL=markdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/chat/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAKnF,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC;CAChE;AAED,UAAU,eAAe;IACvB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC;CAC/B;AAYD,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM3C;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEjD;AAiND,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,MAAM,MAAM,aAAa,GAAG,eAAe,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAExE,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,EAAE,EAAE,aAAa,GAAG,YAAY,CAOrF"}
@@ -0,0 +1,187 @@
1
+ import { createElement, Fragment } from 'react';
2
+ import { fromMarkdown } from 'mdast-util-from-markdown';
3
+ import { gfmFromMarkdown } from 'mdast-util-gfm';
4
+ import { gfm } from 'micromark-extension-gfm';
5
+ function unfiled(options) {
6
+ const { definitions, slugs, onLink } = options;
7
+ return onLink === undefined ? { definitions, slugs } : { definitions, slugs, onLink };
8
+ }
9
+ export function slugOf(text) {
10
+ return text
11
+ .trim()
12
+ .toLowerCase()
13
+ .replace(/[^\p{L}\p{M}\p{N}\s_-]/gu, '')
14
+ .replace(/\s/g, '-');
15
+ }
16
+ export function anchorOf(fragment) {
17
+ return `md-${slugOf(fragment)}`;
18
+ }
19
+ function headingId(slugs, text) {
20
+ const slug = slugOf(text);
21
+ const seen = slugs.get(slug) ?? 0;
22
+ slugs.set(slug, seen + 1);
23
+ return anchorOf(seen === 0 ? slug : `${slug}-${seen}`);
24
+ }
25
+ function whole(file, text) {
26
+ return file !== undefined && [...text.matchAll(file.pattern)].some((one) => one[0] === text);
27
+ }
28
+ function referenced(file, text, key) {
29
+ const parts = [];
30
+ let from = 0;
31
+ for (const found of text.matchAll(file.pattern)) {
32
+ const at = found.index;
33
+ if (at > from)
34
+ parts.push(text.slice(from, at));
35
+ parts.push(createElement(Fragment, { key: at }, file.draw(found[0], found[0])));
36
+ from = at + found[0].length;
37
+ }
38
+ if (from === 0)
39
+ return text;
40
+ if (from < text.length)
41
+ parts.push(text.slice(from));
42
+ return createElement(Fragment, { key }, ...parts);
43
+ }
44
+ function parseMarkdown(text) {
45
+ return fromMarkdown(text, { extensions: [gfm()], mdastExtensions: [gfmFromMarkdown()] });
46
+ }
47
+ function safeHref(url) {
48
+ const href = url.replace(/[\t\n\r]/g, '').replace(/^[\u0000-\u0020]+|[\u0000-\u0020]+$/g, '');
49
+ if (href === '' || /^[\\/]{2}/.test(href))
50
+ return null;
51
+ if (/^(?:https?:|mailto:)/i.test(href))
52
+ return href;
53
+ if (/^[a-z][a-z0-9+.-]*:/i.test(href))
54
+ return null;
55
+ return href;
56
+ }
57
+ function external(href) {
58
+ return /^(?:https?:|mailto:)/i.test(href);
59
+ }
60
+ function textOf(node) {
61
+ if ('value' in node && typeof node.value === 'string')
62
+ return node.value;
63
+ if ('children' in node)
64
+ return node.children.map(textOf).join('');
65
+ return '';
66
+ }
67
+ function definitionsOf(node, found = new Map()) {
68
+ if (node.type === 'definition' && !found.has(node.identifier))
69
+ found.set(node.identifier, node.url);
70
+ if ('children' in node)
71
+ for (const child of node.children)
72
+ definitionsOf(child, found);
73
+ return found;
74
+ }
75
+ function link(url, node, key, options) {
76
+ if (options.file !== undefined && whole(options.file, url)) {
77
+ return createElement(Fragment, { key }, options.file.draw(url, textOf(node) || url));
78
+ }
79
+ const inside = node.children.map((child, at) => render(child, at, unfiled(options)));
80
+ const href = safeHref(url);
81
+ if (href === null)
82
+ return createElement(Fragment, { key }, ...inside);
83
+ const onLink = options.onLink;
84
+ if (external(href) || onLink === undefined) {
85
+ return createElement('a', { key, href, rel: 'noreferrer' }, ...inside);
86
+ }
87
+ return createElement('a', {
88
+ key,
89
+ href,
90
+ onClick: (event) => {
91
+ event.preventDefault();
92
+ onLink(href);
93
+ },
94
+ }, ...inside);
95
+ }
96
+ function render(node, key, options, header = false) {
97
+ const children = () => 'children' in node
98
+ ? node.children.map((child, at) => render(child, at, options))
99
+ : [];
100
+ switch (node.type) {
101
+ case 'root':
102
+ return createElement(Fragment, { key }, ...children());
103
+ case 'paragraph':
104
+ return createElement('p', { key }, ...children());
105
+ case 'heading':
106
+ return createElement(`h${node.depth}`, { key, id: headingId(options.slugs, textOf(node)) }, ...children());
107
+ case 'text':
108
+ return options.file === undefined ? node.value : referenced(options.file, node.value, key);
109
+ case 'emphasis':
110
+ return createElement('em', { key }, ...children());
111
+ case 'strong':
112
+ return createElement('strong', { key }, ...children());
113
+ case 'delete':
114
+ return createElement('del', { key }, ...children());
115
+ case 'inlineCode':
116
+ return createElement('code', { key }, node.value);
117
+ case 'code':
118
+ return createElement('pre', { key }, createElement('code', null, node.value));
119
+ case 'blockquote':
120
+ return createElement('blockquote', { key }, ...children());
121
+ case 'list':
122
+ return node.ordered === true
123
+ ? createElement('ol', { key, start: node.start ?? undefined }, ...children())
124
+ : createElement('ul', { key }, ...children());
125
+ case 'listItem': {
126
+ const items = node.children.flatMap((child, at) => child.type === 'paragraph' && node.spread !== true
127
+ ? child.children.map((inline, place) => render(inline, at * 1000 + place, options))
128
+ : [render(child, at, options)]);
129
+ return createElement('li', { key }, node.checked == null
130
+ ? null
131
+ : createElement('input', { type: 'checkbox', checked: node.checked, disabled: true }), ...items);
132
+ }
133
+ case 'thematicBreak':
134
+ return createElement('hr', { key });
135
+ case 'break':
136
+ return createElement('br', { key });
137
+ case 'link':
138
+ return link(node.url, node, key, options);
139
+ case 'linkReference':
140
+ return link(options.definitions.get(node.identifier) ?? '', node, key, options);
141
+ case 'image':
142
+ return options.file !== undefined && whole(options.file, node.url)
143
+ ? createElement(Fragment, { key }, options.file.draw(node.url, node.alt || node.url))
144
+ : (node.alt ?? '');
145
+ case 'html':
146
+ return node.value;
147
+ case 'table':
148
+ return createElement('table', { key }, createElement('thead', null, ...node.children.slice(0, 1).map((row, at) => render(row, at, options, true))), createElement('tbody', null, ...node.children.slice(1).map((row, at) => render(row, at, options))));
149
+ case 'tableRow':
150
+ return createElement('tr', { key }, ...node.children.map((cell, at) => createElement(header ? 'th' : 'td', { key: at }, ...cell.children.map((inline, place) => render(inline, place, options)))));
151
+ case 'footnoteReference':
152
+ return createElement('sup', { key }, node.label ?? node.identifier);
153
+ case 'definition':
154
+ case 'yaml':
155
+ return null;
156
+ default:
157
+ return textOf(node);
158
+ }
159
+ }
160
+ const INLINE = new Set([
161
+ 'paragraph',
162
+ 'heading',
163
+ 'emphasis',
164
+ 'strong',
165
+ 'delete',
166
+ 'link',
167
+ 'linkReference',
168
+ 'tableCell',
169
+ ]);
170
+ function spokenOf(node) {
171
+ if (node.type === 'yaml')
172
+ return '';
173
+ if (node.type === 'image')
174
+ return node.alt ?? '';
175
+ if ('value' in node && typeof node.value === 'string')
176
+ return node.value;
177
+ if (!('children' in node))
178
+ return node.type === 'break' ? ' ' : '';
179
+ return node.children.map(spokenOf).join(INLINE.has(node.type) ? '' : ' ');
180
+ }
181
+ export function plainText(text) {
182
+ return spokenOf(parseMarkdown(text)).replace(/\s+/g, ' ').trim();
183
+ }
184
+ export function Markdown({ text, className, ...options }) {
185
+ const root = parseMarkdown(text);
186
+ return createElement('div', { className }, render(root, 0, { ...options, definitions: definitionsOf(root), slugs: new Map() }));
187
+ }
@@ -0,0 +1,6 @@
1
+ import { type ReactElement } from 'react';
2
+ export declare const Linked: import("react").Context<((href: string) => void) | null>;
3
+ export declare function UserMessage(): ReactElement;
4
+ export declare function Undelivered(): ReactElement;
5
+ export declare function AssistantMessage(): ReactElement;
6
+ //# sourceMappingURL=message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/chat/message.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,YAAY,EAElB,MAAM,OAAO,CAAC;AAkCf,eAAO,MAAM,MAAM,kCAAyB,MAAM,KAAK,IAAI,SAAe,CAAC;AA4O3E,wBAAgB,WAAW,IAAI,YAAY,CA4B1C;AAED,wBAAgB,WAAW,IAAI,YAAY,CAE1C;AAED,wBAAgB,gBAAgB,IAAI,YAAY,CA0F/C"}