@haaaiawd/second-nature 0.1.22 → 0.1.23
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/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/runtime/cli/commands/connector-init.d.ts +19 -0
- package/runtime/cli/commands/connector-init.js +168 -0
- package/runtime/cli/commands/connector-status.d.ts +12 -0
- package/runtime/cli/commands/connector-status.js +156 -0
- package/runtime/cli/commands/index.js +40 -0
- package/runtime/cli/ops/ops-router.d.ts +5 -0
- package/runtime/cli/ops/ops-router.js +34 -0
- package/runtime/cli/ops/workspace-heartbeat-runner.js +22 -0
- package/runtime/connectors/base/manifest.d.ts +13 -0
- package/runtime/connectors/base/manifest.js +47 -0
- package/runtime/connectors/manifest/manifest-parser.d.ts +16 -0
- package/runtime/connectors/manifest/manifest-parser.js +35 -0
- package/runtime/connectors/manifest/manifest-schema.d.ts +145 -0
- package/runtime/connectors/manifest/manifest-schema.js +51 -0
- package/runtime/connectors/registry/dynamic-connector-registry.d.ts +29 -0
- package/runtime/connectors/registry/dynamic-connector-registry.js +123 -0
- package/runtime/connectors/registry/index.d.ts +3 -0
- package/runtime/connectors/registry/index.js +3 -0
- package/runtime/connectors/registry/manifest-scanner.d.ts +9 -0
- package/runtime/connectors/registry/manifest-scanner.js +29 -0
- package/runtime/connectors/registry/trust-policy.d.ts +13 -0
- package/runtime/connectors/registry/trust-policy.js +37 -0
- package/runtime/core/second-nature/heartbeat/heartbeat-loop.d.ts +3 -0
- package/runtime/core/second-nature/heartbeat/heartbeat-loop.js +52 -1
- package/runtime/core/second-nature/heartbeat/snapshot-builder.d.ts +3 -0
- package/runtime/core/second-nature/orchestrator/goal-priority.d.ts +19 -0
- package/runtime/core/second-nature/orchestrator/goal-priority.js +67 -0
- package/runtime/core/second-nature/orchestrator/intent-planner.js +8 -0
- package/runtime/core/second-nature/orchestrator/narrative-update.d.ts +27 -0
- package/runtime/core/second-nature/orchestrator/narrative-update.js +107 -0
- package/runtime/core/second-nature/types.d.ts +4 -0
- package/runtime/guidance/draft-narrative-outreach.d.ts +36 -0
- package/runtime/guidance/draft-narrative-outreach.js +84 -0
- package/runtime/guidance/index.d.ts +1 -0
- package/runtime/guidance/index.js +1 -0
- package/runtime/guidance/outreach-draft-schema.d.ts +3 -3
- package/runtime/observability/connector-inventory-ledger.d.ts +45 -0
- package/runtime/observability/connector-inventory-ledger.js +72 -0
- package/runtime/observability/db/index.js +13 -0
- package/runtime/observability/db/schema/connector-inventory.d.ts +174 -0
- package/runtime/observability/db/schema/connector-inventory.js +15 -0
- package/runtime/observability/db/schema/index.d.ts +1 -0
- package/runtime/observability/db/schema/index.js +1 -0
- package/runtime/storage/chronicle/session-chronicle-store.d.ts +42 -0
- package/runtime/storage/chronicle/session-chronicle-store.js +66 -0
- package/runtime/storage/db/index.js +75 -0
- package/runtime/storage/db/schema/agent-goal.d.ts +235 -0
- package/runtime/storage/db/schema/agent-goal.js +19 -0
- package/runtime/storage/db/schema/index.d.ts +5 -0
- package/runtime/storage/db/schema/index.js +5 -0
- package/runtime/storage/db/schema/memory-store.d.ts +199 -0
- package/runtime/storage/db/schema/memory-store.js +18 -0
- package/runtime/storage/db/schema/narrative-state.d.ts +195 -0
- package/runtime/storage/db/schema/narrative-state.js +16 -0
- package/runtime/storage/db/schema/relationship-memory.d.ts +174 -0
- package/runtime/storage/db/schema/relationship-memory.js +14 -0
- package/runtime/storage/db/schema/session-chronicle.d.ts +199 -0
- package/runtime/storage/db/schema/session-chronicle.js +18 -0
- package/runtime/storage/goal/agent-goal-store.d.ts +57 -0
- package/runtime/storage/goal/agent-goal-store.js +109 -0
- package/runtime/storage/index.d.ts +5 -0
- package/runtime/storage/index.js +5 -0
- package/runtime/storage/memory-store/memory-store-lifecycle.d.ts +70 -0
- package/runtime/storage/memory-store/memory-store-lifecycle.js +113 -0
- package/runtime/storage/narrative/narrative-state-store.d.ts +40 -0
- package/runtime/storage/narrative/narrative-state-store.js +79 -0
- package/runtime/storage/relationship/relationship-memory-store.d.ts +42 -0
- package/runtime/storage/relationship/relationship-memory-store.js +76 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { eq } from "drizzle-orm";
|
|
2
|
+
import { narrativeState } from "../db/schema/narrative-state.js";
|
|
3
|
+
function safeParseJson(json, fallback) {
|
|
4
|
+
try {
|
|
5
|
+
return JSON.parse(json);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return fallback;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function rowToState(row) {
|
|
12
|
+
return {
|
|
13
|
+
narrativeId: row.narrativeId,
|
|
14
|
+
revision: row.revision,
|
|
15
|
+
focus: row.focus,
|
|
16
|
+
progress: safeParseJson(row.progressJson, []),
|
|
17
|
+
nextIntent: row.nextIntent,
|
|
18
|
+
confidence: row.confidence,
|
|
19
|
+
sourceRefs: safeParseJson(row.sourceRefsJson, []),
|
|
20
|
+
unsupportedClaims: safeParseJson(row.unsupportedClaimsJson, []),
|
|
21
|
+
status: row.status,
|
|
22
|
+
updatedAt: row.updatedAt,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const DEFAULT_NARRATIVE_ID = "default";
|
|
26
|
+
export function createNarrativeStateStore(database) {
|
|
27
|
+
const db = database.db;
|
|
28
|
+
return {
|
|
29
|
+
async updateNarrativeState(input) {
|
|
30
|
+
const existing = await db
|
|
31
|
+
.select()
|
|
32
|
+
.from(narrativeState)
|
|
33
|
+
.where(eq(narrativeState.narrativeId, input.narrativeId))
|
|
34
|
+
.limit(1);
|
|
35
|
+
if (existing.length > 0) {
|
|
36
|
+
await db
|
|
37
|
+
.update(narrativeState)
|
|
38
|
+
.set({
|
|
39
|
+
revision: input.revision,
|
|
40
|
+
focus: input.focus,
|
|
41
|
+
progressJson: JSON.stringify(input.progress),
|
|
42
|
+
nextIntent: input.nextIntent,
|
|
43
|
+
confidence: input.confidence,
|
|
44
|
+
sourceRefsJson: JSON.stringify(input.sourceRefs),
|
|
45
|
+
unsupportedClaimsJson: JSON.stringify(input.unsupportedClaims),
|
|
46
|
+
status: input.status,
|
|
47
|
+
updatedAt: input.updatedAt,
|
|
48
|
+
})
|
|
49
|
+
.where(eq(narrativeState.narrativeId, input.narrativeId));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
await db.insert(narrativeState).values({
|
|
53
|
+
narrativeId: input.narrativeId,
|
|
54
|
+
revision: input.revision,
|
|
55
|
+
focus: input.focus,
|
|
56
|
+
progressJson: JSON.stringify(input.progress),
|
|
57
|
+
nextIntent: input.nextIntent,
|
|
58
|
+
confidence: input.confidence,
|
|
59
|
+
sourceRefsJson: JSON.stringify(input.sourceRefs),
|
|
60
|
+
unsupportedClaimsJson: JSON.stringify(input.unsupportedClaims),
|
|
61
|
+
status: input.status,
|
|
62
|
+
updatedAt: input.updatedAt,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return { narrativeId: input.narrativeId, status: "acknowledged" };
|
|
66
|
+
},
|
|
67
|
+
async loadNarrativeState(narrativeId) {
|
|
68
|
+
const id = narrativeId ?? DEFAULT_NARRATIVE_ID;
|
|
69
|
+
const rows = await db
|
|
70
|
+
.select()
|
|
71
|
+
.from(narrativeState)
|
|
72
|
+
.where(eq(narrativeState.narrativeId, id))
|
|
73
|
+
.limit(1);
|
|
74
|
+
if (rows.length === 0)
|
|
75
|
+
return null;
|
|
76
|
+
return rowToState(rows[0]);
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { StateDatabase } from "../db/index.js";
|
|
2
|
+
export interface SourceRef {
|
|
3
|
+
sourceId: string;
|
|
4
|
+
kind: string;
|
|
5
|
+
url?: string;
|
|
6
|
+
snippet?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface TopicAffinity {
|
|
9
|
+
topic: string;
|
|
10
|
+
affinity: number;
|
|
11
|
+
}
|
|
12
|
+
export interface RelationshipMemory {
|
|
13
|
+
relationshipId: string;
|
|
14
|
+
revision: number;
|
|
15
|
+
tonePreference: "casual" | "direct" | "quiet" | "unknown";
|
|
16
|
+
averageReplyDelayMinutes?: number;
|
|
17
|
+
noReplyCount: number;
|
|
18
|
+
topicAffinities: TopicAffinity[];
|
|
19
|
+
lastInteractionAt?: string;
|
|
20
|
+
sourceRefs: SourceRef[];
|
|
21
|
+
updatedAt: string;
|
|
22
|
+
}
|
|
23
|
+
export interface RelationshipMemoryUpdate {
|
|
24
|
+
relationshipId: string;
|
|
25
|
+
revision: number;
|
|
26
|
+
tonePreference: "casual" | "direct" | "quiet" | "unknown";
|
|
27
|
+
averageReplyDelayMinutes?: number;
|
|
28
|
+
noReplyCount: number;
|
|
29
|
+
topicAffinities: TopicAffinity[];
|
|
30
|
+
lastInteractionAt?: string;
|
|
31
|
+
sourceRefs: SourceRef[];
|
|
32
|
+
updatedAt: string;
|
|
33
|
+
}
|
|
34
|
+
export interface RelationshipMemoryWriteAck {
|
|
35
|
+
relationshipId: string;
|
|
36
|
+
status: "acknowledged" | "degraded";
|
|
37
|
+
}
|
|
38
|
+
export interface RelationshipMemoryStore {
|
|
39
|
+
upsertRelationshipMemory(input: RelationshipMemoryUpdate): Promise<RelationshipMemoryWriteAck>;
|
|
40
|
+
loadRelationshipMemory(relationshipId?: string): Promise<RelationshipMemory | null>;
|
|
41
|
+
}
|
|
42
|
+
export declare function createRelationshipMemoryStore(database: StateDatabase): RelationshipMemoryStore;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { eq } from "drizzle-orm";
|
|
2
|
+
import { relationshipMemory } from "../db/schema/relationship-memory.js";
|
|
3
|
+
function safeParseJson(json, fallback) {
|
|
4
|
+
try {
|
|
5
|
+
return JSON.parse(json);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return fallback;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function rowToMemory(row) {
|
|
12
|
+
return {
|
|
13
|
+
relationshipId: row.relationshipId,
|
|
14
|
+
revision: row.revision,
|
|
15
|
+
tonePreference: row.tonePreference,
|
|
16
|
+
averageReplyDelayMinutes: row.averageReplyDelayMinutes ?? undefined,
|
|
17
|
+
noReplyCount: row.noReplyCount,
|
|
18
|
+
topicAffinities: safeParseJson(row.topicAffinitiesJson, []),
|
|
19
|
+
lastInteractionAt: row.lastInteractionAt ?? undefined,
|
|
20
|
+
sourceRefs: safeParseJson(row.sourceRefsJson, []),
|
|
21
|
+
updatedAt: row.updatedAt,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const DEFAULT_RELATIONSHIP_ID = "default";
|
|
25
|
+
export function createRelationshipMemoryStore(database) {
|
|
26
|
+
const db = database.db;
|
|
27
|
+
return {
|
|
28
|
+
async upsertRelationshipMemory(input) {
|
|
29
|
+
const existing = await db
|
|
30
|
+
.select()
|
|
31
|
+
.from(relationshipMemory)
|
|
32
|
+
.where(eq(relationshipMemory.relationshipId, input.relationshipId))
|
|
33
|
+
.limit(1);
|
|
34
|
+
if (existing.length > 0) {
|
|
35
|
+
await db
|
|
36
|
+
.update(relationshipMemory)
|
|
37
|
+
.set({
|
|
38
|
+
revision: input.revision,
|
|
39
|
+
tonePreference: input.tonePreference,
|
|
40
|
+
averageReplyDelayMinutes: input.averageReplyDelayMinutes ?? null,
|
|
41
|
+
noReplyCount: input.noReplyCount,
|
|
42
|
+
topicAffinitiesJson: JSON.stringify(input.topicAffinities),
|
|
43
|
+
lastInteractionAt: input.lastInteractionAt ?? null,
|
|
44
|
+
sourceRefsJson: JSON.stringify(input.sourceRefs),
|
|
45
|
+
updatedAt: input.updatedAt,
|
|
46
|
+
})
|
|
47
|
+
.where(eq(relationshipMemory.relationshipId, input.relationshipId));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
await db.insert(relationshipMemory).values({
|
|
51
|
+
relationshipId: input.relationshipId,
|
|
52
|
+
revision: input.revision,
|
|
53
|
+
tonePreference: input.tonePreference,
|
|
54
|
+
averageReplyDelayMinutes: input.averageReplyDelayMinutes ?? null,
|
|
55
|
+
noReplyCount: input.noReplyCount,
|
|
56
|
+
topicAffinitiesJson: JSON.stringify(input.topicAffinities),
|
|
57
|
+
lastInteractionAt: input.lastInteractionAt ?? null,
|
|
58
|
+
sourceRefsJson: JSON.stringify(input.sourceRefs),
|
|
59
|
+
updatedAt: input.updatedAt,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return { relationshipId: input.relationshipId, status: "acknowledged" };
|
|
63
|
+
},
|
|
64
|
+
async loadRelationshipMemory(relationshipId) {
|
|
65
|
+
const id = relationshipId ?? DEFAULT_RELATIONSHIP_ID;
|
|
66
|
+
const rows = await db
|
|
67
|
+
.select()
|
|
68
|
+
.from(relationshipMemory)
|
|
69
|
+
.where(eq(relationshipMemory.relationshipId, id))
|
|
70
|
+
.limit(1);
|
|
71
|
+
if (rows.length === 0)
|
|
72
|
+
return null;
|
|
73
|
+
return rowToMemory(rows[0]);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|