@sixb/azure-ai-foundry 0.2.0 → 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.
- package/dist/chat-request.d.ts.map +1 -1
- package/dist/index.js +75 -31
- package/dist/index.js.map +7 -7
- package/dist/messages-request.d.ts +14 -1
- package/dist/messages-request.d.ts.map +1 -1
- package/dist/provider.d.ts.map +1 -1
- package/dist/request.d.ts +6 -1
- package/dist/request.d.ts.map +1 -1
- package/dist/structured-output.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/chat-request.ts +18 -20
- package/src/messages-request.ts +39 -8
- package/src/provider.ts +48 -19
- package/src/request.ts +24 -11
- package/src/structured-output.ts +8 -0
|
@@ -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,
|
|
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,CAqFZ"}
|
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
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
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 &&
|
|
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
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
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 &&
|
|
752
|
+
parallel_tool_calls: !schema && caps.parallelToolCalls === true
|
|
737
753
|
} : {}
|
|
738
754
|
} : {},
|
|
739
755
|
...schema && request.responseFormat ? {
|
|
@@ -1524,7 +1540,12 @@ import {
|
|
|
1524
1540
|
modelReasoningSupportIssue as modelReasoningSupportIssue3,
|
|
1525
1541
|
UnsupportedModelFeatureError as UnsupportedModelFeatureError4
|
|
1526
1542
|
} from "@sixb/core/models";
|
|
1527
|
-
import {
|
|
1543
|
+
import {
|
|
1544
|
+
messagesInput,
|
|
1545
|
+
messagesStrictTools,
|
|
1546
|
+
StrictToolRefusals,
|
|
1547
|
+
strictToolsKey
|
|
1548
|
+
} from "@sixb/model-protocols/messages";
|
|
1528
1549
|
|
|
1529
1550
|
// src/messages-schema.ts
|
|
1530
1551
|
import { isJsonObject as isJsonObject4 } from "@sixb/core/models";
|
|
@@ -1602,6 +1623,7 @@ function messagesOutputSchema(schema) {
|
|
|
1602
1623
|
}
|
|
1603
1624
|
|
|
1604
1625
|
// src/messages-request.ts
|
|
1626
|
+
var strictToolRefusals = new StrictToolRefusals;
|
|
1605
1627
|
var RESERVED3 = new Set([
|
|
1606
1628
|
"model",
|
|
1607
1629
|
"messages",
|
|
@@ -1633,7 +1655,7 @@ function validateMessagesOptions(options) {
|
|
|
1633
1655
|
throw new TypeError(`${PREFIX} cache_control must be ephemeral with an optional 5m or 1h ttl.`);
|
|
1634
1656
|
}
|
|
1635
1657
|
}
|
|
1636
|
-
function foundryMessagesRequest(request, definition, options, scope) {
|
|
1658
|
+
function foundryMessagesRequest(request, definition, options, scope, unconstrained = false) {
|
|
1637
1659
|
const max = prepareRequest(request, definition, options, scope, true);
|
|
1638
1660
|
let conversation = false;
|
|
1639
1661
|
for (const message of request.messages) {
|
|
@@ -1658,7 +1680,17 @@ function foundryMessagesRequest(request, definition, options, scope) {
|
|
|
1658
1680
|
...thinking.effort === undefined ? {} : { effort: thinking.effort },
|
|
1659
1681
|
...schema ? { format: { type: "json_schema", schema } } : {}
|
|
1660
1682
|
};
|
|
1661
|
-
|
|
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 = {
|
|
1662
1694
|
...options.request,
|
|
1663
1695
|
model: definition.modelId,
|
|
1664
1696
|
messages: mapped.messages,
|
|
@@ -1668,15 +1700,16 @@ function foundryMessagesRequest(request, definition, options, scope) {
|
|
|
1668
1700
|
...thinking.thinking ? { thinking: thinking.thinking } : {},
|
|
1669
1701
|
...Object.keys(output).length ? { output_config: output } : {},
|
|
1670
1702
|
...request.tools.length ? {
|
|
1671
|
-
tools: request.tools.map((tool) => ({
|
|
1703
|
+
tools: request.tools.map((tool, index) => ({
|
|
1672
1704
|
name: tool.name,
|
|
1673
1705
|
description: tool.description,
|
|
1674
1706
|
input_schema: tool.inputSchema,
|
|
1675
|
-
...
|
|
1707
|
+
...strict[index] ? { strict: true } : {}
|
|
1676
1708
|
})),
|
|
1677
1709
|
tool_choice: { type: "auto", disable_parallel_tool_use: caps.parallelToolCalls !== true }
|
|
1678
1710
|
} : {}
|
|
1679
1711
|
};
|
|
1712
|
+
return { body, ...strictTools === undefined ? {} : { strictTools } };
|
|
1680
1713
|
}
|
|
1681
1714
|
function reasoningRequest(request, definition, options, max) {
|
|
1682
1715
|
const reasoning = request.reasoning;
|
|
@@ -1994,8 +2027,7 @@ class FoundryModel {
|
|
|
1994
2027
|
const model = await abortable(() => this.#pendingExecution, request.signal);
|
|
1995
2028
|
return model.stream(request);
|
|
1996
2029
|
}
|
|
1997
|
-
const
|
|
1998
|
-
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);
|
|
1999
2031
|
const id = this.transport.redactText(response, requestId(response));
|
|
2000
2032
|
if (!response.body)
|
|
2001
2033
|
throw new ModelProviderError4(`${PREFIX} Provider returned an empty streaming response.`, this.providerId, this.modelId, { requestId: id, status: response.status });
|
|
@@ -2033,6 +2065,18 @@ class FoundryModel {
|
|
|
2033
2065
|
}), response)
|
|
2034
2066
|
};
|
|
2035
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
|
+
}
|
|
2036
2080
|
async* events(source, response) {
|
|
2037
2081
|
try {
|
|
2038
2082
|
for await (const event of source) {
|
|
@@ -2066,4 +2110,4 @@ export {
|
|
|
2066
2110
|
createAzureAIFoundry
|
|
2067
2111
|
};
|
|
2068
2112
|
|
|
2069
|
-
//# debugId=
|
|
2113
|
+
//# debugId=8BAD6E2F429F859E64756E2164756E21
|