@lobu/runtime-device 24.3.0 → 24.4.0

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/cli",
3
- "version": "24.3.0",
3
+ "version": "24.4.0",
4
4
  "description": "CLI for deploying and managing AI agents on Lobu",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/connector-sdk",
3
- "version": "24.3.0",
3
+ "version": "24.4.0",
4
4
  "description": "Lobu memory SDK — build pluggable connectors for Lobu memory",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -7,6 +7,7 @@
7
7
  * What this module adds is only the envelope: the guest bundle, the allowlist,
8
8
  * and reporting the result.
9
9
  */
10
+ import { createChildSpan, initTracing, runInSpanContext, SpanStatusCode, traceparentHeader } from '@lobu/core';
10
11
  import { AGENT_TURN_BRIDGE_BYTES, AGENT_TURN_INPUT_MAX, TURN_DELTA_MAX_CHARS, TURN_TOOL_EVENT_QUEUE_MAX, } from '@lobu/core/contracts/worker/protocol';
11
12
  import { agentGuestBundle } from '../agent-turn/bundle.js';
12
13
  import { selectExecutor } from '../executor/select.js';
@@ -36,7 +37,60 @@ const TURN_DELTA_DRAIN_BATCHES = 4;
36
37
  function isAgentTurnPayload(value) {
37
38
  return !!value && typeof value === 'object' && 'turn' in value;
38
39
  }
40
+ function ensureWorkerTracing() {
41
+ const otlpEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT?.trim();
42
+ if (!otlpEndpoint)
43
+ return;
44
+ initTracing({
45
+ serviceName: 'lobu-worker',
46
+ serviceVersion: process.env.APP_GIT_SHA,
47
+ otlpEndpoint,
48
+ });
49
+ }
39
50
  export async function executeAgentTurnRun(client, job, env, cfg) {
51
+ let span = null;
52
+ try {
53
+ ensureWorkerTracing();
54
+ const traceparent = traceparentHeader(job.traceparent);
55
+ if (traceparent) {
56
+ span = createChildSpan('agent_turn', traceparent, {
57
+ 'lobu.run_id': String(job.run_id ?? ''),
58
+ });
59
+ }
60
+ }
61
+ catch (error) {
62
+ // Telemetry is optional. A missing exporter must not fail a claimed turn.
63
+ log.info('[agent-turn] Tracing unavailable; continuing without a span:', error);
64
+ }
65
+ try {
66
+ const result = await runInSpanContext(span, () => runAgentTurn(client, job, env, cfg));
67
+ // The gateway's typed receipt is authoritative, including a cancellation
68
+ // that raced the worker's completion. Keep this internal to tracing.
69
+ const { terminalStatus, ...outcome } = result;
70
+ const status = terminalStatus ?? (outcome.error ? 'failed' : 'completed');
71
+ span?.setAttribute('lobu.run_status', status);
72
+ if (status !== 'cancelled') {
73
+ span?.setStatus({
74
+ code: status === 'failed' ? SpanStatusCode.ERROR : SpanStatusCode.OK,
75
+ ...(outcome.error ? { message: outcome.error } : {}),
76
+ });
77
+ }
78
+ return outcome;
79
+ }
80
+ catch (error) {
81
+ span?.setAttribute('lobu.run_status', 'failed');
82
+ span?.setStatus({
83
+ code: SpanStatusCode.ERROR,
84
+ message: error instanceof Error ? error.message : String(error),
85
+ });
86
+ span?.recordException(error instanceof Error ? error : new Error(String(error)));
87
+ throw error;
88
+ }
89
+ finally {
90
+ span?.end();
91
+ }
92
+ }
93
+ async function runAgentTurn(client, job, env, cfg) {
40
94
  const runId = job.run_id;
41
95
  if (!runId)
42
96
  return { itemsCollected: 0, error: 'agent turn run missing its run id' };
@@ -58,7 +112,7 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
58
112
  ...(trailing?.length ? { turn_tool_events: trailing } : {}),
59
113
  exit_reason: 'error_message',
60
114
  });
61
- return { itemsCollected: 0, ...(receipt.status === 'completed' ? {} : { error }) };
115
+ return { itemsCollected: 0, terminalStatus: receipt.status, ...(receipt.status === 'completed' ? {} : { error }) };
62
116
  }
63
117
  catch (deliveryError) {
64
118
  // The outer executor must not replace this failure's evidence with a
@@ -609,8 +663,9 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
609
663
  ...(result.turn.suggestions ? { suggestions: result.turn.suggestions } : {}),
610
664
  exit_reason: 'ok',
611
665
  });
