@alpacakit/agents 0.1.0-beta.19

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 (249) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +224 -0
  3. package/dist/agents/builtin.d.ts +19 -0
  4. package/dist/agents/builtin.d.ts.map +1 -0
  5. package/dist/agents/builtin.js +14 -0
  6. package/dist/agents/claude.d.ts +20 -0
  7. package/dist/agents/claude.d.ts.map +1 -0
  8. package/dist/agents/claude.js +480 -0
  9. package/dist/agents/codex.d.ts +19 -0
  10. package/dist/agents/codex.d.ts.map +1 -0
  11. package/dist/agents/codex.js +355 -0
  12. package/dist/agents/openai-compatible/config.d.ts +16 -0
  13. package/dist/agents/openai-compatible/config.d.ts.map +1 -0
  14. package/dist/agents/openai-compatible/config.js +160 -0
  15. package/dist/agents/openai-compatible/engine.d.ts +18 -0
  16. package/dist/agents/openai-compatible/engine.d.ts.map +1 -0
  17. package/dist/agents/openai-compatible/engine.js +10 -0
  18. package/dist/agents/openai-compatible/fetch-engine.d.ts +38 -0
  19. package/dist/agents/openai-compatible/fetch-engine.d.ts.map +1 -0
  20. package/dist/agents/openai-compatible/fetch-engine.js +216 -0
  21. package/dist/agents/openai-compatible/pi/engine.d.ts +32 -0
  22. package/dist/agents/openai-compatible/pi/engine.d.ts.map +1 -0
  23. package/dist/agents/openai-compatible/pi/engine.js +98 -0
  24. package/dist/agents/openai-compatible/pi/module.d.ts +87 -0
  25. package/dist/agents/openai-compatible/pi/module.d.ts.map +1 -0
  26. package/dist/agents/openai-compatible/pi/module.js +43 -0
  27. package/dist/agents/openai-compatible/pi/sandbox.d.ts +25 -0
  28. package/dist/agents/openai-compatible/pi/sandbox.d.ts.map +1 -0
  29. package/dist/agents/openai-compatible/pi/sandbox.js +69 -0
  30. package/dist/agents/openai-compatible/pi/session.d.ts +17 -0
  31. package/dist/agents/openai-compatible/pi/session.d.ts.map +1 -0
  32. package/dist/agents/openai-compatible/pi/session.js +354 -0
  33. package/dist/agents/openai-compatible/response.d.ts +19 -0
  34. package/dist/agents/openai-compatible/response.d.ts.map +1 -0
  35. package/dist/agents/openai-compatible/response.js +203 -0
  36. package/dist/agents/openai-compatible/types.d.ts +34 -0
  37. package/dist/agents/openai-compatible/types.d.ts.map +1 -0
  38. package/dist/agents/openai-compatible/types.js +1 -0
  39. package/dist/agents/openai-compatible.d.ts +12 -0
  40. package/dist/agents/openai-compatible.d.ts.map +1 -0
  41. package/dist/agents/openai-compatible.js +45 -0
  42. package/dist/auth/login-probe.d.ts +21 -0
  43. package/dist/auth/login-probe.d.ts.map +1 -0
  44. package/dist/auth/login-probe.js +47 -0
  45. package/dist/auth/login.d.ts +79 -0
  46. package/dist/auth/login.d.ts.map +1 -0
  47. package/dist/auth/login.js +9 -0
  48. package/dist/auth/material.d.ts +87 -0
  49. package/dist/auth/material.d.ts.map +1 -0
  50. package/dist/auth/material.js +59 -0
  51. package/dist/auth/profile-store.d.ts +14 -0
  52. package/dist/auth/profile-store.d.ts.map +1 -0
  53. package/dist/auth/profile-store.js +101 -0
  54. package/dist/auth/secrets.d.ts +14 -0
  55. package/dist/auth/secrets.d.ts.map +1 -0
  56. package/dist/auth/secrets.js +40 -0
  57. package/dist/codex/app-server.d.ts +30 -0
  58. package/dist/codex/app-server.d.ts.map +1 -0
  59. package/dist/codex/app-server.js +322 -0
  60. package/dist/codex/index.d.ts +3 -0
  61. package/dist/codex/index.d.ts.map +1 -0
  62. package/dist/codex/index.js +1 -0
  63. package/dist/codex/protocol.d.ts +124 -0
  64. package/dist/codex/protocol.d.ts.map +1 -0
  65. package/dist/codex/protocol.js +283 -0
  66. package/dist/config/agent-config-validation.d.ts +22 -0
  67. package/dist/config/agent-config-validation.d.ts.map +1 -0
  68. package/dist/config/agent-config-validation.js +31 -0
  69. package/dist/config/agent-configs.d.ts +37 -0
  70. package/dist/config/agent-configs.d.ts.map +1 -0
  71. package/dist/config/agent-configs.js +214 -0
  72. package/dist/config/compose.d.ts +10 -0
  73. package/dist/config/compose.d.ts.map +1 -0
  74. package/dist/config/compose.js +89 -0
  75. package/dist/config/config.d.ts +21 -0
  76. package/dist/config/config.d.ts.map +1 -0
  77. package/dist/config/config.js +33 -0
  78. package/dist/config/errors.d.ts +45 -0
  79. package/dist/config/errors.d.ts.map +1 -0
  80. package/dist/config/errors.js +37 -0
  81. package/dist/config/extension.d.ts +3 -0
  82. package/dist/config/extension.d.ts.map +1 -0
  83. package/dist/config/extension.js +1 -0
  84. package/dist/config/ids.d.ts +8 -0
  85. package/dist/config/ids.d.ts.map +1 -0
  86. package/dist/config/ids.js +4 -0
  87. package/dist/config/index.d.ts +12 -0
  88. package/dist/config/index.d.ts.map +1 -0
  89. package/dist/config/index.js +6 -0
  90. package/dist/config/model.d.ts +105 -0
  91. package/dist/config/model.d.ts.map +1 -0
  92. package/dist/config/model.js +1 -0
  93. package/dist/config/paths.d.ts +7 -0
  94. package/dist/config/paths.d.ts.map +1 -0
  95. package/dist/config/paths.js +10 -0
  96. package/dist/config/schema.d.ts +59 -0
  97. package/dist/config/schema.d.ts.map +1 -0
  98. package/dist/config/schema.js +83 -0
  99. package/dist/config/store.d.ts +34 -0
  100. package/dist/config/store.d.ts.map +1 -0
  101. package/dist/config/store.js +420 -0
  102. package/dist/config/support.d.ts +14 -0
  103. package/dist/config/support.d.ts.map +1 -0
  104. package/dist/config/support.js +32 -0
  105. package/dist/config/values.d.ts +21 -0
  106. package/dist/config/values.d.ts.map +1 -0
  107. package/dist/config/values.js +22 -0
  108. package/dist/config/xdg.d.ts +20 -0
  109. package/dist/config/xdg.d.ts.map +1 -0
  110. package/dist/config/xdg.js +23 -0
  111. package/dist/core/async-queue.d.ts +14 -0
  112. package/dist/core/async-queue.d.ts.map +1 -0
  113. package/dist/core/async-queue.js +46 -0
  114. package/dist/core/env.d.ts +19 -0
  115. package/dist/core/env.d.ts.map +1 -0
  116. package/dist/core/env.js +39 -0
  117. package/dist/core/error.d.ts +121 -0
  118. package/dist/core/error.d.ts.map +1 -0
  119. package/dist/core/error.js +88 -0
  120. package/dist/core/fs.d.ts +16 -0
  121. package/dist/core/fs.d.ts.map +1 -0
  122. package/dist/core/fs.js +30 -0
  123. package/dist/core/json.d.ts +20 -0
  124. package/dist/core/json.d.ts.map +1 -0
  125. package/dist/core/json.js +42 -0
  126. package/dist/core/node-ports.d.ts +9 -0
  127. package/dist/core/node-ports.d.ts.map +1 -0
  128. package/dist/core/node-ports.js +135 -0
  129. package/dist/core/ports.d.ts +71 -0
  130. package/dist/core/ports.d.ts.map +1 -0
  131. package/dist/core/ports.js +19 -0
  132. package/dist/core/redact.d.ts +8 -0
  133. package/dist/core/redact.d.ts.map +1 -0
  134. package/dist/core/redact.js +66 -0
  135. package/dist/core/run.d.ts +125 -0
  136. package/dist/core/run.d.ts.map +1 -0
  137. package/dist/core/run.js +27 -0
  138. package/dist/core/values.d.ts +12 -0
  139. package/dist/core/values.d.ts.map +1 -0
  140. package/dist/core/values.js +9 -0
  141. package/dist/corpus/failure-corpus.d.ts +21 -0
  142. package/dist/corpus/failure-corpus.d.ts.map +1 -0
  143. package/dist/corpus/failure-corpus.js +89 -0
  144. package/dist/fleet/fleet.d.ts +120 -0
  145. package/dist/fleet/fleet.d.ts.map +1 -0
  146. package/dist/fleet/fleet.js +409 -0
  147. package/dist/fleet/policy.d.ts +45 -0
  148. package/dist/fleet/policy.d.ts.map +1 -0
  149. package/dist/fleet/policy.js +50 -0
  150. package/dist/fleet/store.d.ts +28 -0
  151. package/dist/fleet/store.d.ts.map +1 -0
  152. package/dist/fleet/store.js +225 -0
  153. package/dist/host/capabilities.d.ts +146 -0
  154. package/dist/host/capabilities.d.ts.map +1 -0
  155. package/dist/host/capabilities.js +59 -0
  156. package/dist/host/context.d.ts +29 -0
  157. package/dist/host/context.d.ts.map +1 -0
  158. package/dist/host/context.js +11 -0
  159. package/dist/host/github-dir.d.ts +16 -0
  160. package/dist/host/github-dir.d.ts.map +1 -0
  161. package/dist/host/github-dir.js +164 -0
  162. package/dist/host/mcp-list.d.ts +12 -0
  163. package/dist/host/mcp-list.d.ts.map +1 -0
  164. package/dist/host/mcp-list.js +122 -0
  165. package/dist/host/requirement-ref.d.ts +12 -0
  166. package/dist/host/requirement-ref.d.ts.map +1 -0
  167. package/dist/host/requirement-ref.js +40 -0
  168. package/dist/host/run-command.d.ts +27 -0
  169. package/dist/host/run-command.d.ts.map +1 -0
  170. package/dist/host/run-command.js +66 -0
  171. package/dist/host/validate-spec.d.ts +10 -0
  172. package/dist/host/validate-spec.d.ts.map +1 -0
  173. package/dist/host/validate-spec.js +69 -0
  174. package/dist/index.d.ts +69 -0
  175. package/dist/index.d.ts.map +1 -0
  176. package/dist/index.js +41 -0
  177. package/dist/kernel/classify.d.ts +44 -0
  178. package/dist/kernel/classify.d.ts.map +1 -0
  179. package/dist/kernel/classify.js +136 -0
  180. package/dist/kernel/cli-agent.d.ts +62 -0
  181. package/dist/kernel/cli-agent.d.ts.map +1 -0
  182. package/dist/kernel/cli-agent.js +281 -0
  183. package/dist/kernel/cli-login.d.ts +13 -0
  184. package/dist/kernel/cli-login.d.ts.map +1 -0
  185. package/dist/kernel/cli-login.js +199 -0
  186. package/dist/kernel/definition.d.ts +41 -0
  187. package/dist/kernel/definition.d.ts.map +1 -0
  188. package/dist/kernel/definition.js +13 -0
  189. package/dist/kernel/env-template.d.ts +17 -0
  190. package/dist/kernel/env-template.d.ts.map +1 -0
  191. package/dist/kernel/env-template.js +78 -0
  192. package/dist/kernel/facets.d.ts +58 -0
  193. package/dist/kernel/facets.d.ts.map +1 -0
  194. package/dist/kernel/facets.js +102 -0
  195. package/dist/kernel/guard.d.ts +24 -0
  196. package/dist/kernel/guard.d.ts.map +1 -0
  197. package/dist/kernel/guard.js +69 -0
  198. package/dist/kernel/handle.d.ts +29 -0
  199. package/dist/kernel/handle.d.ts.map +1 -0
  200. package/dist/kernel/handle.js +97 -0
  201. package/dist/kernel/keyed.d.ts +19 -0
  202. package/dist/kernel/keyed.d.ts.map +1 -0
  203. package/dist/kernel/keyed.js +35 -0
  204. package/dist/kernel/login.d.ts +20 -0
  205. package/dist/kernel/login.d.ts.map +1 -0
  206. package/dist/kernel/login.js +74 -0
  207. package/dist/kernel/options.d.ts +73 -0
  208. package/dist/kernel/options.d.ts.map +1 -0
  209. package/dist/kernel/options.js +41 -0
  210. package/dist/kernel/run.d.ts +20 -0
  211. package/dist/kernel/run.d.ts.map +1 -0
  212. package/dist/kernel/run.js +245 -0
  213. package/dist/kernel/runtime.d.ts +48 -0
  214. package/dist/kernel/runtime.d.ts.map +1 -0
  215. package/dist/kernel/runtime.js +108 -0
  216. package/dist/keyring/index.d.ts +2 -0
  217. package/dist/keyring/index.d.ts.map +1 -0
  218. package/dist/keyring/index.js +1 -0
  219. package/dist/keyring/resolver.d.ts +9 -0
  220. package/dist/keyring/resolver.d.ts.map +1 -0
  221. package/dist/keyring/resolver.js +62 -0
  222. package/dist/run-agent.d.ts +19 -0
  223. package/dist/run-agent.d.ts.map +1 -0
  224. package/dist/run-agent.js +25 -0
  225. package/dist/structured/extract.d.ts +27 -0
  226. package/dist/structured/extract.d.ts.map +1 -0
  227. package/dist/structured/extract.js +188 -0
  228. package/dist/structured/run-structured.d.ts +83 -0
  229. package/dist/structured/run-structured.d.ts.map +1 -0
  230. package/dist/structured/run-structured.js +202 -0
  231. package/dist/structured/standard-schema.d.ts +34 -0
  232. package/dist/structured/standard-schema.d.ts.map +1 -0
  233. package/dist/structured/standard-schema.js +6 -0
  234. package/dist/testing/fake-agent.d.ts +32 -0
  235. package/dist/testing/fake-agent.d.ts.map +1 -0
  236. package/dist/testing/fake-agent.js +43 -0
  237. package/dist/testing/fake-clock.d.ts +8 -0
  238. package/dist/testing/fake-clock.d.ts.map +1 -0
  239. package/dist/testing/fake-clock.js +44 -0
  240. package/dist/testing/fake-exec.d.ts +26 -0
  241. package/dist/testing/fake-exec.d.ts.map +1 -0
  242. package/dist/testing/fake-exec.js +69 -0
  243. package/dist/testing/fake-secrets.d.ts +3 -0
  244. package/dist/testing/fake-secrets.d.ts.map +1 -0
  245. package/dist/testing/fake-secrets.js +5 -0
  246. package/dist/testing/index.d.ts +10 -0
  247. package/dist/testing/index.d.ts.map +1 -0
  248. package/dist/testing/index.js +9 -0
  249. package/package.json +75 -0
