latchgate-integrations-common 0.1.0__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.
- latchgate_common/__init__.py +44 -0
- latchgate_common/audit.py +36 -0
- latchgate_common/discovery.py +296 -0
- latchgate_common/py.typed +0 -0
- latchgate_common/schema.py +85 -0
- latchgate_common/serialization.py +64 -0
- latchgate_common/sync.py +85 -0
- latchgate_common/transport.py +63 -0
- latchgate_integrations_common-0.1.0.dist-info/METADATA +52 -0
- latchgate_integrations_common-0.1.0.dist-info/RECORD +12 -0
- latchgate_integrations_common-0.1.0.dist-info/WHEEL +4 -0
- latchgate_integrations_common-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Shared internals for LatchGate framework integrations.
|
|
2
|
+
|
|
3
|
+
This package provides the canonical implementation of discovery, schema
|
|
4
|
+
conversion, result serialization, and transport resolution used by every
|
|
5
|
+
Python integration package (LangChain, CrewAI, OpenAI Agents, Pydantic AI).
|
|
6
|
+
|
|
7
|
+
End users should install a framework-specific package (e.g.
|
|
8
|
+
``latchgate-langchain``) rather than depending on this package directly.
|
|
9
|
+
|
|
10
|
+
Security-relevant logic — especially the ``expose_security_details``
|
|
11
|
+
redaction in :func:`build_description` and the output-only filtering
|
|
12
|
+
in :func:`serialize_result` — lives here exactly once.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from latchgate_common.audit import AuditCallback, AuditRecord
|
|
16
|
+
from latchgate_common.discovery import (
|
|
17
|
+
ActionDescriptor,
|
|
18
|
+
build_description,
|
|
19
|
+
discover_actions,
|
|
20
|
+
)
|
|
21
|
+
from latchgate_common.schema import (
|
|
22
|
+
JSON_TYPE_MAP,
|
|
23
|
+
resolve_type,
|
|
24
|
+
schema_to_pydantic,
|
|
25
|
+
)
|
|
26
|
+
from latchgate_common.serialization import serialize_result
|
|
27
|
+
from latchgate_common.sync import run_sync
|
|
28
|
+
from latchgate_common.transport import resolve_discovery_params
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"JSON_TYPE_MAP",
|
|
32
|
+
"ActionDescriptor",
|
|
33
|
+
"AuditCallback",
|
|
34
|
+
"AuditRecord",
|
|
35
|
+
"build_description",
|
|
36
|
+
"discover_actions",
|
|
37
|
+
"resolve_discovery_params",
|
|
38
|
+
"resolve_type",
|
|
39
|
+
"run_sync",
|
|
40
|
+
"schema_to_pydantic",
|
|
41
|
+
"serialize_result",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Audit metadata callback for LatchGate integrations.
|
|
2
|
+
|
|
3
|
+
After every successful action execution, LatchGate returns a receipt ID,
|
|
4
|
+
trace ID, and verification outcome. By default this metadata is logged at
|
|
5
|
+
INFO level. The ``AuditCallback`` protocol allows orchestrators to consume
|
|
6
|
+
it programmatically — for example to store receipts in a database, emit
|
|
7
|
+
OpenTelemetry spans, or feed a compliance pipeline.
|
|
8
|
+
|
|
9
|
+
The callback is invoked *after* the model-facing output has been
|
|
10
|
+
serialized. It never affects the return value seen by the model.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
from typing import Any, Protocol
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True)
|
|
20
|
+
class AuditRecord:
|
|
21
|
+
"""Audit metadata from a single LatchGate action execution."""
|
|
22
|
+
|
|
23
|
+
action_id: str
|
|
24
|
+
receipt_id: str | None
|
|
25
|
+
trace_id: str | None
|
|
26
|
+
verification: Any
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class AuditCallback(Protocol):
|
|
30
|
+
"""Protocol for audit metadata handlers.
|
|
31
|
+
|
|
32
|
+
Implementations may be sync or async — the integration layer
|
|
33
|
+
calls whichever variant the framework supports.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __call__(self, record: AuditRecord) -> None: ...
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"""Action discovery from the LatchGate REST API.
|
|
2
|
+
|
|
3
|
+
Fetches the action registry and request schemas via unauthenticated endpoints.
|
|
4
|
+
These endpoints expose only structural metadata — never credentials or secrets.
|
|
5
|
+
|
|
6
|
+
Discovery is a one-time operation at toolkit initialization, not per-call.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import logging
|
|
12
|
+
import re
|
|
13
|
+
from dataclasses import dataclass, field
|
|
14
|
+
from typing import Any, Literal
|
|
15
|
+
|
|
16
|
+
import httpx
|
|
17
|
+
|
|
18
|
+
logger = logging.getLogger(__name__)
|
|
19
|
+
|
|
20
|
+
# Identifier format: alphanumeric start, then alphanumeric/hyphens/underscores/dots.
|
|
21
|
+
# No path separators, query strings, or URL-special characters.
|
|
22
|
+
_SAFE_IDENTIFIER_RE = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9._-]*$")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _is_safe_identifier(value: str) -> bool:
|
|
26
|
+
"""Check whether a string is safe for URL path interpolation.
|
|
27
|
+
|
|
28
|
+
Used to validate action_ids received from the gate before embedding
|
|
29
|
+
them in URLs for schema and detail fetches. The gate is a trusted
|
|
30
|
+
source, but a compromised or buggy gate could return a crafted
|
|
31
|
+
action_id (e.g. ``"../../admin"``) that alters the request path.
|
|
32
|
+
"""
|
|
33
|
+
return bool(value) and len(value) <= 256 and _SAFE_IDENTIFIER_RE.match(value) is not None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass(frozen=True)
|
|
37
|
+
class ActionDescriptor:
|
|
38
|
+
"""Metadata for a single discovered LatchGate action."""
|
|
39
|
+
|
|
40
|
+
action_id: str
|
|
41
|
+
version: str
|
|
42
|
+
risk_level: str
|
|
43
|
+
request_schema: dict[str, Any]
|
|
44
|
+
description: str
|
|
45
|
+
declared_side_effects: list[str] = field(default_factory=list)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
async def discover_actions(
|
|
49
|
+
gate_url: str,
|
|
50
|
+
*,
|
|
51
|
+
timeout: float = 15.0,
|
|
52
|
+
include: set[str] | None = None,
|
|
53
|
+
exclude: set[str] | None = None,
|
|
54
|
+
allow_schemaless: bool = False,
|
|
55
|
+
expose_security_details: Literal["none", "debug"] = "none",
|
|
56
|
+
_http: httpx.AsyncClient | None = None,
|
|
57
|
+
) -> list[ActionDescriptor]:
|
|
58
|
+
"""Discover all registered actions from a LatchGate instance.
|
|
59
|
+
|
|
60
|
+
Parameters
|
|
61
|
+
----------
|
|
62
|
+
gate_url:
|
|
63
|
+
Base URL of the running gate (e.g. ``"http://localhost:3000"``).
|
|
64
|
+
timeout:
|
|
65
|
+
HTTP timeout for discovery requests in seconds.
|
|
66
|
+
include:
|
|
67
|
+
If provided, only return actions whose ``action_id`` is in this set.
|
|
68
|
+
exclude:
|
|
69
|
+
If provided, skip actions whose ``action_id`` is in this set.
|
|
70
|
+
``exclude`` is applied after ``include``.
|
|
71
|
+
allow_schemaless:
|
|
72
|
+
When ``False`` (default), actions without a request schema are
|
|
73
|
+
skipped with a warning. Production LatchGate always serves
|
|
74
|
+
schemas; a missing schema indicates a degraded gate. Set to
|
|
75
|
+
``True`` only for development against a gate that legitimately
|
|
76
|
+
omits schemas.
|
|
77
|
+
expose_security_details:
|
|
78
|
+
Controls how much enforcement metadata appears in model-visible
|
|
79
|
+
tool descriptions. ``"none"`` (default) omits egress profiles,
|
|
80
|
+
allowed domains, database modes, and statement IDs — a
|
|
81
|
+
compromised model could use these to craft targeted attacks.
|
|
82
|
+
``"debug"`` includes all available detail.
|
|
83
|
+
_http:
|
|
84
|
+
Optional pre-configured ``httpx.AsyncClient`` — used for testing.
|
|
85
|
+
When provided, the caller owns the client lifecycle.
|
|
86
|
+
|
|
87
|
+
Returns
|
|
88
|
+
-------
|
|
89
|
+
List of :class:`ActionDescriptor` for each discovered action.
|
|
90
|
+
"""
|
|
91
|
+
base = gate_url.rstrip("/")
|
|
92
|
+
|
|
93
|
+
if _http is not None:
|
|
94
|
+
return await _discover_with_client(
|
|
95
|
+
_http,
|
|
96
|
+
base,
|
|
97
|
+
include,
|
|
98
|
+
exclude,
|
|
99
|
+
allow_schemaless,
|
|
100
|
+
expose_security_details,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
async with httpx.AsyncClient(timeout=timeout) as http:
|
|
104
|
+
return await _discover_with_client(
|
|
105
|
+
http,
|
|
106
|
+
base,
|
|
107
|
+
include,
|
|
108
|
+
exclude,
|
|
109
|
+
allow_schemaless,
|
|
110
|
+
expose_security_details,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
async def _discover_with_client(
|
|
115
|
+
http: httpx.AsyncClient,
|
|
116
|
+
base: str,
|
|
117
|
+
include: set[str] | None,
|
|
118
|
+
exclude: set[str] | None,
|
|
119
|
+
allow_schemaless: bool,
|
|
120
|
+
security_detail: Literal["none", "debug"],
|
|
121
|
+
) -> list[ActionDescriptor]:
|
|
122
|
+
"""Core discovery logic using an existing HTTP client."""
|
|
123
|
+
actions_resp = await http.get(f"{base}/v1/actions")
|
|
124
|
+
actions_resp.raise_for_status()
|
|
125
|
+
actions_data = actions_resp.json()
|
|
126
|
+
|
|
127
|
+
raw_actions: list[dict[str, Any]] = actions_data.get("actions", [])
|
|
128
|
+
if not raw_actions:
|
|
129
|
+
logger.warning("gate returned zero actions from %s/v1/actions", base)
|
|
130
|
+
return []
|
|
131
|
+
|
|
132
|
+
# Filter before fetching schemas to avoid unnecessary network calls.
|
|
133
|
+
filtered = _filter_actions(raw_actions, include, exclude)
|
|
134
|
+
|
|
135
|
+
descriptors: list[ActionDescriptor] = []
|
|
136
|
+
for action in filtered:
|
|
137
|
+
action_id = action["action_id"]
|
|
138
|
+
|
|
139
|
+
if not _is_safe_identifier(action_id):
|
|
140
|
+
logger.warning(
|
|
141
|
+
"skipping action with unsafe identifier: %r — "
|
|
142
|
+
"action_id must be alphanumeric with hyphens, underscores, "
|
|
143
|
+
"or dots (max 256 chars)",
|
|
144
|
+
action_id,
|
|
145
|
+
)
|
|
146
|
+
continue
|
|
147
|
+
|
|
148
|
+
version = action.get("version", "0.0.0")
|
|
149
|
+
risk_level = action.get("risk_level", "unknown")
|
|
150
|
+
|
|
151
|
+
schema = await _fetch_schema(http, base, action_id)
|
|
152
|
+
|
|
153
|
+
if schema is None:
|
|
154
|
+
if allow_schemaless:
|
|
155
|
+
logger.warning(
|
|
156
|
+
"no schema for action '%s' — wrapping with permissive "
|
|
157
|
+
"schema (allow_schemaless=True)",
|
|
158
|
+
action_id,
|
|
159
|
+
)
|
|
160
|
+
schema = {"type": "object", "additionalProperties": True}
|
|
161
|
+
else:
|
|
162
|
+
logger.warning(
|
|
163
|
+
"skipping action '%s': gate did not return a request schema. "
|
|
164
|
+
"This usually means the gate is degraded. Pass "
|
|
165
|
+
"allow_schemaless=True to wrap anyway (not recommended "
|
|
166
|
+
"for production).",
|
|
167
|
+
action_id,
|
|
168
|
+
)
|
|
169
|
+
continue
|
|
170
|
+
|
|
171
|
+
detail = await _fetch_detail(http, base, action_id)
|
|
172
|
+
|
|
173
|
+
side_effects = detail.get("declared_side_effects", []) if detail else []
|
|
174
|
+
description = build_description(action_id, version, risk_level, detail, security_detail)
|
|
175
|
+
|
|
176
|
+
descriptors.append(
|
|
177
|
+
ActionDescriptor(
|
|
178
|
+
action_id=action_id,
|
|
179
|
+
version=version,
|
|
180
|
+
risk_level=risk_level,
|
|
181
|
+
request_schema=schema,
|
|
182
|
+
description=description,
|
|
183
|
+
declared_side_effects=side_effects,
|
|
184
|
+
)
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
logger.info("discovered %d LatchGate actions from %s", len(descriptors), base)
|
|
188
|
+
return descriptors
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _filter_actions(
|
|
192
|
+
actions: list[dict[str, Any]],
|
|
193
|
+
include: set[str] | None,
|
|
194
|
+
exclude: set[str] | None,
|
|
195
|
+
) -> list[dict[str, Any]]:
|
|
196
|
+
"""Apply include/exclude filters to the raw action list."""
|
|
197
|
+
result = actions
|
|
198
|
+
if include is not None:
|
|
199
|
+
result = [a for a in result if a.get("action_id") in include]
|
|
200
|
+
if exclude is not None:
|
|
201
|
+
result = [a for a in result if a.get("action_id") not in exclude]
|
|
202
|
+
return result
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
async def _fetch_schema(
|
|
206
|
+
http: httpx.AsyncClient,
|
|
207
|
+
base: str,
|
|
208
|
+
action_id: str,
|
|
209
|
+
) -> dict[str, Any] | None:
|
|
210
|
+
"""Fetch the request JSON Schema for an action. Returns None on failure."""
|
|
211
|
+
try:
|
|
212
|
+
resp = await http.get(f"{base}/v1/actions/{action_id}/schema/request")
|
|
213
|
+
if resp.status_code == 200:
|
|
214
|
+
schema: dict[str, Any] = resp.json()
|
|
215
|
+
return schema
|
|
216
|
+
except (httpx.HTTPError, ValueError) as exc:
|
|
217
|
+
logger.warning(
|
|
218
|
+
"failed to fetch schema for action '%s': %s",
|
|
219
|
+
action_id,
|
|
220
|
+
exc,
|
|
221
|
+
)
|
|
222
|
+
return None
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
async def _fetch_detail(
|
|
226
|
+
http: httpx.AsyncClient,
|
|
227
|
+
base: str,
|
|
228
|
+
action_id: str,
|
|
229
|
+
) -> dict[str, Any] | None:
|
|
230
|
+
"""Fetch the full action detail. Returns None on failure (best-effort)."""
|
|
231
|
+
try:
|
|
232
|
+
resp = await http.get(f"{base}/v1/actions/{action_id}")
|
|
233
|
+
if resp.status_code == 200:
|
|
234
|
+
detail: dict[str, Any] = resp.json()
|
|
235
|
+
return detail
|
|
236
|
+
except (httpx.HTTPError, ValueError) as exc:
|
|
237
|
+
logger.debug("failed to fetch detail for action '%s': %s", action_id, exc)
|
|
238
|
+
return None
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def build_description(
|
|
242
|
+
action_id: str,
|
|
243
|
+
version: str,
|
|
244
|
+
risk_level: str,
|
|
245
|
+
detail: dict[str, Any] | None,
|
|
246
|
+
security_detail: Literal["none", "debug"] = "none",
|
|
247
|
+
) -> str:
|
|
248
|
+
"""Build a human-readable tool description from action metadata.
|
|
249
|
+
|
|
250
|
+
The description gives an LLM enough context to decide when to call
|
|
251
|
+
the tool and how to construct valid arguments.
|
|
252
|
+
|
|
253
|
+
When ``security_detail`` is ``"none"`` (default), egress profiles,
|
|
254
|
+
allowed domains, database modes, and statement IDs are omitted —
|
|
255
|
+
exposing these to a potentially compromised model leaks enforcement
|
|
256
|
+
topology that could be used for targeted attacks.
|
|
257
|
+
|
|
258
|
+
When ``security_detail`` is ``"debug"``, all available metadata is
|
|
259
|
+
included. Use this only in trusted development environments.
|
|
260
|
+
"""
|
|
261
|
+
parts: list[str] = [
|
|
262
|
+
f"LatchGate protected action: {action_id} (v{version}, risk={risk_level}).",
|
|
263
|
+
]
|
|
264
|
+
|
|
265
|
+
if detail:
|
|
266
|
+
side_effects = detail.get("declared_side_effects", [])
|
|
267
|
+
if side_effects:
|
|
268
|
+
parts.append(f"Side effects: {', '.join(side_effects)}.")
|
|
269
|
+
|
|
270
|
+
if security_detail == "debug":
|
|
271
|
+
egress = detail.get("egress")
|
|
272
|
+
if isinstance(egress, dict):
|
|
273
|
+
profile = egress.get("profile", "")
|
|
274
|
+
domains = egress.get("allowed_domains", [])
|
|
275
|
+
if profile:
|
|
276
|
+
parts.append(f"Egress profile: {profile}.")
|
|
277
|
+
if domains:
|
|
278
|
+
parts.append(f"Allowed domains: {', '.join(domains)}.")
|
|
279
|
+
|
|
280
|
+
db = detail.get("database")
|
|
281
|
+
if isinstance(db, dict):
|
|
282
|
+
mode = db.get("mode", "unknown")
|
|
283
|
+
parts.append(f"Database mode: {mode}.")
|
|
284
|
+
stmts = db.get("statements", [])
|
|
285
|
+
if stmts:
|
|
286
|
+
ids = [s.get("id", "?") for s in stmts]
|
|
287
|
+
parts.append(f"Available statements: {', '.join(ids)}.")
|
|
288
|
+
if db.get("allows_parameterized_queries"):
|
|
289
|
+
ops = db.get("parameterized_operations", [])
|
|
290
|
+
parts.append(f"Parameterized queries allowed for: {', '.join(ops)}.")
|
|
291
|
+
|
|
292
|
+
parts.append(
|
|
293
|
+
"All calls are authenticated, policy-evaluated, sandboxed, "
|
|
294
|
+
"and produce signed audit receipts."
|
|
295
|
+
)
|
|
296
|
+
return " ".join(parts)
|
|
File without changes
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""JSON Schema to Pydantic model conversion for LatchGate action parameters.
|
|
2
|
+
|
|
3
|
+
Used by framework integrations that require a Pydantic model for tool
|
|
4
|
+
argument validation (LangChain, CrewAI). Frameworks with native JSON Schema
|
|
5
|
+
support (OpenAI Agents, Pydantic AI) bypass this module.
|
|
6
|
+
|
|
7
|
+
We deliberately do NOT attempt to support the full JSON Schema spec.
|
|
8
|
+
Over-engineering the conversion creates fragile code that breaks on
|
|
9
|
+
edge cases. The gate is the authoritative validator; the Pydantic model
|
|
10
|
+
here serves two purposes:
|
|
11
|
+
|
|
12
|
+
1. Give the framework a schema to emit in function-call descriptions.
|
|
13
|
+
2. Provide basic client-side type hints.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel, create_model
|
|
21
|
+
from pydantic.fields import FieldInfo
|
|
22
|
+
|
|
23
|
+
# JSON Schema type => Python type mapping for dynamic Pydantic model generation.
|
|
24
|
+
JSON_TYPE_MAP: dict[str, type] = {
|
|
25
|
+
"string": str,
|
|
26
|
+
"integer": int,
|
|
27
|
+
"number": float,
|
|
28
|
+
"boolean": bool,
|
|
29
|
+
"array": list,
|
|
30
|
+
"object": dict,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def schema_to_pydantic(action_id: str, schema: dict[str, Any]) -> type[BaseModel]:
|
|
35
|
+
"""Convert a JSON Schema ``{"type": "object", "properties": ...}`` to a Pydantic model.
|
|
36
|
+
|
|
37
|
+
Handles the common patterns emitted by LatchGate manifests:
|
|
38
|
+
flat objects with typed properties, required fields, and descriptions.
|
|
39
|
+
Nested objects and arrays are mapped to ``dict`` / ``list`` respectively —
|
|
40
|
+
the framework passes them as raw JSON and the gate validates server-side.
|
|
41
|
+
"""
|
|
42
|
+
properties: dict[str, Any] = schema.get("properties", {})
|
|
43
|
+
required_fields: set[str] = set(schema.get("required", []))
|
|
44
|
+
|
|
45
|
+
field_definitions: dict[str, Any] = {}
|
|
46
|
+
|
|
47
|
+
for prop_name, prop_schema in properties.items():
|
|
48
|
+
python_type = resolve_type(prop_schema)
|
|
49
|
+
description = prop_schema.get("description", "")
|
|
50
|
+
default = prop_schema.get("default")
|
|
51
|
+
|
|
52
|
+
if prop_name in required_fields:
|
|
53
|
+
field_definitions[prop_name] = (
|
|
54
|
+
python_type,
|
|
55
|
+
FieldInfo(description=description),
|
|
56
|
+
)
|
|
57
|
+
else:
|
|
58
|
+
# Optional field — default to None if no default specified.
|
|
59
|
+
effective_default = default if default is not None else None
|
|
60
|
+
field_definitions[prop_name] = (
|
|
61
|
+
python_type | None,
|
|
62
|
+
FieldInfo(default=effective_default, description=description),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
# Sanitize the action_id into a valid Python class name.
|
|
66
|
+
model_name = (
|
|
67
|
+
"".join(part.capitalize() for part in action_id.replace("-", "_").split("_")) + "Input"
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
model: type[BaseModel] = create_model(model_name, **field_definitions)
|
|
71
|
+
return model
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def resolve_type(prop_schema: dict[str, Any]) -> type:
|
|
75
|
+
"""Map a JSON Schema property to a Python type."""
|
|
76
|
+
json_type = prop_schema.get("type", "string")
|
|
77
|
+
|
|
78
|
+
# Handle union types like ["string", "null"] — take the first non-null.
|
|
79
|
+
if isinstance(json_type, list):
|
|
80
|
+
for t in json_type:
|
|
81
|
+
if t != "null" and t in JSON_TYPE_MAP:
|
|
82
|
+
return JSON_TYPE_MAP[t]
|
|
83
|
+
return str
|
|
84
|
+
|
|
85
|
+
return JSON_TYPE_MAP.get(json_type, str)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Result serialization for model-facing output.
|
|
2
|
+
|
|
3
|
+
Only the action output is returned to the model. Receipt and trace
|
|
4
|
+
metadata are logged at INFO level for orchestrator consumption —
|
|
5
|
+
exposing them in the model context would leak enforcement internals
|
|
6
|
+
to a potentially compromised model.
|
|
7
|
+
|
|
8
|
+
This is security-critical: every integration package must use this
|
|
9
|
+
single implementation to ensure consistent redaction.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import logging
|
|
16
|
+
from typing import TYPE_CHECKING
|
|
17
|
+
|
|
18
|
+
from latchgate_common.audit import AuditCallback, AuditRecord
|
|
19
|
+
|
|
20
|
+
if TYPE_CHECKING:
|
|
21
|
+
from latchgate import ActionResult
|
|
22
|
+
|
|
23
|
+
logger = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def serialize_result(
|
|
27
|
+
result: ActionResult,
|
|
28
|
+
*,
|
|
29
|
+
action_id: str = "",
|
|
30
|
+
on_audit: AuditCallback | None = None,
|
|
31
|
+
) -> str:
|
|
32
|
+
"""Serialize an ActionResult to a JSON string for the model.
|
|
33
|
+
|
|
34
|
+
Returns only ``result.output``. Receipt ID, trace ID, and verification
|
|
35
|
+
are emitted via structured log at INFO level — never in the return value.
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
result:
|
|
40
|
+
The execution result from LatchGate.
|
|
41
|
+
action_id:
|
|
42
|
+
The action that produced this result (for audit context).
|
|
43
|
+
on_audit:
|
|
44
|
+
Optional callback invoked with the audit metadata. Called
|
|
45
|
+
*after* serialization, does not affect the return value.
|
|
46
|
+
"""
|
|
47
|
+
logger.info(
|
|
48
|
+
"action completed: receipt_id=%s trace_id=%s verification=%s",
|
|
49
|
+
result.receipt_id,
|
|
50
|
+
result.trace_id,
|
|
51
|
+
result.verification,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
if on_audit is not None:
|
|
55
|
+
on_audit(
|
|
56
|
+
AuditRecord(
|
|
57
|
+
action_id=action_id,
|
|
58
|
+
receipt_id=result.receipt_id,
|
|
59
|
+
trace_id=result.trace_id,
|
|
60
|
+
verification=result.verification,
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
return json.dumps(result.output, default=str, ensure_ascii=False)
|
latchgate_common/sync.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Sync-to-async bridge for LatchGate framework integrations.
|
|
2
|
+
|
|
3
|
+
Provides a safe way to call async LatchGate operations from synchronous
|
|
4
|
+
code, including inside a running event loop (Jupyter, FastAPI, Celery).
|
|
5
|
+
|
|
6
|
+
The previous approach used ``nest_asyncio.apply()`` which monkey-patches
|
|
7
|
+
the running event loop globally. This caused subtle reentrancy bugs and
|
|
8
|
+
introduced a hidden global side-effect. The background-thread approach
|
|
9
|
+
here is isolated: each sync call gets its own event loop on a daemon
|
|
10
|
+
thread, with no mutation of the caller's loop.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import asyncio
|
|
16
|
+
import threading
|
|
17
|
+
from collections.abc import Coroutine
|
|
18
|
+
from concurrent.futures import Future
|
|
19
|
+
from typing import Any, TypeVar
|
|
20
|
+
|
|
21
|
+
T = TypeVar("T")
|
|
22
|
+
|
|
23
|
+
_DEFAULT_TIMEOUT_SECONDS: float = 120.0
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def run_sync(coro: Coroutine[Any, Any, T], *, timeout: float = _DEFAULT_TIMEOUT_SECONDS) -> T:
|
|
27
|
+
"""Run an async coroutine from synchronous context.
|
|
28
|
+
|
|
29
|
+
Behaviour:
|
|
30
|
+
|
|
31
|
+
- **No running loop** — delegates to ``asyncio.run()``.
|
|
32
|
+
- **Running loop detected** — spawns a daemon thread with its own
|
|
33
|
+
event loop, runs the coroutine there, and blocks until completion.
|
|
34
|
+
No global side-effects, no monkey-patching.
|
|
35
|
+
|
|
36
|
+
Parameters
|
|
37
|
+
----------
|
|
38
|
+
coro:
|
|
39
|
+
The coroutine to execute.
|
|
40
|
+
timeout:
|
|
41
|
+
Maximum seconds to wait for the background thread to complete.
|
|
42
|
+
Only applies when a running event loop forces the background-thread
|
|
43
|
+
path. Default: 120s.
|
|
44
|
+
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
The coroutine's return value.
|
|
48
|
+
|
|
49
|
+
Raises
|
|
50
|
+
------
|
|
51
|
+
TimeoutError
|
|
52
|
+
If the background thread does not complete within ``timeout``.
|
|
53
|
+
Exception
|
|
54
|
+
Any exception raised by the coroutine is re-raised in the
|
|
55
|
+
calling thread.
|
|
56
|
+
"""
|
|
57
|
+
try:
|
|
58
|
+
asyncio.get_running_loop()
|
|
59
|
+
except RuntimeError:
|
|
60
|
+
# No running loop — fast path.
|
|
61
|
+
return asyncio.run(coro)
|
|
62
|
+
|
|
63
|
+
# Inside a running loop — run in a background thread to avoid
|
|
64
|
+
# blocking the caller's loop or requiring nest_asyncio.
|
|
65
|
+
future: Future[T] = Future()
|
|
66
|
+
|
|
67
|
+
def _run_in_thread() -> None:
|
|
68
|
+
try:
|
|
69
|
+
result = asyncio.run(coro)
|
|
70
|
+
future.set_result(result)
|
|
71
|
+
except BaseException as exc:
|
|
72
|
+
future.set_exception(exc)
|
|
73
|
+
|
|
74
|
+
thread = threading.Thread(target=_run_in_thread, daemon=True)
|
|
75
|
+
thread.start()
|
|
76
|
+
thread.join(timeout=timeout)
|
|
77
|
+
|
|
78
|
+
if thread.is_alive():
|
|
79
|
+
raise TimeoutError(
|
|
80
|
+
f"LatchGate operation did not complete within {timeout}s. "
|
|
81
|
+
f"The background thread is still running — this usually "
|
|
82
|
+
f"indicates a hung network call or unresponsive gate."
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
return future.result()
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""Discovery transport resolution for LatchGate integrations.
|
|
2
|
+
|
|
3
|
+
Resolves the gate URL and optional HTTP transport used during
|
|
4
|
+
action discovery. Supports explicit URLs, the ``LATCHGATE_URL``
|
|
5
|
+
environment variable, and UDS transport reuse from a pre-configured
|
|
6
|
+
:class:`LatchGateClient`.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
from typing import TYPE_CHECKING
|
|
13
|
+
|
|
14
|
+
import httpx
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from latchgate import LatchGateClient
|
|
18
|
+
|
|
19
|
+
# Server's default public_base_url — used for DPoP htu when no explicit
|
|
20
|
+
# gate_url is configured. Must match ListenerConfig::default() in
|
|
21
|
+
# crates/latchgate-config/src/listener.rs.
|
|
22
|
+
DEFAULT_PUBLIC_BASE_URL = "http://localhost:3000"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def resolve_discovery_params(
|
|
26
|
+
gate_url: str | None,
|
|
27
|
+
client: LatchGateClient | None,
|
|
28
|
+
) -> tuple[str, httpx.AsyncClient | None]:
|
|
29
|
+
"""Resolve the gate URL and optional HTTP transport for discovery.
|
|
30
|
+
|
|
31
|
+
Returns ``(url, http_client_or_none)``. When a pre-configured
|
|
32
|
+
:class:`LatchGateClient` is provided and no explicit ``gate_url`` is
|
|
33
|
+
given, the client's internal ``httpx.AsyncClient`` (which may be
|
|
34
|
+
configured for UDS transport) is reused for discovery.
|
|
35
|
+
|
|
36
|
+
Raises
|
|
37
|
+
------
|
|
38
|
+
ValueError
|
|
39
|
+
If no usable gate URL can be determined from the arguments
|
|
40
|
+
or the environment.
|
|
41
|
+
"""
|
|
42
|
+
if gate_url is not None:
|
|
43
|
+
return gate_url, None
|
|
44
|
+
|
|
45
|
+
env_url = os.environ.get("LATCHGATE_URL")
|
|
46
|
+
if env_url:
|
|
47
|
+
return env_url, None
|
|
48
|
+
|
|
49
|
+
# Use the client's own transport for discovery (supports UDS).
|
|
50
|
+
if client is not None:
|
|
51
|
+
url = getattr(client, "gate_url", None)
|
|
52
|
+
if not url:
|
|
53
|
+
raise ValueError(
|
|
54
|
+
"gate_url is required. The provided client has no gate_url. "
|
|
55
|
+
"Provide gate_url explicitly or set the LATCHGATE_URL "
|
|
56
|
+
"environment variable."
|
|
57
|
+
)
|
|
58
|
+
return url, client.http_transport
|
|
59
|
+
|
|
60
|
+
raise ValueError(
|
|
61
|
+
"gate_url is required. Provide it explicitly, pass a client, "
|
|
62
|
+
"or set the LATCHGATE_URL environment variable."
|
|
63
|
+
)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: latchgate-integrations-common
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Shared discovery, schema, serialization, and transport logic for LatchGate framework integrations
|
|
5
|
+
Project-URL: Homepage, https://github.com/latchgate-ai/latchgate-integrations
|
|
6
|
+
Project-URL: Repository, https://github.com/latchgate-ai/latchgate-integrations
|
|
7
|
+
Author: latchgate-ai
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: ai-agents,execution-security,latchgate,security
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Security
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: httpx<1,>=0.27.0
|
|
24
|
+
Requires-Dist: latchgate>=0.1.0
|
|
25
|
+
Requires-Dist: pydantic<3,>=2.0.0
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# latchgate-integrations-common
|
|
29
|
+
|
|
30
|
+
Shared discovery, schema conversion, serialization, and transport logic for [LatchGate](https://github.com/latchgate-ai/latchgate) framework integrations.
|
|
31
|
+
|
|
32
|
+
This package is an **internal dependency** — not a public SDK. It provides the canonical implementation of security-relevant code used by:
|
|
33
|
+
|
|
34
|
+
- [`latchgate-langchain`](../langchain/)
|
|
35
|
+
- [`latchgate-crewai`](../crewai/)
|
|
36
|
+
- [`latchgate-openai-agents`](../openai-agents/)
|
|
37
|
+
- [`latchgate-pydantic-ai`](../pydantic/)
|
|
38
|
+
|
|
39
|
+
## Modules
|
|
40
|
+
|
|
41
|
+
| Module | Responsibility |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `discovery` | Action registry fetch, `expose_security_details` redaction |
|
|
44
|
+
| `schema` | JSON Schema → Pydantic model conversion |
|
|
45
|
+
| `serialization` | Output-only result filtering (strips receipt/trace/verification) |
|
|
46
|
+
| `transport` | Gate URL + UDS transport resolution |
|
|
47
|
+
| `audit` | `AuditRecord` dataclass and `AuditCallback` protocol |
|
|
48
|
+
| `sync` | Sync-to-async bridge via background thread (no `nest_asyncio`) |
|
|
49
|
+
|
|
50
|
+
## Why a separate package?
|
|
51
|
+
|
|
52
|
+
Every function in this package is security-relevant. Duplicating it across framework adapters meant a fix in one copy could be missed in another. A single implementation eliminates drift.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
latchgate_common/__init__.py,sha256=LRaZLH2rm_I0hexqXMP3C3gmFr_dLf9-_uY_qYhM-ik,1347
|
|
2
|
+
latchgate_common/audit.py,sha256=FSHEZ5lxpcod3gdc6snx7Vmct7BZjNU_uW1XzRnz86s,1113
|
|
3
|
+
latchgate_common/discovery.py,sha256=UdrpNYlaoGfnGgWx3_TGiH16rLvEip8jVSTimxQiXZ8,10373
|
|
4
|
+
latchgate_common/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
latchgate_common/schema.py,sha256=eob4kkXgEm5yB9vXur4mi9n63qo2KBKCoIGeooah-wQ,3129
|
|
6
|
+
latchgate_common/serialization.py,sha256=cfRjk-KNpS6bzFRWx8c8vZtHwQMqxY33k7tHLyoW0XM,1866
|
|
7
|
+
latchgate_common/sync.py,sha256=1Fn1UnLGHlu4qxkSOfBuM9NBr5hf8tj18ja4X9LESrw,2681
|
|
8
|
+
latchgate_common/transport.py,sha256=R96Lmc9saWYK7M6MqLGgeaeK4cILFgMj9i4N4XXNmhI,2042
|
|
9
|
+
latchgate_integrations_common-0.1.0.dist-info/METADATA,sha256=ATuSj2ZFxl4_DYc9-ZIJ46WpyXRCaGpNJUC1_aYWMQU,2332
|
|
10
|
+
latchgate_integrations_common-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
11
|
+
latchgate_integrations_common-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
12
|
+
latchgate_integrations_common-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
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
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and 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
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|