zitejs 0.10.0-start.9 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/auth/actions.d.ts +28 -0
- package/dist/cjs/auth/actions.js +93 -0
- package/dist/cjs/auth/client.d.ts +357 -0
- package/dist/cjs/auth/client.js +66 -0
- package/dist/cjs/auth/config.js +9 -3
- package/dist/cjs/auth/index.d.ts +2 -249
- package/dist/cjs/auth/index.js +11 -108
- package/dist/cjs/auth/index.test.js +60 -0
- package/dist/cjs/auth/previewClaim.d.ts +7 -0
- package/dist/cjs/auth/previewClaim.js +16 -0
- package/dist/cjs/auth/profileUpdates.d.ts +9 -0
- package/dist/cjs/auth/profileUpdates.js +11 -0
- package/dist/cjs/backend/index.d.ts +15 -9
- package/dist/cjs/backend/index.js +13 -13
- package/dist/cjs/backend/index.test.js +102 -102
- package/dist/cjs/bundle/index.d.ts +8 -0
- package/dist/cjs/bundle/index.js +38 -24
- package/dist/cjs/caller/index.js +43 -43
- package/dist/cjs/check/index.d.ts +20 -9
- package/dist/cjs/check/index.js +113 -88
- package/dist/cjs/check/start/routeTree.d.ts +8 -0
- package/dist/cjs/check/start/routeTree.js +118 -0
- package/dist/cjs/check/start/tsgo.d.ts +2 -0
- package/dist/cjs/check/start/tsgo.js +35 -0
- package/dist/cjs/cli.js +10 -4
- package/dist/cjs/client/index.d.ts +26 -2
- package/dist/cjs/client/index.js +25 -25
- package/dist/cjs/dev/index.js +79 -54
- package/dist/cjs/dev/signin.d.ts +16 -0
- package/dist/cjs/dev/signin.js +84 -0
- package/dist/cjs/index.d.ts +5 -5
- package/dist/cjs/integrations/client.d.ts +3 -3
- package/dist/cjs/integrations/client.js +5 -4
- package/dist/cjs/integrations/client.test-d.js +15 -15
- package/dist/cjs/integrations/index.d.ts +2 -2
- package/dist/cjs/integrations/rules.d.ts +1 -0
- package/dist/cjs/integrations/rules.js +48 -43
- package/dist/cjs/integrations/rules.test.js +60 -54
- package/dist/cjs/internal/appMode.d.ts +14 -0
- package/dist/cjs/internal/appMode.js +19 -0
- package/dist/cjs/internal/env.js +3 -2
- package/dist/cjs/internal/platformFetch.d.ts +2 -0
- package/dist/cjs/internal/platformFetch.js +14 -0
- package/dist/cjs/internal/reservedIds.d.ts +8 -0
- package/dist/cjs/internal/reservedIds.js +14 -0
- package/dist/cjs/internal/serviceUrls.d.ts +5 -0
- package/dist/cjs/internal/serviceUrls.js +14 -0
- package/dist/cjs/pdf/index.js +2 -1
- package/dist/cjs/runtime/filterConditionTypes.test-d.js +11 -11
- package/dist/cjs/runtime/index.d.ts +126 -39
- package/dist/cjs/runtime/index.js +32 -26
- package/dist/cjs/runtime/index.test.js +34 -34
- package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +50 -0
- package/dist/cjs/runtime/writeResultTypes.test-d.js +8 -8
- package/dist/cjs/sourceRoots.js +15 -15
- package/dist/cjs/sourceRoots.test.js +29 -27
- package/dist/cjs/start/{entries.d.ts → build/entries.d.ts} +9 -4
- package/dist/cjs/start/{entries.js → build/entries.js} +38 -21
- package/dist/cjs/start/build/placeholders/devApp.d.ts +1 -0
- package/dist/cjs/start/build/placeholders/devApp.js +6 -0
- package/dist/cjs/start/{describeBuilt.d.ts → describe/describeBuilt.d.ts} +2 -0
- package/dist/cjs/start/{describeBuilt.js → describe/describeBuilt.js} +55 -17
- package/dist/cjs/start/platform/aiUsage.d.ts +29 -0
- package/dist/cjs/start/platform/aiUsage.js +215 -0
- package/dist/cjs/start/platform/airtable/cache.d.ts +17 -0
- package/dist/cjs/start/platform/airtable/cache.js +93 -0
- package/dist/cjs/start/protocol.d.ts +19 -0
- package/dist/cjs/start/protocol.js +33 -0
- package/dist/cjs/start/serve/local/provider.d.ts +25 -0
- package/dist/cjs/start/serve/local/provider.js +196 -0
- package/dist/cjs/start/serve/provider.d.ts +19 -0
- package/dist/cjs/start/serve/provider.js +86 -0
- package/dist/cjs/start/types.d.ts +373 -0
- package/dist/cjs/start/types.js +2 -0
- package/dist/cjs/steps/index.d.ts +78 -0
- package/dist/cjs/steps/index.js +507 -0
- package/dist/cjs/steps/index.test.js +635 -0
- package/dist/cjs/sync/index.d.ts +1 -1
- package/dist/cjs/sync/index.js +28 -27
- package/dist/cjs/sync/lib.d.ts +15 -8
- package/dist/cjs/sync/lib.js +655 -655
- package/dist/cjs/sync/lib.test.js +177 -46
- package/dist/cjs/sync/sdkNames.d.ts +67 -9
- package/dist/cjs/sync/sdkNames.js +97 -31
- package/dist/cjs/sync/sdkNames.test.js +189 -113
- package/dist/cjs/types/fields.d.ts +9 -2
- package/dist/cjs/types/fields.js +110 -96
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/cjs/types/tables.d.ts +17 -1
- package/dist/cjs/upload/index.js +89 -24
- package/dist/cjs/upload/index.test.js +104 -1
- package/dist/cjs/vite/domTagNames.js +252 -252
- package/dist/cjs/vite/index.d.ts +1 -1
- package/dist/cjs/vite/index.js +46 -42
- package/dist/esm/auth/actions.d.ts +28 -0
- package/dist/esm/auth/actions.js +55 -0
- package/dist/esm/auth/client.d.ts +357 -0
- package/dist/esm/auth/client.js +62 -0
- package/dist/esm/auth/config.js +9 -3
- package/dist/esm/auth/index.d.ts +2 -249
- package/dist/esm/auth/index.js +2 -103
- package/dist/esm/auth/index.test.js +60 -0
- package/dist/esm/auth/previewClaim.d.ts +7 -0
- package/dist/esm/auth/previewClaim.js +12 -0
- package/dist/esm/auth/profileUpdates.d.ts +9 -0
- package/dist/esm/auth/profileUpdates.js +6 -0
- package/dist/esm/backend/index.d.ts +15 -9
- package/dist/esm/backend/index.js +13 -13
- package/dist/esm/backend/index.test.js +106 -106
- package/dist/esm/bundle/index.d.ts +8 -0
- package/dist/esm/bundle/index.js +37 -24
- package/dist/esm/caller/index.js +44 -44
- package/dist/esm/check/index.d.ts +20 -9
- package/dist/esm/check/index.js +117 -93
- package/dist/esm/check/start/routeTree.d.ts +8 -0
- package/dist/esm/check/start/routeTree.js +77 -0
- package/dist/esm/check/start/tsgo.d.ts +2 -0
- package/dist/esm/check/start/tsgo.js +29 -0
- package/dist/esm/cli.js +10 -4
- package/dist/esm/client/index.d.ts +26 -2
- package/dist/esm/client/index.js +25 -25
- package/dist/esm/dev/index.js +86 -61
- package/dist/esm/dev/signin.d.ts +16 -0
- package/dist/esm/dev/signin.js +80 -0
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.js +3 -3
- package/dist/esm/integrations/client.d.ts +3 -3
- package/dist/esm/integrations/client.js +6 -5
- package/dist/esm/integrations/client.test-d.js +19 -19
- package/dist/esm/integrations/index.d.ts +2 -2
- package/dist/esm/integrations/index.js +1 -1
- package/dist/esm/integrations/rules.d.ts +1 -0
- package/dist/esm/integrations/rules.js +48 -43
- package/dist/esm/integrations/rules.test.js +62 -56
- package/dist/esm/internal/appMode.d.ts +14 -0
- package/dist/esm/internal/appMode.js +13 -0
- package/dist/esm/internal/env.js +3 -2
- package/dist/esm/internal/platformFetch.d.ts +2 -0
- package/dist/esm/internal/platformFetch.js +9 -0
- package/dist/esm/internal/reservedIds.d.ts +8 -0
- package/dist/esm/internal/reservedIds.js +10 -0
- package/dist/esm/internal/serviceUrls.d.ts +5 -0
- package/dist/esm/internal/serviceUrls.js +10 -0
- package/dist/esm/pdf/index.js +2 -1
- package/dist/esm/runtime/filterConditionTypes.test-d.js +12 -12
- package/dist/esm/runtime/index.d.ts +126 -39
- package/dist/esm/runtime/index.js +35 -29
- package/dist/esm/runtime/index.test.js +36 -36
- package/dist/esm/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
- package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +48 -0
- package/dist/esm/runtime/writeResultTypes.test-d.js +9 -9
- package/dist/esm/signin/conformance.d.ts +100 -0
- package/dist/esm/signin/conformance.js +616 -0
- package/dist/esm/signin/cookies.d.ts +28 -0
- package/dist/esm/signin/cookies.js +67 -0
- package/dist/esm/signin/encoding.d.ts +1 -0
- package/dist/esm/signin/encoding.js +12 -0
- package/dist/esm/signin/endpoints.d.ts +12 -0
- package/dist/esm/signin/endpoints.js +32 -0
- package/dist/esm/signin/http.d.ts +25 -0
- package/dist/esm/signin/http.js +106 -0
- package/dist/esm/signin/index.d.ts +8 -0
- package/dist/esm/signin/index.js +9 -0
- package/dist/esm/signin/keys.d.ts +35 -0
- package/dist/esm/signin/keys.js +230 -0
- package/dist/esm/signin/paths.d.ts +2 -0
- package/dist/esm/signin/paths.js +5 -0
- package/dist/esm/signin/seal.d.ts +19 -0
- package/dist/esm/signin/seal.js +47 -0
- package/dist/esm/signin/signin.d.ts +60 -0
- package/dist/esm/signin/signin.js +447 -0
- package/dist/esm/signin/transport.d.ts +112 -0
- package/dist/esm/signin/transport.js +1 -0
- package/dist/esm/signin/verifier.d.ts +2 -0
- package/dist/esm/signin/verifier.js +4 -0
- package/dist/esm/signin/verify.d.ts +83 -0
- package/dist/esm/signin/verify.js +142 -0
- package/dist/esm/sourceRoots.js +17 -17
- package/dist/esm/sourceRoots.test.js +34 -32
- package/dist/esm/start/access.d.ts +19 -0
- package/dist/esm/start/access.js +43 -0
- package/dist/esm/start/auth.d.ts +28 -0
- package/dist/esm/start/auth.js +33 -0
- package/dist/esm/start/automations/quiet.d.ts +2 -0
- package/dist/esm/start/automations/quiet.js +36 -0
- package/dist/esm/start/{registration.d.ts → automations/registration.d.ts} +1 -1
- package/dist/esm/start/{registration.js → automations/registration.js} +11 -7
- package/dist/esm/start/automations/steps.d.ts +29 -0
- package/dist/esm/start/automations/steps.js +95 -0
- package/dist/esm/start/automations/workflow.d.ts +83 -0
- package/dist/esm/start/automations/workflow.js +36 -0
- package/dist/esm/start/automations/workflow.test-d.d.ts +1 -0
- package/dist/esm/start/automations/workflow.test-d.js +130 -0
- package/dist/esm/start/automations/workflowRun.d.ts +130 -0
- package/dist/esm/start/automations/workflowRun.js +185 -0
- package/dist/esm/start/barrel.test-d.d.ts +10 -0
- package/dist/esm/start/barrel.test-d.js +6 -0
- package/dist/esm/start/{entries.d.ts → build/entries.d.ts} +9 -4
- package/dist/esm/start/{entries.js → build/entries.js} +38 -22
- package/dist/esm/start/build/placeholders/devApp.d.ts +1 -0
- package/dist/esm/start/build/placeholders/devApp.js +3 -0
- package/dist/esm/start/build/placeholders/devSignIn.d.ts +1 -0
- package/dist/esm/start/build/placeholders/devSignIn.js +3 -0
- package/dist/esm/start/build/placeholders/siteHead.d.ts +2 -0
- package/dist/esm/start/build/placeholders/siteHead.js +3 -0
- package/dist/esm/start/{workflowModules.js → build/placeholders/workflowModules.js} +1 -1
- package/dist/esm/start/build/placeholders/workspaceSchema.d.ts +2 -0
- package/dist/esm/start/build/placeholders/workspaceSchema.js +3 -0
- package/dist/esm/start/build/registrationHash.d.ts +11 -0
- package/dist/esm/start/build/registrationHash.js +88 -0
- package/dist/esm/start/build/sdk/axios.d.ts +76 -0
- package/dist/esm/start/build/sdk/axios.js +253 -0
- package/dist/esm/start/build/sdk/nodeFetch.d.ts +41 -0
- package/dist/esm/start/build/sdk/nodeFetch.js +35 -0
- package/dist/esm/start/build/sdk/undici.d.ts +34 -0
- package/dist/esm/start/build/sdk/undici.js +18 -0
- package/dist/esm/start/build/sdkPatches.d.ts +22 -0
- package/dist/esm/start/build/sdkPatches.js +430 -0
- package/dist/esm/start/build/siteHead.d.ts +26 -0
- package/dist/esm/start/build/siteHead.js +88 -0
- package/dist/esm/start/build/vite.d.ts +50 -0
- package/dist/esm/start/build/vite.js +487 -0
- package/dist/esm/start/classicOnly.d.ts +1 -0
- package/dist/esm/start/classicOnly.js +4 -0
- package/dist/esm/start/{describe.d.ts → describe/describe.d.ts} +44 -9
- package/dist/esm/start/describe/describe.js +372 -0
- package/dist/esm/start/{describeBuilt.d.ts → describe/describeBuilt.d.ts} +2 -0
- package/dist/esm/start/describe/describeBuilt.js +102 -0
- package/dist/esm/start/{descriptions.js → describe/descriptions.js} +17 -10
- package/dist/esm/start/errors.d.ts +15 -4
- package/dist/esm/start/errors.js +87 -28
- package/dist/esm/start/errors.test.js +47 -16
- package/dist/esm/start/factories.d.ts +14 -0
- package/dist/esm/start/factories.js +23 -0
- package/dist/esm/start/factories.test-d.d.ts +2 -1
- package/dist/esm/start/factories.test-d.js +52 -12
- package/dist/esm/start/failures.d.ts +7 -0
- package/dist/esm/start/failures.js +62 -0
- package/dist/esm/start/fnFactory.d.ts +16 -0
- package/dist/esm/start/fnFactory.js +1 -0
- package/dist/esm/start/host.d.ts +2 -2
- package/dist/esm/start/host.js +3 -3
- package/dist/esm/start/index.d.ts +10 -66
- package/dist/esm/start/index.js +7 -146
- package/dist/esm/start/login.d.ts +5 -0
- package/dist/esm/start/login.js +29 -0
- package/dist/esm/start/middlewareKind.d.ts +13 -0
- package/dist/esm/start/middlewareKind.js +9 -0
- package/dist/esm/start/platform/aiUsage.d.ts +29 -0
- package/dist/esm/start/platform/aiUsage.js +210 -0
- package/dist/esm/start/platform/airtable/built.d.ts +2 -0
- package/dist/esm/start/platform/airtable/built.js +3 -0
- package/dist/esm/start/platform/airtable/cache.d.ts +17 -0
- package/dist/esm/start/platform/airtable/cache.js +89 -0
- package/dist/esm/start/{airtable → platform/airtable}/dispatch.d.ts +5 -2
- package/dist/esm/start/{airtable → platform/airtable}/dispatch.js +195 -119
- package/dist/esm/start/{airtable → platform/airtable}/formulas.d.ts +2 -1
- package/dist/esm/start/{airtable → platform/airtable}/formulas.js +51 -25
- package/dist/esm/start/platform/airtable/index.d.ts +6 -0
- package/dist/esm/start/platform/airtable/index.js +51 -0
- package/dist/esm/start/platform/airtable/settings.d.ts +37 -0
- package/dist/esm/start/platform/airtable/settings.js +138 -0
- package/dist/esm/start/platform/analytics.d.ts +3 -0
- package/dist/esm/start/platform/analytics.js +59 -0
- package/dist/esm/start/platform/calls.d.ts +5 -0
- package/dist/esm/start/platform/calls.js +104 -0
- package/dist/esm/start/platform/caps.d.ts +9 -0
- package/dist/esm/start/platform/caps.js +35 -0
- package/dist/esm/start/platform/connections.d.ts +25 -0
- package/dist/esm/start/platform/connections.js +198 -0
- package/dist/esm/start/{data → platform/data}/baseRunner.d.ts +11 -6
- package/dist/esm/start/platform/data/baseRunner.js +117 -0
- package/dist/esm/start/{data → platform/data}/dispatch.d.ts +3 -2
- package/dist/esm/start/{data → platform/data}/dispatch.js +69 -51
- package/dist/esm/start/platform/data/fetch.d.ts +7 -0
- package/dist/esm/start/platform/data/fetch.js +9 -0
- package/dist/esm/start/platform/data/index.d.ts +27 -0
- package/dist/esm/start/platform/data/index.js +75 -0
- package/dist/esm/start/platform/data/names.d.ts +7 -0
- package/dist/esm/start/platform/data/names.js +18 -0
- package/dist/esm/start/{data → platform/data}/transformations.d.ts +0 -31
- package/dist/esm/start/{data → platform/data}/transformations.js +0 -56
- package/dist/esm/start/{data → platform/data}/types.d.ts +4 -1
- package/dist/esm/start/{data → platform/data}/types.js +2 -2
- package/dist/esm/start/platform/local.d.ts +6 -0
- package/dist/esm/start/platform/local.js +18 -0
- package/dist/esm/start/platform/meta.d.ts +3 -0
- package/dist/esm/start/platform/meta.js +33 -0
- package/dist/esm/start/platform/outbound.d.ts +17 -0
- package/dist/esm/start/platform/outbound.js +510 -0
- package/dist/esm/start/platform/redactSecrets.d.ts +13 -0
- package/dist/esm/start/{redactSecrets.js → platform/redactSecrets.js} +32 -7
- package/dist/esm/start/platform/redactSecrets.test.d.ts +1 -0
- package/dist/esm/start/platform/requestSecrets.d.ts +15 -0
- package/dist/esm/start/platform/requestSecrets.js +41 -0
- package/dist/esm/start/platform/runLog.d.ts +40 -0
- package/dist/esm/start/platform/runLog.js +149 -0
- package/dist/esm/start/platform/services.d.ts +7 -0
- package/dist/esm/start/platform/services.js +46 -0
- package/dist/esm/start/platform/steps.d.ts +9 -0
- package/dist/esm/start/platform/steps.js +60 -0
- package/dist/esm/start/platform/telemetry.d.ts +13 -0
- package/dist/esm/start/platform/telemetry.js +71 -0
- package/dist/esm/start/platform/transport.d.ts +28 -0
- package/dist/esm/start/platform/transport.js +59 -0
- package/dist/esm/start/platformHead.d.ts +23 -0
- package/dist/esm/start/platformHead.js +133 -0
- package/dist/esm/start/previewClaim.d.ts +3 -7
- package/dist/esm/start/previewClaim.js +9 -17
- package/dist/esm/start/protocol.d.ts +19 -0
- package/dist/esm/start/protocol.js +27 -0
- package/dist/esm/start/roles.d.ts +12 -0
- package/dist/esm/start/roles.js +27 -0
- package/dist/esm/start/router.d.ts +27 -4
- package/dist/esm/start/router.js +221 -22
- package/dist/esm/start/serve/authHooks.js +18 -0
- package/dist/esm/start/serve/demo.d.ts +9 -0
- package/dist/esm/start/serve/demo.js +24 -0
- package/dist/esm/start/serve/fetch.d.ts +1 -0
- package/dist/esm/start/serve/fetch.js +6 -0
- package/dist/esm/start/{instance.d.ts → serve/instance.d.ts} +6 -5
- package/dist/esm/start/serve/instance.js +134 -0
- package/dist/esm/start/serve/invoke.d.ts +13 -0
- package/dist/esm/start/serve/invoke.js +126 -0
- package/dist/esm/start/serve/local/load.d.ts +8 -0
- package/dist/esm/start/serve/local/load.js +44 -0
- package/dist/esm/start/serve/local/provider.d.ts +25 -0
- package/dist/esm/start/serve/local/provider.js +188 -0
- package/dist/esm/start/serve/local/signIn.d.ts +28 -0
- package/dist/esm/start/serve/local/signIn.js +123 -0
- package/dist/esm/start/serve/pageHead.d.ts +20 -0
- package/dist/esm/start/serve/pageHead.js +34 -0
- package/dist/esm/start/serve/provider.d.ts +19 -0
- package/dist/esm/start/serve/provider.js +78 -0
- package/dist/esm/start/serve/requestEnv.d.ts +2 -0
- package/dist/esm/start/serve/requestEnv.js +84 -0
- package/dist/esm/start/serve/scope.d.ts +18 -0
- package/dist/esm/start/serve/scope.js +67 -0
- package/dist/esm/start/serve/server.d.ts +56 -0
- package/dist/esm/start/serve/server.js +297 -0
- package/dist/esm/start/serve/uploads.d.ts +2 -0
- package/dist/esm/start/serve/uploads.js +49 -0
- package/dist/esm/start/serve/worker.d.ts +6 -0
- package/dist/esm/start/serve/worker.js +12 -0
- package/dist/esm/start/types.d.ts +270 -56
- package/dist/esm/start/version.d.ts +1 -1
- package/dist/esm/start/version.js +1 -1
- package/dist/esm/steps/index.d.ts +78 -0
- package/dist/esm/steps/index.js +502 -0
- package/dist/esm/steps/index.test.d.ts +1 -0
- package/dist/esm/steps/index.test.js +633 -0
- package/dist/esm/sync/index.d.ts +1 -1
- package/dist/esm/sync/index.js +32 -31
- package/dist/esm/sync/lib.d.ts +15 -8
- package/dist/esm/sync/lib.js +659 -659
- package/dist/esm/sync/lib.test.js +177 -46
- package/dist/esm/sync/sdkNames.d.ts +67 -9
- package/dist/esm/sync/sdkNames.js +94 -30
- package/dist/esm/sync/sdkNames.test.js +192 -116
- package/dist/esm/types/fields.d.ts +9 -2
- package/dist/esm/types/fields.js +110 -96
- package/dist/esm/types/index.d.ts +2 -2
- package/dist/esm/types/index.js +2 -2
- package/dist/esm/types/tables.d.ts +17 -1
- package/dist/esm/types/tables.js +2 -2
- package/dist/esm/upload/index.js +89 -24
- package/dist/esm/upload/index.test.js +104 -1
- package/dist/esm/vite/domTagNames.js +252 -252
- package/dist/esm/vite/index.d.ts +1 -1
- package/dist/esm/vite/index.js +51 -47
- package/package.json +95 -37
- package/dist/cjs/auth-server/index.d.ts +0 -369
- package/dist/cjs/auth-server/index.js +0 -119
- package/dist/cjs/check/start/describeRules.d.ts +0 -35
- package/dist/cjs/check/start/describeRules.js +0 -89
- package/dist/cjs/check/start/problem.d.ts +0 -11
- package/dist/cjs/check/start/problem.js +0 -5
- package/dist/cjs/check/start/sourceRules.d.ts +0 -3
- package/dist/cjs/check/start/sourceRules.js +0 -441
- package/dist/cjs/start/problems.d.ts +0 -19
- package/dist/cjs/start/problems.js +0 -11
- package/dist/esm/auth-server/index.d.ts +0 -369
- package/dist/esm/auth-server/index.js +0 -116
- package/dist/esm/check/start/describeRules.d.ts +0 -35
- package/dist/esm/check/start/describeRules.js +0 -86
- package/dist/esm/check/start/problem.d.ts +0 -11
- package/dist/esm/check/start/problem.js +0 -1
- package/dist/esm/check/start/sourceRules.d.ts +0 -3
- package/dist/esm/check/start/sourceRules.js +0 -438
- package/dist/esm/start/airtable/index.d.ts +0 -11
- package/dist/esm/start/airtable/index.js +0 -70
- package/dist/esm/start/authHooks.js +0 -10
- package/dist/esm/start/data/baseRunner.js +0 -83
- package/dist/esm/start/data/index.d.ts +0 -18
- package/dist/esm/start/data/index.js +0 -76
- package/dist/esm/start/describe.js +0 -204
- package/dist/esm/start/describeBuilt.js +0 -66
- package/dist/esm/start/instance.js +0 -80
- package/dist/esm/start/problems.d.ts +0 -19
- package/dist/esm/start/problems.js +0 -8
- package/dist/esm/start/redactSecrets.d.ts +0 -7
- package/dist/esm/start/runLog.d.ts +0 -8
- package/dist/esm/start/runLog.js +0 -76
- package/dist/esm/start/scope.d.ts +0 -15
- package/dist/esm/start/scope.js +0 -58
- package/dist/esm/start/server.d.ts +0 -55
- package/dist/esm/start/server.js +0 -317
- package/dist/esm/start/vite.d.ts +0 -9
- package/dist/esm/start/vite.js +0 -173
- package/dist/esm/start/worker.d.ts +0 -11
- package/dist/esm/start/worker.js +0 -20
- package/dist/esm/start/workflow.d.ts +0 -53
- package/dist/esm/start/workflow.js +0 -13
- package/dist/esm/start/workflow.test-d.js +0 -44
- package/dist/esm/start/workflowRun.d.ts +0 -80
- package/dist/esm/start/workflowRun.js +0 -108
- /package/dist/{esm/start/redactSecrets.test.d.ts → cjs/runtime/sendEmailParamsTypes.test-d.d.ts} +0 -0
- /package/dist/{esm/start/workflow.test-d.d.ts → cjs/steps/index.test.d.ts} +0 -0
- /package/dist/esm/start/{authHooksModule.d.ts → build/placeholders/authHooksModule.d.ts} +0 -0
- /package/dist/esm/start/{authHooksModule.js → build/placeholders/authHooksModule.js} +0 -0
- /package/dist/esm/start/{workflowModules.d.ts → build/placeholders/workflowModules.d.ts} +0 -0
- /package/dist/esm/start/{descriptions.d.ts → describe/descriptions.d.ts} +0 -0
- /package/dist/esm/start/{airtable → platform/airtable}/arrayFields.d.ts +0 -0
- /package/dist/esm/start/{airtable → platform/airtable}/arrayFields.js +0 -0
- /package/dist/esm/start/{data → platform/data}/sqlNameMappings.d.ts +0 -0
- /package/dist/esm/start/{data → platform/data}/sqlNameMappings.js +0 -0
- /package/dist/esm/start/{redactSecrets.test.js → platform/redactSecrets.test.js} +0 -0
- /package/dist/esm/start/{authHooks.d.ts → serve/authHooks.d.ts} +0 -0
package/dist/esm/start/index.js
CHANGED
|
@@ -1,146 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { getHost, inScope, runInScope } from "./scope.js";
|
|
9
|
-
export { isSignInRequired, SIGN_IN_REQUIRED, ZiteError, ZITE_ERROR_STATUS, } from "./errors.js";
|
|
10
|
-
export { createZiteRouter } from "./router.js";
|
|
11
|
-
export { createWorkflow, } from "./workflow.js";
|
|
12
|
-
/** By the role's id or its name. */
|
|
13
|
-
export const hasRole = (user, role) => user.roles.some(({ id, name }) => id === role || name === role);
|
|
14
|
-
/**
|
|
15
|
-
* The platform's sign-in page, returning to `redirectTo` (default: the current
|
|
16
|
-
* page). For guards: `throw redirect({ href: loginHref(), reloadDocument: true })`.
|
|
17
|
-
*/
|
|
18
|
-
export function loginHref(redirectTo) {
|
|
19
|
-
const current = typeof window !== "undefined" ? window.location.href : currentHost()?.url;
|
|
20
|
-
// Absolute on purpose: better-auth drops a relative callback with an encoded
|
|
21
|
-
// space, fragment or non-ASCII path, and never checks an absolute one.
|
|
22
|
-
const target = current ? new URL(redirectTo ?? current, current) : undefined;
|
|
23
|
-
const params = new URLSearchParams();
|
|
24
|
-
if (target && !(target.pathname === "/" && !target.search && !target.hash))
|
|
25
|
-
params.set("redirectUrl", target.toString());
|
|
26
|
-
else if (!target && redirectTo)
|
|
27
|
-
params.set("redirectUrl", redirectTo);
|
|
28
|
-
// The editor preview's sign-in page needs the preview's token, and its claim where the frame dropped the cookie.
|
|
29
|
-
const usageToken = current ? new URL(current).searchParams.get(USAGE_TOKEN_QUERY_PARAM) : null;
|
|
30
|
-
if (usageToken)
|
|
31
|
-
params.set(USAGE_TOKEN_QUERY_PARAM, usageToken);
|
|
32
|
-
const claim = previewClaim();
|
|
33
|
-
if (claim)
|
|
34
|
-
params.set(PREVIEW_CLAIM_PARAM, claim);
|
|
35
|
-
const query = params.toString();
|
|
36
|
-
return query ? `/auth/login?${query}` : "/auth/login";
|
|
37
|
-
}
|
|
38
|
-
const kinds = new WeakMap();
|
|
39
|
-
const tag = (middleware, kind) => {
|
|
40
|
-
kinds.set(middleware, kind);
|
|
41
|
-
return middleware;
|
|
42
|
-
};
|
|
43
|
-
/** @internal */
|
|
44
|
-
export const ziteMiddlewareKind = (middleware) => typeof middleware === "object" && middleware !== null ? kinds.get(middleware) : undefined;
|
|
45
|
-
// Identity comes from server-only storage, never TanStack's context, which
|
|
46
|
-
// merges whatever context the browser sends.
|
|
47
|
-
const host = () => {
|
|
48
|
-
const current = getHost();
|
|
49
|
-
if (!current)
|
|
50
|
-
throw new ZiteError("UNAUTHORIZED", "Missing platform context");
|
|
51
|
-
return current;
|
|
52
|
-
};
|
|
53
|
-
// TanStack fails a validator with a plain Error whose message is the issues as JSON.
|
|
54
|
-
const validationIssues = (error) => {
|
|
55
|
-
if (!(error instanceof Error) || error.constructor !== Error)
|
|
56
|
-
return undefined;
|
|
57
|
-
try {
|
|
58
|
-
const issues = JSON.parse(error.message);
|
|
59
|
-
return Array.isArray(issues) && issues.length > 0 && issues.every((issue) => typeof issue?.message === "string")
|
|
60
|
-
? issues
|
|
61
|
-
: undefined;
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const invalidInput = (issues) => {
|
|
68
|
-
if (getHost()?.mode !== "preview")
|
|
69
|
-
return new ZiteError("INVALID_INPUT", "Invalid input");
|
|
70
|
-
const describe = ({ message, path = [] }) => {
|
|
71
|
-
const at = path.map((segment) => String(typeof segment === "object" ? segment.key : segment)).join(".");
|
|
72
|
-
return at ? `${at}: ${message}` : message;
|
|
73
|
-
};
|
|
74
|
-
return new ZiteError("INVALID_INPUT", issues.map(describe).join("; "));
|
|
75
|
-
};
|
|
76
|
-
// Server functions report a status through TanStack's error envelope; server
|
|
77
|
-
// routes need a Response. A nested call's failure is the caller's to handle.
|
|
78
|
-
const withStatus = async (isServerFn, fn) => {
|
|
79
|
-
const nested = inScope();
|
|
80
|
-
try {
|
|
81
|
-
return await fn();
|
|
82
|
-
}
|
|
83
|
-
catch (caught) {
|
|
84
|
-
const issues = validationIssues(caught);
|
|
85
|
-
const error = issues ? invalidInput(issues) : asZiteError(caught);
|
|
86
|
-
if (!isServerFn) {
|
|
87
|
-
if (!error)
|
|
88
|
-
throw caught;
|
|
89
|
-
const message = toClientErrorMessage(error.message, getHost()?.mode, error.userFacingMessage);
|
|
90
|
-
return new Response(message, { status: ZITE_ERROR_STATUS[error.code] });
|
|
91
|
-
}
|
|
92
|
-
// TanStack answers a failed server function 200, with the error in the body. Redirects and notFound aren't Errors.
|
|
93
|
-
if (!nested && (error || caught instanceof Error))
|
|
94
|
-
setResponseStatus(error ? ZITE_ERROR_STATUS[error.code] : 500);
|
|
95
|
-
throw error ?? caught;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
// A server route's run is recorded around its access decision, so a refusal shows with its status.
|
|
99
|
-
const decide = (serverFnMeta, request, fn) => serverFnMeta ? withStatus(true, fn) : recordRoute(getHost(), request, () => withStatus(false, fn));
|
|
100
|
-
/** Only signed-in users. Handlers get `context.user: User`. */
|
|
101
|
-
export const signedIn = tag(createMiddleware().server(({ next, serverFnMeta, request }) => decide(serverFnMeta, request, async () => {
|
|
102
|
-
const { user } = host();
|
|
103
|
-
if (!user)
|
|
104
|
-
throw new ZiteError("UNAUTHORIZED", SIGN_IN_REQUIRED);
|
|
105
|
-
return runInScope({ kind: "signedIn", user }, () => next({ context: { user } }));
|
|
106
|
-
})), { kind: "signedIn" });
|
|
107
|
-
/** Anyone, signed in or not. Handlers get `context.user: User | null`. */
|
|
108
|
-
export const anyone = tag(createMiddleware().server(({ next, serverFnMeta, request }) => decide(serverFnMeta, request, async () => {
|
|
109
|
-
const { user } = host();
|
|
110
|
-
return runInScope({ kind: "anyone", user }, () => next({ context: { user } }));
|
|
111
|
-
})), { kind: "anyone" });
|
|
112
|
-
const webhookMiddleware = (paused) => tag(createMiddleware().server(({ next, request }) => {
|
|
113
|
-
if (host().invoke?.kind !== "webhook")
|
|
114
|
-
return new Response("Not found", { status: 404 });
|
|
115
|
-
return recordRoute(getHost(), request, async () => runInScope({ kind: "webhook", user: null }, () => next()));
|
|
116
|
-
}), paused ? { kind: "webhook", paused: true } : { kind: "webhook" });
|
|
117
|
-
/**
|
|
118
|
-
* Webhooks delivered by the platform, which already checked the URL token.
|
|
119
|
-
* `webhook.paused` keeps the URL but runs nothing: the platform answers the
|
|
120
|
-
* provider 200 and drops the delivery until it's switched back.
|
|
121
|
-
*/
|
|
122
|
-
export const webhook = Object.assign(webhookMiddleware(false), { paused: webhookMiddleware(true) });
|
|
123
|
-
/** Signed-in users with this role. */
|
|
124
|
-
export const role = (name) => tag(createMiddleware()
|
|
125
|
-
.middleware([signedIn])
|
|
126
|
-
.server(({ next, context, serverFnMeta }) => withStatus(!!serverFnMeta, async () => {
|
|
127
|
-
if (!hasRole(context.user, name))
|
|
128
|
-
throw new ZiteError("FORBIDDEN", `Requires the ${name} role`);
|
|
129
|
-
return next();
|
|
130
|
-
})), { kind: "role", role: name });
|
|
131
|
-
// TanStack's compiler tags every server function it compiles with an id. A
|
|
132
|
-
// builder it didn't compile (an object property, one returned from a helper)
|
|
133
|
-
// has none and would run its handler wherever it was called, so it fails here.
|
|
134
|
-
const compiled = tag(createMiddleware({ type: "function" }).client(({ next, serverFnMeta }) => {
|
|
135
|
-
if (!serverFnMeta?.id) {
|
|
136
|
-
throw new Error("This server function was not compiled by TanStack Start. Assign signedInFn(...)/publicFn(...)" +
|
|
137
|
-
".handler(...) directly to its own top-level const, not an object property or a helper's return value.");
|
|
138
|
-
}
|
|
139
|
-
return next();
|
|
140
|
-
}), { kind: "factory" });
|
|
141
|
-
// TanStack doesn't export its builder-after-middleware type, so name it through the public builder.
|
|
142
|
-
const builder = createServerFn();
|
|
143
|
-
/** A server function only signed-in users can call. */
|
|
144
|
-
export const signedInFn = createServerFn().middleware([compiled, signedIn]);
|
|
145
|
-
/** A server function anyone can call (external apps only). */
|
|
146
|
-
export const publicFn = createServerFn().middleware([compiled, anyone]);
|
|
1
|
+
export { isSignInRequired, SIGN_IN_REQUIRED, ZiteError, } from './errors.js';
|
|
2
|
+
export { createZiteRouter } from './router.js';
|
|
3
|
+
export { createAutomation, createProviderTrigger, } from './automations/workflow.js';
|
|
4
|
+
export { anyone, signedIn, webhook } from './access.js';
|
|
5
|
+
export { publicFn, signedInFn } from './factories.js';
|
|
6
|
+
export { loginHref } from './login.js';
|
|
7
|
+
export { hasRole, role } from './roles.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { USAGE_TOKEN_QUERY_PARAM } from '../auth/constants.js';
|
|
2
|
+
import { currentHost } from './host.js';
|
|
3
|
+
import { PREVIEW_CLAIM_PARAM, previewClaim } from './previewClaim.js';
|
|
4
|
+
/**
|
|
5
|
+
* The platform's sign-in page, returning to `redirectTo` (default: the current
|
|
6
|
+
* page). For guards: `throw redirect({ href: loginHref(), reloadDocument: true })`.
|
|
7
|
+
*/
|
|
8
|
+
export function loginHref(redirectTo) {
|
|
9
|
+
const current = typeof window !== 'undefined' ? window.location.href : currentHost()?.url;
|
|
10
|
+
// Absolute on purpose: better-auth drops a relative callback with an encoded
|
|
11
|
+
// space, fragment or non-ASCII path, and never checks an absolute one.
|
|
12
|
+
const target = current ? new URL(redirectTo ?? current, current) : undefined;
|
|
13
|
+
const params = new URLSearchParams();
|
|
14
|
+
if (target && !(target.pathname === '/' && !target.search && !target.hash))
|
|
15
|
+
params.set('redirectUrl', target.toString());
|
|
16
|
+
else if (!target && redirectTo)
|
|
17
|
+
params.set('redirectUrl', redirectTo);
|
|
18
|
+
// The editor preview's sign-in page needs the preview's token, and its claim where the frame dropped the cookie.
|
|
19
|
+
const usageToken = current
|
|
20
|
+
? new URL(current).searchParams.get(USAGE_TOKEN_QUERY_PARAM)
|
|
21
|
+
: null;
|
|
22
|
+
if (usageToken)
|
|
23
|
+
params.set(USAGE_TOKEN_QUERY_PARAM, usageToken);
|
|
24
|
+
const claim = previewClaim();
|
|
25
|
+
if (claim)
|
|
26
|
+
params.set(PREVIEW_CLAIM_PARAM, claim);
|
|
27
|
+
const query = params.toString();
|
|
28
|
+
return query ? `/auth/login?${query}` : '/auth/login';
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** What a zitejs middleware means, for describe. Keyed by identity, so composing or re-exporting keeps it. */
|
|
2
|
+
export type ZiteMiddlewareKind = {
|
|
3
|
+
kind: 'signedIn' | 'anyone' | 'factory';
|
|
4
|
+
} | {
|
|
5
|
+
kind: 'webhook';
|
|
6
|
+
paused?: true;
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'role';
|
|
9
|
+
role: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const tag: <T extends object>(middleware: T, kind: ZiteMiddlewareKind) => T;
|
|
12
|
+
/** @internal */
|
|
13
|
+
export declare const ziteMiddlewareKind: (middleware: unknown) => ZiteMiddlewareKind | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const kinds = new WeakMap();
|
|
2
|
+
export const tag = (middleware, kind) => {
|
|
3
|
+
kinds.set(middleware, kind);
|
|
4
|
+
return middleware;
|
|
5
|
+
};
|
|
6
|
+
/** @internal */
|
|
7
|
+
export const ziteMiddlewareKind = (middleware) => typeof middleware === 'object' && middleware !== null
|
|
8
|
+
? kinds.get(middleware)
|
|
9
|
+
: undefined;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a call on an org's own AI key used, read from the provider's answer as
|
|
3
|
+
* classic's runtime reads it. For analytics only: the org pays the provider.
|
|
4
|
+
* OpenAI, Anthropic and Gemini; the host meters Zite's own key itself.
|
|
5
|
+
*/
|
|
6
|
+
export type AiProvider = 'openai' | 'anthropic' | 'gemini';
|
|
7
|
+
export type AiUsageRecord = {
|
|
8
|
+
provider: AiProvider;
|
|
9
|
+
model?: string;
|
|
10
|
+
inputTokens?: number;
|
|
11
|
+
outputTokens?: number;
|
|
12
|
+
cachedReadInputTokens?: number;
|
|
13
|
+
cacheCreationInputTokens?: number;
|
|
14
|
+
isStreaming?: true;
|
|
15
|
+
};
|
|
16
|
+
export declare const AI_USAGE_HOSTS: Record<string, AiProvider>;
|
|
17
|
+
/** As classic: an OpenAI chat stream reports its usage only when asked to. The body to send instead, if any. */
|
|
18
|
+
export declare const withStreamUsage: (url: URL, method: string, body: unknown) => string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The response to hand the app, and its usage once read; a stream is split so the app reads one copy as it arrives.
|
|
21
|
+
* `request` is what the app sent, which names Gemini's model and holds what its embeddings are estimated from.
|
|
22
|
+
*/
|
|
23
|
+
export declare const meterAiResponse: (provider: AiProvider, response: Response, request: {
|
|
24
|
+
url: URL;
|
|
25
|
+
body: unknown;
|
|
26
|
+
}) => {
|
|
27
|
+
response: Response;
|
|
28
|
+
usage: Promise<AiUsageRecord | undefined>;
|
|
29
|
+
};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a call on an org's own AI key used, read from the provider's answer as
|
|
3
|
+
* classic's runtime reads it. For analytics only: the org pays the provider.
|
|
4
|
+
* OpenAI, Anthropic and Gemini; the host meters Zite's own key itself.
|
|
5
|
+
*/
|
|
6
|
+
export const AI_USAGE_HOSTS = {
|
|
7
|
+
'api.openai.com': 'openai',
|
|
8
|
+
'api.anthropic.com': 'anthropic',
|
|
9
|
+
'generativelanguage.googleapis.com': 'gemini',
|
|
10
|
+
};
|
|
11
|
+
// Gemini's answers name no model, so it's read from the path: `/v1beta/models/gemini-2.0-flash:generateContent`.
|
|
12
|
+
const geminiModelOf = (url) => /\/models\/([^/:]+)/.exec(url.pathname)?.[1];
|
|
13
|
+
// Gemini's embeddings answer with no usage, so classic estimates their input at four characters a token.
|
|
14
|
+
const GEMINI_EMBED_PATH = /:(embedContent|batchEmbedContents)$/;
|
|
15
|
+
const geminiEmbedTokens = (body) => {
|
|
16
|
+
let parsed;
|
|
17
|
+
try {
|
|
18
|
+
parsed = typeof body === 'string' ? JSON.parse(body) : undefined;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
if (!isRecord(parsed))
|
|
24
|
+
return 0;
|
|
25
|
+
const contents = Array.isArray(parsed.requests)
|
|
26
|
+
? parsed.requests.map(request => isRecord(request) ? request.content : undefined)
|
|
27
|
+
: [parsed.content];
|
|
28
|
+
const chars = contents
|
|
29
|
+
.flatMap(content => isRecord(content) && Array.isArray(content.parts) ? content.parts : [])
|
|
30
|
+
.reduce((sum, part) => sum +
|
|
31
|
+
(isRecord(part) && typeof part.text === 'string'
|
|
32
|
+
? part.text.length
|
|
33
|
+
: 0), 0);
|
|
34
|
+
return chars > 0 ? Math.ceil(chars / 4) : 0;
|
|
35
|
+
};
|
|
36
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
37
|
+
const isNumber = (value) => typeof value === 'number' && Number.isFinite(value);
|
|
38
|
+
/** As classic: an OpenAI chat stream reports its usage only when asked to. The body to send instead, if any. */
|
|
39
|
+
export const withStreamUsage = (url, method, body) => {
|
|
40
|
+
if (method !== 'POST' ||
|
|
41
|
+
typeof body !== 'string' ||
|
|
42
|
+
!url.pathname.endsWith('/chat/completions'))
|
|
43
|
+
return undefined;
|
|
44
|
+
try {
|
|
45
|
+
const json = JSON.parse(body);
|
|
46
|
+
if (!isRecord(json) || json.stream !== true)
|
|
47
|
+
return undefined;
|
|
48
|
+
const options = isRecord(json.stream_options) ? json.stream_options : {};
|
|
49
|
+
if (options.include_usage === true)
|
|
50
|
+
return undefined;
|
|
51
|
+
return JSON.stringify({
|
|
52
|
+
...json,
|
|
53
|
+
stream_options: { ...options, include_usage: true },
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
// OpenAI and Gemini count cached tokens inside their input; classic takes them apart.
|
|
61
|
+
const tokensFromJson = (provider, body) => {
|
|
62
|
+
const tokens = {};
|
|
63
|
+
if (!isRecord(body))
|
|
64
|
+
return tokens;
|
|
65
|
+
if (provider === 'gemini') {
|
|
66
|
+
if (typeof body.model === 'string')
|
|
67
|
+
tokens.model = body.model;
|
|
68
|
+
const usage = isRecord(body.usageMetadata) ? body.usageMetadata : undefined;
|
|
69
|
+
if (!usage)
|
|
70
|
+
return tokens;
|
|
71
|
+
const cached = usage.cachedContentTokenCount;
|
|
72
|
+
if (isNumber(usage.promptTokenCount))
|
|
73
|
+
tokens.inputTokens =
|
|
74
|
+
usage.promptTokenCount - (isNumber(cached) ? cached : 0);
|
|
75
|
+
if (isNumber(usage.candidatesTokenCount))
|
|
76
|
+
tokens.outputTokens = usage.candidatesTokenCount;
|
|
77
|
+
if (isNumber(cached))
|
|
78
|
+
tokens.cachedReadInputTokens = cached;
|
|
79
|
+
return tokens;
|
|
80
|
+
}
|
|
81
|
+
if (provider === 'openai') {
|
|
82
|
+
const source = isRecord(body.response) ? body.response : body;
|
|
83
|
+
if (typeof source.model === 'string')
|
|
84
|
+
tokens.model = source.model;
|
|
85
|
+
const usage = isRecord(source.usage) ? source.usage : undefined;
|
|
86
|
+
if (!usage)
|
|
87
|
+
return tokens;
|
|
88
|
+
const details = (name) => isRecord(usage[name]) ? usage[name] : {};
|
|
89
|
+
const cached = details('prompt_tokens_details').cached_tokens ??
|
|
90
|
+
details('input_tokens_details').cached_tokens;
|
|
91
|
+
const input = usage.prompt_tokens ?? usage.input_tokens;
|
|
92
|
+
const output = usage.completion_tokens ?? usage.output_tokens;
|
|
93
|
+
if (isNumber(input))
|
|
94
|
+
tokens.inputTokens = input - (isNumber(cached) ? cached : 0);
|
|
95
|
+
if (isNumber(output))
|
|
96
|
+
tokens.outputTokens = output;
|
|
97
|
+
if (isNumber(cached))
|
|
98
|
+
tokens.cachedReadInputTokens = cached;
|
|
99
|
+
return tokens;
|
|
100
|
+
}
|
|
101
|
+
// A stream splits these: message_start has the input, message_delta the running output.
|
|
102
|
+
const message = isRecord(body.message) ? body.message : body;
|
|
103
|
+
if (typeof message.model === 'string')
|
|
104
|
+
tokens.model = message.model;
|
|
105
|
+
const usage = isRecord(message.usage)
|
|
106
|
+
? message.usage
|
|
107
|
+
: isRecord(body.usage)
|
|
108
|
+
? body.usage
|
|
109
|
+
: undefined;
|
|
110
|
+
if (!usage)
|
|
111
|
+
return tokens;
|
|
112
|
+
if (isNumber(usage.input_tokens))
|
|
113
|
+
tokens.inputTokens = usage.input_tokens;
|
|
114
|
+
if (isNumber(usage.output_tokens))
|
|
115
|
+
tokens.outputTokens = usage.output_tokens;
|
|
116
|
+
if (isNumber(usage.cache_read_input_tokens))
|
|
117
|
+
tokens.cachedReadInputTokens = usage.cache_read_input_tokens;
|
|
118
|
+
if (isNumber(usage.cache_creation_input_tokens))
|
|
119
|
+
tokens.cacheCreationInputTokens = usage.cache_creation_input_tokens;
|
|
120
|
+
return tokens;
|
|
121
|
+
};
|
|
122
|
+
// Later readings win: Anthropic's output is cumulative, OpenAI's usage comes last.
|
|
123
|
+
const merge = (into, next) => ({
|
|
124
|
+
model: next.model ?? into.model,
|
|
125
|
+
inputTokens: next.inputTokens ?? into.inputTokens,
|
|
126
|
+
outputTokens: next.outputTokens ?? into.outputTokens,
|
|
127
|
+
cachedReadInputTokens: next.cachedReadInputTokens ?? into.cachedReadInputTokens,
|
|
128
|
+
cacheCreationInputTokens: next.cacheCreationInputTokens ?? into.cacheCreationInputTokens,
|
|
129
|
+
});
|
|
130
|
+
const MAX_PENDING_LINE = 1024 * 1024;
|
|
131
|
+
const tokensFromStream = async (provider, stream, model) => {
|
|
132
|
+
const reader = stream.getReader();
|
|
133
|
+
const decoder = new TextDecoder();
|
|
134
|
+
let pending = '';
|
|
135
|
+
let tokens = { model };
|
|
136
|
+
const readLine = (line) => {
|
|
137
|
+
if (!line.startsWith('data:'))
|
|
138
|
+
return;
|
|
139
|
+
const payload = line.slice(5).trim();
|
|
140
|
+
if (!payload || payload === '[DONE]')
|
|
141
|
+
return;
|
|
142
|
+
try {
|
|
143
|
+
tokens = merge(tokens, tokensFromJson(provider, JSON.parse(payload)));
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// Not JSON; nothing to count.
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
try {
|
|
150
|
+
for (;;) {
|
|
151
|
+
const { done, value } = await reader.read();
|
|
152
|
+
if (done)
|
|
153
|
+
break;
|
|
154
|
+
pending += decoder.decode(value, { stream: true });
|
|
155
|
+
const lines = pending.split('\n');
|
|
156
|
+
pending = lines.pop() ?? '';
|
|
157
|
+
if (pending.length > MAX_PENDING_LINE)
|
|
158
|
+
pending = '';
|
|
159
|
+
lines.forEach(readLine);
|
|
160
|
+
}
|
|
161
|
+
readLine(pending);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
// What was read before the stream broke still counts.
|
|
165
|
+
}
|
|
166
|
+
return tokens;
|
|
167
|
+
};
|
|
168
|
+
const counted = (tokens) => tokens.inputTokens !== undefined || tokens.outputTokens !== undefined;
|
|
169
|
+
const usageOf = (provider, tokens, streaming) => counted(tokens)
|
|
170
|
+
? {
|
|
171
|
+
provider,
|
|
172
|
+
...Object.fromEntries(Object.entries(tokens).filter(([, value]) => value !== undefined)),
|
|
173
|
+
...(streaming && { isStreaming: true }),
|
|
174
|
+
}
|
|
175
|
+
: undefined;
|
|
176
|
+
/**
|
|
177
|
+
* The response to hand the app, and its usage once read; a stream is split so the app reads one copy as it arrives.
|
|
178
|
+
* `request` is what the app sent, which names Gemini's model and holds what its embeddings are estimated from.
|
|
179
|
+
*/
|
|
180
|
+
export const meterAiResponse = (provider, response, request) => {
|
|
181
|
+
const type = response.headers.get('content-type') ?? '';
|
|
182
|
+
const model = provider === 'gemini' ? geminiModelOf(request.url) : undefined;
|
|
183
|
+
if (!response.ok)
|
|
184
|
+
return { response, usage: Promise.resolve(undefined) };
|
|
185
|
+
if (provider === 'gemini' && GEMINI_EMBED_PATH.test(request.url.pathname)) {
|
|
186
|
+
return {
|
|
187
|
+
response,
|
|
188
|
+
usage: Promise.resolve(usageOf(provider, { model, inputTokens: geminiEmbedTokens(request.body) }, false)),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
if (!response.body)
|
|
192
|
+
return { response, usage: Promise.resolve(undefined) };
|
|
193
|
+
if (type.includes('text/event-stream')) {
|
|
194
|
+
const [forApp, forUs] = response.body.tee();
|
|
195
|
+
return {
|
|
196
|
+
response: new Response(forApp, response),
|
|
197
|
+
usage: tokensFromStream(provider, forUs, model).then(tokens => usageOf(provider, tokens, true)),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (!type.includes('json'))
|
|
201
|
+
return { response, usage: Promise.resolve(undefined) };
|
|
202
|
+
return {
|
|
203
|
+
response,
|
|
204
|
+
usage: response
|
|
205
|
+
.clone()
|
|
206
|
+
.json()
|
|
207
|
+
.then((json) => usageOf(provider, merge({ model }, tokensFromJson(provider, json)), false))
|
|
208
|
+
.catch(() => undefined),
|
|
209
|
+
};
|
|
210
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** How long a read is served from the cache, as classic's. */
|
|
2
|
+
export declare const AIRTABLE_READ_TTL_MS = 10000;
|
|
3
|
+
export type AirtableCache = {
|
|
4
|
+
/** A read kept across requests; a write to `table` makes it stale. */
|
|
5
|
+
read<T>(table: string, key: string, load: () => Promise<T>): Promise<T>;
|
|
6
|
+
/** A write to `table`, which makes its reads stale in every isolate the cache reaches, this request's at once. */
|
|
7
|
+
wrote(table: string): Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* One request's view of the cache for one connection. Entries are keyed by its token's hash, so only a caller holding
|
|
11
|
+
* the same token reads them, whoever shares the cache.
|
|
12
|
+
*/
|
|
13
|
+
export declare const createAirtableCache: ({ token, waitUntil, now, }: {
|
|
14
|
+
token: string;
|
|
15
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
16
|
+
now?: () => number;
|
|
17
|
+
}) => Promise<AirtableCache | undefined>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Classic keeps an Airtable read for 10 s across runs, in KV, and a write makes the table's reads stale wherever the
|
|
2
|
+
// version it bumps reaches (restly's apps/cloudflare-lambda/src/integrationCache.ts). A Start app keeps them in its
|
|
3
|
+
// Worker's own Cache API cache, per colo, on the same terms. Off Workers there is none, and each read goes to Airtable.
|
|
4
|
+
const CACHE_NAME = 'zite-airtable';
|
|
5
|
+
const ORIGIN = 'https://airtable-cache.zite.invalid';
|
|
6
|
+
/** How long a read is served from the cache, as classic's. */
|
|
7
|
+
export const AIRTABLE_READ_TTL_MS = 10_000;
|
|
8
|
+
// What the cache may keep an entry for, past which it's gone whether read or not; classic's KV minimum.
|
|
9
|
+
const HARD_TTL_S = 60;
|
|
10
|
+
const VERSION_TTL_S = 24 * 60 * 60;
|
|
11
|
+
// Classic's cap, KV's largest value.
|
|
12
|
+
const MAX_ENTRY_CHARS = 25 * 1024 * 1024;
|
|
13
|
+
const openCache = async () => {
|
|
14
|
+
const storage = globalThis.caches;
|
|
15
|
+
if (!storage?.open)
|
|
16
|
+
return undefined;
|
|
17
|
+
try {
|
|
18
|
+
return await storage.open(CACHE_NAME);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const sha256 = async (text) => [
|
|
25
|
+
...new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text))),
|
|
26
|
+
]
|
|
27
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
28
|
+
.join('');
|
|
29
|
+
/**
|
|
30
|
+
* One request's view of the cache for one connection. Entries are keyed by its token's hash, so only a caller holding
|
|
31
|
+
* the same token reads them, whoever shares the cache.
|
|
32
|
+
*/
|
|
33
|
+
export const createAirtableCache = async ({ token, waitUntil, now = () => Date.now(), }) => {
|
|
34
|
+
const cache = await openCache();
|
|
35
|
+
if (!cache)
|
|
36
|
+
return undefined;
|
|
37
|
+
const scope = (await sha256(token)).slice(0, 32);
|
|
38
|
+
// This request's writes, added to what the cache says, so a read after a write misses even before the bump lands.
|
|
39
|
+
const bumps = new Map();
|
|
40
|
+
const at = (...parts) => new Request(`${ORIGIN}/${parts.map(encodeURIComponent).join('/')}`);
|
|
41
|
+
const stored = async (table) => {
|
|
42
|
+
const held = await cache
|
|
43
|
+
.match(at('v', scope, table))
|
|
44
|
+
.catch(() => undefined);
|
|
45
|
+
return Number.parseInt((await held?.text().catch(() => '')) ?? '', 10) || 0;
|
|
46
|
+
};
|
|
47
|
+
const kept = (put) => {
|
|
48
|
+
const quiet = put.catch((error) => console.warn('[zite] Airtable cache write failed', error));
|
|
49
|
+
waitUntil?.(quiet);
|
|
50
|
+
return quiet;
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
async read(table, key, load) {
|
|
54
|
+
let entry;
|
|
55
|
+
try {
|
|
56
|
+
entry = at('r', scope, table, String((await stored(table)) + (bumps.get(table) ?? 0)), await sha256(key));
|
|
57
|
+
const held = await cache.match(entry);
|
|
58
|
+
const found = held
|
|
59
|
+
? (await held.json())
|
|
60
|
+
: undefined;
|
|
61
|
+
if (found &&
|
|
62
|
+
typeof found.at === 'number' &&
|
|
63
|
+
now() - found.at < AIRTABLE_READ_TTL_MS)
|
|
64
|
+
return found.value;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.warn('[zite] Airtable cache read failed', error);
|
|
68
|
+
}
|
|
69
|
+
const value = await load();
|
|
70
|
+
const body = entry ? JSON.stringify({ at: now(), value }) : undefined;
|
|
71
|
+
if (entry && body && body.length <= MAX_ENTRY_CHARS) {
|
|
72
|
+
void kept(cache.put(entry, new Response(body, {
|
|
73
|
+
headers: {
|
|
74
|
+
'content-type': 'application/json',
|
|
75
|
+
'cache-control': `max-age=${HARD_TTL_S}`,
|
|
76
|
+
},
|
|
77
|
+
})));
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
},
|
|
81
|
+
async wrote(table) {
|
|
82
|
+
bumps.set(table, (bumps.get(table) ?? 0) + 1);
|
|
83
|
+
const next = String((await stored(table)) + 1);
|
|
84
|
+
await kept(cache.put(at('v', scope, table), new Response(next, {
|
|
85
|
+
headers: { 'cache-control': `max-age=${VERSION_TTL_S}` },
|
|
86
|
+
})));
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { AirtableCache } from './cache.js';
|
|
1
2
|
/** As `@fillout/zite`'s `IntegrationFieldMappingType`, from zite.lock. */
|
|
2
3
|
export type AirtableFieldMapping = {
|
|
3
4
|
mapping: {
|
|
4
5
|
sdkName: string;
|
|
5
6
|
};
|
|
6
|
-
fieldType
|
|
7
|
-
fieldName
|
|
7
|
+
fieldType: string;
|
|
8
|
+
fieldName: string;
|
|
8
9
|
fieldOptions?: Record<string, unknown>;
|
|
9
10
|
};
|
|
10
11
|
export type AirtableFieldMappings = Record<string, AirtableFieldMapping>;
|
|
@@ -37,6 +38,8 @@ export type AirtableContext = {
|
|
|
37
38
|
fetch: AirtableFetch;
|
|
38
39
|
/** One request's reads, so the same read twice in a request goes to Airtable once. */
|
|
39
40
|
reads?: Map<string, Promise<unknown>>;
|
|
41
|
+
/** Reads kept across requests, as classic keeps them. */
|
|
42
|
+
cache?: AirtableCache;
|
|
40
43
|
sleep?: (ms: number) => Promise<void>;
|
|
41
44
|
};
|
|
42
45
|
/** The npm SDK's error, whose shape apps (and the goldens) see: not an `Error`. */
|