@weaviate/agents 0.0.0-stage → 0.0.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.
Files changed (35) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +130 -2
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +1 -0
  5. package/dist/query/agent.d.ts +539 -0
  6. package/dist/query/agent.js +373 -0
  7. package/dist/query/agent.test.d.ts +1 -0
  8. package/dist/query/agent.test.js +1118 -0
  9. package/dist/query/collection.d.ts +22 -0
  10. package/dist/query/collection.js +12 -0
  11. package/dist/query/connection.d.ts +10 -0
  12. package/dist/query/connection.js +19 -0
  13. package/dist/query/filter.d.ts +2 -0
  14. package/dist/query/filter.js +20 -0
  15. package/dist/query/index.d.ts +4 -0
  16. package/dist/query/index.js +3 -0
  17. package/dist/query/media.d.ts +25 -0
  18. package/dist/query/media.js +24 -0
  19. package/dist/query/response/api-response-mapping.d.ts +3 -0
  20. package/dist/query/response/api-response-mapping.js +172 -0
  21. package/dist/query/response/api-response.d.ts +219 -0
  22. package/dist/query/response/api-response.js +1 -0
  23. package/dist/query/response/error.d.ts +6 -0
  24. package/dist/query/response/error.js +34 -0
  25. package/dist/query/response/index.d.ts +2 -0
  26. package/dist/query/response/index.js +2 -0
  27. package/dist/query/response/response-mapping.d.ts +23 -0
  28. package/dist/query/response/response-mapping.js +308 -0
  29. package/dist/query/response/response.d.ts +332 -0
  30. package/dist/query/response/response.js +44 -0
  31. package/dist/query/response/server-sent-events.d.ts +14 -0
  32. package/dist/query/response/server-sent-events.js +85 -0
  33. package/dist/query/search.d.ts +37 -0
  34. package/dist/query/search.js +87 -0
  35. package/package.json +46 -3
