@abhishek944/pi-embeddings 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/README.md +87 -2
- package/dist/errors.d.ts +21 -0
- package/dist/errors.js +41 -0
- package/dist/execute.d.ts +25 -0
- package/dist/execute.js +229 -0
- package/dist/extension.d.ts +2 -0
- package/dist/extension.js +195 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/local-runtime.d.ts +14 -0
- package/dist/local-runtime.js +246 -0
- package/dist/mcp-cli.d.ts +2 -0
- package/dist/mcp-cli.js +46 -0
- package/dist/mcp-server.d.ts +23 -0
- package/dist/mcp-server.js +154 -0
- package/dist/provider-http.d.ts +11 -0
- package/dist/provider-http.js +60 -0
- package/dist/provider-types.d.ts +30 -0
- package/dist/provider-types.js +1 -0
- package/dist/providers.d.ts +18 -0
- package/dist/providers.js +265 -0
- package/dist/response.d.ts +11 -0
- package/dist/response.js +62 -0
- package/dist/runtime.d.ts +19 -0
- package/dist/runtime.js +121 -0
- package/dist/schemas.d.ts +431 -0
- package/dist/schemas.js +214 -0
- package/dist/settings-write.d.ts +9 -0
- package/dist/settings-write.js +77 -0
- package/dist/settings.d.ts +8 -0
- package/dist/settings.js +97 -0
- package/dist/tool-contracts.d.ts +200 -0
- package/dist/tool-contracts.js +19 -0
- package/package.json +83 -4
- package/src/errors.ts +52 -0
- package/src/execute.ts +261 -0
- package/src/extension.ts +245 -0
- package/src/index.ts +37 -0
- package/src/local-runtime.ts +273 -0
- package/src/mcp-cli.ts +52 -0
- package/src/mcp-server.ts +206 -0
- package/src/provider-http.ts +67 -0
- package/src/provider-types.ts +33 -0
- package/src/providers.ts +335 -0
- package/src/response.ts +74 -0
- package/src/runtime.ts +146 -0
- package/src/schemas.ts +326 -0
- package/src/settings-write.ts +96 -0
- package/src/settings.ts +115 -0
- package/src/tool-contracts.ts +34 -0
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authoritative public schemas for pi-embeddings.
|
|
3
|
+
*
|
|
4
|
+
* Types across the library, Pi extension and MCP server derive from this file. The descriptor shape
|
|
5
|
+
* deliberately matches the stored HighSKU vector space document, so legacy vectors remain compatible
|
|
6
|
+
* without rewriting stored bytes or inventing unknown provenance.
|
|
7
|
+
*/
|
|
8
|
+
import { Type } from 'typebox';
|
|
9
|
+
export const EMBEDDINGS_SETTINGS_KEY = 'pi-embeddings';
|
|
10
|
+
export const EMBEDDINGS_PROTOCOL_VERSION = 1;
|
|
11
|
+
export const EMBEDDING_FORMAT_VERSION = 'host-display-attributes-v1';
|
|
12
|
+
export const EMBEDDING_DOCUMENT_PREFIX = 'title: none | text: ';
|
|
13
|
+
export const EMBEDDING_NORMALIZATION_VERSION = 'finite-nonzero-l2-v1';
|
|
14
|
+
export const EMBEDDING_CONTEXT_META_KEY = 'pi-embeddings/context';
|
|
15
|
+
export const EMBEDDING_ROUTE_IDS = ['local', 'openai', 'sarvam', 'gateway'];
|
|
16
|
+
export const GATEWAY_EMBEDDING_MODELS = [
|
|
17
|
+
'text-embedding-3-small',
|
|
18
|
+
'openai/text-embedding-3-small',
|
|
19
|
+
];
|
|
20
|
+
const gatewayModelSchema = Type.Union([
|
|
21
|
+
Type.Literal('text-embedding-3-small'),
|
|
22
|
+
Type.Literal('openai/text-embedding-3-small'),
|
|
23
|
+
]);
|
|
24
|
+
const embeddingErrorCodeSchema = Type.Union([
|
|
25
|
+
Type.Literal('configuration-invalid'),
|
|
26
|
+
Type.Literal('route-unconfigured'),
|
|
27
|
+
Type.Literal('missing-credentials'),
|
|
28
|
+
Type.Literal('http-auth'),
|
|
29
|
+
Type.Literal('http-not-found'),
|
|
30
|
+
Type.Literal('http-rate-limit'),
|
|
31
|
+
Type.Literal('http-forbidden'),
|
|
32
|
+
Type.Literal('http-bad-request'),
|
|
33
|
+
Type.Literal('http-server-error'),
|
|
34
|
+
Type.Literal('transport-failed'),
|
|
35
|
+
Type.Literal('provider-response-invalid'),
|
|
36
|
+
Type.Literal('provider-response-mismatch'),
|
|
37
|
+
Type.Literal('vector-invalid'),
|
|
38
|
+
Type.Literal('vector-zero'),
|
|
39
|
+
Type.Literal('input-empty'),
|
|
40
|
+
Type.Literal('input-too-long'),
|
|
41
|
+
Type.Literal('tokenizer-roundtrip-failed'),
|
|
42
|
+
Type.Literal('attribution-unavailable'),
|
|
43
|
+
Type.Literal('local-resources-unavailable'),
|
|
44
|
+
Type.Literal('local-model-mismatch'),
|
|
45
|
+
Type.Literal('local-runtime-mismatch'),
|
|
46
|
+
Type.Literal('local-startup-failed'),
|
|
47
|
+
Type.Literal('local-cpu-startup-invalid'),
|
|
48
|
+
Type.Literal('cancelled'),
|
|
49
|
+
Type.Literal('unstarted'),
|
|
50
|
+
]);
|
|
51
|
+
export const EMBEDDING_ERROR_CODES = [
|
|
52
|
+
'configuration-invalid',
|
|
53
|
+
'route-unconfigured',
|
|
54
|
+
'missing-credentials',
|
|
55
|
+
'http-auth',
|
|
56
|
+
'http-not-found',
|
|
57
|
+
'http-rate-limit',
|
|
58
|
+
'http-forbidden',
|
|
59
|
+
'http-bad-request',
|
|
60
|
+
'http-server-error',
|
|
61
|
+
'transport-failed',
|
|
62
|
+
'provider-response-invalid',
|
|
63
|
+
'provider-response-mismatch',
|
|
64
|
+
'vector-invalid',
|
|
65
|
+
'vector-zero',
|
|
66
|
+
'input-empty',
|
|
67
|
+
'input-too-long',
|
|
68
|
+
'tokenizer-roundtrip-failed',
|
|
69
|
+
'attribution-unavailable',
|
|
70
|
+
'local-resources-unavailable',
|
|
71
|
+
'local-model-mismatch',
|
|
72
|
+
'local-runtime-mismatch',
|
|
73
|
+
'local-startup-failed',
|
|
74
|
+
'local-cpu-startup-invalid',
|
|
75
|
+
'cancelled',
|
|
76
|
+
'unstarted',
|
|
77
|
+
];
|
|
78
|
+
const embeddingProviderSchema = Type.Union([
|
|
79
|
+
Type.Literal('local'),
|
|
80
|
+
Type.Literal('openai'),
|
|
81
|
+
Type.Literal('sarvam'),
|
|
82
|
+
Type.Literal('gateway'),
|
|
83
|
+
]);
|
|
84
|
+
export const embeddingRouteSchema = Type.Object({
|
|
85
|
+
provider: embeddingProviderSchema,
|
|
86
|
+
model: Type.String({ minLength: 1 }),
|
|
87
|
+
}, { additionalProperties: false });
|
|
88
|
+
const spaceCommon = {
|
|
89
|
+
format: Type.Literal(EMBEDDING_FORMAT_VERSION),
|
|
90
|
+
prefix: Type.Literal(EMBEDDING_DOCUMENT_PREFIX),
|
|
91
|
+
normalization: Type.Literal(EMBEDDING_NORMALIZATION_VERSION),
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Complete generating-space identity. `provider` is canonical: the gateway route deliberately
|
|
95
|
+
* reports the OpenAI recipe it declares, not its transport alias.
|
|
96
|
+
*/
|
|
97
|
+
export const embeddingSpaceSchema = Type.Union([
|
|
98
|
+
Type.Object({
|
|
99
|
+
...spaceCommon,
|
|
100
|
+
provider: Type.Literal('local'),
|
|
101
|
+
model: Type.Literal('embeddinggemma-2'),
|
|
102
|
+
revision: Type.String({ minLength: 1 }),
|
|
103
|
+
quantization: Type.Literal('Q8_0'),
|
|
104
|
+
runtime: Type.String({ minLength: 1 }),
|
|
105
|
+
dimensions: Type.Literal(768),
|
|
106
|
+
}, { additionalProperties: false }),
|
|
107
|
+
Type.Object({
|
|
108
|
+
...spaceCommon,
|
|
109
|
+
provider: Type.Literal('openai'),
|
|
110
|
+
model: Type.Literal('text-embedding-3-small'),
|
|
111
|
+
revision: Type.Null(),
|
|
112
|
+
quantization: Type.Null(),
|
|
113
|
+
runtime: Type.Null(),
|
|
114
|
+
dimensions: Type.Literal(1536),
|
|
115
|
+
}, { additionalProperties: false }),
|
|
116
|
+
Type.Object({
|
|
117
|
+
...spaceCommon,
|
|
118
|
+
provider: Type.Literal('sarvam'),
|
|
119
|
+
model: Type.Literal('embeddinggemma-2'),
|
|
120
|
+
revision: Type.Null(),
|
|
121
|
+
quantization: Type.Null(),
|
|
122
|
+
runtime: Type.Literal('sarvam-v2'),
|
|
123
|
+
dimensions: Type.Literal(768),
|
|
124
|
+
}, { additionalProperties: false }),
|
|
125
|
+
]);
|
|
126
|
+
export const embeddingSettingsSchema = Type.Object({
|
|
127
|
+
version: Type.Optional(Type.Literal(1)),
|
|
128
|
+
default: embeddingRouteSchema,
|
|
129
|
+
fallback: Type.Optional(Type.Array(embeddingRouteSchema)),
|
|
130
|
+
compare: Type.Optional(Type.Array(embeddingRouteSchema)),
|
|
131
|
+
providers: Type.Optional(Type.Object({
|
|
132
|
+
local: Type.Optional(Type.Object({
|
|
133
|
+
executable: Type.String({ minLength: 1 }),
|
|
134
|
+
modelPath: Type.String({ minLength: 1 }),
|
|
135
|
+
port: Type.Optional(Type.Integer({ minimum: 1, maximum: 65535 })),
|
|
136
|
+
}, { additionalProperties: false })),
|
|
137
|
+
openai: Type.Optional(Type.Object({ apiKey: Type.Optional(Type.String({ minLength: 1 })) }, { additionalProperties: false })),
|
|
138
|
+
sarvam: Type.Optional(Type.Object({ apiKey: Type.Optional(Type.String({ minLength: 1 })) }, { additionalProperties: false })),
|
|
139
|
+
gateway: Type.Optional(Type.Object({
|
|
140
|
+
baseUrl: Type.String({ minLength: 1 }),
|
|
141
|
+
apiKey: Type.String({ minLength: 1 }),
|
|
142
|
+
model: gatewayModelSchema,
|
|
143
|
+
stage: Type.Union([Type.Literal('dev'), Type.Literal('prod')]),
|
|
144
|
+
}, { additionalProperties: false })),
|
|
145
|
+
}, { additionalProperties: false })),
|
|
146
|
+
}, { additionalProperties: false });
|
|
147
|
+
export const embeddingRequestSchema = Type.Object({
|
|
148
|
+
inputs: Type.Array(Type.String({ minLength: 1 }), { minItems: 1 }),
|
|
149
|
+
}, { additionalProperties: false });
|
|
150
|
+
/** Generic, host-owned attribution. It is never a model argument or proof of ownership. */
|
|
151
|
+
export const embeddingContextSchema = Type.Object({
|
|
152
|
+
endUser: Type.String({ minLength: 1 }),
|
|
153
|
+
tags: Type.Array(Type.String({ minLength: 1 })),
|
|
154
|
+
}, { additionalProperties: false });
|
|
155
|
+
export const embeddingUsageSchema = Type.Object({
|
|
156
|
+
providerReportedInputTokens: Type.Union([Type.Integer({ minimum: 0 }), Type.Null()]),
|
|
157
|
+
preparedInputTokens: Type.Union([Type.Integer({ minimum: 0 }), Type.Null()]),
|
|
158
|
+
billedTokens: Type.Union([Type.Integer({ minimum: 0 }), Type.Null()]),
|
|
159
|
+
}, { additionalProperties: false });
|
|
160
|
+
export const embeddingAttemptSchema = Type.Object({
|
|
161
|
+
id: Type.String({ minLength: 1 }),
|
|
162
|
+
route: embeddingProviderSchema,
|
|
163
|
+
model: Type.String({ minLength: 1 }),
|
|
164
|
+
routeIndex: Type.Integer({ minimum: 0 }),
|
|
165
|
+
status: Type.Union([Type.Literal('success'), Type.Literal('error'), Type.Literal('cancelled')]),
|
|
166
|
+
usage: Type.Union([embeddingUsageSchema, Type.Null()]),
|
|
167
|
+
errorCode: Type.Optional(embeddingErrorCodeSchema),
|
|
168
|
+
}, { additionalProperties: false });
|
|
169
|
+
const successOutcomeSchema = Type.Object({
|
|
170
|
+
status: Type.Literal('success'),
|
|
171
|
+
index: Type.Integer({ minimum: 0 }),
|
|
172
|
+
vector: Type.Array(Type.Number()),
|
|
173
|
+
route: embeddingProviderSchema,
|
|
174
|
+
model: Type.String({ minLength: 1 }),
|
|
175
|
+
space: embeddingSpaceSchema,
|
|
176
|
+
attemptId: Type.String({ minLength: 1 }),
|
|
177
|
+
normalization: Type.Literal(EMBEDDING_NORMALIZATION_VERSION),
|
|
178
|
+
}, { additionalProperties: false });
|
|
179
|
+
const errorOutcomeSchema = Type.Object({
|
|
180
|
+
status: Type.Literal('error'),
|
|
181
|
+
index: Type.Integer({ minimum: 0 }),
|
|
182
|
+
code: embeddingErrorCodeSchema,
|
|
183
|
+
attemptId: Type.Union([Type.String({ minLength: 1 }), Type.Null()]),
|
|
184
|
+
}, { additionalProperties: false });
|
|
185
|
+
export const embeddingOutcomeSchema = Type.Union([successOutcomeSchema, errorOutcomeSchema]);
|
|
186
|
+
export const embeddingResultSchema = Type.Object({
|
|
187
|
+
schemaVersion: Type.Literal(EMBEDDINGS_PROTOCOL_VERSION),
|
|
188
|
+
outcomes: Type.Array(embeddingOutcomeSchema),
|
|
189
|
+
attempts: Type.Array(embeddingAttemptSchema),
|
|
190
|
+
}, { additionalProperties: false });
|
|
191
|
+
export const embeddingCompareEntrySchema = Type.Object({
|
|
192
|
+
route: embeddingProviderSchema,
|
|
193
|
+
model: Type.String({ minLength: 1 }),
|
|
194
|
+
status: Type.Union([Type.Literal('success'), Type.Literal('error'), Type.Literal('cancelled')]),
|
|
195
|
+
result: embeddingResultSchema,
|
|
196
|
+
}, { additionalProperties: false });
|
|
197
|
+
export const embeddingCompareResultSchema = Type.Object({
|
|
198
|
+
schemaVersion: Type.Literal(EMBEDDINGS_PROTOCOL_VERSION),
|
|
199
|
+
entries: Type.Array(embeddingCompareEntrySchema),
|
|
200
|
+
}, { 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 });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type EmbeddingRoute } from './schemas.js';
|
|
2
|
+
export declare class EmbeddingsSettingsWriteError extends Error {
|
|
3
|
+
}
|
|
4
|
+
/** Update only the trusted project's `pi-embeddings.default`, preserving every unrelated key. */
|
|
5
|
+
export declare function updateProjectEmbeddingSettings({ cwd, projectTrusted, route, }: {
|
|
6
|
+
cwd: string;
|
|
7
|
+
projectTrusted: boolean;
|
|
8
|
+
route: EmbeddingRoute;
|
|
9
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { lstat, mkdir, open, readFile, rename, unlink } from 'node:fs/promises';
|
|
3
|
+
import { withFileMutationQueue } from '@earendil-works/pi-coding-agent';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
import { validateEmbeddingSettings } from './settings.js';
|
|
6
|
+
import { EMBEDDINGS_SETTINGS_KEY } from './schemas.js';
|
|
7
|
+
export class EmbeddingsSettingsWriteError extends Error {
|
|
8
|
+
}
|
|
9
|
+
/** Update only the trusted project's `pi-embeddings.default`, preserving every unrelated key. */
|
|
10
|
+
export function updateProjectEmbeddingSettings({ cwd, projectTrusted, route, }) {
|
|
11
|
+
validateEmbeddingSettings({ default: route });
|
|
12
|
+
const settingsPath = resolve(cwd, '.pi', 'settings.json');
|
|
13
|
+
return withFileMutationQueue(settingsPath, () => updateProjectEmbeddingSettingsNow({ cwd, projectTrusted, route }));
|
|
14
|
+
}
|
|
15
|
+
async function updateProjectEmbeddingSettingsNow(args) {
|
|
16
|
+
if (!args.projectTrusted)
|
|
17
|
+
throw new EmbeddingsSettingsWriteError('Project settings are not trusted. Trust this project before changing .pi/settings.json.');
|
|
18
|
+
const settingsDir = join(args.cwd, '.pi');
|
|
19
|
+
const settingsPath = join(settingsDir, 'settings.json');
|
|
20
|
+
await rejectSymlink(settingsDir);
|
|
21
|
+
await mkdir(settingsDir, { recursive: true, mode: 0o700 });
|
|
22
|
+
await rejectSymlink(settingsPath);
|
|
23
|
+
let root = {};
|
|
24
|
+
let mode = 0o600;
|
|
25
|
+
try {
|
|
26
|
+
const [text, stat] = await Promise.all([readFile(settingsPath, 'utf8'), lstat(settingsPath)]);
|
|
27
|
+
const parsed = JSON.parse(text);
|
|
28
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
|
|
29
|
+
throw new EmbeddingsSettingsWriteError('Project settings must contain a JSON object.');
|
|
30
|
+
root = { ...parsed };
|
|
31
|
+
mode = stat.mode & 0o777;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (error instanceof EmbeddingsSettingsWriteError)
|
|
35
|
+
throw error;
|
|
36
|
+
const code = error.code;
|
|
37
|
+
if (code !== 'ENOENT') {
|
|
38
|
+
if (error instanceof SyntaxError)
|
|
39
|
+
throw new EmbeddingsSettingsWriteError('Project settings contain invalid JSON. Fix .pi/settings.json before changing embedding settings.');
|
|
40
|
+
throw new EmbeddingsSettingsWriteError('Could not read project settings.');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const current = root[EMBEDDINGS_SETTINGS_KEY];
|
|
44
|
+
if (current !== undefined && (typeof current !== 'object' || current === null || Array.isArray(current)))
|
|
45
|
+
throw new EmbeddingsSettingsWriteError('pi-embeddings settings must contain a JSON object.');
|
|
46
|
+
root[EMBEDDINGS_SETTINGS_KEY] = { ...(current ?? {}), default: args.route };
|
|
47
|
+
const tempPath = join(settingsDir, `.settings.json.pi-embeddings-${randomUUID()}`);
|
|
48
|
+
let handle;
|
|
49
|
+
let created = false;
|
|
50
|
+
try {
|
|
51
|
+
handle = await open(tempPath, 'wx', mode);
|
|
52
|
+
created = true;
|
|
53
|
+
await handle.writeFile(`${JSON.stringify(root, null, 2)}\n`, 'utf8');
|
|
54
|
+
await handle.close();
|
|
55
|
+
handle = undefined;
|
|
56
|
+
await rename(tempPath, settingsPath);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
if (handle)
|
|
60
|
+
await handle.close().catch(() => undefined);
|
|
61
|
+
if (created)
|
|
62
|
+
await unlink(tempPath).catch(() => undefined);
|
|
63
|
+
throw new EmbeddingsSettingsWriteError('Could not update project settings.');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function rejectSymlink(path) {
|
|
67
|
+
try {
|
|
68
|
+
if ((await lstat(path)).isSymbolicLink())
|
|
69
|
+
throw new EmbeddingsSettingsWriteError('The project settings path must not be a symbolic link.');
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (error instanceof EmbeddingsSettingsWriteError)
|
|
73
|
+
throw error;
|
|
74
|
+
if (error.code !== 'ENOENT')
|
|
75
|
+
throw new EmbeddingsSettingsWriteError('Could not inspect project settings.');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type EmbeddingRoute, type EmbeddingSettings } from './schemas.js';
|
|
2
|
+
export declare const isEmbeddingSettings: (value: unknown) => value is EmbeddingSettings;
|
|
3
|
+
/** Validate the whole settings object before any route is resolved or inference is attempted. */
|
|
4
|
+
export declare function validateEmbeddingSettings(value: unknown): EmbeddingSettings;
|
|
5
|
+
/** Shared precedence: global < agent config < explicitly trusted project. */
|
|
6
|
+
export declare function loadEmbeddingSettings(cwd: string, projectTrusted?: boolean): EmbeddingSettings;
|
|
7
|
+
export declare const configuredDefault: (settings: EmbeddingSettings) => EmbeddingRoute;
|
|
8
|
+
export declare const configuredRoutes: (settings: EmbeddingSettings, kind: "fallback" | "compare") => readonly EmbeddingRoute[];
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { loadPiSettings, resolveConfigDir } from '@amaster.ai/pi-shared/settings';
|
|
5
|
+
import { Value } from 'typebox/value';
|
|
6
|
+
import { EmbeddingsError } from './errors.js';
|
|
7
|
+
import { EMBEDDINGS_SETTINGS_KEY, GATEWAY_EMBEDDING_MODELS, embeddingSettingsSchema, } from './schemas.js';
|
|
8
|
+
const MODELS_BY_PROVIDER = {
|
|
9
|
+
local: ['embeddinggemma-2'],
|
|
10
|
+
openai: ['text-embedding-3-small'],
|
|
11
|
+
sarvam: ['embeddinggemma-2'],
|
|
12
|
+
gateway: GATEWAY_EMBEDDING_MODELS,
|
|
13
|
+
};
|
|
14
|
+
export const isEmbeddingSettings = (value) => Value.Check(embeddingSettingsSchema, value);
|
|
15
|
+
function configuration(message) {
|
|
16
|
+
throw new EmbeddingsError(message);
|
|
17
|
+
}
|
|
18
|
+
function assertRoute(value, location) {
|
|
19
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
20
|
+
return configuration('configuration-invalid');
|
|
21
|
+
const record = value;
|
|
22
|
+
const provider = record.provider;
|
|
23
|
+
const model = record.model;
|
|
24
|
+
if (typeof provider !== 'string' || typeof model !== 'string' || model.length === 0)
|
|
25
|
+
return configuration('configuration-invalid');
|
|
26
|
+
if (!Object.hasOwn(MODELS_BY_PROVIDER, provider))
|
|
27
|
+
return configuration('configuration-invalid');
|
|
28
|
+
const allowed = MODELS_BY_PROVIDER[provider];
|
|
29
|
+
if (allowed === undefined || !allowed.includes(model))
|
|
30
|
+
return configuration('configuration-invalid');
|
|
31
|
+
return { provider: provider, model };
|
|
32
|
+
}
|
|
33
|
+
/** Validate the whole settings object before any route is resolved or inference is attempted. */
|
|
34
|
+
export function validateEmbeddingSettings(value) {
|
|
35
|
+
if (!isEmbeddingSettings(value))
|
|
36
|
+
return configuration('configuration-invalid');
|
|
37
|
+
assertRoute(value.default, 'default');
|
|
38
|
+
for (const [index, route] of (value.fallback ?? []).entries())
|
|
39
|
+
assertRoute(route, `fallback[${index}]`);
|
|
40
|
+
for (const [index, route] of (value.compare ?? []).entries())
|
|
41
|
+
assertRoute(route, `compare[${index}]`);
|
|
42
|
+
if (value.version !== undefined && value.version !== 1)
|
|
43
|
+
return configuration('configuration-invalid');
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
function validateSettingsLayer(path) {
|
|
47
|
+
let text;
|
|
48
|
+
try {
|
|
49
|
+
text = readFileSync(path, 'utf8');
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error.code === 'ENOENT')
|
|
53
|
+
return;
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
if (text.charCodeAt(0) === 0xfeff)
|
|
57
|
+
return configuration('configuration-invalid');
|
|
58
|
+
const root = JSON.parse(text);
|
|
59
|
+
if (typeof root !== 'object' ||
|
|
60
|
+
root === null ||
|
|
61
|
+
Array.isArray(root) ||
|
|
62
|
+
(Object.hasOwn(root, EMBEDDINGS_SETTINGS_KEY) &&
|
|
63
|
+
(typeof root[EMBEDDINGS_SETTINGS_KEY] !== 'object' ||
|
|
64
|
+
root[EMBEDDINGS_SETTINGS_KEY] === null ||
|
|
65
|
+
Array.isArray(root[EMBEDDINGS_SETTINGS_KEY]))))
|
|
66
|
+
return configuration('configuration-invalid');
|
|
67
|
+
}
|
|
68
|
+
/** Shared precedence: global < agent config < explicitly trusted project. */
|
|
69
|
+
export function loadEmbeddingSettings(cwd, projectTrusted = false) {
|
|
70
|
+
try {
|
|
71
|
+
const paths = new Set([
|
|
72
|
+
join(resolveConfigDir(join(homedir(), '.pi', 'agent')), 'settings.json'),
|
|
73
|
+
join(resolveConfigDir(), 'settings.json'),
|
|
74
|
+
...(projectTrusted ? [join(resolve(cwd), '.pi', 'settings.json')] : []),
|
|
75
|
+
]);
|
|
76
|
+
for (const path of paths) {
|
|
77
|
+
statSync(path, { throwIfNoEntry: false });
|
|
78
|
+
validateSettingsLayer(path);
|
|
79
|
+
}
|
|
80
|
+
const raw = loadPiSettings(EMBEDDINGS_SETTINGS_KEY, {
|
|
81
|
+
cwd,
|
|
82
|
+
projectTrusted,
|
|
83
|
+
strictProjectSettings: true,
|
|
84
|
+
});
|
|
85
|
+
return validateEmbeddingSettings(raw);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (error instanceof EmbeddingsError)
|
|
89
|
+
throw error;
|
|
90
|
+
return configuration('configuration-invalid');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export const configuredDefault = (settings) => assertRoute(settings.default, 'default');
|
|
94
|
+
export const configuredRoutes = (settings, kind) => {
|
|
95
|
+
const raw = kind === 'fallback' ? settings.fallback : settings.compare;
|
|
96
|
+
return (raw ?? []).map((route, index) => assertRoute(route, `${kind}[${index}]`));
|
|
97
|
+
};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { Type } from 'typebox';
|
|
2
|
+
export declare const EMBED_TOOL = "embed";
|
|
3
|
+
export declare const EMBED_COMPARE_TOOL = "embed_compare";
|
|
4
|
+
export declare const EMBEDDINGS_DESCRIBE_TOOL = "embeddings_describe";
|
|
5
|
+
export declare const EMBED_TOOL_DESCRIPTION = "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.";
|
|
6
|
+
export declare const EMBED_COMPARE_TOOL_DESCRIPTION = "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.";
|
|
7
|
+
export declare const EMBEDDINGS_DESCRIBE_TOOL_DESCRIPTION = "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.";
|
|
8
|
+
export declare const embedParameters: Type.TObject<{
|
|
9
|
+
inputs: Type.TArray<Type.TString>;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const embedCompareParameters: Type.TObject<{
|
|
12
|
+
inputs: Type.TArray<Type.TString>;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const embeddingsDescribeParameters: Type.TObject<{}>;
|
|
15
|
+
export declare const embedOutput: Type.TObject<{
|
|
16
|
+
schemaVersion: Type.TLiteral<1>;
|
|
17
|
+
outcomes: Type.TArray<Type.TUnion<[Type.TObject<{
|
|
18
|
+
status: Type.TLiteral<"success">;
|
|
19
|
+
index: Type.TInteger;
|
|
20
|
+
vector: Type.TArray<Type.TNumber>;
|
|
21
|
+
route: Type.TUnion<[Type.TLiteral<"local">, Type.TLiteral<"openai">, Type.TLiteral<"sarvam">, Type.TLiteral<"gateway">]>;
|
|
22
|
+
model: Type.TString;
|
|
23
|
+
space: Type.TUnion<[Type.TObject<{
|
|
24
|
+
provider: Type.TLiteral<"local">;
|
|
25
|
+
model: Type.TLiteral<"embeddinggemma-2">;
|
|
26
|
+
revision: Type.TString;
|
|
27
|
+
quantization: Type.TLiteral<"Q8_0">;
|
|
28
|
+
runtime: Type.TString;
|
|
29
|
+
dimensions: Type.TLiteral<768>;
|
|
30
|
+
format: Type.TLiteral<"host-display-attributes-v1">;
|
|
31
|
+
prefix: Type.TLiteral<"title: none | text: ">;
|
|
32
|
+
normalization: Type.TLiteral<"finite-nonzero-l2-v1">;
|
|
33
|
+
}>, Type.TObject<{
|
|
34
|
+
provider: Type.TLiteral<"openai">;
|
|
35
|
+
model: Type.TLiteral<"text-embedding-3-small">;
|
|
36
|
+
revision: Type.TNull;
|
|
37
|
+
quantization: Type.TNull;
|
|
38
|
+
runtime: Type.TNull;
|
|
39
|
+
dimensions: Type.TLiteral<1536>;
|
|
40
|
+
format: Type.TLiteral<"host-display-attributes-v1">;
|
|
41
|
+
prefix: Type.TLiteral<"title: none | text: ">;
|
|
42
|
+
normalization: Type.TLiteral<"finite-nonzero-l2-v1">;
|
|
43
|
+
}>, Type.TObject<{
|
|
44
|
+
provider: Type.TLiteral<"sarvam">;
|
|
45
|
+
model: Type.TLiteral<"embeddinggemma-2">;
|
|
46
|
+
revision: Type.TNull;
|
|
47
|
+
quantization: Type.TNull;
|
|
48
|
+
runtime: Type.TLiteral<"sarvam-v2">;
|
|
49
|
+
dimensions: Type.TLiteral<768>;
|
|
50
|
+
format: Type.TLiteral<"host-display-attributes-v1">;
|
|
51
|
+
prefix: Type.TLiteral<"title: none | text: ">;
|
|
52
|
+
normalization: Type.TLiteral<"finite-nonzero-l2-v1">;
|
|
53
|
+
}>]>;
|
|
54
|
+
attemptId: Type.TString;
|
|
55
|
+
normalization: Type.TLiteral<"finite-nonzero-l2-v1">;
|
|
56
|
+
}>, Type.TObject<{
|
|
57
|
+
status: Type.TLiteral<"error">;
|
|
58
|
+
index: Type.TInteger;
|
|
59
|
+
code: Type.TUnion<[Type.TLiteral<"configuration-invalid">, Type.TLiteral<"route-unconfigured">, Type.TLiteral<"missing-credentials">, Type.TLiteral<"http-auth">, Type.TLiteral<"http-not-found">, Type.TLiteral<"http-rate-limit">, Type.TLiteral<"http-forbidden">, Type.TLiteral<"http-bad-request">, Type.TLiteral<"http-server-error">, Type.TLiteral<"transport-failed">, Type.TLiteral<"provider-response-invalid">, Type.TLiteral<"provider-response-mismatch">, Type.TLiteral<"vector-invalid">, Type.TLiteral<"vector-zero">, Type.TLiteral<"input-empty">, Type.TLiteral<"input-too-long">, Type.TLiteral<"tokenizer-roundtrip-failed">, Type.TLiteral<"attribution-unavailable">, Type.TLiteral<"local-resources-unavailable">, Type.TLiteral<"local-model-mismatch">, Type.TLiteral<"local-runtime-mismatch">, Type.TLiteral<"local-startup-failed">, Type.TLiteral<"local-cpu-startup-invalid">, Type.TLiteral<"cancelled">, Type.TLiteral<"unstarted">]>;
|
|
60
|
+
attemptId: Type.TUnion<[Type.TString, Type.TNull]>;
|
|
61
|
+
}>]>>;
|
|
62
|
+
attempts: Type.TArray<Type.TObject<{
|
|
63
|
+
id: Type.TString;
|
|
64
|
+
route: Type.TUnion<[Type.TLiteral<"local">, Type.TLiteral<"openai">, Type.TLiteral<"sarvam">, Type.TLiteral<"gateway">]>;
|
|
65
|
+
model: Type.TString;
|
|
66
|
+
routeIndex: Type.TInteger;
|
|
67
|
+
status: Type.TUnion<[Type.TLiteral<"success">, Type.TLiteral<"error">, Type.TLiteral<"cancelled">]>;
|
|
68
|
+
usage: Type.TUnion<[Type.TObject<{
|
|
69
|
+
providerReportedInputTokens: Type.TUnion<[Type.TInteger, Type.TNull]>;
|
|
70
|
+
preparedInputTokens: Type.TUnion<[Type.TInteger, Type.TNull]>;
|
|
71
|
+
billedTokens: Type.TUnion<[Type.TInteger, Type.TNull]>;
|
|
72
|
+
}>, Type.TNull]>;
|
|
73
|
+
errorCode: Type.TOptional<Type.TUnion<[Type.TLiteral<"configuration-invalid">, Type.TLiteral<"route-unconfigured">, Type.TLiteral<"missing-credentials">, Type.TLiteral<"http-auth">, Type.TLiteral<"http-not-found">, Type.TLiteral<"http-rate-limit">, Type.TLiteral<"http-forbidden">, Type.TLiteral<"http-bad-request">, Type.TLiteral<"http-server-error">, Type.TLiteral<"transport-failed">, Type.TLiteral<"provider-response-invalid">, Type.TLiteral<"provider-response-mismatch">, Type.TLiteral<"vector-invalid">, Type.TLiteral<"vector-zero">, Type.TLiteral<"input-empty">, Type.TLiteral<"input-too-long">, Type.TLiteral<"tokenizer-roundtrip-failed">, Type.TLiteral<"attribution-unavailable">, Type.TLiteral<"local-resources-unavailable">, Type.TLiteral<"local-model-mismatch">, Type.TLiteral<"local-runtime-mismatch">, Type.TLiteral<"local-startup-failed">, Type.TLiteral<"local-cpu-startup-invalid">, Type.TLiteral<"cancelled">, Type.TLiteral<"unstarted">]>>;
|
|
74
|
+
}>>;
|
|
75
|
+
}>;
|
|
76
|
+
export declare const embedCompareOutput: Type.TObject<{
|
|
77
|
+
schemaVersion: Type.TLiteral<1>;
|
|
78
|
+
entries: Type.TArray<Type.TObject<{
|
|
79
|
+
route: Type.TUnion<[Type.TLiteral<"local">, Type.TLiteral<"openai">, Type.TLiteral<"sarvam">, Type.TLiteral<"gateway">]>;
|
|
80
|
+
model: Type.TString;
|
|
81
|
+
status: Type.TUnion<[Type.TLiteral<"success">, Type.TLiteral<"error">, Type.TLiteral<"cancelled">]>;
|
|
82
|
+
result: Type.TObject<{
|
|
83
|
+
schemaVersion: Type.TLiteral<1>;
|
|
84
|
+
outcomes: Type.TArray<Type.TUnion<[Type.TObject<{
|
|
85
|
+
status: Type.TLiteral<"success">;
|
|
86
|
+
index: Type.TInteger;
|
|
87
|
+
vector: Type.TArray<Type.TNumber>;
|
|
88
|
+
route: Type.TUnion<[Type.TLiteral<"local">, Type.TLiteral<"openai">, Type.TLiteral<"sarvam">, Type.TLiteral<"gateway">]>;
|
|
89
|
+
model: Type.TString;
|
|
90
|
+
space: Type.TUnion<[Type.TObject<{
|
|
91
|
+
provider: Type.TLiteral<"local">;
|
|
92
|
+
model: Type.TLiteral<"embeddinggemma-2">;
|
|
93
|
+
revision: Type.TString;
|
|
94
|
+
quantization: Type.TLiteral<"Q8_0">;
|
|
95
|
+
runtime: Type.TString;
|
|
96
|
+
dimensions: Type.TLiteral<768>;
|
|
97
|
+
format: Type.TLiteral<"host-display-attributes-v1">;
|
|
98
|
+
prefix: Type.TLiteral<"title: none | text: ">;
|
|
99
|
+
normalization: Type.TLiteral<"finite-nonzero-l2-v1">;
|
|
100
|
+
}>, Type.TObject<{
|
|
101
|
+
provider: Type.TLiteral<"openai">;
|
|
102
|
+
model: Type.TLiteral<"text-embedding-3-small">;
|
|
103
|
+
revision: Type.TNull;
|
|
104
|
+
quantization: Type.TNull;
|
|
105
|
+
runtime: Type.TNull;
|
|
106
|
+
dimensions: Type.TLiteral<1536>;
|
|
107
|
+
format: Type.TLiteral<"host-display-attributes-v1">;
|
|
108
|
+
prefix: Type.TLiteral<"title: none | text: ">;
|
|
109
|
+
normalization: Type.TLiteral<"finite-nonzero-l2-v1">;
|
|
110
|
+
}>, Type.TObject<{
|
|
111
|
+
provider: Type.TLiteral<"sarvam">;
|
|
112
|
+
model: Type.TLiteral<"embeddinggemma-2">;
|
|
113
|
+
revision: Type.TNull;
|
|
114
|
+
quantization: Type.TNull;
|
|
115
|
+
runtime: Type.TLiteral<"sarvam-v2">;
|
|
116
|
+
dimensions: Type.TLiteral<768>;
|
|
117
|
+
format: Type.TLiteral<"host-display-attributes-v1">;
|
|
118
|
+
prefix: Type.TLiteral<"title: none | text: ">;
|
|
119
|
+
normalization: Type.TLiteral<"finite-nonzero-l2-v1">;
|
|
120
|
+
}>]>;
|
|
121
|
+
attemptId: Type.TString;
|
|
122
|
+
normalization: Type.TLiteral<"finite-nonzero-l2-v1">;
|
|
123
|
+
}>, Type.TObject<{
|
|
124
|
+
status: Type.TLiteral<"error">;
|
|
125
|
+
index: Type.TInteger;
|
|
126
|
+
code: Type.TUnion<[Type.TLiteral<"configuration-invalid">, Type.TLiteral<"route-unconfigured">, Type.TLiteral<"missing-credentials">, Type.TLiteral<"http-auth">, Type.TLiteral<"http-not-found">, Type.TLiteral<"http-rate-limit">, Type.TLiteral<"http-forbidden">, Type.TLiteral<"http-bad-request">, Type.TLiteral<"http-server-error">, Type.TLiteral<"transport-failed">, Type.TLiteral<"provider-response-invalid">, Type.TLiteral<"provider-response-mismatch">, Type.TLiteral<"vector-invalid">, Type.TLiteral<"vector-zero">, Type.TLiteral<"input-empty">, Type.TLiteral<"input-too-long">, Type.TLiteral<"tokenizer-roundtrip-failed">, Type.TLiteral<"attribution-unavailable">, Type.TLiteral<"local-resources-unavailable">, Type.TLiteral<"local-model-mismatch">, Type.TLiteral<"local-runtime-mismatch">, Type.TLiteral<"local-startup-failed">, Type.TLiteral<"local-cpu-startup-invalid">, Type.TLiteral<"cancelled">, Type.TLiteral<"unstarted">]>;
|
|
127
|
+
attemptId: Type.TUnion<[Type.TString, Type.TNull]>;
|
|
128
|
+
}>]>>;
|
|
129
|
+
attempts: Type.TArray<Type.TObject<{
|
|
130
|
+
id: Type.TString;
|
|
131
|
+
route: Type.TUnion<[Type.TLiteral<"local">, Type.TLiteral<"openai">, Type.TLiteral<"sarvam">, Type.TLiteral<"gateway">]>;
|
|
132
|
+
model: Type.TString;
|
|
133
|
+
routeIndex: Type.TInteger;
|
|
134
|
+
status: Type.TUnion<[Type.TLiteral<"success">, Type.TLiteral<"error">, Type.TLiteral<"cancelled">]>;
|
|
135
|
+
usage: Type.TUnion<[Type.TObject<{
|
|
136
|
+
providerReportedInputTokens: Type.TUnion<[Type.TInteger, Type.TNull]>;
|
|
137
|
+
preparedInputTokens: Type.TUnion<[Type.TInteger, Type.TNull]>;
|
|
138
|
+
billedTokens: Type.TUnion<[Type.TInteger, Type.TNull]>;
|
|
139
|
+
}>, Type.TNull]>;
|
|
140
|
+
errorCode: Type.TOptional<Type.TUnion<[Type.TLiteral<"configuration-invalid">, Type.TLiteral<"route-unconfigured">, Type.TLiteral<"missing-credentials">, Type.TLiteral<"http-auth">, Type.TLiteral<"http-not-found">, Type.TLiteral<"http-rate-limit">, Type.TLiteral<"http-forbidden">, Type.TLiteral<"http-bad-request">, Type.TLiteral<"http-server-error">, Type.TLiteral<"transport-failed">, Type.TLiteral<"provider-response-invalid">, Type.TLiteral<"provider-response-mismatch">, Type.TLiteral<"vector-invalid">, Type.TLiteral<"vector-zero">, Type.TLiteral<"input-empty">, Type.TLiteral<"input-too-long">, Type.TLiteral<"tokenizer-roundtrip-failed">, Type.TLiteral<"attribution-unavailable">, Type.TLiteral<"local-resources-unavailable">, Type.TLiteral<"local-model-mismatch">, Type.TLiteral<"local-runtime-mismatch">, Type.TLiteral<"local-startup-failed">, Type.TLiteral<"local-cpu-startup-invalid">, Type.TLiteral<"cancelled">, Type.TLiteral<"unstarted">]>>;
|
|
141
|
+
}>>;
|
|
142
|
+
}>;
|
|
143
|
+
}>>;
|
|
144
|
+
}>;
|
|
145
|
+
export declare const embeddingsDescribeOutput: Type.TObject<{
|
|
146
|
+
schemaVersion: Type.TLiteral<1>;
|
|
147
|
+
ready: Type.TBoolean;
|
|
148
|
+
selected: Type.TObject<{
|
|
149
|
+
provider: Type.TUnion<[Type.TLiteral<"local">, Type.TLiteral<"openai">, Type.TLiteral<"sarvam">, Type.TLiteral<"gateway">]>;
|
|
150
|
+
model: Type.TString;
|
|
151
|
+
}>;
|
|
152
|
+
space: Type.TUnion<[Type.TUnion<[Type.TObject<{
|
|
153
|
+
provider: Type.TLiteral<"local">;
|
|
154
|
+
model: Type.TLiteral<"embeddinggemma-2">;
|
|
155
|
+
revision: Type.TString;
|
|
156
|
+
quantization: Type.TLiteral<"Q8_0">;
|
|
157
|
+
runtime: Type.TString;
|
|
158
|
+
dimensions: Type.TLiteral<768>;
|
|
159
|
+
format: Type.TLiteral<"host-display-attributes-v1">;
|
|
160
|
+
prefix: Type.TLiteral<"title: none | text: ">;
|
|
161
|
+
normalization: Type.TLiteral<"finite-nonzero-l2-v1">;
|
|
162
|
+
}>, Type.TObject<{
|
|
163
|
+
provider: Type.TLiteral<"openai">;
|
|
164
|
+
model: Type.TLiteral<"text-embedding-3-small">;
|
|
165
|
+
revision: Type.TNull;
|
|
166
|
+
quantization: Type.TNull;
|
|
167
|
+
runtime: Type.TNull;
|
|
168
|
+
dimensions: Type.TLiteral<1536>;
|
|
169
|
+
format: Type.TLiteral<"host-display-attributes-v1">;
|
|
170
|
+
prefix: Type.TLiteral<"title: none | text: ">;
|
|
171
|
+
normalization: Type.TLiteral<"finite-nonzero-l2-v1">;
|
|
172
|
+
}>, Type.TObject<{
|
|
173
|
+
provider: Type.TLiteral<"sarvam">;
|
|
174
|
+
model: Type.TLiteral<"embeddinggemma-2">;
|
|
175
|
+
revision: Type.TNull;
|
|
176
|
+
quantization: Type.TNull;
|
|
177
|
+
runtime: Type.TLiteral<"sarvam-v2">;
|
|
178
|
+
dimensions: Type.TLiteral<768>;
|
|
179
|
+
format: Type.TLiteral<"host-display-attributes-v1">;
|
|
180
|
+
prefix: Type.TLiteral<"title: none | text: ">;
|
|
181
|
+
normalization: Type.TLiteral<"finite-nonzero-l2-v1">;
|
|
182
|
+
}>]>, Type.TNull]>;
|
|
183
|
+
default: Type.TObject<{
|
|
184
|
+
provider: Type.TUnion<[Type.TLiteral<"local">, Type.TLiteral<"openai">, Type.TLiteral<"sarvam">, Type.TLiteral<"gateway">]>;
|
|
185
|
+
model: Type.TString;
|
|
186
|
+
}>;
|
|
187
|
+
fallback: Type.TArray<Type.TObject<{
|
|
188
|
+
provider: Type.TUnion<[Type.TLiteral<"local">, Type.TLiteral<"openai">, Type.TLiteral<"sarvam">, Type.TLiteral<"gateway">]>;
|
|
189
|
+
model: Type.TString;
|
|
190
|
+
}>>;
|
|
191
|
+
compare: Type.TArray<Type.TObject<{
|
|
192
|
+
provider: Type.TUnion<[Type.TLiteral<"local">, Type.TLiteral<"openai">, Type.TLiteral<"sarvam">, Type.TLiteral<"gateway">]>;
|
|
193
|
+
model: Type.TString;
|
|
194
|
+
}>>;
|
|
195
|
+
diagnostics: Type.TArray<Type.TObject<{
|
|
196
|
+
code: Type.TString;
|
|
197
|
+
severity: Type.TUnion<[Type.TLiteral<"error">, Type.TLiteral<"warning">, Type.TLiteral<"info">]>;
|
|
198
|
+
}>>;
|
|
199
|
+
}>;
|
|
200
|
+
export declare const EMBEDDINGS_TOOL_NAMES: readonly ["embed", "embed_compare", "embeddings_describe"];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Type } from 'typebox';
|
|
2
|
+
import { embeddingDescribeSchema, embeddingCompareResultSchema, embeddingRequestSchema, embeddingResultSchema, } from './schemas.js';
|
|
3
|
+
export const EMBED_TOOL = 'embed';
|
|
4
|
+
export const EMBED_COMPARE_TOOL = 'embed_compare';
|
|
5
|
+
export const EMBEDDINGS_DESCRIBE_TOOL = 'embeddings_describe';
|
|
6
|
+
export const EMBED_TOOL_DESCRIPTION = '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.';
|
|
7
|
+
export const EMBED_COMPARE_TOOL_DESCRIPTION = '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.';
|
|
8
|
+
export const EMBEDDINGS_DESCRIBE_TOOL_DESCRIPTION = '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.';
|
|
9
|
+
export const embedParameters = embeddingRequestSchema;
|
|
10
|
+
export const embedCompareParameters = embeddingRequestSchema;
|
|
11
|
+
export const embeddingsDescribeParameters = Type.Object({}, { additionalProperties: false });
|
|
12
|
+
export const embedOutput = embeddingResultSchema;
|
|
13
|
+
export const embedCompareOutput = embeddingCompareResultSchema;
|
|
14
|
+
export const embeddingsDescribeOutput = embeddingDescribeSchema;
|
|
15
|
+
export const EMBEDDINGS_TOOL_NAMES = [
|
|
16
|
+
EMBED_TOOL,
|
|
17
|
+
EMBED_COMPARE_TOOL,
|
|
18
|
+
EMBEDDINGS_DESCRIBE_TOOL,
|
|
19
|
+
];
|