@kagan-sh/opensearch 0.1.0
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/CONTRIBUTING.md +104 -0
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/SKILL.md +53 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.js +66 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +276 -0
- package/dist/orchestrator.d.ts +60 -0
- package/dist/orchestrator.js +152 -0
- package/dist/schema.d.ts +419 -0
- package/dist/schema.js +100 -0
- package/dist/sources/code.d.ts +3 -0
- package/dist/sources/code.js +36 -0
- package/dist/sources/session.d.ts +4 -0
- package/dist/sources/session.js +75 -0
- package/dist/sources/shared.d.ts +9 -0
- package/dist/sources/shared.js +19 -0
- package/dist/sources/web.d.ts +3 -0
- package/dist/sources/web.js +53 -0
- package/dist/synth.d.ts +3 -0
- package/dist/synth.js +79 -0
- package/package.json +62 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { searchCode } from "./sources/code";
|
|
2
|
+
import { searchSessions } from "./sources/session";
|
|
3
|
+
import { searchWeb } from "./sources/web";
|
|
4
|
+
function clampUnit(value) {
|
|
5
|
+
return Math.max(0, Math.min(1, value));
|
|
6
|
+
}
|
|
7
|
+
export function normalize(raw) {
|
|
8
|
+
return {
|
|
9
|
+
id: raw.id,
|
|
10
|
+
type: raw.type,
|
|
11
|
+
title: raw.title,
|
|
12
|
+
snippet: raw.snippet,
|
|
13
|
+
url: raw.url,
|
|
14
|
+
relevance: clampUnit(raw.relevance),
|
|
15
|
+
timestamp: raw.timestamp,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function resultMeta(input) {
|
|
19
|
+
return {
|
|
20
|
+
query: input.query,
|
|
21
|
+
duration: Date.now() - input.start,
|
|
22
|
+
sources_requested: input.requested.length,
|
|
23
|
+
sources_queried: input.queried.length,
|
|
24
|
+
sources_yielded: input.yielded,
|
|
25
|
+
sources_unavailable: input.unavailable,
|
|
26
|
+
source_errors: input.sourceErrors,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function createResult(input) {
|
|
30
|
+
return {
|
|
31
|
+
status: input.status,
|
|
32
|
+
answer: input.answer,
|
|
33
|
+
confidence: input.confidence,
|
|
34
|
+
evidence: input.evidence,
|
|
35
|
+
sources: input.sources,
|
|
36
|
+
followups: input.followups,
|
|
37
|
+
meta: input.meta,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export async function runSourceSearches(input) {
|
|
41
|
+
const outcomes = await Promise.all(input.sources.map((source) => {
|
|
42
|
+
if (source === "session") {
|
|
43
|
+
return searchSessions(input.client, input.directory, input.query, input.depth);
|
|
44
|
+
}
|
|
45
|
+
if (source === "web") {
|
|
46
|
+
return searchWeb(input.query, input.config.sources.web.key, input.depth);
|
|
47
|
+
}
|
|
48
|
+
return searchCode(input.query, input.depth);
|
|
49
|
+
}));
|
|
50
|
+
return {
|
|
51
|
+
raw: outcomes.flatMap((outcome) => outcome.results),
|
|
52
|
+
sourceErrors: outcomes.flatMap((outcome) => outcome.error ? [outcome.error] : []),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export function noSourcesResult(input) {
|
|
56
|
+
return createResult({
|
|
57
|
+
status: "no_sources",
|
|
58
|
+
answer: "No sources available",
|
|
59
|
+
confidence: "none",
|
|
60
|
+
evidence: [],
|
|
61
|
+
sources: [],
|
|
62
|
+
followups: [
|
|
63
|
+
"Enable at least one search source in opensearch config",
|
|
64
|
+
"Set OPENSEARCH_WEB_KEY or EXA_API_KEY to enable web search",
|
|
65
|
+
],
|
|
66
|
+
meta: resultMeta({
|
|
67
|
+
query: input.query,
|
|
68
|
+
start: input.start,
|
|
69
|
+
requested: input.requested,
|
|
70
|
+
queried: [],
|
|
71
|
+
yielded: 0,
|
|
72
|
+
unavailable: input.unavailable,
|
|
73
|
+
sourceErrors: [],
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export function noResultsResult(input) {
|
|
78
|
+
const followups = [
|
|
79
|
+
`Use broader terms for: ${input.query}`,
|
|
80
|
+
`Search only web for: ${input.query}`,
|
|
81
|
+
];
|
|
82
|
+
if (input.sourceErrors.length > 0) {
|
|
83
|
+
followups.unshift("Inspect meta.source_errors for failed search sources");
|
|
84
|
+
}
|
|
85
|
+
return createResult({
|
|
86
|
+
status: "no_results",
|
|
87
|
+
answer: "No results found",
|
|
88
|
+
confidence: "none",
|
|
89
|
+
evidence: [],
|
|
90
|
+
sources: [],
|
|
91
|
+
followups,
|
|
92
|
+
meta: resultMeta({
|
|
93
|
+
query: input.query,
|
|
94
|
+
start: input.start,
|
|
95
|
+
requested: input.requested,
|
|
96
|
+
queried: input.queried,
|
|
97
|
+
yielded: 0,
|
|
98
|
+
unavailable: input.unavailable,
|
|
99
|
+
sourceErrors: input.sourceErrors,
|
|
100
|
+
}),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
export function rawResultsResult(input) {
|
|
104
|
+
const answer = input.status === "raw"
|
|
105
|
+
? "Raw results (synthesis disabled)"
|
|
106
|
+
: "Unable to synthesize structured answer. Returning raw evidence.";
|
|
107
|
+
const followups = input.status === "raw"
|
|
108
|
+
? [
|
|
109
|
+
`Enable synthesis for: ${input.query}`,
|
|
110
|
+
`Filter to one source for: ${input.query}`,
|
|
111
|
+
]
|
|
112
|
+
: [
|
|
113
|
+
`Refine: ${input.query}`,
|
|
114
|
+
`Find contradictory sources for: ${input.query}`,
|
|
115
|
+
];
|
|
116
|
+
return createResult({
|
|
117
|
+
status: input.status,
|
|
118
|
+
answer,
|
|
119
|
+
confidence: "none",
|
|
120
|
+
evidence: [],
|
|
121
|
+
sources: input.raw.map(normalize),
|
|
122
|
+
followups,
|
|
123
|
+
meta: resultMeta({
|
|
124
|
+
query: input.query,
|
|
125
|
+
start: input.start,
|
|
126
|
+
requested: input.requested,
|
|
127
|
+
queried: input.queried,
|
|
128
|
+
yielded: input.raw.length,
|
|
129
|
+
unavailable: input.unavailable,
|
|
130
|
+
sourceErrors: input.sourceErrors,
|
|
131
|
+
}),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
export function synthesizedResult(input) {
|
|
135
|
+
return createResult({
|
|
136
|
+
status: "ok",
|
|
137
|
+
answer: input.synthesis.answer,
|
|
138
|
+
confidence: input.synthesis.confidence,
|
|
139
|
+
evidence: input.synthesis.evidence,
|
|
140
|
+
sources: input.raw.map(normalize),
|
|
141
|
+
followups: input.synthesis.followups,
|
|
142
|
+
meta: resultMeta({
|
|
143
|
+
query: input.query,
|
|
144
|
+
start: input.start,
|
|
145
|
+
requested: input.requested,
|
|
146
|
+
queried: input.queried,
|
|
147
|
+
yielded: input.raw.length,
|
|
148
|
+
unavailable: input.unavailable,
|
|
149
|
+
sourceErrors: input.sourceErrors,
|
|
150
|
+
}),
|
|
151
|
+
});
|
|
152
|
+
}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const SOURCE_IDS: readonly ["session", "web", "code"];
|
|
3
|
+
export declare const DEPTHS: readonly ["quick", "thorough"];
|
|
4
|
+
export declare const RESULT_STATUSES: readonly ["ok", "raw", "raw_fallback", "no_sources", "no_results"];
|
|
5
|
+
export declare const SourceIdSchema: z.ZodEnum<["session", "web", "code"]>;
|
|
6
|
+
export declare const DepthSchema: z.ZodEnum<["quick", "thorough"]>;
|
|
7
|
+
export declare const ResultStatusSchema: z.ZodEnum<["ok", "raw", "raw_fallback", "no_sources", "no_results"]>;
|
|
8
|
+
export declare const SourceSchema: z.ZodObject<{
|
|
9
|
+
id: z.ZodString;
|
|
10
|
+
type: z.ZodEnum<["session", "web", "code"]>;
|
|
11
|
+
url: z.ZodOptional<z.ZodString>;
|
|
12
|
+
title: z.ZodString;
|
|
13
|
+
snippet: z.ZodString;
|
|
14
|
+
relevance: z.ZodNumber;
|
|
15
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
16
|
+
}, "strict", z.ZodTypeAny, {
|
|
17
|
+
id: string;
|
|
18
|
+
type: "session" | "web" | "code";
|
|
19
|
+
title: string;
|
|
20
|
+
snippet: string;
|
|
21
|
+
relevance: number;
|
|
22
|
+
url?: string | undefined;
|
|
23
|
+
timestamp?: number | undefined;
|
|
24
|
+
}, {
|
|
25
|
+
id: string;
|
|
26
|
+
type: "session" | "web" | "code";
|
|
27
|
+
title: string;
|
|
28
|
+
snippet: string;
|
|
29
|
+
relevance: number;
|
|
30
|
+
url?: string | undefined;
|
|
31
|
+
timestamp?: number | undefined;
|
|
32
|
+
}>;
|
|
33
|
+
export declare const SourceErrorSchema: z.ZodObject<{
|
|
34
|
+
source: z.ZodEnum<["session", "web", "code"]>;
|
|
35
|
+
code: z.ZodEnum<["unavailable", "request_failed", "invalid_response"]>;
|
|
36
|
+
message: z.ZodString;
|
|
37
|
+
}, "strict", z.ZodTypeAny, {
|
|
38
|
+
code: "unavailable" | "request_failed" | "invalid_response";
|
|
39
|
+
message: string;
|
|
40
|
+
source: "session" | "web" | "code";
|
|
41
|
+
}, {
|
|
42
|
+
code: "unavailable" | "request_failed" | "invalid_response";
|
|
43
|
+
message: string;
|
|
44
|
+
source: "session" | "web" | "code";
|
|
45
|
+
}>;
|
|
46
|
+
export declare const EvidenceSchema: z.ZodObject<{
|
|
47
|
+
claim: z.ZodString;
|
|
48
|
+
sources: z.ZodArray<z.ZodString, "many">;
|
|
49
|
+
confidence: z.ZodEnum<["high", "medium", "low"]>;
|
|
50
|
+
}, "strict", z.ZodTypeAny, {
|
|
51
|
+
claim: string;
|
|
52
|
+
sources: string[];
|
|
53
|
+
confidence: "high" | "medium" | "low";
|
|
54
|
+
}, {
|
|
55
|
+
claim: string;
|
|
56
|
+
sources: string[];
|
|
57
|
+
confidence: "high" | "medium" | "low";
|
|
58
|
+
}>;
|
|
59
|
+
export declare const ResultSchema: z.ZodObject<{
|
|
60
|
+
status: z.ZodEnum<["ok", "raw", "raw_fallback", "no_sources", "no_results"]>;
|
|
61
|
+
answer: z.ZodString;
|
|
62
|
+
confidence: z.ZodEnum<["high", "medium", "low", "none"]>;
|
|
63
|
+
evidence: z.ZodArray<z.ZodObject<{
|
|
64
|
+
claim: z.ZodString;
|
|
65
|
+
sources: z.ZodArray<z.ZodString, "many">;
|
|
66
|
+
confidence: z.ZodEnum<["high", "medium", "low"]>;
|
|
67
|
+
}, "strict", z.ZodTypeAny, {
|
|
68
|
+
claim: string;
|
|
69
|
+
sources: string[];
|
|
70
|
+
confidence: "high" | "medium" | "low";
|
|
71
|
+
}, {
|
|
72
|
+
claim: string;
|
|
73
|
+
sources: string[];
|
|
74
|
+
confidence: "high" | "medium" | "low";
|
|
75
|
+
}>, "many">;
|
|
76
|
+
sources: z.ZodArray<z.ZodObject<{
|
|
77
|
+
id: z.ZodString;
|
|
78
|
+
type: z.ZodEnum<["session", "web", "code"]>;
|
|
79
|
+
url: z.ZodOptional<z.ZodString>;
|
|
80
|
+
title: z.ZodString;
|
|
81
|
+
snippet: z.ZodString;
|
|
82
|
+
relevance: z.ZodNumber;
|
|
83
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
84
|
+
}, "strict", z.ZodTypeAny, {
|
|
85
|
+
id: string;
|
|
86
|
+
type: "session" | "web" | "code";
|
|
87
|
+
title: string;
|
|
88
|
+
snippet: string;
|
|
89
|
+
relevance: number;
|
|
90
|
+
url?: string | undefined;
|
|
91
|
+
timestamp?: number | undefined;
|
|
92
|
+
}, {
|
|
93
|
+
id: string;
|
|
94
|
+
type: "session" | "web" | "code";
|
|
95
|
+
title: string;
|
|
96
|
+
snippet: string;
|
|
97
|
+
relevance: number;
|
|
98
|
+
url?: string | undefined;
|
|
99
|
+
timestamp?: number | undefined;
|
|
100
|
+
}>, "many">;
|
|
101
|
+
followups: z.ZodArray<z.ZodString, "many">;
|
|
102
|
+
meta: z.ZodObject<{
|
|
103
|
+
query: z.ZodString;
|
|
104
|
+
duration: z.ZodNumber;
|
|
105
|
+
sources_requested: z.ZodNumber;
|
|
106
|
+
sources_queried: z.ZodNumber;
|
|
107
|
+
sources_yielded: z.ZodNumber;
|
|
108
|
+
sources_unavailable: z.ZodArray<z.ZodEnum<["session", "web", "code"]>, "many">;
|
|
109
|
+
source_errors: z.ZodArray<z.ZodObject<{
|
|
110
|
+
source: z.ZodEnum<["session", "web", "code"]>;
|
|
111
|
+
code: z.ZodEnum<["unavailable", "request_failed", "invalid_response"]>;
|
|
112
|
+
message: z.ZodString;
|
|
113
|
+
}, "strict", z.ZodTypeAny, {
|
|
114
|
+
code: "unavailable" | "request_failed" | "invalid_response";
|
|
115
|
+
message: string;
|
|
116
|
+
source: "session" | "web" | "code";
|
|
117
|
+
}, {
|
|
118
|
+
code: "unavailable" | "request_failed" | "invalid_response";
|
|
119
|
+
message: string;
|
|
120
|
+
source: "session" | "web" | "code";
|
|
121
|
+
}>, "many">;
|
|
122
|
+
}, "strict", z.ZodTypeAny, {
|
|
123
|
+
query: string;
|
|
124
|
+
duration: number;
|
|
125
|
+
sources_requested: number;
|
|
126
|
+
sources_queried: number;
|
|
127
|
+
sources_yielded: number;
|
|
128
|
+
sources_unavailable: ("session" | "web" | "code")[];
|
|
129
|
+
source_errors: {
|
|
130
|
+
code: "unavailable" | "request_failed" | "invalid_response";
|
|
131
|
+
message: string;
|
|
132
|
+
source: "session" | "web" | "code";
|
|
133
|
+
}[];
|
|
134
|
+
}, {
|
|
135
|
+
query: string;
|
|
136
|
+
duration: number;
|
|
137
|
+
sources_requested: number;
|
|
138
|
+
sources_queried: number;
|
|
139
|
+
sources_yielded: number;
|
|
140
|
+
sources_unavailable: ("session" | "web" | "code")[];
|
|
141
|
+
source_errors: {
|
|
142
|
+
code: "unavailable" | "request_failed" | "invalid_response";
|
|
143
|
+
message: string;
|
|
144
|
+
source: "session" | "web" | "code";
|
|
145
|
+
}[];
|
|
146
|
+
}>;
|
|
147
|
+
}, "strict", z.ZodTypeAny, {
|
|
148
|
+
status: "ok" | "raw" | "raw_fallback" | "no_sources" | "no_results";
|
|
149
|
+
sources: {
|
|
150
|
+
id: string;
|
|
151
|
+
type: "session" | "web" | "code";
|
|
152
|
+
title: string;
|
|
153
|
+
snippet: string;
|
|
154
|
+
relevance: number;
|
|
155
|
+
url?: string | undefined;
|
|
156
|
+
timestamp?: number | undefined;
|
|
157
|
+
}[];
|
|
158
|
+
confidence: "high" | "medium" | "low" | "none";
|
|
159
|
+
answer: string;
|
|
160
|
+
evidence: {
|
|
161
|
+
claim: string;
|
|
162
|
+
sources: string[];
|
|
163
|
+
confidence: "high" | "medium" | "low";
|
|
164
|
+
}[];
|
|
165
|
+
followups: string[];
|
|
166
|
+
meta: {
|
|
167
|
+
query: string;
|
|
168
|
+
duration: number;
|
|
169
|
+
sources_requested: number;
|
|
170
|
+
sources_queried: number;
|
|
171
|
+
sources_yielded: number;
|
|
172
|
+
sources_unavailable: ("session" | "web" | "code")[];
|
|
173
|
+
source_errors: {
|
|
174
|
+
code: "unavailable" | "request_failed" | "invalid_response";
|
|
175
|
+
message: string;
|
|
176
|
+
source: "session" | "web" | "code";
|
|
177
|
+
}[];
|
|
178
|
+
};
|
|
179
|
+
}, {
|
|
180
|
+
status: "ok" | "raw" | "raw_fallback" | "no_sources" | "no_results";
|
|
181
|
+
sources: {
|
|
182
|
+
id: string;
|
|
183
|
+
type: "session" | "web" | "code";
|
|
184
|
+
title: string;
|
|
185
|
+
snippet: string;
|
|
186
|
+
relevance: number;
|
|
187
|
+
url?: string | undefined;
|
|
188
|
+
timestamp?: number | undefined;
|
|
189
|
+
}[];
|
|
190
|
+
confidence: "high" | "medium" | "low" | "none";
|
|
191
|
+
answer: string;
|
|
192
|
+
evidence: {
|
|
193
|
+
claim: string;
|
|
194
|
+
sources: string[];
|
|
195
|
+
confidence: "high" | "medium" | "low";
|
|
196
|
+
}[];
|
|
197
|
+
followups: string[];
|
|
198
|
+
meta: {
|
|
199
|
+
query: string;
|
|
200
|
+
duration: number;
|
|
201
|
+
sources_requested: number;
|
|
202
|
+
sources_queried: number;
|
|
203
|
+
sources_yielded: number;
|
|
204
|
+
sources_unavailable: ("session" | "web" | "code")[];
|
|
205
|
+
source_errors: {
|
|
206
|
+
code: "unavailable" | "request_failed" | "invalid_response";
|
|
207
|
+
message: string;
|
|
208
|
+
source: "session" | "web" | "code";
|
|
209
|
+
}[];
|
|
210
|
+
};
|
|
211
|
+
}>;
|
|
212
|
+
export declare const SynthesisSchema: z.ZodObject<Omit<{
|
|
213
|
+
status: z.ZodEnum<["ok", "raw", "raw_fallback", "no_sources", "no_results"]>;
|
|
214
|
+
answer: z.ZodString;
|
|
215
|
+
confidence: z.ZodEnum<["high", "medium", "low", "none"]>;
|
|
216
|
+
evidence: z.ZodArray<z.ZodObject<{
|
|
217
|
+
claim: z.ZodString;
|
|
218
|
+
sources: z.ZodArray<z.ZodString, "many">;
|
|
219
|
+
confidence: z.ZodEnum<["high", "medium", "low"]>;
|
|
220
|
+
}, "strict", z.ZodTypeAny, {
|
|
221
|
+
claim: string;
|
|
222
|
+
sources: string[];
|
|
223
|
+
confidence: "high" | "medium" | "low";
|
|
224
|
+
}, {
|
|
225
|
+
claim: string;
|
|
226
|
+
sources: string[];
|
|
227
|
+
confidence: "high" | "medium" | "low";
|
|
228
|
+
}>, "many">;
|
|
229
|
+
sources: z.ZodArray<z.ZodObject<{
|
|
230
|
+
id: z.ZodString;
|
|
231
|
+
type: z.ZodEnum<["session", "web", "code"]>;
|
|
232
|
+
url: z.ZodOptional<z.ZodString>;
|
|
233
|
+
title: z.ZodString;
|
|
234
|
+
snippet: z.ZodString;
|
|
235
|
+
relevance: z.ZodNumber;
|
|
236
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
237
|
+
}, "strict", z.ZodTypeAny, {
|
|
238
|
+
id: string;
|
|
239
|
+
type: "session" | "web" | "code";
|
|
240
|
+
title: string;
|
|
241
|
+
snippet: string;
|
|
242
|
+
relevance: number;
|
|
243
|
+
url?: string | undefined;
|
|
244
|
+
timestamp?: number | undefined;
|
|
245
|
+
}, {
|
|
246
|
+
id: string;
|
|
247
|
+
type: "session" | "web" | "code";
|
|
248
|
+
title: string;
|
|
249
|
+
snippet: string;
|
|
250
|
+
relevance: number;
|
|
251
|
+
url?: string | undefined;
|
|
252
|
+
timestamp?: number | undefined;
|
|
253
|
+
}>, "many">;
|
|
254
|
+
followups: z.ZodArray<z.ZodString, "many">;
|
|
255
|
+
meta: z.ZodObject<{
|
|
256
|
+
query: z.ZodString;
|
|
257
|
+
duration: z.ZodNumber;
|
|
258
|
+
sources_requested: z.ZodNumber;
|
|
259
|
+
sources_queried: z.ZodNumber;
|
|
260
|
+
sources_yielded: z.ZodNumber;
|
|
261
|
+
sources_unavailable: z.ZodArray<z.ZodEnum<["session", "web", "code"]>, "many">;
|
|
262
|
+
source_errors: z.ZodArray<z.ZodObject<{
|
|
263
|
+
source: z.ZodEnum<["session", "web", "code"]>;
|
|
264
|
+
code: z.ZodEnum<["unavailable", "request_failed", "invalid_response"]>;
|
|
265
|
+
message: z.ZodString;
|
|
266
|
+
}, "strict", z.ZodTypeAny, {
|
|
267
|
+
code: "unavailable" | "request_failed" | "invalid_response";
|
|
268
|
+
message: string;
|
|
269
|
+
source: "session" | "web" | "code";
|
|
270
|
+
}, {
|
|
271
|
+
code: "unavailable" | "request_failed" | "invalid_response";
|
|
272
|
+
message: string;
|
|
273
|
+
source: "session" | "web" | "code";
|
|
274
|
+
}>, "many">;
|
|
275
|
+
}, "strict", z.ZodTypeAny, {
|
|
276
|
+
query: string;
|
|
277
|
+
duration: number;
|
|
278
|
+
sources_requested: number;
|
|
279
|
+
sources_queried: number;
|
|
280
|
+
sources_yielded: number;
|
|
281
|
+
sources_unavailable: ("session" | "web" | "code")[];
|
|
282
|
+
source_errors: {
|
|
283
|
+
code: "unavailable" | "request_failed" | "invalid_response";
|
|
284
|
+
message: string;
|
|
285
|
+
source: "session" | "web" | "code";
|
|
286
|
+
}[];
|
|
287
|
+
}, {
|
|
288
|
+
query: string;
|
|
289
|
+
duration: number;
|
|
290
|
+
sources_requested: number;
|
|
291
|
+
sources_queried: number;
|
|
292
|
+
sources_yielded: number;
|
|
293
|
+
sources_unavailable: ("session" | "web" | "code")[];
|
|
294
|
+
source_errors: {
|
|
295
|
+
code: "unavailable" | "request_failed" | "invalid_response";
|
|
296
|
+
message: string;
|
|
297
|
+
source: "session" | "web" | "code";
|
|
298
|
+
}[];
|
|
299
|
+
}>;
|
|
300
|
+
}, "status" | "sources" | "meta">, "strict", z.ZodTypeAny, {
|
|
301
|
+
confidence: "high" | "medium" | "low" | "none";
|
|
302
|
+
answer: string;
|
|
303
|
+
evidence: {
|
|
304
|
+
claim: string;
|
|
305
|
+
sources: string[];
|
|
306
|
+
confidence: "high" | "medium" | "low";
|
|
307
|
+
}[];
|
|
308
|
+
followups: string[];
|
|
309
|
+
}, {
|
|
310
|
+
confidence: "high" | "medium" | "low" | "none";
|
|
311
|
+
answer: string;
|
|
312
|
+
evidence: {
|
|
313
|
+
claim: string;
|
|
314
|
+
sources: string[];
|
|
315
|
+
confidence: "high" | "medium" | "low";
|
|
316
|
+
}[];
|
|
317
|
+
followups: string[];
|
|
318
|
+
}>;
|
|
319
|
+
export declare const RawResultSchema: z.ZodObject<{
|
|
320
|
+
id: z.ZodString;
|
|
321
|
+
type: z.ZodEnum<["session", "web", "code"]>;
|
|
322
|
+
title: z.ZodString;
|
|
323
|
+
snippet: z.ZodString;
|
|
324
|
+
url: z.ZodOptional<z.ZodString>;
|
|
325
|
+
relevance: z.ZodNumber;
|
|
326
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
327
|
+
}, "strict", z.ZodTypeAny, {
|
|
328
|
+
id: string;
|
|
329
|
+
type: "session" | "web" | "code";
|
|
330
|
+
title: string;
|
|
331
|
+
snippet: string;
|
|
332
|
+
relevance: number;
|
|
333
|
+
url?: string | undefined;
|
|
334
|
+
timestamp?: number | undefined;
|
|
335
|
+
}, {
|
|
336
|
+
id: string;
|
|
337
|
+
type: "session" | "web" | "code";
|
|
338
|
+
title: string;
|
|
339
|
+
snippet: string;
|
|
340
|
+
relevance: number;
|
|
341
|
+
url?: string | undefined;
|
|
342
|
+
timestamp?: number | undefined;
|
|
343
|
+
}>;
|
|
344
|
+
export declare const ConfigSchema: z.ZodObject<{
|
|
345
|
+
sources: z.ZodObject<{
|
|
346
|
+
session: z.ZodBoolean;
|
|
347
|
+
web: z.ZodObject<{
|
|
348
|
+
enabled: z.ZodBoolean;
|
|
349
|
+
key: z.ZodOptional<z.ZodString>;
|
|
350
|
+
}, "strict", z.ZodTypeAny, {
|
|
351
|
+
enabled: boolean;
|
|
352
|
+
key?: string | undefined;
|
|
353
|
+
}, {
|
|
354
|
+
enabled: boolean;
|
|
355
|
+
key?: string | undefined;
|
|
356
|
+
}>;
|
|
357
|
+
code: z.ZodBoolean;
|
|
358
|
+
}, "strict", z.ZodTypeAny, {
|
|
359
|
+
session: boolean;
|
|
360
|
+
web: {
|
|
361
|
+
enabled: boolean;
|
|
362
|
+
key?: string | undefined;
|
|
363
|
+
};
|
|
364
|
+
code: boolean;
|
|
365
|
+
}, {
|
|
366
|
+
session: boolean;
|
|
367
|
+
web: {
|
|
368
|
+
enabled: boolean;
|
|
369
|
+
key?: string | undefined;
|
|
370
|
+
};
|
|
371
|
+
code: boolean;
|
|
372
|
+
}>;
|
|
373
|
+
depth: z.ZodEnum<["quick", "thorough"]>;
|
|
374
|
+
synth: z.ZodBoolean;
|
|
375
|
+
}, "strict", z.ZodTypeAny, {
|
|
376
|
+
sources: {
|
|
377
|
+
session: boolean;
|
|
378
|
+
web: {
|
|
379
|
+
enabled: boolean;
|
|
380
|
+
key?: string | undefined;
|
|
381
|
+
};
|
|
382
|
+
code: boolean;
|
|
383
|
+
};
|
|
384
|
+
depth: "quick" | "thorough";
|
|
385
|
+
synth: boolean;
|
|
386
|
+
}, {
|
|
387
|
+
sources: {
|
|
388
|
+
session: boolean;
|
|
389
|
+
web: {
|
|
390
|
+
enabled: boolean;
|
|
391
|
+
key?: string | undefined;
|
|
392
|
+
};
|
|
393
|
+
code: boolean;
|
|
394
|
+
};
|
|
395
|
+
depth: "quick" | "thorough";
|
|
396
|
+
synth: boolean;
|
|
397
|
+
}>;
|
|
398
|
+
export type SourceId = z.infer<typeof SourceIdSchema>;
|
|
399
|
+
export type Depth = z.infer<typeof DepthSchema>;
|
|
400
|
+
export type ResultStatus = z.infer<typeof ResultStatusSchema>;
|
|
401
|
+
export type Source = z.infer<typeof SourceSchema>;
|
|
402
|
+
export type SourceError = z.infer<typeof SourceErrorSchema>;
|
|
403
|
+
export type Evidence = z.infer<typeof EvidenceSchema>;
|
|
404
|
+
export type Result = z.infer<typeof ResultSchema>;
|
|
405
|
+
export type Synthesis = z.infer<typeof SynthesisSchema>;
|
|
406
|
+
export type RawResult = z.infer<typeof RawResultSchema>;
|
|
407
|
+
export type Config = z.infer<typeof ConfigSchema>;
|
|
408
|
+
export declare function resultJsonSchema(): import("zod-to-json-schema").JsonSchema7Type & {
|
|
409
|
+
$schema?: string | undefined;
|
|
410
|
+
definitions?: {
|
|
411
|
+
[key: string]: import("zod-to-json-schema").JsonSchema7Type;
|
|
412
|
+
} | undefined;
|
|
413
|
+
};
|
|
414
|
+
export declare function synthesisJsonSchema(): import("zod-to-json-schema").JsonSchema7Type & {
|
|
415
|
+
$schema?: string | undefined;
|
|
416
|
+
definitions?: {
|
|
417
|
+
[key: string]: import("zod-to-json-schema").JsonSchema7Type;
|
|
418
|
+
} | undefined;
|
|
419
|
+
};
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
|
+
export const SOURCE_IDS = ["session", "web", "code"];
|
|
4
|
+
export const DEPTHS = ["quick", "thorough"];
|
|
5
|
+
export const RESULT_STATUSES = [
|
|
6
|
+
"ok",
|
|
7
|
+
"raw",
|
|
8
|
+
"raw_fallback",
|
|
9
|
+
"no_sources",
|
|
10
|
+
"no_results",
|
|
11
|
+
];
|
|
12
|
+
export const SourceIdSchema = z.enum(SOURCE_IDS);
|
|
13
|
+
export const DepthSchema = z.enum(DEPTHS);
|
|
14
|
+
export const ResultStatusSchema = z.enum(RESULT_STATUSES);
|
|
15
|
+
export const SourceSchema = z
|
|
16
|
+
.object({
|
|
17
|
+
id: z.string(),
|
|
18
|
+
type: SourceIdSchema,
|
|
19
|
+
url: z.string().optional(),
|
|
20
|
+
title: z.string(),
|
|
21
|
+
snippet: z.string(),
|
|
22
|
+
relevance: z.number().min(0).max(1),
|
|
23
|
+
timestamp: z.number().optional(),
|
|
24
|
+
})
|
|
25
|
+
.strict();
|
|
26
|
+
export const SourceErrorSchema = z
|
|
27
|
+
.object({
|
|
28
|
+
source: SourceIdSchema,
|
|
29
|
+
code: z.enum(["unavailable", "request_failed", "invalid_response"]),
|
|
30
|
+
message: z.string(),
|
|
31
|
+
})
|
|
32
|
+
.strict();
|
|
33
|
+
export const EvidenceSchema = z
|
|
34
|
+
.object({
|
|
35
|
+
claim: z.string(),
|
|
36
|
+
sources: z.array(z.string()),
|
|
37
|
+
confidence: z.enum(["high", "medium", "low"]),
|
|
38
|
+
})
|
|
39
|
+
.strict();
|
|
40
|
+
export const ResultSchema = z
|
|
41
|
+
.object({
|
|
42
|
+
status: ResultStatusSchema,
|
|
43
|
+
answer: z.string(),
|
|
44
|
+
confidence: z.enum(["high", "medium", "low", "none"]),
|
|
45
|
+
evidence: z.array(EvidenceSchema),
|
|
46
|
+
sources: z.array(SourceSchema),
|
|
47
|
+
followups: z.array(z.string()),
|
|
48
|
+
meta: z
|
|
49
|
+
.object({
|
|
50
|
+
query: z.string(),
|
|
51
|
+
duration: z.number(),
|
|
52
|
+
sources_requested: z.number(),
|
|
53
|
+
sources_queried: z.number(),
|
|
54
|
+
sources_yielded: z.number(),
|
|
55
|
+
sources_unavailable: z.array(SourceIdSchema),
|
|
56
|
+
source_errors: z.array(SourceErrorSchema),
|
|
57
|
+
})
|
|
58
|
+
.strict(),
|
|
59
|
+
})
|
|
60
|
+
.strict();
|
|
61
|
+
export const SynthesisSchema = ResultSchema.omit({
|
|
62
|
+
status: true,
|
|
63
|
+
sources: true,
|
|
64
|
+
meta: true,
|
|
65
|
+
});
|
|
66
|
+
export const RawResultSchema = z
|
|
67
|
+
.object({
|
|
68
|
+
id: z.string(),
|
|
69
|
+
type: SourceIdSchema,
|
|
70
|
+
title: z.string(),
|
|
71
|
+
snippet: z.string(),
|
|
72
|
+
url: z.string().optional(),
|
|
73
|
+
relevance: z.number(),
|
|
74
|
+
timestamp: z.number().optional(),
|
|
75
|
+
})
|
|
76
|
+
.strict();
|
|
77
|
+
export const ConfigSchema = z
|
|
78
|
+
.object({
|
|
79
|
+
sources: z
|
|
80
|
+
.object({
|
|
81
|
+
session: z.boolean(),
|
|
82
|
+
web: z
|
|
83
|
+
.object({
|
|
84
|
+
enabled: z.boolean(),
|
|
85
|
+
key: z.string().optional(),
|
|
86
|
+
})
|
|
87
|
+
.strict(),
|
|
88
|
+
code: z.boolean(),
|
|
89
|
+
})
|
|
90
|
+
.strict(),
|
|
91
|
+
depth: DepthSchema,
|
|
92
|
+
synth: z.boolean(),
|
|
93
|
+
})
|
|
94
|
+
.strict();
|
|
95
|
+
export function resultJsonSchema() {
|
|
96
|
+
return zodToJsonSchema(ResultSchema, "OpensearchResult");
|
|
97
|
+
}
|
|
98
|
+
export function synthesisJsonSchema() {
|
|
99
|
+
return zodToJsonSchema(SynthesisSchema, "OpensearchSynthesis");
|
|
100
|
+
}
|