@tracewayapp/opamp 0.0.0-stage → 2.0.0-beta.1

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.
@@ -0,0 +1,150 @@
1
+ /** AgentCapabilities from the OpAMP spec. */
2
+ declare const AgentCapabilities: {
3
+ readonly ReportsStatus: 1;
4
+ readonly AcceptsRemoteConfig: 2;
5
+ readonly ReportsEffectiveConfig: 4;
6
+ readonly ReportsHealth: 2048;
7
+ readonly ReportsRemoteConfig: 4096;
8
+ readonly ReportsHeartbeat: 8192;
9
+ };
10
+ declare const AgentToServerFlags: {
11
+ readonly RequestInstanceUid: 1;
12
+ };
13
+ declare const ServerToAgentFlags: {
14
+ readonly ReportFullState: 1;
15
+ };
16
+ declare enum RemoteConfigStatus {
17
+ Unset = 0,
18
+ Applied = 1,
19
+ Applying = 2,
20
+ Failed = 3
21
+ }
22
+ declare enum ServerErrorType {
23
+ Unknown = 0,
24
+ BadRequest = 1,
25
+ Unavailable = 2
26
+ }
27
+ type AttributeValue = string | boolean | number | string[];
28
+ interface AgentToServer {
29
+ instanceUid: Uint8Array;
30
+ sequenceNum: number;
31
+ agentDescription?: {
32
+ identifying: Record<string, AttributeValue>;
33
+ nonIdentifying: Record<string, AttributeValue>;
34
+ };
35
+ capabilities: number;
36
+ remoteConfigStatus?: {
37
+ lastRemoteConfigHash: Uint8Array;
38
+ status: RemoteConfigStatus;
39
+ errorMessage?: string;
40
+ };
41
+ agentDisconnect?: boolean;
42
+ flags?: number;
43
+ customCapabilities?: string[];
44
+ }
45
+ interface AgentConfigObject {
46
+ body: Uint8Array;
47
+ contentType: string;
48
+ }
49
+ interface ServerToAgent {
50
+ instanceUid?: Uint8Array;
51
+ errorResponse?: {
52
+ type: ServerErrorType;
53
+ message: string;
54
+ retryAfterMs?: number;
55
+ };
56
+ remoteConfig?: {
57
+ configMap: Record<string, AgentConfigObject>;
58
+ configHash: Uint8Array;
59
+ };
60
+ heartbeatIntervalSeconds?: number;
61
+ flags: number;
62
+ capabilities: number;
63
+ newInstanceUid?: Uint8Array;
64
+ customMessage?: {
65
+ capability: string;
66
+ type: string;
67
+ data: Uint8Array;
68
+ };
69
+ }
70
+ declare function encodeAgentToServer(msg: AgentToServer): Uint8Array;
71
+ declare function decodeServerToAgent(buf: Uint8Array): ServerToAgent;
72
+ /** Encodes the parts of a ServerToAgent this client reads; for mock servers in tests. */
73
+ declare function encodeServerToAgent(msg: Omit<ServerToAgent, "errorResponse" | "customMessage">): Uint8Array;
74
+
75
+ interface AgentDescription {
76
+ identifying: Record<string, AttributeValue>;
77
+ nonIdentifying: Record<string, AttributeValue>;
78
+ }
79
+ interface RemoteConfig {
80
+ configMap: Record<string, AgentConfigObject>;
81
+ configHash: Uint8Array;
82
+ }
83
+ type ApplyResult = {
84
+ applied: true;
85
+ } | {
86
+ applied: false;
87
+ errorMessage: string;
88
+ };
89
+ interface OpampClientOptions {
90
+ /** The server's OpAMP endpoint, e.g. https://traceway.example.com/api/otel/v1/opamp. */
91
+ endpoint: string;
92
+ headers?: Record<string, string>;
93
+ instanceUid: Uint8Array;
94
+ capabilities: number;
95
+ customCapabilities?: string[];
96
+ /** Read on every poll: the client sends its full state each time, so a stateless server can answer. */
97
+ describe: () => AgentDescription;
98
+ onRemoteConfig: (config: RemoteConfig) => ApplyResult;
99
+ /** Hash of the config applied on an earlier page, so the server does not resend what is already in effect. */
100
+ appliedConfigHash?: Uint8Array;
101
+ onHeartbeatChange?: (seconds: number) => void;
102
+ onInstanceUidChange?: (uid: Uint8Array) => void;
103
+ /** Called once when the server rejects the credentials; the client stops polling. */
104
+ onUnauthorized?: () => void;
105
+ /** A pre-OpAMP server: stop polling and let the SDK use its legacy protocol. */
106
+ onUnsupported?: () => void;
107
+ /** Fetch failed, including a missing CORS preflight on older cross-origin servers. */
108
+ onUnavailable?: () => void;
109
+ onConnected?: () => void;
110
+ defaultPollIntervalMs?: number;
111
+ fetchImpl?: typeof fetch;
112
+ requestTimeoutMs?: number;
113
+ }
114
+ declare function uuidString(bytes: Uint8Array): string;
115
+ /**
116
+ * An OpAMP client for the plain-HTTP transport: it polls, applies the remote
117
+ * config the server offers and reports the result on the next poll. Polling
118
+ * follows the server's heartbeat interval, backs off on errors and honours
119
+ * Retry-After; a 413 is not retried and a 401/403 stops the client.
120
+ */
121
+ declare class OpampHttpClient {
122
+ private readonly options;
123
+ private uid;
124
+ private sequenceNum;
125
+ private status;
126
+ private intervalMs;
127
+ private backoffMs;
128
+ private timer;
129
+ private inFlight;
130
+ private stopped;
131
+ private lastPollAt;
132
+ private readonly fetchImpl;
133
+ constructor(options: OpampClientOptions);
134
+ start(): void;
135
+ stop(): void;
136
+ pollIntervalMs(): number;
137
+ millisSinceLastPoll(): number;
138
+ /** Polls now unless a poll is running or the client is backing off after an error. */
139
+ poll(): Promise<void>;
140
+ /** Polls with the current description even if a poll is under way, e.g. right after a targeting attribute changed. */
141
+ refresh(): Promise<void>;
142
+ private schedule;
143
+ private exchange;
144
+ private exchangeWithSignal;
145
+ private handle;
146
+ private backOff;
147
+ private send;
148
+ }
149
+
150
+ export { AgentCapabilities, type AgentConfigObject, type AgentDescription, type AgentToServer, AgentToServerFlags, type ApplyResult, type AttributeValue, type OpampClientOptions, OpampHttpClient, type RemoteConfig, RemoteConfigStatus, ServerErrorType, type ServerToAgent, ServerToAgentFlags, decodeServerToAgent, encodeAgentToServer, encodeServerToAgent, uuidString };
@@ -0,0 +1,150 @@
1
+ /** AgentCapabilities from the OpAMP spec. */
2
+ declare const AgentCapabilities: {
3
+ readonly ReportsStatus: 1;
4
+ readonly AcceptsRemoteConfig: 2;
5
+ readonly ReportsEffectiveConfig: 4;
6
+ readonly ReportsHealth: 2048;
7
+ readonly ReportsRemoteConfig: 4096;
8
+ readonly ReportsHeartbeat: 8192;
9
+ };
10
+ declare const AgentToServerFlags: {
11
+ readonly RequestInstanceUid: 1;
12
+ };
13
+ declare const ServerToAgentFlags: {
14
+ readonly ReportFullState: 1;
15
+ };
16
+ declare enum RemoteConfigStatus {
17
+ Unset = 0,
18
+ Applied = 1,
19
+ Applying = 2,
20
+ Failed = 3
21
+ }
22
+ declare enum ServerErrorType {
23
+ Unknown = 0,
24
+ BadRequest = 1,
25
+ Unavailable = 2
26
+ }
27
+ type AttributeValue = string | boolean | number | string[];
28
+ interface AgentToServer {
29
+ instanceUid: Uint8Array;
30
+ sequenceNum: number;
31
+ agentDescription?: {
32
+ identifying: Record<string, AttributeValue>;
33
+ nonIdentifying: Record<string, AttributeValue>;
34
+ };
35
+ capabilities: number;
36
+ remoteConfigStatus?: {
37
+ lastRemoteConfigHash: Uint8Array;
38
+ status: RemoteConfigStatus;
39
+ errorMessage?: string;
40
+ };
41
+ agentDisconnect?: boolean;
42
+ flags?: number;
43
+ customCapabilities?: string[];
44
+ }
45
+ interface AgentConfigObject {
46
+ body: Uint8Array;
47
+ contentType: string;
48
+ }
49
+ interface ServerToAgent {
50
+ instanceUid?: Uint8Array;
51
+ errorResponse?: {
52
+ type: ServerErrorType;
53
+ message: string;
54
+ retryAfterMs?: number;
55
+ };
56
+ remoteConfig?: {
57
+ configMap: Record<string, AgentConfigObject>;
58
+ configHash: Uint8Array;
59
+ };
60
+ heartbeatIntervalSeconds?: number;
61
+ flags: number;
62
+ capabilities: number;
63
+ newInstanceUid?: Uint8Array;
64
+ customMessage?: {
65
+ capability: string;
66
+ type: string;
67
+ data: Uint8Array;
68
+ };
69
+ }
70
+ declare function encodeAgentToServer(msg: AgentToServer): Uint8Array;
71
+ declare function decodeServerToAgent(buf: Uint8Array): ServerToAgent;
72
+ /** Encodes the parts of a ServerToAgent this client reads; for mock servers in tests. */
73
+ declare function encodeServerToAgent(msg: Omit<ServerToAgent, "errorResponse" | "customMessage">): Uint8Array;
74
+
75
+ interface AgentDescription {
76
+ identifying: Record<string, AttributeValue>;
77
+ nonIdentifying: Record<string, AttributeValue>;
78
+ }
79
+ interface RemoteConfig {
80
+ configMap: Record<string, AgentConfigObject>;
81
+ configHash: Uint8Array;
82
+ }
83
+ type ApplyResult = {
84
+ applied: true;
85
+ } | {
86
+ applied: false;
87
+ errorMessage: string;
88
+ };
89
+ interface OpampClientOptions {
90
+ /** The server's OpAMP endpoint, e.g. https://traceway.example.com/api/otel/v1/opamp. */
91
+ endpoint: string;
92
+ headers?: Record<string, string>;
93
+ instanceUid: Uint8Array;
94
+ capabilities: number;
95
+ customCapabilities?: string[];
96
+ /** Read on every poll: the client sends its full state each time, so a stateless server can answer. */
97
+ describe: () => AgentDescription;
98
+ onRemoteConfig: (config: RemoteConfig) => ApplyResult;
99
+ /** Hash of the config applied on an earlier page, so the server does not resend what is already in effect. */
100
+ appliedConfigHash?: Uint8Array;
101
+ onHeartbeatChange?: (seconds: number) => void;
102
+ onInstanceUidChange?: (uid: Uint8Array) => void;
103
+ /** Called once when the server rejects the credentials; the client stops polling. */
104
+ onUnauthorized?: () => void;
105
+ /** A pre-OpAMP server: stop polling and let the SDK use its legacy protocol. */
106
+ onUnsupported?: () => void;
107
+ /** Fetch failed, including a missing CORS preflight on older cross-origin servers. */
108
+ onUnavailable?: () => void;
109
+ onConnected?: () => void;
110
+ defaultPollIntervalMs?: number;
111
+ fetchImpl?: typeof fetch;
112
+ requestTimeoutMs?: number;
113
+ }
114
+ declare function uuidString(bytes: Uint8Array): string;
115
+ /**
116
+ * An OpAMP client for the plain-HTTP transport: it polls, applies the remote
117
+ * config the server offers and reports the result on the next poll. Polling
118
+ * follows the server's heartbeat interval, backs off on errors and honours
119
+ * Retry-After; a 413 is not retried and a 401/403 stops the client.
120
+ */
121
+ declare class OpampHttpClient {
122
+ private readonly options;
123
+ private uid;
124
+ private sequenceNum;
125
+ private status;
126
+ private intervalMs;
127
+ private backoffMs;
128
+ private timer;
129
+ private inFlight;
130
+ private stopped;
131
+ private lastPollAt;
132
+ private readonly fetchImpl;
133
+ constructor(options: OpampClientOptions);
134
+ start(): void;
135
+ stop(): void;
136
+ pollIntervalMs(): number;
137
+ millisSinceLastPoll(): number;
138
+ /** Polls now unless a poll is running or the client is backing off after an error. */
139
+ poll(): Promise<void>;
140
+ /** Polls with the current description even if a poll is under way, e.g. right after a targeting attribute changed. */
141
+ refresh(): Promise<void>;
142
+ private schedule;
143
+ private exchange;
144
+ private exchangeWithSignal;
145
+ private handle;
146
+ private backOff;
147
+ private send;
148
+ }
149
+
150
+ export { AgentCapabilities, type AgentConfigObject, type AgentDescription, type AgentToServer, AgentToServerFlags, type ApplyResult, type AttributeValue, type OpampClientOptions, OpampHttpClient, type RemoteConfig, RemoteConfigStatus, ServerErrorType, type ServerToAgent, ServerToAgentFlags, decodeServerToAgent, encodeAgentToServer, encodeServerToAgent, uuidString };