|
| 1 | +# Sentience API Specification |
| 2 | + |
| 3 | +This directory contains the **single source of truth** for the API contract between the Chrome extension and SDKs. |
| 4 | + |
| 5 | +## Files |
| 6 | + |
| 7 | +- **`snapshot.schema.json`** - JSON Schema for snapshot response validation |
| 8 | +- **`SNAPSHOT_V1.md`** - Human-readable snapshot API contract |
| 9 | +- **`sdk-types.md`** - SDK-level type definitions (ActionResult, WaitResult, TraceStep) |
| 10 | + |
| 11 | +## Purpose |
| 12 | + |
| 13 | +These specifications ensure: |
| 14 | +1. **Consistency**: Both Python and TypeScript SDKs implement the same contract |
| 15 | +2. **Validation**: SDKs can validate extension responses |
| 16 | +3. **Type Safety**: Strong typing in both languages |
| 17 | +4. **Documentation**: Clear reference for developers |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +### For SDK Developers |
| 22 | + |
| 23 | +1. **Read** `SNAPSHOT_V1.md` for human-readable contract |
| 24 | +2. **Use** `snapshot.schema.json` for JSON Schema validation |
| 25 | +3. **Reference** `sdk-types.md` for SDK-level types |
| 26 | + |
| 27 | +### For Extension Developers |
| 28 | + |
| 29 | +1. **Ensure** extension output matches `snapshot.schema.json` |
| 30 | +2. **Update** schema when adding new fields |
| 31 | +3. **Version** schema for breaking changes |
| 32 | + |
| 33 | +## Versioning |
| 34 | + |
| 35 | +- **v1.0.0**: Initial stable version (Day 1) |
| 36 | +- Future versions: Increment major version for breaking changes |
| 37 | +- SDKs should validate version and handle compatibility |
| 38 | + |
| 39 | +## Validation |
| 40 | + |
| 41 | +Both SDKs should validate extension responses: |
| 42 | + |
| 43 | +**Python**: |
| 44 | +```python |
| 45 | +import jsonschema |
| 46 | +from spec.snapshot.schema import load_schema |
| 47 | + |
| 48 | +schema = load_schema() |
| 49 | +jsonschema.validate(snapshot_data, schema) |
| 50 | +``` |
| 51 | + |
| 52 | +**TypeScript**: |
| 53 | +```typescript |
| 54 | +import Ajv from 'ajv'; |
| 55 | +import schema from './spec/snapshot.schema.json'; |
| 56 | + |
| 57 | +const ajv = new Ajv(); |
| 58 | +const validate = ajv.compile(schema); |
| 59 | +validate(snapshot_data); |
| 60 | +``` |
| 61 | + |
| 62 | +## Testing |
| 63 | + |
| 64 | +- Validate against real extension output |
| 65 | +- Test with edge cases (empty pages, many elements, errors) |
| 66 | +- Verify type coercion and defaults |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +**Last Updated**: Day 1 Implementation |
| 71 | +**Status**: ✅ Stable |
| 72 | + |
0 commit comments