@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
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ACKLifecycleManager } from './ackLifecycle.js';
|
|
2
|
+
export declare enum MessageType {
|
|
3
|
+
MESSAGE_TYPE_UNSPECIFIED = 0,
|
|
4
|
+
CONTROL = 1,
|
|
5
|
+
DATA = 2,
|
|
6
|
+
HEARTBEAT = 3,
|
|
7
|
+
NOTIFICATION = 4,
|
|
8
|
+
ACKNOWLEDGEMENT = 5,
|
|
9
|
+
HITL_INVOCATION = 6,
|
|
10
|
+
WORKTREE_CONTROL = 7,
|
|
11
|
+
NEGOTIATION = 8,
|
|
12
|
+
TOOL_CALL = 9,
|
|
13
|
+
TOOL_RESULT = 10,
|
|
14
|
+
TOOL_ERROR = 11
|
|
15
|
+
}
|
|
16
|
+
export interface EnvelopeLike {
|
|
17
|
+
message_id: string;
|
|
18
|
+
message_type: MessageType;
|
|
19
|
+
correlation_id: string;
|
|
20
|
+
payload?: Uint8Array;
|
|
21
|
+
}
|
|
22
|
+
type Handler = (env: EnvelopeLike) => Promise<void> | void;
|
|
23
|
+
export declare class MessageProcessor {
|
|
24
|
+
private handlers;
|
|
25
|
+
private defaultHandler?;
|
|
26
|
+
private ack;
|
|
27
|
+
constructor(ack: ACKLifecycleManager);
|
|
28
|
+
registerHandler(type: MessageType, handler: Handler): void;
|
|
29
|
+
setDefaultHandler(handler: Handler): void;
|
|
30
|
+
process(env: EnvelopeLike): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface WorktreePolicyContext {
|
|
2
|
+
agent_id: string;
|
|
3
|
+
current_state: string;
|
|
4
|
+
target_worktree_id?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface WorktreePolicyHook {
|
|
7
|
+
canBind(ctx: WorktreePolicyContext, repoId: string, worktreeId: string): boolean;
|
|
8
|
+
canUnbind(ctx: WorktreePolicyContext): boolean;
|
|
9
|
+
canSwitch(ctx: WorktreePolicyContext): boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class DefaultWorktreePolicy implements WorktreePolicyHook {
|
|
12
|
+
canBind(): boolean;
|
|
13
|
+
canUnbind(): boolean;
|
|
14
|
+
canSwitch(): boolean;
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type WorktreeState = 'UNBOUND' | 'BOUND_HOME' | 'SWITCH_PENDING' | 'BOUND_NON_HOME' | 'BIND_FAILED';
|
|
2
|
+
export declare class PersistentWorktreeState {
|
|
3
|
+
private state;
|
|
4
|
+
private repoId?;
|
|
5
|
+
private worktreeId?;
|
|
6
|
+
bind(repoId: string, worktreeId: string): void;
|
|
7
|
+
unbind(): void;
|
|
8
|
+
setState(state: WorktreeState): void;
|
|
9
|
+
current(): {
|
|
10
|
+
state: WorktreeState;
|
|
11
|
+
repo_id: string | undefined;
|
|
12
|
+
worktree_id: string | undefined;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface PersistenceBackend {
|
|
2
|
+
saveActivity(records: any[]): Promise<void>;
|
|
3
|
+
loadActivity(): Promise<any[]>;
|
|
4
|
+
saveAcks(states: any[]): Promise<void>;
|
|
5
|
+
loadAcks(): Promise<any[]>;
|
|
6
|
+
}
|
|
7
|
+
export declare class JSONFilePersistence implements PersistenceBackend {
|
|
8
|
+
private baseDir;
|
|
9
|
+
private activityFile;
|
|
10
|
+
private acksFile;
|
|
11
|
+
constructor(baseDir: string);
|
|
12
|
+
private safeWrite;
|
|
13
|
+
saveActivity(records: any[]): Promise<void>;
|
|
14
|
+
loadActivity(): Promise<any[]>;
|
|
15
|
+
saveAcks(states: any[]): Promise<void>;
|
|
16
|
+
loadAcks(): Promise<any[]>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type * as grpc from '@grpc/grpc-js';
|
|
2
|
+
import { RouterClient } from '../clients/router.js';
|
|
3
|
+
import { ACKLifecycleManager, AckStage } from '../internal/runtime/ackLifecycle.js';
|
|
4
|
+
import { EnvelopeBuilt } from '../internal/envelope.js';
|
|
5
|
+
export interface SendWithAckOptions {
|
|
6
|
+
receivedTimeoutMs?: number;
|
|
7
|
+
correlationIdHeader?: string;
|
|
8
|
+
}
|
|
9
|
+
export type AckExtractor = (env: {
|
|
10
|
+
msg: EnvelopeBuilt;
|
|
11
|
+
}) => {
|
|
12
|
+
ackFor?: string;
|
|
13
|
+
stage?: AckStage;
|
|
14
|
+
} | undefined;
|
|
15
|
+
export declare function sendMessageWithAck(router: RouterClient, inboundStream: grpc.ClientReadableStream<{
|
|
16
|
+
msg: EnvelopeBuilt;
|
|
17
|
+
}>, envelope: EnvelopeBuilt, ackLifecycle: ACKLifecycleManager, ackExtractor: AckExtractor, opts?: SendWithAckOptions): Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ActivityBuffer } from '../internal/runtime/activityBuffer.js';
|
|
2
|
+
import { SchedulerClient } from '../clients/scheduler.js';
|
|
3
|
+
export declare class ActivityBufferSync {
|
|
4
|
+
private buf;
|
|
5
|
+
private sched;
|
|
6
|
+
constructor(buf: ActivityBuffer, sched: SchedulerClient);
|
|
7
|
+
refresh(agentId: string): Promise<void>;
|
|
8
|
+
purge(agentId: string, taskIds: string[]): Promise<number>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type NegotiationEventKind = 'open' | 'policy' | 'propose' | 'counter' | 'evaluate' | 'decide' | 'abort' | {
|
|
2
|
+
unknown: string;
|
|
3
|
+
};
|
|
4
|
+
export interface NegotiationEventBase {
|
|
5
|
+
kind: string;
|
|
6
|
+
ts?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface OpenEvent extends NegotiationEventBase {
|
|
9
|
+
kind: 'open';
|
|
10
|
+
topic: string;
|
|
11
|
+
corr: string;
|
|
12
|
+
}
|
|
13
|
+
export interface PolicyEvent extends NegotiationEventBase {
|
|
14
|
+
kind: 'policy';
|
|
15
|
+
negotiation_id: string;
|
|
16
|
+
profile?: string;
|
|
17
|
+
policy: any;
|
|
18
|
+
}
|
|
19
|
+
export interface PayloadEventBase extends NegotiationEventBase {
|
|
20
|
+
from: string;
|
|
21
|
+
ct: string;
|
|
22
|
+
payload_b64?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ProposeEvent extends PayloadEventBase {
|
|
25
|
+
kind: 'propose';
|
|
26
|
+
}
|
|
27
|
+
export interface CounterEvent extends PayloadEventBase {
|
|
28
|
+
kind: 'counter';
|
|
29
|
+
}
|
|
30
|
+
export interface EvaluateEvent extends NegotiationEventBase {
|
|
31
|
+
kind: 'evaluate';
|
|
32
|
+
from: string;
|
|
33
|
+
score?: number;
|
|
34
|
+
notes?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface DecideEvent extends NegotiationEventBase {
|
|
37
|
+
kind: 'decide';
|
|
38
|
+
by: string;
|
|
39
|
+
ct: string;
|
|
40
|
+
result_b64?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface AbortEvent extends NegotiationEventBase {
|
|
43
|
+
kind: 'abort';
|
|
44
|
+
reason?: string;
|
|
45
|
+
}
|
|
46
|
+
export type NegotiationEvent = OpenEvent | PolicyEvent | ProposeEvent | CounterEvent | EvaluateEvent | DecideEvent | AbortEvent | NegotiationEventBase;
|
|
47
|
+
export declare function parseNegotiationEvent(json: string): NegotiationEvent;
|
|
48
|
+
export declare function decodeBase64(b64?: string): Uint8Array | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ActivityBuffer } from '../internal/runtime/activityBuffer.js';
|
|
2
|
+
import { ACKLifecycleManager } from '../internal/runtime/ackLifecycle.js';
|
|
3
|
+
import { PersistenceBackend } from '../persistence/persistence.js';
|
|
4
|
+
export interface PersistenceOptions {
|
|
5
|
+
autosaveMs?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class RuntimePersistence {
|
|
8
|
+
private backend;
|
|
9
|
+
private activity;
|
|
10
|
+
private acks;
|
|
11
|
+
private opts?;
|
|
12
|
+
private timer?;
|
|
13
|
+
constructor(backend: PersistenceBackend, activity: ActivityBuffer, acks: ACKLifecycleManager, opts?: PersistenceOptions | undefined);
|
|
14
|
+
static json(baseDir: string, activity: ActivityBuffer, acks: ACKLifecycleManager, opts?: PersistenceOptions): RuntimePersistence;
|
|
15
|
+
load(): Promise<void>;
|
|
16
|
+
save(): Promise<void>;
|
|
17
|
+
startAutosave(): void;
|
|
18
|
+
stopAutosave(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { RouterClient } from '../clients/router.js';
|
|
3
|
+
export interface ResilientOptions {
|
|
4
|
+
initialBackoffMs?: number;
|
|
5
|
+
maxBackoffMs?: number;
|
|
6
|
+
multiplier?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function createResilientIncomingStream(router: RouterClient, agentId: string, opts?: ResilientOptions): EventEmitter;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Scope, SecretKey, SecretValue } from './types.js';
|
|
2
|
+
export interface SecretsBackend {
|
|
3
|
+
set(scope: Scope, key: SecretKey, value: SecretValue): Promise<void>;
|
|
4
|
+
get(scope: Scope, key: SecretKey): Promise<string>;
|
|
5
|
+
list(scope?: Scope | null): Promise<Map<[string | null, string], string>>;
|
|
6
|
+
}
|
|
7
|
+
export declare class Secrets<B extends SecretsBackend> {
|
|
8
|
+
readonly backend: B;
|
|
9
|
+
constructor(backend: B);
|
|
10
|
+
set(scope: Scope, key: SecretKey, value: SecretValue): Promise<void>;
|
|
11
|
+
get(scope: Scope, key: SecretKey): Promise<string>;
|
|
12
|
+
list(scope?: Scope | null): Promise<Map<[string | null, string], string>>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SecretsBackend } from '../backend.js';
|
|
2
|
+
import { Scope, SecretKey, SecretValue } from '../types.js';
|
|
3
|
+
export declare class FileBackend implements SecretsBackend {
|
|
4
|
+
private path;
|
|
5
|
+
constructor(path?: string);
|
|
6
|
+
private enforceFilePerms;
|
|
7
|
+
private safeWrite;
|
|
8
|
+
private load;
|
|
9
|
+
set(scope: Scope, key: SecretKey, value: SecretValue): Promise<void>;
|
|
10
|
+
get(scope: Scope, key: SecretKey): Promise<string>;
|
|
11
|
+
list(scope?: Scope | null): Promise<Map<[string | null, string], string>>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SecretsBackend } from '../backend.js';
|
|
2
|
+
import { Scope, SecretKey, SecretValue } from '../types.js';
|
|
3
|
+
export declare class KeyringBackend implements SecretsBackend {
|
|
4
|
+
private keytar;
|
|
5
|
+
private servicePrefix;
|
|
6
|
+
constructor(servicePrefix?: string);
|
|
7
|
+
private ensureKeytar;
|
|
8
|
+
private service;
|
|
9
|
+
set(scope: Scope, key: SecretKey, value: SecretValue): Promise<void>;
|
|
10
|
+
get(scope: Scope, key: SecretKey): Promise<string>;
|
|
11
|
+
list(): Promise<Map<[string | null, string], string>>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class SecretError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export declare class SecretNotFound extends SecretError {
|
|
4
|
+
readonly scope: string;
|
|
5
|
+
readonly key: string;
|
|
6
|
+
constructor(scope: string, key: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class SecretBackendError extends SecretError {
|
|
9
|
+
}
|
|
10
|
+
export declare class SecretPermissionError extends SecretError {
|
|
11
|
+
}
|
|
12
|
+
export declare class SecretValidationError extends SecretError {
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SecretsBackend } from './backend.js';
|
|
2
|
+
import { Scope, SecretKey, SecretSource } from './types.js';
|
|
3
|
+
export declare class Resolver<B extends SecretsBackend> {
|
|
4
|
+
private readonly backend;
|
|
5
|
+
private readonly env;
|
|
6
|
+
constructor(backend: B, env?: Record<string, string>);
|
|
7
|
+
resolve(key: SecretKey, scope: Scope, opts?: {
|
|
8
|
+
explicit?: string | null;
|
|
9
|
+
envVar?: string | null;
|
|
10
|
+
}): Promise<[string, SecretSource]>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare enum SecretSource {
|
|
2
|
+
CLI = "cli",
|
|
3
|
+
ENV = "env",
|
|
4
|
+
SCOPED = "scoped",
|
|
5
|
+
GLOBAL = "global"
|
|
6
|
+
}
|
|
7
|
+
export declare class Scope {
|
|
8
|
+
readonly name: string | null;
|
|
9
|
+
constructor(name?: string | null);
|
|
10
|
+
get isGlobal(): boolean;
|
|
11
|
+
label(): string;
|
|
12
|
+
}
|
|
13
|
+
export declare class SecretKey {
|
|
14
|
+
readonly key: string;
|
|
15
|
+
constructor(key: string);
|
|
16
|
+
}
|
|
17
|
+
export declare class SecretValue {
|
|
18
|
+
readonly value: string;
|
|
19
|
+
static MAX_LEN: number;
|
|
20
|
+
constructor(value: string);
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sw4rm/js-sdk",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "SW4RM Agentic Protocol JavaScript/TypeScript SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.cjs",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
12
|
+
"import": "./dist/esm/index.js",
|
|
13
|
+
"require": "./dist/cjs/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "npm run build:proto && npm run build:lib",
|
|
18
|
+
"example": "tsx",
|
|
19
|
+
"build:proto": "npm run proto:js && npm run proto:ts",
|
|
20
|
+
"build:lib": "npm run build:esm && npm run build:cjs && npm run build:types",
|
|
21
|
+
"build:esm": "esbuild src/index.ts --bundle --platform=node --target=node18 --format=esm --outfile=dist/esm/index.js --external:@grpc/grpc-js --external:keytar",
|
|
22
|
+
"build:cjs": "esbuild src/index.ts --bundle --platform=node --target=node18 --format=cjs --outfile=dist/cjs/index.cjs --external:@grpc/grpc-js --external:keytar",
|
|
23
|
+
"build:types": "tsc --emitDeclarationOnly --project tsconfig.json --outDir dist/types",
|
|
24
|
+
"proto:js": "grpc_tools_node_protoc --js_out=import_style=commonjs,binary:src/types/generated --grpc_out=grpc_js:src/types/generated --proto_path=../../protos ../../protos/*.proto",
|
|
25
|
+
"proto:ts": "grpc_tools_node_protoc --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts --ts_out=grpc_js:src/types/generated --proto_path=../../protos ../../protos/*.proto",
|
|
26
|
+
"test": "vitest",
|
|
27
|
+
"test:coverage": "vitest --coverage",
|
|
28
|
+
"lint": "eslint src --ext .ts,.js",
|
|
29
|
+
"format": "prettier --write src"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/rahulrajaram/sw4rm.git",
|
|
42
|
+
"directory": "sdks/js_sdk"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/rahulrajaram/sw4rm/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/rahulrajaram/sw4rm#readme",
|
|
48
|
+
"keywords": [
|
|
49
|
+
"sw4rm",
|
|
50
|
+
"agent",
|
|
51
|
+
"protocol",
|
|
52
|
+
"grpc",
|
|
53
|
+
"typescript",
|
|
54
|
+
"javascript"
|
|
55
|
+
],
|
|
56
|
+
"author": "SW4RM Team",
|
|
57
|
+
"license": "Apache-2.0",
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@types/keytar": "^4.4.0",
|
|
60
|
+
"@types/node": "^20.11.0",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
|
62
|
+
"@typescript-eslint/parser": "^6.19.0",
|
|
63
|
+
"@vitest/coverage-v8": "^1.2.0",
|
|
64
|
+
"esbuild": "^0.19.0",
|
|
65
|
+
"eslint": "^8.56.0",
|
|
66
|
+
"grpc_tools_node_protoc_ts": "^5.3.3",
|
|
67
|
+
"grpc-tools": "^1.12.4",
|
|
68
|
+
"prettier": "^3.2.0",
|
|
69
|
+
"tsx": "^4.15.7",
|
|
70
|
+
"typescript": "^5.3.0",
|
|
71
|
+
"vitest": "^1.2.0"
|
|
72
|
+
},
|
|
73
|
+
"dependencies": {
|
|
74
|
+
"@grpc/grpc-js": "^1.10.0",
|
|
75
|
+
"@grpc/proto-loader": "^0.7.10",
|
|
76
|
+
"google-protobuf": "^3.21.2"
|
|
77
|
+
},
|
|
78
|
+
"engines": {
|
|
79
|
+
"node": ">=20.0.0"
|
|
80
|
+
}
|
|
81
|
+
}
|