jiva-core 0.2.2 → 0.3.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/.dockerignore +53 -0
- package/.gcloudignore +49 -0
- package/CONTRIBUTING.md +92 -0
- package/Dockerfile +63 -0
- package/LICENSE +21 -0
- package/README.md +248 -102
- package/cloud-run-deploy.yaml +135 -0
- package/cloud-run.yaml +135 -0
- package/cloud-run.yaml.template +143 -0
- package/deploy.sh +107 -0
- package/dist/core/agent-spawner.d.ts +89 -0
- package/dist/core/agent-spawner.d.ts.map +1 -0
- package/dist/core/agent-spawner.js +195 -0
- package/dist/core/agent-spawner.js.map +1 -0
- package/dist/core/client-agent.d.ts +82 -0
- package/dist/core/client-agent.d.ts.map +1 -0
- package/dist/core/client-agent.js +406 -0
- package/dist/core/client-agent.js.map +1 -0
- package/dist/core/config.d.ts +59 -10
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +19 -2
- package/dist/core/config.js.map +1 -1
- package/dist/core/conversation-manager.d.ts +10 -18
- package/dist/core/conversation-manager.d.ts.map +1 -1
- package/dist/core/conversation-manager.js +28 -60
- package/dist/core/conversation-manager.js.map +1 -1
- package/dist/core/dual-agent.d.ts +24 -3
- package/dist/core/dual-agent.d.ts.map +1 -1
- package/dist/core/dual-agent.js +112 -19
- package/dist/core/dual-agent.js.map +1 -1
- package/dist/core/manager-agent.d.ts +3 -1
- package/dist/core/manager-agent.d.ts.map +1 -1
- package/dist/core/manager-agent.js +66 -14
- package/dist/core/manager-agent.js.map +1 -1
- package/dist/core/worker-agent.d.ts +15 -1
- package/dist/core/worker-agent.d.ts.map +1 -1
- package/dist/core/worker-agent.js +244 -11
- package/dist/core/worker-agent.js.map +1 -1
- package/dist/core/workspace.d.ts +5 -0
- package/dist/core/workspace.d.ts.map +1 -1
- package/dist/core/workspace.js +47 -7
- package/dist/core/workspace.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/cli/index.js +376 -44
- package/dist/interfaces/cli/index.js.map +1 -1
- package/dist/interfaces/cli/repl.d.ts.map +1 -1
- package/dist/interfaces/cli/repl.js +6 -0
- package/dist/interfaces/cli/repl.js.map +1 -1
- package/dist/interfaces/http/index.d.ts +22 -0
- package/dist/interfaces/http/index.d.ts.map +1 -0
- package/dist/interfaces/http/index.js +135 -0
- package/dist/interfaces/http/index.js.map +1 -0
- package/dist/interfaces/http/middleware/auth.d.ts +32 -0
- package/dist/interfaces/http/middleware/auth.d.ts.map +1 -0
- package/dist/interfaces/http/middleware/auth.js +176 -0
- package/dist/interfaces/http/middleware/auth.js.map +1 -0
- package/dist/interfaces/http/routes/chat.d.ts +7 -0
- package/dist/interfaces/http/routes/chat.d.ts.map +1 -0
- package/dist/interfaces/http/routes/chat.js +144 -0
- package/dist/interfaces/http/routes/chat.js.map +1 -0
- package/dist/interfaces/http/routes/health.d.ts +6 -0
- package/dist/interfaces/http/routes/health.d.ts.map +1 -0
- package/dist/interfaces/http/routes/health.js +25 -0
- package/dist/interfaces/http/routes/health.js.map +1 -0
- package/dist/interfaces/http/routes/session.d.ts +7 -0
- package/dist/interfaces/http/routes/session.d.ts.map +1 -0
- package/dist/interfaces/http/routes/session.js +114 -0
- package/dist/interfaces/http/routes/session.js.map +1 -0
- package/dist/interfaces/http/session-manager.d.ts +76 -0
- package/dist/interfaces/http/session-manager.d.ts.map +1 -0
- package/dist/interfaces/http/session-manager.js +339 -0
- package/dist/interfaces/http/session-manager.js.map +1 -0
- package/dist/interfaces/http/websocket-handler.d.ts +18 -0
- package/dist/interfaces/http/websocket-handler.d.ts.map +1 -0
- package/dist/interfaces/http/websocket-handler.js +146 -0
- package/dist/interfaces/http/websocket-handler.js.map +1 -0
- package/dist/mcp/client.d.ts +11 -2
- package/dist/mcp/client.d.ts.map +1 -1
- package/dist/mcp/client.js +44 -19
- package/dist/mcp/client.js.map +1 -1
- package/dist/mcp/server-manager.d.ts +1 -1
- package/dist/mcp/server-manager.d.ts.map +1 -1
- package/dist/mcp/server-manager.js +12 -2
- package/dist/mcp/server-manager.js.map +1 -1
- package/dist/personas/index.d.ts +13 -0
- package/dist/personas/index.d.ts.map +1 -0
- package/dist/personas/index.js +13 -0
- package/dist/personas/index.js.map +1 -0
- package/dist/personas/persona-loader.d.ts +30 -0
- package/dist/personas/persona-loader.d.ts.map +1 -0
- package/dist/personas/persona-loader.js +246 -0
- package/dist/personas/persona-loader.js.map +1 -0
- package/dist/personas/persona-manager.d.ts +82 -0
- package/dist/personas/persona-manager.d.ts.map +1 -0
- package/dist/personas/persona-manager.js +211 -0
- package/dist/personas/persona-manager.js.map +1 -0
- package/dist/personas/skill-loader.d.ts +35 -0
- package/dist/personas/skill-loader.d.ts.map +1 -0
- package/dist/personas/skill-loader.js +144 -0
- package/dist/personas/skill-loader.js.map +1 -0
- package/dist/personas/skill-packager.d.ts +25 -0
- package/dist/personas/skill-packager.d.ts.map +1 -0
- package/dist/personas/skill-packager.js +233 -0
- package/dist/personas/skill-packager.js.map +1 -0
- package/dist/personas/types.d.ts +134 -0
- package/dist/personas/types.d.ts.map +1 -0
- package/dist/personas/types.js +7 -0
- package/dist/personas/types.js.map +1 -0
- package/dist/personas/validator.d.ts +22 -0
- package/dist/personas/validator.d.ts.map +1 -0
- package/dist/personas/validator.js +144 -0
- package/dist/personas/validator.js.map +1 -0
- package/dist/storage/factory.d.ts +51 -0
- package/dist/storage/factory.d.ts.map +1 -0
- package/dist/storage/factory.js +154 -0
- package/dist/storage/factory.js.map +1 -0
- package/dist/storage/gcp-bucket-provider.d.ts +59 -0
- package/dist/storage/gcp-bucket-provider.d.ts.map +1 -0
- package/dist/storage/gcp-bucket-provider.js +275 -0
- package/dist/storage/gcp-bucket-provider.js.map +1 -0
- package/dist/storage/index.d.ts +33 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +37 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/local-provider.d.ts +36 -0
- package/dist/storage/local-provider.d.ts.map +1 -0
- package/dist/storage/local-provider.js +219 -0
- package/dist/storage/local-provider.js.map +1 -0
- package/dist/storage/provider.d.ts +137 -0
- package/dist/storage/provider.d.ts.map +1 -0
- package/dist/storage/provider.js +136 -0
- package/dist/storage/provider.js.map +1 -0
- package/dist/storage/types.d.ts +78 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +14 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/utils/orchestration-logger.d.ts +36 -0
- package/dist/utils/orchestration-logger.d.ts.map +1 -0
- package/dist/utils/orchestration-logger.js +224 -0
- package/dist/utils/orchestration-logger.js.map +1 -0
- package/jiva-new-demo.gif +0 -0
- package/package.json +30 -2
- package/.fluen/cache/state.json +0 -7
- package/actions/action_registry.py +0 -75
- package/actions/python_coder.py +0 -470
- package/api/main.py +0 -269
- package/downloaded_image.avif +0 -0
- package/downloads/snipping_tool.avif +0 -0
- package/image.avif +0 -0
- package/ms_image.avif +0 -0
- package/screenshot.png +0 -0
- package/snipping_tool.avif +0 -0
- package/tmp_image.avif +0 -0
package/api/main.py
DELETED
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
# api/main.py
|
|
2
|
-
|
|
3
|
-
import asyncio
|
|
4
|
-
from fastapi import FastAPI, Depends, HTTPException
|
|
5
|
-
from fastapi.responses import JSONResponse
|
|
6
|
-
from typing import Dict, Any, List, Optional
|
|
7
|
-
import logging
|
|
8
|
-
from datetime import datetime
|
|
9
|
-
|
|
10
|
-
# Initialize FastAPI app
|
|
11
|
-
app = FastAPI(
|
|
12
|
-
title="Jiva Agent API",
|
|
13
|
-
description="REST API for interacting with Jiva agents",
|
|
14
|
-
version="1.0.0"
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
logger = logging.getLogger("Jiva.API")
|
|
18
|
-
|
|
19
|
-
def get_agent():
|
|
20
|
-
"""Dependency to get the agent instance from app state."""
|
|
21
|
-
if not hasattr(app.state, 'agent'):
|
|
22
|
-
raise HTTPException(status_code=503, detail="Agent not initialized")
|
|
23
|
-
return app.state.agent
|
|
24
|
-
|
|
25
|
-
@app.get("/status", response_model=Dict[str, Any])
|
|
26
|
-
async def get_status(agent = Depends(get_agent)) -> Dict[str, Any]:
|
|
27
|
-
"""Get the current status of the Jiva agent."""
|
|
28
|
-
try:
|
|
29
|
-
return {
|
|
30
|
-
"status": "Working" if agent.task_manager.has_pending_tasks() else "Idle",
|
|
31
|
-
"current_goal": agent.current_goal,
|
|
32
|
-
"pending_tasks": [
|
|
33
|
-
{
|
|
34
|
-
"id": task.id,
|
|
35
|
-
"description": task.description,
|
|
36
|
-
"status": task.status,
|
|
37
|
-
"created_at": task.created_at.isoformat()
|
|
38
|
-
} for task in agent.task_manager.task_queue.queue
|
|
39
|
-
] if agent.task_manager.has_pending_tasks() else []
|
|
40
|
-
}
|
|
41
|
-
except Exception as e:
|
|
42
|
-
logger.error(f"Error getting agent status: {str(e)}")
|
|
43
|
-
raise HTTPException(status_code=500, detail=str(e))
|
|
44
|
-
|
|
45
|
-
@app.get("/goals", response_model=List[Dict[str, Any]])
|
|
46
|
-
async def get_goals(agent = Depends(get_agent)) -> List[Dict[str, Any]]:
|
|
47
|
-
"""Get list of all goals, ordered by latest first."""
|
|
48
|
-
try:
|
|
49
|
-
# Get tasks from memory that have goal information
|
|
50
|
-
goal_tasks = []
|
|
51
|
-
for task_id, task in agent.task_manager.all_tasks.items():
|
|
52
|
-
if task.goal and not any(g["goal"] == task.goal for g in goal_tasks):
|
|
53
|
-
goal_tasks.append({
|
|
54
|
-
"goal": task.goal,
|
|
55
|
-
"created_at": task.created_at.isoformat(),
|
|
56
|
-
"status": "completed" if all(t.status == "completed"
|
|
57
|
-
for t in agent.task_manager.all_tasks.values()
|
|
58
|
-
if t.goal == task.goal) else "in_progress",
|
|
59
|
-
"first_task_id": task_id
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
# Sort by creation time, latest first
|
|
63
|
-
return sorted(goal_tasks, key=lambda x: x["created_at"], reverse=True)
|
|
64
|
-
except Exception as e:
|
|
65
|
-
logger.error(f"Error getting goals: {str(e)}")
|
|
66
|
-
raise HTTPException(status_code=500, detail=str(e))
|
|
67
|
-
|
|
68
|
-
@app.get("/tasks", response_model=List[Dict[str, Any]])
|
|
69
|
-
async def get_tasks(goal: Optional[str] = None, agent = Depends(get_agent)) -> List[Dict[str, Any]]:
|
|
70
|
-
"""Get list of tasks, optionally filtered by goal."""
|
|
71
|
-
try:
|
|
72
|
-
tasks = []
|
|
73
|
-
for task_id, task in agent.task_manager.all_tasks.items():
|
|
74
|
-
if goal is None or task.goal == goal:
|
|
75
|
-
tasks.append({
|
|
76
|
-
"id": task_id,
|
|
77
|
-
"description": task.description,
|
|
78
|
-
"status": task.status,
|
|
79
|
-
"created_at": task.created_at.isoformat(),
|
|
80
|
-
"completed_at": task.completed_at.isoformat() if task.completed_at else None,
|
|
81
|
-
"goal": task.goal,
|
|
82
|
-
"action": task.action,
|
|
83
|
-
"result": str(task.result) if task.result else None
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
# Sort by creation time, latest first
|
|
87
|
-
return sorted(tasks, key=lambda x: x["created_at"], reverse=True)
|
|
88
|
-
except Exception as e:
|
|
89
|
-
logger.error(f"Error getting tasks: {str(e)}")
|
|
90
|
-
raise HTTPException(status_code=500, detail=str(e))
|
|
91
|
-
|
|
92
|
-
@app.post("/goal", response_model=Dict[str, Any])
|
|
93
|
-
async def create_goal(goal: Dict[str, str], agent = Depends(get_agent)) -> Dict[str, Any]:
|
|
94
|
-
"""Create a new goal for the agent."""
|
|
95
|
-
try:
|
|
96
|
-
if 'description' not in goal:
|
|
97
|
-
raise HTTPException(status_code=400, detail="Goal description is required")
|
|
98
|
-
|
|
99
|
-
# Process the goal like a regular input
|
|
100
|
-
input_data = [{
|
|
101
|
-
"type": "goal",
|
|
102
|
-
"content": goal['description'],
|
|
103
|
-
"timestamp": datetime.now().isoformat()
|
|
104
|
-
}]
|
|
105
|
-
|
|
106
|
-
await agent.process_input(input_data)
|
|
107
|
-
|
|
108
|
-
# Wait a short time to allow initial task generation
|
|
109
|
-
await asyncio.sleep(0.5)
|
|
110
|
-
|
|
111
|
-
# Get the initial set of tasks
|
|
112
|
-
initial_tasks = [
|
|
113
|
-
{
|
|
114
|
-
"id": task.id,
|
|
115
|
-
"description": task.description,
|
|
116
|
-
"status": task.status
|
|
117
|
-
}
|
|
118
|
-
for task in agent.task_manager.task_queue.queue
|
|
119
|
-
] if agent.task_manager.has_pending_tasks() else []
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
"status": "success",
|
|
123
|
-
"message": "Goal created successfully",
|
|
124
|
-
"goal": goal['description'],
|
|
125
|
-
"initial_tasks": initial_tasks
|
|
126
|
-
}
|
|
127
|
-
except Exception as e:
|
|
128
|
-
logger.error(f"Error creating goal: {str(e)}")
|
|
129
|
-
raise HTTPException(status_code=500, detail=str(e))
|
|
130
|
-
|
|
131
|
-
@app.get("/about", response_model=Dict[str, Any])
|
|
132
|
-
async def get_about(agent = Depends(get_agent)) -> Dict[str, Any]:
|
|
133
|
-
"""Get information about the agent and its configuration."""
|
|
134
|
-
try:
|
|
135
|
-
# Get config without sensitive information
|
|
136
|
-
config = agent.config.copy()
|
|
137
|
-
# Remove sensitive fields
|
|
138
|
-
for provider in ['llm', 'mistral-llm']:
|
|
139
|
-
if provider in config:
|
|
140
|
-
if 'api_key' in config[provider]:
|
|
141
|
-
config[provider]['api_key'] = '***'
|
|
142
|
-
|
|
143
|
-
# Get available actions
|
|
144
|
-
actions = agent.action_manager.get_available_actions()
|
|
145
|
-
# Clean up action info for API response
|
|
146
|
-
clean_actions = {}
|
|
147
|
-
for action_name, action_info in actions.items():
|
|
148
|
-
clean_actions[action_name] = {
|
|
149
|
-
"description": action_info["description"],
|
|
150
|
-
"parameters": action_info["parameters"]
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
"config": config,
|
|
155
|
-
"available_actions": clean_actions,
|
|
156
|
-
"sensors": list(agent.sensor_manager.get_available_sensors())
|
|
157
|
-
}
|
|
158
|
-
except Exception as e:
|
|
159
|
-
logger.error(f"Error getting agent information: {str(e)}")
|
|
160
|
-
raise HTTPException(status_code=500, detail=str(e))
|
|
161
|
-
|
|
162
|
-
# Error handling
|
|
163
|
-
@app.exception_handler(Exception)
|
|
164
|
-
async def generic_exception_handler(request, exc):
|
|
165
|
-
logger.error(f"Unhandled exception: {str(exc)}")
|
|
166
|
-
return JSONResponse(
|
|
167
|
-
status_code=500,
|
|
168
|
-
content={"detail": "Internal server error"}
|
|
169
|
-
)
|
|
170
|
-
|
|
171
|
-
@app.post("/trigger", response_model=Dict[str, Any])
|
|
172
|
-
async def trigger_agent(agent = Depends(get_agent)) -> Dict[str, Any]:
|
|
173
|
-
"""Trigger the agent to check and execute pending tasks if it's idle."""
|
|
174
|
-
try:
|
|
175
|
-
if not agent.is_awake:
|
|
176
|
-
raise HTTPException(
|
|
177
|
-
status_code=400,
|
|
178
|
-
detail="Agent is sleeping and cannot be triggered"
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
# First get all pending tasks
|
|
182
|
-
pending_tasks = agent.task_manager.get_pending_tasks()
|
|
183
|
-
|
|
184
|
-
if not pending_tasks:
|
|
185
|
-
return {
|
|
186
|
-
"status": "no_action",
|
|
187
|
-
"message": "No pending tasks to execute",
|
|
188
|
-
"debug": {
|
|
189
|
-
"queue_size": 0,
|
|
190
|
-
"queue_tasks": [],
|
|
191
|
-
"all_pending_count": 0,
|
|
192
|
-
"all_pending": [],
|
|
193
|
-
"has_pending_tasks": False
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
# Requeue the pending tasks
|
|
198
|
-
agent.task_manager.requeue_pending_tasks()
|
|
199
|
-
|
|
200
|
-
# Signal the agent to check for tasks
|
|
201
|
-
agent._task_trigger.set()
|
|
202
|
-
|
|
203
|
-
return {
|
|
204
|
-
"status": "triggered",
|
|
205
|
-
"message": f"Agent triggered to execute {len(pending_tasks)} pending tasks",
|
|
206
|
-
"debug": {
|
|
207
|
-
"queue_size": len(pending_tasks),
|
|
208
|
-
"queue_tasks": [
|
|
209
|
-
{
|
|
210
|
-
"id": task.id,
|
|
211
|
-
"description": task.description,
|
|
212
|
-
"status": task.status,
|
|
213
|
-
"created_at": task.created_at.isoformat()
|
|
214
|
-
} for task in pending_tasks
|
|
215
|
-
],
|
|
216
|
-
"all_pending_count": len(pending_tasks),
|
|
217
|
-
"all_pending": [
|
|
218
|
-
{
|
|
219
|
-
"id": task.id,
|
|
220
|
-
"description": task.description
|
|
221
|
-
} for task in pending_tasks
|
|
222
|
-
],
|
|
223
|
-
"has_pending_tasks": True
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
except Exception as e:
|
|
228
|
-
logger.error(f"Error triggering agent: {str(e)}")
|
|
229
|
-
raise HTTPException(status_code=500, detail=str(e))
|
|
230
|
-
|
|
231
|
-
@app.get("/about", response_model=Dict[str, Any])
|
|
232
|
-
async def get_about(agent = Depends(get_agent)) -> Dict[str, Any]:
|
|
233
|
-
"""Get information about the agent and its configuration."""
|
|
234
|
-
try:
|
|
235
|
-
# Get config without sensitive information
|
|
236
|
-
config = agent.config.copy()
|
|
237
|
-
# Remove sensitive fields
|
|
238
|
-
for provider in ['llm', 'mistral-llm']:
|
|
239
|
-
if provider in config:
|
|
240
|
-
if 'api_key' in config[provider]:
|
|
241
|
-
config[provider]['api_key'] = '***'
|
|
242
|
-
|
|
243
|
-
# Get available actions
|
|
244
|
-
actions = agent.action_manager.get_available_actions()
|
|
245
|
-
clean_actions = {}
|
|
246
|
-
for action_name, action_info in actions.items():
|
|
247
|
-
clean_actions[action_name] = {
|
|
248
|
-
"description": action_info["description"],
|
|
249
|
-
"parameters": action_info["parameters"]
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
# Add sleep cycle status
|
|
253
|
-
status = {
|
|
254
|
-
"sleep_cycle": {
|
|
255
|
-
"enabled": agent.sleep_config.get('enabled', False),
|
|
256
|
-
"is_awake": agent.is_awake,
|
|
257
|
-
"last_sleep_time": agent.last_sleep_time.isoformat() if agent.last_sleep_time else None
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return {
|
|
262
|
-
"config": config,
|
|
263
|
-
"available_actions": clean_actions,
|
|
264
|
-
"sensors": list(agent.sensor_manager.get_available_sensors()),
|
|
265
|
-
"status": status
|
|
266
|
-
}
|
|
267
|
-
except Exception as e:
|
|
268
|
-
logger.error(f"Error getting agent information: {str(e)}")
|
|
269
|
-
raise HTTPException(status_code=500, detail=str(e))
|
package/downloaded_image.avif
DELETED
|
Binary file
|
|
Binary file
|
package/image.avif
DELETED
|
Binary file
|
package/ms_image.avif
DELETED
|
Binary file
|
package/screenshot.png
DELETED
|
Binary file
|
package/snipping_tool.avif
DELETED
|
Binary file
|
package/tmp_image.avif
DELETED
|
Binary file
|