@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
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ToolSchema } from "../types.js";
|
|
2
|
+
import { type Provider, type ToolCall, type ToolResultOptions } from "./base.js";
|
|
3
|
+
/** OpenAI function definition — the wire format owned here, no `openai` dep. */
|
|
4
|
+
export interface OpenAIFunctionDef {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
parameters: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
/** Passes directly into `openai.chat.completions.create({ tools })`. */
|
|
10
|
+
export interface OpenAIToolDef {
|
|
11
|
+
type: "function";
|
|
12
|
+
function: OpenAIFunctionDef;
|
|
13
|
+
}
|
|
14
|
+
export declare class OpenAIProvider implements Provider {
|
|
15
|
+
readonly name = "openai";
|
|
16
|
+
wrapTool(canonical: ToolSchema): OpenAIToolDef;
|
|
17
|
+
wrapTools(canonicals: ToolSchema[]): OpenAIToolDef[];
|
|
18
|
+
parseToolCalls(llmResponse: unknown): ToolCall[];
|
|
19
|
+
formatToolResult(call: ToolCall, options: ToolResultOptions): unknown;
|
|
20
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { get } from "./base.js";
|
|
2
|
+
export class OpenAIProvider {
|
|
3
|
+
name = "openai";
|
|
4
|
+
wrapTool(canonical) {
|
|
5
|
+
return {
|
|
6
|
+
type: "function",
|
|
7
|
+
function: {
|
|
8
|
+
name: canonical.toolSlug,
|
|
9
|
+
description: canonical.description ?? "",
|
|
10
|
+
parameters: canonical.inputSchema ?? {},
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
wrapTools(canonicals) {
|
|
15
|
+
return canonicals.map((c) => this.wrapTool(c));
|
|
16
|
+
}
|
|
17
|
+
parseToolCalls(llmResponse) {
|
|
18
|
+
const choices = get(llmResponse, "choices") ?? [];
|
|
19
|
+
const message = choices.length ? get(choices[0], "message") : undefined;
|
|
20
|
+
const rawCalls = get(message, "tool_calls") ?? [];
|
|
21
|
+
return rawCalls.map((raw) => {
|
|
22
|
+
const fn = get(raw, "function");
|
|
23
|
+
const args = get(fn, "arguments");
|
|
24
|
+
return {
|
|
25
|
+
id: String(get(raw, "id") ?? ""),
|
|
26
|
+
name: String(get(fn, "name") ?? ""),
|
|
27
|
+
arguments: typeof args === "string"
|
|
28
|
+
? JSON.parse(args)
|
|
29
|
+
: (args ?? {}),
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
formatToolResult(call, options) {
|
|
34
|
+
const content = options.error != null ? { error: options.error } : options.output;
|
|
35
|
+
return { role: "tool", tool_call_id: call.id, content: JSON.stringify(content) };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applications resource — discover connector apps and their detail.
|
|
3
|
+
*
|
|
4
|
+
* `list` auto-paginates the catalog (optionally filtered by free-text `search`
|
|
5
|
+
* or `available`), sliced to `limit`. `get` returns the full detail for one app,
|
|
6
|
+
* including its authentication methods.
|
|
7
|
+
*/
|
|
8
|
+
import { type ApplicationDetailDto, type ApplicationDto } from "@engini/client";
|
|
9
|
+
import { type Transport } from "../http.js";
|
|
10
|
+
/** Options for `client.applications.list(...)`. */
|
|
11
|
+
export interface ApplicationsListOptions {
|
|
12
|
+
search?: string;
|
|
13
|
+
available?: boolean;
|
|
14
|
+
limit?: number;
|
|
15
|
+
}
|
|
16
|
+
/** Minimal client surface this resource needs (satisfied by `Engini`). */
|
|
17
|
+
export interface ApplicationsClient {
|
|
18
|
+
_transport: Transport;
|
|
19
|
+
}
|
|
20
|
+
export declare class ApplicationsResource {
|
|
21
|
+
private readonly client;
|
|
22
|
+
constructor(client: ApplicationsClient);
|
|
23
|
+
list(options?: ApplicationsListOptions): Promise<ApplicationDto[]>;
|
|
24
|
+
get(slug: string): Promise<ApplicationDetailDto>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applications resource — discover connector apps and their detail.
|
|
3
|
+
*
|
|
4
|
+
* `list` auto-paginates the catalog (optionally filtered by free-text `search`
|
|
5
|
+
* or `available`), sliced to `limit`. `get` returns the full detail for one app,
|
|
6
|
+
* including its authentication methods.
|
|
7
|
+
*/
|
|
8
|
+
import { applicationsGetApplication, applicationsListApplications, } from "@engini/client";
|
|
9
|
+
import { call } from "../http.js";
|
|
10
|
+
import { collect, paginate } from "../pagination.js";
|
|
11
|
+
export class ApplicationsResource {
|
|
12
|
+
client;
|
|
13
|
+
constructor(client) {
|
|
14
|
+
this.client = client;
|
|
15
|
+
}
|
|
16
|
+
async list(options = {}) {
|
|
17
|
+
const transport = this.client._transport;
|
|
18
|
+
const items = await collect(paginate((offset, top) => call(applicationsListApplications, {
|
|
19
|
+
client: transport,
|
|
20
|
+
query: { search: options.search, available: options.available, offset, top },
|
|
21
|
+
})));
|
|
22
|
+
return options.limit !== undefined ? items.slice(0, options.limit) : items;
|
|
23
|
+
}
|
|
24
|
+
async get(slug) {
|
|
25
|
+
return call(applicationsGetApplication, {
|
|
26
|
+
client: this.client._transport,
|
|
27
|
+
path: { slug },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Auth resource — identity of the authenticated caller. */
|
|
2
|
+
import { type WhoAmIResponse } from "@engini/client";
|
|
3
|
+
import { type Transport } from "../http.js";
|
|
4
|
+
/** Minimal client surface this resource needs (satisfied by `Engini`). */
|
|
5
|
+
export interface AuthClient {
|
|
6
|
+
_transport: Transport;
|
|
7
|
+
}
|
|
8
|
+
export declare class AuthResource {
|
|
9
|
+
private readonly client;
|
|
10
|
+
constructor(client: AuthClient);
|
|
11
|
+
whoami(): Promise<WhoAmIResponse>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Auth resource — identity of the authenticated caller. */
|
|
2
|
+
import { authWhoAmI } from "@engini/client";
|
|
3
|
+
import { call } from "../http.js";
|
|
4
|
+
export class AuthResource {
|
|
5
|
+
client;
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
async whoami() {
|
|
10
|
+
return call(authWhoAmI, { client: this.client._transport });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Connections resource — listing, defaults, and name→id resolution. */
|
|
2
|
+
import { type ConnectionPublicDetail, type ConnectionPublicListItem, type DefaultConnectionDto } from "@engini/client";
|
|
3
|
+
import { type Transport } from "../http.js";
|
|
4
|
+
/** Minimal client surface this resource needs (satisfied by `Engini`). */
|
|
5
|
+
export interface ConnectionsClient {
|
|
6
|
+
_transport: Transport;
|
|
7
|
+
}
|
|
8
|
+
export declare class ConnectionsResource {
|
|
9
|
+
private readonly client;
|
|
10
|
+
constructor(client: ConnectionsClient);
|
|
11
|
+
list(application?: string): Promise<ConnectionPublicListItem[]>;
|
|
12
|
+
get(connectionId: number): Promise<ConnectionPublicDetail>;
|
|
13
|
+
defaults(): Promise<DefaultConnectionDto[]>;
|
|
14
|
+
setDefault(connectionId: number): Promise<unknown>;
|
|
15
|
+
clearDefault(application: string): Promise<unknown>;
|
|
16
|
+
resolve(application: string, name: string): Promise<number>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Connections resource — listing, defaults, and name→id resolution. */
|
|
2
|
+
import { connectionsGetConnection, connectionsGetConnections, connectionsGetDefaultConnections, connectionsSetDefaultConnection, connectionsClearDefaultConnection, } from "@engini/client";
|
|
3
|
+
import { call } from "../http.js";
|
|
4
|
+
import { paginate, collect } from "../pagination.js";
|
|
5
|
+
import { EnginiConnectionError, EnginiToolsetError } from "../errors.js";
|
|
6
|
+
export class ConnectionsResource {
|
|
7
|
+
client;
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
}
|
|
11
|
+
async list(application) {
|
|
12
|
+
const transport = this.client._transport;
|
|
13
|
+
return collect(paginate((offset, top) => call(connectionsGetConnections, {
|
|
14
|
+
client: transport,
|
|
15
|
+
query: { applicationSlug: application, offset, top },
|
|
16
|
+
}), { top: 25 }));
|
|
17
|
+
}
|
|
18
|
+
async get(connectionId) {
|
|
19
|
+
return call(connectionsGetConnection, {
|
|
20
|
+
client: this.client._transport,
|
|
21
|
+
path: { connectionId },
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async defaults() {
|
|
25
|
+
const res = await call(connectionsGetDefaultConnections, { client: this.client._transport });
|
|
26
|
+
return res.items ?? [];
|
|
27
|
+
}
|
|
28
|
+
async setDefault(connectionId) {
|
|
29
|
+
return call(connectionsSetDefaultConnection, {
|
|
30
|
+
client: this.client._transport,
|
|
31
|
+
path: { connectionId },
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async clearDefault(application) {
|
|
35
|
+
for (const d of await this.defaults()) {
|
|
36
|
+
if (d.applicationSlug === application) {
|
|
37
|
+
return call(connectionsClearDefaultConnection, {
|
|
38
|
+
client: this.client._transport,
|
|
39
|
+
path: { connectionId: d.connectionId },
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
throw new EnginiConnectionError(`No default connection for application '${application}'.`);
|
|
44
|
+
}
|
|
45
|
+
async resolve(application, name) {
|
|
46
|
+
const transport = this.client._transport;
|
|
47
|
+
const all = await collect(paginate((offset, top) => call(connectionsGetConnections, {
|
|
48
|
+
client: transport,
|
|
49
|
+
query: { applicationSlug: application, name, offset, top },
|
|
50
|
+
}), { top: 25 }));
|
|
51
|
+
const matches = all.filter((c) => c.connectionName === name);
|
|
52
|
+
if (matches.length === 0) {
|
|
53
|
+
throw new EnginiConnectionError(`No connection named '${name}' for application '${application}'.`);
|
|
54
|
+
}
|
|
55
|
+
if (matches.length > 1) {
|
|
56
|
+
throw new EnginiToolsetError(`Ambiguous connection name '${name}' for '${application}': ${matches.length} matches.`);
|
|
57
|
+
}
|
|
58
|
+
return matches[0].connectionId;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ToolsResource } from "./tools.js";
|
|
2
|
+
export type { ToolsGetOptions, ToolsExecuteOptions } from "./tools.js";
|
|
3
|
+
export { ConnectionsResource } from "./connections.js";
|
|
4
|
+
export { ToolsetsResource } from "./toolsets.js";
|
|
5
|
+
export { ApplicationsResource } from "./applications.js";
|
|
6
|
+
export type { ApplicationsListOptions } from "./applications.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Transport } from "../http.js";
|
|
2
|
+
import type { Filter, Sort, ToolExecuteResult, ToolSchema } from "../types.js";
|
|
3
|
+
/** Minimal client surface this resource needs (satisfied by `Engini`). */
|
|
4
|
+
export interface ToolsClient {
|
|
5
|
+
_transport: Transport;
|
|
6
|
+
_toolCache: Map<string, ToolSchema>;
|
|
7
|
+
}
|
|
8
|
+
/** Options for `client.tools.get(...)`. */
|
|
9
|
+
export interface ToolsGetOptions {
|
|
10
|
+
applications?: string[];
|
|
11
|
+
tools?: string[];
|
|
12
|
+
search?: string;
|
|
13
|
+
scopes?: string[];
|
|
14
|
+
limit?: number;
|
|
15
|
+
}
|
|
16
|
+
/** Options for `client.tools.execute(...)`. */
|
|
17
|
+
export interface ToolsExecuteOptions {
|
|
18
|
+
connectionId?: number;
|
|
19
|
+
toolsetId?: string;
|
|
20
|
+
applicationSlug?: string;
|
|
21
|
+
filters?: Filter[];
|
|
22
|
+
sort?: Sort[];
|
|
23
|
+
top?: number;
|
|
24
|
+
offset?: number;
|
|
25
|
+
}
|
|
26
|
+
export declare class ToolsResource {
|
|
27
|
+
private readonly client;
|
|
28
|
+
constructor(client: ToolsClient);
|
|
29
|
+
get(options?: ToolsGetOptions): Promise<ToolSchema[]>;
|
|
30
|
+
getOne(toolSlug: string, applicationSlug?: string): Promise<ToolSchema>;
|
|
31
|
+
execute(toolSlug: string, args?: Record<string, unknown>, options?: ToolsExecuteOptions): Promise<ToolExecuteResult>;
|
|
32
|
+
private gate;
|
|
33
|
+
private discoverSlugs;
|
|
34
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools resource — discovery, canonical schema retrieval, and execution.
|
|
3
|
+
*
|
|
4
|
+
* `get` returns canonical `ToolSchema` (== `ToolDetailDto`) objects. Only the
|
|
5
|
+
* detail endpoint carries `inputSchema` + `supports*`, so `get` lists tools
|
|
6
|
+
* then fetches detail per slug (an N+1), caching each detail on the client so
|
|
7
|
+
* `execute` can auto-fill `applicationSlug` and gate advanced kwargs.
|
|
8
|
+
*/
|
|
9
|
+
import { toolsListTools, toolsGetTool, toolsExecuteTool } from "@engini/client";
|
|
10
|
+
import { call } from "../http.js";
|
|
11
|
+
import { paginate, collect } from "../pagination.js";
|
|
12
|
+
import { EnginiToolExecutionError, EnginiValidationError } from "../errors.js";
|
|
13
|
+
export class ToolsResource {
|
|
14
|
+
client;
|
|
15
|
+
constructor(client) {
|
|
16
|
+
this.client = client;
|
|
17
|
+
}
|
|
18
|
+
async get(options = {}) {
|
|
19
|
+
let pairs;
|
|
20
|
+
if (options.tools && options.tools.length) {
|
|
21
|
+
pairs = options.tools.map((slug) => [slug, undefined]);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
pairs = await this.discoverSlugs(options.applications, options.search);
|
|
25
|
+
}
|
|
26
|
+
if (options.limit !== undefined)
|
|
27
|
+
pairs = pairs.slice(0, options.limit);
|
|
28
|
+
return Promise.all(pairs.map(([slug, app]) => this.getOne(slug, app)));
|
|
29
|
+
}
|
|
30
|
+
async getOne(toolSlug, applicationSlug) {
|
|
31
|
+
const cached = this.client._toolCache.get(toolSlug);
|
|
32
|
+
if (cached)
|
|
33
|
+
return cached;
|
|
34
|
+
const detail = await call(toolsGetTool, {
|
|
35
|
+
client: this.client._transport,
|
|
36
|
+
path: { toolSlug },
|
|
37
|
+
query: applicationSlug !== undefined ? { applicationSlug } : undefined,
|
|
38
|
+
});
|
|
39
|
+
this.client._toolCache.set(toolSlug, detail);
|
|
40
|
+
return detail;
|
|
41
|
+
}
|
|
42
|
+
async execute(toolSlug, args = {}, options = {}) {
|
|
43
|
+
const cached = this.client._toolCache.get(toolSlug);
|
|
44
|
+
let applicationSlug = options.applicationSlug;
|
|
45
|
+
if (applicationSlug === undefined && cached)
|
|
46
|
+
applicationSlug = cached.applicationSlug;
|
|
47
|
+
// The tool inputSchema flattens connector fields and the request-level knobs
|
|
48
|
+
// into one object, so split the LLM's args back out: hoist Filters/Sorts/
|
|
49
|
+
// SelectTop/SelectOffset to the top level and flatten a Fields list into the
|
|
50
|
+
// fields dict. Explicit options win.
|
|
51
|
+
const norm = normalizeExecuteArgs(args);
|
|
52
|
+
const merged = {
|
|
53
|
+
filters: options.filters ?? norm.filters,
|
|
54
|
+
sort: options.sort ?? norm.sort,
|
|
55
|
+
top: options.top ?? norm.top,
|
|
56
|
+
offset: options.offset ?? norm.offset,
|
|
57
|
+
};
|
|
58
|
+
if (cached)
|
|
59
|
+
this.gate(cached, merged);
|
|
60
|
+
const toolsetId = options.connectionId === undefined ? options.toolsetId : undefined;
|
|
61
|
+
const response = await call(toolsExecuteTool, {
|
|
62
|
+
client: this.client._transport,
|
|
63
|
+
path: { toolSlug },
|
|
64
|
+
query: {
|
|
65
|
+
applicationSlug,
|
|
66
|
+
toolsetId,
|
|
67
|
+
connectionId: options.connectionId,
|
|
68
|
+
},
|
|
69
|
+
body: {
|
|
70
|
+
fields: norm.fields,
|
|
71
|
+
filters: merged.filters,
|
|
72
|
+
sort: merged.sort,
|
|
73
|
+
top: merged.top,
|
|
74
|
+
offset: merged.offset,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
if (!response.isSuccess) {
|
|
78
|
+
throw new EnginiToolExecutionError(response.errorMessage ?? null, {
|
|
79
|
+
executionInfo: response.executionInfo ?? null,
|
|
80
|
+
historyId: response.historyId ?? null,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
output: response.output ?? null,
|
|
85
|
+
historyId: response.historyId ?? null,
|
|
86
|
+
executionInfo: response.executionInfo ?? null,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
gate(schema, o) {
|
|
90
|
+
if (o.filters?.length && !schema.supportsFilters) {
|
|
91
|
+
throw new EnginiValidationError(`${schema.toolSlug} does not support filters.`);
|
|
92
|
+
}
|
|
93
|
+
if (o.sort?.length && !schema.supportsSort) {
|
|
94
|
+
throw new EnginiValidationError(`${schema.toolSlug} does not support sort.`);
|
|
95
|
+
}
|
|
96
|
+
if ((o.top !== undefined || o.offset !== undefined) && !schema.supportsTopOffset) {
|
|
97
|
+
throw new EnginiValidationError(`${schema.toolSlug} does not support top/offset.`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async discoverSlugs(applications, search) {
|
|
101
|
+
const transport = this.client._transport;
|
|
102
|
+
const apps = applications?.length ? applications : [undefined];
|
|
103
|
+
const pairs = [];
|
|
104
|
+
for (const app of apps) {
|
|
105
|
+
const items = await collect(paginate((offset, top) => call(toolsListTools, {
|
|
106
|
+
client: transport,
|
|
107
|
+
query: { applicationSlug: app, search, offset, top },
|
|
108
|
+
})));
|
|
109
|
+
for (const item of items)
|
|
110
|
+
pairs.push([item.toolSlug, item.applicationSlug]);
|
|
111
|
+
}
|
|
112
|
+
return pairs;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Split a flat LLM `arguments` dict into the execute request's shape. Engini's
|
|
117
|
+
* tool `inputSchema` flattens the connector's fields together with the
|
|
118
|
+
* request-level knobs, so route each back: hoist `Filters`/`Sorts`/`SelectTop`/
|
|
119
|
+
* `SelectOffset` to the top level (translated to the request wire shape), flatten
|
|
120
|
+
* a `Fields` list of `{FieldName, Value}` into the `fields` dict, and keep every
|
|
121
|
+
* other key (e.g. `objectType`) as a `fields` entry.
|
|
122
|
+
*/
|
|
123
|
+
function normalizeExecuteArgs(args) {
|
|
124
|
+
const fields = {};
|
|
125
|
+
let filters;
|
|
126
|
+
let sort;
|
|
127
|
+
let top;
|
|
128
|
+
let offset;
|
|
129
|
+
for (const [key, value] of Object.entries(args)) {
|
|
130
|
+
if (key === "Filters") {
|
|
131
|
+
filters = (value ?? []).map((f) => ({
|
|
132
|
+
fieldName: f.FieldName,
|
|
133
|
+
operator: f.Operator,
|
|
134
|
+
value: f.Value,
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
else if (key === "Sorts") {
|
|
138
|
+
sort = (value ?? []).map((s) => ({
|
|
139
|
+
fieldName: s.FieldName,
|
|
140
|
+
orderDirection: String(s.Order).toLowerCase() === "asc" ? 1 : -1,
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
else if (key === "SelectTop") {
|
|
144
|
+
top = value;
|
|
145
|
+
}
|
|
146
|
+
else if (key === "SelectOffset") {
|
|
147
|
+
offset = value;
|
|
148
|
+
}
|
|
149
|
+
else if (key === "Fields" && Array.isArray(value)) {
|
|
150
|
+
for (const item of value) {
|
|
151
|
+
if (item && typeof item === "object" && "FieldName" in item && item.FieldName) {
|
|
152
|
+
fields[item.FieldName] = item.Value;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
fields[key] = value;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return { fields, filters, sort, top, offset };
|
|
161
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Toolsets resource — server-persisted toolset CRUD. */
|
|
2
|
+
import { type ToolsetDto, type ToolsetConnectionRequest } from "@engini/client";
|
|
3
|
+
import { type Transport } from "../http.js";
|
|
4
|
+
/** Minimal client surface this resource needs (satisfied by `Engini`). */
|
|
5
|
+
export interface ToolsetsClient {
|
|
6
|
+
_transport: Transport;
|
|
7
|
+
}
|
|
8
|
+
export declare class ToolsetsResource {
|
|
9
|
+
private readonly client;
|
|
10
|
+
constructor(client: ToolsetsClient);
|
|
11
|
+
list(): Promise<ToolsetDto[]>;
|
|
12
|
+
get(toolsetId: string): Promise<ToolsetDto>;
|
|
13
|
+
delete(toolsetId: string): Promise<unknown>;
|
|
14
|
+
create(params: {
|
|
15
|
+
name: string;
|
|
16
|
+
connections: ToolsetConnectionRequest[];
|
|
17
|
+
workflows?: string[];
|
|
18
|
+
}): Promise<ToolsetDto>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Toolsets resource — server-persisted toolset CRUD. */
|
|
2
|
+
import { toolsetsListToolsets, toolsetsGetToolset, toolsetsDeleteToolset, toolsetsCreateToolset, } from "@engini/client";
|
|
3
|
+
import { call } from "../http.js";
|
|
4
|
+
import { paginate, collect } from "../pagination.js";
|
|
5
|
+
import { EnginiNotFoundError, EnginiToolsetError } from "../errors.js";
|
|
6
|
+
export class ToolsetsResource {
|
|
7
|
+
client;
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
}
|
|
11
|
+
async list() {
|
|
12
|
+
const transport = this.client._transport;
|
|
13
|
+
return collect(paginate((offset, top) => call(toolsetsListToolsets, { client: transport, query: { offset, top } })));
|
|
14
|
+
}
|
|
15
|
+
async get(toolsetId) {
|
|
16
|
+
try {
|
|
17
|
+
return await call(toolsetsGetToolset, {
|
|
18
|
+
client: this.client._transport,
|
|
19
|
+
path: { toolsetId },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
if (err instanceof EnginiNotFoundError) {
|
|
24
|
+
throw new EnginiToolsetError(`Unknown toolset id '${toolsetId}'.`);
|
|
25
|
+
}
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async delete(toolsetId) {
|
|
30
|
+
return call(toolsetsDeleteToolset, {
|
|
31
|
+
client: this.client._transport,
|
|
32
|
+
path: { toolsetId },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
async create(params) {
|
|
36
|
+
return call(toolsetsCreateToolset, {
|
|
37
|
+
client: this.client._transport,
|
|
38
|
+
body: { name: params.name, connections: params.connections, workflows: params.workflows },
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `Toolset` object — ergonomic application→connection binding + agent loop.
|
|
3
|
+
* Built locally via `client.toolset({ connections })` (no I/O until used) or
|
|
4
|
+
* loaded via `client.toolset({ toolsetId })`.
|
|
5
|
+
*/
|
|
6
|
+
import type { ToolsetDto, ToolsetConnectionRequest } from "@engini/client";
|
|
7
|
+
import type { Filter, Sort, ToolExecuteResult, ToolSchema } from "./types.js";
|
|
8
|
+
import type { ToolCall } from "./providers/base.js";
|
|
9
|
+
/** Connection binding value: pin an id (number), a connection name (string), or server default (null). */
|
|
10
|
+
export type ConnectionBinding = number | string | null;
|
|
11
|
+
/** Higher-level client surface the Toolset depends on (satisfied by `Engini`). */
|
|
12
|
+
export interface ToolsetClient {
|
|
13
|
+
tools: {
|
|
14
|
+
get(options: {
|
|
15
|
+
applications?: string[];
|
|
16
|
+
tools?: string[];
|
|
17
|
+
}): Promise<ToolSchema[]>;
|
|
18
|
+
getOne(slug: string): Promise<ToolSchema>;
|
|
19
|
+
execute(slug: string, args: Record<string, unknown>, options: {
|
|
20
|
+
connectionId?: number;
|
|
21
|
+
toolsetId?: string;
|
|
22
|
+
applicationSlug?: string;
|
|
23
|
+
filters?: Filter[];
|
|
24
|
+
sort?: Sort[];
|
|
25
|
+
top?: number;
|
|
26
|
+
offset?: number;
|
|
27
|
+
}): Promise<ToolExecuteResult>;
|
|
28
|
+
};
|
|
29
|
+
connections: {
|
|
30
|
+
resolve(application: string, name: string): Promise<number>;
|
|
31
|
+
defaults(): Promise<Array<{
|
|
32
|
+
applicationSlug: string;
|
|
33
|
+
connectionId: number;
|
|
34
|
+
}>>;
|
|
35
|
+
};
|
|
36
|
+
toolsets: {
|
|
37
|
+
create(params: {
|
|
38
|
+
name: string;
|
|
39
|
+
connections: ToolsetConnectionRequest[];
|
|
40
|
+
workflows?: string[];
|
|
41
|
+
}): Promise<ToolsetDto>;
|
|
42
|
+
};
|
|
43
|
+
provider: {
|
|
44
|
+
wrapTools(schemas: ToolSchema[]): unknown[];
|
|
45
|
+
parseToolCalls(llmResponse: unknown): ToolCall[];
|
|
46
|
+
formatToolResult(call: ToolCall, options: {
|
|
47
|
+
output?: unknown;
|
|
48
|
+
error?: string | null;
|
|
49
|
+
}): unknown;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface ToolsetExecuteOptions {
|
|
53
|
+
connectionId?: number;
|
|
54
|
+
filters?: Filter[];
|
|
55
|
+
sort?: Sort[];
|
|
56
|
+
top?: number;
|
|
57
|
+
offset?: number;
|
|
58
|
+
}
|
|
59
|
+
export declare class Toolset {
|
|
60
|
+
private readonly client;
|
|
61
|
+
id: string | null;
|
|
62
|
+
private readonly connections;
|
|
63
|
+
private readonly toolFilter;
|
|
64
|
+
constructor(client: ToolsetClient, params: {
|
|
65
|
+
connections?: Record<string, ConnectionBinding>;
|
|
66
|
+
tools?: string[];
|
|
67
|
+
id?: string | null;
|
|
68
|
+
});
|
|
69
|
+
static fromDto(client: ToolsetClient, dto: ToolsetDto): Toolset;
|
|
70
|
+
tools(options?: {
|
|
71
|
+
format?: "provider" | "canonical";
|
|
72
|
+
}): Promise<unknown[]>;
|
|
73
|
+
execute(toolSlug: string, args?: Record<string, unknown>, options?: ToolsetExecuteOptions): Promise<ToolExecuteResult>;
|
|
74
|
+
handleToolCalls(llmResponse: unknown): Promise<unknown[]>;
|
|
75
|
+
save(params: {
|
|
76
|
+
name: string;
|
|
77
|
+
}): Promise<string>;
|
|
78
|
+
private resolveForSave;
|
|
79
|
+
private toolSlugsForApp;
|
|
80
|
+
}
|