@sixb/azure-ai-foundry 0.2.4 → 0.2.6
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 +187 -2
- package/dist/decision.d.ts +18 -0
- package/dist/decision.d.ts.map +1 -0
- package/dist/discovery.d.ts +3 -0
- package/dist/discovery.d.ts.map +1 -1
- package/dist/embedding.d.ts +1 -1
- package/dist/embedding.d.ts.map +1 -1
- package/dist/image.d.ts +20 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1178 -71
- package/dist/index.js.map +15 -9
- package/dist/kinds.d.ts +13 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/provider.d.ts +15 -0
- package/dist/provider.d.ts.map +1 -1
- package/dist/request.d.ts.map +1 -1
- package/dist/reranking.d.ts +18 -0
- package/dist/reranking.d.ts.map +1 -0
- package/dist/speech.d.ts +20 -0
- package/dist/speech.d.ts.map +1 -0
- package/dist/transcription.d.ts +20 -0
- package/dist/transcription.d.ts.map +1 -0
- package/dist/transport.d.ts +10 -2
- package/dist/transport.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/decision.ts +211 -0
- package/src/discovery.ts +18 -0
- package/src/embedding.ts +15 -36
- package/src/image.ts +457 -0
- package/src/index.ts +8 -0
- package/src/kinds.ts +100 -0
- package/src/provider.ts +73 -12
- package/src/request.ts +2 -1
- package/src/reranking.ts +264 -0
- package/src/speech.ts +390 -0
- package/src/transcription.ts +322 -0
- package/src/transport.ts +90 -11
package/dist/kinds.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AzureAIFoundryDeployment } from "./discovery";
|
|
2
|
+
/**
|
|
3
|
+
* What a deployment runs, read from its model name. Project discovery reports no kind: an audio
|
|
4
|
+
* or rerank deployment lists no capabilities, or `chat_completion`, like a language model.
|
|
5
|
+
*/
|
|
6
|
+
export type FoundryKind = "language" | "embedding" | "decision" | "transcription" | "reranking" | "speech" | "image";
|
|
7
|
+
export declare const KIND_BINDINGS: Readonly<Record<FoundryKind, string>>;
|
|
8
|
+
export declare function deploymentKind(deployment: AzureAIFoundryDeployment): FoundryKind;
|
|
9
|
+
/** Reject a deployment of another kind, naming the binding that serves it. */
|
|
10
|
+
export declare function assertDeploymentKind(deployment: AzureAIFoundryDeployment, deploymentName: string, kind: Exclude<FoundryKind, "language">): void;
|
|
11
|
+
/** "an image", "a speech": the article a kind's name takes. */
|
|
12
|
+
export declare function article(kind: FoundryKind): string;
|
|
13
|
+
//# sourceMappingURL=kinds.d.ts.map
|
|
@@ -0,0 +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,CAWN;AAED,+DAA+D;AAC/D,wBAAgB,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAEjD"}
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { type LanguageModel, type LanguageModelDefinition, type LanguageModelLabel, type LanguageModelProvider, type ModelCostEstimator, type ModelRateCard, type ModelReasoningLevel } from "@sixb/core/models";
|
|
2
2
|
import { type AzureAIFoundryCatalogOptions } from "./catalog";
|
|
3
3
|
import { type ChatRequestOptions } from "./chat-request";
|
|
4
|
+
import { type AzureAIFoundryDecisionModel, type AzureAIFoundryDecisionOptions } from "./decision";
|
|
4
5
|
import { type AzureAIFoundryCatalog, type AzureAIFoundryDeployment, type AzureAIFoundryDiscoveryOptions } from "./discovery";
|
|
5
6
|
import { type AzureAIFoundryEmbeddingModel, type AzureAIFoundryEmbeddingOptions, type AzureAIFoundryEmbeddingTransportOptions } from "./embedding";
|
|
7
|
+
import { type AzureAIFoundryImageModel, type AzureAIFoundryImageOptions } from "./image";
|
|
6
8
|
import { type MessagesRequestOptions } from "./messages-request";
|
|
7
9
|
import { type RequestOptions } from "./request";
|
|
10
|
+
import { type AzureAIFoundryRerankingModel, type AzureAIFoundryRerankingOptions } from "./reranking";
|
|
11
|
+
import { type AzureAIFoundrySpeechModel, type AzureAIFoundrySpeechOptions } from "./speech";
|
|
12
|
+
import { type AzureAIFoundryTranscriptionModel, type AzureAIFoundryTranscriptionOptions } from "./transcription";
|
|
8
13
|
import { type FoundryProtocol, type TransportOptions } from "./transport";
|
|
9
14
|
export interface AzureAIFoundryOptions extends TransportOptions {
|
|
10
15
|
/** Explicit resource transport: project endpoints do not route embeddings. */
|
|
@@ -65,6 +70,16 @@ export interface AzureAIFoundryProvider extends LanguageModelProvider {
|
|
|
65
70
|
responses(deploymentName: string, options?: AzureAIFoundryModelOptions): AzureAIFoundryModel<"responses">;
|
|
66
71
|
messages(deploymentName: string, options?: AzureAIFoundryMessagesOptions): AzureAIFoundryModel<"messages">;
|
|
67
72
|
embedding(deploymentName: string, options: AzureAIFoundryEmbeddingOptions): AzureAIFoundryEmbeddingModel;
|
|
73
|
+
/** A deployment of a decision model, such as Microsoft-Decision-1, for `models.decision`. */
|
|
74
|
+
decision(deploymentName: string, options?: AzureAIFoundryDecisionOptions): AzureAIFoundryDecisionModel;
|
|
75
|
+
/** A transcription deployment, such as gpt-4o-transcribe, for `models.audio.transcription`. */
|
|
76
|
+
transcription(deploymentName: string, options?: AzureAIFoundryTranscriptionOptions): AzureAIFoundryTranscriptionModel;
|
|
77
|
+
/** A Cohere rerank deployment, such as Cohere-rerank-v5-fast, for `models.reranking`. */
|
|
78
|
+
reranking(deploymentName: string, options?: AzureAIFoundryRerankingOptions): AzureAIFoundryRerankingModel;
|
|
79
|
+
/** A speech deployment, such as gpt-4o-mini-tts, for `models.audio.speech`. */
|
|
80
|
+
speech(deploymentName: string, options?: AzureAIFoundrySpeechOptions): AzureAIFoundrySpeechModel;
|
|
81
|
+
/** An image deployment, such as gpt-image-1.5 or FLUX.1-Kontext-pro, for `models.image`. */
|
|
82
|
+
image(deploymentName: string, options?: AzureAIFoundryImageOptions): AzureAIFoundryImageModel;
|
|
68
83
|
readonly catalog: AzureAIFoundryCatalog;
|
|
69
84
|
chat(deploymentName: string, options?: AzureAIFoundryChatOptions): AzureAIFoundryModel<"chat">;
|
|
70
85
|
}
|
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;AAK1B,OAAO,EACL,KAAK,4BAA4B,EAGlC,MAAM,WAAW,CAAA;AAElB,OAAO,EAAE,KAAK,kBAAkB,EAA2C,MAAM,gBAAgB,CAAA;AACjG,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,8BAA8B,EAGpC,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,8BAA8B,EACnC,KAAK,uCAAuC,EAE7C,MAAM,aAAa,CAAA;
|
|
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AC,iBAAiB,CAAC,EAAE,MAAM,CAAA;CACpC;AAyBD,wBAAgB,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAe7D;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,oBAAoB,EAC7B,UAAU,EAAE,uBAAuB,EACnC,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,wBAAwB,GACpC,UAAU,CAsGZ;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,oBAAoB,EAC7B,UAAU,EAAE,uBAAuB,EACnC,OAAO,EAAE;IAAE,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAAE,EACnF,KAAK,EAAE,MAAM,EACb,SAAS,UAAQ,GAChB,MAAM,GAAG,SAAS,CAepB;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,UAAU,EAAE,uBAAuB,EACnC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,SAAS,UAAQ,GAChB,IAAI,CAwDN;AAUD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,sBAAsB,GAAG,UAAU,GAAG,SAAS,CAItF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ModelCostEstimator, type ModelRateCard, type RerankingModel } from "@sixb/core/models";
|
|
2
|
+
import { type FoundryDeployments } from "./discovery";
|
|
3
|
+
import type { AzureAIFoundryModelMetadata } from "./provider";
|
|
4
|
+
import { type FoundryTransport } from "./transport";
|
|
5
|
+
export interface AzureAIFoundryRerankingOptions {
|
|
6
|
+
/** Deadline for one reranking, response included. Default: 30,000 ms. */
|
|
7
|
+
readonly timeoutMs?: number;
|
|
8
|
+
readonly rateCard?: ModelRateCard;
|
|
9
|
+
readonly costEstimator?: ModelCostEstimator;
|
|
10
|
+
}
|
|
11
|
+
export interface AzureAIFoundryRerankingModel extends RerankingModel {
|
|
12
|
+
readonly metadata: AzureAIFoundryModelMetadata;
|
|
13
|
+
resolve(options?: {
|
|
14
|
+
readonly offline?: boolean;
|
|
15
|
+
}): Promise<AzureAIFoundryRerankingModel>;
|
|
16
|
+
}
|
|
17
|
+
export declare function createFoundryReranking(providerId: string, modelId: string, options: AzureAIFoundryRerankingOptions, transport: FoundryTransport, deployments: FoundryDeployments): AzureAIFoundryRerankingModel;
|
|
18
|
+
//# sourceMappingURL=reranking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reranking.d.ts","sourceRoot":"","sources":["../src/reranking.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EAEvB,KAAK,aAAa,EAElB,KAAK,cAAc,EAQpB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAGL,KAAK,kBAAkB,EAExB,MAAM,aAAa,CAAA;AAEpB,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAE7D,OAAO,EAAa,KAAK,gBAAgB,EAAuB,MAAM,aAAa,CAAA;AAGnF,MAAM,WAAW,8BAA8B;IAC7C,yEAAyE;IACzE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAA;IACjC,QAAQ,CAAC,aAAa,CAAC,EAAE,kBAAkB,CAAA;CAC5C;AAED,MAAM,WAAW,4BAA6B,SAAQ,cAAc;IAClE,QAAQ,CAAC,QAAQ,EAAE,2BAA2B,CAAA;IAC9C,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAA;CACzF;AAoCD,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,8BAA8B,EACvC,SAAS,EAAE,gBAAgB,EAC3B,WAAW,EAAE,kBAAkB,GAC9B,4BAA4B,CAe9B"}
|
package/dist/speech.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ModelRateCard, type SpeechCostEstimator, type SpeechModel } from "@sixb/core/models";
|
|
2
|
+
import { type FoundryDeployments } from "./discovery";
|
|
3
|
+
import type { AzureAIFoundryModelMetadata } from "./provider";
|
|
4
|
+
import { type FoundryTransport } from "./transport";
|
|
5
|
+
export interface AzureAIFoundrySpeechOptions {
|
|
6
|
+
/** The voice used when a request names none. Default: `alloy`. */
|
|
7
|
+
readonly voice?: string;
|
|
8
|
+
/** Deadline for one generation, response included. Default: 120,000 ms. */
|
|
9
|
+
readonly timeoutMs?: number;
|
|
10
|
+
readonly rateCard?: ModelRateCard;
|
|
11
|
+
readonly costEstimator?: SpeechCostEstimator;
|
|
12
|
+
}
|
|
13
|
+
export interface AzureAIFoundrySpeechModel extends SpeechModel {
|
|
14
|
+
readonly metadata: AzureAIFoundryModelMetadata;
|
|
15
|
+
resolve(options?: {
|
|
16
|
+
readonly offline?: boolean;
|
|
17
|
+
}): Promise<AzureAIFoundrySpeechModel>;
|
|
18
|
+
}
|
|
19
|
+
export declare function createFoundrySpeech(providerId: string, modelId: string, options: AzureAIFoundrySpeechOptions, transport: FoundryTransport, deployments: FoundryDeployments): AzureAIFoundrySpeechModel;
|
|
20
|
+
//# sourceMappingURL=speech.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"speech.d.ts","sourceRoot":"","sources":["../src/speech.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,aAAa,EAGlB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAOjB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAGL,KAAK,kBAAkB,EAExB,MAAM,aAAa,CAAA;AAEpB,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAE7D,OAAO,EAAa,KAAK,gBAAgB,EAAa,MAAM,aAAa,CAAA;AAGzE,MAAM,WAAW,2BAA2B;IAC1C,kEAAkE;IAClE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,2EAA2E;IAC3E,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAA;IACjC,QAAQ,CAAC,aAAa,CAAC,EAAE,mBAAmB,CAAA;CAC7C;AAED,MAAM,WAAW,yBAA0B,SAAQ,WAAW;IAC5D,QAAQ,CAAC,QAAQ,EAAE,2BAA2B,CAAA;IAC9C,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAA;CACtF;AAqDD,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,2BAA2B,EACpC,SAAS,EAAE,gBAAgB,EAC3B,WAAW,EAAE,kBAAkB,GAC9B,yBAAyB,CAkB3B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ModelRateCard, type TranscriptionCostEstimator, type TranscriptionModel } from "@sixb/core/models";
|
|
2
|
+
import { type FoundryDeployments } from "./discovery";
|
|
3
|
+
import type { AzureAIFoundryModelMetadata } from "./provider";
|
|
4
|
+
import { type FoundryTransport } from "./transport";
|
|
5
|
+
export interface AzureAIFoundryTranscriptionOptions {
|
|
6
|
+
/** The spoken language as an ISO-639 code, such as `en`. Default: detected by the model. */
|
|
7
|
+
readonly language?: string;
|
|
8
|
+
/** Deadline for one transcription, upload and response included. Default: 120,000 ms. */
|
|
9
|
+
readonly timeoutMs?: number;
|
|
10
|
+
readonly rateCard?: ModelRateCard;
|
|
11
|
+
readonly costEstimator?: TranscriptionCostEstimator;
|
|
12
|
+
}
|
|
13
|
+
export interface AzureAIFoundryTranscriptionModel extends TranscriptionModel {
|
|
14
|
+
readonly metadata: AzureAIFoundryModelMetadata;
|
|
15
|
+
resolve(options?: {
|
|
16
|
+
readonly offline?: boolean;
|
|
17
|
+
}): Promise<AzureAIFoundryTranscriptionModel>;
|
|
18
|
+
}
|
|
19
|
+
export declare function createFoundryTranscription(providerId: string, modelId: string, options: AzureAIFoundryTranscriptionOptions, transport: FoundryTransport, deployments: FoundryDeployments): AzureAIFoundryTranscriptionModel;
|
|
20
|
+
//# sourceMappingURL=transcription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcription.d.ts","sourceRoot":"","sources":["../src/transcription.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,aAAa,EAGlB,KAAK,0BAA0B,EAC/B,KAAK,kBAAkB,EAKxB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAGL,KAAK,kBAAkB,EAExB,MAAM,aAAa,CAAA;AAEpB,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAE7D,OAAO,EAAa,KAAK,gBAAgB,EAAuB,MAAM,aAAa,CAAA;AAGnF,MAAM,WAAW,kCAAkC;IACjD,4FAA4F;IAC5F,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,yFAAyF;IACzF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAA;IACjC,QAAQ,CAAC,aAAa,CAAC,EAAE,0BAA0B,CAAA;CACpD;AAED,MAAM,WAAW,gCAAiC,SAAQ,kBAAkB;IAC1E,QAAQ,CAAC,QAAQ,EAAE,2BAA2B,CAAA;IAC9C,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAA;CAC7F;AA8FD,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,kCAAkC,EAC3C,SAAS,EAAE,gBAAgB,EAC3B,WAAW,EAAE,kBAAkB,GAC9B,gCAAgC,CAkBlC"}
|
package/dist/transport.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { ModelProviderError } from "@sixb/core/models";
|
|
|
2
2
|
import { RequestDiagnostics } from "./diagnostics";
|
|
3
3
|
export type ValueSource<T> = T | ((signal: AbortSignal) => T | Promise<T>);
|
|
4
4
|
export type FoundryProtocol = "responses" | "messages" | "chat";
|
|
5
|
+
type FoundryRoute = FoundryProtocol | OneShotRoute;
|
|
6
|
+
/** Routes that answer in one body. A failure is never replayed: the call may have been billed. */
|
|
7
|
+
type OneShotRoute = "embeddings" | "decision" | "transcription" | "reranking" | "speech" | "image" | "image-edit";
|
|
5
8
|
export interface TransportOptions {
|
|
6
9
|
readonly endpoint: string;
|
|
7
10
|
readonly apiKey: ValueSource<string | undefined>;
|
|
@@ -16,15 +19,20 @@ export declare class FoundryTransport {
|
|
|
16
19
|
readonly projectUrl: string;
|
|
17
20
|
private readonly options;
|
|
18
21
|
constructor(options: TransportOptions, target?: "project" | "resource");
|
|
19
|
-
post(body: string, signal: AbortSignal, providerId: string, modelId: string, protocol?:
|
|
22
|
+
post(body: string | FormData, signal: AbortSignal, providerId: string, modelId: string, protocol?: FoundryRoute): Promise<Response>;
|
|
20
23
|
redactText(response: Response, value: string | undefined): string | undefined;
|
|
21
24
|
redactError(response: Response, error: ModelProviderError): ModelProviderError;
|
|
22
25
|
redactFailure(response: Response, error: unknown): unknown;
|
|
23
26
|
headers(signal: AbortSignal, diagnostics: RequestDiagnostics, keyHeader?: "api-key" | "x-api-key"): Promise<Headers>;
|
|
24
27
|
fetch(url: string, init: RequestInit): Promise<Response>;
|
|
25
|
-
url(protocol:
|
|
28
|
+
url(protocol: FoundryRoute, deployment?: string): string;
|
|
26
29
|
}
|
|
30
|
+
/** Read a JSON body up to `maxBytes`; the reader is released on success, failure or abort. */
|
|
31
|
+
export declare function readJson(response: Response, signal: AbortSignal, maxBytes: number): Promise<unknown>;
|
|
32
|
+
/** Read a body as UTF-8 up to `maxBytes`; the reader is released on success, failure or abort. */
|
|
33
|
+
export declare function readText(response: Response, signal: AbortSignal, maxBytes: number): Promise<string>;
|
|
27
34
|
export declare function requestId(response: Response): string | undefined;
|
|
28
35
|
/** Bound credential/transport work even when an injected implementation ignores the signal. */
|
|
29
36
|
export declare function abortable<T>(operation: () => T | Promise<T>, signal: AbortSignal): Promise<T>;
|
|
37
|
+
export {};
|
|
30
38
|
//# sourceMappingURL=transport.d.ts.map
|
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;
|
|
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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
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.6",
|
|
35
|
+
"@sixb/model-protocols": "0.2.6"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/bun": "latest",
|
package/src/decision.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type DecisionModel,
|
|
3
|
+
type DecisionModelDefinition,
|
|
4
|
+
type DecisionModelRequest,
|
|
5
|
+
type DecisionModelResult,
|
|
6
|
+
defineModelRateCard,
|
|
7
|
+
type ModelCostEstimator,
|
|
8
|
+
ModelProviderError,
|
|
9
|
+
type ModelRateCard,
|
|
10
|
+
} from "@sixb/core/models"
|
|
11
|
+
import { systemOneRequest, systemOneResult } from "@sixb/model-protocols/systemone"
|
|
12
|
+
import { tokenEstimator } from "./accounting"
|
|
13
|
+
import {
|
|
14
|
+
type AzureAIFoundryDeployment,
|
|
15
|
+
deploymentMetadata,
|
|
16
|
+
type FoundryDeployments,
|
|
17
|
+
type ResolvedDeployment,
|
|
18
|
+
} from "./discovery"
|
|
19
|
+
import { assertDeploymentKind } from "./kinds"
|
|
20
|
+
import type { AzureAIFoundryModelMetadata } from "./provider"
|
|
21
|
+
import { azurePublisher } from "./publisher"
|
|
22
|
+
import { abortable, type FoundryTransport, readJson, requestId } from "./transport"
|
|
23
|
+
import { PREFIX, positiveInteger } from "./util"
|
|
24
|
+
|
|
25
|
+
export interface AzureAIFoundryDecisionOptions {
|
|
26
|
+
/** Deadline for one evaluation, body included. Default: 30,000 ms. */
|
|
27
|
+
readonly timeoutMs?: number
|
|
28
|
+
readonly rateCard?: ModelRateCard
|
|
29
|
+
readonly costEstimator?: ModelCostEstimator
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface AzureAIFoundryDecisionModel extends DecisionModel {
|
|
33
|
+
readonly metadata: AzureAIFoundryModelMetadata
|
|
34
|
+
resolve(options?: { readonly offline?: boolean }): Promise<AzureAIFoundryDecisionModel>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Azure Retail Prices, meter "Microsoft Decision 1 1M Tokens", USD 0.042 in every region from
|
|
39
|
+
* 2026-10-01 (verified 2026-11-13). The launch post lists output tokens as N/A: one per question.
|
|
40
|
+
*/
|
|
41
|
+
const DECISION_1_RATE_CARD: ModelRateCard = { currency: "USD", input: "0.042", output: "0" }
|
|
42
|
+
|
|
43
|
+
/** Microsoft-Decision-1 rejects other sizes with HTTP 400 `unsupported_request_argument`. */
|
|
44
|
+
const CAPABILITIES: DecisionModelDefinition["capabilities"] = Object.freeze({
|
|
45
|
+
questions: Object.freeze(["choice", "score", "probability"] as const),
|
|
46
|
+
maxChoices: 255,
|
|
47
|
+
maxScoreLevels: 10,
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
/** 20 questions of 255 options answer in about 200 KB. */
|
|
51
|
+
const MAX_RESPONSE_BYTES = 16 * 1024 * 1024
|
|
52
|
+
|
|
53
|
+
/** AbortSignal.timeout's largest delay. */
|
|
54
|
+
const MAX_TIMEOUT_MS = 2 ** 31 - 1
|
|
55
|
+
|
|
56
|
+
interface DecisionSettings {
|
|
57
|
+
readonly timeoutMs: number
|
|
58
|
+
readonly rateCard?: ModelRateCard
|
|
59
|
+
readonly costEstimator?: ModelCostEstimator
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface DecisionResolution extends ResolvedDeployment {
|
|
63
|
+
readonly costEstimator: ModelCostEstimator
|
|
64
|
+
/** Lowercase model names the deployment may answer with. */
|
|
65
|
+
readonly models: readonly string[]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function createFoundryDecision(
|
|
69
|
+
providerId: string,
|
|
70
|
+
modelId: string,
|
|
71
|
+
options: AzureAIFoundryDecisionOptions,
|
|
72
|
+
transport: FoundryTransport,
|
|
73
|
+
deployments: FoundryDeployments
|
|
74
|
+
): AzureAIFoundryDecisionModel {
|
|
75
|
+
if (!modelId.trim() || modelId !== modelId.trim())
|
|
76
|
+
throw new TypeError(`${PREFIX} deploymentName must be nonempty without surrounding whitespace.`)
|
|
77
|
+
positiveInteger(options.timeoutMs, "timeoutMs")
|
|
78
|
+
if (options.timeoutMs !== undefined && options.timeoutMs > MAX_TIMEOUT_MS)
|
|
79
|
+
throw new TypeError(`${PREFIX} timeoutMs must be at most ${MAX_TIMEOUT_MS}.`)
|
|
80
|
+
if (options.rateCard && options.costEstimator)
|
|
81
|
+
throw new TypeError(`${PREFIX} Configure either rateCard or costEstimator, not both.`)
|
|
82
|
+
// Validate and snapshot now: later edits to the caller's object change nothing.
|
|
83
|
+
const settings: DecisionSettings = Object.freeze({
|
|
84
|
+
timeoutMs: options.timeoutMs ?? 30_000,
|
|
85
|
+
...(options.rateCard ? { rateCard: defineModelRateCard(options.rateCard) } : {}),
|
|
86
|
+
...(options.costEstimator ? { costEstimator: options.costEstimator } : {}),
|
|
87
|
+
})
|
|
88
|
+
return decisionBinding(providerId, modelId, settings, transport, deployments)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Discovery pins the deployed model for pricing; inference posts System One to the resource. */
|
|
92
|
+
function decisionBinding(
|
|
93
|
+
providerId: string,
|
|
94
|
+
modelId: string,
|
|
95
|
+
settings: DecisionSettings,
|
|
96
|
+
transport: FoundryTransport,
|
|
97
|
+
deployments: FoundryDeployments,
|
|
98
|
+
resolution?: DecisionResolution
|
|
99
|
+
): AzureAIFoundryDecisionModel {
|
|
100
|
+
const deployment = resolution?.deployment
|
|
101
|
+
const definition: DecisionModelDefinition = Object.freeze({
|
|
102
|
+
kind: "decision",
|
|
103
|
+
providerId,
|
|
104
|
+
modelId,
|
|
105
|
+
...(deployment ? { publisher: azurePublisher(deployment.modelPublisher) } : {}),
|
|
106
|
+
via: "Azure AI Foundry",
|
|
107
|
+
capabilities: CAPABILITIES,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
let pending: Promise<AzureAIFoundryDecisionModel> | undefined
|
|
111
|
+
const binding: AzureAIFoundryDecisionModel = Object.freeze({
|
|
112
|
+
providerId,
|
|
113
|
+
modelId,
|
|
114
|
+
definition,
|
|
115
|
+
metadata: deploymentMetadata(resolution),
|
|
116
|
+
costEstimator: resolution?.costEstimator,
|
|
117
|
+
|
|
118
|
+
async resolve(input?: { readonly offline?: boolean }) {
|
|
119
|
+
if (resolution) return binding
|
|
120
|
+
const resolved = await deployments.resolve(modelId, input?.offline === true)
|
|
121
|
+
const found = resolved.deployment
|
|
122
|
+
assertDeploymentKind(found, modelId, "decision")
|
|
123
|
+
// Azure answers with the lowercase model name, e.g. "microsoft-decision-1".
|
|
124
|
+
const models = [modelId, found.modelName, `${found.modelName}-${found.modelVersion}`].map(
|
|
125
|
+
(name) => name.toLowerCase()
|
|
126
|
+
)
|
|
127
|
+
return decisionBinding(providerId, modelId, settings, transport, deployments, {
|
|
128
|
+
...resolved,
|
|
129
|
+
models,
|
|
130
|
+
costEstimator:
|
|
131
|
+
settings.costEstimator ?? decisionEstimator(found, settings.rateCard, models),
|
|
132
|
+
})
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
async evaluate(request: DecisionModelRequest): Promise<DecisionModelResult> {
|
|
136
|
+
const signal = AbortSignal.any([
|
|
137
|
+
...(request.signal ? [request.signal] : []),
|
|
138
|
+
AbortSignal.timeout(settings.timeoutMs),
|
|
139
|
+
])
|
|
140
|
+
signal.throwIfAborted()
|
|
141
|
+
if (!resolution) {
|
|
142
|
+
// A direct call pins the deployment once, as the runtime does before admission.
|
|
143
|
+
pending ??= binding.resolve().catch((error) => {
|
|
144
|
+
pending = undefined
|
|
145
|
+
throw error
|
|
146
|
+
})
|
|
147
|
+
const resolved = await abortable(() => pending!, signal)
|
|
148
|
+
return resolved.evaluate({ ...request, signal })
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const response = await transport.post(
|
|
152
|
+
JSON.stringify(systemOneRequest(modelId, request)),
|
|
153
|
+
signal,
|
|
154
|
+
providerId,
|
|
155
|
+
modelId,
|
|
156
|
+
"decision"
|
|
157
|
+
)
|
|
158
|
+
const id = transport.redactText(response, requestId(response))
|
|
159
|
+
let body: unknown
|
|
160
|
+
try {
|
|
161
|
+
body = await readJson(response, signal, MAX_RESPONSE_BYTES)
|
|
162
|
+
} catch {
|
|
163
|
+
// The parse error can quote the body; only the status and request ID travel.
|
|
164
|
+
if (signal.aborted) throw signal.reason
|
|
165
|
+
throw new ModelProviderError(
|
|
166
|
+
`${PREFIX} Decision model returned invalid JSON.`,
|
|
167
|
+
providerId,
|
|
168
|
+
modelId,
|
|
169
|
+
{ code: "invalid_json", requestId: id, status: response.status }
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
return systemOneResult(body, request.questions, {
|
|
173
|
+
providerId,
|
|
174
|
+
modelId,
|
|
175
|
+
errorPrefix: PREFIX,
|
|
176
|
+
requestId: id,
|
|
177
|
+
// Answers from another model than the deployment's are not this binding's answers.
|
|
178
|
+
assertModel: (model) => {
|
|
179
|
+
if (typeof model !== "string" || !resolution.models.includes(model.toLowerCase()))
|
|
180
|
+
throw new Error("Unexpected response model")
|
|
181
|
+
},
|
|
182
|
+
redact: (value) => transport.redactText(response, value) ?? value,
|
|
183
|
+
})
|
|
184
|
+
},
|
|
185
|
+
})
|
|
186
|
+
return binding
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Microsoft-Decision-1 version 1 has a published price; any other model stays unknown. */
|
|
190
|
+
function decisionEstimator(
|
|
191
|
+
deployment: AzureAIFoundryDeployment,
|
|
192
|
+
rateCard: ModelRateCard | undefined,
|
|
193
|
+
models: readonly string[]
|
|
194
|
+
): ModelCostEstimator {
|
|
195
|
+
const { modelName, modelVersion } = deployment
|
|
196
|
+
const published =
|
|
197
|
+
modelName.toLowerCase() === "microsoft-decision-1" && modelVersion === "1"
|
|
198
|
+
? DECISION_1_RATE_CARD
|
|
199
|
+
: undefined
|
|
200
|
+
const estimator = tokenEstimator(rateCard ?? published, undefined, [], () => true)
|
|
201
|
+
return {
|
|
202
|
+
estimateReservation: estimator.estimateReservation,
|
|
203
|
+
// An answer from another model is never priced at this deployment's rates.
|
|
204
|
+
estimate: (input) => {
|
|
205
|
+
const actual = input.route?.modelId ?? input.responseModelId
|
|
206
|
+
return actual === undefined || models.includes(actual.toLowerCase())
|
|
207
|
+
? estimator.estimate(input)
|
|
208
|
+
: { status: "unpriceable", reason: "missing-rate-card" }
|
|
209
|
+
},
|
|
210
|
+
}
|
|
211
|
+
}
|
package/src/discovery.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
ModelProviderError,
|
|
6
6
|
} from "@sixb/core/models"
|
|
7
7
|
import { RequestDiagnostics } from "./diagnostics"
|
|
8
|
+
import type { AzureAIFoundryModelMetadata } from "./provider"
|
|
8
9
|
import type { FoundryProtocol } from "./transport"
|
|
9
10
|
import { abortable, type FoundryTransport, requestId } from "./transport"
|
|
10
11
|
import { object, PREFIX, positiveInteger } from "./util"
|
|
@@ -61,6 +62,23 @@ export interface ResolvedDeployment {
|
|
|
61
62
|
readonly discoveredAt: string
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
/** What a resolved binding reports about its deployment; empty before resolution. */
|
|
66
|
+
export function deploymentMetadata(resolution?: ResolvedDeployment): AzureAIFoundryModelMetadata {
|
|
67
|
+
const deployment = resolution?.deployment
|
|
68
|
+
return Object.freeze(
|
|
69
|
+
deployment
|
|
70
|
+
? {
|
|
71
|
+
deployment,
|
|
72
|
+
modelName: deployment.modelName,
|
|
73
|
+
modelVersion: deployment.modelVersion,
|
|
74
|
+
publisher: deployment.modelPublisher,
|
|
75
|
+
sku: deployment.sku.name,
|
|
76
|
+
discoveredAt: resolution.discoveredAt,
|
|
77
|
+
}
|
|
78
|
+
: {}
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
64
82
|
interface DiscoverySettings {
|
|
65
83
|
readonly url: string
|
|
66
84
|
readonly ttlMs: number
|
package/src/embedding.ts
CHANGED
|
@@ -15,9 +15,20 @@ import {
|
|
|
15
15
|
} from "@sixb/core/models"
|
|
16
16
|
import { tokenEstimator } from "./accounting"
|
|
17
17
|
import type { CatalogEmbeddingModel, RemoteModelsDevCatalog } from "./catalog"
|
|
18
|
-
import
|
|
18
|
+
import {
|
|
19
|
+
type AzureAIFoundryDeployment,
|
|
20
|
+
deploymentMetadata,
|
|
21
|
+
type FoundryDeployments,
|
|
22
|
+
type ResolvedDeployment,
|
|
23
|
+
} from "./discovery"
|
|
19
24
|
import type { AzureAIFoundryModelMetadata } from "./provider"
|
|
20
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
abortable,
|
|
27
|
+
type FoundryTransport,
|
|
28
|
+
readJson,
|
|
29
|
+
requestId,
|
|
30
|
+
type TransportOptions,
|
|
31
|
+
} from "./transport"
|
|
21
32
|
import { counter, object, PREFIX } from "./util"
|
|
22
33
|
|
|
23
34
|
export type AzureAIFoundryEmbeddingTransportOptions = Pick<
|
|
@@ -92,19 +103,7 @@ export function createFoundryEmbedding(
|
|
|
92
103
|
rateCard: options.rateCard && defineModelRateCard(options.rateCard),
|
|
93
104
|
costEstimator: options.costEstimator,
|
|
94
105
|
})
|
|
95
|
-
const
|
|
96
|
-
const metadata = Object.freeze(
|
|
97
|
-
deployment
|
|
98
|
-
? {
|
|
99
|
-
deployment,
|
|
100
|
-
modelName: deployment.modelName,
|
|
101
|
-
modelVersion: deployment.modelVersion,
|
|
102
|
-
publisher: deployment.modelPublisher,
|
|
103
|
-
sku: deployment.sku.name,
|
|
104
|
-
discoveredAt: resolution.discoveredAt,
|
|
105
|
-
}
|
|
106
|
-
: {}
|
|
107
|
-
)
|
|
106
|
+
const metadata = deploymentMetadata(resolution)
|
|
108
107
|
let pending: Promise<AzureAIFoundryEmbeddingModel> | undefined
|
|
109
108
|
const binding: AzureAIFoundryEmbeddingModel = Object.freeze({
|
|
110
109
|
providerId,
|
|
@@ -286,26 +285,6 @@ function invalidResponse(
|
|
|
286
285
|
)
|
|
287
286
|
}
|
|
288
287
|
|
|
289
|
-
async function readResponse(response: Response, signal: AbortSignal): Promise<unknown> {
|
|
290
|
-
const reader = response.body?.getReader()
|
|
291
|
-
if (!reader) throw new Error("Empty embedding response")
|
|
292
|
-
const chunks: Uint8Array[] = []
|
|
293
|
-
let bytes = 0
|
|
294
|
-
try {
|
|
295
|
-
for (;;) {
|
|
296
|
-
const chunk = await abortable(() => reader.read(), signal)
|
|
297
|
-
if (chunk.done) break
|
|
298
|
-
bytes += chunk.value.length
|
|
299
|
-
if (bytes > 128 * 1024 * 1024) throw new Error("Embedding response exceeds 128 MiB")
|
|
300
|
-
chunks.push(chunk.value)
|
|
301
|
-
}
|
|
302
|
-
return JSON.parse(Buffer.concat(chunks).toString("utf8"))
|
|
303
|
-
} finally {
|
|
304
|
-
void reader.cancel().catch(() => {})
|
|
305
|
-
reader.releaseLock()
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
288
|
function embeddingUsage(raw: JsonObject | undefined): ModelUsage {
|
|
310
289
|
const inputTokens = counter(raw?.prompt_tokens)
|
|
311
290
|
const totalTokens = counter(raw?.total_tokens)
|
|
@@ -351,7 +330,7 @@ async function readEmbeddingResult(
|
|
|
351
330
|
}
|
|
352
331
|
let body: Record<string, unknown> | undefined
|
|
353
332
|
try {
|
|
354
|
-
body = record(await
|
|
333
|
+
body = record(await readJson(response, signal, 128 * 1024 * 1024))
|
|
355
334
|
} catch {
|
|
356
335
|
if (signal.aborted) throw signal.reason
|
|
357
336
|
throw invalidResponse(providerId, modelId, facts)
|