@lucern/mcp 0.3.0-alpha.6 → 0.3.0-alpha.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.
package/dist/index.js CHANGED
@@ -90,6 +90,9 @@ function hasValue(value) {
90
90
  }
91
91
  return true;
92
92
  }
93
+ function isRecord(value) {
94
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
95
+ }
93
96
  function normalizeToolExecutionParams(params) {
94
97
  const normalized = { ...params };
95
98
  for (const aliases of SCOPE_ALIAS_GROUPS) {
@@ -112,16 +115,19 @@ function parseToolExecutionMetadata(result) {
112
115
  }
113
116
  try {
114
117
  const payload = JSON.parse(raw);
118
+ if (!isRecord(payload)) {
119
+ return { isError: Boolean(result.isError) };
120
+ }
115
121
  return {
116
122
  isError: Boolean(result.isError),
117
123
  code: typeof payload.code === "string" ? payload.code : void 0,
118
124
  status: typeof payload.status === "number" ? payload.status : void 0,
119
- correlationId: typeof payload.correlationId === "string" || payload.correlationId === null ? payload.correlationId : void 0,
120
- policyTraceId: typeof payload.policyTraceId === "string" || payload.policyTraceId === null ? payload.policyTraceId : void 0,
121
- invariant: typeof payload.invariant === "string" || payload.invariant === null ? payload.invariant : void 0
125
+ correlationId: optionalStringOrNull(payload.correlationId),
126
+ policyTraceId: optionalStringOrNull(payload.policyTraceId),
127
+ invariant: optionalStringOrNull(payload.invariant)
122
128
  };
123
- } catch {
124
- return { isError: Boolean(result.isError) };
129
+ } catch (error) {
130
+ return ignoreMalformedToolMetadata(error, result);
125
131
  }
126
132
  }
127
133
  async function executeToolWithEnvelope(args) {
@@ -139,6 +145,15 @@ async function executeToolWithEnvelope(args) {
139
145
  });
140
146
  return result;
141
147
  }
148
+ function ignoreMalformedToolMetadata(_error, result) {
149
+ return { isError: Boolean(result.isError) };
150
+ }
151
+ function optionalStringOrNull(value) {
152
+ if (typeof value === "string" || value === null) {
153
+ return value;
154
+ }
155
+ return void 0;
156
+ }
142
157
 
143
158
  // src/agentInstructions.ts
144
159
  var LUCERN_OBSERVER_PROMPT_NAME = "lucern-observer";
@@ -187,9 +202,29 @@ function buildLucernObserverPrompt(topicId) {
187
202
  ].join("\n");
188
203
  }
189
204
 
205
+ // ../cli/src/guards.ts
206
+ function isRecord2(value) {
207
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
208
+ }
209
+ function formatUnknownError(error) {
210
+ if (error instanceof Error) {
211
+ return error.message;
212
+ }
213
+ if (typeof error === "string") {
214
+ return error;
215
+ }
216
+ return String(error);
217
+ }
218
+
190
219
  // ../cli/src/types.ts
191
220
  var EXIT = {
221
+ ok: 0,
222
+ usage: 2,
223
+ auth: 10,
192
224
  config: 11,
225
+ api: 20,
226
+ invariant: 30,
227
+ local: 40,
193
228
  unexpected: 70
194
229
  };
195
230
  var CliError = class extends Error {
@@ -217,6 +252,34 @@ var CliError = class extends Error {
217
252
  }
218
253
  };
219
254
 
255
+ // ../cli/src/parse.ts
256
+ function parseJsonValue(value, label) {
257
+ try {
258
+ return JSON.parse(value);
259
+ } catch (error) {
260
+ if (error instanceof SyntaxError) {
261
+ throw new CliError({
262
+ code: "USAGE_INVALID_JSON",
263
+ exitCode: EXIT.usage,
264
+ message: `${label} must be valid JSON.`,
265
+ details: formatUnknownError(error)
266
+ });
267
+ }
268
+ throw error;
269
+ }
270
+ }
271
+ function parseJsonRecord(value, label) {
272
+ const parsed = parseJsonValue(value, label);
273
+ if (!isRecord2(parsed)) {
274
+ throw new CliError({
275
+ code: "USAGE_INVALID_JSON",
276
+ exitCode: EXIT.usage,
277
+ message: `${label} must be a JSON object.`
278
+ });
279
+ }
280
+ return parsed;
281
+ }
282
+
220
283
  // ../cli/src/config.ts
221
284
  var CONFIG_DIR = ".lucern";
222
285
  var CREDENTIALS_FILE = "credentials";
@@ -237,9 +300,14 @@ function loadProfile(options) {
237
300
  const profiles = readProfilesFile(profilesPath());
238
301
  const localEnv = options.readLocalEnv === false ? {} : readLocalEnvFiles(options.cwd);
239
302
  const mergedEnv = { ...localEnv, ...options.env };
240
- const selected = options.profileName ?? mergedEnv.LUCERN_PROFILE ?? profiles.activeProfile ?? credentials.LUCERN_PROFILE ?? "default";
241
- const savedProfile = profiles.profiles?.[selected] ?? {};
242
303
  const envProfile = profileFromEnvironment(mergedEnv);
304
+ const hasEnvCredentials = Boolean(
305
+ envProfile.apiKey || envProfile.userToken || envProfile.packKey
306
+ );
307
+ const explicitProfileSelected = options.profileName !== void 0 || mergedEnv.LUCERN_PROFILE !== void 0;
308
+ const selectedProfile = options.profileName ?? mergedEnv.LUCERN_PROFILE ?? profiles.activeProfile ?? credentials.LUCERN_PROFILE ?? "default";
309
+ const selected = hasEnvCredentials && !explicitProfileSelected ? "env" : selectedProfile;
310
+ const savedProfile = hasEnvCredentials && !explicitProfileSelected ? {} : profiles.profiles?.[selectedProfile] ?? {};
243
311
  const credentialsProfile = {
244
312
  apiKey: credentials.LUCERN_API_KEY,
245
313
  userToken: readFirst(credentials, ["LUCERN_SESSION_TOKEN", "LUCERN_USER_TOKEN"]),
@@ -329,13 +397,21 @@ function readProfilesFile(path3) {
329
397
  return {};
330
398
  }
331
399
  try {
332
- return JSON.parse(readFileSync(path3, "utf8"));
400
+ const parsed = parseJsonRecord(readFileSync(path3, "utf8"), path3);
401
+ if (!isProfilesFile(parsed)) {
402
+ throw new CliError({
403
+ code: "CONFIG_INVALID_PROFILE_FILE",
404
+ exitCode: EXIT.config,
405
+ message: `${path3} must be a JSON object with profile definitions.`
406
+ });
407
+ }
408
+ return parsed;
333
409
  } catch (error) {
334
410
  throw new CliError({
335
411
  code: "CONFIG_INVALID_PROFILE_FILE",
336
412
  exitCode: EXIT.config,
337
413
  message: `${path3} is not valid JSON.`,
338
- details: error
414
+ details: formatUnknownError(error)
339
415
  });
340
416
  }
341
417
  }
@@ -394,12 +470,32 @@ function stripQuotes(value) {
394
470
  if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
395
471
  try {
396
472
  return JSON.parse(trimmed);
397
- } catch {
398
- return trimmed.slice(1, -1);
473
+ } catch (error) {
474
+ return ignoreQuotedValueParseError(error, trimmed);
399
475
  }
400
476
  }
401
477
  return trimmed;
402
478
  }
479
+ function ignoreQuotedValueParseError(_error, trimmed) {
480
+ return trimmed.slice(1, -1);
481
+ }
482
+ function isProfilesFile(value) {
483
+ if (!isRecord2(value)) {
484
+ return false;
485
+ }
486
+ if (value.activeProfile !== void 0 && typeof value.activeProfile !== "string") {
487
+ return false;
488
+ }
489
+ if (value.profiles === void 0) {
490
+ return true;
491
+ }
492
+ if (!isRecord2(value.profiles)) {
493
+ return false;
494
+ }
495
+ return Object.values(value.profiles).every(
496
+ (profile) => profile === void 0 || isRecord2(profile)
497
+ );
498
+ }
403
499
 
404
500
  // ../contracts/src/graph-intelligence.contract.ts
405
501
  var GRAPH_INTELLIGENCE_QUERY_CATALOG_VERSION = "graph_intelligence_query_catalog.v1";
@@ -5332,6 +5428,11 @@ var TENANT_CLIENT_INSTALLABLE_PACKAGES = [
5332
5428
  role: "sdk_dependency",
5333
5429
  directTenantImport: false
5334
5430
  },
5431
+ {
5432
+ packageName: "@lucern/graph-sync",
5433
+ role: "host_addon_runtime",
5434
+ directTenantImport: true
5435
+ },
5335
5436
  {
5336
5437
  packageName: "@lucern/identity",
5337
5438
  role: "component_runtime",
@@ -5620,8 +5721,11 @@ function compactRecord(input) {
5620
5721
  Object.entries(input).filter(([, value]) => value !== void 0)
5621
5722
  );
5622
5723
  }
5724
+ function isRecord3(value) {
5725
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5726
+ }
5623
5727
  function recordValue(value) {
5624
- return value && typeof value === "object" && !Array.isArray(value) ? value : {};
5728
+ return isRecord3(value) ? value : {};
5625
5729
  }
