@project-ajax/sdk 0.0.32 → 0.0.33

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.
@@ -13,18 +13,30 @@ export interface ToolConfiguration<I extends JSONValue, O extends JSONValue = JS
13
13
  */
14
14
  export declare class InvalidToolInputError extends Error {
15
15
  constructor(message: string);
16
+ toJSON(): {
17
+ name: string;
18
+ message: string;
19
+ };
16
20
  }
17
21
  /**
18
22
  * An error returned when the output from a tool doesn't match the output schema.
19
23
  */
20
24
  export declare class InvalidToolOutputError extends Error {
21
25
  constructor(message: string);
26
+ toJSON(): {
27
+ name: string;
28
+ message: string;
29
+ };
22
30
  }
23
31
  /**
24
32
  * An error returned when the tool execution fails.
25
33
  */
26
34
  export declare class ToolExecutionError extends Error {
27
35
  constructor(message: string);
36
+ toJSON(): {
37
+ name: string;
38
+ message: string;
39
+ };
28
40
  }
29
41
  /**
30
42
  * Creates a capability definition for a tool to be used by an agent.
@@ -1 +1 @@
1
- {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/capabilities/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAE/C,KAAK,SAAS,GACX,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,EAAE,GACX;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEhC,MAAM,WAAW,iBAAiB,CACjC,CAAC,SAAS,SAAS,EACnB,CAAC,SAAS,SAAS,GAAG,SAAS;IAE/B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAC1B,YAAY,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IACjC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACtC;AAED;;GAEG;AACH,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,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;IAK3B,MAAM;;;;CAMN;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM;IAK3B,MAAM;;;;CAMN;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;IAK3B,MAAM;;;;CAMN;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,SAAS,GAAG,SAAS,EACxE,MAAM,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC;;;;;;;mBAeT,SAAS,GAAG,OAAO,CACrC;QACA,IAAI,EAAE,SAAS,CAAC;QAChB,KAAK,EAAE,CAAC,CAAC;KACR,GACD;QACA,IAAI,EAAE,OAAO,CAAC;QACd,KAAK,EACF,qBAAqB,GACrB,sBAAsB,GACtB,kBAAkB,CAAC;KACrB,CACH;EA0DF"}
@@ -4,18 +4,36 @@ class InvalidToolInputError extends Error {
4
4
  super(message);
5
5
  this.name = "InvalidToolInputError";
6
6
  }
7
+ toJSON() {
8
+ return {
9
+ name: this.name,
10
+ message: this.message
11
+ };
12
+ }
7
13
  }
8
14
  class InvalidToolOutputError extends Error {
9
15
  constructor(message) {
10
16
  super(message);
11
17
  this.name = "InvalidToolOutputError";
12
18
  }
19
+ toJSON() {
20
+ return {
21
+ name: this.name,
22
+ message: this.message
23
+ };
24
+ }
13
25
  }
14
26
  class ToolExecutionError extends Error {
15
27
  constructor(message) {
16
28
  super(message);
17
29
  this.name = "ToolExecutionError";
18
30
  }
31
+ toJSON() {
32
+ return {
33
+ name: this.name,
34
+ message: this.message
35
+ };
36
+ }
19
37
  }
20
38
  function tool(config) {
21
39
  const ajv = new Ajv();
@@ -35,22 +53,32 @@ function tool(config) {
35
53
  "Unexpected: No validation errors after failed validation"
36
54
  );
37
55
  }
38
- return {
56
+ const result = {
39
57
  _tag: "error",
40
58
  error: new InvalidToolInputError(
41
59
  JSON.stringify(validateInput.errors, null, 2)
42
60
  )
43
61
  };
62
+ process.stdout.write(`
63
+ <output>${JSON.stringify(result)}</output>
64
+ `);
65
+ return result;
44
66
  }
45
67
  try {
46
68
  const result = await config.execute(input);
47
69
  if (validateOutput && !validateOutput(result)) {
48
- return {
70
+ const result2 = {
49
71
  _tag: "error",
50
72
  error: new InvalidToolOutputError(
51
73
  JSON.stringify(validateOutput.errors, null, 2)
52
74
  )
53
75
  };
76
+ process.stdout.write(
77
+ `
78
+ <output>${JSON.stringify(result2)}</output>
79
+ `
80
+ );
81
+ return result2;
54
82
  }
55
83
  process.stdout.write(`
56
84
  <output>${JSON.stringify(result)}</output>
@@ -60,12 +88,16 @@ function tool(config) {
60
88
  value: result
61
89
  };
62
90
  } catch (err) {
63
- return {
91
+ const result = {
64
92
  _tag: "error",
65
93
  error: new ToolExecutionError(
66
94
  err instanceof Error ? err.message : String(err)
67
95
  )
68
96
  };
97
+ process.stdout.write(`
98
+ <output>${JSON.stringify(result)}</output>
99
+ `);
100
+ return result;
69
101
  }
70
102
  }
71
103
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@project-ajax/sdk",
3
- "version": "0.0.32",
3
+ "version": "0.0.33",
4
4
  "description": "An SDK for building workers for the Project Ajax platform",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -26,6 +26,13 @@ export class InvalidToolInputError extends Error {
26
26
  super(message);
27
27
  this.name = "InvalidToolInputError";
28
28
  }
29
+
30
+ toJSON() {
31
+ return {
32
+ name: this.name,
33
+ message: this.message,
34
+ };
35
+ }
29
36
  }
30
37
 
31
38
  /**
@@ -36,6 +43,13 @@ export class InvalidToolOutputError extends Error {
36
43
  super(message);
37
44
  this.name = "InvalidToolOutputError";
38
45
  }
46
+
47
+ toJSON() {
48
+ return {
49
+ name: this.name,
50
+ message: this.message,
51
+ };
52
+ }
39
53
  }
40
54
 
41
55
  /**
@@ -46,6 +60,13 @@ export class ToolExecutionError extends Error {
46
60
  super(message);
47
61
  this.name = "ToolExecutionError";
48
62
  }
63
+
64
+ toJSON() {
65
+ return {
66
+ name: this.name,
67
+ message: this.message,
68
+ };
69
+ }
49
70
  }
50
71
 
51
72
  /**
@@ -109,23 +130,33 @@ export function tool<I extends JSONValue, O extends JSONValue = JSONValue>(
109
130
  );
110
131
  }
111
132
 
112
- return {
133
+ const result = {
113
134
  _tag: "error" as const,
114
135
  error: new InvalidToolInputError(
115
136
  JSON.stringify(validateInput.errors, null, 2),
116
137
  ),
117
138
  };
139
+
140
+ process.stdout.write(`\n<output>${JSON.stringify(result)}</output>\n`);
141
+
142
+ return result;
118
143
  }
119
144
 
120
145
  try {
121
146
  const result = await config.execute(input);
122
147
  if (validateOutput && !validateOutput(result)) {
123
- return {
148
+ const result = {
124
149
  _tag: "error" as const,
125
150
  error: new InvalidToolOutputError(
126
151
  JSON.stringify(validateOutput.errors, null, 2),
127
152
  ),
128
153
  };
154
+
155
+ process.stdout.write(
156
+ `\n<output>${JSON.stringify(result)}</output>\n`,
157
+ );
158
+
159
+ return result;
129
160
  }
130
161
 
131
162
  process.stdout.write(`\n<output>${JSON.stringify(result)}</output>\n`);
@@ -135,12 +166,16 @@ export function tool<I extends JSONValue, O extends JSONValue = JSONValue>(
135
166
  value: result,
136
167
  };
137
168
  } catch (err) {
138
- return {
169
+ const result = {
139
170
  _tag: "error" as const,
140
171
  error: new ToolExecutionError(
141
172
  err instanceof Error ? err.message : String(err),
142
173
  ),
143
174
  };
175
+
176
+ process.stdout.write(`\n<output>${JSON.stringify(result)}</output>\n`);
177
+
178
+ return result;
144
179
  }
145
180
  },
146
181
  };