tila-sdk 0.1.0 → 0.2.0

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.
package/dist/index.d.ts CHANGED
@@ -1,13 +1,324 @@
1
1
  import { TilaProjectConfig } from './config';
2
2
  import { z } from 'zod';
3
- import { EntityResponse, EntityDetailResponse, EntityListResponse, ArchiveSuccessResponse, CreateEntityRelationshipResponse, EntityArtifactReferenceListResponse, AcquireSuccessResponse, RenewSuccessResponse, ReleaseSuccessResponse, StateListResponse, StateResponse, ArtifactPutResponse, ArtifactListResponse, ArtifactSearchResponse, ArtifactGrepResponse, ArtifactRelationshipOkResponse, ArtifactRelationshipListResponse, TokenIssueResponse, TokenRevokeResponse, TokenListResponse, JournalResponse, PresenceHeartbeatSuccessResponse, PresenceListResponse, PresenceAllListResponse, RecordCreateRequest, RecordMutateResponse, RecordSetRequest, RecordGetResponse, RecordPatchRequest, RecordArchiveRequest, RecordUnarchiveRequest, RecordHistoryResponse, RecordListResponse, RecordTypesResponse, InstantiateTemplateRequest, InstantiateTemplateResponse, SummaryResponse, UnifiedSearchResponse } from './api';
3
+ import { ArtifactPointer, EntityArtifactReference } from './artifact';
4
+ import { ArtifactPutResponse, ArtifactListResponse, ArtifactSearchResponse, ArtifactGrepResponse, ArtifactRelationshipOkResponse, ArtifactRelationshipListResponse, AcquireSuccessResponse, RenewSuccessResponse, ReleaseSuccessResponse, StateListResponse, StateResponse, EntityResponse, EntityDetailResponse, EntityListResponse, ArchiveSuccessResponse, CreateEntityRelationshipResponse, ListEntityRelationshipsResponse, EntityArtifactReferenceListResponse, JournalResponse, PresenceHeartbeatSuccessResponse, PresenceListResponse, PresenceAllListResponse, RecordCreateRequest, RecordMutateResponse, RecordSetRequest, RecordGetResponse, RecordPatchRequest, RecordArchiveRequest, RecordUnarchiveRequest, RecordHistoryResponse, RecordListResponse, RecordTypesResponse, UnifiedSearchResponse, SummaryResponse, InstantiateTemplateRequest, InstantiateTemplateResponse, TokenIssueResponse, TokenRevokeResponse, TokenListResponse, RecordRow, RecordListItem, RecordHistoryItem } from './api';
4
5
  export { AcquireSuccessResponse, ArtifactGrepResponse, ArtifactListResponse, ArtifactPutResponse, ArtifactSearchResponse, EntityDetailResponse, EntityListResponse, EntityResponse, InstantiateTemplateRequest, InstantiateTemplateResponse, JournalResponse, PresenceAllListResponse, PresenceListResponse, RecordArchiveRequest, RecordCreateRequest, RecordGetResponse, RecordHistoryItem, RecordHistoryResponse, RecordItem, RecordListItem, RecordListResponse, RecordMutateResponse, RecordPatchRequest, RecordSetRequest, RecordTypesResponse, RecordUnarchiveRequest, ReleaseSuccessResponse, RenewSuccessResponse, SummaryResponse, TokenIssueResponse, TokenListResponse, TokenRevokeResponse, UnifiedSearchQuery, UnifiedSearchResponse, UnifiedSearchResult } from './api';
5
- import { ClaimMode } from './claim';
6
- import { ArtifactPointer } from './artifact';
7
- import { InboxResponse, SendSignalRequest, SendSignalResponse, AckSignalResponse } from './signal';
8
- export { AckSignalResponse, InboxResponse, SendSignalRequest, SendSignalResponse } from './signal';
6
+ import { ClaimMode, Claim } from './claim';
9
7
  import { GateListResponse, CreateGateRequest, GateResponse, ResolveGateRequest } from './gate';
10
8
  export { CreateGateRequest, GateListResponse, GateResponse, ResolveGateRequest } from './gate';
