ommlds 0.0.0.dev494__py3-none-any.whl → 0.0.0.dev495__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 (52) hide show
  1. ommlds/cli/_dataclasses.py +7 -7
  2. ommlds/cli/backends/inject.py +51 -8
  3. ommlds/cli/backends/meta.py +35 -0
  4. ommlds/cli/inject.py +1 -1
  5. ommlds/cli/sessions/chat/drivers/{driver.py → impl.py} +2 -9
  6. ommlds/cli/sessions/chat/drivers/inject.py +5 -3
  7. ommlds/cli/sessions/chat/drivers/state/inject.py +2 -3
  8. ommlds/cli/sessions/chat/drivers/tools/injection.py +4 -4
  9. ommlds/cli/sessions/chat/drivers/types.py +21 -0
  10. ommlds/cli/sessions/chat/drivers/user/inject.py +1 -1
  11. ommlds/cli/sessions/chat/facades/commands/inject.py +0 -2
  12. ommlds/cli/sessions/chat/facades/commands/simple.py +2 -8
  13. ommlds/cli/sessions/chat/facades/facade.py +1 -1
  14. ommlds/cli/sessions/chat/facades/inject.py +5 -0
  15. ommlds/cli/sessions/chat/facades/ui.py +11 -0
  16. ommlds/cli/sessions/chat/interfaces/bare/interactive.py +1 -1
  17. ommlds/cli/sessions/chat/interfaces/bare/oneshot.py +1 -1
  18. ommlds/cli/sessions/chat/interfaces/textual/app.py +21 -3
  19. ommlds/cli/sessions/chat/interfaces/textual/inject.py +2 -5
  20. ommlds/cli/sessions/chat/interfaces/textual/styles/messages.tcss +2 -0
  21. ommlds/cli/sessions/chat/interfaces/textual/widgets/messages.py +12 -5
  22. ommlds/minichain/__init__.py +16 -6
  23. ommlds/minichain/_dataclasses.py +6872 -3644
  24. ommlds/minichain/backends/strings/resolving.py +1 -1
  25. ommlds/minichain/chat/messages.py +1 -1
  26. ommlds/minichain/content/_marshal.py +6 -4
  27. ommlds/minichain/content/cancontent.py +32 -0
  28. ommlds/minichain/content/materialize.py +2 -25
  29. ommlds/minichain/content/prepare.py +3 -3
  30. ommlds/minichain/content/sequence.py +2 -2
  31. ommlds/minichain/content/tag.py +19 -0
  32. ommlds/minichain/content/transforms/interleave.py +10 -3
  33. ommlds/minichain/lib/fs/tools/read.py +1 -1
  34. ommlds/minichain/lib/fs/tools/recursivels/rendering.py +1 -1
  35. ommlds/minichain/lib/fs/tools/recursivels/running.py +1 -1
  36. ommlds/minichain/lib/todo/types.py +1 -1
  37. ommlds/minichain/meta/__init__.py +0 -0
  38. ommlds/minichain/meta/firstinwins.py +131 -0
  39. ommlds/minichain/text/applypatch.py +2 -1
  40. ommlds/minichain/text/toolparsing/llamacpp/types.py +1 -1
  41. ommlds/minichain/tokens/specials.py +1 -1
  42. ommlds/minichain/tools/execution/errorhandling.py +35 -0
  43. ommlds/minichain/tools/execution/errors.py +1 -1
  44. ommlds/minichain/tools/reflect.py +1 -1
  45. ommlds/minichain/tools/types.py +1 -1
  46. ommlds/minichain/vectors/_marshal.py +1 -1
  47. {ommlds-0.0.0.dev494.dist-info → ommlds-0.0.0.dev495.dist-info}/METADATA +4 -4
  48. {ommlds-0.0.0.dev494.dist-info → ommlds-0.0.0.dev495.dist-info}/RECORD +52 -46
  49. {ommlds-0.0.0.dev494.dist-info → ommlds-0.0.0.dev495.dist-info}/WHEEL +0 -0
  50. {ommlds-0.0.0.dev494.dist-info → ommlds-0.0.0.dev495.dist-info}/entry_points.txt +0 -0
  51. {ommlds-0.0.0.dev494.dist-info → ommlds-0.0.0.dev495.dist-info}/licenses/LICENSE +0 -0
  52. {ommlds-0.0.0.dev494.dist-info → ommlds-0.0.0.dev495.dist-info}/top_level.txt +0 -0
