@useorgx/openclaw-plugin 0.4.9 → 0.7.2

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.
Files changed (224) hide show
  1. package/README.md +77 -11
  2. package/dashboard/dist/assets/6mILZQ2a.js +1 -0
  3. package/dashboard/dist/assets/6mILZQ2a.js.br +0 -0
  4. package/dashboard/dist/assets/6mILZQ2a.js.gz +0 -0
  5. package/dashboard/dist/assets/8dksYiq4.js +2 -0
  6. package/dashboard/dist/assets/8dksYiq4.js.br +0 -0
  7. package/dashboard/dist/assets/8dksYiq4.js.gz +0 -0
  8. package/dashboard/dist/assets/B5zYRHc3.js +1 -0
  9. package/dashboard/dist/assets/B5zYRHc3.js.br +0 -0
  10. package/dashboard/dist/assets/B5zYRHc3.js.gz +0 -0
  11. package/dashboard/dist/assets/B6wPWJ35.js +1 -0
  12. package/dashboard/dist/assets/B6wPWJ35.js.br +0 -0
  13. package/dashboard/dist/assets/B6wPWJ35.js.gz +0 -0
  14. package/dashboard/dist/assets/BJgZIVUQ.js +53 -0
  15. package/dashboard/dist/assets/BJgZIVUQ.js.br +0 -0
  16. package/dashboard/dist/assets/BJgZIVUQ.js.gz +0 -0
  17. package/dashboard/dist/assets/BWEwjt1W.js +1 -0
  18. package/dashboard/dist/assets/BWEwjt1W.js.br +0 -0
  19. package/dashboard/dist/assets/BWEwjt1W.js.gz +0 -0
  20. package/dashboard/dist/assets/BgOYB78t.js +4 -0
  21. package/dashboard/dist/assets/BgOYB78t.js.br +0 -0
  22. package/dashboard/dist/assets/BgOYB78t.js.gz +0 -0
  23. package/dashboard/dist/assets/BzRbDCAD.css +1 -0
  24. package/dashboard/dist/assets/BzRbDCAD.css.br +0 -0
  25. package/dashboard/dist/assets/BzRbDCAD.css.gz +0 -0
  26. package/dashboard/dist/assets/C-KIc3Wc.js.br +0 -0
  27. package/dashboard/dist/assets/C-KIc3Wc.js.gz +0 -0
  28. package/dashboard/dist/assets/C8uM3AX8.js +1 -0
  29. package/dashboard/dist/assets/C8uM3AX8.js.br +0 -0
  30. package/dashboard/dist/assets/C8uM3AX8.js.gz +0 -0
  31. package/dashboard/dist/assets/C9jy61eu.js +212 -0
  32. package/dashboard/dist/assets/C9jy61eu.js.br +0 -0
  33. package/dashboard/dist/assets/C9jy61eu.js.gz +0 -0
  34. package/dashboard/dist/assets/CC63EwFD.js +1 -0
  35. package/dashboard/dist/assets/CC63EwFD.js.br +0 -0
  36. package/dashboard/dist/assets/CC63EwFD.js.gz +0 -0
  37. package/dashboard/dist/assets/CL_wXqR7.js +1 -0
  38. package/dashboard/dist/assets/CL_wXqR7.js.br +0 -0
  39. package/dashboard/dist/assets/CL_wXqR7.js.gz +0 -0
  40. package/dashboard/dist/assets/CZaT3ob_.js +1 -0
  41. package/dashboard/dist/assets/CZaT3ob_.js.br +0 -0
  42. package/dashboard/dist/assets/CZaT3ob_.js.gz +0 -0
  43. package/dashboard/dist/assets/CgaottFX.js +1 -0
  44. package/dashboard/dist/assets/CgaottFX.js.br +0 -0
  45. package/dashboard/dist/assets/CgaottFX.js.gz +0 -0
  46. package/dashboard/dist/assets/{CpJsfbXo.js → CxQ08qFN.js} +2 -2
  47. package/dashboard/dist/assets/CxQ08qFN.js.br +0 -0
  48. package/dashboard/dist/assets/CxQ08qFN.js.gz +0 -0
  49. package/dashboard/dist/assets/CzCxAZlW.js +1 -0
  50. package/dashboard/dist/assets/CzCxAZlW.js.br +0 -0
  51. package/dashboard/dist/assets/CzCxAZlW.js.gz +0 -0
  52. package/dashboard/dist/assets/D3iMTYEj.js +1 -0
  53. package/dashboard/dist/assets/D3iMTYEj.js.br +0 -0
  54. package/dashboard/dist/assets/D3iMTYEj.js.gz +0 -0
  55. package/dashboard/dist/assets/D8JNX8kq.js +2 -0
  56. package/dashboard/dist/assets/D8JNX8kq.js.br +0 -0
  57. package/dashboard/dist/assets/D8JNX8kq.js.gz +0 -0
  58. package/dashboard/dist/assets/DnA8dpj6.js +1 -0
  59. package/dashboard/dist/assets/DnA8dpj6.js.br +0 -0
  60. package/dashboard/dist/assets/DnA8dpj6.js.gz +0 -0
  61. package/dashboard/dist/assets/IUexzymk.js +1 -0
  62. package/dashboard/dist/assets/IUexzymk.js.br +0 -0
  63. package/dashboard/dist/assets/IUexzymk.js.gz +0 -0
  64. package/dashboard/dist/assets/cNrhgGc1.js +8 -0
  65. package/dashboard/dist/assets/cNrhgGc1.js.br +0 -0
  66. package/dashboard/dist/assets/cNrhgGc1.js.gz +0 -0
  67. package/dashboard/dist/assets/ic2FaMnh.js +1 -0
  68. package/dashboard/dist/assets/ic2FaMnh.js.br +0 -0
  69. package/dashboard/dist/assets/ic2FaMnh.js.gz +0 -0
  70. package/dashboard/dist/assets/qm8xLgv-.css +1 -0
  71. package/dashboard/dist/assets/qm8xLgv-.css.br +0 -0
  72. package/dashboard/dist/assets/qm8xLgv-.css.gz +0 -0
  73. package/dashboard/dist/assets/rttbDbEx.js +1 -0
  74. package/dashboard/dist/assets/rttbDbEx.js.br +0 -0
  75. package/dashboard/dist/assets/rttbDbEx.js.gz +0 -0
  76. package/dashboard/dist/brand/anthropic-mark.svg.br +0 -0
  77. package/dashboard/dist/brand/anthropic-mark.svg.gz +0 -0
  78. package/dashboard/dist/brand/openai-mark.svg.br +0 -0
  79. package/dashboard/dist/brand/openai-mark.svg.gz +0 -0
  80. package/dashboard/dist/brand/openclaw-mark.svg.br +0 -0
  81. package/dashboard/dist/brand/openclaw-mark.svg.gz +0 -0
  82. package/dashboard/dist/brand/xandy-orchestrator.png +0 -0
  83. package/dashboard/dist/index.html +7 -5
  84. package/dashboard/dist/index.html.br +0 -0
  85. package/dashboard/dist/index.html.gz +0 -0
  86. package/dist/activity-actor-fields.js +26 -4
  87. package/dist/activity-store.js +34 -8
  88. package/dist/agent-context-store.js +79 -17
  89. package/dist/agent-run-store.js +44 -3
  90. package/dist/agent-suite.d.ts +9 -0
  91. package/dist/agent-suite.js +149 -9
  92. package/dist/artifacts/artifact-domain-schemas.d.ts +66 -0
  93. package/dist/artifacts/artifact-domain-schemas.js +357 -0
  94. package/dist/artifacts/register-artifact.d.ts +4 -3
  95. package/dist/artifacts/register-artifact.js +170 -57
  96. package/dist/chat-store.d.ts +157 -0
  97. package/dist/chat-store.js +586 -0
  98. package/dist/cli/orgx.js +11 -0
  99. package/dist/contracts/client.d.ts +43 -3
  100. package/dist/contracts/client.js +159 -30
  101. package/dist/contracts/practice-exercise-schema.d.ts +216 -0
  102. package/dist/contracts/practice-exercise-schema.js +314 -0
  103. package/dist/contracts/retro-schema.d.ts +81 -0
  104. package/dist/contracts/retro-schema.js +80 -0
  105. package/dist/contracts/shared-types.d.ts +159 -0
  106. package/dist/contracts/shared-types.js +199 -1
  107. package/dist/contracts/skill-pack-schema.d.ts +192 -0
  108. package/dist/contracts/skill-pack-schema.js +180 -0
  109. package/dist/contracts/types.d.ts +247 -2
  110. package/dist/entities/auto-assignment.js +43 -17
  111. package/dist/event-sanitization.d.ts +11 -0
  112. package/dist/event-sanitization.js +113 -0
  113. package/dist/gateway-watchdog.d.ts +5 -0
  114. package/dist/gateway-watchdog.js +50 -0
  115. package/dist/hooks/post-reporting-event.mjs +1 -5
  116. package/dist/http/helpers/activity-headline.js +13 -132
  117. package/dist/http/helpers/auto-continue-engine.d.ts +198 -10
  118. package/dist/http/helpers/auto-continue-engine.js +3145 -186
  119. package/dist/http/helpers/autopilot-operations.d.ts +19 -0
  120. package/dist/http/helpers/autopilot-operations.js +182 -31
  121. package/dist/http/helpers/autopilot-runtime.d.ts +1 -0
  122. package/dist/http/helpers/autopilot-runtime.js +328 -25
  123. package/dist/http/helpers/autopilot-slice-utils.d.ts +18 -0
  124. package/dist/http/helpers/autopilot-slice-utils.js +514 -93
  125. package/dist/http/helpers/decision-mapper.d.ts +40 -0
  126. package/dist/http/helpers/decision-mapper.js +223 -7
  127. package/dist/http/helpers/dispatch-lifecycle.d.ts +19 -2
  128. package/dist/http/helpers/dispatch-lifecycle.js +242 -37
  129. package/dist/http/helpers/kickoff-context.js +104 -0
  130. package/dist/http/helpers/llm-client.d.ts +47 -0
  131. package/dist/http/helpers/llm-client.js +256 -0
  132. package/dist/http/helpers/mission-control.d.ts +102 -3
  133. package/dist/http/helpers/mission-control.js +498 -9
  134. package/dist/http/helpers/sentinel-catalog.d.ts +23 -0
  135. package/dist/http/helpers/sentinel-catalog.js +193 -0
  136. package/dist/http/helpers/session-classification.d.ts +9 -0
  137. package/dist/http/helpers/session-classification.js +564 -0
  138. package/dist/http/helpers/slice-experience-v2.d.ts +137 -0
  139. package/dist/http/helpers/slice-experience-v2.js +677 -0
  140. package/dist/http/helpers/slice-run-projections.d.ts +72 -0
  141. package/dist/http/helpers/slice-run-projections.js +877 -0
  142. package/dist/http/helpers/triage-mapper.d.ts +43 -0
  143. package/dist/http/helpers/triage-mapper.js +549 -0
  144. package/dist/http/helpers/value-utils.js +7 -2
  145. package/dist/http/helpers/workspace-scope.d.ts +15 -0
  146. package/dist/http/helpers/workspace-scope.js +170 -0
  147. package/dist/http/index.js +1420 -105
  148. package/dist/http/routes/agent-suite.d.ts +9 -0
  149. package/dist/http/routes/agent-suite.js +294 -8
  150. package/dist/http/routes/agents-catalog.js +64 -19
  151. package/dist/http/routes/chat.d.ts +19 -0
  152. package/dist/http/routes/chat.js +522 -0
  153. package/dist/http/routes/decision-actions.d.ts +8 -1
  154. package/dist/http/routes/decision-actions.js +42 -5
  155. package/dist/http/routes/dispatch-gateway-envelope.d.ts +25 -0
  156. package/dist/http/routes/dispatch-gateway-envelope.js +26 -0
  157. package/dist/http/routes/entities.d.ts +16 -0
  158. package/dist/http/routes/entities.js +232 -6
  159. package/dist/http/routes/live-legacy.d.ts +5 -0
  160. package/dist/http/routes/live-legacy.js +23 -509
  161. package/dist/http/routes/live-misc.d.ts +12 -0
  162. package/dist/http/routes/live-misc.js +251 -31
  163. package/dist/http/routes/live-snapshot.d.ts +49 -2
  164. package/dist/http/routes/live-snapshot.js +653 -23
  165. package/dist/http/routes/live-terminal.d.ts +11 -0
  166. package/dist/http/routes/live-terminal.js +154 -0
  167. package/dist/http/routes/live-triage.d.ts +61 -0
  168. package/dist/http/routes/live-triage.js +192 -0
  169. package/dist/http/routes/mission-control-actions.d.ts +49 -1
  170. package/dist/http/routes/mission-control-actions.js +1246 -84
  171. package/dist/http/routes/mission-control-read.d.ts +48 -3
  172. package/dist/http/routes/mission-control-read.js +1658 -20
  173. package/dist/http/routes/realtime-orchestrator.d.ts +10 -0
  174. package/dist/http/routes/realtime-orchestrator.js +74 -0
  175. package/dist/http/routes/run-control.d.ts +5 -2
  176. package/dist/http/routes/run-control.js +10 -0
  177. package/dist/http/routes/sentinels-catalog.d.ts +7 -0
  178. package/dist/http/routes/sentinels-catalog.js +24 -0
  179. package/dist/http/routes/summary.js +10 -3
  180. package/dist/http/routes/usage.d.ts +24 -0
  181. package/dist/http/routes/usage.js +362 -0
  182. package/dist/http/routes/work-artifacts.js +28 -9
  183. package/dist/index.js +165 -27
  184. package/dist/local-openclaw.js +29 -6
  185. package/dist/mcp-client-setup.js +3 -3
  186. package/dist/mcp-http-handler.d.ts +3 -0
  187. package/dist/mcp-http-handler.js +34 -60
  188. package/dist/next-up-queue-store.d.ts +16 -1
  189. package/dist/next-up-queue-store.js +89 -7
  190. package/dist/outbox.d.ts +5 -0
  191. package/dist/outbox.js +113 -9
  192. package/dist/paths.js +36 -5
  193. package/dist/reporting/rollups.d.ts +41 -0
  194. package/dist/reporting/rollups.js +113 -0
  195. package/dist/retro/domain-templates.d.ts +45 -0
  196. package/dist/retro/domain-templates.js +297 -0
  197. package/dist/retro/quality-rubric.d.ts +33 -0
  198. package/dist/retro/quality-rubric.js +213 -0
  199. package/dist/runtime-cleanup.d.ts +18 -0
  200. package/dist/runtime-cleanup.js +87 -0
  201. package/dist/services/background.d.ts +11 -0
  202. package/dist/services/background.js +22 -0
  203. package/dist/services/experiment-randomization.d.ts +21 -0
  204. package/dist/services/experiment-randomization.js +63 -0
  205. package/dist/skill-pack-state.d.ts +36 -5
  206. package/dist/skill-pack-state.js +273 -29
  207. package/dist/sync/local-agent-telemetry.d.ts +13 -0
  208. package/dist/sync/local-agent-telemetry.js +128 -0
  209. package/dist/sync/outbox-replay.js +131 -24
  210. package/dist/team-context-store.d.ts +23 -0
  211. package/dist/team-context-store.js +116 -0
  212. package/dist/telemetry/posthog.js +4 -2
  213. package/dist/tools/core-tools.d.ts +10 -14
  214. package/dist/tools/core-tools.js +1289 -24
  215. package/dist/types.d.ts +2 -0
  216. package/dist/types.js +2 -0
  217. package/dist/worker-supervisor.js +23 -0
  218. package/package.json +20 -6
  219. package/dashboard/dist/assets/B3ziCA02.js +0 -8
  220. package/dashboard/dist/assets/B5NEElEI.css +0 -1
  221. package/dashboard/dist/assets/BhapSNAs.js +0 -215
  222. package/dashboard/dist/assets/iFdvE7lx.js +0 -1
  223. package/dashboard/dist/assets/jRJsmpYM.js +0 -1
  224. package/dashboard/dist/assets/sAhvFnpk.js +0 -4
