@mcoda/shared 0.1.71 → 0.1.73
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
|
@@ -6,6 +6,7 @@ export * from "./qa/QaPlan.js";
|
|
|
6
6
|
export * from "./qa/QaReadiness.js";
|
|
7
7
|
export * from "./qa/QaTechStack.js";
|
|
8
8
|
export * from "./metadata/CommandMetadata.js";
|
|
9
|
+
export * from "./llm/LocalRunnerConfig.js";
|
|
9
10
|
export * from "./status/TaskStatus.js";
|
|
10
11
|
export type { BacklogLaneTotals, BacklogTotals, BacklogSummary, EffectiveVelocity, EstimateResult, EstimateDurations, EstimateEtas, EstimateStatusCounts, EstimateCompletionMetric, EstimateCompletion, VelocitySource, AgentHealth, AgentHealthStatus, AgentUsageLimitScope, AgentUsageLimitWindowType, AgentUsageLimitStatus, AgentUsageLimitRecord, UpsertAgentUsageLimitInput, RoutingDefaults, RoutingDefault, RoutingProvenance, RoutingCandidate, RoutingPreview, RoutingDefaultsUpdate, RefineTasksRequest, RefineTasksPlan, RefineTasksResult, RefineStrategy, RefineOperation, UpdateTaskOp, SplitTaskOp, MergeTasksOp, UpdateEstimateOp, UpdateInfo, UpdateChannel, ApplyUpdateResponse, } from "./openapi/OpenApiTypes.js";
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,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,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
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export declare const LOCAL_OPENAI_COMPATIBLE_ADAPTER: "openai-compatible-local";
|
|
2
|
+
export declare const VLLM_LOCAL_ADAPTER: "vllm-local";
|
|
3
|
+
export declare const LLAMA_CPP_LOCAL_ADAPTER: "llama-cpp-local";
|
|
4
|
+
export declare const LEGACY_LLAMACPP_LOCAL_ADAPTER: "llamacpp-local";
|
|
5
|
+
export declare const LOCAL_OPENAI_COMPATIBLE_ADAPTER_ALIASES: readonly ["openai-compatible-local", "vllm-local", "llama-cpp-local", "llamacpp-local"];
|
|
6
|
+
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 LocalRunnerAuthMode = "none" | "bearer" | "dummy-bearer";
|
|
9
|
+
export type LocalRunnerResponseFormatStrategy = "openai" | "json-object" | "json-schema" | "gbnf" | "prompt-only" | "none";
|
|
10
|
+
export type ResponseFormatStrategy = LocalRunnerResponseFormatStrategy;
|
|
11
|
+
export interface LocalOpenAiCompatibleRunnerConfig {
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
endpoint?: string;
|
|
14
|
+
apiBaseUrl?: string;
|
|
15
|
+
runnerKind?: LocalRunnerKind;
|
|
16
|
+
authMode?: LocalRunnerAuthMode;
|
|
17
|
+
dummyBearerToken?: string;
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
extraBody?: Record<string, unknown>;
|
|
20
|
+
responseFormatStrategy?: LocalRunnerResponseFormatStrategy;
|
|
21
|
+
healthPath?: string;
|
|
22
|
+
modelsPath?: string;
|
|
23
|
+
requireModelInRequest?: boolean;
|
|
24
|
+
supportsStreaming?: boolean;
|
|
25
|
+
supportsTools?: boolean;
|
|
26
|
+
supportsJsonSchema?: boolean;
|
|
27
|
+
supportsGbnf?: boolean;
|
|
28
|
+
}
|
|
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";
|
|
30
|
+
export interface LocalRunnerConfigIssue {
|
|
31
|
+
code: LocalRunnerConfigIssueCode;
|
|
32
|
+
path: string;
|
|
33
|
+
message: string;
|
|
34
|
+
value?: unknown;
|
|
35
|
+
}
|
|
36
|
+
export interface LocalRunnerNormalizationInput {
|
|
37
|
+
adapter?: unknown;
|
|
38
|
+
config?: unknown;
|
|
39
|
+
agentConfig?: unknown;
|
|
40
|
+
defaultRunnerKind?: unknown;
|
|
41
|
+
}
|
|
42
|
+
export interface NormalizedLocalOpenAiCompatibleRunnerConfig {
|
|
43
|
+
adapter?: typeof LOCAL_OPENAI_COMPATIBLE_ADAPTER;
|
|
44
|
+
originalAdapter?: string;
|
|
45
|
+
isLocalOpenAiCompatible: boolean;
|
|
46
|
+
config: LocalOpenAiCompatibleRunnerConfig;
|
|
47
|
+
issues: LocalRunnerConfigIssue[];
|
|
48
|
+
}
|
|
49
|
+
export declare const LOCAL_RUNNER_SECRET_HEADER_KEYS: readonly ["authorization", "proxy-authorization", "x-api-key", "api-key"];
|
|
50
|
+
export declare const LOCAL_RUNNER_RESERVED_EXTRA_BODY_KEYS: readonly ["model", "messages", "stream", "tools", "tool_choice", "response_format", "max_tokens", "temperature"];
|
|
51
|
+
export declare function isLocalOpenAiCompatibleAdapter(adapter: unknown): boolean;
|
|
52
|
+
export declare function normalizeLocalOpenAiCompatibleAdapter(adapter: unknown): typeof LOCAL_OPENAI_COMPATIBLE_ADAPTER | undefined;
|
|
53
|
+
export declare function defaultLocalRunnerKindForAdapter(adapter: unknown): LocalRunnerKind | undefined;
|
|
54
|
+
export declare function normalizeLocalRunnerKind(value: unknown): LocalRunnerKind | undefined;
|
|
55
|
+
export declare function normalizeLocalRunnerAuthMode(value: unknown): LocalRunnerAuthMode | undefined;
|
|
56
|
+
export declare function normalizeLocalRunnerResponseFormatStrategy(value: unknown): LocalRunnerResponseFormatStrategy | undefined;
|
|
57
|
+
export declare function isSecretLocalRunnerHeaderKey(key: string): boolean;
|
|
58
|
+
export declare function isReservedLocalRunnerExtraBodyKey(key: string): boolean;
|
|
59
|
+
export declare function normalizeLocalOpenAiCompatibleRunnerConfig(input?: LocalRunnerNormalizationInput): NormalizedLocalOpenAiCompatibleRunnerConfig;
|
|
60
|
+
export declare function validateLocalOpenAiCompatibleRunnerConfig(config: LocalOpenAiCompatibleRunnerConfig): LocalRunnerConfigIssue[];
|
|
61
|
+
//# sourceMappingURL=LocalRunnerConfig.d.ts.map
|
|
@@ -0,0 +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,a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3
|
+
export const LLAMA_CPP_LOCAL_ADAPTER = "llama-cpp-local";
|
|
4
|
+
export const LEGACY_LLAMACPP_LOCAL_ADAPTER = "llamacpp-local";
|
|
5
|
+
export const LOCAL_OPENAI_COMPATIBLE_ADAPTER_ALIASES = [
|
|
6
|
+
LOCAL_OPENAI_COMPATIBLE_ADAPTER,
|
|
7
|
+
VLLM_LOCAL_ADAPTER,
|
|
8
|
+
LLAMA_CPP_LOCAL_ADAPTER,
|
|
9
|
+
LEGACY_LLAMACPP_LOCAL_ADAPTER,
|
|
10
|
+
];
|
|
11
|
+
export const LOCAL_RUNNER_SECRET_HEADER_KEYS = [
|
|
12
|
+
"authorization",
|
|
13
|
+
"proxy-authorization",
|
|
14
|
+
"x-api-key",
|
|
15
|
+
"api-key",
|
|
16
|
+
];
|
|
17
|
+
export const LOCAL_RUNNER_RESERVED_EXTRA_BODY_KEYS = [
|
|
18
|
+
"model",
|
|
19
|
+
"messages",
|
|
20
|
+
"stream",
|
|
21
|
+
"tools",
|
|
22
|
+
"tool_choice",
|
|
23
|
+
"response_format",
|
|
24
|
+
"max_tokens",
|
|
25
|
+
"temperature",
|
|
26
|
+
];
|
|
27
|
+
const LOCAL_OPENAI_COMPATIBLE_ADAPTER_SET = new Set(LOCAL_OPENAI_COMPATIBLE_ADAPTER_ALIASES);
|
|
28
|
+
const SECRET_HEADER_SET = new Set(LOCAL_RUNNER_SECRET_HEADER_KEYS);
|
|
29
|
+
const RESERVED_EXTRA_BODY_KEY_SET = new Set(LOCAL_RUNNER_RESERVED_EXTRA_BODY_KEYS);
|
|
30
|
+
const RUNNER_KIND_ALIASES = {
|
|
31
|
+
vllm: "vllm",
|
|
32
|
+
"llama-cpp": "llama-cpp",
|
|
33
|
+
"llama.cpp": "llama-cpp",
|
|
34
|
+
llamacpp: "llama-cpp",
|
|
35
|
+
"llama_cpp": "llama-cpp",
|
|
36
|
+
"llama-cpp-python": "llama-cpp-python",
|
|
37
|
+
"llama.cpp-python": "llama-cpp-python",
|
|
38
|
+
llamacpppython: "llama-cpp-python",
|
|
39
|
+
"llama_cpp_python": "llama-cpp-python",
|
|
40
|
+
"lm-studio": "lm-studio",
|
|
41
|
+
lmstudio: "lm-studio",
|
|
42
|
+
"lm_studio": "lm-studio",
|
|
43
|
+
localai: "localai",
|
|
44
|
+
"local-ai": "localai",
|
|
45
|
+
local_ai: "localai",
|
|
46
|
+
sglang: "sglang",
|
|
47
|
+
tgi: "tgi",
|
|
48
|
+
"text-generation-inference": "tgi",
|
|
49
|
+
text_generation_inference: "tgi",
|
|
50
|
+
custom: "custom",
|
|
51
|
+
};
|
|
52
|
+
const AUTH_MODE_ALIASES = {
|
|
53
|
+
none: "none",
|
|
54
|
+
bearer: "bearer",
|
|
55
|
+
"dummy-bearer": "dummy-bearer",
|
|
56
|
+
dummy_bearer: "dummy-bearer",
|
|
57
|
+
dummybearer: "dummy-bearer",
|
|
58
|
+
dummy: "dummy-bearer",
|
|
59
|
+
};
|
|
60
|
+
const RESPONSE_FORMAT_STRATEGY_ALIASES = {
|
|
61
|
+
openai: "openai",
|
|
62
|
+
"json-object": "json-object",
|
|
63
|
+
json_object: "json-object",
|
|
64
|
+
jsonobject: "json-object",
|
|
65
|
+
"json-schema": "json-schema",
|
|
66
|
+
json_schema: "json-schema",
|
|
67
|
+
jsonschema: "json-schema",
|
|
68
|
+
gbnf: "gbnf",
|
|
69
|
+
"prompt-only": "prompt-only",
|
|
70
|
+
prompt_only: "prompt-only",
|
|
71
|
+
promptonly: "prompt-only",
|
|
72
|
+
none: "none",
|
|
73
|
+
};
|
|
74
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
75
|
+
const asString = (value) => {
|
|
76
|
+
if (typeof value !== "string")
|
|
77
|
+
return undefined;
|
|
78
|
+
const trimmed = value.trim();
|
|
79
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
80
|
+
};
|
|
81
|
+
const asBoolean = (value) => typeof value === "boolean" ? value : undefined;
|
|
82
|
+
const normalizeLookupKey = (value) => value.trim().toLowerCase();
|
|
83
|
+
const readString = (record, keys) => {
|
|
84
|
+
for (const key of keys) {
|
|
85
|
+
const value = asString(record[key]);
|
|
86
|
+
if (value)
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
};
|
|
91
|
+
const pushIssue = (issues, issue) => {
|
|
92
|
+
issues.push(issue);
|
|
93
|
+
};
|
|
94
|
+
export function isLocalOpenAiCompatibleAdapter(adapter) {
|
|
95
|
+
const normalized = asString(adapter);
|
|
96
|
+
return normalized ? LOCAL_OPENAI_COMPATIBLE_ADAPTER_SET.has(normalizeLookupKey(normalized)) : false;
|
|
97
|
+
}
|
|
98
|
+
export function normalizeLocalOpenAiCompatibleAdapter(adapter) {
|
|
99
|
+
return isLocalOpenAiCompatibleAdapter(adapter) ? LOCAL_OPENAI_COMPATIBLE_ADAPTER : undefined;
|
|
100
|
+
}
|
|
101
|
+
export function defaultLocalRunnerKindForAdapter(adapter) {
|
|
102
|
+
const normalized = asString(adapter);
|
|
103
|
+
if (!normalized)
|
|
104
|
+
return undefined;
|
|
105
|
+
const lookupKey = normalizeLookupKey(normalized);
|
|
106
|
+
if (lookupKey === VLLM_LOCAL_ADAPTER)
|
|
107
|
+
return "vllm";
|
|
108
|
+
if (lookupKey === LLAMA_CPP_LOCAL_ADAPTER || lookupKey === LEGACY_LLAMACPP_LOCAL_ADAPTER) {
|
|
109
|
+
return "llama-cpp";
|
|
110
|
+
}
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
export function normalizeLocalRunnerKind(value) {
|
|
114
|
+
const normalized = asString(value);
|
|
115
|
+
if (!normalized)
|
|
116
|
+
return undefined;
|
|
117
|
+
return RUNNER_KIND_ALIASES[normalizeLookupKey(normalized)];
|
|
118
|
+
}
|
|
119
|
+
export function normalizeLocalRunnerAuthMode(value) {
|
|
120
|
+
const normalized = asString(value);
|
|
121
|
+
if (!normalized)
|
|
122
|
+
return undefined;
|
|
123
|
+
return AUTH_MODE_ALIASES[normalizeLookupKey(normalized)];
|
|
124
|
+
}
|
|
125
|
+
export function normalizeLocalRunnerResponseFormatStrategy(value) {
|
|
126
|
+
const normalized = asString(value);
|
|
127
|
+
if (!normalized)
|
|
128
|
+
return undefined;
|
|
129
|
+
return RESPONSE_FORMAT_STRATEGY_ALIASES[normalizeLookupKey(normalized)];
|
|
130
|
+
}
|
|
131
|
+
export function isSecretLocalRunnerHeaderKey(key) {
|
|
132
|
+
return SECRET_HEADER_SET.has(normalizeLookupKey(key));
|
|
133
|
+
}
|
|
134
|
+
export function isReservedLocalRunnerExtraBodyKey(key) {
|
|
135
|
+
return RESERVED_EXTRA_BODY_KEY_SET.has(normalizeLookupKey(key));
|
|
136
|
+
}
|
|
137
|
+
const normalizeHeaders = (value, issues) => {
|
|
138
|
+
if (value === undefined)
|
|
139
|
+
return undefined;
|
|
140
|
+
if (!isRecord(value)) {
|
|
141
|
+
pushIssue(issues, {
|
|
142
|
+
code: "invalid_headers",
|
|
143
|
+
path: "headers",
|
|
144
|
+
message: "Local runner headers must be an object with string values.",
|
|
145
|
+
value,
|
|
146
|
+
});
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
const headers = {};
|
|
150
|
+
for (const [key, headerValue] of Object.entries(value)) {
|
|
151
|
+
const stringValue = asString(headerValue);
|
|
152
|
+
if (!stringValue) {
|
|
153
|
+
pushIssue(issues, {
|
|
154
|
+
code: "invalid_header_value",
|
|
155
|
+
path: `headers.${key}`,
|
|
156
|
+
message: "Local runner header values must be non-empty strings.",
|
|
157
|
+
value: headerValue,
|
|
158
|
+
});
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (isSecretLocalRunnerHeaderKey(key)) {
|
|
162
|
+
pushIssue(issues, {
|
|
163
|
+
code: "secret_header",
|
|
164
|
+
path: `headers.${key}`,
|
|
165
|
+
message: "Secret-bearing headers must not be stored in local runner config.",
|
|
166
|
+
value: key,
|
|
167
|
+
});
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
headers[key] = stringValue;
|
|
171
|
+
}
|
|
172
|
+
return Object.keys(headers).length > 0 ? headers : undefined;
|
|
173
|
+
};
|
|
174
|
+
const normalizeExtraBody = (value, issues) => {
|
|
175
|
+
if (value === undefined)
|
|
176
|
+
return undefined;
|
|
177
|
+
if (!isRecord(value)) {
|
|
178
|
+
pushIssue(issues, {
|
|
179
|
+
code: "invalid_extra_body",
|
|
180
|
+
path: "extraBody",
|
|
181
|
+
message: "Local runner extraBody must be an object.",
|
|
182
|
+
value,
|
|
183
|
+
});
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
const extraBody = {};
|
|
187
|
+
for (const [key, entryValue] of Object.entries(value)) {
|
|
188
|
+
if (isReservedLocalRunnerExtraBodyKey(key)) {
|
|
189
|
+
pushIssue(issues, {
|
|
190
|
+
code: "reserved_extra_body_key",
|
|
191
|
+
path: `extraBody.${key}`,
|
|
192
|
+
message: "extraBody must not override core OpenAI-compatible request fields.",
|
|
193
|
+
value: key,
|
|
194
|
+
});
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
extraBody[key] = entryValue;
|
|
198
|
+
}
|
|
199
|
+
return Object.keys(extraBody).length > 0 ? extraBody : undefined;
|
|
200
|
+
};
|
|
201
|
+
const mergeConfigRecords = (input) => {
|
|
202
|
+
const topLevelConfig = isRecord(input.config) ? input.config : {};
|
|
203
|
+
const nestedAgent = isRecord(topLevelConfig.agent) ? topLevelConfig.agent : {};
|
|
204
|
+
const nestedAgentConfig = isRecord(nestedAgent.config) ? nestedAgent.config : {};
|
|
205
|
+
const explicitAgentConfig = isRecord(input.agentConfig) ? input.agentConfig : {};
|
|
206
|
+
const localRunnerConfig = isRecord(topLevelConfig.localRunner) ? topLevelConfig.localRunner : {};
|
|
207
|
+
return {
|
|
208
|
+
...nestedAgentConfig,
|
|
209
|
+
...explicitAgentConfig,
|
|
210
|
+
...localRunnerConfig,
|
|
211
|
+
...topLevelConfig,
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
export function normalizeLocalOpenAiCompatibleRunnerConfig(input = {}) {
|
|
215
|
+
const issues = [];
|
|
216
|
+
const merged = mergeConfigRecords(input);
|
|
217
|
+
const nestedAgent = isRecord(merged.agent) ? merged.agent : {};
|
|
218
|
+
const originalAdapter = asString(input.adapter) ?? asString(merged.adapter) ?? asString(nestedAgent.adapter);
|
|
219
|
+
const adapter = normalizeLocalOpenAiCompatibleAdapter(originalAdapter);
|
|
220
|
+
const isLocalOpenAiCompatible = adapter !== undefined;
|
|
221
|
+
const rawRunnerKind = merged.runnerKind;
|
|
222
|
+
const normalizedRunnerKind = normalizeLocalRunnerKind(rawRunnerKind);
|
|
223
|
+
const runnerKind = normalizedRunnerKind ??
|
|
224
|
+
normalizeLocalRunnerKind(input.defaultRunnerKind) ??
|
|
225
|
+
defaultLocalRunnerKindForAdapter(originalAdapter);
|
|
226
|
+
if (rawRunnerKind !== undefined && normalizedRunnerKind === undefined) {
|
|
227
|
+
pushIssue(issues, {
|
|
228
|
+
code: "invalid_runner_kind",
|
|
229
|
+
path: "runnerKind",
|
|
230
|
+
message: "Unknown local runner kind.",
|
|
231
|
+
value: rawRunnerKind,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
const rawAuthMode = merged.authMode;
|
|
235
|
+
const authMode = normalizeLocalRunnerAuthMode(rawAuthMode) ?? (isLocalOpenAiCompatible ? "none" : undefined);
|
|
236
|
+
if (rawAuthMode !== undefined && normalizeLocalRunnerAuthMode(rawAuthMode) === undefined) {
|
|
237
|
+
pushIssue(issues, {
|
|
238
|
+
code: "invalid_auth_mode",
|
|
239
|
+
path: "authMode",
|
|
240
|
+
message: "Unknown local runner auth mode.",
|
|
241
|
+
value: rawAuthMode,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
const rawResponseFormatStrategy = merged.responseFormatStrategy;
|
|
245
|
+
const responseFormatStrategy = normalizeLocalRunnerResponseFormatStrategy(rawResponseFormatStrategy);
|
|
246
|
+
if (rawResponseFormatStrategy !== undefined &&
|
|
247
|
+
normalizeLocalRunnerResponseFormatStrategy(rawResponseFormatStrategy) === undefined) {
|
|
248
|
+
pushIssue(issues, {
|
|
249
|
+
code: "invalid_response_format_strategy",
|
|
250
|
+
path: "responseFormatStrategy",
|
|
251
|
+
message: "Unknown local runner response format strategy.",
|
|
252
|
+
value: rawResponseFormatStrategy,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
const dummyBearerToken = readString(merged, ["dummyBearerToken", "dummyApiKey"]);
|
|
256
|
+
const config = {
|
|
257
|
+
baseUrl: readString(merged, ["baseUrl", "endpoint", "apiBaseUrl"]),
|
|
258
|
+
endpoint: readString(merged, ["endpoint"]),
|
|
259
|
+
apiBaseUrl: readString(merged, ["apiBaseUrl"]),
|
|
260
|
+
runnerKind,
|
|
261
|
+
authMode,
|
|
262
|
+
dummyBearerToken: authMode === "dummy-bearer" ? dummyBearerToken ?? "local" : dummyBearerToken,
|
|
263
|
+
headers: normalizeHeaders(merged.headers, issues),
|
|
264
|
+
extraBody: normalizeExtraBody(merged.extraBody, issues),
|
|
265
|
+
responseFormatStrategy,
|
|
266
|
+
healthPath: readString(merged, ["healthPath"]),
|
|
267
|
+
modelsPath: readString(merged, ["modelsPath"]),
|
|
268
|
+
requireModelInRequest: asBoolean(merged.requireModelInRequest),
|
|
269
|
+
supportsStreaming: asBoolean(merged.supportsStreaming),
|
|
270
|
+
supportsTools: asBoolean(merged.supportsTools),
|
|
271
|
+
supportsJsonSchema: asBoolean(merged.supportsJsonSchema),
|
|
272
|
+
supportsGbnf: asBoolean(merged.supportsGbnf),
|
|
273
|
+
};
|
|
274
|
+
return {
|
|
275
|
+
adapter,
|
|
276
|
+
originalAdapter,
|
|
277
|
+
isLocalOpenAiCompatible,
|
|
278
|
+
config,
|
|
279
|
+
issues,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
export function validateLocalOpenAiCompatibleRunnerConfig(config) {
|
|
283
|
+
return normalizeLocalOpenAiCompatibleRunnerConfig({
|
|
284
|
+
adapter: LOCAL_OPENAI_COMPATIBLE_ADAPTER,
|
|
285
|
+
config,
|
|
286
|
+
}).issues;
|
|
287
|
+
}
|