@opendatalabs/personal-server-ts-core 0.0.1-canary.00328bf
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 +408 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +1257 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/raw-envelope.d.ts +3 -0
- package/dist/api/raw-envelope.d.ts.map +1 -0
- package/dist/api/raw-envelope.js +215 -0
- package/dist/api/raw-envelope.js.map +1 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +2 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/request.d.ts +28 -0
- package/dist/auth/request.d.ts.map +1 -0
- package/dist/auth/request.js +106 -0
- package/dist/auth/request.js.map +1 -0
- package/dist/client.d.ts +233 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +243 -0
- package/dist/client.js.map +1 -0
- package/dist/config/defaults.d.ts +12 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +12 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/paths.d.ts +9 -0
- package/dist/config/paths.d.ts.map +1 -0
- package/dist/config/paths.js +14 -0
- package/dist/config/paths.js.map +1 -0
- package/dist/contracts/access-logs.d.ts +8 -0
- package/dist/contracts/access-logs.d.ts.map +1 -0
- package/dist/contracts/access-logs.js +7 -0
- package/dist/contracts/access-logs.js.map +1 -0
- package/dist/contracts/auth-device.d.ts +70 -0
- package/dist/contracts/auth-device.d.ts.map +1 -0
- package/dist/contracts/auth-device.js +163 -0
- package/dist/contracts/auth-device.js.map +1 -0
- package/dist/contracts/binary.d.ts +66 -0
- package/dist/contracts/binary.d.ts.map +1 -0
- package/dist/contracts/binary.js +123 -0
- package/dist/contracts/binary.js.map +1 -0
- package/dist/contracts/config.d.ts +5 -0
- package/dist/contracts/config.d.ts.map +1 -0
- package/dist/contracts/config.js +30 -0
- package/dist/contracts/config.js.map +1 -0
- package/dist/contracts/data.d.ts +165 -0
- package/dist/contracts/data.d.ts.map +1 -0
- package/dist/contracts/data.js +371 -0
- package/dist/contracts/data.js.map +1 -0
- package/dist/contracts/grants.d.ts +45 -0
- package/dist/contracts/grants.d.ts.map +1 -0
- package/dist/contracts/grants.js +177 -0
- package/dist/contracts/grants.js.map +1 -0
- package/dist/contracts/http.d.ts +21 -0
- package/dist/contracts/http.d.ts.map +1 -0
- package/dist/contracts/http.js +49 -0
- package/dist/contracts/http.js.map +1 -0
- package/dist/contracts/index.d.ts +16 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +10 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/contracts/oauth.d.ts +38 -0
- package/dist/contracts/oauth.d.ts.map +1 -0
- package/dist/contracts/oauth.js +130 -0
- package/dist/contracts/oauth.js.map +1 -0
- package/dist/contracts/sync.d.ts +10 -0
- package/dist/contracts/sync.d.ts.map +1 -0
- package/dist/contracts/sync.js +35 -0
- package/dist/contracts/sync.js.map +1 -0
- package/dist/derivatives/answer-shape.d.ts +83 -0
- package/dist/derivatives/answer-shape.d.ts.map +1 -0
- package/dist/derivatives/answer-shape.js +320 -0
- package/dist/derivatives/answer-shape.js.map +1 -0
- package/dist/derivatives/api.d.ts +48 -0
- package/dist/derivatives/api.d.ts.map +1 -0
- package/dist/derivatives/api.js +374 -0
- package/dist/derivatives/api.js.map +1 -0
- package/dist/derivatives/compute.d.ts +112 -0
- package/dist/derivatives/compute.d.ts.map +1 -0
- package/dist/derivatives/compute.js +476 -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 +11 -0
- package/dist/derivatives/index.d.ts.map +1 -0
- package/dist/derivatives/index.js +11 -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 +99 -0
- package/dist/derivatives/prompt.d.ts.map +1 -0
- package/dist/derivatives/prompt.js +281 -0
- package/dist/derivatives/prompt.js.map +1 -0
- package/dist/derivatives/registration.d.ts +56 -0
- package/dist/derivatives/registration.d.ts.map +1 -0
- package/dist/derivatives/registration.js +187 -0
- package/dist/derivatives/registration.js.map +1 -0
- package/dist/derivatives/scheduler.d.ts +114 -0
- package/dist/derivatives/scheduler.d.ts.map +1 -0
- package/dist/derivatives/scheduler.js +331 -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 +79 -0
- package/dist/derivatives/store.js.map +1 -0
- package/dist/derivatives/types.d.ts +102 -0
- package/dist/derivatives/types.d.ts.map +1 -0
- package/dist/derivatives/types.js +29 -0
- package/dist/derivatives/types.js.map +1 -0
- package/dist/errors/catalog.d.ts +125 -0
- package/dist/errors/catalog.d.ts.map +1 -0
- package/dist/errors/catalog.js +198 -0
- package/dist/errors/catalog.js.map +1 -0
- package/dist/errors/pdpp-catalog.d.ts +36 -0
- package/dist/errors/pdpp-catalog.d.ts.map +1 -0
- package/dist/errors/pdpp-catalog.js +82 -0
- package/dist/errors/pdpp-catalog.js.map +1 -0
- package/dist/grants/index.d.ts +5 -0
- package/dist/grants/index.d.ts.map +1 -0
- package/dist/grants/index.js +6 -0
- package/dist/grants/index.js.map +1 -0
- package/dist/grants/pdpp-binding-store.d.ts +58 -0
- package/dist/grants/pdpp-binding-store.d.ts.map +1 -0
- package/dist/grants/pdpp-binding-store.js +97 -0
- package/dist/grants/pdpp-binding-store.js.map +1 -0
- package/dist/grants/pdpp-binding.d.ts +179 -0
- package/dist/grants/pdpp-binding.d.ts.map +1 -0
- package/dist/grants/pdpp-binding.js +214 -0
- package/dist/grants/pdpp-binding.js.map +1 -0
- package/dist/keys/index.d.ts +3 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/index.js +2 -0
- package/dist/keys/index.js.map +1 -0
- 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 +24 -0
- package/dist/keys/server-account.d.ts.map +1 -0
- package/dist/keys/server-account.js +2 -0
- package/dist/keys/server-account.js.map +1 -0
- 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/logger/index.d.ts +9 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +5 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/logging/access-log.d.ts +23 -0
- package/dist/logging/access-log.d.ts.map +1 -0
- package/dist/logging/access-log.js +2 -0
- package/dist/logging/access-log.js.map +1 -0
- package/dist/logging/access-reader.d.ts +14 -0
- package/dist/logging/access-reader.d.ts.map +1 -0
- package/dist/logging/access-reader.js +2 -0
- package/dist/logging/access-reader.js.map +1 -0
- package/dist/mcp/activity.d.ts +68 -0
- package/dist/mcp/activity.d.ts.map +1 -0
- package/dist/mcp/activity.js +111 -0
- package/dist/mcp/activity.js.map +1 -0
- package/dist/mcp/builder-registration.d.ts +24 -0
- package/dist/mcp/builder-registration.d.ts.map +1 -0
- package/dist/mcp/builder-registration.js +89 -0
- package/dist/mcp/builder-registration.js.map +1 -0
- package/dist/mcp/connection-api.d.ts +201 -0
- package/dist/mcp/connection-api.d.ts.map +1 -0
- package/dist/mcp/connection-api.js +506 -0
- package/dist/mcp/connection-api.js.map +1 -0
- package/dist/mcp/grantee.d.ts +52 -0
- package/dist/mcp/grantee.d.ts.map +1 -0
- package/dist/mcp/grantee.js +91 -0
- package/dist/mcp/grantee.js.map +1 -0
- package/dist/mcp/index.d.ts +12 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +12 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/read-client.d.ts +176 -0
- package/dist/mcp/read-client.d.ts.map +1 -0
- package/dist/mcp/read-client.js +579 -0
- package/dist/mcp/read-client.js.map +1 -0
- 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 +34 -0
- package/dist/mcp/search/index.d.ts.map +1 -0
- package/dist/mcp/search/index.js +156 -0
- package/dist/mcp/search/index.js.map +1 -0
- package/dist/mcp/server.d.ts +72 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +447 -0
- package/dist/mcp/server.js.map +1 -0
- 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/store.d.ts +13 -0
- package/dist/mcp/store.d.ts.map +1 -0
- package/dist/mcp/store.js +119 -0
- package/dist/mcp/store.js.map +1 -0
- package/dist/mcp/token-expiry.d.ts +38 -0
- package/dist/mcp/token-expiry.d.ts.map +1 -0
- package/dist/mcp/token-expiry.js +55 -0
- package/dist/mcp/token-expiry.js.map +1 -0
- package/dist/mcp/tools.d.ts +95 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +1381 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/mcp/types.d.ts +135 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +24 -0
- package/dist/mcp/types.js.map +1 -0
- 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/pdpp/approval.d.ts +182 -0
- package/dist/pdpp/approval.d.ts.map +1 -0
- package/dist/pdpp/approval.js +337 -0
- package/dist/pdpp/approval.js.map +1 -0
- package/dist/pdpp/client-identity.d.ts +88 -0
- package/dist/pdpp/client-identity.d.ts.map +1 -0
- package/dist/pdpp/client-identity.js +183 -0
- package/dist/pdpp/client-identity.js.map +1 -0
- package/dist/pdpp/client-metadata.d.ts +95 -0
- package/dist/pdpp/client-metadata.d.ts.map +1 -0
- package/dist/pdpp/client-metadata.js +96 -0
- package/dist/pdpp/client-metadata.js.map +1 -0
- package/dist/pdpp/declaration.d.ts +118 -0
- package/dist/pdpp/declaration.d.ts.map +1 -0
- package/dist/pdpp/declaration.js +549 -0
- package/dist/pdpp/declaration.js.map +1 -0
- package/dist/pdpp/index.d.ts +35 -0
- package/dist/pdpp/index.d.ts.map +1 -0
- package/dist/pdpp/index.js +22 -0
- package/dist/pdpp/index.js.map +1 -0
- package/dist/pdpp/issuance.d.ts +91 -0
- package/dist/pdpp/issuance.d.ts.map +1 -0
- package/dist/pdpp/issuance.js +124 -0
- package/dist/pdpp/issuance.js.map +1 -0
- package/dist/pdpp/pkce.d.ts +53 -0
- package/dist/pdpp/pkce.d.ts.map +1 -0
- package/dist/pdpp/pkce.js +109 -0
- package/dist/pdpp/pkce.js.map +1 -0
- package/dist/pdpp/redirect.d.ts +60 -0
- package/dist/pdpp/redirect.d.ts.map +1 -0
- package/dist/pdpp/redirect.js +125 -0
- package/dist/pdpp/redirect.js.map +1 -0
- package/dist/pdpp/resolve.d.ts +53 -0
- package/dist/pdpp/resolve.d.ts.map +1 -0
- package/dist/pdpp/resolve.js +218 -0
- package/dist/pdpp/resolve.js.map +1 -0
- package/dist/pdpp/review.d.ts +155 -0
- package/dist/pdpp/review.d.ts.map +1 -0
- package/dist/pdpp/review.js +142 -0
- package/dist/pdpp/review.js.map +1 -0
- package/dist/pdpp/selection.d.ts +43 -0
- package/dist/pdpp/selection.d.ts.map +1 -0
- package/dist/pdpp/selection.js +211 -0
- package/dist/pdpp/selection.js.map +1 -0
- package/dist/pdpp/store.d.ts +204 -0
- package/dist/pdpp/store.d.ts.map +1 -0
- package/dist/pdpp/store.js +501 -0
- package/dist/pdpp/store.js.map +1 -0
- package/dist/pdpp/tokens.d.ts +149 -0
- package/dist/pdpp/tokens.d.ts.map +1 -0
- package/dist/pdpp/tokens.js +387 -0
- package/dist/pdpp/tokens.js.map +1 -0
- package/dist/pdpp/types.d.ts +258 -0
- package/dist/pdpp/types.d.ts.map +1 -0
- package/dist/pdpp/types.js +40 -0
- package/dist/pdpp/types.js.map +1 -0
- package/dist/pdpp-version.d.ts +28 -0
- package/dist/pdpp-version.d.ts.map +1 -0
- package/dist/pdpp-version.js +28 -0
- package/dist/pdpp-version.js.map +1 -0
- package/dist/policy/data-read.d.ts +56 -0
- package/dist/policy/data-read.d.ts.map +1 -0
- package/dist/policy/data-read.js +176 -0
- package/dist/policy/data-read.js.map +1 -0
- 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 +4 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +4 -0
- package/dist/policy/index.js.map +1 -0
- 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 +243 -0
- package/dist/ports/index.d.ts.map +1 -0
- package/dist/ports/index.js +7 -0
- package/dist/ports/index.js.map +1 -0
- package/dist/ports/pdpp-auth.d.ts +103 -0
- package/dist/ports/pdpp-auth.d.ts.map +1 -0
- package/dist/ports/pdpp-auth.js +37 -0
- package/dist/ports/pdpp-auth.js.map +1 -0
- package/dist/ports/pdpp-auth.test-utils.d.ts +9 -0
- package/dist/ports/pdpp-auth.test-utils.d.ts.map +1 -0
- package/dist/ports/pdpp-auth.test-utils.js +18 -0
- package/dist/ports/pdpp-auth.test-utils.js.map +1 -0
- package/dist/schemas/server-config.d.ts +190 -0
- package/dist/schemas/server-config.d.ts.map +1 -0
- package/dist/schemas/server-config.js +282 -0
- package/dist/schemas/server-config.js.map +1 -0
- package/dist/signing/index.d.ts +3 -0
- package/dist/signing/index.d.ts.map +1 -0
- package/dist/signing/index.js +3 -0
- package/dist/signing/index.js.map +1 -0
- package/dist/signing/request-signer.d.ts +20 -0
- package/dist/signing/request-signer.d.ts.map +1 -0
- package/dist/signing/request-signer.js +23 -0
- package/dist/signing/request-signer.js.map +1 -0
- package/dist/signing/signer.d.ts +40 -0
- package/dist/signing/signer.d.ts.map +1 -0
- package/dist/signing/signer.js +56 -0
- package/dist/signing/signer.js.map +1 -0
- package/dist/storage/adapters/index.d.ts +4 -0
- package/dist/storage/adapters/index.d.ts.map +1 -0
- package/dist/storage/adapters/index.js +3 -0
- package/dist/storage/adapters/index.js.map +1 -0
- package/dist/storage/adapters/interface.d.ts +57 -0
- package/dist/storage/adapters/interface.d.ts.map +1 -0
- package/dist/storage/adapters/interface.js +2 -0
- package/dist/storage/adapters/interface.js.map +1 -0
- package/dist/storage/adapters/sdk.d.ts +23 -0
- package/dist/storage/adapters/sdk.d.ts.map +1 -0
- package/dist/storage/adapters/sdk.js +73 -0
- package/dist/storage/adapters/sdk.js.map +1 -0
- package/dist/storage/adapters/vana.d.ts +12 -0
- package/dist/storage/adapters/vana.d.ts.map +1 -0
- package/dist/storage/adapters/vana.js +111 -0
- package/dist/storage/adapters/vana.js.map +1 -0
- package/dist/storage/blocks/build.d.ts +20 -0
- package/dist/storage/blocks/build.d.ts.map +1 -0
- package/dist/storage/blocks/build.js +378 -0
- package/dist/storage/blocks/build.js.map +1 -0
- package/dist/storage/blocks/cursor.d.ts +33 -0
- package/dist/storage/blocks/cursor.d.ts.map +1 -0
- package/dist/storage/blocks/cursor.js +142 -0
- package/dist/storage/blocks/cursor.js.map +1 -0
- package/dist/storage/blocks/errors.d.ts +6 -0
- package/dist/storage/blocks/errors.d.ts.map +1 -0
- package/dist/storage/blocks/errors.js +9 -0
- package/dist/storage/blocks/errors.js.map +1 -0
- package/dist/storage/blocks/index.d.ts +6 -0
- package/dist/storage/blocks/index.d.ts.map +1 -0
- package/dist/storage/blocks/index.js +5 -0
- package/dist/storage/blocks/index.js.map +1 -0
- 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 +56 -0
- package/dist/storage/blocks/types.d.ts.map +1 -0
- package/dist/storage/blocks/types.js +2 -0
- package/dist/storage/blocks/types.js.map +1 -0
- package/dist/storage/hierarchy/index.d.ts +3 -0
- package/dist/storage/hierarchy/index.d.ts.map +1 -0
- package/dist/storage/hierarchy/index.js +2 -0
- package/dist/storage/hierarchy/index.js.map +1 -0
- package/dist/storage/hierarchy/manager.d.ts +9 -0
- package/dist/storage/hierarchy/manager.d.ts.map +1 -0
- package/dist/storage/hierarchy/manager.js +2 -0
- package/dist/storage/hierarchy/manager.js.map +1 -0
- package/dist/storage/hierarchy/paths.d.ts +11 -0
- package/dist/storage/hierarchy/paths.d.ts.map +1 -0
- package/dist/storage/hierarchy/paths.js +43 -0
- package/dist/storage/hierarchy/paths.js.map +1 -0
- package/dist/storage/index/index.d.ts +3 -0
- package/dist/storage/index/index.d.ts.map +1 -0
- package/dist/storage/index/index.js +2 -0
- package/dist/storage/index/index.js.map +1 -0
- package/dist/storage/index/manager.d.ts +63 -0
- package/dist/storage/index/manager.d.ts.map +1 -0
- package/dist/storage/index/manager.js +2 -0
- package/dist/storage/index/manager.js.map +1 -0
- package/dist/storage/index/schema.d.ts +2 -0
- package/dist/storage/index/schema.d.ts.map +1 -0
- package/dist/storage/index/schema.js +2 -0
- package/dist/storage/index/schema.js.map +1 -0
- package/dist/storage/index/types.d.ts +37 -0
- package/dist/storage/index/types.d.ts.map +1 -0
- package/dist/storage/index/types.js +2 -0
- package/dist/storage/index/types.js.map +1 -0
- package/dist/storage/pdpp-records/cursor.d.ts +27 -0
- package/dist/storage/pdpp-records/cursor.d.ts.map +1 -0
- package/dist/storage/pdpp-records/cursor.js +49 -0
- package/dist/storage/pdpp-records/cursor.js.map +1 -0
- package/dist/storage/pdpp-records/enforcement.d.ts +37 -0
- package/dist/storage/pdpp-records/enforcement.d.ts.map +1 -0
- package/dist/storage/pdpp-records/enforcement.js +79 -0
- package/dist/storage/pdpp-records/enforcement.js.map +1 -0
- package/dist/storage/pdpp-records/index.d.ts +8 -0
- package/dist/storage/pdpp-records/index.d.ts.map +1 -0
- package/dist/storage/pdpp-records/index.js +8 -0
- package/dist/storage/pdpp-records/index.js.map +1 -0
- package/dist/storage/pdpp-records/interface.d.ts +49 -0
- package/dist/storage/pdpp-records/interface.d.ts.map +1 -0
- package/dist/storage/pdpp-records/interface.js +2 -0
- package/dist/storage/pdpp-records/interface.js.map +1 -0
- package/dist/storage/pdpp-records/memory-store.d.ts +9 -0
- package/dist/storage/pdpp-records/memory-store.d.ts.map +1 -0
- package/dist/storage/pdpp-records/memory-store.js +0 -0
- package/dist/storage/pdpp-records/memory-store.js.map +1 -0
- package/dist/storage/pdpp-records/record-key.d.ts +52 -0
- package/dist/storage/pdpp-records/record-key.d.ts.map +1 -0
- package/dist/storage/pdpp-records/record-key.js +97 -0
- package/dist/storage/pdpp-records/record-key.js.map +1 -0
- package/dist/storage/pdpp-records/stream-declaration.d.ts +43 -0
- package/dist/storage/pdpp-records/stream-declaration.d.ts.map +1 -0
- package/dist/storage/pdpp-records/stream-declaration.js +17 -0
- package/dist/storage/pdpp-records/stream-declaration.js.map +1 -0
- package/dist/storage/pdpp-records/types.d.ts +93 -0
- package/dist/storage/pdpp-records/types.d.ts.map +1 -0
- package/dist/storage/pdpp-records/types.js +17 -0
- package/dist/storage/pdpp-records/types.js.map +1 -0
- package/dist/storage/preview.d.ts +12 -0
- package/dist/storage/preview.d.ts.map +1 -0
- package/dist/storage/preview.js +239 -0
- package/dist/storage/preview.js.map +1 -0
- package/dist/sync/cursor.d.ts +10 -0
- package/dist/sync/cursor.d.ts.map +1 -0
- package/dist/sync/cursor.js +2 -0
- package/dist/sync/cursor.js.map +1 -0
- 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 +58 -0
- package/dist/sync/engine/sync-manager.d.ts.map +1 -0
- package/dist/sync/engine/sync-manager.js +285 -0
- package/dist/sync/engine/sync-manager.js.map +1 -0
- package/dist/sync/index.d.ts +15 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +14 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/issues.d.ts +55 -0
- package/dist/sync/issues.d.ts.map +1 -0
- package/dist/sync/issues.js +168 -0
- package/dist/sync/issues.js.map +1 -0
- package/dist/sync/pdpp-import.d.ts +192 -0
- package/dist/sync/pdpp-import.d.ts.map +1 -0
- package/dist/sync/pdpp-import.js +422 -0
- package/dist/sync/pdpp-import.js.map +1 -0
- 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/types.d.ts +27 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync/types.js +2 -0
- package/dist/sync/types.js.map +1 -0
- package/dist/sync/workers/delete.d.ts +163 -0
- package/dist/sync/workers/delete.d.ts.map +1 -0
- package/dist/sync/workers/delete.js +474 -0
- package/dist/sync/workers/delete.js.map +1 -0
- package/dist/sync/workers/download.d.ts +159 -0
- package/dist/sync/workers/download.d.ts.map +1 -0
- package/dist/sync/workers/download.js +731 -0
- package/dist/sync/workers/download.js.map +1 -0
- package/dist/sync/workers/upload.d.ts +98 -0
- package/dist/sync/workers/upload.d.ts.map +1 -0
- package/dist/sync/workers/upload.js +412 -0
- package/dist/sync/workers/upload.js.map +1 -0
- 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 +5 -0
- package/dist/test-utils/index.d.ts.map +1 -0
- package/dist/test-utils/index.js +5 -0
- package/dist/test-utils/index.js.map +1 -0
- 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 +47 -0
- package/dist/test-utils/wallet.d.ts.map +1 -0
- package/dist/test-utils/wallet.js +98 -0
- package/dist/test-utils/wallet.js.map +1 -0
- 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 +175 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inference provider adapter for the derivative compute layer.
|
|
3
|
+
*
|
|
4
|
+
* One implementation: OpenAI-compatible chat completions over `fetch`, so it
|
|
5
|
+
* runs unchanged in Node and in the browser (PS-Lite). In production the
|
|
6
|
+
* base URL is the Vana inference relay, which holds the provider key; the
|
|
7
|
+
* optional API key header exists for local development against a provider
|
|
8
|
+
* directly.
|
|
9
|
+
*
|
|
10
|
+
* RELAY AUTH: the Vana inference relay
|
|
11
|
+
* (`POST /v1/inference/chat/completions` on the data gateway) only forwards
|
|
12
|
+
* a request that is signed by the owner or by one of the owner's ACTIVE
|
|
13
|
+
* registered servers, with the same Web3Signed scheme the lineage read uses
|
|
14
|
+
* (`RequestSigner`, see ../signing/request-signer.ts). Pass `requestSigner`
|
|
15
|
+
* and every relay call carries `Authorization: Web3Signed ...` over the
|
|
16
|
+
* exact bytes that go on the wire. `apiKey` is the local-development
|
|
17
|
+
* alternative (direct provider, `Authorization: Bearer`) and wins when both
|
|
18
|
+
* are set: a bearer key means "not the relay".
|
|
19
|
+
*
|
|
20
|
+
* E2EE SEAM: the Phala confidential-inference E2EE v2 protocol encrypts each
|
|
21
|
+
* `messages[i].content` to the gateway's attested public key and adds the
|
|
22
|
+
* headers X-E2EE-Version, X-Client-Pub-Key, X-Model-Pub-Key, X-E2EE-Nonce
|
|
23
|
+
* and X-E2EE-Timestamp; the response content comes back encrypted to the
|
|
24
|
+
* client key. `InferenceRequestEncryption` below is the hook, implemented
|
|
25
|
+
* by `createPhalaE2eeEncryption` in ./e2ee. This module only knows the
|
|
26
|
+
* shape: encrypt the outgoing messages, decrypt the one response field.
|
|
27
|
+
*/
|
|
28
|
+
export const DEFAULT_INFERENCE_BASE_URL = "https://inference.phala.com/v1";
|
|
29
|
+
export const DEFAULT_INFERENCE_MODEL = "z-ai/glm-5.3-flash";
|
|
30
|
+
export const DEFAULT_INFERENCE_TIMEOUT_MS = 120_000;
|
|
31
|
+
export const DEFAULT_INFERENCE_MAX_TOKENS = 2_048;
|
|
32
|
+
export const DEFAULT_INFERENCE_REQUEST_FIELDS = {
|
|
33
|
+
provider: { aci_verified: true, zdr: true },
|
|
34
|
+
};
|
|
35
|
+
/** Thrown for a non-2xx or malformed provider reply. Carries no prompt text. */
|
|
36
|
+
export class InferenceRequestError extends Error {
|
|
37
|
+
status;
|
|
38
|
+
/** OpenAI-style `error.type` of the rejection, when the body had one. */
|
|
39
|
+
errorType;
|
|
40
|
+
/**
|
|
41
|
+
* Explicit retry hint. When undefined the compute layer falls back to the
|
|
42
|
+
* status: no response, 429 or 5xx are retried.
|
|
43
|
+
*/
|
|
44
|
+
retryable;
|
|
45
|
+
constructor(message, status, options = {}) {
|
|
46
|
+
super(message);
|
|
47
|
+
this.status = status;
|
|
48
|
+
this.name = "InferenceRequestError";
|
|
49
|
+
this.errorType = options.errorType ?? null;
|
|
50
|
+
this.retryable = options.retryable;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function isRecord(value) {
|
|
54
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
55
|
+
}
|
|
56
|
+
function readUsage(value) {
|
|
57
|
+
if (!isRecord(value))
|
|
58
|
+
return undefined;
|
|
59
|
+
const num = (v) => (typeof v === "number" ? v : undefined);
|
|
60
|
+
const usage = {
|
|
61
|
+
promptTokens: num(value.prompt_tokens),
|
|
62
|
+
completionTokens: num(value.completion_tokens),
|
|
63
|
+
totalTokens: num(value.total_tokens),
|
|
64
|
+
};
|
|
65
|
+
return usage;
|
|
66
|
+
}
|
|
67
|
+
function readContent(body) {
|
|
68
|
+
if (!isRecord(body) || !Array.isArray(body.choices))
|
|
69
|
+
return null;
|
|
70
|
+
const first = body.choices[0];
|
|
71
|
+
if (!isRecord(first) || !isRecord(first.message))
|
|
72
|
+
return null;
|
|
73
|
+
const index = typeof first.index === "number" ? first.index : 0;
|
|
74
|
+
const field = `choices.${index}.message.content`;
|
|
75
|
+
const id = typeof body.id === "string" ? body.id : "";
|
|
76
|
+
const content = first.message.content;
|
|
77
|
+
if (typeof content === "string")
|
|
78
|
+
return { content, field, id };
|
|
79
|
+
// Some providers return content parts.
|
|
80
|
+
if (Array.isArray(content)) {
|
|
81
|
+
const text = content
|
|
82
|
+
.map((part) => isRecord(part) && typeof part.text === "string" ? part.text : "")
|
|
83
|
+
.join("");
|
|
84
|
+
return { content: text, field, id };
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
/** OpenAI-style `{ error: { type } }` of a rejection; never its message. */
|
|
89
|
+
async function readErrorType(response) {
|
|
90
|
+
try {
|
|
91
|
+
const body = await response.json();
|
|
92
|
+
if (isRecord(body) && isRecord(body.error)) {
|
|
93
|
+
return typeof body.error.type === "string" ? body.error.type : null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// Not JSON: no type to report.
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Sign one relay request. A signer that cannot sign (locked key, wallet
|
|
103
|
+
* gone) is a permanent failure: the request is never sent unsigned, and the
|
|
104
|
+
* compute layer must not retry it into a storm.
|
|
105
|
+
*/
|
|
106
|
+
async function signOrThrow(signer, params) {
|
|
107
|
+
try {
|
|
108
|
+
return await signer.signRequest(params);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
const name = err instanceof Error ? err.name : "Error";
|
|
112
|
+
throw new InferenceRequestError(`inference request could not be signed (${name})`, null, { errorType: "relay_signing_failed", retryable: false });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export function createOpenAiCompatibleInferenceProvider(options = {}) {
|
|
116
|
+
const base = (options.baseUrl ?? DEFAULT_INFERENCE_BASE_URL).replace(/\/+$/, "");
|
|
117
|
+
const defaultModel = options.model ?? DEFAULT_INFERENCE_MODEL;
|
|
118
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_INFERENCE_TIMEOUT_MS;
|
|
119
|
+
const doFetch = options.fetch ?? fetch;
|
|
120
|
+
const requestFields = options.requestFields ?? DEFAULT_INFERENCE_REQUEST_FIELDS;
|
|
121
|
+
const encryption = options.encryption;
|
|
122
|
+
// A bearer key means the base URL is a provider, not the relay: the relay
|
|
123
|
+
// never takes one, so the key wins and no signature is produced.
|
|
124
|
+
const requestSigner = options.apiKey ? undefined : options.requestSigner;
|
|
125
|
+
const chatUrl = new URL(`${base}/chat/completions`);
|
|
126
|
+
/** One send; `rejected` reports a non-2xx so the caller may retry once. */
|
|
127
|
+
async function send(input) {
|
|
128
|
+
const headers = new Headers({ "Content-Type": "application/json" });
|
|
129
|
+
if (options.apiKey) {
|
|
130
|
+
headers.set("Authorization", `Bearer ${options.apiKey}`);
|
|
131
|
+
}
|
|
132
|
+
const model = input.model || defaultModel;
|
|
133
|
+
let messages = input.messages;
|
|
134
|
+
let encrypted = null;
|
|
135
|
+
if (encryption) {
|
|
136
|
+
encrypted = await encryption.encryptRequest({
|
|
137
|
+
model,
|
|
138
|
+
messages,
|
|
139
|
+
headers,
|
|
140
|
+
});
|
|
141
|
+
messages = encrypted.messages;
|
|
142
|
+
}
|
|
143
|
+
const body = {
|
|
144
|
+
...requestFields,
|
|
145
|
+
model,
|
|
146
|
+
messages,
|
|
147
|
+
max_tokens: input.maxTokens ?? DEFAULT_INFERENCE_MAX_TOKENS,
|
|
148
|
+
};
|
|
149
|
+
// Serialized ONCE, after encryption: the bytes that are hashed into the
|
|
150
|
+
// signature are the bytes that go on the wire (ciphertext included).
|
|
151
|
+
const payload = JSON.stringify(body);
|
|
152
|
+
if (requestSigner) {
|
|
153
|
+
headers.set("Authorization", await signOrThrow(requestSigner, {
|
|
154
|
+
aud: chatUrl.origin,
|
|
155
|
+
method: "POST",
|
|
156
|
+
uri: `${chatUrl.pathname}${chatUrl.search}`,
|
|
157
|
+
body: new TextEncoder().encode(payload),
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
let response;
|
|
161
|
+
try {
|
|
162
|
+
response = await doFetch(chatUrl.toString(), {
|
|
163
|
+
method: "POST",
|
|
164
|
+
headers,
|
|
165
|
+
body: payload,
|
|
166
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
// Transport failure: no status, no body. The message is the error
|
|
171
|
+
// class name only; it never carries request contents.
|
|
172
|
+
const name = err instanceof Error ? err.name : "Error";
|
|
173
|
+
throw new InferenceRequestError(`inference request failed before a response (${name})`, null);
|
|
174
|
+
}
|
|
175
|
+
if (!response.ok) {
|
|
176
|
+
const errorType = await readErrorType(response);
|
|
177
|
+
const retry = (await encryption?.onRejected?.({
|
|
178
|
+
status: response.status,
|
|
179
|
+
errorType,
|
|
180
|
+
headers: response.headers,
|
|
181
|
+
})) === true;
|
|
182
|
+
return {
|
|
183
|
+
ok: false,
|
|
184
|
+
retry,
|
|
185
|
+
error: new InferenceRequestError(`inference request failed with status ${response.status}${errorType ? ` (${errorType})` : ""}`, response.status, { errorType }),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
let parsed;
|
|
189
|
+
try {
|
|
190
|
+
parsed = await response.json();
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
throw new InferenceRequestError("inference response was not JSON", response.status);
|
|
194
|
+
}
|
|
195
|
+
const choice = readContent(parsed);
|
|
196
|
+
if (choice === null) {
|
|
197
|
+
throw new InferenceRequestError("inference response carried no assistant content", response.status);
|
|
198
|
+
}
|
|
199
|
+
let content = choice.content;
|
|
200
|
+
if (encrypted) {
|
|
201
|
+
// Fail closed: a reply that is not valid ciphertext for this request
|
|
202
|
+
// is an error, never used as plaintext.
|
|
203
|
+
content = await encrypted.decryptResponse({
|
|
204
|
+
content,
|
|
205
|
+
field: choice.field,
|
|
206
|
+
id: choice.id,
|
|
207
|
+
headers: response.headers,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (content.trim() === "") {
|
|
211
|
+
// An empty reply must never become a "ready" derivative.
|
|
212
|
+
throw new InferenceRequestError("inference response carried no assistant content", response.status);
|
|
213
|
+
}
|
|
214
|
+
const receiptId = response.headers.get("x-receipt-id") ?? undefined;
|
|
215
|
+
const aciIdentity = response.headers.get("x-aci-identity") ?? undefined;
|
|
216
|
+
return {
|
|
217
|
+
ok: true,
|
|
218
|
+
result: {
|
|
219
|
+
content,
|
|
220
|
+
usage: readUsage(isRecord(parsed) ? parsed.usage : undefined),
|
|
221
|
+
...(receiptId ? { receiptId } : {}),
|
|
222
|
+
...(aciIdentity ? { aciIdentity } : {}),
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
defaultModel,
|
|
228
|
+
async chat(input) {
|
|
229
|
+
const first = await send(input);
|
|
230
|
+
if (first.ok)
|
|
231
|
+
return first.result;
|
|
232
|
+
if (!first.retry)
|
|
233
|
+
throw first.error;
|
|
234
|
+
// The encryption asked for one re-send (fresh key, fresh nonce).
|
|
235
|
+
const second = await send(input);
|
|
236
|
+
if (second.ok)
|
|
237
|
+
return second.result;
|
|
238
|
+
throw second.error;
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/** Test double: records calls, answers with a fixed JSON object by default. */
|
|
243
|
+
export function createFakeInferenceProvider(options = {}) {
|
|
244
|
+
const calls = [];
|
|
245
|
+
return {
|
|
246
|
+
defaultModel: options.model ?? "fake-model",
|
|
247
|
+
calls,
|
|
248
|
+
async chat(input) {
|
|
249
|
+
calls.push(input);
|
|
250
|
+
if (options.respond)
|
|
251
|
+
return options.respond(input, calls.length - 1);
|
|
252
|
+
return {
|
|
253
|
+
content: JSON.stringify({
|
|
254
|
+
answer: "fake answer",
|
|
255
|
+
evidence: "fake evidence",
|
|
256
|
+
}),
|
|
257
|
+
receiptId: "fake-receipt",
|
|
258
|
+
};
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=inference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inference.js","sourceRoot":"","sources":["../../src/derivatives/inference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAiFH,MAAM,CAAC,MAAM,0BAA0B,GAAG,gCAAgC,CAAC;AAC3E,MAAM,CAAC,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AAC5D,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAO,CAAC;AACpD,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,CAAC;AAyBlD,MAAM,CAAC,MAAM,gCAAgC,GAA4B;IACvE,QAAQ,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE;CAC5C,CAAC;AAEF,gFAAgF;AAChF,MAAM,OAAO,qBAAsB,SAAQ,KAAK;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 -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt assembly for a question: the source scopes' latest local records,
|
|
3
|
+
* trimmed newest-first to a bounded number of items each, framed by a system
|
|
4
|
+
* prompt that pins the model to the provided data and to a JSON answer.
|
|
5
|
+
*
|
|
6
|
+
* Nothing here leaves the Personal Server except through the inference
|
|
7
|
+
* provider call the compute step makes.
|
|
8
|
+
*/
|
|
9
|
+
import { type AnswerShape } from "./answer-shape.js";
|
|
10
|
+
import type { InferenceMessage } from "./inference.js";
|
|
11
|
+
export declare const DEFAULT_MAX_SOURCE_ITEMS = 50;
|
|
12
|
+
/** Upper bound on the serialized size of one source's trimmed data. */
|
|
13
|
+
export declare const DEFAULT_MAX_SOURCE_CHARS = 200000;
|
|
14
|
+
/**
|
|
15
|
+
* Newest first. Items that carry a timestamp sort by it; items that do not
|
|
16
|
+
* keep their relative order after the timestamped ones, reversed, on the
|
|
17
|
+
* assumption that a connector appends newest last. Stable.
|
|
18
|
+
*/
|
|
19
|
+
export declare function sortNewestFirst<T>(items: readonly T[]): T[];
|
|
20
|
+
export interface TrimResult {
|
|
21
|
+
data: unknown;
|
|
22
|
+
/** Items kept / items present, summed over every array that was trimmed. */
|
|
23
|
+
kept: number;
|
|
24
|
+
total: number;
|
|
25
|
+
/** True when the char cap cut the serialization. */
|
|
26
|
+
truncated: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The trim rule. A record whose `data` is an array is trimmed to the newest
|
|
30
|
+
* `maxItems`; a record object trims every top-level array value the same
|
|
31
|
+
* way and keeps its other keys; reserved server keys are dropped. When the
|
|
32
|
+
* serialized result still exceeds `maxChars`, items are dropped from the
|
|
33
|
+
* old end until it fits (at least one is kept), and as a last resort the
|
|
34
|
+
* serialization itself is cut at `maxChars`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function trimSourceData(data: unknown, options?: {
|
|
37
|
+
maxItems?: number;
|
|
38
|
+
maxChars?: number;
|
|
39
|
+
}): TrimResult;
|
|
40
|
+
export interface PromptSource {
|
|
41
|
+
scope: string;
|
|
42
|
+
collectedAt: string;
|
|
43
|
+
version: number;
|
|
44
|
+
data: unknown;
|
|
45
|
+
kept: number;
|
|
46
|
+
total: number;
|
|
47
|
+
truncated: boolean;
|
|
48
|
+
}
|
|
49
|
+
export declare const SYSTEM_PROMPT: string;
|
|
50
|
+
/**
|
|
51
|
+
* The system prompt for a question that declared an answer shape: the same
|
|
52
|
+
* grounding, but `answer` is the declared object rather than prose. The
|
|
53
|
+
* prompt is not the boundary (the reply is validated against the compiled
|
|
54
|
+
* shape afterwards); it is what makes the model produce a matching reply
|
|
55
|
+
* on the first try.
|
|
56
|
+
*/
|
|
57
|
+
export declare function shapedSystemPrompt(shape: AnswerShape): string;
|
|
58
|
+
/** Assemble the chat messages for one compute. */
|
|
59
|
+
export declare function buildQuestionMessages(input: {
|
|
60
|
+
question: string;
|
|
61
|
+
sources: readonly PromptSource[];
|
|
62
|
+
answerShape?: AnswerShape | null;
|
|
63
|
+
}): InferenceMessage[];
|
|
64
|
+
/**
|
|
65
|
+
* The corrective turn after a reply that did not match the declared shape:
|
|
66
|
+
* the model's own reply back as context, then what was wrong with it. The
|
|
67
|
+
* issue list comes from zod and states constraints only, so nothing of the
|
|
68
|
+
* user data is restated here that the model did not already send.
|
|
69
|
+
*/
|
|
70
|
+
export declare function buildShapeRetryMessages(input: {
|
|
71
|
+
messages: readonly InferenceMessage[];
|
|
72
|
+
reply: string;
|
|
73
|
+
issues: readonly string[];
|
|
74
|
+
answerShape: AnswerShape;
|
|
75
|
+
}): InferenceMessage[];
|
|
76
|
+
export interface ParsedAnswer {
|
|
77
|
+
answer: string;
|
|
78
|
+
evidence: string | null;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Read the model's JSON answer. Tolerates a fenced code block or leading
|
|
82
|
+
* prose around the object; falls back to the whole text as the answer when
|
|
83
|
+
* no object can be parsed (the answer is still the model's, just unframed).
|
|
84
|
+
*/
|
|
85
|
+
export declare function parseAnswer(content: string): ParsedAnswer;
|
|
86
|
+
export interface ParsedShapedAnswer {
|
|
87
|
+
/** The object to check against the compiled shape; never validated here. */
|
|
88
|
+
answer: Record<string, unknown>;
|
|
89
|
+
evidence: string | null;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Read the model's reply for a question that declared a shape. Returns
|
|
93
|
+
* every object worth checking, best first: the `answer` member of the
|
|
94
|
+
* envelope, then the envelope itself for a model that put the declared
|
|
95
|
+
* fields at the top level. Empty when nothing parsed as an object at all,
|
|
96
|
+
* which is a shape failure like any other.
|
|
97
|
+
*/
|
|
98
|
+
export declare function parseShapedAnswer(content: string): ParsedShapedAnswer[];
|
|
99
|
+
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/derivatives/prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAC3C,uEAAuE;AACvE,eAAO,MAAM,wBAAwB,SAAU,CAAC;AAyChD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,EAAE,CAW3D;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,4EAA4E;IAC5E,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,oDAAoD;IACpD,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,OAAO,EACb,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAA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OAAO,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAkBvE"}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt assembly for a question: the source scopes' latest local records,
|
|
3
|
+
* trimmed newest-first to a bounded number of items each, framed by a system
|
|
4
|
+
* prompt that pins the model to the provided data and to a JSON answer.
|
|
5
|
+
*
|
|
6
|
+
* Nothing here leaves the Personal Server except through the inference
|
|
7
|
+
* provider call the compute step makes.
|
|
8
|
+
*/
|
|
9
|
+
import { describeAnswerShape } from "./answer-shape.js";
|
|
10
|
+
export const DEFAULT_MAX_SOURCE_ITEMS = 50;
|
|
11
|
+
/** Upper bound on the serialized size of one source's trimmed data. */
|
|
12
|
+
export const DEFAULT_MAX_SOURCE_CHARS = 200_000;
|
|
13
|
+
/** Keys a record commonly carries its own timestamp under, in priority order. */
|
|
14
|
+
const TIMESTAMP_KEYS = [
|
|
15
|
+
"collectedAt",
|
|
16
|
+
"updatedAt",
|
|
17
|
+
"updated_at",
|
|
18
|
+
"update_time",
|
|
19
|
+
"createdAt",
|
|
20
|
+
"created_at",
|
|
21
|
+
"create_time",
|
|
22
|
+
"timestamp",
|
|
23
|
+
"time",
|
|
24
|
+
"date",
|
|
25
|
+
"publishedAt",
|
|
26
|
+
"published_at",
|
|
27
|
+
];
|
|
28
|
+
/** Server-stamped envelope keys that are not user data. */
|
|
29
|
+
const RESERVED_KEYS = new Set(["$lineage", "$writtenBy", "$binary"]);
|
|
30
|
+
function isRecord(value) {
|
|
31
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
32
|
+
}
|
|
33
|
+
function timestampOf(item) {
|
|
34
|
+
if (!isRecord(item))
|
|
35
|
+
return null;
|
|
36
|
+
for (const key of TIMESTAMP_KEYS) {
|
|
37
|
+
const value = item[key];
|
|
38
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
39
|
+
// Seconds vs milliseconds: anything below 1e12 is taken as seconds.
|
|
40
|
+
return value < 1e12 ? value * 1000 : value;
|
|
41
|
+
}
|
|
42
|
+
if (typeof value === "string") {
|
|
43
|
+
const parsed = Date.parse(value);
|
|
44
|
+
if (!Number.isNaN(parsed))
|
|
45
|
+
return parsed;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Newest first. Items that carry a timestamp sort by it; items that do not
|
|
52
|
+
* keep their relative order after the timestamped ones, reversed, on the
|
|
53
|
+
* assumption that a connector appends newest last. Stable.
|
|
54
|
+
*/
|
|
55
|
+
export function sortNewestFirst(items) {
|
|
56
|
+
const indexed = items.map((item, index) => ({
|
|
57
|
+
item,
|
|
58
|
+
index,
|
|
59
|
+
at: timestampOf(item),
|
|
60
|
+
}));
|
|
61
|
+
const dated = indexed
|
|
62
|
+
.filter((entry) => entry.at !== null)
|
|
63
|
+
.sort((a, b) => b.at - a.at || b.index - a.index);
|
|
64
|
+
const undated = indexed.filter((entry) => entry.at === null).reverse();
|
|
65
|
+
return [...dated, ...undated].map((entry) => entry.item);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The trim rule. A record whose `data` is an array is trimmed to the newest
|
|
69
|
+
* `maxItems`; a record object trims every top-level array value the same
|
|
70
|
+
* way and keeps its other keys; reserved server keys are dropped. When the
|
|
71
|
+
* serialized result still exceeds `maxChars`, items are dropped from the
|
|
72
|
+
* old end until it fits (at least one is kept), and as a last resort the
|
|
73
|
+
* serialization itself is cut at `maxChars`.
|
|
74
|
+
*/
|
|
75
|
+
export function trimSourceData(data, options = {}) {
|
|
76
|
+
const maxItems = Math.max(1, options.maxItems ?? DEFAULT_MAX_SOURCE_ITEMS);
|
|
77
|
+
const maxChars = Math.max(1, options.maxChars ?? DEFAULT_MAX_SOURCE_CHARS);
|
|
78
|
+
let kept = 0;
|
|
79
|
+
let total = 0;
|
|
80
|
+
const trimArray = (items, limit) => {
|
|
81
|
+
total += items.length;
|
|
82
|
+
const sorted = sortNewestFirst(items).slice(0, limit);
|
|
83
|
+
kept += sorted.length;
|
|
84
|
+
return sorted;
|
|
85
|
+
};
|
|
86
|
+
const build = (limit) => {
|
|
87
|
+
kept = 0;
|
|
88
|
+
total = 0;
|
|
89
|
+
if (Array.isArray(data))
|
|
90
|
+
return trimArray(data, limit);
|
|
91
|
+
if (isRecord(data)) {
|
|
92
|
+
// A stamped derivative also stores the caller lineage field the server
|
|
93
|
+
// consumed; it carries the same source data-point ids as `$lineage`
|
|
94
|
+
// and must not reach the prompt, or a question could echo them into
|
|
95
|
+
// an answer a grantee reads.
|
|
96
|
+
const stamped = "$lineage" in data;
|
|
97
|
+
const out = {};
|
|
98
|
+
for (const [key, value] of Object.entries(data)) {
|
|
99
|
+
if (RESERVED_KEYS.has(key))
|
|
100
|
+
continue;
|
|
101
|
+
if (stamped && key === "lineage")
|
|
102
|
+
continue;
|
|
103
|
+
out[key] = Array.isArray(value) ? trimArray(value, limit) : value;
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
return data;
|
|
108
|
+
};
|
|
109
|
+
let limit = maxItems;
|
|
110
|
+
let result = build(limit);
|
|
111
|
+
let text = JSON.stringify(result) ?? "null";
|
|
112
|
+
// Shrink the item budget while the serialization is over the cap. Each
|
|
113
|
+
// pass at least halves the budget, so this ends in O(log maxItems) steps.
|
|
114
|
+
while (text.length > maxChars && limit > 1) {
|
|
115
|
+
limit = Math.max(1, Math.floor(limit / 2));
|
|
116
|
+
result = build(limit);
|
|
117
|
+
text = JSON.stringify(result) ?? "null";
|
|
118
|
+
}
|
|
119
|
+
if (text.length > maxChars) {
|
|
120
|
+
return {
|
|
121
|
+
data: `${text.slice(0, maxChars)}...[truncated]`,
|
|
122
|
+
kept,
|
|
123
|
+
total,
|
|
124
|
+
truncated: true,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return { data: result, kept, total, truncated: false };
|
|
128
|
+
}
|
|
129
|
+
const GROUNDING = [
|
|
130
|
+
"You answer a question about a person using ONLY the user data provided in the message.",
|
|
131
|
+
"Do not use outside knowledge and do not guess; if the data does not support an answer, say so in the answer.",
|
|
132
|
+
];
|
|
133
|
+
export const SYSTEM_PROMPT = [
|
|
134
|
+
...GROUNDING,
|
|
135
|
+
"Respond with a single JSON object and nothing else, with exactly these fields:",
|
|
136
|
+
' "answer": string, the answer to the question, written for the person the data belongs to;',
|
|
137
|
+
' "evidence": string, a short summary of which parts of the data support the answer.',
|
|
138
|
+
].join("\n");
|
|
139
|
+
/**
|
|
140
|
+
* The system prompt for a question that declared an answer shape: the same
|
|
141
|
+
* grounding, but `answer` is the declared object rather than prose. The
|
|
142
|
+
* prompt is not the boundary (the reply is validated against the compiled
|
|
143
|
+
* shape afterwards); it is what makes the model produce a matching reply
|
|
144
|
+
* on the first try.
|
|
145
|
+
*/
|
|
146
|
+
export function shapedSystemPrompt(shape) {
|
|
147
|
+
return [
|
|
148
|
+
...GROUNDING,
|
|
149
|
+
"Respond with a single JSON object and nothing else, with exactly these fields:",
|
|
150
|
+
' "answer": object, holding exactly the fields listed below and no others;',
|
|
151
|
+
' "evidence": string, a short summary of which parts of the data support the answer.',
|
|
152
|
+
'The "answer" object holds:',
|
|
153
|
+
...describeAnswerShape(shape),
|
|
154
|
+
"Use the declared type for every field: a number field is a JSON number, not a string.",
|
|
155
|
+
"Do not add fields, do not rename them and do not put prose outside them.",
|
|
156
|
+
].join("\n");
|
|
157
|
+
}
|
|
158
|
+
/** Assemble the chat messages for one compute. */
|
|
159
|
+
export function buildQuestionMessages(input) {
|
|
160
|
+
const sections = input.sources.map((source) => {
|
|
161
|
+
const note = source.total > source.kept
|
|
162
|
+
? ` (newest ${source.kept} of ${source.total} items)`
|
|
163
|
+
: "";
|
|
164
|
+
const cut = source.truncated ? " (truncated)" : "";
|
|
165
|
+
return [
|
|
166
|
+
`### Scope: ${source.scope}${note}${cut}`,
|
|
167
|
+
`Collected at: ${source.collectedAt}`,
|
|
168
|
+
JSON.stringify(source.data),
|
|
169
|
+
].join("\n");
|
|
170
|
+
});
|
|
171
|
+
const user = [
|
|
172
|
+
"## Question",
|
|
173
|
+
input.question,
|
|
174
|
+
"",
|
|
175
|
+
"## User data",
|
|
176
|
+
...sections,
|
|
177
|
+
"",
|
|
178
|
+
input.answerShape
|
|
179
|
+
? "Answer the question as a JSON object with the fields answer and evidence, where answer holds exactly the declared fields."
|
|
180
|
+
: "Answer the question as a JSON object with the fields answer and evidence.",
|
|
181
|
+
].join("\n");
|
|
182
|
+
return [
|
|
183
|
+
{
|
|
184
|
+
role: "system",
|
|
185
|
+
content: input.answerShape
|
|
186
|
+
? shapedSystemPrompt(input.answerShape)
|
|
187
|
+
: SYSTEM_PROMPT,
|
|
188
|
+
},
|
|
189
|
+
{ role: "user", content: user },
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* The corrective turn after a reply that did not match the declared shape:
|
|
194
|
+
* the model's own reply back as context, then what was wrong with it. The
|
|
195
|
+
* issue list comes from zod and states constraints only, so nothing of the
|
|
196
|
+
* user data is restated here that the model did not already send.
|
|
197
|
+
*/
|
|
198
|
+
export function buildShapeRetryMessages(input) {
|
|
199
|
+
return [
|
|
200
|
+
...input.messages,
|
|
201
|
+
{ role: "assistant", content: input.reply },
|
|
202
|
+
{
|
|
203
|
+
role: "user",
|
|
204
|
+
content: [
|
|
205
|
+
"That reply did not match the required answer shape:",
|
|
206
|
+
...input.issues.map((issue) => `- ${issue}`),
|
|
207
|
+
"",
|
|
208
|
+
'Answer again as a single JSON object with the fields answer and evidence, where "answer" holds:',
|
|
209
|
+
...describeAnswerShape(input.answerShape),
|
|
210
|
+
"Return the JSON object and nothing else.",
|
|
211
|
+
].join("\n"),
|
|
212
|
+
},
|
|
213
|
+
];
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The framings a model wraps its JSON in: a fenced code block, the bare
|
|
217
|
+
* text, and the span between the first `{` and the last `}`. Deduplicated,
|
|
218
|
+
* because a bare object is all three at once.
|
|
219
|
+
*/
|
|
220
|
+
function jsonFramings(content) {
|
|
221
|
+
const candidates = [content.trim()];
|
|
222
|
+
const fenced = /```(?:json)?\s*([\s\S]*?)```/i.exec(content);
|
|
223
|
+
if (fenced?.[1])
|
|
224
|
+
candidates.unshift(fenced[1].trim());
|
|
225
|
+
const first = content.indexOf("{");
|
|
226
|
+
const last = content.lastIndexOf("}");
|
|
227
|
+
if (first !== -1 && last > first) {
|
|
228
|
+
candidates.push(content.slice(first, last + 1));
|
|
229
|
+
}
|
|
230
|
+
return [...new Set(candidates)];
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Read the model's JSON answer. Tolerates a fenced code block or leading
|
|
234
|
+
* prose around the object; falls back to the whole text as the answer when
|
|
235
|
+
* no object can be parsed (the answer is still the model's, just unframed).
|
|
236
|
+
*/
|
|
237
|
+
export function parseAnswer(content) {
|
|
238
|
+
for (const candidate of jsonFramings(content)) {
|
|
239
|
+
try {
|
|
240
|
+
const parsed = JSON.parse(candidate);
|
|
241
|
+
if (isRecord(parsed) && typeof parsed.answer === "string") {
|
|
242
|
+
return {
|
|
243
|
+
answer: parsed.answer,
|
|
244
|
+
evidence: typeof parsed.evidence === "string" ? parsed.evidence : null,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
// try the next framing
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return { answer: content.trim(), evidence: null };
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Read the model's reply for a question that declared a shape. Returns
|
|
256
|
+
* every object worth checking, best first: the `answer` member of the
|
|
257
|
+
* envelope, then the envelope itself for a model that put the declared
|
|
258
|
+
* fields at the top level. Empty when nothing parsed as an object at all,
|
|
259
|
+
* which is a shape failure like any other.
|
|
260
|
+
*/
|
|
261
|
+
export function parseShapedAnswer(content) {
|
|
262
|
+
const found = [];
|
|
263
|
+
for (const candidate of jsonFramings(content)) {
|
|
264
|
+
let parsed;
|
|
265
|
+
try {
|
|
266
|
+
parsed = JSON.parse(candidate);
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
if (!isRecord(parsed))
|
|
272
|
+
continue;
|
|
273
|
+
const evidence = typeof parsed.evidence === "string" ? parsed.evidence : null;
|
|
274
|
+
if (isRecord(parsed.answer)) {
|
|
275
|
+
found.push({ answer: parsed.answer, evidence });
|
|
276
|
+
}
|
|
277
|
+
found.push({ answer: parsed, evidence });
|
|
278
|
+
}
|
|
279
|
+
return found;
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=prompt.js.map
|