@@ -1,8 +1,25 @@
1
1
  import { randomUUID } from "node:crypto";
2
+ import { stableHash } from "../hash-utils.js";
3
+ import { validateArtifactMetadata, normalizeArtifactType, } from "./artifact-domain-schemas.js";
4
+ const ALLOWED_ENTITY_TYPES = new Set([
5
+ "initiative",
6
+ "workstream",
7
+ "milestone",
8
+ "task",
9
+ "decision",
10
+ "project",
11
+ ]);
2
12
  const MAX_PREVIEW_MARKDOWN = 25_000;
3
13
  function normalizeText(value) {
4
14
  return typeof value === "string" ? value.trim() : "";
5
15
  }
16
+ function normalizeConfidenceScore(value) {
17
+ if (typeof value !== "number" || !Number.isFinite(value))
18
+ return null;
19
+ if (value < 0 || value > 1)
20
+ return null;
21
+ return value;
22
+ }
6
23
  function isUuid(value) {
7
24
  return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value);
8
25
  }
@@ -28,6 +45,9 @@ export function validateRegisterArtifactInput(input) {
28
45
  const entityType = normalizeText(input.entity_type);
29
46
  if (!entityType)
30
47
  errors.push("entity_type is required");
48
+ else if (!ALLOWED_ENTITY_TYPES.has(entityType)) {
49
+ errors.push("entity_type must be one of: initiative, workstream, milestone, task, decision, project");
50
+ }
31
51
  const entityId = normalizeText(input.entity_id);
32
52
  if (!entityId)
33
53
  errors.push("entity_id is required");
@@ -39,6 +59,10 @@ export function validateRegisterArtifactInput(input) {
39
59
  const artifactType = normalizeText(input.artifact_type);
40
60
  if (!artifactType)
41
61
  errors.push("artifact_type is required");
62
+ if (typeof input.confidence_score !== "undefined" &&
63
+ normalizeConfidenceScore(input.confidence_score) == null) {
64
+ errors.push("confidence_score must be a number between 0 and 1 when provided");
65
+ }
42
66
  const createdByType = normalizeText(input.created_by_type);
43
67
  if (createdByType && createdByType !== "human" && createdByType !== "agent") {
44
68
  errors.push("created_by_type must be 'human' or 'agent' when provided");
@@ -60,6 +84,44 @@ function isArtifactTypeConstraintError(err) {
60
84
  return (msg.includes("artifact_type") &&
61
85
  (msg.includes("constraint") || msg.includes("foreign") || msg.includes("violat")));
62
86
  }
87
+ function isRecord(value) {
88
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
89
+ }
90
+ function extractArtifactFromCreateResponse(payload) {
91
+ if (!isRecord(payload))
92
+ return null;
93
+ if (isRecord(payload.artifact))
94
+ return payload.artifact;
95
+ if (isRecord(payload.data) && isRecord(payload.data.artifact)) {
96
+ return payload.data.artifact;
97
+ }
98
+ if (isRecord(payload.data))
99
+ return payload.data;
100
+ return null;
101
+ }
102
+ function extractArtifactFromDetailResponse(payload) {
103
+ if (!isRecord(payload))
104
+ return null;
105
+ if (isRecord(payload.artifact))
106
+ return payload.artifact;
107
+ if (isRecord(payload.data) && isRecord(payload.data.artifact)) {
108
+ return payload.data.artifact;
109
+ }
110
+ if (isRecord(payload.data))
111
+ return payload.data;
112
+ return null;
113
+ }
114
+ function extractArtifactsFromListResponse(payload) {
115
+ if (!isRecord(payload))
116
+ return [];
117
+ const direct = payload.artifacts;
118
+ if (Array.isArray(direct))
119
+ return direct.filter(isRecord);
120
+ if (isRecord(payload.data) && Array.isArray(payload.data.artifacts)) {
121
+ return payload.data.artifacts.filter(isRecord);
122
+ }
123
+ return [];
124
+ }
63
125
  function normalizeBaseUrl(baseUrl) {
64
126
  return baseUrl.replace(/\/+$/, "");
65
127
  }
@@ -67,18 +129,20 @@ async function sleep(ms) {
67
129
  await new Promise((r) => setTimeout(r, ms));
68
130
  }
69
131
  async function validateArtifactPersistence(client, input) {
70
- // Use API-key compatible entity CRUD endpoints for validation.
71
- // The web UI endpoints (/api/artifacts/*, /api/work-artifacts/*) are session-authenticated (401 for API keys).
72
- const detail = await client.rawRequest("GET", `/api/entities?type=artifact&id=${encodeURIComponent(input.artifactId)}`);
73
- const rows = detail && typeof detail === "object" ? detail.data : null;
74
- const artifact = Array.isArray(rows) ? rows.find((r) => r && typeof r === "object" && r.id === input.artifactId) : null;
75
- const artifactOk = artifact && typeof artifact === "object" && typeof artifact.id === "string" && artifact.id === input.artifactId;
76
- const linkedOk = artifactOk &&
77
- typeof artifact.entity_type === "string" &&
78
- typeof artifact.entity_id === "string" &&
79
- artifact.entity_type === input.entity_type &&
80
- artifact.entity_id === input.entity_id;
81
- return { artifact_detail_ok: Boolean(artifactOk), linked_ok: Boolean(linkedOk) };
132
+ const detail = await client.rawRequest("GET", `/api/client/artifacts/${encodeURIComponent(input.artifactId)}`);
133
+ const detailArtifact = extractArtifactFromDetailResponse(detail);
134
+ const detailOk = Boolean(detailArtifact && typeof detailArtifact.id === "string" && detailArtifact.id === input.artifactId);
135
+ const list = await client.rawRequest("GET", `/api/client/artifacts/by-entity?entity_type=${encodeURIComponent(input.entity_type)}&entity_id=${encodeURIComponent(input.entity_id)}&limit=25`);
136
+ const artifacts = extractArtifactsFromListResponse(list);
137
+ const linkedArtifact = artifacts.find((artifact) => {
138
+ return (typeof artifact.id === "string" &&
139
+ artifact.id === input.artifactId &&
140
+ typeof artifact.entity_type === "string" &&
141
+ artifact.entity_type === input.entity_type &&
142
+ typeof artifact.entity_id === "string" &&
143
+ artifact.entity_id === input.entity_id);
144
+ });
145
+ return { artifact_detail_ok: detailOk, linked_ok: Boolean(linkedArtifact) };
82
146
  }
83
147
  export async function registerArtifact(client, baseUrl, input) {
84
148
  const warnings = [];
@@ -111,6 +175,9 @@ export async function registerArtifact(client, baseUrl, input) {
111
175
  ? input.metadata
112
176
  : {}),
113
177
  };
178
+ const confidenceScore = normalizeConfidenceScore(input.confidence_score);
179
+ if (confidenceScore != null)
180
+ metadata.confidence_score = confidenceScore;
114
181
  if (input.external_url)
115
182
  metadata.external_url = String(input.external_url);
116
183
  if (input.preview_markdown) {
@@ -122,20 +189,102 @@ export async function registerArtifact(client, baseUrl, input) {
122
189
  if (preview.length > MAX_PREVIEW_MARKDOWN)
123
190
  metadata.preview_truncated = true;
124
191
  }
192
+ // --- Proof Ladder: atomic unit normalization + schema validation ---
193
+ const explicitAtomicType = typeof metadata.atomic_unit_type === "string"
194
+ ? metadata.atomic_unit_type.trim()
195
+ : null;
196
+ const inferredAtomicType = normalizeArtifactType(input.artifact_type);
197
+ const atomicUnitType = explicitAtomicType || inferredAtomicType;
198
+ if (atomicUnitType) {
199
+ metadata.atomic_unit_type = atomicUnitType;
200
+ const validation = validateArtifactMetadata(atomicUnitType, metadata);
201
+ metadata.schema_validated = validation.valid;
202
+ if (!validation.valid) {
203
+ warnings.push(...validation.warnings);
204
+ }
205
+ }
206
+ // --- Proof Ladder: artifact content hash ---
207
+ const hashSource = input.preview_markdown || input.external_url || input.name;
208
+ if (hashSource && !metadata.artifact_hash) {
209
+ metadata.artifact_hash = stableHash(String(hashSource));
210
+ }
211
+ // --- Proof Ladder: queue_ref from environment / caller ---
212
+ if (!metadata.queue_ref) {
213
+ const queueRef = {};
214
+ const envInitId = normalizeText(process.env.ORGX_INITIATIVE_ID);
215
+ const envWsId = normalizeText(process.env.ORGX_WORKSTREAM_ID);
216
+ const envTaskId = normalizeText(process.env.ORGX_TASK_ID);
217
+ if (envInitId)
218
+ queueRef.initiative_id = envInitId;
219
+ if (envWsId)
220
+ queueRef.workstream_id = envWsId;
221
+ if (envTaskId)
222
+ queueRef.task_id = envTaskId;
223
+ if (Object.keys(queueRef).length > 0) {
224
+ metadata.queue_ref = queueRef;
225
+ }
226
+ }
227
+ // --- Proof Ladder: run_ref from environment / caller ---
228
+ if (!metadata.run_ref) {
229
+ const runRef = {};
230
+ const envRunId = normalizeText(process.env.ORGX_RUN_ID);
231
+ const envCorrId = normalizeText(process.env.ORGX_CORRELATION_ID);
232
+ const envSessionId = normalizeText(process.env.ORGX_SESSION_ID);
233
+ if (envRunId)
234
+ runRef.run_id = envRunId;
235
+ if (envCorrId)
236
+ runRef.correlation_id = envCorrId;
237
+ if (envSessionId)
238
+ runRef.session_id = envSessionId;
239
+ if (Object.keys(runRef).length > 0) {
240
+ metadata.run_ref = runRef;
241
+ }
242
+ }
125
243
  const metadataInitiativeId = typeof metadata.initiative_id === "string" && metadata.initiative_id.trim().length > 0
126
244
  ? metadata.initiative_id.trim()
127
245
  : null;
128
246
  const initiativeIdHint = input.entity_type === "initiative" ? input.entity_id : metadataInitiativeId;
129
247
  let entity = null;
130
248
  let created = false;
131
- // Attempt idempotent create using a client-provided UUID id (preferred).
249
+ let usedLegacyCreate = false;
250
+ // Primary path: canonical client artifact contract.
132
251
  try {
252
+ const response = await client.rawRequest("POST", "/api/client/artifacts", {
253
+ artifact_id: desiredId,
254
+ entity_type: input.entity_type,
255
+ entity_id: input.entity_id,
256
+ name: input.name,
257
+ artifact_type: input.artifact_type,
258
+ description: input.description ?? undefined,
259
+ artifact_url: artifactUrl,
260
+ external_url: input.external_url ?? undefined,
261
+ preview_markdown: input.preview_markdown ?? undefined,
262
+ status,
263
+ metadata,
264
+ ...(initiativeIdHint ? { initiative_id: initiativeIdHint } : {}),
265
+ ...createdBy,
266
+ });
267
+ entity = extractArtifactFromCreateResponse(response);
268
+ if (!entity) {
269
+ warnings.push("client artifact create returned an unexpected payload shape");
270
+ }
271
+ else {
272
+ created = true;
273
+ }
274
+ }
275
+ catch (err) {
276
+ warnings.push(`client artifact create failed; falling back to legacy entities route: ${safeErrorMessage(err)}`);
277
+ }
278
+ // Compatibility path for older OrgX servers.
279
+ if (!entity) {
280
+ usedLegacyCreate = true;
133
281
  try {
134
282
  entity = await client.createEntity("artifact", {
135
283
  id: desiredId,
136
284
  name: input.name,
137
285
  description: input.description ?? undefined,
138
286
  artifact_type: input.artifact_type,
287
+ confidence_score: confidenceScore ?? undefined,
139
288
  entity_type: input.entity_type,
140
289
  entity_id: input.entity_id,
141
290
  ...(initiativeIdHint ? { initiative_id: initiativeIdHint } : {}),
@@ -150,13 +299,14 @@ export async function registerArtifact(client, baseUrl, input) {
150
299
  if (!isArtifactTypeConstraintError(err)) {
151
300
  throw err;
152
301
  }
153
- warnings.push(`artifact_type rejected; retrying with shared.project_handbook`);
302
+ warnings.push(`artifact_type rejected on legacy route; retrying with shared.project_handbook`);
154
303
  metadata.requested_artifact_type = input.artifact_type;
155
304
  entity = await client.createEntity("artifact", {
156
305
  id: desiredId,
157
306
  name: input.name,
158
307
  description: input.description ?? undefined,
159
308
  artifact_type: "shared.project_handbook",
309
+ confidence_score: confidenceScore ?? undefined,
160
310
  entity_type: input.entity_type,
161
311
  entity_id: input.entity_id,
162
312
  ...(initiativeIdHint ? { initiative_id: initiativeIdHint } : {}),
@@ -168,52 +318,15 @@ export async function registerArtifact(client, baseUrl, input) {
168
318
  created = true;
169
319
  }
170
320
  }
171
- catch (err) {
172
- warnings.push(`artifact create with explicit id failed: ${safeErrorMessage(err)}`);
173
- // Fallback: create without id, then patch artifact_url once we know the server id.
174
- try {
175
- entity = await client.createEntity("artifact", {
176
- name: input.name,
177
- description: input.description ?? undefined,
178
- artifact_type: input.artifact_type,
179
- entity_type: input.entity_type,
180
- entity_id: input.entity_id,
181
- ...(initiativeIdHint ? { initiative_id: initiativeIdHint } : {}),
182
- artifact_url: input.external_url ?? `${normalizeBaseUrl(baseUrl)}/artifacts/pending`,
183
- status,
184
- metadata,
185
- ...createdBy,
186
- });
187
- created = true;
188
- }
189
- catch (inner) {
190
- if (!isArtifactTypeConstraintError(inner)) {
191
- throw inner;
192
- }
193
- warnings.push(`artifact_type rejected; retrying with shared.project_handbook`);
194
- metadata.requested_artifact_type = input.artifact_type;
195
- entity = await client.createEntity("artifact", {
196
- name: input.name,
197
- description: input.description ?? undefined,
198
- artifact_type: "shared.project_handbook",
199
- entity_type: input.entity_type,
200
- entity_id: input.entity_id,
201
- ...(initiativeIdHint ? { initiative_id: initiativeIdHint } : {}),
202
- artifact_url: input.external_url ?? `${normalizeBaseUrl(baseUrl)}/artifacts/pending`,
203
- status,
204
- metadata,
205
- ...createdBy,
206
- });
207
- created = true;
208
- }
209
- }
210
321
  const artifactId = entity && typeof entity === "object" && typeof entity.id === "string"
211
322
  ? String(entity.id)
212
323
  : null;
213
- let finalArtifactUrl = artifactId
214
- ? `${normalizeBaseUrl(baseUrl)}/artifacts/${artifactId}`
215
- : null;
216
- if (artifactId) {
324
+ let finalArtifactUrl = entity && typeof entity === "object" && typeof entity.artifact_url === "string"
325
+ ? String(entity.artifact_url)
326
+ : artifactId
327
+ ? `${normalizeBaseUrl(baseUrl)}/artifacts/${artifactId}`
328
+ : null;
329
+ if (artifactId && usedLegacyCreate) {
217
330
  try {
218
331
  await client.updateEntity("artifact", artifactId, {
219
332
  artifact_url: finalArtifactUrl,
@@ -0,0 +1,157 @@
1
+ export type ChatAttachmentState = "preparing" | "indexing" | "ready" | "failed";
2
+ export type ChatMessageRole = "user" | "agent" | "system";
3
+ export type ChatLaunchStatus = "requested" | "queued" | "running" | "blocked" | "completed" | "failed";
4
+ export type ChatThreadStatus = "message_only" | "queued" | "running" | "blocked" | "completed" | "failed";
5
+ export type ChatAttachmentRecord = {
6
+ id: string;
7
+ name: string;
8
+ mimeType: string | null;
9
+ sizeBytes: number | null;
10
+ status: ChatAttachmentState;
11
+ error: string | null;
12
+ masked: boolean;
13
+ createdAt: string;
14
+ updatedAt: string;
15
+ };
16
+ export type ChatMessageRecord = {
17
+ id: string;
18
+ threadId: string;
19
+ role: ChatMessageRole;
20
+ body: string;
21
+ senderId: string | null;
22
+ senderName: string | null;
23
+ createdAt: string;
24
+ updatedAt: string;
25
+ attachments: ChatAttachmentRecord[];
26
+ metadata: Record<string, unknown>;
27
+ };
28
+ export type ChatLaunchAttemptRecord = {
29
+ id: string;
30
+ threadId: string;
31
+ messageId: string;
32
+ assigneeId: string | null;
33
+ assigneeName: string | null;
34
+ watcherIds: string[];
35
+ watcherNames: string[];
36
+ executionMode: "local_queue" | "cloud" | "hybrid";
37
+ provider: string | null;
38
+ runId: string | null;
39
+ status: ChatLaunchStatus;
40
+ blockedReason: string | null;
41
+ warnings: string[];
42
+ requestedAt: string;
43
+ updatedAt: string;
44
+ metadata: Record<string, unknown>;
45
+ };
46
+ export type ChatThreadRecord = {
47
+ id: string;
48
+ commandCenterId: string | null;
49
+ initiativeId: string | null;
50
+ initiativeTitle: string | null;
51
+ workstreamId: string | null;
52
+ taskId: string | null;
53
+ title: string;
54
+ summary: string | null;
55
+ status: ChatThreadStatus;
56
+ assigneeId: string | null;
57
+ assigneeName: string | null;
58
+ watcherIds: string[];
59
+ watcherNames: string[];
60
+ messageCount: number;
61
+ launchCount: number;
62
+ lastMessageAt: string | null;
63
+ lastLaunchAt: string | null;
64
+ lastActivityAt: string;
65
+ lastSnippet: string | null;
66
+ createdAt: string;
67
+ updatedAt: string;
68
+ messages: ChatMessageRecord[];
69
+ launches: ChatLaunchAttemptRecord[];
70
+ metadata: Record<string, unknown>;
71
+ };
72
+ export type ChatThreadSummary = Omit<ChatThreadRecord, "messages" | "launches"> & {
73
+ latestMessage: ChatMessageRecord | null;
74
+ latestLaunch: ChatLaunchAttemptRecord | null;
75
+ };
76
+ export declare function listChatThreads(input?: {
77
+ commandCenterId?: string | null;
78
+ initiativeId?: string | null;
79
+ query?: string | null;
80
+ status?: string | null;
81
+ limit?: number;
82
+ offset?: number;
83
+ }): {
84
+ threads: ChatThreadSummary[];
85
+ total: number;
86
+ updatedAt: string;
87
+ };
88
+ export declare function getChatThread(threadId: string): ChatThreadRecord | null;
89
+ export declare function sendChatMessage(input: {
90
+ threadId?: string | null;
91
+ commandCenterId?: string | null;
92
+ initiativeId?: string | null;
93
+ initiativeTitle?: string | null;
94
+ workstreamId?: string | null;
95
+ taskId?: string | null;
96
+ title?: string | null;
97
+ body: string;
98
+ role?: ChatMessageRole;
99
+ senderId?: string | null;
100
+ senderName?: string | null;
101
+ assigneeId?: string | null;
102
+ assigneeName?: string | null;
103
+ watcherIds?: string[];
104
+ watcherNames?: string[];
105
+ attachments?: Array<Partial<ChatAttachmentRecord> & {
106
+ name?: string | null;
107
+ }>;
108
+ metadata?: Record<string, unknown>;
109
+ }): {
110
+ thread: ChatThreadRecord;
111
+ message: ChatMessageRecord;
112
+ createdThread: boolean;
113
+ updatedAt: string;
114
+ };
115
+ export declare function recordChatLaunch(input: {
116
+ threadId: string;
117
+ messageId: string;
118
+ assigneeId?: string | null;
119
+ assigneeName?: string | null;
120
+ watcherIds?: string[];
121
+ watcherNames?: string[];
122
+ executionMode?: "local_queue" | "cloud" | "hybrid";
123
+ provider?: string | null;
124
+ runId?: string | null;
125
+ status?: ChatLaunchStatus;
126
+ blockedReason?: string | null;
127
+ warnings?: string[];
128
+ metadata?: Record<string, unknown>;
129
+ }): {
130
+ thread: ChatThreadRecord;
131
+ launch: ChatLaunchAttemptRecord;
132
+ updatedAt: string;
133
+ };
134
+ export declare function updateChatLaunchStatus(input: {
135
+ threadId: string;
136
+ launchId: string;
137
+ status: ChatLaunchStatus;
138
+ runId?: string | null;
139
+ blockedReason?: string | null;
140
+ warnings?: string[];
141
+ }): {
142
+ thread: ChatThreadRecord;
143
+ launch: ChatLaunchAttemptRecord;
144
+ updatedAt: string;
145
+ };
146
+ export declare function linkChatThreadScope(input: {
147
+ threadId: string;
148
+ commandCenterId?: string | null;
149
+ initiativeId?: string | null;
150
+ initiativeTitle?: string | null;
151
+ workstreamId?: string | null;
152
+ taskId?: string | null;
153
+ }): {
154
+ thread: ChatThreadRecord;
155
+ eventMessage: ChatMessageRecord;
156
+ updatedAt: string;
157
+ };