micro-models-agent 0.24.4 → 0.24.5

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.
Files changed (2) hide show
  1. package/dist/main.js +22 -8
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -4435,12 +4435,12 @@ class OpenAICompatProvider {
4435
4435
  };
4436
4436
  this.rateLimiter = createRateLimiter(config.rateLimits);
4437
4437
  }
4438
- async* chat(messages, tools) {
4438
+ async* chat(messages, tools, signal) {
4439
4439
  if (!this.rateLimiter.canMakeRequest()) {
4440
4440
  throw new Error(`Rate limit exceeded: ${this.rateLimiter.getConfig().maxRequestsPerMinute} requests per minute`);
4441
4441
  }
4442
4442
  this.rateLimiter.recordRequest();
4443
- const streamResult = this.doStream(messages, tools);
4443
+ const streamResult = this.doStream(messages, tools, signal);
4444
4444
  let hasToolCall = false;
4445
4445
  let hasText = false;
4446
4446
  let reasoningAcc = "";
@@ -4455,13 +4455,13 @@ class OpenAICompatProvider {
4455
4455
  yield chunk;
4456
4456
  }
4457
4457
  if (!hasToolCall && !hasText) {
4458
- const fallback = await this.doNonStreaming(messages, tools);
4458
+ const fallback = await this.doNonStreaming(messages, tools, signal);
4459
4459
  for (const chunk of fallback) {
4460
4460
  yield chunk;
4461
4461
  }
4462
4462
  }
4463
4463
  }
4464
- async* doStream(messages, tools) {
4464
+ async* doStream(messages, tools, externalSignal) {
4465
4465
  const body = {
4466
4466
  model: this.model,
4467
4467
  messages,
@@ -4488,6 +4488,15 @@ class OpenAICompatProvider {
4488
4488
  const controller = new AbortController;
4489
4489
  const totalTimeoutMs = 120000;
4490
4490
  const timeoutId = setTimeout(() => controller.abort(), totalTimeoutMs);
4491
+ if (externalSignal) {
4492
+ if (externalSignal.aborted) {
4493
+ controller.abort();
4494
+ } else {
4495
+ externalSignal.addEventListener("abort", () => controller.abort(), {
4496
+ once: true
4497
+ });
4498
+ }
4499
+ }
4491
4500
  const response = await this.fetchWithRetry(`${this.config.baseUrl}/chat/completions`, {
4492
4501
  method: "POST",
4493
4502
  headers,
@@ -4591,7 +4600,7 @@ class OpenAICompatProvider {
4591
4600
  reader.releaseLock();
4592
4601
  }
4593
4602
  }
4594
- async doNonStreaming(messages, tools) {
4603
+ async doNonStreaming(messages, tools, externalSignal) {
4595
4604
  const body = {
4596
4605
  model: this.model,
4597
4606
  messages,
@@ -4616,11 +4625,15 @@ class OpenAICompatProvider {
4616
4625
  headers["Authorization"] = `Bearer ${this.config.apiKey}`;
4617
4626
  }
4618
4627
  try {
4619
- const response = await this.fetchWithRetry(`${this.config.baseUrl}/chat/completions`, {
4628
+ const fetchInit = {
4620
4629
  method: "POST",
4621
4630
  headers,
4622
4631
  body: JSON.stringify(body)
4623
- });
4632
+ };
4633
+ if (externalSignal) {
4634
+ fetchInit.signal = externalSignal;
4635
+ }
4636
+ const response = await this.fetchWithRetry(`${this.config.baseUrl}/chat/completions`, fetchInit);
4624
4637
  if (!response.ok) {
4625
4638
  const errorText = await response.text();
4626
4639
  throw new Error(t("error.llm_api", {
@@ -9329,7 +9342,7 @@ ${t("tool.truncated", { tokens: Math.ceil(removedChars / 2) })}`;
9329
9342
  const textChunks = [];
9330
9343
  this.emitPhase(iteration, "thinking", onPhase);
9331
9344
  try {
9332
- for await (const chunk of llmProvider.chat(history, allTools)) {
9345
+ for await (const chunk of llmProvider.chat(history, allTools, this.abortController?.signal)) {
9333
9346
  if (this.shutdownRequested)
9334
9347
  break;
9335
9348
  if (chunk.type === "text" && chunk.content) {
@@ -26256,6 +26269,7 @@ class Repl {
26256
26269
  ${t("repl.interrupt")}
26257
26270
  `));
26258
26271
  this.agent.shutdown();
26272
+ setTimeout(() => process.exit(1), 3000);
26259
26273
  }
26260
26274
  this.lastEscTime = 0;
26261
26275
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "micro-models-agent",
3
- "version": "0.24.4",
3
+ "version": "0.24.5",
4
4
  "description": "Micro Models Agent (MMA) — LLM agent harness for small models (Qwen3.5-9B, 32K-64K context)",
5
5
  "type": "module",
6
6
  "bin": {