sst 3.0.23 → 3.0.25
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/dist/aws/bus.d.ts +8 -3
- package/dist/aws/bus.js +13 -3
- package/dist/event/index.d.ts +9 -10
- package/dist/event/index.js +6 -8
- package/package.json +1 -1
- package/dist/event/bus.d.ts +0 -20
- package/dist/event/bus.js +0 -57
- package/dist/event/destination.d.ts +0 -19
- package/dist/event/destination.js +0 -6
- package/dist/event/event.d.ts +0 -75
- package/dist/event/event.js +0 -43
- package/dist/vector-client.d.ts +0 -186
- package/dist/vector-client.js +0 -41
package/dist/aws/bus.d.ts
CHANGED
|
@@ -7,14 +7,19 @@ export declare namespace bus {
|
|
|
7
7
|
type Name = Extract<typeof Resource, {
|
|
8
8
|
type: "sst.aws.Bus";
|
|
9
9
|
}>["name"];
|
|
10
|
-
function
|
|
10
|
+
function subscriber<Events extends event.Definition>(_events: Events | Events[], cb: (input: {
|
|
11
11
|
[K in Events["type"]]: Extract<Events, {
|
|
12
12
|
type: K;
|
|
13
13
|
}>["$payload"];
|
|
14
14
|
}[Events["type"]], raw: EventBridgeEvent<string, any>) => Promise<void>): EventBridgeHandler<string, any, void>;
|
|
15
|
-
|
|
15
|
+
/** @deprecated
|
|
16
|
+
* use bus.subscriber instead
|
|
17
|
+
* */
|
|
18
|
+
const handler: typeof subscriber;
|
|
19
|
+
function publish<Definition extends event.Definition = any>(name: string | {
|
|
16
20
|
name: string;
|
|
17
|
-
}, def: Definition, properties: Definition["$input"], options?: {
|
|
21
|
+
}, def: Definition | string, properties: Definition["$input"], options?: {
|
|
22
|
+
metadata?: Definition["$metadata"];
|
|
18
23
|
aws?: AwsOptions;
|
|
19
24
|
}): Promise<any>;
|
|
20
25
|
class PublishError extends Error {
|
package/dist/aws/bus.js
CHANGED
|
@@ -6,7 +6,7 @@ export var bus;
|
|
|
6
6
|
const region = options?.region || client.region;
|
|
7
7
|
return `https://events.${region}.amazonaws.com/`;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function subscriber(_events, cb) {
|
|
10
10
|
return async function (event) {
|
|
11
11
|
const payload = {
|
|
12
12
|
type: event["detail-type"],
|
|
@@ -16,10 +16,20 @@ export var bus;
|
|
|
16
16
|
return cb(payload, event);
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
bus.
|
|
19
|
+
bus.subscriber = subscriber;
|
|
20
|
+
/** @deprecated
|
|
21
|
+
* use bus.subscriber instead
|
|
22
|
+
* */
|
|
23
|
+
bus.handler = subscriber;
|
|
20
24
|
async function publish(name, def, properties, options) {
|
|
21
25
|
const u = url(options?.aws);
|
|
22
|
-
const evt =
|
|
26
|
+
const evt = typeof def === "string"
|
|
27
|
+
? {
|
|
28
|
+
type: def,
|
|
29
|
+
properties,
|
|
30
|
+
metadata: options?.metadata || {},
|
|
31
|
+
}
|
|
32
|
+
: await def.create(properties);
|
|
23
33
|
const res = await client.fetch(u, {
|
|
24
34
|
method: "POST",
|
|
25
35
|
aws: options?.aws,
|
package/dist/event/index.d.ts
CHANGED
|
@@ -8,20 +8,19 @@ export declare namespace event {
|
|
|
8
8
|
$payload: any;
|
|
9
9
|
create: (...args: any[]) => Promise<any>;
|
|
10
10
|
};
|
|
11
|
-
export function builder<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
validator: Validator;
|
|
11
|
+
export function builder<Metadata extends ((type: string, properties: any) => any) | Parameters<Validator>[0], Validator extends (schema: any) => (input: any) => any = typeof ZodValidator>(input: {
|
|
12
|
+
validator?: Validator;
|
|
13
|
+
metadata?: Metadata;
|
|
15
14
|
}): {
|
|
16
15
|
<Type extends string, Schema extends Parameters<Validator>[0]>(type: Type, schema: Schema): {
|
|
17
|
-
create:
|
|
16
|
+
create: Metadata extends (type: string, properties: any) => any ? (properties: inferParser<Schema>["in"]) => Promise<{
|
|
18
17
|
type: Type;
|
|
19
18
|
properties: inferParser<Schema>["out"];
|
|
20
|
-
metadata: ReturnType<
|
|
21
|
-
}> : (properties: inferParser<Schema>["in"], metadata: inferParser<
|
|
19
|
+
metadata: Metadata extends (type: string, properties: any) => any ? ReturnType<Metadata> : inferParser<Metadata>["out"];
|
|
20
|
+
}> : (properties: inferParser<Schema>["in"], metadata: inferParser<Metadata>["in"]) => Promise<{
|
|
22
21
|
type: Type;
|
|
23
22
|
properties: inferParser<Schema>["out"];
|
|
24
|
-
metadata: ReturnType<
|
|
23
|
+
metadata: Metadata extends (type: string, properties: any) => any ? ReturnType<Metadata> : inferParser<Metadata>["out"];
|
|
25
24
|
}>;
|
|
26
25
|
type: Type;
|
|
27
26
|
$input: inferParser<Schema>["in"];
|
|
@@ -29,9 +28,9 @@ export declare namespace event {
|
|
|
29
28
|
$payload: {
|
|
30
29
|
type: Type;
|
|
31
30
|
properties: inferParser<Schema>["out"];
|
|
32
|
-
metadata: ReturnType<
|
|
31
|
+
metadata: Metadata extends (type: string, properties: any) => any ? ReturnType<Metadata> : inferParser<Metadata>["out"];
|
|
33
32
|
};
|
|
34
|
-
$metadata: ReturnType<
|
|
33
|
+
$metadata: Metadata extends (type: string, properties: any) => any ? ReturnType<Metadata> : inferParser<Metadata>["out"];
|
|
35
34
|
};
|
|
36
35
|
coerce<Events extends Definition>(_events: Events | Events[], raw: any): { [K in Events["type"]]: Extract<Events, {
|
|
37
36
|
type: K;
|
package/dist/event/index.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
export var event;
|
|
2
2
|
(function (event) {
|
|
3
3
|
function builder(input) {
|
|
4
|
-
const validator = input.validator;
|
|
5
|
-
const metadataValidator = input.metadata ? validator(input.metadata) : null;
|
|
4
|
+
const validator = input.validator || ZodValidator;
|
|
6
5
|
const fn = function event(type, schema) {
|
|
7
6
|
const validate = validator(schema);
|
|
8
7
|
async function create(properties, metadata) {
|
|
9
|
-
|
|
10
|
-
metadata
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
8
|
+
metadata = input.metadata
|
|
9
|
+
? typeof input.metadata === "function"
|
|
10
|
+
? input.metadata(type, properties)
|
|
11
|
+
: input.metadata(metadata)
|
|
12
|
+
: {};
|
|
15
13
|
properties = validate(properties);
|
|
16
14
|
return {
|
|
17
15
|
type,
|
package/package.json
CHANGED
package/dist/event/bus.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { AwsOptions } from "../aws/client.js";
|
|
3
|
-
import { Resource } from "../resource.js";
|
|
4
|
-
import { EventDefinition } from "./event.js";
|
|
5
|
-
import { EventBridgeEvent, EventBridgeHandler } from "aws-lambda";
|
|
6
|
-
export declare namespace bus {
|
|
7
|
-
type Name = Extract<typeof Resource, {
|
|
8
|
-
type: "sst.aws.Bus";
|
|
9
|
-
}>["name"];
|
|
10
|
-
function handle<Events extends EventDefinition>(_events: Events | Events[], cb: (input: {
|
|
11
|
-
[K in Events["type"]]: Extract<Events, {
|
|
12
|
-
type: K;
|
|
13
|
-
}>["$payload"];
|
|
14
|
-
}[Events["type"]], raw: EventBridgeEvent<string, any>) => Promise<void>): EventBridgeHandler<string, any, void>;
|
|
15
|
-
function publish<N extends Name, Definition extends EventDefinition>(name: N, def: Definition, properties: Definition["$input"], options?: AwsOptions): Promise<unknown>;
|
|
16
|
-
class PublishError extends Error {
|
|
17
|
-
readonly response: Response;
|
|
18
|
-
constructor(response: Response);
|
|
19
|
-
}
|
|
20
|
-
}
|
package/dist/event/bus.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { client } from "../aws/client.js";
|
|
2
|
-
import { Resource } from "../resource.js";
|
|
3
|
-
export var bus;
|
|
4
|
-
(function (bus) {
|
|
5
|
-
function url(options) {
|
|
6
|
-
const region = options?.region || client.region;
|
|
7
|
-
return `https://events.${region}.amazonaws.com/`;
|
|
8
|
-
}
|
|
9
|
-
function handle(_events, cb) {
|
|
10
|
-
return async function (event) {
|
|
11
|
-
const payload = {
|
|
12
|
-
type: event["detail-type"],
|
|
13
|
-
properties: event.detail.properties,
|
|
14
|
-
metadata: event.detail.metadata,
|
|
15
|
-
};
|
|
16
|
-
return cb(payload, event);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
bus.handle = handle;
|
|
20
|
-
async function publish(name, def, properties, options) {
|
|
21
|
-
const u = url(options);
|
|
22
|
-
const evt = await def.create(properties);
|
|
23
|
-
const res = await client.fetch(u, {
|
|
24
|
-
method: "POST",
|
|
25
|
-
aws: options,
|
|
26
|
-
headers: {
|
|
27
|
-
"X-Amz-Target": "AWSEvents.PutEvents",
|
|
28
|
-
"Content-Type": "application/x-amz-json-1.1",
|
|
29
|
-
},
|
|
30
|
-
body: JSON.stringify({
|
|
31
|
-
Entries: [
|
|
32
|
-
{
|
|
33
|
-
Source: [Resource.App.name, Resource.App.stage].join("."),
|
|
34
|
-
DetailType: evt.type,
|
|
35
|
-
Detail: JSON.stringify({
|
|
36
|
-
metadata: evt.metadata,
|
|
37
|
-
payload: evt.properties,
|
|
38
|
-
}),
|
|
39
|
-
EventBusName: name,
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
}),
|
|
43
|
-
});
|
|
44
|
-
if (!res.ok)
|
|
45
|
-
throw new PublishError(res);
|
|
46
|
-
return res.json();
|
|
47
|
-
}
|
|
48
|
-
bus.publish = publish;
|
|
49
|
-
class PublishError extends Error {
|
|
50
|
-
response;
|
|
51
|
-
constructor(response) {
|
|
52
|
-
super("Failed to publish event to bus");
|
|
53
|
-
this.response = response;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
bus.PublishError = PublishError;
|
|
57
|
-
})(bus || (bus = {}));
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Prettify } from "../util/prettify.js";
|
|
2
|
-
export interface Payload {
|
|
3
|
-
type: string;
|
|
4
|
-
properties: any;
|
|
5
|
-
metadata: any;
|
|
6
|
-
}
|
|
7
|
-
declare const Publishers: {
|
|
8
|
-
"sst.aws.Bus": (properties: {
|
|
9
|
-
name: string;
|
|
10
|
-
}, payload: Payload) => void;
|
|
11
|
-
};
|
|
12
|
-
type Publishers = typeof Publishers;
|
|
13
|
-
export type Destinations = {
|
|
14
|
-
[key in keyof Publishers]: Prettify<{
|
|
15
|
-
type: key;
|
|
16
|
-
} & Parameters<Publishers[key]>[0]>;
|
|
17
|
-
}[keyof Publishers];
|
|
18
|
-
export declare function publish(destination: Destinations, payload: Payload): void;
|
|
19
|
-
export {};
|
package/dist/event/event.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { ZodSchema, z } from "zod";
|
|
2
|
-
export declare namespace event {
|
|
3
|
-
export type Definition = {
|
|
4
|
-
type: string;
|
|
5
|
-
$input: any;
|
|
6
|
-
$output: any;
|
|
7
|
-
$metadata: any;
|
|
8
|
-
$payload: any;
|
|
9
|
-
create: (...args: any[]) => Promise<any>;
|
|
10
|
-
};
|
|
11
|
-
export function builder<MetadataFunction extends (type: string, properties: any) => any, Validator extends (schema: any) => (input: any) => any, MetadataSchema extends Parameters<Validator>[0] | undefined>(input: {
|
|
12
|
-
metadata?: MetadataSchema;
|
|
13
|
-
metadataFn?: MetadataFunction;
|
|
14
|
-
validator: Validator;
|
|
15
|
-
}): {
|
|
16
|
-
<Type extends string, Schema extends Parameters<Validator>[0]>(type: Type, schema: Schema): {
|
|
17
|
-
create: undefined extends MetadataSchema ? (properties: inferParser<Schema>["in"]) => Promise<{
|
|
18
|
-
type: Type;
|
|
19
|
-
properties: inferParser<Schema>["out"];
|
|
20
|
-
metadata: ReturnType<MetadataFunction>;
|
|
21
|
-
}> : (properties: inferParser<Schema>["in"], metadata: inferParser<MetadataSchema>["in"]) => Promise<{
|
|
22
|
-
type: Type;
|
|
23
|
-
properties: inferParser<Schema>["out"];
|
|
24
|
-
metadata: ReturnType<MetadataFunction>;
|
|
25
|
-
}>;
|
|
26
|
-
type: Type;
|
|
27
|
-
$input: inferParser<Schema>["in"];
|
|
28
|
-
$output: inferParser<Schema>["out"];
|
|
29
|
-
$payload: {
|
|
30
|
-
type: Type;
|
|
31
|
-
properties: inferParser<Schema>["out"];
|
|
32
|
-
metadata: ReturnType<MetadataFunction>;
|
|
33
|
-
};
|
|
34
|
-
$metadata: ReturnType<MetadataFunction>;
|
|
35
|
-
};
|
|
36
|
-
coerce<Events extends Definition>(_events: Events | Events[], raw: any): { [K in Events["type"]]: Extract<Events, {
|
|
37
|
-
type: K;
|
|
38
|
-
}>["$payload"]; }[Events["type"]];
|
|
39
|
-
};
|
|
40
|
-
export function ZodValidator<Schema extends ZodSchema>(schema: Schema): (input: z.input<Schema>) => z.output<Schema>;
|
|
41
|
-
type ParserZodEsque<TInput, TParsedInput> = {
|
|
42
|
-
_input: TInput;
|
|
43
|
-
_output: TParsedInput;
|
|
44
|
-
};
|
|
45
|
-
type ParserValibotEsque<TInput, TParsedInput> = {
|
|
46
|
-
_types?: {
|
|
47
|
-
input: TInput;
|
|
48
|
-
output: TParsedInput;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
type ParserMyZodEsque<TInput> = {
|
|
52
|
-
parse: (input: any) => TInput;
|
|
53
|
-
};
|
|
54
|
-
type ParserSuperstructEsque<TInput> = {
|
|
55
|
-
create: (input: unknown) => TInput;
|
|
56
|
-
};
|
|
57
|
-
type ParserCustomValidatorEsque<TInput> = (input: unknown) => Promise<TInput> | TInput;
|
|
58
|
-
type ParserYupEsque<TInput> = {
|
|
59
|
-
validateSync: (input: unknown) => TInput;
|
|
60
|
-
};
|
|
61
|
-
type ParserScaleEsque<TInput> = {
|
|
62
|
-
assert(value: unknown): asserts value is TInput;
|
|
63
|
-
};
|
|
64
|
-
export type ParserWithoutInput<TInput> = ParserCustomValidatorEsque<TInput> | ParserMyZodEsque<TInput> | ParserScaleEsque<TInput> | ParserSuperstructEsque<TInput> | ParserYupEsque<TInput>;
|
|
65
|
-
export type ParserWithInputOutput<TInput, TParsedInput> = ParserZodEsque<TInput, TParsedInput> | ParserValibotEsque<TInput, TParsedInput>;
|
|
66
|
-
export type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
|
|
67
|
-
export type inferParser<TParser extends Parser> = TParser extends ParserWithInputOutput<infer $TIn, infer $TOut> ? {
|
|
68
|
-
in: $TIn;
|
|
69
|
-
out: $TOut;
|
|
70
|
-
} : TParser extends ParserWithoutInput<infer $InOut> ? {
|
|
71
|
-
in: $InOut;
|
|
72
|
-
out: $InOut;
|
|
73
|
-
} : never;
|
|
74
|
-
export {};
|
|
75
|
-
}
|
package/dist/event/event.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export var event;
|
|
2
|
-
(function (event) {
|
|
3
|
-
function builder(input) {
|
|
4
|
-
const validator = input.validator;
|
|
5
|
-
const metadataValidator = input.metadata ? validator(input.metadata) : null;
|
|
6
|
-
const fn = function event(type, schema) {
|
|
7
|
-
const validate = validator(schema);
|
|
8
|
-
async function create(properties, metadata) {
|
|
9
|
-
if (metadataValidator) {
|
|
10
|
-
metadata = metadataValidator(metadata);
|
|
11
|
-
}
|
|
12
|
-
if (input.metadataFn) {
|
|
13
|
-
metadata = input.metadataFn(type, properties);
|
|
14
|
-
}
|
|
15
|
-
properties = validate(properties);
|
|
16
|
-
return {
|
|
17
|
-
type,
|
|
18
|
-
properties,
|
|
19
|
-
metadata,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
create: create,
|
|
24
|
-
type,
|
|
25
|
-
$input: {},
|
|
26
|
-
$output: {},
|
|
27
|
-
$payload: {},
|
|
28
|
-
$metadata: {},
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
fn.coerce = (_events, raw) => {
|
|
32
|
-
return raw;
|
|
33
|
-
};
|
|
34
|
-
return fn;
|
|
35
|
-
}
|
|
36
|
-
event.builder = builder;
|
|
37
|
-
function ZodValidator(schema) {
|
|
38
|
-
return (input) => {
|
|
39
|
-
return schema.parse(input);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
event.ZodValidator = ZodValidator;
|
|
43
|
-
})(event || (event = {}));
|
package/dist/vector-client.d.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { Resource } from "./resource.js";
|
|
2
|
-
export type IngestEvent = {
|
|
3
|
-
/**
|
|
4
|
-
* The text used to generate the embedding vector.
|
|
5
|
-
* At least one of `text` or `image` must be provided.
|
|
6
|
-
* @example
|
|
7
|
-
* ```js
|
|
8
|
-
* {
|
|
9
|
-
* text: "This is an example text.",
|
|
10
|
-
* }
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
text?: string;
|
|
14
|
-
/**
|
|
15
|
-
* The base64 representation of the image used to generate the embedding vector.
|
|
16
|
-
* At least one of `text` or `image` must be provided.
|
|
17
|
-
* @example
|
|
18
|
-
* ```js
|
|
19
|
-
* {
|
|
20
|
-
* image: await fs.readFile("./file.jpg").toString("base64"),
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
image?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Metadata for the event in JSON format.
|
|
27
|
-
* This metadata will be used to filter when retrieving and removing embeddings.
|
|
28
|
-
* @example
|
|
29
|
-
* ```js
|
|
30
|
-
* {
|
|
31
|
-
* metadata: {
|
|
32
|
-
* type: "movie",
|
|
33
|
-
* id: "movie-123",
|
|
34
|
-
* name: "Spiderman",
|
|
35
|
-
* }
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
metadata: Record<string, any>;
|
|
40
|
-
};
|
|
41
|
-
export type RetrieveEvent = {
|
|
42
|
-
/**
|
|
43
|
-
* The text prompt used to retrieve embeddings.
|
|
44
|
-
* At least one of `text` or `image` must be provided.
|
|
45
|
-
* @example
|
|
46
|
-
* ```js
|
|
47
|
-
* {
|
|
48
|
-
* text: "This is an example text.",
|
|
49
|
-
* }
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
text?: string;
|
|
53
|
-
/**
|
|
54
|
-
* The base64 representation of the image prompt used to retrive embeddings.
|
|
55
|
-
* At least one of `text` or `image` must be provided.
|
|
56
|
-
* @example
|
|
57
|
-
* ```js
|
|
58
|
-
* {
|
|
59
|
-
* image: await fs.readFile("./file.jpg").toString("base64"),
|
|
60
|
-
* }
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
image?: string;
|
|
64
|
-
/**
|
|
65
|
-
* The metadata used to filter the retrieval of embeddings.
|
|
66
|
-
* Only embeddings with metadata that match the provided fields will be returned.
|
|
67
|
-
* @example
|
|
68
|
-
* ```js
|
|
69
|
-
* {
|
|
70
|
-
* include: {
|
|
71
|
-
* type: "movie",
|
|
72
|
-
* release: "2001",
|
|
73
|
-
* }
|
|
74
|
-
* }
|
|
75
|
-
* ```
|
|
76
|
-
* This will match the embedding with metadata:
|
|
77
|
-
* {
|
|
78
|
-
* type: "movie",
|
|
79
|
-
* name: "Spiderman",
|
|
80
|
-
* release: "2001",
|
|
81
|
-
* }
|
|
82
|
-
*
|
|
83
|
-
* But not the embedding with metadata:
|
|
84
|
-
* {
|
|
85
|
-
* type: "book",
|
|
86
|
-
* name: "Spiderman",
|
|
87
|
-
* release: "2001",
|
|
88
|
-
* }
|
|
89
|
-
*/
|
|
90
|
-
include: Record<string, any>;
|
|
91
|
-
/**
|
|
92
|
-
* Exclude embeddings with metadata that match the provided fields.
|
|
93
|
-
* @example
|
|
94
|
-
* ```js
|
|
95
|
-
* {
|
|
96
|
-
* include: {
|
|
97
|
-
* type: "movie",
|
|
98
|
-
* release: "2001",
|
|
99
|
-
* },
|
|
100
|
-
* exclude: {
|
|
101
|
-
* name: "Spiderman",
|
|
102
|
-
* }
|
|
103
|
-
* }
|
|
104
|
-
* ```
|
|
105
|
-
* This will match the embedding with metadata:
|
|
106
|
-
* {
|
|
107
|
-
* type: "movie",
|
|
108
|
-
* name: "A Beautiful Mind",
|
|
109
|
-
* release: "2001",
|
|
110
|
-
* }
|
|
111
|
-
*
|
|
112
|
-
* But not the embedding with metadata:
|
|
113
|
-
* {
|
|
114
|
-
* type: "book",
|
|
115
|
-
* name: "Spiderman",
|
|
116
|
-
* release: "2001",
|
|
117
|
-
* }
|
|
118
|
-
*/
|
|
119
|
-
exclude?: Record<string, any>;
|
|
120
|
-
/**
|
|
121
|
-
* The threshold of similarity between the prompt and the retrieved embeddings.
|
|
122
|
-
* Only embeddings with a similarity score higher than the threshold will be returned.
|
|
123
|
-
* Expected value is between 0 and 1.
|
|
124
|
-
* - 0 means the prompt and the retrieved embeddings are completely different.
|
|
125
|
-
* - 1 means the prompt and the retrieved embeddings are identical.
|
|
126
|
-
* @default `0`
|
|
127
|
-
* @example
|
|
128
|
-
* ```js
|
|
129
|
-
* {
|
|
130
|
-
* threshold: 0.5,
|
|
131
|
-
* }
|
|
132
|
-
* ```
|
|
133
|
-
*/
|
|
134
|
-
threshold?: number;
|
|
135
|
-
/**
|
|
136
|
-
* The number of results to return.
|
|
137
|
-
* @default `10`
|
|
138
|
-
* @example
|
|
139
|
-
* ```js
|
|
140
|
-
* {
|
|
141
|
-
* count: 10,
|
|
142
|
-
* }
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
count?: number;
|
|
146
|
-
};
|
|
147
|
-
export type RemoveEvent = {
|
|
148
|
-
/**
|
|
149
|
-
* The metadata used to filter the removal of embeddings.
|
|
150
|
-
* Only embeddings with metadata that match the provided fields will be removed.
|
|
151
|
-
* @example
|
|
152
|
-
* To remove embeddings for movie with id "movie-123":
|
|
153
|
-
* ```js
|
|
154
|
-
* {
|
|
155
|
-
* include: {
|
|
156
|
-
* id: "movie-123",
|
|
157
|
-
* }
|
|
158
|
-
* }
|
|
159
|
-
* ```
|
|
160
|
-
* To remove embeddings for all movies:
|
|
161
|
-
* {
|
|
162
|
-
* include: {
|
|
163
|
-
* type: "movie",
|
|
164
|
-
* }
|
|
165
|
-
* }
|
|
166
|
-
*/
|
|
167
|
-
include: Record<string, any>;
|
|
168
|
-
};
|
|
169
|
-
type RetriveResponse = {
|
|
170
|
-
/**
|
|
171
|
-
* Metadata for the event in JSON format that was provided when ingesting the embedding.
|
|
172
|
-
*/
|
|
173
|
-
metadata: Record<string, any>;
|
|
174
|
-
/**
|
|
175
|
-
* The similarity score between the prompt and the retrieved embedding.
|
|
176
|
-
*/
|
|
177
|
-
score: number;
|
|
178
|
-
};
|
|
179
|
-
export declare function VectorClient<T extends keyof {
|
|
180
|
-
[key in keyof Resource as "sst.aws.Vector" extends Resource[key]["type"] ? string extends key ? never : key : never]: Resource[key];
|
|
181
|
-
}>(name: T): {
|
|
182
|
-
ingest: (event: IngestEvent) => Promise<void>;
|
|
183
|
-
retrieve: (event: RetrieveEvent) => Promise<RetriveResponse>;
|
|
184
|
-
remove: (event: RemoveEvent) => Promise<void>;
|
|
185
|
-
};
|
|
186
|
-
export {};
|
package/dist/vector-client.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { LambdaClient, InvokeCommand, } from "@aws-sdk/client-lambda";
|
|
2
|
-
import { Resource } from "./resource.js";
|
|
3
|
-
const lambda = new LambdaClient();
|
|
4
|
-
export function VectorClient(name) {
|
|
5
|
-
return {
|
|
6
|
-
ingest: async (event) => {
|
|
7
|
-
const ret = await lambda.send(new InvokeCommand({
|
|
8
|
-
// @ts-expect-error
|
|
9
|
-
FunctionName: Resource[name].ingestor,
|
|
10
|
-
Payload: JSON.stringify(event),
|
|
11
|
-
}));
|
|
12
|
-
parsePayload(ret, "Failed to ingest into the vector db");
|
|
13
|
-
},
|
|
14
|
-
retrieve: async (event) => {
|
|
15
|
-
const ret = await lambda.send(new InvokeCommand({
|
|
16
|
-
// @ts-expect-error
|
|
17
|
-
FunctionName: Resource[name].retriever,
|
|
18
|
-
Payload: JSON.stringify(event),
|
|
19
|
-
}));
|
|
20
|
-
return parsePayload(ret, "Failed to retrieve from the vector db");
|
|
21
|
-
},
|
|
22
|
-
remove: async (event) => {
|
|
23
|
-
const ret = await lambda.send(new InvokeCommand({
|
|
24
|
-
// @ts-expect-error
|
|
25
|
-
FunctionName: Resource[name].remover,
|
|
26
|
-
Payload: JSON.stringify(event),
|
|
27
|
-
}));
|
|
28
|
-
parsePayload(ret, "Failed to remove from the vector db");
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function parsePayload(output, message) {
|
|
33
|
-
const payload = JSON.parse(Buffer.from(output.Payload).toString());
|
|
34
|
-
// Set cause to the payload so that it can be logged in CloudWatch
|
|
35
|
-
if (output.FunctionError) {
|
|
36
|
-
const e = new Error(message);
|
|
37
|
-
e.cause = payload;
|
|
38
|
-
throw e;
|
|
39
|
-
}
|
|
40
|
-
return payload;
|
|
41
|
-
}
|