agents-city 0.4.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.es.md +240 -11
  3. package/README.md +238 -11
  4. package/benchmarks/latency/fake-claude-cli.mjs +2 -1
  5. package/benchmarks/reception/README.md +16 -0
  6. package/benchmarks/reception/run.mjs +84 -0
  7. package/bin/agents-city.js +1 -0
  8. package/bin/connect +5 -0
  9. package/bin/hall.html +117 -18
  10. package/bin/navegador.mjs +170 -1
  11. package/bin/serve.py +201 -101
  12. package/bin/test +15 -3
  13. package/bin/test-arnes.py +192 -0
  14. package/bin/test-cage.py +9 -0
  15. package/bin/test-channel.py +178 -12
  16. package/bin/test-claude-runtime.py +132 -4
  17. package/bin/test-connect-client.mjs +609 -0
  18. package/bin/test-connect.py +52 -0
  19. package/bin/test-contracts.py +214 -0
  20. package/bin/test-diario.py +185 -0
  21. package/bin/test-doctor.py +31 -0
  22. package/bin/test-i18n.py +189 -0
  23. package/bin/test-navegador.py +61 -0
  24. package/bin/test-seat.py +78 -20
  25. package/bin/test-security.py +2 -0
  26. package/bin/test-serve.py +366 -0
  27. package/city/web/dist-hall/hall.js +789 -214
  28. package/city/web/src/bienvenida.ts +14 -13
  29. package/city/web/src/casa.ts +143 -56
  30. package/city/web/src/demo.ts +61 -31
  31. package/city/web/src/es.ts +187 -27
  32. package/city/web/src/explorador.ts +70 -43
  33. package/city/web/src/hall.ts +520 -103
  34. package/city/web/src/idioma.ts +21 -1
  35. package/city/web/src/motores.ts +48 -1
  36. package/city/web/src/vista.ts +58 -0
  37. package/demo/graba.py +5 -10
  38. package/docs/managed-connect.md +237 -0
  39. package/docs/security.md +41 -2
  40. package/package.json +8 -4
  41. package/plugin/.claude-plugin/plugin.json +1 -1
  42. package/plugin/channel/adapter-prompts.ts +10 -0
  43. package/plugin/channel/adapter.js +78 -31
  44. package/plugin/channel/agents_city_hybrid_crypto_bg.wasm +0 -0
  45. package/plugin/channel/bus.js +109 -65
  46. package/plugin/channel/bus.ts +11 -1
  47. package/plugin/channel/client.js +67 -30
  48. package/plugin/channel/delivery-queue.ts +160 -21
  49. package/plugin/channel/hub/remote-roads.ts +32 -1
  50. package/plugin/channel/hub/road-controller.ts +116 -16
  51. package/plugin/channel/kinsh_vodozemac_wasm_bg.wasm +0 -0
  52. package/plugin/channel/licenses/CONNECT_CLIENT_THIRD_PARTY_NOTICES.md +21 -0
  53. package/plugin/channel/licenses/HYBRID_CRYPTO_THIRD_PARTY_NOTICES.md +12 -0
  54. package/plugin/channel/licenses/hybrid-crypto-Apache-2.0.txt +201 -0
  55. package/plugin/channel/licenses/keyring-MIT.txt +21 -0
  56. package/plugin/channel/licenses/vodozemac-Apache-2.0.txt +201 -0
  57. package/plugin/channel/local-hub.js +2080 -97
  58. package/plugin/channel/local-hub.ts +5 -4
  59. package/plugin/channel/managed-connect/bridge.ts +208 -0
  60. package/plugin/channel/managed-connect/cli.ts +416 -0
  61. package/plugin/channel/managed-connect/device.ts +15 -0
  62. package/plugin/channel/managed-connect/local-cities.ts +94 -0
  63. package/plugin/channel/managed-connect/person-message.ts +74 -0
  64. package/plugin/channel/managed-connect/reception-bridge.ts +341 -0
  65. package/plugin/channel/managed-connect/relay-session.ts +7 -0
  66. package/plugin/channel/managed-connect/storage.ts +653 -0
  67. package/plugin/channel/managed-connect/transport.ts +87 -0
  68. package/plugin/channel/managed-connect-cli.js +4777 -0
  69. package/plugin/channel/managed-connect-cli.ts +7 -0
  70. package/plugin/channel/managed-connect-client.d.ts +261 -0
  71. package/plugin/channel/managed-connect-client.js +6572 -0
  72. package/plugin/channel/managed-connect-client.manifest.json +38 -0
  73. package/plugin/channel/package-lock.json +123 -105
  74. package/plugin/channel/package.json +4 -4
  75. package/plugin/channel/protocol.ts +4 -0
  76. package/plugin/channel/reception.ts +896 -0
  77. package/plugin/channel/road-cli.ts +1 -1
  78. package/plugin/channel/runtime/arnes.json +189 -0
  79. package/plugin/channel/runtime/arnes.ts +47 -0
  80. package/plugin/channel/runtime/claude.ts +18 -0
  81. package/plugin/channel/runtime/codex-config.ts +51 -1
  82. package/plugin/channel/runtime/codex.ts +31 -11
  83. package/plugin/channel/runtime/kimi.ts +6 -4
  84. package/plugin/channel/runtime-files.ts +39 -5
  85. package/plugin/channel/runtime-gateway.js +426 -100
  86. package/plugin/channel/runtime-gateway.ts +12 -0
  87. package/plugin/channel/trust/agents-city-sandbox-roots.json +66 -0
  88. package/plugin/scripts/arnes.py +271 -0
  89. package/plugin/scripts/busca.py +46 -10
  90. package/plugin/scripts/cage.py +5 -0
  91. package/plugin/scripts/city-session.sh +144 -28
  92. package/plugin/scripts/crecimiento.py +4 -1
  93. package/plugin/scripts/demos.py +58 -43
  94. package/plugin/scripts/desinstala.py +36 -21
  95. package/plugin/scripts/diario.py +119 -0
  96. package/plugin/scripts/doctor.py +90 -15
  97. package/plugin/scripts/read-card.py +48 -8
  98. package/plugin/scripts/reception.py +665 -0
