Add TEE attestation and data settlement metadata to LLM responses#7
Merged
adambalogh merged 1 commit intomainfrom May 5, 2026
Merged
Conversation
Brings the TS SDK's LLM response surface in line with the Python SDK. - TextGenerationOutput: replace `transactionHash` with the Python field set — `dataSettlementTransactionHash`, `dataSettlementBlobId`, `chatOutput`, `completionOutput`, `usage`, `paymentHash`, `teeSignature`, `teeTimestamp`, `teeId`, `teeEndpoint`, `teePaymentAddress`, `finishReason`. - StreamChunk: add TEE attestation and data settlement fields populated on the final chunk; rename `is_final` to `isFinal`. SSE parser now handles servers that send the non-streaming `message` key in a delta event (mirrors Python's `from_sse_data`). - X402SettlementMode: align enum values with the wire protocol used by the Python SDK (`private` / `batch` / `individual`). - TEE_LLM: refresh the model list (GPT-5 family, Claude Sonnet/Haiku/ Opus 4.5+, Gemini 3, Grok 4 family, ByteDance Seed). - Add `ResponseFormat` type with json_object/json_schema enforcement (and the Anthropic + json_object guard from the Python SDK). - llm.ts: read x-settlement-tx-hash and x-settlement-walrus-blob-id response headers; flatten Anthropic content-block arrays; fall back to non-streaming for tool-call requests and emit a single final StreamChunk; only retry on connection-level failures (preserve the HTTP-status no-retry rule). - teeConnection.ts: dedupe concurrent reconnect() calls and guard the refresh loop after close.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR enhances the LLM client to include TEE (Trusted Execution Environment) attestation fields and data settlement metadata in all responses. It also updates the settlement mode enum to reflect the current protocol, adds support for response format control, and improves streaming reliability for tool-call requests.
Key Changes
TEE Attestation Fields: All responses now include
teeSignature,teeTimestamp,teeId,teeEndpoint, andteePaymentAddressto cryptographically verify inference was performed inside a TEE enclave.Data Settlement Metadata: Responses now carry
dataSettlementTransactionHashanddataSettlementBlobIdheaders extracted from the server response, enabling auditability of inference data settlement.Settlement Mode Enum Update: Renamed settlement modes to match current protocol:
SETTLE→PRIVATE(payment-only, no on-chain data)SETTLE_BATCH→BATCH_HASHED(default, aggregated batch settlement)SETTLE_METADATA→INDIVIDUAL_FULL(full on-chain metadata)Response Format Support: Added
ResponseFormatinterface and validation to supportjson_objectandjson_schemaoutput formats, with provider-specific validation (e.g., rejectingjson_objectfor Anthropic models).Tool-Call Streaming Fallback: Implemented
chatToolsAsStream()to handle tool-call requests by falling back to non-streaming mode and emitting a single final chunk, matching Python SDK behavior.Streaming Improvements:
messagekey instead ofdelta[DONE]marker to ensure all metadata is availableTokenUsagetype for consistent token reporting across streaming and non-streaming responsesModel Catalog Updates: Updated
TEE_LLMenum with latest model versions across OpenAI, Anthropic, Google, xAI, and added ByteDance Seed models.Connection Management: Enhanced
RegistryTEEConnectionwith deduplication of concurrent reconnect attempts and proper cleanup on close.Notable Implementation Details
jsonSchemais provided whentype: "json_schema"is specifiedBATCH_HASHEDfor cost efficiencyhttps://claude.ai/code/session_01BE3dkcPw4jbUrrZN3cizCh