src / providers / DummyProvider.ts
src / providers / DummyProvider.ts
import { SearchOptions } from "../types/search";
import { BaseProvider } from "./BaseProvider";
import { InternalProviderResult } from "./types/InternalProviderResult";
/**
* Dummy search provider implementation used to validate the provider framework end-to-end.
* Does not make external network requests; returns in-memory candidate InternalProviderResult objects.
*/
export class DummyProvider extends BaseProvider {
public static readonly PROVIDER_NAME = "dummy";
public static readonly DISPLAY_NAME = "Dummy Provider";
constructor() {
super(DummyProvider.PROVIDER_NAME, DummyProvider.DISPLAY_NAME, ["web"]);
}
/**
* Execute in-memory deterministic search for testing and validation.
*/
public async search(query: string, options?: SearchOptions): Promise<InternalProviderResult[]> {
const cleanQuery = query ? query.trim() : "test";
const numResults = options?.numResults ?? 2;
const results: InternalProviderResult[] = [
{
title: `Dummy Search Result for '${cleanQuery}'`,
url: `https://dummy.example.com/search?q=${encodeURIComponent(cleanQuery)}`,
snippetCandidate: `This is a synthetic search result snippet generated for query: "${cleanQuery}".`,
publishedDate: new Date().toISOString().split("T")[0],
source: this.providerName,
score: 0.99,
raw: {
synthetic: true,
query: cleanQuery,
},
debug: { snippetSource: "native_snippet" },
},
{
title: `Secondary Reference: ${cleanQuery}`,
url: `https://dummy.example.com/ref/${encodeURIComponent(cleanQuery)}`,
snippetCandidate: `Additional mock content providing secondary reference details for "${cleanQuery}".`,
publishedDate: new Date().toISOString().split("T")[0],
source: this.providerName,
score: 0.85,
raw: {
synthetic: true,
query: cleanQuery,
},
debug: { snippetSource: "native_snippet" },
},
];
const sliced = this.enforceResultLimit(results, numResults);
this._lastRawResultsCount = results.length;
this._lastHttpResponseBytes = Buffer.byteLength(JSON.stringify(sliced.map((r) => r.raw)), "utf-8");
return sliced;
}
}
import { SearchOptions } from "../types/search";
import { BaseProvider } from "./BaseProvider";
import { InternalProviderResult } from "./types/InternalProviderResult";
/**
* Dummy search provider implementation used to validate the provider framework end-to-end.
* Does not make external network requests; returns in-memory candidate InternalProviderResult objects.
*/
export class DummyProvider extends BaseProvider {
public static readonly PROVIDER_NAME = "dummy";
public static readonly DISPLAY_NAME = "Dummy Provider";
constructor() {
super(DummyProvider.PROVIDER_NAME, DummyProvider.DISPLAY_NAME, ["web"]);
}
/**
* Execute in-memory deterministic search for testing and validation.
*/
public async search(query: string, options?: SearchOptions): Promise<InternalProviderResult[]> {
const cleanQuery = query ? query.trim() : "test";
const numResults = options?.numResults ?? 2;
const results: InternalProviderResult[] = [
{
title: `Dummy Search Result for '${cleanQuery}'`,
url: `https://dummy.example.com/search?q=${encodeURIComponent(cleanQuery)}`,
snippetCandidate: `This is a synthetic search result snippet generated for query: "${cleanQuery}".`,
publishedDate: new Date().toISOString().split("T")[0],
source: this.providerName,
score: 0.99,
raw: {
synthetic: true,
query: cleanQuery,
},
debug: { snippetSource: "native_snippet" },
},
{
title: `Secondary Reference: ${cleanQuery}`,
url: `https://dummy.example.com/ref/${encodeURIComponent(cleanQuery)}`,
snippetCandidate: `Additional mock content providing secondary reference details for "${cleanQuery}".`,
publishedDate: new Date().toISOString().split("T")[0],
source: this.providerName,
score: 0.85,
raw: {
synthetic: true,
query: cleanQuery,
},
debug: { snippetSource: "native_snippet" },
},
];
const sliced = this.enforceResultLimit(results, numResults);
this._lastRawResultsCount = results.length;
this._lastHttpResponseBytes = Buffer.byteLength(JSON.stringify(sliced.map((r) => r.raw)), "utf-8");
return sliced;
}
}