Extract client SDK package (#1052)
* Extract client SDK package * Polish SDK client identity defaults * Build client before dependent CI jobs * Restore daemon client server export * Extract protocol and client SDK packages * Fix provider override schema validation * Fix app test daemon client imports * Simplify workspace build targets * Fix CLI test server build bootstrap * Run SDK package tests in CI * Fix rebase package split drift * Restore lockfile registry metadata * Update SDK config test for prompt default * Move terminal stream router test to client package * Fix rebase drift for protocol imports * Fix SDK agent capability fixture * Restore legacy server client exports * Fix server export compatibility test * Advertise custom mode icon client capability * Remove server daemon-client exports * Format rebased mode control import * Fix rebase drift for protocol imports Files added by upstream PRs (#893, #1147, #1154) referenced the pre-split shared/ paths that this branch moves into @getpaseo/protocol. Redirect those imports to the protocol package so typecheck stays green after the rebase.
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
import { z } from "zod";
|
||||
import type { AgentProvider } from "./agent-types.js";
|
||||
import { AgentProviderSchema } from "./provider-manifest.js";
|
||||
|
||||
const ProviderCommandDefaultSchema = z
|
||||
.object({
|
||||
mode: z.literal("default"),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const ProviderCommandAppendSchema = z
|
||||
.object({
|
||||
mode: z.literal("append"),
|
||||
args: z.array(z.string()).optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const ProviderCommandReplaceSchema = z
|
||||
.object({
|
||||
mode: z.literal("replace"),
|
||||
argv: z.array(z.string().min(1)).min(1),
|
||||
})
|
||||
.strict();
|
||||
|
||||
export const ProviderCommandSchema = z.discriminatedUnion("mode", [
|
||||
ProviderCommandDefaultSchema,
|
||||
ProviderCommandAppendSchema,
|
||||
ProviderCommandReplaceSchema,
|
||||
]);
|
||||
|
||||
export const ProviderRuntimeSettingsSchema = z
|
||||
.object({
|
||||
command: ProviderCommandSchema.optional(),
|
||||
env: z.record(z.string()).optional(),
|
||||
disallowedTools: z.array(z.string()).optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const ProviderProfileThinkingOptionSchema = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
label: z.string(),
|
||||
description: z.string().optional(),
|
||||
isDefault: z.boolean().optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
export const ProviderProfileModelSchema = z
|
||||
.object({
|
||||
id: z.string().min(1),
|
||||
label: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
isDefault: z.boolean().optional(),
|
||||
thinkingOptions: z.array(ProviderProfileThinkingOptionSchema).optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
export const ProviderOverrideSchema = z
|
||||
.object({
|
||||
extends: z.string().optional(),
|
||||
label: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
command: z.array(z.string().min(1)).min(1).optional(),
|
||||
env: z.record(z.string()).optional(),
|
||||
models: z.array(ProviderProfileModelSchema).optional(),
|
||||
additionalModels: z.array(ProviderProfileModelSchema).optional(),
|
||||
disallowedTools: z.array(z.string()).optional(),
|
||||
enabled: z.boolean().optional(),
|
||||
order: z.number().optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const BUILTIN_PROVIDER_IDS = ["claude", "codex", "copilot", "opencode", "pi"] as const;
|
||||
const PROVIDER_ID_PATTERN = /^[a-z][a-z0-9-]*$/;
|
||||
|
||||
export const ProviderOverridesSchema = z
|
||||
.record(ProviderOverrideSchema)
|
||||
.superRefine((providers, ctx) => {
|
||||
const builtinProviderIdSet = new Set<string>(BUILTIN_PROVIDER_IDS);
|
||||
const validExtendsValues = new Set<string>([...BUILTIN_PROVIDER_IDS, "acp"]);
|
||||
|
||||
for (const [providerId, provider] of Object.entries(providers)) {
|
||||
if (!PROVIDER_ID_PATTERN.test(providerId)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: [providerId],
|
||||
message: `Provider ID "${providerId}" must match ${PROVIDER_ID_PATTERN}.`,
|
||||
});
|
||||
}
|
||||
|
||||
const isBuiltinProvider = builtinProviderIdSet.has(providerId);
|
||||
if (!isBuiltinProvider && !provider.extends) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: [providerId, "extends"],
|
||||
message: `Custom provider "${providerId}" must declare extends.`,
|
||||
});
|
||||
}
|
||||
|
||||
if (!isBuiltinProvider && !provider.label) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: [providerId, "label"],
|
||||
message: `Custom provider "${providerId}" must declare label.`,
|
||||
});
|
||||
}
|
||||
|
||||
if (provider.extends && !validExtendsValues.has(provider.extends)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: [providerId, "extends"],
|
||||
message: `Provider "${providerId}" extends unknown provider "${provider.extends}".`,
|
||||
});
|
||||
}
|
||||
|
||||
if (provider.extends === "acp" && !provider.command) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: [providerId, "command"],
|
||||
message: `Provider "${providerId}" extending "acp" must declare command.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export const AgentProviderRuntimeSettingsMapSchema = z
|
||||
.record(ProviderRuntimeSettingsSchema)
|
||||
.superRefine((providers, ctx) => {
|
||||
for (const providerId of Object.keys(providers)) {
|
||||
const parsedProviderId = AgentProviderSchema.safeParse(providerId);
|
||||
if (!parsedProviderId.success) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: [providerId],
|
||||
message: `Invalid agent provider "${providerId}".`,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export type ProviderCommand = z.infer<typeof ProviderCommandSchema>;
|
||||
export type ProviderRuntimeSettings = z.infer<typeof ProviderRuntimeSettingsSchema>;
|
||||
export type ProviderProfileModel = z.infer<typeof ProviderProfileModelSchema>;
|
||||
export type ProviderOverride = z.infer<typeof ProviderOverrideSchema>;
|
||||
export type ProviderOverrides = z.infer<typeof ProviderOverridesSchema>;
|
||||
export type AgentProviderRuntimeSettingsMap = Partial<
|
||||
Record<AgentProvider, ProviderRuntimeSettings>
|
||||
>;
|
||||
Reference in New Issue
Block a user