@m6d/cortex-server 1.7.0 → 2.0.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 (239) hide show
  1. package/README.md +8 -3
  2. package/contracts/README.md +23 -0
  3. package/contracts/graph/embed.ts +50 -0
  4. package/{src → contracts}/graph/helpers.ts +4 -10
  5. package/{src → contracts}/graph/neo4j.ts +14 -27
  6. package/contracts/graph/schema.ts +65 -0
  7. package/{src → contracts}/graph/types.ts +2 -29
  8. package/contracts/graph.ts +36 -0
  9. package/contracts/runtime.ts +208 -0
  10. package/contracts/wire.ts +143 -0
  11. package/dist/contracts/graph/embed.d.ts +22 -0
  12. package/dist/{src → contracts}/graph/helpers.d.ts +14 -12
  13. package/dist/{src → contracts}/graph/neo4j.d.ts +5 -5
  14. package/dist/contracts/graph/schema.d.ts +62 -0
  15. package/dist/{src → contracts}/graph/types.d.ts +1 -1
  16. package/dist/contracts/graph.d.ts +14 -0
  17. package/dist/contracts/runtime.d.ts +278 -0
  18. package/dist/contracts/wire.d.ts +120 -0
  19. package/dist/index.d.ts +1 -1
  20. package/dist/src/lib/adapters/database/index.d.ts +61 -0
  21. package/dist/src/lib/adapters/database/message-content.d.ts +30 -0
  22. package/dist/src/lib/adapters/database/mssql/attachments.d.ts +100 -0
  23. package/dist/src/lib/adapters/database/mssql/client.d.ts +8 -0
  24. package/dist/src/lib/adapters/database/mssql/index.d.ts +194 -0
  25. package/dist/src/lib/adapters/database/mssql/llm-requests.d.ts +17 -0
  26. package/dist/src/lib/adapters/database/mssql/messages.d.ts +37 -0
  27. package/dist/src/lib/adapters/database/mssql/threads.d.ts +50 -0
  28. package/dist/src/lib/adapters/database/postgres/attachments.d.ts +113 -0
  29. package/dist/src/lib/adapters/database/postgres/client.d.ts +8 -0
  30. package/dist/src/lib/adapters/database/postgres/index.d.ts +207 -0
  31. package/dist/src/lib/adapters/database/postgres/llm-requests.d.ts +17 -0
  32. package/dist/src/lib/adapters/database/postgres/messages.d.ts +37 -0
  33. package/dist/src/lib/adapters/database/postgres/threads.d.ts +50 -0
  34. package/{src/adapters/storage.ts → dist/src/lib/adapters/storage/index.d.ts} +1 -1
  35. package/dist/src/{adapters → lib/adapters/storage}/minio.d.ts +1 -1
  36. package/dist/src/lib/ai/active-runs.d.ts +63 -0
  37. package/dist/src/lib/ai/attachments.d.ts +30 -0
  38. package/dist/src/lib/ai/backend-url.d.ts +16 -0
  39. package/dist/src/lib/ai/cc-runtime.d.ts +61 -0
  40. package/dist/src/lib/ai/commit-gate.d.ts +21 -0
  41. package/dist/src/{ai → lib/ai}/context/builder.d.ts +6 -7
  42. package/dist/src/lib/ai/context/compression-middleware.d.ts +15 -0
  43. package/dist/src/lib/ai/context/compressor.d.ts +7 -0
  44. package/dist/src/lib/ai/context/intra-turn-compressor.d.ts +24 -0
  45. package/dist/src/lib/ai/context/optimize-thread-context.d.ts +9 -0
  46. package/dist/src/lib/ai/context/summarizer.d.ts +5 -0
  47. package/dist/src/{ai → lib/ai}/context/token-estimator.d.ts +5 -8
  48. package/dist/src/{ai → lib/ai}/context/types.d.ts +2 -0
  49. package/dist/src/{ai → lib/ai}/fetch.d.ts +1 -1
  50. package/dist/src/lib/ai/finish-turn.d.ts +23 -0
  51. package/dist/src/lib/ai/helpers.d.ts +38 -0
  52. package/dist/src/lib/ai/index.d.ts +7 -0
  53. package/dist/src/lib/ai/inspector.d.ts +41 -0
  54. package/dist/src/lib/ai/interceptors/request-interceptor.d.ts +13 -0
  55. package/dist/src/{ai → lib/ai}/prompt.d.ts +5 -4
  56. package/dist/src/lib/ai/redis-runs.d.ts +41 -0
  57. package/dist/src/lib/ai/redis-stream-log.d.ts +39 -0
  58. package/dist/src/lib/ai/tools/execute-code.tool.d.ts +18 -0
  59. package/dist/src/lib/ai/tools/query-graph.tool.d.ts +13 -0
  60. package/dist/src/lib/ai/tools/read-attachment.tool.d.ts +21 -0
  61. package/dist/src/lib/ai/tools/search-common.d.ts +17 -0
  62. package/dist/src/lib/ai/tools/search-knowledge.tool.d.ts +15 -0
  63. package/dist/src/lib/ai/tools/search-services.tool.d.ts +12 -0
  64. package/dist/src/lib/ai/tools/search-tools.tool.d.ts +12 -0
  65. package/dist/src/lib/ai/turn-tools.d.ts +39 -0
  66. package/dist/src/lib/ai/vision/rasterize-pdf.d.ts +26 -0
  67. package/dist/src/lib/ai/vision/rasterize-pdf.worker.d.ts +1 -0
  68. package/dist/src/lib/ai/vision/vision-reader.d.ts +45 -0
  69. package/dist/src/lib/cc/client.d.ts +183 -0
  70. package/dist/src/lib/cc/config-cache.d.ts +20 -0
  71. package/dist/src/lib/cc/format.d.ts +23 -0
  72. package/dist/src/lib/cc/registry.d.ts +34 -0
  73. package/dist/src/lib/cc/types.d.ts +27 -0
  74. package/dist/src/lib/config.d.ts +170 -0
  75. package/dist/src/lib/db/drizzle.config.mssql.d.ts +2 -0
  76. package/dist/src/lib/db/drizzle.config.pg.d.ts +2 -0
  77. package/dist/src/lib/db/migrate.d.ts +7 -0
  78. package/dist/src/{db/schema.d.ts → lib/db/schema.mssql.d.ts} +236 -24
  79. package/dist/src/lib/db/schema.pg.d.ts +546 -0
  80. package/dist/src/{factory.d.ts → lib/factory.d.ts} +2 -12
  81. package/dist/src/lib/graph/index.d.ts +10 -0
  82. package/dist/src/{graph → lib/graph}/resolver.d.ts +2 -3
  83. package/dist/src/{index.d.ts → lib/index.d.ts} +3 -4
  84. package/dist/src/lib/redis.d.ts +19 -0
  85. package/dist/src/{routes → lib/routes}/chat.d.ts +1 -1
  86. package/dist/src/{routes → lib/routes}/files.d.ts +1 -1
  87. package/dist/src/lib/routes/owned-thread.d.ts +17 -0
  88. package/dist/src/{routes → lib/routes}/threads.d.ts +1 -1
  89. package/dist/src/{routes → lib/routes}/ws.d.ts +1 -1
  90. package/dist/src/lib/types.d.ts +58 -0
  91. package/dist/src/{ws → lib/ws}/connections.d.ts +2 -1
  92. package/index.ts +1 -1
  93. package/package.json +35 -15
  94. package/src/lib/adapters/database/index.ts +78 -0
  95. package/src/lib/adapters/database/message-content.ts +39 -0
  96. package/src/lib/adapters/database/mssql/attachments.ts +90 -0
  97. package/src/lib/adapters/database/mssql/client.ts +11 -0
  98. package/src/lib/adapters/database/mssql/index.ts +23 -0
  99. package/src/lib/adapters/database/mssql/llm-requests.ts +43 -0
  100. package/src/lib/adapters/database/mssql/messages.ts +92 -0
  101. package/src/lib/adapters/database/mssql/threads.ts +83 -0
  102. package/src/lib/adapters/database/postgres/attachments.ts +88 -0
  103. package/src/lib/adapters/database/postgres/client.ts +11 -0
  104. package/src/lib/adapters/database/postgres/index.ts +23 -0
  105. package/src/lib/adapters/database/postgres/llm-requests.ts +45 -0
  106. package/src/lib/adapters/database/postgres/messages.ts +92 -0
  107. package/src/lib/adapters/database/postgres/threads.ts +84 -0
  108. package/{dist/src/adapters/storage.d.ts → src/lib/adapters/storage/index.ts} +1 -1
  109. package/src/{adapters → lib/adapters/storage}/minio.ts +7 -6
  110. package/src/lib/ai/active-runs.ts +157 -0
  111. package/src/lib/ai/attachments.ts +144 -0
  112. package/src/lib/ai/backend-url.ts +27 -0
  113. package/src/lib/ai/cc-runtime.ts +63 -0
  114. package/src/lib/ai/commit-gate.ts +116 -0
  115. package/src/{ai → lib/ai}/context/builder.ts +12 -14
  116. package/src/lib/ai/context/compression-middleware.ts +44 -0
  117. package/src/lib/ai/context/compressor.ts +267 -0
  118. package/src/lib/ai/context/intra-turn-compressor.ts +181 -0
  119. package/src/lib/ai/context/optimize-thread-context.ts +50 -0
  120. package/src/lib/ai/context/summarizer.ts +48 -0
  121. package/src/lib/ai/context/token-estimator.ts +65 -0
  122. package/src/{ai → lib/ai}/context/types.ts +4 -1
  123. package/src/{ai → lib/ai}/fetch.ts +10 -5
  124. package/src/lib/ai/finish-turn.ts +75 -0
  125. package/src/lib/ai/helpers.ts +100 -0
  126. package/src/lib/ai/index.ts +408 -0
  127. package/src/lib/ai/inspector.ts +112 -0
  128. package/src/lib/ai/interceptors/request-interceptor.ts +89 -0
  129. package/src/lib/ai/prompt.ts +355 -0
  130. package/src/lib/ai/redis-runs.ts +167 -0
  131. package/src/lib/ai/redis-stream-log.ts +219 -0
  132. package/src/lib/ai/tools/execute-code.tool.ts +267 -0
  133. package/src/{ai → lib/ai}/tools/query-graph.tool.ts +7 -8
  134. package/src/lib/ai/tools/read-attachment.tool.ts +59 -0
  135. package/src/lib/ai/tools/search-common.ts +15 -0
  136. package/src/lib/ai/tools/search-knowledge.tool.ts +33 -0
  137. package/src/lib/ai/tools/search-services.tool.ts +31 -0
  138. package/src/lib/ai/tools/search-tools.tool.ts +29 -0
  139. package/src/lib/ai/turn-tools.ts +154 -0
  140. package/src/lib/ai/vision/rasterize-pdf.ts +69 -0
  141. package/src/lib/ai/vision/rasterize-pdf.worker.ts +81 -0
  142. package/src/lib/ai/vision/vision-reader.ts +130 -0
  143. package/src/{auth → lib/auth}/middleware.ts +12 -3
  144. package/src/lib/cc/client.ts +273 -0
  145. package/src/lib/cc/config-cache.ts +32 -0
  146. package/src/lib/cc/format.ts +96 -0
  147. package/src/lib/cc/registry.ts +62 -0
  148. package/src/lib/cc/types.ts +44 -0
  149. package/src/lib/config.ts +212 -0
  150. package/src/lib/db/drizzle.config.mssql.ts +9 -0
  151. package/src/lib/db/drizzle.config.pg.ts +9 -0
  152. package/src/lib/db/migrate.ts +56 -0
  153. package/src/{db/migrations/20260309012148_cloudy_maria_hill → lib/db/migrations/mssql/20260326231647_nice_speedball}/migration.sql +12 -0
  154. package/src/{db/migrations/20260309012148_cloudy_maria_hill → lib/db/migrations/mssql/20260326231647_nice_speedball}/snapshot.json +106 -1
  155. package/src/lib/db/migrations/mssql/20260729092726_talented_wilson_fisk/migration.sql +20 -0
  156. package/src/lib/db/migrations/mssql/20260729092726_talented_wilson_fisk/snapshot.json +497 -0
  157. package/src/lib/db/migrations/mssql/20260801003652_perpetual_blue_shield/migration.sql +1 -0
  158. package/src/lib/db/migrations/mssql/20260801003652_perpetual_blue_shield/snapshot.json +516 -0
  159. package/src/lib/db/migrations/mssql/20260812174642_user_id_text/migration.sql +2 -0
  160. package/src/lib/db/migrations/mssql/20260812174642_user_id_text/snapshot.json +516 -0
  161. package/src/lib/db/migrations/pg/20260801084117_thick_ben_grimm/migration.sql +53 -0
  162. package/src/lib/db/migrations/pg/20260801084117_thick_ben_grimm/snapshot.json +584 -0
  163. package/src/lib/db/migrations/pg/20260812174622_user_id_text/migration.sql +2 -0
  164. package/src/lib/db/migrations/pg/20260812174622_user_id_text/snapshot.json +584 -0
  165. package/src/lib/db/schema.mssql.ts +94 -0
  166. package/src/lib/db/schema.pg.ts +95 -0
  167. package/src/lib/factory.ts +127 -0
  168. package/src/lib/graph/index.ts +19 -0
  169. package/src/lib/graph/resolver.ts +387 -0
  170. package/src/{index.ts → lib/index.ts} +13 -5
  171. package/src/lib/redis.ts +44 -0
  172. package/src/lib/routes/chat.ts +115 -0
  173. package/src/lib/routes/files.ts +129 -0
  174. package/src/lib/routes/owned-thread.ts +17 -0
  175. package/src/{routes → lib/routes}/threads.ts +22 -31
  176. package/src/{routes → lib/routes}/ws.ts +9 -3
  177. package/src/lib/types.ts +76 -0
  178. package/src/{ws → lib/ws}/connections.ts +9 -1
  179. package/tsconfig.json +48 -0
  180. package/dist/src/adapters/database.d.ts +0 -30
  181. package/dist/src/adapters/mssql.d.ts +0 -3
  182. package/dist/src/ai/active-streams.d.ts +0 -14
  183. package/dist/src/ai/context/compressor.d.ts +0 -7
  184. package/dist/src/ai/context/index.d.ts +0 -15
  185. package/dist/src/ai/context/summarizer.d.ts +0 -5
  186. package/dist/src/ai/helpers.d.ts +0 -5
  187. package/dist/src/ai/index.d.ts +0 -4
  188. package/dist/src/ai/interceptors/request-interceptor.d.ts +0 -12
  189. package/dist/src/ai/tools/call-endpoint.tool.d.ts +0 -7
  190. package/dist/src/ai/tools/capture-files.tool.d.ts +0 -6
  191. package/dist/src/ai/tools/execute-code.tool.d.ts +0 -4
  192. package/dist/src/ai/tools/query-graph.tool.d.ts +0 -5
  193. package/dist/src/cli/extract-endpoints.d.ts +0 -6
  194. package/dist/src/config.d.ts +0 -165
  195. package/dist/src/db/migrate.d.ts +0 -1
  196. package/dist/src/graph/expand-domains.d.ts +0 -2
  197. package/dist/src/graph/generate-cypher.d.ts +0 -22
  198. package/dist/src/graph/index.d.ts +0 -11
  199. package/dist/src/graph/seed.d.ts +0 -19
  200. package/dist/src/graph/validate.d.ts +0 -2
  201. package/dist/src/routes/index.d.ts +0 -4
  202. package/dist/src/types.d.ts +0 -74
  203. package/dist/src/ws/events.d.ts +0 -39
  204. package/dist/src/ws/index.d.ts +0 -3
  205. package/dist/src/ws/notify.d.ts +0 -2
  206. package/src/adapters/database.ts +0 -29
  207. package/src/adapters/mssql.ts +0 -195
  208. package/src/ai/active-streams.ts +0 -123
  209. package/src/ai/context/compressor.ts +0 -47
  210. package/src/ai/context/index.ts +0 -75
  211. package/src/ai/context/summarizer.ts +0 -50
  212. package/src/ai/context/token-estimator.ts +0 -60
  213. package/src/ai/helpers.ts +0 -32
  214. package/src/ai/index.ts +0 -277
  215. package/src/ai/interceptors/request-interceptor.ts +0 -61
  216. package/src/ai/prompt.ts +0 -126
  217. package/src/ai/tools/call-endpoint.tool.ts +0 -89
  218. package/src/ai/tools/capture-files.tool.ts +0 -20
  219. package/src/ai/tools/execute-code.tool.ts +0 -153
  220. package/src/cli/extract-endpoints.ts +0 -550
  221. package/src/config.ts +0 -182
  222. package/src/db/migrate.ts +0 -21
  223. package/src/db/migrations/20260315000000_add_context_meta/migration.sql +0 -1
  224. package/src/db/schema.ts +0 -70
  225. package/src/factory.ts +0 -171
  226. package/src/graph/expand-domains.ts +0 -276
  227. package/src/graph/generate-cypher.ts +0 -192
  228. package/src/graph/index.ts +0 -47
  229. package/src/graph/resolver.ts +0 -357
  230. package/src/graph/seed.ts +0 -162
  231. package/src/graph/validate.ts +0 -78
  232. package/src/routes/chat.ts +0 -86
  233. package/src/routes/files.ts +0 -100
  234. package/src/routes/index.ts +0 -4
  235. package/src/types.ts +0 -74
  236. package/src/ws/events.ts +0 -39
  237. package/src/ws/index.ts +0 -11
  238. package/src/ws/notify.ts +0 -9
  239. /package/dist/src/{auth → lib/auth}/middleware.d.ts +0 -0
