openclaw-cloudflare-vectorize-memory 0.1.8 → 0.1.10

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.
@@ -1 +1 @@
1
- {"version":3,"file":"cloudflare-api.js","names":[],"sources":["../src/cloudflare-api.ts"],"sourcesContent":["import { CloudflareApiError } from \"./errors.js\";\r\n\r\ntype CloudflareResponseEnvelope<T> = {\r\n\tsuccess: boolean;\r\n\tresult: T;\r\n\terrors?: Array<{ code?: number; message?: string }>;\r\n};\r\n\r\ntype ResponseMode = \"auto\" | \"envelope\";\r\n\r\nfunction describeFailure(envelope: Partial<CloudflareResponseEnvelope<unknown>> | undefined, fallback: string): string {\r\n\tconst message = envelope?.errors\r\n\t\t?.map((entry) => entry.message)\r\n\t\t.filter(Boolean)\r\n\t\t.join(\"; \");\r\n\treturn message || fallback;\r\n}\r\n\r\nfunction isResponseEnvelope<T>(value: unknown): value is Partial<CloudflareResponseEnvelope<T>> & { success: boolean } {\r\n\treturn value !== null && typeof value === \"object\" && \"success\" in value;\r\n}\r\n\r\nfunction parseResponseBody(rawText: string): unknown {\r\n\tif (!rawText) {\r\n\t\treturn undefined;\r\n\t}\r\n\treturn JSON.parse(rawText) as unknown;\r\n}\r\n\r\nexport function isCloudflareNotFoundError(error: unknown): boolean {\r\n\treturn error instanceof CloudflareApiError && error.status === 404;\r\n}\r\n\r\nexport async function requestCloudflare<T>(params: {\r\n\turl: string;\r\n\tapiToken: string;\r\n\tmethod?: string;\r\n\theaders?: Record<string, string>;\r\n\tbody?: string;\r\n\tresponseMode?: ResponseMode;\r\n}): Promise<T> {\r\n\tconst headers = new Headers(params.headers);\r\n\theaders.set(\"Authorization\", `Bearer ${params.apiToken}`);\r\n\tif (!headers.has(\"Content-Type\") && params.body) {\r\n\t\theaders.set(\"Content-Type\", \"application/json\");\r\n\t}\r\n\r\n\tconst response = await fetch(params.url, {\r\n\t\tmethod: params.method ?? (params.body ? \"POST\" : \"GET\"),\r\n\t\theaders,\r\n\t\tbody: params.body,\r\n\t});\r\n\r\n\tconst rawText = await response.text();\r\n\tconst parsed = parseResponseBody(rawText);\r\n\tif (!response.ok) {\r\n\t\tthrow new CloudflareApiError(\r\n\t\t\tdescribeFailure(isResponseEnvelope(parsed) ? parsed : undefined, `Cloudflare request failed with ${response.status}.`),\r\n\t\t\tresponse.status,\r\n\t\t\tparsed,\r\n\t\t);\r\n\t}\r\n\r\n\tif (isResponseEnvelope<T>(parsed)) {\r\n\t\tif (!parsed.success) {\r\n\t\t\tthrow new CloudflareApiError(describeFailure(parsed, \"Cloudflare request failed.\"), response.status, parsed);\r\n\t\t}\r\n\t\treturn parsed.result as T;\r\n\t}\r\n\r\n\tif ((params.responseMode ?? \"envelope\") === \"auto\") {\r\n\t\treturn parsed as T;\r\n\t}\r\n\r\n\tthrow new CloudflareApiError(\"Cloudflare response did not include the expected success/result envelope.\", response.status, parsed);\r\n}\r\n"],"mappings":";;AAUA,SAAS,EAAgB,GAAoE,GAA0B;AAKtH,QAJgB,GAAU,QACvB,KAAK,MAAU,EAAM,QAAQ,CAC9B,OAAO,QAAQ,CACf,KAAK,KAAK,IACM;;AAGnB,SAAS,EAAsB,GAAwF;AACtH,QAAyB,OAAO,KAAU,cAAnC,KAA+C,aAAa;;AAGpE,SAAS,EAAkB,GAA0B;AAC/C,OAGL,QAAO,KAAK,MAAM,EAAQ;;AAG3B,SAAgB,EAA0B,GAAyB;AAClE,QAAO,aAAiB,KAAsB,EAAM,WAAW;;AAGhE,eAAsB,EAAqB,GAO5B;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,EAGI,IAAS,EADC,MAAM,EAAS,MAAM,CACI;AACzC,KAAI,CAAC,EAAS,GACb,OAAM,IAAI,EACT,EAAgB,EAAmB,EAAO,GAAG,IAAS,KAAA,GAAW,kCAAkC,EAAS,OAAO,GAAG,EACtH,EAAS,QACT,EACA;AAGF,KAAI,EAAsB,EAAO,EAAE;AAClC,MAAI,CAAC,EAAO,QACX,OAAM,IAAI,EAAmB,EAAgB,GAAQ,6BAA6B,EAAE,EAAS,QAAQ,EAAO;AAE7G,SAAO,EAAO;;AAGf,MAAK,EAAO,gBAAgB,gBAAgB,OAC3C,QAAO;AAGR,OAAM,IAAI,EAAmB,6EAA6E,EAAS,QAAQ,EAAO"}
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\ntype ResponseMode = \"auto\" | \"envelope\";\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\nfunction isResponseEnvelope<T>(value: unknown): value is Partial<CloudflareResponseEnvelope<T>> & { success: boolean } {\n\treturn value !== null && typeof value === \"object\" && \"success\" in value;\n}\n\nfunction parseResponseBody(rawText: string): unknown {\n\tif (!rawText) {\n\t\treturn undefined;\n\t}\n\treturn JSON.parse(rawText) as unknown;\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\tresponseMode?: ResponseMode;\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 = parseResponseBody(rawText);\n\tif (!response.ok) {\n\t\tthrow new CloudflareApiError(\n\t\t\tdescribeFailure(isResponseEnvelope(parsed) ? parsed : undefined, `Cloudflare request failed with ${response.status}.`),\n\t\t\tresponse.status,\n\t\t\tparsed,\n\t\t);\n\t}\n\n\tif (isResponseEnvelope<T>(parsed)) {\n\t\tif (!parsed.success) {\n\t\t\tthrow new CloudflareApiError(describeFailure(parsed, \"Cloudflare request failed.\"), response.status, parsed);\n\t\t}\n\t\treturn parsed.result as T;\n\t}\n\n\tif ((params.responseMode ?? \"envelope\") === \"auto\") {\n\t\treturn parsed as T;\n\t}\n\n\tthrow new CloudflareApiError(\"Cloudflare response did not include the expected success/result envelope.\", response.status, parsed);\n}\n"],"mappings":";;AAUA,SAAS,EAAgB,GAAoE,GAA0B;AAKtH,QAJgB,GAAU,QACvB,KAAK,MAAU,EAAM,QAAQ,CAC9B,OAAO,QAAQ,CACf,KAAK,KAAK,IACM;;AAGnB,SAAS,EAAsB,GAAwF;AACtH,QAAyB,OAAO,KAAU,cAAnC,KAA+C,aAAa;;AAGpE,SAAS,EAAkB,GAA0B;AAC/C,OAGL,QAAO,KAAK,MAAM,EAAQ;;AAG3B,SAAgB,EAA0B,GAAyB;AAClE,QAAO,aAAiB,KAAsB,EAAM,WAAW;;AAGhE,eAAsB,EAAqB,GAO5B;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,EAGI,IAAS,EADC,MAAM,EAAS,MAAM,CACI;AACzC,KAAI,CAAC,EAAS,GACb,OAAM,IAAI,EACT,EAAgB,EAAmB,EAAO,GAAG,IAAS,KAAA,GAAW,kCAAkC,EAAS,OAAO,GAAG,EACtH,EAAS,QACT,EACA;AAGF,KAAI,EAAsB,EAAO,EAAE;AAClC,MAAI,CAAC,EAAO,QACX,OAAM,IAAI,EAAmB,EAAgB,GAAQ,6BAA6B,EAAE,EAAS,QAAQ,EAAO;AAE7G,SAAO,EAAO;;AAGf,MAAK,EAAO,gBAAgB,gBAAgB,OAC3C,QAAO;AAGR,OAAM,IAAI,EAAmB,6EAA6E,EAAS,QAAQ,EAAO"}
package/dist/config.js CHANGED
@@ -216,34 +216,49 @@ var g = h.object({
216
216
  help: `Defaults to \${${n}} or the OpenClaw state directory.`
217
217
  }
218
218
  }
219
- };
220
- function x(...e) {
219
+ }, x = [
220
+ "cloudflare",
221
+ "vectorize",
222
+ "embeddings",
223
+ "storage"
224
+ ];
225
+ function S(e) {
226
+ if (!e || typeof e != "object" || Array.isArray(e)) return e;
227
+ let t = e;
228
+ if ("config" in t) return S(t.config);
229
+ let n = Object.fromEntries(x.filter((e) => e in t).map((e) => [e, t[e]]));
230
+ return Object.keys(n).length > 0 ? n : "enabled" in t && Object.keys(t).every((e) => e === "enabled") ? {} : e;
231
+ }
232
+ function C(...e) {
221
233
  return e.find((e) => e !== void 0);
222
234
  }
