-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
128 lines (122 loc) · 4.35 KB
/
types.ts
File metadata and controls
128 lines (122 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import type { JobId, TraceId } from "@arcp/core";
import type { Logger } from "@arcp/core/logger";
import type {
AuthScheme,
Capabilities,
ClientIdentity,
Envelope,
JobResultPayload,
Lease,
LeaseConstraints,
} from "@arcp/core/messages";
/**
* v1.1 §6.5 — automatic event acknowledgement options. When enabled, the
* client periodically emits `session.ack` with the highest observed
* `event_seq` to allow the runtime to free buffered events earlier than
* the time-based window.
*
* Coalescing: an ack is emitted at most every `intervalMs` (default 250)
* or after `minSeqDelta` new events (default 32), whichever comes first.
*/
export interface ClientAutoAckOptions {
intervalMs?: number;
minSeqDelta?: number;
}
export interface ARCPClientOptions {
/** Client identity broadcast in `session.hello`. */
client: ClientIdentity;
/** Capabilities the client requests/supports. */
capabilities?: Capabilities;
/** Auth scheme to use. v1.0 supports `"bearer"` only. */
authScheme: AuthScheme;
/** Token, where the scheme requires one. */
token?: string;
/** Logger. */
logger?: Logger;
/** Handshake timeout in milliseconds. Default 5000. */
handshakeTimeoutMs?: number;
/**
* v1.1 §6.2 — feature flags this client advertises. Defaults to every v1.1
* feature.
*/
features?: readonly string[];
/**
* v1.1 §6.5 — automatic `session.ack` emission. `true` enables defaults
* (250ms, 32 events). `false` disables auto-ack entirely. Default `false`.
*/
autoAck?: boolean | ClientAutoAckOptions;
}
/** Inbound-message handler on the client side. */
export type ClientHandler = (env: Envelope) => Promise<void> | void;
/**
* Handle returned by `ARCPClient.submit`, exposes job lifecycle (§7.3).
*
* Resolve `done` to obtain the terminal `job.result.payload`; the promise
* rejects with an `ARCPError` if the runtime emitted `job.error` instead.
*
* v1.1: when the runtime streams the result via `result_chunk` events, the
* `done` payload carries `result_id` instead of an inline `result`. Use
* `collectChunks` to assemble the chunks.
*/
export interface JobHandle {
/** Server-assigned `job.accepted.payload.job_id`. */
readonly jobId: JobId;
/** Effective lease as returned in `job.accepted`. */
readonly lease: Lease;
/** Trace id echoed by the runtime, if any. */
readonly traceId: TraceId | undefined;
/**
* Resolved agent identifier echoed by the runtime
* (v1.1 `name@version` form when versioning is in play).
*/
readonly agent: string | undefined;
/** v1.1 — lease constraints echoed by the runtime. */
readonly leaseConstraints: LeaseConstraints | undefined;
/** v1.1 — initial budget echoed by the runtime. */
readonly budget: Readonly<Record<string, number>> | undefined;
/** Promise that resolves to the final `job.result` payload. */
readonly done: Promise<JobResultPayload>;
/**
* v1.1 §8.4 — assemble streamed chunks into a single buffer. Resolves
* after `done`. Throws if the job did not stream a chunked result.
*/
collectChunks(): Promise<Buffer | string>;
}
/**
* v1.1 §7.6 — handle returned by `ARCPClient.subscribe`. Use `unsubscribe()`
* to release the subscription.
*/
export interface JobSubscription {
readonly jobId: JobId;
readonly subscribedFrom: number;
readonly replayed: boolean;
unsubscribe(): Promise<void>;
}
/**
* Options for `ARCPClient.submit`. Mirrors `job.submit.payload` (§7.1) plus
* client-side conveniences (`traceId`, `signal`).
*/
export interface SubmitOptions {
/** Registered agent name (optionally `name@version`) on the runtime. */
agent: string;
/** Arbitrary JSON-serializable input forwarded to the agent. */
input?: unknown;
/**
* Lease request (§9.1). Runtime MAY narrow but MUST NOT broaden.
* Capability namespace → list of glob patterns.
*/
lease?: Lease;
/** v1.1 §9.5 — lease constraints (currently `expires_at`). */
leaseConstraints?: LeaseConstraints;
/**
* Logical idempotency key (§7.2). Same `(principal, idempotencyKey)`
* within the runtime's TTL returns the same `job_id`.
*/
idempotencyKey?: string;
/** Job-level deadline. Exceeding it produces `TIMEOUT`. */
maxRuntimeSec?: number;
/** Explicit W3C 32-hex trace id. Runtime generates one if omitted. */
traceId?: TraceId;
/** Cancel signal. Aborting triggers `cancelJob(jobId)`. */
signal?: AbortSignal;
}