@mondaydotcomorg/atp-protocol 0.19.14 → 0.19.15

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/src/events.ts ADDED
@@ -0,0 +1,199 @@
1
+ /**
2
+ * ATP Event Streaming Types
3
+ *
4
+ * Generic event types for streaming execution events to clients.
5
+ * Framework-agnostic design allows adapters for Vercel AI SDK, LangChain, etc.
6
+ */
7
+
8
+ export enum ATPEventType {
9
+ THINKING = 'thinking',
10
+ TOOL_START = 'tool_start',
11
+ TOOL_END = 'tool_end',
12
+ TEXT = 'text',
13
+ TEXT_END = 'text_end',
14
+ SOURCE = 'source',
15
+ PROGRESS = 'progress',
16
+ ERROR = 'error',
17
+ CUSTOM = 'custom',
18
+ }
19
+
20
+ export interface ATPEvent<T = unknown> {
21
+ type: ATPEventType | string;
22
+ data: T;
23
+ timestamp: number;
24
+ runId?: string;
25
+ }
26
+
27
+ export interface ATPThinkingEvent extends ATPEvent<{ content: string; step?: string }> {
28
+ type: ATPEventType.THINKING;
29
+ }
30
+
31
+ export interface ATPToolStartEvent
32
+ extends ATPEvent<{
33
+ toolName: string;
34
+ apiGroup: string;
35
+ input: unknown;
36
+ }> {
37
+ type: ATPEventType.TOOL_START;
38
+ }
39
+
40
+ export interface ATPToolEndEvent
41
+ extends ATPEvent<{
42
+ toolName: string;
43
+ apiGroup: string;
44
+ output: unknown;
45
+ duration: number;
46
+ success: boolean;
47
+ error?: string;
48
+ }> {
49
+ type: ATPEventType.TOOL_END;
50
+ }
51
+
52
+ export interface ATPTextEvent extends ATPEvent<{ text: string }> {
53
+ type: ATPEventType.TEXT;
54
+ }
55
+
56
+ export interface ATPTextEndEvent extends ATPEvent<Record<string, never>> {
57
+ type: ATPEventType.TEXT_END;
58
+ }
59
+
60
+ export interface ATPSourceEvent
61
+ extends ATPEvent<{
62
+ url: string;
63
+ title: string;
64
+ summary?: string;
65
+ createdAt?: string;
66
+ }> {
67
+ type: ATPEventType.SOURCE;
68
+ }
69
+
70
+ export interface ATPProgressEvent extends ATPEvent<{ message: string; fraction: number }> {
71
+ type: ATPEventType.PROGRESS;
72
+ }
73
+
74
+ export interface ATPErrorEvent extends ATPEvent<{ message: string; code?: string }> {
75
+ type: ATPEventType.ERROR;
76
+ }
77
+
78
+ export interface ATPCustomEvent extends ATPEvent<unknown> {
79
+ type: ATPEventType.CUSTOM;
80
+ customType: string;
81
+ }
82
+
83
+ export type ATPStreamEvent =
84
+ | ATPThinkingEvent
85
+ | ATPToolStartEvent
86
+ | ATPToolEndEvent
87
+ | ATPTextEvent
88
+ | ATPTextEndEvent
89
+ | ATPSourceEvent
90
+ | ATPProgressEvent
91
+ | ATPErrorEvent
92
+ | ATPCustomEvent;
93
+
94
+ export type ATPEventHandler = (event: ATPEvent) => void;
95
+
96
+ export type EventEmitter = (
97
+ eventOrType: ATPEvent | ATPEventType | string,
98
+ data?: unknown,
99
+ runId?: string
100
+ ) => void;
101
+
102
+ export function createEvent<T>(type: ATPEventType | string, data: T, runId?: string): ATPEvent<T> {
103
+ return {
104
+ type,
105
+ data,
106
+ timestamp: Date.now(),
107
+ runId,
108
+ };
109
+ }
110
+
111
+ export function createThinkingEvent(
112
+ content: string,
113
+ step?: string,
114
+ runId?: string
115
+ ): ATPThinkingEvent {
116
+ return {
117
+ type: ATPEventType.THINKING,
118
+ data: { content, step },
119
+ timestamp: Date.now(),
120
+ runId,
121
+ };
122
+ }
123
+
124
+ export function createToolStartEvent(
125
+ toolName: string,
126
+ apiGroup: string,
127
+ input: unknown,
128
+ runId?: string
129
+ ): ATPToolStartEvent {
130
+ return {
131
+ type: ATPEventType.TOOL_START,
132
+ data: { toolName, apiGroup, input },
133
+ timestamp: Date.now(),
134
+ runId,
135
+ };
136
+ }
137
+
138
+ export function createToolEndEvent(
139
+ toolName: string,
140
+ apiGroup: string,
141
+ output: unknown,
142
+ duration: number,
143
+ success: boolean,
144
+ error?: string,
145
+ runId?: string
146
+ ): ATPToolEndEvent {
147
+ return {
148
+ type: ATPEventType.TOOL_END,
149
+ data: { toolName, apiGroup, output, duration, success, error },
150
+ timestamp: Date.now(),
151
+ runId,
152
+ };
153
+ }
154
+
155
+ export function createTextEvent(text: string, runId?: string): ATPTextEvent {
156
+ return {
157
+ type: ATPEventType.TEXT,
158
+ data: { text },
159
+ timestamp: Date.now(),
160
+ runId,
161
+ };
162
+ }
163
+
164
+ export function createTextEndEvent(runId?: string): ATPTextEndEvent {
165
+ return {
166
+ type: ATPEventType.TEXT_END,
167
+ data: {},
168
+ timestamp: Date.now(),
169
+ runId,
170
+ };
171
+ }
172
+
173
+ export function createSourceEvent(
174
+ url: string,
175
+ title: string,
176
+ summary?: string,
177
+ createdAt?: string,
178
+ runId?: string
179
+ ): ATPSourceEvent {
180
+ return {
181
+ type: ATPEventType.SOURCE,
182
+ data: { url, title, summary, createdAt },
183
+ timestamp: Date.now(),
184
+ runId,
185
+ };
186
+ }
187
+
188
+ export function createProgressEvent(
189
+ message: string,
190
+ fraction: number,
191
+ runId?: string
192
+ ): ATPProgressEvent {
193
+ return {
194
+ type: ATPEventType.PROGRESS,
195
+ data: { message, fraction },
196
+ timestamp: Date.now(),
197
+ runId,
198
+ };
199
+ }
package/src/index.ts CHANGED
@@ -4,3 +4,4 @@ export * from './validation.js';
4
4
  export * from './auth.js';
