hoja-cli 0.21.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. VERSION +1 -0
  2. google_workspace/__init__.py +19 -0
  3. google_workspace/client.py +253 -0
  4. google_workspace/config.py +39 -0
  5. google_workspace/errors.py +19 -0
  6. google_workspace/mcp_server.py +100 -0
  7. google_workspace/oauth.py +131 -0
  8. google_workspace/principal.py +83 -0
  9. google_workspace/py.typed +0 -0
  10. google_workspace/tools.py +64 -0
  11. google_workspace/writes.py +44 -0
  12. hoja/__init__.py +29 -0
  13. hoja/__main__.py +6 -0
  14. hoja/auth.py +42 -0
  15. hoja/cli.py +161 -0
  16. hoja/cli_state.py +55 -0
  17. hoja/client.py +268 -0
  18. hoja/commands/__init__.py +4 -0
  19. hoja/commands/auth_cmd.py +271 -0
  20. hoja/commands/comment.py +149 -0
  21. hoja/commands/cycle.py +75 -0
  22. hoja/commands/init.py +108 -0
  23. hoja/commands/issue.py +398 -0
  24. hoja/commands/label.py +163 -0
  25. hoja/commands/memory.py +240 -0
  26. hoja/commands/project.py +56 -0
  27. hoja/commands/raw.py +50 -0
  28. hoja/commands/team.py +102 -0
  29. hoja/commands/update.py +162 -0
  30. hoja/config.py +362 -0
  31. hoja/errors.py +107 -0
  32. hoja/filters.py +150 -0
  33. hoja/graphql/__init__.py +5 -0
  34. hoja/graphql/fragments.py +138 -0
  35. hoja/graphql/mutations.py +160 -0
  36. hoja/graphql/queries.py +245 -0
  37. hoja/mcp/__init__.py +27 -0
  38. hoja/mcp/content.py +151 -0
  39. hoja/mcp/prompts.py +298 -0
  40. hoja/mcp/resources.py +213 -0
  41. hoja/mcp/server.py +189 -0
  42. hoja/memory_board.py +370 -0
  43. hoja/models/__init__.py +37 -0
  44. hoja/models/base.py +64 -0
  45. hoja/models/cycle.py +32 -0
  46. hoja/models/enums.py +62 -0
  47. hoja/models/issue.py +99 -0
  48. hoja/models/label.py +17 -0
  49. hoja/models/project.py +60 -0
  50. hoja/models/team.py +31 -0
  51. hoja/models/user.py +32 -0
  52. hoja/models/workflow.py +65 -0
  53. hoja/output.py +410 -0
  54. hoja/skill_content/commands.md +222 -0
  55. hoja/skill_content/examples.md +193 -0
  56. hoja/skill_content/filters.md +101 -0
  57. hoja/skill_content/output-formats.md +92 -0
  58. hoja/skill_content/overview.md +123 -0
  59. hoja/skill_content/workflows.md +174 -0
  60. hoja_cli-0.21.4.dist-info/METADATA +279 -0
  61. hoja_cli-0.21.4.dist-info/RECORD +107 -0
  62. hoja_cli-0.21.4.dist-info/WHEEL +4 -0
  63. hoja_cli-0.21.4.dist-info/entry_points.txt +4 -0
  64. hoja_cli-0.21.4.dist-info/licenses/LICENSE +21 -0
  65. hoja_server/README.md +135 -0
  66. hoja_server/__init__.py +11 -0
  67. hoja_server/abac.py +116 -0
  68. hoja_server/agent_chat.py +280 -0
  69. hoja_server/agent_conversations.py +91 -0
  70. hoja_server/agent_durable.py +332 -0
  71. hoja_server/agent_prompt.py +117 -0
  72. hoja_server/agent_threads.py +96 -0
  73. hoja_server/agent_uploads.py +60 -0
  74. hoja_server/app.py +2189 -0
  75. hoja_server/cadence.py +231 -0
  76. hoja_server/cli.py +191 -0
  77. hoja_server/cloudflare_realtime.py +110 -0
  78. hoja_server/comment_policy.py +70 -0
  79. hoja_server/connector_actions.py +119 -0
  80. hoja_server/connectors_api.py +375 -0
  81. hoja_server/db.py +1816 -0
  82. hoja_server/denials.py +18 -0
  83. hoja_server/deployment.py +28 -0
  84. hoja_server/email_adapter.py +94 -0
  85. hoja_server/google_login.py +217 -0
  86. hoja_server/google_oidc.py +342 -0
  87. hoja_server/identity_transfer.py +210 -0
  88. hoja_server/mcp_oauth.py +623 -0
  89. hoja_server/mcp_tools.py +579 -0
  90. hoja_server/meeting_policy.py +179 -0
  91. hoja_server/meetings.py +1332 -0
  92. hoja_server/meetings_api.py +909 -0
  93. hoja_server/model_providers.py +205 -0
  94. hoja_server/realtime.py +690 -0
  95. hoja_server/resolvers.py +1281 -0
  96. hoja_server/schema.graphql +477 -0
  97. hoja_server/schema_sdl.py +8 -0
  98. hoja_server/secrets_box.py +39 -0
  99. hoja_server/signup_config.py +292 -0
  100. hoja_server/signup_gate.py +393 -0
  101. hoja_server/signup_policy.py +97 -0
  102. hoja_server/signup_store.py +577 -0
  103. hoja_server/store.py +2179 -0
  104. hoja_server/sync.py +249 -0
  105. hoja_server/tenant_context.py +131 -0
  106. hoja_server/turnstile.py +81 -0
  107. hoja_server/writer.py +1262 -0