@@ -0,0 +1,87 @@
1
+ import WebSocket, { type RawData } from 'ws';
2
+ import {
3
+ ManagedRelaySession,
4
+ initializeHybridCrypto,
5
+ signedRelayHeaders,
6
+ type DeviceIdentity,
7
+ type RelaySessionOptions,
8
+ type RelayTransport,
9
+ } from '../managed-connect-client.js';
10
+
11
+ const CITY_ADDRESS_RE = /^[a-z0-9][a-z0-9_-]{0,31}\/[a-z0-9][a-z0-9_-]{0,31}$/;
12
+ const MAX_SERVER_FRAME_BYTES = 262_144;
13
+
14
+ export type OpenManagedSession = {
15
+ session: ManagedRelaySession;
16
+ socket: WebSocket;
17
+ };
18
+
19
+ export async function openManagedRelaySession(
20
+ identity: DeviceIdentity,
21
+ city: string,
22
+ options: RelaySessionOptions,
23
+ ): Promise<OpenManagedSession> {
24
+ if (!CITY_ADDRESS_RE.test(city)) throw new Error('invalid_city_address');
25
+ if (!options.keyTransparency) throw new Error('key_transparency_required');
26
+ await initializeHybridCrypto();
27
+ const headers = await signedRelayHeaders(identity, city);
28
+ const url = new URL(identity.relayUrl);
29
+ const local = ['127.0.0.1', 'localhost', '[::1]', '::1'].includes(url.hostname);
30
+ if (
31
+ (url.protocol !== 'wss:' && !(local && url.protocol === 'ws:')) ||
32
+ url.pathname !== '/v1/connect' ||
33
+ url.username ||
34
+ url.password ||
35
+ url.search ||
36
+ url.hash
37
+ )
38
+ throw new Error('invalid_relay_url');
39
+ url.searchParams.set('city', city);
40
+ const socket = new WebSocket(url, {
41
+ headers,
42
+ handshakeTimeout: 10_000,
43
+ maxPayload: MAX_SERVER_FRAME_BYTES,
44
+ perMessageDeflate: false,
45
+ followRedirects: false,
46
+ });
47
+ socket.on('error', () => {});
48
+ const transport: RelayTransport = {
49
+ send: (raw) => {
50
+ if (socket.readyState !== WebSocket.OPEN) throw new Error('relay_connection_closed');
51
+ socket.send(raw);
52
+ },
53
+ close: (code, reason) => socket.close(code, reason),
54
+ onMessage: (handler) => {
55
+ socket.on('message', (raw: RawData, isBinary: boolean) => {
56
+ handler(isBinary ? '' : String(raw));
57
+ });
58
+ },
59
+ onClose: (handler) => {
60
+ socket.on('close', handler);
61
+ },
62
+ };
63
+ const session = new ManagedRelaySession(identity, city, transport, {
64
+ ...options,
65
+ sealedSender: options.sealedSender ?? {},
66
+ });
67
+ try {
68
+ await new Promise<void>((resolve, reject) => {
69
+ const timer = setTimeout(() => reject(new Error('relay_connection_timeout')), 10_000);
70
+ socket.once('open', () => {
71
+ clearTimeout(timer);
72
+ resolve();
73
+ });
74
+ socket.once('error', () => {
75
+ clearTimeout(timer);
76
+ reject(new Error('relay_connection_failed'));
77
+ });
78
+ });
79
+ await session.ready();
80
+ return { session, socket };
81
+ } catch (error) {
82
+ try {
83
+ socket.close(1000, 'connection failed');
84
+ } catch {}
85
+ throw error;
86
+ }
87
+ }