@agentshouse/mdruntime 0.1.0-c5d09b1c896fb → 0.1.0-c5f333dfa0583
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/AGENTS.md +225 -215
- package/README.md +9 -8
- package/dist/adapter.d.ts +64 -24
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +4 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +13 -3
- package/dist/bootstrap.d.ts +15 -7
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +90 -61
- package/dist/chain.d.ts +11 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +8 -9
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +10 -85
- package/dist/change.d.ts +31 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +10 -1
- package/dist/chat/earlier.d.ts +10 -0
- package/dist/chat/earlier.d.ts.map +1 -0
- package/dist/chat/earlier.js +54 -0
- package/dist/chat/house.d.ts +25 -0
- package/dist/chat/house.d.ts.map +1 -0
- package/dist/chat/house.js +38 -0
- package/dist/chat/input.d.ts +3 -1
- package/dist/chat/input.d.ts.map +1 -1
- package/dist/chat/input.js +11 -18
- package/dist/chat/list.d.ts +2 -1
- package/dist/chat/list.d.ts.map +1 -1
- package/dist/chat/list.js +45 -5
- package/dist/chat/markdown.d.ts +1 -0
- package/dist/chat/markdown.d.ts.map +1 -1
- package/dist/chat/markdown.js +78 -20
- package/dist/chat/message.d.ts +1 -0
- package/dist/chat/message.d.ts.map +1 -1
- package/dist/chat/message.js +73 -11
- package/dist/chat/messages.d.ts +14 -1
- package/dist/chat/messages.d.ts.map +1 -1
- package/dist/chat/messages.js +79 -24
- package/dist/chat/name.d.ts +1 -0
- package/dist/chat/name.d.ts.map +1 -1
- package/dist/chat/name.js +1 -1
- package/dist/chat/opened.d.ts +1 -0
- package/dist/chat/opened.d.ts.map +1 -1
- package/dist/chat/opened.js +2 -0
- package/dist/chat/overlay.d.ts +1 -0
- package/dist/chat/overlay.d.ts.map +1 -1
- package/dist/chat/overlay.js +11 -5
- package/dist/chat/parts.d.ts +1 -0
- package/dist/chat/parts.d.ts.map +1 -1
- package/dist/chat/parts.js +3 -2
- package/dist/chat/pieces.d.ts +62 -0
- package/dist/chat/pieces.d.ts.map +1 -0
- package/dist/chat/pieces.js +1110 -0
- package/dist/chat/provider.d.ts +8 -1
- package/dist/chat/provider.d.ts.map +1 -1
- package/dist/chat/provider.js +98 -92
- package/dist/chat/question.d.ts +1 -1
- package/dist/chat/question.d.ts.map +1 -1
- package/dist/chat/question.js +7 -18
- package/dist/chat/ready.d.ts +5 -2
- package/dist/chat/ready.d.ts.map +1 -1
- package/dist/chat/ready.js +7 -5
- package/dist/chat/room-file.d.ts +8 -0
- package/dist/chat/room-file.d.ts.map +1 -0
- package/dist/chat/room-file.js +72 -0
- package/dist/chat/steady.d.ts +3 -0
- package/dist/chat/steady.d.ts.map +1 -0
- package/dist/chat/steady.js +26 -0
- package/dist/chat/style.d.ts.map +1 -1
- package/dist/chat/style.js +6 -1
- package/dist/chat.d.ts +3 -2
- package/dist/chat.d.ts.map +1 -1
- package/dist/chat.js +2 -2
- package/dist/client.d.ts +11 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +45 -7
- package/dist/collection.d.ts +6 -19
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +30 -287
- package/dist/compile.d.ts +11 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +712 -0
- package/dist/connection.d.ts +21 -8
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +2319 -688
- package/dist/conversation.d.ts +15 -3
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +233 -80
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/durability.d.ts +2 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +3 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +18 -23
- package/dist/file.d.ts +2 -10
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -120
- package/dist/host.d.ts +5 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +55 -7
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/live.d.ts +22 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +123 -0
- package/dist/memory.d.ts +7 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +39 -17
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +14 -0
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +93 -3
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/outcome.d.ts +35 -4
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +28 -0
- package/dist/overlay.d.ts +2 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +86 -171
- package/dist/query.d.ts +26 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +34 -6
- package/dist/reach.d.ts +5 -1
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +167 -48
- package/dist/react.d.ts +1 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +2 -14
- package/dist/readiness.d.ts +1 -1
- package/dist/readiness.d.ts.map +1 -1
- package/dist/reads.d.ts +11 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +98 -0
- package/dist/recovery.d.ts +2 -2
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +8 -7
- package/dist/refresh.d.ts +12 -15
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +74 -51
- package/dist/replica.d.ts +55 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +295 -186
- package/dist/room-draft.d.ts +3 -1
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +29 -22
- package/dist/rows.d.ts +29 -30
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +113 -64
- package/dist/save.d.ts +51 -14
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +518 -180
- package/dist/search.d.ts +19 -4
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +192 -35
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +75 -0
- package/dist/shared.d.ts +8 -3
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +129 -66
- package/dist/store.d.ts +99 -71
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +461 -586
- package/dist/stored.d.ts +143 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +561 -0
- package/dist/tables.d.ts +320 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +537 -0
- package/dist/turn.d.ts +5 -3
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +51 -21
- package/dist/validation.d.ts +30 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +162 -0
- package/dist/windows.d.ts +22 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +89 -0
- package/dist/wire.d.ts +32 -0
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +8 -0
- package/package.json +10 -3
- package/dist/acquisition.d.ts +0 -14
- package/dist/acquisition.d.ts.map +0 -1
- package/dist/acquisition.js +0 -24
- package/dist/read-side.d.ts +0 -25
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -642
package/dist/chat/list.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useContext, } from 'react';
|
|
3
|
-
import { ThreadPrimitive } from '@assistant-ui/react';
|
|
2
|
+
import { createContext, useContext, useEffect, useRef, } from 'react';
|
|
3
|
+
import { ThreadPrimitive, useAui } from '@assistant-ui/react';
|
|
4
4
|
import Check from 'lucide-react/dist/esm/icons/check.mjs';
|
|
5
5
|
import MessageSquare from 'lucide-react/dist/esm/icons/message-square.mjs';
|
|
6
6
|
import SquarePen from 'lucide-react/dist/esm/icons/square-pen.mjs';
|
|
7
7
|
import { Name, Scoped, Working } from './kit.js';
|
|
8
|
-
import { AssistantMessage, Linked, UserMessage } from './message.js';
|
|
9
|
-
import { awaitsTurn } from './messages.js';
|
|
8
|
+
import { AssistantMessage, HouseMessage, Linked, UserMessage } from './message.js';
|
|
10
9
|
import { ChatName } from './name.js';
|
|
11
10
|
import { useOpened } from './opened.js';
|
|
12
11
|
import { ChatQuestionCard } from './question.js';
|
|
13
12
|
export const Described = createContext({});
|
|
13
|
+
const EARLIER_MARGIN = 240;
|
|
14
14
|
function Chip({ agent, name, on, start, }) {
|
|
15
15
|
const { agentMark, agentDetail, AgentLink } = useContext(Described);
|
|
16
16
|
const content = (_jsxs(_Fragment, { children: [agentMark?.(agent, 16), _jsx(Name, { text: name }), agentDetail === undefined ? null : _jsx(Name, { text: agentDetail(agent), className: "ahc-meta" })] }));
|
|
@@ -26,12 +26,52 @@ function Empty() {
|
|
|
26
26
|
export function ChatMessageList({ components = {}, onLink, footer, waiting, children, }) {
|
|
27
27
|
const chat = useOpened();
|
|
28
28
|
const linked = useContext(Linked);
|
|
29
|
+
const aui = useAui();
|
|
30
|
+
const viewport = useRef(null);
|
|
31
|
+
const content = useRef(null);
|
|
32
|
+
const anchor = useRef(null);
|
|
33
|
+
const first = chat.view?.messages[0]?.identity;
|
|
34
|
+
const shownFirst = useRef(first);
|
|
35
|
+
shownFirst.current = first;
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const element = viewport.current;
|
|
38
|
+
const inner = content.current;
|
|
39
|
+
if (element === null || inner === null)
|
|
40
|
+
return;
|
|
41
|
+
const kept = new ResizeObserver(() => {
|
|
42
|
+
const held = anchor.current;
|
|
43
|
+
if (held === null || held.first === shownFirst.current)
|
|
44
|
+
return;
|
|
45
|
+
if (element.scrollHeight === held.height)
|
|
46
|
+
return;
|
|
47
|
+
anchor.current = null;
|
|
48
|
+
element.scrollTop += element.scrollHeight - held.height;
|
|
49
|
+
});
|
|
50
|
+
kept.observe(inner);
|
|
51
|
+
return () => kept.disconnect();
|
|
52
|
+
}, []);
|
|
53
|
+
const earlier = () => {
|
|
54
|
+
const element = viewport.current;
|
|
55
|
+
if (element === null || element.scrollTop > EARLIER_MARGIN)
|
|
56
|
+
return;
|
|
57
|
+
const thread = aui.thread();
|
|
58
|
+
const state = thread.getState();
|
|
59
|
+
if (!state.hasEarlier || state.isLoadingEarlier)
|
|
60
|
+
return;
|
|
61
|
+
anchor.current = { height: element.scrollHeight, first };
|
|
62
|
+
void thread.loadEarlier();
|
|
63
|
+
};
|
|
64
|
+
const line = waiting?.(chat) ?? null;
|
|
29
65
|
const User = components.UserMessage ?? UserMessage;
|
|
30
66
|
const Assistant = components.AssistantMessage ?? AssistantMessage;
|
|
31
67
|
const silent = chat.view === null
|
|
32
68
|
? chat.conversation === null
|
|
33
69
|
: chat.view.messages.length === 0 && chat.view.turn === null;
|
|
34
|
-
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: [
|
|
70
|
+
return (_jsx(Scoped, { children: _jsx(Linked.Provider, { value: onLink ?? linked, children: _jsx(ThreadPrimitive.Root, { className: "ahc-thread", children: _jsxs(ThreadPrimitive.Viewport, { className: "ahc-viewport", ref: viewport, onScroll: earlier, children: [_jsxs("div", { className: "ahc-column ahc-messages", ref: content, children: [chat.renewed ? (_jsx("p", { role: "note", className: "ahc-meta", children: "New chat started" })) : null, silent ? _jsx(Empty, {}) : null, _jsx(ThreadPrimitive.Messages, { components: {
|
|
71
|
+
UserMessage: User,
|
|
72
|
+
AssistantMessage: Assistant,
|
|
73
|
+
SystemMessage: HouseMessage,
|
|
74
|
+
} }), line === null ? null : (_jsx("div", { className: "ahc-turn", children: _jsx(Working, { label: line }) })), children === undefined
|
|
35
75
|
? chat.questions.map((question) => (_jsx(ChatQuestionCard, { question: question }, question.interaction)))
|
|
36
76
|
: children] }), footer === undefined ? null : (_jsx(ThreadPrimitive.ViewportFooter, { className: "ahc-column ahc-footer", children: footer }))] }) }) }) }));
|
|
37
77
|
}
|
package/dist/chat/markdown.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ interface MarkdownOptions {
|
|
|
11
11
|
}
|
|
12
12
|
export declare function slugOf(text: string): string;
|
|
13
13
|
export declare function anchorOf(fragment: string): string;
|
|
14
|
+
export declare function revealed(anchor: string): HTMLElement | null;
|
|
14
15
|
export declare function plainText(text: string): string;
|
|
15
16
|
export type MarkdownProps = MarkdownOptions & {
|
|
16
17
|
readonly text: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/chat/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/chat/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAYf,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;IAClD,QAAQ,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,SAAS,CAAC;CAChF;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;AAkED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAK3D;AA4JD,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,CAgDrF"}
|
package/dist/chat/markdown.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { createElement, Fragment } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { gfm } from 'micromark-extension-gfm';
|
|
1
|
+
import { createElement, Fragment, useEffect, useMemo, useRef, useState, } from 'react';
|
|
2
|
+
import { flushSync } from 'react-dom';
|
|
3
|
+
import { drawn, longOf, parseMarkdown, pieceAt, remaining, } from './pieces.js';
|
|
5
4
|
function unfiled(options) {
|
|
6
|
-
const { definitions,
|
|
7
|
-
return onLink === undefined ? { definitions,
|
|
5
|
+
const { definitions, ids, onLink } = options;
|
|
6
|
+
return onLink === undefined ? { definitions, ids } : { definitions, ids, onLink };
|
|
8
7
|
}
|
|
9
8
|
export function slugOf(text) {
|
|
10
9
|
return text
|
|
@@ -42,9 +41,6 @@ function referenced(file, text, key) {
|
|
|
42
41
|
parts.push(text.slice(from));
|
|
43
42
|
return createElement(Fragment, { key }, ...parts);
|
|
44
43
|
}
|
|
45
|
-
function parseMarkdown(text) {
|
|
46
|
-
return fromMarkdown(text, { extensions: [gfm()], mdastExtensions: [gfmFromMarkdown()] });
|
|
47
|
-
}
|
|
48
44
|
function safeHref(url) {
|
|
49
45
|
const href = url.replace(/[\t\n\r]/g, '').replace(/^[\u0000-\u0020]+|[\u0000-\u0020]+$/g, '');
|
|
50
46
|
if (href === '' || /^[\\/]{2}/.test(href))
|
|
@@ -65,13 +61,32 @@ function textOf(node) {
|
|
|
65
61
|
return node.children.map(textOf).join('');
|
|
66
62
|
return '';
|
|
67
63
|
}
|
|
68
|
-
function
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
function headingIds(nodes, slugs, ids) {
|
|
65
|
+
for (const node of nodes) {
|
|
66
|
+
if (node.type === 'heading')
|
|
67
|
+
ids.set(node, headingId(slugs, textOf(node)));
|
|
68
|
+
else if (node.type === 'blockquote' || node.type === 'list' || node.type === 'listItem') {
|
|
69
|
+
headingIds(node.children, slugs, ids);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const revealers = new Set();
|
|
74
|
+
export function revealed(anchor) {
|
|
75
|
+
const heading = document.getElementById(anchor);
|
|
76
|
+
if (heading !== null)
|
|
77
|
+
return heading;
|
|
78
|
+
for (const reveal of revealers)
|
|
79
|
+
if (reveal(anchor))
|
|
80
|
+
return document.getElementById(anchor);
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
function fragmentOf(href) {
|
|
84
|
+
try {
|
|
85
|
+
return decodeURIComponent(href.slice(1));
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return href.slice(1);
|
|
89
|
+
}
|
|
75
90
|
}
|
|
76
91
|
function link(url, node, key, options) {
|
|
77
92
|
if (whole(options.file, url)) {
|
|
@@ -83,7 +98,8 @@ function link(url, node, key, options) {
|
|
|
83
98
|
return createElement(Fragment, { key }, ...inside);
|
|
84
99
|
const onLink = options.onLink;
|
|
85
100
|
if (external(href) || onLink === undefined) {
|
|
86
|
-
|
|
101
|
+
const onClick = href.startsWith('#') ? () => revealed(fragmentOf(href)) : undefined;
|
|
102
|
+
return createElement('a', { key, href, rel: 'noreferrer', onClick }, ...inside);
|
|
87
103
|
}
|
|
88
104
|
return createElement('a', {
|
|
89
105
|
key,
|
|
@@ -104,7 +120,7 @@ function render(node, key, options, header = false) {
|
|
|
104
120
|
case 'paragraph':
|
|
105
121
|
return createElement('p', { key }, ...children());
|
|
106
122
|
case 'heading':
|
|
107
|
-
return createElement(`h${node.depth}`, { key, id:
|
|
123
|
+
return createElement(`h${node.depth}`, { key, id: options.ids.get(node) }, ...children());
|
|
108
124
|
case 'text':
|
|
109
125
|
return options.file === undefined ? node.value : referenced(options.file, node.value, key);
|
|
110
126
|
case 'emphasis':
|
|
@@ -183,6 +199,48 @@ export function plainText(text) {
|
|
|
183
199
|
return spokenOf(parseMarkdown(text)).replace(/\s+/g, ' ').trim();
|
|
184
200
|
}
|
|
185
201
|
export function Markdown({ text, className, ...options }) {
|
|
186
|
-
const
|
|
187
|
-
|
|
202
|
+
const long = useMemo(() => longOf(text), [text]);
|
|
203
|
+
const [shown, setShown] = useState(1);
|
|
204
|
+
const more = useRef(null);
|
|
205
|
+
const nodes = drawn(long, shown);
|
|
206
|
+
const showing = Math.min(shown, long.pieces.length);
|
|
207
|
+
const rest = remaining(long, showing);
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
const sentinel = more.current;
|
|
210
|
+
if (sentinel === null)
|
|
211
|
+
return;
|
|
212
|
+
const watcher = new IntersectionObserver((seen) => {
|
|
213
|
+
if (seen.some((one) => one.isIntersecting))
|
|
214
|
+
setShown(showing + 1);
|
|
215
|
+
}, { rootMargin: '0px 0px 100% 0px' });
|
|
216
|
+
watcher.observe(sentinel);
|
|
217
|
+
return () => watcher.disconnect();
|
|
218
|
+
}, [showing, long]);
|
|
219
|
+
useEffect(() => {
|
|
220
|
+
if (!rest)
|
|
221
|
+
return;
|
|
222
|
+
const reveal = (anchor) => {
|
|
223
|
+
const slugs = new Map();
|
|
224
|
+
for (let index = 0;; index += 1) {
|
|
225
|
+
const piece = pieceAt(long, index);
|
|
226
|
+
if (piece === null)
|
|
227
|
+
return false;
|
|
228
|
+
const ids = new Map();
|
|
229
|
+
headingIds(piece.nodes, slugs, ids);
|
|
230
|
+
if ([...ids.values()].includes(anchor)) {
|
|
231
|
+
if (index >= showing)
|
|
232
|
+
flushSync(() => setShown(index + 1));
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
revealers.add(reveal);
|
|
238
|
+
return () => {
|
|
239
|
+
revealers.delete(reveal);
|
|
240
|
+
};
|
|
241
|
+
}, [showing, long, rest]);
|
|
242
|
+
const ids = new Map();
|
|
243
|
+
headingIds(nodes, new Map(), ids);
|
|
244
|
+
const rendering = { ...options, definitions: long.urls, ids };
|
|
245
|
+
return createElement('div', { className }, ...nodes.map((node, at) => render(node, at, rendering)), rest ? createElement('div', { key: 'more', ref: more }) : null);
|
|
188
246
|
}
|
package/dist/chat/message.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ReactElement } from 'react';
|
|
2
2
|
export declare const Linked: import("react").Context<((href: string) => void) | null>;
|
|
3
3
|
export declare function UserMessage(): ReactElement;
|
|
4
|
+
export declare function HouseMessage(): ReactElement;
|
|
4
5
|
export declare function Undelivered(): ReactElement;
|
|
5
6
|
export declare function AssistantMessage(): ReactElement;
|
|
6
7
|
//# sourceMappingURL=message.d.ts.map
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/chat/message.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,YAAY,EAElB,MAAM,OAAO,CAAC;AAuCf,eAAO,MAAM,MAAM,kCAAyB,MAAM,KAAK,IAAI,SAAe,CAAC;AAiR3E,wBAAgB,WAAW,IAAI,YAAY,CAkB1C;AAuCD,wBAAgB,YAAY,IAAI,YAAY,CAW3C;AAkCD,wBAAgB,WAAW,IAAI,YAAY,CAE1C;AAED,wBAAgB,gBAAgB,IAAI,YAAY,CAiG/C"}
|
package/dist/chat/message.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useContext, } from 'react';
|
|
3
|
-
import { ActionBarPrimitive, AuiIf, ErrorPrimitive,
|
|
3
|
+
import { ActionBarPrimitive, AuiIf, ErrorPrimitive, MessagePrimitive, groupPartByType, useAuiState, } from '@assistant-ui/react';
|
|
4
4
|
import { MarkdownTextPrimitive } from '@assistant-ui/react-markdown';
|
|
5
5
|
import { Collapsible } from 'radix-ui';
|
|
6
6
|
import remarkGfm from 'remark-gfm';
|
|
@@ -15,14 +15,17 @@ import ImageGlyph from 'lucide-react/dist/esm/icons/image.mjs';
|
|
|
15
15
|
import Layers from 'lucide-react/dist/esm/icons/layers.mjs';
|
|
16
16
|
import ListChecks from 'lucide-react/dist/esm/icons/list-checks.mjs';
|
|
17
17
|
import ListTodo from 'lucide-react/dist/esm/icons/list-todo.mjs';
|
|
18
|
-
import Paperclip from 'lucide-react/dist/esm/icons/paperclip.mjs';
|
|
19
18
|
import RotateCw from 'lucide-react/dist/esm/icons/rotate-cw.mjs';
|
|
20
19
|
import Send from 'lucide-react/dist/esm/icons/send.mjs';
|
|
21
20
|
import SlidersHorizontal from 'lucide-react/dist/esm/icons/sliders-horizontal.mjs';
|
|
22
21
|
import Terminal from 'lucide-react/dist/esm/icons/terminal.mjs';
|
|
23
22
|
import { SESSION_STARTED } from '../conversation.js';
|
|
24
|
-
import { buttonClass,
|
|
23
|
+
import { buttonClass, Working } from './kit.js';
|
|
25
24
|
import { StillRunning } from './lasting.js';
|
|
25
|
+
import { stamp } from './name.js';
|
|
26
|
+
import { useOpened } from './opened.js';
|
|
27
|
+
import { useChat } from './provider.js';
|
|
28
|
+
import { isRoomPath, RoomFile } from './room-file.js';
|
|
26
29
|
import { list, record, text } from './read.js';
|
|
27
30
|
export const Linked = createContext(null);
|
|
28
31
|
const groupBy = groupPartByType({
|
|
@@ -136,7 +139,11 @@ function Thought({ indices, active, children, }) {
|
|
|
136
139
|
return (_jsx(Toggle, { icon: active ? now.icon : _jsx(ListChecks, { "aria-hidden": "true" }), label: active ? now.title : workedOf(calls), detail: active ? now.detail : '', active: active, children: children }));
|
|
137
140
|
}
|
|
138
141
|
const SCHEME = /^[a-z][a-z0-9+.-]*:/i;
|
|
139
|
-
|
|
142
|
+
const ROOM_LINK = /\[([^\]]*)\]\((\/rooms\/[^)\s]+)\)/gu;
|
|
143
|
+
function nameOf(href) {
|
|
144
|
+
return href.slice(href.lastIndexOf('/') + 1);
|
|
145
|
+
}
|
|
146
|
+
function Linking({ href, ...rest }) {
|
|
140
147
|
const onLink = useContext(Linked);
|
|
141
148
|
if (SCHEME.test(href) || onLink === null)
|
|
142
149
|
return _jsx("a", { ...rest, href: href, rel: "noreferrer" });
|
|
@@ -145,19 +152,74 @@ function Anchor({ node: _node, href = '', ...rest }) {
|
|
|
145
152
|
onLink(href);
|
|
146
153
|
} }));
|
|
147
154
|
}
|
|
155
|
+
function Anchor({ node: _node, href = '', ...rest }) {
|
|
156
|
+
const link = _jsx(Linking, { ...rest, href: href });
|
|
157
|
+
return isRoomPath(href) ? _jsx(RoomFile, { href: href, name: nameOf(href), otherwise: link }) : link;
|
|
158
|
+
}
|
|
148
159
|
const LINKED = { a: Anchor };
|
|
149
160
|
const THOUGHT = { className: 'ahc-thought' };
|
|
150
161
|
function Said({ thought = false }) {
|
|
151
|
-
return (_jsx(MarkdownTextPrimitive, { className: "ahc-text ahc-markdown", containerProps: thought ? THOUGHT : undefined, remarkPlugins: GFM, components: LINKED }));
|
|
162
|
+
return (_jsx(MarkdownTextPrimitive, { className: "ahc-text ahc-markdown", containerProps: thought ? THOUGHT : undefined, remarkPlugins: GFM, components: LINKED, smooth: false }));
|
|
152
163
|
}
|
|
153
|
-
function
|
|
154
|
-
return _jsx(
|
|
164
|
+
function Transcribed({ text: said }) {
|
|
165
|
+
return (_jsxs("span", { className: "ahc-transcript ahc-quiet", children: [_jsx("span", { className: "ahc-meta", children: "Transcript: " }), said] }));
|
|
166
|
+
}
|
|
167
|
+
function UserText({ text: said }) {
|
|
168
|
+
const transcripts = useAuiState((s) => s.message.metadata.custom.transcripts);
|
|
169
|
+
const pieces = [];
|
|
170
|
+
const shown = new Set();
|
|
171
|
+
let from = 0;
|
|
172
|
+
for (const found of said.matchAll(ROOM_LINK)) {
|
|
173
|
+
const [whole, , href] = found;
|
|
174
|
+
pieces.push(said.slice(from, found.index));
|
|
175
|
+
pieces.push(_jsx(RoomFile, { href: href, name: nameOf(href), otherwise: whole }, found.index));
|
|
176
|
+
const transcript = transcripts?.find((one) => one.path === href);
|
|
177
|
+
if (transcript !== undefined && !shown.has(href)) {
|
|
178
|
+
shown.add(href);
|
|
179
|
+
pieces.push(_jsx(Transcribed, { text: transcript.text }, `${found.index}:transcript`));
|
|
180
|
+
}
|
|
181
|
+
from = found.index + whole.length;
|
|
182
|
+
}
|
|
183
|
+
pieces.push(said.slice(from));
|
|
184
|
+
return _jsx("span", { className: "ahc-said", children: pieces });
|
|
155
185
|
}
|
|
156
186
|
export function UserMessage() {
|
|
157
187
|
const said = useAuiState((s) => s.message.parts.some((one) => one.type === 'text' && one.text !== ''));
|
|
158
|
-
const attached = useAuiState((s) => (s.message.attachments?.length ?? 0) > 0);
|
|
159
188
|
const undelivered = useAuiState((s) => s.message.metadata.custom.undelivered === true);
|
|
160
|
-
|
|
189
|
+
const unknown = useAuiState((s) => s.message.metadata.custom.unknown === true);
|
|
190
|
+
const id = useAuiState((s) => s.message.id);
|
|
191
|
+
return (_jsxs(MessagePrimitive.Root, { role: "group", "aria-label": "You", className: "ahc-you", children: [said ? (_jsx("div", { className: "ahc-bubble", children: _jsx(MessagePrimitive.Parts, { components: { Text: UserText } }) })) : null, undelivered ? _jsx(Undelivered, {}) : null, unknown ? _jsx(DeliveryUnknown, { message: id }) : null] }));
|
|
192
|
+
}
|
|
193
|
+
function From({ source }) {
|
|
194
|
+
if (source.kind === 'mail') {
|
|
195
|
+
return (_jsxs("div", { className: "ahc-house__from", children: [_jsx("span", { className: "ahc-house__title", children: "House \u00B7 Mail" }), _jsx("span", { className: "ahc-meta", children: `From ${source.agent} of ${source.owner}` })] }));
|
|
196
|
+
}
|
|
197
|
+
const { requester, room } = source;
|
|
198
|
+
return (_jsxs("div", { className: "ahc-house__from", children: [_jsx("span", { className: "ahc-house__title", children: `House · ${source.routine} v${source.version}` }), _jsx("span", { className: "ahc-meta", children: requester.room ? `From ${requester.name}` : `From ${requester.name} in ${room.name}` })] }));
|
|
199
|
+
}
|
|
200
|
+
function Decided({ source, waiting, }) {
|
|
201
|
+
if (source.kind !== 'request')
|
|
202
|
+
return null;
|
|
203
|
+
if (waiting)
|
|
204
|
+
return _jsx("span", { className: "ahc-meta", children: "Waits for your approval" });
|
|
205
|
+
if (source.approved === null)
|
|
206
|
+
return null;
|
|
207
|
+
return (_jsxs("span", { className: "ahc-meta", children: ["Approved ", _jsx("time", { dateTime: source.approved, children: stamp(source.approved) })] }));
|
|
208
|
+
}
|
|
209
|
+
export function HouseMessage() {
|
|
210
|
+
const custom = useAuiState((s) => s.message.metadata.custom);
|
|
211
|
+
const source = (custom.source ?? null);
|
|
212
|
+
return (_jsxs(MessagePrimitive.Root, { role: "group", "aria-label": "House", className: "ahc-house", children: [source === null ? null : _jsx(From, { source: source }), _jsx(MessagePrimitive.Parts, { components: { Text: UserText } }), source === null ? null : _jsx(Decided, { source: source, waiting: custom.waiting === true }), custom.undelivered === true ? _jsx(Undelivered, {}) : null] }));
|
|
213
|
+
}
|
|
214
|
+
function DeliveryUnknown({ message }) {
|
|
215
|
+
const chat = useChat();
|
|
216
|
+
return (_jsxs("span", { className: "ahc-meta", children: ["Delivery unknown", _jsx("button", { type: "button", className: buttonClass('outline', true, false), disabled: chat.acting.busy, onClick: () => void chat.retry(message), children: "Retry" })] }));
|
|
217
|
+
}
|
|
218
|
+
function Renew() {
|
|
219
|
+
const chat = useOpened();
|
|
220
|
+
if (chat.deleted)
|
|
221
|
+
return null;
|
|
222
|
+
return (_jsx("button", { type: "button", className: buttonClass('outline', true, false), disabled: chat.acting.busy, onClick: () => void chat.renew(), children: "Start new chat" }));
|
|
161
223
|
}
|
|
162
224
|
export function Undelivered() {
|
|
163
225
|
return _jsx("span", { className: "ahc-meta", children: "Telegram didn't receive this" });
|
|
@@ -182,11 +244,11 @@ export function AssistantMessage() {
|
|
|
182
244
|
case 'tool-call':
|
|
183
245
|
return _jsx(ToolCall, { call: part, active: part.status.type === 'running' });
|
|
184
246
|
case 'file':
|
|
185
|
-
return (_jsxs("div", { className: "ahc-toolline ahc-quiet", children: [_jsx(ImageGlyph, { "aria-hidden": "true" }), _jsx("span", { className: "ahc-clipped", children: part.filename })] }));
|
|
247
|
+
return (_jsx(RoomFile, { href: part.data, name: part.filename ?? nameOf(part.data), otherwise: _jsxs("div", { className: "ahc-toolline ahc-quiet", children: [_jsx(ImageGlyph, { "aria-hidden": "true" }), _jsx("span", { className: "ahc-clipped", children: part.filename })] }) }));
|
|
186
248
|
case 'indicator':
|
|
187
249
|
return _jsx(Working, { step: started ? SESSION_STARTED : undefined });
|
|
188
250
|
default:
|
|
189
251
|
return null;
|
|
190
252
|
}
|
|
191
|
-
} }), _jsx(MessagePrimitive.Error, { children: _jsxs(ErrorPrimitive.Root, { className: "ahc-failure", children: [_jsx(ErrorPrimitive.Message, {}), _jsx(AuiIf, { condition: (s) => s.thread.capabilities.reload && s.message.metadata.custom.again === true, children: _jsx(ActionBarPrimitive.Reload, { className: buttonClass('outline', true, false), children: "Try again" }) })] }) }), custom.undelivered === true ? _jsx(Undelivered, {}) : null, said ? (_jsx(ActionBarPrimitive.Root, { hideWhenRunning: true, autohide: "not-last", autohideFloat: "always", className: last ? 'ahc-actions' : 'ahc-actions ahc-actions--floating', children: _jsxs(ActionBarPrimitive.Copy, { className: `${buttonClass('quiet', true, true)} ahc-secondary`, "aria-label": "Copy", children: [_jsx(AuiIf, { condition: (s) => s.message.isCopied, children: _jsx(Check, { "aria-hidden": "true" }) }), _jsx(AuiIf, { condition: (s) => !s.message.isCopied, children: _jsx(Copy, { "aria-hidden": "true" }) })] }) })) : null, lasting.length === 0 ? null : _jsx(StillRunning, { lasting: lasting })] }));
|
|
253
|
+
} }), _jsx(MessagePrimitive.Error, { children: _jsxs(ErrorPrimitive.Root, { className: "ahc-failure", children: [_jsx(ErrorPrimitive.Message, {}), _jsx(AuiIf, { condition: (s) => s.thread.capabilities.reload && s.message.metadata.custom.again === true, children: _jsx(ActionBarPrimitive.Reload, { className: buttonClass('outline', true, false), children: "Try again" }) }), custom.renew === true ? _jsx(Renew, {}) : null] }) }), custom.undelivered === true ? _jsx(Undelivered, {}) : null, said ? (_jsx(ActionBarPrimitive.Root, { hideWhenRunning: true, autohide: "not-last", autohideFloat: "always", className: last ? 'ahc-actions' : 'ahc-actions ahc-actions--floating', children: _jsxs(ActionBarPrimitive.Copy, { className: `${buttonClass('quiet', true, true)} ahc-secondary`, "aria-label": "Copy", children: [_jsx(AuiIf, { condition: (s) => s.message.isCopied, children: _jsx(Check, { "aria-hidden": "true" }) }), _jsx(AuiIf, { condition: (s) => !s.message.isCopied, children: _jsx(Copy, { "aria-hidden": "true" }) })] }) })) : null, lasting.length === 0 ? null : _jsx(StillRunning, { lasting: lasting })] }));
|
|
192
254
|
}
|
package/dist/chat/messages.d.ts
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
import type { ThreadMessageLike } from '@assistant-ui/react';
|
|
2
2
|
import type { TurnContext } from '../adapter.js';
|
|
3
3
|
import type { ConversationView } from '../conversation.js';
|
|
4
|
+
import { type ChatRequest, type HouseSource } from './house.js';
|
|
4
5
|
import { type Part } from './parts.js';
|
|
5
6
|
type Entry = ConversationView['messages'][number];
|
|
7
|
+
export type Transcript = {
|
|
8
|
+
readonly path: string;
|
|
9
|
+
readonly text: string;
|
|
10
|
+
};
|
|
6
11
|
export type Said = {
|
|
7
12
|
readonly turn: string;
|
|
8
13
|
readonly user: boolean;
|
|
14
|
+
readonly house: boolean;
|
|
15
|
+
readonly source: HouseSource | null;
|
|
16
|
+
readonly waiting: boolean;
|
|
9
17
|
readonly text: string;
|
|
18
|
+
readonly transcripts: readonly Transcript[];
|
|
10
19
|
readonly parts: readonly Part[];
|
|
11
20
|
readonly context: TurnContext | null;
|
|
12
21
|
readonly failure: string | null;
|
|
22
|
+
readonly resumeRefused: boolean;
|
|
13
23
|
readonly undelivered: boolean;
|
|
14
|
-
readonly files: readonly string[];
|
|
15
24
|
};
|
|
16
25
|
export declare function saidOf(entry: Entry): Said;
|
|
17
26
|
export declare function awaitsTurn(view: ConversationView | null): boolean;
|
|
27
|
+
export declare function requestIn(view: ConversationView | null): {
|
|
28
|
+
readonly request: ChatRequest;
|
|
29
|
+
readonly waiting: boolean;
|
|
30
|
+
} | null;
|
|
18
31
|
export declare function askedBefore(view: ConversationView | null, id: string | null): string | null;
|
|
19
32
|
export declare function chatMessages(view: ConversationView | null): ThreadMessageLike[];
|
|
20
33
|
export declare function contextOf(view: ConversationView | null): TurnContext | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/chat/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAA0D,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAO/F,KAAK,KAAK,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAElD,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/chat/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAY,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAA0D,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAO/F,KAAK,KAAK,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAElD,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1E,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B,CAAC;AAaF,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAyBzC;AAiGD,wBAAgB,UAAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAAG,OAAO,CAKjE;AAED,wBAAgB,SAAS,CACvB,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAC5B;IAAE,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAOrE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAO3F;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAAG,iBAAiB,EAAE,CAiE/E;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAAG,WAAW,GAAG,IAAI,CAS3E"}
|
package/dist/chat/messages.js
CHANGED
|
@@ -1,17 +1,50 @@
|
|
|
1
|
+
import { sourceOf } from './house.js';
|
|
1
2
|
import { contextIn, jobOf, partsOf, stillRunning } from './parts.js';
|
|
2
3
|
import { list, record, text } from './read.js';
|
|
4
|
+
const SAID = new WeakMap();
|
|
5
|
+
const CONVERTED = new WeakMap();
|
|
3
6
|
export function saidOf(entry) {
|
|
7
|
+
const held = SAID.get(entry);
|
|
8
|
+
if (held !== undefined)
|
|
9
|
+
return held;
|
|
4
10
|
const message = record(entry.message);
|
|
5
|
-
|
|
11
|
+
const house = text(message, 'role') === 'house';
|
|
12
|
+
const said = {
|
|
6
13
|
turn: text(message, 'turn_id') ?? entry.turn,
|
|
7
14
|
user: text(message, 'role') === 'user',
|
|
15
|
+
house,
|
|
16
|
+
source: house ? sourceOf(message.source) : null,
|
|
17
|
+
waiting: message.waiting === true,
|
|
8
18
|
text: text(message, 'text') ?? '',
|
|
19
|
+
transcripts: list(message, 'transcripts').flatMap((entry) => {
|
|
20
|
+
const path = text(record(entry), 'path');
|
|
21
|
+
const said = text(record(entry), 'text');
|
|
22
|
+
return path === null || said === null ? [] : [{ path, text: said }];
|
|
23
|
+
}),
|
|
9
24
|
parts: partsOf(list(message, 'parts')),
|
|
10
25
|
context: contextIn(message.context),
|
|
11
26
|
failure: text(message, 'failure'),
|
|
27
|
+
resumeRefused: message.resume_refused === true,
|
|
12
28
|
undelivered: message.telegram_undelivered === true,
|
|
13
|
-
files: list(message, 'files').flatMap((one) => text(record(one), 'name') ?? []),
|
|
14
29
|
};
|
|
30
|
+
SAID.set(entry, said);
|
|
31
|
+
return said;
|
|
32
|
+
}
|
|
33
|
+
function sameWork(held, now) {
|
|
34
|
+
return (held.length === now.length &&
|
|
35
|
+
held.every((one, at) => one.kind === now[at].kind && one.title === now[at].title && one.next === now[at].next));
|
|
36
|
+
}
|
|
37
|
+
function converted(entry, lasting, again, unknown, convert) {
|
|
38
|
+
const held = CONVERTED.get(entry);
|
|
39
|
+
if (held !== undefined &&
|
|
40
|
+
held.again === again &&
|
|
41
|
+
held.unknown === unknown &&
|
|
42
|
+
sameWork(held.lasting, lasting)) {
|
|
43
|
+
return held.message;
|
|
44
|
+
}
|
|
45
|
+
const message = convert();
|
|
46
|
+
CONVERTED.set(entry, { lasting, again, unknown, message });
|
|
47
|
+
return message;
|
|
15
48
|
}
|
|
16
49
|
function markerArgs(part) {
|
|
17
50
|
if (part.marker !== 'job')
|
|
@@ -58,7 +91,7 @@ function contentOf(id, parts, live) {
|
|
|
58
91
|
args: { steps: part.steps.map((step) => ({ ...step })) },
|
|
59
92
|
};
|
|
60
93
|
case 'image':
|
|
61
|
-
return { type: 'file', filename: part.name, mimeType: part.mediaType, data:
|
|
94
|
+
return { type: 'file', filename: part.name, mimeType: part.mediaType, data: part.path };
|
|
62
95
|
}
|
|
63
96
|
});
|
|
64
97
|
}
|
|
@@ -67,7 +100,7 @@ function leftRunning(view) {
|
|
|
67
100
|
return new Map();
|
|
68
101
|
const turns = view.messages.flatMap((entry) => {
|
|
69
102
|
const one = saidOf(entry);
|
|
70
|
-
return one.user ? [] : [{ turn: one.turn, parts: one.parts, ended: true }];
|
|
103
|
+
return one.user || one.house ? [] : [{ turn: one.turn, parts: one.parts, ended: true }];
|
|
71
104
|
});
|
|
72
105
|
return stillRunning(view.turn === null
|
|
73
106
|
? turns
|
|
@@ -75,15 +108,26 @@ function leftRunning(view) {
|
|
|
75
108
|
}
|
|
76
109
|
export function awaitsTurn(view) {
|
|
77
110
|
const newest = view?.messages.at(-1);
|
|
78
|
-
|
|
111
|
+
if (view?.turn !== null || newest === undefined)
|
|
112
|
+
return false;
|
|
113
|
+
const said = saidOf(newest);
|
|
114
|
+
return said.user || (said.house && !said.waiting);
|
|
115
|
+
}
|
|
116
|
+
export function requestIn(view) {
|
|
117
|
+
for (const entry of view?.messages ?? []) {
|
|
118
|
+
const { waiting, source } = saidOf(entry);
|
|
119
|
+
if (source?.kind === 'request')
|
|
120
|
+
return { request: { request: source.request, room: source.room.ref }, waiting };
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
79
123
|
}
|
|
80
124
|
export function askedBefore(view, id) {
|
|
81
125
|
const said = (view?.messages ?? []).map((entry) => ({ ...saidOf(entry), id: entry.identity }));
|
|
82
126
|
const asked = said
|
|
83
127
|
.slice(0, said.findIndex((one) => one.id === id) + 1)
|
|
84
128
|
.reverse()
|
|
85
|
-
.find((one) => one.user);
|
|
86
|
-
return asked === undefined || asked.text === '' ? null : asked.text;
|
|
129
|
+
.find((one) => one.user || one.house);
|
|
130
|
+
return asked === undefined || asked.house || asked.text === '' ? null : asked.text;
|
|
87
131
|
}
|
|
88
132
|
export function chatMessages(view) {
|
|
89
133
|
if (view === null)
|
|
@@ -92,25 +136,38 @@ export function chatMessages(view) {
|
|
|
92
136
|
const said = view.messages.map((entry, at) => {
|
|
93
137
|
const one = saidOf(entry);
|
|
94
138
|
const custom = { undelivered: one.undelivered };
|
|
139
|
+
if (one.house)
|
|
140
|
+
return converted(entry, [], false, false, () => ({
|
|
141
|
+
id: entry.identity,
|
|
142
|
+
role: 'system',
|
|
143
|
+
content: [{ type: 'text', text: one.text }],
|
|
144
|
+
metadata: {
|
|
145
|
+
custom: {
|
|
146
|
+
...custom,
|
|
147
|
+
source: one.source,
|
|
148
|
+
waiting: one.waiting,
|
|
149
|
+
transcripts: one.transcripts,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
}));
|
|
95
153
|
if (one.user) {
|
|
96
|
-
|
|
154
|
+
const unknown = view.deliveryUnknown.includes(entry.identity);
|
|
155
|
+
return converted(entry, [], false, unknown, () => ({
|
|
97
156
|
id: entry.identity,
|
|
98
157
|
role: 'user',
|
|
99
158
|
content: [{ type: 'text', text: one.text }],
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
type: 'file',
|
|
103
|
-
name,
|
|
104
|
-
status: { type: 'complete' },
|
|
105
|
-
content: [],
|
|
106
|
-
})),
|
|
107
|
-
metadata: { custom },
|
|
108
|
-
};
|
|
159
|
+
metadata: { custom: { ...custom, unknown, transcripts: one.transcripts } },
|
|
160
|
+
}));
|
|
109
161
|
}
|
|
110
162
|
const failed = one.failure === null
|
|
111
163
|
? undefined
|
|
112
164
|
: { type: 'incomplete', reason: 'error', error: one.failure };
|
|
113
|
-
|
|
165
|
+
const working = lasting.get(one.turn) ?? [];
|
|
166
|
+
const again = failed !== undefined &&
|
|
167
|
+
view.turn === null &&
|
|
168
|
+
at === view.messages.length - 1 &&
|
|
169
|
+
askedBefore(view, view.messages[at - 1]?.identity ?? null) !== null;
|
|
170
|
+
return converted(entry, working, again, false, () => ({
|
|
114
171
|
id: entry.identity,
|
|
115
172
|
role: 'assistant',
|
|
116
173
|
content: contentOf(entry.identity, one.parts, false),
|
|
@@ -118,14 +175,12 @@ export function chatMessages(view) {
|
|
|
118
175
|
metadata: {
|
|
119
176
|
custom: {
|
|
120
177
|
...custom,
|
|
121
|
-
lasting:
|
|
122
|
-
again
|
|
123
|
-
|
|
124
|
-
at === view.messages.length - 1 &&
|
|
125
|
-
askedBefore(view, view.messages[at - 1]?.identity ?? null) !== null,
|
|
178
|
+
lasting: working,
|
|
179
|
+
again,
|
|
180
|
+
renew: failed !== undefined && one.resumeRefused,
|
|
126
181
|
},
|
|
127
182
|
},
|
|
128
|
-
};
|
|
183
|
+
}));
|
|
129
184
|
});
|
|
130
185
|
if (view.turn === null)
|
|
131
186
|
return said;
|
package/dist/chat/name.d.ts
CHANGED
package/dist/chat/name.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"name.d.ts","sourceRoot":"","sources":["../../src/chat/name.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"name.d.ts","sourceRoot":"","sources":["../../src/chat/name.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAM1C,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAUxC;AAgBD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI7C;AAED,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,YAAY,CAc1E"}
|
package/dist/chat/name.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
const INSTANT = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})/g;
|
|
3
|
-
function stamp(at) {
|
|
3
|
+
export function stamp(at) {
|
|
4
4
|
const time = new Date(at);
|
|
5
5
|
return Number.isNaN(time.getTime())
|
|
6
6
|
? ''
|
package/dist/chat/opened.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opened.d.ts","sourceRoot":"","sources":["../../src/chat/opened.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"opened.d.ts","sourceRoot":"","sources":["../../src/chat/opened.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAEtE,MAAM,MAAM,MAAM,GAAG,SAAS,GAAG;IAC/B,QAAQ,CAAC,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC9C,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,wBAAgB,SAAS,IAAI,MAAM,CAgBlC"}
|