attachref

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package attachref resolves S3-backed attachment references (`s3ref:K`) emitted by agentsdk.attachToContext into storage-ready or LLM-ready forms.

Two entry points share a canonicalize helper:

  • ResolveForStorage: invoked at SessionAppend time on []session.Message. For any part whose Image/Data carries an `s3ref:K` sentinel, we canonicalize to a derived blob at `llm/agents/<agentID>/K` (fetching, preprocessing and PUTting if missing), and stamp the canonical key into Source. The sentinel stays in Image/Data so future loads can re-resolve without reading Source.

  • ResolveForLLM: invoked on the LLM-bound goai []message.Message before the provider stream call. Overwrites the Image/Data sentinel with either a presigned URL (URL mode) or base64 bytes (inline mode), governed by the provider's AttachmentPolicy. Enforces a request-wide inline cap — excess inline parts are evicted to text placeholders that preserve the re-attach path.

Providers never see `s3ref:` — the resolver always overwrites before handing the message off.

Index

Constants

View Source
const Sentinel = "s3ref:"

Sentinel is the prefix that marks an Image/Data field as an S3 reference rather than base64 or a URL. Value after the colon is the agent-facing key (no `agents/<id>/` scope — airlock adds that).

Variables

This section is empty.

Functions

func ResolveForLLM

func ResolveForLLM(ctx context.Context, s3 *storage.S3Client, q *dbq.Queries, agentID uuid.UUID, policy solprovider.AttachmentPolicy, msgs []message.Message) error

ResolveForLLM resolves s3ref sentinels on goai messages, rewriting Image/Data with presigned URLs (URL mode) or base64 bytes (inline mode) per policy. Enforces the request-wide inline cap by evicting oldest parts to text placeholders.

URL mode reads/writes attachment_url_cache so the same canonical key returns the same URL string across turns, keeping provider prompt cache stable. Pass q=nil to disable the cache (useful in tests).

Mutates msgs in place.

func ResolveForStorage

func ResolveForStorage(ctx context.Context, s3 *storage.S3Client, agentID uuid.UUID, msgs []solsession.Message) error

ResolveForStorage canonicalizes s3ref sentinels on session.Messages and writes canonical derived keys into Source. Leaves the sentinel in the file part's Data (tiny, enables re-resolution without reading Source).

Mutates msgs in place. Returns the first error encountered — callers should treat the whole batch as failed (don't persist partial state).

func ScheduleDelete

func ScheduleDelete(ctx context.Context, s3 *storage.S3Client, logger *zap.Logger, keys []string)

ScheduleDelete fires-and-forgets S3 DeleteObject calls for the given keys. Runs in a detached goroutine with a context that outlives the request (WithoutCancel + 30s deadline per key) so an HTTP request completing doesn't abort mid-cleanup.

Errors are logged; they do not propagate back to the caller. This matches the inline-goroutine pattern used by airlock's other background work (see cmd/airlock/main.go event cleanup).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL