sst 3.0.15 → 3.0.17
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/auth/session.js +1 -1
- package/dist/event/index.d.ts +74 -0
- package/dist/event/index.js +38 -0
- package/dist/realtime/index.d.ts +2 -2
- package/dist/util/prettify.d.ts +3 -0
- package/dist/util/prettify.js +1 -0
- package/dist/vector/index.d.ts +35 -59
- package/dist/vector/index.js +13 -13
- package/package.json +9 -7
package/dist/auth/session.js
CHANGED
|
@@ -6,7 +6,7 @@ export function createSessionBuilder() {
|
|
|
6
6
|
async verify(token) {
|
|
7
7
|
const auth = Object.values(Resource).find((value) => value.publicKey);
|
|
8
8
|
if (!auth) {
|
|
9
|
-
throw new Error("No auth resource found");
|
|
9
|
+
throw new Error("No auth resource found. Make sure to link the auth resource to this function.");
|
|
10
10
|
}
|
|
11
11
|
const publicKey = auth.publicKey;
|
|
12
12
|
const result = await jwtVerify(token, await importSPKI(publicKey, "RS512"));
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ZodObject, ZodSchema, z } from "zod";
|
|
2
|
+
type Event = {
|
|
3
|
+
type: string;
|
|
4
|
+
$output: any;
|
|
5
|
+
$metadata: any;
|
|
6
|
+
$payload: any;
|
|
7
|
+
};
|
|
8
|
+
export declare function EventClient<MetadataFunction extends () => any, Validator extends (schema: any) => (input: any) => any, MetadataSchema extends Parameters<Validator>[0] | undefined>(input: {
|
|
9
|
+
metadata?: MetadataSchema;
|
|
10
|
+
metadataFn?: MetadataFunction;
|
|
11
|
+
validator: Validator;
|
|
12
|
+
}): {
|
|
13
|
+
<Type extends string, Schema extends Parameters<Validator>[0]>(type: Type, schema: Schema): {
|
|
14
|
+
create: undefined extends MetadataSchema ? (properties: inferParser<Schema>["in"]) => {
|
|
15
|
+
type: Type;
|
|
16
|
+
properties: inferParser<Schema>["out"];
|
|
17
|
+
metadata: ReturnType<MetadataFunction>;
|
|
18
|
+
} : (properties: inferParser<Schema>["in"], metadata: inferParser<MetadataSchema>["in"]) => {
|
|
19
|
+
type: Type;
|
|
20
|
+
properties: inferParser<Schema>["out"];
|
|
21
|
+
metadata: ReturnType<MetadataFunction>;
|
|
22
|
+
};
|
|
23
|
+
type: Type;
|
|
24
|
+
$input: inferParser<Schema>["in"];
|
|
25
|
+
$output: inferParser<Schema>["out"];
|
|
26
|
+
$payload: {
|
|
27
|
+
type: Type;
|
|
28
|
+
properties: inferParser<Schema>["out"];
|
|
29
|
+
metadata: ReturnType<MetadataFunction>;
|
|
30
|
+
};
|
|
31
|
+
$metadata: ReturnType<MetadataFunction>;
|
|
32
|
+
};
|
|
33
|
+
coerce<Events extends Event>(_events: Events | Events[], raw: any): { [K in Events["type"]]: Extract<Events, {
|
|
34
|
+
type: K;
|
|
35
|
+
}>["$payload"]; }[Events["type"]];
|
|
36
|
+
};
|
|
37
|
+
export declare function ZodValidator<Schema extends ZodSchema>(schema: Schema): (input: z.input<Schema>) => z.output<Schema>;
|
|
38
|
+
export type ParserZodEsque<TInput, TParsedInput> = {
|
|
39
|
+
_input: TInput;
|
|
40
|
+
_output: TParsedInput;
|
|
41
|
+
};
|
|
42
|
+
export type ParserValibotEsque<TInput, TParsedInput> = {
|
|
43
|
+
_types?: {
|
|
44
|
+
input: TInput;
|
|
45
|
+
output: TParsedInput;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export type ParserMyZodEsque<TInput> = {
|
|
49
|
+
parse: (input: any) => TInput;
|
|
50
|
+
};
|
|
51
|
+
export type ParserSuperstructEsque<TInput> = {
|
|
52
|
+
create: (input: unknown) => TInput;
|
|
53
|
+
};
|
|
54
|
+
export type ParserCustomValidatorEsque<TInput> = (input: unknown) => Promise<TInput> | TInput;
|
|
55
|
+
export type ParserYupEsque<TInput> = {
|
|
56
|
+
validateSync: (input: unknown) => TInput;
|
|
57
|
+
};
|
|
58
|
+
export type ParserScaleEsque<TInput> = {
|
|
59
|
+
assert(value: unknown): asserts value is TInput;
|
|
60
|
+
};
|
|
61
|
+
export type ParserWithoutInput<TInput> = ParserCustomValidatorEsque<TInput> | ParserMyZodEsque<TInput> | ParserScaleEsque<TInput> | ParserSuperstructEsque<TInput> | ParserYupEsque<TInput>;
|
|
62
|
+
export type ParserWithInputOutput<TInput, TParsedInput> = ParserZodEsque<TInput, TParsedInput> | ParserValibotEsque<TInput, TParsedInput>;
|
|
63
|
+
export type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
|
|
64
|
+
export type inferParser<TParser extends Parser> = TParser extends ParserWithInputOutput<infer $TIn, infer $TOut> ? {
|
|
65
|
+
in: $TIn;
|
|
66
|
+
out: $TOut;
|
|
67
|
+
} : TParser extends ParserWithoutInput<infer $InOut> ? {
|
|
68
|
+
in: $InOut;
|
|
69
|
+
out: $InOut;
|
|
70
|
+
} : never;
|
|
71
|
+
export type inferEvent<T extends {
|
|
72
|
+
shape: ZodObject<any>;
|
|
73
|
+
}> = z.infer<T["shape"]>;
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export function EventClient(input) {
|
|
2
|
+
const validator = input.validator;
|
|
3
|
+
const metadataValidator = input.metadata ? validator(input.metadata) : null;
|
|
4
|
+
const fn = function event(type, schema) {
|
|
5
|
+
const validate = validator(schema);
|
|
6
|
+
async function create(properties, metadata) {
|
|
7
|
+
if (metadataValidator) {
|
|
8
|
+
metadata = metadataValidator(metadata);
|
|
9
|
+
}
|
|
10
|
+
if (input.metadataFn) {
|
|
11
|
+
metadata = input.metadataFn();
|
|
12
|
+
}
|
|
13
|
+
properties = validate(properties);
|
|
14
|
+
return {
|
|
15
|
+
type,
|
|
16
|
+
properties,
|
|
17
|
+
metadata,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
create: create,
|
|
22
|
+
type,
|
|
23
|
+
$input: {},
|
|
24
|
+
$output: {},
|
|
25
|
+
$payload: {},
|
|
26
|
+
$metadata: {},
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
fn.coerce = (_events, raw) => {
|
|
30
|
+
return raw;
|
|
31
|
+
};
|
|
32
|
+
return fn;
|
|
33
|
+
}
|
|
34
|
+
export function ZodValidator(schema) {
|
|
35
|
+
return (input) => {
|
|
36
|
+
return schema.parse(input);
|
|
37
|
+
};
|
|
38
|
+
}
|
package/dist/realtime/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface RealtimeAuthResult {
|
|
|
13
13
|
* And to subscribe to all topics under a specific prefix.
|
|
14
14
|
* ```js
|
|
15
15
|
* {
|
|
16
|
-
* subscribe: ["chat
|
|
16
|
+
* subscribe: ["chat/*"]
|
|
17
17
|
* }
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
@@ -30,7 +30,7 @@ export interface RealtimeAuthResult {
|
|
|
30
30
|
* And to publish to all topics under a specific prefix.
|
|
31
31
|
* ```js
|
|
32
32
|
* {
|
|
33
|
-
* publish: ["chat
|
|
33
|
+
* publish: ["chat/*"]
|
|
34
34
|
* }
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/vector/index.d.ts
CHANGED
|
@@ -1,30 +1,18 @@
|
|
|
1
1
|
import { Resource } from "../resource.js";
|
|
2
|
-
export interface
|
|
2
|
+
export interface PutEvent {
|
|
3
3
|
/**
|
|
4
|
-
* The
|
|
5
|
-
* At least one of `text` or `image` must be provided.
|
|
4
|
+
* The vector to store in the database.
|
|
6
5
|
* @example
|
|
7
6
|
* ```js
|
|
8
7
|
* {
|
|
9
|
-
*
|
|
8
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
10
9
|
* }
|
|
11
10
|
* ```
|
|
12
11
|
*/
|
|
13
|
-
|
|
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;
|
|
12
|
+
vector: number[];
|
|
25
13
|
/**
|
|
26
14
|
* Metadata for the event in JSON format.
|
|
27
|
-
* This metadata will be used to filter when
|
|
15
|
+
* This metadata will be used to filter when quering and removing vectors.
|
|
28
16
|
* @example
|
|
29
17
|
* ```js
|
|
30
18
|
* {
|
|
@@ -38,32 +26,20 @@ export interface IngestEvent {
|
|
|
38
26
|
*/
|
|
39
27
|
metadata: Record<string, any>;
|
|
40
28
|
}
|
|
41
|
-
export interface
|
|
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;
|
|
29
|
+
export interface QueryEvent {
|
|
53
30
|
/**
|
|
54
|
-
* The
|
|
55
|
-
* At least one of `text` or `image` must be provided.
|
|
31
|
+
* The vector used to query the database.
|
|
56
32
|
* @example
|
|
57
33
|
* ```js
|
|
58
34
|
* {
|
|
59
|
-
*
|
|
35
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
60
36
|
* }
|
|
61
37
|
* ```
|
|
62
38
|
*/
|
|
63
|
-
|
|
39
|
+
vector: number[];
|
|
64
40
|
/**
|
|
65
|
-
* The metadata used to filter the
|
|
66
|
-
* Only
|
|
41
|
+
* The metadata used to filter the vectors.
|
|
42
|
+
* Only vectors that match the provided fields will be returned.
|
|
67
43
|
* @example
|
|
68
44
|
* ```js
|
|
69
45
|
* {
|
|
@@ -73,7 +49,7 @@ export interface RetrieveEvent {
|
|
|
73
49
|
* }
|
|
74
50
|
* }
|
|
75
51
|
* ```
|
|
76
|
-
* This will match the
|
|
52
|
+
* This will match the vector with metadata:
|
|
77
53
|
* ```js
|
|
78
54
|
* {
|
|
79
55
|
* type: "movie",
|
|
@@ -82,7 +58,7 @@ export interface RetrieveEvent {
|
|
|
82
58
|
* }
|
|
83
59
|
* ```
|
|
84
60
|
*
|
|
85
|
-
* But not the
|
|
61
|
+
* But not the vector with metadata:
|
|
86
62
|
* ```js
|
|
87
63
|
* {
|
|
88
64
|
* type: "book",
|
|
@@ -93,7 +69,7 @@ export interface RetrieveEvent {
|
|
|
93
69
|
*/
|
|
94
70
|
include: Record<string, any>;
|
|
95
71
|
/**
|
|
96
|
-
* Exclude
|
|
72
|
+
* Exclude vectors with metadata that match the provided fields.
|
|
97
73
|
* @example
|
|
98
74
|
* ```js
|
|
99
75
|
* {
|
|
@@ -106,7 +82,7 @@ export interface RetrieveEvent {
|
|
|
106
82
|
* }
|
|
107
83
|
* }
|
|
108
84
|
* ```
|
|
109
|
-
* This will match the
|
|
85
|
+
* This will match the vector with metadata:
|
|
110
86
|
* ```js
|
|
111
87
|
* {
|
|
112
88
|
* type: "movie",
|
|
@@ -115,7 +91,7 @@ export interface RetrieveEvent {
|
|
|
115
91
|
* }
|
|
116
92
|
* ```
|
|
117
93
|
*
|
|
118
|
-
* But not the
|
|
94
|
+
* But not the vector with metadata:
|
|
119
95
|
* ```js
|
|
120
96
|
* {
|
|
121
97
|
* type: "book",
|
|
@@ -126,11 +102,11 @@ export interface RetrieveEvent {
|
|
|
126
102
|
*/
|
|
127
103
|
exclude?: Record<string, any>;
|
|
128
104
|
/**
|
|
129
|
-
* The threshold of similarity between the prompt and the
|
|
130
|
-
* Only
|
|
105
|
+
* The threshold of similarity between the prompt and the queried vectors.
|
|
106
|
+
* Only vectors with a similarity score higher than the threshold will be returned.
|
|
131
107
|
* Expected value is between 0 and 1.
|
|
132
|
-
* - 0 means the prompt and the
|
|
133
|
-
* - 1 means the prompt and the
|
|
108
|
+
* - 0 means the prompt and the queried vectors are completely different.
|
|
109
|
+
* - 1 means the prompt and the queried vectors are identical.
|
|
134
110
|
* @default `0`
|
|
135
111
|
* @example
|
|
136
112
|
* ```js
|
|
@@ -154,10 +130,10 @@ export interface RetrieveEvent {
|
|
|
154
130
|
}
|
|
155
131
|
export interface RemoveEvent {
|
|
156
132
|
/**
|
|
157
|
-
* The metadata used to filter the removal of
|
|
158
|
-
* Only
|
|
133
|
+
* The metadata used to filter the removal of vectors.
|
|
134
|
+
* Only vectors with metadata that match the provided fields will be removed.
|
|
159
135
|
* @example
|
|
160
|
-
* To remove
|
|
136
|
+
* To remove vectors for movie with id "movie-123":
|
|
161
137
|
* ```js
|
|
162
138
|
* {
|
|
163
139
|
* include: {
|
|
@@ -165,7 +141,7 @@ export interface RemoveEvent {
|
|
|
165
141
|
* }
|
|
166
142
|
* }
|
|
167
143
|
* ```
|
|
168
|
-
* To remove
|
|
144
|
+
* To remove vectors for all movies:
|
|
169
145
|
* ```js
|
|
170
146
|
* {
|
|
171
147
|
* include: {
|
|
@@ -176,19 +152,19 @@ export interface RemoveEvent {
|
|
|
176
152
|
*/
|
|
177
153
|
include: Record<string, any>;
|
|
178
154
|
}
|
|
179
|
-
export interface
|
|
155
|
+
export interface QueryResponse {
|
|
180
156
|
/**
|
|
181
|
-
* Metadata for the event in JSON format that was provided when
|
|
157
|
+
* Metadata for the event in JSON format that was provided when storing the vector.
|
|
182
158
|
*/
|
|
183
159
|
metadata: Record<string, any>;
|
|
184
160
|
/**
|
|
185
|
-
* The similarity score between the prompt and the
|
|
161
|
+
* The similarity score between the prompt and the queried vector.
|
|
186
162
|
*/
|
|
187
163
|
score: number;
|
|
188
164
|
}
|
|
189
165
|
export interface VectorClientResponse {
|
|
190
|
-
|
|
191
|
-
|
|
166
|
+
put: (event: PutEvent) => Promise<void>;
|
|
167
|
+
query: (event: QueryEvent) => Promise<QueryResponse>;
|
|
192
168
|
remove: (event: RemoveEvent) => Promise<void>;
|
|
193
169
|
}
|
|
194
170
|
/**
|
|
@@ -198,15 +174,15 @@ export interface VectorClientResponse {
|
|
|
198
174
|
* import { VectorClient } from "sst";
|
|
199
175
|
* const client = VectorClient("MyVectorDB");
|
|
200
176
|
*
|
|
201
|
-
* //
|
|
202
|
-
* await client.
|
|
203
|
-
*
|
|
177
|
+
* // Store a vector into the db
|
|
178
|
+
* await client.put({
|
|
179
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
204
180
|
* metadata: { type: "movie", genre: "comedy" },
|
|
205
181
|
* });
|
|
206
182
|
*
|
|
207
|
-
* //
|
|
208
|
-
* const result = await client.
|
|
209
|
-
*
|
|
183
|
+
* // Query vectors similar to the provided vector
|
|
184
|
+
* const result = await client.query({
|
|
185
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
210
186
|
* include: { type: "movie" },
|
|
211
187
|
* exclude: { genre: "thriller" },
|
|
212
188
|
* });
|
package/dist/vector/index.js
CHANGED
|
@@ -8,15 +8,15 @@ const lambda = new LambdaClient();
|
|
|
8
8
|
* import { VectorClient } from "sst";
|
|
9
9
|
* const client = VectorClient("MyVectorDB");
|
|
10
10
|
*
|
|
11
|
-
* //
|
|
12
|
-
* await client.
|
|
13
|
-
*
|
|
11
|
+
* // Store a vector into the db
|
|
12
|
+
* await client.put({
|
|
13
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
14
14
|
* metadata: { type: "movie", genre: "comedy" },
|
|
15
15
|
* });
|
|
16
16
|
*
|
|
17
|
-
* //
|
|
18
|
-
* const result = await client.
|
|
19
|
-
*
|
|
17
|
+
* // Query vectors similar to the provided vector
|
|
18
|
+
* const result = await client.query({
|
|
19
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
20
20
|
* include: { type: "movie" },
|
|
21
21
|
* exclude: { genre: "thriller" },
|
|
22
22
|
* });
|
|
@@ -24,26 +24,26 @@ const lambda = new LambdaClient();
|
|
|
24
24
|
*/
|
|
25
25
|
export function VectorClient(name) {
|
|
26
26
|
return {
|
|
27
|
-
|
|
27
|
+
put: async (event) => {
|
|
28
28
|
const ret = await lambda.send(new InvokeCommand({
|
|
29
29
|
// @ts-expect-error
|
|
30
|
-
FunctionName: Resource[name].
|
|
30
|
+
FunctionName: Resource[name].putFunction,
|
|
31
31
|
Payload: JSON.stringify(event),
|
|
32
32
|
}));
|
|
33
|
-
parsePayload(ret, "Failed to
|
|
33
|
+
parsePayload(ret, "Failed to store into the vector db");
|
|
34
34
|
},
|
|
35
|
-
|
|
35
|
+
query: async (event) => {
|
|
36
36
|
const ret = await lambda.send(new InvokeCommand({
|
|
37
37
|
// @ts-expect-error
|
|
38
|
-
FunctionName: Resource[name].
|
|
38
|
+
FunctionName: Resource[name].queryFunction,
|
|
39
39
|
Payload: JSON.stringify(event),
|
|
40
40
|
}));
|
|
41
|
-
return parsePayload(ret, "Failed to
|
|
41
|
+
return parsePayload(ret, "Failed to query the vector db");
|
|
42
42
|
},
|
|
43
43
|
remove: async (event) => {
|
|
44
44
|
const ret = await lambda.send(new InvokeCommand({
|
|
45
45
|
// @ts-expect-error
|
|
46
|
-
FunctionName: Resource[name].
|
|
46
|
+
FunctionName: Resource[name].removeFunction,
|
|
47
47
|
Payload: JSON.stringify(event),
|
|
48
48
|
}));
|
|
49
49
|
parsePayload(ret, "Failed to remove from the vector db");
|
package/package.json
CHANGED
|
@@ -3,26 +3,28 @@
|
|
|
3
3
|
"name": "sst",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
|
-
"version": "3.0.
|
|
6
|
+
"version": "3.0.17",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./dist/index.js",
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
]
|
|
10
|
+
"./auth": "./dist/auth/index.js",
|
|
11
|
+
"./auth/adapter": "./dist/auth/index.js",
|
|
12
|
+
"./*": "./dist/*.js"
|
|
14
13
|
},
|
|
15
14
|
"devDependencies": {
|
|
16
15
|
"@tsconfig/node18": "^18.2.2",
|
|
17
16
|
"@types/node": "^20.11.0",
|
|
18
|
-
"typescript": "^5.3.3"
|
|
17
|
+
"typescript": "^5.3.3",
|
|
18
|
+
"hono": "4.3.9"
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"hono": "4.x"
|
|
25
|
+
},
|
|
23
26
|
"dependencies": {
|
|
24
27
|
"@aws-sdk/client-lambda": "3.478.0",
|
|
25
|
-
"hono": "4.0.1",
|
|
26
28
|
"jose": "5.2.3",
|
|
27
29
|
"openid-client": "5.6.4"
|
|
28
30
|
},
|