Artifacts: resolve real artifacts by reference
A reference contains only resolverId, artifactId, and an optional revision; the App resolver provides the real content.
defineArtifactCatalog(resolvers) returns a read-only catalog and an asynchronous resolve(reference,context). Empty identities, unknown resolverId values, and non-function resolvers are rejected. The reference is snapshotted first, and the resolver receives the same reference plus App/cancellation/diagnostics context; cancellation during the wait or after resolution is not returned as success.
An artifact ID or revision is not a file path, access permission, proof of content authenticity, or publication receipt. The resolver must check the current caller, the real saved state, version, and expiry, and return an App-defined Value. The Kit does not store files, create download endpoints, or guarantee that delivery to a user is possible from the reference alone.
Progressive examples for the same business case
First resolve one explicit in-memory artifact
Beginner · Node.js
import { Artifacts } from '@jangts/agent-core/kits/artifacts';
const content = new Map([['manual', { text: 'Agent Core 使用说明', revision: '1' }]]);
const artifacts = Artifacts.defineArtifactCatalog([
{ id: 'document', resolve(reference) { const value = content.get(reference.artifactId); if (!value) throw new Error('产物不存在'); return value; } },
]);
const result = await artifacts.resolve({ resolverId: 'document', artifactId: 'manual' }, { app: {}, signal: new AbortController().signal });
console.log(result.text);import { Artifacts } from '@jangts/agent-core/kits/artifacts';
const content = new Map([['manual', { text: 'Agent Core 使用说明', revision: '1' }]]);
const artifacts = Artifacts.defineArtifactCatalog([
{ id: 'document', resolve(reference) { const value = content.get(reference.artifactId); if (!value)
throw new Error('产物不存在'); return value; } },
]);
const result = await artifacts.resolve({ resolverId: 'document', artifactId: 'manual' }, { app: {}, signal: new AbortController().signal });
console.log(result.text);Add real permission and revision verification to the same resolve
Configuration · Node.js
import { Artifacts } from '@jangts/agent-core/kits/artifacts';
type Value = { text: string; revision: string };
type App = { canRead: boolean; documents: Map<string, Value> };
const artifacts = Artifacts.defineArtifactCatalog<Value, App>([
{ id: 'document', async resolve(reference, { app, signal }) {
signal.throwIfAborted();
if (!app.canRead) throw new Error('没有产物读取权限');
const value = app.documents.get(reference.artifactId);
if (!value) throw new Error('产物不存在或已到期');
if (reference.revision && reference.revision !== value.revision) throw new Error('产物版本已变化');
return structuredClone(value);
} },
]);
const app = { canRead: true, documents: new Map([['manual', { text: 'Agent Core 使用说明', revision: '1' }]]) };
console.log(await artifacts.resolve({ resolverId: 'document', artifactId: 'manual', revision: '1' }, { app, signal: new AbortController().signal }));import { Artifacts } from '@jangts/agent-core/kits/artifacts';
const artifacts = Artifacts.defineArtifactCatalog([
{ id: 'document', async resolve(reference, { app, signal }) {
signal.throwIfAborted();
if (!app.canRead)
throw new Error('没有产物读取权限');
const value = app.documents.get(reference.artifactId);
if (!value)
throw new Error('产物不存在或已到期');
if (reference.revision && reference.revision !== value.revision)
throw new Error('产物版本已变化');
return structuredClone(value);
} },
]);
const app = { canRead: true, documents: new Map([['manual', { text: 'Agent Core 使用说明', revision: '1' }]]) };
console.log(await artifacts.resolve({ resolverId: 'document', artifactId: 'manual', revision: '1' }, { app, signal: new AbortController().signal }));