612
- if (receipt.status !== 'completed')
613
- return { itemsCollected: 0, error: `agent turn ${receipt.status}` };
666
+ if (receipt.status !== 'completed') {
667
+ return { itemsCollected: 0, error: `agent turn ${receipt.status}`, terminalStatus: receipt.status };
668
+ }
614
669
  log.info(`[agent-turn] run ${runId} completed after ${deltaSequence} delta batches and ${toolCalls} tool calls`);
615
670
  return { itemsCollected: 0 };
616
671
  }
@@ -10,6 +10,7 @@ export function trimTrailingSlashes(value) {
10
10
  end--;
11
11
  return end === value.length ? value : value.slice(0, end);
12
12
  }
13
+ import { traceparentHeader } from "@lobu/core";
13
14
  import { resolveRunnableAgentKinds } from "./agent-binaries.js";
14
15
  export class MutableWorkerAdvertisementProvider {
15
16
  current;
@@ -240,7 +241,12 @@ export class WorkerClient {
240
241
  : {}),
241
242
  };
242
243
  try {
243
- return await this.requestJson('/api/workers/poll', body, options?.signal);
244
+ const response = await this.post('/api/workers/poll', body, options?.signal);
245
+ const job = (await response.json());
246
+ const traceparent = traceparentHeader(response.headers.get('traceparent'));
247
+ if (traceparent)
248
+ job.traceparent = traceparent;
249
+ return job;
244
250
  }
