unique-sdk 2026.50.0.dev12__tar.gz → 2026.50.0.dev14__tar.gz
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.
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/PKG-INFO +1 -1
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/pyproject.toml +1 -1
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/__init__.py +4 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/_object_classes.py +2 -0
- unique_sdk-2026.50.0.dev14/unique_sdk/api_resources/_project_chat.py +486 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/cli.py +97 -0
- unique_sdk-2026.50.0.dev14/unique_sdk/cli/commands/user_memory.py +163 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/README.md +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/_api_requestor.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/_api_resource.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/_api_version.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/_error.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/_http_client.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/_list_object.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/_request_options.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/_unique_object.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/_unique_ql.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/_unique_response.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/_util.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/_version.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/_webhook.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/__init__.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_acronyms.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_agentic_table.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_analytics_order.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_benchmarking.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_briefing.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_chat_completion.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_content.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_context_memory.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_elicitation.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_embedding.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_event.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_folder.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_group.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_integrated.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_llm_models.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_mcp.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_message.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_message_assessment.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_message_execution.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_message_log.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_message_tool.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_module.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_project_memory.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_scheduled_task.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_search.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_search_string.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_short_term_memory.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_space.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_user.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_web_search.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/__init__.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/__main__.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/__init__.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/_citation_manifest.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/agentic_table.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/agentic_table_write.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/browser.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/cite_file.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/elicitation.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/files.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/folders.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/mcp.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/navigation.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/read.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/scheduled_tasks.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/search.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/subagent.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/web_search.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/web_search_config.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/config.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/formatting.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/identity.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/metadata_filter.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/paths.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/shell.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/skills/unique-cli-agentic-table/SKILL.md +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/skills/unique-cli-elicitation/SKILL.md +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/skills/unique-cli-file-management/SKILL.md +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/skills/unique-cli-mcp/SKILL.md +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/skills/unique-cli-scheduled-tasks/SKILL.md +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/skills/unique-cli-search/SKILL.md +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/skills/unique-cli-subagent/SKILL.md +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/skills/unique-cli-uploaded-search/SKILL.md +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/skills/unique-cli-web-search/SKILL.md +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/state.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/subagent_turns.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/workspace.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/utils/analytics_order_run.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/utils/benchmarking_run.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/utils/chat_history.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/utils/chat_in_space.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/utils/file_io.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/utils/sources.py +0 -0
- {unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/utils/token.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: unique-sdk
|
|
3
|
-
Version: 2026.50.0.
|
|
3
|
+
Version: 2026.50.0.dev14
|
|
4
4
|
Summary:
|
|
5
5
|
Author: Martin Fadler, Konstantin Krauss, Andreas Hauri
|
|
6
6
|
Author-email: Martin Fadler <martin.fadler@unique.ch>, Konstantin Krauss <konstantin@unique.ch>, Andreas Hauri <andreas@unique.ch>
|
|
@@ -88,6 +88,10 @@ from unique_sdk.api_resources._short_term_memory import (
|
|
|
88
88
|
)
|
|
89
89
|
from unique_sdk.api_resources._context_memory import ContextMemory as ContextMemory
|
|
90
90
|
from unique_sdk.api_resources._project_memory import ProjectMemory as ProjectMemory
|
|
91
|
+
from unique_sdk.api_resources._project_chat import (
|
|
92
|
+
ProjectChat as ProjectChat,
|
|
93
|
+
ProjectChatChunk as ProjectChatChunk,
|
|
94
|
+
)
|
|
91
95
|
from unique_sdk.api_resources._folder import Folder as Folder
|
|
92
96
|
from unique_sdk.api_resources._embedding import Embeddings as Embeddings
|
|
93
97
|
from unique_sdk.api_resources._acronyms import Acronyms as Acronyms
|
|
@@ -12,4 +12,6 @@ OBJECT_CLASSES = {
|
|
|
12
12
|
unique_sdk.WebSearchReview.OBJECT_NAME: unique_sdk.WebSearchReview,
|
|
13
13
|
unique_sdk.WebCrawl.OBJECT_NAME: unique_sdk.WebCrawl,
|
|
14
14
|
unique_sdk.ProjectMemory.OBJECT_NAME: unique_sdk.ProjectMemory,
|
|
15
|
+
unique_sdk.ProjectChat.OBJECT_NAME: unique_sdk.ProjectChat,
|
|
16
|
+
unique_sdk.ProjectChatChunk.OBJECT_NAME: unique_sdk.ProjectChatChunk,
|
|
15
17
|
}
|
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
"""Project chat search: find and read the earlier chats of a user's project.
|
|
2
|
+
|
|
3
|
+
Wraps the public endpoints under ``/search/project-chats``. Chats of a project
|
|
4
|
+
are indexed in chunks of consecutive question and answer pairs:
|
|
5
|
+
|
|
6
|
+
- ``POST /search/project-chats`` returns the chunks that best match a query.
|
|
7
|
+
- ``POST /search/project-chats/chunks`` returns the chunks of one chat in
|
|
8
|
+
order, one page at a time.
|
|
9
|
+
- ``POST /search/project-chats/recent`` lists the chats of the project, most
|
|
10
|
+
recently active first.
|
|
11
|
+
|
|
12
|
+
Only the project's owner can call them, and the Projects feature must be on
|
|
13
|
+
for the company. Search returns an empty list while project chat indexing is
|
|
14
|
+
off for the company.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from datetime import datetime
|
|
18
|
+
from typing import Any, Literal, TypedDict, cast
|
|
19
|
+
|
|
20
|
+
from unique_sdk._api_resource import APIResource
|
|
21
|
+
from unique_sdk._unique_object import UniqueObject
|
|
22
|
+
from unique_sdk._util import classproperty
|
|
23
|
+
|
|
24
|
+
_SEARCH_URL = "/search/project-chats"
|
|
25
|
+
_CHUNKS_URL = "/search/project-chats/chunks"
|
|
26
|
+
_RECENT_URL = "/search/project-chats/recent"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _body(**fields: Any) -> dict[str, Any]:
|
|
30
|
+
# Keyword-only fields: request options such as api_key or headers never
|
|
31
|
+
# reach the body. None is left out so the endpoint applies its defaults.
|
|
32
|
+
body: dict[str, Any] = {}
|
|
33
|
+
for key, value in fields.items():
|
|
34
|
+
if value is None:
|
|
35
|
+
continue
|
|
36
|
+
body[key] = value.isoformat() if isinstance(value, datetime) else value
|
|
37
|
+
return body
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class ProjectChatChunk(UniqueObject):
|
|
41
|
+
"""A chunk of an earlier project chat: consecutive question and answer pairs.
|
|
42
|
+
|
|
43
|
+
Attributes:
|
|
44
|
+
chatId (str): Chat the chunk belongs to.
|
|
45
|
+
chatTitle (str | None): Title of the chat.
|
|
46
|
+
chunkIndex (int): Position of the chunk in its chat, from 0.
|
|
47
|
+
pairIndexStart (int): First question and answer pair in the chunk,
|
|
48
|
+
from 1.
|
|
49
|
+
pairIndexEnd (int): Last question and answer pair in the chunk.
|
|
50
|
+
messageIds (list[str]): Messages in the chunk.
|
|
51
|
+
text (str): Text of the chunk.
|
|
52
|
+
tokenCount (int): Number of tokens in ``text``.
|
|
53
|
+
isOpen (bool): ``True`` for the last chunk of the chat, which can
|
|
54
|
+
still grow.
|
|
55
|
+
createdAt (str): Time of the first message in the chunk, ISO 8601.
|
|
56
|
+
updatedAt (str): Time of the last message in the chunk, ISO 8601.
|
|
57
|
+
score (float | None): Relevance score. Set by search only.
|
|
58
|
+
highlights (list[str] | None): Highlighted passages. Set by search
|
|
59
|
+
only.
|
|
60
|
+
object (Literal["search.project-chat-chunk"]): Object type identifier.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
@classproperty
|
|
64
|
+
def OBJECT_NAME(cls) -> Literal["search.project-chat-chunk"]:
|
|
65
|
+
return "search.project-chat-chunk"
|
|
66
|
+
|
|
67
|
+
chatId: str
|
|
68
|
+
chatTitle: str | None
|
|
69
|
+
chunkIndex: int
|
|
70
|
+
pairIndexStart: int
|
|
71
|
+
pairIndexEnd: int
|
|
72
|
+
messageIds: list[str]
|
|
73
|
+
text: str
|
|
74
|
+
tokenCount: int
|
|
75
|
+
isOpen: bool
|
|
76
|
+
createdAt: str
|
|
77
|
+
updatedAt: str
|
|
78
|
+
score: float | None
|
|
79
|
+
highlights: list[str] | None
|
|
80
|
+
object: Literal["search.project-chat-chunk"]
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class ProjectChat(APIResource["ProjectChat"]):
|
|
84
|
+
"""An earlier chat of a user's project, as listed by ``list_recent``.
|
|
85
|
+
|
|
86
|
+
The class also holds the three project chat search calls: ``search``,
|
|
87
|
+
``list_chunks`` and ``list_recent``, each with an ``_async`` variant.
|
|
88
|
+
|
|
89
|
+
Attributes:
|
|
90
|
+
chatId (str): Chat identifier.
|
|
91
|
+
chatTitle (str | None): Title of the chat.
|
|
92
|
+
chatCreatedAt (str): Creation time of the chat, ISO 8601.
|
|
93
|
+
updatedAt (str): Time of the last message, ISO 8601.
|
|
94
|
+
chunkCount (int): Number of indexed chunks in the chat.
|
|
95
|
+
object (Literal["search.project-chat"]): Object type identifier.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
@classproperty
|
|
99
|
+
def OBJECT_NAME(cls) -> Literal["search.project-chat"]:
|
|
100
|
+
return "search.project-chat"
|
|
101
|
+
|
|
102
|
+
class ChatStats(TypedDict):
|
|
103
|
+
"""Chunk and token totals of one chat.
|
|
104
|
+
|
|
105
|
+
Attributes:
|
|
106
|
+
chatId (str): Chat identifier.
|
|
107
|
+
chunkCount (int): Number of chunks in the chat.
|
|
108
|
+
tokenCount (int): Number of tokens in the chat.
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
chatId: str
|
|
112
|
+
chunkCount: int
|
|
113
|
+
tokenCount: int
|
|
114
|
+
|
|
115
|
+
class ChunkList(TypedDict):
|
|
116
|
+
"""Response of ``search`` and ``list_chunks``.
|
|
117
|
+
|
|
118
|
+
Attributes:
|
|
119
|
+
object (Literal["list"]): Object type identifier.
|
|
120
|
+
data (list[ProjectChatChunk]): The chunks.
|
|
121
|
+
chatStats (list[ProjectChat.ChatStats]): Totals of the chats in
|
|
122
|
+
``data``. Empty unless ``include_chat_stats`` is set.
|
|
123
|
+
nextCursor (str | None): Pass as ``after`` to get the next page.
|
|
124
|
+
``None`` on the last page and always for search.
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
object: Literal["list"]
|
|
128
|
+
data: list[ProjectChatChunk]
|
|
129
|
+
chatStats: list["ProjectChat.ChatStats"]
|
|
130
|
+
nextCursor: str | None
|
|
131
|
+
|
|
132
|
+
class ChatList(TypedDict):
|
|
133
|
+
"""Response of ``list_recent``.
|
|
134
|
+
|
|
135
|
+
Attributes:
|
|
136
|
+
object (Literal["list"]): Object type identifier.
|
|
137
|
+
data (list[ProjectChat]): The chats, most recently active first.
|
|
138
|
+
nextCursor (str | None): Pass as ``after`` to get the next page.
|
|
139
|
+
``None`` on the last page.
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
object: Literal["list"]
|
|
143
|
+
data: list["ProjectChat"]
|
|
144
|
+
nextCursor: str | None
|
|
145
|
+
|
|
146
|
+
chatId: str
|
|
147
|
+
chatTitle: str | None
|
|
148
|
+
chatCreatedAt: str
|
|
149
|
+
updatedAt: str
|
|
150
|
+
chunkCount: int
|
|
151
|
+
object: Literal["search.project-chat"]
|
|
152
|
+
|
|
153
|
+
@staticmethod
|
|
154
|
+
def _search_body(
|
|
155
|
+
project_id: str,
|
|
156
|
+
query: str,
|
|
157
|
+
chat_ids: list[str] | None,
|
|
158
|
+
exclude_chat_ids: list[str] | None,
|
|
159
|
+
created_after: datetime | str | None,
|
|
160
|
+
created_before: datetime | str | None,
|
|
161
|
+
limit: int | None,
|
|
162
|
+
include_chat_stats: bool | None,
|
|
163
|
+
) -> dict[str, Any]:
|
|
164
|
+
return _body(
|
|
165
|
+
projectId=project_id,
|
|
166
|
+
query=query,
|
|
167
|
+
chatIds=chat_ids,
|
|
168
|
+
excludeChatIds=exclude_chat_ids,
|
|
169
|
+
createdAfter=created_after,
|
|
170
|
+
createdBefore=created_before,
|
|
171
|
+
limit=limit,
|
|
172
|
+
includeChatStats=include_chat_stats,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
@staticmethod
|
|
176
|
+
def _chunks_body(
|
|
177
|
+
project_id: str,
|
|
178
|
+
chat_id: str,
|
|
179
|
+
limit: int | None,
|
|
180
|
+
after: str | None,
|
|
181
|
+
include_chat_stats: bool | None,
|
|
182
|
+
) -> dict[str, Any]:
|
|
183
|
+
return _body(
|
|
184
|
+
projectId=project_id,
|
|
185
|
+
chatId=chat_id,
|
|
186
|
+
limit=limit,
|
|
187
|
+
after=after,
|
|
188
|
+
includeChatStats=include_chat_stats,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
@staticmethod
|
|
192
|
+
def _recent_body(
|
|
193
|
+
project_id: str,
|
|
194
|
+
exclude_chat_ids: list[str] | None,
|
|
195
|
+
updated_after: datetime | str | None,
|
|
196
|
+
updated_before: datetime | str | None,
|
|
197
|
+
limit: int | None,
|
|
198
|
+
after: str | None,
|
|
199
|
+
) -> dict[str, Any]:
|
|
200
|
+
return _body(
|
|
201
|
+
projectId=project_id,
|
|
202
|
+
excludeChatIds=exclude_chat_ids,
|
|
203
|
+
updatedAfter=updated_after,
|
|
204
|
+
updatedBefore=updated_before,
|
|
205
|
+
limit=limit,
|
|
206
|
+
after=after,
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
@classmethod
|
|
210
|
+
def search(
|
|
211
|
+
cls,
|
|
212
|
+
user_id: str,
|
|
213
|
+
company_id: str,
|
|
214
|
+
*,
|
|
215
|
+
project_id: str,
|
|
216
|
+
query: str,
|
|
217
|
+
chat_ids: list[str] | None = None,
|
|
218
|
+
exclude_chat_ids: list[str] | None = None,
|
|
219
|
+
created_after: datetime | str | None = None,
|
|
220
|
+
created_before: datetime | str | None = None,
|
|
221
|
+
limit: int | None = None,
|
|
222
|
+
include_chat_stats: bool | None = None,
|
|
223
|
+
) -> "ProjectChat.ChunkList":
|
|
224
|
+
"""Search the earlier chats of a project the user owns.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
user_id (str): The user who owns the project.
|
|
228
|
+
company_id (str): The user's company.
|
|
229
|
+
project_id (str): The project to search.
|
|
230
|
+
query (str): What to look for, at most 2000 characters.
|
|
231
|
+
chat_ids (list[str] | None): Only search these chats, at most 200.
|
|
232
|
+
exclude_chat_ids (list[str] | None): Leave out these chats, at
|
|
233
|
+
most 200, for example the current one.
|
|
234
|
+
created_after (datetime | str | None): Only chunks whose first
|
|
235
|
+
message is at or after this time. Use a timezone-aware
|
|
236
|
+
datetime or an ISO 8601 string.
|
|
237
|
+
created_before (datetime | str | None): Only chunks whose first
|
|
238
|
+
message is at or before this time.
|
|
239
|
+
limit (int | None): Number of chunks, 1 to 50. The endpoint
|
|
240
|
+
defaults to 20.
|
|
241
|
+
include_chat_stats (bool | None): Also return chunk and token
|
|
242
|
+
totals of the chats in the result.
|
|
243
|
+
|
|
244
|
+
Returns:
|
|
245
|
+
ProjectChat.ChunkList: The best matching chunks, with ``score``
|
|
246
|
+
and ``highlights`` set. ``nextCursor`` is always ``None``.
|
|
247
|
+
|
|
248
|
+
Raises:
|
|
249
|
+
InvalidRequestError: The project does not exist or belongs to
|
|
250
|
+
another user (404), or a parameter is invalid (400).
|
|
251
|
+
AuthenticationError: The API key is missing or invalid (401).
|
|
252
|
+
PermissionError: Projects are off for the company, or the user
|
|
253
|
+
may not read chats (403).
|
|
254
|
+
APIError: Any other API failure.
|
|
255
|
+
"""
|
|
256
|
+
return cast(
|
|
257
|
+
"ProjectChat.ChunkList",
|
|
258
|
+
cls._static_request(
|
|
259
|
+
"post",
|
|
260
|
+
_SEARCH_URL,
|
|
261
|
+
user_id,
|
|
262
|
+
company_id,
|
|
263
|
+
params=cls._search_body(
|
|
264
|
+
project_id,
|
|
265
|
+
query,
|
|
266
|
+
chat_ids,
|
|
267
|
+
exclude_chat_ids,
|
|
268
|
+
created_after,
|
|
269
|
+
created_before,
|
|
270
|
+
limit,
|
|
271
|
+
include_chat_stats,
|
|
272
|
+
),
|
|
273
|
+
),
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
@classmethod
|
|
277
|
+
async def search_async(
|
|
278
|
+
cls,
|
|
279
|
+
user_id: str,
|
|
280
|
+
company_id: str,
|
|
281
|
+
*,
|
|
282
|
+
project_id: str,
|
|
283
|
+
query: str,
|
|
284
|
+
chat_ids: list[str] | None = None,
|
|
285
|
+
exclude_chat_ids: list[str] | None = None,
|
|
286
|
+
created_after: datetime | str | None = None,
|
|
287
|
+
created_before: datetime | str | None = None,
|
|
288
|
+
limit: int | None = None,
|
|
289
|
+
include_chat_stats: bool | None = None,
|
|
290
|
+
) -> "ProjectChat.ChunkList":
|
|
291
|
+
"""Search the earlier chats of a project the user owns.
|
|
292
|
+
|
|
293
|
+
See ``search`` for the arguments, return value and errors.
|
|
294
|
+
"""
|
|
295
|
+
return cast(
|
|
296
|
+
"ProjectChat.ChunkList",
|
|
297
|
+
await cls._static_request_async(
|
|
298
|
+
"post",
|
|
299
|
+
_SEARCH_URL,
|
|
300
|
+
user_id,
|
|
301
|
+
company_id,
|
|
302
|
+
params=cls._search_body(
|
|
303
|
+
project_id,
|
|
304
|
+
query,
|
|
305
|
+
chat_ids,
|
|
306
|
+
exclude_chat_ids,
|
|
307
|
+
created_after,
|
|
308
|
+
created_before,
|
|
309
|
+
limit,
|
|
310
|
+
include_chat_stats,
|
|
311
|
+
),
|
|
312
|
+
),
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
@classmethod
|
|
316
|
+
def list_chunks(
|
|
317
|
+
cls,
|
|
318
|
+
user_id: str,
|
|
319
|
+
company_id: str,
|
|
320
|
+
*,
|
|
321
|
+
project_id: str,
|
|
322
|
+
chat_id: str,
|
|
323
|
+
limit: int | None = None,
|
|
324
|
+
after: str | None = None,
|
|
325
|
+
include_chat_stats: bool | None = None,
|
|
326
|
+
) -> "ProjectChat.ChunkList":
|
|
327
|
+
"""Read one chat of a project the user owns, in order.
|
|
328
|
+
|
|
329
|
+
Args:
|
|
330
|
+
user_id (str): The user who owns the project.
|
|
331
|
+
company_id (str): The user's company.
|
|
332
|
+
project_id (str): The project of the chat.
|
|
333
|
+
chat_id (str): The chat to read.
|
|
334
|
+
limit (int | None): Number of chunks per page, 1 to 50. The
|
|
335
|
+
endpoint defaults to 20.
|
|
336
|
+
after (str | None): ``nextCursor`` of the previous page.
|
|
337
|
+
include_chat_stats (bool | None): Also return the chunk and token
|
|
338
|
+
totals of the chat.
|
|
339
|
+
|
|
340
|
+
Returns:
|
|
341
|
+
ProjectChat.ChunkList: One page of chunks, ordered by
|
|
342
|
+
``chunkIndex``. ``score`` and ``highlights`` are ``None``.
|
|
343
|
+
|
|
344
|
+
Raises:
|
|
345
|
+
InvalidRequestError: The project does not exist or belongs to
|
|
346
|
+
another user (404), or a parameter is invalid (400).
|
|
347
|
+
AuthenticationError: The API key is missing or invalid (401).
|
|
348
|
+
PermissionError: Projects are off for the company, or the user
|
|
349
|
+
may not read chats (403).
|
|
350
|
+
APIError: Any other API failure.
|
|
351
|
+
"""
|
|
352
|
+
return cast(
|
|
353
|
+
"ProjectChat.ChunkList",
|
|
354
|
+
cls._static_request(
|
|
355
|
+
"post",
|
|
356
|
+
_CHUNKS_URL,
|
|
357
|
+
user_id,
|
|
358
|
+
company_id,
|
|
359
|
+
params=cls._chunks_body(
|
|
360
|
+
project_id, chat_id, limit, after, include_chat_stats
|
|
361
|
+
),
|
|
362
|
+
),
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
@classmethod
|
|
366
|
+
async def list_chunks_async(
|
|
367
|
+
cls,
|
|
368
|
+
user_id: str,
|
|
369
|
+
company_id: str,
|
|
370
|
+
*,
|
|
371
|
+
project_id: str,
|
|
372
|
+
chat_id: str,
|
|
373
|
+
limit: int | None = None,
|
|
374
|
+
after: str | None = None,
|
|
375
|
+
include_chat_stats: bool | None = None,
|
|
376
|
+
) -> "ProjectChat.ChunkList":
|
|
377
|
+
"""Read one chat of a project the user owns, in order.
|
|
378
|
+
|
|
379
|
+
See ``list_chunks`` for the arguments, return value and errors.
|
|
380
|
+
"""
|
|
381
|
+
return cast(
|
|
382
|
+
"ProjectChat.ChunkList",
|
|
383
|
+
await cls._static_request_async(
|
|
384
|
+
"post",
|
|
385
|
+
_CHUNKS_URL,
|
|
386
|
+
user_id,
|
|
387
|
+
company_id,
|
|
388
|
+
params=cls._chunks_body(
|
|
389
|
+
project_id, chat_id, limit, after, include_chat_stats
|
|
390
|
+
),
|
|
391
|
+
),
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
@classmethod
|
|
395
|
+
def list_recent(
|
|
396
|
+
cls,
|
|
397
|
+
user_id: str,
|
|
398
|
+
company_id: str,
|
|
399
|
+
*,
|
|
400
|
+
project_id: str,
|
|
401
|
+
exclude_chat_ids: list[str] | None = None,
|
|
402
|
+
updated_after: datetime | str | None = None,
|
|
403
|
+
updated_before: datetime | str | None = None,
|
|
404
|
+
limit: int | None = None,
|
|
405
|
+
after: str | None = None,
|
|
406
|
+
) -> "ProjectChat.ChatList":
|
|
407
|
+
"""List the chats of a project the user owns, most recently active first.
|
|
408
|
+
|
|
409
|
+
Args:
|
|
410
|
+
user_id (str): The user who owns the project.
|
|
411
|
+
company_id (str): The user's company.
|
|
412
|
+
project_id (str): The project to list.
|
|
413
|
+
exclude_chat_ids (list[str] | None): Leave out these chats, at
|
|
414
|
+
most 200.
|
|
415
|
+
updated_after (datetime | str | None): Only chats active at or
|
|
416
|
+
after this time. Use a timezone-aware datetime or an ISO 8601
|
|
417
|
+
string.
|
|
418
|
+
updated_before (datetime | str | None): Only chats last active at
|
|
419
|
+
or before this time.
|
|
420
|
+
limit (int | None): Number of chats per page, 1 to 20. The
|
|
421
|
+
endpoint defaults to 20.
|
|
422
|
+
after (str | None): ``nextCursor`` of the previous page.
|
|
423
|
+
|
|
424
|
+
Returns:
|
|
425
|
+
ProjectChat.ChatList: One page of chats.
|
|
426
|
+
|
|
427
|
+
Raises:
|
|
428
|
+
InvalidRequestError: The project does not exist or belongs to
|
|
429
|
+
another user (404), or a parameter is invalid (400).
|
|
430
|
+
AuthenticationError: The API key is missing or invalid (401).
|
|
431
|
+
PermissionError: Projects are off for the company, or the user
|
|
432
|
+
may not read chats (403).
|
|
433
|
+
APIError: Any other API failure.
|
|
434
|
+
"""
|
|
435
|
+
return cast(
|
|
436
|
+
"ProjectChat.ChatList",
|
|
437
|
+
cls._static_request(
|
|
438
|
+
"post",
|
|
439
|
+
_RECENT_URL,
|
|
440
|
+
user_id,
|
|
441
|
+
company_id,
|
|
442
|
+
params=cls._recent_body(
|
|
443
|
+
project_id,
|
|
444
|
+
exclude_chat_ids,
|
|
445
|
+
updated_after,
|
|
446
|
+
updated_before,
|
|
447
|
+
limit,
|
|
448
|
+
after,
|
|
449
|
+
),
|
|
450
|
+
),
|
|
451
|
+
)
|
|
452
|
+
|
|
453
|
+
@classmethod
|
|
454
|
+
async def list_recent_async(
|
|
455
|
+
cls,
|
|
456
|
+
user_id: str,
|
|
457
|
+
company_id: str,
|
|
458
|
+
*,
|
|
459
|
+
project_id: str,
|
|
460
|
+
exclude_chat_ids: list[str] | None = None,
|
|
461
|
+
updated_after: datetime | str | None = None,
|
|
462
|
+
updated_before: datetime | str | None = None,
|
|
463
|
+
limit: int | None = None,
|
|
464
|
+
after: str | None = None,
|
|
465
|
+
) -> "ProjectChat.ChatList":
|
|
466
|
+
"""List the chats of a project the user owns, most recently active first.
|
|
467
|
+
|
|
468
|
+
See ``list_recent`` for the arguments, return value and errors.
|
|
469
|
+
"""
|
|
470
|
+
return cast(
|
|
471
|
+
"ProjectChat.ChatList",
|
|
472
|
+
await cls._static_request_async(
|
|
473
|
+
"post",
|
|
474
|
+
_RECENT_URL,
|
|
475
|
+
user_id,
|
|
476
|
+
company_id,
|
|
477
|
+
params=cls._recent_body(
|
|
478
|
+
project_id,
|
|
479
|
+
exclude_chat_ids,
|
|
480
|
+
updated_after,
|
|
481
|
+
updated_before,
|
|
482
|
+
limit,
|
|
483
|
+
after,
|
|
484
|
+
),
|
|
485
|
+
),
|
|
486
|
+
)
|
|
@@ -110,6 +110,17 @@ from unique_sdk.cli.commands.subagent import cmd_subagent
|
|
|
110
110
|
from unique_sdk.cli.commands.subagent import (
|
|
111
111
|
is_error_output as _is_subagent_error_output,
|
|
112
112
|
)
|
|
113
|
+
from unique_sdk.cli.commands.user_memory import (
|
|
114
|
+
MAX_STDIN_BYTES,
|
|
115
|
+
MEMORY_ERROR_PREFIX,
|
|
116
|
+
access_denied_output,
|
|
117
|
+
cmd_memory_read,
|
|
118
|
+
cmd_memory_write,
|
|
119
|
+
memory_access_enabled,
|
|
120
|
+
)
|
|
121
|
+
from unique_sdk.cli.commands.user_memory import (
|
|
122
|
+
is_error_output as _is_memory_error_output,
|
|
123
|
+
)
|
|
113
124
|
from unique_sdk.cli.commands.web_search import (
|
|
114
125
|
QUERY_REVIEW_WAIT_TIMEOUT_SECONDS,
|
|
115
126
|
cmd_web_crawl,
|
|
@@ -229,6 +240,7 @@ Examples:
|
|
|
229
240
|
unique-cli versions cont_abc123 List archived file versions
|
|
230
241
|
unique-cli restore-version cver_1 Restore a file from a version
|
|
231
242
|
unique-cli elicit ask "Which?" Ask the user a question synchronously
|
|
243
|
+
unique-cli memory read Show your memory profile and its version
|
|
232
244
|
unique-cli subagent Legal "Review" Invoke a connected space/subagent
|
|
233
245
|
unique-cli web-search search "x" Search the web via the public API
|
|
234
246
|
unique-cli web-search crawl URL Crawl a URL via the public API
|
|
@@ -1295,6 +1307,91 @@ def schedule_delete(ctx: click.Context, task_id: str) -> None:
|
|
|
1295
1307
|
ctx.exit(1)
|
|
1296
1308
|
|
|
1297
1309
|
|
|
1310
|
+
# -- User memory ----------------------------------------------------------
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
@main.group()
|
|
1314
|
+
def memory() -> None:
|
|
1315
|
+
"""Read or change the signed-in user's memory profile.
|
|
1316
|
+
|
|
1317
|
+
\b
|
|
1318
|
+
The profile is stored per user, not in a knowledge-base folder, so a
|
|
1319
|
+
space's knowledge scope does not limit it. Both commands work only
|
|
1320
|
+
when the platform sets $UNIQUE_USER_MEMORY_ACCESS=1 for the turn.
|
|
1321
|
+
|
|
1322
|
+
\b
|
|
1323
|
+
Subcommands:
|
|
1324
|
+
read Print the profile body and its version
|
|
1325
|
+
write Replace the profile body with the text on stdin
|
|
1326
|
+
"""
|
|
1327
|
+
|
|
1328
|
+
|
|
1329
|
+
@memory.command(name="read")
|
|
1330
|
+
@click.pass_context
|
|
1331
|
+
def memory_read(ctx: click.Context) -> None:
|
|
1332
|
+
"""Print the memory profile body, preceded by a `version:` line.
|
|
1333
|
+
|
|
1334
|
+
\b
|
|
1335
|
+
Pass that version to `unique-cli memory write --expect-version`.
|
|
1336
|
+
A user without a profile reads `version: none`.
|
|
1337
|
+
|
|
1338
|
+
\b
|
|
1339
|
+
Examples:
|
|
1340
|
+
unique-cli memory read
|
|
1341
|
+
"""
|
|
1342
|
+
if not memory_access_enabled():
|
|
1343
|
+
emit(access_denied_output(), is_error=_is_memory_error_output)
|
|
1344
|
+
return
|
|
1345
|
+
emit(cmd_memory_read(LazyState.get(ctx)), is_error=_is_memory_error_output)
|
|
1346
|
+
|
|
1347
|
+
|
|
1348
|
+
@memory.command(name="write")
|
|
1349
|
+
@click.option(
|
|
1350
|
+
"--expect-version",
|
|
1351
|
+
required=True,
|
|
1352
|
+
help="The version `unique-cli memory read` printed. The write is "
|
|
1353
|
+
"refused when the stored profile changed since then.",
|
|
1354
|
+
)
|
|
1355
|
+
@click.pass_context
|
|
1356
|
+
def memory_write(ctx: click.Context, expect_version: str) -> None:
|
|
1357
|
+
"""Replace the memory profile body with the text on stdin.
|
|
1358
|
+
|
|
1359
|
+
\b
|
|
1360
|
+
Pass the complete profile body, starting with its first `## ` section.
|
|
1361
|
+
Frontmatter on stdin is ignored; the platform writes its own. The
|
|
1362
|
+
text is never written to disk. stdin may hold at most 272 KiB, and
|
|
1363
|
+
the body after frontmatter at most 256 KiB.
|
|
1364
|
+
|
|
1365
|
+
\b
|
|
1366
|
+
Examples:
|
|
1367
|
+
unique-cli memory write --expect-version sha256:3f1c9a0b7d2e4f68 <<'EOF'
|
|
1368
|
+
## Identity
|
|
1369
|
+
- Employer: Unique AG
|
|
1370
|
+
EOF
|
|
1371
|
+
"""
|
|
1372
|
+
if not memory_access_enabled():
|
|
1373
|
+
emit(access_denied_output(), is_error=_is_memory_error_output)
|
|
1374
|
+
return
|
|
1375
|
+
raw = click.get_binary_stream("stdin").read(MAX_STDIN_BYTES + 1)
|
|
1376
|
+
if len(raw) > MAX_STDIN_BYTES:
|
|
1377
|
+
emit(
|
|
1378
|
+
f"{MEMORY_ERROR_PREFIX} input is larger than {MAX_STDIN_BYTES} "
|
|
1379
|
+
"bytes; nothing was saved.",
|
|
1380
|
+
is_error=_is_memory_error_output,
|
|
1381
|
+
)
|
|
1382
|
+
return
|
|
1383
|
+
try:
|
|
1384
|
+
text = raw.decode("utf-8")
|
|
1385
|
+
except UnicodeDecodeError:
|
|
1386
|
+
emit(
|
|
1387
|
+
f"{MEMORY_ERROR_PREFIX} input is not valid UTF-8; nothing was saved.",
|
|
1388
|
+
is_error=_is_memory_error_output,
|
|
1389
|
+
)
|
|
1390
|
+
return
|
|
1391
|
+
output = cmd_memory_write(LazyState.get(ctx), text, expect_version=expect_version)
|
|
1392
|
+
emit(output, is_error=_is_memory_error_output)
|
|
1393
|
+
|
|
1394
|
+
|
|
1298
1395
|
# -- Elicitations ----------------------------------------------------------
|
|
1299
1396
|
|
|
1300
1397
|
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"""Read and write the signed-in user's memory profile through the context-memory API.
|
|
2
|
+
|
|
3
|
+
The profile is addressed by user and company, never by a knowledge-base
|
|
4
|
+
folder, so a space's folder scope does not apply to it. Text moves through
|
|
5
|
+
stdin and stdout and is never written to disk.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import hashlib
|
|
11
|
+
import os
|
|
12
|
+
import re
|
|
13
|
+
from datetime import datetime, timezone
|
|
14
|
+
|
|
15
|
+
import unique_sdk
|
|
16
|
+
from unique_sdk.cli.state import ShellState
|
|
17
|
+
|
|
18
|
+
MEMORY_ERROR_PREFIX = "memory:"
|
|
19
|
+
MEMORY_ACCESS_ENV = "UNIQUE_USER_MEMORY_ACCESS"
|
|
20
|
+
MAX_PROFILE_BYTES = 256 * 1024
|
|
21
|
+
# The whole of stdin is bounded too. The 16 KiB on top of the body limit is
|
|
22
|
+
# room for frontmatter, which is dropped before the body limit applies.
|
|
23
|
+
MAX_STDIN_BYTES = MAX_PROFILE_BYTES + 16 * 1024
|
|
24
|
+
NO_PROFILE_VERSION = "none"
|
|
25
|
+
|
|
26
|
+
# The empty case comes first so `---\n---` never scans ahead to a later
|
|
27
|
+
# `---` horizontal rule in the body.
|
|
28
|
+
_FRONTMATTER_RE = re.compile(r"^---\n(?:---|.*?\n---)[ \t]*(?:\n|\Z)", re.DOTALL)
|
|
29
|
+
_TURN_COUNT_RE = re.compile(r"^turn_count:\s*(\d+)\s*$", re.MULTILINE)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class _StoredProfile:
|
|
33
|
+
__slots__ = ("document", "version")
|
|
34
|
+
|
|
35
|
+
def __init__(self, *, document: str, version: str) -> None:
|
|
36
|
+
self.document = document
|
|
37
|
+
self.version = version
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def is_error_output(output: str) -> bool:
|
|
41
|
+
"""Return True if `output` is a memory command error message."""
|
|
42
|
+
return output.startswith(MEMORY_ERROR_PREFIX)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def memory_access_enabled() -> bool:
|
|
46
|
+
"""True when the platform turned memory access on for this turn."""
|
|
47
|
+
return os.environ.get(MEMORY_ACCESS_ENV, "") == "1"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def access_denied_output() -> str:
|
|
51
|
+
return (
|
|
52
|
+
f"{MEMORY_ERROR_PREFIX} permission denied: user memory cannot be "
|
|
53
|
+
"read or changed in this space."
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def profile_body(text: str) -> str:
|
|
58
|
+
"""The profile without its YAML frontmatter, with LF line endings."""
|
|
59
|
+
normalized = text.replace("\r\n", "\n")
|
|
60
|
+
return _FRONTMATTER_RE.sub("", normalized, count=1).strip()
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def stored_profile(*, body: str, previous: str, user_id: str) -> str:
|
|
64
|
+
"""The stored document: platform frontmatter plus the given body."""
|
|
65
|
+
timestamp = datetime.now(timezone.utc).isoformat(timespec="seconds")
|
|
66
|
+
return (
|
|
67
|
+
"---\n"
|
|
68
|
+
f"user_id: {user_id}\n"
|
|
69
|
+
"schema_version: 1\n"
|
|
70
|
+
f"last_updated: {timestamp}\n"
|
|
71
|
+
f"turn_count: {_turn_count(previous)}\n"
|
|
72
|
+
"---\n\n"
|
|
73
|
+
f"{body}\n"
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _turn_count(profile: str) -> int:
|
|
78
|
+
frontmatter = _FRONTMATTER_RE.match(profile)
|
|
79
|
+
if frontmatter is None:
|
|
80
|
+
return 0
|
|
81
|
+
match = _TURN_COUNT_RE.search(frontmatter.group(0))
|
|
82
|
+
return int(match.group(1)) if match else 0
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _load(state: ShellState) -> _StoredProfile:
|
|
86
|
+
try:
|
|
87
|
+
current = unique_sdk.ContextMemory.retrieve(
|
|
88
|
+
user_id=state.config.user_id,
|
|
89
|
+
company_id=state.config.company_id,
|
|
90
|
+
)
|
|
91
|
+
except unique_sdk.UniqueError as e:
|
|
92
|
+
if e.http_status == 404:
|
|
93
|
+
return _StoredProfile(document="", version=NO_PROFILE_VERSION)
|
|
94
|
+
raise
|
|
95
|
+
document = getattr(current, "document", "") or ""
|
|
96
|
+
if not profile_body(document):
|
|
97
|
+
return _StoredProfile(document="", version=NO_PROFILE_VERSION)
|
|
98
|
+
return _StoredProfile(document=document, version=content_version(document))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def content_version(document: str) -> str:
|
|
102
|
+
"""The version of a stored document.
|
|
103
|
+
|
|
104
|
+
A hash of the content, not the API's `updatedAt`: the read that creates a
|
|
105
|
+
user's first profile reports a different `updatedAt` than every later read
|
|
106
|
+
of the same document, which would refuse that user's first save.
|
|
107
|
+
"""
|
|
108
|
+
digest = hashlib.sha256(document.encode("utf-8")).hexdigest()
|
|
109
|
+
return f"sha256:{digest[:16]}"
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def cmd_memory_read(state: ShellState) -> str:
|
|
113
|
+
"""The stored profile body, preceded by its version line."""
|
|
114
|
+
if not memory_access_enabled():
|
|
115
|
+
return access_denied_output()
|
|
116
|
+
try:
|
|
117
|
+
stored = _load(state)
|
|
118
|
+
except unique_sdk.UniqueError as e:
|
|
119
|
+
return f"{MEMORY_ERROR_PREFIX} read failed: {e}"
|
|
120
|
+
body = profile_body(stored.document)
|
|
121
|
+
if not body:
|
|
122
|
+
return f"version: {NO_PROFILE_VERSION}\n\n(no memory profile yet)"
|
|
123
|
+
return f"version: {stored.version}\n\n{body}"
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def cmd_memory_write(state: ShellState, text: str, *, expect_version: str) -> str:
|
|
127
|
+
"""Replace the profile body with `text` if the stored version still matches."""
|
|
128
|
+
if not memory_access_enabled():
|
|
129
|
+
return access_denied_output()
|
|
130
|
+
body = profile_body(text)
|
|
131
|
+
if not body:
|
|
132
|
+
return f"{MEMORY_ERROR_PREFIX} empty profile on stdin; nothing was saved."
|
|
133
|
+
if len(body.encode("utf-8")) > MAX_PROFILE_BYTES:
|
|
134
|
+
return (
|
|
135
|
+
f"{MEMORY_ERROR_PREFIX} profile is larger than "
|
|
136
|
+
f"{MAX_PROFILE_BYTES} bytes; nothing was saved."
|
|
137
|
+
)
|
|
138
|
+
if not body.startswith("## "):
|
|
139
|
+
return (
|
|
140
|
+
f"{MEMORY_ERROR_PREFIX} the profile must start with its first "
|
|
141
|
+
"`## ` section heading; nothing was saved."
|
|
142
|
+
)
|
|
143
|
+
try:
|
|
144
|
+
stored = _load(state)
|
|
145
|
+
if stored.version != expect_version.strip():
|
|
146
|
+
return (
|
|
147
|
+
f"{MEMORY_ERROR_PREFIX} the profile changed since it was read "
|
|
148
|
+
f"(now version {stored.version}). Run `unique-cli memory read` "
|
|
149
|
+
"again and reapply the change; nothing was saved."
|
|
150
|
+
)
|
|
151
|
+
if profile_body(stored.document) == body:
|
|
152
|
+
return "Memory unchanged; nothing was saved."
|
|
153
|
+
document = stored_profile(
|
|
154
|
+
body=body, previous=stored.document, user_id=state.config.user_id
|
|
155
|
+
)
|
|
156
|
+
_ = unique_sdk.ContextMemory.modify(
|
|
157
|
+
user_id=state.config.user_id,
|
|
158
|
+
company_id=state.config.company_id,
|
|
159
|
+
document=document,
|
|
160
|
+
)
|
|
161
|
+
except unique_sdk.UniqueError as e:
|
|
162
|
+
return f"{MEMORY_ERROR_PREFIX} save failed: {e}"
|
|
163
|
+
return f"Memory saved ({len(document.encode('utf-8'))} bytes)."
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/__init__.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_acronyms.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_agentic_table.py
RENAMED
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_benchmarking.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_briefing.py
RENAMED
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_content.py
RENAMED
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_elicitation.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_embedding.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_event.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_folder.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_group.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_integrated.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_llm_models.py
RENAMED
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_message.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_message_log.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_message_tool.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_module.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_search.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_search_string.py
RENAMED
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_space.py
RENAMED
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/api_resources/_web_search.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/agentic_table.py
RENAMED
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/browser.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/cite_file.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/elicitation.py
RENAMED
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/folders.py
RENAMED
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/navigation.py
RENAMED
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/scheduled_tasks.py
RENAMED
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/subagent.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/cli/commands/web_search.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/utils/analytics_order_run.py
RENAMED
|
File without changes
|
{unique_sdk-2026.50.0.dev12 → unique_sdk-2026.50.0.dev14}/unique_sdk/utils/benchmarking_run.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|