@bastani/pi-ai 0.9.80 → 0.9.81

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 (49) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +8 -11
  3. package/dist/api/anthropic-messages.js +3 -1
  4. package/dist/api/anthropic-messages.js.map +1 -1
  5. package/dist/api/constrained-sampling.d.ts.map +1 -1
  6. package/dist/api/constrained-sampling.js +3 -0
  7. package/dist/api/constrained-sampling.js.map +1 -1
  8. package/dist/api/google-generative-ai.d.ts.map +1 -1
  9. package/dist/api/google-generative-ai.js +5 -10
  10. package/dist/api/google-generative-ai.js.map +1 -1
  11. package/dist/api/google-shared.d.ts +0 -4
  12. package/dist/api/google-shared.d.ts.map +1 -1
  13. package/dist/api/google-shared.js +1 -13
  14. package/dist/api/google-shared.js.map +1 -1
  15. package/dist/api/google-vertex.d.ts.map +1 -1
  16. package/dist/api/google-vertex.js +11 -13
  17. package/dist/api/google-vertex.js.map +1 -1
  18. package/dist/env-api-keys.js +7 -7
  19. package/dist/env-api-keys.js.map +1 -1
  20. package/dist/providers/data/.manifest.json +1 -1
  21. package/dist/providers/data/google-vertex.json +1 -1
  22. package/dist/providers/data/google.json +1 -1
  23. package/dist/providers/data/opencode.json +1 -1
  24. package/dist/providers/data/openrouter.json +1 -1
  25. package/dist/providers/data/qwen-token-plan-cn.json +1 -1
  26. package/dist/providers/data/qwen-token-plan-individual-cn.json +1 -1
  27. package/dist/providers/data/qwen-token-plan-individual.json +1 -1
  28. package/dist/providers/data/qwen-token-plan.json +1 -1
  29. package/dist/providers/data/radius.json +1 -1
  30. package/dist/providers/data/vercel-ai-gateway.json +1 -1
  31. package/dist/providers/qwen-token-plan-cn.d.ts.map +1 -1
  32. package/dist/providers/qwen-token-plan-cn.js +8 -3
  33. package/dist/providers/qwen-token-plan-cn.js.map +1 -1
  34. package/dist/providers/qwen-token-plan-individual-cn.d.ts.map +1 -1
  35. package/dist/providers/qwen-token-plan-individual-cn.js +7 -2
  36. package/dist/providers/qwen-token-plan-individual-cn.js.map +1 -1
  37. package/dist/providers/qwen-token-plan-individual.d.ts.map +1 -1
  38. package/dist/providers/qwen-token-plan-individual.js +7 -2
  39. package/dist/providers/qwen-token-plan-individual.js.map +1 -1
  40. package/dist/providers/qwen-token-plan.d.ts.map +1 -1
  41. package/dist/providers/qwen-token-plan.js +8 -3
  42. package/dist/providers/qwen-token-plan.js.map +1 -1
  43. package/dist/utils/retry.d.ts.map +1 -1
  44. package/dist/utils/retry.js +1 -0
  45. package/dist/utils/retry.js.map +1 -1
  46. package/dist/utils/version.d.ts +1 -1
  47. package/dist/utils/version.js +1 -1
  48. package/dist/utils/version.js.map +1 -1
  49. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"qwen-token-plan-cn.d.ts","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-cn.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,uBAAuB,IAAI,QAAQ,CAAC,oBAAoB,CAAC,CASxE"}