@@ -0,0 +1,205 @@
1
+ """Admin-managed model providers for the agent. Keys are encrypted at rest and never returned."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import ipaddress
6
+ import os
7
+ import socket
8
+ from urllib.parse import urlsplit
9
+
10
+ from ariadne import MutationType, ObjectType, QueryType, gql
11
+ from sqlalchemy import and_, select
12
+
13
+ from hoja_server.db import model_provider, new_id, now_iso
14
+ from hoja_server.secrets_box import encrypt_secret
15
+
16
+ ALLOW_INSECURE_ENV = "HOJA_ALLOW_INSECURE_MODEL_URL"
17
+ MAX_BASE_URL_LENGTH = 2048
18
+
19
+ SDL = gql(
20
+ """
21
+ type ModelProvider {
22
+ id: String!
23
+ name: String!
24
+ provider: String!
25
+ modelId: String!
26
+ baseUrl: String
27
+ enabled: Boolean!
28
+ hasApiKey: Boolean!
29
+ createdAt: DateTime!
30
+ updatedAt: DateTime!
31
+ }
32
+
33
+ extend type Query {
34
+ modelProviders: [ModelProvider!]!
35
+ }
36
+
37
+ extend type Mutation {
38
+ modelProviderCreate(name: String!, provider: String!, modelId: String!, baseUrl: String, apiKey: String!): ModelProvider!
39
+ modelProviderUpdate(id: String!, name: String, modelId: String, baseUrl: String, apiKey: String, enabled: Boolean): ModelProvider!
40
+ modelProviderDelete(id: String!): Boolean!
41
+ }
42
+ """
43
+ )
44
+
45
+ query = QueryType()
46
+ mutation = MutationType()
47
+ model_provider_type = ObjectType("ModelProvider")
48
+
49
+
50
+ def _ctx(info):
51
+ return info.context["store"], info.context["org_id"], info.context["user_id"]
52
+
53
+
54
+ def _is_internal_address(address: str) -> bool:
55
+ ip = ipaddress.ip_address(address)
56
+ if isinstance(ip, ipaddress.IPv6Address) and ip.ipv4_mapped is not None:
57
+ ip = ip.ipv4_mapped
58
+ return (
59
+ ip.is_private
60
+ or ip.is_loopback
61
+ or ip.is_link_local
62
+ or ip.is_multicast
63
+ or ip.is_unspecified
64
+ or ip.is_reserved
65
+ )
66
+
67
+
68
+ def _is_loopback_host(host: str) -> bool:
69
+ if host.lower() == "localhost":
70
+ return True
71
+ try:
72
+ return ipaddress.ip_address(host).is_loopback
73
+ except ValueError:
74
+ return False
75
+
76
+
77
+ def validate_model_base_url(base_url: str | None) -> str | None:
78
+ """Reject model base URLs that could reach internal services (SSRF).
79
+
80
+ Requires https. With HOJA_ALLOW_INSECURE_MODEL_URL=1, http is allowed for
81
+ localhost and loopback/private/link-local/unique-local targets are permitted.
82
+ Hostnames are resolved at validation time; request-time code should re-check.
83
+ """
84
+ if base_url is None:
85
+ return None
86
+ if len(base_url) > MAX_BASE_URL_LENGTH:
87
+ raise ValueError("Model base URL is too long.")
88
+ allow_insecure = os.environ.get(ALLOW_INSECURE_ENV) == "1"
89
+ try:
90
+ parts = urlsplit(base_url)
91
+ host = parts.hostname
92
+ _ = parts.port # raises ValueError on malformed port
93
+ except ValueError as exc:
94
+ raise ValueError("Model base URL is malformed.") from exc
95
+ if not host or parts.username or parts.password:
96
+ raise ValueError("Model base URL must include a host and no credentials.")
97
+ if parts.scheme == "http":
98
+ if not (allow_insecure and _is_loopback_host(host)):
99
+ raise ValueError("Model base URL must use https.")
100
+ elif parts.scheme != "https":
101
+ raise ValueError("Model base URL must use https.")
102
+ if allow_insecure:
103
+ return base_url
104
+ if host.lower() == "localhost" or host.lower().endswith(".localhost"):
105
+ raise ValueError("Model base URL must not point to a local or private address.")
106
+ try:
107
+ addresses = [info[4][0] for info in socket.getaddrinfo(host, None)]
108
+ except socket.gaierror as exc:
109
+ raise ValueError("Model base URL host could not be resolved.") from exc
110
+ for address in addresses:
111
+ if _is_internal_address(address.split("%", 1)[0]):
112
+ raise ValueError("Model base URL must not point to a local or private address.")
113
+ return base_url
114
+
115
+
116
+
117
+
118
+ def _require_admin(store, org, uid):
119
+ actor = store.get_user(org, uid)
120
+ if not actor or not actor.get("admin"):
121
+ raise ValueError("Only workspace admins can manage model providers.")
122
+
123
+
124
+ def _serialize(row) -> dict:
125
+ return {
126
+ "id": row["id"],
127
+ "name": row["name"],
128
+ "provider": row["provider"],
129
+ "modelId": row["model_id"],
130
+ "baseUrl": row["base_url"],
131
+ "enabled": bool(row["enabled"]),
132
+ "hasApiKey": bool(row["encrypted_api_key"]),
133
+ "createdAt": row["created_at"],
134
+ "updatedAt": row["updated_at"],
135
+ }
136
+
137
+
138
+ def _rows(store, org):
139
+ with store.engine.connect() as conn:
140
+ return [dict(r._mapping) for r in conn.execute(
141
+ select(model_provider).where(model_provider.c.organization_id == org)
142
+ .order_by(model_provider.c.created_at))]
143
+
144
+
145
+ def _row(store, org, pid):
146
+ with store.engine.connect() as conn:
147
+ r = conn.execute(select(model_provider).where(
148
+ and_(model_provider.c.organization_id == org, model_provider.c.id == pid))).first()
149
+ return dict(r._mapping) if r else None
150
+
151
+
152
+ @query.field("modelProviders")
153
+ def r_model_providers(_, info):
154
+ store, org, uid = _ctx(info)
155
+ _require_admin(store, org, uid)
156
+ return [_serialize(r) for r in _rows(store, org)]
157
+
158
+
159
+ @mutation.field("modelProviderCreate")
160
+ def m_model_provider_create(_, info, name, provider, modelId, apiKey, baseUrl=None):
161
+ store, org, uid = _ctx(info)
162
+ _require_admin(store, org, uid)
163
+ baseUrl = validate_model_base_url(baseUrl)
164
+ now = now_iso()
165
+ values = {
166
+ "id": new_id(), "organization_id": org, "name": name, "provider": provider,
167
+ "model_id": modelId, "base_url": baseUrl, "encrypted_api_key": encrypt_secret(apiKey),
168
+ "enabled": True, "created_at": now, "updated_at": now,
169
+ }
170
+ with store.engine.begin() as conn:
171
+ conn.execute(model_provider.insert().values(**values))
172
+ return _serialize(values)
173
+
174
+
175
+ @mutation.field("modelProviderUpdate")
176
+ def m_model_provider_update(_, info, id, name=None, modelId=None, baseUrl=None, apiKey=None, enabled=None):
177
+ store, org, uid = _ctx(info)
178
+ _require_admin(store, org, uid)
179
+ current = _row(store, org, id)
180
+ if not current:
181
+ raise ValueError("Model provider not found.")
182
+ changes = {"updated_at": now_iso()}
183
+ if name is not None:
184
+ changes["name"] = name
185
+ if modelId is not None:
186
+ changes["model_id"] = modelId
187
+ if baseUrl is not None:
188
+ changes["base_url"] = validate_model_base_url(baseUrl)
189
+ if apiKey is not None:
190
+ changes["encrypted_api_key"] = encrypt_secret(apiKey)
191
+ if enabled is not None:
192
+ changes["enabled"] = enabled
193
+ with store.engine.begin() as conn:
194
+ conn.execute(model_provider.update().where(model_provider.c.id == id).values(**changes))
195
+ return _serialize(_row(store, org, id))
196
+
197
+
198
+ @mutation.field("modelProviderDelete")
199
+ def m_model_provider_delete(_, info, id):
200
+ store, org, uid = _ctx(info)
201
+ _require_admin(store, org, uid)
202
+ with store.engine.begin() as conn:
203
+ result = conn.execute(model_provider.delete().where(
204
+ and_(model_provider.c.organization_id == org, model_provider.c.id == id)))
205
+ return result.rowcount > 0