hyperpocket 0.3.7__py3-none-any.whl → 0.4.0__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.
- hyperpocket/auth/provider.py +1 -0
- hyperpocket/auth/weaviate/context.py +12 -0
- hyperpocket/auth/weaviate/token_context.py +11 -0
- hyperpocket/auth/weaviate/token_handler.py +68 -0
- hyperpocket/auth/weaviate/token_schema.py +7 -0
- hyperpocket/cli/eject.py +2 -7
- hyperpocket/cli/pull.py +2 -7
- hyperpocket/config/settings.py +2 -1
- hyperpocket/pocket_core.py +41 -68
- hyperpocket/pocket_main.py +37 -16
- hyperpocket/repository/__init__.py +3 -4
- hyperpocket/repository/repository.py +6 -41
- hyperpocket/repository/tool_reference.py +28 -0
- hyperpocket/server/auth/weaviate.py +27 -0
- hyperpocket/server/server.py +127 -61
- hyperpocket/session/in_memory.py +13 -3
- hyperpocket/tool/__init__.py +0 -3
- hyperpocket/tool/dock/__init__.py +3 -0
- hyperpocket/tool/dock/dock.py +34 -0
- hyperpocket/tool/function/__init__.py +1 -1
- hyperpocket/tool/function/tool.py +62 -32
- hyperpocket/tool/tool.py +1 -9
- hyperpocket/tool_like.py +2 -1
- hyperpocket/util/generate_slug.py +4 -0
- hyperpocket/util/json_schema_to_model.py +5 -1
- {hyperpocket-0.3.7.dist-info → hyperpocket-0.4.0.dist-info}/METADATA +4 -1
- {hyperpocket-0.3.7.dist-info → hyperpocket-0.4.0.dist-info}/RECORD +30 -36
- hyperpocket/cli/sync.py +0 -17
- hyperpocket/repository/lock.py +0 -240
- hyperpocket/repository/lockfile.py +0 -62
- hyperpocket/server/tool/__init__.py +0 -10
- hyperpocket/server/tool/dto/script.py +0 -33
- hyperpocket/server/tool/wasm.py +0 -46
- hyperpocket/tool/wasm/README.md +0 -166
- hyperpocket/tool/wasm/__init__.py +0 -3
- hyperpocket/tool/wasm/browser.py +0 -63
- hyperpocket/tool/wasm/invoker.py +0 -41
- hyperpocket/tool/wasm/script.py +0 -134
- hyperpocket/tool/wasm/templates/__init__.py +0 -35
- hyperpocket/tool/wasm/templates/node.py +0 -87
- hyperpocket/tool/wasm/templates/python.py +0 -93
- hyperpocket/tool/wasm/tool.py +0 -163
- /hyperpocket/{server/tool/dto → auth/weaviate}/__init__.py +0 -0
- {hyperpocket-0.3.7.dist-info → hyperpocket-0.4.0.dist-info}/WHEEL +0 -0
- {hyperpocket-0.3.7.dist-info → hyperpocket-0.4.0.dist-info}/entry_points.txt +0 -0
    
        hyperpocket/tool/wasm/tool.py
    DELETED
    
    | @@ -1,163 +0,0 @@ | |
| 1 | 
            -
            import json
         | 
| 2 | 
            -
            import pathlib
         | 
| 3 | 
            -
            from typing import Any, Optional
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            import toml
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            from hyperpocket.auth import AuthProvider
         | 
| 8 | 
            -
            from hyperpocket.config import pocket_logger
         | 
| 9 | 
            -
            from hyperpocket.repository import Lock, Lockfile
         | 
| 10 | 
            -
            from hyperpocket.repository.lock import GitLock, LocalLock
         | 
| 11 | 
            -
            from hyperpocket.tool import Tool, ToolRequest
         | 
| 12 | 
            -
            from hyperpocket.tool.tool import ToolAuth
         | 
| 13 | 
            -
            from hyperpocket.tool.wasm.invoker import WasmInvoker
         | 
| 14 | 
            -
            from hyperpocket.tool.wasm.script import ScriptRuntime
         | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
            class WasmToolRequest(ToolRequest):
         | 
| 18 | 
            -
                lock: Lock
         | 
| 19 | 
            -
                rel_path: str
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                def __init__(self, lock: Lock, rel_path: str, tool_vars: dict):
         | 
| 22 | 
            -
                    self.lock = lock
         | 
| 23 | 
            -
                    self.rel_path = rel_path
         | 
