Skip to content
中文

ArtifactResolver ​

KIT · interface · Type contract

App-registered resolver that turns a reference into an App value.

Import ​

ts
import type { ArtifactResolver } from '@jangts/agent-core/kits/artifacts';
js
/** @typedef {import('@jangts/agent-core/kits/artifacts').ArtifactResolver} ArtifactResolver */

Other public entry points:@jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/kits, @jangts/agent-core/kits/artifacts.

Definition ​

ts
interface ArtifactResolver<Value, App>

Type parameters ​

Type parameterConstraintDefault type
Value——
App——

Field structure ​

FieldTypeRequiredDescription
idstringRequiredRead-only. See the type definition and usage context.
resolve(reference: ArtifactReference, context: OperationContext<App>) => MaybePromise<Value>RequiredResolves the reference; throws when the artifact is unknown or not accessible.

Member index ​

MemberPurpose
resolveResolves the reference; throws when the artifact is unknown or not accessible.

Member details ​

resolve ​

Resolves the reference; throws when the artifact is unknown or not accessible.

ts
ArtifactResolver.resolve(reference: ArtifactReference, context: OperationContext<App>): MaybePromise<Value>

Resolves the reference; throws when the artifact is unknown or not accessible.

ParameterTypePassingDescription
referenceArtifactReferenceRequired—
contextOperationContext<App>Required—
Fields of reference
FieldTypeRequiredDescription
resolverIdstringRequiredRead-only. Resolver that owns the artifact namespace.
artifactIdstringRequiredRead-only. Artifact identity inside that namespace; never blank.
revisionstring | undefinedOptionalRead-only. Optional pinned revision; omission asks the resolver for its current revision.
Fields of context
FieldTypeRequiredDescription
appunknown extends App ? App : Readonly<App>RequiredRead-only. See the type definition and usage context.
loggerSubFlowLog | undefinedOptionalRead-only. Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignalRequiredRead-only. Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Diagnostic scope of the enclosing call, when recording is enabled.

Returns: MaybePromise<Value>.

Awaited value: Awaited<Value>.

Examples ​

First resolve one explicit in-memory artifact ​

Beginner · Node.js

ts
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);
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);

Add real permission and revision verification to the same resolve ​

Configuration · Node.js

ts
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 }));
js
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 }));

API reference, usage examples and developer guides.