@zhivex-ai/gateway 0.3.1-next.0 → 0.4.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/README.md +3 -36
- package/dist/compat.d.ts +2 -1
- package/dist/compat.d.ts.map +1 -1
- package/dist/compat.js +6 -0
- package/dist/compat.js.map +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +443 -155
- package/dist/index.js.map +1 -1
- package/dist/runtime-state.d.ts +1 -1
- package/dist/types.d.ts +49 -194
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -10
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,45 +8,12 @@ The gateway now supports:
|
|
|
8
8
|
- `streamText()`
|
|
9
9
|
- `generateObject()`
|
|
10
10
|
- `streamObject()`
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- a default router policy that scores targets using capabilities, latency, cost, and runtime health
|
|
15
|
-
- a default retry policy with retry classification, backoff, and target cooldowns
|
|
16
|
-
- an in-memory runtime store with per-target health, EWMA/p95 latency tracking, TTL pruning, and circuit states
|
|
17
|
-
- rich routing events through `onEvent`
|
|
11
|
+
- `runAgent()`
|
|
12
|
+
- `streamAgent()`
|
|
18
13
|
|
|
19
14
|
Tool loops continue to run on the selected target after routing, and streaming fallbacks are resolved before the first chunk is emitted.
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
import { createGateway } from "@zhivex-ai/gateway";
|
|
25
|
-
import { createOpenAI } from "@zhivex-ai/openai";
|
|
26
|
-
import { createOllama } from "@zhivex-ai/ollama";
|
|
27
|
-
|
|
28
|
-
const gateway = createGateway({
|
|
29
|
-
adapters: {
|
|
30
|
-
openai: createOpenAI({ apiKey: process.env.OPENAI_API_KEY }),
|
|
31
|
-
ollama: createOllama()
|
|
32
|
-
},
|
|
33
|
-
onEvent(event) {
|
|
34
|
-
console.log(event.type);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const result = await gateway.generate({
|
|
39
|
-
primary: { provider: "openai", modelId: "gpt-4o-mini" },
|
|
40
|
-
fallbacks: [{ provider: "ollama", modelId: "llama3.2" }],
|
|
41
|
-
messages: [{ role: "user", content: "Summarize routing." }],
|
|
42
|
-
maxCostPer1kTokens: 1,
|
|
43
|
-
costStrategy: "strict",
|
|
44
|
-
latencyBudgetMs: 2_000
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
console.log(result.providerUsed);
|
|
48
|
-
console.log(result.routeDecision.policy);
|
|
49
|
-
```
|
|
16
|
+
For agent routing, the gateway can also filter by `agentCapabilities`, such as provider support tier or approval-capable MCP support, before selecting the final target.
|
|
50
17
|
|
|
51
18
|
## Install
|
|
52
19
|
|
package/dist/compat.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ModelMessage } from "@zhivex-ai/core";
|
|
2
|
-
import type { GatewayMessage, GatewayProviderId } from "./types.js";
|
|
2
|
+
import type { GatewayMessage, GatewayModelTarget, GatewayProviderId, GatewayResponse } from "./types.js";
|
|
3
3
|
export declare const supportsVisionInput: (provider: GatewayProviderId, modelId: string) => boolean;
|
|
4
4
|
export declare const stripImagesForUnsupportedModel: (messages: GatewayMessage[], provider: GatewayProviderId, modelId: string) => GatewayMessage[];
|
|
5
5
|
export declare const gatewayMessagesToModelMessages: (messages: GatewayMessage[], systemPrompt?: string) => ModelMessage[];
|
|
6
|
+
export declare const createRouteDecision: (mode: GatewayResponse["routeDecision"]["mode"], intent: GatewayResponse["routeDecision"]["intent"], orderedTargets: GatewayModelTarget[]) => GatewayResponse["routeDecision"];
|
|
6
7
|
//# sourceMappingURL=compat.d.ts.map
|
package/dist/compat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compat.d.ts","sourceRoot":"","sources":["../src/compat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,KAAK,EACV,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"compat.d.ts","sourceRoot":"","sources":["../src/compat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,KAAK,EACV,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EAChB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,mBAAmB,GAAI,UAAU,iBAAiB,EAAE,SAAS,MAAM,KAAG,OAYlF,CAAC;AAEF,eAAO,MAAM,8BAA8B,GACzC,UAAU,cAAc,EAAE,EAC1B,UAAU,iBAAiB,EAC3B,SAAS,MAAM,KACd,cAAc,EAMhB,CAAC;AAEF,eAAO,MAAM,8BAA8B,GACzC,UAAU,cAAc,EAAE,EAC1B,eAAe,MAAM,KACpB,YAAY,EAyBd,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,MAAM,eAAe,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,EAC9C,QAAQ,eAAe,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,EAClD,gBAAgB,kBAAkB,EAAE,KACnC,eAAe,CAAC,eAAe,CAKhC,CAAC"}
|
package/dist/compat.js
CHANGED
|
@@ -37,4 +37,10 @@ export const gatewayMessagesToModelMessages = (messages, systemPrompt) => {
|
|
|
37
37
|
}
|
|
38
38
|
return mappedMessages;
|
|
39
39
|
};
|
|
40
|
+
export const createRouteDecision = (mode, intent, orderedTargets) => ({
|
|
41
|
+
mode,
|
|
42
|
+
intent,
|
|
43
|
+
orderedTargets,
|
|
44
|
+
reason: `Ordered by ${mode} mode with ${intent} intent.`
|
|
45
|
+
});
|
|
40
46
|
//# sourceMappingURL=compat.js.map
|
package/dist/compat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compat.js","source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,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;SAC9C,CAAC,CAAC;IACL,CAAC;IAED,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,cAAc,CAAC,IAAI,CAAC;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,KAAK,EAAE;gBACL,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE;gBACvC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;oBACzC,IAAI,EAAE,OAAgB;oBACtB,KAAK,EAAE,KAAK,CAAC,OAAO;oBACpB,SAAS,EAAE,KAAK,CAAC,QAAQ;iBAC1B,CAAC,CAAC,IAAI,EAAE,CAAC;aACX;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,IAA8C,EAC9C,MAAkD,EAClD,cAAoC,EACF,EAAE,CAAC,CAAC;IACtC,IAAI;IACJ,MAAM;IACN,cAAc;IACd,MAAM,EAAE,cAAc,IAAI,cAAc,MAAM,UAAU;CACzD,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { ZodTypeAny } from "zod";
|
|
2
|
-
import type
|
|
3
|
-
export * from "./policies.js";
|
|
4
|
-
export * from "./runtime-state.js";
|
|
5
|
-
export * from "./types.js";
|
|
2
|
+
import { type GatewayAgentRequest, type GatewayAgentResponse, type GatewayAgentStreamResult, type GatewayConfig, type GatewayGenerateObjectRequest, type GatewayObjectResponse, type GatewayRequest, type GatewayResponse, type GatewayStreamObjectResult, type GatewayStreamTextResult } from "./types.js";
|
|
6
3
|
export declare const createGateway: (config: GatewayConfig) => {
|
|
7
|
-
resolveModel(request: GatewayRequest): Promise<GatewayResolvedModel>;
|
|
8
4
|
generate(request: GatewayRequest): Promise<GatewayResponse>;
|
|
9
5
|
streamText(request: GatewayRequest): GatewayStreamTextResult;
|
|
10
6
|
generateObject<TSchema extends ZodTypeAny>(request: GatewayGenerateObjectRequest<TSchema>): Promise<GatewayObjectResponse<TSchema>>;
|
|
11
7
|
streamObject<TSchema extends ZodTypeAny>(request: GatewayGenerateObjectRequest<TSchema>): GatewayStreamObjectResult<TSchema>;
|
|
8
|
+
runAgent(request: GatewayAgentRequest): Promise<GatewayAgentResponse>;
|
|
9
|
+
streamAgent(request: GatewayAgentRequest): GatewayAgentStreamResult;
|
|
12
10
|
};
|
|
13
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAGtC,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EAClB,KAAK,4BAA4B,EAEjC,KAAK,qBAAqB,EAE1B,KAAK,cAAc,EACnB,KAAK,eAAe,EAEpB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAE7B,MAAM,YAAY,CAAC;AAiSpB,eAAO,MAAM,aAAa,GAAI,QAAQ,aAAa;sBA8RvB,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;wBAK7C,cAAc,GAAG,uBAAuB;mBAyCvC,OAAO,SAAS,UAAU,WACpC,4BAA4B,CAAC,OAAO,CAAC,GAC7C,OAAO,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;iBAuB7B,OAAO,SAAS,UAAU,WAAW,4BAA4B,CAAC,OAAO,CAAC,GAAG,yBAAyB,CAAC,OAAO,CAAC;sBA2DpG,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;yBA4BtD,mBAAmB,GAAG,wBAAwB;CAqEtE,CAAC"}
|