@lucern/sdk 0.2.0-alpha.7 → 0.2.0-alpha.9

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.
Files changed (257) hide show
  1. package/dist/adminClient.d.ts +409 -0
  2. package/dist/adminClient.js +755 -0
  3. package/dist/adminClient.js.map +1 -0
  4. package/dist/answersClient.d.ts +23 -0
  5. package/dist/answersClient.js +333 -0
  6. package/dist/answersClient.js.map +1 -0
  7. package/dist/audiencesClient.d.ts +99 -0
  8. package/dist/audiencesClient.js +472 -0
  9. package/dist/audiencesClient.js.map +1 -0
  10. package/dist/auditClient.d.ts +29 -0
  11. package/dist/auditClient.js +386 -0
  12. package/dist/auditClient.js.map +1 -0
  13. package/dist/beliefsClient.d.ts +162 -0
  14. package/dist/beliefsClient.js +477 -0
  15. package/dist/beliefsClient.js.map +1 -0
  16. package/dist/client.d.ts +2378 -0
  17. package/dist/client.js +6134 -0
  18. package/dist/client.js.map +1 -0
  19. package/dist/contextClient.d.ts +27 -0
  20. package/dist/contextClient.js +396 -0
  21. package/dist/contextClient.js.map +1 -0
  22. package/dist/contextFacade.d.ts +2 -0
  23. package/dist/contextFacade.js +73 -0
  24. package/dist/contextFacade.js.map +1 -0
  25. package/dist/contextPackCompiler.d.ts +102 -0
  26. package/dist/contextPackCompiler.js +1091 -0
  27. package/dist/contextPackCompiler.js.map +1 -0
  28. package/dist/contextPackPolicy.d.ts +84 -0
  29. package/dist/contextPackPolicy.js +347 -0
  30. package/dist/contextPackPolicy.js.map +1 -0
  31. package/dist/contextPackSchema.d.ts +7 -0
  32. package/{src/contextPackSchema.ts → dist/contextPackSchema.js} +22 -70
  33. package/dist/contextPackSchema.js.map +1 -0
  34. package/dist/contextTypes.d.ts +135 -0
  35. package/dist/contextTypes.js +3 -0
  36. package/dist/contextTypes.js.map +1 -0
  37. package/dist/contracts/api-enums.contract.d.ts +81 -0
  38. package/dist/contracts/api-enums.contract.js +92 -0
  39. package/dist/contracts/api-enums.contract.js.map +1 -0
  40. package/dist/contracts/auth-session.contract.d.ts +55 -0
  41. package/dist/contracts/auth-session.contract.js +48 -0
  42. package/dist/contracts/auth-session.contract.js.map +1 -0
  43. package/dist/contracts/context-pack.contract.d.ts +492 -0
  44. package/dist/contracts/context-pack.contract.js +98 -0
  45. package/dist/contracts/context-pack.contract.js.map +1 -0
  46. package/dist/contracts/contextPack.d.ts +1 -0
  47. package/dist/contracts/contextPack.js +98 -0
  48. package/dist/contracts/contextPack.js.map +1 -0
  49. package/dist/contracts/index.d.ts +9 -0
  50. package/dist/contracts/index.js +4892 -0
  51. package/dist/contracts/index.js.map +1 -0
  52. package/dist/contracts/lens-filter.contract.d.ts +72 -0
  53. package/dist/contracts/lens-filter.contract.js +71 -0
  54. package/dist/contracts/lens-filter.contract.js.map +1 -0
  55. package/dist/contracts/lens-workflow.contract.d.ts +87 -0
  56. package/dist/contracts/lens-workflow.contract.js +123 -0
  57. package/dist/contracts/lens-workflow.contract.js.map +1 -0
  58. package/dist/contracts/lensFilter.d.ts +1 -0
  59. package/dist/contracts/lensFilter.js +71 -0
  60. package/dist/contracts/lensFilter.js.map +1 -0
  61. package/dist/contracts/lensWorkflow.d.ts +2 -0
  62. package/dist/contracts/lensWorkflow.js +123 -0
  63. package/dist/contracts/lensWorkflow.js.map +1 -0
  64. package/dist/contracts/mcp-tools.contract.d.ts +1 -0
  65. package/dist/contracts/mcp-tools.contract.js +2986 -0
  66. package/dist/contracts/mcp-tools.contract.js.map +1 -0
  67. package/dist/contracts/mcpTools.d.ts +1 -0
  68. package/dist/contracts/mcpTools.js +2986 -0
  69. package/dist/contracts/mcpTools.js.map +1 -0
  70. package/dist/contracts/prompt.contract.d.ts +26 -0
  71. package/dist/contracts/prompt.contract.js +12 -0
  72. package/dist/contracts/prompt.contract.js.map +1 -0
  73. package/dist/contracts/prompt.d.ts +1 -0
  74. package/dist/contracts/prompt.js +12 -0
  75. package/dist/contracts/prompt.js.map +1 -0
  76. package/dist/contracts/sdk-tools.contract.d.ts +2 -0
  77. package/dist/contracts/sdk-tools.contract.js +4134 -0
  78. package/dist/contracts/sdk-tools.contract.js.map +1 -0
  79. package/dist/contracts/sdkTools.d.ts +2 -0
  80. package/dist/contracts/sdkTools.js +4134 -0
  81. package/dist/contracts/sdkTools.js.map +1 -0
  82. package/dist/contracts/workflow-runtime.contract.d.ts +163 -0
  83. package/dist/contracts/workflow-runtime.contract.js +245 -0
  84. package/dist/contracts/workflow-runtime.contract.js.map +1 -0
  85. package/dist/contracts/workflowRuntime.d.ts +1 -0
  86. package/dist/contracts/workflowRuntime.js +245 -0
  87. package/dist/contracts/workflowRuntime.js.map +1 -0
  88. package/dist/controlObjectOwnership.d.ts +310 -0
  89. package/{src/controlObjectOwnership.ts → dist/controlObjectOwnership.js} +53 -124
  90. package/dist/controlObjectOwnership.js.map +1 -0
  91. package/dist/coreClient.d.ts +144 -0
  92. package/dist/coreClient.js +339 -0
  93. package/dist/coreClient.js.map +1 -0
  94. package/dist/customTools.d.ts +88 -0
  95. package/dist/customTools.js +248 -0
  96. package/dist/customTools.js.map +1 -0
  97. package/dist/decisionsClient.d.ts +111 -0
  98. package/dist/decisionsClient.js +522 -0
  99. package/dist/decisionsClient.js.map +1 -0
  100. package/dist/domainContext.d.ts +1 -0
  101. package/dist/domainContext.js +3 -0
  102. package/dist/domainContext.js.map +1 -0
  103. package/dist/events.d.ts +178 -0
  104. package/dist/events.js +249 -0
  105. package/dist/events.js.map +1 -0
  106. package/dist/eventsCore.d.ts +49 -0
  107. package/dist/eventsCore.js +429 -0
  108. package/dist/eventsCore.js.map +1 -0
  109. package/dist/facade/context.d.ts +18 -0
  110. package/dist/facade/context.js +73 -0
  111. package/dist/facade/context.js.map +1 -0
  112. package/dist/gatewayFacades.d.ts +591 -0
  113. package/dist/gatewayFacades.js +1953 -0
  114. package/dist/gatewayFacades.js.map +1 -0
  115. package/dist/graphClient.d.ts +271 -0
  116. package/dist/graphClient.js +698 -0
  117. package/dist/graphClient.js.map +1 -0
  118. package/dist/harnessClient.d.ts +314 -0
  119. package/dist/harnessClient.js +607 -0
  120. package/dist/harnessClient.js.map +1 -0
  121. package/dist/identityClient.d.ts +140 -0
  122. package/dist/identityClient.js +497 -0
  123. package/dist/identityClient.js.map +1 -0
  124. package/dist/index.d.ts +42 -0
  125. package/dist/index.js +11381 -0
  126. package/dist/index.js.map +1 -0
  127. package/dist/learningClient.d.ts +46 -0
  128. package/dist/learningClient.js +409 -0
  129. package/dist/learningClient.js.map +1 -0
  130. package/dist/mcpParityClient.d.ts +74 -0
  131. package/dist/mcpParityClient.js +516 -0
  132. package/dist/mcpParityClient.js.map +1 -0
  133. package/dist/mcpParitySurface.d.ts +12 -0
  134. package/{src/mcpParitySurface.ts → dist/mcpParitySurface.js} +9 -14
  135. package/dist/mcpParitySurface.js.map +1 -0
  136. package/dist/mcpTools-DPZxowDX.d.ts +254 -0
  137. package/dist/ontologyClient.d.ts +137 -0
  138. package/dist/ontologyClient.js +513 -0
  139. package/dist/ontologyClient.js.map +1 -0
  140. package/dist/packRuntime.d.ts +2 -0
  141. package/dist/packRuntime.js +3 -0
  142. package/dist/packRuntime.js.map +1 -0
  143. package/dist/packsClient.d.ts +131 -0
  144. package/dist/packsClient.js +525 -0
  145. package/dist/packsClient.js.map +1 -0
  146. package/dist/policyClient.d.ts +299 -0
  147. package/dist/policyClient.js +625 -0
  148. package/dist/policyClient.js.map +1 -0
  149. package/dist/realtime/index.d.ts +29 -0
  150. package/dist/realtime/index.js +23 -0
  151. package/dist/realtime/index.js.map +1 -0
  152. package/{src/realtime/refs.ts → dist/realtime/refs.d.ts} +5 -5
  153. package/dist/realtime/refs.js +9 -0
  154. package/dist/realtime/refs.js.map +1 -0
  155. package/dist/reportsClient.d.ts +41 -0
  156. package/dist/reportsClient.js +418 -0
  157. package/dist/reportsClient.js.map +1 -0
  158. package/dist/schemaClient.d.ts +64 -0
  159. package/dist/schemaClient.js +434 -0
  160. package/dist/schemaClient.js.map +1 -0
  161. package/dist/sdkSurface.d.ts +61 -0
  162. package/dist/sdkSurface.js +112 -0
  163. package/dist/sdkSurface.js.map +1 -0
  164. package/dist/sdkTools-CwXJDACb.d.ts +150 -0
  165. package/dist/topicsClient.d.ts +84 -0
  166. package/dist/topicsClient.js +492 -0
  167. package/dist/topicsClient.js.map +1 -0
  168. package/dist/types.d.ts +696 -0
  169. package/dist/types.js +3 -0
  170. package/dist/types.js.map +1 -0
  171. package/dist/version.d.ts +4 -0
  172. package/dist/version.js +6 -0
  173. package/dist/version.js.map +1 -0
  174. package/dist/workflowClient.d.ts +316 -0
  175. package/dist/workflowClient.js +830 -0
  176. package/dist/workflowClient.js.map +1 -0
  177. package/package.json +39 -7
  178. package/.turbo/turbo-build.log +0 -7
  179. package/.turbo/turbo-typecheck.log +0 -4
  180. package/examples/README.md +0 -69
  181. package/examples/contradiction.ts +0 -94
  182. package/examples/investigation-context.ts +0 -118
  183. package/examples/questions-and-tasks.ts +0 -55
  184. package/examples/quickstart.ts +0 -97
  185. package/examples/shared.ts +0 -318
  186. package/examples/strict-public-types.ts +0 -143
  187. package/examples/worktree-lifecycle.ts +0 -79
  188. package/src/README.md +0 -6
  189. package/src/adminClient.ts +0 -789
  190. package/src/answersClient.ts +0 -29
  191. package/src/audiencesClient.ts +0 -209
  192. package/src/auditClient.ts +0 -50
  193. package/src/beliefsClient.ts +0 -319
  194. package/src/client.ts +0 -2647
  195. package/src/contextClient.ts +0 -130
  196. package/src/contextFacade.ts +0 -15
  197. package/src/contextPackCompiler.ts +0 -828
  198. package/src/contextTypes.ts +0 -153
  199. package/src/contracts/api-enums.contract.ts +0 -202
  200. package/src/contracts/auth-session.contract.ts +0 -109
  201. package/src/contracts/context-pack.contract.ts +0 -700
  202. package/src/contracts/contextPack.ts +0 -1
  203. package/src/contracts/index.ts +0 -10
  204. package/src/contracts/lens-filter.contract.ts +0 -183
  205. package/src/contracts/lens-workflow.contract.ts +0 -162
  206. package/src/contracts/lensFilter.ts +0 -1
  207. package/src/contracts/lensWorkflow.ts +0 -1
  208. package/src/contracts/mcp-tools.contract.ts +0 -3636
  209. package/src/contracts/mcpTools.ts +0 -1
  210. package/src/contracts/prompt.contract.ts +0 -50
  211. package/src/contracts/prompt.ts +0 -1
  212. package/src/contracts/sdk-tools.contract.ts +0 -1457
  213. package/src/contracts/sdkTools.ts +0 -1
  214. package/src/contracts/workflow-runtime.contract.ts +0 -440
  215. package/src/contracts/workflowRuntime.ts +0 -1
  216. package/src/coreClient.ts +0 -570
  217. package/src/customTools.ts +0 -398
  218. package/src/decisionsClient.ts +0 -286
  219. package/src/domainContext.ts +0 -15
  220. package/src/events.ts +0 -531
  221. package/src/eventsCore.ts +0 -168
  222. package/src/facade/beliefs.ts +0 -83
  223. package/src/facade/context.ts +0 -110
  224. package/src/facade/contradictions.ts +0 -29
  225. package/src/facade/edges.ts +0 -30
  226. package/src/facade/events.ts +0 -23
  227. package/src/facade/evidence.ts +0 -41
  228. package/src/facade/graph.ts +0 -38
  229. package/src/facade/identity.ts +0 -16
  230. package/src/facade/ontologies.ts +0 -34
  231. package/src/facade/questions.ts +0 -59
  232. package/src/facade/search.ts +0 -16
  233. package/src/facade/tasks.ts +0 -37
  234. package/src/facade/topics.ts +0 -42
  235. package/src/facade/webhooks.ts +0 -58
  236. package/src/facade/worktrees.ts +0 -51
  237. package/src/gatewayFacades.ts +0 -1666
  238. package/src/graphClient.ts +0 -529
  239. package/src/harnessClient.ts +0 -585
  240. package/src/identityClient.ts +0 -278
  241. package/src/index.ts +0 -49
  242. package/src/learningClient.ts +0 -95
  243. package/src/mcpParityClient.ts +0 -240
  244. package/src/ontologyClient.ts +0 -275
  245. package/src/packRuntime.ts +0 -3
  246. package/src/packsClient.ts +0 -260
  247. package/src/policyClient.ts +0 -572
  248. package/src/promptCatalog.ts +0 -1
  249. package/src/realtime/index.ts +0 -51
  250. package/src/reportsClient.ts +0 -99
  251. package/src/schemaClient.ts +0 -129
  252. package/src/sdkSurface.ts +0 -190
  253. package/src/topicsClient.ts +0 -243
  254. package/src/types.ts +0 -807
  255. package/src/version.ts +0 -2
  256. package/src/workflowClient.ts +0 -826
  257. package/tsconfig.json +0 -9
