elasticdash-test 0.1.18-alpha-18 → 0.1.18-alpha-20
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/package.json +1 -1
- package/src/index.ts +8 -0
- package/src/observability.ts +1 -3
- package/src/socket-connector.ts +6 -4
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -103,3 +103,11 @@ export type { AgentTask, AgentPlan, AgentState, AgentTaskStatus, AgentPlanStatus
|
|
|
103
103
|
export { startPortalServer } from './portal-server.js'
|
|
104
104
|
export { executePortalTask } from './portal-executor.js'
|
|
105
105
|
export type { PortalTask, PortalTaskResult, PortalServerOptions, PortalServerHandle, PortalStatus } from './types/portal.js'
|
|
106
|
+
|
|
107
|
+
// ─── Eager auto-init ────────────────────────────────────────
|
|
108
|
+
// When ELASTICDASH_API_KEY is set, automatically initialise observability mode
|
|
109
|
+
// at import time so the socket connection is established immediately (e.g. for
|
|
110
|
+
// onboarding detection). tryAutoInitHttpContext is idempotent and deduplicates
|
|
111
|
+
// concurrent calls, so this is safe even if interceptors trigger it again later.
|
|
112
|
+
import { tryAutoInitHttpContext } from './interceptors/telemetry-push.js'
|
|
113
|
+
tryAutoInitHttpContext().catch(() => {})
|
package/src/observability.ts
CHANGED
|
@@ -18,7 +18,6 @@ import { debugLog } from './utils/debug.js'
|
|
|
18
18
|
export interface ObservabilityOptions {
|
|
19
19
|
serverUrl?: string
|
|
20
20
|
apiKey?: string
|
|
21
|
-
projectId?: string
|
|
22
21
|
sessionId?: string
|
|
23
22
|
batchIntervalMs?: number
|
|
24
23
|
maxBatchSize?: number
|
|
@@ -51,7 +50,6 @@ export function initObservability(options?: ObservabilityOptions): Observability
|
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
const apiKey = options?.apiKey ?? process.env.ELASTICDASH_API_KEY
|
|
54
|
-
const projectId = options?.projectId ?? process.env.ELASTICDASH_PROJECT_ID
|
|
55
53
|
const sessionId = options?.sessionId ?? process.env.ELASTICDASH_SESSION_ID ?? randomUUID()
|
|
56
54
|
const sampleRate = options?.sampleRate ?? 1.0
|
|
57
55
|
const redactKeys = options?.redactKeys ?? []
|
|
@@ -92,7 +90,7 @@ export function initObservability(options?: ObservabilityOptions): Observability
|
|
|
92
90
|
installAIInterceptor()
|
|
93
91
|
interceptFetch()
|
|
94
92
|
installDBAutoInterceptor().catch(() => {})
|
|
95
|
-
connectToBackend({ serverUrl, apiKey, sessionId
|
|
93
|
+
connectToBackend({ serverUrl, apiKey, sessionId })
|
|
96
94
|
|
|
97
95
|
// Heartbeat
|
|
98
96
|
heartbeatTimer = setInterval(() => {
|
package/src/socket-connector.ts
CHANGED
|
@@ -10,7 +10,6 @@ export interface SocketConnectorOptions {
|
|
|
10
10
|
serverUrl: string
|
|
11
11
|
apiKey?: string
|
|
12
12
|
sessionId: string
|
|
13
|
-
projectId?: string
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
let socket: Socket | null = null
|
|
@@ -30,14 +29,13 @@ export function connectToBackend(options: SocketConnectorOptions): Socket {
|
|
|
30
29
|
// If a socket exists but is disconnected/reconnecting, reuse it
|
|
31
30
|
if (socket) return socket
|
|
32
31
|
|
|
33
|
-
const { serverUrl, apiKey, sessionId
|
|
32
|
+
const { serverUrl, apiKey, sessionId } = options
|
|
34
33
|
const cwd = process.cwd()
|
|
35
34
|
|
|
36
35
|
socket = io(serverUrl, {
|
|
37
36
|
auth: {
|
|
38
37
|
...(apiKey ? { apiKey } : {}),
|
|
39
38
|
sessionId,
|
|
40
|
-
...(projectId ? { projectId } : {}),
|
|
41
39
|
},
|
|
42
40
|
transports: ['websocket', 'polling'],
|
|
43
41
|
reconnection: true,
|
|
@@ -51,12 +49,16 @@ export function connectToBackend(options: SocketConnectorOptions): Socket {
|
|
|
51
49
|
const workflows = scanWorkflows(cwd)
|
|
52
50
|
socket!.emit('register', {
|
|
53
51
|
sessionId,
|
|
54
|
-
...(projectId ? { projectId } : {}),
|
|
55
52
|
tools: tools.map(t => t.name),
|
|
56
53
|
workflows: workflows.map(w => w.name),
|
|
57
54
|
})
|
|
58
55
|
})
|
|
59
56
|
|
|
57
|
+
socket.on('auth:ok', (data: { projectId: number }) => {
|
|
58
|
+
debugLog(`[elasticdash] Authenticated for project ${data.projectId}`)
|
|
59
|
+
socket!.emit('join', `sdk:project:${data.projectId}`)
|
|
60
|
+
})
|
|
61
|
+
|
|
60
62
|
socket.on('portal:task', async (task: PortalTask, ack?: (result: PortalTaskResult) => void) => {
|
|
61
63
|
debugLog(`[elasticdash] Socket received portal task: ${task.taskId} type=${task.type} name=${task.name}`)
|
|
62
64
|
try {
|