@@ -4,9 +4,9 @@ TODO:
4
4
  - interop with registry somehow, probably? or is it strictly a different concern?
5
5
  """
6
6
  import abc
7
- import dataclasses as dc
8
7
  import typing as ta
9
8
 
9
+ from omlish import dataclasses as dc
10
10
  from omlish import lang
11
11
  from omlish.manifests.globals import GlobalManifestLoader
12
12
 
@@ -9,7 +9,7 @@ from omlish import marshal as msh
9
9
  from omlish import typedvalues as tv
10
10
 
11
11
  from .._typedvalues import _tv_field_metadata
12
- from ..content.materialize import CanContent
12
+ from ..content.cancontent import CanContent
13
13
  from ..content.transforms.base import ContentTransform
14
14
  from ..content.types import Content
15
15
  from ..metadata import MetadataContainer
@@ -1,18 +1,19 @@
1
1
  import collections.abc
2
- import dataclasses as dc
3
2
  import typing as ta
4
3
 
5
4
  from omlish import check
5
+ from omlish import dataclasses as dc
6
6
  from omlish import lang
7
7
  from omlish import marshal as msh
8
8
  from omlish import reflect as rfl
9
9
 
10
+ from .cancontent import CanContent
11
+ from .cancontent import _InnerCanContent
10
12
  from .images import ImageContent # noqa
11
13
  from .json import JsonContent # noqa
12
- from .materialize import CanContent
13
- from .materialize import _InnerCanContent
14
14
  from .sequence import BlockContent # noqa
15
15
  from .sequence import InlineContent # noqa
16
+ from .tag import TagContent # noqa
16
17
  from .text import TextContent # noqa
17
18
  from .types import CONTENT_RUNTIME_TYPES
18
19
  from .types import Content
@@ -161,10 +162,11 @@ def _install_standard_marshaling() -> None:
161
162
  extended_content_poly = msh.Polymorphism(
162
163
  ExtendedContent,
163
164
  [
164
- msh.Impl(InlineContent, 'inline'),
165
165
  msh.Impl(BlockContent, 'block'),
166
166
  msh.Impl(ImageContent, 'image'),
167
+ msh.Impl(InlineContent, 'inline'),
167
168
  msh.Impl(JsonContent, 'json'),
169
+ msh.Impl(TagContent, 'tag'),
168
170
  msh.Impl(TextContent, 'text'),
169
171
  ],
170
172
  )
@@ -0,0 +1,32 @@
1
+ import typing as ta
2
+
3
+ from omlish.text import templating as tpl
4
+
5
+ from .namespaces import ContentNamespace
6
+ from .placeholders import ContentPlaceholder
7
+ from .placeholders import ContentPlaceholderMarker
8
+ from .types import ExtendedContent
9
+
10
+
11
+ ##
12
+
13
+
14
+ _InnerCanContent: ta.TypeAlias = ta.Union[ # noqa
15
+ str,
16
+ ExtendedContent,
17
+
18
+ ContentPlaceholder,
19
+ type[ContentPlaceholderMarker],
20
+
21
+ type[ContentNamespace],
22
+
23
+ tpl.Templater,
24
+ ]
25
+
26
+ CanContent: ta.TypeAlias = ta.Union[ # noqa
27
+ ta.Iterable['CanContent'],
28
+
29
+ None,
30
+
31
+ _InnerCanContent,
32
+ ]
@@ -2,13 +2,14 @@
2
2
  TODO:
3
3
  - ExtendedCanContent
4
4
  """
5
- import dataclasses as dc
6
5
  import typing as ta
7
6
 