@@ -0,0 +1,183 @@
1
+ import type { ControlCenterConfig } from "../config";
2
+ import type { ExecuteRequest, ResolveRequest, SearchRequest } from "./types";
3
+ type ControlCenterFetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
4
+ export type ExecuteOptions = {
5
+ readOnly: boolean;
6
+ endUserToken?: string;
7
+ threadId: string;
8
+ turnKey: string;
9
+ stepIndex: number;
10
+ callIndex: number;
11
+ timeoutMs?: number;
12
+ abortSignal?: AbortSignal;
13
+ };
14
+ export declare class ControlCenterClient {
15
+ readonly url: string;
16
+ readonly cacheKey: string;
17
+ private readonly apiKey;
18
+ private readonly fetcher;
19
+ constructor(config: ControlCenterConfig, fetcher?: ControlCenterFetch);
20
+ getConfig(agentId: string, etag?: string, abortSignal?: AbortSignal): Promise<{
21
+ readonly status: "not-modified";
22
+ readonly config?: undefined;
23
+ readonly etag?: undefined;
24
+ } | {
25
+ readonly status: "not-found";
26
+ readonly config?: undefined;
27
+ readonly etag?: undefined;
28
+ } | {
29
+ readonly status: "modified";
30
+ readonly config: {
31
+ agentId: string;
32
+ systemPrompt: string;
33
+ promptVariables: ("userName" | "channel" | "locale")[];
34
+ catalogBlurb: string;
35
+ defaultLocale: "en" | "ar";
36
+ metaTools: {
37
+ searchKnowledge: boolean;
38
+ searchTools: boolean;
39
+ searchServices: boolean;
40
+ };
41
+ limits: {
42
+ resolveTokenBudget: number;
43
+ executeTimeoutMs: number;
44
+ maxResponseBytes: number;
45
+ };
46
+ catalogVersion: string;
47
+ publishedAt: string;
48
+ };
49
+ readonly etag: string | null;
50
+ } | null>;
51
+ resolve(agentId: string, request: ResolveRequest, abortSignal?: AbortSignal): Promise<{
52
+ resolveId: string;
53
+ catalogVersion: string;
54
+ locale: "en" | "ar";
55
+ knowledge: {
56
+ chunkId: string;
57
+ text: string;
58
+ score: number;
59
+ citation: {
60
+ documentId: string;
61
+ documentTitle: string;
62
+ page: number | null;
63
+ section: string | null;
64
+ uri: string | null;
65
+ service: string | null;
66
+ };
67
+ }[];
68
+ tools: {
69
+ toolId: string;
70
+ name: string;
71
+ version: number;
72
+ readOnly: boolean;
73
+ tags: string[];
74
+ signature: string;
75
+ score: number | null;
76
+ pinned: boolean;
77
+ }[];
78
+ services: {
79
+ serviceId: string;
80
+ key: string;
81
+ name: string;
82
+ card: string;
83
+ score: number;
84
+ }[];
85
+ sharedShapes: {
86
+ ref: string;
87
+ shape: string;
88
+ }[];
89
+ budget: {
90
+ requested: number;
91
+ used: number;
92
+ truncated: boolean;
93
+ };
94
+ } | null>;
95
+ searchTools(agentId: string, request: SearchRequest, abortSignal?: AbortSignal): Promise<{
96
+ catalogVersion: string;
97
+ tools: {
98
+ toolId: string;
99
+ name: string;
100
+ version: number;
101
+ readOnly: boolean;
102
+ tags: string[];
103
+ signature: string;
104
+ score: number | null;
105
+ pinned: boolean;
106
+ }[];
107
+ sharedShapes: {
108
+ ref: string;
109
+ shape: string;
110
+ }[];
111
+ } | null>;
112
+ searchServices(agentId: string, request: SearchRequest, abortSignal?: AbortSignal): Promise<{
113
+ catalogVersion: string;
114
+ services: {
115
+ serviceId: string;
116
+ key: string;
117
+ name: string;
118
+ card: string;
119
+ score: number;
120
+ }[];
121
+ tools: {
122
+ toolId: string;
123
+ name: string;
124
+ version: number;
125
+ readOnly: boolean;
126
+ tags: string[];
127
+ signature: string;
128
+ score: number | null;
129
+ pinned: boolean;
130
+ }[];
131
+ sharedShapes: {
132
+ ref: string;
133
+ shape: string;
134
+ }[];
135
+ } | null>;
136
+ searchKnowledge(agentId: string, request: SearchRequest, abortSignal?: AbortSignal): Promise<{
137
+ catalogVersion: string;
138
+ knowledge: {
139
+ chunkId: string;
140
+ text: string;
141
+ score: number;
142
+ citation: {
143
+ documentId: string;
144
+ documentTitle: string;
145
+ page: number | null;
146
+ section: string | null;
147
+ uri: string | null;
148
+ service: string | null;
149
+ };
150
+ }[];
151
+ } | null>;
152
+ execute(agentId: string, toolId: string, request: ExecuteRequest, options: ExecuteOptions): Promise<{
153
+ error: {
154
+ kind: "timeout" | "upstream_4xx" | "upstream_5xx" | "schema_mismatch" | "rate_limited" | "not_found" | "unauthorized" | "invalid_request" | "egress_blocked" | "internal";
155
+ detail: string;
156
+ retryable: boolean;
157
+ retryAfterSeconds?: number | undefined;
158
+ upstreamStatus?: number | undefined;
159
+ };
160
+ } | {
161
+ toolId: string;
162
+ name: string;
163
+ version: number;
164
+ output: unknown;
165
+ meta: {
166
+ upstreamStatus: number;
167
+ durationMs: number;
168
+ replayed: boolean;
169
+ truncated: boolean;
170
+ truncatedPaths: string[];
171
+ drift: {
172
+ path: string;
173
+ kind: "missing" | "unexpected" | "type_mismatch";
174
+ }[];
175
+ };
176
+ } | null>;
177
+ private agentPath;
178
+ private post;
179
+ private postResponse;
180
+ private request;
181
+ private parse;
182
+ }
183
+ export {};
@@ -0,0 +1,20 @@
1
+ import type { ControlCenterClient } from "./client";
2
+ export declare function getControlCenterConfig(cc: ControlCenterClient, agentId: string, abortSignal?: AbortSignal): Promise<{
3
+ agentId: string;
4
+ systemPrompt: string;
5
+ promptVariables: ("userName" | "channel" | "locale")[];
6
+ catalogBlurb: string;
7
+ defaultLocale: "en" | "ar";
8
+ metaTools: {
9
+ searchKnowledge: boolean;
10
+ searchTools: boolean;
11
+ searchServices: boolean;
12
+ };
13
+ limits: {
14
+ resolveTokenBudget: number;
15
+ executeTimeoutMs: number;
16
+ maxResponseBytes: number;
17
+ };
18
+ catalogVersion: string;
19
+ publishedAt: string;
20
+ } | null>;
@@ -0,0 +1,23 @@
1
+ import type { ResolveResponse, RuntimeAgentConfig } from "./types";
2
+ type SharedShape = ResolveResponse["sharedShapes"][number];
3
+ type ToolSignature = ResolveResponse["tools"][number];
4
+ type ServiceCard = ResolveResponse["services"][number];
5
+ type KnowledgeChunk = ResolveResponse["knowledge"][number];
6
+ /** Values for the published prompt's `{{variable}}` placeholders, read from session/request context. */
7
+ export declare function buildPromptVariables(promptVariables: RuntimeAgentConfig["promptVariables"], sources: Record<string, unknown>): Record<string, string>;
8
+ export declare function formatSharedShapes(shapes: SharedShape[]): string;
9
+ export declare function formatToolSignatures(tools: ToolSignature[]): string;
10
+ export declare function formatServiceCards(services: ServiceCard[]): string;
11
+ export declare function formatKnowledgeChunks(chunks: KnowledgeChunk[]): string;
12
+ export type CcPromptInput = {
13
+ config: RuntimeAgentConfig;
14
+ resolved: ResolveResponse | null;
15
+ variables: Record<string, string>;
16
+ };
17
+ /**
18
+ * Dumb concatenator by contract: `signature`, `card`, and `shape` arrive
19
+ * pre-rendered from Control Center and are injected verbatim — never
20
+ * re-rendered from structured fields.
21
+ */
22
+ export declare function buildCcSection(cc: CcPromptInput): string;
23
+ export {};
@@ -0,0 +1,34 @@
1
+ import type { ControlCenterClient } from "./client";
2
+ import type { RuntimeAgentConfig } from "./types";
3
+ export type CcToolBinding = {
4
+ toolId: string;
5
+ readOnly: boolean;
6
+ };
7
+ /**
8
+ * Turn-scoped and mutable: seeded from /resolve, extended by searchTools
9
+ * mid-turn so a tool discovered at step 3 is callable at step 4.
10
+ */
11
+ export type CcToolRegistry = Map<string, CcToolBinding>;
12
+ export declare function registerCcTools(registry: CcToolRegistry, tools: {
13
+ name: string;
14
+ toolId: string;
15
+ readOnly: boolean;
16
+ }[]): void;
17
+ export declare function recordRecentCcTool(threadId: string, name: string): void;
18
+ export declare function getRecentCcTools(threadId: string): string[];
19
+ /** Everything a CC-aware tool needs for one turn. */
20
+ export type CcRuntime = {
21
+ client: ControlCenterClient;
22
+ agentId: string;
23
+ config: RuntimeAgentConfig;
24
+ registry: CcToolRegistry;
25
+ threadId: string;
26
+ turnKey: string;
27
+ userId: string;
28
+ locale: RuntimeAgentConfig["defaultLocale"];
29
+ endUserToken: string;
30
+ abortSignal?: AbortSignal;
31
+ getStepIndex: () => number;
32
+ nextCallIndex: (stepIndex: number) => number;
33
+ onToolProgress?: (toolName: string, toolCallId: string, status: "started" | "finished") => void;
34
+ };
@@ -0,0 +1,27 @@
1
+ import z from "zod";
2
+ export { AGENT_SLUG_PATTERN, executeResponseSchema, resolveResponseSchema, runtimeAgentConfigSchema, searchKnowledgeResponseSchema, searchServicesResponseSchema, searchToolsResponseSchema, type ExecuteRequest, type ResolveRequest, type ResolveResponse, type RuntimeAgentConfig, type SearchRequest, } from "../../../contracts/runtime";
3
+ /**
4
+ * The contract's error envelope, hardened for this consumer: a newer runtime may
5
+ * answer with an error kind this build has never heard of, which must degrade to a
6
+ * generic non-retryable `internal` rather than fail the parse.
7
+ */
8
+ export declare const runtimeErrorSchema: z.ZodPreprocess<z.ZodObject<{
9
+ error: z.ZodObject<{
10
+ kind: z.ZodEnum<{
11
+ timeout: "timeout";
12
+ upstream_4xx: "upstream_4xx";
13
+ upstream_5xx: "upstream_5xx";
14
+ schema_mismatch: "schema_mismatch";
15
+ rate_limited: "rate_limited";
16
+ not_found: "not_found";
17
+ unauthorized: "unauthorized";
18
+ invalid_request: "invalid_request";
19
+ egress_blocked: "egress_blocked";
20
+ internal: "internal";
21
+ }>;
22
+ detail: z.ZodString;
23
+ retryable: z.ZodBoolean;
24
+ retryAfterSeconds: z.ZodOptional<z.ZodNumber>;
25
+ upstreamStatus: z.ZodOptional<z.ZodNumber>;
26
+ }, z.core.$strip>;
27
+ }, z.core.$strip>>;
@@ -0,0 +1,170 @@
1
+ import type { AnyServerTool } from "@tanstack/ai";
2
+ import type { DatabaseAdapter } from "./adapters/database/index";
3
+ import type { StorageAdapter } from "./adapters/storage/index";
4
+ import type { DomainDef } from "../../contracts/graph";
5
+ import type { RequestInterceptorOptions } from "./ai/interceptors/request-interceptor";
6
+ import type { ContextConfig } from "./ai/context/types";
7
+ import type { ChatMessage, Thread } from "./types";
8
+ /** An agent's tools, as `chat()` takes them. */
9
+ export type ToolSet = ReadonlyArray<AnyServerTool>;
10
+ type ModelConfig = {
11
+ baseURL: string;
12
+ apiKey: string;
13
+ modelName: string;
14
+ providerName?: string;
15
+ };
16
+ type EmbeddingConfig = {
17
+ baseURL: string;
18
+ apiKey: string;
19
+ modelName: string;
20
+ dimension: number;
21
+ };
22
+ type Neo4jConfig = {
23
+ url: string;
24
+ user: string;
25
+ password: string;
26
+ };
27
+ type RerankerConfig = {
28
+ url: string;
29
+ apiKey: string;
30
+ };
31
+ export type ControlCenterConfig = {
32
+ url: string;
33
+ apiKey: string;
34
+ };
35
+ export type KnowledgeConfig = {
36
+ swagger?: {
37
+ url: string;
38
+ };
39
+ domains?: Record<string, DomainDef>;
40
+ };
41
+ export type PromptContext<TSession extends Record<string, unknown> = Record<string, unknown>, TRequestContext extends Record<string, unknown> = Record<string, unknown>> = {
42
+ session: TSession | null;
43
+ requestContext: TRequestContext;
44
+ };
45
+ /**
46
+ * Per-request context handed to a tools factory. Allows tool implementations to
47
+ * close over the active thread, user, session, and request-level context without
48
+ * reaching for globals or AsyncLocalStorage.
49
+ */
50
+ export type ToolContext<TSession extends Record<string, unknown> = Record<string, unknown>, TRequestContext extends Record<string, unknown> = Record<string, unknown>> = {
51
+ thread: Thread;
52
+ userId: string;
53
+ token: string;
54
+ session: TSession | null;
55
+ requestContext: TRequestContext;
56
+ };
57
+ export type ToolSetFactory<TSession extends Record<string, unknown> = Record<string, unknown>, TRequestContext extends Record<string, unknown> = Record<string, unknown>> = (context: ToolContext<TSession, TRequestContext>) => ToolSet;
58
+ export type DatabaseConfig = {
59
+ type: "mssql" | "postgres";
60
+ connectionString: string;
61
+ };
62
+ /**
63
+ * Optional. With Redis, live runs survive a producer restart and reach every
64
+ * instance: the chunk log, the thread→run claims, and abort fan-out all move
65
+ * there. Without it, an in-memory fallback covers a single process.
66
+ */
67
+ export type RedisConfig = {
68
+ url: string;
69
+ /** How long a finished run's stream log stays replayable. Defaults to 24 h. */
70
+ streamTtlSeconds?: number;
71
+ };
72
+ export type StorageConfig = {
73
+ endPoint: string;
74
+ port: number;
75
+ useSSL: boolean;
76
+ accessKey: string;
77
+ secretKey: string;
78
+ bucketName?: string;
79
+ };
80
+ type BackendFetchConfig = {
81
+ baseUrl: string;
82
+ apiKey: string;
83
+ headers?: Record<string, string>;
84
+ transformRequestBody?: (body: Record<string, unknown>, context: {
85
+ token: string;
86
+ }) => Promise<Record<string, unknown>>;
87
+ interceptor?: RequestInterceptorOptions;
88
+ };
89
+ /** Model and knowledge-graph providers. Declared once at server level; an agent may override any of them. */
90
+ type ProviderConfig = {
91
+ model: ModelConfig;
92
+ fastModel?: ModelConfig;
93
+ vision?: ModelConfig;
94
+ embedding?: EmbeddingConfig;
95
+ neo4j?: Neo4jConfig;
96
+ reranker?: RerankerConfig;
97
+ };
98
+ /**
99
+ * What an agent *does*, independent of where its providers came from. Shared
100
+ * verbatim by the authored definition and its resolved form — the two differ
101
+ * only in how providers and opt-outs are expressed, so everything else lives
102
+ * here and cannot drift between them.
103
+ */
104
+ type AgentBehavior<TSession extends Record<string, unknown>, TRequestContext extends Record<string, unknown>> = {
105
+ systemPrompt?: string | ((context: PromptContext<TSession, TRequestContext>) => string | Promise<string>);
106
+ tools?: ToolSet | ToolSetFactory<TSession, TRequestContext>;
107
+ backendFetch?: BackendFetchConfig;
108
+ loadSessionData?: (token: string) => Promise<TSession>;
109
+ resolveRequestContext?: (request: Request) => TRequestContext | Promise<TRequestContext>;
110
+ onToolCall?: (toolCall: {
111
+ toolName: string;
112
+ toolCallId: string;
113
+ args: Record<string, unknown>;
114
+ }) => void;
115
+ onStreamFinish?: (result: {
116
+ messages: ChatMessage[];
117
+ isAborted: boolean;
118
+ }) => void;
119
+ };
120
+ /**
121
+ * An agent as authored. Providers are optional because an unset one inherits
122
+ * from server level; `null` on knowledge means "opt out entirely" rather than
123
+ * "inherit". The Control Center is server-level only: which agents it backs is
124
+ * decided by publishing them there, not per entry here.
125
+ */
126
+ export type CortexAgentDefinition<TSession extends Record<string, unknown> = Record<string, unknown>, TRequestContext extends Record<string, unknown> = Record<string, unknown>> = AgentBehavior<TSession, TRequestContext> & Partial<ProviderConfig> & {
127
+ knowledge?: KnowledgeConfig | null;
128
+ context?: Partial<ContextConfig>;
129
+ };
130
+ /**
131
+ * An agent after the factory has merged it with server-level config. Every
132
+ * inherit-or-opt-out decision is already resolved, so nothing here is nullable
133
+ * and `model`/`context` are guaranteed present.
134
+ */
135
+ export type ResolvedCortexAgentConfig = AgentBehavior<Record<string, unknown>, Record<string, unknown>> & ProviderConfig & {
136
+ agentId: string;
137
+ db: DatabaseAdapter;
138
+ storage?: StorageAdapter;
139
+ controlCenter?: ControlCenterConfig;
140
+ knowledge?: KnowledgeConfig;
141
+ context: ContextConfig;
142
+ };
143
+ export type CortexConfig = ProviderConfig & {
144
+ port?: number;
145
+ database: DatabaseConfig;
146
+ storage?: StorageConfig;
147
+ redis?: RedisConfig;
148
+ auth?: {
149
+ jwksUri: string;
150
+ issuer: string;
151
+ tokenExtractor?: (req: Request) => string | null;
152
+ cookieName?: string;
153
+ };
154
+ controlCenter?: ControlCenterConfig;
155
+ context?: Partial<ContextConfig>;
156
+ knowledge?: KnowledgeConfig;
157
+ /**
158
+ * Locally-defined agents. With `controlCenter` set, agents published there
159
+ * are served automatically and need no entry here; an entry is only needed
160
+ * for local behavior (tools, backendFetch, provider overrides).
161
+ */
162
+ agents?: Record<string, CortexAgentDefinition>;
163
+ };
164
+ /**
165
+ * Helper to define an agent with full type inference for `systemPrompt` context.
166
+ * The `context.session` type is inferred from `loadSessionData`'s return type,
167
+ * and `context.requestContext` is inferred from `resolveRequestContext`'s return type.
168
+ */
169
+ export declare function defineAgent<TSession extends Record<string, unknown> = Record<string, unknown>, TRequestContext extends Record<string, unknown> = Record<string, unknown>>(config: CortexAgentDefinition<TSession, TRequestContext>): CortexAgentDefinition;
170
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const _default: import("drizzle-kit").Config;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("drizzle-kit").Config;
2
+ export default _default;
@@ -0,0 +1,7 @@
1
+ import type { DatabaseConfig } from "../config";
2
+ /**
3
+ * Each dialect keeps its own migration history — Postgres starts from a
4
+ * squashed initial migration rather than replaying MSSQL's. The driver imports
5
+ * are lazy so a server only loads the one it was configured for.
6
+ */
7
+ export declare function runMigrations(database: DatabaseConfig): Promise<void>;