@engini/sdk 0.16.0 → 0.17.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 +11 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +1 -0
- package/dist/http.d.ts +24 -4
- package/dist/http.js +44 -7
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.js +6 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -31,6 +31,17 @@ JWT auth is the fallback: `new Engini({ token: "<jwt>", companyToken: "<id>" })`
|
|
|
31
31
|
`ENGINI_API_TOKEN` / `ENGINI_COMPANY_TOKEN`. With an API key the company is bound to the key,
|
|
32
32
|
so no company token is needed. Point at another host with `new Engini({ …, baseUrl })`.
|
|
33
33
|
|
|
34
|
+
Every request carries a `User-Agent` identifying this SDK and its runtime (e.g.
|
|
35
|
+
`engini-sdk-ts/0.13.0 node/20.11.0 darwin-arm64`). If you're embedding the SDK inside your own
|
|
36
|
+
product, prepend your own token with `userAgentPrefix`:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
const client = new Engini({ apiKey: "eng_…", userAgentPrefix: "my-product/1.4.0" });
|
|
40
|
+
// -> "my-product/1.4.0 engini-sdk-ts/0.13.0 node/20.11.0 darwin-arm64"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`userAgentPrefix` only *prepends* a token — it can't override or remove the SDK's own identity.
|
|
44
|
+
|
|
34
45
|
## Use with an LLM
|
|
35
46
|
|
|
36
47
|
`Provider` adapters wrap canonical schemas into vendor tool definitions **client-side, with no
|
package/dist/client.d.ts
CHANGED
|
@@ -34,6 +34,13 @@ export interface EnginiOptions {
|
|
|
34
34
|
* host).
|
|
35
35
|
*/
|
|
36
36
|
verify?: Verify;
|
|
37
|
+
/**
|
|
38
|
+
* Product token to prepend to the SDK's own `User-Agent` (e.g. `engini-cli/0.13.0`).
|
|
39
|
+
* The SDK always emits its own identity plus runtime tokens; this only adds a
|
|
40
|
+
* prefix — it cannot override or remove them. Rejected if it contains a
|
|
41
|
+
* control character or exceeds 128 characters.
|
|
42
|
+
*/
|
|
43
|
+
userAgentPrefix?: string;
|
|
37
44
|
}
|
|
38
45
|
/** Engini SDK client — the single public entry point. */
|
|
39
46
|
export declare class Engini {
|
package/dist/client.js
CHANGED
|
@@ -60,6 +60,7 @@ export class Engini {
|
|
|
60
60
|
this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
|
|
61
61
|
this._transport = buildClient(this.baseUrl, auth, companyToken, {
|
|
62
62
|
verify: options.verify ?? true,
|
|
63
|
+
userAgentPrefix: options.userAgentPrefix,
|
|
63
64
|
});
|
|
64
65
|
this.provider = options.provider ?? new OpenAIProvider();
|
|
65
66
|
this.tools = new ToolsResource(this);
|
package/dist/http.d.ts
CHANGED
|
@@ -16,10 +16,29 @@ export type Verify = boolean | string | Dispatcher;
|
|
|
16
16
|
*/
|
|
17
17
|
export declare function tlsDispatcher(verify: Verify): Dispatcher | undefined;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* `
|
|
22
|
-
*
|
|
19
|
+
* Compose the SDK's `User-Agent`. The SDK always emits its own identity plus
|
|
20
|
+
* runtime tokens; a caller (the CLI, or any embedder) may only *prepend* its
|
|
21
|
+
* own product token via `prefix` — there is no way to override or remove the
|
|
22
|
+
* SDK's own token.
|
|
23
|
+
*
|
|
24
|
+
* `prefix` is validated rather than trusted: `Headers` would throw a bare
|
|
25
|
+
* `TypeError` on a control character, which would escape the SDK's typed-error
|
|
26
|
+
* contract, so it's rejected here with `EnginiClientError` instead.
|
|
27
|
+
*/
|
|
28
|
+
export declare function composeUserAgent(prefix?: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Build the generated transport with a `User-Agent`, auth, and optional
|
|
31
|
+
* account headers. `createEnginiClient` accepts only `{ baseUrl, token }`, so
|
|
32
|
+
* these are applied as default headers via `setConfig` (mirrors Python's
|
|
33
|
+
* `build_client`).
|
|
34
|
+
*
|
|
35
|
+
* Headers are assembled on a real `Headers` object — never via object spread.
|
|
36
|
+
* Spread is case-sensitive but `Headers.set` is case-insensitive/last-write-wins,
|
|
37
|
+
* so spreading would let a case-duplicate key (e.g. a stray `X-API-KEY`) survive
|
|
38
|
+
* into `mergeHeaders` (`@engini/client`'s `utils.gen.ts`) and beat the real
|
|
39
|
+
* credential. The composed `User-Agent` is set **last**, after auth's own
|
|
40
|
+
* headers, so a custom `Auth` implementation can't shadow the SDK's identity —
|
|
41
|
+
* matching `composeUserAgent`'s contract that it can't be overridden.
|
|
23
42
|
*
|
|
24
43
|
* `options.verify` controls TLS verification: when it resolves to a dispatcher
|
|
25
44
|
* (i.e. anything other than the default `true`), a custom `fetch` is installed
|
|
@@ -27,6 +46,7 @@ export declare function tlsDispatcher(verify: Verify): Dispatcher | undefined;
|
|
|
27
46
|
*/
|
|
28
47
|
export declare function buildClient(baseUrl: string, auth: Auth, companyToken?: string, options?: {
|
|
29
48
|
verify?: Verify;
|
|
49
|
+
userAgentPrefix?: string;
|
|
30
50
|
}): Transport;
|
|
31
51
|
/** A generated operation function (hey-api), invoked with `{ client, ... }`. */
|
|
32
52
|
type Operation<O, R> = (options: O & {
|
package/dist/http.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
import { readFileSync } from "node:fs";
|
|
8
8
|
import { Agent } from "undici";
|
|
9
9
|
import { createEnginiClient } from "@engini/client";
|
|
10
|
-
import { EnginiAPIError, EnginiAuthError, EnginiConflictError, EnginiNetworkError, EnginiNotFoundError, EnginiRateLimitError, EnginiServerError, EnginiValidationError, } from "./errors.js";
|
|
10
|
+
import { EnginiAPIError, EnginiAuthError, EnginiClientError, EnginiConflictError, EnginiNetworkError, EnginiNotFoundError, EnginiRateLimitError, EnginiServerError, EnginiValidationError, } from "./errors.js";
|
|
11
|
+
import { VERSION } from "./version.js";
|
|
11
12
|
/**
|
|
12
13
|
* Map a `verify` setting onto an undici `Dispatcher`, or `undefined` to keep the
|
|
13
14
|
* default verification. Node's `fetch` has no `verify_ssl` equivalent — TLS
|
|
@@ -31,11 +32,44 @@ const STATUS_TO_ERROR = {
|
|
|
31
32
|
422: EnginiValidationError,
|
|
32
33
|
429: EnginiRateLimitError,
|
|
33
34
|
};
|
|
35
|
+
const USER_AGENT_MAX_LEN = 128;
|
|
36
|
+
// CR/LF/NUL would let a prefix smuggle a second header line or split the value.
|
|
37
|
+
const USER_AGENT_CONTROL_CHAR_RE = /[\r\n\0]/;
|
|
34
38
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* `
|
|
38
|
-
*
|
|
39
|
+
* Compose the SDK's `User-Agent`. The SDK always emits its own identity plus
|
|
40
|
+
* runtime tokens; a caller (the CLI, or any embedder) may only *prepend* its
|
|
41
|
+
* own product token via `prefix` — there is no way to override or remove the
|
|
42
|
+
* SDK's own token.
|
|
43
|
+
*
|
|
44
|
+
* `prefix` is validated rather than trusted: `Headers` would throw a bare
|
|
45
|
+
* `TypeError` on a control character, which would escape the SDK's typed-error
|
|
46
|
+
* contract, so it's rejected here with `EnginiClientError` instead.
|
|
47
|
+
*/
|
|
48
|
+
export function composeUserAgent(prefix) {
|
|
49
|
+
if (prefix !== undefined) {
|
|
50
|
+
if (USER_AGENT_CONTROL_CHAR_RE.test(prefix)) {
|
|
51
|
+
throw new EnginiClientError("userAgentPrefix must not contain control characters.");
|
|
52
|
+
}
|
|
53
|
+
if (prefix.length > USER_AGENT_MAX_LEN) {
|
|
54
|
+
throw new EnginiClientError(`userAgentPrefix must be at most ${USER_AGENT_MAX_LEN} characters.`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const runtime = `engini-sdk-ts/${VERSION} node/${process.versions.node} ${process.platform}-${process.arch}`;
|
|
58
|
+
return prefix ? `${prefix} ${runtime}` : runtime;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Build the generated transport with a `User-Agent`, auth, and optional
|
|
62
|
+
* account headers. `createEnginiClient` accepts only `{ baseUrl, token }`, so
|
|
63
|
+
* these are applied as default headers via `setConfig` (mirrors Python's
|
|
64
|
+
* `build_client`).
|
|
65
|
+
*
|
|
66
|
+
* Headers are assembled on a real `Headers` object — never via object spread.
|
|
67
|
+
* Spread is case-sensitive but `Headers.set` is case-insensitive/last-write-wins,
|
|
68
|
+
* so spreading would let a case-duplicate key (e.g. a stray `X-API-KEY`) survive
|
|
69
|
+
* into `mergeHeaders` (`@engini/client`'s `utils.gen.ts`) and beat the real
|
|
70
|
+
* credential. The composed `User-Agent` is set **last**, after auth's own
|
|
71
|
+
* headers, so a custom `Auth` implementation can't shadow the SDK's identity —
|
|
72
|
+
* matching `composeUserAgent`'s contract that it can't be overridden.
|
|
39
73
|
*
|
|
40
74
|
* `options.verify` controls TLS verification: when it resolves to a dispatcher
|
|
41
75
|
* (i.e. anything other than the default `true`), a custom `fetch` is installed
|
|
@@ -43,9 +77,12 @@ const STATUS_TO_ERROR = {
|
|
|
43
77
|
*/
|
|
44
78
|
export function buildClient(baseUrl, auth, companyToken, options = {}) {
|
|
45
79
|
const client = createEnginiClient({ baseUrl });
|
|
46
|
-
const headers =
|
|
80
|
+
const headers = new Headers();
|
|
81
|
+
for (const [key, value] of Object.entries(auth.apply({})))
|
|
82
|
+
headers.set(key, value);
|
|
47
83
|
if (companyToken !== undefined)
|
|
48
|
-
headers
|
|
84
|
+
headers.set("companytoken", companyToken);
|
|
85
|
+
headers.set("user-agent", composeUserAgent(options.userAgentPrefix));
|
|
49
86
|
const dispatcher = tlsDispatcher(options.verify ?? true);
|
|
50
87
|
const fetchOverride = dispatcher === undefined
|
|
51
88
|
? undefined
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ export { Engini, DEFAULT_BASE_URL } from "./client.js";
|
|
|
2
2
|
export type { EnginiOptions } from "./client.js";
|
|
3
3
|
export { ApiKeyAuth, BearerAuth, ENV_API_KEY_VAR, ENV_TOKEN_VAR, ENV_COMPANY_TOKEN_VAR, } from "./auth.js";
|
|
4
4
|
export type { Auth } from "./auth.js";
|
|
5
|
+
export { composeUserAgent } from "./http.js";
|
|
5
6
|
export type { Verify } from "./http.js";
|
|
7
|
+
export { VERSION } from "./version.js";
|
|
6
8
|
export { EnginiError, EnginiNetworkError, EnginiAPIError, EnginiAuthError, EnginiNotFoundError, EnginiValidationError, EnginiRateLimitError, EnginiConflictError, EnginiServerError, EnginiClientError, EnginiConnectionError, EnginiToolsetError, EnginiToolsetNotFoundError, EnginiTimeoutError, EnginiToolExecutionError, } from "./errors.js";
|
|
7
9
|
export { ToolsResource, ConnectionsResource, ToolsetsResource, ApplicationsResource, refreshFailed, } from "./resources/index.js";
|
|
8
10
|
export type { ToolsGetOptions, ToolsExecuteOptions, ApplicationsListOptions } from "./resources/index.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { Engini, DEFAULT_BASE_URL } from "./client.js";
|
|
2
2
|
export { ApiKeyAuth, BearerAuth, ENV_API_KEY_VAR, ENV_TOKEN_VAR, ENV_COMPANY_TOKEN_VAR, } from "./auth.js";
|
|
3
|
+
export { composeUserAgent } from "./http.js";
|
|
4
|
+
export { VERSION } from "./version.js";
|
|
3
5
|
export { EnginiError, EnginiNetworkError, EnginiAPIError, EnginiAuthError, EnginiNotFoundError, EnginiValidationError, EnginiRateLimitError, EnginiConflictError, EnginiServerError, EnginiClientError, EnginiConnectionError, EnginiToolsetError, EnginiToolsetNotFoundError, EnginiTimeoutError, EnginiToolExecutionError, } from "./errors.js";
|
|
4
6
|
export { ToolsResource, ConnectionsResource, ToolsetsResource, ApplicationsResource, refreshFailed, } from "./resources/index.js";
|
|
5
7
|
export { Toolset } from "./toolset.js";
|
package/dist/version.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@engini/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Engini SDK — agent-first ergonomic layer over the Engini Public API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
"directory": "ts/packages/sdk"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
|
+
"generate-version": "node scripts/generate-version.mjs",
|
|
22
|
+
"pretypecheck": "npm run generate-version",
|
|
23
|
+
"prebuild": "npm run generate-version",
|
|
24
|
+
"pretest": "npm run generate-version",
|
|
21
25
|
"typecheck": "tsc --noEmit",
|
|
22
26
|
"build": "tsc",
|
|
23
27
|
"test": "vitest run"
|