@lobu/runtime-server 24.1.0 → 24.1.1

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.
@@ -4,6 +4,6 @@
4
4
  "server": "dist/server.bundle.mjs",
5
5
  "embeddingsServer": "dist/embeddings-server.mjs"
6
6
  },
7
- "version": "24.1.0",
7
+ "version": "24.1.1",
8
8
  "verify": "dist/verify.mjs"
9
9
  }
@@ -6845,7 +6845,7 @@ function isSemanticallyEqual(existing, params) {
6845
6845
  // from this comparison and from `score` below — they are reconciled in
6846
6846
  // place by applyVolatileState instead of minting a new stored version.
6847
6847
  durableMetadataState(existing.metadata) === durableMetadataState(params.metadata) && // Compare the value a supersede would WRITE: a null parentOriginId copies
6848
- // the predecessor's parent (loadEventLineage), so only a caller-supplied
6848
+ // the predecessor's parent (EVENT_SUPERSEDE_RULES), so only a caller-supplied
6849
6849
  // parent can differ. Comparing the raw param would re-supersede a
6850
6850
  // copied-parent head on every parentless re-sync, forever.
6851
6851
  (params.parentOriginId == null || (existing.origin_parent_id ?? null) === params.parentOriginId) && existing.interaction_type === (params.interactionType ?? "none") && (existing.interaction_status ?? null) === (params.interactionStatus ?? null) && stableJson(existing.interaction_input_schema ?? null) === stableJson(params.interactionInputSchema ?? null) && stableJson(existing.interaction_input ?? null) === stableJson(params.interactionInput ?? null) && stableJson(existing.interaction_output ?? null) === stableJson(params.interactionOutput ?? null) && (existing.interaction_error ?? null) === (params.interactionError ?? null);
@@ -6889,37 +6889,42 @@ async function upsertEmbedding(eventId, embedding, embeddingModel, sql = getDb()
6889
6889
  await sql.begin(async (tx) => replaceIfLive(tx));
6890
6890
  }
6891
6891
  }
