@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/dist/schemas.js
CHANGED
|
@@ -7,20 +7,31 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { Type } from 'typebox';
|
|
9
9
|
export const EMBEDDINGS_SETTINGS_KEY = 'pi-embeddings';
|
|
10
|
-
export const EMBEDDINGS_PROTOCOL_VERSION =
|
|
10
|
+
export const EMBEDDINGS_PROTOCOL_VERSION = 2;
|
|
11
11
|
export const EMBEDDING_FORMAT_VERSION = 'host-display-attributes-v1';
|
|
12
12
|
export const EMBEDDING_DOCUMENT_PREFIX = 'title: none | text: ';
|
|
13
13
|
export const EMBEDDING_NORMALIZATION_VERSION = 'finite-nonzero-l2-v1';
|
|
14
14
|
export const EMBEDDING_CONTEXT_META_KEY = 'pi-embeddings/context';
|
|
15
|
-
export const EMBEDDING_ROUTE_IDS = [
|
|
15
|
+
export const EMBEDDING_ROUTE_IDS = [
|
|
16
|
+
'local',
|
|
17
|
+
'openai',
|
|
18
|
+
'sarvam',
|
|
19
|
+
'gateway',
|
|
20
|
+
'openrouter',
|
|
21
|
+
'cloudflare',
|
|
22
|
+
];
|
|
16
23
|
export const GATEWAY_EMBEDDING_MODELS = [
|
|
17
24
|
'text-embedding-3-small',
|
|
18
25
|
'openai/text-embedding-3-small',
|
|
19
26
|
];
|
|
27
|
+
export const OPENROUTER_EMBEDDING_MODELS = ['openai/text-embedding-3-small'];
|
|
28
|
+
export const CLOUDFLARE_EMBEDDING_MODELS = ['@cf/baai/bge-base-en-v1.5'];
|
|
20
29
|
const gatewayModelSchema = Type.Union([
|
|
21
30
|
Type.Literal('text-embedding-3-small'),
|
|
22
31
|
Type.Literal('openai/text-embedding-3-small'),
|
|
23
32
|
]);
|
|
33
|
+
const openRouterModelSchema = Type.Literal('openai/text-embedding-3-small');
|
|
34
|
+
const cloudflareModelSchema = Type.Literal('@cf/baai/bge-base-en-v1.5');
|
|
24
35
|
const embeddingErrorCodeSchema = Type.Union([
|
|
25
36
|
Type.Literal('configuration-invalid'),
|
|
26
37
|
Type.Literal('route-unconfigured'),
|
|
@@ -80,6 +91,8 @@ const embeddingProviderSchema = Type.Union([
|
|
|
80
91
|
Type.Literal('openai'),
|
|
81
92
|
Type.Literal('sarvam'),
|
|
82
93
|
Type.Literal('gateway'),
|
|
94
|
+
Type.Literal('openrouter'),
|
|
95
|
+
Type.Literal('cloudflare'),
|
|
83
96
|
]);
|
|
84
97
|
export const embeddingRouteSchema = Type.Object({
|
|
85
98
|
provider: embeddingProviderSchema,
|
|
@@ -122,6 +135,16 @@ export const embeddingSpaceSchema = Type.Union([
|
|
|
122
135
|
runtime: Type.Literal('sarvam-v2'),
|
|
123
136
|
dimensions: Type.Literal(768),
|
|
124
137
|
}, { additionalProperties: false }),
|
|
138
|
+
Type.Object({
|
|
139
|
+
...spaceCommon,
|
|
140
|
+
provider: Type.Literal('cloudflare'),
|
|
141
|
+
model: cloudflareModelSchema,
|
|
142
|
+
revision: Type.Null(),
|
|
143
|
+
quantization: Type.Null(),
|
|
144
|
+
runtime: Type.Literal('cloudflare-workers-ai'),
|
|
145
|
+
dimensions: Type.Literal(768),
|
|
146
|
+
pooling: Type.Union([Type.Literal('mean'), Type.Literal('cls')]),
|
|
147
|
+
}, { additionalProperties: false }),
|
|
125
148
|
]);
|
|
126
149
|
export const embeddingSettingsSchema = Type.Object({
|
|
127
150
|
version: Type.Optional(Type.Literal(1)),
|
|
@@ -142,6 +165,14 @@ export const embeddingSettingsSchema = Type.Object({
|
|
|
142
165
|
model: gatewayModelSchema,
|
|
143
166
|
stage: Type.Union([Type.Literal('dev'), Type.Literal('prod')]),
|
|
144
167
|
}, { additionalProperties: false })),
|
|
168
|
+
openrouter: Type.Optional(Type.Object({ apiKey: Type.Optional(Type.String({ minLength: 1 })) }, { additionalProperties: false })),
|
|
169
|
+
cloudflare: Type.Optional(Type.Object({
|
|
170
|
+
accountId: Type.Optional(Type.String({ minLength: 1 })),
|
|
171
|
+
apiKey: Type.Optional(Type.String({ minLength: 1 })),
|
|
172
|
+
gatewayId: Type.Optional(Type.String({ minLength: 1 })),
|
|
173
|
+
model: Type.Optional(cloudflareModelSchema),
|
|
174
|
+
pooling: Type.Optional(Type.Union([Type.Literal('mean'), Type.Literal('cls')])),
|
|
175
|
+
}, { additionalProperties: false })),
|
|
145
176
|
}, { additionalProperties: false })),
|
|
146
177
|
}, { additionalProperties: false });
|
|
147
178
|
export const embeddingRequestSchema = Type.Object({
|
|
@@ -183,8 +214,21 @@ const errorOutcomeSchema = Type.Object({
|
|
|
183
214
|
attemptId: Type.Union([Type.String({ minLength: 1 }), Type.Null()]),
|
|
184
215
|
}, { additionalProperties: false });
|
|
185
216
|
export const embeddingOutcomeSchema = Type.Union([successOutcomeSchema, errorOutcomeSchema]);
|
|
217
|
+
/**
|
|
218
|
+
* Actual generating identity observed on successful outcomes. `generations` is the complete set;
|
|
219
|
+
* the singular fields are populated only when every successful vector came from one generation.
|
|
220
|
+
*/
|
|
221
|
+
export const embeddingGenerationSchema = Type.Object({
|
|
222
|
+
provider: embeddingProviderSchema,
|
|
223
|
+
model: Type.String({ minLength: 1 }),
|
|
224
|
+
space: embeddingSpaceSchema,
|
|
225
|
+
}, { additionalProperties: false });
|
|
186
226
|
export const embeddingResultSchema = Type.Object({
|
|
187
227
|
schemaVersion: Type.Literal(EMBEDDINGS_PROTOCOL_VERSION),
|
|
228
|
+
provider: Type.Union([embeddingProviderSchema, Type.Null()]),
|
|
229
|
+
model: Type.Union([Type.String({ minLength: 1 }), Type.Null()]),
|
|
230
|
+
space: Type.Union([embeddingSpaceSchema, Type.Null()]),
|
|
231
|
+
generations: Type.Array(embeddingGenerationSchema),
|
|
188
232
|
outcomes: Type.Array(embeddingOutcomeSchema),
|
|
189
233
|
attempts: Type.Array(embeddingAttemptSchema),
|
|
190
234
|
}, { additionalProperties: false });
|
|
@@ -198,17 +242,3 @@ export const embeddingCompareResultSchema = Type.Object({
|
|
|
198
242
|
schemaVersion: Type.Literal(EMBEDDINGS_PROTOCOL_VERSION),
|
|
199
243
|
entries: Type.Array(embeddingCompareEntrySchema),
|
|
200
244
|
}, { additionalProperties: false });
|
|
201
|
-
export const embeddingDiagnosticSchema = Type.Object({
|
|
202
|
-
code: Type.String({ minLength: 1 }),
|
|
203
|
-
severity: Type.Union([Type.Literal('error'), Type.Literal('warning'), Type.Literal('info')]),
|
|
204
|
-
}, { additionalProperties: false });
|
|
205
|
-
export const embeddingDescribeSchema = Type.Object({
|
|
206
|
-
schemaVersion: Type.Literal(EMBEDDINGS_PROTOCOL_VERSION),
|
|
207
|
-
ready: Type.Boolean(),
|
|
208
|
-
selected: embeddingRouteSchema,
|
|
209
|
-
space: Type.Union([embeddingSpaceSchema, Type.Null()]),
|
|
210
|
-
default: embeddingRouteSchema,
|
|
211
|
-
fallback: Type.Array(embeddingRouteSchema),
|
|
212
|
-
compare: Type.Array(embeddingRouteSchema),
|
|
213
|
-
diagnostics: Type.Array(embeddingDiagnosticSchema),
|
|
214
|
-
}, { additionalProperties: false });
|
package/dist/settings.js
CHANGED
|
@@ -4,12 +4,14 @@ import { join, resolve } from 'node:path';
|
|
|
4
4
|
import { loadPiSettings, resolveConfigDir } from '@amaster.ai/pi-shared/settings';
|
|
5
5
|
import { Value } from 'typebox/value';
|
|
6
6
|
import { EmbeddingsError } from './errors.js';
|
|
7
|
-
import { EMBEDDINGS_SETTINGS_KEY, GATEWAY_EMBEDDING_MODELS, embeddingSettingsSchema, } from './schemas.js';
|
|
7
|
+
import { CLOUDFLARE_EMBEDDING_MODELS, EMBEDDINGS_SETTINGS_KEY, GATEWAY_EMBEDDING_MODELS, OPENROUTER_EMBEDDING_MODELS, embeddingSettingsSchema, } from './schemas.js';
|
|
8
8
|
const MODELS_BY_PROVIDER = {
|
|
9
9
|
local: ['embeddinggemma-2'],
|
|
10
10
|
openai: ['text-embedding-3-small'],
|
|
11
11
|
sarvam: ['embeddinggemma-2'],
|
|
12
12
|
gateway: GATEWAY_EMBEDDING_MODELS,
|
|
13
|
+
openrouter: OPENROUTER_EMBEDDING_MODELS,
|
|
14
|
+
cloudflare: CLOUDFLARE_EMBEDDING_MODELS,
|
|
13
15
|
};
|
|
14
16
|
export const isEmbeddingSettings = (value) => Value.Check(embeddingSettingsSchema, value);
|
|
15
17
|
function configuration(message) {
|