@lupaflow/types 0.1.0
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/package.json +30 -0
- package/src/agent.ts +46 -0
- package/src/events.ts +155 -0
- package/src/index.ts +7 -0
- package/src/memory.ts +25 -0
- package/src/plugin.ts +18 -0
- package/src/provider.ts +73 -0
- package/src/tool.ts +20 -0
- package/src/workflow.ts +48 -0
- package/tsconfig.json +8 -0
- package/tsup.config.ts +9 -0
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lupaflow/types",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"require": "./dist/index.js",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"dev": "tsup --watch"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"tsup": "^8.3.0",
|
|
28
|
+
"typescript": "^5.6.0"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/agent.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ProviderName } from "./provider"
|
|
2
|
+
import type { Tool } from "./tool"
|
|
3
|
+
|
|
4
|
+
export interface Personality {
|
|
5
|
+
name?: string
|
|
6
|
+
traits?: string[]
|
|
7
|
+
tone?: string
|
|
8
|
+
style?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Goal {
|
|
12
|
+
description: string
|
|
13
|
+
priority?: number
|
|
14
|
+
completed?: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface Constraint {
|
|
18
|
+
description: string
|
|
19
|
+
type?: "hard" | "soft"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface AgentConfig {
|
|
23
|
+
id?: string
|
|
24
|
+
name: string
|
|
25
|
+
provider: ProviderName
|
|
26
|
+
model?: string
|
|
27
|
+
systemPrompt?: string
|
|
28
|
+
personality?: Personality
|
|
29
|
+
goals?: Goal[]
|
|
30
|
+
constraints?: Constraint[]
|
|
31
|
+
temperature?: number
|
|
32
|
+
maxTokens?: number
|
|
33
|
+
topP?: number
|
|
34
|
+
maxRetries?: number
|
|
35
|
+
retryDelay?: number
|
|
36
|
+
maxContextMessages?: number
|
|
37
|
+
tools?: Tool[]
|
|
38
|
+
memory?: {
|
|
39
|
+
shortTerm?: boolean
|
|
40
|
+
longTerm?: boolean
|
|
41
|
+
semantic?: boolean
|
|
42
|
+
session?: boolean
|
|
43
|
+
user?: boolean
|
|
44
|
+
project?: boolean
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/events.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
export type EventName =
|
|
2
|
+
| "agent:start"
|
|
3
|
+
| "agent:thinking"
|
|
4
|
+
| "agent:response"
|
|
5
|
+
| "agent:error"
|
|
6
|
+
| "agent:complete"
|
|
7
|
+
| "tool:start"
|
|
8
|
+
| "tool:finish"
|
|
9
|
+
| "tool:error"
|
|
10
|
+
| "memory:update"
|
|
11
|
+
| "memory:retrieve"
|
|
12
|
+
| "workflow:start"
|
|
13
|
+
| "workflow:step"
|
|
14
|
+
| "workflow:complete"
|
|
15
|
+
| "workflow:error"
|
|
16
|
+
| "provider:start"
|
|
17
|
+
| "provider:complete"
|
|
18
|
+
| "provider:error"
|
|
19
|
+
| "llm:token"
|
|
20
|
+
|
|
21
|
+
export interface BaseEvent {
|
|
22
|
+
id: string
|
|
23
|
+
name: EventName
|
|
24
|
+
timestamp: number
|
|
25
|
+
agentId?: string
|
|
26
|
+
runId?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AgentStartEvent extends BaseEvent {
|
|
30
|
+
name: "agent:start"
|
|
31
|
+
config: Record<string, unknown>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface AgentThinkingEvent extends BaseEvent {
|
|
35
|
+
name: "agent:thinking"
|
|
36
|
+
message: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface AgentResponseEvent extends BaseEvent {
|
|
40
|
+
name: "agent:response"
|
|
41
|
+
content: string
|
|
42
|
+
tokens?: number
|
|
43
|
+
latencyMs?: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface AgentErrorEvent extends BaseEvent {
|
|
47
|
+
name: "agent:error"
|
|
48
|
+
error: string
|
|
49
|
+
retryAttempt?: number
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface AgentCompleteEvent extends BaseEvent {
|
|
53
|
+
name: "agent:complete"
|
|
54
|
+
totalTokens: number
|
|
55
|
+
totalLatencyMs: number
|
|
56
|
+
toolCalls: number
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ToolStartEvent extends BaseEvent {
|
|
60
|
+
name: "tool:start"
|
|
61
|
+
tool: string
|
|
62
|
+
args: Record<string, unknown>
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface ToolFinishEvent extends BaseEvent {
|
|
66
|
+
name: "tool:finish"
|
|
67
|
+
tool: string
|
|
68
|
+
result: unknown
|
|
69
|
+
durationMs: number
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface ToolErrorEvent extends BaseEvent {
|
|
73
|
+
name: "tool:error"
|
|
74
|
+
tool: string
|
|
75
|
+
error: string
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface MemoryUpdateEvent extends BaseEvent {
|
|
79
|
+
name: "memory:update"
|
|
80
|
+
type: string
|
|
81
|
+
key: string
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface MemoryRetrieveEvent extends BaseEvent {
|
|
85
|
+
name: "memory:retrieve"
|
|
86
|
+
type: string
|
|
87
|
+
key: string
|
|
88
|
+
results: number
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface WorkflowStartEvent extends BaseEvent {
|
|
92
|
+
name: "workflow:start"
|
|
93
|
+
steps: number
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface WorkflowStepEvent extends BaseEvent {
|
|
97
|
+
name: "workflow:step"
|
|
98
|
+
step: number
|
|
99
|
+
stepName: string
|
|
100
|
+
status: "running" | "completed" | "failed"
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface WorkflowCompleteEvent extends BaseEvent {
|
|
104
|
+
name: "workflow:complete"
|
|
105
|
+
totalSteps: number
|
|
106
|
+
failedSteps: number
|
|
107
|
+
durationMs: number
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface ProviderStartEvent extends BaseEvent {
|
|
111
|
+
name: "provider:start"
|
|
112
|
+
provider: string
|
|
113
|
+
model: string
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface ProviderCompleteEvent extends BaseEvent {
|
|
117
|
+
name: "provider:complete"
|
|
118
|
+
provider: string
|
|
119
|
+
model: string
|
|
120
|
+
tokens: number
|
|
121
|
+
latencyMs: number
|
|
122
|
+
cost?: number
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface ProviderErrorEvent extends BaseEvent {
|
|
126
|
+
name: "provider:error"
|
|
127
|
+
provider: string
|
|
128
|
+
model: string
|
|
129
|
+
error: string
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface LLMTokenEvent extends BaseEvent {
|
|
133
|
+
name: "llm:token"
|
|
134
|
+
tokens: number
|
|
135
|
+
cost?: number
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export type LupaEvent =
|
|
139
|
+
| AgentStartEvent
|
|
140
|
+
| AgentThinkingEvent
|
|
141
|
+
| AgentResponseEvent
|
|
142
|
+
| AgentErrorEvent
|
|
143
|
+
| AgentCompleteEvent
|
|
144
|
+
| ToolStartEvent
|
|
145
|
+
| ToolFinishEvent
|
|
146
|
+
| ToolErrorEvent
|
|
147
|
+
| MemoryUpdateEvent
|
|
148
|
+
| MemoryRetrieveEvent
|
|
149
|
+
| WorkflowStartEvent
|
|
150
|
+
| WorkflowStepEvent
|
|
151
|
+
| WorkflowCompleteEvent
|
|
152
|
+
| ProviderStartEvent
|
|
153
|
+
| ProviderCompleteEvent
|
|
154
|
+
| ProviderErrorEvent
|
|
155
|
+
| LLMTokenEvent
|
package/src/index.ts
ADDED
package/src/memory.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type MemoryType = "short-term" | "long-term" | "semantic" | "session" | "user" | "project" | "vector"
|
|
2
|
+
|
|
3
|
+
export interface MemoryEntry {
|
|
4
|
+
id: string
|
|
5
|
+
type: MemoryType
|
|
6
|
+
key: string
|
|
7
|
+
content: string
|
|
8
|
+
metadata?: Record<string, unknown>
|
|
9
|
+
timestamp: number
|
|
10
|
+
scope?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface MemoryQuery {
|
|
14
|
+
type?: MemoryType
|
|
15
|
+
key?: string
|
|
16
|
+
scope?: string
|
|
17
|
+
query?: string
|
|
18
|
+
limit?: number
|
|
19
|
+
threshold?: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface MemorySearchResult {
|
|
23
|
+
entry: MemoryEntry
|
|
24
|
+
score: number
|
|
25
|
+
}
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { LupaEvent } from "./events"
|
|
2
|
+
|
|
3
|
+
export interface Plugin {
|
|
4
|
+
name: string
|
|
5
|
+
version: string
|
|
6
|
+
description?: string
|
|
7
|
+
onLoad?: () => void | Promise<void>
|
|
8
|
+
onUnload?: () => void | Promise<void>
|
|
9
|
+
onEvent?: (event: LupaEvent) => void | Promise<void>
|
|
10
|
+
hooks?: {
|
|
11
|
+
beforeAgentRun?: (config: Record<string, unknown>) => Record<string, unknown>
|
|
12
|
+
afterAgentRun?: (result: unknown) => unknown
|
|
13
|
+
beforeToolCall?: (tool: string, args: Record<string, unknown>) => Record<string, unknown>
|
|
14
|
+
afterToolCall?: (result: unknown) => unknown
|
|
15
|
+
beforeProviderCall?: (provider: string, request: Record<string, unknown>) => Record<string, unknown>
|
|
16
|
+
afterProviderCall?: (response: Record<string, unknown>) => Record<string, unknown>
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/provider.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Tool } from "./tool"
|
|
2
|
+
|
|
3
|
+
export type ProviderName = "openai" | "anthropic" | "google" | "openrouter" | "groq" | "mistral" | "xai" | "ollama"
|
|
4
|
+
|
|
5
|
+
export type ModelRole = "system" | "user" | "assistant" | "tool"
|
|
6
|
+
|
|
7
|
+
export interface Message {
|
|
8
|
+
role: ModelRole
|
|
9
|
+
content: string | null
|
|
10
|
+
toolCallId?: string
|
|
11
|
+
name?: string
|
|
12
|
+
toolCalls?: Array<{
|
|
13
|
+
id: string
|
|
14
|
+
type: "function"
|
|
15
|
+
function: { name: string; arguments: string }
|
|
16
|
+
}>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ToolCall {
|
|
20
|
+
id: string
|
|
21
|
+
name: string
|
|
22
|
+
args: Record<string, unknown>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ToolResult {
|
|
26
|
+
toolCallId: string
|
|
27
|
+
name: string
|
|
28
|
+
content: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ProviderConfig {
|
|
32
|
+
apiKey?: string
|
|
33
|
+
baseUrl?: string
|
|
34
|
+
model?: string
|
|
35
|
+
temperature?: number
|
|
36
|
+
maxTokens?: number
|
|
37
|
+
topP?: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface CompletionRequest {
|
|
41
|
+
messages: Message[]
|
|
42
|
+
tools?: Tool[]
|
|
43
|
+
systemPrompt?: string
|
|
44
|
+
temperature?: number
|
|
45
|
+
maxTokens?: number
|
|
46
|
+
topP?: number
|
|
47
|
+
model?: string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface CompletionResponse {
|
|
51
|
+
content: string | null
|
|
52
|
+
toolCalls: ToolCall[]
|
|
53
|
+
usage: {
|
|
54
|
+
promptTokens: number
|
|
55
|
+
completionTokens: number
|
|
56
|
+
totalTokens: number
|
|
57
|
+
}
|
|
58
|
+
model: string
|
|
59
|
+
latencyMs: number
|
|
60
|
+
finishReason: string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type StreamChunk =
|
|
64
|
+
| { type: "text"; text: string }
|
|
65
|
+
| { type: "tool_call"; toolCall: ToolCall }
|
|
66
|
+
| {
|
|
67
|
+
type: "finish"
|
|
68
|
+
content: string
|
|
69
|
+
toolCalls: ToolCall[]
|
|
70
|
+
usage: { promptTokens: number; completionTokens: number; totalTokens: number }
|
|
71
|
+
model: string
|
|
72
|
+
finishReason: string
|
|
73
|
+
}
|
package/src/tool.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface ToolParameter {
|
|
2
|
+
type: "string" | "number" | "boolean" | "array" | "object"
|
|
3
|
+
description: string
|
|
4
|
+
required?: boolean
|
|
5
|
+
enum?: string[]
|
|
6
|
+
items?: ToolParameter
|
|
7
|
+
properties?: Record<string, ToolParameter>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ToolDefinition {
|
|
11
|
+
name: string
|
|
12
|
+
description: string
|
|
13
|
+
parameters: Record<string, ToolParameter>
|
|
14
|
+
required?: string[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface Tool {
|
|
18
|
+
definition: ToolDefinition
|
|
19
|
+
execute: (args: Record<string, unknown>) => Promise<unknown>
|
|
20
|
+
}
|
package/src/workflow.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AgentConfig } from "./agent"
|
|
2
|
+
import type { Tool } from "./tool"
|
|
3
|
+
|
|
4
|
+
export type WorkflowStepType = "agent" | "tool" | "transform" | "condition" | "loop"
|
|
5
|
+
|
|
6
|
+
export interface WorkflowStepConfig {
|
|
7
|
+
id: string
|
|
8
|
+
name: string
|
|
9
|
+
type: WorkflowStepType
|
|
10
|
+
agent?: AgentConfig
|
|
11
|
+
tool?: Tool
|
|
12
|
+
input?: Record<string, unknown>
|
|
13
|
+
transform?: (input: unknown) => unknown
|
|
14
|
+
condition?: (input: unknown) => boolean
|
|
15
|
+
maxIterations?: number
|
|
16
|
+
onComplete?: (result: unknown) => void
|
|
17
|
+
onError?: (error: Error) => void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface WorkflowConfig {
|
|
21
|
+
id?: string
|
|
22
|
+
name: string
|
|
23
|
+
description?: string
|
|
24
|
+
steps: WorkflowStepConfig[]
|
|
25
|
+
maxRetries?: number
|
|
26
|
+
onComplete?: (results: unknown[]) => void
|
|
27
|
+
onError?: (error: Error) => void
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface WorkflowResult {
|
|
31
|
+
id: string
|
|
32
|
+
name: string
|
|
33
|
+
success: boolean
|
|
34
|
+
steps: WorkflowStepResult[]
|
|
35
|
+
durationMs: number
|
|
36
|
+
error?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface WorkflowStepResult {
|
|
40
|
+
id: string
|
|
41
|
+
name: string
|
|
42
|
+
type: WorkflowStepType
|
|
43
|
+
status: "success" | "failed" | "skipped"
|
|
44
|
+
input?: unknown
|
|
45
|
+
output?: unknown
|
|
46
|
+
durationMs: number
|
|
47
|
+
error?: string
|
|
48
|
+
}
|
package/tsconfig.json
ADDED