@lucern/mcp 0.3.0-alpha.6 → 0.3.0-alpha.7

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/cli.js CHANGED
@@ -30,9 +30,29 @@ var __copyProps = (to, from, except, desc) => {
30
30
  };
31
31
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget);
32
32
 
33
+ // ../cli/src/guards.ts
34
+ function isRecord(value) {
35
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
36
+ }
37
+ function formatUnknownError(error) {
38
+ if (error instanceof Error) {
39
+ return error.message;
40
+ }
41
+ if (typeof error === "string") {
42
+ return error;
43
+ }
44
+ return String(error);
45
+ }
46
+
33
47
  // ../cli/src/types.ts
34
48
  var EXIT = {
49
+ ok: 0,
50
+ usage: 2,
51
+ auth: 10,
35
52
  config: 11,
53
+ api: 20,
54
+ invariant: 30,
55
+ local: 40,
36
56
  unexpected: 70
37
57
  };
38
58
  var CliError = class extends Error {
@@ -60,6 +80,34 @@ var CliError = class extends Error {
60
80
  }
61
81
  };
62
82
 
83
+ // ../cli/src/parse.ts
84
+ function parseJsonValue(value, label) {
85
+ try {
86
+ return JSON.parse(value);
87
+ } catch (error) {
88
+ if (error instanceof SyntaxError) {
89
+ throw new CliError({
90
+ code: "USAGE_INVALID_JSON",
91
+ exitCode: EXIT.usage,
92
+ message: `${label} must be valid JSON.`,
93
+ details: formatUnknownError(error)
94
+ });
95
+ }
96
+ throw error;
97
+ }
98
+ }
99
+ function parseJsonRecord(value, label) {
100
+ const parsed = parseJsonValue(value, label);
101
+ if (!isRecord(parsed)) {
102
+ throw new CliError({
103
+ code: "USAGE_INVALID_JSON",
104
+ exitCode: EXIT.usage,
105
+ message: `${label} must be a JSON object.`
106
+ });
107
+ }
108
+ return parsed;
109
+ }
110
+
63
111
  // ../cli/src/config.ts
64
112
  var CONFIG_DIR = ".lucern";
65
113
  var CREDENTIALS_FILE = "credentials";
@@ -172,13 +220,21 @@ function readProfilesFile(path2) {
172
220
  return {};
173
221
  }
174
222
  try {
175
- return JSON.parse(readFileSync(path2, "utf8"));
223
+ const parsed = parseJsonRecord(readFileSync(path2, "utf8"), path2);
224
+ if (!isProfilesFile(parsed)) {
225
+ throw new CliError({
226
+ code: "CONFIG_INVALID_PROFILE_FILE",
227
+ exitCode: EXIT.config,
228
+ message: `${path2} must be a JSON object with profile definitions.`
229
+ });
230
+ }
231
+ return parsed;
176
232
  } catch (error) {
177
233
  throw new CliError({
178
234
  code: "CONFIG_INVALID_PROFILE_FILE",
179
235
  exitCode: EXIT.config,
180
236
  message: `${path2} is not valid JSON.`,
181
- details: error
237
+ details: formatUnknownError(error)
182
238
  });
183
239
  }
184
240
  }
@@ -237,12 +293,32 @@ function stripQuotes(value) {
237
293
  if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
238
294
  try {
239
295
  return JSON.parse(trimmed);
240
- } catch {
241
- return trimmed.slice(1, -1);
296
+ } catch (error) {
297
+ return ignoreQuotedValueParseError(error, trimmed);
242
298
  }
243
299
  }
244
300
  return trimmed;
245
301
  }
302
+ function ignoreQuotedValueParseError(_error, trimmed) {
303
+ return trimmed.slice(1, -1);
304
+ }
305
+ function isProfilesFile(value) {
306
+ if (!isRecord(value)) {
307
+ return false;
308
+ }
309
+ if (value.activeProfile !== void 0 && typeof value.activeProfile !== "string") {
310
+ return false;
311
+ }
312
+ if (value.profiles === void 0) {
313
+ return true;
314
+ }
315
+ if (!isRecord(value.profiles)) {
316
+ return false;
317
+ }
318
+ return Object.values(value.profiles).every(
319
+ (profile) => profile === void 0 || isRecord(profile)
320
+ );
321
+ }
246
322
 
247
323
  // ../contracts/src/graph-intelligence.contract.ts
248
324
  var GRAPH_INTELLIGENCE_QUERY_CATALOG_VERSION = "graph_intelligence_query_catalog.v1";
@@ -5175,6 +5251,11 @@ var TENANT_CLIENT_INSTALLABLE_PACKAGES = [
5175
5251
  role: "sdk_dependency",
5176
5252
  directTenantImport: false
5177
5253
  },
5254
+ {
5255
+ packageName: "@lucern/graph-sync",
5256
+ role: "host_addon_runtime",
5257
+ directTenantImport: true
5258
+ },
5178
5259
  {
5179
5260
  packageName: "@lucern/identity",
5180
5261
  role: "component_runtime",
@@ -5463,8 +5544,11 @@ function compactRecord(input) {
5463
5544
  Object.entries(input).filter(([, value]) => value !== void 0)
5464
5545
  );
5465
5546
  }
5547
+ function isRecord2(value) {
5548
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5549
+ }
5466
5550
  function recordValue(value) {
5467
- return value && typeof value === "object" && !Array.isArray(value) ? value : {};
5551
+ return isRecord2(value) ? value : {};
5468
5552
  }
