@dp-pcs/ogp 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/README.md +437 -0
- package/dist/cli/agent-comms.d.ts +55 -0
- package/dist/cli/agent-comms.d.ts.map +1 -0
- package/dist/cli/agent-comms.js +217 -0
- package/dist/cli/agent-comms.js.map +1 -0
- package/dist/cli/expose.d.ts +3 -0
- package/dist/cli/expose.d.ts.map +1 -0
- package/dist/cli/expose.js +104 -0
- package/dist/cli/expose.js.map +1 -0
- package/dist/cli/federation.d.ts +28 -0
- package/dist/cli/federation.d.ts.map +1 -0
- package/dist/cli/federation.js +409 -0
- package/dist/cli/federation.js.map +1 -0
- package/dist/cli/install.d.ts +3 -0
- package/dist/cli/install.d.ts.map +1 -0
- package/dist/cli/install.js +111 -0
- package/dist/cli/install.js.map +1 -0
- package/dist/cli/setup.d.ts +2 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +33 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +305 -0
- package/dist/cli.js.map +1 -0
- package/dist/daemon/agent-comms.d.ts +76 -0
- package/dist/daemon/agent-comms.d.ts.map +1 -0
- package/dist/daemon/agent-comms.js +188 -0
- package/dist/daemon/agent-comms.js.map +1 -0
- package/dist/daemon/doorman.d.ts +52 -0
- package/dist/daemon/doorman.d.ts.map +1 -0
- package/dist/daemon/doorman.js +203 -0
- package/dist/daemon/doorman.js.map +1 -0
- package/dist/daemon/intent-registry.d.ts +11 -0
- package/dist/daemon/intent-registry.d.ts.map +1 -0
- package/dist/daemon/intent-registry.js +101 -0
- package/dist/daemon/intent-registry.js.map +1 -0
- package/dist/daemon/keypair.d.ts +5 -0
- package/dist/daemon/keypair.d.ts.map +1 -0
- package/dist/daemon/keypair.js +25 -0
- package/dist/daemon/keypair.js.map +1 -0
- package/dist/daemon/message-handler.d.ts +20 -0
- package/dist/daemon/message-handler.d.ts.map +1 -0
- package/dist/daemon/message-handler.js +159 -0
- package/dist/daemon/message-handler.js.map +1 -0
- package/dist/daemon/notify.d.ts +7 -0
- package/dist/daemon/notify.d.ts.map +1 -0
- package/dist/daemon/notify.js +54 -0
- package/dist/daemon/notify.js.map +1 -0
- package/dist/daemon/peers.d.ts +66 -0
- package/dist/daemon/peers.d.ts.map +1 -0
- package/dist/daemon/peers.js +171 -0
- package/dist/daemon/peers.js.map +1 -0
- package/dist/daemon/reply-handler.d.ts +67 -0
- package/dist/daemon/reply-handler.d.ts.map +1 -0
- package/dist/daemon/reply-handler.js +176 -0
- package/dist/daemon/reply-handler.js.map +1 -0
- package/dist/daemon/scopes.d.ts +62 -0
- package/dist/daemon/scopes.d.ts.map +1 -0
- package/dist/daemon/scopes.js +113 -0
- package/dist/daemon/scopes.js.map +1 -0
- package/dist/daemon/server.d.ts +8 -0
- package/dist/daemon/server.d.ts.map +1 -0
- package/dist/daemon/server.js +286 -0
- package/dist/daemon/server.js.map +1 -0
- package/dist/shared/config.d.ts +42 -0
- package/dist/shared/config.d.ts.map +1 -0
- package/dist/shared/config.js +42 -0
- package/dist/shared/config.js.map +1 -0
- package/dist/shared/signing.d.ts +13 -0
- package/dist/shared/signing.d.ts.map +1 -0
- package/dist/shared/signing.js +46 -0
- package/dist/shared/signing.js.map +1 -0
- package/docs/agent-comms.md +277 -0
- package/docs/federation-flow.md +407 -0
- package/docs/quickstart.md +241 -0
- package/docs/scopes.md +198 -0
- package/package.json +57 -0
- package/scripts/install-skills.js +32 -0
- package/skills/ogp/SKILL.md +235 -0
- package/skills/ogp-agent-comms/SKILL.md +345 -0
- package/skills/ogp-expose/SKILL.md +281 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { runSetup } from './cli/setup.js';
|
|
4
|
+
import { startServer, stopServer, getDaemonStatus } from './daemon/server.js';
|
|
5
|
+
import { requireConfig, loadConfig } from './shared/config.js';
|
|
6
|
+
import { federationList, federationRequest, federationApprove, federationReject, federationSend, federationShowScopes, federationUpdateGrants, federationSendAgentComms } from './cli/federation.js';
|
|
7
|
+
import { expose, stopExpose } from './cli/expose.js';
|
|
8
|
+
import { installLaunchAgent, uninstallLaunchAgent } from './cli/install.js';
|
|
9
|
+
import { showPolicies, configurePolicies, addTopic, removeTopic, resetPolicy, showActivity, clearActivity, setDefault, setLogging } from './cli/agent-comms.js';
|
|
10
|
+
const program = new Command();
|
|
11
|
+
program
|
|
12
|
+
.name('ogp')
|
|
13
|
+
.description('OGP (Open Gateway Protocol) federation daemon for OpenClaw')
|
|
14
|
+
.version('0.2.0');
|
|
15
|
+
program
|
|
16
|
+
.command('setup')
|
|
17
|
+
.description('Interactive setup wizard')
|
|
18
|
+
.action(async () => {
|
|
19
|
+
await runSetup();
|
|
20
|
+
});
|
|
21
|
+
program
|
|
22
|
+
.command('start')
|
|
23
|
+
.description('Start the OGP daemon')
|
|
24
|
+
.option('-b, --background', 'Run in background')
|
|
25
|
+
.action((options) => {
|
|
26
|
+
const config = requireConfig();
|
|
27
|
+
startServer(config, options.background);
|
|
28
|
+
});
|
|
29
|
+
program
|
|
30
|
+
.command('stop')
|
|
31
|
+
.description('Stop the OGP daemon')
|
|
32
|
+
.action(() => {
|
|
33
|
+
stopServer();
|
|
34
|
+
});
|
|
35
|
+
program
|
|
36
|
+
.command('status')
|
|
37
|
+
.description('Show daemon status')
|
|
38
|
+
.action(() => {
|
|
39
|
+
const status = getDaemonStatus();
|
|
40
|
+
if (status.running) {
|
|
41
|
+
console.log(`Status: Running (PID: ${status.pid})`);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
console.log('Status: Stopped');
|
|
45
|
+
}
|
|
46
|
+
const config = loadConfig();
|
|
47
|
+
if (!config) {
|
|
48
|
+
console.log('\nConfiguration: Not configured (run "ogp setup")');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
console.log('\nConfiguration:');
|
|
52
|
+
console.log(` Daemon port: ${config.daemonPort}`);
|
|
53
|
+
console.log(` OpenClaw URL: ${config.openclawUrl}`);
|
|
54
|
+
console.log(` Gateway URL: ${config.gatewayUrl}`);
|
|
55
|
+
console.log(` Display name: ${config.displayName}`);
|
|
56
|
+
console.log(` Email: ${config.email}`);
|
|
57
|
+
});
|
|
58
|
+
const federation = program
|
|
59
|
+
.command('federation')
|
|
60
|
+
.description('Manage federation');
|
|
61
|
+
federation
|
|
62
|
+
.command('list')
|
|
63
|
+
.description('List all peers')
|
|
64
|
+
.option('-s, --status <status>', 'Filter by status (pending|approved|rejected)')
|
|
65
|
+
.action(async (options) => {
|
|
66
|
+
await federationList(options.status);
|
|
67
|
+
});
|
|
68
|
+
federation
|
|
69
|
+
.command('request')
|
|
70
|
+
.description('Send federation request to a peer')
|
|
71
|
+
.argument('<peer-url>', 'Peer gateway URL')
|
|
72
|
+
.argument('<peer-id>', 'Peer ID')
|
|
73
|
+
.action(async (peerUrl, peerId) => {
|
|
74
|
+
await federationRequest(peerUrl, peerId);
|
|
75
|
+
});
|
|
76
|
+
federation
|
|
77
|
+
.command('approve')
|
|
78
|
+
.description('Approve a pending federation request with optional scope grants')
|
|
79
|
+
.argument('<peer-id>', 'Peer ID')
|
|
80
|
+
.option('--intents <list>', 'Comma-separated intents to grant (e.g., message,agent-comms)')
|
|
81
|
+
.option('--rate <limit>', 'Rate limit as requests/seconds (e.g., 100/3600)')
|
|
82
|
+
.option('--topics <list>', 'Comma-separated topics for agent-comms (e.g., memory-management,task-delegation)')
|
|
83
|
+
.action(async (peerId, options) => {
|
|
84
|
+
const approveOptions = {
|
|
85
|
+
intents: options.intents ? options.intents.split(',').map((s) => s.trim()) : undefined,
|
|
86
|
+
rate: options.rate,
|
|
87
|
+
topics: options.topics ? options.topics.split(',').map((s) => s.trim()) : undefined
|
|
88
|
+
};
|
|
89
|
+
await federationApprove(peerId, approveOptions);
|
|
90
|
+
});
|
|
91
|
+
federation
|
|
92
|
+
.command('reject')
|
|
93
|
+
.description('Reject a pending federation request')
|
|
94
|
+
.argument('<peer-id>', 'Peer ID')
|
|
95
|
+
.action(async (peerId) => {
|
|
96
|
+
await federationReject(peerId);
|
|
97
|
+
});
|
|
98
|
+
federation
|
|
99
|
+
.command('ping')
|
|
100
|
+
.description('Ping a peer gateway to test connectivity')
|
|
101
|
+
.argument('<peer-url>', 'Peer gateway URL')
|
|
102
|
+
.action(async (peerUrl) => {
|
|
103
|
+
try {
|
|
104
|
+
const res = await fetch(`${peerUrl}/federation/ping`);
|
|
105
|
+
if (res.ok) {
|
|
106
|
+
const data = await res.json();
|
|
107
|
+
console.log(`✓ Pong from ${data.displayName} (${data.gatewayUrl})`);
|
|
108
|
+
console.log(` Time: ${data.timestamp}`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
console.error(`✗ Ping failed: ${res.status} ${res.statusText}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
console.error(`✗ Ping failed:`, err);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
federation
|
|
119
|
+
.command('send')
|
|
120
|
+
.description('Send a message to a federated peer')
|
|
121
|
+
.argument('<peer-id>', 'Peer ID')
|
|
122
|
+
.argument('<intent>', 'Intent name')
|
|
123
|
+
.argument('<payload>', 'Payload as JSON string')
|
|
124
|
+
.action(async (peerId, intent, payload) => {
|
|
125
|
+
await federationSend(peerId, intent, payload);
|
|
126
|
+
});
|
|
127
|
+
federation
|
|
128
|
+
.command('scopes')
|
|
129
|
+
.description('Show scope grants for a peer')
|
|
130
|
+
.argument('<peer-id>', 'Peer ID')
|
|
131
|
+
.action(async (peerId) => {
|
|
132
|
+
await federationShowScopes(peerId);
|
|
133
|
+
});
|
|
134
|
+
federation
|
|
135
|
+
.command('grant')
|
|
136
|
+
.description('Update scope grants for an approved peer')
|
|
137
|
+
.argument('<peer-id>', 'Peer ID')
|
|
138
|
+
.option('--intents <list>', 'Comma-separated intents to grant (e.g., message,agent-comms)')
|
|
139
|
+
.option('--rate <limit>', 'Rate limit as requests/seconds (e.g., 100/3600)')
|
|
140
|
+
.option('--topics <list>', 'Comma-separated topics for agent-comms')
|
|
141
|
+
.action(async (peerId, options) => {
|
|
142
|
+
const grantOptions = {
|
|
143
|
+
intents: options.intents ? options.intents.split(',').map((s) => s.trim()) : undefined,
|
|
144
|
+
rate: options.rate,
|
|
145
|
+
topics: options.topics ? options.topics.split(',').map((s) => s.trim()) : undefined
|
|
146
|
+
};
|
|
147
|
+
await federationUpdateGrants(peerId, grantOptions);
|
|
148
|
+
});
|
|
149
|
+
federation
|
|
150
|
+
.command('agent')
|
|
151
|
+
.description('Send an agent-comms message to a peer')
|
|
152
|
+
.argument('<peer-id>', 'Peer ID')
|
|
153
|
+
.argument('<topic>', 'Topic (e.g., memory-management)')
|
|
154
|
+
.argument('<message>', 'Message text')
|
|
155
|
+
.option('-p, --priority <level>', 'Priority (low|normal|high)', 'normal')
|
|
156
|
+
.option('-c, --conversation <id>', 'Conversation ID for threading')
|
|
157
|
+
.option('-w, --wait', 'Wait for reply')
|
|
158
|
+
.option('-t, --timeout <ms>', 'Reply timeout in milliseconds', '30000')
|
|
159
|
+
.action(async (peerId, topic, message, options) => {
|
|
160
|
+
await federationSendAgentComms(peerId, topic, message, {
|
|
161
|
+
priority: options.priority,
|
|
162
|
+
conversationId: options.conversation,
|
|
163
|
+
waitForReply: options.wait,
|
|
164
|
+
replyTimeout: parseInt(options.timeout, 10)
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
program
|
|
168
|
+
.command('expose')
|
|
169
|
+
.description('Expose daemon via tunnel (cloudflared or ngrok)')
|
|
170
|
+
.option('-m, --method <method>', 'Tunnel method (cloudflared|ngrok)', 'cloudflared')
|
|
171
|
+
.option('-b, --background', 'Run in background')
|
|
172
|
+
.action(async (options) => {
|
|
173
|
+
await expose(options.method, options.background);
|
|
174
|
+
});
|
|
175
|
+
program
|
|
176
|
+
.command('expose-stop')
|
|
177
|
+
.description('Stop background tunnel')
|
|
178
|
+
.action(() => {
|
|
179
|
+
stopExpose();
|
|
180
|
+
});
|
|
181
|
+
program
|
|
182
|
+
.command('shutdown')
|
|
183
|
+
.description('Stop both the OGP daemon and tunnel')
|
|
184
|
+
.action(() => {
|
|
185
|
+
console.log('Shutting down OGP...');
|
|
186
|
+
stopExpose();
|
|
187
|
+
stopServer();
|
|
188
|
+
console.log('✓ OGP daemon and tunnel stopped.');
|
|
189
|
+
});
|
|
190
|
+
program
|
|
191
|
+
.command('install')
|
|
192
|
+
.description('Install LaunchAgent to start daemon on login (macOS)')
|
|
193
|
+
.action(async () => {
|
|
194
|
+
await installLaunchAgent();
|
|
195
|
+
});
|
|
196
|
+
program
|
|
197
|
+
.command('uninstall')
|
|
198
|
+
.description('Uninstall LaunchAgent (macOS)')
|
|
199
|
+
.action(async () => {
|
|
200
|
+
await uninstallLaunchAgent();
|
|
201
|
+
});
|
|
202
|
+
program
|
|
203
|
+
.command('config')
|
|
204
|
+
.description('View or update OGP configuration')
|
|
205
|
+
.option('--set <key=value>', 'Set a config value (e.g. --set gatewayUrl=https://xyz.trycloudflare.com)')
|
|
206
|
+
.option('--get <key>', 'Get a config value')
|
|
207
|
+
.action((opts) => {
|
|
208
|
+
const config = loadConfig() || {};
|
|
209
|
+
if (opts.set) {
|
|
210
|
+
const [key, ...rest] = opts.set.split('=');
|
|
211
|
+
const value = rest.join('=');
|
|
212
|
+
config[key] = value;
|
|
213
|
+
const { saveConfig } = require('./shared/config.js');
|
|
214
|
+
saveConfig(config);
|
|
215
|
+
console.log(`✓ Set ${key} = ${value}`);
|
|
216
|
+
}
|
|
217
|
+
else if (opts.get) {
|
|
218
|
+
console.log(config[opts.get] ?? 'not set');
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
console.log(JSON.stringify(config, null, 2));
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
// Agent-comms configuration commands
|
|
225
|
+
const agentComms = program
|
|
226
|
+
.command('agent-comms')
|
|
227
|
+
.description('Configure agent-to-agent communication policies');
|
|
228
|
+
agentComms
|
|
229
|
+
.command('policies')
|
|
230
|
+
.description('Show response policies (global and per-peer)')
|
|
231
|
+
.argument('[peer-id]', 'Optional peer ID to show specific peer policies')
|
|
232
|
+
.action((peerId) => {
|
|
233
|
+
showPolicies(peerId);
|
|
234
|
+
});
|
|
235
|
+
agentComms
|
|
236
|
+
.command('configure')
|
|
237
|
+
.description('Configure response policies for peers or globally')
|
|
238
|
+
.argument('[peer-ids]', 'Comma-separated peer IDs (or use --global)')
|
|
239
|
+
.option('--global', 'Configure global default policies')
|
|
240
|
+
.option('--topics <list>', 'Comma-separated topics to configure')
|
|
241
|
+
.option('--level <level>', 'Response level (full|summary|escalate|deny)')
|
|
242
|
+
.option('--notes <text>', 'Notes about this policy')
|
|
243
|
+
.action((peerIds, options) => {
|
|
244
|
+
configurePolicies(peerIds, {
|
|
245
|
+
global: options.global,
|
|
246
|
+
topics: options.topics,
|
|
247
|
+
level: options.level,
|
|
248
|
+
notes: options.notes
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
agentComms
|
|
252
|
+
.command('add-topic')
|
|
253
|
+
.description('Add a topic to a peer\'s response policy')
|
|
254
|
+
.argument('<peer-id>', 'Peer ID')
|
|
255
|
+
.argument('<topic>', 'Topic name')
|
|
256
|
+
.option('--level <level>', 'Response level (full|summary|escalate|deny)', 'summary')
|
|
257
|
+
.option('--notes <text>', 'Notes about this topic')
|
|
258
|
+
.action((peerId, topic, options) => {
|
|
259
|
+
addTopic(peerId, topic, options.level, options.notes);
|
|
260
|
+
});
|
|
261
|
+
agentComms
|
|
262
|
+
.command('remove-topic')
|
|
263
|
+
.description('Remove a topic from a peer\'s response policy')
|
|
264
|
+
.argument('<peer-id>', 'Peer ID')
|
|
265
|
+
.argument('<topic>', 'Topic name')
|
|
266
|
+
.action((peerId, topic) => {
|
|
267
|
+
removeTopic(peerId, topic);
|
|
268
|
+
});
|
|
269
|
+
agentComms
|
|
270
|
+
.command('reset')
|
|
271
|
+
.description('Reset a peer\'s policy to global defaults')
|
|
272
|
+
.argument('<peer-id>', 'Peer ID')
|
|
273
|
+
.action((peerId) => {
|
|
274
|
+
resetPolicy(peerId);
|
|
275
|
+
});
|
|
276
|
+
agentComms
|
|
277
|
+
.command('activity')
|
|
278
|
+
.description('Show agent-comms activity log')
|
|
279
|
+
.argument('[peer-id]', 'Optional peer ID to filter')
|
|
280
|
+
.option('--last <n>', 'Show last N entries', '50')
|
|
281
|
+
.option('--clear', 'Clear the activity log')
|
|
282
|
+
.action((peerId, options) => {
|
|
283
|
+
if (options.clear) {
|
|
284
|
+
clearActivity();
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
showActivity(peerId, parseInt(options.last, 10));
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
agentComms
|
|
291
|
+
.command('default')
|
|
292
|
+
.description('Set default response level for unknown topics')
|
|
293
|
+
.argument('<level>', 'Response level (full|summary|escalate|deny)')
|
|
294
|
+
.action((level) => {
|
|
295
|
+
setDefault(level);
|
|
296
|
+
});
|
|
297
|
+
agentComms
|
|
298
|
+
.command('logging')
|
|
299
|
+
.description('Enable or disable activity logging')
|
|
300
|
+
.argument('<state>', 'on or off')
|
|
301
|
+
.action((state) => {
|
|
302
|
+
setLogging(state === 'on' || state === 'true' || state === 'enable');
|
|
303
|
+
});
|
|
304
|
+
program.parse();
|
|
305
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe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AAC,UAAU,CAAC;KACnB,WAAW,CAAC,+BAA+B,CAAC;KAC5C,QAAQ,CAAC,WAAW,EAAE,4BAA4B,CAAC;KACnD,MAAM,CAAC,YAAY,EAAE,qBAAqB,EAAE,IAAI,CAAC;KACjD,MAAM,CAAC,SAAS,EAAE,wBAAwB,CAAC;KAC3C,MAAM,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;IAC1B,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,aAAa,EAAE,CAAC;IAClB,CAAC;SAAM,CAAC;QACN,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IACnD,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,UAAU;KACP,OAAO,CAAC,SAAS,CAAC;KAClB,WAAW,CAAC,+CAA+C,CAAC;KAC5D,QAAQ,CAAC,SAAS,EAAE,6CAA6C,CAAC;KAClE,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;IAChB,UAAU,CAAC,KAAsB,CAAC,CAAC;AACrC,CAAC,CAAC,CAAC;AAEL,UAAU;KACP,OAAO,CAAC,SAAS,CAAC;KAClB,WAAW,CAAC,oCAAoC,CAAC;KACjD,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;KAChC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;IAChB,UAAU,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,QAAQ,CAAC,CAAC;AACvE,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OGP Agent-Comms - Response policies and activity logging
|
|
3
|
+
*
|
|
4
|
+
* This module handles:
|
|
5
|
+
* 1. Global and per-peer response policies
|
|
6
|
+
* 2. Activity logging for agent-comms messages
|
|
7
|
+
* 3. Policy resolution (peer-specific overrides global)
|
|
8
|
+
*/
|
|
9
|
+
import { type ResponseLevel, type ResponsePolicy, type TopicPolicy, type AgentCommsConfig } from '../shared/config.js';
|
|
10
|
+
export type { ResponseLevel, ResponsePolicy, TopicPolicy, AgentCommsConfig };
|
|
11
|
+
/**
|
|
12
|
+
* Load agent-comms configuration from main config
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadAgentCommsConfig(): AgentCommsConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Save agent-comms configuration to main config
|
|
17
|
+
*/
|
|
18
|
+
export declare function saveAgentCommsConfig(agentCommsConfig: AgentCommsConfig): void;
|
|
19
|
+
/**
|
|
20
|
+
* Update global policy
|
|
21
|
+
*/
|
|
22
|
+
export declare function updateGlobalPolicy(policy: ResponsePolicy): void;
|
|
23
|
+
/**
|
|
24
|
+
* Set a topic in global policy
|
|
25
|
+
*/
|
|
26
|
+
export declare function setGlobalTopicPolicy(topic: string, level: ResponseLevel, notes?: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Remove a topic from global policy
|
|
29
|
+
*/
|
|
30
|
+
export declare function removeGlobalTopicPolicy(topic: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Set default response level
|
|
33
|
+
*/
|
|
34
|
+
export declare function setDefaultLevel(level: ResponseLevel): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get effective policy for a peer and topic
|
|
37
|
+
* Priority: peer-specific > global > default
|
|
38
|
+
*/
|
|
39
|
+
export declare function getEffectivePolicy(peerId: string, topic: string): TopicPolicy;
|
|
40
|
+
/**
|
|
41
|
+
* Get all effective policies for a peer (merged global + peer-specific)
|
|
42
|
+
*/
|
|
43
|
+
export declare function getAllEffectivePolicies(peerId: string): ResponsePolicy;
|
|
44
|
+
/**
|
|
45
|
+
* Activity log entry
|
|
46
|
+
*/
|
|
47
|
+
export interface ActivityEntry {
|
|
48
|
+
timestamp: string;
|
|
49
|
+
direction: 'in' | 'out';
|
|
50
|
+
peerId: string;
|
|
51
|
+
peerName: string;
|
|
52
|
+
topic: string;
|
|
53
|
+
message: string;
|
|
54
|
+
level?: ResponseLevel;
|
|
55
|
+
truncated?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Log an activity entry
|
|
59
|
+
*/
|
|
60
|
+
export declare function logActivity(entry: Omit<ActivityEntry, 'timestamp'>): void;
|
|
61
|
+
/**
|
|
62
|
+
* Read activity log entries
|
|
63
|
+
*/
|
|
64
|
+
export declare function readActivityLog(options?: {
|
|
65
|
+
peerId?: string;
|
|
66
|
+
last?: number;
|
|
67
|
+
}): string[];
|
|
68
|
+
/**
|
|
69
|
+
* Clear activity log
|
|
70
|
+
*/
|
|
71
|
+
export declare function clearActivityLog(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Enable/disable activity logging
|
|
74
|
+
*/
|
|
75
|
+
export declare function setActivityLogging(enabled: boolean): void;
|
|
76
|
+
//# sourceMappingURL=agent-comms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-comms.d.ts","sourceRoot":"","sources":["../../src/daemon/agent-comms.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EAEtB,MAAM,qBAAqB,CAAC;AAO7B,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,gBAAgB,EAAE,CAAC;AAW7E;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,gBAAgB,CAIvD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,CAQ7E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAI/D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAI9F;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAI3D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAI1D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,CAgB7E;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAetE;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,IAAI,GAAG,KAAK,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,GAAG,IAAI,CA8BzE;AAkBD;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,MAAM,EAAE,CAkBX;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAIvC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAIzD"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OGP Agent-Comms - Response policies and activity logging
|
|
3
|
+
*
|
|
4
|
+
* This module handles:
|
|
5
|
+
* 1. Global and per-peer response policies
|
|
6
|
+
* 2. Activity logging for agent-comms messages
|
|
7
|
+
* 3. Policy resolution (peer-specific overrides global)
|
|
8
|
+
*/
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { getConfigDir, ensureConfigDir, loadConfig, saveConfig } from '../shared/config.js';
|
|
12
|
+
import { getPeer } from './peers.js';
|
|
13
|
+
const ACTIVITY_LOG_FILE = path.join(getConfigDir(), 'activity.log');
|
|
14
|
+
const MAX_LOG_LINES = 1000;
|
|
15
|
+
const DEFAULT_AGENT_COMMS_CONFIG = {
|
|
16
|
+
globalPolicy: {
|
|
17
|
+
'general': { level: 'summary' },
|
|
18
|
+
'testing': { level: 'full' }
|
|
19
|
+
},
|
|
20
|
+
defaultLevel: 'summary',
|
|
21
|
+
activityLog: true
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Load agent-comms configuration from main config
|
|
25
|
+
*/
|
|
26
|
+
export function loadAgentCommsConfig() {
|
|
27
|
+
const config = loadConfig();
|
|
28
|
+
if (!config)
|
|
29
|
+
return DEFAULT_AGENT_COMMS_CONFIG;
|
|
30
|
+
return config.agentComms || DEFAULT_AGENT_COMMS_CONFIG;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Save agent-comms configuration to main config
|
|
34
|
+
*/
|
|
35
|
+
export function saveAgentCommsConfig(agentCommsConfig) {
|
|
36
|
+
const config = loadConfig();
|
|
37
|
+
if (!config) {
|
|
38
|
+
console.error('No config found. Run "ogp setup" first.');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
config.agentComms = agentCommsConfig;
|
|
42
|
+
saveConfig(config);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Update global policy
|
|
46
|
+
*/
|
|
47
|
+
export function updateGlobalPolicy(policy) {
|
|
48
|
+
const config = loadAgentCommsConfig();
|
|
49
|
+
config.globalPolicy = { ...config.globalPolicy, ...policy };
|
|
50
|
+
saveAgentCommsConfig(config);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Set a topic in global policy
|
|
54
|
+
*/
|
|
55
|
+
export function setGlobalTopicPolicy(topic, level, notes) {
|
|
56
|
+
const config = loadAgentCommsConfig();
|
|
57
|
+
config.globalPolicy[topic] = { level, ...(notes && { notes }) };
|
|
58
|
+
saveAgentCommsConfig(config);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Remove a topic from global policy
|
|
62
|
+
*/
|
|
63
|
+
export function removeGlobalTopicPolicy(topic) {
|
|
64
|
+
const config = loadAgentCommsConfig();
|
|
65
|
+
delete config.globalPolicy[topic];
|
|
66
|
+
saveAgentCommsConfig(config);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Set default response level
|
|
70
|
+
*/
|
|
71
|
+
export function setDefaultLevel(level) {
|
|
72
|
+
const config = loadAgentCommsConfig();
|
|
73
|
+
config.defaultLevel = level;
|
|
74
|
+
saveAgentCommsConfig(config);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get effective policy for a peer and topic
|
|
78
|
+
* Priority: peer-specific > global > default
|
|
79
|
+
*/
|
|
80
|
+
export function getEffectivePolicy(peerId, topic) {
|
|
81
|
+
const config = loadAgentCommsConfig();
|
|
82
|
+
const peer = getPeer(peerId);
|
|
83
|
+
// Check peer-specific policy first
|
|
84
|
+
if (peer?.responsePolicy?.[topic]) {
|
|
85
|
+
return peer.responsePolicy[topic];
|
|
86
|
+
}
|
|
87
|
+
// Fall back to global policy
|
|
88
|
+
if (config.globalPolicy[topic]) {
|
|
89
|
+
return config.globalPolicy[topic];
|
|
90
|
+
}
|
|
91
|
+
// Fall back to default level
|
|
92
|
+
return { level: config.defaultLevel };
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get all effective policies for a peer (merged global + peer-specific)
|
|
96
|
+
*/
|
|
97
|
+
export function getAllEffectivePolicies(peerId) {
|
|
98
|
+
const config = loadAgentCommsConfig();
|
|
99
|
+
const peer = getPeer(peerId);
|
|
100
|
+
// Start with global policies
|
|
101
|
+
const effective = { ...config.globalPolicy };
|
|
102
|
+
// Override with peer-specific policies
|
|
103
|
+
if (peer?.responsePolicy) {
|
|
104
|
+
for (const [topic, policy] of Object.entries(peer.responsePolicy)) {
|
|
105
|
+
effective[topic] = policy;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return effective;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Log an activity entry
|
|
112
|
+
*/
|
|
113
|
+
export function logActivity(entry) {
|
|
114
|
+
const config = loadAgentCommsConfig();
|
|
115
|
+
if (!config.activityLog)
|
|
116
|
+
return;
|
|
117
|
+
ensureConfigDir();
|
|
118
|
+
const fullEntry = {
|
|
119
|
+
timestamp: new Date().toISOString(),
|
|
120
|
+
...entry
|
|
121
|
+
};
|
|
122
|
+
// Truncate message for logging
|
|
123
|
+
const maxMsgLen = 100;
|
|
124
|
+
let msgPreview = entry.message;
|
|
125
|
+
if (msgPreview.length > maxMsgLen) {
|
|
126
|
+
msgPreview = msgPreview.substring(0, maxMsgLen) + '...';
|
|
127
|
+
fullEntry.truncated = true;
|
|
128
|
+
}
|
|
129
|
+
// Format log line
|
|
130
|
+
const dirSymbol = entry.direction === 'in' ? '[IN] ' : '[OUT]';
|
|
131
|
+
const arrow = entry.direction === 'in' ? '→' : '←';
|
|
132
|
+
const levelTag = entry.level ? ` [${entry.level.toUpperCase()}]` : '';
|
|
133
|
+
const logLine = `${fullEntry.timestamp} ${dirSymbol} ${entry.peerName} ${arrow} ${entry.topic}:${levelTag} ${msgPreview}\n`;
|
|
134
|
+
// Append to log file
|
|
135
|
+
fs.appendFileSync(ACTIVITY_LOG_FILE, logLine, 'utf-8');
|
|
136
|
+
// Rotate if too large
|
|
137
|
+
rotateActivityLog();
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Rotate activity log if it exceeds max lines
|
|
141
|
+
*/
|
|
142
|
+
function rotateActivityLog() {
|
|
143
|
+
if (!fs.existsSync(ACTIVITY_LOG_FILE))
|
|
144
|
+
return;
|
|
145
|
+
const content = fs.readFileSync(ACTIVITY_LOG_FILE, 'utf-8');
|
|
146
|
+
const lines = content.split('\n').filter(l => l.trim());
|
|
147
|
+
if (lines.length > MAX_LOG_LINES) {
|
|
148
|
+
// Keep only the last MAX_LOG_LINES entries
|
|
149
|
+
const trimmed = lines.slice(-MAX_LOG_LINES).join('\n') + '\n';
|
|
150
|
+
fs.writeFileSync(ACTIVITY_LOG_FILE, trimmed, 'utf-8');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Read activity log entries
|
|
155
|
+
*/
|
|
156
|
+
export function readActivityLog(options) {
|
|
157
|
+
if (!fs.existsSync(ACTIVITY_LOG_FILE))
|
|
158
|
+
return [];
|
|
159
|
+
const content = fs.readFileSync(ACTIVITY_LOG_FILE, 'utf-8');
|
|
160
|
+
let lines = content.split('\n').filter(l => l.trim());
|
|
161
|
+
// Filter by peer if specified
|
|
162
|
+
if (options?.peerId) {
|
|
163
|
+
const peerId = options.peerId;
|
|
164
|
+
lines = lines.filter(l => l.includes(peerId));
|
|
165
|
+
}
|
|
166
|
+
// Limit to last N entries
|
|
167
|
+
if (options?.last && options.last > 0) {
|
|
168
|
+
lines = lines.slice(-options.last);
|
|
169
|
+
}
|
|
170
|
+
return lines;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Clear activity log
|
|
174
|
+
*/
|
|
175
|
+
export function clearActivityLog() {
|
|
176
|
+
if (fs.existsSync(ACTIVITY_LOG_FILE)) {
|
|
177
|
+
fs.unlinkSync(ACTIVITY_LOG_FILE);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Enable/disable activity logging
|
|
182
|
+
*/
|
|
183
|
+
export function setActivityLogging(enabled) {
|
|
184
|
+
const config = loadAgentCommsConfig();
|
|
185
|
+
config.activityLog = enabled;
|
|
186
|
+
saveAgentCommsConfig(config);
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=agent-comms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-comms.js","sourceRoot":"","sources":["../../src/daemon/agent-comms.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,YAAY,EACZ,eAAe,EACf,UAAU,EACV,UAAU,EAMX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,cAAc,CAAC,CAAC;AACpE,MAAM,aAAa,GAAG,IAAI,CAAC;AAK3B,MAAM,0BAA0B,GAAqB;IACnD,YAAY,EAAE;QACZ,SAAS,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE;QAC/B,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;KAC7B;IACD,YAAY,EAAE,SAAS;IACvB,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,IAAI,CAAC,MAAM;QAAE,OAAO,0BAA0B,CAAC;IAC/C,OAAO,MAAM,CAAC,UAAU,IAAI,0BAA0B,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,gBAAkC;IACrE,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;QACzD,OAAO;IACT,CAAC;IACD,MAAM,CAAC,UAAU,GAAG,gBAAgB,CAAC;IACrC,UAAU,CAAC,MAAM,CAAC,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAA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,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OGP Doorman - Runtime scope enforcement and rate limiting
|
|
3
|
+
*
|
|
4
|
+
* The doorman sits at Layer 3 of the scope model:
|
|
5
|
+
* Layer 1: Gateway Capabilities - What I CAN support
|
|
6
|
+
* Layer 2: Peer Negotiation - What I WILL grant YOU
|
|
7
|
+
* Layer 3: Runtime Enforcement - Is THIS request within YOUR granted scope (doorman)
|
|
8
|
+
*/
|
|
9
|
+
import { type RateLimit } from './scopes.js';
|
|
10
|
+
export interface DoormanResult {
|
|
11
|
+
allowed: boolean;
|
|
12
|
+
reason?: string;
|
|
13
|
+
statusCode?: number;
|
|
14
|
+
retryAfter?: number;
|
|
15
|
+
isV1Peer?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Start the periodic cleanup of expired rate limit entries
|
|
19
|
+
*/
|
|
20
|
+
export declare function startDoormanCleanup(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Stop the periodic cleanup
|
|
23
|
+
*/
|
|
24
|
+
export declare function stopDoormanCleanup(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Check if a request from a peer is allowed
|
|
27
|
+
*
|
|
28
|
+
* @param peerId - The peer making the request
|
|
29
|
+
* @param intent - The intent being requested
|
|
30
|
+
* @param payload - Optional payload with topic for agent-comms
|
|
31
|
+
* @returns DoormanResult indicating if request is allowed
|
|
32
|
+
*/
|
|
33
|
+
export declare function checkAccess(peerId: string, intent: string, payload?: {
|
|
34
|
+
topic?: string;
|
|
35
|
+
}): DoormanResult;
|
|
36
|
+
/**
|
|
37
|
+
* Get current rate limit status for a peer+intent
|
|
38
|
+
*/
|
|
39
|
+
export declare function getRateLimitStatus(peerId: string, intent: string, limit: RateLimit): {
|
|
40
|
+
used: number;
|
|
41
|
+
remaining: number;
|
|
42
|
+
windowSeconds: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Reset rate limit for a specific peer+intent (for testing)
|
|
46
|
+
*/
|
|
47
|
+
export declare function resetRateLimit(peerId: string, intent: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Reset all rate limits (for testing)
|
|
50
|
+
*/
|
|
51
|
+
export declare function resetAllRateLimits(): void;
|
|
52
|
+
//# sourceMappingURL=doorman.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doorman.d.ts","sourceRoot":"","sources":["../../src/daemon/doorman.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAGL,KAAK,SAAS,EAKf,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAeD;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAG1C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAKzC;AAeD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3B,aAAa,CAkFf;AA+CD;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,SAAS,GACf;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAuB5D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAGnE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC"}
|