canyonos 0.2.4.dev1__tar.gz → 0.2.4.dev2__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.
Files changed (120) hide show
  1. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/PKG-INFO +1 -1
  2. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/api.py +87 -41
  3. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/auth.py +2 -2
  4. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/aws_provision.py +3 -2
  5. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/chat.py +34 -32
  6. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/cluster_provision.py +1 -1
  7. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/constants.py +1 -39
  8. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/curl.py +10 -9
  9. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/dashboard.compose.yml +4 -1
  10. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/dashboard.py +9 -18
  11. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/dashboard_stack.py +7 -3
  12. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/deploy.py +47 -116
  13. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/deployment.py +4 -12
  14. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/doctor.py +4 -13
  15. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/forwards.py +6 -6
  16. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/init.py +16 -78
  17. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/internal_ca.py +6 -8
  18. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/kubernetes_local.py +1 -2
  19. canyonos-0.2.4.dev2/canyonos/kubernetes_names.py +66 -0
  20. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/new_app_template/agents/workflow.py.tmpl +1 -1
  21. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/new_app_template/config/workflow_config.yaml +2 -2
  22. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/port_utils.py +8 -21
  23. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/ports.py +8 -11
  24. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/quickstart.py +5 -5
  25. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/records.py +7 -0
  26. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/rosa_provision.py +1 -1
  27. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/sdk/models.py +3 -4
  28. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/helloworld/helloworld/agents/workflow.py.tmpl +4 -3
  29. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/agents/workflow.py.tmpl +5 -4
  30. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/config/workflow_config.yaml +6 -3
  31. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/status.py +15 -22
  32. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/sync.py +3 -27
  33. canyonos-0.2.4.dev2/canyonos/targets/__init__.py +111 -0
  34. canyonos-0.2.4.dev2/canyonos/targets/docker.py +183 -0
  35. canyonos-0.2.4.dev1/canyonos/kubernetes_target.py → canyonos-0.2.4.dev2/canyonos/targets/kubernetes.py +136 -94
  36. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/test.py +45 -34
  37. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos.egg-info/PKG-INFO +1 -1
  38. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos.egg-info/SOURCES.txt +4 -1
  39. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/cli.py +17 -32
  40. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/pyproject.toml +1 -1
  41. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/README.md +0 -0
  42. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/__init__.py +0 -0
  43. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/aws_account.py +0 -0
  44. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/clean.py +0 -0
  45. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/config.py +0 -0
  46. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/contact.py +0 -0
  47. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/context.py +0 -0
  48. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/convert.py +0 -0
  49. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/dashboard_registration.py +0 -0
  50. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/dev_machine.py +0 -0
  51. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/docker_cmd.py +0 -0
  52. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/env.py +0 -0
  53. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/feedback.py +0 -0
  54. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/keychain.py +0 -0
  55. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/login.py +0 -0
  56. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/logout.py +0 -0
  57. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/logs.py +0 -0
  58. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/new_app.py +0 -0
  59. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/new_app_template/.env.example +0 -0
  60. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/new_app_template/.gitignore +0 -0
  61. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/new_app_template/agents/my_agent.py.tmpl +0 -0
  62. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/new_app_template/config/llms.yaml +0 -0
  63. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/new_app_template/config/policy.yaml +0 -0
  64. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/new_app_template/config/prompts.yaml +0 -0
  65. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/new_app_template/config/scaling.yaml +0 -0
  66. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/os_support/__init__.py +0 -0
  67. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/os_support/_posix.py +0 -0
  68. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/os_support/_windows.py +0 -0
  69. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/platform.py +0 -0
  70. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/provision.py +0 -0
  71. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/resources.py +0 -0
  72. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/sdk/__init__.py +0 -0
  73. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/selection.py +0 -0
  74. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/serve.py +0 -0
  75. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/session.py +0 -0
  76. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/helloworld/README.md +0 -0
  77. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/helloworld/helloworld/agents/hello_agent.py.tmpl +0 -0
  78. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/helloworld/helloworld/config/policy.yaml +0 -0
  79. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/helloworld/helloworld/config/test_query.txt +0 -0
  80. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/helloworld/helloworld/config/workflow_config.yaml +0 -0
  81. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/helloworld/workflow_group.yaml +0 -0
  82. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/.env +0 -0
  83. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/.env.example +0 -0
  84. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/agents/advisor_agent.py.tmpl +0 -0
  85. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/agents/intent_agent.py.tmpl +0 -0
  86. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/agents/metrics_agent.py.tmpl +0 -0
  87. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/agents/price_agent.py.tmpl +0 -0
  88. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/agents/risk_agent.py.tmpl +0 -0
  89. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/config/llms.yaml +0 -0
  90. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/config/policy.yaml +0 -0
  91. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/config/prompts.yaml +0 -0
  92. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/config/scaling.yaml +0 -0
  93. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/config/test_query.txt +0 -0
  94. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/workflow_group.yaml +0 -0
  95. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/stop.py +0 -0
  96. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/terraform/rosa/.terraform.lock.hcl +0 -0
  97. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/terraform/rosa/main.tf +0 -0
  98. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/terraform/rosa/outputs.tf +0 -0
  99. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/terraform/rosa/variables.tf +0 -0
  100. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/terraform/rosa/versions.tf +0 -0
  101. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/theme.py +0 -0
  102. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/tools.py +0 -0
  103. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/ui.py +0 -0
  104. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/upgrade.py +0 -0
  105. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/usage/__init__.py +0 -0
  106. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/usage/consent.py +0 -0
  107. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/usage/delivery.py +0 -0
  108. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/usage/outbox.py +0 -0
  109. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/usage/settings.py +0 -0
  110. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/validate.py +0 -0
  111. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/whoami.py +0 -0
  112. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos/workflow_group.yaml +0 -0
  113. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos.egg-info/dependency_links.txt +0 -0
  114. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos.egg-info/entry_points.txt +0 -0
  115. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos.egg-info/requires.txt +0 -0
  116. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/canyonos.egg-info/top_level.txt +0 -0
  117. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/setup.cfg +0 -0
  118. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/utils/__init__.py +0 -0
  119. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/utils/help_screen.py +0 -0
  120. {canyonos-0.2.4.dev1 → canyonos-0.2.4.dev2}/utils/tui.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: canyonos
