@entrys/client 0.1.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 +123 -0
- package/dist/index.d.mts +143 -0
- package/dist/index.d.ts +143 -0
- package/dist/index.js +149 -0
- package/dist/index.mjs +119 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Entrys
|
|
2
|
+
|
|
3
|
+
Give your AI agents a single entry point to access internal APIs and tools. Redact PII by default, audit every request, and control access, without modifying your existing services.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @entrys/client
|
|
10
|
+
# or
|
|
11
|
+
pnpm add @entrys/client
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Quick Start
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import Entry from "@entrys/client";
|
|
18
|
+
|
|
19
|
+
const entry = new Entry({
|
|
20
|
+
apiKey: process.env.ENTRYS_API_KEY
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const customer = await entry.invoke("get_customer", {
|
|
24
|
+
params: { id: "123" }
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
console.log(customer);
|
|
28
|
+
// { name: "Jane Doe", email: "[REDACTED]", ... }
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Configuration
|
|
32
|
+
|
|
33
|
+
Set your API key pass it directly:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
const entry = new Entry({ apiKey: "ent_your_api_key" });
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
For self-hosted deployments, also set the base URL:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const entry = new Entry({
|
|
43
|
+
apiKey: process.env.ENTRYS_API_KEY,
|
|
44
|
+
baseUrl: "http://localhost:3001"
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## API
|
|
49
|
+
|
|
50
|
+
### `new Entry(options?)`
|
|
51
|
+
|
|
52
|
+
Create a new entrys client.
|
|
53
|
+
|
|
54
|
+
**Options (all optional):**
|
|
55
|
+
- `apiKey` - Your agent API key. Defaults to `ENTRYS_API_KEY` env var
|
|
56
|
+
- `baseUrl` - Gateway URL. Defaults to `ENTRYS_BASE_URL` env var or `https://api.entrys.co`
|
|
57
|
+
- `fetch` - Custom fetch implementation
|
|
58
|
+
|
|
59
|
+
### `agent.invoke(toolName, options?)`
|
|
60
|
+
|
|
61
|
+
Invoke a registered tool through the gateway. Returns the output directly.
|
|
62
|
+
|
|
63
|
+
**Parameters:**
|
|
64
|
+
- `toolName` (string) - Name of the tool to invoke
|
|
65
|
+
- `options.params` (object) - URL path parameters
|
|
66
|
+
- `options.input` (object) - Request body data
|
|
67
|
+
- `options.context` (object) - Additional context
|
|
68
|
+
|
|
69
|
+
**Returns:** `Promise<T>` - The tool output (with PII automatically redacted)
|
|
70
|
+
|
|
71
|
+
**Throws:** `EntryError` on failure
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
const customer = await entry.invoke("get_customer", {
|
|
75
|
+
params: { id: "123" }
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const invoice = await entry.invoke("get_invoice", {
|
|
79
|
+
params: { customerId: "123" }
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### `agent.invokeWithMeta(toolName, options?)`
|
|
84
|
+
|
|
85
|
+
Same as `invoke` but also returns metadata including redaction info.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
const { output, meta } = await entry.invokeWithMeta("get_customer", {
|
|
89
|
+
params: { id: "123" }
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
console.log(meta.requestId); // Unique request ID
|
|
93
|
+
console.log(meta.latencyMs); // Request latency
|
|
94
|
+
console.log(meta.redactions); // [{ type: "email", count: 1 }]
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### `agent.invokeRaw(toolName, options?)`
|
|
98
|
+
|
|
99
|
+
Returns the raw response without throwing on errors. Useful if you want to handle errors yourself.
|
|
100
|
+
|
|
101
|
+
## Error Handling
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { Entry, EntryError } from "@entrys/client";
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
await entry.invoke("get_customer", { params: { id: "123" } });
|
|
108
|
+
} catch (err) {
|
|
109
|
+
if (err instanceof EntryError) {
|
|
110
|
+
console.log(err.code); // 'TOOL_NOT_FOUND', 'UNAUTHORIZED', etc.
|
|
111
|
+
console.log(err.message); // Human-readable message
|
|
112
|
+
console.log(err.requestId); // For debugging
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Error Codes
|
|
118
|
+
|
|
119
|
+
- `TOOL_NOT_FOUND` - Tool doesn't exist in this environment
|
|
120
|
+
- `UNAUTHORIZED` - Agent not authorized for this tool
|
|
121
|
+
- `RATE_LIMITED` - Rate limit exceeded (60 req/min)
|
|
122
|
+
- `VALIDATION_ERROR` - Invalid parameters
|
|
123
|
+
- `UPSTREAM_ERROR` - The upstream API returned an error
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Summary of redactions applied to output
|
|
3
|
+
*/
|
|
4
|
+
interface RedactionSummary {
|
|
5
|
+
type: string;
|
|
6
|
+
count: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Successful tool invocation response
|
|
10
|
+
*/
|
|
11
|
+
interface InvokeSuccessResponse {
|
|
12
|
+
ok: true;
|
|
13
|
+
tool: string;
|
|
14
|
+
output: unknown;
|
|
15
|
+
meta: {
|
|
16
|
+
requestId: string;
|
|
17
|
+
latencyMs: number;
|
|
18
|
+
redactions: RedactionSummary[];
|
|
19
|
+
version?: string;
|
|
20
|
+
backendType?: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Error response from tool invocation
|
|
25
|
+
*/
|
|
26
|
+
interface InvokeErrorResponse {
|
|
27
|
+
ok: false;
|
|
28
|
+
error: {
|
|
29
|
+
code: 'TOOL_NOT_FOUND' | 'UNAUTHORIZED' | 'UPSTREAM_ERROR' | 'RATE_LIMITED' | 'VALIDATION_ERROR' | 'MCP_ERROR';
|
|
30
|
+
message: string;
|
|
31
|
+
};
|
|
32
|
+
meta: {
|
|
33
|
+
requestId: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Union type for invoke responses
|
|
38
|
+
*/
|
|
39
|
+
type InvokeResponse = InvokeSuccessResponse | InvokeErrorResponse;
|
|
40
|
+
/**
|
|
41
|
+
* Configuration options for Entry
|
|
42
|
+
*/
|
|
43
|
+
interface EntryOptions {
|
|
44
|
+
/** API key for authentication (starts with "ent_"). Defaults to ENTRYS_API_KEY env var */
|
|
45
|
+
apiKey?: string;
|
|
46
|
+
/** Base URL of the entrys gateway. Defaults to ENTRYS_BASE_URL env var or https://api.entrys.dev */
|
|
47
|
+
baseUrl?: string;
|
|
48
|
+
/** Optional custom fetch implementation (for testing or custom environments) */
|
|
49
|
+
fetch?: typeof fetch;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Options for invoking a tool
|
|
53
|
+
*/
|
|
54
|
+
interface InvokeOptions {
|
|
55
|
+
/** URL path parameters (e.g., { id: "123" } for /customers/{{id}}) */
|
|
56
|
+
params?: Record<string, string>;
|
|
57
|
+
/** Request body/input data */
|
|
58
|
+
input?: Record<string, unknown>;
|
|
59
|
+
/** Additional context passed to the tool */
|
|
60
|
+
context?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Metadata returned with successful invocations
|
|
64
|
+
*/
|
|
65
|
+
interface InvokeMeta {
|
|
66
|
+
requestId: string;
|
|
67
|
+
latencyMs: number;
|
|
68
|
+
redactions: Array<{
|
|
69
|
+
type: string;
|
|
70
|
+
count: number;
|
|
71
|
+
}>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Error thrown when a tool invocation fails
|
|
75
|
+
*/
|
|
76
|
+
declare class EntryError extends Error {
|
|
77
|
+
code: string;
|
|
78
|
+
requestId: string;
|
|
79
|
+
constructor(code: string, message: string, requestId: string);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* entrys client for invoking tools
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* import Entry from "@entrys/client";
|
|
87
|
+
*
|
|
88
|
+
* const entry = new Entry();
|
|
89
|
+
*
|
|
90
|
+
* const customer = await entry.invoke("get_customer", {
|
|
91
|
+
* params: { id: "123" }
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare class Entry {
|
|
96
|
+
private baseUrl;
|
|
97
|
+
private apiKey;
|
|
98
|
+
private fetchFn;
|
|
99
|
+
constructor(options?: EntryOptions);
|
|
100
|
+
/**
|
|
101
|
+
* Invoke a registered tool through the gateway
|
|
102
|
+
*
|
|
103
|
+
* @param toolName - The name of the tool to invoke (e.g., "get_customer")
|
|
104
|
+
* @param options - Parameters, input data, and context for the tool
|
|
105
|
+
* @returns The tool output (with PII automatically redacted)
|
|
106
|
+
* @throws {EntryError} If the tool invocation fails
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const customer = await agent.invoke("get_customer", {
|
|
111
|
+
* params: { id: "123" }
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
invoke<T = unknown>(toolName: string, options?: InvokeOptions): Promise<T>;
|
|
116
|
+
/**
|
|
117
|
+
* Invoke a tool and return both output and metadata
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const { output, meta } = await agent.invokeWithMeta("get_customer", {
|
|
122
|
+
* params: { id: "123" }
|
|
123
|
+
* });
|
|
124
|
+
* console.log(meta.redactions); // PII that was scrubbed
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
invokeWithMeta<T = unknown>(toolName: string, options?: InvokeOptions): Promise<{
|
|
128
|
+
output: T;
|
|
129
|
+
meta: InvokeMeta;
|
|
130
|
+
}>;
|
|
131
|
+
/**
|
|
132
|
+
* Invoke a tool and return the raw response (including error responses)
|
|
133
|
+
* Use this if you want to handle errors yourself instead of catching exceptions
|
|
134
|
+
*/
|
|
135
|
+
invokeRaw(toolName: string, options?: InvokeOptions): Promise<InvokeResponse>;
|
|
136
|
+
}
|
|
137
|
+
declare const createClient: (options?: EntryOptions) => Entry;
|
|
138
|
+
declare const AgentGateway: typeof Entry;
|
|
139
|
+
type AgentGatewayOptions = EntryOptions;
|
|
140
|
+
declare const AgentGatewayError: typeof EntryError;
|
|
141
|
+
declare const ATGError: typeof EntryError;
|
|
142
|
+
|
|
143
|
+
export { ATGError, AgentGateway, AgentGatewayError, type AgentGatewayOptions, Entry, EntryError, type EntryOptions, type InvokeErrorResponse, type InvokeMeta, type InvokeOptions, type InvokeResponse, type InvokeSuccessResponse, type RedactionSummary, createClient, Entry as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Summary of redactions applied to output
|
|
3
|
+
*/
|
|
4
|
+
interface RedactionSummary {
|
|
5
|
+
type: string;
|
|
6
|
+
count: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Successful tool invocation response
|
|
10
|
+
*/
|
|
11
|
+
interface InvokeSuccessResponse {
|
|
12
|
+
ok: true;
|
|
13
|
+
tool: string;
|
|
14
|
+
output: unknown;
|
|
15
|
+
meta: {
|
|
16
|
+
requestId: string;
|
|
17
|
+
latencyMs: number;
|
|
18
|
+
redactions: RedactionSummary[];
|
|
19
|
+
version?: string;
|
|
20
|
+
backendType?: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Error response from tool invocation
|
|
25
|
+
*/
|
|
26
|
+
interface InvokeErrorResponse {
|
|
27
|
+
ok: false;
|
|
28
|
+
error: {
|
|
29
|
+
code: 'TOOL_NOT_FOUND' | 'UNAUTHORIZED' | 'UPSTREAM_ERROR' | 'RATE_LIMITED' | 'VALIDATION_ERROR' | 'MCP_ERROR';
|
|
30
|
+
message: string;
|
|
31
|
+
};
|
|
32
|
+
meta: {
|
|
33
|
+
requestId: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Union type for invoke responses
|
|
38
|
+
*/
|
|
39
|
+
type InvokeResponse = InvokeSuccessResponse | InvokeErrorResponse;
|
|
40
|
+
/**
|
|
41
|
+
* Configuration options for Entry
|
|
42
|
+
*/
|
|
43
|
+
interface EntryOptions {
|
|
44
|
+
/** API key for authentication (starts with "ent_"). Defaults to ENTRYS_API_KEY env var */
|
|
45
|
+
apiKey?: string;
|
|
46
|
+
/** Base URL of the entrys gateway. Defaults to ENTRYS_BASE_URL env var or https://api.entrys.dev */
|
|
47
|
+
baseUrl?: string;
|
|
48
|
+
/** Optional custom fetch implementation (for testing or custom environments) */
|
|
49
|
+
fetch?: typeof fetch;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Options for invoking a tool
|
|
53
|
+
*/
|
|
54
|
+
interface InvokeOptions {
|
|
55
|
+
/** URL path parameters (e.g., { id: "123" } for /customers/{{id}}) */
|
|
56
|
+
params?: Record<string, string>;
|
|
57
|
+
/** Request body/input data */
|
|
58
|
+
input?: Record<string, unknown>;
|
|
59
|
+
/** Additional context passed to the tool */
|
|
60
|
+
context?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Metadata returned with successful invocations
|
|
64
|
+
*/
|
|
65
|
+
interface InvokeMeta {
|
|
66
|
+
requestId: string;
|
|
67
|
+
latencyMs: number;
|
|
68
|
+
redactions: Array<{
|
|
69
|
+
type: string;
|
|
70
|
+
count: number;
|
|
71
|
+
}>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Error thrown when a tool invocation fails
|
|
75
|
+
*/
|
|
76
|
+
declare class EntryError extends Error {
|
|
77
|
+
code: string;
|
|
78
|
+
requestId: string;
|
|
79
|
+
constructor(code: string, message: string, requestId: string);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* entrys client for invoking tools
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* import Entry from "@entrys/client";
|
|
87
|
+
*
|
|
88
|
+
* const entry = new Entry();
|
|
89
|
+
*
|
|
90
|
+
* const customer = await entry.invoke("get_customer", {
|
|
91
|
+
* params: { id: "123" }
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare class Entry {
|
|
96
|
+
private baseUrl;
|
|
97
|
+
private apiKey;
|
|
98
|
+
private fetchFn;
|
|
99
|
+
constructor(options?: EntryOptions);
|
|
100
|
+
/**
|
|
101
|
+
* Invoke a registered tool through the gateway
|
|
102
|
+
*
|
|
103
|
+
* @param toolName - The name of the tool to invoke (e.g., "get_customer")
|
|
104
|
+
* @param options - Parameters, input data, and context for the tool
|
|
105
|
+
* @returns The tool output (with PII automatically redacted)
|
|
106
|
+
* @throws {EntryError} If the tool invocation fails
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const customer = await agent.invoke("get_customer", {
|
|
111
|
+
* params: { id: "123" }
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
invoke<T = unknown>(toolName: string, options?: InvokeOptions): Promise<T>;
|
|
116
|
+
/**
|
|
117
|
+
* Invoke a tool and return both output and metadata
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const { output, meta } = await agent.invokeWithMeta("get_customer", {
|
|
122
|
+
* params: { id: "123" }
|
|
123
|
+
* });
|
|
124
|
+
* console.log(meta.redactions); // PII that was scrubbed
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
invokeWithMeta<T = unknown>(toolName: string, options?: InvokeOptions): Promise<{
|
|
128
|
+
output: T;
|
|
129
|
+
meta: InvokeMeta;
|
|
130
|
+
}>;
|
|
131
|
+
/**
|
|
132
|
+
* Invoke a tool and return the raw response (including error responses)
|
|
133
|
+
* Use this if you want to handle errors yourself instead of catching exceptions
|
|
134
|
+
*/
|
|
135
|
+
invokeRaw(toolName: string, options?: InvokeOptions): Promise<InvokeResponse>;
|
|
136
|
+
}
|
|
137
|
+
declare const createClient: (options?: EntryOptions) => Entry;
|
|
138
|
+
declare const AgentGateway: typeof Entry;
|
|
139
|
+
type AgentGatewayOptions = EntryOptions;
|
|
140
|
+
declare const AgentGatewayError: typeof EntryError;
|
|
141
|
+
declare const ATGError: typeof EntryError;
|
|
142
|
+
|
|
143
|
+
export { ATGError, AgentGateway, AgentGatewayError, type AgentGatewayOptions, Entry, EntryError, type EntryOptions, type InvokeErrorResponse, type InvokeMeta, type InvokeOptions, type InvokeResponse, type InvokeSuccessResponse, type RedactionSummary, createClient, Entry as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ATGError: () => ATGError,
|
|
24
|
+
AgentGateway: () => AgentGateway,
|
|
25
|
+
AgentGatewayError: () => AgentGatewayError,
|
|
26
|
+
Entry: () => Entry,
|
|
27
|
+
EntryError: () => EntryError,
|
|
28
|
+
createClient: () => createClient,
|
|
29
|
+
default: () => index_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
var EntryError = class extends Error {
|
|
33
|
+
code;
|
|
34
|
+
requestId;
|
|
35
|
+
constructor(code, message, requestId) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = "EntryError";
|
|
38
|
+
this.code = code;
|
|
39
|
+
this.requestId = requestId;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var Entry = class {
|
|
43
|
+
baseUrl;
|
|
44
|
+
apiKey;
|
|
45
|
+
fetchFn;
|
|
46
|
+
constructor(options = {}) {
|
|
47
|
+
const apiKey = options.apiKey ?? (typeof process !== "undefined" ? process.env?.ENTRYS_API_KEY : void 0);
|
|
48
|
+
const baseUrl = options.baseUrl ?? (typeof process !== "undefined" ? process.env?.ENTRYS_BASE_URL : void 0) ?? "https://api.entrys.co";
|
|
49
|
+
if (!apiKey) {
|
|
50
|
+
throw new Error("Entry: apiKey is required. Pass it in options or set ENTRYS_API_KEY environment variable.");
|
|
51
|
+
}
|
|
52
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
53
|
+
this.apiKey = apiKey;
|
|
54
|
+
this.fetchFn = options.fetch ?? fetch;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Invoke a registered tool through the gateway
|
|
58
|
+
*
|
|
59
|
+
* @param toolName - The name of the tool to invoke (e.g., "get_customer")
|
|
60
|
+
* @param options - Parameters, input data, and context for the tool
|
|
61
|
+
* @returns The tool output (with PII automatically redacted)
|
|
62
|
+
* @throws {EntryError} If the tool invocation fails
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const customer = await agent.invoke("get_customer", {
|
|
67
|
+
* params: { id: "123" }
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
async invoke(toolName, options) {
|
|
72
|
+
const result = await this.invokeWithMeta(toolName, options);
|
|
73
|
+
return result.output;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Invoke a tool and return both output and metadata
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const { output, meta } = await agent.invokeWithMeta("get_customer", {
|
|
81
|
+
* params: { id: "123" }
|
|
82
|
+
* });
|
|
83
|
+
* console.log(meta.redactions); // PII that was scrubbed
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
async invokeWithMeta(toolName, options) {
|
|
87
|
+
const url = `${this.baseUrl}/v1/invoke/${encodeURIComponent(toolName)}`;
|
|
88
|
+
const body = {};
|
|
89
|
+
if (options?.params) body.params = options.params;
|
|
90
|
+
if (options?.input) body.input = options.input;
|
|
91
|
+
if (options?.context) body.context = options.context;
|
|
92
|
+
const response = await this.fetchFn(url, {
|
|
93
|
+
method: "POST",
|
|
94
|
+
headers: {
|
|
95
|
+
"Content-Type": "application/json",
|
|
96
|
+
"x-api-key": this.apiKey
|
|
97
|
+
},
|
|
98
|
+
body: JSON.stringify(body)
|
|
99
|
+
});
|
|
100
|
+
const data = await response.json();
|
|
101
|
+
if (!data.ok) {
|
|
102
|
+
const errorResult = data;
|
|
103
|
+
throw new EntryError(
|
|
104
|
+
errorResult.error.code,
|
|
105
|
+
errorResult.error.message,
|
|
106
|
+
errorResult.meta.requestId
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
const successResult = data;
|
|
110
|
+
return {
|
|
111
|
+
output: successResult.output,
|
|
112
|
+
meta: successResult.meta
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Invoke a tool and return the raw response (including error responses)
|
|
117
|
+
* Use this if you want to handle errors yourself instead of catching exceptions
|
|
118
|
+
*/
|
|
119
|
+
async invokeRaw(toolName, options) {
|
|
120
|
+
const url = `${this.baseUrl}/v1/invoke/${encodeURIComponent(toolName)}`;
|
|
121
|
+
const body = {};
|
|
122
|
+
if (options?.params) body.params = options.params;
|
|
123
|
+
if (options?.input) body.input = options.input;
|
|
124
|
+
if (options?.context) body.context = options.context;
|
|
125
|
+
const response = await this.fetchFn(url, {
|
|
126
|
+
method: "POST",
|
|
127
|
+
headers: {
|
|
128
|
+
"Content-Type": "application/json",
|
|
129
|
+
"x-api-key": this.apiKey
|
|
130
|
+
},
|
|
131
|
+
body: JSON.stringify(body)
|
|
132
|
+
});
|
|
133
|
+
return await response.json();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
var createClient = (options) => new Entry(options);
|
|
137
|
+
var AgentGateway = Entry;
|
|
138
|
+
var AgentGatewayError = EntryError;
|
|
139
|
+
var ATGError = EntryError;
|
|
140
|
+
var index_default = Entry;
|
|
141
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
142
|
+
0 && (module.exports = {
|
|
143
|
+
ATGError,
|
|
144
|
+
AgentGateway,
|
|
145
|
+
AgentGatewayError,
|
|
146
|
+
Entry,
|
|
147
|
+
EntryError,
|
|
148
|
+
createClient
|
|
149
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var EntryError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
requestId;
|
|
5
|
+
constructor(code, message, requestId) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "EntryError";
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.requestId = requestId;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var Entry = class {
|
|
13
|
+
baseUrl;
|
|
14
|
+
apiKey;
|
|
15
|
+
fetchFn;
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
const apiKey = options.apiKey ?? (typeof process !== "undefined" ? process.env?.ENTRYS_API_KEY : void 0);
|
|
18
|
+
const baseUrl = options.baseUrl ?? (typeof process !== "undefined" ? process.env?.ENTRYS_BASE_URL : void 0) ?? "https://api.entrys.co";
|
|
19
|
+
if (!apiKey) {
|
|
20
|
+
throw new Error("Entry: apiKey is required. Pass it in options or set ENTRYS_API_KEY environment variable.");
|
|
21
|
+
}
|
|
22
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
23
|
+
this.apiKey = apiKey;
|
|
24
|
+
this.fetchFn = options.fetch ?? fetch;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Invoke a registered tool through the gateway
|
|
28
|
+
*
|
|
29
|
+
* @param toolName - The name of the tool to invoke (e.g., "get_customer")
|
|
30
|
+
* @param options - Parameters, input data, and context for the tool
|
|
31
|
+
* @returns The tool output (with PII automatically redacted)
|
|
32
|
+
* @throws {EntryError} If the tool invocation fails
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const customer = await agent.invoke("get_customer", {
|
|
37
|
+
* params: { id: "123" }
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
async invoke(toolName, options) {
|
|
42
|
+
const result = await this.invokeWithMeta(toolName, options);
|
|
43
|
+
return result.output;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Invoke a tool and return both output and metadata
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const { output, meta } = await agent.invokeWithMeta("get_customer", {
|
|
51
|
+
* params: { id: "123" }
|
|
52
|
+
* });
|
|
53
|
+
* console.log(meta.redactions); // PII that was scrubbed
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
async invokeWithMeta(toolName, options) {
|
|
57
|
+
const url = `${this.baseUrl}/v1/invoke/${encodeURIComponent(toolName)}`;
|
|
58
|
+
const body = {};
|
|
59
|
+
if (options?.params) body.params = options.params;
|
|
60
|
+
if (options?.input) body.input = options.input;
|
|
61
|
+
if (options?.context) body.context = options.context;
|
|
62
|
+
const response = await this.fetchFn(url, {
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: {
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
"x-api-key": this.apiKey
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify(body)
|
|
69
|
+
});
|
|
70
|
+
const data = await response.json();
|
|
71
|
+
if (!data.ok) {
|
|
72
|
+
const errorResult = data;
|
|
73
|
+
throw new EntryError(
|
|
74
|
+
errorResult.error.code,
|
|
75
|
+
errorResult.error.message,
|
|
76
|
+
errorResult.meta.requestId
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const successResult = data;
|
|
80
|
+
return {
|
|
81
|
+
output: successResult.output,
|
|
82
|
+
meta: successResult.meta
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Invoke a tool and return the raw response (including error responses)
|
|
87
|
+
* Use this if you want to handle errors yourself instead of catching exceptions
|
|
88
|
+
*/
|
|
89
|
+
async invokeRaw(toolName, options) {
|
|
90
|
+
const url = `${this.baseUrl}/v1/invoke/${encodeURIComponent(toolName)}`;
|
|
91
|
+
const body = {};
|
|
92
|
+
if (options?.params) body.params = options.params;
|
|
93
|
+
if (options?.input) body.input = options.input;
|
|
94
|
+
if (options?.context) body.context = options.context;
|
|
95
|
+
const response = await this.fetchFn(url, {
|
|
96
|
+
method: "POST",
|
|
97
|
+
headers: {
|
|
98
|
+
"Content-Type": "application/json",
|
|
99
|
+
"x-api-key": this.apiKey
|
|
100
|
+
},
|
|
101
|
+
body: JSON.stringify(body)
|
|
102
|
+
});
|
|
103
|
+
return await response.json();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var createClient = (options) => new Entry(options);
|
|
107
|
+
var AgentGateway = Entry;
|
|
108
|
+
var AgentGatewayError = EntryError;
|
|
109
|
+
var ATGError = EntryError;
|
|
110
|
+
var index_default = Entry;
|
|
111
|
+
export {
|
|
112
|
+
ATGError,
|
|
113
|
+
AgentGateway,
|
|
114
|
+
AgentGatewayError,
|
|
115
|
+
Entry,
|
|
116
|
+
EntryError,
|
|
117
|
+
createClient,
|
|
118
|
+
index_default as default
|
|
119
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@entrys/client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript client for Entrys - the entry point for agent tool calls",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
21
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
22
|
+
"prepublishOnly": "pnpm build"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"entrys",
|
|
26
|
+
"agent",
|
|
27
|
+
"ai",
|
|
28
|
+
"tool",
|
|
29
|
+
"gateway",
|
|
30
|
+
"sdk",
|
|
31
|
+
"llm",
|
|
32
|
+
"security"
|
|
33
|
+
],
|
|
34
|
+
"author": "Treadie, Inc",
|
|
35
|
+
"license": "FSL-1.1-MIT",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/treadiehq/entrys.git",
|
|
39
|
+
"directory": "packages/client"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://entrys.co",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/treadiehq/entrys/issues"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"tsup": "^8.0.1",
|
|
50
|
+
"typescript": "^5.3.3"
|
|
51
|
+
}
|
|
52
|
+
}
|