6892
- function nullableNumber(value) {
6893
- return value == null ? null : Number(value);
6892
+ function requestedLineage(params) {
6893
+ return {
6894
+ origin_parent_id: params.parentOriginId ?? null,
6895
+ connector_key: params.connectorKey ?? null,
6896
+ connection_id: params.connectionId ?? null,
6897
+ feed_key: params.feedKey ?? null,
6898
+ feed_id: params.feedId ?? null,
6899
+ run_id: params.runId ?? null,
6900
+ automation_id: params.automationId ?? null,
6901
+ automation_version_id: params.automationVersionId ?? null,
6902
+ client_id: params.clientId ?? null,
6903
+ identity_ns: params.identity?.ns ?? null,
6904
+ identity_key: params.identity?.key ?? null
6905
+ };
6894
6906
  }
6895
- async function loadEventLineage(sql, supersedesEventId, params) {
6896
- const rows = await sql`
6897
- SELECT connector_key, connection_id, feed_key, feed_id, run_id,
6898
- automation_id, automation_version_id, origin_parent_id,
6899
- identity_ns, identity_key
6900
- FROM events
6901
- WHERE id = ${supersedesEventId}
6902
- AND organization_id = ${params.organizationId}
6903
- LIMIT 1
6904
- `;
6905
- const prior = rows[0];
6906
- if (!prior) {
6907
+ async function loadPredecessorLineage(sql, supersedesEventId, organizationId) {
6908
+ const rows = await sql.unsafe(
6909
+ `SELECT ${INHERITED_COLUMNS.join(", ")} FROM events
6910
+ WHERE id = $1 AND organization_id = $2
6911
+ LIMIT 1`,
6912
+ [supersedesEventId, organizationId]
6913
+ );
6914
+ if (!rows[0]) {
6907
6915
  throw new Error(
6908
- `insertEvent: cannot supersede event ${supersedesEventId} \u2014 not found in organization ${params.organizationId}`
6916
+ `insertEvent: cannot supersede event ${supersedesEventId} \u2014 not found in organization ${organizationId}`
6909
6917
  );
6910
6918
  }
6911
- return {
6912
- connectorKey: prior.connector_key ?? null,
6913
- connectionId: nullableNumber(prior.connection_id),
6914
- feedKey: prior.feed_key ?? null,
6915
- feedId: nullableNumber(prior.feed_id),
6916
- runId: params.runId ?? nullableNumber(prior.run_id),
6917
- automationId: params.automationId ?? nullableNumber(prior.automation_id),
6918
- automationVersionId: params.automationVersionId ?? nullableNumber(prior.automation_version_id),
6919
- parentOriginId: params.parentOriginId ?? prior.origin_parent_id ?? null,
6920
- identityNs: prior.identity_ns ?? null,
6921
- identityKey: prior.identity_key ?? null
6922
- };
6919
+ return rows[0];
6920
+ }
6921
+ function successorLineage(prior, requested) {
6922
+ return Object.fromEntries(
6923
+ INHERITED_COLUMNS.map((column) => [
6924
+ column,
6925
+ EVENT_SUPERSEDE_RULES[column] === "chain" ? prior[column] : requested[column] ?? prior[column]
6926
+ ])
6927
+ );
6923
6928
  }
6924
6929
  function isEventsClientIdForeignKeyViolation(error) {
6925
6930
  const err = error;
@@ -6992,7 +6997,6 @@ async function insertEvent(params, options) {
6992
6997
  params = { ...params, metadata: enrichedMetadata };
6993
6998
  }
6994
6999
  const entityIdsValue = params.entityIds.length > 0 ? `{${params.entityIds.join(",")}}` : null;
6995
- const requestedClientId = params.clientId ?? null;
6996
7000
  const runInsert = async (activeSql) => {
6997
7001
  let supersedesEventId = params.supersedesEventId ?? null;
6998
7002
  let previousOccurredAt;
@@ -7051,25 +7055,18 @@ async function insertEvent(params, options) {
7051
7055
  return insertRow(activeSql, supersedesEventId, previousOccurredAt);
7052
7056
  };
7053
7057
  const insertRow = async (sql2, supersedesEventId, previousOccurredAt) => {
7054
- let lineage = supersedesEventId != null ? await loadEventLineage(sql2, supersedesEventId, params) : {
7055
- connectorKey: params.connectorKey ?? null,
7056
- connectionId: params.connectionId ?? null,
7057
- feedKey: params.feedKey ?? null,
7058
- feedId: params.feedId ?? null,
7059
- runId: params.runId ?? null,
7060
- automationId: params.automationId ?? null,
7061
- automationVersionId: params.automationVersionId ?? null,
7062
- parentOriginId: params.parentOriginId ?? null,
7063
- identityNs: params.identity?.ns ?? null,
7064
- identityKey: params.identity?.key ?? null
7065
- };
7058
+ const requested = requestedLineage(params);
7059
+ let lineage = supersedesEventId == null ? requested : successorLineage(
7060
+ await loadPredecessorLineage(sql2, supersedesEventId, params.organizationId),
7061
+ requested
7062
+ );
7066
7063
  if (browserConnector) {
7067
7064
  lineage = {
7068
7065
  ...lineage,
7069
- parentOriginId: sanitizeBrowserText(lineage.parentOriginId) ?? null
7066
+ origin_parent_id: sanitizeBrowserText(lineage.origin_parent_id) ?? null
7070
7067
  };
7071
7068
  }
7072
- const insertWithClientId = (activeSql, clientId) => activeSql`
7069
+ const insertWithClientId = (activeSql, clientId2) => activeSql`
7073
7070
  INSERT INTO events (
7074
7071
  entity_ids, organization_id, origin_id, title,
7075
7072
  payload_type, payload_text, payload_data, payload_template, attachments, metadata,
@@ -7096,17 +7093,17 @@ async function insertEvent(params, options) {
7096
7093
  ${params.authorName ?? null},
7097
7094
  ${params.sourceUrl ?? null},
7098
7095
  ${params.occurredAt ?? /* @__PURE__ */ new Date()},
7099
- ${lineage.parentOriginId},
7096
+ ${lineage.origin_parent_id},
7100
7097
  ${params.originType ?? null},
7101
- ${lineage.connectorKey},
7102
- ${lineage.connectionId},
7103
- ${lineage.feedKey},
7104
- ${lineage.feedId},
7105
- ${lineage.runId},
7106
- ${lineage.automationId},
7107
- ${lineage.automationVersionId},
7098
+ ${lineage.connector_key},
7099
+ ${lineage.connection_id},
7100
+ ${lineage.feed_key},
7101
+ ${lineage.feed_id},
7102
+ ${lineage.run_id},
7103
+ ${lineage.automation_id},
7104
+ ${lineage.automation_version_id},
7108
7105
  ${params.semanticType},
7109
- ${clientId},
7106
+ ${clientId2},
7110
7107
  ${params.createdBy ?? null},
7111
7108
  ${params.interactionType ?? "none"},
7112
7109
  ${params.interactionStatus ?? null},
@@ -7115,8 +7112,8 @@ async function insertEvent(params, options) {
7115
7112
  ${params.interactionOutput ? sql2.json(params.interactionOutput) : null},
7116
7113
  ${params.interactionError ?? null},
7117
7114
  ${supersedesEventId},
7118
- ${lineage.identityNs},
7119
- ${lineage.identityKey},
7115
+ ${lineage.identity_ns},
7116
+ ${lineage.identity_key},
7120
7117
  (
7121
7118
  SELECT COALESCE(array_agg(DISTINCT x.o), '{}'::text[])
7122
7119
  FROM (
@@ -7126,7 +7123,7 @@ async function insertEvent(params, options) {
7126
7123
  UNION ALL
7127
7124
  SELECT c.organization_id AS o
7128
7125
  FROM public.connections c
7129
- WHERE c.id = ${lineage.connectionId}
7126
+ WHERE c.id = ${lineage.connection_id}
7130
7127
  ) x
7131
7128
  WHERE x.o IS NOT NULL
7132
7129
  AND (x.o <> ${params.organizationId}::text OR ${params.organizationId}::text IS NULL)
@@ -7134,16 +7131,17 @@ async function insertEvent(params, options) {
7134
7131
  )
7135
7132
  RETURNING id, entity_ids, origin_id, title, semantic_type, created_at
7136
7133
  `;
7134
+ const clientId = lineage.client_id;
7137
7135
  let result;
7138
7136
  const inTransaction = typeof sql2.savepoint === "function";
7139
7137
  try {
7140
- result = inTransaction ? await sql2.savepoint((sp) => insertWithClientId(sp, requestedClientId)) : await insertWithClientId(sql2, requestedClientId);
7138
+ result = inTransaction ? await sql2.savepoint((sp) => insertWithClientId(sp, clientId)) : await insertWithClientId(sql2, clientId);
7141
7139
  } catch (error) {
7142
- if (!requestedClientId || !isEventsClientIdForeignKeyViolation(error)) {
7140
+ if (!clientId || !isEventsClientIdForeignKeyViolation(error)) {
7143
7141
  throw error;
7144
7142
  }
7145
7143
  logger_default.warn(
7146
- { clientId: requestedClientId },
7144
+ { clientId },
7147
7145
  "[insert-event] retrying insert with client_id NULL \u2014 referenced oauth_clients row no longer exists"
7148
7146
  );
7149
7147
  result = await insertWithClientId(sql2, null);
@@ -7631,7 +7629,7 @@ function recordLifecycleEvent(params) {
7631
7629
  );
7632
7630
  });
7633
7631
  }
7634
- var AUDIT_EVENT_RETRY, EVENT_DEDUP_LOCK_NAMESPACE, DURABLE_ATTACHMENT_KEYS, VOLATILE_METADATA_KEYS, UNREAD_BADGE_PREFIX, AUDIT_IDEMPOTENCY_INDEX;
7632
+ var AUDIT_EVENT_RETRY, EVENT_DEDUP_LOCK_NAMESPACE, DURABLE_ATTACHMENT_KEYS, VOLATILE_METADATA_KEYS, UNREAD_BADGE_PREFIX, EVENT_SUPERSEDE_RULES, INHERITED_COLUMNS, AUDIT_IDEMPOTENCY_INDEX;
7635
7633
  var init_insert_event = __esm({
7636
7634
  "src/utils/insert-event.ts"() {
7637
7635
  "use strict";
@@ -7667,6 +7665,50 @@ var init_insert_event = __esm({
7667
7665
  "updated_at"
7668
7666
  ]);
7669
7667
  UNREAD_BADGE_PREFIX = /^\(\d+\)\s+/;
7668
+ EVENT_SUPERSEDE_RULES = {
7669
+ id: "version",
7670
+ organization_id: "version",
7671
+ entity_ids: "version",
7672
+ origin_id: "version",
7673
+ title: "version",
7674
+ payload_type: "version",
7675
+ payload_text: "version",
7676
+ payload_data: "version",
7677
+ payload_template: "version",
7678
+ attachments: "version",
7679
+ metadata: "version",
7680
+ score: "version",
7681
+ author_name: "version",
7682
+ source_url: "version",
7683
+ occurred_at: "version",
7684
+ created_at: "version",
7685
+ origin_parent_id: "lineage",
7686
+ origin_type: "version",
7687
+ connector_key: "chain",
7688
+ connection_id: "chain",
7689
+ feed_key: "chain",
7690
+ feed_id: "chain",
7691
+ run_id: "lineage",
7692
+ automation_id: "lineage",
7693
+ automation_version_id: "lineage",
7694
+ semantic_type: "version",
7695
+ client_id: "lineage",
7696
+ created_by: "version",
7697
+ interaction_type: "version",
7698
+ interaction_status: "version",
7699
+ interaction_input_schema: "version",
7700
+ interaction_input: "version",
7701
+ interaction_output: "version",
7702
+ interaction_error: "version",
7703
+ supersedes_event_id: "version",
7704
+ superseded_by: "version",
7705
+ content_length: "version",
7706
+ search_tsv: "version",
7707
+ identity_ns: "chain",
7708
+ identity_key: "chain",
7709
+ linked_org_ids: "version"
7710
+ };
7711
+ INHERITED_COLUMNS = Object.keys(EVENT_SUPERSEDE_RULES).filter((column) => EVENT_SUPERSEDE_RULES[column] !== "version");
7670
7712
  AUDIT_IDEMPOTENCY_INDEX = "idx_events_org_idempotency_key";
7671
7713
  }
7672
7714
  });
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@lobu/runtime-server",
3
- "version": "24.1.0",
3
+ "version": "24.1.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@lobu/runtime-server",
9
- "version": "24.1.0",
9
+ "version": "24.1.1",
10
10
  "license": "BUSL-1.1",
11
11
  "dependencies": {
12
12
  "@agentclientprotocol/sdk": "1.4.0",
@@ -11795,7 +11795,7 @@
11795
11795
  },
11796
11796
  "vendor/connector-sdk": {
11797
11797
  "name": "@lobu/connector-sdk",
11798
- "version": "24.1.0",
11798
+ "version": "24.1.1",
11799
11799
  "license": "BUSL-1.1",
11800
11800
  "dependencies": {
11801
11801
  "@lobu/core": "file:../core",
@@ -11810,7 +11810,7 @@
11810
11810
  },
11811
11811
  "vendor/core": {
11812
11812
  "name": "@lobu/core",
11813
- "version": "24.1.0",
11813
+ "version": "24.1.1",
11814
11814
  "license": "Apache-2.0",
11815
11815
  "dependencies": {
11816
11816
  "@opentelemetry/api": "^1.9.0",
@@ -11839,7 +11839,7 @@
11839
11839
  },
11840
11840
  "vendor/views": {
11841
11841
  "name": "@lobu/views",
11842
- "version": "24.1.0",
11842
+ "version": "24.1.1",
11843
11843
  "license": "Apache-2.0",
11844
11844
  "dependencies": {
11845
11845
  "@lobu/core": "file:../core"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/runtime-server",
3
- "version": "24.1.0",
3
+ "version": "24.1.1",
4
4
  "type": "module",
5
5
  "license": "BUSL-1.1",
6
6
  "repository": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/connector-sdk",
3
- "version": "24.1.0",
3
+ "version": "24.1.1",
4
4
  "description": "Lobu memory SDK — build pluggable connectors for Lobu memory",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/core",
3
- "version": "24.1.0",
3
+ "version": "24.1.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Core types and utilities for Lobu agent platform",
6
6
  "repository": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/views",
3
- "version": "24.1.0",
3
+ "version": "24.1.1",
4
4
  "description": "Authoring runtime for Lobu views — React modules rendered in the sandboxed MCP Apps frame",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",