9
+ import { InboxResponse, SendSignalRequest, SendSignalResponse, AckSignalResponse } from './signal';
10
+ export { AckSignalResponse, InboxResponse, SendSignalRequest, SendSignalResponse } from './signal';
11
+ import { EntityBackend, CreateEntityInput, EntityListFilter, RelationshipInput, RelationshipFilter, ReadyFilter, EntityTree, AddArtifactRefInput } from './interfaces/entity-backend';
12
+ import { CoordinationBackend, AcquireResult, RenewResult } from './interfaces/coordination-backend';
13
+ import { ArtifactBackend, ArtifactPutOptions, ArtifactPointerRecord, ArtifactRelationship, ArtifactSearchResultRecord, ArtifactIndexEntry } from './interfaces/artifact-backend';
14
+ import { JournalBackend, JournalQuery, JournalEvent } from './interfaces/journal-backend';
15
+ import { GateBackend, GateRecord, GateFilter } from './interfaces/gate-backend';
16
+ import { SignalBackend, SendSignalInput, SignalRecord } from './interfaces/signal-backend';
17
+ import { SchemaBackend, SchemaRecord, ApplySchemaInput, ApplySchemaOutput } from './interfaces/schema-backend';
18
+ import { SummaryBackend, ProjectSummary } from './interfaces/summary-backend';
19
+ import { RecordBackend, CreateRecordInput, SetRecordInput, PatchRecordInput, ArchiveRecordInput, RecordListFilter, RecordPage, RecordHistoryOptions } from './interfaces/record-backend';
20
+ import { Entity } from './entity';
21
+ import { Presence } from './presence';
22
+ import { EntityRelationship } from './relationship';
23
+
24
+ interface ArtifactUploadOpts {
25
+ kind: string;
26
+ resource?: string;
27
+ fence?: number;
28
+ mimeType?: string;
29
+ flavor?: string;
30
+ tags?: string[];
31
+ }
32
+ declare function createArtifactMethods(client: TilaClient, projectId: string): {
33
+ upload: {
34
+ (file: File | Blob, opts: ArtifactUploadOpts): Promise<ArtifactPutResponse>;
35
+ (stream: ReadableStream, opts: ArtifactUploadOpts & {
36
+ mimeType: string;
37
+ }): Promise<ArtifactPutResponse>;
38
+ };
39
+ download(key: string): Promise<{
40
+ body: ReadableStream;
41
+ contentType: string;
42
+ contentLength: number | null;
43
+ }>;
44
+ list(query?: {
45
+ resource?: string;
46
+ kind?: string;
47
+ limit?: string;
48
+ tagFilter?: string[];
49
+ }): Promise<ArtifactListResponse>;
50
+ search(q: string, opts?: {
51
+ kind?: string;
52
+ resource?: string;
53
+ limit?: string;
54
+ tagFilter?: string[];
55
+ }): Promise<ArtifactSearchResponse>;
56
+ grep(pattern: string, opts?: {
57
+ kind?: string;
58
+ resource?: string;
59
+ regex?: boolean;
60
+ limit?: number;
61
+ }): Promise<ArtifactGrepResponse>;
62
+ addRelationship(fromKey: string, toKeyOrUri: string, type: string, metadata?: Record<string, unknown>): Promise<ArtifactRelationshipOkResponse>;
63
+ listRelationships(key: string): Promise<ArtifactRelationshipListResponse>;
64
+ getLatest(kind: string, resource: string): Promise<ArtifactPointer | null>;
65
+ writeText(content: string, opts: {
66
+ kind: string;
67
+ mimeType?: string;
68
+ resource?: string;
69
+ fence?: number;
70
+ tags?: string[];
71
+ }): Promise<ArtifactPutResponse>;
72
+ readText(key: string): Promise<{
73
+ content: string;
74
+ mimeType: string;
75
+ }>;
76
+ };
77
+
78
+ declare function createClaimMethods(client: TilaClient, projectId: string): {
79
+ acquire(resource: string, mode: ClaimMode, ttlMs: number, opts?: {
80
+ metadata?: Record<string, unknown>;
81
+ idempotency_key?: string;
82
+ }): Promise<AcquireSuccessResponse>;
83
+ renew(resource: string, fence: number, ttlMs: number): Promise<RenewSuccessResponse>;
84
+ release(resource: string, fence: number): Promise<ReleaseSuccessResponse>;
85
+ list(): Promise<StateListResponse>;
86
+ get(resource: string): Promise<StateResponse>;
87
+ };
88
+
89
+ /**
90
+ * Creates task API methods using the canonical /tasks public path.
91
+ */
92
+ declare function createTaskMethods(client: TilaClient, projectId: string): {
93
+ create(id: string, type: string, data?: Record<string, unknown>, tags?: string[]): Promise<EntityResponse>;
94
+ get(id: string): Promise<EntityDetailResponse>;
95
+ list(query?: {
96
+ type?: string;
97
+ status?: string;
98
+ limit?: string;
99
+ cursor?: string;
100
+ tagFilter?: string[];
101
+ /**
102
+ * Request the Worker's compact projection (id/type/title/status/...). HTTP
103
+ * only — the embedded backend has no compact list, so the local adapter
104
+ * ignores this and returns full entities (a documented local divergence).
105
+ */
106
+ compact?: boolean;
107
+ }): Promise<EntityListResponse>;
108
+ update(id: string, data: Record<string, unknown>, fence: number): Promise<EntityResponse>;
109
+ archive(id: string, fence: number): Promise<ArchiveSuccessResponse>;
110
+ addRelationship(fromId: string, toId: string, type: string): Promise<CreateEntityRelationshipResponse>;
111
+ listRelationships(filter?: {
112
+ fromId?: string;
113
+ toId?: string;
114
+ type?: string;
115
+ }): Promise<ListEntityRelationshipsResponse>;
116
+ ready(query?: {
117
+ type?: string;
118
+ parent?: string;
119
+ limit?: number;
120
+ includeSoftBlocked?: boolean;
121
+ }): Promise<EntityListResponse>;
122
+ addArtifactRef(entityId: string, artifactKey: string, slot: string, metadata?: Record<string, unknown>): Promise<{
123
+ ok: true;
124
+ }>;
125
+ listArtifactRefs(entityId: string): Promise<EntityArtifactReferenceListResponse>;
126
+ };
127
+ /**
128
+ * @deprecated Use createTaskMethods instead.
129
+ */
130
+ declare function createEntityMethods(client: TilaClient, projectId: string): {
131
+ create(id: string, type: string, data?: Record<string, unknown>, tags?: string[]): Promise<EntityResponse>;
132
+ get(id: string): Promise<EntityDetailResponse>;
133
+ list(query?: {
134
+ type?: string;
135
+ status?: string;
136
+ limit?: string;
137
+ cursor?: string;
138
+ tagFilter?: string[];
139
+ /**
140
+ * Request the Worker's compact projection (id/type/title/status/...). HTTP
141
+ * only — the embedded backend has no compact list, so the local adapter
142
+ * ignores this and returns full entities (a documented local divergence).
143
+ */
144
+ compact?: boolean;
145
+ }): Promise<EntityListResponse>;
146
+ update(id: string, data: Record<string, unknown>, fence: number): Promise<EntityResponse>;
147
+ archive(id: string, fence: number): Promise<ArchiveSuccessResponse>;
148
+ addRelationship(fromId: string, toId: string, type: string): Promise<CreateEntityRelationshipResponse>;
149
+ listRelationships(filter?: {
150
+ fromId?: string;
151
+ toId?: string;
152
+ type?: string;
153
+ }): Promise<ListEntityRelationshipsResponse>;
154
+ ready(query?: {
155
+ type?: string;
156
+ parent?: string;
157
+ limit?: number;
158
+ includeSoftBlocked?: boolean;
159
+ }): Promise<EntityListResponse>;
160
+ addArtifactRef(entityId: string, artifactKey: string, slot: string, metadata?: Record<string, unknown>): Promise<{
161
+ ok: true;
162
+ }>;
163
+ listArtifactRefs(entityId: string): Promise<EntityArtifactReferenceListResponse>;
164
+ };
165
+ /**
166
+ * @deprecated Use createTaskMethods instead.
167
+ */
168
+ declare function createWorkUnitMethods(client: TilaClient, projectId: string): {
169
+ create(id: string, type: string, data?: Record<string, unknown>, tags?: string[]): Promise<EntityResponse>;
170
+ get(id: string): Promise<EntityDetailResponse>;
171
+ list(query?: {
172
+ type?: string;
173
+ status?: string;
174
+ limit?: string;
175
+ cursor?: string;
176
+ tagFilter?: string[];
177
+ /**
178
+ * Request the Worker's compact projection (id/type/title/status/...). HTTP
179
+ * only — the embedded backend has no compact list, so the local adapter
180
+ * ignores this and returns full entities (a documented local divergence).
181
+ */
182
+ compact?: boolean;
183
+ }): Promise<EntityListResponse>;
184
+ update(id: string, data: Record<string, unknown>, fence: number): Promise<EntityResponse>;
185
+ archive(id: string, fence: number): Promise<ArchiveSuccessResponse>;
186
+ addRelationship(fromId: string, toId: string, type: string): Promise<CreateEntityRelationshipResponse>;
187
+ listRelationships(filter?: {
188
+ fromId?: string;
189
+ toId?: string;
190
+ type?: string;
191
+ }): Promise<ListEntityRelationshipsResponse>;
192
+ ready(query?: {
193
+ type?: string;
194
+ parent?: string;
195
+ limit?: number;
196
+ includeSoftBlocked?: boolean;
197
+ }): Promise<EntityListResponse>;
198
+ addArtifactRef(entityId: string, artifactKey: string, slot: string, metadata?: Record<string, unknown>): Promise<{
199
+ ok: true;
200
+ }>;
201
+ listArtifactRefs(entityId: string): Promise<EntityArtifactReferenceListResponse>;
202
+ };
203
+
204
+ declare function createGateMethods(client: TilaClient, projectId: string): {
205
+ /** List gates with optional filters. GET /projects/:id/gates */
206
+ list(query?: {
207
+ resource?: string;
208
+ status?: string;
209
+ limit?: string;
210
+ }): Promise<GateListResponse>;
211
+ /** Create a new gate. POST /projects/:id/gates */
212
+ create(req: CreateGateRequest): Promise<GateResponse>;
213
+ /** Resolve a gate. POST /projects/:id/gates/:gateId/resolve */
214
+ resolve(gateId: string, req?: ResolveGateRequest): Promise<GateResponse>;
215
+ /** Delete a gate. DELETE /projects/:id/gates/:gateId */
216
+ remove(gateId: string): Promise<{
217
+ ok: true;
218
+ }>;
219
+ };
220
+
221
+ declare function createJournalMethods(client: TilaClient, projectId: string): {
222
+ query(opts?: {
223
+ resource?: string;
224
+ kind?: string;
225
+ after_seq?: string;
226
+ limit?: string;
227
+ }): Promise<JournalResponse>;
228
+ };
229
+
230
+ declare function createPresenceMethods(client: TilaClient, projectId: string): {
231
+ heartbeat(machine: string, info?: Record<string, unknown>): Promise<PresenceHeartbeatSuccessResponse>;
232
+ list(): Promise<PresenceListResponse>;
233
+ /**
234
+ * List all presence records across all machines, including whether each is active.
235
+ * Hits GET /projects/:projectId/presence/all
236
+ */
237
+ listAll(): Promise<PresenceAllListResponse>;
238
+ };
239
+
240
+ declare function createRecordMethods(client: TilaClient, projectId: string): {
241
+ create(type: string, req: RecordCreateRequest): Promise<RecordMutateResponse>;
242
+ set(type: string, key: string, req: RecordSetRequest): Promise<RecordMutateResponse>;
243
+ get(type: string, key: string): Promise<RecordGetResponse>;
244
+ patch(type: string, key: string, req: RecordPatchRequest): Promise<RecordMutateResponse>;
245
+ archive(type: string, key: string, req: RecordArchiveRequest): Promise<RecordMutateResponse>;
246
+ unarchive(type: string, key: string, req: RecordUnarchiveRequest): Promise<RecordMutateResponse>;
247
+ history(type: string, key: string, opts?: {
248
+ limit?: number;
249
+ values?: boolean;
250
+ }): Promise<RecordHistoryResponse>;
251
+ list(type: string, query?: {
252
+ tag?: string;
253
+ filter?: string;
254
+ "include-archived"?: string;
255
+ limit?: string;
256
+ tagFilter?: string[];
257
+ }): Promise<RecordListResponse>;
258
+ types(): Promise<RecordTypesResponse>;
259
+ typesInUse(): Promise<RecordTypesResponse>;
260
+ };
261
+
262
+ declare function createSchemaMethods(client: TilaClient, projectId: string): {
263
+ get(): Promise<{
264
+ ok: true;
265
+ schema: unknown;
266
+ version: number;
267
+ }>;
268
+ apply(schema: unknown, strategy?: string): Promise<{
269
+ ok: true;
270
+ version: number;
271
+ diff: unknown;
272
+ }>;
273
+ history(opts?: {
274
+ limit?: string;
275
+ }): Promise<{
276
+ ok: true;
277
+ entries: unknown[];
278
+ }>;
279
+ };
280
+
281
+ declare function createSearchMethods(client: TilaClient, projectId: string): {
282
+ search(q: string, opts?: {
283
+ limit?: number;
284
+ tagFilter?: string[];
285
+ }): Promise<UnifiedSearchResponse>;
286
+ };
287
+
288
+ declare function createSignalMethods(client: TilaClient, projectId: string): {
289
+ /** Fetch the signal inbox for the current token. GET /projects/:id/signals */
290
+ inbox(): Promise<InboxResponse>;
291
+ /** Send a signal to a target. POST /projects/:id/signals/send */
292
+ send(req: SendSignalRequest): Promise<SendSignalResponse>;
293
+ /** Acknowledge a signal. POST /projects/:id/signals/:signalId/ack */
294
+ ack(signalId: string): Promise<AckSignalResponse>;
295
+ };
296
+
297
+ declare function createSummaryMethods(client: TilaClient, projectId: string): {
298
+ /** Get project summary. GET /projects/:id/summary */
299
+ get(): Promise<SummaryResponse>;
300
+ };
301
+
302
+ declare function createTemplateMethods(client: TilaClient, projectId: string): {
303
+ /** Instantiate an entity template. POST /projects/:id/templates/instantiate */
304
+ instantiate(req: InstantiateTemplateRequest): Promise<InstantiateTemplateResponse>;
305
+ /** List available templates from the project schema. GET /projects/:id/templates */
306
+ list(): Promise<{
307
+ ok: true;
308
+ templates: Array<{
309
+ name: string;
310
+ type: string;
311
+ description: string | null;
312
+ variables: string[];
313
+ }>;
314
+ }>;
315
+ };
316
+
317
+ declare function createTokenMethods(client: TilaClient): {
318
+ issue(name: string, note?: string): Promise<TokenIssueResponse>;
319
+ revoke(name: string): Promise<TokenRevokeResponse>;
320
+ list(): Promise<TokenListResponse>;
321
+ };
11
322
 
12
323
  interface ClientOptions {
13
324
  baseUrl: string;
@@ -34,7 +345,9 @@ declare class TilaClient {
34
345
  * the fallback branch will never execute there.
35
346
  */
36
347
  private createAbortSignal;
37
- static fromConfig(config: TilaProjectConfig, token: string): TilaClient;
348
+ static fromConfig(config: TilaProjectConfig, token: string, opts?: {
349
+ extraHeaders?: Record<string, string>;
350
+ }): TilaClient;
38
351
  request<T>(method: string, path: string, opts?: {
39
352
  body?: unknown;
40
353
  query?: Record<string, string | undefined>;
@@ -83,12 +396,73 @@ declare function exchangeGitHubToken(baseUrl: string, projectId: string, githubT
83
396
  expiresAt: number;
84
397
  permission: string;
85
398
  }>;
86
-
87
- interface RetryOptions {
88
- /** Maximum number of retry attempts after the first failure. Default: 3. */
89
- maxRetries?: number;
90
- /** Base delay in milliseconds for exponential backoff. Default: 200. */
91
- baseDelayMs?: number;
399
+ /**
400
+ * The HTTP resource-method surface. Built from the zod-only factories
401
+ * (`createTaskMethods`, `createRecordMethods`, …) so the type is derived from a
402
+ * single source of truth and never drifts from the factory signatures.
403
+ *
404
+ * The LOCAL branch's `buildLocalResources` (in `./local/resource-adapters`)
405
+ * presents the SAME shape, so consumers swap backends without changing call
406
+ * sites. `tokens.issue` etc. throw `LocalUnsupportedError` under the local
407
+ * backend (HTTP-only — D1 global token store).
408
+ */
409
+ interface TilaFacade {
410
+ tasks: ReturnType<typeof createTaskMethods>;
411
+ records: ReturnType<typeof createRecordMethods>;
412
+ claims: ReturnType<typeof createClaimMethods>;
413
+ artifacts: ReturnType<typeof createArtifactMethods>;
414
+ gates: ReturnType<typeof createGateMethods>;
415
+ signals: ReturnType<typeof createSignalMethods>;
416
+ journal: ReturnType<typeof createJournalMethods>;
417
+ presence: ReturnType<typeof createPresenceMethods>;
418
+ schema: ReturnType<typeof createSchemaMethods>;
419
+ summary: ReturnType<typeof createSummaryMethods>;
420
+ search: ReturnType<typeof createSearchMethods>;
421
+ templates: ReturnType<typeof createTemplateMethods>;
422
+ tokens: ReturnType<typeof createTokenMethods>;
423
+ /**
424
+ * Release backend resources. No-op for the HTTP backend; closes the SQLite
425
+ * connection for the local backend. Always safe (and idempotent) to call.
426
+ */
427
+ close: () => void;
428
+ }
429
+ /**
430
+ * Create a uniform tila facade over either the local (in-process SQLite) or the
431
+ * Cloudflare (HTTP) backend, selected by `config.backend`. Both branches expose
432
+ * the EXACT same resource-method surface ({@link TilaFacade}); a consumer can
433
+ * swap backends without touching any call site.
434
+ *
435
+ * - `backend: "cloudflare"` (default) → constructs a {@link TilaClient} from
436
+ * `config.worker_url` + `token` and wires the zod-only HTTP factories.
437
+ * - `backend: "local"` → DYNAMICALLY imports `tila-sdk/local`'s
438
+ * `createTilaLocal` (the better-sqlite3 + node:fs stack) and the local
439
+ * resource adapters, then presents them through the same facade.
440
+ *
441
+ * ## Entry / bundle hygiene
442
+ *
443
+ * `createTila` lives in the MAIN (zod-only) entry. Its local branch must NOT be
444
+ * statically reachable from the main bundle — the heavy SQLite stack belongs to
445
+ * `tila-sdk/local`. So the local branch uses dynamic `import()` (mirroring how
446
+ * `createTilaLocal` itself dynamically imports the native driver). Nothing heavy
447
+ * is statically imported here, keeping `dist/index.js` zod-only (enforced by
448
+ * `__tests__/bundle-hygiene.test.ts`).
449
+ *
450
+ * @param token Required for the Cloudflare backend; ignored for local.
451
+ * @param opts Optional Cloudflare-backend tuning. `opts.extraHeaders` is
452
+ * forwarded to the underlying `TilaClient` (e.g. a caller-attribution
453
+ * `X-Tila-Source: mcp-server/<version>` header). Ignored for the local
454
+ * backend, which makes no HTTP requests. Additive/back-compat: existing
455
+ * `createTila(config, token)` callers are unaffected.
456
+ */
457
+ declare function createTila(config: TilaProjectConfig, token?: string, opts?: {
458
+ extraHeaders?: Record<string, string>;
459
+ }): Promise<TilaFacade>;
460
+
461
+ interface RetryOptions {
462
+ /** Maximum number of retry attempts after the first failure. Default: 3. */
463
+ maxRetries?: number;
464
+ /** Base delay in milliseconds for exponential backoff. Default: 200. */
465
+ baseDelayMs?: number;
92
466
  /** Maximum delay cap in milliseconds. Default: 30000. */
93
467
  maxDelayMs?: number;
94
468
  /** Whether to apply full jitter to the delay. Default: true. */
@@ -158,234 +532,6 @@ declare const TILA_ERRORS: {
158
532
  };
159
533
  type TilaErrorCode = (typeof TILA_ERRORS)[keyof typeof TILA_ERRORS];
160
534
 
161
- /**
162
- * Creates task API methods using the canonical /tasks public path.
163
- */
164
- declare function createTaskMethods(client: TilaClient, projectId: string): {
165
- create(id: string, type: string, data?: Record<string, unknown>): Promise<EntityResponse>;
166
- get(id: string): Promise<EntityDetailResponse>;
167
- list(query?: {
168
- type?: string;
169
- status?: string;
170
- limit?: string;
171
- cursor?: string;
172
- }): Promise<EntityListResponse>;
173
- update(id: string, data: Record<string, unknown>, fence: number): Promise<EntityResponse>;
174
- archive(id: string, fence: number): Promise<ArchiveSuccessResponse>;
175
- addRelationship(fromId: string, toId: string, type: string): Promise<CreateEntityRelationshipResponse>;
176
- addArtifactRef(entityId: string, artifactKey: string, slot: string, metadata?: Record<string, unknown>): Promise<{
177
- ok: true;
178
- }>;
179
- listArtifactRefs(entityId: string): Promise<EntityArtifactReferenceListResponse>;
180
- };
181
- /**
182
- * @deprecated Use createTaskMethods instead.
183
- */
184
- declare function createEntityMethods(client: TilaClient, projectId: string): {
185
- create(id: string, type: string, data?: Record<string, unknown>): Promise<EntityResponse>;
186
- get(id: string): Promise<EntityDetailResponse>;
187
- list(query?: {
188
- type?: string;
189
- status?: string;
190
- limit?: string;
191
- cursor?: string;
192
- }): Promise<EntityListResponse>;
193
- update(id: string, data: Record<string, unknown>, fence: number): Promise<EntityResponse>;
194
- archive(id: string, fence: number): Promise<ArchiveSuccessResponse>;
195
- addRelationship(fromId: string, toId: string, type: string): Promise<CreateEntityRelationshipResponse>;
196
- addArtifactRef(entityId: string, artifactKey: string, slot: string, metadata?: Record<string, unknown>): Promise<{
197
- ok: true;
198
- }>;
199
- listArtifactRefs(entityId: string): Promise<EntityArtifactReferenceListResponse>;
200
- };
201
- /**
202
- * @deprecated Use createTaskMethods instead.
203
- */
204
- declare function createWorkUnitMethods(client: TilaClient, projectId: string): {
205
- create(id: string, type: string, data?: Record<string, unknown>): Promise<EntityResponse>;
206
- get(id: string): Promise<EntityDetailResponse>;
207
- list(query?: {
208
- type?: string;
209
- status?: string;
210
- limit?: string;
211
- cursor?: string;
212
- }): Promise<EntityListResponse>;
213
- update(id: string, data: Record<string, unknown>, fence: number): Promise<EntityResponse>;
214
- archive(id: string, fence: number): Promise<ArchiveSuccessResponse>;
215
- addRelationship(fromId: string, toId: string, type: string): Promise<CreateEntityRelationshipResponse>;
216
- addArtifactRef(entityId: string, artifactKey: string, slot: string, metadata?: Record<string, unknown>): Promise<{
217
- ok: true;
218
- }>;
219
- listArtifactRefs(entityId: string): Promise<EntityArtifactReferenceListResponse>;
220
- };
221
-
222
- declare function createClaimMethods(client: TilaClient, projectId: string): {
223
- acquire(resource: string, mode: ClaimMode, ttlMs: number, opts?: {
224
- metadata?: Record<string, unknown>;
225
- idempotency_key?: string;
226
- }): Promise<AcquireSuccessResponse>;
227
- renew(resource: string, fence: number, ttlMs: number): Promise<RenewSuccessResponse>;
228
- release(resource: string, fence: number): Promise<ReleaseSuccessResponse>;
229
- list(): Promise<StateListResponse>;
230
- get(resource: string): Promise<StateResponse>;
231
- };
232
-
233
- interface ArtifactUploadOpts {
234
- kind: string;
235
- resource?: string;
236
- fence?: number;
237
- mimeType?: string;
238
- flavor?: string;
239
- }
240
- declare function createArtifactMethods(client: TilaClient, projectId: string): {
241
- upload: {
242
- (file: File | Blob, opts: ArtifactUploadOpts): Promise<ArtifactPutResponse>;
243
- (stream: ReadableStream, opts: ArtifactUploadOpts & {
244
- mimeType: string;
245
- }): Promise<ArtifactPutResponse>;
246
- };
247
- download(key: string): Promise<{
248
- body: ReadableStream;
249
- contentType: string;
250
- contentLength: number | null;
251
- }>;
252
- list(query?: {
253
- resource?: string;
254
- kind?: string;
255
- limit?: string;
256
- }): Promise<ArtifactListResponse>;
257
- search(q: string, opts?: {
258
- kind?: string;
259
- resource?: string;
260
- limit?: string;
261
- }): Promise<ArtifactSearchResponse>;
262
- grep(pattern: string, opts?: {
263
- kind?: string;
264
- resource?: string;
265
- regex?: boolean;
266
- limit?: number;
267
- }): Promise<ArtifactGrepResponse>;
268
- addRelationship(fromKey: string, toKeyOrUri: string, type: string, metadata?: Record<string, unknown>): Promise<ArtifactRelationshipOkResponse>;
269
- listRelationships(key: string): Promise<ArtifactRelationshipListResponse>;
270
- getLatest(kind: string, resource: string): Promise<ArtifactPointer | null>;
271
- writeText(content: string, opts: {
272
- kind: string;
273
- mimeType?: string;
274
- resource?: string;
275
- fence?: number;
276
- }): Promise<ArtifactPutResponse>;
277
- readText(key: string): Promise<{
278
- content: string;
279
- mimeType: string;
280
- }>;
281
- };
282
-
283
- declare function createTokenMethods(client: TilaClient): {
284
- issue(name: string, note?: string): Promise<TokenIssueResponse>;
285
- revoke(name: string): Promise<TokenRevokeResponse>;
286
- list(): Promise<TokenListResponse>;
287
- };
288
-
289
- declare function createJournalMethods(client: TilaClient, projectId: string): {
290
- query(opts?: {
291
- entity_id?: string;
292
- event_kind?: string;
293
- limit?: string;
294
- cursor?: string;
295
- }): Promise<JournalResponse>;
296
- };
297
-
298
- declare function createPresenceMethods(client: TilaClient, projectId: string): {
299
- heartbeat(machine: string, ttlMs?: number): Promise<PresenceHeartbeatSuccessResponse>;
300
- list(): Promise<PresenceListResponse>;
301
- /**
302
- * List all presence records across all machines, including whether each is active.
303
- * Hits GET /projects/:projectId/presence/all
304
- */
305
- listAll(): Promise<PresenceAllListResponse>;
306
- };
307
-
308
- declare function createRecordMethods(client: TilaClient, projectId: string): {
309
- create(type: string, req: RecordCreateRequest): Promise<RecordMutateResponse>;
310
- set(type: string, key: string, req: RecordSetRequest): Promise<RecordMutateResponse>;
311
- get(type: string, key: string): Promise<RecordGetResponse>;
312
- patch(type: string, key: string, req: RecordPatchRequest): Promise<RecordMutateResponse>;
313
- archive(type: string, key: string, req: RecordArchiveRequest): Promise<RecordMutateResponse>;
314
- unarchive(type: string, key: string, req: RecordUnarchiveRequest): Promise<RecordMutateResponse>;
315
- history(type: string, key: string, opts?: {
316
- limit?: number;
317
- values?: boolean;
318
- }): Promise<RecordHistoryResponse>;
319
- list(type: string, query?: {
320
- tag?: string;
321
- filter?: string;
322
- "include-archived"?: string;
323
- limit?: string;
324
- }): Promise<RecordListResponse>;
325
- types(): Promise<RecordTypesResponse>;
326
- typesInUse(): Promise<RecordTypesResponse>;
327
- };
328
-
329
- declare function createSchemaMethods(client: TilaClient, projectId: string): {
330
- get(): Promise<{
331
- ok: true;
332
- schema: unknown;
333
- version: number;
334
- }>;
335
- apply(schema: unknown, strategy?: string): Promise<{
336
- ok: true;
337
- version: number;
338
- diff: unknown;
339
- }>;
340
- history(opts?: {
341
- limit?: string;
342
- }): Promise<{
343
- ok: true;
344
- entries: unknown[];
345
- }>;
346
- };
347
-
348
- declare function createSignalMethods(client: TilaClient, projectId: string): {
349
- /** Fetch the signal inbox for the current token. GET /projects/:id/signals */
350
- inbox(): Promise<InboxResponse>;
351
- /** Send a signal to a target. POST /projects/:id/signals/send */
352
- send(req: SendSignalRequest): Promise<SendSignalResponse>;
353
- /** Acknowledge a signal. POST /projects/:id/signals/:signalId/ack */
354
- ack(signalId: string): Promise<AckSignalResponse>;
355
- };
356
-
357
- declare function createGateMethods(client: TilaClient, projectId: string): {
358
- /** List gates with optional filters. GET /projects/:id/gates */
359
- list(query?: {
360
- resource?: string;
361
- status?: string;
362
- limit?: string;
363
- }): Promise<GateListResponse>;
364
- /** Create a new gate. POST /projects/:id/gates */
365
- create(req: CreateGateRequest): Promise<GateResponse>;
366
- /** Resolve a gate. POST /projects/:id/gates/:gateId/resolve */
367
- resolve(gateId: string, req?: ResolveGateRequest): Promise<GateResponse>;
368
- /** Delete a gate. DELETE /projects/:id/gates/:gateId */
369
- remove(gateId: string): Promise<{
370
- ok: true;
371
- }>;
372
- };
373
-
374
- declare function createTemplateMethods(client: TilaClient, projectId: string): {
375
- /** Instantiate an entity template. POST /projects/:id/templates/instantiate */
376
- instantiate(req: InstantiateTemplateRequest): Promise<InstantiateTemplateResponse>;
377
- /** List available templates from the project schema. GET /projects/:id/templates */
378
- list(): Promise<{
379
- ok: true;
380
- templates: Array<{
381
- name: string;
382
- type: string;
383
- description: string | null;
384
- variables: string[];
385
- }>;
386
- }>;
387
- };
388
-
389
535
  interface IndexCreateOpts {
390
536
  kind?: string;
391
537
  resource?: string;
@@ -413,16 +559,412 @@ declare function createIndexMethods(client: TilaClient, projectId: string): {
413
559
  listEntries(indexKey: string): Promise<ArtifactRelationshipListResponse>;
414
560
  };
415
561
 
416
- declare function createSummaryMethods(client: TilaClient, projectId: string): {
417
- /** Get project summary. GET /projects/:id/summary */
418
- get(): Promise<SummaryResponse>;
562
+ declare function createNamespace(client: TilaClient, projectId: string, ns: string): {
563
+ tasks: {
564
+ create(id: string, type: string, data?: Record<string, unknown>): Promise<{
565
+ entity: {
566
+ type: string;
567
+ tags: string[];
568
+ created_at: number;
569
+ data: Record<string, unknown>;
570
+ schema_version: number;
571
+ id: string;
572
+ archived: number;
573
+ updated_at: number;
574
+ created_by: string;
575
+ };
576
+ ok: true;
577
+ }>;
578
+ get(id: string): Promise<{
579
+ entity: {
580
+ type: string;
581
+ tags: string[];
582
+ created_at: number;
583
+ data: Record<string, unknown>;
584
+ schema_version: number;
585
+ id: string;
586
+ archived: number;
587
+ updated_at: number;
588
+ created_by: string;
589
+ };
590
+ ok: true;
591
+ relationships: {
592
+ type: "parent-child" | "blocks" | "soft-blocks" | "related" | "discovered-from";
593
+ created_at: number;
594
+ from_id: string;
595
+ to_id: string;
596
+ schema_version: number;
597
+ }[];
598
+ }>;
599
+ update(id: string, data: Record<string, unknown>, fence: number): Promise<{
600
+ entity: {
601
+ type: string;
602
+ tags: string[];
603
+ created_at: number;
604
+ data: Record<string, unknown>;
605
+ schema_version: number;
606
+ id: string;
607
+ archived: number;
608
+ updated_at: number;
609
+ created_by: string;
610
+ };
611
+ ok: true;
612
+ }>;
613
+ list(query?: {
614
+ type?: string;
615
+ status?: string;
616
+ limit?: string;
617
+ cursor?: string;
618
+ }): Promise<{
619
+ entities: {
620
+ type: string;
621
+ tags: string[];
622
+ created_at: number;
623
+ data: Record<string, unknown>;
624
+ schema_version: number;
625
+ id: string;
626
+ archived: number;
627
+ updated_at: number;
628
+ created_by: string;
629
+ }[];
630
+ ok: true;
631
+ }>;
632
+ archive(id: string, fence: number): Promise<ArchiveSuccessResponse>;
633
+ addRelationship(fromId: string, toId: string, type: string): Promise<CreateEntityRelationshipResponse>;
634
+ listRelationships(filter?: {
635
+ fromId?: string;
636
+ toId?: string;
637
+ type?: string;
638
+ }): Promise<ListEntityRelationshipsResponse>;
639
+ ready(query?: {
640
+ type?: string;
641
+ parent?: string;
642
+ limit?: number;
643
+ includeSoftBlocked?: boolean;
644
+ }): Promise<EntityListResponse>;
645
+ addArtifactRef(entityId: string, artifactKey: string, slot: string, metadata?: Record<string, unknown>): Promise<{
646
+ ok: true;
647
+ }>;
648
+ listArtifactRefs(entityId: string): Promise<EntityArtifactReferenceListResponse>;
649
+ };
650
+ records: {
651
+ create(type: string, req: Parameters<(type: string, req: RecordCreateRequest) => Promise<RecordMutateResponse>>[1]): Promise<{
652
+ fence: number;
653
+ ok: true;
654
+ record: {
655
+ value: Record<string, unknown>;
656
+ type: string;
657
+ tags: string[];
658
+ created_at: number;
659
+ schema_version: number;
660
+ archived: number;
661
+ updated_at: number;
662
+ key: string;
663
+ value_sha256: string;
664
+ revision: number;
665
+ updated_by: string;
666
+ };
667
+ revision: number;
668
+ }>;
669
+ set(type: string, key: string, req: Parameters<(type: string, key: string, req: RecordSetRequest) => Promise<RecordMutateResponse>>[2]): Promise<{
670
+ fence: number;
671
+ ok: true;
672
+ record: {
673
+ value: Record<string, unknown>;
674
+ type: string;
675
+ tags: string[];
676
+ created_at: number;
677
+ schema_version: number;
678
+ archived: number;
679
+ updated_at: number;
680
+ key: string;
681
+ value_sha256: string;
682
+ revision: number;
683
+ updated_by: string;
684
+ };
685
+ revision: number;
686
+ }>;
687
+ get(type: string, key: string): Promise<{
688
+ fence: number;
689
+ ok: true;
690
+ record: {
691
+ value: Record<string, unknown>;
692
+ type: string;
693
+ tags: string[];
694
+ created_at: number;
695
+ schema_version: number;
696
+ archived: number;
697
+ updated_at: number;
698
+ key: string;
699
+ value_sha256: string;
700
+ revision: number;
701
+ updated_by: string;
702
+ };
703
+ }>;
704
+ patch(type: string, key: string, req: Parameters<(type: string, key: string, req: RecordPatchRequest) => Promise<RecordMutateResponse>>[2]): Promise<{
705
+ fence: number;
706
+ ok: true;
707
+ record: {
708
+ value: Record<string, unknown>;
709
+ type: string;
710
+ tags: string[];
711
+ created_at: number;
712
+ schema_version: number;
713
+ archived: number;
714
+ updated_at: number;
715
+ key: string;
716
+ value_sha256: string;
717
+ revision: number;
718
+ updated_by: string;
719
+ };
720
+ revision: number;
721
+ }>;
722
+ archive(type: string, key: string, req: Parameters<(type: string, key: string, req: RecordArchiveRequest) => Promise<RecordMutateResponse>>[2]): Promise<{
723
+ fence: number;
724
+ ok: true;
725
+ record: {
726
+ value: Record<string, unknown>;
727
+ type: string;
728
+ tags: string[];
729
+ created_at: number;
730
+ schema_version: number;
731
+ archived: number;
732
+ updated_at: number;
733
+ key: string;
734
+ value_sha256: string;
735
+ revision: number;
736
+ updated_by: string;
737
+ };
738
+ revision: number;
739
+ }>;
740
+ unarchive(type: string, key: string, req: Parameters<(type: string, key: string, req: RecordUnarchiveRequest) => Promise<RecordMutateResponse>>[2]): Promise<{
741
+ fence: number;
742
+ ok: true;
743
+ record: {
744
+ value: Record<string, unknown>;
745
+ type: string;
746
+ tags: string[];
747
+ created_at: number;
748
+ schema_version: number;
749
+ archived: number;
750
+ updated_at: number;
751
+ key: string;
752
+ value_sha256: string;
753
+ revision: number;
754
+ updated_by: string;
755
+ };
756
+ revision: number;
757
+ }>;
758
+ history(type: string, key: string, opts?: Parameters<(type: string, key: string, opts?: {
759
+ limit?: number;
760
+ values?: boolean;
761
+ }) => Promise<RecordHistoryResponse>>[2]): Promise<{
762
+ items: {
763
+ type: string;
764
+ message: string | null;
765
+ created_at: number;
766
+ actor: string;
767
+ schema_version: number;
768
+ key: string;
769
+ source_artifact_key: string | null;
770
+ value_sha256: string;
771
+ revision: number;
772
+ operation: "set" | "archived" | "created" | "patch" | "unarchived";
773
+ canonical_artifact_key: string | null;
774
+ value?: Record<string, unknown> | undefined;
775
+ }[];
776
+ ok: true;
777
+ meta: {
778
+ total: number;
779
+ limit: number;
780
+ next_cursor: string | null;
781
+ };
782
+ }>;
783
+ list(type: string, query?: Parameters<(type: string, query?: {
784
+ tag?: string;
785
+ filter?: string;
786
+ "include-archived"?: string;
787
+ limit?: string;
788
+ tagFilter?: string[];
789
+ }) => Promise<RecordListResponse>>[1]): Promise<{
790
+ items: {
791
+ type: string;
792
+ tags: string[];
793
+ archived: number;
794
+ updated_at: number;
795
+ key: string;
796
+ revision: number;
797
+ updated_by: string;
798
+ }[];
799
+ ok: true;
800
+ meta: {
801
+ total: number;
802
+ limit: number;
803
+ next_cursor: string | null;
804
+ };
805
+ }>;
806
+ types(): Promise<{
807
+ types: string[];
808
+ ok: true;
809
+ }>;
810
+ typesInUse(): Promise<{
811
+ types: string[];
812
+ ok: true;
813
+ }>;
814
+ };
815
+ artifacts: {
816
+ upload(input: File | Blob | ReadableStream, opts: Parameters<{
817
+ (file: File | Blob, opts: ArtifactUploadOpts): Promise<ArtifactPutResponse>;
818
+ (stream: ReadableStream, opts: ArtifactUploadOpts & {
819
+ mimeType: string;
820
+ }): Promise<ArtifactPutResponse>;
821
+ }>[1] & {
822
+ mimeType?: string;
823
+ }): Promise<{
824
+ bytes: number;
825
+ ok: true;
826
+ key: string;
827
+ deduplicated: boolean;
828
+ }>;
829
+ writeText(content: string, opts: Parameters<(content: string, opts: {
830
+ kind: string;
831
+ mimeType?: string;
832
+ resource?: string;
833
+ fence?: number;
834
+ tags?: string[];
835
+ }) => Promise<ArtifactPutResponse>>[1]): Promise<{
836
+ bytes: number;
837
+ ok: true;
838
+ key: string;
839
+ deduplicated: boolean;
840
+ }>;
841
+ list(query?: Parameters<(query?: {
842
+ resource?: string;
843
+ kind?: string;
844
+ limit?: string;
845
+ tagFilter?: string[];
846
+ }) => Promise<ArtifactListResponse>>[0]): Promise<{
847
+ pointers: {
848
+ kind: string;
849
+ r2_key: string;
850
+ resource: string | null;
851
+ sha256: string;
852
+ bytes: number;
853
+ fence: number | null;
854
+ mime_type: string;
855
+ produced_at: number;
856
+ produced_by: string;
857
+ expires_at: number | null;
858
+ tombstoned: number;
859
+ tags: string[];
860
+ }[];
861
+ ok: true;
862
+ }>;
863
+ search(q: string, opts?: Parameters<(q: string, opts?: {
864
+ kind?: string;
865
+ resource?: string;
866
+ limit?: string;
867
+ tagFilter?: string[];
868
+ }) => Promise<ArtifactSearchResponse>>[1]): Promise<{
869
+ results: {
870
+ kind: string;
871
+ r2_key: string;
872
+ resource: string | null;
873
+ mime_type: string;
874
+ produced_at: number;
875
+ title: string | null;
876
+ snippet: string | null;
877
+ indexed_at: number;
878
+ }[];
879
+ ok: true;
880
+ total: number;
881
+ }>;
882
+ grep(pattern: string, opts?: Parameters<(pattern: string, opts?: {
883
+ kind?: string;
884
+ resource?: string;
885
+ regex?: boolean;
886
+ limit?: number;
887
+ }) => Promise<ArtifactGrepResponse>>[1]): Promise<{
888
+ results: {
889
+ kind: string;
890
+ resource: string | null;
891
+ key: string;
892
+ lines: {
893
+ line: number;
894
+ text: string;
895
+ col: number;
896
+ }[];
897
+ truncated?: boolean | undefined;
898
+ }[];
899
+ ok: true;
900
+ skipped: number;
901
+ truncated: boolean;
902
+ scanned: number;
903
+ }>;
904
+ getLatest(kind: string, resource: string): Promise<{
905
+ kind: string;
906
+ r2_key: string;
907
+ resource: string | null;
908
+ sha256: string;
909
+ bytes: number;
910
+ fence: number | null;
911
+ mime_type: string;
912
+ produced_at: number;
913
+ produced_by: string;
914
+ expires_at: number | null;
915
+ tombstoned: number;
916
+ tags: string[];
917
+ } | null>;
918
+ download(key: string): Promise<{
919
+ body: ReadableStream;
920
+ contentType: string;
921
+ contentLength: number | null;
922
+ }>;
923
+ addRelationship(fromKey: string, toKeyOrUri: string, type: string, metadata?: Record<string, unknown>): Promise<ArtifactRelationshipOkResponse>;
924
+ listRelationships(key: string): Promise<ArtifactRelationshipListResponse>;
925
+ readText(key: string): Promise<{
926
+ content: string;
927
+ mimeType: string;
928
+ }>;
929
+ };
930
+ templates: {
931
+ instantiate(req: Parameters<(req: InstantiateTemplateRequest) => Promise<InstantiateTemplateResponse>>[0]): Promise<{
932
+ ok: true;
933
+ created_entities: string[];
934
+ created_relationships: number;
935
+ journal_seq: number;
936
+ }>;
937
+ list(): Promise<{
938
+ templates: {
939
+ name: string;
940
+ type: string;
941
+ description: string | null;
942
+ variables: string[];
943
+ }[];
944
+ ok: true;
945
+ }>;
946
+ };
419
947
  };
420
948
 
421
- declare function createSearchMethods(client: TilaClient, projectId: string): {
422
- search(q: string, opts?: {
423
- limit?: number;
424
- }): Promise<UnifiedSearchResponse>;
425
- };
949
+ /**
950
+ * Pure prefix/strip primitives for the namespace coexistence convention.
951
+ * No I/O — shared by all four resource adapters in namespace.ts.
952
+ */
953
+ /**
954
+ * Validates that a namespace string matches /^[a-z][a-z0-9_-]*$/.
955
+ * Throws TypeError for empty strings or strings containing invalid characters.
956
+ */
957
+ declare function validateNamespace(ns: string): void;
958
+ /**
959
+ * Returns "${ns}_${name}".
960
+ * Throws a plain Error (not TilaApiError) if the name already starts with "${ns}_".
961
+ */
962
+ declare function applyPrefix(ns: string, name: string): string;
963
+ /**
964
+ * Returns the name with a leading "${ns}_" removed if present; otherwise returns name unchanged.
965
+ * Never throws — tolerant strip for mixed-namespace lists.
966
+ */
967
+ declare function stripPrefix(ns: string, name: string): string;
426
968
 
427
969
  type ErrorListener = (err: TilaApiError | Error) => void;
428
970
  interface ClaimHandleOptions {
@@ -461,4 +1003,154 @@ declare class ClaimHandle {
461
1003
  }
462
1004
  declare function withClaim<T>(client: TilaClient, projectId: string, resource: string, mode: ClaimMode, ttlMs: number, callback: (handle: ClaimHandle) => Promise<T>): Promise<T>;
463
1005
 
464
- export { type ArtifactUploadOpts, ClaimHandle, type ClaimHandleOptions, type ClientOptions, type IndexCreateOpts, type RetryOptions, TILA_ERRORS, TilaApiError, TilaClient, type TilaErrorCode, createArtifactMethods, createClaimMethods, createEntityMethods, createGateMethods, createIndexMethods, createJournalMethods, createPresenceMethods, createRecordMethods, createSchemaMethods, createSearchMethods, createSignalMethods, createSummaryMethods, createTaskMethods, createTemplateMethods, createTokenMethods, createWorkUnitMethods, exchangeGitHubToken, isTilaApiError, withClaim, withRetry };
1006
+ /**
1007
+ * RemoteBackend implements EntityBackend, CoordinationBackend, and the five
1008
+ * new domain backends (JournalBackend, GateBackend, SignalBackend, SchemaBackend,
1009
+ * SummaryBackend) by delegating to TilaClient HTTP calls and unwrapping response
1010
+ * envelopes.
1011
+ *
1012
+ * ArtifactBackend is intentionally NOT implemented here because EntityBackend
1013
+ * and ArtifactBackend both declare `get` and `list` with incompatible return
1014
+ * types — a single class cannot satisfy both interfaces simultaneously.
1015
+ * See RemoteArtifactBackend below.
1016
+ */
1017
+ declare class RemoteBackend implements EntityBackend, CoordinationBackend, JournalBackend, GateBackend, SignalBackend, SchemaBackend, SummaryBackend {
1018
+ private client;
1019
+ private projectId;
1020
+ constructor(client: TilaClient, projectId: string);
1021
+ create(input: CreateEntityInput): Promise<Entity>;
1022
+ get(id: string): Promise<Entity | null>;
1023
+ list(filter?: EntityListFilter): Promise<Entity[]>;
1024
+ update(id: string, data: Partial<Entity["data"]>): Promise<Entity>;
1025
+ archive(id: string): Promise<void>;
1026
+ addRelationship(input: RelationshipInput): Promise<{
1027
+ created: boolean;
1028
+ }>;
1029
+ listRelationships(filter?: RelationshipFilter): Promise<EntityRelationship[]>;
1030
+ removeRelationship(input: RelationshipInput): Promise<{
1031
+ removed: boolean;
1032
+ }>;
1033
+ listReady(filter?: ReadyFilter): Promise<Entity[]>;
1034
+ tree(_rootId?: string): Promise<EntityTree>;
1035
+ updateWithFence(id: string, data: Partial<Entity["data"]>, fence: number): Promise<Entity>;
1036
+ addArtifactRef(input: AddArtifactRefInput): Promise<void>;
1037
+ listArtifactRefs(entityId: string): Promise<EntityArtifactReference[]>;
1038
+ acquire(resource: string, machine: string, user: string, mode: "exclusive" | "owner" | "presence", ttlMs: number): Promise<AcquireResult>;
1039
+ renew(resource: string, _machine: string, _user: string, fence: number, ttlMs: number): Promise<RenewResult>;
1040
+ release(resource: string, fence: number): Promise<void>;
1041
+ state(resource: string): Promise<Claim | null>;
1042
+ heartbeat(machine: string, info?: Record<string, unknown>): Promise<void>;
1043
+ listPresence(): Promise<Presence[]>;
1044
+ listClaims(): Promise<Claim[]>;
1045
+ listJournal(query: JournalQuery): Promise<JournalEvent[]>;
1046
+ createGate(resource: string, awaitType: string, fence: number, timeoutAt?: number): Promise<GateRecord>;
1047
+ listGates(filter?: GateFilter): Promise<GateRecord[]>;
1048
+ resolveGate(gateId: string, resolution?: string): Promise<void>;
1049
+ cancelGate(gateId: string): Promise<void>;
1050
+ sendSignal(input: SendSignalInput, _createdBy: string): Promise<{
1051
+ id: string;
1052
+ }>;
1053
+ listSignals(_tokenName: string): Promise<SignalRecord[]>;
1054
+ ackSignal(signalId: string): Promise<{
1055
+ found: boolean;
1056
+ }>;
1057
+ getCurrentSchema(): Promise<SchemaRecord>;
1058
+ applySchema(input: ApplySchemaInput): Promise<ApplySchemaOutput>;
1059
+ getSummary(): Promise<ProjectSummary>;
1060
+ }
1061
+ /**
1062
+ * RemoteArtifactBackend implements ArtifactBackend separately from RemoteBackend
1063
+ * because EntityBackend and ArtifactBackend both declare `get` and `list` with
1064
+ * incompatible return types. A single class cannot implement both interfaces.
1065
+ *
1066
+ * Both classes are constructed in resolveContext() and wired into their
1067
+ * respective CommandContext slots independently.
1068
+ */
1069
+ declare class RemoteArtifactBackend implements ArtifactBackend {
1070
+ private client;
1071
+ private projectId;
1072
+ constructor(client: TilaClient, projectId: string);
1073
+ put(options: ArtifactPutOptions): Promise<{
1074
+ key: string;
1075
+ bytes: number;
1076
+ }>;
1077
+ get(key: string): Promise<{
1078
+ body: ReadableStream;
1079
+ contentType: string;
1080
+ metadata: Record<string, string>;
1081
+ } | null>;
1082
+ list(prefix: string): Promise<{
1083
+ key: string;
1084
+ size: number;
1085
+ }[]>;
1086
+ delete(key: string): Promise<void>;
1087
+ listPointers(query: {
1088
+ resource?: string;
1089
+ kind?: string;
1090
+ }): Promise<ArtifactPointerRecord[]>;
1091
+ addRelationship(fromKey: string, toKeyOrUri: {
1092
+ to_key?: string;
1093
+ to_uri?: string;
1094
+ }, type: string): Promise<void>;
1095
+ listRelationships(key: string): Promise<ArtifactRelationship[]>;
1096
+ searchArtifacts(query: {
1097
+ q: string;
1098
+ kind?: string;
1099
+ resource?: string;
1100
+ limit?: number;
1101
+ }): Promise<ArtifactSearchResultRecord[]>;
1102
+ grepArtifacts(query: {
1103
+ pattern: string;
1104
+ kind?: string;
1105
+ resource?: string;
1106
+ regex?: boolean;
1107
+ limit?: number;
1108
+ }): Promise<ArtifactGrepResponse>;
1109
+ listIndexEntries(indexKey: string): Promise<ArtifactIndexEntry[]>;
1110
+ getLatest(kind: string, resource: string): Promise<ArtifactPointerRecord | null>;
1111
+ writeText(content: string, opts: {
1112
+ kind: string;
1113
+ mimeType?: string;
1114
+ resource?: string;
1115
+ fence?: number;
1116
+ }): Promise<{
1117
+ key: string;
1118
+ bytes: number;
1119
+ }>;
1120
+ readText(key: string): Promise<{
1121
+ content: string;
1122
+ mimeType: string;
1123
+ } | null>;
1124
+ }
1125
+ /**
1126
+ * RemoteRecordBackend implements RecordBackend over the Worker record HTTP
1127
+ * routes (see `packages/worker/src/routes/records.ts`). Paths mirror the SDK
1128
+ * record methods (`packages/sdk/src/records.ts`) so the two stay in lockstep.
1129
+ *
1130
+ * Wire ↔ RecordRow mapping: the mutate/get responses return a `record`
1131
+ * (`RecordItem`, no fence) plus a top-level `fence`. RecordBackend returns
1132
+ * `RecordRow`, which is `RecordItem` extended with `fence`, so each method
1133
+ * merges the two: `{ ...result.record, fence: result.fence }`.
1134
+ *
1135
+ * Like the SDK, multi-segment keys are encoded segment-by-segment so embedded
1136
+ * slashes survive routing (the Worker matches `:key{.+}`).
1137
+ */
1138
+ declare class RemoteRecordBackend implements RecordBackend {
1139
+ private client;
1140
+ private projectId;
1141
+ constructor(client: TilaClient, projectId: string);
1142
+ private base;
1143
+ /** Encode a record key per-segment so embedded `/` separators are preserved. */
1144
+ private encodeKey;
1145
+ createRecord(input: CreateRecordInput): Promise<RecordRow>;
1146
+ setRecord(input: SetRecordInput): Promise<RecordRow>;
1147
+ getRecord(type: string, key: string): Promise<RecordRow | null>;
1148
+ patchRecord(input: PatchRecordInput): Promise<RecordRow>;
1149
+ archiveRecord(input: ArchiveRecordInput): Promise<RecordRow>;
1150
+ unarchiveRecord(input: ArchiveRecordInput): Promise<RecordRow>;
1151
+ listRecords(filter: RecordListFilter): Promise<RecordPage<RecordListItem>>;
1152
+ listRecordHistory(type: string, key: string, opts?: RecordHistoryOptions): Promise<RecordPage<RecordHistoryItem>>;
1153
+ listRecordTypesInUse(): Promise<string[]>;
1154
+ }
1155
+
1156
+ export { type ArtifactUploadOpts, ClaimHandle, type ClaimHandleOptions, type ClientOptions, type IndexCreateOpts, RemoteArtifactBackend, RemoteBackend, RemoteRecordBackend, type RetryOptions, TILA_ERRORS, TilaApiError, TilaClient, type TilaErrorCode, type TilaFacade, applyPrefix, createArtifactMethods, createClaimMethods, createEntityMethods, createGateMethods, createIndexMethods, createJournalMethods, createNamespace, createPresenceMethods, createRecordMethods, createSchemaMethods, createSearchMethods, createSignalMethods, createSummaryMethods, createTaskMethods, createTemplateMethods, createTila, createTokenMethods, createWorkUnitMethods, exchangeGitHubToken, isTilaApiError, stripPrefix, validateNamespace, withClaim, withRetry };