agentos-sdk-python 1.1.1__tar.gz → 2.0.0__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.
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/CHANGELOG.md +21 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/PKG-INFO +22 -24
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/README-zh_CN.md +17 -21
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/README.md +21 -23
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/RELEASE.md +7 -7
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/clients/discoverykit.py +1 -19
- agentos_sdk_python-2.0.0/agentos_sdk/clients/transferkit.py +64 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/normalizers.py +8 -12
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/protocol.py +2 -2
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/sdk.py +0 -69
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/pyproject.toml +1 -1
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/tests/test_modelkit.py +63 -18
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/tests/test_normalizers.py +55 -23
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/tests/test_sdk_facade.py +53 -0
- agentos_sdk_python-1.1.1/agentos_sdk/clients/transferkit.py +0 -149
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/.gitignore +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/LICENSE +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/__init__.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/clients/__init__.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/clients/agentkit.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/clients/appkit.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/clients/authkit.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/clients/cronkit.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/clients/harnesskit.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/clients/modelkit.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/clients/notifykit.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/clients/systemkit.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/clients/toolkit.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/handlers.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/py.typed +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/agentos_sdk/transport.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/tests/test_agentkit.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/tests/test_cronkit.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/tests/test_harnesskit.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/tests/test_notifykit.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/tests/test_protocol.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/tests/test_toolkit.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/tests/test_transport.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/tests/typecheck/harnesskit_usage.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/tests/typecheck/modelkit_usage.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/tests/typecheck/notifykit_usage.py +0 -0
- {agentos_sdk_python-1.1.1 → agentos_sdk_python-2.0.0}/tests/typecheck/toolkit_usage.py +0 -0
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
- **Breaking:** Nearby discovery is device-level. Removed `register` and
|
|
6
|
+
`unregister` from `DiscoveryKitClient` and the authenticated
|
|
7
|
+
`sdk.discoverykit` facade. Apps can query nearby devices and the current
|
|
8
|
+
device, and watch discovery events without registering.
|
|
9
|
+
- **Breaking:** Incoming nearby transfers are handled by the receiving device's
|
|
10
|
+
built-in UI. Removed `respond`, `receive_stream`, `set_policy`, `get_policy`,
|
|
11
|
+
`get_history`, `delete_history`, and `clear_history` from `TransferKitClient`
|
|
12
|
+
and the authenticated `sdk.transferkit` facade, including their camelCase
|
|
13
|
+
aliases. Apps can send files and track or cancel their own transfers.
|
|
14
|
+
- **Breaking:** Model info now takes the billing fields of the AgentOS server's
|
|
15
|
+
model list as they are: `billingType` (`ModelBillingType`: `"free"`,
|
|
16
|
+
`"in plan"`, `"pay as you go"` or `"benefit card"`), `cardName` (the benefit
|
|
17
|
+
card, only for `"benefit card"`; it is the only identifier of a card) and
|
|
18
|
+
`planNameZh` / `planNameEn` (the plan, only for `"free"` and `"in plan"`).
|
|
19
|
+
The old `billingType` values `"plan"` and `"payAsYouGo"` are no longer
|
|
20
|
+
understood, and `isBenefitCard`, `benefitCardId` and `benefitCardName` are
|
|
21
|
+
removed: use `billingType == "benefit card"` and `cardName`. A benefit card
|
|
22
|
+
model still keeps `source` `"platform"` and its plain `name` / `alias`.
|
|
23
|
+
|
|
3
24
|
## 1.1.1
|
|
4
25
|
|
|
5
26
|
- Added HarnessKit private App tool registration with `register_private_tools`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: agentos-sdk-python
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0
|
|
4
4
|
Summary: Async Python SDK for AgentOS APIs.
|
|
5
5
|
Project-URL: Repository, https://gitlab.litevar.com/litevar/agentos/agentos-sdk-python
|
|
6
6
|
Project-URL: Issues, https://gitlab.litevar.com/litevar/agentos/agentos-sdk-python/-/issues
|
|
@@ -262,7 +262,7 @@ Every model also carries `source`, the mutually exclusive origin of the model
|
|
|
262
262
|
| `source` | Meaning | Suggested group |
|
|
263
263
|
| --- | --- | --- |
|
|
264
264
|
| `"local"` | Runs on this device | Local Models |
|
|
265
|
-
| `"platform"` | Remote model provided by the AgentOS platform | Platform Models, plus `Remote · System · {
|
|
265
|
+
| `"platform"` | Remote model provided by the AgentOS platform | Platform Models, plus `Remote · System · {cardName}` for each benefit card (see below) |
|
|
266
266
|
| `"custom"` | Remote model configured by the user | Custom Models |
|
|
267
267
|
| `"app"` | Registered by a third-party app | `App · {appName}` (one group per app) |
|
|
268
268
|
|
|
@@ -282,24 +282,25 @@ one, so fall back to `appBundleId`). Against gateways that predate `source`, or
|
|
|
282
282
|
when it holds an unknown value, `source` is derived from the legacy flags with
|
|
283
283
|
the gateway's rules.
|
|
284
284
|
|
|
285
|
+
Platform models also carry the billing fields of the AgentOS server's model list,
|
|
286
|
+
with the same names and values: `billingType` (`"free"`, `"in plan"`,
|
|
287
|
+
`"pay as you go"` or `"benefit card"`), `cardName` (the benefit card, only for
|
|
288
|
+
`"benefit card"`) and `planNameZh` / `planNameEn` (the plan, only for `"free"` and
|
|
289
|
+
`"in plan"`). They are omitted when unknown and for local, custom and app models.
|
|
290
|
+
|
|
285
291
|
Models served through a benefit card keep `source` `"platform"` and their plain
|
|
286
|
-
`name` / `alias
|
|
287
|
-
`
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
each card as its own group:
|
|
292
|
+
`name` / `alias`. The same model can be listed once for the plan and once per
|
|
293
|
+
card, so tell them apart by `id`, `billingType` or `cardName`. `cardName` is the
|
|
294
|
+
only identifier of a card: show each card as its own group named after it, and
|
|
295
|
+
mark each billing type with a small badge:
|
|
291
296
|
|
|
292
297
|
```python
|
|
293
298
|
def system_group_title(model: dict) -> str:
|
|
294
|
-
if model.get("
|
|
295
|
-
return f"Remote · System · {model.get('
|
|
299
|
+
if model.get("billingType") == "benefit card":
|
|
300
|
+
return f"Remote · System · {model.get('cardName') or 'Benefit card'}"
|
|
296
301
|
return "Remote · System"
|
|
297
302
|
```
|
|
298
303
|
|
|
299
|
-
System models that are not benefit card models also report `billingType`
|
|
300
|
-
(`"free"`, `"plan"` or `"payAsYouGo"`; omitted when unknown and for every other
|
|
301
|
-
model), so a picker can mark each type with a small badge.
|
|
302
|
-
|
|
303
304
|
Model dicts also carry `contextWindowSize` and `maxOutputTokens` (the maximum
|
|
304
305
|
number of tokens the model can generate in one response); `maxOutputTokens` is
|
|
305
306
|
only present when the gateway reports it. Only chat models report
|
|
@@ -533,26 +534,29 @@ async with AgentOSSDK() as sdk:
|
|
|
533
534
|
|
|
534
535
|
## DiscoveryKit
|
|
535
536
|
|
|
537
|
+
Device-level discovery of nearby AgentOS devices. Apps can query nearby devices
|
|
538
|
+
and the current device's info; they are never advertised to other devices.
|
|
539
|
+
|
|
536
540
|
```python
|
|
537
541
|
async with AgentOSSDK() as sdk:
|
|
538
542
|
await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
|
|
539
543
|
|
|
540
|
-
await sdk.discoverykit.register({"receivePolicy": "autoAccept"})
|
|
541
|
-
|
|
542
544
|
peers = await sdk.discoverykit.get_peers()
|
|
543
545
|
print(peers)
|
|
544
546
|
|
|
545
547
|
self_info = await sdk.discoverykit.get_self()
|
|
546
|
-
print(self_info["deviceName"], self_info["
|
|
548
|
+
print(self_info["deviceName"], self_info["nearbyTransferEnabled"])
|
|
547
549
|
|
|
548
550
|
async for event in sdk.discoverykit.stream_peers():
|
|
549
551
|
print(event["type"], event["device"]["name"])
|
|
550
|
-
|
|
551
|
-
await sdk.discoverykit.unregister()
|
|
552
552
|
```
|
|
553
553
|
|
|
554
554
|
## TransferKit
|
|
555
555
|
|
|
556
|
+
Sends files to a nearby AgentOS device. The receiving device handles the
|
|
557
|
+
incoming files in its built-in nearby transfer UI. Apps can send files and track
|
|
558
|
+
or cancel their own transfers.
|
|
559
|
+
|
|
556
560
|
```python
|
|
557
561
|
async with AgentOSSDK() as sdk:
|
|
558
562
|
await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
|
|
@@ -573,12 +577,6 @@ async with AgentOSSDK() as sdk:
|
|
|
573
577
|
transfer_id=session["transferId"]
|
|
574
578
|
):
|
|
575
579
|
print(progress["progress"])
|
|
576
|
-
|
|
577
|
-
await sdk.transferkit.set_policy(request={"policy": "autoAccept"})
|
|
578
|
-
policy = await sdk.transferkit.get_policy()
|
|
579
|
-
|
|
580
|
-
history = await sdk.transferkit.get_history()
|
|
581
|
-
await sdk.transferkit.clear_history()
|
|
582
580
|
```
|
|
583
581
|
|
|
584
582
|
`list_tool()` is typed as `list[ToolDto]` and exposes daemon 0.5 metadata. Its
|
|
@@ -227,7 +227,7 @@ async with AgentOSSDK() as sdk:
|
|
|
227
227
|
| `source` | 含义 | 建议分组 |
|
|
228
228
|
| --- | --- | --- |
|
|
229
229
|
| `"local"` | 在本机运行 | 本地模型 |
|
|
230
|
-
| `"platform"` | AgentOS 平台提供的远端模型 | 平台模型,另为每张权益卡单独分组 `远端 · 系统 · {
|
|
230
|
+
| `"platform"` | AgentOS 平台提供的远端模型 | 平台模型,另为每张权益卡单独分组 `远端 · 系统 · {cardName}`(见下) |
|
|
231
231
|
| `"custom"` | 用户自行配置的远端模型 | 自定义模型 |
|
|
232
232
|
| `"app"` | 第三方 app 注册的模型 | `App · {appName}`(每个 app 一组) |
|
|
233
233
|
|
|
@@ -245,21 +245,22 @@ app 模型还会带有 `appBundleId` 与 `appName`(app 的可读名称,用
|
|
|
245
245
|
`appName` 仅在网关返回时才有值,缺失时请回退到 `appBundleId`)。对于尚未提供
|
|
246
246
|
`source` 的旧网关,或 `source` 为未知值时,会按网关的规则由旧布尔字段推导。
|
|
247
247
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
248
|
+
平台模型还带有 AgentOS 服务端模型列表里的计费字段,名称与取值都与服务端一致:`billingType`
|
|
249
|
+
(`"free"`、`"in plan"`、`"pay as you go"` 或 `"benefit card"`)、`cardName`(权益卡名称,仅
|
|
250
|
+
`"benefit card"` 带有)以及 `planNameZh` / `planNameEn`(套餐名称,仅 `"free"` 与 `"in plan"` 带有)。
|
|
251
|
+
未知时,以及本地、自定义和 App 模型,均不包含这些键。
|
|
252
|
+
|
|
253
|
+
由权益卡提供的模型仍保持 `source` 为 `"platform"` 与原样的 `name` / `alias`。同一个模型可能在套餐
|
|
254
|
+
和每张权益卡下各出现一次,请用 `id`、`billingType` 或 `cardName` 区分。`cardName` 是权益卡的唯一标识:
|
|
255
|
+
请让每张权益卡按其名称各自成组,并为每种计费类型加一个小标识:
|
|
252
256
|
|
|
253
257
|
```python
|
|
254
258
|
def system_group_title(model: dict) -> str:
|
|
255
|
-
if model.get("
|
|
256
|
-
return f"远端 · 系统 · {model.get('
|
|
259
|
+
if model.get("billingType") == "benefit card":
|
|
260
|
+
return f"远端 · 系统 · {model.get('cardName') or '权益卡'}"
|
|
257
261
|
return "远端 · 系统"
|
|
258
262
|
```
|
|
259
263
|
|
|
260
|
-
非权益卡的系统模型还会带有 `billingType`(`"free"`、`"plan"` 或 `"payAsYouGo"`;未知时以及其他模型均不包含该键),
|
|
261
|
-
选择器可以为每种类型加一个小标识。
|
|
262
|
-
|
|
263
264
|
模型字典还会带有 `contextWindowSize` 与 `maxOutputTokens`(模型单次响应最多可生成的
|
|
264
265
|
token 数);`maxOutputTokens` 仅在网关返回时才存在。只有 chat 模型才会返回
|
|
265
266
|
`maxOutputTokens`(embedding、ASR、TTS、decision 模型不生成文本,不包含该键);返回了
|
|
@@ -480,26 +481,27 @@ async with AgentOSSDK() as sdk:
|
|
|
480
481
|
|
|
481
482
|
## DiscoveryKit
|
|
482
483
|
|
|
484
|
+
附近 AgentOS 设备的设备级发现。App 可以查询附近设备和本机设备信息,不会被广播给其他设备。
|
|
485
|
+
|
|
483
486
|
```python
|
|
484
487
|
async with AgentOSSDK() as sdk:
|
|
485
488
|
await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
|
|
486
489
|
|
|
487
|
-
await sdk.discoverykit.register({"receivePolicy": "autoAccept"})
|
|
488
|
-
|
|
489
490
|
peers = await sdk.discoverykit.get_peers()
|
|
490
491
|
print(peers)
|
|
491
492
|
|
|
492
493
|
self_info = await sdk.discoverykit.get_self()
|
|
493
|
-
print(self_info["deviceName"], self_info["
|
|
494
|
+
print(self_info["deviceName"], self_info["nearbyTransferEnabled"])
|
|
494
495
|
|
|
495
496
|
async for event in sdk.discoverykit.stream_peers():
|
|
496
497
|
print(event["type"], event["device"]["name"])
|
|
497
|
-
|
|
498
|
-
await sdk.discoverykit.unregister()
|
|
499
498
|
```
|
|
500
499
|
|
|
501
500
|
## TransferKit
|
|
502
501
|
|
|
502
|
+
向附近的 AgentOS 设备发送文件,接收设备在其内置的附近传输界面中处理收到的文件。
|
|
503
|
+
App 可以发送文件,并跟踪或取消自己发起的传输。
|
|
504
|
+
|
|
503
505
|
```python
|
|
504
506
|
async with AgentOSSDK() as sdk:
|
|
505
507
|
await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
|
|
@@ -520,12 +522,6 @@ async with AgentOSSDK() as sdk:
|
|
|
520
522
|
transfer_id=session["transferId"]
|
|
521
523
|
):
|
|
522
524
|
print(progress["progress"])
|
|
523
|
-
|
|
524
|
-
await sdk.transferkit.set_policy(request={"policy": "autoAccept"})
|
|
525
|
-
policy = await sdk.transferkit.get_policy()
|
|
526
|
-
|
|
527
|
-
history = await sdk.transferkit.get_history()
|
|
528
|
-
await sdk.transferkit.clear_history()
|
|
529
525
|
```
|
|
530
526
|
|
|
531
527
|
`list_tool()` 的返回类型为 `list[ToolDto]`,并暴露 daemon 0.5 元数据。可选
|
|
@@ -228,7 +228,7 @@ Every model also carries `source`, the mutually exclusive origin of the model
|
|
|
228
228
|
| `source` | Meaning | Suggested group |
|
|
229
229
|
| --- | --- | --- |
|
|
230
230
|
| `"local"` | Runs on this device | Local Models |
|
|
231
|
-
| `"platform"` | Remote model provided by the AgentOS platform | Platform Models, plus `Remote · System · {
|
|
231
|
+
| `"platform"` | Remote model provided by the AgentOS platform | Platform Models, plus `Remote · System · {cardName}` for each benefit card (see below) |
|
|
232
232
|
| `"custom"` | Remote model configured by the user | Custom Models |
|
|
233
233
|
| `"app"` | Registered by a third-party app | `App · {appName}` (one group per app) |
|
|
234
234
|
|
|
@@ -248,24 +248,25 @@ one, so fall back to `appBundleId`). Against gateways that predate `source`, or
|
|
|
248
248
|
when it holds an unknown value, `source` is derived from the legacy flags with
|
|
249
249
|
the gateway's rules.
|
|
250
250
|
|
|
251
|
+
Platform models also carry the billing fields of the AgentOS server's model list,
|
|
252
|
+
with the same names and values: `billingType` (`"free"`, `"in plan"`,
|
|
253
|
+
`"pay as you go"` or `"benefit card"`), `cardName` (the benefit card, only for
|
|
254
|
+
`"benefit card"`) and `planNameZh` / `planNameEn` (the plan, only for `"free"` and
|
|
255
|
+
`"in plan"`). They are omitted when unknown and for local, custom and app models.
|
|
256
|
+
|
|
251
257
|
Models served through a benefit card keep `source` `"platform"` and their plain
|
|
252
|
-
`name` / `alias
|
|
253
|
-
`
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
each card as its own group:
|
|
258
|
+
`name` / `alias`. The same model can be listed once for the plan and once per
|
|
259
|
+
card, so tell them apart by `id`, `billingType` or `cardName`. `cardName` is the
|
|
260
|
+
only identifier of a card: show each card as its own group named after it, and
|
|
261
|
+
mark each billing type with a small badge:
|
|
257
262
|
|
|
258
263
|
```python
|
|
259
264
|
def system_group_title(model: dict) -> str:
|
|
260
|
-
if model.get("
|
|
261
|
-
return f"Remote · System · {model.get('
|
|
265
|
+
if model.get("billingType") == "benefit card":
|
|
266
|
+
return f"Remote · System · {model.get('cardName') or 'Benefit card'}"
|
|
262
267
|
return "Remote · System"
|
|
263
268
|
```
|
|
264
269
|
|
|
265
|
-
System models that are not benefit card models also report `billingType`
|
|
266
|
-
(`"free"`, `"plan"` or `"payAsYouGo"`; omitted when unknown and for every other
|
|
267
|
-
model), so a picker can mark each type with a small badge.
|
|
268
|
-
|
|
269
270
|
Model dicts also carry `contextWindowSize` and `maxOutputTokens` (the maximum
|
|
270
271
|
number of tokens the model can generate in one response); `maxOutputTokens` is
|
|
271
272
|
only present when the gateway reports it. Only chat models report
|
|
@@ -499,26 +500,29 @@ async with AgentOSSDK() as sdk:
|
|
|
499
500
|
|
|
500
501
|
## DiscoveryKit
|
|
501
502
|
|
|
503
|
+
Device-level discovery of nearby AgentOS devices. Apps can query nearby devices
|
|
504
|
+
and the current device's info; they are never advertised to other devices.
|
|
505
|
+
|
|
502
506
|
```python
|
|
503
507
|
async with AgentOSSDK() as sdk:
|
|
504
508
|
await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
|
|
505
509
|
|
|
506
|
-
await sdk.discoverykit.register({"receivePolicy": "autoAccept"})
|
|
507
|
-
|
|
508
510
|
peers = await sdk.discoverykit.get_peers()
|
|
509
511
|
print(peers)
|
|
510
512
|
|
|
511
513
|
self_info = await sdk.discoverykit.get_self()
|
|
512
|
-
print(self_info["deviceName"], self_info["
|
|
514
|
+
print(self_info["deviceName"], self_info["nearbyTransferEnabled"])
|
|
513
515
|
|
|
514
516
|
async for event in sdk.discoverykit.stream_peers():
|
|
515
517
|
print(event["type"], event["device"]["name"])
|
|
516
|
-
|
|
517
|
-
await sdk.discoverykit.unregister()
|
|
518
518
|
```
|
|
519
519
|
|
|
520
520
|
## TransferKit
|
|
521
521
|
|
|
522
|
+
Sends files to a nearby AgentOS device. The receiving device handles the
|
|
523
|
+
incoming files in its built-in nearby transfer UI. Apps can send files and track
|
|
524
|
+
or cancel their own transfers.
|
|
525
|
+
|
|
522
526
|
```python
|
|
523
527
|
async with AgentOSSDK() as sdk:
|
|
524
528
|
await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
|
|
@@ -539,12 +543,6 @@ async with AgentOSSDK() as sdk:
|
|
|
539
543
|
transfer_id=session["transferId"]
|
|
540
544
|
):
|
|
541
545
|
print(progress["progress"])
|
|
542
|
-
|
|
543
|
-
await sdk.transferkit.set_policy(request={"policy": "autoAccept"})
|
|
544
|
-
policy = await sdk.transferkit.get_policy()
|
|
545
|
-
|
|
546
|
-
history = await sdk.transferkit.get_history()
|
|
547
|
-
await sdk.transferkit.clear_history()
|
|
548
546
|
```
|
|
549
547
|
|
|
550
548
|
`list_tool()` is typed as `list[ToolDto]` and exposes daemon 0.5 metadata. Its
|
|
@@ -12,8 +12,8 @@ The Python import package remains `agentos_sdk`.
|
|
|
12
12
|
```bash
|
|
13
13
|
.venv/bin/python -m pytest -q
|
|
14
14
|
.venv/bin/ruff check .
|
|
15
|
-
.venv/bin/python -m build --no-isolation --outdir dist/
|
|
16
|
-
.venv/bin/python -m twine check dist/
|
|
15
|
+
.venv/bin/python -m build --no-isolation --outdir dist/2.0.0
|
|
16
|
+
.venv/bin/python -m twine check dist/2.0.0/*
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## TestPyPI
|
|
@@ -21,7 +21,7 @@ The Python import package remains `agentos_sdk`.
|
|
|
21
21
|
Upload to TestPyPI first:
|
|
22
22
|
|
|
23
23
|
```bash
|
|
24
|
-
.venv/bin/python -m twine upload --repository testpypi dist/
|
|
24
|
+
.venv/bin/python -m twine upload --repository testpypi dist/2.0.0/*
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
Install from TestPyPI in a clean environment:
|
|
@@ -31,7 +31,7 @@ python3 -m venv /tmp/agentos-sdk-python-test
|
|
|
31
31
|
/tmp/agentos-sdk-python-test/bin/python -m pip install \
|
|
32
32
|
--index-url https://test.pypi.org/simple/ \
|
|
33
33
|
--extra-index-url https://pypi.org/simple/ \
|
|
34
|
-
agentos-sdk-python==
|
|
34
|
+
agentos-sdk-python==2.0.0
|
|
35
35
|
/tmp/agentos-sdk-python-test/bin/python -c "from agentos_sdk import AgentOSSDK; print(AgentOSSDK)"
|
|
36
36
|
```
|
|
37
37
|
|
|
@@ -40,14 +40,14 @@ python3 -m venv /tmp/agentos-sdk-python-test
|
|
|
40
40
|
Upload to PyPI:
|
|
41
41
|
|
|
42
42
|
```bash
|
|
43
|
-
.venv/bin/python -m twine upload dist/
|
|
43
|
+
.venv/bin/python -m twine upload dist/2.0.0/*
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
Tag the released commit:
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
|
-
git tag
|
|
50
|
-
git push github
|
|
49
|
+
git tag v2.0.0
|
|
50
|
+
git push github v2.0.0
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
## Authentication
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
|
-
from typing import Any, AsyncGenerator
|
|
4
|
+
from typing import Any, AsyncGenerator
|
|
5
5
|
|
|
6
6
|
from agentos_sdk.transport import ApiClient, iter_sse
|
|
7
7
|
|
|
@@ -33,24 +33,6 @@ class DiscoveryKitClient:
|
|
|
33
33
|
headers=_auth(bearer_token),
|
|
34
34
|
)
|
|
35
35
|
|
|
36
|
-
async def register(
|
|
37
|
-
self, bearer_token: str, request: Mapping[str, Any] | None = None
|
|
38
|
-
) -> dict[str, Any]:
|
|
39
|
-
return await self.api_client.request(
|
|
40
|
-
"/discoverykit/register",
|
|
41
|
-
method="POST",
|
|
42
|
-
headers=_auth(bearer_token),
|
|
43
|
-
data=dict(request) if request else {},
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
async def unregister(self, bearer_token: str) -> dict[str, Any]:
|
|
47
|
-
return await self.api_client.request(
|
|
48
|
-
"/discoverykit/unregister",
|
|
49
|
-
method="POST",
|
|
50
|
-
headers=_auth(bearer_token),
|
|
51
|
-
data={},
|
|
52
|
-
)
|
|
53
|
-
|
|
54
36
|
getPeers = get_peers
|
|
55
37
|
streamPeers = stream_peers
|
|
56
38
|
getSelf = get_self
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Any, AsyncGenerator, Mapping
|
|
5
|
+
|
|
6
|
+
from agentos_sdk.transport import ApiClient, iter_sse
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class TransferKitClient:
|
|
10
|
+
def __init__(self, api_client: ApiClient | None = None) -> None:
|
|
11
|
+
self.api_client = api_client or ApiClient()
|
|
12
|
+
|
|
13
|
+
async def send(
|
|
14
|
+
self, bearer_token: str, request: Mapping[str, Any]
|
|
15
|
+
) -> dict[str, Any]:
|
|
16
|
+
return await self.api_client.request(
|
|
17
|
+
"/transferkit/send",
|
|
18
|
+
method="POST",
|
|
19
|
+
headers=_auth(bearer_token),
|
|
20
|
+
data=dict(request),
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
async def list_transfers(self, bearer_token: str) -> list[dict[str, Any]]:
|
|
24
|
+
return await self.api_client.request(
|
|
25
|
+
"/transferkit/transfers",
|
|
26
|
+
headers=_auth(bearer_token),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
async def get_status(
|
|
30
|
+
self, bearer_token: str, transfer_id: str
|
|
31
|
+
) -> dict[str, Any]:
|
|
32
|
+
return await self.api_client.request(
|
|
33
|
+
f"/transferkit/transfers/{transfer_id}/status",
|
|
34
|
+
headers=_auth(bearer_token),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
async def stream_progress(
|
|
38
|
+
self, bearer_token: str, transfer_id: str
|
|
39
|
+
) -> AsyncGenerator[dict[str, Any], None]:
|
|
40
|
+
response = await self.api_client.request_stream(
|
|
41
|
+
f"/transferkit/transfers/{transfer_id}/stream",
|
|
42
|
+
headers=_auth(bearer_token),
|
|
43
|
+
)
|
|
44
|
+
async for event in iter_sse(response):
|
|
45
|
+
if event.data:
|
|
46
|
+
yield json.loads(event.data)
|
|
47
|
+
|
|
48
|
+
async def cancel(
|
|
49
|
+
self, bearer_token: str, transfer_id: str
|
|
50
|
+
) -> dict[str, Any]:
|
|
51
|
+
return await self.api_client.request(
|
|
52
|
+
f"/transferkit/transfers/{transfer_id}/cancel",
|
|
53
|
+
method="POST",
|
|
54
|
+
headers=_auth(bearer_token),
|
|
55
|
+
data={},
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
listTransfers = list_transfers
|
|
59
|
+
getStatus = get_status
|
|
60
|
+
streamProgress = stream_progress
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _auth(token: str) -> dict[str, str]:
|
|
64
|
+
return {"authorization": f"Bearer {token}"}
|
|
@@ -97,8 +97,8 @@ def normalize_agent_event_name(event_type: str) -> str:
|
|
|
97
97
|
MODEL_TASKS = {"chat", "embedding", "asr", "tts", "decision"}
|
|
98
98
|
MODALITIES = {"text", "image", "audio", "video", "decisions"}
|
|
99
99
|
MODEL_SOURCES = {"local", "platform", "custom", "app"}
|
|
100
|
-
# Wire values of ``billingType
|
|
101
|
-
MODEL_BILLING_TYPES = {"free"
|
|
100
|
+
# Wire values of ``billingType`` (the same as the AgentOS server's model list); parsing is case-insensitive.
|
|
101
|
+
MODEL_BILLING_TYPES = {"free", "in plan", "pay as you go", "benefit card"}
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
def _model_task(value: Any) -> str:
|
|
@@ -166,19 +166,15 @@ def normalize_model_info(item: Mapping[str, Any]) -> dict[str, Any]:
|
|
|
166
166
|
app_name = str(item["appName"]).strip() if item.get("appName") is not None else ""
|
|
167
167
|
if app_name:
|
|
168
168
|
result["appName"] = app_name
|
|
169
|
-
#
|
|
170
|
-
#
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
169
|
+
# The billing fields are the server's own: only system models carry them, and missing, blank and
|
|
170
|
+
# unknown values are dropped. Benefit card models keep source "platform"; ``cardName`` names the card.
|
|
171
|
+
billing_type = str(item.get("billingType") or "").strip().lower()
|
|
172
|
+
if billing_type in MODEL_BILLING_TYPES:
|
|
173
|
+
result["billingType"] = billing_type
|
|
174
|
+
for key in ("cardName", "planNameZh", "planNameEn"):
|
|
174
175
|
value = str(item[key]).strip() if item.get(key) is not None else ""
|
|
175
176
|
if value:
|
|
176
177
|
result[key] = value
|
|
177
|
-
# Only system models that are not benefit card models carry a billing type; missing,
|
|
178
|
-
# blank and unknown values are dropped.
|
|
179
|
-
billing_type = MODEL_BILLING_TYPES.get(str(item.get("billingType") or "").strip().lower())
|
|
180
|
-
if billing_type:
|
|
181
|
-
result["billingType"] = billing_type
|
|
182
178
|
return result
|
|
183
179
|
|
|
184
180
|
|
|
@@ -10,8 +10,8 @@ ModelTask = Literal["chat", "embedding", "asr", "tts", "decision"]
|
|
|
10
10
|
Modality = Literal["text", "image", "audio", "video", "decisions"]
|
|
11
11
|
# 模型互斥的来源,对应网关 ``/modelkit/models`` 的 ``source`` 字段。
|
|
12
12
|
ModelSource = Literal["local", "platform", "custom", "app"]
|
|
13
|
-
# 系统模型的计费类型,对应网关 ``/modelkit/models`` 的 ``billingType``
|
|
14
|
-
ModelBillingType = Literal["free", "plan", "
|
|
13
|
+
# 系统模型的计费类型,对应网关 ``/modelkit/models`` 的 ``billingType`` 字段,取值与服务端模型列表一致。
|
|
14
|
+
ModelBillingType = Literal["free", "in plan", "pay as you go", "benefit card"]
|
|
15
15
|
ToolContentState = Literal["unknown", "current", "updatePending", "broken"]
|
|
16
16
|
OpenToolRegistrationStatusValue = Literal["running", "starting", "notFound"]
|
|
17
17
|
HistoryTurnStatusValue = Literal["running", "done", "error", "stopped"]
|
|
@@ -843,16 +843,6 @@ class DiscoveryKitModule:
|
|
|
843
843
|
lambda token: self._sdk.discoveryKit.get_self(token)
|
|
844
844
|
)
|
|
845
845
|
|
|
846
|
-
async def register(self, request: Mapping[str, Any] | None = None) -> dict[str, Any]:
|
|
847
|
-
return await self._sdk._with_app_auth_retry(
|
|
848
|
-
lambda token: self._sdk.discoveryKit.register(token, request)
|
|
849
|
-
)
|
|
850
|
-
|
|
851
|
-
async def unregister(self) -> dict[str, Any]:
|
|
852
|
-
return await self._sdk._with_app_auth_retry(
|
|
853
|
-
lambda token: self._sdk.discoveryKit.unregister(token)
|
|
854
|
-
)
|
|
855
|
-
|
|
856
846
|
getPeers = get_peers
|
|
857
847
|
streamPeers = stream_peers
|
|
858
848
|
getSelf = get_self
|
|
@@ -889,68 +879,9 @@ class TransferKitModule:
|
|
|
889
879
|
lambda token: self._sdk.transferKit.cancel(token, transfer_id)
|
|
890
880
|
)
|
|
891
881
|
|
|
892
|
-
async def respond(
|
|
893
|
-
self, *, transfer_id: str, request: Mapping[str, Any]
|
|
894
|
-
) -> dict[str, Any]:
|
|
895
|
-
return await self._sdk._with_app_auth_retry(
|
|
896
|
-
lambda token: self._sdk.transferKit.respond(token, transfer_id, request)
|
|
897
|
-
)
|
|
898
|
-
|
|
899
|
-
async def receive_stream(self) -> AsyncGenerator[dict[str, Any], None]:
|
|
900
|
-
context = await self._sdk._require_auth_context()
|
|
901
|
-
async for event in self._sdk.transferKit.receive_stream(context.token):
|
|
902
|
-
yield event
|
|
903
|
-
|
|
904
|
-
async def set_policy(self, *, request: Mapping[str, Any]) -> dict[str, Any]:
|
|
905
|
-
return await self._sdk._with_app_auth_retry(
|
|
906
|
-
lambda token: self._sdk.transferKit.set_policy(token, request)
|
|
907
|
-
)
|
|
908
|
-
|
|
909
|
-
async def get_policy(self) -> dict[str, Any]:
|
|
910
|
-
return await self._sdk._with_app_auth_retry(
|
|
911
|
-
lambda token: self._sdk.transferKit.get_policy(token)
|
|
912
|
-
)
|
|
913
|
-
|
|
914
|
-
async def get_history(
|
|
915
|
-
self, *, device_id: str | None = None, user_id: str | None = None
|
|
916
|
-
) -> list[dict[str, Any]]:
|
|
917
|
-
return await self._sdk._with_app_auth_retry(
|
|
918
|
-
lambda token: self._sdk.transferKit.get_history(
|
|
919
|
-
token, device_id=device_id, user_id=user_id
|
|
920
|
-
)
|
|
921
|
-
)
|
|
922
|
-
|
|
923
|
-
async def delete_history(
|
|
924
|
-
self,
|
|
925
|
-
*,
|
|
926
|
-
record_id: str,
|
|
927
|
-
device_id: str | None = None,
|
|
928
|
-
user_id: str | None = None,
|
|
929
|
-
) -> dict[str, Any]:
|
|
930
|
-
return await self._sdk._with_app_auth_retry(
|
|
931
|
-
lambda token: self._sdk.transferKit.delete_history(
|
|
932
|
-
token, record_id, device_id=device_id, user_id=user_id
|
|
933
|
-
)
|
|
934
|
-
)
|
|
935
|
-
|
|
936
|
-
async def clear_history(
|
|
937
|
-
self, *, device_id: str | None = None, user_id: str | None = None
|
|
938
|
-
) -> dict[str, Any]:
|
|
939
|
-
return await self._sdk._with_app_auth_retry(
|
|
940
|
-
lambda token: self._sdk.transferKit.clear_history(
|
|
941
|
-
token, device_id=device_id, user_id=user_id
|
|
942
|
-
)
|
|
943
|
-
)
|
|
944
|
-
|
|
945
882
|
listTransfers = list_transfers
|
|
946
883
|
getStatus = get_status
|
|
947
884
|
streamProgress = stream_progress
|
|
948
|
-
receiveStream = receive_stream
|
|
949
|
-
setPolicy = set_policy
|
|
950
|
-
getPolicy = get_policy
|
|
951
|
-
getHistory = get_history
|
|
952
|
-
deleteHistory = delete_history
|
|
953
|
-
clearHistory = clear_history
|
|
954
885
|
|
|
955
886
|
|
|
956
887
|
class HarnessKitModule:
|
|
@@ -189,21 +189,23 @@ async def test_list_models_reports_benefit_card_models_next_to_plan_models():
|
|
|
189
189
|
200,
|
|
190
190
|
json=[
|
|
191
191
|
{
|
|
192
|
-
"id": "
|
|
192
|
+
"id": "plan-binding",
|
|
193
193
|
"name": "deepseek-v4-flash",
|
|
194
194
|
"task": "chat",
|
|
195
195
|
"isRemote": True,
|
|
196
196
|
"source": "platform",
|
|
197
|
+
"billingType": "in plan",
|
|
198
|
+
"planNameZh": " 专业版 ",
|
|
199
|
+
"planNameEn": "Pro",
|
|
197
200
|
},
|
|
198
201
|
{
|
|
199
|
-
"id": "
|
|
202
|
+
"id": "card-binding",
|
|
200
203
|
"name": "deepseek-v4-flash",
|
|
201
204
|
"task": "chat",
|
|
202
205
|
"isRemote": True,
|
|
203
206
|
"source": "platform",
|
|
204
|
-
"
|
|
205
|
-
"
|
|
206
|
-
"benefitCardName": "Spring card",
|
|
207
|
+
"billingType": "benefit card",
|
|
208
|
+
"cardName": "Spring card",
|
|
207
209
|
},
|
|
208
210
|
],
|
|
209
211
|
)
|
|
@@ -212,10 +214,39 @@ async def test_list_models_reports_benefit_card_models_next_to_plan_models():
|
|
|
212
214
|
|
|
213
215
|
assert [m["source"] for m in models] == ["platform", "platform"]
|
|
214
216
|
assert models[0]["name"] == models[1]["name"]
|
|
215
|
-
assert "
|
|
216
|
-
assert models[
|
|
217
|
-
assert models[
|
|
218
|
-
assert
|
|
217
|
+
assert models[0]["billingType"] == "in plan"
|
|
218
|
+
assert models[0]["planNameZh"] == "专业版"
|
|
219
|
+
assert models[0]["planNameEn"] == "Pro"
|
|
220
|
+
assert "cardName" not in models[0]
|
|
221
|
+
assert models[1]["billingType"] == "benefit card"
|
|
222
|
+
assert models[1]["cardName"] == "Spring card"
|
|
223
|
+
assert "planNameZh" not in models[1]
|
|
224
|
+
assert "planNameEn" not in models[1]
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
@pytest.mark.asyncio
|
|
228
|
+
async def test_list_models_ignores_the_retired_flat_benefit_card_fields():
|
|
229
|
+
async def handler(request: httpx.Request) -> httpx.Response:
|
|
230
|
+
return httpx.Response(
|
|
231
|
+
200,
|
|
232
|
+
json=[
|
|
233
|
+
{
|
|
234
|
+
"id": "bc_7",
|
|
235
|
+
"name": "m",
|
|
236
|
+
"task": "chat",
|
|
237
|
+
"isRemote": True,
|
|
238
|
+
"source": "platform",
|
|
239
|
+
"isBenefitCard": True,
|
|
240
|
+
"benefitCardId": "card-1",
|
|
241
|
+
"benefitCardName": "Spring card",
|
|
242
|
+
}
|
|
243
|
+
],
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
models = await _modelkit(handler).list_models()
|
|
247
|
+
|
|
248
|
+
for key in ("isBenefitCard", "benefitCardId", "benefitCardName", "billingType", "cardName"):
|
|
249
|
+
assert key not in models[0], key
|
|
219
250
|
|
|
220
251
|
|
|
221
252
|
@pytest.mark.asyncio
|
|
@@ -226,20 +257,34 @@ async def test_list_models_reports_the_billing_type_of_system_models():
|
|
|
226
257
|
return httpx.Response(
|
|
227
258
|
200,
|
|
228
259
|
json=[
|
|
229
|
-
{"id": "
|
|
230
|
-
{"id": "
|
|
231
|
-
{"id": "
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
{"id": "
|
|
235
|
-
{"id": "
|
|
260
|
+
{"id": "a", "name": "a", **platform, "billingType": "free"},
|
|
261
|
+
{"id": "b", "name": "b", **platform, "billingType": "in plan"},
|
|
262
|
+
{"id": "c", "name": "c", **platform, "billingType": " Pay As You Go "},
|
|
263
|
+
{"id": "d", "name": "d", **platform, "billingType": "benefit card"},
|
|
264
|
+
# No field (local, custom, open-source server), blank and unknown values.
|
|
265
|
+
{"id": "missing", "name": "missing", **platform},
|
|
266
|
+
{"id": "blank", "name": "blank", **platform, "billingType": " "},
|
|
267
|
+
# The retired values of earlier gateways are not understood.
|
|
268
|
+
{"id": "retired-plan", "name": "retired-plan", **platform, "billingType": "plan"},
|
|
269
|
+
{
|
|
270
|
+
"id": "retired-payg",
|
|
271
|
+
"name": "retired-payg",
|
|
272
|
+
**platform,
|
|
273
|
+
"billingType": "payAsYouGo",
|
|
274
|
+
},
|
|
275
|
+
{"id": "unknown", "name": "unknown", **platform, "billingType": "subscription"},
|
|
236
276
|
],
|
|
237
277
|
)
|
|
238
278
|
|
|
239
279
|
models = await _modelkit(handler).list_models()
|
|
240
280
|
|
|
241
|
-
assert [m["billingType"] for m in models[:
|
|
242
|
-
|
|
281
|
+
assert [m["billingType"] for m in models[:4]] == [
|
|
282
|
+
"free",
|
|
283
|
+
"in plan",
|
|
284
|
+
"pay as you go",
|
|
285
|
+
"benefit card",
|
|
286
|
+
]
|
|
287
|
+
for model in models[4:]:
|
|
243
288
|
assert "billingType" not in model, model["id"]
|
|
244
289
|
|
|
245
290
|
|
|
@@ -201,46 +201,78 @@ def test_model_info_reports_app_name_only_when_non_blank():
|
|
|
201
201
|
assert "appName" not in model
|
|
202
202
|
|
|
203
203
|
|
|
204
|
-
def
|
|
204
|
+
def test_model_info_reports_billing_fields_of_the_server_model_list():
|
|
205
|
+
plain = normalize_model_info(
|
|
206
|
+
{"id": "m", "name": "m", "isRemote": True, "source": "platform"}
|
|
207
|
+
)
|
|
205
208
|
plan = normalize_model_info(
|
|
206
|
-
{
|
|
209
|
+
{
|
|
210
|
+
"id": "plan-binding",
|
|
211
|
+
"name": "m",
|
|
212
|
+
"isRemote": True,
|
|
213
|
+
"source": "platform",
|
|
214
|
+
"billingType": "In Plan",
|
|
215
|
+
"planNameZh": " 专业版 ",
|
|
216
|
+
"planNameEn": "Pro",
|
|
217
|
+
"cardName": " ",
|
|
218
|
+
}
|
|
207
219
|
)
|
|
208
220
|
card = normalize_model_info(
|
|
209
221
|
{
|
|
210
|
-
"id": "
|
|
222
|
+
"id": "card-binding",
|
|
211
223
|
"name": "m",
|
|
212
224
|
"isRemote": True,
|
|
213
225
|
"source": "platform",
|
|
214
|
-
"
|
|
215
|
-
"
|
|
216
|
-
"benefitCardName": " Spring card ",
|
|
226
|
+
"billingType": "benefit card",
|
|
227
|
+
"cardName": " Spring card ",
|
|
217
228
|
}
|
|
218
229
|
)
|
|
219
|
-
|
|
230
|
+
nameless_card = normalize_model_info(
|
|
220
231
|
{
|
|
221
|
-
"id": "
|
|
232
|
+
"id": "nameless-card-binding",
|
|
222
233
|
"isRemote": True,
|
|
223
234
|
"source": "platform",
|
|
224
|
-
"
|
|
225
|
-
"
|
|
226
|
-
"benefitCardName": " ",
|
|
235
|
+
"billingType": "benefit card",
|
|
236
|
+
"cardName": " ",
|
|
227
237
|
}
|
|
228
238
|
)
|
|
229
239
|
|
|
230
240
|
# A card model keeps its platform source and plain name.
|
|
231
|
-
assert
|
|
241
|
+
assert plain["source"] == plan["source"] == card["source"] == "platform"
|
|
232
242
|
assert card["name"] == plan["name"]
|
|
233
|
-
for key in ("
|
|
234
|
-
assert key not in
|
|
235
|
-
|
|
236
|
-
assert
|
|
237
|
-
assert
|
|
238
|
-
assert
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
assert
|
|
243
|
-
assert "
|
|
243
|
+
for key in ("billingType", "cardName", "planNameZh", "planNameEn"):
|
|
244
|
+
assert key not in plain
|
|
245
|
+
|
|
246
|
+
assert plan["billingType"] == "in plan"
|
|
247
|
+
assert plan["planNameZh"] == "专业版"
|
|
248
|
+
assert plan["planNameEn"] == "Pro"
|
|
249
|
+
# A blank card name is dropped.
|
|
250
|
+
assert "cardName" not in plan
|
|
251
|
+
|
|
252
|
+
assert card["billingType"] == "benefit card"
|
|
253
|
+
assert card["cardName"] == "Spring card"
|
|
254
|
+
assert "planNameZh" not in card
|
|
255
|
+
assert "planNameEn" not in card
|
|
256
|
+
|
|
257
|
+
assert nameless_card["billingType"] == "benefit card"
|
|
258
|
+
assert "cardName" not in nameless_card
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def test_model_info_drops_the_retired_billing_values_and_flat_card_fields():
|
|
262
|
+
for retired in ("plan", "payAsYouGo", "subscription", ""):
|
|
263
|
+
model = normalize_model_info(
|
|
264
|
+
{
|
|
265
|
+
"id": "m",
|
|
266
|
+
"isRemote": True,
|
|
267
|
+
"source": "platform",
|
|
268
|
+
"billingType": retired,
|
|
269
|
+
"isBenefitCard": True,
|
|
270
|
+
"benefitCardId": "card-1",
|
|
271
|
+
"benefitCardName": "Spring card",
|
|
272
|
+
}
|
|
273
|
+
)
|
|
274
|
+
for key in ("billingType", "isBenefitCard", "benefitCardId", "benefitCardName"):
|
|
275
|
+
assert key not in model, (retired, key)
|
|
244
276
|
|
|
245
277
|
|
|
246
278
|
def test_app_model_normalization_keeps_gateway_generated_id():
|
|
@@ -619,3 +619,56 @@ def test_modelkit_module_app_model_camel_case_aliases():
|
|
|
619
619
|
("toggle_app_model", "toggleAppModel"),
|
|
620
620
|
]:
|
|
621
621
|
assert getattr(ModelKitModule, camel) is getattr(ModelKitModule, snake)
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
def test_nearby_modules_expose_device_level_operations_only():
|
|
625
|
+
from agentos_sdk.sdk import DiscoveryKitModule, TransferKitModule
|
|
626
|
+
|
|
627
|
+
def public(cls):
|
|
628
|
+
return {name for name in dir(cls) if not name.startswith("_")}
|
|
629
|
+
|
|
630
|
+
assert public(DiscoveryKitModule) == {
|
|
631
|
+
"get_peers",
|
|
632
|
+
"getPeers",
|
|
633
|
+
"stream_peers",
|
|
634
|
+
"streamPeers",
|
|
635
|
+
"get_self",
|
|
636
|
+
"getSelf",
|
|
637
|
+
}
|
|
638
|
+
assert public(TransferKitModule) == {
|
|
639
|
+
"send",
|
|
640
|
+
"list_transfers",
|
|
641
|
+
"listTransfers",
|
|
642
|
+
"get_status",
|
|
643
|
+
"getStatus",
|
|
644
|
+
"stream_progress",
|
|
645
|
+
"streamProgress",
|
|
646
|
+
"cancel",
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
@pytest.mark.asyncio
|
|
651
|
+
async def test_transferkit_send_posts_device_level_request():
|
|
652
|
+
state = {"body": None}
|
|
653
|
+
|
|
654
|
+
async def handler(request: httpx.Request) -> httpx.Response:
|
|
655
|
+
if request.url.path == "/appkit/register":
|
|
656
|
+
return httpx.Response(200, json={"token": "token-1"})
|
|
657
|
+
if request.url.path == "/transferkit/send":
|
|
658
|
+
state["body"] = json.loads(request.read())
|
|
659
|
+
assert request.headers["authorization"] == "Bearer token-1"
|
|
660
|
+
return httpx.Response(200, json={"transferId": "tf-1", "state": "preparing"})
|
|
661
|
+
raise AssertionError(f"Unhandled {request.method} {request.url.path}")
|
|
662
|
+
|
|
663
|
+
request = {
|
|
664
|
+
"targetDeviceId": "peer-1",
|
|
665
|
+
"files": [{"fileName": "a.txt", "size": 1, "filePath": "/tmp/a.txt"}],
|
|
666
|
+
}
|
|
667
|
+
async with AgentOSSDK(
|
|
668
|
+
http_client=httpx.AsyncClient(transport=httpx.MockTransport(handler))
|
|
669
|
+
) as sdk:
|
|
670
|
+
await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
|
|
671
|
+
session = await sdk.transferkit.send(request=request)
|
|
672
|
+
|
|
673
|
+
assert session["transferId"] == "tf-1"
|
|
674
|
+
assert state["body"] == request
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import json
|
|
4
|
-
from typing import Any, AsyncGenerator, Mapping
|
|
5
|
-
|
|
6
|
-
from agentos_sdk.transport import ApiClient, iter_sse
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class TransferKitClient:
|
|
10
|
-
def __init__(self, api_client: ApiClient | None = None) -> None:
|
|
11
|
-
self.api_client = api_client or ApiClient()
|
|
12
|
-
|
|
13
|
-
async def send(
|
|
14
|
-
self, bearer_token: str, request: Mapping[str, Any]
|
|
15
|
-
) -> dict[str, Any]:
|
|
16
|
-
return await self.api_client.request(
|
|
17
|
-
"/transferkit/send",
|
|
18
|
-
method="POST",
|
|
19
|
-
headers=_auth(bearer_token),
|
|
20
|
-
data=dict(request),
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
async def list_transfers(self, bearer_token: str) -> list[dict[str, Any]]:
|
|
24
|
-
return await self.api_client.request(
|
|
25
|
-
"/transferkit/transfers",
|
|
26
|
-
headers=_auth(bearer_token),
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
async def get_status(
|
|
30
|
-
self, bearer_token: str, transfer_id: str
|
|
31
|
-
) -> dict[str, Any]:
|
|
32
|
-
return await self.api_client.request(
|
|
33
|
-
f"/transferkit/transfers/{transfer_id}/status",
|
|
34
|
-
headers=_auth(bearer_token),
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
async def stream_progress(
|
|
38
|
-
self, bearer_token: str, transfer_id: str
|
|
39
|
-
) -> AsyncGenerator[dict[str, Any], None]:
|
|
40
|
-
response = await self.api_client.request_stream(
|
|
41
|
-
f"/transferkit/transfers/{transfer_id}/stream",
|
|
42
|
-
headers=_auth(bearer_token),
|
|
43
|
-
)
|
|
44
|
-
async for event in iter_sse(response):
|
|
45
|
-
if event.data:
|
|
46
|
-
yield json.loads(event.data)
|
|
47
|
-
|
|
48
|
-
async def cancel(
|
|
49
|
-
self, bearer_token: str, transfer_id: str
|
|
50
|
-
) -> dict[str, Any]:
|
|
51
|
-
return await self.api_client.request(
|
|
52
|
-
f"/transferkit/transfers/{transfer_id}/cancel",
|
|
53
|
-
method="POST",
|
|
54
|
-
headers=_auth(bearer_token),
|
|
55
|
-
data={},
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
async def respond(
|
|
59
|
-
self, bearer_token: str, transfer_id: str, request: Mapping[str, Any]
|
|
60
|
-
) -> dict[str, Any]:
|
|
61
|
-
return await self.api_client.request(
|
|
62
|
-
f"/transferkit/transfers/{transfer_id}/respond",
|
|
63
|
-
method="POST",
|
|
64
|
-
headers=_auth(bearer_token),
|
|
65
|
-
data=dict(request),
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
async def receive_stream(
|
|
69
|
-
self, bearer_token: str
|
|
70
|
-
) -> AsyncGenerator[dict[str, Any], None]:
|
|
71
|
-
response = await self.api_client.request_stream(
|
|
72
|
-
"/transferkit/receive/stream",
|
|
73
|
-
headers=_auth(bearer_token),
|
|
74
|
-
)
|
|
75
|
-
async for event in iter_sse(response):
|
|
76
|
-
if event.data:
|
|
77
|
-
yield json.loads(event.data)
|
|
78
|
-
|
|
79
|
-
async def set_policy(
|
|
80
|
-
self, bearer_token: str, request: Mapping[str, Any]
|
|
81
|
-
) -> dict[str, Any]:
|
|
82
|
-
return await self.api_client.request(
|
|
83
|
-
"/transferkit/receive/policy",
|
|
84
|
-
method="PUT",
|
|
85
|
-
headers=_auth(bearer_token),
|
|
86
|
-
data=dict(request),
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
async def get_policy(self, bearer_token: str) -> dict[str, Any]:
|
|
90
|
-
return await self.api_client.request(
|
|
91
|
-
"/transferkit/receive/policy",
|
|
92
|
-
headers=_auth(bearer_token),
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
async def get_history(
|
|
96
|
-
self,
|
|
97
|
-
bearer_token: str,
|
|
98
|
-
*,
|
|
99
|
-
device_id: str | None = None,
|
|
100
|
-
user_id: str | None = None,
|
|
101
|
-
) -> list[dict[str, Any]]:
|
|
102
|
-
return await self.api_client.request(
|
|
103
|
-
"/transferkit/history",
|
|
104
|
-
query={"deviceId": device_id, "userId": user_id},
|
|
105
|
-
headers=_auth(bearer_token),
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
async def delete_history(
|
|
109
|
-
self,
|
|
110
|
-
bearer_token: str,
|
|
111
|
-
record_id: str,
|
|
112
|
-
*,
|
|
113
|
-
device_id: str | None = None,
|
|
114
|
-
user_id: str | None = None,
|
|
115
|
-
) -> dict[str, Any]:
|
|
116
|
-
return await self.api_client.request(
|
|
117
|
-
f"/transferkit/history/{record_id}",
|
|
118
|
-
method="DELETE",
|
|
119
|
-
query={"deviceId": device_id, "userId": user_id},
|
|
120
|
-
headers=_auth(bearer_token),
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
async def clear_history(
|
|
124
|
-
self,
|
|
125
|
-
bearer_token: str,
|
|
126
|
-
*,
|
|
127
|
-
device_id: str | None = None,
|
|
128
|
-
user_id: str | None = None,
|
|
129
|
-
) -> dict[str, Any]:
|
|
130
|
-
return await self.api_client.request(
|
|
131
|
-
"/transferkit/history",
|
|
132
|
-
method="DELETE",
|
|
133
|
-
query={"deviceId": device_id, "userId": user_id},
|
|
134
|
-
headers=_auth(bearer_token),
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
listTransfers = list_transfers
|
|
138
|
-
getStatus = get_status
|
|
139
|
-
streamProgress = stream_progress
|
|
140
|
-
receiveStream = receive_stream
|
|
141
|
-
setPolicy = set_policy
|
|
142
|
-
getPolicy = get_policy
|
|
143
|
-
getHistory = get_history
|
|
144
|
-
deleteHistory = delete_history
|
|
145
|
-
clearHistory = clear_history
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
def _auth(token: str) -> dict[str, str]:
|
|
149
|
-
return {"authorization": f"Bearer {token}"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|