5
5
  export * from './providers.js';
6
6
  export * from './oauth.js';
7
+ export * from './events.js';
package/src/types.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import type { ProvenanceMode, SecurityPolicy } from '@mondaydotcomorg/atp-provenance';
2
+ import type { ATPEvent, ATPEventHandler, ATPEventType } from './events.js';
3
+
2
4
  export { ProvenanceMode, type SecurityPolicy } from '@mondaydotcomorg/atp-provenance';
3
5
 
4
6
  /**
@@ -293,6 +295,7 @@ export interface ExecutionConfig {
293
295
  requestContext?: Record<string, unknown>;
294
296
  toolRules?: ClientToolRules;
295
297
  onToolCall?: (event: ToolCallEvent) => void;
298
+ eventCallback?: ATPEventHandler;
296
299
  }
297
300
 
298
301
  /**
@@ -530,7 +533,8 @@ export interface LoggingConfig {
530
533
  /** Context passed to function handlers during execution */
531
534
  export interface FunctionHandlerContext {
532
535
  metadata?: ToolMetadata;
533
- requestContext?: Record<string, unknown>;
536
+ requestContext?: Record<string, unknown>;
537
+ emit: (eventOrType: ATPEvent | ATPEventType | string, data?: unknown, runId?: string) => void;
534
538
  }
535
539
 
536
540
  export interface CustomFunctionDef {