fix: allow more attachments without raising the image payload budget (#12620)
This commit is contained in:
1 parent
1ba471a37c
commit
2b178231eb
9 files changed
+170
-39
No files matched your search
@@ -5,7 +5,7 @@ import * as Path from "effect/Path";
|
||||
import {
|
||||
type ClientOrchestrationCommand,
|
||||
type UserInputAttachments,
|
||||
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
|
||||
getProviderAttachmentLimitError,
|
||||
type IsoDateTime,
|
||||
type OrchestrationCommand,
|
||||
OrchestrationDispatchCommandError,
|
||||
@@ -142,13 +142,9 @@ export const normalizeDispatchCommand = (command: ClientOrchestrationCommand) =>
|
||||
canonicalCommand.type === "thread.turn.start"
|
||||
? canonicalCommand.message.attachments
|
||||
: Object.values(canonicalCommand.attachmentsByQuestionId ?? {}).flat();
|
||||
if (
|
||||
canonicalCommand.type === "thread.user-input.respond" &&
|
||||
attachments.length > PROVIDER_SEND_TURN_MAX_ATTACHMENTS
|
||||
) {
|
||||
return yield* new OrchestrationDispatchCommandError({
|
||||
message: `You can attach up to ${PROVIDER_SEND_TURN_MAX_ATTACHMENTS} files per question response.`,
|
||||
});
|
||||
const attachmentLimitError = getProviderAttachmentLimitError(attachments);
|
||||
if (attachmentLimitError) {
|
||||
return yield* new OrchestrationDispatchCommandError({ message: attachmentLimitError });
|
||||
}
|
||||
if (canonicalCommand.type === "thread.turn.start") {
|
||||
const clientAttachmentIds = new Set<string>();
|
||||
@@ -163,11 +159,12 @@ export const normalizeDispatchCommand = (command: ClientOrchestrationCommand) =>
|
||||
}
|
||||
}
|
||||
const claimedAttachmentPaths: string[] = [];
|
||||
const attachmentsWithDecodedSizes = [...attachments];
|
||||
// Context records bind to attachments by the id the client knew; they follow the rename.
|
||||
const finalAttachmentIdByClientId = new Map<string, string>();
|
||||
const normalizedAttachments = yield* Effect.forEach(
|
||||
attachments,
|
||||
(attachment) =>
|
||||
(attachment, index) =>
|
||||
Effect.gen(function* () {
|
||||
if (!("dataUrl" in attachment)) {
|
||||
const claim = planAttachmentClaim({
|
||||
@@ -259,6 +256,11 @@ export const normalizeDispatchCommand = (command: ClientOrchestrationCommand) =>
|
||||
sizeBytes: bytes.byteLength,
|
||||
...(attachment.source ? { source: attachment.source } : {}),
|
||||
};
|
||||
attachmentsWithDecodedSizes[index] = persistedAttachment;
|
||||
const decodedLimitError = getProviderAttachmentLimitError(attachmentsWithDecodedSizes);
|
||||
if (decodedLimitError) {
|
||||
return yield* new OrchestrationDispatchCommandError({ message: decodedLimitError });
|
||||
}
|
||||
|
||||
const attachmentPath = resolveAttachmentPath({
|
||||
attachmentsDir: serverConfig.attachmentsDir,
|
||||
@@ -286,6 +288,7 @@ export const normalizeDispatchCommand = (command: ClientOrchestrationCommand) =>
|
||||
}),
|
||||
),
|
||||
);
|
||||
claimedAttachmentPaths.push(attachmentPath);
|
||||
if (attachment.id !== undefined) {
|
||||
finalAttachmentIdByClientId.set(attachment.id, attachmentId);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user