@nebulaos/client 0.1.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 +4 -0
- package/dist/index.d.mts +629 -0
- package/dist/index.d.ts +629 -0
- package/dist/index.js +1819 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1765 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +74 -0
package/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
import { BaseAgent, Workflow, Tool, LogLevel, ILogger, ITracingProvider, SpanStartInput, ActiveSpan, TracingContext, IDomainEventsExporter, NebulaEvent } from '@nebulaos/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { IHttpClient, ITelemetryExporter, TelemetryEventV1, IMemory, HttpResponse } from '@nebulaos/types';
|
|
4
|
+
export { HttpResponse, IHttpClient } from '@nebulaos/types';
|
|
5
|
+
import { Socket } from 'socket.io-client';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Factory function that creates a new agent instance.
|
|
9
|
+
* Used to avoid memory/context leakage between executions.
|
|
10
|
+
*/
|
|
11
|
+
type AgentFactory = () => BaseAgent;
|
|
12
|
+
/**
|
|
13
|
+
* Input that can be either an agent instance (backwards compat) or a factory function.
|
|
14
|
+
*/
|
|
15
|
+
type AgentOrFactory = BaseAgent | AgentFactory;
|
|
16
|
+
declare class Registry {
|
|
17
|
+
private readonly agentsById;
|
|
18
|
+
private readonly agentsByName;
|
|
19
|
+
private readonly workflows;
|
|
20
|
+
private readonly toolsById;
|
|
21
|
+
private httpClient?;
|
|
22
|
+
/**
|
|
23
|
+
* Sets the HTTP client to be injected into agents for tool execution.
|
|
24
|
+
*/
|
|
25
|
+
setHttpClient(client: IHttpClient): void;
|
|
26
|
+
/**
|
|
27
|
+
* Registers an agent factory or instance.
|
|
28
|
+
*
|
|
29
|
+
* If an instance is passed directly (backwards compatibility), it will be wrapped
|
|
30
|
+
* in a factory that always returns the same instance. For proper isolation between
|
|
31
|
+
* executions, prefer passing a factory function.
|
|
32
|
+
*
|
|
33
|
+
* @param agentOrFactory - Agent instance or factory function
|
|
34
|
+
*/
|
|
35
|
+
registerAgent(agentOrFactory: AgentOrFactory): void;
|
|
36
|
+
registerWorkflow(workflow: Workflow): void;
|
|
37
|
+
registerTool(tool: Tool): void;
|
|
38
|
+
/**
|
|
39
|
+
* Gets a new agent instance by id or name.
|
|
40
|
+
*
|
|
41
|
+
* Each call creates a fresh instance via the registered factory,
|
|
42
|
+
* ensuring no memory/context leakage between executions.
|
|
43
|
+
*
|
|
44
|
+
* @param idOrName - Agent id or name
|
|
45
|
+
* @returns A new agent instance
|
|
46
|
+
*/
|
|
47
|
+
getAgent(idOrName: string): BaseAgent;
|
|
48
|
+
getWorkflow(id: string): Workflow;
|
|
49
|
+
getTool(id: string): Tool;
|
|
50
|
+
/**
|
|
51
|
+
* Lists all registered agents by creating a sample instance of each.
|
|
52
|
+
*
|
|
53
|
+
* Used for Cloud registration where we need agent metadata (name, id, tools, etc).
|
|
54
|
+
* Creates one instance per agent to extract metadata.
|
|
55
|
+
*
|
|
56
|
+
* @returns Array of agent instances (one per registered agent)
|
|
57
|
+
*/
|
|
58
|
+
listAgents(): BaseAgent[];
|
|
59
|
+
listTools(): Tool[];
|
|
60
|
+
listWorkflows(): Workflow[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
declare const serverConfigSchema: z.ZodObject<{
|
|
64
|
+
url: z.ZodString;
|
|
65
|
+
apiKey: z.ZodString;
|
|
66
|
+
batchSize: z.ZodOptional<z.ZodNumber>;
|
|
67
|
+
flushInterval: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
}, "strip", z.ZodTypeAny, {
|
|
69
|
+
url: string;
|
|
70
|
+
apiKey: string;
|
|
71
|
+
batchSize?: number | undefined;
|
|
72
|
+
flushInterval?: number | undefined;
|
|
73
|
+
}, {
|
|
74
|
+
url: string;
|
|
75
|
+
apiKey: string;
|
|
76
|
+
batchSize?: number | undefined;
|
|
77
|
+
flushInterval?: number | undefined;
|
|
78
|
+
}>;
|
|
79
|
+
type ServerConfig = z.infer<typeof serverConfigSchema>;
|
|
80
|
+
declare const otelTracingConfigSchema: z.ZodObject<{
|
|
81
|
+
/** OTLP HTTP endpoint. Defaults to http://localhost:4318/v1/traces */
|
|
82
|
+
otlpEndpoint: z.ZodOptional<z.ZodString>;
|
|
83
|
+
}, "strip", z.ZodTypeAny, {
|
|
84
|
+
otlpEndpoint?: string | undefined;
|
|
85
|
+
}, {
|
|
86
|
+
otlpEndpoint?: string | undefined;
|
|
87
|
+
}>;
|
|
88
|
+
type OTelTracingClientConfig = z.infer<typeof otelTracingConfigSchema>;
|
|
89
|
+
declare const clientConfigSchema: z.ZodObject<{
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated clientId is now automatically extracted from the API key.
|
|
92
|
+
* This field is optional and only used for local identification/logging.
|
|
93
|
+
*/
|
|
94
|
+
clientId: z.ZodOptional<z.ZodString>;
|
|
95
|
+
/**
|
|
96
|
+
* List of agents to register. Can be either:
|
|
97
|
+
* - Agent instances (backwards compatible, but may cause memory leakage between executions)
|
|
98
|
+
* - Factory functions that return agent instances (recommended for proper isolation)
|
|
99
|
+
*/
|
|
100
|
+
agents: z.ZodOptional<z.ZodArray<z.ZodType<AgentOrFactory, z.ZodTypeDef, AgentOrFactory>, "many">>;
|
|
101
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodType<Tool<any, any>, z.ZodTypeDef, Tool<any, any>>, "many">>;
|
|
102
|
+
workflows: z.ZodOptional<z.ZodArray<z.ZodType<Workflow<any, any>, z.ZodTypeDef, Workflow<any, any>>, "many">>;
|
|
103
|
+
server: z.ZodOptional<z.ZodObject<{
|
|
104
|
+
url: z.ZodString;
|
|
105
|
+
apiKey: z.ZodString;
|
|
106
|
+
batchSize: z.ZodOptional<z.ZodNumber>;
|
|
107
|
+
flushInterval: z.ZodOptional<z.ZodNumber>;
|
|
108
|
+
}, "strip", z.ZodTypeAny, {
|
|
109
|
+
url: string;
|
|
110
|
+
apiKey: string;
|
|
111
|
+
batchSize?: number | undefined;
|
|
112
|
+
flushInterval?: number | undefined;
|
|
113
|
+
}, {
|
|
114
|
+
url: string;
|
|
115
|
+
apiKey: string;
|
|
116
|
+
batchSize?: number | undefined;
|
|
117
|
+
flushInterval?: number | undefined;
|
|
118
|
+
}>>;
|
|
119
|
+
/**
|
|
120
|
+
* OpenTelemetry tracing configuration.
|
|
121
|
+
* When set, the client will set up an OTel TracerProvider and export
|
|
122
|
+
* spans directly to the configured OTLP endpoint.
|
|
123
|
+
*/
|
|
124
|
+
tracing: z.ZodOptional<z.ZodObject<{
|
|
125
|
+
/** OTLP HTTP endpoint. Defaults to http://localhost:4318/v1/traces */
|
|
126
|
+
otlpEndpoint: z.ZodOptional<z.ZodString>;
|
|
127
|
+
}, "strip", z.ZodTypeAny, {
|
|
128
|
+
otlpEndpoint?: string | undefined;
|
|
129
|
+
}, {
|
|
130
|
+
otlpEndpoint?: string | undefined;
|
|
131
|
+
}>>;
|
|
132
|
+
/**
|
|
133
|
+
* Client-side log level (same semantics as @nebulaos/core ConsoleLogger).
|
|
134
|
+
* When set to anything other than "none", the client will emit debug logs for
|
|
135
|
+
* WS/HTTP communication (without full payloads).
|
|
136
|
+
*/
|
|
137
|
+
logLevel: z.ZodOptional<z.ZodType<LogLevel, z.ZodTypeDef, LogLevel>>;
|
|
138
|
+
debug: z.ZodOptional<z.ZodObject<{
|
|
139
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
140
|
+
level: z.ZodOptional<z.ZodType<LogLevel, z.ZodTypeDef, LogLevel>>;
|
|
141
|
+
}, "strip", z.ZodTypeAny, {
|
|
142
|
+
enabled?: boolean | undefined;
|
|
143
|
+
level?: LogLevel | undefined;
|
|
144
|
+
}, {
|
|
145
|
+
enabled?: boolean | undefined;
|
|
146
|
+
level?: LogLevel | undefined;
|
|
147
|
+
}>>;
|
|
148
|
+
}, "strip", z.ZodTypeAny, {
|
|
149
|
+
clientId?: string | undefined;
|
|
150
|
+
agents?: AgentOrFactory[] | undefined;
|
|
151
|
+
tools?: Tool<any, any>[] | undefined;
|
|
152
|
+
workflows?: Workflow<any, any>[] | undefined;
|
|
153
|
+
server?: {
|
|
154
|
+
url: string;
|
|
155
|
+
apiKey: string;
|
|
156
|
+
batchSize?: number | undefined;
|
|
157
|
+
flushInterval?: number | undefined;
|
|
158
|
+
} | undefined;
|
|
159
|
+
tracing?: {
|
|
160
|
+
otlpEndpoint?: string | undefined;
|
|
161
|
+
} | undefined;
|
|
162
|
+
debug?: {
|
|
163
|
+
enabled?: boolean | undefined;
|
|
164
|
+
level?: LogLevel | undefined;
|
|
165
|
+
} | undefined;
|
|
166
|
+
logLevel?: LogLevel | undefined;
|
|
167
|
+
}, {
|
|
168
|
+
clientId?: string | undefined;
|
|
169
|
+
agents?: AgentOrFactory[] | undefined;
|
|
170
|
+
tools?: Tool<any, any>[] | undefined;
|
|
171
|
+
workflows?: Workflow<any, any>[] | undefined;
|
|
172
|
+
server?: {
|
|
173
|
+
url: string;
|
|
174
|
+
apiKey: string;
|
|
175
|
+
batchSize?: number | undefined;
|
|
176
|
+
flushInterval?: number | undefined;
|
|
177
|
+
} | undefined;
|
|
178
|
+
tracing?: {
|
|
179
|
+
otlpEndpoint?: string | undefined;
|
|
180
|
+
} | undefined;
|
|
181
|
+
debug?: {
|
|
182
|
+
enabled?: boolean | undefined;
|
|
183
|
+
level?: LogLevel | undefined;
|
|
184
|
+
} | undefined;
|
|
185
|
+
logLevel?: LogLevel | undefined;
|
|
186
|
+
}>;
|
|
187
|
+
type ClientConfig = z.infer<typeof clientConfigSchema>;
|
|
188
|
+
|
|
189
|
+
declare class NebulaClient {
|
|
190
|
+
private readonly config;
|
|
191
|
+
private readonly registry;
|
|
192
|
+
private readonly serverConnection?;
|
|
193
|
+
private readonly telemetryExporter?;
|
|
194
|
+
private readonly domainEventsExporter?;
|
|
195
|
+
private readonly logger?;
|
|
196
|
+
constructor(config: ClientConfig);
|
|
197
|
+
registerAgent(agent: Parameters<Registry["registerAgent"]>[0]): void;
|
|
198
|
+
registerTool(tool: Parameters<Registry["registerTool"]>[0]): void;
|
|
199
|
+
registerWorkflow(workflow: Parameters<Registry["registerWorkflow"]>[0]): void;
|
|
200
|
+
start(): Promise<void>;
|
|
201
|
+
stop(): Promise<void>;
|
|
202
|
+
getClientId(): string | undefined;
|
|
203
|
+
isConnected(): boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Sets global client context for skills to access API key and server URL
|
|
206
|
+
* This allows skills like RagOpenAISkill to automatically use the client's credentials
|
|
207
|
+
*/
|
|
208
|
+
private setGlobalClientContext;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
declare class TelemetryService {
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
declare class Batcher {
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* WebSocket Event Types for NebulaOS Client-Server Communication
|
|
219
|
+
*/
|
|
220
|
+
/**
|
|
221
|
+
* Resource types supported by the Cloud runtime catalog.
|
|
222
|
+
*/
|
|
223
|
+
type ResourceType = "agent" | "workflow" | "tool";
|
|
224
|
+
/**
|
|
225
|
+
* Resource registration payload (Cloud RegisterClientDto compatible).
|
|
226
|
+
*/
|
|
227
|
+
interface ResourceRegistration {
|
|
228
|
+
type: ResourceType;
|
|
229
|
+
runtimeResourceId: string;
|
|
230
|
+
displayName: string;
|
|
231
|
+
kind?: string;
|
|
232
|
+
description?: string;
|
|
233
|
+
/**
|
|
234
|
+
* Optional resource definition (e.g., workflow graph for visualization).
|
|
235
|
+
*/
|
|
236
|
+
definition?: Record<string, unknown>;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Payload for full client registration
|
|
240
|
+
* Note: clientId is now automatically extracted from the API key
|
|
241
|
+
*/
|
|
242
|
+
interface RegisterClientPayload {
|
|
243
|
+
instanceId: string;
|
|
244
|
+
resources: ResourceRegistration[];
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Response from client registration
|
|
248
|
+
*/
|
|
249
|
+
interface RegisterResponse {
|
|
250
|
+
success: boolean;
|
|
251
|
+
registration?: {
|
|
252
|
+
clientId: string;
|
|
253
|
+
instanceId: string;
|
|
254
|
+
};
|
|
255
|
+
error?: string;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Payload for an explicit graceful shutdown notice (best-effort).
|
|
259
|
+
* Note: clientId is now automatically extracted from the API key
|
|
260
|
+
*/
|
|
261
|
+
interface ShutdownPayload {
|
|
262
|
+
instanceId: string;
|
|
263
|
+
reason?: string;
|
|
264
|
+
}
|
|
265
|
+
interface ShutdownResponse {
|
|
266
|
+
success: boolean;
|
|
267
|
+
error?: string;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Base command payload
|
|
271
|
+
*/
|
|
272
|
+
interface BaseCommandPayload {
|
|
273
|
+
commandId: string;
|
|
274
|
+
/**
|
|
275
|
+
* Stable Cloud execution id (Execution.id). Must be echoed back in command responses
|
|
276
|
+
* and used as telemetry executionId to enable trace lookup by executionId.
|
|
277
|
+
*/
|
|
278
|
+
executionId: string;
|
|
279
|
+
type: ResourceType;
|
|
280
|
+
targetName: string;
|
|
281
|
+
input: unknown;
|
|
282
|
+
options?: unknown;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Agent execution command
|
|
286
|
+
*/
|
|
287
|
+
interface AgentCommandPayload extends BaseCommandPayload {
|
|
288
|
+
type: "agent";
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Workflow execution command
|
|
292
|
+
*/
|
|
293
|
+
interface WorkflowCommandPayload extends BaseCommandPayload {
|
|
294
|
+
type: "workflow";
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Tool execution command
|
|
298
|
+
*/
|
|
299
|
+
interface ToolCommandPayload extends BaseCommandPayload {
|
|
300
|
+
type: "tool";
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Command execution response
|
|
304
|
+
*/
|
|
305
|
+
interface CommandResponse {
|
|
306
|
+
commandId: string;
|
|
307
|
+
executionId: string;
|
|
308
|
+
result: unknown;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Command execution error
|
|
312
|
+
*/
|
|
313
|
+
interface CommandError {
|
|
314
|
+
commandId: string;
|
|
315
|
+
error: {
|
|
316
|
+
code: string;
|
|
317
|
+
message: string;
|
|
318
|
+
details?: unknown;
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* WebSocket client-to-server events
|
|
323
|
+
*/
|
|
324
|
+
interface ClientToServerEvents {
|
|
325
|
+
"client:register:full": (payload: RegisterClientPayload, callback: (response: RegisterResponse) => void) => void;
|
|
326
|
+
"client:snapshot": (payload: RegisterClientPayload) => void;
|
|
327
|
+
"client:shutdown": (payload: ShutdownPayload, callback: (response: ShutdownResponse) => void) => void;
|
|
328
|
+
"command:response": (response: CommandResponse) => void;
|
|
329
|
+
"command:error": (error: CommandError) => void;
|
|
330
|
+
"telemetry:batch": (payload: unknown) => void;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* WebSocket server-to-client events
|
|
334
|
+
*/
|
|
335
|
+
interface ServerToClientEvents {
|
|
336
|
+
"client:online": () => void;
|
|
337
|
+
"command:execute:agent": (payload: AgentCommandPayload) => void;
|
|
338
|
+
"command:execute:workflow": (payload: WorkflowCommandPayload) => void;
|
|
339
|
+
"command:execute:tool": (payload: ToolCommandPayload) => void;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
interface ServerConnectionConfig {
|
|
343
|
+
url: string;
|
|
344
|
+
apiKey: string;
|
|
345
|
+
/**
|
|
346
|
+
* Stable semantic id defined by the developer/runtime deployment.
|
|
347
|
+
* This value MUST be stable across restarts, otherwise the Cloud will treat it as a new client.
|
|
348
|
+
*/
|
|
349
|
+
clientId: string;
|
|
350
|
+
/**
|
|
351
|
+
* Unique instance identifier for this running process/container/VM.
|
|
352
|
+
* Defaults to a random UUID if not provided.
|
|
353
|
+
*/
|
|
354
|
+
instanceId?: string;
|
|
355
|
+
/**
|
|
356
|
+
* Optional: snapshot interval for presence/availability refresh.
|
|
357
|
+
* Defaults to 60 seconds.
|
|
358
|
+
*/
|
|
359
|
+
snapshotIntervalMs?: number;
|
|
360
|
+
}
|
|
361
|
+
declare class ServerConnection {
|
|
362
|
+
private readonly config;
|
|
363
|
+
private socket;
|
|
364
|
+
private reconnectAttempts;
|
|
365
|
+
private registry?;
|
|
366
|
+
private agents;
|
|
367
|
+
private tools;
|
|
368
|
+
private workflows;
|
|
369
|
+
private snapshotTimer?;
|
|
370
|
+
private connectionAttempted;
|
|
371
|
+
private lastConnectError;
|
|
372
|
+
private hasAuthenticated;
|
|
373
|
+
private readonly logger?;
|
|
374
|
+
private readonly commandStarts;
|
|
375
|
+
private readonly clientId;
|
|
376
|
+
private readonly instanceId;
|
|
377
|
+
constructor(config: ServerConnectionConfig, logger?: ILogger);
|
|
378
|
+
/**
|
|
379
|
+
* Sets the registry for executing agents and workflows.
|
|
380
|
+
*/
|
|
381
|
+
setRegistry(registry: Registry): void;
|
|
382
|
+
/**
|
|
383
|
+
* Stores agents and workflows for registration.
|
|
384
|
+
*/
|
|
385
|
+
registerResources(agents: BaseAgent[], tools: Tool[], workflows: Workflow[]): void;
|
|
386
|
+
private collectAgentsFromWorkflows;
|
|
387
|
+
private collectToolsFromAgents;
|
|
388
|
+
/**
|
|
389
|
+
* Creates and configures the Socket.IO client.
|
|
390
|
+
*/
|
|
391
|
+
private createSocket;
|
|
392
|
+
/**
|
|
393
|
+
* Sets up Socket.IO event handlers
|
|
394
|
+
*/
|
|
395
|
+
private setupEventHandlers;
|
|
396
|
+
/**
|
|
397
|
+
* Handles agent execution commands from the server
|
|
398
|
+
*/
|
|
399
|
+
private handleAgentCommand;
|
|
400
|
+
/**
|
|
401
|
+
* Handles workflow execution commands from the server
|
|
402
|
+
*/
|
|
403
|
+
private handleWorkflowCommand;
|
|
404
|
+
/**
|
|
405
|
+
* Handles tool execution commands from the server.
|
|
406
|
+
*/
|
|
407
|
+
private handleToolCommand;
|
|
408
|
+
/**
|
|
409
|
+
* Executes an agent and waits for completion
|
|
410
|
+
*/
|
|
411
|
+
/**
|
|
412
|
+
* Sends a successful command response to the server
|
|
413
|
+
*/
|
|
414
|
+
private sendResponse;
|
|
415
|
+
/**
|
|
416
|
+
* Sends an error response to the server
|
|
417
|
+
*/
|
|
418
|
+
private sendError;
|
|
419
|
+
/**
|
|
420
|
+
* Gets the stable ID for an agent (id if available, otherwise name).
|
|
421
|
+
*/
|
|
422
|
+
private getAgentId;
|
|
423
|
+
/**
|
|
424
|
+
* Gets the description from an agent if available.
|
|
425
|
+
*/
|
|
426
|
+
private getAgentDescription;
|
|
427
|
+
/**
|
|
428
|
+
* Builds the Cloud registration payload (RegisterClientDto compatible).
|
|
429
|
+
*/
|
|
430
|
+
private buildRegisterPayload;
|
|
431
|
+
private isZodSchema;
|
|
432
|
+
private isInstructionResolvable;
|
|
433
|
+
/**
|
|
434
|
+
* Agent definition payload for Cloud persistence + UI inspection.
|
|
435
|
+
*
|
|
436
|
+
* IMPORTANT:
|
|
437
|
+
* - Do NOT embed tool schemas here; tools are registered as independent resources.
|
|
438
|
+
* - We only reference tool ids to avoid duplication.
|
|
439
|
+
*/
|
|
440
|
+
private buildAgentDefinition;
|
|
441
|
+
/**
|
|
442
|
+
* Builds a workflow definition payload suitable for Cloud persistence + UI graph rendering.
|
|
443
|
+
*
|
|
444
|
+
* The base definition comes from `workflow.describe()` (graph nodes/edges).
|
|
445
|
+
* If the workflow was created with an input Zod schema, we also attach `inputSchema`
|
|
446
|
+
* as a JSON Schema object so the UI can render an input form.
|
|
447
|
+
*/
|
|
448
|
+
private buildWorkflowDefinition;
|
|
449
|
+
private buildToolDefinition;
|
|
450
|
+
/**
|
|
451
|
+
* Full registration (discovery) call. This is idempotent on the Cloud side.
|
|
452
|
+
*/
|
|
453
|
+
private registerFull;
|
|
454
|
+
private startSnapshotLoop;
|
|
455
|
+
/**
|
|
456
|
+
* Connects to the Cloud runtime.
|
|
457
|
+
*/
|
|
458
|
+
connect(): Promise<void>;
|
|
459
|
+
/**
|
|
460
|
+
* Disconnects from the server gracefully
|
|
461
|
+
*/
|
|
462
|
+
disconnect(): Promise<void>;
|
|
463
|
+
/**
|
|
464
|
+
* Best-effort shutdown notice to allow the Cloud to immediately clean up instance availability.
|
|
465
|
+
* Never throws: disconnect must be resilient.
|
|
466
|
+
*/
|
|
467
|
+
private sendShutdownNotice;
|
|
468
|
+
/**
|
|
469
|
+
* Checks if the client is connected
|
|
470
|
+
*/
|
|
471
|
+
isConnected(): boolean;
|
|
472
|
+
/**
|
|
473
|
+
* Returns the client ID
|
|
474
|
+
*/
|
|
475
|
+
getClientId(): string;
|
|
476
|
+
getInstanceId(): string;
|
|
477
|
+
/**
|
|
478
|
+
* Returns the socket instance for telemetry
|
|
479
|
+
*/
|
|
480
|
+
getSocket(): Socket<ServerToClientEvents, ClientToServerEvents>;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
interface SocketTelemetryExporterConfig {
|
|
484
|
+
maxBatchSize?: number;
|
|
485
|
+
flushIntervalMs?: number;
|
|
486
|
+
}
|
|
487
|
+
declare class SocketTelemetryExporter implements ITelemetryExporter {
|
|
488
|
+
private readonly serverConnection;
|
|
489
|
+
private readonly config;
|
|
490
|
+
private readonly queue;
|
|
491
|
+
private flushTimer;
|
|
492
|
+
private flushing;
|
|
493
|
+
constructor(serverConnection: ServerConnection, config?: SocketTelemetryExporterConfig);
|
|
494
|
+
exportBatch(events: TelemetryEventV1[]): Promise<void>;
|
|
495
|
+
flush(): Promise<void>;
|
|
496
|
+
stop(): void;
|
|
497
|
+
private sendTelemetryBatch;
|
|
498
|
+
private ensureTimer;
|
|
499
|
+
private flushIfNeeded;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
interface HttpTelemetryExporterConfig {
|
|
503
|
+
/**
|
|
504
|
+
* Request timeout for telemetry POSTs (ms).
|
|
505
|
+
* Telemetry must never block execution, so keep this low.
|
|
506
|
+
*/
|
|
507
|
+
timeoutMs?: number;
|
|
508
|
+
}
|
|
509
|
+
declare class HttpTelemetryExporter implements ITelemetryExporter {
|
|
510
|
+
private readonly input;
|
|
511
|
+
private readonly logger?;
|
|
512
|
+
private readonly baseUrl;
|
|
513
|
+
private readonly timeoutMs;
|
|
514
|
+
constructor(input: {
|
|
515
|
+
cloudUrl: string;
|
|
516
|
+
apiKey?: string;
|
|
517
|
+
clientId: string;
|
|
518
|
+
}, config?: HttpTelemetryExporterConfig, logger?: ILogger | undefined);
|
|
519
|
+
exportBatch(events: TelemetryEventV1[]): Promise<void>;
|
|
520
|
+
private sendSingle;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* OpenTelemetry-backed implementation of ITracingProvider.
|
|
525
|
+
*
|
|
526
|
+
* OTel internally may represent span/trace IDs in base64 (e.g. when
|
|
527
|
+
* propagated over binary protocols). This provider normalises every ID
|
|
528
|
+
* to the W3C hex format expected by the rest of the SDK before handing
|
|
529
|
+
* them to ActiveSpan / TracingContext.
|
|
530
|
+
*/
|
|
531
|
+
declare class OTelTracingProvider implements ITracingProvider {
|
|
532
|
+
private readonly exporter;
|
|
533
|
+
private readonly tracer;
|
|
534
|
+
constructor(serviceName: string, exporter: ITelemetryExporter);
|
|
535
|
+
/**
|
|
536
|
+
* Ensures an OTel ID string is in W3C lowercase hex format.
|
|
537
|
+
*
|
|
538
|
+
* If the value is already valid hex of the expected length it is returned
|
|
539
|
+
* as-is. Otherwise we assume it is base64-encoded and convert it.
|
|
540
|
+
*
|
|
541
|
+
* @param id Raw ID from OTel spanContext()
|
|
542
|
+
* @param hexLen Expected hex length (16 for spanId, 32 for traceId)
|
|
543
|
+
*/
|
|
544
|
+
private ensureW3cHex;
|
|
545
|
+
startSpan(input: SpanStartInput): ActiveSpan;
|
|
546
|
+
getContext(): TracingContext | undefined;
|
|
547
|
+
withSpan<T>(input: SpanStartInput, fn: (span: ActiveSpan) => Promise<T>): Promise<T>;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
interface OTelTracingConfig {
|
|
551
|
+
serviceName: string;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Sets up the global OTel TracerProvider for context propagation.
|
|
555
|
+
*
|
|
556
|
+
* NOTE: The SDK does NOT export spans directly to the collector.
|
|
557
|
+
* Instead, spans are sent as telemetry events to the backend, which
|
|
558
|
+
* then exports them to the collector preserving the original spanIds.
|
|
559
|
+
*
|
|
560
|
+
* This setup only registers the TracerProvider so that:
|
|
561
|
+
* - Spans get proper W3C-compliant IDs
|
|
562
|
+
* - Context propagation works correctly (parent-child relationships)
|
|
563
|
+
* - trace.getTracer() returns instrumented tracers
|
|
564
|
+
*/
|
|
565
|
+
declare function setupOTelTracing(config: OTelTracingConfig): void;
|
|
566
|
+
|
|
567
|
+
interface HttpDomainEventsExporterConfig {
|
|
568
|
+
/**
|
|
569
|
+
* Request timeout for domain events POSTs (ms).
|
|
570
|
+
* Domain events must never block execution, so keep this low.
|
|
571
|
+
*/
|
|
572
|
+
timeoutMs?: number;
|
|
573
|
+
}
|
|
574
|
+
declare class HttpDomainEventsExporter implements IDomainEventsExporter {
|
|
575
|
+
private readonly input;
|
|
576
|
+
private readonly logger?;
|
|
577
|
+
private readonly baseUrl;
|
|
578
|
+
private readonly timeoutMs;
|
|
579
|
+
constructor(input: {
|
|
580
|
+
cloudUrl: string;
|
|
581
|
+
apiKey?: string;
|
|
582
|
+
clientId: string;
|
|
583
|
+
}, config?: HttpDomainEventsExporterConfig, logger?: ILogger | undefined);
|
|
584
|
+
exportBatch(events: NebulaEvent[]): Promise<void>;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
declare class DBMemory implements IMemory {
|
|
588
|
+
get(_key: string, _sessionId?: string): Promise<unknown>;
|
|
589
|
+
set(_key: string, _value: unknown, _sessionId?: string, _ttl?: number): Promise<void>;
|
|
590
|
+
delete(_key: string, _sessionId?: string): Promise<void>;
|
|
591
|
+
clear(_sessionId?: string): Promise<void>;
|
|
592
|
+
getHistory(_sessionId: string, _limit?: number): Promise<never[]>;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
declare class PromptCapture {
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
declare class RAGClient {
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
declare class ClientError extends Error {
|
|
602
|
+
readonly code: string;
|
|
603
|
+
readonly statusCode: number;
|
|
604
|
+
readonly details?: unknown | undefined;
|
|
605
|
+
constructor(message: string, code: string, statusCode?: number, details?: unknown | undefined);
|
|
606
|
+
}
|
|
607
|
+
declare class RegistryError extends ClientError {
|
|
608
|
+
constructor(message: string, details?: unknown);
|
|
609
|
+
}
|
|
610
|
+
declare class NotFoundError extends ClientError {
|
|
611
|
+
constructor(entity: "agent" | "workflow" | "tool", id: string);
|
|
612
|
+
}
|
|
613
|
+
declare class AuthenticationError extends ClientError {
|
|
614
|
+
constructor(message?: string, details?: unknown);
|
|
615
|
+
}
|
|
616
|
+
declare class ConnectionError extends ClientError {
|
|
617
|
+
constructor(message: string, details?: unknown);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
interface HttpRequestOptions extends RequestInit {
|
|
621
|
+
timeout?: number;
|
|
622
|
+
}
|
|
623
|
+
declare class InstrumentedHttpClient implements IHttpClient {
|
|
624
|
+
fetch<T = unknown>(url: string, options?: HttpRequestOptions): Promise<HttpResponse<T>>;
|
|
625
|
+
get<T = unknown>(url: string, options?: Omit<HttpRequestOptions, "method">): Promise<HttpResponse<T>>;
|
|
626
|
+
post<T = unknown>(url: string, body?: unknown, options?: Omit<HttpRequestOptions, "method" | "body">): Promise<HttpResponse<T>>;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
export { type AgentFactory, type AgentOrFactory, AuthenticationError, Batcher, type ClientConfig, ClientError, ConnectionError, DBMemory, HttpDomainEventsExporter, type HttpDomainEventsExporterConfig, type HttpRequestOptions, HttpTelemetryExporter, type HttpTelemetryExporterConfig, InstrumentedHttpClient, NebulaClient, NotFoundError, type OTelTracingClientConfig, type OTelTracingConfig, OTelTracingProvider, PromptCapture, RAGClient, RegistryError, type ServerConfig, SocketTelemetryExporter, type SocketTelemetryExporterConfig, TelemetryService, clientConfigSchema, otelTracingConfigSchema, serverConfigSchema, setupOTelTracing };
|