@kb-labs/host-agent-contracts 0.2.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.
- package/dist/index.d.ts +322 -0
- package/dist/index.js +112 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/** Token pair returned by Gateway /auth/token and /auth/refresh */
|
|
4
|
+
declare const TokenPairSchema: z.ZodObject<{
|
|
5
|
+
accessToken: z.ZodString;
|
|
6
|
+
refreshToken: z.ZodString;
|
|
7
|
+
expiresIn: z.ZodNumber;
|
|
8
|
+
tokenType: z.ZodLiteral<"Bearer">;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
accessToken: string;
|
|
11
|
+
refreshToken: string;
|
|
12
|
+
expiresIn: number;
|
|
13
|
+
tokenType: "Bearer";
|
|
14
|
+
}, {
|
|
15
|
+
accessToken: string;
|
|
16
|
+
refreshToken: string;
|
|
17
|
+
expiresIn: number;
|
|
18
|
+
tokenType: "Bearer";
|
|
19
|
+
}>;
|
|
20
|
+
/** Execution configuration for Workspace Agent */
|
|
21
|
+
declare const ExecutionConfigSchema: z.ZodObject<{
|
|
22
|
+
/** Execution mode: in-process (fast, trust) or subprocess (sandboxed) */
|
|
23
|
+
mode: z.ZodDefault<z.ZodEnum<["in-process", "subprocess"]>>;
|
|
24
|
+
/** Overall execution timeout in ms */
|
|
25
|
+
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
26
|
+
/** Plugin allowlist. Empty/undefined = all plugins allowed. */
|
|
27
|
+
allowedPlugins: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
mode: "in-process" | "subprocess";
|
|
30
|
+
timeoutMs: number;
|
|
31
|
+
allowedPlugins?: string[] | undefined;
|
|
32
|
+
}, {
|
|
33
|
+
mode?: "in-process" | "subprocess" | undefined;
|
|
34
|
+
timeoutMs?: number | undefined;
|
|
35
|
+
allowedPlugins?: string[] | undefined;
|
|
36
|
+
}>;
|
|
37
|
+
/** Workspace entry — describes a project directory managed by this agent */
|
|
38
|
+
declare const WorkspaceEntrySchema: z.ZodObject<{
|
|
39
|
+
/** Logical workspace ID */
|
|
40
|
+
workspaceId: z.ZodString;
|
|
41
|
+
/** Absolute path to project root */
|
|
42
|
+
path: z.ZodString;
|
|
43
|
+
/** Hash(origin URL + root commit) for repo identity */
|
|
44
|
+
repoFingerprint: z.ZodOptional<z.ZodString>;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
path: string;
|
|
47
|
+
workspaceId: string;
|
|
48
|
+
repoFingerprint?: string | undefined;
|
|
49
|
+
}, {
|
|
50
|
+
path: string;
|
|
51
|
+
workspaceId: string;
|
|
52
|
+
repoFingerprint?: string | undefined;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* ~/.kb/agent.json — persisted on the developer's machine after `kb workspace register`
|
|
56
|
+
*/
|
|
57
|
+
declare const AgentConfigSchema: z.ZodObject<{
|
|
58
|
+
clientId: z.ZodString;
|
|
59
|
+
clientSecret: z.ZodString;
|
|
60
|
+
hostId: z.ZodString;
|
|
61
|
+
gatewayUrl: z.ZodEffects<z.ZodString, string, string>;
|
|
62
|
+
/** X25519 private key, base64url — never leaves the machine */
|
|
63
|
+
privateKey: z.ZodOptional<z.ZodString>;
|
|
64
|
+
/** X25519 public key, base64url — sent to Gateway on hello */
|
|
65
|
+
publicKey: z.ZodOptional<z.ZodString>;
|
|
66
|
+
namespaceId: z.ZodDefault<z.ZodString>;
|
|
67
|
+
/** Host type: local (developer laptop) or cloud (provisioned container) */
|
|
68
|
+
hostType: z.ZodDefault<z.ZodEnum<["local", "cloud"]>>;
|
|
69
|
+
/**
|
|
70
|
+
* Explicit list of workspace paths the agent is allowed to access.
|
|
71
|
+
* Principle of least privilege: no access outside these paths.
|
|
72
|
+
*/
|
|
73
|
+
workspacePaths: z.ZodArray<z.ZodString, "many">;
|
|
74
|
+
/** Structured workspace entries (optional, enriches workspacePaths) */
|
|
75
|
+
workspaces: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
76
|
+
/** Logical workspace ID */
|
|
77
|
+
workspaceId: z.ZodString;
|
|
78
|
+
/** Absolute path to project root */
|
|
79
|
+
path: z.ZodString;
|
|
80
|
+
/** Hash(origin URL + root commit) for repo identity */
|
|
81
|
+
repoFingerprint: z.ZodOptional<z.ZodString>;
|
|
82
|
+
}, "strip", z.ZodTypeAny, {
|
|
83
|
+
path: string;
|
|
84
|
+
workspaceId: string;
|
|
85
|
+
repoFingerprint?: string | undefined;
|
|
86
|
+
}, {
|
|
87
|
+
path: string;
|
|
88
|
+
workspaceId: string;
|
|
89
|
+
repoFingerprint?: string | undefined;
|
|
90
|
+
}>, "many">>;
|
|
91
|
+
/** Execution configuration for plugin execution capability */
|
|
92
|
+
execution: z.ZodDefault<z.ZodObject<{
|
|
93
|
+
/** Execution mode: in-process (fast, trust) or subprocess (sandboxed) */
|
|
94
|
+
mode: z.ZodDefault<z.ZodEnum<["in-process", "subprocess"]>>;
|
|
95
|
+
/** Overall execution timeout in ms */
|
|
96
|
+
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
97
|
+
/** Plugin allowlist. Empty/undefined = all plugins allowed. */
|
|
98
|
+
allowedPlugins: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
99
|
+
}, "strip", z.ZodTypeAny, {
|
|
100
|
+
mode: "in-process" | "subprocess";
|
|
101
|
+
timeoutMs: number;
|
|
102
|
+
allowedPlugins?: string[] | undefined;
|
|
103
|
+
}, {
|
|
104
|
+
mode?: "in-process" | "subprocess" | undefined;
|
|
105
|
+
timeoutMs?: number | undefined;
|
|
106
|
+
allowedPlugins?: string[] | undefined;
|
|
107
|
+
}>>;
|
|
108
|
+
}, "strip", z.ZodTypeAny, {
|
|
109
|
+
clientId: string;
|
|
110
|
+
clientSecret: string;
|
|
111
|
+
hostId: string;
|
|
112
|
+
gatewayUrl: string;
|
|
113
|
+
namespaceId: string;
|
|
114
|
+
hostType: "local" | "cloud";
|
|
115
|
+
workspacePaths: string[];
|
|
116
|
+
execution: {
|
|
117
|
+
mode: "in-process" | "subprocess";
|
|
118
|
+
timeoutMs: number;
|
|
119
|
+
allowedPlugins?: string[] | undefined;
|
|
120
|
+
};
|
|
121
|
+
privateKey?: string | undefined;
|
|
122
|
+
publicKey?: string | undefined;
|
|
123
|
+
workspaces?: {
|
|
124
|
+
path: string;
|
|
125
|
+
workspaceId: string;
|
|
126
|
+
repoFingerprint?: string | undefined;
|
|
127
|
+
}[] | undefined;
|
|
128
|
+
}, {
|
|
129
|
+
clientId: string;
|
|
130
|
+
clientSecret: string;
|
|
131
|
+
hostId: string;
|
|
132
|
+
gatewayUrl: string;
|
|
133
|
+
workspacePaths: string[];
|
|
134
|
+
privateKey?: string | undefined;
|
|
135
|
+
publicKey?: string | undefined;
|
|
136
|
+
namespaceId?: string | undefined;
|
|
137
|
+
hostType?: "local" | "cloud" | undefined;
|
|
138
|
+
workspaces?: {
|
|
139
|
+
path: string;
|
|
140
|
+
workspaceId: string;
|
|
141
|
+
repoFingerprint?: string | undefined;
|
|
142
|
+
}[] | undefined;
|
|
143
|
+
execution?: {
|
|
144
|
+
mode?: "in-process" | "subprocess" | undefined;
|
|
145
|
+
timeoutMs?: number | undefined;
|
|
146
|
+
allowedPlugins?: string[] | undefined;
|
|
147
|
+
} | undefined;
|
|
148
|
+
}>;
|
|
149
|
+
type ExecutionConfig = z.infer<typeof ExecutionConfigSchema>;
|
|
150
|
+
type WorkspaceEntry = z.infer<typeof WorkspaceEntrySchema>;
|
|
151
|
+
type AgentConfig = z.infer<typeof AgentConfigSchema>;
|
|
152
|
+
|
|
153
|
+
declare const CapabilitySchema: z.ZodEnum<["filesystem", "git", "editor-context"]>;
|
|
154
|
+
type Capability = z.infer<typeof CapabilitySchema>;
|
|
155
|
+
/** A call dispatched from Gateway → Host Agent for a capability */
|
|
156
|
+
declare const CapabilityCallSchema: z.ZodObject<{
|
|
157
|
+
type: z.ZodLiteral<"call">;
|
|
158
|
+
requestId: z.ZodString;
|
|
159
|
+
adapter: z.ZodString;
|
|
160
|
+
method: z.ZodString;
|
|
161
|
+
args: z.ZodArray<z.ZodUnknown, "many">;
|
|
162
|
+
}, "strip", z.ZodTypeAny, {
|
|
163
|
+
type: "call";
|
|
164
|
+
requestId: string;
|
|
165
|
+
adapter: string;
|
|
166
|
+
method: string;
|
|
167
|
+
args: unknown[];
|
|
168
|
+
}, {
|
|
169
|
+
type: "call";
|
|
170
|
+
requestId: string;
|
|
171
|
+
adapter: string;
|
|
172
|
+
method: string;
|
|
173
|
+
args: unknown[];
|
|
174
|
+
}>;
|
|
175
|
+
type CapabilityCall = z.infer<typeof CapabilityCallSchema>;
|
|
176
|
+
declare const CapabilityResultSchema: z.ZodObject<{
|
|
177
|
+
requestId: z.ZodString;
|
|
178
|
+
data: z.ZodUnknown;
|
|
179
|
+
}, "strip", z.ZodTypeAny, {
|
|
180
|
+
requestId: string;
|
|
181
|
+
data?: unknown;
|
|
182
|
+
}, {
|
|
183
|
+
requestId: string;
|
|
184
|
+
data?: unknown;
|
|
185
|
+
}>;
|
|
186
|
+
type CapabilityResult = z.infer<typeof CapabilityResultSchema>;
|
|
187
|
+
declare const CapabilityErrorSchema: z.ZodObject<{
|
|
188
|
+
requestId: z.ZodString;
|
|
189
|
+
code: z.ZodString;
|
|
190
|
+
message: z.ZodString;
|
|
191
|
+
retryable: z.ZodDefault<z.ZodBoolean>;
|
|
192
|
+
}, "strip", z.ZodTypeAny, {
|
|
193
|
+
code: string;
|
|
194
|
+
message: string;
|
|
195
|
+
requestId: string;
|
|
196
|
+
retryable: boolean;
|
|
197
|
+
}, {
|
|
198
|
+
code: string;
|
|
199
|
+
message: string;
|
|
200
|
+
requestId: string;
|
|
201
|
+
retryable?: boolean | undefined;
|
|
202
|
+
}>;
|
|
203
|
+
type CapabilityError = z.infer<typeof CapabilityErrorSchema>;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* IPC protocol over Unix socket (~/.kb/agent.sock)
|
|
207
|
+
* Used by CLI/Studio to talk to the local daemon.
|
|
208
|
+
*/
|
|
209
|
+
declare const IpcExecuteRequestSchema: z.ZodObject<{
|
|
210
|
+
type: z.ZodLiteral<"execute">;
|
|
211
|
+
requestId: z.ZodString;
|
|
212
|
+
command: z.ZodString;
|
|
213
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
214
|
+
stream: z.ZodDefault<z.ZodBoolean>;
|
|
215
|
+
}, "strip", z.ZodTypeAny, {
|
|
216
|
+
type: "execute";
|
|
217
|
+
requestId: string;
|
|
218
|
+
command: string;
|
|
219
|
+
stream: boolean;
|
|
220
|
+
params?: Record<string, unknown> | undefined;
|
|
221
|
+
}, {
|
|
222
|
+
type: "execute";
|
|
223
|
+
requestId: string;
|
|
224
|
+
command: string;
|
|
225
|
+
params?: Record<string, unknown> | undefined;
|
|
226
|
+
stream?: boolean | undefined;
|
|
227
|
+
}>;
|
|
228
|
+
type IpcExecuteRequest = z.infer<typeof IpcExecuteRequestSchema>;
|
|
229
|
+
declare const IpcEventMessageSchema: z.ZodObject<{
|
|
230
|
+
type: z.ZodLiteral<"event">;
|
|
231
|
+
requestId: z.ZodString;
|
|
232
|
+
data: z.ZodUnknown;
|
|
233
|
+
}, "strip", z.ZodTypeAny, {
|
|
234
|
+
type: "event";
|
|
235
|
+
requestId: string;
|
|
236
|
+
data?: unknown;
|
|
237
|
+
}, {
|
|
238
|
+
type: "event";
|
|
239
|
+
requestId: string;
|
|
240
|
+
data?: unknown;
|
|
241
|
+
}>;
|
|
242
|
+
type IpcEventMessage = z.infer<typeof IpcEventMessageSchema>;
|
|
243
|
+
declare const IpcDoneMessageSchema: z.ZodObject<{
|
|
244
|
+
type: z.ZodLiteral<"done">;
|
|
245
|
+
requestId: z.ZodString;
|
|
246
|
+
result: z.ZodUnknown;
|
|
247
|
+
}, "strip", z.ZodTypeAny, {
|
|
248
|
+
type: "done";
|
|
249
|
+
requestId: string;
|
|
250
|
+
result?: unknown;
|
|
251
|
+
}, {
|
|
252
|
+
type: "done";
|
|
253
|
+
requestId: string;
|
|
254
|
+
result?: unknown;
|
|
255
|
+
}>;
|
|
256
|
+
type IpcDoneMessage = z.infer<typeof IpcDoneMessageSchema>;
|
|
257
|
+
declare const IpcErrorMessageSchema: z.ZodObject<{
|
|
258
|
+
type: z.ZodLiteral<"error">;
|
|
259
|
+
requestId: z.ZodString;
|
|
260
|
+
code: z.ZodString;
|
|
261
|
+
message: z.ZodString;
|
|
262
|
+
}, "strip", z.ZodTypeAny, {
|
|
263
|
+
code: string;
|
|
264
|
+
message: string;
|
|
265
|
+
type: "error";
|
|
266
|
+
requestId: string;
|
|
267
|
+
}, {
|
|
268
|
+
code: string;
|
|
269
|
+
message: string;
|
|
270
|
+
type: "error";
|
|
271
|
+
requestId: string;
|
|
272
|
+
}>;
|
|
273
|
+
type IpcErrorMessage = z.infer<typeof IpcErrorMessageSchema>;
|
|
274
|
+
declare const IpcCancelRequestSchema: z.ZodObject<{
|
|
275
|
+
type: z.ZodLiteral<"cancel">;
|
|
276
|
+
executionId: z.ZodString;
|
|
277
|
+
reason: z.ZodDefault<z.ZodString>;
|
|
278
|
+
}, "strip", z.ZodTypeAny, {
|
|
279
|
+
type: "cancel";
|
|
280
|
+
executionId: string;
|
|
281
|
+
reason: string;
|
|
282
|
+
}, {
|
|
283
|
+
type: "cancel";
|
|
284
|
+
executionId: string;
|
|
285
|
+
reason?: string | undefined;
|
|
286
|
+
}>;
|
|
287
|
+
type IpcCancelRequest = z.infer<typeof IpcCancelRequestSchema>;
|
|
288
|
+
declare const IpcStatusRequestSchema: z.ZodObject<{
|
|
289
|
+
type: z.ZodLiteral<"status">;
|
|
290
|
+
}, "strip", z.ZodTypeAny, {
|
|
291
|
+
type: "status";
|
|
292
|
+
}, {
|
|
293
|
+
type: "status";
|
|
294
|
+
}>;
|
|
295
|
+
type IpcStatusRequest = z.infer<typeof IpcStatusRequestSchema>;
|
|
296
|
+
declare const IpcStatusResponseSchema: z.ZodObject<{
|
|
297
|
+
type: z.ZodLiteral<"status">;
|
|
298
|
+
connected: z.ZodBoolean;
|
|
299
|
+
hostId: z.ZodOptional<z.ZodString>;
|
|
300
|
+
gatewayUrl: z.ZodOptional<z.ZodString>;
|
|
301
|
+
latencyMs: z.ZodOptional<z.ZodNumber>;
|
|
302
|
+
reconnecting: z.ZodDefault<z.ZodBoolean>;
|
|
303
|
+
}, "strip", z.ZodTypeAny, {
|
|
304
|
+
type: "status";
|
|
305
|
+
connected: boolean;
|
|
306
|
+
reconnecting: boolean;
|
|
307
|
+
hostId?: string | undefined;
|
|
308
|
+
gatewayUrl?: string | undefined;
|
|
309
|
+
latencyMs?: number | undefined;
|
|
310
|
+
}, {
|
|
311
|
+
type: "status";
|
|
312
|
+
connected: boolean;
|
|
313
|
+
hostId?: string | undefined;
|
|
314
|
+
gatewayUrl?: string | undefined;
|
|
315
|
+
latencyMs?: number | undefined;
|
|
316
|
+
reconnecting?: boolean | undefined;
|
|
317
|
+
}>;
|
|
318
|
+
type IpcStatusResponse = z.infer<typeof IpcStatusResponseSchema>;
|
|
319
|
+
type IpcRequest = IpcExecuteRequest | IpcCancelRequest | IpcStatusRequest;
|
|
320
|
+
type IpcResponse = IpcEventMessage | IpcDoneMessage | IpcErrorMessage | IpcStatusResponse;
|
|
321
|
+
|
|
322
|
+
export { type AgentConfig, AgentConfigSchema, type Capability, type CapabilityCall, CapabilityCallSchema, type CapabilityError, CapabilityErrorSchema, type CapabilityResult, CapabilityResultSchema, CapabilitySchema, type ExecutionConfig, ExecutionConfigSchema, type IpcCancelRequest, IpcCancelRequestSchema, type IpcDoneMessage, IpcDoneMessageSchema, type IpcErrorMessage, IpcErrorMessageSchema, type IpcEventMessage, IpcEventMessageSchema, type IpcExecuteRequest, IpcExecuteRequestSchema, type IpcRequest, type IpcResponse, type IpcStatusRequest, IpcStatusRequestSchema, type IpcStatusResponse, IpcStatusResponseSchema, TokenPairSchema, type WorkspaceEntry, WorkspaceEntrySchema };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/config.ts
|
|
4
|
+
var TokenPairSchema = z.object({
|
|
5
|
+
accessToken: z.string().min(1),
|
|
6
|
+
refreshToken: z.string().min(1),
|
|
7
|
+
expiresIn: z.number().positive(),
|
|
8
|
+
tokenType: z.literal("Bearer")
|
|
9
|
+
});
|
|
10
|
+
var ExecutionConfigSchema = z.object({
|
|
11
|
+
/** Execution mode: in-process (fast, trust) or subprocess (sandboxed) */
|
|
12
|
+
mode: z.enum(["in-process", "subprocess"]).default("in-process"),
|
|
13
|
+
/** Overall execution timeout in ms */
|
|
14
|
+
timeoutMs: z.number().positive().default(12e4),
|
|
15
|
+
/** Plugin allowlist. Empty/undefined = all plugins allowed. */
|
|
16
|
+
allowedPlugins: z.array(z.string()).optional()
|
|
17
|
+
});
|
|
18
|
+
var WorkspaceEntrySchema = z.object({
|
|
19
|
+
/** Logical workspace ID */
|
|
20
|
+
workspaceId: z.string(),
|
|
21
|
+
/** Absolute path to project root */
|
|
22
|
+
path: z.string(),
|
|
23
|
+
/** Hash(origin URL + root commit) for repo identity */
|
|
24
|
+
repoFingerprint: z.string().optional()
|
|
25
|
+
});
|
|
26
|
+
var AgentConfigSchema = z.object({
|
|
27
|
+
clientId: z.string(),
|
|
28
|
+
clientSecret: z.string(),
|
|
29
|
+
hostId: z.string(),
|
|
30
|
+
gatewayUrl: z.string().url().refine(
|
|
31
|
+
(url) => url.startsWith("https://") || url.startsWith("http://localhost") || url.startsWith("http://127.0.0.1"),
|
|
32
|
+
{ message: "gatewayUrl must use HTTPS (HTTP only allowed for localhost in dev)" }
|
|
33
|
+
),
|
|
34
|
+
/** X25519 private key, base64url — never leaves the machine */
|
|
35
|
+
privateKey: z.string().optional(),
|
|
36
|
+
/** X25519 public key, base64url — sent to Gateway on hello */
|
|
37
|
+
publicKey: z.string().optional(),
|
|
38
|
+
namespaceId: z.string().default("default"),
|
|
39
|
+
/** Host type: local (developer laptop) or cloud (provisioned container) */
|
|
40
|
+
hostType: z.enum(["local", "cloud"]).default("local"),
|
|
41
|
+
/**
|
|
42
|
+
* Explicit list of workspace paths the agent is allowed to access.
|
|
43
|
+
* Principle of least privilege: no access outside these paths.
|
|
44
|
+
*/
|
|
45
|
+
workspacePaths: z.array(z.string()).min(1),
|
|
46
|
+
/** Structured workspace entries (optional, enriches workspacePaths) */
|
|
47
|
+
workspaces: z.array(WorkspaceEntrySchema).optional(),
|
|
48
|
+
/** Execution configuration for plugin execution capability */
|
|
49
|
+
execution: ExecutionConfigSchema.default({})
|
|
50
|
+
});
|
|
51
|
+
var CapabilitySchema = z.enum(["filesystem", "git", "editor-context"]);
|
|
52
|
+
var CapabilityCallSchema = z.object({
|
|
53
|
+
type: z.literal("call"),
|
|
54
|
+
requestId: z.string(),
|
|
55
|
+
adapter: z.string(),
|
|
56
|
+
// 'filesystem' | 'git'
|
|
57
|
+
method: z.string(),
|
|
58
|
+
args: z.array(z.unknown())
|
|
59
|
+
});
|
|
60
|
+
var CapabilityResultSchema = z.object({
|
|
61
|
+
requestId: z.string(),
|
|
62
|
+
data: z.unknown()
|
|
63
|
+
});
|
|
64
|
+
var CapabilityErrorSchema = z.object({
|
|
65
|
+
requestId: z.string(),
|
|
66
|
+
code: z.string(),
|
|
67
|
+
message: z.string(),
|
|
68
|
+
retryable: z.boolean().default(false)
|
|
69
|
+
});
|
|
70
|
+
var IpcExecuteRequestSchema = z.object({
|
|
71
|
+
type: z.literal("execute"),
|
|
72
|
+
requestId: z.string(),
|
|
73
|
+
command: z.string(),
|
|
74
|
+
params: z.record(z.unknown()).optional(),
|
|
75
|
+
stream: z.boolean().default(false)
|
|
76
|
+
});
|
|
77
|
+
var IpcEventMessageSchema = z.object({
|
|
78
|
+
type: z.literal("event"),
|
|
79
|
+
requestId: z.string(),
|
|
80
|
+
data: z.unknown()
|
|
81
|
+
});
|
|
82
|
+
var IpcDoneMessageSchema = z.object({
|
|
83
|
+
type: z.literal("done"),
|
|
84
|
+
requestId: z.string(),
|
|
85
|
+
result: z.unknown()
|
|
86
|
+
});
|
|
87
|
+
var IpcErrorMessageSchema = z.object({
|
|
88
|
+
type: z.literal("error"),
|
|
89
|
+
requestId: z.string(),
|
|
90
|
+
code: z.string(),
|
|
91
|
+
message: z.string()
|
|
92
|
+
});
|
|
93
|
+
var IpcCancelRequestSchema = z.object({
|
|
94
|
+
type: z.literal("cancel"),
|
|
95
|
+
executionId: z.string(),
|
|
96
|
+
reason: z.string().default("user")
|
|
97
|
+
});
|
|
98
|
+
var IpcStatusRequestSchema = z.object({
|
|
99
|
+
type: z.literal("status")
|
|
100
|
+
});
|
|
101
|
+
var IpcStatusResponseSchema = z.object({
|
|
102
|
+
type: z.literal("status"),
|
|
103
|
+
connected: z.boolean(),
|
|
104
|
+
hostId: z.string().optional(),
|
|
105
|
+
gatewayUrl: z.string().optional(),
|
|
106
|
+
latencyMs: z.number().optional(),
|
|
107
|
+
reconnecting: z.boolean().default(false)
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
export { AgentConfigSchema, CapabilityCallSchema, CapabilityErrorSchema, CapabilityResultSchema, CapabilitySchema, ExecutionConfigSchema, IpcCancelRequestSchema, IpcDoneMessageSchema, IpcErrorMessageSchema, IpcEventMessageSchema, IpcExecuteRequestSchema, IpcStatusRequestSchema, IpcStatusResponseSchema, TokenPairSchema, WorkspaceEntrySchema };
|
|
111
|
+
//# sourceMappingURL=index.js.map
|
|
112
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/capability.ts","../src/ipc.ts"],"names":["z"],"mappings":";;;AAGO,IAAM,eAAA,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E,MAAA,EAAO;AAAA,EACf,OAAA,EAASA,EAAE,MAAA;AACb,CAAC;AAGM,IAAM,sBAAA,GAAyBA,EAAE,MAAA,CAAO;AAAA,EAC7C,IAAA,EAAMA,CAAAA,CAAE,OAAA,CAAQ,QAAQ,CAAA;AAAA,EACxB,WAAA,EAAaA,EAAE,MAAA,EAAO;AAAA,EACtB,MAAA,EAAQA,CAAAA,CAAE,MAAA,EAAO,CAAE,QAAQ,MAAM;AACnC,CAAC;AAGM,IAAM,sBAAA,GAAyBA,EAAE,MAAA,CAAO;AAAA,EAC7C,IAAA,EAAMA,CAAAA,CAAE,OAAA,CAAQ,QAAQ;AAC1B,CAAC;AAGM,IAAM,uBAAA,GAA0BA,EAAE,MAAA,CAAO;AAAA,EAC9C,IAAA,EAAMA,CAAAA,CAAE,OAAA,CAAQ,QAAQ,CAAA;AAAA,EACxB,SAAA,EAAWA,EAAE,OAAA,EAAQ;AAAA,EACrB,MAAA,EAAQA,CAAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC5B,UAAA,EAAYA,CAAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAChC,SAAA,EAAWA,CAAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC/B,YAAA,EAAcA,CAAAA,CAAE,OAAA,EAAQ,CAAE,QAAQ,KAAK;AACzC,CAAC","file":"index.js","sourcesContent":["import { z } from 'zod';\n\n/** Token pair returned by Gateway /auth/token and /auth/refresh */\nexport const TokenPairSchema = z.object({\n accessToken: z.string().min(1),\n refreshToken: z.string().min(1),\n expiresIn: z.number().positive(),\n tokenType: z.literal('Bearer'),\n});\n\n/** Execution configuration for Workspace Agent */\nexport const ExecutionConfigSchema = z.object({\n /** Execution mode: in-process (fast, trust) or subprocess (sandboxed) */\n mode: z.enum(['in-process', 'subprocess']).default('in-process'),\n /** Overall execution timeout in ms */\n timeoutMs: z.number().positive().default(120_000),\n /** Plugin allowlist. Empty/undefined = all plugins allowed. */\n allowedPlugins: z.array(z.string()).optional(),\n});\n\n/** Workspace entry — describes a project directory managed by this agent */\nexport const WorkspaceEntrySchema = z.object({\n /** Logical workspace ID */\n workspaceId: z.string(),\n /** Absolute path to project root */\n path: z.string(),\n /** Hash(origin URL + root commit) for repo identity */\n repoFingerprint: z.string().optional(),\n});\n\n/**\n * ~/.kb/agent.json — persisted on the developer's machine after `kb workspace register`\n */\nexport const AgentConfigSchema = z.object({\n clientId: z.string(),\n clientSecret: z.string(),\n hostId: z.string(),\n gatewayUrl: z.string().url().refine(\n (url) => url.startsWith('https://') || url.startsWith('http://localhost') || url.startsWith('http://127.0.0.1'),\n { message: 'gatewayUrl must use HTTPS (HTTP only allowed for localhost in dev)' },\n ),\n /** X25519 private key, base64url — never leaves the machine */\n privateKey: z.string().optional(),\n /** X25519 public key, base64url — sent to Gateway on hello */\n publicKey: z.string().optional(),\n namespaceId: z.string().default('default'),\n /** Host type: local (developer laptop) or cloud (provisioned container) */\n hostType: z.enum(['local', 'cloud']).default('local'),\n /**\n * Explicit list of workspace paths the agent is allowed to access.\n * Principle of least privilege: no access outside these paths.\n */\n workspacePaths: z.array(z.string()).min(1),\n /** Structured workspace entries (optional, enriches workspacePaths) */\n workspaces: z.array(WorkspaceEntrySchema).optional(),\n /** Execution configuration for plugin execution capability */\n execution: ExecutionConfigSchema.default({}),\n});\n\nexport type ExecutionConfig = z.infer<typeof ExecutionConfigSchema>;\nexport type WorkspaceEntry = z.infer<typeof WorkspaceEntrySchema>;\nexport type AgentConfig = z.infer<typeof AgentConfigSchema>;\n","import { z } from 'zod';\n\nexport const CapabilitySchema = z.enum(['filesystem', 'git', 'editor-context']);\nexport type Capability = z.infer<typeof CapabilitySchema>;\n\n/** A call dispatched from Gateway → Host Agent for a capability */\nexport const CapabilityCallSchema = z.object({\n type: z.literal('call'),\n requestId: z.string(),\n adapter: z.string(), // 'filesystem' | 'git'\n method: z.string(),\n args: z.array(z.unknown()),\n});\nexport type CapabilityCall = z.infer<typeof CapabilityCallSchema>;\n\nexport const CapabilityResultSchema = z.object({\n requestId: z.string(),\n data: z.unknown(),\n});\nexport type CapabilityResult = z.infer<typeof CapabilityResultSchema>;\n\nexport const CapabilityErrorSchema = z.object({\n requestId: z.string(),\n code: z.string(),\n message: z.string(),\n retryable: z.boolean().default(false),\n});\nexport type CapabilityError = z.infer<typeof CapabilityErrorSchema>;\n","import { z } from 'zod';\n\n/**\n * IPC protocol over Unix socket (~/.kb/agent.sock)\n * Used by CLI/Studio to talk to the local daemon.\n */\n\nexport const IpcExecuteRequestSchema = z.object({\n type: z.literal('execute'),\n requestId: z.string(),\n command: z.string(),\n params: z.record(z.unknown()).optional(),\n stream: z.boolean().default(false),\n});\nexport type IpcExecuteRequest = z.infer<typeof IpcExecuteRequestSchema>;\n\nexport const IpcEventMessageSchema = z.object({\n type: z.literal('event'),\n requestId: z.string(),\n data: z.unknown(),\n});\nexport type IpcEventMessage = z.infer<typeof IpcEventMessageSchema>;\n\nexport const IpcDoneMessageSchema = z.object({\n type: z.literal('done'),\n requestId: z.string(),\n result: z.unknown(),\n});\nexport type IpcDoneMessage = z.infer<typeof IpcDoneMessageSchema>;\n\nexport const IpcErrorMessageSchema = z.object({\n type: z.literal('error'),\n requestId: z.string(),\n code: z.string(),\n message: z.string(),\n});\nexport type IpcErrorMessage = z.infer<typeof IpcErrorMessageSchema>;\n\nexport const IpcCancelRequestSchema = z.object({\n type: z.literal('cancel'),\n executionId: z.string(),\n reason: z.string().default('user'),\n});\nexport type IpcCancelRequest = z.infer<typeof IpcCancelRequestSchema>;\n\nexport const IpcStatusRequestSchema = z.object({\n type: z.literal('status'),\n});\nexport type IpcStatusRequest = z.infer<typeof IpcStatusRequestSchema>;\n\nexport const IpcStatusResponseSchema = z.object({\n type: z.literal('status'),\n connected: z.boolean(),\n hostId: z.string().optional(),\n gatewayUrl: z.string().optional(),\n latencyMs: z.number().optional(),\n reconnecting: z.boolean().default(false),\n});\nexport type IpcStatusResponse = z.infer<typeof IpcStatusResponseSchema>;\n\nexport type IpcRequest = IpcExecuteRequest | IpcCancelRequest | IpcStatusRequest;\nexport type IpcResponse = IpcEventMessage | IpcDoneMessage | IpcErrorMessage | IpcStatusResponse;\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kb-labs/host-agent-contracts",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"scripts": {
|
|
19
|
+
"clean": "rimraf dist",
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"dev": "tsup --watch",
|
|
22
|
+
"type-check": "tsc --noEmit",
|
|
23
|
+
"lint": "eslint .",
|
|
24
|
+
"lint:fix": "eslint . --fix",
|
|
25
|
+
"test": "vitest run -c ../../vitest.config.ts --passWithNoTests",
|
|
26
|
+
"test:watch": "vitest -c ../../vitest.config.ts --passWithNoTests"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"zod": "^3.23.8"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@kb-labs/devkit": "link:../../../kb-labs-devkit",
|
|
33
|
+
"rimraf": "^6",
|
|
34
|
+
"tsup": "^8.5.0",
|
|
35
|
+
"vitest": "^3.2.4"
|
|
36
|
+
}
|
|
37
|
+
}
|