@@ -0,0 +1,283 @@
1
+ /**
2
+ * The app-server method registry: adding a method adds a row in
3
+ * `CodexAppServerMethods` plus its decoder row in
4
+ * `CODEX_APP_SERVER_RESULT_DECODERS`. Result rows are RESOLVED shapes
5
+ * (rule 2): meaningful absence is `null` / empty collection, never `?`.
6
+ * The decoders normalize the foreign JSON-RPC payload at the boundary
7
+ * (rule 1) — strict on the fields consumers depend on, normalizing on
8
+ * fields the server may omit — so a malformed server response becomes a
9
+ * typed failure in the client instead of a TypeError in a caller.
10
+ */
11
+ import { readArray, readBoolean, readString, readUnknownRecord, } from "../core/json.js";
12
+ export const CODEX_APP_SERVER_METHOD = {
13
+ initialize: "initialize",
14
+ initialized: "initialized",
15
+ pluginList: "plugin/list",
16
+ pluginInstall: "plugin/install",
17
+ skillsList: "skills/list",
18
+ mcpServerStatusList: "mcpServerStatus/list",
19
+ };
20
+ export const CODEX_MCP_STATUS_DETAIL = {
21
+ toolsAndAuthOnly: "toolsAndAuthOnly",
22
+ };
23
+ const RESULT_FIELD = {
24
+ alreadyInstalled: "alreadyInstalled",
25
+ appsNeedingAuth: "appsNeedingAuth",
26
+ authPolicy: "authPolicy",
27
+ authStatus: "authStatus",
28
+ capabilities: "capabilities",
29
+ cwd: "cwd",
30
+ data: "data",
31
+ description: "description",
32
+ displayName: "displayName",
33
+ enabled: "enabled",
34
+ errors: "errors",
35
+ id: "id",
36
+ installPolicy: "installPolicy",
37
+ installed: "installed",
38
+ interface: "interface",
39
+ location: "location",
40
+ longDescription: "longDescription",
41
+ marketplaceLoadErrors: "marketplaceLoadErrors",
42
+ marketplacePath: "marketplacePath",
43
+ marketplaces: "marketplaces",
44
+ message: "message",
45
+ name: "name",
46
+ nextCursor: "nextCursor",
47
+ path: "path",
48
+ plugins: "plugins",
49
+ scope: "scope",
50
+ shortDescription: "shortDescription",
51
+ skills: "skills",
52
+ status: "status",
53
+ tools: "tools",
54
+ };
55
+ export const CODEX_APP_SERVER_RESULT_DECODERS = {
56
+ [CODEX_APP_SERVER_METHOD.pluginList]: decodePluginListResult,
57
+ [CODEX_APP_SERVER_METHOD.pluginInstall]: decodePluginInstallResult,
58
+ [CODEX_APP_SERVER_METHOD.skillsList]: decodeSkillListResult,
59
+ [CODEX_APP_SERVER_METHOD.mcpServerStatusList]: decodeMcpServerStatusPage,
60
+ };
61
+ function decodeItems(values, decodeItem) {
62
+ const items = [];
63
+ for (const value of values) {
64
+ const item = decodeItem(value);
65
+ if (item === null) {
66
+ return null;
67
+ }
68
+ items.push(item);
69
+ }
70
+ return items;
71
+ }
72
+ function decodePluginListResult(value) {
73
+ const record = readUnknownRecord(value);
74
+ if (record === null) {
75
+ return null;
76
+ }
77
+ const marketplaceValues = readArray(record, RESULT_FIELD.marketplaces);
78
+ if (marketplaceValues === null) {
79
+ return null;
80
+ }
81
+ const marketplaces = decodeItems(marketplaceValues, decodePluginMarketplace);
82
+ const loadErrors = decodeItems(readArray(record, RESULT_FIELD.marketplaceLoadErrors) ?? [], decodeMarketplaceLoadError);
83
+ if (marketplaces === null || loadErrors === null) {
84
+ return null;
85
+ }
86
+ return { marketplaces, marketplaceLoadErrors: loadErrors };
87
+ }
88
+ function decodePluginMarketplace(value) {
89
+ const record = readUnknownRecord(value);
90
+ if (record === null) {
91
+ return null;
92
+ }
93
+ const name = readString(record, RESULT_FIELD.name);
94
+ const pluginValues = readArray(record, RESULT_FIELD.plugins);
95
+ if (name === null || pluginValues === null) {
96
+ return null;
97
+ }
98
+ const plugins = decodeItems(pluginValues, decodePluginSummary);
99
+ if (plugins === null) {
100
+ return null;
101
+ }
102
+ return { name, path: readString(record, RESULT_FIELD.path), plugins };
103
+ }
104
+ function decodePluginSummary(value) {
105
+ const record = readUnknownRecord(value);
106
+ if (record === null) {
107
+ return null;
108
+ }
109
+ const id = readString(record, RESULT_FIELD.id);
110
+ const name = readString(record, RESULT_FIELD.name);
111
+ const installed = readBoolean(record, RESULT_FIELD.installed);
112
+ const enabled = readBoolean(record, RESULT_FIELD.enabled);
113
+ const installPolicy = readString(record, RESULT_FIELD.installPolicy);
114
+ if (id === null ||
115
+ name === null ||
116
+ installed === null ||
117
+ enabled === null ||
118
+ installPolicy === null) {
119
+ return null;
120
+ }
121
+ return {
122
+ id,
123
+ name,
124
+ installed,
125
+ enabled,
126
+ installPolicy,
127
+ interface: decodePluginInterface(record[RESULT_FIELD.interface]),
128
+ };
129
+ }
130
+ /** Absent / malformed interface metadata is `null`, never a decode failure. */
131
+ function decodePluginInterface(value) {
132
+ const record = readUnknownRecord(value);
133
+ if (record === null) {
134
+ return null;
135
+ }
136
+ const capabilities = (readArray(record, RESULT_FIELD.capabilities) ?? []).filter((capability) => typeof capability === "string");
137
+ return {
138
+ displayName: readString(record, RESULT_FIELD.displayName),
139
+ shortDescription: readString(record, RESULT_FIELD.shortDescription),
140
+ longDescription: readString(record, RESULT_FIELD.longDescription),
141
+ capabilities,
142
+ };
143
+ }
144
+ function decodeMarketplaceLoadError(value) {
145
+ const record = readUnknownRecord(value);
146
+ if (record === null) {
147
+ return null;
148
+ }
149
+ const marketplacePath = readString(record, RESULT_FIELD.marketplacePath);
150
+ const message = readString(record, RESULT_FIELD.message);
151
+ if (marketplacePath === null || message === null) {
152
+ return null;
153
+ }
154
+ return { marketplacePath, message };
155
+ }
156
+ function decodePluginInstallResult(value) {
157
+ const record = readUnknownRecord(value);
158
+ if (record === null) {
159
+ return null;
160
+ }
161
+ const status = readString(record, RESULT_FIELD.status);
162
+ const alreadyInstalled = readBoolean(record, RESULT_FIELD.alreadyInstalled);
163
+ const appsNeedingAuth = readArray(record, RESULT_FIELD.appsNeedingAuth);
164
+ const authPolicy = readString(record, RESULT_FIELD.authPolicy);
165
+ const hasAuthResult = appsNeedingAuth !== null && authPolicy !== null;
166
+ const hasExplicitInstallResult = status !== null || alreadyInstalled !== null;
167
+ if (!hasAuthResult && !hasExplicitInstallResult) {
168
+ return null;
169
+ }
170
+ return {
171
+ status,
172
+ alreadyInstalled,
173
+ appsNeedingAuth: appsNeedingAuth ?? [],
174
+ authPolicy,
175
+ location: readString(record, RESULT_FIELD.location),
176
+ };
177
+ }
178
+ function decodeSkillListResult(value) {
179
+ const record = readUnknownRecord(value);
180
+ if (record === null) {
181
+ return null;
182
+ }
183
+ const entryValues = readArray(record, RESULT_FIELD.data);
184
+ if (entryValues === null) {
185
+ return null;
186
+ }
187
+ const data = decodeItems(entryValues, decodeSkillListEntry);
188
+ return data === null ? null : { data };
189
+ }
190
+ function decodeSkillListEntry(value) {
191
+ const record = readUnknownRecord(value);
192
+ if (record === null) {
193
+ return null;
194
+ }
195
+ const cwd = readString(record, RESULT_FIELD.cwd);
196
+ const skillValues = readArray(record, RESULT_FIELD.skills);
197
+ if (cwd === null || skillValues === null) {
198
+ return null;
199
+ }
200
+ const skills = decodeItems(skillValues, decodeSkillSummary);
201
+ const errors = decodeItems(readArray(record, RESULT_FIELD.errors) ?? [], decodeSkillListEntryError);
202
+ if (skills === null || errors === null) {
203
+ return null;
204
+ }
205
+ return { cwd, skills, errors };
206
+ }
207
+ function decodeSkillSummary(value) {
208
+ const record = readUnknownRecord(value);
209
+ if (record === null) {
210
+ return null;
211
+ }
212
+ const name = readString(record, RESULT_FIELD.name);
213
+ const description = readString(record, RESULT_FIELD.description);
214
+ const enabled = readBoolean(record, RESULT_FIELD.enabled);
215
+ const path = readString(record, RESULT_FIELD.path);
216
+ const scope = readString(record, RESULT_FIELD.scope);
217
+ if (name === null ||
218
+ description === null ||
219
+ enabled === null ||
220
+ path === null ||
221
+ scope === null) {
222
+ return null;
223
+ }
224
+ return { name, description, enabled, path, scope };
225
+ }
226
+ function decodeSkillListEntryError(value) {
227
+ const record = readUnknownRecord(value);
228
+ if (record === null) {
229
+ return null;
230
+ }
231
+ const path = readString(record, RESULT_FIELD.path);
232
+ const message = readString(record, RESULT_FIELD.message);
233
+ if (path === null || message === null) {
234
+ return null;
235
+ }
236
+ return { path, message };
237
+ }
238
+ function decodeMcpServerStatusPage(value) {
239
+ const record = readUnknownRecord(value);
240
+ if (record === null) {
241
+ return null;
242
+ }
243
+ const statusValues = readArray(record, RESULT_FIELD.data);
244
+ if (statusValues === null) {
245
+ return null;
246
+ }
247
+ const data = decodeItems(statusValues, decodeMcpServerStatus);
248
+ if (data === null) {
249
+ return null;
250
+ }
251
+ return { data, nextCursor: readString(record, RESULT_FIELD.nextCursor) };
252
+ }
253
+ function decodeMcpServerStatus(value) {
254
+ const record = readUnknownRecord(value);
255
+ if (record === null) {
256
+ return null;
257
+ }
258
+ const name = readString(record, RESULT_FIELD.name);
259
+ const authStatus = readString(record, RESULT_FIELD.authStatus);
260
+ if (name === null || authStatus === null) {
261
+ return null;
262
+ }
263
+ return {
264
+ name,
265
+ authStatus,
266
+ tools: decodeMcpTools(record[RESULT_FIELD.tools]),
267
+ };
268
+ }
269
+ /** A server that omits tool enumeration decodes to `null`, not `{}`. */
270
+ function decodeMcpTools(value) {
271
+ const record = readUnknownRecord(value);
272
+ if (record === null) {
273
+ return null;
274
+ }
275
+ const tools = {};
276
+ for (const [key, tool] of Object.entries(record)) {
277
+ const toolRecord = readUnknownRecord(tool);
278
+ tools[key] = {
279
+ name: toolRecord === null ? null : readString(toolRecord, RESULT_FIELD.name),
280
+ };
281
+ }
282
+ return tools;
283
+ }
@@ -0,0 +1,22 @@
1
+ import { type JsonObject } from "@alpacakit/core";
2
+ import type { AgentConfigKind } from "./ids.js";
3
+ import type { AgentConfigType, AgentConfig, AgentConfigTypeRegistry } from "./model.js";
4
+ export declare const AGENT_CONFIG_VALIDATION_RESULT: {
5
+ readonly valid: "valid";
6
+ readonly unknownKind: "unknown_kind";
7
+ readonly invalidPayload: "invalid_payload";
8
+ };
9
+ export type AgentConfigValidationResult = {
10
+ readonly kind: typeof AGENT_CONFIG_VALIDATION_RESULT.valid;
11
+ readonly definition: AgentConfigType<AgentConfigKind, JsonObject, string>;
12
+ readonly record: AgentConfig<AgentConfigKind, JsonObject>;
13
+ } | {
14
+ readonly kind: typeof AGENT_CONFIG_VALIDATION_RESULT.unknownKind;
15
+ readonly agentConfigKind: AgentConfigKind;
16
+ } | {
17
+ readonly kind: typeof AGENT_CONFIG_VALIDATION_RESULT.invalidPayload;
18
+ readonly agentConfigKind: AgentConfigKind;
19
+ readonly issues: readonly string[];
20
+ };
21
+ export declare function validateAgentConfig(record: AgentConfig<AgentConfigKind, JsonObject>, agentConfigTypes: AgentConfigTypeRegistry): AgentConfigValidationResult;
22
+ //# sourceMappingURL=agent-config-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-config-validation.d.ts","sourceRoot":"","sources":["../../src/config/agent-config-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,8BAA8B;;;;CAIjC,CAAC;AAEX,MAAM,MAAM,2BAA2B,GACnC;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,8BAA8B,CAAC,KAAK,CAAC;IAC3D,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC,eAAe,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IAC1E,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;CAC3D,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,8BAA8B,CAAC,WAAW,CAAC;IACjE,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;CAC3C,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,8BAA8B,CAAC,cAAc,CAAC;IACpE,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC,CAAC;AAEN,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,WAAW,CAAC,eAAe,EAAE,UAAU,CAAC,EAChD,gBAAgB,EAAE,uBAAuB,GACxC,2BAA2B,CA0B7B"}
@@ -0,0 +1,31 @@
1
+ import { CODEC_DECODE_RESULT_KIND } from "@alpacakit/core";
2
+ export const AGENT_CONFIG_VALIDATION_RESULT = {
3
+ valid: "valid",
4
+ unknownKind: "unknown_kind",
5
+ invalidPayload: "invalid_payload",
6
+ };
7
+ export function validateAgentConfig(record, agentConfigTypes) {
8
+ const definition = agentConfigTypes.get(record.kind);
9
+ if (definition === null) {
10
+ return {
11
+ kind: AGENT_CONFIG_VALIDATION_RESULT.unknownKind,
12
+ agentConfigKind: record.kind,
13
+ };
14
+ }
15
+ const decoded = definition.payloadCodec.decode(record.payload);
16
+ if (decoded.kind === CODEC_DECODE_RESULT_KIND.invalid) {
17
+ return {
18
+ kind: AGENT_CONFIG_VALIDATION_RESULT.invalidPayload,
19
+ agentConfigKind: definition.kind,
20
+ issues: decoded.issues,
21
+ };
22
+ }
23
+ return {
24
+ kind: AGENT_CONFIG_VALIDATION_RESULT.valid,
25
+ definition,
26
+ record: {
27
+ ...record,
28
+ payload: decoded.value,
29
+ },
30
+ };
31
+ }
@@ -0,0 +1,37 @@
1
+ import { type JsonObject } from "@alpacakit/core";
2
+ import { type AgentConfigKind } from "./ids.js";
3
+ import type { AgentConfig, AgentConfigType, AgentConfigTypeRegistry } from "./model.js";
4
+ import { AGENT_CONFIG_KIND } from "./values.js";
5
+ type BuiltinAgentConfigPayload = {
6
+ readonly model: string | null;
7
+ readonly effort: string | null;
8
+ };
9
+ type OpenAiCompatibleAgentConfigPayload = {
10
+ readonly baseUrl: string;
11
+ readonly model: string;
12
+ readonly apiKey: string | null;
13
+ readonly headers: Readonly<Record<string, string>>;
14
+ readonly requestParams: JsonObject;
15
+ };
16
+ export type BuiltinAgentConfigOptions = {
17
+ readonly id: string;
18
+ readonly enabled?: boolean;
19
+ readonly model?: string;
20
+ readonly effort?: string;
21
+ };
22
+ export type OpenAiCompatibleAgentConfigOptions = {
23
+ readonly id: string;
24
+ readonly enabled?: boolean;
25
+ readonly baseUrl: string;
26
+ readonly model: string;
27
+ readonly apiKey?: string;
28
+ readonly headers?: Readonly<Record<string, string>>;
29
+ readonly requestParams?: JsonObject;
30
+ };
31
+ export declare function codexAgentConfig(options: BuiltinAgentConfigOptions): AgentConfig<typeof AGENT_CONFIG_KIND.codex, BuiltinAgentConfigPayload>;
32
+ export declare function claudeAgentConfig(options: BuiltinAgentConfigOptions): AgentConfig<typeof AGENT_CONFIG_KIND.claude, BuiltinAgentConfigPayload>;
33
+ export declare function openAiCompatibleAgentConfig(options: OpenAiCompatibleAgentConfigOptions): AgentConfig<typeof AGENT_CONFIG_KIND.openaiCompatible, OpenAiCompatibleAgentConfigPayload>;
34
+ export declare function createDefaultAgentConfigTypeRegistry(): AgentConfigTypeRegistry;
35
+ export declare function defineAgentConfigType<Kind extends AgentConfigKind, Payload extends JsonObject, AgentId extends string>(definition: AgentConfigType<Kind, Payload, AgentId>): AgentConfigType<Kind, Payload, AgentId>;
36
+ export {};
37
+ //# sourceMappingURL=agent-configs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-configs.d.ts","sourceRoot":"","sources":["../../src/config/agent-configs.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,UAAU,EAEhB,MAAM,iBAAiB,CAAC;AAQzB,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,UAAU,CAAC;AAC/D,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EAGf,uBAAuB,EAGxB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,iBAAiB,EAGlB,MAAM,aAAa,CAAC;AAQrB,KAAK,yBAAyB,GAAG;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAOF,KAAK,kCAAkC,GAAG;IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,aAAa,CAAC,EAAE,UAAU,CAAC;CACrC,CAAC;AAiCF,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,yBAAyB,GACjC,WAAW,CAAC,OAAO,iBAAiB,CAAC,KAAK,EAAE,yBAAyB,CAAC,CAExE;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,yBAAyB,GACjC,WAAW,CAAC,OAAO,iBAAiB,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAEzE;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,kCAAkC,GAC1C,WAAW,CACZ,OAAO,iBAAiB,CAAC,gBAAgB,EACzC,kCAAkC,CACnC,CAaA;AA2CD,wBAAgB,oCAAoC,IAAI,uBAAuB,CAoB9E;AAED,wBAAgB,qBAAqB,CACnC,IAAI,SAAS,eAAe,EAC5B,OAAO,SAAS,UAAU,EAC1B,OAAO,SAAS,MAAM,EAEtB,UAAU,EAAE,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,GAClD,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAEzC"}
@@ -0,0 +1,214 @@
1
+ import { createKeyedRegistry, createSchemaRuntimeCodec, jsonValueSchema, } from "@alpacakit/core";
2
+ import { z } from "zod";
3
+ import { claude } from "../agents/claude.js";
4
+ import { codex } from "../agents/codex.js";
5
+ import { openaiCompatible } from "../agents/openai-compatible.js";
6
+ import { agentConfigId } from "./ids.js";
7
+ import { formatFieldPath, ZOD_ISSUE_CODE } from "./support.js";
8
+ import { AGENT_CONFIG_KIND, BUILTIN_AGENT_ID, CANDIDATE_SOURCE_KIND, } from "./values.js";
9
+ const ENV_TEMPLATE_EXPRESSION_START = "${";
10
+ const OPENAI_COMPATIBLE_PAYLOAD_FIELD = {
11
+ apiKey: "apiKey",
12
+ headers: "headers",
13
+ };
14
+ const OPENAI_COMPATIBLE_SECRET_FIELD = {
15
+ apiKey: {
16
+ label: OPENAI_COMPATIBLE_PAYLOAD_FIELD.apiKey,
17
+ path: [OPENAI_COMPATIBLE_PAYLOAD_FIELD.apiKey],
18
+ },
19
+ };
20
+ const OPENAI_COMPATIBLE_SECRET_HEADER = {
21
+ authorization: "authorization",
22
+ proxyAuthorization: "proxy-authorization",
23
+ apiKey: "api-key",
24
+ xApiKey: "x-api-key",
25
+ };
26
+ const AGENT_CONFIG_PAYLOAD_ERROR = {
27
+ directSecret: (label) => `${label} must use an environment template instead of a direct secret.`,
28
+ };
29
+ const secretHeaderNames = new Set(Object.values(OPENAI_COMPATIBLE_SECRET_HEADER));
30
+ export function codexAgentConfig(options) {
31
+ return builtinAgentConfigRecord(AGENT_CONFIG_KIND.codex, options);
32
+ }
33
+ export function claudeAgentConfig(options) {
34
+ return builtinAgentConfigRecord(AGENT_CONFIG_KIND.claude, options);
35
+ }
36
+ export function openAiCompatibleAgentConfig(options) {
37
+ return {
38
+ id: agentConfigId(options.id),
39
+ kind: AGENT_CONFIG_KIND.openaiCompatible,
40
+ enabled: options.enabled ?? true,
41
+ payload: {
42
+ baseUrl: options.baseUrl,
43
+ model: options.model,
44
+ apiKey: options.apiKey ?? null,
45
+ headers: options.headers ?? {},
46
+ requestParams: options.requestParams ?? {},
47
+ },
48
+ };
49
+ }
50
+ const builtinAgentConfigPayloadCodec = createSchemaRuntimeCodec(z
51
+ .object({
52
+ model: z.string().min(1).nullable(),
53
+ effort: z.string().min(1).nullable(),
54
+ })
55
+ .strict()
56
+ .readonly());
57
+ const openAiCompatibleAgentConfigPayloadCodec = createSchemaRuntimeCodec(z
58
+ .object({
59
+ baseUrl: z.string().min(1),
60
+ model: z.string().min(1),
61
+ apiKey: z.string().min(1).nullable(),
62
+ headers: z.record(z.string(), z.string().min(1)).readonly(),
63
+ requestParams: z.record(z.string(), jsonValueSchema).readonly(),
64
+ })
65
+ .strict()
66
+ .readonly()
67
+ .superRefine((payload, context) => {
68
+ rejectDirectSecretIfPresent(payload.apiKey, OPENAI_COMPATIBLE_SECRET_FIELD.apiKey, context);
69
+ for (const [name, value] of Object.entries(payload.headers)) {
70
+ if (secretHeaderNames.has(name.toLowerCase())) {
71
+ rejectDirectSecretIfPresent(value, headerSecretField(name), context);
72
+ }
73
+ }
74
+ }));
75
+ export function createDefaultAgentConfigTypeRegistry() {
76
+ return createKeyedRegistry([
77
+ createBuiltinAgentConfig({
78
+ kind: AGENT_CONFIG_KIND.codex,
79
+ agentId: BUILTIN_AGENT_ID.codex,
80
+ defineAgent: codex,
81
+ }),
82
+ createBuiltinAgentConfig({
83
+ kind: AGENT_CONFIG_KIND.claude,
84
+ agentId: BUILTIN_AGENT_ID.claude,
85
+ defineAgent: claude,
86
+ }),
87
+ createOpenAiCompatibleAgentConfig(),
88
+ ], (definition) => definition.kind);
89
+ }
90
+ export function defineAgentConfigType(definition) {
91
+ return definition;
92
+ }
93
+ function createBuiltinAgentConfig(input) {
94
+ return defineAgentConfigType({
95
+ kind: input.kind,
96
+ payloadCodec: builtinAgentConfigPayloadCodec,
97
+ project: (projectionInput) => projectBuiltinAgentConfig({
98
+ ...projectionInput,
99
+ agentId: input.agentId,
100
+ defineAgent: input.defineAgent,
101
+ }),
102
+ });
103
+ }
104
+ function projectBuiltinAgentConfig(input) {
105
+ const candidateDefaults = normalizeBuiltinCandidateDefaults(input.record.payload);
106
+ const matchingProfiles = input.profiles.filter((profile) => profile.agentId === input.agentId);
107
+ const candidates = matchingProfiles.map((profile) => profileCandidate(input.record, candidateDefaults, profile));
108
+ if (input.ambientBuiltinAuth) {
109
+ candidates.push(ambientCandidate(input.record, candidateDefaults, input.agentId));
110
+ }
111
+ return {
112
+ agents: [input.defineAgent()],
113
+ candidates,
114
+ };
115
+ }
116
+ function profileCandidate(record, candidateDefaults, profile) {
117
+ return {
118
+ candidate: withBuiltinDefaults({
119
+ agentId: profile.agentId,
120
+ profile,
121
+ }, candidateDefaults),
122
+ source: {
123
+ agentConfigId: record.id,
124
+ agentConfigKind: record.kind,
125
+ profileId: profile.id,
126
+ kind: CANDIDATE_SOURCE_KIND.profile,
127
+ },
128
+ };
129
+ }
130
+ function ambientCandidate(record, candidateDefaults, agentId) {
131
+ return {
132
+ candidate: withBuiltinDefaults({ agentId }, candidateDefaults),
133
+ source: {
134
+ agentConfigId: record.id,
135
+ agentConfigKind: record.kind,
136
+ profileId: null,
137
+ kind: CANDIDATE_SOURCE_KIND.ambient,
138
+ },
139
+ };
140
+ }
141
+ function withBuiltinDefaults(candidate, candidateDefaults) {
142
+ return {
143
+ ...candidate,
144
+ ...candidateDefaults,
145
+ };
146
+ }
147
+ function normalizeBuiltinCandidateDefaults(payload) {
148
+ return {
149
+ ...(payload.model === null ? {} : { model: payload.model }),
150
+ ...(payload.effort === null ? {} : { effort: payload.effort }),
151
+ };
152
+ }
153
+ function createOpenAiCompatibleAgentConfig() {
154
+ return defineAgentConfigType({
155
+ kind: AGENT_CONFIG_KIND.openaiCompatible,
156
+ payloadCodec: openAiCompatibleAgentConfigPayloadCodec,
157
+ project: (input) => {
158
+ const agentId = String(input.record.id);
159
+ const config = {
160
+ id: agentId,
161
+ baseUrl: input.record.payload.baseUrl,
162
+ model: input.record.payload.model,
163
+ apiKey: input.record.payload.apiKey,
164
+ headers: input.record.payload.headers,
165
+ requestParams: input.record.payload.requestParams,
166
+ };
167
+ return {
168
+ agents: [openaiCompatible(config)],
169
+ candidates: [
170
+ {
171
+ candidate: { agentId, model: input.record.payload.model },
172
+ source: {
173
+ agentConfigId: input.record.id,
174
+ agentConfigKind: input.record.kind,
175
+ profileId: null,
176
+ kind: CANDIDATE_SOURCE_KIND.configured,
177
+ },
178
+ },
179
+ ],
180
+ };
181
+ },
182
+ });
183
+ }
184
+ function rejectDirectSecretIfPresent(value, field, context) {
185
+ if (value === null) {
186
+ return;
187
+ }
188
+ if (value.includes(ENV_TEMPLATE_EXPRESSION_START)) {
189
+ return;
190
+ }
191
+ context.addIssue({
192
+ code: ZOD_ISSUE_CODE.custom,
193
+ path: [...field.path],
194
+ message: AGENT_CONFIG_PAYLOAD_ERROR.directSecret(field.label),
195
+ });
196
+ }
197
+ function headerSecretField(name) {
198
+ const path = [OPENAI_COMPATIBLE_PAYLOAD_FIELD.headers, name];
199
+ return {
200
+ label: formatFieldPath(path),
201
+ path,
202
+ };
203
+ }
204
+ function builtinAgentConfigRecord(kind, options) {
205
+ return {
206
+ id: agentConfigId(options.id),
207
+ kind,
208
+ enabled: options.enabled ?? true,
209
+ payload: {
210
+ model: options.model ?? null,
211
+ effort: options.effort ?? null,
212
+ },
213
+ };
214
+ }
@@ -0,0 +1,10 @@
1
+ import type { AgentConfigTypeRegistry, AgentsRuntimeConfig, ConfigData, NamedSecretResolver } from "./model.js";
2
+ type ComposeAgentsRuntimeConfigOptions = {
3
+ readonly data: ConfigData;
4
+ readonly fleetStateStore: AgentsRuntimeConfig["fleetStateStore"];
5
+ readonly agentConfigTypes: AgentConfigTypeRegistry;
6
+ readonly secretResolvers: readonly NamedSecretResolver[];
7
+ };
8
+ export declare function composeRuntimeConfig(input: ComposeAgentsRuntimeConfigOptions): AgentsRuntimeConfig;
9
+ export {};
10
+ //# sourceMappingURL=compose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/config/compose.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,uBAAuB,EACvB,mBAAmB,EACnB,UAAU,EAEV,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAwBpB,KAAK,iCAAiC,GAAG;IACvC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,eAAe,EAAE,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;IACjE,QAAQ,CAAC,gBAAgB,EAAE,uBAAuB,CAAC;IACnD,QAAQ,CAAC,eAAe,EAAE,SAAS,mBAAmB,EAAE,CAAC;CAC1D,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,iCAAiC,GACvC,mBAAmB,CA2CrB"}