@kognitivedev/cloud-web-search 0.2.28

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/src/types.ts ADDED
@@ -0,0 +1,362 @@
1
+ import type { HttpTransportConfig, LogLevel } from "@kognitivedev/client-core";
2
+ import type { ParsedSSEEvent } from "./sse";
3
+
4
+ export type { LogLevel };
5
+
6
+ export interface CloudWebSearchClientConfig extends HttpTransportConfig {}
7
+
8
+ export type CloudWebSearchJobStatus = "queued" | "in_progress" | "completed" | "error" | "cancelled";
9
+ export type CloudWebSearchMode = "search" | "research";
10
+ export type CloudWebSearchTimeRange = "day" | "week" | "month" | "year";
11
+
12
+ export type CloudWebSearchOutputParser<TOutput> = (value: unknown) => TOutput;
13
+
14
+ export interface CloudWebSearchDecodeOptions<TOutput = unknown> {
15
+ parseOutput?: CloudWebSearchOutputParser<TOutput>;
16
+ }
17
+
18
+ export interface CloudWebSearchSubscribeOptions<TOutput = unknown> extends CloudWebSearchDecodeOptions<TOutput> {
19
+ init?: RequestInit;
20
+ }
21
+
22
+ export interface CloudWebSearchExecutionParameters {
23
+ maxResults?: number;
24
+ maxPages?: number;
25
+ region?: string;
26
+ timeRange?: CloudWebSearchTimeRange;
27
+ includeDomains?: string[];
28
+ excludeDomains?: string[];
29
+ outputSchema?: Record<string, unknown>;
30
+ [key: string]: unknown;
31
+ }
32
+
33
+ export interface CloudWebSearchSearchJobInput {
34
+ mode: "search";
35
+ query: string;
36
+ parameters?: CloudWebSearchExecutionParameters;
37
+ }
38
+
39
+ export interface CloudWebSearchResearchJobInput {
40
+ mode: "research";
41
+ instructions: string;
42
+ responseInstructions?: string;
43
+ responseSchema?: Record<string, unknown>;
44
+ parameters?: CloudWebSearchExecutionParameters;
45
+ }
46
+
47
+ export type CreateCloudWebSearchJobInput =
48
+ | CloudWebSearchSearchJobInput
49
+ | CloudWebSearchResearchJobInput;
50
+
51
+ export interface ResearchPlanTodo {
52
+ id: string;
53
+ title: string;
54
+ objective: string;
55
+ searchQuery?: string;
56
+ rationale?: string;
57
+ }
58
+
59
+ export interface ResearchPlan {
60
+ summary: string;
61
+ todos: ResearchPlanTodo[];
62
+ }
63
+
64
+ export interface CloudWebSearchProgressEntry {
65
+ stage: string;
66
+ message: string;
67
+ timestamp: string;
68
+ metadata?: Record<string, unknown>;
69
+ }
70
+
71
+ export interface CloudWebSearchSource {
72
+ title?: string | null;
73
+ url?: string | null;
74
+ host?: string | null;
75
+ snippet?: string | null;
76
+ relevantContent?: string | null;
77
+ keyFacts?: string[];
78
+ confidence?: number | null;
79
+ score?: number | null;
80
+ faviconUrl?: string | null;
81
+ }
82
+
83
+ export interface CloudWebSearchResult<TOutput = unknown> {
84
+ output?: TOutput;
85
+ text?: string | null;
86
+ sources: CloudWebSearchSource[];
87
+ metadata?: Record<string, unknown>;
88
+ }
89
+
90
+ export interface CloudWebSearchJobRecord<TOutput = unknown> {
91
+ id: string;
92
+ projectId: string;
93
+ mode: CloudWebSearchMode;
94
+ searchQuery?: string | null;
95
+ searchInstructions?: string | null;
96
+ responseInstructions?: string | null;
97
+ responseSchema?: Record<string, unknown> | null;
98
+ researchPlan?: ResearchPlan | null;
99
+ parameters: Record<string, unknown>;
100
+ status: CloudWebSearchJobStatus;
101
+ results?: CloudWebSearchResult<TOutput> | null;
102
+ progress: CloudWebSearchProgressEntry[];
103
+ errorMessage?: string | null;
104
+ cancelRequestedAt?: string | Date | null;
105
+ cancelledAt?: string | Date | null;
106
+ createdAt: string | Date;
107
+ updatedAt: string | Date;
108
+ }
109
+
110
+ export interface CloudWebSearchJobEventRecord {
111
+ id: string;
112
+ jobId: string;
113
+ projectId: string;
114
+ eventType: string;
115
+ stage: string | null;
116
+ status: string | null;
117
+ message: string | null;
118
+ payload: unknown;
119
+ createdAt: string | Date;
120
+ }
121
+
122
+ export interface CloudWebSearchJobResultEnvelope<TOutput = unknown> {
123
+ jobId: string;
124
+ status: "completed";
125
+ result: CloudWebSearchResult<TOutput> | null;
126
+ }
127
+
128
+ export interface WaitForCompletionOptions<TOutput = unknown> extends CloudWebSearchDecodeOptions<TOutput> {
129
+ intervalMs?: number;
130
+ timeoutMs?: number;
131
+ }
132
+
133
+ export interface CloudWebSearchJobWaitResult<TOutput = unknown> {
134
+ job: CloudWebSearchJobRecord<TOutput>;
135
+ result: CloudWebSearchResult<TOutput> | null;
136
+ }
137
+
138
+ export interface CloudWebSearchRichSource extends CloudWebSearchSource {
139
+ host?: string | null;
140
+ relevantContent?: string | null;
141
+ keyFacts?: string[];
142
+ confidence?: number | null;
143
+ }
144
+
145
+ export interface CloudWebSearchProductAnswer {
146
+ kind?: string;
147
+ markdown?: string;
148
+ headline?: string;
149
+ lede?: string;
150
+ table?: unknown;
151
+ takeaways?: string[];
152
+ cites?: Array<Record<string, unknown>>;
153
+ sources?: CloudWebSearchRichSource[];
154
+ [key: string]: unknown;
155
+ }
156
+
157
+ export type CloudWebSearchRichEvent<TOutput = unknown> =
158
+ | {
159
+ type: "plan.started";
160
+ jobId: string;
161
+ message?: string | null;
162
+ eventId?: string;
163
+ raw?: CloudWebSearchJobEventRecord;
164
+ }
165
+ | {
166
+ type: "plan.completed";
167
+ jobId: string;
168
+ plan: ResearchPlan | null;
169
+ eventId?: string;
170
+ raw?: CloudWebSearchJobEventRecord;
171
+ }
172
+ | {
173
+ type: "todo.generated";
174
+ jobId: string;
175
+ todo: ResearchPlanTodo | null;
176
+ eventId?: string;
177
+ raw?: CloudWebSearchJobEventRecord;
178
+ }
179
+ | {
180
+ type: "search.started";
181
+ jobId: string;
182
+ query: string | null;
183
+ input?: unknown;
184
+ eventId?: string;
185
+ raw?: CloudWebSearchJobEventRecord;
186
+ }
187
+ | {
188
+ type: "search.completed";
189
+ jobId: string;
190
+ query: string | null;
191
+ provider?: string | null;
192
+ results: CloudWebSearchRichSource[];
193
+ eventId?: string;
194
+ raw?: CloudWebSearchJobEventRecord;
195
+ }
196
+ | {
197
+ type: "source.opening";
198
+ jobId: string;
199
+ source: CloudWebSearchRichSource | null;
200
+ index?: number | null;
201
+ eventId?: string;
202
+ raw?: CloudWebSearchJobEventRecord;
203
+ }
204
+ | {
205
+ type: "source.extracted";
206
+ jobId: string;
207
+ source: CloudWebSearchRichSource | null;
208
+ snippet?: string | null;
209
+ confidence?: number | null;
210
+ index?: number | null;
211
+ eventId?: string;
212
+ raw?: CloudWebSearchJobEventRecord;
213
+ }
214
+ | {
215
+ type: "source.failed";
216
+ jobId: string;
217
+ source: CloudWebSearchRichSource | null;
218
+ errorMessage: string | null;
219
+ index?: number | null;
220
+ eventId?: string;
221
+ raw?: CloudWebSearchJobEventRecord;
222
+ }
223
+ | {
224
+ type: "reasoning.delta";
225
+ jobId: string;
226
+ delta: string;
227
+ eventId?: string;
228
+ raw?: CloudWebSearchJobEventRecord;
229
+ }
230
+ | {
231
+ type: "answer.delta";
232
+ jobId: string;
233
+ delta: string;
234
+ eventId?: string;
235
+ raw?: CloudWebSearchJobEventRecord;
236
+ }
237
+ | {
238
+ type: "sources.reviewing";
239
+ jobId: string;
240
+ totalExtractions?: number | null;
241
+ message?: string | null;
242
+ eventId?: string;
243
+ raw?: CloudWebSearchJobEventRecord;
244
+ }
245
+ | {
246
+ type: "sources.filtered";
247
+ jobId: string;
248
+ totalSources?: number | null;
249
+ credibleSources?: number | null;
250
+ filteredOut?: number | null;
251
+ message?: string | null;
252
+ eventId?: string;
253
+ raw?: CloudWebSearchJobEventRecord;
254
+ }
255
+ | {
256
+ type: "sources.reviewed";
257
+ jobId: string;
258
+ sources: CloudWebSearchRichSource[];
259
+ credibleSourceCount?: number | null;
260
+ eventId?: string;
261
+ raw?: CloudWebSearchJobEventRecord;
262
+ }
263
+ | {
264
+ type: "synthesis.started";
265
+ jobId: string;
266
+ totalExtractions?: number | null;
267
+ eventId?: string;
268
+ raw?: CloudWebSearchJobEventRecord;
269
+ }
270
+ | {
271
+ type: "synthesis.completed";
272
+ jobId: string;
273
+ eventId?: string;
274
+ raw?: CloudWebSearchJobEventRecord;
275
+ }
276
+ | {
277
+ type: "answer.completed";
278
+ jobId: string;
279
+ result?: CloudWebSearchResult<TOutput> | null;
280
+ answer?: CloudWebSearchProductAnswer | null;
281
+ eventId?: string;
282
+ raw?: CloudWebSearchJobEventRecord;
283
+ }
284
+ | {
285
+ type: "completed";
286
+ jobId: string;
287
+ job: CloudWebSearchJobRecord<TOutput> | null;
288
+ result: CloudWebSearchResult<TOutput> | null;
289
+ eventId?: string;
290
+ raw?: CloudWebSearchJobEventRecord;
291
+ }
292
+ | {
293
+ type: "error";
294
+ jobId: string;
295
+ job: CloudWebSearchJobRecord<TOutput> | null;
296
+ errorMessage: string;
297
+ eventId?: string;
298
+ raw?: CloudWebSearchJobEventRecord;
299
+ }
300
+ | {
301
+ type: "cancelled";
302
+ jobId: string;
303
+ job: CloudWebSearchJobRecord<TOutput> | null;
304
+ eventId?: string;
305
+ raw?: CloudWebSearchJobEventRecord;
306
+ };
307
+
308
+ export type CloudWebSearchStreamEvent<TOutput = unknown> =
309
+ | {
310
+ type: "snapshot";
311
+ job: CloudWebSearchJobRecord<TOutput>;
312
+ }
313
+ | {
314
+ type: "progress";
315
+ jobId: string;
316
+ job: CloudWebSearchJobRecord<TOutput> | null;
317
+ status: CloudWebSearchJobStatus;
318
+ progress: CloudWebSearchProgressEntry;
319
+ eventId?: string;
320
+ replay?: boolean;
321
+ rawEventType?: string;
322
+ raw?: CloudWebSearchJobEventRecord;
323
+ }
324
+ | {
325
+ type: "completed";
326
+ jobId: string;
327
+ job: CloudWebSearchJobRecord<TOutput> | null;
328
+ result: CloudWebSearchResult<TOutput> | null;
329
+ eventId?: string;
330
+ raw?: CloudWebSearchJobEventRecord;
331
+ }
332
+ | {
333
+ type: "error";
334
+ jobId: string;
335
+ job: CloudWebSearchJobRecord<TOutput> | null;
336
+ errorMessage: string;
337
+ eventId?: string;
338
+ raw?: CloudWebSearchJobEventRecord;
339
+ }
340
+ | {
341
+ type: "cancelled";
342
+ jobId: string;
343
+ job: CloudWebSearchJobRecord<TOutput> | null;
344
+ eventId?: string;
345
+ raw?: CloudWebSearchJobEventRecord;
346
+ }
347
+ | {
348
+ type: "keepalive";
349
+ jobId: string;
350
+ timestamp: string;
351
+ }
352
+ | {
353
+ type: "event";
354
+ jobId: string;
355
+ job: CloudWebSearchJobRecord<TOutput> | null;
356
+ event: CloudWebSearchJobEventRecord;
357
+ }
358
+ | {
359
+ type: "unknown";
360
+ job: CloudWebSearchJobRecord<TOutput> | null;
361
+ frame: ParsedSSEEvent<unknown>;
362
+ };