Open History to see the last commit
1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3
4import { ProjectId, ThreadId, TrimmedNonEmptyString, TrimmedString } from "./baseSchemas.ts";
5import { ProviderOptionDescriptor } from "./model.ts";
6import { ProviderInstanceId } from "./providerInstance.ts";
7
8const AcpRegistryAgentId = TrimmedNonEmptyString.check(
9 Schema.isMaxLength(128),
10 Schema.isPattern(/^[a-z0-9][a-z0-9._-]*$/),
11);
12
13const ACP_REGISTRY_CDN_HOSTNAME = "cdn.agentclientprotocol.com";
14const ACP_REGISTRY_AGENT_ID_PATTERN = /^[a-z0-9][a-z0-9._-]*$/;
15
16export function officialAcpRegistryIconUrlForAgentId(
17 agentId: string | null | undefined,
18): string | null {
19 if (agentId === null || agentId === undefined || !ACP_REGISTRY_AGENT_ID_PATTERN.test(agentId)) {
20 return null;
21 }
22 return `https://${ACP_REGISTRY_CDN_HOSTNAME}/registry/v1/latest/${agentId}.svg`;
23}
24
25export function resolveOfficialAcpRegistryIconUrl(icon: string | null | undefined): string | null {
26 if (!icon) return null;
27 try {
28 const url = new URL(icon);
29 if (
30 url.protocol !== "https:" ||
31 url.hostname !== ACP_REGISTRY_CDN_HOSTNAME ||
32 url.port !== "" ||
33 url.username !== "" ||
34 url.password !== ""
35 ) {
36 return null;
37 }
38 return url.href;
39 } catch {
40 return null;
41 }
42}
43
44export const AcpRegistryDistribution = Schema.Literals(["binary", "npx", "uvx"]);
45export type AcpRegistryDistribution = typeof AcpRegistryDistribution.Type;
46
47export const AcpRegistryIntegrity = Schema.Literals(["sha256", "registry"]);
48export type AcpRegistryIntegrity = typeof AcpRegistryIntegrity.Type;
49
50export const ACP_REGISTRY_MAX_AGENTS = 512;
51
52export const AcpRegistrySearchInput = Schema.Struct({
53 query: TrimmedString.check(Schema.isMaxLength(120)),
54 limit: Schema.optional(
55 Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: ACP_REGISTRY_MAX_AGENTS })),
56 ),
57});
58export type AcpRegistrySearchInput = typeof AcpRegistrySearchInput.Type;
59
60const AcpRegistryUrl = Schema.String.check(Schema.isMaxLength(2_048));
61
62export const AcpRegistrySearchAgent = Schema.Struct({
63 id: AcpRegistryAgentId,
64 name: TrimmedNonEmptyString.check(Schema.isMaxLength(160)),
65 version: TrimmedNonEmptyString.check(Schema.isMaxLength(128)),
66 description: Schema.String.check(Schema.isMaxLength(1_024)),
67 authors: Schema.Array(Schema.String.check(Schema.isMaxLength(256))).check(Schema.isMaxLength(16)),
68 license: Schema.NullOr(Schema.String.check(Schema.isMaxLength(128))),
69 website: Schema.NullOr(AcpRegistryUrl),
70 repository: Schema.NullOr(AcpRegistryUrl),
71 icon: Schema.NullOr(AcpRegistryUrl),
72 distribution: AcpRegistryDistribution,
73 integrity: AcpRegistryIntegrity,
74});
75export type AcpRegistrySearchAgent = typeof AcpRegistrySearchAgent.Type;
76
77export const AcpRegistrySearchResult = Schema.Struct({
78 agents: Schema.Array(AcpRegistrySearchAgent).check(Schema.isMaxLength(ACP_REGISTRY_MAX_AGENTS)),
79});
80export type AcpRegistrySearchResult = typeof AcpRegistrySearchResult.Type;
81
82export const AcpRegistryPrepareInput = Schema.Struct({
83 agentId: AcpRegistryAgentId,
84});
85export type AcpRegistryPrepareInput = typeof AcpRegistryPrepareInput.Type;
86
87export const AcpRegistryPrepareResult = Schema.Struct({
88 agentId: AcpRegistryAgentId,
89 version: TrimmedNonEmptyString.check(Schema.isMaxLength(128)),
90 distribution: AcpRegistryDistribution,
91 prepared: Schema.Literal(true),
92});
93export type AcpRegistryPrepareResult = typeof AcpRegistryPrepareResult.Type;
94
95export const AcpRegistryManagedBinaryUninstallInput = Schema.Struct({
96 agentId: AcpRegistryAgentId,
97});
98export type AcpRegistryManagedBinaryUninstallInput =
99 typeof AcpRegistryManagedBinaryUninstallInput.Type;
100
101export const AcpRegistryManagedBinaryUninstallResult = Schema.Struct({
102 agentId: AcpRegistryAgentId,
103 removed: Schema.Boolean,
104});
105export type AcpRegistryManagedBinaryUninstallResult =
106 typeof AcpRegistryManagedBinaryUninstallResult.Type;
107
108const AcpRegistryProbeText = TrimmedNonEmptyString.check(Schema.isMaxLength(256));
109const AcpRegistryProbeDescription = Schema.NullOr(Schema.String.check(Schema.isMaxLength(1_024)));
110
111export const AcpRegistryProbeAuthMethod = Schema.Struct({
112 id: AcpRegistryProbeText,
113 name: AcpRegistryProbeText,
114 description: AcpRegistryProbeDescription,
115 type: Schema.Literals(["agent", "env_var", "terminal"]),
116 command: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(2_048))),
117 envVarNames: Schema.optionalKey(Schema.Array(AcpRegistryProbeText).check(Schema.isMaxLength(16))),
118 link: Schema.optionalKey(AcpRegistryUrl),
119});
120export type AcpRegistryProbeAuthMethod = typeof AcpRegistryProbeAuthMethod.Type;
121
122export const AcpRegistryUrlAuthAction = Schema.Struct({
123 elicitationId: AcpRegistryProbeText,
124 url: AcpRegistryUrl,
125 message: Schema.String.check(Schema.isMaxLength(1_024)),
126 createdAt: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(128))),
127 expiresAt: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(128))),
128});
129export type AcpRegistryUrlAuthAction = typeof AcpRegistryUrlAuthAction.Type;
130
131export const AcpRegistryAcceptUrlAuthInput = Schema.Struct({
132 instanceId: ProviderInstanceId,
133 elicitationId: AcpRegistryProbeText,
134});
135export type AcpRegistryAcceptUrlAuthInput = typeof AcpRegistryAcceptUrlAuthInput.Type;
136
137export const AcpRegistryAcceptUrlAuthResult = Schema.Struct({
138 accepted: Schema.Boolean,
139});
140export type AcpRegistryAcceptUrlAuthResult = typeof AcpRegistryAcceptUrlAuthResult.Type;
141
142const AcpRegistrySessionId = TrimmedNonEmptyString.check(Schema.isMaxLength(1_024));
143const AcpRegistrySessionPath = TrimmedNonEmptyString.check(Schema.isMaxLength(4_096));
144
145export const AcpRegistrySession = Schema.Struct({
146 sessionId: AcpRegistrySessionId,
147 cwd: AcpRegistrySessionPath,
148 additionalDirectories: Schema.Array(AcpRegistrySessionPath).check(Schema.isMaxLength(32)),
149 title: Schema.NullOr(Schema.String.check(Schema.isMaxLength(1_024))),
150 updatedAt: Schema.NullOr(Schema.String.check(Schema.isMaxLength(128))),
151 importedThreadId: Schema.NullOr(ThreadId),
152});
153export type AcpRegistrySession = typeof AcpRegistrySession.Type;
154
155export const AcpRegistryListSessionsInput = Schema.Struct({
156 instanceId: ProviderInstanceId,
157 projectId: ProjectId,
158 cursor: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(2_048))),
159});
160export type AcpRegistryListSessionsInput = typeof AcpRegistryListSessionsInput.Type;
161
162export const AcpRegistryListSessionsResult = Schema.Struct({
163 sessions: Schema.Array(AcpRegistrySession).check(Schema.isMaxLength(256)),
164 nextCursor: Schema.NullOr(Schema.String.check(Schema.isMaxLength(2_048))),
165 canLoad: Schema.Boolean,
166 canResume: Schema.Boolean,
167 canDelete: Schema.Boolean,
168});
169export type AcpRegistryListSessionsResult = typeof AcpRegistryListSessionsResult.Type;
170
171export const AcpRegistryImportSessionInput = Schema.Struct({
172 instanceId: ProviderInstanceId,
173 projectId: ProjectId,
174 sessionId: AcpRegistrySessionId,
175 title: Schema.optionalKey(Schema.NullOr(TrimmedNonEmptyString.check(Schema.isMaxLength(1_024)))),
176 updatedAt: Schema.optionalKey(
177 Schema.NullOr(TrimmedNonEmptyString.check(Schema.isMaxLength(128))),
178 ),
179});
180export type AcpRegistryImportSessionInput = typeof AcpRegistryImportSessionInput.Type;
181
182export const AcpRegistryImportSessionResult = Schema.Struct({
183 threadId: ThreadId,
184 imported: Schema.Boolean,
185});
186export type AcpRegistryImportSessionResult = typeof AcpRegistryImportSessionResult.Type;
187
188export const AcpRegistryDeleteSessionInput = Schema.Struct({
189 instanceId: ProviderInstanceId,
190 projectId: ProjectId,
191 sessionId: AcpRegistrySessionId,
192});
193export type AcpRegistryDeleteSessionInput = typeof AcpRegistryDeleteSessionInput.Type;
194
195export const AcpRegistryDeleteSessionResult = Schema.Struct({ deleted: Schema.Literal(true) });
196export type AcpRegistryDeleteSessionResult = typeof AcpRegistryDeleteSessionResult.Type;
197
198const AcpRegistryProviderId = TrimmedNonEmptyString.check(Schema.isMaxLength(256));
199const AcpRegistryProviderProtocol = TrimmedNonEmptyString.check(Schema.isMaxLength(64));
200
201export const AcpRegistryConfigurableProvider = Schema.Struct({
202 providerId: AcpRegistryProviderId,
203 supported: Schema.Array(AcpRegistryProviderProtocol).check(Schema.isMaxLength(16)),
204 required: Schema.Boolean,
205 current: Schema.NullOr(
206 Schema.Struct({
207 apiType: AcpRegistryProviderProtocol,
208 baseUrl: AcpRegistryUrl,
209 }),
210 ),
211});
212export type AcpRegistryConfigurableProvider = typeof AcpRegistryConfigurableProvider.Type;
213
214export const AcpRegistryListProvidersInput = Schema.Struct({
215 instanceId: ProviderInstanceId,
216 projectId: ProjectId,
217});
218export type AcpRegistryListProvidersInput = typeof AcpRegistryListProvidersInput.Type;
219
220export const AcpRegistryListProvidersResult = Schema.Struct({
221 providers: Schema.Array(AcpRegistryConfigurableProvider).check(Schema.isMaxLength(64)),
222});
223export type AcpRegistryListProvidersResult = typeof AcpRegistryListProvidersResult.Type;
224
225export const AcpRegistrySetProviderInput = Schema.Struct({
226 instanceId: ProviderInstanceId,
227 projectId: ProjectId,
228 providerId: AcpRegistryProviderId,
229 apiType: AcpRegistryProviderProtocol,
230 baseUrl: AcpRegistryUrl,
231 // Write-only secrets. Provider list responses intentionally cannot carry headers.
232 headers: Schema.optionalKey(
233 Schema.Record(
234 TrimmedNonEmptyString.check(Schema.isMaxLength(128)),
235 Schema.String.check(Schema.isMaxLength(8_192)),
236 ),
237 ),
238});
239export type AcpRegistrySetProviderInput = typeof AcpRegistrySetProviderInput.Type;
240
241export const AcpRegistrySetProviderResult = Schema.Struct({ configured: Schema.Literal(true) });
242export type AcpRegistrySetProviderResult = typeof AcpRegistrySetProviderResult.Type;
243
244export const AcpRegistryDisableProviderInput = Schema.Struct({
245 instanceId: ProviderInstanceId,
246 projectId: ProjectId,
247 providerId: AcpRegistryProviderId,
248});
249export type AcpRegistryDisableProviderInput = typeof AcpRegistryDisableProviderInput.Type;
250
251export const AcpRegistryDisableProviderResult = Schema.Struct({ disabled: Schema.Literal(true) });
252export type AcpRegistryDisableProviderResult = typeof AcpRegistryDisableProviderResult.Type;
253
254export const AcpRegistryLogoutInput = Schema.Struct({
255 instanceId: ProviderInstanceId,
256});
257export type AcpRegistryLogoutInput = typeof AcpRegistryLogoutInput.Type;
258
259export const AcpRegistryLogoutResult = Schema.Struct({
260 loggedOut: Schema.Literal(true),
261});
262export type AcpRegistryLogoutResult = typeof AcpRegistryLogoutResult.Type;
263
264export const AcpRegistryProbeModel = Schema.Struct({
265 id: AcpRegistryProbeText,
266 name: AcpRegistryProbeText,
267 description: AcpRegistryProbeDescription,
268});
269export type AcpRegistryProbeModel = typeof AcpRegistryProbeModel.Type;
270
271export const AcpRegistryProbeResult = Schema.Struct({
272 instanceId: ProviderInstanceId,
273 // `ready` requires a disposable ACP session/new probe, not passive auth detection.
274 ready: Schema.Literal(true),
275 icon: Schema.NullOr(AcpRegistryUrl),
276 authMethods: Schema.Array(AcpRegistryProbeAuthMethod).check(Schema.isMaxLength(32)),
277 models: Schema.Array(AcpRegistryProbeModel).check(Schema.isMaxLength(256)),
278 currentModelId: Schema.NullOr(AcpRegistryProbeText),
279 configOptions: Schema.Array(ProviderOptionDescriptor).check(Schema.isMaxLength(16)),
280 sessionManagement: Schema.Struct({
281 canList: Schema.Boolean,
282 canLoad: Schema.Boolean,
283 canResume: Schema.Boolean,
284 canLogout: Schema.Boolean,
285 canDelete: Schema.Boolean,
286 canConfigureProviders: Schema.Boolean,
287 }).pipe(
288 Schema.withDecodingDefault(
289 Effect.succeed({
290 canList: false,
291 canLoad: false,
292 canResume: false,
293 canLogout: false,
294 canDelete: false,
295 canConfigureProviders: false,
296 }),
297 ),
298 ),
299});
300export type AcpRegistryProbeResult = typeof AcpRegistryProbeResult.Type;
301
302export const AcpRegistryOperationErrorReason = Schema.Literals([
303 "agent_not_configured",
304 "agent_not_found",
305 "archive_invalid",
306 "authentication_failed",
307 "checksum_mismatch",
308 "download_failed",
309 "install_failed",
310 "instance_not_found",
311 "logout_unsupported",
312 "logout_failed",
313 "probe_failed",
314 "project_not_found",
315 "registry_unavailable",
316 "runner_unavailable",
317 "session_import_failed",
318 "session_delete_unsupported",
319 "session_delete_failed",
320 "session_list_unsupported",
321 "session_resume_unsupported",
322 "providers_unsupported",
323 "providers_list_failed",
324 "provider_configuration_failed",
325 "unsupported_distribution",
326 "unsupported_platform",
327]);
328export type AcpRegistryOperationErrorReason = typeof AcpRegistryOperationErrorReason.Type;
329
330export class AcpRegistryOperationError extends Schema.TaggedError<AcpRegistryOperationError>()(
331 "AcpRegistryOperationError",
332 {
333 reason: AcpRegistryOperationErrorReason,
334 message: Schema.String,
335 authMethods: Schema.optionalKey(
336 Schema.Array(AcpRegistryProbeAuthMethod).check(Schema.isMaxLength(32)),
337 ),
338 authAction: Schema.optionalKey(AcpRegistryUrlAuthAction),
339 cause: Schema.optionalKey(Schema.Defect()),
340 },
341) {}