llm-cli-gateway 2.13.2 → 2.14.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 (79) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/README.md +68 -29
  3. package/dist/acp/client.d.ts +29 -1
  4. package/dist/acp/client.js +78 -4
  5. package/dist/acp/errors.d.ts +9 -1
  6. package/dist/acp/errors.js +19 -0
  7. package/dist/acp/event-normalizer.d.ts +12 -0
  8. package/dist/acp/event-normalizer.js +16 -0
  9. package/dist/acp/flight-redaction.d.ts +3 -0
  10. package/dist/acp/flight-redaction.js +3 -0
  11. package/dist/acp/permission-bridge.js +11 -5
  12. package/dist/acp/process-manager.d.ts +2 -1
  13. package/dist/acp/process-manager.js +43 -4
  14. package/dist/acp/provider-registry.js +19 -11
  15. package/dist/acp/runtime.d.ts +8 -0
  16. package/dist/acp/runtime.js +47 -4
  17. package/dist/acp/types.d.ts +3083 -55
  18. package/dist/acp/types.js +242 -5
  19. package/dist/async-job-manager.d.ts +38 -1
  20. package/dist/async-job-manager.js +287 -20
  21. package/dist/codex-json-parser.d.ts +1 -0
  22. package/dist/codex-json-parser.js +6 -0
  23. package/dist/config.d.ts +19 -0
  24. package/dist/config.js +84 -1
  25. package/dist/flight-recorder.d.ts +2 -0
  26. package/dist/flight-recorder.js +20 -0
  27. package/dist/gemini-json-parser.d.ts +2 -0
  28. package/dist/gemini-json-parser.js +45 -8
  29. package/dist/grok-json-parser.d.ts +14 -0
  30. package/dist/grok-json-parser.js +156 -0
  31. package/dist/index.d.ts +47 -2
  32. package/dist/index.js +504 -122
  33. package/dist/job-store.d.ts +119 -11
  34. package/dist/job-store.js +372 -42
  35. package/dist/model-registry.d.ts +1 -0
  36. package/dist/model-registry.js +46 -0
  37. package/dist/oauth.js +2 -2
  38. package/dist/postgres-job-store-worker.d.ts +1 -0
  39. package/dist/postgres-job-store-worker.js +444 -0
  40. package/dist/pricing.d.ts +3 -2
  41. package/dist/provider-acp-capabilities.d.ts +52 -0
  42. package/dist/provider-acp-capabilities.js +101 -0
  43. package/dist/provider-admin-tools.d.ts +100 -0
  44. package/dist/provider-admin-tools.js +572 -0
  45. package/dist/provider-capability-cache.d.ts +46 -0
  46. package/dist/provider-capability-cache.js +248 -0
  47. package/dist/provider-capability-discovery.d.ts +85 -0
  48. package/dist/provider-capability-discovery.js +461 -0
  49. package/dist/provider-capability-resolver.d.ts +29 -0
  50. package/dist/provider-capability-resolver.js +92 -0
  51. package/dist/provider-definition-assertions.d.ts +9 -0
  52. package/dist/provider-definition-assertions.js +147 -0
  53. package/dist/provider-definitions.d.ts +127 -0
  54. package/dist/provider-definitions.js +758 -0
  55. package/dist/provider-help-parser.d.ts +34 -0
  56. package/dist/provider-help-parser.js +203 -0
  57. package/dist/provider-model-discovery.d.ts +30 -0
  58. package/dist/provider-model-discovery.js +229 -0
  59. package/dist/provider-output-metadata.d.ts +7 -0
  60. package/dist/provider-output-metadata.js +68 -0
  61. package/dist/provider-schema-builder.d.ts +22 -0
  62. package/dist/provider-schema-builder.js +55 -0
  63. package/dist/provider-surface-generator.d.ts +98 -0
  64. package/dist/provider-surface-generator.js +140 -0
  65. package/dist/provider-tool-capabilities.d.ts +3 -2
  66. package/dist/provider-tool-capabilities.js +77 -62
  67. package/dist/request-helpers.d.ts +37 -4
  68. package/dist/request-helpers.js +134 -0
  69. package/dist/resources.d.ts +6 -1
  70. package/dist/resources.js +64 -192
  71. package/dist/session-manager.js +18 -11
  72. package/dist/sqlite-driver.d.ts +1 -1
  73. package/dist/sqlite-driver.js +2 -1
  74. package/dist/stream-json-parser.d.ts +1 -0
  75. package/dist/stream-json-parser.js +3 -0
  76. package/dist/upstream-contracts.d.ts +17 -1
  77. package/dist/upstream-contracts.js +209 -36
  78. package/npm-shrinkwrap.json +2 -2
  79. package/package.json +8 -3