8
7
  from omlish import check
8
+ from omlish import dataclasses as dc
9
9
  from omlish import dispatch
10
10
  from omlish.text import templating as tpl
11
11
 
12
+ from .cancontent import CanContent
12
13
  from .namespaces import ContentNamespace
13
14
  from .placeholders import ContentPlaceholder
14
15
  from .placeholders import ContentPlaceholderMarker
@@ -19,30 +20,6 @@ from .types import ExtendedContent
19
20
  ##
20
21
 
21
22
 
22
- _InnerCanContent: ta.TypeAlias = ta.Union[ # noqa
23
- str,
24
- ExtendedContent,
25
-
26
- ContentPlaceholder,
27
- type[ContentPlaceholderMarker],
28
-
29
- type[ContentNamespace],
30
-
31
- tpl.Templater,
32
- ]
33
-
34
- CanContent: ta.TypeAlias = ta.Union[ # noqa
35
- ta.Iterable['CanContent'],
36
-
37
- None,
38
-
39
- _InnerCanContent,
40
- ]
41
-
42
-
43
- ##
44
-
45
-
46
23
  ContentPlaceholderKey: ta.TypeAlias = ContentPlaceholder | type[ContentPlaceholderMarker]
47
24
  ContentPlaceholderMap: ta.TypeAlias = ta.Mapping[ContentPlaceholderKey, CanContent]
48
25
  ContentPlaceholderFn: ta.TypeAlias = ta.Callable[[ContentPlaceholderKey], CanContent]
@@ -1,14 +1,14 @@
1
1
  """
2
2
  TODO:
3
- - re-softwrap
3
+ - re-docwrap
4
4
  """
5
5
  import abc
6
- import dataclasses as dc
7
6
  import typing as ta
8
7
 
8
+ from omlish import dataclasses as dc
9
9
  from omlish import lang
10
10
 
11
- from .materialize import CanContent
11
+ from .cancontent import CanContent
12
12
  from .materialize import materialize_content
13
13
  from .transforms.interleave import interleave_content
14
14
  from .transforms.squeeze import squeeze_content
@@ -8,8 +8,8 @@ import typing as ta
8
8
  from omlish import dataclasses as dc
9
9
  from omlish import lang
10
10
 
11
+ from .cancontent import CanContent
11
12
  from .simple import SimpleExtendedContent
12
- from .types import Content
13
13
 
14
14
 
15
15
  ##
@@ -17,7 +17,7 @@ from .types import Content
17
17
 
18
18
  @dc.dataclass(frozen=True)
19
19
  class SequenceContent(SimpleExtendedContent, lang.Abstract):
20
- l: ta.Sequence[Content]
20
+ l: ta.Sequence[CanContent]
21
21
 
22
22
 
23
23
  @dc.dataclass(frozen=True)
@@ -0,0 +1,19 @@
1
+ """
2
+ TODO:
3
+ - track BlockContent nesting depth?
4
+ - section names? dedicated 'section' content with header and body?
5
+ """
6
+ from omlish import dataclasses as dc
7
+ from omlish import lang
8
+
9
+ from .cancontent import CanContent
10
+ from .simple import SimpleExtendedContent
11
+
12
+
13
+ ##
14
+
15
+
16
+ @dc.dataclass(frozen=True)
17
+ class TagContent(SimpleExtendedContent, lang.Final):
18
+ tag: str
19
+ body: CanContent
@@ -4,9 +4,11 @@ from omlish import dataclasses as dc
4
4
  from omlish import dispatch
5
5
  from omlish import lang
6
6
 
7
+ from ..cancontent import CanContent
7
8
  from ..sequence import BlockContent
8
9
  from ..sequence import InlineContent
9
10
  from ..types import Content
11
+ from ..types import ExtendedContent
10
12
 
11
13
 
12
14
  ##
@@ -27,15 +29,15 @@ class ContentInterleaver:
27
29
  self._inline_separator = inline_separator if inline_separator is not None else separator
28
30
  self._block_separator = block_separator if block_separator is not None else separator
