pal-found-cli 0.1.2__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 (89) hide show
  1. pal_found_cli/__init__.py +1 -0
  2. pal_found_cli/_version.py +24 -0
  3. pal_found_cli/admin/__init__.py +2 -0
  4. pal_found_cli/admin/scripts/__init__.py +2 -0
  5. pal_found_cli/admin/scripts/pal_found_admin_cli.py +600 -0
  6. pal_found_cli/aip_agents/__init__.py +1 -0
  7. pal_found_cli/aip_agents/metadata-allow-list.md +20 -0
  8. pal_found_cli/aip_agents/scripts/__init__.py +1 -0
  9. pal_found_cli/aip_agents/scripts/pal_found_aip_agents_cli.py +704 -0
  10. pal_found_cli/audit/__init__.py +1 -0
  11. pal_found_cli/audit/metadata-allow-list.md +4 -0
  12. pal_found_cli/audit/scripts/__init__.py +1 -0
  13. pal_found_cli/audit/scripts/pal_found_audit_cli.py +387 -0
  14. pal_found_cli/checkpoints/__init__.py +9 -0
  15. pal_found_cli/checkpoints/metadata-allow-list.md +7 -0
  16. pal_found_cli/checkpoints/scripts/__init__.py +1 -0
  17. pal_found_cli/checkpoints/scripts/pal_found_checkpoints_cli.py +527 -0
  18. pal_found_cli/common/__init__.py +56 -0
  19. pal_found_cli/common/access_control_guard.py +591 -0
  20. pal_found_cli/common/async_client_factory.py +161 -0
  21. pal_found_cli/common/auth_provider.py +82 -0
  22. pal_found_cli/common/binary_download_handler.py +288 -0
  23. pal_found_cli/common/config_loader.py +388 -0
  24. pal_found_cli/common/error_serializer.py +412 -0
  25. pal_found_cli/common/log_setup.py +241 -0
  26. pal_found_cli/common/metadata-allow-list.md +169 -0
  27. pal_found_cli/common/output_formatter.py +267 -0
  28. pal_found_cli/common/pagination_helper.py +212 -0
  29. pal_found_cli/common/retry.py +617 -0
  30. pal_found_cli/common/sdk_error_utils.py +112 -0
  31. pal_found_cli/common/session_manager.py +461 -0
  32. pal_found_cli/common/tracing_provider.py +107 -0
  33. pal_found_cli/connectivity/__init__.py +9 -0
  34. pal_found_cli/connectivity/metadata-allow-list.md +24 -0
  35. pal_found_cli/connectivity/scripts/__init__.py +1 -0
  36. pal_found_cli/connectivity/scripts/pal_found_connectivity_cli.py +720 -0
  37. pal_found_cli/data_health/__init__.py +9 -0
  38. pal_found_cli/data_health/metadata-allow-list.md +10 -0
  39. pal_found_cli/data_health/scripts/__init__.py +1 -0
  40. pal_found_cli/data_health/scripts/pal_found_data_health_cli.py +458 -0
  41. pal_found_cli/datasets/__init__.py +1 -0
  42. pal_found_cli/datasets/scripts/__init__.py +1 -0
  43. pal_found_cli/datasets/scripts/pal_found_datasets_cli.py +732 -0
  44. pal_found_cli/filesystem/__init__.py +2 -0
  45. pal_found_cli/filesystem/scripts/__init__.py +2 -0
  46. pal_found_cli/filesystem/scripts/pal_found_filesystem_cli.py +659 -0
  47. pal_found_cli/functions/__init__.py +2 -0
  48. pal_found_cli/functions/scripts/__init__.py +2 -0
  49. pal_found_cli/functions/scripts/pal_found_functions_cli.py +389 -0
  50. pal_found_cli/language_models/__init__.py +1 -0
  51. pal_found_cli/language_models/metadata-allow-list.md +6 -0
  52. pal_found_cli/language_models/scripts/__init__.py +1 -0
  53. pal_found_cli/language_models/scripts/pal_found_language_models_cli.py +342 -0
  54. pal_found_cli/media_sets/__init__.py +9 -0
  55. pal_found_cli/media_sets/metadata-allow-list.md +23 -0
  56. pal_found_cli/media_sets/scripts/__init__.py +1 -0
  57. pal_found_cli/media_sets/scripts/pal_found_media_sets_cli.py +642 -0
  58. pal_found_cli/models/__init__.py +5 -0
  59. pal_found_cli/models/metadata-allow-list.md +27 -0
  60. pal_found_cli/models/scripts/__init__.py +1 -0
  61. pal_found_cli/models/scripts/pal_found_models_cli.py +714 -0
  62. pal_found_cli/ontologies/__init__.py +1 -0
  63. pal_found_cli/ontologies/scripts/__init__.py +1 -0
  64. pal_found_cli/ontologies/scripts/pal_found_ontologies_cli.py +1225 -0
  65. pal_found_cli/orchestration/__init__.py +9 -0
  66. pal_found_cli/orchestration/metadata-allow-list.md +24 -0
  67. pal_found_cli/orchestration/scripts/__init__.py +1 -0
  68. pal_found_cli/orchestration/scripts/pal_found_orchestration_cli.py +640 -0
  69. pal_found_cli/sql_queries/__init__.py +9 -0
  70. pal_found_cli/sql_queries/metadata-allow-list.md +9 -0
  71. pal_found_cli/sql_queries/scripts/__init__.py +1 -0
  72. pal_found_cli/sql_queries/scripts/pal_found_sql_queries_cli.py +514 -0
  73. pal_found_cli/streams/__init__.py +9 -0
  74. pal_found_cli/streams/metadata-allow-list.md +19 -0
  75. pal_found_cli/streams/scripts/__init__.py +1 -0
  76. pal_found_cli/streams/scripts/pal_found_streams_cli.py +615 -0
  77. pal_found_cli/third_party_applications/__init__.py +9 -0
  78. pal_found_cli/third_party_applications/metadata-allow-list.md +13 -0
  79. pal_found_cli/third_party_applications/scripts/__init__.py +1 -0
  80. pal_found_cli/third_party_applications/scripts/pal_found_third_party_applications_cli.py +547 -0
  81. pal_found_cli/widgets/__init__.py +9 -0
  82. pal_found_cli/widgets/metadata-allow-list.md +12 -0
  83. pal_found_cli/widgets/scripts/__init__.py +1 -0
  84. pal_found_cli/widgets/scripts/pal_found_widgets_cli.py +571 -0
  85. pal_found_cli-0.1.2.dist-info/METADATA +74 -0
  86. pal_found_cli-0.1.2.dist-info/RECORD +89 -0
  87. pal_found_cli-0.1.2.dist-info/WHEEL +5 -0
  88. pal_found_cli-0.1.2.dist-info/entry_points.txt +19 -0
  89. pal_found_cli-0.1.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,342 @@
