-
Notifications
You must be signed in to change notification settings - Fork 8.1k
/
types.ts
92 lines (86 loc) · 2.3 KB
/
types.ts
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
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import * as t from 'io-ts';
import { FrameworkUser } from '../../adapters/framework/adapter_types';
export const RuntimeAgentEventType = t.union([
t.literal('STATE'),
t.literal('ERROR'),
t.literal('ACTION_RESULT'),
t.literal('ACTION'),
]);
export const RuntimeAgentEventSubtype = t.union([
// State
t.literal('RUNNING'),
t.literal('STARTING'),
t.literal('IN_PROGRESS'),
t.literal('CONFIG'),
t.literal('FAILED'),
t.literal('STOPPED'),
// Action results
t.literal('DATA_DUMP'),
// Actions
t.literal('ACKNOWLEDGED'),
t.literal('UNKNOWN'),
]);
export const RuntimeAgentEvent = t.intersection(
[
t.interface({
type: RuntimeAgentEventType,
subtype: RuntimeAgentEventSubtype,
timestamp: t.string,
message: t.string,
}),
t.partial({
payload: t.any,
data: t.string,
action_id: t.string,
policy_id: t.string,
stream_id: t.string,
}),
],
'AgentEvent'
);
export type AgentEvent = t.TypeOf<typeof RuntimeAgentEvent>;
export const RuntimeAgentEventSOAttributes = t.intersection(
[
t.interface({
type: RuntimeAgentEventType,
subtype: RuntimeAgentEventSubtype,
timestamp: t.string,
message: t.string,
agent_id: t.string,
}),
t.partial({
payload: t.string,
data: t.string,
action_id: t.string,
}),
],
'AgentEventSOAttribute'
);
export type AgentEventSOAttributes = t.TypeOf<typeof RuntimeAgentEventSOAttributes>;
export interface AgentEventsRepository {
createEventsForAgent(user: FrameworkUser, agentId: string, events: AgentEvent[]): Promise<void>;
getEventsForAgent(
user: FrameworkUser,
agentId: string,
options?: {
search?: string;
page?: number;
perPage?: number;
}
): Promise<{ items: AgentEvent[]; total: number }>;
list(
user: FrameworkUser,
options: {
agentId?: string;
search?: string;
page?: number;
perPage?: number;
}
): Promise<{ items: AgentEvent[]; total: number }>;
deleteEventsForAgent(user: FrameworkUser, agentId: string): Promise<void>;
}