-
Notifications
You must be signed in to change notification settings - Fork 0
feat: default value for logos chat client #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kaichaosun
wants to merge
2
commits into
main
Choose a base branch
from
chat-client-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+131
−33
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env python3 | ||
| """Mock keypackage/account registry for the chat-cli CI smoketest. | ||
|
|
||
| On startup the client registers its keypackage and account bundle. Publishing the | ||
| bundle first fetches any existing record, so the stub answers: | ||
|
|
||
| * POST /v0/keypackage, POST /v0/account -> 200 (accept the write) | ||
| * GET (any) -> 404 (nothing published yet) | ||
|
|
||
| A 404 is what a fresh account looks like, which the client reads as "no existing | ||
| record". This validates nothing — it only unblocks the smoketest; protocol-level | ||
| behavior is covered by the workspace tests. | ||
| """ | ||
|
|
||
| from http.server import BaseHTTPRequestHandler, HTTPServer | ||
|
|
||
|
|
||
| class Handler(BaseHTTPRequestHandler): | ||
| # Match the client's HTTP/1.1 requests so reqwest frames the response body. | ||
| protocol_version = "HTTP/1.1" | ||
|
|
||
| def _drain(self): | ||
| # Consume the request body so the client's request completes cleanly. | ||
| length = int(self.headers.get("Content-Length", 0)) | ||
| if length: | ||
| self.rfile.read(length) | ||
|
|
||
| def _reply(self, status): | ||
| self.send_response(status) | ||
| self.send_header("Content-Length", "0") | ||
| self.end_headers() | ||
|
|
||
| def do_POST(self): | ||
| self._drain() | ||
| self._reply(200) | ||
|
|
||
| def do_GET(self): | ||
| self._drain() | ||
| self._reply(404) | ||
|
|
||
| def log_message(self, *args): | ||
| pass | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| HTTPServer(("127.0.0.1", 18080), Handler).serve_forever() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| //! The opinionated Logos client. | ||
| //! | ||
| //! [`ChatClientBuilder`] is generic and can only default the zero-config | ||
| //! components (random identity, ephemeral registry, in-memory storage) — it has | ||
| //! no way to know a registry endpoint or a database path, so its defaults are | ||
| //! the test-grade ones. `LogosChatClient` is the layer that *does* commit to a | ||
| //! stack: a delegate identity, the HTTP keypackage + account registry, and | ||
| //! encrypted on-disk storage. It exists so independently built clients share the | ||
| //! same production services instead of each re-deriving them. | ||
| //! | ||
| //! Only the transport is left to the caller: it carries native dependencies and | ||
| //! environment-specific configuration that belong to the binary, not here. | ||
|
|
||
| use crossbeam_channel::Receiver; | ||
| use libchat::{ChatStorage, StorageConfig}; | ||
|
|
||
| use crate::ChatClientBuilder; | ||
| use crate::client::{ChatClient, Transport}; | ||
| use crate::delegate::DelegateSigner; | ||
| use crate::errors::ClientError; | ||
| use crate::event::Event; | ||
| use components::HttpRegistry; | ||
|
|
||
| // The endpoint for account and keypackage registration service. | ||
| const REGISTRY_ENDPOINT: &str = "https://devnet.chat-kc.logos.co"; | ||
|
|
||
| /// A [`ChatClient`] wired to the Logos service stack: a [`DelegateSigner`] | ||
| /// identity, the HTTP keypackage + account registry ([`HttpRegistry`], which is | ||
| /// both the keypackage store and the account → device directory), and encrypted | ||
| /// [`ChatStorage`]. Only the transport `T` is supplied by the caller. | ||
| pub type LogosChatClient<T> = ChatClient<DelegateSigner, T, HttpRegistry, ChatStorage>; | ||
|
|
||
| impl<T> LogosChatClient<T> | ||
| where | ||
| T: Transport + Send + 'static, | ||
| { | ||
| /// Open a client on the Logos stack over `transport`, persisting to the | ||
| /// encrypted database at `db_path` unlocked with `db_key`. When `registry_url` | ||
| /// is `Some`, it overrides the preconfigured registry endpoint (e.g. a local | ||
| /// deployment); otherwise the baked-in endpoint is used. | ||
| /// | ||
| /// `db_path` is a per-client location and `db_key` is a secret, so both are | ||
| /// caller-supplied — never baked into the library. | ||
|
kaichaosun marked this conversation as resolved.
|
||
| pub fn open( | ||
| transport: T, | ||
|
kaichaosun marked this conversation as resolved.
|
||
| db_path: impl Into<String>, | ||
| db_key: impl Into<String>, | ||
| registry_url: Option<&str>, | ||
|
kaichaosun marked this conversation as resolved.
|
||
| ) -> Result<(Self, Receiver<Event>), ClientError> { | ||
| let endpoint = registry_url.unwrap_or(REGISTRY_ENDPOINT); | ||
| ChatClientBuilder::new() | ||
| .ident(DelegateSigner::random()) | ||
| .transport(transport) | ||
| .registration(HttpRegistry::new(endpoint)) | ||
| .storage_config(StorageConfig::Encrypted { | ||
| path: db_path.into(), | ||
| key: db_key.into(), | ||
| }) | ||
| .build() | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having LogosChatClient located within the "Generic client" seems like it will be full of friction as the objects have separate concerns.
the "GenericClient will tend to be more generic/abstract" and the LogosChatClient will tend towards importing specific implementations and services.
[Sand] LogosChatClient would benefit from being a separate crate, to keep imports separated. That way it can import LogosCore specific implementations and GenericClient could remain free of these implementation details
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split LogosChatClient to its own crate looks too early, we can do it later.
The landscape may also change as we move to production ready, and move ephemeral/in memory dependencies to test.