@hailer/mcp 0.0.1

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 (163) hide show
  1. package/.claude/commands/tool-builder.md +37 -0
  2. package/.claude/commands/ws-pull.md +44 -0
  3. package/.claude/settings.json +8 -0
  4. package/.claude/settings.local.json +49 -0
  5. package/.claude/skills/activity-api/SKILL.md +96 -0
  6. package/.claude/skills/activity-api/references/activity-endpoints.md +845 -0
  7. package/.claude/skills/add-app-member-skill/SKILL.md +977 -0
  8. package/.claude/skills/agent-building/SKILL.md +243 -0
  9. package/.claude/skills/agent-building/references/architecture-patterns.md +446 -0
  10. package/.claude/skills/agent-building/references/code-examples.md +587 -0
  11. package/.claude/skills/agent-building/references/implementation-guide.md +619 -0
  12. package/.claude/skills/app-api/SKILL.md +219 -0
  13. package/.claude/skills/app-api/references/app-endpoints.md +759 -0
  14. package/.claude/skills/building-hailer-apps-skill/SKILL.md +548 -0
  15. package/.claude/skills/create-app-skill/SKILL.md +1101 -0
  16. package/.claude/skills/create-insight-skill/SKILL.md +1317 -0
  17. package/.claude/skills/get-insight-data-skill/SKILL.md +1053 -0
  18. package/.claude/skills/hailer-api/SKILL.md +283 -0
  19. package/.claude/skills/hailer-api/references/activities.md +620 -0
  20. package/.claude/skills/hailer-api/references/authentication.md +216 -0
  21. package/.claude/skills/hailer-api/references/datasets.md +437 -0
  22. package/.claude/skills/hailer-api/references/files.md +301 -0
  23. package/.claude/skills/hailer-api/references/insights.md +469 -0
  24. package/.claude/skills/hailer-api/references/workflows.md +720 -0
  25. package/.claude/skills/hailer-api/references/workspaces-users.md +445 -0
  26. package/.claude/skills/insight-api/SKILL.md +185 -0
  27. package/.claude/skills/insight-api/references/insight-endpoints.md +514 -0
  28. package/.claude/skills/install-workflow-skill/SKILL.md +1056 -0
  29. package/.claude/skills/list-apps-skill/SKILL.md +1010 -0
  30. package/.claude/skills/list-workflows-minimal-skill/SKILL.md +992 -0
  31. package/.claude/skills/local-first-skill/SKILL.md +570 -0
  32. package/.claude/skills/mcp-tools/SKILL.md +419 -0
  33. package/.claude/skills/mcp-tools/references/api-endpoints.md +499 -0
  34. package/.claude/skills/mcp-tools/references/data-structures.md +554 -0
  35. package/.claude/skills/mcp-tools/references/implementation-patterns.md +717 -0
  36. package/.claude/skills/preview-insight-skill/SKILL.md +1290 -0
  37. package/.claude/skills/publish-hailer-app-skill/SKILL.md +453 -0
  38. package/.claude/skills/remove-app-member-skill/SKILL.md +671 -0
  39. package/.claude/skills/remove-app-skill/SKILL.md +985 -0
  40. package/.claude/skills/remove-insight-skill/SKILL.md +1011 -0
  41. package/.claude/skills/remove-workflow-skill/SKILL.md +920 -0
  42. package/.claude/skills/scaffold-hailer-app-skill/SKILL.md +1034 -0
  43. package/.claude/skills/skill-testing/README.md +137 -0
  44. package/.claude/skills/skill-testing/SKILL.md +348 -0
  45. package/.claude/skills/skill-testing/references/test-patterns.md +705 -0
  46. package/.claude/skills/skill-testing/references/testing-guide.md +603 -0
  47. package/.claude/skills/skill-testing/references/validation-checklist.md +537 -0
  48. package/.claude/skills/tool-builder/SKILL.md +328 -0
  49. package/.claude/skills/update-app-skill/SKILL.md +970 -0
  50. package/.claude/skills/update-workflow-field-skill/SKILL.md +1098 -0
  51. package/.env.example +81 -0
  52. package/.mcp.json +13 -0
  53. package/README.md +297 -0
  54. package/dist/app.d.ts +4 -0
  55. package/dist/app.js +74 -0
  56. package/dist/cli.d.ts +3 -0
  57. package/dist/cli.js +5 -0
  58. package/dist/client/adaptive-documentation-bot.d.ts +108 -0
  59. package/dist/client/adaptive-documentation-bot.js +475 -0
  60. package/dist/client/adaptive-documentation-types.d.ts +66 -0
  61. package/dist/client/adaptive-documentation-types.js +9 -0
  62. package/dist/client/agent-activity-bot.d.ts +51 -0
  63. package/dist/client/agent-activity-bot.js +166 -0
  64. package/dist/client/agent-tracker.d.ts +499 -0
  65. package/dist/client/agent-tracker.js +659 -0
  66. package/dist/client/description-updater.d.ts +56 -0
  67. package/dist/client/description-updater.js +259 -0
  68. package/dist/client/log-parser.d.ts +72 -0
  69. package/dist/client/log-parser.js +387 -0
  70. package/dist/client/mcp-client.d.ts +50 -0
  71. package/dist/client/mcp-client.js +532 -0
  72. package/dist/client/message-processor.d.ts +35 -0
  73. package/dist/client/message-processor.js +352 -0
  74. package/dist/client/multi-bot-manager.d.ts +24 -0
  75. package/dist/client/multi-bot-manager.js +74 -0
  76. package/dist/client/providers/anthropic-provider.d.ts +19 -0
  77. package/dist/client/providers/anthropic-provider.js +631 -0
  78. package/dist/client/providers/llm-provider.d.ts +47 -0
  79. package/dist/client/providers/llm-provider.js +367 -0
  80. package/dist/client/providers/openai-provider.d.ts +23 -0
  81. package/dist/client/providers/openai-provider.js +621 -0
  82. package/dist/client/simple-llm-caller.d.ts +19 -0
  83. package/dist/client/simple-llm-caller.js +100 -0
  84. package/dist/client/skill-generator.d.ts +81 -0
  85. package/dist/client/skill-generator.js +386 -0
  86. package/dist/client/test-adaptive-bot.d.ts +9 -0
  87. package/dist/client/test-adaptive-bot.js +82 -0
  88. package/dist/client/token-pricing.d.ts +38 -0
  89. package/dist/client/token-pricing.js +127 -0
  90. package/dist/client/token-tracker.d.ts +232 -0
  91. package/dist/client/token-tracker.js +457 -0
  92. package/dist/client/token-usage-bot.d.ts +53 -0
  93. package/dist/client/token-usage-bot.js +153 -0
  94. package/dist/client/tool-executor.d.ts +69 -0
  95. package/dist/client/tool-executor.js +159 -0
  96. package/dist/client/tool-schema-loader.d.ts +60 -0
  97. package/dist/client/tool-schema-loader.js +178 -0
  98. package/dist/client/types.d.ts +69 -0
  99. package/dist/client/types.js +7 -0
  100. package/dist/config.d.ts +162 -0
  101. package/dist/config.js +296 -0
  102. package/dist/core.d.ts +26 -0
  103. package/dist/core.js +147 -0
  104. package/dist/lib/context-manager.d.ts +111 -0
  105. package/dist/lib/context-manager.js +431 -0
  106. package/dist/lib/logger.d.ts +74 -0
  107. package/dist/lib/logger.js +277 -0
  108. package/dist/lib/materialize.d.ts +3 -0
  109. package/dist/lib/materialize.js +101 -0
  110. package/dist/lib/normalizedName.d.ts +7 -0
  111. package/dist/lib/normalizedName.js +48 -0
  112. package/dist/lib/prompt-length-manager.d.ts +81 -0
  113. package/dist/lib/prompt-length-manager.js +457 -0
  114. package/dist/lib/terminal-prompt.d.ts +9 -0
  115. package/dist/lib/terminal-prompt.js +108 -0
  116. package/dist/mcp/UserContextCache.d.ts +56 -0
  117. package/dist/mcp/UserContextCache.js +163 -0
  118. package/dist/mcp/auth.d.ts +2 -0
  119. package/dist/mcp/auth.js +29 -0
  120. package/dist/mcp/hailer-clients.d.ts +42 -0
  121. package/dist/mcp/hailer-clients.js +246 -0
  122. package/dist/mcp/signal-handler.d.ts +45 -0
  123. package/dist/mcp/signal-handler.js +317 -0
  124. package/dist/mcp/tool-registry.d.ts +100 -0
  125. package/dist/mcp/tool-registry.js +306 -0
  126. package/dist/mcp/tools/activity.d.ts +15 -0
  127. package/dist/mcp/tools/activity.js +955 -0
  128. package/dist/mcp/tools/app.d.ts +20 -0
  129. package/dist/mcp/tools/app.js +1488 -0
  130. package/dist/mcp/tools/discussion.d.ts +19 -0
  131. package/dist/mcp/tools/discussion.js +950 -0
  132. package/dist/mcp/tools/file.d.ts +15 -0
  133. package/dist/mcp/tools/file.js +119 -0
  134. package/dist/mcp/tools/insight.d.ts +17 -0
  135. package/dist/mcp/tools/insight.js +806 -0
  136. package/dist/mcp/tools/skill.d.ts +10 -0
  137. package/dist/mcp/tools/skill.js +279 -0
  138. package/dist/mcp/tools/user.d.ts +10 -0
  139. package/dist/mcp/tools/user.js +108 -0
  140. package/dist/mcp/tools/workflow-template.d.ts +19 -0
  141. package/dist/mcp/tools/workflow-template.js +822 -0
  142. package/dist/mcp/tools/workflow.d.ts +18 -0
  143. package/dist/mcp/tools/workflow.js +1362 -0
  144. package/dist/mcp/utils/api-errors.d.ts +45 -0
  145. package/dist/mcp/utils/api-errors.js +160 -0
  146. package/dist/mcp/utils/data-transformers.d.ts +102 -0
  147. package/dist/mcp/utils/data-transformers.js +194 -0
  148. package/dist/mcp/utils/file-upload.d.ts +33 -0
  149. package/dist/mcp/utils/file-upload.js +148 -0
  150. package/dist/mcp/utils/hailer-api-client.d.ts +120 -0
  151. package/dist/mcp/utils/hailer-api-client.js +323 -0
  152. package/dist/mcp/utils/index.d.ts +13 -0
  153. package/dist/mcp/utils/index.js +39 -0
  154. package/dist/mcp/utils/logger.d.ts +42 -0
  155. package/dist/mcp/utils/logger.js +103 -0
  156. package/dist/mcp/utils/types.d.ts +286 -0
  157. package/dist/mcp/utils/types.js +7 -0
  158. package/dist/mcp/workspace-cache.d.ts +42 -0
  159. package/dist/mcp/workspace-cache.js +97 -0
  160. package/dist/mcp-server.d.ts +42 -0
  161. package/dist/mcp-server.js +280 -0
  162. package/package.json +56 -0
  163. package/tsconfig.json +23 -0
