-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: new package `xsschema` * chore: clean cspell config * fix(tsconfig): add reference * fix(xsschema): add json-schema types to dev deps * chore(xsschema): export schema type * fix(xsschema): export schema type * refactor!: use xsschema instead of typeschema * fix(generate-object): direct return * fix(tool): drop tool result generic type * fix(xsschema): mark return type, handle unknown vendor * feat(xsschema): export json schema type * chore(generate-text): update test snapshot * fix(generate-text): check content length * chore(tool): update test snapshot
- Loading branch information
Showing
22 changed files
with
204 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
/// <reference types="@xsai/generate-text" /> | ||
|
||
import type { Schema } from '@typeschema/main' | ||
|
||
import type { ToolResult } from '.' | ||
|
||
declare module '@xsai/generate-text' { | ||
export interface GenerateTextOptions { | ||
tools?: ToolResult<Schema>[] | ||
tools?: ToolResult[] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`@xsai/tool > generateText with tool 1`] = `"In San Francisco, it's currently 42°F."`; | ||
exports[`@xsai/tool > generateText with tool 1`] = `"Right now, it's 42°F (6°C) partly cloudy in San Francisco."`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"name": "xsschema", | ||
"type": "module", | ||
"version": "0.0.31", | ||
"private": true, | ||
"description": "extra-small, Standard Schema-based alternative to typeschema.", | ||
"author": "Moeru AI", | ||
"license": "MIT", | ||
"homepage": "https://xsai.js.org", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/moeru-ai/xsai.git", | ||
"directory": "packages/xsschema" | ||
}, | ||
"bugs": "https://github.com/moeru-ai/xsai/issues", | ||
"keywords": [ | ||
"xsai", | ||
"standard-schema", | ||
"typeschema" | ||
], | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "pkgroll", | ||
"build:watch": "pkgroll --watch" | ||
}, | ||
"peerDependencies": { | ||
"@valibot/to-json-schema": "catalog:", | ||
"zod-to-json-schema": "^3.24.1" | ||
}, | ||
"peerDependenciesMeta": { | ||
"@valibot/to-json-schema": { | ||
"optional": true | ||
}, | ||
"zod-to-json-schema": { | ||
"optional": true | ||
} | ||
}, | ||
"dependencies": { | ||
"@standard-schema/spec": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/json-schema": "^7.0.15", | ||
"@valibot/to-json-schema": "catalog:", | ||
"zod-to-json-schema": "^3.24.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { toJsonSchema, toJsonSchema as toJSONSchema } from './to-json-schema' | ||
export type { Infer, InferIn, JSONSchema as JsonSchema, JSONSchema, Schema } from './types' | ||
export { validate } from './validate' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { StandardSchemaV1 } from '@standard-schema/spec' | ||
import type { JSONSchema7 } from 'json-schema' | ||
|
||
export const toJsonSchema = async (schema: StandardSchemaV1): Promise<JSONSchema7> => { | ||
switch (schema['~standard'].vendor) { | ||
case 'valibot': | ||
// eslint-disable-next-line ts/no-unsafe-argument | ||
return (await import('./valibot')).toJsonSchema(schema as any) | ||
case 'zod': | ||
// eslint-disable-next-line ts/no-unsafe-argument, @masknet/type-prefer-return-type-annotation | ||
return (await import('./zod')).toJsonSchema(schema as any) as JSONSchema7 | ||
default: | ||
throw new Error(`xsschema: Unsupported schema vendor ${schema['~standard'].vendor}`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { toJsonSchema } from '@valibot/to-json-schema' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { zodToJsonSchema as toJsonSchema } from 'zod-to-json-schema' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { StandardSchemaV1 } from '@standard-schema/spec' | ||
|
||
export type { StandardSchemaV1 as Schema } from '@standard-schema/spec' | ||
export type { JSONSchema7 as JSONSchema } from 'json-schema' | ||
|
||
export type Infer<T extends StandardSchemaV1> = StandardSchemaV1.InferOutput<T> | ||
export type InferIn<T extends StandardSchemaV1> = StandardSchemaV1.InferInput<T> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { StandardSchemaV1 } from '@standard-schema/spec' | ||
|
||
export const validate = async <T extends StandardSchemaV1>(schema: T, input: StandardSchemaV1.InferInput<T>): Promise<StandardSchemaV1.InferOutput<T>> => { | ||
let result = schema['~standard'].validate(input) | ||
if (result instanceof Promise) | ||
result = await result | ||
|
||
if (result.issues) { | ||
throw new Error(JSON.stringify(result.issues, null, 2)) | ||
} | ||
|
||
return result.value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "@importantimport/tsconfig/app.json", | ||
"include": ["src"] | ||
} |
Oops, something went wrong.