@alienplatform/ai-gateway 3.3.0-dev.0d4f932037814a854d56a7e4e82a8a34cc2e35cb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/binding.d.ts +29 -0
- package/dist/binding.d.ts.map +1 -0
- package/dist/client.d.ts +132 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/errors.d.ts +167 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/gateway.d.ts +18 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +748 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/loader.d.ts +45 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/native.d.ts +30 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +33 -0
- package/package.json +77 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@alienplatform/ai-gateway`: the thin TypeScript wrapper that starts the Alien
|
|
3
|
+
* AI gateway as a local subprocess.
|
|
4
|
+
*
|
|
5
|
+
* The gateway itself is a single Rust implementation (the `alien-ai-gateway`
|
|
6
|
+
* binary). This package spawns that binary once per process (or reuses the URL a
|
|
7
|
+
* container launcher already exported) and returns its loopback base URL. The app
|
|
8
|
+
* then points a plain OpenAI-compatible client at that URL, and every request and
|
|
9
|
+
* SSE stream flows over the loopback HTTP socket straight into the Rust gateway;
|
|
10
|
+
* no gateway logic is reimplemented here.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { getAiConnection } from "@alienplatform/ai-gateway"
|
|
15
|
+
* import { createOpenAICompatible } from "@ai-sdk/openai-compatible"
|
|
16
|
+
* const provider = createOpenAICompatible({ name: "alien", ...(await getAiConnection("assistant")) })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
/** Start the AI gateway subprocess (idempotent) and return its running handle. */
|
|
20
|
+
export declare const startAiGateway: () => Promise<import("./loader.js").RawAiGatewayHandle>;
|
|
21
|
+
/** An OpenAI-compatible client for the named AI binding (External BYO-key or ambient). */
|
|
22
|
+
export declare const ai: (name: string) => import("./client.js").Ai;
|
|
23
|
+
/** Resolve an AI binding to `{ baseURL, apiKey? }`, starting the gateway for ambient bindings. */
|
|
24
|
+
export declare const getAiConnection: (name: string) => Promise<import("./client.js").AiConnection>;
|
|
25
|
+
export { Ai } from "./client.js";
|
|
26
|
+
export type { AiConnection, AiModel, ChatCompletionCreateParams, ResponseCreateParams, } from "./client.js";
|
|
27
|
+
export { aiBindingEnvVarName, isExternalAiBinding, parseAiBinding } from "./binding.js";
|
|
28
|
+
export type { AiBinding, AmbientAiBinding, ExternalAiBinding } from "./binding.js";
|
|
29
|
+
export { AiTransportError, AiUpstreamError, BindingNotFoundError, InvalidBindingConfigError, } from "./errors.js";
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AASH,kFAAkF;AAClF,eAAO,MAAM,cAAc,yDAAyB,CAAA;AACpD,0FAA0F;AAC1F,eAAO,MAAM,EAAE,4CAAY,CAAA;AAC3B,kGAAkG;AAClG,eAAO,MAAM,eAAe,+DAAyB,CAAA;AAErD,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAChC,YAAY,EACV,YAAY,EACZ,OAAO,EACP,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AACvF,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAClF,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,aAAa,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { a as createAiClient, c as BindingNotFoundError, d as isExternalAiBinding, f as parseAiBinding, i as Ai, l as InvalidBindingConfigError, o as AiTransportError, r as resolveGatewayBinary, s as AiUpstreamError, t as createGateway, u as aiBindingEnvVarName } from "./gateway.js";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* `@alienplatform/ai-gateway`: the thin TypeScript wrapper that starts the Alien
|
|
5
|
+
* AI gateway as a local subprocess.
|
|
6
|
+
*
|
|
7
|
+
* The gateway itself is a single Rust implementation (the `alien-ai-gateway`
|
|
8
|
+
* binary). This package spawns that binary once per process (or reuses the URL a
|
|
9
|
+
* container launcher already exported) and returns its loopback base URL. The app
|
|
10
|
+
* then points a plain OpenAI-compatible client at that URL, and every request and
|
|
11
|
+
* SSE stream flows over the loopback HTTP socket straight into the Rust gateway;
|
|
12
|
+
* no gateway logic is reimplemented here.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { getAiConnection } from "@alienplatform/ai-gateway"
|
|
17
|
+
* import { createOpenAICompatible } from "@ai-sdk/openai-compatible"
|
|
18
|
+
* const provider = createOpenAICompatible({ name: "alien", ...(await getAiConnection("assistant")) })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const gateway = createGateway(resolveGatewayBinary);
|
|
22
|
+
const client = createAiClient(gateway);
|
|
23
|
+
/** Start the AI gateway subprocess (idempotent) and return its running handle. */
|
|
24
|
+
const startAiGateway = gateway.startAiGateway;
|
|
25
|
+
/** An OpenAI-compatible client for the named AI binding (External BYO-key or ambient). */
|
|
26
|
+
const ai = client.ai;
|
|
27
|
+
/** Resolve an AI binding to `{ baseURL, apiKey? }`, starting the gateway for ambient bindings. */
|
|
28
|
+
const getAiConnection = client.getAiConnection;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { Ai, AiTransportError, AiUpstreamError, BindingNotFoundError, InvalidBindingConfigError, ai, aiBindingEnvVarName, getAiConnection, isExternalAiBinding, parseAiBinding, startAiGateway };
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locate (and, for a compiled Worker, extract) the `alien-ai-gateway` executable
|
|
3
|
+
* that the gateway wrapper spawns.
|
|
4
|
+
*
|
|
5
|
+
* Resolution order (deferred to first spawn, so importing the package does no I/O):
|
|
6
|
+
*
|
|
7
|
+
* 1. An embedded binary registered by the `./native` entry. A `bun build
|
|
8
|
+
* --compile` Worker embeds the executable and hands us its (virtual) path;
|
|
9
|
+
* we copy it to a real, executable temp file once.
|
|
10
|
+
* 2. `ALIEN_AI_GATEWAY_BINARY_PATH`: an explicit path (dev/test escape hatch;
|
|
11
|
+
* never set in published installs).
|
|
12
|
+
* 3. `./alien-ai-gateway` in the working directory: the versioned Worker base
|
|
13
|
+
* stages it there for bundled Workers, which have no node_modules.
|
|
14
|
+
* 4. The per-platform prebuild package `@alienplatform/ai-gateway-<triple>`,
|
|
15
|
+
* which ships the executable (installed via `optionalDependencies`).
|
|
16
|
+
* 5. Dev fallback: the locally-built binary under `target/{release,debug}`,
|
|
17
|
+
* found by walking up from this module.
|
|
18
|
+
*/
|
|
19
|
+
/** A running gateway handle: its loopback base URL. */
|
|
20
|
+
export interface RawAiGatewayHandle {
|
|
21
|
+
readonly url: string;
|
|
22
|
+
}
|
|
23
|
+
export type LinuxLibc = "gnu" | "musl";
|
|
24
|
+
/** Detect glibc vs musl, the same way napi-rs's generated loader does. */
|
|
25
|
+
export declare function detectLinuxLibc(): LinuxLibc;
|
|
26
|
+
/**
|
|
27
|
+
* Map `process.platform`/`arch` to the prebuild triple. The binary is built for
|
|
28
|
+
* musl as well as glibc, so Alpine/musl images resolve a prebuild rather than
|
|
29
|
+
* being rejected for their libc.
|
|
30
|
+
*/
|
|
31
|
+
export declare function platformTriple(platform?: NodeJS.Platform, arch?: NodeJS.Architecture, libc?: LinuxLibc): string;
|
|
32
|
+
/** Walk up from `startDir` to find the locally-built binary, or `undefined`. */
|
|
33
|
+
export declare function findLocalBinary(startDir?: string): string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Register the bun-embedded binary path, so plain `@alienplatform/ai-gateway`
|
|
36
|
+
* imports (which resolve through {@link resolveGatewayBinary}) find it inside a
|
|
37
|
+
* `bun build --compile` binary, where the filesystem/prebuild resolution below
|
|
38
|
+
* cannot. In a normal install this is never called. The `/native` entry calls it.
|
|
39
|
+
*/
|
|
40
|
+
export declare function registerEmbeddedBinary(path: string): void;
|
|
41
|
+
/** Resolve (and memoize) a runnable path to the launcher binary, or throw. */
|
|
42
|
+
export declare function resolveGatewayBinary(): Promise<string>;
|
|
43
|
+
/** Test-only: reset the memoized resolution. */
|
|
44
|
+
export declare function resetGatewayBinaryCacheForTests(): void;
|
|
45
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAgBH,uDAAuD;AACvD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,CAAA;AAEtC,0EAA0E;AAC1E,wBAAgB,eAAe,IAAI,SAAS,CAS3C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,GAAE,MAAM,CAAC,QAA2B,EAC5C,IAAI,GAAE,MAAM,CAAC,YAA2B,EACxC,IAAI,GAAE,SAA4D,GACjE,MAAM,CAQR;AAED,gFAAgF;AAChF,wBAAgB,eAAe,CAC7B,QAAQ,GAAE,MAAgD,GACzD,MAAM,GAAG,SAAS,CAWpB;AAKD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEzD;AAED,8EAA8E;AAC9E,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CA8C5D;AAsED,gDAAgD;AAChD,wBAAgB,+BAA+B,IAAI,IAAI,CAGtD"}
|
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@alienplatform/ai-gateway/native` — static-embed entry for `bun build --compile`.
|
|
3
|
+
*
|
|
4
|
+
* Imports the `alien-ai-gateway` executable through a literal `with { type: "file" }`
|
|
5
|
+
* specifier so bun embeds it into the single-file binary, and registers its path so
|
|
6
|
+
* the default loader extracts and spawns it. Unlike the default entry it does not
|
|
7
|
+
* probe the filesystem: the binary must already be staged next to the built
|
|
8
|
+
* `native.js` (the build owns that copy step). The specifier is kept external at
|
|
9
|
+
* build time (tsdown.config.ts) so the literal survives into `dist/native.js`.
|
|
10
|
+
* `bun build --compile` needs `--format=cjs`.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Register the bun-embedded gateway binary with the default loader, so plain
|
|
14
|
+
* `@alienplatform/ai-gateway` imports — including the SDK's re-exported `ai()`,
|
|
15
|
+
* which resolves through {@link resolveGatewayBinary}, to spawn it inside a compiled
|
|
16
|
+
* binary. `alien build` emits an explicit call to this from the compiled entry
|
|
17
|
+
* (via `@alienplatform/sdk/native`); it's an explicit exported call, not a bare
|
|
18
|
+
* side-effect import, so it survives this package's `sideEffects: false`
|
|
19
|
+
* tree-shaking.
|
|
20
|
+
*/
|
|
21
|
+
export declare function installEmbeddedGateway(): void;
|
|
22
|
+
export declare const startAiGateway: () => Promise<import("./loader.js").RawAiGatewayHandle>;
|
|
23
|
+
export declare const ai: (name: string) => import("./client.js").Ai;
|
|
24
|
+
export declare const getAiConnection: (name: string) => Promise<import("./client.js").AiConnection>;
|
|
25
|
+
export { Ai } from "./client.js";
|
|
26
|
+
export type { AiConnection, AiModel, ChatCompletionCreateParams, ResponseCreateParams, } from "./client.js";
|
|
27
|
+
export { aiBindingEnvVarName, isExternalAiBinding, parseAiBinding } from "./binding.js";
|
|
28
|
+
export type { AiBinding, AmbientAiBinding, ExternalAiBinding } from "./binding.js";
|
|
29
|
+
export { AiTransportError, AiUpstreamError, BindingNotFoundError, InvalidBindingConfigError, } from "./errors.js";
|
|
30
|
+
//# sourceMappingURL=native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C;AAKD,eAAO,MAAM,cAAc,yDAAyB,CAAA;AACpD,eAAO,MAAM,EAAE,4CAAY,CAAA;AAC3B,eAAO,MAAM,eAAe,+DAAyB,CAAA;AAErD,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAChC,YAAY,EACV,YAAY,EACZ,OAAO,EACP,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AACvF,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAClF,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,aAAa,CAAA"}
|
package/dist/native.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { a as createAiClient, c as BindingNotFoundError, d as isExternalAiBinding, f as parseAiBinding, i as Ai, l as InvalidBindingConfigError, n as registerEmbeddedBinary, o as AiTransportError, r as resolveGatewayBinary, s as AiUpstreamError, t as createGateway, u as aiBindingEnvVarName } from "./gateway.js";
|
|
2
|
+
import embeddedBinaryPath from "./alien-ai-gateway.bin" with { type: "file" };
|
|
3
|
+
//#region src/native.ts
|
|
4
|
+
/**
|
|
5
|
+
* `@alienplatform/ai-gateway/native` — static-embed entry for `bun build --compile`.
|
|
6
|
+
*
|
|
7
|
+
* Imports the `alien-ai-gateway` executable through a literal `with { type: "file" }`
|
|
8
|
+
* specifier so bun embeds it into the single-file binary, and registers its path so
|
|
9
|
+
* the default loader extracts and spawns it. Unlike the default entry it does not
|
|
10
|
+
* probe the filesystem: the binary must already be staged next to the built
|
|
11
|
+
* `native.js` (the build owns that copy step). The specifier is kept external at
|
|
12
|
+
* build time (tsdown.config.ts) so the literal survives into `dist/native.js`.
|
|
13
|
+
* `bun build --compile` needs `--format=cjs`.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Register the bun-embedded gateway binary with the default loader, so plain
|
|
17
|
+
* `@alienplatform/ai-gateway` imports — including the SDK's re-exported `ai()`,
|
|
18
|
+
* which resolves through {@link resolveGatewayBinary}, to spawn it inside a compiled
|
|
19
|
+
* binary. `alien build` emits an explicit call to this from the compiled entry
|
|
20
|
+
* (via `@alienplatform/sdk/native`); it's an explicit exported call, not a bare
|
|
21
|
+
* side-effect import, so it survives this package's `sideEffects: false`
|
|
22
|
+
* tree-shaking.
|
|
23
|
+
*/
|
|
24
|
+
function installEmbeddedGateway() {
|
|
25
|
+
registerEmbeddedBinary(embeddedBinaryPath);
|
|
26
|
+
}
|
|
27
|
+
const gateway = createGateway(resolveGatewayBinary);
|
|
28
|
+
const client = createAiClient(gateway);
|
|
29
|
+
const startAiGateway = gateway.startAiGateway;
|
|
30
|
+
const ai = client.ai;
|
|
31
|
+
const getAiConnection = client.getAiConnection;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { Ai, AiTransportError, AiUpstreamError, BindingNotFoundError, InvalidBindingConfigError, ai, aiBindingEnvVarName, getAiConnection, installEmbeddedGateway, isExternalAiBinding, parseAiBinding, startAiGateway };
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alienplatform/ai-gateway",
|
|
3
|
+
"version": "3.3.0-dev.0d4f932037814a854d56a7e4e82a8a34cc2e35cb",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./native": {
|
|
13
|
+
"types": "./dist/native.d.ts",
|
|
14
|
+
"import": "./dist/native.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18",
|
|
22
|
+
"bun": ">=1.0.23"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsdown && tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"test:ts": "tsc --noEmit",
|
|
28
|
+
"format-and-lint": "biome check .",
|
|
29
|
+
"format-and-lint:fix": "biome check . --write"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"alien",
|
|
33
|
+
"ai",
|
|
34
|
+
"gateway"
|
|
35
|
+
],
|
|
36
|
+
"author": "Alien Software, Inc. <hi@alien.dev>",
|
|
37
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
38
|
+
"description": "Thin TypeScript wrapper that spawns the Alien AI gateway (a Rust binary) and points an OpenAI-compatible client at it",
|
|
39
|
+
"homepage": "https://alien.dev",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/alienplatform/alien.git",
|
|
43
|
+
"directory": "packages/ai-gateway"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@alienplatform/typescript-config": "workspace:^",
|
|
50
|
+
"@biomejs/biome": "^1.9.4",
|
|
51
|
+
"@types/node": "^24.0.15",
|
|
52
|
+
"openai": "^4",
|
|
53
|
+
"tsdown": "^0.13.0",
|
|
54
|
+
"typescript": "^5.8.3",
|
|
55
|
+
"vitest": "^3.1.4"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@alienplatform/core": "3.3.0-dev.0d4f932037814a854d56a7e4e82a8a34cc2e35cb",
|
|
59
|
+
"zod": "4.3.2"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"openai": "^4"
|
|
63
|
+
},
|
|
64
|
+
"peerDependenciesMeta": {
|
|
65
|
+
"openai": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"optionalDependencies": {
|
|
70
|
+
"@alienplatform/ai-gateway-darwin-arm64": "3.3.0-dev.0d4f932037814a854d56a7e4e82a8a34cc2e35cb",
|
|
71
|
+
"@alienplatform/ai-gateway-darwin-x64": "3.3.0-dev.0d4f932037814a854d56a7e4e82a8a34cc2e35cb",
|
|
72
|
+
"@alienplatform/ai-gateway-linux-x64-gnu": "3.3.0-dev.0d4f932037814a854d56a7e4e82a8a34cc2e35cb",
|
|
73
|
+
"@alienplatform/ai-gateway-linux-x64-musl": "3.3.0-dev.0d4f932037814a854d56a7e4e82a8a34cc2e35cb",
|
|
74
|
+
"@alienplatform/ai-gateway-linux-arm64-gnu": "3.3.0-dev.0d4f932037814a854d56a7e4e82a8a34cc2e35cb",
|
|
75
|
+
"@alienplatform/ai-gateway-linux-arm64-musl": "3.3.0-dev.0d4f932037814a854d56a7e4e82a8a34cc2e35cb"
|
|
76
|
+
}
|
|
77
|
+
}
|