package/dist/acp/types.js CHANGED
@@ -57,10 +57,60 @@ export const InitializeRequestSchema = z
57
57
  _meta: MetaSchema,
58
58
  })
59
59
  .passthrough();
60
+ const SessionSubCapabilitySchema = z.object({ _meta: MetaSchema }).passthrough().nullish();
61
+ export const PromptCapabilitiesSchema = z
62
+ .object({
63
+ image: z.boolean().optional(),
64
+ audio: z.boolean().optional(),
65
+ embeddedContext: z.boolean().optional(),
66
+ _meta: MetaSchema,
67
+ })
68
+ .passthrough();
69
+ export const McpCapabilitiesSchema = z
70
+ .object({
71
+ http: z.boolean().optional(),
72
+ sse: z.boolean().optional(),
73
+ _meta: MetaSchema,
74
+ })
75
+ .passthrough();
76
+ export const SessionCapabilitiesSchema = z
77
+ .object({
78
+ resume: SessionSubCapabilitySchema,
79
+ list: SessionSubCapabilitySchema,
80
+ close: SessionSubCapabilitySchema,
81
+ delete: SessionSubCapabilitySchema,
82
+ additionalDirectories: SessionSubCapabilitySchema,
83
+ _meta: MetaSchema,
84
+ })
85
+ .passthrough();
86
+ export const AgentAuthCapabilitiesSchema = z
87
+ .object({
88
+ logout: z.object({ _meta: MetaSchema }).passthrough().nullish(),
89
+ _meta: MetaSchema,
90
+ })
91
+ .passthrough();
92
+ export const AgentCapabilitiesSchema = z
93
+ .object({
94
+ loadSession: z.boolean().optional(),
95
+ promptCapabilities: PromptCapabilitiesSchema.optional(),
96
+ mcpCapabilities: McpCapabilitiesSchema.optional(),
97
+ sessionCapabilities: SessionCapabilitiesSchema.optional(),
98
+ auth: AgentAuthCapabilitiesSchema.optional(),
99
+ _meta: MetaSchema,
100
+ })
101
+ .passthrough();
102
+ export const AuthMethodSchema = z
103
+ .object({
104
+ id: z.string().optional(),
105
+ name: z.string().optional(),
106
+ description: z.string().nullish(),
107
+ _meta: MetaSchema,
108
+ })
109
+ .passthrough();
60
110
  export const InitializeResponseSchema = z
61
111
  .object({
62
112
  protocolVersion: ProtocolVersionSchema,
63
- agentCapabilities: z.record(z.unknown()).optional(),
113
+ agentCapabilities: AgentCapabilitiesSchema.optional(),
64
114
  agentInfo: z
65
115
  .object({
66
116
  name: z.string().optional(),
@@ -68,10 +118,51 @@ export const InitializeResponseSchema = z
68
118
  })
69
119
  .passthrough()
70
120
  .optional(),
71
- authMethods: z.array(z.record(z.unknown())).optional(),
121
+ authMethods: z.array(AuthMethodSchema).optional(),
72
122
  _meta: MetaSchema,
73
123
  })
74
124
  .passthrough();
