openclaw-cloudflare-vectorize-memory 0.1.0 → 0.1.2

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.
Files changed (47) hide show
  1. package/README.md +14 -0
  2. package/cli-metadata.ts +18 -0
  3. package/dist/cli.js +119 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/cloudflare-api.js +24 -0
  6. package/dist/cloudflare-api.js.map +1 -0
  7. package/dist/companion-store.js +43 -0
  8. package/dist/companion-store.js.map +1 -0
  9. package/dist/config.js +290 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/constants.js +15 -0
  12. package/dist/constants.js.map +1 -0
  13. package/dist/doctor.js +40 -0
  14. package/dist/doctor.js.map +1 -0
  15. package/dist/embeddings-client.js +28 -0
  16. package/dist/embeddings-client.js.map +1 -0
  17. package/dist/errors.js +18 -0
  18. package/dist/errors.js.map +1 -0
  19. package/dist/index.js +42 -1412
  20. package/dist/index.js.map +1 -1
  21. package/dist/migration.js +282 -0
  22. package/dist/migration.js.map +1 -0
  23. package/dist/namespace.js +18 -0
  24. package/dist/namespace.js.map +1 -0
  25. package/dist/prompt.js +9 -0
  26. package/dist/prompt.js.map +1 -0
  27. package/dist/public-artifacts.js +31 -0
  28. package/dist/public-artifacts.js.map +1 -0
  29. package/dist/record-mapper.js +98 -0
  30. package/dist/record-mapper.js.map +1 -0
  31. package/dist/runtime.js +39 -0
  32. package/dist/runtime.js.map +1 -0
  33. package/dist/search-manager.js +74 -0
  34. package/dist/search-manager.js.map +1 -0
  35. package/dist/service-factory.js +10 -0
  36. package/dist/service-factory.js.map +1 -0
  37. package/dist/service.js +114 -0
  38. package/dist/service.js.map +1 -0
  39. package/dist/tools.js +158 -0
  40. package/dist/tools.js.map +1 -0
  41. package/dist/vectorize-client.js +68 -0
  42. package/dist/vectorize-client.js.map +1 -0
  43. package/hooks/cloudflare-memory-bootstrap/BOOTSTRAP.md +7 -0
  44. package/hooks/cloudflare-memory-bootstrap/HOOK.md +10 -0
  45. package/hooks/cloudflare-memory-bootstrap/handler.d.ts +3 -0
  46. package/hooks/cloudflare-memory-bootstrap/handler.js +17 -0
  47. package/package.json +6 -1
package/README.md CHANGED
@@ -39,6 +39,20 @@ openclaw plugins install openclaw-cloudflare-vectorize-memory
39
39
 
40
40
  Publish the package with the included `openclaw.plugin.json` manifest and install it through normal ClawHub/OpenClaw plugin flows.
41
41
 
42
+ OpenClaw uses the plugin manifest id `memory-cloudflare-vectorize` as the config key, so plugin config stays under `plugins.entries.memory-cloudflare-vectorize`.
43
+
44
+ ## Optional bootstrap hook
45
+
46
+ This package also ships an optional managed hook named `cloudflare-memory-bootstrap`.
47
+
48
+ Enable it after installation with:
49
+
50
+ ```bash
51
+ openclaw hooks enable cloudflare-memory-bootstrap
52
+ ```
53
+
54
+ When enabled, the hook injects packaged bootstrap guidance so agents know the Cloudflare memory plugin is installed and can point operators at `openclaw cf-memory doctor`.
55
+
42
56
  ## Publishing to npmjs
43
57
 
44
58
  After authenticating with npm for the target package owner, publish with:
