kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: first e2e test with gateway working :)
rodzic
a63c75f99e
commit
da9188c49f
|
@ -39,6 +39,7 @@
|
|||
"eventid": "catalog:",
|
||||
"fast-content-type-parse": "^3.0.0",
|
||||
"hono": "catalog:",
|
||||
"plur": "^5.1.0",
|
||||
"type-fest": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -5,7 +5,7 @@ import type {
|
|||
} from '@agentic/platform-types'
|
||||
import { assert } from '@agentic/platform-core'
|
||||
|
||||
import { validateJsonSchema } from './validate-json-schema'
|
||||
import { validateJsonSchemaObject } from './validate-json-schema-object'
|
||||
|
||||
export async function createRequestForOpenAPIOperation({
|
||||
request,
|
||||
|
@ -29,7 +29,7 @@ export async function createRequestForOpenAPIOperation({
|
|||
let incomingRequestParams: Record<string, any> = {}
|
||||
if (request.method === 'GET') {
|
||||
incomingRequestParams = Object.fromEntries(
|
||||
new URLSearchParams(tempInitialRequest.url).entries()
|
||||
new URL(tempInitialRequest.url).searchParams.entries()
|
||||
)
|
||||
} else if (request.method === 'POST') {
|
||||
incomingRequestParams = (await tempInitialRequest.json()) as Record<
|
||||
|
@ -39,7 +39,7 @@ export async function createRequestForOpenAPIOperation({
|
|||
}
|
||||
|
||||
// TODO: Validate incoming request params against the tool's input JSON schema
|
||||
validateJsonSchema({
|
||||
validateJsonSchemaObject({
|
||||
schema: tool.inputSchema,
|
||||
data: incomingRequestParams,
|
||||
errorMessage: `Invalid request parameters for tool "${tool.name}"`
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
import { HttpError } from '@agentic/platform-core'
|
||||
import { Validator } from '@cfworker/json-schema'
|
||||
|
||||
export function validateJsonSchema<
|
||||
T extends Record<string, unknown> = Record<string, unknown>
|
||||
>({
|
||||
schema,
|
||||
data,
|
||||
errorMessage
|
||||
}: {
|
||||
schema: any
|
||||
data: unknown
|
||||
errorMessage?: string
|
||||
}): T {
|
||||
const validator = new Validator(schema)
|
||||
|
||||
const result = validator.validate(data)
|
||||
if (result.valid) {
|
||||
return data as T
|
||||
}
|
||||
|
||||
const finalErrorMessage = [
|
||||
errorMessage,
|
||||
...result.errors.map((error) => JSON.stringify(error, null, 2))
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('\n')
|
||||
|
||||
throw new HttpError({
|
||||
statusCode: 400,
|
||||
message: finalErrorMessage
|
||||
})
|
||||
}
|
|
@ -400,6 +400,9 @@ importers:
|
|||
hono:
|
||||
specifier: 'catalog:'
|
||||
version: 4.7.10
|
||||
plur:
|
||||
specifier: ^5.1.0
|
||||
version: 5.1.0
|
||||
type-fest:
|
||||
specifier: 'catalog:'
|
||||
version: 4.41.0
|
||||
|
@ -3136,6 +3139,10 @@ packages:
|
|||
resolution: {integrity: sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==}
|
||||
engines: {node: '>= 0.10'}
|
||||
|
||||
irregular-plurals@3.5.0:
|
||||
resolution: {integrity: sha512-1ANGLZ+Nkv1ptFb2pa8oG8Lem4krflKuX/gINiHJHjJUKaJHk/SXk5x6K3J+39/p0h1RQ2saROclJJ+QLvETCQ==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
is-absolute-url@4.0.1:
|
||||
resolution: {integrity: sha512-/51/TKE88Lmm7Gc4/8btclNXWS+g50wXhYJq8HWIBAGUBnoAdRu1aXeh364t/O7wXDAcTJDP8PNuNKWUDWie+A==}
|
||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||
|
@ -3780,6 +3787,10 @@ packages:
|
|||
pkg-types@1.3.1:
|
||||
resolution: {integrity: sha512-/Jm5M4RvtBFVkKWRu2BLUTNP8/M2a+UwuAX+ae4770q1qVGtfjG+WTCupoZixokjmHiry8uI+dlY8KXYV5HVVQ==}
|
||||
|
||||
plur@5.1.0:
|
||||
resolution: {integrity: sha512-VP/72JeXqak2KiOzjgKtQen5y3IZHn+9GOuLDafPv0eXa47xq0At93XahYBs26MsifCQ4enGKwbjBTKgb9QJXg==}
|
||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||
|
||||
pluralize@8.0.0:
|
||||
resolution: {integrity: sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==}
|
||||
engines: {node: '>=4'}
|
||||
|
@ -7198,6 +7209,8 @@ snapshots:
|
|||
|
||||
ipaddr.js@1.9.1: {}
|
||||
|
||||
irregular-plurals@3.5.0: {}
|
||||
|
||||
is-absolute-url@4.0.1: {}
|
||||
|
||||
is-array-buffer@3.0.5:
|
||||
|
@ -7848,6 +7861,10 @@ snapshots:
|
|||
mlly: 1.7.4
|
||||
pathe: 2.0.3
|
||||
|
||||
plur@5.1.0:
|
||||
dependencies:
|
||||
irregular-plurals: 3.5.0
|
||||
|
||||
pluralize@8.0.0: {}
|
||||
|
||||
possible-typed-array-names@1.1.0: {}
|
||||
|
|
Ładowanie…
Reference in New Issue