kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
ab32e0bb6a
commit
8883117afb
|
@ -9,17 +9,17 @@ import type { GatewayHonoContext, ToolCallArgs } from './types'
|
|||
export async function createRequestForOpenAPIOperation(
|
||||
ctx: GatewayHonoContext,
|
||||
{
|
||||
toolArgs,
|
||||
toolCallArgs,
|
||||
operation,
|
||||
deployment
|
||||
}: {
|
||||
toolArgs: ToolCallArgs
|
||||
toolCallArgs: ToolCallArgs
|
||||
operation: OpenAPIToolOperation
|
||||
deployment: AdminDeployment
|
||||
}
|
||||
): Promise<Request> {
|
||||
const request = ctx.req.raw
|
||||
assert(toolArgs, 500, 'Tool args are required')
|
||||
assert(toolCallArgs, 500, 'Tool args are required')
|
||||
assert(
|
||||
deployment.originAdapter.type === 'openapi',
|
||||
500,
|
||||
|
@ -49,12 +49,12 @@ export async function createRequestForOpenAPIOperation(
|
|||
|
||||
if (headerParams.length > 0) {
|
||||
for (const [key] of headerParams) {
|
||||
headers[key] = (request.headers.get(key) as string) ?? toolArgs[key]
|
||||
headers[key] = (request.headers.get(key) as string) ?? toolCallArgs[key]
|
||||
}
|
||||
}
|
||||
|
||||
for (const [key] of cookieParams) {
|
||||
headers[key] = String(toolArgs[key])
|
||||
headers[key] = String(toolCallArgs[key])
|
||||
}
|
||||
|
||||
let body: string | undefined
|
||||
|
@ -62,7 +62,7 @@ export async function createRequestForOpenAPIOperation(
|
|||
body = JSON.stringify(
|
||||
Object.fromEntries(
|
||||
bodyParams
|
||||
.map(([key]) => [key, toolArgs[key]])
|
||||
.map(([key]) => [key, toolCallArgs[key]])
|
||||
// Prune undefined values. We know these aren't required fields,
|
||||
// because the incoming request params have already been validated
|
||||
// against the tool's input schema.
|
||||
|
@ -75,7 +75,7 @@ export async function createRequestForOpenAPIOperation(
|
|||
// TODO: Double-check FormData usage.
|
||||
const formData = new FormData()
|
||||
for (const [key] of formDataParams) {
|
||||
const value = toolArgs[key]
|
||||
const value = toolCallArgs[key]
|
||||
if (value !== undefined) {
|
||||
formData.append(key, value)
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ export async function createRequestForOpenAPIOperation(
|
|||
let path = operation.path
|
||||
if (pathParams.length > 0) {
|
||||
for (const [key] of pathParams) {
|
||||
const value: string = toolArgs[key]
|
||||
const value: string = toolCallArgs[key]
|
||||
assert(value, 400, `Missing required parameter "${key}"`)
|
||||
|
||||
const pathParamPlaceholder = `{${key}}`
|
||||
|
@ -109,7 +109,7 @@ export async function createRequestForOpenAPIOperation(
|
|||
|
||||
const query = new URLSearchParams()
|
||||
for (const [key] of queryParams) {
|
||||
query.set(key, toolArgs[key] as string)
|
||||
query.set(key, toolCallArgs[key] as string)
|
||||
}
|
||||
const queryString = query.toString()
|
||||
const originRequestUrl = `${deployment.originUrl}${path}${
|
||||
|
|
|
@ -177,13 +177,15 @@ export async function resolveOriginRequest(
|
|||
|
||||
const { originAdapter } = deployment
|
||||
let originRequest: Request | undefined
|
||||
let toolArgs: ToolCallArgs | undefined
|
||||
let toolCallArgs: ToolCallArgs | undefined
|
||||
|
||||
if (originAdapter.type === 'raw') {
|
||||
const originRequestUrl = `${deployment.originUrl}/${toolName}${requestUrl.search}`
|
||||
originRequest = new Request(originRequestUrl, ctx.req.raw)
|
||||
} else {
|
||||
toolArgs = await getToolArgsFromRequest(ctx, {
|
||||
// Parse tool call args from the request body for both OpenAPI and MCP
|
||||
// origin adapters.
|
||||
toolCallArgs = await getToolArgsFromRequest(ctx, {
|
||||
tool,
|
||||
deployment
|
||||
})
|
||||
|
@ -192,9 +194,10 @@ export async function resolveOriginRequest(
|
|||
if (originAdapter.type === 'openapi') {
|
||||
const operation = originAdapter.toolToOperationMap[tool.name]
|
||||
assert(operation, 404, `Tool "${tool.name}" not found in OpenAPI spec`)
|
||||
assert(toolCallArgs, 500)
|
||||
|
||||
originRequest = await createRequestForOpenAPIOperation(ctx, {
|
||||
toolArgs: toolArgs!,
|
||||
toolCallArgs,
|
||||
operation,
|
||||
deployment
|
||||
})
|
||||
|
@ -207,7 +210,7 @@ export async function resolveOriginRequest(
|
|||
|
||||
return {
|
||||
originRequest,
|
||||
toolCallArgs: toolArgs,
|
||||
toolCallArgs,
|
||||
deployment,
|
||||
consumer,
|
||||
tool,
|
||||
|
|
|
@ -54,6 +54,8 @@
|
|||
## TODO Post-MVP
|
||||
|
||||
- first-party deployment hosting
|
||||
- auth
|
||||
- custom auth provider configs for projects/deployments
|
||||
- stripe
|
||||
- re-add coupons
|
||||
- declarative json-based pricing
|
||||
|
|
Ładowanie…
Reference in New Issue