Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
0109aced
authored
Jul 31, 2026
by
Finley Ge
Committed by
GitHub
Jul 31, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(tool-runtime): support JSON Schema 2019-09 and 2020-12 dialects (#7425)
parent
7d4943e9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
2 deletions
+42
-2
packages/global/core/app/tool/runtime.ts
+16
-2
packages/global/test/core/app/tool/runtime.test.ts
+26
-0
No files found.
packages/global/core/app/tool/runtime.ts
View file @
0109aced
import
Ajv
,
{
type
ErrorObject
,
type
ValidateFunction
}
from
'ajv'
;
import
Ajv
,
{
type
ErrorObject
,
type
ValidateFunction
}
from
'ajv'
;
import
Ajv2019
from
'ajv/dist/2019'
;
import
Ajv2020
from
'ajv/dist/2020'
;
import
type
{
ChatCompletionTool
}
from
'../../ai/llm/type'
;
import
type
{
ChatCompletionTool
}
from
'../../ai/llm/type'
;
import
type
{
FlowNodeInputItemType
}
from
'../../workflow/type/io'
;
import
type
{
FlowNodeInputItemType
}
from
'../../workflow/type/io'
;
import
{
AgentToolInputModeEnum
}
from
'./constants'
;
import
{
AgentToolInputModeEnum
}
from
'./constants'
;
...
@@ -176,15 +178,27 @@ export type ToolSchemaValidationResult = {
...
@@ -176,15 +178,27 @@ export type ToolSchemaValidationResult = {
errors
:
string
[];
errors
:
string
[];
};
};
const
ajv
=
new
Ajv
({
allErrors
:
true
,
strict
:
false
,
validateFormats
:
false
});
const
ajvOptions
=
{
allErrors
:
true
,
strict
:
false
,
validateFormats
:
false
}
as
const
;
const
ajvDraft7
=
new
Ajv
(
ajvOptions
);
const
ajvDraft2019
=
new
Ajv2019
(
ajvOptions
);
const
ajvDraft2020
=
new
Ajv2020
(
ajvOptions
);
const
validatorCache
=
new
Map
<
string
,
ValidateFunction
>
();
const
validatorCache
=
new
Map
<
string
,
ValidateFunction
>
();
const
getAjv
=
(
schema
:
object
)
=>
{
const
dialect
=
(
schema
as
{
$schema
?:
unknown
}).
$schema
;
if
(
typeof
dialect
===
'string'
)
{
if
(
dialect
.
includes
(
'/draft/2020-12/'
))
return
ajvDraft2020
;
if
(
dialect
.
includes
(
'/draft/2019-09/'
))
return
ajvDraft2019
;
}
return
ajvDraft7
;
};
const
getValidator
=
(
schema
:
object
)
=>
{
const
getValidator
=
(
schema
:
object
)
=>
{
const
cacheKey
=
JSON
.
stringify
(
schema
);
const
cacheKey
=
JSON
.
stringify
(
schema
);
const
cached
=
validatorCache
.
get
(
cacheKey
);
const
cached
=
validatorCache
.
get
(
cacheKey
);
if
(
cached
)
return
cached
;
if
(
cached
)
return
cached
;
const
validator
=
ajv
.
compile
(
schema
);
const
validator
=
getAjv
(
schema
)
.
compile
(
schema
);
validatorCache
.
set
(
cacheKey
,
validator
);
validatorCache
.
set
(
cacheKey
,
validator
);
return
validator
;
return
validator
;
};
};
...
...
packages/global/test/core/app/tool/runtime.test.ts
View file @
0109aced
...
@@ -296,4 +296,30 @@ describe('JSON Schema runtime validation', () => {
...
@@ -296,4 +296,30 @@ describe('JSON Schema runtime validation', () => {
.
success
.
success
).
toBe
(
false
);
).
toBe
(
false
);
});
});
it
(
'validates draft 2020-12 schemas with the matching AJV dialect'
,
()
=>
{
const
jsonSchema
=
{
$schema
:
'https://json-schema.org/draft/2020-12/schema'
,
type
:
'object'
,
properties
:
{
query
:
{
type
:
'string'
,
minLength
:
3
}
},
required
:
[
'query'
],
additionalProperties
:
false
};
expect
(
validateToolRuntimeParams
({
jsonSchema
,
params
:
{
query
:
'fastgpt'
}
})
).
toEqual
({
success
:
true
,
errors
:
[]
});
const
invalid
=
validateToolRuntimeParams
({
jsonSchema
,
params
:
{
query
:
'x'
}
});
expect
(
invalid
.
success
).
toBe
(
false
);
expect
(
invalid
.
errors
.
length
).
toBeGreaterThan
(
0
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment