@tpsdev-ai/flair 0.3.12 → 0.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/config.yaml CHANGED
@@ -10,6 +10,10 @@ graphqlSchema:
10
10
  jsResource:
11
11
  files: dist/resources/*.js
12
12
 
13
+ 'harper-fabric-embeddings':
14
+ package: 'harper-fabric-embeddings'
15
+ modelName: nomic-embed-text
16
+
13
17
  authentication:
14
18
  # Default secure. Set to false for local development only.
15
19
  authorizeLocal: true
@@ -1,6 +1,7 @@
1
1
  import { databases } from "@harperfast/harper";
2
2
  import { patchRecord } from "./table-helpers.js";
3
3
  import { isAdmin } from "./auth-middleware.js";
4
+ import { getEmbedding } from "./embeddings-provider.js";
4
5
  export class Memory extends databases.flair.Memory {
5
6
  /**
6
7
  * Override search() to scope collection GETs by authenticated agent.
@@ -81,11 +82,23 @@ export class Memory extends databases.flair.Memory {
81
82
  const ttlHours = Number(process.env.FLAIR_EPHEMERAL_TTL_HOURS || 24);
82
83
  content.expiresAt = new Date(Date.now() + ttlHours * 3600_000).toISOString();
83
84
  }
85
+ // Generate embedding from content text
86
+ if (content.content && !content.embedding) {
87
+ const vec = await getEmbedding(content.content);
88
+ if (vec)
89
+ content.embedding = vec;
90
+ }
84
91
  return super.post(content);
85
92
  }
86
93
  async put(content) {
87
94
  const now = new Date().toISOString();
88
95
  content.updatedAt = now;
96
+ // Re-generate embedding if content changed
97
+ if (content.content && !content.embedding) {
98
+ const vec = await getEmbedding(content.content);
99
+ if (vec)
100
+ content.embedding = vec;
101
+ }
89
102
  // If archiving, record who + when
90
103
  if (content.archived === true && !content.archivedAt) {
91
104
  content.archivedAt = now;
@@ -20,15 +20,24 @@ export async function initEmbeddings() {
20
20
  const state = getState();
21
21
  if (state.initialized)
22
22
  return;
23
- try {
24
- await hfe.init({});
25
- state.available = true;
26
- console.log(`[embeddings] harper-fabric-embeddings ready (${hfe.dimensions()} dims)`);
27
- }
28
- catch (err) {
29
- console.log(`[embeddings] harper-fabric-embeddings unavailable: ${err.message}`);
30
- state.available = false;
23
+ // harper-fabric-embeddings is initialized by Harper as a sub-component
24
+ // (declared in config.yaml). It inits in the background so it may not
25
+ // be ready when resources first load. Retry a few times before giving up.
26
+ for (let attempt = 1; attempt <= 10; attempt++) {
27
+ try {
28
+ const dims = hfe.dimensions();
29
+ state.available = true;
30
+ state.initialized = true;
31
+ console.log(`[embeddings] ready (${dims} dims, attempt ${attempt})`);
32
+ return;
33
+ }
34
+ catch {
35
+ if (attempt < 10)
36
+ await new Promise(r => setTimeout(r, 500));
37
+ }
31
38
  }
39
+ console.log("[embeddings] not available after 10 attempts — search will be keyword-only");
40
+ state.available = false;
32
41
  state.initialized = true;
33
42
  }
34
43
  export async function getEmbedding(text) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tpsdev-ai/flair",
3
- "version": "0.3.12",
3
+ "version": "0.3.14",
4
4
  "description": "Identity, memory, and soul for AI agents. Cryptographic identity (Ed25519), semantic memory with local embeddings, and persistent personality — all in a single process.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -1,6 +1,7 @@
1
1
  import { databases } from "@harperfast/harper";
2
2
  import { patchRecord } from "./table-helpers.js";
3
3
  import { isAdmin } from "./auth-middleware.js";
4
+ import { getEmbedding } from "./embeddings-provider.js";
4
5
 
5
6
  export class Memory extends (databases as any).flair.Memory {
6
7
  /**
@@ -90,6 +91,12 @@ export class Memory extends (databases as any).flair.Memory {
90
91
  content.expiresAt = new Date(Date.now() + ttlHours * 3600_000).toISOString();
91
92
  }
92
93
 
94
+ // Generate embedding from content text
95
+ if (content.content && !content.embedding) {
96
+ const vec = await getEmbedding(content.content);
97
+ if (vec) content.embedding = vec;
98
+ }
99
+
93
100
  return super.post(content);
94
101
  }
95
102
 
@@ -97,6 +104,12 @@ export class Memory extends (databases as any).flair.Memory {
97
104
  const now = new Date().toISOString();
98
105
  content.updatedAt = now;
99
106
 
107
+ // Re-generate embedding if content changed
108
+ if (content.content && !content.embedding) {
109
+ const vec = await getEmbedding(content.content);
110
+ if (vec) content.embedding = vec;
111
+ }
112
+
100
113
  // If archiving, record who + when
101
114
  if (content.archived === true && !content.archivedAt) {
102
115
  content.archivedAt = now;
@@ -28,14 +28,24 @@ function getState(): ProviderState {
28
28
  export async function initEmbeddings(): Promise<void> {
29
29
  const state = getState();
30
30
  if (state.initialized) return;
31
- try {
32
- await hfe.init({});
33
- state.available = true;
34
- console.log(`[embeddings] harper-fabric-embeddings ready (${hfe.dimensions()} dims)`);
35
- } catch (err: any) {
36
- console.log(`[embeddings] harper-fabric-embeddings unavailable: ${err.message}`);
37
- state.available = false;
31
+
32
+ // harper-fabric-embeddings is initialized by Harper as a sub-component
33
+ // (declared in config.yaml). It inits in the background so it may not
34
+ // be ready when resources first load. Retry a few times before giving up.
35
+ for (let attempt = 1; attempt <= 10; attempt++) {
36
+ try {
37
+ const dims = hfe.dimensions();
38
+ state.available = true;
39
+ state.initialized = true;
40
+ console.log(`[embeddings] ready (${dims} dims, attempt ${attempt})`);
41
+ return;
42
+ } catch {
43
+ if (attempt < 10) await new Promise(r => setTimeout(r, 500));
44
+ }
38
45
  }
46
+
47
+ console.log("[embeddings] not available after 10 attempts — search will be keyword-only");
48
+ state.available = false;
39
49
  state.initialized = true;
40
50
  }
41
51