223
- function S(...e) {
235
+ function w(...e) {
224
236
  for (let t of e) if (t && t.trim().length > 0) return t.trim();
225
237
  }
226
- function C(...e) {
238
+ function T(...e) {
227
239
  return e.find((e) => typeof e == "number" && Number.isFinite(e));
228
240
  }
229
- function w(e) {
241
+ function E(e) {
230
242
  return [...new Set((e ?? []).map((e) => e.trim()).filter(Boolean))];
231
243
  }
232
- function T(e) {
244
+ function D(e) {
233
245
  return e ?? "cosine";
234
246
  }
235
- function E(e) {
247
+ function O(e) {
236
248
  return e ?? "vectorize-inline";
237
249
  }
238
- function D(e) {
250
+ function k(e) {
239
251
  return y.parse(e ?? {});
240
252
  }
241
- function O(e) {
253
+ function A(e) {
254
+ return k(S(e) ?? {});
255
+ }
256
+ function j(e) {
242
257
  let t = e.plugins?.entries?.[o];
243
- return D(t ?? {});
258
+ return A(t ?? {});
244
259
  }
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]);
260
+ async function M(n) {
261
+ let a = A(n.pluginConfig), h = n.env ?? process.env, g = `plugins.entries.${o}`, _ = w(a.cloudflare?.accountId, h[e]);
247
262
  if (!_) throw new f(`Missing Cloudflare account id. Set ${e} or ${g}.cloudflare.accountId.`);
248
263
  let v = await m({
249
264
  config: n.openClawConfig,
@@ -254,29 +269,29 @@ async function k(n) {
254
269
  readFallback: () => h[t]
255
270
  });
256
271
  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]);
272
+ let y = w(a.vectorize?.indexName, h[c]);
258
273
  if (!y) throw new f(`Missing Vectorize index name. Set ${c} or ${g}.vectorize.indexName.`);
259
- let b = S(a.cloudflare?.apiBaseUrl, r);
274
+ let b = w(a.cloudflare?.apiBaseUrl, r);
260
275
  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);
276
+ let x = w(a.vectorize?.namespace, h[l]), S = T(a.vectorize?.topK, h.CLOUDFLARE_VECTORIZE_TOP_K ? Number(h[u]) : void 0), k = O(C(a.storage?.mode, h[s])), j = w(a.storage?.companionStorePath, h.OPENCLAW_CF_MEMORY_COMPANION_PATH) ?? p(".openclaw", "memory-cloudflare-vectorize", "companion-store.json"), M = n.resolvePath ?? ((e) => e), N = w(a.embeddings?.model, h[d], i);
262
277
  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));
278
+ let P = T(a.storage?.inlineTextMaxBytes) ?? 6e3, F = T(a.vectorize?.minScore) ?? 0, I = D(C(a.vectorize?.metric, a.vectorize?.createIndex?.metric));
264
279
  return {
265
280
  accountId: _,
266
281
  apiToken: v.value,
267
282
  apiBaseUrl: b,
268
- workersAiBaseUrl: S(a.cloudflare?.workersAiBaseUrl) ?? `${b}/accounts/${_}/ai/v1`,
269
- vectorizeBaseUrl: S(a.cloudflare?.vectorizeBaseUrl) ?? `${b}/accounts/${_}/vectorize/v2/indexes/${y}`,
283
+ workersAiBaseUrl: w(a.cloudflare?.workersAiBaseUrl) ?? `${b}/accounts/${_}/ai/v1`,
284
+ vectorizeBaseUrl: w(a.cloudflare?.vectorizeBaseUrl) ?? `${b}/accounts/${_}/vectorize/v2/indexes/${y}`,
270
285
  indexName: y,
271
- fixedNamespace: O,
272
- topK: k ?? 5,
286
+ fixedNamespace: x,
287
+ topK: S ?? 5,
273
288
  minScore: F,
274
289
  metric: I,
275
290
  model: N,
276
- storageMode: A,
291
+ storageMode: k,
277
292
  companionStorePath: M(j),
278
293
  inlineTextMaxBytes: P,
279
- metadataIndexedFields: w(a.vectorize?.metadataIndexedFields),
294
+ metadataIndexedFields: E(a.vectorize?.metadataIndexedFields),
280
295
  createIndex: {
281
296
  description: a.vectorize?.createIndex?.description ?? "OpenClaw memory index backed by Cloudflare Vectorize.",
282
297
  dimensions: a.vectorize?.createIndex?.dimensions,
@@ -285,6 +300,6 @@ async function k(n) {
285
300
  };
286
301
  }
287
302
  //#endregion
288
- export { O as getPluginConfigFromOpenClawConfig, b as pluginConfigSchema, k as resolvePluginConfig };
303
+ export { j as getPluginConfigFromOpenClawConfig, A as normalizePluginConfigInput, b as pluginConfigSchema, M as resolvePluginConfig };
289
304
 
290
305
  //# sourceMappingURL=config.js.map
@@ -1 +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,CAAC,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N;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"}
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\nconst PLUGIN_CONFIG_ROOT_KEYS = [\"cloudflare\", \"vectorize\", \"embeddings\", \"storage\"] as const satisfies ReadonlyArray<keyof RawPluginConfig>;\n\nfunction unwrapPluginConfigCandidate(value: unknown): unknown {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) {\n\t\treturn value;\n\t}\n\n\tconst candidate = value as Record<string, unknown>;\n\tif (\"config\" in candidate) {\n\t\treturn unwrapPluginConfigCandidate(candidate.config);\n\t}\n\n\tconst directConfig = Object.fromEntries(PLUGIN_CONFIG_ROOT_KEYS.filter((key) => key in candidate).map((key) => [key, candidate[key]]));\n\tif (Object.keys(directConfig).length > 0) {\n\t\treturn directConfig;\n\t}\n\n\tif (\"enabled\" in candidate && Object.keys(candidate).every((key) => key === \"enabled\")) {\n\t\treturn {};\n\t}\n\n\treturn value;\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 normalizePluginConfigInput(value: unknown): RawPluginConfig {\n\treturn parsePluginConfig(unwrapPluginConfigCandidate(value) ?? {});\n}\n\nexport function getPluginConfigFromOpenClawConfig(config: OpenClawConfig): RawPluginConfig {\n\tconst candidate = (config as PluginEntriesAwareConfig).plugins?.entries?.[PLUGIN_ID];\n\treturn normalizePluginConfigInput(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 = normalizePluginConfigInput(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,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"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 = {
7
7
  logicalId: "oc_record_id",
8
+ namespace: "oc_namespace",
8
9
  title: "oc_title",
9
10
  text: "oc_text",
10
11
  storageMode: "oc_storage_mode",
@@ -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\";\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"}
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\tnamespace: \"oc_namespace\",\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,WAAW;CACX,OAAO;CACP,MAAM;CACN,aAAa;CACb,SAAS;CACT,QAAQ;CACR,WAAW;CACX,WAAW;CACX"}
@@ -1,34 +1,47 @@
1
1
  import { requestCloudflare as e } from "./cloudflare-api.js";
2
2
  //#region src/embeddings-client.ts
3
- function t(e) {
3
+ var t = 64;
4
+ function n(e) {
4
5
  return e.data.every((e) => !!e && typeof e == "object" && "embedding" in e && Array.isArray(e.embedding) && "index" in e && typeof e.index == "number");
5
6
  }
6
- var n = class {
7
+ var r = class {
8
+ queryCache = /* @__PURE__ */ new Map();
7
9
  constructor(e) {
8
10
  this.config = e;
9
11
  }
10
12
  async embedQuery(e) {
11
- let [t] = await this.embedBatch([e]);
12
- return t;
13
+ let n = this.queryCache.get(e);
14
+ if (n) return [...await n];
15
+ let r = this.embedBatch([e]).then(([e]) => {
16
+ if (!e) throw Error("Workers AI did not return an embedding.");
17
+ return e;
18
+ }).catch((t) => {
19
+ throw this.queryCache.delete(e), t;
20
+ });
21
+ if (this.queryCache.set(e, r), this.queryCache.size > t) {
22
+ let e = this.queryCache.keys().next().value;
23
+ typeof e == "string" && this.queryCache.delete(e);
24
+ }
25
+ return [...await r];
13
26
  }
14
- async embedBatch(n) {
15
- if (n.length === 0) return [];
27
+ async embedBatch(t) {
28
+ if (t.length === 0) return [];
16
29
  let r = await e({
17
30
  url: `${this.config.workersAiBaseUrl}/embeddings`,
18
31
  apiToken: this.config.apiToken,
19
32
  body: JSON.stringify({
20
33
  model: this.config.model,
21
- input: n
34
+ input: t
22
35
  }),
23
36
  responseMode: "auto"
24
37
  });
25
- return t(r) ? [...r.data].sort((e, t) => e.index - t.index).map((e) => e.embedding) : r.data;
38
+ return n(r) ? [...r.data].sort((e, t) => e.index - t.index).map((e) => e.embedding) : r.data;
26
39
  }
27
40
  async probeDimensions() {
28
41
  return (await this.embedQuery("openclaw-memory-dimension-probe")).length;
29
42
  }
30
43
  };
31
44
  //#endregion
32
- export { n as WorkersAiEmbeddingsClient };
45
+ export { r as WorkersAiEmbeddingsClient };
33
46
 
34
47
  //# sourceMappingURL=embeddings-client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"embeddings-client.js","names":[],"sources":["../src/embeddings-client.ts"],"sourcesContent":["import { requestCloudflare } from \"./cloudflare-api.js\";\r\nimport type { ResolvedPluginConfig } from \"./types.js\";\r\n\r\ntype OpenAiEmbeddingResponse = {\r\n\tdata: Array<{\r\n\t\tembedding: number[];\r\n\t\tindex: number;\r\n\t}>;\r\n};\r\n\r\ntype NativeEmbeddingResponse = {\r\n\tdata: number[][];\r\n\tshape?: number[];\r\n};\r\n\r\ntype EmbeddingResponse = OpenAiEmbeddingResponse | NativeEmbeddingResponse;\r\n\r\nfunction isOpenAiEmbeddingResponse(response: EmbeddingResponse): response is OpenAiEmbeddingResponse {\r\n\treturn response.data.every(\r\n\t\t(entry) =>\r\n\t\t\tBoolean(entry) &&\r\n\t\t\ttypeof entry === \"object\" &&\r\n\t\t\t\"embedding\" in entry &&\r\n\t\t\tArray.isArray(entry.embedding) &&\r\n\t\t\t\"index\" in entry &&\r\n\t\t\ttypeof entry.index === \"number\",\r\n\t);\r\n}\r\n\r\nexport class WorkersAiEmbeddingsClient {\r\n\tconstructor(private readonly config: ResolvedPluginConfig) {}\r\n\r\n\tasync embedQuery(text: string): Promise<number[]> {\r\n\t\tconst [embedding] = await this.embedBatch([text]);\r\n\t\treturn embedding;\r\n\t}\r\n\r\n\tasync embedBatch(texts: string[]): Promise<number[][]> {\r\n\t\tif (texts.length === 0) {\r\n\t\t\treturn [];\r\n\t\t}\r\n\t\tconst response = await requestCloudflare<EmbeddingResponse>({\r\n\t\t\turl: `${this.config.workersAiBaseUrl}/embeddings`,\r\n\t\t\tapiToken: this.config.apiToken,\r\n\t\t\tbody: JSON.stringify({\r\n\t\t\t\tmodel: this.config.model,\r\n\t\t\t\tinput: texts,\r\n\t\t\t}),\r\n\t\t\tresponseMode: \"auto\",\r\n\t\t});\r\n\r\n\t\tif (isOpenAiEmbeddingResponse(response)) {\r\n\t\t\treturn [...response.data].sort((left, right) => left.index - right.index).map((entry) => entry.embedding);\r\n\t\t}\r\n\r\n\t\treturn response.data;\r\n\t}\r\n\r\n\tasync probeDimensions(): Promise<number> {\r\n\t\tconst embedding = await this.embedQuery(\"openclaw-memory-dimension-probe\");\r\n\t\treturn embedding.length;\r\n\t}\r\n}\r\n"],"mappings":";;AAiBA,SAAS,EAA0B,GAAkE;AACpG,QAAO,EAAS,KAAK,OACnB,MACA,EAAQ,KACR,OAAO,KAAU,YACjB,eAAe,KACf,MAAM,QAAQ,EAAM,UAAU,IAC9B,WAAW,KACX,OAAO,EAAM,SAAU,SACxB;;AAGF,IAAa,IAAb,MAAuC;CACtC,YAAY,GAA+C;AAA9B,OAAA,SAAA;;CAE7B,MAAM,WAAW,GAAiC;EACjD,IAAM,CAAC,KAAa,MAAM,KAAK,WAAW,CAAC,EAAK,CAAC;AACjD,SAAO;;CAGR,MAAM,WAAW,GAAsC;AACtD,MAAI,EAAM,WAAW,EACpB,QAAO,EAAE;EAEV,IAAM,IAAW,MAAM,EAAqC;GAC3D,KAAK,GAAG,KAAK,OAAO,iBAAiB;GACrC,UAAU,KAAK,OAAO;GACtB,MAAM,KAAK,UAAU;IACpB,OAAO,KAAK,OAAO;IACnB,OAAO;IACP,CAAC;GACF,cAAc;GACd,CAAC;AAMF,SAJI,EAA0B,EAAS,GAC/B,CAAC,GAAG,EAAS,KAAK,CAAC,MAAM,GAAM,MAAU,EAAK,QAAQ,EAAM,MAAM,CAAC,KAAK,MAAU,EAAM,UAAU,GAGnG,EAAS;;CAGjB,MAAM,kBAAmC;AAExC,UADkB,MAAM,KAAK,WAAW,kCAAkC,EACzD"}
1
+ {"version":3,"file":"embeddings-client.js","names":[],"sources":["../src/embeddings-client.ts"],"sourcesContent":["import { requestCloudflare } from \"./cloudflare-api.js\";\nimport type { ResolvedPluginConfig } from \"./types.js\";\n\nconst QUERY_CACHE_LIMIT = 64;\n\ntype OpenAiEmbeddingResponse = {\n\tdata: Array<{\n\t\tembedding: number[];\n\t\tindex: number;\n\t}>;\n};\n\ntype NativeEmbeddingResponse = {\n\tdata: number[][];\n\tshape?: number[];\n};\n\ntype EmbeddingResponse = OpenAiEmbeddingResponse | NativeEmbeddingResponse;\n\nfunction isOpenAiEmbeddingResponse(response: EmbeddingResponse): response is OpenAiEmbeddingResponse {\n\treturn response.data.every(\n\t\t(entry) =>\n\t\t\tBoolean(entry) &&\n\t\t\ttypeof entry === \"object\" &&\n\t\t\t\"embedding\" in entry &&\n\t\t\tArray.isArray(entry.embedding) &&\n\t\t\t\"index\" in entry &&\n\t\t\ttypeof entry.index === \"number\",\n\t);\n}\n\nexport class WorkersAiEmbeddingsClient {\n\tprivate readonly queryCache = new Map<string, Promise<number[]>>();\n\n\tconstructor(private readonly config: ResolvedPluginConfig) {}\n\n\tasync embedQuery(text: string): Promise<number[]> {\n\t\tconst cached = this.queryCache.get(text);\n\t\tif (cached) {\n\t\t\treturn [...(await cached)];\n\t\t}\n\n\t\tconst pending = this.embedBatch([text])\n\t\t\t.then(([embedding]) => {\n\t\t\t\tif (!embedding) {\n\t\t\t\t\tthrow new Error(\"Workers AI did not return an embedding.\");\n\t\t\t\t}\n\t\t\t\treturn embedding;\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tthis.queryCache.delete(text);\n\t\t\t\tthrow error;\n\t\t\t});\n\t\tthis.queryCache.set(text, pending);\n\t\tif (this.queryCache.size > QUERY_CACHE_LIMIT) {\n\t\t\tconst oldestKey = this.queryCache.keys().next().value;\n\t\t\tif (typeof oldestKey === \"string\") {\n\t\t\t\tthis.queryCache.delete(oldestKey);\n\t\t\t}\n\t\t}\n\n\t\treturn [...(await pending)];\n\t}\n\n\tasync embedBatch(texts: string[]): Promise<number[][]> {\n\t\tif (texts.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst response = await requestCloudflare<EmbeddingResponse>({\n\t\t\turl: `${this.config.workersAiBaseUrl}/embeddings`,\n\t\t\tapiToken: this.config.apiToken,\n\t\t\tbody: JSON.stringify({\n\t\t\t\tmodel: this.config.model,\n\t\t\t\tinput: texts,\n\t\t\t}),\n\t\t\tresponseMode: \"auto\",\n\t\t});\n\n\t\tif (isOpenAiEmbeddingResponse(response)) {\n\t\t\treturn [...response.data].sort((left, right) => left.index - right.index).map((entry) => entry.embedding);\n\t\t}\n\n\t\treturn response.data;\n\t}\n\n\tasync probeDimensions(): Promise<number> {\n\t\tconst embedding = await this.embedQuery(\"openclaw-memory-dimension-probe\");\n\t\treturn embedding.length;\n\t}\n}\n"],"mappings":";;AAGA,IAAM,IAAoB;AAgB1B,SAAS,EAA0B,GAAkE;AACpG,QAAO,EAAS,KAAK,OACnB,MACA,EAAQ,KACR,O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,46 @@
1
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";
2
+ import { pluginConfigSchema as o } from "./config.js";
3
+ import { createCloudflareMemoryService as s, resolveCloudflareMemoryServiceConfig as c } from "./service-factory.js";
4
+ import { registerCloudflareMemoryCli as l } from "./cli.js";
5
+ import { buildPromptSection as u } from "./prompt.js";
6
+ import { createPublicArtifactsProvider as d } from "./public-artifacts.js";
7
+ import { createMemoryRuntime as f } from "./runtime.js";
8
+ import { createDeleteTool as p, createGetTool as m, createSearchTool as h, createUpsertTool as g } from "./tools.js";
9
+ import { definePluginEntry as _ } from "openclaw/plugin-sdk/plugin-entry";
10
10
  //#region src/index.ts
11
- function y() {
11
+ function v(e) {
12
+ return e && e.trim().length > 0 ? e.trim() : void 0;
13
+ }
14
+ function y(e) {
12
15
  return {
13
16
  id: "cloudflare-workers-ai",
14
17
  defaultModel: n,
15
18
  transport: "remote",
16
19
  allowExplicitWhenConfiguredAuto: !0,
17
- async create(e) {
18
- let t = await c({
19
- pluginConfig: o(e.config),
20
- openClawConfig: e.config,
21
- env: process.env
22
- }), n = new l({
23
- ...t,
24
- model: e.model || t.model,
25
- workersAiBaseUrl: e.remote?.baseUrl && e.remote.baseUrl.trim().length > 0 ? e.remote.baseUrl : t.workersAiBaseUrl,
26
- apiToken: typeof e.remote?.apiKey == "string" && e.remote.apiKey.trim().length > 0 ? e.remote.apiKey : t.apiToken
27
- }, e.config);
20
+ async create(t) {
21
+ let n = await s({
22
+ pluginConfig: e.pluginConfig,
23
+ openClawConfig: t.config,
24
+ env: process.env,
25
+ resolvePath: e.resolvePath,
26
+ overrides: {
27
+ model: t.model || void 0,
28
+ workersAiBaseUrl: v(t.remote?.baseUrl),
29
+ apiToken: typeof t.remote?.apiKey == "string" ? v(t.remote.apiKey) : void 0
30
+ }
31
+ });
28
32
  return {
29
33
  provider: {
30
34
  id: "cloudflare-workers-ai",
31
- model: e.model || t.model,
35
+ model: n.config.model,
32
36
  embedQuery: (e) => n.embeddings.embedQuery(e),
33
37
  embedBatch: (e) => n.embeddings.embedBatch(e)
34
38
  },
35
39
  runtime: {
36
40
  id: "cloudflare-workers-ai",
37
41
  cacheKeyData: {
38
- accountId: t.accountId,
39
- model: e.model || t.model
42
+ accountId: n.config.accountId,
43
+ model: n.config.model
40
44
  }
41
45
  }
42
46
  };
@@ -45,28 +49,43 @@ function y() {
45
49
  }
46
50
  function b(n) {
47
51
  n.registerCli(({ program: e }) => {
48
- u(e, {
52
+ l(e, {
49
53
  pluginConfig: n.pluginConfig,
50
54
  openClawConfig: n.config,
51
55
  resolvePath: n.resolvePath
52
56
  });
53
57
  }, n.registrationMode === "cli-metadata" ? { descriptors: [t] } : { commands: [e] });
54
58
  }
55
- var x = v({
59
+ var x = _({
56
60
  id: i,
57
61
  name: a,
58
62
  description: r,
59
63
  kind: "memory",
60
- configSchema: s,
64
+ configSchema: o,
61
65
  register(e) {
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({
66
+ o.parse?.(e.pluginConfig ?? {}), b(e), !(e.registrationMode === "cli-metadata" || typeof e.registerMemoryEmbeddingProvider != "function" || typeof e.registerMemoryCapability != "function" || typeof e.registerTool != "function") && (e.registerMemoryEmbeddingProvider(y({
67
+ pluginConfig: e.pluginConfig,
68
+ resolvePath: e.resolvePath
69
+ })), e.registerMemoryCapability({
70
+ promptBuilder: u,
71
+ runtime: f({
65
72
  pluginConfig: e.pluginConfig,
66
73
  resolvePath: e.resolvePath
67
74
  }),
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({
75
+ publicArtifacts: d(e.pluginConfig, e.resolvePath)
76
+ }), e.registerTool((t) => h({
77
+ pluginConfig: e.pluginConfig,
78
+ resolvePath: e.resolvePath
79
+ }, t), { names: ["cloudflare_memory_search"] }), e.registerTool((t) => m({
80
+ pluginConfig: e.pluginConfig,
81
+ resolvePath: e.resolvePath
82
+ }, t), { names: ["cloudflare_memory_get"] }), e.registerTool((t) => g({
83
+ pluginConfig: e.pluginConfig,
84
+ resolvePath: e.resolvePath
85
+ }, t), { names: ["cloudflare_memory_upsert"] }), e.registerTool((t) => p({
86
+ pluginConfig: e.pluginConfig,
87
+ resolvePath: e.resolvePath
88
+ }, t), { names: ["cloudflare_memory_delete"] }), c({
70
89
  pluginConfig: e.pluginConfig,
71
90
  openClawConfig: e.config,
72
91
  env: process.env,
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, 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,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,EAAI,cAAc,EAAI,EAAE,EAClE,OAAO,CAAC,2BAA2B,EACnC,CAAC,EACF,EAAI,cAAc,MAAQ,EAAc,EAAI,cAAc,EAAI,EAAE,EAC/D,OAAO,CAAC,wBAAwB,EAChC,CAAC,EACF,EAAI,cAAc,MAAQ,EAAiB,EAAI,cAAc,EAAI,EAAE,EAClE,OAAO,CAAC,2BAA2B,EACnC,CAAC,EACF,EAAI,cAAc,MAAQ,EAAiB,EAAI,cAAc,EAAI,EAAE,EAClE,OAAO,CAAC,2BAA2B,EACnC,CAAC,EAEG,EAAoB;GACxB,cAAc,EAAI;GAClB,gBAAgB,EAAI;GACpB,KAAK,QAAQ;GACb,aAAa,EAAI;GACjB,CAAC,CACA,MAAM,MAAa;AACnB,KAAI,OAAO,KAAK,GAAG,EAAU,yBAAyB,EAAS,UAAU,eAAe,EAAS,MAAM,GAAG;IACzG,CACD,OAAO,MAAmB;GAC1B,IAAM,IAAU,aAAiB,QAAQ,EAAM,UAAU;AACzD,KAAI,OAAO,KAAK,GAAG,EAAU,yCAAyC,IAAU;IAC/E;;CAEJ,CAAC"}
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 { pluginConfigSchema } 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 { createCloudflareMemoryService, resolveCloudflareMemoryServiceConfig } from \"./service-factory.js\";\nimport { createDeleteTool, createGetTool, createSearchTool, createUpsertTool } from \"./tools.js\";\n\nfunction pickTrimmed(value: string | undefined): string | undefined {\n\treturn value && value.trim().length > 0 ? value.trim() : undefined;\n}\n\nfunction createMemoryEmbeddingProviderAdapter(params: { pluginConfig: unknown; resolvePath?: (input: string) => string }): 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 service = await createCloudflareMemoryService({\n\t\t\t\tpluginConfig: params.pluginConfig,\n\t\t\t\topenClawConfig: options.config,\n\t\t\t\tenv: process.env,\n\t\t\t\tresolvePath: params.resolvePath,\n\t\t\t\toverrides: {\n\t\t\t\t\tmodel: options.model || undefined,\n\t\t\t\t\tworkersAiBaseUrl: pickTrimmed(options.remote?.baseUrl),\n\t\t\t\t\tapiToken: typeof options.remote?.apiKey === \"string\" ? pickTrimmed(options.remote.apiKey) : undefined,\n\t\t\t\t},\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: service.config.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: service.config.accountId,\n\t\t\t\t\t\tmodel: service.config.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(\n\t\t\tcreateMemoryEmbeddingProviderAdapter({\n\t\t\t\tpluginConfig: api.pluginConfig,\n\t\t\t\tresolvePath: api.resolvePath,\n\t\t\t}),\n\t\t);\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(\n\t\t\t(ctx) =>\n\t\t\t\tcreateSearchTool(\n\t\t\t\t\t{\n\t\t\t\t\t\tpluginConfig: api.pluginConfig,\n\t\t\t\t\t\tresolvePath: api.resolvePath,\n\t\t\t\t\t},\n\t\t\t\t\tctx,\n\t\t\t\t),\n\t\t\t{\n\t\t\t\tnames: [\"cloudflare_memory_search\"],\n\t\t\t},\n\t\t);\n\t\tapi.registerTool(\n\t\t\t(ctx) =>\n\t\t\t\tcreateGetTool(\n\t\t\t\t\t{\n\t\t\t\t\t\tpluginConfig: api.pluginConfig,\n\t\t\t\t\t\tresolvePath: api.resolvePath,\n\t\t\t\t\t},\n\t\t\t\t\tctx,\n\t\t\t\t),\n\t\t\t{\n\t\t\t\tnames: [\"cloudflare_memory_get\"],\n\t\t\t},\n\t\t);\n\t\tapi.registerTool(\n\t\t\t(ctx) =>\n\t\t\t\tcreateUpsertTool(\n\t\t\t\t\t{\n\t\t\t\t\t\tpluginConfig: api.pluginConfig,\n\t\t\t\t\t\tresolvePath: api.resolvePath,\n\t\t\t\t\t},\n\t\t\t\t\tctx,\n\t\t\t\t),\n\t\t\t{\n\t\t\t\tnames: [\"cloudflare_memory_upsert\"],\n\t\t\t},\n\t\t);\n\t\tapi.registerTool(\n\t\t\t(ctx) =>\n\t\t\t\tcreateDeleteTool(\n\t\t\t\t\t{\n\t\t\t\t\t\tpluginConfig: api.pluginConfig,\n\t\t\t\t\t\tresolvePath: api.resolvePath,\n\t\t\t\t\t},\n\t\t\t\t\tctx,\n\t\t\t\t),\n\t\t\t{\n\t\t\t\tnames: [\"cloudflare_memory_delete\"],\n\t\t\t},\n\t\t);\n\n\t\tvoid resolveCloudflareMemoryServiceConfig({\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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,kBACzB,OAAO,EAAI,mCAAoC,cAC/C,OAAO,EAAI,4BAA6B,cACxC,OAAO,EAAI,gBAAiB,gBAK7B,EAAI,gCACH,EAAqC;GACpC,cAAc,EAAI;GAClB,aAAa,EAAI;GACjB,CAAC,CACF,EACD,EAAI,yBAAyB;GAC5B,eAAe;GACf,SAAS,EAAoB;IAC5B,cAAc,EAAI;IAClB,aAAa,EAAI;IACjB,CAAC;GACF,iBAAiB,EAA8B,EAAI,cAAc,EAAI,YAAY;GACjF,CAAC,EAEF,EAAI,cACF,MACA,EACC;GACC,cAAc,EAAI;GAClB,aAAa,EAAI;GACjB,EACD,EACA,EACF,EACC,OAAO,CAAC,2BAA2B,EACnC,CACD,EACD,EAAI,cACF,MACA,EACC;GACC,cAAc,EAAI;GAClB,aAAa,EAAI;GACjB,EACD,EACA,EACF,EACC,OAAO,CAAC,wBAAwB,EAChC,CACD,EACD,EAAI,cACF,MACA,EACC;GACC,cAAc,EAAI;GAClB,aAAa,EAAI;GACjB,EACD,EACA,EACF,EACC,OAAO,CAAC,2BAA2B,EACnC,CACD,EACD,EAAI,cACF,MACA,EACC;GACC,cAAc,EAAI;GAClB,aAAa,EAAI;GACjB,EACD,EACA,EACF,EACC,OAAO,CAAC,2BAA2B,EACnC,CACD,EAEI,EAAqC;GACzC,cAAc,EAAI;GAClB,gBAAgB,EAAI;GACpB,KAAK,QAAQ;GACb,aAAa,EAAI;GACjB,CAAC,CACA,MAAM,MAAa;AACnB,KAAI,OAAO,KAAK,GAAG,EAAU,yBAAyB,EAAS,UAAU,eAAe,EAAS,MAAM,GAAG;IACzG,CACD,OAAO,MAAmB;GAC1B,IAAM,IAAU,aAAiB,QAAQ,EAAM,UAAU;AACzD,KAAI,OAAO,KAAK,GAAG,EAAU,yCAAyC,IAAU;IAC/E;;CAEJ,CAAC"}
@@ -20,17 +20,22 @@ function s(e, t) {
20
20
  let r = `${e}::${t}`;
21
21
  return i.byteLength(r, "utf8") <= 64 ? r : `cfm_${n("sha256").update(r).digest("hex").slice(0, 48)}`;
22
22
  }
23
- function c(e, t) {
23
+ function c(e) {
24
+ if (!e || e.startsWith("cfm_")) return;
25
+ let t = e.indexOf("::");
26
+ if (!(t <= 0)) return e.slice(0, t);
27
+ }
28
+ function l(e, t) {
24
29
  return `${e}/${t}.md`;
25
30
  }
26
- function l(e) {
31
+ function u(e) {
27
32
  let t = e.replace(/\\/g, "/").replace(/^\//, "").split("/");
28
33
  return t.length !== 2 || !t[1].endsWith(".md") ? null : {
29
34
  namespace: t[0],
30
35
  logicalId: t[1].slice(0, -3)
31
36
  };
32
37
  }
33
- function u(e, t) {
38
+ function d(e, t) {
34
39
  let n = e.trim().replace(/\s+/g, " ");
35
40
  if (!n) return "";
36
41
  let r = n.toLowerCase().indexOf(t.trim().toLowerCase());
@@ -38,10 +43,11 @@ function u(e, t) {
38
43
  let i = Math.max(0, r - 80), a = Math.min(n.length, r + Math.max(t.length, 40) + 80);
39
44
  return n.slice(i, a);
40
45
  }
41
- function d(n) {
42
- let a = n.input.id?.trim() || r(), l = s(n.namespace, a), u = (/* @__PURE__ */ new Date()).toISOString(), d = o(n.input.metadata), f = {
46
+ function f(n) {
47
+ let a = n.input.id?.trim() || r(), c = s(n.namespace, a), u = (/* @__PURE__ */ new Date()).toISOString(), d = o(n.input.metadata), f = {
43
48
  ...d,
44
49
  [e.logicalId]: a,
50
+ [e.namespace]: n.namespace,
45
51
  [e.storageMode]: n.config.storageMode,
46
52
  [e.createdAt]: u,
47
53
  [e.updatedAt]: u
@@ -53,7 +59,7 @@ function d(n) {
53
59
  if (r > n.config.inlineTextMaxBytes) throw new t(`Memory text is ${r} bytes, which exceeds the inline metadata limit of ${n.config.inlineTextMaxBytes}. Switch storage.mode to "companion-store" or reduce the payload size.`);
54
60
  f[e.text] = n.input.text;
55
61
  } else {
56
- let t = c(n.namespace, a);
62
+ let t = l(n.namespace, a);
57
63
  f[e.pointer] = t, p = {
58
64
  id: a,
59
65
  namespace: n.namespace,
@@ -67,10 +73,10 @@ function d(n) {
67
73
  }
68
74
  return {
69
75
  logicalId: a,
70
- vectorId: l,
71
- path: c(n.namespace, a),
76
+ vectorId: c,
77
+ path: l(n.namespace, a),
72
78
  vector: {
73
- id: l,
79
+ id: c,
74
80
  namespace: n.namespace,
75
81
  values: n.embedding,
76
82
  metadata: f
@@ -78,22 +84,22 @@ function d(n) {
78
84
  companionRecord: p
79
85
  };
80
86
  }
81
- function f(t) {
82
- let n = t.metadata ?? {}, r = t.namespace ?? (typeof n[e.pointer] == "string" ? String(n[e.pointer]).split("/")[0] : "main"), i = typeof n[e.logicalId] == "string" ? String(n[e.logicalId]) : String(t.id ?? ""), a = Object.fromEntries(Object.entries(n).filter(([e]) => !e.startsWith("oc_")));
87
+ function p(t, n) {
88
+ let r = t.metadata ?? {}, i = typeof r[e.pointer] == "string" ? u(String(r[e.pointer])) : null, a = typeof t.namespace == "string" ? t.namespace : typeof r[e.namespace] == "string" ? String(r[e.namespace]) : i?.namespace ?? c(typeof t.id == "string" ? String(t.id) : void 0) ?? n?.defaultNamespace ?? "main", o = typeof r[e.logicalId] == "string" ? String(r[e.logicalId]) : String(t.id ?? ""), s = Object.fromEntries(Object.entries(r).filter(([e]) => !e.startsWith("oc_")));
83
89
  return {
84
- logicalId: i,
85
- vectorId: String(t.id ?? i),
86
- namespace: r,
87
- title: typeof n[e.title] == "string" ? String(n[e.title]) : void 0,
88
- text: typeof n[e.text] == "string" ? String(n[e.text]) : void 0,
89
- metadata: a,
90
- source: typeof n[e.source] == "string" ? String(n[e.source]) : void 0,
91
- createdAt: typeof n[e.createdAt] == "string" ? String(n[e.createdAt]) : void 0,
92
- updatedAt: typeof n[e.updatedAt] == "string" ? String(n[e.updatedAt]) : void 0,
93
- path: c(r, i)
90
+ logicalId: o,
91
+ vectorId: String(t.id ?? o),
92
+ namespace: a,
93
+ title: typeof r[e.title] == "string" ? String(r[e.title]) : void 0,
94
+ text: typeof r[e.text] == "string" ? String(r[e.text]) : void 0,
95
+ metadata: s,
96
+ source: typeof r[e.source] == "string" ? String(r[e.source]) : void 0,
97
+ createdAt: typeof r[e.createdAt] == "string" ? String(r[e.createdAt]) : void 0,
98
+ updatedAt: typeof r[e.updatedAt] == "string" ? String(r[e.updatedAt]) : void 0,
99
+ path: l(a, o)
94
100
  };
95
101
  }
96
102
  //#endregion
97
- export { u as buildSnippet, s as buildVectorId, f as hydrateInlineRecord, d as mapRecordForUpsert, l as parseVirtualPath };
103
+ export { d as buildSnippet, s as buildVectorId, p as hydrateInlineRecord, f as mapRecordForUpsert, u as parseVirtualPath };
98
104
 
99
105
  //# sourceMappingURL=record-mapper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"record-mapper.js","names":[],"sources":["../src/record-mapper.ts"],"sourcesContent":["import { Buffer } from \"node:buffer\";\r\nimport { createHash, randomUUID } from \"node:crypto\";\r\nimport { RESERVED_METADATA_KEYS, RESERVED_METADATA_PREFIX } from \"./constants.js\";\r\nimport { RecordSizeError } from \"./errors.js\";\r\nimport type {\r\n\tCompanionRecord,\r\n\tHydratedMemoryRecord,\r\n\tMemoryRecordInput,\r\n\tMetadataValue,\r\n\tResolvedPluginConfig,\r\n\tVectorizeQueryMatch,\r\n\tVectorizeVector,\r\n} from \"./types.js\";\r\n\r\nfunction sanitizeMetadataKey(key: string): string {\r\n\tconst sanitized = key.trim().replace(/[.$\"]/g, \"_\").replace(/\\s+/g, \"_\");\r\n\tif (!sanitized) {\r\n\t\treturn \"metadata\";\r\n\t}\r\n\tif (sanitized.startsWith(RESERVED_METADATA_PREFIX)) {\r\n\t\treturn `user_${sanitized}`;\r\n\t}\r\n\treturn sanitized;\r\n}\r\n\r\nfunction sanitizeMetadata(metadata: Record<string, MetadataValue> | undefined): Record<string, MetadataValue> {\r\n\tif (!metadata) {\r\n\t\treturn {};\r\n\t}\r\n\tconst entries = Object.entries(metadata).filter(([, value]) => [\"string\", \"number\", \"boolean\"].includes(typeof value));\r\n\treturn Object.fromEntries(entries.map(([key, value]) => [sanitizeMetadataKey(key), value]));\r\n}\r\n\r\nexport function buildVectorId(namespace: string, logicalId: string): string {\r\n\tconst rawId = `${namespace}::${logicalId}`;\r\n\tif (Buffer.byteLength(rawId, \"utf8\") <= 64) {\r\n\t\treturn rawId;\r\n\t}\r\n\treturn `cfm_${createHash(\"sha256\").update(rawId).digest(\"hex\").slice(0, 48)}`;\r\n}\r\n\r\nexport function buildVirtualPath(namespace: string, logicalId: string): string {\r\n\treturn `${namespace}/${logicalId}.md`;\r\n}\r\n\r\nexport function parseVirtualPath(path: string): { namespace: string; logicalId: string } | null {\r\n\tconst normalized = path.replace(/\\\\/g, \"/\").replace(/^\\//, \"\");\r\n\tconst segments = normalized.split(\"/\");\r\n\tif (segments.length !== 2 || !segments[1].endsWith(\".md\")) {\r\n\t\treturn null;\r\n\t}\r\n\treturn {\r\n\t\tnamespace: segments[0],\r\n\t\tlogicalId: segments[1].slice(0, -3),\r\n\t};\r\n}\r\n\r\nexport function buildSnippet(text: string, query: string): string {\r\n\tconst normalized = text.trim().replace(/\\s+/g, \" \");\r\n\tif (!normalized) {\r\n\t\treturn \"\";\r\n\t}\r\n\tconst lower = normalized.toLowerCase();\r\n\tconst index = lower.indexOf(query.trim().toLowerCase());\r\n\tif (index === -1) {\r\n\t\treturn normalized.slice(0, 220);\r\n\t}\r\n\tconst start = Math.max(0, index - 80);\r\n\tconst end = Math.min(normalized.length, index + Math.max(query.length, 40) + 80);\r\n\treturn normalized.slice(start, end);\r\n}\r\n\r\nexport function mapRecordForUpsert(params: { input: MemoryRecordInput; namespace: string; embedding: number[]; config: ResolvedPluginConfig }): {\r\n\tlogicalId: string;\r\n\tvectorId: string;\r\n\tpath: string;\r\n\tvector: VectorizeVector;\r\n\tcompanionRecord?: CompanionRecord;\r\n} {\r\n\tconst logicalId = params.input.id?.trim() || randomUUID();\r\n\tconst vectorId = buildVectorId(params.namespace, logicalId);\r\n\tconst now = new Date().toISOString();\r\n\tconst userMetadata = sanitizeMetadata(params.input.metadata);\r\n\tconst metadataBase: Record<string, MetadataValue> = {\r\n\t\t...userMetadata,\r\n\t\t[RESERVED_METADATA_KEYS.logicalId]: logicalId,\r\n\t\t[RESERVED_METADATA_KEYS.storageMode]: params.config.storageMode,\r\n\t\t[RESERVED_METADATA_KEYS.createdAt]: now,\r\n\t\t[RESERVED_METADATA_KEYS.updatedAt]: now,\r\n\t};\r\n\r\n\tif (params.input.title) {\r\n\t\tmetadataBase[RESERVED_METADATA_KEYS.title] = params.input.title;\r\n\t}\r\n\tif (params.input.source) {\r\n\t\tmetadataBase[RESERVED_METADATA_KEYS.source] = params.input.source;\r\n\t}\r\n\r\n\tlet companionRecord: CompanionRecord | undefined;\r\n\tif (params.config.storageMode === \"vectorize-inline\") {\r\n\t\tconst byteLength = Buffer.byteLength(params.input.text, \"utf8\");\r\n\t\tif (byteLength > params.config.inlineTextMaxBytes) {\r\n\t\t\tthrow new RecordSizeError(\r\n\t\t\t\t`Memory text is ${byteLength} bytes, which exceeds the inline metadata limit of ${params.config.inlineTextMaxBytes}. Switch storage.mode to \"companion-store\" or reduce the payload size.`,\r\n\t\t\t);\r\n\t\t}\r\n\t\tmetadataBase[RESERVED_METADATA_KEYS.text] = params.input.text;\r\n\t} else {\r\n\t\tconst pointer = buildVirtualPath(params.namespace, logicalId);\r\n\t\tmetadataBase[RESERVED_METADATA_KEYS.pointer] = pointer;\r\n\t\tcompanionRecord = {\r\n\t\t\tid: logicalId,\r\n\t\t\tnamespace: params.namespace,\r\n\t\t\ttitle: params.input.title,\r\n\t\t\ttext: params.input.text,\r\n\t\t\tmetadata: userMetadata,\r\n\t\t\tsource: params.input.source,\r\n\t\t\tcreatedAt: now,\r\n\t\t\tupdatedAt: now,\r\n\t\t};\r\n\t}\r\n\r\n\treturn {\r\n\t\tlogicalId,\r\n\t\tvectorId,\r\n\t\tpath: buildVirtualPath(params.namespace, logicalId),\r\n\t\tvector: {\r\n\t\t\tid: vectorId,\r\n\t\t\tnamespace: params.namespace,\r\n\t\t\tvalues: params.embedding,\r\n\t\t\tmetadata: metadataBase,\r\n\t\t},\r\n\t\tcompanionRecord,\r\n\t};\r\n}\r\n\r\nexport function hydrateInlineRecord(match: VectorizeQueryMatch): Omit<HydratedMemoryRecord, \"text\" | \"path\"> & {\r\n\ttext?: string;\r\n\tpath: string;\r\n} {\r\n\tconst metadata = match.metadata ?? {};\r\n\tconst namespace =\r\n\t\tmatch.namespace ?? (typeof metadata[RESERVED_METADATA_KEYS.pointer] === \"string\" ? String(metadata[RESERVED_METADATA_KEYS.pointer]).split(\"/\")[0] : \"main\");\r\n\tconst logicalId =\r\n\t\ttypeof metadata[RESERVED_METADATA_KEYS.logicalId] === \"string\" ? String(metadata[RESERVED_METADATA_KEYS.logicalId]) : String(match.id ?? \"\");\r\n\tconst userMetadata = Object.fromEntries(Object.entries(metadata).filter(([key]) => !key.startsWith(RESERVED_METADATA_PREFIX)));\r\n\treturn {\r\n\t\tlogicalId,\r\n\t\tvectorId: String(match.id ?? logicalId),\r\n\t\tnamespace,\r\n\t\ttitle: typeof metadata[RESERVED_METADATA_KEYS.title] === \"string\" ? String(metadata[RESERVED_METADATA_KEYS.title]) : undefined,\r\n\t\ttext: typeof metadata[RESERVED_METADATA_KEYS.text] === \"string\" ? String(metadata[RESERVED_METADATA_KEYS.text]) : undefined,\r\n\t\tmetadata: userMetadata,\r\n\t\tsource: typeof metadata[RESERVED_METADATA_KEYS.source] === \"string\" ? String(metadata[RESERVED_METADATA_KEYS.source]) : undefined,\r\n\t\tcreatedAt: typeof metadata[RESERVED_METADATA_KEYS.createdAt] === \"string\" ? String(metadata[RESERVED_METADATA_KEYS.createdAt]) : undefined,\r\n\t\tupdatedAt: typeof metadata[RESERVED_METADATA_KEYS.updatedAt] === \"string\" ? String(metadata[RESERVED_METADATA_KEYS.updatedAt]) : undefined,\r\n\t\tpath: buildVirtualPath(namespace, logicalId),\r\n\t};\r\n}\r\n"],"mappings":";;;;;AAcA,SAAS,EAAoB,GAAqB;CACjD,IAAM,IAAY,EAA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M,IAAW,EAAM,YAAY,EAAE,EAC/B,IACL,EAAM,cAAc,OAAO,EAAS,EAAuB,YAAa,WAAW,OAAO,EAAS,EAAuB,SAAS,CAAC,MAAM,IAAI,CAAC,KAAK,SAC/I,IACL,OAAO,EAAS,EAAuB,cAAe,WAAW,OAAO,EAAS,EAAuB,WAAW,GAAG,OAAO,EAAM,MAAM,GAAG,EACvI,IAAe,OAAO,YAAY,OAAO,QAAQ,EAAS,CAAC,QAAQ,CAAC,OAAS,CAAC,EAAI,WAAA,MAAoC,CAAC,CAAC;AAC9H,QAAO;EACN;EACA,UAAU,OAAO,EAAM,MAAM,EAAU;EACvC;EACA,OAAO,OAAO,EAAS,EAAuB,UAAW,WAAW,OAAO,EAAS,EAAuB,OAAO,GAAG,KAAA;EACrH,MAAM,OAAO,EAAS,EAAuB,SAAU,WAAW,OAAO,EAAS,EAAuB,MAAM,GAAG,KAAA;EAClH,UAAU;EACV,QAAQ,OAAO,EAAS,EAAuB,WAAY,WAAW,OAAO,EAAS,EAAuB,QAAQ,GAAG,KAAA;EACxH,WAAW,OAAO,EAAS,EAAuB,cAAe,WAAW,OAAO,EAAS,EAAuB,WAAW,GAAG,KAAA;EACjI,WAAW,OAAO,EAAS,EAAuB,cAAe,WAAW,OAAO,EAAS,EAAuB,WAAW,GAAG,KAAA;EACjI,MAAM,EAAiB,GAAW,EAAU;EAC5C"}
1
+ {"version":3,"file":"record-mapper.js","names":[],"sources":["../src/record-mapper.ts"],"sourcesContent":["import { Buffer } from \"node:buffer\";\nimport { createHash, randomUUID } from \"node:crypto\";\nimport { RESERVED_METADATA_KEYS, RESERVED_METADATA_PREFIX } from \"./constants.js\";\nimport { RecordSizeError } from \"./errors.js\";\nimport type {\n\tCompanionRecord,\n\tHydratedMemoryRecord,\n\tMemoryRecordInput,\n\tMetadataValue,\n\tResolvedPluginConfig,\n\tVectorizeQueryMatch,\n\tVectorizeVector,\n} from \"./types.js\";\n\nfunction sanitizeMetadataKey(key: string): string {\n\tconst sanitized = key.trim().replace(/[.$\"]/g, \"_\").replace(/\\s+/g, \"_\");\n\tif (!sanitized) {\n\t\treturn \"metadata\";\n\t}\n\tif (sanitized.startsWith(RESERVED_METADATA_PREFIX)) {\n\t\treturn `user_${sanitized}`;\n\t}\n\treturn sanitized;\n}\n\nfunction sanitizeMetadata(metadata: Record<string, MetadataValue> | undefined): Record<string, MetadataValue> {\n\tif (!metadata) {\n\t\treturn {};\n\t}\n\tconst entries = Object.entries(metadata).filter(([, value]) => [\"string\", \"number\", \"boolean\"].includes(typeof value));\n\treturn Object.fromEntries(entries.map(([key, value]) => [sanitizeMetadataKey(key), value]));\n}\n\nexport function buildVectorId(namespace: string, logicalId: string): string {\n\tconst rawId = `${namespace}::${logicalId}`;\n\tif (Buffer.byteLength(rawId, \"utf8\") <= 64) {\n\t\treturn rawId;\n\t}\n\treturn `cfm_${createHash(\"sha256\").update(rawId).digest(\"hex\").slice(0, 48)}`;\n}\n\nfunction parseNamespaceFromVectorId(vectorId: string | undefined): string | undefined {\n\tif (!vectorId || vectorId.startsWith(\"cfm_\")) {\n\t\treturn undefined;\n\t}\n\tconst separatorIndex = vectorId.indexOf(\"::\");\n\tif (separatorIndex <= 0) {\n\t\treturn undefined;\n\t}\n\treturn vectorId.slice(0, separatorIndex);\n}\n\nexport function buildVirtualPath(namespace: string, logicalId: string): string {\n\treturn `${namespace}/${logicalId}.md`;\n}\n\nexport function parseVirtualPath(path: string): { namespace: string; logicalId: string } | null {\n\tconst normalized = path.replace(/\\\\/g, \"/\").replace(/^\\//, \"\");\n\tconst segments = normalized.split(\"/\");\n\tif (segments.length !== 2 || !segments[1].endsWith(\".md\")) {\n\t\treturn null;\n\t}\n\treturn {\n\t\tnamespace: segments[0],\n\t\tlogicalId: segments[1].slice(0, -3),\n\t};\n}\n\nexport function buildSnippet(text: string, query: string): string {\n\tconst normalized = text.trim().replace(/\\s+/g, \" \");\n\tif (!normalized) {\n\t\treturn \"\";\n\t}\n\tconst lower = normalized.toLowerCase();\n\tconst index = lower.indexOf(query.trim().toLowerCase());\n\tif (index === -1) {\n\t\treturn normalized.slice(0, 220);\n\t}\n\tconst start = Math.max(0, index - 80);\n\tconst end = Math.min(normalized.length, index + Math.max(query.length, 40) + 80);\n\treturn normalized.slice(start, end);\n}\n\nexport function mapRecordForUpsert(params: { input: MemoryRecordInput; namespace: string; embedding: number[]; config: ResolvedPluginConfig }): {\n\tlogicalId: string;\n\tvectorId: string;\n\tpath: string;\n\tvector: VectorizeVector;\n\tcompanionRecord?: CompanionRecord;\n} {\n\tconst logicalId = params.input.id?.trim() || randomUUID();\n\tconst vectorId = buildVectorId(params.namespace, logicalId);\n\tconst now = new Date().toISOString();\n\tconst userMetadata = sanitizeMetadata(params.input.metadata);\n\tconst metadataBase: Record<string, MetadataValue> = {\n\t\t...userMetadata,\n\t\t[RESERVED_METADATA_KEYS.logicalId]: logicalId,\n\t\t[RESERVED_METADATA_KEYS.namespace]: params.namespace,\n\t\t[RESERVED_METADATA_KEYS.storageMode]: params.config.storageMode,\n\t\t[RESERVED_METADATA_KEYS.createdAt]: now,\n\t\t[RESERVED_METADATA_KEYS.updatedAt]: now,\n\t};\n\n\tif (params.input.title) {\n\t\tmetadataBase[RESERVED_METADATA_KEYS.title] = params.input.title;\n\t}\n\tif (params.input.source) {\n\t\tmetadataBase[RESERVED_METADATA_KEYS.source] = params.input.source;\n\t}\n\n\tlet companionRecord: CompanionRecord | undefined;\n\tif (params.config.storageMode === \"vectorize-inline\") {\n\t\tconst byteLength = Buffer.byteLength(params.input.text, \"utf8\");\n\t\tif (byteLength > params.config.inlineTextMaxBytes) {\n\t\t\tthrow new RecordSizeError(\n\t\t\t\t`Memory text is ${byteLength} bytes, which exceeds the inline metadata limit of ${params.config.inlineTextMaxBytes}. Switch storage.mode to \"companion-store\" or reduce the payload size.`,\n\t\t\t);\n\t\t}\n\t\tmetadataBase[RESERVED_METADATA_KEYS.text] = params.input.text;\n\t} else {\n\t\tconst pointer = buildVirtualPath(params.namespace, logicalId);\n\t\tmetadataBase[RESERVED_METADATA_KEYS.pointer] = pointer;\n\t\tcompanionRecord = {\n\t\t\tid: logicalId,\n\t\t\tnamespace: params.namespace,\n\t\t\ttitle: params.input.title,\n\t\t\ttext: params.input.text,\n\t\t\tmetadata: userMetadata,\n\t\t\tsource: params.input.source,\n\t\t\tcreatedAt: now,\n\t\t\tupdatedAt: now,\n\t\t};\n\t}\n\n\treturn {\n\t\tlogicalId,\n\t\tvectorId,\n\t\tpath: buildVirtualPath(params.namespace, logicalId),\n\t\tvector: {\n\t\t\tid: vectorId,\n\t\t\tnamespace: params.namespace,\n\t\t\tvalues: params.embedding,\n\t\t\tmetadata: metadataBase,\n\t\t},\n\t\tcompanionRecord,\n\t};\n}\n\nexport function hydrateInlineRecord(\n\tmatch: VectorizeQueryMatch,\n\toptions?: {\n\t\tdefaultNamespace?: string;\n\t},\n): Omit<HydratedMemoryRecord, \"text\" | \"path\"> & {\n\ttext?: string;\n\tpath: string;\n} {\n\tconst metadata = match.metadata ?? {};\n\tconst pointerPath = typeof metadata[RESERVED_METADATA_KEYS.pointer] === \"string\" ? parseVirtualPath(String(metadata[RESERVED_METADATA_KEYS.pointer])) : null;\n\tconst namespace =\n\t\ttypeof match.namespace === \"string\"\n\t\t\t? match.namespace\n\t\t\t: typeof metadata[RESERVED_METADATA_KEYS.namespace] === \"string\"\n\t\t\t\t? String(metadata[RESERVED_METADATA_KEYS.namespace])\n\t\t\t\t: (pointerPath?.namespace ??\n\t\t\t\t\tparseNamespaceFromVectorId(typeof match.id === \"string\" ? String(match.id) : undefined) ??\n\t\t\t\t\toptions?.defaultNamespace ??\n\t\t\t\t\t\"main\");\n\tconst logicalId =\n\t\ttypeof metadata[RESERVED_METADATA_KEYS.logicalId] === \"string\" ? String(metadata[RESERVED_METADATA_KEYS.logicalId]) : String(match.id ?? \"\");\n\tconst userMetadata = Object.fromEntries(Object.entries(metadata).filter(([key]) => !key.startsWith(RESERVED_METADATA_PREFIX)));\n\treturn {\n\t\tlogicalId,\n\t\tvectorId: String(match.id ?? logicalId),\n\t\tnamespace,\n\t\ttitle: typeof metadata[RESERVED_METADATA_KEYS.title] === \"string\" ? String(metadata[RESERVED_METADATA_KEYS.title]) : undefined,\n\t\ttext: typeof metadata[RESERVED_METADATA_KEYS.text] === \"string\" ? String(metadata[RESERVED_METADATA_KEYS.text]) : undefined,\n\t\tmetadata: userMetadata,\n\t\tsource: typeof metadata[RESERVED_METADATA_KEYS.source] === \"string\" ? String(metadata[RESERVED_METADATA_KEYS.source]) : undefined,\n\t\tcreatedAt: typeof metadata[RESERVED_METADATA_KEYS.createdAt] === \"string\" ? String(metadata[RESERVED_METADATA_KEYS.createdAt]) : undefined,\n\t\tupdatedAt: typeof metadata[RESERVED_METADATA_KEYS.updatedAt] === \"string\" ? String(metadata[RESERVED_METADATA_KEYS.updatedAt]) : undefined,\n\t\tpath: buildVirtualPath(namespace, logicalId),\n\t};\n}\n"],"mappings":";;;;;AAcA,SAAS,EAAoB,GAAqB;CACjD,IAAM,IAAY,EAAI,MAAM,CAAC,QAAQ,UAAU,IAAI,CAAC,QAAQ,QAAQ,IAAI;AAOxE,QANK,IAGD,EAAU,WAAA,MAAoC,GAC1C,QAAQ,MAET,IALC;;AAQT,SAAS,EAAiB,GAAoF;AAC7G,KAAI,CAAC,EACJ,QAAO,EAAE;CAEV,IAAM,IAAU,OAAO,QAAQ,EAAS,CAAC,QAAQ,GAAG,OAAW;EAAC;EAAU;EAAU;EAAU,CAAC,SAAS,OAAO,EAAM,CAAC;AACtH,QAAO,OAAO,YAAY,EAAQ,KAAK,CAAC,GAAK,OAAW,CAAC,EAAoB,EAAI,EAAE,EAAM,CAAC,CAAC;;AAG5F,SAAgB,EAAc,GAAmB,GAA2B;CAC3E,IAAM,IAAQ,GAAG,EAAU,IAAI;AAI/B,QAHI,EAAO,WAAW,GAAO,OAAO,IAAI,KAChC,IAED,OAAO,EAAW,SAAS,CAAC,OAAO,EAAM,CAAC,OAAO,MAAM,CAAC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AO,EAAM,MAAM,GAAG,EACvI,IAAe,OAAO,YAAY,OAAO,QAAQ,EAAS,CAAC,QAAQ,CAAC,OAAS,CAAC,EAAI,WAAA,MAAoC,CAAC,CAAC;AAC9H,QAAO;EACN;EACA,UAAU,OAAO,EAAM,MAAM,EAAU;EACvC;EACA,OAAO,OAAO,EAAS,EAAuB,UAAW,WAAW,OAAO,EAAS,EAAuB,OAAO,GAAG,KAAA;EACrH,MAAM,OAAO,EAAS,EAAuB,SAAU,WAAW,OAAO,EAAS,EAAuB,MAAM,GAAG,KAAA;EAClH,UAAU;EACV,QAAQ,OAAO,EAAS,EAAuB,WAAY,WAAW,OAAO,EAAS,EAAuB,QAAQ,GAAG,KAAA;EACxH,WAAW,OAAO,EAAS,EAAuB,cAAe,WAAW,OAAO,EAAS,EAAuB,WAAW,GAAG,KAAA;EACjI,WAAW,OAAO,EAAS,EAAuB,cAAe,WAAW,OAAO,EAAS,EAAuB,WAAW,GAAG,KAAA;EACjI,MAAM,EAAiB,GAAW,EAAU;EAC5C"}
@@ -1,10 +1,30 @@
1
- import { resolvePluginConfig as e } from "./config.js";
2
- import { CloudflareMemoryService as t } from "./service.js";
1
+ import { getPluginConfigFromOpenClawConfig as e, normalizePluginConfigInput as t, resolvePluginConfig as n } from "./config.js";
2
+ import { CloudflareMemoryService as r } from "./service.js";
3
3
  //#region src/service-factory.ts
4
- async function n(n) {
5
- return new t(await e(n), n.openClawConfig);
4
+ function i(e) {
5
+ return e.cloudflare !== void 0 || e.vectorize !== void 0 || e.embeddings !== void 0 || e.storage !== void 0;
6
+ }
7
+ function a(n) {
8
+ let r = e(n.openClawConfig);
9
+ return i(r) ? r : t(n.pluginConfig);
10
+ }
11
+ async function o(e) {
12
+ return {
13
+ ...await n({
14
+ pluginConfig: a(e),
15
+ openClawConfig: e.openClawConfig,
16
+ env: e.env,
17
+ resolvePath: e.resolvePath
18
+ }),
19
+ ...e.overrides?.apiToken === void 0 ? {} : { apiToken: e.overrides.apiToken },
20
+ ...e.overrides?.workersAiBaseUrl === void 0 ? {} : { workersAiBaseUrl: e.overrides.workersAiBaseUrl },
21
+ ...e.overrides?.model === void 0 ? {} : { model: e.overrides.model }
22
+ };
23
+ }
24
+ async function s(e) {
25
+ return new r(await o(e), e.openClawConfig);
6
26
  }
7
27
  //#endregion
8
- export { n as createCloudflareMemoryService };
28
+ export { s as createCloudflareMemoryService, o as resolveCloudflareMemoryServiceConfig };
9
29
 
10
30
  //# sourceMappingURL=service-factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"service-factory.js","names":[],"sources":["../src/service-factory.ts"],"sourcesContent":["import type { OpenClawConfig } from \"openclaw/plugin-sdk/config-runtime\";\nimport { resolvePluginConfig } from \"./config.js\";\nimport { CloudflareMemoryService } from \"./service.js\";\n\nexport async function createCloudflareMemoryService(params: {\n\tpluginConfig: unknown;\n\topenClawConfig: OpenClawConfig;\n\tenv?: NodeJS.ProcessEnv;\n\tresolvePath?: (input: string) => string;\n}): Promise<CloudflareMemoryService> {\n\tconst resolved = await resolvePluginConfig(params);\n\treturn new CloudflareMemoryService(resolved, params.openClawConfig);\n}\n"],"mappings":";;;AAIA,eAAsB,EAA8B,GAKf;AAEpC,QAAO,IAAI,EADM,MAAM,EAAoB,EAAO,EACL,EAAO,eAAe"}
1
+ {"version":3,"file":"service-factory.js","names":[],"sources":["../src/service-factory.ts"],"sourcesContent":["import type { OpenClawConfig } from \"openclaw/plugin-sdk/config-runtime\";\nimport { getPluginConfigFromOpenClawConfig, normalizePluginConfigInput, resolvePluginConfig } from \"./config.js\";\nimport { CloudflareMemoryService } from \"./service.js\";\nimport type { RawPluginConfig, ResolvedPluginConfig } from \"./types.js\";\n\ntype ServiceConfigOverrides = Partial<Pick<ResolvedPluginConfig, \"apiToken\" | \"workersAiBaseUrl\" | \"model\">>;\n\nfunction hasConfiguredPluginValues(config: RawPluginConfig): boolean {\n\treturn config.cloudflare !== undefined || config.vectorize !== undefined || config.embeddings !== undefined || config.storage !== undefined;\n}\n\nfunction resolveServicePluginConfig(params: { pluginConfig?: unknown; openClawConfig: OpenClawConfig }): RawPluginConfig {\n\tconst configuredFromOpenClaw = getPluginConfigFromOpenClawConfig(params.openClawConfig);\n\tif (hasConfiguredPluginValues(configuredFromOpenClaw)) {\n\t\treturn configuredFromOpenClaw;\n\t}\n\treturn normalizePluginConfigInput(params.pluginConfig);\n}\n\nexport async function resolveCloudflareMemoryServiceConfig(params: {\n\tpluginConfig?: unknown;\n\topenClawConfig: OpenClawConfig;\n\tenv?: NodeJS.ProcessEnv;\n\tresolvePath?: (input: string) => string;\n\toverrides?: ServiceConfigOverrides;\n}): Promise<ResolvedPluginConfig> {\n\tconst resolved = await resolvePluginConfig({\n\t\tpluginConfig: resolveServicePluginConfig(params),\n\t\topenClawConfig: params.openClawConfig,\n\t\tenv: params.env,\n\t\tresolvePath: params.resolvePath,\n\t});\n\n\treturn {\n\t\t...resolved,\n\t\t...(params.overrides?.apiToken !== undefined ? { apiToken: params.overrides.apiToken } : {}),\n\t\t...(params.overrides?.workersAiBaseUrl !== undefined ? { workersAiBaseUrl: params.overrides.workersAiBaseUrl } : {}),\n\t\t...(params.overrides?.model !== undefined ? { model: params.overrides.model } : {}),\n\t};\n}\n\nexport async function createCloudflareMemoryService(params: {\n\tpluginConfig?: unknown;\n\topenClawConfig: OpenClawConfig;\n\tenv?: NodeJS.ProcessEnv;\n\tresolvePath?: (input: string) => string;\n\toverrides?: ServiceConfigOverrides;\n}): Promise<CloudflareMemoryService> {\n\tconst resolved = await resolveCloudflareMemoryServiceConfig(params);\n\treturn new CloudflareMemoryService(resolved, params.openClawConfig);\n}\n"],"mappings":";;;AAOA,SAAS,EAA0B,GAAkC;AACpE,QAAO,EAAO,eAAe,KAAA,KAAa,EAAO,cAAc,KAAA,KAAa,EAAO,eAAe,KAAA,KAAa,EAAO,YAAY,KAAA;;AAGnI,SAAS,EAA2B,GAAqF;CACxH,IAAM,IAAyB,EAAkC,EAAO,eAAe;AAIvF,QAHI,EAA0B,EAAuB,GAC7C,IAED,EAA2B,EAAO,aAAa;;AAGvD,eAAsB,EAAqC,GAMzB;AAQjC,QAAO;EACN,GARgB,MAAM,EAAoB;GAC1C,cAAc,EAA2B,EAAO;GAChD,gBAAgB,EAAO;GACvB,KAAK,EAAO;GACZ,aAAa,EAAO;GACpB,CAAC;EAID,GAAI,EAAO,WAAW,aAAa,KAAA,IAAsD,EAAE,GAA5C,EAAE,UAAU,EAAO,UAAU,UAAU;EACtF,GAAI,EAAO,WAAW,qBAAqB,KAAA,IAAsE,EAAE,GAA5D,EAAE,kBAAkB,EAAO,UAAU,kBAAkB;EAC9G,GAAI,EAAO,WAAW,UAAU,KAAA,IAAgD,EAAE,GAAtC,EAAE,OAAO,EAAO,UAAU,OAAO;EAC7E;;AAGF,eAAsB,EAA8B,GAMf;AAEpC,QAAO,IAAI,EADM,MAAM,EAAqC,EAAO,EACtB,EAAO,eAAe"}
package/dist/service.js CHANGED
@@ -30,21 +30,21 @@ var d = 3e4, f = 1e3, p = class {
30
30
  filter: e.filter
31
31
  });
32
32
  return (await Promise.all(r.map(async (e) => {
33
- let t = s(e), n = t.text ?? (await this.companionStore.get(t.namespace, t.logicalId))?.text ?? "";
33
+ let n = s(e, { defaultNamespace: t }), r = n.text ?? (await this.companionStore.get(n.namespace, n.logicalId))?.text ?? "";
34
34
  return {
35
- ...t,
36
- text: n,
35
+ ...n,
36
+ text: r,
37
37
  score: e.score ?? 0
38
38
  };
39
39
  }))).filter((t) => t.score >= (e.minScore ?? this.config.minScore));
40
40
  }
41
41
  async get(e) {
42
- let t = o(this.resolveNamespace(e), e.id), [n] = await this.vectorize.getByIds([t]);
43
- if (!n) return null;
44
- let r = s(n), i = await this.companionStore.get(r.namespace, r.logicalId);
42
+ let t = this.resolveNamespace(e), n = o(t, e.id), [r] = await this.vectorize.getByIds([n]);
43
+ if (!r) return null;
44
+ let i = s(r, { defaultNamespace: t }), a = await this.companionStore.get(i.namespace, i.logicalId);
45
45
  return {
46
- ...r,
47
- text: r.text ?? i?.text ?? ""
46
+ ...i,
47
+ text: i.text ?? a?.text ?? ""
48
48
  };
49
49
  }
50
50
  async upsert(e) {
@@ -229,7 +229,18 @@ var d = 3e4, f = 1e3, p = class {
229
229
  status: "pass",
230
230
  message: `Inserted smoke-test record ${o} in namespace ${a}.`
231
231
  });
232
- let t = await this.waitForSearchHit({
232
+ let t = await this.waitForGetHit({
233
+ namespace: a,
234
+ logicalId: o,
235
+ timeoutMs: e?.timeoutMs ?? d,
236
+ pollIntervalMs: e?.pollIntervalMs ?? f
237
+ });
238
+ n.push({
239
+ name: "probe-get",
240
+ status: t?.namespace === a ? "pass" : "fail",
241
+ message: t ? t.namespace === a ? "Get-by-id returned the smoke-test record in the expected namespace." : `Get-by-id returned namespace ${t.namespace}, expected ${a}.` : `Get-by-id did not return the smoke-test record within ${(e?.timeoutMs ?? d) / 1e3} seconds.`
242
+ });
243
+ let r = await this.waitForSearchHit({
233
244
  query: s,
234
245
  namespace: a,
235
246
  logicalId: o,
@@ -238,8 +249,8 @@ var d = 3e4, f = 1e3, p = class {
238
249
  });
239
250
  n.push({
240
251
  name: "probe-search",
241
- status: t ? "pass" : "fail",
242
- message: t ? "Semantic search returned the smoke-test record." : `Semantic search did not return the smoke-test record within ${(e?.timeoutMs ?? d) / 1e3} seconds.`
252
+ status: r?.namespace === a ? "pass" : "fail",
253
+ message: r ? r.namespace === a ? "Semantic search returned the smoke-test record in the expected namespace." : `Semantic search returned namespace ${r.namespace}, expected ${a}.` : `Semantic search did not return the smoke-test record within ${(e?.timeoutMs ?? d) / 1e3} seconds.`
243
254
  });
244
255
  } catch (e) {
245
256
  n.push({
@@ -308,19 +319,42 @@ var d = 3e4, f = 1e3, p = class {
308
319
  text: t.text ?? ""
309
320
  };
310
321
  }
311
- async waitForSearchHit(e) {
322
+ async waitForGetHit(e) {
312
323
  let t = Date.now() + e.timeoutMs;
313
324
  for (; Date.now() <= t;) {
314
- if ((await this.search({
315
- query: e.query,
316
- namespace: e.namespace,
317
- maxResults: 5,
318
- minScore: 0
319
- })).some((t) => t.logicalId === e.logicalId)) return !0;
325
+ let n = await this.get({
326
+ id: e.logicalId,
327
+ namespace: e.namespace
328
+ });
329
+ if (n) return n;
320
330
  if (Date.now() + e.pollIntervalMs > t) break;
321
331
  await this.pause(e.pollIntervalMs);
322
332
  }
323
- return !1;
333
+ return null;
334
+ }
335
+ async waitForSearchHit(e) {
336
+ let t = await this.embeddings.embedQuery(e.query), n = Date.now() + e.timeoutMs;
337
+ for (; Date.now() <= n;) {
338
+ let r = await this.vectorize.query({
339
+ vector: t,
340
+ namespace: e.namespace,
341
+ topK: 5
342
+ });
343
+ for (let t of r) {
344
+ let n = s(t, { defaultNamespace: e.namespace });
345
+ if (n.logicalId === e.logicalId) {
346
+ let e = n.text ?? (await this.companionStore.get(n.namespace, n.logicalId))?.text ?? "";
347
+ return {
348
+ ...n,
349
+ text: e,
350
+ score: t.score ?? 0
351
+ };
352
+ }
353
+ }
354
+ if (Date.now() + e.pollIntervalMs > n) break;
355
+ await this.pause(e.pollIntervalMs);
356
+ }
357
+ return null;
324
358
  }
325
359
  async pause(e) {
326
360
  await new Promise((t) => setTimeout(t, e));
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","names":[],"sources":["../src/service.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\r\nimport type { OpenClawConfig } from \"openclaw/plugin-sdk/config-runtime\";\r\nimport { isCloudflareNotFoundError } from \"./cloudflare-api.js\";\r\nimport { CompanionStore } from \"./companion-store.js\";\r\nimport { runDoctor } from \"./doctor.js\";\r\nimport { WorkersAiEmbeddingsClient } from \"./embeddings-client.js\";\r\nimport { sanitizeNamespace, resolveDefaultNamespace } from \"./namespace.js\";\r\nimport { buildVectorId, hydrateInlineRecord, mapRecordForUpsert } from \"./record-mapper.js\";\r\nimport type {\r\n\tCompanionRecord,\r\n\tDoctorCheck,\r\n\tDoctorReport,\r\n\tEmbeddingDimensionsInspection,\r\n\tHydratedMemoryRecord,\r\n\tIndexInitializationReport,\r\n\tMemoryRecordInput,\r\n\tMetadataFilter,\r\n\tResolvedPluginConfig,\r\n\tSmokeTestReport,\r\n\tUpsertedMemoryRecord,\r\n\tVectorizeIndexDescription,\r\n} from \"./types.js\";\r\nimport { VectorizeClient } from \"./vectorize-client.js\";\r\n\r\nconst SMOKE_TEST_TIMEOUT_MS = 30_000;\r\nconst SMOKE_TEST_POLL_INTERVAL_MS = 1_000;\r\n\r\nexport class CloudflareMemoryService {\r\n\treadonly embeddings: WorkersAiEmbeddingsClient;\r\n\treadonly vectorize: VectorizeClient;\r\n\treadonly companionStore: CompanionStore;\r\n\r\n\tconstructor(\r\n\t\treadonly config: ResolvedPluginConfig,\r\n\t\treadonly openClawConfig: OpenClawConfig,\r\n\t) {\r\n\t\tthis.embeddings = new WorkersAiEmbeddingsClient(config);\r\n\t\tthis.vectorize = new VectorizeClient(config);\r\n\t\tthis.companionStore = new CompanionStore(config.companionStorePath);\r\n\t}\r\n\r\n\tresolveNamespace(params: { namespace?: string; sessionKey?: string; agentId?: string; workspaceDir?: string }): string {\r\n\t\treturn resolveDefaultNamespace({\r\n\t\t\tfixedNamespace: params.namespace ?? this.config.fixedNamespace,\r\n\t\t\tsessionKey: params.sessionKey,\r\n\t\t\tagentId: params.agentId,\r\n\t\t\tworkspaceDir: params.workspaceDir,\r\n\t\t});\r\n\t}\r\n\r\n\tasync search(params: {\r\n\t\tquery: string;\r\n\t\tnamespace?: string;\r\n\t\tmaxResults?: number;\r\n\t\tminScore?: number;\r\n\t\tfilter?: MetadataFilter;\r\n\t\tsessionKey?: string;\r\n\t\tagentId?: string;\r\n\t\tworkspaceDir?: string;\r\n\t}): Promise<Array<HydratedMemoryRecord & { score: number }>> {\r\n\t\tconst namespace = this.resolveNamespace(params);\r\n\t\tconst vector = await this.embeddings.embedQuery(params.query);\r\n\t\tconst matches = await this.vectorize.query({\r\n\t\t\tvector,\r\n\t\t\tnamespace,\r\n\t\t\ttopK: params.maxResults ?? this.config.topK,\r\n\t\t\tfilter: params.filter,\r\n\t\t});\r\n\r\n\t\tconst hydrated = await Promise.all(\r\n\t\t\tmatches.map(async (match) => {\r\n\t\t\t\tconst base = hydrateInlineRecord(match);\r\n\t\t\t\tconst text = base.text ?? (await this.companionStore.get(base.namespace, base.logicalId))?.text ?? \"\";\r\n\t\t\t\treturn {\r\n\t\t\t\t\t...base,\r\n\t\t\t\t\ttext,\r\n\t\t\t\t\tscore: match.score ?? 0,\r\n\t\t\t\t};\r\n\t\t\t}),\r\n\t\t);\r\n\r\n\t\treturn hydrated.filter((record) => record.score >= (params.minScore ?? this.config.minScore));\r\n\t}\r\n\r\n\tasync get(params: { id: string; namespace?: string; sessionKey?: string; agentId?: string; workspaceDir?: string }): Promise<HydratedMemoryRecord | null> {\r\n\t\tconst namespace = this.resolveNamespace(params);\r\n\t\tconst vectorId = buildVectorId(namespace, params.id);\r\n\t\tconst [match] = await this.vectorize.getByIds([vectorId]);\r\n\t\tif (!match) {\r\n\t\t\treturn null;\r\n\t\t}\r\n\t\tconst base = hydrateInlineRecord(match);\r\n\t\tconst companion = await this.companionStore.get(base.namespace, base.logicalId);\r\n\t\treturn {\r\n\t\t\t...base,\r\n\t\t\ttext: base.text ?? companion?.text ?? \"\",\r\n\t\t};\r\n\t}\r\n\r\n\tasync upsert(params: { input: MemoryRecordInput; sessionKey?: string; agentId?: string; workspaceDir?: string }): Promise<UpsertedMemoryRecord> {\r\n\t\tconst namespace = this.resolveNamespace({\r\n\t\t\tnamespace: params.input.namespace,\r\n\t\t\tsessionKey: params.sessionKey,\r\n\t\t\tagentId: params.agentId,\r\n\t\t\tworkspaceDir: params.workspaceDir,\r\n\t\t});\r\n\t\tconst embedding = await this.embeddings.embedQuery(params.input.text);\r\n\t\tconst mapped = mapRecordForUpsert({\r\n\t\t\tinput: params.input,\r\n\t\t\tnamespace,\r\n\t\t\tembedding,\r\n\t\t\tconfig: this.config,\r\n\t\t});\r\n\r\n\t\tif (mapped.companionRecord) {\r\n\t\t\tawait this.companionStore.upsert(mapped.companionRecord);\r\n\t\t}\r\n\r\n\t\tconst mutationId = await this.vectorize.upsert([mapped.vector]);\r\n\t\tconst hydrated = await this.get({\r\n\t\t\tid: mapped.logicalId,\r\n\t\t\tnamespace,\r\n\t\t});\r\n\t\tconst fallback =\r\n\t\t\tmapped.companionRecord === undefined\r\n\t\t\t\t? this.fromInlineFallback(mapped.vector)\r\n\t\t\t\t: this.fromCompanionFallback(mapped.companionRecord, mapped.logicalId, namespace, mapped.path);\r\n\t\tconst resolved = hydrated\r\n\t\t\t? {\r\n\t\t\t\t\t...fallback,\r\n\t\t\t\t\t...hydrated,\r\n\t\t\t\t\ttitle: hydrated.title ?? fallback.title,\r\n\t\t\t\t\ttext: hydrated.text || fallback.text,\r\n\t\t\t\t\tmetadata: Object.keys(hydrated.metadata).length > 0 ? hydrated.metadata : fallback.metadata,\r\n\t\t\t\t\tsource: hydrated.source ?? fallback.source,\r\n\t\t\t\t\tcreatedAt: hydrated.createdAt ?? fallback.createdAt,\r\n\t\t\t\t\tupdatedAt: hydrated.updatedAt ?? fallback.updatedAt,\r\n\t\t\t }\r\n\t\t\t: fallback;\r\n\r\n\t\treturn {\r\n\t\t\t...resolved,\r\n\t\t\tmutationId,\r\n\t\t};\r\n\t}\r\n\r\n\tasync delete(params: { id: string; namespace?: string; sessionKey?: string; agentId?: string; workspaceDir?: string }): Promise<string | undefined> {\r\n\t\tconst namespace = this.resolveNamespace(params);\r\n\t\tawait this.companionStore.delete(namespace, params.id);\r\n\t\treturn this.vectorize.deleteByIds([buildVectorId(namespace, params.id)]);\r\n\t}\r\n\r\n\tasync doctor(options: { createIndexIfMissing?: boolean }): Promise<DoctorReport> {\r\n\t\treturn runDoctor({\r\n\t\t\tservice: this,\r\n\t\t\tcreateIndexIfMissing: options.createIndexIfMissing ?? false,\r\n\t\t});\r\n\t}\r\n\r\n\tasync inspectEmbeddingDimensions(): Promise<EmbeddingDimensionsInspection> {\r\n\t\tconst embeddingDimensions = await this.embeddings.probeDimensions();\r\n\t\tconst configuredDimensions = this.config.createIndex.dimensions;\r\n\t\treturn {\r\n\t\t\tembeddingDimensions,\r\n\t\t\tconfiguredDimensions,\r\n\t\t\tconfiguredDimensionsMatchModel: configuredDimensions === undefined || configuredDimensions === embeddingDimensions,\r\n\t\t\ttargetDimensions: embeddingDimensions,\r\n\t\t};\r\n\t}\r\n\r\n\tasync describeIndexIfExists(): Promise<VectorizeIndexDescription | null> {\r\n\t\ttry {\r\n\t\t\treturn await this.vectorize.describeIndex();\r\n\t\t} catch (error) {\r\n\t\t\tif (isCloudflareNotFoundError(error)) {\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\t\t\tthrow error;\r\n\t\t}\r\n\t}\r\n\r\n\tasync initializeIndex(options?: { recreateIfDimensionMismatch?: boolean }): Promise<IndexInitializationReport> {\r\n\t\tconst recreateIfDimensionMismatch = options?.recreateIfDimensionMismatch ?? true;\r\n\t\tconst checks: DoctorCheck[] = [];\r\n\t\tchecks.push({\r\n\t\t\tname: \"credentials\",\r\n\t\t\tstatus: \"pass\",\r\n\t\t\tmessage: `Using Cloudflare account ${this.config.accountId} and Vectorize index ${this.config.indexName}.`,\r\n\t\t});\r\n\r\n\t\tconst embedding = await this.inspectEmbeddingDimensions();\r\n\t\tchecks.push({\r\n\t\t\tname: \"workers-ai-embeddings\",\r\n\t\t\tstatus: \"pass\",\r\n\t\t\tmessage: `Workers AI model ${this.config.model} returned ${embedding.embeddingDimensions} dimensions.`,\r\n\t\t});\r\n\t\tif (embedding.configuredDimensions !== undefined) {\r\n\t\t\tchecks.push({\r\n\t\t\t\tname: \"create-index-dimensions\",\r\n\t\t\t\tstatus: embedding.configuredDimensionsMatchModel ? \"pass\" : \"warn\",\r\n\t\t\t\tmessage: embedding.configuredDimensionsMatchModel\r\n\t\t\t\t\t? `Configured createIndex.dimensions matches the embedding model (${embedding.embeddingDimensions}).`\r\n\t\t\t\t\t: `Configured createIndex.dimensions (${embedding.configuredDimensions}) does not match the embedding model (${embedding.embeddingDimensions}). Using the live embedding dimensions for initialization.`,\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tconst existingIndex = await this.describeIndexIfExists();\r\n\t\tlet created = false;\r\n\t\tlet recreated = false;\r\n\t\tlet indexDimensions = existingIndex?.config.dimensions;\r\n\r\n\t\tif (!existingIndex) {\r\n\t\t\tconst createdIndex = await this.vectorize.createIndex(embedding.targetDimensions);\r\n\t\t\tcreated = true;\r\n\t\t\tindexDimensions = createdIndex.config.dimensions;\r\n\t\t\tchecks.push({\r\n\t\t\t\tname: \"vectorize-index\",\r\n\t\t\t\tstatus: \"pass\",\r\n\t\t\t\tmessage: `Created Vectorize index \"${this.config.indexName}\" with ${indexDimensions} dimensions.`,\r\n\t\t\t});\r\n\t\t} else if (existingIndex.config.dimensions === embedding.targetDimensions) {\r\n\t\t\tchecks.push({\r\n\t\t\t\tname: \"vectorize-index\",\r\n\t\t\t\tstatus: \"pass\",\r\n\t\t\t\tmessage: `Vectorize index \"${this.config.indexName}\" already uses ${existingIndex.config.dimensions} dimensions.`,\r\n\t\t\t});\r\n\t\t} else if (!recreateIfDimensionMismatch) {\r\n\t\t\tchecks.push({\r\n\t\t\t\tname: \"vectorize-index\",\r\n\t\t\t\tstatus: \"fail\",\r\n\t\t\t\tmessage: `Vectorize index \"${this.config.indexName}\" uses ${existingIndex.config.dimensions} dimensions, but the embedding model requires ${embedding.targetDimensions}. Recreate the index or rerun init with recreation enabled.`,\r\n\t\t\t});\r\n\t\t} else {\r\n\t\t\tawait this.vectorize.deleteIndex();\r\n\t\t\tconst recreatedIndex = await this.vectorize.createIndex(embedding.targetDimensions);\r\n\t\t\trecreated = true;\r\n\t\t\tindexDimensions = recreatedIndex.config.dimensions;\r\n\t\t\tchecks.push({\r\n\t\t\t\tname: \"vectorize-index\",\r\n\t\t\t\tstatus: \"pass\",\r\n\t\t\t\tmessage: `Recreated Vectorize index \"${this.config.indexName}\" from ${existingIndex.config.dimensions} to ${indexDimensions} dimensions.`,\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tchecks.push({\r\n\t\t\tname: \"dimension-match\",\r\n\t\t\tstatus: indexDimensions === embedding.embeddingDimensions ? \"pass\" : \"fail\",\r\n\t\t\tmessage:\r\n\t\t\t\tindexDimensions === embedding.embeddingDimensions\r\n\t\t\t\t\t? \"Embedding dimensions match the Vectorize index.\"\r\n\t\t\t\t\t: `Embedding dimensions (${embedding.embeddingDimensions}) do not match the Vectorize index dimensions (${indexDimensions ?? \"unknown\"}).`,\r\n\t\t});\r\n\t\tchecks.push({\r\n\t\t\tname: \"metadata-filters\",\r\n\t\t\tstatus: this.config.metadataIndexedFields.length > 0 ? \"pass\" : \"warn\",\r\n\t\t\tmessage:\r\n\t\t\t\tthis.config.metadataIndexedFields.length > 0\r\n\t\t\t\t\t? `Configured metadata-index guidance for: ${this.config.metadataIndexedFields.join(\", \")}.`\r\n\t\t\t\t\t: \"No metadataIndexedFields configured. Add metadata indexes in Cloudflare before relying on filter-heavy queries.\",\r\n\t\t});\r\n\r\n\t\treturn {\r\n\t\t\tok: checks.every((check) => check.status !== \"fail\"),\r\n\t\t\tchecks,\r\n\t\t\tcreated,\r\n\t\t\trecreated,\r\n\t\t\tembeddingDimensions: embedding.embeddingDimensions,\r\n\t\t\tindexDimensions,\r\n\t\t};\r\n\t}\r\n\r\n\tasync runSmokeTest(options?: { timeoutMs?: number; pollIntervalMs?: number }): Promise<SmokeTestReport> {\r\n\t\tconst checks: DoctorCheck[] = [];\r\n\t\tchecks.push({\r\n\t\t\tname: \"credentials\",\r\n\t\t\tstatus: \"pass\",\r\n\t\t\tmessage: `Using Cloudflare account ${this.config.accountId} and Vectorize index ${this.config.indexName}.`,\r\n\t\t});\r\n\r\n\t\tconst embedding = await this.inspectEmbeddingDimensions();\r\n\t\tchecks.push({\r\n\t\t\tname: \"workers-ai-embeddings\",\r\n\t\t\tstatus: \"pass\",\r\n\t\t\tmessage: `Workers AI model ${this.config.model} returned ${embedding.embeddingDimensions} dimensions.`,\r\n\t\t});\r\n\t\tif (embedding.configuredDimensions !== undefined) {\r\n\t\t\tchecks.push({\r\n\t\t\t\tname: \"create-index-dimensions\",\r\n\t\t\t\tstatus: embedding.configuredDimensionsMatchModel ? \"pass\" : \"warn\",\r\n\t\t\t\tmessage: embedding.configuredDimensionsMatchModel\r\n\t\t\t\t\t? `Configured createIndex.dimensions matches the embedding model (${embedding.embeddingDimensions}).`\r\n\t\t\t\t\t: `Configured createIndex.dimensions (${embedding.configuredDimensions}) does not match the embedding model (${embedding.embeddingDimensions}). Using the live embedding dimensions for validation.`,\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tconst existingIndex = await this.describeIndexIfExists();\r\n\t\tif (!existingIndex) {\r\n\t\t\tchecks.push({\r\n\t\t\t\tname: \"vectorize-index\",\r\n\t\t\t\tstatus: \"fail\",\r\n\t\t\t\tmessage: `Vectorize index \"${this.config.indexName}\" was not found. Run \"openclaw cf-memory init\" before rerunning this test.`,\r\n\t\t\t});\r\n\t\t\treturn {\r\n\t\t\t\tok: false,\r\n\t\t\t\tchecks,\r\n\t\t\t\tnamespace: \"n/a\",\r\n\t\t\t\tlogicalId: \"n/a\",\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tchecks.push({\r\n\t\t\tname: \"vectorize-index\",\r\n\t\t\tstatus: \"pass\",\r\n\t\t\tmessage: `Vectorize index \"${this.config.indexName}\" is reachable.`,\r\n\t\t});\r\n\t\tif (existingIndex.config.dimensions !== embedding.embeddingDimensions) {\r\n\t\t\tchecks.push({\r\n\t\t\t\tname: \"dimension-match\",\r\n\t\t\t\tstatus: \"fail\",\r\n\t\t\t\tmessage: `Embedding dimensions (${embedding.embeddingDimensions}) do not match the Vectorize index dimensions (${existingIndex.config.dimensions}). Run \"openclaw cf-memory init\" to repair the index.`,\r\n\t\t\t});\r\n\t\t\treturn {\r\n\t\t\t\tok: false,\r\n\t\t\t\tchecks,\r\n\t\t\t\tnamespace: \"n/a\",\r\n\t\t\t\tlogicalId: \"n/a\",\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tchecks.push({\r\n\t\t\tname: \"dimension-match\",\r\n\t\t\tstatus: \"pass\",\r\n\t\t\tmessage: \"Embedding dimensions match the Vectorize index.\",\r\n\t\t});\r\n\r\n\t\tconst namespace = sanitizeNamespace(`cf-memory-test-${randomUUID()}`);\r\n\t\tconst logicalId = `cf-memory-test-${randomUUID()}`;\r\n\t\tconst probeText = `OpenClaw Cloudflare memory smoke test ${logicalId}`;\r\n\t\tlet probeUpserted = false;\r\n\r\n\t\ttry {\r\n\t\t\tawait this.upsert({\r\n\t\t\t\tinput: {\r\n\t\t\t\t\tid: logicalId,\r\n\t\t\t\t\tnamespace,\r\n\t\t\t\t\ttext: probeText,\r\n\t\t\t\t\tsource: \"cf-memory-test\",\r\n\t\t\t\t\tmetadata: {\r\n\t\t\t\t\t\tprobe: true,\r\n\t\t\t\t\t\tprobeId: logicalId,\r\n\t\t\t\t\t},\r\n\t\t\t\t},\r\n\t\t\t});\r\n\t\t\tprobeUpserted = true;\r\n\t\t\tchecks.push({\r\n\t\t\t\tname: \"probe-upsert\",\r\n\t\t\t\tstatus: \"pass\",\r\n\t\t\t\tmessage: `Inserted smoke-test record ${logicalId} in namespace ${namespace}.`,\r\n\t\t\t});\r\n\r\n\t\t\tconst found = await this.waitForSearchHit({\r\n\t\t\t\tquery: probeText,\r\n\t\t\t\tnamespace,\r\n\t\t\t\tlogicalId,\r\n\t\t\t\ttimeoutMs: options?.timeoutMs ?? SMOKE_TEST_TIMEOUT_MS,\r\n\t\t\t\tpollIntervalMs: options?.pollIntervalMs ?? SMOKE_TEST_POLL_INTERVAL_MS,\r\n\t\t\t});\r\n\t\t\tchecks.push({\r\n\t\t\t\tname: \"probe-search\",\r\n\t\t\t\tstatus: found ? \"pass\" : \"fail\",\r\n\t\t\t\tmessage: found\r\n\t\t\t\t\t? \"Semantic search returned the smoke-test record.\"\r\n\t\t\t\t\t: `Semantic search did not return the smoke-test record within ${(options?.timeoutMs ?? SMOKE_TEST_TIMEOUT_MS) / 1000} seconds.`,\r\n\t\t\t});\r\n\t\t} catch (error) {\r\n\t\t\tchecks.push({\r\n\t\t\t\tname: probeUpserted ? \"probe-search\" : \"probe-upsert\",\r\n\t\t\t\tstatus: \"fail\",\r\n\t\t\t\tmessage: error instanceof Error ? error.message : \"Smoke test failed with an unknown error.\",\r\n\t\t\t});\r\n\t\t} finally {\r\n\t\t\ttry {\r\n\t\t\t\tawait this.delete({ id: logicalId, namespace });\r\n\t\t\t\tchecks.push({\r\n\t\t\t\t\tname: \"probe-cleanup\",\r\n\t\t\t\t\tstatus: \"pass\",\r\n\t\t\t\t\tmessage: `Deleted smoke-test record ${logicalId}.`,\r\n\t\t\t\t});\r\n\t\t\t} catch (error) {\r\n\t\t\t\tchecks.push({\r\n\t\t\t\t\tname: \"probe-cleanup\",\r\n\t\t\t\t\tstatus: \"fail\",\r\n\t\t\t\t\tmessage: error instanceof Error ? error.message : `Failed to delete smoke-test record ${logicalId}.`,\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn {\r\n\t\t\tok: checks.every((check) => check.status !== \"fail\"),\r\n\t\t\tchecks,\r\n\t\t\tnamespace,\r\n\t\t\tlogicalId,\r\n\t\t};\r\n\t}\r\n\r\n\tasync ensureIndexExists(createIfMissing: boolean, targetDimensions?: number): Promise<{ created: boolean; dimensions: number }> {\r\n\t\ttry {\r\n\t\t\tconst description = await this.vectorize.describeIndex();\r\n\t\t\treturn {\r\n\t\t\t\tcreated: false,\r\n\t\t\t\tdimensions: description.config.dimensions,\r\n\t\t\t};\r\n\t\t} catch (error) {\r\n\t\t\tif (!createIfMissing || !isCloudflareNotFoundError(error)) {\r\n\t\t\t\tthrow error;\r\n\t\t\t}\r\n\t\t\tconst dimensions = targetDimensions ?? (await this.inspectEmbeddingDimensions()).targetDimensions;\r\n\t\t\tconst createdIndex = await this.vectorize.createIndex(dimensions);\r\n\t\t\treturn {\r\n\t\t\t\tcreated: true,\r\n\t\t\t\tdimensions: createdIndex.config.dimensions,\r\n\t\t\t};\r\n\t\t}\r\n\t}\r\n\r\n\tprivate fromCompanionFallback(companionRecord: CompanionRecord | undefined, logicalId: string, namespace: string, path: string): UpsertedMemoryRecord {\r\n\t\treturn {\r\n\t\t\tlogicalId,\r\n\t\t\tvectorId: buildVectorId(namespace, logicalId),\r\n\t\t\tnamespace,\r\n\t\t\ttitle: companionRecord?.title,\r\n\t\t\ttext: companionRecord?.text ?? \"\",\r\n\t\t\tmetadata: companionRecord?.metadata ?? {},\r\n\t\t\tsource: companionRecord?.source,\r\n\t\t\tcreatedAt: companionRecord?.createdAt,\r\n\t\t\tupdatedAt: companionRecord?.updatedAt,\r\n\t\t\tpath,\r\n\t\t};\r\n\t}\r\n\r\n\tprivate fromInlineFallback(vector: { id: string; namespace?: string; metadata?: Record<string, string | number | boolean> }): UpsertedMemoryRecord {\r\n\t\tconst record = hydrateInlineRecord(vector);\r\n\t\treturn {\r\n\t\t\t...record,\r\n\t\t\ttext: record.text ?? \"\",\r\n\t\t};\r\n\t}\r\n\r\n\tprivate async waitForSearchHit(params: { query: string; namespace: string; logicalId: string; timeoutMs: number; pollIntervalMs: number }): Promise<boolean> {\r\n\t\tconst deadline = Date.now() + params.timeoutMs;\r\n\t\twhile (Date.now() <= deadline) {\r\n\t\t\tconst results = await this.search({\r\n\t\t\t\tquery: params.query,\r\n\t\t\t\tnamespace: params.namespace,\r\n\t\t\t\tmaxResults: 5,\r\n\t\t\t\tminScore: 0,\r\n\t\t\t});\r\n\t\t\tif (results.some((record) => record.logicalId === params.logicalId)) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t\tif (Date.now() + params.pollIntervalMs > deadline) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tawait this.pause(params.pollIntervalMs);\r\n\t\t}\r\n\t\treturn false;\r\n\t}\r\n\r\n\tprivate async pause(ms: number): Promise<void> {\r\n\t\tawait new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,EAAE;GACzC,QAAQ,GAAiB;GACzB,WAAW,GAAiB;GAC5B,WAAW,GAAiB;GAC5B;GACA;;CAGF,mBAA2B,GAAwH;EAClJ,IAAM,IAAS,EAAoB,EAAO;AAC1C,SAAO;GACN,GAAG;GACH,MAAM,EAAO,QAAQ;GACrB;;CAGF,MAAc,iBAAiB,GAA8H;EAC5J,IAAM,IAAW,KAAK,KAAK,GAAG,EAAO;AACrC,SAAO,KAAK,KAAK,IAAI,IAAU;AAO9B,QANgB,MAAM,KAAK,OAAO;IACjC,OAAO,EAAO;IACd,WAAW,EAAO;IAClB,YAAY;IACZ,UAAU;IACV,CAAC,EACU,MAAM,MAAW,EAAO,cAAc,EAAO,UAAU,CAClE,QAAO;AAER,OAAI,KAAK,KAAK,GAAG,EAAO,iBAAiB,EACxC;AAED,SAAM,KAAK,MAAM,EAAO,eAAe;;AAExC,SAAO;;CAGR,MAAc,MAAM,GAA2B;AAC9C,QAAM,IAAI,SAAS,MAAY,WAAW,GAAS,EAAG,CAAC"}
1
+ {"version":3,"file":"service.js","names":[],"sources":["../src/service.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { OpenClawConfig } from \"openclaw/plugin-sdk/config-runtime\";\nimport { isCloudflareNotFoundError } from \"./cloudflare-api.js\";\nimport { CompanionStore } from \"./companion-store.js\";\nimport { runDoctor } from \"./doctor.js\";\nimport { WorkersAiEmbeddingsClient } from \"./embeddings-client.js\";\nimport { sanitizeNamespace, resolveDefaultNamespace } from \"./namespace.js\";\nimport { buildVectorId, hydrateInlineRecord, mapRecordForUpsert } from \"./record-mapper.js\";\nimport type {\n\tCompanionRecord,\n\tDoctorCheck,\n\tDoctorReport,\n\tEmbeddingDimensionsInspection,\n\tHydratedMemoryRecord,\n\tIndexInitializationReport,\n\tMemoryRecordInput,\n\tMetadataFilter,\n\tResolvedPluginConfig,\n\tSmokeTestReport,\n\tUpsertedMemoryRecord,\n\tVectorizeIndexDescription,\n} from \"./types.js\";\nimport { VectorizeClient } from \"./vectorize-client.js\";\n\nconst SMOKE_TEST_TIMEOUT_MS = 30_000;\nconst SMOKE_TEST_POLL_INTERVAL_MS = 1_000;\n\nexport class CloudflareMemoryService {\n\treadonly embeddings: WorkersAiEmbeddingsClient;\n\treadonly vectorize: VectorizeClient;\n\treadonly companionStore: CompanionStore;\n\n\tconstructor(\n\t\treadonly config: ResolvedPluginConfig,\n\t\treadonly openClawConfig: OpenClawConfig,\n\t) {\n\t\tthis.embeddings = new WorkersAiEmbeddingsClient(config);\n\t\tthis.vectorize = new VectorizeClient(config);\n\t\tthis.companionStore = new CompanionStore(config.companionStorePath);\n\t}\n\n\tresolveNamespace(params: { namespace?: string; sessionKey?: string; agentId?: string; workspaceDir?: string }): string {\n\t\treturn resolveDefaultNamespace({\n\t\t\tfixedNamespace: params.namespace ?? this.config.fixedNamespace,\n\t\t\tsessionKey: params.sessionKey,\n\t\t\tagentId: params.agentId,\n\t\t\tworkspaceDir: params.workspaceDir,\n\t\t});\n\t}\n\n\tasync search(params: {\n\t\tquery: string;\n\t\tnamespace?: string;\n\t\tmaxResults?: number;\n\t\tminScore?: number;\n\t\tfilter?: MetadataFilter;\n\t\tsessionKey?: string;\n\t\tagentId?: string;\n\t\tworkspaceDir?: string;\n\t}): Promise<Array<HydratedMemoryRecord & { score: number }>> {\n\t\tconst namespace = this.resolveNamespace(params);\n\t\tconst vector = await this.embeddings.embedQuery(params.query);\n\t\tconst matches = await this.vectorize.query({\n\t\t\tvector,\n\t\t\tnamespace,\n\t\t\ttopK: params.maxResults ?? this.config.topK,\n\t\t\tfilter: params.filter,\n\t\t});\n\n\t\tconst hydrated = await Promise.all(\n\t\t\tmatches.map(async (match) => {\n\t\t\t\tconst base = hydrateInlineRecord(match, { defaultNamespace: namespace });\n\t\t\t\tconst text = base.text ?? (await this.companionStore.get(base.namespace, base.logicalId))?.text ?? \"\";\n\t\t\t\treturn {\n\t\t\t\t\t...base,\n\t\t\t\t\ttext,\n\t\t\t\t\tscore: match.score ?? 0,\n\t\t\t\t};\n\t\t\t}),\n\t\t);\n\n\t\treturn hydrated.filter((record) => record.score >= (params.minScore ?? this.config.minScore));\n\t}\n\n\tasync get(params: { id: string; namespace?: string; sessionKey?: string; agentId?: string; workspaceDir?: string }): Promise<HydratedMemoryRecord | null> {\n\t\tconst namespace = this.resolveNamespace(params);\n\t\tconst vectorId = buildVectorId(namespace, params.id);\n\t\tconst [match] = await this.vectorize.getByIds([vectorId]);\n\t\tif (!match) {\n\t\t\treturn null;\n\t\t}\n\t\tconst base = hydrateInlineRecord(match, { defaultNamespace: namespace });\n\t\tconst companion = await this.companionStore.get(base.namespace, base.logicalId);\n\t\treturn {\n\t\t\t...base,\n\t\t\ttext: base.text ?? companion?.text ?? \"\",\n\t\t};\n\t}\n\n\tasync upsert(params: { input: MemoryRecordInput; sessionKey?: string; agentId?: string; workspaceDir?: string }): Promise<UpsertedMemoryRecord> {\n\t\tconst namespace = this.resolveNamespace({\n\t\t\tnamespace: params.input.namespace,\n\t\t\tsessionKey: params.sessionKey,\n\t\t\tagentId: params.agentId,\n\t\t\tworkspaceDir: params.workspaceDir,\n\t\t});\n\t\tconst embedding = await this.embeddings.embedQuery(params.input.text);\n\t\tconst mapped = mapRecordForUpsert({\n\t\t\tinput: params.input,\n\t\t\tnamespace,\n\t\t\tembedding,\n\t\t\tconfig: this.config,\n\t\t});\n\n\t\tif (mapped.companionRecord) {\n\t\t\tawait this.companionStore.upsert(mapped.companionRecord);\n\t\t}\n\n\t\tconst mutationId = await this.vectorize.upsert([mapped.vector]);\n\t\tconst hydrated = await this.get({\n\t\t\tid: mapped.logicalId,\n\t\t\tnamespace,\n\t\t});\n\t\tconst fallback =\n\t\t\tmapped.companionRecord === undefined\n\t\t\t\t? this.fromInlineFallback(mapped.vector)\n\t\t\t\t: this.fromCompanionFallback(mapped.companionRecord, mapped.logicalId, namespace, mapped.path);\n\t\tconst resolved = hydrated\n\t\t\t? {\n\t\t\t\t\t...fallback,\n\t\t\t\t\t...hydrated,\n\t\t\t\t\ttitle: hydrated.title ?? fallback.title,\n\t\t\t\t\ttext: hydrated.text || fallback.text,\n\t\t\t\t\tmetadata: Object.keys(hydrated.metadata).length > 0 ? hydrated.metadata : fallback.metadata,\n\t\t\t\t\tsource: hydrated.source ?? fallback.source,\n\t\t\t\t\tcreatedAt: hydrated.createdAt ?? fallback.createdAt,\n\t\t\t\t\tupdatedAt: hydrated.updatedAt ?? fallback.updatedAt,\n\t\t\t\t}\n\t\t\t: fallback;\n\n\t\treturn {\n\t\t\t...resolved,\n\t\t\tmutationId,\n\t\t};\n\t}\n\n\tasync delete(params: { id: string; namespace?: string; sessionKey?: string; agentId?: string; workspaceDir?: string }): Promise<string | undefined> {\n\t\tconst namespace = this.resolveNamespace(params);\n\t\tawait this.companionStore.delete(namespace, params.id);\n\t\treturn this.vectorize.deleteByIds([buildVectorId(namespace, params.id)]);\n\t}\n\n\tasync doctor(options: { createIndexIfMissing?: boolean }): Promise<DoctorReport> {\n\t\treturn runDoctor({\n\t\t\tservice: this,\n\t\t\tcreateIndexIfMissing: options.createIndexIfMissing ?? false,\n\t\t});\n\t}\n\n\tasync inspectEmbeddingDimensions(): Promise<EmbeddingDimensionsInspection> {\n\t\tconst embeddingDimensions = await this.embeddings.probeDimensions();\n\t\tconst configuredDimensions = this.config.createIndex.dimensions;\n\t\treturn {\n\t\t\tembeddingDimensions,\n\t\t\tconfiguredDimensions,\n\t\t\tconfiguredDimensionsMatchModel: configuredDimensions === undefined || configuredDimensions === embeddingDimensions,\n\t\t\ttargetDimensions: embeddingDimensions,\n\t\t};\n\t}\n\n\tasync describeIndexIfExists(): Promise<VectorizeIndexDescription | null> {\n\t\ttry {\n\t\t\treturn await this.vectorize.describeIndex();\n\t\t} catch (error) {\n\t\t\tif (isCloudflareNotFoundError(error)) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync initializeIndex(options?: { recreateIfDimensionMismatch?: boolean }): Promise<IndexInitializationReport> {\n\t\tconst recreateIfDimensionMismatch = options?.recreateIfDimensionMismatch ?? true;\n\t\tconst checks: DoctorCheck[] = [];\n\t\tchecks.push({\n\t\t\tname: \"credentials\",\n\t\t\tstatus: \"pass\",\n\t\t\tmessage: `Using Cloudflare account ${this.config.accountId} and Vectorize index ${this.config.indexName}.`,\n\t\t});\n\n\t\tconst embedding = await this.inspectEmbeddingDimensions();\n\t\tchecks.push({\n\t\t\tname: \"workers-ai-embeddings\",\n\t\t\tstatus: \"pass\",\n\t\t\tmessage: `Workers AI model ${this.config.model} returned ${embedding.embeddingDimensions} dimensions.`,\n\t\t});\n\t\tif (embedding.configuredDimensions !== undefined) {\n\t\t\tchecks.push({\n\t\t\t\tname: \"create-index-dimensions\",\n\t\t\t\tstatus: embedding.configuredDimensionsMatchModel ? \"pass\" : \"warn\",\n\t\t\t\tmessage: embedding.configuredDimensionsMatchModel\n\t\t\t\t\t? `Configured createIndex.dimensions matches the embedding model (${embedding.embeddingDimensions}).`\n\t\t\t\t\t: `Configured createIndex.dimensions (${embedding.configuredDimensions}) does not match the embedding model (${embedding.embeddingDimensions}). Using the live embedding dimensions for initialization.`,\n\t\t\t});\n\t\t}\n\n\t\tconst existingIndex = await this.describeIndexIfExists();\n\t\tlet created = false;\n\t\tlet recreated = false;\n\t\tlet indexDimensions = existingIndex?.config.dimensions;\n\n\t\tif (!existingIndex) {\n\t\t\tconst createdIndex = await this.vectorize.createIndex(embedding.targetDimensions);\n\t\t\tcreated = true;\n\t\t\tindexDimensions = createdIndex.config.dimensions;\n\t\t\tchecks.push({\n\t\t\t\tname: \"vectorize-index\",\n\t\t\t\tstatus: \"pass\",\n\t\t\t\tmessage: `Created Vectorize index \"${this.config.indexName}\" with ${indexDimensions} dimensions.`,\n\t\t\t});\n\t\t} else if (existingIndex.config.dimensions === embedding.targetDimensions) {\n\t\t\tchecks.push({\n\t\t\t\tname: \"vectorize-index\",\n\t\t\t\tstatus: \"pass\",\n\t\t\t\tmessage: `Vectorize index \"${this.config.indexName}\" already uses ${existingIndex.config.dimensions} dimensions.`,\n\t\t\t});\n\t\t} else if (!recreateIfDimensionMismatch) {\n\t\t\tchecks.push({\n\t\t\t\tname: \"vectorize-index\",\n\t\t\t\tstatus: \"fail\",\n\t\t\t\tmessage: `Vectorize index \"${this.config.indexName}\" uses ${existingIndex.config.dimensions} dimensions, but the embedding model requires ${embedding.targetDimensions}. Recreate the index or rerun init with recreation enabled.`,\n\t\t\t});\n\t\t} else {\n\t\t\tawait this.vectorize.deleteIndex();\n\t\t\tconst recreatedIndex = await this.vectorize.createIndex(embedding.targetDimensions);\n\t\t\trecreated = true;\n\t\t\tindexDimensions = recreatedIndex.config.dimensions;\n\t\t\tchecks.push({\n\t\t\t\tname: \"vectorize-index\",\n\t\t\t\tstatus: \"pass\",\n\t\t\t\tmessage: `Recreated Vectorize index \"${this.config.indexName}\" from ${existingIndex.config.dimensions} to ${indexDimensions} dimensions.`,\n\t\t\t});\n\t\t}\n\n\t\tchecks.push({\n\t\t\tname: \"dimension-match\",\n\t\t\tstatus: indexDimensions === embedding.embeddingDimensions ? \"pass\" : \"fail\",\n\t\t\tmessage:\n\t\t\t\tindexDimensions === embedding.embeddingDimensions\n\t\t\t\t\t? \"Embedding dimensions match the Vectorize index.\"\n\t\t\t\t\t: `Embedding dimensions (${embedding.embeddingDimensions}) do not match the Vectorize index dimensions (${indexDimensions ?? \"unknown\"}).`,\n\t\t});\n\t\tchecks.push({\n\t\t\tname: \"metadata-filters\",\n\t\t\tstatus: this.config.metadataIndexedFields.length > 0 ? \"pass\" : \"warn\",\n\t\t\tmessage:\n\t\t\t\tthis.config.metadataIndexedFields.length > 0\n\t\t\t\t\t? `Configured metadata-index guidance for: ${this.config.metadataIndexedFields.join(\", \")}.`\n\t\t\t\t\t: \"No metadataIndexedFields configured. Add metadata indexes in Cloudflare before relying on filter-heavy queries.\",\n\t\t});\n\n\t\treturn {\n\t\t\tok: checks.every((check) => check.status !== \"fail\"),\n\t\t\tchecks,\n\t\t\tcreated,\n\t\t\trecreated,\n\t\t\tembeddingDimensions: embedding.embeddingDimensions,\n\t\t\tindexDimensions,\n\t\t};\n\t}\n\n\tasync runSmokeTest(options?: { timeoutMs?: number; pollIntervalMs?: number }): Promise<SmokeTestReport> {\n\t\tconst checks: DoctorCheck[] = [];\n\t\tchecks.push({\n\t\t\tname: \"credentials\",\n\t\t\tstatus: \"pass\",\n\t\t\tmessage: `Using Cloudflare account ${this.config.accountId} and Vectorize index ${this.config.indexName}.`,\n\t\t});\n\n\t\tconst embedding = await this.inspectEmbeddingDimensions();\n\t\tchecks.push({\n\t\t\tname: \"workers-ai-embeddings\",\n\t\t\tstatus: \"pass\",\n\t\t\tmessage: `Workers AI model ${this.config.model} returned ${embedding.embeddingDimensions} dimensions.`,\n\t\t});\n\t\tif (embedding.configuredDimensions !== undefined) {\n\t\t\tchecks.push({\n\t\t\t\tname: \"create-index-dimensions\",\n\t\t\t\tstatus: embedding.configuredDimensionsMatchModel ? \"pass\" : \"warn\",\n\t\t\t\tmessage: embedding.configuredDimensionsMatchModel\n\t\t\t\t\t? `Configured createIndex.dimensions matches the embedding model (${embedding.embeddingDimensions}).`\n\t\t\t\t\t: `Configured createIndex.dimensions (${embedding.configuredDimensions}) does not match the embedding model (${embedding.embeddingDimensions}). Using the live embedding dimensions for validation.`,\n\t\t\t});\n\t\t}\n\n\t\tconst existingIndex = await this.describeIndexIfExists();\n\t\tif (!existingIndex) {\n\t\t\tchecks.push({\n\t\t\t\tname: \"vectorize-index\",\n\t\t\t\tstatus: \"fail\",\n\t\t\t\tmessage: `Vectorize index \"${this.config.indexName}\" was not found. Run \"openclaw cf-memory init\" before rerunning this test.`,\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tchecks,\n\t\t\t\tnamespace: \"n/a\",\n\t\t\t\tlogicalId: \"n/a\",\n\t\t\t};\n\t\t}\n\n\t\tchecks.push({\n\t\t\tname: \"vectorize-index\",\n\t\t\tstatus: \"pass\",\n\t\t\tmessage: `Vectorize index \"${this.config.indexName}\" is reachable.`,\n\t\t});\n\t\tif (existingIndex.config.dimensions !== embedding.embeddingDimensions) {\n\t\t\tchecks.push({\n\t\t\t\tname: \"dimension-match\",\n\t\t\t\tstatus: \"fail\",\n\t\t\t\tmessage: `Embedding dimensions (${embedding.embeddingDimensions}) do not match the Vectorize index dimensions (${existingIndex.config.dimensions}). Run \"openclaw cf-memory init\" to repair the index.`,\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tchecks,\n\t\t\t\tnamespace: \"n/a\",\n\t\t\t\tlogicalId: \"n/a\",\n\t\t\t};\n\t\t}\n\n\t\tchecks.push({\n\t\t\tname: \"dimension-match\",\n\t\t\tstatus: \"pass\",\n\t\t\tmessage: \"Embedding dimensions match the Vectorize index.\",\n\t\t});\n\n\t\tconst namespace = sanitizeNamespace(`cf-memory-test-${randomUUID()}`);\n\t\tconst logicalId = `cf-memory-test-${randomUUID()}`;\n\t\tconst probeText = `OpenClaw Cloudflare memory smoke test ${logicalId}`;\n\t\tlet probeUpserted = false;\n\n\t\ttry {\n\t\t\tawait this.upsert({\n\t\t\t\tinput: {\n\t\t\t\t\tid: logicalId,\n\t\t\t\t\tnamespace,\n\t\t\t\t\ttext: probeText,\n\t\t\t\t\tsource: \"cf-memory-test\",\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tprobe: true,\n\t\t\t\t\t\tprobeId: logicalId,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\t\t\tprobeUpserted = true;\n\t\t\tchecks.push({\n\t\t\t\tname: \"probe-upsert\",\n\t\t\t\tstatus: \"pass\",\n\t\t\t\tmessage: `Inserted smoke-test record ${logicalId} in namespace ${namespace}.`,\n\t\t\t});\n\n\t\t\tconst fetched = await this.waitForGetHit({\n\t\t\t\tnamespace,\n\t\t\t\tlogicalId,\n\t\t\t\ttimeoutMs: options?.timeoutMs ?? SMOKE_TEST_TIMEOUT_MS,\n\t\t\t\tpollIntervalMs: options?.pollIntervalMs ?? SMOKE_TEST_POLL_INTERVAL_MS,\n\t\t\t});\n\t\t\tchecks.push({\n\t\t\t\tname: \"probe-get\",\n\t\t\t\tstatus: fetched?.namespace === namespace ? \"pass\" : \"fail\",\n\t\t\t\tmessage: !fetched\n\t\t\t\t\t? `Get-by-id did not return the smoke-test record within ${(options?.timeoutMs ?? SMOKE_TEST_TIMEOUT_MS) / 1000} seconds.`\n\t\t\t\t\t: fetched.namespace === namespace\n\t\t\t\t\t\t? \"Get-by-id returned the smoke-test record in the expected namespace.\"\n\t\t\t\t\t\t: `Get-by-id returned namespace ${fetched.namespace}, expected ${namespace}.`,\n\t\t\t});\n\n\t\t\tconst found = await this.waitForSearchHit({\n\t\t\t\tquery: probeText,\n\t\t\t\tnamespace,\n\t\t\t\tlogicalId,\n\t\t\t\ttimeoutMs: options?.timeoutMs ?? SMOKE_TEST_TIMEOUT_MS,\n\t\t\t\tpollIntervalMs: options?.pollIntervalMs ?? SMOKE_TEST_POLL_INTERVAL_MS,\n\t\t\t});\n\t\t\tchecks.push({\n\t\t\t\tname: \"probe-search\",\n\t\t\t\tstatus: found?.namespace === namespace ? \"pass\" : \"fail\",\n\t\t\t\tmessage: !found\n\t\t\t\t\t? `Semantic search did not return the smoke-test record within ${(options?.timeoutMs ?? SMOKE_TEST_TIMEOUT_MS) / 1000} seconds.`\n\t\t\t\t\t: found.namespace === namespace\n\t\t\t\t\t\t? \"Semantic search returned the smoke-test record in the expected namespace.\"\n\t\t\t\t\t\t: `Semantic search returned namespace ${found.namespace}, expected ${namespace}.`,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tchecks.push({\n\t\t\t\tname: probeUpserted ? \"probe-search\" : \"probe-upsert\",\n\t\t\t\tstatus: \"fail\",\n\t\t\t\tmessage: error instanceof Error ? error.message : \"Smoke test failed with an unknown error.\",\n\t\t\t});\n\t\t} finally {\n\t\t\ttry {\n\t\t\t\tawait this.delete({ id: logicalId, namespace });\n\t\t\t\tchecks.push({\n\t\t\t\t\tname: \"probe-cleanup\",\n\t\t\t\t\tstatus: \"pass\",\n\t\t\t\t\tmessage: `Deleted smoke-test record ${logicalId}.`,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tchecks.push({\n\t\t\t\t\tname: \"probe-cleanup\",\n\t\t\t\t\tstatus: \"fail\",\n\t\t\t\t\tmessage: error instanceof Error ? error.message : `Failed to delete smoke-test record ${logicalId}.`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tok: checks.every((check) => check.status !== \"fail\"),\n\t\t\tchecks,\n\t\t\tnamespace,\n\t\t\tlogicalId,\n\t\t};\n\t}\n\n\tasync ensureIndexExists(createIfMissing: boolean, targetDimensions?: number): Promise<{ created: boolean; dimensions: number }> {\n\t\ttry {\n\t\t\tconst description = await this.vectorize.describeIndex();\n\t\t\treturn {\n\t\t\t\tcreated: false,\n\t\t\t\tdimensions: description.config.dimensions,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (!createIfMissing || !isCloudflareNotFoundError(error)) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst dimensions = targetDimensions ?? (await this.inspectEmbeddingDimensions()).targetDimensions;\n\t\t\tconst createdIndex = await this.vectorize.createIndex(dimensions);\n\t\t\treturn {\n\t\t\t\tcreated: true,\n\t\t\t\tdimensions: createdIndex.config.dimensions,\n\t\t\t};\n\t\t}\n\t}\n\n\tprivate fromCompanionFallback(companionRecord: CompanionRecord | undefined, logicalId: string, namespace: string, path: string): UpsertedMemoryRecord {\n\t\treturn {\n\t\t\tlogicalId,\n\t\t\tvectorId: buildVectorId(namespace, logicalId),\n\t\t\tnamespace,\n\t\t\ttitle: companionRecord?.title,\n\t\t\ttext: companionRecord?.text ?? \"\",\n\t\t\tmetadata: companionRecord?.metadata ?? {},\n\t\t\tsource: companionRecord?.source,\n\t\t\tcreatedAt: companionRecord?.createdAt,\n\t\t\tupdatedAt: companionRecord?.updatedAt,\n\t\t\tpath,\n\t\t};\n\t}\n\n\tprivate fromInlineFallback(vector: { id: string; namespace?: string; metadata?: Record<string, string | number | boolean> }): UpsertedMemoryRecord {\n\t\tconst record = hydrateInlineRecord(vector);\n\t\treturn {\n\t\t\t...record,\n\t\t\ttext: record.text ?? \"\",\n\t\t};\n\t}\n\n\tprivate async waitForGetHit(params: {\n\t\tnamespace: string;\n\t\tlogicalId: string;\n\t\ttimeoutMs: number;\n\t\tpollIntervalMs: number;\n\t}): Promise<HydratedMemoryRecord | null> {\n\t\tconst deadline = Date.now() + params.timeoutMs;\n\t\twhile (Date.now() <= deadline) {\n\t\t\tconst record = await this.get({\n\t\t\t\tid: params.logicalId,\n\t\t\t\tnamespace: params.namespace,\n\t\t\t});\n\t\t\tif (record) {\n\t\t\t\treturn record;\n\t\t\t}\n\t\t\tif (Date.now() + params.pollIntervalMs > deadline) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tawait this.pause(params.pollIntervalMs);\n\t\t}\n\t\treturn null;\n\t}\n\n\tprivate async waitForSearchHit(params: {\n\t\tquery: string;\n\t\tnamespace: string;\n\t\tlogicalId: string;\n\t\ttimeoutMs: number;\n\t\tpollIntervalMs: number;\n\t}): Promise<(HydratedMemoryRecord & { score: number }) | null> {\n\t\tconst vector = await this.embeddings.embedQuery(params.query);\n\t\tconst deadline = Date.now() + params.timeoutMs;\n\t\twhile (Date.now() <= deadline) {\n\t\t\tconst matches = await this.vectorize.query({\n\t\t\t\tvector,\n\t\t\t\tnamespace: params.namespace,\n\t\t\t\ttopK: 5,\n\t\t\t});\n\t\t\tfor (const match of matches) {\n\t\t\t\tconst record = hydrateInlineRecord(match, { defaultNamespace: params.namespace });\n\t\t\t\tif (record.logicalId === params.logicalId) {\n\t\t\t\t\tconst text = record.text ?? (await this.companionStore.get(record.namespace, record.logicalId))?.text ?? \"\";\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...record,\n\t\t\t\t\t\ttext,\n\t\t\t\t\t\tscore: match.score ?? 0,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Date.now() + params.pollIntervalMs > deadline) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tawait this.pause(params.pollIntervalMs);\n\t\t}\n\t\treturn null;\n\t}\n\n\tprivate async pause(ms: number): Promise<void> {\n\t\tawait new Promise((resolve) => setTimeout(resolve, ms));\n\t}\n}\n"],"mappings":";;;;;;;;;AAwBA,IAAM,IAAwB,KACxB,IAA8B,KAEvB,IAAb,MAAqC;CACpC;CACA;CACA;CAEA,YACC,GACA,GACC;AAGD,EALS,KAAA,SAAA,GACA,KAAA,iBAAA,GAET,KAAK,aAAa,IAAI,EAA0B,EAAO,EACvD,KAAK,YAAY,IAAI,EAAgB,EAAO,EAC5C,KAAK,iBAAiB,IAAI,EAAe,EAAO,mBAAmB;;CAGpE,iBAAiB,GAAsG;AACtH,SAAO,EAAwB;GAC9B,gBAAgB,EAAO,aAAa,KAAK,OAAO;GAChD,YAAY,EAAO;GACnB,SAAS,EAAO;GAChB,cAAc,EAAO;GACrB,CAAC;;CAGH,MAAM,OAAO,GASgD;EAC5D,IAAM,IAAY,KAAK,iBAAiB,EAAO,EACzC,IAAS,MAAM,KAAK,WAAW,WAAW,EAAO,MAAM,EACvD,IAAU,MAAM,KAAK,UAAU,MAAM;GAC1C;GACA;GACA,MAAM,EAAO,cAAc,KAAK,OAAO;GACvC,QAAQ,EAAO;GACf,CAAC;AAcF,UAZiB,MAAM,QAAQ,IAC9B,EAAQ,IAAI,OAAO,MAAU;GAC5B,IAAM,IAAO,EAAoB,GAAO,EAAE,kBAAkB,GAAW,CAAC,EAClE,IAAO,EAAK,SAAS,MAAM,KAAK,eAAe,IAAI,EAAK,WAAW,EAAK,UAAU,GAAG,QAAQ;AACnG,UAAO;IACN,GAAG;IACH;IACA,OAAO,EAAM,SAAS;IACtB;IACA,CACF,EAEe,QAAQ,MAAW,EAAO,UAAU,EAAO,YAAY,KAAK,OAAO,UAAU;;CAG9F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,IAAW,KAAK,KAAK,GAAG,EAAO;AACrC,SAAO,KAAK,KAAK,IAAI,IAAU;GAC9B,IAAM,IAAU,MAAM,KAAK,UAAU,MAAM;IAC1C;IACA,WAAW,EAAO;IAClB,MAAM;IACN,CAAC;AACF,QAAK,IAAM,KAAS,GAAS;IAC5B,IAAM,IAAS,EAAoB,GAAO,EAAE,kBAAkB,EAAO,WAAW,CAAC;AACjF,QAAI,EAAO,cAAc,EAAO,WAAW;KAC1C,IAAM,IAAO,EAAO,SAAS,MAAM,KAAK,eAAe,IAAI,EAAO,WAAW,EAAO,UAAU,GAAG,QAAQ;AACzG,YAAO;MACN,GAAG;MACH;MACA,OAAO,EAAM,SAAS;MACtB;;;AAGH,OAAI,KAAK,KAAK,GAAG,EAAO,iBAAiB,EACxC;AAED,SAAM,KAAK,MAAM,EAAO,eAAe;;AAExC,SAAO;;CAGR,MAAc,MAAM,GAA2B;AAC9C,QAAM,IAAI,SAAS,MAAY,WAAW,GAAS,EAAG,CAAC"}
package/dist/tools.js CHANGED
@@ -5,9 +5,10 @@ async function n(t, n) {
5
5
  let r = n.runtimeConfig ?? n.config;
6
6
  if (!r) throw Error("Cloudflare memory tools require an OpenClaw runtime config.");
7
7
  return e({
8
- pluginConfig: t,
8
+ pluginConfig: t.pluginConfig,
9
9
  openClawConfig: r,
10
- env: process.env
10
+ env: process.env,
11
+ resolvePath: t.resolvePath
11
12
  });
12
13
  }
13
14
  function r(e, t) {
package/dist/tools.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"tools.js","names":[],"sources":["../src/tools.ts"],"sourcesContent":["import { Type } from \"@sinclair/typebox\";\nimport type { AnyAgentTool, OpenClawPluginToolContext } from \"openclaw/plugin-sdk/plugin-entry\";\nimport type { CloudflareMemoryService } from \"./service.js\";\nimport { createCloudflareMemoryService } from \"./service-factory.js\";\nimport type { MetadataFilter, MetadataValue } from \"./types.js\";\n\nasync function buildService(pluginConfig: unknown, ctx: OpenClawPluginToolContext): Promise<CloudflareMemoryService> {\n\tconst runtimeConfig = ctx.runtimeConfig ?? ctx.config;\n\tif (!runtimeConfig) {\n\t\tthrow new Error(\"Cloudflare memory tools require an OpenClaw runtime config.\");\n\t}\n\treturn createCloudflareMemoryService({\n\t\tpluginConfig,\n\t\topenClawConfig: runtimeConfig,\n\t\tenv: process.env,\n\t});\n}\n\nfunction parseJsonObject<T>(value: string | undefined, label: string): T | 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(`${label} must be a JSON object.`);\n\t}\n\treturn parsed as T;\n}\n\nconst metadataValueSchema = Type.Union([Type.String(), Type.Number(), Type.Boolean()]);\n\nfunction textResult<TDetails>(text: string, details: TDetails) {\n\treturn {\n\t\tcontent: [{ type: \"text\" as const, text }],\n\t\tdetails,\n\t};\n}\n\nexport function createSearchTool(pluginConfig: unknown, ctx: OpenClawPluginToolContext): AnyAgentTool {\n\treturn {\n\t\tname: \"cloudflare_memory_search\",\n\t\tlabel: \"Cloudflare Memory Search\",\n\t\tdescription: \"Search Cloudflare-backed memory records using semantic retrieval.\",\n\t\tparameters: Type.Object({\n\t\t\tquery: Type.String({ description: \"Semantic search query.\" }),\n\t\t\tnamespace: Type.Optional(Type.String({ description: \"Optional namespace override.\" })),\n\t\t\tmaxResults: Type.Optional(Type.Number({ description: \"Maximum results to return.\" })),\n\t\t\tminScore: Type.Optional(Type.Number({ description: \"Minimum similarity score from 0 to 1.\" })),\n\t\t\tfilterJson: Type.Optional(Type.String({ description: \"Optional JSON object for Vectorize metadata filtering.\" })),\n\t\t}),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate) {\n\t\t\tconst service = await buildService(pluginConfig, ctx);\n\t\t\tconst filter = parseJsonObject<MetadataFilter>(params.filterJson as string | undefined, \"filterJson\");\n\t\t\tconst records = await service.search({\n\t\t\t\tquery: params.query as string,\n\t\t\t\tnamespace: params.namespace as string | undefined,\n\t\t\t\tmaxResults: params.maxResults as number | undefined,\n\t\t\t\tminScore: params.minScore as number | undefined,\n\t\t\t\tfilter,\n\t\t\t\tsessionKey: ctx.sessionKey,\n\t\t\t\tagentId: ctx.agentId,\n\t\t\t\tworkspaceDir: ctx.workspaceDir,\n\t\t\t});\n\t\t\tif (records.length === 0) {\n\t\t\t\treturn textResult(\"No matching memories found.\", { count: 0, records: [] });\n\t\t\t}\n\t\t\tconst text = records\n\t\t\t\t.map((record, index) => `${index + 1}. [${record.namespace}] ${record.title ?? record.logicalId} (${record.score.toFixed(3)})\\n${record.text}`)\n\t\t\t\t.join(\"\\n\\n\");\n\t\t\treturn textResult(text, {\n\t\t\t\tcount: records.length,\n\t\t\t\trecords: records.map((record) => ({\n\t\t\t\t\tid: record.logicalId,\n\t\t\t\t\tnamespace: record.namespace,\n\t\t\t\t\ttitle: record.title,\n\t\t\t\t\tscore: record.score,\n\t\t\t\t\tpath: record.path,\n\t\t\t\t})),\n\t\t\t});\n\t\t},\n\t};\n}\n\nexport function createGetTool(pluginConfig: unknown, ctx: OpenClawPluginToolContext): AnyAgentTool {\n\treturn {\n\t\tname: \"cloudflare_memory_get\",\n\t\tlabel: \"Cloudflare Memory Get\",\n\t\tdescription: \"Get a Cloudflare-backed memory record by id.\",\n\t\tparameters: Type.Object({\n\t\t\tid: Type.String({ description: \"Logical memory record id.\" }),\n\t\t\tnamespace: Type.Optional(Type.String({ description: \"Optional namespace override.\" })),\n\t\t}),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate) {\n\t\t\tconst service = await buildService(pluginConfig, ctx);\n\t\t\tconst record = await service.get({\n\t\t\t\tid: params.id as string,\n\t\t\t\tnamespace: params.namespace as string | undefined,\n\t\t\t\tsessionKey: ctx.sessionKey,\n\t\t\t\tagentId: ctx.agentId,\n\t\t\t\tworkspaceDir: ctx.workspaceDir,\n\t\t\t});\n\t\t\tif (!record) {\n\t\t\t\treturn textResult(\"Memory record not found.\", { found: false });\n\t\t\t}\n\t\t\treturn textResult(`${record.title ?? record.logicalId}\\nNamespace: ${record.namespace}\\nPath: ${record.path}\\n\\n${record.text}`, {\n\t\t\t\tfound: true,\n\t\t\t\tid: record.logicalId,\n\t\t\t\tnamespace: record.namespace,\n\t\t\t\tmetadata: record.metadata,\n\t\t\t});\n\t\t},\n\t};\n}\n\nexport function createUpsertTool(pluginConfig: unknown, ctx: OpenClawPluginToolContext): AnyAgentTool {\n\treturn {\n\t\tname: \"cloudflare_memory_upsert\",\n\t\tlabel: \"Cloudflare Memory Upsert\",\n\t\tdescription: \"Insert or update a Cloudflare-backed memory record.\",\n\t\tparameters: Type.Object({\n\t\t\tid: Type.Optional(Type.String({ description: \"Optional stable logical id.\" })),\n\t\t\ttitle: Type.Optional(Type.String({ description: \"Optional title.\" })),\n\t\t\ttext: Type.String({ description: \"Memory text to store.\" }),\n\t\t\tnamespace: Type.Optional(Type.String({ description: \"Optional namespace override.\" })),\n\t\t\tsource: Type.Optional(Type.String({ description: \"Optional source label.\" })),\n\t\t\tmetadata: Type.Optional(\n\t\t\t\tType.Record(Type.String(), metadataValueSchema, {\n\t\t\t\t\tdescription: \"Flat metadata object with string, number, or boolean values.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t}),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate) {\n\t\t\tconst service = await buildService(pluginConfig, ctx);\n\t\t\tconst record = await service.upsert({\n\t\t\t\tinput: {\n\t\t\t\t\tid: params.id as string | undefined,\n\t\t\t\t\ttitle: params.title as string | undefined,\n\t\t\t\t\ttext: params.text as string,\n\t\t\t\t\tnamespace: params.namespace as string | undefined,\n\t\t\t\t\tsource: params.source as string | undefined,\n\t\t\t\t\tmetadata: params.metadata as Record<string, MetadataValue> | undefined,\n\t\t\t\t},\n\t\t\t\tsessionKey: ctx.sessionKey,\n\t\t\t\tagentId: ctx.agentId,\n\t\t\t\tworkspaceDir: ctx.workspaceDir,\n\t\t\t});\n\t\t\treturn textResult(`Stored memory ${record.logicalId} in namespace ${record.namespace}.`, {\n\t\t\t\tid: record.logicalId,\n\t\t\t\tnamespace: record.namespace,\n\t\t\t\tpath: record.path,\n\t\t\t\tmutationId: record.mutationId,\n\t\t\t});\n\t\t},\n\t};\n}\n\nexport function createDeleteTool(pluginConfig: unknown, ctx: OpenClawPluginToolContext): AnyAgentTool {\n\treturn {\n\t\tname: \"cloudflare_memory_delete\",\n\t\tlabel: \"Cloudflare Memory Delete\",\n\t\tdescription: \"Delete a Cloudflare-backed memory record by id.\",\n\t\tparameters: Type.Object({\n\t\t\tid: Type.String({ description: \"Logical memory record id.\" }),\n\t\t\tnamespace: Type.Optional(Type.String({ description: \"Optional namespace override.\" })),\n\t\t}),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate) {\n\t\t\tconst service = await buildService(pluginConfig, ctx);\n\t\t\tconst mutationId = await service.delete({\n\t\t\t\tid: params.id as string,\n\t\t\t\tnamespace: params.namespace as string | undefined,\n\t\t\t\tsessionKey: ctx.sessionKey,\n\t\t\t\tagentId: ctx.agentId,\n\t\t\t\tworkspaceDir: ctx.workspaceDir,\n\t\t\t});\n\t\t\treturn textResult(`Deleted memory ${params.id as string}.`, { mutationId });\n\t\t},\n\t};\n}\n"],"mappings":";;;AAMA,eAAe,EAAa,GAAuB,GAAkE;CACpH,IAAM,IAAgB,EAAI,iBAAiB,EAAI;AAC/C,KAAI,CAAC,EACJ,OAAU,MAAM,8DAA8D;AAE/E,QAAO,EAA8B;EACpC;EACA,gBAAgB;EAChB,KAAK,QAAQ;EACb,CAAC;;AAGH,SAAS,EAAmB,GAA2B,GAA8B;AACpF,KAAI,CAAC,EACJ;CAED,IAAM,IAAS,KAAK,MAAM,EAAM;AAChC,KAAI,CAAC,KAAU,OAAO,KAAW,YAAY,MAAM,QAAQ,EAAO,CACjE,OAAU,MAAM,GAAG,EAAM,yBAAyB;AAEnD,QAAO;;AAGR,IAAM,IAAsB,EAAK,MAAM;CAAC,EAAK,QAAQ;CAAE,EAAK,Q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AK,QAAQ,EAAE,GAAqB,EAC/C,aAAa,gEACb,CAAC,CACF;GACD,CAAC;EACF,MAAM,QAAQ,GAAa,GAAQ,GAAS,GAAW;GAEtD,IAAM,IAAS,OADC,MAAM,EAAa,GAAc,EAAI,EACxB,OAAO;IACnC,OAAO;KACN,IAAI,EAAO;KACX,OAAO,EAAO;KACd,MAAM,EAAO;KACb,WAAW,EAAO;KAClB,QAAQ,EAAO;KACf,UAAU,EAAO;KACjB;IACD,YAAY,EAAI;IAChB,SAAS,EAAI;IACb,cAAc,EAAI;IAClB,CAAC;AACF,UAAO,EAAW,iBAAiB,EAAO,UAAU,gBAAgB,EAAO,UAAU,IAAI;IACxF,IAAI,EAAO;IACX,WAAW,EAAO;IAClB,MAAM,EAAO;IACb,YAAY,EAAO;IACnB,CAAC;;EAEH;;AAGF,SAAgB,EAAiB,GAAuB,GAA8C;AACrG,QAAO;EACN,MAAM;EACN,OAAO;EACP,aAAa;EACb,YAAY,EAAK,OAAO;GACvB,IAAI,EAAK,OAAO,EAAE,aAAa,6BAA6B,CAAC;GAC7D,WAAW,EAAK,SAAS,EAAK,OAAO,EAAE,aAAa,gCAAgC,CAAC,CAAC;GACtF,CAAC;EACF,MAAM,QAAQ,GAAa,GAAQ,GAAS,GAAW;GAEtD,IAAM,IAAa,OADH,MAAM,EAAa,GAAc,EAAI,EACpB,OAAO;IACvC,IAAI,EAAO;IACX,WAAW,EAAO;IAClB,YAAY,EAAI;IAChB,SAAS,EAAI;IACb,cAAc,EAAI;IAClB,CAAC;AACF,UAAO,EAAW,kBAAkB,EAAO,GAAa,IAAI,EAAE,eAAY,CAAC;;EAE5E"}
1
+ {"version":3,"file":"tools.js","names":[],"sources":["../src/tools.ts"],"sourcesContent":["import { Type } from \"@sinclair/typebox\";\nimport type { AnyAgentTool, OpenClawPluginToolContext } from \"openclaw/plugin-sdk/plugin-entry\";\nimport type { CloudflareMemoryService } from \"./service.js\";\nimport { createCloudflareMemoryService } from \"./service-factory.js\";\nimport type { MetadataFilter, MetadataValue } from \"./types.js\";\n\ntype ToolRegistrationContext = {\n\tpluginConfig: unknown;\n\tresolvePath?: (input: string) => string;\n};\n\nasync function buildService(registration: ToolRegistrationContext, ctx: OpenClawPluginToolContext): Promise<CloudflareMemoryService> {\n\tconst runtimeConfig = ctx.runtimeConfig ?? ctx.config;\n\tif (!runtimeConfig) {\n\t\tthrow new Error(\"Cloudflare memory tools require an OpenClaw runtime config.\");\n\t}\n\treturn createCloudflareMemoryService({\n\t\tpluginConfig: registration.pluginConfig,\n\t\topenClawConfig: runtimeConfig,\n\t\tenv: process.env,\n\t\tresolvePath: registration.resolvePath,\n\t});\n}\n\nfunction parseJsonObject<T>(value: string | undefined, label: string): T | 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(`${label} must be a JSON object.`);\n\t}\n\treturn parsed as T;\n}\n\nconst metadataValueSchema = Type.Union([Type.String(), Type.Number(), Type.Boolean()]);\n\nfunction textResult<TDetails>(text: string, details: TDetails) {\n\treturn {\n\t\tcontent: [{ type: \"text\" as const, text }],\n\t\tdetails,\n\t};\n}\n\nexport function createSearchTool(registration: ToolRegistrationContext, ctx: OpenClawPluginToolContext): AnyAgentTool {\n\treturn {\n\t\tname: \"cloudflare_memory_search\",\n\t\tlabel: \"Cloudflare Memory Search\",\n\t\tdescription: \"Search Cloudflare-backed memory records using semantic retrieval.\",\n\t\tparameters: Type.Object({\n\t\t\tquery: Type.String({ description: \"Semantic search query.\" }),\n\t\t\tnamespace: Type.Optional(Type.String({ description: \"Optional namespace override.\" })),\n\t\t\tmaxResults: Type.Optional(Type.Number({ description: \"Maximum results to return.\" })),\n\t\t\tminScore: Type.Optional(Type.Number({ description: \"Minimum similarity score from 0 to 1.\" })),\n\t\t\tfilterJson: Type.Optional(Type.String({ description: \"Optional JSON object for Vectorize metadata filtering.\" })),\n\t\t}),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate) {\n\t\t\tconst service = await buildService(registration, ctx);\n\t\t\tconst filter = parseJsonObject<MetadataFilter>(params.filterJson as string | undefined, \"filterJson\");\n\t\t\tconst records = await service.search({\n\t\t\t\tquery: params.query as string,\n\t\t\t\tnamespace: params.namespace as string | undefined,\n\t\t\t\tmaxResults: params.maxResults as number | undefined,\n\t\t\t\tminScore: params.minScore as number | undefined,\n\t\t\t\tfilter,\n\t\t\t\tsessionKey: ctx.sessionKey,\n\t\t\t\tagentId: ctx.agentId,\n\t\t\t\tworkspaceDir: ctx.workspaceDir,\n\t\t\t});\n\t\t\tif (records.length === 0) {\n\t\t\t\treturn textResult(\"No matching memories found.\", { count: 0, records: [] });\n\t\t\t}\n\t\t\tconst text = records\n\t\t\t\t.map((record, index) => `${index + 1}. [${record.namespace}] ${record.title ?? record.logicalId} (${record.score.toFixed(3)})\\n${record.text}`)\n\t\t\t\t.join(\"\\n\\n\");\n\t\t\treturn textResult(text, {\n\t\t\t\tcount: records.length,\n\t\t\t\trecords: records.map((record) => ({\n\t\t\t\t\tid: record.logicalId,\n\t\t\t\t\tnamespace: record.namespace,\n\t\t\t\t\ttitle: record.title,\n\t\t\t\t\tscore: record.score,\n\t\t\t\t\tpath: record.path,\n\t\t\t\t})),\n\t\t\t});\n\t\t},\n\t};\n}\n\nexport function createGetTool(registration: ToolRegistrationContext, ctx: OpenClawPluginToolContext): AnyAgentTool {\n\treturn {\n\t\tname: \"cloudflare_memory_get\",\n\t\tlabel: \"Cloudflare Memory Get\",\n\t\tdescription: \"Get a Cloudflare-backed memory record by id.\",\n\t\tparameters: Type.Object({\n\t\t\tid: Type.String({ description: \"Logical memory record id.\" }),\n\t\t\tnamespace: Type.Optional(Type.String({ description: \"Optional namespace override.\" })),\n\t\t}),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate) {\n\t\t\tconst service = await buildService(registration, ctx);\n\t\t\tconst record = await service.get({\n\t\t\t\tid: params.id as string,\n\t\t\t\tnamespace: params.namespace as string | undefined,\n\t\t\t\tsessionKey: ctx.sessionKey,\n\t\t\t\tagentId: ctx.agentId,\n\t\t\t\tworkspaceDir: ctx.workspaceDir,\n\t\t\t});\n\t\t\tif (!record) {\n\t\t\t\treturn textResult(\"Memory record not found.\", { found: false });\n\t\t\t}\n\t\t\treturn textResult(`${record.title ?? record.logicalId}\\nNamespace: ${record.namespace}\\nPath: ${record.path}\\n\\n${record.text}`, {\n\t\t\t\tfound: true,\n\t\t\t\tid: record.logicalId,\n\t\t\t\tnamespace: record.namespace,\n\t\t\t\tmetadata: record.metadata,\n\t\t\t});\n\t\t},\n\t};\n}\n\nexport function createUpsertTool(registration: ToolRegistrationContext, ctx: OpenClawPluginToolContext): AnyAgentTool {\n\treturn {\n\t\tname: \"cloudflare_memory_upsert\",\n\t\tlabel: \"Cloudflare Memory Upsert\",\n\t\tdescription: \"Insert or update a Cloudflare-backed memory record.\",\n\t\tparameters: Type.Object({\n\t\t\tid: Type.Optional(Type.String({ description: \"Optional stable logical id.\" })),\n\t\t\ttitle: Type.Optional(Type.String({ description: \"Optional title.\" })),\n\t\t\ttext: Type.String({ description: \"Memory text to store.\" }),\n\t\t\tnamespace: Type.Optional(Type.String({ description: \"Optional namespace override.\" })),\n\t\t\tsource: Type.Optional(Type.String({ description: \"Optional source label.\" })),\n\t\t\tmetadata: Type.Optional(\n\t\t\t\tType.Record(Type.String(), metadataValueSchema, {\n\t\t\t\t\tdescription: \"Flat metadata object with string, number, or boolean values.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t}),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate) {\n\t\t\tconst service = await buildService(registration, ctx);\n\t\t\tconst record = await service.upsert({\n\t\t\t\tinput: {\n\t\t\t\t\tid: params.id as string | undefined,\n\t\t\t\t\ttitle: params.title as string | undefined,\n\t\t\t\t\ttext: params.text as string,\n\t\t\t\t\tnamespace: params.namespace as string | undefined,\n\t\t\t\t\tsource: params.source as string | undefined,\n\t\t\t\t\tmetadata: params.metadata as Record<string, MetadataValue> | undefined,\n\t\t\t\t},\n\t\t\t\tsessionKey: ctx.sessionKey,\n\t\t\t\tagentId: ctx.agentId,\n\t\t\t\tworkspaceDir: ctx.workspaceDir,\n\t\t\t});\n\t\t\treturn textResult(`Stored memory ${record.logicalId} in namespace ${record.namespace}.`, {\n\t\t\t\tid: record.logicalId,\n\t\t\t\tnamespace: record.namespace,\n\t\t\t\tpath: record.path,\n\t\t\t\tmutationId: record.mutationId,\n\t\t\t});\n\t\t},\n\t};\n}\n\nexport function createDeleteTool(registration: ToolRegistrationContext, ctx: OpenClawPluginToolContext): AnyAgentTool {\n\treturn {\n\t\tname: \"cloudflare_memory_delete\",\n\t\tlabel: \"Cloudflare Memory Delete\",\n\t\tdescription: \"Delete a Cloudflare-backed memory record by id.\",\n\t\tparameters: Type.Object({\n\t\t\tid: Type.String({ description: \"Logical memory record id.\" }),\n\t\t\tnamespace: Type.Optional(Type.String({ description: \"Optional namespace override.\" })),\n\t\t}),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate) {\n\t\t\tconst service = await buildService(registration, ctx);\n\t\t\tconst mutationId = await service.delete({\n\t\t\t\tid: params.id as string,\n\t\t\t\tnamespace: params.namespace as string | undefined,\n\t\t\t\tsessionKey: ctx.sessionKey,\n\t\t\t\tagentId: ctx.agentId,\n\t\t\t\tworkspaceDir: ctx.workspaceDir,\n\t\t\t});\n\t\t\treturn textResult(`Deleted memory ${params.id as string}.`, { mutationId });\n\t\t},\n\t};\n}\n"],"mappings":";;;AAWA,eAAe,EAAa,GAAuC,GAAkE;CACpI,IAAM,IAAgB,EAAI,iBAAiB,EAAI;AAC/C,KAAI,CAAC,EACJ,OAAU,MAAM,8DAA8D;AAE/E,QAAO,EAA8B;EACpC,cAAc,EAAa;EAC3B,gBAAgB;EAChB,KAAK,QAAQ;EACb,aAAa,EAAa;EAC1B,CAAC;;AAGH,SAAS,EAAmB,GAA2B,GAA8B;AACpF,KAAI,CAA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E5E"}
@@ -163,6 +163,7 @@ export declare const pluginUiHints: {
163
163
  };
164
164
  export declare const pluginConfigSchema: OpenClawPluginConfigSchema;
165
165
  export declare function parsePluginConfig(value: unknown): RawPluginConfig;
166
+ export declare function normalizePluginConfigInput(value: unknown): RawPluginConfig;
166
167
  export declare function getPluginConfigFromOpenClawConfig(config: OpenClawConfig): RawPluginConfig;
167
168
  export declare function resolvePluginConfig(params: {
168
169
  pluginConfig: unknown;
@@ -28,6 +28,7 @@ export declare const DEFAULT_INDEX_DESCRIPTION = "OpenClaw memory index backed b
28
28
  export declare const RESERVED_METADATA_PREFIX = "oc_";
29
29
  export declare const RESERVED_METADATA_KEYS: {
30
30
  readonly logicalId: "oc_record_id";
31
+ readonly namespace: "oc_namespace";
31
32
  readonly title: "oc_title";
32
33
  readonly text: "oc_text";
33
34
  readonly storageMode: "oc_storage_mode";
@@ -1,6 +1,7 @@
1
1
  import type { ResolvedPluginConfig } from "./types.js";
2
2
  export declare class WorkersAiEmbeddingsClient {
3
3
  private readonly config;
4
+ private readonly queryCache;
4
5
  constructor(config: ResolvedPluginConfig);
5
6
  embedQuery(text: string): Promise<number[]>;
6
7
  embedBatch(texts: string[]): Promise<number[][]>;
@@ -18,7 +18,9 @@ export declare function mapRecordForUpsert(params: {
18
18
  vector: VectorizeVector;
19
19
  companionRecord?: CompanionRecord;
20
20
  };
21
- export declare function hydrateInlineRecord(match: VectorizeQueryMatch): Omit<HydratedMemoryRecord, "text" | "path"> & {
21
+ export declare function hydrateInlineRecord(match: VectorizeQueryMatch, options?: {
22
+ defaultNamespace?: string;
23
+ }): Omit<HydratedMemoryRecord, "text" | "path"> & {
22
24
  text?: string;
23
25
  path: string;
24
26
  };
@@ -1,8 +1,19 @@
1
1
  import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
2
2
  import { CloudflareMemoryService } from "./service.js";
3
+ import type { ResolvedPluginConfig } from "./types.js";
4
+ type ServiceConfigOverrides = Partial<Pick<ResolvedPluginConfig, "apiToken" | "workersAiBaseUrl" | "model">>;
5
+ export declare function resolveCloudflareMemoryServiceConfig(params: {
6
+ pluginConfig?: unknown;
7
+ openClawConfig: OpenClawConfig;
8
+ env?: NodeJS.ProcessEnv;
9
+ resolvePath?: (input: string) => string;
10
+ overrides?: ServiceConfigOverrides;
11
+ }): Promise<ResolvedPluginConfig>;
3
12
  export declare function createCloudflareMemoryService(params: {
4
- pluginConfig: unknown;
13
+ pluginConfig?: unknown;
5
14
  openClawConfig: OpenClawConfig;
6
15
  env?: NodeJS.ProcessEnv;
7
16
  resolvePath?: (input: string) => string;
17
+ overrides?: ServiceConfigOverrides;
8
18
  }): Promise<CloudflareMemoryService>;
19
+ export {};
@@ -66,6 +66,7 @@ export declare class CloudflareMemoryService {
66
66
  }>;
67
67
  private fromCompanionFallback;
68
68
  private fromInlineFallback;
69
+ private waitForGetHit;
69
70
  private waitForSearchHit;
70
71
  private pause;
71
72
  }
@@ -1,5 +1,10 @@
1
1
  import type { AnyAgentTool, OpenClawPluginToolContext } from "openclaw/plugin-sdk/plugin-entry";
2
- export declare function createSearchTool(pluginConfig: unknown, ctx: OpenClawPluginToolContext): AnyAgentTool;
3
- export declare function createGetTool(pluginConfig: unknown, ctx: OpenClawPluginToolContext): AnyAgentTool;
4
- export declare function createUpsertTool(pluginConfig: unknown, ctx: OpenClawPluginToolContext): AnyAgentTool;
5
- export declare function createDeleteTool(pluginConfig: unknown, ctx: OpenClawPluginToolContext): AnyAgentTool;
2
+ type ToolRegistrationContext = {
3
+ pluginConfig: unknown;
4
+ resolvePath?: (input: string) => string;
5
+ };
6
+ export declare function createSearchTool(registration: ToolRegistrationContext, ctx: OpenClawPluginToolContext): AnyAgentTool;
7
+ export declare function createGetTool(registration: ToolRegistrationContext, ctx: OpenClawPluginToolContext): AnyAgentTool;
8
+ export declare function createUpsertTool(registration: ToolRegistrationContext, ctx: OpenClawPluginToolContext): AnyAgentTool;
9
+ export declare function createDeleteTool(registration: ToolRegistrationContext, ctx: OpenClawPluginToolContext): AnyAgentTool;
10
+ export {};
@@ -1 +1 @@
1
- {"version":3,"file":"vectorize-client.js","names":[],"sources":["../src/vectorize-client.ts"],"sourcesContent":["import { requestCloudflare } from \"./cloudflare-api.js\";\r\nimport type { MetadataFilter, ResolvedPluginConfig, VectorizeIndexDescription, VectorizeQueryMatch, VectorizeVector } from \"./types.js\";\r\n\r\ntype MutationResponse = {\r\n\tmutationId?: string;\r\n};\r\n\r\ntype QueryResponse = {\r\n\tcount?: number;\r\n\tmatches?: VectorizeQueryMatch[];\r\n};\r\n\r\nexport class VectorizeClient {\r\n\tconstructor(private readonly config: ResolvedPluginConfig) {}\r\n\r\n\tasync describeIndex(): Promise<VectorizeIndexDescription> {\r\n\t\treturn requestCloudflare<VectorizeIndexDescription>({\r\n\t\t\turl: this.config.vectorizeBaseUrl,\r\n\t\t\tapiToken: this.config.apiToken,\r\n\t\t\tmethod: \"GET\",\r\n\t\t});\r\n\t}\r\n\r\n\tasync createIndex(dimensions: number, metric = this.config.createIndex.metric): Promise<VectorizeIndexDescription> {\r\n\t\treturn requestCloudflare<VectorizeIndexDescription>({\r\n\t\t\turl: `${this.config.apiBaseUrl}/accounts/${this.config.accountId}/vectorize/v2/indexes`,\r\n\t\t\tapiToken: this.config.apiToken,\r\n\t\t\tbody: JSON.stringify({\r\n\t\t\t\tname: this.config.indexName,\r\n\t\t\t\tdescription: this.config.createIndex.description,\r\n\t\t\t\tconfig: {\r\n\t\t\t\t\tdimensions,\r\n\t\t\t\t\tmetric,\r\n\t\t\t\t},\r\n\t\t\t}),\r\n\t\t});\r\n\t}\r\n\r\n\tasync deleteIndex(): Promise<void> {\r\n\t\tawait requestCloudflare<unknown>({\r\n\t\t\turl: this.config.vectorizeBaseUrl,\r\n\t\t\tapiToken: this.config.apiToken,\r\n\t\t\tmethod: \"DELETE\",\r\n\t\t});\r\n\t}\r\n\r\n\tasync upsert(vectors: VectorizeVector[]): Promise<string | undefined> {\r\n\t\tconst body = vectors.map((vector) => JSON.stringify(vector)).join(\"\\n\");\r\n\t\tconst result = await requestCloudflare<MutationResponse>({\r\n\t\t\turl: `${this.config.vectorizeBaseUrl}/upsert`,\r\n\t\t\tapiToken: this.config.apiToken,\r\n\t\t\theaders: {\r\n\t\t\t\t\"Content-Type\": \"application/x-ndjson\",\r\n\t\t\t},\r\n\t\t\tbody,\r\n\t\t});\r\n\t\treturn result.mutationId;\r\n\t}\r\n\r\n\tasync query(params: {\r\n\t\tvector: number[];\r\n\t\tnamespace?: string;\r\n\t\ttopK?: number;\r\n\t\tfilter?: MetadataFilter;\r\n\t\treturnValues?: boolean;\r\n\t}): Promise<VectorizeQueryMatch[]> {\r\n\t\tconst result = await requestCloudflare<QueryResponse>({\r\n\t\t\turl: `${this.config.vectorizeBaseUrl}/query`,\r\n\t\t\tapiToken: this.config.apiToken,\r\n\t\t\tbody: JSON.stringify({\r\n\t\t\t\tvector: params.vector,\r\n\t\t\t\ttopK: params.topK ?? this.config.topK,\r\n\t\t\t\tfilter: params.filter,\r\n\t\t\t\tnamespace: params.namespace,\r\n\t\t\t\treturnValues: params.returnValues ?? false,\r\n\t\t\t\treturnMetadata: \"all\",\r\n\t\t\t}),\r\n\t\t});\r\n\t\treturn result.matches ?? [];\r\n\t}\r\n\r\n\tasync getByIds(ids: string[]): Promise<VectorizeQueryMatch[]> {\r\n\t\tif (ids.length === 0) {\r\n\t\t\treturn [];\r\n\t\t}\r\n\t\treturn requestCloudflare<VectorizeQueryMatch[]>({\r\n\t\t\turl: `${this.config.vectorizeBaseUrl}/get_by_ids`,\r\n\t\t\tapiToken: this.config.apiToken,\r\n\t\t\tbody: JSON.stringify({ ids }),\r\n\t\t});\r\n\t}\r\n\r\n\tasync deleteByIds(ids: string[]): Promise<string | undefined> {\r\n\t\tif (ids.length === 0) {\r\n\t\t\treturn undefined;\r\n\t\t}\r\n\t\tconst result = await requestCloudflare<MutationResponse>({\r\n\t\t\turl: `${this.config.vectorizeBaseUrl}/delete_by_ids`,\r\n\t\t\t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,WAAW,EAAE;;CAG5B,MAAM,SAAS,GAA+C;AAI7D,SAHI,EAAI,WAAW,IACX,EAAE,GAEH,EAAyC;GAC/C,KAAK,GAAG,KAAK,OAAO,iBAAiB;GACrC,UAAU,KAAK,OAAO;GACtB,MAAM,KAAK,UAAU,EAAE,QAAK,CAAC;GAC7B,CAAC;;CAGH,MAAM,YAAY,GAA4C;AACzD,QAAI,WAAW,EAQnB,SALe,MAAM,EAAoC;GACxD,KAAK,GAAG,KAAK,OAAO,iBAAiB;GACrC,UAAU,KAAK,OAAO;GACtB,MAAM,KAAK,UAAU,EAAE,QAAK,CAAC;GAC7B,CAAC,EACY"}
1
+ {"version":3,"file":"vectorize-client.js","names":[],"sources":["../src/vectorize-client.ts"],"sourcesContent":["import { requestCloudflare } from \"./cloudflare-api.js\";\nimport type { MetadataFilter, ResolvedPluginConfig, VectorizeIndexDescription, VectorizeQueryMatch, VectorizeVector } from \"./types.js\";\n\ntype MutationResponse = {\n\tmutationId?: string;\n};\n\ntype QueryResponse = {\n\tcount?: number;\n\tmatches?: VectorizeQueryMatch[];\n};\n\nexport class VectorizeClient {\n\tconstructor(private readonly config: ResolvedPluginConfig) {}\n\n\tasync describeIndex(): Promise<VectorizeIndexDescription> {\n\t\treturn requestCloudflare<VectorizeIndexDescription>({\n\t\t\turl: this.config.vectorizeBaseUrl,\n\t\t\tapiToken: this.config.apiToken,\n\t\t\tmethod: \"GET\",\n\t\t});\n\t}\n\n\tasync createIndex(dimensions: number, metric = this.config.createIndex.metric): Promise<VectorizeIndexDescription> {\n\t\treturn requestCloudflare<VectorizeIndexDescription>({\n\t\t\turl: `${this.config.apiBaseUrl}/accounts/${this.config.accountId}/vectorize/v2/indexes`,\n\t\t\tapiToken: this.config.apiToken,\n\t\t\tbody: JSON.stringify({\n\t\t\t\tname: this.config.indexName,\n\t\t\t\tdescription: this.config.createIndex.description,\n\t\t\t\tconfig: {\n\t\t\t\t\tdimensions,\n\t\t\t\t\tmetric,\n\t\t\t\t},\n\t\t\t}),\n\t\t});\n\t}\n\n\tasync deleteIndex(): Promise<void> {\n\t\tawait requestCloudflare<unknown>({\n\t\t\turl: this.config.vectorizeBaseUrl,\n\t\t\tapiToken: this.config.apiToken,\n\t\t\tmethod: \"DELETE\",\n\t\t});\n\t}\n\n\tasync upsert(vectors: VectorizeVector[]): Promise<string | undefined> {\n\t\tconst body = vectors.map((vector) => JSON.stringify(vector)).join(\"\\n\");\n\t\tconst result = await requestCloudflare<MutationResponse>({\n\t\t\turl: `${this.config.vectorizeBaseUrl}/upsert`,\n\t\t\tapiToken: this.config.apiToken,\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"application/x-ndjson\",\n\t\t\t},\n\t\t\tbody,\n\t\t});\n\t\treturn result.mutationId;\n\t}\n\n\tasync query(params: {\n\t\tvector: number[];\n\t\tnamespace?: string;\n\t\ttopK?: number;\n\t\tfilter?: MetadataFilter;\n\t\treturnValues?: boolean;\n\t}): Promise<VectorizeQueryMatch[]> {\n\t\tconst result = await requestCloudflare<QueryResponse>({\n\t\t\turl: `${this.config.vectorizeBaseUrl}/query`,\n\t\t\tapiToken: this.config.apiToken,\n\t\t\tbody: JSON.stringify({\n\t\t\t\tvector: params.vector,\n\t\t\t\ttopK: params.topK ?? this.config.topK,\n\t\t\t\tfilter: params.filter,\n\t\t\t\tnamespace: params.namespace,\n\t\t\t\treturnValues: params.returnValues ?? false,\n\t\t\t\treturnMetadata: \"all\",\n\t\t\t}),\n\t\t});\n\t\treturn result.matches ?? [];\n\t}\n\n\tasync getByIds(ids: string[]): Promise<VectorizeQueryMatch[]> {\n\t\tif (ids.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\treturn requestCloudflare<VectorizeQueryMatch[]>({\n\t\t\turl: `${this.config.vectorizeBaseUrl}/get_by_ids`,\n\t\t\tapiToken: this.config.apiToken,\n\t\t\tbody: JSON.stringify({ ids }),\n\t\t});\n\t}\n\n\tasync deleteByIds(ids: string[]): Promise<string | undefined> {\n\t\tif (ids.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst result = await requestCloudflare<MutationResponse>({\n\t\t\turl: `${this.config.vectorizeBaseUrl}/delete_by_ids`,\n\t\t\tapiToken: this.config.apiToken,\n\t\t\tbody: JSON.stringify({ ids }),\n\t\t});\n\t\treturn result.mutationId;\n\t}\n}\n"],"mappings":";;AAYA,IAAa,IAAb,MAA6B;CAC5B,YAAY,GAA+C;AAA9B,OAAA,SAAA;;CAE7B,MAAM,gBAAoD;AACzD,SAAO,EAA6C;GACnD,KAAK,KAAK,OAAO;GACjB,UAAU,KAAK,OAAO;GACtB,QAAQ;GACR,CAAC;;CAGH,MAAM,YAAY,GAAoB,IAAS,KAAK,OAAO,YAAY,QAA4C;AAClH,SAAO,EAA6C;GACnD,KAAK,GAAG,KAAK,OAAO,WAAW,YAAY,KAAK,OAAO,UAAU;GACjE,UAAU,KAAK,OAAO;GACtB,MAAM,KAAK,UAAU;IACpB,MAAM,KAAK,OAAO;IAClB,aAAa,KAAK,OAAO,YAAY;IACrC,QAAQ;KACP;KACA;KACA;IACD,CAAC;GACF,CAAC;;CAGH,MAAM,cAA6B;AAClC,QAAM,EAA2B;GAChC,KAAK,KAAK,OAAO;GACjB,UAAU,KAAK,OAAO;GACtB,QAAQ;GACR,CAAC;;CAGH,MAAM,OAAO,GAAyD;EACrE,IAAM,IAAO,EAAQ,KAAK,MAAW,KAAK,UAAU,EAAO,CAAC,CAAC,KAAK,KAAK;AASvE,UARe,MAAM,EAAoC;GACxD,KAAK,GAAG,KAAK,OAAO,iBAAiB;GACrC,UAAU,KAAK,OAAO;GACtB,SAAS,EACR,gBAAgB,wBAChB;GACD;GACA,CAAC,EACY;;CAGf,MAAM,MAAM,GAMuB;AAalC,UAZe,MAAM,EAAiC;GACrD,KAAK,GAAG,KAAK,OAAO,iBAAiB;GACrC,UAAU,KAAK,OAAO;GACtB,MAAM,KAAK,UAAU;IACpB,QAAQ,EAAO;IACf,MAAM,EAAO,QAAQ,KAAK,OAAO;IACjC,QAAQ,EAAO;IACf,WAAW,EAAO;IAClB,cAAc,EAAO,gBAAgB;IACrC,gBAAgB;IAChB,CAAC;GACF,CAAC,EACY,WAAW,EAAE;;CAG5B,MAAM,SAAS,GAA+C;AAI7D,SAHI,EAAI,WAAW,IACX,EAAE,GAEH,EAAyC;GAC/C,KAAK,GAAG,KAAK,OAAO,iBAAiB;GACrC,UAAU,KAAK,OAAO;GACtB,MAAM,KAAK,UAAU,EAAE,QAAK,CAAC;GAC7B,CAAC;;CAGH,MAAM,YAAY,GAA4C;AACzD,QAAI,WAAW,EAQnB,SALe,MAAM,EAAoC;GACxD,KAAK,GAAG,KAAK,OAAO,iBAAiB;GACrC,UAAU,KAAK,OAAO;GACtB,MAAM,KAAK,UAAU,EAAE,QAAK,CAAC;GAC7B,CAAC,EACY"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-cloudflare-vectorize-memory",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "OpenClaw memory plugin for Cloudflare Vectorize and Workers AI embeddings.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",