authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-02-12 15:46:34-08:00
committergravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-02-12 15:46:34-08:00
log73bc60ef8a3c43126c40f317ec65ca38c0a045ba
tree1db4574941823d9df60a93f3b667fc1766b5e7c0
parent86e7bd000c2b13fb1f3fbf946d61a6ed16b6fa87

simp


1 files changed, 24 insertions(+), 40 deletions(-)

packages/contracts/src/provider.ts+24-40
...@@ -59,17 +59,7 @@ export const PROVIDER_SEND_TURN_MAX_ATTACHMENTS = 8;...@@ -59,17 +59,7 @@ export const PROVIDER_SEND_TURN_MAX_ATTACHMENTS = 8;
59export const PROVIDER_SEND_TURN_MAX_IMAGE_BYTES = 10 * 1024 * 1024;59export const PROVIDER_SEND_TURN_MAX_IMAGE_BYTES = 10 * 1024 * 1024;
60export const PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS = 14_000_000;60export const PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS = 14_000_000;
6161
62function validateImageDataUrl(value: { dataUrl: string }, ctx: z.RefinementCtx): void {62export const providerSendTurnImageAttachmentSchema = z.object({
63 if (!value.dataUrl.startsWith("data:image/")) {
64 ctx.addIssue({
65 code: z.ZodIssueCode.custom,
66 message: "Image dataUrl must start with data:image/",
67 path: ["dataUrl"],
68 });
69 }
70}
71
72const providerSendTurnImageAttachmentBaseSchema = z.object({
73 type: z.literal("image"),63 type: z.literal("image"),
74 name: z.string().trim().min(1).max(255),64 name: z.string().trim().min(1).max(255),
75 mimeType: z65 mimeType: z
...@@ -82,35 +72,30 @@ const providerSendTurnImageAttachmentBaseSchema = z.object({...@@ -82,35 +72,30 @@ const providerSendTurnImageAttachmentBaseSchema = z.object({
82 dataUrl: z.string().trim().min(1).max(PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS),72 dataUrl: z.string().trim().min(1).max(PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS),
83});73});
8474
85export const providerSendTurnImageAttachmentInputSchema =
86 providerSendTurnImageAttachmentBaseSchema.superRefine(validateImageDataUrl);
87
88export const providerSendTurnAttachmentInputSchema = z.discriminatedUnion("type", [75export const providerSendTurnAttachmentInputSchema = z.discriminatedUnion("type", [
89 providerSendTurnImageAttachmentBaseSchema,76 providerSendTurnImageAttachmentSchema,
90]).superRefine((value, ctx) => {77]);
91 if (value.type === "image") {
92 validateImageDataUrl(value, ctx);
93 }
94});
9578
96export const providerSendTurnInputSchema = z.object({79export const providerSendTurnInputSchema = z
97 sessionId: z.string().min(1),80 .object({
98 input: z.string().trim().min(1).max(PROVIDER_SEND_TURN_MAX_INPUT_CHARS).optional(),81 sessionId: z.string().min(1),
99 attachments: z82 input: z.string().trim().min(1).max(PROVIDER_SEND_TURN_MAX_INPUT_CHARS).optional(),
100 .array(providerSendTurnAttachmentInputSchema)83 attachments: z
101 .max(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)84 .array(providerSendTurnAttachmentInputSchema)
102 .default([]),85 .max(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)
103 model: z.string().trim().min(1).optional(),86 .default([]),
104 effort: z.string().trim().min(1).optional(),87 model: z.string().trim().min(1).optional(),
105}).superRefine((value, ctx) => {88 effort: z.string().trim().min(1).optional(),
106 if (!value.input && value.attachments.length === 0) {89 })
107 ctx.addIssue({90 .superRefine((value, ctx) => {
108 code: z.ZodIssueCode.custom,91 if (!value.input && value.attachments.length === 0) {
109 message: "Either input text or at least one attachment is required",92 ctx.addIssue({
110 path: ["input"],93 code: z.ZodIssueCode.custom,
111 });94 message: "Either input text or at least one attachment is required",
112 }95 path: ["input"],
113});96 });
97 }
98 });
11499
115export const providerTurnStartResultSchema = z.object({100export const providerTurnStartResultSchema = z.object({
116 threadId: z.string().min(1),101 threadId: z.string().min(1),
...@@ -159,8 +144,7 @@ export type ProviderApprovalDecision = z.infer<typeof providerApprovalDecisionSc...@@ -159,8 +144,7 @@ export type ProviderApprovalDecision = z.infer<typeof providerApprovalDecisionSc
159export type ProviderSessionStatus = z.infer<typeof providerSessionStatusSchema>;144export type ProviderSessionStatus = z.infer<typeof providerSessionStatusSchema>;
160export type ProviderSession = z.infer<typeof providerSessionSchema>;145export type ProviderSession = z.infer<typeof providerSessionSchema>;
161export type ProviderSessionStartInput = z.input<typeof providerSessionStartInputSchema>;146export type ProviderSessionStartInput = z.input<typeof providerSessionStartInputSchema>;
162export type ProviderSendTurnImageAttachment = z.infer<typeof providerSendTurnImageAttachmentInputSchema>;147export type ProviderSendTurnImageAttachment = z.infer<typeof providerSendTurnImageAttachmentSchema>;
163export type ProviderSendTurnImageAttachmentInput = z.input<typeof providerSendTurnImageAttachmentInputSchema>;
164export type ProviderSendTurnAttachment = z.infer<typeof providerSendTurnAttachmentInputSchema>;148export type ProviderSendTurnAttachment = z.infer<typeof providerSendTurnAttachmentInputSchema>;
165export type ProviderSendTurnAttachmentInput = z.input<typeof providerSendTurnAttachmentInputSchema>;149export type ProviderSendTurnAttachmentInput = z.input<typeof providerSendTurnAttachmentInputSchema>;
166export type ProviderSendTurnInput = z.input<typeof providerSendTurnInputSchema>;150export type ProviderSendTurnInput = z.input<typeof providerSendTurnInputSchema>;