@tailor-platform/sdk 2.30.0 → 2.33.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.
Files changed (120) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/dist/ai/index.d.mts +112 -0
  3. package/dist/ai/index.mjs +2 -0
  4. package/dist/ai/index.mjs.map +1 -0
  5. package/dist/aigateway-DsWDjzk4.mjs.map +1 -1
  6. package/dist/{application-D0xNJbag.mjs → application-B9_NHiUC.mjs} +40 -32
  7. package/dist/application-B9_NHiUC.mjs.map +1 -0
  8. package/dist/application-Bet1K5C4.mjs +1 -0
  9. package/dist/assert-WeXvmG4j.mjs.map +1 -1
  10. package/dist/authconnection-CynFBIv8.mjs.map +1 -1
  11. package/dist/brand-C8nMKhJC.mjs.map +1 -1
  12. package/dist/cli/commands/deploy/staticwebsite.d.mts +1 -0
  13. package/dist/cli/lib.mjs +1 -1
  14. package/dist/cli/lib.mjs.map +1 -1
  15. package/dist/cli/main.mjs +44 -33
  16. package/dist/cli/main.mjs.map +1 -1
  17. package/dist/cli/services/resolver/service.d.mts +1 -0
  18. package/dist/cli/shared/client.d.mts +52 -1
  19. package/dist/cli/ts-hook.d.mts +0 -2
  20. package/dist/cli/ts-hook.mjs +0 -113
  21. package/dist/completion/zsh-worker.zsh +30 -6
  22. package/dist/configure/index.mjs.map +1 -1
  23. package/dist/configure/services/staticwebsite/index.d.mts +6 -1
  24. package/dist/context-D0QjfxzD.mjs.map +1 -1
  25. package/dist/crashreport-BCIy33Cz.mjs.map +1 -1
  26. package/dist/date-CgP7gMG_.mjs.map +1 -1
  27. package/dist/date-representation-Cr7W7Pn2.mjs.map +1 -1
  28. package/dist/errors-BOF68LJ5.mjs.map +1 -1
  29. package/dist/es-builtins-SfvXRVoG.mjs.map +1 -1
  30. package/dist/field-parse-C41e3UAF.mjs.map +1 -1
  31. package/dist/file-DKBOj5q4.mjs.map +1 -1
  32. package/dist/globals-BCmGX05J.mjs.map +1 -1
  33. package/dist/guards-yDXyKC9F.mjs.map +1 -1
  34. package/dist/iconv-DlFMt2gW.mjs.map +1 -1
  35. package/dist/idp-G_ojPBB5.mjs.map +1 -1
  36. package/dist/interceptor-DQg3cR_9.mjs.map +1 -1
  37. package/dist/kysely/index.mjs.map +1 -1
  38. package/dist/kysely-type-DxyIWXc6.mjs +51 -0
  39. package/dist/kysely-type-DxyIWXc6.mjs.map +1 -0
  40. package/dist/logger-DP2BjQ93.mjs.map +1 -1
  41. package/dist/logger-RgtbhJ83.mjs.map +1 -1
  42. package/dist/manager-DTRhIupk.mjs +2 -0
  43. package/dist/manager-DTRhIupk.mjs.map +1 -0
  44. package/dist/migration-steps-C6F3zNdQ.mjs.map +1 -1
  45. package/dist/multiline-EyzjEwn9.mjs.map +1 -1
  46. package/dist/node-builtins-DYfhPBnz.mjs.map +1 -1
  47. package/dist/package-json-C690ceex.mjs.map +1 -1
  48. package/dist/platform-serialize-DkiTdHOt.mjs.map +1 -1
  49. package/dist/plugin/builtin/enum-constants/index.mjs +2 -2
  50. package/dist/plugin/builtin/enum-constants/index.mjs.map +1 -1
  51. package/dist/plugin/builtin/file-utils/index.mjs.map +1 -1
  52. package/dist/plugin/builtin/kysely-type/index.mjs +1 -1
  53. package/dist/plugin/index.mjs +1 -1
  54. package/dist/plugin/index.mjs.map +1 -1
  55. package/dist/plugin/types.d.mts +3 -0
  56. package/dist/register-ts-hook-Dp9reSRG.mjs +1053 -0
  57. package/dist/register-ts-hook-Dp9reSRG.mjs.map +1 -0
  58. package/dist/registry-BijIDRVA.mjs.map +1 -1
  59. package/dist/repl-editor-DkrCZmmg.mjs +2 -0
  60. package/dist/repl-editor-DkrCZmmg.mjs.map +1 -0
  61. package/dist/schema-B6hJQWp6.mjs.map +1 -1
  62. package/dist/secret-file-C9wp_FCX.mjs.map +1 -1
  63. package/dist/secretmanager-vHQoXdQz.mjs.map +1 -1
  64. package/dist/seed/index.mjs.map +1 -1
  65. package/dist/seed-Cn-3JApy.mjs.map +1 -1
  66. package/dist/service-9SBPNpK8.mjs.map +1 -1
  67. package/dist/service-9rwi_I4d.mjs.map +1 -1
  68. package/dist/service_pb-6EkMfdOb.mjs +2 -0
  69. package/dist/service_pb-6EkMfdOb.mjs.map +1 -0
  70. package/dist/service_pb-CsJKokDl.mjs +1 -0
  71. package/dist/tailor-proto/src/tailor/v1/metadata_pb.d.mts +5 -2
  72. package/dist/tailor-proto/src/tailor/v1/security_pb.d.mts +213 -0
  73. package/dist/tailor-proto/src/tailor/v1/security_resource_pb.d.mts +301 -0
  74. package/dist/tailor-proto/src/tailor/v1/service_pb.d.mts +200 -8
  75. package/dist/tailor-proto/src/tailor/v1/staticwebsite_pb.d.mts +201 -1
  76. package/dist/tailor-proto/src/tailor/v1/staticwebsite_resource_pb.d.mts +88 -1
  77. package/dist/telemetry-DfT2UfI4.mjs +2 -0
  78. package/dist/telemetry-DfT2UfI4.mjs.map +1 -0
  79. package/dist/{telemetry-DpkFGBmu.mjs → telemetry-nqOtDWNO.mjs} +1 -1
  80. package/dist/type-source--ZNcV8RJ.mjs.map +1 -1
  81. package/dist/types/staticwebsite.generated.d.mts +9 -1
  82. package/dist/user-agent-vdHYF3QL.mjs.map +1 -1
  83. package/dist/utils/test/index.mjs.map +1 -1
  84. package/dist/vitest/environment.mjs.map +1 -1
  85. package/dist/vitest/index.d.mts +2 -2
  86. package/dist/vitest/index.mjs +1 -1
  87. package/dist/vitest/index.mjs.map +1 -1
  88. package/dist/vitest/pglite-kysely.d.mts +19 -0
  89. package/dist/vitest/setup.mjs.map +1 -1
  90. package/dist/wait-point-invoker-eiP-IIux.mjs.map +1 -1
  91. package/dist/wait-point-registry-B-ESkTZX.mjs.map +1 -1
  92. package/dist/workflow-Cs9ISw6j.mjs.map +1 -1
  93. package/dist/{workspace_resource_pb-CaoM2npP.mjs → workspace_resource_pb-C4CkoYww.mjs} +2 -2
  94. package/dist/workspace_resource_pb-C4CkoYww.mjs.map +1 -0
  95. package/docs/ai.md +92 -0
  96. package/docs/cli/tailordb.md +17 -15
  97. package/docs/cli/workspace.md +1 -1
  98. package/docs/github-actions.md +98 -11
  99. package/docs/plugin/custom.md +34 -0
  100. package/docs/plugin/index.md +1 -0
  101. package/docs/services/staticwebsite.md +31 -1
  102. package/docs/services/tailordb/migration.md +78 -41
  103. package/docs/testing.md +2 -1
  104. package/package.json +20 -13
  105. package/dist/application-C2bPmmbh.mjs +0 -1
  106. package/dist/application-D0xNJbag.mjs.map +0 -1
  107. package/dist/kysely-type-BWMfV301.mjs +0 -48
  108. package/dist/kysely-type-BWMfV301.mjs.map +0 -1
  109. package/dist/manager-Bk-7vkwd.mjs +0 -2
  110. package/dist/manager-Bk-7vkwd.mjs.map +0 -1
  111. package/dist/register-ts-hook-CDnN_Jx2.mjs +0 -1012
  112. package/dist/register-ts-hook-CDnN_Jx2.mjs.map +0 -1
  113. package/dist/repl-editor-DGJBfIt1.mjs +0 -2
  114. package/dist/repl-editor-DGJBfIt1.mjs.map +0 -1
  115. package/dist/service_pb-Bbu2QSIr.mjs +0 -2
  116. package/dist/service_pb-Bbu2QSIr.mjs.map +0 -1
  117. package/dist/service_pb-urxAIYHT.mjs +0 -1
  118. package/dist/telemetry-Xk7J829P.mjs +0 -2
  119. package/dist/telemetry-Xk7J829P.mjs.map +0 -1
  120. package/dist/workspace_resource_pb-CaoM2npP.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,97 @@
