feat(sdk): 普通 prompt 逐条上报用户时区
session/prompt 与 session/query 接受可选 timeZone,TS/Python 客户端透传;省略时逐条采样进程时区,写入 sdk-user 来源的 clientTimeZone。time-context 读取不带 rpcId 的 user 来源时区。补持久化记录、Agent Note、升级指南、README,并刷新 SDK snapshot。
This commit is contained in:
1 parent
71ce86fae6
commit
dca075e2a2
109 files changed
+1428
-421
No files matched your search
@@ -12,8 +12,8 @@
|
||||
en: 05298d7872586fcf
|
||||
zh: 9262ee9b2a8dee7d
|
||||
/deepseek-harness-python-sdk/run-text-and-commands:
|
||||
en: b2c847c1452e137d
|
||||
zh: c595c5e82151d0cb
|
||||
en: 6dec2d510bce71bd
|
||||
zh: 742ca999aaacd137
|
||||
/deepseek-harness-python-sdk/client-approvals:
|
||||
en: 1d18c09832dd4a42
|
||||
zh: 6e7260b650a1f987
|
||||
|
||||
@@ -69,6 +69,8 @@ Every call returns `RunResult`, including the receiving `session_id`, root event
|
||||
|
||||
Content-block arrays use the same command routing as strings. Both `session.run([{"type": "text", "text": "/compact"}])` and `session.run("/compact")` invoke native compaction and return `RunResult`. To bypass native command routing, call the low-level `client.session_prompt(session_id, blocks)` and manage subsequent activity; runtime skill recognition still applies.
|
||||
|
||||
Pass the user's zone as `time_zone`, for example `session.run("When is noon tomorrow?", time_zone="Asia/Shanghai")`; `harness.run()` and `client.session_prompt()` accept the same keyword and send it as the `timeZone` wire field. The value is `UTC` or an IANA Area/Location name; the runtime rejects any other value with `JsonRpcError` before running input. Without it, the runtime samples its own process zone for each prompt. Native commands record no zone.
|
||||
|
||||
Select a model that supports image input. Submit a command and image in the existing content-block array, for example `session.run([{"type": "text", "text": "/plan Analyze this image."}, {"type": "image", "data": image_base64, "mimeType": "image/png"}])`; `harness.run()` accepts the same input. Plan input and goal creation or editing accept images; `/plan off`, goal controls, compact, and permission commands reject them through the [native attachment rules](../../packages/sdk/server/README.md#command-input). Native command input supports encoded raster images, not general file uploads or client-supplied attachment references.
|
||||
|
||||
Each call subscribes before sending and releases its subscription before returning or raising. `on_notification` receives the input's Session-tree activity in wire order; the interval can include overlapping work. Calls may overlap without consuming each other's results. Native refusals return `finish_reason="error"`; routing, protocol, transport and observer failures raise. Malformed native-command responses raise `SdkProtocolError`, retaining their validation cause. A timeout or observer failure does not roll back runtime work or authorize an automatic retry. `request_timeout_seconds` bounds the protocol response wait, not later input activity.
|
||||
|
||||
@@ -69,6 +69,8 @@ with DeepSeekHarness(dsh_home="/absolute/path/to/saved-home") as harness:
|
||||
|
||||
内容块数组与字符串使用相同的命令路由。`session.run([{"type": "text", "text": "/compact"}])` 和 `session.run("/compact")` 都调用原生压缩并返回 `RunResult`。要绕过原生命令路由,调用底层 `client.session_prompt(session_id, blocks)` 并管理后续活动;运行时 skill(技能)识别仍然适用。
|
||||
|
||||
以 `time_zone` 传入用户时区,例如 `session.run("When is noon tomorrow?", time_zone="Asia/Shanghai")`;`harness.run()` 与 `client.session_prompt()` 接受同一关键字参数,并以 `timeZone` 协议字段发送。取值为 `UTC` 或 IANA Area/Location 名称;其他取值会在执行输入前被运行时以 `JsonRpcError` 拒绝。不传时,运行时为每条 prompt 采样自身进程时区。原生命令不记录时区。
|
||||
|
||||
先选择支持图片输入的模型。通过现有内容块数组同时提交命令和图片,例如 `session.run([{"type": "text", "text": "/plan Analyze this image."}, {"type": "image", "data": image_base64, "mimeType": "image/png"}])`;`harness.run()` 接受相同输入。计划输入和目标创建、编辑接受图片;`/plan off`、目标控制、压缩和权限命令按[原生附件规则](../../packages/sdk/server/README.zh.md#command-input)拒绝图片。原生命令输入支持编码栅格图片,不支持一般文件上传或客户端提供的附件引用。
|
||||
|
||||
每次调用在发送前订阅,并在返回或抛出异常前释放订阅。`on_notification` 按传输顺序接收本次输入的会话树活动;区间可以包含重叠工作。调用可以重叠,不会消耗彼此的结果。原生拒绝返回 `finish_reason="error"`;路由、协议、传输和观察回调失败则抛出异常。格式错误的原生命令响应抛出 `SdkProtocolError`,保留校验原因。超时或观察回调失败不回滚运行时工作,也不授权自动重试。`request_timeout_seconds` 限制协议响应等待,不限制之后的输入活动。
|
||||
|
||||
@@ -193,9 +193,10 @@ class DeepSeekHarness:
|
||||
*,
|
||||
session_id: str | None = None,
|
||||
on_notification: Callable[[Notification], None] | None = None,
|
||||
time_zone: str | None = None,
|
||||
) -> RunResult:
|
||||
"""Run input to completion on a fresh or named Session and return its RunResult."""
|
||||
return self.start_session(session_id).run(input, on_notification=on_notification)
|
||||
return self.start_session(session_id).run(input, on_notification=on_notification, time_zone=time_zone)
|
||||
|
||||
|
||||
class Session:
|
||||
@@ -218,6 +219,7 @@ class Session:
|
||||
input: str | list[JsonObject],
|
||||
*,
|
||||
on_notification: Callable[[Notification], None] | None = None,
|
||||
time_zone: str | None = None,
|
||||
) -> RunResult:
|
||||
"""Run text or content blocks through native input routing.
|
||||
|
||||
@@ -232,11 +234,14 @@ class Session:
|
||||
wire order. Every result retains this Session id, its root events and
|
||||
Session-tree notifications, including overlapping work. Native refusals
|
||||
return finish_reason="error". Routing, transport and observer failures
|
||||
raise without rolling back work.
|
||||
raise without rolling back work. ``time_zone`` is the user zone for an
|
||||
ordinary prompt, UTC or an IANA Area/Location name; omitted, the runtime
|
||||
samples its process zone. Native commands record no zone, and an invalid
|
||||
zone raises before routing.
|
||||
"""
|
||||
self.harness.start()
|
||||
with self.harness.client.subscribe_session_notifications(self.id) as subscription:
|
||||
response = self.harness.client._query(self.id, input)
|
||||
response = self.harness.client._query(self.id, input, time_zone)
|
||||
if isinstance(response, CommandExecution):
|
||||
activity = _RunActivity(self.id, "command", response.command_id)
|
||||
while True:
|
||||
|
||||
@@ -205,8 +205,15 @@ class HarnessClient:
|
||||
*,
|
||||
on_notification: Callable[[Notification], None] | None = None,
|
||||
notification_subscription: "NotificationSubscription | None" = None,
|
||||
time_zone: str | None = None,
|
||||
) -> str:
|
||||
"""Queue one prompt without command routing and return its message id.
|
||||
|
||||
``time_zone`` is UTC or an IANA Area/Location name; omitted, the runtime samples its process zone.
|
||||
"""
|
||||
payload: JsonObject = {"sessionId": session_id, "contentBlocks": content_blocks}
|
||||
if time_zone is not None:
|
||||
payload["timeZone"] = time_zone
|
||||
response = self.request(
|
||||
"session/prompt",
|
||||
payload,
|
||||
@@ -235,13 +242,14 @@ class HarnessClient:
|
||||
)
|
||||
|
||||
def _query(
|
||||
self, session_id: str, input: str | list[JsonObject],
|
||||
self, session_id: str, input: str | list[JsonObject], time_zone: str | None = None,
|
||||
) -> str | CommandExecution:
|
||||
"""Return a validated prompt receipt or command result for high-level run callers."""
|
||||
blocks = [{"type": "text", "text": input}] if isinstance(input, str) else input
|
||||
result = self._request_raw("session/query", {
|
||||
"sessionId": session_id, "contentBlocks": blocks,
|
||||
})
|
||||
params: JsonObject = {"sessionId": session_id, "contentBlocks": blocks}
|
||||
if time_zone is not None:
|
||||
params["timeZone"] = time_zone
|
||||
result = self._request_raw("session/query", params)
|
||||
if isinstance(result, dict):
|
||||
if result.get("kind") == "prompt" and isinstance(result.get("messageId"), str) and result["messageId"]:
|
||||
return result["messageId"]
|
||||
|
||||
@@ -24,7 +24,7 @@ def test_account_provider_signout_snapshot(tmp_path: Path) -> None:
|
||||
model='deepseek-v4-flash',
|
||||
env={'DSH_TELEMETRY_DISABLED': '1', 'DSH_SNAPSHOT': 'replay'},
|
||||
) as harness:
|
||||
result = harness.run('Reply with exactly: SDK snapshot')
|
||||
result = harness.run('Reply with exactly: SDK snapshot', time_zone='UTC')
|
||||
ending = next(event for event in reversed(result.events) if event['type'] == 'turn/end')
|
||||
actual = {
|
||||
'final_response': result.final_response,
|
||||
|
||||
@@ -74,7 +74,7 @@ for line in sys.stdin:
|
||||
elif method == "session/query":
|
||||
serial += 1
|
||||
params = frame["params"]
|
||||
assert set(params) == {"sessionId", "contentBlocks"}
|
||||
assert set(params) - {"timeZone"} == {"sessionId", "contentBlocks"}
|
||||
text = input_text(frame)
|
||||
if text == "/plan hold":
|
||||
identity = "plan-" + str(serial)
|
||||
@@ -452,3 +452,30 @@ def test_low_level_prompt_keeps_slash_text_as_an_ordinary_prompt(sdk: DeepSeekHa
|
||||
sent = [json.loads(line) for line in (tmp_path / "requests.jsonl").read_text(encoding="utf-8").splitlines()]
|
||||
assert sent[-1]["method"] == "session/prompt"
|
||||
assert sent[-1]["params"] == {"sessionId": "main", "contentBlocks": blocks}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("entry", ["session", "harness"])
|
||||
def test_run_sends_its_prompt_time_zone_as_the_time_zone_wire_field(
|
||||
sdk: DeepSeekHarness, tmp_path: Path, entry: str,
|
||||
) -> None:
|
||||
result = (sdk.run("ordinary", session_id="main", time_zone="Asia/Shanghai")
|
||||
if entry == "harness" else sdk.start_session("main").run("ordinary", time_zone="Asia/Shanghai"))
|
||||
assert isinstance(result, RunResult)
|
||||
sdk.start_session("main").run("ordinary")
|
||||
sent = [json.loads(line) for line in (tmp_path / "requests.jsonl").read_text(encoding="utf-8").splitlines()]
|
||||
assert [frame["params"] for frame in sent if frame["method"] == "session/query"] == [
|
||||
{"sessionId": "main", "contentBlocks": [{"type": "text", "text": "ordinary"}], "timeZone": "Asia/Shanghai"},
|
||||
{"sessionId": "main", "contentBlocks": [{"type": "text", "text": "ordinary"}]},
|
||||
]
|
||||
assert_released(sdk)
|
||||
|
||||
|
||||
def test_low_level_prompt_sends_its_time_zone_as_the_time_zone_wire_field(sdk: DeepSeekHarness, tmp_path: Path) -> None:
|
||||
blocks = [{"type": "text", "text": "when is noon?"}]
|
||||
sdk.client.session_prompt("main", blocks, time_zone="UTC")
|
||||
sdk.client.session_prompt("main", blocks)
|
||||
sent = [json.loads(line) for line in (tmp_path / "requests.jsonl").read_text(encoding="utf-8").splitlines()]
|
||||
assert [frame["params"] for frame in sent if frame["method"] == "session/prompt"] == [
|
||||
{"sessionId": "main", "contentBlocks": blocks, "timeZone": "UTC"},
|
||||
{"sessionId": "main", "contentBlocks": blocks},
|
||||
]
|
||||
Reference in new issue
Block a user