crewx-pi-kit 0.1.17 → 0.1.18
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import type { ExtensionAPI, ProviderConfig } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import type { ExtensionAPI, ProviderConfig, ProviderModelConfig } from '@earendil-works/pi-coding-agent';
|
|
3
3
|
import { openAICompletionsApi } from '@earendil-works/pi-ai/compat';
|
|
4
4
|
|
|
5
5
|
// Pi's production extension loader aliases the package root and selected
|
|
@@ -25,8 +25,31 @@ export function managedModelConfiguration(environment: NodeJS.ProcessEnv): { bas
|
|
|
25
25
|
return { baseUrl, token };
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export function
|
|
28
|
+
export function managedModelDefinition(encoded: string | undefined): ProviderModelConfig | undefined {
|
|
29
|
+
if (encoded === undefined) return undefined; // Older servers retain the installed catalog.
|
|
30
|
+
if (encoded.length > 4096) throw new Error('Invalid CrewX model definition.');
|
|
31
|
+
const value = JSON.parse(encoded);
|
|
32
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) ||
|
|
33
|
+
typeof value.id !== 'string' || value.id.length > 200 ||
|
|
34
|
+
!/^[A-Za-z0-9][A-Za-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9_.:-]*$/.test(value.id) ||
|
|
35
|
+
typeof value.name !== 'string' || !value.name || value.name.length > 300 ||
|
|
36
|
+
typeof value.reasoning !== 'boolean' || !Array.isArray(value.input) ||
|
|
37
|
+
!value.input.includes('text') || value.input.some((input: unknown) => input !== 'text' && input !== 'image') ||
|
|
38
|
+
!Number.isInteger(value.contextWindow) || value.contextWindow < 4096 || value.contextWindow > 128000 ||
|
|
39
|
+
!Number.isInteger(value.maxTokens) || value.maxTokens < 1 || value.maxTokens > 16384) {
|
|
40
|
+
throw new Error('Invalid CrewX model definition.');
|
|
41
|
+
}
|
|
42
|
+
// Never accept URLs, headers, credentials, commands or arbitrary compatibility options from a definition.
|
|
43
|
+
return { id: value.id, name: value.name, reasoning: value.reasoning, input: [...new Set(value.input)] as ('text' | 'image')[],
|
|
44
|
+
contextWindow: value.contextWindow, maxTokens: Math.min(value.maxTokens, value.contextWindow),
|
|
45
|
+
api: 'openai-completions', compat: { thinkingFormat: 'openrouter' },
|
|
46
|
+
// Runtime estimates are not billing authority. The server quotes and meters the exact endpoint.
|
|
47
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function managedModelProvider(configuration: { baseUrl: string; token: string }, definition?: ProviderModelConfig): ProviderConfig {
|
|
29
51
|
return {
|
|
52
|
+
...(definition ? { models: [definition] } : {}),
|
|
30
53
|
baseUrl: configuration.baseUrl,
|
|
31
54
|
apiKey: '$CREWX_MODEL_TOKEN',
|
|
32
55
|
api: 'openai-completions',
|
|
@@ -59,5 +82,5 @@ export function managedModelProvider(configuration: { baseUrl: string; token: st
|
|
|
59
82
|
|
|
60
83
|
export default function managedInference(pi: ExtensionAPI): void {
|
|
61
84
|
const configuration = managedModelConfiguration(process.env);
|
|
62
|
-
if (configuration) pi.registerProvider('openrouter', managedModelProvider(configuration));
|
|
85
|
+
if (configuration) pi.registerProvider('openrouter', managedModelProvider(configuration, managedModelDefinition(process.env.CREWX_MODEL_DEFINITION)));
|
|
63
86
|
}
|