licos-platform-cli 0.6.6__tar.gz → 0.7.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.
Files changed (21) hide show
  1. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/PKG-INFO +3 -3
  2. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/README.md +1 -1
  3. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/pyproject.toml +2 -2
  4. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/src/licos_platform_cli/help_commands.py +5 -1
  5. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/src/licos_platform_cli/ontology_commands.py +2 -0
  6. licos_platform_cli-0.7.0/src/licos_platform_cli/ontology_package_commands.py +133 -0
  7. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/tests/test_cli.py +1 -1
  8. licos_platform_cli-0.7.0/tests/test_ontology_packages.py +56 -0
  9. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/.gitignore +0 -0
  10. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/src/licos_platform_cli/__init__.py +0 -0
  11. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/src/licos_platform_cli/database_commands.py +0 -0
  12. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/src/licos_platform_cli/identity.py +0 -0
  13. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/src/licos_platform_cli/knowledge_commands.py +0 -0
  14. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/src/licos_platform_cli/main.py +0 -0
  15. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/src/licos_platform_cli/oauth_commands.py +0 -0
  16. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/src/licos_platform_cli/project_config_commands.py +0 -0
  17. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/src/licos_platform_cli/storage_commands.py +0 -0
  18. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/src/licos_platform_cli/user_commands.py +0 -0
  19. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/tests/test_identity.py +0 -0
  20. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/tests/test_project_config.py +0 -0
  21. {licos_platform_cli-0.6.6 → licos_platform_cli-0.7.0}/tests/test_user.py +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: licos-platform-cli
3
- Version: 0.6.6
3
+ Version: 0.7.0
4
4
  Summary: LICOS platform CLI
5
5
  Requires-Python: >=3.10
6
- Requires-Dist: licos-platform-sdk>=0.7.6
6
+ Requires-Dist: licos-platform-sdk>=0.8.0
7
7
  Description-Content-Type: text/markdown
8
8
 
9
9
  # licos-platform-cli
@@ -42,7 +42,7 @@ licos-platform user me --token-stdin
42
42
  | --- | --- | --- |
43
43
  | `user me` | 按 `LICOS_CURRENT_USER_ID` 换 Token | 使用 `--token-stdin` |
44
44
  | `knowledge enterprise …` | 按 `LICOS_CURRENT_USER_ID` 换 Token | 使用 `--token-stdin`,企业范围和权限由平台认证结果确定 |
45
- | `ontology search`、`ontology invoke` | 按 `LICOS_CURRENT_USER_ID` 换 Token | 使用 `--token-stdin` |
45
+ | 所有 `ontology` 命令 | 按 `LICOS_CURRENT_USER_ID` 换 Token | 使用 `--token-stdin` |
46
46
  | 普通 `knowledge …` | 项目身份 | 需要用户权限时使用 `--token-stdin` |
47
47
  | 数据库、对象存储、OAuth 应用管理 | 项目身份 | 保持项目身份 |
48
48
 
@@ -34,7 +34,7 @@ licos-platform user me --token-stdin
34
34
  | --- | --- | --- |
35
35
  | `user me` | 按 `LICOS_CURRENT_USER_ID` 换 Token | 使用 `--token-stdin` |
36
36
  | `knowledge enterprise …` | 按 `LICOS_CURRENT_USER_ID` 换 Token | 使用 `--token-stdin`,企业范围和权限由平台认证结果确定 |
37
- | `ontology search`、`ontology invoke` | 按 `LICOS_CURRENT_USER_ID` 换 Token | 使用 `--token-stdin` |
37
+ | 所有 `ontology` 命令 | 按 `LICOS_CURRENT_USER_ID` 换 Token | 使用 `--token-stdin` |
38
38
  | 普通 `knowledge …` | 项目身份 | 需要用户权限时使用 `--token-stdin` |
39
39
  | 数据库、对象存储、OAuth 应用管理 | 项目身份 | 保持项目身份 |
40
40
 
@@ -4,12 +4,12 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "licos-platform-cli"
7
- version = "0.6.6"
7
+ version = "0.7.0"
8
8
  description = "LICOS platform CLI"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
11
11
  dependencies = [
12
- "licos-platform-sdk>=0.7.6",
12
+ "licos-platform-sdk>=0.8.0",
13
13
  ]
14
14
 
15
15
  [project.scripts]
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
  import argparse
4
4
  from typing import Any, Callable
5
5
  from .user_commands import USER_HELP
6
+ from .ontology_package_commands import PACKAGE_HELP
6
7
 
7
8
 
8
9
  Handler = Callable[[argparse.Namespace], Any]
