@hiper2d/ai-agents 0.5.2 → 0.5.3

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.mjs CHANGED
@@ -4412,6 +4412,18 @@ ${schemaDescription}`;
4412
4412
 
4413
4413
  // src/agents/qwen-agent.ts
4414
4414
  import { OpenAI as OpenAI9 } from "openai";
4415
+ function qwenRefusalFrom(model, apiError) {
4416
+ const message = apiError instanceof Error ? apiError.message : String(apiError);
4417
+ if (!/DataInspectionFailed|inappropriate content/i.test(message)) {
4418
+ return void 0;
4419
+ }
4420
+ const detail = message.replace(/^[\s\S]*DataInspectionFailed:\s*/, "").trim();
4421
+ return new ModelRefusalError(
4422
+ model,
4423
+ `${model} refused the prompt (refusalReason: DataInspectionFailed${detail ? `; ${detail}` : ""})`,
4424
+ "DataInspectionFailed"
4425
+ );
4426
+ }
4415
4427
  var QwenAgent = class extends AbstractAgent {
4416
4428
  client;
4417
4429
  // A getter, not a field: `maxOutputTokens` can be raised after construction, and a field
@@ -4536,7 +4548,7 @@ ${schemaDescription}`;
4536
4548
  completion = await this.client.chat.completions.create(params);
4537
4549
  } catch (apiError) {
4538
4550
  this.logger(this.logTemplates.error(this.name, apiError));
4539
- throw new Error(this.errorMessages.apiError(apiError));
4551
+ throw qwenRefusalFrom(this.model, apiError) ?? new Error(this.errorMessages.apiError(apiError));
4540
4552
  }
4541
4553
  const rawReply = completion.choices[0]?.message?.content;
4542
4554
  if (!rawReply) {
@@ -4556,6 +4568,9 @@ ${schemaDescription}`;
4556
4568
  return [validated, thinkingContent, tokenUsage];
4557
4569
  } catch (error) {
4558
4570
  this.logger(this.logTemplates.error(this.name, error));
4571
+ if (error instanceof ModelError) {
4572
+ throw error;
4573
+ }
4559
4574
  throw new Error(this.errorMessages.apiError(error));
4560
4575
  }
4561
4576
  }
@@ -4589,7 +4604,7 @@ ${openAIMessages[0].content}`;
4589
4604
  completion = await this.client.chat.completions.create(params);
4590
4605
  } catch (apiError) {
4591
4606
  this.logger(this.logTemplates.error(this.name, apiError));
4592
- throw new Error(this.errorMessages.apiError(apiError));
4607
+ throw qwenRefusalFrom(this.model, apiError) ?? new Error(this.errorMessages.apiError(apiError));
4593
4608
  }
4594
4609
  const rawReply = completion.choices[0]?.message?.content;
4595
4610
  if (!rawReply) {
@@ -4605,6 +4620,9 @@ ${openAIMessages[0].content}`;
4605
4620
  return [reply, thinkingContent, tokenUsage];
4606
4621
  } catch (error) {
4607
4622
  this.logger(this.logTemplates.error(this.name, error));
4623
+ if (error instanceof ModelError) {
4624
+ throw error;
4625
+ }
4608
4626
  throw new Error(this.errorMessages.apiError(error));
4609
4627
  }
4610
4628
  }