@engini/sdk 0.0.0 → 0.5.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/LICENSE +21 -0
- package/README.md +7 -2
- package/dist/auth.d.ts +30 -0
- package/dist/auth.js +33 -0
- package/dist/client.d.ts +62 -0
- package/dist/client.js +77 -0
- package/dist/errors.d.ts +50 -0
- package/dist/errors.js +55 -0
- package/dist/http.d.ts +41 -0
- package/dist/http.js +101 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +7 -0
- package/dist/pagination.d.ts +17 -0
- package/dist/pagination.js +25 -0
- package/dist/providers/anthropic.d.ts +15 -0
- package/dist/providers/anthropic.js +35 -0
- package/dist/providers/base.d.ts +27 -0
- package/dist/providers/base.js +6 -0
- package/dist/providers/openai.d.ts +20 -0
- package/dist/providers/openai.js +37 -0
- package/dist/resources/applications.d.ts +25 -0
- package/dist/resources/applications.js +30 -0
- package/dist/resources/auth.d.ts +12 -0
- package/dist/resources/auth.js +12 -0
- package/dist/resources/connections.d.ts +17 -0
- package/dist/resources/connections.js +60 -0
- package/dist/resources/index.d.ts +6 -0
- package/dist/resources/index.js +4 -0
- package/dist/resources/tools.d.ts +34 -0
- package/dist/resources/tools.js +161 -0
- package/dist/resources/toolsets.d.ts +19 -0
- package/dist/resources/toolsets.js +41 -0
- package/dist/toolset.d.ts +80 -0
- package/dist/toolset.js +128 -0
- package/dist/types.d.ts +27 -0
- package/dist/types.js +1 -0
- package/package.json +29 -8
- package/index.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Engini AI Ltd.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
# @engini/sdk
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Agent-first TypeScript SDK for the [Engini](https://engini.io) Public API.
|
|
4
|
+
|
|
5
|
+
> **Pre-release scaffold.** The public surface is defined; behavior ships in
|
|
6
|
+
> Phase 3 (after the `@engini/client` autogen package lands). Install betas
|
|
7
|
+
> with `npm install @engini/sdk@beta`.
|
|
8
|
+
|
|
9
|
+
Source: <https://github.com/engini/engini-sdk>
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable authentication. Primary path is the opaque api-key (`x-api-key`);
|
|
3
|
+
* Bearer / PAT is the fallback. Mirrors Python `engini.auth`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const ENV_TOKEN_VAR = "ENGINI_API_TOKEN";
|
|
6
|
+
export declare const ENV_COMPANY_TOKEN_VAR = "ENGINI_COMPANY_TOKEN";
|
|
7
|
+
export declare const ENV_API_KEY_VAR = "ENGINI_API_KEY";
|
|
8
|
+
/** Strategy that injects credentials into outgoing request headers. */
|
|
9
|
+
export interface Auth {
|
|
10
|
+
/** Return a copy of `headers` with credentials applied. Must not mutate. */
|
|
11
|
+
apply(headers: Record<string, string>): Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
/** `Authorization: Bearer <token>` — Engini PATs and JWTs. */
|
|
14
|
+
export declare class BearerAuth implements Auth {
|
|
15
|
+
readonly token: string;
|
|
16
|
+
constructor(token: string);
|
|
17
|
+
apply(headers: Record<string, string>): Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Opaque Engini key (`eng_…`) carried in the `x-api-key` header. The key
|
|
21
|
+
* resolves server-side to owner identity *and* the bound company, so no
|
|
22
|
+
* `companytoken` selector travels with the request. This is the primary v1 auth
|
|
23
|
+
* path; `BearerAuth` (two-token JWT) is the fallback. Header is `x-api-key`
|
|
24
|
+
* (never `x-api-token`). Mirrors Python `engini.auth.ApiKeyAuth`.
|
|
25
|
+
*/
|
|
26
|
+
export declare class ApiKeyAuth implements Auth {
|
|
27
|
+
readonly key: string;
|
|
28
|
+
constructor(key: string);
|
|
29
|
+
apply(headers: Record<string, string>): Record<string, string>;
|
|
30
|
+
}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable authentication. Primary path is the opaque api-key (`x-api-key`);
|
|
3
|
+
* Bearer / PAT is the fallback. Mirrors Python `engini.auth`.
|
|
4
|
+
*/
|
|
5
|
+
export const ENV_TOKEN_VAR = "ENGINI_API_TOKEN";
|
|
6
|
+
export const ENV_COMPANY_TOKEN_VAR = "ENGINI_COMPANY_TOKEN";
|
|
7
|
+
export const ENV_API_KEY_VAR = "ENGINI_API_KEY";
|
|
8
|
+
/** `Authorization: Bearer <token>` — Engini PATs and JWTs. */
|
|
9
|
+
export class BearerAuth {
|
|
10
|
+
token;
|
|
11
|
+
constructor(token) {
|
|
12
|
+
this.token = token;
|
|
13
|
+
}
|
|
14
|
+
apply(headers) {
|
|
15
|
+
return { ...headers, Authorization: `Bearer ${this.token}` };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Opaque Engini key (`eng_…`) carried in the `x-api-key` header. The key
|
|
20
|
+
* resolves server-side to owner identity *and* the bound company, so no
|
|
21
|
+
* `companytoken` selector travels with the request. This is the primary v1 auth
|
|
22
|
+
* path; `BearerAuth` (two-token JWT) is the fallback. Header is `x-api-key`
|
|
23
|
+
* (never `x-api-token`). Mirrors Python `engini.auth.ApiKeyAuth`.
|
|
24
|
+
*/
|
|
25
|
+
export class ApiKeyAuth {
|
|
26
|
+
key;
|
|
27
|
+
constructor(key) {
|
|
28
|
+
this.key = key;
|
|
29
|
+
}
|
|
30
|
+
apply(headers) {
|
|
31
|
+
return { ...headers, "x-api-key": this.key };
|
|
32
|
+
}
|
|
33
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type Auth } from "./auth.js";
|
|
2
|
+
import { type Transport, type Verify } from "./http.js";
|
|
3
|
+
import type { Provider } from "./providers/base.js";
|
|
4
|
+
import { ToolsResource } from "./resources/tools.js";
|
|
5
|
+
import { ConnectionsResource } from "./resources/connections.js";
|
|
6
|
+
import { ToolsetsResource } from "./resources/toolsets.js";
|
|
7
|
+
import { ApplicationsResource } from "./resources/applications.js";
|
|
8
|
+
import { AuthResource } from "./resources/auth.js";
|
|
9
|
+
import { Toolset, type ConnectionBinding } from "./toolset.js";
|
|
10
|
+
import type { ToolSchema } from "./types.js";
|
|
11
|
+
export declare const DEFAULT_BASE_URL = "https://api.engini.io";
|
|
12
|
+
export interface EnginiOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Opaque Engini key (`eng_…`); sugar for `auth: new ApiKeyAuth(key)`. The
|
|
15
|
+
* primary auth path — the company is bound to the key server-side. Falls back
|
|
16
|
+
* to `ENGINI_API_KEY` (which beats `ENGINI_API_TOKEN`). Mutually exclusive
|
|
17
|
+
* with `token`/`auth`.
|
|
18
|
+
*/
|
|
19
|
+
apiKey?: string;
|
|
20
|
+
/** Engini PAT; sugar for `auth: new BearerAuth(token)`. Falls back to `ENGINI_API_TOKEN`. */
|
|
21
|
+
token?: string;
|
|
22
|
+
/** Pluggable auth strategy; mutually exclusive with `token`/`apiKey`. */
|
|
23
|
+
auth?: Auth;
|
|
24
|
+
/** Optional account selector sent as the `companytoken` header. Falls back to `ENGINI_COMPANY_TOKEN`. Not used with api-key auth. */
|
|
25
|
+
companyToken?: string;
|
|
26
|
+
/** LLM provider adapter. Defaults to `new OpenAIProvider()`. */
|
|
27
|
+
provider?: Provider;
|
|
28
|
+
/** API root; defaults to `DEFAULT_BASE_URL`. Override for staging. */
|
|
29
|
+
baseUrl?: string;
|
|
30
|
+
/**
|
|
31
|
+
* TLS verification (Node). `true` (default) verifies against the system store;
|
|
32
|
+
* a CA-bundle path trusts a private CA; an undici `Dispatcher` is used as-is;
|
|
33
|
+
* `false` disables verification (dev only — e.g. a self-signed staging/local
|
|
34
|
+
* host).
|
|
35
|
+
*/
|
|
36
|
+
verify?: Verify;
|
|
37
|
+
}
|
|
38
|
+
/** Engini SDK client — the single public entry point. */
|
|
39
|
+
export declare class Engini {
|
|
40
|
+
readonly tools: ToolsResource;
|
|
41
|
+
readonly connections: ConnectionsResource;
|
|
42
|
+
readonly toolsets: ToolsetsResource;
|
|
43
|
+
readonly applications: ApplicationsResource;
|
|
44
|
+
readonly auth: AuthResource;
|
|
45
|
+
readonly provider: Provider;
|
|
46
|
+
readonly baseUrl: string;
|
|
47
|
+
/** @internal transport + per-tool schema cache, consumed by resources. */
|
|
48
|
+
readonly _transport: Transport;
|
|
49
|
+
readonly _toolCache: Map<string, ToolSchema>;
|
|
50
|
+
constructor(options?: EnginiOptions);
|
|
51
|
+
/**
|
|
52
|
+
* Build a local toolset, or load a server one by id. Local build does no I/O
|
|
53
|
+
* until `.tools()`, `.execute()`, `.handleToolCalls()` or `.save()` is called.
|
|
54
|
+
*/
|
|
55
|
+
toolset(params: {
|
|
56
|
+
toolsetId: string;
|
|
57
|
+
}): Promise<Toolset>;
|
|
58
|
+
toolset(params?: {
|
|
59
|
+
connections?: Record<string, ConnectionBinding>;
|
|
60
|
+
tools?: string[];
|
|
61
|
+
}): Toolset;
|
|
62
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ApiKeyAuth, BearerAuth, ENV_API_KEY_VAR, ENV_TOKEN_VAR, ENV_COMPANY_TOKEN_VAR, } from "./auth.js";
|
|
2
|
+
import { buildClient } from "./http.js";
|
|
3
|
+
import { EnginiClientError } from "./errors.js";
|
|
4
|
+
import { OpenAIProvider } from "./providers/openai.js";
|
|
5
|
+
import { ToolsResource } from "./resources/tools.js";
|
|
6
|
+
import { ConnectionsResource } from "./resources/connections.js";
|
|
7
|
+
import { ToolsetsResource } from "./resources/toolsets.js";
|
|
8
|
+
import { ApplicationsResource } from "./resources/applications.js";
|
|
9
|
+
import { AuthResource } from "./resources/auth.js";
|
|
10
|
+
import { Toolset } from "./toolset.js";
|
|
11
|
+
export const DEFAULT_BASE_URL = "https://api.engini.io";
|
|
12
|
+
/** Engini SDK client — the single public entry point. */
|
|
13
|
+
export class Engini {
|
|
14
|
+
tools;
|
|
15
|
+
connections;
|
|
16
|
+
toolsets;
|
|
17
|
+
applications;
|
|
18
|
+
auth;
|
|
19
|
+
provider;
|
|
20
|
+
baseUrl;
|
|
21
|
+
/** @internal transport + per-tool schema cache, consumed by resources. */
|
|
22
|
+
_transport;
|
|
23
|
+
_toolCache = new Map();
|
|
24
|
+
constructor(options = {}) {
|
|
25
|
+
const explicit = [options.token, options.apiKey, options.auth].filter((c) => c !== undefined);
|
|
26
|
+
if (explicit.length > 1) {
|
|
27
|
+
throw new EnginiClientError("Pass only one of `token`, `apiKey`, or `auth`.");
|
|
28
|
+
}
|
|
29
|
+
let auth = options.auth;
|
|
30
|
+
if (auth === undefined) {
|
|
31
|
+
if (options.apiKey !== undefined) {
|
|
32
|
+
auth = new ApiKeyAuth(options.apiKey);
|
|
33
|
+
}
|
|
34
|
+
else if (options.token !== undefined) {
|
|
35
|
+
auth = new BearerAuth(options.token);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const envKey = process.env[ENV_API_KEY_VAR];
|
|
39
|
+
const envToken = process.env[ENV_TOKEN_VAR];
|
|
40
|
+
if (envKey) {
|
|
41
|
+
auth = new ApiKeyAuth(envKey);
|
|
42
|
+
}
|
|
43
|
+
else if (envToken) {
|
|
44
|
+
auth = new BearerAuth(envToken);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
throw new EnginiClientError(`No credentials. Pass apiKey=... or token=... or set ${ENV_API_KEY_VAR}/${ENV_TOKEN_VAR}.`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// On the api-key path the company is bound to the key, so no companytoken is
|
|
52
|
+
// sent; an explicit companyToken is misuse, an env one is silently ignored.
|
|
53
|
+
const isApiKey = auth instanceof ApiKeyAuth;
|
|
54
|
+
if (isApiKey && options.companyToken !== undefined) {
|
|
55
|
+
throw new EnginiClientError("`companyToken` is not used with api-key auth; the company is bound to the key.");
|
|
56
|
+
}
|
|
57
|
+
const companyToken = isApiKey
|
|
58
|
+
? undefined
|
|
59
|
+
: (options.companyToken ?? process.env[ENV_COMPANY_TOKEN_VAR]);
|
|
60
|
+
this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
|
|
61
|
+
this._transport = buildClient(this.baseUrl, auth, companyToken, {
|
|
62
|
+
verify: options.verify ?? true,
|
|
63
|
+
});
|
|
64
|
+
this.provider = options.provider ?? new OpenAIProvider();
|
|
65
|
+
this.tools = new ToolsResource(this);
|
|
66
|
+
this.connections = new ConnectionsResource(this);
|
|
67
|
+
this.toolsets = new ToolsetsResource(this);
|
|
68
|
+
this.applications = new ApplicationsResource(this);
|
|
69
|
+
this.auth = new AuthResource(this);
|
|
70
|
+
}
|
|
71
|
+
toolset(params = {}) {
|
|
72
|
+
if (params.toolsetId !== undefined) {
|
|
73
|
+
return this.toolsets.get(params.toolsetId).then((dto) => Toolset.fromDto(this, dto));
|
|
74
|
+
}
|
|
75
|
+
return new Toolset(this, { connections: params.connections, tools: params.tools });
|
|
76
|
+
}
|
|
77
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error hierarchy for the Engini SDK. Mirrors the Python `engini.errors`
|
|
3
|
+
* tree; every class is `instanceof`-discriminable.
|
|
4
|
+
*/
|
|
5
|
+
export declare class EnginiError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
/** Transport-level failure before a response was received. */
|
|
9
|
+
export declare class EnginiNetworkError extends EnginiError {
|
|
10
|
+
}
|
|
11
|
+
/** Any non-2xx API response with a parseable body. */
|
|
12
|
+
export declare class EnginiAPIError extends EnginiError {
|
|
13
|
+
}
|
|
14
|
+
/** 401 or 403 — token missing, invalid, expired, or lacking permission. */
|
|
15
|
+
export declare class EnginiAuthError extends EnginiAPIError {
|
|
16
|
+
}
|
|
17
|
+
/** 404 — the requested resource does not exist. */
|
|
18
|
+
export declare class EnginiNotFoundError extends EnginiAPIError {
|
|
19
|
+
}
|
|
20
|
+
/** 400 or 422 — request rejected; exposes field-level details (Phase 3). */
|
|
21
|
+
export declare class EnginiValidationError extends EnginiAPIError {
|
|
22
|
+
}
|
|
23
|
+
/** 429 — rate limited; exposes Retry-After (Phase 3). */
|
|
24
|
+
export declare class EnginiRateLimitError extends EnginiAPIError {
|
|
25
|
+
}
|
|
26
|
+
/** 409 — the request conflicts with current resource state. */
|
|
27
|
+
export declare class EnginiConflictError extends EnginiAPIError {
|
|
28
|
+
}
|
|
29
|
+
/** 5xx — the API failed internally. */
|
|
30
|
+
export declare class EnginiServerError extends EnginiAPIError {
|
|
31
|
+
}
|
|
32
|
+
/** SDK misuse (e.g., a provider used without its optional peer installed). */
|
|
33
|
+
export declare class EnginiClientError extends EnginiError {
|
|
34
|
+
}
|
|
35
|
+
/** No connection could be resolved for an application and no default exists. */
|
|
36
|
+
export declare class EnginiConnectionError extends EnginiError {
|
|
37
|
+
}
|
|
38
|
+
/** Unknown toolset id, or an ambiguous connection name during resolution or save. */
|
|
39
|
+
export declare class EnginiToolsetError extends EnginiError {
|
|
40
|
+
}
|
|
41
|
+
/** A tool ran but reported failure (`ToolExecuteResponse.isSuccess === false`). */
|
|
42
|
+
export declare class EnginiToolExecutionError extends EnginiError {
|
|
43
|
+
readonly errorMessage: string | null;
|
|
44
|
+
readonly executionInfo: unknown;
|
|
45
|
+
readonly historyId: number | null;
|
|
46
|
+
constructor(errorMessage: string | null, opts?: {
|
|
47
|
+
executionInfo?: unknown;
|
|
48
|
+
historyId?: number | null;
|
|
49
|
+
});
|
|
50
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error hierarchy for the Engini SDK. Mirrors the Python `engini.errors`
|
|
3
|
+
* tree; every class is `instanceof`-discriminable.
|
|
4
|
+
*/
|
|
5
|
+
export class EnginiError extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = new.target.name;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/** Transport-level failure before a response was received. */
|
|
12
|
+
export class EnginiNetworkError extends EnginiError {
|
|
13
|
+
}
|
|
14
|
+
/** Any non-2xx API response with a parseable body. */
|
|
15
|
+
export class EnginiAPIError extends EnginiError {
|
|
16
|
+
}
|
|
17
|
+
/** 401 or 403 — token missing, invalid, expired, or lacking permission. */
|
|
18
|
+
export class EnginiAuthError extends EnginiAPIError {
|
|
19
|
+
}
|
|
20
|
+
/** 404 — the requested resource does not exist. */
|
|
21
|
+
export class EnginiNotFoundError extends EnginiAPIError {
|
|
22
|
+
}
|
|
23
|
+
/** 400 or 422 — request rejected; exposes field-level details (Phase 3). */
|
|
24
|
+
export class EnginiValidationError extends EnginiAPIError {
|
|
25
|
+
}
|
|
26
|
+
/** 429 — rate limited; exposes Retry-After (Phase 3). */
|
|
27
|
+
export class EnginiRateLimitError extends EnginiAPIError {
|
|
28
|
+
}
|
|
29
|
+
/** 409 — the request conflicts with current resource state. */
|
|
30
|
+
export class EnginiConflictError extends EnginiAPIError {
|
|
31
|
+
}
|
|
32
|
+
/** 5xx — the API failed internally. */
|
|
33
|
+
export class EnginiServerError extends EnginiAPIError {
|
|
34
|
+
}
|
|
35
|
+
/** SDK misuse (e.g., a provider used without its optional peer installed). */
|
|
36
|
+
export class EnginiClientError extends EnginiError {
|
|
37
|
+
}
|
|
38
|
+
/** No connection could be resolved for an application and no default exists. */
|
|
39
|
+
export class EnginiConnectionError extends EnginiError {
|
|
40
|
+
}
|
|
41
|
+
/** Unknown toolset id, or an ambiguous connection name during resolution or save. */
|
|
42
|
+
export class EnginiToolsetError extends EnginiError {
|
|
43
|
+
}
|
|
44
|
+
/** A tool ran but reported failure (`ToolExecuteResponse.isSuccess === false`). */
|
|
45
|
+
export class EnginiToolExecutionError extends EnginiError {
|
|
46
|
+
errorMessage;
|
|
47
|
+
executionInfo;
|
|
48
|
+
historyId;
|
|
49
|
+
constructor(errorMessage, opts = {}) {
|
|
50
|
+
super(errorMessage ?? "Tool execution failed");
|
|
51
|
+
this.errorMessage = errorMessage;
|
|
52
|
+
this.executionInfo = opts.executionInfo ?? null;
|
|
53
|
+
this.historyId = opts.historyId ?? null;
|
|
54
|
+
}
|
|
55
|
+
}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Dispatcher } from "undici";
|
|
2
|
+
import { createEnginiClient } from "@engini/client";
|
|
3
|
+
import type { Auth } from "./auth.js";
|
|
4
|
+
export type Transport = ReturnType<typeof createEnginiClient>;
|
|
5
|
+
/**
|
|
6
|
+
* TLS verification setting (mirrors Python's `verify`). `true` (default)
|
|
7
|
+
* verifies normally; `false` disables verification (dev only); a string is a
|
|
8
|
+
* CA-bundle file path to trust a private CA; a `Dispatcher` is used as-is (the
|
|
9
|
+
* advanced escape hatch, analogous to Python's `ssl.SSLContext`).
|
|
10
|
+
*/
|
|
11
|
+
export type Verify = boolean | string | Dispatcher;
|
|
12
|
+
/**
|
|
13
|
+
* Map a `verify` setting onto an undici `Dispatcher`, or `undefined` to keep the
|
|
14
|
+
* default verification. Node's `fetch` has no `verify_ssl` equivalent — TLS
|
|
15
|
+
* options are controlled through the dispatcher.
|
|
16
|
+
*/
|
|
17
|
+
export declare function tlsDispatcher(verify: Verify): Dispatcher | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Build the generated transport with auth (and optional account) headers.
|
|
20
|
+
* `createEnginiClient` accepts only `{ baseUrl, token }`, so the pluggable
|
|
21
|
+
* `Auth` strategy and the optional `companytoken` account selector are applied
|
|
22
|
+
* as default headers via `setConfig` (mirrors Python's `build_client`).
|
|
23
|
+
*
|
|
24
|
+
* `options.verify` controls TLS verification: when it resolves to a dispatcher
|
|
25
|
+
* (i.e. anything other than the default `true`), a custom `fetch` is installed
|
|
26
|
+
* that routes requests through that dispatcher.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildClient(baseUrl: string, auth: Auth, companyToken?: string, options?: {
|
|
29
|
+
verify?: Verify;
|
|
30
|
+
}): Transport;
|
|
31
|
+
/** A generated operation function (hey-api), invoked with `{ client, ... }`. */
|
|
32
|
+
type Operation<O, R> = (options: O & {
|
|
33
|
+
throwOnError?: boolean;
|
|
34
|
+
}) => Promise<{
|
|
35
|
+
data?: R;
|
|
36
|
+
error?: unknown;
|
|
37
|
+
response?: Response;
|
|
38
|
+
}>;
|
|
39
|
+
/** Run a generated operation, map errors, return parsed success data. */
|
|
40
|
+
export declare function call<O extends object, R>(operation: Operation<O, R>, options: O): Promise<R>;
|
|
41
|
+
export {};
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP policy layer: builds the configured `@engini/client` and maps its
|
|
3
|
+
* result envelope onto the typed `EnginiError` tree. The SDK is the type
|
|
4
|
+
* boundary — the client's `{ data, error }` shape and `ErrorResponse` never
|
|
5
|
+
* escape this module.
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from "node:fs";
|
|
8
|
+
import { Agent } from "undici";
|
|
9
|
+
import { createEnginiClient } from "@engini/client";
|
|
10
|
+
import { EnginiAPIError, EnginiAuthError, EnginiConflictError, EnginiNetworkError, EnginiNotFoundError, EnginiRateLimitError, EnginiServerError, EnginiValidationError, } from "./errors.js";
|
|
11
|
+
/**
|
|
12
|
+
* Map a `verify` setting onto an undici `Dispatcher`, or `undefined` to keep the
|
|
13
|
+
* default verification. Node's `fetch` has no `verify_ssl` equivalent — TLS
|
|
14
|
+
* options are controlled through the dispatcher.
|
|
15
|
+
*/
|
|
16
|
+
export function tlsDispatcher(verify) {
|
|
17
|
+
if (verify === true)
|
|
18
|
+
return undefined;
|
|
19
|
+
if (verify === false)
|
|
20
|
+
return new Agent({ connect: { rejectUnauthorized: false } });
|
|
21
|
+
if (typeof verify === "string")
|
|
22
|
+
return new Agent({ connect: { ca: readFileSync(verify) } });
|
|
23
|
+
return verify;
|
|
24
|
+
}
|
|
25
|
+
const STATUS_TO_ERROR = {
|
|
26
|
+
400: EnginiValidationError,
|
|
27
|
+
401: EnginiAuthError,
|
|
28
|
+
403: EnginiAuthError,
|
|
29
|
+
404: EnginiNotFoundError,
|
|
30
|
+
409: EnginiConflictError,
|
|
31
|
+
422: EnginiValidationError,
|
|
32
|
+
429: EnginiRateLimitError,
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Build the generated transport with auth (and optional account) headers.
|
|
36
|
+
* `createEnginiClient` accepts only `{ baseUrl, token }`, so the pluggable
|
|
37
|
+
* `Auth` strategy and the optional `companytoken` account selector are applied
|
|
38
|
+
* as default headers via `setConfig` (mirrors Python's `build_client`).
|
|
39
|
+
*
|
|
40
|
+
* `options.verify` controls TLS verification: when it resolves to a dispatcher
|
|
41
|
+
* (i.e. anything other than the default `true`), a custom `fetch` is installed
|
|
42
|
+
* that routes requests through that dispatcher.
|
|
43
|
+
*/
|
|
44
|
+
export function buildClient(baseUrl, auth, companyToken, options = {}) {
|
|
45
|
+
const client = createEnginiClient({ baseUrl });
|
|
46
|
+
const headers = auth.apply({});
|
|
47
|
+
if (companyToken !== undefined)
|
|
48
|
+
headers["companytoken"] = companyToken;
|
|
49
|
+
const dispatcher = tlsDispatcher(options.verify ?? true);
|
|
50
|
+
const fetchOverride = dispatcher === undefined
|
|
51
|
+
? undefined
|
|
52
|
+
: (input, init) => fetch(input, { ...init, dispatcher });
|
|
53
|
+
const current = client.getConfig();
|
|
54
|
+
client.setConfig({
|
|
55
|
+
...current,
|
|
56
|
+
headers,
|
|
57
|
+
...(fetchOverride ? { fetch: fetchOverride } : {}),
|
|
58
|
+
});
|
|
59
|
+
return client;
|
|
60
|
+
}
|
|
61
|
+
/** Shared helper: map an HTTP status to the appropriate error constructor. */
|
|
62
|
+
function errorForStatus(status, error) {
|
|
63
|
+
const message = errorMessage(error, status);
|
|
64
|
+
const Ctor = STATUS_TO_ERROR[status] ?? (status >= 500 ? EnginiServerError : EnginiAPIError);
|
|
65
|
+
return new Ctor(message);
|
|
66
|
+
}
|
|
67
|
+
/** Run a generated operation, map errors, return parsed success data. */
|
|
68
|
+
export async function call(operation, options) {
|
|
69
|
+
let result;
|
|
70
|
+
try {
|
|
71
|
+
result = await operation({ ...options, throwOnError: false });
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
// Check if the thrown value carries a response (e.g. hey-api throws on empty-body parse errors)
|
|
75
|
+
const errWithResponse = err;
|
|
76
|
+
if (errWithResponse.response instanceof Response) {
|
|
77
|
+
throw errorForStatus(errWithResponse.response.status, undefined);
|
|
78
|
+
}
|
|
79
|
+
throw new EnginiNetworkError(err instanceof Error ? err.message : String(err));
|
|
80
|
+
}
|
|
81
|
+
const { data, error, response } = result;
|
|
82
|
+
if (response === undefined) {
|
|
83
|
+
throw new EnginiNetworkError("No response received from the API.");
|
|
84
|
+
}
|
|
85
|
+
const status = response.status;
|
|
86
|
+
if (status >= 200 && status < 300) {
|
|
87
|
+
return data;
|
|
88
|
+
}
|
|
89
|
+
throw errorForStatus(status, error);
|
|
90
|
+
}
|
|
91
|
+
function errorMessage(error, status) {
|
|
92
|
+
if (error && typeof error === "object") {
|
|
93
|
+
const e = error;
|
|
94
|
+
if (typeof e.errorCode === "string" && typeof e.message === "string") {
|
|
95
|
+
return `${e.errorCode}: ${e.message}`;
|
|
96
|
+
}
|
|
97
|
+
if (typeof e.message === "string")
|
|
98
|
+
return e.message;
|
|
99
|
+
}
|
|
100
|
+
return `HTTP ${status}`;
|
|
101
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { Engini, DEFAULT_BASE_URL } from "./client.js";
|
|
2
|
+
export type { EnginiOptions } from "./client.js";
|
|
3
|
+
export { ApiKeyAuth, BearerAuth, ENV_API_KEY_VAR, ENV_TOKEN_VAR, ENV_COMPANY_TOKEN_VAR, } from "./auth.js";
|
|
4
|
+
export type { Auth } from "./auth.js";
|
|
5
|
+
export type { Verify } from "./http.js";
|
|
6
|
+
export { EnginiError, EnginiNetworkError, EnginiAPIError, EnginiAuthError, EnginiNotFoundError, EnginiValidationError, EnginiRateLimitError, EnginiConflictError, EnginiServerError, EnginiClientError, EnginiConnectionError, EnginiToolsetError, EnginiToolExecutionError, } from "./errors.js";
|
|
7
|
+
export { ToolsResource, ConnectionsResource, ToolsetsResource, ApplicationsResource, } from "./resources/index.js";
|
|
8
|
+
export type { ToolsGetOptions, ToolsExecuteOptions, ApplicationsListOptions } from "./resources/index.js";
|
|
9
|
+
export { Toolset } from "./toolset.js";
|
|
10
|
+
export type { ConnectionBinding, ToolsetExecuteOptions } from "./toolset.js";
|
|
11
|
+
export type { ToolSchema, Filter, Sort, ToolExecuteResult, Application, ApplicationDetail, Connection, ConnectionDetail, WhoAmI, } from "./types.js";
|
|
12
|
+
export type { Provider, ToolCall, ToolResultOptions } from "./providers/base.js";
|
|
13
|
+
export { OpenAIProvider } from "./providers/openai.js";
|
|
14
|
+
export type { OpenAIToolDef, OpenAIFunctionDef } from "./providers/openai.js";
|
|
15
|
+
export { AnthropicProvider } from "./providers/anthropic.js";
|
|
16
|
+
export type { AnthropicToolDef } from "./providers/anthropic.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Engini, DEFAULT_BASE_URL } from "./client.js";
|
|
2
|
+
export { ApiKeyAuth, BearerAuth, ENV_API_KEY_VAR, ENV_TOKEN_VAR, ENV_COMPANY_TOKEN_VAR, } from "./auth.js";
|
|
3
|
+
export { EnginiError, EnginiNetworkError, EnginiAPIError, EnginiAuthError, EnginiNotFoundError, EnginiValidationError, EnginiRateLimitError, EnginiConflictError, EnginiServerError, EnginiClientError, EnginiConnectionError, EnginiToolsetError, EnginiToolExecutionError, } from "./errors.js";
|
|
4
|
+
export { ToolsResource, ConnectionsResource, ToolsetsResource, ApplicationsResource, } from "./resources/index.js";
|
|
5
|
+
export { Toolset } from "./toolset.js";
|
|
6
|
+
export { OpenAIProvider } from "./providers/openai.js";
|
|
7
|
+
export { AnthropicProvider } from "./providers/anthropic.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-pagination over the autogen `PaginatedResponseOf*` envelope.
|
|
3
|
+
* `fetchPage(offset, top)` returns a page; `paginate` yields items across pages
|
|
4
|
+
* until `totalCount` is reached or a page comes back empty.
|
|
5
|
+
*/
|
|
6
|
+
/** The shape of every `PaginatedResponseOf*` envelope the client returns. */
|
|
7
|
+
export interface Page<T> {
|
|
8
|
+
items: T[];
|
|
9
|
+
totalCount: number;
|
|
10
|
+
offset: number;
|
|
11
|
+
top: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function paginate<T>(fetchPage: (offset: number, top: number) => Promise<Page<T>>, options?: {
|
|
14
|
+
top?: number;
|
|
15
|
+
}): AsyncGenerator<T>;
|
|
16
|
+
/** Collect an async generator into an array (convenience for resources). */
|
|
17
|
+
export declare function collect<T>(gen: AsyncIterable<T>): Promise<T[]>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-pagination over the autogen `PaginatedResponseOf*` envelope.
|
|
3
|
+
* `fetchPage(offset, top)` returns a page; `paginate` yields items across pages
|
|
4
|
+
* until `totalCount` is reached or a page comes back empty.
|
|
5
|
+
*/
|
|
6
|
+
export async function* paginate(fetchPage, options = {}) {
|
|
7
|
+
const top = options.top ?? 100;
|
|
8
|
+
let offset = 0;
|
|
9
|
+
while (true) {
|
|
10
|
+
const page = await fetchPage(offset, top);
|
|
11
|
+
const items = page.items ?? [];
|
|
12
|
+
for (const item of items)
|
|
13
|
+
yield item;
|
|
14
|
+
offset += items.length;
|
|
15
|
+
if (items.length === 0 || offset >= page.totalCount)
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Collect an async generator into an array (convenience for resources). */
|
|
20
|
+
export async function collect(gen) {
|
|
21
|
+
const out = [];
|
|
22
|
+
for await (const item of gen)
|
|
23
|
+
out.push(item);
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ToolSchema } from "../types.js";
|
|
2
|
+
import { type Provider, type ToolCall, type ToolResultOptions } from "./base.js";
|
|
3
|
+
/** Anthropic tool definition — the wire format owned here, no `anthropic` dep. */
|
|
4
|
+
export interface AnthropicToolDef {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
input_schema: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
export declare class AnthropicProvider implements Provider {
|
|
10
|
+
readonly name = "anthropic";
|
|
11
|
+
wrapTool(canonical: ToolSchema): AnthropicToolDef;
|
|
12
|
+
wrapTools(canonicals: ToolSchema[]): AnthropicToolDef[];
|
|
13
|
+
parseToolCalls(llmResponse: unknown): ToolCall[];
|
|
14
|
+
formatToolResult(call: ToolCall, options: ToolResultOptions): unknown;
|
|
15
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { get } from "./base.js";
|
|
2
|
+
export class AnthropicProvider {
|
|
3
|
+
name = "anthropic";
|
|
4
|
+
wrapTool(canonical) {
|
|
5
|
+
return {
|
|
6
|
+
name: canonical.toolSlug,
|
|
7
|
+
description: canonical.description ?? "",
|
|
8
|
+
input_schema: canonical.inputSchema ?? {},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
wrapTools(canonicals) {
|
|
12
|
+
return canonicals.map((c) => this.wrapTool(c));
|
|
13
|
+
}
|
|
14
|
+
parseToolCalls(llmResponse) {
|
|
15
|
+
const blocks = get(llmResponse, "content") ?? [];
|
|
16
|
+
const calls = [];
|
|
17
|
+
for (const block of blocks) {
|
|
18
|
+
if (get(block, "type") !== "tool_use")
|
|
19
|
+
continue;
|
|
20
|
+
calls.push({
|
|
21
|
+
id: String(get(block, "id") ?? ""),
|
|
22
|
+
name: String(get(block, "name") ?? ""),
|
|
23
|
+
arguments: get(block, "input") ?? {},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return calls;
|
|
27
|
+
}
|
|
28
|
+
formatToolResult(call, options) {
|
|
29
|
+
const content = options.error != null ? { error: options.error } : options.output;
|
|
30
|
+
return {
|
|
31
|
+
role: "user",
|
|
32
|
+
content: [{ type: "tool_result", tool_use_id: call.id, content: JSON.stringify(content) }],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ToolSchema } from "../types.js";
|
|
2
|
+
/** A single tool invocation requested by an LLM, normalized across vendors. */
|
|
3
|
+
export interface ToolCall {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
arguments: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
/** Options for formatting a tool result message. */
|
|
9
|
+
export interface ToolResultOptions {
|
|
10
|
+
output?: unknown;
|
|
11
|
+
error?: string | null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Contract every LLM provider adapter implements. `wrapTool` is pure;
|
|
15
|
+
* `wrapTools` is bulk-equivalent to mapping `wrapTool`; Tier-1 providers never
|
|
16
|
+
* import vendor SDKs. `parseToolCalls`/`formatToolResult` keep the `Toolset`
|
|
17
|
+
* agent loop provider-agnostic.
|
|
18
|
+
*/
|
|
19
|
+
export interface Provider {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
wrapTool(canonical: ToolSchema): unknown;
|
|
22
|
+
wrapTools(canonicals: ToolSchema[]): unknown[];
|
|
23
|
+
parseToolCalls(llmResponse: unknown): ToolCall[];
|
|
24
|
+
formatToolResult(call: ToolCall, options: ToolResultOptions): unknown;
|
|
25
|
+
}
|
|
26
|
+
/** Read `key` whether `obj` is a plain object or undefined. */
|
|
27
|
+
export declare function get(obj: unknown, key: string): unknown;
|