bailinghub 0.10.0 → 0.10.1
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.
- package/README.en.md +6 -6
- package/README.md +6 -6
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/docker-compose.images.yml +2 -2
- package/docs/CHANGELOG.en.md +12 -1
- package/docs/CHANGELOG.md +12 -1
- package/docs/IMPLEMENTATION_STATUS.en.md +12 -3
- package/docs/IMPLEMENTATION_STATUS.md +12 -3
- package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
- package/docs/INDEPENDENT_VALIDATION.md +4 -4
- package/docs/README.en.md +2 -0
- package/docs/README.md +2 -0
- package/docs/RELEASE_NOTES_v0.10.1.en.md +41 -0
- package/docs/RELEASE_NOTES_v0.10.1.md +41 -0
- package/docs/UPGRADE_v0.10.1.en.md +66 -0
- package/docs/UPGRADE_v0.10.1.md +66 -0
- package/package.json +5 -3
- package/scripts/check-doc-links.mjs +2 -0
- package/scripts/check-image-tags.sh +1 -1
- package/scripts/check-php-sdk-artifacts.mjs +152 -0
- package/scripts/check-php-sdk-artifacts.test.mjs +99 -0
- package/scripts/check-release-consistency.test.mjs +2 -2
- package/scripts/install.sh +1 -1
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +5 -1
- package/scripts/sdk-declaration-contract-test.ts +34 -0
- package/scripts/sdk-p1-check.mjs +62 -26
- package/scripts/verify-github-repo.mjs +4 -0
- package/sdk/dotnet/Bailing.Connect/BailingConnect.cs +4 -4
- package/sdk/dotnet/README.md +8 -0
- package/sdk/dotnet/tests/Declaration/Declaration.csproj +11 -0
- package/sdk/dotnet/tests/Declaration/Program.cs +74 -0
- package/sdk/go/README.md +8 -0
- package/sdk/go/bailingconnect/connect.go +5 -5
- package/sdk/go/bailingconnect/declaration_test.go +107 -0
- package/sdk/java/README.md +13 -0
- package/sdk/java/src/main/java/com/bailing/connect/BailingConnect.java +4 -4
- package/sdk/java/tests/DeclarationTest.java +70 -0
- package/sdk/node/README.md +8 -0
- package/sdk/node/src/index.mjs +4 -4
- package/sdk/node/tests/declaration.test.mjs +41 -0
- package/sdk/php/README.md +16 -0
- package/sdk/php/src/Attributes/AiTool.php +4 -4
- package/sdk/php/src/SpecBuilder.php +8 -8
- package/sdk/php/tests/declaration-serialization.php +103 -0
- package/sdk/php7/README.md +14 -0
- package/sdk/php7/src/ToolDef.php +3 -3
- package/sdk/php7/src/ToolSpec.php +8 -13
- package/sdk/php7/tests/declaration-serialization.php +103 -0
- package/sdk/python/README.md +8 -0
- package/sdk/python/bailing_connect/__init__.py +6 -6
- package/sdk/python/tests/test_declaration.py +61 -0
- package/src/core/contracts/explicit-capability-values.test.ts +62 -0
- package/src/core/contracts/openapi-tools.ts +2 -2
- package/src/core/contracts/tool-annotations.ts +4 -4
- package/web/connect/bailing-connect-php.tgz +0 -0
- package/web/connect/bailing-connect-php7.tgz +0 -0
- package/web-admin/package-lock.json +4 -4
- package/web-admin/package.json +1 -1
package/sdk/php7/src/ToolDef.php
CHANGED
|
@@ -35,7 +35,7 @@ final class ToolDef
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// ---- 治理面 ----
|
|
38
|
-
/**
|
|
38
|
+
/** 显式风险级 low / medium / high;不调用时省略,由 ACC 及 binding 缺省规则推导。 */
|
|
39
39
|
public function risk($level)
|
|
40
40
|
{
|
|
41
41
|
$this->opt['risk'] = $level;
|
|
@@ -68,13 +68,13 @@ final class ToolDef
|
|
|
68
68
|
$this->opt['sensitive'] = (bool) $v;
|
|
69
69
|
return $this;
|
|
70
70
|
}
|
|
71
|
-
/**
|
|
71
|
+
/** 显式只读声明,true/false 均保留;不调用时由 binding 解释 GET 等缺省信号。 */
|
|
72
72
|
public function readonly($v = true)
|
|
73
73
|
{
|
|
74
74
|
$this->opt['readonly'] = (bool) $v;
|
|
75
75
|
return $this;
|
|
76
76
|
}
|
|
77
|
-
/**
|
|
77
|
+
/** 显式幂等提示,true/false 均保留;未设置时省略,不替运行时决定重试。 */
|
|
78
78
|
public function idempotent($v = true)
|
|
79
79
|
{
|
|
80
80
|
$this->opt['idempotent'] = (bool) $v;
|
|
@@ -110,9 +110,8 @@ final class ToolSpec
|
|
|
110
110
|
if (trim((string) $d->name) === '') {
|
|
111
111
|
throw new InvalidArgumentException("path {$d->path}: 工具名(第 1 个参数)不能为空");
|
|
112
112
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
throw new InvalidArgumentException("{$where}: risk 仅支持 low/medium/high,收到 {$risk}");
|
|
113
|
+
if (isset($d->opt['risk']) && !in_array($d->opt['risk'], array('low', 'medium', 'high'), true)) {
|
|
114
|
+
throw new InvalidArgumentException("{$where}: risk 仅支持 low/medium/high,收到 {$d->opt['risk']}");
|
|
116
115
|
}
|
|
117
116
|
if (isset($d->opt['rateLimit']) && self::parseRateLimit($d->opt['rateLimit']) === null) {
|
|
118
117
|
throw new InvalidArgumentException("{$where}: rateLimit 格式应为 \"30/min\"、\"600/hour\"、\"10/s\" 或 \"1000/day\",收到 {$d->opt['rateLimit']}");
|
|
@@ -195,11 +194,9 @@ final class ToolSpec
|
|
|
195
194
|
private function buildCapability(ToolDef $d)
|
|
196
195
|
{
|
|
197
196
|
$o = $d->opt;
|
|
198
|
-
$method = $d->method;
|
|
199
197
|
$capability = array('version' => 1, 'enabled' => true, 'scope' => $d->scope);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
$capability['risk'] = array('level' => $risk);
|
|
198
|
+
if (isset($o['risk'])) {
|
|
199
|
+
$capability['risk'] = array('level' => $o['risk']);
|
|
203
200
|
}
|
|
204
201
|
if (!empty($o['confirm']) || !empty($o['confirmWhen']) || isset($o['confirmPrompt'])) {
|
|
205
202
|
$approval = array();
|
|
@@ -218,13 +215,11 @@ final class ToolSpec
|
|
|
218
215
|
$capability['subject'] = array('required' => true);
|
|
219
216
|
}
|
|
220
217
|
$execution = array();
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
$execution['readonly'] = true;
|
|
218
|
+
if (array_key_exists('readonly', $o)) {
|
|
219
|
+
$execution['readonly'] = $o['readonly'];
|
|
224
220
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
$execution['idempotent'] = true;
|
|
221
|
+
if (array_key_exists('idempotent', $o)) {
|
|
222
|
+
$execution['idempotent'] = $o['idempotent'];
|
|
228
223
|
}
|
|
229
224
|
if (isset($o['rateLimit'])) {
|
|
230
225
|
$rateLimit = self::parseRateLimit($o['rateLimit']);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
// Run with PHP >= 7.3. An optional SDK root verifies an extracted distribution:
|
|
4
|
+
// php tests/declaration-serialization.php /path/to/bailing-connect-php7
|
|
5
|
+
$sdkRoot = isset($argv[1]) ? rtrim($argv[1], '/\\') : dirname(__DIR__);
|
|
6
|
+
require_once $sdkRoot . '/src/ToolDef.php';
|
|
7
|
+
require_once $sdkRoot . '/src/ToolSpec.php';
|
|
8
|
+
|
|
9
|
+
use Bailing\Connect\ToolDef;
|
|
10
|
+
use Bailing\Connect\ToolSpec;
|
|
11
|
+
|
|
12
|
+
$checks = 0;
|
|
13
|
+
$errors = array();
|
|
14
|
+
$matrix = array();
|
|
15
|
+
$idempotence = array();
|
|
16
|
+
|
|
17
|
+
function serializationCheck($condition, $label)
|
|
18
|
+
{
|
|
19
|
+
global $checks, $errors;
|
|
20
|
+
$checks++;
|
|
21
|
+
if (!$condition) {
|
|
22
|
+
$errors[] = $label;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function generatedCapability($method, $readonly, $risk, $idempotent = null, $governance = false)
|
|
27
|
+
{
|
|
28
|
+
$builder = ToolSpec::create('Synthetic declaration regression')->tool(
|
|
29
|
+
'serialization_case', $method, '/serialization-case', 'example.record.read',
|
|
30
|
+
'Synthetic declaration regression case',
|
|
31
|
+
function (ToolDef $tool) use ($method, $readonly, $risk, $idempotent, $governance) {
|
|
32
|
+
if ($method === 'GET') {
|
|
33
|
+
$tool->query('record_id', 'integer', true);
|
|
34
|
+
} else {
|
|
35
|
+
$tool->body('record_id', 'integer', true);
|
|
36
|
+
}
|
|
37
|
+
if ($readonly !== null) $tool->readonly($readonly);
|
|
38
|
+
if ($risk !== null) $tool->risk($risk);
|
|
39
|
+
if ($idempotent !== null) $tool->idempotent($idempotent);
|
|
40
|
+
if ($governance) {
|
|
41
|
+
$tool->requiresSubject()->confirm('Approve {record_id}')->confirmWhen(array(
|
|
42
|
+
array('param' => 'record_id', 'op' => '>', 'value' => 100),
|
|
43
|
+
));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
// Test the actual JSON wire output, not a copied private serialization function.
|
|
48
|
+
$spec = json_decode($builder->buildJson(false), true);
|
|
49
|
+
if (!is_array($spec) || !isset($spec['paths']['/serialization-case'][strtolower($method)]['x-agent-capability'])) {
|
|
50
|
+
throw new RuntimeException('Generator did not emit a valid ACC operation');
|
|
51
|
+
}
|
|
52
|
+
return $spec['paths']['/serialization-case'][strtolower($method)]['x-agent-capability'];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
foreach (array('GET', 'POST') as $method) {
|
|
56
|
+
foreach (array(null, false, true) as $readonly) {
|
|
57
|
+
foreach (array(null, 'low', 'medium', 'high') as $risk) {
|
|
58
|
+
$capability = generatedCapability($method, $readonly, $risk);
|
|
59
|
+
$execution = isset($capability['execution']) ? $capability['execution'] : array();
|
|
60
|
+
$label = $method . '/readonly=' . json_encode($readonly) . '/risk=' . json_encode($risk);
|
|
61
|
+
serializationCheck($capability['version'] === 1 && $capability['enabled'] === true && $capability['scope'] === 'example.record.read', $label . ': declaration identity');
|
|
62
|
+
serializationCheck(array_key_exists('risk', $capability) === ($risk !== null), $label . ': risk presence');
|
|
63
|
+
if ($risk !== null) serializationCheck(isset($capability['risk']['level']) && $capability['risk']['level'] === $risk, $label . ': risk value');
|
|
64
|
+
serializationCheck(array_key_exists('readonly', $execution) === ($readonly !== null), $label . ': readonly presence');
|
|
65
|
+
if ($readonly !== null) serializationCheck(array_key_exists('readonly', $execution) && $execution['readonly'] === $readonly, $label . ': readonly value');
|
|
66
|
+
serializationCheck(!array_key_exists('idempotent', $execution), $label . ': unset idempotent remains omitted');
|
|
67
|
+
|
|
68
|
+
// ACC v1 + OpenAPI binding: explicit values win; GET is only a fallback.
|
|
69
|
+
$expectedReadonly = $readonly === null ? $method === 'GET' : $readonly;
|
|
70
|
+
$expectedRisk = $risk === null ? ($expectedReadonly ? 'low' : 'medium') : $risk;
|
|
71
|
+
$wireReadonly = array_key_exists('readonly', $execution) ? $execution['readonly'] : $method === 'GET';
|
|
72
|
+
$effectiveRisk = isset($capability['risk']['level']) ? $capability['risk']['level'] : ($wireReadonly ? 'low' : 'medium');
|
|
73
|
+
serializationCheck($effectiveRisk === $expectedRisk, $label . ': effective risk');
|
|
74
|
+
$matrix[] = array('method' => $method, 'readonly' => $readonly, 'risk' => $risk, 'capability' => $capability, 'expectedRisk' => $expectedRisk, 'effectiveRisk' => $effectiveRisk);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
foreach (array(null, false, true) as $idempotent) {
|
|
78
|
+
$capability = generatedCapability($method, null, null, $idempotent);
|
|
79
|
+
$execution = isset($capability['execution']) ? $capability['execution'] : array();
|
|
80
|
+
$label = $method . '/idempotent=' . json_encode($idempotent);
|
|
81
|
+
serializationCheck(array_key_exists('idempotent', $execution) === ($idempotent !== null), $label . ': presence');
|
|
82
|
+
if ($idempotent !== null) serializationCheck(array_key_exists('idempotent', $execution) && $execution['idempotent'] === $idempotent, $label . ': value');
|
|
83
|
+
serializationCheck(!array_key_exists('risk', $capability) && !array_key_exists('readonly', $execution), $label . ': unrelated unset fields remain omitted');
|
|
84
|
+
$idempotence[] = array('method' => $method, 'idempotent' => $idempotent, 'capability' => $capability);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
$governance = generatedCapability('POST', false, 'low', false, true);
|
|
89
|
+
serializationCheck($governance === array(
|
|
90
|
+
'version' => 1, 'enabled' => true, 'scope' => 'example.record.read',
|
|
91
|
+
'risk' => array('level' => 'low'),
|
|
92
|
+
'approval' => array('required' => true, 'when' => array(array('param' => 'record_id', 'op' => '>', 'value' => 100)), 'prompt' => 'Approve {record_id}'),
|
|
93
|
+
'subject' => array('required' => true),
|
|
94
|
+
'execution' => array('readonly' => false, 'idempotent' => false),
|
|
95
|
+
), 'explicit low and false do not remove approval or subject requirements');
|
|
96
|
+
|
|
97
|
+
echo json_encode(array(
|
|
98
|
+
'sdk' => 'php7', 'phpVersion' => PHP_VERSION,
|
|
99
|
+
'matrixCases' => count($matrix), 'idempotenceCases' => count($idempotence),
|
|
100
|
+
'checks' => $checks, 'passed' => !$errors, 'errors' => $errors,
|
|
101
|
+
'matrix' => $matrix, 'idempotence' => $idempotence,
|
|
102
|
+
), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
|
103
|
+
exit($errors ? 1 : 0);
|
package/sdk/python/README.md
CHANGED
|
@@ -105,3 +105,11 @@ job = hub.run(
|
|
|
105
105
|
result = hub.get_job(job["job_id"])
|
|
106
106
|
hub.send("notice_1001", "team-im", "user_001", "任务已完成")
|
|
107
107
|
```
|
|
108
|
+
|
|
109
|
+
## 声明字段的省略与显式值
|
|
110
|
+
|
|
111
|
+
未设置的 `risk`、`readonly`、`idempotent` 不会写入 ACC 声明。显式的 `risk: low/medium/high` 和布尔值 `false/true` 都会保留,包括 GET 上的 `false`。省略风险时,按 ACC OpenAPI binding:显式只读优先于 HTTP 方法;未声明只读的 GET 默认 low,其余非只读操作默认 medium。风险声明不代替审批或业务最终授权。
|
|
112
|
+
|
|
113
|
+
升级后应重新生成声明并比较差异;不要把以前省略的字段一律补成 low。 `tool()["risk"]` 在未设置时现在为 `None`,不再是 `"low"`;直接读取构建中间对象的调用方需兼容未设置状态。
|
|
114
|
+
|
|
115
|
+
回归:`python3 sdk/python/tests/test_declaration.py`(24种只读/风险组合及6种幂等组合)。
|
|
@@ -85,7 +85,7 @@ def tool(**opts):
|
|
|
85
85
|
"path": opts["path"],
|
|
86
86
|
"method": str(opts.get("method", "GET")).upper(),
|
|
87
87
|
"name": opts.get("name"),
|
|
88
|
-
"risk": opts.get("risk"
|
|
88
|
+
"risk": opts.get("risk"),
|
|
89
89
|
"confirm": bool(opts.get("confirm", False)),
|
|
90
90
|
"confirmWhen": opts.get("confirmWhen", []),
|
|
91
91
|
"readonly": opts.get("readonly"),
|
|
@@ -130,7 +130,7 @@ def _normalize_rate_limit(value: Any) -> Optional[Dict[str, Any]]:
|
|
|
130
130
|
|
|
131
131
|
def _build_capability(t: Dict[str, Any], method: str) -> Dict[str, Any]:
|
|
132
132
|
capability: Dict[str, Any] = {"version": 1, "enabled": True, "scope": t["scope"]}
|
|
133
|
-
if t.get("risk")
|
|
133
|
+
if t.get("risk") is not None:
|
|
134
134
|
capability["risk"] = {"level": t["risk"]}
|
|
135
135
|
if t.get("confirm") or t.get("confirmWhen") or t.get("confirmPrompt"):
|
|
136
136
|
approval: Dict[str, Any] = {}
|
|
@@ -144,10 +144,10 @@ def _build_capability(t: Dict[str, Any], method: str) -> Dict[str, Any]:
|
|
|
144
144
|
if t.get("requiresSubject"):
|
|
145
145
|
capability["subject"] = {"required": True}
|
|
146
146
|
execution: Dict[str, Any] = {}
|
|
147
|
-
if t.get("readonly")
|
|
148
|
-
execution["readonly"] =
|
|
149
|
-
if t.get("idempotent")
|
|
150
|
-
execution["idempotent"] =
|
|
147
|
+
if isinstance(t.get("readonly"), bool):
|
|
148
|
+
execution["readonly"] = t["readonly"]
|
|
149
|
+
if isinstance(t.get("idempotent"), bool):
|
|
150
|
+
execution["idempotent"] = t["idempotent"]
|
|
151
151
|
rate_limit = _normalize_rate_limit(t.get("rateLimit"))
|
|
152
152
|
if rate_limit:
|
|
153
153
|
execution["rate_limit"] = rate_limit
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Exercise the public builder and its actual JSON output, without business calls."""
|
|
2
|
+
import json
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import sys
|
|
5
|
+
import unittest
|
|
6
|
+
|
|
7
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
8
|
+
from bailing_connect import build_openapi_spec, param, tool
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def capability(method, options):
|
|
12
|
+
spec = build_openapi_spec(tools=[tool(
|
|
13
|
+
name="serialization_fixture", description="Declaration serialization fixture",
|
|
14
|
+
path="/fixture", scope="fixture.write", method=method,
|
|
15
|
+
params=[param("fixture", type="string")], **options)])
|
|
16
|
+
return json.loads(json.dumps(spec))["paths"]["/fixture"][method.lower()]["x-agent-capability"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class DeclarationTests(unittest.TestCase):
|
|
20
|
+
def test_readonly_risk_matrix(self):
|
|
21
|
+
combinations = 0
|
|
22
|
+
for method in ("GET", "POST"):
|
|
23
|
+
for readonly in (None, False, True):
|
|
24
|
+
for risk in (None, "low", "medium", "high"):
|
|
25
|
+
combinations += 1
|
|
26
|
+
with self.subTest(method=method, readonly=readonly, risk=risk):
|
|
27
|
+
options = {}
|
|
28
|
+
if readonly is not None:
|
|
29
|
+
options["readonly"] = readonly
|
|
30
|
+
if risk is not None:
|
|
31
|
+
options["risk"] = risk
|
|
32
|
+
cap = capability(method, options)
|
|
33
|
+
self.assertEqual("readonly" in cap.get("execution", {}), readonly is not None)
|
|
34
|
+
if readonly is not None:
|
|
35
|
+
self.assertIs(cap["execution"]["readonly"], readonly)
|
|
36
|
+
self.assertEqual("risk" in cap, risk is not None)
|
|
37
|
+
if risk is not None:
|
|
38
|
+
self.assertEqual(cap["risk"]["level"], risk)
|
|
39
|
+
expected_readonly = readonly if readonly is not None else method == "GET"
|
|
40
|
+
expected_risk = risk if risk is not None else ("low" if expected_readonly else "medium")
|
|
41
|
+
actual_readonly = cap.get("execution", {}).get("readonly", method == "GET")
|
|
42
|
+
actual_risk = cap.get("risk", {}).get("level", "low" if actual_readonly else "medium")
|
|
43
|
+
self.assertEqual(actual_risk, expected_risk)
|
|
44
|
+
self.assertEqual(cap["version"], 1)
|
|
45
|
+
self.assertEqual(combinations, 24)
|
|
46
|
+
|
|
47
|
+
def test_idempotent_presence_and_value(self):
|
|
48
|
+
combinations = 0
|
|
49
|
+
for method in ("GET", "POST"):
|
|
50
|
+
for value in (None, False, True):
|
|
51
|
+
combinations += 1
|
|
52
|
+
with self.subTest(method=method, idempotent=value):
|
|
53
|
+
cap = capability(method, {} if value is None else {"idempotent": value})
|
|
54
|
+
self.assertEqual("idempotent" in cap.get("execution", {}), value is not None)
|
|
55
|
+
if value is not None:
|
|
56
|
+
self.assertIs(cap["execution"]["idempotent"], value)
|
|
57
|
+
self.assertEqual(combinations, 6)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if __name__ == "__main__":
|
|
61
|
+
unittest.main()
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { compileOpenApiTools } from './openapi-tools';
|
|
4
|
+
|
|
5
|
+
function compile(method: string, capability: Record<string, unknown>) {
|
|
6
|
+
const result = compileOpenApiTools(JSON.stringify({
|
|
7
|
+
openapi: '3.0.0',
|
|
8
|
+
info: { title: 'Explicit capability values', version: '1' },
|
|
9
|
+
paths: {
|
|
10
|
+
'/fixture': {
|
|
11
|
+
[method.toLowerCase()]: {
|
|
12
|
+
operationId: 'fixture_operation',
|
|
13
|
+
summary: 'Isolated declaration fixture',
|
|
14
|
+
parameters: [{ name: 'id', in: 'query', schema: { type: 'string' } }],
|
|
15
|
+
'x-agent-capability': { version: 1, enabled: true, scope: 'fixture.operation', ...capability },
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
}));
|
|
20
|
+
assert.equal(result.diagnostics.filter(d => d.severity === 'error').length, 0);
|
|
21
|
+
assert.equal(result.tools.length, 1);
|
|
22
|
+
return result.tools[0]!;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
for (const method of ['GET', 'POST']) {
|
|
26
|
+
for (const readonly of [undefined, false, true]) {
|
|
27
|
+
for (const risk of [undefined, 'low', 'medium', 'high']) {
|
|
28
|
+
test(`ACC explicit values: ${method}, readonly=${readonly}, risk=${risk}`, () => {
|
|
29
|
+
const tool = compile(method, {
|
|
30
|
+
...(readonly === undefined ? {} : { execution: { readonly } }),
|
|
31
|
+
...(risk === undefined ? {} : { risk: { level: risk } }),
|
|
32
|
+
});
|
|
33
|
+
const expectedReadonly = readonly ?? (method === 'GET');
|
|
34
|
+
assert.equal(tool.readonly, expectedReadonly);
|
|
35
|
+
assert.equal(tool.risk, risk ?? (expectedReadonly ? 'low' : 'medium'));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const idempotent of [undefined, false, true]) {
|
|
40
|
+
test(`ACC explicit idempotency: ${method}, idempotent=${idempotent}`, () => {
|
|
41
|
+
const tool = compile(method, idempotent === undefined ? {} : { execution: { idempotent } });
|
|
42
|
+
assert.equal(tool.idempotent, idempotent ?? (method === 'GET'));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
test('Explicit low risk does not erase approval or subject requirements', () => {
|
|
48
|
+
const conditions = [{ param: 'id', op: '==', value: 'review' }];
|
|
49
|
+
const tool = compile('POST', {
|
|
50
|
+
risk: { level: 'low' },
|
|
51
|
+
execution: { readonly: false, idempotent: false },
|
|
52
|
+
approval: { required: true, when: conditions, prompt: 'Review this operation' },
|
|
53
|
+
subject: { required: true },
|
|
54
|
+
audit: { sensitive: true },
|
|
55
|
+
});
|
|
56
|
+
assert.equal(tool.risk, 'low');
|
|
57
|
+
assert.equal(tool.confirmRequired, true);
|
|
58
|
+
assert.deepEqual(tool.confirmWhen, conditions);
|
|
59
|
+
assert.equal(tool.confirmPrompt, 'Review this operation');
|
|
60
|
+
assert.equal(tool.requiresSubject, true);
|
|
61
|
+
assert.equal(tool.sensitive, true);
|
|
62
|
+
});
|
|
@@ -129,7 +129,7 @@ export function compileOpenApiTools(specText: string): ToolCompileResult {
|
|
|
129
129
|
const confirmWhen = parseConfirmWhen(ann.confirmWhen, loc, diagnostics);
|
|
130
130
|
if (confirmWhen === null) continue;
|
|
131
131
|
|
|
132
|
-
const ro = m === 'GET'
|
|
132
|
+
const ro = ann.readonly ?? (m === 'GET');
|
|
133
133
|
const inputSchema = { type: 'object', properties: props, ...(required.length ? { required: [...new Set(required)] } : {}) };
|
|
134
134
|
const tool: ToolDefinition = {
|
|
135
135
|
schemaVersion: TOOL_DEFINITION_SCHEMA_VERSION,
|
|
@@ -148,7 +148,7 @@ export function compileOpenApiTools(specText: string): ToolCompileResult {
|
|
|
148
148
|
requiresSubject: ann.requiresSubject,
|
|
149
149
|
sensitive: ann.sensitive,
|
|
150
150
|
readonly: ro,
|
|
151
|
-
idempotent: m === 'GET'
|
|
151
|
+
idempotent: ann.idempotent ?? (m === 'GET'),
|
|
152
152
|
timeoutMs: ann.timeoutMs,
|
|
153
153
|
...(confirmWhen.length ? { confirmWhen } : {}),
|
|
154
154
|
confirmPrompt: ann.confirmPrompt,
|
|
@@ -52,8 +52,8 @@ export function toolAnnotationsOf(op: Record<string, unknown>): ToolAnnotations
|
|
|
52
52
|
rateLimitPerMin: rateLimit ? rateLimitToPerMin(rateLimit) : 0,
|
|
53
53
|
requiresSubject: subject?.['required'] === true,
|
|
54
54
|
sensitive: audit?.['sensitive'] === true,
|
|
55
|
-
readonly: execution?.['readonly'] ===
|
|
56
|
-
idempotent: execution?.['idempotent'] ===
|
|
55
|
+
readonly: typeof execution?.['readonly'] === 'boolean' ? execution['readonly'] : null,
|
|
56
|
+
idempotent: typeof execution?.['idempotent'] === 'boolean' ? execution['idempotent'] : null,
|
|
57
57
|
timeoutPresent: !!execution && Object.hasOwn(execution, 'timeout_ms'),
|
|
58
58
|
timeoutRaw: execution?.['timeout_ms'],
|
|
59
59
|
timeoutMs: parseTimeout(execution?.['timeout_ms']),
|
|
@@ -67,10 +67,10 @@ export function toolAnnotationsOf(op: Record<string, unknown>): ToolAnnotations
|
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
export function deriveRisk(explicit: unknown,
|
|
70
|
+
export function deriveRisk(explicit: unknown, _method: string, readonly: boolean): ToolRisk {
|
|
71
71
|
const v = String(explicit ?? '').toLowerCase();
|
|
72
72
|
if (v === 'low' || v === 'medium' || v === 'high') return v;
|
|
73
|
-
return
|
|
73
|
+
return readonly ? 'low' : 'medium';
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
function parseRateLimit(v: unknown): ToolRateLimit | undefined {
|
|
Binary file
|
|
Binary file
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@vitejs/plugin-vue": "^5.2.1",
|
|
21
21
|
"typescript": "^5.7.2",
|
|
22
|
-
"vite": "^6.4.
|
|
22
|
+
"vite": "^6.4.5"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"node_modules/@babel/helper-string-parser": {
|
|
@@ -1679,9 +1679,9 @@
|
|
|
1679
1679
|
"license": "MIT"
|
|
1680
1680
|
},
|
|
1681
1681
|
"node_modules/vite": {
|
|
1682
|
-
"version": "6.4.
|
|
1683
|
-
"resolved": "https://registry.npmjs.org/vite/-/vite-6.4.
|
|
1684
|
-
"integrity": "sha512-
|
|
1682
|
+
"version": "6.4.5",
|
|
1683
|
+
"resolved": "https://registry.npmjs.org/vite/-/vite-6.4.5.tgz",
|
|
1684
|
+
"integrity": "sha512-4enwjFfi4IwtEh0w+jPzpLVOFQiPHmmzPxcHXQOyEur47o6u0jE573DmGpjA+7irXoMLYRZD5ZaFUEneS3abPg==",
|
|
1685
1685
|
"dev": true,
|
|
1686
1686
|
"license": "MIT",
|
|
1687
1687
|
"dependencies": {
|