Agent Rooms
Artifacts

Optional artifacts

@agentplat/artifacts@1.4.0 provides tenant-scoped artifact metadata, immutable content revisions, explicit reads and writes, runtime tools, and reference-only events. The @agentplat/artifacts-postgres@1.4.0 adapter persists revisions with transactional compare-and-set (CAS) and an event outbox.

Supported inert UTF-8 formats are Markdown, plain text, source code, CSV, HTML and JSON. JSON is syntax-checked and retained as text; artifact content is never executed. These packages do not generate PDF, XLSX or PPTX files.

Opt-in activation

Installing packages alone does not expose artifact capabilities to agents. The host explicitly constructs a service and registers tools in the runtime tool registry. Tool calls must use a verified tenant context; the baseline restricts access to the creating owner in that tenant. A host can add broader authorization only through its own reviewed policy layer.

For local use, InMemoryArtifactStore is process-local and not durable. For PostgreSQL, follow the package migration entry point and migration documentation in the pinned @agentplat/artifacts-postgres release before constructing PostgresArtifactStore. Adapter construction does not apply schema migrations. Add the migration as an explicit deployment step, back up the selected schema, and verify status before starting consumers. The adapter's destructive rollback drops artifact data and requires explicit confirmation.

Updates require an expected revision. A stale head returns a conflict; successful writes create immutable revisions. When an event publisher is supplied to ArtifactService, the PostgreSQL adapter writes reference events to its outbox in the revision transaction. Delivery is at least once, so workers and downstream consumers must deduplicate by stable event ID and apply a retention policy to delivered rows.

HTML remains inert artifact content. If an application renders it, use an isolated origin or strict sandbox with restrictive CSP. The host remains responsible for identity, authorization, quotas, retention, API delivery, UI and any document generation.

Agent tools

Register artifact tools only when the application intends an agent to read or write artifacts. Bind tenant, owner, Room, message and run authority from verified server-side execution context; do not accept those fields from model arguments. See the package README (opens in a new tab) and catalog.

PostgreSQL namespace and migrations

Use a different schema from Rooms. Both adapters define a table named artifacts with different contracts; sharing the namespace is unsupported. For example, use agentplat_rooms for Rooms/workflows and agentplat_artifacts for this adapter. The schema passed to the store must match its migration runner. Have an administrator provision the namespaces with the intended application owner, then use scoped application credentials with createSchema: false; do not grant database-wide CREATE to the runtime role. See the coordinated migration example. Artifacts requires migrations 001 and 002 in its own application ledger.

Runnable local lifecycle example

This example uses only process-local storage and no provider credentials. Save it as artifacts.mjs in a Node.js 22.13+ project after installation:

npm install @agentplat/artifacts@1.4.0 @agentplat/events@1.4.0 @agentplat/tools@1.4.0
node artifacts.mjs
import { ArtifactService, InMemoryArtifactStore, registerArtifactTools } from '@agentplat/artifacts';
import { InMemoryEventBus } from '@agentplat/events';
import { InMemoryToolRegistry } from '@agentplat/tools';
 
// Demonstration identity only. Production derives this from verified authentication.
const tenant = {
  tenantId: 'demo-tenant',
  actor: { actorId: 'demo-owner', actorType: 'machine' },
};
const events = new InMemoryEventBus();
const service = new ArtifactService({
  store: new InMemoryArtifactStore(),
  events,
  maximumContentBytes: 200_000,
});
const tools = new InMemoryToolRegistry();
await registerArtifactTools(tools, service);
const created = await service.create(tenant, {
  name: 'proposal.md', format: 'markdown', content: '# Initial draft',
});
await service.update(tenant, {
  artifactId: created.id, expectedRevision: 1, content: '# Reviewed draft',
});
console.log((await service.read(tenant, created.id)).revision.content);
console.log((await service.read(tenant, created.id, 1)).revision.content);

The registry must be explicitly supplied to the agent runtime for tools to become available. Registration alone does not invoke a model. The host must expose only the operations currently permitted for that agent and recheck authorization on every invocation. Tool arguments such as Room links do not establish membership or authority; bind them from verified server execution context.

For durable storage, replace the in-memory store with new PostgresArtifactStore(pool, 'agentplat_artifacts') after migrating. If events are enabled, run drainArtifactOutbox(store, publisher) from a worker with stable ID deduplication, retry monitoring and retention. Merely applying migration 002 does not start a dispatcher or deliver notifications. Applications that supply no publisher must not claim event delivery.

For HTML previews, keep original revisions unchanged and sanitize the preview server-side. Use an iframe with an empty sandbox, restrictive CSP, no form or navigation privileges and no ambient credentials, or a separately isolated origin. Provide authorized downloads with explicit content type, attachment filename, nosniff and private/no-store caching. CSV, JSON and code remain data; rendering or exporting them never authorizes execution.