@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.js CHANGED
@@ -4581,6 +4581,18 @@ ${schemaDescription}`;
4581
4581
 
4582
4582
  // src/agents/qwen-agent.ts
4583
4583
  var import_openai9 = require("openai");
4584
+ function qwenRefusalFrom(model, apiError) {
4585
+ const message = apiError instanceof Error ? apiError.message : String(apiError);
4586
+ if (!/DataInspectionFailed|inappropriate content/i.test(message)) {
4587
+ return void 0;
4588
+ }
4589
+ const detail = message.replace(/^[\s\S]*DataInspectionFailed:\s*/, "").trim();
4590
+ return new ModelRefusalError(
4591
+ model,
4592
+ `${model} refused the prompt (refusalReason: DataInspectionFailed${detail ? `; ${detail}` : ""})`,
4593
+ "DataInspectionFailed"
4594
+ );
4595
+ }
4584
4596
  var QwenAgent = class extends AbstractAgent {
4585
4597
  client;
4586
4598
  // A getter, not a field: `maxOutputTokens` can be raised after construction, and a field
@@ -4705,7 +4717,7 @@ ${schemaDescription}`;
4705
4717
  completion = await this.client.chat.completions.create(params);
4706
4718
  } catch (apiError) {
4707
4719
  this.logger(this.logTemplates.error(this.name, apiError));
4708
- throw new Error(this.errorMessages.apiError(apiError));
4720
+ throw qwenRefusalFrom(this.model, apiError) ?? new Error(this.errorMessages.apiError(apiError));
4709
4721
  }
4710
4722
  const rawReply = completion.choices[0]?.message?.content;
4711
4723
  if (!rawReply) {
@@ -4725,6 +4737,9 @@ ${schemaDescription}`;
4725
4737
  return [validated, thinkingContent, tokenUsage];
4726
4738
  } catch (error) {
4727
4739
  this.logger(this.logTemplates.error(this.name, error));
4740
+ if (error instanceof ModelError) {
4741
+ throw error;
4742
+ }
4728
4743
  throw new Error(this.errorMessages.apiError(error));
4729
4744
  }
4730
4745
  }
@@ -4758,7 +4773,7 @@ ${openAIMessages[0].content}`;
4758
4773
  completion = await this.client.chat.completions.create(params);
4759
4774
  } catch (apiError) {
4760
4775
  this.logger(this.logTemplates.error(this.name, apiError));
4761
- throw new Error(this.errorMessages.apiError(apiError));
4776
+ throw qwenRefusalFrom(this.model, apiError) ?? new Error(this.errorMessages.apiError(apiError));
4762
4777
  }
4763
4778
  const rawReply = completion.choices[0]?.message?.content;
4764
4779
  if (!rawReply) {
@@ -4774,6 +4789,9 @@ ${openAIMessages[0].content}`;
4774
4789
  return [reply, thinkingContent, tokenUsage];
4775
4790
  } catch (error) {
4776
4791
  this.logger(this.logTemplates.error(this.name, error));
4792
+ if (error instanceof ModelError) {
4793
+ throw error;
4794
+ }
4777
4795
  throw new Error(this.errorMessages.apiError(error));
4778
4796
  }
4779
4797
  }