@@ -0,0 +1,216 @@
1
+ # Hailer Authentication & Core API
2
+
3
+ ## Authentication Methods
4
+
5
+ ### 1. Access Token Authentication
6
+ ```bash
7
+ curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
8
+ https://api.hailer.local.gd/v3/activities
9
+ ```
10
+
11
+ ### 2. Session-based Authentication
12
+ ```python
13
+ import requests
14
+
15
+ session = requests.Session()
16
+ session.post('https://api.hailer.local.gd/v3/auth/login',
17
+ json={'email': 'user@example.com', 'password': 'password'})
18
+
19
+ # Session cookie is now stored
20
+ response = session.get('https://api.hailer.local.gd/v3/activities')
21
+ ```
22
+
23
+ ### 3. OAuth 2.0 (Recommended for Apps)
24
+ - Authorization endpoint: `/oauth/authorize`
25
+ - Token endpoint: `/oauth/token`
26
+ - Supports authorization code and client credentials flows
27
+
28
+ ## API Base URLs
29
+
30
+ - **Production**: `https://api.hailer.local.gd`
31
+ - **API Version**: `/v3` (current, with some `/v2` endpoints)
32
+ - **Full base**: `https://api.hailer.local.gd/v3`
33
+
34
+ ## Request Headers
35
+
36
+ ```http
37
+ Authorization: Bearer {access_token}
38
+ Content-Type: application/json
39
+ Accept: application/json
40
+ ```
41
+
42
+ ## Response Format
43
+
44
+ All responses are JSON with standard structure:
45
+
46
+ ### Success Response
47
+ ```json
48
+ {
49
+ "data": { /* resource data */ },
50
+ "meta": {
51
+ "page": 1,
52
+ "per_page": 50,
53
+ "total": 150
54
+ }
55
+ }
56
+ ```
57
+
58
+ ### Error Response
59
+ ```json
60
+ {
61
+ "error": {
62
+ "code": "validation_error",
63
+ "message": "Invalid field value",
64
+ "details": {
65
+ "field": "email",
66
+ "issue": "Email format is invalid"
67
+ }
68
+ }
69
+ }
70
+ ```
71
+
72
+ ## Common HTTP Status Codes
73
+
74
+ - `200 OK` - Request successful
75
+ - `201 Created` - Resource created successfully
76
+ - `204 No Content` - Success with no response body
77
+ - `400 Bad Request` - Invalid request parameters
78
+ - `401 Unauthorized` - Authentication required or failed
79
+ - `403 Forbidden` - Insufficient permissions
80
+ - `404 Not Found` - Resource does not exist
81
+ - `422 Unprocessable Entity` - Validation error
82
+ - `429 Too Many Requests` - Rate limit exceeded
83
+ - `500 Internal Server Error` - Server error
84
+
85
+ ## Rate Limiting
86
+
87
+ - Default: 1000 requests per hour per user
88
+ - Headers returned:
89
+ - `X-RateLimit-Limit`: Total requests allowed
90
+ - `X-RateLimit-Remaining`: Requests remaining
91
+ - `X-RateLimit-Reset`: Unix timestamp when limit resets
92
+
93
+ ## Pagination
94
+
95
+ Most list endpoints support pagination:
96
+
97
+ ```http
98
+ GET /v3/activities?page=2&per_page=100
99
+ ```
100
+
101
+ Parameters:
102
+ - `page` - Page number (default: 1)
103
+ - `per_page` - Items per page (default: 50, max: 100)
104
+
105
+ Response includes:
106
+ ```json
107
+ {
108
+ "data": [...],
109
+ "meta": {
110
+ "page": 2,
111
+ "per_page": 100,
112
+ "total": 523,
113
+ "total_pages": 6
114
+ }
115
+ }
116
+ ```
117
+
118
+ ## Filtering & Sorting
119
+
120
+ ### Filtering
121
+ ```http
122
+ GET /v3/activities?filter[status]=open&filter[priority]=high
123
+ ```
124
+
125
+ ### Sorting
126
+ ```http
127
+ GET /v3/activities?sort=-created_at,priority
128
+ ```
129
+ - Prefix with `-` for descending order
130
+ - Multiple sort fields comma-separated
131
+
132
+ ## Field Selection
133
+
134
+ Request specific fields only:
135
+ ```http
136
+ GET /v3/activities?fields=id,title,status,created_at
137
+ ```
138
+
139
+ ## Batch Operations
140
+
141
+ Some endpoints support batch operations:
142
+
143
+ ```json
144
+ POST /v3/activities/batch
145
+ {
146
+ "operations": [
147
+ {
148
+ "method": "POST",
149
+ "path": "/v3/activities",
150
+ "body": { "title": "Task 1" }
151
+ },
152
+ {
153
+ "method": "PATCH",
154
+ "path": "/v3/activities/123",
155
+ "body": { "status": "completed" }
156
+ }
157
+ ]
158
+ }
159
+ ```
160
+
161
+ ## Webhooks
162
+
163
+ Subscribe to events:
164
+
165
+ ```json
166
+ POST /v3/webhooks
167
+ {
168
+ "url": "https://your-server.com/webhook",
169
+ "events": ["activity.created", "activity.updated"],
170
+ "active": true
171
+ }
172
+ ```
173
+
174
+ Event payload:
175
+ ```json
176
+ {
177
+ "event": "activity.created",
178
+ "data": { /* activity object */ },
179
+ "timestamp": "2025-01-15T10:30:00Z",
180
+ "workspace_id": "ws_123"
181
+ }
182
+ ```
183
+
184
+ ## Error Handling Best Practices
185
+
186
+ ```python
187
+ try:
188
+ response = requests.get(
189
+ 'https://api.hailer.local.gd/v3/activities',
190
+ headers={'Authorization': f'Bearer {token}'},
191
+ timeout=30
192
+ )
193
+ response.raise_for_status()
194
+ data = response.json()
195
+ except requests.exceptions.Timeout:
196
+ # Handle timeout
197
+ pass
198
+ except requests.exceptions.HTTPError as e:
199
+ if e.response.status_code == 401:
200
+ # Re-authenticate
201
+ pass
202
+ elif e.response.status_code == 429:
203
+ # Back off and retry
204
+ pass
205
+ else:
206
+ # Handle other errors
207
+ pass
208
+ ```
209
+
210
+ ## API Versioning
211
+
212
+ - Current version: v3 (with some v2 endpoints still in use)
213
+ - Version specified in URL path
214
+ - Old versions supported for 12 months after new version release
215
+ - Breaking changes only in new versions
216
+ - Deprecation warnings sent via email and in response headers
@@ -0,0 +1,437 @@
1
+ # Hailer Datasets API
2
+
3
+ ## Overview
4
+
5
+ Datasets in Hailer provide structured storage for tabular data with type validation, relationships, and SQL querying capabilities.
6
+
7
+ ## Dataset Structure
8
+
9
+ A dataset is a collection of records with defined fields (columns):
10
+
11
+ ```json
12
+ {
13
+ "id": "dataset_123",
14
+ "name": "Customers",
15
+ "description": "Customer master data",
16
+ "fields": [
17
+ {
18
+ "name": "company_name",
19
+ "type": "text",
20
+ "required": true
21
+ },
22
+ {
23
+ "name": "revenue",
24
+ "type": "number",
25
+ "required": false
26
+ },
27
+ {
28
+ "name": "created_at",
29
+ "type": "datetime",
30
+ "required": true
31
+ }
32
+ ],
33
+ "workspace_id": "ws_456",
34
+ "record_count": 1523
35
+ }
36
+ ```
37
+
38
+ ## Field Types
39
+
40
+ - `text` - String values
41
+ - `number` - Numeric values (integer or decimal)
42
+ - `boolean` - True/false values
43
+ - `datetime` - ISO 8601 timestamps
44
+ - `date` - Date only (YYYY-MM-DD)
45
+ - `reference` - Reference to another dataset record
46
+ - `user` - Reference to Hailer user
47
+ - `activity` - Reference to activity
48
+ - `file` - Reference to file
49
+ - `json` - Structured JSON data
50
+ - `array` - Array of values
51
+
52
+ ## Endpoints
53
+
54
+ ### Create Dataset
55
+
56
+ ```http
57
+ POST /v3/datasets
58
+ Content-Type: application/json
59
+
60
+ {
61
+ "name": "Customers",
62
+ "description": "Customer master data",
63
+ "workspace_id": "ws_456",
64
+ "fields": [
65
+ {
66
+ "name": "company_name",
67
+ "type": "text",
68
+ "required": true
69
+ },
70
+ {
71
+ "name": "contact_email",
72
+ "type": "text",
73
+ "required": false
74
+ },
75
+ {
76
+ "name": "annual_revenue",
77
+ "type": "number",
78
+ "required": false
79
+ }
80
+ ]
81
+ }
82
+ ```
83
+
84
+ ### Get Dataset
85
+
86
+ ```http
87
+ GET /v3/datasets/{dataset_id}
88
+ ```
89
+
90
+ ### Update Dataset
91
+
92
+ ```http
93
+ PATCH /v3/datasets/{dataset_id}
94
+ Content-Type: application/json
95
+
96
+ {
97
+ "name": "Updated Customer List",
98
+ "description": "New description"
99
+ }
100
+ ```
101
+
102
+ ### Delete Dataset
103
+
104
+ ```http
105
+ DELETE /v3/datasets/{dataset_id}
106
+ ```
107
+
108
+ ### List Datasets
109
+
110
+ ```http
111
+ GET /v3/datasets?workspace_id=ws_456
112
+ ```
113
+
114
+ ## Dataset Records
115
+
116
+ ### Create Record
117
+
118
+ ```http
119
+ POST /v3/datasets/{dataset_id}/records
120
+ Content-Type: application/json
121
+
122
+ {
123
+ "company_name": "Acme Corp",
124
+ "contact_email": "contact@acme.com",
125
+ "annual_revenue": 5000000
126
+ }
127
+ ```
128
+
129
+ **Response:**
130
+ ```json
131
+ {
132
+ "id": "rec_789",
133
+ "company_name": "Acme Corp",
134
+ "contact_email": "contact@acme.com",
135
+ "annual_revenue": 5000000,
136
+ "created_at": "2025-01-15T10:30:00Z",
137
+ "updated_at": "2025-01-15T10:30:00Z",
138
+ "created_by": {
139
+ "id": "user_123",
140
+ "name": "Johan Rekna"
141
+ }
142
+ }
143
+ ```
144
+
145
+ ### Get Record
146
+
147
+ ```http
148
+ GET /v3/datasets/{dataset_id}/records/{record_id}
149
+ ```
150
+
151
+ ### Update Record
152
+
153
+ ```http
154
+ PATCH /v3/datasets/{dataset_id}/records/{record_id}
155
+ Content-Type: application/json
156
+
157
+ {
158
+ "annual_revenue": 5500000
159
+ }
160
+ ```
161
+
162
+ ### Delete Record
163
+
164
+ ```http
165
+ DELETE /v3/datasets/{dataset_id}/records/{record_id}
166
+ ```
167
+
168
+ ### List Records
169
+
170
+ ```http
171
+ GET /v3/datasets/{dataset_id}/records?page=1&per_page=100
172
+ ```
173
+
174
+ **Query Parameters:**
175
+ - `page` - Page number
176
+ - `per_page` - Records per page (max 1000)
177
+ - `sort` - Sort field (e.g., `-created_at`)
178
+ - `filter[field_name]` - Filter by field value
179
+
180
+ **Example with filters:**
181
+ ```http
182
+ GET /v3/datasets/{dataset_id}/records?filter[annual_revenue]=>1000000&sort=-annual_revenue
183
+ ```
184
+
185
+ ## Batch Operations
186
+
187
+ ### Batch Create Records
188
+
189
+ ```http
190
+ POST /v3/datasets/{dataset_id}/records/batch
191
+ Content-Type: application/json
192
+
193
+ {
194
+ "records": [
195
+ {
196
+ "company_name": "Company 1",
197
+ "annual_revenue": 1000000
198
+ },
199
+ {
200
+ "company_name": "Company 2",
201
+ "annual_revenue": 2000000
202
+ }
203
+ ]
204
+ }
205
+ ```
206
+
207
+ **Response:**
208
+ ```json
209
+ {
210
+ "created": 2,
211
+ "failed": 0,
212
+ "records": [
213
+ {
214
+ "id": "rec_123",
215
+ "success": true
216
+ },
217
+ {
218
+ "id": "rec_124",
219
+ "success": true
220
+ }
221
+ ]
222
+ }
223
+ ```
224
+
225
+ ### Batch Update Records
226
+
227
+ ```http
228
+ PATCH /v3/datasets/{dataset_id}/records/batch
229
+ Content-Type: application/json
230
+
231
+ {
232
+ "records": [
233
+ {
234
+ "id": "rec_123",
235
+ "annual_revenue": 1100000
236
+ },
237
+ {
238
+ "id": "rec_124",
239
+ "annual_revenue": 2200000
240
+ }
241
+ ]
242
+ }
243
+ ```
244
+
245
+ ### Batch Delete Records
246
+
247
+ ```http
248
+ DELETE /v3/datasets/{dataset_id}/records/batch
249
+ Content-Type: application/json
250
+
251
+ {
252
+ "record_ids": ["rec_123", "rec_124", "rec_125"]
253
+ }
254
+ ```
255
+
256
+ ## SQL Queries
257
+
258
+ Query datasets using SQL through the Insights API:
259
+
260
+ ```http
261
+ POST /v3/insights/query
262
+ Content-Type: application/json
263
+
264
+ {
265
+ "sql": "SELECT company_name, annual_revenue FROM dataset_123 WHERE annual_revenue > 1000000 ORDER BY annual_revenue DESC",
266
+ "workspace_id": "ws_456"
267
+ }
268
+ ```
269
+
270
+ ### Available SQL Functions
271
+
272
+ **Aggregates:**
273
+ - `COUNT(*)`, `COUNT(field)`
274
+ - `SUM(field)`
275
+ - `AVG(field)`
276
+ - `MIN(field)`, `MAX(field)`
277
+
278
+ **String Functions:**
279
+ - `UPPER(field)`, `LOWER(field)`
280
+ - `LENGTH(field)`
281
+ - `SUBSTR(field, start, length)`
282
+ - `REPLACE(field, from, to)`
283
+
284
+ **Date Functions:**
285
+ - `DATE(field)` - Extract date
286
+ - `DATETIME(field)` - Convert to datetime
287
+ - `STRFTIME(format, field)` - Format date
288
+
289
+ **Example Complex Query:**
290
+ ```sql
291
+ SELECT
292
+ STRFTIME('%Y-%m', created_at) as month,
293
+ COUNT(*) as customer_count,
294
+ SUM(annual_revenue) as total_revenue,
295
+ AVG(annual_revenue) as avg_revenue
296
+ FROM dataset_123
297
+ WHERE created_at >= '2024-01-01'
298
+ GROUP BY month
299
+ ORDER BY month DESC
300
+ ```
301
+
302
+ ## Field Constraints
303
+
304
+ ### Validation Rules
305
+
306
+ ```http
307
+ PATCH /v3/datasets/{dataset_id}/fields/{field_name}
308
+ Content-Type: application/json
309
+
310
+ {
311
+ "validation": {
312
+ "type": "text",
313
+ "min_length": 3,
314
+ "max_length": 100,
315
+ "pattern": "^[A-Za-z0-9]+$"
316
+ }
317
+ }
318
+ ```
319
+
320
+ ### Reference Fields
321
+
322
+ Create relationships between datasets:
323
+
324
+ ```json
325
+ {
326
+ "name": "customer_id",
327
+ "type": "reference",
328
+ "reference_dataset_id": "dataset_123",
329
+ "required": true
330
+ }
331
+ ```
332
+
333
+ Query with references:
334
+ ```sql
335
+ SELECT
336
+ orders.id,
337
+ orders.amount,
338
+ customers.company_name
339
+ FROM dataset_orders AS orders
340
+ JOIN dataset_customers AS customers
341
+ ON orders.customer_id = customers.id
342
+ WHERE orders.amount > 10000
343
+ ```
344
+
345
+ ## Dataset Import/Export
346
+
347
+ ### Export Dataset
348
+
349
+ ```http
350
+ GET /v3/datasets/{dataset_id}/export?format=csv
351
+ GET /v3/datasets/{dataset_id}/export?format=json
352
+ GET /v3/datasets/{dataset_id}/export?format=xlsx
353
+ ```
354
+
355
+ **Response:** File download with appropriate Content-Type
356
+
357
+ ### Import from CSV
358
+
359
+ ```http
360
+ POST /v3/datasets/{dataset_id}/import
361
+ Content-Type: multipart/form-data
362
+
363
+ file: (CSV file)
364
+ options: {
365
+ "skip_header": true,
366
+ "delimiter": ",",
367
+ "update_existing": false
368
+ }
369
+ ```
370
+
371
+ **Response:**
372
+ ```json
373
+ {
374
+ "imported": 150,
375
+ "updated": 25,
376
+ "failed": 3,
377
+ "errors": [
378
+ {
379
+ "row": 45,
380
+ "error": "Invalid email format"
381
+ }
382
+ ]
383
+ }
384
+ ```
385
+
386
+ ## Dataset Permissions
387
+
388
+ Control who can access datasets:
389
+
390
+ ```http
391
+ POST /v3/datasets/{dataset_id}/permissions
392
+ Content-Type: application/json
393
+
394
+ {
395
+ "user_id": "user_123",
396
+ "role": "editor"
397
+ }
398
+ ```
399
+
400
+ **Roles:**
401
+ - `viewer` - Read-only access
402
+ - `editor` - Can create, update, delete records
403
+ - `admin` - Full control including dataset structure
404
+
405
+ ### List Permissions
406
+
407
+ ```http
408
+ GET /v3/datasets/{dataset_id}/permissions
409
+ ```
410
+
411
+ ## Webhooks for Datasets
412
+
413
+ Subscribe to dataset changes:
414
+
415
+ ```http
416
+ POST /v3/webhooks
417
+ {
418
+ "url": "https://your-server.com/webhook",
419
+ "events": [
420
+ "dataset.record.created",
421
+ "dataset.record.updated",
422
+ "dataset.record.deleted"
423
+ ],
424
+ "dataset_id": "dataset_123"
425
+ }
426
+ ```
427
+
428
+ ## Best Practices
429
+
430
+ 1. **Define field types carefully** - Hard to change after records exist
431
+ 2. **Use references for relationships** - Better than storing IDs as text
432
+ 3. **Add indexes for frequently queried fields** - Improves query performance
433
+ 4. **Use batch operations** - More efficient than individual operations
434
+ 5. **Validate data before import** - Check formats, required fields
435
+ 6. **Use SQL for complex queries** - More powerful than filter parameters
436
+ 7. **Set appropriate permissions** - Protect sensitive data
437
+ 8. **Consider dataset size** - Performance degrades beyond ~100k records