@sw4rm/js-sdk 0.3.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 +159 -0
- package/dist/cjs/index.cjs +11263 -0
- package/dist/esm/index.js +11194 -0
- package/dist/types/clients/activity.d.ts +13 -0
- package/dist/types/clients/connector.d.ts +31 -0
- package/dist/types/clients/hitl.d.ts +17 -0
- package/dist/types/clients/logging.d.ts +18 -0
- package/dist/types/clients/negotiation.d.ts +53 -0
- package/dist/types/clients/reasoning.d.ts +13 -0
- package/dist/types/clients/registry.d.ts +21 -0
- package/dist/types/clients/router.d.ts +15 -0
- package/dist/types/clients/scheduler.d.ts +61 -0
- package/dist/types/clients/schedulerPolicy.d.ts +31 -0
- package/dist/types/clients/tool.d.ts +50 -0
- package/dist/types/clients/worktree.d.ts +25 -0
- package/dist/types/index.d.ts +41 -0
- package/dist/types/internal/ack.d.ts +13 -0
- package/dist/types/internal/baseClient.d.ts +33 -0
- package/dist/types/internal/control.d.ts +22 -0
- package/dist/types/internal/envelope.d.ts +53 -0
- package/dist/types/internal/errorMapper.d.ts +13 -0
- package/dist/types/internal/errorMapping.d.ts +27 -0
- package/dist/types/internal/idempotency.d.ts +6 -0
- package/dist/types/internal/ids.d.ts +1 -0
- package/dist/types/internal/interceptors.d.ts +25 -0
- package/dist/types/internal/runtime/ackLifecycle.d.ts +25 -0
- package/dist/types/internal/runtime/activityBuffer.d.ts +31 -0
- package/dist/types/internal/runtime/messageProcessor.d.ts +32 -0
- package/dist/types/internal/time.d.ts +6 -0
- package/dist/types/internal/worktreePolicy.d.ts +15 -0
- package/dist/types/internal/worktreeState.d.ts +14 -0
- package/dist/types/persistence/persistence.d.ts +17 -0
- package/dist/types/runtime/ackHelpers.d.ts +17 -0
- package/dist/types/runtime/activitySync.d.ts +9 -0
- package/dist/types/runtime/negotiationEvents.d.ts +48 -0
- package/dist/types/runtime/persistenceAdapter.d.ts +19 -0
- package/dist/types/runtime/streams.d.ts +8 -0
- package/dist/types/secrets/backend.d.ts +13 -0
- package/dist/types/secrets/backends/file.d.ts +12 -0
- package/dist/types/secrets/backends/keyring.d.ts +12 -0
- package/dist/types/secrets/errors.d.ts +13 -0
- package/dist/types/secrets/factory.d.ts +3 -0
- package/dist/types/secrets/resolver.d.ts +11 -0
- package/dist/types/secrets/types.d.ts +21 -0
- package/package.json +81 -0
package/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# SW4RM JavaScript SDK
|
|
2
|
+
|
|
3
|
+
Reference JavaScript SDK for the SW4RM Agentic Protocol. This is one of three SDKs in this repository (Python, Rust, JavaScript). 🚧 Under development: initial implementation includes a basic RegistryClient and core utilities.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @sw4rm/js-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start with Working Services
|
|
12
|
+
|
|
13
|
+
🎉 **NEW**: Complete working example with services included! You can now run a full SW4RM setup locally.
|
|
14
|
+
|
|
15
|
+
### 1. Start the Services
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
cd ../../examples/reference-services/
|
|
19
|
+
./start_services_local.sh
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 2. Test the Setup
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Test the complete setup
|
|
26
|
+
python test_complete_setup.py
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 3. Run JavaScript Examples
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
cd ../../examples/sdk-usage/
|
|
33
|
+
npm install
|
|
34
|
+
npm run register_agent # Register an agent
|
|
35
|
+
npm run router_send_receive # Send and receive messages
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
You should see successful agent registration and message routing!
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { RegistryClient, AgentState, CommunicationClass } from '@sw4rm/js-sdk';
|
|
44
|
+
|
|
45
|
+
const client = new RegistryClient('localhost:50051');
|
|
46
|
+
|
|
47
|
+
// Register agent
|
|
48
|
+
await client.registerAgent({
|
|
49
|
+
agent_id: 'my-agent',
|
|
50
|
+
name: 'My Agent',
|
|
51
|
+
description: 'Example agent implementation',
|
|
52
|
+
capabilities: ['example'],
|
|
53
|
+
communication_class: CommunicationClass.STANDARD,
|
|
54
|
+
modalities_supported: ['application/json'],
|
|
55
|
+
reasoning_connectors: ['http://localhost:8080'],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Send heartbeat
|
|
59
|
+
await client.heartbeat('my-agent', AgentState.RUNNING);
|
|
60
|
+
|
|
61
|
+
// Deregister
|
|
62
|
+
await client.deregisterAgent('my-agent', 'Done');
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Implementation Status
|
|
66
|
+
|
|
67
|
+
- ✅ Base gRPC client infrastructure
|
|
68
|
+
- ✅ RegistryClient (agent registration, heartbeat, deregistration)
|
|
69
|
+
- ✅ TypeScript type definitions
|
|
70
|
+
- ✅ Unit tests
|
|
71
|
+
- ⏳ Additional service clients (planned)
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|
|
76
|
+
## Builds
|
|
77
|
+
|
|
78
|
+
This package ships dual builds for maximum compatibility:
|
|
79
|
+
|
|
80
|
+
- ESM: `dist/esm` (modern Node, bundlers)
|
|
81
|
+
- CommonJS: `dist/cjs` (require)
|
|
82
|
+
- Types: `dist/types` for TypeScript and editors
|
|
83
|
+
|
|
84
|
+
## Usage
|
|
85
|
+
|
|
86
|
+
JavaScript (CommonJS):
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
const { RouterClient, buildEnvelope, MessageType } = require('@sw4rm/js-sdk');
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
ESM/TypeScript:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { RouterClient, buildEnvelope, MessageType } from '@sw4rm/js-sdk';
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Quick example: route + ACK
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { RouterClient, buildEnvelope, MessageType, ACKLifecycleManager, createResilientIncomingStream, sendMessageWithAck } from '@sw4rm/js-sdk';
|
|
102
|
+
|
|
103
|
+
const router = new RouterClient({ address: 'localhost:50051' });
|
|
104
|
+
const stream = createResilientIncomingStream(router, 'agent-123');
|
|
105
|
+
const ack = new ACKLifecycleManager();
|
|
106
|
+
|
|
107
|
+
const env = buildEnvelope({
|
|
108
|
+
producer_id: 'agent-123',
|
|
109
|
+
message_type: MessageType.DATA,
|
|
110
|
+
payload: new TextEncoder().encode(JSON.stringify({ hello: 'world' })),
|
|
111
|
+
content_type: 'application/json',
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Example ACK extractor if server sends acknowledgements as envelopes
|
|
115
|
+
const extractor = (item: { msg: any }) => ({ ackFor: item.msg?.ack_for_message_id, stage: item.msg?.ack_stage });
|
|
116
|
+
await sendMessageWithAck(router, stream as any, env, ack, extractor, { receivedTimeoutMs: 10000 });
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## CONTROL helpers
|
|
120
|
+
|
|
121
|
+
When using CONTROL-only orchestration flows, use the provided content-types and encoder:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { buildEnvelope, MessageType } from '@sw4rm/js-sdk';
|
|
125
|
+
import { CT_SCHEDULER_COMMAND_V1, encodeSchedulerCommandV1 } from '@sw4rm/js-sdk';
|
|
126
|
+
|
|
127
|
+
const payload = encodeSchedulerCommandV1({ stage: 'run', input: { repo: 'demo' } });
|
|
128
|
+
const env = buildEnvelope({
|
|
129
|
+
producer_id: 'frontend-agent',
|
|
130
|
+
message_type: MessageType.CONTROL,
|
|
131
|
+
payload,
|
|
132
|
+
content_type: CT_SCHEDULER_COMMAND_V1,
|
|
133
|
+
});
|
|
134
|
+
// send `env` via RouterClient
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Persistence
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { ActivityBuffer, ACKLifecycleManager, RuntimePersistence } from '@sw4rm/js-sdk';
|
|
141
|
+
const buf = new ActivityBuffer();
|
|
142
|
+
const acks = new ACKLifecycleManager();
|
|
143
|
+
const persist = RuntimePersistence.json('.sw4rm', buf, acks, { autosaveMs: 5000 });
|
|
144
|
+
await persist.load();
|
|
145
|
+
persist.startAutosave();
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Spec compliance
|
|
149
|
+
|
|
150
|
+
- Envelope, ACK lifecycle, Scheduler (priority/Duration), Worktree, HITL, Negotiation, Reasoning, Connector, Logging clients implemented.
|
|
151
|
+
- Streaming resilience and interceptor hooks included by default.
|
|
152
|
+
- JSON persistence for ActivityBuffer and ACK states.
|
|
153
|
+
|
|
154
|
+
## Links
|
|
155
|
+
|
|
156
|
+
- Top-level README (overview and API): `../../README.md`
|
|
157
|
+
- Quickstart for running local services: `../../QUICKSTART.md`
|
|
158
|
+
- Python SDK: `../py_sdk/README.md`
|
|
159
|
+
- Rust SDK: `../rust_sdk/README.md`
|