@workser/engine 0.1.22 → 0.1.23

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.
@@ -8,6 +8,7 @@ export interface ToolsClient {
8
8
  description?: string;
9
9
  side_effect?: boolean;
10
10
  spends?: boolean;
11
+ input_schema?: unknown;
11
12
  }>;
12
13
  ask_before_paying_usd?: number;
13
14
  }>;
@@ -49,3 +50,11 @@ export declare function listedTools<T extends {
49
50
  }>(tools: readonly T[], query: string): Array<T & {
50
51
  description?: string;
51
52
  }>;
53
+ /**
54
+ * The tools a call's arguments fit (a call that came without its name): every argument given is one of the tool's
55
+ * parameters, and every parameter it requires is given. Tools that don't describe their parameters never fit.
56
+ */
57
+ export declare function toolsForArguments(tools: ReadonlyArray<{
58
+ name: string;
59
+ input_schema?: unknown;
60
+ }>, given: Record<string, unknown>): string[];
@@ -41,6 +41,15 @@ export function workserTool(client) {
41
41
  }
42
42
  // Trace 01a1d4cc (13 Nov): 4 of 57 calls of a job went out as {action: "call", approval_id: "", spend_approval_id: ""} with no
43
43
  // name (the model reached for an approval on a preview DELETE that needed none), failed, and were sent again.
44
+ // Owner 21 Nov: again, a count on the preview ({query, environment}) with no name stopped a job. A call with arguments
45
+ // that only one tool takes is that tool's call; several (or none) say which names would fit.
46
+ if (args.action === 'call' && (typeof args.name !== 'string' || !args.name) && args.arguments && typeof args.arguments === 'object') {
47
+ const fits = toolsForArguments((await client.listTools()).tools, args.arguments);
48
+ if (fits.length === 1)
49
+ args = { ...args, name: fits[0] };
50
+ else if (fits.length > 1)
51
+ throw new Error(`A call needs a name. These tools take those arguments: ${fits.slice(0, 6).join(', ')}. Call again with name set to the one you mean.`);
52
+ }
44
53
  if (args.action !== 'call' || typeof args.name !== 'string' || !args.name) {
45
54
  throw new Error("action is 'list' or 'call'. A call needs a name (the tool's, for example name: \"app_db_query\" with its arguments); approval_id only when a result gave you one.");
46
55
  }
@@ -81,3 +90,22 @@ export function listedTools(tools, query) {
81
90
  return { ...tool, ...(tool.description ? { description: first } : {}) };
82
91
  });
83
92
  }
93
+ /**
94
+ * The tools a call's arguments fit (a call that came without its name): every argument given is one of the tool's
95
+ * parameters, and every parameter it requires is given. Tools that don't describe their parameters never fit.
96
+ */
97
+ export function toolsForArguments(tools, given) {
98
+ const keys = Object.keys(given);
99
+ if (!keys.length)
100
+ return [];
101
+ return tools
102
+ .filter((tool) => {
103
+ const schema = tool.input_schema && typeof tool.input_schema === 'object' ? tool.input_schema : null;
104
+ const properties = schema?.properties && typeof schema.properties === 'object' ? Object.keys(schema.properties) : null;
105
+ if (!properties?.length)
106
+ return false;
107
+ const required = Array.isArray(schema.required) ? schema.required.filter((one) => typeof one === 'string') : [];
108
+ return keys.every((key) => properties.includes(key)) && required.every((key) => keys.includes(key));
109
+ })
110
+ .map((tool) => tool.name);
111
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workser/engine",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "description": "Workser's coding engine for the 'loop in our service' mode: OpenCode's agent contract (its prompts, tool schemas and edit semantics, vendored from v1.19.5) running on Node, with every file and shell action going through a Place — so the machine can be a remote sandbox and no model key is ever on it.",
5
5
  "license": "MIT",
6
6
  "type": "module",