@ours.network/fleet 1.2.0-nightly.57 → 1.2.0-nightly.59

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.
@@ -1,113 +0,0 @@
1
- const object = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
2
- const parse = (line) => { try {
3
- const v = JSON.parse(line);
4
- return object(v) ? v : undefined;
5
- }
6
- catch {
7
- return undefined;
8
- } };
9
- export class CodexFileInventory {
10
- sendToCodex;
11
- emitToClient;
12
- checks = new Map();
13
- sequence = 0;
14
- constructor(sendToCodex, emitToClient) {
15
- this.sendToCodex = sendToCodex;
16
- this.emitToClient = emitToClient;
17
- }
18
- /** Hold only a turn/start; unrelated tools/configuration are preserved. */
19
- observeClientLine(line) {
20
- const message = parse(line);
21
- if (message?.method !== 'turn/start')
22
- return true;
23
- const threadId = object(message.params) ? message.params.threadId : undefined;
24
- if (typeof threadId !== 'string' || !threadId || message.id === undefined || this.checks.size >= 8) {
25
- this.reject(message);
26
- return false;
27
- }
28
- const check = { request: message, threadId, servers: [], cursors: new Set(), timer: setTimeout(() => {
29
- for (const [id, c] of this.checks)
30
- if (c === check)
31
- this.checks.delete(id);
32
- this.reject(message);
33
- }, 30_000) };
34
- this.query(check);
35
- return false;
36
- }
37
- observeServerLine(line) {
38
- const message = parse(line), id = message?.id;
39
- if (typeof id !== 'string')
40
- return true;
41
- const check = this.checks.get(id);
42
- if (!check)
43
- return true;
44
- this.checks.delete(id);
45
- const result = message?.result;
46
- if (!object(result) || !Array.isArray(result.data) || result.data.some(s => !object(s)) || check.servers.length + result.data.length > 1000) {
47
- this.finish(check, false);
48
- return false;
49
- }
50
- check.servers.push(...result.data);
51
- if (result.nextCursor !== null) {
52
- const cursor = result.nextCursor;
53
- if (typeof cursor !== 'string' || !cursor || check.cursors.has(cursor) || check.cursors.size >= 10)
54
- this.finish(check, false);
55
- else {
56
- check.cursors.add(cursor);
57
- this.query(check, cursor);
58
- }
59
- return false;
60
- }
61
- this.finish(check, this.qualified(check.servers));
62
- return false;
63
- }
64
- close() { for (const c of this.checks.values())
65
- clearTimeout(c.timer); this.checks.clear(); }
66
- query(check, cursor) {
67
- const id = `ours-fleet-file-inventory-${++this.sequence}`;
68
- this.checks.set(id, check);
69
- this.sendToCodex(JSON.stringify({ id, method: 'mcpServerStatus/list', params: { threadId: check.threadId, detail: 'full', limit: 100, ...(cursor ? { cursor } : {}) } }));
70
- }
71
- qualified(servers) {
72
- let managed = 0;
73
- for (const server of servers) {
74
- // Unknown or failed discovery cannot establish absence of another connector.
75
- if (server.toolsError !== null || !object(server.tools))
76
- return false;
77
- if (!object(server.serverInfo) || typeof server.serverInfo.name !== 'string')
78
- return false;
79
- const tools = Object.values(server.tools).filter(object);
80
- const names = new Set(tools.map(t => t.name));
81
- if (server.name !== 'ours') {
82
- if (server.serverInfo.name === 'ours')
83
- return false;
84
- if (tools.some(t => t.name === 'send_file' && object(t.inputSchema) && object(t.inputSchema.properties) && 'contact' in t.inputSchema.properties))
85
- return false;
86
- if (names.has('current_identity') && names.has('send_file') && names.has('get_messages'))
87
- return false;
88
- continue;
89
- }
90
- managed++;
91
- if (server.serverInfo.name !== 'ours' || server.runtimeStatus !== 'connected')
92
- return false;
93
- const files = tools.filter(t => t.name === 'send_file');
94
- if (files.length !== 1 || !object(files[0].inputSchema))
95
- return false;
96
- const schema = files[0].inputSchema;
97
- if (!object(schema.properties) || !object(schema.properties.contact) || schema.additionalProperties !== false
98
- || (Array.isArray(schema.required) && schema.required.includes('contact')))
99
- return false;
100
- }
101
- return managed === 1;
102
- }
103
- finish(check, allowed) {
104
- clearTimeout(check.timer);
105
- if (allowed)
106
- this.sendToCodex(JSON.stringify(check.request));
107
- else
108
- this.reject(check.request);
109
- }
110
- reject(request) {
111
- this.emitToClient(JSON.stringify({ id: request.id, error: { code: -32000, message: 'CURRENT_CHAT_DELIVERY_UNAVAILABLE: unqualified MCP inventory' } }));
112
- }
113
- }