@arbol-ai/maximus 8.0.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/analytics/analytics.d.ts +1 -1
  2. package/dist/analytics/analytics.js +2 -2
  3. package/dist/body.d.ts +1 -1
  4. package/dist/capture/index.d.ts +37 -0
  5. package/dist/capture/index.js +182 -0
  6. package/dist/chunks/{define-app-CfVZBt7D.js → define-app-BxGZdNmS.js} +20 -4
  7. package/dist/chunks/delay-BsKQP_lF.js +12 -0
  8. package/dist/chunks/digest-C7UGt760.js +13 -0
  9. package/dist/chunks/{errors-WfyKhiyk.js → errors-CWgE9uvM.js} +2 -2
  10. package/dist/chunks/execution-BTiAWA4n.js +264 -0
  11. package/dist/chunks/{handler-DWTGoduQ.js → handler-iebR-urt.js} +1 -0
  12. package/dist/chunks/{http-layout-_h7xwgPC.js → http-layout-BvlbD__1.js} +1 -1
  13. package/dist/chunks/{openapi-CV0KmJpS.js → openapi-BF3eCpux.js} +12 -21
  14. package/dist/chunks/{openapi-file-OjSs9mRv.js → openapi-file-RcXoq0AF.js} +1 -1
  15. package/dist/chunks/{pages-DyC0m8Zb.js → pages-BCksUeRf.js} +1 -1
  16. package/dist/chunks/{runtime-CVVf5hmp.js → runtime-D5eR9-Es.js} +38 -9
  17. package/dist/chunks/{schemas-p_aRcMC1.js → schemas-BOFxZP1c.js} +1 -1
  18. package/dist/chunks/{server-CCc7fil4.js → server-B9C8KPwa.js} +5 -4
  19. package/dist/chunks/{src--HZrH1U9.js → src-C-4z443M.js} +67 -16
  20. package/dist/chunks/{standard-failures-CLjxS2ea.js → standard-failures-Lh4mSfwG.js} +1 -1
  21. package/dist/chunks/{telemetry-C3LfZcOB.js → telemetry-BtxJh69Q.js} +4 -4
  22. package/dist/chunks/{types-BQYB4Ads.d.ts → types-Dqo3oGig.d.ts} +245 -34
  23. package/dist/chunks/{validation-fTohBT6R.js → validation-DMu0rkMQ.js} +266 -16
  24. package/dist/chunks/{workers-types-iONp32T4.d.ts → workers-types-BgjyDtGd.d.ts} +1 -1
  25. package/dist/diagnostics.d.ts +1 -1
  26. package/dist/diagnostics.js +1 -1
  27. package/dist/errors.d.ts +1 -1
  28. package/dist/errors.js +1 -1
  29. package/dist/http-paths.d.ts +1 -1
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.js +7 -7
  32. package/dist/internals.d.ts +2 -2
  33. package/dist/internals.js +5 -5
  34. package/dist/mcp/index.d.ts +1 -1
  35. package/dist/mcp/index.js +1 -1
  36. package/dist/project/config.d.ts +1 -1
  37. package/dist/project/config.js +1 -1
  38. package/dist/project/index.d.ts +2 -2
  39. package/dist/project/index.js +3 -3
  40. package/dist/schemas.d.ts +2 -2
  41. package/dist/schemas.js +3 -3
  42. package/dist/standard-failures.d.ts +1 -1
  43. package/dist/standard-failures.js +1 -1
  44. package/dist/tooling/cli.js +1 -1
  45. package/dist/vite/index.d.ts +3 -3
  46. package/dist/vite/index.js +12 -7
  47. package/dist/webhooks.d.ts +1 -1
  48. package/dist/workers/runtime.d.ts +1 -1
  49. package/dist/workers/runtime.js +1 -1
  50. package/package.json +5 -1
  51. package/skills/maximus/SKILL.md +7 -0
  52. package/skills/maximus/references/project.md +4 -0
  53. package/skills/maximus/references/routes-and-tools.md +2 -0
  54. package/templates/project/CLAUDE.md.template +3 -3
  55. package/templates/project/README.md.template +1 -0
  56. package/templates/project/tsconfig.json.template +1 -0
  57. package/dist/chunks/execution-CfZEx_JP.js +0 -84
