Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ const (
)

type ToolExecutor struct {
store objectstore.Store
db workerdata.QueryDB
config sharedconfig.Resolver
routingLoader *routing.ConfigLoader
generate func(context.Context, llm.ResolvedGatewayConfig, llm.ImageGenerationRequest) (llm.GeneratedImage, error)
store objectstore.Store
messageAttachmentStore objectstore.Store
db workerdata.QueryDB
config sharedconfig.Resolver
routingLoader *routing.ConfigLoader
generate func(context.Context, llm.ResolvedGatewayConfig, llm.ImageGenerationRequest) (llm.GeneratedImage, error)
}

func NewToolExecutor(
Expand All @@ -49,6 +50,11 @@ func NewToolExecutor(
}
}

func (e *ToolExecutor) WithMessageAttachmentStore(s objectstore.Store) *ToolExecutor {
e.messageAttachmentStore = s
return e
}
Comment on lines +53 to +56

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Wire the attachment store into image generation

This setter is never used by the production registration path: registerStoredArtifactTools still constructs imagegeneratetool.NewToolExecutor(...) without chaining WithMessageAttachmentStore(attachmentStore). As a result, in normal worker/desktop composition messageAttachmentStore remains nil, so the fallback added below for unprefixed attachment keys is dead code and input_images that only exist in the message-attachment bucket still fail.

Useful? React with 👍 / 👎.


func (e *ToolExecutor) Execute(
ctx context.Context,
_ string,
Expand Down Expand Up @@ -251,6 +257,12 @@ func (e *ToolExecutor) loadInputImages(ctx context.Context, args map[string]any,
return nil, fmt.Errorf("input_images[%d] is outside the current account", idx)
}
data, contentType, err := e.store.GetWithContentType(ctx, key)
if err != nil && e.messageAttachmentStore != nil {
data, contentType, err = e.messageAttachmentStore.GetWithContentType(ctx, key)
}
if err != nil && e.messageAttachmentStore != nil && !strings.HasPrefix(key, "attachments/") {
data, contentType, err = e.messageAttachmentStore.GetWithContentType(ctx, "attachments/"+key)
}
if err != nil {
return nil, fmt.Errorf("input_images[%d] not found", idx)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ func authorizeObjectKey(ctx context.Context, store objectstore.Store, key string
return nil
}
info, err := store.Head(ctx, key)
if err != nil && objectstore.IsNotFound(err) && attachment && !strings.HasPrefix(key, "attachments/") {
info, err = store.Head(ctx, "attachments/"+key)
}
Comment on lines +126 to +128

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fetch the same fallback key that was authorized

When an attachment is passed as attachment:<account_id>/... and the object exists only at attachments/<account_id>/..., this fallback can authorize the prefixed object, but fetch then calls getObject(ctx, e.AttachmentStore, key) with the original unprefixed key. In real stores where GetWithContentType returns not-found for the unprefixed key, the copy still fails after authorization succeeds; the resolved fallback key needs to be used for the subsequent read as well.

Useful? React with 👍 / 👎.

if err != nil {
return &tools.ExecutionError{ErrorClass: errorFetchFailed, Message: fmt.Sprintf("read resource metadata failed: %s", err.Error())}
}
Expand Down
Loading