29
31
 
30
- def _interleave(self, l: ta.Iterable[Content], separator: Content | None) -> ta.Sequence[Content]:
32
+ def _interleave(self, l: ta.Iterable[CanContent], separator: Content | None) -> ta.Sequence[Content]:
31
33
  cs: ta.Iterable[Content] = map(self.interleave, l)
32
34
  if separator is not None:
33
35
  cs = lang.interleave(cs, separator)
34
36
  return list(cs)
35
37
 
36
38
  @dispatch.method()
37
- def interleave(self, c: Content) -> Content:
38
- return c
39
+ def interleave(self, c: CanContent) -> Content:
40
+ raise TypeError(c)
39
41
 
40
42
  @interleave.register
41
43
  def interleave_str(self, c: str) -> Content:
@@ -45,6 +47,11 @@ class ContentInterleaver:
45
47
  def interleave_sequence(self, c: ta.Sequence) -> Content:
46
48
  return self._interleave(c, self._sequence_separator)
47
49
 
50
+ @interleave.register
51
+ def interleave_extended_content(self, c: ExtendedContent) -> Content:
52
+ # FIXME:
53
+ return c
54
+
48
55
  @interleave.register
49
56
  def interleave_inline_content(self, c: InlineContent) -> Content:
50
57
  return dc.replace(c, l=self._interleave(c.l, self._inline_separator))
@@ -27,7 +27,7 @@ MAX_LINE_LENGTH = 2_000
27
27
 
