@agentshouse/mdruntime 0.1.0-cebcd51f70ed1 → 0.1.0-cec6690d5712e
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 +82 -27
- package/README.md +13 -3
- package/dist/adapter.d.ts +13 -3
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +15 -2
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +57 -0
- package/dist/bootstrap.d.ts +17 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +88 -35
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +13 -7
- package/dist/change.d.ts +4 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/chat/acts.d.ts +34 -0
- package/dist/chat/acts.d.ts.map +1 -0
- package/dist/chat/acts.js +36 -0
- package/dist/chat/context.d.ts +3 -0
- package/dist/chat/context.d.ts.map +1 -0
- package/dist/chat/context.js +10 -0
- package/dist/chat/input.d.ts +9 -0
- package/dist/chat/input.d.ts.map +1 -0
- package/dist/chat/input.js +99 -0
- package/dist/chat/kit.d.ts +60 -0
- package/dist/chat/kit.d.ts.map +1 -0
- package/dist/chat/kit.js +123 -0
- package/dist/chat/lasting.d.ts +6 -0
- package/dist/chat/lasting.d.ts.map +1 -0
- package/dist/chat/lasting.js +19 -0
- package/dist/chat/list.d.ts +20 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +59 -0
- package/dist/chat/markdown.d.ts +19 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +187 -0
- package/dist/chat/message.d.ts +6 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +192 -0
- package/dist/chat/messages.d.ts +21 -0
- package/dist/chat/messages.d.ts.map +1 -0
- package/dist/chat/messages.js +151 -0
- package/dist/chat/name.d.ts +6 -0
- package/dist/chat/name.d.ts.map +1 -0
- package/dist/chat/name.js +37 -0
- package/dist/chat/opened.d.ts +11 -0
- package/dist/chat/opened.d.ts.map +1 -0
- package/dist/chat/opened.js +17 -0
- package/dist/chat/overlay.d.ts +31 -0
- package/dist/chat/overlay.d.ts.map +1 -0
- package/dist/chat/overlay.js +97 -0
- package/dist/chat/parts.d.ts +57 -0
- package/dist/chat/parts.d.ts.map +1 -0
- package/dist/chat/parts.js +119 -0
- package/dist/chat/process.d.ts +20 -0
- package/dist/chat/process.d.ts.map +1 -0
- package/dist/chat/process.js +32 -0
- package/dist/chat/provider.d.ts +63 -0
- package/dist/chat/provider.d.ts.map +1 -0
- package/dist/chat/provider.js +645 -0
- package/dist/chat/question.d.ts +9 -0
- package/dist/chat/question.d.ts.map +1 -0
- package/dist/chat/question.js +80 -0
- package/dist/chat/questions.d.ts +31 -0
- package/dist/chat/questions.d.ts.map +1 -0
- package/dist/chat/questions.js +111 -0
- package/dist/chat/read.d.ts +5 -0
- package/dist/chat/read.d.ts.map +1 -0
- package/dist/chat/read.js +13 -0
- package/dist/chat/ready.d.ts +33 -0
- package/dist/chat/ready.d.ts.map +1 -0
- package/dist/chat/ready.js +91 -0
- package/dist/chat/style.d.ts +4 -0
- package/dist/chat/style.d.ts.map +1 -0
- package/dist/chat/style.js +302 -0
- package/dist/chat.d.ts +14 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +8 -0
- package/dist/client.d.ts +9 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +61 -15
- package/dist/collection.d.ts +6 -11
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +56 -19
- package/dist/connection.d.ts +14 -7
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +239 -102
- package/dist/conversation.d.ts +11 -3
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +47 -7
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/host.d.ts +1 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +5 -8
- package/dist/identity.d.ts +2 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +10 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/memory.d.ts +2 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +31 -11
- package/dist/model.d.ts +10 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +2 -0
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/outcome.d.ts +22 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +35 -1
- package/dist/overlay.d.ts +1 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +19 -15
- package/dist/query.d.ts +2 -0
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +5 -31
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +21 -19
- package/dist/react.d.ts +25 -16
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +8 -6
- package/dist/refresh.d.ts +10 -0
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +33 -24
- package/dist/replica.d.ts +5 -5
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +44 -29
- package/dist/room-draft.d.ts +8 -8
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +13 -22
- package/dist/rows.d.ts +2 -0
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +7 -1
- package/dist/save.d.ts +3 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +38 -21
- package/dist/search.d.ts +3 -2
- package/dist/search.d.ts.map +1 -1
- package/dist/status.d.ts +2 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -8
- package/dist/store.d.ts +25 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +206 -90
- package/dist/wire.d.ts +5 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +13 -2
- package/package.json +17 -9
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { contextIn, jobOf, partsOf, stillRunning } from './parts.js';
|
|
2
|
+
import { list, record, text } from './read.js';
|
|
3
|
+
export function saidOf(entry) {
|
|
4
|
+
const message = record(entry.message);
|
|
5
|
+
return {
|
|
6
|
+
turn: text(message, 'turn_id') ?? entry.turn,
|
|
7
|
+
user: text(message, 'role') === 'user',
|
|
8
|
+
text: text(message, 'text') ?? '',
|
|
9
|
+
parts: partsOf(list(message, 'parts')),
|
|
10
|
+
context: contextIn(message.context),
|
|
11
|
+
failure: text(message, 'failure'),
|
|
12
|
+
undelivered: message.telegram_undelivered === true,
|
|
13
|
+
files: list(message, 'files').flatMap((one) => text(record(one), 'name') ?? []),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function markerArgs(part) {
|
|
17
|
+
if (part.marker !== 'job')
|
|
18
|
+
return { marker: part.marker, text: part.text };
|
|
19
|
+
const job = jobOf(part.text);
|
|
20
|
+
return {
|
|
21
|
+
marker: part.marker,
|
|
22
|
+
text: part.text,
|
|
23
|
+
job: job.kind,
|
|
24
|
+
label: job.label,
|
|
25
|
+
state: job.state,
|
|
26
|
+
next: job.next ?? '',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function contentOf(id, parts, live) {
|
|
30
|
+
return parts.map((part, at) => {
|
|
31
|
+
const done = !live || at < parts.length - 1;
|
|
32
|
+
const call = (toolName, args) => ({
|
|
33
|
+
type: 'tool-call',
|
|
34
|
+
toolCallId: `${id}:${at}`,
|
|
35
|
+
toolName,
|
|
36
|
+
args,
|
|
37
|
+
result: done ? null : undefined,
|
|
38
|
+
});
|
|
39
|
+
switch (part.type) {
|
|
40
|
+
case 'text':
|
|
41
|
+
return { type: 'text', text: part.text };
|
|
42
|
+
case 'reasoning':
|
|
43
|
+
return { type: 'reasoning', text: part.text };
|
|
44
|
+
case 'commands':
|
|
45
|
+
return call('commands', { count: part.count });
|
|
46
|
+
case 'subagent':
|
|
47
|
+
return {
|
|
48
|
+
...call('subagent', { description: part.description }),
|
|
49
|
+
result: part.done ? part.result : undefined,
|
|
50
|
+
};
|
|
51
|
+
case 'message':
|
|
52
|
+
return call('message', { command: part.command, target: part.target ?? '' });
|
|
53
|
+
case 'marker':
|
|
54
|
+
return call('marker', markerArgs(part));
|
|
55
|
+
case 'plan':
|
|
56
|
+
return {
|
|
57
|
+
...call('plan', {}),
|
|
58
|
+
args: { steps: part.steps.map((step) => ({ ...step })) },
|
|
59
|
+
};
|
|
60
|
+
case 'image':
|
|
61
|
+
return { type: 'file', filename: part.name, mimeType: part.mediaType, data: '' };
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function leftRunning(view) {
|
|
66
|
+
if (view.process?.running === false)
|
|
67
|
+
return new Map();
|
|
68
|
+
const turns = view.messages.flatMap((entry) => {
|
|
69
|
+
const one = saidOf(entry);
|
|
70
|
+
return one.user ? [] : [{ turn: one.turn, parts: one.parts, ended: true }];
|
|
71
|
+
});
|
|
72
|
+
return stillRunning(view.turn === null
|
|
73
|
+
? turns
|
|
74
|
+
: [...turns, { turn: view.turn.turn, parts: partsOf(view.turn.parts), ended: false }]);
|
|
75
|
+
}
|
|
76
|
+
export function askedBefore(view, id) {
|
|
77
|
+
const said = (view?.messages ?? []).map((entry) => ({ ...saidOf(entry), id: entry.identity }));
|
|
78
|
+
const asked = said
|
|
79
|
+
.slice(0, said.findIndex((one) => one.id === id) + 1)
|
|
80
|
+
.reverse()
|
|
81
|
+
.find((one) => one.user);
|
|
82
|
+
return asked === undefined || asked.text === '' ? null : asked.text;
|
|
83
|
+
}
|
|
84
|
+
export function chatMessages(view) {
|
|
85
|
+
if (view === null)
|
|
86
|
+
return [];
|
|
87
|
+
const lasting = leftRunning(view);
|
|
88
|
+
const said = view.messages.map((entry, at) => {
|
|
89
|
+
const one = saidOf(entry);
|
|
90
|
+
const custom = { undelivered: one.undelivered };
|
|
91
|
+
if (one.user) {
|
|
92
|
+
return {
|
|
93
|
+
id: entry.identity,
|
|
94
|
+
role: 'user',
|
|
95
|
+
content: [{ type: 'text', text: one.text }],
|
|
96
|
+
attachments: one.files.map((name, at) => ({
|
|
97
|
+
id: `${entry.identity}:${at}`,
|
|
98
|
+
type: 'file',
|
|
99
|
+
name,
|
|
100
|
+
status: { type: 'complete' },
|
|
101
|
+
content: [],
|
|
102
|
+
})),
|
|
103
|
+
metadata: { custom },
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const failed = one.failure === null
|
|
107
|
+
? undefined
|
|
108
|
+
: { type: 'incomplete', reason: 'error', error: one.failure };
|
|
109
|
+
return {
|
|
110
|
+
id: entry.identity,
|
|
111
|
+
role: 'assistant',
|
|
112
|
+
content: contentOf(entry.identity, one.parts, false),
|
|
113
|
+
status: failed,
|
|
114
|
+
metadata: {
|
|
115
|
+
custom: {
|
|
116
|
+
...custom,
|
|
117
|
+
lasting: lasting.get(one.turn) ?? [],
|
|
118
|
+
again: failed !== undefined &&
|
|
119
|
+
view.turn === null &&
|
|
120
|
+
at === view.messages.length - 1 &&
|
|
121
|
+
askedBefore(view, view.messages[at - 1]?.identity ?? null) !== null,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
if (view.turn === null)
|
|
127
|
+
return said;
|
|
128
|
+
const running = `running:${view.turn.turn}`;
|
|
129
|
+
return [
|
|
130
|
+
...said,
|
|
131
|
+
{
|
|
132
|
+
id: running,
|
|
133
|
+
role: 'assistant',
|
|
134
|
+
content: contentOf(running, partsOf(view.turn.parts), true),
|
|
135
|
+
status: { type: 'running' },
|
|
136
|
+
},
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
export function contextOf(view) {
|
|
140
|
+
if (view === null)
|
|
141
|
+
return null;
|
|
142
|
+
const running = view.turn === null ? null : contextIn(view.turn.context);
|
|
143
|
+
if (running !== null)
|
|
144
|
+
return running;
|
|
145
|
+
for (const entry of [...view.messages].reverse()) {
|
|
146
|
+
const held = contextIn(record(entry.message).context);
|
|
147
|
+
if (held !== null)
|
|
148
|
+
return held;
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
@@ -0,0 +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;AAgC1C,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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
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) {
|
|
4
|
+
const time = new Date(at);
|
|
5
|
+
return Number.isNaN(time.getTime())
|
|
6
|
+
? ''
|
|
7
|
+
: time.toLocaleString('en-US', {
|
|
8
|
+
month: 'short',
|
|
9
|
+
day: 'numeric',
|
|
10
|
+
hour: '2-digit',
|
|
11
|
+
minute: '2-digit',
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function partsOf(name) {
|
|
15
|
+
const parts = [];
|
|
16
|
+
let from = 0;
|
|
17
|
+
for (const found of name.matchAll(INSTANT)) {
|
|
18
|
+
const shown = stamp(found[0]);
|
|
19
|
+
if (shown === '')
|
|
20
|
+
continue;
|
|
21
|
+
if (found.index > from)
|
|
22
|
+
parts.push({ text: name.slice(from, found.index), at: null });
|
|
23
|
+
parts.push({ text: shown, at: found[0] });
|
|
24
|
+
from = found.index + found[0].length;
|
|
25
|
+
}
|
|
26
|
+
if (from < name.length)
|
|
27
|
+
parts.push({ text: name.slice(from), at: null });
|
|
28
|
+
return parts;
|
|
29
|
+
}
|
|
30
|
+
export function readable(name) {
|
|
31
|
+
return partsOf(name)
|
|
32
|
+
.map((part) => part.text)
|
|
33
|
+
.join('');
|
|
34
|
+
}
|
|
35
|
+
export function ChatName({ name }) {
|
|
36
|
+
return (_jsx(_Fragment, { children: partsOf(name).map((part, at) => part.at === null ? (part.text) : (_jsx("time", { dateTime: part.at, children: part.text }, at))) }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ConversationEntry } from '../conversation.js';
|
|
2
|
+
import { type ChatState } from './provider.js';
|
|
3
|
+
export type Opened = ChatState & {
|
|
4
|
+
readonly entry: ConversationEntry | undefined;
|
|
5
|
+
readonly by: string | null;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly deleted: boolean;
|
|
8
|
+
readonly busy: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function useOpened(): Opened;
|
|
11
|
+
//# sourceMappingURL=opened.d.ts.map
|
|
@@ -0,0 +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;AAC5D,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;CACxB,CAAC;AAEF,wBAAgB,SAAS,IAAI,MAAM,CAelC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useChat, useChatScope } from './provider.js';
|
|
2
|
+
export function useOpened() {
|
|
3
|
+
const chat = useChat();
|
|
4
|
+
const { known } = useChatScope();
|
|
5
|
+
const entry = chat.conversations.find((one) => one.conversation === chat.conversation);
|
|
6
|
+
const by = entry?.agent.identity ?? chat.agent;
|
|
7
|
+
const live = chat.agents.find((one) => one.identity === by);
|
|
8
|
+
const asks = chat.view?.process?.running === true && chat.questions.length > 0;
|
|
9
|
+
return {
|
|
10
|
+
...chat,
|
|
11
|
+
entry,
|
|
12
|
+
by,
|
|
13
|
+
name: live?.name ?? entry?.agent.name ?? '',
|
|
14
|
+
deleted: known && chat.conversation !== null && by !== null && live === undefined,
|
|
15
|
+
busy: chat.running || asks,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ChatDraft, ConversationEntry, ConversationView } from '../conversation.js';
|
|
2
|
+
import { type ExpectedOf, type Expecting } from '../expectation.js';
|
|
3
|
+
type Entries = readonly ConversationEntry[];
|
|
4
|
+
export type Expectation = {
|
|
5
|
+
readonly key: string;
|
|
6
|
+
readonly view: 'conversation';
|
|
7
|
+
draw(held: ConversationView): ConversationView;
|
|
8
|
+
shown(held: ConversationView): boolean;
|
|
9
|
+
} | {
|
|
10
|
+
readonly key: string;
|
|
11
|
+
readonly view: 'conversations';
|
|
12
|
+
draw(held: Entries): Entries;
|
|
13
|
+
shown(held: Entries): boolean;
|
|
14
|
+
};
|
|
15
|
+
export type Expected = ExpectedOf<Expectation>;
|
|
16
|
+
export type Overlay = Omit<Expecting<Expectation>, 'expect' | 'heard' | 'drawn'> & {
|
|
17
|
+
expect(act: number, expected: Expected): void;
|
|
18
|
+
heard(held: ConversationView): void;
|
|
19
|
+
heardList(held: Entries): void;
|
|
20
|
+
conversation(held: ConversationView): ConversationView;
|
|
21
|
+
conversations(held: Entries): Entries;
|
|
22
|
+
};
|
|
23
|
+
export declare function overlay(): Overlay;
|
|
24
|
+
export declare function sentMessage(key: string, into: readonly string[], said: ChatDraft, turn: string | null): Expectation;
|
|
25
|
+
export declare function optionChosen(conversation: string, option: string, value: string): Expectation;
|
|
26
|
+
export declare function questionAnswered(conversation: string, interaction: string): Expectation;
|
|
27
|
+
export declare function conversationListed(entry: ConversationEntry): Expectation;
|
|
28
|
+
export declare function conversationChanged(conversation: string, changes: Partial<Pick<ConversationEntry, 'name' | 'finished'>>, shown: (entry: ConversationEntry) => boolean): Expectation;
|
|
29
|
+
export declare function conversationGone(conversation: string): Expectation;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=overlay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../src/chat/overlay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAa,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG/E,KAAK,OAAO,GAAG,SAAS,iBAAiB,EAAE,CAAC;AAE5C,MAAM,MAAM,WAAW,GACnB;IACE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,IAAI,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB,CAAC;IAC/C,KAAK,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC;CACxC,GACD;IACE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;IAC7B,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;CAC/B,CAAC;AAEN,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;AAE/C,MAAM,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC,GAAG;IACjF,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC9C,KAAK,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACpC,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAC/B,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB,CAAC;IACvD,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;CACvC,CAAC;AAEF,wBAAgB,OAAO,IAAI,OAAO,CAiBjC;AAED,wBAAgB,WAAW,CACzB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,MAAM,GAAG,IAAI,GAClB,WAAW,CA2Bb;AAED,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,CAkB7F;AAED,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,WAAW,CAWvF;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,WAAW,CAQxE;AAED,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,EAC9D,KAAK,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,OAAO,GAC3C,WAAW,CAQb;AAED,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,WAAW,CAQlE"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { expecting } from '../expectation.js';
|
|
2
|
+
import { record, text } from './read.js';
|
|
3
|
+
export function overlay() {
|
|
4
|
+
const held = expecting();
|
|
5
|
+
return {
|
|
6
|
+
subscribe: held.subscribe,
|
|
7
|
+
version: held.version,
|
|
8
|
+
begin: held.begin,
|
|
9
|
+
drop: held.drop,
|
|
10
|
+
expect: (act, expected) => held.expect(act, expected),
|
|
11
|
+
heard: (view) => held.heard((one) => one.view === 'conversation' && one.shown(view)),
|
|
12
|
+
heardList: (entries) => held.heard((one) => one.view === 'conversations' && one.shown(entries)),
|
|
13
|
+
conversation: (view) => held.drawn().reduce((now, one) => (one.view === 'conversation' ? one.draw(now) : now), view),
|
|
14
|
+
conversations: (entries) => held
|
|
15
|
+
.drawn()
|
|
16
|
+
.reduce((now, one) => (one.view === 'conversations' ? one.draw(now) : now), entries),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function sentMessage(key, into, said, turn) {
|
|
20
|
+
const sealed = (held) => turn !== null && held.messages.some((one) => one.turn === turn);
|
|
21
|
+
return {
|
|
22
|
+
key,
|
|
23
|
+
view: 'conversation',
|
|
24
|
+
draw: (held) => !into.includes(held.conversation) || sealed(held)
|
|
25
|
+
? held
|
|
26
|
+
: {
|
|
27
|
+
...held,
|
|
28
|
+
messages: [
|
|
29
|
+
...held.messages,
|
|
30
|
+
{
|
|
31
|
+
identity: key,
|
|
32
|
+
turn: turn ?? key,
|
|
33
|
+
text: said.text,
|
|
34
|
+
message: {
|
|
35
|
+
role: 'user',
|
|
36
|
+
text: said.text,
|
|
37
|
+
files: said.files.map((file) => ({ name: file.name })),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
shown: sealed,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function optionChosen(conversation, option, value) {
|
|
46
|
+
const ours = (entry) => text(record(entry), 'id') === option;
|
|
47
|
+
return {
|
|
48
|
+
key: `option ${conversation} ${option}`,
|
|
49
|
+
view: 'conversation',
|
|
50
|
+
draw: (held) => held.conversation !== conversation
|
|
51
|
+
? held
|
|
52
|
+
: {
|
|
53
|
+
...held,
|
|
54
|
+
options: held.options.map((entry) => ours(entry) && entry.type === 'select' ? { ...entry, currentValue: value } : entry),
|
|
55
|
+
},
|
|
56
|
+
shown: (held) => held.conversation === conversation &&
|
|
57
|
+
held.options.some((entry) => ours(entry) && text(record(entry), 'currentValue') === value),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export function questionAnswered(conversation, interaction) {
|
|
61
|
+
const ours = (entry) => text(record(entry), 'interaction_id') === interaction;
|
|
62
|
+
return {
|
|
63
|
+
key: `answer ${conversation} ${interaction}`,
|
|
64
|
+
view: 'conversation',
|
|
65
|
+
draw: (held) => held.conversation !== conversation
|
|
66
|
+
? held
|
|
67
|
+
: { ...held, questions: held.questions.filter((entry) => !ours(entry)) },
|
|
68
|
+
shown: (held) => held.conversation === conversation && !held.questions.some(ours),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function conversationListed(entry) {
|
|
72
|
+
const ours = (one) => one.conversation === entry.conversation;
|
|
73
|
+
return {
|
|
74
|
+
key: `conversation ${entry.conversation}`,
|
|
75
|
+
view: 'conversations',
|
|
76
|
+
draw: (held) => (held.some(ours) ? held : [...held, entry]),
|
|
77
|
+
shown: (held) => held.some(ours),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function conversationChanged(conversation, changes, shown) {
|
|
81
|
+
const ours = (one) => one.conversation === conversation;
|
|
82
|
+
return {
|
|
83
|
+
key: `conversation ${conversation} ${Object.keys(changes).sort().join(' ')}`,
|
|
84
|
+
view: 'conversations',
|
|
85
|
+
draw: (held) => held.map((one) => (ours(one) ? { ...one, ...changes } : one)),
|
|
86
|
+
shown: (held) => held.some((one) => ours(one) && shown(one)),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export function conversationGone(conversation) {
|
|
90
|
+
const ours = (one) => one.conversation === conversation;
|
|
91
|
+
return {
|
|
92
|
+
key: `conversation ${conversation}`,
|
|
93
|
+
view: 'conversations',
|
|
94
|
+
draw: (held) => held.filter((one) => !ours(one)),
|
|
95
|
+
shown: (held) => !held.some(ours),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { TurnContext } from '../adapter.js';
|
|
2
|
+
export type PlanStep = {
|
|
3
|
+
readonly content: string;
|
|
4
|
+
readonly status: string;
|
|
5
|
+
};
|
|
6
|
+
export type Marker = 'mode' | 'compaction' | 'retry' | 'model' | 'job';
|
|
7
|
+
export type Part = {
|
|
8
|
+
readonly type: 'text';
|
|
9
|
+
readonly text: string;
|
|
10
|
+
} | {
|
|
11
|
+
readonly type: 'reasoning';
|
|
12
|
+
readonly text: string;
|
|
13
|
+
} | {
|
|
14
|
+
readonly type: 'commands';
|
|
15
|
+
readonly count: number;
|
|
16
|
+
} | {
|
|
17
|
+
readonly type: 'subagent';
|
|
18
|
+
readonly description: string;
|
|
19
|
+
readonly done: boolean;
|
|
20
|
+
readonly result: string | null;
|
|
21
|
+
} | {
|
|
22
|
+
readonly type: 'message';
|
|
23
|
+
readonly command: string;
|
|
24
|
+
readonly target: string | null;
|
|
25
|
+
} | {
|
|
26
|
+
readonly type: 'image';
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly mediaType: string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: 'marker';
|
|
31
|
+
readonly marker: Marker;
|
|
32
|
+
readonly text: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly type: 'plan';
|
|
35
|
+
readonly steps: readonly PlanStep[];
|
|
36
|
+
};
|
|
37
|
+
export declare function partsOf(raw: readonly unknown[]): readonly Part[];
|
|
38
|
+
export declare function contextIn(raw: unknown): TurnContext | null;
|
|
39
|
+
export type Turn = {
|
|
40
|
+
readonly turn: string;
|
|
41
|
+
readonly parts: readonly Part[];
|
|
42
|
+
readonly ended: boolean;
|
|
43
|
+
};
|
|
44
|
+
export type ChatWork = {
|
|
45
|
+
readonly kind: 'job' | 'schedule' | 'subagent';
|
|
46
|
+
readonly title: string;
|
|
47
|
+
readonly next: string | null;
|
|
48
|
+
};
|
|
49
|
+
export type Job = {
|
|
50
|
+
readonly label: string;
|
|
51
|
+
readonly kind: 'started' | 'scheduled' | 'ended';
|
|
52
|
+
readonly state: string;
|
|
53
|
+
readonly next: string | null;
|
|
54
|
+
};
|
|
55
|
+
export declare function jobOf(said: string): Job;
|
|
56
|
+
export declare function stillRunning(turns: readonly Turn[]): ReadonlyMap<string, readonly ChatWork[]>;
|
|
57
|
+
//# sourceMappingURL=parts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parts.d.ts","sourceRoot":"","sources":["../../src/chat/parts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGjD,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;AAEvE,MAAM,MAAM,IAAI,GACZ;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrD;IACE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GACtF;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC7E;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC3E;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAA;CAAE,CAAC;AAmDnE,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,IAAI,EAAE,CAEhE;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAK1D;AAED,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,UAAU,GAAG,UAAU,CAAC;IAC/C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,GAAG,GAAG;IAChB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,GAAG,OAAO,CAAC;IACjD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAIF,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CASvC;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,WAAW,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,CAAC,CA0C7F"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { list, record, text } from './read.js';
|
|
2
|
+
const MARKERS = ['mode', 'compaction', 'retry', 'model', 'job'];
|
|
3
|
+
function partOf(raw) {
|
|
4
|
+
const part = record(raw);
|
|
5
|
+
switch (text(part, 'type')) {
|
|
6
|
+
case 'text':
|
|
7
|
+
case 'reasoning': {
|
|
8
|
+
const said = text(part, 'text');
|
|
9
|
+
return said === null ? null : { type: part.type, text: said };
|
|
10
|
+
}
|
|
11
|
+
case 'commands':
|
|
12
|
+
return typeof part.count === 'number' ? { type: 'commands', count: part.count } : null;
|
|
13
|
+
case 'subagent':
|
|
14
|
+
return {
|
|
15
|
+
type: 'subagent',
|
|
16
|
+
description: text(part, 'description') ?? '',
|
|
17
|
+
done: part.status === 'done',
|
|
18
|
+
result: text(part, 'result'),
|
|
19
|
+
};
|
|
20
|
+
case 'message': {
|
|
21
|
+
const command = text(part, 'command');
|
|
22
|
+
return command === null ? null : { type: 'message', command, target: text(part, 'target') };
|
|
23
|
+
}
|
|
24
|
+
case 'image': {
|
|
25
|
+
const name = text(part, 'name');
|
|
26
|
+
return name === null
|
|
27
|
+
? null
|
|
28
|
+
: { type: 'image', name, mediaType: text(part, 'media_type') ?? '' };
|
|
29
|
+
}
|
|
30
|
+
case 'marker': {
|
|
31
|
+
const marker = text(part, 'marker');
|
|
32
|
+
return marker === null || !MARKERS.includes(marker)
|
|
33
|
+
? null
|
|
34
|
+
: { type: 'marker', marker: marker, text: text(part, 'text') ?? '' };
|
|
35
|
+
}
|
|
36
|
+
case 'plan':
|
|
37
|
+
return {
|
|
38
|
+
type: 'plan',
|
|
39
|
+
steps: list(part, 'entries').flatMap((entry) => {
|
|
40
|
+
const step = record(entry);
|
|
41
|
+
const content = text(step, 'content');
|
|
42
|
+
return content === null ? [] : [{ content, status: text(step, 'status') ?? '' }];
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
45
|
+
default:
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function partsOf(raw) {
|
|
50
|
+
return raw.flatMap((one) => partOf(one) ?? []);
|
|
51
|
+
}
|
|
52
|
+
export function contextIn(raw) {
|
|
53
|
+
const held = record(raw);
|
|
54
|
+
return typeof held.used === 'number' && typeof held.window === 'number' && held.window > 0
|
|
55
|
+
? { used: held.used, window: held.window }
|
|
56
|
+
: null;
|
|
57
|
+
}
|
|
58
|
+
const NEXT_RUN = 'next run ';
|
|
59
|
+
export function jobOf(said) {
|
|
60
|
+
const at = said.lastIndexOf(': ');
|
|
61
|
+
const label = at === -1 ? said : said.slice(0, at);
|
|
62
|
+
const state = at === -1 ? '' : said.slice(at + 2);
|
|
63
|
+
if (state === 'running')
|
|
64
|
+
return { label, kind: 'started', state, next: null };
|
|
65
|
+
if (state === 'scheduled')
|
|
66
|
+
return { label, kind: 'scheduled', state, next: null };
|
|
67
|
+
return state.startsWith(NEXT_RUN)
|
|
68
|
+
? { label, kind: 'scheduled', state, next: state.slice(NEXT_RUN.length) }
|
|
69
|
+
: { label, kind: 'ended', state, next: null };
|
|
70
|
+
}
|
|
71
|
+
export function stillRunning(turns) {
|
|
72
|
+
const open = [];
|
|
73
|
+
const close = (key) => {
|
|
74
|
+
const at = open.map((one) => one.key).lastIndexOf(key);
|
|
75
|
+
if (at !== -1)
|
|
76
|
+
open.splice(at, 1);
|
|
77
|
+
};
|
|
78
|
+
for (const { turn, parts, ended } of turns) {
|
|
79
|
+
for (const part of parts) {
|
|
80
|
+
if (part.type === 'subagent') {
|
|
81
|
+
const key = `subagent\u0000${part.description}`;
|
|
82
|
+
if (part.done)
|
|
83
|
+
close(key);
|
|
84
|
+
else if (ended) {
|
|
85
|
+
open.push({ turn, key, work: { kind: 'subagent', title: part.description, next: null } });
|
|
86
|
+
}
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (part.type !== 'marker' || part.marker !== 'job')
|
|
90
|
+
continue;
|
|
91
|
+
const job = jobOf(part.text);
|
|
92
|
+
const started = `job\u0000${job.label}`;
|
|
93
|
+
const schedule = `schedule\u0000${job.label}`;
|
|
94
|
+
if (job.kind === 'scheduled') {
|
|
95
|
+
close(schedule);
|
|
96
|
+
if (ended) {
|
|
97
|
+
open.push({
|
|
98
|
+
turn,
|
|
99
|
+
key: schedule,
|
|
100
|
+
work: { kind: 'schedule', title: job.label, next: job.next },
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (job.kind === 'started') {
|
|
105
|
+
if (ended) {
|
|
106
|
+
open.push({ turn, key: started, work: { kind: 'job', title: job.label, next: null } });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
close(started);
|
|
111
|
+
close(schedule);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const under = new Map();
|
|
116
|
+
for (const one of open)
|
|
117
|
+
under.set(one.turn, [...(under.get(one.turn) ?? []), one.work]);
|
|
118
|
+
return under;
|
|
119
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ConversationView } from '../conversation.js';
|
|
2
|
+
export type ChatOptionValue = {
|
|
3
|
+
readonly value: string;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
};
|
|
6
|
+
export type ChatOption = {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly value: string;
|
|
10
|
+
readonly values: readonly ChatOptionValue[];
|
|
11
|
+
};
|
|
12
|
+
export type ChatCommand = {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly description: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function optionsOf(view: ConversationView | null): readonly ChatOption[];
|
|
17
|
+
export declare function commandsOf(view: ConversationView | null): readonly ChatCommand[];
|
|
18
|
+
export declare const COMMAND = "/";
|
|
19
|
+
export declare function commandIn(said: string, commands: readonly ChatCommand[]): boolean;
|
|
20
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/chat/process.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAG3D,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B,CAAC;AAWF,wBAAgB,SAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,UAAU,EAAE,CAU9E;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,WAAW,EAAE,CAMhF;AAED,eAAO,MAAM,OAAO,MAAM,CAAC;AAE3B,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,WAAW,EAAE,GAAG,OAAO,CAGjF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { list, record, text } from './read.js';
|
|
2
|
+
function valuesOf(option) {
|
|
3
|
+
return list(option, 'options').flatMap((entry) => {
|
|
4
|
+
const choice = record(entry);
|
|
5
|
+
const value = text(choice, 'value');
|
|
6
|
+
const name = text(choice, 'name');
|
|
7
|
+
return value === null || name === null ? [] : [{ value, name }];
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export function optionsOf(view) {
|
|
11
|
+
return (view?.options ?? []).flatMap((entry) => {
|
|
12
|
+
const option = record(entry);
|
|
13
|
+
const id = text(option, 'id');
|
|
14
|
+
const name = text(option, 'name');
|
|
15
|
+
const value = text(option, 'currentValue');
|
|
16
|
+
return id === null || name === null || value === null
|
|
17
|
+
? []
|
|
18
|
+
: [{ id, name, value, values: valuesOf(option) }];
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export function commandsOf(view) {
|
|
22
|
+
return (view?.commands ?? []).flatMap((entry) => {
|
|
23
|
+
const command = record(entry);
|
|
24
|
+
const name = text(command, 'name');
|
|
25
|
+
return name === null ? [] : [{ name, description: text(command, 'description') ?? '' }];
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export const COMMAND = '/';
|
|
29
|
+
export function commandIn(said, commands) {
|
|
30
|
+
const [first] = said.split(/\s/);
|
|
31
|
+
return commands.some((one) => first === `${COMMAND}${one.name}`);
|
|
32
|
+
}
|