ommlds 0.0.0.dev448__py3-none-any.whl → 0.0.0.dev450__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.
Files changed (50) hide show
  1. ommlds/.omlish-manifests.json +1 -1
  2. ommlds/backends/google/protocol/__init__.py +3 -0
  3. ommlds/backends/google/protocol/_marshal.py +16 -0
  4. ommlds/backends/google/protocol/types.py +303 -76
  5. ommlds/backends/mlx/generation.py +1 -1
  6. ommlds/cli/main.py +27 -6
  7. ommlds/cli/sessions/chat/code.py +114 -0
  8. ommlds/cli/sessions/chat/interactive.py +2 -5
  9. ommlds/cli/sessions/chat/printing.py +1 -4
  10. ommlds/cli/sessions/chat/prompt.py +8 -1
  11. ommlds/cli/sessions/chat/state.py +1 -0
  12. ommlds/cli/sessions/chat/tools.py +17 -7
  13. ommlds/cli/tools/config.py +1 -0
  14. ommlds/cli/tools/inject.py +11 -3
  15. ommlds/minichain/__init__.py +4 -0
  16. ommlds/minichain/backends/impls/google/chat.py +66 -11
  17. ommlds/minichain/backends/impls/google/tools.py +149 -0
  18. ommlds/minichain/lib/code/prompts.py +6 -0
  19. ommlds/minichain/lib/fs/binfiles.py +108 -0
  20. ommlds/minichain/lib/fs/context.py +112 -0
  21. ommlds/minichain/lib/fs/errors.py +95 -0
  22. ommlds/minichain/lib/fs/suggestions.py +36 -0
  23. ommlds/minichain/lib/fs/tools/__init__.py +0 -0
  24. ommlds/minichain/lib/fs/tools/ls.py +38 -0
  25. ommlds/minichain/lib/fs/tools/read.py +115 -0
  26. ommlds/minichain/lib/fs/tools/recursivels/__init__.py +0 -0
  27. ommlds/minichain/lib/fs/tools/recursivels/execution.py +40 -0
  28. ommlds/minichain/lib/todo/__init__.py +0 -0
  29. ommlds/minichain/lib/todo/context.py +27 -0
  30. ommlds/minichain/lib/todo/tools/__init__.py +0 -0
  31. ommlds/minichain/lib/todo/tools/read.py +39 -0
  32. ommlds/minichain/lib/todo/tools/write.py +275 -0
  33. ommlds/minichain/lib/todo/types.py +55 -0
  34. ommlds/minichain/tools/execution/context.py +34 -14
  35. ommlds/minichain/tools/execution/errors.py +15 -0
  36. ommlds/minichain/tools/execution/reflect.py +0 -3
  37. ommlds/minichain/tools/jsonschema.py +11 -1
  38. ommlds/minichain/tools/reflect.py +47 -15
  39. ommlds/minichain/tools/types.py +9 -0
  40. ommlds/minichain/utils.py +27 -0
  41. {ommlds-0.0.0.dev448.dist-info → ommlds-0.0.0.dev450.dist-info}/METADATA +3 -3
  42. {ommlds-0.0.0.dev448.dist-info → ommlds-0.0.0.dev450.dist-info}/RECORD +49 -29
  43. ommlds/minichain/lib/fs/ls/execution.py +0 -32
  44. /ommlds/minichain/lib/{fs/ls → code}/__init__.py +0 -0
  45. /ommlds/minichain/lib/fs/{ls → tools/recursivels}/rendering.py +0 -0
  46. /ommlds/minichain/lib/fs/{ls → tools/recursivels}/running.py +0 -0
  47. {ommlds-0.0.0.dev448.dist-info → ommlds-0.0.0.dev450.dist-info}/WHEEL +0 -0
  48. {ommlds-0.0.0.dev448.dist-info → ommlds-0.0.0.dev450.dist-info}/entry_points.txt +0 -0
  49. {ommlds-0.0.0.dev448.dist-info → ommlds-0.0.0.dev450.dist-info}/licenses/LICENSE +0 -0
  50. {ommlds-0.0.0.dev448.dist-info → ommlds-0.0.0.dev450.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,275 @@
1
+ """
2
+ TODO:
3
+ - ContentNamespace
4
+ """
5
+ import typing as ta
6
+
7
+ from omlish import lang
8
+
9
+ from ....tools.execution.catalog import ToolCatalogEntry
10
+ from ....tools.execution.reflect import reflect_tool_catalog_entry
11
+ from ....tools.reflect import tool_spec_override
12
+ from ..context import todo_tool_context
13
+ from ..types import TODO_ITEM_FIELD_DESCS
14
+ from ..types import TodoItem
15
+
16
+
17
+ ##
18
+
19
+
20
+ @tool_spec_override(
21
+ desc=f"""
22
+ Use this tool to create and manage a structured list of todo items corresponding to subtasks for your current
23
+ session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user. It
24
+ also helps the user understand the progress of the overall task and progress of their requests.
25
+
26
+ A todo item is comprised of the following fields:
27
+ - id: {TODO_ITEM_FIELD_DESCS['id']}
28
+ - content: {TODO_ITEM_FIELD_DESCS['content']}
29
+ - priority: {TODO_ITEM_FIELD_DESCS['priority']}
30
+ - status: {TODO_ITEM_FIELD_DESCS['status']}
31
+
32
+ Todo item priorities are as follows:
33
+ - pending: Task not yet started.
34
+ - in_progress: Currently working on (limit to ONE task at a time).
35
+ - completed: Task finished successfully.
36
+ - cancelled: Task no longer needed.
37
+
38
+ Manage todo items in the following manner:
39
+ - Update todo item status in real-time as you work.
40
+ - Mark todo items complete IMMEDIATELY after finishing (don't batch completions).
41
+ - Only have ONE todo item task in_progress at any time.
42
+ - Complete current todo item tasks before starting new ones.
43
+ - Cancel todo items that become irrelevant.
44
+
45
+ Breakdown tasks in the following manner:
46
+ - Create specific, actionable items.
47
+ - Break complex tasks into smaller, manageable steps.
48
+ - Use clear, descriptive task names.
49
+
50
+ Use this tool proactively in these scenarios:
51
+ - Complex multi-step tasks - When a task requires 3 or more distinct steps or actions.
52
+ - Non-trivial and complex tasks - Tasks that require careful planning or multiple operations.
53
+ - User explicitly requests todo list - When the user directly asks you to use the todo list.
54
+ - User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated).
55
+ - After receiving new instructions - Immediately capture user requirements as todos. Feel free to edit the todo
56
+ list based on new information.
57
+ - After completing a task - Mark it complete and add any new follow-up tasks
58
+ - When you start working on a new task, mark the todo item as in_progress. Ideally you should only have one todo
59
+ item as in_progress at a time. Complete existing tasks before starting new ones.
60
+
61
+ Skip using this tool when:
62
+ - There is only a single, straightforward task.
63
+ - The task is trivial and tracking it provides no organizational benefit.
64
+ - The task can be completed in less than 3 trivial steps.
65
+ - The task is purely conversational or informational.
66
+
67
+ You should not use this tool if there is only one trivial task to do. In this case you are better off just doing
68
+ the task directly.
69
+
70
+ ## Examples of WHEN to use the todo list
71
+
72
+ <example>
73
+ <user>
74
+ I want to add a dark mode toggle to the application settings. Make sure you run the tests and build when
75
+ you're done!
76
+ </user>
77
+ <assistant>
78
+ I'll help add a dark mode toggle to your application settings. Let me create a todo list to track this
79
+ implementation.
80
+ </assistant>
81
+ <action>
82
+ * Creates todo list with the following items *
83
+ 1. Create dark mode toggle component in Settings page
84
+ 2. Add dark mode state management (context/store)
85
+ 3. Implement CSS-in-JS styles for dark theme
86
+ 4. Update existing components to support theme switching
87
+ 5. Run tests and build process, addressing any failures or errors that occur
88
+
89
+ * Begins working on the first task *
90
+ </action>
91
+ <reasoning>
92
+ The assistant used the todo list because:
93
+ - Adding dark mode is a multi-step feature requiring UI, state management, and styling changes.
94
+ - The user explicitly requested tests and build be run afterward.
95
+ - The assistant inferred that tests and build need to pass by adding "Ensure tests and build succeed" as
96
+ the final task.
97
+ </reasoning>
98
+ </example>
99
+
100
+ <example>
101
+ <user>
102
+ Help me rename the function getCwd to getCurrentWorkingDirectory across my project
103
+ </user>
104
+ <assistant>
105
+ Let me first search through your codebase to find all occurrences of 'getCwd'.
106
+ </assistant>
107
+ <action>
108
+ * Uses grep or search tools to locate all instances of getCwd in the codebase *
109
+ </action>
110
+ <assistant>
111
+ I've found 15 instances of 'getCwd' across 8 different files. Let me create a todo list to track these
112
+ changes.
113
+ </assistant>
114
+ <action>
115
+ * Creates todo list with specific items for each file that needs updating *
116
+ </action>
117
+ <reasoning>
118
+ The assistant used the todo list because:
119
+ - First, the assistant searched to understand the scope of the task.
120
+ - Upon finding multiple occurrences across different files, it determined this was a complex task with
121
+ multiple steps.
122
+ - The todo list helps ensure every instance is tracked and updated systematically.
123
+ - This approach prevents missing any occurrences and maintains code consistency.
124
+ </reasoning>
125
+ </example>
126
+
127
+ <example>
128
+ <user>
129
+ I need to implement these features for my e-commerce site: user registration, product catalog, shopping
130
+ cart, and checkout flow.
131
+ </user>
132
+ <assistant>
133
+ I'll help implement these features. First, let's add all the features to the todo list.
134
+ </assistant>
135
+ <action>
136
+ * Creates a todo list breaking down each feature into specific tasks based on the project architecture *
137
+ </action>
138
+ <assistant>
139
+ Let's start with user registration. This will involve creating database models, API endpoints, and
140
+ frontend forms that integrate with your existing authentication system.
141
+ </assistant>
142
+ <reasoning>
143
+ The assistant used the todo list because:
144
+ - The user provided multiple complex features to implement in a comma separated list.
145
+ - The todo list helps organize these large features into manageable tasks.
146
+ - This approach allows for tracking progress across the entire implementation.
147
+ </reasoning>
148
+ </example>
149
+
150
+ <example>
151
+ <user>
152
+ Can you help optimize my React application? It's rendering slowly and has performance issues.
153
+ </user>
154
+ <assistant>
155
+ I'll help optimize your React application. First, let me examine your codebase to identify potential
156
+ performance bottlenecks.
157
+ </assistant>
158
+ <action>
159
+ * Reviews component structure, render patterns, state management, and data fetching *
160
+ </action>
161
+ <assistant>
162
+ After analyzing your codebase, I've identified several performance issues. Let me create a todo list to
163
+ track our optimization efforts.
164
+ </assistant>
165
+ <action>
166
+ * Creates todo list with the following items *
167
+ 1. Implement memoization for expensive calculations in ProductList
168
+ 2. Add virtualization for long lists in Dashboard
169
+ 3. Optimize image loading in Gallery component
170
+ 4. Fix state update loops in ShoppingCart
171
+ 5. Review bundle size and implement code splitting
172
+ </action>
173
+ <assistant>
174
+ Let's start by implementing memoization for the expensive calculations in your ProductList component.
175
+ </assistant>
176
+ <reasoning>
177
+ The assistant used the todo list because:
178
+ - First, the assistant examined the codebase to identify specific performance issues.
179
+ - Based on this analysis, it identified multiple optimization opportunities.
180
+ - Performance optimization is a non-trivial task requiring multiple steps.
181
+ - The todo list helps methodically track improvements across different components.
182
+ - This systematic approach ensures all performance bottlenecks are addressed.
183
+ </reasoning>
184
+ </example>
185
+
186
+ ## Examples of when NOT to use the todo list
187
+
188
+ <example>
189
+ <user>
190
+ How do I print 'Hello World' in Python?
191
+ </user>
192
+ <assistant>
193
+ In Python, you can print "Hello World" with this simple code:
194
+
195
+ print("Hello World")
196
+
197
+ This will output the text "Hello World" to the console when executed.
198
+ </assistant>
199
+ <reasoning>
200
+ The assistant did not use the todo list because this is a single, trivial task that can be completed in
201
+ one step. There's no need to track multiple tasks or steps for such a straightforward request.
202
+ </reasoning>
203
+ </counter>
204
+
205
+ <example>
206
+ <user>
207
+ What does the git status command do?
208
+ </user>
209
+ <assistant>
210
+ The git status command shows the current state of your working directory and staging area. It displays
211
+ which changes have been staged, which haven't, and which files aren't being tracked by Git. This is a
212
+ fundamental command for understanding the current state of your repository before making commits.
213
+ </assistant>
214
+ <reasoning>
215
+ The assistant did not use the todo list because this is an informational request with no actual coding
216
+ task to complete. The user is simply asking for an explanation, not for the assistant to perform
217
+ multiple steps or tasks.
218
+ </reasoning>
219
+ </example>
220
+
221
+ <example>
222
+ <user>
223
+ Can you add a comment to the calculateTotal function to explain what it does?
224
+ </user>
225
+ <assistant>
226
+ Sure, let me add a comment to the calculateTotal function to explain what it does.
227
+ </assistant>
228
+ <action>
229
+ * Uses the Edit tool to add a comment to the calculateTotal function *
230
+ </action>
231
+ <reasoning>
232
+ The assistant did not use the todo list because this is a single, straightforward task confined to one
233
+ location in the code. Adding a comment doesn't require tracking multiple steps or systematic
234
+ organization.
235
+ </reasoning>
236
+ </example>
237
+
238
+ <example>
239
+ <user>
240
+ Run npm install for me and tell me what happens.
241
+ </user>
242
+ <assistant>
243
+ I'll run the npm install command for you.
244
+ </assistant>
245
+ <action>
246
+ * Executes: npm install *
247
+ </action>
248
+ <assistant>
249
+ The command completed successfully. Here's the output:
250
+
251
+ [Output of npm install command]
252
+
253
+ All dependencies have been installed according to your package.json file.
254
+ </assistant>
255
+ <reasoning>
256
+ The assistant did not use the todo list because this is a single command execution with immediate
257
+ results. There are no multiple steps to track or organize, making the todo list unnecessary for this
258
+ straightforward task.
259
+ </reasoning>
260
+ </example>
261
+
262
+ When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you
263
+ complete all requirements successfully.
264
+ """,
265
+ )
266
+ def execute_todo_write_tool(todo_items: ta.Sequence[TodoItem]) -> str:
267
+ ctx = todo_tool_context()
268
+ ctx.set_items(todo_items)
269
+
270
+ return 'Todo list updated.'
271
+
272
+
273
+ @lang.cached_function
274
+ def todo_write_tool() -> ToolCatalogEntry:
275
+ return reflect_tool_catalog_entry(execute_todo_write_tool)
@@ -0,0 +1,55 @@
1
+ """
2
+ TODO:
3
+ - enums lol
4
+ - * with ToolParam-like desc metadata somehow *
5
+ """
6
+ import dataclasses as dc
7
+ import typing as ta
8
+
9
+ from omlish import lang
10
+
11
+ from ...tools.reflect import tool_param_metadata
12
+ from ...tools.types import ToolParam
13
+ from ...utils import join_human_readable_str_list
14
+ from ...utils import str_literal_values
15
+
16
+
17
+ ##
18
+
19
+
20
+ TodoStatus: ta.TypeAlias = ta.Literal[
21
+ 'pending',
22
+ 'in_progress',
23
+ 'completed',
24
+ 'cancelled',
25
+ ]
26
+
27
+ TOOL_STATUSES: ta.Sequence[str] = str_literal_values(TodoStatus)
28
+
29
+
30
+ ToolPriority: ta.TypeAlias = ta.Literal[
31
+ 'high',
32
+ 'medium',
33
+ 'low',
34
+ ]
35
+
36
+ TOOL_PRIORITIES: ta.Sequence[str] = str_literal_values(ToolPriority)
37
+
38
+
39
+ @dc.dataclass(frozen=True, kw_only=True)
40
+ class TodoItem(lang.Final):
41
+ id: str = dc.field(metadata=tool_param_metadata(desc='A unique identifier for this todo item.'))
42
+ content: str = dc.field(metadata=tool_param_metadata(desc='A brief description of the task.'))
43
+ priority: ToolPriority = dc.field(metadata=tool_param_metadata(
44
+ desc=f'Priority of the task: {join_human_readable_str_list(map(repr, TOOL_PRIORITIES))}.',
45
+ ))
46
+
47
+ status: TodoStatus = dc.field(metadata=tool_param_metadata(
48
+ desc=f'Current status of the task: {join_human_readable_str_list(map(repr, TOOL_STATUSES))}.',
49
+ ))
50
+
51
+
52
+ TODO_ITEM_FIELD_DESCS: ta.Mapping[str, str] = {
53
+ f.name: f.metadata[ToolParam].desc
54
+ for f in dc.fields(TodoItem) # noqa
55
+ }
@@ -2,8 +2,8 @@ import contextlib
2
2
  import contextvars
3
3
  import typing as ta
4
4
 
5
+ from omlish import check
5
6
  from omlish import collections as col
6
- from omlish import dataclasses as dc
7
7
  from omlish import lang
8
8
 
9
9
 
@@ -13,30 +13,34 @@ T = ta.TypeVar('T')
13
13
  ##
14
14
 
15
15
 
16
- @dc.dataclass(frozen=True)
17
16
  class ToolContext(lang.Final):
18
- dct: col.TypeMap = col.TypeMap()
17
+ def __init__(self, *items: ta.Any) -> None:
18
+ super().__init__()
19
19
 
20
- @classmethod
21
- def new(cls, *objs: ta.Any) -> 'ToolContext':
22
- return cls(col.TypeMap(objs))
20
+ self._dct: col.TypeMap = col.TypeMap(items)
21
+ if ToolContext in self._dct:
22
+ raise KeyError(ToolContext)
23
23
 
24
- #
24
+ def __repr__(self) -> str:
25
+ return f'{self.__class__.__name__}<{", ".join(ic.__name__ for ic in self._dct)}>'
25
26
 
26
27
  def __len__(self) -> int:
27
- return len(self.dct)
28
+ return len(self._dct)
28
29
 
29
30
  def __iter__(self) -> ta.Iterator[ta.Any]:
30
- return iter(self.dct)
31
+ return iter(self._dct)
32
+
33
+ def __contains__(self, ty: type[T]) -> bool:
34
+ return ty in self._dct
31
35
 
32
36
  def get(self, ty: type[T]) -> T | None:
33
- return self.dct.get(ty)
37
+ return self._dct.get(ty)
34
38
 
35
39
  def __getitem__(self, cls: type[T]) -> T:
36
- return self.dct[cls]
40
+ return self._dct[cls]
37
41
 
38
42
  def get_any(self, cls: type | tuple[type, ...]) -> ta.Sequence[T]:
39
- return self.dct.get_any(cls)
43
+ return self._dct.get_any(cls)
40
44
 
41
45
 
42
46
  ##
@@ -45,8 +49,24 @@ class ToolContext(lang.Final):
45
49
  _TOOL_CONTEXT: contextvars.ContextVar[ToolContext] = contextvars.ContextVar(f'{__name__}._TOOL_CONTEXT')
46
50
 
47
51
 
48
- @contextlib.contextmanager
49
- def bind_tool_context(ctx: ToolContext) -> ta.Generator[ToolContext]:
52
+ @ta.overload
53
+ def bind_tool_context(ctx: ToolContext) -> ta.ContextManager[ToolContext]:
54
+ ...
55
+
56
+
57
+ @ta.overload
58
+ def bind_tool_context(*items: ta.Any) -> ta.ContextManager[ToolContext]:
59
+ ...
60
+
61
+
62
+ @contextlib.contextmanager # type: ignore[misc]
63
+ def bind_tool_context(*args):
64
+ if args and isinstance(args[0], ToolContext):
65
+ check.arg(len(args) == 1)
66
+ ctx = args[0]
67
+ else:
68
+ ctx = ToolContext(*args)
69
+
50
70
  try:
51
71
  cur = _TOOL_CONTEXT.get()
52
72
  except LookupError:
@@ -0,0 +1,15 @@
1
+ import abc
2
+
3
+ from omlish import lang
4
+
5
+ from ...content.materialize import CanContent
6
+
7
+
8
+ ##
9
+
10
+
11
+ class ToolExecutionError(Exception, lang.Abstract):
12
+ @property
13
+ @abc.abstractmethod
14
+ def content(self) -> CanContent:
15
+ raise NotImplementedError
@@ -1,6 +1,3 @@
1
- """
2
- TODO:
3
- """
4
1
  import inspect
5
2
  import typing as ta
6
3
 
@@ -9,6 +9,7 @@ from ..content.prepare import default_content_str_preparer
9
9
  from .types import EnumToolDtype
10
10
  from .types import MappingToolDtype
11
11
  from .types import NullableToolDtype
12
+ from .types import ObjectToolDtype
12
13
  from .types import PrimitiveToolDtype
13
14
  from .types import SequenceToolDtype
14
15
  from .types import ToolDtype
@@ -72,6 +73,15 @@ class ToolJsonschemaRenderer:
72
73
  'enum': list(t.values),
73
74
  }