3
- Version: 0.2.4.dev1
3
+ Version: 0.2.4.dev2
4
4
  Summary: Open-source platform for multi-agent apps: per-agent scaling, tracing and cost, in plain Python
5
5
  License-Expression: AGPL-3.0-only
6
6
  Project-URL: Homepage, https://canyonos.ai
@@ -8,11 +8,9 @@ read a workflow group don't each restate the same routes, payloads and failure m
8
8
  On Docker the API is the local stack's (`dashboard_stack`), on 127.0.0.1 at its host
9
9
  port, and every call sends this machine's deploy key, which opens every workflow
10
10
  group's routes here and is the only key that creates one; the API runs each workflow
11
- group's Global Controller container through Docker. On Kubernetes it is the cluster's,
12
- the one the operator's chart installs, reached through a port-forward with the user's
13
- kubectl login (`kubernetes_target.kubernetes_state`); it runs each workflow group as a
14
- CanyonProject. Both answer the same routes and shapes, and an error is
15
- `{error, message, findings?, warnings?}`.
11
+ group's Global Controller container through Docker. Another target's API is elsewhere,
12
+ at the URL and with the headers its `state()` gives (`canyonos.targets`). All answer the
13
+ same routes and shapes, and an error is `{error, message, findings?, warnings?}`.
16
14
  """
17
15
 
18
16
  import json
@@ -28,10 +26,9 @@ from canyonos.init import load_state
28
26
 
29
27
  REQUEST_TIMEOUT_SECONDS = 60
30
28
  STATUS_TIMEOUT_SECONDS = 5
31
- # Longer than the API's wait for the deploy to stop, which drains every replica first:
32
- # on Docker, and on Kubernetes, where it waits up to 15 minutes for the operator.
29
+ # Longer than this machine's API's wait for the deploy to stop, which drains every
30
+ # replica first.
33
31
  CLEAN_REQUEST_TIMEOUT_SECONDS = 270
34
- KUBERNETES_CLEAN_REQUEST_TIMEOUT_SECONDS = 905
35
32
  # Longer than one log read on a replica's machine, which may take up to 180s over SSH.
36
33
  LOGS_REQUEST_TIMEOUT_SECONDS = 200
37
34
  # The API stores a registration without reaching the workflow group's Redis.
@@ -45,10 +42,10 @@ PREFIX = "/v1/workflow-groups"
45
42
  # The CanyonOS API names its errors `workflow_groups.<code>`.
46
43
  ERROR_PREFIX = "workflow_groups."
47
44
  UNKNOWN_WORKFLOW_GROUP = "unknown_workflow_group"
48
- # What an older chart's API answers on Kubernetes: no route there (a release before
49
- # the /v1 routes), or the /v1 routes of an API that drives only Docker, without Docker
50
- # or the control key those releases asked for.
51
- OLDER_CHART_ERRORS = {
45
+ # What an older API elsewhere answers: no route there (a release before the /v1
46
+ # routes), or the /v1 routes of an API that drives only Docker, without Docker or the
47
+ # control key those releases asked for.
48
+ OLDER_API_ERRORS = {
52
49
  404: (None, "not_found"),
53
50
  503: ("docker.disabled",),
54
51
  401: ("auth.control_key_unset",),
@@ -111,8 +108,9 @@ def forget_api_url():
111
108
  _docker_url = None
112
109
 
113
110
 
114
- def _on_kubernetes(state):
115
- """Whether `state`'s workflow group is reached through the cluster's API."""
111
+ def _api_elsewhere(state):
112
+ """Whether `state`'s workflow group is reached through a CanyonOS API that is not
113
+ this machine's."""
116
114
  return bool(state and "api_url" in state)
