@mcoda/shared 0.1.101 → 0.1.102

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/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from "./qa/QaReadiness.js";
7
7
  export * from "./qa/QaTechStack.js";
8
8
  export * from "./metadata/CommandMetadata.js";
9
9
  export * from "./llm/LocalRunnerConfig.js";
10
+ export * from "./llm/GenerativeOperation.js";
10
11
  export * from "./mswarm/GenericJobContract.js";
11
12
  export * from "./mswarm/CapabilityContract.js";
12
13
  export * from "./mswarm/ArtifactSandboxContract.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,oBAAoB,EACpB,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,mBAAmB,GACpB,MAAM,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,oBAAoB,EACpB,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,mBAAmB,GACpB,MAAM,2BAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ export * from "./qa/QaReadiness.js";
7
7
  export * from "./qa/QaTechStack.js";
8
8
  export * from "./metadata/CommandMetadata.js";
9
9
  export * from "./llm/LocalRunnerConfig.js";
10
+ export * from "./llm/GenerativeOperation.js";
10
11
  export * from "./mswarm/GenericJobContract.js";
11
12
  export * from "./mswarm/CapabilityContract.js";
12
13
  export * from "./mswarm/ArtifactSandboxContract.js";
@@ -0,0 +1,50 @@
1
+ export declare const GENERATIVE_OPERATIONS: readonly ["chat.completions", "images.generations", "audio.generations"];
2
+ export type GenerativeOperation = (typeof GENERATIVE_OPERATIONS)[number];
3
+ export declare const GENERATIVE_MODALITIES: readonly ["text", "image", "audio"];
4
+ export type GenerativeModality = (typeof GENERATIVE_MODALITIES)[number];
5
+ export type GenerativeOperationPath = `/${string}`;
6
+ export type GenerativeOperationMethod = "POST";
7
+ export declare const GENERATIVE_OPERATION_DEFAULT_PATHS: Readonly<Record<GenerativeOperation, GenerativeOperationPath>>;
8
+ export declare const GENERATIVE_REQUEST_PARAMETER_ALLOWLISTS: {
9
+ readonly "chat.completions": readonly ["model", "messages", "stream", "temperature", "top_p", "max_tokens", "stop", "response_format", "tools", "tool_choice"];
10
+ readonly "images.generations": readonly ["model", "prompt", "n", "size", "response_format", "seed", "steps", "negative_prompt"];
11
+ readonly "audio.generations": readonly ["model", "prompt", "duration_seconds", "response_format", "n", "seed", "steps", "negative_prompt", "sample_rate"];
12
+ };
13
+ export type GenerativeRequestParameterByOperation = {
14
+ [Operation in GenerativeOperation]: (typeof GENERATIVE_REQUEST_PARAMETER_ALLOWLISTS)[Operation][number];
15
+ };
16
+ export type GenerativeRequestParameter<Operation extends GenerativeOperation = GenerativeOperation> = GenerativeRequestParameterByOperation[Operation];
17
+ export type GenerativeRequestParameterAllowlist<Operation extends GenerativeOperation = GenerativeOperation> = readonly GenerativeRequestParameter<Operation>[];
18
+ export declare const GENERATIVE_OPERATION_LIMIT_KEYS: readonly ["maxRequestBytes", "maxOutputBytes", "maxPromptChars", "maxNegativePromptChars", "maxN", "maxWidth", "maxHeight", "maxPixels", "minDurationSeconds", "maxDurationSeconds", "maxSampleRate", "maxSteps"];
19
+ export type GenerativeOperationLimitKey = (typeof GENERATIVE_OPERATION_LIMIT_KEYS)[number];
20
+ export interface GenerativeOperationLimits {
21
+ maxRequestBytes?: number;
22
+ maxOutputBytes?: number;
23
+ maxPromptChars?: number;
24
+ maxNegativePromptChars?: number;
25
+ maxN?: number;
26
+ maxWidth?: number;
27
+ maxHeight?: number;
28
+ maxPixels?: number;
29
+ minDurationSeconds?: number;
30
+ maxDurationSeconds?: number;
31
+ maxSampleRate?: number;
32
+ maxSteps?: number;
33
+ }
34
+ export interface SelfHostedGenerativeOperation<Operation extends GenerativeOperation = GenerativeOperation> {
35
+ operation: Operation;
36
+ path: GenerativeOperationPath;
37
+ method?: GenerativeOperationMethod;
38
+ requestParameterAllowlist?: GenerativeRequestParameterAllowlist<Operation>;
39
+ responseFormats?: readonly string[];
40
+ outputMimeTypes?: readonly string[];
41
+ limits?: GenerativeOperationLimits;
42
+ }
43
+ export type GenerativeOperationDescriptor<Operation extends GenerativeOperation = GenerativeOperation> = SelfHostedGenerativeOperation<Operation>;
44
+ export declare function normalizeGenerativeOperation(value: unknown): GenerativeOperation | undefined;
45
+ export declare function normalizeGenerativeModality(value: unknown): GenerativeModality | undefined;
46
+ export declare function normalizeGenerativeModalities(value: unknown): GenerativeModality[] | undefined;
47
+ export declare function isGenerativeOperationPath(value: unknown): value is GenerativeOperationPath;
48
+ export declare function normalizeGenerativeOperationPath(value: unknown): GenerativeOperationPath | undefined;
49
+ export declare function normalizeSelfHostedGenerativeOperation(value: unknown): SelfHostedGenerativeOperation | undefined;
50
+ //# sourceMappingURL=GenerativeOperation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenerativeOperation.d.ts","sourceRoot":"","sources":["../../src/llm/GenerativeOperation.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,0EAIxB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzE,eAAO,MAAM,qBAAqB,q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C5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,6BAA6B,CAC5C,SAAS,SAAS,mBAAmB,GAAG,mBAAmB;IAE3D,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,EAAE,uBAAuB,CAAC;IAC9B,MAAM,CAAC,EAAE,yBAAyB,CAAC;IACnC,yBAAyB,CAAC,EAAE,mCAAmC,CAAC,SAAS,CAAC,CAAC;IAC3E,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,MAAM,CAAC,EAAE,yBAAyB,CAAC;CACpC;AAED,MAAM,MAAM,6BAA6B,CACvC,SAAS,SAAS,mBAAmB,GAAG,mBAAmB,IACzD,6BAA6B,CAAC,SAAS,CAAC,CAAC;AAsD7C,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,GAAG,SAAS,CAG5F;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,kBAAkB,GAAG,SAAS,CAG1F;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,OAAO,GACb,kBAAkB,EAAE,GAAG,SAAS,CAUlC;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,uBAAuB,CAc1F;AAED,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,OAAO,GACb,uBAAuB,GAAG,SAAS,CAErC;AAmFD,wBAAgB,sCAAsC,CACpD,KAAK,EAAE,OAAO,GACb,6BAA6B,GAAG,SAAS,CA6C3C"}
@@ -0,0 +1,238 @@
1
+ export const GENERATIVE_OPERATIONS = [
2
+ "chat.completions",
3
+ "images.generations",
4
+ "audio.generations",
5
+ ];
6
+ export const GENERATIVE_MODALITIES = ["text", "image", "audio"];
7
+ export const GENERATIVE_OPERATION_DEFAULT_PATHS = {
8
+ "chat.completions": "/v1/chat/completions",
9
+ "images.generations": "/v1/images/generations",
10
+ "audio.generations": "/v1/audio/generations",
11
+ };
12
+ export const GENERATIVE_REQUEST_PARAMETER_ALLOWLISTS = {
13
+ "chat.completions": [
14
+ "model",
15
+ "messages",
16
+ "stream",
17
+ "temperature",
18
+ "top_p",
19
+ "max_tokens",
20
+ "stop",
21
+ "response_format",
22
+ "tools",
23
+ "tool_choice",
24
+ ],
25
+ "images.generations": [
26
+ "model",
27
+ "prompt",
28
+ "n",
29
+ "size",
30
+ "response_format",
31
+ "seed",
32
+ "steps",
33
+ "negative_prompt",
34
+ ],
35
+ "audio.generations": [
36
+ "model",
37
+ "prompt",
38
+ "duration_seconds",
39
+ "response_format",
40
+ "n",
41
+ "seed",
42
+ "steps",
43
+ "negative_prompt",
44
+ "sample_rate",
45
+ ],
46
+ };
47
+ export const GENERATIVE_OPERATION_LIMIT_KEYS = [
48
+ "maxRequestBytes",
49
+ "maxOutputBytes",
50
+ "maxPromptChars",
51
+ "maxNegativePromptChars",
52
+ "maxN",
53
+ "maxWidth",
54
+ "maxHeight",
55
+ "maxPixels",
56
+ "minDurationSeconds",
57
+ "maxDurationSeconds",
58
+ "maxSampleRate",
59
+ "maxSteps",
60
+ ];
61
+ const OPERATION_ALIASES = {
62
+ chat: "chat.completions",
63
+ "chat.completion": "chat.completions",
64
+ "chat.completions": "chat.completions",
65
+ "chat-completion": "chat.completions",
66
+ "chat-completions": "chat.completions",
67
+ "/v1/chat/completions": "chat.completions",
68
+ image: "images.generations",
69
+ images: "images.generations",
70
+ "image.generation": "images.generations",
71
+ "image.generations": "images.generations",
72
+ "images.generation": "images.generations",
73
+ "images.generations": "images.generations",
74
+ "image-generation": "images.generations",
75
+ "image-generations": "images.generations",
76
+ "/v1/images/generations": "images.generations",
77
+ audio: "audio.generations",
78
+ "audio.generation": "audio.generations",
79
+ "audio.generations": "audio.generations",
80
+ "audio-generation": "audio.generations",
81
+ "audio-generations": "audio.generations",
82
+ "/v1/audio/generations": "audio.generations",
83
+ };
84
+ const MODALITY_ALIASES = {
85
+ text: "text",
86
+ chat: "text",
87
+ image: "image",
88
+ images: "image",
89
+ audio: "audio",
90
+ };
91
+ const REQUEST_PARAMETER_SETS = {
92
+ "chat.completions": new Set(GENERATIVE_REQUEST_PARAMETER_ALLOWLISTS["chat.completions"]),
93
+ "images.generations": new Set(GENERATIVE_REQUEST_PARAMETER_ALLOWLISTS["images.generations"]),
94
+ "audio.generations": new Set(GENERATIVE_REQUEST_PARAMETER_ALLOWLISTS["audio.generations"]),
95
+ };
96
+ const LIMIT_KEY_SET = new Set(GENERATIVE_OPERATION_LIMIT_KEYS);
97
+ const STRICT_ORIGIN_RELATIVE_PATH = /^\/[A-Za-z0-9._~-]+(?:\/[A-Za-z0-9._~-]+)*$/;
98
+ const MAX_OPERATION_PATH_LENGTH = 2048;
99
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
100
+ const asNormalizedLookupKey = (value) => {
101
+ if (typeof value !== "string")
102
+ return undefined;
103
+ const normalized = value.trim().toLowerCase();
104
+ return normalized.length > 0 ? normalized : undefined;
105
+ };
106
+ export function normalizeGenerativeOperation(value) {
107
+ const normalized = asNormalizedLookupKey(value);
108
+ return normalized ? OPERATION_ALIASES[normalized] : undefined;
109
+ }
110
+ export function normalizeGenerativeModality(value) {
111
+ const normalized = asNormalizedLookupKey(value);
112
+ return normalized ? MODALITY_ALIASES[normalized] : undefined;
113
+ }
114
+ export function normalizeGenerativeModalities(value) {
115
+ if (!Array.isArray(value))
116
+ return undefined;
117
+ const normalized = [];
118
+ for (const item of value) {
119
+ const modality = normalizeGenerativeModality(item);
120
+ if (modality && !normalized.includes(modality)) {
121
+ normalized.push(modality);
122
+ }
123
+ }
124
+ return normalized.length > 0 ? normalized : undefined;
125
+ }
126
+ export function isGenerativeOperationPath(value) {
127
+ if (typeof value !== "string"
128
+ || value.length === 0
129
+ || value.length > MAX_OPERATION_PATH_LENGTH
130
+ || value.trim() !== value
131
+ || !STRICT_ORIGIN_RELATIVE_PATH.test(value)) {
132
+ return false;
133
+ }
134
+ return value
135
+ .split("/")
136
+ .slice(1)
137
+ .every((segment) => segment !== "." && segment !== "..");
138
+ }
139
+ export function normalizeGenerativeOperationPath(value) {
140
+ return isGenerativeOperationPath(value) ? value : undefined;
141
+ }
142
+ const normalizeRequestParameterAllowlist = (operation, value) => {
143
+ const defaults = GENERATIVE_REQUEST_PARAMETER_ALLOWLISTS[operation];
144
+ if (value === undefined) {
145
+ return [...defaults];
146
+ }
147
+ if (!Array.isArray(value))
148
+ return [];
149
+ const allowed = REQUEST_PARAMETER_SETS[operation];
150
+ const normalized = [];
151
+ for (const item of value) {
152
+ if (typeof item !== "string")
153
+ continue;
154
+ const parameter = item.trim();
155
+ if (allowed.has(parameter) && !normalized.includes(parameter)) {
156
+ normalized.push(parameter);
157
+ }
158
+ }
159
+ return normalized;
160
+ };
161
+ const normalizeStringList = (value, normalize) => {
162
+ if (!Array.isArray(value))
163
+ return undefined;
164
+ const normalized = [];
165
+ for (const item of value) {
166
+ if (typeof item !== "string")
167
+ continue;
168
+ const candidate = normalize(item);
169
+ if (candidate && !normalized.includes(candidate)) {
170
+ normalized.push(candidate);
171
+ }
172
+ }
173
+ return normalized;
174
+ };
175
+ const normalizeResponseFormat = (value) => {
176
+ const normalized = value.trim().toLowerCase();
177
+ return /^[a-z0-9][a-z0-9._+-]{0,63}$/.test(normalized) ? normalized : undefined;
178
+ };
179
+ const normalizeMimeType = (value) => {
180
+ const normalized = value.trim().toLowerCase();
181
+ return /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/.test(normalized)
182
+ ? normalized
183
+ : undefined;
184
+ };
185
+ const normalizeGenerativeOperationLimits = (value) => {
186
+ if (!isRecord(value))
187
+ return undefined;
188
+ const normalized = {};
189
+ for (const [key, candidate] of Object.entries(value)) {
190
+ if (LIMIT_KEY_SET.has(key)
191
+ && typeof candidate === "number"
192
+ && Number.isSafeInteger(candidate)
193
+ && candidate > 0) {
194
+ normalized[key] = candidate;
195
+ }
196
+ }
197
+ return Object.keys(normalized).length > 0 ? normalized : undefined;
198
+ };
199
+ const normalizeOperationMethod = (value) => {
200
+ if (value === undefined)
201
+ return "POST";
202
+ return typeof value === "string" && value.trim().toUpperCase() === "POST"
203
+ ? "POST"
204
+ : undefined;
205
+ };
206
+ export function normalizeSelfHostedGenerativeOperation(value) {
207
+ const record = isRecord(value) ? value : undefined;
208
+ const operation = normalizeGenerativeOperation(record ? record.operation : value);
209
+ if (!operation)
210
+ return undefined;
211
+ const method = normalizeOperationMethod(record?.method);
212
+ if (!method)
213
+ return undefined;
214
+ const path = record && record.path !== undefined
215
+ ? normalizeGenerativeOperationPath(record.path)
216
+ : GENERATIVE_OPERATION_DEFAULT_PATHS[operation];
217
+ if (!path)
218
+ return undefined;
219
+ const normalized = {
220
+ operation,
221
+ path,
222
+ method,
223
+ requestParameterAllowlist: normalizeRequestParameterAllowlist(operation, record?.requestParameterAllowlist),
224
+ };
225
+ const responseFormats = normalizeStringList(record?.responseFormats, normalizeResponseFormat);
226
+ if (responseFormats !== undefined) {
227
+ normalized.responseFormats = responseFormats;
228
+ }
229
+ const outputMimeTypes = normalizeStringList(record?.outputMimeTypes, normalizeMimeType);
230
+ if (outputMimeTypes !== undefined) {
231
+ normalized.outputMimeTypes = outputMimeTypes;
232
+ }
233
+ const limits = normalizeGenerativeOperationLimits(record?.limits);
234
+ if (limits) {
235
+ normalized.limits = limits;
236
+ }
237
+ return normalized;
238
+ }
@@ -1,10 +1,11 @@
1
+ import { type GenerativeModality, type SelfHostedGenerativeOperation } from "./GenerativeOperation.js";
1
2
  export declare const LOCAL_OPENAI_COMPATIBLE_ADAPTER: "openai-compatible-local";
