@nylorun/runtime 0.14.0-beta → 0.15.1-beta

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 (198) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/README.md +82 -40
  3. package/dist/adapters/execution/restate.js +2 -2
  4. package/dist/adapters/replication/pgoutput.d.ts +5 -0
  5. package/dist/adapters/replication/pgoutput.js +4 -3
  6. package/dist/admin-openapi.json +185 -686
  7. package/dist/api/components.d.ts +308 -68
  8. package/dist/api/components.js +4 -5
  9. package/dist/api/gate/keys.d.ts +14 -0
  10. package/dist/api/gate/keys.js +59 -0
  11. package/dist/api/gate/routes.d.ts +34 -0
  12. package/dist/api/gate/routes.js +235 -0
  13. package/dist/api/http/define.js +0 -8
  14. package/dist/api/http/routes/access.js +25 -18
  15. package/dist/api/http/routes/tenant.d.ts +2 -1
  16. package/dist/api/http/routes/tenant.js +77 -5
  17. package/dist/api/http/routes/vaults.js +2 -2
  18. package/dist/api/openapi.js +6 -7
  19. package/dist/gates/contract.d.ts +51 -0
  20. package/dist/gates/contract.js +37 -0
  21. package/dist/gates/handler.d.ts +21 -0
  22. package/dist/gates/handler.js +55 -0
  23. package/dist/gates/http-client.d.ts +12 -0
  24. package/dist/gates/http-client.js +160 -0
  25. package/dist/gates/in-process.d.ts +32 -0
  26. package/dist/gates/in-process.js +42 -0
  27. package/dist/gates/inflight.d.ts +39 -0
  28. package/dist/gates/inflight.js +70 -0
  29. package/dist/gates/mcp-handler.d.ts +35 -0
  30. package/dist/gates/mcp-handler.js +142 -0
  31. package/dist/gates/meter.d.ts +24 -0
  32. package/dist/gates/meter.js +165 -0
  33. package/dist/gates/model-gate.d.ts +45 -0
  34. package/dist/gates/model-gate.js +1 -0
  35. package/dist/gates/tenant-vaults.d.ts +64 -0
  36. package/dist/gates/tenant-vaults.js +94 -0
  37. package/dist/gates/tool-calls.d.ts +51 -0
  38. package/dist/gates/tool-calls.js +64 -0
  39. package/dist/gates/tool-client.d.ts +12 -0
  40. package/dist/gates/tool-client.js +201 -0
  41. package/dist/gates/tool-contract.d.ts +116 -0
  42. package/dist/gates/tool-contract.js +64 -0
  43. package/dist/gates/tool-gate.d.ts +45 -0
  44. package/dist/gates/tool-gate.js +10 -0
  45. package/dist/host/admin-api.d.ts +7 -6
  46. package/dist/host/admin-api.js +9 -113
  47. package/dist/host/app.d.ts +1 -1
  48. package/dist/host/app.js +20 -24
  49. package/dist/host/config-for.d.ts +1 -1
  50. package/dist/host/config-for.js +2 -2
  51. package/dist/host/create-host.d.ts +5 -5
  52. package/dist/host/create-host.js +5 -15
  53. package/dist/host/execution.d.ts +20 -18
  54. package/dist/host/execution.js +2 -2
  55. package/dist/host/gates.d.ts +58 -0
  56. package/dist/host/gates.js +127 -0
  57. package/dist/host/http.d.ts +6 -1
  58. package/dist/host/http.js +17 -0
  59. package/dist/host/index.d.ts +1 -1
  60. package/dist/host/main.js +151 -71
  61. package/dist/host/stack-config.d.ts +71 -19
  62. package/dist/host/stack-config.js +192 -18
  63. package/dist/infra/database.d.ts +2 -2
  64. package/dist/infra/execution.d.ts +5 -5
  65. package/dist/infra/execution.js +8 -6
  66. package/dist/infra/index.d.ts +1 -1
  67. package/dist/infra/workers.d.ts +17 -17
  68. package/dist/infra/workers.js +9 -9
  69. package/dist/keys/client.d.ts +9 -0
  70. package/dist/keys/client.js +70 -0
  71. package/dist/keys/contract.d.ts +24 -0
  72. package/dist/keys/contract.js +12 -0
  73. package/dist/keys/keys.d.ts +41 -0
  74. package/dist/keys/keys.js +50 -0
  75. package/dist/mcp/connect.d.ts +43 -3
  76. package/dist/mcp/connect.js +12 -5
  77. package/dist/mcp/pool.d.ts +21 -3
  78. package/dist/mcp/pool.js +15 -2
  79. package/dist/openapi.json +888 -695
  80. package/dist/record/append.d.ts +51 -0
  81. package/dist/record/append.js +20 -0
  82. package/dist/{store/event.js → record/envelope.js} +1 -1
  83. package/dist/record/index.d.ts +11 -0
  84. package/dist/record/index.js +11 -0
  85. package/dist/store/postgres/connect.d.ts +15 -12
  86. package/dist/store/postgres/connect.js +24 -12
  87. package/dist/store/postgres/db.d.ts +16 -0
  88. package/dist/store/postgres/db.js +28 -0
  89. package/dist/store/postgres/drizzle/0000_foundation.sql +22 -0
  90. package/dist/store/postgres/drizzle/0001_baseline.sql +255 -0
  91. package/dist/store/postgres/drizzle/0002_stream_relay.sql +4 -0
  92. package/dist/store/postgres/drizzle/0003_tool_crossings.sql +9 -0
  93. package/dist/store/postgres/drizzle/meta/_journal.json +34 -0
  94. package/dist/store/postgres/migrate.d.ts +68 -0
  95. package/dist/store/postgres/migrate.js +183 -0
  96. package/dist/store/postgres/record-writer.d.ts +4 -0
  97. package/dist/store/postgres/record-writer.js +34 -0
  98. package/dist/store/postgres/record.d.ts +2 -8
  99. package/dist/store/postgres/record.js +50 -54
  100. package/dist/store/postgres/schema.d.ts +3096 -0
  101. package/dist/store/postgres/schema.js +363 -0
  102. package/dist/store/postgres/store.d.ts +2 -4
  103. package/dist/store/postgres/store.js +481 -567
  104. package/dist/store/postgres/tenant.d.ts +56 -0
  105. package/dist/store/postgres/tenant.js +154 -0
  106. package/dist/store/types.d.ts +43 -87
  107. package/dist/store/types.js +0 -1
  108. package/dist/streams/control.d.ts +1 -1
  109. package/dist/streams/control.js +6 -2
  110. package/dist/streams/relay/types.d.ts +2 -1
  111. package/dist/streams/relay/types.js +2 -1
  112. package/dist/streams/types.d.ts +5 -0
  113. package/dist/tenant/advance.d.ts +7 -2
  114. package/dist/tenant/advance.js +95 -16
  115. package/dist/tenant/cause.d.ts +25 -0
  116. package/dist/tenant/cause.js +45 -0
  117. package/dist/tenant/commands.js +4 -2
  118. package/dist/tenant/context.d.ts +26 -3
  119. package/dist/tenant/delivery-token.js +17 -18
  120. package/dist/tenant/delivery.d.ts +1 -1
  121. package/dist/tenant/delivery.js +18 -13
  122. package/dist/tenant/effects.d.ts +15 -1
  123. package/dist/tenant/effects.js +93 -17
  124. package/dist/tenant/ephemeral.d.ts +16 -7
  125. package/dist/tenant/ephemeral.js +45 -111
  126. package/dist/tenant/history.d.ts +64 -0
  127. package/dist/tenant/history.js +120 -0
  128. package/dist/tenant/model-setting.d.ts +2 -2
  129. package/dist/tenant/module.d.ts +14 -28
  130. package/dist/tenant/module.js +131 -271
  131. package/dist/tenant/paths.d.ts +11 -16
  132. package/dist/tenant/paths.js +24 -68
  133. package/dist/tenant/pool.d.ts +1 -1
  134. package/dist/tenant/pool.js +1 -1
  135. package/dist/tenant/principals.d.ts +23 -11
  136. package/dist/tenant/principals.js +61 -49
  137. package/dist/tenant/runtime.d.ts +19 -1
  138. package/dist/tenant/runtime.js +40 -26
  139. package/dist/tenant/scheduler.d.ts +4 -2
  140. package/dist/tenant/scheduler.js +4 -4
  141. package/dist/tenant/session-streams.d.ts +2 -0
  142. package/dist/tenant/session-streams.js +8 -3
  143. package/dist/tenant/status.d.ts +3 -0
  144. package/dist/tenant/status.js +1 -1
  145. package/dist/tenant/store-pg.d.ts +9 -6
  146. package/dist/tenant/store-pg.js +60 -125
  147. package/dist/tenant/streams.d.ts +9 -25
  148. package/dist/tenant/streams.js +7 -22
  149. package/dist/tenant/tokens.js +16 -14
  150. package/dist/tenant/types.d.ts +41 -92
  151. package/dist/tenant/types.js +4 -15
  152. package/dist/tenant/worker.js +4 -4
  153. package/dist/vault/host-model.d.ts +31 -0
  154. package/dist/vault/host-model.js +57 -0
  155. package/dist/vault/service.d.ts +26 -15
  156. package/dist/vault/service.js +70 -109
  157. package/dist/version.d.ts +1 -1
  158. package/dist/version.js +1 -1
  159. package/package.json +9 -5
  160. package/dist/store/memory.d.ts +0 -69
  161. package/dist/store/memory.js +0 -810
  162. package/dist/store/postgres/migrations/001_initial.d.ts +0 -27
  163. package/dist/store/postgres/migrations/001_initial.js +0 -196
  164. package/dist/store/postgres/migrations/002_session_owner.d.ts +0 -6
  165. package/dist/store/postgres/migrations/002_session_owner.js +0 -13
  166. package/dist/store/postgres/migrations/003_subject_tokens.d.ts +0 -8
  167. package/dist/store/postgres/migrations/003_subject_tokens.js +0 -42
  168. package/dist/store/postgres/migrations/004_publishable_keys.d.ts +0 -6
  169. package/dist/store/postgres/migrations/004_publishable_keys.js +0 -18
  170. package/dist/store/postgres/migrations/005_action_endpoints.d.ts +0 -6
  171. package/dist/store/postgres/migrations/005_action_endpoints.js +0 -32
  172. package/dist/store/postgres/migrations/006_drop_executors.d.ts +0 -11
  173. package/dist/store/postgres/migrations/006_drop_executors.js +0 -32
  174. package/dist/store/postgres/migrations/007_event_time.d.ts +0 -7
  175. package/dist/store/postgres/migrations/007_event_time.js +0 -14
  176. package/dist/store/postgres/migrations/008_durable_streams.d.ts +0 -13
  177. package/dist/store/postgres/migrations/008_durable_streams.js +0 -35
  178. package/dist/store/postgres/migrations/index.d.ts +0 -53
  179. package/dist/store/postgres/migrations/index.js +0 -96
  180. package/dist/store/postgres/migrations/shared/index.d.ts +0 -31
  181. package/dist/store/postgres/migrations/shared/index.js +0 -92
  182. package/dist/store/postgres/names.d.ts +0 -11
  183. package/dist/store/postgres/names.js +0 -42
  184. package/dist/store/postgres/tenants.d.ts +0 -90
  185. package/dist/store/postgres/tenants.js +0 -228
  186. package/dist/streams/relay/memory.d.ts +0 -69
  187. package/dist/streams/relay/memory.js +0 -176
  188. package/dist/tenant/envelope.d.ts +0 -7
  189. package/dist/tenant/envelope.js +0 -22
  190. package/dist/tenant/quarantine-error.d.ts +0 -6
  191. package/dist/tenant/quarantine-error.js +0 -9
  192. package/dist/tenant/quarantine.d.ts +0 -27
  193. package/dist/tenant/quarantine.js +0 -72
  194. package/dist/tenant/store-memory.d.ts +0 -16
  195. package/dist/tenant/store-memory.js +0 -111
  196. /package/dist/{store → record}/cursor.d.ts +0 -0
  197. /package/dist/{store → record}/cursor.js +0 -0
  198. /package/dist/{store/event.d.ts → record/envelope.d.ts} +0 -0