| 24 | 
            -
                    self.overridden_tool_vars = tool_vars
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                def __str__(self):
         | 
| 27 | 
            -
                    return f"ToolRequest(lock={self.lock}, rel_path={self.rel_path})"
         | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
            def from_local(
         | 
| 31 | 
            -
                path: str, tool_vars: Optional[dict[str, str]] = None
         | 
| 32 | 
            -
            ) -> WasmToolRequest:
         | 
| 33 | 
            -
                if tool_vars is None:
         | 
| 34 | 
            -
                    tool_vars = dict()
         | 
| 35 | 
            -
                return WasmToolRequest(LocalLock(path), "", tool_vars)
         | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
            def from_git(
         | 
| 39 | 
            -
                repository: str, ref: str, rel_path: str, tool_vars: Optional[dict[str, str]] = None
         | 
| 40 | 
            -
            ) -> WasmToolRequest:
         | 
| 41 | 
            -
                if not tool_vars:
         | 
| 42 | 
            -
                    tool_vars = dict()
         | 
| 43 | 
            -
                return WasmToolRequest(
         | 
| 44 | 
            -
                    GitLock(repository_url=repository, git_ref=ref), rel_path, tool_vars
         | 
| 45 | 
            -
                )
         | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
            class WasmTool(Tool):
         | 
| 49 | 
            -
                """
         | 
| 50 | 
            -
                WasmTool is Tool executing local python method.
         | 
| 51 | 
            -
                """
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                _invoker: WasmInvoker = None
         | 
| 54 | 
            -
                pkg_lock: Lock = None
         | 
| 55 | 
            -
                rel_path: str
         | 
| 56 | 
            -
                runtime: ScriptRuntime = None
         | 
| 57 | 
            -
                json_schema: Optional[dict] = None
         | 
| 58 | 
            -
                readme: Optional[str] = None
         | 
| 59 | 
            -
             | 
| 60 | 
            -
                @property
         | 
| 61 | 
            -
                def invoker(self) -> WasmInvoker:
         | 
| 62 | 
            -
                    if not self._invoker:
         | 
| 63 | 
            -
                        self._invoker = WasmInvoker()
         | 
| 64 | 
            -
                    return self._invoker
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                @classmethod
         | 
| 67 | 
            -
                def from_tool_request(
         | 
| 68 | 
            -
                    cls, tool_req: WasmToolRequest, lockfile: Lockfile = None, **kwargs
         | 
| 69 | 
            -
                ) -> "WasmTool":
         | 
| 70 | 
            -
                    if not lockfile:
         | 
| 71 | 
            -
                        raise ValueError("lockfile is required")
         | 
| 72 | 
            -
                    tool_req.lock = lockfile.get_lock(tool_req.lock.key())
         | 
| 73 | 
            -
                    toolpkg_path = tool_req.lock.toolpkg_path()
         | 
| 74 | 
            -
                    rel_path = tool_req.rel_path
         | 
| 75 | 
            -
                    rootpath = pathlib.Path(toolpkg_path) / rel_path
         | 
| 76 | 
            -
                    schema_path = rootpath / "schema.json"
         | 
| 77 | 
            -
                    config_path = rootpath / "config.toml"
         | 
| 78 | 
            -
                    readme_path = rootpath / "README.md"
         | 
| 79 | 
            -
             | 
| 80 | 
            -
                    try:
         | 
| 81 | 
            -
                        with schema_path.open("r") as f:
         | 
| 82 | 
            -
                            json_schema = json.load(f)
         | 
| 83 | 
            -
                    except Exception as e:
         | 
| 84 | 
            -
                        pocket_logger.warning(
         | 
| 85 | 
            -
                            f"{toolpkg_path} failed to load json schema. error : {e}"
         | 
| 86 | 
            -
                        )
         | 
| 87 | 
            -
                        json_schema = None
         | 
| 88 | 
            -
             | 
| 89 | 
            -
                    default_tool_vars = dict()
         | 
| 90 | 
            -
                    try:
         | 
| 91 | 
            -
                        with config_path.open("r") as f:
         | 
| 92 | 
            -
                            config = toml.load(f)
         | 
| 93 | 
            -
                            name = config.get("name")
         | 
| 94 | 
            -
                            description = config.get("description")
         | 
| 95 | 
            -
                            if language := config.get("language"):
         | 
| 96 | 
            -
                                lang = language.lower()
         | 
| 97 | 
            -
                                if lang == "python":
         | 
| 98 | 
            -
                                    runtime = ScriptRuntime.Python
         | 