@@ -797,7 +798,8 @@ ONTOLOGY_HELP = {
797
798
  "Search the catalog before invoking a tool; the catalog is filtered by the current user's permissions.",
798
799
  "Resolve elements by stable IDs before querying context, model checks, or mapped data.",
799
800
  "elementId/objectElementId 是部署实例 ID;objectTypeId 从实例上下文读取,是对象模板 ID。",
800
- "函数和动作列表读取 id,分别用于 functionId/actionTypeId;返回已移除 actionTypeId、functionKind、implementationRef,业务 definition 按实际返回读取。",
801
+ "函数使用目录中的 apiName 和 version,input 满足 inputSchema;objects 传对象导入描述,每组需明确部署实例。动作仍使用列表 id 作为 actionTypeId。",
802
+ "正式应用使用 ontology releases/package/bind/validate/query/function/diff;绑定只接受正式发布版本。函数版本与包版本分别固定,不能调用 CURRENT 或包外函数。",
801
803
  "动作预览明确传入 objectElementId 和真实 objectKey;用户确认后用同一草稿的 confirmationId 执行。实例参数必须已在当前工具 schema 中声明,缺失时报告上游目录问题。",
802
804
  "READ tools query state, PREPARE tools validate a change draft, and PERSIST tools apply an explicitly confirmed draft.",
803
805
  "PERSIST commands require --confirm. Never reuse a catalog result after its catalogVersion changes.",
@@ -844,6 +846,8 @@ ONTOLOGY_HELP = {
844
846
  }
845
847
 
846
848
 
849
+ ONTOLOGY_HELP["commands"].update(PACKAGE_HELP)
850
+
847
851
  HELP_TOPICS = {
848
852
  "user": USER_HELP,
849
853
  "storage": STORAGE_HELP,
@@ -7,6 +7,7 @@ from typing import Any, Callable
7
7
 
8
8
  from licos_platform_sdk import ontology
9
9
  from .identity import add_user_token_option, user_token
10
+ from .ontology_package_commands import add_package_commands
10
11
 
11
12
  Handler = Callable[[argparse.Namespace], Any]
12
13
 
@@ -60,6 +61,7 @@ def add_ontology_parser(
60
61
  help="Discover and invoke authorized ontology and Data Factory AI tools",
61
62
  )
62
63
  commands = parser.add_subparsers(dest="ontology_command", required=True)
64
+ add_package_commands(commands)
63
65
 
64
66
  search = commands.add_parser("search", help="Search the authorized AI tool catalog")
65
67
  search.add_argument("query")
@@ -0,0 +1,133 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import json
5
+ from copy import deepcopy
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ from licos_platform_sdk import ontology
10
+ from .identity import add_user_token_option, user_token
11
+
12
+
13
+ PACKAGE_HELP = {
14
+ "releases": {"description": "List visible published releases using the current execution identity.", "parameters": [],
15
+ "example": "licos-platform ontology releases"},
16
+ "package": {"description": "Inspect semantic metadata of a specific release; excludes physical mappings and implementation DSL.",
17
+ "parameters": [{"name": "release_id", "required": True, "description": "Release ID from releases."}],
18
+ "example": "licos-platform ontology package <release_id>"},
19
+ "bind": {"description": "Create a binding JSON for a published release; save the output in trusted application configuration.",
20
+ "parameters": [{"name": "release_id", "required": True, "description": "Explicit published release ID."},
21
+ {"name": "--objects-file", "required": True, "description": "JSON array of elementId and attributeIds selections."},
22
+ {"name": "--functions-file", "required": False, "description": "JSON array of apiName/version selections. Omitted selects no functions."}],
23
+ "example": "licos-platform ontology bind <release_id> --objects-file objects.json --functions-file functions.json"},
24
+ "validate": {"description": "Re-read the published artifact and validate binding identity, hash metadata and selected scope.",
25
+ "parameters": [{"name": "--binding-file", "required": True, "description": "Trusted binding JSON file."}],
26
+ "example": "licos-platform ontology validate --binding-file binding.json"},
27
+ "query": {"description": "Query bound business records; preserve primary keys and pagination metadata.",
28
+ "parameters": [{"name": "--binding-file", "required": True, "description": "Binding JSON file."},
29
+ {"name": "--element-id", "required": True, "description": "Deployment ID in the binding."},
30
+ {"name": "--query-file", "required": True, "description": "JSON with attributeIds and explicit pagination; optional conditionGroup/sorts/includeTotalCount."}],
31
+ "example": "licos-platform ontology query --binding-file binding.json --element-id <id> --query-file query.json"},
32
+ "function": {"description": "Invoke an explicitly selected published function through its package runtime; no automatic latest-version fallback.",
33
+ "parameters": [{"name": "--binding-file", "required": True, "description": "Binding JSON file."},
34
+ {"name": "--api-name", "required": True, "description": "Bound function API name."},
35
+ {"name": "--version", "required": True, "description": "Function version, distinct from package version."},
36
+ {"name": "--input-file", "required": True, "description": "Business input JSON satisfying inputSchema."},
37
+ {"name": "--objects-file", "required": False, "description": "JSON import descriptors alias/objectTypeId/objectElementId; at most 8 groups."}],
38
+ "example": "licos-platform ontology function --binding-file binding.json --api-name <name> --version <function_version> --input-file input.json"},
39
+ "diff": {"description": "Compare semantic object, attribute and function changes between two releases.",
40
+ "parameters": [{"name": "before", "required": True, "description": "Previous release ID."},
41
+ {"name": "after", "required": True, "description": "Proposed release ID."}],
42
+ "example": "licos-platform ontology diff <before_release_id> <after_release_id>"},
43
+ }
44
+
45
+
46
+ def _file(path: str) -> Any:
47
+ try:
48
+ return json.loads(Path(path).read_text(encoding="utf-8"))
49
+ except (OSError, json.JSONDecodeError) as exc:
50
+ raise argparse.ArgumentTypeError(f"cannot read ontology JSON file: {exc}") from exc
51
+
52
+
53
+ def _diff(before: Any, after: Any, path: str = "") -> list[dict[str, Any]]:
54
+ if before == after:
55
+ return []
56
+ if isinstance(before, dict) and isinstance(after, dict):
57
+ changes = []
58
+ for key in sorted(before.keys() | after.keys()):
59
+ location = f"{path}/{key}"
60
+ if key not in before:
61
+ changes.append({"path": location, "change": "added", "after": after[key]})
62
+ elif key not in after:
63
+ changes.append({"path": location, "change": "removed", "before": before[key]})
64
+ else:
65
+ changes.extend(_diff(before[key], after[key], location))
66
+ return changes
67
+ return [{"path": path, "change": "changed", "before": before, "after": after}]
68
+
69
+
70
+ def _indexed(context: dict[str, Any]) -> dict[str, Any]:
71
+ result = deepcopy(context)
72
+ for key in ("types", "instances", "relations"):
73
+ result[key] = {item["id"]: item for item in result[key]}
74
+ result["functions"] = {f"{item['apiName']}@{item.get('functionVersion', 'historical')}": item for item in result["functions"]}
75
+ for instance in result["instances"].values():
76
+ instance["attributes"] = {item["id"]: item for item in instance["attributes"]}
77
+ return result
78
+
79
+
80
+ def _run(args: argparse.Namespace) -> Any:
81
+ token = user_token(args)
82
+ operation = args.ontology_command
83
+ if operation == "releases":
84
+ return ontology.list_releases(user_token=token)
85
+ if operation == "package":
86
+ return ontology.get_package(args.release_id, user_token=token)
87
+ if operation == "bind":
88
+ return ontology.create_binding(args.release_id, _file(args.objects_file),
89
+ _file(args.functions_file) if args.functions_file else [], user_token=token)
90
+ if operation == "diff":
91
+ before = ontology.get_package(args.before, user_token=token)
92
+ after = ontology.get_package(args.after, user_token=token)
93
+ return {"before": before["package"], "after": after["package"], "changes": _diff(_indexed(before), _indexed(after))}
94
+ binding = _file(args.binding_file)
95
+ if operation == "validate":
96
+ return ontology.validate_binding(binding, user_token=token)
97
+ if operation == "query":
98
+ return ontology.query_package_objects(binding, args.element_id, _file(args.query_file), user_token=token)
99
+ return ontology.invoke_package_function(binding, args.api_name, args.version, _file(args.input_file), user_token=token,
100
+ objects=_file(args.objects_file) if args.objects_file else [])
101
+
102
+
103
+ def add_package_commands(commands: argparse._SubParsersAction) -> None:
104
+ for name, description in (
105
+ ("releases", "List visible published ontology releases"),
106
+ ("package", "Inspect semantic metadata of one release"),
107
+ ("bind", "Create an explicit release and capability binding"),
108
+ ("validate", "Verify a binding against its published artifact"),
109
+ ("query", "Query business objects within a binding"),
110
+ ("function", "Invoke a versioned read-only function within a binding"),
111
+ ("diff", "Compare semantic metadata of two releases"),
112
+ ):
113
+ parser = commands.add_parser(name, help=description)
114
+ add_user_token_option(parser)
115
+ parser.set_defaults(handler=_run)
116
+ if name in {"package", "bind"}:
117
+ parser.add_argument("release_id")
118
+ if name in {"validate", "query", "function"}:
119
+ parser.add_argument("--binding-file", required=True)
120
+ if name == "bind":
121
+ parser.add_argument("--objects-file", required=True, help="JSON array of elementId/attributeIds selections")
122
+ parser.add_argument("--functions-file", help="JSON array of apiName/version selections; omitted selects no functions")
123
+ if name == "query":
124
+ parser.add_argument("--element-id", required=True)
125
+ parser.add_argument("--query-file", required=True)
126
+ if name == "function":
127
+ parser.add_argument("--api-name", required=True)
128
+ parser.add_argument("--version", required=True)
129
+ parser.add_argument("--input-file", required=True)
130
+ parser.add_argument("--objects-file")
131
+ if name == "diff":
132
+ parser.add_argument("before")
133
+ parser.add_argument("after")
@@ -136,7 +136,7 @@ class PlatformCliTests(unittest.TestCase):
136
136
  self.assertEqual(stderr, "")
137
137
  payload = json.loads(stdout)
138
138
  self.assertEqual(payload["topic"], "ontology")
139
- self.assertEqual(set(payload["commands"]), {"search", "invoke"})
139
+ self.assertEqual(set(payload["commands"]), {"search", "invoke", "releases", "package", "bind", "validate", "query", "function", "diff"})
140
140
  self.assertTrue(any("catalogVersion" in rule for rule in payload["rules"]))
141
141
  sdk_help = "\n".join(payload["sdk"].values())
142
142
  self.assertNotIn("items[0]", sdk_help)
@@ -0,0 +1,56 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import os
5
+ import sys
6
+ import tempfile
7
+ import unittest
8
+ from pathlib import Path
9
+ from unittest.mock import patch
10
+
11
+ sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "licos-platform-sdk" / "src"))
12
+ sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
13
+ from licos_platform_cli.ontology_package_commands import _indexed, _diff
14
+ from test_cli import run_cli
15
+
16
+
17
+ class OntologyPackageCliTests(unittest.TestCase):
18
+ def test_package_commands_have_structured_help(self):
19
+ for command in ("releases", "package", "bind", "validate", "query", "function", "diff"):
20
+ code, output, error = run_cli("help", "ontology", command)
21
+ self.assertEqual((code, error), (0, ""))
22
+ self.assertIn("parameters", json.loads(output))
23
+
24
+ def setUp(self):
25
+ identity = patch.dict(os.environ, {"LICOS_CURRENT_USER_ID": "caller"})
26
+ identity.start()
27
+ self.addCleanup(identity.stop)
28
+
29
+ @patch("licos_platform_cli.identity.runtime_user_token", return_value="caller-token")
30
+ @patch("licos_platform_cli.ontology_package_commands.ontology.list_releases", return_value=[])
31
+ def test_releases_forwards_runtime_identity(self, releases, _identity):
32
+ code, output, error = run_cli("ontology", "releases")
33
+ self.assertEqual((code, error), (0, ""))
34
+ releases.assert_called_once_with(user_token="caller-token")
35
+
36
+ @patch("licos_platform_cli.identity.runtime_user_token", return_value="caller-token")
37
+ @patch("licos_platform_cli.ontology_package_commands.ontology.invoke_package_function", return_value={"result": 42})
38
+ def test_function_preserves_binding_version_and_structured_input(self, invoke, _identity):
39
+ with tempfile.TemporaryDirectory() as root:
40
+ binding, inputs = Path(root)/"binding.json", Path(root)/"input.json"
41
+ binding.write_text(json.dumps({"releaseId": "release-1"}), encoding="utf-8")
42
+ inputs.write_text(json.dumps({"value": 3}), encoding="utf-8")
43
+ code, _, error = run_cli("ontology", "function", "--binding-file", str(binding),
44
+ "--api-name", "readStatus", "--version", "1.0.1", "--input-file", str(inputs))
45
+ self.assertEqual((code, error), (0, ""))
46
+ invoke.assert_called_once_with({"releaseId": "release-1"}, "readStatus", "1.0.1", {"value": 3}, user_token="caller-token", objects=[])
47
+
48
+ def test_diff_preserves_multiple_versions_and_does_not_mutate_input(self):
49
+ context = {"types": [], "relations": [], "instances": [{"id": "pump", "attributes": [{"id": "pressure"}]}],
50
+ "functions": [{"apiName": "read", "functionVersion": "1"}, {"apiName": "read", "functionVersion": "2"}]}
51
+ indexed = _indexed(context)
52
+ self.assertEqual(len(indexed["functions"]), 2)
53
+ self.assertIsInstance(context["instances"][0]["attributes"], list)
54
+ updated = json.loads(json.dumps(indexed))
55
+ updated["instances"]["pump"]["attributes"]["pressure"]["valueType"] = "Double"
56
+ self.assertEqual(_diff(indexed, updated)[0]["path"], "/instances/pump/attributes/pressure/valueType")