@unson/brainbase-mcp 0.51.7 → 0.51.8

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.
@@ -1,4 +1,5 @@
1
- export type RunReceiptSourceType = 'mana' | 'codex_automations' | 'github_actions' | 'salestailor' | 'openryoko' | 'openclaw';
1
+ declare const SOURCE_TYPE_VALUES: readonly ["mana", "codex_automations", "github_actions", "salestailor", "openryoko", "openclaw", "orca"];
2
+ export type RunReceiptSourceType = typeof SOURCE_TYPE_VALUES[number];
2
3
  export type RunReceiptStatus = 'success' | 'failed' | 'blocked' | 'waiting_human' | 'cancelled';
3
4
  export type RunReceiptEvidenceState = 'confirmed' | 'unconfirmed' | 'no_data';
4
5
  export type RunReceiptObservationKind = 'source_run' | 'connector_observation';
@@ -38,3 +39,4 @@ export declare function createRunReceiptIdentity({ projectId, sourceType, extern
38
39
  sourceWorkflowId: string;
39
40
  }): RunReceiptIdentity;
40
41
  export declare function normalizeRunReceipt(payload: unknown): NormalizedRunReceipt;
42
+ export {};
@@ -1,7 +1,8 @@
1
1
  // @ts-nocheck
2
2
  import { createHash } from 'node:crypto';
3
3
  const CONTRACT_VERSION = 'run_receipt.v1';
4
- const SOURCE_TYPES = new Set(['mana', 'codex_automations', 'github_actions', 'salestailor', 'openryoko', 'openclaw']);
4
+ const SOURCE_TYPE_VALUES = ['mana', 'codex_automations', 'github_actions', 'salestailor', 'openryoko', 'openclaw', 'orca'];
5
+ const SOURCE_TYPES = new Set(SOURCE_TYPE_VALUES);
5
6
  const RUN_STATUSES = new Set(['success', 'failed', 'blocked', 'waiting_human', 'cancelled']);
6
7
  const EVIDENCE_STATES = new Set(['confirmed', 'unconfirmed', 'no_data']);
7
8
  const OBSERVATION_KINDS = new Set(['source_run', 'connector_observation']);
@@ -50,6 +51,8 @@ const RUN_KEYS = new Set([
50
51
  'evidence_refs',
51
52
  'judgment_trace'
52
53
  ]);
54
+ const ORCA_RUN_KEYS = new Set([...RUN_KEYS, 'cost_basis', 'observed_at', 'stall_reason']);
55
+ const ORCA_COST_METRICS = new Set(['cost_usd', 'cost_usd_24h']);
53
56
  const DELIVERY_KEYS = new Set(['idempotency_key', 'attempt', 'sent_at']);
54
57
  const EVIDENCE_KEYS = new Set(['kind', 'ref', 'label']);
