@mrtdown/core 2.0.0-alpha.3 → 2.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/create.d.ts +30 -0
- package/dist/cli/commands/create.js +189 -0
- package/dist/cli/commands/create.js.map +1 -0
- package/dist/cli/commands/list.d.ts +6 -0
- package/dist/cli/commands/list.js +106 -0
- package/dist/cli/commands/list.js.map +1 -0
- package/dist/cli/commands/show.d.ts +6 -0
- package/dist/cli/commands/show.js +156 -0
- package/dist/cli/commands/show.js.map +1 -0
- package/dist/cli/commands/validate.d.ts +6 -0
- package/dist/cli/commands/validate.js +19 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +162 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/llm/client.d.ts +2 -0
- package/dist/llm/client.js +5 -0
- package/dist/llm/client.js.map +1 -0
- package/dist/llm/common/MemoryStore.d.ts +21 -0
- package/dist/llm/common/MemoryStore.js +100 -0
- package/dist/llm/common/MemoryStore.js.map +1 -0
- package/dist/llm/common/MemoryStore.test.d.ts +1 -0
- package/dist/llm/common/MemoryStore.test.js +225 -0
- package/dist/llm/common/MemoryStore.test.js.map +1 -0
- package/dist/llm/common/formatCurrentState.d.ts +10 -0
- package/dist/llm/common/formatCurrentState.js +342 -0
- package/dist/llm/common/formatCurrentState.js.map +1 -0
- package/dist/llm/common/tool.d.ts +32 -0
- package/dist/llm/common/tool.js +6 -0
- package/dist/llm/common/tool.js.map +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/eval.test.d.ts +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/eval.test.js +433 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/eval.test.js.map +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/index.d.ts +18 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/index.js +153 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/index.js.map +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/prompt.d.ts +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/prompt.js +168 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/prompt.js.map +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindLinesTool.d.ts +19 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindLinesTool.js +65 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindLinesTool.js.map +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindServicesTool.d.ts +21 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindServicesTool.js +115 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindServicesTool.js.map +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindStationsTool.d.ts +24 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindStationsTool.js +110 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindStationsTool.js.map +1 -0
- package/dist/llm/functions/generateIssueTitleAndSlug/index.d.ts +14 -0
- package/dist/llm/functions/generateIssueTitleAndSlug/index.js +38 -0
- package/dist/llm/functions/generateIssueTitleAndSlug/index.js.map +1 -0
- package/dist/llm/functions/generateIssueTitleAndSlug/prompt.d.ts +1 -0
- package/dist/llm/functions/generateIssueTitleAndSlug/prompt.js +23 -0
- package/dist/llm/functions/generateIssueTitleAndSlug/prompt.js.map +1 -0
- package/dist/llm/functions/translate/index.d.ts +1 -0
- package/dist/llm/functions/translate/index.js +59 -0
- package/dist/llm/functions/translate/index.js.map +1 -0
- package/dist/llm/functions/triageNewEvidence/eval.test.d.ts +1 -0
- package/dist/llm/functions/triageNewEvidence/eval.test.js +139 -0
- package/dist/llm/functions/triageNewEvidence/eval.test.js.map +1 -0
- package/dist/llm/functions/triageNewEvidence/index.d.ts +37 -0
- package/dist/llm/functions/triageNewEvidence/index.js +121 -0
- package/dist/llm/functions/triageNewEvidence/index.js.map +1 -0
- package/dist/llm/functions/triageNewEvidence/prompt.d.ts +1 -0
- package/dist/llm/functions/triageNewEvidence/prompt.js +60 -0
- package/dist/llm/functions/triageNewEvidence/prompt.js.map +1 -0
- package/dist/llm/functions/triageNewEvidence/tools/FindIssuesTool.d.ts +19 -0
- package/dist/llm/functions/triageNewEvidence/tools/FindIssuesTool.js +65 -0
- package/dist/llm/functions/triageNewEvidence/tools/FindIssuesTool.js.map +1 -0
- package/dist/llm/functions/triageNewEvidence/tools/GetIssueTool.d.ts +19 -0
- package/dist/llm/functions/triageNewEvidence/tools/GetIssueTool.js +37 -0
- package/dist/llm/functions/triageNewEvidence/tools/GetIssueTool.js.map +1 -0
- package/dist/scripts/ingestViaWebhook.d.ts +1 -0
- package/dist/scripts/ingestViaWebhook.js +9 -0
- package/dist/scripts/ingestViaWebhook.js.map +1 -0
- package/dist/validators/buildContext.d.ts +7 -0
- package/dist/validators/buildContext.js +164 -0
- package/dist/validators/buildContext.js.map +1 -0
- package/dist/validators/index.d.ts +17 -0
- package/dist/validators/index.js +58 -0
- package/dist/validators/index.js.map +1 -0
- package/dist/validators/issue.d.ts +13 -0
- package/dist/validators/issue.js +220 -0
- package/dist/validators/issue.js.map +1 -0
- package/dist/validators/landmark.d.ts +7 -0
- package/dist/validators/landmark.js +43 -0
- package/dist/validators/landmark.js.map +1 -0
- package/dist/validators/line.d.ts +8 -0
- package/dist/validators/line.js +87 -0
- package/dist/validators/line.js.map +1 -0
- package/dist/validators/operator.d.ts +7 -0
- package/dist/validators/operator.js +43 -0
- package/dist/validators/operator.js.map +1 -0
- package/dist/validators/service.d.ts +8 -0
- package/dist/validators/service.js +87 -0
- package/dist/validators/service.js.map +1 -0
- package/dist/validators/station.d.ts +8 -0
- package/dist/validators/station.js +93 -0
- package/dist/validators/station.js.map +1 -0
- package/dist/validators/town.d.ts +7 -0
- package/dist/validators/town.js +43 -0
- package/dist/validators/town.js.map +1 -0
- package/dist/validators/types.d.ts +19 -0
- package/dist/validators/types.js +2 -0
- package/dist/validators/types.js.map +1 -0
- package/dist/validators/utils.d.ts +2 -0
- package/dist/validators/utils.js +9 -0
- package/dist/validators/utils.js.map +1 -0
- package/package.json +11 -7
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { gfmToMarkdown } from 'mdast-util-gfm';
|
|
2
|
+
import { toMarkdown } from 'mdast-util-to-markdown';
|
|
3
|
+
/**
|
|
4
|
+
* Format the current state as markdown for better LLM readability
|
|
5
|
+
*/
|
|
6
|
+
export function formatCurrentState(stateOrOptions) {
|
|
7
|
+
const options = stateOrOptions != null &&
|
|
8
|
+
typeof stateOrOptions === 'object' &&
|
|
9
|
+
'state' in stateOrOptions
|
|
10
|
+
? stateOrOptions
|
|
11
|
+
: { state: stateOrOptions };
|
|
12
|
+
const state = options.state;
|
|
13
|
+
const evidence = options.evidence ?? [];
|
|
14
|
+
if (state == null && evidence.length === 0) {
|
|
15
|
+
return 'No state';
|
|
16
|
+
}
|
|
17
|
+
const services = state?.services ?? {};
|
|
18
|
+
const facilities = state?.facilities ?? {};
|
|
19
|
+
const impactEventIds = state?.impactEventIds ?? [];
|
|
20
|
+
const relevantEvidenceIds = state != null ? collectEvidenceIds(state) : [];
|
|
21
|
+
const root = {
|
|
22
|
+
type: 'root',
|
|
23
|
+
children: [],
|
|
24
|
+
};
|
|
25
|
+
// Evidence Section
|
|
26
|
+
root.children.push({
|
|
27
|
+
type: 'heading',
|
|
28
|
+
depth: 2,
|
|
29
|
+
children: [{ type: 'text', value: 'Evidence' }],
|
|
30
|
+
});
|
|
31
|
+
if (evidence.length === 0) {
|
|
32
|
+
root.children.push({
|
|
33
|
+
type: 'paragraph',
|
|
34
|
+
children: [{ type: 'text', value: 'None' }],
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
for (const ev of evidence) {
|
|
39
|
+
root.children.push(...formatEvidenceItem(ev));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Services Section
|
|
43
|
+
root.children.push({
|
|
44
|
+
type: 'heading',
|
|
45
|
+
depth: 2,
|
|
46
|
+
children: [{ type: 'text', value: 'Services' }],
|
|
47
|
+
});
|
|
48
|
+
const serviceKeys = Object.keys(services);
|
|
49
|
+
if (serviceKeys.length === 0) {
|
|
50
|
+
root.children.push({
|
|
51
|
+
type: 'paragraph',
|
|
52
|
+
children: [{ type: 'text', value: 'None' }],
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
for (const key of serviceKeys) {
|
|
57
|
+
const svc = services[key];
|
|
58
|
+
root.children.push(...formatServiceSection(key, svc.serviceId, svc.effect, svc.scopes, svc.periods, svc.causes));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Facilities Section
|
|
62
|
+
const facilitiesHeading = {
|
|
63
|
+
type: 'heading',
|
|
64
|
+
depth: 2,
|
|
65
|
+
children: [{ type: 'text', value: 'Facilities' }],
|
|
66
|
+
};
|
|
67
|
+
root.children.push(facilitiesHeading);
|
|
68
|
+
const facilityKeys = Object.keys(facilities);
|
|
69
|
+
if (facilityKeys.length === 0) {
|
|
70
|
+
root.children.push({
|
|
71
|
+
type: 'paragraph',
|
|
72
|
+
children: [{ type: 'text', value: 'None' }],
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
for (const key of facilityKeys) {
|
|
77
|
+
const fac = facilities[key];
|
|
78
|
+
root.children.push(...formatFacilitySection(key, fac.stationId, fac.kind, fac.effect, fac.periods));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Impact Event IDs Section
|
|
82
|
+
root.children.push({
|
|
83
|
+
type: 'heading',
|
|
84
|
+
depth: 2,
|
|
85
|
+
children: [{ type: 'text', value: 'Impact Event IDs' }],
|
|
86
|
+
});
|
|
87
|
+
if (impactEventIds.length === 0) {
|
|
88
|
+
root.children.push({
|
|
89
|
+
type: 'paragraph',
|
|
90
|
+
children: [{ type: 'text', value: 'None' }],
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
root.children.push({
|
|
95
|
+
type: 'list',
|
|
96
|
+
ordered: false,
|
|
97
|
+
children: impactEventIds.map((id) => ({
|
|
98
|
+
type: 'listItem',
|
|
99
|
+
children: [
|
|
100
|
+
{
|
|
101
|
+
type: 'paragraph',
|
|
102
|
+
children: [{ type: 'inlineCode', value: id }],
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
})),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// Relevant Evidence IDs Section
|
|
109
|
+
const evidenceHeading = {
|
|
110
|
+
type: 'heading',
|
|
111
|
+
depth: 2,
|
|
112
|
+
children: [{ type: 'text', value: 'Relevant Evidence IDs' }],
|
|
113
|
+
};
|
|
114
|
+
root.children.push(evidenceHeading);
|
|
115
|
+
if (relevantEvidenceIds.length === 0) {
|
|
116
|
+
root.children.push({
|
|
117
|
+
type: 'paragraph',
|
|
118
|
+
children: [{ type: 'text', value: 'None' }],
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
root.children.push({
|
|
123
|
+
type: 'list',
|
|
124
|
+
ordered: false,
|
|
125
|
+
children: relevantEvidenceIds.map((id) => ({
|
|
126
|
+
type: 'listItem',
|
|
127
|
+
children: [
|
|
128
|
+
{
|
|
129
|
+
type: 'paragraph',
|
|
130
|
+
children: [{ type: 'inlineCode', value: id }],
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
})),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return toMarkdown(root, { extensions: [gfmToMarkdown()] });
|
|
137
|
+
}
|
|
138
|
+
function formatEvidenceItem(ev) {
|
|
139
|
+
const children = [];
|
|
140
|
+
children.push({
|
|
141
|
+
type: 'heading',
|
|
142
|
+
depth: 3,
|
|
143
|
+
children: [
|
|
144
|
+
{ type: 'inlineCode', value: ev.id },
|
|
145
|
+
{ type: 'text', value: ` (${ev.type})` },
|
|
146
|
+
],
|
|
147
|
+
});
|
|
148
|
+
children.push({
|
|
149
|
+
type: 'paragraph',
|
|
150
|
+
children: [
|
|
151
|
+
{ type: 'text', value: 'Timestamp: ' },
|
|
152
|
+
{ type: 'inlineCode', value: ev.ts },
|
|
153
|
+
],
|
|
154
|
+
});
|
|
155
|
+
children.push({
|
|
156
|
+
type: 'paragraph',
|
|
157
|
+
children: [
|
|
158
|
+
{ type: 'text', value: 'Source: ' },
|
|
159
|
+
{ type: 'inlineCode', value: ev.render?.source ?? '—' },
|
|
160
|
+
],
|
|
161
|
+
});
|
|
162
|
+
if ('sourceUrl' in ev) {
|
|
163
|
+
children.push({
|
|
164
|
+
type: 'paragraph',
|
|
165
|
+
children: [
|
|
166
|
+
{ type: 'text', value: 'URL: ' },
|
|
167
|
+
{
|
|
168
|
+
type: 'link',
|
|
169
|
+
url: ev.sourceUrl,
|
|
170
|
+
children: [{ type: 'text', value: ev.sourceUrl }],
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
children.push({
|
|
176
|
+
type: 'paragraph',
|
|
177
|
+
children: [{ type: 'text', value: 'Text:' }],
|
|
178
|
+
});
|
|
179
|
+
children.push({
|
|
180
|
+
type: 'blockquote',
|
|
181
|
+
children: [
|
|
182
|
+
{
|
|
183
|
+
type: 'paragraph',
|
|
184
|
+
children: [{ type: 'text', value: ev.text }],
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
});
|
|
188
|
+
return children;
|
|
189
|
+
}
|
|
190
|
+
function collectEvidenceIds(state) {
|
|
191
|
+
const ids = new Set();
|
|
192
|
+
for (const prov of Object.values(state.servicesProvenance)) {
|
|
193
|
+
if (prov.effect?.evidenceId)
|
|
194
|
+
ids.add(prov.effect.evidenceId);
|
|
195
|
+
if (prov.scopes?.evidenceId)
|
|
196
|
+
ids.add(prov.scopes.evidenceId);
|
|
197
|
+
if (prov.periods?.evidenceId)
|
|
198
|
+
ids.add(prov.periods.evidenceId);
|
|
199
|
+
if (prov.causes?.evidenceId)
|
|
200
|
+
ids.add(prov.causes.evidenceId);
|
|
201
|
+
}
|
|
202
|
+
for (const prov of Object.values(state.facilitiesProvenance)) {
|
|
203
|
+
if (prov.effect?.evidenceId)
|
|
204
|
+
ids.add(prov.effect.evidenceId);
|
|
205
|
+
if (prov.periods?.evidenceId)
|
|
206
|
+
ids.add(prov.periods.evidenceId);
|
|
207
|
+
}
|
|
208
|
+
return [...ids];
|
|
209
|
+
}
|
|
210
|
+
function formatServiceSection(key, serviceId, effect, scopes, periods, causes) {
|
|
211
|
+
const children = [];
|
|
212
|
+
children.push({
|
|
213
|
+
type: 'heading',
|
|
214
|
+
depth: 3,
|
|
215
|
+
children: [{ type: 'text', value: key }],
|
|
216
|
+
});
|
|
217
|
+
children.push({
|
|
218
|
+
type: 'paragraph',
|
|
219
|
+
children: [
|
|
220
|
+
{ type: 'text', value: 'Service ID: ' },
|
|
221
|
+
{ type: 'inlineCode', value: serviceId },
|
|
222
|
+
],
|
|
223
|
+
});
|
|
224
|
+
children.push({
|
|
225
|
+
type: 'paragraph',
|
|
226
|
+
children: [
|
|
227
|
+
{ type: 'text', value: 'Effect: ' },
|
|
228
|
+
{ type: 'inlineCode', value: effect?.kind ?? 'null' },
|
|
229
|
+
],
|
|
230
|
+
});
|
|
231
|
+
if (scopes.length > 0) {
|
|
232
|
+
children.push({
|
|
233
|
+
type: 'paragraph',
|
|
234
|
+
children: [{ type: 'text', value: 'Scopes:' }],
|
|
235
|
+
});
|
|
236
|
+
children.push({
|
|
237
|
+
type: 'list',
|
|
238
|
+
ordered: false,
|
|
239
|
+
children: scopes.map((scope) => ({
|
|
240
|
+
type: 'listItem',
|
|
241
|
+
children: [
|
|
242
|
+
{
|
|
243
|
+
type: 'paragraph',
|
|
244
|
+
children: [{ type: 'inlineCode', value: formatScope(scope) }],
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
})),
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
if (periods.length > 0) {
|
|
251
|
+
children.push({
|
|
252
|
+
type: 'paragraph',
|
|
253
|
+
children: [{ type: 'text', value: 'Periods:' }],
|
|
254
|
+
});
|
|
255
|
+
children.push({
|
|
256
|
+
type: 'list',
|
|
257
|
+
ordered: false,
|
|
258
|
+
children: periods.map((period, i) => ({
|
|
259
|
+
type: 'listItem',
|
|
260
|
+
children: [
|
|
261
|
+
{
|
|
262
|
+
type: 'paragraph',
|
|
263
|
+
children: [{ type: 'text', value: formatPeriod(period, i) }],
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
})),
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
if (causes.length > 0) {
|
|
270
|
+
children.push({
|
|
271
|
+
type: 'paragraph',
|
|
272
|
+
children: [
|
|
273
|
+
{ type: 'text', value: 'Causes: ' },
|
|
274
|
+
{ type: 'inlineCode', value: causes.join(', ') },
|
|
275
|
+
],
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
return children;
|
|
279
|
+
}
|
|
280
|
+
function formatFacilitySection(key, stationId, kind, effect, periods) {
|
|
281
|
+
const children = [];
|
|
282
|
+
children.push({
|
|
283
|
+
type: 'heading',
|
|
284
|
+
depth: 3,
|
|
285
|
+
children: [{ type: 'text', value: key }],
|
|
286
|
+
});
|
|
287
|
+
children.push({
|
|
288
|
+
type: 'paragraph',
|
|
289
|
+
children: [
|
|
290
|
+
{ type: 'text', value: 'Station: ' },
|
|
291
|
+
{ type: 'inlineCode', value: stationId },
|
|
292
|
+
{ type: 'text', value: ', Kind: ' },
|
|
293
|
+
{ type: 'inlineCode', value: kind },
|
|
294
|
+
],
|
|
295
|
+
});
|
|
296
|
+
children.push({
|
|
297
|
+
type: 'paragraph',
|
|
298
|
+
children: [
|
|
299
|
+
{ type: 'text', value: 'Effect: ' },
|
|
300
|
+
{ type: 'inlineCode', value: effect?.kind ?? 'null' },
|
|
301
|
+
],
|
|
302
|
+
});
|
|
303
|
+
if (periods.length > 0) {
|
|
304
|
+
children.push({
|
|
305
|
+
type: 'paragraph',
|
|
306
|
+
children: [{ type: 'text', value: 'Periods:' }],
|
|
307
|
+
});
|
|
308
|
+
children.push({
|
|
309
|
+
type: 'list',
|
|
310
|
+
ordered: false,
|
|
311
|
+
children: periods.map((period, i) => ({
|
|
312
|
+
type: 'listItem',
|
|
313
|
+
children: [
|
|
314
|
+
{
|
|
315
|
+
type: 'paragraph',
|
|
316
|
+
children: [{ type: 'text', value: formatPeriod(period, i) }],
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
})),
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
return children;
|
|
323
|
+
}
|
|
324
|
+
function formatScope(scope) {
|
|
325
|
+
switch (scope.type) {
|
|
326
|
+
case 'service.whole':
|
|
327
|
+
return scope.type;
|
|
328
|
+
case 'service.segment':
|
|
329
|
+
return `${scope.type} (${scope.fromStationId} → ${scope.toStationId})`;
|
|
330
|
+
case 'service.point':
|
|
331
|
+
return `${scope.type} (${scope.stationId})`;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
function formatPeriod(period, index) {
|
|
335
|
+
switch (period.kind) {
|
|
336
|
+
case 'fixed':
|
|
337
|
+
return `[${index}] fixed: ${period.startAt} → ${period.endAt ?? 'ongoing'}`;
|
|
338
|
+
case 'recurring':
|
|
339
|
+
return `[${index}] recurring ${period.frequency}: ${period.startAt}–${period.endAt} ${period.timeWindow.startAt}–${period.timeWindow.endAt}`;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
//# sourceMappingURL=formatCurrentState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatCurrentState.js","sourceRoot":"/","sources":["llm/common/formatCurrentState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC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AAU,CAAC,OAAO,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IACjJ,CAAC;AACH,CAAC","sourcesContent":["import type { Heading, Root } from 'mdast';\nimport { gfmToMarkdown } from 'mdast-util-gfm';\nimport { toMarkdown } from 'mdast-util-to-markdown';\nimport type { IssueBundleState } from '#repo/issue/helpers/deriveCurrentState.js';\nimport type { Evidence } from '#schema/issue/evidence.js';\nimport type { Period } from '#schema/issue/period.js';\nimport type { ServiceScope } from '#schema/issue/serviceScope.js';\n\nexport type FormatCurrentStateOptions = {\n state: IssueBundleState | null;\n evidence?: Evidence[];\n};\n\n/**\n * Format the current state as markdown for better LLM readability\n */\nexport function formatCurrentState(\n stateOrOptions: IssueBundleState | null | FormatCurrentStateOptions,\n): string {\n const options: FormatCurrentStateOptions =\n stateOrOptions != null &&\n typeof stateOrOptions === 'object' &&\n 'state' in stateOrOptions\n ? stateOrOptions\n : { state: stateOrOptions };\n const state = options.state;\n const evidence = options.evidence ?? [];\n\n if (state == null && evidence.length === 0) {\n return 'No state';\n }\n\n const services = state?.services ?? {};\n const facilities = state?.facilities ?? {};\n const impactEventIds = state?.impactEventIds ?? [];\n const relevantEvidenceIds = state != null ? collectEvidenceIds(state) : [];\n\n const root: Root = {\n type: 'root',\n children: [],\n };\n\n // Evidence Section\n root.children.push({\n type: 'heading',\n depth: 2,\n children: [{ type: 'text', value: 'Evidence' }],\n });\n\n if (evidence.length === 0) {\n root.children.push({\n type: 'paragraph',\n children: [{ type: 'text', value: 'None' }],\n });\n } else {\n for (const ev of evidence) {\n root.children.push(...formatEvidenceItem(ev));\n }\n }\n\n // Services Section\n root.children.push({\n type: 'heading',\n depth: 2,\n children: [{ type: 'text', value: 'Services' }],\n });\n\n const serviceKeys = Object.keys(services);\n if (serviceKeys.length === 0) {\n root.children.push({\n type: 'paragraph',\n children: [{ type: 'text', value: 'None' }],\n });\n } else {\n for (const key of serviceKeys) {\n const svc = services[key];\n root.children.push(\n ...formatServiceSection(\n key,\n svc.serviceId,\n svc.effect,\n svc.scopes,\n svc.periods,\n svc.causes,\n ),\n );\n }\n }\n\n // Facilities Section\n const facilitiesHeading: Heading = {\n type: 'heading',\n depth: 2,\n children: [{ type: 'text', value: 'Facilities' }],\n };\n root.children.push(facilitiesHeading);\n\n const facilityKeys = Object.keys(facilities);\n if (facilityKeys.length === 0) {\n root.children.push({\n type: 'paragraph',\n children: [{ type: 'text', value: 'None' }],\n });\n } else {\n for (const key of facilityKeys) {\n const fac = facilities[key];\n root.children.push(\n ...formatFacilitySection(\n key,\n fac.stationId,\n fac.kind,\n fac.effect,\n fac.periods,\n ),\n );\n }\n }\n\n // Impact Event IDs Section\n root.children.push({\n type: 'heading',\n depth: 2,\n children: [{ type: 'text', value: 'Impact Event IDs' }],\n });\n\n if (impactEventIds.length === 0) {\n root.children.push({\n type: 'paragraph',\n children: [{ type: 'text', value: 'None' }],\n });\n } else {\n root.children.push({\n type: 'list',\n ordered: false,\n children: impactEventIds.map((id) => ({\n type: 'listItem',\n children: [\n {\n type: 'paragraph',\n children: [{ type: 'inlineCode', value: id }],\n },\n ],\n })),\n });\n }\n\n // Relevant Evidence IDs Section\n const evidenceHeading: Heading = {\n type: 'heading',\n depth: 2,\n children: [{ type: 'text', value: 'Relevant Evidence IDs' }],\n };\n root.children.push(evidenceHeading);\n\n if (relevantEvidenceIds.length === 0) {\n root.children.push({\n type: 'paragraph',\n children: [{ type: 'text', value: 'None' }],\n });\n } else {\n root.children.push({\n type: 'list',\n ordered: false,\n children: relevantEvidenceIds.map((id) => ({\n type: 'listItem',\n children: [\n {\n type: 'paragraph',\n children: [{ type: 'inlineCode', value: id }],\n },\n ],\n })),\n });\n }\n\n return toMarkdown(root, { extensions: [gfmToMarkdown()] });\n}\n\nfunction formatEvidenceItem(ev: Evidence): Root['children'] {\n const children: Root['children'] = [];\n\n children.push({\n type: 'heading',\n depth: 3,\n children: [\n { type: 'inlineCode', value: ev.id },\n { type: 'text', value: ` (${ev.type})` },\n ],\n });\n\n children.push({\n type: 'paragraph',\n children: [\n { type: 'text', value: 'Timestamp: ' },\n { type: 'inlineCode', value: ev.ts },\n ],\n });\n\n children.push({\n type: 'paragraph',\n children: [\n { type: 'text', value: 'Source: ' },\n { type: 'inlineCode', value: ev.render?.source ?? '—' },\n ],\n });\n\n if ('sourceUrl' in ev) {\n children.push({\n type: 'paragraph',\n children: [\n { type: 'text', value: 'URL: ' },\n {\n type: 'link',\n url: ev.sourceUrl,\n children: [{ type: 'text', value: ev.sourceUrl }],\n },\n ],\n });\n }\n\n children.push({\n type: 'paragraph',\n children: [{ type: 'text', value: 'Text:' }],\n });\n children.push({\n type: 'blockquote',\n children: [\n {\n type: 'paragraph',\n children: [{ type: 'text', value: ev.text }],\n },\n ],\n });\n\n return children;\n}\n\nfunction collectEvidenceIds(state: IssueBundleState): string[] {\n const ids = new Set<string>();\n for (const prov of Object.values(state.servicesProvenance)) {\n if (prov.effect?.evidenceId) ids.add(prov.effect.evidenceId);\n if (prov.scopes?.evidenceId) ids.add(prov.scopes.evidenceId);\n if (prov.periods?.evidenceId) ids.add(prov.periods.evidenceId);\n if (prov.causes?.evidenceId) ids.add(prov.causes.evidenceId);\n }\n for (const prov of Object.values(state.facilitiesProvenance)) {\n if (prov.effect?.evidenceId) ids.add(prov.effect.evidenceId);\n if (prov.periods?.evidenceId) ids.add(prov.periods.evidenceId);\n }\n return [...ids];\n}\n\nfunction formatServiceSection(\n key: string,\n serviceId: string,\n effect: { kind: string } | null,\n scopes: ServiceScope[],\n periods: Period[],\n causes: string[],\n): Root['children'] {\n const children: Root['children'] = [];\n\n children.push({\n type: 'heading',\n depth: 3,\n children: [{ type: 'text', value: key }],\n });\n\n children.push({\n type: 'paragraph',\n children: [\n { type: 'text', value: 'Service ID: ' },\n { type: 'inlineCode', value: serviceId },\n ],\n });\n\n children.push({\n type: 'paragraph',\n children: [\n { type: 'text', value: 'Effect: ' },\n { type: 'inlineCode', value: effect?.kind ?? 'null' },\n ],\n });\n\n if (scopes.length > 0) {\n children.push({\n type: 'paragraph',\n children: [{ type: 'text', value: 'Scopes:' }],\n });\n children.push({\n type: 'list',\n ordered: false,\n children: scopes.map((scope) => ({\n type: 'listItem',\n children: [\n {\n type: 'paragraph',\n children: [{ type: 'inlineCode', value: formatScope(scope) }],\n },\n ],\n })),\n });\n }\n\n if (periods.length > 0) {\n children.push({\n type: 'paragraph',\n children: [{ type: 'text', value: 'Periods:' }],\n });\n children.push({\n type: 'list',\n ordered: false,\n children: periods.map((period, i) => ({\n type: 'listItem',\n children: [\n {\n type: 'paragraph',\n children: [{ type: 'text', value: formatPeriod(period, i) }],\n },\n ],\n })),\n });\n }\n\n if (causes.length > 0) {\n children.push({\n type: 'paragraph',\n children: [\n { type: 'text', value: 'Causes: ' },\n { type: 'inlineCode', value: causes.join(', ') },\n ],\n });\n }\n\n return children;\n}\n\nfunction formatFacilitySection(\n key: string,\n stationId: string,\n kind: string,\n effect: { kind: string } | null,\n periods: Period[],\n): Root['children'] {\n const children: Root['children'] = [];\n\n children.push({\n type: 'heading',\n depth: 3,\n children: [{ type: 'text', value: key }],\n });\n\n children.push({\n type: 'paragraph',\n children: [\n { type: 'text', value: 'Station: ' },\n { type: 'inlineCode', value: stationId },\n { type: 'text', value: ', Kind: ' },\n { type: 'inlineCode', value: kind },\n ],\n });\n\n children.push({\n type: 'paragraph',\n children: [\n { type: 'text', value: 'Effect: ' },\n { type: 'inlineCode', value: effect?.kind ?? 'null' },\n ],\n });\n\n if (periods.length > 0) {\n children.push({\n type: 'paragraph',\n children: [{ type: 'text', value: 'Periods:' }],\n });\n children.push({\n type: 'list',\n ordered: false,\n children: periods.map((period, i) => ({\n type: 'listItem',\n children: [\n {\n type: 'paragraph',\n children: [{ type: 'text', value: formatPeriod(period, i) }],\n },\n ],\n })),\n });\n }\n\n return children;\n}\n\nfunction formatScope(scope: ServiceScope): string {\n switch (scope.type) {\n case 'service.whole':\n return scope.type;\n case 'service.segment':\n return `${scope.type} (${scope.fromStationId} → ${scope.toStationId})`;\n case 'service.point':\n return `${scope.type} (${scope.stationId})`;\n }\n}\n\nfunction formatPeriod(period: Period, index: number): string {\n switch (period.kind) {\n case 'fixed':\n return `[${index}] fixed: ${period.startAt} → ${period.endAt ?? 'ongoing'}`;\n case 'recurring':\n return `[${index}] recurring ${period.frequency}: ${period.startAt}–${period.endAt} ${period.timeWindow.startAt}–${period.timeWindow.endAt}`;\n }\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A generic class for LLM tools.
|
|
3
|
+
*/
|
|
4
|
+
export declare abstract class Tool<TParams = any> {
|
|
5
|
+
/**
|
|
6
|
+
* The name of the tool.
|
|
7
|
+
*/
|
|
8
|
+
abstract name: string;
|
|
9
|
+
/**
|
|
10
|
+
* The description of the tool.
|
|
11
|
+
*/
|
|
12
|
+
abstract description: string;
|
|
13
|
+
/**
|
|
14
|
+
* The JSON schema for the tool's parameters.
|
|
15
|
+
*/
|
|
16
|
+
abstract get paramsSchema(): {
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Parse the parameters into a typed object.
|
|
21
|
+
* @param params
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
abstract parseParams(params: unknown): TParams;
|
|
25
|
+
/**
|
|
26
|
+
* Run the tool with the given parameters.
|
|
27
|
+
* @param param
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
abstract runner(param: TParams): Promise<string>;
|
|
31
|
+
}
|
|
32
|
+
export type ToolRegistry = Record<string, Tool>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"/","sources":["llm/common/tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAgB,IAAI;CA6BzB","sourcesContent":["/**\n * A generic class for LLM tools.\n */\nexport abstract class Tool<TParams = any> {\n /**\n * The name of the tool.\n */\n public abstract name: string;\n\n /**\n * The description of the tool.\n */\n public abstract description: string;\n\n /**\n * The JSON schema for the tool's parameters.\n */\n public abstract get paramsSchema(): { [key: string]: unknown };\n\n /**\n * Parse the parameters into a typed object.\n * @param params\n * @returns\n */\n public abstract parseParams(params: unknown): TParams;\n\n /**\n * Run the tool with the given parameters.\n * @param param\n * @returns\n */\n public abstract runner(param: TParams): Promise<string>;\n}\n\nexport type ToolRegistry = Record<string, Tool>;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'dotenv/config';
|