2
3
  export declare const VLLM_LOCAL_ADAPTER: "vllm-local";
3
4
  export declare const LLAMA_CPP_LOCAL_ADAPTER: "llama-cpp-local";
4
5
  export declare const LEGACY_LLAMACPP_LOCAL_ADAPTER: "llamacpp-local";
5
6
  export declare const LOCAL_OPENAI_COMPATIBLE_ADAPTER_ALIASES: readonly ["openai-compatible-local", "vllm-local", "llama-cpp-local", "llamacpp-local"];
6
7
  export type LocalOpenAiCompatibleAdapter = (typeof LOCAL_OPENAI_COMPATIBLE_ADAPTER_ALIASES)[number];
7
- export type LocalRunnerKind = "vllm" | "llama-cpp" | "llama-cpp-python" | "lm-studio" | "localai" | "sglang" | "tgi" | "custom";
8
+ export type LocalRunnerKind = "vllm" | "llama-cpp" | "llama-cpp-python" | "stable-diffusion-cpp" | "lm-studio" | "localai" | "sglang" | "tgi" | "custom";
8
9
  export type LocalRunnerAuthMode = "none" | "bearer" | "dummy-bearer";
9
10
  export type LocalRunnerResponseFormatStrategy = "openai" | "json-object" | "json-schema" | "gbnf" | "prompt-only" | "none";
