@skilder-ai/runtime 0.7.5 → 0.7.7

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.
@@ -21,7 +21,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  callTool: () => callTool,
24
- delegate: () => delegate
24
+ callToolJson: () => callToolJson,
25
+ callToolText: () => callToolText,
26
+ delegate: () => delegate,
27
+ delegateJson: () => delegateJson,
28
+ delegateText: () => delegateText,
29
+ execute: () => execute,
30
+ executeJson: () => executeJson,
31
+ executeText: () => executeText
25
32
  });
26
33
  module.exports = __toCommonJS(index_exports);
27
34
 
@@ -94,8 +101,70 @@ async function delegate(context, options) {
94
101
  }
95
102
  return result;
96
103
  }
104
+ async function callToolText(name, args = {}) {
105
+ const result = await callTool(name, args);
106
+ const first = result.content[0];
107
+ if (!first || first.type !== "text") {
108
+ throw new Error(`Expected text content from tool "${name}", got ${first?.type ?? "empty"}`);
109
+ }
110
+ return first.text;
111
+ }
112
+ async function delegateText(context, options) {
113
+ const result = await delegate(context, options);
114
+ const first = result.content[0];
115
+ if (!first || first.type !== "text") {
116
+ throw new Error(`Expected text content from delegate, got ${first?.type ?? "empty"}`);
117
+ }
118
+ return first.text;
119
+ }
120
+ async function callToolJson(name, args = {}) {
121
+ const text = await callToolText(name, args);
122
+ try {
123
+ return JSON.parse(text);
124
+ } catch {
125
+ throw new Error(`Tool "${name}" returned invalid JSON: ${text.slice(0, 200)}`);
126
+ }
127
+ }
128
+ async function delegateJson(context, options) {
129
+ const text = await delegateText(context, options);
130
+ try {
131
+ return JSON.parse(text);
132
+ } catch {
133
+ throw new Error(`Delegate returned invalid JSON: ${text.slice(0, 200)}`);
134
+ }
135
+ }
136
+ async function execute(path, args) {
137
+ const result = await sendRequest("scripts/execute", { path, arguments: args });
138
+ if (!result || typeof result !== "object" || !Array.isArray(result.content)) {
139
+ throw new Error("Invalid CallToolResult received from host");
140
+ }
141
+ return result;
142
+ }
143
+ async function executeText(path, args) {
144
+ const result = await execute(path, args);
145
+ const first = result.content[0];
146
+ if (!first || first.type !== "text") {
147
+ throw new Error(`Expected text content from script "${path}", got ${first?.type ?? "empty"}`);
148
+ }
149
+ return first.text;
150
+ }
151
+ async function executeJson(path, args) {
152
+ const text = await executeText(path, args);
153
+ try {
154
+ return JSON.parse(text);
155
+ } catch {
156
+ throw new Error(`Script "${path}" returned invalid JSON: ${text.slice(0, 200)}`);
157
+ }
158
+ }
97
159
  // Annotate the CommonJS export names for ESM import in node:
98
160
  0 && (module.exports = {
99
161
  callTool,
100
- delegate
162
+ callToolJson,
163
+ callToolText,
164
+ delegate,
165
+ delegateJson,
166
+ delegateText,
167
+ execute,
168
+ executeJson,
169
+ executeText
101
170
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skilder-ai/runtime",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "description": "Skilder Runtime - NodeJS processes for edge execution connected to backend orchestrator via NATS",
5
5
  "author": "Skilder AI",
6
6
  "license": "See license in LICENSE",
@@ -61,7 +61,7 @@
61
61
  "esbuild-plugin-tsc": "^0.5.0",
62
62
  "inversify": "^7.0.0-alpha.5",
63
63
  "reflect-metadata": "^0.2.2",
64
- "@skilder-ai/common": "0.7.5"
64
+ "@skilder-ai/common": "0.7.7"
65
65
  },
66
66
  "scripts": {
67
67
  "build": "tsx tooling/esbuild.build.ts",