@looopy-ai/core 1.0.1
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/LICENSE +9 -0
- package/dist/core/agent.d.ts +53 -0
- package/dist/core/agent.js +416 -0
- package/dist/core/cleanup.d.ts +12 -0
- package/dist/core/cleanup.js +45 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +3 -0
- package/dist/core/iteration.d.ts +5 -0
- package/dist/core/iteration.js +60 -0
- package/dist/core/logger.d.ts +11 -0
- package/dist/core/logger.js +31 -0
- package/dist/core/loop.d.ts +5 -0
- package/dist/core/loop.js +125 -0
- package/dist/core/tools.d.ts +4 -0
- package/dist/core/tools.js +78 -0
- package/dist/core/types.d.ts +30 -0
- package/dist/core/types.js +1 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.js +2 -0
- package/dist/events/utils.d.ts +250 -0
- package/dist/events/utils.js +263 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/observability/index.d.ts +1 -0
- package/dist/observability/index.js +1 -0
- package/dist/observability/spans/agent-turn.d.ts +31 -0
- package/dist/observability/spans/agent-turn.js +94 -0
- package/dist/observability/spans/index.d.ts +5 -0
- package/dist/observability/spans/index.js +5 -0
- package/dist/observability/spans/iteration.d.ts +14 -0
- package/dist/observability/spans/iteration.js +41 -0
- package/dist/observability/spans/llm-call.d.ts +14 -0
- package/dist/observability/spans/llm-call.js +50 -0
- package/dist/observability/spans/loop.d.ts +14 -0
- package/dist/observability/spans/loop.js +40 -0
- package/dist/observability/spans/tool.d.ts +14 -0
- package/dist/observability/spans/tool.js +44 -0
- package/dist/observability/tracing.d.ts +58 -0
- package/dist/observability/tracing.js +203 -0
- package/dist/providers/chat-completions/aggregate.d.ts +4 -0
- package/dist/providers/chat-completions/aggregate.js +152 -0
- package/dist/providers/chat-completions/content.d.ts +25 -0
- package/dist/providers/chat-completions/content.js +229 -0
- package/dist/providers/chat-completions/index.d.ts +4 -0
- package/dist/providers/chat-completions/index.js +4 -0
- package/dist/providers/chat-completions/streaming.d.ts +12 -0
- package/dist/providers/chat-completions/streaming.js +3 -0
- package/dist/providers/chat-completions/types.d.ts +39 -0
- package/dist/providers/chat-completions/types.js +1 -0
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.js +1 -0
- package/dist/providers/litellm-provider.d.ts +43 -0
- package/dist/providers/litellm-provider.js +377 -0
- package/dist/server/event-buffer.d.ts +37 -0
- package/dist/server/event-buffer.js +116 -0
- package/dist/server/event-router.d.ts +31 -0
- package/dist/server/event-router.js +91 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +3 -0
- package/dist/server/sse.d.ts +60 -0
- package/dist/server/sse.js +159 -0
- package/dist/stores/artifacts/artifact-scheduler.d.ts +50 -0
- package/dist/stores/artifacts/artifact-scheduler.js +86 -0
- package/dist/stores/artifacts/index.d.ts +3 -0
- package/dist/stores/artifacts/index.js +3 -0
- package/dist/stores/artifacts/internal-event-artifact-store.d.ts +54 -0
- package/dist/stores/artifacts/internal-event-artifact-store.js +126 -0
- package/dist/stores/artifacts/memory-artifact-store.d.ts +52 -0
- package/dist/stores/artifacts/memory-artifact-store.js +268 -0
- package/dist/stores/filesystem/filesystem-agent-store.d.ts +18 -0
- package/dist/stores/filesystem/filesystem-agent-store.js +61 -0
- package/dist/stores/filesystem/filesystem-artifact-store.d.ts +59 -0
- package/dist/stores/filesystem/filesystem-artifact-store.js +325 -0
- package/dist/stores/filesystem/filesystem-context-store.d.ts +37 -0
- package/dist/stores/filesystem/filesystem-context-store.js +245 -0
- package/dist/stores/filesystem/filesystem-message-store.d.ts +28 -0
- package/dist/stores/filesystem/filesystem-message-store.js +149 -0
- package/dist/stores/filesystem/filesystem-task-state-store.d.ts +27 -0
- package/dist/stores/filesystem/filesystem-task-state-store.js +220 -0
- package/dist/stores/filesystem/index.d.ts +10 -0
- package/dist/stores/filesystem/index.js +5 -0
- package/dist/stores/index.d.ts +5 -0
- package/dist/stores/index.js +5 -0
- package/dist/stores/memory/memory-state-store.d.ts +15 -0
- package/dist/stores/memory/memory-state-store.js +55 -0
- package/dist/stores/messages/hybrid-message-store.d.ts +29 -0
- package/dist/stores/messages/hybrid-message-store.js +72 -0
- package/dist/stores/messages/index.d.ts +4 -0
- package/dist/stores/messages/index.js +4 -0
- package/dist/stores/messages/interfaces.d.ts +42 -0
- package/dist/stores/messages/interfaces.js +18 -0
- package/dist/stores/messages/mem0-message-store.d.ts +34 -0
- package/dist/stores/messages/mem0-message-store.js +218 -0
- package/dist/stores/messages/memory-message-store.d.ts +27 -0
- package/dist/stores/messages/memory-message-store.js +183 -0
- package/dist/tools/artifact-tools.d.ts +4 -0
- package/dist/tools/artifact-tools.js +277 -0
- package/dist/tools/client-tool-provider.d.ts +25 -0
- package/dist/tools/client-tool-provider.js +139 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/local-tools.d.ts +13 -0
- package/dist/tools/local-tools.js +70 -0
- package/dist/tools/mcp-client.d.ts +29 -0
- package/dist/tools/mcp-client.js +62 -0
- package/dist/tools/mcp-tool-provider.d.ts +22 -0
- package/dist/tools/mcp-tool-provider.js +86 -0
- package/dist/types/a2a.d.ts +36 -0
- package/dist/types/a2a.js +1 -0
- package/dist/types/agent.d.ts +14 -0
- package/dist/types/agent.js +1 -0
- package/dist/types/artifact.d.ts +126 -0
- package/dist/types/artifact.js +1 -0
- package/dist/types/context.d.ts +13 -0
- package/dist/types/context.js +1 -0
- package/dist/types/event.d.ts +360 -0
- package/dist/types/event.js +30 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.js +9 -0
- package/dist/types/llm.d.ts +24 -0
- package/dist/types/llm.js +1 -0
- package/dist/types/message.d.ts +9 -0
- package/dist/types/message.js +1 -0
- package/dist/types/state.d.ts +86 -0
- package/dist/types/state.js +1 -0
- package/dist/types/tools.d.ts +57 -0
- package/dist/types/tools.js +53 -0
- package/dist/utils/error.d.ts +8 -0
- package/dist/utils/error.js +23 -0
- package/dist/utils/process-signals.d.ts +3 -0
- package/dist/utils/process-signals.js +67 -0
- package/package.json +54 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { MCPClient } from './mcp-client';
|
|
2
|
+
export const mcp = (config) => {
|
|
3
|
+
return new McpToolProvider(config);
|
|
4
|
+
};
|
|
5
|
+
export class McpToolProvider {
|
|
6
|
+
id;
|
|
7
|
+
client;
|
|
8
|
+
toolCache = new Map();
|
|
9
|
+
cacheExpiry = null;
|
|
10
|
+
cacheTTL = 300_000;
|
|
11
|
+
ongoingRequest = null;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.id = `mcp:${config.serverId}`;
|
|
14
|
+
this.client = new MCPClient({
|
|
15
|
+
baseUrl: config.serverUrl,
|
|
16
|
+
timeout: config.timeout || 30000,
|
|
17
|
+
getHeaders: config.getHeaders,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async getTools() {
|
|
21
|
+
if (this.toolCache.size > 0 && this.cacheExpiry && Date.now() < this.cacheExpiry) {
|
|
22
|
+
return Array.from(this.toolCache.values());
|
|
23
|
+
}
|
|
24
|
+
if (this.ongoingRequest) {
|
|
25
|
+
return this.ongoingRequest;
|
|
26
|
+
}
|
|
27
|
+
this.ongoingRequest = this.client
|
|
28
|
+
.listTools()
|
|
29
|
+
.then((tools) => {
|
|
30
|
+
const toolDefs = tools.map(this.convertMCPTool);
|
|
31
|
+
this.toolCache.clear();
|
|
32
|
+
for (const tool of toolDefs) {
|
|
33
|
+
this.toolCache.set(tool.name, tool);
|
|
34
|
+
}
|
|
35
|
+
this.cacheExpiry = Date.now() + this.cacheTTL;
|
|
36
|
+
return toolDefs;
|
|
37
|
+
})
|
|
38
|
+
.finally(() => {
|
|
39
|
+
this.ongoingRequest = null;
|
|
40
|
+
});
|
|
41
|
+
return this.ongoingRequest;
|
|
42
|
+
}
|
|
43
|
+
canHandle(toolName) {
|
|
44
|
+
return this.toolCache.has(toolName);
|
|
45
|
+
}
|
|
46
|
+
async execute(toolCall, context) {
|
|
47
|
+
const { name, arguments: args } = toolCall.function;
|
|
48
|
+
if (typeof args !== 'object' || args === null) {
|
|
49
|
+
return {
|
|
50
|
+
toolCallId: toolCall.id,
|
|
51
|
+
toolName: name,
|
|
52
|
+
success: false,
|
|
53
|
+
error: 'Tool arguments must be an object',
|
|
54
|
+
result: null,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const response = await this.client.callTool({
|
|
59
|
+
name,
|
|
60
|
+
arguments: args,
|
|
61
|
+
}, context.authContext);
|
|
62
|
+
return {
|
|
63
|
+
toolCallId: toolCall.id,
|
|
64
|
+
toolName: name,
|
|
65
|
+
success: true,
|
|
66
|
+
result: response.result,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
return {
|
|
71
|
+
toolCallId: toolCall.id,
|
|
72
|
+
toolName: name,
|
|
73
|
+
success: false,
|
|
74
|
+
error: error instanceof Error ? error.message : String(error),
|
|
75
|
+
result: null,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
convertMCPTool = (mcpTool) => {
|
|
80
|
+
return {
|
|
81
|
+
name: mcpTool.name,
|
|
82
|
+
description: mcpTool.description,
|
|
83
|
+
parameters: mcpTool.inputSchema,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Message } from './message';
|
|
2
|
+
export type A2ATaskState = 'submitted' | 'working' | 'input-required' | 'completed' | 'canceled' | 'failed' | 'rejected' | 'auth-required' | 'unknown';
|
|
3
|
+
export interface A2ATaskStatus {
|
|
4
|
+
state: A2ATaskState;
|
|
5
|
+
message?: Message;
|
|
6
|
+
timestamp?: string;
|
|
7
|
+
}
|
|
8
|
+
export type A2APart = A2ATextPart | A2AFilePart | A2ADataPart;
|
|
9
|
+
export interface A2ATextPart {
|
|
10
|
+
kind: 'text';
|
|
11
|
+
text: string;
|
|
12
|
+
metadata?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
export interface A2AFilePart {
|
|
15
|
+
kind: 'file';
|
|
16
|
+
file: {
|
|
17
|
+
name?: string;
|
|
18
|
+
mimeType?: string;
|
|
19
|
+
bytes?: string;
|
|
20
|
+
uri?: string;
|
|
21
|
+
};
|
|
22
|
+
metadata?: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
export interface A2ADataPart {
|
|
25
|
+
kind: 'data';
|
|
26
|
+
data: Record<string, unknown>;
|
|
27
|
+
metadata?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
export interface A2AArtifact {
|
|
30
|
+
artifactId: string;
|
|
31
|
+
name?: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
parts: A2APart[];
|
|
34
|
+
metadata?: Record<string, unknown>;
|
|
35
|
+
extensions?: string[];
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SerializedError } from '../utils/error';
|
|
2
|
+
export interface AgentState {
|
|
3
|
+
status: 'created' | 'ready' | 'busy' | 'shutdown' | 'error';
|
|
4
|
+
turnCount: number;
|
|
5
|
+
lastActivity: Date;
|
|
6
|
+
createdAt: Date;
|
|
7
|
+
error?: SerializedError;
|
|
8
|
+
metadata?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface AgentStore {
|
|
11
|
+
load(contextId: string): Promise<AgentState | null>;
|
|
12
|
+
save(contextId: string, state: AgentState): Promise<void>;
|
|
13
|
+
delete?(contextId: string): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
export type ArtifactType = 'file' | 'data' | 'dataset';
|
|
2
|
+
export interface ArtifactStore {
|
|
3
|
+
createFileArtifact(params: {
|
|
4
|
+
artifactId: string;
|
|
5
|
+
taskId: string;
|
|
6
|
+
contextId: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
mimeType?: string;
|
|
10
|
+
encoding?: 'utf-8' | 'base64';
|
|
11
|
+
override?: boolean;
|
|
12
|
+
}): Promise<string>;
|
|
13
|
+
createDataArtifact(params: {
|
|
14
|
+
artifactId: string;
|
|
15
|
+
taskId: string;
|
|
16
|
+
contextId: string;
|
|
17
|
+
name?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
override?: boolean;
|
|
20
|
+
}): Promise<string>;
|
|
21
|
+
createDatasetArtifact(params: {
|
|
22
|
+
artifactId: string;
|
|
23
|
+
taskId: string;
|
|
24
|
+
contextId: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
schema?: DatasetSchema;
|
|
28
|
+
override?: boolean;
|
|
29
|
+
}): Promise<string>;
|
|
30
|
+
appendFileChunk(contextId: string, artifactId: string, chunk: string, options?: {
|
|
31
|
+
isLastChunk?: boolean;
|
|
32
|
+
encoding?: 'utf-8' | 'base64';
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
writeData(contextId: string, artifactId: string, data: Record<string, unknown>): Promise<void>;
|
|
35
|
+
appendDatasetBatch(contextId: string, artifactId: string, rows: Record<string, unknown>[], options?: {
|
|
36
|
+
isLastBatch?: boolean;
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
getArtifact(contextId: string, artifactId: string): Promise<StoredArtifact | null>;
|
|
39
|
+
getFileContent(contextId: string, artifactId: string): Promise<string>;
|
|
40
|
+
getDataContent(contextId: string, artifactId: string): Promise<Record<string, unknown>>;
|
|
41
|
+
getDatasetRows(contextId: string, artifactId: string): Promise<Record<string, unknown>[]>;
|
|
42
|
+
listArtifacts(contextId: string, taskId?: string): Promise<string[]>;
|
|
43
|
+
deleteArtifact(contextId: string, artifactId: string): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
export interface DatasetSchema {
|
|
46
|
+
columns: DatasetColumn[];
|
|
47
|
+
primaryKey?: string[];
|
|
48
|
+
indexes?: string[][];
|
|
49
|
+
}
|
|
50
|
+
export interface DatasetColumn {
|
|
51
|
+
name: string;
|
|
52
|
+
type: 'string' | 'number' | 'boolean' | 'date' | 'json' | 'null';
|
|
53
|
+
nullable?: boolean;
|
|
54
|
+
description?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface BaseArtifact {
|
|
57
|
+
artifactId: string;
|
|
58
|
+
taskId: string;
|
|
59
|
+
contextId: string;
|
|
60
|
+
name?: string;
|
|
61
|
+
description?: string;
|
|
62
|
+
status: 'building' | 'complete' | 'failed';
|
|
63
|
+
version: number;
|
|
64
|
+
operations: ArtifactOperation[];
|
|
65
|
+
createdAt: string;
|
|
66
|
+
updatedAt: string;
|
|
67
|
+
completedAt?: string;
|
|
68
|
+
externalStorage?: {
|
|
69
|
+
provider: 'local' | 's3' | 'gcs' | 'azure';
|
|
70
|
+
key: string;
|
|
71
|
+
bucket?: string;
|
|
72
|
+
region?: string;
|
|
73
|
+
checksum?: string;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export interface FileArtifact extends BaseArtifact {
|
|
77
|
+
type: 'file';
|
|
78
|
+
chunks: ArtifactChunk[];
|
|
79
|
+
mimeType?: string;
|
|
80
|
+
encoding?: 'utf-8' | 'base64';
|
|
81
|
+
totalChunks: number;
|
|
82
|
+
totalSize: number;
|
|
83
|
+
}
|
|
84
|
+
export interface DataArtifact extends BaseArtifact {
|
|
85
|
+
type: 'data';
|
|
86
|
+
data: Record<string, unknown>;
|
|
87
|
+
}
|
|
88
|
+
export interface DatasetArtifact extends BaseArtifact {
|
|
89
|
+
type: 'dataset';
|
|
90
|
+
rows: Record<string, unknown>[];
|
|
91
|
+
schema?: DatasetSchema;
|
|
92
|
+
totalChunks: number;
|
|
93
|
+
totalSize: number;
|
|
94
|
+
}
|
|
95
|
+
export type StoredArtifact = FileArtifact | DataArtifact | DatasetArtifact;
|
|
96
|
+
export interface ArtifactChunk {
|
|
97
|
+
index: number;
|
|
98
|
+
data: string;
|
|
99
|
+
size: number;
|
|
100
|
+
checksum?: string;
|
|
101
|
+
timestamp: string;
|
|
102
|
+
}
|
|
103
|
+
export interface ArtifactPart {
|
|
104
|
+
index: number;
|
|
105
|
+
kind: 'text' | 'file' | 'data';
|
|
106
|
+
content?: string;
|
|
107
|
+
data?: Record<string, unknown>;
|
|
108
|
+
fileReference?: {
|
|
109
|
+
storageKey: string;
|
|
110
|
+
size: number;
|
|
111
|
+
checksum?: string;
|
|
112
|
+
};
|
|
113
|
+
metadata?: {
|
|
114
|
+
mimeType?: string;
|
|
115
|
+
fileName?: string;
|
|
116
|
+
[key: string]: unknown;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export interface ArtifactOperation {
|
|
120
|
+
operationId: string;
|
|
121
|
+
type: 'create' | 'append' | 'replace' | 'complete' | 'reset';
|
|
122
|
+
timestamp: string;
|
|
123
|
+
partIndex?: number;
|
|
124
|
+
chunkIndex?: number;
|
|
125
|
+
replacedPartIndexes?: number[];
|
|
126
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface AuthContext {
|
|
2
|
+
userId?: string;
|
|
3
|
+
credentials?: Record<string, unknown>;
|
|
4
|
+
scopes?: string[];
|
|
5
|
+
}
|
|
6
|
+
export interface ExecutionContext {
|
|
7
|
+
taskId: string;
|
|
8
|
+
contextId: string;
|
|
9
|
+
agentId: string;
|
|
10
|
+
parentContext: import('@opentelemetry/api').Context;
|
|
11
|
+
authContext?: AuthContext;
|
|
12
|
+
metadata?: Record<string, unknown>;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import type { ToolCall } from './tools';
|
|
2
|
+
export type TaskStatus = 'working' | 'waiting-input' | 'waiting-auth' | 'waiting-subtask' | 'completed' | 'failed' | 'canceled';
|
|
3
|
+
export type ThoughtVerbosity = 'brief' | 'normal' | 'detailed';
|
|
4
|
+
export type ThoughtType = 'analysis' | 'planning' | 'reasoning' | 'reflection' | 'thinking' | 'decision' | 'observation' | 'strategy';
|
|
5
|
+
export type InputType = 'tool-execution' | 'confirmation' | 'clarification' | 'selection' | 'custom';
|
|
6
|
+
export type AuthType = 'oauth2' | 'api-key' | 'password' | 'biometric' | 'custom';
|
|
7
|
+
export type TaskInitiator = 'user' | 'agent';
|
|
8
|
+
export type InputProvider = 'user' | 'agent';
|
|
9
|
+
export interface JSONSchema {
|
|
10
|
+
type?: string;
|
|
11
|
+
properties?: Record<string, JSONSchema>;
|
|
12
|
+
required?: string[];
|
|
13
|
+
items?: JSONSchema;
|
|
14
|
+
format?: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
export interface TaskCreatedEvent {
|
|
18
|
+
kind: 'task-created';
|
|
19
|
+
contextId: string;
|
|
20
|
+
taskId: string;
|
|
21
|
+
parentTaskId?: string;
|
|
22
|
+
initiator: TaskInitiator;
|
|
23
|
+
timestamp: string;
|
|
24
|
+
metadata?: {
|
|
25
|
+
agentId?: string;
|
|
26
|
+
model?: string;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface TaskStatusEvent {
|
|
31
|
+
kind: 'task-status';
|
|
32
|
+
contextId: string;
|
|
33
|
+
taskId: string;
|
|
34
|
+
status: TaskStatus;
|
|
35
|
+
message?: string;
|
|
36
|
+
timestamp: string;
|
|
37
|
+
metadata?: {
|
|
38
|
+
reason?: string;
|
|
39
|
+
blockedBy?: string;
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface TaskCompleteEvent {
|
|
44
|
+
kind: 'task-complete';
|
|
45
|
+
contextId: string;
|
|
46
|
+
taskId: string;
|
|
47
|
+
content?: string;
|
|
48
|
+
artifacts?: string[];
|
|
49
|
+
timestamp: string;
|
|
50
|
+
metadata?: {
|
|
51
|
+
duration?: number;
|
|
52
|
+
iterations?: number;
|
|
53
|
+
tokensUsed?: number;
|
|
54
|
+
[key: string]: unknown;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export type TaskLifecycleEvent = TaskCreatedEvent | TaskStatusEvent | TaskCompleteEvent;
|
|
58
|
+
export interface ContentDeltaEvent {
|
|
59
|
+
kind: 'content-delta';
|
|
60
|
+
contextId: string;
|
|
61
|
+
taskId: string;
|
|
62
|
+
delta: string;
|
|
63
|
+
index: number;
|
|
64
|
+
timestamp: string;
|
|
65
|
+
}
|
|
66
|
+
export type FinishReason = 'stop' | 'length' | 'tool_calls' | 'content_filter';
|
|
67
|
+
export interface ContentCompleteEvent {
|
|
68
|
+
kind: 'content-complete';
|
|
69
|
+
contextId: string;
|
|
70
|
+
taskId: string;
|
|
71
|
+
content: string;
|
|
72
|
+
finishReason: FinishReason;
|
|
73
|
+
toolCalls?: Array<{
|
|
74
|
+
id: string;
|
|
75
|
+
type: 'function';
|
|
76
|
+
function: {
|
|
77
|
+
name: string;
|
|
78
|
+
arguments: Record<string, unknown>;
|
|
79
|
+
};
|
|
80
|
+
}>;
|
|
81
|
+
timestamp: string;
|
|
82
|
+
}
|
|
83
|
+
export type ContentStreamingEvent = ContentDeltaEvent | ContentCompleteEvent;
|
|
84
|
+
export interface ToolCallEvent {
|
|
85
|
+
kind: 'tool-call';
|
|
86
|
+
contextId: string;
|
|
87
|
+
taskId: string;
|
|
88
|
+
toolCallId: string;
|
|
89
|
+
toolName: string;
|
|
90
|
+
arguments: Record<string, unknown>;
|
|
91
|
+
timestamp: string;
|
|
92
|
+
metadata?: {
|
|
93
|
+
[key: string]: unknown;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export interface ToolStartEvent {
|
|
97
|
+
kind: 'tool-start';
|
|
98
|
+
contextId: string;
|
|
99
|
+
taskId: string;
|
|
100
|
+
toolCallId: string;
|
|
101
|
+
toolName: string;
|
|
102
|
+
arguments: Record<string, unknown>;
|
|
103
|
+
timestamp: string;
|
|
104
|
+
metadata?: {
|
|
105
|
+
provider?: string;
|
|
106
|
+
concurrent?: boolean;
|
|
107
|
+
[key: string]: unknown;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
export interface ToolProgressEvent {
|
|
111
|
+
kind: 'tool-progress';
|
|
112
|
+
contextId: string;
|
|
113
|
+
taskId: string;
|
|
114
|
+
toolCallId: string;
|
|
115
|
+
progress: number;
|
|
116
|
+
message?: string;
|
|
117
|
+
timestamp: string;
|
|
118
|
+
metadata?: {
|
|
119
|
+
step?: string;
|
|
120
|
+
stepsCompleted?: number;
|
|
121
|
+
stepsTotal?: number;
|
|
122
|
+
[key: string]: unknown;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export interface ToolCompleteEvent {
|
|
126
|
+
kind: 'tool-complete';
|
|
127
|
+
contextId: string;
|
|
128
|
+
taskId: string;
|
|
129
|
+
toolCallId: string;
|
|
130
|
+
toolName: string;
|
|
131
|
+
success: boolean;
|
|
132
|
+
result?: unknown;
|
|
133
|
+
error?: string;
|
|
134
|
+
timestamp: string;
|
|
135
|
+
metadata?: {
|
|
136
|
+
duration?: number;
|
|
137
|
+
cached?: boolean;
|
|
138
|
+
retries?: number;
|
|
139
|
+
[key: string]: unknown;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
export type ToolExecutionEvent = ToolCallEvent | ToolStartEvent | ToolProgressEvent | ToolCompleteEvent;
|
|
143
|
+
export interface InputRequiredEvent {
|
|
144
|
+
kind: 'input-required';
|
|
145
|
+
contextId: string;
|
|
146
|
+
taskId: string;
|
|
147
|
+
inputId: string;
|
|
148
|
+
requireUser?: boolean;
|
|
149
|
+
inputType: InputType;
|
|
150
|
+
prompt: string;
|
|
151
|
+
schema?: JSONSchema;
|
|
152
|
+
options?: unknown[];
|
|
153
|
+
timestamp: string;
|
|
154
|
+
metadata?: {
|
|
155
|
+
toolCall?: ToolCall;
|
|
156
|
+
urgency?: 'low' | 'medium' | 'high';
|
|
157
|
+
timeout?: number;
|
|
158
|
+
[key: string]: unknown;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
export interface InputReceivedEvent {
|
|
162
|
+
kind: 'input-received';
|
|
163
|
+
contextId: string;
|
|
164
|
+
taskId: string;
|
|
165
|
+
inputId: string;
|
|
166
|
+
providedBy: InputProvider;
|
|
167
|
+
userId?: string;
|
|
168
|
+
agentId?: string;
|
|
169
|
+
timestamp: string;
|
|
170
|
+
metadata?: {
|
|
171
|
+
duration?: number;
|
|
172
|
+
[key: string]: unknown;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
export type InputRequestEvent = InputRequiredEvent | InputReceivedEvent;
|
|
176
|
+
export interface AuthRequiredEvent {
|
|
177
|
+
kind: 'auth-required';
|
|
178
|
+
contextId: string;
|
|
179
|
+
taskId: string;
|
|
180
|
+
authId: string;
|
|
181
|
+
authType: AuthType;
|
|
182
|
+
provider?: string;
|
|
183
|
+
scopes?: string[];
|
|
184
|
+
prompt: string;
|
|
185
|
+
authUrl?: string;
|
|
186
|
+
timestamp: string;
|
|
187
|
+
metadata?: {
|
|
188
|
+
expiresIn?: number;
|
|
189
|
+
[key: string]: unknown;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
export interface AuthCompletedEvent {
|
|
193
|
+
kind: 'auth-completed';
|
|
194
|
+
contextId: string;
|
|
195
|
+
taskId: string;
|
|
196
|
+
authId: string;
|
|
197
|
+
userId: string;
|
|
198
|
+
timestamp: string;
|
|
199
|
+
metadata?: {
|
|
200
|
+
expiresAt?: string;
|
|
201
|
+
[key: string]: unknown;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
export type AuthenticationEvent = AuthRequiredEvent | AuthCompletedEvent;
|
|
205
|
+
export interface FileWriteEvent {
|
|
206
|
+
kind: 'file-write';
|
|
207
|
+
contextId: string;
|
|
208
|
+
taskId: string;
|
|
209
|
+
artifactId: string;
|
|
210
|
+
data: string;
|
|
211
|
+
index: number;
|
|
212
|
+
complete: boolean;
|
|
213
|
+
timestamp: string;
|
|
214
|
+
name?: string;
|
|
215
|
+
description?: string;
|
|
216
|
+
mimeType?: string;
|
|
217
|
+
encoding?: 'utf-8' | 'base64';
|
|
218
|
+
metadata?: {
|
|
219
|
+
toolCallId?: string;
|
|
220
|
+
totalSize?: number;
|
|
221
|
+
[key: string]: unknown;
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
export interface DataWriteEvent {
|
|
225
|
+
kind: 'data-write';
|
|
226
|
+
contextId: string;
|
|
227
|
+
taskId: string;
|
|
228
|
+
artifactId: string;
|
|
229
|
+
name?: string;
|
|
230
|
+
description?: string;
|
|
231
|
+
data: Record<string, unknown>;
|
|
232
|
+
timestamp: string;
|
|
233
|
+
metadata?: {
|
|
234
|
+
toolCallId?: string;
|
|
235
|
+
version?: number;
|
|
236
|
+
[key: string]: unknown;
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
export interface DatasetWriteEvent {
|
|
240
|
+
kind: 'dataset-write';
|
|
241
|
+
contextId: string;
|
|
242
|
+
taskId: string;
|
|
243
|
+
artifactId: string;
|
|
244
|
+
rows: Record<string, unknown>[];
|
|
245
|
+
index: number;
|
|
246
|
+
complete: boolean;
|
|
247
|
+
timestamp: string;
|
|
248
|
+
name?: string;
|
|
249
|
+
description?: string;
|
|
250
|
+
schema?: JSONSchema;
|
|
251
|
+
metadata?: {
|
|
252
|
+
toolCallId?: string;
|
|
253
|
+
totalRows?: number;
|
|
254
|
+
batchSize?: number;
|
|
255
|
+
[key: string]: unknown;
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
export type ArtifactEvent = FileWriteEvent | DataWriteEvent | DatasetWriteEvent;
|
|
259
|
+
export interface SubtaskCreatedEvent {
|
|
260
|
+
kind: 'subtask-created';
|
|
261
|
+
contextId: string;
|
|
262
|
+
taskId: string;
|
|
263
|
+
subtaskId: string;
|
|
264
|
+
agentId?: string;
|
|
265
|
+
prompt: string;
|
|
266
|
+
timestamp: string;
|
|
267
|
+
}
|
|
268
|
+
export type SubAgentEvent = SubtaskCreatedEvent;
|
|
269
|
+
export interface ThoughtStreamEvent {
|
|
270
|
+
kind: 'thought-stream';
|
|
271
|
+
contextId: string;
|
|
272
|
+
taskId: string;
|
|
273
|
+
thoughtId: string;
|
|
274
|
+
thoughtType: ThoughtType;
|
|
275
|
+
verbosity: ThoughtVerbosity;
|
|
276
|
+
content: string;
|
|
277
|
+
index: number;
|
|
278
|
+
timestamp: string;
|
|
279
|
+
metadata?: {
|
|
280
|
+
source?: 'content' | 'content-delta' | 'tool-call';
|
|
281
|
+
confidence?: number;
|
|
282
|
+
alternatives?: string[];
|
|
283
|
+
relatedTo?: string;
|
|
284
|
+
[key: string]: unknown;
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
export interface InternalThoughtProcessEvent {
|
|
288
|
+
kind: 'internal:thought-process';
|
|
289
|
+
contextId: string;
|
|
290
|
+
taskId: string;
|
|
291
|
+
iteration: number;
|
|
292
|
+
stage: 'pre-llm' | 'post-llm' | 'pre-tool' | 'post-tool';
|
|
293
|
+
reasoning: string;
|
|
294
|
+
state: Record<string, unknown>;
|
|
295
|
+
timestamp: string;
|
|
296
|
+
}
|
|
297
|
+
export interface InternalLLMCallEvent {
|
|
298
|
+
kind: 'internal:llm-call';
|
|
299
|
+
contextId: string;
|
|
300
|
+
taskId: string;
|
|
301
|
+
iteration: number;
|
|
302
|
+
messageCount: number;
|
|
303
|
+
toolCount: number;
|
|
304
|
+
timestamp: string;
|
|
305
|
+
}
|
|
306
|
+
export interface InternalCheckpointEvent {
|
|
307
|
+
kind: 'internal:checkpoint';
|
|
308
|
+
contextId: string;
|
|
309
|
+
taskId: string;
|
|
310
|
+
iteration: number;
|
|
311
|
+
timestamp: string;
|
|
312
|
+
}
|
|
313
|
+
export interface InternalToolStartEvent {
|
|
314
|
+
kind: 'internal:tool-start';
|
|
315
|
+
contextId: string;
|
|
316
|
+
taskId: string;
|
|
317
|
+
toolCallId: string;
|
|
318
|
+
toolName: string;
|
|
319
|
+
timestamp: string;
|
|
320
|
+
}
|
|
321
|
+
export interface InternalToolCompleteEvent {
|
|
322
|
+
kind: 'internal:tool-complete';
|
|
323
|
+
contextId: string;
|
|
324
|
+
taskId: string;
|
|
325
|
+
toolCallId: string;
|
|
326
|
+
toolName: string;
|
|
327
|
+
success: boolean;
|
|
328
|
+
error?: string;
|
|
329
|
+
timestamp: string;
|
|
330
|
+
}
|
|
331
|
+
export type InternalDebugEvent = InternalLLMCallEvent | InternalCheckpointEvent | InternalToolStartEvent | InternalToolCompleteEvent | InternalThoughtProcessEvent;
|
|
332
|
+
export interface LLMUsageEvent {
|
|
333
|
+
kind: 'llm-usage';
|
|
334
|
+
contextId: string;
|
|
335
|
+
taskId: string;
|
|
336
|
+
model: string;
|
|
337
|
+
prompt_tokens?: number;
|
|
338
|
+
completion_tokens?: number;
|
|
339
|
+
total_tokens?: number;
|
|
340
|
+
completion_tokens_details?: Record<string, number>;
|
|
341
|
+
prompt_tokens_details?: Record<string, number>;
|
|
342
|
+
cache_creation_input_tokens?: number;
|
|
343
|
+
cache_read_input_tokens?: number;
|
|
344
|
+
timestamp: string;
|
|
345
|
+
}
|
|
346
|
+
export type UsageEvent = LLMUsageEvent;
|
|
347
|
+
export type AnyEvent = TaskLifecycleEvent | ContentStreamingEvent | ToolExecutionEvent | InputRequestEvent | AuthenticationEvent | ArtifactEvent | SubAgentEvent | ThoughtStreamEvent | InternalDebugEvent | UsageEvent;
|
|
348
|
+
export type LLMEvent<T> = Omit<T, 'contextId' | 'taskId'>;
|
|
349
|
+
export type ExternalEvent = Exclude<AnyEvent, InternalDebugEvent>;
|
|
350
|
+
export type DebugEvent = InternalDebugEvent;
|
|
351
|
+
export declare function isExternalEvent(event: AnyEvent): event is ExternalEvent;
|
|
352
|
+
export declare function isDebugEvent(event: AnyEvent): event is DebugEvent;
|
|
353
|
+
export declare function isTaskLifecycleEvent(event: AnyEvent): event is TaskLifecycleEvent;
|
|
354
|
+
export declare function isContentStreamingEvent(event: AnyEvent): event is ContentStreamingEvent;
|
|
355
|
+
export declare function isToolExecutionEvent(event: AnyEvent): event is ToolExecutionEvent;
|
|
356
|
+
export declare function isInputRequestEvent(event: AnyEvent): event is InputRequestEvent;
|
|
357
|
+
export declare function isAuthenticationEvent(event: AnyEvent): event is AuthenticationEvent;
|
|
358
|
+
export declare function isArtifactEvent(event: AnyEvent): event is ArtifactEvent;
|
|
359
|
+
export declare function isSubAgentEvent(event: AnyEvent): event is SubAgentEvent;
|
|
360
|
+
export declare function isThoughtStreamEvent(event: AnyEvent): event is ThoughtStreamEvent;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function isExternalEvent(event) {
|
|
2
|
+
return !event.kind.startsWith('internal:');
|
|
3
|
+
}
|
|
4
|
+
export function isDebugEvent(event) {
|
|
5
|
+
return event.kind.startsWith('internal:');
|
|
6
|
+
}
|
|
7
|
+
export function isTaskLifecycleEvent(event) {
|
|
8
|
+
return (event.kind === 'task-created' || event.kind === 'task-status' || event.kind === 'task-complete');
|
|
9
|
+
}
|
|
10
|
+
export function isContentStreamingEvent(event) {
|
|
11
|
+
return event.kind === 'content-delta' || event.kind === 'content-complete';
|
|
12
|
+
}
|
|
13
|
+
export function isToolExecutionEvent(event) {
|
|
14
|
+
return (event.kind === 'tool-start' || event.kind === 'tool-progress' || event.kind === 'tool-complete');
|
|
15
|
+
}
|
|
16
|
+
export function isInputRequestEvent(event) {
|
|
17
|
+
return event.kind === 'input-required' || event.kind === 'input-received';
|
|
18
|
+
}
|
|
19
|
+
export function isAuthenticationEvent(event) {
|
|
20
|
+
return event.kind === 'auth-required' || event.kind === 'auth-completed';
|
|
21
|
+
}
|
|
22
|
+
export function isArtifactEvent(event) {
|
|
23
|
+
return (event.kind === 'file-write' || event.kind === 'data-write' || event.kind === 'dataset-write');
|
|
24
|
+
}
|
|
25
|
+
export function isSubAgentEvent(event) {
|
|
26
|
+
return event.kind === 'subtask-created';
|
|
27
|
+
}
|
|
28
|
+
export function isThoughtStreamEvent(event) {
|
|
29
|
+
return event.kind === 'thought-stream';
|
|
30
|
+
}
|