forge-openclaw-plugin 0.2.3 → 0.2.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/README.md +114 -6
- package/dist/assets/board-CzgvdLO8.js +6 -0
- package/dist/assets/board-CzgvdLO8.js.map +1 -0
- package/dist/assets/favicon-BCHm9dUV.ico +0 -0
- package/dist/assets/index-8d_oM8fL.js +27 -0
- package/dist/assets/index-8d_oM8fL.js.map +1 -0
- package/dist/assets/index-D4A_bq8m.css +1 -0
- package/dist/assets/motion-STUd1O46.js +10 -0
- package/dist/assets/motion-STUd1O46.js.map +1 -0
- package/dist/assets/plus-jakarta-sans-latin-ext-wght-normal-DmpS2jIq.woff2 +0 -0
- package/dist/assets/plus-jakarta-sans-latin-wght-normal-eXO_dkmS.woff2 +0 -0
- package/dist/assets/plus-jakarta-sans-vietnamese-wght-normal-qRpaaN48.woff2 +0 -0
- package/dist/assets/sora-latin-ext-wght-normal-CawQDOvP.woff2 +0 -0
- package/dist/assets/sora-latin-wght-normal-DdqRvwsR.woff2 +0 -0
- package/dist/assets/space-grotesk-latin-500-normal-CNSSEhBt.woff +0 -0
- package/dist/assets/space-grotesk-latin-500-normal-lFbtlQH6.woff2 +0 -0
- package/dist/assets/space-grotesk-latin-700-normal-CwsQ-cCU.woff +0 -0
- package/dist/assets/space-grotesk-latin-700-normal-RjhwGPKo.woff2 +0 -0
- package/dist/assets/space-grotesk-latin-ext-500-normal-3dgZTiw9.woff +0 -0
- package/dist/assets/space-grotesk-latin-ext-500-normal-DUe3BAxM.woff2 +0 -0
- package/dist/assets/space-grotesk-latin-ext-700-normal-BQnZhY3m.woff2 +0 -0
- package/dist/assets/space-grotesk-latin-ext-700-normal-HVCqSBdx.woff +0 -0
- package/dist/assets/space-grotesk-vietnamese-500-normal-BTqKIpxg.woff +0 -0
- package/dist/assets/space-grotesk-vietnamese-500-normal-BmEvtly_.woff2 +0 -0
- package/dist/assets/space-grotesk-vietnamese-700-normal-DMty7AZE.woff2 +0 -0
- package/dist/assets/space-grotesk-vietnamese-700-normal-Duxec5Rn.woff +0 -0
- package/dist/assets/table-CtNlETLc.js +23 -0
- package/dist/assets/table-CtNlETLc.js.map +1 -0
- package/dist/assets/ui-ThzkR_oW.js +46 -0
- package/dist/assets/ui-ThzkR_oW.js.map +1 -0
- package/dist/assets/vendor-CRS-psbw.css +1 -0
- package/dist/assets/vendor-DyHAI6nk.js +423 -0
- package/dist/assets/vendor-DyHAI6nk.js.map +1 -0
- package/dist/assets/viz-BJuBCz_G.js +34 -0
- package/dist/assets/viz-BJuBCz_G.js.map +1 -0
- package/dist/favicon.ico +0 -0
- package/dist/favicon.png +0 -0
- package/dist/index.html +29 -0
- package/dist/openclaw/api-client.d.ts +8 -0
- package/dist/openclaw/api-client.js +31 -4
- package/dist/openclaw/local-runtime.d.ts +3 -0
- package/dist/openclaw/local-runtime.js +135 -0
- package/dist/openclaw/parity.d.ts +4 -4
- package/dist/openclaw/parity.js +23 -33
- package/dist/openclaw/plugin-entry-shared.d.ts +5 -3
- package/dist/openclaw/plugin-entry-shared.js +52 -10
- package/dist/openclaw/routes.d.ts +12 -3
- package/dist/openclaw/routes.js +156 -924
- package/dist/openclaw/tools.js +242 -1100
- package/dist/server/app.js +2450 -0
- package/dist/server/db.js +313 -0
- package/dist/server/e2e-server.js +20 -0
- package/dist/server/errors.js +15 -0
- package/dist/server/index.js +16 -0
- package/dist/server/managers/base.js +17 -0
- package/dist/server/managers/contracts.js +47 -0
- package/dist/server/managers/platform/api-gateway-manager.js +11 -0
- package/dist/server/managers/platform/audit-manager.js +15 -0
- package/dist/server/managers/platform/authentication-manager.js +56 -0
- package/dist/server/managers/platform/authorization-manager.js +56 -0
- package/dist/server/managers/platform/background-job-manager.js +10 -0
- package/dist/server/managers/platform/configuration-manager.js +33 -0
- package/dist/server/managers/platform/database-manager.js +14 -0
- package/dist/server/managers/platform/event-bus-manager.js +7 -0
- package/dist/server/managers/platform/external-service-manager.js +11 -0
- package/dist/server/managers/platform/health-manager.js +7 -0
- package/dist/server/managers/platform/migration-manager.js +8 -0
- package/dist/server/managers/platform/search-index-manager.js +4 -0
- package/dist/server/managers/platform/secrets-manager.js +19 -0
- package/dist/server/managers/platform/session-manager.js +121 -0
- package/dist/server/managers/platform/storage-manager.js +16 -0
- package/dist/server/managers/platform/token-manager.js +37 -0
- package/dist/server/managers/platform/transaction-manager.js +8 -0
- package/dist/server/managers/platform/trusted-network.js +39 -0
- package/dist/server/managers/runtime.js +56 -0
- package/dist/server/managers/type-guards.js +4 -0
- package/dist/server/openapi.js +3512 -0
- package/dist/server/psyche-types.js +395 -0
- package/dist/server/repositories/activity-events.js +157 -0
- package/dist/server/repositories/collaboration.js +497 -0
- package/dist/server/repositories/comments.js +176 -0
- package/dist/server/repositories/deleted-entities.js +192 -0
- package/dist/server/repositories/domains.js +30 -0
- package/dist/server/repositories/event-log.js +64 -0
- package/dist/server/repositories/goals.js +159 -0
- package/dist/server/repositories/projects.js +214 -0
- package/dist/server/repositories/psyche.js +1356 -0
- package/dist/server/repositories/rewards.js +675 -0
- package/dist/server/repositories/settings.js +399 -0
- package/dist/server/repositories/tags.js +160 -0
- package/dist/server/repositories/task-runs.js +488 -0
- package/dist/server/repositories/tasks.js +413 -0
- package/dist/server/services/context.js +214 -0
- package/dist/server/services/dashboard.js +170 -0
- package/dist/server/services/entity-crud.js +576 -0
- package/dist/server/services/gamification.js +215 -0
- package/dist/server/services/insights.js +91 -0
- package/dist/server/services/projects.js +75 -0
- package/dist/server/services/psyche.js +63 -0
- package/dist/server/services/relations.js +28 -0
- package/dist/server/services/reviews.js +88 -0
- package/dist/server/services/run-recovery.js +13 -0
- package/dist/server/services/tagging.js +49 -0
- package/dist/server/services/task-run-watchdog.js +92 -0
- package/dist/server/services/work-time.js +176 -0
- package/dist/server/types.js +999 -0
- package/dist/server/web.js +91 -0
- package/openclaw.plugin.json +22 -10
- package/package.json +17 -4
- package/server/migrations/001_core.sql +333 -0
- package/server/migrations/002_psyche.sql +241 -0
- package/server/migrations/003_timer_execution.sql +18 -0
- package/server/migrations/004_psyche_linked_entities.sql +5 -0
- package/server/migrations/005_adaptive_schemas.sql +157 -0
- package/server/migrations/006_psyche_auth_setting.sql +4 -0
- package/server/migrations/007_deleted_entities.sql +16 -0
- package/skills/forge-openclaw/SKILL.md +189 -275
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const trimmedString = z.string().trim();
|
|
3
|
+
const nonEmptyTrimmedString = trimmedString.min(1);
|
|
4
|
+
const uniqueStringArraySchema = z.array(nonEmptyTrimmedString);
|
|
5
|
+
export const triggerReportStatusSchema = z.enum(["draft", "reviewed", "integrated"]);
|
|
6
|
+
export const commentSourceSchema = z.enum(["ui", "openclaw", "agent", "system"]);
|
|
7
|
+
export const behaviorKindSchema = z.enum(["away", "committed", "recovery"]);
|
|
8
|
+
export const beliefTypeSchema = z.enum(["absolute", "conditional"]);
|
|
9
|
+
export const modeFamilySchema = z.enum(["coping", "child", "critic_parent", "healthy_adult", "happy_child"]);
|
|
10
|
+
export const schemaTypeSchema = z.enum(["maladaptive", "adaptive"]);
|
|
11
|
+
export const PSYCHE_ENTITY_TYPES = [
|
|
12
|
+
"psyche_value",
|
|
13
|
+
"behavior_pattern",
|
|
14
|
+
"behavior",
|
|
15
|
+
"belief_entry",
|
|
16
|
+
"mode_profile",
|
|
17
|
+
"trigger_report"
|
|
18
|
+
];
|
|
19
|
+
export const domainSchema = z.object({
|
|
20
|
+
id: z.string(),
|
|
21
|
+
slug: nonEmptyTrimmedString,
|
|
22
|
+
title: nonEmptyTrimmedString,
|
|
23
|
+
description: trimmedString,
|
|
24
|
+
themeColor: z.string(),
|
|
25
|
+
sensitive: z.boolean(),
|
|
26
|
+
createdAt: z.string(),
|
|
27
|
+
updatedAt: z.string()
|
|
28
|
+
});
|
|
29
|
+
export const schemaCatalogEntrySchema = z.object({
|
|
30
|
+
id: z.string(),
|
|
31
|
+
slug: nonEmptyTrimmedString,
|
|
32
|
+
title: nonEmptyTrimmedString,
|
|
33
|
+
family: nonEmptyTrimmedString,
|
|
34
|
+
schemaType: schemaTypeSchema,
|
|
35
|
+
description: trimmedString,
|
|
36
|
+
createdAt: z.string(),
|
|
37
|
+
updatedAt: z.string()
|
|
38
|
+
});
|
|
39
|
+
export const eventTypeSchema = z.object({
|
|
40
|
+
id: z.string(),
|
|
41
|
+
domainId: z.string(),
|
|
42
|
+
label: nonEmptyTrimmedString,
|
|
43
|
+
description: trimmedString,
|
|
44
|
+
system: z.boolean(),
|
|
45
|
+
createdAt: z.string(),
|
|
46
|
+
updatedAt: z.string()
|
|
47
|
+
});
|
|
48
|
+
export const emotionDefinitionSchema = z.object({
|
|
49
|
+
id: z.string(),
|
|
50
|
+
domainId: z.string(),
|
|
51
|
+
label: nonEmptyTrimmedString,
|
|
52
|
+
description: trimmedString,
|
|
53
|
+
category: trimmedString,
|
|
54
|
+
system: z.boolean(),
|
|
55
|
+
createdAt: z.string(),
|
|
56
|
+
updatedAt: z.string()
|
|
57
|
+
});
|
|
58
|
+
export const psycheValueSchema = z.object({
|
|
59
|
+
id: z.string(),
|
|
60
|
+
domainId: z.string(),
|
|
61
|
+
title: nonEmptyTrimmedString,
|
|
62
|
+
description: trimmedString,
|
|
63
|
+
valuedDirection: trimmedString,
|
|
64
|
+
whyItMatters: trimmedString,
|
|
65
|
+
linkedGoalIds: uniqueStringArraySchema.default([]),
|
|
66
|
+
linkedProjectIds: uniqueStringArraySchema.default([]),
|
|
67
|
+
linkedTaskIds: uniqueStringArraySchema.default([]),
|
|
68
|
+
committedActions: z.array(trimmedString).default([]),
|
|
69
|
+
createdAt: z.string(),
|
|
70
|
+
updatedAt: z.string()
|
|
71
|
+
});
|
|
72
|
+
export const behaviorPatternSchema = z.object({
|
|
73
|
+
id: z.string(),
|
|
74
|
+
domainId: z.string(),
|
|
75
|
+
title: nonEmptyTrimmedString,
|
|
76
|
+
description: trimmedString,
|
|
77
|
+
targetBehavior: trimmedString,
|
|
78
|
+
cueContexts: z.array(trimmedString).default([]),
|
|
79
|
+
shortTermPayoff: trimmedString,
|
|
80
|
+
longTermCost: trimmedString,
|
|
81
|
+
preferredResponse: trimmedString,
|
|
82
|
+
linkedValueIds: uniqueStringArraySchema.default([]),
|
|
83
|
+
linkedSchemaLabels: z.array(trimmedString).default([]),
|
|
84
|
+
linkedModeLabels: z.array(trimmedString).default([]),
|
|
85
|
+
linkedModeIds: uniqueStringArraySchema.default([]),
|
|
86
|
+
linkedBeliefIds: uniqueStringArraySchema.default([]),
|
|
87
|
+
createdAt: z.string(),
|
|
88
|
+
updatedAt: z.string()
|
|
89
|
+
});
|
|
90
|
+
export const behaviorSchema = z.object({
|
|
91
|
+
id: z.string(),
|
|
92
|
+
domainId: z.string(),
|
|
93
|
+
kind: behaviorKindSchema,
|
|
94
|
+
title: nonEmptyTrimmedString,
|
|
95
|
+
description: trimmedString,
|
|
96
|
+
commonCues: z.array(trimmedString).default([]),
|
|
97
|
+
urgeStory: trimmedString,
|
|
98
|
+
shortTermPayoff: trimmedString,
|
|
99
|
+
longTermCost: trimmedString,
|
|
100
|
+
replacementMove: trimmedString,
|
|
101
|
+
repairPlan: trimmedString,
|
|
102
|
+
linkedPatternIds: uniqueStringArraySchema.default([]),
|
|
103
|
+
linkedValueIds: uniqueStringArraySchema.default([]),
|
|
104
|
+
linkedSchemaIds: uniqueStringArraySchema.default([]),
|
|
105
|
+
linkedModeIds: uniqueStringArraySchema.default([]),
|
|
106
|
+
createdAt: z.string(),
|
|
107
|
+
updatedAt: z.string()
|
|
108
|
+
});
|
|
109
|
+
export const beliefEntrySchema = z.object({
|
|
110
|
+
id: z.string(),
|
|
111
|
+
domainId: z.string(),
|
|
112
|
+
schemaId: z.string().nullable(),
|
|
113
|
+
statement: nonEmptyTrimmedString,
|
|
114
|
+
beliefType: beliefTypeSchema,
|
|
115
|
+
originNote: trimmedString,
|
|
116
|
+
confidence: z.number().int().min(0).max(100),
|
|
117
|
+
evidenceFor: z.array(trimmedString).default([]),
|
|
118
|
+
evidenceAgainst: z.array(trimmedString).default([]),
|
|
119
|
+
flexibleAlternative: trimmedString,
|
|
120
|
+
linkedValueIds: uniqueStringArraySchema.default([]),
|
|
121
|
+
linkedBehaviorIds: uniqueStringArraySchema.default([]),
|
|
122
|
+
linkedModeIds: uniqueStringArraySchema.default([]),
|
|
123
|
+
linkedReportIds: uniqueStringArraySchema.default([]),
|
|
124
|
+
createdAt: z.string(),
|
|
125
|
+
updatedAt: z.string()
|
|
126
|
+
});
|
|
127
|
+
export const modeProfileSchema = z.object({
|
|
128
|
+
id: z.string(),
|
|
129
|
+
domainId: z.string(),
|
|
130
|
+
family: modeFamilySchema,
|
|
131
|
+
archetype: trimmedString,
|
|
132
|
+
title: nonEmptyTrimmedString,
|
|
133
|
+
persona: trimmedString,
|
|
134
|
+
imagery: trimmedString,
|
|
135
|
+
symbolicForm: trimmedString,
|
|
136
|
+
facialExpression: trimmedString,
|
|
137
|
+
fear: trimmedString,
|
|
138
|
+
burden: trimmedString,
|
|
139
|
+
protectiveJob: trimmedString,
|
|
140
|
+
originContext: trimmedString,
|
|
141
|
+
firstAppearanceAt: z.string().nullable(),
|
|
142
|
+
linkedPatternIds: uniqueStringArraySchema.default([]),
|
|
143
|
+
linkedBehaviorIds: uniqueStringArraySchema.default([]),
|
|
144
|
+
linkedValueIds: uniqueStringArraySchema.default([]),
|
|
145
|
+
createdAt: z.string(),
|
|
146
|
+
updatedAt: z.string()
|
|
147
|
+
});
|
|
148
|
+
export const modeTimelineEntrySchema = z.object({
|
|
149
|
+
id: z.string(),
|
|
150
|
+
stage: nonEmptyTrimmedString,
|
|
151
|
+
modeId: z.string().nullable(),
|
|
152
|
+
label: nonEmptyTrimmedString,
|
|
153
|
+
note: trimmedString.default("")
|
|
154
|
+
});
|
|
155
|
+
export const modeGuideAnswerSchema = z.object({
|
|
156
|
+
questionKey: nonEmptyTrimmedString,
|
|
157
|
+
value: nonEmptyTrimmedString
|
|
158
|
+
});
|
|
159
|
+
export const modeGuideResultSchema = z.object({
|
|
160
|
+
family: modeFamilySchema,
|
|
161
|
+
archetype: trimmedString,
|
|
162
|
+
label: nonEmptyTrimmedString,
|
|
163
|
+
confidence: z.number().min(0).max(1),
|
|
164
|
+
reasoning: trimmedString
|
|
165
|
+
});
|
|
166
|
+
export const modeGuideSessionSchema = z.object({
|
|
167
|
+
id: z.string(),
|
|
168
|
+
summary: nonEmptyTrimmedString,
|
|
169
|
+
answers: z.array(modeGuideAnswerSchema),
|
|
170
|
+
results: z.array(modeGuideResultSchema),
|
|
171
|
+
createdAt: z.string(),
|
|
172
|
+
updatedAt: z.string()
|
|
173
|
+
});
|
|
174
|
+
export const triggerEmotionSchema = z.object({
|
|
175
|
+
id: z.string(),
|
|
176
|
+
emotionDefinitionId: z.string().nullable().default(null),
|
|
177
|
+
label: nonEmptyTrimmedString,
|
|
178
|
+
intensity: z.number().int().min(0).max(100),
|
|
179
|
+
note: trimmedString.default("")
|
|
180
|
+
});
|
|
181
|
+
export const triggerThoughtSchema = z.object({
|
|
182
|
+
id: z.string(),
|
|
183
|
+
text: nonEmptyTrimmedString,
|
|
184
|
+
parentMode: trimmedString.default(""),
|
|
185
|
+
criticMode: trimmedString.default(""),
|
|
186
|
+
beliefId: z.string().nullable().default(null)
|
|
187
|
+
});
|
|
188
|
+
export const triggerBehaviorSchema = z.object({
|
|
189
|
+
id: z.string(),
|
|
190
|
+
text: nonEmptyTrimmedString,
|
|
191
|
+
mode: trimmedString.default(""),
|
|
192
|
+
behaviorId: z.string().nullable().default(null)
|
|
193
|
+
});
|
|
194
|
+
export const triggerConsequencesSchema = z.object({
|
|
195
|
+
selfShortTerm: z.array(trimmedString).default([]),
|
|
196
|
+
selfLongTerm: z.array(trimmedString).default([]),
|
|
197
|
+
othersShortTerm: z.array(trimmedString).default([]),
|
|
198
|
+
othersLongTerm: z.array(trimmedString).default([])
|
|
199
|
+
});
|
|
200
|
+
export const triggerReportSchema = z.object({
|
|
201
|
+
id: z.string(),
|
|
202
|
+
domainId: z.string(),
|
|
203
|
+
title: nonEmptyTrimmedString,
|
|
204
|
+
status: triggerReportStatusSchema,
|
|
205
|
+
eventTypeId: z.string().nullable(),
|
|
206
|
+
customEventType: trimmedString,
|
|
207
|
+
eventSituation: trimmedString,
|
|
208
|
+
occurredAt: z.string().nullable(),
|
|
209
|
+
emotions: z.array(triggerEmotionSchema).default([]),
|
|
210
|
+
thoughts: z.array(triggerThoughtSchema).default([]),
|
|
211
|
+
behaviors: z.array(triggerBehaviorSchema).default([]),
|
|
212
|
+
consequences: triggerConsequencesSchema,
|
|
213
|
+
linkedPatternIds: uniqueStringArraySchema.default([]),
|
|
214
|
+
linkedValueIds: uniqueStringArraySchema.default([]),
|
|
215
|
+
linkedGoalIds: uniqueStringArraySchema.default([]),
|
|
216
|
+
linkedProjectIds: uniqueStringArraySchema.default([]),
|
|
217
|
+
linkedTaskIds: uniqueStringArraySchema.default([]),
|
|
218
|
+
linkedBehaviorIds: uniqueStringArraySchema.default([]),
|
|
219
|
+
linkedBeliefIds: uniqueStringArraySchema.default([]),
|
|
220
|
+
linkedModeIds: uniqueStringArraySchema.default([]),
|
|
221
|
+
modeOverlays: z.array(trimmedString).default([]),
|
|
222
|
+
schemaLinks: z.array(trimmedString).default([]),
|
|
223
|
+
modeTimeline: z.array(modeTimelineEntrySchema).default([]),
|
|
224
|
+
nextMoves: z.array(trimmedString).default([]),
|
|
225
|
+
createdAt: z.string(),
|
|
226
|
+
updatedAt: z.string()
|
|
227
|
+
});
|
|
228
|
+
export const commentSchema = z.object({
|
|
229
|
+
id: z.string(),
|
|
230
|
+
entityType: nonEmptyTrimmedString,
|
|
231
|
+
entityId: nonEmptyTrimmedString,
|
|
232
|
+
anchorKey: trimmedString.nullable(),
|
|
233
|
+
body: nonEmptyTrimmedString,
|
|
234
|
+
author: trimmedString.nullable(),
|
|
235
|
+
source: commentSourceSchema,
|
|
236
|
+
createdAt: z.string(),
|
|
237
|
+
updatedAt: z.string()
|
|
238
|
+
});
|
|
239
|
+
export const schemaPressureEntrySchema = z.object({
|
|
240
|
+
schemaId: z.string(),
|
|
241
|
+
title: nonEmptyTrimmedString,
|
|
242
|
+
activationCount: z.number().int().nonnegative()
|
|
243
|
+
});
|
|
244
|
+
export const psycheOverviewPayloadSchema = z.object({
|
|
245
|
+
generatedAt: z.string(),
|
|
246
|
+
domain: domainSchema,
|
|
247
|
+
values: z.array(psycheValueSchema),
|
|
248
|
+
patterns: z.array(behaviorPatternSchema),
|
|
249
|
+
behaviors: z.array(behaviorSchema),
|
|
250
|
+
beliefs: z.array(beliefEntrySchema),
|
|
251
|
+
modes: z.array(modeProfileSchema),
|
|
252
|
+
reports: z.array(triggerReportSchema),
|
|
253
|
+
schemaPressure: z.array(schemaPressureEntrySchema),
|
|
254
|
+
openInsights: z.number().int().nonnegative(),
|
|
255
|
+
unresolvedComments: z.number().int().nonnegative(),
|
|
256
|
+
committedActions: z.array(trimmedString)
|
|
257
|
+
});
|
|
258
|
+
export const createPsycheValueSchema = z.object({
|
|
259
|
+
title: nonEmptyTrimmedString,
|
|
260
|
+
description: trimmedString.default(""),
|
|
261
|
+
valuedDirection: trimmedString.default(""),
|
|
262
|
+
whyItMatters: trimmedString.default(""),
|
|
263
|
+
linkedGoalIds: uniqueStringArraySchema.default([]),
|
|
264
|
+
linkedProjectIds: uniqueStringArraySchema.default([]),
|
|
265
|
+
linkedTaskIds: uniqueStringArraySchema.default([]),
|
|
266
|
+
committedActions: z.array(trimmedString).default([])
|
|
267
|
+
});
|
|
268
|
+
export const updatePsycheValueSchema = createPsycheValueSchema.partial();
|
|
269
|
+
export const createBehaviorPatternSchema = z.object({
|
|
270
|
+
title: nonEmptyTrimmedString,
|
|
271
|
+
description: trimmedString.default(""),
|
|
272
|
+
targetBehavior: trimmedString.default(""),
|
|
273
|
+
cueContexts: z.array(trimmedString).default([]),
|
|
274
|
+
shortTermPayoff: trimmedString.default(""),
|
|
275
|
+
longTermCost: trimmedString.default(""),
|
|
276
|
+
preferredResponse: trimmedString.default(""),
|
|
277
|
+
linkedValueIds: uniqueStringArraySchema.default([]),
|
|
278
|
+
linkedSchemaLabels: z.array(trimmedString).default([]),
|
|
279
|
+
linkedModeLabels: z.array(trimmedString).default([]),
|
|
280
|
+
linkedModeIds: uniqueStringArraySchema.default([]),
|
|
281
|
+
linkedBeliefIds: uniqueStringArraySchema.default([])
|
|
282
|
+
});
|
|
283
|
+
export const updateBehaviorPatternSchema = createBehaviorPatternSchema.partial();
|
|
284
|
+
export const createBehaviorSchema = z.object({
|
|
285
|
+
kind: behaviorKindSchema,
|
|
286
|
+
title: nonEmptyTrimmedString,
|
|
287
|
+
description: trimmedString.default(""),
|
|
288
|
+
commonCues: z.array(trimmedString).default([]),
|
|
289
|
+
urgeStory: trimmedString.default(""),
|
|
290
|
+
shortTermPayoff: trimmedString.default(""),
|
|
291
|
+
longTermCost: trimmedString.default(""),
|
|
292
|
+
replacementMove: trimmedString.default(""),
|
|
293
|
+
repairPlan: trimmedString.default(""),
|
|
294
|
+
linkedPatternIds: uniqueStringArraySchema.default([]),
|
|
295
|
+
linkedValueIds: uniqueStringArraySchema.default([]),
|
|
296
|
+
linkedSchemaIds: uniqueStringArraySchema.default([]),
|
|
297
|
+
linkedModeIds: uniqueStringArraySchema.default([])
|
|
298
|
+
});
|
|
299
|
+
export const updateBehaviorSchema = createBehaviorSchema.partial();
|
|
300
|
+
export const createBeliefEntrySchema = z.object({
|
|
301
|
+
schemaId: z.string().nullable().default(null),
|
|
302
|
+
statement: nonEmptyTrimmedString,
|
|
303
|
+
beliefType: beliefTypeSchema,
|
|
304
|
+
originNote: trimmedString.default(""),
|
|
305
|
+
confidence: z.number().int().min(0).max(100).default(60),
|
|
306
|
+
evidenceFor: z.array(trimmedString).default([]),
|
|
307
|
+
evidenceAgainst: z.array(trimmedString).default([]),
|
|
308
|
+
flexibleAlternative: trimmedString.default(""),
|
|
309
|
+
linkedValueIds: uniqueStringArraySchema.default([]),
|
|
310
|
+
linkedBehaviorIds: uniqueStringArraySchema.default([]),
|
|
311
|
+
linkedModeIds: uniqueStringArraySchema.default([]),
|
|
312
|
+
linkedReportIds: uniqueStringArraySchema.default([])
|
|
313
|
+
});
|
|
314
|
+
export const updateBeliefEntrySchema = createBeliefEntrySchema.partial();
|
|
315
|
+
export const createModeProfileSchema = z.object({
|
|
316
|
+
family: modeFamilySchema,
|
|
317
|
+
archetype: trimmedString.default(""),
|
|
318
|
+
title: nonEmptyTrimmedString,
|
|
319
|
+
persona: trimmedString.default(""),
|
|
320
|
+
imagery: trimmedString.default(""),
|
|
321
|
+
symbolicForm: trimmedString.default(""),
|
|
322
|
+
facialExpression: trimmedString.default(""),
|
|
323
|
+
fear: trimmedString.default(""),
|
|
324
|
+
burden: trimmedString.default(""),
|
|
325
|
+
protectiveJob: trimmedString.default(""),
|
|
326
|
+
originContext: trimmedString.default(""),
|
|
327
|
+
firstAppearanceAt: trimmedString.nullable().default(null),
|
|
328
|
+
linkedPatternIds: uniqueStringArraySchema.default([]),
|
|
329
|
+
linkedBehaviorIds: uniqueStringArraySchema.default([]),
|
|
330
|
+
linkedValueIds: uniqueStringArraySchema.default([])
|
|
331
|
+
});
|
|
332
|
+
export const updateModeProfileSchema = createModeProfileSchema.partial();
|
|
333
|
+
export const createModeGuideSessionSchema = z.object({
|
|
334
|
+
summary: nonEmptyTrimmedString,
|
|
335
|
+
answers: z.array(modeGuideAnswerSchema).min(1)
|
|
336
|
+
});
|
|
337
|
+
export const updateModeGuideSessionSchema = createModeGuideSessionSchema.partial();
|
|
338
|
+
export const createEventTypeSchema = z.object({
|
|
339
|
+
label: nonEmptyTrimmedString,
|
|
340
|
+
description: trimmedString.default("")
|
|
341
|
+
});
|
|
342
|
+
export const updateEventTypeSchema = createEventTypeSchema.partial();
|
|
343
|
+
export const createEmotionDefinitionSchema = z.object({
|
|
344
|
+
label: nonEmptyTrimmedString,
|
|
345
|
+
description: trimmedString.default(""),
|
|
346
|
+
category: trimmedString.default("")
|
|
347
|
+
});
|
|
348
|
+
export const updateEmotionDefinitionSchema = createEmotionDefinitionSchema.partial();
|
|
349
|
+
export const createTriggerReportSchema = z.object({
|
|
350
|
+
title: nonEmptyTrimmedString,
|
|
351
|
+
status: triggerReportStatusSchema.default("draft"),
|
|
352
|
+
eventTypeId: z.string().nullable().default(null),
|
|
353
|
+
customEventType: trimmedString.default(""),
|
|
354
|
+
eventSituation: trimmedString.default(""),
|
|
355
|
+
occurredAt: trimmedString.nullable().default(null),
|
|
356
|
+
emotions: z.array(triggerEmotionSchema.omit({ id: true }).extend({ id: z.string().optional() })).default([]),
|
|
357
|
+
thoughts: z.array(triggerThoughtSchema.omit({ id: true }).extend({ id: z.string().optional() })).default([]),
|
|
358
|
+
behaviors: z.array(triggerBehaviorSchema.omit({ id: true }).extend({ id: z.string().optional() })).default([]),
|
|
359
|
+
consequences: triggerConsequencesSchema.default({
|
|
360
|
+
selfShortTerm: [],
|
|
361
|
+
selfLongTerm: [],
|
|
362
|
+
othersShortTerm: [],
|
|
363
|
+
othersLongTerm: []
|
|
364
|
+
}),
|
|
365
|
+
linkedPatternIds: uniqueStringArraySchema.default([]),
|
|
366
|
+
linkedValueIds: uniqueStringArraySchema.default([]),
|
|
367
|
+
linkedGoalIds: uniqueStringArraySchema.default([]),
|
|
368
|
+
linkedProjectIds: uniqueStringArraySchema.default([]),
|
|
369
|
+
linkedTaskIds: uniqueStringArraySchema.default([]),
|
|
370
|
+
linkedBehaviorIds: uniqueStringArraySchema.default([]),
|
|
371
|
+
linkedBeliefIds: uniqueStringArraySchema.default([]),
|
|
372
|
+
linkedModeIds: uniqueStringArraySchema.default([]),
|
|
373
|
+
modeOverlays: z.array(trimmedString).default([]),
|
|
374
|
+
schemaLinks: z.array(trimmedString).default([]),
|
|
375
|
+
modeTimeline: z.array(modeTimelineEntrySchema.omit({ id: true }).extend({ id: z.string().optional() })).default([]),
|
|
376
|
+
nextMoves: z.array(trimmedString).default([])
|
|
377
|
+
});
|
|
378
|
+
export const updateTriggerReportSchema = createTriggerReportSchema.partial();
|
|
379
|
+
export const createCommentSchema = z.object({
|
|
380
|
+
entityType: nonEmptyTrimmedString,
|
|
381
|
+
entityId: nonEmptyTrimmedString,
|
|
382
|
+
anchorKey: trimmedString.nullable().default(null),
|
|
383
|
+
body: nonEmptyTrimmedString,
|
|
384
|
+
author: trimmedString.nullable().default(null)
|
|
385
|
+
});
|
|
386
|
+
export const updateCommentSchema = z.object({
|
|
387
|
+
body: nonEmptyTrimmedString,
|
|
388
|
+
author: trimmedString.nullable().default(null)
|
|
389
|
+
});
|
|
390
|
+
export const commentsListQuerySchema = z.object({
|
|
391
|
+
entityType: nonEmptyTrimmedString.optional(),
|
|
392
|
+
entityId: nonEmptyTrimmedString.optional(),
|
|
393
|
+
limit: z.coerce.number().int().positive().max(200).optional()
|
|
394
|
+
});
|
|
395
|
+
export const commentListQuerySchema = commentsListQuerySchema;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { getDatabase, runInTransaction } from "../db.js";
|
|
3
|
+
import { recordEventLog } from "./event-log.js";
|
|
4
|
+
import { activityEventSchema } from "../types.js";
|
|
5
|
+
function mapActivityEvent(row) {
|
|
6
|
+
return activityEventSchema.parse({
|
|
7
|
+
id: row.id,
|
|
8
|
+
entityType: row.entity_type,
|
|
9
|
+
entityId: row.entity_id,
|
|
10
|
+
eventType: row.event_type,
|
|
11
|
+
title: row.title,
|
|
12
|
+
description: row.description,
|
|
13
|
+
actor: row.actor,
|
|
14
|
+
source: row.source,
|
|
15
|
+
metadata: JSON.parse(row.metadata_json),
|
|
16
|
+
createdAt: row.created_at
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function recordActivityEvent(input, now = new Date()) {
|
|
20
|
+
const id = `evt_${randomUUID().replaceAll("-", "").slice(0, 10)}`;
|
|
21
|
+
const createdAt = now.toISOString();
|
|
22
|
+
const event = activityEventSchema.parse({
|
|
23
|
+
id,
|
|
24
|
+
entityType: input.entityType,
|
|
25
|
+
entityId: input.entityId,
|
|
26
|
+
eventType: input.eventType,
|
|
27
|
+
title: input.title,
|
|
28
|
+
description: input.description ?? "",
|
|
29
|
+
actor: input.actor ?? null,
|
|
30
|
+
source: input.source,
|
|
31
|
+
metadata: input.metadata ?? {},
|
|
32
|
+
createdAt
|
|
33
|
+
});
|
|
34
|
+
getDatabase()
|
|
35
|
+
.prepare(`INSERT INTO activity_events (
|
|
36
|
+
id, entity_type, entity_id, event_type, title, description, actor, source, metadata_json, created_at
|
|
37
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
38
|
+
.run(event.id, event.entityType, event.entityId, event.eventType, event.title, event.description, event.actor, event.source, JSON.stringify(event.metadata), event.createdAt);
|
|
39
|
+
recordEventLog({
|
|
40
|
+
eventKind: `activity.${event.eventType}`,
|
|
41
|
+
entityType: event.entityType,
|
|
42
|
+
entityId: event.entityId,
|
|
43
|
+
actor: event.actor,
|
|
44
|
+
source: event.source,
|
|
45
|
+
metadata: {
|
|
46
|
+
activityEventId: event.id,
|
|
47
|
+
title: event.title
|
|
48
|
+
}
|
|
49
|
+
}, now);
|
|
50
|
+
return event;
|
|
51
|
+
}
|
|
52
|
+
export function listActivityEvents(filters = {}) {
|
|
53
|
+
const whereClauses = [];
|
|
54
|
+
const params = [];
|
|
55
|
+
if (filters.entityType) {
|
|
56
|
+
whereClauses.push("entity_type = ?");
|
|
57
|
+
params.push(filters.entityType);
|
|
58
|
+
}
|
|
59
|
+
if (filters.entityId) {
|
|
60
|
+
whereClauses.push("entity_id = ?");
|
|
61
|
+
params.push(filters.entityId);
|
|
62
|
+
}
|
|
63
|
+
if (filters.source) {
|
|
64
|
+
whereClauses.push("source = ?");
|
|
65
|
+
params.push(filters.source);
|
|
66
|
+
}
|
|
67
|
+
if (!filters.includeCorrected) {
|
|
68
|
+
whereClauses.push("event_type != 'activity_corrected'");
|
|
69
|
+
whereClauses.push("NOT EXISTS (SELECT 1 FROM activity_event_corrections WHERE activity_event_corrections.corrected_event_id = activity_events.id)");
|
|
70
|
+
}
|
|
71
|
+
const whereSql = whereClauses.length > 0 ? `WHERE ${whereClauses.join(" AND ")}` : "";
|
|
72
|
+
const limitSql = filters.limit ? "LIMIT ?" : "";
|
|
73
|
+
if (filters.limit) {
|
|
74
|
+
params.push(filters.limit);
|
|
75
|
+
}
|
|
76
|
+
const rows = getDatabase()
|
|
77
|
+
.prepare(`SELECT id, entity_type, entity_id, event_type, title, description, actor, source, metadata_json, created_at
|
|
78
|
+
FROM activity_events
|
|
79
|
+
${whereSql}
|
|
80
|
+
ORDER BY created_at DESC
|
|
81
|
+
${limitSql}`)
|
|
82
|
+
.all(...params);
|
|
83
|
+
return rows.map(mapActivityEvent);
|
|
84
|
+
}
|
|
85
|
+
export function listActivityEventsForTask(taskId, limit = 25) {
|
|
86
|
+
const rows = getDatabase()
|
|
87
|
+
.prepare(`SELECT
|
|
88
|
+
activity_events.id,
|
|
89
|
+
activity_events.entity_type,
|
|
90
|
+
activity_events.entity_id,
|
|
91
|
+
activity_events.event_type,
|
|
92
|
+
activity_events.title,
|
|
93
|
+
activity_events.description,
|
|
94
|
+
activity_events.actor,
|
|
95
|
+
activity_events.source,
|
|
96
|
+
activity_events.metadata_json,
|
|
97
|
+
activity_events.created_at
|
|
98
|
+
FROM activity_events
|
|
99
|
+
LEFT JOIN task_runs
|
|
100
|
+
ON activity_events.entity_type = 'task_run'
|
|
101
|
+
AND task_runs.id = activity_events.entity_id
|
|
102
|
+
WHERE (
|
|
103
|
+
(activity_events.entity_type = 'task' AND activity_events.entity_id = ?)
|
|
104
|
+
OR (activity_events.entity_type = 'task_run' AND task_runs.task_id = ?)
|
|
105
|
+
)
|
|
106
|
+
AND activity_events.event_type != 'activity_corrected'
|
|
107
|
+
AND NOT EXISTS (
|
|
108
|
+
SELECT 1
|
|
109
|
+
FROM activity_event_corrections
|
|
110
|
+
WHERE activity_event_corrections.corrected_event_id = activity_events.id
|
|
111
|
+
)
|
|
112
|
+
ORDER BY activity_events.created_at DESC
|
|
113
|
+
LIMIT ?`)
|
|
114
|
+
.all(taskId, taskId, limit);
|
|
115
|
+
return rows.map(mapActivityEvent);
|
|
116
|
+
}
|
|
117
|
+
export function getActivityEventById(eventId) {
|
|
118
|
+
const row = getDatabase()
|
|
119
|
+
.prepare(`SELECT id, entity_type, entity_id, event_type, title, description, actor, source, metadata_json, created_at
|
|
120
|
+
FROM activity_events
|
|
121
|
+
WHERE id = ?`)
|
|
122
|
+
.get(eventId);
|
|
123
|
+
return row ? mapActivityEvent(row) : undefined;
|
|
124
|
+
}
|
|
125
|
+
export function removeActivityEvent(eventId, input, activity) {
|
|
126
|
+
const original = getActivityEventById(eventId);
|
|
127
|
+
if (!original || original.eventType === "activity_corrected") {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
return runInTransaction(() => {
|
|
131
|
+
const existingCorrection = getDatabase()
|
|
132
|
+
.prepare(`SELECT correcting_event_id FROM activity_event_corrections WHERE corrected_event_id = ?`)
|
|
133
|
+
.get(eventId);
|
|
134
|
+
if (existingCorrection) {
|
|
135
|
+
return getActivityEventById(existingCorrection.correcting_event_id);
|
|
136
|
+
}
|
|
137
|
+
const correction = recordActivityEvent({
|
|
138
|
+
entityType: "system",
|
|
139
|
+
entityId: original.id,
|
|
140
|
+
eventType: "activity_corrected",
|
|
141
|
+
title: `Log removed: ${original.title}`,
|
|
142
|
+
description: input.reason,
|
|
143
|
+
actor: activity.actor ?? null,
|
|
144
|
+
source: activity.source,
|
|
145
|
+
metadata: {
|
|
146
|
+
correctedEventId: original.id,
|
|
147
|
+
correctedEntityType: original.entityType,
|
|
148
|
+
correctedEntityId: original.entityId
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
getDatabase()
|
|
152
|
+
.prepare(`INSERT INTO activity_event_corrections (corrected_event_id, correcting_event_id, created_at)
|
|
153
|
+
VALUES (?, ?, ?)`)
|
|
154
|
+
.run(original.id, correction.id, correction.createdAt);
|
|
155
|
+
return correction;
|
|
156
|
+
});
|
|
157
|
+
}
|