125
+ export const BASELINE_ACP_METHODS = [
126
+ "session/new",
127
+ "session/prompt",
128
+ "session/cancel",
129
+ "session/update",
130
+ ];
131
+ function subCapabilityPresent(value) {
132
+ return value !== null && value !== undefined && typeof value === "object";
133
+ }
134
+ export function deriveAcpMethodAvailability(init) {
135
+ const methods = new Set(BASELINE_ACP_METHODS);
136
+ const caps = init.agentCapabilities;
137
+ if (caps?.loadSession === true) {
138
+ methods.add("session/load");
139
+ }
140
+ const sc = caps?.sessionCapabilities;
141
+ if (sc) {
142
+ if (subCapabilityPresent(sc.resume))
143
+ methods.add("session/resume");
144
+ if (subCapabilityPresent(sc.list))
145
+ methods.add("session/list");
146
+ if (subCapabilityPresent(sc.close))
147
+ methods.add("session/close");
148
+ if (subCapabilityPresent(sc.delete))
149
+ methods.add("session/delete");
150
+ }
151
+ if (Array.isArray(init.authMethods) && init.authMethods.length > 0) {
152
+ methods.add("authenticate");
153
+ }
154
+ return methods;
155
+ }
156
+ export function sessionResponseMethods(response) {
157
+ const methods = new Set();
158
+ if (response.modes !== null && response.modes !== undefined) {
159
+ methods.add("session/set_mode");
160
+ }
161
+ if (response.configOptions !== null && response.configOptions !== undefined) {
162
+ methods.add("session/set_config_option");
163
+ }
164
+ return methods;
165
+ }
75
166
  export const McpServerSchema = z.record(z.unknown());
76
167
  export const SessionNewRequestSchema = z
77
168
  .object({
@@ -83,7 +174,8 @@ export const SessionNewRequestSchema = z
83
174
  export const SessionNewResponseSchema = z
84
175
  .object({
85
176
  sessionId: SessionIdSchema,
86
- modes: z.record(z.unknown()).optional(),
177
+ modes: z.record(z.unknown()).nullish(),
178
+ configOptions: z.array(z.record(z.unknown())).nullish(),
87
179
  _meta: MetaSchema,
88
180
  })
89
181
  .passthrough();
@@ -97,7 +189,124 @@ export const SessionLoadRequestSchema = z
97
189
  .passthrough();
98
190
  export const SessionLoadResponseSchema = z
99
191
  .object({
100
- modes: z.record(z.unknown()).optional(),
192
+ modes: z.record(z.unknown()).nullish(),
193
+ configOptions: z.array(z.record(z.unknown())).nullish(),
194
+ _meta: MetaSchema,
195
+ })
196
+ .passthrough();
197
+ export const SessionResumeRequestSchema = z
198
+ .object({
199
+ sessionId: SessionIdSchema,
200
+ cwd: z.string().min(1),
201
+ mcpServers: z.array(McpServerSchema).default([]),
202
+ _meta: MetaSchema,
203
+ })
204
+ .passthrough();
205
+ export const SessionResumeResponseSchema = z
206
+ .object({
207
+ modes: z.record(z.unknown()).nullish(),
208
+ configOptions: z.array(z.record(z.unknown())).nullish(),
209
+ _meta: MetaSchema,
210
+ })
211
+ .passthrough();
212
+ export const SessionModeSchema = z
213
+ .object({
214
+ id: z.string().min(1),
215
+ name: z.string().min(1),
216
+ description: z.string().nullish(),
217
+ _meta: MetaSchema,
218
+ })
219
+ .passthrough();
220
+ export const SessionModeStateSchema = z
221
+ .object({
222
+ currentModeId: z.string().min(1),
223
+ availableModes: z.array(SessionModeSchema),
224
+ _meta: MetaSchema,
225
+ })
226
+ .passthrough();
227
+ export const SessionConfigSelectValueSchema = z
228
+ .object({
229
+ value: z.string().min(1),
230
+ label: z.string().nullish(),
231
+ description: z.string().nullish(),
232
+ _meta: MetaSchema,
233
+ })
234
+ .passthrough();
235
+ export const SessionConfigOptionSchema = z.discriminatedUnion("type", [
236
+ z
237
+ .object({
238
+ type: z.literal("select"),
239
+ id: z.string().min(1),
240
+ name: z.string().min(1),
241
+ description: z.string().nullish(),
242
+ category: z.string().nullish(),
243
+ currentValue: z.string().min(1),
244
+ options: z.array(SessionConfigSelectValueSchema),
245
+ _meta: MetaSchema,
246
+ })
247
+ .passthrough(),
248
+ z
249
+ .object({
250
+ type: z.literal("boolean"),
251
+ id: z.string().min(1),
252
+ name: z.string().min(1),
253
+ description: z.string().nullish(),
254
+ category: z.string().nullish(),
255
+ currentValue: z.boolean(),
256
+ _meta: MetaSchema,
257
+ })
258
+ .passthrough(),
259
+ ]);
260
+ export const SessionInfoSchema = z
261
+ .object({
262
+ sessionId: SessionIdSchema,
263
+ cwd: z.string().min(1),
264
+ additionalDirectories: z.array(z.string()).optional(),
265
+ title: z.string().nullish(),
266
+ updatedAt: z.string().nullish(),
267
+ _meta: MetaSchema,
268
+ })
269
+ .passthrough();
270
+ export const ListSessionsRequestSchema = z
271
+ .object({
272
+ cursor: z.string().nullish(),
273
+ _meta: MetaSchema,
274
+ })
275
+ .passthrough();
276
+ export const ListSessionsResponseSchema = z
277
+ .object({
278
+ sessions: z.array(SessionInfoSchema),
279
+ nextCursor: z.string().nullish(),
280
+ _meta: MetaSchema,
281
+ })
282
+ .passthrough();
283
+ export const CloseSessionRequestSchema = z
284
+ .object({ sessionId: SessionIdSchema, _meta: MetaSchema })
285
+ .passthrough();
286
+ export const CloseSessionResponseSchema = z.object({ _meta: MetaSchema }).passthrough();
287
+ export const DeleteSessionRequestSchema = z
288
+ .object({ sessionId: SessionIdSchema, _meta: MetaSchema })
289
+ .passthrough();
290
+ export const DeleteSessionResponseSchema = z.object({ _meta: MetaSchema }).passthrough();
291
+ export const SetSessionModeRequestSchema = z
292
+ .object({
293
+ sessionId: SessionIdSchema,
294
+ modeId: z.string().min(1),
295
+ _meta: MetaSchema,
296
+ })
297
+ .passthrough();
298
+ export const SetSessionModeResponseSchema = z.object({ _meta: MetaSchema }).passthrough();
299
+ export const SetSessionConfigOptionRequestSchema = z
300
+ .object({
301
+ sessionId: SessionIdSchema,
302
+ configId: z.string().min(1),
303
+ value: z.string().min(1),
304
+ _meta: MetaSchema,
305
+ })
306
+ .passthrough();
307
+ export const SetSessionConfigOptionResponseSchema = z
308
+ .object({
309
+ configOptions: z.array(SessionConfigOptionSchema),
101
310
  _meta: MetaSchema,
102
311
  })
103
312
  .passthrough();
@@ -184,6 +393,13 @@ const UsageUpdate = z
184
393
  _meta: MetaSchema,
185
394
  })
