@engini/sdk 0.5.1 → 0.6.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 CHANGED
@@ -51,6 +51,40 @@ const results = await toolset.handleToolCalls(llmResponse); // runs t
51
51
  `client.toolset(...)` builds a local toolset (no I/O until used) or loads a server one via
52
52
  `client.toolset({ toolsetId })`.
53
53
 
54
+ ## Files
55
+
56
+ Tools whose `inputSchema` marks a field `"format": "engini/file"` accept files. Wrap a file with
57
+ `File` and pass it as the field value — the SDK base64-encodes it into the
58
+ `{ base64_content, mime_type, filename }` wire shape. A field takes a single file or a list, per
59
+ the tool's schema.
60
+
61
+ ```ts
62
+ import { Engini, File } from "@engini/sdk";
63
+
64
+ await client.tools.execute(
65
+ "gmail_send_mail",
66
+ {
67
+ to: "alex@acme.com",
68
+ subject: "Reports",
69
+ body: "See attached.",
70
+ attachmentsarray: [File.fromPath("q3-report.pdf"), File.fromPath("chart.png")],
71
+ },
72
+ { connectionId },
73
+ );
74
+ ```
75
+
76
+ `File.fromPath` infers the filename + mime type; `File.fromBytes(data, { filename, mimeType })`
77
+ and `File.fromBase64(b64, { filename, mimeType })` cover in-memory content.
78
+
79
+ In the LLM loop an agent can't produce base64, so file fields are presented to it as string
80
+ fields. Register the files you'll allow and let the model reference one by key:
81
+
82
+ ```ts
83
+ const results = await toolset.handleToolCalls(llmResponse, {
84
+ files: { "q3-report.pdf": File.fromPath("q3-report.pdf") },
85
+ });
86
+ ```
87
+
54
88
  ## What this adds over the raw REST client
55
89
 
