@zengxingyuan/aamp-cli-bridge 0.1.7-dev.3 → 0.1.7-dev.4
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/README.md +33 -4
- package/dist/agent-bridge.d.ts +5 -0
- package/dist/agent-bridge.js +208 -30
- package/dist/agent-bridge.js.map +1 -1
- package/dist/bridge.d.ts +109 -0
- package/dist/bridge.js +35 -1
- package/dist/bridge.js.map +1 -1
- package/dist/cli-agent-client.d.ts +1 -0
- package/dist/cli-agent-client.js +13 -0
- package/dist/cli-agent-client.js.map +1 -1
- package/dist/cli-profiles.js +1 -1
- package/dist/cli-profiles.js.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/discovery.d.ts +20 -0
- package/dist/discovery.js +172 -0
- package/dist/discovery.js.map +1 -0
- package/dist/index.js +152 -7
- package/dist/index.js.map +1 -1
- package/dist/json-init.d.ts +280 -0
- package/dist/json-init.js +177 -0
- package/dist/json-init.js.map +1 -0
- package/dist/sender-policy.d.ts +27 -0
- package/dist/sender-policy.js +161 -0
- package/dist/sender-policy.js.map +1 -0
- package/dist/stream-parser.js +17 -6
- package/dist/stream-parser.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
declare const jsonInitInputSchema: z.ZodObject<{
|
|
3
|
+
aampHost: z.ZodOptional<z.ZodString>;
|
|
4
|
+
rejectUnauthorized: z.ZodOptional<z.ZodBoolean>;
|
|
5
|
+
agents: z.ZodArray<z.ZodObject<{
|
|
6
|
+
name: z.ZodString;
|
|
7
|
+
cliProfile: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
8
|
+
name: z.ZodOptional<z.ZodString>;
|
|
9
|
+
description: z.ZodOptional<z.ZodString>;
|
|
10
|
+
command: z.ZodString;
|
|
11
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
12
|
+
stdin: z.ZodOptional<z.ZodString>;
|
|
13
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
14
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
15
|
+
shell: z.ZodOptional<z.ZodBoolean>;
|
|
16
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
successExitCodes: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
18
|
+
stream: z.ZodOptional<z.ZodObject<{
|
|
19
|
+
format: z.ZodEnum<["sse", "ndjson"]>;
|
|
20
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
format: "sse" | "ndjson";
|
|
23
|
+
enabled?: boolean | undefined;
|
|
24
|
+
}, {
|
|
25
|
+
format: "sse" | "ndjson";
|
|
26
|
+
enabled?: boolean | undefined;
|
|
27
|
+
}>>;
|
|
28
|
+
output: z.ZodOptional<z.ZodObject<{
|
|
29
|
+
includeStderr: z.ZodOptional<z.ZodBoolean>;
|
|
30
|
+
stripAnsi: z.ZodOptional<z.ZodBoolean>;
|
|
31
|
+
trim: z.ZodOptional<z.ZodBoolean>;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
includeStderr?: boolean | undefined;
|
|
34
|
+
stripAnsi?: boolean | undefined;
|
|
35
|
+
trim?: boolean | undefined;
|
|
36
|
+
}, {
|
|
37
|
+
includeStderr?: boolean | undefined;
|
|
38
|
+
stripAnsi?: boolean | undefined;
|
|
39
|
+
trim?: boolean | undefined;
|
|
40
|
+
}>>;
|
|
41
|
+
}, "strip", z.ZodTypeAny, {
|
|
42
|
+
command: string;
|
|
43
|
+
name?: string | undefined;
|
|
44
|
+
description?: string | undefined;
|
|
45
|
+
args?: string[] | undefined;
|
|
46
|
+
stdin?: string | undefined;
|
|
47
|
+
env?: Record<string, string> | undefined;
|
|
48
|
+
cwd?: string | undefined;
|
|
49
|
+
shell?: boolean | undefined;
|
|
50
|
+
timeoutMs?: number | undefined;
|
|
51
|
+
successExitCodes?: number[] | undefined;
|
|
52
|
+
stream?: {
|
|
53
|
+
format: "sse" | "ndjson";
|
|
54
|
+
enabled?: boolean | undefined;
|
|
55
|
+
} | undefined;
|
|
56
|
+
output?: {
|
|
57
|
+
includeStderr?: boolean | undefined;
|
|
58
|
+
stripAnsi?: boolean | undefined;
|
|
59
|
+
trim?: boolean | undefined;
|
|
60
|
+
} | undefined;
|
|
61
|
+
}, {
|
|
62
|
+
command: string;
|
|
63
|
+
name?: string | undefined;
|
|
64
|
+
description?: string | undefined;
|
|
65
|
+
args?: string[] | undefined;
|
|
66
|
+
stdin?: string | undefined;
|
|
67
|
+
env?: Record<string, string> | undefined;
|
|
68
|
+
cwd?: string | undefined;
|
|
69
|
+
shell?: boolean | undefined;
|
|
70
|
+
timeoutMs?: number | undefined;
|
|
71
|
+
successExitCodes?: number[] | undefined;
|
|
72
|
+
stream?: {
|
|
73
|
+
format: "sse" | "ndjson";
|
|
74
|
+
enabled?: boolean | undefined;
|
|
75
|
+
} | undefined;
|
|
76
|
+
output?: {
|
|
77
|
+
includeStderr?: boolean | undefined;
|
|
78
|
+
stripAnsi?: boolean | undefined;
|
|
79
|
+
trim?: boolean | undefined;
|
|
80
|
+
} | undefined;
|
|
81
|
+
}>]>>;
|
|
82
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
83
|
+
description: z.ZodOptional<z.ZodString>;
|
|
84
|
+
summary: z.ZodOptional<z.ZodString>;
|
|
85
|
+
cardText: z.ZodOptional<z.ZodString>;
|
|
86
|
+
credentialsFile: z.ZodOptional<z.ZodString>;
|
|
87
|
+
pairingFile: z.ZodOptional<z.ZodString>;
|
|
88
|
+
senderPoliciesFile: z.ZodOptional<z.ZodString>;
|
|
89
|
+
senderPolicies: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
90
|
+
sender: z.ZodString;
|
|
91
|
+
dispatchContextRules: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
|
|
92
|
+
}, "strip", z.ZodTypeAny, {
|
|
93
|
+
sender: string;
|
|
94
|
+
dispatchContextRules?: Record<string, string[]> | undefined;
|
|
95
|
+
}, {
|
|
96
|
+
sender: string;
|
|
97
|
+
dispatchContextRules?: Record<string, string[]> | undefined;
|
|
98
|
+
}>, "many">>;
|
|
99
|
+
taskDispatchConcurrency: z.ZodOptional<z.ZodNumber>;
|
|
100
|
+
createPairing: z.ZodOptional<z.ZodBoolean>;
|
|
101
|
+
}, "strip", z.ZodTypeAny, {
|
|
102
|
+
name: string;
|
|
103
|
+
description?: string | undefined;
|
|
104
|
+
cliProfile?: string | {
|
|
105
|
+
command: string;
|
|
106
|
+
name?: string | undefined;
|
|
107
|
+
description?: string | undefined;
|
|
108
|
+
args?: string[] | undefined;
|
|
109
|
+
stdin?: string | undefined;
|
|
110
|
+
env?: Record<string, string> | undefined;
|
|
111
|
+
cwd?: string | undefined;
|
|
112
|
+
shell?: boolean | undefined;
|
|
113
|
+
timeoutMs?: number | undefined;
|
|
114
|
+
successExitCodes?: number[] | undefined;
|
|
115
|
+
stream?: {
|
|
116
|
+
format: "sse" | "ndjson";
|
|
117
|
+
enabled?: boolean | undefined;
|
|
118
|
+
} | undefined;
|
|
119
|
+
output?: {
|
|
120
|
+
includeStderr?: boolean | undefined;
|
|
121
|
+
stripAnsi?: boolean | undefined;
|
|
122
|
+
trim?: boolean | undefined;
|
|
123
|
+
} | undefined;
|
|
124
|
+
} | undefined;
|
|
125
|
+
slug?: string | undefined;
|
|
126
|
+
summary?: string | undefined;
|
|
127
|
+
cardText?: string | undefined;
|
|
128
|
+
credentialsFile?: string | undefined;
|
|
129
|
+
pairingFile?: string | undefined;
|
|
130
|
+
senderPoliciesFile?: string | undefined;
|
|
131
|
+
senderPolicies?: {
|
|
132
|
+
sender: string;
|
|
133
|
+
dispatchContextRules?: Record<string, string[]> | undefined;
|
|
134
|
+
}[] | undefined;
|
|
135
|
+
taskDispatchConcurrency?: number | undefined;
|
|
136
|
+
createPairing?: boolean | undefined;
|
|
137
|
+
}, {
|
|
138
|
+
name: string;
|
|
139
|
+
description?: string | undefined;
|
|
140
|
+
cliProfile?: string | {
|
|
141
|
+
command: string;
|
|
142
|
+
name?: string | undefined;
|
|
143
|
+
description?: string | undefined;
|
|
144
|
+
args?: string[] | undefined;
|
|
145
|
+
stdin?: string | undefined;
|
|
146
|
+
env?: Record<string, string> | undefined;
|
|
147
|
+
cwd?: string | undefined;
|
|
148
|
+
shell?: boolean | undefined;
|
|
149
|
+
timeoutMs?: number | undefined;
|
|
150
|
+
successExitCodes?: number[] | undefined;
|
|
151
|
+
stream?: {
|
|
152
|
+
format: "sse" | "ndjson";
|
|
153
|
+
enabled?: boolean | undefined;
|
|
154
|
+
} | undefined;
|
|
155
|
+
output?: {
|
|
156
|
+
includeStderr?: boolean | undefined;
|
|
157
|
+
stripAnsi?: boolean | undefined;
|
|
158
|
+
trim?: boolean | undefined;
|
|
159
|
+
} | undefined;
|
|
160
|
+
} | undefined;
|
|
161
|
+
slug?: string | undefined;
|
|
162
|
+
summary?: string | undefined;
|
|
163
|
+
cardText?: string | undefined;
|
|
164
|
+
credentialsFile?: string | undefined;
|
|
165
|
+
pairingFile?: string | undefined;
|
|
166
|
+
senderPoliciesFile?: string | undefined;
|
|
167
|
+
senderPolicies?: {
|
|
168
|
+
sender: string;
|
|
169
|
+
dispatchContextRules?: Record<string, string[]> | undefined;
|
|
170
|
+
}[] | undefined;
|
|
171
|
+
taskDispatchConcurrency?: number | undefined;
|
|
172
|
+
createPairing?: boolean | undefined;
|
|
173
|
+
}>, "many">;
|
|
174
|
+
}, "strip", z.ZodTypeAny, {
|
|
175
|
+
agents: {
|
|
176
|
+
name: string;
|
|
177
|
+
description?: string | undefined;
|
|
178
|
+
cliProfile?: string | {
|
|
179
|
+
command: string;
|
|
180
|
+
name?: string | undefined;
|
|
181
|
+
description?: string | undefined;
|
|
182
|
+
args?: string[] | undefined;
|
|
183
|
+
stdin?: string | undefined;
|
|
184
|
+
env?: Record<string, string> | undefined;
|
|
185
|
+
cwd?: string | undefined;
|
|
186
|
+
shell?: boolean | undefined;
|
|
187
|
+
timeoutMs?: number | undefined;
|
|
188
|
+
successExitCodes?: number[] | undefined;
|
|
189
|
+
stream?: {
|
|
190
|
+
format: "sse" | "ndjson";
|
|
191
|
+
enabled?: boolean | undefined;
|
|
192
|
+
} | undefined;
|
|
193
|
+
output?: {
|
|
194
|
+
includeStderr?: boolean | undefined;
|
|
195
|
+
stripAnsi?: boolean | undefined;
|
|
196
|
+
trim?: boolean | undefined;
|
|
197
|
+
} | undefined;
|
|
198
|
+
} | undefined;
|
|
199
|
+
slug?: string | undefined;
|
|
200
|
+
summary?: string | undefined;
|
|
201
|
+
cardText?: string | undefined;
|
|
202
|
+
credentialsFile?: string | undefined;
|
|
203
|
+
pairingFile?: string | undefined;
|
|
204
|
+
senderPoliciesFile?: string | undefined;
|
|
205
|
+
senderPolicies?: {
|
|
206
|
+
sender: string;
|
|
207
|
+
dispatchContextRules?: Record<string, string[]> | undefined;
|
|
208
|
+
}[] | undefined;
|
|
209
|
+
taskDispatchConcurrency?: number | undefined;
|
|
210
|
+
createPairing?: boolean | undefined;
|
|
211
|
+
}[];
|
|
212
|
+
aampHost?: string | undefined;
|
|
213
|
+
rejectUnauthorized?: boolean | undefined;
|
|
214
|
+
}, {
|
|
215
|
+
agents: {
|
|
216
|
+
name: string;
|
|
217
|
+
description?: string | undefined;
|
|
218
|
+
cliProfile?: string | {
|
|
219
|
+
command: string;
|
|
220
|
+
name?: string | undefined;
|
|
221
|
+
description?: string | undefined;
|
|
222
|
+
args?: string[] | undefined;
|
|
223
|
+
stdin?: string | undefined;
|
|
224
|
+
env?: Record<string, string> | undefined;
|
|
225
|
+
cwd?: string | undefined;
|
|
226
|
+
shell?: boolean | undefined;
|
|
227
|
+
timeoutMs?: number | undefined;
|
|
228
|
+
successExitCodes?: number[] | undefined;
|
|
229
|
+
stream?: {
|
|
230
|
+
format: "sse" | "ndjson";
|
|
231
|
+
enabled?: boolean | undefined;
|
|
232
|
+
} | undefined;
|
|
233
|
+
output?: {
|
|
234
|
+
includeStderr?: boolean | undefined;
|
|
235
|
+
stripAnsi?: boolean | undefined;
|
|
236
|
+
trim?: boolean | undefined;
|
|
237
|
+
} | undefined;
|
|
238
|
+
} | undefined;
|
|
239
|
+
slug?: string | undefined;
|
|
240
|
+
summary?: string | undefined;
|
|
241
|
+
cardText?: string | undefined;
|
|
242
|
+
credentialsFile?: string | undefined;
|
|
243
|
+
pairingFile?: string | undefined;
|
|
244
|
+
senderPoliciesFile?: string | undefined;
|
|
245
|
+
senderPolicies?: {
|
|
246
|
+
sender: string;
|
|
247
|
+
dispatchContextRules?: Record<string, string[]> | undefined;
|
|
248
|
+
}[] | undefined;
|
|
249
|
+
taskDispatchConcurrency?: number | undefined;
|
|
250
|
+
createPairing?: boolean | undefined;
|
|
251
|
+
}[];
|
|
252
|
+
aampHost?: string | undefined;
|
|
253
|
+
rejectUnauthorized?: boolean | undefined;
|
|
254
|
+
}>;
|
|
255
|
+
export type JsonInitInput = z.infer<typeof jsonInitInputSchema>;
|
|
256
|
+
export declare function runJsonInit(configPath: string, rawInput: unknown): Promise<{
|
|
257
|
+
schemaVersion: number;
|
|
258
|
+
type: string;
|
|
259
|
+
bridge: string;
|
|
260
|
+
configPath: string;
|
|
261
|
+
aampHost: string;
|
|
262
|
+
agents: {
|
|
263
|
+
pairing?: {
|
|
264
|
+
mailbox: string;
|
|
265
|
+
pairCode: string;
|
|
266
|
+
expiresAt: string;
|
|
267
|
+
connectUrl: string;
|
|
268
|
+
webUrl: string;
|
|
269
|
+
pairingFile: string;
|
|
270
|
+
} | undefined;
|
|
271
|
+
name: string;
|
|
272
|
+
bridge: string;
|
|
273
|
+
connection: string;
|
|
274
|
+
email: string;
|
|
275
|
+
registered: boolean;
|
|
276
|
+
credentialsFile: string;
|
|
277
|
+
profile: string;
|
|
278
|
+
}[];
|
|
279
|
+
}>;
|
|
280
|
+
export {};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { AampClient } from 'aamp-sdk';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { resolveCliProfile } from './cli-profiles.js';
|
|
6
|
+
import { cliProfileDefinitionSchema } from './config.js';
|
|
7
|
+
import { createPairingCode, defaultPairingFile, defaultSenderPoliciesFile, pairingUrlToWebUrl, resolvePairingFile } from './pairing.js';
|
|
8
|
+
import { getDefaultCredentialsPath, resolveCredentialsFile } from './storage.js';
|
|
9
|
+
const senderPolicySchema = z.object({
|
|
10
|
+
sender: z.string().min(1),
|
|
11
|
+
dispatchContextRules: z.record(z.array(z.string().min(1))).optional(),
|
|
12
|
+
});
|
|
13
|
+
const jsonInitAgentSchema = z.object({
|
|
14
|
+
name: z.string().min(1),
|
|
15
|
+
cliProfile: z.union([z.string().min(1), cliProfileDefinitionSchema]).optional(),
|
|
16
|
+
slug: z.string().regex(/^[a-z0-9-]+$/).optional(),
|
|
17
|
+
description: z.string().optional(),
|
|
18
|
+
summary: z.string().optional(),
|
|
19
|
+
cardText: z.string().optional(),
|
|
20
|
+
credentialsFile: z.string().optional(),
|
|
21
|
+
pairingFile: z.string().optional(),
|
|
22
|
+
senderPoliciesFile: z.string().optional(),
|
|
23
|
+
senderPolicies: z.array(senderPolicySchema).optional(),
|
|
24
|
+
taskDispatchConcurrency: z.number().int().positive().optional(),
|
|
25
|
+
createPairing: z.boolean().optional(),
|
|
26
|
+
});
|
|
27
|
+
const jsonInitInputSchema = z.object({
|
|
28
|
+
aampHost: z.string().url().optional(),
|
|
29
|
+
rejectUnauthorized: z.boolean().optional(),
|
|
30
|
+
agents: z.array(jsonInitAgentSchema).min(1),
|
|
31
|
+
});
|
|
32
|
+
function loadPreviousConfig(configPath) {
|
|
33
|
+
if (!existsSync(configPath))
|
|
34
|
+
return undefined;
|
|
35
|
+
try {
|
|
36
|
+
const raw = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
37
|
+
if (!raw || !Array.isArray(raw.agents))
|
|
38
|
+
return undefined;
|
|
39
|
+
return {
|
|
40
|
+
aampHost: typeof raw.aampHost === 'string' ? raw.aampHost : 'https://meshmail.ai',
|
|
41
|
+
rejectUnauthorized: raw.rejectUnauthorized === true,
|
|
42
|
+
...(raw.profiles ? { profiles: raw.profiles } : {}),
|
|
43
|
+
agents: raw.agents,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function loadCredentials(path) {
|
|
51
|
+
if (!existsSync(path))
|
|
52
|
+
return undefined;
|
|
53
|
+
const creds = JSON.parse(readFileSync(path, 'utf-8'));
|
|
54
|
+
if (!creds.email || !creds.smtpPassword)
|
|
55
|
+
return undefined;
|
|
56
|
+
return {
|
|
57
|
+
email: creds.email,
|
|
58
|
+
...(creds.mailboxToken ? { mailboxToken: creds.mailboxToken } : {}),
|
|
59
|
+
smtpPassword: creds.smtpPassword,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function normalizeSenderPolicies(policies) {
|
|
63
|
+
const normalized = policies
|
|
64
|
+
?.map((policy) => ({
|
|
65
|
+
sender: policy.sender.trim().toLowerCase(),
|
|
66
|
+
...(policy.dispatchContextRules ? { dispatchContextRules: policy.dispatchContextRules } : {}),
|
|
67
|
+
}))
|
|
68
|
+
.filter((policy) => Boolean(policy.sender));
|
|
69
|
+
return normalized?.length ? normalized : undefined;
|
|
70
|
+
}
|
|
71
|
+
export async function runJsonInit(configPath, rawInput) {
|
|
72
|
+
const input = jsonInitInputSchema.parse(rawInput);
|
|
73
|
+
const previousConfig = loadPreviousConfig(configPath);
|
|
74
|
+
const previousAgents = new Map((previousConfig?.agents ?? []).map((agent) => [agent.name, agent]));
|
|
75
|
+
const aampHost = input.aampHost ?? previousConfig?.aampHost ?? 'https://meshmail.ai';
|
|
76
|
+
const rejectUnauthorized = input.rejectUnauthorized ?? previousConfig?.rejectUnauthorized ?? false;
|
|
77
|
+
const nextAgents = new Map((previousConfig?.agents ?? []).map((agent) => [agent.name, agent]));
|
|
78
|
+
const results = [];
|
|
79
|
+
for (const requestedAgent of input.agents) {
|
|
80
|
+
const previousAgent = previousAgents.get(requestedAgent.name);
|
|
81
|
+
const cliProfile = requestedAgent.cliProfile ?? previousAgent?.cliProfile ?? requestedAgent.name;
|
|
82
|
+
resolveCliProfile(cliProfile, previousConfig?.profiles);
|
|
83
|
+
const credentialsFile = requestedAgent.credentialsFile
|
|
84
|
+
?? previousAgent?.credentialsFile
|
|
85
|
+
?? getDefaultCredentialsPath(requestedAgent.name);
|
|
86
|
+
const resolvedCredentialsFile = resolveCredentialsFile(credentialsFile, requestedAgent.name);
|
|
87
|
+
const pairingFile = requestedAgent.pairingFile
|
|
88
|
+
?? previousAgent?.pairingFile
|
|
89
|
+
?? defaultPairingFile(requestedAgent.name);
|
|
90
|
+
const resolvedPairingFile = resolvePairingFile(pairingFile, requestedAgent.name);
|
|
91
|
+
const senderPoliciesFile = requestedAgent.senderPoliciesFile
|
|
92
|
+
?? previousAgent?.senderPoliciesFile
|
|
93
|
+
?? defaultSenderPoliciesFile(requestedAgent.name);
|
|
94
|
+
const slug = requestedAgent.slug
|
|
95
|
+
?? previousAgent?.slug
|
|
96
|
+
?? `${requestedAgent.name}-cli-bridge`;
|
|
97
|
+
const description = requestedAgent.description
|
|
98
|
+
?? previousAgent?.description
|
|
99
|
+
?? `${requestedAgent.name} via CLI bridge`;
|
|
100
|
+
const senderPolicies = normalizeSenderPolicies(requestedAgent.senderPolicies)
|
|
101
|
+
?? previousAgent?.senderPolicies;
|
|
102
|
+
let credentials = loadCredentials(resolvedCredentialsFile);
|
|
103
|
+
let registered = false;
|
|
104
|
+
if (!credentials) {
|
|
105
|
+
const created = await AampClient.registerMailbox({
|
|
106
|
+
aampHost,
|
|
107
|
+
slug,
|
|
108
|
+
description,
|
|
109
|
+
});
|
|
110
|
+
credentials = {
|
|
111
|
+
email: created.email,
|
|
112
|
+
mailboxToken: created.mailboxToken,
|
|
113
|
+
smtpPassword: created.smtpPassword,
|
|
114
|
+
};
|
|
115
|
+
mkdirSync(dirname(resolvedCredentialsFile), { recursive: true });
|
|
116
|
+
writeFileSync(resolvedCredentialsFile, `${JSON.stringify(credentials, null, 2)}\n`);
|
|
117
|
+
registered = true;
|
|
118
|
+
}
|
|
119
|
+
const agent = {
|
|
120
|
+
...(previousAgent ?? {}),
|
|
121
|
+
name: requestedAgent.name,
|
|
122
|
+
cliProfile,
|
|
123
|
+
slug,
|
|
124
|
+
description,
|
|
125
|
+
...(requestedAgent.summary ?? previousAgent?.summary ? { summary: requestedAgent.summary ?? previousAgent?.summary } : {}),
|
|
126
|
+
...(requestedAgent.cardText ?? previousAgent?.cardText ? { cardText: requestedAgent.cardText ?? previousAgent?.cardText } : {}),
|
|
127
|
+
credentialsFile,
|
|
128
|
+
pairingFile,
|
|
129
|
+
senderPoliciesFile,
|
|
130
|
+
...(senderPolicies ? { senderPolicies } : {}),
|
|
131
|
+
...(requestedAgent.taskDispatchConcurrency ?? previousAgent?.taskDispatchConcurrency
|
|
132
|
+
? { taskDispatchConcurrency: requestedAgent.taskDispatchConcurrency ?? previousAgent?.taskDispatchConcurrency }
|
|
133
|
+
: {}),
|
|
134
|
+
};
|
|
135
|
+
delete agent.senderWhitelist;
|
|
136
|
+
nextAgents.set(requestedAgent.name, agent);
|
|
137
|
+
const pairing = requestedAgent.createPairing
|
|
138
|
+
? createPairingCode({ mailbox: credentials.email, file: resolvedPairingFile })
|
|
139
|
+
: undefined;
|
|
140
|
+
results.push({
|
|
141
|
+
name: requestedAgent.name,
|
|
142
|
+
bridge: 'cli-bridge',
|
|
143
|
+
connection: 'cli_bridge',
|
|
144
|
+
email: credentials.email,
|
|
145
|
+
registered,
|
|
146
|
+
credentialsFile: resolvedCredentialsFile,
|
|
147
|
+
profile: typeof cliProfile === 'string' ? cliProfile : (cliProfile.name ?? 'inline'),
|
|
148
|
+
...(pairing ? {
|
|
149
|
+
pairing: {
|
|
150
|
+
mailbox: pairing.mailbox,
|
|
151
|
+
pairCode: pairing.pairCode,
|
|
152
|
+
expiresAt: pairing.expiresAt,
|
|
153
|
+
connectUrl: pairing.connectUrl,
|
|
154
|
+
webUrl: pairingUrlToWebUrl(pairing.connectUrl),
|
|
155
|
+
pairingFile: resolvedPairingFile,
|
|
156
|
+
},
|
|
157
|
+
} : {}),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
const config = {
|
|
161
|
+
...(previousConfig ?? {}),
|
|
162
|
+
aampHost,
|
|
163
|
+
rejectUnauthorized,
|
|
164
|
+
agents: [...nextAgents.values()],
|
|
165
|
+
};
|
|
166
|
+
mkdirSync(dirname(configPath), { recursive: true });
|
|
167
|
+
writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
168
|
+
return {
|
|
169
|
+
schemaVersion: 1,
|
|
170
|
+
type: 'init.completed',
|
|
171
|
+
bridge: 'cli-bridge',
|
|
172
|
+
configPath,
|
|
173
|
+
aampHost,
|
|
174
|
+
agents: results,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=json-init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-init.js","sourceRoot":"","sources":["../src/json-init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,EAAE,0BAA0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: string;
|
|
4
|
+
dispatchContextRules?: Record<string, string[]>;
|
|
5
|
+
};
|
|
6
|
+
export declare function policyTextFromSenderPolicies(senderPolicies: PolicyLike[] | undefined): string;
|
|
7
|
+
export declare function senderPoliciesFromPolicyText(policyText: string): SenderPolicy[] | undefined;
|
|
8
|
+
export declare function getAgentSenderPolicy(config: BridgeConfig, agentName: string): {
|
|
9
|
+
schemaVersion: number;
|
|
10
|
+
type: string;
|
|
11
|
+
bridge: string;
|
|
12
|
+
agent: string;
|
|
13
|
+
senderPolicy: string;
|
|
14
|
+
senderPolicies: PolicyLike[];
|
|
15
|
+
};
|
|
16
|
+
export declare function setAgentSenderPolicy(config: BridgeConfig, configPath: string, agentName: string, policyText: string): {
|
|
17
|
+
schemaVersion: number;
|
|
18
|
+
type: string;
|
|
19
|
+
bridge: string;
|
|
20
|
+
agent: string;
|
|
21
|
+
senderPolicy: string;
|
|
22
|
+
senderPolicies: {
|
|
23
|
+
sender: string;
|
|
24
|
+
dispatchContextRules?: Record<string, string[]> | undefined;
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { loadSenderPolicies, resolveSenderPoliciesFile } from './pairing.js';
|
|
4
|
+
export function policyTextFromSenderPolicies(senderPolicies) {
|
|
5
|
+
const policies = senderPolicies ?? [];
|
|
6
|
+
const lines = [];
|
|
7
|
+
for (const policy of policies) {
|
|
8
|
+
const sender = policy.sender.trim();
|
|
9
|
+
if (!sender)
|
|
10
|
+
continue;
|
|
11
|
+
lines.push(`allow_from: ${sender}`);
|
|
12
|
+
const contextRules = [];
|
|
13
|
+
for (const [key, values] of Object.entries(policy.dispatchContextRules ?? {})) {
|
|
14
|
+
const normalizedKey = key.trim();
|
|
15
|
+
if (!normalizedKey)
|
|
16
|
+
continue;
|
|
17
|
+
for (const value of values ?? []) {
|
|
18
|
+
const normalizedValue = value.trim();
|
|
19
|
+
if (normalizedValue)
|
|
20
|
+
contextRules.push(`${normalizedKey}=${normalizedValue}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (contextRules.length > 0) {
|
|
24
|
+
lines.push(`context_equals: ${contextRules.join(', ')}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return lines.join('\n');
|
|
28
|
+
}
|
|
29
|
+
export function senderPoliciesFromPolicyText(policyText) {
|
|
30
|
+
const policies = [];
|
|
31
|
+
let activeIndexes = [];
|
|
32
|
+
for (const rawLine of policyText.split(/\r?\n/)) {
|
|
33
|
+
const line = rawLine.trim();
|
|
34
|
+
if (!line || line.startsWith('#'))
|
|
35
|
+
continue;
|
|
36
|
+
const match = /^([a-z_]+)\s*:\s*(.+)$/i.exec(line);
|
|
37
|
+
if (!match?.[1] || !match[2])
|
|
38
|
+
continue;
|
|
39
|
+
const key = match[1].toLowerCase();
|
|
40
|
+
const value = match[2].trim();
|
|
41
|
+
if (key === 'allow_from') {
|
|
42
|
+
activeIndexes = [];
|
|
43
|
+
for (const sender of value.split(',').map((entry) => entry.trim().toLowerCase()).filter(Boolean)) {
|
|
44
|
+
const existingIndex = policies.findIndex((policy) => policy.sender === sender);
|
|
45
|
+
if (existingIndex >= 0) {
|
|
46
|
+
activeIndexes.push(existingIndex);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
activeIndexes.push(policies.push({ sender }) - 1);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (key === 'context_equals') {
|
|
55
|
+
if (activeIndexes.length === 0)
|
|
56
|
+
continue;
|
|
57
|
+
for (const entry of value.split(',')) {
|
|
58
|
+
const [rawContextKey, ...rawContextValueParts] = entry.split('=');
|
|
59
|
+
const contextKey = rawContextKey?.trim().toLowerCase();
|
|
60
|
+
const contextValue = rawContextValueParts.join('=').trim();
|
|
61
|
+
if (!contextKey || !contextValue)
|
|
62
|
+
continue;
|
|
63
|
+
for (const index of activeIndexes) {
|
|
64
|
+
const policy = policies[index];
|
|
65
|
+
if (!policy)
|
|
66
|
+
continue;
|
|
67
|
+
policy.dispatchContextRules = {
|
|
68
|
+
...(policy.dispatchContextRules ?? {}),
|
|
69
|
+
[contextKey]: [
|
|
70
|
+
...(policy.dispatchContextRules?.[contextKey] ?? []),
|
|
71
|
+
contextValue,
|
|
72
|
+
],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return policies.length > 0 ? policies : undefined;
|
|
79
|
+
}
|
|
80
|
+
export function getAgentSenderPolicy(config, agentName) {
|
|
81
|
+
const agent = getAgent(config, agentName);
|
|
82
|
+
const pairedPolicies = loadSenderPolicies(resolveSenderPoliciesFile(agent.senderPoliciesFile, agent.name));
|
|
83
|
+
const senderPolicies = mergeSenderPolicies([
|
|
84
|
+
...(agent.senderPolicies ?? []),
|
|
85
|
+
...pairedPolicies,
|
|
86
|
+
]);
|
|
87
|
+
return {
|
|
88
|
+
schemaVersion: 1,
|
|
89
|
+
type: 'sender-policy.loaded',
|
|
90
|
+
bridge: 'cli-bridge',
|
|
91
|
+
agent: agent.name,
|
|
92
|
+
senderPolicy: policyTextFromSenderPolicies(senderPolicies),
|
|
93
|
+
senderPolicies,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export function setAgentSenderPolicy(config, configPath, agentName, policyText) {
|
|
97
|
+
const nextAgents = config.agents.map((agent) => {
|
|
98
|
+
if (agent.name !== agentName)
|
|
99
|
+
return agent;
|
|
100
|
+
const senderPolicies = senderPoliciesFromPolicyText(policyText);
|
|
101
|
+
const nextAgent = {
|
|
102
|
+
...agent,
|
|
103
|
+
...(senderPolicies ? { senderPolicies } : {}),
|
|
104
|
+
};
|
|
105
|
+
if (!senderPolicies)
|
|
106
|
+
delete nextAgent.senderPolicies;
|
|
107
|
+
delete nextAgent.senderWhitelist;
|
|
108
|
+
return nextAgent;
|
|
109
|
+
});
|
|
110
|
+
if (!config.agents.some((agent) => agent.name === agentName)) {
|
|
111
|
+
throw new Error(`Agent "${agentName}" not found in config`);
|
|
112
|
+
}
|
|
113
|
+
const nextConfig = {
|
|
114
|
+
...config,
|
|
115
|
+
agents: nextAgents,
|
|
116
|
+
};
|
|
117
|
+
mkdirSync(dirname(configPath), { recursive: true });
|
|
118
|
+
writeFileSync(configPath, `${JSON.stringify(nextConfig, null, 2)}\n`);
|
|
119
|
+
return {
|
|
120
|
+
schemaVersion: 1,
|
|
121
|
+
type: 'sender-policy.updated',
|
|
122
|
+
bridge: 'cli-bridge',
|
|
123
|
+
agent: agentName,
|
|
124
|
+
senderPolicy: policyText,
|
|
125
|
+
senderPolicies: senderPoliciesFromPolicyText(policyText) ?? [],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function mergeSenderPolicies(policies) {
|
|
129
|
+
const merged = new Map();
|
|
130
|
+
for (const policy of policies) {
|
|
131
|
+
const sender = policy.sender.trim().toLowerCase();
|
|
132
|
+
if (!sender)
|
|
133
|
+
continue;
|
|
134
|
+
const current = merged.get(sender) ?? { sender };
|
|
135
|
+
for (const [key, values] of Object.entries(policy.dispatchContextRules ?? {})) {
|
|
136
|
+
const normalizedKey = key.trim().toLowerCase();
|
|
137
|
+
if (!normalizedKey)
|
|
138
|
+
continue;
|
|
139
|
+
const currentValues = new Set(current.dispatchContextRules?.[normalizedKey] ?? []);
|
|
140
|
+
for (const value of values ?? []) {
|
|
141
|
+
const normalizedValue = value.trim();
|
|
142
|
+
if (normalizedValue)
|
|
143
|
+
currentValues.add(normalizedValue);
|
|
144
|
+
}
|
|
145
|
+
current.dispatchContextRules = {
|
|
146
|
+
...(current.dispatchContextRules ?? {}),
|
|
147
|
+
[normalizedKey]: [...currentValues],
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
merged.set(sender, current);
|
|
151
|
+
}
|
|
152
|
+
return [...merged.values()];
|
|
153
|
+
}
|
|
154
|
+
function getAgent(config, agentName) {
|
|
155
|
+
const agent = config.agents.find((item) => item.name === agentName);
|
|
156
|
+
if (!agent) {
|
|
157
|
+
throw new Error(`Agent "${agentName}" not found in config`);
|
|
158
|
+
}
|
|
159
|
+
return agent;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=sender-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sender-policy.js","sourceRoot":"","sources":["../src/sender-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAO5E,MAAM,UAAU,4BAA4B,CAAC,cAAwC;IACnF,MAAM,QAAQ,GAAG,cAAc,IAAI,EAAE,CAAA;IACrC,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,KAAK,MAAM,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;QACnC,IAAI,CAAC,MAAM;YAAE,SAAQ;QACrB,KAAK,CAAC,IAAI,CAAC,eAAe,MAAM,EAAE,CAAC,CAAA;QACnC,MAAM,YAAY,GAAa,EAAE,CAAA;QACjC,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,oBAAoB,IAAI,EAAE,CAAC,EAAE,CAAC;YAC9E,MAAM,aAAa,GAAG,GAAG,CAAC,IAAI,EAAE,CAAA;YAChC,IAAI,CAAC,aAAa;gBAAE,SAAQ;YAC5B,KAAK,MAAM,KAAK,IAAI,MAAM,IAAI,EAAE,EAAE,CAAC;gBACjC,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;gBAC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