-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtaskResultHelpers.ts
More file actions
67 lines (58 loc) · 1.52 KB
/
Copy pathtaskResultHelpers.ts
File metadata and controls
67 lines (58 loc) · 1.52 KB
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
/**
* @file taskResultHelpers.ts
* @description Helpers for propagating task terminal outcomes (failed / blocked)
* back to the SaaS via the handler context.
*/
import { logger } from './logger.js';
import { HandlerContext } from './handlerContext.js';
export type TaskTerminalStatus = 'failed' | 'blocked';
export function sendTaskTerminalToSaas(
ctx: HandlerContext,
agentId: string,
taskId: string | undefined,
status: TaskTerminalStatus,
reason: string,
source: string,
): void {
if (!taskId) return;
const normalizedReason = reason?.trim() || 'INVOKE_ERROR';
logger.warn('intent.task_terminal_propagated', {
agentId,
taskId,
status,
source,
reason: normalizedReason,
});
ctx.sendToSaas({
action: 'task_complete',
agentId,
taskId,
status,
reason: normalizedReason,
source,
});
}
export function sendTaskFailureToSaas(
ctx: HandlerContext,
agentId: string,
taskId: string | undefined,
reason: string,
source: string,
): void {
sendTaskTerminalToSaas(ctx, agentId, taskId, 'failed', reason, source);
}
export function sendTaskBlockedToSaas(
ctx: HandlerContext,
agentId: string,
taskId: string | undefined,
reason: string,
source: string,
): void {
sendTaskTerminalToSaas(ctx, agentId, taskId, 'blocked', reason, source);
}
export function classifyTaskTerminalStatus(responseStatus: number, responseText: string): TaskTerminalStatus {
if (responseStatus === 401 || /unauthorized/i.test(responseText)) {
return 'blocked';
}
return 'failed';
}