117
115
 
118
116
 
@@ -126,9 +124,9 @@ def docker_api_headers():
126
124
 
127
125
  def _connection(state):
128
126
  """The base URL and headers a call about `state`'s workflow group goes to: the
129
- cluster's API on Kubernetes, else this machine's with its deploy key; this
127
+ API elsewhere that `state` names, else this machine's with its deploy key; this
130
128
  machine's when `state` is None."""
131
- if _on_kubernetes(state):
129
+ if _api_elsewhere(state):
132
130
  return state["api_url"], state["api_headers"]
133
131
  return docker_api_url(), docker_api_headers()
134
132
 
@@ -168,8 +166,8 @@ def error_detail(body, status):
168
166
 
169
167
  def _database_hint(state):
170
168
  """What to do about the API's database being down: on this machine, `canyonos
171
- serve` starts it again; "" on Kubernetes, where it is the cluster's."""
172
- if _on_kubernetes(state):
169
+ serve` starts it again; "" for an API elsewhere, whose database is not here."""
170
+ if _api_elsewhere(state):
173
171
  return ""
174
172
  return " If it stays down, run `canyonos serve`, which starts it again."
175
173
 
@@ -177,7 +175,7 @@ def _database_hint(state):
177
175
  def _next_step(state, code):
178
176
  """What to do about the API refusing a call with `code`, as a sentence to add to
179
177
  its message; "" when there is nothing to add."""
180
- if _on_kubernetes(state):
178
+ if _api_elsewhere(state):
181
179
  return ""
182
180
  if code in API_KEY_REFUSALS:
183
181
  # deploy, sync and stop restart an API on another deploy key themselves
@@ -208,13 +206,10 @@ def _open(state, method, path, action, data=None, headers=None, timeout=None):
208
206
  except urllib.error.HTTPError as e:
209
207
  detail = error_detail(e.read(), e.code)
210
208
  message = detail["error"]
211
- if _on_kubernetes(state) and detail["code"] in OLDER_CHART_ERRORS.get(
212
- e.code, ()
213
- ):
214
- # Imported here: kubernetes_target imports this module.
215
- from canyonos.kubernetes_target import UPGRADE_CHART
216
-
217
- message = f"{UPGRADE_CHART} (the cluster's API answered: {message})"
209
+ if _api_elsewhere(state) and detail["code"] in OLDER_API_ERRORS.get(e.code, ()):
210
+ message = (
211
+ f"{state['older_api_fix']} ({state['api_name']} answered: {message})"
212
+ )
218
213
  next_step = _next_step(state, detail["code"])
219
214
  if next_step:
220
215
  message = f"{message.rstrip('.')}.{next_step}"
@@ -234,7 +229,7 @@ def _open(state, method, path, action, data=None, headers=None, timeout=None):
234
229
  reason = getattr(e, "reason", e)
235
230
  hint = (
236
231
  ""
237
- if _on_kubernetes(state)
232
+ if _api_elsewhere(state)
238
233
  else "Run `canyonos deploy` or `canyonos serve` to start it."
239
234
  )
240
235
  raise ApiError(
@@ -303,7 +298,7 @@ def start_api_for(state):
303
298
  `state` records is on this machine, so a command that only reads can ask it. A
304
299
  running API is left as it is, and one that won't start is left to the request that
305
300
  follows to report."""
306
- if _on_kubernetes(state):
301
+ if _api_elsewhere(state):
307
302
  return
308
303
  # Imported here: serve imports this module.
309
304
  from canyonos.serve import start_api_if_down
@@ -381,8 +376,8 @@ def probe(state=None):
381
376
  raise ApiError(
382
377
  f"The CanyonOS API at {_connection(state)[0]} has no {PREFIX} routes: it "
383
378
  f"runs an older image than this CLI ({env.api_image}). In a checkout, build "
384
- "it with `bun run canyonos:dev` or point CANYONOS_API_IMAGE at an image "
385
- "built from it.",
379
+ "it with `bun run canyonos:dev` and retry with `cli-dev` in that shell, "
380
+ "or point CANYONOS_API_IMAGE at an image built from this checkout.",
386
381
  status=404,
387
382
  code=e.code,
388
383
  ) from None
@@ -444,8 +439,8 @@ def delete_workflow_group(state):
444
439
  "DELETE",
445
440
  _group_path(state),
446
441
  "Stop",
447
- timeout=KUBERNETES_CLEAN_REQUEST_TIMEOUT_SECONDS
448
- if _on_kubernetes(state)
442
+ timeout=state["clean_timeout"]
443
+ if _api_elsewhere(state)
449
444
  else CLEAN_REQUEST_TIMEOUT_SECONDS,
450
445
  )
451
446
 
@@ -468,13 +463,12 @@ def workflow_group_status(state):
468
463
  return None
469
464
  raise
470
465
  version = status.get("version")
471
- # A checkout's CLI runs whatever core image it is pointed at, as on Kubernetes.
466
+ # A checkout's CLI runs whatever core image it is pointed at.
472
467
  # A Global Controller that has not reported yet has no version to compare.
473
468
  if not env.is_development and version is not None and version != env.VERSION:
474
- # On Kubernetes it is the cluster's API's, the chart's, which a deploy keeps.
475
- if _on_kubernetes(state):
476
- runs = "The cluster's CanyonOS API runs"
477
- fix = f"Upgrade the CanyonOS operator chart to {env.VERSION}."
469
+ # Elsewhere it is that API's own release, which a deploy keeps.
470
+ if _api_elsewhere(state):
471
+ runs, fix = state["other_release"]
478
472
  else:
479
473
  runs = "This workflow group's Global Controller runs"
480
474
  fix = (
@@ -502,9 +496,8 @@ def deploy_status(state):
502
496
 
503
497
 
504
498
  def deployed_endpoint(state):
505
- """Return the endpoint record the running deploy published (`public_host`,
506
- `api_port`, and `routes`, each with its `agent`, `method`, `arguments` and `url`);
507
- raise ApiError when the deploy has none yet."""
499
+ """Return the running deploy's endpoint as the CanyonOS API reports it, reachable
500
+ from here (`reachable_endpoint`); raise ApiError when the deploy has none yet."""
508
501
  status = workflow_group_status(state) or {}
509
502
  endpoint = status.get("endpoint")
510
503
  if endpoint is None:
@@ -514,7 +507,60 @@ def deployed_endpoint(state):
514
507
  f"The running deploy has no endpoint yet.{reasons} Run `canyonos status` "
515
508
  "to see when it is up."
516
509
  )
517
- return endpoint
510
+ return reachable_endpoint(state, endpoint)
511
+
512
+
513
+ def reachable_endpoint(state, endpoint):
514
+ """`endpoint`, a workflow group's `routes` (each with its `workflow`,
515
+ `workflow_id`, `agent`, `method`, `arguments` and the `url` it is called at),
516
+ `webhooks` and the `status_url` a request's status is read under, as the CanyonOS
517
+ API reports them, with every URL reachable from here: on Kubernetes the ones that
518
+ name the cluster's in-cluster API Service point at this machine's forward to it."""
519
+ if not _api_elsewhere(state):
520
+ return endpoint
521
+ # Imported here: canyonos.targets.kubernetes imports this module.
522
+ from canyonos.targets.kubernetes import local_api_url
523
+
524
+ def reachable(url):
525
+ return local_api_url(url, state["api_url"])
526
+
527
+ return {
528
+ **endpoint,
529
+ "routes": [
530
+ {**route, "url": reachable(route["url"])} for route in endpoint["routes"]
531
+ ],
532
+ "webhooks": [
533
+ {**webhook, "url": reachable(webhook["url"])}
534
+ for webhook in endpoint["webhooks"]
535
+ ],
536
+ "status_url": reachable(endpoint["status_url"]),
537
+ }
538
+
539
+
540
+ def api_base(url):
541
+ """The base URL of the CanyonOS API in `url`, a route's URL or the `status_url` it
542
+ reports: `url` without its last path segment and its query."""
543
+ parts = urllib.parse.urlsplit(url)
544
+ return urllib.parse.urlunsplit(
545
+ (parts.scheme, parts.netloc, parts.path.rsplit("/", 1)[0], "", "")
546
+ )
547
+
548
+
549
+ def request_status_url(route_url, request_id):
550
+ """Where the status of request `request_id`, sent to the route at `route_url`, is
551
+ read."""
552
+ return f"{api_base(route_url)}/status/{request_id}"
553
+
554
+
555
+ def answers_url(route_url, workflow_group_id, request_id):
556
+ """Where an answer to a question of request `request_id`, sent to the route at
557
+ `route_url` of workflow group `workflow_group_id`, is posted; `?question=<id>`
558
+ names the question, else the oldest one waiting is answered."""
559
+ workflow_id = urllib.parse.urlsplit(route_url).path.rsplit("/", 1)[1]
560
+ return (
561
+ f"{api_base(route_url)}{PREFIX}/{_quoted(workflow_group_id)}/workflows/"
562
+ f"{workflow_id}/requests/{request_id}/answers"
563
+ )
518
564
 
519
565
 
520
566
  def test_queries(state):
@@ -26,8 +26,8 @@ API_KEY_FILE = "api_key"
26
26
  BEARER_PLACEHOLDER = '-H "Authorization: Bearer <your api key>"'
27
27
 
28
28
  NO_KEY_WARNING = (
29
- "This workflow group has no API key: its endpoint and its dashboard routes answer "
30
- "anyone who reaches them. Set one with --api-key <key>."
29
+ "This workflow group has no API key: anyone who reaches the CanyonOS API can call "
30
+ "its workflows and its dashboard routes. Set one with --api-key <key>."
31
31
  )
32
32
  KEY_SET = "This workflow group now uses an API key for secure connections."
33
33
  ONLY_THIS_GROUP = (
@@ -53,8 +53,9 @@ ROOT_VOLUME_GIB = 30
53
53
  SWAP_GIB = 2
54
54
  MACHINE_NAME = "canyonos-controller"
55
55
  ROLE_NAME = "canyonos-controller"
56
- # Ports you reach the machine on from your own address: SSH, then the API (8080, or
57
- # 8082 when 8080 is taken, since it skips the dashboard's) and the dashboard (8081).
56
+ # Ports you reach the machine on from your own address: SSH, then the CanyonOS API,
57
+ # which takes every workflow call (8080, or 8082 when 8080 is taken, since it skips the
58
+ # dashboard's), and the dashboard (8081).
58
59
  CALLER_PORTS = ((22, 22), (8080, 8082))
59
60
  CALLER_IP_URL = "https://checkip.amazonaws.com"
60
61
  REPO = "CanyonCodeCoreAI/canyonos"
@@ -30,7 +30,12 @@ from rich.text import Text
30
30
  from canyonos import deployment, records, ui
31
31
  from canyonos.auth import bearer_header, group_api_key
32
32
  from canyonos.deploy import is_workflow_id
33
- from canyonos.api import ApiError, deployed_endpoint, existing_deploy
33
+ from canyonos.api import (
34
+ ApiError,
35
+ deployed_endpoint,
36
+ existing_deploy,
37
+ request_status_url,
38
+ )
34
39
  from canyonos.os_support import is_terminal, write_private_file
35
40
  from canyonos.test import _error_body, _parse_answer, _query_route, _Run
36
41
  from canyonos.theme import GREEN, WHITE
@@ -66,11 +71,8 @@ def _from_curl(text):
66
71
  words = shlex.split(text.replace("\\\n", " "))
67
72
  url = next(word for word in words if word.startswith(("http://", "https://")))
68
73
  body = json.loads(words[words.index("-d") + 1])
69
- # A workflow's route is `/<workflow_id>`, a UUID, or `/<workflow>/<agent>/<method>`,
70
- # and its body a JSON object.
71
- path = urlsplit(url).path.strip("/").split("/")
72
- route = len(path) >= 3 or (len(path) == 1 and is_workflow_id(path[0]))
73
- if not route or not isinstance(body, dict):
74
+ # A workflow is called at `/<workflow_id>`, a UUID, with a JSON object.
75
+ if not is_workflow_id(_workflow_id(url)) or not isinstance(body, dict):
74
76
  raise ValueError("not a workflow's curl command")
75
77
  return {
76
78
  "url": url,
@@ -95,24 +97,26 @@ def _deployed_workflows():
95
97
  ]
96
98
 
97
99
 
98
- def _workflow_group_at(url):
99
- """The workflow group recorded here whose endpoint was last on `url`'s port, for a
100
- workflow added with /add, or None."""
101
- port = urlsplit(url).port
100
+ def _workflow_id(url):
101
+ """The workflow_id a workflow's `url`, `<CanyonOS API>/<workflow_id>`, calls."""
102
+ return urlsplit(url).path.rsplit("/", 1)[-1]
103
+
104
+
105
+ def _workflow_group_of(workflow):
106
+ """The name of the workflow group recorded here that `workflow` belongs to, the one
107
+ whose record lists its workflow_id for a workflow added with /add, or None."""
108
+ if workflow.get("workflow_group"):
109
+ return workflow["workflow_group"]
110
+ workflow_id = _workflow_id(workflow["url"])
102
111
  for name in records.names():
103
- try:
104
- with open(deployment.state_path(name), encoding="utf-8") as f:
105
- if json.load(f).get("api_port") == port:
106
- return name
107
- except (OSError, ValueError, AttributeError):
108
- continue
112
+ if any(w["workflow_id"] == workflow_id for w in records.workflows(name)):
113
+ return name
109
114
  return None
110
115
 
111
116
 
112
- def _signer(workflow):
113
- """What gives the header each call to `workflow` sends: the API key of the workflow
114
- group it belongs to, none when it belongs to none recorded here."""
115
- name = workflow.get("workflow_group") or _workflow_group_at(workflow["url"])
117
+ def _signer(name):
118
+ """What gives the header each call to a workflow of workflow group `name` sends: its
119
+ API key, none when `name` is None."""
116
120
  return lambda: bearer_header(group_api_key(name) if name else None)
117
121
 
118
122
 
@@ -244,8 +248,7 @@ def _show_recent(workflow, sign):
244
248
  picked = tui.select_menu(options, "Show the result of")
245
249
  if picked is None:
246
250
  return
247
- parts = urlsplit(workflow["url"])
248
- url = f"{parts.scheme}://{parts.netloc}/status/{picked['id']}"
251
+ url = request_status_url(workflow["url"], picked["id"])
249
252
  try:
250
253
  request = urllib.request.Request(url, headers=sign())
251
254
  with urllib.request.urlopen(request, timeout=10) as response:
@@ -268,28 +271,27 @@ def _show_recent(workflow, sign):
268
271
  ui.say(f"Request {picked['id']} is {status['status'].replace('_', ' ')}.")
269
272
 
270
273
 
271
- def _call(workflow, values, sign):
272
- """Call `workflow` with `values`, typed in its argument boxes in order, each request
273
- with the header `sign` returns, answer the questions it asks, and show its result
274
- or error, then its request ID and how long it took."""
274
+ def _call(workflow, values, workflow_group):
275
+ """Call `workflow` of `workflow_group`, recorded here or None, with `values`, typed
276
+ in its argument boxes in order, each request with that workflow group's API key,
277
+ answer the questions it asks, and show its result or error, then its request ID and
278
+ how long it took."""
275
279
  arguments = workflow["arguments"].items()
276
280
  body = {
277
281
  name: _parse_answer(value, kind)
278
282
  for (name, kind), value in zip(arguments, values)
279
283
  }
280
- parts = urlsplit(workflow["url"])
281
- base = f"{parts.scheme}://{parts.netloc}"
282
284
  run = _Run(None)
283
285
  started = time.monotonic()
284
286
  try:
285
287
  result = _query_route(
286
288
  # No time limit: Ctrl-C stops waiting instead.
287
289
  run,
288
- base,
289
290
  workflow["url"],
291
+ records.workflow_group_id(workflow_group) if workflow_group else None,
290
292
  body,
291
293
  math.inf,
292
- sign,
294
+ _signer(workflow_group),
293
295
  _answer_in_boxes,
294
296
  )
295
297
  except RuntimeError as e:
@@ -374,10 +376,10 @@ def run_chat():
374
376
  elif workflow is None:
375
377
  error = "Add a workflow first: /add <its curl command>"
376
378
  elif values[0] == "/recent":
377
- _show_recent(workflow, _signer(workflow))
379
+ _show_recent(workflow, _signer(_workflow_group_of(workflow)))
378
380
  else:
379
381
  sent.append(values)
380
- _call(workflow, values, _signer(workflow))
382
+ _call(workflow, values, _workflow_group_of(workflow))
381
383
  finally:
382
384
  # Give the whole screen back to the shell, with its prompt under the boxes.
383
385
  sys.stderr.write(f"\x1b[r\x1b[{shutil.get_terminal_size().lines};1H\n")
@@ -41,7 +41,7 @@ from pathlib import Path
41
41
  from types import SimpleNamespace
42
42
 
43
43
  from canyonos import env, tools, ui
44
- from canyonos.kubernetes_target import kubectl
44
+ from canyonos.targets.kubernetes import kubectl
45
45
  from canyonos.os_support import make_private_dir, write_private_file
46
46
  from canyonos.provision import CREATED_BY, PROVISION_ID_TAG, Cancelled, pick
47
47
 
@@ -16,10 +16,9 @@ from ruamel.yaml.error import MarkedYAMLError
16
16
 
17
17
  from canyonos.port_utils import is_port_free
18
18
 
19
- DEFAULT_API_PORT = 8080
20
19
  DEFAULT_REDIS_PORT = 6379
21
20
  DEFAULT_DASHBOARD_PORT = 8081
22
- DEFAULT_DASHBOARD_API_PORT = 3000
21
+ DEFAULT_DASHBOARD_API_PORT = 8080
23
22
 
24
23
  _EC2_TOKEN_URL = "http://169.254.169.254/latest/api/token"
25
24
  _EC2_PUBLIC_IP_URL = "http://169.254.169.254/latest/meta-data/public-ipv4"
@@ -153,43 +152,6 @@ def _ec2_metadata(url, timeout):
153
152
  return _metadata_cache[url]
154
153
 
155
154
 
156
- def endpoint_api_port(config_path):
157
- """Return the endpoint's `api_port` from the config, or None when the config sets
158
- none, or sets something other than a port number, which the deploy's schema check
159
- then reports. Raises when the config is not valid YAML."""
160
- endpoint = (load_yaml(config_path, yaml.safe_load) or {}).get("endpoint")
161
- if not isinstance(endpoint, dict):
162
- return None
163
- port = endpoint.get("api_port")
164
- return port if isinstance(port, int) and not isinstance(port, bool) else None
165
-
166
-
167
- # What an endpoint answers before the Global Controller has published the API key
168
- # hash (`auth.not_ready`): up, but refusing every request.
169
- NOT_READY_STATUS = 503
170
-
171
-
172
- def endpoint_answers_at(url, timeout):
173
- """True when the endpoint at `url` is up and taking requests: any HTTP answer to
174
- the probe, which sends no key, counts (a 401 is the endpoint checking its API key,
175
- and the 404 of its unknown request id comes with no key set), except the 503 it
176
- answers while it waits for the API key hash."""
177
- try:
178
- urllib.request.urlopen(
179
- f"{url.rstrip('/')}/status/canyonos-test-probe", timeout=timeout
180
- )
181
- except urllib.error.HTTPError as error:
182
- return error.code != NOT_READY_STATUS
183
- except OSError:
184
- return False
185
- return True
186
-
187
-
188
- def endpoint_answers(api_port):
189
- """`endpoint_answers_at` for the endpoint on this machine."""
190
- return endpoint_answers_at(f"http://127.0.0.1:{api_port}", timeout=2)
191
-
192
-
193
155
  def local_redis_port(config_path):
194
156
  """Return this machine's Redis port from the config's `redis.port`, or None when it
195
157
  sets none, or sets something other than a port number."""
@@ -3,9 +3,10 @@
3
3
 
4
4
  """
5
5
  Logic for `canyonos curl`: POST one JSON body to a workflow of the running workflow group,
6
- this folder's or the selected one, with that workflow group's API key, and print what
7
- the endpoint answers. It sends that one request and waits for nothing else: the answer to
8
- a queued request is its `request_id`, whose result `/status/<request_id>` gives.
6
+ this folder's or the selected one, through the CanyonOS API with that workflow group's
7
+ API key, and print what the API answers. It sends that one request and waits for nothing
8
+ else: the answer to a queued request is its `request_id`, whose result
9
+ `/status/<request_id>` gives.
9
10
  """
10
11
 
11
12
  import json
@@ -35,8 +36,8 @@ def _named(routes, wanted):
35
36
  """The routes `wanted` names: its URL, `<workflow>/<agent>/<method>`,
36
37
  `<agent>/<method>` or `<method>`."""
37
38
  if wanted.startswith(("http://", "https://")):
38
- path = urlsplit(wanted).path
39
- return [r for r in routes if urlsplit(r["url"]).path == path]
39
+ place = urlsplit(wanted)[2:4]
40
+ return [r for r in routes if urlsplit(r["url"])[2:4] == place]
40
41
  parts = wanted.strip("/").split("/")
41
42
  return [r for r in routes if _route_path(r).split("/")[-len(parts) :] == parts]
42
43
 
@@ -78,7 +79,7 @@ def _pick_route(routes, wanted):
78
79
 
79
80
  def _send(url, body, key):
80
81
  """POST `body` to `url` with `key`, if any, and return the status code and the
81
- body the endpoint answered with."""
82
+ body the API answered with."""
82
83
  request = urllib.request.Request(
83
84
  url,
84
85
  data=json.dumps(body).encode(),
@@ -95,7 +96,7 @@ def _send(url, body, key):
95
96
 
96
97
 
97
98
  def _show(text):
98
- """Print the endpoint's answer on stdout, indented when it is JSON."""
99
+ """Print the API's answer on stdout, indented when it is JSON."""
99
100
  try:
100
101
  text = json.dumps(json.loads(text), indent=2)
101
102
  except ValueError:
@@ -107,7 +108,7 @@ def run_curl(body_text, route=None, show_command=False):
107
108
  """Run `canyonos curl`: POST the JSON `body_text` to a route of the running
108
109
  workflow group, by default its only one, and print the answer; with `show_command`,
109
110
  print the equivalent `curl` instead, the key left out. Returns the exit code: 0
110
- when the endpoint answers 2xx."""
111
+ when the API answers 2xx."""
111
112
  try:
112
113
  body = json.loads(body_text)
113
114
  except ValueError as e:
@@ -139,5 +140,5 @@ def run_curl(body_text, route=None, show_command=False):
139
140
  _show(answer)
140
141
  if 200 <= status < 300:
141
142
  return 0
142
- ui.fail(f"The endpoint answered HTTP {status}.")
143
+ ui.fail(f"The CanyonOS API answered HTTP {status}.")
143
144
  return 1
@@ -42,9 +42,12 @@ services:
42
42
  # route doesn't reach ports bound to loopback only, so a 127.0.0.1 bind
43
43
  # here silently black-holed every OTLP span export.
44
44
  ports:
45
- - "${CANYONOS_API_PORT:-3000}:3000"
45
+ - "${CANYONOS_API_PORT:-8080}:8080"
46
46
  environment:
47
47
  DATABASE_URL: postgresql://canyonos:canyonos@db:5432/canyonos
48
+ # The base of the workflow, status and webhook URLs the API reports: where callers
49
+ # reach it on this machine.
50
+ API_URL: http://${CANYONOS_PUBLIC_HOST:-127.0.0.1}:${CANYONOS_API_PORT:-8080}
48
51
  REDIS_PASSWORD_ENCRYPTION_KEY: ${CANYONOS_REDIS_PASSWORD_ENCRYPTION_KEY}
49
52
  # The SHA-256 of this machine's deploy key, which the CLI makes once and sends
50
53
  # on every `/v1/workflow-groups` call; only it creates a workflow group. Each
@@ -17,8 +17,7 @@ from urllib.parse import quote
17
17
 
18
18
  from canyonos import ui
19
19
  from canyonos.auth import group_api_key
20
- from canyonos.dashboard_stack import dashboard_url, running_api_port, running_web_port
21
- from canyonos.deployment import configured_target
20
+ from canyonos.targets import target
22
21
  from canyonos.os_support import is_terminal
23
22
 
24
23
 
@@ -52,22 +51,14 @@ def run_open_dashboard():
52
51
  the API key of the workflow group this command acts on, or show its URL and how to
53
52
  sign in when it has no key. On Kubernetes it is the cluster's dashboard, forwarded
54
53
  to this machine as `canyonos serve` does. Returns False when no dashboard runs."""
55
- if configured_target() == "kubernetes":
56
- # Imported here: Docker's dashboard needs none of the cluster's modules.
57
- from canyonos.kubernetes_target import _open_dashboard
58
-
59
- url, api_url = f"http://127.0.0.1:{_open_dashboard()}", None
60
- else:
61
- port = running_web_port()
62
- if port is None:
63
- ui.fail(
64
- "The dashboard is not running. Start it with `canyonos serve`, or deploy "
65
- "with `canyonos deploy`."
66
- )
67
- return False
68
- url = dashboard_url(port)
69
- api_port = running_api_port()
70
- api_url = f"http://127.0.0.1:{api_port}" if api_port else None
54
+ opened = target().open_dashboard()
55
+ if opened is None:
56
+ ui.fail(
57
+ "The dashboard is not running. Start it with `canyonos serve`, or deploy "
58
+ "with `canyonos deploy`."
59
+ )
60
+ return False
61
+ url, api_url = opened
71
62
  key = group_api_key()
72
63
  if not _requires_key(api_url):
73
64
  with ui.to_stderr():
@@ -61,10 +61,11 @@ DEPLOY_KEY_FILE = "deploy_key"
61
61
  DEPLOY_KEY_HASH_ENV = "CANYONOS_DEPLOY_KEY_HASH"
62
62
  # The services the dashboard publishes on the host, each with the port it listens on
63
63
  # in its container, the host port it starts from, and its name in a warning: the web
64
- # app (none, as the CLI prints its address itself) and the API, which the CLI reaches.
64
+ # app (none, as the CLI prints its address itself) and the CanyonOS API, which the CLI
65
+ # and every workflow call reach.
65
66
  SERVICE_PORTS = {
66
67
  "web": (8080, DEFAULT_DASHBOARD_PORT, None),
67
- "api": (3000, DEFAULT_DASHBOARD_API_PORT, "the dashboard's API"),
68
+ "api": (8080, DEFAULT_DASHBOARD_API_PORT, "the CanyonOS API"),
68
69
  }
69
70
  # The services a workflow group's containers reach by container name on its network.
70
71
  NETWORK_SERVICES = ("api", "db")
@@ -521,6 +522,9 @@ def _prepare(stack: DashboardStack) -> tuple[dict[str, str], str]:
521
522
  f"CANYONOS_{service.upper()}_PORT": str(port)
522
523
  for service, port in stack.host_ports.items()
523
524
  },
525
+ # Where callers reach the API, which it reports workflow URLs under: this
526
+ # machine's public IP on EC2, else loopback, as the dashboard's address.
527
+ "CANYONOS_PUBLIC_HOST": public_ip() or "127.0.0.1",
524
528
  DEPLOY_KEY_HASH_ENV: hash_api_key(deploy_key()),
525
529
  # The API runs each workflow group's Global Controller through the same
526
530
  # engine the CLI created that container on.
@@ -637,7 +641,7 @@ def _missing_message(missing: list[tuple[str, str]], failure: str) -> str:
637
641
  variables = " and ".join(variable for _image, variable in missing)
638
642
  fix = (
639
643
  f"Point {variables} at an image this machine has, or build this "
640
- "checkout's with `bun run canyonos:dev`."
644
+ "checkout's with `bun run canyonos:dev` and retry with `cli-dev` in that shell."
641
645
  )
642
646
  verb = "are" if len(missing) > 1 else "is"
643
647
  return f"{images} {verb} not on this machine and could not be pulled ({failure}). {fix}"