@elizaos/plugin-goals 2.0.3-beta.5 → 2.0.3-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/goals.d.ts +16 -0
- package/dist/actions/goals.d.ts.map +1 -0
- package/dist/actions/goals.js +150 -0
- package/dist/actions/goals.js.map +1 -0
- package/dist/components/goals/GoalsSpatialView.d.ts +42 -0
- package/dist/components/goals/GoalsSpatialView.d.ts.map +1 -0
- package/dist/components/goals/GoalsSpatialView.js +149 -0
- package/dist/components/goals/GoalsSpatialView.js.map +1 -0
- package/dist/components/goals/GoalsView.d.ts +60 -0
- package/dist/components/goals/GoalsView.d.ts.map +1 -0
- package/dist/components/goals/GoalsView.js +150 -0
- package/dist/components/goals/GoalsView.js.map +1 -0
- package/dist/components/goals/goals-view-bundle.d.ts +2 -0
- package/dist/components/goals/goals-view-bundle.d.ts.map +1 -0
- package/dist/components/goals/goals-view-bundle.js +5 -0
- package/dist/components/goals/goals-view-bundle.js.map +1 -0
- package/dist/db/goals-repository.d.ts +54 -0
- package/dist/db/goals-repository.d.ts.map +1 -0
- package/dist/db/goals-repository.js +239 -0
- package/dist/db/goals-repository.js.map +1 -0
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +2 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/schema.d.ts +826 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +61 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/db/sql.d.ts +32 -0
- package/dist/db/sql.d.ts.map +1 -0
- package/dist/db/sql.js +130 -0
- package/dist/db/sql.js.map +1 -0
- package/dist/goal-grounding.d.ts +54 -0
- package/dist/goal-grounding.d.ts.map +1 -0
- package/dist/goal-grounding.js +148 -0
- package/dist/goal-grounding.js.map +1 -0
- package/dist/goal-normalize.d.ts +30 -0
- package/dist/goal-normalize.d.ts.map +1 -0
- package/dist/goal-normalize.js +99 -0
- package/dist/goal-normalize.js.map +1 -0
- package/dist/goal-semantic-evaluator.d.ts +12 -0
- package/dist/goal-semantic-evaluator.d.ts.map +1 -0
- package/dist/goal-semantic-evaluator.js +208 -0
- package/dist/goal-semantic-evaluator.js.map +1 -0
- package/dist/goals-runtime.d.ts +34 -0
- package/dist/goals-runtime.d.ts.map +1 -0
- package/dist/goals-runtime.js +44 -0
- package/dist/goals-runtime.js.map +1 -0
- package/dist/goals-service.d.ts +68 -0
- package/dist/goals-service.d.ts.map +1 -0
- package/dist/goals-service.js +293 -0
- package/dist/goals-service.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +13 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +47 -0
- package/dist/plugin.js.map +1 -0
- package/dist/register-terminal-view.d.ts +15 -0
- package/dist/register-terminal-view.d.ts.map +1 -0
- package/dist/register-terminal-view.js +25 -0
- package/dist/register-terminal-view.js.map +1 -0
- package/dist/register.d.ts +9 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +5 -0
- package/dist/register.js.map +1 -0
- package/dist/services/checkin.d.ts +23 -0
- package/dist/services/checkin.d.ts.map +1 -0
- package/dist/services/checkin.js +27 -0
- package/dist/services/checkin.js.map +1 -0
- package/dist/services/migration.d.ts +49 -0
- package/dist/services/migration.d.ts.map +1 -0
- package/dist/services/migration.js +113 -0
- package/dist/services/migration.js.map +1 -0
- package/dist/types.d.ts +49 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +53 -0
- package/dist/types.js.map +1 -0
- package/dist/views/bundle.js +304 -0
- package/dist/views/bundle.js.map +1 -0
- package/package.json +9 -9
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IAgentRuntime } from "@elizaos/core";
|
|
2
|
+
import type { LifeOpsGoalDefinition } from "@elizaos/shared";
|
|
3
|
+
import { type GoalSemanticReviewMetadata } from "./goal-grounding.js";
|
|
4
|
+
export interface GoalSemanticEvaluationResult extends GoalSemanticReviewMetadata {
|
|
5
|
+
}
|
|
6
|
+
export declare function evaluateGoalProgressWithLlm(args: {
|
|
7
|
+
runtime: IAgentRuntime;
|
|
8
|
+
evidence: Record<string, unknown>;
|
|
9
|
+
goal: LifeOpsGoalDefinition;
|
|
10
|
+
nowIso: string;
|
|
11
|
+
}): Promise<GoalSemanticEvaluationResult | null>;
|
|
12
|
+
//# sourceMappingURL=goal-semantic-evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goal-semantic-evaluator.d.ts","sourceRoot":"","sources":["../src/goal-semantic-evaluator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAOnD,OAAO,KAAK,EACV,qBAAqB,EAGtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,KAAK,0BAA0B,EAEhC,MAAM,qBAAqB,CAAC;AAgB7B,MAAM,WAAW,4BACf,SAAQ,0BAA0B;CAAG;AA+LvC,wBAAsB,2BAA2B,CAAC,IAAI,EAAE;IACtD,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,IAAI,EAAE,qBAAqB,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC,4BAA4B,GAAG,IAAI,CAAC,CAiD/C"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import {
|
|
2
|
+
logger,
|
|
3
|
+
ModelType,
|
|
4
|
+
parseJsonModelRecord,
|
|
5
|
+
runWithTrajectoryContext
|
|
6
|
+
} from "@elizaos/core";
|
|
7
|
+
import {
|
|
8
|
+
buildGoalSemanticReviewMetadata
|
|
9
|
+
} from "./goal-grounding.js";
|
|
10
|
+
const VALID_REVIEW_STATES = /* @__PURE__ */ new Set([
|
|
11
|
+
"idle",
|
|
12
|
+
"needs_attention",
|
|
13
|
+
"on_track",
|
|
14
|
+
"at_risk"
|
|
15
|
+
]);
|
|
16
|
+
const VALID_SUGGESTION_KINDS = /* @__PURE__ */ new Set([
|
|
17
|
+
"create_support",
|
|
18
|
+
"focus_now",
|
|
19
|
+
"resolve_overdue",
|
|
20
|
+
"review_progress",
|
|
21
|
+
"tighten_cadence"
|
|
22
|
+
]);
|
|
23
|
+
function normalizeText(value) {
|
|
24
|
+
if (typeof value !== "string") {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const trimmed = value.trim();
|
|
28
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
29
|
+
}
|
|
30
|
+
function normalizeFiniteNumber(value) {
|
|
31
|
+
const parsedValue = typeof value === "string" && value.trim().length > 0 ? Number(value) : value;
|
|
32
|
+
if (typeof parsedValue !== "number" || !Number.isFinite(parsedValue)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return Math.max(0, Math.min(1, parsedValue));
|
|
36
|
+
}
|
|
37
|
+
function normalizeStringArray(value) {
|
|
38
|
+
if (typeof value === "string") {
|
|
39
|
+
return value.split(/\n|,/).map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
40
|
+
}
|
|
41
|
+
if (!Array.isArray(value)) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
return value.filter((entry) => typeof entry === "string").map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
45
|
+
}
|
|
46
|
+
function normalizeSuggestions(value) {
|
|
47
|
+
if (!Array.isArray(value)) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
return value.map((entry) => {
|
|
51
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const record = entry;
|
|
55
|
+
const title = normalizeText(record.title);
|
|
56
|
+
const detail = normalizeText(record.detail);
|
|
57
|
+
if (!title || !detail) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const kind = normalizeText(record.kind);
|
|
61
|
+
return {
|
|
62
|
+
kind: kind && VALID_SUGGESTION_KINDS.has(kind) ? kind : null,
|
|
63
|
+
title,
|
|
64
|
+
detail
|
|
65
|
+
};
|
|
66
|
+
}).filter((entry) => entry !== null);
|
|
67
|
+
}
|
|
68
|
+
function formatPromptValue(value, depth = 0) {
|
|
69
|
+
const indent = " ".repeat(depth);
|
|
70
|
+
const childIndent = " ".repeat(depth + 1);
|
|
71
|
+
if (value === null) return "null";
|
|
72
|
+
if (value === void 0) return "";
|
|
73
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
74
|
+
return String(value);
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(value)) {
|
|
77
|
+
if (value.length === 0) return "(none)";
|
|
78
|
+
return value.map((entry) => `${childIndent}- ${formatPromptValue(entry, depth + 1)}`).join("\n");
|
|
79
|
+
}
|
|
80
|
+
if (typeof value === "object") {
|
|
81
|
+
const entries = Object.entries(value);
|
|
82
|
+
if (entries.length === 0) return "(empty)";
|
|
83
|
+
return entries.map(([key, entry]) => {
|
|
84
|
+
const formatted = formatPromptValue(entry, depth + 1);
|
|
85
|
+
return formatted.includes("\n") ? `${indent}${key}:
|
|
86
|
+
${formatted}` : `${indent}${key}: ${formatted}`;
|
|
87
|
+
}).join("\n");
|
|
88
|
+
}
|
|
89
|
+
return String(value);
|
|
90
|
+
}
|
|
91
|
+
function buildSemanticEvaluationPrompt(args) {
|
|
92
|
+
return [
|
|
93
|
+
"Evaluate the user's goal semantically using the grounded goal contract and the evidence.",
|
|
94
|
+
"Do not rely only on linked support tasks. If the goal has direct evidence such as sleep data, use it.",
|
|
95
|
+
"Do not bluff. If the evidence is too weak, say so clearly and lower confidence.",
|
|
96
|
+
"",
|
|
97
|
+
"Return ONLY a JSON object with these fields:",
|
|
98
|
+
"reviewState: one of idle, needs_attention, on_track, at_risk",
|
|
99
|
+
"- progressScore: number from 0 to 1 or null if not enough evidence",
|
|
100
|
+
"- confidence: number from 0 to 1",
|
|
101
|
+
"- explanation: short grounded explanation",
|
|
102
|
+
"- evidenceSummary: short summary of the strongest evidence used",
|
|
103
|
+
"- missingEvidence: array of short evidence gaps",
|
|
104
|
+
"- suggestions: up to 3 objects with kind, title, and detail. kind must be one of create_support, focus_now, resolve_overdue, review_progress, tighten_cadence",
|
|
105
|
+
"",
|
|
106
|
+
'Example: {"reviewState":"needs_attention","progressScore":0.4,"confidence":0.65,"explanation":"Some supporting evidence exists, but the outcome evidence is thin.","evidenceSummary":"One recent support task was completed.","missingEvidence":["Direct outcome measurement"],"suggestions":[{"kind":"review_progress","title":"Review goal evidence","detail":"Ask for the latest measurement before changing status."}]}',
|
|
107
|
+
"",
|
|
108
|
+
"Guidance:",
|
|
109
|
+
"- Use on_track only when the available evidence supports progress.",
|
|
110
|
+
"- Use at_risk when the evidence suggests drift, missed targets, or contradictory outcomes.",
|
|
111
|
+
"- Use needs_attention when the goal is grounded but the evidence is insufficient or the support structure is weak.",
|
|
112
|
+
"- Use idle only when the goal is brand new and there is genuinely nothing to judge yet.",
|
|
113
|
+
"",
|
|
114
|
+
`Now: ${args.nowIso}`,
|
|
115
|
+
"Goal:",
|
|
116
|
+
formatPromptValue(args.goal),
|
|
117
|
+
"Evidence:",
|
|
118
|
+
formatPromptValue(args.evidence)
|
|
119
|
+
].join("\n");
|
|
120
|
+
}
|
|
121
|
+
function buildSemanticRepairPrompt(args) {
|
|
122
|
+
return [
|
|
123
|
+
"Your last reply for the goal semantic evaluator was invalid.",
|
|
124
|
+
"Return ONLY JSON with exactly these fields:",
|
|
125
|
+
"reviewState, progressScore, confidence, explanation, evidenceSummary, missingEvidence, suggestions",
|
|
126
|
+
"",
|
|
127
|
+
"reviewState must be one of idle, needs_attention, on_track, at_risk.",
|
|
128
|
+
"Use a missingEvidence array for evidence gaps.",
|
|
129
|
+
"Use a suggestions array of {kind,title,detail} objects.",
|
|
130
|
+
"",
|
|
131
|
+
`Now: ${args.nowIso}`,
|
|
132
|
+
"Goal:",
|
|
133
|
+
formatPromptValue(args.goal),
|
|
134
|
+
"Evidence:",
|
|
135
|
+
formatPromptValue(args.evidence),
|
|
136
|
+
"Previous invalid output:",
|
|
137
|
+
args.rawResponse
|
|
138
|
+
].join("\n");
|
|
139
|
+
}
|
|
140
|
+
function parseSemanticEvaluationOutput(raw) {
|
|
141
|
+
return parseJsonModelRecord(raw);
|
|
142
|
+
}
|
|
143
|
+
function buildSemanticEvaluationResult(parsed, nowIso) {
|
|
144
|
+
const reviewState = normalizeText(parsed.reviewState);
|
|
145
|
+
const explanation = normalizeText(parsed.explanation);
|
|
146
|
+
if (!reviewState || !VALID_REVIEW_STATES.has(reviewState) || !explanation) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
return buildGoalSemanticReviewMetadata({
|
|
150
|
+
confidence: normalizeFiniteNumber(parsed.confidence),
|
|
151
|
+
evidenceSummary: normalizeText(parsed.evidenceSummary),
|
|
152
|
+
explanation,
|
|
153
|
+
missingEvidence: normalizeStringArray(parsed.missingEvidence),
|
|
154
|
+
progressScore: normalizeFiniteNumber(parsed.progressScore),
|
|
155
|
+
reviewState,
|
|
156
|
+
reviewedAt: nowIso,
|
|
157
|
+
suggestions: normalizeSuggestions(parsed.suggestions)
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
async function evaluateGoalProgressWithLlm(args) {
|
|
161
|
+
if (typeof args.runtime.useModel !== "function") {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
const prompt = buildSemanticEvaluationPrompt(args);
|
|
165
|
+
try {
|
|
166
|
+
const raw = await runWithTrajectoryContext(
|
|
167
|
+
{ purpose: "lifeops-goal-evaluator-first-pass" },
|
|
168
|
+
() => args.runtime.useModel(ModelType.TEXT_LARGE, { prompt })
|
|
169
|
+
);
|
|
170
|
+
const parsed = parseSemanticEvaluationOutput(
|
|
171
|
+
typeof raw === "string" ? raw : ""
|
|
172
|
+
);
|
|
173
|
+
const evaluation = parsed ? buildSemanticEvaluationResult(parsed, args.nowIso) : null;
|
|
174
|
+
if (evaluation) {
|
|
175
|
+
return evaluation;
|
|
176
|
+
}
|
|
177
|
+
const repairedRaw = await runWithTrajectoryContext(
|
|
178
|
+
{ purpose: "lifeops-goal-evaluator-repair-pass" },
|
|
179
|
+
() => args.runtime.useModel(ModelType.TEXT_LARGE, {
|
|
180
|
+
prompt: buildSemanticRepairPrompt({
|
|
181
|
+
evidence: args.evidence,
|
|
182
|
+
goal: args.goal,
|
|
183
|
+
nowIso: args.nowIso,
|
|
184
|
+
rawResponse: typeof raw === "string" ? raw : ""
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
);
|
|
188
|
+
const repairedParsed = parseSemanticEvaluationOutput(
|
|
189
|
+
typeof repairedRaw === "string" ? repairedRaw : ""
|
|
190
|
+
);
|
|
191
|
+
return repairedParsed ? buildSemanticEvaluationResult(repairedParsed, args.nowIso) : null;
|
|
192
|
+
} catch (error) {
|
|
193
|
+
logger.warn(
|
|
194
|
+
{
|
|
195
|
+
boundary: "lifeops",
|
|
196
|
+
component: "goal-semantic-evaluator",
|
|
197
|
+
goalId: args.goal.id,
|
|
198
|
+
detail: error instanceof Error ? error.message : String(error)
|
|
199
|
+
},
|
|
200
|
+
"[goal-semantic-evaluator] evaluation failed; returning null"
|
|
201
|
+
);
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
export {
|
|
206
|
+
evaluateGoalProgressWithLlm
|
|
207
|
+
};
|
|
208
|
+
//# sourceMappingURL=goal-semantic-evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/goal-semantic-evaluator.ts"],"sourcesContent":["import type { IAgentRuntime } from \"@elizaos/core\";\nimport {\n logger,\n ModelType,\n parseJsonModelRecord,\n runWithTrajectoryContext,\n} from \"@elizaos/core\";\nimport type {\n LifeOpsGoalDefinition,\n LifeOpsGoalReviewState,\n LifeOpsGoalSuggestionKind,\n} from \"@elizaos/shared\";\nimport {\n buildGoalSemanticReviewMetadata,\n type GoalSemanticReviewMetadata,\n type GoalSemanticSuggestionMetadata,\n} from \"./goal-grounding.js\";\n\nconst VALID_REVIEW_STATES = new Set<LifeOpsGoalReviewState>([\n \"idle\",\n \"needs_attention\",\n \"on_track\",\n \"at_risk\",\n]);\nconst VALID_SUGGESTION_KINDS = new Set<LifeOpsGoalSuggestionKind>([\n \"create_support\",\n \"focus_now\",\n \"resolve_overdue\",\n \"review_progress\",\n \"tighten_cadence\",\n]);\n\nexport interface GoalSemanticEvaluationResult\n extends GoalSemanticReviewMetadata {}\n\nfunction normalizeText(value: unknown): string | null {\n if (typeof value !== \"string\") {\n return null;\n }\n const trimmed = value.trim();\n return trimmed.length > 0 ? trimmed : null;\n}\n\nfunction normalizeFiniteNumber(value: unknown): number | null {\n const parsedValue =\n typeof value === \"string\" && value.trim().length > 0\n ? Number(value)\n : value;\n if (typeof parsedValue !== \"number\" || !Number.isFinite(parsedValue)) {\n return null;\n }\n return Math.max(0, Math.min(1, parsedValue));\n}\n\nfunction normalizeStringArray(value: unknown): string[] {\n if (typeof value === \"string\") {\n return value\n .split(/\\n|,/)\n .map((entry) => entry.trim())\n .filter((entry) => entry.length > 0);\n }\n if (!Array.isArray(value)) {\n return [];\n }\n return value\n .filter((entry): entry is string => typeof entry === \"string\")\n .map((entry) => entry.trim())\n .filter((entry) => entry.length > 0);\n}\n\nfunction normalizeSuggestions(\n value: unknown,\n): GoalSemanticSuggestionMetadata[] {\n if (!Array.isArray(value)) {\n return [];\n }\n return value\n .map((entry) => {\n if (!entry || typeof entry !== \"object\" || Array.isArray(entry)) {\n return null;\n }\n const record = entry as Record<string, unknown>;\n const title = normalizeText(record.title);\n const detail = normalizeText(record.detail);\n if (!title || !detail) {\n return null;\n }\n const kind = normalizeText(record.kind);\n return {\n kind:\n kind && VALID_SUGGESTION_KINDS.has(kind as LifeOpsGoalSuggestionKind)\n ? kind\n : null,\n title,\n detail,\n };\n })\n .filter((entry): entry is GoalSemanticSuggestionMetadata => entry !== null);\n}\n\nfunction formatPromptValue(value: unknown, depth = 0): string {\n const indent = \" \".repeat(depth);\n const childIndent = \" \".repeat(depth + 1);\n if (value === null) return \"null\";\n if (value === undefined) return \"\";\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\"\n ) {\n return String(value);\n }\n if (Array.isArray(value)) {\n if (value.length === 0) return \"(none)\";\n return value\n .map((entry) => `${childIndent}- ${formatPromptValue(entry, depth + 1)}`)\n .join(\"\\n\");\n }\n if (typeof value === \"object\") {\n const entries = Object.entries(value as Record<string, unknown>);\n if (entries.length === 0) return \"(empty)\";\n return entries\n .map(([key, entry]) => {\n const formatted = formatPromptValue(entry, depth + 1);\n return formatted.includes(\"\\n\")\n ? `${indent}${key}:\\n${formatted}`\n : `${indent}${key}: ${formatted}`;\n })\n .join(\"\\n\");\n }\n return String(value);\n}\n\nfunction buildSemanticEvaluationPrompt(args: {\n evidence: Record<string, unknown>;\n goal: LifeOpsGoalDefinition;\n nowIso: string;\n}): string {\n return [\n \"Evaluate the user's goal semantically using the grounded goal contract and the evidence.\",\n \"Do not rely only on linked support tasks. If the goal has direct evidence such as sleep data, use it.\",\n \"Do not bluff. If the evidence is too weak, say so clearly and lower confidence.\",\n \"\",\n \"Return ONLY a JSON object with these fields:\",\n \"reviewState: one of idle, needs_attention, on_track, at_risk\",\n \"- progressScore: number from 0 to 1 or null if not enough evidence\",\n \"- confidence: number from 0 to 1\",\n \"- explanation: short grounded explanation\",\n \"- evidenceSummary: short summary of the strongest evidence used\",\n \"- missingEvidence: array of short evidence gaps\",\n \"- suggestions: up to 3 objects with kind, title, and detail. kind must be one of create_support, focus_now, resolve_overdue, review_progress, tighten_cadence\",\n \"\",\n 'Example: {\"reviewState\":\"needs_attention\",\"progressScore\":0.4,\"confidence\":0.65,\"explanation\":\"Some supporting evidence exists, but the outcome evidence is thin.\",\"evidenceSummary\":\"One recent support task was completed.\",\"missingEvidence\":[\"Direct outcome measurement\"],\"suggestions\":[{\"kind\":\"review_progress\",\"title\":\"Review goal evidence\",\"detail\":\"Ask for the latest measurement before changing status.\"}]}',\n \"\",\n \"Guidance:\",\n \"- Use on_track only when the available evidence supports progress.\",\n \"- Use at_risk when the evidence suggests drift, missed targets, or contradictory outcomes.\",\n \"- Use needs_attention when the goal is grounded but the evidence is insufficient or the support structure is weak.\",\n \"- Use idle only when the goal is brand new and there is genuinely nothing to judge yet.\",\n \"\",\n `Now: ${args.nowIso}`,\n \"Goal:\",\n formatPromptValue(args.goal),\n \"Evidence:\",\n formatPromptValue(args.evidence),\n ].join(\"\\n\");\n}\n\nfunction buildSemanticRepairPrompt(args: {\n evidence: Record<string, unknown>;\n goal: LifeOpsGoalDefinition;\n nowIso: string;\n rawResponse: string;\n}): string {\n return [\n \"Your last reply for the goal semantic evaluator was invalid.\",\n \"Return ONLY JSON with exactly these fields:\",\n \"reviewState, progressScore, confidence, explanation, evidenceSummary, missingEvidence, suggestions\",\n \"\",\n \"reviewState must be one of idle, needs_attention, on_track, at_risk.\",\n \"Use a missingEvidence array for evidence gaps.\",\n \"Use a suggestions array of {kind,title,detail} objects.\",\n \"\",\n `Now: ${args.nowIso}`,\n \"Goal:\",\n formatPromptValue(args.goal),\n \"Evidence:\",\n formatPromptValue(args.evidence),\n \"Previous invalid output:\",\n args.rawResponse,\n ].join(\"\\n\");\n}\n\nfunction parseSemanticEvaluationOutput(\n raw: string,\n): Record<string, unknown> | null {\n return parseJsonModelRecord<Record<string, unknown>>(raw);\n}\n\nfunction buildSemanticEvaluationResult(\n parsed: Record<string, unknown>,\n nowIso: string,\n): GoalSemanticEvaluationResult | null {\n const reviewState = normalizeText(parsed.reviewState);\n const explanation = normalizeText(parsed.explanation);\n if (\n !reviewState ||\n !VALID_REVIEW_STATES.has(reviewState as LifeOpsGoalReviewState) ||\n !explanation\n ) {\n return null;\n }\n return buildGoalSemanticReviewMetadata({\n confidence: normalizeFiniteNumber(parsed.confidence),\n evidenceSummary: normalizeText(parsed.evidenceSummary),\n explanation,\n missingEvidence: normalizeStringArray(parsed.missingEvidence),\n progressScore: normalizeFiniteNumber(parsed.progressScore),\n reviewState: reviewState as LifeOpsGoalReviewState,\n reviewedAt: nowIso,\n suggestions: normalizeSuggestions(parsed.suggestions),\n });\n}\n\nexport async function evaluateGoalProgressWithLlm(args: {\n runtime: IAgentRuntime;\n evidence: Record<string, unknown>;\n goal: LifeOpsGoalDefinition;\n nowIso: string;\n}): Promise<GoalSemanticEvaluationResult | null> {\n if (typeof args.runtime.useModel !== \"function\") {\n return null;\n }\n const prompt = buildSemanticEvaluationPrompt(args);\n try {\n const raw = await runWithTrajectoryContext(\n { purpose: \"lifeops-goal-evaluator-first-pass\" },\n () => args.runtime.useModel(ModelType.TEXT_LARGE, { prompt }),\n );\n const parsed = parseSemanticEvaluationOutput(\n typeof raw === \"string\" ? raw : \"\",\n );\n const evaluation = parsed\n ? buildSemanticEvaluationResult(parsed, args.nowIso)\n : null;\n if (evaluation) {\n return evaluation;\n }\n const repairedRaw = await runWithTrajectoryContext(\n { purpose: \"lifeops-goal-evaluator-repair-pass\" },\n () =>\n args.runtime.useModel(ModelType.TEXT_LARGE, {\n prompt: buildSemanticRepairPrompt({\n evidence: args.evidence,\n goal: args.goal,\n nowIso: args.nowIso,\n rawResponse: typeof raw === \"string\" ? raw : \"\",\n }),\n }),\n );\n const repairedParsed = parseSemanticEvaluationOutput(\n typeof repairedRaw === \"string\" ? repairedRaw : \"\",\n );\n return repairedParsed\n ? buildSemanticEvaluationResult(repairedParsed, args.nowIso)\n : null;\n } catch (error) {\n logger.warn(\n {\n boundary: \"lifeops\",\n component: \"goal-semantic-evaluator\",\n goalId: args.goal.id,\n detail: error instanceof Error ? error.message : String(error),\n },\n \"[goal-semantic-evaluator] evaluation failed; returning null\",\n );\n return null;\n }\n}\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AA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GoalsService} construction for the plugin-goals action and
|
|
3
|
+
* routes, with default hooks for the owner-scoped surface.
|
|
4
|
+
*
|
|
5
|
+
* The two PA-owned concerns the service needs are reproduced here for the
|
|
6
|
+
* PA-free deployment topology:
|
|
7
|
+
* - `normalizeOwnership` — the action drives the owner surface (ADMIN role,
|
|
8
|
+
* owner contexts), so goals are always owner-scoped. We return the fixed
|
|
9
|
+
* owner ownership (`user_lifeops` / `owner` / `owner_only` /
|
|
10
|
+
* `explicit_only`, subjectId = the agent's admin entity) that PA's
|
|
11
|
+
* `normalizeOwnership` produces for the owner case.
|
|
12
|
+
* - `recordAudit` — writes the goal audit event into PA's shared
|
|
13
|
+
* `app_lifeops.life_audit_events` table via {@link GoalsRepository}.
|
|
14
|
+
*
|
|
15
|
+
* When PA is loaded it constructs the {@link GoalsService} with its own
|
|
16
|
+
* `recordAudit` / `normalizeOwnership` bound from the LifeOps service base, so
|
|
17
|
+
* the agent-scoped path and PA's domain invariants stay intact.
|
|
18
|
+
*/
|
|
19
|
+
import { type IAgentRuntime } from "@elizaos/core";
|
|
20
|
+
import type { LifeOpsOwnership } from "@elizaos/shared";
|
|
21
|
+
import { GoalsService } from "./goals-service.js";
|
|
22
|
+
/** Owner-entity id PA derives for the admin/owner entity of an agent. */
|
|
23
|
+
export declare function ownerEntityIdFor(runtime: IAgentRuntime): string;
|
|
24
|
+
/**
|
|
25
|
+
* Fixed owner-scope ownership. Matches the result of PA's `normalizeOwnership`
|
|
26
|
+
* for an owner request with no explicit overrides.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildOwnerOwnership(runtime: IAgentRuntime): LifeOpsOwnership;
|
|
29
|
+
/**
|
|
30
|
+
* Construct a {@link GoalsService} bound to the owner surface with default
|
|
31
|
+
* hooks, for use without `@elizaos/plugin-personal-assistant`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createOwnerGoalsService(runtime: IAgentRuntime): GoalsService;
|
|
34
|
+
//# sourceMappingURL=goals-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goals-runtime.d.ts","sourceRoot":"","sources":["../src/goals-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,KAAK,aAAa,EAAgB,MAAM,eAAe,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAGL,YAAY,EACb,MAAM,oBAAoB,CAAC;AAE5B,yEAAyE;AACzE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAE/D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,gBAAgB,CAQ5E;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CA6B5E"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import { stringToUuid } from "@elizaos/core";
|
|
3
|
+
import { GoalsRepository } from "./db/goals-repository.js";
|
|
4
|
+
import { requireAgentId } from "./goal-normalize.js";
|
|
5
|
+
import {
|
|
6
|
+
GoalsService
|
|
7
|
+
} from "./goals-service.js";
|
|
8
|
+
function ownerEntityIdFor(runtime) {
|
|
9
|
+
return stringToUuid(`${requireAgentId(runtime)}-admin-entity`);
|
|
10
|
+
}
|
|
11
|
+
function buildOwnerOwnership(runtime) {
|
|
12
|
+
return {
|
|
13
|
+
domain: "user_lifeops",
|
|
14
|
+
subjectType: "owner",
|
|
15
|
+
subjectId: ownerEntityIdFor(runtime),
|
|
16
|
+
visibilityScope: "owner_only",
|
|
17
|
+
contextPolicy: "explicit_only"
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function createOwnerGoalsService(runtime) {
|
|
21
|
+
const repository = new GoalsRepository(runtime);
|
|
22
|
+
const normalizeOwnership = () => buildOwnerOwnership(runtime);
|
|
23
|
+
const recordAudit = async (eventType, ownerType, ownerId, reason, inputs, decision) => {
|
|
24
|
+
await repository.createAuditEvent({
|
|
25
|
+
id: crypto.randomUUID(),
|
|
26
|
+
agentId: requireAgentId(runtime),
|
|
27
|
+
eventType,
|
|
28
|
+
ownerType,
|
|
29
|
+
ownerId,
|
|
30
|
+
reason,
|
|
31
|
+
inputs,
|
|
32
|
+
decision,
|
|
33
|
+
actor: "user",
|
|
34
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
return new GoalsService(runtime, { recordAudit, normalizeOwnership });
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
buildOwnerOwnership,
|
|
41
|
+
createOwnerGoalsService,
|
|
42
|
+
ownerEntityIdFor
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=goals-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/goals-runtime.ts"],"sourcesContent":["/**\n * Standalone {@link GoalsService} construction for the plugin-goals action and\n * routes, with default hooks for the owner-scoped surface.\n *\n * The two PA-owned concerns the service needs are reproduced here for the\n * PA-free deployment topology:\n * - `normalizeOwnership` — the action drives the owner surface (ADMIN role,\n * owner contexts), so goals are always owner-scoped. We return the fixed\n * owner ownership (`user_lifeops` / `owner` / `owner_only` /\n * `explicit_only`, subjectId = the agent's admin entity) that PA's\n * `normalizeOwnership` produces for the owner case.\n * - `recordAudit` — writes the goal audit event into PA's shared\n * `app_lifeops.life_audit_events` table via {@link GoalsRepository}.\n *\n * When PA is loaded it constructs the {@link GoalsService} with its own\n * `recordAudit` / `normalizeOwnership` bound from the LifeOps service base, so\n * the agent-scoped path and PA's domain invariants stay intact.\n */\n\nimport crypto from \"node:crypto\";\nimport { type IAgentRuntime, stringToUuid } from \"@elizaos/core\";\nimport type { LifeOpsOwnership } from \"@elizaos/shared\";\nimport { GoalsRepository } from \"./db/goals-repository.js\";\nimport { requireAgentId } from \"./goal-normalize.js\";\nimport {\n type GoalsNormalizeOwnership,\n type GoalsRecordAudit,\n GoalsService,\n} from \"./goals-service.js\";\n\n/** Owner-entity id PA derives for the admin/owner entity of an agent. */\nexport function ownerEntityIdFor(runtime: IAgentRuntime): string {\n return stringToUuid(`${requireAgentId(runtime)}-admin-entity`);\n}\n\n/**\n * Fixed owner-scope ownership. Matches the result of PA's `normalizeOwnership`\n * for an owner request with no explicit overrides.\n */\nexport function buildOwnerOwnership(runtime: IAgentRuntime): LifeOpsOwnership {\n return {\n domain: \"user_lifeops\",\n subjectType: \"owner\",\n subjectId: ownerEntityIdFor(runtime),\n visibilityScope: \"owner_only\",\n contextPolicy: \"explicit_only\",\n };\n}\n\n/**\n * Construct a {@link GoalsService} bound to the owner surface with default\n * hooks, for use without `@elizaos/plugin-personal-assistant`.\n */\nexport function createOwnerGoalsService(runtime: IAgentRuntime): GoalsService {\n const repository = new GoalsRepository(runtime);\n\n const normalizeOwnership: GoalsNormalizeOwnership = () =>\n buildOwnerOwnership(runtime);\n\n const recordAudit: GoalsRecordAudit = async (\n eventType,\n ownerType,\n ownerId,\n reason,\n inputs,\n decision,\n ) => {\n await repository.createAuditEvent({\n id: crypto.randomUUID(),\n agentId: requireAgentId(runtime),\n eventType,\n ownerType,\n ownerId,\n reason,\n inputs,\n decision,\n actor: \"user\",\n createdAt: new Date().toISOString(),\n });\n };\n\n return new GoalsService(runtime, { recordAudit, normalizeOwnership });\n}\n"],"mappings":"AAmBA,OAAO,YAAY;AACnB,SAA6B,oBAAoB;AAEjD,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B;AAAA,EAGE;AAAA,OACK;AAGA,SAAS,iBAAiB,SAAgC;AAC/D,SAAO,aAAa,GAAG,eAAe,OAAO,CAAC,eAAe;AAC/D;AAMO,SAAS,oBAAoB,SAA0C;AAC5E,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,WAAW,iBAAiB,OAAO;AAAA,IACnC,iBAAiB;AAAA,IACjB,eAAe;AAAA,EACjB;AACF;AAMO,SAAS,wBAAwB,SAAsC;AAC5E,QAAM,aAAa,IAAI,gBAAgB,OAAO;AAE9C,QAAM,qBAA8C,MAClD,oBAAoB,OAAO;AAE7B,QAAM,cAAgC,OACpC,WACA,WACA,SACA,QACA,QACA,aACG;AACH,UAAM,WAAW,iBAAiB;AAAA,MAChC,IAAI,OAAO,WAAW;AAAA,MACtB,SAAS,eAAe,OAAO;AAAA,MAC/B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,IACpC,CAAC;AAAA,EACH;AAEA,SAAO,IAAI,aAAa,SAAS,EAAE,aAAa,mBAAmB,CAAC;AACtE;","names":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GoalsService — the goals back-end (goal CRUD + dedup + similarity scoring).
|
|
3
|
+
*
|
|
4
|
+
* Standalone successor to the goal CRUD half of PA's `withGoals` LifeOps
|
|
5
|
+
* service mixin. It holds its own runtime + {@link GoalsRepository} and the
|
|
6
|
+
* small identity helpers the methods need, so it has no dependency on
|
|
7
|
+
* `@elizaos/plugin-personal-assistant`. Behavior and the data it returns are
|
|
8
|
+
* preserved verbatim from the original mixin.
|
|
9
|
+
*
|
|
10
|
+
* Cross-domain goal logic is NOT here: goal review / overview / experience-loop
|
|
11
|
+
* (`reviewGoal`, `getOverview`, `buildGoalExperienceLoop`,
|
|
12
|
+
* `reviewGoalsForWeek`, `explainOccurrence`) aggregate PA's
|
|
13
|
+
* definition / occurrence / reminder / calendar / activity-signal graph, so
|
|
14
|
+
* they remain LifeOps mixin methods in PA.
|
|
15
|
+
*
|
|
16
|
+
* Two PA-owned concerns are taken as injected hooks rather than reimplemented:
|
|
17
|
+
* - `recordAudit` — audit events persist into PA's shared `app_lifeops` audit
|
|
18
|
+
* store; goal creates/updates/deletes record there exactly as before.
|
|
19
|
+
* - `normalizeOwnership` — ownership normalization carries PA's domain /
|
|
20
|
+
* subject rules and resolves the owner-entity / agent identity; it stays
|
|
21
|
+
* PA-owned and is passed in.
|
|
22
|
+
*/
|
|
23
|
+
import type { IAgentRuntime } from "@elizaos/core";
|
|
24
|
+
import { type CreateLifeOpsGoalRequest, type LifeOpsAuditEventType, type LifeOpsGoalDefinition, type LifeOpsGoalRecord, type LifeOpsOwnership, type LifeOpsOwnershipInput, type UpdateLifeOpsGoalRequest } from "@elizaos/shared";
|
|
25
|
+
import { GoalsRepository } from "./db/goals-repository.js";
|
|
26
|
+
/**
|
|
27
|
+
* Compute a 0..1 similarity score between a reference goal and an existing
|
|
28
|
+
* candidate. Used by {@link GoalsService.createGoal} for near-duplicate
|
|
29
|
+
* short-circuiting and (in PA) by the goal experience-loop matcher.
|
|
30
|
+
*/
|
|
31
|
+
export declare function scoreGoalSimilarity(args: {
|
|
32
|
+
reference: {
|
|
33
|
+
title: string;
|
|
34
|
+
description?: string | null;
|
|
35
|
+
successCriteria?: Record<string, unknown> | null;
|
|
36
|
+
};
|
|
37
|
+
candidate: LifeOpsGoalDefinition;
|
|
38
|
+
}): number;
|
|
39
|
+
/**
|
|
40
|
+
* Audit hook signature. Mirrors PA's `recordAudit` exactly; the goal back-end
|
|
41
|
+
* always passes `ownerType: "goal"`.
|
|
42
|
+
*/
|
|
43
|
+
export type GoalsRecordAudit = (eventType: LifeOpsAuditEventType, ownerType: "goal", ownerId: string, reason: string, inputs: Record<string, unknown>, decision: Record<string, unknown>) => Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Ownership-normalization hook signature. Mirrors PA's `normalizeOwnership`.
|
|
46
|
+
* Stays PA-owned because it resolves owner-entity / agent identity and applies
|
|
47
|
+
* PA's domain / subject invariants.
|
|
48
|
+
*/
|
|
49
|
+
export type GoalsNormalizeOwnership = (input: LifeOpsOwnershipInput | undefined, current?: LifeOpsOwnership) => LifeOpsOwnership;
|
|
50
|
+
export interface GoalsServiceDependencies {
|
|
51
|
+
recordAudit: GoalsRecordAudit;
|
|
52
|
+
normalizeOwnership: GoalsNormalizeOwnership;
|
|
53
|
+
}
|
|
54
|
+
export declare class GoalsService {
|
|
55
|
+
private readonly runtime;
|
|
56
|
+
readonly repository: GoalsRepository;
|
|
57
|
+
private readonly recordAudit;
|
|
58
|
+
private readonly normalizeOwnership;
|
|
59
|
+
constructor(runtime: IAgentRuntime, deps: GoalsServiceDependencies);
|
|
60
|
+
private agentId;
|
|
61
|
+
private getGoalRecord;
|
|
62
|
+
deleteGoal(goalId: string): Promise<void>;
|
|
63
|
+
listGoals(): Promise<LifeOpsGoalRecord[]>;
|
|
64
|
+
getGoal(goalId: string): Promise<LifeOpsGoalRecord>;
|
|
65
|
+
createGoal(request: CreateLifeOpsGoalRequest): Promise<LifeOpsGoalRecord>;
|
|
66
|
+
updateGoal(goalId: string, request: UpdateLifeOpsGoalRequest): Promise<LifeOpsGoalRecord>;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=goals-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goals-service.d.ts","sourceRoot":"","sources":["../src/goals-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,KAAK,wBAAwB,EAG7B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC9B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAoDlC;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IACxC,SAAS,EAAE;QACT,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC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