@kindgi/api 0.1.4-rc.4 → 0.1.4-rc.5

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 (45) hide show
  1. package/dist/app.d.ts +7 -0
  2. package/dist/app.d.ts.map +1 -1
  3. package/dist/app.js +12 -1
  4. package/dist/app.js.map +1 -1
  5. package/dist/errors.d.ts.map +1 -1
  6. package/dist/errors.js +6 -0
  7. package/dist/errors.js.map +1 -1
  8. package/dist/handler-binding.d.ts +9 -0
  9. package/dist/handler-binding.d.ts.map +1 -1
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/middleware/error-mapper.d.ts.map +1 -1
  14. package/dist/middleware/error-mapper.js +2 -0
  15. package/dist/middleware/error-mapper.js.map +1 -1
  16. package/dist/middleware/request-log.d.ts +31 -0
  17. package/dist/middleware/request-log.d.ts.map +1 -0
  18. package/dist/middleware/request-log.js +80 -0
  19. package/dist/middleware/request-log.js.map +1 -0
  20. package/dist/openapi/operations.d.ts.map +1 -1
  21. package/dist/openapi/operations.js +2 -0
  22. package/dist/openapi/operations.js.map +1 -1
  23. package/dist/openapi/schemas.d.ts.map +1 -1
  24. package/dist/openapi/schemas.js +5 -0
  25. package/dist/openapi/schemas.js.map +1 -1
  26. package/dist/routes/runs.d.ts.map +1 -1
  27. package/dist/routes/runs.js +5 -2
  28. package/dist/routes/runs.js.map +1 -1
  29. package/dist/secrets-binding.d.ts +8 -0
  30. package/dist/secrets-binding.d.ts.map +1 -1
  31. package/dist/types.d.ts +9 -0
  32. package/dist/types.d.ts.map +1 -1
  33. package/openapi.json +33 -0
  34. package/package.json +22 -21
  35. package/src/app.ts +17 -1
  36. package/src/errors.ts +6 -0
  37. package/src/handler-binding.ts +10 -0
  38. package/src/index.ts +1 -0
  39. package/src/middleware/error-mapper.ts +3 -0
  40. package/src/middleware/request-log.ts +89 -0
  41. package/src/openapi/operations.ts +6 -0
  42. package/src/openapi/schemas.ts +6 -0
  43. package/src/routes/runs.ts +11 -1
  44. package/src/secrets-binding.ts +5 -0
  45. package/src/types.ts +9 -0
@@ -637,6 +637,12 @@ export const RunSchema: JsonSchema = {
637
637
  description:
638
638
  "The segment path the run was started with (coarse to fine), which picks live agent versions. A child run has its parent's. Absent when there was none.",
639
639
  },
640
+ traceId: {
641
+ type: 'string',
642
+ pattern: '^[0-9a-f]{32}$',
643
+ description:
644
+ "The W3C trace id of the request that started the run: the caller's (from its `traceparent`) or one the API minted. The runtime's records about the run carry it; `GET` responses answer `traceresponse` with each request's own. Absent for a run no request started, and on runs from before runs recorded it.",
645
+ },
640
646
  publicAccessToken: {
641
647
  type: 'string',
642
648
  description:
@@ -23,6 +23,7 @@ import type {
23
23
  RunHandlerBinding,
24
24
  RunHandlerFailure,
25
25
  RunHandlerOutcome,
26
+ RunTrace,
26
27
  } from '../handler-binding.js';
27
28
  import type { Authorizer } from '../middleware/authorize.js';
28
29
  import type { MintPublicRunTokenResult } from '../public-run-token.js';
@@ -161,7 +162,13 @@ export function runsRouter(
161
162
  return c.json(toWireError(parsed.error, requestId));
162
163
  }
163
164
 
164
- const invocation = await invokeFromBody(binding, tenantId, parsed.value);
165
+ const trace = c.get('trace');
166
+ const invocation = await invokeFromBody(
167
+ binding,
168
+ tenantId,
169
+ parsed.value,
170
+ trace !== undefined ? { traceId: trace.traceId, spanId: trace.spanId } : undefined,
171
+ );
165
172
 
166
173
  if (invocation.kind === 'err') {
167
174
  c.status(statusFor(invocation.error.code) as never);
@@ -624,9 +631,11 @@ function invokeFromBody(
624
631
  binding: RunHandlerBinding,
625
632
  tenantId: TenantId,
626
633
  body: ParsedStartRunBody,
634
+ trace?: RunTrace,
627
635
  ): Promise<RunHandlerOutcome> {
628
636
  const common = {
629
637
  tenantId,
638
+ ...(trace !== undefined && { trace }),
630
639
  ...(body.projectId !== undefined && { projectId: body.projectId }),
631
640
  input: body.input,
632
641
  ...(body.segments !== undefined && { segments: body.segments }),
@@ -690,6 +699,7 @@ function serializeRun(
690
699
  row.segments.length > 0 && {
691
700
  segments: row.segments.map(({ key, value }) => ({ key, value })),
692
701
  }),
702
+ ...(row.traceId != null && { traceId: row.traceId }),
693
703
  };
694
704
  }
695
705
 
@@ -305,4 +305,9 @@ export type SecretError =
305
305
  readonly message: string;
306
306
  readonly currentVersion: number;
307
307
  }
308
+ /**
309
+ * The store doesn't do this by design (the dev store keeps no versions to
310
+ * rotate and no revocation): the message says what to do instead.
311
+ */
312
+ | { readonly code: 'secret-operation-unsupported'; readonly message: string }
308
313
  | { readonly code: 'secret-store-error'; readonly message: string; readonly cause?: unknown };
package/src/types.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  // Copyright (C) 2026 Kindgi Inc.
3
3
 
4
4
  import type { Principal, ReviewerRole } from '@kindgi/authz';
5
+ import type { Logger, TraceContext } from '@kindgi/log';
5
6
  import type { ApiTokenId, RunId, SessionId, TenantId, UserId } from '@kindgi/types';
6
7
 
7
8
  /**
@@ -11,6 +12,14 @@ import type { ApiTokenId, RunId, SessionId, TenantId, UserId } from '@kindgi/typ
11
12
  export interface AppEnv {
12
13
  Variables: {
13
14
  requestId: string;
15
+ /**
16
+ * The request's logger (`requestLogMiddleware`): the app's, with the
17
+ * request's `requestId`, `traceId` and `spanId`, and its `tenantId`
18
+ * once authenticated. Routes log through it.
19
+ */
20
+ log: Logger;
21
+ /** The request's W3C trace context: the caller's trace when it sent a valid `traceparent`. */
22
+ trace: TraceContext;
14
23
  /** Set by `bearerAuthMiddleware` on authenticated routes. */
15
24
  tenantId: TenantId;
16
25
  /**