1
1
  # @tailor-platform/sdk
2
2
 
3
+ ## 2.33.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2742](https://github.com/tailor-platform/sdk/pull/2742) [`4f3f30c`](https://github.com/tailor-platform/sdk/commit/4f3f30c4b7a305d654a1b8ad9cb709f7effe75ec) Thanks [@mocchira](https://github.com/mocchira)! - `customDomains` entries can now name a destination, moving a domain to another static website — in the same workspace or a different one — without downtime, a new certificate, or a DNS change:
8
+
9
+ ```typescript
10
+ defineStaticWebSite("my-website", {
11
+ customDomains: [{ domain: "app.example.com", transferTo: { workspaceId: "..." } }],
12
+ });
13
+ ```
14
+
15
+ Deploying opens the offer; the receiving side accepts it by listing the domain normally and deploying. `tailor deploy` reports an open offer and says when the domain has moved and the entry can be deleted.
16
+
17
+ While an offer is open, `tailor deploy` and `tailor remove` refuse to remove the domain or the static website holding it, at plan time and before anything is applied. A plan also fails, rather than quietly doing nothing, when an entry names a domain the site does not hold and no transfer from this workspace accounts for it, or when the domain is still being removed.
18
+
19
+ `tailor deploy` also now takes ownership of a custom domain that already exists but carries no SDK labels, instead of trying to add it again — the recovery path when a previous deploy lost the response, or when the domain was added through the API or console.
20
+
21
+ - [#2591](https://github.com/tailor-platform/sdk/pull/2591) [`59fcb9a`](https://github.com/tailor-platform/sdk/commit/59fcb9a356455494bdbc0068d59ae4daa4de1582) Thanks [@toiroakr](https://github.com/toiroakr)! - Let a TailorDB migration script that exports `steps` roll back instead of staying in progress when a step fails. Export `onFailure = "rollback"` next to `steps` and `tailor deploy` restores the pre-migration schema, clears the in-progress record, and takes the tables out of maintenance mode. The deploy then fails with the step's error under the code `MIGRATION_ROLLED_BACK`, and the next deploy runs every step again from the beginning. Nothing is rolled back while the run may still be executing, or when the in-progress record cannot be cleared. If some tables cannot be rolled back, the deploy warns which tables need manual repair. Without `onFailure`, or with `"resume"`, a failed run stays in progress as before
22
+
23
+ - [#2700](https://github.com/tailor-platform/sdk/pull/2700) [`6eb2033`](https://github.com/tailor-platform/sdk/commit/6eb203365aa0aedf6619b63f192aac948e2e0876) Thanks [@toiroakr](https://github.com/toiroakr)! - The `db.pglite.ts` that `tailor tailordb migration generate` writes now enforces relations: a row pointing at a parent that does not exist is rejected, as on the platform. Migration tests that stage a row whose parent is missing must create the parent first or stage the row with `prepareFixtures`. A relation the pre-migration schema cannot satisfy is left unenforced: one whose pending type change leaves the field a different type from its target, or one the migration retargets.
24
+
25
+ `prepareFixtures` from `@tailor-platform/sdk/vitest` writes a test's starting records with relations unchecked, so a migration test can stage rows that predate a relation, and checks them again before the script runs. The migration PGlite test scaffold uses it.
26
+
27
+ ### Patch Changes
28
+
29
+ - [#2741](https://github.com/tailor-platform/sdk/pull/2741) [`6f6ca9f`](https://github.com/tailor-platform/sdk/commit/6f6ca9fb72255f4124c04933af012ef6d7170380) Thanks [@mocchira](https://github.com/mocchira)! - `tailor staticwebsite domain list` and `domain get` now report a domain being removed as `removing` instead of `unknown`, and `tailor api` can inspect and call the custom domain transfer endpoints (`RequestCustomDomainTransfer`, `CancelCustomDomainTransfer`, `AcceptCustomDomainTransfer`, `GetCustomDomainTransfer`, `ListCustomDomainTransfers`).
30
+
31
+ - [#2736](https://github.com/tailor-platform/sdk/pull/2736) [`8595d14`](https://github.com/tailor-platform/sdk/commit/8595d14c76d8ce364448f321ad430c01582d910f) Thanks [@toiroakr](https://github.com/toiroakr)! - `tailor login` now shows an HTML page in the browser after authentication instead of raw JSON, telling you to close the tab and return to the terminal. The page follows the system light/dark theme. A failed login shows the reason in the page as well, and `tailor authconnection authorize` shows the same pages on success and failure.
32
+
33
+ - [#2740](https://github.com/tailor-platform/sdk/pull/2740) [`ef844ff`](https://github.com/tailor-platform/sdk/commit/ef844ffc39a84a39e02818eec9f6a08188ce2ccb) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update dependency @​napi-rs/keyring to v2.1.2
34
+
35
+ - [#2760](https://github.com/tailor-platform/sdk/pull/2760) [`a7d1cb8`](https://github.com/tailor-platform/sdk/commit/a7d1cb8ce6dbc324f57ff2704f5ffe92af5bf963) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update @​inquirer
36
+
37
+ - [#2766](https://github.com/tailor-platform/sdk/pull/2766) [`15b6f4a`](https://github.com/tailor-platform/sdk/commit/15b6f4a7a9b6c0c2dd6514c6a5a7ca73a4870000) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update dependency pkg-types to v2.4.0
38
+
39
+ - [#2718](https://github.com/tailor-platform/sdk/pull/2718) [`8927563`](https://github.com/tailor-platform/sdk/commit/89275638f7732fd69015e4b70ad8101b55b22649) Thanks [@toiroakr](https://github.com/toiroakr)! - The `tailor query` REPL now highlights SQL block comments (`/* ... */`) and GraphQL block strings (`"""..."""`) that span multiple lines, and also colours SQL `--` comments and trailing GraphQL `#` comments.
40
+
41
+ - [#2731](https://github.com/tailor-platform/sdk/pull/2731) [`bbfb9b1`](https://github.com/tailor-platform/sdk/commit/bbfb9b1e9918cb59fdbc6865c6eb81bc3136aecd) Thanks [@dqn](https://github.com/dqn)! - Fix plugin-generated resolvers being silently ignored. Resolver output from table and namespace hooks is now loaded, bundled, and deployed to the resolver namespace with the same name as the hook's TailorDB namespace. The two are separate namespaces that only share the name; the resolver namespace is created automatically when it is not configured, and its settings apply when it is. Resolvers that your existing plugins already return are deployed on the next `deploy`; without `defaultPermission` on their resolver namespace, anonymous callers can reach them.
42
+
43
+ - [#2747](https://github.com/tailor-platform/sdk/pull/2747) [`d52ec40`](https://github.com/tailor-platform/sdk/commit/d52ec402c9cc295eb94e69ee45b6f87e888badfa) Thanks [@dqn](https://github.com/dqn)! - Internal refactoring: remove the unused asynchronous variants of the SDK's internal TypeScript loader hooks. Loading `.ts` config and resource files is unchanged.
44
+
45
+ - [#2744](https://github.com/tailor-platform/sdk/pull/2744) [`559d442`](https://github.com/tailor-platform/sdk/commit/559d442b7ab19d900ccfd5b84694b88490ae62e2) Thanks [@dqn](https://github.com/dqn)! - Reject duplicate generated enum constant names instead of silently overwriting definitions. Duplicates with identical values, which previously generated successfully, now fail too. Rename conflicting tables or fields to give their enum constants unique names.
46
+
47
+ ## 2.32.0
48
+
49
+ ### Minor Changes
50
+
51
+ - [#2697](https://github.com/tailor-platform/sdk/pull/2697) [`8706209`](https://github.com/tailor-platform/sdk/commit/870620945d19e068add0092c01c2bbbb68c2061b) Thanks [@dqn](https://github.com/dqn)! - Add a provider-independent System One client for boolean, choice, and ordered score decisions through AI Gateway.
52
+
53
+ - [#2727](https://github.com/tailor-platform/sdk/pull/2727) [`cc8a577`](https://github.com/tailor-platform/sdk/commit/cc8a5777314ac9daaf32b9659b182d1585f5a173) Thanks [@toiroakr](https://github.com/toiroakr)! - `tailordb migration test` now records a 24-hour expiry on every temporary workspace it creates, right after creating it. If the run is interrupted (for example, a cancelled CI job), the workspace stays and `tailor workspace prune --expired` deletes it once the expiry has passed. A workspace given with `--target-workspace-id` gets no expiry, and `--keep` without `--keep-ttl` still records none.
54
+
55
+ - [#2696](https://github.com/tailor-platform/sdk/pull/2696) [`dc605c2`](https://github.com/tailor-platform/sdk/commit/dc605c207e6af179dc000b747def7f41fefedc66) Thanks [@toiroakr](https://github.com/toiroakr)! - `kyselyTypePlugin`'s `pgliteSchemaPath` script now enforces relations: a row pointing at a parent that does not exist is rejected, as on the platform. Tests that insert child rows before their parents must create the parents first.
56
+
57
+ A relation to a field other than `id` that is not unique, or whose type differs from the referencing field, fails generation, as the platform rejects it on deploy.
58
+
59
+ ### Patch Changes
60
+
61
+ - [#2725](https://github.com/tailor-platform/sdk/pull/2725) [`c85d2d8`](https://github.com/tailor-platform/sdk/commit/c85d2d8f27be5a02117f1d6197390b159b36df15) Thanks [@dqn](https://github.com/dqn)! - Fix migration detection and Pre-phase relaxation for nested required and enum constraints, and reject unsupported nested shape changes and rename combinations.
62
+
63
+ - [#2724](https://github.com/tailor-platform/sdk/pull/2724) [`6152316`](https://github.com/tailor-platform/sdk/commit/615231674d129ca888b5c8be599b1f54bdea4fdc) Thanks [@dqn](https://github.com/dqn)! - `tailor deploy` and `tailor remove` no longer fail when deleting an IdP client whose Secret Manager vault (`idp-<namespace>-<client>`) has already been deleted.
64
+
65
+ - [`127454d`](https://github.com/tailor-platform/sdk/commit/127454d6cd9d4fe20ccc3504f44430650874df71) Thanks [@haru0017](https://github.com/haru0017)! - Re-apply rolldown 1.2.14
66
+
67
+ rolldown's output was fine; the crash came from another platform dependency, which has been fixed, so the temporary downgrade to 1.2.13 is no longer needed.
68
+
69
+ - [#2685](https://github.com/tailor-platform/sdk/pull/2685) [`3b21d1c`](https://github.com/tailor-platform/sdk/commit/3b21d1c36e8eaa282374b9e9601e95537ac00377) Thanks [@dqn](https://github.com/dqn)! - Split how `tailor deploy` applies TailorDB changes and migrations into smaller steps. No observable behavior change.
70
+
71
+ - [#2707](https://github.com/tailor-platform/sdk/pull/2707) [`ab7cb70`](https://github.com/tailor-platform/sdk/commit/ab7cb704ece975c7e3b7a2868ec71077643e26ac) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update dependency kysely to v0.29.7
72
+
73
+ - [#2716](https://github.com/tailor-platform/sdk/pull/2716) [`698343b`](https://github.com/tailor-platform/sdk/commit/698343bbcc0fedfa790e2a3e085423f19b0e608c) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update dependency execa to v10.2.0
74
+
75
+ - [#2726](https://github.com/tailor-platform/sdk/pull/2726) [`bfea8a3`](https://github.com/tailor-platform/sdk/commit/bfea8a3c5653017fc9b798e30e674b0e0a4f9859) Thanks [@dqn](https://github.com/dqn)! - Fix migration templates to replace removed enum values within array fields while preserving other elements.
76
+
77
+ ## 2.31.1
78
+
79
+ ### Patch Changes
80
+
81
+ - [#2714](https://github.com/tailor-platform/sdk/pull/2714) [`5db635d`](https://github.com/tailor-platform/sdk/commit/5db635dad2db0e333a94998c59b83ecffe696506) Thanks [@dragon3](https://github.com/dragon3)! - List `europe-west` in the workspace regions shown by `tailor workspace create --help`, matching the regions the Platform now offers for workspace creation (`asia-northeast, us-west, europe-west`).
82
+
83
+ ## 2.31.0
84
+
85
+ ### Minor Changes
86
+
87
+ - [#2563](https://github.com/tailor-platform/sdk/pull/2563) [`8fdb4e8`](https://github.com/tailor-platform/sdk/commit/8fdb4e81d1dd362f0ad1ad5608885d9df5c9651c) Thanks [@toiroakr](https://github.com/toiroakr)! - `tailor tailordb migration test` now accepts `--organization-id` and `--folder-id` to choose where the temporary workspace is created. With only `--organization-id` it is created at that organization's root; with `--folder-id` it is created in that folder, and the command fails before creating anything if the folder is not found in the organization (`--folder-id` alone also fails when the source workspace is not in an organization, so pass `--organization-id` with it). Without either option it still follows the source workspace's organization and folder. With `--target-workspace-id`, the given organization and folder must match the ones the target workspace is already in; otherwise the command fails and names the mismatch.
88
+
89
+ ### Patch Changes
90
+
91
+ - [#2705](https://github.com/tailor-platform/sdk/pull/2705) [`d579565`](https://github.com/tailor-platform/sdk/commit/d579565ff260258c0fa96b331204160539d28500) Thanks [@toiroakr](https://github.com/toiroakr)! - `tailor deploy` no longer reads an IdP client's `clientSecret` from the list response. When a deploy forced by an SDK version change finds that an IdP client's secret vault is missing, it now fetches the client with `getIdPClient` and creates the secret from that value. This keeps the deploy working when the platform stops returning `clientSecret` from the list API.
92
+
93
+ - [#2715](https://github.com/tailor-platform/sdk/pull/2715) [`6b9b5b2`](https://github.com/tailor-platform/sdk/commit/6b9b5b290ed7aae3a606263223d7863155fc61a5) Thanks [@toiroakr](https://github.com/toiroakr)! - Replace the `@opentelemetry/sdk-trace-node` dependency with `@opentelemetry/sdk-trace` for CLI telemetry.
94
+
3
95
  ## 2.30.0
4
96
 
5
97
  ### Minor Changes
@@ -0,0 +1,112 @@
1
+ //#region src/ai/index.d.ts
2
+ /**
3
+ * Client for semantic decisions through Tailor AI Gateway.
4
+ *
5
+ * @example
6
+ * import { createSystemOne } from "@tailor-platform/sdk/ai";
7
+ *
8
+ * const systemOne = createSystemOne({
9
+ * baseURL: "https://my-aigateway.example.com",
10
+ * token: accessToken,
11
+ * });
12
+ *
13
+ * const decision = await systemOne.choice({
14
+ * state: { subject: "Charged twice" },
15
+ * question: "Which department should handle this ticket?",
16
+ * choices: ["billing", "sales", "support"],
17
+ * });
18
+ */
19
+ /** Error codes returned for System One decisions. */
20
+ export type SystemOneErrorCode = "INVALID_REQUEST" | "INVALID_ANSWER_SPACE" | "UNAUTHORIZED" | "PROVIDER_UNAVAILABLE" | "PROVIDER_TIMEOUT" | "RATE_LIMITED" | "MODEL_ERROR";
21
+ /** Error returned when a System One decision cannot be completed. */
22
+ export declare class SystemOneError extends Error {
23
+ /** Stable, provider-independent error code. */
24
+ readonly code: SystemOneErrorCode;
25
+ /** HTTP status returned by AI Gateway, when available. */
26
+ readonly status?: number;
27
+ /**
28
+ * Create a System One error.
29
+ * @param message - Human-readable error message
30
+ * @param code - Stable error code
31
+ * @param options - Additional error details
32
+ */
33
+ constructor(message: string, code: SystemOneErrorCode, options?: ErrorOptions & {
34
+ status?: number;
35
+ });
36
+ }
37
+ /** Options used to connect a System One client to Tailor AI Gateway. */
38
+ export interface CreateSystemOneOptions {
39
+ /** AI Gateway base URL. */
40
+ baseURL: string | URL;
41
+ /** Access token issued by the AI Gateway's auth namespace. Omit this inside a Tailor Function. */
42
+ token?: string | (() => string | Promise<string>);
43
+ /** Milliseconds, as a non-negative integer, to wait for AI Gateway to respond before failing with `PROVIDER_TIMEOUT`. Omit to wait until AI Gateway responds. */
44
+ timeoutMs?: number;
45
+ /** Custom Fetch implementation. */
46
+ fetch?: typeof globalThis.fetch;
47
+ }
48
+ /** Common input shared by all System One decisions. */
49
+ export interface SystemOneInput {
50
+ /** Data used to make the decision: a JSON object, array, string, or `null`. */
51
+ state: unknown;
52
+ /** Natural-language question to answer. */
53
+ question: string;
54
+ /** Decision model. Defaults to `jev-1.13.0`. */
55
+ model?: string;
56
+ }
57
+ /** Input for a choice decision. */
58
+ export interface ChoiceInput<Choices extends readonly [string, ...string[]]> extends SystemOneInput {
59
+ /** Allowed answers. Each value must be unique. */
60
+ choices: Choices;
61
+ }
62
+ /** Result of a choice or score decision. */
63
+ export interface ChoiceResult<Value extends string> {
64
+ /** Selected answer. */
65
+ value: Value;
66
+ /** Probability for every allowed answer. */
67
+ probabilities: Record<Value, number>;
68
+ /** Provider-reported confidence in the selected answer. */
69
+ confidence: number;
70
+ }
71
+ /** Input for a boolean decision. */
72
+ export type BooleanInput = SystemOneInput;
73
+ /** Result of a boolean decision. */
74
+ export interface BooleanResult {
75
+ /** `true` when the probability of "yes" is at least 0.5. */
76
+ value: boolean;
77
+ /** Probability assigned to the selected answer. */
78
+ probability: number;
79
+ }
80
+ /** Input for an ordered score decision. */
81
+ export interface ScoreInput<Levels extends readonly [string, string, ...string[]]> extends SystemOneInput {
82
+ /** Ordered score levels, from lowest to highest. Each level must be unique. */
83
+ levels: Levels;
84
+ }
85
+ /** System One semantic decision client. */
86
+ export interface SystemOneClient {
87
+ /**
88
+ * Select one value from an answer space.
89
+ * @param input - State, question, and allowed choices
90
+ * @returns The selected value and its probability distribution
91
+ */
92
+ choice<const Choices extends readonly [string, ...string[]]>(input: ChoiceInput<Choices>): Promise<ChoiceResult<Choices[number]>>;
93
+ /**
94
+ * Answer a binary question.
95
+ * @param input - State and question
96
+ * @returns The boolean answer and its probability
97
+ */
98
+ boolean(input: BooleanInput): Promise<BooleanResult>;
99
+ /**
100
+ * Select one value from an ordered answer space. The level with the highest probability is selected.
101
+ * @param input - State, question, and ordered score levels
102
+ * @returns The selected level and its probability distribution
103
+ */
104
+ score<const Levels extends readonly [string, string, ...string[]]>(input: ScoreInput<Levels>): Promise<ChoiceResult<Levels[number]>>;
105
+ }
106
+ /**
107
+ * Create a System One client that makes decisions through Tailor AI Gateway.
108
+ * @param options - AI Gateway connection options
109
+ * @returns A semantic decision client
110
+ */
111
+ export declare function createSystemOne(options: CreateSystemOneOptions): SystemOneClient;
112
+ //#endregion
@@ -0,0 +1,2 @@
1
+ var SystemOneError=class extends Error{code;status;constructor(e,t,n={}){super(e,n),this.name=`SystemOneError`,this.code=t,this.status=n.status}};function endpoint(e){return`${String(e).replace(/\/+$/,``)}/v1/systemone`}async function resolveToken(e){return typeof e==`function`?e():e}function asObject(e){return typeof e==`object`&&e?e:void 0}function isProbability(e){return typeof e==`number`&&Number.isFinite(e)&&e>=0&&e<=1}function invalidResponse(e){return new SystemOneError(e,`MODEL_ERROR`)}function assertUniqueAnswers(e){if(new Set(e).size!==e.length)throw new SystemOneError(`System One answer values must be unique.`,`INVALID_ANSWER_SPACE`)}function invalidState(e){return new SystemOneError(`System One state must be a JSON object, array, string, or null.`,`INVALID_REQUEST`,e)}function toDecisionState(e){let t;try{let n=JSON.stringify(e);t=n===void 0?void 0:JSON.parse(n)}catch(e){throw invalidState({cause:e})}if(typeof t!=`string`&&typeof t!=`object`)throw invalidState();return t}function errorCode(e){return e===401||e===403?`UNAUTHORIZED`:e===408||e===504?`PROVIDER_TIMEOUT`:e===429?`RATE_LIMITED`:e>=500?`PROVIDER_UNAVAILABLE`:e>=400?`INVALID_REQUEST`:`MODEL_ERROR`}function errorMessage(e){if(typeof e==`string`)return e.trim()||void 0;let t=asObject(e),n=asObject(t?.error)?.message;if(typeof n==`string`)return n;if(typeof t?.message==`string`)return t.message;if(typeof t?.detail==`string`)return t.detail;if(Array.isArray(t?.detail)){let e=t.detail.map(e=>asObject(e)?.msg).filter(e=>typeof e==`string`);return e.length>0?e.join(`; `):void 0}}async function readErrorMessage(e){let t=await e.text().catch(()=>``);try{return errorMessage(JSON.parse(t))}catch{return errorMessage(t)}}function isTimeout(e){return e instanceof Error&&e.name===`TimeoutError`}function timeoutError(e,t){return new SystemOneError(`AI Gateway request timed out.`,`PROVIDER_TIMEOUT`,{cause:e,status:t})}async function readJSON(e){try{return await e.json()}catch(t){throw isTimeout(t)?timeoutError(t,e.status):new SystemOneError(`AI Gateway returned an invalid JSON response.`,`MODEL_ERROR`,{cause:t,status:e.status})}}async function evaluate(e,t,n){let r=JSON.stringify({model:t.model??`jev-1.13.0`,state:toDecisionState(t.state),questions:{decision:n}}),i=await resolveToken(e.token),a=new Headers({"content-type":`application/json`});i&&a.set(`authorization`,`Bearer ${i}`);let o=e.fetch??globalThis.fetch,s=e.timeoutMs===void 0?void 0:AbortSignal.timeout(e.timeoutMs),c;try{c=await o(endpoint(e.baseURL),{method:`POST`,headers:a,body:r,signal:s})}catch(e){throw isTimeout(e)?timeoutError(e):new SystemOneError(`Unable to reach AI Gateway.`,`PROVIDER_UNAVAILABLE`,{cause:e})}if(!c.ok)throw new SystemOneError(await readErrorMessage(c)??`System One decision request failed.`,errorCode(c.status),{status:c.status});let l=asObject(asObject(asObject(await readJSON(c))?.answers)?.decision);if(l?.type!==n.type)throw invalidResponse(`AI Gateway response did not contain a decision answer.`);return l}function parseChoiceAnswer(e,t){if(typeof e.choice!=`string`||!t.includes(e.choice))throw invalidResponse(`System One returned a value outside the requested answer space.`);let n=asObject(e.probabilities);if(!n)throw invalidResponse(`System One returned an invalid probability distribution.`);let r=Object.fromEntries(t.map(e=>{let t=n[e];if(!isProbability(t))throw invalidResponse(`System One returned an invalid probability for "${e}".`);return[e,t]}));if(!isProbability(e.confidence))throw invalidResponse(`System One returned an invalid confidence value.`);return{value:e.choice,probabilities:r,confidence:e.confidence}}function parseBooleanAnswer(e){if(!isProbability(e.noul))throw invalidResponse(`System One returned an invalid probability.`);let t=e.noul>=.5;return{value:t,probability:t?e.noul:1-e.noul}}function parseScoreAnswer(e,t){let n=asObject(e.probabilities);if(!n)throw invalidResponse(`System One returned an invalid probability distribution.`);let r=t.map((e,t)=>{let r=n[String(t)];if(!isProbability(r))throw invalidResponse(`System One returned an invalid probability for "${e}".`);return{level:e,probability:r}});if(!isProbability(e.confidence))throw invalidResponse(`System One returned an invalid confidence value.`);return{value:r.reduce((e,t)=>t.probability>e.probability?t:e).level,probabilities:Object.fromEntries(r.map(({level:e,probability:t})=>[e,t])),confidence:e.confidence}}function createSystemOne(e){return{choice:async t=>(assertUniqueAnswers(t.choices),parseChoiceAnswer(await evaluate(e,t,{type:`choice`,instructions:t.question,criteria:Object.fromEntries(t.choices.map(e=>[e,null]))}),t.choices)),boolean:async t=>parseBooleanAnswer(await evaluate(e,t,{type:`noul`,instructions:t.question})),score:async t=>(assertUniqueAnswers(t.levels),parseScoreAnswer(await evaluate(e,t,{type:`score`,instructions:t.question,criteria:t.levels}),t.levels))}}export{SystemOneError,createSystemOne};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["message","options","code","baseURL","token","value","values","serialized","state","cause","status","payload","root","nested","messages","detail","text","response","body","input","question","headers","fetchImplementation","signal","answer","choices","rawProbabilities","probabilities","probability","choice","scores","levels","index","level","score","selected"],"sources":["../../src/ai/index.ts"],"sourcesContent":["/**\n * Client for semantic decisions through Tailor AI Gateway.\n *\n * @example\n * import { createSystemOne } from \"@tailor-platform/sdk/ai\";\n *\n * const systemOne = createSystemOne({\n * baseURL: \"https://my-aigateway.example.com\",\n * token: accessToken,\n * });\n *\n * const decision = await systemOne.choice({\n * state: { subject: \"Charged twice\" },\n * question: \"Which department should handle this ticket?\",\n * choices: [\"billing\", \"sales\", \"support\"],\n * });\n */\n\n/** Error codes returned for System One decisions. */\nexport type SystemOneErrorCode =\n | \"INVALID_REQUEST\"\n | \"INVALID_ANSWER_SPACE\"\n | \"UNAUTHORIZED\"\n | \"PROVIDER_UNAVAILABLE\"\n | \"PROVIDER_TIMEOUT\"\n | \"RATE_LIMITED\"\n | \"MODEL_ERROR\";\n\n/** Error returned when a System One decision cannot be completed. */\nexport class SystemOneError extends Error {\n /** Stable, provider-independent error code. */\n readonly code: SystemOneErrorCode;\n\n /** HTTP status returned by AI Gateway, when available. */\n readonly status?: number;\n\n /**\n * Create a System One error.\n * @param message - Human-readable error message\n * @param code - Stable error code\n * @param options - Additional error details\n */\n constructor(\n message: string,\n code: SystemOneErrorCode,\n options: ErrorOptions & { status?: number } = {},\n ) {\n super(message, options);\n this.name = \"SystemOneError\";\n this.code = code;\n this.status = options.status;\n }\n}\n\n/** Options used to connect a System One client to Tailor AI Gateway. */\nexport interface CreateSystemOneOptions {\n /** AI Gateway base URL. */\n baseURL: string | URL;\n /** Access token issued by the AI Gateway's auth namespace. Omit this inside a Tailor Function. */\n token?: string | (() => string | Promise<string>);\n /** Milliseconds, as a non-negative integer, to wait for AI Gateway to respond before failing with `PROVIDER_TIMEOUT`. Omit to wait until AI Gateway responds. */\n timeoutMs?: number;\n /** Custom Fetch implementation. */\n fetch?: typeof globalThis.fetch;\n}\n\n/** Common input shared by all System One decisions. */\nexport interface SystemOneInput {\n /** Data used to make the decision: a JSON object, array, string, or `null`. */\n state: unknown;\n /** Natural-language question to answer. */\n question: string;\n /** Decision model. Defaults to `jev-1.13.0`. */\n model?: string;\n}\n\n/** Input for a choice decision. */\nexport interface ChoiceInput<\n Choices extends readonly [string, ...string[]],\n> extends SystemOneInput {\n /** Allowed answers. Each value must be unique. */\n choices: Choices;\n}\n\n/** Result of a choice or score decision. */\nexport interface ChoiceResult<Value extends string> {\n /** Selected answer. */\n value: Value;\n /** Probability for every allowed answer. */\n probabilities: Record<Value, number>;\n /** Provider-reported confidence in the selected answer. */\n confidence: number;\n}\n\n/** Input for a boolean decision. */\nexport type BooleanInput = SystemOneInput;\n\n/** Result of a boolean decision. */\nexport interface BooleanResult {\n /** `true` when the probability of \"yes\" is at least 0.5. */\n value: boolean;\n /** Probability assigned to the selected answer. */\n probability: number;\n}\n\n/** Input for an ordered score decision. */\nexport interface ScoreInput<\n Levels extends readonly [string, string, ...string[]],\n> extends SystemOneInput {\n /** Ordered score levels, from lowest to highest. Each level must be unique. */\n levels: Levels;\n}\n\n/** System One semantic decision client. */\nexport interface SystemOneClient {\n /**\n * Select one value from an answer space.\n * @param input - State, question, and allowed choices\n * @returns The selected value and its probability distribution\n */\n choice<const Choices extends readonly [string, ...string[]]>(\n input: ChoiceInput<Choices>,\n ): Promise<ChoiceResult<Choices[number]>>;\n\n /**\n * Answer a binary question.\n * @param input - State and question\n * @returns The boolean answer and its probability\n */\n boolean(input: BooleanInput): Promise<BooleanResult>;\n\n /**\n * Select one value from an ordered answer space. The level with the highest probability is selected.\n * @param input - State, question, and ordered score levels\n * @returns The selected level and its probability distribution\n */\n score<const Levels extends readonly [string, string, ...string[]]>(\n input: ScoreInput<Levels>,\n ): Promise<ChoiceResult<Levels[number]>>;\n}\n\ntype DecisionQuestion =\n | { type: \"noul\"; instructions: string }\n | { type: \"choice\"; instructions: string; criteria: Record<string, null> }\n | { type: \"score\"; instructions: string; criteria: readonly string[] };\n\ntype DecisionAnswer = Record<string, unknown>;\n\nconst defaultModel = \"jev-1.13.0\";\n\nfunction endpoint(baseURL: string | URL): string {\n return `${String(baseURL).replace(/\\/+$/, \"\")}/v1/systemone`;\n}\n\nasync function resolveToken(token: CreateSystemOneOptions[\"token\"]): Promise<string | undefined> {\n return typeof token === \"function\" ? token() : token;\n}\n\nfunction asObject(value: unknown): Record<string, unknown> | undefined {\n return typeof value === \"object\" && value !== null\n ? (value as Record<string, unknown>)\n : undefined;\n}\n\nfunction isProbability(value: unknown): value is number {\n return typeof value === \"number\" && Number.isFinite(value) && value >= 0 && value <= 1;\n}\n\nfunction invalidResponse(message: string): SystemOneError {\n return new SystemOneError(message, \"MODEL_ERROR\");\n}\n\nfunction assertUniqueAnswers(values: readonly string[]): void {\n if (new Set(values).size !== values.length) {\n throw new SystemOneError(\"System One answer values must be unique.\", \"INVALID_ANSWER_SPACE\");\n }\n}\n\nfunction invalidState(options?: ErrorOptions): SystemOneError {\n return new SystemOneError(\n \"System One state must be a JSON object, array, string, or null.\",\n \"INVALID_REQUEST\",\n options,\n );\n}\n\nfunction toDecisionState(state: unknown): unknown {\n let value: unknown;\n try {\n const serialized = JSON.stringify(state) as string | undefined;\n value = serialized === undefined ? undefined : JSON.parse(serialized);\n } catch (cause) {\n throw invalidState({ cause });\n }\n if (typeof value !== \"string\" && typeof value !== \"object\") {\n throw invalidState();\n }\n return value;\n}\n\nfunction errorCode(status: number): SystemOneErrorCode {\n if (status === 401 || status === 403) {\n return \"UNAUTHORIZED\";\n }\n if (status === 408 || status === 504) {\n return \"PROVIDER_TIMEOUT\";\n }\n if (status === 429) {\n return \"RATE_LIMITED\";\n }\n if (status >= 500) {\n return \"PROVIDER_UNAVAILABLE\";\n }\n if (status >= 400) {\n return \"INVALID_REQUEST\";\n }\n return \"MODEL_ERROR\";\n}\n\nfunction errorMessage(payload: unknown): string | undefined {\n if (typeof payload === \"string\") {\n return payload.trim() || undefined;\n }\n const root = asObject(payload);\n const nested = asObject(root?.error)?.message;\n if (typeof nested === \"string\") {\n return nested;\n }\n if (typeof root?.message === \"string\") {\n return root.message;\n }\n if (typeof root?.detail === \"string\") {\n return root.detail;\n }\n if (Array.isArray(root?.detail)) {\n const messages = root.detail\n .map((detail) => asObject(detail)?.msg)\n .filter((message) => typeof message === \"string\");\n return messages.length > 0 ? messages.join(\"; \") : undefined;\n }\n return undefined;\n}\n\nasync function readErrorMessage(response: Response): Promise<string | undefined> {\n const text = await response.text().catch(() => \"\");\n try {\n return errorMessage(JSON.parse(text));\n } catch {\n return errorMessage(text);\n }\n}\n\nfunction isTimeout(cause: unknown): boolean {\n return cause instanceof Error && cause.name === \"TimeoutError\";\n}\n\nfunction timeoutError(cause: unknown, status?: number): SystemOneError {\n return new SystemOneError(\"AI Gateway request timed out.\", \"PROVIDER_TIMEOUT\", {\n cause,\n status,\n });\n}\n\nasync function readJSON(response: Response): Promise<unknown> {\n try {\n return await response.json();\n } catch (cause) {\n if (isTimeout(cause)) {\n throw timeoutError(cause, response.status);\n }\n throw new SystemOneError(\"AI Gateway returned an invalid JSON response.\", \"MODEL_ERROR\", {\n cause,\n status: response.status,\n });\n }\n}\n\nasync function evaluate(\n options: CreateSystemOneOptions,\n input: SystemOneInput,\n question: DecisionQuestion,\n): Promise<DecisionAnswer> {\n const body = JSON.stringify({\n model: input.model ?? defaultModel,\n state: toDecisionState(input.state),\n questions: { decision: question },\n });\n\n const token = await resolveToken(options.token);\n const headers = new Headers({ \"content-type\": \"application/json\" });\n if (token) {\n headers.set(\"authorization\", `Bearer ${token}`);\n }\n\n const fetchImplementation = options.fetch ?? globalThis.fetch;\n const signal =\n options.timeoutMs === undefined ? undefined : AbortSignal.timeout(options.timeoutMs);\n let response: Response;\n try {\n response = await fetchImplementation(endpoint(options.baseURL), {\n method: \"POST\",\n headers,\n body,\n signal,\n });\n } catch (cause) {\n if (isTimeout(cause)) {\n throw timeoutError(cause);\n }\n throw new SystemOneError(\"Unable to reach AI Gateway.\", \"PROVIDER_UNAVAILABLE\", { cause });\n }\n\n if (!response.ok) {\n const message = (await readErrorMessage(response)) ?? \"System One decision request failed.\";\n throw new SystemOneError(message, errorCode(response.status), { status: response.status });\n }\n\n const answer = asObject(asObject(asObject(await readJSON(response))?.answers)?.decision);\n if (answer?.type !== question.type) {\n throw invalidResponse(\"AI Gateway response did not contain a decision answer.\");\n }\n return answer;\n}\n\nfunction parseChoiceAnswer<Choices extends readonly [string, ...string[]]>(\n answer: DecisionAnswer,\n choices: Choices,\n): ChoiceResult<Choices[number]> {\n if (typeof answer.choice !== \"string\" || !choices.includes(answer.choice)) {\n throw invalidResponse(\"System One returned a value outside the requested answer space.\");\n }\n\n const rawProbabilities = asObject(answer.probabilities);\n if (!rawProbabilities) {\n throw invalidResponse(\"System One returned an invalid probability distribution.\");\n }\n\n const probabilities = Object.fromEntries(\n choices.map((choice) => {\n const probability = rawProbabilities[choice];\n if (!isProbability(probability)) {\n throw invalidResponse(`System One returned an invalid probability for \"${choice}\".`);\n }\n return [choice, probability];\n }),\n ) as Record<Choices[number], number>;\n\n if (!isProbability(answer.confidence)) {\n throw invalidResponse(\"System One returned an invalid confidence value.\");\n }\n\n return { value: answer.choice, probabilities, confidence: answer.confidence };\n}\n\nfunction parseBooleanAnswer(answer: DecisionAnswer): BooleanResult {\n if (!isProbability(answer.noul)) {\n throw invalidResponse(\"System One returned an invalid probability.\");\n }\n const value = answer.noul >= 0.5;\n return { value, probability: value ? answer.noul : 1 - answer.noul };\n}\n\nfunction parseScoreAnswer<Levels extends readonly [string, string, ...string[]]>(\n answer: DecisionAnswer,\n levels: Levels,\n): ChoiceResult<Levels[number]> {\n const rawProbabilities = asObject(answer.probabilities);\n if (!rawProbabilities) {\n throw invalidResponse(\"System One returned an invalid probability distribution.\");\n }\n\n const scores = levels.map((level, index) => {\n const probability = rawProbabilities[String(index)];\n if (!isProbability(probability)) {\n throw invalidResponse(`System One returned an invalid probability for \"${level}\".`);\n }\n return { level, probability };\n });\n\n if (!isProbability(answer.confidence)) {\n throw invalidResponse(\"System One returned an invalid confidence value.\");\n }\n\n return {\n value: scores.reduce((selected, score) =>\n score.probability > selected.probability ? score : selected,\n ).level,\n probabilities: Object.fromEntries(\n scores.map(({ level, probability }) => [level, probability]),\n ) as Record<Levels[number], number>,\n confidence: answer.confidence,\n };\n}\n\n/**\n * Create a System One client that makes decisions through Tailor AI Gateway.\n * @param options - AI Gateway connection options\n * @returns A semantic decision client\n */\nexport function createSystemOne(options: CreateSystemOneOptions): SystemOneClient {\n const choice: SystemOneClient[\"choice\"] = async (input) => {\n assertUniqueAnswers(input.choices);\n const answer = await evaluate(options, input, {\n type: \"choice\",\n instructions: input.question,\n criteria: Object.fromEntries(input.choices.map((value) => [value, null])),\n });\n return parseChoiceAnswer(answer, input.choices);\n };\n\n const boolean: SystemOneClient[\"boolean\"] = async (input) => {\n const answer = await evaluate(options, input, {\n type: \"noul\",\n instructions: input.question,\n });\n return parseBooleanAnswer(answer);\n };\n\n const score: SystemOneClient[\"score\"] = async (input) => {\n assertUniqueAnswers(input.levels);\n const answer = await evaluate(options, input, {\n type: \"score\",\n instructions: input.question,\n criteria: input.levels,\n });\n return parseScoreAnswer(answer, input.levels);\n };\n\n return { choice, boolean, score };\n}\n"],"mappings":"AA6BA,IAAa,eAAb,cAAoC,KAAM,CAExC,KAGA,OAQA,YACE,EACA,EACA,EAA8C,CAAC,EAC/C,CACA,MAAMA,EAASC,CAAO,EACtB,KAAK,KAAO,iBACZ,KAAK,KAAOC,EACZ,KAAK,OAASD,EAAQ,MACxB,CACF,EAkGA,SAAS,SAAS,EAA+B,CAC/C,MAAO,GAAG,OAAOE,CAAO,CAAC,CAAC,QAAQ,OAAQ,EAAE,EAAE,cAChD,CAEA,eAAe,aAAa,EAAqE,CAC/F,OAAO,OAAOC,GAAU,WAAaA,EAAM,EAAIA,CACjD,CAEA,SAAS,SAAS,EAAqD,CACrE,OAAO,OAAOC,GAAU,UAAYA,EAC/BA,EACD,IAAA,EACN,CAEA,SAAS,cAAc,EAAiC,CACtD,OAA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4.mjs","names":["aigateway","args"],"sources":["../src/runtime/aigateway.ts"],"sourcesContent":["/**\n * AI Gateway utilities.\n *\n * Thin typed wrapper around the platform-provided `tailor.aigateway` runtime API.\n * At runtime this delegates to `globalThis.tailor.aigateway`. Use `mockAigateway`\n * from `@tailor-platform/sdk/vitest` to mock these calls in unit tests.\n *\n * `name` is narrowed to the AI Gateway names defined via `defineAIGateway()`\n * once `tailor.d.ts` has been generated (via `tailor deploy`/`generate`).\n * @example\n * import { aigateway } from \"@tailor-platform/sdk/runtime\";\n *\n * const { url } = await aigateway.get(\"my-aigateway\");\n */\n\n// Import from the public entry (not `#/configure/types/aigateway-name`) so this d.ts\n// references `@tailor-platform/sdk` externally instead of inlining the registry — the\n// same generated `declare module \"@tailor-platform/sdk\"` that narrows\n// `authconnection.getConnectionToken` then also narrows this entry.\nimport type { AIGatewayName } from \"@tailor-platform/sdk\";\n\n/** Result of {@link TailorAigatewayAPI.get}. */\nexport interface GetAIGatewayResult {\n /** The platform-assigned URL of the AI Gateway. */\n url: string;\n}\n\n/**\n * Platform API surface for `tailor.aigateway`. Describes the shape the\n * platform runtime injects on `globalThis.tailor.aigateway`.\n */\nexport interface TailorAigatewayAPI {\n /**\n * Resolves an AI Gateway defined in the caller's own workspace.\n * @param name - AI Gateway name, as passed to `defineAIGateway()`\n * @returns The resolved AI Gateway's platform-assigned URL\n */\n get(name: AIGatewayName): Promise<GetAIGatewayResult>;\n}\n\nconst api = (): TailorAigatewayAPI =>\n (globalThis as unknown as { tailor: { aigateway: TailorAigatewayAPI } }).tailor.aigateway;\n\nconst get: TailorAigatewayAPI[\"get\"] = (...args) => api().get(...args);\n\n/** Runtime wrapper namespace for `tailor.aigateway`. */\nexport const aigateway = { get } as const satisfies TailorAigatewayAPI;\n"],"mappings":"AAwCA,MAAM,QACH,WAAwE,OAAO,UAKrEA,EAAY,CAAE,KAHa,GAAGC,IAAS,IAAI,CAAC,CAAC,IAAI,GAAGA,CAAI,CAGtC"}
1
+ {"version":3,"file":"aigateway-DsWDjzk4.mjs","names":["aigateway","args"],"sources":["../src/runtime/aigateway.ts"],"sourcesContent":["/**\n * AI Gateway utilities.\n *\n * Thin typed wrapper around the platform-provided `tailor.aigateway` runtime API.\n * At runtime this delegates to `globalThis.tailor.aigateway`. Use `mockAigateway`\n * from `@tailor-platform/sdk/vitest` to mock these calls in unit tests.\n *\n * `name` is narrowed to the AI Gateway names defined via `defineAIGateway()`\n * once `tailor.d.ts` has been generated (via `tailor deploy`/`generate`).\n * @example\n * import { aigateway } from \"@tailor-platform/sdk/runtime\";\n *\n * const { url } = await aigateway.get(\"my-aigateway\");\n */\n\n// Import from the public entry (not `#/configure/types/aigateway-name`) so this d.ts\n// references `@tailor-platform/sdk` externally instead of inlining the registry — the\n// same generated `declare module \"@tailor-platform/sdk\"` that narrows\n// `authconnection.getConnectionToken` then also narrows this entry.\nimport type { AIGatewayName } from \"@tailor-platform/sdk\";\n\n/** Result of {@link TailorAigatewayAPI.get}. */\nexport interface GetAIGatewayResult {\n /** The platform-assigned URL of the AI Gateway. */\n url: string;\n}\n\n/**\n * Platform API surface for `tailor.aigateway`. Describes the shape the\n * platform runtime injects on `globalThis.tailor.aigateway`.\n */\nexport interface TailorAigatewayAPI {\n /**\n * Resolves an AI Gateway defined in the caller's own workspace.\n * @param name - AI Gateway name, as passed to `defineAIGateway()`\n * @returns The resolved AI Gateway's platform-assigned URL\n */\n get(name: AIGatewayName): Promise<GetAIGatewayResult>;\n}\n\nconst api = (): TailorAigatewayAPI =>\n (globalThis as unknown as { tailor: { aigateway: TailorAigatewayAPI } }).tailor.aigateway;\n\nconst get: TailorAigatewayAPI[\"get\"] = (...args) => api().get(...args);\n\n/** Runtime wrapper namespace for `tailor.aigateway`. */\nexport const aigateway = { get } as const satisfies TailorAigatewayAPI;\n"],"mappings":"AAwCA,MAAM,QACH,WAAwE,OAAO,UAKrEA,EAAY,CAAE,KAHa,GAAGC,IAAS,IAAI,CAAC,CAAC,IAAI,GAAGA,CAAI,CAGtC,E"}