@mcoda/agents 0.1.8 → 0.1.10
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/CHANGELOG.md +3 -0
- package/README.md +1 -0
- package/dist/AgentService/AgentService.d.ts +3 -1
- package/dist/AgentService/AgentService.d.ts.map +1 -1
- package/dist/AgentService/AgentService.js +189 -24
- package/dist/adapters/AdapterTypes.d.ts +10 -0
- package/dist/adapters/AdapterTypes.d.ts.map +1 -1
- package/dist/adapters/codali/CodaliAdapter.d.ts +19 -0
- package/dist/adapters/codali/CodaliAdapter.d.ts.map +1 -0
- package/dist/adapters/codali/CodaliAdapter.js +290 -0
- package/dist/adapters/codali/CodaliCliRunner.d.ts +36 -0
- package/dist/adapters/codali/CodaliCliRunner.d.ts.map +1 -0
- package/dist/adapters/codali/CodaliCliRunner.js +230 -0
- package/dist/adapters/codex/CodexCliRunner.d.ts.map +1 -1
- package/dist/adapters/codex/CodexCliRunner.js +628 -34
- package/dist/adapters/ollama/OllamaRemoteAdapter.d.ts.map +1 -1
- package/dist/adapters/ollama/OllamaRemoteAdapter.js +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ await service.close();
|
|
|
30
30
|
## Notes
|
|
31
31
|
- Primarily used by the mcoda CLI; APIs may evolve.
|
|
32
32
|
- Set `MCODA_STREAM_IO=1` to emit adapter I/O lines to stderr.
|
|
33
|
+
- If `~/.docdex/agents.md` exists, AgentService prepends it to every agent invocation.
|
|
33
34
|
|
|
34
35
|
## License
|
|
35
36
|
MIT - see `LICENSE`.
|
|
@@ -13,10 +13,12 @@ export declare class AgentService {
|
|
|
13
13
|
private getDecryptedSecret;
|
|
14
14
|
private buildAdapterConfig;
|
|
15
15
|
private resolveAdapterType;
|
|
16
|
-
getAdapter(agent: Agent): Promise<AgentAdapter>;
|
|
16
|
+
getAdapter(agent: Agent, adapterOverride?: string): Promise<AgentAdapter>;
|
|
17
17
|
healthCheck(agentId: string): Promise<AgentHealth>;
|
|
18
18
|
invoke(agentId: string, request: InvocationRequest): Promise<InvocationResult>;
|
|
19
19
|
invokeStream(agentId: string, request: InvocationRequest): Promise<AsyncGenerator<InvocationResult>>;
|
|
20
20
|
private applyGatewayHandoff;
|
|
21
|
+
private recordInvocationFailure;
|
|
22
|
+
private applyDocdexGuidance;
|
|
21
23
|
}
|
|
22
24
|
//# sourceMappingURL=AgentService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentService.d.ts","sourceRoot":"","sources":["../../src/AgentService/AgentService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AgentService.d.ts","sourceRoot":"","sources":["../../src/AgentService/AgentService.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzG,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAW7C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AA4KhG,qBAAa,YAAY;IACX,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,gBAAgB;WAE7B,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC;IAKtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAUhD,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IAIrE,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAInD,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;YAIpD,kBAAkB;YAMlB,kBAAkB;IA6BhC,OAAO,CAAC,kBAAkB;IA+BpB,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAyCzE,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAmBlD,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAyB9E,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC;YAyC5F,mBAAmB;YAkBnB,uBAAuB;YAwBvB,mBAAmB;CAYlC"}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { promises as fs } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
2
4
|
import { CryptoHelper } from "@mcoda/shared";
|
|
3
5
|
import { GlobalRepository } from "@mcoda/db";
|
|
4
6
|
import { CodexAdapter } from "../adapters/codex/CodexAdapter.js";
|
|
5
7
|
import { GeminiAdapter } from "../adapters/gemini/GeminiAdapter.js";
|
|
6
8
|
import { LocalAdapter } from "../adapters/local/LocalAdapter.js";
|
|
9
|
+
import { CodaliAdapter } from "../adapters/codali/CodaliAdapter.js";
|
|
7
10
|
import { OllamaRemoteAdapter } from "../adapters/ollama/OllamaRemoteAdapter.js";
|
|
8
11
|
import { OllamaCliAdapter } from "../adapters/ollama/OllamaCliAdapter.js";
|
|
9
12
|
import { OpenAiAdapter } from "../adapters/openai/OpenAiAdapter.js";
|
|
10
13
|
import { OpenAiCliAdapter } from "../adapters/openai/OpenAiCliAdapter.js";
|
|
11
14
|
import { ZhipuApiAdapter } from "../adapters/zhipu/ZhipuApiAdapter.js";
|
|
12
15
|
import { QaAdapter } from "../adapters/qa/QaAdapter.js";
|
|
13
|
-
const CLI_BASED_ADAPTERS = new Set(["codex-cli", "gemini-cli", "openai-cli", "ollama-cli"]);
|
|
16
|
+
const CLI_BASED_ADAPTERS = new Set(["codex-cli", "gemini-cli", "openai-cli", "ollama-cli", "codali-cli"]);
|
|
14
17
|
const LOCAL_ADAPTERS = new Set(["local-model"]);
|
|
15
18
|
const SUPPORTED_ADAPTERS = new Set([
|
|
16
19
|
"openai-api",
|
|
@@ -22,16 +25,22 @@ const SUPPORTED_ADAPTERS = new Set([
|
|
|
22
25
|
"qa-cli",
|
|
23
26
|
"ollama-remote",
|
|
24
27
|
"ollama-cli",
|
|
28
|
+
"codali-cli",
|
|
25
29
|
]);
|
|
26
30
|
const DEFAULT_JOB_PROMPT = "You are an mcoda agent that follows workspace runbooks and responds with actionable, concise output.";
|
|
27
31
|
const DEFAULT_CHARACTER_PROMPT = "Write clearly, avoid hallucinations, cite assumptions, and prioritize risk mitigation for the user.";
|
|
28
32
|
const HANDOFF_ENV_INLINE = "MCODA_GATEWAY_HANDOFF";
|
|
29
33
|
const HANDOFF_ENV_PATH = "MCODA_GATEWAY_HANDOFF_PATH";
|
|
30
34
|
const HANDOFF_HEADER = "[Gateway handoff]";
|
|
31
|
-
const MAX_HANDOFF_CHARS = 8000;
|
|
32
35
|
const IO_ENV = "MCODA_STREAM_IO";
|
|
33
36
|
const IO_PROMPT_ENV = "MCODA_STREAM_IO_PROMPT";
|
|
34
37
|
const IO_PREFIX = "[agent-io]";
|
|
38
|
+
const DOCDEX_GUIDANCE_HEADER = "[Docdex guidance]";
|
|
39
|
+
const DOCDEX_GUIDANCE_PATH = path.join(os.homedir(), ".docdex", "agents.md");
|
|
40
|
+
let docdexGuidanceCache;
|
|
41
|
+
let docdexGuidanceLoaded = false;
|
|
42
|
+
const DOCDEX_JSON_ONLY_MARKERS = [/output json only/i, /return json only/i, /no prose, no analysis/i];
|
|
43
|
+
const HANDOFF_END_MARKERS = [/^\s*END OF FILE\s*$/i, /^\s*\*\*\* End of File\s*$/i];
|
|
35
44
|
const isIoEnabled = () => {
|
|
36
45
|
const raw = process.env[IO_ENV];
|
|
37
46
|
if (!raw)
|
|
@@ -46,9 +55,19 @@ const isIoPromptEnabled = () => {
|
|
|
46
55
|
const normalized = raw.trim().toLowerCase();
|
|
47
56
|
return !["0", "false", "off", "no"].includes(normalized);
|
|
48
57
|
};
|
|
58
|
+
let ioWriteQueue = Promise.resolve();
|
|
49
59
|
const emitIoLine = (line) => {
|
|
50
60
|
const normalized = line.endsWith("\n") ? line : `${line}\n`;
|
|
51
|
-
|
|
61
|
+
ioWriteQueue = ioWriteQueue
|
|
62
|
+
.then(() => new Promise((resolve) => {
|
|
63
|
+
try {
|
|
64
|
+
process.stderr.write(normalized, () => resolve());
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
resolve();
|
|
68
|
+
}
|
|
69
|
+
}))
|
|
70
|
+
.catch(() => { });
|
|
52
71
|
};
|
|
53
72
|
const renderIoHeader = (agent, request, mode) => {
|
|
54
73
|
emitIoLine(`${IO_PREFIX} begin agent=${agent.slug ?? agent.id} adapter=${agent.adapter} model=${agent.defaultModel ?? "default"} mode=${mode}`);
|
|
@@ -65,28 +84,98 @@ const renderIoChunk = (chunk) => {
|
|
|
65
84
|
emitIoLine(`${IO_PREFIX} output ${chunk.output}`);
|
|
66
85
|
}
|
|
67
86
|
};
|
|
87
|
+
const createStreamIoRenderer = () => {
|
|
88
|
+
let buffer = "";
|
|
89
|
+
const flushLine = (line) => {
|
|
90
|
+
const cleaned = line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
91
|
+
emitIoLine(`${IO_PREFIX} output ${cleaned}`);
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
push: (chunk) => {
|
|
95
|
+
if (!chunk.output)
|
|
96
|
+
return;
|
|
97
|
+
buffer += chunk.output;
|
|
98
|
+
let newlineIndex = buffer.indexOf("\n");
|
|
99
|
+
while (newlineIndex !== -1) {
|
|
100
|
+
const line = buffer.slice(0, newlineIndex);
|
|
101
|
+
flushLine(line);
|
|
102
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
103
|
+
newlineIndex = buffer.indexOf("\n");
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
flush: () => {
|
|
107
|
+
if (!buffer)
|
|
108
|
+
return;
|
|
109
|
+
flushLine(buffer);
|
|
110
|
+
buffer = "";
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
};
|
|
68
114
|
const renderIoEnd = () => {
|
|
69
115
|
emitIoLine(`${IO_PREFIX} end`);
|
|
70
116
|
};
|
|
117
|
+
const stripHandoffEndMarkers = (content) => {
|
|
118
|
+
const lines = content.split(/\r?\n/);
|
|
119
|
+
const filtered = lines.filter((line) => !HANDOFF_END_MARKERS.some((marker) => marker.test(line)));
|
|
120
|
+
return filtered.join("\n").trim();
|
|
121
|
+
};
|
|
71
122
|
const readGatewayHandoff = async () => {
|
|
72
123
|
const inline = process.env[HANDOFF_ENV_INLINE];
|
|
73
124
|
if (inline && inline.trim()) {
|
|
74
|
-
|
|
125
|
+
const normalized = stripHandoffEndMarkers(inline.trim());
|
|
126
|
+
if (!normalized)
|
|
127
|
+
return undefined;
|
|
128
|
+
return normalized;
|
|
75
129
|
}
|
|
76
130
|
const filePath = process.env[HANDOFF_ENV_PATH];
|
|
77
131
|
if (!filePath)
|
|
78
132
|
return undefined;
|
|
79
133
|
try {
|
|
80
134
|
const content = await fs.readFile(filePath, "utf8");
|
|
135
|
+
const normalized = stripHandoffEndMarkers(content.trim());
|
|
136
|
+
if (!normalized)
|
|
137
|
+
return undefined;
|
|
138
|
+
return normalized;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const readDocdexGuidance = async () => {
|
|
145
|
+
if (docdexGuidanceLoaded)
|
|
146
|
+
return docdexGuidanceCache;
|
|
147
|
+
docdexGuidanceLoaded = true;
|
|
148
|
+
try {
|
|
149
|
+
const content = await fs.readFile(DOCDEX_GUIDANCE_PATH, "utf8");
|
|
81
150
|
const trimmed = content.trim();
|
|
82
151
|
if (!trimmed)
|
|
83
152
|
return undefined;
|
|
84
|
-
|
|
153
|
+
docdexGuidanceCache = trimmed;
|
|
154
|
+
return docdexGuidanceCache;
|
|
85
155
|
}
|
|
86
156
|
catch {
|
|
87
157
|
return undefined;
|
|
88
158
|
}
|
|
89
159
|
};
|
|
160
|
+
const stripJsonOnlyGuidance = (guidance) => {
|
|
161
|
+
const lines = guidance.split(/\r?\n/);
|
|
162
|
+
const filtered = lines.filter((line) => !DOCDEX_JSON_ONLY_MARKERS.some((marker) => marker.test(line)));
|
|
163
|
+
return filtered.join("\n").trim();
|
|
164
|
+
};
|
|
165
|
+
const normalizeDocdexGuidanceInput = (input, prefix) => {
|
|
166
|
+
const trimmed = input.trimStart();
|
|
167
|
+
if (!trimmed.startsWith(DOCDEX_GUIDANCE_HEADER)) {
|
|
168
|
+
return `${prefix}${input}`;
|
|
169
|
+
}
|
|
170
|
+
if (!trimmed.startsWith(prefix)) {
|
|
171
|
+
return trimmed;
|
|
172
|
+
}
|
|
173
|
+
let remainder = trimmed.slice(prefix.length);
|
|
174
|
+
while (remainder.startsWith(prefix)) {
|
|
175
|
+
remainder = remainder.slice(prefix.length);
|
|
176
|
+
}
|
|
177
|
+
return `${prefix}${remainder}`;
|
|
178
|
+
};
|
|
90
179
|
export class AgentService {
|
|
91
180
|
constructor(repo) {
|
|
92
181
|
this.repo = repo;
|
|
@@ -149,12 +238,12 @@ export class AgentService {
|
|
|
149
238
|
authMetadata,
|
|
150
239
|
};
|
|
151
240
|
}
|
|
152
|
-
resolveAdapterType(agent, apiKey) {
|
|
241
|
+
resolveAdapterType(agent, apiKey, adapterOverride) {
|
|
153
242
|
const hasSecret = Boolean(apiKey);
|
|
154
243
|
const config = agent.config;
|
|
155
244
|
const cliAdapter = config?.cliAdapter;
|
|
156
245
|
const localAdapter = config?.localAdapter;
|
|
157
|
-
let adapterType = agent.adapter;
|
|
246
|
+
let adapterType = adapterOverride?.trim() || agent.adapter;
|
|
158
247
|
if (!SUPPORTED_ADAPTERS.has(adapterType)) {
|
|
159
248
|
throw new Error(`Unsupported adapter type: ${adapterType}`);
|
|
160
249
|
}
|
|
@@ -180,9 +269,9 @@ export class AgentService {
|
|
|
180
269
|
}
|
|
181
270
|
return adapterType;
|
|
182
271
|
}
|
|
183
|
-
async getAdapter(agent) {
|
|
272
|
+
async getAdapter(agent, adapterOverride) {
|
|
184
273
|
const config = await this.buildAdapterConfig(agent);
|
|
185
|
-
const adapterType = this.resolveAdapterType(agent, config.apiKey);
|
|
274
|
+
const adapterType = this.resolveAdapterType(agent, config.apiKey, adapterOverride);
|
|
186
275
|
const configWithAdapter = { ...config, adapter: adapterType };
|
|
187
276
|
if (adapterType === "openai-api") {
|
|
188
277
|
return new OpenAiAdapter(configWithAdapter);
|
|
@@ -208,6 +297,9 @@ export class AgentService {
|
|
|
208
297
|
if (adapterType === "ollama-cli") {
|
|
209
298
|
return new OllamaCliAdapter(configWithAdapter);
|
|
210
299
|
}
|
|
300
|
+
if (adapterType === "codali-cli") {
|
|
301
|
+
return new CodaliAdapter(configWithAdapter);
|
|
302
|
+
}
|
|
211
303
|
if (adapterType === "gemini-cli") {
|
|
212
304
|
return new GeminiAdapter(configWithAdapter);
|
|
213
305
|
}
|
|
@@ -237,42 +329,66 @@ export class AgentService {
|
|
|
237
329
|
}
|
|
238
330
|
async invoke(agentId, request) {
|
|
239
331
|
const agent = await this.resolveAgent(agentId);
|
|
240
|
-
const adapter = await this.getAdapter(agent);
|
|
332
|
+
const adapter = await this.getAdapter(agent, request.adapterType);
|
|
241
333
|
if (!adapter.invoke) {
|
|
242
334
|
throw new Error("Adapter does not support invoke");
|
|
243
335
|
}
|
|
244
|
-
const
|
|
336
|
+
const withDocdex = await this.applyDocdexGuidance(request);
|
|
337
|
+
const enriched = await this.applyGatewayHandoff(withDocdex);
|
|
245
338
|
const ioEnabled = isIoEnabled();
|
|
246
339
|
if (ioEnabled) {
|
|
247
340
|
renderIoHeader(agent, enriched, "invoke");
|
|
248
341
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
342
|
+
try {
|
|
343
|
+
const result = await adapter.invoke(enriched);
|
|
344
|
+
if (ioEnabled) {
|
|
345
|
+
renderIoChunk(result);
|
|
346
|
+
renderIoEnd();
|
|
347
|
+
}
|
|
348
|
+
return result;
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
await this.recordInvocationFailure(agent, error);
|
|
352
|
+
throw error;
|
|
253
353
|
}
|
|
254
|
-
return result;
|
|
255
354
|
}
|
|
256
355
|
async invokeStream(agentId, request) {
|
|
257
356
|
const agent = await this.resolveAgent(agentId);
|
|
258
|
-
const adapter = await this.getAdapter(agent);
|
|
357
|
+
const adapter = await this.getAdapter(agent, request.adapterType);
|
|
259
358
|
if (!adapter.invokeStream) {
|
|
260
359
|
throw new Error("Adapter does not support streaming");
|
|
261
360
|
}
|
|
262
|
-
const
|
|
361
|
+
const withDocdex = await this.applyDocdexGuidance(request);
|
|
362
|
+
const enriched = await this.applyGatewayHandoff(withDocdex);
|
|
263
363
|
const ioEnabled = isIoEnabled();
|
|
264
|
-
|
|
364
|
+
let generator;
|
|
365
|
+
try {
|
|
366
|
+
generator = await adapter.invokeStream(enriched);
|
|
367
|
+
}
|
|
368
|
+
catch (error) {
|
|
369
|
+
await this.recordInvocationFailure(agent, error);
|
|
370
|
+
throw error;
|
|
371
|
+
}
|
|
372
|
+
const recordFailure = (error) => this.recordInvocationFailure(agent, error);
|
|
265
373
|
async function* wrap() {
|
|
374
|
+
const streamIo = ioEnabled ? createStreamIoRenderer() : undefined;
|
|
266
375
|
if (ioEnabled) {
|
|
267
376
|
renderIoHeader(agent, enriched, "stream");
|
|
268
377
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
378
|
+
try {
|
|
379
|
+
for await (const chunk of generator) {
|
|
380
|
+
if (ioEnabled) {
|
|
381
|
+
streamIo?.push(chunk);
|
|
382
|
+
}
|
|
383
|
+
yield chunk;
|
|
272
384
|
}
|
|
273
|
-
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
await recordFailure(error);
|
|
388
|
+
throw error;
|
|
274
389
|
}
|
|
275
390
|
if (ioEnabled) {
|
|
391
|
+
streamIo?.flush();
|
|
276
392
|
renderIoEnd();
|
|
277
393
|
}
|
|
278
394
|
}
|
|
@@ -282,10 +398,59 @@ export class AgentService {
|
|
|
282
398
|
if (request.metadata?.command === "gateway-agent") {
|
|
283
399
|
return request;
|
|
284
400
|
}
|
|
401
|
+
const currentInput = request.input ?? "";
|
|
402
|
+
if (currentInput.includes(HANDOFF_HEADER)) {
|
|
403
|
+
return request;
|
|
404
|
+
}
|
|
405
|
+
if (request.metadata?.gatewayHandoffApplied) {
|
|
406
|
+
return request;
|
|
407
|
+
}
|
|
285
408
|
const handoff = await readGatewayHandoff();
|
|
286
409
|
if (!handoff)
|
|
287
410
|
return request;
|
|
288
411
|
const suffix = `\n\n${HANDOFF_HEADER}\n${handoff}`;
|
|
289
|
-
|
|
412
|
+
const metadata = { ...(request.metadata ?? {}), gatewayHandoffApplied: true };
|
|
413
|
+
return { ...request, input: `${currentInput}${suffix}`, metadata };
|
|
414
|
+
}
|
|
415
|
+
async recordInvocationFailure(agent, error) {
|
|
416
|
+
const adapter = (agent.adapter ?? "").toLowerCase();
|
|
417
|
+
if (adapter !== "ollama-remote")
|
|
418
|
+
return;
|
|
419
|
+
const message = error instanceof Error ? error.message : String(error ?? "");
|
|
420
|
+
if (!/MODEL_NOT_FOUND/i.test(message))
|
|
421
|
+
return;
|
|
422
|
+
const baseUrl = agent.config?.baseUrl;
|
|
423
|
+
const health = {
|
|
424
|
+
agentId: agent.id,
|
|
425
|
+
status: "unreachable",
|
|
426
|
+
lastCheckedAt: new Date().toISOString(),
|
|
427
|
+
details: {
|
|
428
|
+
reason: "model_missing",
|
|
429
|
+
model: agent.defaultModel ?? null,
|
|
430
|
+
baseUrl,
|
|
431
|
+
error: message,
|
|
432
|
+
},
|
|
433
|
+
};
|
|
434
|
+
try {
|
|
435
|
+
await this.repo.setAgentHealth(health);
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
// ignore health update failures
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
async applyDocdexGuidance(request) {
|
|
442
|
+
const guidance = await readDocdexGuidance();
|
|
443
|
+
if (!guidance)
|
|
444
|
+
return request;
|
|
445
|
+
const command = request.metadata?.command ? String(request.metadata.command) : "";
|
|
446
|
+
const cleaned = command === "gateway-agent" ? guidance : stripJsonOnlyGuidance(guidance);
|
|
447
|
+
if (!cleaned)
|
|
448
|
+
return request;
|
|
449
|
+
const prefix = `${DOCDEX_GUIDANCE_HEADER}\n${cleaned}\n\n`;
|
|
450
|
+
const currentInput = request.input ?? "";
|
|
451
|
+
const nextInput = normalizeDocdexGuidanceInput(currentInput, prefix);
|
|
452
|
+
if (nextInput === currentInput)
|
|
453
|
+
return request;
|
|
454
|
+
return { ...request, input: nextInput };
|
|
290
455
|
}
|
|
291
456
|
}
|
|
@@ -4,6 +4,16 @@ export interface AdapterConfig {
|
|
|
4
4
|
capabilities: string[];
|
|
5
5
|
model?: string;
|
|
6
6
|
apiKey?: string;
|
|
7
|
+
provider?: string;
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
docdexBaseUrl?: string;
|
|
10
|
+
docdexRepoId?: string;
|
|
11
|
+
docdexRepoRoot?: string;
|
|
12
|
+
docdex?: {
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
repoId?: string;
|
|
15
|
+
repoRoot?: string;
|
|
16
|
+
};
|
|
7
17
|
prompts?: AgentPromptManifest;
|
|
8
18
|
authMetadata?: AgentAuthMetadata;
|
|
9
19
|
adapter?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AdapterTypes.d.ts","sourceRoot":"","sources":["../../src/adapters/AdapterTypes.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MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AgentHealth } from "@mcoda/shared";
|
|
2
|
+
import { AdapterConfig, AgentAdapter, InvocationRequest, InvocationResult } from "../AdapterTypes.js";
|
|
3
|
+
export declare const resolveCodaliProviderFromAdapter: (params: {
|
|
4
|
+
sourceAdapter?: string;
|
|
5
|
+
explicitProvider?: string;
|
|
6
|
+
}) => {
|
|
7
|
+
provider: string;
|
|
8
|
+
sourceAdapter?: string;
|
|
9
|
+
requiresApiKey: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare class CodaliAdapter implements AgentAdapter {
|
|
12
|
+
private config;
|
|
13
|
+
constructor(config: AdapterConfig);
|
|
14
|
+
getCapabilities(): Promise<string[]>;
|
|
15
|
+
healthCheck(): Promise<AgentHealth>;
|
|
16
|
+
invoke(request: InvocationRequest): Promise<InvocationResult>;
|
|
17
|
+
invokeStream(request: InvocationRequest): AsyncGenerator<InvocationResult, void, unknown>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=CodaliAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodaliAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/codali/CodaliAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAyEtG,eAAO,MAAM,gCAAgC,GAAI,QAAQ;IACvD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,KAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAiCtE,CAAC;AAmEF,qBAAa,aAAc,YAAW,YAAY;IACpC,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAEnC,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAIpC,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAanC,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAwE5D,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,OAAO,CAAC;CAyEjG"}
|