186
395
  .passthrough();
396
+ const ConfigOptionUpdate = z
397
+ .object({
398
+ sessionUpdate: z.literal("config_option_update"),
399
+ configOptions: z.array(SessionConfigOptionSchema),
400
+ _meta: MetaSchema,
401
+ })
402
+ .passthrough();
187
403
  const KNOWN_UPDATE_SCHEMAS = {
188
404
  user_message_chunk: MessageChunkUpdate("user_message_chunk"),
189
405
  agent_message_chunk: MessageChunkUpdate("agent_message_chunk"),
@@ -193,6 +409,7 @@ const KNOWN_UPDATE_SCHEMAS = {
193
409
  plan: PlanUpdate,
194
410
  available_commands_update: AvailableCommandsUpdate,
195
411
  current_mode_update: CurrentModeUpdate,
412
+ config_option_update: ConfigOptionUpdate,
196
413
  usage_update: UsageUpdate,
197
414
  };
198
415
  export const SessionUpdateSchema = z
@@ -227,7 +444,6 @@ export const KNOWN_SESSION_UPDATE_VARIANTS = [
227
444
  "available_commands_update",
228
445
  "current_mode_update",
229
446
  "config_option_update",
230
- "session_info_update",
231
447
  "usage_update",
232
448
  ];
233
449
  export function isUnknownSessionUpdate(update) {
@@ -333,3 +549,24 @@ export function parseWriteTextFileRequest(value, provider) {
333
549
  provider,
334
550
  });
335
551
  }