@@ -1,11 +1,12 @@
1
- import { t as STANDARD_FAILURES } from "./standard-failures-CLjxS2ea.js";
2
- import { S as wireInput, r as parseInput } from "./validation-fTohBT6R.js";
3
- import { i as standardErrors } from "./errors-WfyKhiyk.js";
1
+ import { t as STANDARD_FAILURES } from "./standard-failures-Lh4mSfwG.js";
2
+ import { C as wireInput, T as withoutSecretKeyword, i as parseInput } from "./validation-DMu0rkMQ.js";
3
+ import { t as isRecord } from "./record-DQUDTpEA.js";
4
+ import { i as standardErrors } from "./errors-CWgE9uvM.js";
4
5
  import { a as operationPathParameters } from "./http-paths-DMBxwpp6.js";
5
6
  import { a as routeGroup, i as pathParameterSchemas, r as ok, t as err } from "./result-CKgZHrnj.js";
6
- import { t as isRecord } from "./record-DQUDTpEA.js";
7
- import { i as UuidSchema, n as OrganizationIdSchema } from "./schemas-p_aRcMC1.js";
7
+ import { i as UuidSchema, n as OrganizationIdSchema } from "./schemas-BOFxZP1c.js";
8
8
  import { t as queryKind } from "./query-kind-CWKAXEME.js";
9
+ import { t as sha256Hex } from "./digest-C7UGt760.js";
9
10
  import { Type } from "@sinclair/typebox";
10
11
  import { createRemoteJWKSet, jwtVerify } from "jose";
11
12
 
@@ -426,10 +427,12 @@ function replaceReferences(value, replace) {
426
427
  * against its enclosing `$id`, as in JSON Schema; structurally different definitions that share an
427
428
  * `$id` (for example a normalized input projection and its output) become distinct components. A
428
429
  * reference outside any definition must name exactly one variant. Use-site annotations stay beside
429
- * the reference. The owner's runtime schemas are not changed.
430
+ * the reference, and `secret`, which only capture reads, is left out. The owner's runtime schemas are not
431
+ * changed.
430
432
  */
431
433
  function bundleSchemas(sources, existing) {
432
- const ids = schemaIds(sources);
434
+ const published = sources.map((source) => withoutSecretKeyword(source));
435
+ const ids = schemaIds(published);
433
436
  const components = {};
434
437
  const variants = /* @__PURE__ */ new Map();
435
438
  const taken = new Set(Object.keys(existing));
@@ -469,7 +472,7 @@ function bundleSchemas(sources, existing) {
469
472
  return [key, rewrite(child, scope)];
470
473
  }));
471
474
  }
472
- const rewritten = sources.map((source) => rewrite(source, /* @__PURE__ */ new Map()));
475
+ const rewritten = published.map((source) => rewrite(source, /* @__PURE__ */ new Map()));
473
476
  /**
474
477
  * A pending reference as the one component its name has once every variant is known; refused when the name
475
478
  * has several shapes or none.
@@ -740,18 +743,6 @@ function failureUnion(codes) {
740
743
  };
741
744
  }
742
745
 
743
- // src/internal/digest.ts
744
- /**
745
- * SHA-256 digests in hexadecimal, for rate limit keys, the development token's comparison and skill
746
- * manifests.
747
- */
748
- /** The SHA-256 digest of text or bytes, in lowercase hexadecimal. */
749
- async function sha256Hex(value) {
750
- const bytes = typeof value === "string" ? new TextEncoder().encode(value) : value;
751
- const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", bytes));
752
- return Array.from(digest, (byte) => byte.toString(16).padStart(2, "0")).join("");
753
- }
754
-
755
746
  // src/tokens.ts
