@sixb/azure-ai-foundry 0.1.6 → 0.2.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"chat-request.d.ts","sourceRoot":"","sources":["../src/chat-request.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EAG1B,MAAM,mBAAmB,CAAA;AAM1B,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAA;IACjC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,UAAU,CAAA;IAC7B,0FAA0F;IAC1F,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IACxC,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAA;IAC5C,wGAAwG;IACxG,QAAQ,CAAC,kBAAkB,CAAC,EAAE,uBAAuB,GAAG,YAAY,CAAA;IACpE,oGAAoG;IACpG,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAA;IAC/B,mGAAmG;IACnG,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAAA;CACxD;AAwBD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAiBrE;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,oBAAoB,EAC7B,UAAU,EAAE,uBAAuB,EACnC,OAAO,EAAE,kBAAkB,EAC3B,KAAK,EAAE,MAAM,GACZ,UAAU,CAuFZ"}
1
+ {"version":3,"file":"chat-request.d.ts","sourceRoot":"","sources":["../src/chat-request.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EAG1B,MAAM,mBA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file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAEtD,gGAAgG;AAChG,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAE5C,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIxB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAM3B,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,kBAAkB;IAW5D,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK;CAO/B"}
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  UnsupportedModelFeatureError as UnsupportedModelFeatureError6
9
9
  } from "@sixb/core/models";
10
10
  import { chatEvents } from "@sixb/model-protocols/chat";
11
- import { messagesEvents } from "@sixb/model-protocols/messages";
11
+ import { isStrictToolLimitError, messagesEvents } from "@sixb/model-protocols/messages";
12
12
  import { responsesEvents } from "@sixb/model-protocols/responses";
13
13
 
14
14
  // src/accounting.ts
@@ -377,7 +377,7 @@ import {
377
377
  modelReasoningSupportIssue,
378
378
  UnsupportedModelFeatureError
379
379
  } from "@sixb/core/models";
380
- import { responsesInput } from "@sixb/model-protocols/responses";
380
+ import { requiredNullableSchema, responsesInput } from "@sixb/model-protocols/responses";
381
381
 
382
382
  // src/structured-output.ts
383
383
  import { isJsonObject as isJsonObject2 } from "@sixb/core/models";
@@ -393,7 +393,13 @@ var KEYWORDS = new Set([
393
393
  "anyOf",
394
394
  "$ref",
395
395
  "$defs",
396
- "definitions"
396
+ "definitions",
397
+ "minimum",
398
+ "maximum",
399
+ "minLength",
400
+ "maxLength",
401
+ "minItems",
402
+ "maxItems"
397
403
  ]);
398
404
  var TYPES = new Set(["object", "array", "string", "number", "integer", "boolean", "null"]);
