@xsai/generate-object 0.3.3 → 0.3.5

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/dist/index.d.ts CHANGED
@@ -5,6 +5,8 @@ interface GenerateObjectOptions<T extends Schema> extends GenerateTextOptions {
5
5
  schema: T;
6
6
  schemaDescription?: string;
7
7
  schemaName?: string;
8
+ /** @default true */
9
+ strict?: boolean;
8
10
  }
9
11
  type GenerateObjectResult<O> = GenerateTextResult & {
10
12
  object: O;
package/dist/index.js CHANGED
@@ -13,8 +13,9 @@ const wrap = (items) => ({
13
13
  });
14
14
 
15
15
  async function generateObject(options) {
16
- const { schema: schemaValidator } = options;
17
- let schema = await toJsonSchema(schemaValidator).then((schema2) => strictJsonSchema(schema2));
16
+ let schema = await toJsonSchema(options.schema);
17
+ if (options.strict !== false)
18
+ schema = strictJsonSchema(schema);
18
19
  if (options.output === "array")
19
20
  schema = wrap(schema);
20
21
  return generateText({
@@ -24,7 +25,7 @@ async function generateObject(options) {
24
25
  description: options.schemaDescription,
25
26
  name: options.schemaName ?? "json_schema",
26
27
  schema,
27
- strict: true
28
+ strict: options.strict ?? true
28
29
  },
29
30
  type: "json_schema"
30
31
  },
@@ -32,15 +33,17 @@ async function generateObject(options) {
32
33
  // Remove schema from options
33
34
  schemaDescription: void 0,
34
35
  // Remove schemaDescription from options
35
- schemaName: void 0
36
+ schemaName: void 0,
36
37
  // Remove schemaName from options
38
+ strict: void 0
39
+ // Remove strict from options
37
40
  }).then(async ({ finishReason, messages, steps, text, toolCalls, toolResults, usage }) => {
38
41
  const json = JSON.parse(text);
39
42
  if (options.output === "array") {
40
43
  return {
41
44
  finishReason,
42
45
  messages,
43
- object: await Promise.all(json.elements.map(async (element) => validate(schemaValidator, element))),
46
+ object: await Promise.all(json.elements.map(async (element) => validate(options.schema, element))),
44
47
  steps,
45
48
  text,
46
49
  toolCalls,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xsai/generate-object",
3
3
  "type": "module",
4
- "version": "0.3.3",
4
+ "version": "0.3.5",
5
5
  "description": "extra-small AI SDK.",
6
6
  "author": "Moeru AI",
7
7
  "license": "MIT",
@@ -29,8 +29,8 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@xsai/generate-text": "~0.3.3",
33
- "xsschema": "~0.3.3"
32
+ "@xsai/generate-text": "~0.3.5",
33
+ "xsschema": "~0.3.5"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@valibot/to-json-schema": "^1.0.0",