opencode-gitlab-duo-agentic 0.1.4 → 0.1.6
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.js +21 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1180,7 +1180,7 @@ var TokenUsageEstimator = class {
|
|
|
1180
1180
|
};
|
|
1181
1181
|
|
|
1182
1182
|
// src/provider/core/debug_log.ts
|
|
1183
|
-
import { appendFileSync
|
|
1183
|
+
import { appendFileSync } from "fs";
|
|
1184
1184
|
var LOG_PATH = "/tmp/duo-debug.log";
|
|
1185
1185
|
function duoLog(...args) {
|
|
1186
1186
|
const ts = (/* @__PURE__ */ new Date()).toISOString().slice(11, 23);
|
|
@@ -1192,14 +1192,9 @@ function duoLog(...args) {
|
|
|
1192
1192
|
} catch {
|
|
1193
1193
|
}
|
|
1194
1194
|
}
|
|
1195
|
-
function duoLogReset() {
|
|
1196
|
-
try {
|
|
1197
|
-
writeFileSync(LOG_PATH, "");
|
|
1198
|
-
} catch {
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
1195
|
|
|
1202
1196
|
// src/provider/application/model.ts
|
|
1197
|
+
var EMPTY_USAGE = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
1203
1198
|
var GitLabDuoAgenticLanguageModel = class {
|
|
1204
1199
|
specificationVersion = "v2";
|
|
1205
1200
|
provider = GITLAB_DUO_PROVIDER_ID;
|
|
@@ -1214,6 +1209,7 @@ var GitLabDuoAgenticLanguageModel = class {
|
|
|
1214
1209
|
#agentMode;
|
|
1215
1210
|
#agentModeReminder;
|
|
1216
1211
|
#usageEstimator = new TokenUsageEstimator();
|
|
1212
|
+
#streaming = false;
|
|
1217
1213
|
constructor(modelId, options, runtime) {
|
|
1218
1214
|
this.modelId = modelId;
|
|
1219
1215
|
this.#options = options;
|
|
@@ -1242,11 +1238,15 @@ var GitLabDuoAgenticLanguageModel = class {
|
|
|
1242
1238
|
};
|
|
1243
1239
|
}
|
|
1244
1240
|
async doStream(options) {
|
|
1245
|
-
const workflowType = "chat";
|
|
1246
1241
|
const promptText = extractLastUserText(options.prompt);
|
|
1242
|
+
if (this.#streaming) {
|
|
1243
|
+
duoLog("--- doStream BUSY (rejected)", "prompt=" + (promptText?.slice(0, 40) ?? "null"));
|
|
1244
|
+
return { stream: emptyFinishStream() };
|
|
1245
|
+
}
|
|
1246
|
+
this.#streaming = true;
|
|
1247
|
+
const workflowType = "chat";
|
|
1247
1248
|
const toolResults = extractToolResults(options.prompt);
|
|
1248
|
-
|
|
1249
|
-
duoLog("doStream", "hasStarted=" + this.#runtime.hasStarted, "prompt=" + (promptText?.slice(0, 60) ?? "null"), "toolResults=" + toolResults.length);
|
|
1249
|
+
duoLog("--- doStream", "hasStarted=" + this.#runtime.hasStarted, "prompt=" + (promptText?.slice(0, 60) ?? "null"));
|
|
1250
1250
|
this.#runtime.resetMapperState();
|
|
1251
1251
|
if (!this.#runtime.hasStarted) {
|
|
1252
1252
|
this.#sentToolCallIds.clear();
|
|
@@ -1264,7 +1264,6 @@ var GitLabDuoAgenticLanguageModel = class {
|
|
|
1264
1264
|
const mcpTools = this.#options.enableMcp === false ? [] : buildMcpTools(options);
|
|
1265
1265
|
const toolContext = buildToolContext(mcpTools);
|
|
1266
1266
|
const isNewUserMessage = promptText != null && promptText !== this.#lastSentPrompt;
|
|
1267
|
-
duoLog("gate", "isNewUserMessage=" + isNewUserMessage, "freshTools=" + freshToolResults.length, "lastSent=" + (this.#lastSentPrompt?.slice(0, 40) ?? "null"));
|
|
1268
1267
|
let sentToolResults = false;
|
|
1269
1268
|
if (freshToolResults.length > 0) {
|
|
1270
1269
|
for (const result of freshToolResults) {
|
|
@@ -1385,8 +1384,6 @@ var GitLabDuoAgenticLanguageModel = class {
|
|
|
1385
1384
|
for (const ctx of extraContext) {
|
|
1386
1385
|
if (ctx.content) this.#usageEstimator.addInputChars(ctx.content);
|
|
1387
1386
|
}
|
|
1388
|
-
} else {
|
|
1389
|
-
duoLog("SKIP startRequest", "sentToolResults=" + sentToolResults, "isNewUserMessage=" + isNewUserMessage);
|
|
1390
1387
|
}
|
|
1391
1388
|
const iterator = this.#mapEventsToStream(this.#runtime.getEventStream());
|
|
1392
1389
|
const stream = asyncIteratorToReadableStream(iterator);
|
|
@@ -1405,7 +1402,6 @@ var GitLabDuoAgenticLanguageModel = class {
|
|
|
1405
1402
|
try {
|
|
1406
1403
|
for await (const event of events) {
|
|
1407
1404
|
eventCount++;
|
|
1408
|
-
duoLog("evt", event.type, eventCount);
|
|
1409
1405
|
if (event.type === "TEXT_CHUNK") {
|
|
1410
1406
|
if (event.content.length > 0) {
|
|
1411
1407
|
estimator.addOutputChars(event.content);
|
|
@@ -1454,6 +1450,8 @@ var GitLabDuoAgenticLanguageModel = class {
|
|
|
1454
1450
|
duoLog("streamErr", streamErr instanceof Error ? streamErr.message : String(streamErr));
|
|
1455
1451
|
yield { type: "error", error: streamErr instanceof Error ? streamErr : new Error(String(streamErr)) };
|
|
1456
1452
|
return;
|
|
1453
|
+
} finally {
|
|
1454
|
+
this.#streaming = false;
|
|
1457
1455
|
}
|
|
1458
1456
|
duoLog("finish", "events=" + eventCount);
|
|
1459
1457
|
yield { type: "finish", finishReason: "stop", usage: this.#currentUsage };
|
|
@@ -1494,6 +1492,14 @@ var GitLabDuoAgenticLanguageModel = class {
|
|
|
1494
1492
|
yield { type: "finish", finishReason: "tool-calls", usage: this.#currentUsage };
|
|
1495
1493
|
}
|
|
1496
1494
|
};
|
|
1495
|
+
function emptyFinishStream() {
|
|
1496
|
+
return new ReadableStream({
|
|
1497
|
+
start(controller) {
|
|
1498
|
+
controller.enqueue({ type: "finish", finishReason: "stop", usage: EMPTY_USAGE });
|
|
1499
|
+
controller.close();
|
|
1500
|
+
}
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1497
1503
|
function buildReminderContext(reminders, modeReminder) {
|
|
1498
1504
|
const nonModeReminders = reminders.filter((reminder) => classifyModeReminder2(reminder) === "other");
|
|
1499
1505
|
if (!modeReminder) {
|
|
@@ -1904,7 +1910,6 @@ var GitLabAgenticRuntime = class {
|
|
|
1904
1910
|
async ensureConnected(goal, workflowType) {
|
|
1905
1911
|
duoLog("ensureConnected", "stream=" + !!this.#stream, "wfId=" + !!this.#workflowId, "queue=" + !!this.#queue);
|
|
1906
1912
|
if (this.#stream && this.#workflowId && this.#queue) {
|
|
1907
|
-
duoLog("ensureConnected", "skip (connected)");
|
|
1908
1913
|
return;
|
|
1909
1914
|
}
|
|
1910
1915
|
if (!this.#containerParams) {
|
|
@@ -1977,8 +1982,7 @@ var GitLabAgenticRuntime = class {
|
|
|
1977
1982
|
preapproved_tools: preapprovedTools
|
|
1978
1983
|
}
|
|
1979
1984
|
};
|
|
1980
|
-
|
|
1981
|
-
duoLog("startReq write=" + ok2, "wf=" + this.#workflowId);
|
|
1985
|
+
this.#stream.write(startRequest);
|
|
1982
1986
|
this.#startRequestSent = true;
|
|
1983
1987
|
}
|
|
1984
1988
|
sendToolResponse(requestId, response, responseType) {
|
|
@@ -2082,7 +2086,6 @@ var GitLabAgenticRuntime = class {
|
|
|
2082
2086
|
workflowStatus: action.newCheckpoint.status
|
|
2083
2087
|
};
|
|
2084
2088
|
const events = await this.#mapper.mapWorkflowEvent(duoEvent);
|
|
2085
|
-
duoLog("mapped", events.length, events.map((e) => e.type).join(","));
|
|
2086
2089
|
for (const event of events) {
|
|
2087
2090
|
queue.push(event);
|
|
2088
2091
|
}
|