74
75
 
76
+ if isinstance(t, ObjectToolDtype):
77
+ return {
78
+ 'type': 'object',
79
+ 'properties': {
80
+ k: self.render_type(v)
81
+ for k, v in t.fields.items()
82
+ },
83
+ }
84
+
75
85
  raise TypeError(t)
76
86
 
77
87
  def render_tool_params(self, ts: ToolSpec) -> dict:
@@ -98,7 +108,7 @@ class ToolJsonschemaRenderer:
98
108
  }
99
109
 
100
110
  def render_tool(self, ts: ToolSpec) -> dict:
101
- pa_dct = self.render_tool_params(ts)
111
+ pa_dct = self.render_tool_params(ts) if ts.params else None
102
112
 
103
113
  ret_dct = {
104
114
  **({'description': self._content_str_preparer.prepare_str(ts.returns_desc)} if ts.returns_desc is not None else {}), # noqa
@@ -23,9 +23,11 @@ from omlish import metadata as md
23
23
  from omlish import reflect as rfl
24
24
  from omlish.lite.cached import cached_nullary
25
25
 
26
+ from ..content.materialize import CanContent
26
27
  from .types import EnumToolDtype
27
28
  from .types import MappingToolDtype
28
29
  from .types import NullableToolDtype
30
+ from .types import ObjectToolDtype
29
31
  from .types import PrimitiveToolDtype
30
32
  from .types import SequenceToolDtype
31
33
  from .types import ToolDtype
@@ -108,6 +110,12 @@ class ToolReflector:
108
110
  ])