28
28
  @tool_spec_override(
29
29
  desc=f"""
30
- Reads a file from the local filesystem. You can access any file directly by using this tool.
30
+ Reads a file from the local filesystem. You can access any file directly by using this tool.
31
31
 
32
32
  Assume this tool is able to read all files on the machine. If the User provides a path to a file assume that
33
33
  path is valid. It is okay to read a file that does not exist; an error will be returned.
@@ -5,10 +5,10 @@ TODO:
5
5
  - any directory with unlisted children will be suffixed inline with '...'
6
6
  - absence of '...' indicates an empty directory
7
7
  """
8
- import dataclasses as dc
9
8
  import typing as ta
10
9
 
11
10
  from omlish import check
11
+ from omlish import dataclasses as dc
12
12
  from omlish import lang
13
13
 
14
14
  from .running import DirLsItem
@@ -1,8 +1,8 @@
1
- import dataclasses as dc
2
1
  import os.path
3
2
  import typing as ta
4
3
 
5
4
  from omlish import check
5
+ from omlish import dataclasses as dc
6
6
  from omlish import lang
7
7
 
8
8
 
@@ -3,9 +3,9 @@ TODO:
3
3
  - enums lol
4
4
  - * with ToolParam-like desc metadata somehow *
5
5
  """
6
- import dataclasses as dc
7
6
  import typing as ta
8
7
 
8
+ from omlish import dataclasses as dc
9
9
  from omlish import lang
10
10
 
11
11
  from ...tools.reflect import tool_param_metadata
File without changes
@@ -0,0 +1,131 @@
1
+ import typing as ta
2
+
3
+ from omlish import check
4
+ from omlish import dataclasses as dc
5
+ from omlish import lang
6
+
7
+ from ..services.requests import Request
8
+ from ..services.responses import Response
9
+ from ..services.services import Service
10
+ from ..types import Option
11
+ from ..types import Output
12
+
13
+
14
+ with lang.auto_proxy_import(globals()):
15
+ import asyncio
16
+
17
+
18
+ RequestV = ta.TypeVar('RequestV')
19
+ OptionT = ta.TypeVar('OptionT', bound=Option)
20
+
21
+ ResponseV = ta.TypeVar('ResponseV')
22
+ OutputT = ta.TypeVar('OutputT', bound=Output)
23
+
24
+
25
+ ##
26
+
27
+
28
+ @dc.dataclass(frozen=True)
29
+ class FirstInWinsServiceCancelledError(Exception):
30
+ e: BaseException
31
+
32
+
33
+ class FirstInWinsServiceExceptionGroup(ExceptionGroup):
34
+ pass
35
+
36
+
37
+ @dc.dataclass(frozen=True)
38
+ class FirstInWinsServiceOutput(Output):
39
+ first_in_wins_service: 'FirstInWinsService'
40
+ response_service: Service
41
+ service_exceptions: ta.Mapping[Service, Exception] | None = None
42
+
43
+
44
+ class FirstInWinsService(
45
+ lang.Abstract,
46
+ ta.Generic[
47
+ RequestV,
48
+ OptionT,
49
+ ResponseV,
50
+ OutputT,
51
+ ],
52
+ ):
53
+ def __init__(
54
+ self,
55
+ *services: Service[
56
+ Request[
57
+ RequestV,
58
+ OptionT,
59
+ ],
60
+ Response[
61
+ ResponseV,
62
+ OutputT,
63
+ ],
64
+ ],
65
+ ) -> None:
66
+ super().__init__()
67
+
68
+ self._services = check.not_empty(services)
69
+
70
+
71
+ ##
72
+
73
+
74
+ class AsyncioFirstInWinsService(
75
+ FirstInWinsService[
76
+ RequestV,
77
+ OptionT,
78
+ ResponseV,
79
+ OutputT,
80
+ ],
81
+ ):
82
+ async def invoke(self, request: Request[RequestV, OptionT]) -> Response[ResponseV, OutputT]:
83
+ tasks: list = []
84
+ services_by_task: dict = {}
85
+ for svc in self._services:
86
+ task: asyncio.Task = asyncio.create_task(svc.invoke(request)) # type: ignore[arg-type]
87
+ tasks.append(task)
88
+ services_by_task[task] = svc
89
+
90
+ failures_by_service: dict[Service, Exception] = {}
91
+
92
+ try:
93
+ pending = set(tasks)
94
+
95
+ while pending:
96
+ done, pending = await asyncio.wait(pending, return_when=asyncio.FIRST_COMPLETED)
97
+
98
+ for t in done:
99
+ svc = services_by_task[t]
100
+
101
+ try:
102
+ response = t.result()
103
+ except asyncio.CancelledError as exc:
104
+ failures_by_service[svc] = FirstInWinsServiceCancelledError(exc)
105
+ continue
106
+ except Exception as exc: # noqa
107
+ failures_by_service[svc] = exc
108
+ continue
109
+
110
+ for p in pending:
111
+ p.cancel()
112
+
113
+ await asyncio.gather(*pending, return_exceptions=True)
114
+
115
+ return response.with_outputs(FirstInWinsServiceOutput(
116
+ self,
117
+ svc,
118
+ failures_by_service,
119
+ ))
120
+
121
+ raise FirstInWinsServiceExceptionGroup(
122
+ 'All service calls failed',
123
+ list(failures_by_service.values()),
124
+ )
125
+
126
+ finally:
127
+ for t in tasks:
128
+ if not t.done():
129
+ t.cancel()
130
+
131
+ await asyncio.gather(*tasks, return_exceptions=True)
@@ -20,11 +20,12 @@
20
20
  A self-contained **pure-Python 3.9+** utility for applying human-readable "pseudo-diff" patch files to a collection of
21
21
  text files.
22
22
  """
23
- import dataclasses as dc
24
23
  import enum
25
24
  import pathlib
26
25
  import typing as ta
27
26
 
27
+ from omlish import dataclasses as dc
28
+
28
29
 
29
30
  ##
30
31
  # Domain objects
@@ -1,4 +1,4 @@
1
- import dataclasses as dc
1
+ from omlish import dataclasses as dc
2
2
 
3
3
 
4
4
  ##
@@ -1,7 +1,7 @@
1
- import dataclasses as dc
2
1
  import typing as ta
3
2
 
4
3
  from omlish import check
4
+ from omlish import dataclasses as dc
5
5
  from omlish import lang
6
6
 
7
7
  from .types import NonSpecialToken
@@ -0,0 +1,35 @@
1
+ import typing as ta
2
+
3
+ from ...content.materialize import ContentMaterializer
4
+ from ...content.types import Content
5
+ from .context import ToolContext
6
+ from .errors import ToolExecutionError
7
+ from .executors import ToolExecutor
8
+
9
+
10
+ ##
11
+
12
+
13
+ class ErrorHandlingToolExecutor(ToolExecutor):
14
+ def __init__(
15
+ self,
16
+ *,
17
+ wrapped: ToolExecutor,
18
+ content_materializer: ContentMaterializer = ContentMaterializer(),
19
+ ) -> None:
20
+ super().__init__()
21
+
22
+ self._wrapped = wrapped
23
+ self._content_materializer = content_materializer
24
+
25
+ async def execute_tool(
26
+ self,
27
+ ctx: ToolContext,
28
+ name: str,
29
+ args: ta.Mapping[str, ta.Any],
30
+ ) -> Content:
31
+ try:
32
+ return await self._wrapped.execute_tool(ctx, name, args)
33
+
34
+ except ToolExecutionError as txe:
35
+ return self._content_materializer.materialize(txe.content)
@@ -2,7 +2,7 @@ import abc
2
2
 
3
3
  from omlish import lang
4
4
 
5
- from ...content.materialize import CanContent
5
+ from ...content.cancontent import CanContent
6
6
 
7
7
 
8
8
  ##
@@ -23,7 +23,7 @@ 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
+ from ..content.cancontent import CanContent
27
27
  from .types import EnumToolDtype
28
28
  from .types import MappingToolDtype
29
29
  from .types import NullableToolDtype
@@ -11,7 +11,7 @@ from omlish import lang
11
11
  from omlish import marshal as msh
12
12
  from omlish import reflect as rfl
13
13
 
14
- from ..content.materialize import CanContent
14
+ from ..content.cancontent import CanContent
15
15
  from ..content.transforms.base import ContentTransform
16
16
  from ..content.types import Content
17
17
 
@@ -2,10 +2,10 @@
2
2
  TODO:
3
3
  - serialize as base64 bytes? at least support deserializing as it
4
4
  """
5
- import dataclasses as dc
6
5
  import typing as ta
7
6
 
8
7
  from omlish import check
8
+ from omlish import dataclasses as dc
9
9
  from omlish import lang
10
10
  from omlish import marshal as msh
11
11
  from omlish import reflect as rfl
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ommlds
3
- Version: 0.0.0.dev494
3
+ Version: 0.0.0.dev495
4
4
  Summary: ommlds
5
5
  Author: wrmsr
6
6
  License-Expression: BSD-3-Clause
@@ -14,9 +14,9 @@ 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: omlish==0.0.0.dev494
17
+ Requires-Dist: omlish==0.0.0.dev495
18
18
  Provides-Extra: all
19
- Requires-Dist: omdev==0.0.0.dev494; extra == "all"
19
+ Requires-Dist: omdev==0.0.0.dev495; extra == "all"
20
20
  Requires-Dist: llama-cpp-python~=0.3; extra == "all"
21
21
  Requires-Dist: mlx~=0.30; sys_platform == "darwin" and extra == "all"
22
22
  Requires-Dist: mlx-lm~=0.29; sys_platform == "darwin" and extra == "all"
@@ -38,7 +38,7 @@ Requires-Dist: mwparserfromhell~=0.7; extra == "all"
38
38
  Requires-Dist: wikitextparser~=0.56; extra == "all"
39
39
  Requires-Dist: lxml>=5.3; python_version < "3.13" and extra == "all"
40
40
  Provides-Extra: omdev
41
- Requires-Dist: omdev==0.0.0.dev494; extra == "omdev"
41
+ Requires-Dist: omdev==0.0.0.dev495; extra == "omdev"
42
42
  Provides-Extra: backends
43
43
  Requires-Dist: llama-cpp-python~=0.3; extra == "backends"
44
44
  Requires-Dist: mlx~=0.30; sys_platform == "darwin" and extra == "backends"