@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,13 @@
|
|
|
1
|
+
import { BaseClient, ClientOptions } from '../internal/baseClient.js';
|
|
2
|
+
export declare class ActivityClient extends BaseClient {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(opts: ClientOptions);
|
|
5
|
+
private unary;
|
|
6
|
+
appendArtifact(artifact: any): Promise<{
|
|
7
|
+
ok: boolean;
|
|
8
|
+
reason?: string;
|
|
9
|
+
}>;
|
|
10
|
+
listArtifacts(negotiation_id: string, kind?: string): Promise<{
|
|
11
|
+
items: any[];
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BaseClient, ClientOptions } from '../internal/baseClient.js';
|
|
2
|
+
export interface ToolDescriptor {
|
|
3
|
+
tool_name: string;
|
|
4
|
+
input_schema?: string;
|
|
5
|
+
output_schema?: string;
|
|
6
|
+
idempotent?: boolean;
|
|
7
|
+
needs_worktree?: boolean;
|
|
8
|
+
default_timeout_s?: number;
|
|
9
|
+
max_concurrency?: number;
|
|
10
|
+
side_effects?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ProviderRegisterRequest {
|
|
13
|
+
provider_id: string;
|
|
14
|
+
tools: ToolDescriptor[];
|
|
15
|
+
}
|
|
16
|
+
export interface ProviderRegisterResponse {
|
|
17
|
+
ok: boolean;
|
|
18
|
+
reason?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface DescribeToolsRequest {
|
|
21
|
+
provider_id: string;
|
|
22
|
+
}
|
|
23
|
+
export interface DescribeToolsResponse {
|
|
24
|
+
tools: ToolDescriptor[];
|
|
25
|
+
}
|
|
26
|
+
export declare class ConnectorClient extends BaseClient {
|
|
27
|
+
private client;
|
|
28
|
+
constructor(opts: ClientOptions);
|
|
29
|
+
registerProvider(req: ProviderRegisterRequest): Promise<ProviderRegisterResponse>;
|
|
30
|
+
describeTools(providerId: string): Promise<ToolDescriptor[]>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseClient, ClientOptions } from '../internal/baseClient.js';
|
|
2
|
+
export interface HitlInvocation {
|
|
3
|
+
reason_type: string;
|
|
4
|
+
context: Uint8Array;
|
|
5
|
+
proposed_actions: string[];
|
|
6
|
+
priority?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface HitlDecision {
|
|
9
|
+
action: string;
|
|
10
|
+
decision_payload?: Uint8Array;
|
|
11
|
+
rationale?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class HITLClient extends BaseClient {
|
|
14
|
+
private client;
|
|
15
|
+
constructor(opts: ClientOptions);
|
|
16
|
+
decide(inv: HitlInvocation): Promise<HitlDecision>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseClient, ClientOptions } from '../internal/baseClient.js';
|
|
2
|
+
export interface Timestamp {
|
|
3
|
+
seconds: number | string;
|
|
4
|
+
nanos?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface LogEvent {
|
|
7
|
+
ts: Timestamp;
|
|
8
|
+
correlation_id: string;
|
|
9
|
+
agent_id: string;
|
|
10
|
+
event_type: string;
|
|
11
|
+
level: string;
|
|
12
|
+
details_json: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class LoggingClient extends BaseClient {
|
|
15
|
+
private client;
|
|
16
|
+
constructor(opts: ClientOptions);
|
|
17
|
+
ingest(evt: LogEvent): Promise<boolean>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BaseClient, ClientOptions } from '../internal/baseClient.js';
|
|
2
|
+
export interface Empty {
|
|
3
|
+
}
|
|
4
|
+
export interface NegotiationOpen {
|
|
5
|
+
negotiation_id: string;
|
|
6
|
+
correlation_id: string;
|
|
7
|
+
topic: string;
|
|
8
|
+
participants: string[];
|
|
9
|
+
intensity: string;
|
|
10
|
+
debate_timeout?: {
|
|
11
|
+
seconds: number | string;
|
|
12
|
+
nanos?: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface Proposal {
|
|
16
|
+
negotiation_id: string;
|
|
17
|
+
from_agent: string;
|
|
18
|
+
content_type: string;
|
|
19
|
+
payload: Uint8Array;
|
|
20
|
+
}
|
|
21
|
+
export interface CounterProposal {
|
|
22
|
+
negotiation_id: string;
|
|
23
|
+
from_agent: string;
|
|
24
|
+
content_type: string;
|
|
25
|
+
payload: Uint8Array;
|
|
26
|
+
}
|
|
27
|
+
export interface Evaluation {
|
|
28
|
+
negotiation_id: string;
|
|
29
|
+
from_agent: string;
|
|
30
|
+
confidence_score?: number;
|
|
31
|
+
notes?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface Decision {
|
|
34
|
+
negotiation_id: string;
|
|
35
|
+
decided_by: string;
|
|
36
|
+
content_type: string;
|
|
37
|
+
result: Uint8Array;
|
|
38
|
+
}
|
|
39
|
+
export interface AbortRequest {
|
|
40
|
+
negotiation_id: string;
|
|
41
|
+
reason?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare class NegotiationClient extends BaseClient {
|
|
44
|
+
private client;
|
|
45
|
+
constructor(opts: ClientOptions);
|
|
46
|
+
private unary;
|
|
47
|
+
open(req: NegotiationOpen): Promise<Empty>;
|
|
48
|
+
propose(req: Proposal): Promise<Empty>;
|
|
49
|
+
counter(req: CounterProposal): Promise<Empty>;
|
|
50
|
+
evaluate(req: Evaluation): Promise<Empty>;
|
|
51
|
+
decide(req: Decision): Promise<Empty>;
|
|
52
|
+
abort(req: AbortRequest): Promise<Empty>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseClient, ClientOptions } from '../internal/baseClient.js';
|
|
2
|
+
export declare class ReasoningClient extends BaseClient {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(opts: ClientOptions);
|
|
5
|
+
checkParallelism(scopeA: string, scopeB: string): Promise<{
|
|
6
|
+
confidence_score: number;
|
|
7
|
+
notes?: string;
|
|
8
|
+
}>;
|
|
9
|
+
evaluateDebate(negotiationId: string, proposalA: string, proposalB: string, intensity?: string): Promise<{
|
|
10
|
+
confidence_score: number;
|
|
11
|
+
notes?: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseClient, ClientOptions } from '../internal/baseClient.js';
|
|
2
|
+
export interface AgentDescriptor {
|
|
3
|
+
agent_id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
capabilities: string[];
|
|
7
|
+
communication_class: string;
|
|
8
|
+
modalities_supported: string[];
|
|
9
|
+
reasoning_connectors: string[];
|
|
10
|
+
public_key?: Uint8Array;
|
|
11
|
+
}
|
|
12
|
+
export declare class RegistryClient extends BaseClient {
|
|
13
|
+
private client;
|
|
14
|
+
constructor(opts: ClientOptions);
|
|
15
|
+
registerAgent(agent: AgentDescriptor): Promise<{
|
|
16
|
+
accepted: boolean;
|
|
17
|
+
reason?: string;
|
|
18
|
+
}>;
|
|
19
|
+
heartbeat(agentId: string, state: string, health?: Record<string, string>): Promise<boolean>;
|
|
20
|
+
deregisterAgent(agentId: string, reason?: string): Promise<boolean>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as grpc from '@grpc/grpc-js';
|
|
2
|
+
import { BaseClient, ClientOptions } from '../internal/baseClient.js';
|
|
3
|
+
import { EnvelopeBuilt } from '../internal/envelope.js';
|
|
4
|
+
export interface SendResult {
|
|
5
|
+
accepted: boolean;
|
|
6
|
+
reason?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class RouterClient extends BaseClient {
|
|
9
|
+
private client;
|
|
10
|
+
constructor(opts: ClientOptions);
|
|
11
|
+
sendMessage(envelope: EnvelopeBuilt): Promise<SendResult>;
|
|
12
|
+
streamIncoming(agentId: string, meta?: grpc.Metadata): grpc.ClientReadableStream<{
|
|
13
|
+
msg: EnvelopeBuilt;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { BaseClient, ClientOptions } from '../internal/baseClient.js';
|
|
2
|
+
export interface SubmitTaskRequest {
|
|
3
|
+
agent_id: string;
|
|
4
|
+
task_id: string;
|
|
5
|
+
priority: number;
|
|
6
|
+
params: Uint8Array;
|
|
7
|
+
content_type: string;
|
|
8
|
+
scope: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SubmitTaskResponse {
|
|
11
|
+
accepted: boolean;
|
|
12
|
+
reason?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PreemptRequest {
|
|
15
|
+
agent_id: string;
|
|
16
|
+
task_id: string;
|
|
17
|
+
reason?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface PreemptResponse {
|
|
20
|
+
enqueued: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface ShutdownAgentRequest {
|
|
23
|
+
agent_id: string;
|
|
24
|
+
grace_period?: {
|
|
25
|
+
seconds: number | string;
|
|
26
|
+
nanos?: number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface ShutdownAgentResponse {
|
|
30
|
+
ok: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface PollActivityBufferRequest {
|
|
33
|
+
agent_id: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ActivityEntry {
|
|
36
|
+
task_id: string;
|
|
37
|
+
repo_id: string;
|
|
38
|
+
worktree_id: string;
|
|
39
|
+
branch: string;
|
|
40
|
+
description: string;
|
|
41
|
+
timestamp: string;
|
|
42
|
+
}
|
|
43
|
+
export interface PollActivityBufferResponse {
|
|
44
|
+
entries: ActivityEntry[];
|
|
45
|
+
}
|
|
46
|
+
export interface PurgeActivityRequest {
|
|
47
|
+
agent_id: string;
|
|
48
|
+
task_ids: string[];
|
|
49
|
+
}
|
|
50
|
+
export interface PurgeActivityResponse {
|
|
51
|
+
purged: number;
|
|
52
|
+
}
|
|
53
|
+
export declare class SchedulerClient extends BaseClient {
|
|
54
|
+
private client;
|
|
55
|
+
constructor(opts: ClientOptions);
|
|
56
|
+
submitTask(req: SubmitTaskRequest): Promise<SubmitTaskResponse>;
|
|
57
|
+
requestPreemption(agentId: string, taskId: string, reason?: string): Promise<PreemptResponse>;
|
|
58
|
+
shutdownAgent(agentId: string, graceMs: number): Promise<ShutdownAgentResponse>;
|
|
59
|
+
pollActivityBuffer(agentId: string): Promise<ActivityEntry[]>;
|
|
60
|
+
purgeActivity(agentId: string, taskIds: string[]): Promise<number>;
|
|
61
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BaseClient, ClientOptions } from '../internal/baseClient.js';
|
|
2
|
+
export declare class SchedulerPolicyClient extends BaseClient {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(opts: ClientOptions);
|
|
5
|
+
private unary;
|
|
6
|
+
setWagglePolicy(policy: any): Promise<{
|
|
7
|
+
ok: boolean;
|
|
8
|
+
reason?: string;
|
|
9
|
+
}>;
|
|
10
|
+
getWagglePolicy(): Promise<{
|
|
11
|
+
policy?: any;
|
|
12
|
+
}>;
|
|
13
|
+
setPolicyProfiles(profiles: any[]): Promise<{
|
|
14
|
+
ok: boolean;
|
|
15
|
+
reason?: string;
|
|
16
|
+
}>;
|
|
17
|
+
listPolicyProfiles(): Promise<{
|
|
18
|
+
profiles: any[];
|
|
19
|
+
}>;
|
|
20
|
+
getEffectivePolicy(negotiation_id: string): Promise<{
|
|
21
|
+
effective?: any;
|
|
22
|
+
}>;
|
|
23
|
+
submitEvaluation(negotiation_id: string, report: any): Promise<{
|
|
24
|
+
accepted: boolean;
|
|
25
|
+
reason?: string;
|
|
26
|
+
}>;
|
|
27
|
+
hitlAction(negotiation_id: string, action: string, rationale?: string): Promise<{
|
|
28
|
+
ok: boolean;
|
|
29
|
+
reason?: string;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as grpc from '@grpc/grpc-js';
|
|
2
|
+
import { BaseClient, ClientOptions } from '../internal/baseClient.js';
|
|
3
|
+
export interface ExecutionPolicy {
|
|
4
|
+
timeout?: {
|
|
5
|
+
seconds: number | string;
|
|
6
|
+
nanos?: number;
|
|
7
|
+
};
|
|
8
|
+
max_retries?: number;
|
|
9
|
+
backoff?: string;
|
|
10
|
+
worktree_required?: boolean;
|
|
11
|
+
network_policy?: string;
|
|
12
|
+
privilege_level?: string;
|
|
13
|
+
budget_cpu_ms?: string | number;
|
|
14
|
+
budget_wall_ms?: string | number;
|
|
15
|
+
}
|
|
16
|
+
export interface ToolCall {
|
|
17
|
+
call_id: string;
|
|
18
|
+
tool_name: string;
|
|
19
|
+
provider_id?: string;
|
|
20
|
+
content_type: string;
|
|
21
|
+
args: Uint8Array;
|
|
22
|
+
policy?: ExecutionPolicy;
|
|
23
|
+
stream?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface ToolFrame {
|
|
26
|
+
call_id: string;
|
|
27
|
+
frame_no: string | number;
|
|
28
|
+
final: boolean;
|
|
29
|
+
content_type: string;
|
|
30
|
+
data: Uint8Array;
|
|
31
|
+
summary?: Uint8Array;
|
|
32
|
+
}
|
|
33
|
+
export interface ToolError {
|
|
34
|
+
call_id: string;
|
|
35
|
+
error_code?: string;
|
|
36
|
+
message?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare class ToolClient extends BaseClient {
|
|
39
|
+
private client;
|
|
40
|
+
private getWorktreeState?;
|
|
41
|
+
constructor(opts: ClientOptions, deps?: {
|
|
42
|
+
getWorktreeState?: () => {
|
|
43
|
+
state: string;
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
private ensureWorktreeIfNeeded;
|
|
47
|
+
call(call: ToolCall): Promise<ToolFrame>;
|
|
48
|
+
callStream(call: ToolCall, meta?: grpc.Metadata): grpc.ClientReadableStream<ToolFrame>;
|
|
49
|
+
cancel(call: ToolCall): Promise<ToolError>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseClient, ClientOptions } from '../internal/baseClient.js';
|
|
2
|
+
import { WorktreePolicyHook } from '../internal/worktreePolicy.js';
|
|
3
|
+
export declare class WorktreeClient extends BaseClient {
|
|
4
|
+
private client;
|
|
5
|
+
private policy;
|
|
6
|
+
constructor(opts: ClientOptions);
|
|
7
|
+
setPolicy(policy: WorktreePolicyHook): void;
|
|
8
|
+
bind(agentId: string, repoId: string, worktreeId: string): Promise<{
|
|
9
|
+
ok: boolean;
|
|
10
|
+
reason?: string;
|
|
11
|
+
}>;
|
|
12
|
+
unbind(agentId: string): Promise<boolean>;
|
|
13
|
+
requestSwitch(agentId: string, targetWorktreeId: string, requiresHitl: boolean): Promise<{
|
|
14
|
+
state: string;
|
|
15
|
+
repo_id?: string;
|
|
16
|
+
worktree_id?: string;
|
|
17
|
+
}>;
|
|
18
|
+
approveSwitch(agentId: string, targetWorktreeId: string, ttlMs: number): Promise<string>;
|
|
19
|
+
rejectSwitch(agentId: string, reason?: string): Promise<string>;
|
|
20
|
+
status(agentId: string): Promise<{
|
|
21
|
+
state: string;
|
|
22
|
+
repo_id?: string;
|
|
23
|
+
worktree_id?: string;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare const version = "0.3.0";
|
|
2
|
+
export * from './clients/router.js';
|
|
3
|
+
export * from './clients/scheduler.js';
|
|
4
|
+
export * from './clients/schedulerPolicy.js';
|
|
5
|
+
export * from './clients/worktree.js';
|
|
6
|
+
export * from './clients/tool.js';
|
|
7
|
+
export { LoggingClient, type LogEvent, } from './clients/logging.js';
|
|
8
|
+
export * from './clients/activity.js';
|
|
9
|
+
export * from './clients/hitl.js';
|
|
10
|
+
export * from './clients/negotiation.js';
|
|
11
|
+
export * from './clients/reasoning.js';
|
|
12
|
+
export * from './clients/connector.js';
|
|
13
|
+
export * from './clients/registry.js';
|
|
14
|
+
export { buildEnvelope, type EnvelopeBuilt, type EnvelopeInput, nowTimestamp, type Timestamp, } from './internal/envelope.js';
|
|
15
|
+
export * from './internal/errorMapping.js';
|
|
16
|
+
export * from './internal/baseClient.js';
|
|
17
|
+
export * from './internal/time.js';
|
|
18
|
+
export * from './internal/interceptors.js';
|
|
19
|
+
export * from './internal/worktreeState.js';
|
|
20
|
+
export * from './internal/worktreePolicy.js';
|
|
21
|
+
export * from './internal/runtime/activityBuffer.js';
|
|
22
|
+
export * from './internal/runtime/ackLifecycle.js';
|
|
23
|
+
export * from './internal/runtime/messageProcessor.js';
|
|
24
|
+
export * from './runtime/ackHelpers.js';
|
|
25
|
+
export * from './runtime/activitySync.js';
|
|
26
|
+
export * from './runtime/streams.js';
|
|
27
|
+
export * from './runtime/negotiationEvents.js';
|
|
28
|
+
export * from './persistence/persistence.js';
|
|
29
|
+
export * from './internal/ids.js';
|
|
30
|
+
export * from './internal/idempotency.js';
|
|
31
|
+
export * from './runtime/persistenceAdapter.js';
|
|
32
|
+
export * from './internal/errorMapper.js';
|
|
33
|
+
export * from './internal/ack.js';
|
|
34
|
+
export * from './internal/control.js';
|
|
35
|
+
export * from './secrets/types.js';
|
|
36
|
+
export * from './secrets/errors.js';
|
|
37
|
+
export * from './secrets/backend.js';
|
|
38
|
+
export * from './secrets/resolver.js';
|
|
39
|
+
export * from './secrets/backends/file.js';
|
|
40
|
+
export * from './secrets/backends/keyring.js';
|
|
41
|
+
export * from './secrets/factory.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EnvelopeBuilt } from './envelope.js';
|
|
2
|
+
export interface AckPayload {
|
|
3
|
+
ack_for_message_id: string;
|
|
4
|
+
ack_stage: number;
|
|
5
|
+
error_code?: number;
|
|
6
|
+
note?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function buildAckEnvelope(params: {
|
|
9
|
+
producer_id: string;
|
|
10
|
+
correlation_id?: string;
|
|
11
|
+
ack: AckPayload;
|
|
12
|
+
content_type?: 'application/json';
|
|
13
|
+
}): EnvelopeBuilt;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as grpc from '@grpc/grpc-js';
|
|
2
|
+
import { ErrorCodeMapper } from './errorMapper.js';
|
|
3
|
+
import { InterceptorChain } from './interceptors.js';
|
|
4
|
+
export interface RetryPolicy {
|
|
5
|
+
maxAttempts: number;
|
|
6
|
+
initialBackoffMs: number;
|
|
7
|
+
maxBackoffMs: number;
|
|
8
|
+
multiplier: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ClientOptions {
|
|
11
|
+
address: string;
|
|
12
|
+
deadlineMs?: number;
|
|
13
|
+
retry?: RetryPolicy;
|
|
14
|
+
userAgent?: string;
|
|
15
|
+
interceptors?: (chain: InterceptorChain) => void;
|
|
16
|
+
errorMapper?: (m: ErrorCodeMapper) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare class BaseClient {
|
|
19
|
+
protected readonly address: string;
|
|
20
|
+
protected readonly deadlineMs: number;
|
|
21
|
+
protected readonly retry: RetryPolicy;
|
|
22
|
+
protected readonly userAgent: string;
|
|
23
|
+
private readonly pkgDef;
|
|
24
|
+
private readonly root;
|
|
25
|
+
protected readonly interceptors: InterceptorChain;
|
|
26
|
+
protected readonly errorMapper: ErrorCodeMapper;
|
|
27
|
+
constructor(opts: ClientOptions);
|
|
28
|
+
protected channelCredentials(): grpc.ChannelCredentials;
|
|
29
|
+
protected metadata(base?: grpc.Metadata): grpc.Metadata;
|
|
30
|
+
protected deadlineFromNow(): Date;
|
|
31
|
+
protected getServiceClient<T = any>(fqn: string): T;
|
|
32
|
+
protected withRetryUnary<Req, Res>(fn: () => Promise<Res>, methodName?: string, mdForCtx?: grpc.Metadata): Promise<Res>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const CT_SCHEDULER_COMMAND_V1 = "application/vnd.sw4rm.scheduler.command+json;v=1";
|
|
2
|
+
export declare const CT_AGENT_REPORT_V1 = "application/vnd.sw4rm.agent.report+json;v=1";
|
|
3
|
+
export type SchedulerStage = 'prompt' | 'plan' | 'run';
|
|
4
|
+
export interface SchedulerCommandV1 {
|
|
5
|
+
stage: SchedulerStage;
|
|
6
|
+
input?: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface AgentReportFileV1 {
|
|
9
|
+
path: string;
|
|
10
|
+
b64: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AgentReportV1 {
|
|
13
|
+
agent_id?: string;
|
|
14
|
+
stage?: string;
|
|
15
|
+
success?: boolean;
|
|
16
|
+
files?: AgentReportFileV1[];
|
|
17
|
+
logs?: string[];
|
|
18
|
+
error?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function encodeSchedulerCommandV1(cmd: SchedulerCommandV1): Uint8Array;
|
|
21
|
+
export declare function decodeAgentReportV1(payload: Uint8Array): AgentReportV1;
|
|
22
|
+
export declare function normalizeReportPaths(report: AgentReportV1): AgentReportV1;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export type Timestamp = {
|
|
2
|
+
seconds: number;
|
|
3
|
+
nanos: number;
|
|
4
|
+
};
|
|
5
|
+
export declare enum MessageType {
|
|
6
|
+
MESSAGE_TYPE_UNSPECIFIED = 0,
|
|
7
|
+
CONTROL = 1,
|
|
8
|
+
DATA = 2,
|
|
9
|
+
HEARTBEAT = 3,
|
|
10
|
+
NOTIFICATION = 4,
|
|
11
|
+
ACKNOWLEDGEMENT = 5,
|
|
12
|
+
HITL_INVOCATION = 6,
|
|
13
|
+
WORKTREE_CONTROL = 7,
|
|
14
|
+
NEGOTIATION = 8,
|
|
15
|
+
TOOL_CALL = 9,
|
|
16
|
+
TOOL_RESULT = 10,
|
|
17
|
+
TOOL_ERROR = 11
|
|
18
|
+
}
|
|
19
|
+
export interface EnvelopeInput {
|
|
20
|
+
producer_id: string;
|
|
21
|
+
message_type: MessageType;
|
|
22
|
+
payload?: Uint8Array | Buffer;
|
|
23
|
+
content_type?: string;
|
|
24
|
+
correlation_id?: string;
|
|
25
|
+
idempotency_token?: string;
|
|
26
|
+
sequence_number?: number;
|
|
27
|
+
retry_count?: number;
|
|
28
|
+
repo_id?: string;
|
|
29
|
+
worktree_id?: string;
|
|
30
|
+
hlc_timestamp?: string;
|
|
31
|
+
ttl_ms?: number;
|
|
32
|
+
timestamp?: Date;
|
|
33
|
+
}
|
|
34
|
+
export interface EnvelopeBuilt {
|
|
35
|
+
message_id: string;
|
|
36
|
+
idempotency_token?: string;
|
|
37
|
+
producer_id: string;
|
|
38
|
+
correlation_id: string;
|
|
39
|
+
sequence_number: number;
|
|
40
|
+
retry_count: number;
|
|
41
|
+
message_type: MessageType;
|
|
42
|
+
content_type: string;
|
|
43
|
+
content_length?: number;
|
|
44
|
+
repo_id?: string;
|
|
45
|
+
worktree_id?: string;
|
|
46
|
+
hlc_timestamp: string;
|
|
47
|
+
ttl_ms?: number;
|
|
48
|
+
timestamp: Timestamp;
|
|
49
|
+
payload?: Uint8Array;
|
|
50
|
+
}
|
|
51
|
+
export declare function nowTimestamp(date?: Date): Timestamp;
|
|
52
|
+
export declare function nowHlcStub(date?: Date): string;
|
|
53
|
+
export declare function buildEnvelope(input: EnvelopeInput): EnvelopeBuilt;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ErrorCode } from './errorMapping.js';
|
|
2
|
+
export type GrpcErrorInfo = {
|
|
3
|
+
status?: number;
|
|
4
|
+
message?: string;
|
|
5
|
+
details?: string;
|
|
6
|
+
};
|
|
7
|
+
export type ErrorMapRule = (err: GrpcErrorInfo) => ErrorCode | undefined;
|
|
8
|
+
export declare class ErrorCodeMapper {
|
|
9
|
+
private rules;
|
|
10
|
+
constructor(rules?: ErrorMapRule[]);
|
|
11
|
+
addRule(rule: ErrorMapRule): void;
|
|
12
|
+
map(err: GrpcErrorInfo, fallback: (status?: number) => ErrorCode): ErrorCode;
|
|
13
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare enum ErrorCode {
|
|
2
|
+
ERROR_CODE_UNSPECIFIED = 0,
|
|
3
|
+
BUFFER_FULL = 1,
|
|
4
|
+
NO_ROUTE = 2,
|
|
5
|
+
ACK_TIMEOUT = 3,
|
|
6
|
+
AGENT_UNAVAILABLE = 4,
|
|
7
|
+
AGENT_SHUTDOWN = 5,
|
|
8
|
+
VALIDATION_ERROR = 6,
|
|
9
|
+
PERMISSION_DENIED = 7,
|
|
10
|
+
UNSUPPORTED_MESSAGE_TYPE = 8,
|
|
11
|
+
OVERSIZE_PAYLOAD = 9,
|
|
12
|
+
TOOL_TIMEOUT = 10,
|
|
13
|
+
PARTIAL_DELIVERY = 11,
|
|
14
|
+
FORCED_PREEMPTION = 12,
|
|
15
|
+
TTL_EXPIRED = 13,
|
|
16
|
+
INTERNAL_ERROR = 99
|
|
17
|
+
}
|
|
18
|
+
export declare class Sw4rmError extends Error {
|
|
19
|
+
readonly code: ErrorCode;
|
|
20
|
+
readonly grpcStatus?: number;
|
|
21
|
+
readonly details?: string;
|
|
22
|
+
constructor(message: string, code: ErrorCode, opts?: {
|
|
23
|
+
grpcStatus?: number;
|
|
24
|
+
details?: string;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export declare function mapGrpcStatusToErrorCode(status: number): ErrorCode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function uuidv4(): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface UnaryContext {
|
|
2
|
+
method: string;
|
|
3
|
+
metadata: Map<string, string>;
|
|
4
|
+
startTime: number;
|
|
5
|
+
}
|
|
6
|
+
export interface UnaryInterceptor {
|
|
7
|
+
onRequest?(ctx: UnaryContext): void;
|
|
8
|
+
onResponse?(ctx: UnaryContext, status: {
|
|
9
|
+
ok: boolean;
|
|
10
|
+
error?: unknown;
|
|
11
|
+
durationMs: number;
|
|
12
|
+
}): void;
|
|
13
|
+
}
|
|
14
|
+
export declare class InterceptorChain {
|
|
15
|
+
private chain;
|
|
16
|
+
use(i: UnaryInterceptor): void;
|
|
17
|
+
runRequest(ctx: UnaryContext): void;
|
|
18
|
+
runResponse(ctx: UnaryContext, status: {
|
|
19
|
+
ok: boolean;
|
|
20
|
+
error?: unknown;
|
|
21
|
+
durationMs: number;
|
|
22
|
+
}): void;
|
|
23
|
+
}
|
|
24
|
+
export declare function timingInterceptor(): UnaryInterceptor;
|
|
25
|
+
export declare function loggingInterceptor(): UnaryInterceptor;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare enum AckStage {
|
|
2
|
+
ACK_STAGE_UNSPECIFIED = 0,
|
|
3
|
+
RECEIVED = 1,
|
|
4
|
+
READ = 2,
|
|
5
|
+
FULFILLED = 3,
|
|
6
|
+
REJECTED = 4,
|
|
7
|
+
FAILED = 5,
|
|
8
|
+
TIMED_OUT = 6
|
|
9
|
+
}
|
|
10
|
+
export interface AckState {
|
|
11
|
+
messageId: string;
|
|
12
|
+
stage: AckStage;
|
|
13
|
+
lastUpdateIso: string;
|
|
14
|
+
note?: string;
|
|
15
|
+
errorCode?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare class ACKLifecycleManager {
|
|
18
|
+
private acks;
|
|
19
|
+
mark(messageId: string, stage: AckStage, note?: string, errorCode?: number): void;
|
|
20
|
+
get(messageId: string): AckState | undefined;
|
|
21
|
+
recent(limit?: number): AckState[];
|
|
22
|
+
reconcileLateAck(messageId: string, stage: AckStage): void;
|
|
23
|
+
toJSON(): AckState[];
|
|
24
|
+
fromJSON(states: AckState[]): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface ActivityRecord {
|
|
2
|
+
task_id: string;
|
|
3
|
+
repo_id: string;
|
|
4
|
+
worktree_id: string;
|
|
5
|
+
branch: string;
|
|
6
|
+
description: string;
|
|
7
|
+
timestamp: string;
|
|
8
|
+
}
|
|
9
|
+
export interface BufferStrategy {
|
|
10
|
+
prune(records: ActivityRecord[], maxEntries: number): ActivityRecord[];
|
|
11
|
+
}
|
|
12
|
+
export declare class MaxEntriesStrategy implements BufferStrategy {
|
|
13
|
+
prune(records: ActivityRecord[], maxEntries: number): ActivityRecord[];
|
|
14
|
+
}
|
|
15
|
+
export declare class ActivityBuffer {
|
|
16
|
+
private records;
|
|
17
|
+
private maxEntries;
|
|
18
|
+
private strategy;
|
|
19
|
+
constructor(opts?: {
|
|
20
|
+
maxEntries?: number;
|
|
21
|
+
strategy?: BufferStrategy;
|
|
22
|
+
});
|
|
23
|
+
upsert(rec: ActivityRecord): void;
|
|
24
|
+
remove(taskId: string): void;
|
|
25
|
+
list(): ActivityRecord[];
|
|
26
|
+
recent(limit?: number): ActivityRecord[];
|
|
27
|
+
reconcile(knownTaskIds: Set<string>): void;
|
|
28
|
+
private prune;
|
|
29
|
+
toJSON(): ActivityRecord[];
|
|
30
|
+
fromJSON(records: ActivityRecord[]): void;
|
|
31
|
+
}
|