1
+ #!/usr/bin/env python3
2
+ """Foundry Language Models CLI for messages and embeddings inference."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import asyncio
8
+ import json
9
+ import logging
10
+ import sys
11
+ from pathlib import Path
12
+ from typing import Any, NoReturn
13
+
14
+ from pal_found_cli.common.access_control_guard import AccessControlGuard
15
+ from pal_found_cli.common.async_client_factory import AsyncClientFactory
16
+ from pal_found_cli.common.config_loader import ConfigLoader, ConfigurationError
17
+ from pal_found_cli.common.error_serializer import (
18
+ EXIT_ACCESS_CONTROL,
19
+ EXIT_AUTH,
20
+ EXIT_CONFIGURATION,
21
+ EXIT_NOT_FOUND,
22
+ EXIT_PERMISSION_DENIED,
23
+ EXIT_RATE_LIMIT,
24
+ EXIT_SERVER_ERROR,
25
+ EXIT_SUCCESS,
26
+ EXIT_TIMEOUT,
27
+ EXIT_USER_INPUT,
28
+ ErrorSerializer,
29
+ )
30
+ from pal_found_cli.common.log_setup import LogSetup
31
+ from pal_found_cli.common.output_formatter import OutputFormatter
32
+ from pal_found_cli.common.retry import RetryHandler
33
+ from pal_found_cli.common.sdk_error_utils import sdk_exception_exit_code, sdk_http_status
34
+
35
+ logger = logging.getLogger(__name__)
36
+ OperationSpec = dict[str, Any]
37
+ _METADATA_ALLOWLIST_PATH = Path(__file__).resolve().parents[1] / "metadata-allow-list.md"
38
+
39
+
40
+ class _ArgumentParser(argparse.ArgumentParser):
41
+ """Raise parser failures into the structured error boundary."""
42
+
43
+ def error(self, message: str) -> NoReturn:
44
+ raise CLIInputError("Invalid command input")
45
+
46
+
47
+ class CLIInputError(ValueError):
48
+ """A locally generated input error whose message contains no supplied value."""
49
+
50
+ exit_code = EXIT_USER_INPUT
51
+
52
+
53
+ OP_SPECS: tuple[OperationSpec, ...] = (
54
+ {
55
+ "resource": "anthropic_model",
56
+ "operation": "messages",
57
+ "client_path": ("AnthropicModel",),
58
+ "method": "messages",
59
+ "positional": ("model_id",),
60
+ "required": ("max_tokens", "messages"),
61
+ "optional": (
62
+ "output_config",
63
+ "stop_sequences",
64
+ "system",
65
+ "temperature",
66
+ "thinking",
67
+ "tool_choice",
68
+ "tools",
69
+ "top_k",
70
+ "top_p",
71
+ ),
72
+ "object_json": frozenset({"output_config", "thinking", "tool_choice"}),
73
+ "object_list_json": frozenset({"messages", "system", "tools"}),
74
+ "string_list_json": frozenset({"stop_sequences"}),
75
+ },
76
+ {
77
+ "resource": "open_ai_model",
78
+ "operation": "embeddings",
79
+ "client_path": ("OpenAiModel",),
80
+ "method": "embeddings",
81
+ "positional": ("model_id",),
82
+ "required": ("input",),
83
+ "optional": ("dimensions", "encoding_format"),
84
+ "object_json": frozenset(),
85
+ "object_list_json": frozenset(),
86
+ "string_list_json": frozenset({"input"}),
87
+ },
88
+ )
89
+
90
+ OPERATION_BY_RESOURCE = {
91
+ spec["resource"]: {spec["operation"]: spec} for spec in OP_SPECS
92
+ }
93
+
94
+
95
+ def _common_parser() -> _ArgumentParser:
96
+ """Create shared operation options."""
97
+ parser = _ArgumentParser(add_help=False)
98
+ parser.add_argument("--timeout", type=int, default=None)
99
+ parser.add_argument("--format", choices=("json", "toon", "auto"), default="auto")
100
+ parser.add_argument("--pretty", action="store_true")
101
+ return parser
102
+
103
+
104
+ def build_parser() -> argparse.ArgumentParser:
105
+ """Build the two-operation Language Models parser."""
106
+ parser = _ArgumentParser(
107
+ prog="pal-found-language-models",
108
+ description="Foundry Language Models CLI - messages and embeddings",
109
+ )
110
+ resources = parser.add_subparsers(dest="resource")
111
+ anthropic = resources.add_parser("anthropic-model")
112
+ anthropic_ops = anthropic.add_subparsers(dest="operation")
113
+ messages = anthropic_ops.add_parser("messages", parents=[_common_parser()])
114
+ messages.add_argument("model_id")
115
+ messages.add_argument("--max-tokens", required=True, type=int)
116
+ messages.add_argument("--messages-json", required=True, dest="messages")
117
+ messages.add_argument("--output-config-json", dest="output_config")
118
+ messages.add_argument("--stop-sequences-json", dest="stop_sequences")
119
+ messages.add_argument("--system-json", dest="system")
120
+ messages.add_argument("--temperature", type=float)
121
+ messages.add_argument("--thinking-json", dest="thinking")
122
+ messages.add_argument("--tool-choice-json", dest="tool_choice")
123
+ messages.add_argument("--tools-json", dest="tools")
124
+ messages.add_argument("--top-k", type=int)
125
+ messages.add_argument("--top-p", type=float)
126
+
127
+ open_ai = resources.add_parser("open-ai-model")
128
+ open_ai_ops = open_ai.add_subparsers(dest="operation")
129
+ embeddings = open_ai_ops.add_parser("embeddings", parents=[_common_parser()])
130
+ embeddings.add_argument("model_id")
131
+ embeddings.add_argument("--input-json", required=True, dest="input")
132
+ embeddings.add_argument("--dimensions", type=int)
133
+ embeddings.add_argument("--encoding-format", choices=("FLOAT", "BASE64"))
134
+ return parser
135
+
136
+
137
+ def _spec_for(resource: str, operation: str) -> OperationSpec:
138
+ """Return one catalog specification."""
139
+ try:
140
+ return OPERATION_BY_RESOURCE[resource][operation]
141
+ except KeyError as exc:
142
+ raise CLIInputError(f"Unknown operation: {resource}.{operation}") from exc
143
+
144
+
145
+ def _required_text(value: Any, *, field: str) -> str:
146
+ """Validate a non-empty string while preserving its original value."""
147
+ if not isinstance(value, str) or not value.strip():
148
+ raise CLIInputError(f"{field} must not be empty")
149
+ return value
150
+
151
+
152
+ def _decode_json(value: str, *, field: str) -> Any:
153
+ try:
154
+ return json.loads(value)
155
+ except json.JSONDecodeError as exc:
156
+ raise CLIInputError(f"{field} must contain valid JSON") from exc
157
+
158
+
159
+ def _parse_json_object(value: str, *, field: str) -> dict[str, Any]:
160
+ """Decode one JSON object."""
161
+ result = _decode_json(value, field=field)
162
+ if not isinstance(result, dict):
163
+ raise CLIInputError(f"{field} must be a JSON object")
164
+ return result
165
+
166
+
167
+ def _parse_json_object_list(value: str, *, field: str) -> list[dict[str, Any]]:
168
+ """Decode one JSON array containing only objects."""
169
+ result = _decode_json(value, field=field)
170
+ if not isinstance(result, list) or not all(isinstance(item, dict) for item in result):
171
+ raise CLIInputError(f"{field} must be a JSON array of objects")
172
+ return result
173
+
174
+
175
+ def _parse_json_string_list(value: str, *, field: str) -> list[str]:
176
+ """Decode one JSON array containing only strings."""
177
+ result = _decode_json(value, field=field)
178
+ if not isinstance(result, list) or not all(isinstance(item, str) for item in result):
179
+ raise CLIInputError(f"{field} must be a JSON array of strings")
180
+ return result
181
+
182
+
183
+ def _validate_inputs(spec: OperationSpec, args: argparse.Namespace) -> None:
184
+ """Validate scalar and outer JSON shapes before client creation."""
185
+ _required_text(args.model_id, field="model_id")
186
+ for name in spec["object_json"]:
187
+ value = getattr(args, name, None)
188
+ if value is not None:
189
+ setattr(args, name, _parse_json_object(value, field=name))
190
+ for name in spec["object_list_json"]:
191
+ value = getattr(args, name, None)
192
+ if value is not None:
193
+ setattr(args, name, _parse_json_object_list(value, field=name))
194
+ for name in spec["string_list_json"]:
195
+ value = getattr(args, name, None)
196
+ if value is not None:
197
+ setattr(args, name, _parse_json_string_list(value, field=name))
198
+
199
+
200
+ def _validate_timeout(value: int) -> int:
201
+ """Validate the effective ADR-002 timeout."""
202
+ if isinstance(value, bool) or not isinstance(value, int) or not 1 <= value <= 3600:
203
+ raise CLIInputError("timeout must be between 1 and 3600 seconds")
204
+ return value
205
+
206
+
207
+ def _get_client(root_client: Any, client_path: tuple[str, ...]) -> Any:
208
+ """Resolve one exact public Language Models SDK resource."""
209
+ client = root_client.language_models
210
+ for attribute in client_path:
211
+ client = getattr(client, attribute)
212
+ return client
213
+
214
+
215
+ def _model_to_dict(value: Any) -> Any:
216
+ """Convert SDK models to JSON-compatible values."""
217
+ if isinstance(value, list):
218
+ return [_model_to_dict(item) for item in value]
219
+ if isinstance(value, dict):
220
+ return {key: _model_to_dict(item) for key, item in value.items()}
221
+ for method_name in ("to_dict", "model_dump", "dict"):
222
+ method = getattr(value, method_name, None)
223
+ if callable(method):
224
+ result = method()
225
+ if isinstance(result, dict):
226
+ return {key: _model_to_dict(item) for key, item in result.items()}
227
+ return value
228
+
229
+
230
+ async def _invoke_sdk(
231
+ spec: OperationSpec,
232
+ client: Any,
233
+ args: argparse.Namespace,
234
+ timeout: int,
235
+ ) -> Any:
236
+ """Call one decoded SDK inference method with exact documented arguments."""
237
+ kwargs: dict[str, Any] = {}
238
+ for name in (*spec["required"], *spec["optional"]):
239
+ value = getattr(args, name, None)
240
+ if value is not None:
241
+ kwargs[name] = value
242
+ kwargs["request_timeout"] = timeout
243
+ return await getattr(client, spec["method"])(args.model_id, **kwargs)
244
+
245
+
246
+ def _serialize_error(exception: BaseException) -> int:
247
+ """Write one privacy-safe ADR-001 error envelope."""
248
+ serializer = ErrorSerializer()
249
+ status = sdk_http_status(exception)
250
+ declared = getattr(exception, "exit_code", None)
251
+ sdk_exit = sdk_exception_exit_code(exception)
252
+ if isinstance(declared, int) and 1 <= declared <= 9:
253
+ exit_code = declared
254
+ elif sdk_exit is not None:
255
+ exit_code = sdk_exit
256
+ elif status == 401:
257
+ exit_code = EXIT_AUTH
258
+ elif status == 403:
259
+ exit_code = EXIT_PERMISSION_DENIED
260
+ elif status == 404:
261
+ exit_code = EXIT_NOT_FOUND
262
+ elif status == 409:
263
+ exit_code = EXIT_USER_INPUT
264
+ elif status == 429:
265
+ exit_code = EXIT_RATE_LIMIT
266
+ elif isinstance(exception, ConfigurationError):
267
+ exit_code = EXIT_CONFIGURATION
268
+ elif isinstance(exception, (TypeError, ValueError)):
269
+ exit_code = EXIT_USER_INPUT
270
+ elif isinstance(exception, TimeoutError):
271
+ exit_code = EXIT_TIMEOUT
272
+ else:
273
+ exit_code = EXIT_SERVER_ERROR
274
+ safe = isinstance(exception, (CLIInputError, ConfigurationError, TimeoutError)) or declared in {
275
+ EXIT_ACCESS_CONTROL,
276
+ EXIT_CONFIGURATION,
277
+ }
278
+ message = str(exception) if safe else "Language Models operation failed"
279
+ envelope = serializer.create_error_envelope(
280
+ exit_code, message, type(exception).__name__, serializer.call_id
281
+ )
282
+ if status is not None:
283
+ envelope["http_status"] = status
284
+ sys.stdout.write(json.dumps(envelope, default=str) + "\n")
285
+ sys.stdout.flush()
286
+ logger.error(
287
+ "Language Models operation failed",
288
+ extra={"call_id": serializer.call_id, "exception_type": type(exception).__name__, "http_status": status},
289
+ )
290
+ return exit_code
291
+
292
+
293
+ async def main() -> int:
294
+ """Run one stateless Language Models invocation."""
295
+ parser = build_parser()
296
+ try:
297
+ args = parser.parse_args()
298
+ if not args.resource or not getattr(args, "operation", None):
299
+ raise CLIInputError("a Language Models operation is required")
300
+ except CLIInputError as exc:
301
+ return _serialize_error(exc)
302
+
303
+ try:
304
+ cfg = ConfigLoader()
305
+ cfg.load()
306
+ LogSetup.configure(log_level=cfg.log_level)
307
+ resource = args.resource.replace("-", "_")
308
+ operation = args.operation.replace("-", "_")
309
+ spec = _spec_for(resource, operation)
310
+ _validate_inputs(spec, args)
311
+ timeout = _validate_timeout(args.timeout if args.timeout is not None else cfg.timeout_s)
312
+ AccessControlGuard(
313
+ cfg,
314
+ "LANGUAGE_MODELS",
315
+ metadata_allowlist_path=str(_METADATA_ALLOWLIST_PATH),
316
+ ).check(resource, operation)
317
+
318
+ factory = AsyncClientFactory()
319
+ with factory.invocation_scope(cfg, include_attribution=True):
320
+ root_client = factory.create(cfg, include_attribution=True)
321
+ client = _get_client(root_client, spec["client_path"])
322
+ result = await RetryHandler(timeout_s=timeout).execute(
323
+ _invoke_sdk, spec, client, args, timeout
324
+ )
325
+ rendered = OutputFormatter(
326
+ format_setting=args.format, pretty=args.pretty
327
+ ).format(_model_to_dict(result))
328
+ print(rendered)
329
+ return EXIT_SUCCESS
330
+ except asyncio.CancelledError:
331
+ return _serialize_error(TimeoutError("Operation cancelled"))
332
+ except Exception as exc:
333
+ return _serialize_error(exc)
334
+
335
+
336
+ def console_main() -> int:
337
+ """Run async CLI through one event-loop boundary."""
338
+ return asyncio.run(main())
339
+
340
+
341
+ if __name__ == "__main__":
342
+ raise SystemExit(console_main())
@@ -0,0 +1,9 @@
1
+ """Foundry Media Sets CLI package."""
2
+
3
+ from pal_found_cli.media_sets.scripts.pal_found_media_sets_cli import (
4
+ build_parser,
5
+ console_main,
6
+ main,
7
+ )
8
+
9
+ __all__ = ["build_parser", "console_main", "main"]
@@ -0,0 +1,23 @@
1
+ # Media Sets metadata allow-list
2
+
3
+ | SDK Path | Status | Rationale |
4
+ | --- | --- | --- |
5
+ | `media_sets.media_set.abort` | BLOCKED | Aborts a transaction |
6
+ | `media_sets.media_set.calculate` | BLOCKED | Starts a transformation job |
7
+ | `media_sets.media_set.clear` | BLOCKED | Clears a media item path |
8
+ | `media_sets.media_set.commit` | BLOCKED | Commits a transaction |
9
+ | `media_sets.media_set.create` | BLOCKED | Opens a transaction |
10
+ | `media_sets.media_set.get` | PERMITTED | Media set metadata |
11
+ | `media_sets.media_set.get_result` | BLOCKED | Transformation result content bytes |
12
+ | `media_sets.media_set.get_rid_by_path` | PERMITTED | Media item path metadata |
13
+ | `media_sets.media_set.get_status` | PERMITTED | Transformation job status metadata |
14
+ | `media_sets.media_set.info` | PERMITTED | Media item metadata |
15
+ | `media_sets.media_set.metadata` | PERMITTED | Media item metadata |
16
+ | `media_sets.media_set.read` | BLOCKED | Media content bytes |
17
+ | `media_sets.media_set.read_original` | BLOCKED | Original media content bytes |
18
+ | `media_sets.media_set.reference` | BLOCKED | Media reference content |
19
+ | `media_sets.media_set.register` | BLOCKED | Registers a media item |
20
+ | `media_sets.media_set.retrieve` | BLOCKED | Thumbnail content bytes |
21
+ | `media_sets.media_set.transform` | BLOCKED | Runs a transformation |
22
+ | `media_sets.media_set.upload` | BLOCKED | Uploads media content |
23
+ | `media_sets.media_set.upload_media` | BLOCKED | Uploads temporary media content |
@@ -0,0 +1 @@
1
+ """Foundry Media Sets CLI scripts package."""