756
747
  /**
757
748
  * Token verification: the principal every operation receives, the token policy, OAuth access token
@@ -1585,4 +1576,4 @@ function securitySchemes(tokens, scopes) {
1585
1576
  };
1586
1577
  }
1587
1578
 
1588
- export { operationOutputLimit as A, MAX_BODY_BYTES_CEILING as C, mcpOpenWorld as D, isPublicOperation as E, isNamespacedScope as M, matchesScopes as N, operation as O, DEFAULT_MAX_BODY_BYTES as S, composeOperations as T, projectAccessToken as _, createTokenVerifier as a, ADMISSION_CODES as b, tokenIssuer as c, canonical as d, hasSchemaReferences as f, isCrossSiteWrite as g, queryKinds as h, createTokenAuthorization as i, operationScopes as j, operationMatchesScopes as k, usesOwnBearer as l, queryInput as m, createRpcOpenApi as n, projectToken as o, standaloneSchema as p, checkTokenAuthority as r, tokenAudiences as s, createOpenApi as t, sha256Hex as u, usesCloudflareAccess as v, STANDARD_CODES as w, BODY_CODES as x, PrincipalSchema as y };
1579
+ export { operationOutputLimit as A, MAX_BODY_BYTES_CEILING as C, mcpOpenWorld as D, isPublicOperation as E, isNamespacedScope as M, matchesScopes as N, operation as O, DEFAULT_MAX_BODY_BYTES as S, composeOperations as T, projectAccessToken as _, createTokenVerifier as a, ADMISSION_CODES as b, tokenAudiences as c, canonical as d, hasSchemaReferences as f, isCrossSiteWrite as g, queryKinds as h, createTokenAuthorization as i, operationScopes as j, operationMatchesScopes as k, tokenIssuer as l, queryInput as m, createRpcOpenApi as n, presentedToken as o, standaloneSchema as p, checkTokenAuthority as r, projectToken as s, createOpenApi as t, usesOwnBearer as u, usesCloudflareAccess as v, STANDARD_CODES as w, BODY_CODES as x, PrincipalSchema as y };
@@ -1,4 +1,4 @@
1
- import { n as createRpcOpenApi } from "./openapi-CV0KmJpS.js";
1
+ import { n as createRpcOpenApi } from "./openapi-BF3eCpux.js";
2
2
  import { t as prepareConfiguredProject } from "./prepare-configured-Cithjf80.js";
3
3
  import { t as packageDirectory } from "./scaffold-DZD6dfoZ.js";
4
4
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
@@ -1,4 +1,4 @@
1
- import { a as ownsPrefix, i as nativePaths, t as VERSIONED_PATH } from "./http-layout-_h7xwgPC.js";
1
+ import { a as ownsPrefix, i as nativePaths, t as VERSIONED_PATH } from "./http-layout-BvlbD__1.js";
2
2
 
3
3
  // src/project/pages.ts
4
4
  /**
@@ -1,11 +1,11 @@
1
- import { r as parseInput } from "./validation-fTohBT6R.js";
1
+ import { i as parseInput } from "./validation-DMu0rkMQ.js";
2
2
  import { r as isRequestId } from "./correlation-4b23a-a4.js";
3
- import { i as standardErrors } from "./errors-WfyKhiyk.js";
3
+ import { i as standardErrors } from "./errors-CWgE9uvM.js";
4
4
  import { r as ok, t as err } from "./result-CKgZHrnj.js";
5
- import { y as PrincipalSchema } from "./openapi-CV0KmJpS.js";
6
- import { r as createHttpHandler } from "./src--HZrH1U9.js";
7
- import { a as telemetryEnabled, i as reportUnexpected, r as recordExecution, s as withTelemetry } from "./telemetry-C3LfZcOB.js";
8
- import { t as executeOperation } from "./execution-CfZEx_JP.js";
5
+ import { y as PrincipalSchema } from "./openapi-BF3eCpux.js";
6
+ import { r as createHttpHandler } from "./src-C-4z443M.js";
7
+ import { a as recordExecution, l as withTelemetry, o as reportUnexpected, s as telemetryEnabled } from "./telemetry-BtxJh69Q.js";
8
+ import { n as recordCapture, t as executeOperation } from "./execution-BTiAWA4n.js";
9
9
  import { DurableObject, WorkerEntrypoint, tracing } from "cloudflare:workers";
10
10
 
11
11
  // src/workers/assets.ts
@@ -200,13 +200,32 @@ function createWorker(application, options = {}) {
200
200
  Object.defineProperty(Entrypoint.prototype, name, {
201
201
  configurable: true,
202
202
  async value(principal, input) {
203
+ const requestStarted = performance.now();
203
204
  const props = this.ctx.props;
204
- if (!props || Object.keys(props).length !== 1 || typeof props.caller !== "string" || !callers.includes(props.caller)) return err(standardErrors.unauthorized.create());
205
205
  const parsed = parseInput(PrincipalSchema, principal);
206
- if (!parsed.ok) return err(standardErrors.unauthorized.create());
206
+ /**
207
+ * Refuses the call, and captures the refusal: the principal it names is unverified, so the record keeps
208
+ * its request id, for correlation, and never its organization or actor.
209
+ */
210
+ const refuse = () => {
211
+ const refusal = err(standardErrors.unauthorized.create());
212
+ recordCapture(manifest, this.env, this.ctx, {
213
+ operation: name,
214
+ surface: "rpc",
215
+ requestId: parsed.ok ? parsed.value.requestId : crypto.randomUUID(),
216
+ principal: null,
217
+ requestStarted,
218
+ result: refusal,
219
+ call: typeof props?.caller === "string" ? { rpcCaller: props.caller.slice(0, 64) } : {}
220
+ });
221
+ return refusal;
222
+ };
223
+ if (!props || Object.keys(props).length !== 1 || typeof props.caller !== "string" || !callers.includes(props.caller)) return refuse();
224
+ if (!parsed.ok) return refuse();
207
225
  if (telemetryEnabled(manifest.telemetry, this.env)) annotateInvocation(manifest.name, name, parsed.value.requestId);
