melaya 0.1.4 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1dac0d815408d37da57f6288caec96ebd16db731405ae977759211cba627ac0
4
- data.tar.gz: adc032f6a8446ae788f0c4288b0b14d755288c92c50cd10cd5400dd8874dad74
3
+ metadata.gz: 47fefbce18553e5a38d414eb96ad35da805b1bb4d685e9fd809206b00d2dbe68
4
+ data.tar.gz: 822418410f53fc0cb03caf2fd06a8a122db8082e58ded4c68f6032dea5898965
5
5
  SHA512:
6
- metadata.gz: 6088333696eec5b43ec4d917477b4afd628f136507d2b492f4d50d540836645aaf76e7bbc2427fa19bca2ed05a5444a148d9b189a8c4a04b4a257d8536a9a777
7
- data.tar.gz: 1c2e6cb42d6a23940c49a1b0fbd7a07160416923584541106b2a11935a9ca67bf16f6b18561d8f1099a4be7b3b70e3e93a7eb0f31ee4b5e298325635ad74ab3e
6
+ metadata.gz: 7680af7ede9b7cfa4e4fa2c6860c3e40260c488f2a3b6906930382b9a44ab36862ff8117ac6ce533bcac5fe5d7b8f12c4961257a61c149ebf6c07953da84e1e7
7
+ data.tar.gz: 6e929c21c54d44b99c0cfffa1d717ca85ca95bf0c95ecbc1d2e260e9343e8cc4383d47e38d7b9ffe965aa15798e7ee202ae2230f2fc4de75a21b15bdd2aa500e
data/LICENSE ADDED
@@ -0,0 +1,158 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but not
32
+ limited to compiled object code, generated documentation, and
33
+ conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including the
48
+ original version of the Work and any modifications or additions
49
+ to that Work or Derivative Works thereof, that is intentionally
50
+ submitted to Licensor for inclusion in the Work by the copyright owner
51
+ or by an individual or Legal Entity authorized to submit on behalf of
52
+ the copyright owner. For the purposes of this definition, "submitted"
53
+ means any form of electronic, verbal, or written communication sent
54
+ to the Licensor or its representatives, including but not limited to
55
+ communication on electronic mailing lists, source code control systems,
56
+ and issue tracking systems that are managed by, or on behalf of, the
57
+ Licensor for the purpose of discussing and improving the Work, but
58
+ excluding communication that is conspicuously marked or otherwise
59
+ designated in writing by the copyright owner as "Not a Contribution."
60
+
61
+ "Contributor" shall mean Licensor and any individual or Legal Entity
62
+ on behalf of whom a Contribution has been received by Licensor and
63
+ subsequently incorporated within the Work.
64
+
65
+ 2. Grant of Copyright License. Subject to the terms and conditions of
66
+ this License, each Contributor hereby grants to You a perpetual,
67
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
68
+ copyright license to reproduce, prepare Derivative Works of,
69
+ publicly display, publicly perform, sublicense, and distribute the
70
+ Work and such Derivative Works in Source or Object form.
71
+
72
+ 3. Grant of Patent License. Subject to the terms and conditions of
73
+ this License, each Contributor hereby grants to You a perpetual,
74
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
75
+ (except as stated in this section) patent license to make, have made,
76
+ use, offer to sell, sell, import, and otherwise transfer the Work,
77
+ where such license applies only to those patent claims licensable
78
+ by such Contributor that are necessarily infringed by their
79
+ Contribution(s) alone or by combination of their Contribution(s)
80
+ with the Work to which such Contribution(s) was submitted. If You
81
+ institute patent litigation against any entity (including a
82
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
83
+ or a Contribution incorporated within the Work constitutes direct
84
+ or contributory patent infringement, then any patent licenses
85
+ granted to You under this License for that Work shall terminate
86
+ as of the date such litigation is filed.
87
+
88
+ 4. Redistribution. You may reproduce and distribute copies of the
89
+ Work or Derivative Works thereof in any medium, with or without
90
+ modifications, and in Source or Object form, provided that You
91
+ meet the following conditions:
92
+
93
+ (a) You must give any other recipients of the Work or Derivative
94
+ Works a copy of this License; and
95
+
96
+ (b) You must cause any modified files to carry prominent notices
97
+ stating that You changed the files; and
98
+
99
+ (c) You must retain, in the Source form of any Derivative Works
100
+ that You distribute, all copyright, patent, trademark, and
101
+ attribution notices from the Source form of the Work; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, then any Derivative Works that You distribute must
105
+ include a readable copy of the attribution notices contained
106
+ within such NOTICE file.
107
+
108
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
109
+ any Contribution intentionally submitted for inclusion in the Work
110
+ by You to the Licensor shall be under the terms and conditions of
111
+ this License, without any additional terms or conditions.
112
+
113
+ 6. Trademarks. This License does not grant permission to use the trade
114
+ names, trademarks, service marks, or product names of the Licensor,
115
+ except as required for reasonable and customary use in describing the
116
+ origin of the Work and reproducing the content of the NOTICE file.
117
+
118
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed
119
+ to in writing, Licensor provides the Work (and each Contributor
120
+ provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
121
+ OR CONDITIONS OF ANY KIND, either express or implied, including,
122
+ without limitation, any warranties or conditions of TITLE,
123
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
124
+ PURPOSE. You are solely responsible for determining the
125
+ appropriateness of using or redistributing the Work.
126
+
127
+ 8. Limitation of Liability. In no event and under no legal theory,
128
+ whether in tort (including negligence), contract, or otherwise,
129
+ unless required by applicable law (such as deliberate and grossly
130
+ negligent acts) or agreed to in writing, shall any Contributor be
131
+ liable to You for damages, including any direct, indirect, special,
132
+ incidental, or consequential damages of any character arising as a
133
+ result of this License or out of the use or inability to use the
134
+ Work.
135
+
136
+ 9. Accepting Warranty or Additional Liability. While redistributing
137
+ the Work or Derivative Works thereof, You may choose to offer, and
138
+ charge a fee for, acceptance of support, warranty, indemnity, or
139
+ other liability obligations and/or rights consistent with this
140
+ License. However, in accepting such obligations, You may act only
141
+ on Your own behalf and on Your sole responsibility, not on behalf
142
+ of any other Contributor.
143
+
144
+ END OF TERMS AND CONDITIONS
145
+
146
+ Copyright 2026 Melaya (Antoine Roche)
147
+
148
+ Licensed under the Apache License, Version 2.0 (the "License");
149
+ you may not use this file except in compliance with the License.
150
+ You may obtain a copy of the License at
151
+
152
+ http://www.apache.org/licenses/LICENSE-2.0
153
+
154
+ Unless required by applicable law or agreed to in writing, software
155
+ distributed under the License is distributed on an "AS IS" BASIS,
156
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
157
+ See the License for the specific language governing permissions and
158
+ limitations under the License.
data/README.md CHANGED
@@ -1,10 +1,15 @@
1
1
  # melaya
2
2
 
3
- Official Ruby SDK for the **[Melaya](https://melaya.org)** trading platform — normalized market data, paper + live trading, backtesting, and an AI agentic trading crew across **70+ venues**, powered by an in-house Rust engine.
3
+ > **Current production scope:** Agent Builder and Mobile Device Control are available now. Melaya Trading namespaces are preview-only and not generally available; do not use them with real funds.
4
+
5
+ Official SDK for the **[Melaya](https://melaya.org)** Agent Builder and flagship Mobile Device Control APIs. Trading namespaces are included only as a preview of a later product.
6
+
7
+ **Melaya products:** [Melaya Agents](https://melaya.org/en/product/agentic-framework) · [Melaya Assistant](https://melaya.org/en/product/assistant) · [Device Control](https://melaya.org/en/product/agentic-device-control) · [Browser Control](https://melaya.org/en/product/agentic-browser-control) · [MCP Server](https://melaya.org/en/product/mcp) · [Melaya Marketing](https://melaya.org/en/product/marketing)
4
8
 
5
9
  - Zero runtime gem dependencies (stdlib `net/http`, `openssl`, `json` only).
10
+ - Full Agent Builder lifecycle: projects, pipelines, templates, Connectors, HITL, evals, events, billing, team, and runner management.
11
+ - Catalogs of **1,500+ scoped tools**, **100+ specialized subagents**, and **20+ model providers** (runtime catalog endpoints are the source of truth).
6
12
  - Pure Ruby WebSocket client (RFC 6455) — no external gem required for streaming.
7
- - Full market data, strategies, sim trading, backtesting, and streaming from one client.
8
13
 
9
14
  ## Install
10
15
 
@@ -20,7 +25,128 @@ Or once published to RubyGems:
20
25
  gem install melaya
21
26
  ```
22
27
 
23
- ## Quick start
28
+ ## Agent Builder & Device Control
29
+
30
+ ### Quick start: pair a phone
31
+
32
+ ```ruby
33
+ require "melaya"
34
+
35
+ melaya = Melaya::Client.new(api_key: ENV["MELAYA_API_KEY"]) # keys are prefixed mk_
36
+
37
+ pairing = melaya.agents.phone.pair
38
+ puts "Pairing code: #{pairing["code"]} (expires in #{pairing["expiresInSeconds"]}s)"
39
+ # Enter the code in the Melaya APK on the phone
40
+
41
+ devices = melaya.agents.phone.list_devices
42
+ apps = melaya.agents.phone.list_apps
43
+
44
+ melaya.agents.phone.set_allowed_apps(["com.android.chrome"])
45
+ ```
46
+
47
+ A Melaya platform key is required. "No app API required" means Device Control operates the target app through its user interface; it does not mean the Melaya SDK is unauthenticated.
48
+
49
+ ### Quick start: run an agent pipeline
50
+
51
+ Configure provider credentials through Melaya Connectors first. Never include a provider key in pipeline configuration or per-run overrides.
52
+
53
+ A pipeline's run is generated **only** from `config["steps"]` — a top-level `agents` list alone produces an **empty** pipeline. Every agent a step runs must be embedded inline on that step's `"agent"` key. There is no `prompt` field: the two prompt fields are `instruction` (the task) and, optionally, `system_prompt_override`.
54
+
55
+ ```ruby
56
+ melaya.agents.pipelines.create(
57
+ name: "mobile-review",
58
+ project: "Operations",
59
+ steps: [{
60
+ "kind" => "agent",
61
+ "agent" => {
62
+ "name" => "mobile-operator",
63
+ "role" => "Careful mobile operator",
64
+ "instruction" => "Read before acting. Never send, publish, or delete.",
65
+ "model" => { "provider" => "anthropic", "name" => "claude-sonnet-4-6" },
66
+ "agent_tools" => [
67
+ "phone_get_screen_tree",
68
+ "phone_current_app",
69
+ "phone_open_app",
70
+ "phone_click_text",
71
+ "phone_back",
72
+ "phone_wait"
73
+ ],
74
+ "human_approval_tools" => []
75
+ }
76
+ }],
77
+ maxCostUsd: 1.00
78
+ )
79
+
80
+ run = melaya.agents.pipelines.run("mobile-review", project: "Operations")
81
+ run_id = run["run_id"]
82
+
83
+ melaya.agents.phone.register_active_run(run_id)
84
+
85
+ status = melaya.agents.pipelines.run_status("mobile-review", run_id)
86
+
87
+ # Real-time run events over Socket.IO (connects lazily on first use)
88
+ melaya.events.on_run_update(run_id) { |e| puts e["event_type"] }
89
+ ```
90
+
91
+ Other config fields worth knowing: `"hitl_mode"` (`"safe"` default | `"autonomous"` | `"payments_only"` — only `"safe"` honours each agent's `human_approval_tools`), `"connector_source"` (`"personal"` | `"project"`), `"force_local_runner"`, and `"inputs"` (declared run-input fields, see `run_inputs:` below).
92
+
93
+ `get` returns an **envelope**, not a bare config — `{ "name", "client", "config", "code", "docs" }`. To edit and save, mutate `envelope["config"]` and pass that to `update`:
94
+
95
+ ```ruby
96
+ envelope = melaya.pipelines.get("mobile-review", project: "Operations")
97
+ config = envelope["config"]
98
+ config["steps"][0]["agent"]["model"] = { "provider" => "anthropic", "name" => "claude-opus-4-8" }
99
+ melaya.pipelines.update("mobile-review", config: config, project: "Operations")
100
+ ```
101
+
102
+ ### Quick start: run inputs and file attachments
103
+
104
+ ```ruby
105
+ # Upload a file ahead of a run, then reference it by file_id
106
+ upload = melaya.pipelines.upload_run_file("mobile-review", "screenshot", File.open("shot.png", "rb"))
107
+
108
+ run = melaya.pipelines.run("mobile-review",
109
+ project: "Operations",
110
+ run_inputs: {
111
+ "brief" => "Review the attached screenshot for policy violations.",
112
+ "values" => { "screenshot" => { "file_id" => upload["file_id"] } }
113
+ }
114
+ )
115
+
116
+ # Download a run's own input file back (raw bytes — do not JSON-parse)
117
+ bytes = melaya.pipelines.run_input_file("mobile-review", run["run_id"], 0)
118
+ ```
119
+
120
+ ### Quick start: call a connector tool directly
121
+
122
+ Call any of your already-connected service tools (Gmail, Slack, Stripe, ...) —
123
+ the same surface the MCP server and the Melaya Assistant use. This is
124
+ different from `melaya.connectors`, which only stores project credentials.
125
+
126
+ Reads run immediately. Writes default to `approval: "required"`, which stages
127
+ the same approval card the Assistant raises in the Melaya app and returns
128
+ HTTP 202 (a success, not an error) with a `requestId` to poll; pass
129
+ `approval: "none"` to run a write immediately instead (still audit-logged).
130
+ Money-moving/trading tools are always refused, under both approval modes. No
131
+ method here ever accepts or returns a credential value.
132
+
133
+ ```ruby
134
+ melaya.agents.connector_tools.services # { "services" => [...], "toolCounts" => {...} }
135
+ melaya.agents.connector_tools.search("unread email") # discover tools by keyword
136
+ melaya.agents.connector_tools.describe("gmail_list_messages")
137
+
138
+ # Read — runs immediately
139
+ result = melaya.agents.connector_tools.call("gmail_list_messages", args: { max_results: 5 })
140
+ puts result["result"]
141
+
142
+ # Write — staged for approval by default; block until decided (or it times out)
143
+ outcome = melaya.agents.connector_tools.call_and_wait("gmail_send", args: { to: "a@b.com" })
144
+
145
+ # Also reachable via the flat alias:
146
+ melaya.connector_tools.services
147
+ ```
148
+
149
+ ## Trading quick start (preview)
24
150
 
25
151
  ```ruby
26
152
  require "melaya"
@@ -38,7 +164,7 @@ ob = melaya.market.orderbook(exchange: "bybit", symbol: "BTC/USDT", market: "spo
38
164
  candles = melaya.market.ohlcv(exchange: "okx", symbol: "ETH/USDT", timeframe: "1h", limit: 200)
39
165
  ```
40
166
 
41
- ## Streaming
167
+ ## Streaming (preview)
42
168
 
43
169
  ```ruby
44
170
  # Live ticker (block form — closes when block returns)
@@ -54,7 +180,7 @@ melaya.stream.liquidations(exchange: "binance") do |ev|
54
180
  end
55
181
  ```
56
182
 
57
- ## Trading
183
+ ## Trading (preview)
58
184
 
59
185
  ```ruby
60
186
  # Account: connected exchange keys and usage
@@ -126,21 +252,43 @@ melaya.strategies.delete(sid)
126
252
 
127
253
  ## Authentication
128
254
 
129
- Create an API key in the dashboard (**melaya.org → Settings → API Keys**). Keys are prefixed `mk_`; the SDK sends it automatically on every REST call and WebSocket connection.
255
+ Create an API key in the dashboard (**melaya.org → Settings → API Keys**). Keys are prefixed `mk_`. Every REST call sends the key **only** as an `Authorization: Bearer mk_...` header — never in the URL query string. Public WebSocket market-data streams authenticate with `?apiKey=` in the `wss://` URL (server protocol); private WebSocket streams instead use a short-lived `?wsTicket=` that the SDK mints automatically.
130
256
 
131
257
  Public market-data and account/strategy reads work with the `mk_` key alone. **Live** order placement and live strategy launches additionally require a connected exchange key — connect one in **Settings → Connectors**, then reference it by `apiKeyId`. Paper trading and backtesting never touch a venue and need no exchange credentials.
132
258
 
133
- ## TLS verification
134
-
135
- The SDK verifies TLS certificates by default. To disable on a dev box with TLS interception:
136
-
137
- ```bash
138
- MELAYA_INSECURE_TLS=1 ruby your_script.rb
139
- ```
259
+ ## API surface
140
260
 
141
- Or pass `verify_ssl: false` to the constructor. **Never disable TLS in production.**
261
+ ### Agent Builder & platform (GA)
142
262
 
143
- ## API surface
263
+ | Area | Methods |
264
+ |---|---|
265
+ | Auth | `auth.login`, `verify_mfa`, `register`, `verify_signup`, `resend_verification`, `me`, `check`, `change_password`, `forgot_password`, `reset_password`, `mobile_handoff`, `permissions`, `refresh` |
266
+ | MFA | `auth.mfa_status`, `mfa_setup`, `mfa_confirm` (also via `melaya.platform.mfa`) |
267
+ | Projects | `projects.list`, `create`, `rename`, `runner_projects` |
268
+ | Connectors | `connectors.connected_services`, `set`, `delete`, `env_handle`, `google_oauth_start`, `apply_personal`, `shared_by`, `google_status`, `google_set_default`, `google_disconnect`, `db_test_start`, `db_test_status` |
269
+ | Connector Tools | `connector_tools.services`, `search`, `describe`, `test`, `connect`, `call`, `call_status`, `call_and_wait` |
270
+ | Credentials | `credentials.list`, `connected_services`, `get`, `set`, `delete`, `test`, `list_models`, `google_status`, `google_set_default`, `google_disconnect`, `db_test_start`, `db_test_status`, `telegram_qr_start`, `telegram_qr_poll`, `whatsapp_signup_config`, `whatsapp_signup_exchange`, `tiktok_creator_info`, `substack_email_link_send`, `substack_email_link_redeem`, plus operator-profile, OAuth, and RAG helpers |
271
+ | Pipelines | `pipelines.create`, `get`, `update`, `delete_pipeline`, `list_pipelines`, `run`, `upload_run_file`, `run_inputs`, `run_input_file`, `run_active`, `run_ids`, `run_status`, `cancel_run`, `outputs`, `output`, `preview_code`, `tools`, `subagents`, `instantiate_template`, `build_with_ai` |
272
+ | Pipeline docs & RAG | `pipelines.list_docs`, `upload_doc`, `delete_doc`, `upload_retrieval_doc`, `ingest_retrieval`, `delete_retrieval_doc` |
273
+ | Runs & traces | `pipelines.list`, `recent`, `count`, `traces`, `trace`, `trace_stats`, `delete_traces` |
274
+ | Tool-call audit | `pipelines.project_tool_calls`, `project_tool_call_facets`, `tool_call_detail` |
275
+ | Schedules | `pipelines.list_schedules`, `get_schedule`, `upsert_schedule`, `pause_schedule`, `resume_schedule` |
276
+ | Overview | `pipelines.overview`, `model_prices`, `chart_data`, `cost_breakdown`, `server_version` |
277
+ | Templates | `templates.list`, `list_global`, `list_validated`, `save`, `update`, `duplicate`, `delete`, `share`, `share_targets`, `list_assignments`, `assign(id, user_id:` \| `project_id:)`, `unassign(id, user_id:` \| `project_id:)` |
278
+ | Phone | `phone.pair`, `list_devices`, `revoke_device`, `screen_tree`, `list_apps`, `set_allowed_apps`, `register_active_run`, `grant_app`, `request_cast` |
279
+ | HITL | `hitl.pending`, `history`, `approve`, `reject`, `bulk_decide`, `run_tool_stats`, `run_tool_stats_by_agent`, `run_messages`, `run_tool_calls` |
280
+ | Evals | `evals.list_runs`, `summary`, `run_detail`, `compare`, `memory_graph`, `run_memory`, `crew_memory`, `edit_crew_memory_entry`, `delete_crew_memory_entry`, `benchmarks` |
281
+ | Events | `events.on_run_update`, `on_init_phase`, `on_project_event`, `on_hitl_approval`, `on_pipeline_created`, `on_pipeline_updated`, `on_pipeline_deleted`, `leave_run`, `leave_project`, `close` |
282
+ | Billing | `billing.subscription`, `create_checkout`, `create_portal`, `plans`, `credits`, `ai_credits`, `portfolio_ideas_credits`, `risk_monitoring_credits`, `ambassador_perk`, `redeem_code`, `reserved_promo` |
283
+ | Accounts | `accounts.export_data`, `remove_key`, `update_profile`, `resend_email_verification`, `verify_email` |
284
+ | Runner | `runner.create_token`, `list_tokens`, `revoke_token` |
285
+ | Team | `team.list_members`, `invite`, `create_invite_link`, `accept_invite`, `update_member_role`, `remove_member`, `transfer_ownership`, `get_pipeline_visibility`, `set_pipeline_visibility` |
286
+ | Assistant | `assistant.get_profile`, `set_profile` |
287
+ | Bugs | `bugs.create`, `list_mine`, `get`, `add_comment`, `list_notifications`, `mark_notifications_read` |
288
+
289
+ Every area is also reachable through the domain namespaces: `melaya.agents.*` (pipelines/runs, hitl, assistant, phone, evals, models, connector_tools) and `melaya.platform.*` (projects, credentials, connectors, billing, team, templates, overview, runner, auth, mfa, accounts, bugs, events).
290
+
291
+ ### Trading (preview — not generally available)
144
292
 
145
293
  | Area | Methods |
146
294
  |---|---|
@@ -156,7 +304,7 @@ Or pass `verify_ssl: false` to the constructor. **Never disable TLS in productio
156
304
  | Public streaming | `stream.ticker`, `orderbook`, `ohlcv`, `trades`, `liquidations` |
157
305
  | Private streaming | `stream.strategies`, `stream.private` |
158
306
 
159
- Full docs: **[melaya.org/docs](https://melaya.org/docs)**.
307
+ Full docs: **[melaya.org/documentation](https://melaya.org/documentation)**.
160
308
 
161
309
  ## License
162
310
 
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Melaya
4
+ # Accounts API — GDPR data export, API key management, and profile updates.
5
+ #
6
+ # Maps to /api/v1/private/accounts/* and /api/v1/private/keys/*.
7
+ #
8
+ # Note: credit balance endpoints live in BillingAPI to keep billing concerns
9
+ # co-located. Key listing is in AccountAPI (trading plane) for backward
10
+ # compatibility; this module covers the write/management side.
11
+ class AccountsAPI
12
+ def initialize(http)
13
+ @http = http
14
+ end
15
+
16
+ # POST /api/v1/private/accounts/export
17
+ # GDPR Art 15/20 data export; returns JSON blob of all user data.
18
+ def export_data
19
+ @http.post("/api/v1/private/accounts/export")
20
+ end
21
+
22
+ # POST /api/v1/private/accounts/resend-email-verification
23
+ # Send a verification email to the signed-in account's saved address.
24
+ def resend_email_verification
25
+ @http.post("/api/v1/private/accounts/resend-email-verification")
26
+ end
27
+
28
+ # POST /api/v1/private/accounts/verify-email
29
+ # Confirm saved-email ownership without creating a login session.
30
+ # @param token [String] 64 hex-char verification token
31
+ def verify_email(token)
32
+ @http.post("/api/v1/private/accounts/verify-email", "token" => token)
33
+ end
34
+
35
+ # DELETE /api/v1/private/keys/:keyId
36
+ # Remove a stored CEX API key.
37
+ # @param key_id [String]
38
+ def remove_key(key_id)
39
+ @http.delete("/api/v1/private/keys/#{enc(key_id)}")
40
+ end
41
+
42
+ # PATCH /api/v1/private/accounts/profile
43
+ # Update user display name, avatar, or settings.
44
+ # @param body [Hash]
45
+ def update_profile(body = {})
46
+ @http.patch("/api/v1/private/accounts/profile", body)
47
+ end
48
+
49
+ private
50
+
51
+ def enc(s)
52
+ URI.encode_www_form_component(s.to_s)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Melaya
4
+ # Assistant API — get and save the caller's onboarding / persona profile.
5
+ #
6
+ # The profile is stored envelope-encrypted (service=assistant_profile) and
7
+ # used to personalise the in-app assistant experience.
8
+ #
9
+ # Maps to /api/v1/private/assistant/profile.
10
+ #
11
+ # @example
12
+ # profile = melaya.assistant.get_profile
13
+ # melaya.assistant.set_profile(name: "Antoine", goals: ["grow my trading edge"])
14
+ class AssistantAPI
15
+ def initialize(http)
16
+ @http = http
17
+ end
18
+
19
+ # GET /api/v1/private/assistant/profile
20
+ # Get the caller's assistant onboarding profile.
21
+ def get_profile
22
+ @http.get("/api/v1/private/assistant/profile")
23
+ end
24
+
25
+ # PUT /api/v1/private/assistant/profile
26
+ # Save the caller's assistant onboarding profile.
27
+ # @param name [String, nil]
28
+ # @param goals [Array<String>, nil]
29
+ # @param context [String, nil]
30
+ # @param preferences [Hash, nil]
31
+ # @param extra [Hash] any additional profile fields
32
+ def set_profile(name: nil, goals: nil, context: nil, preferences: nil, **extra)
33
+ profile = extra.transform_keys(&:to_s)
34
+ profile["name"] = name unless name.nil?
35
+ profile["goals"] = goals unless goals.nil?
36
+ profile["context"] = context unless context.nil?
37
+ profile["preferences"] = preferences unless preferences.nil?
38
+ @http.put("/api/v1/private/assistant/profile", profile)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Melaya
4
+ # Auth API — login, MFA, registration, password management, and session tokens.
5
+ #
6
+ # Most endpoints are public (no Bearer token needed for login/register).
7
+ # However, the SDK HttpClient always sends the mk_* API key which is fine —
8
+ # the server simply ignores it for public routes.
9
+ #
10
+ # Maps to /api/v1/private/auth/* and /api/v1/auth/*.
11
+ class AuthAPI
12
+ def initialize(http)
13
+ @http = http
14
+ end
15
+
16
+ # POST /api/v1/private/auth/login
17
+ # Password + username login; returns session JWT + optional MFA challenge token.
18
+ # @param username [String]
19
+ # @param password [String]
20
+ def login(username:, password:)
21
+ @http.post("/api/v1/private/auth/login",
22
+ "username" => username,
23
+ "password" => password)
24
+ end
25
+
26
+ # POST /api/v1/private/auth/mfa/verify
27
+ # Resolve MFA challenge after login.
28
+ # @param challenge_token [String]
29
+ # @param code [String] TOTP or recovery code
30
+ def verify_mfa(challenge_token:, code:)
31
+ @http.post("/api/v1/private/auth/mfa/verify",
32
+ "challengeToken" => challenge_token,
33
+ "code" => code)
34
+ end
35
+
36
+ # POST /api/v1/private/auth/register
37
+ # Create a new user account; sends email verification.
38
+ def register(username:, email:, password:)
39
+ @http.post("/api/v1/private/auth/register",
40
+ "username" => username,
41
+ "email" => email,
42
+ "password" => password)
43
+ end
44
+
45
+ # POST /api/v1/private/auth/verify-signup
46
+ # Confirm email address from signup link token.
47
+ # @param token [String]
48
+ def verify_signup(token:)
49
+ @http.post("/api/v1/private/auth/verify-signup", "token" => token)
50
+ end
51
+
52
+ # POST /api/v1/private/auth/resend-verification
53
+ # Re-send email verification message.
54
+ # @param email [String]
55
+ def resend_verification(email:)
56
+ @http.post("/api/v1/private/auth/resend-verification", "email" => email)
57
+ end
58
+
59
+ # GET /api/v1/private/auth/me
60
+ # Return current authenticated user profile.
61
+ def me
62
+ @http.get("/api/v1/private/auth/me")
63
+ end
64
+
65
+ # GET /api/v1/private/auth/check
66
+ # Lightweight session validity check; returns ok: true.
67
+ def check
68
+ @http.get("/api/v1/private/auth/check")
69
+ end
70
+
71
+ # POST /api/v1/private/auth/change-password
72
+ # Change password (current + new).
73
+ # @param current_password [String]
74
+ # @param new_password [String]
75
+ def change_password(current_password:, new_password:)
76
+ @http.post("/api/v1/private/auth/change-password",
77
+ "currentPassword" => current_password,
78
+ "newPassword" => new_password)
79
+ end
80
+
81
+ # POST /api/v1/private/auth/forgot-password
82
+ # Initiate password reset flow; sends email with reset token.
83
+ # @param email [String]
84
+ def forgot_password(email:)
85
+ @http.post("/api/v1/private/auth/forgot-password", "email" => email)
86
+ end
87
+
88
+ # POST /api/v1/private/auth/reset-password
89
+ # Complete password reset using token from email.
90
+ # @param token [String]
91
+ # @param new_password [String]
92
+ def reset_password(token:, new_password:)
93
+ @http.post("/api/v1/private/auth/reset-password",
94
+ "token" => token,
95
+ "newPassword" => new_password)
96
+ end
97
+
98
+ # POST /api/v1/private/auth/mobile-handoff
99
+ # Create a short-lived handoff token for mobile app deep-link auth.
100
+ def mobile_handoff
101
+ @http.post("/api/v1/private/auth/mobile-handoff")
102
+ end
103
+
104
+ # GET /api/v1/private/auth/permissions
105
+ # Return caller's permission flags (capabilities, tier, feature gates).
106
+ def permissions
107
+ @http.get("/api/v1/private/auth/permissions")
108
+ end
109
+
110
+ # POST /api/v1/private/auth/refresh
111
+ # Rotate session JWT (sliding expiry); returns new token.
112
+ def refresh
113
+ @http.post("/api/v1/private/auth/refresh")
114
+ end
115
+
116
+ # ── MFA ───────────────────────────────────────────────────────────────────
117
+
118
+ # GET /api/v1/private/mfa/status
119
+ # Return MFA enrollment status for the caller.
120
+ def mfa_status
121
+ @http.get("/api/v1/private/mfa/status")
122
+ end
123
+
124
+ # POST /api/v1/private/mfa/setup
125
+ # Initiate TOTP setup; returns QR/secret.
126
+ def mfa_setup
127
+ @http.post("/api/v1/private/mfa/setup")
128
+ end
129
+
130
+ # POST /api/v1/private/mfa/confirm
131
+ # Confirm TOTP setup with first valid code; activates MFA.
132
+ # @param code [String]
133
+ def mfa_confirm(code:)
134
+ @http.post("/api/v1/private/mfa/confirm", "code" => code)
135
+ end
136
+ end
137
+ end