mote-core 0.1.2
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/README.md +28 -0
- package/dist/cache.d.ts +14 -0
- package/dist/cache.js +43 -0
- package/dist/cache.js.map +1 -0
- package/dist/connectors/qmd.d.ts +61 -0
- package/dist/connectors/qmd.js +124 -0
- package/dist/connectors/qmd.js.map +1 -0
- package/dist/connectors/types.d.ts +27 -0
- package/dist/connectors/types.js +2 -0
- package/dist/connectors/types.js.map +1 -0
- package/dist/contracts.d.ts +667 -0
- package/dist/contracts.js +229 -0
- package/dist/contracts.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/kernel.d.ts +51 -0
- package/dist/kernel.js +421 -0
- package/dist/kernel.js.map +1 -0
- package/dist/registry.d.ts +271 -0
- package/dist/registry.js +33 -0
- package/dist/registry.js.map +1 -0
- package/dist/runtime/engine.d.ts +24 -0
- package/dist/runtime/engine.js +151 -0
- package/dist/runtime/engine.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { z, type ZodType } from "zod";
|
|
2
|
+
import type { AccessMode, ConnectorKind, ExecutionContext } from "./contracts.js";
|
|
3
|
+
export interface ResourceDefinition {
|
|
4
|
+
id: string;
|
|
5
|
+
title: string;
|
|
6
|
+
description: string;
|
|
7
|
+
connectorKinds?: ConnectorKind[];
|
|
8
|
+
requiresConnectors?: string[];
|
|
9
|
+
accessModes?: AccessMode[];
|
|
10
|
+
cacheTtlMs?: number;
|
|
11
|
+
mcp?: {
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
kind?: "resource";
|
|
14
|
+
tenantSafe?: boolean;
|
|
15
|
+
};
|
|
16
|
+
load: (args: {
|
|
17
|
+
context: ExecutionContext;
|
|
18
|
+
}) => Promise<unknown>;
|
|
19
|
+
}
|
|
20
|
+
export interface ToolDefinition {
|
|
21
|
+
id: string;
|
|
22
|
+
title: string;
|
|
23
|
+
description: string;
|
|
24
|
+
connectorKinds?: ConnectorKind[];
|
|
25
|
+
accessModes?: AccessMode[];
|
|
26
|
+
inputSchema: ZodType;
|
|
27
|
+
outputSchema: ZodType;
|
|
28
|
+
mcp?: {
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
kind?: "tool";
|
|
31
|
+
tenantSafe?: boolean;
|
|
32
|
+
};
|
|
33
|
+
execute: (input: unknown, args: {
|
|
34
|
+
context: ExecutionContext;
|
|
35
|
+
}) => Promise<unknown>;
|
|
36
|
+
}
|
|
37
|
+
export interface PromptDefinition {
|
|
38
|
+
id: string;
|
|
39
|
+
title: string;
|
|
40
|
+
description: string;
|
|
41
|
+
connectorKinds?: ConnectorKind[];
|
|
42
|
+
accessModes?: AccessMode[];
|
|
43
|
+
inputSchema: ZodType;
|
|
44
|
+
mcp?: {
|
|
45
|
+
enabled: boolean;
|
|
46
|
+
kind?: "prompt";
|
|
47
|
+
tenantSafe?: boolean;
|
|
48
|
+
};
|
|
49
|
+
render: (input: unknown, args: {
|
|
50
|
+
context: ExecutionContext;
|
|
51
|
+
}) => Promise<string> | string;
|
|
52
|
+
}
|
|
53
|
+
export declare class Registry<T extends {
|
|
54
|
+
id: string;
|
|
55
|
+
accessModes?: AccessMode[];
|
|
56
|
+
}> {
|
|
57
|
+
private readonly values;
|
|
58
|
+
add(entry: T): void;
|
|
59
|
+
get(id: string): T;
|
|
60
|
+
list(context?: ExecutionContext): T[];
|
|
61
|
+
}
|
|
62
|
+
export declare const renderInsightPromptSchema: z.ZodObject<{
|
|
63
|
+
request: z.ZodCustom<{
|
|
64
|
+
question: string;
|
|
65
|
+
resourceIds: string[];
|
|
66
|
+
structuredQueries: {
|
|
67
|
+
connectorId: string;
|
|
68
|
+
request: {
|
|
69
|
+
surface: string;
|
|
70
|
+
select: string[];
|
|
71
|
+
filters: {
|
|
72
|
+
field: string;
|
|
73
|
+
op: "in" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte";
|
|
74
|
+
value: unknown;
|
|
75
|
+
}[];
|
|
76
|
+
orderBy: {
|
|
77
|
+
field: string;
|
|
78
|
+
direction: "asc" | "desc";
|
|
79
|
+
}[];
|
|
80
|
+
limit: number;
|
|
81
|
+
accessLevel: "system" | "serving";
|
|
82
|
+
};
|
|
83
|
+
}[];
|
|
84
|
+
knowledgeQueries: {
|
|
85
|
+
connectorId: string;
|
|
86
|
+
request: {
|
|
87
|
+
searches: {
|
|
88
|
+
type: "lex" | "vec" | "hyde";
|
|
89
|
+
query: string;
|
|
90
|
+
}[];
|
|
91
|
+
collections: string[];
|
|
92
|
+
limit: number;
|
|
93
|
+
minScore: number;
|
|
94
|
+
rerank: boolean;
|
|
95
|
+
query?: string | undefined;
|
|
96
|
+
intent?: string | undefined;
|
|
97
|
+
};
|
|
98
|
+
}[];
|
|
99
|
+
maxFindings: number;
|
|
100
|
+
promptId?: string | undefined;
|
|
101
|
+
}, {
|
|
102
|
+
question: string;
|
|
103
|
+
resourceIds: string[];
|
|
104
|
+
structuredQueries: {
|
|
105
|
+
connectorId: string;
|
|
106
|
+
request: {
|
|
107
|
+
surface: string;
|
|
108
|
+
select: string[];
|
|
109
|
+
filters: {
|
|
110
|
+
field: string;
|
|
111
|
+
op: "in" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte";
|
|
112
|
+
value: unknown;
|
|
113
|
+
}[];
|
|
114
|
+
orderBy: {
|
|
115
|
+
field: string;
|
|
116
|
+
direction: "asc" | "desc";
|
|
117
|
+
}[];
|
|
118
|
+
limit: number;
|
|
119
|
+
accessLevel: "system" | "serving";
|
|
120
|
+
};
|
|
121
|
+
}[];
|
|
122
|
+
knowledgeQueries: {
|
|
123
|
+
connectorId: string;
|
|
124
|
+
request: {
|
|
125
|
+
searches: {
|
|
126
|
+
type: "lex" | "vec" | "hyde";
|
|
127
|
+
query: string;
|
|
128
|
+
}[];
|
|
129
|
+
collections: string[];
|
|
130
|
+
limit: number;
|
|
131
|
+
minScore: number;
|
|
132
|
+
rerank: boolean;
|
|
133
|
+
query?: string | undefined;
|
|
134
|
+
intent?: string | undefined;
|
|
135
|
+
};
|
|
136
|
+
}[];
|
|
137
|
+
maxFindings: number;
|
|
138
|
+
promptId?: string | undefined;
|
|
139
|
+
}>;
|
|
140
|
+
insight: z.ZodOptional<z.ZodCustom<{
|
|
141
|
+
question: string;
|
|
142
|
+
summary: string;
|
|
143
|
+
findings: {
|
|
144
|
+
id: string;
|
|
145
|
+
title: string;
|
|
146
|
+
summary: string;
|
|
147
|
+
confidence: number;
|
|
148
|
+
evidence: {
|
|
149
|
+
kind: "structured_row" | "knowledge_doc" | "resource" | "prompt";
|
|
150
|
+
connectorId?: string | undefined;
|
|
151
|
+
resourceId?: string | undefined;
|
|
152
|
+
surface?: string | undefined;
|
|
153
|
+
rowIndex?: number | undefined;
|
|
154
|
+
path?: string | undefined;
|
|
155
|
+
docId?: string | undefined;
|
|
156
|
+
snippet?: string | undefined;
|
|
157
|
+
label?: string | undefined;
|
|
158
|
+
}[];
|
|
159
|
+
chartIntents: {
|
|
160
|
+
type: "table" | "line" | "bar" | "metric" | "timeline";
|
|
161
|
+
title: string;
|
|
162
|
+
datasetId: string;
|
|
163
|
+
rationale: string;
|
|
164
|
+
xField?: string | undefined;
|
|
165
|
+
yField?: string | undefined;
|
|
166
|
+
groupBy?: string | undefined;
|
|
167
|
+
}[];
|
|
168
|
+
}[];
|
|
169
|
+
datasets: {
|
|
170
|
+
id: string;
|
|
171
|
+
label: string;
|
|
172
|
+
connectorId: string;
|
|
173
|
+
kind: "structured" | "knowledge";
|
|
174
|
+
columns: {
|
|
175
|
+
name: string;
|
|
176
|
+
dataType: string;
|
|
177
|
+
nullable: boolean;
|
|
178
|
+
}[];
|
|
179
|
+
rows: Record<string, unknown>[];
|
|
180
|
+
docs: {
|
|
181
|
+
connectorId: string;
|
|
182
|
+
path: string;
|
|
183
|
+
collection?: string | undefined;
|
|
184
|
+
docId?: string | undefined;
|
|
185
|
+
title?: string | undefined;
|
|
186
|
+
snippet?: string | undefined;
|
|
187
|
+
score?: number | undefined;
|
|
188
|
+
context?: string | undefined;
|
|
189
|
+
}[];
|
|
190
|
+
metadata: Record<string, unknown>;
|
|
191
|
+
}[];
|
|
192
|
+
evidence: {
|
|
193
|
+
kind: "structured_row" | "knowledge_doc" | "resource" | "prompt";
|
|
194
|
+
connectorId?: string | undefined;
|
|
195
|
+
resourceId?: string | undefined;
|
|
196
|
+
surface?: string | undefined;
|
|
197
|
+
rowIndex?: number | undefined;
|
|
198
|
+
path?: string | undefined;
|
|
199
|
+
docId?: string | undefined;
|
|
200
|
+
snippet?: string | undefined;
|
|
201
|
+
label?: string | undefined;
|
|
202
|
+
}[];
|
|
203
|
+
warnings: string[];
|
|
204
|
+
prompt?: string | undefined;
|
|
205
|
+
}, {
|
|
206
|
+
question: string;
|
|
207
|
+
summary: string;
|
|
208
|
+
findings: {
|
|
209
|
+
id: string;
|
|
210
|
+
title: string;
|
|
211
|
+
summary: string;
|
|
212
|
+
confidence: number;
|
|
213
|
+
evidence: {
|
|
214
|
+
kind: "structured_row" | "knowledge_doc" | "resource" | "prompt";
|
|
215
|
+
connectorId?: string | undefined;
|
|
216
|
+
resourceId?: string | undefined;
|
|
217
|
+
surface?: string | undefined;
|
|
218
|
+
rowIndex?: number | undefined;
|
|
219
|
+
path?: string | undefined;
|
|
220
|
+
docId?: string | undefined;
|
|
221
|
+
snippet?: string | undefined;
|
|
222
|
+
label?: string | undefined;
|
|
223
|
+
}[];
|
|
224
|
+
chartIntents: {
|
|
225
|
+
type: "table" | "line" | "bar" | "metric" | "timeline";
|
|
226
|
+
title: string;
|
|
227
|
+
datasetId: string;
|
|
228
|
+
rationale: string;
|
|
229
|
+
xField?: string | undefined;
|
|
230
|
+
yField?: string | undefined;
|
|
231
|
+
groupBy?: string | undefined;
|
|
232
|
+
}[];
|
|
233
|
+
}[];
|
|
234
|
+
datasets: {
|
|
235
|
+
id: string;
|
|
236
|
+
label: string;
|
|
237
|
+
connectorId: string;
|
|
238
|
+
kind: "structured" | "knowledge";
|
|
239
|
+
columns: {
|
|
240
|
+
name: string;
|
|
241
|
+
dataType: string;
|
|
242
|
+
nullable: boolean;
|
|
243
|
+
}[];
|
|
244
|
+
rows: Record<string, unknown>[];
|
|
245
|
+
docs: {
|
|
246
|
+
connectorId: string;
|
|
247
|
+
path: string;
|
|
248
|
+
collection?: string | undefined;
|
|
249
|
+
docId?: string | undefined;
|
|
250
|
+
title?: string | undefined;
|
|
251
|
+
snippet?: string | undefined;
|
|
252
|
+
score?: number | undefined;
|
|
253
|
+
context?: string | undefined;
|
|
254
|
+
}[];
|
|
255
|
+
metadata: Record<string, unknown>;
|
|
256
|
+
}[];
|
|
257
|
+
evidence: {
|
|
258
|
+
kind: "structured_row" | "knowledge_doc" | "resource" | "prompt";
|
|
259
|
+
connectorId?: string | undefined;
|
|
260
|
+
resourceId?: string | undefined;
|
|
261
|
+
surface?: string | undefined;
|
|
262
|
+
rowIndex?: number | undefined;
|
|
263
|
+
path?: string | undefined;
|
|
264
|
+
docId?: string | undefined;
|
|
265
|
+
snippet?: string | undefined;
|
|
266
|
+
label?: string | undefined;
|
|
267
|
+
}[];
|
|
268
|
+
warnings: string[];
|
|
269
|
+
prompt?: string | undefined;
|
|
270
|
+
}>>;
|
|
271
|
+
}, z.core.$strip>;
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export class Registry {
|
|
3
|
+
values = new Map();
|
|
4
|
+
add(entry) {
|
|
5
|
+
if (this.values.has(entry.id)) {
|
|
6
|
+
throw new Error(`duplicate registry entry: ${entry.id}`);
|
|
7
|
+
}
|
|
8
|
+
this.values.set(entry.id, entry);
|
|
9
|
+
}
|
|
10
|
+
get(id) {
|
|
11
|
+
const entry = this.values.get(id);
|
|
12
|
+
if (!entry) {
|
|
13
|
+
throw new Error(`unknown registry entry: ${id}`);
|
|
14
|
+
}
|
|
15
|
+
return entry;
|
|
16
|
+
}
|
|
17
|
+
list(context) {
|
|
18
|
+
if (!context) {
|
|
19
|
+
return [...this.values.values()];
|
|
20
|
+
}
|
|
21
|
+
return [...this.values.values()].filter((entry) => {
|
|
22
|
+
if (!entry.accessModes || entry.accessModes.length === 0) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return entry.accessModes.includes(context.accessMode);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export const renderInsightPromptSchema = z.object({
|
|
30
|
+
request: z.custom(),
|
|
31
|
+
insight: z.custom().optional()
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAgB,MAAM,KAAK,CAAC;AAyDtC,MAAM,OAAO,QAAQ;IACF,MAAM,GAAG,IAAI,GAAG,EAAa,CAAC;IAE/C,GAAG,CAAC,KAAQ;QACV,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,6BAA6B,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;QAC3D,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,GAAG,CAAC,EAAU;QACZ,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC,OAA0B;QAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YAChD,IAAI,CAAC,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACzD,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChD,OAAO,EAAE,CAAC,CAAC,MAAM,EAAkB;IACnC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAiB,CAAC,QAAQ,EAAE;CAC9C,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ExecutionContext, type InsightBundle, type InsightRequest, type KnowledgeQueryResult, type StructuredQueryResult } from "../contracts.js";
|
|
2
|
+
export interface InsightContextData {
|
|
3
|
+
request: InsightRequest;
|
|
4
|
+
context: ExecutionContext;
|
|
5
|
+
prompt?: string;
|
|
6
|
+
resources: Array<{
|
|
7
|
+
id: string;
|
|
8
|
+
value: unknown;
|
|
9
|
+
}>;
|
|
10
|
+
structuredResults: Array<{
|
|
11
|
+
queryId: string;
|
|
12
|
+
result: StructuredQueryResult;
|
|
13
|
+
}>;
|
|
14
|
+
knowledgeResults: Array<{
|
|
15
|
+
queryId: string;
|
|
16
|
+
result: KnowledgeQueryResult;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
export interface InsightEngine {
|
|
20
|
+
generate(input: InsightContextData): Promise<InsightBundle>;
|
|
21
|
+
}
|
|
22
|
+
export declare class DeterministicInsightEngine implements InsightEngine {
|
|
23
|
+
generate(input: InsightContextData): Promise<InsightBundle>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { insightBundleSchema, insightRequestSchema } from "../contracts.js";
|
|
2
|
+
export class DeterministicInsightEngine {
|
|
3
|
+
async generate(input) {
|
|
4
|
+
const request = insightRequestSchema.parse(input.request);
|
|
5
|
+
const datasets = [];
|
|
6
|
+
const evidence = [];
|
|
7
|
+
const findings = [];
|
|
8
|
+
const warnings = [];
|
|
9
|
+
for (const item of input.structuredResults) {
|
|
10
|
+
const datasetId = `dataset:${item.queryId}`;
|
|
11
|
+
datasets.push({
|
|
12
|
+
id: datasetId,
|
|
13
|
+
label: item.result.surface,
|
|
14
|
+
connectorId: item.result.connectorId,
|
|
15
|
+
kind: "structured",
|
|
16
|
+
columns: item.result.columns,
|
|
17
|
+
rows: item.result.rows,
|
|
18
|
+
docs: [],
|
|
19
|
+
metadata: {
|
|
20
|
+
rowCount: item.result.rowCount,
|
|
21
|
+
surface: item.result.surface
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
evidence.push(...item.result.provenance);
|
|
25
|
+
findings.push({
|
|
26
|
+
id: `finding:${item.queryId}`,
|
|
27
|
+
title: `${item.result.surface} returned ${item.result.rowCount} rows`,
|
|
28
|
+
summary: describeStructuredFinding(item.result),
|
|
29
|
+
confidence: item.result.rowCount > 0 ? 0.74 : 0.32,
|
|
30
|
+
evidence: item.result.provenance,
|
|
31
|
+
chartIntents: buildChartIntents(datasetId, item.result)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
for (const item of input.knowledgeResults) {
|
|
35
|
+
const datasetId = `dataset:${item.queryId}`;
|
|
36
|
+
datasets.push({
|
|
37
|
+
id: datasetId,
|
|
38
|
+
label: `${item.result.connectorId} knowledge hits`,
|
|
39
|
+
connectorId: item.result.connectorId,
|
|
40
|
+
kind: "knowledge",
|
|
41
|
+
columns: [],
|
|
42
|
+
rows: [],
|
|
43
|
+
docs: item.result.hits,
|
|
44
|
+
metadata: {
|
|
45
|
+
totalHits: item.result.totalHits
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
evidence.push(...item.result.provenance);
|
|
49
|
+
findings.push({
|
|
50
|
+
id: `finding:${item.queryId}`,
|
|
51
|
+
title: `${item.result.totalHits} knowledge hits from ${item.result.connectorId}`,
|
|
52
|
+
summary: describeKnowledgeFinding(item.result),
|
|
53
|
+
confidence: item.result.totalHits > 0 ? 0.66 : 0.25,
|
|
54
|
+
evidence: item.result.provenance,
|
|
55
|
+
chartIntents: item.result.totalHits > 0 ? [{
|
|
56
|
+
type: "table",
|
|
57
|
+
title: `${item.result.connectorId} supporting documents`,
|
|
58
|
+
datasetId,
|
|
59
|
+
rationale: "Use a table when the supporting evidence is document-centric."
|
|
60
|
+
}] : []
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (findings.length === 0) {
|
|
64
|
+
warnings.push("No structured or knowledge evidence was available for this insight request.");
|
|
65
|
+
}
|
|
66
|
+
const summary = [
|
|
67
|
+
`Question: ${request.question}`,
|
|
68
|
+
`${input.structuredResults.length} structured query set(s)`,
|
|
69
|
+
`${input.knowledgeResults.length} knowledge query set(s)`,
|
|
70
|
+
`${findings.length} finding(s)`
|
|
71
|
+
].join(" | ");
|
|
72
|
+
return insightBundleSchema.parse({
|
|
73
|
+
question: request.question,
|
|
74
|
+
summary,
|
|
75
|
+
findings: findings.slice(0, request.maxFindings),
|
|
76
|
+
datasets,
|
|
77
|
+
evidence,
|
|
78
|
+
warnings,
|
|
79
|
+
prompt: input.prompt
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function describeStructuredFinding(result) {
|
|
84
|
+
if (result.rowCount === 0) {
|
|
85
|
+
return `No rows matched ${result.surface}.`;
|
|
86
|
+
}
|
|
87
|
+
const sample = result.rows[0];
|
|
88
|
+
const preview = sample
|
|
89
|
+
? Object.entries(sample).slice(0, 3).map(([key, value]) => `${key}=${String(value)}`).join(", ")
|
|
90
|
+
: "no sample values";
|
|
91
|
+
return `${result.surface} produced ${result.rowCount} row(s). Sample: ${preview}.`;
|
|
92
|
+
}
|
|
93
|
+
function describeKnowledgeFinding(result) {
|
|
94
|
+
if (result.totalHits === 0) {
|
|
95
|
+
return `No supporting documents were found in ${result.connectorId}.`;
|
|
96
|
+
}
|
|
97
|
+
const firstHit = result.hits[0];
|
|
98
|
+
return `Top supporting document: ${firstHit?.title ?? firstHit?.path ?? "unknown"} with ${result.totalHits} total hit(s).`;
|
|
99
|
+
}
|
|
100
|
+
function buildChartIntents(datasetId, result) {
|
|
101
|
+
const numericFields = result.columns.filter((field) => isNumericField(field));
|
|
102
|
+
const timeField = result.columns.find((field) => /(time|_at)$/.test(field.name));
|
|
103
|
+
const categoryField = result.columns.find((field) => !isNumericField(field) && field.name !== timeField?.name);
|
|
104
|
+
if (numericFields.length === 0) {
|
|
105
|
+
return [{
|
|
106
|
+
type: "table",
|
|
107
|
+
title: `${result.surface} records`,
|
|
108
|
+
datasetId,
|
|
109
|
+
rationale: "A table is the safest default when no numeric measures are present."
|
|
110
|
+
}];
|
|
111
|
+
}
|
|
112
|
+
if (result.rowCount === 1) {
|
|
113
|
+
return [{
|
|
114
|
+
type: "metric",
|
|
115
|
+
title: `${numericFields[0].name} latest value`,
|
|
116
|
+
datasetId,
|
|
117
|
+
yField: numericFields[0].name,
|
|
118
|
+
rationale: "Single-row numeric result is best presented as a metric."
|
|
119
|
+
}];
|
|
120
|
+
}
|
|
121
|
+
if (timeField) {
|
|
122
|
+
return [{
|
|
123
|
+
type: "line",
|
|
124
|
+
title: `${numericFields[0].name} over time`,
|
|
125
|
+
datasetId,
|
|
126
|
+
xField: timeField.name,
|
|
127
|
+
yField: numericFields[0].name,
|
|
128
|
+
rationale: "Time-series data should default to a line chart."
|
|
129
|
+
}];
|
|
130
|
+
}
|
|
131
|
+
if (categoryField) {
|
|
132
|
+
return [{
|
|
133
|
+
type: "bar",
|
|
134
|
+
title: `${numericFields[0].name} by ${categoryField.name}`,
|
|
135
|
+
datasetId,
|
|
136
|
+
xField: categoryField.name,
|
|
137
|
+
yField: numericFields[0].name,
|
|
138
|
+
rationale: "Grouped numeric values should default to a bar chart."
|
|
139
|
+
}];
|
|
140
|
+
}
|
|
141
|
+
return [{
|
|
142
|
+
type: "table",
|
|
143
|
+
title: `${result.surface} records`,
|
|
144
|
+
datasetId,
|
|
145
|
+
rationale: "Fallback to table when no safe visual encoding is obvious."
|
|
146
|
+
}];
|
|
147
|
+
}
|
|
148
|
+
function isNumericField(field) {
|
|
149
|
+
return /int|numeric|real|double|decimal|number/i.test(field.dataType);
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/runtime/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EAUrB,MAAM,iBAAiB,CAAC;AAezB,MAAM,OAAO,0BAA0B;IACrC,KAAK,CAAC,QAAQ,CAAC,KAAyB;QACtC,MAAM,OAAO,GAAG,oBAAoB,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1D,MAAM,QAAQ,GAAkB,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAoB,EAAE,CAAC;QACrC,MAAM,QAAQ,GAA8B,EAAE,CAAC;QAC/C,MAAM,QAAQ,GAAa,EAAE,CAAC;QAE9B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC3C,MAAM,SAAS,GAAG,WAAW,IAAI,CAAC,OAAO,EAAE,CAAC;YAC5C,QAAQ,CAAC,IAAI,CAAC;gBACZ,EAAE,EAAE,SAAS;gBACb,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;gBAC1B,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;gBACpC,IAAI,EAAE,YAAY;gBAClB,OA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gBACtB,MAAM,EAAE,aAAa,CAAC,CAAC,CAAE,CAAC,IAAI;gBAC9B,SAAS,EAAE,kDAAkD;aAC9D,CAAC,CAAC;IACL,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,CAAC;gBACN,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,GAAG,aAAa,CAAC,CAAC,CAAE,CAAC,IAAI,OAAO,aAAa,CAAC,IAAI,EAAE;gBAC3D,SAAS;gBACT,MAAM,EAAE,aAAa,CAAC,IAAI;gBAC1B,MAAM,EAAE,aAAa,CAAC,CAAC,CAAE,CAAC,IAAI;gBAC9B,SAAS,EAAE,uDAAuD;aACnE,CAAC,CAAC;IACL,CAAC;IAED,OAAO,CAAC;YACN,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,GAAG,MAAM,CAAC,OAAO,UAAU;YAClC,SAAS;YACT,SAAS,EAAE,4DAA4D;SACxE,CAAC,CAAC;AACL,CAAC;AAED,SAAS,cAAc,CAAC,KAAsB;IAC5C,OAAO,yCAAyC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AACxE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mote-core",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Platform-neutral kernel contracts and orchestration for mote.",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/liy/mote-app.git",
|
|
22
|
+
"directory": "mote-core"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/liy/mote-app/tree/main/mote-core",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/liy/mote-app/issues"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"mote",
|
|
30
|
+
"kernel",
|
|
31
|
+
"analytics",
|
|
32
|
+
"mcp",
|
|
33
|
+
"cross-platform"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=20.0.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"zod": "^4.2.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^24.5.2",
|
|
43
|
+
"typescript": "^5.9.3",
|
|
44
|
+
"vitest": "^3.2.4"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
50
|
+
}
|
|
51
|
+
}
|