226
+ const call = { rpcCaller: props.caller };
208
227
  const started = performance.now();
209
- const result = await withTelemetry(manifest.telemetry, this.env, () => executeOperation(manifest, op, this.env, parsed.value, input, void 0, this.ctx));
228
+ const result = await withTelemetry(manifest.telemetry, this.env, () => executeOperation(manifest, op, this.env, parsed.value, input, void 0, this.ctx, void 0, call));
210
229
  recordExecution(manifest, this.env, this.ctx, {
211
230
  principal: parsed.value,
212
231
  operation: name,
@@ -214,6 +233,16 @@ function createWorker(application, options = {}) {
214
233
  started,
215
234
  result
216
235
  });
236
+ recordCapture(manifest, this.env, this.ctx, {
237
+ operation: name,
238
+ surface: "rpc",
239
+ requestId: parsed.value.requestId,
240
+ principal: parsed.value,
241
+ requestStarted,
242
+ executionStarted: started,
243
+ result,
244
+ call
245
+ });
217
246
  return result;
218
247
  }
219
248
  });
@@ -1,4 +1,4 @@
1
- import { a as codecFault, c as defaultSchema, d as inputSchema, n as decodeSchema, o as decodeIssues, s as SchemaValidationError } from "./validation-fTohBT6R.js";
1
+ import { c as SchemaValidationError, f as inputSchema, l as defaultSchema, o as codecFault, r as decodeSchema, s as decodeIssues } from "./validation-DMu0rkMQ.js";
2
2
  import { Kind, Type, Type as Type$1, Type as t } from "@sinclair/typebox";
3
3
 
4
4
  // src/schema-reader.ts
