acp-sdk 0.8.2__py3-none-any.whl → 0.8.4__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.
acp_sdk/models/models.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import asyncio
|
1
2
|
import uuid
|
2
3
|
from datetime import datetime, timezone
|
3
4
|
from enum import Enum
|
@@ -5,7 +6,7 @@ from typing import Any, Literal, Optional, Union
|
|
5
6
|
|
6
7
|
from pydantic import AnyUrl, BaseModel, ConfigDict, Field
|
7
8
|
|
8
|
-
from acp_sdk.models.errors import Error
|
9
|
+
from acp_sdk.models.errors import ACPError, Error
|
9
10
|
|
10
11
|
|
11
12
|
class AnyModel(BaseModel):
|
@@ -95,7 +96,7 @@ class Artifact(MessagePart):
|
|
95
96
|
|
96
97
|
class Message(BaseModel):
|
97
98
|
parts: list[MessagePart]
|
98
|
-
created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
99
|
+
created_at: datetime | None = Field(default_factory=lambda: datetime.now(timezone.utc))
|
99
100
|
completed_at: datetime | None = Field(default_factory=lambda: datetime.now(timezone.utc))
|
100
101
|
|
101
102
|
def __add__(self, other: "Message") -> "Message":
|
@@ -103,8 +104,10 @@ class Message(BaseModel):
|
|
103
104
|
raise TypeError(f"Cannot concatenate Message with {type(other).__name__}")
|
104
105
|
return Message(
|
105
106
|
parts=self.parts + other.parts,
|
106
|
-
created_at=min(self.created_at, other.created_at),
|
107
|
-
completed_at=max(self.completed_at, other.completed_at)
|
107
|
+
created_at=min(self.created_at, other.created_at) if self.created_at and other.created_at else None,
|
108
|
+
completed_at=max(self.completed_at, other.completed_at)
|
109
|
+
if self.completed_at and other.completed_at
|
110
|
+
else None,
|
108
111
|
)
|
109
112
|
|
110
113
|
def __str__(self) -> str:
|
@@ -194,6 +197,15 @@ class Run(BaseModel):
|
|
194
197
|
created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
195
198
|
finished_at: datetime | None = None
|
196
199
|
|
200
|
+
def raise_for_status(self) -> "Run":
|
201
|
+
match self.status:
|
202
|
+
case RunStatus.CANCELLED:
|
203
|
+
raise asyncio.CancelledError()
|
204
|
+
case RunStatus.FAILED:
|
205
|
+
raise ACPError(error=self.error)
|
206
|
+
case _:
|
207
|
+
return self
|
208
|
+
|
197
209
|
|
198
210
|
class MessageCreatedEvent(BaseModel):
|
199
211
|
type: Literal["message.created"] = "message.created"
|
acp_sdk/server/agent.py
CHANGED
@@ -58,13 +58,13 @@ class Agent(abc.ABC):
|
|
58
58
|
run = asyncio.get_running_loop().run_in_executor(executor, self._run_func, input, context)
|
59
59
|
|
60
60
|
try:
|
61
|
-
while
|
61
|
+
while not run.done() or yield_queue.async_q.qsize() > 0:
|
62
62
|
value = yield await yield_queue.async_q.get()
|
63
|
+
if isinstance(value, Exception):
|
64
|
+
raise value
|
63
65
|
await yield_resume_queue.async_q.put(value)
|
64
66
|
except janus.AsyncQueueShutDown:
|
65
67
|
pass
|
66
|
-
finally:
|
67
|
-
await run # Raise exceptions
|
68
68
|
|
69
69
|
async def _run_async_gen(self, input: list[Message], context: Context) -> None:
|
70
70
|
try:
|
@@ -74,12 +74,16 @@ class Agent(abc.ABC):
|
|
74
74
|
value = await context.yield_async(await gen.asend(value))
|
75
75
|
except StopAsyncIteration:
|
76
76
|
pass
|
77
|
+
except Exception as e:
|
78
|
+
await context.yield_async(e)
|
77
79
|
finally:
|
78
80
|
context.shutdown()
|
79
81
|
|
80
82
|
async def _run_coro(self, input: list[Message], context: Context) -> None:
|
81
83
|
try:
|
82
84
|
await context.yield_async(await self.run(input, context))
|
85
|
+
except Exception as e:
|
86
|
+
await context.yield_async(e)
|
83
87
|
finally:
|
84
88
|
context.shutdown()
|
85
89
|
|
@@ -91,12 +95,16 @@ class Agent(abc.ABC):
|
|
91
95
|
value = context.yield_sync(gen.send(value))
|
92
96
|
except StopIteration:
|
93
97
|
pass
|
98
|
+
except Exception as e:
|
99
|
+
context.yield_sync(e)
|
94
100
|
finally:
|
95
101
|
context.shutdown()
|
96
102
|
|
97
103
|
def _run_func(self, input: list[Message], context: Context) -> None:
|
98
104
|
try:
|
99
105
|
context.yield_sync(self.run(input, context))
|
106
|
+
except Exception as e:
|
107
|
+
context.yield_sync(e)
|
100
108
|
finally:
|
101
109
|
context.shutdown()
|
102
110
|
|
acp_sdk/server/types.py
CHANGED
@@ -5,5 +5,5 @@ from pydantic import BaseModel
|
|
5
5
|
from acp_sdk.models import AwaitRequest, AwaitResume, Message
|
6
6
|
from acp_sdk.models.models import MessagePart
|
7
7
|
|
8
|
-
RunYield = Message | MessagePart | str | AwaitRequest | BaseModel | dict[str | Any] | None
|
8
|
+
RunYield = Message | MessagePart | str | AwaitRequest | BaseModel | dict[str | Any] | None | Exception
|
9
9
|
RunYieldResume = AwaitResume | None
|
@@ -8,10 +8,10 @@ acp_sdk/client/types.py,sha256=_H6zYt-2OHOOYRtssRnbDIiwmgsl2-KIXc9lb-mJLFA,133
|
|
8
8
|
acp_sdk/client/utils.py,sha256=2jhJyrPJmVFRoDJh0q_JMqOMlC3IxCh-6HXed-PIZS8,924
|
9
9
|
acp_sdk/models/__init__.py,sha256=numSDBDT1QHx7n_Y3Deb5VOvKWcUBxbOEaMwQBSRHxc,151
|
10
10
|
acp_sdk/models/errors.py,sha256=rEyaMVvQuBi7fwWe_d0PGGySYsD3FZTluQ-SkC0yhAs,444
|
11
|
-
acp_sdk/models/models.py,sha256=
|
11
|
+
acp_sdk/models/models.py,sha256=PSv3Vq07ahCi6JpvEMzEdEjHdUU7NT9KTf21CF9B3-g,7629
|
12
12
|
acp_sdk/models/schemas.py,sha256=_ah7_zHsQJGxDXvnzsBvASdRsQHVphFQ7Sum6A04iRw,759
|
13
13
|
acp_sdk/server/__init__.py,sha256=mxBBBFaZuMEUENRMLwp1XZkuLeT9QghcFmNvjnqvAAU,377
|
14
|
-
acp_sdk/server/agent.py,sha256=
|
14
|
+
acp_sdk/server/agent.py,sha256=6VBKn_qVXqUl79G8T7grwhnuLMwr67d4UGagMGX1hMs,6586
|
15
15
|
acp_sdk/server/app.py,sha256=1S1mxECioL5NeGjGo5C8u94x7Ybvj79L_Aauu2352vA,7117
|
16
16
|
acp_sdk/server/bundle.py,sha256=5Rq6E4WgmuwPQ4u-sViaHeu5loCLEUgojWav9LAghX4,7036
|
17
17
|
acp_sdk/server/context.py,sha256=MgnLV6qcDIhc_0BjW7r4Jj1tHts4ZuwpdTGIBnz2Mgo,1036
|
@@ -20,8 +20,8 @@ acp_sdk/server/logging.py,sha256=Oc8yZigCsuDnHHPsarRzu0RX3NKaLEgpELM2yovGKDI,411
|
|
20
20
|
acp_sdk/server/server.py,sha256=JLQ2tyZpQaWvhZYw6-OWbKlSRNWezXLXhD5OFbKPysw,8014
|
21
21
|
acp_sdk/server/session.py,sha256=ekz1o6Sy1tQZlpaoS_VgbvFuUQh2qpiHG71mvBdvhgc,662
|
22
22
|
acp_sdk/server/telemetry.py,sha256=1BUxNg-xL_Vqgs27PDWNc3HikrQW2lidAtT_FKlp_Qk,1833
|
23
|
-
acp_sdk/server/types.py,sha256=
|
23
|
+
acp_sdk/server/types.py,sha256=gLb5wCkMYhmu2laj_ymK-TPfN9LSjRgKOP1H_893UzA,304
|
24
24
|
acp_sdk/server/utils.py,sha256=BhZKBNaLgczX6aYjxYva-6VI1bKmHtYQ5YDA5LrwF50,1831
|
25
|
-
acp_sdk-0.8.
|
26
|
-
acp_sdk-0.8.
|
27
|
-
acp_sdk-0.8.
|
25
|
+
acp_sdk-0.8.4.dist-info/METADATA,sha256=AZFhr-FKotfSVMuKUCdixS18rg6d-fjePoy2hWw3SnY,1651
|
26
|
+
acp_sdk-0.8.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
27
|
+
acp_sdk-0.8.4.dist-info/RECORD,,
|
File without changes
|