@abhishek944/pi-embeddings 0.4.0 → 0.5.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 +9 -4
- package/dist/execute.js +2 -1
- package/dist/extension.js +23 -5
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/provider-types.d.ts +4 -0
- package/dist/providers.d.ts +13 -4
- package/dist/providers.js +147 -4
- package/dist/response.d.ts +11 -0
- package/dist/response.js +64 -3
- package/dist/runtime.d.ts +6 -1
- package/dist/runtime.js +8 -3
- package/dist/schemas.d.ts +275 -22
- package/dist/schemas.js +65 -0
- package/dist/settings.js +3 -1
- package/dist/tool-contracts.d.ts +129 -9
- package/package.json +3 -2
- package/src/execute.ts +2 -1
- package/src/extension.ts +43 -5
- package/src/index.ts +6 -0
- package/src/provider-types.ts +7 -0
- package/src/providers.ts +200 -2
- package/src/response.ts +73 -3
- package/src/runtime.ts +25 -6
- package/src/schemas.ts +87 -0
- package/src/settings.ts +4 -0
package/README.md
CHANGED
|
@@ -59,13 +59,15 @@ Settings live under the `pi-embeddings` namespace. Pi loading follows global < a
|
|
|
59
59
|
"apiKey": "${GEMINI_API_KEY}",
|
|
60
60
|
"dimensions": 3072,
|
|
61
61
|
"taskFormat": "retrieval-document"
|
|
62
|
-
}
|
|
62
|
+
},
|
|
63
|
+
"opencode": { "apiKey": "${OPENCODE_API_KEY}" },
|
|
64
|
+
"opencode-go": { "apiKey": "${OPENCODE_API_KEY}" }
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
```
|
|
67
69
|
|
|
68
|
-
Provider IDs are route identifiers: `local`, `openai`, `sarvam`, `gateway`, `openrouter`, `cloudflare`, `gemini` and `
|
|
70
|
+
Provider IDs are route identifiers: `local`, `openai`, `sarvam`, `gateway`, `openrouter`, `cloudflare`, `gemini`, `vertex`, `opencode` and `opencode-go`. Only the declared model pairs are valid. Omitted or empty `fallback` and `compare` lists are inactive. No route is activated by a schema annotation, a present key or existing model files. Credentials and identifiers may also come from `OPENROUTER_API_KEY`, `CLOUDFLARE_ACCOUNT_ID`, `CLOUDFLARE_API_TOKEN`, `CLOUDFLARE_AI_GATEWAY_ID`, `GEMINI_API_KEY` and `OPENCODE_API_KEY` in the trusted host environment. An environment fallback works only when the MCP process itself receives that variable; a hosted settings file that is copied without environment forwarding must carry the relevant `providers.<route>.apiKey` directly. In the Pi extension, OpenCode routes can also use the provider key already resolved by Pi through `ModelRegistry.getApiKeyForProvider`; the library and MCP server never read Pi's credential file.
|
|
69
71
|
|
|
70
72
|
### Google Cloud Vertex (keyless ADC)
|
|
71
73
|
|
|
@@ -109,6 +111,9 @@ Ordinary calls use the configured default, then configured fallback in order, ad
|
|
|
109
111
|
- `cloudflare`: `@cf/baai/bge-base-en-v1.5` through Cloudflare's documented REST `POST /ai/run/{model}`. The Cloudflare API token goes in `Authorization`, and the gateway ID goes in `cf-aig-gateway-id` as Workers AI requires. `pooling` defaults to `mean`; `cls` produces a different generating space and is recorded in the result. The REST API wraps the model output in its standard `result` envelope; the parser also accepts the model's raw `{ shape, data, pooling }` form. Cloudflare reports no local token usage, so usage fields are null.
|
|
110
112
|
- `gemini`: `gemini-embedding-2` through the fixed Gemini API `POST /v1beta/models/gemini-embedding-2:embedContent` endpoint with the `x-goog-api-key` header. `dimensions` accepts the documented 128–3072 range (768, 1536 and 3072 are Google's recommended sizes) and defaults to `3072`. `taskFormat` selects the documented Gemini 2 text prefix (`retrieval-document` by default, plus query and single-input formats); the package does not send `task_type`, which applies only to `gemini-embedding-001`. Each exact prepared prompt is counted with the model's `countTokens` endpoint before a single-input `embedContent` request; inputs over the documented 8192-token boundary fail before inference, and the embed response token count must match the preflight count before a vector is accepted. `autoTruncate: false` is deliberately not sent because the official SDK marks it Enterprise/Vertex-only. The exact dimension, task format and prefix are recorded in the generating space.
|
|
111
113
|
|
|
114
|
+
- `opencode`: OpenCode Console pay-as-you-go models through the fixed `POST https://opencode.ai/inference/openai/v1/embeddings` endpoint with bearer authentication. Pi calls this catalog OpenCode Zen. The twelve documented embedding model IDs are `text-embedding-3-small`, `text-embedding-3-large`, `gemini-embedding-2`, `gemini-embedding-001`, `codestral-embed`, `mistral-embed`, `cohere-embed-v5-pro`, `cohere-embed-v5-fast`, `voyage-4`, `voyage-code-4`, `qwen3-embedding-8b` and `bge-m3`. No `dimensions` option is guessed; the response's vector length becomes the observed dimension in the actual generating space. An echoed model that differs from the configured model fails closed.
|
|
115
|
+
- `opencode-go`: OpenCode Go subscription through the fixed `POST https://opencode.ai/inference/go/openai/v1/embeddings` endpoint. The documented models are `text-embedding-3-small`, `qwen3-embedding-8b` and `gemini-embedding-2`. Embeddings do not need the chat `x-opencode-session` header; the adapter identifies itself with a `pi-embeddings` user agent. A missing or non-Go key returns HTTP 401 or 403; 403 entitlement failures do not advance fallback. Both OpenCode routes use explicit `providers.opencode.apiKey` or `providers.opencode-go.apiKey`, Pi's stored provider key in the extension, or `OPENCODE_API_KEY`, in that order.
|
|
116
|
+
|
|
112
117
|
- `vertex`: Google Cloud `gemini-embedding-2` through the fixed Vertex `v1` `embedContent` and `countTokens` resource methods with keyless ADC. Each exact instruction-prefixed text is counted before inference and must fit the documented 8192-token window; `role: user` is consistent in both operations. Dimensions use `embedContentConfig.outputDimensionality`. The model's `task_type` and `autoTruncate` options are not used. A true response `truncated` flag, mismatched prompt count, missing usage, invalid dimensions or invalid vector fails closed; no truncated vector is accepted. Its complete descriptor has `provider: vertex` and `runtime: vertex-ai-v1`, distinct from `gemini` even for identical model names and dimensions.
|
|
113
118
|
|
|
114
119
|
The package supplies the document prefix `title: none | text: ` exactly once and normalizes vectors with the recorded stable L2 identity. It never summarizes, trims, chunks or truncates input text.
|
|
@@ -127,11 +132,11 @@ This is attribution only. The authenticated server-to-server boundary supplies c
|
|
|
127
132
|
|
|
128
133
|
Descriptors record canonical provider, model, known revision or explicit null, quantization/runtime/pooling provenance, dimensions, preparation prefix and normalization identity. Local, Sarvam and Cloudflare remain distinct at 768 dimensions, and Cloudflare `mean` and `cls` are distinct spaces. Gemini and Vertex dimensions and task formats are distinct spaces, including 768-dimensional MRL output; Vertex is never relabeled as the Developer API or vice versa, because the provider, prompt format and normalization provenance differ. Direct OpenAI, the declared gateway alias and the declared OpenRouter alias share the OpenAI descriptor only when the effective text, preparation and normalization remain identical. API keys, service URLs, account IDs and gateway IDs are route metadata, not implicit new spaces. The ordinary embed result carries these descriptors for actual successful work; no separate metadata call is required.
|
|
129
134
|
|
|
130
|
-
Existing stored vector documents are preserved. Package outcome descriptors allow callers to compare complete identity before persistence; a successful inference from an incompatible space is still reported truthfully.
|
|
135
|
+
OpenCode Console and Go are always distinct from direct OpenAI and from each other, even when the model ID is the same: their runtime provenance differs, and bit-for-bit equivalence has not been verified. OpenCode preflight descriptors report `dimensions: null`; a successful outcome records the positive vector length observed in that response. Existing stored vector documents are preserved. Package outcome descriptors allow callers to compare complete identity before persistence; a successful inference from an incompatible space is still reported truthfully.
|
|
131
136
|
|
|
132
137
|
## Limits
|
|
133
138
|
|
|
134
|
-
No application capacity caps are added. Provider request limits above are mandatory documented constraints. Sarvam, local and
|
|
139
|
+
No application capacity caps are added. Provider request limits above are mandatory documented constraints. Sarvam, local, Cloudflare and OpenCode publish no aggregate request cap, so none is invented. OpenCode requires each input to fit the chosen model's context window; the package does not guess a local tokenizer or dimension ceiling for its multi-model catalog, so the service may reject an oversized input. Gemini publishes an 8192-token input boundary and no aggregate request cap; one exact prompt per request is pre-counted with `countTokens`, and a mismatched embed token count fails closed. Cloudflare documents a 512-token per-input ceiling for `bge-base-en-v1.5`; this package does not ship that model's tokenizer and does not approximate the ceiling locally, so Cloudflare may reject an oversized input. No cost estimator or pricing table is included; unknown provider accounting is reported as null. OpenCode's reported `usage.cost` and Go allowance are billing metadata outside the token-usage protocol and remain null in `billedTokens`.
|
|
135
140
|
|
|
136
141
|
Official Vertex contracts: [embedContent](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.publishers.models/embedContent), [countTokens](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.publishers.models/countTokens), [multimodal model constraints and task instructions](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/embeddings/get-multimodal-embeddings), and [ADC discovery order](https://docs.cloud.google.com/docs/authentication/application-default-credentials).
|
|
137
142
|
|
package/dist/execute.js
CHANGED
|
@@ -163,6 +163,7 @@ export async function executeEmbeddings(args) {
|
|
|
163
163
|
attempt.usage = result.usage;
|
|
164
164
|
if (result.vectors.length !== captured.length)
|
|
165
165
|
throw new EmbeddingsError('provider-response-mismatch');
|
|
166
|
+
const actualSpace = result.space ?? provider.space;
|
|
166
167
|
for (const [offset, entry] of captured.entries()) {
|
|
167
168
|
const vector = result.vectors[offset];
|
|
168
169
|
if (vector === undefined)
|
|
@@ -173,7 +174,7 @@ export async function executeEmbeddings(args) {
|
|
|
173
174
|
vector: [...vector],
|
|
174
175
|
route: route.provider,
|
|
175
176
|
model: provider.model,
|
|
176
|
-
space:
|
|
177
|
+
space: actualSpace,
|
|
177
178
|
attemptId,
|
|
178
179
|
normalization: EMBEDDING_NORMALIZATION_VERSION,
|
|
179
180
|
};
|
package/dist/extension.js
CHANGED
|
@@ -13,15 +13,33 @@ const summary = (result) => {
|
|
|
13
13
|
};
|
|
14
14
|
const codeOf = (error) => error instanceof EmbeddingsError ? error.code : 'configuration-invalid';
|
|
15
15
|
const signalOptions = (signal) => signal === undefined ? {} : { signal };
|
|
16
|
+
/** Pi exposes provider keys through ModelRegistry; only nonsecret availability is retained. */
|
|
17
|
+
async function piCredentials(ctx) {
|
|
18
|
+
const opencode = (await ctx.modelRegistry.getApiKeyForProvider('opencode')) !== undefined;
|
|
19
|
+
const go = (await ctx.modelRegistry.getApiKeyForProvider('opencode-go')) !== undefined;
|
|
20
|
+
return {
|
|
21
|
+
available: { opencode, 'opencode-go': go },
|
|
22
|
+
resolver: async (provider) => {
|
|
23
|
+
if (provider === 'opencode' || provider === 'opencode-go')
|
|
24
|
+
return ctx.modelRegistry.getApiKeyForProvider(provider);
|
|
25
|
+
return undefined;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
16
29
|
export default function piEmbeddingsExtension(pi) {
|
|
17
30
|
let settings;
|
|
18
31
|
let runtime;
|
|
19
32
|
let cwd = process.cwd();
|
|
20
|
-
const refresh = async (next, nextCwd
|
|
33
|
+
const refresh = async (next, nextCwd, credentials) => {
|
|
21
34
|
await runtime?.close();
|
|
22
35
|
settings = next;
|
|
23
36
|
cwd = nextCwd;
|
|
24
|
-
runtime = createEmbeddingsRuntimeWithDiagnostics({
|
|
37
|
+
runtime = createEmbeddingsRuntimeWithDiagnostics({
|
|
38
|
+
settings: next,
|
|
39
|
+
cwd: nextCwd,
|
|
40
|
+
credentialResolver: credentials.resolver,
|
|
41
|
+
piCredentialAvailable: credentials.available,
|
|
42
|
+
});
|
|
25
43
|
};
|
|
26
44
|
const currentRuntime = (ctx) => {
|
|
27
45
|
if (runtime === undefined || cwd !== ctx.cwd)
|
|
@@ -29,7 +47,7 @@ export default function piEmbeddingsExtension(pi) {
|
|
|
29
47
|
return runtime;
|
|
30
48
|
};
|
|
31
49
|
pi.on('session_start', async (_event, ctx) => {
|
|
32
|
-
await refresh(loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx)), ctx.cwd);
|
|
50
|
+
await refresh(loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx)), ctx.cwd, await piCredentials(ctx));
|
|
33
51
|
});
|
|
34
52
|
pi.on('session_shutdown', async () => {
|
|
35
53
|
await runtime?.close();
|
|
@@ -122,7 +140,7 @@ export default function piEmbeddingsExtension(pi) {
|
|
|
122
140
|
if (parts.length !== 1)
|
|
123
141
|
throw new EmbeddingsError('configuration-invalid');
|
|
124
142
|
const next = loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx));
|
|
125
|
-
await refresh(next, ctx.cwd);
|
|
143
|
+
await refresh(next, ctx.cwd, await piCredentials(ctx));
|
|
126
144
|
reply(pi, ctx, `${EMBEDDINGS_SETTINGS_KEY} settings reloaded. No inference was run.`);
|
|
127
145
|
return;
|
|
128
146
|
}
|
|
@@ -136,7 +154,7 @@ export default function piEmbeddingsExtension(pi) {
|
|
|
136
154
|
projectTrusted: isProjectTrusted(ctx),
|
|
137
155
|
route,
|
|
138
156
|
});
|
|
139
|
-
await refresh(loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx)), ctx.cwd);
|
|
157
|
+
await refresh(loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx)), ctx.cwd, await piCredentials(ctx));
|
|
140
158
|
reply(pi, ctx, `Selected ${route.provider}/${route.model} in trusted project settings.`);
|
|
141
159
|
return;
|
|
142
160
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { createEmbeddingsRuntime, type EmbeddingsRuntime } from './runtime.js';
|
|
2
2
|
export { loadEmbeddingSettings, validateEmbeddingSettings, configuredDefault, configuredRoutes, isEmbeddingSettings, } from './settings.js';
|
|
3
3
|
export { EmbeddingsError } from './errors.js';
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
4
|
+
export type { EmbeddingCredentialResolver } from './provider-types.js';
|
|
5
|
+
export { EMBEDDINGS_SETTINGS_KEY, EMBEDDINGS_PROTOCOL_VERSION, EMBEDDING_FORMAT_VERSION, EMBEDDING_DOCUMENT_PREFIX, EMBEDDING_NORMALIZATION_VERSION, EMBEDDING_CONTEXT_META_KEY, EMBEDDING_ROUTE_IDS, GATEWAY_EMBEDDING_MODELS, GEMINI_EMBEDDING_MODELS, VERTEX_EMBEDDING_LOCATIONS, OPENCODE_EMBEDDING_MODELS, OPENCODE_GO_EMBEDDING_MODELS, GEMINI_EMBEDDING_MIN_DIMENSIONS, GEMINI_EMBEDDING_MAX_DIMENSIONS, GEMINI_EMBEDDING_TASK_FORMATS, GEMINI_TASK_PREFIXES, DEFAULT_GEMINI_DIMENSIONS, DEFAULT_GEMINI_TASK_FORMAT, EMBEDDING_ERROR_CODES, } from './schemas.js';
|
|
6
|
+
export type { EmbeddingSettings, EmbeddingRoute, EmbeddingRouteId, EmbeddingSpace, EmbeddingRequest, EmbeddingContext, EmbeddingUsage, EmbeddingAttempt, EmbeddingOutcome, EmbeddingGeneration, EmbeddingResult, EmbeddingCompareEntry, EmbeddingCompareResult, EmbeddingErrorCode, GeminiEmbeddingDimension, GeminiEmbeddingTaskFormat, OpenCodeRouteId, OpenCodeEmbeddingModel, OpenCodeGoEmbeddingModel, } from './schemas.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { createEmbeddingsRuntime } from './runtime.js';
|
|
2
2
|
export { loadEmbeddingSettings, validateEmbeddingSettings, configuredDefault, configuredRoutes, isEmbeddingSettings, } from './settings.js';
|
|
3
3
|
export { EmbeddingsError } from './errors.js';
|
|
4
|
-
export { EMBEDDINGS_SETTINGS_KEY, EMBEDDINGS_PROTOCOL_VERSION, EMBEDDING_FORMAT_VERSION, EMBEDDING_DOCUMENT_PREFIX, EMBEDDING_NORMALIZATION_VERSION, EMBEDDING_CONTEXT_META_KEY, EMBEDDING_ROUTE_IDS, GATEWAY_EMBEDDING_MODELS, GEMINI_EMBEDDING_MODELS, VERTEX_EMBEDDING_LOCATIONS, GEMINI_EMBEDDING_MIN_DIMENSIONS, GEMINI_EMBEDDING_MAX_DIMENSIONS, GEMINI_EMBEDDING_TASK_FORMATS, GEMINI_TASK_PREFIXES, DEFAULT_GEMINI_DIMENSIONS, DEFAULT_GEMINI_TASK_FORMAT, EMBEDDING_ERROR_CODES, } from './schemas.js';
|
|
4
|
+
export { EMBEDDINGS_SETTINGS_KEY, EMBEDDINGS_PROTOCOL_VERSION, EMBEDDING_FORMAT_VERSION, EMBEDDING_DOCUMENT_PREFIX, EMBEDDING_NORMALIZATION_VERSION, EMBEDDING_CONTEXT_META_KEY, EMBEDDING_ROUTE_IDS, GATEWAY_EMBEDDING_MODELS, GEMINI_EMBEDDING_MODELS, VERTEX_EMBEDDING_LOCATIONS, OPENCODE_EMBEDDING_MODELS, OPENCODE_GO_EMBEDDING_MODELS, GEMINI_EMBEDDING_MIN_DIMENSIONS, GEMINI_EMBEDDING_MAX_DIMENSIONS, GEMINI_EMBEDDING_TASK_FORMATS, GEMINI_TASK_PREFIXES, DEFAULT_GEMINI_DIMENSIONS, DEFAULT_GEMINI_TASK_FORMAT, EMBEDDING_ERROR_CODES, } from './schemas.js';
|
package/dist/provider-types.d.ts
CHANGED
|
@@ -16,7 +16,11 @@ export type ProviderUsage = Readonly<{
|
|
|
16
16
|
export type ProviderBatchResult = Readonly<{
|
|
17
17
|
readonly vectors: readonly (readonly number[])[];
|
|
18
18
|
readonly usage: ProviderUsage;
|
|
19
|
+
/** Set only when the response establishes a more specific space than the preflight descriptor. */
|
|
20
|
+
readonly space?: EmbeddingSpace | undefined;
|
|
19
21
|
}>;
|
|
22
|
+
/** Supplied by hosts with a supported provider-key lookup; never invoked with a secret value. */
|
|
23
|
+
export type EmbeddingCredentialResolver = (provider: EmbeddingRouteId) => Promise<string | undefined>;
|
|
20
24
|
export interface EmbeddingsProvider {
|
|
21
25
|
readonly route: EmbeddingRouteId;
|
|
22
26
|
readonly model: string;
|
package/dist/providers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type EmbeddingRoute, type EmbeddingSettings, type EmbeddingSpace, type GeminiEmbeddingDimension, type GeminiEmbeddingTaskFormat } from './schemas.js';
|
|
2
|
-
import type { EmbeddingsProvider } from './provider-types.js';
|
|
1
|
+
import { type EmbeddingRoute, type EmbeddingSettings, type EmbeddingSpace, type GeminiEmbeddingDimension, type GeminiEmbeddingTaskFormat, type OpenCodeRouteId } from './schemas.js';
|
|
2
|
+
import type { EmbeddingCredentialResolver, EmbeddingsProvider } from './provider-types.js';
|
|
3
3
|
export declare const OPENAI_EMBEDDING_SPACE: EmbeddingSpace;
|
|
4
4
|
export declare const SARVAM_EMBEDDING_SPACE: EmbeddingSpace;
|
|
5
5
|
type CloudflarePooling = 'mean' | 'cls';
|
|
@@ -8,22 +8,31 @@ export declare const geminiEmbeddingSpace: (config: {
|
|
|
8
8
|
dimensions: GeminiEmbeddingDimension;
|
|
9
9
|
taskFormat: GeminiEmbeddingTaskFormat;
|
|
10
10
|
}) => EmbeddingSpace;
|
|
11
|
+
export declare const OPENCODE_CONSOLE_EMBEDDINGS_URL = "https://opencode.ai/inference/openai/v1/embeddings";
|
|
12
|
+
export declare const OPENCODE_GO_EMBEDDINGS_URL = "https://opencode.ai/inference/go/openai/v1/embeddings";
|
|
13
|
+
export declare const opencodeEmbeddingSpace: (args: {
|
|
14
|
+
provider: OpenCodeRouteId;
|
|
15
|
+
model: string;
|
|
16
|
+
dimensions: number | null;
|
|
17
|
+
}) => EmbeddingSpace;
|
|
11
18
|
export declare const routeKey: (route: EmbeddingRoute) => string;
|
|
19
|
+
export type OpenCodeCredentialAvailability = Readonly<Partial<Record<OpenCodeRouteId, boolean>>>;
|
|
12
20
|
export type EmbeddingDiagnostic = Readonly<{
|
|
13
21
|
readonly code: string;
|
|
14
22
|
readonly severity: 'error' | 'warning' | 'info';
|
|
15
23
|
}>;
|
|
16
24
|
/** Diagnostics are provider-free and never contain keys, origins or model paths. */
|
|
17
|
-
export declare function routeDiagnostics(settings: EmbeddingSettings, route: EmbeddingRoute): EmbeddingDiagnostic[];
|
|
25
|
+
export declare function routeDiagnostics(settings: EmbeddingSettings, route: EmbeddingRoute, piCredentialAvailable?: OpenCodeCredentialAvailability): EmbeddingDiagnostic[];
|
|
18
26
|
export type AcquiredProvider = Readonly<{
|
|
19
27
|
readonly provider: EmbeddingsProvider;
|
|
20
28
|
readonly release: () => Promise<void>;
|
|
21
29
|
}>;
|
|
22
30
|
/** Resolve a configured route only when that route is actually about to be used. */
|
|
23
|
-
export declare function acquireProvider({ settings, route, signal, }: {
|
|
31
|
+
export declare function acquireProvider({ settings, route, signal, credentialResolver, }: {
|
|
24
32
|
settings: EmbeddingSettings;
|
|
25
33
|
route: EmbeddingRoute;
|
|
26
34
|
signal: AbortSignal;
|
|
35
|
+
credentialResolver?: EmbeddingCredentialResolver | undefined;
|
|
27
36
|
}): Promise<AcquiredProvider>;
|
|
28
37
|
export declare const spaceForRoute: (route: EmbeddingRoute, settings?: EmbeddingSettings | undefined) => EmbeddingSpace;
|
|
29
38
|
export {};
|
package/dist/providers.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { getEncoding } from 'js-tiktoken';
|
|
2
2
|
import { VertexProvider, vertexEmbeddingSpace } from './vertex-provider.js';
|
|
3
3
|
import { EmbeddingsError } from './errors.js';
|
|
4
|
-
import { EMBEDDING_DOCUMENT_PREFIX, EMBEDDING_FORMAT_VERSION, EMBEDDING_NORMALIZATION_VERSION, CLOUDFLARE_EMBEDDING_MODELS, DEFAULT_GEMINI_DIMENSIONS, DEFAULT_GEMINI_TASK_FORMAT, GEMINI_EMBEDDING_MODELS, GEMINI_TASK_PREFIXES, OPENROUTER_EMBEDDING_MODELS, } from './schemas.js';
|
|
4
|
+
import { EMBEDDING_DOCUMENT_PREFIX, EMBEDDING_FORMAT_VERSION, EMBEDDING_NORMALIZATION_VERSION, CLOUDFLARE_EMBEDDING_MODELS, DEFAULT_GEMINI_DIMENSIONS, DEFAULT_GEMINI_TASK_FORMAT, GEMINI_EMBEDDING_MODELS, GEMINI_TASK_PREFIXES, OPENCODE_EMBEDDING_MODELS, OPENCODE_GO_EMBEDDING_MODELS, OPENROUTER_EMBEDDING_MODELS, } from './schemas.js';
|
|
5
5
|
import { fixedOrigin, headerValueIsSafe, requestJson } from './provider-http.js';
|
|
6
6
|
import { acquireLocalRuntime, LOCAL_EMBEDDING_SPACE } from './local-runtime.js';
|
|
7
|
-
import { parseBatchResponse, parseCloudflareBatchResponse, parseGeminiCountTokensResponse, parseGeminiEmbeddingResponse, } from './response.js';
|
|
7
|
+
import { parseBatchResponse, parseCloudflareBatchResponse, parseGeminiCountTokensResponse, parseGeminiEmbeddingResponse, parseOpenCodeBatchResponse, } from './response.js';
|
|
8
8
|
export const OPENAI_EMBEDDING_SPACE = Object.freeze({
|
|
9
9
|
provider: 'openai',
|
|
10
10
|
model: 'text-embedding-3-small',
|
|
@@ -51,6 +51,9 @@ export const geminiEmbeddingSpace = (config) => Object.freeze({
|
|
|
51
51
|
prefix: GEMINI_TASK_PREFIXES[config.taskFormat],
|
|
52
52
|
normalization: EMBEDDING_NORMALIZATION_VERSION,
|
|
53
53
|
});
|
|
54
|
+
export const OPENCODE_CONSOLE_EMBEDDINGS_URL = 'https://opencode.ai/inference/openai/v1/embeddings';
|
|
55
|
+
export const OPENCODE_GO_EMBEDDINGS_URL = 'https://opencode.ai/inference/go/openai/v1/embeddings';
|
|
56
|
+
const OPENCODE_USER_AGENT = 'pi-embeddings';
|
|
54
57
|
const OPENAI_MODEL = 'text-embedding-3-small';
|
|
55
58
|
const SARVAM_MODEL = 'embeddinggemma-2';
|
|
56
59
|
const SARVAM_ORIGIN = 'https://api.sarvam.ai';
|
|
@@ -61,13 +64,44 @@ const GEMINI_MAX_INPUT_TOKENS = 8192;
|
|
|
61
64
|
const OPENAI_MAX_INPUT_TOKENS = 8192;
|
|
62
65
|
const OPENAI_MAX_REQUEST_INPUTS = 2048;
|
|
63
66
|
const OPENAI_MAX_REQUEST_TOKENS = 300000;
|
|
67
|
+
const isOneOf = (values, value) => values.some((candidate) => candidate === value);
|
|
68
|
+
export const opencodeEmbeddingSpace = (args) => {
|
|
69
|
+
const common = {
|
|
70
|
+
revision: null,
|
|
71
|
+
quantization: null,
|
|
72
|
+
dimensions: args.dimensions,
|
|
73
|
+
format: EMBEDDING_FORMAT_VERSION,
|
|
74
|
+
prefix: EMBEDDING_DOCUMENT_PREFIX,
|
|
75
|
+
normalization: EMBEDDING_NORMALIZATION_VERSION,
|
|
76
|
+
};
|
|
77
|
+
if (args.provider === 'opencode') {
|
|
78
|
+
if (!isOneOf(OPENCODE_EMBEDDING_MODELS, args.model))
|
|
79
|
+
throw new EmbeddingsError('configuration-invalid');
|
|
80
|
+
const space = {
|
|
81
|
+
...common,
|
|
82
|
+
provider: 'opencode',
|
|
83
|
+
model: args.model,
|
|
84
|
+
runtime: 'opencode-console-embeddings-v1',
|
|
85
|
+
};
|
|
86
|
+
return Object.freeze(space);
|
|
87
|
+
}
|
|
88
|
+
if (!isOneOf(OPENCODE_GO_EMBEDDING_MODELS, args.model))
|
|
89
|
+
throw new EmbeddingsError('configuration-invalid');
|
|
90
|
+
const space = {
|
|
91
|
+
...common,
|
|
92
|
+
provider: 'opencode-go',
|
|
93
|
+
model: args.model,
|
|
94
|
+
runtime: 'opencode-go-embeddings-v1',
|
|
95
|
+
};
|
|
96
|
+
return Object.freeze(space);
|
|
97
|
+
};
|
|
64
98
|
const trim = (value) => {
|
|
65
99
|
const trimmed = value?.trim();
|
|
66
100
|
return trimmed === undefined || trimmed === '' ? undefined : trimmed;
|
|
67
101
|
};
|
|
68
102
|
export const routeKey = (route) => `${route.provider}\u0000${route.model}`;
|
|
69
103
|
/** Diagnostics are provider-free and never contain keys, origins or model paths. */
|
|
70
|
-
export function routeDiagnostics(settings, route) {
|
|
104
|
+
export function routeDiagnostics(settings, route, piCredentialAvailable = {}) {
|
|
71
105
|
const diagnostics = [];
|
|
72
106
|
const add = (code, severity = 'error') => {
|
|
73
107
|
diagnostics.push({ code, severity });
|
|
@@ -113,6 +147,18 @@ export function routeDiagnostics(settings, route) {
|
|
|
113
147
|
if (trim(settings.providers?.gemini?.apiKey) === undefined && trim(process.env.GEMINI_API_KEY) === undefined)
|
|
114
148
|
add('gemini-key-unconfigured');
|
|
115
149
|
break;
|
|
150
|
+
case 'opencode':
|
|
151
|
+
if (trim(settings.providers?.opencode?.apiKey) === undefined &&
|
|
152
|
+
trim(process.env.OPENCODE_API_KEY) === undefined &&
|
|
153
|
+
piCredentialAvailable.opencode !== true)
|
|
154
|
+
add('opencode-key-unconfigured');
|
|
155
|
+
break;
|
|
156
|
+
case 'opencode-go':
|
|
157
|
+
if (trim(settings.providers?.['opencode-go']?.apiKey) === undefined &&
|
|
158
|
+
trim(process.env.OPENCODE_API_KEY) === undefined &&
|
|
159
|
+
piCredentialAvailable['opencode-go'] !== true)
|
|
160
|
+
add('opencode-go-key-unconfigured');
|
|
161
|
+
break;
|
|
116
162
|
case 'vertex':
|
|
117
163
|
if (settings.providers?.vertex === undefined)
|
|
118
164
|
add('vertex-configuration-unconfigured');
|
|
@@ -133,6 +179,31 @@ const headerCredential = (configured, env) => {
|
|
|
133
179
|
throw new EmbeddingsError('configuration-invalid');
|
|
134
180
|
return value;
|
|
135
181
|
};
|
|
182
|
+
const safeHeaderValue = (value) => {
|
|
183
|
+
if (!headerValueIsSafe(value))
|
|
184
|
+
throw new EmbeddingsError('configuration-invalid');
|
|
185
|
+
return value;
|
|
186
|
+
};
|
|
187
|
+
/** Host-provided provider keys are read only when a route is acquired; errors never carry a value. */
|
|
188
|
+
async function openCodeCredential(args) {
|
|
189
|
+
const configured = args.route === 'opencode'
|
|
190
|
+
? args.settings.providers?.opencode?.apiKey
|
|
191
|
+
: args.settings.providers?.['opencode-go']?.apiKey;
|
|
192
|
+
const explicit = trim(configured);
|
|
193
|
+
if (explicit !== undefined)
|
|
194
|
+
return safeHeaderValue(explicit);
|
|
195
|
+
if (args.resolver !== undefined) {
|
|
196
|
+
try {
|
|
197
|
+
const resolved = trim(await args.resolver(args.route));
|
|
198
|
+
if (resolved !== undefined)
|
|
199
|
+
return safeHeaderValue(resolved);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
// A host resolver that cannot supply a key leaves the trusted environment fallback intact.
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return headerCredential(undefined, process.env.OPENCODE_API_KEY);
|
|
206
|
+
}
|
|
136
207
|
/** The documented text-string path avoids the token-array schema contradiction without truncating. */
|
|
137
208
|
const openAIPrepare = (encoding, text, signal) => {
|
|
138
209
|
signal.throwIfAborted();
|
|
@@ -187,6 +258,62 @@ class OpenAiProvider {
|
|
|
187
258
|
// js-tiktoken is pure JavaScript and owns no process or handle.
|
|
188
259
|
}
|
|
189
260
|
}
|
|
261
|
+
class OpenCodeProvider {
|
|
262
|
+
route;
|
|
263
|
+
model;
|
|
264
|
+
space;
|
|
265
|
+
// OpenCode documents per-input context requirements but publishes no aggregate request ceiling.
|
|
266
|
+
maxRequestInputs = Number.POSITIVE_INFINITY;
|
|
267
|
+
maxRequestTokens = Number.POSITIVE_INFINITY;
|
|
268
|
+
#url;
|
|
269
|
+
#key;
|
|
270
|
+
constructor(args) {
|
|
271
|
+
this.route = args.route;
|
|
272
|
+
this.model = args.model;
|
|
273
|
+
this.space = opencodeEmbeddingSpace({
|
|
274
|
+
provider: args.route,
|
|
275
|
+
model: args.model,
|
|
276
|
+
dimensions: null,
|
|
277
|
+
});
|
|
278
|
+
this.#url = args.url;
|
|
279
|
+
this.#key = args.key;
|
|
280
|
+
}
|
|
281
|
+
async prepare(text, signal) {
|
|
282
|
+
signal.throwIfAborted();
|
|
283
|
+
return { kind: 'text', text: EMBEDDING_DOCUMENT_PREFIX + text, tokenCount: null };
|
|
284
|
+
}
|
|
285
|
+
async embed(inputs, signal) {
|
|
286
|
+
const parsed = parseOpenCodeBatchResponse({
|
|
287
|
+
response: await requestJson({
|
|
288
|
+
url: this.#url,
|
|
289
|
+
signal,
|
|
290
|
+
headers: {
|
|
291
|
+
authorization: `Bearer ${this.#key}`,
|
|
292
|
+
'user-agent': OPENCODE_USER_AGENT,
|
|
293
|
+
},
|
|
294
|
+
body: {
|
|
295
|
+
model: this.model,
|
|
296
|
+
input: providerTexts(inputs),
|
|
297
|
+
encoding_format: 'float',
|
|
298
|
+
},
|
|
299
|
+
}),
|
|
300
|
+
expectedModels: [this.model],
|
|
301
|
+
expectedCount: inputs.length,
|
|
302
|
+
});
|
|
303
|
+
return {
|
|
304
|
+
vectors: parsed.vectors,
|
|
305
|
+
usage: parsed.usage,
|
|
306
|
+
space: opencodeEmbeddingSpace({
|
|
307
|
+
provider: this.route,
|
|
308
|
+
model: this.model,
|
|
309
|
+
dimensions: parsed.dimensions,
|
|
310
|
+
}),
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
async close() {
|
|
314
|
+
// Native fetch owns no long-lived resource.
|
|
315
|
+
}
|
|
316
|
+
}
|
|
190
317
|
class SarvamProvider {
|
|
191
318
|
route = 'sarvam';
|
|
192
319
|
model = SARVAM_MODEL;
|
|
@@ -414,7 +541,7 @@ class GeminiProvider {
|
|
|
414
541
|
}
|
|
415
542
|
const noRelease = async () => undefined;
|
|
416
543
|
/** Resolve a configured route only when that route is actually about to be used. */
|
|
417
|
-
export async function acquireProvider({ settings, route, signal, }) {
|
|
544
|
+
export async function acquireProvider({ settings, route, signal, credentialResolver, }) {
|
|
418
545
|
switch (route.provider) {
|
|
419
546
|
case 'local': {
|
|
420
547
|
const local = settings.providers?.local;
|
|
@@ -480,6 +607,19 @@ export async function acquireProvider({ settings, route, signal, }) {
|
|
|
480
607
|
release: noRelease,
|
|
481
608
|
};
|
|
482
609
|
}
|
|
610
|
+
case 'opencode':
|
|
611
|
+
case 'opencode-go':
|
|
612
|
+
return {
|
|
613
|
+
provider: new OpenCodeProvider({
|
|
614
|
+
route: route.provider,
|
|
615
|
+
model: route.model,
|
|
616
|
+
key: await openCodeCredential({ route: route.provider, settings, resolver: credentialResolver }),
|
|
617
|
+
url: new URL(route.provider === 'opencode'
|
|
618
|
+
? OPENCODE_CONSOLE_EMBEDDINGS_URL
|
|
619
|
+
: OPENCODE_GO_EMBEDDINGS_URL),
|
|
620
|
+
}),
|
|
621
|
+
release: noRelease,
|
|
622
|
+
};
|
|
483
623
|
case 'vertex': {
|
|
484
624
|
const configured = settings.providers?.vertex;
|
|
485
625
|
if (configured === undefined)
|
|
@@ -521,5 +661,8 @@ export const spaceForRoute = (route, settings) => {
|
|
|
521
661
|
dimensions: settings?.providers?.gemini?.dimensions ?? DEFAULT_GEMINI_DIMENSIONS,
|
|
522
662
|
taskFormat: settings?.providers?.gemini?.taskFormat ?? DEFAULT_GEMINI_TASK_FORMAT,
|
|
523
663
|
});
|
|
664
|
+
case 'opencode':
|
|
665
|
+
case 'opencode-go':
|
|
666
|
+
return opencodeEmbeddingSpace({ provider: route.provider, model: route.model, dimensions: null });
|
|
524
667
|
}
|
|
525
668
|
};
|
package/dist/response.d.ts
CHANGED
|
@@ -11,6 +11,17 @@ export declare function parseBatchResponse(args: {
|
|
|
11
11
|
expectedPreparedTokens?: number | null;
|
|
12
12
|
preparedInputTokens?: number | null;
|
|
13
13
|
}): ProviderBatchResult;
|
|
14
|
+
/**
|
|
15
|
+
* OpenCode's OpenAI-compatible embeddings response does not publish per-model dimensions, so the
|
|
16
|
+
* dimension is observed from the returned vectors and included in the actual generating space.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseOpenCodeBatchResponse(args: {
|
|
19
|
+
response: unknown;
|
|
20
|
+
expectedModels: readonly string[];
|
|
21
|
+
expectedCount: number;
|
|
22
|
+
}): ProviderBatchResult & {
|
|
23
|
+
readonly dimensions: number;
|
|
24
|
+
};
|
|
14
25
|
/**
|
|
15
26
|
* Gemini `embedContent` returns one embedding and provider-counted prompt tokens. A vector is accepted
|
|
16
27
|
* only when that response count matches the exact prepared prompt counted before inference; a mismatch
|
package/dist/response.js
CHANGED
|
@@ -11,6 +11,16 @@ const responseSchema = Type.Object({
|
|
|
11
11
|
prompt_tokens: Type.Integer({ minimum: 0 }),
|
|
12
12
|
}),
|
|
13
13
|
});
|
|
14
|
+
const openCodeResponseSchema = Type.Object({
|
|
15
|
+
model: Type.Optional(Type.String({ minLength: 1 })),
|
|
16
|
+
data: Type.Array(Type.Object({
|
|
17
|
+
index: Type.Integer({ minimum: 0 }),
|
|
18
|
+
embedding: Type.Array(Type.Number()),
|
|
19
|
+
})),
|
|
20
|
+
usage: Type.Optional(Type.Object({
|
|
21
|
+
prompt_tokens: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
22
|
+
})),
|
|
23
|
+
});
|
|
14
24
|
const cloudflareResponseSchema = Type.Object({
|
|
15
25
|
shape: Type.Optional(Type.Array(Type.Integer({ minimum: 0 }))),
|
|
16
26
|
data: Type.Array(Type.Array(Type.Number())),
|
|
@@ -53,6 +63,11 @@ export function normalizeVector(vector, dimensions) {
|
|
|
53
63
|
const norm = Math.sqrt(vector.reduce((sum, value) => sum + (value / scale) ** 2, 0));
|
|
54
64
|
return vector.map((value) => value / scale / norm);
|
|
55
65
|
}
|
|
66
|
+
function dimensionsOf(space) {
|
|
67
|
+
if (typeof space.dimensions !== 'number')
|
|
68
|
+
throw new EmbeddingsError('vector-invalid');
|
|
69
|
+
return space.dimensions;
|
|
70
|
+
}
|
|
56
71
|
export function parseBatchResponse(args) {
|
|
57
72
|
const prepared = args.preparedInputTokens ?? args.expectedPreparedTokens ?? null;
|
|
58
73
|
if (!Value.Check(responseSchema, args.response))
|
|
@@ -76,7 +91,7 @@ export function parseBatchResponse(args) {
|
|
|
76
91
|
throw known('provider-response-mismatch');
|
|
77
92
|
let vectors;
|
|
78
93
|
try {
|
|
79
|
-
vectors = ordered.map((item) => normalizeVector(item.embedding, args.space
|
|
94
|
+
vectors = ordered.map((item) => normalizeVector(item.embedding, dimensionsOf(args.space)));
|
|
80
95
|
}
|
|
81
96
|
catch (error) {
|
|
82
97
|
if (error instanceof EmbeddingsError)
|
|
@@ -92,6 +107,52 @@ export function parseBatchResponse(args) {
|
|
|
92
107
|
},
|
|
93
108
|
};
|
|
94
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* OpenCode's OpenAI-compatible embeddings response does not publish per-model dimensions, so the
|
|
112
|
+
* dimension is observed from the returned vectors and included in the actual generating space.
|
|
113
|
+
*/
|
|
114
|
+
export function parseOpenCodeBatchResponse(args) {
|
|
115
|
+
if (!Value.Check(openCodeResponseSchema, args.response))
|
|
116
|
+
throw new EmbeddingsError('provider-response-invalid', { knownUsage: {} });
|
|
117
|
+
const parsed = args.response;
|
|
118
|
+
const providerReportedInputTokens = parsed.usage?.prompt_tokens ?? null;
|
|
119
|
+
const knownUsage = {
|
|
120
|
+
providerReportedInputTokens,
|
|
121
|
+
preparedInputTokens: null,
|
|
122
|
+
};
|
|
123
|
+
const fail = (code) => {
|
|
124
|
+
throw new EmbeddingsError(code, { knownUsage });
|
|
125
|
+
};
|
|
126
|
+
if (parsed.model !== undefined && !args.expectedModels.includes(parsed.model))
|
|
127
|
+
fail('provider-response-mismatch');
|
|
128
|
+
const ordered = [...parsed.data].sort((left, right) => left.index - right.index);
|
|
129
|
+
if (ordered.length !== args.expectedCount || ordered.some((item, index) => item.index !== index))
|
|
130
|
+
fail('provider-response-mismatch');
|
|
131
|
+
const first = ordered[0];
|
|
132
|
+
if (first === undefined)
|
|
133
|
+
throw new EmbeddingsError('provider-response-mismatch', { knownUsage });
|
|
134
|
+
const dimensions = first.embedding.length;
|
|
135
|
+
if (dimensions === 0)
|
|
136
|
+
fail('vector-invalid');
|
|
137
|
+
let vectors;
|
|
138
|
+
try {
|
|
139
|
+
vectors = ordered.map((item) => normalizeVector(item.embedding, dimensions));
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
if (error instanceof EmbeddingsError)
|
|
143
|
+
fail(error.code === 'vector-zero' ? 'vector-zero' : 'vector-invalid');
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
vectors,
|
|
148
|
+
usage: {
|
|
149
|
+
providerReportedInputTokens,
|
|
150
|
+
preparedInputTokens: null,
|
|
151
|
+
billedTokens: null,
|
|
152
|
+
},
|
|
153
|
+
dimensions,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
95
156
|
/**
|
|
96
157
|
* Gemini `embedContent` returns one embedding and provider-counted prompt tokens. A vector is accepted
|
|
97
158
|
* only when that response count matches the exact prepared prompt counted before inference; a mismatch
|
|
@@ -114,7 +175,7 @@ export function parseGeminiEmbeddingResponse(args) {
|
|
|
114
175
|
throw new EmbeddingsError('input-too-long', { knownUsage });
|
|
115
176
|
let vector;
|
|
116
177
|
try {
|
|
117
|
-
vector = normalizeVector(parsed.embedding.values, args.space
|
|
178
|
+
vector = normalizeVector(parsed.embedding.values, dimensionsOf(args.space));
|
|
118
179
|
}
|
|
119
180
|
catch (error) {
|
|
120
181
|
if (error instanceof EmbeddingsError)
|
|
@@ -157,7 +218,7 @@ export function parseCloudflareBatchResponse(args) {
|
|
|
157
218
|
throw new EmbeddingsError('provider-response-mismatch', { knownUsage: {} });
|
|
158
219
|
let vectors;
|
|
159
220
|
try {
|
|
160
|
-
vectors = parsed.data.map((vector) => normalizeVector(vector, args.space
|
|
221
|
+
vectors = parsed.data.map((vector) => normalizeVector(vector, dimensionsOf(args.space)));
|
|
161
222
|
}
|
|
162
223
|
catch (error) {
|
|
163
224
|
if (error instanceof EmbeddingsError)
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { spaceForRoute, type EmbeddingDiagnostic } from './providers.js';
|
|
1
|
+
import { spaceForRoute, type EmbeddingDiagnostic, type OpenCodeCredentialAvailability } from './providers.js';
|
|
2
|
+
import type { EmbeddingCredentialResolver } from './provider-types.js';
|
|
2
3
|
import { EMBEDDINGS_PROTOCOL_VERSION, type EmbeddingCompareResult, type EmbeddingContext, type EmbeddingRequest, type EmbeddingResult, type EmbeddingRoute, type EmbeddingSettings } from './schemas.js';
|
|
3
4
|
export interface EmbeddingsRuntime {
|
|
4
5
|
/** Acquire the selected local child at MCP startup; cloud selections start no local process. */
|
|
@@ -31,9 +32,13 @@ export interface EmbeddingsRuntimeWithDiagnostics extends EmbeddingsRuntime {
|
|
|
31
32
|
export declare function createEmbeddingsRuntime(args: {
|
|
32
33
|
settings: EmbeddingSettings;
|
|
33
34
|
cwd?: string | undefined;
|
|
35
|
+
credentialResolver?: EmbeddingCredentialResolver | undefined;
|
|
36
|
+
piCredentialAvailable?: OpenCodeCredentialAvailability | undefined;
|
|
34
37
|
}): EmbeddingsRuntime;
|
|
35
38
|
/** Package-internal factory for Pi command output and provider-free host startup checks. */
|
|
36
39
|
export declare function createEmbeddingsRuntimeWithDiagnostics(args: {
|
|
37
40
|
settings: EmbeddingSettings;
|
|
38
41
|
cwd?: string | undefined;
|
|
42
|
+
credentialResolver?: EmbeddingCredentialResolver | undefined;
|
|
43
|
+
piCredentialAvailable?: OpenCodeCredentialAvailability | undefined;
|
|
39
44
|
}): EmbeddingsRuntimeWithDiagnostics;
|
package/dist/runtime.js
CHANGED
|
@@ -27,7 +27,12 @@ function createRuntime(args) {
|
|
|
27
27
|
const inFlight = pending.get(key);
|
|
28
28
|
if (inFlight !== undefined)
|
|
29
29
|
return inFlight;
|
|
30
|
-
const promise = acquireProvider({
|
|
30
|
+
const promise = acquireProvider({
|
|
31
|
+
settings,
|
|
32
|
+
route,
|
|
33
|
+
signal: lifetime.signal,
|
|
34
|
+
credentialResolver: args.credentialResolver,
|
|
35
|
+
})
|
|
31
36
|
.then((entry) => {
|
|
32
37
|
pending.delete(key);
|
|
33
38
|
if (closed || closing !== undefined) {
|
|
@@ -84,10 +89,10 @@ function createRuntime(args) {
|
|
|
84
89
|
});
|
|
85
90
|
},
|
|
86
91
|
describe() {
|
|
87
|
-
const defaultDiagnostics = routeDiagnostics(settings, defaultRoute);
|
|
92
|
+
const defaultDiagnostics = routeDiagnostics(settings, defaultRoute, args.piCredentialAvailable ?? {});
|
|
88
93
|
const diagnostics = [...defaultDiagnostics];
|
|
89
94
|
for (const route of fallbackRoutes)
|
|
90
|
-
diagnostics.push(...routeDiagnostics(settings, route).map((entry) => ({
|
|
95
|
+
diagnostics.push(...routeDiagnostics(settings, route, args.piCredentialAvailable ?? {}).map((entry) => ({
|
|
91
96
|
...entry,
|
|
92
97
|
severity: 'warning',
|
|
93
98
|
})));
|