552
+ export function parseSessionResumeResponse(value, provider) {
553
+ return parseAcp(SessionResumeResponseSchema, value, { method: "session/resume", provider });
554
+ }
555
+ export function parseListSessionsResponse(value, provider) {
556
+ return parseAcp(ListSessionsResponseSchema, value, { method: "session/list", provider });
557
+ }
558
+ export function parseCloseSessionResponse(value, provider) {
559
+ return parseAcp(CloseSessionResponseSchema, value, { method: "session/close", provider });
560
+ }
561
+ export function parseDeleteSessionResponse(value, provider) {
562
+ return parseAcp(DeleteSessionResponseSchema, value, { method: "session/delete", provider });
563
+ }
564
+ export function parseSetSessionModeResponse(value, provider) {
565
+ return parseAcp(SetSessionModeResponseSchema, value, { method: "session/set_mode", provider });
566
+ }
567
+ export function parseSetSessionConfigOptionResponse(value, provider) {
568
+ return parseAcp(SetSessionConfigOptionResponseSchema, value, {
569
+ method: "session/set_config_option",
570
+ provider,
571
+ });
572
+ }
@@ -5,6 +5,14 @@ import { type FlightRecorderLike } from "./flight-recorder.js";
5
5
  import type { ValidationRunStore } from "./job-store.js";
6
6
  import { type ApiProvider, type ApiRequest, type ApiUsage } from "./api-provider.js";
7
7
  import { type JobLimitsConfig } from "./config.js";
8
+ export interface LeaseRuntimeConfig {
9
+ instanceHeartbeatMs: number;
10
+ instanceLeaseTtlMs: number;
11
+ httpJobGraceMs: number;
12
+ orphanSweepIntervalMs: number;
13
+ instanceGcMs: number;
14
+ role?: string;
15
+ }
8
16
  export declare function extractApiHttpStatus(error: unknown): number | null;
9
17
  export declare function extractApiErrorBody(error: unknown): string | undefined;
10
18
  export type LlmCli = "claude" | "codex" | "gemini" | "grok" | "mistral" | "devin" | "cursor";
@@ -69,6 +77,8 @@ export interface AsyncJobResult extends AsyncJobSnapshot {
69
77
  responseId?: string | null;
70
78
  model?: string;
71
79
  errorBody?: string;
80
+ providerSessionId?: string;
81
+ stopReason?: string;
72
82
  }
73
83
  export interface StartJobOptions {
74
84
  cwd?: string;
@@ -100,7 +110,34 @@ export declare class AsyncJobManager {
100
110
  private readonly limiter;
101
111
  private readonly completedJobMemoryTtlMs;
102
112
  private readonly maxJobOutputBytes;
103
- constructor(logger?: Logger, onJobComplete?: ((cli: JobProvider, durationMs: number, success: boolean) => void) | undefined, store?: JobStore | null, flightRecorder?: FlightRecorderLike, limits?: JobLimitsConfig);
113
+ private readonly instanceId;
114
+ private readonly hostname;
115
+ private readonly instancePid;
116
+ private readonly lease;
117
+ private heartbeatTimer;
118
+ private sweepTimer;
119
+ private durableAdmission;
120
+ private consecutiveHeartbeatFailures;
121
+ private skipSweepThisCycle;
122
+ private nextHeartbeatExpectedAt;
123
+ private disposed;
124
+ private readonly pendingWrites;
125
+ constructor(logger?: Logger, onJobComplete?: ((cli: JobProvider, durationMs: number, success: boolean) => void) | undefined, store?: JobStore | null, flightRecorder?: FlightRecorderLike, limits?: JobLimitsConfig, _deprecatedOwnsOrphanRecovery?: boolean, leaseConfig?: LeaseRuntimeConfig);
126
+ canAdmitDurableJobs(): boolean;
127
+ private assertDurableAdmission;
128
+ private trackPendingWrite;
129
+ dispose(opts?: {
130
+ timeoutMs?: number;
131
+ }): Promise<void>;
132
+ getInstanceId(): string;
133
+ private startHeartbeat;
134
+ private onHeartbeatTick;
135
+ runOrphanSweepNow(): void;
136
+ private startReaper;
137
+ private runOrphanSweep;
138
+ private confirmLiveProcessCandidates;
139
+ private recordStartOrFailClosed;
140
+ private markRunningDurable;
104
141
  private buildOrphanFlightResult;
105
142
  checkStalledJobs(now?: number): void;
106
143
  hasStore(): boolean;