-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathshared-types.ts
More file actions
106 lines (97 loc) · 2.38 KB
/
shared-types.ts
File metadata and controls
106 lines (97 loc) · 2.38 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Shared types for AI clients across all providers
*/
export interface ToolCall {
id: string;
name: string;
arguments: Record<string, unknown>;
}
export interface ToolCallOutput {
tool_call_id: string;
tool_name: string;
arguments: Record<string, unknown>;
status: "success" | "error";
timestamp: string;
result?: string;
}
export interface OutputData {
type: "display_data" | "execute_result" | "error";
data: Record<string, unknown>;
metadata?: Record<string, unknown>;
}
export interface AgenticOptions {
maxIterations?: number;
onIteration?: (
iteration: number,
messages: unknown[],
) => Promise<boolean>;
interruptSignal?: AbortSignal;
}
export interface AnodeCellMetadata {
role?: "assistant" | "user" | "function_call" | "tool";
ai_provider?: string;
ai_model?: string;
iteration?: number;
tool_call?: boolean;
tool_name?: string;
tool_args?: Record<string, unknown>;
tool_error?: boolean;
tool_call_id?: string;
}
/**
* Helper function to format tool calls consistently across providers
*/
export function formatToolCall(
_toolName: string,
args: Record<string, unknown>,
): string {
const formattedArgs = Object.entries(args)
.map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
.join(", ");
return `**Arguments**: ${formattedArgs}`;
}
/**
* Helper function to create configuration help output
*/
export function createConfigHelpOutput(
provider: string,
requirements: string[],
): OutputData[] {
return [{
type: "display_data" as const,
data: {
"text/markdown": `## ${provider} Configuration Required\n\n${
requirements.join("\n")
}\n\nPlease configure ${provider} to use AI features.`,
"text/plain": `${provider} configuration required: ${
requirements.join(", ")
}`,
},
metadata: {
"anode/ai_config_help": true,
"anode/ai_provider": provider.toLowerCase(),
},
}];
}
/**
* Helper function to create error output
*/
export function createErrorOutput(
message: string,
provider?: string,
): OutputData[] {
return [{
type: "error" as const,
data: {
ename: `${
provider ? provider.charAt(0).toUpperCase() + provider.slice(1) : "AI"
}Error`,
evalue: message,
traceback: [message],
},
metadata: {
"anode/ai_error": true,
...(provider && { "anode/ai_provider": provider }),
},
}];
}