opencode-gitlab-duo-agentic 0.1.5 → 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 +22 -26
- 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);
|
|
@@ -1194,6 +1194,7 @@ function duoLog(...args) {
|
|
|
1194
1194
|
}
|
|
1195
1195
|
|
|
1196
1196
|
// src/provider/application/model.ts
|
|
1197
|
+
var EMPTY_USAGE = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
1197
1198
|
var GitLabDuoAgenticLanguageModel = class {
|
|
1198
1199
|
specificationVersion = "v2";
|
|
1199
1200
|
provider = GITLAB_DUO_PROVIDER_ID;
|
|
@@ -1208,6 +1209,7 @@ var GitLabDuoAgenticLanguageModel = class {
|
|
|
1208
1209
|
#agentMode;
|
|
1209
1210
|
#agentModeReminder;
|
|
1210
1211
|
#usageEstimator = new TokenUsageEstimator();
|
|
1212
|
+
#streaming = false;
|
|
1211
1213
|
constructor(modelId, options, runtime) {
|
|
1212
1214
|
this.modelId = modelId;
|
|
1213
1215
|
this.#options = options;
|
|
@@ -1236,10 +1238,15 @@ var GitLabDuoAgenticLanguageModel = class {
|
|
|
1236
1238
|
};
|
|
1237
1239
|
}
|
|
1238
1240
|
async doStream(options) {
|
|
1239
|
-
const workflowType = "chat";
|
|
1240
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";
|
|
1241
1248
|
const toolResults = extractToolResults(options.prompt);
|
|
1242
|
-
duoLog("--- doStream", "hasStarted=" + this.#runtime.hasStarted, "prompt=" + (promptText?.slice(0, 60) ?? "null")
|
|
1249
|
+
duoLog("--- doStream", "hasStarted=" + this.#runtime.hasStarted, "prompt=" + (promptText?.slice(0, 60) ?? "null"));
|
|
1243
1250
|
this.#runtime.resetMapperState();
|
|
1244
1251
|
if (!this.#runtime.hasStarted) {
|
|
1245
1252
|
this.#sentToolCallIds.clear();
|
|
@@ -1257,7 +1264,6 @@ var GitLabDuoAgenticLanguageModel = class {
|
|
|
1257
1264
|
const mcpTools = this.#options.enableMcp === false ? [] : buildMcpTools(options);
|
|
1258
1265
|
const toolContext = buildToolContext(mcpTools);
|
|
1259
1266
|
const isNewUserMessage = promptText != null && promptText !== this.#lastSentPrompt;
|
|
1260
|
-
duoLog("gate", "isNewUserMessage=" + isNewUserMessage, "freshTools=" + freshToolResults.length, "lastSent=" + (this.#lastSentPrompt?.slice(0, 40) ?? "null"));
|
|
1261
1267
|
let sentToolResults = false;
|
|
1262
1268
|
if (freshToolResults.length > 0) {
|
|
1263
1269
|
for (const result of freshToolResults) {
|
|
@@ -1378,8 +1384,6 @@ var GitLabDuoAgenticLanguageModel = class {
|
|
|
1378
1384
|
for (const ctx of extraContext) {
|
|
1379
1385
|
if (ctx.content) this.#usageEstimator.addInputChars(ctx.content);
|
|
1380
1386
|
}
|
|
1381
|
-
} else {
|
|
1382
|
-
duoLog("SKIP startRequest", "sentToolResults=" + sentToolResults, "isNewUserMessage=" + isNewUserMessage);
|
|
1383
1387
|
}
|
|
1384
1388
|
const iterator = this.#mapEventsToStream(this.#runtime.getEventStream());
|
|
1385
1389
|
const stream = asyncIteratorToReadableStream(iterator);
|
|
@@ -1398,7 +1402,6 @@ var GitLabDuoAgenticLanguageModel = class {
|
|
|
1398
1402
|
try {
|
|
1399
1403
|
for await (const event of events) {
|
|
1400
1404
|
eventCount++;
|
|
1401
|
-
duoLog("evt", event.type, eventCount);
|
|
1402
1405
|
if (event.type === "TEXT_CHUNK") {
|
|
1403
1406
|
if (event.content.length > 0) {
|
|
1404
1407
|
estimator.addOutputChars(event.content);
|
|
@@ -1447,6 +1450,8 @@ var GitLabDuoAgenticLanguageModel = class {
|
|
|
1447
1450
|
duoLog("streamErr", streamErr instanceof Error ? streamErr.message : String(streamErr));
|
|
1448
1451
|
yield { type: "error", error: streamErr instanceof Error ? streamErr : new Error(String(streamErr)) };
|
|
1449
1452
|
return;
|
|
1453
|
+
} finally {
|
|
1454
|
+
this.#streaming = false;
|
|
1450
1455
|
}
|
|
1451
1456
|
duoLog("finish", "events=" + eventCount);
|
|
1452
1457
|
yield { type: "finish", finishReason: "stop", usage: this.#currentUsage };
|
|
@@ -1487,6 +1492,14 @@ var GitLabDuoAgenticLanguageModel = class {
|
|
|
1487
1492
|
yield { type: "finish", finishReason: "tool-calls", usage: this.#currentUsage };
|
|
1488
1493
|
}
|
|
1489
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
|
+
}
|
|
1490
1503
|
function buildReminderContext(reminders, modeReminder) {
|
|
1491
1504
|
const nonModeReminders = reminders.filter((reminder) => classifyModeReminder2(reminder) === "other");
|
|
1492
1505
|
if (!modeReminder) {
|
|
@@ -1873,7 +1886,6 @@ var GitLabAgenticRuntime = class {
|
|
|
1873
1886
|
#mapper = new WorkflowEventMapper();
|
|
1874
1887
|
#containerParams;
|
|
1875
1888
|
#startRequestSent = false;
|
|
1876
|
-
#connectingPromise;
|
|
1877
1889
|
constructor(options, dependencies) {
|
|
1878
1890
|
this.#options = options;
|
|
1879
1891
|
this.#dependencies = dependencies;
|
|
@@ -1896,24 +1908,10 @@ var GitLabAgenticRuntime = class {
|
|
|
1896
1908
|
// Connection lifecycle
|
|
1897
1909
|
// ---------------------------------------------------------------------------
|
|
1898
1910
|
async ensureConnected(goal, workflowType) {
|
|
1899
|
-
duoLog("ensureConnected", "stream=" + !!this.#stream, "wfId=" + !!this.#workflowId, "queue=" + !!this.#queue
|
|
1900
|
-
if (this.#connectingPromise) {
|
|
1901
|
-
duoLog("ensureConnected", "awaiting in-flight connection");
|
|
1902
|
-
await this.#connectingPromise;
|
|
1903
|
-
return;
|
|
1904
|
-
}
|
|
1911
|
+
duoLog("ensureConnected", "stream=" + !!this.#stream, "wfId=" + !!this.#workflowId, "queue=" + !!this.#queue);
|
|
1905
1912
|
if (this.#stream && this.#workflowId && this.#queue) {
|
|
1906
|
-
duoLog("ensureConnected", "skip (connected)");
|
|
1907
1913
|
return;
|
|
1908
1914
|
}
|
|
1909
|
-
this.#connectingPromise = this.#doConnect(goal, workflowType);
|
|
1910
|
-
try {
|
|
1911
|
-
await this.#connectingPromise;
|
|
1912
|
-
} finally {
|
|
1913
|
-
this.#connectingPromise = void 0;
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
async #doConnect(goal, workflowType) {
|
|
1917
1915
|
if (!this.#containerParams) {
|
|
1918
1916
|
this.#containerParams = await this.#resolveContainerParams();
|
|
1919
1917
|
}
|
|
@@ -1984,8 +1982,7 @@ var GitLabAgenticRuntime = class {
|
|
|
1984
1982
|
preapproved_tools: preapprovedTools
|
|
1985
1983
|
}
|
|
1986
1984
|
};
|
|
1987
|
-
|
|
1988
|
-
duoLog("startReq write=" + ok2, "wf=" + this.#workflowId);
|
|
1985
|
+
this.#stream.write(startRequest);
|
|
1989
1986
|
this.#startRequestSent = true;
|
|
1990
1987
|
}
|
|
1991
1988
|
sendToolResponse(requestId, response, responseType) {
|
|
@@ -2089,7 +2086,6 @@ var GitLabAgenticRuntime = class {
|
|
|
2089
2086
|
workflowStatus: action.newCheckpoint.status
|
|
2090
2087
|
};
|
|
2091
2088
|
const events = await this.#mapper.mapWorkflowEvent(duoEvent);
|
|
2092
|
-
duoLog("mapped", events.length, events.map((e) => e.type).join(","));
|
|
2093
2089
|
for (const event of events) {
|
|
2094
2090
|
queue.push(event);
|
|
2095
2091
|
}
|