56
90
  Built on the autogenerated [`@engini/client`](https://www.npmjs.com/package/@engini/client), the
@@ -0,0 +1,69 @@
1
+ /** The `format` marker that flags a file field in a tool `inputSchema`. */
2
+ export declare const FILE_FORMAT = "engini/file";
3
+ /** The wire shape the execute endpoint expects for each file. */
4
+ export interface FileWire {
5
+ base64_content: string;
6
+ mime_type: string;
7
+ filename: string;
8
+ }
9
+ /**
10
+ * A file to attach to a tool execution. Construct with `File.fromPath`,
11
+ * `File.fromBytes`, or `File.fromBase64`; the SDK base64-encodes the content
12
+ * into the wire shape at execution time.
13
+ */
14
+ export declare class File {
15
+ readonly content: Uint8Array;
16
+ readonly filename: string;
17
+ readonly mimeType: string;
18
+ constructor(content: Uint8Array | string, filename: string, mimeType?: string);
19
+ /** Read a file from disk, inferring `filename` and (if not given) mime type. */
20
+ static fromPath(path: string, options?: {
21
+ mimeType?: string;
22
+ }): File;
23
+ /** Wrap in-memory bytes; `filename` and `mimeType` are caller-supplied. */
24
+ static fromBytes(data: Uint8Array | string, options: {
25
+ filename: string;
26
+ mimeType?: string;
27
+ }): File;
28
+ /** Wrap already-base64 content; decoded now so the encoding is validated once. */
29
+ static fromBase64(b64: string, options: {
30
+ filename: string;
31
+ mimeType?: string;
32
+ }): File;
33
+ /** The `{ base64_content, mime_type, filename }` object the API expects. */
34
+ toWire(): FileWire;
35
+ }
36
+ /**
37
+ * Recursively replace every `File` in `value` with its wire object. Pure:
38
+ * returns a new structure, never mutates the input.
39
+ */
40
+ export declare function encodeFileValues(value: unknown): unknown;
41
+ type FileKind = "single" | "list";
42
+ /** Map a schema's file field names to `"single"` | `"list"`. Tolerant of a non-object schema. */
43
+ export declare function fileFields(inputSchema: unknown): Record<string, FileKind>;
44
+ /**
45
+ * Check `File` values landed on file fields with matching cardinality. Only runs
46
+ * when the schema carries a usable `properties` map, and only inspects fields
47
+ * that are present and declared — the server stays the authority on the rest.
48
+ *
49
+ * @throws EnginiValidationError on wrong cardinality, or a `File` on a field the
50
+ * schema declares as non-file.
51
+ */
52
+ export declare function validateFiles(fields: Record<string, unknown>, inputSchema: unknown): void;
53
+ /**
54
+ * Rewrite `engini/file` properties into an LLM-presentable string shape: a
55
+ * string (single) or array-of-strings (list), so an LLM never sees a contentless
56
+ * file object — it supplies a reference key resolved by `resolveFileRefs`.
57
+ * Returns a deep copy.
58
+ */
59
+ export declare function rewriteFileSchema(inputSchema: unknown): unknown;
60
+ /**
61
+ * Swap string reference keys on file fields for their `File` (via `files`). Used
62
+ * in the LLM agent loop: the model fills a file field with a key string; this
63
+ * resolves it against the developer-supplied `files` registry. Values already a
64
+ * `File` or wire object pass through untouched.
65
+ *
66
+ * @throws EnginiValidationError if a reference key is absent from `files`.
67
+ */
68
+ export declare function resolveFileRefs(args: Record<string, unknown>, inputSchema: unknown, files: Record<string, File> | undefined): Record<string, unknown>;
69
+ export {};
package/dist/files.js ADDED
@@ -0,0 +1,253 @@
1
+ /**
2
+ * The `engini/file` format — the `File` helper and its (de)serialization.
3
+ *
4
+ * A tool `inputSchema` marks a file field with `"format": "engini/file"` — a
5
+ * single file (an object property) or a list of files (an array carrying the
6
+ * marker, optionally also on its `items`). On the wire each file is
7
+ * `{ base64_content, mime_type, filename }`.
8
+ *
9
+ * Translation is *value-driven*: `encodeFileValues` turns any `File` in an
10
+ * arguments tree into its wire object regardless of schema. When the schema is
11
+ * known, `validateFiles` checks cardinality and `rewriteFileSchema` rewrites
12
+ * file fields into an LLM-presentable string shape (an LLM can't produce
13
+ * base64, so it references a file by key — see `resolveFileRefs`).
14
+ *
15
+ * Mirror of the Python `engini._files` module.
16
+ */
17
+ import { readFileSync } from "node:fs";
18
+ import { basename, extname } from "node:path";
19
+ import { EnginiValidationError } from "./errors.js";
20
+ /** The `format` marker that flags a file field in a tool `inputSchema`. */
21
+ export const FILE_FORMAT = "engini/file";
22
+ const DEFAULT_MIME = "application/octet-stream";
23
+ const FILE_HINT = "provide the reference key of an available file";
24
+ const MIME_BY_EXT = {
25
+ ".txt": "text/plain",
26
+ ".md": "text/markdown",
27
+ ".csv": "text/csv",
28
+ ".json": "application/json",
29
+ ".xml": "application/xml",
30
+ ".html": "text/html",
31
+ ".htm": "text/html",
32
+ ".pdf": "application/pdf",
33
+ ".png": "image/png",
34
+ ".jpg": "image/jpeg",
35
+ ".jpeg": "image/jpeg",
36
+ ".gif": "image/gif",
37
+ ".webp": "image/webp",
38
+ ".svg": "image/svg+xml",
39
+ ".zip": "application/zip",
40
+ ".doc": "application/msword",
41
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
42
+ ".xls": "application/vnd.ms-excel",
43
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
44
+ ".ppt": "application/vnd.ms-powerpoint",
45
+ ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
46
+ };
47
+ function guessMime(filename) {
48
+ return MIME_BY_EXT[extname(filename).toLowerCase()] ?? DEFAULT_MIME;
49
+ }
50
+ function toBytes(data) {
51
+ return typeof data === "string" ? new TextEncoder().encode(data) : data;
52
+ }
53
+ /**
54
+ * A file to attach to a tool execution. Construct with `File.fromPath`,
55
+ * `File.fromBytes`, or `File.fromBase64`; the SDK base64-encodes the content
56
+ * into the wire shape at execution time.
57
+ */
58
+ export class File {
59
+ content;
60
+ filename;
61
+ mimeType;
62
+ constructor(content, filename, mimeType = DEFAULT_MIME) {
63
+ this.content = toBytes(content);
64
+ this.filename = filename;
65
+ this.mimeType = mimeType;
66
+ }
67
+ /** Read a file from disk, inferring `filename` and (if not given) mime type. */
68
+ static fromPath(path, options = {}) {
69
+ const data = readFileSync(path);
70
+ const filename = basename(path);
71
+ return new File(new Uint8Array(data), filename, options.mimeType ?? guessMime(filename));
72
+ }
73
+ /** Wrap in-memory bytes; `filename` and `mimeType` are caller-supplied. */
74
+ static fromBytes(data, options) {
75
+ return new File(data, options.filename, options.mimeType ?? DEFAULT_MIME);
76
+ }
77
+ /** Wrap already-base64 content; decoded now so the encoding is validated once. */
78
+ static fromBase64(b64, options) {
79
+ return new File(new Uint8Array(Buffer.from(b64, "base64")), options.filename, options.mimeType ?? DEFAULT_MIME);
80
+ }
81
+ /** The `{ base64_content, mime_type, filename }` object the API expects. */
82
+ toWire() {
83
+ return {
84
+ base64_content: Buffer.from(this.content).toString("base64"),
85
+ mime_type: this.mimeType,
86
+ filename: this.filename,
87
+ };
88
+ }
89
+ }
90
+ /**
91
+ * Recursively replace every `File` in `value` with its wire object. Pure:
92
+ * returns a new structure, never mutates the input.
93
+ */
94
+ export function encodeFileValues(value) {
95
+ if (value instanceof File)
96
+ return value.toWire();
97
+ if (Array.isArray(value))
98
+ return value.map((item) => encodeFileValues(item));
99
+ if (value && typeof value === "object") {
100
+ const out = {};
101
+ for (const [key, item] of Object.entries(value)) {
102
+ out[key] = encodeFileValues(item);
103
+ }
104
+ return out;
105
+ }
106
+ return value;
107
+ }
108
+ /**
109
+ * Classify one schema property as a file field. Engini marks a *list* of files
110
+ * as `{ type: "array", format: "engini/file", items: {...} }` — the marker sits
111
+ * on the array itself — so an array with the marker is a list. The marker also
112
+ * on `items` is accepted as a list for robustness.
113
+ */
114
+ function fileKind(prop) {
115
+ if (!prop || typeof prop !== "object")
116
+ return undefined;
117
+ const p = prop;
118
+ const items = p.items;
119
+ const itemsMarked = !!items && typeof items === "object" && items.format === FILE_FORMAT;
120
+ if (p.format === FILE_FORMAT)
121
+ return p.type === "array" ? "list" : "single";
122
+ if (itemsMarked)
123
+ return "list";
124
+ return undefined;
125
+ }
126
+ function properties(inputSchema) {
127
+ if (!inputSchema || typeof inputSchema !== "object")
128
+ return undefined;
129
+ const props = inputSchema.properties;
130
+ return props && typeof props === "object" ? props : undefined;
131
+ }
132
+ /** Map a schema's file field names to `"single"` | `"list"`. Tolerant of a non-object schema. */
133
+ export function fileFields(inputSchema) {
134
+ const props = properties(inputSchema);
135
+ if (!props)
136
+ return {};
137
+ const kinds = {};
138
+ for (const [name, prop] of Object.entries(props)) {
139
+ const kind = fileKind(prop);
140
+ if (kind)
141
+ kinds[name] = kind;
142
+ }
143
+ return kinds;
144
+ }
145
+ function containsFile(value) {
146
+ if (value instanceof File)
147
+ return true;
148
+ if (Array.isArray(value))
149
+ return value.some((item) => containsFile(item));
150
+ if (value && typeof value === "object") {
151
+ return Object.values(value).some((item) => containsFile(item));
152
+ }
153
+ return false;
154
+ }
155
+ /**
156
+ * Check `File` values landed on file fields with matching cardinality. Only runs
157
+ * when the schema carries a usable `properties` map, and only inspects fields
158
+ * that are present and declared — the server stays the authority on the rest.
159
+ *
160
+ * @throws EnginiValidationError on wrong cardinality, or a `File` on a field the
161
+ * schema declares as non-file.
162
+ */
163
+ export function validateFiles(fields, inputSchema) {
164
+ const props = properties(inputSchema);
165
+ if (!props)
166
+ return;
167
+ const kinds = fileFields(inputSchema);
168
+ for (const [name, value] of Object.entries(fields)) {
169
+ const kind = kinds[name];
170
+ if (kind === "single") {
171
+ if (Array.isArray(value)) {
172
+ throw new EnginiValidationError(`Field '${name}' expects a single file, got a list.`);
173
+ }
174
+ }
175
+ else if (kind === "list") {
176
+ if (!Array.isArray(value)) {
177
+ throw new EnginiValidationError(`Field '${name}' expects a list of files.`);
178
+ }
179
+ }
180
+ else if (name in props && containsFile(value)) {
181
+ throw new EnginiValidationError(`Field '${name}' is not a file field but received a File value.`);
182
+ }
183
+ }
184
+ }
185
+ function hint(description) {
186
+ if (typeof description === "string" && description)
187
+ return `${description} — ${FILE_HINT}`;
188
+ return FILE_HINT.charAt(0).toUpperCase() + FILE_HINT.slice(1) + ".";
189
+ }
190
+ /**
191
+ * Rewrite `engini/file` properties into an LLM-presentable string shape: a
192
+ * string (single) or array-of-strings (list), so an LLM never sees a contentless
193
+ * file object — it supplies a reference key resolved by `resolveFileRefs`.
194
+ * Returns a deep copy.
195
+ */
196
+ export function rewriteFileSchema(inputSchema) {
197
+ if (!inputSchema || typeof inputSchema !== "object")
198
+ return inputSchema;
199
+ const schema = structuredClone(inputSchema);
200
+ const props = schema.properties;
201
+ if (!props || typeof props !== "object")
202
+ return schema;
203
+ const propsObj = props;
204
+ for (const [name, prop] of Object.entries(propsObj)) {
205
+ const kind = fileKind(prop);
206
+ if (!kind)
207
+ continue;
208
+ const description = prop && typeof prop === "object" ? prop.description : undefined;
209
+ propsObj[name] =
210
+ kind === "list"
211
+ ? { type: "array", items: { type: "string" }, description: hint(description) }
212
+ : { type: "string", description: hint(description) };
213
+ }
214
+ return schema;
215
+ }
216
+ function lookupFile(value, files) {
217
+ if (value instanceof File || (value && typeof value === "object"))
218
+ return value;
219
+ if (typeof value === "string") {
220
+ if (!(value in files))
221
+ throw new EnginiValidationError(`Unknown file reference '${value}'.`);
222
+ return files[value];
223
+ }
224
+ return value;
225
+ }
226
+ /**
227
+ * Swap string reference keys on file fields for their `File` (via `files`). Used
228
+ * in the LLM agent loop: the model fills a file field with a key string; this
229
+ * resolves it against the developer-supplied `files` registry. Values already a
230
+ * `File` or wire object pass through untouched.
231
+ *
232
+ * @throws EnginiValidationError if a reference key is absent from `files`.
233
+ */
234
+ export function resolveFileRefs(args, inputSchema, files) {
235
+ if (!files || Object.keys(files).length === 0)
236
+ return args;
237
+ const kinds = fileFields(inputSchema);
238
+ if (Object.keys(kinds).length === 0)
239
+ return args;
240
+ const resolved = { ...args };
241
+ for (const [name, kind] of Object.entries(kinds)) {
242
+ if (!(name in resolved))
243
+ continue;
244
+ const value = resolved[name];
245
+ if (kind === "single") {
246
+ resolved[name] = lookupFile(value, files);
247
+ }
248
+ else if (Array.isArray(value)) {
249
+ resolved[name] = value.map((item) => lookupFile(item, files));
250
+ }
251
+ }
252
+ return resolved;
253
+ }
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@ export { ToolsResource, ConnectionsResource, ToolsetsResource, ApplicationsResou
8
8
  export type { ToolsGetOptions, ToolsExecuteOptions, ApplicationsListOptions } from "./resources/index.js";
9
9
  export { Toolset } from "./toolset.js";
10
10
  export type { ConnectionBinding, ToolsetExecuteOptions } from "./toolset.js";
11
+ export { File } from "./files.js";
12
+ export type { FileWire } from "./files.js";
11
13
  export type { ToolSchema, Filter, Sort, ToolExecuteResult, Application, ApplicationDetail, Connection, ConnectionDetail, WhoAmI, } from "./types.js";
12
14
  export type { Provider, ToolCall, ToolResultOptions } from "./providers/base.js";
13
15
  export { OpenAIProvider } from "./providers/openai.js";
package/dist/index.js CHANGED
@@ -3,5 +3,6 @@ export { ApiKeyAuth, BearerAuth, ENV_API_KEY_VAR, ENV_TOKEN_VAR, ENV_COMPANY_TOK
3
3
  export { EnginiError, EnginiNetworkError, EnginiAPIError, EnginiAuthError, EnginiNotFoundError, EnginiValidationError, EnginiRateLimitError, EnginiConflictError, EnginiServerError, EnginiClientError, EnginiConnectionError, EnginiToolsetError, EnginiToolExecutionError, } from "./errors.js";
4
4
  export { ToolsResource, ConnectionsResource, ToolsetsResource, ApplicationsResource, } from "./resources/index.js";
5
5
  export { Toolset } from "./toolset.js";
6
+ export { File } from "./files.js";
6
7
  export { OpenAIProvider } from "./providers/openai.js";
7
8
  export { AnthropicProvider } from "./providers/anthropic.js";
@@ -1,3 +1,4 @@
1
+ import { rewriteFileSchema } from "../files.js";
1
2
  import { get } from "./base.js";
2
3
  export class AnthropicProvider {
3
4
  name = "anthropic";
@@ -5,7 +6,7 @@ export class AnthropicProvider {
5
6
  return {
6
7
  name: canonical.toolSlug,
7
8
  description: canonical.description ?? "",
8
- input_schema: canonical.inputSchema ?? {},
9
+ input_schema: rewriteFileSchema(canonical.inputSchema ?? {}),
9
10
  };
10
11
  }
11
12
  wrapTools(canonicals) {
@@ -1,3 +1,4 @@
1
+ import { rewriteFileSchema } from "../files.js";
1
2
  import { get } from "./base.js";
2
3
  export class OpenAIProvider {
3
4
  name = "openai";
@@ -7,7 +8,7 @@ export class OpenAIProvider {
7
8
  function: {
8
9
  name: canonical.toolSlug,
9
10
  description: canonical.description ?? "",
10
- parameters: canonical.inputSchema ?? {},
11
+ parameters: rewriteFileSchema(canonical.inputSchema ?? {}),
11
12
  },
12
13
  };
13
14
  }
@@ -17,7 +17,6 @@ export interface ToolsGetOptions {
17
17
  export interface ToolsExecuteOptions {
18
18
  connectionId?: number;
19
19
  toolsetId?: string;
20
- applicationSlug?: string;
21
20
  filters?: Filter[];
22
21
  sort?: Sort[];
23
22
  top?: number;
@@ -4,12 +4,14 @@
4
4
  * `get` returns canonical `ToolSchema` (== `ToolDetailDto`) objects. Only the
5
5
  * detail endpoint carries `inputSchema` + `supports*`, so `get` lists tools
6
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.
7
+ * `execute` can gate advanced kwargs without refetching (the execute endpoint
8
+ * derives the application server-side from the tool slug and connection).
8
9
  */
9
10
  import { toolsListTools, toolsGetTool, toolsExecuteTool } from "@engini/client";
10
11
  import { call } from "../http.js";
11
12
  import { paginate, collect } from "../pagination.js";
12
13
  import { EnginiToolExecutionError, EnginiValidationError } from "../errors.js";
14
+ import { validateFiles, encodeFileValues } from "../files.js";
13
15
  export class ToolsResource {
14
16
  client;
15
17
  constructor(client) {
@@ -41,9 +43,6 @@ export class ToolsResource {
41
43
  }
42
44
  async execute(toolSlug, args = {}, options = {}) {
43
45
  const cached = this.client._toolCache.get(toolSlug);
44
- let applicationSlug = options.applicationSlug;
45
- if (applicationSlug === undefined && cached)
46
- applicationSlug = cached.applicationSlug;
47
46
  // The tool inputSchema flattens connector fields and the request-level knobs
48
47
  // into one object, so split the LLM's args back out: hoist Filters/Sorts/
49
48
  // SelectTop/SelectOffset to the top level and flatten a Fields list into the
@@ -55,19 +54,23 @@ export class ToolsResource {
55
54
  top: options.top ?? norm.top,
56
55
  offset: options.offset ?? norm.offset,
57
56
  };
58
- if (cached)
57
+ if (cached) {
59
58
  this.gate(cached, merged);
59
+ validateFiles(norm.fields, cached.inputSchema);
60
+ }
61
+ // Translate any File the caller attached into the wire shape the API expects
62
+ // ({ base64_content, mime_type, filename }); plain values pass through.
63
+ const fields = encodeFileValues(norm.fields);
60
64
  const toolsetId = options.connectionId === undefined ? options.toolsetId : undefined;
61
65
  const response = await call(toolsExecuteTool, {
62
66
  client: this.client._transport,
63
67
  path: { toolSlug },
64
68
  query: {
65
- applicationSlug,
66
69
  toolsetId,
67
70
  connectionId: options.connectionId,
68
71
  },
69
72
  body: {
70
- fields: norm.fields,
73
+ fields,
71
74
  filters: merged.filters,
72
75
  sort: merged.sort,
73
76
  top: merged.top,
package/dist/toolset.d.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  import type { ToolsetDto, ToolsetConnectionRequest } from "@engini/client";
7
7
  import type { Filter, Sort, ToolExecuteResult, ToolSchema } from "./types.js";
8
8
  import type { ToolCall } from "./providers/base.js";
9
+ import { File } from "./files.js";
9
10
  /** Connection binding value: pin an id (number), a connection name (string), or server default (null). */
10
11
  export type ConnectionBinding = number | string | null;
11
12
  /** Higher-level client surface the Toolset depends on (satisfied by `Engini`). */
@@ -19,7 +20,6 @@ export interface ToolsetClient {
19
20
  execute(slug: string, args: Record<string, unknown>, options: {
20
21
  connectionId?: number;
21
22
  toolsetId?: string;
22
- applicationSlug?: string;
23
23
  filters?: Filter[];
24
24
  sort?: Sort[];
25
25
  top?: number;
@@ -71,7 +71,17 @@ export declare class Toolset {
71
71
  format?: "provider" | "canonical";
72
72
  }): Promise<unknown[]>;
73
73
  execute(toolSlug: string, args?: Record<string, unknown>, options?: ToolsetExecuteOptions): Promise<ToolExecuteResult>;
74
- handleToolCalls(llmResponse: unknown): Promise<unknown[]>;
74
+ /**
75
+ * Run every tool call in an LLM response; return result messages.
76
+ *
77
+ * `files` is an optional `{ key: File }` registry. An LLM can't produce
78
+ * base64, so file fields are presented to it as string fields (see
79
+ * `provider.wrapTool`); the model fills one with a key, resolved here against
80
+ * `files`. An unknown key surfaces as a per-call error result.
81
+ */
82
+ handleToolCalls(llmResponse: unknown, options?: {
83
+ files?: Record<string, File>;
84
+ }): Promise<unknown[]>;
75
85
  save(params: {
76
86
  name: string;
77
87
  }): Promise<string>;
package/dist/toolset.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { resolveFileRefs } from "./files.js";
1
2
  import { EnginiClientError, EnginiConnectionError, EnginiToolExecutionError, EnginiValidationError, } from "./errors.js";
2
3
  export class Toolset {
3
4
  client;
@@ -60,19 +61,31 @@ export class Toolset {
60
61
  }
61
62
  return this.client.tools.execute(toolSlug, args, {
62
63
  connectionId: resolved,
63
- applicationSlug: application,
64
64
  filters: options.filters,
65
65
  sort: options.sort,
66
66
  top: options.top,
67
67
  offset: options.offset,
68
68
  });
69
69
  }
70
- async handleToolCalls(llmResponse) {
70
+ /**
71
+ * Run every tool call in an LLM response; return result messages.
72
+ *
73
+ * `files` is an optional `{ key: File }` registry. An LLM can't produce
74
+ * base64, so file fields are presented to it as string fields (see
75
+ * `provider.wrapTool`); the model fills one with a key, resolved here against
76
+ * `files`. An unknown key surfaces as a per-call error result.
77
+ */
78
+ async handleToolCalls(llmResponse, options = {}) {
71
79
  const provider = this.client.provider;
72
80
  const results = [];
73
81
  for (const call of provider.parseToolCalls(llmResponse)) {
74
82
  try {
75
- const result = await this.execute(call.name, call.arguments);
83
+ let args = call.arguments;
84
+ if (options.files && Object.keys(options.files).length) {
85
+ const schema = await this.client.tools.getOne(call.name);
86
+ args = resolveFileRefs(args, schema.inputSchema, options.files);
87
+ }
88
+ const result = await this.execute(call.name, args);
76
89
  results.push(provider.formatToolResult(call, { output: result.output }));
77
90
  }
78
91
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engini/sdk",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "Engini SDK — agent-first ergonomic layer over the Engini Public API",
5
5
  "license": "MIT",
6
6
  "type": "module",