1
+ {"version":3,"file":"qwen-token-plan-cn.d.ts","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-cn.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,uBAAuB,IAAI,QAAQ,CAAC,oBAAoB,CAAC,CAcxE"}
@@ -5,9 +5,14 @@ import { QWEN_TOKEN_PLAN_CN_MODELS } from "./qwen-token-plan-cn.models.js";
5
5
  export function qwenTokenPlanCnProvider() {
6
6
  return createProvider({
7
7
  id: "qwen-token-plan-cn",
8
- name: "Qwen Token Plan CN",
9
- baseUrl: "https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
10
- auth: { apiKey: envApiKeyAuth("Qwen Token Plan CN API key", ["QWEN_TOKEN_PLAN_CN_API_KEY"]) },
8
+ name: "Qwen Token Plan Team CN",
9
+ baseUrl: "https://token-plan.maas.qianwenaiapi.com/compatible-mode/v1",
10
+ auth: {
11
+ apiKey: envApiKeyAuth("Qwen Token Plan Team CN API key", [
12
+ "QWEN_TOKEN_PLAN_TEAM_CN_API_KEY",
13
+ "QWEN_TOKEN_PLAN_CN_API_KEY",
14
+ ]),
15
+ },
11
16
  models: Object.values(QWEN_TOKEN_PLAN_CN_MODELS),
12
17
  api: openAICompletionsApi(),
13
18
  });
@@ -1 +1 @@
1
- {"version":3,"file":"qwen-token-plan-cn.js","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-cn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,MAAM,UAAU,uBAAuB;IACtC,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,oBAAoB;QACxB,IAAI,EAAE,oBAAoB;QAC1B,OAAO,EAAE,oEAAoE;QAC7E,IAAI,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,4BAA4B,EAAE,CAAC,4BAA4B,CAAC,CAAC,EAAE;QAC7F,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,yBAAyB,CAAC;QAChD,GAAG,EAAE,oBAAoB,EAAE;KAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { envApiKeyAuth } from \"../auth/helpers.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { QWEN_TOKEN_PLAN_CN_MODELS } from \"./qwen-token-plan-cn.models.ts\";\n\nexport function qwenTokenPlanCnProvider(): Provider<\"openai-completions\"> {\n\treturn createProvider({\n\t\tid: \"qwen-token-plan-cn\",\n\t\tname: \"Qwen Token Plan CN\",\n\t\tbaseUrl: \"https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1\",\n\t\tauth: { apiKey: envApiKeyAuth(\"Qwen Token Plan CN API key\", [\"QWEN_TOKEN_PLAN_CN_API_KEY\"]) },\n\t\tmodels: Object.values(QWEN_TOKEN_PLAN_CN_MODELS),\n\t\tapi: openAICompletionsApi(),\n\t});\n}\n"]}
1
+ {"version":3,"file":"qwen-token-plan-cn.js","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-cn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,MAAM,UAAU,uBAAuB;IACtC,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,oBAAoB;QACxB,IAAI,EAAE,yBAAyB;QAC/B,OAAO,EAAE,6DAA6D;QACtE,IAAI,EAAE;YACL,MAAM,EAAE,aAAa,CAAC,iCAAiC,EAAE;gBACxD,iCAAiC;gBACjC,4BAA4B;aAC5B,CAAC;SACF;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,yBAAyB,CAAC;QAChD,GAAG,EAAE,oBAAoB,EAAE;KAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { envApiKeyAuth } from \"../auth/helpers.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { QWEN_TOKEN_PLAN_CN_MODELS } from \"./qwen-token-plan-cn.models.ts\";\n\nexport function qwenTokenPlanCnProvider(): Provider<\"openai-completions\"> {\n\treturn createProvider({\n\t\tid: \"qwen-token-plan-cn\",\n\t\tname: \"Qwen Token Plan Team CN\",\n\t\tbaseUrl: \"https://token-plan.maas.qianwenaiapi.com/compatible-mode/v1\",\n\t\tauth: {\n\t\t\tapiKey: envApiKeyAuth(\"Qwen Token Plan Team CN API key\", [\n\t\t\t\t\"QWEN_TOKEN_PLAN_TEAM_CN_API_KEY\",\n\t\t\t\t\"QWEN_TOKEN_PLAN_CN_API_KEY\",\n\t\t\t]),\n\t\t},\n\t\tmodels: Object.values(QWEN_TOKEN_PLAN_CN_MODELS),\n\t\tapi: openAICompletionsApi(),\n\t});\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"qwen-token-plan-individual-cn.d.ts","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-individual-cn.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,iCAAiC,IAAI,QAAQ,CAAC,oBAAoB,CAAC,CASlF"}
1
+ {"version":3,"file":"qwen-token-plan-individual-cn.d.ts","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-individual-cn.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,iCAAiC,IAAI,QAAQ,CAAC,oBAAoB,CAAC,CAclF"}
@@ -6,8 +6,13 @@ export function qwenTokenPlanIndividualCnProvider() {
6
6
  return createProvider({
7
7
  id: "qwen-token-plan-individual-cn",
8
8
  name: "Qwen Token Plan Individual CN",
9
- baseUrl: "https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
10
- auth: { apiKey: envApiKeyAuth("Qwen Token Plan Individual CN API key", ["QWEN_TOKEN_PLAN_CN_API_KEY"]) },
9
+ baseUrl: "https://token-plan.maas.qianwenaiapi.com/compatible-mode/v1",
10
+ auth: {
11
+ apiKey: envApiKeyAuth("Qwen Token Plan Individual CN API key", [
12
+ "QWEN_TOKEN_PLAN_INDIVIDUAL_CN_API_KEY",
13
+ "QWEN_TOKEN_PLAN_CN_API_KEY",
14
+ ]),
15
+ },
11
16
  models: Object.values(QWEN_TOKEN_PLAN_INDIVIDUAL_CN_MODELS),
12
17
  api: openAICompletionsApi(),
13
18
  });
@@ -1 +1 @@
1
- {"version":3,"file":"qwen-token-plan-individual-cn.js","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-individual-cn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,oCAAoC,EAAE,MAAM,2CAA2C,CAAC;AAEjG,MAAM,UAAU,iCAAiC;IAChD,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,+BAA+B;QACnC,IAAI,EAAE,+BAA+B;QACrC,OAAO,EAAE,oEAAoE;QAC7E,IAAI,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,uCAAuC,EAAE,CAAC,4BAA4B,CAAC,CAAC,EAAE;QACxG,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,oCAAoC,CAAC;QAC3D,GAAG,EAAE,oBAAoB,EAAE;KAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { envApiKeyAuth } from \"../auth/helpers.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { QWEN_TOKEN_PLAN_INDIVIDUAL_CN_MODELS } from \"./qwen-token-plan-individual-cn.models.ts\";\n\nexport function qwenTokenPlanIndividualCnProvider(): Provider<\"openai-completions\"> {\n\treturn createProvider({\n\t\tid: \"qwen-token-plan-individual-cn\",\n\t\tname: \"Qwen Token Plan Individual CN\",\n\t\tbaseUrl: \"https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1\",\n\t\tauth: { apiKey: envApiKeyAuth(\"Qwen Token Plan Individual CN API key\", [\"QWEN_TOKEN_PLAN_CN_API_KEY\"]) },\n\t\tmodels: Object.values(QWEN_TOKEN_PLAN_INDIVIDUAL_CN_MODELS),\n\t\tapi: openAICompletionsApi(),\n\t});\n}\n"]}
1
+ {"version":3,"file":"qwen-token-plan-individual-cn.js","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-individual-cn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,oCAAoC,EAAE,MAAM,2CAA2C,CAAC;AAEjG,MAAM,UAAU,iCAAiC;IAChD,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,+BAA+B;QACnC,IAAI,EAAE,+BAA+B;QACrC,OAAO,EAAE,6DAA6D;QACtE,IAAI,EAAE;YACL,MAAM,EAAE,aAAa,CAAC,uCAAuC,EAAE;gBAC9D,uCAAuC;gBACvC,4BAA4B;aAC5B,CAAC;SACF;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,oCAAoC,CAAC;QAC3D,GAAG,EAAE,oBAAoB,EAAE;KAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { envApiKeyAuth } from \"../auth/helpers.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { QWEN_TOKEN_PLAN_INDIVIDUAL_CN_MODELS } from \"./qwen-token-plan-individual-cn.models.ts\";\n\nexport function qwenTokenPlanIndividualCnProvider(): Provider<\"openai-completions\"> {\n\treturn createProvider({\n\t\tid: \"qwen-token-plan-individual-cn\",\n\t\tname: \"Qwen Token Plan Individual CN\",\n\t\tbaseUrl: \"https://token-plan.maas.qianwenaiapi.com/compatible-mode/v1\",\n\t\tauth: {\n\t\t\tapiKey: envApiKeyAuth(\"Qwen Token Plan Individual CN API key\", [\n\t\t\t\t\"QWEN_TOKEN_PLAN_INDIVIDUAL_CN_API_KEY\",\n\t\t\t\t\"QWEN_TOKEN_PLAN_CN_API_KEY\",\n\t\t\t]),\n\t\t},\n\t\tmodels: Object.values(QWEN_TOKEN_PLAN_INDIVIDUAL_CN_MODELS),\n\t\tapi: openAICompletionsApi(),\n\t});\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"qwen-token-plan-individual.d.ts","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-individual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,+BAA+B,IAAI,QAAQ,CAAC,oBAAoB,CAAC,CAShF"}
1
+ {"version":3,"file":"qwen-token-plan-individual.d.ts","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-individual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,+BAA+B,IAAI,QAAQ,CAAC,oBAAoB,CAAC,CAchF"}
@@ -6,8 +6,13 @@ export function qwenTokenPlanIndividualProvider() {
6
6
  return createProvider({
7
7
  id: "qwen-token-plan-individual",
8
8
  name: "Qwen Token Plan Individual",
9
- baseUrl: "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
10
- auth: { apiKey: envApiKeyAuth("Qwen Token Plan Individual API key", ["QWEN_TOKEN_PLAN_API_KEY"]) },
9
+ baseUrl: "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1",
10
+ auth: {
11
+ apiKey: envApiKeyAuth("Qwen Token Plan Individual API key", [
12
+ "QWEN_TOKEN_PLAN_INDIVIDUAL_API_KEY",
13
+ "QWEN_TOKEN_PLAN_API_KEY",
14
+ ]),
15
+ },
11
16
  models: Object.values(QWEN_TOKEN_PLAN_INDIVIDUAL_MODELS),
12
17
  api: openAICompletionsApi(),
13
18
  });
@@ -1 +1 @@
1
- {"version":3,"file":"qwen-token-plan-individual.js","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-individual.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAE3F,MAAM,UAAU,+BAA+B;IAC9C,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,4BAA4B;QAChC,IAAI,EAAE,4BAA4B;QAClC,OAAO,EAAE,wEAAwE;QACjF,IAAI,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,oCAAoC,EAAE,CAAC,yBAAyB,CAAC,CAAC,EAAE;QAClG,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,iCAAiC,CAAC;QACxD,GAAG,EAAE,oBAAoB,EAAE;KAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { envApiKeyAuth } from \"../auth/helpers.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { QWEN_TOKEN_PLAN_INDIVIDUAL_MODELS } from \"./qwen-token-plan-individual.models.ts\";\n\nexport function qwenTokenPlanIndividualProvider(): Provider<\"openai-completions\"> {\n\treturn createProvider({\n\t\tid: \"qwen-token-plan-individual\",\n\t\tname: \"Qwen Token Plan Individual\",\n\t\tbaseUrl: \"https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1\",\n\t\tauth: { apiKey: envApiKeyAuth(\"Qwen Token Plan Individual API key\", [\"QWEN_TOKEN_PLAN_API_KEY\"]) },\n\t\tmodels: Object.values(QWEN_TOKEN_PLAN_INDIVIDUAL_MODELS),\n\t\tapi: openAICompletionsApi(),\n\t});\n}\n"]}
1
+ {"version":3,"file":"qwen-token-plan-individual.js","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-individual.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAE3F,MAAM,UAAU,+BAA+B;IAC9C,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,4BAA4B;QAChC,IAAI,EAAE,4BAA4B;QAClC,OAAO,EAAE,6DAA6D;QACtE,IAAI,EAAE;YACL,MAAM,EAAE,aAAa,CAAC,oCAAoC,EAAE;gBAC3D,oCAAoC;gBACpC,yBAAyB;aACzB,CAAC;SACF;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,iCAAiC,CAAC;QACxD,GAAG,EAAE,oBAAoB,EAAE;KAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { envApiKeyAuth } from \"../auth/helpers.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { QWEN_TOKEN_PLAN_INDIVIDUAL_MODELS } from \"./qwen-token-plan-individual.models.ts\";\n\nexport function qwenTokenPlanIndividualProvider(): Provider<\"openai-completions\"> {\n\treturn createProvider({\n\t\tid: \"qwen-token-plan-individual\",\n\t\tname: \"Qwen Token Plan Individual\",\n\t\tbaseUrl: \"https://token-plan.maas.qwencloudapi.com/compatible-mode/v1\",\n\t\tauth: {\n\t\t\tapiKey: envApiKeyAuth(\"Qwen Token Plan Individual API key\", [\n\t\t\t\t\"QWEN_TOKEN_PLAN_INDIVIDUAL_API_KEY\",\n\t\t\t\t\"QWEN_TOKEN_PLAN_API_KEY\",\n\t\t\t]),\n\t\t},\n\t\tmodels: Object.values(QWEN_TOKEN_PLAN_INDIVIDUAL_MODELS),\n\t\tapi: openAICompletionsApi(),\n\t});\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"qwen-token-plan.d.ts","sourceRoot":"","sources":["../../src/providers/qwen-token-plan.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,qBAAqB,IAAI,QAAQ,CAAC,oBAAoB,CAAC,CAStE"}
1
+ {"version":3,"file":"qwen-token-plan.d.ts","sourceRoot":"","sources":["../../src/providers/qwen-token-plan.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,qBAAqB,IAAI,QAAQ,CAAC,oBAAoB,CAAC,CActE"}
@@ -5,9 +5,14 @@ import { QWEN_TOKEN_PLAN_MODELS } from "./qwen-token-plan.models.js";
5
5
  export function qwenTokenPlanProvider() {
6
6
  return createProvider({
7
7
  id: "qwen-token-plan",
8
- name: "Qwen Token Plan",
9
- baseUrl: "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
10
- auth: { apiKey: envApiKeyAuth("Qwen Token Plan API key", ["QWEN_TOKEN_PLAN_API_KEY"]) },
8
+ name: "Qwen Token Plan Team",
9
+ baseUrl: "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1",
10
+ auth: {
11
+ apiKey: envApiKeyAuth("Qwen Token Plan Team API key", [
12
+ "QWEN_TOKEN_PLAN_TEAM_API_KEY",
13
+ "QWEN_TOKEN_PLAN_API_KEY",
14
+ ]),
15
+ },
11
16
  models: Object.values(QWEN_TOKEN_PLAN_MODELS),
12
17
  api: openAICompletionsApi(),
13
18
  });
@@ -1 +1 @@
1
- {"version":3,"file":"qwen-token-plan.js","sourceRoot":"","sources":["../../src/providers/qwen-token-plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,MAAM,UAAU,qBAAqB;IACpC,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,iBAAiB;QACrB,IAAI,EAAE,iBAAiB;QACvB,OAAO,EAAE,wEAAwE;QACjF,IAAI,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,yBAAyB,EAAE,CAAC,yBAAyB,CAAC,CAAC,EAAE;QACvF,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC;QAC7C,GAAG,EAAE,oBAAoB,EAAE;KAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { envApiKeyAuth } from \"../auth/helpers.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { QWEN_TOKEN_PLAN_MODELS } from \"./qwen-token-plan.models.ts\";\n\nexport function qwenTokenPlanProvider(): Provider<\"openai-completions\"> {\n\treturn createProvider({\n\t\tid: \"qwen-token-plan\",\n\t\tname: \"Qwen Token Plan\",\n\t\tbaseUrl: \"https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1\",\n\t\tauth: { apiKey: envApiKeyAuth(\"Qwen Token Plan API key\", [\"QWEN_TOKEN_PLAN_API_KEY\"]) },\n\t\tmodels: Object.values(QWEN_TOKEN_PLAN_MODELS),\n\t\tapi: openAICompletionsApi(),\n\t});\n}\n"]}
1
+ {"version":3,"file":"qwen-token-plan.js","sourceRoot":"","sources":["../../src/providers/qwen-token-plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,MAAM,UAAU,qBAAqB;IACpC,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,iBAAiB;QACrB,IAAI,EAAE,sBAAsB;QAC5B,OAAO,EAAE,6DAA6D;QACtE,IAAI,EAAE;YACL,MAAM,EAAE,aAAa,CAAC,8BAA8B,EAAE;gBACrD,8BAA8B;gBAC9B,yBAAyB;aACzB,CAAC;SACF;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC;QAC7C,GAAG,EAAE,oBAAoB,EAAE;KAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { envApiKeyAuth } from \"../auth/helpers.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { QWEN_TOKEN_PLAN_MODELS } from \"./qwen-token-plan.models.ts\";\n\nexport function qwenTokenPlanProvider(): Provider<\"openai-completions\"> {\n\treturn createProvider({\n\t\tid: \"qwen-token-plan\",\n\t\tname: \"Qwen Token Plan Team\",\n\t\tbaseUrl: \"https://token-plan.maas.qwencloudapi.com/compatible-mode/v1\",\n\t\tauth: {\n\t\t\tapiKey: envApiKeyAuth(\"Qwen Token Plan Team API key\", [\n\t\t\t\t\"QWEN_TOKEN_PLAN_TEAM_API_KEY\",\n\t\t\t\t\"QWEN_TOKEN_PLAN_API_KEY\",\n\t\t\t]),\n\t\t},\n\t\tmodels: Object.values(QWEN_TOKEN_PLAN_MODELS),\n\t\tapi: openAICompletionsApi(),\n\t});\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAsIpD;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,qFAAqF;IACrF,UAAU,EAAE,MAAM,CAAC;IACnB,0FAA0F;IAC1F,WAAW,EAAE,MAAM,CAAC;IACpB,sEAA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AAgB,qBAAqB,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAGrH;AAED,kFAAkF;AAClF,MAAM,WAAW,cAAc;IAC9B,0EAA0E;IAC1E,gBAAgB,CAAC,EAAE,CAClB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,KAChB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,mFAAmF;IACnF,mBAAmB,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,mFAAmF;IACnF,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnG;AA0BD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,kBAAkB,CACvC,OAAO,EAAE,MAAM,OAAO,CAAC,gBAAgB,CAAC,EACxC,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,SAAS,CAAC,EAAE,cAAc,GACxB,OAAO,CAAC,gBAAgB,CAAC,CA4C3B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAOxE"}
@@ -57,6 +57,7 @@ const RETRYABLE_PROVIDER_ERROR_PATTERN = buildProviderErrorPattern([
57
57
  "connection.?error",
58
58
  "connection.?refused",
59
59
  "connection.?lost",
60
+ "connection.?closed",
60
61
  "ECONNRESET",
61
62
  "connection.?reset",
62
63
  "other side closed",
@@ -1 +1 @@
1
- {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB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AQ,CAAC,YAAY,IAAI,eAAe,EAAE,CAAC;QAChF,MAAM,SAAS,EAAE,gBAAgB,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC;QAE3F,8EAA8E;QAC9E,qFAAqF;QACrF,IAAI,CAAC;YACJ,MAAM,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC9B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,SAAS,EAAE,eAAe,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC;YAC3E,IAAI,KAAK,YAAY,oBAAoB,EAAE,CAAC;gBAC3C,OAAO,EAAE,GAAG,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;YACxE,CAAC;YACD,MAAM,KAAK,CAAC;QACb,CAAC;QACD,MAAM,SAAS,EAAE,mBAAmB,EAAE,EAAE,CAAC;IAC1C,CAAC;AACF,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAqB;IAC9D,IAAI,OAAO,CAAC,UAAU,KAAK,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY;QAAE,OAAO,KAAK,CAAC;IAC1E,MAAM,YAAY,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IACpD,IAAI,YAAY,KAAK,SAAS;QAAE,OAAO,YAAY,CAAC,SAAS,CAAC;IAC9D,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC1C,IAAI,0CAA0C,CAAC,IAAI,CAAC,YAAY,CAAC;QAAE,OAAO,KAAK,CAAC;IAChF,OAAO,gCAAgC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import { getGitHubCopilotError } from \"../providers/github-copilot-errors.ts\";\nimport type { AssistantMessage } from \"../types.ts\";\n\nfunction buildProviderErrorPattern(patterns: readonly string[]): RegExp {\n\treturn new RegExp(patterns.join(\"|\"), \"i\");\n}\n\nconst NON_RETRYABLE_PROVIDER_LIMIT_ERROR_PATTERN = buildProviderErrorPattern([\n\t// OpenCode Go/free-tier limits returned as 429 JSON error types by OpenCode's\n\t// Zen API. These are subscription/account limits, not transient throttles.\n\t\"GoUsageLimitError\",\n\t\"FreeUsageLimitError\",\n\n\t// OpenCode Go subscription-limit text asks users to enable available-balance\n\t// usage after rolling/weekly/monthly limits are reached.\n\t\"Monthly usage limit reached\",\n\t\"available balance\",\n\n\t// Generic quota/budget/billing exhaustion. `insufficient_quota` is OpenAI's\n\t// quota/billing error code; the other strings cover common gateway wording.\n\t\"insufficient_quota\",\n\t\"out of budget\",\n\t\"quota exceeded\",\n\t\"billing\",\n\t\"subscription_sharing_usage_limit_exceeded\",\n\t// Sign in with ChatGPT on a ChatGPT Business plan: a usage limit set by the\n\t// workspace admin. Only the admin can raise it.\n\t\"subscription_sharing_workplace_individual_usage_limit_exceeded\",\n\n\t// Zhipu/Z.ai (open.bigmodel.cn) error code 1308: the plan's usage limit is\n\t// reached, sent as HTTP 429. It resets after hours, not seconds (#11537).\n\t'\"code\"\\\\s*:\\\\s*\"?1308(?![0-9])',\n]);\n\nconst RETRYABLE_PROVIDER_ERROR_PATTERN = buildProviderErrorPattern([\n\t// Generic provider load, HTTP status, and server-side transient failures.\n\t\"overloaded\",\n\t\"server_busy\",\n\t\"servers are currently busy\",\n\t\"currently experiencing high demand\",\n\t\"model is at capacity\",\n\t\"rate.?limit\",\n\t\"too many requests\",\n\t// Status codes must not be part of a longer word or number, e.g. a request id or byte count (#11057).\n\t// 521-523 are Cloudflare origin errors (#3623); 529 is an overload response.\n\t\"(?<![a-z0-9])(?:429|500|502|503|504|52[0-4]|529)(?![a-z0-9])\",\n\t// Also matches \"The service is temporarily unavailable\" (#10965).\n\t\"service.?(?:is.?)?(?:temporarily.?)?unavailable\",\n\t\"server.?error\",\n\t\"internal.?error\",\n\n\t// Wrapper/provider text for transient upstream failures, including OpenRouter\n\t// \"Provider returned error\" responses (#2264).\n\t\"provider.?returned.?(?:an.?)?error\",\n\t\"exceeded request buffer limit while retrying upstream\",\n\t\"unable to forward upstream\",\n\t\"upstream.?request.?failed\",\n\t\"upstream_stream_read_error\",\n\t\"stream was interrupted\",\n\t\"http/?2 stream failed\",\n\n\t// Network, proxy, and fetch transport failures. This includes OpenAI Codex\n\t// raw-fetch failures such as \"upstream connect\", \"connection refused\", and\n\t// \"reset before headers\" (#733), plus OpenRouter connection drops (#3317).\n\t\"network.?error\",\n\t\"connection.?error\",\n\t\"connection.?refused\",\n\t\"connection.?lost\",\n\t\"ECONNRESET\",\n\t\"connection.?reset\",\n\t\"other side closed\",\n\t\"fetch failed\",\n\t\"request to \\\\S+ failed, reason:\",\n\t\"getaddrinfo\",\n\t\"ENOTFOUND\",\n\t\"EAI_AGAIN\",\n\t\"upstream.?connect\",\n\t\"reset before headers\",\n\t\"socket hang up\",\n\t\"socket connection was closed\",\n\t\"timed? out\",\n\t\"timeout\",\n\t\"terminated\",\n\n\t// WebSocket transports can report close/error text instead of HTTP/fetch text.\n\t\"websocket.?closed\",\n\t\"websocket.?error\",\n\n\t// Response-body decompression failures. Node/Bun zlib rejects a body whose\n\t// Content-Encoding lied or whose compressed bytes were corrupted, and the\n\t// fetch/WebSocket layer wraps it with a \"Library error:\" prefix. GitHub\n\t// Copilot on the default `transport: \"auto\"` reports this as\n\t// \"Library error: zlib error: incorrect header check\" (#2553). The transfer\n\t// is already unusable, and a fresh attempt normally succeeds, so treat every\n\t// variant as a transient transport failure rather than a deterministic error.\n\t\"zlib\",\n\t\"incorrect header check\",\n\t\"decompress\",\n\t\"library error\",\n\n\t// Idle-stream deadline enforced below the HTTP layer by `withStreamDeadline`\n\t// so a stream that never settles cannot hang an attempt forever (#2553).\n\t\"stream deadline exceeded\",\n\n\t// Premature stream endings from SDKs and transports. Anthropic can throw\n\t// \"stream ended without ...\" and \"Anthropic stream ended before message_stop\"\n\t// (#4433); Bedrock/Smithy can throw an HTTP/2 no-response error (#3594).\n\t\"ended without\",\n\t\"stream ended before message_stop\",\n\t\"stream ended before a terminal response event\",\n\t\"http2 request did not get a response\",\n\t// Codex CLI mid-stream disconnect, relayed by proxies that wrap the Codex CLI,\n\t// e.g. \"stream disconnected before completion: stream closed before response.completed\" (#11057).\n\t\"stream disconnected before completion\",\n\t// Magpie gateway relaying a dropped upstream Anthropic stream, e.g.\n\t// \"Claude Code's stream from Anthropic was cut short after the reply had begun\" (#11879).\n\t\"cut short after the reply had begun\",\n\t\"pending stream has been canceled\",\n\n\t// Provider-requested retry delay cap failures should flow through the outer\n\t// retry policy so callers can surface/abort the backoff (#1123).\n\t\"retry delay\",\n\n\t// Explicit retry guidance emitted mid-stream by OpenAI Responses and Bedrock\n\t// stream exceptions (#6019).\n\t\"you can retry your request\",\n\t\"try your request again\",\n\t\"please retry your request\",\n\n\t// gRPC based providers (e.g. NVIDIA NIM)\n\t\"ResourceExhausted\",\n\t\"subscription_sharing_usage_unavailable\",\n\t\"subscription_sharing_user_unavailable\",\n]);\n\n/**\n * Retry policy: bounded attempts with exponential backoff (`baseDelayMs * 2^(attempt-1)`).\n * Each delay is capped by `maxAgentDelayMs` (60 seconds by default).\n * Matches `settings.retry` (`enabled`, `maxRetries`, `baseDelayMs`) in coding-agent; kept\n * here so the classifier and the policy-driven retry loop live together and stay reusable\n * by the SDK and other callers.\n */\nexport interface RetryPolicy {\n\tenabled: boolean;\n\t/** Max retry attempts (0 = no retries). The initial call never counts as a retry. */\n\tmaxRetries: number;\n\t/** Base delay in ms. Per-attempt delay is `baseDelayMs * 2^(attempt-1)` before jitter. */\n\tbaseDelayMs: number;\n\t/** Cap for agent-level retry delays in ms. Defaults to 60 seconds. */\n\tmaxAgentDelayMs?: number;\n\t/**\n\t * Cap for a server retry hint (`Retry-After-Ms`, `Retry-After`, a body `retry_after`).\n\t * Defaults to 60 seconds; 0 caps the hint by `maxAgentDelayMs` instead.\n\t */\n\tmaxRetryDelayMs?: number;\n}\n\nexport const DEFAULT_MAX_AGENT_RETRY_DELAY_MS = 60_000;\n\nexport function retryDelayMs(policy: Pick<RetryPolicy, \"baseDelayMs\" | \"maxAgentDelayMs\">, attempt: number): number {\n\tconst delay = policy.baseDelayMs * 2 ** Math.max(0, attempt - 1);\n\tconst safeDelay = Number.isSafeInteger(delay) ? delay : Number.MAX_SAFE_INTEGER;\n\treturn Math.min(safeDelay, policy.maxAgentDelayMs ?? DEFAULT_MAX_AGENT_RETRY_DELAY_MS);\n}\n\ntype RetryFailure = Pick<AssistantMessage, \"stopReason\" | \"errorMessage\" | \"retryAfterMs\" | \"diagnostics\">;\n\n/**\n * Wait before retry `attempt` (1-indexed): the server retry hint when the failure\n * carries one, capped by `maxRetryDelayMs`, otherwise the exponential backoff.\n */\nexport function failureRetryDelayMs(\n\tpolicy: Pick<RetryPolicy, \"baseDelayMs\" | \"maxAgentDelayMs\" | \"maxRetryDelayMs\">,\n\tattempt: number,\n\tfailure: Pick<AssistantMessage, \"retryAfterMs\">,\n): number {\n\tconst hintMs = failure.retryAfterMs;\n\tif (hintMs === undefined || !Number.isFinite(hintMs) || hintMs <= 0) return retryDelayMs(policy, attempt);\n\tconst capMs = policy.maxRetryDelayMs || (policy.maxAgentDelayMs ?? DEFAULT_MAX_AGENT_RETRY_DELAY_MS);\n\treturn Math.min(hintMs, capMs);\n}\n\n/**\n * Delay before retry `attempt` (1-indexed) of a failed assistant call, or `undefined`\n * when it is not retryable or `maxRetries` is spent.\n */\nexport function assistantRetryDelayMs(policy: RetryPolicy, attempt: number, message: RetryFailure): number | undefined {\n\tif (!policy.enabled || attempt > policy.maxRetries || !isRetryableAssistantError(message)) return undefined;\n\treturn failureRetryDelayMs(policy, attempt, message);\n}\n\n/** Optional callbacks emitted by {@link retryAssistantCall} around each retry. */\nexport interface RetryCallbacks {\n\t/** Emitted before the backoff sleep of each retry attempt (1-indexed). */\n\tonRetryScheduled?: (\n\t\tattempt: number,\n\t\tmaxAttempts: number,\n\t\tdelayMs: number,\n\t\terrorMessage: string,\n\t) => void | Promise<void>;\n\t/** Emitted after the backoff sleep, immediately before the retried call starts. */\n\tonRetryAttemptStart?: () => void | Promise<void>;\n\t/** Emitted once when the loop ends: success if a later call completed normally. */\n\tonRetryFinished?: (success: boolean, attempt: number, finalError?: string) => void | Promise<void>;\n}\n\nclass RetrySleepAbortError extends Error {\n\tconstructor() {\n\t\tsuper(\"Aborted\");\n\t}\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(new RetrySleepAbortError());\n\t\t\treturn;\n\t\t}\n\t\tconst timeout = setTimeout(resolve, ms);\n\t\tsignal?.addEventListener(\n\t\t\t\"abort\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\treject(new RetrySleepAbortError());\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t});\n}\n\n/**\n * Run a single assistant-producing call with bounded retry on transient errors.\n *\n * Behavior:\n * - A successful response is returned immediately. Aborts are terminal and never\n * retried, but reported as unsuccessful if they happen after a retry was scheduled.\n * Aborts during the backoff sleep are normalized to an aborted `AssistantMessage`\n * too, so callers do not need to care when cancellation happened.\n * - A non-retryable error (per {@link isRetryableAssistantError}, including quota/\n * billing exhaustion) is returned immediately so deterministic errors fail fast.\n * - Otherwise retries up to `maxRetries` times, waiting for the server retry hint or\n * the exponential backoff (see {@link assistantRetryDelayMs}), emitting\n * `onRetryScheduled` before each sleep, `onRetryAttemptStart` after each sleep before\n * the retried call starts, and `onRetryFinished` once at the end (whether the loop\n * ends in success, exhausted retries, or an aborted backoff).\n *\n * When `policy` is undefined or disabled, the first response is returned unchanged\n * (equivalent to calling `produce()` directly).\n */\nexport async function retryAssistantCall(\n\tproduce: () => Promise<AssistantMessage>,\n\tpolicy: RetryPolicy | undefined,\n\tsignal: AbortSignal | undefined,\n\tcallbacks?: RetryCallbacks,\n): Promise<AssistantMessage> {\n\tconst maxAttempts = policy?.enabled ? policy.maxRetries : 0;\n\n\tlet attempt = 0;\n\tlet lastRetry: { attempt: number; errorMessage: string } | undefined;\n\tfor (;;) {\n\t\tconst response = await produce();\n\n\t\t// Abort: terminal but not successful. Never retry an aborted message.\n\t\tif (response.stopReason === \"aborted\") {\n\t\t\tif (lastRetry) await callbacks?.onRetryFinished?.(false, lastRetry.attempt);\n\t\t\treturn response;\n\t\t}\n\n\t\t// Success: non-error, non-abort responses return as-is.\n\t\tif (response.stopReason !== \"error\") {\n\t\t\tif (lastRetry) await callbacks?.onRetryFinished?.(true, lastRetry.attempt);\n\t\t\treturn response;\n\t\t}\n\n\t\t// Non-retryable, or budget exhausted: return the final error message.\n\t\tconst delayMs = policy ? assistantRetryDelayMs(policy, attempt + 1, response) : undefined;\n\t\tif (delayMs === undefined) {\n\t\t\tif (lastRetry) await callbacks?.onRetryFinished?.(false, lastRetry.attempt, response.errorMessage);\n\t\t\treturn response;\n\t\t}\n\n\t\tattempt++;\n\t\tlastRetry = { attempt, errorMessage: response.errorMessage || \"Unknown error\" };\n\t\tawait callbacks?.onRetryScheduled?.(attempt, maxAttempts, delayMs, lastRetry.errorMessage);\n\n\t\t// Normalize aborts during retry backoff to the same AssistantMessage shape as\n\t\t// provider stream aborts, so callers do not need to care when cancellation happened.\n\t\ttry {\n\t\t\tawait sleep(delayMs, signal);\n\t\t} catch (error) {\n\t\t\tawait callbacks?.onRetryFinished?.(false, attempt, lastRetry.errorMessage);\n\t\t\tif (error instanceof RetrySleepAbortError) {\n\t\t\t\treturn { ...response, stopReason: \"aborted\", errorMessage: undefined };\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tawait callbacks?.onRetryAttemptStart?.();\n\t}\n}\n\n/**\n * Classifies whether a failed assistant message looks like a transient provider\n * or transport error, so callers can decide if the last assistant turn should be\n * restarted.\n *\n * A GitHub Copilot failure carries its typed error, whose `retryable` decides.\n *\n * This does not implement retry policy. Callers should first handle context\n * overflow separately, then apply their own retry budget, backoff, and reporting\n * before restarting the assistant turn.\n */\nexport function isRetryableAssistantError(message: RetryFailure): boolean {\n\tif (message.stopReason !== \"error\" || !message.errorMessage) return false;\n\tconst copilotError = getGitHubCopilotError(message);\n\tif (copilotError !== undefined) return copilotError.retryable;\n\tconst errorMessage = message.errorMessage;\n\tif (NON_RETRYABLE_PROVIDER_LIMIT_ERROR_PATTERN.test(errorMessage)) return false;\n\treturn RETRYABLE_PROVIDER_ERROR_PATTERN.test(errorMessage);\n}\n"]}
1
+ {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAG9E,SAAS,yBAAyB,CAAC,QAA2B;IAC7D,OAAO,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,0CAA0C,GAAG,yBAAyB,CAAC;IAC5E,8EAA8E;IAC9E,2EAA2E;IAC3E,mBAAmB;IACnB,qBAAqB;IAErB,6EAA6E;IAC7E,yDAAyD;IACzD,6BAA6B;IAC7B,mBAAmB;IAEnB,4EAA4E;IAC5E,4EAA4E;IAC5E,oBAAoB;IACpB,eAAe;IACf,gBAAgB;IAChB,SAAS;IACT,2CAA2C;IAC3C,4EAA4E;IAC5E,gDAAgD;IAChD,gEAAgE;IAEhE,2EAA2E;IAC3E,0EAA0E;IAC1E,gCAAgC;CAChC,CAAC,CAAC;AAEH,MAAM,gCAAgC,GAAG,yBAAyB,CAAC;IAClE,0EAA0E;IAC1E,YAAY;IACZ,aAAa;IACb,4BAA4B;IAC5B,oCAAoC;IACpC,sBAAsB;IACtB,aAAa;IACb,mBAAmB;IACnB,sGAAsG;IACtG,6EAA6E;IAC7E,8DAA8D;IAC9D,kEAAkE;IAClE,iDAAiD;IACjD,eAAe;IACf,iBAAiB;IAEjB,8EAA8E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QAAE,OAAO,KAAK,CAAC;IAC1E,MAAM,YAAY,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IACpD,IAAI,YAAY,KAAK,SAAS;QAAE,OAAO,YAAY,CAAC,SAAS,CAAC;IAC9D,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC1C,IAAI,0CAA0C,CAAC,IAAI,CAAC,YAAY,CAAC;QAAE,OAAO,KAAK,CAAC;IAChF,OAAO,gCAAgC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import { getGitHubCopilotError } from \"../providers/github-copilot-errors.ts\";\nimport type { AssistantMessage } from \"../types.ts\";\n\nfunction buildProviderErrorPattern(patterns: readonly string[]): RegExp {\n\treturn new RegExp(patterns.join(\"|\"), \"i\");\n}\n\nconst NON_RETRYABLE_PROVIDER_LIMIT_ERROR_PATTERN = buildProviderErrorPattern([\n\t// OpenCode Go/free-tier limits returned as 429 JSON error types by OpenCode's\n\t// Zen API. These are subscription/account limits, not transient throttles.\n\t\"GoUsageLimitError\",\n\t\"FreeUsageLimitError\",\n\n\t// OpenCode Go subscription-limit text asks users to enable available-balance\n\t// usage after rolling/weekly/monthly limits are reached.\n\t\"Monthly usage limit reached\",\n\t\"available balance\",\n\n\t// Generic quota/budget/billing exhaustion. `insufficient_quota` is OpenAI's\n\t// quota/billing error code; the other strings cover common gateway wording.\n\t\"insufficient_quota\",\n\t\"out of budget\",\n\t\"quota exceeded\",\n\t\"billing\",\n\t\"subscription_sharing_usage_limit_exceeded\",\n\t// Sign in with ChatGPT on a ChatGPT Business plan: a usage limit set by the\n\t// workspace admin. Only the admin can raise it.\n\t\"subscription_sharing_workplace_individual_usage_limit_exceeded\",\n\n\t// Zhipu/Z.ai (open.bigmodel.cn) error code 1308: the plan's usage limit is\n\t// reached, sent as HTTP 429. It resets after hours, not seconds (#11537).\n\t'\"code\"\\\\s*:\\\\s*\"?1308(?![0-9])',\n]);\n\nconst RETRYABLE_PROVIDER_ERROR_PATTERN = buildProviderErrorPattern([\n\t// Generic provider load, HTTP status, and server-side transient failures.\n\t\"overloaded\",\n\t\"server_busy\",\n\t\"servers are currently busy\",\n\t\"currently experiencing high demand\",\n\t\"model is at capacity\",\n\t\"rate.?limit\",\n\t\"too many requests\",\n\t// Status codes must not be part of a longer word or number, e.g. a request id or byte count (#11057).\n\t// 521-523 are Cloudflare origin errors (#3623); 529 is an overload response.\n\t\"(?<![a-z0-9])(?:429|500|502|503|504|52[0-4]|529)(?![a-z0-9])\",\n\t// Also matches \"The service is temporarily unavailable\" (#10965).\n\t\"service.?(?:is.?)?(?:temporarily.?)?unavailable\",\n\t\"server.?error\",\n\t\"internal.?error\",\n\n\t// Wrapper/provider text for transient upstream failures, including OpenRouter\n\t// \"Provider returned error\" responses (#2264).\n\t\"provider.?returned.?(?:an.?)?error\",\n\t\"exceeded request buffer limit while retrying upstream\",\n\t\"unable to forward upstream\",\n\t\"upstream.?request.?failed\",\n\t\"upstream_stream_read_error\",\n\t\"stream was interrupted\",\n\t\"http/?2 stream failed\",\n\n\t// Network, proxy, and fetch transport failures. This includes OpenAI Codex\n\t// raw-fetch failures such as \"upstream connect\", \"connection refused\", and\n\t// \"reset before headers\" (#733), plus OpenRouter connection drops (#3317).\n\t\"network.?error\",\n\t\"connection.?error\",\n\t\"connection.?refused\",\n\t\"connection.?lost\",\n\t\"connection.?closed\",\n\t\"ECONNRESET\",\n\t\"connection.?reset\",\n\t\"other side closed\",\n\t\"fetch failed\",\n\t\"request to \\\\S+ failed, reason:\",\n\t\"getaddrinfo\",\n\t\"ENOTFOUND\",\n\t\"EAI_AGAIN\",\n\t\"upstream.?connect\",\n\t\"reset before headers\",\n\t\"socket hang up\",\n\t\"socket connection was closed\",\n\t\"timed? out\",\n\t\"timeout\",\n\t\"terminated\",\n\n\t// WebSocket transports can report close/error text instead of HTTP/fetch text.\n\t\"websocket.?closed\",\n\t\"websocket.?error\",\n\n\t// Response-body decompression failures. Node/Bun zlib rejects a body whose\n\t// Content-Encoding lied or whose compressed bytes were corrupted, and the\n\t// fetch/WebSocket layer wraps it with a \"Library error:\" prefix. GitHub\n\t// Copilot on the default `transport: \"auto\"` reports this as\n\t// \"Library error: zlib error: incorrect header check\" (#2553). The transfer\n\t// is already unusable, and a fresh attempt normally succeeds, so treat every\n\t// variant as a transient transport failure rather than a deterministic error.\n\t\"zlib\",\n\t\"incorrect header check\",\n\t\"decompress\",\n\t\"library error\",\n\n\t// Idle-stream deadline enforced below the HTTP layer by `withStreamDeadline`\n\t// so a stream that never settles cannot hang an attempt forever (#2553).\n\t\"stream deadline exceeded\",\n\n\t// Premature stream endings from SDKs and transports. Anthropic can throw\n\t// \"stream ended without ...\" and \"Anthropic stream ended before message_stop\"\n\t// (#4433); Bedrock/Smithy can throw an HTTP/2 no-response error (#3594).\n\t\"ended without\",\n\t\"stream ended before message_stop\",\n\t\"stream ended before a terminal response event\",\n\t\"http2 request did not get a response\",\n\t// Codex CLI mid-stream disconnect, relayed by proxies that wrap the Codex CLI,\n\t// e.g. \"stream disconnected before completion: stream closed before response.completed\" (#11057).\n\t\"stream disconnected before completion\",\n\t// Magpie gateway relaying a dropped upstream Anthropic stream, e.g.\n\t// \"Claude Code's stream from Anthropic was cut short after the reply had begun\" (#11879).\n\t\"cut short after the reply had begun\",\n\t\"pending stream has been canceled\",\n\n\t// Provider-requested retry delay cap failures should flow through the outer\n\t// retry policy so callers can surface/abort the backoff (#1123).\n\t\"retry delay\",\n\n\t// Explicit retry guidance emitted mid-stream by OpenAI Responses and Bedrock\n\t// stream exceptions (#6019).\n\t\"you can retry your request\",\n\t\"try your request again\",\n\t\"please retry your request\",\n\n\t// gRPC based providers (e.g. NVIDIA NIM)\n\t\"ResourceExhausted\",\n\t\"subscription_sharing_usage_unavailable\",\n\t\"subscription_sharing_user_unavailable\",\n]);\n\n/**\n * Retry policy: bounded attempts with exponential backoff (`baseDelayMs * 2^(attempt-1)`).\n * Each delay is capped by `maxAgentDelayMs` (60 seconds by default).\n * Matches `settings.retry` (`enabled`, `maxRetries`, `baseDelayMs`) in coding-agent; kept\n * here so the classifier and the policy-driven retry loop live together and stay reusable\n * by the SDK and other callers.\n */\nexport interface RetryPolicy {\n\tenabled: boolean;\n\t/** Max retry attempts (0 = no retries). The initial call never counts as a retry. */\n\tmaxRetries: number;\n\t/** Base delay in ms. Per-attempt delay is `baseDelayMs * 2^(attempt-1)` before jitter. */\n\tbaseDelayMs: number;\n\t/** Cap for agent-level retry delays in ms. Defaults to 60 seconds. */\n\tmaxAgentDelayMs?: number;\n\t/**\n\t * Cap for a server retry hint (`Retry-After-Ms`, `Retry-After`, a body `retry_after`).\n\t * Defaults to 60 seconds; 0 caps the hint by `maxAgentDelayMs` instead.\n\t */\n\tmaxRetryDelayMs?: number;\n}\n\nexport const DEFAULT_MAX_AGENT_RETRY_DELAY_MS = 60_000;\n\nexport function retryDelayMs(policy: Pick<RetryPolicy, \"baseDelayMs\" | \"maxAgentDelayMs\">, attempt: number): number {\n\tconst delay = policy.baseDelayMs * 2 ** Math.max(0, attempt - 1);\n\tconst safeDelay = Number.isSafeInteger(delay) ? delay : Number.MAX_SAFE_INTEGER;\n\treturn Math.min(safeDelay, policy.maxAgentDelayMs ?? DEFAULT_MAX_AGENT_RETRY_DELAY_MS);\n}\n\ntype RetryFailure = Pick<AssistantMessage, \"stopReason\" | \"errorMessage\" | \"retryAfterMs\" | \"diagnostics\">;\n\n/**\n * Wait before retry `attempt` (1-indexed): the server retry hint when the failure\n * carries one, capped by `maxRetryDelayMs`, otherwise the exponential backoff.\n */\nexport function failureRetryDelayMs(\n\tpolicy: Pick<RetryPolicy, \"baseDelayMs\" | \"maxAgentDelayMs\" | \"maxRetryDelayMs\">,\n\tattempt: number,\n\tfailure: Pick<AssistantMessage, \"retryAfterMs\">,\n): number {\n\tconst hintMs = failure.retryAfterMs;\n\tif (hintMs === undefined || !Number.isFinite(hintMs) || hintMs <= 0) return retryDelayMs(policy, attempt);\n\tconst capMs = policy.maxRetryDelayMs || (policy.maxAgentDelayMs ?? DEFAULT_MAX_AGENT_RETRY_DELAY_MS);\n\treturn Math.min(hintMs, capMs);\n}\n\n/**\n * Delay before retry `attempt` (1-indexed) of a failed assistant call, or `undefined`\n * when it is not retryable or `maxRetries` is spent.\n */\nexport function assistantRetryDelayMs(policy: RetryPolicy, attempt: number, message: RetryFailure): number | undefined {\n\tif (!policy.enabled || attempt > policy.maxRetries || !isRetryableAssistantError(message)) return undefined;\n\treturn failureRetryDelayMs(policy, attempt, message);\n}\n\n/** Optional callbacks emitted by {@link retryAssistantCall} around each retry. */\nexport interface RetryCallbacks {\n\t/** Emitted before the backoff sleep of each retry attempt (1-indexed). */\n\tonRetryScheduled?: (\n\t\tattempt: number,\n\t\tmaxAttempts: number,\n\t\tdelayMs: number,\n\t\terrorMessage: string,\n\t) => void | Promise<void>;\n\t/** Emitted after the backoff sleep, immediately before the retried call starts. */\n\tonRetryAttemptStart?: () => void | Promise<void>;\n\t/** Emitted once when the loop ends: success if a later call completed normally. */\n\tonRetryFinished?: (success: boolean, attempt: number, finalError?: string) => void | Promise<void>;\n}\n\nclass RetrySleepAbortError extends Error {\n\tconstructor() {\n\t\tsuper(\"Aborted\");\n\t}\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(new RetrySleepAbortError());\n\t\t\treturn;\n\t\t}\n\t\tconst timeout = setTimeout(resolve, ms);\n\t\tsignal?.addEventListener(\n\t\t\t\"abort\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\treject(new RetrySleepAbortError());\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t});\n}\n\n/**\n * Run a single assistant-producing call with bounded retry on transient errors.\n *\n * Behavior:\n * - A successful response is returned immediately. Aborts are terminal and never\n * retried, but reported as unsuccessful if they happen after a retry was scheduled.\n * Aborts during the backoff sleep are normalized to an aborted `AssistantMessage`\n * too, so callers do not need to care when cancellation happened.\n * - A non-retryable error (per {@link isRetryableAssistantError}, including quota/\n * billing exhaustion) is returned immediately so deterministic errors fail fast.\n * - Otherwise retries up to `maxRetries` times, waiting for the server retry hint or\n * the exponential backoff (see {@link assistantRetryDelayMs}), emitting\n * `onRetryScheduled` before each sleep, `onRetryAttemptStart` after each sleep before\n * the retried call starts, and `onRetryFinished` once at the end (whether the loop\n * ends in success, exhausted retries, or an aborted backoff).\n *\n * When `policy` is undefined or disabled, the first response is returned unchanged\n * (equivalent to calling `produce()` directly).\n */\nexport async function retryAssistantCall(\n\tproduce: () => Promise<AssistantMessage>,\n\tpolicy: RetryPolicy | undefined,\n\tsignal: AbortSignal | undefined,\n\tcallbacks?: RetryCallbacks,\n): Promise<AssistantMessage> {\n\tconst maxAttempts = policy?.enabled ? policy.maxRetries : 0;\n\n\tlet attempt = 0;\n\tlet lastRetry: { attempt: number; errorMessage: string } | undefined;\n\tfor (;;) {\n\t\tconst response = await produce();\n\n\t\t// Abort: terminal but not successful. Never retry an aborted message.\n\t\tif (response.stopReason === \"aborted\") {\n\t\t\tif (lastRetry) await callbacks?.onRetryFinished?.(false, lastRetry.attempt);\n\t\t\treturn response;\n\t\t}\n\n\t\t// Success: non-error, non-abort responses return as-is.\n\t\tif (response.stopReason !== \"error\") {\n\t\t\tif (lastRetry) await callbacks?.onRetryFinished?.(true, lastRetry.attempt);\n\t\t\treturn response;\n\t\t}\n\n\t\t// Non-retryable, or budget exhausted: return the final error message.\n\t\tconst delayMs = policy ? assistantRetryDelayMs(policy, attempt + 1, response) : undefined;\n\t\tif (delayMs === undefined) {\n\t\t\tif (lastRetry) await callbacks?.onRetryFinished?.(false, lastRetry.attempt, response.errorMessage);\n\t\t\treturn response;\n\t\t}\n\n\t\tattempt++;\n\t\tlastRetry = { attempt, errorMessage: response.errorMessage || \"Unknown error\" };\n\t\tawait callbacks?.onRetryScheduled?.(attempt, maxAttempts, delayMs, lastRetry.errorMessage);\n\n\t\t// Normalize aborts during retry backoff to the same AssistantMessage shape as\n\t\t// provider stream aborts, so callers do not need to care when cancellation happened.\n\t\ttry {\n\t\t\tawait sleep(delayMs, signal);\n\t\t} catch (error) {\n\t\t\tawait callbacks?.onRetryFinished?.(false, attempt, lastRetry.errorMessage);\n\t\t\tif (error instanceof RetrySleepAbortError) {\n\t\t\t\treturn { ...response, stopReason: \"aborted\", errorMessage: undefined };\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tawait callbacks?.onRetryAttemptStart?.();\n\t}\n}\n\n/**\n * Classifies whether a failed assistant message looks like a transient provider\n * or transport error, so callers can decide if the last assistant turn should be\n * restarted.\n *\n * A GitHub Copilot failure carries its typed error, whose `retryable` decides.\n *\n * This does not implement retry policy. Callers should first handle context\n * overflow separately, then apply their own retry budget, backoff, and reporting\n * before restarting the assistant turn.\n */\nexport function isRetryableAssistantError(message: RetryFailure): boolean {\n\tif (message.stopReason !== \"error\" || !message.errorMessage) return false;\n\tconst copilotError = getGitHubCopilotError(message);\n\tif (copilotError !== undefined) return copilotError.retryable;\n\tconst errorMessage = message.errorMessage;\n\tif (NON_RETRYABLE_PROVIDER_LIMIT_ERROR_PATTERN.test(errorMessage)) return false;\n\treturn RETRYABLE_PROVIDER_ERROR_PATTERN.test(errorMessage);\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const PI_AI_VERSION = "0.9.80";
1
+ export declare const PI_AI_VERSION = "0.9.81";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,3 +1,3 @@
1
1
  // The @bastani/pi-ai package version. scripts/bump-version.ts keeps it in sync with package.json.
2
- export const PI_AI_VERSION = "0.9.80";
2
+ export const PI_AI_VERSION = "0.9.81";
3
3
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC","sourcesContent":["// The @bastani/pi-ai package version. scripts/bump-version.ts keeps it in sync with package.json.\nexport const PI_AI_VERSION = \"0.9.80\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC","sourcesContent":["// The @bastani/pi-ai package version. scripts/bump-version.ts keeps it in sync with package.json.\nexport const PI_AI_VERSION = \"0.9.81\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/pi-ai",
3
- "version": "0.9.80",
3
+ "version": "0.9.81",
4
4
  "description": "Bastani-branded unified LLM API with automatic model discovery and provider configuration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -91,7 +91,7 @@
91
91
  "@aws-sdk/client-bedrock-runtime": "3.1127.0",
92
92
  "@earendil-works/pi-schema": "1.5.2",
93
93
  "@earendil-works/pi-telemetry": "1.5.2",
94
- "@google/genai": "2.21.0",
94
+ "@google/genai": "2.32.0",
95
95
  "@smithy/node-http-handler": "4.13.0",
96
96
  "http-proxy-agent": "9.1.0",
97
97
  "https-proxy-agent": "9.1.0",