19
ItemDeprecatedToolkit,
20
ItemToolkit,
21
)
22
-from composio_client.types.tool_router import session_link_params, session_patch_params
22
+from composio_client.types.tool_router import (
23
+ session_attach_response,
24
+ session_create_response,
25
+ session_link_params,
26
+ session_patch_params,
27
+ session_patch_response,
28
+ session_retrieve_response,
29
+)
30
from composio_client.types.tool_router.session_execute_response import (
31
SessionExecuteResponse,
32
)
94
tools: t.Union[t.List[str], t.Literal["all"]]
95
96
97
+#: Server-side session configuration as returned by the API: toolkit and tool
98
+#: allowlists, tags, auth configs, connected accounts, ``manage_connections``,
99
+#: preload, sandbox (``workbench``), search and execute settings. The four
100
+#: Stainless response models carry the same fields.
101
+ToolRouterSessionConfig = t.Union[
102
+ session_create_response.Config,
103
+ session_retrieve_response.Config,
104
+ session_attach_response.Config,
105
+ session_patch_response.Config,
106
+]
107
+
108
+
109
class ToolRouterSession(t.Generic[TTool, TToolCollection]):
110
"""
111
A Composio session — the object returned by ``composio.create(...)`` /
124
125
Attributes:
126
session_id: Unique session identifier
127
+ config: Server-side session configuration as returned by the API,
128
+ refreshed in place by :meth:`update`
129
experimental: Experimental features (files, assistive prompt, etc.)
130
"""
131
132
#: Unique session identifier.
133
session_id: str
134
+ #: Server-side session configuration (toolkit/tool allowlists, tags,
135
+ #: preload, sandbox, manage_connections) as returned by the API. Refreshed
136
+ #: in place by :meth:`update`.
137
+ config: ToolRouterSessionConfig
138
#: Experimental capabilities available on this session.
139
experimental: "ToolRouterSessionExperimental"
140
150
session_id: str,
151
mcp: t.Any,
152
experimental: "ToolRouterSessionExperimental",
153
+ config: t.Optional[ToolRouterSessionConfig] = None,
154
custom_tools_map: t.Optional[CustomToolsMap] = None,
155
user_id: t.Optional[str] = None,
156
preload: t.Optional[ToolRouterSessionPreloadConfig] = None,
164
self._file_upload_path_deny_segments = file_upload_path_deny_segments
165
self._file_upload_dirs = file_upload_dirs
166
self.session_id = session_id
167
+ self.preload = preload or ToolRouterSessionPreloadConfig(tools=[])
168
+ # Sessions built from an API response always carry their config; the
169
+ # fallback only covers direct construction without one (tests).
170
+ self.config = config or session_create_response.Config(
171
+ user_id=user_id or "",
172
+ execute=session_create_response.ConfigExecute(),
173
+ search=session_create_response.ConfigSearch(),
174
+ preload=session_create_response.ConfigPreload(tools=self.preload.tools),
175
+ )
176
# The MCP endpoint exists on every session at runtime (kept for
177
# backwards compatibility), but is only typed via
178
# ToolRouterSessionWithMcp. Assign through setattr so type checkers do
179
# not surface `mcp` on the base class — MCP is an explicit opt-in.
180
setattr(self, "mcp", mcp)
181
self.experimental = experimental
147
- self.preload = preload or ToolRouterSessionPreloadConfig(tools=[])
182
self._custom_tools_map = custom_tools_map
183
self._user_id = user_id
184
self._preloaded_custom_tool_slugs = preloaded_custom_tool_slugs or []
943
t.Optional[session_patch_params.MultiAccount], "Omit"
944
] = omit,
945
preload: t.Union[session_patch_params.Preload, "Omit"] = omit,
912
- ) -> None:
946
+ ) -> ToolRouterSessionConfig:
947
"""Partially update the session configuration.
948
949
Only the fields provided will be changed; omitted fields are preserved.
916
- Mutates this session's ``preload`` in-place.
950
+ Mutates this session's ``config`` and ``preload`` in-place and returns
951
+ the updated session configuration.
952
953
Pass ``None`` for ``manage_connections``, ``sandbox``/``workbench``, or
954
``multi_account`` to clear the stored value.
981
multi_account=multi_account,
982
preload=preload,
983
)
984
+ self.config = response.config
985
self.preload = _session_preload_config(response.config.preload)
986
+ return self.config
987
988
def delete(self) -> ToolRouterSessionDeleteResponse:
989
"""