109
111
 
110
112
  def reflect_type(self, rty: rfl.Type) -> ToolDtype:
113
+ if isinstance(rty, type) and dc.is_dataclass(rty):
114
+ return ObjectToolDtype({
115
+ f.name: self.reflect_type(rfl.type_(f.type))
116
+ for f in dc.fields(rty)
117
+ })
118
+
111
119
  if isinstance(rty, (type, rfl.Any)):
112
120
  return PrimitiveToolDtype.of(rty)
113
121
 
@@ -160,14 +168,22 @@ class ToolReflector:
160
168
 
161
169
  #
162
170
 
171
+ p_ovr_dct: dict[str, dict[str, ta.Any]] = {}
163
172
  ts_ovr: dict[str, ta.Any] = {}
173
+ o: _ToolSpecOverride
164
174
  for o in md.get_object_metadata(fn, type=_ToolSpecOverride):
165
- # TODO: better params handling / merging
166
175
  ts_ovr.update({
167
176
  k: v
168
177
  for k, v in dc.asdict(o).items()
169
- if v is not None
178
+ if k != 'params'
179
+ and v is not None
170
180
  })
181
+ for op in (o.params or []):
182
+ p_ovr_dct.setdefault(check.non_empty_str(op.name), {}).update({
183
+ k: v
184
+ for k, v in dc.asdict(op).items()
185
+ if v is not None
186
+ })
171
187
 