@@ -0,0 +1,22 @@
1
+ import { FilterValue } from "@weaviate/core";
2
+ export declare const mapCollections: (collections: (string | QueryAgentCollectionConfig)[]) => (string | {
3
+ name: string;
4
+ tenant: string | undefined;
5
+ view_properties: string[] | undefined;
6
+ target_vector: string | string[] | undefined;
7
+ additional_filters: any;
8
+ })[];
9
+ export type QueryAgentCollection = string | QueryAgentCollectionConfig;
10
+ /** Configuration for a collection to query. */
11
+ export type QueryAgentCollectionConfig = {
12
+ /** The name of the collection to query. */
13
+ name: string;
14
+ /** Tenant for the collection if multi-tenancy is enabled. */
15
+ tenant?: string;
16
+ /** List of of property names the agent has the ability to view for the collection. */
17
+ viewProperties?: string[];
18
+ /** Target vector for the query if a collection uses named vector. */
19
+ targetVector?: string | string[];
20
+ /** Filters to apply when query is executed, in addition to filters selected by the Query Agent. */
21
+ additionalFilters?: FilterValue;
22
+ };
@@ -0,0 +1,12 @@
1
+ import { mapFilter } from "./filter.js";
2
+ export const mapCollections = (collections) => collections.map((collection) => typeof collection === "string"
3
+ ? collection
4
+ : {
5
+ name: collection.name,
6
+ tenant: collection.tenant,
7
+ view_properties: collection.viewProperties,
8
+ target_vector: collection.targetVector,
9
+ additional_filters: collection.additionalFilters
10
+ ? mapFilter(collection.additionalFilters)
11
+ : undefined,
12
+ });
@@ -0,0 +1,10 @@
1
+ import { WeaviateClient } from "@weaviate/core";
2
+ export declare const getHeaders: (client: WeaviateClient) => Promise<{
3
+ requestHeaders: {
4
+ "Content-Type": string;
5
+ Authorization: string;
6
+ "X-Weaviate-Cluster-Url": string;
7
+ "X-Agent-Request-Origin": string;
8
+ };
9
+ connectionHeaders: import("@weaviate/core").Headers | undefined;
10
+ }>;
@@ -0,0 +1,19 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export const getHeaders = (client) => __awaiter(void 0, void 0, void 0, function* () {
11
+ const { host, bearerToken, headers: connectionHeaders, } = yield client.getConnectionDetails();
12
+ const requestHeaders = {
13
+ "Content-Type": "application/json",
14
+ Authorization: bearerToken,
15
+ "X-Weaviate-Cluster-Url": host,
16
+ "X-Agent-Request-Origin": "typescript-client",
17
+ };
18
+ return { requestHeaders, connectionHeaders };
19
+ });
@@ -0,0 +1,2 @@
1
+ import { FilterValue } from "@weaviate/core";
2
+ export declare const mapFilter: (filters: FilterValue) => any;
@@ -0,0 +1,20 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ export const mapFilter = (filters) => {
3
+ var _a, _b;
4
+ return filters.filters
5
+ ? {
6
+ combine: mapFilterCombineOperator(filters.operator),
7
+ filters: filters.filters.map(mapFilter),
8
+ }
9
+ : Object.assign(Object.assign({}, filters), { target: (_b = (_a = filters.target) === null || _a === void 0 ? void 0 : _a.property) !== null && _b !== void 0 ? _b : filters.target });
10
+ };
11
+ const mapFilterCombineOperator = (operator) => {
12
+ switch (operator) {
13
+ case "And":
14
+ return "and";
15
+ case "Or":
16
+ return "or";
17
+ default:
18
+ return operator;
19
+ }
20
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./agent.js";
2
+ export { QueryAgentCollection, QueryAgentCollectionConfig, } from "./collection.js";
3
+ export { GeneratedImage, ImageShape, ImageOptions, generatedImageWithOptions, } from "./media.js";
4
+ export * from "./response/index.js";
@@ -0,0 +1,3 @@
1
+ export * from "./agent.js";
2
+ export { GeneratedImage, generatedImageWithOptions, } from "./media.js";
3
+ export * from "./response/index.js";
@@ -0,0 +1,25 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * An image field for a structured output, returned with the generated PNG as base64 in `base64`.
4
+ *
5
+ * Lists of images need a `.max()`, and a schema may request at most 10 images in the worst case.
6
+ */
7
+ export declare const GeneratedImage: z.ZodObject<{
8
+ image_prompt: z.ZodString;
9
+ base64: z.ZodString;
10
+ }, z.core.$strip>;
11
+ export type GeneratedImage = z.infer<typeof GeneratedImage>;
12
+ export type ImageShape = "square" | "landscape" | "portrait";
13
+ /** Options for generating an image; unset options fall back to the backend defaults. */
14
+ export type ImageOptions = {
15
+ shape?: ImageShape;
16
+ };
17
+ /** A {@link GeneratedImage} field generated with the given options. */
18
+ export declare const generatedImageWithOptions: ({ shape }: ImageOptions) => z.ZodObject<{
19
+ image_prompt: z.ZodString;
20
+ base64: z.ZodString;
21
+ }, z.core.$strip>;
22
+ /** Hides `base64` from image nodes in the emitted JSON Schema, since the server adds it after generation. */
23
+ export declare const hideImageBase64: ({ jsonSchema, }: {
24
+ jsonSchema: z.core.JSONSchema.BaseSchema;
25
+ }) => void;
@@ -0,0 +1,24 @@
1
+ import { z } from "zod";
2
+ const imageKeyword = "X-query-agent-image";
3
+ /**
4
+ * An image field for a structured output, returned with the generated PNG as base64 in `base64`.
5
+ *
6
+ * Lists of images need a `.max()`, and a schema may request at most 10 images in the worst case.
7
+ */
8
+ export const GeneratedImage = z
9
+ .object({
10
+ image_prompt: z.string(),
11
+ base64: z.string(), // hidden from the agent's schema; the server fills it
12
+ })
13
+ .meta({ [imageKeyword]: true });
14
+ /** A {@link GeneratedImage} field generated with the given options. */
15
+ export const generatedImageWithOptions = ({ shape }) => GeneratedImage.meta(shape === undefined ? {} : { "X-image-shape": shape });
16
+ /** Hides `base64` from image nodes in the emitted JSON Schema, since the server adds it after generation. */
17
+ export const hideImageBase64 = ({ jsonSchema, }) => {
18
+ var _a, _b;
19
+ if (jsonSchema[imageKeyword] !== true) {
20
+ return;
21
+ }
22
+ (_a = jsonSchema.properties) === null || _a === void 0 ? true : delete _a.base64;
23
+ jsonSchema.required = (_b = jsonSchema.required) === null || _b === void 0 ? void 0 : _b.filter((key) => key !== "base64");
24
+ };
@@ -0,0 +1,3 @@
1
+ import { QueryAgentResponse } from "./response.js";
2
+ import { ApiQueryAgentResponse } from "./api-response.js";
3
+ export declare const mapApiResponse: (response: QueryAgentResponse) => ApiQueryAgentResponse;
@@ -0,0 +1,172 @@
1
+ export const mapApiResponse = (response) => ({
2
+ original_query: response.originalQuery,
3
+ collection_names: response.collectionNames,
4
+ searches: mapApiSearches(response.searches),
5
+ aggregations: mapApiAggregations(response.aggregations),
6
+ usage: mapApiUsage(response.usage),
7
+ total_time: response.totalTime,
8
+ is_partial_answer: response.isPartialAnswer,
9
+ missing_information: response.missingInformation,
10
+ final_answer: response.finalAnswer,
11
+ sources: mapApiSources(response.sources),
12
+ });
13
+ const mapApiSearches = (searches) => searches.map((searchGroup) => searchGroup.map((result) => ({
14
+ collection: result.collection,
15
+ queries: result.queries,
16
+ filters: result.filters.map(mapApiPropertyFilters),
17
+ filter_operators: result.filterOperators,
18
+ })));
19
+ const mapDateFilterValue = (value) => {
20
+ if ("exactTimestamp" in value) {
21
+ return {
22
+ exact_timestamp: value.exactTimestamp,
23
+ operator: value.operator,
24
+ };
25
+ }
26
+ else if ("dateFrom" in value &&
27
+ "dateTo" in value &&
28
+ value.dateFrom != null &&
29
+ value.dateTo != null) {
30
+ return {
31
+ date_from: value.dateFrom,
32
+ date_to: value.dateTo,
33
+ inclusive_from: value.inclusiveFrom,
34
+ inclusive_to: value.inclusiveTo,
35
+ };
36
+ }
37
+ else if ("dateFrom" in value && value.dateFrom != null) {
38
+ return {
39
+ date_from: value.dateFrom,
40
+ inclusive_from: value.inclusiveFrom,
41
+ };
42
+ }
43
+ else if ("dateTo" in value && value.dateTo != null) {
44
+ return {
45
+ date_to: value.dateTo,
46
+ inclusive_to: value.inclusiveTo,
47
+ };
48
+ }
49
+ else {
50
+ return undefined;
51
+ }
52
+ };
53
+ const mapApiPropertyFilters = (filters) => filters
54
+ .map((filter) => {
55
+ switch (filter.filterType) {
56
+ case "integer":
57
+ return {
58
+ filter_type: "integer",
59
+ property_name: filter.propertyName,
60
+ operator: filter.operator,
61
+ value: filter.value,
62
+ };
63
+ case "integerArray":
64
+ return {
65
+ filter_type: "integer_array",
66
+ property_name: filter.propertyName,
67
+ operator: filter.operator,
68
+ value: filter.value,
69
+ };
70
+ case "text":
71
+ return {
72
+ filter_type: "text",
73
+ property_name: filter.propertyName,
74
+ operator: filter.operator,
75
+ value: filter.value,
76
+ };
77
+ case "textArray":
78
+ return {
79
+ filter_type: "text_array",
80
+ property_name: filter.propertyName,
81
+ operator: filter.operator,
82
+ value: filter.value,
83
+ };
84
+ case "boolean":
85
+ return {
86
+ filter_type: "boolean",
87
+ property_name: filter.propertyName,
88
+ operator: filter.operator,
89
+ value: filter.value,
90
+ };
91
+ case "booleanArray":
92
+ return {
93
+ filter_type: "boolean_array",
94
+ property_name: filter.propertyName,
95
+ operator: filter.operator,
96
+ value: filter.value,
97
+ };
98
+ case "dateRange":
99
+ const value = mapDateFilterValue(filter.value);
100
+ if (!value) {
101
+ return undefined;
102
+ }
103
+ return {
104
+ filter_type: "date_range",
105
+ property_name: filter.propertyName,
106
+ value,
107
+ };
108
+ case "dateArray":
109
+ return {
110
+ filter_type: "date_array",
111
+ property_name: filter.propertyName,
112
+ operator: filter.operator,
113
+ value: filter.value,
114
+ };
115
+ case "geo":
116
+ return {
117
+ filter_type: "geo",
118
+ property_name: filter.propertyName,
119
+ latitude: filter.latitude,
120
+ longitude: filter.longitude,
121
+ max_distance_meters: filter.maxDistanceMeters,
122
+ };
123
+ case "isNull":
124
+ return {
125
+ filter_type: "is_null",
126
+ property_name: filter.propertyName,
127
+ is_null: filter.isNull,
128
+ };
129
+ case "uuid":
130
+ return {
131
+ filter_type: "uuid",
132
+ property_name: filter.propertyName,
133
+ operator: filter.operator,
134
+ value: filter.value,
135
+ };
136
+ case "uuidArray":
137
+ return {
138
+ filter_type: "uuid_array",
139
+ property_name: filter.propertyName,
140
+ operator: filter.operator,
141
+ value: filter.value,
142
+ };
143
+ default:
144
+ return undefined;
145
+ }
146
+ })
147
+ .filter((filter) => filter !== undefined);
148
+ const mapApiAggregations = (aggregations) => aggregations.map((aggregationGroup) => aggregationGroup.map((result) => ({
149
+ collection: result.collection,
150
+ search_query: result.searchQuery,
151
+ groupby_property: result.groupbyProperty,
152
+ aggregations: result.aggregations.map(mapApiPropertyAggregation),
153
+ filters: mapApiPropertyFilters(result.filters),
154
+ })));
155
+ const mapApiPropertyAggregation = (aggregation) => ({
156
+ property_name: aggregation.propertyName,
157
+ metrics: aggregation.metrics,
158
+ top_occurrences_limit: "topOccurrencesLimit" in aggregation
159
+ ? aggregation.topOccurrencesLimit
160
+ : undefined,
161
+ });
162
+ const mapApiUsage = (usage) => ({
163
+ requests: usage.requests,
164
+ request_tokens: usage.requestTokens,
165
+ response_tokens: usage.responseTokens,
166
+ total_tokens: usage.totalTokens,
167
+ details: usage.details,
168
+ });
169
+ const mapApiSources = (sources) => sources.map((source) => ({
170
+ object_id: source.objectId,
171
+ collection: source.collection,
172
+ }));
@@ -0,0 +1,219 @@
1
+ import { Vectors, WeaviateField } from "@weaviate/core";
2
+ import { NumericMetrics, TextMetrics, BooleanMetrics, DateMetrics, ComparisonOperator } from "./response.js";
3
+ export type ApiAskModeResponse = {
4
+ searches: ApiSearch[];
5
+ aggregations: ApiAggregation[];
6
+ usage: ApiModelUnitUsage;
7
+ total_time: number;
8
+ is_partial_answer?: boolean;
9
+ missing_information?: string[];
10
+ final_answer: string;
11
+ sources?: ApiSource[];
12
+ };
13
+ export type ApiQuerySort = {
14
+ property_name: string;
15
+ order: "ascending" | "descending";
16
+ tie_break?: ApiQuerySort;
17
+ };
18
+ export type ApiSearch = {
19
+ query?: string;
20
+ filters?: ApiPropertyFilter | ApiFilterAndOr;
21
+ collection: string;
22
+ sort_property?: ApiQuerySort;
23
+ uuid_value?: string;
24
+ };
25
+ export type ApiAggregation = {
26
+ groupby_property?: string;
27
+ aggregation: ApiPropertyAggregation;
28
+ filters?: ApiPropertyFilter | ApiFilterAndOr;
29
+ collection: string;
30
+ };
31
+ export type ApiFilterAndOr = {
32
+ combine: "AND" | "OR";
33
+ filters: (ApiPropertyFilter | ApiFilterAndOr)[];
34
+ };
35
+ export type ApiModelUnitUsage = {
36
+ model_units: number;
37
+ usage_in_plan: boolean;
38
+ remaining_plan_requests: number;
39
+ };
40
+ export type ApiQueryAgentResponse = {
41
+ original_query: string;
42
+ collection_names: string[];
43
+ searches: ApiSearchResult[][];
44
+ aggregations: ApiAggregationResult[][];
45
+ usage: ApiUsage;
46
+ total_time: number;
47
+ is_partial_answer: boolean;
48
+ missing_information: string[];
49
+ final_answer: string;
50
+ sources: ApiSource[];
51
+ };
52
+ export type ApiSearchResult = {
53
+ collection: string;
54
+ queries: (string | null)[];
55
+ filters: ApiPropertyFilter[][];
56
+ filter_operators: "AND" | "OR";
57
+ };
58
+ export type ApiPropertyFilter = ApiIntegerPropertyFilter | ApiIntegerArrayPropertyFilter | ApiTextPropertyFilter | ApiTextArrayPropertyFilter | ApiBooleanPropertyFilter | ApiBooleanArrayPropertyFilter | ApiDatePropertyFilter | ApiDateArrayPropertyFilter | ApiGeoPropertyFilter | ApiIsNullPropertyFilter | ApiUuidPropertyFilter | ApiUuidArrayPropertyFilter;
59
+ type ApiPropertyFilterBase = {
60
+ filter_type: string;
61
+ property_name: string;
62
+ };
63
+ export type ApiIntegerPropertyFilter = ApiPropertyFilterBase & {
64
+ filter_type: "integer";
65
+ operator: ComparisonOperator;
66
+ value: number;
67
+ };
68
+ export type ApiIntegerArrayPropertyFilter = ApiPropertyFilterBase & {
69
+ filter_type: "integer_array";
70
+ operator: ComparisonOperator;
71
+ value: number[];
72
+ };
73
+ export type ApiTextPropertyFilter = ApiPropertyFilterBase & {
74
+ filter_type: "text";
75
+ operator: ComparisonOperator;
76
+ value: string;
77
+ };
78
+ export type ApiTextArrayPropertyFilter = ApiPropertyFilterBase & {
79
+ filter_type: "text_array";
80
+ operator: ComparisonOperator;
81
+ value: string[];
82
+ };
83
+ export type ApiBooleanPropertyFilter = ApiPropertyFilterBase & {
84
+ filter_type: "boolean";
85
+ operator: ComparisonOperator;
86
+ value: boolean;
87
+ };
88
+ export type ApiBooleanArrayPropertyFilter = ApiPropertyFilterBase & {
89
+ filter_type: "boolean_array";
90
+ operator: ComparisonOperator;
91
+ value: boolean[];
92
+ };
93
+ export type ApiDateExact = {
94
+ exact_timestamp: string;
95
+ operator: ComparisonOperator;
96
+ };
97
+ export type ApiDateRangeFrom = {
98
+ date_from: string;
99
+ inclusive_from: boolean;
100
+ };
101
+ export type ApiDateRangeTo = {
102
+ date_to: string;
103
+ inclusive_to: boolean;
104
+ };
105
+ export type ApiDateRangeBetween = {
106
+ date_from: string;
107
+ date_to: string;
108
+ inclusive_from: boolean;
109
+ inclusive_to: boolean;
110
+ };
111
+ export type ApiDateFilterValue = ApiDateExact | ApiDateRangeFrom | ApiDateRangeTo | ApiDateRangeBetween;
112
+ export type ApiDatePropertyFilter = ApiPropertyFilterBase & {
113
+ filter_type: "date_range";
114
+ value: ApiDateFilterValue;
115
+ };
116
+ export type ApiDateArrayPropertyFilter = ApiPropertyFilterBase & {
117
+ filter_type: "date_array";
118
+ operator: ComparisonOperator;
119
+ value: string[];
120
+ };
121
+ export type ApiGeoPropertyFilter = ApiPropertyFilterBase & {
122
+ filter_type: "geo";
123
+ latitude: number;
124
+ longitude: number;
125
+ max_distance_meters: number;
126
+ };
127
+ export type ApiIsNullPropertyFilter = ApiPropertyFilterBase & {
128
+ filter_type: "is_null";
129
+ is_null: boolean;
130
+ };
131
+ export type ApiUuidPropertyFilter = ApiPropertyFilterBase & {
132
+ filter_type: "uuid";
133
+ operator: ComparisonOperator;
134
+ value: string;
135
+ };
136
+ export type ApiUuidArrayPropertyFilter = ApiPropertyFilterBase & {
137
+ filter_type: "uuid_array";
138
+ operator: ComparisonOperator;
139
+ value: string[];
140
+ };
141
+ export type ApiAggregationResult = {
142
+ collection: string;
143
+ search_query?: string;
144
+ groupby_property?: string;
145
+ aggregations: ApiPropertyAggregation[];
146
+ filters: ApiPropertyFilter[];
147
+ };
148
+ export type ApiPropertyAggregation = ApiIntegerPropertyAggregation | ApiTextPropertyAggregation | ApiBooleanPropertyAggregation | ApiDatePropertyAggregation;
149
+ type ApiPropertyAggregationBase = {
150
+ property_name: string;
151
+ };
152
+ export type ApiIntegerPropertyAggregation = ApiPropertyAggregationBase & {
153
+ metrics: NumericMetrics;
154
+ };
155
+ export type ApiTextPropertyAggregation = ApiPropertyAggregationBase & {
156
+ metrics: TextMetrics;
157
+ top_occurrences_limit?: number;
158
+ };
159
+ export type ApiBooleanPropertyAggregation = ApiPropertyAggregationBase & {
160
+ metrics: BooleanMetrics;
161
+ };
162
+ export type ApiDatePropertyAggregation = ApiPropertyAggregationBase & {
163
+ metrics: DateMetrics;
164
+ };
165
+ export type ApiUsage = {
166
+ requests: number;
167
+ request_tokens?: number;
168
+ response_tokens?: number;
169
+ total_tokens?: number;
170
+ details?: Record<string, number>;
171
+ };
172
+ export type ApiSource = {
173
+ object_id: string;
174
+ collection: string;
175
+ };
176
+ export type ApiReturnMetadata = {
177
+ creation_time: Date | null;
178
+ update_time: Date | null;
179
+ distance: number | null;
180
+ certainty: number | null;
181
+ score: number | null;
182
+ explain_score: string | null;
183
+ rerank_score: number | null;
184
+ is_consistent: boolean | null;
185
+ };
186
+ export type ApiWeaviateObject = {
187
+ /** The returned properties of the object as untyped key-value pairs from the API. */
188
+ properties: Record<string, WeaviateField>;
189
+ /** The returned metadata of the object. */
190
+ metadata: ApiReturnMetadata;
191
+ /** The returned references of the object. */
192
+ references: null;
193
+ /** The UUID of the object. */
194
+ uuid: string;
195
+ /** The returned vectors of the object. */
196
+ vector: Vectors;
197
+ /** The collection this object belongs to. */
198
+ collection: string;
199
+ };
200
+ export type ApiWeaviateReturn = {
201
+ /** The objects that were found by the query. */
202
+ objects: ApiWeaviateObject[];
203
+ };
204
+ export type ApiSearchModeResponse = {
205
+ searches?: ApiSearch[];
206
+ usage: ApiModelUnitUsage;
207
+ total_time: number;
208
+ search_results: ApiWeaviateReturn;
209
+ };
210
+ export type ApiSuggestedQuery = {
211
+ query: string;
212
+ };
213
+ export type ApiSuggestQueryResponse = {
214
+ queries: ApiSuggestedQuery[];
215
+ collection_count: number;
216
+ usage: ApiModelUnitUsage;
217
+ total_time: number;
218
+ };
219
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare const handleError: (responseText: string) => Promise<never>;
2
+ export declare class QueryAgentError extends Error {
3
+ code: string;
4
+ details?: Record<string, unknown> | undefined;
5
+ constructor(message: string, code: string, details?: Record<string, unknown> | undefined);
6
+ }
@@ -0,0 +1,34 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export const handleError = (responseText) => __awaiter(void 0, void 0, void 0, function* () {
11
+ const json = getJson(responseText);
12
+ if (json === null || json === void 0 ? void 0 : json.error) {
13
+ const error = json.error;
14
+ throw new QueryAgentError(error.message, error.code, error.details);
15
+ }
16
+ throw new Error(`Query agent failed. ${responseText}`);
17
+ });
18
+ const getJson = (responseText) => {
19
+ try {
20
+ return JSON.parse(responseText);
21
+ }
22
+ catch (_a) {
23
+ return null;
24
+ }
25
+ };
26
+ export class QueryAgentError extends Error {
27
+ constructor(message, code, details) {
28
+ super(message);
29
+ this.code = code;
30
+ this.details = details;
31
+ this.code = code;
32
+ this.details = details;
33
+ }
34
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./response.js";
2
+ export { QueryAgentError } from "./error.js";
@@ -0,0 +1,2 @@
1
+ export * from "./response.js";
2
+ export { QueryAgentError } from "./error.js";
@@ -0,0 +1,23 @@
1
+ import { QueryAgentResponse, StreamedTokens, ProgressMessage, WeaviateReturnWithCollection, SearchModeResponse, AskModeResponse, SuggestQueryResponse, OutputFormat, ParsedAskModeResponse } from "./response.js";
2
+ import { z } from "zod";
3
+ import { ApiQueryAgentResponse, ApiSearchModeResponse, ApiWeaviateReturn, ApiAskModeResponse, ApiSearch, ApiSuggestQueryResponse } from "./api-response.js";
4
+ import { ServerSentEvent } from "./server-sent-events.js";
5
+ /**
6
+ * Duck-types a value as a Zod schema (as opposed to a raw JSON Schema object):
7
+ * only a Zod schema carries a `parse` method, and a function value can never
8
+ * appear in a JSON-serialisable schema, so this reliably tells the two apart.
9
+ */
10
+ export declare const isZodSchema: (value: OutputFormat) => value is z.ZodType;
11
+ export declare function mapAskModeResponse(response: ApiAskModeResponse): AskModeResponse;
12
+ export declare function mapAskModeResponse<S extends z.ZodType>(response: ApiAskModeResponse, outputFormat: S): ParsedAskModeResponse<z.infer<S>>;
13
+ export declare function mapAskModeResponse(response: ApiAskModeResponse, outputFormat: Record<string, unknown>): ParsedAskModeResponse<Record<string, unknown>>;
14
+ export declare function mapAskModeResponse(response: ApiAskModeResponse, outputFormat: OutputFormat): ParsedAskModeResponse<unknown>;
15
+ export declare const mapResponse: (response: ApiQueryAgentResponse) => QueryAgentResponse;
16
+ export declare const mapProgressMessageFromSSE: (sse: ServerSentEvent) => ProgressMessage;
17
+ export declare const mapStreamedTokensFromSSE: (sse: ServerSentEvent) => StreamedTokens;
18
+ export declare const mapWeviateSearchResults: (response: ApiWeaviateReturn) => WeaviateReturnWithCollection;
19
+ export declare const mapSuggestQueryResponse: (response: ApiSuggestQueryResponse) => SuggestQueryResponse;
20
+ export declare const mapSearchOnlyResponse: (response: ApiSearchModeResponse) => {
21
+ mappedResponse: Omit<SearchModeResponse, "next">;
22
+ apiSearches: ApiSearch[] | undefined;
23
+ };