zephyrcode 1.0.0__tar.gz → 1.0.1__tar.gz

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.
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zephyrcode
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: Official ZephyrCode AI coding agent SDK — generate code, use TTS, and build with AI.
5
- Author-email: ZephyrCode Labs <support@zephyrcode.ai>
5
+ Author-email: ZephyrCode Labs <hackerkk826@gmail.com>
6
6
  License: MIT
7
7
  Project-URL: Homepage, https://zephyrcode.space-z.ai
8
8
  Project-URL: Documentation, https://zephyrcode.space-z.ai/apikey
@@ -4,12 +4,12 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "zephyrcode"
7
- version = "1.0.0"
7
+ version = "1.0.1"
8
8
  description = "Official ZephyrCode AI coding agent SDK — generate code, use TTS, and build with AI."
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
11
11
  authors = [
12
- {name = "ZephyrCode Labs", email = "support@zephyrcode.ai"}
12
+ {name = "ZephyrCode Labs", email = "hackerkk826@gmail.com"}
13
13
  ]
14
14
  keywords = [
15
15
  "AI", "coding agent", "code generator", "AI code", "TTS",
@@ -26,9 +26,9 @@ import json
26
26
  import requests
27
27
  from typing import List, Dict, Optional, Any
28
28
 
29
- __version__ = "1.0.0"
29
+ __version__ = "1.0.1"
30
30
  __author__ = "ZephyrCode Labs"
31
- __email__ = "support@zephyrcode.ai"
31
+ __email__ = "hackerkk826@gmail.com"
32
32
 
33
33
  BASE_URL = "https://zephyrcode.space-z.ai"
34
34
 
@@ -52,7 +52,112 @@ class ZephyrCode:
52
52
  self.base_url = base_url.rstrip("/")
53
53
  self.chat = Chat(self)
54
54
 
55
- def _request(self, method: str, path: str, data: Optional[Dict] = None) -> Dict:
55
+ def _request_sse(self, method: str, path: str, data: Optional[Dict] = None) -> Dict:
56
+ """
57
+ Send a request that returns Server-Sent Events (SSE) and parse the
58
+ stream into a combined response dict.
59
+
60
+ The /api/agent endpoint returns events like:
61
+ event: content
62
+ data: {"delta": "Hello", "final": false}
63
+
64
+ event: done
65
+ data: {"model": "z-code-ultra", ...}
66
+
67
+ This method reads the full stream, concatenates all content deltas,
68
+ and returns a dict with the final assembled response.
69
+ """
70
+ url = f"{self.base_url}{path}"
71
+ headers = {
72
+ "Content-Type": "application/json",
73
+ "Authorization": f"Bearer {self.api_key}",
74
+ "Accept": "text/event-stream",
75
+ }
76
+ resp = requests.request(method, url, headers=headers, json=data, timeout=300, stream=True)
77
+
78
+ if resp.status_code == 401:
79
+ raise ZephyrCodeError("Invalid API key. Get one at https://zephyrcode.space-z.ai/apikey")
80
+ if resp.status_code == 429:
81
+ raise ZephyrCodeError("Rate limit exceeded. Upgrade your plan for higher limits.")
82
+ if resp.status_code >= 500:
83
+ raise ZephyrCodeError(f"Server error: {resp.status_code}")
84
+
85
+ # Parse the SSE stream
86
+ content_parts: List[str] = []
87
+ reasoning: List[Dict] = []
88
+ tool_calls: List[Dict] = []
89
+ plan: Optional[Dict] = None
90
+ model = ""
91
+ mode = ""
92
+ fallback_used = False
93
+ error_msg = None
94
+
95
+ current_event = ""
96
+ buffer = ""
97
+
98
+ for line in resp.iter_lines(decode_unicode=True):
99
+ if line is None:
100
+ continue
101
+
102
+ if line.startswith("event:"):
103
+ current_event = line[6:].strip()
104
+ elif line.startswith("data:"):
105
+ data_str = line[5:].strip()
106
+ if not data_str:
107
+ continue
108
+
109
+ try:
110
+ parsed = json.loads(data_str)
111
+ except json.JSONDecodeError:
112
+ continue
113
+
114
+ if current_event == "content":
115
+ delta = parsed.get("delta", "")
116
+ if delta:
117
+ content_parts.append(delta)
118
+ if parsed.get("final"):
119
+ pass # stream ended
120
+
121
+ elif current_event == "reasoning":
122
+ reasoning.append(parsed)
123
+
124
+ elif current_event == "tool_call":
125
+ tool_calls.append(parsed)
126
+
127
+ elif current_event == "tool_result":
128
+ if tool_calls:
129
+ tool_calls[-1]["result"] = parsed
130
+
131
+ elif current_event == "plan":
132
+ plan = parsed
133
+
134
+ elif current_event == "meta":
135
+ model = parsed.get("model", "")
136
+ mode = parsed.get("mode", "")
137
+
138
+ elif current_event == "error":
139
+ error_msg = parsed.get("message", "Unknown error")
140
+
141
+ elif current_event == "done":
142
+ model = parsed.get("model", model)
143
+ mode = parsed.get("mode", mode)
144
+ fallback_used = parsed.get("fallback_used", False)
145
+
146
+ if error_msg:
147
+ raise ZephyrCodeError(f"API error: {error_msg}")
148
+
149
+ return {
150
+ "content": "".join(content_parts),
151
+ "reasoning": reasoning,
152
+ "tool_calls": tool_calls,
153
+ "plan": plan,
154
+ "model": model,
155
+ "mode": mode,
156
+ "fallback_used": fallback_used,
157
+ }
158
+
159
+ def _request_json(self, method: str, path: str, data: Optional[Dict] = None) -> Dict:
160
+ """Send a request that returns regular JSON."""
56
161
  url = f"{self.base_url}{path}"
57
162
  headers = {
58
163
  "Content-Type": "application/json",
@@ -61,13 +166,16 @@ class ZephyrCode:
61
166
  resp = requests.request(method, url, headers=headers, json=data, timeout=120)
62
167
 
63
168
  if resp.status_code == 401:
64
- raise ZephyrCodeError("Invalid API key. Check your key at https://zephyrcode.space-z.ai/apikey")
169
+ raise ZephyrCodeError("Invalid API key. Get one at https://zephyrcode.space-z.ai/apikey")
65
170
  if resp.status_code == 429:
66
171
  raise ZephyrCodeError("Rate limit exceeded. Upgrade your plan for higher limits.")
67
172
  if resp.status_code >= 500:
68
173
  raise ZephyrCodeError(f"Server error: {resp.status_code}")
69
174
 
70
- return resp.json()
175
+ try:
176
+ return resp.json()
177
+ except Exception:
178
+ raise ZephyrCodeError(f"Failed to parse response (status {resp.status_code}): {resp.text[:200]}")
71
179
 
72
180
  def tts(self, text: str, voice: str = "adam", speed: float = 1.0) -> bytes:
73
181
  """
@@ -122,7 +230,7 @@ class Chat:
122
230
  Returns:
123
231
  ChatResponse object with .content, .reasoning, .tool_calls, .plan.
124
232
  """
125
- data = self.client._request("POST", "/api/agent", {
233
+ data = self.client._request_sse("POST", "/api/agent", {
126
234
  "messages": messages,
127
235
  "model": model,
128
236
  "mode": mode,
@@ -1,6 +1,6 @@
1
1
  """ZephyrCode Python SDK — Official AI coding agent SDK."""
2
2
 
3
- __version__ = "1.0.0"
3
+ __version__ = "1.0.1"
4
4
  __author__ = "ZephyrCode Labs"
5
- __email__ = "support@zephyrcode.ai"
5
+ __email__ = "hackerkk826@gmail.com"
6
6
  __all__ = ["ZephyrCode", "ZephyrCodeError", "ChatResponse", "generate"]
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zephyrcode
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: Official ZephyrCode AI coding agent SDK — generate code, use TTS, and build with AI.
5
- Author-email: ZephyrCode Labs <support@zephyrcode.ai>
5
+ Author-email: ZephyrCode Labs <hackerkk826@gmail.com>
6
6
  License: MIT
7
7
  Project-URL: Homepage, https://zephyrcode.space-z.ai
8
8
  Project-URL: Documentation, https://zephyrcode.space-z.ai/apikey
File without changes
File without changes
File without changes
File without changes