| 99 | 
            -
                                elif lang == "node":
         | 
| 100 | 
            -
                                    runtime = ScriptRuntime.Node
         | 
| 101 | 
            -
                                else:
         | 
| 102 | 
            -
                                    raise ValueError(f"The language `{lang}` is not supported.")
         | 
| 103 | 
            -
                            else:
         | 
| 104 | 
            -
                                raise ValueError("`language` field is required in config.toml")
         | 
| 105 | 
            -
                            auth = cls._get_auth(config)
         | 
| 106 | 
            -
                            default_tool_vars = config.get("tool_vars", {})
         | 
| 107 | 
            -
                    except Exception as e:
         | 
| 108 | 
            -
                        raise ValueError(f"Failed to load config.toml: {e}")
         | 
| 109 | 
            -
             | 
| 110 | 
            -
                    if readme_path.exists():
         | 
| 111 | 
            -
                        with readme_path.open("r") as f:
         | 
| 112 | 
            -
                            readme = f.read()
         | 
| 113 | 
            -
                    else:
         | 
| 114 | 
            -
                        readme = None
         | 
| 115 | 
            -
             | 
| 116 | 
            -
                    return cls(
         | 
| 117 | 
            -
                        name=name,
         | 
| 118 | 
            -
                        description=description,
         | 
| 119 | 
            -
                        argument_json_schema=json_schema,
         | 
| 120 | 
            -
                        auth=auth,
         | 
| 121 | 
            -
                        runtime=runtime,
         | 
| 122 | 
            -
                        readme=readme,
         | 
| 123 | 
            -
                        pkg_lock=tool_req.lock,
         | 
| 124 | 
            -
                        rel_path=tool_req.rel_path,
         | 
| 125 | 
            -
                        postprocessings=tool_req.postprocessings,
         | 
| 126 | 
            -
                        default_tool_vars=default_tool_vars,
         | 
| 127 | 
            -
                        overridden_tool_vars=tool_req.overridden_tool_vars,
         | 
| 128 | 
            -
                    )
         | 
| 129 | 
            -
             | 
| 130 | 
            -
                @classmethod
         | 
| 131 | 
            -
                def _get_auth(cls, config: dict) -> Optional[ToolAuth]:
         | 
| 132 | 
            -
                    auth = config.get("auth")
         | 
| 133 | 
            -
                    if not auth:
         | 
| 134 | 
            -
                        return
         | 
| 135 | 
            -
                    auth_provider = auth.get("auth_provider")
         | 
| 136 | 
            -
                    auth_handler = auth.get("auth_handler")
         | 
| 137 | 
            -
                    scopes = auth.get("scopes", [])
         | 
| 138 | 
            -
                    return ToolAuth(
         | 
| 139 | 
            -
                        auth_provider=AuthProvider.get_auth_provider(auth_provider),
         | 
| 140 | 
            -
                        auth_handler=auth_handler,
         | 
| 141 | 
            -
                        scopes=scopes,
         | 
| 142 | 
            -
                    )
         | 
| 143 | 
            -
             | 
| 144 | 
            -
                def template_arguments(self) -> dict[str, str]:
         | 
| 145 | 
            -
                    return {}
         | 
| 146 | 
            -
             | 
| 147 | 
            -
                def invoke(self, body: Any, envs: dict, **kwargs) -> str:
         | 
| 148 | 
            -
                    return self.invoker.invoke(
         | 
| 149 | 
            -
                        str(self.pkg_lock.toolpkg_path() / self.rel_path),
         | 
| 150 | 
            -
                        self.runtime,
         | 
| 151 | 
            -
                        body,
         | 
| 152 | 
            -
                        envs | self.tool_vars,
         | 
| 153 | 
            -
                        **kwargs,
         | 
| 154 | 
            -
                    )
         | 
| 155 | 
            -
             | 
| 156 | 
            -
                async def ainvoke(self, body: Any, envs: dict, **kwargs) -> str:
         | 
| 157 | 
            -
                    return await self.invoker.ainvoke(
         | 
| 158 | 
            -
                        str(self.pkg_lock.toolpkg_path() / self.rel_path),
         | 
| 159 | 
            -
                        self.runtime,
         | 
| 160 | 
            -
                        body,
         | 
| 161 | 
            -
                        envs | self.tool_vars,
         | 
| 162 | 
            -
                        **kwargs,
         | 
| 163 | 
            -
                    )
         | 
| 
            File without changes
         | 
| 
            File without changes
         | 
| 
            File without changes
         |