@abhishek944/pi-embeddings 0.4.0 → 0.6.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@abhishek944/pi-embeddings",
3
- "version": "0.4.0",
4
- "description": "Config-driven text embeddings for Pi and MCP with local, OpenAI, Sarvam, Gemini, Vertex ADC and gateway routes, ordered fallback and explicit comparisons.",
3
+ "version": "0.6.0",
4
+ "description": "Config-driven text embeddings for Pi and MCP with local, OpenAI, Sarvam, Gemini, Vertex ADC, OpenCode, Voyage, Cohere, Jina, Alibaba DashScope, Hetzner, gateway and OpenRouter routes, ordered fallback and explicit comparisons.",
5
5
  "keywords": [
6
6
  "pi-package",
7
7
  "pi",
@@ -11,7 +11,13 @@
11
11
  "sarvam",
12
12
  "gemini",
13
13
  "embeddinggemma",
14
- "litellm"
14
+ "opencode",
15
+ "litellm",
16
+ "voyage",
17
+ "cohere",
18
+ "jina",
19
+ "dashscope",
20
+ "hetzner"
15
21
  ],
16
22
  "license": "Apache-2.0",
17
23
  "type": "module",
package/src/execute.ts CHANGED
@@ -195,6 +195,7 @@ export async function executeEmbeddings(args: ExecuteArgs): Promise<EmbeddingRes
195
195
  attempt.usage = result.usage;
196
196
  if (result.vectors.length !== captured.length)
197
197
  throw new EmbeddingsError('provider-response-mismatch');
198
+ const actualSpace = result.space ?? provider.space;
198
199
  for (const [offset, entry] of captured.entries()) {
199
200
  const vector = result.vectors[offset];
200
201
  if (vector === undefined) throw new EmbeddingsError('provider-response-mismatch');
@@ -204,7 +205,7 @@ export async function executeEmbeddings(args: ExecuteArgs): Promise<EmbeddingRes
204
205
  vector: [...vector],
205
206
  route: route.provider,
206
207
  model: provider.model,
207
- space: provider.space,
208
+ space: actualSpace,
208
209
  attemptId,
209
210
  normalization: EMBEDDING_NORMALIZATION_VERSION,
210
211
  };
package/src/extension.ts CHANGED
@@ -5,6 +5,8 @@ import {
5
5
  type ExtensionContext,
6
6
  } from '@earendil-works/pi-coding-agent';
7
7
  import { EmbeddingsError } from './errors.js';
8
+ import type { EmbeddingCredentialResolver } from './provider-types.js';
9
+ import type { OpenCodeCredentialAvailability } from './providers.js';
8
10
  import {
9
11
  createEmbeddingsRuntimeWithDiagnostics,
10
12
  type EmbeddingsRuntimeWithDiagnostics,
@@ -41,16 +43,44 @@ const codeOf = (error: unknown): string =>
41
43
  const signalOptions = (signal: AbortSignal | undefined) =>
42
44
  signal === undefined ? {} : { signal };
43
45
 
46
+ type PiCredentials = Readonly<{
47
+ readonly resolver: EmbeddingCredentialResolver;
48
+ readonly available: OpenCodeCredentialAvailability;
49
+ }>;
50
+
51
+ /** Pi exposes provider keys through ModelRegistry; only nonsecret availability is retained. */
52
+ async function piCredentials(ctx: ExtensionContext): Promise<PiCredentials> {
53
+ const opencode = (await ctx.modelRegistry.getApiKeyForProvider('opencode')) !== undefined;
54
+ const go = (await ctx.modelRegistry.getApiKeyForProvider('opencode-go')) !== undefined;
55
+ return {
56
+ available: { opencode, 'opencode-go': go },
57
+ resolver: async (provider) => {
58
+ if (provider === 'opencode' || provider === 'opencode-go')
59
+ return ctx.modelRegistry.getApiKeyForProvider(provider);
60
+ return undefined;
61
+ },
62
+ };
63
+ }
64
+
44
65
  export default function piEmbeddingsExtension(pi: ExtensionAPI): void {
45
66
  let settings: EmbeddingSettings | undefined;
46
67
  let runtime: EmbeddingsRuntimeWithDiagnostics | undefined;
47
68
  let cwd = process.cwd();
48
69
 
49
- const refresh = async (next: EmbeddingSettings, nextCwd = cwd): Promise<void> => {
70
+ const refresh = async (
71
+ next: EmbeddingSettings,
72
+ nextCwd: string,
73
+ credentials: PiCredentials
74
+ ): Promise<void> => {
50
75
  await runtime?.close();
51
76
  settings = next;
52
77
  cwd = nextCwd;
53
- runtime = createEmbeddingsRuntimeWithDiagnostics({ settings: next, cwd: nextCwd });
78
+ runtime = createEmbeddingsRuntimeWithDiagnostics({
79
+ settings: next,
80
+ cwd: nextCwd,
81
+ credentialResolver: credentials.resolver,
82
+ piCredentialAvailable: credentials.available,
83
+ });
54
84
  };
55
85
 
56
86
  const currentRuntime = (ctx: ExtensionContext): EmbeddingsRuntimeWithDiagnostics => {
@@ -60,7 +90,11 @@ export default function piEmbeddingsExtension(pi: ExtensionAPI): void {
60
90
  };
61
91
 
62
92
  pi.on('session_start', async (_event: unknown, ctx: ExtensionContext) => {
63
- await refresh(loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx)), ctx.cwd);
93
+ await refresh(
94
+ loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx)),
95
+ ctx.cwd,
96
+ await piCredentials(ctx)
97
+ );
64
98
  });
