assistant-stream 0.3.6 → 0.3.8

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.
@@ -25,6 +25,11 @@ export type ToToolsJSONSchemaOptions = {
25
25
  * - Plain JSONSchema7 objects (must have a "type" property)
26
26
  */
27
27
  export declare function toJSONSchema(schema: StandardSchemaV1 | JSONSchema7): JSONSchema7;
28
+ /**
29
+ * Returns a copy of the JSON Schema with `required` removed recursively,
30
+ * making every property optional. Array item schemas are left unchanged.
31
+ */
32
+ export declare function toPartialJSONSchema(schema: JSONSchema7): JSONSchema7;
28
33
  /**
29
34
  * Converts a record of tools to a record of tool definitions with JSON Schema parameters.
30
35
  * By default, filters out disabled tools and backend tools.
@@ -1 +1 @@
1
- {"version":3,"file":"schema-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tool/schema-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAqB;AAEzC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,WAAW,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;CAChD,CAAC;AAoCF;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,gBAAgB,GAAG,WAAW,GACrC,WAAW,CAyCb;AAMD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,SAAS,EACvC,OAAO,GAAE,wBAA6B,GACrC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAgBhC"}
1
+ {"version":3,"file":"schema-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tool/schema-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAqB;AAEzC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,WAAW,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;CAChD,CAAC;AAoCF;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,gBAAgB,GAAG,WAAW,GACrC,WAAW,CAyCb;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAgBpE;AAMD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,SAAS,EACvC,OAAO,GAAE,wBAA6B,GACrC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAgBhC"}
@@ -58,6 +58,23 @@ export function toJSONSchema(schema) {
58
58
  // Already a plain JSONSchema7
59
59
  return schema;
60
60
  }
61
+ /**
62
+ * Returns a copy of the JSON Schema with `required` removed recursively,
63
+ * making every property optional. Array item schemas are left unchanged.
64
+ */
65
+ export function toPartialJSONSchema(schema) {
66
+ const { required: _, ...result } = schema;
67
+ if (result.properties) {
68
+ result.properties = Object.fromEntries(Object.entries(result.properties).map(([key, prop]) => {
69
+ if (typeof prop === "object" && prop !== null && !Array.isArray(prop)) {
70
+ const p = prop;
71
+ return [key, p.properties != null ? toPartialJSONSchema(p) : prop];
72
+ }
73
+ return [key, prop];
74
+ }));
75
+ }
76
+ return result;
77
+ }
61
78
  function defaultToolFilter(_name, tool) {
62
79
  return !tool.disabled && tool.type !== "backend";
63
80
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schema-utils.js","sourceRoot":"","sources":["../../../src/core/tool/schema-utils.ts"],"names":[],"mappings":"AAoBA,SAAS,gBAAgB,CAAC,MAAe;IAMvC,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,WAAW,IAAI,MAAM;QACrB,OAAQ,MAA2B,CAAC,WAAW,CAAC,KAAK,QAAQ,CAC9D,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAC5B,MAAe;IAEf,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,cAAc,IAAI,MAAM;QACxB,OAAQ,MAAoC,CAAC,YAAY,KAAK,UAAU,CACzE,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,MAAe;IACtC,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,QAAQ,IAAI,MAAM;QAClB,OAAQ,MAA8B,CAAC,MAAM,KAAK,UAAU,CAC7D,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAsC;IAEtC,8DAA8D;IAC9D,IAAI,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,MAAM,kBAAkB,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC;QAC5D,IAAI,OAAO,kBAAkB,KAAK,UAAU,EAAE,CAAC;YAC7C,OAAO,kBAAkB,EAAiB,CAAC;QAC7C,CAAC;QAED,qDAAqD;QACrD,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC;QACl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AI,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACrE,CAAC;YACD,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACrB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAa,EAAE,IAAU;IAClD,OAAO,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAuC,EACvC,UAAoC,EAAE;IAEtC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IAEtB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,iBAAiB,CAAC;IAEnD,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;SAClB,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC;SAC/D,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;QACrB,IAAI;QACJ;YACE,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;YAC1D,UAAU,EAAE,YAAY,CAAC,IAAI,CAAC,UAAW,CAAC;SAC3C;KACF,CAAC,CACL,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@ export { ToolResponse, type ToolResponseLike } from "./core/tool/ToolResponse.js
14
14
  export { ToolExecutionStream } from "./core/tool/ToolExecutionStream.js";
15
15
  export type { ToolCallReader } from "./core/tool/tool-types.js";
16
16
  export { toolResultStream as unstable_toolResultStream, unstable_runPendingTools, type ToolResultStreamOptions, } from "./core/tool/toolResultStream.js";
17
- export { toJSONSchema, toToolsJSONSchema, type ToolJSONSchema, type ToToolsJSONSchemaOptions, } from "./core/tool/schema-utils.js";
17
+ export { toJSONSchema, toPartialJSONSchema, toToolsJSONSchema, type ToolJSONSchema, type ToToolsJSONSchemaOptions, } from "./core/tool/schema-utils.js";
18
18
  export type { TextStreamController } from "./core/modules/text.js";
19
19
  export type { ToolCallStreamController } from "./core/modules/tool-call.js";
20
20
  export { createObjectStream } from "./core/object/createObjectStream.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,+BAA+B,GAChC,2CAAwC;AACzC,OAAO,EACL,2BAA2B,EAC3B,oBAAoB,IAAI,6BAA6B,GACtD,6DAA0D;AAC3D,OAAO,EAAE,eAAe,EAAE,kCAA+B;AACzD,YAAY,EAAE,yBAAyB,EAAE,2CAAwC;AACjF,YAAY,EAAE,oBAAoB,EAAE,uCAAoC;AACxE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAClB,uDAAoD;AACrD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,GACjB,0CAAuC;AACxC,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,uEAAoE;AACrE,OAAO,EACL,sBAAsB,EACtB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,6BAA6B,GACnC,kEAA+D;AAChE,OAAO,EAAE,sBAAsB,EAAE,sDAAmD;AACpF,YAAY,EACV,gBAAgB,EAChB,sBAAsB,GACvB,8BAA2B;AAE5B,YAAY,EAAE,IAAI,EAAE,kCAA+B;AACnD,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,oCAAiC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,2CAAwC;AACtE,YAAY,EAAE,cAAc,EAAE,kCAA+B;AAC7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sBAAsB,EAAE,sDAAmD;AACpF,YAAY,EACV,gBAAgB,EAChB,sBAAsB,GACvB,8BAA2B;AAE5B,YAAY,EAAE,IAAI,EAAE,kCAA+B;AACnD,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,oCAAiC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,2CAAwC;AACtE,YAAY,EAAE,cAAc,EAAE,kCAA+B;AAC7D,OAAO,EACL,gBAAgB,IAAI,yBAAyB,EAC7C,wBAAwB,EACxB,KAAK,uBAAuB,GAC7B,wCAAqC;AACtC,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,wBAAwB,GAC9B,oCAAiC;AAElC,YAAY,EAAE,oBAAoB,EAAE,+BAA4B;AAChE,YAAY,EAAE,wBAAwB,EAAE,oCAAiC;AAEzE,OAAO,EAAE,kBAAkB,EAAE,4CAAyC;AACtE,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GACzB,8CAA2C;AAC5C,YAAY,EAAE,iBAAiB,EAAE,+BAA4B;AAE7D,OAAO,EACL,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,GAC3B,+CAA4C"}
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ export { AssistantMessageStream } from "./core/accumulators/AssistantMessageStre
9
9
  export { ToolResponse } from "./core/tool/ToolResponse.js";
10
10
  export { ToolExecutionStream } from "./core/tool/ToolExecutionStream.js";
11
11
  export { toolResultStream as unstable_toolResultStream, unstable_runPendingTools, } from "./core/tool/toolResultStream.js";
12
- export { toJSONSchema, toToolsJSONSchema, } from "./core/tool/schema-utils.js";
12
+ export { toJSONSchema, toPartialJSONSchema, toToolsJSONSchema, } from "./core/tool/schema-utils.js";
13
13
  export { createObjectStream } from "./core/object/createObjectStream.js";
14
14
  export { ObjectStreamResponse, fromObjectStreamResponse, } from "./core/object/ObjectStreamResponse.js";
15
15
  export { toGenericMessages, } from "./core/converters/toGenericMessages.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,+BAA+B,GAChC,2CAAwC;AACzC,OAAO,EACL,2BAA2B,EAC3B,oBAAoB,IAAI,6BAA6B,GACtD,6DAA0D;AAC3D,OAAO,EAAE,eAAe,EAAE,kCAA+B;AAGzD,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAClB,uDAAoD;AACrD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,GACjB,0CAAuC;AACxC,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,uEAAoE;AACrE,OAAO,EACL,sBAAsB,GAIvB,kEAA+D;AAChE,OAAO,EAAE,sBAAsB,EAAE,sDAAmD;AAOpF,OAAO,EAAE,YAAY,EAAyB,oCAAiC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,2CAAwC;AAEtE,OAAO,EACL,gBAAgB,IAAI,yBAAyB,EAC7C,wBAAwB,GAEzB,wCAAqC;AACtC,OAAO,EACL,YAAY,EACZ,iBAAiB,GAGlB,oCAAiC;AAKlC,OAAO,EAAE,kBAAkB,EAAE,4CAAyC;AACtE,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GACzB,8CAA2C;AAG5C,OAAO,EACL,iBAAiB,GAUlB,+CAA4C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,+BAA+B,GAChC,2CAAwC;AACzC,OAAO,EACL,2BAA2B,EAC3B,oBAAoB,IAAI,6BAA6B,GACtD,6DAA0D;AAC3D,OAAO,EAAE,eAAe,EAAE,kCAA+B;AAGzD,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAClB,uDAAoD;AACrD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,GACjB,0CAAuC;AACxC,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,uEAAoE;AACrE,OAAO,EACL,sBAAsB,GAIvB,kEAA+D;AAChE,OAAO,EAAE,sBAAsB,EAAE,sDAAmD;AAOpF,OAAO,EAAE,YAAY,EAAyB,oCAAiC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,2CAAwC;AAEtE,OAAO,EACL,gBAAgB,IAAI,yBAAyB,EAC7C,wBAAwB,GAEzB,wCAAqC;AACtC,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,GAGlB,oCAAiC;AAKlC,OAAO,EAAE,kBAAkB,EAAE,4CAAyC;AACtE,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GACzB,8CAA2C;AAG5C,OAAO,EACL,iBAAiB,GAUlB,+CAA4C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assistant-stream",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "Streaming utilities for AI assistants",
5
5
  "keywords": [
6
6
  "ai",
@@ -37,12 +37,12 @@
37
37
  "sideEffects": false,
38
38
  "dependencies": {
39
39
  "@standard-schema/spec": "^1.1.0",
40
- "nanoid": "^5.1.6",
40
+ "nanoid": "^5.1.7",
41
41
  "secure-json-parse": "^4.1.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/json-schema": "^7.0.15",
45
- "vitest": "^4.1.0",
45
+ "vitest": "^4.1.1",
46
46
  "@assistant-ui/x-buildutils": "0.0.3"
47
47
  },
48
48
  "publishConfig": {
@@ -1,5 +1,9 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { toJSONSchema, toToolsJSONSchema } from "./schema-utils";
2
+ import {
3
+ toJSONSchema,
4
+ toPartialJSONSchema,
5
+ toToolsJSONSchema,
6
+ } from "./schema-utils";
3
7
  import type { Tool } from "./tool-types";
4
8
 
5
9
  describe("toJSONSchema", () => {
@@ -135,6 +139,96 @@ describe("toJSONSchema", () => {
135
139
  });
136
140
  });
137
141
 
142
+ describe("toPartialJSONSchema", () => {
143
+ it("removes required from a flat object schema", () => {
144
+ const schema = {
145
+ type: "object" as const,
146
+ properties: {
147
+ name: { type: "string" as const },
148
+ age: { type: "number" as const },
149
+ },
150
+ required: ["name", "age"],
151
+ };
152
+ const result = toPartialJSONSchema(schema);
153
+ expect(result.required).toBeUndefined();
154
+ expect(result.properties).toEqual(schema.properties);
155
+ });
156
+
157
+ it("recursively removes required from nested objects", () => {
158
+ const schema = {
159
+ type: "object" as const,
160
+ properties: {
161
+ address: {
162
+ type: "object" as const,
163
+ properties: {
164
+ street: { type: "string" as const },
165
+ city: { type: "string" as const },
166
+ },
167
+ required: ["street", "city"],
168
+ },
169
+ },
170
+ required: ["address"],
171
+ };
172
+ const result = toPartialJSONSchema(schema);
173
+ expect(result.required).toBeUndefined();
174
+ const address = result.properties!["address"] as Record<string, unknown>;
175
+ expect(address.required).toBeUndefined();
176
+ });
177
+
178
+ it("leaves array item schemas unchanged", () => {
179
+ const schema = {
180
+ type: "object" as const,
181
+ properties: {
182
+ tags: {
183
+ type: "array" as const,
184
+ items: {
185
+ type: "object" as const,
186
+ properties: { label: { type: "string" as const } },
187
+ required: ["label"],
188
+ },
189
+ },
190
+ },
191
+ required: ["tags"],
192
+ };
193
+ const result = toPartialJSONSchema(schema);
194
+ expect(result.required).toBeUndefined();
195
+ const tags = result.properties!["tags"] as Record<string, unknown>;
196
+ const items = tags.items as Record<string, unknown>;
197
+ expect(items.required).toEqual(["label"]);
198
+ });
199
+
200
+ it("handles schema with no required field", () => {
201
+ const schema = {
202
+ type: "object" as const,
203
+ properties: { x: { type: "string" as const } },
204
+ };
205
+ const result = toPartialJSONSchema(schema);
206
+ expect(result).toEqual(schema);
207
+ });
208
+
209
+ it("does not mutate the input schema", () => {
210
+ const schema = {
211
+ type: "object" as const,
212
+ properties: { a: { type: "string" as const } },
213
+ required: ["a"],
214
+ };
215
+ toPartialJSONSchema(schema);
216
+ expect(schema.required).toEqual(["a"]);
217
+ });
218
+
219
+ it("preserves additionalProperties", () => {
220
+ const schema = {
221
+ type: "object" as const,
222
+ properties: { x: { type: "string" as const } },
223
+ required: ["x"],
224
+ additionalProperties: false,
225
+ };
226
+ const result = toPartialJSONSchema(schema);
227
+ expect(result.additionalProperties).toBe(false);
228
+ expect(result.required).toBeUndefined();
229
+ });
230
+ });
231
+
138
232
  describe("toToolsJSONSchema", () => {
139
233
  describe("filtering", () => {
140
234
  it("excludes disabled tools by default", () => {
@@ -106,6 +106,28 @@ export function toJSONSchema(
106
106
  return schema as JSONSchema7;
107
107
  }
108
108
 
109
+ /**
110
+ * Returns a copy of the JSON Schema with `required` removed recursively,
111
+ * making every property optional. Array item schemas are left unchanged.
112
+ */
113
+ export function toPartialJSONSchema(schema: JSONSchema7): JSONSchema7 {
114
+ const { required: _, ...result } = schema;
115
+
116
+ if (result.properties) {
117
+ result.properties = Object.fromEntries(
118
+ Object.entries(result.properties).map(([key, prop]) => {
119
+ if (typeof prop === "object" && prop !== null && !Array.isArray(prop)) {
120
+ const p = prop as JSONSchema7;
121
+ return [key, p.properties != null ? toPartialJSONSchema(p) : prop];
122
+ }
123
+ return [key, prop];
124
+ }),
125
+ );
126
+ }
127
+
128
+ return result;
129
+ }
130
+
109
131
  function defaultToolFilter(_name: string, tool: Tool): boolean {
110
132
  return !tool.disabled && tool.type !== "backend";
111
133
  }
package/src/index.ts CHANGED
@@ -45,6 +45,7 @@ export {
45
45
  } from "./core/tool/toolResultStream";
46
46
  export {
47
47
  toJSONSchema,
48
+ toPartialJSONSchema,
48
49
  toToolsJSONSchema,
49
50
  type ToolJSONSchema,
50
51
  type ToToolsJSONSchemaOptions,