@tailor-platform/sdk 2.30.0 → 2.32.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/CHANGELOG.md +48 -0
- package/dist/ai/index.d.mts +112 -0
- package/dist/ai/index.mjs +2 -0
- package/dist/ai/index.mjs.map +1 -0
- package/dist/aigateway-DsWDjzk4.mjs.map +1 -1
- package/dist/application-D0xNJbag.mjs.map +1 -1
- package/dist/assert-WeXvmG4j.mjs.map +1 -1
- package/dist/authconnection-CynFBIv8.mjs.map +1 -1
- package/dist/brand-C8nMKhJC.mjs.map +1 -1
- package/dist/cli/lib.mjs +1 -1
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/cli/main.mjs +6 -6
- package/dist/cli/main.mjs.map +1 -1
- package/dist/completion/zsh-worker.zsh +6 -2
- package/dist/configure/index.mjs.map +1 -1
- package/dist/context-D0QjfxzD.mjs.map +1 -1
- package/dist/crashreport-BCIy33Cz.mjs.map +1 -1
- package/dist/date-CgP7gMG_.mjs.map +1 -1
- package/dist/date-representation-Cr7W7Pn2.mjs.map +1 -1
- package/dist/errors-BOF68LJ5.mjs.map +1 -1
- package/dist/es-builtins-SfvXRVoG.mjs.map +1 -1
- package/dist/field-parse-C41e3UAF.mjs.map +1 -1
- package/dist/file-DKBOj5q4.mjs.map +1 -1
- package/dist/globals-BCmGX05J.mjs.map +1 -1
- package/dist/guards-yDXyKC9F.mjs.map +1 -1
- package/dist/iconv-DlFMt2gW.mjs.map +1 -1
- package/dist/idp-G_ojPBB5.mjs.map +1 -1
- package/dist/interceptor-DQg3cR_9.mjs.map +1 -1
- package/dist/kysely/index.mjs.map +1 -1
- package/dist/{kysely-type-BWMfV301.mjs → kysely-type-CBwsdx16.mjs} +6 -3
- package/dist/kysely-type-CBwsdx16.mjs.map +1 -0
- package/dist/logger-DP2BjQ93.mjs.map +1 -1
- package/dist/logger-RgtbhJ83.mjs.map +1 -1
- package/dist/manager-Bk-7vkwd.mjs.map +1 -1
- package/dist/migration-steps-C6F3zNdQ.mjs.map +1 -1
- package/dist/multiline-EyzjEwn9.mjs.map +1 -1
- package/dist/node-builtins-DYfhPBnz.mjs.map +1 -1
- package/dist/package-json-C690ceex.mjs.map +1 -1
- package/dist/platform-serialize-DkiTdHOt.mjs.map +1 -1
- package/dist/plugin/builtin/enum-constants/index.mjs.map +1 -1
- package/dist/plugin/builtin/file-utils/index.mjs.map +1 -1
- package/dist/plugin/builtin/kysely-type/index.mjs +1 -1
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/{register-ts-hook-CDnN_Jx2.mjs → register-ts-hook-_dHIREtU.mjs} +127 -89
- package/dist/register-ts-hook-_dHIREtU.mjs.map +1 -0
- package/dist/registry-BijIDRVA.mjs.map +1 -1
- package/dist/repl-editor-DGJBfIt1.mjs.map +1 -1
- package/dist/schema-B6hJQWp6.mjs.map +1 -1
- package/dist/secret-file-C9wp_FCX.mjs.map +1 -1
- package/dist/secretmanager-vHQoXdQz.mjs.map +1 -1
- package/dist/seed/index.mjs.map +1 -1
- package/dist/seed-Cn-3JApy.mjs.map +1 -1
- package/dist/service-9SBPNpK8.mjs.map +1 -1
- package/dist/service-9rwi_I4d.mjs.map +1 -1
- package/dist/service_pb-Bbu2QSIr.mjs.map +1 -1
- package/dist/telemetry-DfT2UfI4.mjs +2 -0
- package/dist/telemetry-DfT2UfI4.mjs.map +1 -0
- package/dist/{telemetry-DpkFGBmu.mjs → telemetry-nqOtDWNO.mjs} +1 -1
- package/dist/type-source--ZNcV8RJ.mjs.map +1 -1
- package/dist/user-agent-vdHYF3QL.mjs.map +1 -1
- package/dist/utils/test/index.mjs.map +1 -1
- package/dist/vitest/environment.mjs.map +1 -1
- package/dist/vitest/index.mjs.map +1 -1
- package/dist/vitest/setup.mjs.map +1 -1
- package/dist/wait-point-invoker-eiP-IIux.mjs.map +1 -1
- package/dist/wait-point-registry-B-ESkTZX.mjs.map +1 -1
- package/dist/workflow-Cs9ISw6j.mjs.map +1 -1
- package/dist/workspace_resource_pb-CaoM2npP.mjs.map +1 -1
- package/docs/ai.md +92 -0
- package/docs/cli/tailordb.md +17 -15
- package/docs/cli/workspace.md +1 -1
- package/docs/github-actions.md +98 -11
- package/docs/services/tailordb/migration.md +45 -31
- package/docs/testing.md +2 -1
- package/package.json +16 -9
- package/dist/kysely-type-BWMfV301.mjs.map +0 -1
- package/dist/register-ts-hook-CDnN_Jx2.mjs.map +0 -1
- package/dist/telemetry-Xk7J829P.mjs +0 -2
- package/dist/telemetry-Xk7J829P.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
# @tailor-platform/sdk
|
|
2
2
|
|
|
3
|
+
## 2.32.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#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.
|
|
8
|
+
|
|
9
|
+
- [#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.
|
|
10
|
+
|
|
11
|
+
- [#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.
|
|
12
|
+
|
|
13
|
+
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.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#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.
|
|
18
|
+
|
|
19
|
+
- [#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.
|
|
20
|
+
|
|
21
|
+
- [`127454d`](https://github.com/tailor-platform/sdk/commit/127454d6cd9d4fe20ccc3504f44430650874df71) Thanks [@haru0017](https://github.com/haru0017)! - Re-apply rolldown 1.2.14
|
|
22
|
+
|
|
23
|
+
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.
|
|
24
|
+
|
|
25
|
+
- [#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.
|
|
26
|
+
|
|
27
|
+
- [#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
|
|
28
|
+
|
|
29
|
+
- [#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
|
|
30
|
+
|
|
31
|
+
- [#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.
|
|
32
|
+
|
|
33
|
+
## 2.31.1
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- [#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`).
|
|
38
|
+
|
|
39
|
+
## 2.31.0
|
|
40
|
+
|
|
41
|
+
### Minor Changes
|
|
42
|
+
|
|
43
|
+
- [#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.
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- [#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.
|
|
48
|
+
|
|
49
|
+
- [#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.
|
|
50
|
+
|
|
3
51
|
## 2.30.0
|
|
4
52
|
|
|
5
53
|
### 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,OAAO,OAAOA,GAAU,UAAY,OAAO,SAASA,CAAK,GAAKA,GAAS,GAAKA,GAAS,CACvF,CAEA,SAAS,gBAAgB,EAAiC,CACxD,OAAO,IAAI,eAAeL,EAAS,aAAa,CAClD,CAEA,SAAS,oBAAoB,EAAiC,CAC5D,GAAI,IAAI,IAAIM,CAAM,CAAC,CAAC,OAASA,EAAO,OAClC,MAAM,IAAI,eAAe,2CAA4C,sBAAsB,CAE/F,CAEA,SAAS,aAAa,EAAwC,CAC5D,OAAO,IAAI,eACT,kEACA,kBACAL,CACF,CACF,CAEA,SAAS,gBAAgB,EAAyB,CAChD,IAAII,EACJ,GAAI,CACF,IAAME,EAAa,KAAK,UAAUC,CAAK,EACvC,EAAQD,IAAe,IAAA,GAAY,IAAA,GAAY,KAAK,MAAMA,CAAU,CACtE,OAASE,EAAO,CACd,MAAM,aAAa,CAAE,OAAM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,QAAO,iBAAkB,CAACG,EAAOL,CAAW,CAAC,CAC7D,EACA,WAAYJ,EAAO,UACrB,CACF,CAOA,SAAgB,gBAAgB,EAAkD,CA6BhF,MAAO,CAAE,YA5BwC,KAC/C,oBAAoBL,EAAM,OAAO,EAM1B,kBAAkB,MALJ,SAASlB,EAASkB,EAAO,CAC5C,KAAM,SACN,aAAcA,EAAM,SACpB,SAAU,OAAO,YAAYA,EAAM,QAAQ,IAAK,GAAU,CAACd,EAAO,IAAI,CAAC,CAAC,CAC1E,CAAC,EACgCc,EAAM,OAAO,GAqB/B,aAlBkC,IAK1C,mBAAmB,MAJL,SAASlB,EAASkB,EAAO,CAC5C,KAAM,OACN,aAAcA,EAAM,QACtB,CAAC,CAC+B,EAaR,WAVqB,KAC7C,oBAAoBA,EAAM,MAAM,EAMzB,iBAAiB,MALH,SAASlB,EAASkB,EAAO,CAC5C,KAAM,QACN,aAAcA,EAAM,SACpB,SAAUA,EAAM,MAClB,CAAC,EAC+BA,EAAM,MAAM,EAGd,CAClC,C"}
|
|
@@ -1 +1 @@
|
|
|
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"}
|
|
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"}
|