5469
5553
  var createEvidenceProjection = defineProjection({
5470
5554
  contractName: "create_evidence",
@@ -6170,9 +6254,16 @@ var ADD_WORKTREE = {
6170
6254
  },
6171
6255
  projectId: {
6172
6256
  type: "string",
6173
- description: "Legacy topicId alias"
6257
+ description: "Legacy topicId alias or resolver hint"
6258
+ },
6259
+ topicId: {
6260
+ type: "string",
6261
+ description: "Optional topic scope hint for resolver validation"
6262
+ },
6263
+ topicHint: {
6264
+ type: "string",
6265
+ description: "Natural-language topic hint for automatic topic resolution"
6174
6266
  },
6175
- topicId: { type: "string", description: "Optional topic scope hint" },
6176
6267
  branchId: {
6177
6268
  type: "string",
6178
6269
  description: "The branch this worktree investigates"
@@ -6270,6 +6361,22 @@ var ADD_WORKTREE = {
6270
6361
  type: "string",
6271
6362
  description: "Optional domain pack whose shaping hooks should influence generated questions and tasks"
6272
6363
  },
6364
+ tags: {
6365
+ type: "array",
6366
+ description: "Additional topic-resolution tags for the worktree"
6367
+ },
6368
+ touchedPaths: {
6369
+ type: "array",
6370
+ description: "File paths used as topic-resolution signals"
6371
+ },
6372
+ sourceRef: {
6373
+ type: "string",
6374
+ description: "Source reference used as a topic-resolution signal"
6375
+ },
6376
+ sourceKind: {
6377
+ type: "string",
6378
+ description: "Source kind used as a topic-resolution signal"
6379
+ },
6273
6380
  campaign: {
6274
6381
  type: "number",
6275
6382
  description: "Top-level pipeline campaign number. Campaigns define the outer execution slice."
@@ -6307,7 +6414,7 @@ var ADD_WORKTREE = {
6307
6414
  description: "Timestamp when worktree metadata was last reconciled"
6308
6415
  }
6309
6416
  },
6310
- required: ["title", "topicId"],
6417
+ required: ["title"],
6311
6418
  response: {
6312
6419
  description: "The created worktree",
6313
6420
  fields: {
@@ -8010,18 +8117,60 @@ var CREATE_TASK = {
8010
8117
  name: "create_task",
8011
8118
  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.",
8012
8119
  parameters: {
8013
- title: { type: "string", description: "Task description" },
8120
+ title: { type: "string", description: "Task title" },
8014
8121
  topicId: { type: "string", description: "Topic scope" },
8122
+ description: {
8123
+ type: "string",
8124
+ description: "Long-form task description"
8125
+ },
8015
8126
  taskType: {
8016
8127
  type: "string",
8017
- description: "Type: research, interview, analysis, data_collection",
8018
- enum: ["research", "interview", "analysis", "data_collection"]
8128
+ description: "Task taxonomy",
8129
+ enum: [
8130
+ "general",
8131
+ "find_evidence",
8132
+ "verify_claim",
8133
+ "research",
8134
+ "review",
8135
+ "interview",
8136
+ "analysis",
8137
+ "track_metrics"
8138
+ ]
8139
+ },
8140
+ priority: {
8141
+ type: "string",
8142
+ description: "Priority",
8143
+ enum: ["urgent", "high", "medium", "low"]
8144
+ },
8145
+ status: {
8146
+ type: "string",
8147
+ description: "Initial status (defaults to todo)",
8148
+ enum: ["todo", "in_progress", "blocked", "done"]
8149
+ },
8150
+ linkedWorktreeId: {
8151
+ type: "string",
8152
+ description: "Worktree this task belongs to"
8153
+ },
8154
+ linkedBeliefId: {
8155
+ type: "string",
8156
+ description: "Belief this task supports"
8019
8157
  },
8020
8158
  linkedQuestionId: {
8021
8159
  type: "string",
8022
8160
  description: "Question this task addresses"
8023
8161
  },
8024
- linkedWorktreeId: { type: "string", description: "Worktree scope" }
8162
+ assigneeId: {
8163
+ type: "string",
8164
+ description: "Principal assigned to the task"
8165
+ },
8166
+ dueDate: {
8167
+ type: "number",
8168
+ description: "Due date as epoch milliseconds"
8169
+ },
8170
+ tags: {
8171
+ type: "array",
8172
+ description: "Free-form string tags"
8173
+ }
8025
8174
  },
8026
8175
  required: ["title"],
8027
8176
  response: {
@@ -10116,9 +10265,7 @@ function mcpContractFromArgsSchema(base, args, contractName) {
10116
10265
  required: converted.filter(([, field]) => field.required).map(([fieldName]) => fieldName)
10117
10266
  };
10118
10267
  }
10119
- function defineFunctionContract(contract) {
10120
- return contract;
10121
- }
10268
+ var defineFunctionContract = (contract) => contract;
10122
10269
  function authUserId(context) {
10123
10270
  return context.userId ?? context.principalId ?? "lucern-agent";
10124
10271
  }
@@ -10272,6 +10419,9 @@ var observationContextArgs = z.object({
10272
10419
  limit: z.number().optional().describe("Maximum observations to return."),
10273
10420
  status: z.string().optional().describe("Observation status filter.")
10274
10421
  });
10422
+ function isRecord3(value) {
10423
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
10424
+ }
10275
10425
  var observationInput = (input, context) => withUserId(
10276
10426
  compactRecord4({
10277
10427
  projectId: input.projectId,
@@ -10326,8 +10476,8 @@ var contextContracts = [
10326
10476
  kind: "mutation",
10327
10477
  inputProjection: observationInput,
10328
10478
  outputProjection: (output, input) => ({
10329
- ...output && typeof output === "object" ? output : {},
10330
- observationId: output && typeof output === "object" ? output.nodeId : void 0,
10479
+ ...isRecord3(output) ? output : {},
10480
+ observationId: isRecord3(output) ? output.nodeId : void 0,
10331
10481
  observationType: input.observationType
10332
10482
  })
10333
10483
  },
@@ -11808,10 +11958,11 @@ var worktreeDecisionGateInputSchema = z.object({
11808
11958
  decidedBy: z.string().optional().describe("Actor that decided the gate verdict.")
11809
11959
  }).passthrough().describe("Decision gate contract for worktree activation or exit.");
11810
11960
  var addWorktreeArgs = z.object({
11811
- title: z.string().optional().describe("Human-readable worktree name or objective."),
11961
+ title: z.string().describe("Human-readable worktree name or objective."),
11812
11962
  name: z.string().optional().describe("Storage-name alias for callers that already use backend naming."),
11813
- topicId: z.string().describe("Primary topic scope for the worktree."),
11814
- projectId: z.string().optional().describe("Legacy topicId alias."),
11963
+ topicId: z.string().optional().describe("Optional primary topic scope hint for resolver validation."),
11964
+ projectId: z.string().optional().describe("Legacy topicId alias/hint."),
11965
+ topicHint: z.string().optional().describe("Natural-language topic hint for automatic topic resolution."),
11815
11966
  branchId: z.string().optional().describe("Legacy branch identifier for compatibility with workflow callers."),
11816
11967
  objective: z.string().optional().describe("Reasoning objective this worktree is intended to resolve."),
11817
11968
  hypothesis: z.string().optional().describe("Testable claim this worktree investigates."),
@@ -11836,6 +11987,10 @@ var addWorktreeArgs = z.object({
11836
11987
  autoShape: z.boolean().optional().describe("Whether to invoke inquiry auto-shaping during creation."),
11837
11988
  autoFixPolicy: autoFixPolicyInputSchema.optional(),
11838
11989
  domainPackId: z.string().optional().describe("Domain pack whose shaping hooks should influence the worktree."),
11990
+ tags: z.array(z.string()).optional().describe("Additional topic-resolution tags for the worktree."),
11991
+ touchedPaths: z.array(z.string()).optional().describe("File paths used as topic-resolution signals."),
11992
+ sourceRef: z.string().optional().describe("Source reference used as a topic-resolution signal."),
11993
+ sourceKind: z.string().optional().describe("Source kind used as a topic-resolution signal."),
11839
11994
  campaign: z.number().optional().describe("Top-level pipeline campaign number."),
11840
11995
  lane: z.string().optional().describe("Campaign lane for the worktree."),
11841
11996
  laneOrderInCampaign: z.number().optional().describe("Ordering for this lane within its campaign."),
@@ -12165,8 +12320,46 @@ var worktreesContracts = [
12165
12320
  args: openPullRequestArgs
12166
12321
  })
12167
12322
  ];
12168
-
12169
- // ../contracts/src/function-registry/tasks.ts
12323
+ var taskPrioritySchema = z.enum(["urgent", "high", "medium", "low"]);
12324
+ var taskStatusSchema2 = z.enum(["todo", "in_progress", "blocked", "done"]);
12325
+ var taskTypeSchema = z.enum([
12326
+ "general",
12327
+ "find_evidence",
12328
+ "verify_claim",
12329
+ "research",
12330
+ "review",
12331
+ "interview",
12332
+ "analysis",
12333
+ "track_metrics"
12334
+ ]);
12335
+ var createTaskArgs = z.object({
12336
+ title: z.string().describe("Task title."),
12337
+ topicId: z.string().optional().describe("Topic scope."),
12338
+ description: z.string().optional().describe("Long-form task description."),
12339
+ taskType: taskTypeSchema.optional().describe("Task taxonomy."),
12340
+ priority: taskPrioritySchema.optional().describe("Priority. Defaults to medium when omitted by the server."),
12341
+ status: taskStatusSchema2.optional().describe("Initial status. Defaults to todo."),
12342
+ linkedWorktreeId: z.string().optional().describe("Worktree this task belongs to."),
12343
+ linkedBeliefId: z.string().optional().describe("Belief this task supports."),
12344
+ linkedQuestionId: z.string().optional().describe("Question this task addresses."),
12345
+ assigneeId: z.string().optional().describe("Principal assigned to the task."),
12346
+ dueDate: z.number().optional().describe("Due date as epoch milliseconds."),
12347
+ tags: z.array(z.string()).optional().describe("Free-form tags.")
12348
+ });
12349
+ var createTaskInput = (input) => compactRecord4({
12350
+ title: input.title,
12351
+ topicId: input.topicId,
12352
+ description: input.description,
12353
+ taskType: input.taskType,
12354
+ priority: input.priority ?? "medium",
12355
+ status: input.status ?? "todo",
12356
+ linkedWorktreeId: input.linkedWorktreeId,
12357
+ linkedBeliefId: input.linkedBeliefId,
12358
+ linkedQuestionId: input.linkedQuestionId,
12359
+ assigneeId: input.assigneeId,
12360
+ dueDate: input.dueDate,
12361
+ tags: input.tags
12362
+ });
12170
12363
  var taskInput = (input) => compactRecord4({
12171
12364
  ...input,
12172
12365
  taskId: input.taskId ?? input.id
@@ -12198,8 +12391,10 @@ var tasksContracts = [
12198
12391
  convex: {
12199
12392
  module: "tasks",
12200
12393
  functionName: "create",
12201
- kind: "mutation"
12202
- }
12394
+ kind: "mutation",
12395
+ inputProjection: createTaskInput
12396
+ },
12397
+ args: createTaskArgs
12203
12398
  }),
12204
12399
  surfaceContract({
12205
12400
  name: "list_tasks",
@@ -13318,9 +13513,12 @@ var ALL_FUNCTION_CONTRACTS = [
13318
13513
  ];
13319
13514
  assertSurfaceCoverage(ALL_FUNCTION_CONTRACTS);
13320
13515
  var FUNCTION_SURFACE_CONTRACTS = ALL_FUNCTION_CONTRACTS;
13321
- new Map(
13516
+ var FUNCTION_CONTRACTS_BY_NAME = new Map(
13322
13517
  ALL_FUNCTION_CONTRACTS.map((contract) => [contract.name, contract])
13323
13518
  );
13519
+ FUNCTION_CONTRACTS_BY_NAME.get.bind(
13520
+ FUNCTION_CONTRACTS_BY_NAME
13521
+ );
13324
13522
 
13325
13523
  // ../contracts/src/tenant-bootstrap-seed.contract.ts
13326
13524
  function isCopyableSeedRequirement(entry) {
@@ -13966,10 +14164,18 @@ function isInfisicalRuntimeDisabled(env = {}) {
13966
14164
  }
13967
14165
  async function hydrateInfisicalRuntimeEnv(options) {
13968
14166
  const env = options.env ?? {};
13969
- const bootstrap = mergeBootstrap(
13970
- readInfisicalRuntimeBootstrap(env, options.bootstrap),
13971
- options.bootstrap
13972
- );
14167
+ const baseBootstrap = readInfisicalRuntimeBootstrap(env, options.bootstrap);
14168
+ const bootstrap = baseBootstrap ? {
14169
+ ...baseBootstrap,
14170
+ ...Object.fromEntries(
14171
+ Object.entries(options.bootstrap ?? {}).filter(
14172
+ ([, value]) => value !== void 0
14173
+ )
14174
+ ),
14175
+ apiUrl: trimTrailingSlash(
14176
+ options.bootstrap?.apiUrl ?? baseBootstrap.apiUrl
14177
+ )
14178
+ } : null;
13973
14179
  if (!bootstrap) {
13974
14180
  return {
13975
14181
  status: "disabled",
@@ -14065,16 +14271,6 @@ function normalizeInfisicalEnvironment(value) {
14065
14271
  }
14066
14272
  return "prod";
14067
14273
  }
14068
- function mergeBootstrap(base, overrides) {
14069
- if (!base) {
14070
- return null;
14071
- }
14072
- return {
14073
- ...base,
14074
- ...compact(overrides ?? {}),
14075
- apiUrl: trimTrailingSlash(overrides?.apiUrl ?? base.apiUrl)
14076
- };
14077
- }
14078
14274
  async function loginWithUniversalAuth(bootstrap, fetchImpl) {
14079
14275
  const response = await fetchImpl(
14080
14276
  `${trimTrailingSlash(bootstrap.apiUrl)}/api/v1/auth/universal-auth/login`,
@@ -14159,14 +14355,18 @@ async function readSecretValue(args) {
14159
14355
  async function readJson(response) {
14160
14356
  try {
14161
14357
  return await response.json();
14162
- } catch {
14358
+ } catch (error) {
14359
+ debugInfisicalRuntimeFallback("response.json", error);
14163
14360
  return void 0;
14164
14361
  }
14165
14362
  }
14363
+ function isRecord4(value) {
14364
+ return value !== null && typeof value === "object" && !Array.isArray(value);
14365
+ }
14166
14366
  function readNestedString(value, path2) {
14167
14367
  let current = value;
14168
14368
  for (const key of path2) {
14169
- if (!current || typeof current !== "object" || !(key in current)) {
14369
+ if (!isRecord4(current) || !(key in current)) {
14170
14370
  return null;
14171
14371
  }
14172
14372
  current = current[key];
@@ -14174,13 +14374,12 @@ function readNestedString(value, path2) {
14174
14374
  return typeof current === "string" && current.length > 0 ? current : null;
14175
14375
  }
14176
14376
  function messageFromBody(body4) {
14177
- if (!body4 || typeof body4 !== "object") {
14377
+ if (!isRecord4(body4)) {
14178
14378
  return "no response body";
14179
14379
  }
14180
- const record = body4;
14181
14380
  for (const key of ["message", "error", "errorMessage"]) {
14182
- if (typeof record[key] === "string") {
14183
- return record[key];
14381
+ if (typeof body4[key] === "string") {
14382
+ return body4[key];
14184
14383
  }
14185
14384
  }
14186
14385
  return JSON.stringify(body4);
@@ -14200,10 +14399,32 @@ function isTruthyEnv(value) {
14200
14399
  function trimTrailingSlash(value) {
14201
14400
  return value.replace(/\/+$/u, "");
14202
14401
  }
14203
- function compact(value) {
14204
- return Object.fromEntries(
14205
- Object.entries(value).filter(([, entry]) => entry !== void 0)
14206
- );
14402
+ function debugInfisicalRuntimeFallback(message, error) {
14403
+ const env = globalThis.process?.env;
14404
+ if (env?.LUCERN_COMPAT_FALLBACK_DEBUG !== "1" && env?.LUCERN_INFISICAL_RUNTIME_DEBUG !== "1") {
14405
+ return;
14406
+ }
14407
+ console.debug(`[infisical-runtime] ${message}`, {
14408
+ error: formatInfisicalRuntimeError(error)
14409
+ });
14410
+ }
14411
+ function formatInfisicalRuntimeError(error) {
14412
+ if (error instanceof Error) {
14413
+ return `${error.name}: ${error.message}`;
14414
+ }
14415
+ if (typeof error === "string") {
14416
+ return error;
14417
+ }
14418
+ if (typeof error === "number" || typeof error === "boolean") {
14419
+ return String(error);
14420
+ }
14421
+ if (error && typeof error === "object") {
14422
+ const keys = Object.keys(error).slice(0, 5);
14423
+ if (keys.length > 0) {
14424
+ return `Unknown Infisical runtime error object with keys: ${keys.join(", ")}`;
14425
+ }
14426
+ }
14427
+ return "Unknown Infisical runtime error shape";
14207
14428
  }
14208
14429
 
14209
14430
  // src/infisical-runtime.ts
@@ -14560,6 +14781,7 @@ __export(src_exports, {
14560
14781
  WORKTREE_PHASES: () => WORKTREE_PHASES,
14561
14782
  applyInfisicalRuntimeEnv: () => applyInfisicalRuntimeEnv,
14562
14783
  asListItems: () => asListItems,
14784
+ asRecord: () => asRecord,
14563
14785
  assertValidWebhookSecret: () => assertValidWebhookSecret,
14564
14786
  assertValidWebhookUrl: () => assertValidWebhookUrl,
14565
14787
  buildDeprecatedBranchMetadata: () => buildDeprecatedBranchMetadata,
@@ -14631,6 +14853,7 @@ __export(src_exports, {
14631
14853
  isLensFilterCriteria: () => isLensFilterCriteria2,
14632
14854
  isLucernPrompt: () => isLucernPrompt,
14633
14855
  isMcpToolAllowed: () => isMcpToolAllowed,
14856
+ isRecord: () => isRecord6,
14634
14857
  isTaxonomyFilterCriteriaV1: () => isTaxonomyFilterCriteriaV12,
14635
14858
  lastDelegator: () => lastDelegator,
14636
14859
  listControlObjectOwnershipCases: () => listControlObjectOwnershipCases,
@@ -14940,9 +15163,7 @@ function generatePortableRequestId() {
14940
15163
  8
14941
15164
  ).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10).join("")}`;
14942
15165
  }
14943
- function randomIdempotencyKey() {
14944
- return generatePortableRequestId();
14945
- }
15166
+ var randomIdempotencyKey = generatePortableRequestId;
14946
15167
  function isRetryableStatus(status) {
14947
15168
  return status >= 500 || status === 408 || status === 429;
14948
15169
  }
@@ -15007,8 +15228,11 @@ function timeoutError(timeoutMs) {
15007
15228
  error.name = "AbortError";
15008
15229
  return error;
15009
15230
  }
15231
+ function isRecord5(value) {
15232
+ return value !== null && typeof value === "object" && !Array.isArray(value);
15233
+ }
15010
15234
  function readPolicySummaryFromDetails(details) {
15011
- if (!details || typeof details !== "object" || Array.isArray(details)) {
15235
+ if (!isRecord5(details)) {
15012
15236
  return null;
15013
15237
  }
15014
15238
  const directSummary = details.summary;
@@ -15016,11 +15240,11 @@ function readPolicySummaryFromDetails(details) {
15016
15240
  return directSummary.trim();
15017
15241
  }
15018
15242
  const policy = details.policy;
15019
- if (!policy || typeof policy !== "object" || Array.isArray(policy)) {
15243
+ if (!isRecord5(policy)) {
15020
15244
  return null;
15021
15245
  }
15022
15246
  const explanation = policy.explanation;
15023
- if (!explanation || typeof explanation !== "object" || Array.isArray(explanation)) {
15247
+ if (!isRecord5(explanation)) {
15024
15248
  return null;
15025
15249
  }
15026
15250
  const nestedSummary = explanation.summary;
@@ -15084,11 +15308,11 @@ function createGatewayRequestClient(config = {}) {
15084
15308
  if (!text) {
15085
15309
  return null;
15086
15310
  }
15087
- try {
15088
- return JSON.parse(text);
15089
- } catch {
15311
+ const parsed = tryParseGatewayEnvelopeJson(text);
15312
+ if (!parsed.ok) {
15090
15313
  return null;
15091
15314
  }
15315
+ return isRecord5(parsed.value) ? parsed.value : null;
15092
15316
  }
15093
15317
  function resolveTimeoutMs(method, requestTimeoutMs) {
15094
15318
  if (typeof requestTimeoutMs === "number") {
@@ -15100,16 +15324,31 @@ function createGatewayRequestClient(config = {}) {
15100
15324
  }
15101
15325
  return config.timeoutMs ?? 15e3;
15102
15326
  }
15327
+ function tryParseGatewayEnvelopeJson(text) {
15328
+ const trimmed = text.trim();
15329
+ if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) {
15330
+ return { ok: false, reason: "non-json" };
15331
+ }
15332
+ try {
15333
+ return { ok: true, value: JSON.parse(trimmed) };
15334
+ } catch (error) {
15335
+ if (error instanceof SyntaxError) {
15336
+ return { ok: false, reason: "invalid-json", error };
15337
+ }
15338
+ throw error;
15339
+ }
15340
+ }
15103
15341
  function buildApiError(args) {
15104
15342
  const failure = args.failure;
15105
- const legacyError = failure && typeof failure.error === "object" && failure.error !== null ? failure.error : failure?.legacyError;
15343
+ const legacyError = failure && isRecord5(failure.error) ? failure.error : failure?.legacyError;
15106
15344
  const correlationId = failure?.correlationId ?? args.response.headers.get("x-lucern-correlation-id")?.trim() ?? args.requestId;
15107
15345
  const policyTraceId = failure?.policyTraceId ?? args.response.headers.get("x-lucern-policy-trace-id")?.trim() ?? null;
15108
15346
  const details = failure?.details ?? legacyError?.details;
15109
15347
  const policySummary = readPolicySummaryFromDetails(details);
15348
+ const failureMessage = typeof failure?.error === "string" ? failure.error : legacyError?.message;
15110
15349
  return new LucernApiError({
15111
15350
  code: failure?.code ?? legacyError?.code ?? fallbackErrorCode(args.response.status),
15112
- message: policySummary ?? (typeof failure?.error === "string" ? failure.error : legacyError?.message ?? (args.response.ok ? "Platform API returned an invalid success payload." : "Platform API request failed.")),
15351
+ message: policySummary ?? failureMessage ?? (args.response.ok ? "Platform API returned an invalid success payload." : "Platform API request failed."),
15113
15352
  status: args.response.status,
15114
15353
  invariant: failure?.invariant,
15115
15354
  suggestion: failure?.suggestion,
@@ -15235,8 +15474,11 @@ function createGatewayRequestClient(config = {}) {
15235
15474
  }
15236
15475
 
15237
15476
  // ../sdk/src/sdkSurface.ts
15477
+ function isRecord6(value) {
15478
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
15479
+ }
15238
15480
  function asRecord(value) {
15239
- return value && typeof value === "object" ? value : {};
15481
+ return isRecord6(value) ? value : {};
15240
15482
  }
15241
15483
  function cleanString2(value) {
15242
15484
  return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
@@ -15297,9 +15539,7 @@ function normalizeNodeWriteInput(value) {
15297
15539
  }
15298
15540
  return next;
15299
15541
  }
15300
- function normalizeNodeVerificationStatus(value) {
15301
- return normalizeVerificationStatus(value);
15302
- }
15542
+ var normalizeNodeVerificationStatus = normalizeVerificationStatus;
15303
15543
  function normalizeTopicQuery(value) {
15304
15544
  const topicId = cleanString2(value.topicId);
15305
15545
  if (!topicId) {
@@ -15326,7 +15566,10 @@ function createListResult(items, legacyKey) {
15326
15566
  total: items.length
15327
15567
  };
15328
15568
  if (legacyKey) {
15329
- result[legacyKey] = items;
15569
+ return {
15570
+ ...result,
15571
+ [legacyKey]: items
15572
+ };
15330
15573
  }
15331
15574
  return result;
15332
15575
  }
@@ -15370,6 +15613,17 @@ function asTenantVaultSecretArray(data) {
15370
15613
  }
15371
15614
  function createAdminClient(config = {}) {
15372
15615
  const gateway = createGatewayRequestClient(config);
15616
+ const getControlObjectOwnership = async () => gateway.request({
15617
+ path: "/api/platform/v1/admin/control-ownership"
15618
+ });
15619
+ const createMembership = async (input, idempotencyKey) => gateway.request({
15620
+ path: "/api/platform/v1/memberships",
15621
+ method: "POST",
15622
+ body: input,
15623
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
15624
+ });
15625
+ const updateMembership = createMembership;
15626
+ const upsertMembership = createMembership;
15373
15627
  return {
15374
15628
  /**
15375
15629
  * List tenants visible to the current principal.
@@ -15401,19 +15655,11 @@ function createAdminClient(config = {}) {
15401
15655
  /**
15402
15656
  * Get the control-object ownership contract.
15403
15657
  */
15404
- async getControlObjectOwnership() {
15405
- return gateway.request({
15406
- path: "/api/platform/v1/admin/control-ownership"
15407
- });
15408
- },
15658
+ getControlObjectOwnership,
15409
15659
  /**
15410
15660
  * @deprecated Use getControlObjectOwnership.
15411
15661
  */
15412
- async getControlObjectOwnershipContract() {
15413
- return gateway.request({
15414
- path: "/api/platform/v1/admin/control-ownership"
15415
- });
15416
- },
15662
+ getControlObjectOwnershipContract: getControlObjectOwnership,
15417
15663
  /**
15418
15664
  * List workspaces for the current admin scope.
15419
15665
  */
@@ -15460,26 +15706,15 @@ function createAdminClient(config = {}) {
15460
15706
  /**
15461
15707
  * Create a membership.
15462
15708
  */
15463
- async createMembership(input, idempotencyKey) {
15464
- return gateway.request({
15465
- path: "/api/platform/v1/memberships",
15466
- method: "POST",
15467
- body: input,
15468
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
15469
- });
15470
- },
15709
+ createMembership,
15471
15710
  /**
15472
15711
  * Update a membership.
15473
15712
  */
15474
- async updateMembership(input, idempotencyKey) {
15475
- return this.createMembership(input, idempotencyKey);
15476
- },
15713
+ updateMembership,
15477
15714
  /**
15478
15715
  * @deprecated Use createMembership or updateMembership.
15479
15716
  */
15480
- async upsertMembership(input, idempotencyKey) {
15481
- return this.createMembership(input, idempotencyKey);
15482
- },
15717
+ upsertMembership,
15483
15718
  /**
15484
15719
  * List tenant API keys in the current admin scope.
15485
15720
  */
@@ -15761,115 +15996,111 @@ function createAnswersClient(config = {}) {
15761
15996
  // ../sdk/src/audiencesClient.ts
15762
15997
  function createAudiencesClient(config = {}) {
15763
15998
  const gateway = createGatewayRequestClient(config);
15999
+ const listRegistry = async (query5 = {}) => {
16000
+ return gateway.request({
16001
+ path: `/api/platform/v1/audiences/registry${toQueryString({
16002
+ ...query5,
16003
+ effective: typeof query5.effective === "boolean" ? query5.effective ? "true" : "false" : void 0,
16004
+ status: query5.status
16005
+ })}`
16006
+ }).then(
16007
+ (response) => mapGatewayData(
16008
+ response,
16009
+ (data) => createListResult(Array.isArray(data) ? data : [], "registryEntries")
16010
+ )
16011
+ );
16012
+ };
16013
+ const createRegistryEntry = async (input, idempotencyKey) => {
16014
+ return gateway.request({
16015
+ path: "/api/platform/v1/audiences/registry",
16016
+ method: "POST",
16017
+ body: input,
16018
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
16019
+ });
16020
+ };
16021
+ const updateRegistryEntry = createRegistryEntry;
16022
+ const upsertRegistry = createRegistryEntry;
16023
+ const getRegistry = listRegistry;
16024
+ const listGrants = async (query5 = {}) => {
16025
+ return gateway.request({
16026
+ path: `/api/platform/v1/audiences/grants${toQueryString({
16027
+ ...query5,
16028
+ audienceKey: query5.audienceKey,
16029
+ principalId: query5.principalId,
16030
+ groupId: query5.groupId,
16031
+ status: query5.status
16032
+ })}`
16033
+ }).then(
16034
+ (response) => mapGatewayData(
16035
+ response,
16036
+ (data) => createListResult(Array.isArray(data) ? data : [], "grants")
16037
+ )
16038
+ );
16039
+ };
16040
+ const createGrant = async (input, idempotencyKey) => {
16041
+ return gateway.request({
16042
+ path: "/api/platform/v1/audiences/grants",
16043
+ method: "POST",
16044
+ body: input,
16045
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
16046
+ });
16047
+ };
16048
+ const getGrants = listGrants;
16049
+ const grant = createGrant;
16050
+ const deleteGrant = async (input, idempotencyKey) => {
16051
+ return gateway.request({
16052
+ path: "/api/platform/v1/audiences/grants/revoke",
16053
+ method: "POST",
16054
+ body: input,
16055
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
16056
+ });
16057
+ };
16058
+ const revokeGrant = deleteGrant;
15764
16059
  return {
15765
16060
  /**
15766
16061
  * List audience registry entries.
15767
16062
  */
15768
- async listRegistry(query5 = {}) {
15769
- return gateway.request({
15770
- path: `/api/platform/v1/audiences/registry${toQueryString({
15771
- ...query5,
15772
- effective: typeof query5.effective === "boolean" ? query5.effective ? "true" : "false" : void 0,
15773
- status: query5.status
15774
- })}`
15775
- }).then(
15776
- (response) => mapGatewayData(
15777
- response,
15778
- (data) => createListResult(
15779
- Array.isArray(data) ? data : [],
15780
- "registryEntries"
15781
- )
15782
- )
15783
- );
15784
- },
16063
+ listRegistry,
15785
16064
  /**
15786
16065
  * @deprecated Use listRegistry.
15787
16066
  */
15788
- async getRegistry(query5 = {}) {
15789
- return this.listRegistry(query5);
15790
- },
16067
+ getRegistry,
15791
16068
  /**
15792
16069
  * Create an audience registry entry.
15793
16070
  */
15794
- async createRegistryEntry(input, idempotencyKey) {
15795
- return gateway.request({
15796
- path: "/api/platform/v1/audiences/registry",
15797
- method: "POST",
15798
- body: input,
15799
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
15800
- });
15801
- },
16071
+ createRegistryEntry,
15802
16072
  /**
15803
16073
  * Update an audience registry entry.
15804
16074
  */
15805
- async updateRegistryEntry(input, idempotencyKey) {
15806
- return this.createRegistryEntry(input, idempotencyKey);
15807
- },
16075
+ updateRegistryEntry,
15808
16076
  /**
15809
16077
  * @deprecated Use createRegistryEntry or updateRegistryEntry.
15810
16078
  */
15811
- async upsertRegistry(input, idempotencyKey) {
15812
- return this.createRegistryEntry(input, idempotencyKey);
15813
- },
16079
+ upsertRegistry,
15814
16080
  /**
15815
16081
  * List audience grants.
15816
16082
  */
15817
- async listGrants(query5 = {}) {
15818
- return gateway.request({
15819
- path: `/api/platform/v1/audiences/grants${toQueryString({
15820
- ...query5,
15821
- audienceKey: query5.audienceKey,
15822
- principalId: query5.principalId,
15823
- groupId: query5.groupId,
15824
- status: query5.status
15825
- })}`
15826
- }).then(
15827
- (response) => mapGatewayData(
15828
- response,
15829
- (data) => createListResult(Array.isArray(data) ? data : [], "grants")
15830
- )
15831
- );
15832
- },
16083
+ listGrants,
15833
16084
  /**
15834
16085
  * @deprecated Use listGrants.
15835
16086
  */
15836
- async getGrants(query5 = {}) {
15837
- return this.listGrants(query5);
15838
- },
16087
+ getGrants,
15839
16088
  /**
15840
16089
  * Create an audience grant.
15841
16090
  */
15842
- async createGrant(input, idempotencyKey) {
15843
- return gateway.request({
15844
- path: "/api/platform/v1/audiences/grants",
15845
- method: "POST",
15846
- body: input,
15847
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
15848
- });
15849
- },
16091
+ createGrant,
15850
16092
  /**
15851
16093
  * @deprecated Use createGrant.
15852
16094
  */
15853
- async grant(input, idempotencyKey) {
15854
- return this.createGrant(input, idempotencyKey);
15855
- },
16095
+ grant,
15856
16096
  /**
15857
16097
  * Delete an audience grant by revoking it.
15858
16098
  */
15859
- async deleteGrant(input, idempotencyKey) {
15860
- return gateway.request({
15861
- path: "/api/platform/v1/audiences/grants/revoke",
15862
- method: "POST",
15863
- body: input,
15864
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
15865
- });
15866
- },
16099
+ deleteGrant,
15867
16100
  /**
15868
16101
  * @deprecated Use deleteGrant.
15869
16102
  */
15870
- async revokeGrant(input, idempotencyKey) {
15871
- return this.deleteGrant(input, idempotencyKey);
15872
- }
16103
+ revokeGrant
15873
16104
  };
15874
16105
  }
15875
16106
 
@@ -15910,8 +16141,18 @@ function authBaseUrl(config) {
15910
16141
  return config.baseUrl?.replace(/\/+$/, "") ?? "";
15911
16142
  }
15912
16143
  async function readJson2(response) {
15913
- const payload = await response.json().catch(() => ({}));
15914
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
16144
+ try {
16145
+ const payload = await response.json();
16146
+ return isRecord7(payload) ? payload : {};
16147
+ } catch (error) {
16148
+ return unreadableJsonBodyFallback();
16149
+ }
16150
+ }
16151
+ function unreadableJsonBodyFallback(_error) {
16152
+ return {};
16153
+ }
16154
+ function isRecord7(value) {
16155
+ return value !== null && typeof value === "object" && !Array.isArray(value);
15915
16156
  }
15916
16157
  function readString(value) {
15917
16158
  const normalized = typeof value === "string" ? value.trim() : "";
@@ -15953,7 +16194,10 @@ function assertDeviceTokenResponse(payload) {
15953
16194
  tenant_id: tenantId,
15954
16195
  workspace_id: readString(payload.workspace_id),
15955
16196
  principal_id: principalId,
15956
- user: payload.user && typeof payload.user === "object" && !Array.isArray(payload.user) ? payload.user : void 0
16197
+ user: isRecord7(payload.user) && typeof payload.user.id === "string" && typeof payload.user.principalId === "string" ? {
16198
+ id: payload.user.id,
16199
+ principalId: payload.user.principalId
16200
+ } : void 0
15957
16201
  };
15958
16202
  }
15959
16203
  function maybeThrowDeviceError(payload) {
@@ -16101,12 +16345,12 @@ function createBeliefsClient(config = {}) {
16101
16345
  body: normalizeModulateConfidenceInput(input),
16102
16346
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
16103
16347
  });
16104
- async function getOpinionHistory(beliefId) {
16348
+ const getOpinionHistory = async (beliefId) => {
16105
16349
  const response = await gateway.request({
16106
16350
  path: `/api/platform/v1/beliefs/${encodeURIComponent(beliefId)}/confidence-history`
16107
16351
  });
16108
16352
  return mapOpinionHistoryEntriesFromGatewayData(response.data);
16109
- }
16353
+ };
16110
16354
  return {
16111
16355
  /**
16112
16356
  * Create a belief within a topic scope.
@@ -16151,13 +16395,9 @@ function createBeliefsClient(config = {}) {
16151
16395
  * trigger = cause of the score change
16152
16396
  * triggeringRef = optional pointer to the evidence or worktree that drove the change
16153
16397
  */
16154
- async getOpinionHistory(beliefId) {
16155
- return getOpinionHistory(beliefId);
16156
- },
16398
+ getOpinionHistory,
16157
16399
  /** @deprecated Use getOpinionHistory(). */
16158
- async getConfidenceHistory(beliefId) {
16159
- return getOpinionHistory(beliefId);
16160
- },
16400
+ getConfidenceHistory: getOpinionHistory,
16161
16401
  /**
16162
16402
  * Fork a scored belief into a new formulation.
16163
16403
  */
@@ -16305,6 +16545,9 @@ function cleanOptionalString(value) {
16305
16545
  const normalized = value?.trim();
16306
16546
  return normalized ? normalized : void 0;
16307
16547
  }
16548
+ function isRecord8(value) {
16549
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
16550
+ }
16308
16551
  function cleanRequiredString(value, label) {
16309
16552
  const normalized = cleanOptionalString(value);
16310
16553
  if (!normalized) {
@@ -16344,9 +16587,10 @@ function topicPayload(input, allowed, operation) {
16344
16587
  };
16345
16588
  }
16346
16589
  function listResultFromEnvelope(data, legacyKey) {
16347
- const record = data && typeof data === "object" ? data : {};
16590
+ const record = isRecord8(data) ? data : {};
16591
+ const legacyItems = record[legacyKey];
16348
16592
  return createListResult(
16349
- Array.isArray(record[legacyKey]) ? record[legacyKey] : Array.isArray(data) ? data : [],
16593
+ Array.isArray(legacyItems) ? legacyItems : Array.isArray(data) ? data : [],
16350
16594
  legacyKey
16351
16595
  );
16352
16596
  }
@@ -16718,7 +16962,7 @@ async function invokeRegisteredCustomTool(fullName, params, context) {
16718
16962
  // ../sdk/src/ontologyClient.ts
16719
16963
  function createOntologyClient(config = {}) {
16720
16964
  const gateway = createGatewayRequestClient(config);
16721
- return {
16965
+ const client = {
16722
16966
  /**
16723
16967
  * List ontology definitions matching optional filters.
16724
16968
  */
@@ -16727,13 +16971,14 @@ function createOntologyClient(config = {}) {
16727
16971
  path: `/api/platform/v1/ontologies${toQueryString(filters)}`
16728
16972
  }).then(
16729
16973
  (response) => mapGatewayData(response, (data) => {
16730
- const record = data && typeof data === "object" && !Array.isArray(data) ? data : {};
16731
- const ontologies = Array.isArray(record.ontologies) ? record.ontologies : Array.isArray(record.definitions) ? record.definitions : Array.isArray(data) ? data : [];
16732
- const total = typeof record.total === "number" && Number.isFinite(record.total) ? record.total : ontologies.length;
16974
+ const record = asRecord(data);
16975
+ const ontologies = asListItems(data, "ontologies");
16976
+ const definitions = ontologies.length > 0 ? ontologies : asListItems(data, "definitions");
16977
+ const total = typeof record.total === "number" && Number.isFinite(record.total) ? record.total : definitions.length;
16733
16978
  return {
16734
16979
  ...record,
16735
- ...createListResult(ontologies, "definitions"),
16736
- ontologies,
16980
+ ...createListResult(definitions, "definitions"),
16981
+ ontologies: definitions,
16737
16982
  total
16738
16983
  };
16739
16984
  })
@@ -16760,18 +17005,6 @@ function createOntologyClient(config = {}) {
16760
17005
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
16761
17006
  });
16762
17007
  },
16763
- /**
16764
- * List ontology definitions.
16765
- */
16766
- async listDefinitions(filters = {}) {
16767
- return this.list(filters);
16768
- },
16769
- /**
16770
- * Get an ontology definition.
16771
- */
16772
- async getDefinition(id) {
16773
- return this.get(id);
16774
- },
16775
17008
  /**
16776
17009
  * Create an ontology definition.
16777
17010
  */
@@ -16813,7 +17046,7 @@ function createOntologyClient(config = {}) {
16813
17046
  }).then(
16814
17047
  (response) => mapGatewayData(
16815
17048
  response,
16816
- (data) => createListResult(Array.isArray(data) ? data : [], "versions")
17049
+ (data) => createListResult(asListItems(data, "versions"), "versions")
16817
17050
  )
16818
17051
  );
16819
17052
  },
@@ -16861,20 +17094,19 @@ function createOntologyClient(config = {}) {
16861
17094
  (data) => createListResult(Array.isArray(data) ? data : [], "topics")
16862
17095
  )
16863
17096
  );
16864
- },
16865
- /**
16866
- * @deprecated Use listTopics.
16867
- */
16868
- async listTopicsByOntology(ontologyId) {
16869
- return this.listTopics(ontologyId);
16870
17097
  }
16871
17098
  };
17099
+ return Object.assign(client, {
17100
+ listDefinitions: client.list,
17101
+ getDefinition: client.get,
17102
+ listTopicsByOntology: client.listTopics
17103
+ });
16872
17104
  }
16873
17105
 
16874
17106
  // ../sdk/src/graphClient.ts
16875
17107
  function createGraphClient(config = {}) {
16876
17108
  const gateway = createGatewayRequestClient(config);
16877
- return {
17109
+ const client = {
16878
17110
  /**
16879
17111
  * List graph nodes matching the provided filters.
16880
17112
  */
@@ -16887,12 +17119,6 @@ function createGraphClient(config = {}) {
16887
17119
  (response) => mapGatewayData(response, (data) => mapAliasedList(data, "nodes"))
16888
17120
  );
16889
17121
  },
16890
- /**
16891
- * @deprecated Use listNodes.
16892
- */
16893
- async queryNodes(query5) {
16894
- return this.listNodes(query5);
16895
- },
16896
17122
  /**
16897
17123
  * Retrieve a single graph node by nodeId or globalId.
16898
17124
  */
@@ -17003,12 +17229,6 @@ function createGraphClient(config = {}) {
17003
17229
  )
17004
17230
  );
17005
17231
  },
17006
- /**
17007
- * @deprecated Use listEdges.
17008
- */
17009
- async queryEdges(query5) {
17010
- return this.listEdges(query5);
17011
- },
17012
17232
  /**
17013
17233
  * Create a graph edge.
17014
17234
  */
@@ -17096,12 +17316,6 @@ function createGraphClient(config = {}) {
17096
17316
  body: normalizeTopicQuery(query5)
17097
17317
  });
17098
17318
  },
17099
- /**
17100
- * Retrieve a graph neighborhood around a root node.
17101
- */
17102
- async getNeighborhood(query5) {
17103
- return this.neighborhood(query5);
17104
- },
17105
17319
  /**
17106
17320
  * Retrieve the shortest known path between two graph nodes.
17107
17321
  */
@@ -17119,6 +17333,11 @@ function createGraphClient(config = {}) {
17119
17333
  });
17120
17334
  }
17121
17335
  };
17336
+ return Object.assign(client, {
17337
+ queryNodes: client.listNodes,
17338
+ queryEdges: client.listEdges,
17339
+ getNeighborhood: client.neighborhood
17340
+ });
17122
17341
  }
17123
17342
 
17124
17343
  // ../sdk/src/identityClient.ts
@@ -17172,6 +17391,13 @@ function createIdentityClient(config = {}) {
17172
17391
  body: input,
17173
17392
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
17174
17393
  });
17394
+ const updatePrincipal = (input, idempotencyKey) => requestPrincipalWrite("PATCH", input, idempotencyKey);
17395
+ const deleteKey = (keyId, input = {}, idempotencyKey) => gateway.request({
17396
+ path: `/api/platform/v1/identity/keys/${encodeURIComponent(keyId)}/revoke`,
17397
+ method: "POST",
17398
+ body: input,
17399
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
17400
+ });
17175
17401
  return {
17176
17402
  /**
17177
17403
  * Resolve the current authenticated identity summary.
@@ -17220,15 +17446,11 @@ function createIdentityClient(config = {}) {
17220
17446
  /**
17221
17447
  * Update a principal.
17222
17448
  */
17223
- async updatePrincipal(input, idempotencyKey) {
17224
- return requestPrincipalWrite("PATCH", input, idempotencyKey);
17225
- },
17449
+ updatePrincipal,
17226
17450
  /**
17227
17451
  * @deprecated Use createPrincipal or updatePrincipal.
17228
17452
  */
17229
- async upsertPrincipal(input, idempotencyKey) {
17230
- return requestPrincipalWrite("PATCH", input, idempotencyKey);
17231
- },
17453
+ upsertPrincipal: updatePrincipal,
17232
17454
  /**
17233
17455
  * List keys in the current identity scope.
17234
17456
  */
@@ -17267,20 +17489,11 @@ function createIdentityClient(config = {}) {
17267
17489
  /**
17268
17490
  * Delete an API key by revoking it.
17269
17491
  */
17270
- async deleteKey(keyId, input = {}, idempotencyKey) {
17271
- return gateway.request({
17272
- path: `/api/platform/v1/identity/keys/${encodeURIComponent(keyId)}/revoke`,
17273
- method: "POST",
17274
- body: input,
17275
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
17276
- });
17277
- },
17492
+ deleteKey,
17278
17493
  /**
17279
17494
  * @deprecated Use deleteKey.
17280
17495
  */
17281
- async revokeKey(keyId, input = {}, idempotencyKey) {
17282
- return this.deleteKey(keyId, input, idempotencyKey);
17283
- },
17496
+ revokeKey: deleteKey,
17284
17497
  /**
17285
17498
  * Search Clerk users by email or display attributes.
17286
17499
  */
@@ -17396,14 +17609,11 @@ function createIdentityClient(config = {}) {
17396
17609
  }
17397
17610
 
17398
17611
  // ../sdk/src/topicsClient.ts
17399
- function asRecord3(value) {
17400
- return value && typeof value === "object" ? value : {};
17401
- }
17402
17612
  function cleanString3(value) {
17403
17613
  return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
17404
17614
  }
17405
17615
  function normalizeTopicRecord(value) {
17406
- const record = asRecord3(value);
17616
+ const record = asRecord(value);
17407
17617
  const topicId = cleanString3(record.topicId) ?? cleanString3(record.id) ?? cleanString3(record._id);
17408
17618
  return withTopicAlias({
17409
17619
  ...record,
@@ -17428,7 +17638,7 @@ function createTopicsClient(config = {}) {
17428
17638
  })}`
17429
17639
  }).then(
17430
17640
  (response) => mapGatewayData(response, (data) => {
17431
- const record = asRecord3(data);
17641
+ const record = asRecord(data);
17432
17642
  const items = Array.isArray(record.topics) ? record.topics.map(normalizeTopicRecord) : [];
17433
17643
  return {
17434
17644
  ...createListResult(items, "topics"),
@@ -17445,7 +17655,7 @@ function createTopicsClient(config = {}) {
17445
17655
  }).then(
17446
17656
  (response) => mapGatewayData(
17447
17657
  response,
17448
- (data) => normalizeTopicRecord(asRecord3(data).topic ?? data)
17658
+ (data) => normalizeTopicRecord(asRecord(data).topic ?? data)
17449
17659
  )
17450
17660
  );
17451
17661
  },
@@ -17481,7 +17691,7 @@ function createTopicsClient(config = {}) {
17481
17691
  )}`
17482
17692
  }).then(
17483
17693
  (response) => mapGatewayData(response, (data) => {
17484
- const record = asRecord3(data);
17694
+ const record = asRecord(data);
17485
17695
  return {
17486
17696
  tree: Array.isArray(record.tree) ? record.tree.map(normalizeTopicTreeNode) : []
17487
17697
  };
@@ -17900,7 +18110,7 @@ function createEventsFacade(config = {}) {
17900
18110
  function createGraphFacade(config = {}) {
17901
18111
  const graphClient = createGraphClient(config);
17902
18112
  const gateway = createGatewayRequestClient(config);
17903
- return {
18113
+ const graphFacade = {
17904
18114
  async neighborhood(input) {
17905
18115
  return graphClient.neighborhood({
17906
18116
  globalId: input.globalId,
@@ -17908,18 +18118,6 @@ function createGraphFacade(config = {}) {
17908
18118
  maxDepth: input.maxDepth
17909
18119
  });
17910
18120
  },
17911
- async traverse(input) {
17912
- return graphClient.traverse(input);
17913
- },
17914
- async analyze(input = {}) {
17915
- return graphClient.analyze(input);
17916
- },
17917
- async bias(input = {}) {
17918
- return graphClient.bias(input);
17919
- },
17920
- async gaps(input) {
17921
- return graphClient.gaps(input);
17922
- },
17923
18121
  async falsify(input, idempotencyKey = randomIdempotencyKey()) {
17924
18122
  return gateway.request({
17925
18123
  path: "/api/platform/v1/graph/falsify",
@@ -17929,6 +18127,12 @@ function createGraphFacade(config = {}) {
17929
18127
  });
17930
18128
  }
17931
18129
  };
18130
+ return Object.assign(graphFacade, {
18131
+ traverse: graphClient.traverse,
18132
+ analyze: graphClient.analyze,
18133
+ bias: graphClient.bias,
18134
+ gaps: graphClient.gaps
18135
+ });
17932
18136
  }
17933
18137
  function createIdentityFacade(config = {}) {
17934
18138
  const identityClient = createIdentityClient(config);
@@ -17942,15 +18146,12 @@ function createIdentityFacade(config = {}) {
17942
18146
  function createOntologiesFacade(config = {}) {
17943
18147
  const ontologyClient = createOntologyClient(config);
17944
18148
  const gateway = createGatewayRequestClient(config);
17945
- return {
18149
+ const ontologyFacade = {
17946
18150
  async get(id) {
17947
18151
  return gateway.request({
17948
18152
  path: `/api/platform/v1/ontologies/${encodeURIComponent(id)}`
17949
18153
  });
17950
18154
  },
17951
- async list(query5 = {}) {
17952
- return ontologyClient.list(query5);
17953
- },
17954
18155
  async bind(input, idempotencyKey) {
17955
18156
  return gateway.request({
17956
18157
  path: `/api/platform/v1/ontologies/${encodeURIComponent(input.ontologyId)}/bind`,
@@ -17970,6 +18171,9 @@ function createOntologiesFacade(config = {}) {
17970
18171
  });
17971
18172
  }
17972
18173
  };
18174
+ return Object.assign(ontologyFacade, {
18175
+ list: ontologyClient.list
18176
+ });
17973
18177
  }
17974
18178
  function createQuestionsFacade(config = {}) {
17975
18179
  const gateway = createGatewayRequestClient(config);
@@ -18162,15 +18366,9 @@ function createTasksFacade(config = {}) {
18162
18366
  function createTopicsFacade(config = {}) {
18163
18367
  const topicsClient = createTopicsClient(config);
18164
18368
  return {
18165
- async create(input, idempotencyKey) {
18166
- return topicsClient.create(input, idempotencyKey);
18167
- },
18168
- async get(id) {
18169
- return topicsClient.get(id);
18170
- },
18171
- async list(query5 = {}) {
18172
- return topicsClient.list(query5);
18173
- },
18369
+ create: topicsClient.create,
18370
+ get: topicsClient.get,
18371
+ list: topicsClient.list,
18174
18372
  async update(input, idempotencyKey) {
18175
18373
  const { id, ...rest } = input;
18176
18374
  return topicsClient.update(id, rest, idempotencyKey);
@@ -18186,12 +18384,8 @@ function createTopicsFacade(config = {}) {
18186
18384
  maxDepth: input.maxDepth
18187
18385
  });
18188
18386
  },
18189
- async remove(id, idempotencyKey = randomIdempotencyKey()) {
18190
- return topicsClient.remove(id, idempotencyKey);
18191
- },
18192
- async bulkCreate(input, idempotencyKey = randomIdempotencyKey()) {
18193
- return topicsClient.bulkCreate(input, idempotencyKey);
18194
- }
18387
+ remove: topicsClient.remove,
18388
+ bulkCreate: topicsClient.bulkCreate
18195
18389
  };
18196
18390
  }
18197
18391
  function createWebhooksFacade(config = {}) {
@@ -18391,7 +18585,7 @@ function createWorktreesFacade(config = {}) {
18391
18585
  // ../sdk/src/decisionsClient.ts
18392
18586
  function createDecisionsClient(config = {}) {
18393
18587
  const gateway = createGatewayRequestClient(config);
18394
- return {
18588
+ const client = {
18395
18589
  /**
18396
18590
  * List judgments for a topic scope.
18397
18591
  */
@@ -18469,12 +18663,6 @@ function createDecisionsClient(config = {}) {
18469
18663
  })
18470
18664
  );
18471
18665
  },
18472
- /**
18473
- * @deprecated Use listPendingOutcomeReviews.
18474
- */
18475
- async listPendingJudgmentOutcomeReview(query5) {
18476
- return this.listPendingOutcomeReviews(query5);
18477
- },
18478
18666
  /**
18479
18667
  * Get audit integrity checks for judgment transitions.
18480
18668
  */
@@ -18507,12 +18695,6 @@ function createDecisionsClient(config = {}) {
18507
18695
  )
18508
18696
  );
18509
18697
  },
18510
- /**
18511
- * @deprecated Use createJudgment.
18512
- */
18513
- async recordJudgment(input, idempotencyKey) {
18514
- return this.createJudgment(input, idempotencyKey);
18515
- },
18516
18698
  /**
18517
18699
  * Update the outcome for an existing judgment.
18518
18700
  */
@@ -18523,14 +18705,13 @@ function createDecisionsClient(config = {}) {
18523
18705
  body: input,
18524
18706
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
18525
18707
  });
18526
- },
18527
- /**
18528
- * @deprecated Use updateJudgmentOutcome.
18529
- */
18530
- async recordJudgmentOutcome(judgmentId, input, idempotencyKey) {
18531
- return this.updateJudgmentOutcome(judgmentId, input, idempotencyKey);
18532
18708
  }
18533
18709
  };
18710
+ return Object.assign(client, {
18711
+ listPendingJudgmentOutcomeReview: client.listPendingOutcomeReviews,
18712
+ recordJudgment: client.createJudgment,
18713
+ recordJudgmentOutcome: client.updateJudgmentOutcome
18714
+ });
18534
18715
  }
18535
18716
 
18536
18717
  // ../sdk/src/embeddingsClient.ts
@@ -19154,7 +19335,7 @@ function createGraphStateClassifierClient(config = {}) {
19154
19335
  // ../sdk/src/harnessClient.ts
19155
19336
  function createHarnessClient(config = {}) {
19156
19337
  const gateway = createGatewayRequestClient(config);
19157
- return {
19338
+ const client = {
19158
19339
  /**
19159
19340
  * List agent definitions.
19160
19341
  */
@@ -19187,12 +19368,6 @@ function createHarnessClient(config = {}) {
19187
19368
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
19188
19369
  });
19189
19370
  },
19190
- /**
19191
- * @deprecated Use createAgentDefinition.
19192
- */
19193
- async registerAgentDefinition(input, idempotencyKey) {
19194
- return this.createAgentDefinition(input, idempotencyKey);
19195
- },
19196
19371
  /**
19197
19372
  * Update an agent definition.
19198
19373
  */
@@ -19231,12 +19406,6 @@ function createHarnessClient(config = {}) {
19231
19406
  )
19232
19407
  );
19233
19408
  },
19234
- /**
19235
- * @deprecated Use listAgentRuns.
19236
- */
19237
- async listRunsForAgent(agentId, scope = {}) {
19238
- return this.listAgentRuns(agentId, scope);
19239
- },
19240
19409
  /**
19241
19410
  * List tool definitions.
19242
19411
  */
@@ -19269,12 +19438,6 @@ function createHarnessClient(config = {}) {
19269
19438
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
19270
19439
  });
19271
19440
  },
19272
- /**
19273
- * @deprecated Use createToolDefinition.
19274
- */
19275
- async registerToolDefinition(input, idempotencyKey) {
19276
- return this.createToolDefinition(input, idempotencyKey);
19277
- },
19278
19441
  /**
19279
19442
  * Update a tool definition.
19280
19443
  */
@@ -19309,12 +19472,6 @@ function createHarnessClient(config = {}) {
19309
19472
  )
19310
19473
  );
19311
19474
  },
19312
- /**
19313
- * @deprecated Use listRunEntries.
19314
- */
19315
- async listRunLedgerEntries(scope = {}) {
19316
- return this.listRunEntries(scope);
19317
- },
19318
19475
  /**
19319
19476
  * Create a harness run.
19320
19477
  */
@@ -19389,6 +19546,12 @@ function createHarnessClient(config = {}) {
19389
19546
  });
19390
19547
  }
19391
19548
  };
19549
+ return Object.assign(client, {
19550
+ registerAgentDefinition: client.createAgentDefinition,
19551
+ listRunsForAgent: client.listAgentRuns,
19552
+ registerToolDefinition: client.createToolDefinition,
19553
+ listRunLedgerEntries: client.listRunEntries
19554
+ });
19392
19555
  }
19393
19556
 
19394
19557
  // ../sdk/src/jobsClient.ts
@@ -19516,45 +19679,41 @@ function createJobsClient(config = {}) {
19516
19679
  // ../sdk/src/learningClient.ts
19517
19680
  function createLearningClient(config = {}) {
19518
19681
  const gateway = createGatewayRequestClient(config);
19682
+ const listRecentExecutions = async (args = {}) => gateway.request({
19683
+ path: `/api/platform/v1/learning/executions/recent${toQueryString({
19684
+ ...normalizeTopicQuery(args),
19685
+ namespace: args.namespace,
19686
+ audienceMode: args.audienceMode,
19687
+ success: typeof args.success === "boolean" ? args.success ? "true" : "false" : void 0,
19688
+ limit: typeof args.limit === "number" && Number.isFinite(args.limit) ? String(args.limit) : void 0
19689
+ })}`
19690
+ }).then(
19691
+ (response) => mapGatewayData(
19692
+ response,
19693
+ (data) => createListResult(Array.isArray(data) ? data : [], "executions")
19694
+ )
19695
+ );
19696
+ const getExecutionStats = async (args = {}) => gateway.request({
19697
+ path: `/api/platform/v1/learning/executions/stats${toQueryString({
19698
+ ...normalizeTopicQuery(args),
19699
+ namespace: args.namespace,
19700
+ audienceMode: args.audienceMode,
19701
+ hours: typeof args.hours === "number" && Number.isFinite(args.hours) ? String(args.hours) : void 0
19702
+ })}`
19703
+ });
19519
19704
  return {
19520
19705
  /**
19521
19706
  * List recent execution records.
19522
19707
  */
19523
- async listRecentExecutions(args = {}) {
19524
- return gateway.request({
19525
- path: `/api/platform/v1/learning/executions/recent${toQueryString({
19526
- ...normalizeTopicQuery(args),
19527
- namespace: args.namespace,
19528
- audienceMode: args.audienceMode,
19529
- success: typeof args.success === "boolean" ? args.success ? "true" : "false" : void 0,
19530
- limit: typeof args.limit === "number" && Number.isFinite(args.limit) ? String(args.limit) : void 0
19531
- })}`
19532
- }).then(
19533
- (response) => mapGatewayData(
19534
- response,
19535
- (data) => createListResult(Array.isArray(data) ? data : [], "executions")
19536
- )
19537
- );
19538
- },
19708
+ listRecentExecutions,
19539
19709
  /**
19540
19710
  * @deprecated Use listRecentExecutions.
19541
19711
  */
19542
- async getRecentExecutions(args = {}) {
19543
- return this.listRecentExecutions(args);
19544
- },
19712
+ getRecentExecutions: listRecentExecutions,
19545
19713
  /**
19546
19714
  * Get aggregate execution statistics.
19547
19715
  */
19548
- async getExecutionStats(args = {}) {
19549
- return gateway.request({
19550
- path: `/api/platform/v1/learning/executions/stats${toQueryString({
19551
- ...normalizeTopicQuery(args),
19552
- namespace: args.namespace,
19553
- audienceMode: args.audienceMode,
19554
- hours: typeof args.hours === "number" && Number.isFinite(args.hours) ? String(args.hours) : void 0
19555
- })}`
19556
- });
19557
- }
19716
+ getExecutionStats
19558
19717
  };
19559
19718
  }
19560
19719
 
@@ -20591,7 +20750,7 @@ function createOrgGraphSearchClient(config = {}) {
20591
20750
  // ../sdk/src/packsClient.ts
20592
20751
  function createPacksClient(config = {}) {
20593
20752
  const gateway = createGatewayRequestClient(config);
20594
- return {
20753
+ const client = {
20595
20754
  /**
20596
20755
  * List catalog entries for available packs.
20597
20756
  */
@@ -20605,12 +20764,6 @@ function createPacksClient(config = {}) {
20605
20764
  )
20606
20765
  );
20607
20766
  },
20608
- /**
20609
- * @deprecated Use listCatalog.
20610
- */
20611
- async getCatalog() {
20612
- return this.listCatalog();
20613
- },
20614
20767
  /**
20615
20768
  * Get the discovery catalog for packs.
20616
20769
  */
@@ -20640,12 +20793,6 @@ function createPacksClient(config = {}) {
20640
20793
  )
20641
20794
  );
20642
20795
  },
20643
- /**
20644
- * @deprecated Use listStates.
20645
- */
20646
- async getStates(query5 = {}) {
20647
- return this.listStates(query5);
20648
- },
20649
20796
  /**
20650
20797
  * Get health details for a pack.
20651
20798
  */
@@ -20669,12 +20816,6 @@ function createPacksClient(config = {}) {
20669
20816
  )
20670
20817
  );
20671
20818
  },
20672
- /**
20673
- * @deprecated Use listTelemetry.
20674
- */
20675
- async getTelemetry(query5 = {}) {
20676
- return this.listTelemetry(query5);
20677
- },
20678
20819
  /**
20679
20820
  * Create a pack entitlement.
20680
20821
  */
@@ -20686,18 +20827,6 @@ function createPacksClient(config = {}) {
20686
20827
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
20687
20828
  });
20688
20829
  },
20689
- /**
20690
- * Update a pack entitlement.
20691
- */
20692
- async updateEntitlement(input, idempotencyKey) {
20693
- return this.createEntitlement(input, idempotencyKey);
20694
- },
20695
- /**
20696
- * @deprecated Use createEntitlement or updateEntitlement.
20697
- */
20698
- async upsertEntitlement(input, idempotencyKey) {
20699
- return this.createEntitlement(input, idempotencyKey);
20700
- },
20701
20830
  /**
20702
20831
  * Install a pack.
20703
20832
  */
@@ -20754,6 +20883,13 @@ function createPacksClient(config = {}) {
20754
20883
  });
20755
20884
  }
20756
20885
  };
20886
+ return Object.assign(client, {
20887
+ getCatalog: client.listCatalog,
20888
+ getStates: client.listStates,
20889
+ getTelemetry: client.listTelemetry,
20890
+ updateEntitlement: client.createEntitlement,
20891
+ upsertEntitlement: client.createEntitlement
20892
+ });
20757
20893
  }
20758
20894
 
20759
20895
  // ../sdk/src/policyClient.ts
@@ -20789,6 +20925,14 @@ function asRolePolicyArray(data) {
20789
20925
  }
20790
20926
  return data.map(asRolePolicyRecord).filter((row) => Boolean(row));
20791
20927
  }
20928
+ function buildFilterByPermissionResponse(permission, allowedTopicIds, deniedTopics, count) {
20929
+ const result = {};
20930
+ result.permission = permission;
20931
+ result.allowedTopicIds = allowedTopicIds;
20932
+ result.deniedTopics = deniedTopics;
20933
+ result.count = count;
20934
+ return result;
20935
+ }
20792
20936
  function createPolicyClient(config = {}) {
20793
20937
  const gateway = createGatewayRequestClient(config);
20794
20938
  return {
@@ -21011,15 +21155,15 @@ function createPolicyClient(config = {}) {
21011
21155
  });
21012
21156
  const allowedTopicIds = Array.isArray(response.data?.allowedTopicIds) ? response.data.allowedTopicIds : [];
21013
21157
  const deniedTopics = Array.isArray(response.data?.deniedTopics) ? response.data.deniedTopics : [];
21014
- return {
21015
- success: true,
21016
- data: {
21017
- permission,
21018
- allowedTopicIds,
21019
- deniedTopics,
21020
- count: typeof response.data?.count === "number" ? response.data.count : allowedTopicIds.length
21021
- }
21022
- };
21158
+ const result = {};
21159
+ result.success = true;
21160
+ result.data = buildFilterByPermissionResponse(
21161
+ permission,
21162
+ allowedTopicIds,
21163
+ deniedTopics,
21164
+ typeof response.data?.count === "number" ? response.data.count : allowedTopicIds.length
21165
+ );
21166
+ return result;
21023
21167
  }
21024
21168
  };
21025
21169
  }
@@ -21027,64 +21171,66 @@ function createPolicyClient(config = {}) {
21027
21171
  // ../sdk/src/reportsClient.ts
21028
21172
  function createReportsClient(config = {}) {
21029
21173
  const gateway = createGatewayRequestClient(config);
21174
+ const listTemplates = async (args = {}) => gateway.request({
21175
+ path: `/api/platform/v1/reports/templates${toQueryString({
21176
+ slug: args.slug
21177
+ })}`
21178
+ }).then(
21179
+ (response) => mapGatewayData(response, (data) => {
21180
+ const rows = asListItems(data, "templates");
21181
+ return createListResult(rows, "templates");
21182
+ })
21183
+ );
21184
+ const listReports = async (input, args = {}) => {
21185
+ const topicId = resolveTopicId(input);
21186
+ if (!topicId) {
21187
+ throw new Error("topicId is required");
21188
+ }
21189
+ return gateway.request({
21190
+ path: `/api/platform/v1/reports/topics/${encodeURIComponent(topicId)}${toQueryString(
21191
+ {
21192
+ summary: typeof args.summary === "boolean" ? args.summary ? "true" : "false" : void 0
21193
+ }
21194
+ )}`
21195
+ }).then(
21196
+ (response) => mapGatewayData(
21197
+ response,
21198
+ (data) => createListResult(Array.isArray(data) ? data : [], "reports")
21199
+ )
21200
+ );
21201
+ };
21202
+ const getReport = async (reportId) => gateway.request({
21203
+ path: `/api/platform/v1/reports/${encodeURIComponent(reportId)}`
21204
+ });
21030
21205
  return {
21031
21206
  /**
21032
21207
  * List report templates.
21033
21208
  */
21034
- async listTemplates(args = {}) {
21035
- return gateway.request({
21036
- path: `/api/platform/v1/reports/templates${toQueryString({
21037
- slug: args.slug
21038
- })}`
21039
- }).then(
21040
- (response) => mapGatewayData(response, (data) => {
21041
- const record = data && typeof data === "object" ? data : {};
21042
- const rows = Array.isArray(data) ? data : Array.isArray(record.templates) ? record.templates : [];
21043
- return createListResult(rows, "templates");
21044
- })
21045
- );
21046
- },
21209
+ listTemplates,
21047
21210
  /**
21048
21211
  * @deprecated Use listTemplates.
21049
21212
  */
21050
- async getTemplates(args = {}) {
21051
- return this.listTemplates(args);
21052
- },
21213
+ getTemplates: listTemplates,
21053
21214
  /**
21054
21215
  * List reports for a topic scope.
21055
21216
  */
21056
- async listReports(input, args = {}) {
21057
- const topicId = resolveTopicId(input);
21058
- if (!topicId) {
21059
- throw new Error("topicId is required");
21060
- }
21061
- return gateway.request({
21062
- path: `/api/platform/v1/reports/topics/${encodeURIComponent(topicId)}${toQueryString(
21063
- {
21064
- summary: typeof args.summary === "boolean" ? args.summary ? "true" : "false" : void 0
21065
- }
21066
- )}`
21067
- }).then(
21068
- (response) => mapGatewayData(
21069
- response,
21070
- (data) => createListResult(Array.isArray(data) ? data : [], "reports")
21071
- )
21072
- );
21073
- },
21217
+ listReports,
21074
21218
  /**
21075
21219
  * Get a generated report.
21076
21220
  */
21077
- async getReport(reportId) {
21078
- return gateway.request({
21079
- path: `/api/platform/v1/reports/${encodeURIComponent(reportId)}`
21080
- });
21081
- }
21221
+ getReport
21082
21222
  };
21083
21223
  }
21084
21224
 
21085
21225
  // ../sdk/src/schemaClient.ts
21086
21226
  function createSchemaClient(config = {}) {
21087
21227
  const gateway = createGatewayRequestClient(config);
21228
+ const createEntitlement = (input, idempotencyKey) => gateway.request({
21229
+ path: "/api/platform/v1/schema/entitlements",
21230
+ method: "POST",
21231
+ body: input,
21232
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
21233
+ });
21088
21234
  return {
21089
21235
  /**
21090
21236
  * List schema packs.
@@ -21136,29 +21282,95 @@ function createSchemaClient(config = {}) {
21136
21282
  /**
21137
21283
  * Create a schema entitlement.
21138
21284
  */
21139
- async createEntitlement(input, idempotencyKey) {
21140
- return gateway.request({
21141
- path: "/api/platform/v1/schema/entitlements",
21142
- method: "POST",
21143
- body: input,
21144
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
21145
- });
21146
- },
21285
+ createEntitlement,
21147
21286
  /**
21148
21287
  * Update a schema entitlement.
21149
21288
  */
21150
- async updateEntitlement(input, idempotencyKey) {
21151
- return this.createEntitlement(input, idempotencyKey);
21152
- },
21289
+ updateEntitlement: createEntitlement,
21153
21290
  /**
21154
21291
  * @deprecated Use createEntitlement or updateEntitlement.
21155
21292
  */
21156
- async upsertEntitlement(input, idempotencyKey) {
21157
- return this.createEntitlement(input, idempotencyKey);
21158
- }
21293
+ upsertEntitlement: createEntitlement
21159
21294
  };
21160
21295
  }
21161
21296
 
21297
+ // ../sdk/src/clientHelpers.ts
21298
+ function asNodeArray(data) {
21299
+ const rows = asListItems(data, "nodes");
21300
+ if (rows.length > 0) {
21301
+ return rows.filter(
21302
+ (value) => Boolean(value) && typeof value === "object"
21303
+ );
21304
+ }
21305
+ if (data && typeof data === "object") {
21306
+ return [data];
21307
+ }
21308
+ return [];
21309
+ }
21310
+ function requireTopicId4(args) {
21311
+ const topicId = resolveTopicId(args);
21312
+ if (!topicId) {
21313
+ throw new Error("topicId is required");
21314
+ }
21315
+ return topicId;
21316
+ }
21317
+ function requireTopicOrProjectId(args) {
21318
+ const topicId = args.topicId?.trim() || args.projectId?.trim() || void 0;
21319
+ if (!topicId) {
21320
+ throw new Error("topicId is required");
21321
+ }
21322
+ return topicId;
21323
+ }
21324
+ var AUDIT_NODE_REFERENCE_KEY_PATTERN = /(^|_)(id|nodeid|beliefid|resourceid|targetid|sourceid|subjectid|globalid|entityid|recordid|fromnodeid|tonodeid|linkednodeid|linkedbeliefid|nodeids|beliefids|resourceids)$/i;
21325
+ function matchesAuditNodeReference(value, nodeId) {
21326
+ if (Array.isArray(value)) {
21327
+ return value.some((entry) => matchesAuditNodeReference(entry, nodeId));
21328
+ }
21329
+ if (!value || typeof value !== "object") {
21330
+ return false;
21331
+ }
21332
+ return Object.entries(value).some(([key, entry]) => {
21333
+ if (typeof entry === "string" && entry === nodeId && AUDIT_NODE_REFERENCE_KEY_PATTERN.test(key)) {
21334
+ return true;
21335
+ }
21336
+ if (Array.isArray(entry) && AUDIT_NODE_REFERENCE_KEY_PATTERN.test(key) && entry.some((item) => item === nodeId)) {
21337
+ return true;
21338
+ }
21339
+ return matchesAuditNodeReference(entry, nodeId);
21340
+ });
21341
+ }
21342
+ function requireText(args) {
21343
+ const text = resolveText(args);
21344
+ if (!text) {
21345
+ throw new Error("text is required");
21346
+ }
21347
+ return text;
21348
+ }
21349
+ function requireBaseRate(args) {
21350
+ const baseRate = typeof args.baseRate === "number" && Number.isFinite(args.baseRate) ? args.baseRate : 0.5;
21351
+ if (baseRate < 0 || baseRate > 1) {
21352
+ throw new Error("baseRate must be within [0, 1].");
21353
+ }
21354
+ return baseRate;
21355
+ }
21356
+ function sdkQueryString(input) {
21357
+ const params = new URLSearchParams();
21358
+ for (const [key, value] of Object.entries(input)) {
21359
+ if (value === void 0 || value === null) {
21360
+ continue;
21361
+ }
21362
+ if (Array.isArray(value)) {
21363
+ if (value.length > 0) {
21364
+ params.set(key, value.join(","));
21365
+ }
21366
+ continue;
21367
+ }
21368
+ params.set(key, String(value));
21369
+ }
21370
+ const serialized = params.toString();
21371
+ return serialized ? `?${serialized}` : "";
21372
+ }
21373
+
21162
21374
  // ../sdk/src/telemetryClient.ts
21163
21375
  var TELEMETRY_FIELDS = [
21164
21376
  "tenantId",
@@ -21329,6 +21541,16 @@ function query4(input) {
21329
21541
  cursor: input.cursor
21330
21542
  };
21331
21543
  }
21544
+ function effectiveToolsQuery(input) {
21545
+ return {
21546
+ ...query4(input),
21547
+ callerRole: input.callerRole,
21548
+ surface: input.surface,
21549
+ sessionType: input.sessionType,
21550
+ permittedToolNames: input.permittedToolNames ? JSON.stringify(input.permittedToolNames) : void 0,
21551
+ executableOnly: input.executableOnly
21552
+ };
21553
+ }
21332
21554
  function writeBody(input, operation) {
21333
21555
  return knownPayload(input, TOOL_REGISTRY_FIELDS, operation);
21334
21556
  }
@@ -21357,7 +21579,9 @@ function createToolRegistryClient(config = {}) {
21357
21579
  },
21358
21580
  listEffectiveTools(input) {
21359
21581
  return gateway.request({
21360
- path: `/api/platform/v1/tools/effective${toQueryString(query4(input))}`
21582
+ path: `/api/platform/v1/tools/effective${toQueryString(
21583
+ effectiveToolsQuery(input)
21584
+ )}`
21361
21585
  }).then(
21362
21586
  (response) => mapGatewayData(
21363
21587
  response,
@@ -21448,7 +21672,7 @@ function createToolRegistryClient(config = {}) {
21448
21672
  }
21449
21673
 
21450
21674
  // ../sdk/src/version.ts
21451
- var LUCERN_SDK_VERSION = "0.2.0-alpha.1";
21675
+ var LUCERN_SDK_VERSION = "0.3.0-alpha.7";
21452
21676
 
21453
21677
  // ../sdk/src/workflowClient.ts
21454
21678
  function normalizeLensQuery(value) {
@@ -21642,12 +21866,6 @@ function createWorkflowClient(config = {}) {
21642
21866
  )
21643
21867
  );
21644
21868
  },
21645
- /**
21646
- * @deprecated Use createWorktree.
21647
- */
21648
- async addWorktree(input, idempotencyKey) {
21649
- return client.createWorktree(input, idempotencyKey);
21650
- },
21651
21869
  /**
21652
21870
  * Merge a worktree into the main belief line.
21653
21871
  */
@@ -21845,54 +22063,19 @@ function createWorkflowClient(config = {}) {
21845
22063
  body: input,
21846
22064
  idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
21847
22065
  });
21848
- },
21849
- /**
21850
- * @deprecated Use createBranch.
21851
- */
21852
- async createPillar(input, idempotencyKey) {
21853
- return client.createBranch(input, idempotencyKey);
21854
- },
21855
- /**
21856
- * @deprecated Use addWorktree.
21857
- */
21858
- async createSprint(input, idempotencyKey) {
21859
- return client.createWorktree(input, idempotencyKey);
21860
- },
21861
- /**
21862
- * @deprecated Use merge.
21863
- */
21864
- async completeSprint(worktreeId, input, idempotencyKey) {
21865
- return client.merge(worktreeId, input, idempotencyKey);
21866
- },
21867
- /**
21868
- * @deprecated Use openPullRequest.
21869
- */
21870
- async requestReview(worktreeId, input, idempotencyKey) {
21871
- return client.openPullRequest(worktreeId, input, idempotencyKey);
21872
- },
21873
- /**
21874
- * @deprecated Use push.
21875
- */
21876
- async publishFindings(worktreeId, input, idempotencyKey) {
21877
- return client.push(worktreeId, input, idempotencyKey);
21878
22066
  }
21879
22067
  };
21880
- return client;
22068
+ return Object.assign(client, {
22069
+ addWorktree: client.createWorktree,
22070
+ createPillar: client.createBranch,
22071
+ createSprint: client.createWorktree,
22072
+ completeSprint: client.merge,
22073
+ requestReview: client.openPullRequest,
22074
+ publishFindings: client.push
22075
+ });
21881
22076
  }
21882
22077
 
21883
22078
  // ../sdk/src/client.ts
21884
- function asNodeArray(data) {
21885
- const rows = asListItems(data, "nodes");
21886
- if (rows.length > 0) {
21887
- return rows.filter(
21888
- (value) => Boolean(value) && typeof value === "object"
21889
- );
21890
- }
21891
- if (data && typeof data === "object") {
21892
- return [data];
21893
- }
21894
- return [];
21895
- }
21896
22079
  function toGatewayConfig(config) {
21897
22080
  return {
21898
22081
  baseUrl: config.baseUrl,
@@ -21920,72 +22103,9 @@ function toGatewayConfig(config) {
21920
22103
  }
21921
22104
  };
21922
22105
  }
21923
- function requireTopicId4(args) {
21924
- const topicId = resolveTopicId(args);
21925
- if (!topicId) {
21926
- throw new Error("topicId is required");
21927
- }
21928
- return topicId;
21929
- }
21930
- function requireTopicOrProjectId(args) {
21931
- const topicId = args.topicId?.trim() || args.projectId?.trim() || void 0;
21932
- if (!topicId) {
21933
- throw new Error("topicId is required");
21934
- }
21935
- return topicId;
21936
- }
21937
- var AUDIT_NODE_REFERENCE_KEY_PATTERN = /(^|_)(id|nodeid|beliefid|resourceid|targetid|sourceid|subjectid|globalid|entityid|recordid|fromnodeid|tonodeid|linkednodeid|linkedbeliefid|nodeids|beliefids|resourceids)$/i;
21938
- function matchesAuditNodeReference(value, nodeId) {
21939
- if (Array.isArray(value)) {
21940
- return value.some((entry) => matchesAuditNodeReference(entry, nodeId));
21941
- }
21942
- if (!value || typeof value !== "object") {
21943
- return false;
21944
- }
21945
- return Object.entries(value).some(([key, entry]) => {
21946
- if (typeof entry === "string" && entry === nodeId && AUDIT_NODE_REFERENCE_KEY_PATTERN.test(key)) {
21947
- return true;
21948
- }
21949
- if (Array.isArray(entry) && AUDIT_NODE_REFERENCE_KEY_PATTERN.test(key) && entry.some((item) => item === nodeId)) {
21950
- return true;
21951
- }
21952
- return matchesAuditNodeReference(entry, nodeId);
21953
- });
21954
- }
21955
- function requireText(args) {
21956
- const text = resolveText(args);
21957
- if (!text) {
21958
- throw new Error("text is required");
21959
- }
21960
- return text;
21961
- }
21962
- function requireBaseRate(args) {
21963
- const baseRate = typeof args.baseRate === "number" && Number.isFinite(args.baseRate) ? args.baseRate : 0.5;
21964
- if (baseRate < 0 || baseRate > 1) {
21965
- throw new Error("baseRate must be within [0, 1].");
21966
- }
21967
- return baseRate;
21968
- }
21969
22106
  function exposeGatewayData(response) {
21970
22107
  return Object.assign({}, response, response.data);
21971
22108
  }
21972
- function sdkQueryString(input) {
21973
- const params = new URLSearchParams();
21974
- for (const [key, value] of Object.entries(input)) {
21975
- if (value === void 0 || value === null) {
21976
- continue;
21977
- }
21978
- if (Array.isArray(value)) {
21979
- if (value.length > 0) {
21980
- params.set(key, value.join(","));
21981
- }
21982
- continue;
21983
- }
21984
- params.set(key, String(value));
21985
- }
21986
- const serialized = params.toString();
21987
- return serialized ? `?${serialized}` : "";
21988
- }
21989
22109
  function createLucernClient(config = {}) {
21990
22110
  const gatewayConfig = toGatewayConfig(config);
21991
22111
  const beliefsClient = createBeliefsClient(gatewayConfig);
@@ -22209,7 +22329,7 @@ function createLucernClient(config = {}) {
22209
22329
  topicId,
22210
22330
  nodeType: "contradiction",
22211
22331
  limit: 500
22212
- }) : args.nodeId ? await graphClient.queryNodes({ nodeId: args.nodeId }) : { data: [] };
22332
+ }) : args.nodeId ? await graphClient.listNodes({ nodeId: args.nodeId }) : { data: [] };
22213
22333
  const contradictions2 = asNodeArray(response.data).filter((node) => {
22214
22334
  const status = typeof node.metadata?.status === "string" ? node.metadata.status : typeof node.status === "string" ? node.status : "unresolved";
22215
22335
  if (args.status && status !== args.status) {
@@ -22389,23 +22509,15 @@ function createLucernClient(config = {}) {
22389
22509
  }).then(exposeGatewayData);
22390
22510
  }
22391
22511
  const nodesNamespace = {
22392
- list(query5) {
22393
- return graphClient.listNodes(query5);
22394
- },
22512
+ list: graphClient.listNodes,
22395
22513
  get(input) {
22396
22514
  return graphClient.getNode(
22397
22515
  typeof input === "string" ? { nodeId: input } : input
22398
22516
  );
22399
22517
  },
22400
- create(input, idempotencyKey) {
22401
- return graphClient.createNode(input, idempotencyKey);
22402
- },
22403
- update(input, idempotencyKey) {
22404
- return graphClient.updateNode(input, idempotencyKey);
22405
- },
22406
- batchCreate(input, idempotencyKey) {
22407
- return graphClient.batchCreateNodes(input, idempotencyKey);
22408
- },
22518
+ create: graphClient.createNode,
22519
+ update: graphClient.updateNode,
22520
+ batchCreate: graphClient.batchCreateNodes,
22409
22521
  listByTopicAndType(input) {
22410
22522
  return gateway.request({
22411
22523
  path: `/api/platform/v1/nodes${sdkQueryString({
@@ -22430,15 +22542,9 @@ function createLucernClient(config = {}) {
22430
22542
  })}`
22431
22543
  }).then(exposeGatewayData);
22432
22544
  },
22433
- supersede(input, idempotencyKey) {
22434
- return graphClient.supersedeNode(input, idempotencyKey);
22435
- },
22436
- verify(input, idempotencyKey) {
22437
- return graphClient.verifyNode(input, idempotencyKey);
22438
- },
22439
- hardDelete(input, idempotencyKey) {
22440
- return graphClient.hardDeleteNode(input, idempotencyKey);
22441
- }
22545
+ supersede: graphClient.supersedeNode,
22546
+ verify: graphClient.verifyNode,
22547
+ hardDelete: graphClient.hardDeleteNode
22442
22548
  };
22443
22549
  const publicationNamespace = {
22444
22550
  create(input, idempotencyKey) {
@@ -22515,9 +22621,7 @@ function createLucernClient(config = {}) {
22515
22621
  return {
22516
22622
  config,
22517
22623
  version: LUCERN_SDK_VERSION,
22518
- search(query5, options) {
22519
- return searchResources(query5, options);
22520
- },
22624
+ search: searchResources,
22521
22625
  events: {
22522
22626
  list(query5 = {}) {
22523
22627
  return eventsFacade.list(query5).then(exposeGatewayData);
@@ -22614,9 +22718,7 @@ function createLucernClient(config = {}) {
22614
22718
  confidenceHistory(nodeId) {
22615
22719
  return beliefsFacade.confidenceHistory(nodeId).then(exposeGatewayData);
22616
22720
  },
22617
- opinionHistory(nodeId) {
22618
- return getOpinionHistory(nodeId);
22619
- },
22721
+ opinionHistory: getOpinionHistory,
22620
22722
  createContract(nodeId, input) {
22621
22723
  return beliefsFacade.createContract(nodeId, input).then(exposeGatewayData);
22622
22724
  },
@@ -22870,10 +22972,10 @@ function createLucernClient(config = {}) {
22870
22972
  }));
22871
22973
  },
22872
22974
  getHighPriority(args) {
22873
- return this.list({
22975
+ return questionsFacade.list({
22874
22976
  topicId: requireTopicId4(args),
22875
22977
  status: args.includeAnswered ? void 0 : "open"
22876
- }).then((data) => {
22978
+ }).then(exposeGatewayData).then((data) => {
22877
22979
  const questions = Array.isArray(data.questions) ? data.questions : [];
22878
22980
  const rank = (priority) => {
22879
22981
  switch (priority) {
@@ -22903,9 +23005,7 @@ function createLucernClient(config = {}) {
22903
23005
  },
22904
23006
  graph: {
22905
23007
  nodes: nodesNamespace,
22906
- createEdge(input) {
22907
- return graphClient.createEdge(input);
22908
- },
23008
+ createEdge: graphClient.createEdge,
22909
23009
  neighborhood(args) {
22910
23010
  return graphFacade.neighborhood({
22911
23011
  globalId: args.globalId,
@@ -22964,7 +23064,7 @@ function createLucernClient(config = {}) {
22964
23064
  bisectConfidence,
22965
23065
  listBeliefs,
22966
23066
  detectConfirmationBias(topicId, threshold) {
22967
- return this.bias({
23067
+ return graphFacade.bias({
22968
23068
  topicId,
22969
23069
  threshold,
22970
23070
  limit: 200
@@ -22975,7 +23075,7 @@ function createLucernClient(config = {}) {
22975
23075
  }));
22976
23076
  },
22977
23077
  getStructureAnalysis(topicId) {
22978
- return this.analyze({
23078
+ return graphFacade.analyze({
22979
23079
  topicId,
22980
23080
  limit: 200
22981
23081
  }).then((response) => ({
@@ -23042,38 +23142,20 @@ function createLucernClient(config = {}) {
23042
23142
  }
23043
23143
  },
23044
23144
  judgments: {
23045
- create(input) {
23046
- return decisionsClient.createJudgment(input);
23047
- },
23048
- record(input) {
23049
- return decisionsClient.recordJudgment(input);
23050
- },
23051
- list(query5) {
23052
- return decisionsClient.listJudgments(query5);
23053
- },
23054
- get(judgmentId) {
23055
- return decisionsClient.getJudgment(judgmentId);
23056
- },
23057
- recordOutcome(judgmentId, input) {
23058
- return decisionsClient.recordJudgmentOutcome(judgmentId, input);
23059
- },
23060
- updateOutcome(judgmentId, input) {
23061
- return decisionsClient.updateJudgmentOutcome(judgmentId, input);
23062
- },
23145
+ create: decisionsClient.createJudgment,
23146
+ record: decisionsClient.recordJudgment,
23147
+ list: decisionsClient.listJudgments,
23148
+ get: decisionsClient.getJudgment,
23149
+ recordOutcome: decisionsClient.recordJudgmentOutcome,
23150
+ updateOutcome: decisionsClient.updateJudgmentOutcome,
23063
23151
  readiness(topicId) {
23064
- return decisionsClient.getJudgmentReadiness({
23065
- topicId
23066
- });
23152
+ return decisionsClient.getJudgmentReadiness({ topicId });
23067
23153
  },
23068
23154
  calibration(topicId) {
23069
- return decisionsClient.getJudgmentCalibration({
23070
- topicId
23071
- });
23155
+ return decisionsClient.getJudgmentCalibration({ topicId });
23072
23156
  },
23073
23157
  pendingOutcomeReview(topicId) {
23074
- return decisionsClient.listPendingJudgmentOutcomeReview({
23075
- topicId
23076
- });
23158
+ return decisionsClient.listPendingJudgmentOutcomeReview({ topicId });
23077
23159
  },
23078
23160
  transitionAuditIntegrity(args) {
23079
23161
  return decisionsClient.getJudgmentTransitionAuditIntegrity({
@@ -23083,21 +23165,11 @@ function createLucernClient(config = {}) {
23083
23165
  }
23084
23166
  },
23085
23167
  decisions: {
23086
- create(input) {
23087
- return decisionsClient.createJudgment(input);
23088
- },
23089
- record(input) {
23090
- return decisionsClient.recordJudgment(input);
23091
- },
23092
- list(query5) {
23093
- return decisionsClient.listJudgments(query5);
23094
- },
23095
- get(decisionId) {
23096
- return decisionsClient.getJudgment(decisionId);
23097
- },
23098
- recordOutcome(decisionId, input) {
23099
- return decisionsClient.recordJudgmentOutcome(decisionId, input);
23100
- },
23168
+ create: decisionsClient.createJudgment,
23169
+ record: decisionsClient.recordJudgment,
23170
+ list: decisionsClient.listJudgments,
23171
+ get: decisionsClient.getJudgment,
23172
+ recordOutcome: decisionsClient.recordJudgmentOutcome,
23101
23173
  lessons(decisionId, input, idempotencyKey) {
23102
23174
  return gateway.request({
23103
23175
  path: `/api/platform/v1/decisions/${encodeURIComponent(
@@ -23129,21 +23201,11 @@ function createLucernClient(config = {}) {
23129
23201
  }
23130
23202
  },
23131
23203
  worktrees: {
23132
- createBranch(input) {
23133
- return workflowClient.createBranch(input);
23134
- },
23135
- createLens(input) {
23136
- return workflowClient.createLens(input);
23137
- },
23138
- listLenses(query5) {
23139
- return workflowClient.listLenses(query5);
23140
- },
23141
- applyLensToTopic(input) {
23142
- return workflowClient.applyLensToTopic(input);
23143
- },
23144
- removeLensFromTopic(input) {
23145
- return workflowClient.removeLensFromTopic(input);
23146
- },
23204
+ createBranch: workflowClient.createBranch,
23205
+ createLens: workflowClient.createLens,
23206
+ listLenses: workflowClient.listLenses,
23207
+ applyLensToTopic: workflowClient.applyLensToTopic,
23208
+ removeLensFromTopic: workflowClient.removeLensFromTopic,
23147
23209
  create(input) {
23148
23210
  return worktreesFacade.create({
23149
23211
  title: input.title,
@@ -23248,7 +23310,9 @@ function createLucernClient(config = {}) {
23248
23310
  const dependsOn = Array.isArray(input.dependsOn) ? input.dependsOn.filter(
23249
23311
  (value) => typeof value === "string"
23250
23312
  ) : void 0;
23251
- const blocks = Array.isArray(input.blocks) ? input.blocks.filter((value) => typeof value === "string") : void 0;
23313
+ const blocks = Array.isArray(input.blocks) ? input.blocks.filter(
23314
+ (value) => typeof value === "string"
23315
+ ) : void 0;
23252
23316
  return worktreesFacade.update({
23253
23317
  id: typeof input.worktreeId === "string" ? input.worktreeId : "",
23254
23318
  hypothesis: typeof input.hypothesis === "string" ? input.hypothesis : void 0,
@@ -23262,7 +23326,23 @@ function createLucernClient(config = {}) {
23262
23326
  });
23263
23327
  },
23264
23328
  update(input) {
23265
- return this.updateMetadata(input);
23329
+ const dependsOn = Array.isArray(input.dependsOn) ? input.dependsOn.filter(
23330
+ (value) => typeof value === "string"
23331
+ ) : void 0;
23332
+ const blocks = Array.isArray(input.blocks) ? input.blocks.filter(
23333
+ (value) => typeof value === "string"
23334
+ ) : void 0;
23335
+ return worktreesFacade.update({
23336
+ id: typeof input.worktreeId === "string" ? input.worktreeId : "",
23337
+ hypothesis: typeof input.hypothesis === "string" ? input.hypothesis : void 0,
23338
+ campaign: typeof input.campaign === "number" ? input.campaign : void 0,
23339
+ lane: typeof input.lane === "string" ? input.lane : void 0,
23340
+ laneOrderInCampaign: typeof input.laneOrderInCampaign === "number" ? input.laneOrderInCampaign : void 0,
23341
+ orderInLane: typeof input.orderInLane === "number" ? input.orderInLane : void 0,
23342
+ dependsOn,
23343
+ blocks,
23344
+ gate: typeof input.gate === "string" ? input.gate : void 0
23345
+ });
23266
23346
  },
23267
23347
  updateTargets(input) {
23268
23348
  return worktreesFacade.updateTargets({
@@ -23273,9 +23353,7 @@ function createLucernClient(config = {}) {
23273
23353
  removeQuestionIds: input.removeQuestionIds
23274
23354
  });
23275
23355
  },
23276
- listAll(query5 = {}) {
23277
- return workflowClient.listAllWorktrees(query5);
23278
- },
23356
+ listAll: workflowClient.listAllWorktrees,
23279
23357
  merge(worktreeId, input) {
23280
23358
  return worktreesFacade.merge({
23281
23359
  id: worktreeId,
@@ -23283,18 +23361,12 @@ function createLucernClient(config = {}) {
23283
23361
  summary: input.summary
23284
23362
  });
23285
23363
  },
23286
- push(worktreeId, input) {
23287
- return workflowClient.push(worktreeId, input);
23288
- },
23289
- openPullRequest(worktreeId, input) {
23290
- return workflowClient.openPullRequest(worktreeId, input);
23291
- },
23364
+ push: workflowClient.push,
23365
+ openPullRequest: workflowClient.openPullRequest,
23292
23366
  pipelineSnapshot(topicId) {
23293
23367
  return functionSurfaceClient.pipelineSnapshot({ topicId });
23294
23368
  },
23295
- complete(input, idempotencyKey) {
23296
- return worktreesFacade.complete(input, idempotencyKey);
23297
- },
23369
+ complete: worktreesFacade.complete,
23298
23370
  advancePhase(worktreeId, idempotencyKey) {
23299
23371
  return worktreesFacade.advancePhase(
23300
23372
  { worktreeId },
@@ -23307,12 +23379,8 @@ function createLucernClient(config = {}) {
23307
23379
  idempotencyKey
23308
23380
  );
23309
23381
  },
23310
- patchState(input, idempotencyKey) {
23311
- return worktreesFacade.patchState(input, idempotencyKey);
23312
- },
23313
- bulkCreate(input, idempotencyKey) {
23314
- return worktreesFacade.bulkCreate(input, idempotencyKey);
23315
- }
23382
+ patchState: worktreesFacade.patchState,
23383
+ bulkCreate: worktreesFacade.bulkCreate
23316
23384
  },
23317
23385
  context: {
23318
23386
  listTopics(query5 = {}) {
@@ -23323,27 +23391,15 @@ function createLucernClient(config = {}) {
23323
23391
  type: query5.type
23324
23392
  });
23325
23393
  },
23326
- compile(topicId, input = {}) {
23327
- return contextClient.compile(topicId, input);
23328
- },
23329
- recordScopeLearning(input, idempotencyKey) {
23330
- return functionSurfaceClient.recordScopeLearning(input, idempotencyKey);
23331
- },
23394
+ compile: contextClient.compile,
23395
+ recordScopeLearning: functionSurfaceClient.recordScopeLearning,
23332
23396
  discover(input) {
23333
23397
  return discoverTopics(input);
23334
23398
  },
23335
- analyzeTopicDensity(input) {
23336
- return functionSurfaceClient.analyzeTopicDensity(input);
23337
- },
23338
- applyAutoBranching(input, idempotencyKey) {
23339
- return functionSurfaceClient.applyAutoBranching(input, idempotencyKey);
23340
- },
23341
- seedBeliefLattice(input = {}, idempotencyKey) {
23342
- return functionSurfaceClient.seedBeliefLattice(input, idempotencyKey);
23343
- },
23344
- getLatticeCoverage(input = {}) {
23345
- return functionSurfaceClient.getLatticeCoverage(input);
23346
- },
23399
+ analyzeTopicDensity: functionSurfaceClient.analyzeTopicDensity,
23400
+ applyAutoBranching: functionSurfaceClient.applyAutoBranching,
23401
+ seedBeliefLattice: functionSurfaceClient.seedBeliefLattice,
23402
+ getLatticeCoverage: functionSurfaceClient.getLatticeCoverage,
23347
23403
  matchEntityType(input) {
23348
23404
  return ontologiesFacade.match(input).then(exposeGatewayData);
23349
23405
  },
@@ -23428,9 +23484,7 @@ function createLucernClient(config = {}) {
23428
23484
  type: input.type
23429
23485
  });
23430
23486
  },
23431
- get(topicId) {
23432
- return topicsFacade.get(topicId);
23433
- },
23487
+ get: topicsFacade.get,
23434
23488
  create(input) {
23435
23489
  return topicsFacade.create({
23436
23490
  name: input.name,
@@ -23475,12 +23529,8 @@ function createLucernClient(config = {}) {
23475
23529
  maxDepth: query5.maxDepth
23476
23530
  });
23477
23531
  },
23478
- remove(topicId, idempotencyKey) {
23479
- return topicsFacade.remove(topicId, idempotencyKey);
23480
- },
23481
- bulkCreate(input, idempotencyKey) {
23482
- return topicsFacade.bulkCreate(input, idempotencyKey);
23483
- }
23532
+ remove: topicsFacade.remove,
23533
+ bulkCreate: topicsFacade.bulkCreate
23484
23534
  },
23485
23535
  answers: {
23486
23536
  create(input) {
@@ -23579,33 +23629,15 @@ function createLucernClient(config = {}) {
23579
23629
  raw: ontologyClient
23580
23630
  },
23581
23631
  coordination: {
23582
- registerSession(input = {}, idempotencyKey) {
23583
- return functionSurfaceClient.registerSession(input, idempotencyKey);
23584
- },
23585
- heartbeatSession(input = {}, idempotencyKey) {
23586
- return functionSurfaceClient.heartbeatSession(input, idempotencyKey);
23587
- },
23588
- endSession(input = {}, idempotencyKey) {
23589
- return functionSurfaceClient.endSession(input, idempotencyKey);
23590
- },
23591
- listActiveSessions(input = {}) {
23592
- return functionSurfaceClient.listActiveSessions(input);
23593
- },
23594
- sendAgentMessage(input, idempotencyKey) {
23595
- return functionSurfaceClient.sendAgentMessage(input, idempotencyKey);
23596
- },
23597
- broadcastMessage(input, idempotencyKey) {
23598
- return functionSurfaceClient.broadcastMessage(input, idempotencyKey);
23599
- },
23600
- getInbox(input = {}) {
23601
- return functionSurfaceClient.getAgentInbox(input);
23602
- },
23603
- getAgentInbox(input = {}) {
23604
- return functionSurfaceClient.getAgentInbox(input);
23605
- },
23606
- claimFiles(input, idempotencyKey) {
23607
- return functionSurfaceClient.claimFiles(input, idempotencyKey);
23608
- }
23632
+ registerSession: functionSurfaceClient.registerSession,
23633
+ heartbeatSession: functionSurfaceClient.heartbeatSession,
23634
+ endSession: functionSurfaceClient.endSession,
23635
+ listActiveSessions: functionSurfaceClient.listActiveSessions,
23636
+ sendAgentMessage: functionSurfaceClient.sendAgentMessage,
23637
+ broadcastMessage: functionSurfaceClient.broadcastMessage,
23638
+ getInbox: functionSurfaceClient.getAgentInbox,
23639
+ getAgentInbox: functionSurfaceClient.getAgentInbox,
23640
+ claimFiles: functionSurfaceClient.claimFiles
23609
23641
  },
23610
23642
  policy: {
23611
23643
  checkPermission(input) {
@@ -23636,38 +23668,24 @@ function createLucernClient(config = {}) {
23636
23668
  principalId: typeof input.principalId === "string" ? input.principalId : void 0
23637
23669
  });
23638
23670
  },
23671
+ // Backward compatibility shim: keep the policy namespace exposing the
23672
+ // historical manageWritePolicy entry point.
23639
23673
  manageWritePolicy(input, idempotencyKey) {
23640
23674
  return functionSurfaceClient.manageWritePolicy(input, idempotencyKey);
23641
23675
  },
23642
23676
  raw: policyClient
23643
23677
  },
23644
23678
  observations: {
23645
- ingest(input, idempotencyKey) {
23646
- return functionSurfaceClient.ingestObservation(input, idempotencyKey);
23647
- },
23648
- ingestObservation(input, idempotencyKey) {
23649
- return functionSurfaceClient.ingestObservation(input, idempotencyKey);
23650
- },
23651
- getContext(input) {
23652
- return functionSurfaceClient.getObservationContext(input);
23653
- },
23654
- getObservationContext(input) {
23655
- return functionSurfaceClient.getObservationContext(input);
23656
- }
23679
+ ingest: functionSurfaceClient.ingestObservation,
23680
+ ingestObservation: functionSurfaceClient.ingestObservation,
23681
+ getContext: functionSurfaceClient.getObservationContext,
23682
+ getObservationContext: functionSurfaceClient.getObservationContext
23657
23683
  },
23658
23684
  coding: {
23659
- getCodeContext(input) {
23660
- return functionSurfaceClient.getCodeContext(input);
23661
- },
23662
- getChangeHistory(input) {
23663
- return functionSurfaceClient.getChangeHistory(input);
23664
- },
23665
- recordAttempt(input, idempotencyKey) {
23666
- return functionSurfaceClient.recordAttempt(input, idempotencyKey);
23667
- },
23668
- getFailureLog(input) {
23669
- return functionSurfaceClient.getFailureLog(input);
23670
- }
23685
+ getCodeContext: functionSurfaceClient.getCodeContext,
23686
+ getChangeHistory: functionSurfaceClient.getChangeHistory,
23687
+ recordAttempt: functionSurfaceClient.recordAttempt,
23688
+ getFailureLog: functionSurfaceClient.getFailureLog
23671
23689
  },
23672
23690
  contracts: {
23673
23691
  create(input) {
@@ -23693,9 +23711,7 @@ function createLucernClient(config = {}) {
23693
23711
  }
23694
23712
  },
23695
23713
  bootstrap: {
23696
- generateSessionHandoff(input) {
23697
- return functionSurfaceClient.generateSessionHandoff(input);
23698
- }
23714
+ generateSessionHandoff: functionSurfaceClient.generateSessionHandoff
23699
23715
  },
23700
23716
  embeddings: embeddingsClient,
23701
23717
  graphAnalysis: graphAnalysisClient,
@@ -23717,25 +23733,15 @@ function createLucernClient(config = {}) {
23717
23733
  createAcl: toolRegistryClient.createAcl,
23718
23734
  deleteAcl: toolRegistryClient.deleteAcl,
23719
23735
  registerCustomTool: toolRegistryClient.registerCustomTool,
23720
- register(registration) {
23721
- return registerCustomTool(registration);
23722
- },
23723
- unregister(fullName) {
23724
- return unregisterCustomTool(fullName);
23725
- },
23726
- list() {
23727
- return listRegisteredCustomTools();
23728
- },
23729
- clear() {
23730
- clearRegisteredCustomTools();
23731
- },
23736
+ register: registerCustomTool,
23737
+ unregister: unregisterCustomTool,
23738
+ list: listRegisteredCustomTools,
23739
+ clear: clearRegisteredCustomTools,
23732
23740
  invoke(name, input = {}) {
23733
23741
  const fullName = name.includes(".") ? name : `custom.${name}`;
23734
23742
  return invokeCustomTool(fullName, input);
23735
23743
  },
23736
- namespace(namespace) {
23737
- return getCustomNamespace(namespace);
23738
- }
23744
+ namespace: getCustomNamespace
23739
23745
  },
23740
23746
  packs: {
23741
23747
  /**
@@ -23750,27 +23756,13 @@ function createLucernClient(config = {}) {
23750
23756
  get isInstalled() {
23751
23757
  return _packInstalled;
23752
23758
  },
23753
- listCatalog() {
23754
- return packsClient.listCatalog();
23755
- },
23756
- catalog() {
23757
- return packsClient.getCatalog();
23758
- },
23759
- listStates(scope) {
23760
- return packsClient.listStates(scope);
23761
- },
23762
- states(scope) {
23763
- return packsClient.getStates(scope);
23764
- },
23765
- install(input) {
23766
- return packsClient.install(input);
23767
- },
23768
- enable(input) {
23769
- return packsClient.enable(input);
23770
- },
23771
- disable(input) {
23772
- return packsClient.disable(input);
23773
- }
23759
+ listCatalog: packsClient.listCatalog,
23760
+ catalog: packsClient.listCatalog,
23761
+ listStates: packsClient.listStates,
23762
+ states: packsClient.getStates,
23763
+ install: packsClient.install,
23764
+ enable: packsClient.enable,
23765
+ disable: packsClient.disable
23774
23766
  },
23775
23767
  nodes: nodesNamespace,
23776
23768
  identity: {
@@ -23783,30 +23775,16 @@ function createLucernClient(config = {}) {
23783
23775
  raw: identityClient
23784
23776
  },
23785
23777
  mcp: {
23786
- bootstrapSession(input) {
23787
- return mcpClient.bootstrapSession(input);
23788
- },
23789
- checkWritePolicy(input) {
23790
- return mcpClient.checkWritePolicy(input);
23791
- },
23792
- beginBuildSession(input) {
23793
- return mcpClient.beginBuildSession(input);
23794
- },
23795
- evaluateEngineeringContract(input) {
23796
- return mcpClient.evaluateEngineeringContract(input);
23797
- },
23798
- evaluateResearchContract(input) {
23799
- return mcpClient.evaluateResearchContract(input);
23800
- }
23778
+ bootstrapSession: mcpClient.bootstrapSession,
23779
+ checkWritePolicy: mcpClient.checkWritePolicy,
23780
+ beginBuildSession: mcpClient.beginBuildSession,
23781
+ evaluateEngineeringContract: mcpClient.evaluateEngineeringContract,
23782
+ evaluateResearchContract: mcpClient.evaluateResearchContract
23801
23783
  },
23802
23784
  auth: {
23803
23785
  device: {
23804
- createCode(input) {
23805
- return authDeviceClient.createDeviceCode(input);
23806
- },
23807
- pollToken(deviceCode) {
23808
- return authDeviceClient.pollDeviceToken(deviceCode);
23809
- }
23786
+ createCode: authDeviceClient.createDeviceCode,
23787
+ pollToken: authDeviceClient.pollDeviceToken
23810
23788
  }
23811
23789
  },
23812
23790
  custom: getCustomNamespace("custom"),
@@ -23992,17 +23970,11 @@ var TOKENS_PER_WORD = 1.35;
23992
23970
  var MIN_TOKEN_ESTIMATE = 8;
23993
23971
 
23994
23972
  // ../sdk/src/contextPackPolicy.ts
23995
- function nowMs() {
23996
- return Date.now();
23997
- }
23998
- function normalizeText(text) {
23999
- return text.trim().toLowerCase();
24000
- }
24001
23973
  function tokenHits(text, tokens) {
24002
23974
  if (tokens.length === 0) {
24003
23975
  return 1;
24004
23976
  }
24005
- const haystack = normalizeText(text);
23977
+ const haystack = text.trim().toLowerCase();
24006
23978
  let hits = 0;
24007
23979
  for (const token of tokens) {
24008
23980
  if (haystack.includes(token)) {
@@ -24017,7 +23989,7 @@ function clamp013(value) {
24017
23989
  }
24018
23990
  return Math.max(0, Math.min(1, value));
24019
23991
  }
24020
- function recencyScore(updatedAt, referenceTimeMs = nowMs()) {
23992
+ function recencyScore(updatedAt, referenceTimeMs = Date.now()) {
24021
23993
  if (!updatedAt || !Number.isFinite(updatedAt)) {
24022
23994
  return 0.25;
24023
23995
  }
@@ -24033,15 +24005,15 @@ function confidenceScore(confidence) {
24033
24005
  return clamp013(confidence);
24034
24006
  }
24035
24007
  function priorityScore(priority) {
24036
- const value = normalizeText(priority || "");
24008
+ const value = (priority || "").trim().toLowerCase();
24037
24009
  return PRIORITY_SCORES[value] ?? DEFAULT_PRIORITY_SCORE;
24038
24010
  }
24039
24011
  function severityScore(severity) {
24040
- const value = normalizeText(severity || "");
24012
+ const value = (severity || "").trim().toLowerCase();
24041
24013
  return SEVERITY_SCORES[value] ?? DEFAULT_SEVERITY_SCORE;
24042
24014
  }
24043
24015
  function beliefTypeBonus(beliefType) {
24044
- const value = normalizeText(beliefType || "");
24016
+ const value = (beliefType || "").trim().toLowerCase();
24045
24017
  return BELIEF_TYPE_BONUS[value] ?? DEFAULT_BELIEF_TYPE_BONUS;
24046
24018
  }
24047
24019
  function resolveEffectiveWeights(overrides) {
@@ -24067,7 +24039,7 @@ function generateJustification(_section, candidate, queryTokens, weights) {
24067
24039
  }
24068
24040
  const ts = candidate.updatedAt || candidate.createdAt || null;
24069
24041
  if (ts && Number.isFinite(ts)) {
24070
- const ageDays = Math.max(0, nowMs() - ts) / (1e3 * 60 * 60 * 24);
24042
+ const ageDays = Math.max(0, Date.now() - ts) / (1e3 * 60 * 60 * 24);
24071
24043
  if (ageDays < 1) {
24072
24044
  parts.push("updated today");
24073
24045
  } else if (ageDays < 7) {
@@ -24092,10 +24064,6 @@ function generateJustification(_section, candidate, queryTokens, weights) {
24092
24064
  }
24093
24065
  return parts.join(", ");
24094
24066
  }
24095
- function computeBaselineScore(candidate, queryTokens) {
24096
- const hits = tokenHits(candidate.text, queryTokens);
24097
- return queryTokens.length === 0 ? 1 : hits;
24098
- }
24099
24067
  function computeWeightedScore(section, candidate, queryTokens, effectiveWeights, referenceTimeMs) {
24100
24068
  const weights = (effectiveWeights ?? RANKING_WEIGHTS)[section];
24101
24069
  const queryComponent = queryTokens.length === 0 ? 0.4 : clamp013(tokenHits(candidate.text, queryTokens) / queryTokens.length);
@@ -24129,7 +24097,7 @@ function rankContextSection(section, rows, queryTokens, limit, profile, options)
24129
24097
  queryTokens,
24130
24098
  effectiveWeights,
24131
24099
  referenceTimeMs
24132
- ) : computeBaselineScore(row, queryTokens);
24100
+ ) : queryTokens.length === 0 ? 1 : tokenHits(row.text, queryTokens);
24133
24101
  const result = { ...row, score };
24134
24102
  if (includeJustifications && profile === "weighted_v1") {
24135
24103
  const weights = (effectiveWeights ?? RANKING_WEIGHTS)[section];
@@ -24496,18 +24464,21 @@ function normalizeQueryTokens(query5) {
24496
24464
  function parseRankingProfile(value) {
24497
24465
  return value === "baseline_v1" ? "baseline_v1" : "weighted_v1";
24498
24466
  }
24467
+ function isRecord9(value) {
24468
+ return value !== null && typeof value === "object" && !Array.isArray(value);
24469
+ }
24499
24470
  function beliefTypeOf(node) {
24500
24471
  if (typeof node.beliefType === "string") {
24501
24472
  return node.beliefType;
24502
24473
  }
24503
- const metadata = node.metadata || {};
24474
+ const metadata = isRecord9(node.metadata) ? node.metadata : {};
24504
24475
  if (typeof metadata.beliefType === "string") {
24505
24476
  return metadata.beliefType;
24506
24477
  }
24507
24478
  return "";
24508
24479
  }
24509
24480
  function questionStatusOf(node) {
24510
- const metadata = node.metadata || {};
24481
+ const metadata = isRecord9(node.metadata) ? node.metadata : {};
24511
24482
  const direct = typeof node.status === "string" ? node.status : "";
24512
24483
  const questionStatus = typeof metadata.questionStatus === "string" ? metadata.questionStatus : "";
24513
24484
  return (questionStatus || direct || "open").toLowerCase();
@@ -24523,9 +24494,6 @@ function isOpenQuestion(status) {
24523
24494
  "belief_forked"
24524
24495
  ].includes(status);
24525
24496
  }
24526
- function metadataText(payload) {
24527
- return JSON.stringify(payload).toLowerCase();
24528
- }
24529
24497
  function collectTopicNeighborhood(topics2, rootTopicId, maxDescendantDepth = 2) {
24530
24498
  const byId = /* @__PURE__ */ new Map();
24531
24499
  const children = /* @__PURE__ */ new Map();
@@ -24587,11 +24555,10 @@ function dedupeById(rows) {
24587
24555
  return output;
24588
24556
  }
24589
24557
  function candidateTimestamp(candidate) {
24590
- if (!candidate || typeof candidate !== "object") {
24558
+ if (!isRecord9(candidate)) {
24591
24559
  return 0;
24592
24560
  }
24593
- const record = candidate;
24594
- const timestamps = [record.updatedAt, record.createdAt, record.generatedAt].filter(
24561
+ const timestamps = [candidate.updatedAt, candidate.createdAt, candidate.generatedAt].filter(
24595
24562
  (value) => typeof value === "number" && Number.isFinite(value)
24596
24563
  );
24597
24564
  return timestamps.length > 0 ? Math.max(...timestamps) : 0;
@@ -24713,7 +24680,7 @@ function compileContextPackFromSnapshot(snapshot) {
24713
24680
  beliefType: beliefTypeOf(belief) || null,
24714
24681
  status: belief.status || "active",
24715
24682
  updatedAt: belief.updatedAt || belief.createdAt || null,
24716
- metadataText: belief.metadata && typeof belief.metadata === "object" ? metadataText(belief.metadata) : ""
24683
+ metadataText: belief.metadata && typeof belief.metadata === "object" ? JSON.stringify(belief.metadata).toLowerCase() : ""
24717
24684
  }));
24718
24685
  const activeBeliefs = rankContextSection(
24719
24686
  "activeBeliefs",
@@ -24745,7 +24712,7 @@ function compileContextPackFromSnapshot(snapshot) {
24745
24712
  status,
24746
24713
  priority: typeof metadata.priority === "string" ? metadata.priority : "medium",
24747
24714
  updatedAt: question.updatedAt || question.createdAt || null,
24748
- metadataText: metadataText(metadata)
24715
+ metadataText: JSON.stringify(metadata).toLowerCase()
24749
24716
  };
24750
24717
  }).filter((row) => isOpenQuestion(row.status));
24751
24718
  const openQuestions = rankContextSection(
@@ -24777,7 +24744,7 @@ function compileContextPackFromSnapshot(snapshot) {
24777
24744
  kind: typeof metadata.kind === "string" && metadata.kind || "observation",
24778
24745
  createdAt: item.createdAt || null,
24779
24746
  updatedAt: item.updatedAt || item.createdAt || null,
24780
- metadataText: metadataText(metadata)
24747
+ metadataText: JSON.stringify(metadata).toLowerCase()
24781
24748
  };
24782
24749
  });
24783
24750
  const recentEvidence = rankContextSection(
@@ -24859,7 +24826,7 @@ function compileContextPackFromSnapshot(snapshot) {
24859
24826
  let failureContext;
24860
24827
  if (snapshot.plan.includeFailures && snapshot.failures) {
24861
24828
  const allFailures = snapshot.failures.filter((node) => {
24862
- const metadata = node.metadata || {};
24829
+ const metadata = isRecord9(node.metadata) ? node.metadata : {};
24863
24830
  return metadata.failedApproach === true || metadata.isFailedAttempt === true;
24864
24831
  });
24865
24832
  const rankedFailures = rankContextSection(
@@ -24877,7 +24844,7 @@ function compileContextPackFromSnapshot(snapshot) {
24877
24844
  );
24878
24845
  const failures = rankedFailures.map((row) => {
24879
24846
  const original = allFailures.find((node) => String(node._id) === row.id);
24880
- const metadata = original?.metadata || {};
24847
+ const metadata = isRecord9(original?.metadata) ? original?.metadata : {};
24881
24848
  return {
24882
24849
  attemptId: row.id,
24883
24850
  approach: String(row.text || ""),
@@ -25361,9 +25328,7 @@ function lastDelegator(delegationChain) {
25361
25328
 
25362
25329
  // ../sdk/src/contracts/lens-filter.contract.ts
25363
25330
  function isLensFilterCriteria2(value) {
25364
- if (!value || typeof value !== "object") return false;
25365
- const obj = value;
25366
- return typeof obj.version === "number" && typeof obj.kind === "string";
25331
+ return isRecord10(value) && typeof value.version === "number" && typeof value.kind === "string";
25367
25332
  }
25368
25333
  function isTaxonomyFilterCriteriaV12(value) {
25369
25334
  if (!isLensFilterCriteria2(value)) return false;
@@ -25392,6 +25357,9 @@ function validateFilterCriteria2(value) {
25392
25357
  ]
25393
25358
  };
25394
25359
  }
25360
+ function isRecord10(value) {
25361
+ return value !== null && typeof value === "object" && !Array.isArray(value);
25362
+ }
25395
25363
  function validateTaxonomyFilterV1(criteria) {
25396
25364
  const errors = [];
25397
25365
  if (!Array.isArray(criteria.entityTypeFilters)) {
@@ -25898,6 +25866,9 @@ function fromBase64(value) {
25898
25866
  const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
25899
25867
  return decodeURIComponent(escape(atob(normalized)));
25900
25868
  }
25869
+ function isRecord11(value) {
25870
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
25871
+ }
25901
25872
  function createEventId() {
25902
25873
  const random = typeof globalThis.crypto?.randomUUID === "function" ? globalThis.crypto.randomUUID().replace(/-/g, "") : Array.from(
25903
25874
  typeof globalThis.crypto?.getRandomValues === "function" ? globalThis.crypto.getRandomValues(new Uint8Array(16)) : Array.from({ length: 16 }, () => Math.floor(Math.random() * 256)),
@@ -25946,14 +25917,14 @@ function decodeEventCursor(cursor) {
25946
25917
  }
25947
25918
  try {
25948
25919
  const parsed = JSON.parse(fromBase64(cursor.trim()));
25949
- if (typeof parsed.timestamp !== "number" || !Number.isFinite(parsed.timestamp) || typeof parsed.eventId !== "string" || parsed.eventId.trim().length === 0) {
25920
+ if (!isRecord11(parsed) || typeof parsed.timestamp !== "number" || !Number.isFinite(parsed.timestamp) || typeof parsed.eventId !== "string" || parsed.eventId.trim().length === 0) {
25950
25921
  return null;
25951
25922
  }
25952
25923
  return {
25953
25924
  timestamp: parsed.timestamp,
25954
25925
  eventId: parsed.eventId.trim()
25955
25926
  };
25956
- } catch {
25927
+ } catch (error) {
25957
25928
  return null;
25958
25929
  }
25959
25930
  }
@@ -25982,7 +25953,7 @@ var LOCALHOST_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1"])
25982
25953
  function normalizeUrl(url) {
25983
25954
  try {
25984
25955
  return new URL(url.trim());
25985
- } catch {
25956
+ } catch (error) {
25986
25957
  throw new Error("Webhook URL must be a valid absolute URL.");
25987
25958
  }
25988
25959
  }
@@ -26228,6 +26199,9 @@ function hasValue(value) {
26228
26199
  }
26229
26200
  return true;
26230
26201
  }
26202
+ function isRecord12(value) {
26203
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
26204
+ }
26231
26205
  function normalizeToolExecutionParams(params) {
26232
26206
  const normalized = { ...params };
26233
26207
  for (const aliases of SCOPE_ALIAS_GROUPS) {
@@ -26250,16 +26224,19 @@ function parseToolExecutionMetadata(result) {
26250
26224
  }
26251
26225
  try {
26252
26226
  const payload = JSON.parse(raw);
26227
+ if (!isRecord12(payload)) {
26228
+ return { isError: Boolean(result.isError) };
26229
+ }
26253
26230
  return {
26254
26231
  isError: Boolean(result.isError),
26255
26232
  code: typeof payload.code === "string" ? payload.code : void 0,
26256
26233
  status: typeof payload.status === "number" ? payload.status : void 0,
26257
- correlationId: typeof payload.correlationId === "string" || payload.correlationId === null ? payload.correlationId : void 0,
26258
- policyTraceId: typeof payload.policyTraceId === "string" || payload.policyTraceId === null ? payload.policyTraceId : void 0,
26259
- invariant: typeof payload.invariant === "string" || payload.invariant === null ? payload.invariant : void 0
26234
+ correlationId: optionalStringOrNull(payload.correlationId),
26235
+ policyTraceId: optionalStringOrNull(payload.policyTraceId),
26236
+ invariant: optionalStringOrNull(payload.invariant)
26260
26237
  };
26261
- } catch {
26262
- return { isError: Boolean(result.isError) };
26238
+ } catch (error) {
26239
+ return ignoreMalformedToolMetadata(error, result);
26263
26240
  }
26264
26241
  }
26265
26242
  async function executeToolWithEnvelope(args) {
@@ -26277,6 +26254,15 @@ async function executeToolWithEnvelope(args) {
26277
26254
  });
26278
26255
  return result;
26279
26256
  }
26257
+ function ignoreMalformedToolMetadata(_error, result) {
26258
+ return { isError: Boolean(result.isError) };
26259
+ }
26260
+ function optionalStringOrNull(value) {
26261
+ if (typeof value === "string" || value === null) {
26262
+ return value;
26263
+ }
26264
+ return void 0;
26265
+ }
26280
26266
 
26281
26267
  // src/types.ts
26282
26268
  var McpHandlerError = class extends Error {
@@ -27786,18 +27772,22 @@ function createWorktreeHandlers(context) {
27786
27772
  MCP_TOOL_CONTRACTS.add_worktree,
27787
27773
  async (params) => {
27788
27774
  const topicId = readTopicId4(params);
27789
- if (!topicId) {
27790
- throw new Error("add_worktree requires topicId");
27791
- }
27792
27775
  const result = await workflow.addWorktree({
27793
27776
  title: readString3(params, "title", { required: true }),
27794
27777
  topicId,
27778
+ topicHint: readString3(params, "topicHint"),
27795
27779
  branchId: readString3(params, "branchId"),
27796
27780
  objective: readString3(params, "objective"),
27797
27781
  hypothesis: readString3(params, "hypothesis"),
27782
+ rationale: readString3(params, "rationale"),
27783
+ worktreeType: readString3(params, "worktreeType"),
27798
27784
  beliefIds: readStringArray(params, "beliefIds"),
27799
27785
  autoShape: readBoolean(params, "autoShape"),
27800
27786
  domainPackId: readString3(params, "domainPackId"),
27787
+ tags: readStringArray(params, "tags"),
27788
+ touchedPaths: readStringArray(params, "touchedPaths"),
27789
+ sourceRef: readString3(params, "sourceRef"),
27790
+ sourceKind: readString3(params, "sourceKind"),
27801
27791
  campaign: typeof params.campaign === "number" ? params.campaign : void 0,
27802
27792
  lane: readString3(params, "lane"),
27803
27793
  laneOrderInCampaign: typeof params.laneOrderInCampaign === "number" ? params.laneOrderInCampaign : void 0,
@@ -27917,8 +27907,8 @@ function loadMcpSdk() {
27917
27907
  try {
27918
27908
  const dynamicRequire = eval("require");
27919
27909
  return dynamicRequire("@modelcontextprotocol/sdk") ?? {};
27920
- } catch {
27921
- return {};
27910
+ } catch (error) {
27911
+ return ignoreMcpSdkLoadError();
27922
27912
  }
27923
27913
  }
27924
27914
  var MCP_AUTH_ERROR_CODES = [
@@ -27997,11 +27987,11 @@ function deriveCustomToolScopes(customTool) {
27997
27987
  return uniqueScopes(customTool.metadata.requiredScopes ?? ["custom:execute"]);
27998
27988
  }
27999
27989
  function createFallbackRuntime() {
27990
+ function noop() {
27991
+ }
28000
27992
  return {
28001
- registerResource: () => {
28002
- },
28003
- registerTool: () => {
28004
- }
27993
+ registerResource: noop,
27994
+ registerTool: noop
28005
27995
  };
28006
27996
  }
28007
27997
  function createMcpRuntime() {
@@ -28015,7 +28005,7 @@ function createMcpRuntime() {
28015
28005
  { name: "lucern-platform-mcp", version: "1.2.0" },
28016
28006
  { capabilities: { resources: {}, tools: {} } }
28017
28007
  );
28018
- } catch {
28008
+ } catch (error) {
28019
28009
  return createFallbackRuntime();
28020
28010
  }
28021
28011
  }
@@ -28039,15 +28029,14 @@ function executeWithHandler(_name, handler, contract, params) {
28039
28029
  }
28040
28030
  }
28041
28031
  function isMcpToolResult(value) {
28042
- if (!value || typeof value !== "object") {
28032
+ if (!isRecord13(value)) {
28043
28033
  return false;
28044
28034
  }
28045
- const candidate = value;
28046
- if (!Array.isArray(candidate.content)) {
28035
+ if (!Array.isArray(value.content)) {
28047
28036
  return false;
28048
28037
  }
28049
- return candidate.content.every((entry) => {
28050
- if (!entry || typeof entry !== "object") {
28038
+ return value.content.every((entry) => {
28039
+ if (!isRecord13(entry)) {
28051
28040
  return false;
28052
28041
  }
28053
28042
  return typeof entry.text === "string";
@@ -28218,6 +28207,12 @@ function createLucernMcpServer(options) {
28218
28207
  unimplementedToolNames
28219
28208
  };
28220
28209
  }
28210
+ function isRecord13(value) {
28211
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
28212
+ }
28213
+ function ignoreMcpSdkLoadError(_error) {
28214
+ return {};
28215
+ }
28221
28216
 
28222
28217
  // src/standalone.ts
28223
28218
  var OBSERVATION_RESOURCE_TEMPLATE = "lucern://observations/topic/{topicId}";
@@ -28259,6 +28254,9 @@ function resourceName(uri) {
28259
28254
  return uri.replace("lucern://", "lucern-").replace(/[{}]/g, "").replace(/[^a-zA-Z0-9]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
28260
28255
  }
28261
28256
  function readTemplateVar(variables, key) {
28257
+ if (!isRecord14(variables)) {
28258
+ return;
28259
+ }
28262
28260
  const value = variables[key];
28263
28261
  if (typeof value === "string") {
28264
28262
  return value;
@@ -28271,7 +28269,7 @@ function readTemplateVar(variables, key) {
28271
28269
  async function notifyResourceUpdated(server, uri) {
28272
28270
  try {
28273
28271
  await server.server.sendResourceUpdated({ uri });
28274
- } catch {
28272
+ } catch (error) {
28275
28273
  }
28276
28274
  }
28277
28275
  function registerResources(server, runtime, observationStore) {
@@ -28332,10 +28330,7 @@ function registerResources(server, runtime, observationStore) {
28332
28330
  mimeType: "application/json"
28333
28331
  },
28334
28332
  async (_uri, variables) => {
28335
- const topicId = readTemplateVar(
28336
- variables,
28337
- "topicId"
28338
- );
28333
+ const topicId = readTemplateVar(variables, "topicId");
28339
28334
  const records = topicId ? observationStore.list(topicId, 25) : [];
28340
28335
  return {
28341
28336
  contents: [
@@ -28368,9 +28363,8 @@ function registerResources(server, runtime, observationStore) {
28368
28363
  mimeType: "application/json"
28369
28364
  },
28370
28365
  async (_uri, variables) => {
28371
- const values = variables;
28372
- const topicId = readTemplateVar(values, "topicId");
28373
- const query5 = readTemplateVar(values, "query");
28366
+ const topicId = readTemplateVar(variables, "topicId");
28367
+ const query5 = readTemplateVar(variables, "query");
28374
28368
  const matches = topicId && query5 ? observationStore.search(topicId, query5, 25) : [];
28375
28369
  return {
28376
28370
  contents: [
@@ -28403,10 +28397,7 @@ function registerResources(server, runtime, observationStore) {
28403
28397
  mimeType: "application/json"
28404
28398
  },
28405
28399
  async (_uri, variables) => {
28406
- const topicId = readTemplateVar(
28407
- variables,
28408
- "topicId"
28409
- );
28400
+ const topicId = readTemplateVar(variables, "topicId");
28410
28401
  const context = topicId ? observationStore.getContext({ topicId, limit: 12 }) : observationStore.getContext({ topicId: "unknown", limit: 12 });
28411
28402
  return {
28412
28403
  contents: [
@@ -28430,9 +28421,8 @@ function registerResources(server, runtime, observationStore) {
28430
28421
  mimeType: "application/json"
28431
28422
  },
28432
28423
  async (_uri, variables) => {
28433
- const values = variables;
28434
- const topicId = readTemplateVar(values, "topicId");
28435
- const query5 = readTemplateVar(values, "query");
28424
+ const topicId = readTemplateVar(variables, "topicId");
28425
+ const query5 = readTemplateVar(variables, "query");
28436
28426
  const context = observationStore.getContext({
28437
28427
  topicId: topicId ?? "unknown",
28438
28428
  query: query5,
@@ -28458,7 +28448,7 @@ function registerResources(server, runtime, observationStore) {
28458
28448
  await notifyResourceUpdated(server, `lucern://context/topic/${encoded}`);
28459
28449
  try {
28460
28450
  await server.server.sendResourceListChanged();
28461
- } catch {
28451
+ } catch (error) {
28462
28452
  }
28463
28453
  };
28464
28454
  return { resourceUris, notifyObservationChanged };
@@ -28498,15 +28488,14 @@ function registerTools(server, runtime) {
28498
28488
  inputSchema: shape
28499
28489
  },
28500
28490
  async (args) => {
28501
- return handler(args, tool.contract);
28491
+ return handler(isRecord14(args) ? args : {}, tool.contract);
28502
28492
  }
28503
28493
  );
28504
28494
  }
28505
28495
  }
28506
28496
  function createLucernStandaloneMcpServer(options) {
28507
28497
  const observationStore = new McpObservationStore();
28508
- let notifyObservationChanged = async () => {
28509
- };
28498
+ let notifyObservationChanged = noopAsync;
28510
28499
  const runtime = createLucernMcpServer({
28511
28500
  ...options,
28512
28501
  observationStore,
@@ -28516,7 +28505,7 @@ function createLucernStandaloneMcpServer(options) {
28516
28505
  });
28517
28506
  const server = new McpServer({
28518
28507
  name: "lucern-mcp",
28519
- version: "0.2.0-alpha.2"
28508
+ version: "0.3.0-alpha.7"
28520
28509
  });
28521
28510
  registerTools(server, runtime);
28522
28511
  const resources = registerResources(server, runtime, observationStore);
@@ -28539,6 +28528,11 @@ async function startLucernMcpStdioServer(options) {
28539
28528
  await packageServer.server.connect(transport);
28540
28529
  return packageServer;
28541
28530
  }
28531
+ function isRecord14(value) {
28532
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
28533
+ }
28534
+ async function noopAsync() {
28535
+ }
28542
28536
 
28543
28537
  // src/remote.ts
28544
28538
  function resolveAuthMode(auth) {