65
99
 
66
100
  pi.on('session_shutdown', async () => {
@@ -172,7 +206,7 @@ export default function piEmbeddingsExtension(pi: ExtensionAPI): void {
172
206
  if (command === 'reload') {
173
207
  if (parts.length !== 1) throw new EmbeddingsError('configuration-invalid');
174
208
  const next = loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx));
175
- await refresh(next, ctx.cwd);
209
+ await refresh(next, ctx.cwd, await piCredentials(ctx));
176
210
  reply(pi, ctx, `${EMBEDDINGS_SETTINGS_KEY} settings reloaded. No inference was run.`);
177
211
  return;
178
212
  }
@@ -185,7 +219,11 @@ export default function piEmbeddingsExtension(pi: ExtensionAPI): void {
185
219
  projectTrusted: isProjectTrusted(ctx),
186
220
  route,
187
221
  });
188
- await refresh(loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx)), ctx.cwd);
222
+ await refresh(
223
+ loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx)),
224
+ ctx.cwd,
225
+ await piCredentials(ctx)
226
+ );
189
227
  reply(pi, ctx, `Selected ${route.provider}/${route.model} in trusted project settings.`);
190
228
  return;
191
229
  }
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export {
7
7
  isEmbeddingSettings,
8
8
  } from './settings.js';
9
9
  export { EmbeddingsError } from './errors.js';
10
+ export type { EmbeddingCredentialResolver } from './provider-types.js';
10
11
  export {
11
12
  EMBEDDINGS_SETTINGS_KEY,
12
13
  EMBEDDINGS_PROTOCOL_VERSION,
@@ -15,9 +16,27 @@ export {
15
16
  EMBEDDING_NORMALIZATION_VERSION,
16
17
  EMBEDDING_CONTEXT_META_KEY,
17
18
  EMBEDDING_ROUTE_IDS,
19
+ OPENAI_EMBEDDING_MODELS,
20
+ OPENAI_EMBEDDING_DIMENSIONS,
18
21
  GATEWAY_EMBEDDING_MODELS,
19
22
  GEMINI_EMBEDDING_MODELS,
20
23
  VERTEX_EMBEDDING_LOCATIONS,
24
+ OPENCODE_EMBEDDING_MODELS,
25
+ OPENCODE_GO_EMBEDDING_MODELS,
26
+ OPENROUTER_EMBEDDING_MODELS,
27
+ VOYAGE_EMBEDDING_MODELS,
28
+ VOYAGE_EMBEDDING_DIMENSIONS,
29
+ VOYAGE_INPUT_TYPES,
30
+ COHERE_EMBEDDING_MODELS,
31
+ COHERE_EMBEDDING_DIMENSIONS,
32
+ COHERE_INPUT_TYPES,
33
+ JINA_EMBEDDING_MODELS,
34
+ JINA_EMBEDDING_DIMENSIONS,
35
+ JINA_EMBEDDING_TASKS,
36
+ DASHSCOPE_EMBEDDING_MODELS,
37
+ DASHSCOPE_EMBEDDING_DIMENSIONS,
38
+ HETZNER_EMBEDDING_MODELS,
39
+ HETZNER_EMBEDDING_DIMENSIONS,
21
40
  GEMINI_EMBEDDING_MIN_DIMENSIONS,
22
41
  GEMINI_EMBEDDING_MAX_DIMENSIONS,
23
42
  GEMINI_EMBEDDING_TASK_FORMATS,
@@ -43,4 +62,20 @@ export type {
43
62
  EmbeddingErrorCode,
44
63
  GeminiEmbeddingDimension,
45
64
  GeminiEmbeddingTaskFormat,
65
+ OpenAiEmbeddingModel,
66
+ OpenRouterEmbeddingModel,
67
+ VoyageEmbeddingModel,
68
+ VoyageEmbeddingDimension,
69
+ VoyageInputType,
70
+ CohereEmbeddingModel,
71
+ CohereEmbeddingDimension,
72
+ CohereInputType,
73
+ JinaEmbeddingModel,
74
+ JinaEmbeddingTask,
75
+ DashScopeEmbeddingModel,
76
+ DashScopeEmbeddingDimension,
77
+ HetznerEmbeddingModel,
78
+ OpenCodeRouteId,
79
+ OpenCodeEmbeddingModel,
80
+ OpenCodeGoEmbeddingModel,
46
81
  } from './schemas.js';
@@ -14,8 +14,15 @@ export type ProviderUsage = Readonly<{
14
14
  export type ProviderBatchResult = Readonly<{
15
15
  readonly vectors: readonly (readonly number[])[];
16
16
  readonly usage: ProviderUsage;
17
+ /** Set only when the response establishes a more specific space than the preflight descriptor. */
18
+ readonly space?: EmbeddingSpace | undefined;
17
19
  }>;
18
20
 
21
+ /** Supplied by hosts with a supported provider-key lookup; never invoked with a secret value. */
22
+ export type EmbeddingCredentialResolver = (
23
+ provider: EmbeddingRouteId
24
+ ) => Promise<string | undefined>;
25
+
19
26
  export interface EmbeddingsProvider {
20
27
  readonly route: EmbeddingRouteId;
21
28
  readonly model: string;