field-studio-sdk 0.1.0__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.
@@ -0,0 +1,400 @@
1
+ # Folder view configuration files
2
+ .DS_Store
3
+
4
+ # Thumbnail cache files
5
+ Thumbs.db
6
+
7
+ # Local files
8
+ .local/
9
+
10
+ # dotenv environment variable files
11
+ .env
12
+ .env.*
13
+ !.env.example
14
+
15
+ # Byte-compiled / optimized / DLL files
16
+ __pycache__/
17
+ *.py[codz]
18
+ *$py.class
19
+
20
+ # C extensions
21
+ *.so
22
+
23
+ # Distribution / packaging
24
+ .Python
25
+ build/
26
+ develop-eggs/
27
+ dist/
28
+ downloads/
29
+ eggs/
30
+ .eggs/
31
+ lib/
32
+ lib64/
33
+ parts/
34
+ sdist/
35
+ var/
36
+ wheels/
37
+ share/python-wheels/
38
+ *.egg-info/
39
+ .installed.cfg
40
+ *.egg
41
+ MANIFEST
42
+
43
+ # PyInstaller
44
+ # Usually these files are written by a python script from a template
45
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
46
+ *.manifest
47
+ *.spec
48
+
49
+ # Installer logs
50
+ pip-log.txt
51
+ pip-delete-this-directory.txt
52
+
53
+ # Unit test / coverage reports
54
+ htmlcov/
55
+ .tox/
56
+ .nox/
57
+ .coverage
58
+ .coverage.*
59
+ .cache
60
+ nosetests.xml
61
+ coverage.xml
62
+ *.cover
63
+ *.py.cover
64
+ *.lcov
65
+ .hypothesis/
66
+ .pytest_cache/
67
+ cover/
68
+
69
+ # Translations
70
+ *.mo
71
+ *.pot
72
+
73
+ # Django stuff:
74
+ *.log
75
+ local_settings.py
76
+ db.sqlite3
77
+ db.sqlite3-journal
78
+
79
+ # Flask stuff:
80
+ instance/
81
+ .webassets-cache
82
+
83
+ # Scrapy stuff:
84
+ .scrapy
85
+
86
+ # Sphinx documentation
87
+ docs/_build/
88
+
89
+ # PyBuilder
90
+ .pybuilder/
91
+ target/
92
+
93
+ # Jupyter Notebook
94
+ .ipynb_checkpoints
95
+
96
+ # IPython
97
+ profile_default/
98
+ ipython_config.py
99
+
100
+ # pyenv
101
+ # For a library or package, you might want to ignore these files since the code is
102
+ # intended to run in multiple environments; otherwise, check them in:
103
+ .python-version
104
+
105
+ # pipenv
106
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
107
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
108
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
109
+ # install all needed dependencies.
110
+ # Pipfile.lock
111
+
112
+ # uv
113
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
114
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
115
+ # commonly ignored for libraries.
116
+ # uv.lock
117
+
118
+ # poetry
119
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
120
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
121
+ # commonly ignored for libraries.
122
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
123
+ # poetry.lock
124
+ # poetry.toml
125
+
126
+ # pdm
127
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
128
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
129
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
130
+ # pdm.lock
131
+ # pdm.toml
132
+ .pdm-python
133
+ .pdm-build/
134
+
135
+ # pixi
136
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
137
+ # pixi.lock
138
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
139
+ # in the .venv directory. It is recommended not to include this directory in version control.
140
+ .pixi/*
141
+ !.pixi/config.toml
142
+
143
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
144
+ __pypackages__/
145
+
146
+ # Celery stuff
147
+ celerybeat-schedule*
148
+ celerybeat.pid
149
+
150
+ # Redis
151
+ *.rdb
152
+ *.aof
153
+ *.pid
154
+
155
+ # RabbitMQ
156
+ mnesia/
157
+ rabbitmq/
158
+ rabbitmq-data/
159
+
160
+ # ActiveMQ
161
+ activemq-data/
162
+
163
+ # SageMath parsed files
164
+ *.sage.py
165
+
166
+ # Environments
167
+ .env
168
+ .envrc
169
+ .venv
170
+ env/
171
+ venv/
172
+ ENV/
173
+ env.bak/
174
+ venv.bak/
175
+
176
+ # Conda environments
177
+ conda-meta/
178
+
179
+ # Spyder project settings
180
+ .spyderproject
181
+ .spyproject
182
+
183
+ # Rope project settings
184
+ .ropeproject
185
+
186
+ # mkdocs/Zensical documentation
187
+ /site
188
+
189
+ # mypy
190
+ .mypy_cache/
191
+ .dmypy.json
192
+ dmypy.json
193
+
194
+ # Pyre type checker
195
+ .pyre/
196
+
197
+ # pytype static type analyzer
198
+ .pytype/
199
+
200
+ # Cython debug symbols
201
+ cython_debug/
202
+
203
+ # PyCharm
204
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
205
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
206
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
207
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
208
+ # .idea/
209
+
210
+ # Abstra
211
+ # Abstra is an AI-powered process automation framework.
212
+ # Ignore directories containing user credentials, local state, and settings.
213
+ # Learn more at https://abstra.io/docs
214
+ .abstra/
215
+
216
+ # Visual Studio Code
217
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
218
+ # can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
219
+ # and can be added to the global gitignore or merged into this file. However, if you prefer, you
220
+ # could uncomment the following to ignore the entire vscode folder
221
+ # .vscode/
222
+ # Temporary file for partial code execution
223
+ tempCodeRunnerFile.py
224
+
225
+ # Ruff stuff:
226
+ .ruff_cache/
227
+
228
+ # PyPI configuration file
229
+ .pypirc
230
+
231
+ # Marimo
232
+ marimo/_static/
233
+ marimo/_lsp/
234
+ __marimo__/
235
+
236
+ # Streamlit
237
+ .streamlit/secrets.toml
238
+
239
+ # Logs
240
+ logs
241
+ !/web/src/app/apps/*/logs/
242
+ *.log
243
+ npm-debug.log*
244
+ yarn-debug.log*
245
+ yarn-error.log*
246
+ lerna-debug.log*
247
+
248
+ # Diagnostic reports (https://nodejs.org/api/report.html)
249
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
250
+
251
+ # Runtime data
252
+ pids
253
+ *.pid
254
+ *.seed
255
+ *.pid.lock
256
+
257
+ # Directory for instrumented libs generated by jscoverage/JSCover
258
+ lib-cov
259
+
260
+ # Coverage directory used by tools like istanbul
261
+ coverage
262
+ *.lcov
263
+
264
+ # nyc test coverage
265
+ .nyc_output
266
+
267
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
268
+ .grunt
269
+
270
+ # Bower dependency directory (https://bower.io/)
271
+ bower_components
272
+
273
+ # node-waf configuration
274
+ .lock-wscript
275
+
276
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
277
+ build/Release
278
+
279
+ # Dependency directories
280
+ node_modules/
281
+ jspm_packages/
282
+
283
+ # Snowpack dependency directory (https://snowpack.dev/)
284
+ web_modules/
285
+
286
+ # TypeScript cache
287
+ *.tsbuildinfo
288
+
289
+ # Optional npm cache directory
290
+ .npm
291
+
292
+ # Optional eslint cache
293
+ .eslintcache
294
+
295
+ # Optional stylelint cache
296
+ .stylelintcache
297
+
298
+ # Optional REPL history
299
+ .node_repl_history
300
+
301
+ # Output of 'npm pack'
302
+ *.tgz
303
+
304
+ # Yarn Integrity file
305
+ .yarn-integrity
306
+
307
+ # dotenv environment variable files
308
+ .env
309
+ .env.*
310
+ !.env.example
311
+
312
+ # parcel-bundler cache (https://parceljs.org/)
313
+ .cache
314
+ .parcel-cache
315
+
316
+ # Next.js build output
317
+ .next
318
+ next-env.d.ts
319
+ out
320
+ !/web/src/lib/
321
+ !/web/src/lib/**
322
+
323
+ # Nuxt.js build / generate output
324
+ .nuxt
325
+ dist
326
+ .output
327
+
328
+ # NitroJS
329
+ .nitro/
330
+
331
+ # Gatsby files
332
+ .cache/
333
+ # Comment in the public line in if your project uses Gatsby and not Next.js
334
+ # https://nextjs.org/blog/next-9-1#public-directory-support
335
+ # public
336
+
337
+ # vuepress build output
338
+ .vuepress/dist
339
+
340
+ # vuepress v2.x temp directory
341
+ .temp
342
+
343
+ # Sveltekit cache directory
344
+ .svelte-kit/
345
+
346
+ # vitepress build output
347
+ **/.vitepress/dist
348
+
349
+ # vitepress cache directory
350
+ **/.vitepress/cache
351
+
352
+ # Docusaurus cache and generated files
353
+ .docusaurus
354
+
355
+ # Serverless directories
356
+ .serverless/
357
+
358
+ # FuseBox cache
359
+ .fusebox/
360
+
361
+ # DynamoDB Local files
362
+ .dynamodb/
363
+
364
+ # Firebase cache directory
365
+ .firebase/
366
+
367
+ # TernJS port file
368
+ .tern-port
369
+
370
+ # Stores Visual Studio Code versions used for testing Visual Studio Code extensions
371
+ .vscode-test
372
+
373
+ # pnpm
374
+ .pnpm-store
375
+
376
+ # yarn v3
377
+ .pnp.*
378
+ .yarn/*
379
+ !.yarn/patches
380
+ !.yarn/plugins
381
+ !.yarn/releases
382
+ !.yarn/sdks
383
+ !.yarn/versions
384
+
385
+ # Vite files
386
+ vite.config.js.timestamp-*
387
+ vite.config.ts.timestamp-*
388
+ .vite/
389
+
390
+ # Astro generated types
391
+ .astro/
392
+
393
+ # Turbo Repo
394
+ .turbo
395
+
396
+ # Other
397
+ .nvmrc
398
+ compose.override.yaml
399
+
400
+ .pnpm-store/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Andrew Lyu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.5
2
+ Name: field-studio-sdk
3
+ Version: 0.1.0
4
+ Summary: Typed clients and data contracts for Field Studio
5
+ Project-URL: Repository, https://github.com/apemost/field-studio
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.14
9
+ Requires-Dist: httpx>=0.28
10
+ Requires-Dist: jsonschema<5,>=4.25
11
+ Requires-Dist: pydantic<3,>=2
12
+ Requires-Dist: rfc8785<1,>=0.1.4
13
+ Description-Content-Type: text/markdown
14
+
15
+ # Field Studio Python SDK
16
+
17
+ Typed backend clients and data contracts for Field Studio. Requires Python 3.14
18
+ or later.
19
+
20
+ ```sh
21
+ pip install field-studio-sdk
22
+ ```
23
+
24
+ ```python
25
+ from field_studio_sdk.identity import IdentityClient
26
+ from field_studio_sdk.workspace import WorkspaceClient
27
+ ```
28
+
29
+ - Use `IdentityClient` to call the platform identity service.
30
+ - Use `WorkspaceClient` to access the workspace resolved by the host's
31
+ authenticated session.
32
+ - Import shared models and errors from `field_studio_sdk.contracts`.
33
+
34
+ Use the SDK version that matches your Field Studio deployment. Configure the
35
+ platform URL and service credentials in the backend. Remote connections require
36
+ verified HTTPS.
37
+
38
+ The SDK is licensed under MIT. The distribution includes the license text.
@@ -0,0 +1,24 @@
1
+ # Field Studio Python SDK
2
+
3
+ Typed backend clients and data contracts for Field Studio. Requires Python 3.14
4
+ or later.
5
+
6
+ ```sh
7
+ pip install field-studio-sdk
8
+ ```
9
+
10
+ ```python
11
+ from field_studio_sdk.identity import IdentityClient
12
+ from field_studio_sdk.workspace import WorkspaceClient
13
+ ```
14
+
15
+ - Use `IdentityClient` to call the platform identity service.
16
+ - Use `WorkspaceClient` to access the workspace resolved by the host's
17
+ authenticated session.
18
+ - Import shared models and errors from `field_studio_sdk.contracts`.
19
+
20
+ Use the SDK version that matches your Field Studio deployment. Configure the
21
+ platform URL and service credentials in the backend. Remote connections require
22
+ verified HTTPS.
23
+
24
+ The SDK is licensed under MIT. The distribution includes the license text.
@@ -0,0 +1,24 @@
1
+ [project]
2
+ name = "field-studio-sdk"
3
+ version = "0.1.0"
4
+ description = "Typed clients and data contracts for Field Studio"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.14"
9
+ dependencies = [
10
+ "httpx>=0.28",
11
+ "jsonschema>=4.25,<5",
12
+ "pydantic>=2,<3",
13
+ "rfc8785>=0.1.4,<1",
14
+ ]
15
+
16
+ [project.urls]
17
+ Repository = "https://github.com/apemost/field-studio"
18
+
19
+ [build-system]
20
+ requires = ["hatchling>=1.27"]
21
+ build-backend = "hatchling.build"
22
+
23
+ [tool.hatch.build.targets.wheel]
24
+ packages = ["src/field_studio_sdk"]
@@ -0,0 +1,146 @@
1
+ """Standalone AI work clients; no business or framework dependencies."""
2
+
3
+ import re
4
+ from typing import Any
5
+ from urllib.parse import urlsplit
6
+
7
+ import httpx
8
+
9
+ from .contracts import CreateTask, PlatformError
10
+
11
+ __all__ = ["PlatformClient", "PlatformError"]
12
+
13
+
14
+ def _identifier(value: str) -> str:
15
+ if not re.fullmatch(r"[A-Za-z0-9_-]+(?:\.result)?", value):
16
+ raise ValueError("Invalid resource identifier")
17
+ return value
18
+
19
+
20
+ class PlatformClient:
21
+ """Use a scoped runtime capability without business or UI dependencies."""
22
+
23
+ def __init__(
24
+ self, runtime_url: str, *, client: httpx.AsyncClient | None = None
25
+ ) -> None:
26
+ parsed = urlsplit(runtime_url)
27
+ if (
28
+ parsed.scheme not in ("http", "https")
29
+ or not parsed.hostname
30
+ or parsed.username
31
+ or parsed.password
32
+ or parsed.query
33
+ or parsed.fragment
34
+ ):
35
+ raise ValueError("Invalid runtime URL")
36
+ self.url = runtime_url.rstrip("/")
37
+ self.http = client or httpx.AsyncClient(
38
+ timeout=30, follow_redirects=False, trust_env=False
39
+ )
40
+ self.owned = client is None
41
+
42
+ async def __aenter__(self) -> PlatformClient:
43
+ return self
44
+
45
+ async def __aexit__(self, *args: object) -> None:
46
+ if self.owned:
47
+ await self.http.aclose()
48
+
49
+ async def _request(
50
+ self,
51
+ method: str,
52
+ path: str,
53
+ body: dict[str, Any] | None = None,
54
+ key: str | None = None,
55
+ *,
56
+ raw: bool = False,
57
+ ) -> Any:
58
+ headers = {}
59
+ if method != "GET":
60
+ if not key or not key.strip() or len(key) > 200:
61
+ raise ValueError("A stable idempotency key is required")
62
+ headers["Idempotency-Key"] = key
63
+ try:
64
+ request = httpx.Request(method, self.url + path, json=body, headers=headers)
65
+ response = await self.http.send(request, auth=None, follow_redirects=False)
66
+ except httpx.HTTPError:
67
+ raise PlatformError(
68
+ "RUNTIME_UNAVAILABLE", "Platform request failed", 503
69
+ ) from None
70
+ if not 200 <= response.status_code < 300:
71
+ try:
72
+ error = response.json().get("error", {})
73
+ code = str(error.get("code", "PROTOCOL_ERROR"))
74
+ except ValueError, AttributeError:
75
+ code = "PROTOCOL_ERROR"
76
+ raise PlatformError(
77
+ code, "Platform rejected the request", response.status_code
78
+ )
79
+ if raw:
80
+ return response.content
81
+ try:
82
+ value = response.json()
83
+ if not isinstance(value, dict):
84
+ raise ValueError("Invalid envelope")
85
+ return value
86
+ except ValueError:
87
+ raise PlatformError(
88
+ "PROTOCOL_ERROR", "Invalid platform response", 502
89
+ ) from None
90
+
91
+ async def create_task(
92
+ self, body: dict[str, Any], *, idempotency_key: str
93
+ ) -> dict[str, Any]:
94
+ """Create work once per caller-owned intent key."""
95
+ payload = CreateTask.model_validate(body).model_dump()
96
+ return await self._request("POST", "/tasks", payload, idempotency_key)
97
+
98
+ async def get_task(self, task_id: str) -> dict[str, Any]:
99
+ """Fetch the authoritative state of an owned task."""
100
+ return await self._request("GET", f"/tasks/{_identifier(task_id)}")
101
+
102
+ async def list_tasks(self) -> dict[str, Any]:
103
+ """List work visible to the runtime session."""
104
+ return await self._request("GET", "/tasks")
105
+
106
+ async def events(
107
+ self, task_id: str, *, after: str = "0", limit: int = 50
108
+ ) -> dict[str, Any]:
109
+ """Continue durable resource events from a previously returned cursor."""
110
+ if not after.isascii() or not after.isdigit() or not 1 <= limit <= 200:
111
+ raise ValueError("Invalid event page")
112
+ return await self._request(
113
+ "GET", f"/tasks/{_identifier(task_id)}/events?after={after}&limit={limit}"
114
+ )
115
+
116
+ async def cancel(
117
+ self, task_id: str, expected_version: int, *, idempotency_key: str
118
+ ) -> dict[str, Any]:
119
+ """Cancel only the task version the user observed."""
120
+ return await self._request(
121
+ "POST",
122
+ f"/tasks/{_identifier(task_id)}/cancel",
123
+ {"expectedVersion": expected_version},
124
+ idempotency_key,
125
+ )
126
+
127
+ async def retry(
128
+ self, task_id: str, expected_version: int, *, idempotency_key: str
129
+ ) -> dict[str, Any]:
130
+ """Request a new attempt; do not automatically replay failed requests."""
131
+ return await self._request(
132
+ "POST",
133
+ f"/tasks/{_identifier(task_id)}/retry",
134
+ {"expectedVersion": expected_version},
135
+ idempotency_key,
136
+ )
137
+
138
+ async def artifacts(self, task_id: str) -> dict[str, Any]:
139
+ """List published result metadata."""
140
+ return await self._request("GET", f"/tasks/{_identifier(task_id)}/artifacts")
141
+
142
+ async def download(self, artifact_id: str) -> bytes:
143
+ """Download an artifact through the same scoped runtime session."""
144
+ return await self._request(
145
+ "GET", f"/artifacts/{_identifier(artifact_id)}/content", raw=True
146
+ )