@abhishek944/pi-embeddings 0.1.0 → 0.2.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.
- package/README.md +18 -8
- package/dist/execute.js +36 -1
- package/dist/extension.js +6 -37
- package/dist/index.d.ts +1 -1
- package/dist/mcp-server.js +1 -14
- package/dist/providers.d.ts +9 -2
- package/dist/providers.js +153 -3
- package/dist/response.d.ts +6 -0
- package/dist/response.js +43 -0
- package/dist/runtime.d.ts +22 -2
- package/dist/runtime.js +12 -3
- package/dist/schemas.d.ts +408 -81
- package/dist/schemas.js +46 -16
- package/dist/settings.js +3 -1
- package/dist/tool-contracts.d.ts +327 -184
- package/dist/tool-contracts.js +2 -11
- package/package.json +1 -1
- package/src/execute.ts +40 -1
- package/src/extension.ts +10 -45
- package/src/index.ts +1 -2
- package/src/mcp-server.ts +0 -19
- package/src/providers.ts +185 -3
- package/src/response.ts +51 -0
- package/src/runtime.ts +44 -6
- package/src/schemas.ts +68 -26
- package/src/settings.ts +4 -0
- package/src/tool-contracts.ts +1 -13
package/src/schemas.ts
CHANGED
|
@@ -8,13 +8,20 @@
|
|
|
8
8
|
import { Type, type Static } from 'typebox';
|
|
9
9
|
|
|
10
10
|
export const EMBEDDINGS_SETTINGS_KEY = 'pi-embeddings';
|
|
11
|
-
export const EMBEDDINGS_PROTOCOL_VERSION =
|
|
11
|
+
export const EMBEDDINGS_PROTOCOL_VERSION = 2;
|
|
12
12
|
export const EMBEDDING_FORMAT_VERSION = 'host-display-attributes-v1';
|
|
13
13
|
export const EMBEDDING_DOCUMENT_PREFIX = 'title: none | text: ';
|
|
14
14
|
export const EMBEDDING_NORMALIZATION_VERSION = 'finite-nonzero-l2-v1';
|
|
15
15
|
export const EMBEDDING_CONTEXT_META_KEY = 'pi-embeddings/context';
|
|
16
16
|
|
|
17
|
-
export const EMBEDDING_ROUTE_IDS = [
|
|
17
|
+
export const EMBEDDING_ROUTE_IDS = [
|
|
18
|
+
'local',
|
|
19
|
+
'openai',
|
|
20
|
+
'sarvam',
|
|
21
|
+
'gateway',
|
|
22
|
+
'openrouter',
|
|
23
|
+
'cloudflare',
|
|
24
|
+
] as const;
|
|
18
25
|
export type EmbeddingRouteId = (typeof EMBEDDING_ROUTE_IDS)[number];
|
|
19
26
|
|
|
20
27
|
export const GATEWAY_EMBEDDING_MODELS = [
|
|
@@ -22,11 +29,17 @@ export const GATEWAY_EMBEDDING_MODELS = [
|
|
|
22
29
|
'openai/text-embedding-3-small',
|
|
23
30
|
] as const;
|
|
24
31
|
|
|
32
|
+
export const OPENROUTER_EMBEDDING_MODELS = ['openai/text-embedding-3-small'] as const;
|
|
33
|
+
export const CLOUDFLARE_EMBEDDING_MODELS = ['@cf/baai/bge-base-en-v1.5'] as const;
|
|
34
|
+
|
|
25
35
|
const gatewayModelSchema = Type.Union([
|
|
26
36
|
Type.Literal('text-embedding-3-small'),
|
|
27
37
|
Type.Literal('openai/text-embedding-3-small'),
|
|
28
38
|
]);
|
|
29
39
|
|
|
40
|
+
const openRouterModelSchema = Type.Literal('openai/text-embedding-3-small');
|
|
41
|
+
const cloudflareModelSchema = Type.Literal('@cf/baai/bge-base-en-v1.5');
|
|
42
|
+
|
|
30
43
|
const embeddingErrorCodeSchema = Type.Union([
|
|
31
44
|
Type.Literal('configuration-invalid'),
|
|
32
45
|
Type.Literal('route-unconfigured'),
|
|
@@ -89,6 +102,8 @@ const embeddingProviderSchema = Type.Union([
|
|
|
89
102
|
Type.Literal('openai'),
|
|
90
103
|
Type.Literal('sarvam'),
|
|
91
104
|
Type.Literal('gateway'),
|
|
105
|
+
Type.Literal('openrouter'),
|
|
106
|
+
Type.Literal('cloudflare'),
|
|
92
107
|
]);
|
|
93
108
|
|
|
94
109
|
export const embeddingRouteSchema = Type.Object(
|
|
@@ -146,6 +161,19 @@ export const embeddingSpaceSchema = Type.Union([
|
|
|
146
161
|
},
|
|
147
162
|
{ additionalProperties: false }
|
|
148
163
|
),
|
|
164
|
+
Type.Object(
|
|
165
|
+
{
|
|
166
|
+
...spaceCommon,
|
|
167
|
+
provider: Type.Literal('cloudflare'),
|
|
168
|
+
model: cloudflareModelSchema,
|
|
169
|
+
revision: Type.Null(),
|
|
170
|
+
quantization: Type.Null(),
|
|
171
|
+
runtime: Type.Literal('cloudflare-workers-ai'),
|
|
172
|
+
dimensions: Type.Literal(768),
|
|
173
|
+
pooling: Type.Union([Type.Literal('mean'), Type.Literal('cls')]),
|
|
174
|
+
},
|
|
175
|
+
{ additionalProperties: false }
|
|
176
|
+
),
|
|
149
177
|
]);
|
|
150
178
|
|
|
151
179
|
export const embeddingSettingsSchema = Type.Object(
|
|
@@ -190,6 +218,26 @@ export const embeddingSettingsSchema = Type.Object(
|
|
|
190
218
|
{ additionalProperties: false }
|
|
191
219
|
)
|
|
192
220
|
),
|
|
221
|
+
openrouter: Type.Optional(
|
|
222
|
+
Type.Object(
|
|
223
|
+
{ apiKey: Type.Optional(Type.String({ minLength: 1 })) },
|
|
224
|
+
{ additionalProperties: false }
|
|
225
|
+
)
|
|
226
|
+
),
|
|
227
|
+
cloudflare: Type.Optional(
|
|
228
|
+
Type.Object(
|
|
229
|
+
{
|
|
230
|
+
accountId: Type.Optional(Type.String({ minLength: 1 })),
|
|
231
|
+
apiKey: Type.Optional(Type.String({ minLength: 1 })),
|
|
232
|
+
gatewayId: Type.Optional(Type.String({ minLength: 1 })),
|
|
233
|
+
model: Type.Optional(cloudflareModelSchema),
|
|
234
|
+
pooling: Type.Optional(
|
|
235
|
+
Type.Union([Type.Literal('mean'), Type.Literal('cls')])
|
|
236
|
+
),
|
|
237
|
+
},
|
|
238
|
+
{ additionalProperties: false }
|
|
239
|
+
)
|
|
240
|
+
),
|
|
193
241
|
},
|
|
194
242
|
{ additionalProperties: false }
|
|
195
243
|
)
|
|
@@ -262,9 +310,26 @@ const errorOutcomeSchema = Type.Object(
|
|
|
262
310
|
|
|
263
311
|
export const embeddingOutcomeSchema = Type.Union([successOutcomeSchema, errorOutcomeSchema]);
|
|
264
312
|
|
|
313
|
+
/**
|
|
314
|
+
* Actual generating identity observed on successful outcomes. `generations` is the complete set;
|
|
315
|
+
* the singular fields are populated only when every successful vector came from one generation.
|
|
316
|
+
*/
|
|
317
|
+
export const embeddingGenerationSchema = Type.Object(
|
|
318
|
+
{
|
|
319
|
+
provider: embeddingProviderSchema,
|
|
320
|
+
model: Type.String({ minLength: 1 }),
|
|
321
|
+
space: embeddingSpaceSchema,
|
|
322
|
+
},
|
|
323
|
+
{ additionalProperties: false }
|
|
324
|
+
);
|
|
325
|
+
|
|
265
326
|
export const embeddingResultSchema = Type.Object(
|
|
266
327
|
{
|
|
267
328
|
schemaVersion: Type.Literal(EMBEDDINGS_PROTOCOL_VERSION),
|
|
329
|
+
provider: Type.Union([embeddingProviderSchema, Type.Null()]),
|
|
330
|
+
model: Type.Union([Type.String({ minLength: 1 }), Type.Null()]),
|
|
331
|
+
space: Type.Union([embeddingSpaceSchema, Type.Null()]),
|
|
332
|
+
generations: Type.Array(embeddingGenerationSchema),
|
|
268
333
|
outcomes: Type.Array(embeddingOutcomeSchema),
|
|
269
334
|
attempts: Type.Array(embeddingAttemptSchema),
|
|
270
335
|
},
|
|
@@ -289,28 +354,6 @@ export const embeddingCompareResultSchema = Type.Object(
|
|
|
289
354
|
{ additionalProperties: false }
|
|
290
355
|
);
|
|
291
356
|
|
|
292
|
-
export const embeddingDiagnosticSchema = Type.Object(
|
|
293
|
-
{
|
|
294
|
-
code: Type.String({ minLength: 1 }),
|
|
295
|
-
severity: Type.Union([Type.Literal('error'), Type.Literal('warning'), Type.Literal('info')]),
|
|
296
|
-
},
|
|
297
|
-
{ additionalProperties: false }
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
export const embeddingDescribeSchema = Type.Object(
|
|
301
|
-
{
|
|
302
|
-
schemaVersion: Type.Literal(EMBEDDINGS_PROTOCOL_VERSION),
|
|
303
|
-
ready: Type.Boolean(),
|
|
304
|
-
selected: embeddingRouteSchema,
|
|
305
|
-
space: Type.Union([embeddingSpaceSchema, Type.Null()]),
|
|
306
|
-
default: embeddingRouteSchema,
|
|
307
|
-
fallback: Type.Array(embeddingRouteSchema),
|
|
308
|
-
compare: Type.Array(embeddingRouteSchema),
|
|
309
|
-
diagnostics: Type.Array(embeddingDiagnosticSchema),
|
|
310
|
-
},
|
|
311
|
-
{ additionalProperties: false }
|
|
312
|
-
);
|
|
313
|
-
|
|
314
357
|
export type EmbeddingSettings = Static<typeof embeddingSettingsSchema>;
|
|
315
358
|
export type EmbeddingRoute = Static<typeof embeddingRouteSchema>;
|
|
316
359
|
export type EmbeddingSpace = Static<typeof embeddingSpaceSchema>;
|
|
@@ -319,8 +362,7 @@ export type EmbeddingContext = Static<typeof embeddingContextSchema>;
|
|
|
319
362
|
export type EmbeddingUsage = Static<typeof embeddingUsageSchema>;
|
|
320
363
|
export type EmbeddingAttempt = Static<typeof embeddingAttemptSchema>;
|
|
321
364
|
export type EmbeddingOutcome = Static<typeof embeddingOutcomeSchema>;
|
|
365
|
+
export type EmbeddingGeneration = Static<typeof embeddingGenerationSchema>;
|
|
322
366
|
export type EmbeddingResult = Static<typeof embeddingResultSchema>;
|
|
323
367
|
export type EmbeddingCompareEntry = Static<typeof embeddingCompareEntrySchema>;
|
|
324
368
|
export type EmbeddingCompareResult = Static<typeof embeddingCompareResultSchema>;
|
|
325
|
-
export type EmbeddingDiagnostic = Static<typeof embeddingDiagnosticSchema>;
|
|
326
|
-
export type EmbeddingDescribe = Static<typeof embeddingDescribeSchema>;
|
package/src/settings.ts
CHANGED
|
@@ -5,8 +5,10 @@ import { loadPiSettings, resolveConfigDir } from '@amaster.ai/pi-shared/settings
|
|
|
5
5
|
import { Value } from 'typebox/value';
|
|
6
6
|
import { EmbeddingsError } from './errors.js';
|
|
7
7
|
import {
|
|
8
|
+
CLOUDFLARE_EMBEDDING_MODELS,
|
|
8
9
|
EMBEDDINGS_SETTINGS_KEY,
|
|
9
10
|
GATEWAY_EMBEDDING_MODELS,
|
|
11
|
+
OPENROUTER_EMBEDDING_MODELS,
|
|
10
12
|
embeddingSettingsSchema,
|
|
11
13
|
type EmbeddingRoute,
|
|
12
14
|
type EmbeddingSettings,
|
|
@@ -17,6 +19,8 @@ const MODELS_BY_PROVIDER: Readonly<Record<EmbeddingRoute['provider'], readonly s
|
|
|
17
19
|
openai: ['text-embedding-3-small'],
|
|
18
20
|
sarvam: ['embeddinggemma-2'],
|
|
19
21
|
gateway: GATEWAY_EMBEDDING_MODELS,
|
|
22
|
+
openrouter: OPENROUTER_EMBEDDING_MODELS,
|
|
23
|
+
cloudflare: CLOUDFLARE_EMBEDDING_MODELS,
|
|
20
24
|
};
|
|
21
25
|
|
|
22
26
|
export const isEmbeddingSettings = (value: unknown): value is EmbeddingSettings =>
|
package/src/tool-contracts.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { Type } from 'typebox';
|
|
2
1
|
import {
|
|
3
|
-
embeddingDescribeSchema,
|
|
4
2
|
embeddingCompareResultSchema,
|
|
5
3
|
embeddingRequestSchema,
|
|
6
4
|
embeddingResultSchema,
|
|
@@ -8,7 +6,6 @@ import {
|
|
|
8
6
|
|
|
9
7
|
export const EMBED_TOOL = 'embed';
|
|
10
8
|
export const EMBED_COMPARE_TOOL = 'embed_compare';
|
|
11
|
-
export const EMBEDDINGS_DESCRIBE_TOOL = 'embeddings_describe';
|
|
12
9
|
|
|
13
10
|
export const EMBED_TOOL_DESCRIPTION =
|
|
14
11
|
'Embed one or more text inputs with the server-configured embedding route. Provider, model, fallback routes and credentials stay in trusted settings; this tool cannot override them. Returns vectors and their actual generating space as structured data. Full text is preserved; the package owns prefixing and provider batching. Use embed_compare only for an explicit comparison.';
|
|
@@ -16,19 +13,10 @@ export const EMBED_TOOL_DESCRIPTION =
|
|
|
16
13
|
export const EMBED_COMPARE_TOOL_DESCRIPTION =
|
|
17
14
|
'Explicitly compare the same text inputs using exactly the configured compare routes. Every entry is a separate request and may incur charges. No implicit default, fallback, ranking or settings mutation.';
|
|
18
15
|
|
|
19
|
-
export const EMBEDDINGS_DESCRIBE_TOOL_DESCRIPTION =
|
|
20
|
-
'Report the selected configured embedding route, generating space and provider-free readiness diagnostics without inference or credentials. Information is not a reservation or a caller storage policy.';
|
|
21
|
-
|
|
22
16
|
export const embedParameters = embeddingRequestSchema;
|
|
23
17
|
export const embedCompareParameters = embeddingRequestSchema;
|
|
24
|
-
export const embeddingsDescribeParameters = Type.Object({}, { additionalProperties: false });
|
|
25
18
|
|
|
26
19
|
export const embedOutput = embeddingResultSchema;
|
|
27
20
|
export const embedCompareOutput = embeddingCompareResultSchema;
|
|
28
|
-
export const embeddingsDescribeOutput = embeddingDescribeSchema;
|
|
29
21
|
|
|
30
|
-
export const EMBEDDINGS_TOOL_NAMES = [
|
|
31
|
-
EMBED_TOOL,
|
|
32
|
-
EMBED_COMPARE_TOOL,
|
|
33
|
-
EMBEDDINGS_DESCRIBE_TOOL,
|
|
34
|
-
] as const;
|
|
22
|
+
export const EMBEDDINGS_TOOL_NAMES = [EMBED_TOOL, EMBED_COMPARE_TOOL] as const;
|