nova-ai-pro 1.2.15.dev178__py3-none-any.whl → 1.2.15.dev182__py3-none-any.whl

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.
@@ -81,6 +81,32 @@ def _gcal_api_event_patch(
81
81
  return resp.json()
82
82
 
83
83
 
84
+ def _gcal_api_event_insert(
85
+ token: str,
86
+ calendar_id: str,
87
+ body: Dict[str, Any],
88
+ ) -> Dict[str, Any]:
89
+ """Create a calendar event via the ``events.insert`` endpoint."""
90
+ resp = httpx.post(
91
+ f"{_GCAL_API_BASE}/calendars/{calendar_id}/events",
92
+ headers={"Authorization": f"Bearer {token}"},
93
+ json=body,
94
+ timeout=30.0,
95
+ )
96
+ resp.raise_for_status()
97
+ return resp.json()
98
+
99
+
100
+ def _gcal_api_event_delete(token: str, calendar_id: str, event_id: str) -> None:
101
+ """Delete a calendar event via the ``events.delete`` endpoint."""
102
+ resp = httpx.delete(
103
+ f"{_GCAL_API_BASE}/calendars/{calendar_id}/events/{event_id}",
104
+ headers={"Authorization": f"Bearer {token}"},
105
+ timeout=30.0,
106
+ )
107
+ resp.raise_for_status()
108
+
109
+
84
110
  def _gcal_api_calendars_list(token: str) -> Dict[str, Any]:
85
111
  """Call the Calendar ``calendarList.list`` endpoint.
86
112
 
@@ -470,6 +496,39 @@ class GCalendarConnector(BaseConnector):
470
496
  updated.append({"email": user_email, "responseStatus": "declined"})
471
497
  _gcal_api_event_patch(token, calendar_id, event_id, {"attendees": updated})
472
498
 
499
+ def get_event(
500
+ self, event_id: str, calendar_id: str = "primary"
501
+ ) -> Dict[str, Any]:
502
+ """Fetch a single event resource."""
503
+ return _gcal_api_event_get(self._get_token(), calendar_id, event_id)
504
+
505
+ def create_event(
506
+ self,
507
+ summary: str,
508
+ start: Dict[str, str],
509
+ end: Dict[str, str],
510
+ calendar_id: str = "primary",
511
+ **fields: Any,
512
+ ) -> Dict[str, Any]:
513
+ """Create an event. *start*/*end* are ``{"dateTime": ...}`` mappings."""
514
+ body: Dict[str, Any] = {"summary": summary, "start": start, "end": end}
515
+ body.update({k: v for k, v in fields.items() if v is not None})
516
+ return _gcal_api_event_insert(self._get_token(), calendar_id, body)
517
+
518
+ def update_event(
519
+ self,
520
+ event_id: str,
521
+ calendar_id: str = "primary",
522
+ **fields: Any,
523
+ ) -> Dict[str, Any]:
524
+ """Patch an event with the given fields."""
525
+ body = {k: v for k, v in fields.items() if v is not None}
526
+ return _gcal_api_event_patch(self._get_token(), calendar_id, event_id, body)
527
+
528
+ def delete_event(self, event_id: str, calendar_id: str = "primary") -> None:
529
+ """Delete an event."""
530
+ _gcal_api_event_delete(self._get_token(), calendar_id, event_id)
531
+
473
532
  def sync_status(self) -> SyncStatus:
474
533
  """Return sync progress from the most recent :meth:`sync` call."""
475
534
  return SyncStatus(
@@ -284,6 +284,9 @@ class IntelligenceConfig:
284
284
  top_k: int = 40
285
285
  repetition_penalty: float = 1.0
286
286
  stop_sequences: str = "" # Comma-separated stop strings
287
+ # Ollama only: send think=true to thinking-capable models (Qwen3 etc.).
288
+ # Default off so offline responses never burn tokens on a think trace.
289
+ ollama_thinking: bool = False
287
290
 
288
291
 
289
292
  @dataclass(slots=True)
@@ -47,10 +47,16 @@ def _make_engine(key: str, config: NovaConfig) -> InferenceEngine:
47
47
  )
48
48
 
49
49
  host_attr = _HOST_MAP.get(key)
50
- if host_attr is not None:
51
- host = getattr(config.engine, host_attr, None)
52
- if host:
53
- return cls(host=host)
50
+ host = getattr(config.engine, host_attr, None) if host_attr is not None else None
51
+ # Ollama always gets the thinking config; an empty host is fine (the
52
+ # engine itself falls back to OLLAMA_HOST and its own default).
53
+ if key == "ollama":
54
+ return cls(
55
+ host=host or None,
56
+ thinking=getattr(config.intelligence, "ollama_thinking", False),
57
+ )
58
+ if host:
59
+ return cls(host=host)
54
60
  return cls()
55
61
 
56
62
 
nova_ai/engine/ollama.py CHANGED
@@ -67,12 +67,14 @@ class OllamaEngine(InferenceEngine):
67
67
  host: str | None = None,
68
68
  *,
69
69
  timeout: float = 1800.0,
70
+ thinking: bool = False,
70
71
  ) -> None:
71
72
  if host is None:
72
73
  env_host = os.environ.get("OLLAMA_HOST")
73
74
  host = env_host or self._DEFAULT_HOST
74
75
  self._host = host.rstrip("/")
75
76
  self._timeout = timeout
77
+ self._thinking = thinking
76
78
  self._client = httpx.Client(base_url=self._host, timeout=timeout)
77
79
  # Async counterpart for stream()/stream_full()/​_run_stream(): the sync
78
80
  # client's request methods block, so calling them from these async
@@ -115,9 +117,11 @@ class OllamaEngine(InferenceEngine):
115
117
  }
116
118
  # Disable extended thinking by default (Qwen3.5 etc.).
117
119
  # When enabled, thinking tokens consume the entire budget and
118
- # the visible content comes back empty.
120
+ # the visible content comes back empty. The configured default
121
+ # ([intelligence] ollama_thinking) can opt in; an explicit caller
122
+ # kwarg always wins.
119
123
  if "think" not in kwargs:
120
- payload["think"] = False
124
+ payload["think"] = self._thinking
121
125
  elif kwargs["think"] is not None:
122
126
  payload["think"] = kwargs["think"]
123
127
  # Pass tools if provided
@@ -250,7 +254,7 @@ class OllamaEngine(InferenceEngine):
250
254
  # stream for 60+ seconds before any tokens reach the client, which
251
255
  # frontends interpret as a "Load failed" timeout.
252
256
  if "think" not in kwargs:
253
- payload["think"] = False
257
+ payload["think"] = self._thinking
254
258
  elif kwargs["think"] is not None:
255
259
  payload["think"] = kwargs["think"]
256
260
  # Ollama OOMs allocating the KV cache when num_ctx is too large for
nova_ai/tools/__init__.py CHANGED
@@ -161,14 +161,19 @@ except ImportError:
161
161
  try:
162
162
  import nova_ai.tools.api_tester # noqa: F401
163
163
  import nova_ai.tools.browser # noqa: F401
164
+ import nova_ai.tools.calendar_tool # noqa: F401
164
165
  import nova_ai.tools.code_scaffolder # noqa: F401
165
166
  import nova_ai.tools.data_analyzer # noqa: F401
167
+ import nova_ai.tools.excel_tool # noqa: F401
166
168
  import nova_ai.tools.file_converter # noqa: F401
167
169
  import nova_ai.tools.git_manager # noqa: F401
168
170
  import nova_ai.tools.knowledge_search # noqa: F401
169
171
  import nova_ai.tools.notebook_generator # noqa: F401
172
+ import nova_ai.tools.process_manager # noqa: F401
170
173
  import nova_ai.tools.scheduler_tool # noqa: F401
174
+ import nova_ai.tools.screenshot_diff # noqa: F401
171
175
  import nova_ai.tools.system_monitor # noqa: F401
176
+ import nova_ai.tools.test_runner # noqa: F401
172
177
  except ImportError:
173
178
  pass
174
179
 
@@ -0,0 +1,292 @@
1
+ """Calendar write tool — create, update, delete, and read Google Calendar events.
2
+
3
+ Read paths (sync, search) already exist on the connector and as MCP tools;
4
+ this tool closes the write gap so agents can schedule on the user's behalf.
5
+
6
+ Network-facing (``is_local = False``) and confirmation-gated: every action
7
+ mutates or reads the user's live calendar.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import logging
13
+ from typing import Any, Dict, List, Optional
14
+
15
+ from nova_ai.connectors.gcalendar import GCalendarConnector, _format_event
16
+ from nova_ai.core.registry import ToolRegistry
17
+ from nova_ai.core.types import ToolResult
18
+ from nova_ai.engine.self_optimizer import track_execution
19
+ from nova_ai.tools._stubs import BaseTool, ToolSpec
20
+
21
+ logger = logging.getLogger(__name__)
22
+
23
+
24
+ def _event_datetime(value: str) -> Dict[str, str]:
25
+ """Build an API ``start``/``end`` mapping from a date or datetime string."""
26
+ value = value.strip()
27
+ if len(value) == 10: # YYYY-MM-DD → all-day event
28
+ return {"date": value}
29
+ return {"dateTime": value}
30
+
31
+
32
+ def _split_attendees(raw: Any) -> Optional[List[Dict[str, str]]]:
33
+ """Normalise a comma-separated attendee string into API attendee objects."""
34
+ if raw is None:
35
+ return None
36
+ if isinstance(raw, list):
37
+ emails = [str(e).strip() for e in raw if str(e).strip()]
38
+ else:
39
+ emails = [e.strip() for e in str(raw).split(",") if e.strip()]
40
+ if not emails:
41
+ return None
42
+ return [{"email": email} for email in emails]
43
+
44
+
45
+ @ToolRegistry.register("calendar_tool")
46
+ class CalendarTool(BaseTool):
47
+ """Create, update, delete, and fetch Google Calendar events."""
48
+
49
+ tool_id = "calendar_tool"
50
+ is_local = False
51
+
52
+ @property
53
+ def spec(self) -> ToolSpec:
54
+ return ToolSpec(
55
+ name="calendar_tool",
56
+ description=(
57
+ "Manage Google Calendar events. Actions: 'create' a new event "
58
+ "(needs summary, start, end), 'update' an existing event "
59
+ "(needs event_id plus the fields to change), 'delete' an event "
60
+ "(needs event_id), 'get' one event's details. Times accept "
61
+ "RFC 3339 datetimes (e.g. '2026-10-09T10:00:00Z') or plain "
62
+ "dates ('2026-10-09') for all-day events."
63
+ ),
64
+ parameters={
65
+ "type": "object",
66
+ "properties": {
67
+ "action": {
68
+ "type": "string",
69
+ "enum": ["create", "update", "delete", "get"],
70
+ "description": "Calendar operation to perform.",
71
+ },
72
+ "calendar_id": {
73
+ "type": "string",
74
+ "description": "Calendar ID. Defaults to 'primary'.",
75
+ "default": "primary",
76
+ },
77
+ "event_id": {
78
+ "type": "string",
79
+ "description": "Event ID (required for update, delete, get).",
80
+ },
81
+ "summary": {
82
+ "type": "string",
83
+ "description": "Event title (required for create).",
84
+ },
85
+ "start": {
86
+ "type": "string",
87
+ "description": "Start time, RFC 3339 or YYYY-MM-DD.",
88
+ },
89
+ "end": {
90
+ "type": "string",
91
+ "description": "End time, RFC 3339 or YYYY-MM-DD.",
92
+ },
93
+ "description": {
94
+ "type": "string",
95
+ "description": "Event description.",
96
+ },
97
+ "location": {
98
+ "type": "string",
99
+ "description": "Event location.",
100
+ },
101
+ "attendees": {
102
+ "type": ["string", "array"],
103
+ "description": (
104
+ "Attendee emails, comma-separated or as a list. "
105
+ "Attendees receive invites on create."
106
+ ),
107
+ },
108
+ "credentials_path": {
109
+ "type": "string",
110
+ "description": (
111
+ "Optional Google credentials file path. "
112
+ "Defaults to the connector's configured location."
113
+ ),
114
+ },
115
+ },
116
+ "required": ["action"],
117
+ },
118
+ category="productivity",
119
+ requires_confirmation=True,
120
+ timeout_seconds=30.0,
121
+ )
122
+
123
+ @track_execution("calendar_tool")
124
+ def execute(
125
+ self,
126
+ action: str,
127
+ calendar_id: str = "primary",
128
+ event_id: str = "",
129
+ summary: str = "",
130
+ start: str = "",
131
+ end: str = "",
132
+ description: str = "",
133
+ location: str = "",
134
+ attendees: Any = None,
135
+ credentials_path: str = "",
136
+ **kwargs: Any,
137
+ ) -> ToolResult:
138
+ action = (action or "").lower().strip()
139
+ if action not in ("create", "update", "delete", "get"):
140
+ return ToolResult(
141
+ tool_name="calendar_tool",
142
+ content=f"Error: unknown action '{action}'. Use create, update, delete, or get.",
143
+ success=False,
144
+ )
145
+
146
+ try:
147
+ connector = (
148
+ GCalendarConnector(credentials_path=credentials_path)
149
+ if credentials_path
150
+ else GCalendarConnector()
151
+ )
152
+ token_check = connector._get_token()
153
+ if not token_check:
154
+ raise RuntimeError("Google Calendar token missing")
155
+ except RuntimeError as exc:
156
+ return ToolResult(
157
+ tool_name="calendar_tool",
158
+ content=f"Error: Google Calendar not authenticated ({exc}). "
159
+ "Connect the calendar first.",
160
+ success=False,
161
+ )
162
+
163
+ try:
164
+ if action == "create":
165
+ return self._create(
166
+ connector, calendar_id, summary, start, end,
167
+ description, location, attendees,
168
+ )
169
+ if action in ("update", "delete", "get"):
170
+ if not event_id.strip():
171
+ return ToolResult(
172
+ tool_name="calendar_tool",
173
+ content=f"Error: event_id is required for '{action}'.",
174
+ success=False,
175
+ )
176
+ if action == "delete":
177
+ connector.delete_event(event_id.strip(), calendar_id)
178
+ return ToolResult(
179
+ tool_name="calendar_tool",
180
+ content=f"Deleted event '{event_id.strip()}'.",
181
+ success=True,
182
+ metadata={"action": action, "event_id": event_id.strip()},
183
+ )
184
+ if action == "get":
185
+ event = connector.get_event(event_id.strip(), calendar_id)
186
+ return ToolResult(
187
+ tool_name="calendar_tool",
188
+ content=_format_event(event),
189
+ success=True,
190
+ metadata={
191
+ "action": action,
192
+ "event_id": event.get("id", event_id.strip()),
193
+ },
194
+ )
195
+ return self._update(
196
+ connector, calendar_id, event_id.strip(), summary,
197
+ start, end, description, location, attendees,
198
+ )
199
+ except Exception as exc: # noqa: BLE001 — surfaced to the agent verbatim
200
+ return ToolResult(
201
+ tool_name="calendar_tool",
202
+ content=f"Calendar {action} failed: {exc}",
203
+ success=False,
204
+ )
205
+ # Unreachable: all actions return above.
206
+ return ToolResult(
207
+ tool_name="calendar_tool",
208
+ content=f"Error: unhandled action '{action}'.",
209
+ success=False,
210
+ )
211
+
212
+ def _create(
213
+ self,
214
+ connector: GCalendarConnector,
215
+ calendar_id: str,
216
+ summary: str,
217
+ start: str,
218
+ end: str,
219
+ description: str,
220
+ location: str,
221
+ attendees: Any,
222
+ ) -> ToolResult:
223
+ if not summary.strip():
224
+ return ToolResult(
225
+ tool_name="calendar_tool",
226
+ content="Error: summary is required for 'create'.",
227
+ success=False,
228
+ )
229
+ if not start.strip() or not end.strip():
230
+ return ToolResult(
231
+ tool_name="calendar_tool",
232
+ content="Error: start and end are required for 'create'.",
233
+ success=False,
234
+ )
235
+ event = connector.create_event(
236
+ summary.strip(),
237
+ _event_datetime(start),
238
+ _event_datetime(end),
239
+ calendar_id,
240
+ description=description.strip() or None,
241
+ location=location.strip() or None,
242
+ attendees=_split_attendees(attendees),
243
+ )
244
+ return ToolResult(
245
+ tool_name="calendar_tool",
246
+ content=f"Created event:\n{_format_event(event)}",
247
+ success=True,
248
+ metadata={"action": "create", "event_id": event.get("id", "")},
249
+ )
250
+
251
+ def _update(
252
+ self,
253
+ connector: GCalendarConnector,
254
+ calendar_id: str,
255
+ event_id: str,
256
+ summary: str,
257
+ start: str,
258
+ end: str,
259
+ description: str,
260
+ location: str,
261
+ attendees: Any,
262
+ ) -> ToolResult:
263
+ fields: Dict[str, Any] = {}
264
+ if summary.strip():
265
+ fields["summary"] = summary.strip()
266
+ if start.strip():
267
+ fields["start"] = _event_datetime(start)
268
+ if end.strip():
269
+ fields["end"] = _event_datetime(end)
270
+ if description.strip():
271
+ fields["description"] = description.strip()
272
+ if location.strip():
273
+ fields["location"] = location.strip()
274
+ parsed_attendees = _split_attendees(attendees)
275
+ if parsed_attendees is not None:
276
+ fields["attendees"] = parsed_attendees
277
+ if not fields:
278
+ return ToolResult(
279
+ tool_name="calendar_tool",
280
+ content="Error: nothing to update. Provide at least one field to change.",
281
+ success=False,
282
+ )
283
+ event = connector.update_event(event_id, calendar_id, **fields)
284
+ return ToolResult(
285
+ tool_name="calendar_tool",
286
+ content=f"Updated event:\n{_format_event(event)}",
287
+ success=True,
288
+ metadata={"action": "update", "event_id": event.get("id", event_id)},
289
+ )
290
+
291
+
292
+ __all__ = ["CalendarTool"]