@engini/sdk 0.0.0 → 0.3.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.
@@ -0,0 +1,128 @@
1
+ import { EnginiClientError, EnginiConnectionError, EnginiToolExecutionError, EnginiValidationError, } from "./errors.js";
2
+ export class Toolset {
3
+ client;
4
+ id;
5
+ connections;
6
+ toolFilter;
7
+ constructor(client, params) {
8
+ this.client = client;
9
+ this.connections = { ...(params.connections ?? {}) };
10
+ this.toolFilter = params.tools && params.tools.length ? [...params.tools] : null;
11
+ this.id = params.id ?? null;
12
+ }
13
+ static fromDto(client, dto) {
14
+ const connections = {};
15
+ const toolSlugs = [];
16
+ for (const conn of dto.connections) {
17
+ connections[conn.applicationSlug] = conn.connectionId;
18
+ toolSlugs.push(...conn.toolSlugs);
19
+ }
20
+ return new Toolset(client, {
21
+ connections,
22
+ tools: toolSlugs.length ? toolSlugs : undefined,
23
+ id: dto.toolsetId,
24
+ });
25
+ }
26
+ async tools(options = {}) {
27
+ const format = options.format ?? "provider";
28
+ const applications = Object.keys(this.connections);
29
+ const schemas = await this.client.tools.get({
30
+ applications: applications.length ? applications : undefined,
31
+ tools: this.toolFilter ?? undefined,
32
+ });
33
+ if (format === "canonical")
34
+ return schemas;
35
+ if (format === "provider")
36
+ return this.client.provider.wrapTools(schemas);
37
+ throw new EnginiClientError(`Unknown tools format '${format}'.`);
38
+ }
39
+ async execute(toolSlug, args = {}, options = {}) {
40
+ if (this.id !== null) {
41
+ return this.client.tools.execute(toolSlug, args, {
42
+ connectionId: options.connectionId,
43
+ toolsetId: options.connectionId === undefined ? this.id : undefined,
44
+ filters: options.filters,
45
+ sort: options.sort,
46
+ top: options.top,
47
+ offset: options.offset,
48
+ });
49
+ }
50
+ const schema = await this.client.tools.getOne(toolSlug);
51
+ const application = schema.applicationSlug;
52
+ let resolved = options.connectionId;
53
+ if (resolved === undefined) {
54
+ const binding = this.connections[application];
55
+ if (typeof binding === "number")
56
+ resolved = binding;
57
+ else if (typeof binding === "string")
58
+ resolved = await this.client.connections.resolve(application, binding);
59
+ // null / absent → leave undefined (server default)
60
+ }
61
+ return this.client.tools.execute(toolSlug, args, {
62
+ connectionId: resolved,
63
+ applicationSlug: application,
64
+ filters: options.filters,
65
+ sort: options.sort,
66
+ top: options.top,
67
+ offset: options.offset,
68
+ });
69
+ }
70
+ async handleToolCalls(llmResponse) {
71
+ const provider = this.client.provider;
72
+ const results = [];
73
+ for (const call of provider.parseToolCalls(llmResponse)) {
74
+ try {
75
+ const result = await this.execute(call.name, call.arguments);
76
+ results.push(provider.formatToolResult(call, { output: result.output }));
77
+ }
78
+ catch (err) {
79
+ if (err instanceof EnginiToolExecutionError ||
80
+ err instanceof EnginiConnectionError ||
81
+ err instanceof EnginiValidationError) {
82
+ const message = `${err.name}: ${err.message}`;
83
+ results.push(provider.formatToolResult(call, { error: message }));
84
+ }
85
+ else {
86
+ throw err; // systemic (auth/network/server) propagates
87
+ }
88
+ }
89
+ }
90
+ return results;
91
+ }
92
+ async save(params) {
93
+ const connectionRequests = [];
94
+ for (const [application, binding] of Object.entries(this.connections)) {
95
+ const connectionId = await this.resolveForSave(application, binding);
96
+ const toolSlugs = await this.toolSlugsForApp(application);
97
+ connectionRequests.push({
98
+ connectionId,
99
+ toolSlugs: toolSlugs && toolSlugs.length ? toolSlugs : undefined,
100
+ });
101
+ }
102
+ const dto = await this.client.toolsets.create({ name: params.name, connections: connectionRequests });
103
+ this.id = dto.toolsetId;
104
+ return dto.toolsetId;
105
+ }
106
+ async resolveForSave(application, binding) {
107
+ if (typeof binding === "number")
108
+ return binding;
109
+ if (typeof binding === "string")
110
+ return this.client.connections.resolve(application, binding);
111
+ for (const d of await this.client.connections.defaults()) {
112
+ if (d.applicationSlug === application)
113
+ return d.connectionId;
114
+ }
115
+ throw new EnginiConnectionError(`No default connection for '${application}'; cannot save toolset.`);
116
+ }
117
+ async toolSlugsForApp(application) {
118
+ if (!this.toolFilter)
119
+ return null;
120
+ const subset = [];
121
+ for (const slug of this.toolFilter) {
122
+ const schema = await this.client.tools.getOne(slug);
123
+ if (schema.applicationSlug === application)
124
+ subset.push(slug);
125
+ }
126
+ return subset.length ? subset : null;
127
+ }
128
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Canonical, provider-agnostic tool schema and execution result types.
3
+ * Bound to the autogen `@engini/client` models — the SDK's public surface.
4
+ */
5
+ import type { ToolDetailDto, ActivityCondition, ActivitySort, ApplicationDto, ApplicationDetailDto, ConnectionPublicListItem, ConnectionPublicDetail, WhoAmIResponse } from "@engini/client";
6
+ /** Canonical tool schema (== client `ToolDetailDto`; carries `inputSchema` + `supports*`). */
7
+ export type ToolSchema = ToolDetailDto;
8
+ /** A connector application summary (== client `ApplicationDto`). */
9
+ export type Application = ApplicationDto;
10
+ /** Full application detail incl. auth methods (== client `ApplicationDetailDto`). */
11
+ export type ApplicationDetail = ApplicationDetailDto;
12
+ /** A connection summary (== client `ConnectionPublicListItem`). */
13
+ export type Connection = ConnectionPublicListItem;
14
+ /** Full connection detail (== client `ConnectionPublicDetail`). */
15
+ export type ConnectionDetail = ConnectionPublicDetail;
16
+ /** Authenticated caller identity (== client `WhoAmIResponse`). */
17
+ export type WhoAmI = WhoAmIResponse;
18
+ /** Execute-time filter condition (gated by `supportsFilters`). */
19
+ export type Filter = ActivityCondition;
20
+ /** Execute-time sort directive (gated by `supportsSort`). */
21
+ export type Sort = ActivitySort;
22
+ /** Successful result of `tools.execute` / `Toolset.execute`. */
23
+ export interface ToolExecuteResult {
24
+ output: unknown;
25
+ historyId: number | null;
26
+ executionInfo: unknown;
27
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,11 +1,32 @@
1
1
  {
2
2
  "name": "@engini/sdk",
3
- "version": "0.0.0",
4
- "description": "Name reservation for the Engini SDK. Real releases follow.",
3
+ "version": "0.3.0",
4
+ "description": "Engini SDK — agent-first ergonomic layer over the Engini Public API",
5
5
  "license": "UNLICENSED",
6
- "homepage": "https://engini.io",
7
- "author": "Engini",
8
- "main": "index.js",
9
- "files": ["index.js", "README.md"],
10
- "publishConfig": { "access": "public" }
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/engini/engini-sdk",
15
+ "directory": "ts/packages/sdk"
16
+ },
17
+ "scripts": {
18
+ "typecheck": "tsc --noEmit",
19
+ "build": "tsc",
20
+ "test": "vitest run"
21
+ },
22
+ "dependencies": {
23
+ "@engini/client": ">=0.4.0 <0.5.0",
24
+ "undici": "^6.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^25.9.2",
28
+ "msw": "^2.6.0",
29
+ "typescript": "^5.5.0",
30
+ "vitest": "^2.1.0"
31
+ }
11
32
  }
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = { version: "0.0.0" };