@acedatacloud/openclaw-provider 2026.5.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,73 @@
1
+ import type {
2
+ ModelDefinitionConfig,
3
+ ModelProviderConfig,
4
+ } from "openclaw/plugin-sdk/provider-model-shared";
5
+ import { ACEDATA_BASE_URL } from "../constants.js";
6
+ import { GENERATED_CHAT_MODELS } from "./generated-catalog.js";
7
+
8
+ const ZERO_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } as const;
9
+
10
+ const CATALOG_REASONING_BY_ID = new Map<string, boolean>(
11
+ GENERATED_CHAT_MODELS.map((m) => [m.id.toLowerCase(), m.reasoning]),
12
+ );
13
+
14
+ // Heuristic fallback for ids NOT in the curated catalog (used by
15
+ // resolveDynamicModel passthrough). Authoritative source: catalog lookup above.
16
+ const REASONING_HEURISTIC_PREFIXES = [
17
+ "gpt-5",
18
+ "claude-opus-",
19
+ "claude-sonnet-4",
20
+ "claude-3-7-sonnet",
21
+ "gemini-3.1-pro",
22
+ "gemini-3-pro",
23
+ "grok-4",
24
+ "deepseek-r",
25
+ "deepseek-v4",
26
+ "deepseek-reasoner",
27
+ "kimi-k2-thinking",
28
+ "kimi-k2.5",
29
+ "glm-5",
30
+ ] as const;
31
+
32
+ const REASONING_HEURISTIC_EXACT = new Set<string>([
33
+ "o1",
34
+ "o1-mini",
35
+ "o1-pro",
36
+ "o3",
37
+ "o3-mini",
38
+ "o3-pro",
39
+ "o4-mini",
40
+ ]);
41
+
42
+ export function isAcedataReasoningModel(modelId: string): boolean {
43
+ const normalized = modelId.trim().toLowerCase();
44
+ if (!normalized) return false;
45
+ const fromCatalog = CATALOG_REASONING_BY_ID.get(normalized);
46
+ if (fromCatalog !== undefined) return fromCatalog;
47
+ if (REASONING_HEURISTIC_EXACT.has(normalized)) return true;
48
+ return REASONING_HEURISTIC_PREFIXES.some((prefix) => normalized.startsWith(prefix));
49
+ }
50
+
51
+ function toModelDefinition(entry: (typeof GENERATED_CHAT_MODELS)[number]): ModelDefinitionConfig {
52
+ return {
53
+ id: entry.id,
54
+ name: entry.name,
55
+ reasoning: entry.reasoning,
56
+ input: entry.vision ? ["text", "image"] : ["text"],
57
+ cost: ZERO_COST,
58
+ contextWindow: entry.contextWindow,
59
+ maxTokens: entry.maxTokens,
60
+ };
61
+ }
62
+
63
+ export function listAcedataChatModels(): ModelDefinitionConfig[] {
64
+ return GENERATED_CHAT_MODELS.map(toModelDefinition);
65
+ }
66
+
67
+ export function buildAcedataChatProvider(): ModelProviderConfig {
68
+ return {
69
+ baseUrl: ACEDATA_BASE_URL,
70
+ api: "openai-completions",
71
+ models: listAcedataChatModels(),
72
+ };
73
+ }
@@ -0,0 +1,3 @@
1
+ export const ACEDATA_BASE_URL = "https://api.acedata.cloud/v1";
2
+ export const ACEDATA_PROVIDER_ID = "acedatacloud";
3
+ export const ACEDATA_DEFAULT_MODEL_REF = "acedatacloud/gpt-4.1-mini";
@@ -0,0 +1,160 @@
1
+ import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
2
+ import {
3
+ resolveAcedataSearchApiKey,
4
+ resolveAcedataSearchBaseUrl,
5
+ resolveAcedataSearchTimeoutSeconds,
6
+ } from "./acedata-search-config.js";
7
+
8
+ export type AcedataSearchType = "search" | "images" | "news" | "videos" | "maps" | "places";
9
+
10
+ export type AcedataSearchOrganicResult = {
11
+ title?: string;
12
+ link?: string;
13
+ snippet?: string;
14
+ position?: number;
15
+ date?: string;
16
+ source?: string;
17
+ thumbnail?: string;
18
+ };
19
+
20
+ export type AcedataSearchResponse = {
21
+ type: AcedataSearchType;
22
+ query: string;
23
+ organic_results: AcedataSearchOrganicResult[];
24
+ knowledge_graph?: Record<string, unknown>;
25
+ answer_box?: Record<string, unknown>;
26
+ related_searches?: Array<{ query?: string }>;
27
+ total?: number;
28
+ raw?: unknown;
29
+ };
30
+
31
+ export type RunAcedataSearchArgs = {
32
+ cfg?: OpenClawConfig;
33
+ query: string;
34
+ type?: AcedataSearchType;
35
+ country?: string;
36
+ language?: string;
37
+ range?: string;
38
+ number?: number;
39
+ page?: number;
40
+ timeoutSeconds?: number;
41
+ };
42
+
43
+ const SEARCH_PATH = "/serp/google";
44
+
45
+ function buildSearchUrl(baseUrl: string): string {
46
+ return `${baseUrl.replace(/\/$/, "")}${SEARCH_PATH}`;
47
+ }
48
+
49
+ function asString(value: unknown): string | undefined {
50
+ return typeof value === "string" && value.trim() ? value : undefined;
51
+ }
52
+
53
+ function asNumber(value: unknown): number | undefined {
54
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
55
+ }
56
+
57
+ function normalizeOrganicResults(value: unknown): AcedataSearchOrganicResult[] {
58
+ if (!Array.isArray(value)) return [];
59
+ const out: AcedataSearchOrganicResult[] = [];
60
+ for (const item of value) {
61
+ if (!item || typeof item !== "object") continue;
62
+ const row = item as Record<string, unknown>;
63
+ out.push({
64
+ title: asString(row.title),
65
+ link: asString(row.link) ?? asString(row.url),
66
+ snippet: asString(row.snippet) ?? asString(row.description),
67
+ position: asNumber(row.position),
68
+ date: asString(row.date),
69
+ source: asString(row.source),
70
+ thumbnail: asString(row.thumbnail),
71
+ });
72
+ }
73
+ return out;
74
+ }
75
+
76
+ export async function runAcedataSearch(args: RunAcedataSearchArgs): Promise<AcedataSearchResponse> {
77
+ const { cfg, query, type = "search" } = args;
78
+ if (!query.trim()) {
79
+ throw new Error("Ace Data Cloud search query is required");
80
+ }
81
+ const apiKey = resolveAcedataSearchApiKey(cfg);
82
+ if (!apiKey) {
83
+ throw new Error(
84
+ "Ace Data Cloud API key not configured. Set ACEDATA_API_KEY env var or configure plugins.entries.acedatacloud.config.webSearch.apiKey.",
85
+ );
86
+ }
87
+ const baseUrl = resolveAcedataSearchBaseUrl(cfg);
88
+ const timeoutSeconds = resolveAcedataSearchTimeoutSeconds(args.timeoutSeconds);
89
+
90
+ const body: Record<string, unknown> = { query, type };
91
+ if (args.country) body.country = args.country;
92
+ if (args.language) body.language = args.language;
93
+ if (args.range) body.range = args.range;
94
+ if (typeof args.number === "number" && args.number > 0) body.number = args.number;
95
+ if (typeof args.page === "number" && args.page > 0) body.page = args.page;
96
+
97
+ const controller = new AbortController();
98
+ const timer = setTimeout(() => controller.abort(), timeoutSeconds * 1000);
99
+ let response: Response;
100
+ try {
101
+ response = await fetch(buildSearchUrl(baseUrl), {
102
+ method: "POST",
103
+ headers: {
104
+ Authorization: `Bearer ${apiKey}`,
105
+ "Content-Type": "application/json",
106
+ Accept: "application/json",
107
+ },
108
+ body: JSON.stringify(body),
109
+ signal: controller.signal,
110
+ });
111
+ } catch (cause) {
112
+ if ((cause as Error)?.name === "AbortError") {
113
+ throw new Error(`Ace Data Cloud search timed out after ${timeoutSeconds}s`);
114
+ }
115
+ throw new Error(`Ace Data Cloud search request failed: ${(cause as Error).message}`, { cause });
116
+ } finally {
117
+ clearTimeout(timer);
118
+ }
119
+
120
+ if (!response.ok) {
121
+ const text = await response.text().catch(() => "");
122
+ throw new Error(
123
+ `Ace Data Cloud search API returned HTTP ${response.status}${text ? `: ${text.slice(0, 500)}` : ""}`,
124
+ );
125
+ }
126
+
127
+ let payload: unknown;
128
+ try {
129
+ payload = await response.json();
130
+ } catch (cause) {
131
+ throw new Error("Ace Data Cloud search returned malformed JSON", { cause });
132
+ }
133
+
134
+ const root = (payload && typeof payload === "object" ? payload : {}) as Record<string, unknown>;
135
+ const data =
136
+ (root.data && typeof root.data === "object" ? (root.data as Record<string, unknown>) : root) ?? {};
137
+
138
+ const organic = normalizeOrganicResults(data.organic_results ?? data.results ?? data.items);
139
+
140
+ const result: AcedataSearchResponse = {
141
+ type,
142
+ query,
143
+ organic_results: organic,
144
+ };
145
+ if (data.knowledge_graph && typeof data.knowledge_graph === "object") {
146
+ result.knowledge_graph = data.knowledge_graph as Record<string, unknown>;
147
+ }
148
+ if (data.answer_box && typeof data.answer_box === "object") {
149
+ result.answer_box = data.answer_box as Record<string, unknown>;
150
+ }
151
+ if (Array.isArray(data.related_searches)) {
152
+ result.related_searches = (data.related_searches as Array<Record<string, unknown>>)
153
+ .map((item) => ({ query: asString(item?.query) }))
154
+ .filter((item) => Boolean(item.query));
155
+ }
156
+ if (typeof data.total === "number") {
157
+ result.total = data.total;
158
+ }
159
+ return result;
160
+ }
@@ -0,0 +1,76 @@
1
+ import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
2
+ import { resolvePositiveTimeoutSeconds } from "openclaw/plugin-sdk/provider-web-search";
3
+ import {
4
+ normalizeResolvedSecretInputString,
5
+ normalizeSecretInput,
6
+ } from "openclaw/plugin-sdk/secret-input";
7
+ import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
8
+ import { ACEDATA_BASE_URL } from "../constants.js";
9
+
10
+ export const ACEDATA_SEARCH_DEFAULT_TIMEOUT_SECONDS = 30;
11
+
12
+ type AcedataSearchConfig =
13
+ | {
14
+ apiKey?: unknown;
15
+ baseUrl?: string;
16
+ }
17
+ | undefined;
18
+
19
+ type PluginEntryConfig = {
20
+ webSearch?: AcedataSearchConfig;
21
+ providerCredentials?: { acedatacloud?: { apiKey?: unknown } };
22
+ };
23
+
24
+ export function resolveAcedataSearchConfig(cfg?: OpenClawConfig): AcedataSearchConfig {
25
+ const pluginConfig = cfg?.plugins?.entries?.acedatacloud?.config as PluginEntryConfig | undefined;
26
+ const ws = pluginConfig?.webSearch;
27
+ if (ws && typeof ws === "object" && !Array.isArray(ws)) {
28
+ return ws;
29
+ }
30
+ return undefined;
31
+ }
32
+
33
+ function normalizeConfiguredSecret(value: unknown, path: string): string | undefined {
34
+ return normalizeSecretInput(
35
+ normalizeResolvedSecretInputString({
36
+ value,
37
+ path,
38
+ }),
39
+ );
40
+ }
41
+
42
+ export function resolveAcedataSearchApiKey(cfg?: OpenClawConfig): string | undefined {
43
+ const search = resolveAcedataSearchConfig(cfg);
44
+ const fromSearch = normalizeConfiguredSecret(
45
+ search?.apiKey,
46
+ "plugins.entries.acedatacloud.config.webSearch.apiKey",
47
+ );
48
+ if (fromSearch) return fromSearch;
49
+ const fromChat = normalizeConfiguredSecret(
50
+ (cfg?.plugins?.entries?.acedatacloud?.config as PluginEntryConfig | undefined)
51
+ ?.providerCredentials?.acedatacloud?.apiKey,
52
+ "plugins.entries.acedatacloud.config.providerCredentials.acedatacloud.apiKey",
53
+ );
54
+ if (fromChat) return fromChat;
55
+ return (
56
+ normalizeSecretInput(process.env.ACEDATA_API_KEY) ||
57
+ normalizeSecretInput(process.env.ACEDATACLOUD_API_KEY) ||
58
+ undefined
59
+ );
60
+ }
61
+
62
+ export function resolveAcedataSearchBaseUrl(cfg?: OpenClawConfig): string {
63
+ const search = resolveAcedataSearchConfig(cfg);
64
+ const configured =
65
+ (normalizeOptionalString(search?.baseUrl) ?? "") ||
66
+ normalizeSecretInput(process.env.ACEDATA_BASE_URL) ||
67
+ "";
68
+ if (!configured) {
69
+ return ACEDATA_BASE_URL.replace(/\/v1\/?$/, "");
70
+ }
71
+ return configured.replace(/\/$/, "");
72
+ }
73
+
74
+ export function resolveAcedataSearchTimeoutSeconds(override?: number): number {
75
+ return resolvePositiveTimeoutSeconds(override, ACEDATA_SEARCH_DEFAULT_TIMEOUT_SECONDS);
76
+ }
@@ -0,0 +1,80 @@
1
+ import { readPositiveIntegerParam } from "openclaw/plugin-sdk/param-readers";
2
+ import type { WebSearchProviderPlugin } from "openclaw/plugin-sdk/provider-web-search-contract";
3
+ import { runAcedataSearch, type AcedataSearchType } from "./acedata-search-client.js";
4
+ import { buildAcedataSearchProviderBase } from "./acedata-search-shared.js";
5
+
6
+ const SUPPORTED_TYPES: AcedataSearchType[] = ["search", "images", "news", "videos", "maps", "places"];
7
+
8
+ const AcedataSearchSchema = {
9
+ type: "object",
10
+ properties: {
11
+ query: { type: "string", description: "Search query string." },
12
+ count: {
13
+ type: "integer",
14
+ description: "Number of results to return (1-100).",
15
+ minimum: 1,
16
+ maximum: 100,
17
+ },
18
+ type: {
19
+ type: "string",
20
+ enum: SUPPORTED_TYPES,
21
+ description:
22
+ 'Search vertical: "search" (default), "images", "news", "videos", "maps", or "places".',
23
+ },
24
+ country: {
25
+ type: "string",
26
+ description: 'Two-letter country code (e.g. "us", "cn", "jp").',
27
+ },
28
+ language: {
29
+ type: "string",
30
+ description: 'Two-letter language code (e.g. "en", "zh", "ja").',
31
+ },
32
+ range: {
33
+ type: "string",
34
+ description:
35
+ 'Recency filter using Google qdr syntax: "qdr:h" (hour), "qdr:d" (day), "qdr:w" (week), "qdr:m" (month), "qdr:y" (year).',
36
+ },
37
+ page: {
38
+ type: "integer",
39
+ description: "Page number for pagination (1-based).",
40
+ minimum: 1,
41
+ },
42
+ },
43
+ additionalProperties: false,
44
+ } satisfies Record<string, unknown>;
45
+
46
+ function normalizeSearchType(value: unknown): AcedataSearchType | undefined {
47
+ if (typeof value !== "string") return undefined;
48
+ return (SUPPORTED_TYPES as string[]).includes(value) ? (value as AcedataSearchType) : undefined;
49
+ }
50
+
51
+ export function createAcedataWebSearchProvider(): WebSearchProviderPlugin {
52
+ return {
53
+ ...buildAcedataSearchProviderBase(),
54
+ createTool: (ctx) => ({
55
+ description:
56
+ "Search the web using Ace Data Cloud's Google SERP API. Returns structured organic results plus optional knowledge graph and answer box. Supports image/news/video/maps verticals.",
57
+ parameters: AcedataSearchSchema,
58
+ execute: async (args) => {
59
+ const query = typeof args.query === "string" ? args.query : "";
60
+ const count = readPositiveIntegerParam(args, "count", {
61
+ message: "count must be an integer from 1 to 100",
62
+ max: 100,
63
+ });
64
+ const page = readPositiveIntegerParam(args, "page", {
65
+ message: "page must be a positive integer",
66
+ });
67
+ return await runAcedataSearch({
68
+ cfg: ctx.config,
69
+ query,
70
+ type: normalizeSearchType(args.type) ?? "search",
71
+ country: typeof args.country === "string" ? args.country : undefined,
72
+ language: typeof args.language === "string" ? args.language : undefined,
73
+ range: typeof args.range === "string" ? args.range : undefined,
74
+ number: count,
75
+ page,
76
+ });
77
+ },
78
+ }),
79
+ };
80
+ }
@@ -0,0 +1,29 @@
1
+ import {
2
+ createWebSearchProviderContractFields,
3
+ type WebSearchProviderPlugin,
4
+ } from "openclaw/plugin-sdk/provider-web-search-contract";
5
+
6
+ export const ACEDATA_SEARCH_CREDENTIAL_PATH =
7
+ "plugins.entries.acedatacloud.config.webSearch.apiKey";
8
+
9
+ export function buildAcedataSearchProviderBase(): Omit<WebSearchProviderPlugin, "createTool"> {
10
+ return {
11
+ id: "acedatacloud",
12
+ label: "Ace Data Cloud Google Search",
13
+ hint: "Google web/image/news/video search via Ace Data Cloud SERP API",
14
+ onboardingScopes: ["text-inference"],
15
+ credentialLabel: "Ace Data Cloud API key",
16
+ envVars: ["ACEDATA_API_KEY", "ACEDATACLOUD_API_KEY"],
17
+ placeholder: "ace-...",
18
+ signupUrl: "https://platform.acedata.cloud/",
19
+ docsUrl: "https://platform.acedata.cloud/services/3a30e2fb-3a99-4ae7-bc3e-9a51d5d6f02b",
20
+ autoDetectOrder: 80,
21
+ credentialPath: ACEDATA_SEARCH_CREDENTIAL_PATH,
22
+ ...createWebSearchProviderContractFields({
23
+ credentialPath: ACEDATA_SEARCH_CREDENTIAL_PATH,
24
+ searchCredential: { type: "scoped", scopeId: "acedatacloud" },
25
+ configuredCredential: { pluginId: "acedatacloud" },
26
+ selectionPluginId: "acedatacloud",
27
+ }),
28
+ };
29
+ }