172
188
  #
173
189
 
@@ -207,23 +223,39 @@ class ToolReflector:
207
223
  if 'params' not in ts_kw:
208
224
  ds_p_dct = {
209
225
  ds_p.arg_name: ds_p
210
- for ds_p in (ds.params if ds is not None else [])
226
+ for ds_p in (ds.params if ds is not None else {})
211
227
  }
212
228
 
213
- params: dict[str, ToolParam] = {}
214
- for sig_p in sig().parameters.values():
215
- check.not_in(sig_p.name, params)
216
-
217
- ds_p = ds_p_dct.get(sig_p.name)
218
-
219
- params[sig_p.name] = ToolParam(
220
- sig_p.name,
229
+ sig_p_dct = sig().parameters
221
230
 
222
- desc=self._prepare_desc(ds_p.description) if ds_p is not None else None,
231
+ pns: list[str] = list({**p_ovr_dct, **ds_p_dct, **sig_p_dct})
223
232
 
224
- type=self.reflect_type(rfl.type_(th()[sig_p.name])) if sig_p.name in th() else None,
225
-
226
- required=sig_p.default is inspect.Parameter.empty,
233
+ params: dict[str, ToolParam] = {}
234
+ for pn in pns:
235
+ ovr_p = p_ovr_dct.get(pn, {})
236
+ ds_p = ds_p_dct.get(pn)
237
+ sig_p = sig_p_dct.get(pn)
238
+
239
+ p_desc: CanContent
240
+ if (p_desc := ovr_p.get('desc')) is None:
241
+ if ds_p is not None:
242
+ p_desc = ds_p.description
243
+
244
+ p_type: ToolDtype | None
245
+ if (p_type := ovr_p.get('type')) is None:
246
+ if sig_p is not None and sig_p.name in th():
247
+ p_type = self.reflect_type(rfl.type_(th()[sig_p.name]))
248
+
249
+ p_required: bool | None
250
+ if (p_required := ovr_p.get('required')) is None:
251
+ if sig_p is not None:
252
+ p_required = sig_p.default is inspect.Parameter.empty
253
+
254
+ params[pn] = ToolParam(
255
+ pn,
256
+ desc=self._prepare_desc(p_desc) if p_desc is not None else None,
257
+ type=p_type,
258
+ required=p_required,
227
259
  )
228
260
 
229
261
  ts_kw.update(params=tuple(params.values()) if params else None)
@@ -127,6 +127,15 @@ class EnumToolDtype(ToolDtype):
127
127
  values: ta.Sequence[ta.Any]
128
128
 
129
129
 
130
+ #
131
+
132
+
133
+ @dc.dataclass(frozen=True)
134
+ @dc.extra_class_params(terse_repr=True)
135
+ class ObjectToolDtype(ToolDtype):
136
+ fields: ta.Mapping[str, ToolDtype]
137
+
138
+
130
139
  ##
131
140
 
132
141
 
@@ -0,0 +1,27 @@
1
+ import typing as ta
2
+
3
+ from omlish import check
4
+ from omlish import reflect as rfl
5
+
6
+
7
+ ##
8
+
9
+
10
+ def join_human_readable_str_list(
11
+ strs: ta.Iterable[str],
12
+ *,
13
+ sep: str = ', ',
14
+ disj: str = 'or ',
15
+ ) -> str:
16
+ seq = list(strs)
17
+ return sep.join(
18
+ (disj if i == len(seq) - 1 else '') + s
19
+ for i, s in enumerate(seq)
20
+ )
21
+
22
+
23
+ ##
24
+
25
+
26
+ def str_literal_values(lit: ta.Any) -> ta.Sequence[str]:
27
+ return tuple(check.isinstance(rfl.type_(lit), rfl.Literal).args)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ommlds
3
- Version: 0.0.0.dev448
3
+ Version: 0.0.0.dev450
4
4
  Summary: ommlds
5
5
  Author: wrmsr
6
6
  License-Expression: BSD-3-Clause
@@ -14,8 +14,8 @@ Classifier: Programming Language :: Python :: 3.13
14
14
  Requires-Python: >=3.13
15
15
  Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
- Requires-Dist: omdev==0.0.0.dev448
18
- Requires-Dist: omlish==0.0.0.dev448
17
+ Requires-Dist: omdev==0.0.0.dev450
18
+ Requires-Dist: omlish==0.0.0.dev450
19
19
  Provides-Extra: all
20
20
  Requires-Dist: llama-cpp-python~=0.3; extra == "all"
21
21
  Requires-Dist: mlx~=0.29; extra == "all"