@tensorcost/sdk 0.5.0 → 1.0.0
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/CHANGELOG.md +117 -0
- package/README.md +63 -95
- package/dist/adapters/crewai.d.ts +4 -0
- package/dist/adapters/crewai.d.ts.map +1 -0
- package/dist/adapters/crewai.js +6 -0
- package/dist/adapters/crewai.js.map +1 -0
- package/dist/adapters/langchain.d.ts +4 -0
- package/dist/adapters/langchain.d.ts.map +1 -0
- package/dist/adapters/langchain.js +6 -0
- package/dist/adapters/langchain.js.map +1 -0
- package/dist/adapters/llamaindex.d.ts +4 -0
- package/dist/adapters/llamaindex.d.ts.map +1 -0
- package/dist/adapters/llamaindex.js +6 -0
- package/dist/adapters/llamaindex.js.map +1 -0
- package/dist/adapters/vercel-ai.d.ts +4 -0
- package/dist/adapters/vercel-ai.d.ts.map +1 -0
- package/dist/adapters/vercel-ai.js +6 -0
- package/dist/adapters/vercel-ai.js.map +1 -0
- package/dist/admit-client.d.ts +39 -0
- package/dist/admit-client.d.ts.map +1 -0
- package/dist/admit-client.js +93 -0
- package/dist/admit-client.js.map +1 -0
- package/dist/applied.d.ts +6 -1
- package/dist/applied.d.ts.map +1 -1
- package/dist/applied.js +13 -1
- package/dist/applied.js.map +1 -1
- package/dist/circuit-observations.d.ts +12 -0
- package/dist/circuit-observations.d.ts.map +1 -0
- package/dist/circuit-observations.js +37 -0
- package/dist/circuit-observations.js.map +1 -0
- package/dist/circuit.d.ts +4 -1
- package/dist/circuit.d.ts.map +1 -1
- package/dist/circuit.js +13 -7
- package/dist/circuit.js.map +1 -1
- package/dist/config.d.ts +2 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +74 -6
- package/dist/config.js.map +1 -1
- package/dist/decision.d.ts +11 -0
- package/dist/decision.d.ts.map +1 -0
- package/dist/decision.js +40 -0
- package/dist/decision.js.map +1 -0
- package/dist/errors.d.ts +40 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +46 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/layer.d.ts +27 -0
- package/dist/layer.d.ts.map +1 -0
- package/dist/layer.js +77 -0
- package/dist/layer.js.map +1 -0
- package/dist/providers/anthropic.d.ts +11 -1
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +196 -18
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/bedrock.d.ts +1 -1
- package/dist/providers/bedrock.d.ts.map +1 -1
- package/dist/providers/bedrock.js +21 -3
- package/dist/providers/bedrock.js.map +1 -1
- package/dist/providers/detect.d.ts.map +1 -1
- package/dist/providers/detect.js +17 -2
- package/dist/providers/detect.js.map +1 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/openai.d.ts +11 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +255 -20
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/vertex.d.ts +14 -0
- package/dist/providers/vertex.d.ts.map +1 -0
- package/dist/providers/vertex.js +174 -0
- package/dist/providers/vertex.js.map +1 -0
- package/dist/proxy-client.d.ts +37 -1
- package/dist/proxy-client.d.ts.map +1 -1
- package/dist/proxy-client.js +124 -4
- package/dist/proxy-client.js.map +1 -1
- package/dist/sdk-layer.d.ts +26 -0
- package/dist/sdk-layer.d.ts.map +1 -0
- package/dist/sdk-layer.js +73 -0
- package/dist/sdk-layer.js.map +1 -0
- package/dist/transport.d.ts +6 -1
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +14 -3
- package/dist/transport.js.map +1 -1
- package/dist/types.d.ts +178 -17
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +9 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +10 -0
- package/dist/version.js.map +1 -0
- package/dist/wrap.d.ts +13 -14
- package/dist/wrap.d.ts.map +1 -1
- package/dist/wrap.js +66 -59
- package/dist/wrap.js.map +1 -1
- package/package.json +7 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bedrock.js","sourceRoot":"","sources":["../../src/providers/bedrock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,
|
|
1
|
+
{"version":3,"file":"bedrock.js","sourceRoot":"","sources":["../../src/providers/bedrock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,sEAAsE;AACtE,6CAA6C;AAC7C,MAAM,eAAe,GAAG,gCAAgC,CAAC;AAmCzD,iFAAiF;AAEjF,SAAS,MAAM;IACb,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,WAA+B;IAIzD,QAAQ,WAAW,EAAE,CAAC;QACpB,KAAK,oBAAoB;YACvB,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;QACnE,KAAK,iBAAiB;YACpB,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;QAC/D,KAAK,sCAAsC;YACzC,OAAO,EAAE,SAAS,EAAE,6BAA6B,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;QACzE,KAAK,uBAAuB;YAC1B,OAAO,EAAE,SAAS,EAAE,yBAAyB,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;QAC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,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,GAAG,GAAgB;gBACvB,GAAG,YAAY;gBACf,WAAW,EAAE,MAAM,EAAE;gBACrB,YAAY,EAAE,IAAI;gBAClB,aAAa,EAAE,IAAI;gBACnB,cAAc,EAAE,IAAI;gBACpB,MAAM,EAAE,OAAO;gBACf,aAAa,EAAE,GAAI,GAAa,CAAC,IAAI,KAAM,GAAa,CAAC,OAAO,EAAE;aACnE,CAAC;YACF,IAAI,CAAC;gBAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC;YACtD,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;IAEF,eAAe,CAAC,GAAG,CAAC,UAAU,EAAE;QAC9B,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,eAAe;QACrB,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/providers/detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,QAAQ,
|
|
1
|
+
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/providers/detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,QAAQ,CAoExD"}
|
package/dist/providers/detect.js
CHANGED
|
@@ -33,6 +33,20 @@ export function detectProvider(client) {
|
|
|
33
33
|
if (hasBedrockShape) {
|
|
34
34
|
return "bedrock";
|
|
35
35
|
}
|
|
36
|
+
// google-genai Client in Vertex mode: vertexai=true + models.generate_content.
|
|
37
|
+
const apiClient = c._apiClient;
|
|
38
|
+
const vertexaiFlag = c.vertexai === true ||
|
|
39
|
+
(apiClient != null &&
|
|
40
|
+
typeof apiClient === "object" &&
|
|
41
|
+
apiClient.vertexai === true);
|
|
42
|
+
const models = c.models;
|
|
43
|
+
const hasVertexShape = vertexaiFlag &&
|
|
44
|
+
models != null &&
|
|
45
|
+
typeof models === "object" &&
|
|
46
|
+
typeof models.generateContent === "function";
|
|
47
|
+
if (hasVertexShape) {
|
|
48
|
+
return "vertex";
|
|
49
|
+
}
|
|
36
50
|
// OpenAI: has chat.completions.create OR completions.create
|
|
37
51
|
const chat = c.chat;
|
|
38
52
|
const chatCompletions = chat && typeof chat === "object" ? chat.completions : undefined;
|
|
@@ -50,8 +64,9 @@ export function detectProvider(client) {
|
|
|
50
64
|
if (hasAnthropicShape) {
|
|
51
65
|
return "anthropic";
|
|
52
66
|
}
|
|
53
|
-
throw new UnsupportedClientError("tensorcost: client does not look like an OpenAI, Anthropic,
|
|
67
|
+
throw new UnsupportedClientError("tensorcost: client does not look like an OpenAI, Anthropic, BedrockRuntimeClient, " +
|
|
68
|
+
"or Vertex AI Client instance " +
|
|
54
69
|
"(missing chat.completions.create / completions.create / messages.create / " +
|
|
55
|
-
"send+config.serviceId='Bedrock Runtime').");
|
|
70
|
+
"send+config.serviceId='Bedrock Runtime' / vertexai=true+models.generateContent).");
|
|
56
71
|
}
|
|
57
72
|
//# sourceMappingURL=detect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../../src/providers/detect.ts"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,KAAK,IAAI,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACxB,MAAM,cAAc,GAClB,YAAY;QACZ,MAAM,IAAI,IAAI;QACd,OAAO,MAAM,KAAK,QAAQ;QAC1B,OAAQ,MAAkC,CAAC,eAAe,KAAK,UAAU,CAAC;IAE5E,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,4DAA4D;IAC5D,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;IACpB,MAAM,eAAe,GACnB,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;IAClE,MAAM,cAAc,GAClB,CAAC,eAAe,IAAI,OAAO,eAAe,CAAC,MAAM,KAAK,UAAU,CAAC;QACjE,CAAC,CAAC,CAAC,WAAW,IAAI,OAAO,CAAC,CAAC,WAAW,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC;IAEhE,iCAAiC;IACjC,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;IAC5B,MAAM,iBAAiB,GACrB,QAAQ,IAAI,OAAO,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC;IAEpD,wEAAwE;IACxE,qEAAqE;IACrE,sEAAsE;IACtE,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,MAAM,IAAI,sBAAsB,CAC9B,oFAAoF;QAClF,+BAA+B;QAC/B,4EAA4E;QAC5E,kFAAkF,CACrF,CAAC;AACJ,CAAC"}
|
|
@@ -2,4 +2,5 @@ export { detectProvider, UnsupportedClientError } from "./detect.js";
|
|
|
2
2
|
export * as openaiProvider from "./openai.js";
|
|
3
3
|
export * as anthropicProvider from "./anthropic.js";
|
|
4
4
|
export * as bedrockProvider from "./bedrock.js";
|
|
5
|
+
export * as vertexProvider from "./vertex.js";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,cAAc,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,iBAAiB,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,eAAe,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,cAAc,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,iBAAiB,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,eAAe,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,cAAc,MAAM,aAAa,CAAC"}
|
package/dist/providers/index.js
CHANGED
|
@@ -2,4 +2,5 @@ export { detectProvider, UnsupportedClientError } from "./detect.js";
|
|
|
2
2
|
export * as openaiProvider from "./openai.js";
|
|
3
3
|
export * as anthropicProvider from "./anthropic.js";
|
|
4
4
|
export * as bedrockProvider from "./bedrock.js";
|
|
5
|
+
export * as vertexProvider from "./vertex.js";
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,cAAc,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,iBAAiB,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,eAAe,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,cAAc,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,iBAAiB,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,eAAe,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,cAAc,MAAM,aAAa,CAAC"}
|
|
@@ -18,17 +18,27 @@ import type { ObservationTransport } from "../transport.js";
|
|
|
18
18
|
import type { CircuitBreaker } from "../circuit.js";
|
|
19
19
|
import type { LifecycleEventCallback } from "../telemetry.js";
|
|
20
20
|
import type { RetryConfig } from "../retry.js";
|
|
21
|
+
import type { ControlLayer } from "../layer.js";
|
|
22
|
+
import type { SdkLayerClient } from "../sdk-layer.js";
|
|
21
23
|
export interface AppliedModeHardeningOpts {
|
|
24
|
+
maxLayer: ControlLayer;
|
|
22
25
|
appliedMode: boolean;
|
|
23
26
|
proxyUrl: string | null;
|
|
27
|
+
baseUrl: string;
|
|
28
|
+
sdkLayer: SdkLayerClient;
|
|
24
29
|
retry: RetryConfig;
|
|
25
30
|
timeoutMs: number;
|
|
26
31
|
onLifecycleEvent: LifecycleEventCallback | undefined;
|
|
27
32
|
failOpenEnabled: boolean;
|
|
28
33
|
circuit: CircuitBreaker;
|
|
34
|
+
application?: string | null;
|
|
35
|
+
tags?: string[];
|
|
36
|
+
customer?: string | null;
|
|
37
|
+
feature?: string | null;
|
|
29
38
|
}
|
|
30
|
-
export declare function install(client: unknown, transport: ObservationTransport, tenantId: string | null, environment: string | null, connectionId: string | null, hardening: AppliedModeHardeningOpts): void;
|
|
39
|
+
export declare function install(client: unknown, transport: ObservationTransport, tenantId: string | null, environment: string | null, connectionId: string | null, hardening: AppliedModeHardeningOpts, deployment?: string | null, promptTemplateId?: string | null, agentId?: string | null, workflowId?: string | null): void;
|
|
31
40
|
export declare const __test__: {
|
|
32
41
|
MARKER: string;
|
|
42
|
+
WITH_META_MARKER: string;
|
|
33
43
|
};
|
|
34
44
|
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAO5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAMtD,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,YAAY,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,WAAW,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,sBAAsB,GAAG,SAAS,CAAC;IACrD,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,cAAc,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAucD,wBAAgB,OAAO,CACrB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,oBAAoB,EAC/B,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,YAAY,EAAE,MAAM,GAAG,IAAI,EAC3B,SAAS,EAAE,wBAAwB,EACnC,UAAU,GAAE,MAAM,GAAG,IAAW,EAChC,gBAAgB,GAAE,MAAM,GAAG,IAAW,EACtC,OAAO,GAAE,MAAM,GAAG,IAAW,EAC7B,UAAU,GAAE,MAAM,GAAG,IAAW,GAC/B,IAAI,CAoKN;AAED,eAAO,MAAM,QAAQ;;;CAA+B,CAAC"}
|
package/dist/providers/openai.js
CHANGED
|
@@ -15,11 +15,15 @@
|
|
|
15
15
|
* call falls back to the customer's direct provider path.
|
|
16
16
|
*/
|
|
17
17
|
import { randomUUID } from "node:crypto";
|
|
18
|
-
import { proxyRequest } from "../proxy-client.js";
|
|
19
|
-
import {
|
|
18
|
+
import { proxyRequest, shouldFallBackToProvider } from "../proxy-client.js";
|
|
19
|
+
import { admitRequest } from "../admit-client.js";
|
|
20
|
+
import { TensorCostProxyError, TensorCostModelGovernanceDeniedError, } from "../errors.js";
|
|
20
21
|
import { emitEvent } from "../telemetry.js";
|
|
21
|
-
|
|
22
|
+
import { needsProxyUrl } from "../layer.js";
|
|
23
|
+
import { decisionMetadata } from "../decision.js";
|
|
24
|
+
import { SDK_VERSION } from "../version.js";
|
|
22
25
|
const MARKER = "__tensorcost_wrapped__";
|
|
26
|
+
const WITH_META_MARKER = "__tensorcost_with_meta__";
|
|
23
27
|
function nowIso() {
|
|
24
28
|
return new Date().toISOString();
|
|
25
29
|
}
|
|
@@ -61,6 +65,24 @@ function readClientApiKey(client) {
|
|
|
61
65
|
const raw = client["apiKey"];
|
|
62
66
|
return typeof raw === "string" && raw.length > 0 ? raw : null;
|
|
63
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Build the metadata bag to attach to an observation. Merges the wrap-time
|
|
70
|
+
* defaults (deployment + promptTemplateId) with any per-call overrides
|
|
71
|
+
* supplied via withMeta(). Returns undefined when nothing is configured so
|
|
72
|
+
* the field is absent from the envelope and the wire is not polluted by an
|
|
73
|
+
* empty object.
|
|
74
|
+
*/
|
|
75
|
+
function buildMetadata(deployment, promptTemplateId, perCallMeta) {
|
|
76
|
+
const base = {};
|
|
77
|
+
if (deployment !== null)
|
|
78
|
+
base.deployment = deployment;
|
|
79
|
+
if (promptTemplateId !== null)
|
|
80
|
+
base.prompt_template_id = promptTemplateId;
|
|
81
|
+
// Per-call meta wins over wrap-time defaults for overlapping keys.
|
|
82
|
+
if (perCallMeta)
|
|
83
|
+
Object.assign(base, perCallMeta);
|
|
84
|
+
return Object.keys(base).length > 0 ? base : undefined;
|
|
85
|
+
}
|
|
64
86
|
function wrapMethod(bound, opts) {
|
|
65
87
|
const wrapped = async function (...args) {
|
|
66
88
|
const requestAt = nowIso();
|
|
@@ -68,8 +90,65 @@ function wrapMethod(bound, opts) {
|
|
|
68
90
|
const model = (firstArg && typeof firstArg === "object" && firstArg.model) ||
|
|
69
91
|
"unknown";
|
|
70
92
|
const correlationId = randomUUID();
|
|
71
|
-
//
|
|
72
|
-
|
|
93
|
+
// Build metadata once per call. Per-call overrides beat wrap-time defaults.
|
|
94
|
+
const meta = buildMetadata(opts.deployment, opts.promptTemplateId, opts.perCallMeta);
|
|
95
|
+
const metaSpread = meta !== undefined ? { metadata: meta } : {};
|
|
96
|
+
// Per-agent-run attribution. Dedicated top-level fields (NOT the
|
|
97
|
+
// metadata bag — see Observation.agent_id doc in types.ts). Per-call
|
|
98
|
+
// withMeta() override beats the wrap-time default.
|
|
99
|
+
const resolvedAgentId = opts.perCallAgentId ?? opts.agentId ?? undefined;
|
|
100
|
+
const resolvedWorkflowId = opts.perCallWorkflowId ?? opts.workflowId ?? undefined;
|
|
101
|
+
const resolvedCustomer = opts.perCallCustomer ?? opts.hardening.customer ?? undefined;
|
|
102
|
+
const resolvedFeature = opts.perCallFeature ?? opts.hardening.feature ?? undefined;
|
|
103
|
+
const effectiveLayer = await opts.hardening.sdkLayer.effectiveLayer(opts.hardening.maxLayer);
|
|
104
|
+
let decisionMeta;
|
|
105
|
+
if (effectiveLayer === "govern" &&
|
|
106
|
+
opts.operation === "chat.completions") {
|
|
107
|
+
try {
|
|
108
|
+
const getToken = opts.getToken ?? (() => opts.transport.getToken());
|
|
109
|
+
const bearerToken = await getToken();
|
|
110
|
+
const admit = await admitRequest({
|
|
111
|
+
baseUrl: opts.hardening.baseUrl,
|
|
112
|
+
bearerToken,
|
|
113
|
+
maxLayer: effectiveLayer,
|
|
114
|
+
metadata: {
|
|
115
|
+
provider: "openai",
|
|
116
|
+
model: String(model),
|
|
117
|
+
operation: opts.operation,
|
|
118
|
+
correlation_id: correlationId,
|
|
119
|
+
environment: opts.environment,
|
|
120
|
+
connection_id: opts.connectionId,
|
|
121
|
+
agent_id: resolvedAgentId,
|
|
122
|
+
workflow_id: resolvedWorkflowId,
|
|
123
|
+
customer: resolvedCustomer,
|
|
124
|
+
feature: resolvedFeature,
|
|
125
|
+
application: opts.hardening.application ?? null,
|
|
126
|
+
tags: opts.hardening.tags ?? [],
|
|
127
|
+
},
|
|
128
|
+
transport: opts.transport,
|
|
129
|
+
failOpen: true,
|
|
130
|
+
});
|
|
131
|
+
if (!admit.allowed) {
|
|
132
|
+
throw new TensorCostModelGovernanceDeniedError("tensorcost: request refused at govern layer", "openai", String(model), null, { attempt: 1 });
|
|
133
|
+
}
|
|
134
|
+
decisionMeta = decisionMetadata(admit.decisionHeader);
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
if (err instanceof TensorCostModelGovernanceDeniedError)
|
|
138
|
+
throw err;
|
|
139
|
+
// Fail-open: token/admit unavailable — proceed to direct provider.
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const decisionSpread = decisionMeta !== undefined
|
|
143
|
+
? {
|
|
144
|
+
metadata: {
|
|
145
|
+
...(meta !== undefined ? meta : {}),
|
|
146
|
+
...decisionMeta,
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
: metaSpread;
|
|
150
|
+
// steer/route path: route through proxy-client with full hardening.
|
|
151
|
+
if (needsProxyUrl(effectiveLayer) &&
|
|
73
152
|
opts.hardening.proxyUrl &&
|
|
74
153
|
opts.operation === "chat.completions") {
|
|
75
154
|
const providerUrl = readClientBaseUrl(opts.clientRef);
|
|
@@ -86,14 +165,18 @@ function wrapMethod(bound, opts) {
|
|
|
86
165
|
};
|
|
87
166
|
// Snapshot circuit state before the call to detect fallback events.
|
|
88
167
|
const circuitWasOpen = opts.hardening.circuit.shouldBypass();
|
|
168
|
+
let shouldTryProxy = !circuitWasOpen;
|
|
169
|
+
if (circuitWasOpen) {
|
|
170
|
+
shouldTryProxy = opts.hardening.circuit.shouldProbe();
|
|
171
|
+
}
|
|
89
172
|
let proxyResult;
|
|
90
173
|
let proxyFailed = false;
|
|
91
174
|
let proxyFailureError = null;
|
|
92
|
-
if (
|
|
175
|
+
if (shouldTryProxy) {
|
|
93
176
|
try {
|
|
94
177
|
const getToken = opts.getToken ?? (() => opts.transport.getToken());
|
|
95
178
|
const bearerToken = await getToken();
|
|
96
|
-
|
|
179
|
+
const proxyResp = await proxyRequest({
|
|
97
180
|
proxyUrl: opts.hardening.proxyUrl,
|
|
98
181
|
bearerToken,
|
|
99
182
|
providerUrl,
|
|
@@ -104,13 +187,28 @@ function wrapMethod(bound, opts) {
|
|
|
104
187
|
operation: String(opts.operation),
|
|
105
188
|
correlationId,
|
|
106
189
|
environment: opts.environment,
|
|
190
|
+
application: opts.hardening.application ?? null,
|
|
191
|
+
tags: opts.hardening.tags ?? [],
|
|
192
|
+
agentId: resolvedAgentId,
|
|
193
|
+
workflowId: resolvedWorkflowId,
|
|
194
|
+
customer: resolvedCustomer,
|
|
195
|
+
feature: resolvedFeature,
|
|
107
196
|
retry: opts.hardening.retry,
|
|
108
197
|
timeoutMs: opts.hardening.timeoutMs,
|
|
109
198
|
onLifecycleEvent: opts.hardening.onLifecycleEvent,
|
|
110
199
|
circuit: opts.hardening.circuit,
|
|
200
|
+
maxLayer: effectiveLayer,
|
|
111
201
|
});
|
|
202
|
+
proxyResult = proxyResp.body;
|
|
203
|
+
decisionMeta = decisionMetadata(proxyResp.decisionHeader);
|
|
112
204
|
}
|
|
113
205
|
catch (proxyErr) {
|
|
206
|
+
// A run-budget refusal is a decision, not a failure. Rethrow it
|
|
207
|
+
// immediately so it never reaches the fail-open fallback below —
|
|
208
|
+
// otherwise the cap would be enforced by the proxy and then
|
|
209
|
+
// silently bypassed by us calling OpenAI directly.
|
|
210
|
+
if (!shouldFallBackToProvider(proxyErr))
|
|
211
|
+
throw proxyErr;
|
|
114
212
|
proxyFailed = true;
|
|
115
213
|
proxyFailureError = proxyErr;
|
|
116
214
|
}
|
|
@@ -139,9 +237,13 @@ function wrapMethod(bound, opts) {
|
|
|
139
237
|
status: "error",
|
|
140
238
|
error_message: `${tcErr.name}: ${tcErr.message}`,
|
|
141
239
|
correlation_id: correlationId,
|
|
142
|
-
tenant_id: opts.tenantId,
|
|
143
240
|
...(opts.environment !== null ? { environment: opts.environment } : {}),
|
|
144
241
|
...(opts.connectionId !== null ? { connection_id: opts.connectionId } : {}),
|
|
242
|
+
...(resolvedAgentId !== undefined ? { agent_id: resolvedAgentId } : {}),
|
|
243
|
+
...(resolvedWorkflowId !== undefined ? { workflow_id: resolvedWorkflowId } : {}),
|
|
244
|
+
...(resolvedCustomer !== undefined ? { customer: resolvedCustomer } : {}),
|
|
245
|
+
...(resolvedFeature !== undefined ? { feature: resolvedFeature } : {}),
|
|
246
|
+
...decisionSpread,
|
|
145
247
|
};
|
|
146
248
|
try {
|
|
147
249
|
opts.transport.post(obs);
|
|
@@ -175,9 +277,13 @@ function wrapMethod(bound, opts) {
|
|
|
175
277
|
status: "success",
|
|
176
278
|
error_message: null,
|
|
177
279
|
correlation_id: correlationId,
|
|
178
|
-
tenant_id: opts.tenantId,
|
|
179
280
|
...(opts.environment !== null ? { environment: opts.environment } : {}),
|
|
180
281
|
...(opts.connectionId !== null ? { connection_id: opts.connectionId } : {}),
|
|
282
|
+
...(resolvedAgentId !== undefined ? { agent_id: resolvedAgentId } : {}),
|
|
283
|
+
...(resolvedWorkflowId !== undefined ? { workflow_id: resolvedWorkflowId } : {}),
|
|
284
|
+
...(resolvedCustomer !== undefined ? { customer: resolvedCustomer } : {}),
|
|
285
|
+
...(resolvedFeature !== undefined ? { feature: resolvedFeature } : {}),
|
|
286
|
+
...decisionSpread,
|
|
181
287
|
};
|
|
182
288
|
try {
|
|
183
289
|
opts.transport.post(obs);
|
|
@@ -199,9 +305,13 @@ function wrapMethod(bound, opts) {
|
|
|
199
305
|
status: "error",
|
|
200
306
|
error_message: `${directErr.name}: ${directErr.message}`,
|
|
201
307
|
correlation_id: correlationId,
|
|
202
|
-
tenant_id: opts.tenantId,
|
|
203
308
|
...(opts.environment !== null ? { environment: opts.environment } : {}),
|
|
204
309
|
...(opts.connectionId !== null ? { connection_id: opts.connectionId } : {}),
|
|
310
|
+
...(resolvedAgentId !== undefined ? { agent_id: resolvedAgentId } : {}),
|
|
311
|
+
...(resolvedWorkflowId !== undefined ? { workflow_id: resolvedWorkflowId } : {}),
|
|
312
|
+
...(resolvedCustomer !== undefined ? { customer: resolvedCustomer } : {}),
|
|
313
|
+
...(resolvedFeature !== undefined ? { feature: resolvedFeature } : {}),
|
|
314
|
+
...decisionSpread,
|
|
205
315
|
};
|
|
206
316
|
try {
|
|
207
317
|
opts.transport.post(obs);
|
|
@@ -210,6 +320,14 @@ function wrapMethod(bound, opts) {
|
|
|
210
320
|
throw directErr;
|
|
211
321
|
}
|
|
212
322
|
}
|
|
323
|
+
const proxyDecisionSpread = decisionMeta !== undefined
|
|
324
|
+
? {
|
|
325
|
+
metadata: {
|
|
326
|
+
...(meta !== undefined ? meta : {}),
|
|
327
|
+
...decisionMeta,
|
|
328
|
+
},
|
|
329
|
+
}
|
|
330
|
+
: metaSpread;
|
|
213
331
|
// Proxy call succeeded.
|
|
214
332
|
const respBody = proxyResult;
|
|
215
333
|
const usageRaw = respBody?.usage;
|
|
@@ -228,9 +346,13 @@ function wrapMethod(bound, opts) {
|
|
|
228
346
|
status: "success",
|
|
229
347
|
error_message: null,
|
|
230
348
|
correlation_id: correlationId,
|
|
231
|
-
tenant_id: opts.tenantId,
|
|
232
349
|
...(opts.environment !== null ? { environment: opts.environment } : {}),
|
|
233
350
|
...(opts.connectionId !== null ? { connection_id: opts.connectionId } : {}),
|
|
351
|
+
...(resolvedAgentId !== undefined ? { agent_id: resolvedAgentId } : {}),
|
|
352
|
+
...(resolvedWorkflowId !== undefined ? { workflow_id: resolvedWorkflowId } : {}),
|
|
353
|
+
...(resolvedCustomer !== undefined ? { customer: resolvedCustomer } : {}),
|
|
354
|
+
...(resolvedFeature !== undefined ? { feature: resolvedFeature } : {}),
|
|
355
|
+
...proxyDecisionSpread,
|
|
234
356
|
};
|
|
235
357
|
try {
|
|
236
358
|
opts.transport.post(obs);
|
|
@@ -238,7 +360,7 @@ function wrapMethod(bound, opts) {
|
|
|
238
360
|
catch { /* belt-and-suspenders */ }
|
|
239
361
|
return proxyResult;
|
|
240
362
|
}
|
|
241
|
-
// Observe
|
|
363
|
+
// Observe / govern direct path (or legacy completions.create).
|
|
242
364
|
try {
|
|
243
365
|
const response = await bound.apply(this, args);
|
|
244
366
|
const { input, output } = extractUsage(response);
|
|
@@ -255,9 +377,13 @@ function wrapMethod(bound, opts) {
|
|
|
255
377
|
status: "success",
|
|
256
378
|
error_message: null,
|
|
257
379
|
correlation_id: correlationId,
|
|
258
|
-
tenant_id: opts.tenantId,
|
|
259
380
|
...(opts.environment !== null ? { environment: opts.environment } : {}),
|
|
260
381
|
...(opts.connectionId !== null ? { connection_id: opts.connectionId } : {}),
|
|
382
|
+
...(resolvedAgentId !== undefined ? { agent_id: resolvedAgentId } : {}),
|
|
383
|
+
...(resolvedWorkflowId !== undefined ? { workflow_id: resolvedWorkflowId } : {}),
|
|
384
|
+
...(resolvedCustomer !== undefined ? { customer: resolvedCustomer } : {}),
|
|
385
|
+
...(resolvedFeature !== undefined ? { feature: resolvedFeature } : {}),
|
|
386
|
+
...decisionSpread,
|
|
261
387
|
};
|
|
262
388
|
try {
|
|
263
389
|
opts.transport.post(obs);
|
|
@@ -279,9 +405,13 @@ function wrapMethod(bound, opts) {
|
|
|
279
405
|
status: "error",
|
|
280
406
|
error_message: `${err.name}: ${err.message}`,
|
|
281
407
|
correlation_id: correlationId,
|
|
282
|
-
tenant_id: opts.tenantId,
|
|
283
408
|
...(opts.environment !== null ? { environment: opts.environment } : {}),
|
|
284
409
|
...(opts.connectionId !== null ? { connection_id: opts.connectionId } : {}),
|
|
410
|
+
...(resolvedAgentId !== undefined ? { agent_id: resolvedAgentId } : {}),
|
|
411
|
+
...(resolvedWorkflowId !== undefined ? { workflow_id: resolvedWorkflowId } : {}),
|
|
412
|
+
...(resolvedCustomer !== undefined ? { customer: resolvedCustomer } : {}),
|
|
413
|
+
...(resolvedFeature !== undefined ? { feature: resolvedFeature } : {}),
|
|
414
|
+
...decisionSpread,
|
|
285
415
|
};
|
|
286
416
|
try {
|
|
287
417
|
opts.transport.post(obs);
|
|
@@ -293,42 +423,147 @@ function wrapMethod(bound, opts) {
|
|
|
293
423
|
Object.defineProperty(wrapped, MARKER, { value: true, enumerable: false });
|
|
294
424
|
return wrapped;
|
|
295
425
|
}
|
|
296
|
-
export function install(client, transport, tenantId, environment, connectionId, hardening) {
|
|
426
|
+
export function install(client, transport, tenantId, environment, connectionId, hardening, deployment = null, promptTemplateId = null, agentId = null, workflowId = null) {
|
|
297
427
|
if (!client || typeof client !== "object")
|
|
298
428
|
return;
|
|
299
429
|
const c = client;
|
|
300
430
|
const chat = c.chat;
|
|
301
431
|
const chatCompletions = chat && typeof chat === "object" ? chat.completions : undefined;
|
|
432
|
+
// Capture the original (pre-wrap) bound functions so withMeta() can build
|
|
433
|
+
// fresh wrappers from the real provider method — not from an already-wrapped
|
|
434
|
+
// one that would post a second observation.
|
|
435
|
+
let originalChatBound;
|
|
436
|
+
let originalLegacyBound;
|
|
302
437
|
if (chatCompletions &&
|
|
303
438
|
typeof chatCompletions.create === "function" &&
|
|
304
439
|
!chatCompletions.create[MARKER]) {
|
|
305
|
-
|
|
306
|
-
chatCompletions.create = wrapMethod(
|
|
440
|
+
originalChatBound = chatCompletions.create.bind(chatCompletions);
|
|
441
|
+
chatCompletions.create = wrapMethod(originalChatBound, {
|
|
307
442
|
operation: "chat.completions",
|
|
308
443
|
transport,
|
|
309
444
|
tenantId,
|
|
310
445
|
environment,
|
|
311
446
|
connectionId,
|
|
312
447
|
hardening,
|
|
448
|
+
deployment,
|
|
449
|
+
promptTemplateId,
|
|
450
|
+
agentId,
|
|
451
|
+
workflowId,
|
|
313
452
|
clientRef: client,
|
|
314
453
|
});
|
|
315
454
|
}
|
|
455
|
+
else if (chatCompletions && chatCompletions.create?.[MARKER]) {
|
|
456
|
+
// Already wrapped — store the underlying original for withMeta.
|
|
457
|
+
// We can't easily unwrap; withMeta on a double-wrapped client is a no-op
|
|
458
|
+
// for the double-post concern (the original is not recoverable without
|
|
459
|
+
// a stronger bookkeeping mechanism). This is an edge case (wrap called
|
|
460
|
+
// twice); the MARKER guard below prevents the second wrap anyway.
|
|
461
|
+
originalChatBound = chatCompletions.create;
|
|
462
|
+
}
|
|
316
463
|
const legacy = c.completions;
|
|
317
464
|
if (legacy &&
|
|
318
465
|
typeof legacy === "object" &&
|
|
319
466
|
typeof legacy.create === "function" &&
|
|
320
467
|
!legacy.create[MARKER]) {
|
|
321
|
-
|
|
322
|
-
legacy.create = wrapMethod(
|
|
468
|
+
originalLegacyBound = legacy.create.bind(legacy);
|
|
469
|
+
legacy.create = wrapMethod(originalLegacyBound, {
|
|
323
470
|
operation: "completions",
|
|
324
471
|
transport,
|
|
325
472
|
tenantId,
|
|
326
473
|
environment,
|
|
327
474
|
connectionId,
|
|
328
475
|
hardening: { ...hardening, appliedMode: false }, // legacy completions not proxied
|
|
476
|
+
deployment,
|
|
477
|
+
promptTemplateId,
|
|
478
|
+
agentId,
|
|
479
|
+
workflowId,
|
|
329
480
|
clientRef: client,
|
|
330
481
|
});
|
|
331
482
|
}
|
|
483
|
+
// withMeta() — returns a shallow proxy of the client with per-call metadata
|
|
484
|
+
// overrides. Builds fresh wrapMethod() calls against the ORIGINAL (pre-wrap)
|
|
485
|
+
// bound function so exactly one observation is emitted per call.
|
|
486
|
+
//
|
|
487
|
+
// Usage:
|
|
488
|
+
// (client as any).withMeta({ promptTemplateId: 'rerank-v3' })
|
|
489
|
+
// .chat.completions.create({ model: 'gpt-4o', messages })
|
|
490
|
+
if (typeof c[WITH_META_MARKER] === "undefined" && originalChatBound !== undefined) {
|
|
491
|
+
c[WITH_META_MARKER] = true; // mark so we don't add it twice
|
|
492
|
+
client["withMeta"] = function (callMeta) {
|
|
493
|
+
const perCallMeta = {};
|
|
494
|
+
if (callMeta.deployment !== undefined)
|
|
495
|
+
perCallMeta.deployment = callMeta.deployment;
|
|
496
|
+
if (callMeta.promptTemplateId !== undefined)
|
|
497
|
+
perCallMeta.prompt_template_id = callMeta.promptTemplateId;
|
|
498
|
+
// Any extra caller-supplied keys also land in the metadata bag.
|
|
499
|
+
// agentId / workflowId / customer / feature are extracted separately
|
|
500
|
+
// below (they are dedicated envelope fields, not metadata bag members)
|
|
501
|
+
// so they are excluded from this freeform pass-through.
|
|
502
|
+
for (const [k, v] of Object.entries(callMeta)) {
|
|
503
|
+
if (k !== "deployment" &&
|
|
504
|
+
k !== "promptTemplateId" &&
|
|
505
|
+
k !== "agentId" &&
|
|
506
|
+
k !== "workflowId" &&
|
|
507
|
+
k !== "customer" &&
|
|
508
|
+
k !== "feature") {
|
|
509
|
+
perCallMeta[k] = v;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
const perCallAgentId = callMeta.agentId;
|
|
513
|
+
const perCallWorkflowId = callMeta.workflowId;
|
|
514
|
+
const perCallCustomer = callMeta.customer;
|
|
515
|
+
const perCallFeature = callMeta.feature;
|
|
516
|
+
const proxyChat = originalChatBound !== undefined
|
|
517
|
+
? wrapMethod(originalChatBound, {
|
|
518
|
+
operation: "chat.completions",
|
|
519
|
+
transport,
|
|
520
|
+
tenantId,
|
|
521
|
+
environment,
|
|
522
|
+
connectionId,
|
|
523
|
+
hardening,
|
|
524
|
+
deployment,
|
|
525
|
+
promptTemplateId,
|
|
526
|
+
agentId,
|
|
527
|
+
workflowId,
|
|
528
|
+
perCallAgentId,
|
|
529
|
+
perCallWorkflowId,
|
|
530
|
+
perCallCustomer,
|
|
531
|
+
perCallFeature,
|
|
532
|
+
perCallMeta,
|
|
533
|
+
clientRef: client,
|
|
534
|
+
})
|
|
535
|
+
: undefined;
|
|
536
|
+
const proxyLegacy = originalLegacyBound !== undefined
|
|
537
|
+
? wrapMethod(originalLegacyBound, {
|
|
538
|
+
operation: "completions",
|
|
539
|
+
transport,
|
|
540
|
+
tenantId,
|
|
541
|
+
environment,
|
|
542
|
+
connectionId,
|
|
543
|
+
hardening: { ...hardening, appliedMode: false },
|
|
544
|
+
deployment,
|
|
545
|
+
promptTemplateId,
|
|
546
|
+
agentId,
|
|
547
|
+
workflowId,
|
|
548
|
+
perCallAgentId,
|
|
549
|
+
perCallWorkflowId,
|
|
550
|
+
perCallCustomer,
|
|
551
|
+
perCallFeature,
|
|
552
|
+
perCallMeta,
|
|
553
|
+
clientRef: client,
|
|
554
|
+
})
|
|
555
|
+
: undefined;
|
|
556
|
+
return {
|
|
557
|
+
...c,
|
|
558
|
+
chat: chatCompletions !== undefined && proxyChat !== undefined
|
|
559
|
+
? { ...chat, completions: { ...chatCompletions, create: proxyChat } }
|
|
560
|
+
: chat,
|
|
561
|
+
completions: legacy !== undefined && proxyLegacy !== undefined
|
|
562
|
+
? { ...legacy, create: proxyLegacy }
|
|
563
|
+
: legacy,
|
|
564
|
+
};
|
|
565
|
+
};
|
|
566
|
+
}
|
|
332
567
|
}
|
|
333
|
-
export const __test__ = { MARKER };
|
|
568
|
+
export const __test__ = { MARKER, WITH_META_MARKER };
|
|
334
569
|
//# sourceMappingURL=openai.js.map
|