245
251
  catch (error) {
246
252
  const description = error instanceof WorkerHttpError ? upgradeRequiredDescription(error) : null;
@@ -6,7 +6,7 @@
6
6
  * the run's start and its terminal result — plus startup/shutdown and hard
7
7
  * failures. Pass `--debug` to enable the poll/heartbeat/retry chatter.
8
8
  */
9
- import { scrubDiagnosticValue } from '@lobu/core';
9
+ import { currentTraceLogFields, scrubDiagnosticValue } from '@lobu/core';
10
10
  let debugEnabled = false;
11
11
  function write(level, parts) {
12
12
  let line;
@@ -14,6 +14,7 @@ function write(level, parts) {
14
14
  const record = scrubDiagnosticValue({
15
15
  timestamp: new Date().toISOString(), level, service: 'lobu-worker',
16
16
  release: process.env.APP_GIT_SHA,
17
+ ...currentTraceLogFields(),
17
18
  message: parts.filter((part) => typeof part === 'string').join(' '),
18
19
  data: parts.filter((part) => typeof part !== 'string'),
19
20
  });
@@ -5,6 +5,7 @@
5
5
  * polling, concurrency, and graceful-shutdown lifecycle. Run execution stays
6
6
  * injected so the device build does not import fleet connector machinery.
7
7
  */
8
+ import { shutdownTracing } from '@lobu/core';
8
9
  import { WORKER_POLL_MAX_WAIT_SECONDS } from '@lobu/core/contracts/worker/protocol';
9
10
  import { WorkerHttpError, WorkerUpgradeRequiredError, } from './client.js';
10
11
  import { log } from './log.js';
@@ -16,17 +17,22 @@ const DEFAULT_SHUTDOWN_DRAIN_MS = 30_000;
16
17
  */
17
18
  const SHUTDOWN_EXIT_MARGIN_MS = 15_000;
18
19
  /**
19
- * How long SIGTERM waits for in-flight runs. A fleet pod is SIGKILLed
20
+ * The pod's whole grace period after SIGTERM. A fleet pod is SIGKILLed
20
21
  * `terminationGracePeriodSeconds` after SIGTERM; the chart passes that same
21
- * value as `WORKER_SHUTDOWN_GRACE_SECONDS`, so the drain uses all of it except
22
- * the exit margin. Anything else keeps the fixed default.
22
+ * value as `WORKER_SHUTDOWN_GRACE_SECONDS`. Anything else keeps the fixed
23
+ * default drain plus the exit margin.
23
24
  */
24
- function resolveWorkerShutdownDrainMs(env = process.env) {
25
+ function resolveWorkerShutdownGraceMs(env = process.env) {
25
26
  const raw = env.WORKER_SHUTDOWN_GRACE_SECONDS?.trim();
26
27
  const seconds = raw ? Number(raw) : Number.NaN;
27
- if (!Number.isInteger(seconds) || seconds < 0)
28
- return DEFAULT_SHUTDOWN_DRAIN_MS;
29
- return Math.max(0, seconds * 1000 - SHUTDOWN_EXIT_MARGIN_MS);
28
+ if (!Number.isInteger(seconds) || seconds < 0) {
29
+ return DEFAULT_SHUTDOWN_DRAIN_MS + SHUTDOWN_EXIT_MARGIN_MS;
30
+ }
31
+ return seconds * 1000;
32
+ }
33
+ /** How long SIGTERM waits for in-flight runs: the grace minus the exit margin. */
34
+ function resolveWorkerShutdownDrainMs(env = process.env) {
35
+ return Math.max(0, resolveWorkerShutdownGraceMs(env) - SHUTDOWN_EXIT_MARGIN_MS);
30
36
  }
31
37
  export function shouldHandleWorkerPollLoopStdinEof(options = {}) {
32
38
  return options.stdinEof === true;
@@ -200,6 +206,7 @@ export class WorkerPollLoop {
200
206
  }
201
207
  export function createWorkerPollLoopShutdownHandler(loop, onShutdown = () => loop.stop(), exit = process.exit) {
202
208
  const drainTimeoutMs = resolveWorkerShutdownDrainMs();
209
+ const shutdownGraceMs = resolveWorkerShutdownGraceMs();
203
210
  let shuttingDown = false;
204
211
  return async (signal) => {
205
212
  if (shuttingDown) {
@@ -208,6 +215,7 @@ export function createWorkerPollLoopShutdownHandler(loop, onShutdown = () => loo
208
215
  return;
209
216
  }
210
217
  shuttingDown = true;
218
+ const shutdownDeadline = Date.now() + shutdownGraceMs;
211
219
  log.info(`\n[daemon] Received ${signal}, shutting down...`);
212
220
  let shutdownHookSucceeded = true;
213
221
  try {
@@ -221,6 +229,17 @@ export function createWorkerPollLoopShutdownHandler(loop, onShutdown = () => loo
221
229
  const allDone = await loop.waitForActiveJobs(drainTimeoutMs);
222
230
  if (!allDone)
223
231
  log.info('[daemon] Forcing exit with active jobs still running');
232
+ // Exporters can still be waiting on a collector. Spend only the grace
233
+ // left after hooks/draining, cap telemetry at 5s, and retain 1s to exit.
234
+ const tracingTimeoutMs = Math.min(5_000, Math.max(0, shutdownDeadline - Date.now() - 1_000));
235
+ if (tracingTimeoutMs > 0) {
236
+ try {
237
+ await shutdownTracing(tracingTimeoutMs);
238
+ }
239
+ catch (error) {
240
+ log.info('[daemon] Tracing shutdown failed:', error);
241
+ }
242
+ }
224
243
  exit(allDone && shutdownHookSucceeded ? 0 : 1);
225
244
  };
226
245
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/connector-worker",
3
- "version": "24.3.0",
3
+ "version": "24.4.0",
4
4
  "description": "Self-hosted worker for Lobu memory — connectors and embedding generation",
5
5
  "type": "module",
6
6
  "bin": {
@@ -57,7 +57,7 @@ export declare const ListEntitiesAction: import("@sinclair/typebox").TObject<{
57
57
  export declare const GetEntityAction: import("@sinclair/typebox").TObject<{
58
58
  action: import("@sinclair/typebox").TLiteral<"get">;
59
59
  entity_id: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>;
60
- entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
60
+ entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
61
61
  include_deleted: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
62
62
  }>;
63
63
  export declare const DeleteEntityAction: import("@sinclair/typebox").TObject<{
@@ -76,8 +76,8 @@ export declare const LinkEntitiesAction: import("@sinclair/typebox").TObject<{
76
76
  action: import("@sinclair/typebox").TLiteral<"link">;
77
77
  from_entity_id: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>;
78
78
  to_entity_id: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>;
79
- from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
80
- to_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
79
+ from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
80
+ to_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
81
81
  relationship_type_slug: import("@sinclair/typebox").TString;
82
82
  confidence: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
83
83
  source: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"ui">, import("@sinclair/typebox").TLiteral<"llm">, import("@sinclair/typebox").TLiteral<"feed">, import("@sinclair/typebox").TLiteral<"api">]>>;
@@ -97,8 +97,8 @@ export declare const UnlinkEntitiesAction: import("@sinclair/typebox").TObject<{
97
97
  relationship_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
98
98
  from_entity_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>>;
99
99
  to_entity_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>>;
100
- from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
101
- to_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
100
+ from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
101
+ to_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
102
102
  relationship_type_slug: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
103
103
  }>;
104
104
  export declare const UpdateLinkAction: import("@sinclair/typebox").TObject<{
@@ -106,8 +106,8 @@ export declare const UpdateLinkAction: import("@sinclair/typebox").TObject<{
106
106
  relationship_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
107
107
  from_entity_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>>;
108
108
  to_entity_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>>;
109
- from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
110
- to_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
109
+ from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
110
+ to_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
111
111
  relationship_type_slug: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
112
112
  confidence: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
113
113
  source: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"ui">, import("@sinclair/typebox").TLiteral<"llm">, import("@sinclair/typebox").TLiteral<"feed">, import("@sinclair/typebox").TLiteral<"api">]>>;
@@ -123,7 +123,7 @@ export declare const ListLinksAction: import("@sinclair/typebox").TObject<{
123
123
  offset: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
124
124
  action: import("@sinclair/typebox").TLiteral<"list_links">;
125
125
  entity_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>>;
126
- entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
126
+ entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
127
127
  record: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
128
128
  type: import("@sinclair/typebox").TString;
129
129
  key: import("@sinclair/typebox").TString;
@@ -141,6 +141,11 @@ export declare const DiscoverDuplicatesAction: import("@sinclair/typebox").TObje
141
141
  cursor: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
142
142
  }>;
143
143
  export declare const ManageEntitySchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
144
+ action: import("@sinclair/typebox").TLiteral<"get">;
145
+ entity_id: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>;
146
+ entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
147
+ include_deleted: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
148
+ }>, import("@sinclair/typebox").TObject<{
144
149
  action: import("@sinclair/typebox").TLiteral<"create">;
145
150
  entity_type: import("@sinclair/typebox").TString;
146
151
  name: import("@sinclair/typebox").TString;
@@ -191,11 +196,6 @@ export declare const ManageEntitySchema: import("@sinclair/typebox").TUnion<[imp
191
196
  parent_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TNumber, import("@sinclair/typebox").TNull]>>;
192
197
  search: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
193
198
  segment: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
194
- }>, import("@sinclair/typebox").TObject<{
195
- action: import("@sinclair/typebox").TLiteral<"get">;
196
- entity_id: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>;
197
- entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
198
- include_deleted: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
199
199
  }>, import("@sinclair/typebox").TObject<{
200
200
  action: import("@sinclair/typebox").TLiteral<"delete">;
201
201
  entity_id: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>;
@@ -211,8 +211,8 @@ export declare const ManageEntitySchema: import("@sinclair/typebox").TUnion<[imp
211
211
  action: import("@sinclair/typebox").TLiteral<"link">;
212
212
  from_entity_id: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>;
213
213
  to_entity_id: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>;
214
- from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
215
- to_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
214
+ from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
215
+ to_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
216
216
  relationship_type_slug: import("@sinclair/typebox").TString;
217
217
  confidence: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
218
218
  source: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"ui">, import("@sinclair/typebox").TLiteral<"llm">, import("@sinclair/typebox").TLiteral<"feed">, import("@sinclair/typebox").TLiteral<"api">]>>;
@@ -231,16 +231,16 @@ export declare const ManageEntitySchema: import("@sinclair/typebox").TUnion<[imp
231
231
  relationship_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
232
232
  from_entity_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>>;
233
233
  to_entity_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>>;
234
- from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
235
- to_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
234
+ from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
235
+ to_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
236
236
  relationship_type_slug: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
237
237
  }>, import("@sinclair/typebox").TObject<{
238
238
  action: import("@sinclair/typebox").TLiteral<"update_link">;
239
239
  relationship_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
240
240
  from_entity_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>>;
241
241
  to_entity_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>>;
242
- from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
243
- to_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
242
+ from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
243
+ to_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
244
244
  relationship_type_slug: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
245
245
  confidence: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
246
246
  source: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"ui">, import("@sinclair/typebox").TLiteral<"llm">, import("@sinclair/typebox").TLiteral<"feed">, import("@sinclair/typebox").TLiteral<"api">]>>;
@@ -255,7 +255,7 @@ export declare const ManageEntitySchema: import("@sinclair/typebox").TUnion<[imp
255
255
  offset: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
256
256
  action: import("@sinclair/typebox").TLiteral<"list_links">;
257
257
  entity_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TString]>>;
258
- entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
258
+ entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TInteger]>>;
259
259
  record: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
260
260
  type: import("@sinclair/typebox").TString;
261
261
  key: import("@sinclair/typebox").TString;
@@ -292,6 +292,10 @@ export declare const RelationshipRowSchema: import("@sinclair/typebox").TObject<
292
292
  relationship_type_name: import("@sinclair/typebox").TString;
293
293
  is_symmetric: import("@sinclair/typebox").TBoolean;
294
294
  acl_managed: import("@sinclair/typebox").TBoolean;
295
+ from_entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
296
+ to_entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
297
+ from_entity_url: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
298
+ to_entity_url: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
295
299
  from_entity_name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
296
300
  from_entity_slug: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
297
301
  from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
@@ -332,6 +336,7 @@ export declare const ManageEntityItemSchema: import("@sinclair/typebox").TObject
332
336
  root_id: import("@sinclair/typebox").TInteger;
333
337
  member_ids: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TInteger>;
334
338
  }>>;
339
+ entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
335
340
  entity_type: import("@sinclair/typebox").TString;
336
341
  name: import("@sinclair/typebox").TString;
337
342
  slug: import("@sinclair/typebox").TString;
@@ -366,6 +371,7 @@ export declare const ManageEntityResultSchema: import("@sinclair/typebox").TUnio
366
371
  root_id: import("@sinclair/typebox").TInteger;
367
372
  member_ids: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TInteger>;
368
373
  }>>;
374
+ entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
369
375
  entity_type: import("@sinclair/typebox").TString;
370
376
  name: import("@sinclair/typebox").TString;
371
377
  slug: import("@sinclair/typebox").TString;
@@ -399,6 +405,7 @@ export declare const ManageEntityResultSchema: import("@sinclair/typebox").TUnio
399
405
  root_id: import("@sinclair/typebox").TInteger;
400
406
  member_ids: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TInteger>;
401
407
  }>>;
408
+ entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
402
409
  entity_type: import("@sinclair/typebox").TString;
403
410
  name: import("@sinclair/typebox").TString;
404
411
  slug: import("@sinclair/typebox").TString;
@@ -442,6 +449,7 @@ export declare const ManageEntityResultSchema: import("@sinclair/typebox").TUnio
442
449
  root_id: import("@sinclair/typebox").TInteger;
443
450
  member_ids: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TInteger>;
444
451
  }>>;
452
+ entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
445
453
  entity_type: import("@sinclair/typebox").TString;
446
454
  name: import("@sinclair/typebox").TString;
447
455
  slug: import("@sinclair/typebox").TString;
@@ -481,6 +489,7 @@ export declare const ManageEntityResultSchema: import("@sinclair/typebox").TUnio
481
489
  root_id: import("@sinclair/typebox").TInteger;
482
490
  member_ids: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TInteger>;
483
491
  }>>;
492
+ entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
484
493
  entity_type: import("@sinclair/typebox").TString;
485
494
  name: import("@sinclair/typebox").TString;
486
495
  slug: import("@sinclair/typebox").TString;
@@ -547,6 +556,10 @@ export declare const ManageEntityResultSchema: import("@sinclair/typebox").TUnio
547
556
  relationship_type_name: import("@sinclair/typebox").TString;
548
557
  is_symmetric: import("@sinclair/typebox").TBoolean;
549
558
  acl_managed: import("@sinclair/typebox").TBoolean;
559
+ from_entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
560
+ to_entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
561
+ from_entity_url: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
562
+ to_entity_url: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
550
563
  from_entity_name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
551
564
  from_entity_slug: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
552
565
  from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
@@ -574,6 +587,10 @@ export declare const ManageEntityResultSchema: import("@sinclair/typebox").TUnio
574
587
  relationship_type_name: import("@sinclair/typebox").TString;
575
588
  is_symmetric: import("@sinclair/typebox").TBoolean;
576
589
  acl_managed: import("@sinclair/typebox").TBoolean;
590
+ from_entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
591
+ to_entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
592
+ from_entity_url: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
593
+ to_entity_url: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
577
594
  from_entity_name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
578
595
  from_entity_slug: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
579
596
  from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
@@ -621,6 +638,10 @@ export declare const ManageEntityResultSchema: import("@sinclair/typebox").TUnio
621
638
  relationship_type_name: import("@sinclair/typebox").TString;
622
639
  is_symmetric: import("@sinclair/typebox").TBoolean;
623
640
  acl_managed: import("@sinclair/typebox").TBoolean;
641
+ from_entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
642
+ to_entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
643
+ from_entity_url: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
644
+ to_entity_url: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
624
645
  from_entity_name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
625
646
  from_entity_slug: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
626
647
  from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
@@ -677,6 +698,10 @@ export declare const ManageEntityResultSchema: import("@sinclair/typebox").TUnio
677
698
  relationship_type_name: import("@sinclair/typebox").TString;
678
699
  is_symmetric: import("@sinclair/typebox").TBoolean;
679
700
  acl_managed: import("@sinclair/typebox").TBoolean;
701
+ from_entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
702
+ to_entity_type_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
703
+ from_entity_url: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
704
+ to_entity_url: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
680
705
  from_entity_name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
681
706
  from_entity_slug: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
682
707
  from_entity_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
@@ -18,6 +18,10 @@ function SortOrderField(description) {
18
18
  const EntityType = typebox_1.Type.String({
19
19
  description: "Entity type as defined in your workspace",
20
20
  });
21
+ // Type names are local; a discovered numeric ID identifies one immutable type.
22
+ const EntityReferenceType = typebox_1.Type.Union([EntityType, typebox_1.Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER })], {
23
+ description: "[get/list_links and relationship endpoints] A local type slug or discovered numeric type ID. Other actions require a slug. Foreign IDs allow only public-record reads, not workspace access.",
24
+ });
21
25
  const EntityId = typebox_1.Type.Union([
22
26
  typebox_1.Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),
23
27
  typebox_1.Type.String({ minLength: 1, maxLength: 1024 }),
@@ -74,8 +78,8 @@ const IncludeDeleted = typebox_1.Type.Boolean({
74
78
  const EdgeEndpoints = {
75
79
  from_entity_id: EntityId,
76
80
  to_entity_id: EntityId,
77
- from_entity_type: typebox_1.Type.Optional(EntityType),
78
- to_entity_type: typebox_1.Type.Optional(EntityType),
81
+ from_entity_type: typebox_1.Type.Optional(EntityReferenceType),
82
+ to_entity_type: typebox_1.Type.Optional(EntityReferenceType),
79
83
  relationship_type_slug: typebox_1.Type.String({
80
84
  description: "[link/unlink/update_link/list_links] Relationship type slug",
81
85
  minLength: 1,
@@ -157,7 +161,7 @@ exports.ListEntitiesAction = typebox_1.Type.Object({
157
161
  exports.GetEntityAction = typebox_1.Type.Object({
158
162
  action: typebox_1.Type.Literal("get", { description: "Fetch one entity." }),
159
163
  entity_id: EntityId,
160
- entity_type: typebox_1.Type.Optional(EntityType),
164
+ entity_type: typebox_1.Type.Optional(EntityReferenceType),
161
165
  include_deleted: typebox_1.Type.Optional(IncludeDeleted),
162
166
  });
163
167
  exports.DeleteEntityAction = typebox_1.Type.Object({
@@ -248,7 +252,7 @@ exports.ListLinksAction = typebox_1.Type.Object({
248
252
  description: "List relationships for an entity with filters + counts.",
249
253
  }),
250
254
  entity_id: typebox_1.Type.Optional(EntityId),
251
- entity_type: typebox_1.Type.Optional(EntityType),
255
+ entity_type: typebox_1.Type.Optional(EntityReferenceType),
252
256
  record: typebox_1.Type.Optional(typebox_1.Type.Object({
253
257
  type: typebox_1.Type.String({ minLength: 1 }),
254
258
  key: typebox_1.Type.String({ minLength: 1 }),
@@ -287,10 +291,12 @@ exports.DiscoverDuplicatesAction = typebox_1.Type.Object({
287
291
  })),
288
292
  });
289
293
  exports.ManageEntitySchema = typebox_1.Type.Union([
294
+ // MCP flattens duplicate fields first-occurrence-wins: advertise the read
295
+ // selector superset while each mutation still validates its slug-only input.
296
+ exports.GetEntityAction,
290
297
  exports.CreateEntityAction,
291
298
  exports.UpdateEntityAction,
292
299
  exports.ListEntitiesAction,
293
- exports.GetEntityAction,
294
300
  exports.DeleteEntityAction,
295
301
  exports.LinkEntitiesAction,
296
302
  exports.UnlinkEntitiesAction,
@@ -325,6 +331,11 @@ exports.RelationshipRowSchema = typebox_1.Type.Object({
325
331
  // dead affordance this exists to remove. Every producer projects it from
326
332
  // the one shared RELATIONSHIP_SELECT, so no path needs to omit it.
327
333
  acl_managed: typebox_1.Type.Boolean(),
334
+ from_entity_type_id: typebox_1.Type.Optional(typebox_1.Type.Integer({ minimum: 1 })),
335
+ to_entity_type_id: typebox_1.Type.Optional(typebox_1.Type.Integer({ minimum: 1 })),
336
+ // Canonical links for foreign endpoints; same-workspace peeks are unchanged.
337
+ from_entity_url: typebox_1.Type.Optional(typebox_1.Type.String()),
338
+ to_entity_url: typebox_1.Type.Optional(typebox_1.Type.String()),
328
339
  from_entity_name: typebox_1.Type.Optional(typebox_1.Type.String()),
329
340
  from_entity_slug: typebox_1.Type.Optional(typebox_1.Type.String()),
330
341
  from_entity_type: typebox_1.Type.Optional(typebox_1.Type.String()),
@@ -363,6 +374,7 @@ exports.EntityIdentitySchema = typebox_1.Type.Object({
363
374
  exports.ManageEntityItemSchema = typebox_1.Type.Object({
364
375
  id: typebox_1.Type.Union([EntityId, typebox_1.Type.Null()]),
365
376
  identity: typebox_1.Type.Optional(exports.EntityIdentitySchema),
377
+ entity_type_id: typebox_1.Type.Optional(typebox_1.Type.Integer({ minimum: 1 })),
366
378
  entity_type: typebox_1.Type.String(),
367
379
  name: typebox_1.Type.String(),
368
380
  slug: typebox_1.Type.String(),
@@ -26,6 +26,7 @@ export * from "./logger";
26
26
  export * from "./modules";
27
27
  export type { OtelConfig, Span, Tracer } from "./otel";
28
28
  export { createChildSpan, createRootSpan, createSpan, flushTracing, getCurrentSpan, getTraceparent, getTracer, initTracing, runInSpanContext, SpanKind, SpanStatusCode, shutdownTracing, withChildSpan, withSpan, } from "./otel";
29
+ export { currentTraceLogFields, traceparentHeader } from "./trace-context";
29
30
  export type { ProviderConfigEntry, ProviderOAuthConfig, ProviderOAuthGrantKind, } from "./provider-config-types";
30
31
  export { isSdkCompat, type PiAiApi, resolveSdkCompat, SDK_COMPAT_PROTOCOLS, type SdkCompat, type SdkCompatProtocol, } from "./sdk-compat";
31
32
  export * from "./secret-refs";
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.withLobuFileParameters = exports.slugify = exports.titleFromSessionJsonl = exports.parseSessionEntries = exports.entryToMessage = exports.sanitizeSuggestionPrompts = exports.SUGGESTION_LIMITS = exports.isRefreshSuspended = exports.hasCredentialSource = exports.generateTraceId = exports.extractTraceId = exports.SDK_COMPAT_PROTOCOLS = exports.resolveSdkCompat = exports.isSdkCompat = exports.withSpan = exports.withChildSpan = exports.shutdownTracing = exports.SpanStatusCode = exports.SpanKind = exports.runInSpanContext = exports.initTracing = exports.getTracer = exports.getTraceparent = exports.getCurrentSpan = exports.flushTracing = exports.createSpan = exports.createRootSpan = exports.createChildSpan = exports.renderSkillMemorySection = exports.renderFallbackSystemContext = exports.BaseInstructionProvider = exports.CommandRegistry = exports.inferGrantKind = void 0;
19
+ exports.withLobuFileParameters = exports.slugify = exports.titleFromSessionJsonl = exports.parseSessionEntries = exports.entryToMessage = exports.sanitizeSuggestionPrompts = exports.SUGGESTION_LIMITS = exports.isRefreshSuspended = exports.hasCredentialSource = exports.generateTraceId = exports.extractTraceId = exports.SDK_COMPAT_PROTOCOLS = exports.resolveSdkCompat = exports.isSdkCompat = exports.traceparentHeader = exports.currentTraceLogFields = exports.withSpan = exports.withChildSpan = exports.shutdownTracing = exports.SpanStatusCode = exports.SpanKind = exports.runInSpanContext = exports.initTracing = exports.getTracer = exports.getTraceparent = exports.getCurrentSpan = exports.flushTracing = exports.createSpan = exports.createRootSpan = exports.createChildSpan = exports.renderSkillMemorySection = exports.renderFallbackSystemContext = exports.BaseInstructionProvider = exports.CommandRegistry = exports.inferGrantKind = void 0;
20
20
  __exportStar(require("./agent-policy"), exports);
21
21
  __exportStar(require("./tool-trace-summary"), exports);
22
22
  __exportStar(require("./shell-safety"), exports);
@@ -70,6 +70,9 @@ Object.defineProperty(exports, "SpanStatusCode", { enumerable: true, get: functi
70
70
  Object.defineProperty(exports, "shutdownTracing", { enumerable: true, get: function () { return otel_1.shutdownTracing; } });
71
71
  Object.defineProperty(exports, "withChildSpan", { enumerable: true, get: function () { return otel_1.withChildSpan; } });
72
72
  Object.defineProperty(exports, "withSpan", { enumerable: true, get: function () { return otel_1.withSpan; } });
73
+ var trace_context_1 = require("./trace-context");
74
+ Object.defineProperty(exports, "currentTraceLogFields", { enumerable: true, get: function () { return trace_context_1.currentTraceLogFields; } });
75
+ Object.defineProperty(exports, "traceparentHeader", { enumerable: true, get: function () { return trace_context_1.traceparentHeader; } });
73
76
  // Wire-protocol registry (sdkCompat → pi-ai adapter)
74
77
  var sdk_compat_1 = require("./sdk-compat");
75
78
  Object.defineProperty(exports, "isSdkCompat", { enumerable: true, get: function () { return sdk_compat_1.isSdkCompat; } });
@@ -10,6 +10,7 @@ const USE_WINSTON_LOGGER = process.env.USE_WINSTON_LOGGER === "true";
10
10
  // Use JSON format for structured logging (better for Loki parsing in production)
11
11
  const USE_JSON_FORMAT = process.env.LOG_FORMAT === "json";
12
12
  const winston_1 = __importDefault(require("winston"));
13
+ const trace_context_1 = require("./trace-context");
13
14
  const diagnostic_scrubber_1 = require("./utils/diagnostic-scrubber");
14
15
  function safeStringify(value, space) {
15
16
  try {
@@ -59,12 +60,14 @@ function createConsoleLogger(serviceName) {
59
60
  // all of these, and that coverage now lives here.
60
61
  msgStr = (0, diagnostic_scrubber_1.scrubDiagnosticValue)(String(message));
61
62
  }
63
+ const traceFields = (0, trace_context_1.currentTraceLogFields)();
62
64
  if (USE_JSON_FORMAT) {
63
65
  return safeStringify({
64
66
  timestamp,
65
67
  level: lvl,
66
68
  service: serviceName,
67
69
  release: process.env.APP_GIT_SHA,
70
+ ...traceFields,
68
71
  message: msgStr,
69
72
  ...(args.length > 0
70
73
  ? { data: args.length === 1 ? args[0] : args }
@@ -75,7 +78,10 @@ function createConsoleLogger(serviceName) {
75
78
  if (args.length > 0) {
76
79
  msgStr += ` ${safeStringify(args.length === 1 ? args[0] : args)}`;
77
80
  }
78
- return `[${timestamp.replace("T", " ").slice(0, 19)}] [${lvl}] [${serviceName}] ${msgStr}`;
81
+ const traced = traceFields.trace_id
82
+ ? ` trace_id=${traceFields.trace_id} span_id=${traceFields.span_id}`
83
+ : "";
84
+ return `[${timestamp.replace("T", " ").slice(0, 19)}] [${lvl}] [${serviceName}] ${msgStr}${traced}`;
79
85
  };
80
86
  return {
81
87
  error: (message, ...args) => {
@@ -131,7 +137,7 @@ function createLogger(serviceName) {
131
137
  format: winston_1.default.format.combine(winston_1.default.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston_1.default.format.errors({ stack: true }), winston_1.default.format.splat(), winston_1.default.format((info) => {
132
138
  // Preserve Winston's symbol fields while applying the same boundary
133
139
  // scrubbing as the default console transport.
134
- return Object.assign(info, (0, diagnostic_scrubber_1.scrubDiagnosticValue)(info));
140
+ return Object.assign(info, (0, diagnostic_scrubber_1.scrubDiagnosticValue)(info), (0, trace_context_1.currentTraceLogFields)());
135
141
  })()),
136
142
  defaultMeta: { service: serviceName, release: process.env.APP_GIT_SHA },
137
143
  transports,