55
58
  const TRACE_KEYS = new Set([
@@ -210,7 +213,7 @@ function hasIndependentEvidence(leftRefs, rightRefs) {
210
213
  const left = new Set(leftRefs.map((ref) => `${ref.kind}:${ref.ref}`));
211
214
  return rightRefs.some((ref) => !left.has(`${ref.kind}:${ref.ref}`));
212
215
  }
213
- function validateMetrics(value) {
216
+ function validateMetrics(value, isOrca) {
214
217
  if (value === undefined || value === null)
215
218
  return undefined;
216
219
  const metrics = requireObject(value, 'run.metrics');
@@ -221,6 +224,15 @@ function validateMetrics(value) {
221
224
  fail('forbidden_metric_name', `run.metrics.${key} is content-like`, { path: `run.metrics.${key}` });
222
225
  }
223
226
  const metric = metrics[key];
227
+ if (isOrca && metric !== null) {
228
+ const path = `run.metrics.${key}`;
229
+ if (ORCA_COST_METRICS.has(key) && (!Number.isFinite(metric) || metric < 0)) {
230
+ fail('invalid_orca_cost', `${path} must be a non-negative finite number or null`, { path });
231
+ }
232
+ if (key === 'staleness_threshold_sec' && (!Number.isInteger(metric) || metric <= 0)) {
233
+ fail('invalid_orca_staleness_threshold', `${path} must be a positive integer or null`, { path });
234
+ }
235
+ }
224
236
  if (metric !== null && typeof metric !== 'boolean' && !(typeof metric === 'number' && Number.isFinite(metric))) {
225
237
  fail('invalid_metric_value', `run.metrics.${key} must be a finite number, boolean, or null`, {
226
238
  path: `run.metrics.${key}`
@@ -230,6 +242,33 @@ function validateMetrics(value) {
230
242
  });
231
243
  return normalized;
232
244
  }
245
+ function validateOrcaRunFields(run) {
246
+ const { cost_basis, observed_at, stall_reason } = run;
247
+ if (cost_basis !== undefined && cost_basis !== 'run_estimated') {
248
+ fail('unsupported_orca_cost_basis', 'run.cost_basis must be run_estimated', { path: 'run.cost_basis' });
249
+ }
250
+ if (observed_at !== undefined) {
251
+ const path = 'run.observed_at';
252
+ if (typeof observed_at !== 'string' || observed_at.length > 64
253
+ || observed_at !== observed_at.trim() || !RFC3339_PATTERN.test(observed_at)
254
+ || !Number.isFinite(Date.parse(observed_at)) || Number(observed_at.slice(11, 13)) >= 24
255
+ // Date.parse can roll impossible days forward. Check the local calendar date in UTC.
256
+ || new Date(`${observed_at.slice(0, 10)}T00:00:00Z`).toISOString().slice(0, 10) !== observed_at.slice(0, 10)) {
257
+ fail('invalid_timestamp', `${path} must be a valid RFC 3339 timestamp`, { path });
258
+ }
259
+ }
260
+ if (stall_reason !== undefined) {
261
+ requireString(stall_reason, 'run.stall_reason', 300);
262
+ if (/[\u0080-\u009f\u2028\u2029]/.test(stall_reason)) {
263
+ fail('invalid_string', 'run.stall_reason must be single-line and control-character free', { path: 'run.stall_reason' });
264
+ }
265
+ }
266
+ return {
267
+ ...(cost_basis !== undefined ? { cost_basis } : {}),
268
+ ...(observed_at !== undefined ? { observed_at } : {}),
269
+ ...(stall_reason !== undefined ? { stall_reason } : {})
270
+ };
271
+ }
233
272
  function validateEvidenceRefs(value, path = 'run.evidence_refs', maxLength = null) {
234
273
  if (value === undefined || value === null)
235
274
  return [];
@@ -526,7 +565,8 @@ export function normalizeRunReceipt(payload) {
526
565
  const runValue = requireObject(envelope.run, 'run');
527
566
  const deliveryValue = requireObject(envelope.delivery, 'delivery');
528
567
  rejectUnknownKeys(sourceValue, SOURCE_KEYS, 'source');
529
- rejectUnknownKeys(runValue, RUN_KEYS, 'run');
568
+ const isOrca = sourceValue.type === 'orca';
569
+ rejectUnknownKeys(runValue, isOrca ? ORCA_RUN_KEYS : RUN_KEYS, 'run');
530
570
  rejectUnknownKeys(deliveryValue, DELIVERY_KEYS, 'delivery');
531
571
  const source = {
532
572
  type: requireEnum(sourceValue.type, 'source.type', SOURCE_TYPES, 'unsupported_source_type'),
@@ -544,7 +584,7 @@ export function normalizeRunReceipt(payload) {
544
584
  fail('invalid_timestamp_order', 'run.finished_at may not precede run.started_at');
545
585
  }
546
586
  const evidenceRefs = validateEvidenceRefs(runValue.evidence_refs);
547
- const metrics = validateMetrics(runValue.metrics);
587
+ const metrics = validateMetrics(runValue.metrics, isOrca);
548
588
  const judgmentTrace = validateJudgmentTrace(runValue.judgment_trace);
549
589
  const actionRequired = optionalEnum(runValue.action_required, 'run.action_required', ACTIONS, 'unsupported_action_required');
550
590
  const run = {
@@ -568,6 +608,7 @@ export function normalizeRunReceipt(payload) {
568
608
  : {}),
569
609
  ...(actionRequired ? { action_required: actionRequired } : {}),
570
610
  ...(metrics !== undefined ? { metrics } : {}),
611
+ ...(isOrca ? validateOrcaRunFields(runValue) : {}),
571
612
  ...(judgmentTrace !== undefined ? { judgment_trace: judgmentTrace } : {}),
572
613
  evidence_refs: evidenceRefs
573
614
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unson/brainbase-mcp",
3
- "version": "0.51.7",
3
+ "version": "0.51.8",
4
4
  "description": "Local-first Brainbase judgment OS that lets supported AI agents reuse a user's approved goals, priorities, decisions, and judgment criteria.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -673,5 +673,5 @@
673
673
  "url": "https://github.com/Unson-LLC/brainbase/issues"
674
674
  },
675
675
  "homepage": "https://github.com/Unson-LLC/brainbase#readme",
676
- "gitHead": "e15a6fd96a68b50142e9a8ee0ee47fbda4fa1ba5"
676
+ "gitHead": "db93501fc9226053fdb20082921e6c062c2d4b56"
677
677
  }