aikernel-tools 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aikernel_tools/__init__.py +47 -0
- aikernel_tools/native/AIKernel.Abstractions.dll +0 -0
- aikernel_tools/native/AIKernel.Common.dll +0 -0
- aikernel_tools/native/AIKernel.Core.dll +0 -0
- aikernel_tools/native/AIKernel.Dtos.dll +0 -0
- aikernel_tools/native/AIKernel.Enums.dll +0 -0
- aikernel_tools/native/AIKernel.Tools.Capability.RomStorage.dll +0 -0
- aikernel_tools/native/AIKernel.Tools.Inspectors.ChatHistoryScraper.dll +0 -0
- aikernel_tools/native/AIKernel.Tools.Inspectors.KernelClock.dll +0 -0
- aikernel_tools/native/AIKernel.Tools.Inspectors.Vfs.dll +0 -0
- aikernel_tools/native/AIKernel.Tools.Instrumentation.dll +0 -0
- aikernel_tools/native/ChatHistoryProvider.dll +0 -0
- aikernel_tools/native/Microsoft.Extensions.Configuration.Abstractions.dll +0 -0
- aikernel_tools/native/Microsoft.Extensions.Configuration.Binder.dll +0 -0
- aikernel_tools/native/Microsoft.Extensions.Configuration.dll +0 -0
- aikernel_tools/native/Microsoft.Extensions.DependencyInjection.Abstractions.dll +0 -0
- aikernel_tools/native/Microsoft.Extensions.DependencyInjection.dll +0 -0
- aikernel_tools/native/Microsoft.Extensions.Diagnostics.Abstractions.dll +0 -0
- aikernel_tools/native/Microsoft.Extensions.Diagnostics.dll +0 -0
- aikernel_tools/native/Microsoft.Extensions.Http.dll +0 -0
- aikernel_tools/native/Microsoft.Extensions.Logging.Abstractions.dll +0 -0
- aikernel_tools/native/Microsoft.Extensions.Logging.dll +0 -0
- aikernel_tools/native/Microsoft.Extensions.Options.ConfigurationExtensions.dll +0 -0
- aikernel_tools/native/Microsoft.Extensions.Options.dll +0 -0
- aikernel_tools/native/Microsoft.Extensions.Primitives.dll +0 -0
- aikernel_tools/native/YamlDotNet.dll +0 -0
- aikernel_tools/native/__init__.py +179 -0
- aikernel_tools/tools/__init__.py +42 -0
- aikernel_tools/tools/capabilities.py +148 -0
- aikernel_tools/tools/formatter.py +260 -0
- aikernel_tools/tools/inspector.py +136 -0
- aikernel_tools/tools/managed.py +116 -0
- aikernel_tools/tools/replay.py +80 -0
- aikernel_tools/tools/session.py +36 -0
- aikernel_tools-0.1.1.dist-info/METADATA +84 -0
- aikernel_tools-0.1.1.dist-info/RECORD +38 -0
- aikernel_tools-0.1.1.dist-info/WHEEL +5 -0
- aikernel_tools-0.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""[EN]
|
|
2
|
+
Unified Python API for AIKernel.Tools instrumentation contracts.
|
|
3
|
+
|
|
4
|
+
[JA]
|
|
5
|
+
AIKernel.Tools instrumentation 契約を扱う統一 Python API です。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .native import tools_assemblies, load_tools_runtime
|
|
9
|
+
from .tools import (
|
|
10
|
+
CanonicalFormatter,
|
|
11
|
+
CanonicalSerializer,
|
|
12
|
+
CapabilityContract,
|
|
13
|
+
ChatHistoryRecord,
|
|
14
|
+
ChatHistoryScraper,
|
|
15
|
+
InfoCommand,
|
|
16
|
+
Inspector,
|
|
17
|
+
MdExporter,
|
|
18
|
+
NowCommand,
|
|
19
|
+
ReplayEngine,
|
|
20
|
+
ReplaySession,
|
|
21
|
+
RomExporter,
|
|
22
|
+
RomStorageCapability,
|
|
23
|
+
TimelineCommand,
|
|
24
|
+
TreeCommand,
|
|
25
|
+
VfsGitCapability,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"CanonicalFormatter",
|
|
30
|
+
"CanonicalSerializer",
|
|
31
|
+
"CapabilityContract",
|
|
32
|
+
"ChatHistoryRecord",
|
|
33
|
+
"ChatHistoryScraper",
|
|
34
|
+
"InfoCommand",
|
|
35
|
+
"Inspector",
|
|
36
|
+
"MdExporter",
|
|
37
|
+
"NowCommand",
|
|
38
|
+
"ReplayEngine",
|
|
39
|
+
"ReplaySession",
|
|
40
|
+
"RomExporter",
|
|
41
|
+
"RomStorageCapability",
|
|
42
|
+
"TimelineCommand",
|
|
43
|
+
"TreeCommand",
|
|
44
|
+
"VfsGitCapability",
|
|
45
|
+
"load_tools_runtime",
|
|
46
|
+
"tools_assemblies",
|
|
47
|
+
]
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"""[EN]
|
|
2
|
+
Managed assembly discovery and pythonnet loading for AIKernel.Tools.
|
|
3
|
+
|
|
4
|
+
[JA]
|
|
5
|
+
AIKernel.Tools の managed assembly 探索と pythonnet 読み込みを提供します。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
_TOOLS_PACKAGE_VERSION = "0.1.1"
|
|
16
|
+
_CONTRACT_PACKAGE_VERSION = "0.1.1"
|
|
17
|
+
_CORE_PACKAGE_VERSION = "0.1.1"
|
|
18
|
+
_PROVIDER_PACKAGE_VERSION = "0.1.1"
|
|
19
|
+
_ASSEMBLIES = (
|
|
20
|
+
"AIKernel.Abstractions.dll",
|
|
21
|
+
"AIKernel.Common.dll",
|
|
22
|
+
"AIKernel.Core.dll",
|
|
23
|
+
"AIKernel.Dtos.dll",
|
|
24
|
+
"AIKernel.Enums.dll",
|
|
25
|
+
"ChatHistoryProvider.dll",
|
|
26
|
+
"AIKernel.Tools.Instrumentation.dll",
|
|
27
|
+
"AIKernel.Tools.Capability.RomStorage.dll",
|
|
28
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper.dll",
|
|
29
|
+
"AIKernel.Tools.Inspectors.KernelClock.dll",
|
|
30
|
+
"AIKernel.Tools.Inspectors.Vfs.dll",
|
|
31
|
+
)
|
|
32
|
+
_ASSEMBLY_PACKAGES = {
|
|
33
|
+
"AIKernel.Abstractions.dll": ("AIKernel.Abstractions", _CONTRACT_PACKAGE_VERSION),
|
|
34
|
+
"AIKernel.Common.dll": ("AIKernel.Common", _CORE_PACKAGE_VERSION),
|
|
35
|
+
"AIKernel.Core.dll": ("AIKernel.Core", _CORE_PACKAGE_VERSION),
|
|
36
|
+
"AIKernel.Dtos.dll": ("AIKernel.Dtos", _CONTRACT_PACKAGE_VERSION),
|
|
37
|
+
"AIKernel.Enums.dll": ("AIKernel.Enums", _CONTRACT_PACKAGE_VERSION),
|
|
38
|
+
"ChatHistoryProvider.dll": ("AIKernel.Providers.ChatHistory", _PROVIDER_PACKAGE_VERSION),
|
|
39
|
+
"AIKernel.Tools.Instrumentation.dll": (
|
|
40
|
+
"AIKernel.Tools.Instrumentation",
|
|
41
|
+
_TOOLS_PACKAGE_VERSION,
|
|
42
|
+
),
|
|
43
|
+
"AIKernel.Tools.Capability.RomStorage.dll": (
|
|
44
|
+
"AIKernel.Tools.Capability.RomStorage",
|
|
45
|
+
_TOOLS_PACKAGE_VERSION,
|
|
46
|
+
),
|
|
47
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper.dll": (
|
|
48
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper",
|
|
49
|
+
_TOOLS_PACKAGE_VERSION,
|
|
50
|
+
),
|
|
51
|
+
"AIKernel.Tools.Inspectors.KernelClock.dll": (
|
|
52
|
+
"AIKernel.Tools.Inspectors.KernelClock",
|
|
53
|
+
_TOOLS_PACKAGE_VERSION,
|
|
54
|
+
),
|
|
55
|
+
"AIKernel.Tools.Inspectors.Vfs.dll": (
|
|
56
|
+
"AIKernel.Tools.Inspectors.Vfs",
|
|
57
|
+
_TOOLS_PACKAGE_VERSION,
|
|
58
|
+
),
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass(frozen=True)
|
|
63
|
+
class ToolsAssemblySet:
|
|
64
|
+
"""[EN]
|
|
65
|
+
Resolved managed assemblies that define the Tools instrumentation boundary.
|
|
66
|
+
|
|
67
|
+
[JA]
|
|
68
|
+
Tools instrumentation 境界を定義する解決済み managed assembly 群です。
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
root: Path
|
|
72
|
+
assemblies: tuple[Path, ...]
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def is_complete(self) -> bool:
|
|
76
|
+
"""[EN] Return whether every expected assembly exists.
|
|
77
|
+
|
|
78
|
+
[JA] 期待されるすべての assembly が存在するかを返します。
|
|
79
|
+
"""
|
|
80
|
+
return all(path.exists() for path in self.assemblies)
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def missing(self) -> tuple[str, ...]:
|
|
84
|
+
"""[EN] Return missing assembly file names.
|
|
85
|
+
|
|
86
|
+
[JA] 不足している assembly ファイル名を返します。
|
|
87
|
+
"""
|
|
88
|
+
return tuple(path.name for path in self.assemblies if not path.exists())
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def tools_assemblies() -> ToolsAssemblySet:
|
|
92
|
+
"""[EN] Resolve bundled or NuGet-provided Tools assemblies.
|
|
93
|
+
|
|
94
|
+
[JA] 同梱または NuGet 提供の Tools assembly を解決します。
|
|
95
|
+
"""
|
|
96
|
+
root = _native_root()
|
|
97
|
+
return ToolsAssemblySet(
|
|
98
|
+
root=root,
|
|
99
|
+
assemblies=tuple(_resolve_assembly(name) for name in _ASSEMBLIES),
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def require_tools_assemblies() -> ToolsAssemblySet:
|
|
104
|
+
"""[EN] Resolve assemblies and fail if any required assembly is missing.
|
|
105
|
+
|
|
106
|
+
[JA] assembly を解決し、不足がある場合は失敗します。
|
|
107
|
+
"""
|
|
108
|
+
assemblies = tools_assemblies()
|
|
109
|
+
if not assemblies.is_complete:
|
|
110
|
+
missing = ", ".join(assemblies.missing)
|
|
111
|
+
raise FileNotFoundError(
|
|
112
|
+
"AIKernel.Tools managed assemblies are not available: "
|
|
113
|
+
f"{missing}. Bundle them in aikernel_tools/native or restore "
|
|
114
|
+
"the corresponding NuGet packages."
|
|
115
|
+
)
|
|
116
|
+
return assemblies
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def load_tools_runtime() -> ToolsAssemblySet:
|
|
120
|
+
"""[EN] Load bundled C# assemblies through pythonnet.
|
|
121
|
+
|
|
122
|
+
[JA] 同梱 C# assembly を pythonnet 経由で読み込みます。
|
|
123
|
+
"""
|
|
124
|
+
assemblies = require_tools_assemblies()
|
|
125
|
+
try:
|
|
126
|
+
from pythonnet import load # type: ignore[import-not-found]
|
|
127
|
+
|
|
128
|
+
try:
|
|
129
|
+
load("coreclr")
|
|
130
|
+
except RuntimeError:
|
|
131
|
+
# The runtime may already be loaded by another AIKernel wrapper.
|
|
132
|
+
pass
|
|
133
|
+
import clr # type: ignore[import-not-found]
|
|
134
|
+
except ImportError as exc:
|
|
135
|
+
raise RuntimeError("pythonnet is required to load AIKernel.Tools assemblies.") from exc
|
|
136
|
+
|
|
137
|
+
for assembly in assemblies.assemblies:
|
|
138
|
+
clr.AddReference(str(assembly))
|
|
139
|
+
return assemblies
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _resolve_assembly(name: str) -> Path:
|
|
143
|
+
for root in _assembly_roots():
|
|
144
|
+
candidate = root / name
|
|
145
|
+
if candidate.exists():
|
|
146
|
+
return candidate
|
|
147
|
+
|
|
148
|
+
nuget_candidate = _resolve_nuget_assembly(name)
|
|
149
|
+
if nuget_candidate is not None:
|
|
150
|
+
return nuget_candidate
|
|
151
|
+
|
|
152
|
+
return _native_root() / name
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _assembly_roots() -> tuple[Path, ...]:
|
|
156
|
+
roots = [_native_root()]
|
|
157
|
+
override = os.environ.get("AIKERNEL_TOOLS_ASSEMBLY_PATH")
|
|
158
|
+
if override:
|
|
159
|
+
roots.extend(Path(path) for path in override.split(os.pathsep) if path)
|
|
160
|
+
return tuple(roots)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _native_root() -> Path:
|
|
164
|
+
return Path(__file__).resolve().parent
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _resolve_nuget_assembly(name: str) -> Path | None:
|
|
168
|
+
package, version = _ASSEMBLY_PACKAGES[name]
|
|
169
|
+
candidate = _nuget_root() / package.lower() / version / "lib" / "net10.0" / name
|
|
170
|
+
if candidate.exists():
|
|
171
|
+
return candidate
|
|
172
|
+
return None
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _nuget_root() -> Path:
|
|
176
|
+
configured = os.environ.get("NUGET_PACKAGES")
|
|
177
|
+
if configured:
|
|
178
|
+
return Path(configured)
|
|
179
|
+
return Path.home() / ".nuget" / "packages"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""[EN]
|
|
2
|
+
Instrumentation wrappers for AIKernel.Tools.
|
|
3
|
+
|
|
4
|
+
[JA]
|
|
5
|
+
AIKernel.Tools の instrumentation wrapper 群です。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .capabilities import (
|
|
9
|
+
CapabilityContract,
|
|
10
|
+
RomStorageCapability,
|
|
11
|
+
VfsGitCapability,
|
|
12
|
+
)
|
|
13
|
+
from .formatter import (
|
|
14
|
+
CanonicalFormatter,
|
|
15
|
+
CanonicalSerializer,
|
|
16
|
+
ChatHistoryRecord,
|
|
17
|
+
ChatHistoryScraper,
|
|
18
|
+
MdExporter,
|
|
19
|
+
RomExporter,
|
|
20
|
+
)
|
|
21
|
+
from .inspector import InfoCommand, Inspector, NowCommand, TimelineCommand, TreeCommand
|
|
22
|
+
from .replay import ReplayEngine
|
|
23
|
+
from .session import ReplaySession
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"CanonicalFormatter",
|
|
27
|
+
"CanonicalSerializer",
|
|
28
|
+
"CapabilityContract",
|
|
29
|
+
"ChatHistoryRecord",
|
|
30
|
+
"ChatHistoryScraper",
|
|
31
|
+
"InfoCommand",
|
|
32
|
+
"Inspector",
|
|
33
|
+
"MdExporter",
|
|
34
|
+
"NowCommand",
|
|
35
|
+
"ReplayEngine",
|
|
36
|
+
"ReplaySession",
|
|
37
|
+
"RomExporter",
|
|
38
|
+
"RomStorageCapability",
|
|
39
|
+
"TimelineCommand",
|
|
40
|
+
"TreeCommand",
|
|
41
|
+
"VfsGitCapability",
|
|
42
|
+
]
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import Mapping
|
|
5
|
+
|
|
6
|
+
from .managed import call_static, create_managed, to_dictionary
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass(frozen=True)
|
|
10
|
+
class CapabilityContract:
|
|
11
|
+
"""[EN]
|
|
12
|
+
Python view of AIKernel.Dtos.Capabilities.CapabilityModuleDescriptor.
|
|
13
|
+
|
|
14
|
+
[JA]
|
|
15
|
+
AIKernel.Dtos.Capabilities.CapabilityModuleDescriptor の Python view です。
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
_managed: object
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def managed(self):
|
|
22
|
+
"""[EN] Return the underlying C# descriptor.
|
|
23
|
+
|
|
24
|
+
[JA] 背後の C# descriptor を返します。
|
|
25
|
+
"""
|
|
26
|
+
return self._managed
|
|
27
|
+
|
|
28
|
+
def to_managed(self):
|
|
29
|
+
"""[EN] Return the underlying C# descriptor.
|
|
30
|
+
|
|
31
|
+
[JA] 背後の C# descriptor を返します。
|
|
32
|
+
"""
|
|
33
|
+
return self._managed
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def capability_id(self) -> str:
|
|
37
|
+
return str(self.managed.CapabilityId)
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def name(self) -> str:
|
|
41
|
+
return str(self.managed.Name)
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def kind(self) -> str:
|
|
45
|
+
return str(self.managed.Kind)
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def invocation_mode(self) -> str:
|
|
49
|
+
return str(self.managed.InvocationMode)
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def version(self) -> str:
|
|
53
|
+
return str(self.managed.Version)
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def entry_point(self) -> str | None:
|
|
57
|
+
value = self.managed.EntryPoint
|
|
58
|
+
return None if value is None else str(value)
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def artifact_uri(self) -> str | None:
|
|
62
|
+
value = self.managed.ArtifactUri
|
|
63
|
+
return None if value is None else str(value)
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def artifact_hash(self) -> str | None:
|
|
67
|
+
value = self.managed.ArtifactHash
|
|
68
|
+
return None if value is None else str(value)
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def provided_operations(self) -> tuple[str, ...]:
|
|
72
|
+
return tuple(str(value) for value in self.managed.ProvidedOperations)
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def required_permissions(self) -> tuple[str, ...]:
|
|
76
|
+
return tuple(str(value) for value in self.managed.RequiredPermissions)
|
|
77
|
+
|
|
78
|
+
@property
|
|
79
|
+
def metadata(self) -> dict[str, str]:
|
|
80
|
+
return {str(key): str(self.managed.Metadata[key]) for key in self.managed.Metadata.Keys}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@dataclass(frozen=True)
|
|
84
|
+
class RomStorageCapability:
|
|
85
|
+
"""[EN] Wrapper for ROM storage capability contracts.
|
|
86
|
+
|
|
87
|
+
[JA] ROM storage capability contract の wrapper です。
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
capability_id: str
|
|
91
|
+
storage_scheme: str = "rom"
|
|
92
|
+
metadata: Mapping[str, str] = field(default_factory=dict)
|
|
93
|
+
|
|
94
|
+
def _metadata(self):
|
|
95
|
+
return _metadata(self.metadata)
|
|
96
|
+
|
|
97
|
+
def to_contract(self) -> CapabilityContract:
|
|
98
|
+
return CapabilityContract(
|
|
99
|
+
call_static(
|
|
100
|
+
"AIKernel.Core.Storage.RomStorageCapabilityContracts",
|
|
101
|
+
"AIKernel.Core",
|
|
102
|
+
"ToContract",
|
|
103
|
+
create_managed(
|
|
104
|
+
"AIKernel.Core.Storage.RomStorageCapabilityDescriptor",
|
|
105
|
+
"AIKernel.Core",
|
|
106
|
+
self.capability_id,
|
|
107
|
+
self.storage_scheme,
|
|
108
|
+
self._metadata(),
|
|
109
|
+
),
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@dataclass(frozen=True)
|
|
115
|
+
class VfsGitCapability:
|
|
116
|
+
"""[EN] Wrapper for VFS Git capability contracts.
|
|
117
|
+
|
|
118
|
+
[JA] VFS Git capability contract の wrapper です。
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
capability_id: str
|
|
122
|
+
repository_mode: str = "readonly"
|
|
123
|
+
metadata: Mapping[str, str] = field(default_factory=dict)
|
|
124
|
+
|
|
125
|
+
def _metadata(self):
|
|
126
|
+
return _metadata(self.metadata)
|
|
127
|
+
|
|
128
|
+
def to_contract(self) -> CapabilityContract:
|
|
129
|
+
return CapabilityContract(
|
|
130
|
+
call_static(
|
|
131
|
+
"AIKernel.Core.Vfs.VfsGit.VfsGitCapabilityContracts",
|
|
132
|
+
"AIKernel.Core",
|
|
133
|
+
"ToContract",
|
|
134
|
+
create_managed(
|
|
135
|
+
"AIKernel.Core.Vfs.VfsGit.VfsGitCapabilityDescriptor",
|
|
136
|
+
"AIKernel.Core",
|
|
137
|
+
self.capability_id,
|
|
138
|
+
self.repository_mode,
|
|
139
|
+
self._metadata(),
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _metadata(values: Mapping[str, str]):
|
|
146
|
+
metadata = {"version": "0.1.1"}
|
|
147
|
+
metadata.update({str(key): str(value) for key, value in values.items()})
|
|
148
|
+
return to_dictionary(metadata)
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from datetime import datetime, timezone
|
|
5
|
+
from typing import Any, Sequence
|
|
6
|
+
|
|
7
|
+
from .managed import call_static, to_string_list
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True)
|
|
11
|
+
class ChatHistoryRecord:
|
|
12
|
+
"""[EN]
|
|
13
|
+
Python wrapper for the public ChatHistoryRecord DTO.
|
|
14
|
+
|
|
15
|
+
[JA]
|
|
16
|
+
公開 ChatHistoryRecord DTO の Python wrapper です。
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
role: str
|
|
20
|
+
content: str
|
|
21
|
+
timestamp: datetime | str
|
|
22
|
+
_managed: object | None = None
|
|
23
|
+
|
|
24
|
+
def __post_init__(self):
|
|
25
|
+
object.__setattr__(self, "_managed", self._managed)
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def managed(self):
|
|
29
|
+
"""[EN] Return the underlying C# record when materialized.
|
|
30
|
+
|
|
31
|
+
[JA] materialize 済みの場合に背後の C# record を返します。
|
|
32
|
+
"""
|
|
33
|
+
return self._managed
|
|
34
|
+
|
|
35
|
+
@classmethod
|
|
36
|
+
def from_managed(cls, managed) -> "ChatHistoryRecord":
|
|
37
|
+
"""[EN] Create a Python wrapper from a managed ChatHistoryRecord.
|
|
38
|
+
|
|
39
|
+
[JA] managed ChatHistoryRecord から Python wrapper を作成します。
|
|
40
|
+
"""
|
|
41
|
+
return cls(str(managed.Role), str(managed.Content), str(managed.Timestamp), managed)
|
|
42
|
+
|
|
43
|
+
def to_managed(self):
|
|
44
|
+
"""[EN] Convert to AIKernel.Tools ChatHistoryRecord.
|
|
45
|
+
|
|
46
|
+
[JA] AIKernel.Tools ChatHistoryRecord に変換します。
|
|
47
|
+
"""
|
|
48
|
+
if self._managed is not None:
|
|
49
|
+
return self._managed
|
|
50
|
+
|
|
51
|
+
raise RuntimeError(
|
|
52
|
+
"ChatHistoryRecord is materialized by the AIKernel.Tools C# formatter bridge."
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@dataclass(frozen=True)
|
|
57
|
+
class CanonicalFormatter:
|
|
58
|
+
"""[EN]
|
|
59
|
+
Canonical formatting facade for AIKernel.Tools public exporters.
|
|
60
|
+
|
|
61
|
+
[JA]
|
|
62
|
+
AIKernel.Tools 公開 exporter 用の canonical formatting facade です。
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
backend: Any | None = None
|
|
66
|
+
|
|
67
|
+
def format(self, obj: Any) -> str:
|
|
68
|
+
"""[EN] Format a public Tools object without changing C# semantics.
|
|
69
|
+
|
|
70
|
+
[JA] C# semantics を変更せずに公開 Tools object を format します。
|
|
71
|
+
"""
|
|
72
|
+
if self.backend is not None:
|
|
73
|
+
return str(_call(self.backend, "format", "Format", obj))
|
|
74
|
+
return _to_markdown(obj)
|
|
75
|
+
|
|
76
|
+
def serialize(self, obj: Any) -> str:
|
|
77
|
+
"""[EN] Serialize a public Tools object using canonical C# exporters.
|
|
78
|
+
|
|
79
|
+
[JA] canonical C# exporter を使って公開 Tools object を serialize します。
|
|
80
|
+
"""
|
|
81
|
+
if self.backend is not None:
|
|
82
|
+
return str(_call(self.backend, "serialize", "Serialize", obj))
|
|
83
|
+
return _to_rom(obj)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
CanonicalSerializer = CanonicalFormatter
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class MdExporter:
|
|
90
|
+
"""[EN]
|
|
91
|
+
Python facade for the public C# MdExporter.
|
|
92
|
+
|
|
93
|
+
[JA]
|
|
94
|
+
公開 C# MdExporter に対応する Python facade です。
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
@staticmethod
|
|
98
|
+
def to_markdown(records: Any) -> str:
|
|
99
|
+
"""[EN] Format chat-history records as deterministic Markdown.
|
|
100
|
+
|
|
101
|
+
[JA] chat-history record を deterministic Markdown として format します。
|
|
102
|
+
"""
|
|
103
|
+
return _to_markdown(records)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class RomExporter:
|
|
107
|
+
"""[EN]
|
|
108
|
+
Python facade for the public C# RomExporter.
|
|
109
|
+
|
|
110
|
+
[JA]
|
|
111
|
+
公開 C# RomExporter に対応する Python facade です。
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
@staticmethod
|
|
115
|
+
def to_rom(
|
|
116
|
+
records: Any,
|
|
117
|
+
namespace: str = "scraper",
|
|
118
|
+
name: str = "history",
|
|
119
|
+
generated_at_utc: datetime | str | None = None,
|
|
120
|
+
) -> str:
|
|
121
|
+
"""[EN] Serialize chat-history records as deterministic HistoryROM Markdown.
|
|
122
|
+
|
|
123
|
+
[JA] chat-history record を deterministic HistoryROM Markdown として serialize します。
|
|
124
|
+
"""
|
|
125
|
+
if namespace == "scraper" and name == "history" and generated_at_utc is None:
|
|
126
|
+
return _to_rom(records)
|
|
127
|
+
|
|
128
|
+
generated_at = "" if generated_at_utc is None else _timestamp_text(generated_at_utc)
|
|
129
|
+
return str(
|
|
130
|
+
call_static(
|
|
131
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper.Export.ChatHistoryPythonBridge",
|
|
132
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper",
|
|
133
|
+
"ToRomWithMetadata",
|
|
134
|
+
*_to_record_parts(records),
|
|
135
|
+
namespace,
|
|
136
|
+
name,
|
|
137
|
+
generated_at,
|
|
138
|
+
)
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class ChatHistoryScraper:
|
|
143
|
+
"""[EN]
|
|
144
|
+
Python facade for the public C# ChatHistoryScraper.
|
|
145
|
+
|
|
146
|
+
[JA]
|
|
147
|
+
公開 C# ChatHistoryScraper に対応する Python facade です。
|
|
148
|
+
"""
|
|
149
|
+
|
|
150
|
+
@staticmethod
|
|
151
|
+
def export(url: str):
|
|
152
|
+
"""[EN] Export a shared ChatGPT history by delegating to C# ExportAsync.
|
|
153
|
+
|
|
154
|
+
[JA] C# ExportAsync に委譲して共有 ChatGPT history を export します。
|
|
155
|
+
"""
|
|
156
|
+
task = call_static(
|
|
157
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper.ChatHistoryScraper",
|
|
158
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper",
|
|
159
|
+
"ExportAsync",
|
|
160
|
+
url,
|
|
161
|
+
)
|
|
162
|
+
return task.GetAwaiter().GetResult()
|
|
163
|
+
|
|
164
|
+
@staticmethod
|
|
165
|
+
def to_records(history: Any) -> tuple[ChatHistoryRecord, ...]:
|
|
166
|
+
"""[EN] Convert a managed ChatHistory object into Python record wrappers.
|
|
167
|
+
|
|
168
|
+
[JA] managed ChatHistory object を Python record wrapper に変換します。
|
|
169
|
+
"""
|
|
170
|
+
records = call_static(
|
|
171
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper.ChatHistoryScraper",
|
|
172
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper",
|
|
173
|
+
"ToRecords",
|
|
174
|
+
history,
|
|
175
|
+
)
|
|
176
|
+
return tuple(ChatHistoryRecord.from_managed(record) for record in records)
|
|
177
|
+
|
|
178
|
+
@staticmethod
|
|
179
|
+
def to_markdown(history: Any, source_url: str) -> str:
|
|
180
|
+
"""[EN] Convert a managed ChatHistory object into Markdown.
|
|
181
|
+
|
|
182
|
+
[JA] managed ChatHistory object を Markdown に変換します。
|
|
183
|
+
"""
|
|
184
|
+
return str(
|
|
185
|
+
call_static(
|
|
186
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper.ChatHistoryScraper",
|
|
187
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper",
|
|
188
|
+
"ToMarkdown",
|
|
189
|
+
history,
|
|
190
|
+
source_url,
|
|
191
|
+
)
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _to_markdown(obj: Any) -> str:
|
|
196
|
+
return str(
|
|
197
|
+
call_static(
|
|
198
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper.Export.ChatHistoryPythonBridge",
|
|
199
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper",
|
|
200
|
+
"ToMarkdown",
|
|
201
|
+
*_to_record_parts(obj),
|
|
202
|
+
)
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _to_rom(obj: Any) -> str:
|
|
207
|
+
return str(
|
|
208
|
+
call_static(
|
|
209
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper.Export.ChatHistoryPythonBridge",
|
|
210
|
+
"AIKernel.Tools.Inspectors.ChatHistoryScraper",
|
|
211
|
+
"ToRom",
|
|
212
|
+
*_to_record_parts(obj),
|
|
213
|
+
)
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _to_record_parts(obj: Any):
|
|
218
|
+
roles = []
|
|
219
|
+
contents = []
|
|
220
|
+
timestamps = []
|
|
221
|
+
for item in _as_sequence(obj):
|
|
222
|
+
record = _coerce_record(item)
|
|
223
|
+
roles.append(record.role)
|
|
224
|
+
contents.append(record.content)
|
|
225
|
+
timestamps.append(_timestamp_text(record.timestamp))
|
|
226
|
+
return to_string_list(roles), to_string_list(contents), to_string_list(timestamps)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def _as_sequence(obj: Any) -> Sequence[Any]:
|
|
230
|
+
if isinstance(obj, (str, bytes)):
|
|
231
|
+
raise TypeError("canonical chat-history formatting requires a record sequence")
|
|
232
|
+
if isinstance(obj, Sequence):
|
|
233
|
+
return obj
|
|
234
|
+
return tuple(obj)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def _timestamp_text(value: datetime | str) -> str:
|
|
238
|
+
if isinstance(value, datetime):
|
|
239
|
+
if value.tzinfo is None:
|
|
240
|
+
value = value.replace(tzinfo=timezone.utc)
|
|
241
|
+
return value.isoformat()
|
|
242
|
+
return str(value)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def _coerce_record(value: Any) -> ChatHistoryRecord:
|
|
246
|
+
if isinstance(value, ChatHistoryRecord):
|
|
247
|
+
return value
|
|
248
|
+
role = getattr(value, "role", None) or getattr(value, "Role", None)
|
|
249
|
+
content = getattr(value, "content", None) or getattr(value, "Content", None)
|
|
250
|
+
timestamp = getattr(value, "timestamp", None) or getattr(value, "Timestamp", None)
|
|
251
|
+
if role is None or content is None or timestamp is None:
|
|
252
|
+
raise TypeError("chat-history records require role, content, and timestamp")
|
|
253
|
+
return ChatHistoryRecord(str(role), str(content), str(timestamp))
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def _call(target: Any, python_name: str, managed_name: str, *args) -> Any:
|
|
257
|
+
method = getattr(target, python_name, None) or getattr(target, managed_name, None)
|
|
258
|
+
if method is None:
|
|
259
|
+
raise AttributeError(f"formatter backend must expose {python_name}()")
|
|
260
|
+
return method(*args)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from .managed import call_static
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass(frozen=True)
|
|
10
|
+
class Inspector:
|
|
11
|
+
"""[EN]
|
|
12
|
+
Thin inspector facade over a public Tools backend.
|
|
13
|
+
|
|
14
|
+
[JA]
|
|
15
|
+
公開 Tools backend に委譲する薄い inspector facade です。
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
backend: Any | None = None
|
|
19
|
+
|
|
20
|
+
def inspect(self, obj: Any):
|
|
21
|
+
"""[EN] Inspect an object through the configured backend.
|
|
22
|
+
|
|
23
|
+
[JA] 設定された backend 経由で object を inspect します。
|
|
24
|
+
"""
|
|
25
|
+
return _call(self.backend, "inspect", "Inspect", obj)
|
|
26
|
+
|
|
27
|
+
def tree(self, obj: Any):
|
|
28
|
+
"""[EN] Return a tree view through the configured backend.
|
|
29
|
+
|
|
30
|
+
[JA] 設定された backend 経由で tree view を返します。
|
|
31
|
+
"""
|
|
32
|
+
return _call(self.backend, "tree", "Tree", obj)
|
|
33
|
+
|
|
34
|
+
def diff(self, a: Any, b: Any):
|
|
35
|
+
"""[EN] Return a deterministic diff through the configured backend.
|
|
36
|
+
|
|
37
|
+
[JA] 設定された backend 経由で決定論的 diff を返します。
|
|
38
|
+
"""
|
|
39
|
+
return _call(self.backend, "diff", "Diff", a, b)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class NowCommand:
|
|
43
|
+
"""[EN]
|
|
44
|
+
Python facade for the public C# KernelClock NowCommand.
|
|
45
|
+
|
|
46
|
+
[JA]
|
|
47
|
+
公開 C# KernelClock NowCommand に対応する Python facade です。
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def run() -> None:
|
|
52
|
+
"""[EN] Executes the C# now command.
|
|
53
|
+
|
|
54
|
+
[JA] C# now command を実行します。
|
|
55
|
+
"""
|
|
56
|
+
call_static(
|
|
57
|
+
"AIKernel.Tools.Inspectors.KernelClock.Commands.NowCommand",
|
|
58
|
+
"AIKernel.Tools.Inspectors.KernelClock",
|
|
59
|
+
"Run",
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class TimelineCommand:
|
|
64
|
+
"""[EN]
|
|
65
|
+
Python facade for the public C# KernelClock TimelineCommand.
|
|
66
|
+
|
|
67
|
+
[JA]
|
|
68
|
+
公開 C# KernelClock TimelineCommand に対応する Python facade です。
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
@staticmethod
|
|
72
|
+
def run() -> None:
|
|
73
|
+
"""[EN] Executes the C# timeline command.
|
|
74
|
+
|
|
75
|
+
[JA] C# timeline command を実行します。
|
|
76
|
+
"""
|
|
77
|
+
call_static(
|
|
78
|
+
"AIKernel.Tools.Inspectors.KernelClock.Commands.TimelineCommand",
|
|
79
|
+
"AIKernel.Tools.Inspectors.KernelClock",
|
|
80
|
+
"Run",
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class InfoCommand:
|
|
85
|
+
"""[EN]
|
|
86
|
+
Python facade for the public C# VFS InfoCommand.
|
|
87
|
+
|
|
88
|
+
[JA]
|
|
89
|
+
公開 C# VFS InfoCommand に対応する Python facade です。
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
@staticmethod
|
|
93
|
+
def run(path: str = ".") -> None:
|
|
94
|
+
"""[EN] Executes the C# VFS info command.
|
|
95
|
+
|
|
96
|
+
[JA] C# VFS info command を実行します。
|
|
97
|
+
"""
|
|
98
|
+
call_static(
|
|
99
|
+
"AIKernel.Tools.Inspectors.Vfs.Commands.InfoCommand",
|
|
100
|
+
"AIKernel.Tools.Inspectors.Vfs",
|
|
101
|
+
"Run",
|
|
102
|
+
path,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class TreeCommand:
|
|
107
|
+
"""[EN]
|
|
108
|
+
Python facade for the public C# VFS TreeCommand.
|
|
109
|
+
|
|
110
|
+
[JA]
|
|
111
|
+
公開 C# VFS TreeCommand に対応する Python facade です。
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
@staticmethod
|
|
115
|
+
def run(path: str = ".") -> None:
|
|
116
|
+
"""[EN] Executes the C# VFS tree command.
|
|
117
|
+
|
|
118
|
+
[JA] C# VFS tree command を実行します。
|
|
119
|
+
"""
|
|
120
|
+
call_static(
|
|
121
|
+
"AIKernel.Tools.Inspectors.Vfs.Commands.TreeCommand",
|
|
122
|
+
"AIKernel.Tools.Inspectors.Vfs",
|
|
123
|
+
"Run",
|
|
124
|
+
path,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _call(target: Any, python_name: str, managed_name: str, *args) -> Any:
|
|
129
|
+
if target is None:
|
|
130
|
+
raise RuntimeError(
|
|
131
|
+
f"Inspector requires a backend exposing {python_name}() or {managed_name}()."
|
|
132
|
+
)
|
|
133
|
+
method = getattr(target, python_name, None) or getattr(target, managed_name, None)
|
|
134
|
+
if method is None:
|
|
135
|
+
raise AttributeError(f"inspector backend must expose {python_name}()")
|
|
136
|
+
return method(*args)
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Mapping
|
|
4
|
+
|
|
5
|
+
from aikernel_tools.native import load_tools_runtime
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ManagedObject:
|
|
9
|
+
"""[EN]
|
|
10
|
+
Base wrapper for public C# Tools objects.
|
|
11
|
+
|
|
12
|
+
[JA]
|
|
13
|
+
公開 C# Tools object の基底 wrapper です。
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, managed):
|
|
17
|
+
self._managed = managed
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def managed(self):
|
|
21
|
+
"""[EN] Return the underlying C# object.
|
|
22
|
+
|
|
23
|
+
[JA] 背後の C# object を返します。
|
|
24
|
+
"""
|
|
25
|
+
return self._managed
|
|
26
|
+
|
|
27
|
+
def to_managed(self):
|
|
28
|
+
"""[EN] Return the underlying C# object for contract calls.
|
|
29
|
+
|
|
30
|
+
[JA] 契約呼び出し用に背後の C# object を返します。
|
|
31
|
+
"""
|
|
32
|
+
return self._managed
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def to_dictionary(values: Mapping[str, str]):
|
|
36
|
+
"""[EN]
|
|
37
|
+
Convert a Python mapping to System.Collections.Generic.Dictionary.
|
|
38
|
+
|
|
39
|
+
[JA]
|
|
40
|
+
Python mapping を System.Collections.Generic.Dictionary に変換します。
|
|
41
|
+
"""
|
|
42
|
+
load_tools_runtime()
|
|
43
|
+
from System.Collections.Generic import Dictionary # type: ignore[import-not-found]
|
|
44
|
+
|
|
45
|
+
dictionary = Dictionary[str, str]()
|
|
46
|
+
for key, value in values.items():
|
|
47
|
+
dictionary[str(key)] = str(value)
|
|
48
|
+
return dictionary
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def to_string_list(values):
|
|
52
|
+
"""[EN]
|
|
53
|
+
Convert Python values to System.Collections.Generic.List[str].
|
|
54
|
+
|
|
55
|
+
[JA]
|
|
56
|
+
Python values を System.Collections.Generic.List[str] に変換します。
|
|
57
|
+
"""
|
|
58
|
+
load_tools_runtime()
|
|
59
|
+
from System.Collections.Generic import List # type: ignore[import-not-found]
|
|
60
|
+
|
|
61
|
+
items = List[str]()
|
|
62
|
+
for value in values:
|
|
63
|
+
items.Add(str(value))
|
|
64
|
+
return items
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def managed_type(type_name: str, assembly_name: str):
|
|
68
|
+
"""[EN]
|
|
69
|
+
Resolve a C# type by assembly-qualified name.
|
|
70
|
+
|
|
71
|
+
[JA]
|
|
72
|
+
assembly-qualified name で C# type を解決します。
|
|
73
|
+
"""
|
|
74
|
+
load_tools_runtime()
|
|
75
|
+
from System import Type # type: ignore[import-not-found]
|
|
76
|
+
|
|
77
|
+
resolved = Type.GetType(f"{type_name}, {assembly_name}")
|
|
78
|
+
if resolved is None:
|
|
79
|
+
raise RuntimeError(f"Unable to resolve managed type: {type_name}, {assembly_name}")
|
|
80
|
+
return resolved
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def create_managed(type_name: str, assembly_name: str, *args):
|
|
84
|
+
"""[EN]
|
|
85
|
+
Create a managed object through reflection.
|
|
86
|
+
|
|
87
|
+
[JA]
|
|
88
|
+
reflection 経由で managed object を作成します。
|
|
89
|
+
"""
|
|
90
|
+
constructors = managed_type(type_name, assembly_name).GetConstructors()
|
|
91
|
+
if len(constructors) == 0:
|
|
92
|
+
raise RuntimeError(f"Unable to resolve managed constructor: {type_name}")
|
|
93
|
+
return constructors[0].Invoke(_object_array(args))
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def call_static(type_name: str, assembly_name: str, method_name: str, *args):
|
|
97
|
+
"""[EN]
|
|
98
|
+
Invoke a public static C# method through reflection.
|
|
99
|
+
|
|
100
|
+
[JA]
|
|
101
|
+
公開 static C# method を reflection 経由で呼び出します。
|
|
102
|
+
"""
|
|
103
|
+
method = managed_type(type_name, assembly_name).GetMethod(method_name)
|
|
104
|
+
if method is None:
|
|
105
|
+
raise RuntimeError(f"Unable to resolve managed method: {type_name}.{method_name}")
|
|
106
|
+
return method.Invoke(None, _object_array(args))
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _object_array(values):
|
|
110
|
+
load_tools_runtime()
|
|
111
|
+
from System import Array, Object # type: ignore[import-not-found]
|
|
112
|
+
|
|
113
|
+
items = Array[Object](len(values))
|
|
114
|
+
for index, value in enumerate(values):
|
|
115
|
+
items[index] = value
|
|
116
|
+
return items
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from .session import ReplaySession
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class ReplayEngine:
|
|
11
|
+
"""[EN]
|
|
12
|
+
Thin replay facade that delegates to a public Tools backend.
|
|
13
|
+
|
|
14
|
+
[JA]
|
|
15
|
+
公開 Tools backend に委譲する薄い replay facade です。
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
backend: Any | None = None
|
|
19
|
+
_session: ReplaySession = ReplaySession()
|
|
20
|
+
|
|
21
|
+
def load(self, path: str) -> "ReplayEngine":
|
|
22
|
+
"""[EN] Load replay material through the configured backend.
|
|
23
|
+
|
|
24
|
+
[JA] 設定された backend 経由で replay material を読み込みます。
|
|
25
|
+
"""
|
|
26
|
+
result = _call(self.backend, "load", "Load", path)
|
|
27
|
+
if result is not None:
|
|
28
|
+
self._session = _coerce_session(result)
|
|
29
|
+
return self
|
|
30
|
+
|
|
31
|
+
def run(self):
|
|
32
|
+
"""[EN] Run replay through the configured backend.
|
|
33
|
+
|
|
34
|
+
[JA] 設定された backend 経由で replay を実行します。
|
|
35
|
+
"""
|
|
36
|
+
result = _call(self.backend, "run", "Run")
|
|
37
|
+
if result is not None:
|
|
38
|
+
self._session = _coerce_session(result)
|
|
39
|
+
return result
|
|
40
|
+
|
|
41
|
+
def step(self):
|
|
42
|
+
"""[EN] Advance replay by one deterministic step.
|
|
43
|
+
|
|
44
|
+
[JA] replay を決定論的に 1 step 進めます。
|
|
45
|
+
"""
|
|
46
|
+
result = _call(self.backend, "step", "Step")
|
|
47
|
+
if result is not None and not isinstance(result, (str, int, float, bool)):
|
|
48
|
+
self._session = _coerce_session(result)
|
|
49
|
+
return result
|
|
50
|
+
|
|
51
|
+
def session(self) -> ReplaySession:
|
|
52
|
+
"""[EN] Return the current replay session view.
|
|
53
|
+
|
|
54
|
+
[JA] 現在の replay session view を返します。
|
|
55
|
+
"""
|
|
56
|
+
result = _call(self.backend, "session", "Session", required=False)
|
|
57
|
+
if result is not None:
|
|
58
|
+
self._session = _coerce_session(result)
|
|
59
|
+
return self._session
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _call(target: Any, python_name: str, managed_name: str, *args, required: bool = True) -> Any:
|
|
63
|
+
if target is None:
|
|
64
|
+
if required:
|
|
65
|
+
raise RuntimeError(
|
|
66
|
+
f"ReplayEngine requires a backend exposing {python_name}() or {managed_name}()."
|
|
67
|
+
)
|
|
68
|
+
return None
|
|
69
|
+
method = getattr(target, python_name, None) or getattr(target, managed_name, None)
|
|
70
|
+
if method is None:
|
|
71
|
+
if required:
|
|
72
|
+
raise AttributeError(f"replay backend must expose {python_name}()")
|
|
73
|
+
return None
|
|
74
|
+
return method(*args)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _coerce_session(value: Any) -> ReplaySession:
|
|
78
|
+
if isinstance(value, ReplaySession):
|
|
79
|
+
return value
|
|
80
|
+
return ReplaySession.from_managed(value)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import Any, Mapping, Sequence
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass(frozen=True)
|
|
8
|
+
class ReplaySession:
|
|
9
|
+
"""[EN]
|
|
10
|
+
Public replay session contract exposed to Python.
|
|
11
|
+
|
|
12
|
+
[JA]
|
|
13
|
+
Python に公開される replay session 契約です。
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
events: Sequence[Any] = field(default_factory=tuple)
|
|
17
|
+
state: str = "Created"
|
|
18
|
+
metadata: Mapping[str, str] = field(default_factory=dict)
|
|
19
|
+
|
|
20
|
+
@classmethod
|
|
21
|
+
def from_managed(cls, managed) -> "ReplaySession":
|
|
22
|
+
"""[EN] Create a Python session view from a managed object.
|
|
23
|
+
|
|
24
|
+
[JA] managed object から Python session view を作成します。
|
|
25
|
+
"""
|
|
26
|
+
events = getattr(managed, "Events", ())
|
|
27
|
+
state = getattr(managed, "State", "Created")
|
|
28
|
+
metadata = getattr(managed, "Metadata", {})
|
|
29
|
+
return cls(tuple(events), str(state), _metadata_to_dict(metadata))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _metadata_to_dict(metadata) -> dict[str, str]:
|
|
33
|
+
keys = getattr(metadata, "Keys", None)
|
|
34
|
+
if keys is not None:
|
|
35
|
+
return {str(key): str(metadata[key]) for key in keys}
|
|
36
|
+
return {str(key): str(value) for key, value in dict(metadata).items()}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aikernel-tools
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Python wrapper for AIKernel.Tools v0.1.1 instrumentation contracts with bundled managed assemblies and pythonnet loading.
|
|
5
|
+
Author: Takuya Sogawa
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/AIKernel-NET/AIKernel.Tools
|
|
8
|
+
Project-URL: Repository, https://github.com/AIKernel-NET/AIKernel.Tools
|
|
9
|
+
Project-URL: Documentation, https://aikernel.net/reference/
|
|
10
|
+
Project-URL: Issues, https://github.com/AIKernel-NET/AIKernel.Tools/issues
|
|
11
|
+
Project-URL: Releases, https://github.com/AIKernel-NET/AIKernel.Tools/releases
|
|
12
|
+
Keywords: aikernel,tools,instrumentation,deterministic-debugging,capability,inspector,canonical-formatting,pythonnet
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Requires-Dist: pythonnet>=3.0.3
|
|
21
|
+
Provides-Extra: test
|
|
22
|
+
Requires-Dist: pytest>=9.0; extra == "test"
|
|
23
|
+
|
|
24
|
+
# aikernel-tools
|
|
25
|
+
|
|
26
|
+
[日本語](README-ja.md)
|
|
27
|
+
|
|
28
|
+
Python wrapper for the public instrumentation surface of AIKernel.Tools.
|
|
29
|
+
|
|
30
|
+
The package bundles the AIKernel.Tools managed assemblies and loads them through
|
|
31
|
+
pythonnet. Python code receives a single API surface for replay facades,
|
|
32
|
+
inspection facades, canonical chat-history formatting, and public capability
|
|
33
|
+
contract descriptors without re-implementing the internal C# semantics.
|
|
34
|
+
|
|
35
|
+
See [Python Tools Wrapper](../docs/python/index.md) for package scope, managed
|
|
36
|
+
assembly bundle requirements, Linux CoreCLR loading, and validation guidance.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install aikernel-tools
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from aikernel_tools import (
|
|
48
|
+
CanonicalFormatter,
|
|
49
|
+
ChatHistoryRecord,
|
|
50
|
+
InfoCommand,
|
|
51
|
+
MdExporter,
|
|
52
|
+
NowCommand,
|
|
53
|
+
RomExporter,
|
|
54
|
+
RomStorageCapability,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
capability = RomStorageCapability("tools.rom")
|
|
58
|
+
contract = capability.to_contract()
|
|
59
|
+
|
|
60
|
+
formatter = CanonicalFormatter()
|
|
61
|
+
rom = formatter.serialize([
|
|
62
|
+
ChatHistoryRecord("user", "hello", "2026-06-09T00:00:00+00:00")
|
|
63
|
+
])
|
|
64
|
+
|
|
65
|
+
markdown = MdExporter.to_markdown([
|
|
66
|
+
ChatHistoryRecord("assistant", "world", "2026-06-09T00:00:01+00:00")
|
|
67
|
+
])
|
|
68
|
+
history_rom = RomExporter.to_rom(
|
|
69
|
+
[ChatHistoryRecord("assistant", "world", "2026-06-09T00:00:01+00:00")],
|
|
70
|
+
namespace="python",
|
|
71
|
+
name="history",
|
|
72
|
+
)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`ReplayEngine`, `Inspector`, and `CanonicalFormatter` can also delegate to an
|
|
76
|
+
explicit backend object that exposes the same method names. `MdExporter`,
|
|
77
|
+
`RomExporter`, `ChatHistoryScraper`, and the inspector command facades such as
|
|
78
|
+
`NowCommand` / `InfoCommand` mirror the public C# names so Python callers can
|
|
79
|
+
address the same contract surface. This keeps Python as a contract boundary
|
|
80
|
+
while the implementation stays in the configured tooling runtime.
|
|
81
|
+
|
|
82
|
+
The wheel bundles `AIKernel.Tools.Instrumentation.dll`,
|
|
83
|
+
`AIKernel.Tools.Capability.RomStorage.dll`, inspector assemblies, AIKernel.NET
|
|
84
|
+
contract assemblies, AIKernel.Core dependencies, and `ChatHistoryProvider.dll`.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
aikernel_tools/__init__.py,sha256=xAzAnd6SxLtVsNZN6cU-6bU8fQnbolNxRxEgNzzJRRI,983
|
|
2
|
+
aikernel_tools/native/AIKernel.Abstractions.dll,sha256=ct_ZXuqaCQcyrtUF_GKPwUhpIp_MGZYfit_fW-6DUDY,77824
|
|
3
|
+
aikernel_tools/native/AIKernel.Common.dll,sha256=uMsc8OhzckZRUZoibtMmQ0X_b-Wa428JcEF8EF3VTsI,116736
|
|
4
|
+
aikernel_tools/native/AIKernel.Core.dll,sha256=xoHFmTJd98QzQUmCgdZXHo-pkSAcUJptsuNWHkHlFFI,634880
|
|
5
|
+
aikernel_tools/native/AIKernel.Dtos.dll,sha256=xBriUj9xyY7lC6iE6rdl5V3TlR7HZ2iiENzTFnH_6ZQ,460800
|
|
6
|
+
aikernel_tools/native/AIKernel.Enums.dll,sha256=cKGrqoo0xQupvW2X2vga9JARV3vwwFME2_iq6m9NwUM,17920
|
|
7
|
+
aikernel_tools/native/AIKernel.Tools.Capability.RomStorage.dll,sha256=R71TjOfdK-KidJpmqQWSyqgDCkPslYEP09Xio9ko2CQ,6144
|
|
8
|
+
aikernel_tools/native/AIKernel.Tools.Inspectors.ChatHistoryScraper.dll,sha256=QRkwqlare2JySG__4S561kvWiIGT0t6IZCMvtyaCM7k,43008
|
|
9
|
+
aikernel_tools/native/AIKernel.Tools.Inspectors.KernelClock.dll,sha256=CCEi3jThOre6SnEGuCbsM9C2p0ggwDdnuTiqIUvq7UU,7680
|
|
10
|
+
aikernel_tools/native/AIKernel.Tools.Inspectors.Vfs.dll,sha256=pgrMnGnXpYYjCxKnEiW3LV8BBgq0B7Ilv0sz5rIcH6c,12800
|
|
11
|
+
aikernel_tools/native/AIKernel.Tools.Instrumentation.dll,sha256=v_C0tmZCKASsdUKGmZQZNPhVkNx1fHpDoiNnP9rk7dg,17408
|
|
12
|
+
aikernel_tools/native/ChatHistoryProvider.dll,sha256=IPsxx3-objBPsPwnXQ5Byq0ARZcdUxbsNB4WBslhiko,24576
|
|
13
|
+
aikernel_tools/native/Microsoft.Extensions.Configuration.Abstractions.dll,sha256=wpXmwzhO1h5P6g_ENHmq3t-Bpgycl9Pb25JH9WLghG8,28496
|
|
14
|
+
aikernel_tools/native/Microsoft.Extensions.Configuration.Binder.dll,sha256=YBxW1vdUzJ87Qjs6SKXOEYBwefDvLEzb0BSAkLdAKxE,43344
|
|
15
|
+
aikernel_tools/native/Microsoft.Extensions.Configuration.dll,sha256=fZE845ofFXaIJkM8wGUZz3_6hI6HUhssvg5Td4Pvk8I,44840
|
|
16
|
+
aikernel_tools/native/Microsoft.Extensions.DependencyInjection.Abstractions.dll,sha256=ynCEIngvslgZlBoWoFfqltbRiwN-fly_3zQLegQ2K1c,65832
|
|
17
|
+
aikernel_tools/native/Microsoft.Extensions.DependencyInjection.dll,sha256=R_gXXTTpCH04WGRIA8VYy5z1Kym__aeW9lwcUn0baiI,95528
|
|
18
|
+
aikernel_tools/native/Microsoft.Extensions.Diagnostics.Abstractions.dll,sha256=NJMA67OaAt79XLk1U9XTfjEoHQpdPMPOsKBZEZPNVqQ,31016
|
|
19
|
+
aikernel_tools/native/Microsoft.Extensions.Diagnostics.dll,sha256=XtWGAnvEhVWHJ5l972Z4OqE-_d9SZbfAJqDjkDyqbFg,36136
|
|
20
|
+
aikernel_tools/native/Microsoft.Extensions.Http.dll,sha256=wqHsf53YAK78RbOfwfLp8KI7cyxTFUkthzpNdzjAJCc,92968
|
|
21
|
+
aikernel_tools/native/Microsoft.Extensions.Logging.Abstractions.dll,sha256=7CRKLbGd_-kM0pn6SwaRRWztNCoHi0qTzzcmqbQx6aw,66856
|
|
22
|
+
aikernel_tools/native/Microsoft.Extensions.Logging.dll,sha256=dNj9LXmX_GOEdOK9eZFkWKMEgeamkltQ5-lrS4UgMcM,51496
|
|
23
|
+
aikernel_tools/native/Microsoft.Extensions.Options.ConfigurationExtensions.dll,sha256=7jH3KS72OHrmPjIgIEKUPZ6J7DFCkWgFB7Jj-qZU5U0,21800
|
|
24
|
+
aikernel_tools/native/Microsoft.Extensions.Options.dll,sha256=ZENQ-MJATUR5uXolDtspWF5fr-wbbOhIauYAxQFf1_s,65320
|
|
25
|
+
aikernel_tools/native/Microsoft.Extensions.Primitives.dll,sha256=oHlMO6stfgyEjw3_s7mqS0POB9wKvRIuu3v23HlFLsQ,44840
|
|
26
|
+
aikernel_tools/native/YamlDotNet.dll,sha256=yylbyRxp4hK8ANPW-PKrkLu_h9HIBvAIgWvymM81g54,300032
|
|
27
|
+
aikernel_tools/native/__init__.py,sha256=NewAKKzfoxpSboiCnxYihpBq8r2fg6GUGilbgUebIpQ,5654
|
|
28
|
+
aikernel_tools/tools/__init__.py,sha256=i7WCAMfc-EgamvBtiqz5ibWn9ubyQ-dOqsCbix2GDZ8,905
|
|
29
|
+
aikernel_tools/tools/capabilities.py,sha256=7K9MeZKOOcKK1s3f95pBSeR20a9cHeQwVDaxyaTsTuc,4168
|
|
30
|
+
aikernel_tools/tools/formatter.py,sha256=uAvm5zS64UDvZMKAKtulK5VN5J_ExpNCZ1wE4tuZhvw,8269
|
|
31
|
+
aikernel_tools/tools/inspector.py,sha256=fmJ7eSD1vbkoV5U06o_eEgu7-m7vU27Y1GH5wf57wxI,3678
|
|
32
|
+
aikernel_tools/tools/managed.py,sha256=OO_UHxFFP0IyUp0HdkwtYs2JptWw4QUwAzxWSY9Faf4,3300
|
|
33
|
+
aikernel_tools/tools/replay.py,sha256=mkG9Wys7-BWJaSm7P85oe0TuUZ_O5jdoqV6t9SMDlEI,2557
|
|
34
|
+
aikernel_tools/tools/session.py,sha256=8AaZ8ewEyQKcoHXwGejBQX6jnidOeGVXq2BPQeFnCI0,1175
|
|
35
|
+
aikernel_tools-0.1.1.dist-info/METADATA,sha256=AyKHYn3a0lya3nCMuaPsX4mpiqcHhs4_bzlQP1bd9XU,3189
|
|
36
|
+
aikernel_tools-0.1.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
37
|
+
aikernel_tools-0.1.1.dist-info/top_level.txt,sha256=sQigt6kkgkUpxaaaJ_I-AsOUM-j__H5iNV1IImvfHuM,15
|
|
38
|
+
aikernel_tools-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aikernel_tools
|