@@ -1,7 +1,8 @@
1
- import { S as wireInput } from "./validation-fTohBT6R.js";
2
- import { i as standardErrors } from "./errors-WfyKhiyk.js";
3
- import { C as MAX_BODY_BYTES_CEILING, D as mcpOpenWorld, d as canonical, k as operationMatchesScopes, p as standaloneSchema, u as sha256Hex } from "./openapi-CV0KmJpS.js";
4
- import { i as reportUnexpected } from "./telemetry-C3LfZcOB.js";
1
+ import { C as wireInput } from "./validation-DMu0rkMQ.js";
2
+ import { i as standardErrors } from "./errors-CWgE9uvM.js";
3
+ import { C as MAX_BODY_BYTES_CEILING, D as mcpOpenWorld, d as canonical, k as operationMatchesScopes, p as standaloneSchema } from "./openapi-BF3eCpux.js";
4
+ import { t as sha256Hex } from "./digest-C7UGt760.js";
5
+ import { o as reportUnexpected } from "./telemetry-BtxJh69Q.js";
5
6
  import { t as toYaml } from "./yaml-Dk2L24yQ.js";
6
7
  import { Type } from "@sinclair/typebox";
7
8
  import { Value } from "@sinclair/typebox/value";
@@ -1,12 +1,13 @@
1
- import { i as standardErrors } from "./errors-WfyKhiyk.js";
1
+ import { i as standardErrors } from "./errors-CWgE9uvM.js";
2
2
  import { r as readBodyText } from "./body-DOIHwIIl.js";
3
- import { i as binaryBody, n as defineApp, r as attachmentResponse } from "./define-app-CfVZBt7D.js";
3
+ import { i as binaryBody, n as defineApp, r as attachmentResponse } from "./define-app-BxGZdNmS.js";
4
4
  import { t as createHttpRouteResolver } from "./http-paths-DMBxwpp6.js";
5
5
  import { r as ok, t as err } from "./result-CKgZHrnj.js";
6
- import { E as isPublicOperation, S as DEFAULT_MAX_BODY_BYTES, T as composeOperations, c as tokenIssuer, g as isCrossSiteWrite, h as queryKinds, i as createTokenAuthorization, j as operationScopes, k as operationMatchesScopes, m as queryInput, s as tokenAudiences, t as createOpenApi, u as sha256Hex } from "./openapi-CV0KmJpS.js";
7
- import { a as telemetryEnabled, i as reportUnexpected, n as recordAdmission, r as recordExecution, s as withTelemetry } from "./telemetry-C3LfZcOB.js";
8
- import { t as executeOperation } from "./execution-CfZEx_JP.js";
9
- import { a as ownsPrefix, i as nativePaths, n as composition, o as servesCloudflareAccess, r as httpTransports, s as servesOwnBearer, t as VERSIONED_PATH } from "./http-layout-_h7xwgPC.js";
6
+ import { E as isPublicOperation, S as DEFAULT_MAX_BODY_BYTES, T as composeOperations, c as tokenAudiences, g as isCrossSiteWrite, h as queryKinds, i as createTokenAuthorization, j as operationScopes, k as operationMatchesScopes, l as tokenIssuer, m as queryInput, o as presentedToken, t as createOpenApi } from "./openapi-BF3eCpux.js";
7
+ import { t as sha256Hex } from "./digest-C7UGt760.js";
8
+ import { a as recordExecution, i as recordAdmission, l as withTelemetry, o as reportUnexpected, s as telemetryEnabled } from "./telemetry-BtxJh69Q.js";
9
+ import { n as recordCapture, t as executeOperation } from "./execution-BTiAWA4n.js";
10
+ import { a as ownsPrefix, i as nativePaths, n as composition, o as servesCloudflareAccess, r as httpTransports, s as servesOwnBearer, t as VERSIONED_PATH } from "./http-layout-BvlbD__1.js";
10
11
  import { n as mediaType } from "./json-B14evE6-.js";
11
12
  import { t as toYaml } from "./yaml-Dk2L24yQ.js";
12
13
  import { Type as Type$1, Type as t } from "@sinclair/typebox";
