Skip to content
中文

WebProfile ​

KIT · type · Type contract

Name of an entry in webHeaderProfiles.

Import ​

ts
import type { WebProfile } from '@jangts/agent-core/mock/web';
js
/** @typedef {import('@jangts/agent-core/mock/web').WebProfile} WebProfile */

Other public entry points:@jangts/agent-core/mock/web.

Definition ​

ts
type WebProfile = keyof typeof webHeaderProfiles;

Index structure ​

FieldTypeRequiredDescription
[key: number]stringRequiredRead-only. Index entry.

Union branch structure ​

Examples ​

A trusted load supplies offline body text ​

Beginner · Node.js

ts
import { MockGPT, generators } from '@jangts/agent-core/mock';
import { sources, isPublicAddress } from '@jangts/agent-core/mock/web';
const source = sources.web({ url: 'https://example.com/article', async load(url, signal, maxBytes) {
  signal.throwIfAborted();
  const bytes = new TextEncoder().encode('服务维护完成。健康检查通过。');
  if (bytes.byteLength > maxBytes) throw new Error('来源超过预算');
  return { bytes, url: url.href, contentType: 'text/plain; charset=utf-8' };
} });
const mock = new MockGPT({ rules: [{ generator: generators.summary({ source }) }] });
console.log(await mock.generate({ model: 'demo', messages: [{ role: 'user', content: '概括正文' }] }));
console.log(isPublicAddress('127.0.0.1')); // false
js
import { MockGPT, generators } from '@jangts/agent-core/mock';
import { sources, isPublicAddress } from '@jangts/agent-core/mock/web';
const source = sources.web({ url: 'https://example.com/article', async load(url, signal, maxBytes) {
        signal.throwIfAborted();
        const bytes = new TextEncoder().encode('服务维护完成。健康检查通过。');
        if (bytes.byteLength > maxBytes)
            throw new Error('来源超过预算');
        return { bytes, url: url.href, contentType: 'text/plain; charset=utf-8' };
    } });
const mock = new MockGPT({ rules: [{ generator: generators.summary({ source }) }] });
console.log(await mock.generate({ model: 'demo', messages: [{ role: 'user', content: '概括正文' }] }));
console.log(isPublicAddress('127.0.0.1')); // false

Explicitly enable a web source and a failure replacement text ​

Configuration · Node.js

ts
import { MockGPT, generators } from '@jangts/agent-core/mock';
import { sources } from '@jangts/agent-core/mock/web';
const mock = new MockGPT({ rules: [{ generator: generators.summary({ source: sources.web({
  url: 'https://example.com/article', timeoutMs: 5000,
  fallback: '网页不可读取,请提供正文。',
}) }) }] });
console.log(await mock.generate({ model: 'demo', messages: [{ role: 'user', content: '总结文章' }] }));
console.log(mock.records); // 检查 sourceFallback/sourceError,不把替代文本当原文
js
import { MockGPT, generators } from '@jangts/agent-core/mock';
import { sources } from '@jangts/agent-core/mock/web';
const mock = new MockGPT({ rules: [{ generator: generators.summary({ source: sources.web({
                    url: 'https://example.com/article', timeoutMs: 5000,
                    fallback: '网页不可读取,请提供正文。',
                }) }) }] });
console.log(await mock.generate({ model: 'demo', messages: [{ role: 'user', content: '总结文章' }] }));
console.log(mock.records); // 检查 sourceFallback/sourceError,不把替代文本当原文

API reference, usage examples and developer guides.