@sixb/azure-ai-foundry 0.2.6 → 0.2.7
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/README.md +66 -33
- package/dist/accounting.d.ts +5 -0
- package/dist/accounting.d.ts.map +1 -1
- package/dist/caching.d.ts +34 -0
- package/dist/caching.d.ts.map +1 -0
- package/dist/catalog.d.ts.map +1 -1
- package/dist/chat-accounting.d.ts.map +1 -1
- package/dist/chat-request.d.ts +2 -1
- package/dist/chat-request.d.ts.map +1 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/embedding.d.ts +1 -3
- package/dist/embedding.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +254 -113
- package/dist/index.js.map +17 -16
- package/dist/kinds.d.ts.map +1 -1
- package/dist/messages-request.d.ts.map +1 -1
- package/dist/provider.d.ts +10 -5
- package/dist/provider.d.ts.map +1 -1
- package/dist/request.d.ts +6 -2
- package/dist/request.d.ts.map +1 -1
- package/dist/resolution.d.ts.map +1 -1
- package/dist/transport.d.ts +30 -3
- package/dist/transport.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/accounting.ts +33 -11
- package/src/caching.ts +80 -0
- package/src/catalog.ts +15 -4
- package/src/chat-accounting.ts +12 -9
- package/src/chat-request.ts +14 -3
- package/src/discovery.ts +6 -0
- package/src/embedding.ts +1 -13
- package/src/index.ts +2 -6
- package/src/kinds.ts +0 -9
- package/src/messages-accounting.ts +6 -1
- package/src/messages-request.ts +32 -24
- package/src/provider.ts +65 -50
- package/src/request.ts +55 -23
- package/src/resolution.ts +13 -14
- package/src/transport.ts +130 -31
package/dist/kinds.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../src/kinds.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAG3D;;;GAGG;AACH,MAAM,MAAM,WAAW,GACnB,UAAU,GACV,WAAW,GACX,UAAU,GACV,eAAe,GACf,WAAW,GACX,QAAQ,GACR,OAAO,CAAA;AAEX,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAQ/D,CAAA;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,wBAAwB,GAAG,WAAW,CAmBhF;AAED,8EAA8E;AAC9E,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,wBAAwB,EACpC,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,GACrC,IAAI,
|
|
1
|
+
{"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../src/kinds.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAG3D;;;GAGG;AACH,MAAM,MAAM,WAAW,GACnB,UAAU,GACV,WAAW,GACX,UAAU,GACV,eAAe,GACf,WAAW,GACX,QAAQ,GACR,OAAO,CAAA;AAEX,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAQ/D,CAAA;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,wBAAwB,GAAG,WAAW,CAmBhF;AAED,8EAA8E;AAC9E,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,wBAAwB,EACpC,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,GACrC,IAAI,CAMN;AAED,+DAA+D;AAC/D,wBAAgB,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAEjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages-request.d.ts","sourceRoot":"","sources":["../src/messages-request.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EAG1B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,
|
|
1
|
+
{"version":3,"file":"messages-request.d.ts","sourceRoot":"","sources":["../src/messages-request.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EAG1B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAIL,kBAAkB,EAEnB,MAAM,gCAAgC,CAAA;AAKvC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAA;IACjC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,UAAU,CAAA;IAC7B,6EAA6E;IAC7E,QAAQ,CAAC,YAAY,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAA;CAC9C;AAED,+FAA+F;AAC/F,eAAO,MAAM,kBAAkB,oBAA2B,CAAA;AAE1D,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;IACzB,oFAAoF;IACpF,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAC9B;AAmBD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,sBAAsB,GAAG,IAAI,CAqB7E;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,oBAAoB,EAC7B,UAAU,EAAE,uBAAuB,EACnC,OAAO,EAAE,sBAAsB,EAC/B,KAAK,EAAE,MAAM,EACb,aAAa,UAAQ,GACpB,sBAAsB,CA+ExB"}
|
package/dist/provider.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type AzureAIFoundryCatalogOptions } from "./catalog";
|
|
|
3
3
|
import { type ChatRequestOptions } from "./chat-request";
|
|
4
4
|
import { type AzureAIFoundryDecisionModel, type AzureAIFoundryDecisionOptions } from "./decision";
|
|
5
5
|
import { type AzureAIFoundryCatalog, type AzureAIFoundryDeployment, type AzureAIFoundryDiscoveryOptions } from "./discovery";
|
|
6
|
-
import { type AzureAIFoundryEmbeddingModel, type AzureAIFoundryEmbeddingOptions
|
|
6
|
+
import { type AzureAIFoundryEmbeddingModel, type AzureAIFoundryEmbeddingOptions } from "./embedding";
|
|
7
7
|
import { type AzureAIFoundryImageModel, type AzureAIFoundryImageOptions } from "./image";
|
|
8
8
|
import { type MessagesRequestOptions } from "./messages-request";
|
|
9
9
|
import { type RequestOptions } from "./request";
|
|
@@ -11,9 +11,14 @@ import { type AzureAIFoundryRerankingModel, type AzureAIFoundryRerankingOptions
|
|
|
11
11
|
import { type AzureAIFoundrySpeechModel, type AzureAIFoundrySpeechOptions } from "./speech";
|
|
12
12
|
import { type AzureAIFoundryTranscriptionModel, type AzureAIFoundryTranscriptionOptions } from "./transcription";
|
|
13
13
|
import { type FoundryProtocol, type TransportOptions } from "./transport";
|
|
14
|
-
export interface AzureAIFoundryOptions extends TransportOptions {
|
|
15
|
-
/**
|
|
16
|
-
|
|
14
|
+
export interface AzureAIFoundryOptions extends Omit<TransportOptions, "endpoint"> {
|
|
15
|
+
/**
|
|
16
|
+
* The project endpoint from the Foundry portal,
|
|
17
|
+
* `https://<resource>.services.ai.azure.com/api/projects/<project>`.
|
|
18
|
+
* Default: `AZURE_AI_FOUNDRY_ENDPOINT`. Without `credential`, `apiKey` defaults to
|
|
19
|
+
* `AZURE_AI_FOUNDRY_API_KEY`, read for each call.
|
|
20
|
+
*/
|
|
21
|
+
readonly endpoint?: string;
|
|
17
22
|
/** Public model capabilities and reference pricing from models.dev. */
|
|
18
23
|
readonly catalog?: AzureAIFoundryCatalogOptions;
|
|
19
24
|
/** Namespace bindings from different resources/projects in a single Sixb catalog. */
|
|
@@ -83,5 +88,5 @@ export interface AzureAIFoundryProvider extends LanguageModelProvider {
|
|
|
83
88
|
readonly catalog: AzureAIFoundryCatalog;
|
|
84
89
|
chat(deploymentName: string, options?: AzureAIFoundryChatOptions): AzureAIFoundryModel<"chat">;
|
|
85
90
|
}
|
|
86
|
-
export declare function createAzureAIFoundry(options
|
|
91
|
+
export declare function createAzureAIFoundry(options?: AzureAIFoundryOptions): AzureAIFoundryProvider;
|
|
87
92
|
//# sourceMappingURL=provider.d.ts.map
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAM1B,KAAK,kBAAkB,EAEvB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EAEzB,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAM1B,KAAK,kBAAkB,EAEvB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EAEzB,MAAM,mBAAmB,CAAA;AAM1B,OAAO,EACL,KAAK,4BAA4B,EAGlC,MAAM,WAAW,CAAA;AAElB,OAAO,EAAE,KAAK,kBAAkB,EAA2C,MAAM,gBAAgB,CAAA;AACjG,OAAO,EACL,KAAK,2BAA2B,EAChC,KAAK,6BAA6B,EAEnC,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,8BAA8B,EAGpC,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,8BAA8B,EAEpC,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAEhC,MAAM,SAAS,CAAA;AAGhB,OAAO,EAEL,KAAK,sBAAsB,EAG5B,MAAM,oBAA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O,EAAE,qBAAqB,CAAA;IACvC,IAAI,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAA;CAC/F;AAED,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,qBAA0B,GAAG,sBAAsB,CAuHhG"}
|
package/dist/request.d.ts
CHANGED
|
@@ -12,11 +12,15 @@ export interface RequestOptions {
|
|
|
12
12
|
}
|
|
13
13
|
export declare function validateOptions(options: RequestOptions): void;
|
|
14
14
|
export declare function responsesRequest(request: LanguageModelRequest, definition: LanguageModelDefinition, options: RequestOptions, scope: string, deployment?: AzureAIFoundryDeployment): JsonObject;
|
|
15
|
+
/** The output ceiling, and the messages to send: validated, with only this scope's replay state. */
|
|
15
16
|
export declare function prepareRequest(request: LanguageModelRequest, definition: LanguageModelDefinition, options: {
|
|
16
17
|
readonly maxOutputTokens?: number;
|
|
17
18
|
readonly maxInputFileBytes?: number;
|
|
18
|
-
}, scope: string, remotePdf?: boolean):
|
|
19
|
-
|
|
19
|
+
}, scope: string, remotePdf?: boolean): {
|
|
20
|
+
readonly max: number | undefined;
|
|
21
|
+
readonly messages: readonly ModelMessage[];
|
|
22
|
+
};
|
|
23
|
+
export declare function validateMessages(messages: readonly ModelMessage[], definition: LanguageModelDefinition, budget: number, remotePdf?: boolean): void;
|
|
20
24
|
/**
|
|
21
25
|
* A tool that asked for strict arguments, in the form OpenAI's strict mode takes (every property
|
|
22
26
|
* required, an optional one nullable), when it fits Azure's strict subset.
|
package/dist/request.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EAEf,KAAK,uBAAuB,EAC5B,K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MAAM,EAAE,MAAM,EACd,SAAS,UAAQ,GAChB,IAAI,CAgDN;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,sBAAsB,GAAG,UAAU,GAAG,SAAS,CAItF"}
|
package/dist/resolution.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolution.d.ts","sourceRoot":"","sources":["../src/resolution.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,uBAAuB,EAE7B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAC3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAChE,OAAO,KAAK,EAA+B,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAEzF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B,OAAO,EAAE,0BAA0B,GAAG,kBAAkB,GAAG,sBAAsB,CAAA;IACjF,UAAU,CAAC,EAAE,wBAAwB,CAAA;IACrC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"resolution.d.ts","sourceRoot":"","sources":["../src/resolution.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,uBAAuB,EAE7B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAC3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAChE,OAAO,KAAK,EAA+B,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAEzF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B,OAAO,EAAE,0BAA0B,GAAG,kBAAkB,GAAG,sBAAsB,CAAA;IACjF,UAAU,CAAC,EAAE,wBAAwB,CAAA;IACrC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B;;;;;;;;;;;;;;;;;;;EAsFA"}
|
package/dist/transport.d.ts
CHANGED
|
@@ -5,25 +5,52 @@ export type FoundryProtocol = "responses" | "messages" | "chat";
|
|
|
5
5
|
type FoundryRoute = FoundryProtocol | OneShotRoute;
|
|
6
6
|
/** Routes that answer in one body. A failure is never replayed: the call may have been billed. */
|
|
7
7
|
type OneShotRoute = "embeddings" | "decision" | "transcription" | "reranking" | "speech" | "image" | "image-edit";
|
|
8
|
+
/** Entra ID sign-in, such as `DefaultAzureCredential` or `ManagedIdentityCredential` from `@azure/identity`. */
|
|
9
|
+
export interface AzureAIFoundryCredential {
|
|
10
|
+
getToken(scopes: string | string[], options?: {
|
|
11
|
+
readonly abortSignal?: AbortSignal;
|
|
12
|
+
}): Promise<{
|
|
13
|
+
readonly token: string;
|
|
14
|
+
readonly expiresOnTimestamp?: number;
|
|
15
|
+
readonly refreshAfterTimestamp?: number;
|
|
16
|
+
} | null>;
|
|
17
|
+
}
|
|
8
18
|
export interface TransportOptions {
|
|
9
19
|
readonly endpoint: string;
|
|
10
|
-
|
|
20
|
+
/** The project resource's key, sent as `api-key` (`x-api-key` to Messages). */
|
|
21
|
+
readonly apiKey?: ValueSource<string | undefined>;
|
|
22
|
+
/** Entra ID in place of a key: a bearer token for every call, renewed before it expires. */
|
|
23
|
+
readonly credential?: AzureAIFoundryCredential;
|
|
11
24
|
readonly headers?: ValueSource<Readonly<Record<string, string>>>;
|
|
12
25
|
readonly fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
13
26
|
readonly maxRetries?: number;
|
|
14
27
|
readonly maxRetryDelayMs?: number;
|
|
15
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* The project URL says what is deployed; every model call goes to the resource that owns the
|
|
31
|
+
* project. The project's own inference path answers through another service that trails new
|
|
32
|
+
* models: for gpt-6.2-sol it refused reasoning efforts, ignored tools and reported no input
|
|
33
|
+
* tokens, where the resource answered all three (measured November 2026).
|
|
34
|
+
*/
|
|
16
35
|
export declare class FoundryTransport {
|
|
17
36
|
private readonly diagnostics;
|
|
18
|
-
|
|
37
|
+
/** Deployment discovery: `https://<resource>.services.ai.azure.com/api/projects/<project>`. */
|
|
19
38
|
readonly projectUrl: string;
|
|
39
|
+
/** Every model call: the project URL's origin. */
|
|
40
|
+
readonly resourceUrl: string;
|
|
20
41
|
private readonly options;
|
|
21
|
-
|
|
42
|
+
private token?;
|
|
43
|
+
private renewal?;
|
|
44
|
+
constructor(options: TransportOptions);
|
|
22
45
|
post(body: string | FormData, signal: AbortSignal, providerId: string, modelId: string, protocol?: FoundryRoute): Promise<Response>;
|
|
23
46
|
redactText(response: Response, value: string | undefined): string | undefined;
|
|
24
47
|
redactError(response: Response, error: ModelProviderError): ModelProviderError;
|
|
25
48
|
redactFailure(response: Response, error: unknown): unknown;
|
|
26
49
|
headers(signal: AbortSignal, diagnostics: RequestDiagnostics, keyHeader?: "api-key" | "x-api-key"): Promise<Headers>;
|
|
50
|
+
/** One token for every call; a call waits only when there is none, or it is about to expire. */
|
|
51
|
+
private bearerToken;
|
|
52
|
+
/** Concurrent callers share one getToken call. */
|
|
53
|
+
private renewToken;
|
|
27
54
|
fetch(url: string, init: RequestInit): Promise<Response>;
|
|
28
55
|
url(protocol: FoundryRoute, deployment?: string): string;
|
|
29
56
|
}
|
package/dist/transport.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAGlD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,WAAW,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AAC1E,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,CAAA;AAC/D,KAAK,YAAY,GAAG,eAAe,GAAG,YAAY,CAAA;AAClD,kGAAkG;AAClG,KAAK,YAAY,GACb,YAAY,GACZ,UAAU,GACV,eAAe,GACf,WAAW,GACX,QAAQ,GACR,OAAO,GACP,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAGlD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,WAAW,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AAC1E,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,CAAA;AAC/D,KAAK,YAAY,GAAG,eAAe,GAAG,YAAY,CAAA;AAClD,kGAAkG;AAClG,KAAK,YAAY,GAC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MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAkBjB;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAOhE;AAWD,+FAA+F;AAC/F,wBAAgB,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAgB7F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/azure-ai-foundry",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Azure AI Foundry model provider for Sixb",
|
|
5
5
|
"homepage": "https://sixb.ai",
|
|
6
6
|
"bugs": {
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"prepack": "bun run build"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@sixb/core": "^0.2.
|
|
35
|
-
"@sixb/model-protocols": "0.2.
|
|
34
|
+
"@sixb/core": "^0.2.7",
|
|
35
|
+
"@sixb/model-protocols": "0.2.7"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/bun": "latest",
|
package/src/accounting.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
rateModelCall,
|
|
9
9
|
} from "@sixb/core/models"
|
|
10
10
|
import { responsesUsage } from "@sixb/model-protocols/responses"
|
|
11
|
-
import { object } from "./util"
|
|
11
|
+
import { counter, object } from "./util"
|
|
12
12
|
|
|
13
13
|
export function foundryUsage(
|
|
14
14
|
raw: JsonObject | undefined,
|
|
@@ -17,6 +17,9 @@ export function foundryUsage(
|
|
|
17
17
|
const usage = responsesUsage(raw)
|
|
18
18
|
const { reasoningOutputTokens, ...totals } = usage
|
|
19
19
|
const cached = usage.cacheReadInputTokens
|
|
20
|
+
// GPT-5.6 and later bill a cache write in place of ordinary input: input tokens are uncached,
|
|
21
|
+
// read or written, each once (measured on Azure: 7,546 input, 7,543 written, 0 read).
|
|
22
|
+
const written = counter(object(raw?.input_tokens_details)?.cache_write_tokens)
|
|
20
23
|
const input = usage.inputTokens
|
|
21
24
|
const output = usage.outputTokens
|
|
22
25
|
const knownReasoning =
|
|
@@ -26,11 +29,12 @@ export function foundryUsage(
|
|
|
26
29
|
(reliableReasoning === true || (reliableReasoning === undefined && reasoningOutputTokens > 0))
|
|
27
30
|
return {
|
|
28
31
|
...totals,
|
|
29
|
-
...(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
...(written === undefined ? {} : { cacheWriteInputTokens: written }),
|
|
33
|
+
...(input !== undefined &&
|
|
34
|
+
cached !== undefined &&
|
|
35
|
+
cached + (written ?? 0) <= input &&
|
|
36
|
+
onlyTokenMeters(raw)
|
|
37
|
+
? { uncachedInputTokens: input - cached - (written ?? 0) }
|
|
34
38
|
: {}),
|
|
35
39
|
...(knownReasoning ? { reasoningOutputTokens } : {}),
|
|
36
40
|
...(knownReasoning &&
|
|
@@ -56,7 +60,8 @@ export function foundryEstimator(
|
|
|
56
60
|
return tokenEstimator(
|
|
57
61
|
card,
|
|
58
62
|
request,
|
|
59
|
-
|
|
63
|
+
// A cache key and 24-hour retention do not change the price; prompt_cache_options can.
|
|
64
|
+
["temperature", "top_p", "metadata", "prompt_cache_key", "prompt_cache_retention"],
|
|
60
65
|
onlyTokenMeters,
|
|
61
66
|
modelName,
|
|
62
67
|
modelVersion,
|
|
@@ -94,7 +99,7 @@ export function tokenEstimator(
|
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
|
|
97
|
-
/** Unknown
|
|
102
|
+
/** Unknown or new meters require a custom estimator. */
|
|
98
103
|
function onlyTokenMeters(raw: JsonObject | undefined): boolean {
|
|
99
104
|
if (!raw) return true
|
|
100
105
|
if (
|
|
@@ -110,12 +115,29 @@ function onlyTokenMeters(raw: JsonObject | undefined): boolean {
|
|
|
110
115
|
)
|
|
111
116
|
)
|
|
112
117
|
return false
|
|
113
|
-
// Azure includes this meter with zero on ordinary Responses calls. Nonzero writes have
|
|
114
|
-
// offering-specific billing/overlap semantics and still require a custom estimator.
|
|
115
118
|
return (
|
|
116
119
|
Object.entries(object(raw.input_tokens_details) ?? {}).every(
|
|
117
|
-
([key, value]) =>
|
|
120
|
+
([key, value]) =>
|
|
121
|
+
key === "cached_tokens" ||
|
|
122
|
+
key === "cache_write_tokens" ||
|
|
123
|
+
(key === "cache_write_tokens_details" && defaultLifetimeWrites(value))
|
|
118
124
|
) &&
|
|
119
125
|
Object.keys(object(raw.output_tokens_details) ?? {}).every((key) => key === "reasoning_tokens")
|
|
120
126
|
)
|
|
121
127
|
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Writes by cache lifetime, as GPT-5.6 and later report them. The catalog's write rate is the
|
|
131
|
+
* default 30 minutes'; a 12-hour write costs twice that, so any makes the call unpriceable.
|
|
132
|
+
*/
|
|
133
|
+
export function defaultLifetimeWrites(details: unknown): boolean {
|
|
134
|
+
const lifetimes = object(details)
|
|
135
|
+
return (
|
|
136
|
+
lifetimes !== undefined &&
|
|
137
|
+
Object.entries(lifetimes).every(
|
|
138
|
+
([key, value]) =>
|
|
139
|
+
(key === "ttl_30m_tokens" && counter(value) !== undefined) ||
|
|
140
|
+
(key === "ttl_12h_tokens" && value === 0)
|
|
141
|
+
)
|
|
142
|
+
)
|
|
143
|
+
}
|
package/src/caching.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { JsonObject, ModelCaching, ModelMessage } from "@sixb/core/models"
|
|
2
|
+
import { billsPromptCacheWrites } from "@sixb/model-protocols/responses"
|
|
3
|
+
import type { AzureAIFoundryDeployment } from "./discovery"
|
|
4
|
+
|
|
5
|
+
/** The caching settings Sixb sends on Responses and Chat; Azure may refuse any for a deployment. */
|
|
6
|
+
const CACHING_FIELDS = ["prompt_cache_key", "prompt_cache_retention", "prompt_cache_options"]
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Settings Azure refused, by request scope and field. A caching setting is an optimization: one
|
|
10
|
+
* Azure refuses is dropped from that deployment's later requests instead of failing them.
|
|
11
|
+
*/
|
|
12
|
+
const refusals = new Set<string>()
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Responses and Chat cache a prompt of 1,024 tokens or more on their own, so these settings only
|
|
16
|
+
* say what Sixb knows about the request (measured on Azure, November 2026):
|
|
17
|
+
*
|
|
18
|
+
* - `prompt_cache_key`: the intent's key, such as a conversation's, which keeps its requests where
|
|
19
|
+
* their prefix is cached. Every model tried accepts it; Kimi hit the cache one call sooner.
|
|
20
|
+
* - A one-shot request (no tools and no earlier answer) on a model that bills cache writes
|
|
21
|
+
* (GPT-5.6 and later) asks for explicit caching with no breakpoints, which writes nothing:
|
|
22
|
+
* nothing reads its prefix again, and a write costs 1.25 times input. `caching: "off"` too.
|
|
23
|
+
* - A conversation's `"long"` lifetime keeps an earlier OpenAI model's cache for 24 hours instead
|
|
24
|
+
* of its 5 to 10 idle minutes, at the same price. GPT-5.6 and later keep their 30-minute default:
|
|
25
|
+
* twelve hours would double the price of every write to cover longer pauses.
|
|
26
|
+
*
|
|
27
|
+
* The binding's own `request` settings win, and so does a refusal.
|
|
28
|
+
*/
|
|
29
|
+
export function promptCaching(input: {
|
|
30
|
+
readonly caching: ModelCaching | undefined
|
|
31
|
+
readonly messages: readonly ModelMessage[]
|
|
32
|
+
readonly localTools: number
|
|
33
|
+
readonly deployment: AzureAIFoundryDeployment | undefined
|
|
34
|
+
readonly request: JsonObject | undefined
|
|
35
|
+
readonly scope: string
|
|
36
|
+
}): JsonObject {
|
|
37
|
+
const { caching, deployment } = input
|
|
38
|
+
const openai = deployment?.modelPublisher.toLowerCase() === "openai"
|
|
39
|
+
const billsWrites = openai && billsPromptCacheWrites(deployment.modelName)
|
|
40
|
+
const reusable =
|
|
41
|
+
caching === "auto" ||
|
|
42
|
+
(caching !== "off" &&
|
|
43
|
+
(input.localTools > 0 || input.messages.some((message) => message.role === "assistant")))
|
|
44
|
+
const intent = typeof caching === "object" ? caching : undefined
|
|
45
|
+
const settings: JsonObject = {
|
|
46
|
+
...(intent?.key ? { prompt_cache_key: intent.key } : {}),
|
|
47
|
+
...(!reusable && billsWrites ? { prompt_cache_options: { mode: "explicit" } } : {}),
|
|
48
|
+
...(reusable && openai && !billsWrites && intent?.lifetime === "long"
|
|
49
|
+
? { prompt_cache_retention: "24h" }
|
|
50
|
+
: {}),
|
|
51
|
+
}
|
|
52
|
+
return Object.fromEntries(
|
|
53
|
+
Object.entries(settings).filter(
|
|
54
|
+
([field]) =>
|
|
55
|
+
!Object.hasOwn(input.request ?? {}, field) && !refusals.has(`${input.scope}\0${field}`)
|
|
56
|
+
)
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Remember a caching setting Sixb added to the sent body that Azure refused with a 400 naming it;
|
|
62
|
+
* whether there was one, so the request can go again without it. The binding's own are its call.
|
|
63
|
+
*/
|
|
64
|
+
export function refusedCaching(
|
|
65
|
+
error: { readonly status?: number; readonly message: string },
|
|
66
|
+
body: JsonObject,
|
|
67
|
+
request: JsonObject | undefined,
|
|
68
|
+
scope: string
|
|
69
|
+
): boolean {
|
|
70
|
+
if (error.status !== 400) return false
|
|
71
|
+
const field = CACHING_FIELDS.find(
|
|
72
|
+
(name) =>
|
|
73
|
+
Object.hasOwn(body, name) &&
|
|
74
|
+
!Object.hasOwn(request ?? {}, name) &&
|
|
75
|
+
error.message.includes(name)
|
|
76
|
+
)
|
|
77
|
+
if (!field) return false
|
|
78
|
+
refusals.add(`${scope}\0${field}`)
|
|
79
|
+
return true
|
|
80
|
+
}
|
package/src/catalog.ts
CHANGED
|
@@ -6,7 +6,11 @@ import {
|
|
|
6
6
|
type ModelRateCard,
|
|
7
7
|
type ModelReasoningCapabilities,
|
|
8
8
|
} from "@sixb/core/models"
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
downloadModelsDev,
|
|
11
|
+
modelsDevRateCard,
|
|
12
|
+
scaleTokenPrice,
|
|
13
|
+
} from "@sixb/model-protocols/models-dev"
|
|
10
14
|
import { fireworksPublisher } from "./publisher"
|
|
11
15
|
import type { FoundryProtocol } from "./transport"
|
|
12
16
|
import { object, PREFIX } from "./util"
|
|
@@ -243,8 +247,15 @@ function rates(
|
|
|
243
247
|
): ModelRateCard | undefined {
|
|
244
248
|
const card = modelsDevRateCard(raw)
|
|
245
249
|
if (protocol !== "messages" || card?.cacheWriteInput === undefined) return card
|
|
246
|
-
// models.dev's Messages cache_write is five-minute
|
|
247
|
-
//
|
|
250
|
+
// models.dev's Messages cache_write is the five-minute write, in context tiers too. It lists
|
|
251
|
+
// Claude on Azure at Anthropic's prices (Azure publishes no meter of its own), where a one-hour
|
|
252
|
+
// write costs twice the input price.
|
|
248
253
|
const { cacheWriteInput, ...rest } = card
|
|
249
|
-
return defineModelRateCard({
|
|
254
|
+
return defineModelRateCard({
|
|
255
|
+
...rest,
|
|
256
|
+
cacheWriteInput5m: cacheWriteInput,
|
|
257
|
+
...(rest.input === undefined
|
|
258
|
+
? {}
|
|
259
|
+
: { cacheWriteInput1h: scaleTokenPrice(rest.input, [2n, 1n]) }),
|
|
260
|
+
})
|
|
250
261
|
}
|
package/src/chat-accounting.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JsonObject, ModelCostEstimator, ModelRateCard, ModelUsage } from "@sixb/core/models"
|
|
2
|
-
import { type PricedEstimator, tokenEstimator } from "./accounting"
|
|
2
|
+
import { defaultLifetimeWrites, type PricedEstimator, tokenEstimator } from "./accounting"
|
|
3
3
|
import { counter, object } from "./util"
|
|
4
4
|
|
|
5
5
|
// Interpret Chat counters directly. Cache reads overlap prompt_tokens; reasoning overlaps
|
|
@@ -11,6 +11,8 @@ export function foundryChatUsage(
|
|
|
11
11
|
const input = counter(raw?.prompt_tokens)
|
|
12
12
|
const output = counter(raw?.completion_tokens)
|
|
13
13
|
const read = counter(object(raw?.prompt_tokens_details)?.cached_tokens)
|
|
14
|
+
// Written tokens are input billed at the write rate, apart from reads (as on Responses).
|
|
15
|
+
const written = counter(object(raw?.prompt_tokens_details)?.cache_write_tokens)
|
|
14
16
|
const reported = reasoningTokens(raw)
|
|
15
17
|
const reasoning =
|
|
16
18
|
reported !== undefined &&
|
|
@@ -23,11 +25,9 @@ export function foundryChatUsage(
|
|
|
23
25
|
...(input === undefined ? {} : { inputTokens: input }),
|
|
24
26
|
...(output === undefined ? {} : { outputTokens: output }),
|
|
25
27
|
...(read === undefined ? {} : { cacheReadInputTokens: read }),
|
|
26
|
-
...(
|
|
27
|
-
|
|
28
|
-
:
|
|
29
|
-
...(input !== undefined && read !== undefined && read <= input && known
|
|
30
|
-
? { uncachedInputTokens: input - read }
|
|
28
|
+
...(written === undefined ? {} : { cacheWriteInputTokens: written }),
|
|
29
|
+
...(input !== undefined && read !== undefined && read + (written ?? 0) <= input && known
|
|
30
|
+
? { uncachedInputTokens: input - read - (written ?? 0) }
|
|
31
31
|
: {}),
|
|
32
32
|
...(reasoning === undefined ? {} : { reasoningOutputTokens: reasoning }),
|
|
33
33
|
...(output !== undefined && reasoning !== undefined && reasoning <= output && known
|
|
@@ -47,7 +47,7 @@ export function foundryChatEstimator(
|
|
|
47
47
|
const estimator = tokenEstimator(
|
|
48
48
|
card,
|
|
49
49
|
request,
|
|
50
|
-
["temperature", "top_p", "metadata"],
|
|
50
|
+
["temperature", "top_p", "metadata", "prompt_cache_key", "prompt_cache_retention"],
|
|
51
51
|
tokenMeters,
|
|
52
52
|
modelName,
|
|
53
53
|
modelVersion,
|
|
@@ -80,10 +80,13 @@ function tokenMeters(raw: JsonObject | undefined): boolean {
|
|
|
80
80
|
if (!details) return false
|
|
81
81
|
for (const [meter, count] of Object.entries(details)) {
|
|
82
82
|
if (
|
|
83
|
-
(key === "prompt_tokens_details" &&
|
|
83
|
+
(key === "prompt_tokens_details" &&
|
|
84
|
+
(meter === "cached_tokens" || meter === "cache_write_tokens")) ||
|
|
84
85
|
(key !== "prompt_tokens_details" && meter === "reasoning_tokens")
|
|
85
86
|
) {
|
|
86
87
|
if (counter(count) === undefined) return false
|
|
88
|
+
} else if (key === "prompt_tokens_details" && meter === "cache_write_tokens_details") {
|
|
89
|
+
if (!defaultLifetimeWrites(count)) return false
|
|
87
90
|
} else if (key === "prompt_tokens_details" && meter === "image_tokens") {
|
|
88
91
|
// Image tokens are already included in prompt_tokens, at the input token rate.
|
|
89
92
|
const image = counter(count)
|
|
@@ -93,7 +96,7 @@ function tokenMeters(raw: JsonObject | undefined): boolean {
|
|
|
93
96
|
![
|
|
94
97
|
"audio_tokens",
|
|
95
98
|
...(key === "prompt_tokens_details"
|
|
96
|
-
? [
|
|
99
|
+
? []
|
|
97
100
|
: ["accepted_prediction_tokens", "rejected_prediction_tokens"]),
|
|
98
101
|
].includes(meter) ||
|
|
99
102
|
count !== 0
|
package/src/chat-request.ts
CHANGED
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
UnsupportedModelFeatureError,
|
|
7
7
|
} from "@sixb/core/models"
|
|
8
8
|
import { chatInput } from "@sixb/model-protocols/chat"
|
|
9
|
+
import { promptCaching } from "./caching"
|
|
10
|
+
import type { AzureAIFoundryDeployment } from "./discovery"
|
|
9
11
|
import { foundryStrictTool, prepareRequest } from "./request"
|
|
10
12
|
import { foundryOutputSchema } from "./structured-output"
|
|
11
13
|
import { PREFIX, positiveInteger } from "./util"
|
|
@@ -70,9 +72,10 @@ export function foundryChatRequest(
|
|
|
70
72
|
request: LanguageModelRequest,
|
|
71
73
|
definition: LanguageModelDefinition,
|
|
72
74
|
options: ChatRequestOptions,
|
|
73
|
-
scope: string
|
|
75
|
+
scope: string,
|
|
76
|
+
deployment?: AzureAIFoundryDeployment
|
|
74
77
|
): JsonObject {
|
|
75
|
-
const max = prepareRequest(request, definition, options, scope)
|
|
78
|
+
const { max, messages } = prepareRequest(request, definition, options, scope)
|
|
76
79
|
const profile = options.profile ?? "openai"
|
|
77
80
|
if (profile !== "deepseek" && options.reasoningReplay === "tool-continuation")
|
|
78
81
|
throw new UnsupportedModelFeatureError(
|
|
@@ -118,7 +121,7 @@ export function foundryChatRequest(
|
|
|
118
121
|
return {
|
|
119
122
|
...options.request,
|
|
120
123
|
model: definition.modelId,
|
|
121
|
-
messages: chatInput(
|
|
124
|
+
messages: chatInput(messages, {
|
|
122
125
|
providerId: definition.providerId,
|
|
123
126
|
errorPrefix: PREFIX,
|
|
124
127
|
systemRole: options.systemRole,
|
|
@@ -126,6 +129,14 @@ export function foundryChatRequest(
|
|
|
126
129
|
}),
|
|
127
130
|
stream: true,
|
|
128
131
|
...(options.includeUsage === false ? {} : { stream_options: { include_usage: true } }),
|
|
132
|
+
...promptCaching({
|
|
133
|
+
caching: request.caching,
|
|
134
|
+
messages: request.messages,
|
|
135
|
+
localTools: request.tools.length,
|
|
136
|
+
deployment,
|
|
137
|
+
request: options.request,
|
|
138
|
+
scope,
|
|
139
|
+
}),
|
|
129
140
|
...(max === undefined ? {} : { [options.maxTokensParameter ?? "max_completion_tokens"]: max }),
|
|
130
141
|
...(explicitReasoning && typeof reasoning === "string" ? { reasoning_effort: reasoning } : {}),
|
|
131
142
|
...(tools.length
|
package/src/discovery.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
type LanguageModelDefinitionCatalog,
|
|
4
4
|
ModelCatalogUnavailableError,
|
|
5
5
|
ModelProviderError,
|
|
6
|
+
UnsupportedModelFeatureError,
|
|
6
7
|
} from "@sixb/core/models"
|
|
7
8
|
import { RequestDiagnostics } from "./diagnostics"
|
|
8
9
|
import type { AzureAIFoundryModelMetadata } from "./provider"
|
|
@@ -128,6 +129,11 @@ export class FoundryDeployments {
|
|
|
128
129
|
throw this.invalid(
|
|
129
130
|
`Deployment '${name}' was not found in ${offline ? "cached project deployments; resolve online first" : "this project"}.`
|
|
130
131
|
)
|
|
132
|
+
// Sixb calls models on the project's own resource; a connection's deployment is elsewhere.
|
|
133
|
+
if (deployment.connectionName)
|
|
134
|
+
throw new UnsupportedModelFeatureError(
|
|
135
|
+
`${PREFIX} Deployment '${name}' comes from project connection '${deployment.connectionName}', on another resource. Configure a provider with that resource's project URL.`
|
|
136
|
+
)
|
|
131
137
|
return {
|
|
132
138
|
deployment,
|
|
133
139
|
discoveredAt: snapshot.fetchedAt,
|
package/src/embedding.ts
CHANGED
|
@@ -22,20 +22,9 @@ import {
|
|
|
22
22
|
type ResolvedDeployment,
|
|
23
23
|
} from "./discovery"
|
|
24
24
|
import type { AzureAIFoundryModelMetadata } from "./provider"
|
|
25
|
-
import {
|
|
26
|
-
abortable,
|
|
27
|
-
type FoundryTransport,
|
|
28
|
-
readJson,
|
|
29
|
-
requestId,
|
|
30
|
-
type TransportOptions,
|
|
31
|
-
} from "./transport"
|
|
25
|
+
import { abortable, type FoundryTransport, readJson, requestId } from "./transport"
|
|
32
26
|
import { counter, object, PREFIX } from "./util"
|
|
33
27
|
|
|
34
|
-
export type AzureAIFoundryEmbeddingTransportOptions = Pick<
|
|
35
|
-
TransportOptions,
|
|
36
|
-
"endpoint" | "apiKey" | "headers" | "fetch"
|
|
37
|
-
>
|
|
38
|
-
|
|
39
28
|
export interface AzureAIFoundryEmbeddingOptions {
|
|
40
29
|
/** Pin the actual model behind the deployment; discovery must match before inference. */
|
|
41
30
|
readonly model: { readonly name: string; readonly version: string }
|
|
@@ -55,7 +44,6 @@ interface EmbeddingResolution extends ResolvedDeployment {
|
|
|
55
44
|
readonly configurableDimensions: boolean
|
|
56
45
|
}
|
|
57
46
|
|
|
58
|
-
/** Discovery uses project credentials; inference uses only the explicit resource transport. */
|
|
59
47
|
export function createFoundryEmbedding(
|
|
60
48
|
providerId: string,
|
|
61
49
|
modelId: string,
|
package/src/index.ts
CHANGED
|
@@ -5,11 +5,7 @@ export type {
|
|
|
5
5
|
AzureAIFoundryDeployment,
|
|
6
6
|
AzureAIFoundryDiscoveryOptions,
|
|
7
7
|
} from "./discovery"
|
|
8
|
-
export type {
|
|
9
|
-
AzureAIFoundryEmbeddingModel,
|
|
10
|
-
AzureAIFoundryEmbeddingOptions,
|
|
11
|
-
AzureAIFoundryEmbeddingTransportOptions,
|
|
12
|
-
} from "./embedding"
|
|
8
|
+
export type { AzureAIFoundryEmbeddingModel, AzureAIFoundryEmbeddingOptions } from "./embedding"
|
|
13
9
|
export type { AzureAIFoundryImageModel, AzureAIFoundryImageOptions } from "./image"
|
|
14
10
|
export type {
|
|
15
11
|
AzureAIFoundryChatOptions,
|
|
@@ -27,4 +23,4 @@ export type {
|
|
|
27
23
|
AzureAIFoundryTranscriptionModel,
|
|
28
24
|
AzureAIFoundryTranscriptionOptions,
|
|
29
25
|
} from "./transcription"
|
|
30
|
-
export type { FoundryProtocol } from "./transport"
|
|
26
|
+
export type { AzureAIFoundryCredential, FoundryProtocol } from "./transport"
|
package/src/kinds.ts
CHANGED
|
@@ -57,11 +57,6 @@ export function assertDeploymentKind(
|
|
|
57
57
|
throw new UnsupportedModelFeatureError(
|
|
58
58
|
`${PREFIX} Deployment '${deploymentName}' runs ${deployment.modelName}, not ${article(kind)} ${kind} model. Use ${KIND_BINDINGS[actual]}.`
|
|
59
59
|
)
|
|
60
|
-
// A connection's deployment lives on another resource, which its record does not name.
|
|
61
|
-
if (deployment.connectionName)
|
|
62
|
-
throw new UnsupportedModelFeatureError(
|
|
63
|
-
`${PREFIX} ${capitalize(article(kind))} ${kind} deployment from a project connection cannot be routed; use the owning resource's project URL and API key.`
|
|
64
|
-
)
|
|
65
60
|
}
|
|
66
61
|
|
|
67
62
|
/** "an image", "a speech": the article a kind's name takes. */
|
|
@@ -69,10 +64,6 @@ export function article(kind: FoundryKind): string {
|
|
|
69
64
|
return /^[aeiou]/.test(kind) ? "an" : "a"
|
|
70
65
|
}
|
|
71
66
|
|
|
72
|
-
function capitalize(word: string): string {
|
|
73
|
-
return word.charAt(0).toUpperCase() + word.slice(1)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
67
|
function isEmbeddingDeployment(deployment: AzureAIFoundryDeployment): boolean {
|
|
77
68
|
return (
|
|
78
69
|
deployment.capabilities.embeddings === "true" ||
|
|
@@ -93,7 +93,12 @@ function tokenMeters(raw: JsonObject | undefined): boolean {
|
|
|
93
93
|
)
|
|
94
94
|
)
|
|
95
95
|
return false
|
|
96
|
-
} else if (
|
|
96
|
+
} else if (
|
|
97
|
+
(key === "service_tier" && value === "standard") ||
|
|
98
|
+
(key === "speed" && value === "standard") ||
|
|
99
|
+
// Claude on Azure reports "global"; US-only inference costs 1.1 times as much.
|
|
100
|
+
(key === "inference_geo" && value === "global")
|
|
101
|
+
) {
|
|
97
102
|
} else return false
|
|
98
103
|
}
|
|
99
104
|
return true
|