399
405
  function foundryOutputSchema(schema) {
@@ -552,13 +558,16 @@ function responsesRequest(request, definition, options, scope, deployment) {
552
558
  }
553
559
  if (summary && (!caps.reasoning || typeof caps.reasoning !== "object"))
554
560
  throw new UnsupportedModelFeatureError(`${PREFIX} Reasoning summaries require a declared reasoning capability.`);
555
- const tools = request.tools.map((tool) => ({
556
- type: "function",
557
- name: tool.name,
558
- description: tool.description,
559
- parameters: tool.inputSchema,
560
- strict: caps.nativeStructuredOutput === true && foundryOutputSchema(tool.inputSchema) !== undefined
561
- }));
561
+ const tools = request.tools.map((tool) => {
562
+ const schema = caps.nativeStructuredOutput === true ? foundryStrictTool(tool) : undefined;
563
+ return {
564
+ type: "function",
565
+ name: tool.name,
566
+ description: tool.description,
567
+ parameters: schema ?? tool.inputSchema,
568
+ strict: schema !== undefined
569
+ };
570
+ });
562
571
  return {
563
572
  ...options.request,
564
573
  model: definition.modelId,
@@ -570,7 +579,7 @@ function responsesRequest(request, definition, options, scope, deployment) {
570
579
  ...tools.length ? {
571
580
  tools,
572
581
  tool_choice: "auto",
573
- parallel_tool_calls: !schema && !tools.some((t) => t.strict) && caps.parallelToolCalls === true
582
+ parallel_tool_calls: !schema && caps.parallelToolCalls === true
574
583
  } : {},
575
584
  ...reasoning !== undefined && reasoning !== "provider-default" || summary ? {
576
585
  reasoning: {
@@ -646,6 +655,12 @@ function checkScope(data, scope) {
646
655
  throw new UnsupportedModelFeatureError(`${PREFIX} Replay state belongs to a different endpoint, deployment, or protocol.`);
647
656
  }
648
657
  }
658
+ function foundryStrictTool(tool) {
659
+ if (!tool.strict)
660
+ return;
661
+ const schema = requiredNullableSchema(tool.inputSchema);
662
+ return foundryOutputSchema(schema) === undefined ? undefined : schema;
663
+ }
649
664
 
650
665
  // src/chat-request.ts
651
666
  var RESERVED2 = new Set([
@@ -705,17 +720,18 @@ function foundryChatRequest(request, definition, options, scope) {
705
720
  const schema = request.responseFormat && foundryOutputSchema(request.responseFormat.schema);
706
721
  if (request.responseFormat && (profile === "deepseek" || caps.nativeStructuredOutput !== true || !schema))
707
722
  throw new UnsupportedModelFeatureError2(`${PREFIX} Chat structured output requires verified OpenAI-compatible strict-schema support. DeepSeek JSON mode is not strict schema decoding.`);
708
- const tools = request.tools.map((tool) => ({
709
- type: "function",
710
- function: {
711
- name: tool.name,
712
- description: tool.description,
713
- parameters: tool.inputSchema,
714
- ...profile === "openai" ? {
715
- strict: caps.nativeStructuredOutput === true && foundryOutputSchema(tool.inputSchema) !== undefined
716
- } : {}
717
- }
718
- }));
723
+ const tools = request.tools.map((tool) => {
724
+ const strict = profile === "openai" && caps.nativeStructuredOutput === true ? foundryStrictTool(tool) : undefined;
725
+ return {
726
+ type: "function",
727
+ function: {
728
+ name: tool.name,
729
+ description: tool.description,
730
+ parameters: strict ?? tool.inputSchema,
731
+ ...profile === "openai" ? { strict: strict !== undefined } : {}
732
+ }
733
+ };
734
+ });
719
735
  return {
720
736
  ...options.request,
721
737
  model: definition.modelId,
@@ -733,7 +749,7 @@ function foundryChatRequest(request, definition, options, scope) {
733
749
  tools,
734
750
  tool_choice: "auto",
735
751
  ...profile === "openai" ? {
736
- parallel_tool_calls: !schema && !tools.some((tool) => tool.function.strict) && caps.parallelToolCalls === true
752
+ parallel_tool_calls: !schema && caps.parallelToolCalls === true
737
753
  } : {}
738
754
  } : {},
739
755
  ...schema && request.responseFormat ? {
@@ -776,7 +792,8 @@ class RequestDiagnostics {
776
792
  retryable: error.retryable,
777
793
  retryAfterMs: error.retryAfterMs,
778
794
  code: error.code === undefined ? undefined : this.text(error.code),
779
- requestId: error.requestId === undefined ? undefined : this.text(error.requestId)
795
+ requestId: error.requestId === undefined ? undefined : this.text(error.requestId),
796
+ reason: error.reason
780
797
  });
781
798
  }
782
799
  failure(error) {
@@ -790,6 +807,7 @@ class RequestDiagnostics {
790
807
 
791
808
  // src/transport.ts
792
809
  import { ModelProviderError as ModelProviderError2 } from "@sixb/core/models";
810
+ import { contextWindowRejection } from "@sixb/model-protocols/responses";
793
811
  class FoundryTransport {
794
812
  diagnostics = new WeakMap;
795
813
  baseUrl;
@@ -962,6 +980,7 @@ async function httpError(response, providerId, modelId, signal) {
962
980
  status: response.status,
963
981
  requestId: requestId(response),
964
982
  code,
983
+ ...contextWindowRejection({ status: response.status, code, message }),
965
984
  retryable: response.status === 408 || response.status === 429 || response.status >= 500,
966
985
  ...ms !== undefined && Number.isFinite(ms) && ms >= 0 ? { retryAfterMs: Math.ceil(ms) } : {}
967
986
  });
@@ -1521,7 +1540,12 @@ import {
1521
1540
  modelReasoningSupportIssue as modelReasoningSupportIssue3,
1522
1541
  UnsupportedModelFeatureError as UnsupportedModelFeatureError4
1523
1542
  } from "@sixb/core/models";
1524
- import { messagesInput } from "@sixb/model-protocols/messages";
1543
+ import {
1544
+ messagesInput,
1545
+ messagesStrictTools,
1546
+ StrictToolRefusals,
1547
+ strictToolsKey
1548
+ } from "@sixb/model-protocols/messages";
1525
1549
 
1526
1550
  // src/messages-schema.ts
1527
1551
  import { isJsonObject as isJsonObject4 } from "@sixb/core/models";
@@ -1599,6 +1623,7 @@ function messagesOutputSchema(schema) {
1599
1623
  }
1600
1624
 
1601
1625
  // src/messages-request.ts
1626
+ var strictToolRefusals = new StrictToolRefusals;
1602
1627
  var RESERVED3 = new Set([
1603
1628
  "model",
1604
1629
  "messages",
@@ -1630,7 +1655,7 @@ function validateMessagesOptions(options) {
1630
1655
  throw new TypeError(`${PREFIX} cache_control must be ephemeral with an optional 5m or 1h ttl.`);
1631
1656
  }
1632
1657
  }
1633
- function foundryMessagesRequest(request, definition, options, scope) {
1658
+ function foundryMessagesRequest(request, definition, options, scope, unconstrained = false) {
1634
1659
  const max = prepareRequest(request, definition, options, scope, true);
1635
1660
  let conversation = false;
1636
1661
  for (const message of request.messages) {
@@ -1655,7 +1680,17 @@ function foundryMessagesRequest(request, definition, options, scope) {
1655
1680
  ...thinking.effort === undefined ? {} : { effort: thinking.effort },
1656
1681
  ...schema ? { format: { type: "json_schema", schema } } : {}
1657
1682
  };
1658
- return {
1683
+ const candidates = request.tools.map((tool) => ({
1684
+ strict: tool.strict === true && caps.nativeStructuredOutput === true,
1685
+ schema: messagesOutputSchema(tool.inputSchema)
1686
+ }));
1687
+ const chosen = messagesStrictTools(candidates, schema);
1688
+ const constrained = request.tools.flatMap((tool, index) => chosen[index] ? [{ name: tool.name, input_schema: tool.inputSchema }] : []);
1689
+ const key = constrained.length === 0 ? undefined : strictToolsKey(constrained);
1690
+ const refused = unconstrained || key !== undefined && strictToolRefusals.has(key);
1691
+ const strict = chosen.map((choice) => choice && !refused);
1692
+ const strictTools = refused ? undefined : key;
1693
+ const body = {
1659
1694
  ...options.request,
1660
1695
  model: definition.modelId,
1661
1696
  messages: mapped.messages,
@@ -1665,15 +1700,16 @@ function foundryMessagesRequest(request, definition, options, scope) {
1665
1700
  ...thinking.thinking ? { thinking: thinking.thinking } : {},
1666
1701
  ...Object.keys(output).length ? { output_config: output } : {},
1667
1702
  ...request.tools.length ? {
1668
- tools: request.tools.map((tool) => ({
1703
+ tools: request.tools.map((tool, index) => ({
1669
1704
  name: tool.name,
1670
1705
  description: tool.description,
1671
1706
  input_schema: tool.inputSchema,
1672
- ...caps.nativeStructuredOutput === true && messagesOutputSchema(tool.inputSchema) ? { strict: true } : {}
1707
+ ...strict[index] ? { strict: true } : {}
1673
1708
  })),
1674
1709
  tool_choice: { type: "auto", disable_parallel_tool_use: caps.parallelToolCalls !== true }
1675
1710
  } : {}
1676
1711
  };
1712
+ return { body, ...strictTools === undefined ? {} : { strictTools } };
1677
1713
  }
1678
1714
  function reasoningRequest(request, definition, options, max) {
1679
1715
  const reasoning = request.reasoning;
@@ -1991,8 +2027,7 @@ class FoundryModel {
1991
2027
  const model = await abortable(() => this.#pendingExecution, request.signal);
1992
2028
  return model.stream(request);
1993
2029
  }
1994
- const body = this.protocol === "messages" ? foundryMessagesRequest(request, this.definition, this.options, this.scope) : this.protocol === "chat" ? foundryChatRequest(request, this.definition, this.options, this.scope) : responsesRequest(request, this.definition, this.options, this.scope, this.resolution?.deployment);
1995
- const response = await this.transport.post(JSON.stringify(body), request.signal, this.providerId, this.modelId, this.protocol);
2030
+ const response = this.protocol === "messages" ? await this.postMessages(request) : await this.transport.post(JSON.stringify(this.protocol === "chat" ? foundryChatRequest(request, this.definition, this.options, this.scope) : responsesRequest(request, this.definition, this.options, this.scope, this.resolution?.deployment)), request.signal, this.providerId, this.modelId, this.protocol);
1996
2031
  const id = this.transport.redactText(response, requestId(response));
1997
2032
  if (!response.body)
1998
2033
  throw new ModelProviderError4(`${PREFIX} Provider returned an empty streaming response.`, this.providerId, this.modelId, { requestId: id, status: response.status });
@@ -2030,6 +2065,18 @@ class FoundryModel {
2030
2065
  }), response)
2031
2066
  };
2032
2067
  }
2068
+ async postMessages(request) {
2069
+ const prepared = foundryMessagesRequest(request, this.definition, this.options, this.scope);
2070
+ const post = (body) => this.transport.post(JSON.stringify(body), request.signal, this.providerId, this.modelId, "messages");
2071
+ try {
2072
+ return await post(prepared.body);
2073
+ } catch (error) {
2074
+ if (prepared.strictTools === undefined || !(error instanceof ModelProviderError4) || !isStrictToolLimitError(error))
2075
+ throw error;
2076
+ strictToolRefusals.add(prepared.strictTools);
2077
+ return post(foundryMessagesRequest(request, this.definition, this.options, this.scope, true).body);
2078
+ }
2079
+ }
2033
2080
  async* events(source, response) {
2034
2081
  try {
2035
2082
  for await (const event of source) {
@@ -2063,4 +2110,4 @@ export {
2063
2110
  createAzureAIFoundry
2064
2111
  };
2065
2112
 
2066
- //# debugId=A039AA13A59ECF2964756E2164756E21
2113
+ //# debugId=8BAD6E2F429F859E64756E2164756E21