micro-models-agent 0.50.4 → 0.51.1
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/main.js +106 -17
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -12639,16 +12639,41 @@ ${t("tool.truncated", { tokens: Math.ceil(removedChars / 2) })}`;
|
|
|
12639
12639
|
}
|
|
12640
12640
|
contextManager.addMessage({ role: "user", content: input });
|
|
12641
12641
|
slog.logUser(input);
|
|
12642
|
-
|
|
12643
|
-
|
|
12642
|
+
const startedAt = Date.now();
|
|
12643
|
+
let toolCalls = 0;
|
|
12644
|
+
const countTool = (ev) => {
|
|
12645
|
+
if (ev.type === "end")
|
|
12646
|
+
toolCalls++;
|
|
12647
|
+
onTool?.(ev);
|
|
12648
|
+
};
|
|
12649
|
+
const emitTurnEnd = (result, err) => {
|
|
12650
|
+
const interrupted = err instanceof Error && err.name === "AbortError" || this.shutdownRequested;
|
|
12651
|
+
pluginManager.runOnTurnEnd?.({
|
|
12652
|
+
logger,
|
|
12653
|
+
sessionManager: sessionManager?.getActiveMeta(),
|
|
12654
|
+
contextManager
|
|
12655
|
+
}, {
|
|
12656
|
+
success: !!result && result.success !== false && !err,
|
|
12657
|
+
durationMs: Date.now() - startedAt,
|
|
12658
|
+
textLength: (result?.text || "").length,
|
|
12659
|
+
toolCalls,
|
|
12660
|
+
interrupted: interrupted || undefined
|
|
12661
|
+
});
|
|
12662
|
+
};
|
|
12663
|
+
try {
|
|
12664
|
+
const result = config.moe?.enabled === true ? await runWithMoE({
|
|
12644
12665
|
config,
|
|
12645
12666
|
llmProvider,
|
|
12646
12667
|
toolExecutor,
|
|
12647
12668
|
logger,
|
|
12648
12669
|
baseDir: this.deps.baseDir
|
|
12649
|
-
}, input, () => this.executeSingleAgentLoop(input, onChunk, onMeta,
|
|
12670
|
+
}, input, () => this.executeSingleAgentLoop(input, onChunk, onMeta, countTool, onPhase), { onMeta, onTool: countTool, onPhase }) : await this.executeSingleAgentLoop(input, onChunk, onMeta, countTool, onPhase);
|
|
12671
|
+
emitTurnEnd(result);
|
|
12672
|
+
return result;
|
|
12673
|
+
} catch (err) {
|
|
12674
|
+
emitTurnEnd(null, err);
|
|
12675
|
+
throw err;
|
|
12650
12676
|
}
|
|
12651
|
-
return this.executeSingleAgentLoop(input, onChunk, onMeta, onTool, onPhase);
|
|
12652
12677
|
}
|
|
12653
12678
|
async executeSingleAgentLoop(input, onChunk, onMeta, onTool, onPhase) {
|
|
12654
12679
|
const {
|
|
@@ -14303,6 +14328,18 @@ var init_checker = __esm(() => {
|
|
|
14303
14328
|
// src/modules/plugins/manager.ts
|
|
14304
14329
|
class PluginManager {
|
|
14305
14330
|
plugins = [];
|
|
14331
|
+
hostBridge = null;
|
|
14332
|
+
setHostBridge(bridge) {
|
|
14333
|
+
this.hostBridge = bridge;
|
|
14334
|
+
}
|
|
14335
|
+
withHost(ctx) {
|
|
14336
|
+
if (!ctx || typeof ctx !== "object")
|
|
14337
|
+
return ctx;
|
|
14338
|
+
if (!this.hostBridge || ctx.hostBridge !== undefined) {
|
|
14339
|
+
return ctx;
|
|
14340
|
+
}
|
|
14341
|
+
return { ...ctx, hostBridge: this.hostBridge };
|
|
14342
|
+
}
|
|
14306
14343
|
register(plugin, source) {
|
|
14307
14344
|
if (source)
|
|
14308
14345
|
plugin.source = source;
|
|
@@ -14341,7 +14378,8 @@ class PluginManager {
|
|
|
14341
14378
|
}
|
|
14342
14379
|
});
|
|
14343
14380
|
}
|
|
14344
|
-
async runOnBeforeTool(
|
|
14381
|
+
async runOnBeforeTool(rawCtx, call) {
|
|
14382
|
+
const ctx = this.withHost(rawCtx);
|
|
14345
14383
|
for (const plugin of this.plugins) {
|
|
14346
14384
|
if (plugin.onBeforeTool) {
|
|
14347
14385
|
try {
|
|
@@ -14353,7 +14391,8 @@ class PluginManager {
|
|
|
14353
14391
|
}
|
|
14354
14392
|
return true;
|
|
14355
14393
|
}
|
|
14356
|
-
async runOnAfterTool(
|
|
14394
|
+
async runOnAfterTool(rawCtx, call, result) {
|
|
14395
|
+
const ctx = this.withHost(rawCtx);
|
|
14357
14396
|
for (const plugin of this.plugins) {
|
|
14358
14397
|
if (plugin.onAfterTool) {
|
|
14359
14398
|
try {
|
|
@@ -14362,7 +14401,8 @@ class PluginManager {
|
|
|
14362
14401
|
}
|
|
14363
14402
|
}
|
|
14364
14403
|
}
|
|
14365
|
-
async runOnError(
|
|
14404
|
+
async runOnError(rawCtx, error) {
|
|
14405
|
+
const ctx = this.withHost(rawCtx);
|
|
14366
14406
|
for (const plugin of this.plugins) {
|
|
14367
14407
|
if (plugin.onError) {
|
|
14368
14408
|
try {
|
|
@@ -14371,7 +14411,8 @@ class PluginManager {
|
|
|
14371
14411
|
}
|
|
14372
14412
|
}
|
|
14373
14413
|
}
|
|
14374
|
-
runOnSessionStart(
|
|
14414
|
+
runOnSessionStart(rawCtx) {
|
|
14415
|
+
const ctx = this.withHost(rawCtx);
|
|
14375
14416
|
for (const plugin of this.plugins) {
|
|
14376
14417
|
if (plugin.onSessionStart) {
|
|
14377
14418
|
try {
|
|
@@ -14380,7 +14421,8 @@ class PluginManager {
|
|
|
14380
14421
|
}
|
|
14381
14422
|
}
|
|
14382
14423
|
}
|
|
14383
|
-
runOnBeforeThink(
|
|
14424
|
+
runOnBeforeThink(rawCtx) {
|
|
14425
|
+
const ctx = this.withHost(rawCtx);
|
|
14384
14426
|
for (const plugin of this.plugins) {
|
|
14385
14427
|
if (plugin.onBeforeThink) {
|
|
14386
14428
|
try {
|
|
@@ -14389,7 +14431,8 @@ class PluginManager {
|
|
|
14389
14431
|
}
|
|
14390
14432
|
}
|
|
14391
14433
|
}
|
|
14392
|
-
runOnAfterThink(
|
|
14434
|
+
runOnAfterThink(rawCtx, response) {
|
|
14435
|
+
const ctx = this.withHost(rawCtx);
|
|
14393
14436
|
for (const plugin of this.plugins) {
|
|
14394
14437
|
if (plugin.onAfterThink) {
|
|
14395
14438
|
try {
|
|
@@ -14398,7 +14441,8 @@ class PluginManager {
|
|
|
14398
14441
|
}
|
|
14399
14442
|
}
|
|
14400
14443
|
}
|
|
14401
|
-
runOnSessionEnd(
|
|
14444
|
+
runOnSessionEnd(rawCtx) {
|
|
14445
|
+
const ctx = this.withHost(rawCtx);
|
|
14402
14446
|
for (const plugin of this.plugins) {
|
|
14403
14447
|
if (plugin.onSessionEnd) {
|
|
14404
14448
|
try {
|
|
@@ -14407,7 +14451,8 @@ class PluginManager {
|
|
|
14407
14451
|
}
|
|
14408
14452
|
}
|
|
14409
14453
|
}
|
|
14410
|
-
runOnToolCall(
|
|
14454
|
+
runOnToolCall(rawCtx) {
|
|
14455
|
+
const ctx = this.withHost(rawCtx);
|
|
14411
14456
|
for (const plugin of this.plugins) {
|
|
14412
14457
|
if (plugin.onToolCall) {
|
|
14413
14458
|
try {
|
|
@@ -14416,7 +14461,8 @@ class PluginManager {
|
|
|
14416
14461
|
}
|
|
14417
14462
|
}
|
|
14418
14463
|
}
|
|
14419
|
-
runOnPhase(
|
|
14464
|
+
runOnPhase(rawCtx, phase) {
|
|
14465
|
+
const ctx = this.withHost(rawCtx);
|
|
14420
14466
|
for (const plugin of this.plugins) {
|
|
14421
14467
|
if (plugin.onPhase) {
|
|
14422
14468
|
try {
|
|
@@ -14425,7 +14471,8 @@ class PluginManager {
|
|
|
14425
14471
|
}
|
|
14426
14472
|
}
|
|
14427
14473
|
}
|
|
14428
|
-
runOnToolStart(
|
|
14474
|
+
runOnToolStart(rawCtx, call) {
|
|
14475
|
+
const ctx = this.withHost(rawCtx);
|
|
14429
14476
|
for (const plugin of this.plugins) {
|
|
14430
14477
|
if (plugin.onToolStart) {
|
|
14431
14478
|
try {
|
|
@@ -14434,7 +14481,8 @@ class PluginManager {
|
|
|
14434
14481
|
}
|
|
14435
14482
|
}
|
|
14436
14483
|
}
|
|
14437
|
-
runOnToolEnd(
|
|
14484
|
+
runOnToolEnd(rawCtx, call, result, durationMs) {
|
|
14485
|
+
const ctx = this.withHost(rawCtx);
|
|
14438
14486
|
for (const plugin of this.plugins) {
|
|
14439
14487
|
if (plugin.onToolEnd) {
|
|
14440
14488
|
try {
|
|
@@ -14443,7 +14491,8 @@ class PluginManager {
|
|
|
14443
14491
|
}
|
|
14444
14492
|
}
|
|
14445
14493
|
}
|
|
14446
|
-
runOnText(
|
|
14494
|
+
runOnText(rawCtx, chunk) {
|
|
14495
|
+
const ctx = this.withHost(rawCtx);
|
|
14447
14496
|
for (const plugin of this.plugins) {
|
|
14448
14497
|
if (plugin.onText) {
|
|
14449
14498
|
try {
|
|
@@ -14455,7 +14504,8 @@ class PluginManager {
|
|
|
14455
14504
|
}
|
|
14456
14505
|
return chunk;
|
|
14457
14506
|
}
|
|
14458
|
-
runOnMeta(
|
|
14507
|
+
runOnMeta(rawCtx, chunk) {
|
|
14508
|
+
const ctx = this.withHost(rawCtx);
|
|
14459
14509
|
for (const plugin of this.plugins) {
|
|
14460
14510
|
if (plugin.onMeta) {
|
|
14461
14511
|
try {
|
|
@@ -14467,6 +14517,16 @@ class PluginManager {
|
|
|
14467
14517
|
}
|
|
14468
14518
|
return chunk;
|
|
14469
14519
|
}
|
|
14520
|
+
runOnTurnEnd(rawCtx, summary) {
|
|
14521
|
+
const ctx = this.withHost(rawCtx);
|
|
14522
|
+
for (const plugin of this.plugins) {
|
|
14523
|
+
if (plugin.onTurnEnd) {
|
|
14524
|
+
try {
|
|
14525
|
+
plugin.onTurnEnd(ctx, summary);
|
|
14526
|
+
} catch {}
|
|
14527
|
+
}
|
|
14528
|
+
}
|
|
14529
|
+
}
|
|
14470
14530
|
}
|
|
14471
14531
|
var init_manager3 = __esm(() => {
|
|
14472
14532
|
init_checker();
|
|
@@ -35050,6 +35110,22 @@ function formatContextBar(used, limit, compactions, quality) {
|
|
|
35050
35110
|
}
|
|
35051
35111
|
return line;
|
|
35052
35112
|
}
|
|
35113
|
+
function createHostBridge(opts) {
|
|
35114
|
+
return {
|
|
35115
|
+
isBusy: opts.isBusy,
|
|
35116
|
+
async submit(text, o) {
|
|
35117
|
+
if (opts.isBusy())
|
|
35118
|
+
throw new Error("agent is busy");
|
|
35119
|
+
for (const url of o?.images ?? [])
|
|
35120
|
+
opts.addPendingImage(url);
|
|
35121
|
+
return opts.runAgent(text);
|
|
35122
|
+
},
|
|
35123
|
+
interrupt() {
|
|
35124
|
+
if (opts.isBusy())
|
|
35125
|
+
opts.interruptRun();
|
|
35126
|
+
}
|
|
35127
|
+
};
|
|
35128
|
+
}
|
|
35053
35129
|
|
|
35054
35130
|
class Repl {
|
|
35055
35131
|
completer = new Completer;
|
|
@@ -35122,6 +35198,19 @@ class Repl {
|
|
|
35122
35198
|
registerAllCommands(this);
|
|
35123
35199
|
this.setupCompleter();
|
|
35124
35200
|
this.setupListeners();
|
|
35201
|
+
if (pluginManager) {
|
|
35202
|
+
pluginManager.setHostBridge(createHostBridge({
|
|
35203
|
+
isBusy: () => this.agentRunning,
|
|
35204
|
+
addPendingImage: (url) => {
|
|
35205
|
+
this.agent.contextManager?.addPendingImage?.({
|
|
35206
|
+
type: "image_url",
|
|
35207
|
+
image_url: { url }
|
|
35208
|
+
});
|
|
35209
|
+
},
|
|
35210
|
+
runAgent: (text) => this.runAgent(text),
|
|
35211
|
+
interruptRun: () => this.agent.shutdown()
|
|
35212
|
+
}));
|
|
35213
|
+
}
|
|
35125
35214
|
}
|
|
35126
35215
|
loadHistory() {
|
|
35127
35216
|
if (existsSync52(this.historyPath)) {
|