@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.
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toCloudWebSearchRichEvents = toCloudWebSearchRichEvents;
4
+ const validation_1 = require("./validation");
5
+ function asString(value) {
6
+ return typeof value === "string" && value.trim() ? value : null;
7
+ }
8
+ function asNumber(value) {
9
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
10
+ }
11
+ function asIndex(value) {
12
+ return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : null;
13
+ }
14
+ function toSource(value) {
15
+ if (!(0, validation_1.isPlainObject)(value))
16
+ return null;
17
+ const url = asString(value.url);
18
+ const title = asString(value.title);
19
+ const keyFacts = Array.isArray(value.keyFacts)
20
+ ? value.keyFacts.filter((fact) => typeof fact === "string")
21
+ : undefined;
22
+ return Object.assign({ title,
23
+ url, snippet: asString(value.snippet), score: asNumber(value.score), confidence: asNumber(value.confidence), faviconUrl: asString(value.faviconUrl), host: asString(value.host), relevantContent: asString(value.relevantContent) }, (keyFacts ? { keyFacts } : {}));
24
+ }
25
+ function sourceFromPayload(payload) {
26
+ if ((0, validation_1.isPlainObject)(payload.source)) {
27
+ return toSource(payload.source);
28
+ }
29
+ return toSource(payload);
30
+ }
31
+ function sourcesFromPayload(payload) {
32
+ const values = Array.isArray(payload.results)
33
+ ? payload.results
34
+ : Array.isArray(payload.sources)
35
+ ? payload.sources
36
+ : [];
37
+ return values.map((source) => toSource(source)).filter((source) => Boolean(source));
38
+ }
39
+ function payloadOf(record) {
40
+ return (0, validation_1.isPlainObject)(record.payload) ? record.payload : {};
41
+ }
42
+ function answerFromResult(value) {
43
+ if (!(0, validation_1.isPlainObject)(value))
44
+ return null;
45
+ if ((0, validation_1.isPlainObject)(value.output)) {
46
+ return (0, validation_1.cloneUnknown)(value.output);
47
+ }
48
+ return null;
49
+ }
50
+ function fromRecord(record) {
51
+ var _a;
52
+ const payload = payloadOf(record);
53
+ const base = {
54
+ jobId: record.jobId,
55
+ eventId: record.id,
56
+ raw: (0, validation_1.cloneUnknown)(record),
57
+ };
58
+ switch (record.eventType) {
59
+ case "websearch.research.plan.started":
60
+ return [Object.assign(Object.assign({ type: "plan.started" }, base), { message: record.message })];
61
+ case "websearch.research.plan.completed":
62
+ return [Object.assign(Object.assign({ type: "plan.completed" }, base), { plan: (0, validation_1.isPlainObject)(record.payload) ? (0, validation_1.cloneUnknown)(record.payload) : null })];
63
+ case "websearch.research.todo.generated":
64
+ return [Object.assign(Object.assign({ type: "todo.generated" }, base), { todo: (0, validation_1.isPlainObject)(record.payload) ? (0, validation_1.cloneUnknown)(record.payload) : null })];
65
+ case "websearch.search.started":
66
+ return [Object.assign(Object.assign({ type: "search.started" }, base), { query: asString(payload.query), input: payload.input })];
67
+ case "websearch.search.completed":
68
+ return [Object.assign(Object.assign({ type: "search.completed" }, base), { query: asString(payload.query), provider: asString(payload.provider), results: sourcesFromPayload(payload) })];
69
+ case "websearch.fetch.started":
70
+ case "websearch.source.opening":
71
+ return [Object.assign(Object.assign({ type: "source.opening" }, base), { source: sourceFromPayload(payload), index: asIndex(payload.index) })];
72
+ case "websearch.extract.completed":
73
+ case "websearch.source.extracted":
74
+ return [Object.assign(Object.assign({ type: "source.extracted" }, base), { source: sourceFromPayload(payload), snippet: asString(payload.snippet), confidence: asNumber(payload.confidence), index: asIndex(payload.index) })];
75
+ case "websearch.fetch.failed":
76
+ case "websearch.source.failed":
77
+ return [Object.assign(Object.assign({ type: "source.failed" }, base), { source: sourceFromPayload(payload), errorMessage: (_a = asString(payload.error)) !== null && _a !== void 0 ? _a : asString(payload.errorMessage), index: asIndex(payload.index) })];
78
+ case "websearch.research.reasoning":
79
+ return asString(payload.delta)
80
+ ? [Object.assign(Object.assign({ type: "reasoning.delta" }, base), { delta: asString(payload.delta) })]
81
+ : [];
82
+ case "websearch.research.answer.delta":
83
+ return asString(payload.delta)
84
+ ? [Object.assign(Object.assign({ type: "answer.delta" }, base), { delta: asString(payload.delta) })]
85
+ : [];
86
+ case "websearch.tool.sources.reviewing":
87
+ case "websearch.tool.synthesis.started":
88
+ return [Object.assign(Object.assign({ type: "sources.reviewing" }, base), { totalExtractions: asNumber(payload.totalExtractions), message: record.message })];
89
+ case "websearch.tool.sources.filtered":
90
+ return [Object.assign(Object.assign({ type: "sources.filtered" }, base), { totalSources: asNumber(payload.totalSources), credibleSources: asNumber(payload.credibleSources), filteredOut: asNumber(payload.filteredOut), message: record.message })];
91
+ case "websearch.tool.retrieval.completed":
92
+ case "websearch.tool.synthesis.completed":
93
+ return [Object.assign(Object.assign({ type: "sources.reviewed" }, base), { sources: sourcesFromPayload(payload), credibleSourceCount: asNumber(payload.credibleSourceCount) })];
94
+ case "websearch.research.synthesis.started":
95
+ case "websearch.synthesis.started":
96
+ return [Object.assign(Object.assign({ type: "synthesis.started" }, base), { totalExtractions: asNumber(payload.totalExtractions) })];
97
+ case "websearch.research.synthesis.completed":
98
+ return [Object.assign({ type: "synthesis.completed" }, base)];
99
+ case "websearch.research.answer.completed":
100
+ return [Object.assign({ type: "answer.completed" }, base)];
101
+ default:
102
+ return [];
103
+ }
104
+ }
105
+ function toCloudWebSearchRichEvents(event) {
106
+ if (event.type === "progress" && event.raw) {
107
+ return fromRecord(event.raw);
108
+ }
109
+ if (event.type === "event") {
110
+ return fromRecord(event.event);
111
+ }
112
+ if (event.type === "completed") {
113
+ return [Object.assign(Object.assign({ type: "answer.completed", jobId: event.jobId, result: event.result, answer: answerFromResult(event.result) }, (event.eventId ? { eventId: event.eventId } : {})), (event.raw ? { raw: event.raw } : {})), Object.assign(Object.assign({ type: "completed", jobId: event.jobId, job: event.job, result: event.result }, (event.eventId ? { eventId: event.eventId } : {})), (event.raw ? { raw: event.raw } : {}))];
114
+ }
115
+ if (event.type === "error") {
116
+ return [Object.assign(Object.assign({ type: "error", jobId: event.jobId, job: event.job, errorMessage: event.errorMessage }, (event.eventId ? { eventId: event.eventId } : {})), (event.raw ? { raw: event.raw } : {}))];
117
+ }
118
+ if (event.type === "cancelled") {
119
+ return [Object.assign(Object.assign({ type: "cancelled", jobId: event.jobId, job: event.job }, (event.eventId ? { eventId: event.eventId } : {})), (event.raw ? { raw: event.raw } : {}))];
120
+ }
121
+ return [];
122
+ }
package/dist/sse.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export type ParsedSSEEvent<T = unknown> = {
2
+ event: string;
3
+ data: T;
4
+ dataText: string;
5
+ id?: string;
6
+ retry?: number;
7
+ };
8
+ export declare function readSSEStream<T = unknown>(stream: ReadableStream<Uint8Array>): AsyncGenerator<ParsedSSEEvent<T>>;
package/dist/sse.js ADDED
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
3
+ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
4
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
5
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
6
+ return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
7
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
8
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
9
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
10
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
11
+ function fulfill(value) { resume("next", value); }
12
+ function reject(value) { resume("throw", value); }
13
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.readSSEStream = readSSEStream;
17
+ function parseEventData(dataText) {
18
+ try {
19
+ return JSON.parse(dataText);
20
+ }
21
+ catch (_a) {
22
+ return dataText;
23
+ }
24
+ }
25
+ function finalizeEvent(eventName, dataLines, lastEventId, retry) {
26
+ if (dataLines.length === 0) {
27
+ return null;
28
+ }
29
+ const dataText = dataLines.join("\n");
30
+ return Object.assign(Object.assign({ event: eventName || "message", data: parseEventData(dataText), dataText }, (lastEventId === undefined ? {} : { id: lastEventId })), (retry === undefined ? {} : { retry }));
31
+ }
32
+ function findNextLineBreak(buffer) {
33
+ for (let index = 0; index < buffer.length; index += 1) {
34
+ const code = buffer.charCodeAt(index);
35
+ if (code === 0x0a) {
36
+ return { index, length: 1 };
37
+ }
38
+ if (code === 0x0d) {
39
+ return {
40
+ index,
41
+ length: buffer.charCodeAt(index + 1) === 0x0a ? 2 : 1,
42
+ };
43
+ }
44
+ }
45
+ return null;
46
+ }
47
+ function parseField(line) {
48
+ const separator = line.indexOf(":");
49
+ if (separator < 0) {
50
+ return { field: line, value: "" };
51
+ }
52
+ let value = line.slice(separator + 1);
53
+ if (value.startsWith(" ")) {
54
+ value = value.slice(1);
55
+ }
56
+ return {
57
+ field: line.slice(0, separator),
58
+ value,
59
+ };
60
+ }
61
+ function readSSEStream(stream) {
62
+ return __asyncGenerator(this, arguments, function* readSSEStream_1() {
63
+ const reader = stream.getReader();
64
+ const decoder = new TextDecoder();
65
+ let buffer = "";
66
+ let eventName = "message";
67
+ let dataLines = [];
68
+ let lastEventId;
69
+ let pendingEventId;
70
+ let pendingRetry;
71
+ const processLine = (line) => {
72
+ if (line === "") {
73
+ if (pendingEventId !== undefined) {
74
+ lastEventId = pendingEventId;
75
+ }
76
+ const event = finalizeEvent(eventName, dataLines, lastEventId, pendingRetry);
77
+ eventName = "message";
78
+ dataLines = [];
79
+ pendingEventId = undefined;
80
+ pendingRetry = undefined;
81
+ return event;
82
+ }
83
+ if (line.startsWith(":")) {
84
+ return null;
85
+ }
86
+ const { field, value } = parseField(line);
87
+ switch (field) {
88
+ case "event":
89
+ eventName = value || "message";
90
+ break;
91
+ case "data":
92
+ dataLines.push(value);
93
+ break;
94
+ case "id":
95
+ if (!value.includes("\0")) {
96
+ pendingEventId = value;
97
+ }
98
+ break;
99
+ case "retry":
100
+ if (/^\d+$/.test(value)) {
101
+ pendingRetry = Number.parseInt(value, 10);
102
+ }
103
+ break;
104
+ default:
105
+ break;
106
+ }
107
+ return null;
108
+ };
109
+ try {
110
+ let isDone = false;
111
+ while (!isDone) {
112
+ const { done, value } = yield __await(reader.read());
113
+ isDone = done;
114
+ buffer += decoder.decode(value !== null && value !== void 0 ? value : new Uint8Array(), { stream: !done });
115
+ let nextLine = findNextLineBreak(buffer);
116
+ while (nextLine) {
117
+ const line = buffer.slice(0, nextLine.index);
118
+ buffer = buffer.slice(nextLine.index + nextLine.length);
119
+ const event = processLine(line);
120
+ if (event) {
121
+ yield yield __await(event);
122
+ }
123
+ nextLine = findNextLineBreak(buffer);
124
+ }
125
+ }
126
+ buffer += decoder.decode();
127
+ if (buffer.length > 0) {
128
+ const event = processLine(buffer);
129
+ if (event) {
130
+ yield yield __await(event);
131
+ }
132
+ }
133
+ if (pendingEventId !== undefined) {
134
+ lastEventId = pendingEventId;
135
+ }
136
+ const trailingEvent = finalizeEvent(eventName, dataLines, lastEventId, pendingRetry);
137
+ if (trailingEvent) {
138
+ yield yield __await(trailingEvent);
139
+ }
140
+ }
141
+ finally {
142
+ try {
143
+ yield __await(reader.cancel());
144
+ }
145
+ catch (_a) {
146
+ // Best effort cleanup for partially consumed streams.
147
+ }
148
+ reader.releaseLock();
149
+ }
150
+ });
151
+ }
@@ -0,0 +1,310 @@
1
+ import type { HttpTransportConfig, LogLevel } from "@kognitivedev/client-core";
2
+ import type { ParsedSSEEvent } from "./sse";
3
+ export type { LogLevel };
4
+ export interface CloudWebSearchClientConfig extends HttpTransportConfig {
5
+ }
6
+ export type CloudWebSearchJobStatus = "queued" | "in_progress" | "completed" | "error" | "cancelled";
7
+ export type CloudWebSearchMode = "search" | "research";
8
+ export type CloudWebSearchTimeRange = "day" | "week" | "month" | "year";
9
+ export type CloudWebSearchOutputParser<TOutput> = (value: unknown) => TOutput;
10
+ export interface CloudWebSearchDecodeOptions<TOutput = unknown> {
11
+ parseOutput?: CloudWebSearchOutputParser<TOutput>;
12
+ }
13
+ export interface CloudWebSearchSubscribeOptions<TOutput = unknown> extends CloudWebSearchDecodeOptions<TOutput> {
14
+ init?: RequestInit;
15
+ }
16
+ export interface CloudWebSearchExecutionParameters {
17
+ maxResults?: number;
18
+ maxPages?: number;
19
+ region?: string;
20
+ timeRange?: CloudWebSearchTimeRange;
21
+ includeDomains?: string[];
22
+ excludeDomains?: string[];
23
+ outputSchema?: Record<string, unknown>;
24
+ [key: string]: unknown;
25
+ }
26
+ export interface CloudWebSearchSearchJobInput {
27
+ mode: "search";
28
+ query: string;
29
+ parameters?: CloudWebSearchExecutionParameters;
30
+ }
31
+ export interface CloudWebSearchResearchJobInput {
32
+ mode: "research";
33
+ instructions: string;
34
+ responseInstructions?: string;
35
+ responseSchema?: Record<string, unknown>;
36
+ parameters?: CloudWebSearchExecutionParameters;
37
+ }
38
+ export type CreateCloudWebSearchJobInput = CloudWebSearchSearchJobInput | CloudWebSearchResearchJobInput;
39
+ export interface ResearchPlanTodo {
40
+ id: string;
41
+ title: string;
42
+ objective: string;
43
+ searchQuery?: string;
44
+ rationale?: string;
45
+ }
46
+ export interface ResearchPlan {
47
+ summary: string;
48
+ todos: ResearchPlanTodo[];
49
+ }
50
+ export interface CloudWebSearchProgressEntry {
51
+ stage: string;
52
+ message: string;
53
+ timestamp: string;
54
+ metadata?: Record<string, unknown>;
55
+ }
56
+ export interface CloudWebSearchSource {
57
+ title?: string | null;
58
+ url?: string | null;
59
+ host?: string | null;
60
+ snippet?: string | null;
61
+ relevantContent?: string | null;
62
+ keyFacts?: string[];
63
+ confidence?: number | null;
64
+ score?: number | null;
65
+ faviconUrl?: string | null;
66
+ }
67
+ export interface CloudWebSearchResult<TOutput = unknown> {
68
+ output?: TOutput;
69
+ text?: string | null;
70
+ sources: CloudWebSearchSource[];
71
+ metadata?: Record<string, unknown>;
72
+ }
73
+ export interface CloudWebSearchJobRecord<TOutput = unknown> {
74
+ id: string;
75
+ projectId: string;
76
+ mode: CloudWebSearchMode;
77
+ searchQuery?: string | null;
78
+ searchInstructions?: string | null;
79
+ responseInstructions?: string | null;
80
+ responseSchema?: Record<string, unknown> | null;
81
+ researchPlan?: ResearchPlan | null;
82
+ parameters: Record<string, unknown>;
83
+ status: CloudWebSearchJobStatus;
84
+ results?: CloudWebSearchResult<TOutput> | null;
85
+ progress: CloudWebSearchProgressEntry[];
86
+ errorMessage?: string | null;
87
+ cancelRequestedAt?: string | Date | null;
88
+ cancelledAt?: string | Date | null;
89
+ createdAt: string | Date;
90
+ updatedAt: string | Date;
91
+ }
92
+ export interface CloudWebSearchJobEventRecord {
93
+ id: string;
94
+ jobId: string;
95
+ projectId: string;
96
+ eventType: string;
97
+ stage: string | null;
98
+ status: string | null;
99
+ message: string | null;
100
+ payload: unknown;
101
+ createdAt: string | Date;
102
+ }
103
+ export interface CloudWebSearchJobResultEnvelope<TOutput = unknown> {
104
+ jobId: string;
105
+ status: "completed";
106
+ result: CloudWebSearchResult<TOutput> | null;
107
+ }
108
+ export interface WaitForCompletionOptions<TOutput = unknown> extends CloudWebSearchDecodeOptions<TOutput> {
109
+ intervalMs?: number;
110
+ timeoutMs?: number;
111
+ }
112
+ export interface CloudWebSearchJobWaitResult<TOutput = unknown> {
113
+ job: CloudWebSearchJobRecord<TOutput>;
114
+ result: CloudWebSearchResult<TOutput> | null;
115
+ }
116
+ export interface CloudWebSearchRichSource extends CloudWebSearchSource {
117
+ host?: string | null;
118
+ relevantContent?: string | null;
119
+ keyFacts?: string[];
120
+ confidence?: number | null;
121
+ }
122
+ export interface CloudWebSearchProductAnswer {
123
+ kind?: string;
124
+ markdown?: string;
125
+ headline?: string;
126
+ lede?: string;
127
+ table?: unknown;
128
+ takeaways?: string[];
129
+ cites?: Array<Record<string, unknown>>;
130
+ sources?: CloudWebSearchRichSource[];
131
+ [key: string]: unknown;
132
+ }
133
+ export type CloudWebSearchRichEvent<TOutput = unknown> = {
134
+ type: "plan.started";
135
+ jobId: string;
136
+ message?: string | null;
137
+ eventId?: string;
138
+ raw?: CloudWebSearchJobEventRecord;
139
+ } | {
140
+ type: "plan.completed";
141
+ jobId: string;
142
+ plan: ResearchPlan | null;
143
+ eventId?: string;
144
+ raw?: CloudWebSearchJobEventRecord;
145
+ } | {
146
+ type: "todo.generated";
147
+ jobId: string;
148
+ todo: ResearchPlanTodo | null;
149
+ eventId?: string;
150
+ raw?: CloudWebSearchJobEventRecord;
151
+ } | {
152
+ type: "search.started";
153
+ jobId: string;
154
+ query: string | null;
155
+ input?: unknown;
156
+ eventId?: string;
157
+ raw?: CloudWebSearchJobEventRecord;
158
+ } | {
159
+ type: "search.completed";
160
+ jobId: string;
161
+ query: string | null;
162
+ provider?: string | null;
163
+ results: CloudWebSearchRichSource[];
164
+ eventId?: string;
165
+ raw?: CloudWebSearchJobEventRecord;
166
+ } | {
167
+ type: "source.opening";
168
+ jobId: string;
169
+ source: CloudWebSearchRichSource | null;
170
+ index?: number | null;
171
+ eventId?: string;
172
+ raw?: CloudWebSearchJobEventRecord;
173
+ } | {
174
+ type: "source.extracted";
175
+ jobId: string;
176
+ source: CloudWebSearchRichSource | null;
177
+ snippet?: string | null;
178
+ confidence?: number | null;
179
+ index?: number | null;
180
+ eventId?: string;
181
+ raw?: CloudWebSearchJobEventRecord;
182
+ } | {
183
+ type: "source.failed";
184
+ jobId: string;
185
+ source: CloudWebSearchRichSource | null;
186
+ errorMessage: string | null;
187
+ index?: number | null;
188
+ eventId?: string;
189
+ raw?: CloudWebSearchJobEventRecord;
190
+ } | {
191
+ type: "reasoning.delta";
192
+ jobId: string;
193
+ delta: string;
194
+ eventId?: string;
195
+ raw?: CloudWebSearchJobEventRecord;
196
+ } | {
197
+ type: "answer.delta";
198
+ jobId: string;
199
+ delta: string;
200
+ eventId?: string;
201
+ raw?: CloudWebSearchJobEventRecord;
202
+ } | {
203
+ type: "sources.reviewing";
204
+ jobId: string;
205
+ totalExtractions?: number | null;
206
+ message?: string | null;
207
+ eventId?: string;
208
+ raw?: CloudWebSearchJobEventRecord;
209
+ } | {
210
+ type: "sources.filtered";
211
+ jobId: string;
212
+ totalSources?: number | null;
213
+ credibleSources?: number | null;
214
+ filteredOut?: number | null;
215
+ message?: string | null;
216
+ eventId?: string;
217
+ raw?: CloudWebSearchJobEventRecord;
218
+ } | {
219
+ type: "sources.reviewed";
220
+ jobId: string;
221
+ sources: CloudWebSearchRichSource[];
222
+ credibleSourceCount?: number | null;
223
+ eventId?: string;
224
+ raw?: CloudWebSearchJobEventRecord;
225
+ } | {
226
+ type: "synthesis.started";
227
+ jobId: string;
228
+ totalExtractions?: number | null;
229
+ eventId?: string;
230
+ raw?: CloudWebSearchJobEventRecord;
231
+ } | {
232
+ type: "synthesis.completed";
233
+ jobId: string;
234
+ eventId?: string;
235
+ raw?: CloudWebSearchJobEventRecord;
236
+ } | {
237
+ type: "answer.completed";
238
+ jobId: string;
239
+ result?: CloudWebSearchResult<TOutput> | null;
240
+ answer?: CloudWebSearchProductAnswer | null;
241
+ eventId?: string;
242
+ raw?: CloudWebSearchJobEventRecord;
243
+ } | {
244
+ type: "completed";
245
+ jobId: string;
246
+ job: CloudWebSearchJobRecord<TOutput> | null;
247
+ result: CloudWebSearchResult<TOutput> | null;
248
+ eventId?: string;
249
+ raw?: CloudWebSearchJobEventRecord;
250
+ } | {
251
+ type: "error";
252
+ jobId: string;
253
+ job: CloudWebSearchJobRecord<TOutput> | null;
254
+ errorMessage: string;
255
+ eventId?: string;
256
+ raw?: CloudWebSearchJobEventRecord;
257
+ } | {
258
+ type: "cancelled";
259
+ jobId: string;
260
+ job: CloudWebSearchJobRecord<TOutput> | null;
261
+ eventId?: string;
262
+ raw?: CloudWebSearchJobEventRecord;
263
+ };
264
+ export type CloudWebSearchStreamEvent<TOutput = unknown> = {
265
+ type: "snapshot";
266
+ job: CloudWebSearchJobRecord<TOutput>;
267
+ } | {
268
+ type: "progress";
269
+ jobId: string;
270
+ job: CloudWebSearchJobRecord<TOutput> | null;
271
+ status: CloudWebSearchJobStatus;
272
+ progress: CloudWebSearchProgressEntry;
273
+ eventId?: string;
274
+ replay?: boolean;
275
+ rawEventType?: string;
276
+ raw?: CloudWebSearchJobEventRecord;
277
+ } | {
278
+ type: "completed";
279
+ jobId: string;
280
+ job: CloudWebSearchJobRecord<TOutput> | null;
281
+ result: CloudWebSearchResult<TOutput> | null;
282
+ eventId?: string;
283
+ raw?: CloudWebSearchJobEventRecord;
284
+ } | {
285
+ type: "error";
286
+ jobId: string;
287
+ job: CloudWebSearchJobRecord<TOutput> | null;
288
+ errorMessage: string;
289
+ eventId?: string;
290
+ raw?: CloudWebSearchJobEventRecord;
291
+ } | {
292
+ type: "cancelled";
293
+ jobId: string;
294
+ job: CloudWebSearchJobRecord<TOutput> | null;
295
+ eventId?: string;
296
+ raw?: CloudWebSearchJobEventRecord;
297
+ } | {
298
+ type: "keepalive";
299
+ jobId: string;
300
+ timestamp: string;
301
+ } | {
302
+ type: "event";
303
+ jobId: string;
304
+ job: CloudWebSearchJobRecord<TOutput> | null;
305
+ event: CloudWebSearchJobEventRecord;
306
+ } | {
307
+ type: "unknown";
308
+ job: CloudWebSearchJobRecord<TOutput> | null;
309
+ frame: ParsedSSEEvent<unknown>;
310
+ };
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,39 @@
1
+ import type { CloudWebSearchDecodeOptions, CloudWebSearchJobEventRecord, CloudWebSearchJobRecord, CloudWebSearchJobResultEnvelope, CloudWebSearchJobStatus, CloudWebSearchProgressEntry, CloudWebSearchResult, CloudWebSearchSource, CreateCloudWebSearchJobInput } from "./types";
2
+ type PlainObject = Record<string, unknown>;
3
+ export declare function isPlainObject(value: unknown): value is PlainObject;
4
+ export declare function cloneUnknown<T>(value: T): T;
5
+ export declare function isJobStatus(value: unknown): value is CloudWebSearchJobStatus;
6
+ export declare function decodeCloudWebSearchSource(value: unknown, path: string): CloudWebSearchSource;
7
+ export declare function decodeCloudWebSearchResult<TOutput = unknown>(value: unknown, options?: CloudWebSearchDecodeOptions<TOutput>, path?: string): CloudWebSearchResult<TOutput>;
8
+ export declare function decodeCloudWebSearchProgressEntry(value: unknown, path: string): CloudWebSearchProgressEntry;
9
+ export declare function decodeCloudWebSearchJobRecord<TOutput = unknown>(value: unknown, options?: CloudWebSearchDecodeOptions<TOutput>, path?: string): CloudWebSearchJobRecord<TOutput>;
10
+ export declare function decodeCloudWebSearchJobEventRecord(value: unknown, path?: string): CloudWebSearchJobEventRecord;
11
+ export declare function decodeCloudWebSearchJobListEnvelope<TOutput = unknown>(value: unknown, options?: CloudWebSearchDecodeOptions<TOutput>, path?: string): {
12
+ jobs: CloudWebSearchJobRecord<TOutput>[];
13
+ };
14
+ export declare function decodeCloudWebSearchJobResultEnvelope<TOutput = unknown>(value: unknown, options?: CloudWebSearchDecodeOptions<TOutput>, path?: string): CloudWebSearchJobResultEnvelope<TOutput>;
15
+ export declare function decodeJobSnapshotPayload<TOutput = unknown>(value: unknown, options?: CloudWebSearchDecodeOptions<TOutput>, path?: string): {
16
+ job: CloudWebSearchJobRecord<TOutput>;
17
+ };
18
+ export declare function decodeDirectProgressPayload(value: unknown, path?: string): {
19
+ jobId: string;
20
+ status: CloudWebSearchJobStatus;
21
+ progress: CloudWebSearchProgressEntry;
22
+ };
23
+ export declare function decodeDirectCompletedPayload<TOutput = unknown>(value: unknown, options?: CloudWebSearchDecodeOptions<TOutput>, path?: string): {
24
+ job: CloudWebSearchJobRecord<TOutput>;
25
+ result: CloudWebSearchResult<TOutput> | null;
26
+ };
27
+ export declare function decodeDirectErrorPayload<TOutput = unknown>(value: unknown, options?: CloudWebSearchDecodeOptions<TOutput>, path?: string): {
28
+ job: CloudWebSearchJobRecord<TOutput>;
29
+ errorMessage: string;
30
+ };
31
+ export declare function decodeDirectCancelledPayload<TOutput = unknown>(value: unknown, options?: CloudWebSearchDecodeOptions<TOutput>, path?: string): {
32
+ job: CloudWebSearchJobRecord<TOutput>;
33
+ };
34
+ export declare function decodeKeepalivePayload(value: unknown, path?: string): {
35
+ jobId: string;
36
+ timestamp: string;
37
+ };
38
+ export declare function validateCreateCloudWebSearchJobInput(value: CreateCloudWebSearchJobInput, path?: string): CreateCloudWebSearchJobInput;
39
+ export {};