10
11
  export type ResponseFormatStrategy = LocalRunnerResponseFormatStrategy;
@@ -12,6 +13,10 @@ export interface LocalOpenAiCompatibleRunnerConfig {
12
13
  baseUrl?: string;
13
14
  endpoint?: string;
14
15
  apiBaseUrl?: string;
16
+ publicModelId?: string;
17
+ inputModalities?: GenerativeModality[];
18
+ outputModalities?: GenerativeModality[];
19
+ operations?: SelfHostedGenerativeOperation[];
15
20
  runnerKind?: LocalRunnerKind;
16
21
  authMode?: LocalRunnerAuthMode;
17
22
  dummyBearerToken?: string;
@@ -26,7 +31,7 @@ export interface LocalOpenAiCompatibleRunnerConfig {
26
31
  supportsJsonSchema?: boolean;
27
32
  supportsGbnf?: boolean;
28
33
  }
29
- export type LocalRunnerConfigIssueCode = "invalid_auth_mode" | "invalid_runner_kind" | "invalid_response_format_strategy" | "invalid_headers" | "invalid_header_value" | "secret_header" | "invalid_extra_body" | "reserved_extra_body_key";
34
+ export type LocalRunnerConfigIssueCode = "invalid_auth_mode" | "invalid_runner_kind" | "invalid_response_format_strategy" | "invalid_input_modalities" | "invalid_output_modalities" | "invalid_operations" | "invalid_headers" | "invalid_header_value" | "secret_header" | "invalid_extra_body" | "reserved_extra_body_key";
30
35
  export interface LocalRunnerConfigIssue {
31
36
  code: LocalRunnerConfigIssueCode;
32
37
  path: string;
@@ -1 +1 @@
1
- {"version":3,"file":"LocalRunnerConfig.d.ts","sourceRoot":"","sources":["../../src/llm/LocalRunnerConfig.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,+BAA+B,EAAG,yBAAkC,CAAC;AAClF,eAAO,MAAM,kBAAkB,EAAG,YAAqB,CAAC;AACxD,eAAO,MAAM,uBAAuB,EAAG,iBAA0B,CAAC;AAClE,eAAO,MAAM,6BAA6B,EAAG,gBAAyB,CAAC;AAEvE,eAAO,MAAM,uCAAuC,yFAK1C,CAAC;AAEX,MAAM,MAAM,4BAA4B,GAAG,CAAC,OAAO,uCAAuC,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpG,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,WAAW,GACX,kBAAkB,GAClB,WAAW,GACX,SAAS,GACT,QAAQ,GACR,KAAK,GACL,QAAQ,CAAC;AAEb,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,QAAQ,GAAG,cAAc,CAAC;AAErE,MAAM,MAAM,iCAAiC,GACzC,QAAQ,GACR,aAAa,GACb,aAAa,GACb,MAAM,GACN,aAAa,GACb,MAAM,CAAC;AAEX,MAAM,MAAM,sBAAsB,GAAG,iCAAiC,CAAC;AAEvE,MAAM,WAAW,iCAAiC;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,sBAAs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E,MAAM,GAAG,OAAO,CAEtE;AAgLD,wBAAgB,0CAA0C,CACxD,KAAK,GAAE,6BAAkC,GACxC,2CAA2C,CA6F7C;AAED,wBAAgB,yCAAyC,CACvD,MAAM,EAAE,iCAAiC,GACxC,sBAAsB,EAAE,CAK1B"}
@@ -1,3 +1,4 @@
1
+ import { normalizeGenerativeModality, normalizeSelfHostedGenerativeOperation, } from "./GenerativeOperation.js";
1
2
  export const LOCAL_OPENAI_COMPATIBLE_ADAPTER = "openai-compatible-local";
2
3
  export const VLLM_LOCAL_ADAPTER = "vllm-local";
3
4
  export const LLAMA_CPP_LOCAL_ADAPTER = "llama-cpp-local";
@@ -37,6 +38,11 @@ const RUNNER_KIND_ALIASES = {
37
38
  "llama.cpp-python": "llama-cpp-python",
38
39
  llamacpppython: "llama-cpp-python",
39
40
  "llama_cpp_python": "llama-cpp-python",
41
+ "stable-diffusion-cpp": "stable-diffusion-cpp",
42
+ "stable-diffusion.cpp": "stable-diffusion-cpp",
43
+ stable_diffusion_cpp: "stable-diffusion-cpp",
44
+ "sd-cpp": "stable-diffusion-cpp",
45
+ "sd.cpp": "stable-diffusion-cpp",
40
46
  "lm-studio": "lm-studio",
41
47
  lmstudio: "lm-studio",
42
48
  "lm_studio": "lm-studio",
@@ -198,6 +204,84 @@ const normalizeExtraBody = (value, issues) => {
198
204
  }
199
205
  return Object.keys(extraBody).length > 0 ? extraBody : undefined;
200
206
  };
207
+ const normalizeModalityDeclaration = (value, fallback, path, issueCode, issues) => {
208
+ if (value === undefined)
209
+ return [...fallback];
210
+ if (!Array.isArray(value)) {
211
+ pushIssue(issues, {
212
+ code: issueCode,
213
+ path,
214
+ message: `${path} must be an array of supported generative modalities.`,
215
+ value,
216
+ });
217
+ return [...fallback];
218
+ }
219
+ const modalities = [];
220
+ for (let index = 0; index < value.length; index += 1) {
221
+ const modality = normalizeGenerativeModality(value[index]);
222
+ if (!modality) {
223
+ pushIssue(issues, {
224
+ code: issueCode,
225
+ path: `${path}.${index}`,
226
+ message: "Unknown generative modality.",
227
+ value: value[index],
228
+ });
229
+ continue;
230
+ }
231
+ if (!modalities.includes(modality))
232
+ modalities.push(modality);
233
+ }
234
+ return modalities.length > 0 ? modalities : [...fallback];
235
+ };
236
+ const defaultChatOperation = () => {
237
+ const operation = normalizeSelfHostedGenerativeOperation({
238
+ operation: "chat.completions",
239
+ });
240
+ if (!operation) {
241
+ throw new Error("Invalid built-in chat.completions operation");
242
+ }
243
+ return operation;
244
+ };
245
+ const normalizeOperationDeclarations = (value, issues) => {
246
+ if (value === undefined)
247
+ return [defaultChatOperation()];
248
+ if (!Array.isArray(value)) {
249
+ pushIssue(issues, {
250
+ code: "invalid_operations",
251
+ path: "operations",
252
+ message: "operations must be an array of supported generative operation descriptors.",
253
+ value,
254
+ });
255
+ return [defaultChatOperation()];
256
+ }
257
+ const operations = [];
258
+ for (let index = 0; index < value.length; index += 1) {
259
+ const operation = normalizeSelfHostedGenerativeOperation(value[index]);
260
+ if (!operation) {
261
+ pushIssue(issues, {
262
+ code: "invalid_operations",
263
+ path: `operations.${index}`,
264
+ message: "Invalid generative operation descriptor.",
265
+ value: value[index],
266
+ });
267
+ continue;
268
+ }
269
+ if (!operations.some((entry) => entry.operation === operation.operation)) {
270
+ operations.push(operation);
271
+ }
272
+ }
273
+ if (operations.length > 0)
274
+ return operations;
275
+ if (value.length === 0) {
276
+ pushIssue(issues, {
277
+ code: "invalid_operations",
278
+ path: "operations",
279
+ message: "operations must declare at least one supported generative operation.",
280
+ value,
281
+ });
282
+ }
283
+ return [defaultChatOperation()];
284
+ };
201
285
  const mergeConfigRecords = (input) => {
202
286
  const topLevelConfig = isRecord(input.config) ? input.config : {};
203
287
  const nestedAgent = isRecord(topLevelConfig.agent) ? topLevelConfig.agent : {};
@@ -257,6 +341,10 @@ export function normalizeLocalOpenAiCompatibleRunnerConfig(input = {}) {
257
341
  baseUrl: readString(merged, ["baseUrl", "endpoint", "apiBaseUrl"]),
258
342
  endpoint: readString(merged, ["endpoint"]),
259
343
  apiBaseUrl: readString(merged, ["apiBaseUrl"]),
344
+ publicModelId: readString(merged, ["publicModelId", "public_model_id"]),
345
+ inputModalities: normalizeModalityDeclaration(merged.inputModalities ?? merged.input_modalities, ["text"], "inputModalities", "invalid_input_modalities", issues),
346
+ outputModalities: normalizeModalityDeclaration(merged.outputModalities ?? merged.output_modalities, ["text"], "outputModalities", "invalid_output_modalities", issues),
347
+ operations: normalizeOperationDeclarations(merged.operations, issues),
260
348
  runnerKind,
261
349
  authMode,
262
350
  dummyBearerToken: authMode === "dummy-bearer" ? dummyBearerToken ?? "local" : dummyBearerToken,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcoda/shared",
3
- "version": "0.1.101",
3
+ "version": "0.1.102",
4
4
  "description": "Shared utilities and schemas for mcoda.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",