@@ -9,7 +9,6 @@ import { type EventType } from "@nylorun/core/contracts";
9
9
  export declare const Rejected: z.ZodObject<{
10
10
  status: z.ZodLiteral<"rejected">;
11
11
  code: z.ZodEnum<{
12
- active_work: "active_work";
13
12
  connection_missing: "connection_missing";
14
13
  host_rejected: "host_rejected";
15
14
  incompatible_host: "incompatible_host";
@@ -23,7 +22,6 @@ export declare const Rejected: z.ZodObject<{
23
22
  scope_required: "scope_required";
24
23
  subject_invalid: "subject_invalid";
25
24
  subject_required: "subject_required";
26
- tenant_conflict: "tenant_conflict";
27
25
  token_expired: "token_expired";
28
26
  unsupported_media_type: "unsupported_media_type";
29
27
  }>;
@@ -41,68 +39,6 @@ export declare const ProtocolRejected: z.ZodObject<{
41
39
  features: z.ZodArray<z.ZodString>;
42
40
  }, z.core.$strict>;
43
41
  }, z.core.$strict>;
44
- export declare const TenantEnvelope: z.ZodObject<{
45
- id: z.ZodString;
46
- name: z.ZodString;
47
- createdAt: z.ZodString;
48
- updatedAt: z.ZodString;
49
- schemaVersion: z.ZodNumber;
50
- }, z.core.$strict>;
51
- export declare const CreateTenantRequest: z.ZodObject<{
52
- tenantId: z.ZodString;
53
- name: z.ZodString;
54
- principalId: z.ZodString;
55
- credentialHash: z.ZodString;
56
- idempotencyKey: z.ZodString;
57
- studioCredentialHash: z.ZodOptional<z.ZodString>;
58
- derivedPrincipals: z.ZodOptional<z.ZodArray<z.ZodObject<{
59
- id: z.ZodString;
60
- credentialHash: z.ZodString;
61
- }, z.core.$strict>>>;
62
- }, z.core.$strict>;
63
- export declare const AdminTenantList: z.ZodArray<z.ZodObject<{
64
- id: z.ZodString;
65
- name: z.ZodNullable<z.ZodString>;
66
- state: z.ZodEnum<{
67
- open: "open";
68
- quarantined: "quarantined";
69
- }>;
70
- envelope: z.ZodNullable<z.ZodObject<{
71
- id: z.ZodString;
72
- name: z.ZodString;
73
- createdAt: z.ZodString;
74
- updatedAt: z.ZodString;
75
- schemaVersion: z.ZodNumber;
76
- }, z.core.$strict>>;
77
- }, z.core.$strict>>;
78
- export declare const AdminTenantStatus: z.ZodObject<{
79
- id: z.ZodString;
80
- name: z.ZodNullable<z.ZodString>;
81
- state: z.ZodEnum<{
82
- open: "open";
83
- quarantined: "quarantined";
84
- }>;
85
- envelope: z.ZodNullable<z.ZodObject<{
86
- id: z.ZodString;
87
- name: z.ZodString;
88
- createdAt: z.ZodString;
89
- updatedAt: z.ZodString;
90
- schemaVersion: z.ZodNumber;
91
- }, z.core.$strict>>;
92
- quarantine: z.ZodOptional<z.ZodObject<{
93
- code: z.ZodEnum<{
94
- corrupt: "corrupt";
95
- "envelope-invalid": "envelope-invalid";
96
- "kek-missing": "kek-missing";
97
- "migration-failed": "migration-failed";
98
- "open-failed": "open-failed";
99
- "open-timeout": "open-timeout";
100
- "schema-too-new": "schema-too-new";
101
- }>;
102
- message: z.ZodString;
103
- repair: z.ZodString;
104
- }, z.core.$strict>>;
105
- }, z.core.$strict>;
106
42
  export declare const AdminStatus: z.ZodObject<{
107
43
  service: z.ZodString;
108
44
  version: z.ZodString;
@@ -111,12 +47,12 @@ export declare const AdminStatus: z.ZodObject<{
111
47
  max: z.ZodNumber;
112
48
  features: z.ZodArray<z.ZodString>;
113
49
  }, z.core.$strict>;
114
- tenants: z.ZodArray<z.ZodObject<{
115
- id: z.ZodString;
50
+ tenant: z.ZodObject<{
51
+ id: z.ZodNullable<z.ZodString>;
116
52
  name: z.ZodNullable<z.ZodString>;
117
53
  state: z.ZodEnum<{
118
54
  open: "open";
119
- quarantined: "quarantined";
55
+ unavailable: "unavailable";
120
56
  }>;
121
57
  envelope: z.ZodNullable<z.ZodObject<{
122
58
  id: z.ZodString;
@@ -125,7 +61,21 @@ export declare const AdminStatus: z.ZodObject<{
125
61
  updatedAt: z.ZodString;
126
62
  schemaVersion: z.ZodNumber;
127
63
  }, z.core.$strict>>;
128
- }, z.core.$strict>>;
64
+ cause: z.ZodOptional<z.ZodObject<{
65
+ code: z.ZodEnum<{
66
+ corrupt: "corrupt";
67
+ "database-layout-old": "database-layout-old";
68
+ "envelope-invalid": "envelope-invalid";
69
+ "kek-missing": "kek-missing";
70
+ "migration-failed": "migration-failed";
71
+ "open-failed": "open-failed";
72
+ "open-timeout": "open-timeout";
73
+ "schema-too-new": "schema-too-new";
74
+ }>;
75
+ message: z.ZodString;
76
+ repair: z.ZodString;
77
+ }, z.core.$strict>>;
78
+ }, z.core.$strict>;
129
79
  aggregate: z.ZodObject<{
130
80
  runningSessions: z.ZodNumber;
131
81
  inFlightDeliveries: z.ZodNumber;
@@ -2039,6 +1989,66 @@ export declare const SessionEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
2039
1989
  full: "full";
2040
1990
  metadata: "metadata";
2041
1991
  }>;
1992
+ } & {
1993
+ type: z.ZodLiteral<"transcript.updated">;
1994
+ payload: z.ZodObject<{
1995
+ keep: z.ZodNumber;
1996
+ entries: z.ZodArray<z.ZodUnknown>;
1997
+ length: z.ZodNumber;
1998
+ }, z.core.$loose>;
1999
+ }, z.core.$strip> | z.ZodObject<{
2000
+ schema: z.ZodLiteral<"nylorun.event/2">;
2001
+ eventId: z.ZodString;
2002
+ tenantId: z.ZodString;
2003
+ sessionId: z.ZodString;
2004
+ runId: z.ZodNullable<z.ZodString>;
2005
+ turnId: z.ZodNullable<z.ZodString>;
2006
+ incarnation: z.ZodNumber;
2007
+ epoch: z.ZodNumber;
2008
+ seq: z.ZodNumber;
2009
+ cursor: z.ZodString;
2010
+ time: z.ZodString;
2011
+ schemaVersion: z.ZodNumber;
2012
+ source: z.ZodObject<{
2013
+ kind: z.ZodEnum<{
2014
+ api: "api";
2015
+ controller: "controller";
2016
+ edge: "edge";
2017
+ "egress-gate": "egress-gate";
2018
+ evidence: "evidence";
2019
+ harness: "harness";
2020
+ human: "human";
2021
+ init: "init";
2022
+ loop: "loop";
2023
+ "model-gate": "model-gate";
2024
+ operator: "operator";
2025
+ sandboxd: "sandboxd";
2026
+ supervisor: "supervisor";
2027
+ "tool-gate": "tool-gate";
2028
+ }>;
2029
+ id: z.ZodString;
2030
+ }, z.core.$strip>;
2031
+ evidence: z.ZodEnum<{
2032
+ asserted: "asserted";
2033
+ attested: "attested";
2034
+ claimed: "claimed";
2035
+ measured: "measured";
2036
+ observed: "observed";
2037
+ }>;
2038
+ trace: z.ZodOptional<z.ZodObject<{
2039
+ traceId: z.ZodString;
2040
+ spanId: z.ZodString;
2041
+ parentSpanId: z.ZodOptional<z.ZodString>;
2042
+ }, z.core.$strip>>;
2043
+ visibility: z.ZodEnum<{
2044
+ internal: "internal";
2045
+ public: "public";
2046
+ restricted: "restricted";
2047
+ }>;
2048
+ retention: z.ZodEnum<{
2049
+ full: "full";
2050
+ metadata: "metadata";
2051
+ }>;
2042
2052
  } & {
2043
2053
  type: z.ZodLiteral<"turn.cancelled">;
2044
2054
  payload: z.ZodObject<{
@@ -3706,6 +3716,66 @@ export declare const SessionEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
3706
3716
  full: "full";
3707
3717
  metadata: "metadata";
3708
3718
  }>;
3719
+ } & {
3720
+ type: z.ZodLiteral<"transcript.updated">;
3721
+ payload: z.ZodObject<{
3722
+ keep: z.ZodNumber;
3723
+ entries: z.ZodArray<z.ZodUnknown>;
3724
+ length: z.ZodNumber;
3725
+ }, z.core.$loose>;
3726
+ }, z.core.$strip> | z.ZodObject<{
3727
+ schema: z.ZodLiteral<"nylorun.event/2">;
3728
+ eventId: z.ZodString;
3729
+ tenantId: z.ZodString;
3730
+ sessionId: z.ZodString;
3731
+ runId: z.ZodNullable<z.ZodString>;
3732
+ turnId: z.ZodNullable<z.ZodString>;
3733
+ incarnation: z.ZodNumber;
3734
+ epoch: z.ZodNumber;
3735
+ seq: z.ZodNumber;
3736
+ cursor: z.ZodString;
3737
+ time: z.ZodString;
3738
+ schemaVersion: z.ZodNumber;
3739
+ source: z.ZodObject<{
3740
+ kind: z.ZodEnum<{
3741
+ api: "api";
3742
+ controller: "controller";
3743
+ edge: "edge";
3744
+ "egress-gate": "egress-gate";
3745
+ evidence: "evidence";
3746
+ harness: "harness";
3747
+ human: "human";
3748
+ init: "init";
3749
+ loop: "loop";
3750
+ "model-gate": "model-gate";
3751
+ operator: "operator";
3752
+ sandboxd: "sandboxd";
3753
+ supervisor: "supervisor";
3754
+ "tool-gate": "tool-gate";
3755
+ }>;
3756
+ id: z.ZodString;
3757
+ }, z.core.$strip>;
3758
+ evidence: z.ZodEnum<{
3759
+ asserted: "asserted";
3760
+ attested: "attested";
3761
+ claimed: "claimed";
3762
+ measured: "measured";
3763
+ observed: "observed";
3764
+ }>;
3765
+ trace: z.ZodOptional<z.ZodObject<{
3766
+ traceId: z.ZodString;
3767
+ spanId: z.ZodString;
3768
+ parentSpanId: z.ZodOptional<z.ZodString>;
3769
+ }, z.core.$strip>>;
3770
+ visibility: z.ZodEnum<{
3771
+ internal: "internal";
3772
+ public: "public";
3773
+ restricted: "restricted";
3774
+ }>;
3775
+ retention: z.ZodEnum<{
3776
+ full: "full";
3777
+ metadata: "metadata";
3778
+ }>;
3709
3779
  } & {
3710
3780
  type: z.ZodLiteral<"turn.cancelled">;
3711
3781
  payload: z.ZodObject<{
@@ -5376,6 +5446,66 @@ export declare const SessionItemsResponse: z.ZodObject<{
5376
5446
  full: "full";
5377
5447
  metadata: "metadata";
5378
5448
  }>;
5449
+ } & {
5450
+ type: z.ZodLiteral<"transcript.updated">;
5451
+ payload: z.ZodObject<{
5452
+ keep: z.ZodNumber;
5453
+ entries: z.ZodArray<z.ZodUnknown>;
5454
+ length: z.ZodNumber;
5455
+ }, z.core.$loose>;
5456
+ }, z.core.$strip> | z.ZodObject<{
5457
+ schema: z.ZodLiteral<"nylorun.event/2">;
5458
+ eventId: z.ZodString;
5459
+ tenantId: z.ZodString;
5460
+ sessionId: z.ZodString;
5461
+ runId: z.ZodNullable<z.ZodString>;
5462
+ turnId: z.ZodNullable<z.ZodString>;
5463
+ incarnation: z.ZodNumber;
5464
+ epoch: z.ZodNumber;
5465
+ seq: z.ZodNumber;
5466
+ cursor: z.ZodString;
5467
+ time: z.ZodString;
5468
+ schemaVersion: z.ZodNumber;
5469
+ source: z.ZodObject<{
5470
+ kind: z.ZodEnum<{
5471
+ api: "api";
5472
+ controller: "controller";
5473
+ edge: "edge";
5474
+ "egress-gate": "egress-gate";
5475
+ evidence: "evidence";
5476
+ harness: "harness";
5477
+ human: "human";
5478
+ init: "init";
5479
+ loop: "loop";
5480
+ "model-gate": "model-gate";
5481
+ operator: "operator";
5482
+ sandboxd: "sandboxd";
5483
+ supervisor: "supervisor";
5484
+ "tool-gate": "tool-gate";
5485
+ }>;
5486
+ id: z.ZodString;
5487
+ }, z.core.$strip>;
5488
+ evidence: z.ZodEnum<{
5489
+ asserted: "asserted";
5490
+ attested: "attested";
5491
+ claimed: "claimed";
5492
+ measured: "measured";
5493
+ observed: "observed";
5494
+ }>;
5495
+ trace: z.ZodOptional<z.ZodObject<{
5496
+ traceId: z.ZodString;
5497
+ spanId: z.ZodString;
5498
+ parentSpanId: z.ZodOptional<z.ZodString>;
5499
+ }, z.core.$strip>>;
5500
+ visibility: z.ZodEnum<{
5501
+ internal: "internal";
5502
+ public: "public";
5503
+ restricted: "restricted";
5504
+ }>;
5505
+ retention: z.ZodEnum<{
5506
+ full: "full";
5507
+ metadata: "metadata";
5508
+ }>;
5379
5509
  } & {
5380
5510
  type: z.ZodLiteral<"turn.cancelled">;
5381
5511
  payload: z.ZodObject<{
@@ -7043,6 +7173,66 @@ export declare const SessionItemsResponse: z.ZodObject<{
7043
7173
  full: "full";
7044
7174
  metadata: "metadata";
7045
7175
  }>;
7176
+ } & {
7177
+ type: z.ZodLiteral<"transcript.updated">;
7178
+ payload: z.ZodObject<{
7179
+ keep: z.ZodNumber;
7180
+ entries: z.ZodArray<z.ZodUnknown>;
7181
+ length: z.ZodNumber;
7182
+ }, z.core.$loose>;
7183
+ }, z.core.$strip> | z.ZodObject<{
7184
+ schema: z.ZodLiteral<"nylorun.event/2">;
7185
+ eventId: z.ZodString;
7186
+ tenantId: z.ZodString;
7187
+ sessionId: z.ZodString;
7188
+ runId: z.ZodNullable<z.ZodString>;
7189
+ turnId: z.ZodNullable<z.ZodString>;
7190
+ incarnation: z.ZodNumber;
7191
+ epoch: z.ZodNumber;
7192
+ seq: z.ZodNumber;
7193
+ cursor: z.ZodString;
7194
+ time: z.ZodString;
7195
+ schemaVersion: z.ZodNumber;
7196
+ source: z.ZodObject<{
7197
+ kind: z.ZodEnum<{
7198
+ api: "api";
7199
+ controller: "controller";
7200
+ edge: "edge";
7201
+ "egress-gate": "egress-gate";
7202
+ evidence: "evidence";
7203
+ harness: "harness";
7204
+ human: "human";
7205
+ init: "init";
7206
+ loop: "loop";
7207
+ "model-gate": "model-gate";
7208
+ operator: "operator";
7209
+ sandboxd: "sandboxd";
7210
+ supervisor: "supervisor";
7211
+ "tool-gate": "tool-gate";
7212
+ }>;
7213
+ id: z.ZodString;
7214
+ }, z.core.$strip>;
7215
+ evidence: z.ZodEnum<{
7216
+ asserted: "asserted";
7217
+ attested: "attested";
7218
+ claimed: "claimed";
7219
+ measured: "measured";
7220
+ observed: "observed";
7221
+ }>;
7222
+ trace: z.ZodOptional<z.ZodObject<{
7223
+ traceId: z.ZodString;
7224
+ spanId: z.ZodString;
7225
+ parentSpanId: z.ZodOptional<z.ZodString>;
7226
+ }, z.core.$strip>>;
7227
+ visibility: z.ZodEnum<{
7228
+ internal: "internal";
7229
+ public: "public";
7230
+ restricted: "restricted";
7231
+ }>;
7232
+ retention: z.ZodEnum<{
7233
+ full: "full";
7234
+ metadata: "metadata";
7235
+ }>;
7046
7236
  } & {
7047
7237
  type: z.ZodLiteral<"turn.cancelled">;
7048
7238
  payload: z.ZodObject<{
@@ -7456,6 +7646,56 @@ export declare const TenantSandboxView: z.ZodObject<{
7456
7646
  }, z.core.$strict>;
7457
7647
  }, z.core.$strict>;
7458
7648
  }, z.core.$strict>;
7649
+ export declare const ModelUsageTotals: z.ZodObject<{
7650
+ scope: z.ZodEnum<{
7651
+ agent: "agent";
7652
+ tenant: "tenant";
7653
+ turn: "turn";
7654
+ }>;
7655
+ id: z.ZodOptional<z.ZodString>;
7656
+ period: z.ZodEnum<{
7657
+ day: "day";
7658
+ month: "month";
7659
+ total: "total";
7660
+ }>;
7661
+ since: z.ZodOptional<z.ZodString>;
7662
+ calls: z.ZodNumber;
7663
+ tokens: z.ZodNumber;
7664
+ costUsd: z.ZodNumber;
7665
+ }, z.core.$strict>;
7666
+ export declare const ModelBudgets: z.ZodObject<{
7667
+ budgets: z.ZodArray<z.ZodObject<{
7668
+ scope: z.ZodEnum<{
7669
+ agent: "agent";
7670
+ tenant: "tenant";
7671
+ turn: "turn";
7672
+ }>;
7673
+ id: z.ZodOptional<z.ZodString>;
7674
+ period: z.ZodOptional<z.ZodEnum<{
7675
+ day: "day";
7676
+ month: "month";
7677
+ }>>;
7678
+ limitUsd: z.ZodOptional<z.ZodNumber>;
7679
+ limitTokens: z.ZodOptional<z.ZodNumber>;
7680
+ }, z.core.$strict>>;
7681
+ }, z.core.$strict>;
7682
+ export declare const PutModelBudgetsRequest: z.ZodObject<{
7683
+ requestId: z.ZodOptional<z.ZodString>;
7684
+ budgets: z.ZodArray<z.ZodObject<{
7685
+ scope: z.ZodEnum<{
7686
+ agent: "agent";
7687
+ tenant: "tenant";
7688
+ turn: "turn";
7689
+ }>;
7690
+ id: z.ZodOptional<z.ZodString>;
7691
+ period: z.ZodOptional<z.ZodEnum<{
7692
+ day: "day";
7693
+ month: "month";
7694
+ }>>;
7695
+ limitUsd: z.ZodOptional<z.ZodNumber>;
7696
+ limitTokens: z.ZodOptional<z.ZodNumber>;
7697
+ }, z.core.$strict>>;
7698
+ }, z.core.$strict>;
7459
7699
  export declare const PutTenantSandboxRequest: z.ZodObject<{
7460
7700
  default: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"none">, z.ZodLiteral<"virtual">, z.ZodObject<{
7461
7701
  image: z.ZodOptional<z.ZodString>;
@@ -5,16 +5,12 @@
5
5
  * global registry.
6
6
  */
7
7
  import { z } from "zod";
8
- import { JwksSchema, CreateTokenRequestSchema, CreateTokenResponseSchema, AccessPolicyResponseSchema, PutAccessPolicyRequestSchema, SigningKeyListSchema, SigningKeyViewSchema, RotateSigningKeysRequestSchema, RevokeSigningKeyRequestSchema, ListPublishableKeysResponseSchema, PublishableKeySchema, CreatePublishableKeyRequestSchema, UpdatePublishableKeyRequestSchema, RevokeSubjectRequestSchema, RevokeSubjectResponseSchema, TenantStatusSchema, ResetTenantRequestSchema, ResetTenantResponseSchema, SeedTenantConfigRequestSchema, SeedTenantConfigResponseSchema, HostModelCatalogSchema, TenantSandboxViewSchema, PutTenantSandboxRequestSchema, ListProvidersResponseSchema, HostModelViewSchema, PutHostModelRequestSchema, SelectHostModelRequestSchema, CreateVaultRequestSchema, VaultInfoSchema, ListVaultsResponseSchema, CreateCredentialRequestSchema, CredentialInfoSchema, ListCredentialsResponseSchema, RotateCredentialRequestSchema, DeletedResponseSchema, ListAgentsResponseSchema, ListPublicAgentsResponseSchema, ListSessionsResponseSchema, LiveEventSchema, PutAgentRequestSchema, PutAgentResponseSchema, PutSessionRequestSchema, SessionItemsResponseSchema, SessionViewSchema, StreamClosedFrameSchema, AcceptedResponseSchema, ActionResultReceiptSchema, DeleteEndpointResponseSchema, DeliveryHeartbeatResponseSchema, ActionOutcomeSchema, EndpointPingResponseSchema, ListEndpointsResponseSchema, PutEndpointsRequestSchema, SandboxToolOutcomeSchema, SessionCommandSchema, AdminStatusSchema, AdminTenantListSchema, AdminTenantStatusSchema, CreateTenantRequestSchema, HostShutdownResponseSchema, ProtocolRejectedResponseSchema, RejectedResponseSchema, TenantEnvelopeSchema, EVENT_SCHEMAS, EVENT_TYPES, } from "@nylorun/core/contracts";
8
+ import { JwksSchema, CreateTokenRequestSchema, CreateTokenResponseSchema, AccessPolicyResponseSchema, PutAccessPolicyRequestSchema, SigningKeyListSchema, SigningKeyViewSchema, RotateSigningKeysRequestSchema, RevokeSigningKeyRequestSchema, ListPublishableKeysResponseSchema, PublishableKeySchema, CreatePublishableKeyRequestSchema, UpdatePublishableKeyRequestSchema, RevokeSubjectRequestSchema, RevokeSubjectResponseSchema, TenantStatusSchema, ResetTenantRequestSchema, ResetTenantResponseSchema, SeedTenantConfigRequestSchema, SeedTenantConfigResponseSchema, HostModelCatalogSchema, TenantSandboxViewSchema, ModelUsageTotalsSchema, ModelBudgetsSchema, PutModelBudgetsRequestSchema, PutTenantSandboxRequestSchema, ListProvidersResponseSchema, HostModelViewSchema, PutHostModelRequestSchema, SelectHostModelRequestSchema, CreateVaultRequestSchema, VaultInfoSchema, ListVaultsResponseSchema, CreateCredentialRequestSchema, CredentialInfoSchema, ListCredentialsResponseSchema, RotateCredentialRequestSchema, DeletedResponseSchema, ListAgentsResponseSchema, ListPublicAgentsResponseSchema, ListSessionsResponseSchema, LiveEventSchema, PutAgentRequestSchema, PutAgentResponseSchema, PutSessionRequestSchema, SessionItemsResponseSchema, SessionViewSchema, StreamClosedFrameSchema, AcceptedResponseSchema, ActionResultReceiptSchema, DeleteEndpointResponseSchema, DeliveryHeartbeatResponseSchema, ActionOutcomeSchema, EndpointPingResponseSchema, ListEndpointsResponseSchema, PutEndpointsRequestSchema, SandboxToolOutcomeSchema, SessionCommandSchema, AdminStatusSchema, HostShutdownResponseSchema, ProtocolRejectedResponseSchema, RejectedResponseSchema, EVENT_SCHEMAS, EVENT_TYPES, } from "@nylorun/core/contracts";
9
9
  function named(id, schema) {
10
10
  return schema.meta({ id });
11
11
  }
12
12
  export const Rejected = named("Rejected", RejectedResponseSchema);
13
13
  export const ProtocolRejected = named("ProtocolRejected", ProtocolRejectedResponseSchema);
14
- export const TenantEnvelope = named("TenantEnvelope", TenantEnvelopeSchema);
15
- export const CreateTenantRequest = named("CreateTenantRequest", CreateTenantRequestSchema);
16
- export const AdminTenantList = named("AdminTenantList", AdminTenantListSchema);
17
- export const AdminTenantStatus = named("AdminTenantStatus", AdminTenantStatusSchema);
18
14
  export const AdminStatus = named("AdminStatus", AdminStatusSchema);
19
15
  export const HostShutdownResponse = named("HostShutdownResponse", HostShutdownResponseSchema);
20
16
  export const SandboxToolOutcome = named("SandboxToolOutcome", SandboxToolOutcomeSchema);
@@ -53,6 +49,9 @@ export const SeedTenantConfigRequest = named("SeedTenantConfigRequest", SeedTena
53
49
  export const SeedTenantConfigResponse = named("SeedTenantConfigResponse", SeedTenantConfigResponseSchema);
54
50
  export const HostModelCatalog = named("HostModelCatalog", HostModelCatalogSchema);
55
51
  export const TenantSandboxView = named("TenantSandboxView", TenantSandboxViewSchema);
52
+ export const ModelUsageTotals = named("ModelUsageTotals", ModelUsageTotalsSchema);
53
+ export const ModelBudgets = named("ModelBudgets", ModelBudgetsSchema);
54
+ export const PutModelBudgetsRequest = named("PutModelBudgetsRequest", PutModelBudgetsRequestSchema);
56
55
  export const PutTenantSandboxRequest = named("PutTenantSandboxRequest", PutTenantSandboxRequestSchema);
57
56
  export const ListProvidersResponse = named("ListProvidersResponse", ListProvidersResponseSchema);
58
57
  export const HostModelView = named("HostModelView", HostModelViewSchema);
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The `keys` service's route on the gateway's listener (F4.2, `contract.ts`): one operation of
3
+ * `Keys` per request, run with the vault key of the gateway's Tenant. Errors keep their status,
4
+ * code and details. Logs the operation and its outcome, never an argument or a result.
5
+ */
6
+ import type { Hono, MiddlewareHandler } from "hono";
7
+ import type { Logger } from "../../tenant/types.js";
8
+ import { type Keys } from "../../keys/keys.js";
9
+ export declare function mountKeysRoutes(app: Hono, options: {
10
+ readonly authorized: MiddlewareHandler;
11
+ /** The gateway's Tenant's keys; rejects when the Tenant is not ready. */
12
+ readonly keys: () => Promise<Keys>;
13
+ readonly logger: Logger;
14
+ }): void;
@@ -0,0 +1,59 @@
1
+ import { bodyLimit } from "hono/body-limit";
2
+ import { HttpError } from "../../tenant/http.js";
3
+ import { VaultError } from "../../vault/error.js";
4
+ import { KEYS_PATH, MAX_KEYS_BODY_BYTES } from "../../keys/contract.js";
5
+ import { KEYS_OPERATIONS } from "../../keys/keys.js";
6
+ export function mountKeysRoutes(app, options) {
7
+ app.post(`${KEYS_PATH}/:operation`, options.authorized, bodyLimit({
8
+ maxSize: MAX_KEYS_BODY_BYTES,
9
+ onError: (c) => c.json({ error: { code: "invalid_request", message: "The body is too large" } }, 400),
10
+ }), async (c) => {
11
+ const operation = c.req.param("operation");
12
+ if (!KEYS_OPERATIONS.includes(operation))
13
+ return c.json({ error: { code: "invalid_request", message: `Unknown keys operation ${operation}` } }, 404);
14
+ let args;
15
+ try {
16
+ args = (await c.req.json()).args;
17
+ }
18
+ catch {
19
+ args = undefined;
20
+ }
21
+ if (!Array.isArray(args))
22
+ return c.json({ error: { code: "invalid_request", message: "The body must be {args: [...]}" } }, 400);
23
+ const started = Date.now();
24
+ let answer;
25
+ try {
26
+ const keys = await options.keys();
27
+ const run = keys[operation];
28
+ answer = { result: (await run.apply(keys, args)) ?? null };
29
+ }
30
+ catch (error) {
31
+ answer = { error: errorOf(error) };
32
+ }
33
+ options.logger.info("keys_request", {
34
+ operation,
35
+ ms: Date.now() - started,
36
+ outcome: "result" in answer ? "ok" : String(answer.error.status),
37
+ });
38
+ return c.json(answer);
39
+ });
40
+ }
41
+ function errorOf(error) {
42
+ if (error instanceof VaultError)
43
+ return { kind: "vault", status: error.status, message: error.message };
44
+ if (error instanceof HttpError)
45
+ return {
46
+ kind: "http",
47
+ status: error.status,
48
+ message: error.message,
49
+ ...(error.rejection.code === undefined ? {} : { code: error.rejection.code }),
50
+ ...(error.rejection.details === undefined ? {} : { details: error.rejection.details }),
51
+ };
52
+ // A request error the route would answer 400 for, or an internal failure.
53
+ const zod = error?.name === "ZodError";
54
+ return {
55
+ kind: "http",
56
+ status: zod ? 400 : 500,
57
+ message: zod ? error.message : "The keys service failed",
58
+ };
59
+ }
@@ -0,0 +1,34 @@
1
+ import { Hono } from "hono";
2
+ import type { ModelCallHandler } from "../../gates/handler.js";
3
+ import { type InflightCalls } from "../../gates/inflight.js";
4
+ import type { McpHandler } from "../../gates/mcp-handler.js";
5
+ import type { ToolCalls } from "../../gates/tool-calls.js";
6
+ import type { Keys } from "../../keys/keys.js";
7
+ import type { Logger } from "../../tenant/types.js";
8
+ import { type OutboundPolicy } from "../../tenant/outbound.js";
9
+ export interface GatesAppOptions {
10
+ /** The bearer every model call must present (`NYLORUN_GATES_TOKEN`). */
11
+ readonly token: string;
12
+ /** Serves an authenticated, well-formed call. */
13
+ readonly modelGate: ModelCallHandler;
14
+ /** Keyed calls, which outlive their client (P1.2). */
15
+ readonly inflight: InflightCalls;
16
+ /** Whether the gate's dependencies answer (Postgres). */
17
+ readonly ready: () => Promise<boolean>;
18
+ /** Largest body read. Default `MAX_MODEL_CALL_BYTES`. */
19
+ readonly maxBodyBytes?: number;
20
+ /** Remote MCP servers (F4.1). Without it the MCP routes answer 404. */
21
+ readonly mcp?: McpHandler;
22
+ /** Keyed MCP calls, which outlive their client and run once (F4.1 G3). Needs `mcp`. */
23
+ readonly toolCalls?: ToolCalls;
24
+ /** The keys service's operations (F4.2). Without it the keys route answers 404. */
25
+ readonly keys?: () => Promise<Keys>;
26
+ /** Logs the keys service's requests. */
27
+ readonly logger?: Logger;
28
+ /**
29
+ * How the gate may call Action endpoints (the gateway's own `NYLORUN_ENDPOINT_*`), for
30
+ * deliveries (F4.1). Without it the delivery route answers 404.
31
+ */
32
+ readonly delivery?: OutboundPolicy;
33
+ }
34
+ export declare function createGatesApp(options: GatesAppOptions): Hono;