@@ -217,7 +218,12 @@ function createHttpHandler(manifest, hooks = {}) {
217
218
  headers.set("cache-control", "private, no-store");
218
219
  headers.set("x-content-type-options", "nosniff");
219
220
  headers.set("x-request-id", requestId);
220
- if (error.code === "UNAUTHORIZED" && !headers.has("www-authenticate")) {
221
+ const status = manifest.errors.status(error.code);
222
+ if ((status === 401 || status === 403) && !headers.has("www-authenticate")) {
223
+ const challenge = manifest.tokens.challenge?.(error, context);
224
+ if (challenge) headers.set("www-authenticate", challenge);
225
+ }
226
+ if (status === 401 && !headers.has("www-authenticate")) {
221
227
  const metadataUrl = oauth ? challengeMetadataUrl(context) : null;
222
228
  headers.set("www-authenticate", metadataUrl === null ? "Bearer" : `Bearer resource_metadata="${metadataUrl}"`);
223
229
  }
@@ -277,6 +283,8 @@ function createHttpHandler(manifest, hooks = {}) {
277
283
  let surface = "http";
278
284
  let plain = false;
279
285
  let requestEnv = env;
286
+ let verified;
287
+ const userAgent = incoming.headers.get("user-agent")?.slice(0, 200) || void 0;
280
288
  const context = {
281
289
  requestId,
282
290
  fail: (error, headers) => failure(error, requestId, resolutionContext(), headers),
@@ -299,6 +307,19 @@ function createHttpHandler(manifest, hooks = {}) {
299
307
  applicationScopes,
300
308
  background
301
309
  });
310
+ /** Captures a refusal before execution, of this request's operation or the one a transport names. */
311
+ function captureRefusal(error, refused, scopedEnv) {
312
+ recordCapture(manifest, scopedEnv, background, {
313
+ operation: refused,
314
+ surface,
315
+ requestId,
316
+ principal,
317
+ ...verified ? { verified } : {},
318
+ requestStarted: started,
319
+ result: err(error),
320
+ call: userAgent ? { userAgent } : {}
321
+ });
322
+ }
302
323
  /** A refusal before execution, observed as a rejected admission. */
303
324
  function reject(error) {
304
325
  recordAdmission(manifest, requestEnv, background, {
@@ -309,6 +330,7 @@ function createHttpHandler(manifest, hooks = {}) {
309
330
  started,
310
331
  errorCode: error.code
311
332
  });
333
+ captureRefusal(error, operation, requestEnv);
312
334
  return failure(error, requestId, resolutionContext());
313
335
  }
314
336
  /**
@@ -381,6 +403,14 @@ function createHttpHandler(manifest, hooks = {}) {
381
403
  requestId
382
404
  };
383
405
  principal = actor;
406
+ if (manifest.capture) {
407
+ const token = presentedToken(incoming, manifest.tokens);
408
+ verified = {
409
+ scopes: authenticated.scopes,
410
+ ...authenticated.client ? { client: authenticated.client } : {},
411
+ ...token ? { token } : {}
412
+ };
413
+ }
384
414
  if (!await withinRateLimit(scopedEnv, authenticated)) return reject(standardErrors.rateLimited.create());
385
415
  let request = incoming;
386
416
  let bodyText = "";
@@ -410,22 +440,31 @@ function createHttpHandler(manifest, hooks = {}) {
410
440
  * Runs one operation through the shared execution path as the admitted caller, and records the call.
411
441
  */
412
442
  async function invoke(name, op, input) {
413
- if (transport && !operations.some(([selectedName, selected]) => selectedName === name && selected === op)) return {
414
- ok: false,
415
- error: standardErrors.notFound.create()
416
- };
417
- if (transport && !operationMatchesScopes(op, authenticated.scopes)) return {
418
- ok: false,
419
- error: standardErrors.forbidden.create()
420
- };
443
+ if (transport && !operations.some(([selectedName, selected]) => selectedName === name && selected === op)) {
444
+ const error = standardErrors.notFound.create();
445
+ captureRefusal(error, null, scopedEnv);
446
+ return {
447
+ ok: false,
448
+ error
449
+ };
450
+ }
451
+ if (transport && !operationMatchesScopes(op, authenticated.scopes)) {
452
+ const error = standardErrors.forbidden.create();
453
+ captureRefusal(error, name, scopedEnv);
454
+ return {
455
+ ok: false,
456
+ error
457
+ };
458
+ }
421
459
  if (telemetryEnabled(manifest.telemetry, scopedEnv)) hooks.annotate?.(name, requestId);
460
+ const call = userAgent ? { userAgent } : {};
422
461
  const invocationStarted = performance.now();
423
462
  const output = await executeOperation(manifest, op, scopedEnv, actor, input, authenticated.client ? {
424
463
  surface: transport ? "mcp" : "http",
425
464
  scopes: authenticated.scopes,
426
465
  client: authenticated.client,
427
466
  ...accessToken ? { token: accessToken } : {}
428
- } : void 0, background, byteOperation ? binaryBody(incoming, op.maxBodyBytes ?? fallbackBodyBytes) : void 0);
467
+ } : void 0, background, byteOperation ? binaryBody(incoming, op.maxBodyBytes ?? fallbackBodyBytes) : void 0, call);
429
468
  recordExecution(manifest, scopedEnv, background, {
430
469
  principal: actor,
431
470
  operation: name,
@@ -433,6 +472,17 @@ function createHttpHandler(manifest, hooks = {}) {
433
472
  started: invocationStarted,
434
473
  result: output
435
474
  });
475
+ recordCapture(manifest, scopedEnv, background, {
476
+ operation: name,
477
+ surface: transport ? "mcp" : "http",
478
+ requestId,
479
+ principal: actor,
480
+ ...verified ? { verified } : {},
481
+ requestStarted: started,
482
+ executionStarted: invocationStarted,
483
+ result: output,
484
+ call
485
+ });
436
486
  return output;
437
487
  }
438
488
  if (transport) return transport.handle({
@@ -455,6 +505,7 @@ function createHttpHandler(manifest, hooks = {}) {
455
505
  started,
456
506
  errorCode: error.code
457
507
  });
508
+ captureRefusal(error, name ?? null, scopedEnv);
458
509
  },
459
510
  body: bodyText,
460
511
  bodyLimit: (op) => op.maxBodyBytes ?? fallbackBodyBytes
@@ -19,7 +19,7 @@ const STANDARD_FAILURES = {
19
19
  notFound: {
20
20
  code: "NOT_FOUND",
21
21
  status: 404,
22
- message: "The requested operation does not exist."
22
+ message: "The requested resource does not exist."
23
23
  },
24
24
  methodNotAllowed: {
25
25
  code: "HTTP_METHOD_NOT_ALLOWED",
@@ -95,9 +95,9 @@ function createDiagnostics(errorNames = []) {
95
95
  * Telemetry: invocation-local diagnostics kept in AsyncLocalStorage, safe native log events, and observers
96
96
  * that receive execution and admission observations as background work.
97
97
  */
98
- /** Microseconds since `started`, a `performance.now()` reading. */
99
- function elapsedMicros(started) {
100
- return Math.max(0, Math.round((performance.now() - started) * 1e3));
98
+ /** Microseconds from `started` to `until` or now, each a `performance.now()` reading. */
99
+ function elapsedMicros(started, until = performance.now()) {
100
+ return Math.max(0, Math.round((until - started) * 1e3));
101
101
  }
102
102
  /**
103
103
  * Hands one event to one observer as background work: a failed delivery is logged with its request id
@@ -236,4 +236,4 @@ function recordExecution(manifest, env, background, invocation) {
236
236
  for (const observer of manifest.telemetry?.observers ?? []) if (observer.execution) deliver(background, event.principal.requestId, () => observer.execution?.(event, env));
237
237
  }
238
238
 
239
- export { telemetryEnabled as a, createDiagnostics as c, reportUnexpected as i, recordAdmission as n, withDiagnostics as o, recordExecution as r, withTelemetry as s, diagnosticsEnabled as t };
239
+ export { recordExecution as a, withDiagnostics as c, recordAdmission as i, withTelemetry as l, diagnosticsEnabled as n, reportUnexpected as o, elapsedMicros as r, telemetryEnabled as s, activeTraceId as t, createDiagnostics as u };