openclaw-cloudflare-vectorize-memory 0.1.5 → 0.1.7
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.
- package/cli-metadata.ts +2 -2
- package/dist/cli.js +71 -70
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +6 -2
- package/dist/constants.js.map +1 -1
- package/dist/index.js +34 -34
- package/dist/index.js.map +1 -1
- package/dist/types/constants.d.ts +6 -0
- package/package.json +1 -1
package/cli-metadata.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
2
|
-
import {
|
|
2
|
+
import { CLI_ROOT_DESCRIPTOR } from "./src/constants.js";
|
|
3
3
|
|
|
4
4
|
export default definePluginEntry({
|
|
5
5
|
id: "memory-cloudflare-vectorize",
|
|
@@ -17,7 +17,7 @@ export default definePluginEntry({
|
|
|
17
17
|
});
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
|
-
|
|
20
|
+
descriptors: [CLI_ROOT_DESCRIPTOR],
|
|
21
21
|
},
|
|
22
22
|
);
|
|
23
23
|
},
|
package/dist/cli.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CLI_ROOT_COMMAND as e, CLI_ROOT_DESCRIPTION as t } from "./constants.js";
|
|
2
|
+
import { formatMigrationSummary as n, runCloudflareMemoryMigration as r } from "./migration.js";
|
|
3
|
+
import { createCloudflareMemoryService as i } from "./service-factory.js";
|
|
3
4
|
//#region src/cli.ts
|
|
4
|
-
function
|
|
5
|
+
function a(e) {
|
|
5
6
|
console.log(JSON.stringify(e, null, 2));
|
|
6
7
|
}
|
|
7
|
-
function
|
|
8
|
+
function o(e) {
|
|
8
9
|
for (let t of e.checks) console.log(`[${t.status}] ${t.name}: ${t.message}`);
|
|
9
10
|
}
|
|
10
|
-
function
|
|
11
|
+
function s(e) {
|
|
11
12
|
if (!e) return;
|
|
12
13
|
let t = JSON.parse(e);
|
|
13
14
|
if (!t || typeof t != "object" || Array.isArray(t)) throw Error("--metadata must be a JSON object.");
|
|
14
15
|
return t;
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
+
function c(e) {
|
|
17
18
|
if (!e) return;
|
|
18
19
|
let t = JSON.parse(e);
|
|
19
20
|
if (!t || typeof t != "object" || Array.isArray(t)) throw Error("--filter must be a JSON object.");
|
|
20
21
|
return t;
|
|
21
22
|
}
|
|
22
|
-
function
|
|
23
|
+
function l(e) {
|
|
23
24
|
return !!e && typeof e == "object" && typeof e.opts == "function";
|
|
24
25
|
}
|
|
25
|
-
function
|
|
26
|
+
function u(e) {
|
|
26
27
|
let t = e.at(-1);
|
|
27
|
-
return
|
|
28
|
+
return l(t) ? {
|
|
28
29
|
positionals: e.slice(0, -1),
|
|
29
30
|
options: t.opts?.() ?? {}
|
|
30
31
|
} : {
|
|
@@ -32,105 +33,105 @@ function c(e) {
|
|
|
32
33
|
options: {}
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
|
-
function
|
|
36
|
+
function d(e) {
|
|
36
37
|
if (e !== void 0) {
|
|
37
38
|
if (e === "overwrite" || e === "skip" || e === "fail") return e;
|
|
38
39
|
throw Error("--if-exists must be overwrite, skip, or fail.");
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
|
-
function
|
|
42
|
-
let
|
|
43
|
-
function
|
|
44
|
-
return
|
|
42
|
+
function f(l, f) {
|
|
43
|
+
let p = l.command(e).description(t);
|
|
44
|
+
function m(e) {
|
|
45
|
+
return u(e).options;
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
-
let t =
|
|
48
|
-
pluginConfig:
|
|
49
|
-
openClawConfig:
|
|
47
|
+
p.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) => {
|
|
48
|
+
let t = m(e), n = await (await i({
|
|
49
|
+
pluginConfig: f.pluginConfig,
|
|
50
|
+
openClawConfig: f.openClawConfig,
|
|
50
51
|
env: process.env,
|
|
51
|
-
resolvePath:
|
|
52
|
+
resolvePath: f.resolvePath
|
|
52
53
|
})).doctor({ createIndexIfMissing: !!t.createIndex });
|
|
53
|
-
t.json ?
|
|
54
|
-
}),
|
|
55
|
-
let t =
|
|
56
|
-
pluginConfig:
|
|
57
|
-
openClawConfig:
|
|
54
|
+
t.json ? a(n) : o(n), n.ok || (process.exitCode = 1);
|
|
55
|
+
}), p.command("init").description("Initialize the Cloudflare Vectorize index for the configured embedding model.").option("--json", "Print structured JSON output.").action(async (...e) => {
|
|
56
|
+
let t = m(e), n = await (await i({
|
|
57
|
+
pluginConfig: f.pluginConfig,
|
|
58
|
+
openClawConfig: f.openClawConfig,
|
|
58
59
|
env: process.env,
|
|
59
|
-
resolvePath:
|
|
60
|
+
resolvePath: f.resolvePath
|
|
60
61
|
})).initializeIndex();
|
|
61
|
-
t.json ?
|
|
62
|
-
}),
|
|
63
|
-
let t =
|
|
64
|
-
pluginConfig:
|
|
65
|
-
openClawConfig:
|
|
62
|
+
t.json ? a(n) : o(n), n.ok || (process.exitCode = 1);
|
|
63
|
+
}), p.command("test").description("Run an end-to-end embedding and semantic-search smoke test.").option("--json", "Print structured JSON output.").action(async (...e) => {
|
|
64
|
+
let t = m(e), n = await (await i({
|
|
65
|
+
pluginConfig: f.pluginConfig,
|
|
66
|
+
openClawConfig: f.openClawConfig,
|
|
66
67
|
env: process.env,
|
|
67
|
-
resolvePath:
|
|
68
|
+
resolvePath: f.resolvePath
|
|
68
69
|
})).runSmokeTest();
|
|
69
|
-
t.json ?
|
|
70
|
-
}),
|
|
71
|
-
let
|
|
72
|
-
|
|
73
|
-
pluginConfig:
|
|
74
|
-
openClawConfig:
|
|
70
|
+
t.json ? a(n) : o(n), n.ok || (process.exitCode = 1);
|
|
71
|
+
}), p.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) => {
|
|
72
|
+
let n = t;
|
|
73
|
+
a(await (await i({
|
|
74
|
+
pluginConfig: f.pluginConfig,
|
|
75
|
+
openClawConfig: f.openClawConfig,
|
|
75
76
|
env: process.env,
|
|
76
|
-
resolvePath:
|
|
77
|
+
resolvePath: f.resolvePath
|
|
77
78
|
})).search({
|
|
78
79
|
query: String(e),
|
|
79
|
-
namespace:
|
|
80
|
-
maxResults:
|
|
81
|
-
filter:
|
|
80
|
+
namespace: n.namespace,
|
|
81
|
+
maxResults: n.limit ? Number(n.limit) : void 0,
|
|
82
|
+
filter: c(n.filter)
|
|
82
83
|
}));
|
|
83
|
-
}),
|
|
84
|
-
let
|
|
85
|
-
|
|
86
|
-
pluginConfig:
|
|
87
|
-
openClawConfig:
|
|
84
|
+
}), p.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) => {
|
|
85
|
+
let n = t;
|
|
86
|
+
a(await (await i({
|
|
87
|
+
pluginConfig: f.pluginConfig,
|
|
88
|
+
openClawConfig: f.openClawConfig,
|
|
88
89
|
env: process.env,
|
|
89
|
-
resolvePath:
|
|
90
|
+
resolvePath: f.resolvePath
|
|
90
91
|
})).upsert({ input: {
|
|
91
|
-
id:
|
|
92
|
-
title:
|
|
92
|
+
id: n.id,
|
|
93
|
+
title: n.title,
|
|
93
94
|
text: String(e),
|
|
94
|
-
namespace:
|
|
95
|
-
source:
|
|
96
|
-
metadata:
|
|
95
|
+
namespace: n.namespace,
|
|
96
|
+
source: n.source,
|
|
97
|
+
metadata: s(n.metadata)
|
|
97
98
|
} }));
|
|
98
|
-
}),
|
|
99
|
-
let
|
|
100
|
-
|
|
99
|
+
}), p.command("delete").description("Delete a memory record.").argument("<id>", "Logical memory record id.").option("--namespace <namespace>", "Optional namespace override.").action(async (e, t) => {
|
|
100
|
+
let n = t;
|
|
101
|
+
a({
|
|
101
102
|
id: e,
|
|
102
|
-
mutationId: await (await
|
|
103
|
-
pluginConfig:
|
|
104
|
-
openClawConfig:
|
|
103
|
+
mutationId: await (await i({
|
|
104
|
+
pluginConfig: f.pluginConfig,
|
|
105
|
+
openClawConfig: f.openClawConfig,
|
|
105
106
|
env: process.env,
|
|
106
|
-
resolvePath:
|
|
107
|
+
resolvePath: f.resolvePath
|
|
107
108
|
})).delete({
|
|
108
109
|
id: String(e),
|
|
109
|
-
namespace:
|
|
110
|
+
namespace: n.namespace
|
|
110
111
|
})
|
|
111
112
|
});
|
|
112
|
-
}),
|
|
113
|
-
let { positionals:
|
|
114
|
-
service: await
|
|
115
|
-
pluginConfig:
|
|
116
|
-
openClawConfig:
|
|
113
|
+
}), p.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 (...e) => {
|
|
114
|
+
let { positionals: t, options: o } = u(e), s = t[0], c = t.length === 0 ? [] : Array.isArray(s) ? s.map((e) => String(e)) : t.map((e) => String(e)), l = await r({
|
|
115
|
+
service: await i({
|
|
116
|
+
pluginConfig: f.pluginConfig,
|
|
117
|
+
openClawConfig: f.openClawConfig,
|
|
117
118
|
env: process.env,
|
|
118
|
-
resolvePath:
|
|
119
|
+
resolvePath: f.resolvePath
|
|
119
120
|
}),
|
|
120
121
|
options: {
|
|
121
|
-
sourcePaths:
|
|
122
|
+
sourcePaths: c,
|
|
122
123
|
workspaceDir: o.workspace,
|
|
123
124
|
namespace: o.namespace,
|
|
124
125
|
namespaceStrategy: o.deriveNamespaceFromPath ? "path" : "single-target",
|
|
125
|
-
duplicateStrategy:
|
|
126
|
+
duplicateStrategy: d(o.ifExists),
|
|
126
127
|
dryRun: !!o.dryRun,
|
|
127
128
|
createIndexIfMissing: !!o.createIndex
|
|
128
129
|
}
|
|
129
130
|
});
|
|
130
|
-
o.json ?
|
|
131
|
+
o.json ? a(l) : console.log(n(l)), l.failed > 0 && (process.exitCode = 1);
|
|
131
132
|
});
|
|
132
133
|
}
|
|
133
134
|
//#endregion
|
|
134
|
-
export {
|
|
135
|
+
export { f as registerCloudflareMemoryCli };
|
|
135
136
|
|
|
136
137
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import type { OpenClawConfig } from \"openclaw/plugin-sdk/config-runtime\";\nimport type { DoctorReport, IndexInitializationReport, MetadataFilter, MigrationDuplicateStrategy, SmokeTestReport } from \"./types.js\";\nimport { formatMigrationSummary, runCloudflareMemoryMigration } from \"./migration.js\";\nimport { createCloudflareMemoryService } from \"./service-factory.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 printCheckReport(report: DoctorReport | IndexInitializationReport | SmokeTestReport): void {\n\tfor (const check of report.checks) {\n\t\tconsole.log(`[${check.status}] ${check.name}: ${check.message}`);\n\t}\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\tprintCheckReport(report);\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(\"init\")\n\t\t.description(\"Initialize the Cloudflare Vectorize index for the configured embedding model.\")\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.initializeIndex();\n\t\t\tif (options.json) {\n\t\t\t\tprintJson(report);\n\t\t\t} else {\n\t\t\t\tprintCheckReport(report);\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(\"test\")\n\t\t.description(\"Run an end-to-end embedding and semantic-search smoke test.\")\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.runSmokeTest();\n\t\t\tif (options.json) {\n\t\t\t\tprintJson(report);\n\t\t\t} else {\n\t\t\t\tprintCheckReport(report);\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":";;;AAcA,SAAS,EAAU,GAAsB;AACxC,SAAQ,IAAI,KAAK,UAAU,GAAO,MAAM,EAAE,CAAC;;AAG5C,SAAS,EAAiB,GAA0E;AACnG,MAAK,IAAM,KAAS,EAAO,OAC1B,SAAQ,IAAI,IAAI,EAAM,OAAO,IAAI,EAAM,KAAK,IAAI,EAAM,UAAU;;AAIlE,SAAS,EAAkB,GAAkF;A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5I,OAAO,0BAA0B,gDAAgD,CACjF,OAAO,kBAAkB,yCAAyC,CAClE,OAAO,aAAa,8CAA8C,CAClE,OAAO,UAAU,gCAAgC,CACjD,OAAO,OAAO,GAAG,MAAS;EAC1B,IAAM,EAAE,gBAAa,eAAY,EAAkB,EAAK,EAClD,IAAa,EAAY,IACzB,IACL,EAAY,WAAW,IAAI,EAAE,GAAG,MAAM,QAAQ,EAAW,GAAG,EAAW,KAAK,MAAU,OAAO,EAAM,CAAC,GAAG,EAAY,KAAK,MAAU,OAAO,EAAM,CAAC,EAO3I,IAAU,MAAM,EAA6B;GAClD,SAPe,MAAM,EAA8B;IACnD,cAAc,EAAO;IACrB,gBAAgB,EAAO;IACvB,KAAK,QAAQ;IACb,aAAa,EAAO;IACpB,CAAC;GAGD,SAAS;IACR;IACA,cAAc,EAAQ;IACtB,WAAW,EAAQ;IACnB,mBAAmB,EAAQ,0BAA0B,SAAS;IAC9D,mBAAmB,EAAuB,EAAQ,SAAS;IAC3D,QAAQ,EAAQ,EAAQ;IACxB,sBAAsB,EAAQ,EAAQ;IACtC;GACD,CAAC;AAMF,EALI,EAAQ,OACX,EAAU,EAAQ,GAElB,QAAQ,IAAI,EAAuB,EAAQ,CAAC,EAEzC,EAAQ,SAAS,MACpB,QAAQ,WAAW;GAEnB"}
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import type { OpenClawConfig } from \"openclaw/plugin-sdk/config-runtime\";\nimport { CLI_ROOT_COMMAND, CLI_ROOT_DESCRIPTION } from \"./constants.js\";\nimport type { DoctorReport, IndexInitializationReport, MetadataFilter, MigrationDuplicateStrategy, SmokeTestReport } from \"./types.js\";\nimport { formatMigrationSummary, runCloudflareMemoryMigration } from \"./migration.js\";\nimport { createCloudflareMemoryService } from \"./service-factory.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 printCheckReport(report: DoctorReport | IndexInitializationReport | SmokeTestReport): void {\n\tfor (const check of report.checks) {\n\t\tconsole.log(`[${check.status}] ${check.name}: ${check.message}`);\n\t}\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(CLI_ROOT_COMMAND).description(CLI_ROOT_DESCRIPTION);\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\tprintCheckReport(report);\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(\"init\")\n\t\t.description(\"Initialize the Cloudflare Vectorize index for the configured embedding model.\")\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.initializeIndex();\n\t\t\tif (options.json) {\n\t\t\t\tprintJson(report);\n\t\t\t} else {\n\t\t\t\tprintCheckReport(report);\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(\"test\")\n\t\t.description(\"Run an end-to-end embedding and semantic-search smoke test.\")\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.runSmokeTest();\n\t\t\tif (options.json) {\n\t\t\t\tprintJson(report);\n\t\t\t} else {\n\t\t\t\tprintCheckReport(report);\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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
var e = "memory-cloudflare-vectorize", t = "Cloudflare Vectorize Memory", n = "OpenClaw memory plugin backed by Cloudflare Vectorize and Workers AI embeddings.", r = "cf-memory", i = "
|
|
2
|
+
var e = "memory-cloudflare-vectorize", t = "Cloudflare Vectorize Memory", n = "OpenClaw memory plugin backed by Cloudflare Vectorize and Workers AI embeddings.", r = "cf-memory", i = "Manage Cloudflare memory records.", a = {
|
|
3
|
+
name: r,
|
|
4
|
+
description: i,
|
|
5
|
+
hasSubcommands: !0
|
|
6
|
+
}, o = "CLOUDFLARE_ACCOUNT_ID", s = "CLOUDFLARE_API_TOKEN", c = "CLOUDFLARE_VECTORIZE_INDEX_NAME", l = "CLOUDFLARE_VECTORIZE_NAMESPACE", u = "CLOUDFLARE_WORKERS_AI_EMBEDDING_MODEL", d = "CLOUDFLARE_VECTORIZE_TOP_K", f = "OPENCLAW_CF_MEMORY_STORAGE_MODE", p = "OPENCLAW_CF_MEMORY_COMPANION_PATH", m = "@cf/baai/bge-base-en-v1.5", h = 6e3, g = "cosine", _ = "vectorize-inline", v = "https://api.cloudflare.com/client/v4", y = "OpenClaw memory index backed by Cloudflare Vectorize.", b = {
|
|
3
7
|
logicalId: "oc_record_id",
|
|
4
8
|
title: "oc_title",
|
|
5
9
|
text: "oc_text",
|
|
@@ -10,6 +14,6 @@ var e = "memory-cloudflare-vectorize", t = "Cloudflare Vectorize Memory", n = "O
|
|
|
10
14
|
updatedAt: "oc_updated_at"
|
|
11
15
|
};
|
|
12
16
|
//#endregion
|
|
13
|
-
export { r as CLI_ROOT_COMMAND, i as
|
|
17
|
+
export { r as CLI_ROOT_COMMAND, i as CLI_ROOT_DESCRIPTION, a as CLI_ROOT_DESCRIPTOR, o as CLOUDFLARE_ACCOUNT_ID_ENV, s as CLOUDFLARE_API_TOKEN_ENV, p as COMPANION_PATH_ENV, v as DEFAULT_CLOUDFLARE_API_BASE_URL, m as DEFAULT_EMBEDDING_MODEL, y as DEFAULT_INDEX_DESCRIPTION, h as DEFAULT_INLINE_TEXT_MAX_BYTES, _ as DEFAULT_STORAGE_MODE, g as DEFAULT_VECTORIZE_METRIC, n as PLUGIN_DESCRIPTION, e as PLUGIN_ID, t as PLUGIN_NAME, b as RESERVED_METADATA_KEYS, f as STORAGE_MODE_ENV, c as VECTORIZE_INDEX_ENV, l as VECTORIZE_NAMESPACE_ENV, d as VECTORIZE_TOP_K_ENV, u as WORKERS_AI_MODEL_ENV };
|
|
14
18
|
|
|
15
19
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +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.\";\nexport const CLI_ROOT_COMMAND = \"cf-memory\";\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,oFACrB,IAAmB,
|
|
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.\";\nexport const CLI_ROOT_COMMAND = \"cf-memory\";\nexport const CLI_ROOT_DESCRIPTION = \"Manage Cloudflare memory records.\";\nexport const CLI_ROOT_DESCRIPTOR = {\n\tname: CLI_ROOT_COMMAND,\n\tdescription: CLI_ROOT_DESCRIPTION,\n\thasSubcommands: true,\n} as const;\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,oFACrB,IAAmB,aACnB,IAAuB,qCACvB,IAAsB;CAClC,MAAM;CACN,aAAa;CACb,gBAAgB;CAChB,EAEY,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"}
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { CLI_ROOT_COMMAND as e,
|
|
2
|
-
import { getPluginConfigFromOpenClawConfig as
|
|
3
|
-
import { CloudflareMemoryService as
|
|
4
|
-
import { registerCloudflareMemoryCli as
|
|
5
|
-
import { buildPromptSection as
|
|
6
|
-
import { createPublicArtifactsProvider as
|
|
7
|
-
import { createMemoryRuntime as
|
|
8
|
-
import { createDeleteTool as
|
|
9
|
-
import { definePluginEntry as
|
|
1
|
+
import { CLI_ROOT_COMMAND as e, CLI_ROOT_DESCRIPTOR as t, DEFAULT_EMBEDDING_MODEL as n, PLUGIN_DESCRIPTION as r, PLUGIN_ID as i, PLUGIN_NAME as a } from "./constants.js";
|
|
2
|
+
import { getPluginConfigFromOpenClawConfig as o, pluginConfigSchema as s, resolvePluginConfig as c } from "./config.js";
|
|
3
|
+
import { CloudflareMemoryService as l } from "./service.js";
|
|
4
|
+
import { registerCloudflareMemoryCli as u } from "./cli.js";
|
|
5
|
+
import { buildPromptSection as d } from "./prompt.js";
|
|
6
|
+
import { createPublicArtifactsProvider as f } from "./public-artifacts.js";
|
|
7
|
+
import { createMemoryRuntime as p } from "./runtime.js";
|
|
8
|
+
import { createDeleteTool as m, createGetTool as h, createSearchTool as g, createUpsertTool as _ } from "./tools.js";
|
|
9
|
+
import { definePluginEntry as v } from "openclaw/plugin-sdk/plugin-entry";
|
|
10
10
|
//#region src/index.ts
|
|
11
|
-
function
|
|
11
|
+
function y() {
|
|
12
12
|
return {
|
|
13
13
|
id: "cloudflare-workers-ai",
|
|
14
|
-
defaultModel:
|
|
14
|
+
defaultModel: n,
|
|
15
15
|
transport: "remote",
|
|
16
16
|
allowExplicitWhenConfiguredAuto: !0,
|
|
17
17
|
async create(e) {
|
|
18
|
-
let t = await
|
|
19
|
-
pluginConfig:
|
|
18
|
+
let t = await c({
|
|
19
|
+
pluginConfig: o(e.config),
|
|
20
20
|
openClawConfig: e.config,
|
|
21
21
|
env: process.env
|
|
22
|
-
}), n = new
|
|
22
|
+
}), n = new l({
|
|
23
23
|
...t,
|
|
24
24
|
model: e.model || t.model,
|
|
25
25
|
workersAiBaseUrl: e.remote?.baseUrl && e.remote.baseUrl.trim().length > 0 ? e.remote.baseUrl : t.workersAiBaseUrl,
|
|
@@ -43,43 +43,43 @@ function v() {
|
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
pluginConfig:
|
|
50
|
-
openClawConfig:
|
|
51
|
-
resolvePath:
|
|
46
|
+
function b(n) {
|
|
47
|
+
n.registerCli(({ program: e }) => {
|
|
48
|
+
u(e, {
|
|
49
|
+
pluginConfig: n.pluginConfig,
|
|
50
|
+
openClawConfig: n.config,
|
|
51
|
+
resolvePath: n.resolvePath
|
|
52
52
|
});
|
|
53
|
-
}, { commands: [e] });
|
|
53
|
+
}, n.registrationMode === "cli-metadata" ? { descriptors: [t] } : { commands: [e] });
|
|
54
54
|
}
|
|
55
|
-
var
|
|
56
|
-
id:
|
|
57
|
-
name:
|
|
58
|
-
description:
|
|
55
|
+
var x = v({
|
|
56
|
+
id: i,
|
|
57
|
+
name: a,
|
|
58
|
+
description: r,
|
|
59
59
|
kind: "memory",
|
|
60
|
-
configSchema:
|
|
60
|
+
configSchema: s,
|
|
61
61
|
register(e) {
|
|
62
|
-
|
|
63
|
-
promptBuilder:
|
|
64
|
-
runtime:
|
|
62
|
+
s.parse?.(e.pluginConfig ?? {}), b(e), !(e.registrationMode === "cli-metadata" || typeof e.registerMemoryEmbeddingProvider != "function" || typeof e.registerMemoryCapability != "function" || typeof e.registerTool != "function") && (e.registerMemoryEmbeddingProvider(y()), e.registerMemoryCapability({
|
|
63
|
+
promptBuilder: d,
|
|
64
|
+
runtime: p({
|
|
65
65
|
pluginConfig: e.pluginConfig,
|
|
66
66
|
resolvePath: e.resolvePath
|
|
67
67
|
}),
|
|
68
|
-
publicArtifacts:
|
|
69
|
-
}), e.registerTool((t) =>
|
|
68
|
+
publicArtifacts: f(e.pluginConfig, e.resolvePath)
|
|
69
|
+
}), e.registerTool((t) => g(e.pluginConfig, t), { names: ["cloudflare_memory_search"] }), e.registerTool((t) => h(e.pluginConfig, t), { names: ["cloudflare_memory_get"] }), e.registerTool((t) => _(e.pluginConfig, t), { names: ["cloudflare_memory_upsert"] }), e.registerTool((t) => m(e.pluginConfig, t), { names: ["cloudflare_memory_delete"] }), c({
|
|
70
70
|
pluginConfig: e.pluginConfig,
|
|
71
71
|
openClawConfig: e.config,
|
|
72
72
|
env: process.env,
|
|
73
73
|
resolvePath: e.resolvePath
|
|
74
74
|
}).then((t) => {
|
|
75
|
-
e.logger.info(`${
|
|
75
|
+
e.logger.info(`${i}: registered for index ${t.indexName} using model ${t.model}.`);
|
|
76
76
|
}).catch((t) => {
|
|
77
77
|
let n = t instanceof Error ? t.message : "Unknown configuration error.";
|
|
78
|
-
e.logger.warn(`${
|
|
78
|
+
e.logger.warn(`${i}: deferred config validation reported: ${n}`);
|
|
79
79
|
}));
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
82
|
//#endregion
|
|
83
|
-
export {
|
|
83
|
+
export { x as default };
|
|
84
84
|
|
|
85
85
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { MemoryEmbeddingProviderAdapter } from \"openclaw/plugin-sdk/memory-core-host-engine-embeddings\";\nimport { definePluginEntry, type OpenClawPluginApi } from \"openclaw/plugin-sdk/plugin-entry\";\nimport { registerCloudflareMemoryCli } from \"./cli.js\";\nimport { getPluginConfigFromOpenClawConfig, pluginConfigSchema, resolvePluginConfig } from \"./config.js\";\nimport { CLI_ROOT_COMMAND, DEFAULT_EMBEDDING_MODEL, PLUGIN_DESCRIPTION, PLUGIN_ID, PLUGIN_NAME } from \"./constants.js\";\nimport { buildPromptSection } from \"./prompt.js\";\nimport { createPublicArtifactsProvider } from \"./public-artifacts.js\";\nimport { createMemoryRuntime } from \"./runtime.js\";\nimport { CloudflareMemoryService } from \"./service.js\";\nimport { createDeleteTool, createGetTool, createSearchTool, createUpsertTool } from \"./tools.js\";\n\nfunction createMemoryEmbeddingProviderAdapter(): MemoryEmbeddingProviderAdapter {\n\treturn {\n\t\tid: \"cloudflare-workers-ai\",\n\t\tdefaultModel: DEFAULT_EMBEDDING_MODEL,\n\t\ttransport: \"remote\",\n\t\tallowExplicitWhenConfiguredAuto: true,\n\t\tasync create(options) {\n\t\t\tconst pluginConfig = getPluginConfigFromOpenClawConfig(options.config);\n\t\t\tconst resolved = await resolvePluginConfig({\n\t\t\t\tpluginConfig,\n\t\t\t\topenClawConfig: options.config,\n\t\t\t\tenv: process.env,\n\t\t\t});\n\t\t\tconst service = new CloudflareMemoryService(\n\t\t\t\t{\n\t\t\t\t\t...resolved,\n\t\t\t\t\tmodel: options.model || resolved.model,\n\t\t\t\t\tworkersAiBaseUrl: options.remote?.baseUrl && options.remote.baseUrl.trim().length > 0 ? options.remote.baseUrl : resolved.workersAiBaseUrl,\n\t\t\t\t\tapiToken: typeof options.remote?.apiKey === \"string\" && options.remote.apiKey.trim().length > 0 ? options.remote.apiKey : resolved.apiToken,\n\t\t\t\t},\n\t\t\t\toptions.config,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tprovider: {\n\t\t\t\t\tid: \"cloudflare-workers-ai\",\n\t\t\t\t\tmodel: options.model || resolved.model,\n\t\t\t\t\tembedQuery: (text) => service.embeddings.embedQuery(text),\n\t\t\t\t\tembedBatch: (texts) => service.embeddings.embedBatch(texts),\n\t\t\t\t},\n\t\t\t\truntime: {\n\t\t\t\t\tid: \"cloudflare-workers-ai\",\n\t\t\t\t\tcacheKeyData: {\n\t\t\t\t\t\taccountId: resolved.accountId,\n\t\t\t\t\t\tmodel: options.model || resolved.model,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n\nfunction registerCloudflareMemoryCliEntry(api: Pick<OpenClawPluginApi, \"registerCli\" | \"pluginConfig\" | \"config\" | \"resolvePath\">): void {\n\tapi.registerCli(\n\t\t({ program }) => {\n\t\t\tregisterCloudflareMemoryCli(program, {\n\t\t\t\tpluginConfig: api.pluginConfig,\n\t\t\t\topenClawConfig: api.config,\n\t\t\t\tresolvePath: api.resolvePath,\n\t\t\t});\n\t\t},\n\t\t{\n\t\t\tcommands: [CLI_ROOT_COMMAND],\n\t\t},\n\t);\n}\n\nexport default definePluginEntry({\n\tid: PLUGIN_ID,\n\tname: PLUGIN_NAME,\n\tdescription: PLUGIN_DESCRIPTION,\n\tkind: \"memory\",\n\tconfigSchema: pluginConfigSchema,\n\tregister(api: OpenClawPluginApi) {\n\t\tpluginConfigSchema.parse?.(api.pluginConfig ?? {});\n\n\t\tregisterCloudflareMemoryCliEntry(api);\n\n\t\tif (\n\t\t\tapi.registrationMode === \"cli-metadata\" ||\n\t\t\ttypeof api.registerMemoryEmbeddingProvider !== \"function\" ||\n\t\t\ttypeof api.registerMemoryCapability !== \"function\" ||\n\t\t\ttypeof api.registerTool !== \"function\"\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tapi.registerMemoryEmbeddingProvider(createMemoryEmbeddingProviderAdapter());\n\t\tapi.registerMemoryCapability({\n\t\t\tpromptBuilder: buildPromptSection,\n\t\t\truntime: createMemoryRuntime({\n\t\t\t\tpluginConfig: api.pluginConfig,\n\t\t\t\tresolvePath: api.resolvePath,\n\t\t\t}),\n\t\t\tpublicArtifacts: createPublicArtifactsProvider(api.pluginConfig, api.resolvePath),\n\t\t});\n\n\t\tapi.registerTool((ctx) => createSearchTool(api.pluginConfig, ctx), {\n\t\t\tnames: [\"cloudflare_memory_search\"],\n\t\t});\n\t\tapi.registerTool((ctx) => createGetTool(api.pluginConfig, ctx), {\n\t\t\tnames: [\"cloudflare_memory_get\"],\n\t\t});\n\t\tapi.registerTool((ctx) => createUpsertTool(api.pluginConfig, ctx), {\n\t\t\tnames: [\"cloudflare_memory_upsert\"],\n\t\t});\n\t\tapi.registerTool((ctx) => createDeleteTool(api.pluginConfig, ctx), {\n\t\t\tnames: [\"cloudflare_memory_delete\"],\n\t\t});\n\n\t\tvoid resolvePluginConfig({\n\t\t\tpluginConfig: api.pluginConfig,\n\t\t\topenClawConfig: api.config,\n\t\t\tenv: process.env,\n\t\t\tresolvePath: api.resolvePath,\n\t\t})\n\t\t\t.then((resolved) => {\n\t\t\t\tapi.logger.info(`${PLUGIN_ID}: registered for index ${resolved.indexName} using model ${resolved.model}.`);\n\t\t\t})\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tconst message = error instanceof Error ? error.message : \"Unknown configuration error.\";\n\t\t\t\tapi.logger.warn(`${PLUGIN_ID}: deferred config validation reported: ${message}`);\n\t\t\t});\n\t},\n});\n"],"mappings":";;;;;;;;;;AAWA,SAAS,IAAuE;AAC/E,QAAO;EACN,IAAI;EACJ,cAAc;EACd,WAAW;EACX,iCAAiC;EACjC,MAAM,OAAO,GAAS;GAErB,IAAM,IAAW,MAAM,EAAoB;IAC1C,cAFoB,EAAkC,EAAQ,OAAO;IAGrE,gBAAgB,EAAQ;IACxB,KAAK,QAAQ;IACb,CAAC,EACI,IAAU,IAAI,EACnB;IACC,GAAG;IACH,OAAO,EAAQ,SAAS,EAAS;IACjC,kBAAkB,EAAQ,QAAQ,WAAW,EAAQ,OAAO,QAAQ,MAAM,CAAC,SAAS,IAAI,EAAQ,OAAO,UAAU,EAAS;IAC1H,UAAU,OAAO,EAAQ,QAAQ,UAAW,YAAY,EAAQ,OAAO,OAAO,MAAM,CAAC,SAAS,IAAI,EAAQ,OAAO,SAAS,EAAS;IACnI,EACD,EAAQ,OACR;AACD,UAAO;IACN,UAAU;KACT,IAAI;KACJ,OAAO,EAAQ,SAAS,EAAS;KACjC,aAAa,MAAS,EAAQ,WAAW,WAAW,EAAK;KACzD,aAAa,MAAU,EAAQ,WAAW,WAAW,EAAM;KAC3D;IACD,SAAS;KACR,IAAI;KACJ,cAAc;MACb,WAAW,EAAS;MACpB,OAAO,EAAQ,SAAS,EAAS;MACjC;KACD;IACD;;EAEF;;AAGF,SAAS,EAAiC,
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { MemoryEmbeddingProviderAdapter } from \"openclaw/plugin-sdk/memory-core-host-engine-embeddings\";\nimport { definePluginEntry, type OpenClawPluginApi } from \"openclaw/plugin-sdk/plugin-entry\";\nimport { registerCloudflareMemoryCli } from \"./cli.js\";\nimport { getPluginConfigFromOpenClawConfig, pluginConfigSchema, resolvePluginConfig } from \"./config.js\";\nimport { CLI_ROOT_COMMAND, CLI_ROOT_DESCRIPTOR, DEFAULT_EMBEDDING_MODEL, PLUGIN_DESCRIPTION, PLUGIN_ID, PLUGIN_NAME } from \"./constants.js\";\nimport { buildPromptSection } from \"./prompt.js\";\nimport { createPublicArtifactsProvider } from \"./public-artifacts.js\";\nimport { createMemoryRuntime } from \"./runtime.js\";\nimport { CloudflareMemoryService } from \"./service.js\";\nimport { createDeleteTool, createGetTool, createSearchTool, createUpsertTool } from \"./tools.js\";\n\nfunction createMemoryEmbeddingProviderAdapter(): MemoryEmbeddingProviderAdapter {\n\treturn {\n\t\tid: \"cloudflare-workers-ai\",\n\t\tdefaultModel: DEFAULT_EMBEDDING_MODEL,\n\t\ttransport: \"remote\",\n\t\tallowExplicitWhenConfiguredAuto: true,\n\t\tasync create(options) {\n\t\t\tconst pluginConfig = getPluginConfigFromOpenClawConfig(options.config);\n\t\t\tconst resolved = await resolvePluginConfig({\n\t\t\t\tpluginConfig,\n\t\t\t\topenClawConfig: options.config,\n\t\t\t\tenv: process.env,\n\t\t\t});\n\t\t\tconst service = new CloudflareMemoryService(\n\t\t\t\t{\n\t\t\t\t\t...resolved,\n\t\t\t\t\tmodel: options.model || resolved.model,\n\t\t\t\t\tworkersAiBaseUrl: options.remote?.baseUrl && options.remote.baseUrl.trim().length > 0 ? options.remote.baseUrl : resolved.workersAiBaseUrl,\n\t\t\t\t\tapiToken: typeof options.remote?.apiKey === \"string\" && options.remote.apiKey.trim().length > 0 ? options.remote.apiKey : resolved.apiToken,\n\t\t\t\t},\n\t\t\t\toptions.config,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tprovider: {\n\t\t\t\t\tid: \"cloudflare-workers-ai\",\n\t\t\t\t\tmodel: options.model || resolved.model,\n\t\t\t\t\tembedQuery: (text) => service.embeddings.embedQuery(text),\n\t\t\t\t\tembedBatch: (texts) => service.embeddings.embedBatch(texts),\n\t\t\t\t},\n\t\t\t\truntime: {\n\t\t\t\t\tid: \"cloudflare-workers-ai\",\n\t\t\t\t\tcacheKeyData: {\n\t\t\t\t\t\taccountId: resolved.accountId,\n\t\t\t\t\t\tmodel: options.model || resolved.model,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n\nfunction registerCloudflareMemoryCliEntry(api: Pick<OpenClawPluginApi, \"registerCli\" | \"pluginConfig\" | \"config\" | \"resolvePath\" | \"registrationMode\">): void {\n\tapi.registerCli(\n\t\t({ program }) => {\n\t\t\tregisterCloudflareMemoryCli(program, {\n\t\t\t\tpluginConfig: api.pluginConfig,\n\t\t\t\topenClawConfig: api.config,\n\t\t\t\tresolvePath: api.resolvePath,\n\t\t\t});\n\t\t},\n\t\tapi.registrationMode === \"cli-metadata\"\n\t\t\t? {\n\t\t\t\t\tdescriptors: [CLI_ROOT_DESCRIPTOR],\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tcommands: [CLI_ROOT_COMMAND],\n\t\t\t\t},\n\t);\n}\n\nexport default definePluginEntry({\n\tid: PLUGIN_ID,\n\tname: PLUGIN_NAME,\n\tdescription: PLUGIN_DESCRIPTION,\n\tkind: \"memory\",\n\tconfigSchema: pluginConfigSchema,\n\tregister(api: OpenClawPluginApi) {\n\t\tpluginConfigSchema.parse?.(api.pluginConfig ?? {});\n\n\t\tregisterCloudflareMemoryCliEntry(api);\n\n\t\tif (\n\t\t\tapi.registrationMode === \"cli-metadata\" ||\n\t\t\ttypeof api.registerMemoryEmbeddingProvider !== \"function\" ||\n\t\t\ttypeof api.registerMemoryCapability !== \"function\" ||\n\t\t\ttypeof api.registerTool !== \"function\"\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tapi.registerMemoryEmbeddingProvider(createMemoryEmbeddingProviderAdapter());\n\t\tapi.registerMemoryCapability({\n\t\t\tpromptBuilder: buildPromptSection,\n\t\t\truntime: createMemoryRuntime({\n\t\t\t\tpluginConfig: api.pluginConfig,\n\t\t\t\tresolvePath: api.resolvePath,\n\t\t\t}),\n\t\t\tpublicArtifacts: createPublicArtifactsProvider(api.pluginConfig, api.resolvePath),\n\t\t});\n\n\t\tapi.registerTool((ctx) => createSearchTool(api.pluginConfig, ctx), {\n\t\t\tnames: [\"cloudflare_memory_search\"],\n\t\t});\n\t\tapi.registerTool((ctx) => createGetTool(api.pluginConfig, ctx), {\n\t\t\tnames: [\"cloudflare_memory_get\"],\n\t\t});\n\t\tapi.registerTool((ctx) => createUpsertTool(api.pluginConfig, ctx), {\n\t\t\tnames: [\"cloudflare_memory_upsert\"],\n\t\t});\n\t\tapi.registerTool((ctx) => createDeleteTool(api.pluginConfig, ctx), {\n\t\t\tnames: [\"cloudflare_memory_delete\"],\n\t\t});\n\n\t\tvoid resolvePluginConfig({\n\t\t\tpluginConfig: api.pluginConfig,\n\t\t\topenClawConfig: api.config,\n\t\t\tenv: process.env,\n\t\t\tresolvePath: api.resolvePath,\n\t\t})\n\t\t\t.then((resolved) => {\n\t\t\t\tapi.logger.info(`${PLUGIN_ID}: registered for index ${resolved.indexName} using model ${resolved.model}.`);\n\t\t\t})\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tconst message = error instanceof Error ? error.message : \"Unknown configuration error.\";\n\t\t\t\tapi.logger.warn(`${PLUGIN_ID}: deferred config validation reported: ${message}`);\n\t\t\t});\n\t},\n});\n"],"mappings":";;;;;;;;;;AAWA,SAAS,IAAuE;AAC/E,QAAO;EACN,IAAI;EACJ,cAAc;EACd,WAAW;EACX,iCAAiC;EACjC,MAAM,OAAO,GAAS;GAErB,IAAM,IAAW,MAAM,EAAoB;IAC1C,cAFoB,EAAkC,EAAQ,OAAO;IAGrE,gBAAgB,EAAQ;IACxB,KAAK,QAAQ;IACb,CAAC,EACI,IAAU,IAAI,EACnB;IACC,GAAG;IACH,OAAO,EAAQ,SAAS,EAAS;IACjC,kBAAkB,EAAQ,QAAQ,WAAW,EAAQ,OAAO,QAAQ,MAAM,CAAC,SAAS,IAAI,EAAQ,OAAO,UAAU,EAAS;IAC1H,UAAU,OAAO,EAAQ,QAAQ,UAAW,YAAY,EAAQ,OAAO,OAAO,MAAM,CAAC,SAAS,IAAI,EAAQ,OAAO,SAAS,EAAS;IACnI,EACD,EAAQ,OACR;AACD,UAAO;IACN,UAAU;KACT,IAAI;KACJ,OAAO,EAAQ,SAAS,EAAS;KACjC,aAAa,MAAS,EAAQ,WAAW,WAAW,EAAK;KACzD,aAAa,MAAU,EAAQ,WAAW,WAAW,EAAM;KAC3D;IACD,SAAS;KACR,IAAI;KACJ,cAAc;MACb,WAAW,EAAS;MACpB,OAAO,EAAQ,SAAS,EAAS;MACjC;KACD;IACD;;EAEF;;AAGF,SAAS,EAAiC,GAAoH;AAC7J,GAAI,aACF,EAAE,iBAAc;AAChB,IAA4B,GAAS;GACpC,cAAc,EAAI;GAClB,gBAAgB,EAAI;GACpB,aAAa,EAAI;GACjB,CAAC;IAEH,EAAI,qBAAqB,iBACtB,EACA,aAAa,CAAC,EAAoB,EAClC,GACA,EACA,UAAU,CAAC,EAAiB,EAC5B,CACH;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udflare-vectorize";
|
|
|
3
3
|
export declare const PLUGIN_NAME = "Cloudflare Vectorize Memory";
|
|
4
4
|
export declare const PLUGIN_DESCRIPTION = "OpenClaw memory plugin backed by Cloudflare Vectorize and Workers AI embeddings.";
|
|
5
5
|
export declare const CLI_ROOT_COMMAND = "cf-memory";
|
|
6
|
+
export declare const CLI_ROOT_DESCRIPTION = "Manage Cloudflare memory records.";
|
|
7
|
+
export declare const CLI_ROOT_DESCRIPTOR: {
|
|
8
|
+
readonly name: "cf-memory";
|
|
9
|
+
readonly description: "Manage Cloudflare memory records.";
|
|
10
|
+
readonly hasSubcommands: true;
|
|
11
|
+
};
|
|
6
12
|
export declare const CLOUDFLARE_ACCOUNT_ID_ENV = "CLOUDFLARE_ACCOUNT_ID";
|
|
7
13
|
export declare const CLOUDFLARE_API_TOKEN_ENV = "CLOUDFLARE_API_TOKEN";
|
|
8
14
|
export declare const VECTORIZE_INDEX_ENV = "CLOUDFLARE_VECTORIZE_INDEX_NAME";
|
package/package.json
CHANGED