@@ -0,0 +1,18 @@
1
+ import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
2
+
3
+ export default definePluginEntry({
4
+ id: "memory-cloudflare-vectorize",
5
+ name: "Cloudflare Vectorize Memory",
6
+ description: "OpenClaw memory plugin backed by Cloudflare Vectorize and Workers AI embeddings.",
7
+ register(api) {
8
+ api.registerCli(() => {}, {
9
+ descriptors: [
10
+ {
11
+ name: "cf-memory",
12
+ description: "Manage Cloudflare Vectorize memory",
13
+ hasSubcommands: true,
14
+ },
15
+ ],
16
+ });
17
+ },
18
+ });
package/dist/cli.js ADDED
@@ -0,0 +1,119 @@
1
+ import { formatMigrationSummary as e, runCloudflareMemoryMigration as t } from "./migration.js";
2
+ import { createCloudflareMemoryService as n } from "./service-factory.js";
3
+ //#region src/cli.ts
4
+ function r(e) {
5
+ console.log(JSON.stringify(e, null, 2));
6
+ }
7
+ function i(e) {
8
+ if (!e) return;
9
+ let t = JSON.parse(e);
10
+ if (!t || typeof t != "object" || Array.isArray(t)) throw Error("--metadata must be a JSON object.");
11
+ return t;
12
+ }
13
+ function a(e) {
14
+ if (!e) return;
15
+ let t = JSON.parse(e);
16
+ if (!t || typeof t != "object" || Array.isArray(t)) throw Error("--filter must be a JSON object.");
17
+ return t;
18
+ }
19
+ function o(e) {
20
+ return !!e && typeof e == "object" && typeof e.opts == "function";
21
+ }
22
+ function s(e) {
23
+ let t = e.at(-1);
24
+ return o(t) ? {
25
+ positionals: e.slice(0, -1),
26
+ options: t.opts?.() ?? {}
27
+ } : {
28
+ positionals: e,
29
+ options: {}
30
+ };
31
+ }
32
+ function c(e) {
33
+ if (e !== void 0) {
34
+ if (e === "overwrite" || e === "skip" || e === "fail") return e;
35
+ throw Error("--if-exists must be overwrite, skip, or fail.");
36
+ }
37
+ }
38
+ function l(o, l) {
39
+ let u = o.command("cf-memory").description("Manage Cloudflare memory records.");
40
+ function d(e) {
41
+ return s(e).options;
42
+ }
43
+ u.command("doctor").description("Validate Workers AI and Vectorize configuration.").option("--create-index", "Create the Vectorize index if missing.").option("--json", "Print structured JSON output.").action(async (...e) => {
44
+ let t = d(e), i = await (await n({
45
+ pluginConfig: l.pluginConfig,
46
+ openClawConfig: l.openClawConfig,
47
+ env: process.env,
48
+ resolvePath: l.resolvePath
49
+ })).doctor({ createIndexIfMissing: !!t.createIndex });
50
+ if (t.json) r(i);
51
+ else for (let e of i.checks) console.log(`[${e.status}] ${e.name}: ${e.message}`);
52
+ i.ok || (process.exitCode = 1);
53
+ }), u.command("search").description("Search stored Cloudflare memory.").argument("<query>", "Semantic search query.").option("--namespace <namespace>", "Optional namespace override.").option("--limit <count>", "Maximum number of results.").option("--filter <json>", "Optional metadata filter JSON.").action(async (e, t) => {
54
+ let i = t;
55
+ r(await (await n({
56
+ pluginConfig: l.pluginConfig,
57
+ openClawConfig: l.openClawConfig,
58
+ env: process.env,
59
+ resolvePath: l.resolvePath
60
+ })).search({
61
+ query: String(e),
62
+ namespace: i.namespace,
63
+ maxResults: i.limit ? Number(i.limit) : void 0,
64
+ filter: a(i.filter)
65
+ }));
66
+ }), u.command("upsert").description("Insert or update a memory record.").argument("<text>", "Memory text.").option("--id <id>", "Stable logical id.").option("--title <title>", "Optional title.").option("--namespace <namespace>", "Optional namespace override.").option("--source <source>", "Optional source label.").option("--metadata <json>", "Optional metadata JSON object.").action(async (e, t) => {
67
+ let a = t;
68
+ r(await (await n({
69
+ pluginConfig: l.pluginConfig,
70
+ openClawConfig: l.openClawConfig,
71
+ env: process.env,
72
+ resolvePath: l.resolvePath
73
+ })).upsert({ input: {
74
+ id: a.id,
75
+ title: a.title,
76
+ text: String(e),
77
+ namespace: a.namespace,
78
+ source: a.source,
79
+ metadata: i(a.metadata)
80
+ } }));
81
+ }), u.command("delete").description("Delete a memory record.").argument("<id>", "Logical memory record id.").option("--namespace <namespace>", "Optional namespace override.").action(async (e, t) => {
82
+ let i = t;
83
+ r({
84
+ id: e,
85
+ mutationId: await (await n({
86
+ pluginConfig: l.pluginConfig,
87
+ openClawConfig: l.openClawConfig,
88
+ env: process.env,
89
+ resolvePath: l.resolvePath
90
+ })).delete({
91
+ id: String(e),
92
+ namespace: i.namespace
93
+ })
94
+ });
95
+ }), u.command("migrate").description("Migrate legacy markdown memory into Cloudflare Vectorize.").argument("[sources...]", "Markdown files, directories, or glob patterns. Defaults to the current OpenClaw memory corpus when omitted.").option("--workspace <path>", "Workspace root used for default-provider discovery and relative path normalization.").option("--namespace <namespace>", "Target namespace override.").option("--derive-namespace-from-path", "Derive namespaces from the first relative path segment instead of using a single target namespace.").option("--if-exists <strategy>", "Duplicate handling: overwrite, skip, or fail.").option("--create-index", "Create the Vectorize index if missing.").option("--dry-run", "Plan the migration without writing records.").option("--json", "Print structured JSON output.").action(async (...i) => {
96
+ let { positionals: a, options: o } = s(i), u = a[0], d = a.length === 0 ? [] : Array.isArray(u) ? u.map((e) => String(e)) : a.map((e) => String(e)), f = await t({
97
+ service: await n({
98
+ pluginConfig: l.pluginConfig,
99
+ openClawConfig: l.openClawConfig,
100
+ env: process.env,
101
+ resolvePath: l.resolvePath
102
+ }),
103
+ options: {
104
+ sourcePaths: d,
105
+ workspaceDir: o.workspace,
106
+ namespace: o.namespace,
107
+ namespaceStrategy: o.deriveNamespaceFromPath ? "path" : "single-target",
108
+ duplicateStrategy: c(o.ifExists),
109
+ dryRun: !!o.dryRun,
110
+ createIndexIfMissing: !!o.createIndex
111
+ }
112
+ });
113
+ o.json ? r(f) : console.log(e(f)), f.failed > 0 && (process.exitCode = 1);
114
+ });
115
+ }
116
+ //#endregion
117
+ export { l as registerCloudflareMemoryCli };
118
+
119
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import type { OpenClawConfig } from \"openclaw/plugin-sdk/config-runtime\";\nimport type { MigrationDuplicateStrategy } from \"./types.js\";\nimport { formatMigrationSummary, runCloudflareMemoryMigration } from \"./migration.js\";\nimport { createCloudflareMemoryService } from \"./service-factory.js\";\nimport type { MetadataFilter } from \"./types.js\";\n\ntype CliCommand = {\n\tcommand: (name: string) => CliCommand;\n\tdescription: (description: string) => CliCommand;\n\targument: (name: string, description: string) => CliCommand;\n\toption: (flags: string, description: string) => CliCommand;\n\taction: (handler: (...args: unknown[]) => Promise<void> | void) => CliCommand;\n\topts?: () => Record<string, unknown>;\n};\n\nfunction printJson(value: unknown): void {\n\tconsole.log(JSON.stringify(value, null, 2));\n}\n\nfunction parseMetadataFlag(value: string | undefined): Record<string, string | number | boolean> | undefined {\n\tif (!value) {\n\t\treturn undefined;\n\t}\n\tconst parsed = JSON.parse(value) as unknown;\n\tif (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n\t\tthrow new Error(\"--metadata must be a JSON object.\");\n\t}\n\treturn parsed as Record<string, string | number | boolean>;\n}\n\nfunction parseFilterFlag(value: string | undefined): MetadataFilter | undefined {\n\tif (!value) {\n\t\treturn undefined;\n\t}\n\tconst parsed = JSON.parse(value) as unknown;\n\tif (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n\t\tthrow new Error(\"--filter must be a JSON object.\");\n\t}\n\treturn parsed as MetadataFilter;\n}\n\nfunction isCliCommand(value: unknown): value is CliCommand {\n\treturn Boolean(value) && typeof value === \"object\" && typeof (value as CliCommand).opts === \"function\";\n}\n\nfunction resolveInvocation(args: unknown[]): { positionals: unknown[]; options: Record<string, unknown> } {\n\tconst maybeCommand = args.at(-1);\n\tif (!isCliCommand(maybeCommand)) {\n\t\treturn {\n\t\t\tpositionals: args,\n\t\t\toptions: {},\n\t\t};\n\t}\n\treturn {\n\t\tpositionals: args.slice(0, -1),\n\t\toptions: maybeCommand.opts?.() ?? {},\n\t};\n}\n\nfunction parseDuplicateStrategy(value: unknown): MigrationDuplicateStrategy | undefined {\n\tif (value === undefined) {\n\t\treturn undefined;\n\t}\n\tif (value === \"overwrite\" || value === \"skip\" || value === \"fail\") {\n\t\treturn value;\n\t}\n\tthrow new Error(\"--if-exists must be overwrite, skip, or fail.\");\n}\n\nexport function registerCloudflareMemoryCli(\n\tprogram: {\n\t\tcommand: (name: string) => CliCommand;\n\t},\n\tparams: {\n\t\tpluginConfig: unknown;\n\t\topenClawConfig: OpenClawConfig;\n\t\tresolvePath?: (input: string) => string;\n\t},\n): void {\n\tconst root = program.command(\"cf-memory\").description(\"Manage Cloudflare memory records.\");\n\n\tfunction resolveOptions(args: unknown[]): Record<string, unknown> {\n\t\treturn resolveInvocation(args).options;\n\t}\n\n\troot\n\t\t.command(\"doctor\")\n\t\t.description(\"Validate Workers AI and Vectorize configuration.\")\n\t\t.option(\"--create-index\", \"Create the Vectorize index if missing.\")\n\t\t.option(\"--json\", \"Print structured JSON output.\")\n\t\t.action(async (...args) => {\n\t\t\tconst options = resolveOptions(args);\n\t\t\tconst service = await createCloudflareMemoryService({\n\t\t\t\tpluginConfig: params.pluginConfig,\n\t\t\t\topenClawConfig: params.openClawConfig,\n\t\t\t\tenv: process.env,\n\t\t\t\tresolvePath: params.resolvePath,\n\t\t\t});\n\t\t\tconst report = await service.doctor({\n\t\t\t\tcreateIndexIfMissing: Boolean(options.createIndex),\n\t\t\t});\n\t\t\tif (options.json) {\n\t\t\t\tprintJson(report);\n\t\t\t} else {\n\t\t\t\tfor (const check of report.checks) {\n\t\t\t\t\tconsole.log(`[${check.status}] ${check.name}: ${check.message}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!report.ok) {\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t});\n\n\troot\n\t\t.command(\"search\")\n\t\t.description(\"Search stored Cloudflare memory.\")\n\t\t.argument(\"<query>\", \"Semantic search query.\")\n\t\t.option(\"--namespace <namespace>\", \"Optional namespace override.\")\n\t\t.option(\"--limit <count>\", \"Maximum number of results.\")\n\t\t.option(\"--filter <json>\", \"Optional metadata filter JSON.\")\n\t\t.action(async (query, opts) => {\n\t\t\tconst options = opts as Record<string, unknown>;\n\t\t\tconst service = await createCloudflareMemoryService({\n\t\t\t\tpluginConfig: params.pluginConfig,\n\t\t\t\topenClawConfig: params.openClawConfig,\n\t\t\t\tenv: process.env,\n\t\t\t\tresolvePath: params.resolvePath,\n\t\t\t});\n\t\t\tconst results = await service.search({\n\t\t\t\tquery: String(query),\n\t\t\t\tnamespace: options.namespace as string | undefined,\n\t\t\t\tmaxResults: options.limit ? Number(options.limit) : undefined,\n\t\t\t\tfilter: parseFilterFlag(options.filter as string | undefined),\n\t\t\t});\n\t\t\tprintJson(results);\n\t\t});\n\n\troot\n\t\t.command(\"upsert\")\n\t\t.description(\"Insert or update a memory record.\")\n\t\t.argument(\"<text>\", \"Memory text.\")\n\t\t.option(\"--id <id>\", \"Stable logical id.\")\n\t\t.option(\"--title <title>\", \"Optional title.\")\n\t\t.option(\"--namespace <namespace>\", \"Optional namespace override.\")\n\t\t.option(\"--source <source>\", \"Optional source label.\")\n\t\t.option(\"--metadata <json>\", \"Optional metadata JSON object.\")\n\t\t.action(async (text, opts) => {\n\t\t\tconst options = opts as Record<string, unknown>;\n\t\t\tconst service = await createCloudflareMemoryService({\n\t\t\t\tpluginConfig: params.pluginConfig,\n\t\t\t\topenClawConfig: params.openClawConfig,\n\t\t\t\tenv: process.env,\n\t\t\t\tresolvePath: params.resolvePath,\n\t\t\t});\n\t\t\tconst result = await service.upsert({\n\t\t\t\tinput: {\n\t\t\t\t\tid: options.id as string | undefined,\n\t\t\t\t\ttitle: options.title as string | undefined,\n\t\t\t\t\ttext: String(text),\n\t\t\t\t\tnamespace: options.namespace as string | undefined,\n\t\t\t\t\tsource: options.source as string | undefined,\n\t\t\t\t\tmetadata: parseMetadataFlag(options.metadata as string | undefined),\n\t\t\t\t},\n\t\t\t});\n\t\t\tprintJson(result);\n\t\t});\n\n\troot\n\t\t.command(\"delete\")\n\t\t.description(\"Delete a memory record.\")\n\t\t.argument(\"<id>\", \"Logical memory record id.\")\n\t\t.option(\"--namespace <namespace>\", \"Optional namespace override.\")\n\t\t.action(async (id, opts) => {\n\t\t\tconst options = opts as Record<string, unknown>;\n\t\t\tconst service = await createCloudflareMemoryService({\n\t\t\t\tpluginConfig: params.pluginConfig,\n\t\t\t\topenClawConfig: params.openClawConfig,\n\t\t\t\tenv: process.env,\n\t\t\t\tresolvePath: params.resolvePath,\n\t\t\t});\n\t\t\tconst mutationId = await service.delete({\n\t\t\t\tid: String(id),\n\t\t\t\tnamespace: options.namespace as string | undefined,\n\t\t\t});\n\t\t\tprintJson({ id, mutationId });\n\t\t});\n\n\troot\n\t\t.command(\"migrate\")\n\t\t.description(\"Migrate legacy markdown memory into Cloudflare Vectorize.\")\n\t\t.argument(\"[sources...]\", \"Markdown files, directories, or glob patterns. Defaults to the current OpenClaw memory corpus when omitted.\")\n\t\t.option(\"--workspace <path>\", \"Workspace root used for default-provider discovery and relative path normalization.\")\n\t\t.option(\"--namespace <namespace>\", \"Target namespace override.\")\n\t\t.option(\"--derive-namespace-from-path\", \"Derive namespaces from the first relative path segment instead of using a single target namespace.\")\n\t\t.option(\"--if-exists <strategy>\", \"Duplicate handling: overwrite, skip, or fail.\")\n\t\t.option(\"--create-index\", \"Create the Vectorize index if missing.\")\n\t\t.option(\"--dry-run\", \"Plan the migration without writing records.\")\n\t\t.option(\"--json\", \"Print structured JSON output.\")\n\t\t.action(async (...args) => {\n\t\t\tconst { positionals, options } = resolveInvocation(args);\n\t\t\tconst rawSources = positionals[0];\n\t\t\tconst sourcePaths =\n\t\t\t\tpositionals.length === 0 ? [] : Array.isArray(rawSources) ? rawSources.map((value) => String(value)) : positionals.map((value) => String(value));\n\t\t\tconst service = await createCloudflareMemoryService({\n\t\t\t\tpluginConfig: params.pluginConfig,\n\t\t\t\topenClawConfig: params.openClawConfig,\n\t\t\t\tenv: process.env,\n\t\t\t\tresolvePath: params.resolvePath,\n\t\t\t});\n\t\t\tconst summary = await runCloudflareMemoryMigration({\n\t\t\t\tservice,\n\t\t\t\toptions: {\n\t\t\t\t\tsourcePaths,\n\t\t\t\t\tworkspaceDir: options.workspace as string | undefined,\n\t\t\t\t\tnamespace: options.namespace as string | undefined,\n\t\t\t\t\tnamespaceStrategy: options.deriveNamespaceFromPath ? \"path\" : \"single-target\",\n\t\t\t\t\tduplicateStrategy: parseDuplicateStrategy(options.ifExists),\n\t\t\t\t\tdryRun: Boolean(options.dryRun),\n\t\t\t\t\tcreateIndexIfMissing: Boolean(options.createIndex),\n\t\t\t\t},\n\t\t\t});\n\t\t\tif (options.json) {\n\t\t\t\tprintJson(summary);\n\t\t\t} else {\n\t\t\t\tconsole.log(formatMigrationSummary(summary));\n\t\t\t}\n\t\t\tif (summary.failed > 0) {\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t});\n}\n"],"mappings":";;;AAeA,SAAS,EAAU,GAAsB;AACxC,SAAQ,IAAI,KAAK,UAAU,GAAO,MAAM,EAAE,CAAC;;AAG5C,SAAS,EAAkB,GAAkF;AAC5G,KAAI,CAAC,EACJ;CAED,IAA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,EAAQ;IACtC;GACD,CAAC;AAMF,EALI,EAAQ,OACX,EAAU,EAAQ,GAElB,QAAQ,IAAI,EAAuB,EAAQ,CAAC,EAEzC,EAAQ,SAAS,MACpB,QAAQ,WAAW;GAEnB"}
@@ -0,0 +1,24 @@
1
+ import { CloudflareApiError as e } from "./errors.js";
2
+ //#region src/cloudflare-api.ts
3
+ function t(e, t) {
4
+ return e?.errors?.map((e) => e.message).filter(Boolean).join("; ") || t;
5
+ }
6
+ function n(t) {
7
+ return t instanceof e && t.status === 404;
8
+ }
9
+ async function r(n) {
10
+ let r = new Headers(n.headers);
11
+ r.set("Authorization", `Bearer ${n.apiToken}`), !r.has("Content-Type") && n.body && r.set("Content-Type", "application/json");
12
+ let i = await fetch(n.url, {
13
+ method: n.method ?? (n.body ? "POST" : "GET"),
14
+ headers: r,
15
+ body: n.body
16
+ }), a = await i.text(), o = a ? JSON.parse(a) : void 0;
17
+ if (!i.ok) throw new e(t(o, `Cloudflare request failed with ${i.status}.`), i.status, o);
18
+ if (!o?.success) throw new e(t(o, "Cloudflare request failed."), i.status, o);
19
+ return o.result;
20
+ }
21
+ //#endregion
22
+ export { n as isCloudflareNotFoundError, r as requestCloudflare };
23
+
24
+ //# sourceMappingURL=cloudflare-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare-api.js","names":[],"sources":["../src/cloudflare-api.ts"],"sourcesContent":["import { CloudflareApiError } from \"./errors.js\";\n\ntype CloudflareResponseEnvelope<T> = {\n\tsuccess: boolean;\n\tresult: T;\n\terrors?: Array<{ code?: number; message?: string }>;\n};\n\nfunction describeFailure(envelope: Partial<CloudflareResponseEnvelope<unknown>> | undefined, fallback: string): string {\n\tconst message = envelope?.errors\n\t\t?.map((entry) => entry.message)\n\t\t.filter(Boolean)\n\t\t.join(\"; \");\n\treturn message || fallback;\n}\n\nexport function isCloudflareNotFoundError(error: unknown): boolean {\n\treturn error instanceof CloudflareApiError && error.status === 404;\n}\n\nexport async function requestCloudflare<T>(params: {\n\turl: string;\n\tapiToken: string;\n\tmethod?: string;\n\theaders?: Record<string, string>;\n\tbody?: string;\n}): Promise<T> {\n\tconst headers = new Headers(params.headers);\n\theaders.set(\"Authorization\", `Bearer ${params.apiToken}`);\n\tif (!headers.has(\"Content-Type\") && params.body) {\n\t\theaders.set(\"Content-Type\", \"application/json\");\n\t}\n\n\tconst response = await fetch(params.url, {\n\t\tmethod: params.method ?? (params.body ? \"POST\" : \"GET\"),\n\t\theaders,\n\t\tbody: params.body,\n\t});\n\n\tconst rawText = await response.text();\n\tconst parsed = rawText ? (JSON.parse(rawText) as CloudflareResponseEnvelope<T>) : undefined;\n\tif (!response.ok) {\n\t\tthrow new CloudflareApiError(describeFailure(parsed, `Cloudflare request failed with ${response.status}.`), response.status, parsed);\n\t}\n\tif (!parsed?.success) {\n\t\tthrow new CloudflareApiError(describeFailure(parsed, \"Cloudflare request failed.\"), response.status, parsed);\n\t}\n\n\treturn parsed.result;\n}\n"],"mappings":";;AAQA,SAAS,EAAgB,GAAoE,GAA0B;AAKtH,QAJgB,GAAU,QACvB,KAAK,MAAU,EAAM,QAAQ,CAC9B,OAAO,QAAQ,CACf,KAAK,KAAK,IACM;;AAGnB,SAAgB,EAA0B,GAAyB;AAClE,QAAO,aAAiB,KAAsB,EAAM,WAAW;;AAGhE,eAAsB,EAAqB,GAM5B;CACd,IAAM,IAAU,IAAI,QAAQ,EAAO,QAAQ;AAE3C,CADA,EAAQ,IAAI,iBAAiB,UAAU,EAAO,WAAW,EACrD,CAAC,EAAQ,IAAI,eAAe,IAAI,EAAO,QAC1C,EAAQ,IAAI,gBAAgB,mBAAmB;CAGhD,IAAM,IAAW,MAAM,MAAM,EAAO,KAAK;EACxC,QAAQ,EAAO,WAAW,EAAO,OAAO,SAAS;EACjD;EACA,MAAM,EAAO;EACb,CAAC,EAEI,IAAU,MAAM,EAAS,MAAM,EAC/B,IAAS,IAAW,KAAK,MAAM,EAAQ,GAAqC,KAAA;AAClF,KAAI,CAAC,EAAS,GACb,OAAM,IAAI,EAAmB,EAAgB,GAAQ,kCAAkC,EAAS,OAAO,GAAG,EAAE,EAAS,QAAQ,EAAO;AAErI,KAAI,CAAC,GAAQ,QACZ,OAAM,IAAI,EAAmB,EAAgB,GAAQ,6BAA6B,EAAE,EAAS,QAAQ,EAAO;AAG7G,QAAO,EAAO"}
@@ -0,0 +1,43 @@
1
+ import { mkdir as e, readFile as t, rm as n, writeFile as r } from "node:fs/promises";
2
+ import { dirname as i } from "node:path";
3
+ //#region src/companion-store.ts
4
+ function a(e, t) {
5
+ return `${e}::${t}`;
6
+ }
7
+ async function o(e) {
8
+ try {
9
+ let n = await t(e, "utf8");
10
+ return JSON.parse(n);
11
+ } catch {
12
+ return {
13
+ version: 1,
14
+ records: {}
15
+ };
16
+ }
17
+ }
18
+ var s = class {
19
+ constructor(e) {
20
+ this.path = e;
21
+ }
22
+ get filePath() {
23
+ return this.path;
24
+ }
25
+ async upsert(t) {
26
+ let n = await o(this.path);
27
+ n.records[a(t.namespace, t.id)] = t, await e(i(this.path), { recursive: !0 }), await r(this.path, JSON.stringify(n, null, 2), "utf8");
28
+ }
29
+ async get(e, t) {
30
+ return (await o(this.path)).records[a(e, t)] ?? null;
31
+ }
32
+ async delete(t, n) {
33
+ let s = await o(this.path);
34
+ delete s.records[a(t, n)], await e(i(this.path), { recursive: !0 }), await r(this.path, JSON.stringify(s, null, 2), "utf8");
35
+ }
36
+ async clear() {
37
+ await n(this.path, { force: !0 });
38
+ }
39
+ };
40
+ //#endregion
41
+ export { s as CompanionStore };
42
+
43
+ //# sourceMappingURL=companion-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"companion-store.js","names":[],"sources":["../src/companion-store.ts"],"sourcesContent":["import { mkdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport type { CompanionRecord } from \"./types.js\";\n\ntype CompanionStoreFile = {\n\tversion: 1;\n\trecords: Record<string, CompanionRecord>;\n};\n\nfunction buildStoreKey(namespace: string, id: string): string {\n\treturn `${namespace}::${id}`;\n}\n\nasync function readStore(path: string): Promise<CompanionStoreFile> {\n\ttry {\n\t\tconst raw = await readFile(path, \"utf8\");\n\t\treturn JSON.parse(raw) as CompanionStoreFile;\n\t} catch {\n\t\treturn {\n\t\t\tversion: 1,\n\t\t\trecords: {},\n\t\t};\n\t}\n}\n\nexport class CompanionStore {\n\tconstructor(private readonly path: string) {}\n\n\tget filePath(): string {\n\t\treturn this.path;\n\t}\n\n\tasync upsert(record: CompanionRecord): Promise<void> {\n\t\tconst state = await readStore(this.path);\n\t\tstate.records[buildStoreKey(record.namespace, record.id)] = record;\n\t\tawait mkdir(dirname(this.path), { recursive: true });\n\t\tawait writeFile(this.path, JSON.stringify(state, null, 2), \"utf8\");\n\t}\n\n\tasync get(namespace: string, id: string): Promise<CompanionRecord | null> {\n\t\tconst state = await readStore(this.path);\n\t\treturn state.records[buildStoreKey(namespace, id)] ?? null;\n\t}\n\n\tasync delete(namespace: string, id: string): Promise<void> {\n\t\tconst state = await readStore(this.path);\n\t\tdelete state.records[buildStoreKey(namespace, id)];\n\t\tawait mkdir(dirname(this.path), { recursive: true });\n\t\tawait writeFile(this.path, JSON.stringify(state, null, 2), \"utf8\");\n\t}\n\n\tasync clear(): Promise<void> {\n\t\tawait rm(this.path, { force: true });\n\t}\n}\n"],"mappings":";;;AASA,SAAS,EAAc,GAAmB,GAAoB;AAC7D,QAAO,GAAG,EAAU,IAAI;;AAGzB,eAAe,EAAU,GAA2C;AACnE,KAAI;EACH,IAAM,IAAM,MAAM,EAAS,GAAM,OAAO;AACxC,SAAO,KAAK,MAAM,EAAI;SACf;AACP,SAAO;GACN,SAAS;GACT,SAAS,EAAE;GACX;;;AAIH,IAAa,IAAb,MAA4B;CAC3B,YAAY,GAA+B;AAAd,OAAA,OAAA;;CAE7B,IAAI,WAAmB;AACtB,SAAO,KAAK;;CAGb,MAAM,OAAO,GAAwC;EACpD,IAAM,IAAQ,MAAM,EAAU,KAAK,KAAK;AAGxC,EAFA,EAAM,QAAQ,EAAc,EAAO,WAAW,EAAO,GAAG,IAAI,GAC5D,MAAM,EAAM,EAAQ,KAAK,KAAK,EAAE,EAAE,WAAW,IAAM,CAAC,EACpD,MAAM,EAAU,KAAK,MAAM,KAAK,UAAU,GAAO,MAAM,EAAE,EAAE,OAAO;;CAGnE,MAAM,IAAI,GAAmB,GAA6C;AAEzE,UADc,MAAM,EAAU,KAAK,KAAK,EAC3B,QAAQ,EAAc,GAAW,EAAG,KAAK;;CAGvD,MAAM,OAAO,GAAmB,GAA2B;EAC1D,IAAM,IAAQ,MAAM,EAAU,KAAK,KAAK;AAGxC,EAFA,OAAO,EAAM,QAAQ,EAAc,GAAW,EAAG,GACjD,MAAM,EAAM,EAAQ,KAAK,KAAK,EAAE,EAAE,WAAW,IAAM,CAAC,EACpD,MAAM,EAAU,KAAK,MAAM,KAAK,UAAU,GAAO,MAAM,EAAE,EAAE,OAAO;;CAGnE,MAAM,QAAuB;AAC5B,QAAM,EAAG,KAAK,MAAM,EAAE,OAAO,IAAM,CAAC"}
package/dist/config.js ADDED
@@ -0,0 +1,290 @@
1
+ import { CLOUDFLARE_ACCOUNT_ID_ENV as e, CLOUDFLARE_API_TOKEN_ENV as t, COMPANION_PATH_ENV as n, DEFAULT_CLOUDFLARE_API_BASE_URL as r, DEFAULT_EMBEDDING_MODEL as i, DEFAULT_STORAGE_MODE as a, PLUGIN_ID as o, STORAGE_MODE_ENV as s, VECTORIZE_INDEX_ENV as c, VECTORIZE_NAMESPACE_ENV as l, VECTORIZE_TOP_K_ENV as u, WORKERS_AI_MODEL_ENV as d } from "./constants.js";
2
+ import { ConfigurationError as f } from "./errors.js";
3
+ import { join as p } from "node:path";
4
+ import { resolveConfiguredSecretInputWithFallback as m } from "openclaw/plugin-sdk/config-runtime";
5
+ import { z as h } from "zod";
6
+ //#region src/config.ts
7
+ var g = h.object({
8
+ source: h.enum([
9
+ "env",
10
+ "file",
11
+ "exec"
12
+ ]),
13
+ provider: h.string().min(1),
14
+ id: h.string().min(1)
15
+ }).strict(), _ = h.union([h.string().min(1), g]), v = h.object({
16
+ description: h.string().min(1).optional(),
17
+ dimensions: h.number().int().min(1).max(1536).optional(),
18
+ metric: h.enum([
19
+ "cosine",
20
+ "euclidean",
21
+ "dot-product"
22
+ ]).optional()
23
+ }).strict(), y = h.object({
24
+ cloudflare: h.object({
25
+ accountId: h.string().min(1).optional(),
26
+ apiToken: _.optional(),
27
+ apiBaseUrl: h.string().url().optional(),
28
+ workersAiBaseUrl: h.string().url().optional(),
29
+ vectorizeBaseUrl: h.string().url().optional()
30
+ }).strict().optional(),
31
+ vectorize: h.object({
32
+ indexName: h.string().min(1).optional(),
33
+ namespace: h.string().min(1).optional(),
34
+ topK: h.number().int().min(1).max(50).optional(),
35
+ minScore: h.number().min(0).max(1).optional(),
36
+ metric: h.enum([
37
+ "cosine",
38
+ "euclidean",
39
+ "dot-product"
40
+ ]).optional(),
41
+ createIndex: v.optional(),
42
+ metadataIndexedFields: h.array(h.string().min(1)).default([])
43
+ }).strict().optional(),
44
+ embeddings: h.object({ model: h.string().min(1).optional() }).strict().optional(),
45
+ storage: h.object({
46
+ mode: h.enum(["vectorize-inline", "companion-store"]).optional(),
47
+ companionStorePath: h.string().min(1).optional(),
48
+ inlineTextMaxBytes: h.number().int().min(256).max(1e4).optional()
49
+ }).strict().optional()
50
+ }).strict(), b = {
51
+ parse(e) {
52
+ return y.parse(e ?? {});
53
+ },
54
+ safeParse(e) {
55
+ let t = y.safeParse(e ?? {});
56
+ return t.success ? {
57
+ success: !0,
58
+ data: t.data
59
+ } : {
60
+ success: !1,
61
+ error: { issues: t.error.issues.map((e) => ({
62
+ path: e.path.filter((e) => typeof e == "string" || typeof e == "number"),
63
+ message: e.message
64
+ })) }
65
+ };
66
+ },
67
+ jsonSchema: {
68
+ type: "object",
69
+ additionalProperties: !1,
70
+ properties: {
71
+ cloudflare: {
72
+ type: "object",
73
+ additionalProperties: !1,
74
+ properties: {
75
+ accountId: { type: "string" },
76
+ apiToken: { anyOf: [{ type: "string" }, {
77
+ type: "object",
78
+ additionalProperties: !1,
79
+ properties: {
80
+ source: {
81
+ type: "string",
82
+ enum: [
83
+ "env",
84
+ "file",
85
+ "exec"
86
+ ]
87
+ },
88
+ provider: { type: "string" },
89
+ id: { type: "string" }
90
+ },
91
+ required: [
92
+ "source",
93
+ "provider",
94
+ "id"
95
+ ]
96
+ }] },
97
+ apiBaseUrl: {
98
+ type: "string",
99
+ format: "uri"
100
+ },
101
+ workersAiBaseUrl: {
102
+ type: "string",
103
+ format: "uri"
104
+ },
105
+ vectorizeBaseUrl: {
106
+ type: "string",
107
+ format: "uri"
108
+ }
109
+ }
110
+ },
111
+ vectorize: {
112
+ type: "object",
113
+ additionalProperties: !1,
114
+ properties: {
115
+ indexName: { type: "string" },
116
+ namespace: { type: "string" },
117
+ topK: {
118
+ type: "integer",
119
+ minimum: 1,
120
+ maximum: 50
121
+ },
122
+ minScore: {
123
+ type: "number",
124
+ minimum: 0,
125
+ maximum: 1
126
+ },
127
+ metric: {
128
+ type: "string",
129
+ enum: [
130
+ "cosine",
131
+ "euclidean",
132
+ "dot-product"
133
+ ]
134
+ },
135
+ createIndex: {
136
+ type: "object",
137
+ additionalProperties: !1,
138
+ properties: {
139
+ description: { type: "string" },
140
+ dimensions: {
141
+ type: "integer",
142
+ minimum: 1,
143
+ maximum: 1536
144
+ },
145
+ metric: {
146
+ type: "string",
147
+ enum: [
148
+ "cosine",
149
+ "euclidean",
150
+ "dot-product"
151
+ ]
152
+ }
153
+ }
154
+ },
155
+ metadataIndexedFields: {
156
+ type: "array",
157
+ items: { type: "string" }
158
+ }
159
+ }
160
+ },
161
+ embeddings: {
162
+ type: "object",
163
+ additionalProperties: !1,
164
+ properties: { model: { type: "string" } }
165
+ },
166
+ storage: {
167
+ type: "object",
168
+ additionalProperties: !1,
169
+ properties: {
170
+ mode: {
171
+ type: "string",
172
+ enum: ["vectorize-inline", "companion-store"]
173
+ },
174
+ companionStorePath: { type: "string" },
175
+ inlineTextMaxBytes: {
176
+ type: "integer",
177
+ minimum: 256,
178
+ maximum: 1e4
179
+ }
180
+ }
181
+ }
182
+ }
183
+ },
184
+ uiHints: {
185
+ "cloudflare.accountId": {
186
+ label: "Cloudflare account ID",
187
+ help: `Defaults to \${${e}}.`
188
+ },
189
+ "cloudflare.apiToken": {
190
+ label: "Cloudflare API token",
191
+ sensitive: !0,
192
+ help: `Defaults to \${${t}}.`
193
+ },
194
+ "vectorize.indexName": {
195
+ label: "Vectorize index name",
196
+ help: `Defaults to \${${c}}.`
197
+ },
198
+ "vectorize.namespace": {
199
+ label: "Fixed namespace override",
200
+ help: `Defaults to \${${l}} or derives from the agent/session context.`
201
+ },
202
+ "vectorize.topK": {
203
+ label: "Top-K results",
204
+ help: `Defaults to \${${u}} or 5.`
205
+ },
206
+ "embeddings.model": {
207
+ label: "Workers AI embedding model",
208
+ help: `Defaults to \${${d}} or ${i}.`
209
+ },
210
+ "storage.mode": {
211
+ label: "Storage mode",
212
+ help: `Defaults to \${${s}} or ${a}.`
213
+ },
214
+ "storage.companionStorePath": {
215
+ label: "Companion store path",
216
+ help: `Defaults to \${${n}} or the OpenClaw state directory.`
217
+ }
218
+ }
219
+ };
220
+ function x(...e) {
221
+ return e.find((e) => e !== void 0);
222
+ }
223
+ function S(...e) {
224
+ for (let t of e) if (t && t.trim().length > 0) return t.trim();
225
+ }
226
+ function C(...e) {
227
+ return e.find((e) => typeof e == "number" && Number.isFinite(e));
228
+ }
229
+ function w(e) {
230
+ return [...new Set((e ?? []).map((e) => e.trim()).filter(Boolean))];
231
+ }
232
+ function T(e) {
233
+ return e ?? "cosine";
234
+ }
235
+ function E(e) {
236
+ return e ?? "vectorize-inline";
237
+ }
238
+ function D(e) {
239
+ return y.parse(e ?? {});
240
+ }
241
+ function O(e) {
242
+ let t = e.plugins?.entries?.[o];
243
+ return D(t ?? {});
244
+ }
245
+ async function k(n) {
246
+ let a = D(n.pluginConfig), h = n.env ?? process.env, g = `plugins.entries.${o}`, _ = S(a.cloudflare?.accountId, h[e]);
247
+ if (!_) throw new f(`Missing Cloudflare account id. Set ${e} or ${g}.cloudflare.accountId.`);
248
+ let v = await m({
249
+ config: n.openClawConfig,
250
+ env: h,
251
+ value: a.cloudflare?.apiToken,
252
+ path: `${g}.cloudflare.apiToken`,
253
+ unresolvedReasonStyle: "detailed",
254
+ readFallback: () => h[t]
255
+ });
256
+ if (!v.value) throw new f(`Missing Cloudflare API token. Set ${t} or ${g}.cloudflare.apiToken.${v.unresolvedRefReason ? ` ${v.unresolvedRefReason}` : ""}`.trim());
257
+ let y = S(a.vectorize?.indexName, h[c]);
258
+ if (!y) throw new f(`Missing Vectorize index name. Set ${c} or ${g}.vectorize.indexName.`);
259
+ let b = S(a.cloudflare?.apiBaseUrl, r);
260
+ if (!b) throw new f(`Invalid Cloudflare API base URL. Set ${g}.cloudflare.apiBaseUrl or ensure ${r} is a valid URL.`);
261
+ let O = S(a.vectorize?.namespace, h[l]), k = C(a.vectorize?.topK, h.CLOUDFLARE_VECTORIZE_TOP_K ? Number(h[u]) : void 0), A = E(x(a.storage?.mode, h[s])), j = S(a.storage?.companionStorePath, h.OPENCLAW_CF_MEMORY_COMPANION_PATH) ?? p(".openclaw", "memory-cloudflare-vectorize", "companion-store.json"), M = n.resolvePath ?? ((e) => e), N = S(a.embeddings?.model, h[d], i);
262
+ if (!N) throw new f(`Missing Workers AI embedding model. Set ${d} or ${g}.embeddings.model.`);
263
+ let P = C(a.storage?.inlineTextMaxBytes) ?? 6e3, F = C(a.vectorize?.minScore) ?? 0, I = T(x(a.vectorize?.metric, a.vectorize?.createIndex?.metric));
264
+ return {
265
+ accountId: _,
266
+ apiToken: v.value,
267
+ apiBaseUrl: b,
268
+ workersAiBaseUrl: S(a.cloudflare?.workersAiBaseUrl) ?? `${b}/accounts/${_}/ai/v1`,
269
+ vectorizeBaseUrl: S(a.cloudflare?.vectorizeBaseUrl) ?? `${b}/accounts/${_}/vectorize/v2/indexes/${y}`,
270
+ indexName: y,
271
+ fixedNamespace: O,
272
+ topK: k ?? 5,
273
+ minScore: F,
274
+ metric: I,
275
+ model: N,
276
+ storageMode: A,
277
+ companionStorePath: M(j),
278
+ inlineTextMaxBytes: P,
279
+ metadataIndexedFields: w(a.vectorize?.metadataIndexedFields),
280
+ createIndex: {
281
+ description: a.vectorize?.createIndex?.description ?? "OpenClaw memory index backed by Cloudflare Vectorize.",
282
+ dimensions: a.vectorize?.createIndex?.dimensions,
283
+ metric: I
284
+ }
285
+ };
286
+ }
287
+ //#endregion
288
+ export { O as getPluginConfigFromOpenClawConfig, b as pluginConfigSchema, k as resolvePluginConfig };
289
+
290
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","names":[],"sources":["../src/config.ts"],"sourcesContent":["import { join } from \"node:path\";\nimport type { OpenClawConfig } from \"openclaw/plugin-sdk/config-runtime\";\nimport { resolveConfiguredSecretInputWithFallback } from \"openclaw/plugin-sdk/config-runtime\";\nimport type { OpenClawPluginConfigSchema } from \"openclaw/plugin-sdk/plugin-entry\";\nimport type { SecretInput } from \"openclaw/plugin-sdk/secret-ref-runtime\";\nimport { z } from \"zod\";\nimport {\n\tCLOUDFLARE_ACCOUNT_ID_ENV,\n\tCLOUDFLARE_API_TOKEN_ENV,\n\tCOMPANION_PATH_ENV,\n\tDEFAULT_CLOUDFLARE_API_BASE_URL,\n\tDEFAULT_EMBEDDING_MODEL,\n\tDEFAULT_INDEX_DESCRIPTION,\n\tDEFAULT_INLINE_TEXT_MAX_BYTES,\n\tDEFAULT_MIN_SCORE,\n\tDEFAULT_STORAGE_MODE,\n\tDEFAULT_TOP_K,\n\tDEFAULT_VECTORIZE_METRIC,\n\tPLUGIN_ID,\n\tSTORAGE_MODE_ENV,\n\tVECTORIZE_INDEX_ENV,\n\tVECTORIZE_NAMESPACE_ENV,\n\tVECTORIZE_TOP_K_ENV,\n\tWORKERS_AI_MODEL_ENV,\n} from \"./constants.js\";\nimport { ConfigurationError } from \"./errors.js\";\nimport type { RawPluginConfig, ResolvedPluginConfig, StorageMode, VectorizeMetric } from \"./types.js\";\n\nconst secretRefSchema = z\n\t.object({\n\t\tsource: z.enum([\"env\", \"file\", \"exec\"]),\n\t\tprovider: z.string().min(1),\n\t\tid: z.string().min(1),\n\t})\n\t.strict();\n\nconst secretInputSchema: z.ZodType<SecretInput> = z.union([z.string().min(1), secretRefSchema]);\n\nconst createIndexSchema = z\n\t.object({\n\t\tdescription: z.string().min(1).optional(),\n\t\tdimensions: z.number().int().min(1).max(1536).optional(),\n\t\tmetric: z.enum([\"cosine\", \"euclidean\", \"dot-product\"]).optional(),\n\t})\n\t.strict();\n\nconst pluginConfigZod: z.ZodType<RawPluginConfig> = z\n\t.object({\n\t\tcloudflare: z\n\t\t\t.object({\n\t\t\t\taccountId: z.string().min(1).optional(),\n\t\t\t\tapiToken: secretInputSchema.optional(),\n\t\t\t\tapiBaseUrl: z.string().url().optional(),\n\t\t\t\tworkersAiBaseUrl: z.string().url().optional(),\n\t\t\t\tvectorizeBaseUrl: z.string().url().optional(),\n\t\t\t})\n\t\t\t.strict()\n\t\t\t.optional(),\n\t\tvectorize: z\n\t\t\t.object({\n\t\t\t\tindexName: z.string().min(1).optional(),\n\t\t\t\tnamespace: z.string().min(1).optional(),\n\t\t\t\ttopK: z.number().int().min(1).max(50).optional(),\n\t\t\t\tminScore: z.number().min(0).max(1).optional(),\n\t\t\t\tmetric: z.enum([\"cosine\", \"euclidean\", \"dot-product\"]).optional(),\n\t\t\t\tcreateIndex: createIndexSchema.optional(),\n\t\t\t\tmetadataIndexedFields: z.array(z.string().min(1)).default([]),\n\t\t\t})\n\t\t\t.strict()\n\t\t\t.optional(),\n\t\tembeddings: z\n\t\t\t.object({\n\t\t\t\tmodel: z.string().min(1).optional(),\n\t\t\t})\n\t\t\t.strict()\n\t\t\t.optional(),\n\t\tstorage: z\n\t\t\t.object({\n\t\t\t\tmode: z.enum([\"vectorize-inline\", \"companion-store\"]).optional(),\n\t\t\t\tcompanionStorePath: z.string().min(1).optional(),\n\t\t\t\tinlineTextMaxBytes: z.number().int().min(256).max(10_000).optional(),\n\t\t\t})\n\t\t\t.strict()\n\t\t\t.optional(),\n\t})\n\t.strict();\n\nexport const pluginConfigJsonSchema = {\n\ttype: \"object\",\n\tadditionalProperties: false,\n\tproperties: {\n\t\tcloudflare: {\n\t\t\ttype: \"object\",\n\t\t\tadditionalProperties: false,\n\t\t\tproperties: {\n\t\t\t\taccountId: { type: \"string\" },\n\t\t\t\tapiToken: {\n\t\t\t\t\tanyOf: [\n\t\t\t\t\t\t{ type: \"string\" },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\tsource: { type: \"string\", enum: [\"env\", \"file\", \"exec\"] },\n\t\t\t\t\t\t\t\tprovider: { type: \"string\" },\n\t\t\t\t\t\t\t\tid: { type: \"string\" },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\trequired: [\"source\", \"provider\", \"id\"],\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\tapiBaseUrl: { type: \"string\", format: \"uri\" },\n\t\t\t\tworkersAiBaseUrl: { type: \"string\", format: \"uri\" },\n\t\t\t\tvectorizeBaseUrl: { type: \"string\", format: \"uri\" },\n\t\t\t},\n\t\t},\n\t\tvectorize: {\n\t\t\ttype: \"object\",\n\t\t\tadditionalProperties: false,\n\t\t\tproperties: {\n\t\t\t\tindexName: { type: \"string\" },\n\t\t\t\tnamespace: { type: \"string\" },\n\t\t\t\ttopK: { type: \"integer\", minimum: 1, maximum: 50 },\n\t\t\t\tminScore: { type: \"number\", minimum: 0, maximum: 1 },\n\t\t\t\tmetric: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tenum: [\"cosine\", \"euclidean\", \"dot-product\"],\n\t\t\t\t},\n\t\t\t\tcreateIndex: {\n\t\t\t\t\ttype: \"object\",\n\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t\tproperties: {\n\t\t\t\t\t\tdescription: { type: \"string\" },\n\t\t\t\t\t\tdimensions: { type: \"integer\", minimum: 1, maximum: 1536 },\n\t\t\t\t\t\tmetric: {\n\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\tenum: [\"cosine\", \"euclidean\", \"dot-product\"],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tmetadataIndexedFields: {\n\t\t\t\t\ttype: \"array\",\n\t\t\t\t\titems: { type: \"string\" },\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tembeddings: {\n\t\t\ttype: \"object\",\n\t\t\tadditionalProperties: false,\n\t\t\tproperties: {\n\t\t\t\tmodel: { type: \"string\" },\n\t\t\t},\n\t\t},\n\t\tstorage: {\n\t\t\ttype: \"object\",\n\t\t\tadditionalProperties: false,\n\t\t\tproperties: {\n\t\t\t\tmode: { type: \"string\", enum: [\"vectorize-inline\", \"companion-store\"] },\n\t\t\t\tcompanionStorePath: { type: \"string\" },\n\t\t\t\tinlineTextMaxBytes: { type: \"integer\", minimum: 256, maximum: 10000 },\n\t\t\t},\n\t\t},\n\t},\n} as const;\n\nexport const pluginUiHints = {\n\t\"cloudflare.accountId\": {\n\t\tlabel: \"Cloudflare account ID\",\n\t\thelp: `Defaults to \\${${CLOUDFLARE_ACCOUNT_ID_ENV}}.`,\n\t},\n\t\"cloudflare.apiToken\": {\n\t\tlabel: \"Cloudflare API token\",\n\t\tsensitive: true,\n\t\thelp: `Defaults to \\${${CLOUDFLARE_API_TOKEN_ENV}}.`,\n\t},\n\t\"vectorize.indexName\": {\n\t\tlabel: \"Vectorize index name\",\n\t\thelp: `Defaults to \\${${VECTORIZE_INDEX_ENV}}.`,\n\t},\n\t\"vectorize.namespace\": {\n\t\tlabel: \"Fixed namespace override\",\n\t\thelp: `Defaults to \\${${VECTORIZE_NAMESPACE_ENV}} or derives from the agent/session context.`,\n\t},\n\t\"vectorize.topK\": {\n\t\tlabel: \"Top-K results\",\n\t\thelp: `Defaults to \\${${VECTORIZE_TOP_K_ENV}} or ${DEFAULT_TOP_K}.`,\n\t},\n\t\"embeddings.model\": {\n\t\tlabel: \"Workers AI embedding model\",\n\t\thelp: `Defaults to \\${${WORKERS_AI_MODEL_ENV}} or ${DEFAULT_EMBEDDING_MODEL}.`,\n\t},\n\t\"storage.mode\": {\n\t\tlabel: \"Storage mode\",\n\t\thelp: `Defaults to \\${${STORAGE_MODE_ENV}} or ${DEFAULT_STORAGE_MODE}.`,\n\t},\n\t\"storage.companionStorePath\": {\n\t\tlabel: \"Companion store path\",\n\t\thelp: `Defaults to \\${${COMPANION_PATH_ENV}} or the OpenClaw state directory.`,\n\t},\n} as const;\n\nexport const pluginConfigSchema: OpenClawPluginConfigSchema = {\n\tparse(value: unknown) {\n\t\treturn pluginConfigZod.parse(value ?? {});\n\t},\n\tsafeParse(value: unknown) {\n\t\tconst result = pluginConfigZod.safeParse(value ?? {});\n\t\tif (result.success) {\n\t\t\treturn { success: true, data: result.data };\n\t\t}\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: {\n\t\t\t\tissues: result.error.issues.map((issue) => ({\n\t\t\t\t\tpath: issue.path.filter((segment): segment is string | number => typeof segment === \"string\" || typeof segment === \"number\"),\n\t\t\t\t\tmessage: issue.message,\n\t\t\t\t})),\n\t\t\t},\n\t\t};\n\t},\n\tjsonSchema: pluginConfigJsonSchema,\n\tuiHints: pluginUiHints,\n};\n\ntype PluginEntriesAwareConfig = OpenClawConfig & {\n\tplugins?: {\n\t\tentries?: Record<string, unknown>;\n\t};\n};\n\nfunction pickFirstDefined<T>(...values: Array<T | undefined>): T | undefined {\n\treturn values.find((value) => value !== undefined);\n}\n\nfunction pickTrimmed(...values: Array<string | undefined>): string | undefined {\n\tfor (const value of values) {\n\t\tif (value && value.trim().length > 0) {\n\t\t\treturn value.trim();\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction pickNumber(...values: Array<number | undefined>): number | undefined {\n\treturn values.find((value) => typeof value === \"number\" && Number.isFinite(value));\n}\n\nfunction normalizeMetadataIndexedFields(fields: string[] | undefined): string[] {\n\treturn [...new Set((fields ?? []).map((field) => field.trim()).filter(Boolean))];\n}\n\nfunction ensureVectorizeMetric(metric: VectorizeMetric | undefined): VectorizeMetric {\n\treturn metric ?? DEFAULT_VECTORIZE_METRIC;\n}\n\nfunction ensureStorageMode(mode: StorageMode | undefined): StorageMode {\n\treturn mode ?? DEFAULT_STORAGE_MODE;\n}\n\nexport function parsePluginConfig(value: unknown): RawPluginConfig {\n\treturn pluginConfigZod.parse(value ?? {});\n}\n\nexport function getPluginConfigFromOpenClawConfig(config: OpenClawConfig): RawPluginConfig {\n\tconst candidate = (config as PluginEntriesAwareConfig).plugins?.entries?.[PLUGIN_ID];\n\treturn parsePluginConfig(candidate ?? {});\n}\n\nexport async function resolvePluginConfig(params: {\n\tpluginConfig: unknown;\n\topenClawConfig: OpenClawConfig;\n\tenv?: NodeJS.ProcessEnv;\n\tresolvePath?: (input: string) => string;\n}): Promise<ResolvedPluginConfig> {\n\tconst parsed = parsePluginConfig(params.pluginConfig);\n\tconst env = params.env ?? process.env;\n\tconst configPathBase = `plugins.entries.${PLUGIN_ID}`;\n\tconst accountId = pickTrimmed(parsed.cloudflare?.accountId, env[CLOUDFLARE_ACCOUNT_ID_ENV]);\n\tif (!accountId) {\n\t\tthrow new ConfigurationError(`Missing Cloudflare account id. Set ${CLOUDFLARE_ACCOUNT_ID_ENV} or ${configPathBase}.cloudflare.accountId.`);\n\t}\n\n\tconst tokenResult = await resolveConfiguredSecretInputWithFallback({\n\t\tconfig: params.openClawConfig,\n\t\tenv,\n\t\tvalue: parsed.cloudflare?.apiToken,\n\t\tpath: `${configPathBase}.cloudflare.apiToken`,\n\t\tunresolvedReasonStyle: \"detailed\",\n\t\treadFallback: () => env[CLOUDFLARE_API_TOKEN_ENV],\n\t});\n\tif (!tokenResult.value) {\n\t\tconst reason = tokenResult.unresolvedRefReason ? ` ${tokenResult.unresolvedRefReason}` : \"\";\n\t\tthrow new ConfigurationError(`Missing Cloudflare API token. Set ${CLOUDFLARE_API_TOKEN_ENV} or ${configPathBase}.cloudflare.apiToken.${reason}`.trim());\n\t}\n\n\tconst indexName = pickTrimmed(parsed.vectorize?.indexName, env[VECTORIZE_INDEX_ENV]);\n\tif (!indexName) {\n\t\tthrow new ConfigurationError(`Missing Vectorize index name. Set ${VECTORIZE_INDEX_ENV} or ${configPathBase}.vectorize.indexName.`);\n\t}\n\n\tconst apiBaseUrl = pickTrimmed(parsed.cloudflare?.apiBaseUrl, DEFAULT_CLOUDFLARE_API_BASE_URL);\n\tif (!apiBaseUrl) {\n\t\tthrow new ConfigurationError(\n\t\t\t`Invalid Cloudflare API base URL. Set ${configPathBase}.cloudflare.apiBaseUrl or ensure ${DEFAULT_CLOUDFLARE_API_BASE_URL} is a valid URL.`,\n\t\t);\n\t}\n\tconst fixedNamespace = pickTrimmed(parsed.vectorize?.namespace, env[VECTORIZE_NAMESPACE_ENV]);\n\tconst topK = pickNumber(parsed.vectorize?.topK, env[VECTORIZE_TOP_K_ENV] ? Number(env[VECTORIZE_TOP_K_ENV]) : undefined);\n\tconst storageMode = ensureStorageMode(pickFirstDefined(parsed.storage?.mode, env[STORAGE_MODE_ENV] as StorageMode | undefined));\n\tconst companionStorePath = pickTrimmed(parsed.storage?.companionStorePath, env[COMPANION_PATH_ENV]) ?? join(\".openclaw\", PLUGIN_ID, \"companion-store.json\");\n\n\tconst resolvePath = params.resolvePath ?? ((input: string) => input);\n\tconst model = pickTrimmed(parsed.embeddings?.model, env[WORKERS_AI_MODEL_ENV], DEFAULT_EMBEDDING_MODEL);\n\tif (!model) {\n\t\tthrow new ConfigurationError(`Missing Workers AI embedding model. Set ${WORKERS_AI_MODEL_ENV} or ${configPathBase}.embeddings.model.`);\n\t}\n\tconst inlineTextMaxBytes = pickNumber(parsed.storage?.inlineTextMaxBytes) ?? DEFAULT_INLINE_TEXT_MAX_BYTES;\n\tconst minScore = pickNumber(parsed.vectorize?.minScore) ?? DEFAULT_MIN_SCORE;\n\tconst metric = ensureVectorizeMetric(pickFirstDefined(parsed.vectorize?.metric, parsed.vectorize?.createIndex?.metric));\n\n\treturn {\n\t\taccountId,\n\t\tapiToken: tokenResult.value,\n\t\tapiBaseUrl,\n\t\tworkersAiBaseUrl: pickTrimmed(parsed.cloudflare?.workersAiBaseUrl) ?? `${apiBaseUrl}/accounts/${accountId}/ai/v1`,\n\t\tvectorizeBaseUrl: pickTrimmed(parsed.cloudflare?.vectorizeBaseUrl) ?? `${apiBaseUrl}/accounts/${accountId}/vectorize/v2/indexes/${indexName}`,\n\t\tindexName,\n\t\tfixedNamespace,\n\t\ttopK: topK ?? DEFAULT_TOP_K,\n\t\tminScore,\n\t\tmetric,\n\t\tmodel,\n\t\tstorageMode,\n\t\tcompanionStorePath: resolvePath(companionStorePath),\n\t\tinlineTextMaxBytes,\n\t\tmetadataIndexedFields: normalizeMetadataIndexedFields(parsed.vectorize?.metadataIndexedFields),\n\t\tcreateIndex: {\n\t\t\tdescription: parsed.vectorize?.createIndex?.description ?? DEFAULT_INDEX_DESCRIPTION,\n\t\t\tdimensions: parsed.vectorize?.createIndex?.dimensions,\n\t\t\tmetric,\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;AA4BA,IAAM,IAAkB,EACtB,OAAO;CACP,QAAQ,EAAE,KAAK;EAAC;EAAO;EAAQ;EAAO,CAAC;CACvC,UAAU,EAAE,QAAQ,CAAC,IAAI,EAAE;CAC3B,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE;CACrB,CAAC,CACD,QAAQ,EAEJ,IAA4C,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAgB,CAAC,EAEzF,IAAoB,EACxB,OAAO;CACP,aAAa,EAAE,QAAQ,CAAC,IAAI,EAAE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AAA;EACN;EACA;EACA;EACA;EACA,oBAAoB,EAAY,EAAmB;EACnD;EACA,uBAAuB,EAA+B,EAAO,WAAW,sBAAsB;EAC9F,aAAa;GACZ,aAAa,EAAO,WAAW,aAAa,eAAA;GAC5C,YAAY,EAAO,WAAW,aAAa;GAC3C;GACA;EACD"}
@@ -0,0 +1,15 @@
1
+ //#region src/constants.ts
2
+ var e = "memory-cloudflare-vectorize", t = "Cloudflare Vectorize Memory", n = "OpenClaw memory plugin backed by Cloudflare Vectorize and Workers AI embeddings.", r = "CLOUDFLARE_ACCOUNT_ID", i = "CLOUDFLARE_API_TOKEN", a = "CLOUDFLARE_VECTORIZE_INDEX_NAME", o = "CLOUDFLARE_VECTORIZE_NAMESPACE", s = "CLOUDFLARE_WORKERS_AI_EMBEDDING_MODEL", c = "CLOUDFLARE_VECTORIZE_TOP_K", l = "OPENCLAW_CF_MEMORY_STORAGE_MODE", u = "OPENCLAW_CF_MEMORY_COMPANION_PATH", d = "@cf/baai/bge-base-en-v1.5", f = 6e3, p = "cosine", m = "vectorize-inline", h = "https://api.cloudflare.com/client/v4", g = "OpenClaw memory index backed by Cloudflare Vectorize.", _ = {
3
+ logicalId: "oc_record_id",
4
+ title: "oc_title",
5
+ text: "oc_text",
6
+ storageMode: "oc_storage_mode",
7
+ pointer: "oc_pointer",
8
+ source: "oc_source",
9
+ createdAt: "oc_created_at",
10
+ updatedAt: "oc_updated_at"
11
+ };
12
+ //#endregion
13
+ export { r as CLOUDFLARE_ACCOUNT_ID_ENV, i as CLOUDFLARE_API_TOKEN_ENV, u as COMPANION_PATH_ENV, h as DEFAULT_CLOUDFLARE_API_BASE_URL, d as DEFAULT_EMBEDDING_MODEL, g as DEFAULT_INDEX_DESCRIPTION, f as DEFAULT_INLINE_TEXT_MAX_BYTES, m as DEFAULT_STORAGE_MODE, p as DEFAULT_VECTORIZE_METRIC, n as PLUGIN_DESCRIPTION, e as PLUGIN_ID, t as PLUGIN_NAME, _ as RESERVED_METADATA_KEYS, l as STORAGE_MODE_ENV, a as VECTORIZE_INDEX_ENV, o as VECTORIZE_NAMESPACE_ENV, c as VECTORIZE_TOP_K_ENV, s as WORKERS_AI_MODEL_ENV };
14
+
15
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type { StorageMode, VectorizeMetric } from \"./types.js\";\n\nexport const PLUGIN_ID = \"memory-cloudflare-vectorize\";\nexport const PLUGIN_NAME = \"Cloudflare Vectorize Memory\";\nexport const PLUGIN_DESCRIPTION = \"OpenClaw memory plugin backed by Cloudflare Vectorize and Workers AI embeddings.\";\n\nexport const CLOUDFLARE_ACCOUNT_ID_ENV = \"CLOUDFLARE_ACCOUNT_ID\";\nexport const CLOUDFLARE_API_TOKEN_ENV = \"CLOUDFLARE_API_TOKEN\";\nexport const VECTORIZE_INDEX_ENV = \"CLOUDFLARE_VECTORIZE_INDEX_NAME\";\nexport const VECTORIZE_NAMESPACE_ENV = \"CLOUDFLARE_VECTORIZE_NAMESPACE\";\nexport const WORKERS_AI_MODEL_ENV = \"CLOUDFLARE_WORKERS_AI_EMBEDDING_MODEL\";\nexport const VECTORIZE_TOP_K_ENV = \"CLOUDFLARE_VECTORIZE_TOP_K\";\nexport const STORAGE_MODE_ENV = \"OPENCLAW_CF_MEMORY_STORAGE_MODE\";\nexport const COMPANION_PATH_ENV = \"OPENCLAW_CF_MEMORY_COMPANION_PATH\";\n\nexport const DEFAULT_EMBEDDING_MODEL = \"@cf/baai/bge-base-en-v1.5\";\nexport const DEFAULT_TOP_K = 5;\nexport const DEFAULT_MIN_SCORE = 0;\nexport const DEFAULT_INLINE_TEXT_MAX_BYTES = 6_000;\nexport const DEFAULT_VECTORIZE_METRIC: VectorizeMetric = \"cosine\";\nexport const DEFAULT_STORAGE_MODE: StorageMode = \"vectorize-inline\";\nexport const DEFAULT_CLOUDFLARE_API_BASE_URL = \"https://api.cloudflare.com/client/v4\";\nexport const DEFAULT_INDEX_DESCRIPTION = \"OpenClaw memory index backed by Cloudflare Vectorize.\";\n\nexport const RESERVED_METADATA_PREFIX = \"oc_\";\nexport const RESERVED_METADATA_KEYS = {\n\tlogicalId: \"oc_record_id\",\n\ttitle: \"oc_title\",\n\ttext: \"oc_text\",\n\tstorageMode: \"oc_storage_mode\",\n\tpointer: \"oc_pointer\",\n\tsource: \"oc_source\",\n\tcreatedAt: \"oc_created_at\",\n\tupdatedAt: \"oc_updated_at\",\n} as const;\n"],"mappings":";AAEA,IAAa,IAAY,+BACZ,IAAc,+BACd,IAAqB,oFAErB,IAA4B,yBAC5B,IAA2B,wBAC3B,IAAsB,mCACtB,IAA0B,kCAC1B,IAAuB,yCACvB,IAAsB,8BACtB,IAAmB,mCACnB,IAAqB,qCAErB,IAA0B,6BAG1B,IAAgC,KAChC,IAA4C,UAC5C,IAAoC,oBACpC,IAAkC,wCAClC,IAA4B,yDAG5B,IAAyB;CACrC,WAAW;CACX,OAAO;CACP,MAAM;CACN,aAAa;CACb,SAAS;CACT,QAAQ;CACR,WAAW;CACX,WAAW;CACX"}