feat(core): add embedded v2 session runtime and tool foundation (#30632)
This commit is contained in:
parent
c35267776a
commit
76ee87ead8
215 changed files with 31398 additions and 3332 deletions
|
|
@ -41,6 +41,20 @@ export const Native = Schema.Struct({
|
|||
export const Api = Schema.Union([AISDK, Native]).pipe(Schema.toTaggedUnion("type"))
|
||||
export type Api = typeof Api.Type
|
||||
|
||||
export const PublicAISDK = Schema.Struct({
|
||||
type: Schema.Literal("aisdk"),
|
||||
package: Schema.String,
|
||||
url: Schema.String.pipe(Schema.optional),
|
||||
})
|
||||
|
||||
export const PublicNative = Schema.Struct({
|
||||
type: Schema.Literal("native"),
|
||||
url: Schema.String.pipe(Schema.optional),
|
||||
})
|
||||
|
||||
export const PublicApi = Schema.Union([PublicAISDK, PublicNative]).pipe(Schema.toTaggedUnion("type"))
|
||||
export type PublicApi = typeof PublicApi.Type
|
||||
|
||||
export const Request = Schema.Struct({
|
||||
headers: Schema.Record(Schema.String, Schema.String),
|
||||
body: Schema.Record(Schema.String, Schema.Any),
|
||||
|
|
@ -86,3 +100,49 @@ export class Info extends Schema.Class<Info>("ProviderV2.Info")({
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
export class PublicInfo extends Schema.Class<PublicInfo>("ProviderV2.PublicInfo")({
|
||||
id: ID,
|
||||
name: Schema.String,
|
||||
enabled: Schema.Union([
|
||||
Schema.Literal(false),
|
||||
Schema.Struct({
|
||||
via: Schema.Literal("env"),
|
||||
name: Schema.String,
|
||||
}),
|
||||
Schema.Struct({
|
||||
via: Schema.Literal("account"),
|
||||
service: Schema.String,
|
||||
}),
|
||||
Schema.Struct({
|
||||
via: Schema.Literal("custom"),
|
||||
}),
|
||||
]),
|
||||
env: Schema.String.pipe(Schema.Array),
|
||||
api: PublicApi,
|
||||
}) {}
|
||||
|
||||
export function sanitizePublicUrl(value: string | undefined): string | undefined {
|
||||
if (!value) return undefined
|
||||
try {
|
||||
const url = new URL(value)
|
||||
return url.protocol === "http:" || url.protocol === "https:" ? url.origin : undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
export function toPublic(info: Info): PublicInfo {
|
||||
const enabled = info.enabled === false || info.enabled.via !== "custom" ? info.enabled : { via: "custom" as const }
|
||||
const api =
|
||||
info.api.type === "aisdk"
|
||||
? { type: info.api.type, package: info.api.package, url: sanitizePublicUrl(info.api.url) }
|
||||
: { type: info.api.type, url: sanitizePublicUrl(info.api.url) }
|
||||
return new PublicInfo({
|
||||
id: info.id,
|
||||
name: info.name,
|
||||
enabled,
|
||||
env: [...info.env],
|
||||
api,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue