@opendatalabs/personal-server-ts-core 0.0.1-canary.01ca694 → 0.0.1-canary.052d47e
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/api/index.d.ts +282 -9
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +867 -163
- package/dist/api/index.js.map +1 -1
- package/dist/auth/request.d.ts.map +1 -1
- package/dist/auth/request.js.map +1 -1
- package/dist/client.d.ts +8 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +21 -3
- package/dist/client.js.map +1 -1
- package/dist/contracts/binary.d.ts +12 -0
- package/dist/contracts/binary.d.ts.map +1 -1
- package/dist/contracts/binary.js +31 -0
- package/dist/contracts/binary.js.map +1 -1
- package/dist/contracts/data.d.ts +51 -5
- package/dist/contracts/data.d.ts.map +1 -1
- package/dist/contracts/data.js +166 -30
- package/dist/contracts/data.js.map +1 -1
- package/dist/contracts/grants.d.ts +7 -5
- package/dist/contracts/grants.d.ts.map +1 -1
- package/dist/contracts/grants.js +60 -37
- package/dist/contracts/grants.js.map +1 -1
- package/dist/contracts/index.d.ts +1 -1
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +1 -1
- package/dist/contracts/index.js.map +1 -1
- package/dist/derivatives/api.d.ts +48 -0
- package/dist/derivatives/api.d.ts.map +1 -0
- package/dist/derivatives/api.js +366 -0
- package/dist/derivatives/api.js.map +1 -0
- package/dist/derivatives/compute.d.ts +106 -0
- package/dist/derivatives/compute.d.ts.map +1 -0
- package/dist/derivatives/compute.js +414 -0
- package/dist/derivatives/compute.js.map +1 -0
- package/dist/derivatives/e2ee/aad.d.ts +22 -0
- package/dist/derivatives/e2ee/aad.d.ts.map +1 -0
- package/dist/derivatives/e2ee/aad.js +32 -0
- package/dist/derivatives/e2ee/aad.js.map +1 -0
- package/dist/derivatives/e2ee/attestation.d.ts +134 -0
- package/dist/derivatives/e2ee/attestation.d.ts.map +1 -0
- package/dist/derivatives/e2ee/attestation.js +248 -0
- package/dist/derivatives/e2ee/attestation.js.map +1 -0
- package/dist/derivatives/e2ee/index.d.ts +6 -0
- package/dist/derivatives/e2ee/index.d.ts.map +1 -0
- package/dist/derivatives/e2ee/index.js +6 -0
- package/dist/derivatives/e2ee/index.js.map +1 -0
- package/dist/derivatives/e2ee/jcs.d.ts +17 -0
- package/dist/derivatives/e2ee/jcs.d.ts.map +1 -0
- package/dist/derivatives/e2ee/jcs.js +55 -0
- package/dist/derivatives/e2ee/jcs.js.map +1 -0
- package/dist/derivatives/e2ee/phala.d.ts +62 -0
- package/dist/derivatives/e2ee/phala.d.ts.map +1 -0
- package/dist/derivatives/e2ee/phala.js +168 -0
- package/dist/derivatives/e2ee/phala.js.map +1 -0
- package/dist/derivatives/e2ee/suite.d.ts +56 -0
- package/dist/derivatives/e2ee/suite.d.ts.map +1 -0
- package/dist/derivatives/e2ee/suite.js +164 -0
- package/dist/derivatives/e2ee/suite.js.map +1 -0
- package/dist/derivatives/index.d.ts +10 -0
- package/dist/derivatives/index.d.ts.map +1 -0
- package/dist/derivatives/index.js +10 -0
- package/dist/derivatives/index.js.map +1 -0
- package/dist/derivatives/inference.d.ts +151 -0
- package/dist/derivatives/inference.d.ts.map +1 -0
- package/dist/derivatives/inference.js +262 -0
- package/dist/derivatives/inference.js.map +1 -0
- package/dist/derivatives/prompt.d.ts +64 -0
- package/dist/derivatives/prompt.d.ts.map +1 -0
- package/dist/derivatives/prompt.js +193 -0
- package/dist/derivatives/prompt.js.map +1 -0
- package/dist/derivatives/registration.d.ts +54 -0
- package/dist/derivatives/registration.d.ts.map +1 -0
- package/dist/derivatives/registration.js +180 -0
- package/dist/derivatives/registration.js.map +1 -0
- package/dist/derivatives/scheduler.d.ts +84 -0
- package/dist/derivatives/scheduler.d.ts.map +1 -0
- package/dist/derivatives/scheduler.js +257 -0
- package/dist/derivatives/scheduler.js.map +1 -0
- package/dist/derivatives/store.d.ts +14 -0
- package/dist/derivatives/store.d.ts.map +1 -0
- package/dist/derivatives/store.js +77 -0
- package/dist/derivatives/store.js.map +1 -0
- package/dist/derivatives/types.d.ts +92 -0
- package/dist/derivatives/types.d.ts.map +1 -0
- package/dist/derivatives/types.js +27 -0
- package/dist/derivatives/types.js.map +1 -0
- package/dist/errors/catalog.d.ts +75 -0
- package/dist/errors/catalog.d.ts.map +1 -1
- package/dist/errors/catalog.js +104 -0
- package/dist/errors/catalog.js.map +1 -1
- package/dist/grants/index.d.ts +2 -1
- package/dist/grants/index.d.ts.map +1 -1
- package/dist/grants/index.js +1 -1
- package/dist/grants/index.js.map +1 -1
- package/dist/keys/index.d.ts +1 -0
- package/dist/keys/index.d.ts.map +1 -1
- package/dist/keys/index.js +1 -1
- package/dist/keys/index.js.map +1 -1
- package/dist/keys/public-only-account.d.ts +8 -0
- package/dist/keys/public-only-account.d.ts.map +1 -0
- package/dist/keys/public-only-account.js +21 -0
- package/dist/keys/public-only-account.js.map +1 -0
- package/dist/keys/server-account.d.ts +2 -2
- package/dist/keys/server-account.d.ts.map +1 -1
- package/dist/lineage/attestation.d.ts +42 -0
- package/dist/lineage/attestation.d.ts.map +1 -0
- package/dist/lineage/attestation.js +25 -0
- package/dist/lineage/attestation.js.map +1 -0
- package/dist/lineage/gateway.d.ts +105 -0
- package/dist/lineage/gateway.d.ts.map +1 -0
- package/dist/lineage/gateway.js +242 -0
- package/dist/lineage/gateway.js.map +1 -0
- package/dist/lineage/index.d.ts +5 -0
- package/dist/lineage/index.d.ts.map +1 -0
- package/dist/lineage/index.js +5 -0
- package/dist/lineage/index.js.map +1 -0
- package/dist/lineage/lineage.d.ts +141 -0
- package/dist/lineage/lineage.d.ts.map +1 -0
- package/dist/lineage/lineage.js +255 -0
- package/dist/lineage/lineage.js.map +1 -0
- package/dist/logging/access-log.d.ts +10 -1
- package/dist/logging/access-log.d.ts.map +1 -1
- package/dist/mcp/activity.d.ts.map +1 -1
- package/dist/mcp/activity.js.map +1 -1
- package/dist/mcp/connection-api.d.ts.map +1 -1
- package/dist/mcp/connection-api.js +0 -1
- package/dist/mcp/connection-api.js.map +1 -1
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/read-client.d.ts +61 -1
- package/dist/mcp/read-client.d.ts.map +1 -1
- package/dist/mcp/read-client.js +397 -42
- package/dist/mcp/read-client.js.map +1 -1
- package/dist/mcp/resources.d.ts +37 -0
- package/dist/mcp/resources.d.ts.map +1 -0
- package/dist/mcp/resources.js +114 -0
- package/dist/mcp/resources.js.map +1 -0
- package/dist/mcp/search/index.d.ts.map +1 -1
- package/dist/mcp/search/index.js +108 -21
- package/dist/mcp/search/index.js.map +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +27 -9
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/session.d.ts +160 -0
- package/dist/mcp/session.d.ts.map +1 -0
- package/dist/mcp/session.js +243 -0
- package/dist/mcp/session.js.map +1 -0
- package/dist/mcp/tools.d.ts +29 -3
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +515 -48
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/payment/index.d.ts +2 -0
- package/dist/payment/index.d.ts.map +1 -0
- package/dist/payment/index.js +2 -0
- package/dist/payment/index.js.map +1 -0
- package/dist/payment/x402.d.ts +155 -0
- package/dist/payment/x402.d.ts.map +1 -0
- package/dist/payment/x402.js +402 -0
- package/dist/payment/x402.js.map +1 -0
- package/dist/policy/data-read.d.ts +18 -2
- package/dist/policy/data-read.d.ts.map +1 -1
- package/dist/policy/data-read.js +80 -49
- package/dist/policy/data-read.js.map +1 -1
- package/dist/policy/data-write.d.ts +69 -0
- package/dist/policy/data-write.d.ts.map +1 -0
- package/dist/policy/data-write.js +131 -0
- package/dist/policy/data-write.js.map +1 -0
- package/dist/policy/index.d.ts +3 -1
- package/dist/policy/index.d.ts.map +1 -1
- package/dist/policy/index.js +3 -1
- package/dist/policy/index.js.map +1 -1
- package/dist/policy/signed-artifacts.d.ts +17 -0
- package/dist/policy/signed-artifacts.d.ts.map +1 -0
- package/dist/policy/signed-artifacts.js +110 -0
- package/dist/policy/signed-artifacts.js.map +1 -0
- package/dist/ports/index.d.ts +159 -32
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js +6 -5
- package/dist/ports/index.js.map +1 -1
- package/dist/schemas/server-config.d.ts +49 -4
- package/dist/schemas/server-config.d.ts.map +1 -1
- package/dist/schemas/server-config.js +95 -13
- package/dist/schemas/server-config.js.map +1 -1
- package/dist/signing/index.d.ts +2 -2
- package/dist/signing/index.d.ts.map +1 -1
- package/dist/signing/index.js +1 -1
- package/dist/signing/index.js.map +1 -1
- package/dist/signing/request-signer.d.ts +2 -0
- package/dist/signing/request-signer.d.ts.map +1 -1
- package/dist/signing/request-signer.js +1 -0
- package/dist/signing/request-signer.js.map +1 -1
- package/dist/signing/signer.d.ts +27 -25
- package/dist/signing/signer.d.ts.map +1 -1
- package/dist/signing/signer.js +27 -51
- package/dist/signing/signer.js.map +1 -1
- package/dist/storage/adapters/index.d.ts +1 -1
- package/dist/storage/adapters/index.d.ts.map +1 -1
- package/dist/storage/adapters/index.js +1 -1
- package/dist/storage/adapters/index.js.map +1 -1
- package/dist/storage/adapters/interface.d.ts +10 -0
- package/dist/storage/adapters/interface.d.ts.map +1 -1
- package/dist/storage/adapters/sdk.d.ts +11 -1
- package/dist/storage/adapters/sdk.d.ts.map +1 -1
- package/dist/storage/adapters/sdk.js +38 -3
- package/dist/storage/adapters/sdk.js.map +1 -1
- package/dist/storage/adapters/vana.d.ts +3 -0
- package/dist/storage/adapters/vana.d.ts.map +1 -1
- package/dist/storage/adapters/vana.js +95 -2
- package/dist/storage/adapters/vana.js.map +1 -1
- package/dist/storage/blocks/errors.d.ts.map +1 -1
- package/dist/storage/blocks/errors.js.map +1 -1
- package/dist/storage/blocks/index.d.ts +2 -0
- package/dist/storage/blocks/index.d.ts.map +1 -1
- package/dist/storage/blocks/index.js +2 -0
- package/dist/storage/blocks/index.js.map +1 -1
- package/dist/storage/blocks/select.d.ts +29 -0
- package/dist/storage/blocks/select.d.ts.map +1 -0
- package/dist/storage/blocks/select.js +120 -0
- package/dist/storage/blocks/select.js.map +1 -0
- package/dist/storage/blocks/types.d.ts +7 -0
- package/dist/storage/blocks/types.d.ts.map +1 -1
- package/dist/storage/index/manager.d.ts +30 -2
- package/dist/storage/index/manager.d.ts.map +1 -1
- package/dist/storage/index/schema.d.ts +1 -1
- package/dist/storage/index/schema.js +1 -1
- package/dist/storage/index/types.d.ts +6 -1
- package/dist/storage/index/types.d.ts.map +1 -1
- package/dist/sync/data-point-feed.d.ts +35 -0
- package/dist/sync/data-point-feed.d.ts.map +1 -0
- package/dist/sync/data-point-feed.js +122 -0
- package/dist/sync/data-point-feed.js.map +1 -0
- package/dist/sync/data-point-id.d.ts +7 -0
- package/dist/sync/data-point-id.d.ts.map +1 -0
- package/dist/sync/data-point-id.js +16 -0
- package/dist/sync/data-point-id.js.map +1 -0
- package/dist/sync/delete-data-port.d.ts +50 -0
- package/dist/sync/delete-data-port.d.ts.map +1 -0
- package/dist/sync/delete-data-port.js +244 -0
- package/dist/sync/delete-data-port.js.map +1 -0
- package/dist/sync/engine/sync-manager.d.ts +16 -4
- package/dist/sync/engine/sync-manager.d.ts.map +1 -1
- package/dist/sync/engine/sync-manager.js +93 -32
- package/dist/sync/engine/sync-manager.js.map +1 -1
- package/dist/sync/index.d.ts +7 -0
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +7 -0
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/issues.d.ts.map +1 -1
- package/dist/sync/issues.js +21 -3
- package/dist/sync/issues.js.map +1 -1
- package/dist/sync/pending-blob-deletions.d.ts +29 -0
- package/dist/sync/pending-blob-deletions.d.ts.map +1 -0
- package/dist/sync/pending-blob-deletions.js +116 -0
- package/dist/sync/pending-blob-deletions.js.map +1 -0
- package/dist/sync/retry-memory.d.ts +33 -0
- package/dist/sync/retry-memory.d.ts.map +1 -0
- package/dist/sync/retry-memory.js +68 -0
- package/dist/sync/retry-memory.js.map +1 -0
- package/dist/sync/scope-deletions.d.ts +155 -0
- package/dist/sync/scope-deletions.d.ts.map +1 -0
- package/dist/sync/scope-deletions.js +225 -0
- package/dist/sync/scope-deletions.js.map +1 -0
- package/dist/sync/tombstone.d.ts +27 -0
- package/dist/sync/tombstone.d.ts.map +1 -0
- package/dist/sync/tombstone.js +28 -0
- package/dist/sync/tombstone.js.map +1 -0
- package/dist/sync/workers/delete.d.ts +152 -31
- package/dist/sync/workers/delete.d.ts.map +1 -1
- package/dist/sync/workers/delete.js +457 -55
- package/dist/sync/workers/delete.js.map +1 -1
- package/dist/sync/workers/download.d.ts +108 -27
- package/dist/sync/workers/download.d.ts.map +1 -1
- package/dist/sync/workers/download.js +321 -126
- package/dist/sync/workers/download.js.map +1 -1
- package/dist/sync/workers/upload.d.ts +65 -10
- package/dist/sync/workers/upload.d.ts.map +1 -1
- package/dist/sync/workers/upload.js +371 -42
- package/dist/sync/workers/upload.js.map +1 -1
- package/dist/test-utils/e2ee-fixtures.d.ts +94 -0
- package/dist/test-utils/e2ee-fixtures.d.ts.map +1 -0
- package/dist/test-utils/e2ee-fixtures.js +116 -0
- package/dist/test-utils/e2ee-fixtures.js.map +1 -0
- package/dist/test-utils/e2ee-gateway.d.ts +61 -0
- package/dist/test-utils/e2ee-gateway.d.ts.map +1 -0
- package/dist/test-utils/e2ee-gateway.js +248 -0
- package/dist/test-utils/e2ee-gateway.js.map +1 -0
- package/dist/test-utils/index.d.ts +3 -0
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/index.js +3 -0
- package/dist/test-utils/index.js.map +1 -1
- package/dist/test-utils/memory-storage.d.ts +12 -0
- package/dist/test-utils/memory-storage.d.ts.map +1 -0
- package/dist/test-utils/memory-storage.js +146 -0
- package/dist/test-utils/memory-storage.js.map +1 -0
- package/dist/test-utils/wallet.d.ts +6 -0
- package/dist/test-utils/wallet.d.ts.map +1 -1
- package/dist/test-utils/wallet.js +46 -0
- package/dist/test-utils/wallet.js.map +1 -1
- package/dist/write/attribution.d.ts +185 -0
- package/dist/write/attribution.d.ts.map +1 -0
- package/dist/write/attribution.js +450 -0
- package/dist/write/attribution.js.map +1 -0
- package/dist/write/authorize.d.ts +77 -0
- package/dist/write/authorize.d.ts.map +1 -0
- package/dist/write/authorize.js +109 -0
- package/dist/write/authorize.js.map +1 -0
- package/dist/write/index.d.ts +5 -0
- package/dist/write/index.d.ts.map +1 -0
- package/dist/write/index.js +5 -0
- package/dist/write/index.js.map +1 -0
- package/dist/write/route.d.ts +61 -0
- package/dist/write/route.d.ts.map +1 -0
- package/dist/write/route.js +132 -0
- package/dist/write/route.js.map +1 -0
- package/dist/write/session.d.ts +96 -0
- package/dist/write/session.d.ts.map +1 -0
- package/dist/write/session.js +136 -0
- package/dist/write/session.js.map +1 -0
- package/package.json +19 -3
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP surface of the compute layer, mounted under `/v1/derivatives`:
|
|
3
|
+
*
|
|
4
|
+
* POST /questions register (builder write auth or owner)
|
|
5
|
+
* GET /questions list (owner; builder with ?derivedScope=)
|
|
6
|
+
* GET /questions/:id status (owner or the registering builder)
|
|
7
|
+
* POST /questions/:id/recompute owner or the registering builder
|
|
8
|
+
* DELETE /questions/:id owner or the registering builder
|
|
9
|
+
*
|
|
10
|
+
* Builder authentication is the Write API's: a write-session bearer token
|
|
11
|
+
* plus the X-Vana-Write-Signature proof over the request, authorized for
|
|
12
|
+
* `write:<derivedScope>` (api-auth authorizeWrite). No new credential.
|
|
13
|
+
*
|
|
14
|
+
* The proof signs the request URI INCLUDING its query string (see
|
|
15
|
+
* canonicalSignedUri in write/attribution.ts), because on the list route the
|
|
16
|
+
* query decides the authorization: `?derivedScope=X` is the scope the caller
|
|
17
|
+
* is authorized against, and a proof that did not commit to it could be
|
|
18
|
+
* captured on one scope and replayed on another.
|
|
19
|
+
*/
|
|
20
|
+
import type { PersonalServerApiAuthPort, PersonalServerApiDispatchOptions } from "../api/index.js";
|
|
21
|
+
import type { RecomputeScheduler } from "./scheduler.js";
|
|
22
|
+
import { type QuestionStore } from "./types.js";
|
|
23
|
+
/** Registration bodies are small; anything larger is refused up front. */
|
|
24
|
+
export declare const MAX_QUESTION_BODY_BYTES: number;
|
|
25
|
+
export interface PersonalServerDerivativesApiDeps {
|
|
26
|
+
auth: Pick<PersonalServerApiAuthPort, "authorizeOwner" | "authorizeWrite" | "authorizeWriteSession" | "authorizeBuilderRead">;
|
|
27
|
+
/** Absent = the compute layer is not wired; every route answers 503. */
|
|
28
|
+
compute?: {
|
|
29
|
+
store: QuestionStore;
|
|
30
|
+
scheduler: Pick<RecomputeScheduler, "requestRecompute" | "markSourceChanged"> & {
|
|
31
|
+
/**
|
|
32
|
+
* Next scheduled automatic retry of a failed question (ISO time), or
|
|
33
|
+
* null. Optional so a minimal scheduler stays a valid dependency; the
|
|
34
|
+
* status route then reports no retry.
|
|
35
|
+
*/
|
|
36
|
+
nextRetryAt?(questionId: string): string | null;
|
|
37
|
+
/** True while a retry compute is running (timer fired, not settled). */
|
|
38
|
+
retryInFlight?(questionId: string): boolean;
|
|
39
|
+
};
|
|
40
|
+
} | null;
|
|
41
|
+
now?: () => Date;
|
|
42
|
+
createQuestionId?: () => string;
|
|
43
|
+
logger?: {
|
|
44
|
+
info?(payload: Record<string, unknown>, message: string): void;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export declare function handlePersonalServerDerivativesRequest(request: Request, deps: PersonalServerDerivativesApiDeps, options?: PersonalServerApiDispatchOptions): Promise<Response>;
|
|
48
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/derivatives/api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under `/v1/derivatives`:
|
|
3
|
+
*
|
|
4
|
+
* POST /questions register (builder write auth or owner)
|
|
5
|
+
* GET /questions list (owner; builder with ?derivedScope=)
|
|
6
|
+
* GET /questions/:id status (owner or the registering builder)
|
|
7
|
+
* POST /questions/:id/recompute owner or the registering builder
|
|
8
|
+
* DELETE /questions/:id owner or the registering builder
|
|
9
|
+
*
|
|
10
|
+
* Builder authentication is the Write API's: a write-session bearer token
|
|
11
|
+
* plus the X-Vana-Write-Signature proof over the request, authorized for
|
|
12
|
+
* `write:<derivedScope>` (api-auth authorizeWrite). No new credential.
|
|
13
|
+
*
|
|
14
|
+
* The proof signs the request URI INCLUDING its query string (see
|
|
15
|
+
* canonicalSignedUri in write/attribution.ts), because on the list route the
|
|
16
|
+
* query decides the authorization: `?derivedScope=X` is the scope the caller
|
|
17
|
+
* is authorized against, and a proof that did not commit to it could be
|
|
18
|
+
* captured on one scope and replayed on another.
|
|
19
|
+
*/
|
|
20
|
+
import { ContentTooLargeError, DerivativeComputeUnavailableError, DerivativeDerivedScopeRequiredError, DerivativeQuestionNotFoundError, DerivativeSourceNotGrantedError, ProtocolError, } from "../errors/catalog.js";
|
|
21
|
+
import { parseJsonObjectBody } from "../contracts/http.js";
|
|
22
|
+
import { parseDataScopeContract } from "../contracts/data.js";
|
|
23
|
+
import { selectedGrantId } from "../api/index.js";
|
|
24
|
+
import { createQuestionRegistration, parseQuestionInput, uncoveredSourceScopes, } from "./registration.js";
|
|
25
|
+
import { questionRegistrationView, } from "./types.js";
|
|
26
|
+
/** Registration bodies are small; anything larger is refused up front. */
|
|
27
|
+
export const MAX_QUESTION_BODY_BYTES = 16 * 1024;
|
|
28
|
+
/** Poll hint served while a retry compute is in flight (no scheduled time). */
|
|
29
|
+
const RETRY_IN_FLIGHT_POLL_SECONDS = 5;
|
|
30
|
+
function jsonResponse(body, init) {
|
|
31
|
+
const headers = new Headers(init?.headers);
|
|
32
|
+
headers.set("Content-Type", "application/json");
|
|
33
|
+
return new Response(JSON.stringify(body), { ...init, headers });
|
|
34
|
+
}
|
|
35
|
+
function errorResponse(status, errorCode, message) {
|
|
36
|
+
return jsonResponse({ error: { code: status, errorCode, message } }, { status });
|
|
37
|
+
}
|
|
38
|
+
function stripBasePath(pathname, basePath) {
|
|
39
|
+
if (!basePath || basePath === "/")
|
|
40
|
+
return pathname;
|
|
41
|
+
if (pathname === basePath)
|
|
42
|
+
return "/";
|
|
43
|
+
if (pathname.startsWith(`${basePath}/`))
|
|
44
|
+
return pathname.slice(basePath.length);
|
|
45
|
+
return pathname;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Authorize as the owner or, through the write-session path, as a builder
|
|
49
|
+
* holding `write:<scope>`. Returns the builder result or undefined (owner).
|
|
50
|
+
*/
|
|
51
|
+
async function authorizeOwnerOrWriter(deps, request, scope) {
|
|
52
|
+
if (deps.auth.authorizeWrite) {
|
|
53
|
+
return (await deps.auth.authorizeWrite({ request, scope })) ?? undefined;
|
|
54
|
+
}
|
|
55
|
+
await deps.auth.authorizeOwner(request);
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
function sameBuilder(a, b) {
|
|
59
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Is this a builder call at all? Identity only (no scope is authorized), for
|
|
63
|
+
* the two answers that have no scope to authorize against: an unknown
|
|
64
|
+
* question id and a list call with no `?derivedScope=`. Nothing is disclosed
|
|
65
|
+
* either way, and the caller's proof is handed straight back — the request
|
|
66
|
+
* ends in an error, so it must not burn the proof.
|
|
67
|
+
*/
|
|
68
|
+
async function recognizeWriteSession(deps, request) {
|
|
69
|
+
if (!deps.auth.authorizeWriteSession)
|
|
70
|
+
return undefined;
|
|
71
|
+
const session = (await deps.auth.authorizeWriteSession(request)) ?? undefined;
|
|
72
|
+
await session?.releaseProof?.();
|
|
73
|
+
return session;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The registration a caller may act on, or a 404 for everyone who may not:
|
|
77
|
+
* the owner sees every registration; a builder sees the ones it registered.
|
|
78
|
+
* An id the store does not hold is 404 for any authenticated caller (a
|
|
79
|
+
* builder holding a live write session, or the owner) and 401 for everyone
|
|
80
|
+
* else, so a builder learns nothing from probing ids that it could not learn
|
|
81
|
+
* from probing another builder's ids, which already answers 404.
|
|
82
|
+
*/
|
|
83
|
+
async function loadForCaller(deps, request, store, questionId) {
|
|
84
|
+
const registration = await store.get(questionId);
|
|
85
|
+
if (!registration) {
|
|
86
|
+
// No registration means no derived scope to authorize a builder against,
|
|
87
|
+
// so fall back to identity: a live write session is enough to be told
|
|
88
|
+
// 404. Without it the owner gate decides (and answers 401).
|
|
89
|
+
if (!(await recognizeWriteSession(deps, request))) {
|
|
90
|
+
await deps.auth.authorizeOwner(request);
|
|
91
|
+
}
|
|
92
|
+
throw new DerivativeQuestionNotFoundError({ questionId });
|
|
93
|
+
}
|
|
94
|
+
const writer = await authorizeOwnerOrWriter(deps, request, registration.derivedScope);
|
|
95
|
+
if (writer) {
|
|
96
|
+
const by = registration.registeredBy;
|
|
97
|
+
if (by.kind !== "builder" || !sameBuilder(by.builder, writer.builder)) {
|
|
98
|
+
await writer.releaseProof?.();
|
|
99
|
+
throw new DerivativeQuestionNotFoundError({ questionId });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return { registration, writer };
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* `GET /v1/derivatives/status?derivedScope=<scope>`: the lifecycle of the
|
|
106
|
+
* question behind a derived scope, for the party that will READ the answer.
|
|
107
|
+
*
|
|
108
|
+
* Authorization is the data read's (`authorizeBuilderRead`, i.e. a live
|
|
109
|
+
* grant covering the derived scope, or the owner) — deliberately NOT the
|
|
110
|
+
* write-session path, because a consent-flow reader holds only a bare read
|
|
111
|
+
* entry and can never open a write session. Nothing is served and nothing
|
|
112
|
+
* is charged: this is authorization only, no x402 challenge and no
|
|
113
|
+
* RECORD_DATA_ACCESS receipt, the same bar as the lineage read.
|
|
114
|
+
*
|
|
115
|
+
* The view is deliberately narrow: lifecycle only. The question text, the
|
|
116
|
+
* source scopes, the question id, the registrar and the raw error string
|
|
117
|
+
* stay owner-only — `errorCode` is a closed vocabulary precisely so a
|
|
118
|
+
* stored error like "source scope X is deleted" cannot leak a scope name.
|
|
119
|
+
* One class needs the same care as the raw string: `grant_invalid` arises
|
|
120
|
+
* only from a builder-registered question, so a third-party reader gets
|
|
121
|
+
* `internal` instead of learning who registered.
|
|
122
|
+
* Auth runs before the store lookup, so an uncovered caller cannot probe
|
|
123
|
+
* which scopes have questions behind them.
|
|
124
|
+
*
|
|
125
|
+
* Like every Web3Signed read (data, lineage), the signature covers the
|
|
126
|
+
* path, not the query; per-scope authorization is enforced live against
|
|
127
|
+
* the caller's grant on each request.
|
|
128
|
+
*/
|
|
129
|
+
async function handleStatusRoute(request, url, deps, store, scheduler, now) {
|
|
130
|
+
if (request.method !== "GET") {
|
|
131
|
+
return errorResponse(405, "METHOD_NOT_ALLOWED", "Method not allowed");
|
|
132
|
+
}
|
|
133
|
+
const derivedScopeParam = url.searchParams.get("derivedScope");
|
|
134
|
+
if (!derivedScopeParam) {
|
|
135
|
+
throw new DerivativeDerivedScopeRequiredError();
|
|
136
|
+
}
|
|
137
|
+
// Same grammar gate as every scope-taking route, before anything is
|
|
138
|
+
// authorized: an arbitrary string never reaches the grant policy.
|
|
139
|
+
const scopeResult = parseDataScopeContract(derivedScopeParam);
|
|
140
|
+
if (!scopeResult.ok) {
|
|
141
|
+
return errorResponse(scopeResult.status, scopeResult.body.error, scopeResult.body.message);
|
|
142
|
+
}
|
|
143
|
+
const derivedScope = scopeResult.scope;
|
|
144
|
+
const auth = (await deps.auth.authorizeBuilderRead({
|
|
145
|
+
request,
|
|
146
|
+
scope: derivedScope,
|
|
147
|
+
grantId: selectedGrantId(request, url),
|
|
148
|
+
})) ?? undefined;
|
|
149
|
+
const registrations = await store.list({ derivedScope });
|
|
150
|
+
if (registrations.length === 0) {
|
|
151
|
+
throw new DerivativeQuestionNotFoundError({ derivedScope });
|
|
152
|
+
}
|
|
153
|
+
// Several registrations may share a derived scope, and data serving is
|
|
154
|
+
// registration-agnostic: if ANY of them is ready, the scope has an answer
|
|
155
|
+
// and the reader must not be told "failed" by a duplicate that never
|
|
156
|
+
// wrote anything. Report the most optimistic true state — ready, then an
|
|
157
|
+
// in-flight recompute, then never-computed, then failed — and within a
|
|
158
|
+
// class let the most recently updated registration speak.
|
|
159
|
+
const STATUS_PRECEDENCE = {
|
|
160
|
+
ready: 0,
|
|
161
|
+
stale: 1,
|
|
162
|
+
pending: 2,
|
|
163
|
+
failed: 3,
|
|
164
|
+
};
|
|
165
|
+
const registration = registrations.reduce((best, candidate) => {
|
|
166
|
+
const byStatus = STATUS_PRECEDENCE[candidate.status] - STATUS_PRECEDENCE[best.status];
|
|
167
|
+
if (byStatus !== 0)
|
|
168
|
+
return byStatus < 0 ? candidate : best;
|
|
169
|
+
return candidate.updatedAt >= best.updatedAt ? candidate : best;
|
|
170
|
+
});
|
|
171
|
+
const nextRetryAt = scheduler.nextRetryAt?.(registration.questionId) ?? null;
|
|
172
|
+
// While the retry compute is RUNNING there is no scheduled time, but null
|
|
173
|
+
// would be the terminal "will never retry" signature; serve a short poll
|
|
174
|
+
// hint instead. 0 is never served — it invites a tight poll loop.
|
|
175
|
+
const retryAfterSeconds = nextRetryAt !== null
|
|
176
|
+
? Math.max(1, Math.ceil((Date.parse(nextRetryAt) - now().getTime()) / 1000))
|
|
177
|
+
: scheduler.retryInFlight?.(registration.questionId)
|
|
178
|
+
? RETRY_IN_FLIGHT_POLL_SECONDS
|
|
179
|
+
: null;
|
|
180
|
+
// `grant_invalid` can only come from the live re-check of a REGISTERING
|
|
181
|
+
// BUILDER's grant, which an owner-registered question never runs. Serving
|
|
182
|
+
// it to a third-party reader would therefore disclose the registrar class
|
|
183
|
+
// the rest of this view withholds. The owner and the registrar itself lose
|
|
184
|
+
// nothing — they are the two parties who can act on it — and everyone else
|
|
185
|
+
// reads the honest generic class: something is wrong server-side and no
|
|
186
|
+
// retry is coming.
|
|
187
|
+
const registrarView = auth === undefined ||
|
|
188
|
+
auth.grantId === "owner" ||
|
|
189
|
+
auth.grantId === "policy-bypass" ||
|
|
190
|
+
(registration.registeredBy.kind === "builder" &&
|
|
191
|
+
typeof auth.builder === "string" &&
|
|
192
|
+
sameBuilder(registration.registeredBy.builder, auth.builder));
|
|
193
|
+
const disclosedErrorCode = registration.errorCode === "grant_invalid" && !registrarView
|
|
194
|
+
? "internal"
|
|
195
|
+
: registration.errorCode;
|
|
196
|
+
return jsonResponse({
|
|
197
|
+
derivedScope: registration.derivedScope,
|
|
198
|
+
status: registration.status,
|
|
199
|
+
lastComputedAt: registration.lastComputedAt,
|
|
200
|
+
derivedVersion: registration.derivedVersion,
|
|
201
|
+
derivedCollectedAt: registration.derivedCollectedAt,
|
|
202
|
+
// Null unless failed, whatever an old store row holds: a stale question
|
|
203
|
+
// is a recompute in progress, not a terminal failure.
|
|
204
|
+
errorCode: registration.status === "failed" ? disclosedErrorCode : null,
|
|
205
|
+
retryAfterSeconds,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
export async function handlePersonalServerDerivativesRequest(request, deps, options = {}) {
|
|
209
|
+
try {
|
|
210
|
+
const url = new URL(request.url);
|
|
211
|
+
const pathname = stripBasePath(url.pathname, options.basePath);
|
|
212
|
+
const parts = pathname.split("/").filter(Boolean);
|
|
213
|
+
const isStatusRoute = parts[0] === "status" && parts.length === 1;
|
|
214
|
+
if (!isStatusRoute && (parts[0] !== "questions" || parts.length > 3)) {
|
|
215
|
+
return errorResponse(404, "NOT_FOUND", "Not found");
|
|
216
|
+
}
|
|
217
|
+
const compute = deps.compute;
|
|
218
|
+
if (!compute)
|
|
219
|
+
throw new DerivativeComputeUnavailableError();
|
|
220
|
+
const { store, scheduler } = compute;
|
|
221
|
+
const now = deps.now ?? (() => new Date());
|
|
222
|
+
// /status — the reader-facing lifecycle view of a derived scope.
|
|
223
|
+
if (isStatusRoute) {
|
|
224
|
+
return await handleStatusRoute(request, url, deps, store, scheduler, now);
|
|
225
|
+
}
|
|
226
|
+
// /questions
|
|
227
|
+
if (parts.length === 1) {
|
|
228
|
+
if (request.method === "GET") {
|
|
229
|
+
const derivedScope = url.searchParams.get("derivedScope") ?? undefined;
|
|
230
|
+
if (derivedScope) {
|
|
231
|
+
const writer = await authorizeOwnerOrWriter(deps, request, derivedScope);
|
|
232
|
+
const registrations = await store.list({
|
|
233
|
+
derivedScope,
|
|
234
|
+
...(writer ? { builder: writer.builder } : {}),
|
|
235
|
+
});
|
|
236
|
+
return jsonResponse({
|
|
237
|
+
questions: registrations.map(questionRegistrationView),
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
// The unfiltered list is the owner's. A builder that reached it
|
|
241
|
+
// simply forgot the parameter, so say that instead of 401: the
|
|
242
|
+
// 401 would send a re-handshake-on-401 client through a handshake
|
|
243
|
+
// and then report an authentication problem it does not have.
|
|
244
|
+
if (await recognizeWriteSession(deps, request)) {
|
|
245
|
+
throw new DerivativeDerivedScopeRequiredError();
|
|
246
|
+
}
|
|
247
|
+
await deps.auth.authorizeOwner(request);
|
|
248
|
+
const registrations = await store.list();
|
|
249
|
+
return jsonResponse({
|
|
250
|
+
questions: registrations.map(questionRegistrationView),
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
if (request.method === "POST") {
|
|
254
|
+
// The derived scope decides which write grant must cover the call,
|
|
255
|
+
// so the body is read (from a clone: the proof check reads it too)
|
|
256
|
+
// before authorization. Nothing is stored until auth passed.
|
|
257
|
+
const declared = Number(request.headers.get("content-length") ?? "0");
|
|
258
|
+
if (declared > MAX_QUESTION_BODY_BYTES) {
|
|
259
|
+
throw new ContentTooLargeError({ max: MAX_QUESTION_BODY_BYTES });
|
|
260
|
+
}
|
|
261
|
+
const bodyBytes = new Uint8Array(await request.clone().arrayBuffer());
|
|
262
|
+
if (bodyBytes.byteLength > MAX_QUESTION_BODY_BYTES) {
|
|
263
|
+
throw new ContentTooLargeError({ max: MAX_QUESTION_BODY_BYTES });
|
|
264
|
+
}
|
|
265
|
+
const parsed = await parseJsonObjectBody(request.clone(), "Request body must be valid JSON");
|
|
266
|
+
if (!parsed.ok) {
|
|
267
|
+
return jsonResponse(parsed.result.body, {
|
|
268
|
+
status: parsed.result.status,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
const rawScope = parsed.body.derivedScope;
|
|
272
|
+
const scopeForAuth = typeof rawScope === "string" ? rawScope : "";
|
|
273
|
+
const writer = await authorizeOwnerOrWriter(deps, request, scopeForAuth);
|
|
274
|
+
const registeredBy = writer
|
|
275
|
+
? {
|
|
276
|
+
kind: "builder",
|
|
277
|
+
builder: writer.builder,
|
|
278
|
+
grantId: writer.grantId,
|
|
279
|
+
}
|
|
280
|
+
: { kind: "owner" };
|
|
281
|
+
let registration;
|
|
282
|
+
try {
|
|
283
|
+
if (writer) {
|
|
284
|
+
// Consent: the answer exposes the sources to the builder, so
|
|
285
|
+
// every source must be read-granted to it. Fail closed when
|
|
286
|
+
// the auth port did not hand over the grant's scopes.
|
|
287
|
+
const input = parseQuestionInput(parsed.body);
|
|
288
|
+
const uncovered = uncoveredSourceScopes(input.sourceScopes, writer.grantScopes);
|
|
289
|
+
if (uncovered.length > 0) {
|
|
290
|
+
throw new DerivativeSourceNotGrantedError({ scopes: uncovered });
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
registration = await createQuestionRegistration({
|
|
294
|
+
body: parsed.body,
|
|
295
|
+
registeredBy,
|
|
296
|
+
store,
|
|
297
|
+
questionId: deps.createQuestionId?.() ?? crypto.randomUUID(),
|
|
298
|
+
now,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
catch (err) {
|
|
302
|
+
// Nothing stored: hand the builder's proof back for a retry.
|
|
303
|
+
await writer?.releaseProof?.();
|
|
304
|
+
throw err;
|
|
305
|
+
}
|
|
306
|
+
deps.logger?.info?.({
|
|
307
|
+
questionId: registration.questionId,
|
|
308
|
+
derivedScope: registration.derivedScope,
|
|
309
|
+
sourceScopes: registration.sourceScopes,
|
|
310
|
+
registeredBy: registeredBy.kind,
|
|
311
|
+
...(writer
|
|
312
|
+
? { builder: writer.builder, grantId: writer.grantId }
|
|
313
|
+
: {}),
|
|
314
|
+
}, "Derivative question registered");
|
|
315
|
+
scheduler.requestRecompute(registration.questionId, {
|
|
316
|
+
immediate: true,
|
|
317
|
+
});
|
|
318
|
+
return jsonResponse(questionRegistrationView(registration), {
|
|
319
|
+
status: 201,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
return errorResponse(405, "METHOD_NOT_ALLOWED", "Method not allowed");
|
|
323
|
+
}
|
|
324
|
+
const questionId = decodeURIComponent(parts[1] ?? "");
|
|
325
|
+
// /questions/:id/recompute
|
|
326
|
+
if (parts.length === 3) {
|
|
327
|
+
if (parts[2] !== "recompute") {
|
|
328
|
+
return errorResponse(404, "NOT_FOUND", "Not found");
|
|
329
|
+
}
|
|
330
|
+
if (request.method !== "POST") {
|
|
331
|
+
return errorResponse(405, "METHOD_NOT_ALLOWED", "Method not allowed");
|
|
332
|
+
}
|
|
333
|
+
// Owner, or the registering builder (its retry after a transient
|
|
334
|
+
// failure); same gate as GET / DELETE.
|
|
335
|
+
const { registration } = await loadForCaller(deps, request, store, questionId);
|
|
336
|
+
scheduler.requestRecompute(questionId, { immediate: true });
|
|
337
|
+
// The same registration view every other route returns, so a client
|
|
338
|
+
// needs one schema. The status is the one the scheduled run starts
|
|
339
|
+
// from: a question that never computed stays `pending`, anything else
|
|
340
|
+
// is `stale` until the run lands.
|
|
341
|
+
return jsonResponse(questionRegistrationView({
|
|
342
|
+
...registration,
|
|
343
|
+
status: registration.status === "pending" ? "pending" : "stale",
|
|
344
|
+
}), { status: 202 });
|
|
345
|
+
}
|
|
346
|
+
// /questions/:id
|
|
347
|
+
if (request.method === "GET") {
|
|
348
|
+
const { registration } = await loadForCaller(deps, request, store, questionId);
|
|
349
|
+
return jsonResponse(questionRegistrationView(registration));
|
|
350
|
+
}
|
|
351
|
+
if (request.method === "DELETE") {
|
|
352
|
+
const { registration } = await loadForCaller(deps, request, store, questionId);
|
|
353
|
+
await store.delete(questionId);
|
|
354
|
+
deps.logger?.info?.({ questionId, derivedScope: registration.derivedScope }, "Derivative question deleted");
|
|
355
|
+
return jsonResponse({ questionId, deleted: true });
|
|
356
|
+
}
|
|
357
|
+
return errorResponse(405, "METHOD_NOT_ALLOWED", "Method not allowed");
|
|
358
|
+
}
|
|
359
|
+
catch (err) {
|
|
360
|
+
if (err instanceof ProtocolError) {
|
|
361
|
+
return jsonResponse(err.toJSON(), { status: err.code });
|
|
362
|
+
}
|
|
363
|
+
return errorResponse(500, "INTERNAL_ERROR", "Internal server error");
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/derivatives/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,oBAAoB,EACpB,iCAAiC,EACjC,mCAAmC,EACnC,+BAA+B,EAC/B,+BAA+B,EAC/B,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAOlD,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,wBAAwB,GAIzB,MAAM,YAAY,CAAC;AAEpB,0EAA0E;AAC1E,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,GAAG,IAAI,CAAC;AAEjD,+EAA+E;AAC/E,MAAM,4BAA4B,GAAG,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,OAAO,EACP,KAAK,EACL,UAAU,CACX,CAAC;YACF,MAAM,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAC/B,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CACjB,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,CAAC,YAAY,EAAE,EACvD,6BAA6B,CAC9B,CAAC;YACF,OAAO,YAAY,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,aAAa,CAAC,GAAG,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;IACxE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,aAAa,EAAE,CAAC;YACjC,OAAO,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO,aAAa,CAAC,GAAG,EAAE,gBAAgB,EAAE,uBAAuB,CAAC,CAAC;IACvE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The compute job: answer one registered question from local data and
|
|
3
|
+
* write the answer as a derivative record (owner path, `$lineage` = the
|
|
4
|
+
* source data points).
|
|
5
|
+
*/
|
|
6
|
+
import type { ScopeDeletionTracker } from "../sync/scope-deletions.js";
|
|
7
|
+
import type { DataStoragePort, RuntimeAvailabilityPort } from "../ports/index.js";
|
|
8
|
+
import { type DataWritePolicyPorts } from "../policy/data-write.js";
|
|
9
|
+
import { type InferenceProvider } from "./inference.js";
|
|
10
|
+
import type { QuestionRegistration, QuestionStore } from "./types.js";
|
|
11
|
+
export interface ComputeLogger {
|
|
12
|
+
info?(payload: Record<string, unknown>, message: string): void;
|
|
13
|
+
warn?(payload: Record<string, unknown>, message: string): void;
|
|
14
|
+
}
|
|
15
|
+
export interface ComputeSyncNotifier {
|
|
16
|
+
notifyNewData?(): void;
|
|
17
|
+
trigger?(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export interface QuestionComputeDeps {
|
|
20
|
+
storage: DataStoragePort;
|
|
21
|
+
store: QuestionStore;
|
|
22
|
+
provider: InferenceProvider;
|
|
23
|
+
/** Required: lineage ids are keccak256(owner, scope). */
|
|
24
|
+
serverOwner: `0x${string}` | undefined;
|
|
25
|
+
/** Newest-first items kept per source scope (default 50). */
|
|
26
|
+
maxSourceItems?: number;
|
|
27
|
+
maxSourceChars?: number;
|
|
28
|
+
maxTokens?: number;
|
|
29
|
+
/** Uploads the derivative after it is written locally. */
|
|
30
|
+
syncManager?: ComputeSyncNotifier | null;
|
|
31
|
+
/** Re-add marker, same as an HTTP ingest (see api/index.ts). */
|
|
32
|
+
scopeDeletions?: ScopeDeletionTracker;
|
|
33
|
+
/**
|
|
34
|
+
* When present, a builder-registered question re-checks its write grant
|
|
35
|
+
* before every compute (revoked / expired / scope no longer covered =>
|
|
36
|
+
* failed, no inference call). Owner registrations skip the check.
|
|
37
|
+
*/
|
|
38
|
+
writePolicyPorts?: DataWritePolicyPorts;
|
|
39
|
+
/**
|
|
40
|
+
* Called after the derivative is written and the question marked ready,
|
|
41
|
+
* so a question that reads THIS derived scope recomputes in turn
|
|
42
|
+
* (A -> B -> C chains). The compute path never goes through the HTTP
|
|
43
|
+
* ingest hook.
|
|
44
|
+
*/
|
|
45
|
+
onDerivedWritten?: (event: {
|
|
46
|
+
scope: string;
|
|
47
|
+
collectedAt: string;
|
|
48
|
+
lineageSources: string[];
|
|
49
|
+
}) => void;
|
|
50
|
+
/** When unavailable the compute is skipped and the status left as is. */
|
|
51
|
+
runtimeAvailability?: RuntimeAvailabilityPort;
|
|
52
|
+
/**
|
|
53
|
+
* Backoff between retries of a transient inference or gateway failure
|
|
54
|
+
* (default 1s, 4s: three attempts). Tests pass zeros.
|
|
55
|
+
*/
|
|
56
|
+
retryDelaysMs?: readonly number[];
|
|
57
|
+
sleep?: (ms: number) => Promise<void>;
|
|
58
|
+
now?: () => Date;
|
|
59
|
+
logger?: ComputeLogger;
|
|
60
|
+
}
|
|
61
|
+
export type ComputeOutcome = {
|
|
62
|
+
status: "ready";
|
|
63
|
+
registration: QuestionRegistration;
|
|
64
|
+
} | {
|
|
65
|
+
status: "failed";
|
|
66
|
+
registration: QuestionRegistration;
|
|
67
|
+
error: string;
|
|
68
|
+
} | {
|
|
69
|
+
status: "skipped";
|
|
70
|
+
reason: "unknown-question" | "runtime-unavailable";
|
|
71
|
+
};
|
|
72
|
+
/** The record written into the derived scope. */
|
|
73
|
+
export interface DerivativeAnswerRecord {
|
|
74
|
+
questionId: string;
|
|
75
|
+
question: string;
|
|
76
|
+
answer: string;
|
|
77
|
+
evidence: string | null;
|
|
78
|
+
model: string;
|
|
79
|
+
computedAt: string;
|
|
80
|
+
sources: Array<{
|
|
81
|
+
scope: string;
|
|
82
|
+
version: number;
|
|
83
|
+
collectedAt: string;
|
|
84
|
+
}>;
|
|
85
|
+
/** Caller-side lineage field, mirrored by the server into `$lineage`. */
|
|
86
|
+
lineage: `0x${string}`[];
|
|
87
|
+
inference?: {
|
|
88
|
+
receiptId?: string;
|
|
89
|
+
aciIdentity?: string;
|
|
90
|
+
};
|
|
91
|
+
[key: string]: unknown;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Version stamp for the derived record, second precision like an HTTP
|
|
95
|
+
* ingest. A recompute inside the same second as the previous one would
|
|
96
|
+
* collide on the (scope, collectedAt) path, so the stamp advances past any
|
|
97
|
+
* version the scope already holds (bounded: at most one minute ahead).
|
|
98
|
+
*/
|
|
99
|
+
export declare function collectedAtStamp(now: () => Date, isTaken: (collectedAt: string) => boolean): string;
|
|
100
|
+
/**
|
|
101
|
+
* Compute one question end to end. Never throws for a compute failure: the
|
|
102
|
+
* registration is marked `failed` with a short reason and the outcome says
|
|
103
|
+
* so. Throws only when the store itself fails.
|
|
104
|
+
*/
|
|
105
|
+
export declare function computeQuestion(questionId: string, deps: QuestionComputeDeps): Promise<ComputeOutcome>;
|
|
106
|
+
//# sourceMappingURL=compute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compute.d.ts","sourceRoot":"","sources":["../../src/derivatives/compute.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkBH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAyB,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAO/E,OAAO,KAAK,EAEV,oBAAoB,EACpB,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/D,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAChE;AAED,MAAM,WAAW,mBAAmB;IAClC,aAAa,CAAC,IAAI,IAAI,CAAC;IACvB,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,eAAe,CAAC;IACzB,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,yDAAyD;IACzD,WAAW,EAAE,KAAK,MAAM,EAAE,GAAG,SAAS,CAAC;IACvC,6DAA6D;IAC7D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,W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