@@ -0,0 +1,607 @@
1
+ // src/coreClient.ts
2
+ var LucernApiError = class extends Error {
3
+ code;
4
+ status;
5
+ invariant;
6
+ suggestion;
7
+ details;
8
+ requestId;
9
+ correlationId;
10
+ policyTraceId;
11
+ constructor(args) {
12
+ super(args.message);
13
+ this.name = "LucernApiError";
14
+ this.code = args.code;
15
+ this.status = args.status;
16
+ this.invariant = args.invariant;
17
+ this.suggestion = args.suggestion;
18
+ this.details = args.details;
19
+ this.requestId = args.requestId;
20
+ this.correlationId = args.correlationId;
21
+ this.policyTraceId = args.policyTraceId;
22
+ }
23
+ };
24
+ function toQueryString(scope) {
25
+ const params = new URLSearchParams();
26
+ if (scope.tenantId) {
27
+ params.set("tenantId", scope.tenantId);
28
+ }
29
+ if (scope.workspaceId) {
30
+ params.set("workspaceId", scope.workspaceId);
31
+ }
32
+ for (const [key, value] of Object.entries(scope)) {
33
+ if (key === "tenantId" || key === "workspaceId") {
34
+ continue;
35
+ }
36
+ if (value === void 0) {
37
+ continue;
38
+ }
39
+ params.set(key, String(value));
40
+ }
41
+ const serialized = params.toString();
42
+ return serialized.length > 0 ? `?${serialized}` : "";
43
+ }
44
+ function fillRandomBytes(length) {
45
+ const bytes = new Uint8Array(length);
46
+ if (typeof globalThis.crypto?.getRandomValues === "function") {
47
+ globalThis.crypto.getRandomValues(bytes);
48
+ return bytes;
49
+ }
50
+ for (let index = 0; index < length; index += 1) {
51
+ bytes[index] = Math.floor(Math.random() * 256);
52
+ }
53
+ return bytes;
54
+ }
55
+ function generatePortableRequestId() {
56
+ if (typeof globalThis.crypto?.randomUUID === "function") {
57
+ return globalThis.crypto.randomUUID();
58
+ }
59
+ const bytes = fillRandomBytes(16);
60
+ bytes[6] = bytes[6] & 15 | 64;
61
+ bytes[8] = bytes[8] & 63 | 128;
62
+ const hex = Array.from(bytes, (value) => value.toString(16).padStart(2, "0"));
63
+ return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(
64
+ 6,
65
+ 8
66
+ ).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10).join("")}`;
67
+ }
68
+ function randomIdempotencyKey() {
69
+ return generatePortableRequestId();
70
+ }
71
+ function isRetryableStatus(status) {
72
+ return status >= 500 || status === 408 || status === 429;
73
+ }
74
+ function fallbackErrorCode(status) {
75
+ if (status === 401) {
76
+ return "AUTHENTICATION_REQUIRED";
77
+ }
78
+ if (status === 403) {
79
+ return "FORBIDDEN";
80
+ }
81
+ if (status === 404) {
82
+ return "NOT_FOUND";
83
+ }
84
+ if (status === 408) {
85
+ return "UPSTREAM_ERROR";
86
+ }
87
+ if (status === 409) {
88
+ return "CONFLICT";
89
+ }
90
+ if (status === 429) {
91
+ return "RATE_LIMIT_EXCEEDED";
92
+ }
93
+ if (status >= 500) {
94
+ return "UPSTREAM_ERROR";
95
+ }
96
+ return "INTERNAL_ERROR";
97
+ }
98
+ function delay(ms) {
99
+ return new Promise((resolve) => setTimeout(resolve, ms));
100
+ }
101
+ function parseRetryAfterMs(value) {
102
+ if (!value) {
103
+ return null;
104
+ }
105
+ const trimmed = value.trim();
106
+ if (!trimmed) {
107
+ return null;
108
+ }
109
+ const numeric = Number(trimmed);
110
+ if (Number.isFinite(numeric)) {
111
+ return Math.max(0, Math.round(numeric * 1e3));
112
+ }
113
+ const parsedDate = Date.parse(trimmed);
114
+ if (Number.isFinite(parsedDate)) {
115
+ return Math.max(0, parsedDate - Date.now());
116
+ }
117
+ return null;
118
+ }
119
+ function computeRetryDelayMs(args) {
120
+ const baseDelay = args.status === 429 ? Math.max(
121
+ args.retryAfterMs ?? 0,
122
+ Math.min(1e3 * 2 ** args.attempt, 1e4)
123
+ ) : Math.min(1e3 * 2 ** args.attempt, 4e3);
124
+ if (args.status !== 429) {
125
+ return baseDelay;
126
+ }
127
+ const jitterWindow = Math.max(250, Math.round(baseDelay * 0.25));
128
+ return baseDelay + Math.round(Math.random() * jitterWindow);
129
+ }
130
+ function timeoutError(timeoutMs) {
131
+ const error = new Error(`Request timed out after ${timeoutMs}ms`);
132
+ error.name = "AbortError";
133
+ return error;
134
+ }
135
+ function readPolicySummaryFromDetails(details) {
136
+ if (!details || typeof details !== "object" || Array.isArray(details)) {
137
+ return null;
138
+ }
139
+ const directSummary = details.summary;
140
+ if (typeof directSummary === "string" && directSummary.trim().length > 0) {
141
+ return directSummary.trim();
142
+ }
143
+ const policy = details.policy;
144
+ if (!policy || typeof policy !== "object" || Array.isArray(policy)) {
145
+ return null;
146
+ }
147
+ const explanation = policy.explanation;
148
+ if (!explanation || typeof explanation !== "object" || Array.isArray(explanation)) {
149
+ return null;
150
+ }
151
+ const nestedSummary = explanation.summary;
152
+ if (typeof nestedSummary === "string" && nestedSummary.trim().length > 0) {
153
+ return nestedSummary.trim();
154
+ }
155
+ return null;
156
+ }
157
+ function createGatewayRequestClient(config = {}) {
158
+ const fetchImpl = config.fetchImpl ?? fetch;
159
+ const baseUrl = config.baseUrl?.replace(/\/+$/, "") ?? "";
160
+ const maxRetries = config.maxRetries ?? 2;
161
+ const requestIdFactory = config.requestIdFactory ?? (() => generatePortableRequestId());
162
+ async function resolveAuthHeaders() {
163
+ if (!config.getAuthHeaders) {
164
+ return {};
165
+ }
166
+ return await config.getAuthHeaders();
167
+ }
168
+ async function fetchWithTimeout(url, init, timeoutMs) {
169
+ const controller = new AbortController();
170
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
171
+ try {
172
+ return await fetchImpl(url, { ...init, signal: controller.signal });
173
+ } catch (error) {
174
+ if (controller.signal.aborted) {
175
+ throw timeoutError(timeoutMs);
176
+ }
177
+ throw error;
178
+ } finally {
179
+ clearTimeout(timer);
180
+ }
181
+ }
182
+ async function parsePayload(response) {
183
+ const text = await response.text();
184
+ if (!text) {
185
+ return null;
186
+ }
187
+ try {
188
+ return JSON.parse(text);
189
+ } catch {
190
+ return null;
191
+ }
192
+ }
193
+ function resolveTimeoutMs(method, requestTimeoutMs) {
194
+ if (typeof requestTimeoutMs === "number") {
195
+ return requestTimeoutMs;
196
+ }
197
+ const methodTimeoutMs = config.timeoutMsByMethod?.[method];
198
+ if (typeof methodTimeoutMs === "number") {
199
+ return methodTimeoutMs;
200
+ }
201
+ return config.timeoutMs ?? 15e3;
202
+ }
203
+ function buildApiError(args) {
204
+ const failure = args.failure;
205
+ const legacyError = failure && typeof failure.error === "object" && failure.error !== null ? failure.error : failure?.legacyError;
206
+ const correlationId = failure?.correlationId ?? args.response.headers.get("x-lucern-correlation-id")?.trim() ?? args.requestId;
207
+ const policyTraceId = failure?.policyTraceId ?? args.response.headers.get("x-lucern-policy-trace-id")?.trim() ?? null;
208
+ const details = failure?.details ?? legacyError?.details;
209
+ const policySummary = readPolicySummaryFromDetails(details);
210
+ return new LucernApiError({
211
+ code: failure?.code ?? legacyError?.code ?? fallbackErrorCode(args.response.status),
212
+ message: policySummary ?? (typeof failure?.error === "string" ? failure.error : legacyError?.message ?? (args.response.ok ? "Platform API returned an invalid success payload." : "Platform API request failed.")),
213
+ status: args.response.status,
214
+ invariant: failure?.invariant,
215
+ suggestion: failure?.suggestion,
216
+ details,
217
+ requestId: args.requestId,
218
+ correlationId,
219
+ policyTraceId
220
+ });
221
+ }
222
+ async function request(args) {
223
+ const authHeaders = await resolveAuthHeaders();
224
+ const method = args.method ?? "GET";
225
+ const timeoutMs = resolveTimeoutMs(method, args.timeoutMs);
226
+ const headers = new Headers({
227
+ "content-type": "application/json",
228
+ ...authHeaders
229
+ });
230
+ if (args.idempotencyKey) {
231
+ headers.set("idempotency-key", args.idempotencyKey);
232
+ }
233
+ const requestId = headers.get("x-correlation-id")?.trim() || headers.get("x-request-id")?.trim() || args.requestId || requestIdFactory();
234
+ if (!headers.has("x-correlation-id") && !headers.has("x-request-id")) {
235
+ headers.set("x-correlation-id", requestId);
236
+ }
237
+ const url = `${baseUrl}${args.path}`;
238
+ const serializedBody = args.body ? JSON.stringify(args.body) : void 0;
239
+ const init = {
240
+ method,
241
+ headers,
242
+ body: serializedBody
243
+ };
244
+ let lastError;
245
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
246
+ const hookRequestContext = {
247
+ requestId,
248
+ attempt,
249
+ maxRetries,
250
+ method,
251
+ path: args.path,
252
+ url,
253
+ headers: new Headers(headers),
254
+ body: serializedBody,
255
+ timeoutMs
256
+ };
257
+ await config.onRequest?.(hookRequestContext);
258
+ const startedAt = Date.now();
259
+ try {
260
+ const response = await fetchWithTimeout(url, init, timeoutMs);
261
+ const responseClone = response.clone();
262
+ const payload = await parsePayload(response);
263
+ const retryAfterMs = parseRetryAfterMs(
264
+ response.headers.get("Retry-After")
265
+ );
266
+ if (!response.ok || !payload?.success) {
267
+ const failure = payload && !payload.success ? payload : null;
268
+ const apiError = buildApiError({
269
+ requestId,
270
+ response,
271
+ failure
272
+ });
273
+ const willRetry = attempt < maxRetries && isRetryableStatus(response.status);
274
+ await config.onResponse?.({
275
+ ...hookRequestContext,
276
+ durationMs: Date.now() - startedAt,
277
+ status: response.status,
278
+ response: responseClone,
279
+ error: apiError,
280
+ correlationId: apiError.correlationId ?? requestId,
281
+ policyTraceId: apiError.policyTraceId ?? null,
282
+ retryAfterMs,
283
+ willRetry
284
+ });
285
+ if (willRetry) {
286
+ lastError = apiError;
287
+ await delay(
288
+ computeRetryDelayMs({
289
+ attempt,
290
+ status: response.status,
291
+ retryAfterMs
292
+ })
293
+ );
294
+ continue;
295
+ }
296
+ throw apiError;
297
+ }
298
+ const successPayload = payload;
299
+ await config.onResponse?.({
300
+ ...hookRequestContext,
301
+ durationMs: Date.now() - startedAt,
302
+ status: response.status,
303
+ response: responseClone,
304
+ correlationId: successPayload.correlationId ?? response.headers.get("x-lucern-correlation-id")?.trim() ?? requestId,
305
+ policyTraceId: successPayload.policyTraceId ?? response.headers.get("x-lucern-policy-trace-id")?.trim() ?? null,
306
+ idempotentReplay: successPayload.idempotentReplay,
307
+ retryAfterMs,
308
+ willRetry: false
309
+ });
310
+ return successPayload;
311
+ } catch (fetchError) {
312
+ if (fetchError instanceof LucernApiError) {
313
+ throw fetchError;
314
+ }
315
+ const willRetry = attempt < maxRetries;
316
+ await config.onResponse?.({
317
+ ...hookRequestContext,
318
+ durationMs: Date.now() - startedAt,
319
+ error: fetchError,
320
+ correlationId: requestId,
321
+ policyTraceId: null,
322
+ willRetry
323
+ });
324
+ lastError = fetchError;
325
+ if (willRetry) {
326
+ await delay(computeRetryDelayMs({ attempt }));
327
+ }
328
+ }
329
+ }
330
+ throw lastError instanceof Error ? lastError : new Error("Platform API request failed after retries.");
331
+ }
332
+ return {
333
+ request
334
+ };
335
+ }
336
+
337
+ // src/sdkSurface.ts
338
+ function cleanString(value) {
339
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
340
+ }
341
+ function normalizeTopicQuery(value) {
342
+ const topicId = cleanString(value.topicId);
343
+ if (!topicId) {
344
+ return value;
345
+ }
346
+ return { ...value, topicId };
347
+ }
348
+ function createListResult(items, legacyKey) {
349
+ const result = {
350
+ items,
351
+ total: items.length
352
+ };
353
+ if (legacyKey) {
354
+ result[legacyKey] = items;
355
+ }
356
+ return result;
357
+ }
358
+ function mapGatewayData(response, mapper) {
359
+ return {
360
+ ...response,
361
+ data: mapper(response.data)
362
+ };
363
+ }
364
+
365
+ // src/harnessClient.ts
366
+ function createHarnessClient(config = {}) {
367
+ const gateway = createGatewayRequestClient(config);
368
+ return {
369
+ /**
370
+ * List agent definitions.
371
+ */
372
+ async listAgentDefinitions(scope = {}) {
373
+ return gateway.request({
374
+ path: `/api/platform/v1/harness/agents${toQueryString(scope)}`
375
+ }).then(
376
+ (response) => mapGatewayData(
377
+ response,
378
+ (data) => createListResult(Array.isArray(data) ? data : [], "agents")
379
+ )
380
+ );
381
+ },
382
+ /**
383
+ * Get an agent definition.
384
+ */
385
+ async getAgentDefinition(agentId, scope = {}) {
386
+ return gateway.request({
387
+ path: `/api/platform/v1/harness/agents/${encodeURIComponent(agentId)}${toQueryString(scope)}`
388
+ });
389
+ },
390
+ /**
391
+ * Create an agent definition.
392
+ */
393
+ async createAgentDefinition(input, idempotencyKey) {
394
+ return gateway.request({
395
+ path: "/api/platform/v1/harness/agents",
396
+ method: "POST",
397
+ body: input,
398
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
399
+ });
400
+ },
401
+ /**
402
+ * @deprecated Use createAgentDefinition.
403
+ */
404
+ async registerAgentDefinition(input, idempotencyKey) {
405
+ return this.createAgentDefinition(input, idempotencyKey);
406
+ },
407
+ /**
408
+ * Update an agent definition.
409
+ */
410
+ async updateAgentDefinition(agentId, input, idempotencyKey) {
411
+ return gateway.request({
412
+ path: `/api/platform/v1/harness/agents/${encodeURIComponent(agentId)}`,
413
+ method: "PUT",
414
+ body: input,
415
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
416
+ });
417
+ },
418
+ /**
419
+ * Invoke a managed agent definition.
420
+ */
421
+ async invokeManagedAgentDefinition(agentId, input, idempotencyKey) {
422
+ return gateway.request({
423
+ path: `/api/platform/v1/harness/agents/${encodeURIComponent(agentId)}/runs`,
424
+ method: "POST",
425
+ body: {
426
+ agentDefinitionId: agentId,
427
+ ...input
428
+ },
429
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
430
+ });
431
+ },
432
+ /**
433
+ * List runs for an agent definition.
434
+ */
435
+ async listAgentRuns(agentId, scope = {}) {
436
+ return gateway.request({
437
+ path: `/api/platform/v1/harness/agents/${encodeURIComponent(agentId)}/runs${toQueryString(scope)}`
438
+ }).then(
439
+ (response) => mapGatewayData(
440
+ response,
441
+ (data) => createListResult(Array.isArray(data) ? data : [], "runs")
442
+ )
443
+ );
444
+ },
445
+ /**
446
+ * @deprecated Use listAgentRuns.
447
+ */
448
+ async listRunsForAgent(agentId, scope = {}) {
449
+ return this.listAgentRuns(agentId, scope);
450
+ },
451
+ /**
452
+ * List tool definitions.
453
+ */
454
+ async listToolDefinitions(scope = {}) {
455
+ return gateway.request({
456
+ path: `/api/platform/v1/harness/tools${toQueryString(scope)}`
457
+ }).then(
458
+ (response) => mapGatewayData(
459
+ response,
460
+ (data) => createListResult(Array.isArray(data) ? data : [], "tools")
461
+ )
462
+ );
463
+ },
464
+ /**
465
+ * Get a tool definition.
466
+ */
467
+ async getToolDefinition(toolId, scope = {}) {
468
+ return gateway.request({
469
+ path: `/api/platform/v1/harness/tools/${encodeURIComponent(toolId)}${toQueryString(scope)}`
470
+ });
471
+ },
472
+ /**
473
+ * Create a tool definition.
474
+ */
475
+ async createToolDefinition(input, idempotencyKey) {
476
+ return gateway.request({
477
+ path: "/api/platform/v1/harness/tools",
478
+ method: "POST",
479
+ body: input,
480
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
481
+ });
482
+ },
483
+ /**
484
+ * @deprecated Use createToolDefinition.
485
+ */
486
+ async registerToolDefinition(input, idempotencyKey) {
487
+ return this.createToolDefinition(input, idempotencyKey);
488
+ },
489
+ /**
490
+ * Update a tool definition.
491
+ */
492
+ async updateToolDefinition(toolId, input, idempotencyKey) {
493
+ return gateway.request({
494
+ path: `/api/platform/v1/harness/tools/${encodeURIComponent(toolId)}`,
495
+ method: "PUT",
496
+ body: input,
497
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
498
+ });
499
+ },
500
+ /**
501
+ * Execute a tool definition.
502
+ */
503
+ async executeToolDefinition(toolId, input = {}) {
504
+ return gateway.request({
505
+ path: `/api/platform/v1/harness/tools/${encodeURIComponent(toolId)}/execute`,
506
+ method: "POST",
507
+ body: input
508
+ });
509
+ },
510
+ /**
511
+ * List run ledger entries.
512
+ */
513
+ async listRunEntries(scope = {}) {
514
+ return gateway.request({
515
+ path: `/api/platform/v1/harness/runs${toQueryString(scope)}`
516
+ }).then(
517
+ (response) => mapGatewayData(
518
+ response,
519
+ (data) => createListResult(Array.isArray(data) ? data : [], "runs")
520
+ )
521
+ );
522
+ },
523
+ /**
524
+ * @deprecated Use listRunEntries.
525
+ */
526
+ async listRunLedgerEntries(scope = {}) {
527
+ return this.listRunEntries(scope);
528
+ },
529
+ /**
530
+ * Create a harness run.
531
+ */
532
+ async startHarnessRun(input, idempotencyKey) {
533
+ return gateway.request({
534
+ path: "/api/platform/v1/harness/runs",
535
+ method: "POST",
536
+ body: normalizeTopicQuery(input),
537
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
538
+ });
539
+ },
540
+ /**
541
+ * Get a run ledger entry.
542
+ */
543
+ async getRunLedgerEntry(runId) {
544
+ return gateway.request({
545
+ path: `/api/platform/v1/harness/runs/${encodeURIComponent(runId)}`
546
+ });
547
+ },
548
+ /**
549
+ * Update a harness run with a ledger event.
550
+ */
551
+ async reportHarnessRunEvent(runId, input, idempotencyKey) {
552
+ return gateway.request({
553
+ path: `/api/platform/v1/harness/runs/${encodeURIComponent(runId)}/report`,
554
+ method: "POST",
555
+ body: input,
556
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
557
+ });
558
+ },
559
+ /**
560
+ * Update a harness run heartbeat.
561
+ */
562
+ async heartbeatHarnessRun(runId, input, idempotencyKey) {
563
+ return gateway.request({
564
+ path: `/api/platform/v1/harness/runs/${encodeURIComponent(runId)}/heartbeat`,
565
+ method: "POST",
566
+ body: input,
567
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
568
+ });
569
+ },
570
+ /**
571
+ * Complete a harness run.
572
+ */
573
+ async completeHarnessRun(runId, input, idempotencyKey) {
574
+ return gateway.request({
575
+ path: `/api/platform/v1/harness/runs/${encodeURIComponent(runId)}/complete`,
576
+ method: "POST",
577
+ body: input,
578
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
579
+ });
580
+ },
581
+ /**
582
+ * List prompt resolutions.
583
+ */
584
+ async listPromptResolutions(query = {}) {
585
+ return gateway.request({
586
+ path: `/api/platform/v1/harness/prompts${toQueryString(query)}`
587
+ }).then(
588
+ (response) => mapGatewayData(
589
+ response,
590
+ (data) => createListResult(Array.isArray(data) ? data : [], "prompts")
591
+ )
592
+ );
593
+ },
594
+ /**
595
+ * Get the harness scope taxonomy.
596
+ */
597
+ async getScopeTaxonomy() {
598
+ return gateway.request({
599
+ path: "/api/platform/v1/harness/scopes"
600
+ });
601
+ }
602
+ };
603
+ }
604
+
605
+ export { LucernApiError, createHarnessClient };
606
+ //# sourceMappingURL=harnessClient.js.map
607
+ //# sourceMappingURL=harnessClient.js.map