5626
5730
  var createEvidenceProjection = defineProjection({
5627
5731
  contractName: "create_evidence",
@@ -6327,9 +6431,16 @@ var ADD_WORKTREE = {
6327
6431
  },
6328
6432
  projectId: {
6329
6433
  type: "string",
6330
- description: "Legacy topicId alias"
6434
+ description: "Legacy topicId alias or resolver hint"
6435
+ },
6436
+ topicId: {
6437
+ type: "string",
6438
+ description: "Optional topic scope hint for resolver validation"
6439
+ },
6440
+ topicHint: {
6441
+ type: "string",
6442
+ description: "Natural-language topic hint for automatic topic resolution"
6331
6443
  },
6332
- topicId: { type: "string", description: "Optional topic scope hint" },
6333
6444
  branchId: {
6334
6445
  type: "string",
6335
6446
  description: "The branch this worktree investigates"
@@ -6427,6 +6538,22 @@ var ADD_WORKTREE = {
6427
6538
  type: "string",
6428
6539
  description: "Optional domain pack whose shaping hooks should influence generated questions and tasks"
6429
6540
  },
6541
+ tags: {
6542
+ type: "array",
6543
+ description: "Additional topic-resolution tags for the worktree"
6544
+ },
6545
+ touchedPaths: {
6546
+ type: "array",
6547
+ description: "File paths used as topic-resolution signals"
6548
+ },
6549
+ sourceRef: {
6550
+ type: "string",
6551
+ description: "Source reference used as a topic-resolution signal"
6552
+ },
6553
+ sourceKind: {
6554
+ type: "string",
6555
+ description: "Source kind used as a topic-resolution signal"
6556
+ },
6430
6557
  campaign: {
6431
6558
  type: "number",
6432
6559
  description: "Top-level pipeline campaign number. Campaigns define the outer execution slice."
@@ -6464,7 +6591,7 @@ var ADD_WORKTREE = {
6464
6591
  description: "Timestamp when worktree metadata was last reconciled"
6465
6592
  }
6466
6593
  },
6467
- required: ["title", "topicId"],
6594
+ required: ["title"],
6468
6595
  response: {
6469
6596
  description: "The created worktree",
6470
6597
  fields: {
@@ -7961,15 +8088,15 @@ var IDENTITY_WHOAMI = {
7961
8088
  };
7962
8089
  var COMPILE_CONTEXT = {
7963
8090
  name: "compile_context",
7964
- description: "Compile a focused reasoning context for a topic. Like `git log --graph --decorate` for the reasoning substrate \u2014 returns the canonical Pillar 3 context pack through the public API shape.",
8091
+ description: "Compile a focused reasoning context. If topicId is omitted, Lucern resolves the best topic from the query. Like `git log --graph --decorate` for the reasoning substrate \u2014 returns the canonical Pillar 3 context pack through the public API shape.",
7965
8092
  parameters: {
7966
8093
  topicId: {
7967
8094
  type: "string",
7968
- description: "Topic scope ID to compile"
8095
+ description: "Optional topic scope ID. Omit to resolve the topic from query."
7969
8096
  },
7970
8097
  query: {
7971
8098
  type: "string",
7972
- description: "Optional focus query used to rank context items"
8099
+ description: "Focus query used to resolve the topic and rank context items. Required when topicId is omitted."
7973
8100
  },
7974
8101
  budget: {
7975
8102
  type: "number",
@@ -7993,7 +8120,7 @@ var COMPILE_CONTEXT = {
7993
8120
  description: "Include related ontological entities in the compiled result"
7994
8121
  }
7995
8122
  },
7996
- required: ["topicId"],
8123
+ required: [],
7997
8124
  response: {
7998
8125
  description: "Compiled context pack for the requested topic",
7999
8126
  fields: {
@@ -8167,18 +8294,60 @@ var CREATE_TASK = {
8167
8294
  name: "create_task",
8168
8295
  description: "Create an execution task tied to the reasoning state. Like `git task` \u2014 tracks concrete work items (calls to make, data to gather, analyses to run) linked to questions, beliefs, or worktrees.",
8169
8296
  parameters: {
8170
- title: { type: "string", description: "Task description" },
8297
+ title: { type: "string", description: "Task title" },
8171
8298
  topicId: { type: "string", description: "Topic scope" },
8299
+ description: {
8300
+ type: "string",
8301
+ description: "Long-form task description"
8302
+ },
8172
8303
  taskType: {
8173
8304
  type: "string",
8174
- description: "Type: research, interview, analysis, data_collection",
8175
- enum: ["research", "interview", "analysis", "data_collection"]
8305
+ description: "Task taxonomy",
8306
+ enum: [
8307
+ "general",
8308
+ "find_evidence",
8309
+ "verify_claim",
8310
+ "research",
8311
+ "review",
8312
+ "interview",
8313
+ "analysis",
8314
+ "track_metrics"
8315
+ ]
8316
+ },
8317
+ priority: {
8318
+ type: "string",
8319
+ description: "Priority",
8320
+ enum: ["urgent", "high", "medium", "low"]
8321
+ },
8322
+ status: {
8323
+ type: "string",
8324
+ description: "Initial status (defaults to todo)",
8325
+ enum: ["todo", "in_progress", "blocked", "done"]
8326
+ },
8327
+ linkedWorktreeId: {
8328
+ type: "string",
8329
+ description: "Worktree this task belongs to"
8330
+ },
8331
+ linkedBeliefId: {
8332
+ type: "string",
8333
+ description: "Belief this task supports"
8176
8334
  },
8177
8335
  linkedQuestionId: {
8178
8336
  type: "string",
8179
8337
  description: "Question this task addresses"
8180
8338
  },
8181
- linkedWorktreeId: { type: "string", description: "Worktree scope" }
8339
+ assigneeId: {
8340
+ type: "string",
8341
+ description: "Principal assigned to the task"
8342
+ },
8343
+ dueDate: {
8344
+ type: "number",
8345
+ description: "Due date as epoch milliseconds"
8346
+ },
8347
+ tags: {
8348
+ type: "array",
8349
+ description: "Free-form string tags"
8350
+ }
8182
8351
  },
8183
8352
  required: ["title"],
8184
8353
  response: {
@@ -10273,9 +10442,7 @@ function mcpContractFromArgsSchema(base, args, contractName) {
10273
10442
  required: converted.filter(([, field]) => field.required).map(([fieldName]) => fieldName)
10274
10443
  };
10275
10444
  }
10276
- function defineFunctionContract(contract) {
10277
- return contract;
10278
- }
10445
+ var defineFunctionContract = (contract) => contract;
10279
10446
  function authUserId(context) {
10280
10447
  return context.userId ?? context.principalId ?? "lucern-agent";
10281
10448
  }
@@ -10429,6 +10596,9 @@ var observationContextArgs = z.object({
10429
10596
  limit: z.number().optional().describe("Maximum observations to return."),
10430
10597
  status: z.string().optional().describe("Observation status filter.")
10431
10598
  });
10599
+ function isRecord4(value) {
10600
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
10601
+ }
10432
10602
  var observationInput = (input, context) => withUserId(
10433
10603
  compactRecord4({
10434
10604
  projectId: input.projectId,
@@ -10461,7 +10631,7 @@ var contextContracts = [
10461
10631
  path: "/context/compile",
10462
10632
  sdkNamespace: "context",
10463
10633
  sdkMethod: "compileContext",
10464
- summary: "Compile a focused reasoning context for a topic.",
10634
+ summary: "Compile a focused reasoning context, resolving topic from query when omitted.",
10465
10635
  convex: {
10466
10636
  module: "contextCompiler",
10467
10637
  functionName: "compile",
@@ -10483,8 +10653,8 @@ var contextContracts = [
10483
10653
  kind: "mutation",
10484
10654
  inputProjection: observationInput,
10485
10655
  outputProjection: (output, input) => ({
10486
- ...output && typeof output === "object" ? output : {},
10487
- observationId: output && typeof output === "object" ? output.nodeId : void 0,
10656
+ ...isRecord4(output) ? output : {},
10657
+ observationId: isRecord4(output) ? output.nodeId : void 0,
10488
10658
  observationType: input.observationType
10489
10659
  })
10490
10660
  },
@@ -11965,10 +12135,11 @@ var worktreeDecisionGateInputSchema = z.object({
11965
12135
  decidedBy: z.string().optional().describe("Actor that decided the gate verdict.")
11966
12136
  }).passthrough().describe("Decision gate contract for worktree activation or exit.");
11967
12137
  var addWorktreeArgs = z.object({
11968
- title: z.string().optional().describe("Human-readable worktree name or objective."),
12138
+ title: z.string().describe("Human-readable worktree name or objective."),
11969
12139
  name: z.string().optional().describe("Storage-name alias for callers that already use backend naming."),
11970
- topicId: z.string().describe("Primary topic scope for the worktree."),
11971
- projectId: z.string().optional().describe("Legacy topicId alias."),
12140
+ topicId: z.string().optional().describe("Optional primary topic scope hint for resolver validation."),
12141
+ projectId: z.string().optional().describe("Legacy topicId alias/hint."),
12142
+ topicHint: z.string().optional().describe("Natural-language topic hint for automatic topic resolution."),
11972
12143
  branchId: z.string().optional().describe("Legacy branch identifier for compatibility with workflow callers."),
11973
12144
  objective: z.string().optional().describe("Reasoning objective this worktree is intended to resolve."),
11974
12145
  hypothesis: z.string().optional().describe("Testable claim this worktree investigates."),
@@ -11993,6 +12164,10 @@ var addWorktreeArgs = z.object({
11993
12164
  autoShape: z.boolean().optional().describe("Whether to invoke inquiry auto-shaping during creation."),
11994
12165
  autoFixPolicy: autoFixPolicyInputSchema.optional(),
11995
12166
  domainPackId: z.string().optional().describe("Domain pack whose shaping hooks should influence the worktree."),
12167
+ tags: z.array(z.string()).optional().describe("Additional topic-resolution tags for the worktree."),
12168
+ touchedPaths: z.array(z.string()).optional().describe("File paths used as topic-resolution signals."),
12169
+ sourceRef: z.string().optional().describe("Source reference used as a topic-resolution signal."),
12170
+ sourceKind: z.string().optional().describe("Source kind used as a topic-resolution signal."),
11996
12171
  campaign: z.number().optional().describe("Top-level pipeline campaign number."),
11997
12172
  lane: z.string().optional().describe("Campaign lane for the worktree."),
11998
12173
  laneOrderInCampaign: z.number().optional().describe("Ordering for this lane within its campaign."),
@@ -12322,8 +12497,46 @@ var worktreesContracts = [
12322
12497
  args: openPullRequestArgs
12323
12498
  })
12324
12499
  ];
12325
-
12326
- // ../contracts/src/function-registry/tasks.ts
12500
+ var taskPrioritySchema = z.enum(["urgent", "high", "medium", "low"]);
12501
+ var taskStatusSchema2 = z.enum(["todo", "in_progress", "blocked", "done"]);
12502
+ var taskTypeSchema = z.enum([
12503
+ "general",
12504
+ "find_evidence",
12505
+ "verify_claim",
12506
+ "research",
12507
+ "review",
12508
+ "interview",
12509
+ "analysis",
12510
+ "track_metrics"
12511
+ ]);
12512
+ var createTaskArgs = z.object({
12513
+ title: z.string().describe("Task title."),
12514
+ topicId: z.string().optional().describe("Topic scope."),
12515
+ description: z.string().optional().describe("Long-form task description."),
12516
+ taskType: taskTypeSchema.optional().describe("Task taxonomy."),
12517
+ priority: taskPrioritySchema.optional().describe("Priority. Defaults to medium when omitted by the server."),
12518
+ status: taskStatusSchema2.optional().describe("Initial status. Defaults to todo."),
12519
+ linkedWorktreeId: z.string().optional().describe("Worktree this task belongs to."),
12520
+ linkedBeliefId: z.string().optional().describe("Belief this task supports."),
12521
+ linkedQuestionId: z.string().optional().describe("Question this task addresses."),
12522
+ assigneeId: z.string().optional().describe("Principal assigned to the task."),
12523
+ dueDate: z.number().optional().describe("Due date as epoch milliseconds."),
12524
+ tags: z.array(z.string()).optional().describe("Free-form tags.")
12525
+ });
12526
+ var createTaskInput = (input) => compactRecord4({
12527
+ title: input.title,
12528
+ topicId: input.topicId,
12529
+ description: input.description,
12530
+ taskType: input.taskType,
12531
+ priority: input.priority ?? "medium",
12532
+ status: input.status ?? "todo",
12533
+ linkedWorktreeId: input.linkedWorktreeId,
12534
+ linkedBeliefId: input.linkedBeliefId,
12535
+ linkedQuestionId: input.linkedQuestionId,
12536
+ assigneeId: input.assigneeId,
12537
+ dueDate: input.dueDate,
12538
+ tags: input.tags
12539
+ });
12327
12540
  var taskInput = (input) => compactRecord4({
12328
12541
  ...input,
12329
12542
  taskId: input.taskId ?? input.id
@@ -12355,8 +12568,10 @@ var tasksContracts = [
12355
12568
  convex: {
12356
12569
  module: "tasks",
12357
12570
  functionName: "create",
12358
- kind: "mutation"
12359
- }
12571
+ kind: "mutation",
12572
+ inputProjection: createTaskInput
12573
+ },
12574
+ args: createTaskArgs
12360
12575
  }),
12361
12576
  surfaceContract({
12362
12577
  name: "list_tasks",
@@ -13475,9 +13690,12 @@ var ALL_FUNCTION_CONTRACTS = [
13475
13690
  ];
13476
13691
  assertSurfaceCoverage(ALL_FUNCTION_CONTRACTS);
13477
13692
  var FUNCTION_SURFACE_CONTRACTS = ALL_FUNCTION_CONTRACTS;
13478
- new Map(
13693
+ var FUNCTION_CONTRACTS_BY_NAME = new Map(
13479
13694
  ALL_FUNCTION_CONTRACTS.map((contract) => [contract.name, contract])
13480
13695
  );
13696
+ FUNCTION_CONTRACTS_BY_NAME.get.bind(
13697
+ FUNCTION_CONTRACTS_BY_NAME
13698
+ );
13481
13699
 
13482
13700
  // ../contracts/src/tenant-bootstrap-seed.contract.ts
13483
13701
  function isCopyableSeedRequirement(entry) {
@@ -14123,10 +14341,18 @@ function isInfisicalRuntimeDisabled(env = {}) {
14123
14341
  }
14124
14342
  async function hydrateInfisicalRuntimeEnv(options) {
14125
14343
  const env = options.env ?? {};
14126
- const bootstrap = mergeBootstrap(
14127
- readInfisicalRuntimeBootstrap(env, options.bootstrap),
14128
- options.bootstrap
14129
- );
14344
+ const baseBootstrap = readInfisicalRuntimeBootstrap(env, options.bootstrap);
14345
+ const bootstrap = baseBootstrap ? {
14346
+ ...baseBootstrap,
14347
+ ...Object.fromEntries(
14348
+ Object.entries(options.bootstrap ?? {}).filter(
14349
+ ([, value]) => value !== void 0
14350
+ )
14351
+ ),
14352
+ apiUrl: trimTrailingSlash(
14353
+ options.bootstrap?.apiUrl ?? baseBootstrap.apiUrl
14354
+ )
14355
+ } : null;
14130
14356
  if (!bootstrap) {
14131
14357
  return {
14132
14358
  status: "disabled",
@@ -14222,16 +14448,6 @@ function normalizeInfisicalEnvironment(value) {
14222
14448
  }
14223
14449
  return "prod";
14224
14450
  }
14225
- function mergeBootstrap(base, overrides) {
14226
- if (!base) {
14227
- return null;
14228
- }
14229
- return {
14230
- ...base,
14231
- ...compact(overrides ?? {}),
14232
- apiUrl: trimTrailingSlash(overrides?.apiUrl ?? base.apiUrl)
14233
- };
14234
- }
14235
14451
  async function loginWithUniversalAuth(bootstrap, fetchImpl) {
14236
14452
  const response = await fetchImpl(
14237
14453
  `${trimTrailingSlash(bootstrap.apiUrl)}/api/v1/auth/universal-auth/login`,
@@ -14316,14 +14532,18 @@ async function readSecretValue(args) {
14316
14532
  async function readJson(response) {
14317
14533
  try {
14318
14534
  return await response.json();
14319
- } catch {
14535
+ } catch (error) {
14536
+ debugInfisicalRuntimeFallback("response.json", error);
14320
14537
  return void 0;
14321
14538
  }
14322
14539
  }
14540
+ function isRecord5(value) {
14541
+ return value !== null && typeof value === "object" && !Array.isArray(value);
14542
+ }
14323
14543
  function readNestedString(value, path3) {
14324
14544
  let current = value;
14325
14545
  for (const key of path3) {
14326
- if (!current || typeof current !== "object" || !(key in current)) {
14546
+ if (!isRecord5(current) || !(key in current)) {
14327
14547
  return null;
14328
14548
  }
14329
14549
  current = current[key];
@@ -14331,13 +14551,12 @@ function readNestedString(value, path3) {
14331
14551
  return typeof current === "string" && current.length > 0 ? current : null;
14332
14552
  }
14333
14553
  function messageFromBody(body4) {
14334
- if (!body4 || typeof body4 !== "object") {
14554
+ if (!isRecord5(body4)) {
14335
14555
  return "no response body";
14336
14556
  }
14337
- const record = body4;
14338
14557
  for (const key of ["message", "error", "errorMessage"]) {
14339
- if (typeof record[key] === "string") {
14340
- return record[key];
14558
+ if (typeof body4[key] === "string") {
14559
+ return body4[key];
14341
14560
  }
14342
14561
  }
14343
14562
  return JSON.stringify(body4);
@@ -14357,10 +14576,32 @@ function isTruthyEnv(value) {
14357
14576
  function trimTrailingSlash(value) {
14358
14577
  return value.replace(/\/+$/u, "");
14359
14578
  }
14360
- function compact(value) {
14361
- return Object.fromEntries(
14362
- Object.entries(value).filter(([, entry]) => entry !== void 0)
14363
- );
14579
+ function debugInfisicalRuntimeFallback(message, error) {
14580
+ const env = globalThis.process?.env;
14581
+ if (env?.LUCERN_COMPAT_FALLBACK_DEBUG !== "1" && env?.LUCERN_INFISICAL_RUNTIME_DEBUG !== "1") {
14582
+ return;
14583
+ }
14584
+ console.debug(`[infisical-runtime] ${message}`, {
14585
+ error: formatInfisicalRuntimeError(error)
14586
+ });
14587
+ }
14588
+ function formatInfisicalRuntimeError(error) {
14589
+ if (error instanceof Error) {
14590
+ return `${error.name}: ${error.message}`;
14591
+ }
14592
+ if (typeof error === "string") {
14593
+ return error;
14594
+ }
14595
+ if (typeof error === "number" || typeof error === "boolean") {
14596
+ return String(error);
14597
+ }
14598
+ if (error && typeof error === "object") {
14599
+ const keys = Object.keys(error).slice(0, 5);
14600
+ if (keys.length > 0) {
14601
+ return `Unknown Infisical runtime error object with keys: ${keys.join(", ")}`;
14602
+ }
14603
+ }
14604
+ return "Unknown Infisical runtime error shape";
14364
14605
  }
14365
14606
 
14366
14607
  // src/infisical-runtime.ts
@@ -14670,6 +14911,7 @@ __export(src_exports, {
14670
14911
  WORKTREE_PHASES: () => WORKTREE_PHASES,
14671
14912
  applyInfisicalRuntimeEnv: () => applyInfisicalRuntimeEnv,
14672
14913
  asListItems: () => asListItems,
14914
+ asRecord: () => asRecord,
14673
14915
  assertValidWebhookSecret: () => assertValidWebhookSecret,
14674
14916
  assertValidWebhookUrl: () => assertValidWebhookUrl,
14675
14917
  buildDeprecatedBranchMetadata: () => buildDeprecatedBranchMetadata,
@@ -14741,6 +14983,7 @@ __export(src_exports, {
14741
14983
  isLensFilterCriteria: () => isLensFilterCriteria2,
14742
14984
  isLucernPrompt: () => isLucernPrompt,
14743
14985
  isMcpToolAllowed: () => isMcpToolAllowed,
14986
+ isRecord: () => isRecord7,
14744
14987
  isTaxonomyFilterCriteriaV1: () => isTaxonomyFilterCriteriaV12,
14745
14988
  lastDelegator: () => lastDelegator,
14746
14989
  listControlObjectOwnershipCases: () => listControlObjectOwnershipCases,
@@ -15050,9 +15293,7 @@ function generatePortableRequestId() {
15050
15293
  8
15051
15294
  ).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10).join("")}`;
15052
15295
  }
15053
- function randomIdempotencyKey() {
15054
- return generatePortableRequestId();
15055
- }
15296
+ var randomIdempotencyKey = generatePortableRequestId;
15056
15297
  function isRetryableStatus(status) {
15057
15298
  return status >= 500 || status === 408 || status === 429;
15058
15299
  }
@@ -15117,8 +15358,11 @@ function timeoutError(timeoutMs) {
15117
15358
  error.name = "AbortError";
15118
15359
  return error;
15119
15360
  }
15361
+ function isRecord6(value) {
15362
+ return value !== null && typeof value === "object" && !Array.isArray(value);
15363
+ }
15120
15364
  function readPolicySummaryFromDetails(details) {
15121
- if (!details || typeof details !== "object" || Array.isArray(details)) {
15365
+ if (!isRecord6(details)) {
15122
15366
  return null;
15123
15367
  }
15124
15368
  const directSummary = details.summary;
@@ -15126,11 +15370,11 @@ function readPolicySummaryFromDetails(details) {
15126
15370
  return directSummary.trim();
15127
15371
  }
15128
15372
  const policy = details.policy;
15129
- if (!policy || typeof policy !== "object" || Array.isArray(policy)) {
15373
+ if (!isRecord6(policy)) {
15130
15374
  return null;
15131
15375
  }
15132
15376
  const explanation = policy.explanation;
15133
- if (!explanation || typeof explanation !== "object" || Array.isArray(explanation)) {
15377
+ if (!isRecord6(explanation)) {
15134
15378
  return null;
15135
15379
  }
15136
15380
  const nestedSummary = explanation.summary;
@@ -15194,11 +15438,11 @@ function createGatewayRequestClient(config = {}) {
15194
15438
  if (!text) {
15195
15439
  return null;
15196
15440
  }
15197
- try {
15198
- return JSON.parse(text);
15199
- } catch {
15441
+ const parsed = tryParseGatewayEnvelopeJson(text);
15442
+ if (!parsed.ok) {
15200
15443
  return null;
15201
15444
  }
15445
+ return isRecord6(parsed.value) ? parsed.value : null;
15202
15446
  }
15203
15447
  function resolveTimeoutMs(method, requestTimeoutMs) {
15204
15448
  if (typeof requestTimeoutMs === "number") {
@@ -15210,16 +15454,31 @@ function createGatewayRequestClient(config = {}) {
15210
15454
  }
15211
15455
  return config.timeoutMs ?? 15e3;
15212
15456
  }
15457
+ function tryParseGatewayEnvelopeJson(text) {
15458
+ const trimmed = text.trim();
15459
+ if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) {
15460
+ return { ok: false, reason: "non-json" };
15461
+ }
15462
+ try {
15463
+ return { ok: true, value: JSON.parse(trimmed) };
15464
+ } catch (error) {
15465
+ if (error instanceof SyntaxError) {
15466
+ return { ok: false, reason: "invalid-json", error };
15467
+ }
15468
+ throw error;
15469
+ }
15470
+ }
15213
15471
  function buildApiError(args) {
15214
15472
  const failure = args.failure;
15215
- const legacyError = failure && typeof failure.error === "object" && failure.error !== null ? failure.error : failure?.legacyError;
15473
+ const legacyError = failure && isRecord6(failure.error) ? failure.error : failure?.legacyError;
15216
15474
  const correlationId = failure?.correlationId ?? args.response.headers.get("x-lucern-correlation-id")?.trim() ?? args.requestId;
15217
15475
  const policyTraceId = failure?.policyTraceId ?? args.response.headers.get("x-lucern-policy-trace-id")?.trim() ?? null;
15218
15476
  const details = failure?.details ?? legacyError?.details;
15219
15477
  const policySummary = readPolicySummaryFromDetails(details);
15478
+ const failureMessage = typeof failure?.error === "string" ? failure.error : legacyError?.message;
15220
15479
  return new LucernApiError({
15221
15480
  code: failure?.code ?? legacyError?.code ?? fallbackErrorCode(args.response.status),
15222
- message: policySummary ?? (typeof failure?.error === "string" ? failure.error : legacyError?.message ?? (args.response.ok ? "Platform API returned an invalid success payload." : "Platform API request failed.")),
15481
+ message: policySummary ?? failureMessage ?? (args.response.ok ? "Platform API returned an invalid success payload." : "Platform API request failed."),
15223
15482
  status: args.response.status,
15224
15483
  invariant: failure?.invariant,
15225
15484
  suggestion: failure?.suggestion,
@@ -15345,8 +15604,11 @@ function createGatewayRequestClient(config = {}) {
15345
15604
  }
15346
15605
 
15347
15606
  // ../sdk/src/sdkSurface.ts
15607
+ function isRecord7(value) {
15608
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
15609
+ }
15348
15610
  function asRecord(value) {
15349
- return value && typeof value === "object" ? value : {};
15611
+ return isRecord7(value) ? value : {};
15350
15612
  }
15351
15613
  function cleanString2(value) {
15352
15614
  return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
@@ -15407,9 +15669,7 @@ function normalizeNodeWriteInput(value) {
15407
15669
  }
15408
15670
  return next;
15409
15671
  }
15410
- function normalizeNodeVerificationStatus(value) {
15411
- return normalizeVerificationStatus(value);
15412
- }
15672
+ var normalizeNodeVerificationStatus = normalizeVerificationStatus;
15413
15673
  function normalizeTopicQuery(value) {
15414
15674
  const topicId = cleanString2(value.topicId);
15415
15675
  if (!topicId) {
@@ -15436,7 +15696,10 @@ function createListResult(items, legacyKey) {
15436
15696
  total: items.length
15437
15697
  };
15438
15698
  if (legacyKey) {
15439
- result[legacyKey] = items;
15699
+ return {
15700
+ ...result,
15701
+ [legacyKey]: items
15702
+ };
15440
15703
  }
15441
15704
  return result;
15442
15705
  }
@@ -15480,6 +15743,17 @@ function asTenantVaultSecretArray(data) {
15480
15743
  }
15481
15744
  function createAdminClient(config = {}) {
15482
15745
  const gateway = createGatewayRequestClient(config);
15746
+ const getControlObjectOwnership = async () => gateway.request({
15747
+ path: "/api/platform/v1/admin/control-ownership"
15748
+ });
15749
+ const createMembership = async (input, idempotencyKey) => gateway.request({
15750
+ path: "/api/platform/v1/memberships",
15751
+ method: "POST",
15752
+ body: input,
15753
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
15754
+ });
15755
+ const updateMembership = createMembership;
15756
+ const upsertMembership = createMembership;
15483
15757
  return {
15484
15758
  /**
15485
15759
  * List tenants visible to the current principal.
@@ -15511,19 +15785,11 @@ function createAdminClient(config = {}) {
15511
15785
  /**
15512
15786
  * Get the control-object ownership contract.
15513
15787
  */
15514
- async getControlObjectOwnership() {
15515
- return gateway.request({
15516
- path: "/api/platform/v1/admin/control-ownership"
15517
- });
15518
- },
15788
+ getControlObjectOwnership,
15519
15789
  /**
15520
15790
  * @deprecated Use getControlObjectOwnership.
15521
15791
  */
15522
- async getControlObjectOwnershipContract() {
15523
- return gateway.request({
15524
- path: "/api/platform/v1/admin/control-ownership"
15525
- });
15526
- },
15792
+ getControlObjectOwnershipContract: getControlObjectOwnership,
15527
15793
  /**
15528
15794
  * List workspaces for the current admin scope.
15529
15795
  */
@@ -15570,26 +15836,15 @@ function createAdminClient(config = {}) {
15570
15836
  /**
15571
15837
  * Create a membership.
15572
15838
  */
15573
- async createMembership(input, idempotencyKey) {
15574
- return gateway.request({
15575
- path: "/api/platform/v1/memberships",
15576
- method: "POST",
15577
- body: input,
15578
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
15579
- });
15580
- },
15839
+ createMembership,
15581
15840
  /**
15582
15841
  * Update a membership.
15583
15842
  */
15584
- async updateMembership(input, idempotencyKey) {
15585
- return this.createMembership(input, idempotencyKey);
15586
- },
15843
+ updateMembership,
15587
15844
  /**
15588
15845
  * @deprecated Use createMembership or updateMembership.
15589
15846
  */
15590
- async upsertMembership(input, idempotencyKey) {
15591
- return this.createMembership(input, idempotencyKey);
15592
- },
15847
+ upsertMembership,
15593
15848
  /**
15594
15849
  * List tenant API keys in the current admin scope.
15595
15850
  */
@@ -15871,115 +16126,111 @@ function createAnswersClient(config = {}) {
15871
16126
  // ../sdk/src/audiencesClient.ts
15872
16127
  function createAudiencesClient(config = {}) {
15873
16128
  const gateway = createGatewayRequestClient(config);
16129
+ const listRegistry = async (query5 = {}) => {
16130
+ return gateway.request({
16131
+ path: `/api/platform/v1/audiences/registry${toQueryString({
16132
+ ...query5,
16133
+ effective: typeof query5.effective === "boolean" ? query5.effective ? "true" : "false" : void 0,
16134
+ status: query5.status
16135
+ })}`
16136
+ }).then(
16137
+ (response) => mapGatewayData(
16138
+ response,
16139
+ (data) => createListResult(Array.isArray(data) ? data : [], "registryEntries")
16140
+ )
16141
+ );
16142
+ };
16143
+ const createRegistryEntry = async (input, idempotencyKey) => {
16144
+ return gateway.request({
16145
+ path: "/api/platform/v1/audiences/registry",
16146
+ method: "POST",
16147
+ body: input,
16148
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
16149
+ });
16150
+ };
16151
+ const updateRegistryEntry = createRegistryEntry;
16152
+ const upsertRegistry = createRegistryEntry;
16153
+ const getRegistry = listRegistry;
16154
+ const listGrants = async (query5 = {}) => {
16155
+ return gateway.request({
16156
+ path: `/api/platform/v1/audiences/grants${toQueryString({
16157
+ ...query5,
16158
+ audienceKey: query5.audienceKey,
16159
+ principalId: query5.principalId,
16160
+ groupId: query5.groupId,
16161
+ status: query5.status
16162
+ })}`
16163
+ }).then(
16164
+ (response) => mapGatewayData(
16165
+ response,
16166
+ (data) => createListResult(Array.isArray(data) ? data : [], "grants")
16167
+ )
16168
+ );
16169
+ };
16170
+ const createGrant = async (input, idempotencyKey) => {
16171
+ return gateway.request({
16172
+ path: "/api/platform/v1/audiences/grants",
16173
+ method: "POST",
16174
+ body: input,
16175
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
16176
+ });
16177
+ };
16178
+ const getGrants = listGrants;
16179
+ const grant = createGrant;
16180
+ const deleteGrant = async (input, idempotencyKey) => {
16181
+ return gateway.request({
16182
+ path: "/api/platform/v1/audiences/grants/revoke",
16183
+ method: "POST",
16184
+ body: input,
16185
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
16186
+ });
16187
+ };
16188
+ const revokeGrant = deleteGrant;
15874
16189
  return {
15875
16190
  /**
15876
16191
  * List audience registry entries.
15877
16192
  */
15878
- async listRegistry(query5 = {}) {
15879
- return gateway.request({
15880
- path: `/api/platform/v1/audiences/registry${toQueryString({
15881
- ...query5,
15882
- effective: typeof query5.effective === "boolean" ? query5.effective ? "true" : "false" : void 0,
15883
- status: query5.status
15884
- })}`
15885
- }).then(
15886
- (response) => mapGatewayData(
15887
- response,
15888
- (data) => createListResult(
15889
- Array.isArray(data) ? data : [],
15890
- "registryEntries"
15891
- )
15892
- )
15893
- );
15894
- },
16193
+ listRegistry,
15895
16194
  /**
15896
16195
  * @deprecated Use listRegistry.
15897
16196
  */
15898
- async getRegistry(query5 = {}) {
15899
- return this.listRegistry(query5);
15900
- },
16197
+ getRegistry,
15901
16198
  /**
15902
16199
  * Create an audience registry entry.
15903
16200
  */
15904
- async createRegistryEntry(input, idempotencyKey) {
15905
- return gateway.request({
15906
- path: "/api/platform/v1/audiences/registry",
15907
- method: "POST",
15908
- body: input,
15909
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
15910
- });
15911
- },
16201
+ createRegistryEntry,
15912
16202
  /**
15913
16203
  * Update an audience registry entry.
15914
16204
  */
15915
- async updateRegistryEntry(input, idempotencyKey) {
15916
- return this.createRegistryEntry(input, idempotencyKey);
15917
- },
16205
+ updateRegistryEntry,
15918
16206
  /**
15919
16207
  * @deprecated Use createRegistryEntry or updateRegistryEntry.
15920
16208
  */
15921
- async upsertRegistry(input, idempotencyKey) {
15922
- return this.createRegistryEntry(input, idempotencyKey);
15923
- },
16209
+ upsertRegistry,
15924
16210
  /**
15925
16211
  * List audience grants.
15926
16212
  */
15927
- async listGrants(query5 = {}) {
15928
- return gateway.request({
15929
- path: `/api/platform/v1/audiences/grants${toQueryString({
15930
- ...query5,
15931
- audienceKey: query5.audienceKey,
15932
- principalId: query5.principalId,
15933
- groupId: query5.groupId,
15934
- status: query5.status
15935
- })}`
15936
- }).then(
15937
- (response) => mapGatewayData(
15938
- response,
15939
- (data) => createListResult(Array.isArray(data) ? data : [], "grants")
15940
- )
15941
- );
15942
- },
16213
+ listGrants,
15943
16214
  /**
15944
16215
  * @deprecated Use listGrants.
15945
16216
  */
15946
- async getGrants(query5 = {}) {
15947
- return this.listGrants(query5);
15948
- },
16217
+ getGrants,
15949
16218
  /**
15950
16219
  * Create an audience grant.
15951
16220
  */
15952
- async createGrant(input, idempotencyKey) {
15953
- return gateway.request({
15954
- path: "/api/platform/v1/audiences/grants",
15955
- method: "POST",
15956
- body: input,
15957
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
15958
- });
15959
- },
16221
+ createGrant,
15960
16222
  /**
15961
16223
  * @deprecated Use createGrant.
15962
16224
  */
15963
- async grant(input, idempotencyKey) {
15964
- return this.createGrant(input, idempotencyKey);
15965
- },
16225
+ grant,
15966
16226
  /**
15967
16227
  * Delete an audience grant by revoking it.
15968
16228
  */
15969
- async deleteGrant(input, idempotencyKey) {
15970
- return gateway.request({
15971
- path: "/api/platform/v1/audiences/grants/revoke",
15972
- method: "POST",
15973
- body: input,
15974
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
15975
- });
15976
- },
16229
+ deleteGrant,
15977
16230
  /**
15978
16231
  * @deprecated Use deleteGrant.
15979
16232
  */
15980
- async revokeGrant(input, idempotencyKey) {
15981
- return this.deleteGrant(input, idempotencyKey);
15982
- }
16233
+ revokeGrant
15983
16234
  };
15984
16235
  }
15985
16236
 
@@ -16020,8 +16271,18 @@ function authBaseUrl(config) {
16020
16271
  return config.baseUrl?.replace(/\/+$/, "") ?? "";
16021
16272
  }
16022
16273
  async function readJson2(response) {
16023
- const payload = await response.json().catch(() => ({}));
16024
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
16274
+ try {
16275
+ const payload = await response.json();
16276
+ return isRecord8(payload) ? payload : {};
16277
+ } catch (error) {
16278
+ return unreadableJsonBodyFallback();
16279
+ }
16280
+ }
16281
+ function unreadableJsonBodyFallback(_error) {
16282
+ return {};
16283
+ }
16284
+ function isRecord8(value) {
16285
+ return value !== null && typeof value === "object" && !Array.isArray(value);
16025
16286
  }
16026
16287
  function readString(value) {
16027
16288
  const normalized = typeof value === "string" ? value.trim() : "";
@@ -16063,7 +16324,10 @@ function assertDeviceTokenResponse(payload) {
16063
16324
  tenant_id: tenantId,
16064
16325
  workspace_id: readString(payload.workspace_id),
16065
16326
  principal_id: principalId,
16066
- user: payload.user && typeof payload.user === "object" && !Array.isArray(payload.user) ? payload.user : void 0
16327
+ user: isRecord8(payload.user) && typeof payload.user.id === "string" && typeof payload.user.principalId === "string" ? {
16328
+ id: payload.user.id,
16329
+ principalId: payload.user.principalId
16330
+ } : void 0
16067
16331
  };
16068
16332
  }
16069
16333
  function maybeThrowDeviceError(payload) {
@@ -16211,12 +16475,12 @@ function createBeliefsClient(config = {}) {
16211
16475
  body: normalizeModulateConfidenceInput(input),
16212
16476
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
16213
16477
  });
16214
- async function getOpinionHistory(beliefId) {
16478
+ const getOpinionHistory = async (beliefId) => {
16215
16479
  const response = await gateway.request({
16216
16480
  path: `/api/platform/v1/beliefs/${encodeURIComponent(beliefId)}/confidence-history`
16217
16481
  });
16218
16482
  return mapOpinionHistoryEntriesFromGatewayData(response.data);
16219
- }
16483
+ };
16220
16484
  return {
16221
16485
  /**
16222
16486
  * Create a belief within a topic scope.
@@ -16261,13 +16525,9 @@ function createBeliefsClient(config = {}) {
16261
16525
  * trigger = cause of the score change
16262
16526
  * triggeringRef = optional pointer to the evidence or worktree that drove the change
16263
16527
  */
16264
- async getOpinionHistory(beliefId) {
16265
- return getOpinionHistory(beliefId);
16266
- },
16528
+ getOpinionHistory,
16267
16529
  /** @deprecated Use getOpinionHistory(). */
16268
- async getConfidenceHistory(beliefId) {
16269
- return getOpinionHistory(beliefId);
16270
- },
16530
+ getConfidenceHistory: getOpinionHistory,
16271
16531
  /**
16272
16532
  * Fork a scored belief into a new formulation.
16273
16533
  */
@@ -16415,6 +16675,9 @@ function cleanOptionalString(value) {
16415
16675
  const normalized = value?.trim();
16416
16676
  return normalized ? normalized : void 0;
16417
16677
  }
16678
+ function isRecord9(value) {
16679
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
16680
+ }
16418
16681
  function cleanRequiredString(value, label) {
16419
16682
  const normalized = cleanOptionalString(value);
16420
16683
  if (!normalized) {
@@ -16454,9 +16717,10 @@ function topicPayload(input, allowed, operation) {
16454
16717
  };
16455
16718
  }
16456
16719
  function listResultFromEnvelope(data, legacyKey) {
16457
- const record = data && typeof data === "object" ? data : {};
16720
+ const record = isRecord9(data) ? data : {};
16721
+ const legacyItems = record[legacyKey];
16458
16722
  return createListResult(
16459
- Array.isArray(record[legacyKey]) ? record[legacyKey] : Array.isArray(data) ? data : [],
16723
+ Array.isArray(legacyItems) ? legacyItems : Array.isArray(data) ? data : [],
16460
16724
  legacyKey
16461
16725
  );
16462
16726
  }
@@ -16828,7 +17092,7 @@ async function invokeRegisteredCustomTool(fullName, params, context) {
16828
17092
  // ../sdk/src/ontologyClient.ts
16829
17093
  function createOntologyClient(config = {}) {
16830
17094
  const gateway = createGatewayRequestClient(config);
16831
- return {
17095
+ const client = {
16832
17096
  /**
16833
17097
  * List ontology definitions matching optional filters.
16834
17098
  */
@@ -16837,13 +17101,14 @@ function createOntologyClient(config = {}) {
16837
17101
  path: `/api/platform/v1/ontologies${toQueryString(filters)}`
16838
17102
  }).then(
16839
17103
  (response) => mapGatewayData(response, (data) => {
16840
- const record = data && typeof data === "object" && !Array.isArray(data) ? data : {};
16841
- const ontologies = Array.isArray(record.ontologies) ? record.ontologies : Array.isArray(record.definitions) ? record.definitions : Array.isArray(data) ? data : [];
16842
- const total = typeof record.total === "number" && Number.isFinite(record.total) ? record.total : ontologies.length;
17104
+ const record = asRecord(data);
17105
+ const ontologies = asListItems(data, "ontologies");
17106
+ const definitions = ontologies.length > 0 ? ontologies : asListItems(data, "definitions");
17107
+ const total = typeof record.total === "number" && Number.isFinite(record.total) ? record.total : definitions.length;
16843
17108
  return {
16844
17109
  ...record,
16845
- ...createListResult(ontologies, "definitions"),
16846
- ontologies,
17110
+ ...createListResult(definitions, "definitions"),
17111
+ ontologies: definitions,
16847
17112
  total
16848
17113
  };
16849
17114
  })
@@ -16870,18 +17135,6 @@ function createOntologyClient(config = {}) {
16870
17135
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
16871
17136
  });
16872
17137
  },
16873
- /**
16874
- * List ontology definitions.
16875
- */
16876
- async listDefinitions(filters = {}) {
16877
- return this.list(filters);
16878
- },
16879
- /**
16880
- * Get an ontology definition.
16881
- */
16882
- async getDefinition(id) {
16883
- return this.get(id);
16884
- },
16885
17138
  /**
16886
17139
  * Create an ontology definition.
16887
17140
  */
@@ -16923,7 +17176,7 @@ function createOntologyClient(config = {}) {
16923
17176
  }).then(
16924
17177
  (response) => mapGatewayData(
16925
17178
  response,
16926
- (data) => createListResult(Array.isArray(data) ? data : [], "versions")
17179
+ (data) => createListResult(asListItems(data, "versions"), "versions")
16927
17180
  )
16928
17181
  );
16929
17182
  },
@@ -16971,20 +17224,19 @@ function createOntologyClient(config = {}) {
16971
17224
  (data) => createListResult(Array.isArray(data) ? data : [], "topics")
16972
17225
  )
16973
17226
  );
16974
- },
16975
- /**
16976
- * @deprecated Use listTopics.
16977
- */
16978
- async listTopicsByOntology(ontologyId) {
16979
- return this.listTopics(ontologyId);
16980
17227
  }
16981
17228
  };
17229
+ return Object.assign(client, {
17230
+ listDefinitions: client.list,
17231
+ getDefinition: client.get,
17232
+ listTopicsByOntology: client.listTopics
17233
+ });
16982
17234
  }
16983
17235
 
16984
17236
  // ../sdk/src/graphClient.ts
16985
17237
  function createGraphClient(config = {}) {
16986
17238
  const gateway = createGatewayRequestClient(config);
16987
- return {
17239
+ const client = {
16988
17240
  /**
16989
17241
  * List graph nodes matching the provided filters.
16990
17242
  */
@@ -16997,12 +17249,6 @@ function createGraphClient(config = {}) {
16997
17249
  (response) => mapGatewayData(response, (data) => mapAliasedList(data, "nodes"))
16998
17250
  );
16999
17251
  },
17000
- /**
17001
- * @deprecated Use listNodes.
17002
- */
17003
- async queryNodes(query5) {
17004
- return this.listNodes(query5);
17005
- },
17006
17252
  /**
17007
17253
  * Retrieve a single graph node by nodeId or globalId.
17008
17254
  */
@@ -17113,12 +17359,6 @@ function createGraphClient(config = {}) {
17113
17359
  )
17114
17360
  );
17115
17361
  },
17116
- /**
17117
- * @deprecated Use listEdges.
17118
- */
17119
- async queryEdges(query5) {
17120
- return this.listEdges(query5);
17121
- },
17122
17362
  /**
17123
17363
  * Create a graph edge.
17124
17364
  */
@@ -17206,12 +17446,6 @@ function createGraphClient(config = {}) {
17206
17446
  body: normalizeTopicQuery(query5)
17207
17447
  });
17208
17448
  },
17209
- /**
17210
- * Retrieve a graph neighborhood around a root node.
17211
- */
17212
- async getNeighborhood(query5) {
17213
- return this.neighborhood(query5);
17214
- },
17215
17449
  /**
17216
17450
  * Retrieve the shortest known path between two graph nodes.
17217
17451
  */
@@ -17229,6 +17463,11 @@ function createGraphClient(config = {}) {
17229
17463
  });
17230
17464
  }
17231
17465
  };
17466
+ return Object.assign(client, {
17467
+ queryNodes: client.listNodes,
17468
+ queryEdges: client.listEdges,
17469
+ getNeighborhood: client.neighborhood
17470
+ });
17232
17471
  }
17233
17472
 
17234
17473
  // ../sdk/src/identityClient.ts
@@ -17282,6 +17521,13 @@ function createIdentityClient(config = {}) {
17282
17521
  body: input,
17283
17522
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
17284
17523
  });
17524
+ const updatePrincipal = (input, idempotencyKey) => requestPrincipalWrite("PATCH", input, idempotencyKey);
17525
+ const deleteKey = (keyId, input = {}, idempotencyKey) => gateway.request({
17526
+ path: `/api/platform/v1/identity/keys/${encodeURIComponent(keyId)}/revoke`,
17527
+ method: "POST",
17528
+ body: input,
17529
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
17530
+ });
17285
17531
  return {
17286
17532
  /**
17287
17533
  * Resolve the current authenticated identity summary.
@@ -17330,15 +17576,11 @@ function createIdentityClient(config = {}) {
17330
17576
  /**
17331
17577
  * Update a principal.
17332
17578
  */
17333
- async updatePrincipal(input, idempotencyKey) {
17334
- return requestPrincipalWrite("PATCH", input, idempotencyKey);
17335
- },
17579
+ updatePrincipal,
17336
17580
  /**
17337
17581
  * @deprecated Use createPrincipal or updatePrincipal.
17338
17582
  */
17339
- async upsertPrincipal(input, idempotencyKey) {
17340
- return requestPrincipalWrite("PATCH", input, idempotencyKey);
17341
- },
17583
+ upsertPrincipal: updatePrincipal,
17342
17584
  /**
17343
17585
  * List keys in the current identity scope.
17344
17586
  */
@@ -17377,20 +17619,11 @@ function createIdentityClient(config = {}) {
17377
17619
  /**
17378
17620
  * Delete an API key by revoking it.
17379
17621
  */
17380
- async deleteKey(keyId, input = {}, idempotencyKey) {
17381
- return gateway.request({
17382
- path: `/api/platform/v1/identity/keys/${encodeURIComponent(keyId)}/revoke`,
17383
- method: "POST",
17384
- body: input,
17385
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
17386
- });
17387
- },
17622
+ deleteKey,
17388
17623
  /**
17389
17624
  * @deprecated Use deleteKey.
17390
17625
  */
17391
- async revokeKey(keyId, input = {}, idempotencyKey) {
17392
- return this.deleteKey(keyId, input, idempotencyKey);
17393
- },
17626
+ revokeKey: deleteKey,
17394
17627
  /**
17395
17628
  * Search Clerk users by email or display attributes.
17396
17629
  */
@@ -17506,14 +17739,11 @@ function createIdentityClient(config = {}) {
17506
17739
  }
17507
17740
 
17508
17741
  // ../sdk/src/topicsClient.ts
17509
- function asRecord3(value) {
17510
- return value && typeof value === "object" ? value : {};
17511
- }
17512
17742
  function cleanString3(value) {
17513
17743
  return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
17514
17744
  }
17515
17745
  function normalizeTopicRecord(value) {
17516
- const record = asRecord3(value);
17746
+ const record = asRecord(value);
17517
17747
  const topicId = cleanString3(record.topicId) ?? cleanString3(record.id) ?? cleanString3(record._id);
17518
17748
  return withTopicAlias({
17519
17749
  ...record,
@@ -17538,7 +17768,7 @@ function createTopicsClient(config = {}) {
17538
17768
  })}`
17539
17769
  }).then(
17540
17770
  (response) => mapGatewayData(response, (data) => {
17541
- const record = asRecord3(data);
17771
+ const record = asRecord(data);
17542
17772
  const items = Array.isArray(record.topics) ? record.topics.map(normalizeTopicRecord) : [];
17543
17773
  return {
17544
17774
  ...createListResult(items, "topics"),
@@ -17555,7 +17785,7 @@ function createTopicsClient(config = {}) {
17555
17785
  }).then(
17556
17786
  (response) => mapGatewayData(
17557
17787
  response,
17558
- (data) => normalizeTopicRecord(asRecord3(data).topic ?? data)
17788
+ (data) => normalizeTopicRecord(asRecord(data).topic ?? data)
17559
17789
  )
17560
17790
  );
17561
17791
  },
@@ -17591,7 +17821,7 @@ function createTopicsClient(config = {}) {
17591
17821
  )}`
17592
17822
  }).then(
17593
17823
  (response) => mapGatewayData(response, (data) => {
17594
- const record = asRecord3(data);
17824
+ const record = asRecord(data);
17595
17825
  return {
17596
17826
  tree: Array.isArray(record.tree) ? record.tree.map(normalizeTopicTreeNode) : []
17597
17827
  };
@@ -18010,7 +18240,7 @@ function createEventsFacade(config = {}) {
18010
18240
  function createGraphFacade(config = {}) {
18011
18241
  const graphClient = createGraphClient(config);
18012
18242
  const gateway = createGatewayRequestClient(config);
18013
- return {
18243
+ const graphFacade = {
18014
18244
  async neighborhood(input) {
18015
18245
  return graphClient.neighborhood({
18016
18246
  globalId: input.globalId,
@@ -18018,18 +18248,6 @@ function createGraphFacade(config = {}) {
18018
18248
  maxDepth: input.maxDepth
18019
18249
  });
18020
18250
  },
18021
- async traverse(input) {
18022
- return graphClient.traverse(input);
18023
- },
18024
- async analyze(input = {}) {
18025
- return graphClient.analyze(input);
18026
- },
18027
- async bias(input = {}) {
18028
- return graphClient.bias(input);
18029
- },
18030
- async gaps(input) {
18031
- return graphClient.gaps(input);
18032
- },
18033
18251
  async falsify(input, idempotencyKey = randomIdempotencyKey()) {
18034
18252
  return gateway.request({
18035
18253
  path: "/api/platform/v1/graph/falsify",
@@ -18039,6 +18257,12 @@ function createGraphFacade(config = {}) {
18039
18257
  });
18040
18258
  }
18041
18259
  };
18260
+ return Object.assign(graphFacade, {
18261
+ traverse: graphClient.traverse,
18262
+ analyze: graphClient.analyze,
18263
+ bias: graphClient.bias,
18264
+ gaps: graphClient.gaps
18265
+ });
18042
18266
  }
18043
18267
  function createIdentityFacade(config = {}) {
18044
18268
  const identityClient = createIdentityClient(config);
@@ -18052,15 +18276,12 @@ function createIdentityFacade(config = {}) {
18052
18276
  function createOntologiesFacade(config = {}) {
18053
18277
  const ontologyClient = createOntologyClient(config);
18054
18278
  const gateway = createGatewayRequestClient(config);
18055
- return {
18279
+ const ontologyFacade = {
18056
18280
  async get(id) {
18057
18281
  return gateway.request({
18058
18282
  path: `/api/platform/v1/ontologies/${encodeURIComponent(id)}`
18059
18283
  });
18060
18284
  },
18061
- async list(query5 = {}) {
18062
- return ontologyClient.list(query5);
18063
- },
18064
18285
  async bind(input, idempotencyKey) {
18065
18286
  return gateway.request({
18066
18287
  path: `/api/platform/v1/ontologies/${encodeURIComponent(input.ontologyId)}/bind`,
@@ -18080,6 +18301,9 @@ function createOntologiesFacade(config = {}) {
18080
18301
  });
18081
18302
  }
18082
18303
  };
18304
+ return Object.assign(ontologyFacade, {
18305
+ list: ontologyClient.list
18306
+ });
18083
18307
  }
18084
18308
  function createQuestionsFacade(config = {}) {
18085
18309
  const gateway = createGatewayRequestClient(config);
@@ -18272,15 +18496,9 @@ function createTasksFacade(config = {}) {
18272
18496
  function createTopicsFacade(config = {}) {
18273
18497
  const topicsClient = createTopicsClient(config);
18274
18498
  return {
18275
- async create(input, idempotencyKey) {
18276
- return topicsClient.create(input, idempotencyKey);
18277
- },
18278
- async get(id) {
18279
- return topicsClient.get(id);
18280
- },
18281
- async list(query5 = {}) {
18282
- return topicsClient.list(query5);
18283
- },
18499
+ create: topicsClient.create,
18500
+ get: topicsClient.get,
18501
+ list: topicsClient.list,
18284
18502
  async update(input, idempotencyKey) {
18285
18503
  const { id, ...rest } = input;
18286
18504
  return topicsClient.update(id, rest, idempotencyKey);
@@ -18296,12 +18514,8 @@ function createTopicsFacade(config = {}) {
18296
18514
  maxDepth: input.maxDepth
18297
18515
  });
18298
18516
  },
18299
- async remove(id, idempotencyKey = randomIdempotencyKey()) {
18300
- return topicsClient.remove(id, idempotencyKey);
18301
- },
18302
- async bulkCreate(input, idempotencyKey = randomIdempotencyKey()) {
18303
- return topicsClient.bulkCreate(input, idempotencyKey);
18304
- }
18517
+ remove: topicsClient.remove,
18518
+ bulkCreate: topicsClient.bulkCreate
18305
18519
  };
18306
18520
  }
18307
18521
  function createWebhooksFacade(config = {}) {
@@ -18501,7 +18715,7 @@ function createWorktreesFacade(config = {}) {
18501
18715
  // ../sdk/src/decisionsClient.ts
18502
18716
  function createDecisionsClient(config = {}) {
18503
18717
  const gateway = createGatewayRequestClient(config);
18504
- return {
18718
+ const client = {
18505
18719
  /**
18506
18720
  * List judgments for a topic scope.
18507
18721
  */
@@ -18579,12 +18793,6 @@ function createDecisionsClient(config = {}) {
18579
18793
  })
18580
18794
  );
18581
18795
  },
18582
- /**
18583
- * @deprecated Use listPendingOutcomeReviews.
18584
- */
18585
- async listPendingJudgmentOutcomeReview(query5) {
18586
- return this.listPendingOutcomeReviews(query5);
18587
- },
18588
18796
  /**
18589
18797
  * Get audit integrity checks for judgment transitions.
18590
18798
  */
@@ -18617,12 +18825,6 @@ function createDecisionsClient(config = {}) {
18617
18825
  )
18618
18826
  );
18619
18827
  },
18620
- /**
18621
- * @deprecated Use createJudgment.
18622
- */
18623
- async recordJudgment(input, idempotencyKey) {
18624
- return this.createJudgment(input, idempotencyKey);
18625
- },
18626
18828
  /**
18627
18829
  * Update the outcome for an existing judgment.
18628
18830
  */
@@ -18633,14 +18835,13 @@ function createDecisionsClient(config = {}) {
18633
18835
  body: input,
18634
18836
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
18635
18837
  });
18636
- },
18637
- /**
18638
- * @deprecated Use updateJudgmentOutcome.
18639
- */
18640
- async recordJudgmentOutcome(judgmentId, input, idempotencyKey) {
18641
- return this.updateJudgmentOutcome(judgmentId, input, idempotencyKey);
18642
18838
  }
18643
18839
  };
18840
+ return Object.assign(client, {
18841
+ listPendingJudgmentOutcomeReview: client.listPendingOutcomeReviews,
18842
+ recordJudgment: client.createJudgment,
18843
+ recordJudgmentOutcome: client.updateJudgmentOutcome
18844
+ });
18644
18845
  }
18645
18846
 
18646
18847
  // ../sdk/src/embeddingsClient.ts
@@ -18765,50 +18966,55 @@ function cleanNumber(value) {
18765
18966
  function cleanBoolean(value) {
18766
18967
  return typeof value === "boolean" ? value : void 0;
18767
18968
  }
18768
- function buildCompileContextRequest(topicId, input = {}) {
18769
- const payload = { topicId };
18770
- const query5 = cleanString4(input.query);
18969
+ function buildCompileContextRequest(topicIdOrInput = {}, input = {}) {
18970
+ const effectiveInput = typeof topicIdOrInput === "string" ? input : topicIdOrInput;
18971
+ const payload = {};
18972
+ const topicId = typeof topicIdOrInput === "string" ? cleanString4(topicIdOrInput) : cleanString4(effectiveInput.topicId);
18973
+ if (topicId) {
18974
+ payload.topicId = topicId;
18975
+ }
18976
+ const query5 = cleanString4(effectiveInput.query);
18771
18977
  if (query5) {
18772
18978
  payload.query = query5;
18773
18979
  }
18774
- const budget = cleanNumber(input.budget) ?? cleanNumber(input.tokenBudget);
18980
+ const budget = cleanNumber(effectiveInput.budget) ?? cleanNumber(effectiveInput.tokenBudget);
18775
18981
  if (budget !== void 0) {
18776
18982
  payload.budget = budget;
18777
18983
  }
18778
- const ranking = cleanString4(input.ranking) ?? cleanString4(input.rankingProfile);
18984
+ const ranking = cleanString4(effectiveInput.ranking) ?? cleanString4(effectiveInput.rankingProfile);
18779
18985
  if (ranking) {
18780
18986
  payload.ranking = ranking;
18781
18987
  }
18782
- const limit = cleanNumber(input.limit);
18988
+ const limit = cleanNumber(effectiveInput.limit);
18783
18989
  if (limit !== void 0) {
18784
18990
  payload.limit = limit;
18785
18991
  }
18786
- const maxDepth = cleanNumber(input.maxDepth);
18992
+ const maxDepth = cleanNumber(effectiveInput.maxDepth);
18787
18993
  if (maxDepth !== void 0) {
18788
18994
  payload.maxDepth = maxDepth;
18789
18995
  }
18790
- const includeEntities = cleanBoolean(input.includeEntities);
18996
+ const includeEntities = cleanBoolean(effectiveInput.includeEntities);
18791
18997
  if (includeEntities !== void 0) {
18792
18998
  payload.includeEntities = includeEntities;
18793
18999
  }
18794
- const mode = cleanString4(input.mode);
19000
+ const mode = cleanString4(effectiveInput.mode);
18795
19001
  if (mode) {
18796
19002
  payload.mode = mode;
18797
19003
  }
18798
- const includeFailures = cleanBoolean(input.includeFailures);
19004
+ const includeFailures = cleanBoolean(effectiveInput.includeFailures);
18799
19005
  if (includeFailures !== void 0) {
18800
19006
  payload.includeFailures = includeFailures;
18801
19007
  }
18802
- const worktreeId = cleanString4(input.worktreeId);
19008
+ const worktreeId = cleanString4(effectiveInput.worktreeId);
18803
19009
  if (worktreeId) {
18804
19010
  payload.worktreeId = worktreeId;
18805
19011
  }
18806
- const sessionId = cleanString4(input.sessionId);
19012
+ const sessionId = cleanString4(effectiveInput.sessionId);
18807
19013
  if (sessionId) {
18808
19014
  payload.sessionId = sessionId;
18809
19015
  }
18810
- if (Array.isArray(input.packWeightOverrides) && input.packWeightOverrides.length > 0) {
18811
- payload.packWeightOverrides = input.packWeightOverrides;
19016
+ if (Array.isArray(effectiveInput.packWeightOverrides) && effectiveInput.packWeightOverrides.length > 0) {
19017
+ payload.packWeightOverrides = effectiveInput.packWeightOverrides;
18812
19018
  }
18813
19019
  return {
18814
19020
  path: "/api/platform/v1/context/compile",
@@ -18820,13 +19026,20 @@ function createContextClient(config = {}) {
18820
19026
  const gateway = createGatewayRequestClient(config);
18821
19027
  return {
18822
19028
  /**
18823
- * Compile a focused reasoning context pack for a topic scope.
18824
- * @param topicId - The topic to compile context for.
19029
+ * Compile a focused reasoning context pack.
19030
+ * @param topicIdOrInput - Optional topic ID, or compile input for query-first resolution.
18825
19031
  * @param input - Optional compile parameters (query, budget, ranking, etc.).
18826
19032
  * @returns The compiled context payload with beliefs, questions, and evidence.
18827
19033
  */
18828
- async compile(topicId, input = {}) {
18829
- const request = buildCompileContextRequest(topicId, input);
19034
+ async compile(topicIdOrInput = {}, input = {}) {
19035
+ const request = buildCompileContextRequest(topicIdOrInput, input);
19036
+ return gateway.request({
19037
+ ...request,
19038
+ body: request.body
19039
+ });
19040
+ },
19041
+ async compileByQuery(input = {}) {
19042
+ const request = buildCompileContextRequest(input);
18830
19043
  return gateway.request({
18831
19044
  ...request,
18832
19045
  body: request.body
@@ -19264,7 +19477,7 @@ function createGraphStateClassifierClient(config = {}) {
19264
19477
  // ../sdk/src/harnessClient.ts
19265
19478
  function createHarnessClient(config = {}) {
19266
19479
  const gateway = createGatewayRequestClient(config);
19267
- return {
19480
+ const client = {
19268
19481
  /**
19269
19482
  * List agent definitions.
19270
19483
  */
@@ -19297,12 +19510,6 @@ function createHarnessClient(config = {}) {
19297
19510
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
19298
19511
  });
19299
19512
  },
19300
- /**
19301
- * @deprecated Use createAgentDefinition.
19302
- */
19303
- async registerAgentDefinition(input, idempotencyKey) {
19304
- return this.createAgentDefinition(input, idempotencyKey);
19305
- },
19306
19513
  /**
19307
19514
  * Update an agent definition.
19308
19515
  */
@@ -19341,12 +19548,6 @@ function createHarnessClient(config = {}) {
19341
19548
  )
19342
19549
  );
19343
19550
  },
19344
- /**
19345
- * @deprecated Use listAgentRuns.
19346
- */
19347
- async listRunsForAgent(agentId, scope = {}) {
19348
- return this.listAgentRuns(agentId, scope);
19349
- },
19350
19551
  /**
19351
19552
  * List tool definitions.
19352
19553
  */
@@ -19379,12 +19580,6 @@ function createHarnessClient(config = {}) {
19379
19580
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
19380
19581
  });
19381
19582
  },
19382
- /**
19383
- * @deprecated Use createToolDefinition.
19384
- */
19385
- async registerToolDefinition(input, idempotencyKey) {
19386
- return this.createToolDefinition(input, idempotencyKey);
19387
- },
19388
19583
  /**
19389
19584
  * Update a tool definition.
19390
19585
  */
@@ -19419,12 +19614,6 @@ function createHarnessClient(config = {}) {
19419
19614
  )
19420
19615
  );
19421
19616
  },
19422
- /**
19423
- * @deprecated Use listRunEntries.
19424
- */
19425
- async listRunLedgerEntries(scope = {}) {
19426
- return this.listRunEntries(scope);
19427
- },
19428
19617
  /**
19429
19618
  * Create a harness run.
19430
19619
  */
@@ -19499,6 +19688,12 @@ function createHarnessClient(config = {}) {
19499
19688
  });
19500
19689
  }
19501
19690
  };
19691
+ return Object.assign(client, {
19692
+ registerAgentDefinition: client.createAgentDefinition,
19693
+ listRunsForAgent: client.listAgentRuns,
19694
+ registerToolDefinition: client.createToolDefinition,
19695
+ listRunLedgerEntries: client.listRunEntries
19696
+ });
19502
19697
  }
19503
19698
 
19504
19699
  // ../sdk/src/jobsClient.ts
@@ -19626,45 +19821,41 @@ function createJobsClient(config = {}) {
19626
19821
  // ../sdk/src/learningClient.ts
19627
19822
  function createLearningClient(config = {}) {
19628
19823
  const gateway = createGatewayRequestClient(config);
19824
+ const listRecentExecutions = async (args = {}) => gateway.request({
19825
+ path: `/api/platform/v1/learning/executions/recent${toQueryString({
19826
+ ...normalizeTopicQuery(args),
19827
+ namespace: args.namespace,
19828
+ audienceMode: args.audienceMode,
19829
+ success: typeof args.success === "boolean" ? args.success ? "true" : "false" : void 0,
19830
+ limit: typeof args.limit === "number" && Number.isFinite(args.limit) ? String(args.limit) : void 0
19831
+ })}`
19832
+ }).then(
19833
+ (response) => mapGatewayData(
19834
+ response,
19835
+ (data) => createListResult(Array.isArray(data) ? data : [], "executions")
19836
+ )
19837
+ );
19838
+ const getExecutionStats = async (args = {}) => gateway.request({
19839
+ path: `/api/platform/v1/learning/executions/stats${toQueryString({
19840
+ ...normalizeTopicQuery(args),
19841
+ namespace: args.namespace,
19842
+ audienceMode: args.audienceMode,
19843
+ hours: typeof args.hours === "number" && Number.isFinite(args.hours) ? String(args.hours) : void 0
19844
+ })}`
19845
+ });
19629
19846
  return {
19630
19847
  /**
19631
19848
  * List recent execution records.
19632
19849
  */
19633
- async listRecentExecutions(args = {}) {
19634
- return gateway.request({
19635
- path: `/api/platform/v1/learning/executions/recent${toQueryString({
19636
- ...normalizeTopicQuery(args),
19637
- namespace: args.namespace,
19638
- audienceMode: args.audienceMode,
19639
- success: typeof args.success === "boolean" ? args.success ? "true" : "false" : void 0,
19640
- limit: typeof args.limit === "number" && Number.isFinite(args.limit) ? String(args.limit) : void 0
19641
- })}`
19642
- }).then(
19643
- (response) => mapGatewayData(
19644
- response,
19645
- (data) => createListResult(Array.isArray(data) ? data : [], "executions")
19646
- )
19647
- );
19648
- },
19850
+ listRecentExecutions,
19649
19851
  /**
19650
19852
  * @deprecated Use listRecentExecutions.
19651
19853
  */
19652
- async getRecentExecutions(args = {}) {
19653
- return this.listRecentExecutions(args);
19654
- },
19854
+ getRecentExecutions: listRecentExecutions,
19655
19855
  /**
19656
19856
  * Get aggregate execution statistics.
19657
19857
  */
19658
- async getExecutionStats(args = {}) {
19659
- return gateway.request({
19660
- path: `/api/platform/v1/learning/executions/stats${toQueryString({
19661
- ...normalizeTopicQuery(args),
19662
- namespace: args.namespace,
19663
- audienceMode: args.audienceMode,
19664
- hours: typeof args.hours === "number" && Number.isFinite(args.hours) ? String(args.hours) : void 0
19665
- })}`
19666
- });
19667
- }
19858
+ getExecutionStats
19668
19859
  };
19669
19860
  }
19670
19861
 
@@ -20701,7 +20892,7 @@ function createOrgGraphSearchClient(config = {}) {
20701
20892
  // ../sdk/src/packsClient.ts
20702
20893
  function createPacksClient(config = {}) {
20703
20894
  const gateway = createGatewayRequestClient(config);
20704
- return {
20895
+ const client = {
20705
20896
  /**
20706
20897
  * List catalog entries for available packs.
20707
20898
  */
@@ -20715,12 +20906,6 @@ function createPacksClient(config = {}) {
20715
20906
  )
20716
20907
  );
20717
20908
  },
20718
- /**
20719
- * @deprecated Use listCatalog.
20720
- */
20721
- async getCatalog() {
20722
- return this.listCatalog();
20723
- },
20724
20909
  /**
20725
20910
  * Get the discovery catalog for packs.
20726
20911
  */
@@ -20750,12 +20935,6 @@ function createPacksClient(config = {}) {
20750
20935
  )
20751
20936
  );
20752
20937
  },
20753
- /**
20754
- * @deprecated Use listStates.
20755
- */
20756
- async getStates(query5 = {}) {
20757
- return this.listStates(query5);
20758
- },
20759
20938
  /**
20760
20939
  * Get health details for a pack.
20761
20940
  */
@@ -20779,12 +20958,6 @@ function createPacksClient(config = {}) {
20779
20958
  )
20780
20959
  );
20781
20960
  },
20782
- /**
20783
- * @deprecated Use listTelemetry.
20784
- */
20785
- async getTelemetry(query5 = {}) {
20786
- return this.listTelemetry(query5);
20787
- },
20788
20961
  /**
20789
20962
  * Create a pack entitlement.
20790
20963
  */
@@ -20796,18 +20969,6 @@ function createPacksClient(config = {}) {
20796
20969
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
20797
20970
  });
20798
20971
  },
20799
- /**
20800
- * Update a pack entitlement.
20801
- */
20802
- async updateEntitlement(input, idempotencyKey) {
20803
- return this.createEntitlement(input, idempotencyKey);
20804
- },
20805
- /**
20806
- * @deprecated Use createEntitlement or updateEntitlement.
20807
- */
20808
- async upsertEntitlement(input, idempotencyKey) {
20809
- return this.createEntitlement(input, idempotencyKey);
20810
- },
20811
20972
  /**
20812
20973
  * Install a pack.
20813
20974
  */
@@ -20864,6 +21025,13 @@ function createPacksClient(config = {}) {
20864
21025
  });
20865
21026
  }
20866
21027
  };
21028
+ return Object.assign(client, {
21029
+ getCatalog: client.listCatalog,
21030
+ getStates: client.listStates,
21031
+ getTelemetry: client.listTelemetry,
21032
+ updateEntitlement: client.createEntitlement,
21033
+ upsertEntitlement: client.createEntitlement
21034
+ });
20867
21035
  }
20868
21036
 
20869
21037
  // ../sdk/src/policyClient.ts
@@ -20899,6 +21067,14 @@ function asRolePolicyArray(data) {
20899
21067
  }
20900
21068
  return data.map(asRolePolicyRecord).filter((row) => Boolean(row));
20901
21069
  }
21070
+ function buildFilterByPermissionResponse(permission, allowedTopicIds, deniedTopics, count) {
21071
+ const result = {};
21072
+ result.permission = permission;
21073
+ result.allowedTopicIds = allowedTopicIds;
21074
+ result.deniedTopics = deniedTopics;
21075
+ result.count = count;
21076
+ return result;
21077
+ }
20902
21078
  function createPolicyClient(config = {}) {
20903
21079
  const gateway = createGatewayRequestClient(config);
20904
21080
  return {
@@ -21121,15 +21297,15 @@ function createPolicyClient(config = {}) {
21121
21297
  });
21122
21298
  const allowedTopicIds = Array.isArray(response.data?.allowedTopicIds) ? response.data.allowedTopicIds : [];
21123
21299
  const deniedTopics = Array.isArray(response.data?.deniedTopics) ? response.data.deniedTopics : [];
21124
- return {
21125
- success: true,
21126
- data: {
21127
- permission,
21128
- allowedTopicIds,
21129
- deniedTopics,
21130
- count: typeof response.data?.count === "number" ? response.data.count : allowedTopicIds.length
21131
- }
21132
- };
21300
+ const result = {};
21301
+ result.success = true;
21302
+ result.data = buildFilterByPermissionResponse(
21303
+ permission,
21304
+ allowedTopicIds,
21305
+ deniedTopics,
21306
+ typeof response.data?.count === "number" ? response.data.count : allowedTopicIds.length
21307
+ );
21308
+ return result;
21133
21309
  }
21134
21310
  };
21135
21311
  }
@@ -21137,64 +21313,66 @@ function createPolicyClient(config = {}) {
21137
21313
  // ../sdk/src/reportsClient.ts
21138
21314
  function createReportsClient(config = {}) {
21139
21315
  const gateway = createGatewayRequestClient(config);
21316
+ const listTemplates = async (args = {}) => gateway.request({
21317
+ path: `/api/platform/v1/reports/templates${toQueryString({
21318
+ slug: args.slug
21319
+ })}`
21320
+ }).then(
21321
+ (response) => mapGatewayData(response, (data) => {
21322
+ const rows = asListItems(data, "templates");
21323
+ return createListResult(rows, "templates");
21324
+ })
21325
+ );
21326
+ const listReports = async (input, args = {}) => {
21327
+ const topicId = resolveTopicId(input);
21328
+ if (!topicId) {
21329
+ throw new Error("topicId is required");
21330
+ }
21331
+ return gateway.request({
21332
+ path: `/api/platform/v1/reports/topics/${encodeURIComponent(topicId)}${toQueryString(
21333
+ {
21334
+ summary: typeof args.summary === "boolean" ? args.summary ? "true" : "false" : void 0
21335
+ }
21336
+ )}`
21337
+ }).then(
21338
+ (response) => mapGatewayData(
21339
+ response,
21340
+ (data) => createListResult(Array.isArray(data) ? data : [], "reports")
21341
+ )
21342
+ );
21343
+ };
21344
+ const getReport = async (reportId) => gateway.request({
21345
+ path: `/api/platform/v1/reports/${encodeURIComponent(reportId)}`
21346
+ });
21140
21347
  return {
21141
21348
  /**
21142
21349
  * List report templates.
21143
21350
  */
21144
- async listTemplates(args = {}) {
21145
- return gateway.request({
21146
- path: `/api/platform/v1/reports/templates${toQueryString({
21147
- slug: args.slug
21148
- })}`
21149
- }).then(
21150
- (response) => mapGatewayData(response, (data) => {
21151
- const record = data && typeof data === "object" ? data : {};
21152
- const rows = Array.isArray(data) ? data : Array.isArray(record.templates) ? record.templates : [];
21153
- return createListResult(rows, "templates");
21154
- })
21155
- );
21156
- },
21351
+ listTemplates,
21157
21352
  /**
21158
21353
  * @deprecated Use listTemplates.
21159
21354
  */
21160
- async getTemplates(args = {}) {
21161
- return this.listTemplates(args);
21162
- },
21355
+ getTemplates: listTemplates,
21163
21356
  /**
21164
21357
  * List reports for a topic scope.
21165
21358
  */
21166
- async listReports(input, args = {}) {
21167
- const topicId = resolveTopicId(input);
21168
- if (!topicId) {
21169
- throw new Error("topicId is required");
21170
- }
21171
- return gateway.request({
21172
- path: `/api/platform/v1/reports/topics/${encodeURIComponent(topicId)}${toQueryString(
21173
- {
21174
- summary: typeof args.summary === "boolean" ? args.summary ? "true" : "false" : void 0
21175
- }
21176
- )}`
21177
- }).then(
21178
- (response) => mapGatewayData(
21179
- response,
21180
- (data) => createListResult(Array.isArray(data) ? data : [], "reports")
21181
- )
21182
- );
21183
- },
21359
+ listReports,
21184
21360
  /**
21185
21361
  * Get a generated report.
21186
21362
  */
21187
- async getReport(reportId) {
21188
- return gateway.request({
21189
- path: `/api/platform/v1/reports/${encodeURIComponent(reportId)}`
21190
- });
21191
- }
21363
+ getReport
21192
21364
  };
21193
21365
  }
21194
21366
 
21195
21367
  // ../sdk/src/schemaClient.ts
21196
21368
  function createSchemaClient(config = {}) {
21197
21369
  const gateway = createGatewayRequestClient(config);
21370
+ const createEntitlement = (input, idempotencyKey) => gateway.request({
21371
+ path: "/api/platform/v1/schema/entitlements",
21372
+ method: "POST",
21373
+ body: input,
21374
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
21375
+ });
21198
21376
  return {
21199
21377
  /**
21200
21378
  * List schema packs.
@@ -21246,29 +21424,95 @@ function createSchemaClient(config = {}) {
21246
21424
  /**
21247
21425
  * Create a schema entitlement.
21248
21426
  */
21249
- async createEntitlement(input, idempotencyKey) {
21250
- return gateway.request({
21251
- path: "/api/platform/v1/schema/entitlements",
21252
- method: "POST",
21253
- body: input,
21254
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
21255
- });
21256
- },
21427
+ createEntitlement,
21257
21428
  /**
21258
21429
  * Update a schema entitlement.
21259
21430
  */
21260
- async updateEntitlement(input, idempotencyKey) {
21261
- return this.createEntitlement(input, idempotencyKey);
21262
- },
21431
+ updateEntitlement: createEntitlement,
21263
21432
  /**
21264
21433
  * @deprecated Use createEntitlement or updateEntitlement.
21265
21434
  */
21266
- async upsertEntitlement(input, idempotencyKey) {
21267
- return this.createEntitlement(input, idempotencyKey);
21268
- }
21435
+ upsertEntitlement: createEntitlement
21269
21436
  };
21270
21437
  }
21271
21438
 
21439
+ // ../sdk/src/clientHelpers.ts
21440
+ function asNodeArray(data) {
21441
+ const rows = asListItems(data, "nodes");
21442
+ if (rows.length > 0) {
21443
+ return rows.filter(
21444
+ (value) => Boolean(value) && typeof value === "object"
21445
+ );
21446
+ }
21447
+ if (data && typeof data === "object") {
21448
+ return [data];
21449
+ }
21450
+ return [];
21451
+ }
21452
+ function requireTopicId4(args) {
21453
+ const topicId = resolveTopicId(args);
21454
+ if (!topicId) {
21455
+ throw new Error("topicId is required");
21456
+ }
21457
+ return topicId;
21458
+ }
21459
+ function requireTopicOrProjectId(args) {
21460
+ const topicId = args.topicId?.trim() || args.projectId?.trim() || void 0;
21461
+ if (!topicId) {
21462
+ throw new Error("topicId is required");
21463
+ }
21464
+ return topicId;
21465
+ }
21466
+ var AUDIT_NODE_REFERENCE_KEY_PATTERN = /(^|_)(id|nodeid|beliefid|resourceid|targetid|sourceid|subjectid|globalid|entityid|recordid|fromnodeid|tonodeid|linkednodeid|linkedbeliefid|nodeids|beliefids|resourceids)$/i;
21467
+ function matchesAuditNodeReference(value, nodeId) {
21468
+ if (Array.isArray(value)) {
21469
+ return value.some((entry) => matchesAuditNodeReference(entry, nodeId));
21470
+ }
21471
+ if (!value || typeof value !== "object") {
21472
+ return false;
21473
+ }
21474
+ return Object.entries(value).some(([key, entry]) => {
21475
+ if (typeof entry === "string" && entry === nodeId && AUDIT_NODE_REFERENCE_KEY_PATTERN.test(key)) {
21476
+ return true;
21477
+ }
21478
+ if (Array.isArray(entry) && AUDIT_NODE_REFERENCE_KEY_PATTERN.test(key) && entry.some((item) => item === nodeId)) {
21479
+ return true;
21480
+ }
21481
+ return matchesAuditNodeReference(entry, nodeId);
21482
+ });
21483
+ }
21484
+ function requireText(args) {
21485
+ const text = resolveText(args);
21486
+ if (!text) {
21487
+ throw new Error("text is required");
21488
+ }
21489
+ return text;
21490
+ }
21491
+ function requireBaseRate(args) {
21492
+ const baseRate = typeof args.baseRate === "number" && Number.isFinite(args.baseRate) ? args.baseRate : 0.5;
21493
+ if (baseRate < 0 || baseRate > 1) {
21494
+ throw new Error("baseRate must be within [0, 1].");
21495
+ }
21496
+ return baseRate;
21497
+ }
21498
+ function sdkQueryString(input) {
21499
+ const params = new URLSearchParams();
21500
+ for (const [key, value] of Object.entries(input)) {
21501
+ if (value === void 0 || value === null) {
21502
+ continue;
21503
+ }
21504
+ if (Array.isArray(value)) {
21505
+ if (value.length > 0) {
21506
+ params.set(key, value.join(","));
21507
+ }
21508
+ continue;
21509
+ }
21510
+ params.set(key, String(value));
21511
+ }
21512
+ const serialized = params.toString();
21513
+ return serialized ? `?${serialized}` : "";
21514
+ }
21515
+
21272
21516
  // ../sdk/src/telemetryClient.ts
21273
21517
  var TELEMETRY_FIELDS = [
21274
21518
  "tenantId",
@@ -21439,6 +21683,16 @@ function query4(input) {
21439
21683
  cursor: input.cursor
21440
21684
  };
21441
21685
  }
21686
+ function effectiveToolsQuery(input) {
21687
+ return {
21688
+ ...query4(input),
21689
+ callerRole: input.callerRole,
21690
+ surface: input.surface,
21691
+ sessionType: input.sessionType,
21692
+ permittedToolNames: input.permittedToolNames ? JSON.stringify(input.permittedToolNames) : void 0,
21693
+ executableOnly: input.executableOnly
21694
+ };
21695
+ }
21442
21696
  function writeBody(input, operation) {
21443
21697
  return knownPayload(input, TOOL_REGISTRY_FIELDS, operation);
21444
21698
  }
@@ -21467,7 +21721,9 @@ function createToolRegistryClient(config = {}) {
21467
21721
  },
21468
21722
  listEffectiveTools(input) {
21469
21723
  return gateway.request({
21470
- path: `/api/platform/v1/tools/effective${toQueryString(query4(input))}`
21724
+ path: `/api/platform/v1/tools/effective${toQueryString(
21725
+ effectiveToolsQuery(input)
21726
+ )}`
21471
21727
  }).then(
21472
21728
  (response) => mapGatewayData(
21473
21729
  response,
@@ -21558,7 +21814,7 @@ function createToolRegistryClient(config = {}) {
21558
21814
  }
21559
21815
 
21560
21816
  // ../sdk/src/version.ts
21561
- var LUCERN_SDK_VERSION = "0.2.0-alpha.1";
21817
+ var LUCERN_SDK_VERSION = "0.3.0-alpha.8";
21562
21818
 
21563
21819
  // ../sdk/src/workflowClient.ts
21564
21820
  function normalizeLensQuery(value) {
@@ -21752,12 +22008,6 @@ function createWorkflowClient(config = {}) {
21752
22008
  )
21753
22009
  );
21754
22010
  },
21755
- /**
21756
- * @deprecated Use createWorktree.
21757
- */
21758
- async addWorktree(input, idempotencyKey) {
21759
- return client.createWorktree(input, idempotencyKey);
21760
- },
21761
22011
  /**
21762
22012
  * Merge a worktree into the main belief line.
21763
22013
  */
@@ -21955,54 +22205,19 @@ function createWorkflowClient(config = {}) {
21955
22205
  body: input,
21956
22206
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
21957
22207
  });
21958
- },
21959
- /**
21960
- * @deprecated Use createBranch.
21961
- */
21962
- async createPillar(input, idempotencyKey) {
21963
- return client.createBranch(input, idempotencyKey);
21964
- },
21965
- /**
21966
- * @deprecated Use addWorktree.
21967
- */
21968
- async createSprint(input, idempotencyKey) {
21969
- return client.createWorktree(input, idempotencyKey);
21970
- },
21971
- /**
21972
- * @deprecated Use merge.
21973
- */
21974
- async completeSprint(worktreeId, input, idempotencyKey) {
21975
- return client.merge(worktreeId, input, idempotencyKey);
21976
- },
21977
- /**
21978
- * @deprecated Use openPullRequest.
21979
- */
21980
- async requestReview(worktreeId, input, idempotencyKey) {
21981
- return client.openPullRequest(worktreeId, input, idempotencyKey);
21982
- },
21983
- /**
21984
- * @deprecated Use push.
21985
- */
21986
- async publishFindings(worktreeId, input, idempotencyKey) {
21987
- return client.push(worktreeId, input, idempotencyKey);
21988
22208
  }
21989
22209
  };
21990
- return client;
22210
+ return Object.assign(client, {
22211
+ addWorktree: client.createWorktree,
22212
+ createPillar: client.createBranch,
22213
+ createSprint: client.createWorktree,
22214
+ completeSprint: client.merge,
22215
+ requestReview: client.openPullRequest,
22216
+ publishFindings: client.push
22217
+ });
21991
22218
  }
21992
22219
 
21993
22220
  // ../sdk/src/client.ts
21994
- function asNodeArray(data) {
21995
- const rows = asListItems(data, "nodes");
21996
- if (rows.length > 0) {
21997
- return rows.filter(
21998
- (value) => Boolean(value) && typeof value === "object"
21999
- );
22000
- }
22001
- if (data && typeof data === "object") {
22002
- return [data];
22003
- }
22004
- return [];
22005
- }
22006
22221
  function toGatewayConfig(config) {
22007
22222
  return {
22008
22223
  baseUrl: config.baseUrl,
@@ -22030,72 +22245,9 @@ function toGatewayConfig(config) {
22030
22245
  }
22031
22246
  };
22032
22247
  }
22033
- function requireTopicId4(args) {
22034
- const topicId = resolveTopicId(args);
22035
- if (!topicId) {
22036
- throw new Error("topicId is required");
22037
- }
22038
- return topicId;
22039
- }
22040
- function requireTopicOrProjectId(args) {
22041
- const topicId = args.topicId?.trim() || args.projectId?.trim() || void 0;
22042
- if (!topicId) {
22043
- throw new Error("topicId is required");
22044
- }
22045
- return topicId;
22046
- }
22047
- var AUDIT_NODE_REFERENCE_KEY_PATTERN = /(^|_)(id|nodeid|beliefid|resourceid|targetid|sourceid|subjectid|globalid|entityid|recordid|fromnodeid|tonodeid|linkednodeid|linkedbeliefid|nodeids|beliefids|resourceids)$/i;
22048
- function matchesAuditNodeReference(value, nodeId) {
22049
- if (Array.isArray(value)) {
22050
- return value.some((entry) => matchesAuditNodeReference(entry, nodeId));
22051
- }
22052
- if (!value || typeof value !== "object") {
22053
- return false;
22054
- }
22055
- return Object.entries(value).some(([key, entry]) => {
22056
- if (typeof entry === "string" && entry === nodeId && AUDIT_NODE_REFERENCE_KEY_PATTERN.test(key)) {
22057
- return true;
22058
- }
22059
- if (Array.isArray(entry) && AUDIT_NODE_REFERENCE_KEY_PATTERN.test(key) && entry.some((item) => item === nodeId)) {
22060
- return true;
22061
- }
22062
- return matchesAuditNodeReference(entry, nodeId);
22063
- });
22064
- }
22065
- function requireText(args) {
22066
- const text = resolveText(args);
22067
- if (!text) {
22068
- throw new Error("text is required");
22069
- }
22070
- return text;
22071
- }
22072
- function requireBaseRate(args) {
22073
- const baseRate = typeof args.baseRate === "number" && Number.isFinite(args.baseRate) ? args.baseRate : 0.5;
22074
- if (baseRate < 0 || baseRate > 1) {
22075
- throw new Error("baseRate must be within [0, 1].");
22076
- }
22077
- return baseRate;
22078
- }
22079
22248
  function exposeGatewayData(response) {
22080
22249
  return Object.assign({}, response, response.data);
22081
22250
  }
22082
- function sdkQueryString(input) {
22083
- const params = new URLSearchParams();
22084
- for (const [key, value] of Object.entries(input)) {
22085
- if (value === void 0 || value === null) {
22086
- continue;
22087
- }
22088
- if (Array.isArray(value)) {
22089
- if (value.length > 0) {
22090
- params.set(key, value.join(","));
22091
- }
22092
- continue;
22093
- }
22094
- params.set(key, String(value));
22095
- }
22096
- const serialized = params.toString();
22097
- return serialized ? `?${serialized}` : "";
22098
- }
22099
22251
  function createLucernClient(config = {}) {
22100
22252
  const gatewayConfig = toGatewayConfig(config);
22101
22253
  const beliefsClient = createBeliefsClient(gatewayConfig);
@@ -22319,7 +22471,7 @@ function createLucernClient(config = {}) {
22319
22471
  topicId,
22320
22472
  nodeType: "contradiction",
22321
22473
  limit: 500
22322
- }) : args.nodeId ? await graphClient.queryNodes({ nodeId: args.nodeId }) : { data: [] };
22474
+ }) : args.nodeId ? await graphClient.listNodes({ nodeId: args.nodeId }) : { data: [] };
22323
22475
  const contradictions2 = asNodeArray(response.data).filter((node) => {
22324
22476
  const status = typeof node.metadata?.status === "string" ? node.metadata.status : typeof node.status === "string" ? node.status : "unresolved";
22325
22477
  if (args.status && status !== args.status) {
@@ -22499,23 +22651,15 @@ function createLucernClient(config = {}) {
22499
22651
  }).then(exposeGatewayData);
22500
22652
  }
22501
22653
  const nodesNamespace = {
22502
- list(query5) {
22503
- return graphClient.listNodes(query5);
22504
- },
22654
+ list: graphClient.listNodes,
22505
22655
  get(input) {
22506
22656
  return graphClient.getNode(
22507
22657
  typeof input === "string" ? { nodeId: input } : input
22508
22658
  );
22509
22659
  },
22510
- create(input, idempotencyKey) {
22511
- return graphClient.createNode(input, idempotencyKey);
22512
- },
22513
- update(input, idempotencyKey) {
22514
- return graphClient.updateNode(input, idempotencyKey);
22515
- },
22516
- batchCreate(input, idempotencyKey) {
22517
- return graphClient.batchCreateNodes(input, idempotencyKey);
22518
- },
22660
+ create: graphClient.createNode,
22661
+ update: graphClient.updateNode,
22662
+ batchCreate: graphClient.batchCreateNodes,
22519
22663
  listByTopicAndType(input) {
22520
22664
  return gateway.request({
22521
22665
  path: `/api/platform/v1/nodes${sdkQueryString({
@@ -22540,15 +22684,9 @@ function createLucernClient(config = {}) {
22540
22684
  })}`
22541
22685
  }).then(exposeGatewayData);
22542
22686
  },
22543
- supersede(input, idempotencyKey) {
22544
- return graphClient.supersedeNode(input, idempotencyKey);
22545
- },
22546
- verify(input, idempotencyKey) {
22547
- return graphClient.verifyNode(input, idempotencyKey);
22548
- },
22549
- hardDelete(input, idempotencyKey) {
22550
- return graphClient.hardDeleteNode(input, idempotencyKey);
22551
- }
22687
+ supersede: graphClient.supersedeNode,
22688
+ verify: graphClient.verifyNode,
22689
+ hardDelete: graphClient.hardDeleteNode
22552
22690
  };
22553
22691
  const publicationNamespace = {
22554
22692
  create(input, idempotencyKey) {
@@ -22625,9 +22763,7 @@ function createLucernClient(config = {}) {
22625
22763
  return {
22626
22764
  config,
22627
22765
  version: LUCERN_SDK_VERSION,
22628
- search(query5, options) {
22629
- return searchResources(query5, options);
22630
- },
22766
+ search: searchResources,
22631
22767
  events: {
22632
22768
  list(query5 = {}) {
22633
22769
  return eventsFacade.list(query5).then(exposeGatewayData);
@@ -22724,9 +22860,7 @@ function createLucernClient(config = {}) {
22724
22860
  confidenceHistory(nodeId) {
22725
22861
  return beliefsFacade.confidenceHistory(nodeId).then(exposeGatewayData);
22726
22862
  },
22727
- opinionHistory(nodeId) {
22728
- return getOpinionHistory(nodeId);
22729
- },
22863
+ opinionHistory: getOpinionHistory,
22730
22864
  createContract(nodeId, input) {
22731
22865
  return beliefsFacade.createContract(nodeId, input).then(exposeGatewayData);
22732
22866
  },
@@ -22980,10 +23114,10 @@ function createLucernClient(config = {}) {
22980
23114
  }));
22981
23115
  },
22982
23116
  getHighPriority(args) {
22983
- return this.list({
23117
+ return questionsFacade.list({
22984
23118
  topicId: requireTopicId4(args),
22985
23119
  status: args.includeAnswered ? void 0 : "open"
22986
- }).then((data) => {
23120
+ }).then(exposeGatewayData).then((data) => {
22987
23121
  const questions = Array.isArray(data.questions) ? data.questions : [];
22988
23122
  const rank = (priority) => {
22989
23123
  switch (priority) {
@@ -23013,9 +23147,7 @@ function createLucernClient(config = {}) {
23013
23147
  },
23014
23148
  graph: {
23015
23149
  nodes: nodesNamespace,
23016
- createEdge(input) {
23017
- return graphClient.createEdge(input);
23018
- },
23150
+ createEdge: graphClient.createEdge,
23019
23151
  neighborhood(args) {
23020
23152
  return graphFacade.neighborhood({
23021
23153
  globalId: args.globalId,
@@ -23074,7 +23206,7 @@ function createLucernClient(config = {}) {
23074
23206
  bisectConfidence,
23075
23207
  listBeliefs,
23076
23208
  detectConfirmationBias(topicId, threshold) {
23077
- return this.bias({
23209
+ return graphFacade.bias({
23078
23210
  topicId,
23079
23211
  threshold,
23080
23212
  limit: 200
@@ -23085,7 +23217,7 @@ function createLucernClient(config = {}) {
23085
23217
  }));
23086
23218
  },
23087
23219
  getStructureAnalysis(topicId) {
23088
- return this.analyze({
23220
+ return graphFacade.analyze({
23089
23221
  topicId,
23090
23222
  limit: 200
23091
23223
  }).then((response) => ({
@@ -23152,38 +23284,20 @@ function createLucernClient(config = {}) {
23152
23284
  }
23153
23285
  },
23154
23286
  judgments: {
23155
- create(input) {
23156
- return decisionsClient.createJudgment(input);
23157
- },
23158
- record(input) {
23159
- return decisionsClient.recordJudgment(input);
23160
- },
23161
- list(query5) {
23162
- return decisionsClient.listJudgments(query5);
23163
- },
23164
- get(judgmentId) {
23165
- return decisionsClient.getJudgment(judgmentId);
23166
- },
23167
- recordOutcome(judgmentId, input) {
23168
- return decisionsClient.recordJudgmentOutcome(judgmentId, input);
23169
- },
23170
- updateOutcome(judgmentId, input) {
23171
- return decisionsClient.updateJudgmentOutcome(judgmentId, input);
23172
- },
23287
+ create: decisionsClient.createJudgment,
23288
+ record: decisionsClient.recordJudgment,
23289
+ list: decisionsClient.listJudgments,
23290
+ get: decisionsClient.getJudgment,
23291
+ recordOutcome: decisionsClient.recordJudgmentOutcome,
23292
+ updateOutcome: decisionsClient.updateJudgmentOutcome,
23173
23293
  readiness(topicId) {
23174
- return decisionsClient.getJudgmentReadiness({
23175
- topicId
23176
- });
23294
+ return decisionsClient.getJudgmentReadiness({ topicId });
23177
23295
  },
23178
23296
  calibration(topicId) {
23179
- return decisionsClient.getJudgmentCalibration({
23180
- topicId
23181
- });
23297
+ return decisionsClient.getJudgmentCalibration({ topicId });
23182
23298
  },
23183
23299
  pendingOutcomeReview(topicId) {
23184
- return decisionsClient.listPendingJudgmentOutcomeReview({
23185
- topicId
23186
- });
23300
+ return decisionsClient.listPendingJudgmentOutcomeReview({ topicId });
23187
23301
  },
23188
23302
  transitionAuditIntegrity(args) {
23189
23303
  return decisionsClient.getJudgmentTransitionAuditIntegrity({
@@ -23193,21 +23307,11 @@ function createLucernClient(config = {}) {
23193
23307
  }
23194
23308
  },
23195
23309
  decisions: {
23196
- create(input) {
23197
- return decisionsClient.createJudgment(input);
23198
- },
23199
- record(input) {
23200
- return decisionsClient.recordJudgment(input);
23201
- },
23202
- list(query5) {
23203
- return decisionsClient.listJudgments(query5);
23204
- },
23205
- get(decisionId) {
23206
- return decisionsClient.getJudgment(decisionId);
23207
- },
23208
- recordOutcome(decisionId, input) {
23209
- return decisionsClient.recordJudgmentOutcome(decisionId, input);
23210
- },
23310
+ create: decisionsClient.createJudgment,
23311
+ record: decisionsClient.recordJudgment,
23312
+ list: decisionsClient.listJudgments,
23313
+ get: decisionsClient.getJudgment,
23314
+ recordOutcome: decisionsClient.recordJudgmentOutcome,
23211
23315
  lessons(decisionId, input, idempotencyKey) {
23212
23316
  return gateway.request({
23213
23317
  path: `/api/platform/v1/decisions/${encodeURIComponent(
@@ -23239,21 +23343,11 @@ function createLucernClient(config = {}) {
23239
23343
  }
23240
23344
  },
23241
23345
  worktrees: {
23242
- createBranch(input) {
23243
- return workflowClient.createBranch(input);
23244
- },
23245
- createLens(input) {
23246
- return workflowClient.createLens(input);
23247
- },
23248
- listLenses(query5) {
23249
- return workflowClient.listLenses(query5);
23250
- },
23251
- applyLensToTopic(input) {
23252
- return workflowClient.applyLensToTopic(input);
23253
- },
23254
- removeLensFromTopic(input) {
23255
- return workflowClient.removeLensFromTopic(input);
23256
- },
23346
+ createBranch: workflowClient.createBranch,
23347
+ createLens: workflowClient.createLens,
23348
+ listLenses: workflowClient.listLenses,
23349
+ applyLensToTopic: workflowClient.applyLensToTopic,
23350
+ removeLensFromTopic: workflowClient.removeLensFromTopic,
23257
23351
  create(input) {
23258
23352
  return worktreesFacade.create({
23259
23353
  title: input.title,
@@ -23358,7 +23452,9 @@ function createLucernClient(config = {}) {
23358
23452
  const dependsOn = Array.isArray(input.dependsOn) ? input.dependsOn.filter(
23359
23453
  (value) => typeof value === "string"
23360
23454
  ) : void 0;
23361
- const blocks = Array.isArray(input.blocks) ? input.blocks.filter((value) => typeof value === "string") : void 0;
23455
+ const blocks = Array.isArray(input.blocks) ? input.blocks.filter(
23456
+ (value) => typeof value === "string"
23457
+ ) : void 0;
23362
23458
  return worktreesFacade.update({
23363
23459
  id: typeof input.worktreeId === "string" ? input.worktreeId : "",
23364
23460
  hypothesis: typeof input.hypothesis === "string" ? input.hypothesis : void 0,
@@ -23372,7 +23468,23 @@ function createLucernClient(config = {}) {
23372
23468
  });
23373
23469
  },
23374
23470
  update(input) {
23375
- return this.updateMetadata(input);
23471
+ const dependsOn = Array.isArray(input.dependsOn) ? input.dependsOn.filter(
23472
+ (value) => typeof value === "string"
23473
+ ) : void 0;
23474
+ const blocks = Array.isArray(input.blocks) ? input.blocks.filter(
23475
+ (value) => typeof value === "string"
23476
+ ) : void 0;
23477
+ return worktreesFacade.update({
23478
+ id: typeof input.worktreeId === "string" ? input.worktreeId : "",
23479
+ hypothesis: typeof input.hypothesis === "string" ? input.hypothesis : void 0,
23480
+ campaign: typeof input.campaign === "number" ? input.campaign : void 0,
23481
+ lane: typeof input.lane === "string" ? input.lane : void 0,
23482
+ laneOrderInCampaign: typeof input.laneOrderInCampaign === "number" ? input.laneOrderInCampaign : void 0,
23483
+ orderInLane: typeof input.orderInLane === "number" ? input.orderInLane : void 0,
23484
+ dependsOn,
23485
+ blocks,
23486
+ gate: typeof input.gate === "string" ? input.gate : void 0
23487
+ });
23376
23488
  },
23377
23489
  updateTargets(input) {
23378
23490
  return worktreesFacade.updateTargets({
@@ -23383,9 +23495,7 @@ function createLucernClient(config = {}) {
23383
23495
  removeQuestionIds: input.removeQuestionIds
23384
23496
  });
23385
23497
  },
23386
- listAll(query5 = {}) {
23387
- return workflowClient.listAllWorktrees(query5);
23388
- },
23498
+ listAll: workflowClient.listAllWorktrees,
23389
23499
  merge(worktreeId, input) {
23390
23500
  return worktreesFacade.merge({
23391
23501
  id: worktreeId,
@@ -23393,18 +23503,12 @@ function createLucernClient(config = {}) {
23393
23503
  summary: input.summary
23394
23504
  });
23395
23505
  },
23396
- push(worktreeId, input) {
23397
- return workflowClient.push(worktreeId, input);
23398
- },
23399
- openPullRequest(worktreeId, input) {
23400
- return workflowClient.openPullRequest(worktreeId, input);
23401
- },
23506
+ push: workflowClient.push,
23507
+ openPullRequest: workflowClient.openPullRequest,
23402
23508
  pipelineSnapshot(topicId) {
23403
23509
  return functionSurfaceClient.pipelineSnapshot({ topicId });
23404
23510
  },
23405
- complete(input, idempotencyKey) {
23406
- return worktreesFacade.complete(input, idempotencyKey);
23407
- },
23511
+ complete: worktreesFacade.complete,
23408
23512
  advancePhase(worktreeId, idempotencyKey) {
23409
23513
  return worktreesFacade.advancePhase(
23410
23514
  { worktreeId },
@@ -23417,12 +23521,8 @@ function createLucernClient(config = {}) {
23417
23521
  idempotencyKey
23418
23522
  );
23419
23523
  },
23420
- patchState(input, idempotencyKey) {
23421
- return worktreesFacade.patchState(input, idempotencyKey);
23422
- },
23423
- bulkCreate(input, idempotencyKey) {
23424
- return worktreesFacade.bulkCreate(input, idempotencyKey);
23425
- }
23524
+ patchState: worktreesFacade.patchState,
23525
+ bulkCreate: worktreesFacade.bulkCreate
23426
23526
  },
23427
23527
  context: {
23428
23528
  listTopics(query5 = {}) {
@@ -23433,27 +23533,15 @@ function createLucernClient(config = {}) {
23433
23533
  type: query5.type
23434
23534
  });
23435
23535
  },
23436
- compile(topicId, input = {}) {
23437
- return contextClient.compile(topicId, input);
23438
- },
23439
- recordScopeLearning(input, idempotencyKey) {
23440
- return functionSurfaceClient.recordScopeLearning(input, idempotencyKey);
23441
- },
23536
+ compile: contextClient.compile,
23537
+ recordScopeLearning: functionSurfaceClient.recordScopeLearning,
23442
23538
  discover(input) {
23443
23539
  return discoverTopics(input);
23444
23540
  },
23445
- analyzeTopicDensity(input) {
23446
- return functionSurfaceClient.analyzeTopicDensity(input);
23447
- },
23448
- applyAutoBranching(input, idempotencyKey) {
23449
- return functionSurfaceClient.applyAutoBranching(input, idempotencyKey);
23450
- },
23451
- seedBeliefLattice(input = {}, idempotencyKey) {
23452
- return functionSurfaceClient.seedBeliefLattice(input, idempotencyKey);
23453
- },
23454
- getLatticeCoverage(input = {}) {
23455
- return functionSurfaceClient.getLatticeCoverage(input);
23456
- },
23541
+ analyzeTopicDensity: functionSurfaceClient.analyzeTopicDensity,
23542
+ applyAutoBranching: functionSurfaceClient.applyAutoBranching,
23543
+ seedBeliefLattice: functionSurfaceClient.seedBeliefLattice,
23544
+ getLatticeCoverage: functionSurfaceClient.getLatticeCoverage,
23457
23545
  matchEntityType(input) {
23458
23546
  return ontologiesFacade.match(input).then(exposeGatewayData);
23459
23547
  },
@@ -23538,9 +23626,7 @@ function createLucernClient(config = {}) {
23538
23626
  type: input.type
23539
23627
  });
23540
23628
  },
23541
- get(topicId) {
23542
- return topicsFacade.get(topicId);
23543
- },
23629
+ get: topicsFacade.get,
23544
23630
  create(input) {
23545
23631
  return topicsFacade.create({
23546
23632
  name: input.name,
@@ -23585,12 +23671,8 @@ function createLucernClient(config = {}) {
23585
23671
  maxDepth: query5.maxDepth
23586
23672
  });
23587
23673
  },
23588
- remove(topicId, idempotencyKey) {
23589
- return topicsFacade.remove(topicId, idempotencyKey);
23590
- },
23591
- bulkCreate(input, idempotencyKey) {
23592
- return topicsFacade.bulkCreate(input, idempotencyKey);
23593
- }
23674
+ remove: topicsFacade.remove,
23675
+ bulkCreate: topicsFacade.bulkCreate
23594
23676
  },
23595
23677
  answers: {
23596
23678
  create(input) {
@@ -23689,33 +23771,15 @@ function createLucernClient(config = {}) {
23689
23771
  raw: ontologyClient
23690
23772
  },
23691
23773
  coordination: {
23692
- registerSession(input = {}, idempotencyKey) {
23693
- return functionSurfaceClient.registerSession(input, idempotencyKey);
23694
- },
23695
- heartbeatSession(input = {}, idempotencyKey) {
23696
- return functionSurfaceClient.heartbeatSession(input, idempotencyKey);
23697
- },
23698
- endSession(input = {}, idempotencyKey) {
23699
- return functionSurfaceClient.endSession(input, idempotencyKey);
23700
- },
23701
- listActiveSessions(input = {}) {
23702
- return functionSurfaceClient.listActiveSessions(input);
23703
- },
23704
- sendAgentMessage(input, idempotencyKey) {
23705
- return functionSurfaceClient.sendAgentMessage(input, idempotencyKey);
23706
- },
23707
- broadcastMessage(input, idempotencyKey) {
23708
- return functionSurfaceClient.broadcastMessage(input, idempotencyKey);
23709
- },
23710
- getInbox(input = {}) {
23711
- return functionSurfaceClient.getAgentInbox(input);
23712
- },
23713
- getAgentInbox(input = {}) {
23714
- return functionSurfaceClient.getAgentInbox(input);
23715
- },
23716
- claimFiles(input, idempotencyKey) {
23717
- return functionSurfaceClient.claimFiles(input, idempotencyKey);
23718
- }
23774
+ registerSession: functionSurfaceClient.registerSession,
23775
+ heartbeatSession: functionSurfaceClient.heartbeatSession,
23776
+ endSession: functionSurfaceClient.endSession,
23777
+ listActiveSessions: functionSurfaceClient.listActiveSessions,
23778
+ sendAgentMessage: functionSurfaceClient.sendAgentMessage,
23779
+ broadcastMessage: functionSurfaceClient.broadcastMessage,
23780
+ getInbox: functionSurfaceClient.getAgentInbox,
23781
+ getAgentInbox: functionSurfaceClient.getAgentInbox,
23782
+ claimFiles: functionSurfaceClient.claimFiles
23719
23783
  },
23720
23784
  policy: {
23721
23785
  checkPermission(input) {
@@ -23746,38 +23810,24 @@ function createLucernClient(config = {}) {
23746
23810
  principalId: typeof input.principalId === "string" ? input.principalId : void 0
23747
23811
  });
23748
23812
  },
23813
+ // Backward compatibility shim: keep the policy namespace exposing the
23814
+ // historical manageWritePolicy entry point.
23749
23815
  manageWritePolicy(input, idempotencyKey) {
23750
23816
  return functionSurfaceClient.manageWritePolicy(input, idempotencyKey);
23751
23817
  },
23752
23818
  raw: policyClient
23753
23819
  },
23754
23820
  observations: {
23755
- ingest(input, idempotencyKey) {
23756
- return functionSurfaceClient.ingestObservation(input, idempotencyKey);
23757
- },
23758
- ingestObservation(input, idempotencyKey) {
23759
- return functionSurfaceClient.ingestObservation(input, idempotencyKey);
23760
- },
23761
- getContext(input) {
23762
- return functionSurfaceClient.getObservationContext(input);
23763
- },
23764
- getObservationContext(input) {
23765
- return functionSurfaceClient.getObservationContext(input);
23766
- }
23821
+ ingest: functionSurfaceClient.ingestObservation,
23822
+ ingestObservation: functionSurfaceClient.ingestObservation,
23823
+ getContext: functionSurfaceClient.getObservationContext,
23824
+ getObservationContext: functionSurfaceClient.getObservationContext
23767
23825
  },
23768
23826
  coding: {
23769
- getCodeContext(input) {
23770
- return functionSurfaceClient.getCodeContext(input);
23771
- },
23772
- getChangeHistory(input) {
23773
- return functionSurfaceClient.getChangeHistory(input);
23774
- },
23775
- recordAttempt(input, idempotencyKey) {
23776
- return functionSurfaceClient.recordAttempt(input, idempotencyKey);
23777
- },
23778
- getFailureLog(input) {
23779
- return functionSurfaceClient.getFailureLog(input);
23780
- }
23827
+ getCodeContext: functionSurfaceClient.getCodeContext,
23828
+ getChangeHistory: functionSurfaceClient.getChangeHistory,
23829
+ recordAttempt: functionSurfaceClient.recordAttempt,
23830
+ getFailureLog: functionSurfaceClient.getFailureLog
23781
23831
  },
23782
23832
  contracts: {
23783
23833
  create(input) {
@@ -23803,9 +23853,7 @@ function createLucernClient(config = {}) {
23803
23853
  }
23804
23854
  },
23805
23855
  bootstrap: {
23806
- generateSessionHandoff(input) {
23807
- return functionSurfaceClient.generateSessionHandoff(input);
23808
- }
23856
+ generateSessionHandoff: functionSurfaceClient.generateSessionHandoff
23809
23857
  },
23810
23858
  embeddings: embeddingsClient,
23811
23859
  graphAnalysis: graphAnalysisClient,
@@ -23827,25 +23875,15 @@ function createLucernClient(config = {}) {
23827
23875
  createAcl: toolRegistryClient.createAcl,
23828
23876
  deleteAcl: toolRegistryClient.deleteAcl,
23829
23877
  registerCustomTool: toolRegistryClient.registerCustomTool,
23830
- register(registration) {
23831
- return registerCustomTool(registration);
23832
- },
23833
- unregister(fullName) {
23834
- return unregisterCustomTool(fullName);
23835
- },
23836
- list() {
23837
- return listRegisteredCustomTools();
23838
- },
23839
- clear() {
23840
- clearRegisteredCustomTools();
23841
- },
23878
+ register: registerCustomTool,
23879
+ unregister: unregisterCustomTool,
23880
+ list: listRegisteredCustomTools,
23881
+ clear: clearRegisteredCustomTools,
23842
23882
  invoke(name, input = {}) {
23843
23883
  const fullName = name.includes(".") ? name : `custom.${name}`;
23844
23884
  return invokeCustomTool(fullName, input);
23845
23885
  },
23846
- namespace(namespace) {
23847
- return getCustomNamespace(namespace);
23848
- }
23886
+ namespace: getCustomNamespace
23849
23887
  },
23850
23888
  packs: {
23851
23889
  /**
@@ -23860,27 +23898,13 @@ function createLucernClient(config = {}) {
23860
23898
  get isInstalled() {
23861
23899
  return _packInstalled;
23862
23900
  },
23863
- listCatalog() {
23864
- return packsClient.listCatalog();
23865
- },
23866
- catalog() {
23867
- return packsClient.getCatalog();
23868
- },
23869
- listStates(scope) {
23870
- return packsClient.listStates(scope);
23871
- },
23872
- states(scope) {
23873
- return packsClient.getStates(scope);
23874
- },
23875
- install(input) {
23876
- return packsClient.install(input);
23877
- },
23878
- enable(input) {
23879
- return packsClient.enable(input);
23880
- },
23881
- disable(input) {
23882
- return packsClient.disable(input);
23883
- }
23901
+ listCatalog: packsClient.listCatalog,
23902
+ catalog: packsClient.listCatalog,
23903
+ listStates: packsClient.listStates,
23904
+ states: packsClient.getStates,
23905
+ install: packsClient.install,
23906
+ enable: packsClient.enable,
23907
+ disable: packsClient.disable
23884
23908
  },
23885
23909
  nodes: nodesNamespace,
23886
23910
  identity: {
@@ -23893,30 +23917,16 @@ function createLucernClient(config = {}) {
23893
23917
  raw: identityClient
23894
23918
  },
23895
23919
  mcp: {
23896
- bootstrapSession(input) {
23897
- return mcpClient.bootstrapSession(input);
23898
- },
23899
- checkWritePolicy(input) {
23900
- return mcpClient.checkWritePolicy(input);
23901
- },
23902
- beginBuildSession(input) {
23903
- return mcpClient.beginBuildSession(input);
23904
- },
23905
- evaluateEngineeringContract(input) {
23906
- return mcpClient.evaluateEngineeringContract(input);
23907
- },
23908
- evaluateResearchContract(input) {
23909
- return mcpClient.evaluateResearchContract(input);
23910
- }
23920
+ bootstrapSession: mcpClient.bootstrapSession,
23921
+ checkWritePolicy: mcpClient.checkWritePolicy,
23922
+ beginBuildSession: mcpClient.beginBuildSession,
23923
+ evaluateEngineeringContract: mcpClient.evaluateEngineeringContract,
23924
+ evaluateResearchContract: mcpClient.evaluateResearchContract
23911
23925
  },
23912
23926
  auth: {
23913
23927
  device: {
23914
- createCode(input) {
23915
- return authDeviceClient.createDeviceCode(input);
23916
- },
23917
- pollToken(deviceCode) {
23918
- return authDeviceClient.pollDeviceToken(deviceCode);
23919
- }
23928
+ createCode: authDeviceClient.createDeviceCode,
23929
+ pollToken: authDeviceClient.pollDeviceToken
23920
23930
  }
23921
23931
  },
23922
23932
  custom: getCustomNamespace("custom"),
@@ -23969,50 +23979,55 @@ function cleanNumber2(value) {
23969
23979
  function cleanBoolean2(value) {
23970
23980
  return typeof value === "boolean" ? value : void 0;
23971
23981
  }
23972
- function buildCompileContextRequest2(topicId, input = {}) {
23973
- const payload = { topicId };
23974
- const query5 = cleanString6(input.query);
23982
+ function buildCompileContextRequest2(topicIdOrInput = {}, input = {}) {
23983
+ const effectiveInput = typeof topicIdOrInput === "string" ? input : topicIdOrInput;
23984
+ const payload = {};
23985
+ const topicId = typeof topicIdOrInput === "string" ? cleanString6(topicIdOrInput) : cleanString6(effectiveInput.topicId);
23986
+ if (topicId) {
23987
+ payload.topicId = topicId;
23988
+ }
23989
+ const query5 = cleanString6(effectiveInput.query);
23975
23990
  if (query5) {
23976
23991
  payload.query = query5;
23977
23992
  }
23978
- const budget = cleanNumber2(input.budget) ?? cleanNumber2(input.tokenBudget);
23993
+ const budget = cleanNumber2(effectiveInput.budget) ?? cleanNumber2(effectiveInput.tokenBudget);
23979
23994
  if (budget !== void 0) {
23980
23995
  payload.budget = budget;
23981
23996
  }
23982
- const ranking = cleanString6(input.ranking) ?? cleanString6(input.rankingProfile);
23997
+ const ranking = cleanString6(effectiveInput.ranking) ?? cleanString6(effectiveInput.rankingProfile);
23983
23998
  if (ranking) {
23984
23999
  payload.ranking = ranking;
23985
24000
  }
23986
- const limit = cleanNumber2(input.limit);
24001
+ const limit = cleanNumber2(effectiveInput.limit);
23987
24002
  if (limit !== void 0) {
23988
24003
  payload.limit = limit;
23989
24004
  }
23990
- const maxDepth = cleanNumber2(input.maxDepth);
24005
+ const maxDepth = cleanNumber2(effectiveInput.maxDepth);
23991
24006
  if (maxDepth !== void 0) {
23992
24007
  payload.maxDepth = maxDepth;
23993
24008
  }
23994
- const includeEntities = cleanBoolean2(input.includeEntities);
24009
+ const includeEntities = cleanBoolean2(effectiveInput.includeEntities);
23995
24010
  if (includeEntities !== void 0) {
23996
24011
  payload.includeEntities = includeEntities;
23997
24012
  }
23998
- const mode = cleanString6(input.mode);
24013
+ const mode = cleanString6(effectiveInput.mode);
23999
24014
  if (mode) {
24000
24015
  payload.mode = mode;
24001
24016
  }
24002
- const includeFailures = cleanBoolean2(input.includeFailures);
24017
+ const includeFailures = cleanBoolean2(effectiveInput.includeFailures);
24003
24018
  if (includeFailures !== void 0) {
24004
24019
  payload.includeFailures = includeFailures;
24005
24020
  }
24006
- const worktreeId = cleanString6(input.worktreeId);
24021
+ const worktreeId = cleanString6(effectiveInput.worktreeId);
24007
24022
  if (worktreeId) {
24008
24023
  payload.worktreeId = worktreeId;
24009
24024
  }
24010
- const sessionId = cleanString6(input.sessionId);
24025
+ const sessionId = cleanString6(effectiveInput.sessionId);
24011
24026
  if (sessionId) {
24012
24027
  payload.sessionId = sessionId;
24013
24028
  }
24014
- if (Array.isArray(input.packWeightOverrides) && input.packWeightOverrides.length > 0) {
24015
- payload.packWeightOverrides = input.packWeightOverrides;
24029
+ if (Array.isArray(effectiveInput.packWeightOverrides) && effectiveInput.packWeightOverrides.length > 0) {
24030
+ payload.packWeightOverrides = effectiveInput.packWeightOverrides;
24016
24031
  }
24017
24032
  return {
24018
24033
  path: "/api/platform/v1/context/compile",
@@ -24022,8 +24037,12 @@ function buildCompileContextRequest2(topicId, input = {}) {
24022
24037
  }
24023
24038
  function createContextFacade(config) {
24024
24039
  return {
24025
- compile(topicId, input = {}) {
24026
- const request = buildCompileContextRequest2(topicId, input);
24040
+ compile(topicIdOrInput = {}, input = {}) {
24041
+ const request = buildCompileContextRequest2(topicIdOrInput, input);
24042
+ return config.transport.request(request);
24043
+ },
24044
+ compileByQuery(input = {}) {
24045
+ const request = buildCompileContextRequest2(input);
24027
24046
  return config.transport.request(request);
24028
24047
  }
24029
24048
  };
@@ -24102,17 +24121,11 @@ var TOKENS_PER_WORD = 1.35;
24102
24121
  var MIN_TOKEN_ESTIMATE = 8;
24103
24122
 
24104
24123
  // ../sdk/src/contextPackPolicy.ts
24105
- function nowMs() {
24106
- return Date.now();
24107
- }
24108
- function normalizeText(text) {
24109
- return text.trim().toLowerCase();
24110
- }
24111
24124
  function tokenHits(text, tokens) {
24112
24125
  if (tokens.length === 0) {
24113
24126
  return 1;
24114
24127
  }
24115
- const haystack = normalizeText(text);
24128
+ const haystack = text.trim().toLowerCase();
24116
24129
  let hits = 0;
24117
24130
  for (const token of tokens) {
24118
24131
  if (haystack.includes(token)) {
@@ -24127,7 +24140,7 @@ function clamp013(value) {
24127
24140
  }
24128
24141
  return Math.max(0, Math.min(1, value));
24129
24142
  }
24130
- function recencyScore(updatedAt, referenceTimeMs = nowMs()) {
24143
+ function recencyScore(updatedAt, referenceTimeMs = Date.now()) {
24131
24144
  if (!updatedAt || !Number.isFinite(updatedAt)) {
24132
24145
  return 0.25;
24133
24146
  }
@@ -24143,15 +24156,15 @@ function confidenceScore(confidence) {
24143
24156
  return clamp013(confidence);
24144
24157
  }
24145
24158
  function priorityScore(priority) {
24146
- const value = normalizeText(priority || "");
24159
+ const value = (priority || "").trim().toLowerCase();
24147
24160
  return PRIORITY_SCORES[value] ?? DEFAULT_PRIORITY_SCORE;
24148
24161
  }
24149
24162
  function severityScore(severity) {
24150
- const value = normalizeText(severity || "");
24163
+ const value = (severity || "").trim().toLowerCase();
24151
24164
  return SEVERITY_SCORES[value] ?? DEFAULT_SEVERITY_SCORE;
24152
24165
  }
24153
24166
  function beliefTypeBonus(beliefType) {
24154
- const value = normalizeText(beliefType || "");
24167
+ const value = (beliefType || "").trim().toLowerCase();
24155
24168
  return BELIEF_TYPE_BONUS[value] ?? DEFAULT_BELIEF_TYPE_BONUS;
24156
24169
  }
24157
24170
  function resolveEffectiveWeights(overrides) {
@@ -24177,7 +24190,7 @@ function generateJustification(_section, candidate, queryTokens, weights) {
24177
24190
  }
24178
24191
  const ts = candidate.updatedAt || candidate.createdAt || null;
24179
24192
  if (ts && Number.isFinite(ts)) {
24180
- const ageDays = Math.max(0, nowMs() - ts) / (1e3 * 60 * 60 * 24);
24193
+ const ageDays = Math.max(0, Date.now() - ts) / (1e3 * 60 * 60 * 24);
24181
24194
  if (ageDays < 1) {
24182
24195
  parts.push("updated today");
24183
24196
  } else if (ageDays < 7) {
@@ -24202,10 +24215,6 @@ function generateJustification(_section, candidate, queryTokens, weights) {
24202
24215
  }
24203
24216
  return parts.join(", ");
24204
24217
  }
24205
- function computeBaselineScore(candidate, queryTokens) {
24206
- const hits = tokenHits(candidate.text, queryTokens);
24207
- return queryTokens.length === 0 ? 1 : hits;
24208
- }
24209
24218
  function computeWeightedScore(section, candidate, queryTokens, effectiveWeights, referenceTimeMs) {
24210
24219
  const weights = (effectiveWeights ?? RANKING_WEIGHTS)[section];
24211
24220
  const queryComponent = queryTokens.length === 0 ? 0.4 : clamp013(tokenHits(candidate.text, queryTokens) / queryTokens.length);
@@ -24239,7 +24248,7 @@ function rankContextSection(section, rows, queryTokens, limit, profile, options)
24239
24248
  queryTokens,
24240
24249
  effectiveWeights,
24241
24250
  referenceTimeMs
24242
- ) : computeBaselineScore(row, queryTokens);
24251
+ ) : queryTokens.length === 0 ? 1 : tokenHits(row.text, queryTokens);
24243
24252
  const result = { ...row, score };
24244
24253
  if (includeJustifications && profile === "weighted_v1") {
24245
24254
  const weights = (effectiveWeights ?? RANKING_WEIGHTS)[section];
@@ -24606,18 +24615,21 @@ function normalizeQueryTokens(query5) {
24606
24615
  function parseRankingProfile(value) {
24607
24616
  return value === "baseline_v1" ? "baseline_v1" : "weighted_v1";
24608
24617
  }
24618
+ function isRecord10(value) {
24619
+ return value !== null && typeof value === "object" && !Array.isArray(value);
24620
+ }
24609
24621
  function beliefTypeOf(node) {
24610
24622
  if (typeof node.beliefType === "string") {
24611
24623
  return node.beliefType;
24612
24624
  }
24613
- const metadata = node.metadata || {};
24625
+ const metadata = isRecord10(node.metadata) ? node.metadata : {};
24614
24626
  if (typeof metadata.beliefType === "string") {
24615
24627
  return metadata.beliefType;
24616
24628
  }
24617
24629
  return "";
24618
24630
  }
24619
24631
  function questionStatusOf(node) {
24620
- const metadata = node.metadata || {};
24632
+ const metadata = isRecord10(node.metadata) ? node.metadata : {};
24621
24633
  const direct = typeof node.status === "string" ? node.status : "";
24622
24634
  const questionStatus = typeof metadata.questionStatus === "string" ? metadata.questionStatus : "";
24623
24635
  return (questionStatus || direct || "open").toLowerCase();
@@ -24633,9 +24645,6 @@ function isOpenQuestion(status) {
24633
24645
  "belief_forked"
24634
24646
  ].includes(status);
24635
24647
  }
24636
- function metadataText(payload) {
24637
- return JSON.stringify(payload).toLowerCase();
24638
- }
24639
24648
  function collectTopicNeighborhood(topics2, rootTopicId, maxDescendantDepth = 2) {
24640
24649
  const byId = /* @__PURE__ */ new Map();
24641
24650
  const children = /* @__PURE__ */ new Map();
@@ -24697,11 +24706,10 @@ function dedupeById(rows) {
24697
24706
  return output;
24698
24707
  }
24699
24708
  function candidateTimestamp(candidate) {
24700
- if (!candidate || typeof candidate !== "object") {
24709
+ if (!isRecord10(candidate)) {
24701
24710
  return 0;
24702
24711
  }
24703
- const record = candidate;
24704
- const timestamps = [record.updatedAt, record.createdAt, record.generatedAt].filter(
24712
+ const timestamps = [candidate.updatedAt, candidate.createdAt, candidate.generatedAt].filter(
24705
24713
  (value) => typeof value === "number" && Number.isFinite(value)
24706
24714
  );
24707
24715
  return timestamps.length > 0 ? Math.max(...timestamps) : 0;
@@ -24823,7 +24831,7 @@ function compileContextPackFromSnapshot(snapshot) {
24823
24831
  beliefType: beliefTypeOf(belief) || null,
24824
24832
  status: belief.status || "active",
24825
24833
  updatedAt: belief.updatedAt || belief.createdAt || null,
24826
- metadataText: belief.metadata && typeof belief.metadata === "object" ? metadataText(belief.metadata) : ""
24834
+ metadataText: belief.metadata && typeof belief.metadata === "object" ? JSON.stringify(belief.metadata).toLowerCase() : ""
24827
24835
  }));
24828
24836
  const activeBeliefs = rankContextSection(
24829
24837
  "activeBeliefs",
@@ -24855,7 +24863,7 @@ function compileContextPackFromSnapshot(snapshot) {
24855
24863
  status,
24856
24864
  priority: typeof metadata.priority === "string" ? metadata.priority : "medium",
24857
24865
  updatedAt: question.updatedAt || question.createdAt || null,
24858
- metadataText: metadataText(metadata)
24866
+ metadataText: JSON.stringify(metadata).toLowerCase()
24859
24867
  };
24860
24868
  }).filter((row) => isOpenQuestion(row.status));
24861
24869
  const openQuestions = rankContextSection(
@@ -24887,7 +24895,7 @@ function compileContextPackFromSnapshot(snapshot) {
24887
24895
  kind: typeof metadata.kind === "string" && metadata.kind || "observation",
24888
24896
  createdAt: item.createdAt || null,
24889
24897
  updatedAt: item.updatedAt || item.createdAt || null,
24890
- metadataText: metadataText(metadata)
24898
+ metadataText: JSON.stringify(metadata).toLowerCase()
24891
24899
  };
24892
24900
  });
24893
24901
  const recentEvidence = rankContextSection(
@@ -24969,7 +24977,7 @@ function compileContextPackFromSnapshot(snapshot) {
24969
24977
  let failureContext;
24970
24978
  if (snapshot.plan.includeFailures && snapshot.failures) {
24971
24979
  const allFailures = snapshot.failures.filter((node) => {
24972
- const metadata = node.metadata || {};
24980
+ const metadata = isRecord10(node.metadata) ? node.metadata : {};
24973
24981
  return metadata.failedApproach === true || metadata.isFailedAttempt === true;
24974
24982
  });
24975
24983
  const rankedFailures = rankContextSection(
@@ -24987,7 +24995,7 @@ function compileContextPackFromSnapshot(snapshot) {
24987
24995
  );
24988
24996
  const failures = rankedFailures.map((row) => {
24989
24997
  const original = allFailures.find((node) => String(node._id) === row.id);
24990
- const metadata = original?.metadata || {};
24998
+ const metadata = isRecord10(original?.metadata) ? original?.metadata : {};
24991
24999
  return {
24992
25000
  attemptId: row.id,
24993
25001
  approach: String(row.text || ""),
@@ -25471,9 +25479,7 @@ function lastDelegator(delegationChain) {
25471
25479
 
25472
25480
  // ../sdk/src/contracts/lens-filter.contract.ts
25473
25481
  function isLensFilterCriteria2(value) {
25474
- if (!value || typeof value !== "object") return false;
25475
- const obj = value;
25476
- return typeof obj.version === "number" && typeof obj.kind === "string";
25482
+ return isRecord11(value) && typeof value.version === "number" && typeof value.kind === "string";
25477
25483
  }
25478
25484
  function isTaxonomyFilterCriteriaV12(value) {
25479
25485
  if (!isLensFilterCriteria2(value)) return false;
@@ -25502,6 +25508,9 @@ function validateFilterCriteria2(value) {
25502
25508
  ]
25503
25509
  };
25504
25510
  }
25511
+ function isRecord11(value) {
25512
+ return value !== null && typeof value === "object" && !Array.isArray(value);
25513
+ }
25505
25514
  function validateTaxonomyFilterV1(criteria) {
25506
25515
  const errors = [];
25507
25516
  if (!Array.isArray(criteria.entityTypeFilters)) {
@@ -26008,6 +26017,9 @@ function fromBase64(value) {
26008
26017
  const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
26009
26018
  return decodeURIComponent(escape(atob(normalized)));
26010
26019
  }
26020
+ function isRecord12(value) {
26021
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
26022
+ }
26011
26023
  function createEventId() {
26012
26024
  const random = typeof globalThis.crypto?.randomUUID === "function" ? globalThis.crypto.randomUUID().replace(/-/g, "") : Array.from(
26013
26025
  typeof globalThis.crypto?.getRandomValues === "function" ? globalThis.crypto.getRandomValues(new Uint8Array(16)) : Array.from({ length: 16 }, () => Math.floor(Math.random() * 256)),
@@ -26056,14 +26068,14 @@ function decodeEventCursor(cursor) {
26056
26068
  }
26057
26069
  try {
26058
26070
  const parsed = JSON.parse(fromBase64(cursor.trim()));
26059
- if (typeof parsed.timestamp !== "number" || !Number.isFinite(parsed.timestamp) || typeof parsed.eventId !== "string" || parsed.eventId.trim().length === 0) {
26071
+ if (!isRecord12(parsed) || typeof parsed.timestamp !== "number" || !Number.isFinite(parsed.timestamp) || typeof parsed.eventId !== "string" || parsed.eventId.trim().length === 0) {
26060
26072
  return null;
26061
26073
  }
26062
26074
  return {
26063
26075
  timestamp: parsed.timestamp,
26064
26076
  eventId: parsed.eventId.trim()
26065
26077
  };
26066
- } catch {
26078
+ } catch (error) {
26067
26079
  return null;
26068
26080
  }
26069
26081
  }
@@ -26092,7 +26104,7 @@ var LOCALHOST_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1"])
26092
26104
  function normalizeUrl(url) {
26093
26105
  try {
26094
26106
  return new URL(url.trim());
26095
- } catch {
26107
+ } catch (error) {
26096
26108
  throw new Error("Webhook URL must be a valid absolute URL.");
26097
26109
  }
26098
26110
  }
@@ -26679,24 +26691,27 @@ function readResultString(value, key) {
26679
26691
  }
26680
26692
  function createContextHandlers(context) {
26681
26693
  const compiler = createContextClient(context.sdkConfig);
26694
+ const functionSurface = createFunctionSurfaceClient(context.sdkConfig);
26682
26695
  return {
26683
26696
  compile_context: contractToHandler(
26684
26697
  MCP_TOOL_CONTRACTS.compile_context,
26685
26698
  async (params) => {
26686
- const topicId = readTopicId4(params, { required: true });
26687
- const response = await compiler.compile(
26688
- topicId,
26689
- {
26690
- ...readString3(params, "query") ? { query: readString3(params, "query") } : {},
26691
- ...readNumber2(params, "budget") !== void 0 ? { budget: readNumber2(params, "budget") } : {},
26692
- ...readString3(params, "ranking") ? {
26693
- ranking: readString3(params, "ranking")
26694
- } : {},
26695
- ...readNumber2(params, "limit") !== void 0 ? { limit: readNumber2(params, "limit") } : {},
26696
- ...readNumber2(params, "maxDepth") !== void 0 ? { maxDepth: readNumber2(params, "maxDepth") } : {},
26697
- ...readBoolean(params, "includeEntities") !== void 0 ? { includeEntities: readBoolean(params, "includeEntities") } : {}
26698
- }
26699
- );
26699
+ const topicId = readTopicId4(params);
26700
+ const query5 = readString3(params, "query");
26701
+ const input = {
26702
+ ...query5 ? { query: query5 } : {},
26703
+ ...readNumber2(params, "budget") !== void 0 ? { budget: readNumber2(params, "budget") } : {},
26704
+ ...readString3(params, "ranking") ? {
26705
+ ranking: readString3(params, "ranking")
26706
+ } : {},
26707
+ ...readNumber2(params, "limit") !== void 0 ? { limit: readNumber2(params, "limit") } : {},
26708
+ ...readNumber2(params, "maxDepth") !== void 0 ? { maxDepth: readNumber2(params, "maxDepth") } : {},
26709
+ ...readBoolean(params, "includeEntities") !== void 0 ? { includeEntities: readBoolean(params, "includeEntities") } : {}
26710
+ };
26711
+ if (!topicId && !query5) {
26712
+ throw new Error("[compile_context] query is required when topicId is omitted.");
26713
+ }
26714
+ const response = topicId ? await compiler.compile(topicId, input) : await functionSurface.compileContext(input);
26700
26715
  writeLocalLucernContext({
26701
26716
  topicId: readResultString(response.data, "topicId") ?? topicId,
26702
26717
  topicName: readResultString(response.data, "topicName"),
@@ -27802,18 +27817,22 @@ function createWorktreeHandlers(context) {
27802
27817
  MCP_TOOL_CONTRACTS.add_worktree,
27803
27818
  async (params) => {
27804
27819
  const topicId = readTopicId4(params);
27805
- if (!topicId) {
27806
- throw new Error("add_worktree requires topicId");
27807
- }
27808
27820
  const result = await workflow.addWorktree({
27809
27821
  title: readString3(params, "title", { required: true }),
27810
27822
  topicId,
27823
+ topicHint: readString3(params, "topicHint"),
27811
27824
  branchId: readString3(params, "branchId"),
27812
27825
  objective: readString3(params, "objective"),
27813
27826
  hypothesis: readString3(params, "hypothesis"),
27827
+ rationale: readString3(params, "rationale"),
27828
+ worktreeType: readString3(params, "worktreeType"),
27814
27829
  beliefIds: readStringArray(params, "beliefIds"),
27815
27830
  autoShape: readBoolean(params, "autoShape"),
27816
27831
  domainPackId: readString3(params, "domainPackId"),
27832
+ tags: readStringArray(params, "tags"),
27833
+ touchedPaths: readStringArray(params, "touchedPaths"),
27834
+ sourceRef: readString3(params, "sourceRef"),
27835
+ sourceKind: readString3(params, "sourceKind"),
27817
27836
  campaign: typeof params.campaign === "number" ? params.campaign : void 0,
27818
27837
  lane: readString3(params, "lane"),
27819
27838
  laneOrderInCampaign: typeof params.laneOrderInCampaign === "number" ? params.laneOrderInCampaign : void 0,
@@ -27933,8 +27952,8 @@ function loadMcpSdk() {
27933
27952
  try {
27934
27953
  const dynamicRequire = eval("require");
27935
27954
  return dynamicRequire("@modelcontextprotocol/sdk") ?? {};
27936
- } catch {
27937
- return {};
27955
+ } catch (error) {
27956
+ return ignoreMcpSdkLoadError();
27938
27957
  }
27939
27958
  }
27940
27959
  var LUCERN_MCP_RESOURCE_URIS = [
@@ -28022,11 +28041,11 @@ function deriveCustomToolScopes(customTool) {
28022
28041
  return uniqueScopes(customTool.metadata.requiredScopes ?? ["custom:execute"]);
28023
28042
  }
28024
28043
  function createFallbackRuntime() {
28044
+ function noop() {
28045
+ }
28025
28046
  return {
28026
- registerResource: () => {
28027
- },
28028
- registerTool: () => {
28029
- }
28047
+ registerResource: noop,
28048
+ registerTool: noop
28030
28049
  };
28031
28050
  }
28032
28051
  function createMcpRuntime() {
@@ -28040,7 +28059,7 @@ function createMcpRuntime() {
28040
28059
  { name: "lucern-platform-mcp", version: "1.2.0" },
28041
28060
  { capabilities: { resources: {}, tools: {} } }
28042
28061
  );
28043
- } catch {
28062
+ } catch (error) {
28044
28063
  return createFallbackRuntime();
28045
28064
  }
28046
28065
  }
@@ -28064,15 +28083,14 @@ function executeWithHandler(_name, handler, contract, params) {
28064
28083
  }
28065
28084
  }
28066
28085
  function isMcpToolResult(value) {
28067
- if (!value || typeof value !== "object") {
28086
+ if (!isRecord13(value)) {
28068
28087
  return false;
28069
28088
  }
28070
- const candidate = value;
28071
- if (!Array.isArray(candidate.content)) {
28089
+ if (!Array.isArray(value.content)) {
28072
28090
  return false;
28073
28091
  }
28074
- return candidate.content.every((entry) => {
28075
- if (!entry || typeof entry !== "object") {
28092
+ return value.content.every((entry) => {
28093
+ if (!isRecord13(entry)) {
28076
28094
  return false;
28077
28095
  }
28078
28096
  return typeof entry.text === "string";
@@ -28243,6 +28261,12 @@ function createLucernMcpServer(options) {
28243
28261
  unimplementedToolNames
28244
28262
  };
28245
28263
  }
28264
+ function isRecord13(value) {
28265
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
28266
+ }
28267
+ function ignoreMcpSdkLoadError(_error) {
28268
+ return {};
28269
+ }
28246
28270
 
28247
28271
  // src/standalone.ts
28248
28272
  var OBSERVATION_RESOURCE_TEMPLATE = "lucern://observations/topic/{topicId}";
@@ -28284,6 +28308,9 @@ function resourceName(uri) {
28284
28308
  return uri.replace("lucern://", "lucern-").replace(/[{}]/g, "").replace(/[^a-zA-Z0-9]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
28285
28309
  }
28286
28310
  function readTemplateVar(variables, key) {
28311
+ if (!isRecord14(variables)) {
28312
+ return;
28313
+ }
28287
28314
  const value = variables[key];
28288
28315
  if (typeof value === "string") {
28289
28316
  return value;
@@ -28296,7 +28323,7 @@ function readTemplateVar(variables, key) {
28296
28323
  async function notifyResourceUpdated(server, uri) {
28297
28324
  try {
28298
28325
  await server.server.sendResourceUpdated({ uri });
28299
- } catch {
28326
+ } catch (error) {
28300
28327
  }
28301
28328
  }
28302
28329
  function registerResources(server, runtime, observationStore) {
@@ -28357,10 +28384,7 @@ function registerResources(server, runtime, observationStore) {
28357
28384
  mimeType: "application/json"
28358
28385
  },
28359
28386
  async (_uri, variables) => {
28360
- const topicId = readTemplateVar(
28361
- variables,
28362
- "topicId"
28363
- );
28387
+ const topicId = readTemplateVar(variables, "topicId");
28364
28388
  const records = topicId ? observationStore.list(topicId, 25) : [];
28365
28389
  return {
28366
28390
  contents: [
@@ -28393,9 +28417,8 @@ function registerResources(server, runtime, observationStore) {
28393
28417
  mimeType: "application/json"
28394
28418
  },
28395
28419
  async (_uri, variables) => {
28396
- const values = variables;
28397
- const topicId = readTemplateVar(values, "topicId");
28398
- const query5 = readTemplateVar(values, "query");
28420
+ const topicId = readTemplateVar(variables, "topicId");
28421
+ const query5 = readTemplateVar(variables, "query");
28399
28422
  const matches = topicId && query5 ? observationStore.search(topicId, query5, 25) : [];
28400
28423
  return {
28401
28424
  contents: [
@@ -28428,10 +28451,7 @@ function registerResources(server, runtime, observationStore) {
28428
28451
  mimeType: "application/json"
28429
28452
  },
28430
28453
  async (_uri, variables) => {
28431
- const topicId = readTemplateVar(
28432
- variables,
28433
- "topicId"
28434
- );
28454
+ const topicId = readTemplateVar(variables, "topicId");
28435
28455
  const context = topicId ? observationStore.getContext({ topicId, limit: 12 }) : observationStore.getContext({ topicId: "unknown", limit: 12 });
28436
28456
  return {
28437
28457
  contents: [
@@ -28455,9 +28475,8 @@ function registerResources(server, runtime, observationStore) {
28455
28475
  mimeType: "application/json"
28456
28476
  },
28457
28477
  async (_uri, variables) => {
28458
- const values = variables;
28459
- const topicId = readTemplateVar(values, "topicId");
28460
- const query5 = readTemplateVar(values, "query");
28478
+ const topicId = readTemplateVar(variables, "topicId");
28479
+ const query5 = readTemplateVar(variables, "query");
28461
28480
  const context = observationStore.getContext({
28462
28481
  topicId: topicId ?? "unknown",
28463
28482
  query: query5,
@@ -28483,7 +28502,7 @@ function registerResources(server, runtime, observationStore) {
28483
28502
  await notifyResourceUpdated(server, `lucern://context/topic/${encoded}`);
28484
28503
  try {
28485
28504
  await server.server.sendResourceListChanged();
28486
- } catch {
28505
+ } catch (error) {
28487
28506
  }
28488
28507
  };
28489
28508
  return { resourceUris, notifyObservationChanged };
@@ -28523,15 +28542,14 @@ function registerTools(server, runtime) {
28523
28542
  inputSchema: shape
28524
28543
  },
28525
28544
  async (args) => {
28526
- return handler(args, tool.contract);
28545
+ return handler(isRecord14(args) ? args : {}, tool.contract);
28527
28546
  }
28528
28547
  );
28529
28548
  }
28530
28549
  }
28531
28550
  function createLucernStandaloneMcpServer(options) {
28532
28551
  const observationStore = new McpObservationStore();
28533
- let notifyObservationChanged = async () => {
28534
- };
28552
+ let notifyObservationChanged = noopAsync;
28535
28553
  const runtime = createLucernMcpServer({
28536
28554
  ...options,
28537
28555
  observationStore,
@@ -28541,7 +28559,7 @@ function createLucernStandaloneMcpServer(options) {
28541
28559
  });
28542
28560
  const server = new McpServer({
28543
28561
  name: "lucern-mcp",
28544
- version: "0.2.0-alpha.2"
28562
+ version: "0.3.0-alpha.8"
28545
28563
  });
28546
28564
  registerTools(server, runtime);
28547
28565
  const resources = registerResources(server, runtime, observationStore);
@@ -28564,6 +28582,11 @@ async function startLucernMcpStdioServer(options) {
28564
28582
  await packageServer.server.connect(transport);
28565
28583
  return packageServer;
28566
28584
  }
28585
+ function isRecord14(value) {
28586
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
28587
+ }
28588
+ async function noopAsync() {
28589
+ }
28567
28590
 
28568
28591
  // src/remote.ts
28569
28592
  function resolveAuthMode(auth) {
@@ -29215,10 +29238,14 @@ function parseToolJson(result) {
29215
29238
  throw new Error("MCP tool returned no text payload");
29216
29239
  }
29217
29240
  try {
29218
- return JSON.parse(textBlock.text);
29241
+ const parsed = JSON.parse(textBlock.text);
29242
+ if (!isJsonRecord(parsed)) {
29243
+ throw new Error("MCP tool returned non-object JSON payload.");
29244
+ }
29245
+ return parsed;
29219
29246
  } catch (error) {
29220
29247
  throw new Error(
29221
- `Failed to parse MCP tool payload: ${error instanceof Error ? error.message : String(error)}`
29248
+ `Failed to parse MCP tool payload: ${describeUnknownValue(error)}`
29222
29249
  );
29223
29250
  }
29224
29251
  }
@@ -29253,7 +29280,7 @@ async function resolveMcpSessionTenantId() {
29253
29280
  });
29254
29281
  const response = await identity.whoami();
29255
29282
  return typeof response.data?.tenantId === "string" && response.data.tenantId.trim().length > 0 ? response.data.tenantId.trim() : void 0;
29256
- } catch {
29283
+ } catch (error) {
29257
29284
  return void 0;
29258
29285
  }
29259
29286
  }
@@ -29263,13 +29290,41 @@ async function callMcpTool(client, toolName, args) {
29263
29290
  arguments: args
29264
29291
  });
29265
29292
  if (result.isError) {
29266
- throw new Error(`[${toolName}] ${JSON.stringify(result.content || [])}`);
29293
+ throw new Error(`[${toolName}] ${describeUnknownValue(result.content || [])}`);
29267
29294
  }
29268
29295
  return parseToolJson(result);
29269
29296
  }
29270
29297
  async function closeMcpClient(client) {
29271
29298
  await client.close();
29272
29299
  }
29300
+ function isJsonRecord(value) {
29301
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
29302
+ }
29303
+ function describeUnknownValue(value) {
29304
+ if (value instanceof Error) {
29305
+ return `${value.name}: ${value.message}`;
29306
+ }
29307
+ if (typeof value === "string") {
29308
+ return value;
29309
+ }
29310
+ if (typeof value === "number") {
29311
+ return "numeric value";
29312
+ }
29313
+ if (typeof value === "boolean") {
29314
+ return "boolean value";
29315
+ }
29316
+ if (value === null) {
29317
+ return "null value";
29318
+ }
29319
+ if (value === void 0) {
29320
+ return "undefined value";
29321
+ }
29322
+ if (Array.isArray(value)) {
29323
+ return "array value";
29324
+ }
29325
+ const keys = Object.keys(value);
29326
+ return keys.length > 0 ? `object with keys: ${keys.slice(0, 5).join(", ")}` : "object";
29327
+ }
29273
29328
 
29274
29329
  // src/discovery.ts
29275
29330
  async function loadDiscoveryHandlers() {