@effect/ai-typesafe 4.0.4 → 4.0.6
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/README.md +15 -0
- package/ai-docs/package.json +1 -1
- package/ai-docs/src/06_schedule/10_schedules.ts +5 -4
- package/ai-docs/src/52_graphql/10_basics.ts +19 -13
- package/ai-docs/src/52_graphql/30_batching.ts +6 -4
- package/ai-docs/src/52_graphql/40_aliased-batching.ts +6 -4
- package/ai-docs/tsconfig.json +3 -1
- package/dist/TypeSafeDecisionModel.d.ts.map +1 -1
- package/dist/TypeSafeDecisionModel.js +2 -2
- package/dist/TypeSafeDecisionModel.js.map +1 -1
- package/dist/TypeSafeSchema.d.ts +26 -26
- package/dist/TypeSafeSchema.d.ts.map +1 -1
- package/dist/TypeSafeSchema.js +11 -10
- package/dist/TypeSafeSchema.js.map +1 -1
- package/dist/internal/errors.d.ts.map +1 -1
- package/dist/internal/errors.js +11 -8
- package/dist/internal/errors.js.map +1 -1
- package/package.json +3 -3
- package/src/TypeSafeDecisionModel.ts +6 -2
- package/src/TypeSafeSchema.ts +11 -9
- package/src/internal/errors.ts +11 -8
package/README.md
CHANGED
|
@@ -28,4 +28,19 @@ Whether your team is considering Effect, rolling it out, or already running it i
|
|
|
28
28
|
|
|
29
29
|
Use `TypeSafeClient.layerConfig()` to read `TYPESAFE_API_KEY`, then provide `TypeSafeDecisionModel.model("jev-latest")` to a decision workflow. Versioned model identifiers such as `jev-1.13.0` are also supported.
|
|
30
30
|
|
|
31
|
+
Instructions and descriptions can be strings, JSON objects, or JSON arrays, as in TypeSafe's [structured questions](https://docs.typesafe.ai/primitives/advanced). A rating level with a structured description takes an explicit label, which answers use:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { Decision } from "effect/ai"
|
|
35
|
+
|
|
36
|
+
const severity = Decision.rate({
|
|
37
|
+
instructions: "How severe is the reported issue?",
|
|
38
|
+
criteria: [
|
|
39
|
+
{ label: "cosmetic", description: { what: "No impact to functionality", examples: ["typo in a label"] } },
|
|
40
|
+
{ label: "degraded", description: { what: "Broken, but a workaround exists", examples: ["fails in one browser"] } },
|
|
41
|
+
{ label: "blocking", description: { what: "No workaround exists", examples: ["cannot log in"] } }
|
|
42
|
+
]
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
31
46
|
The client does not retry automatically. Rate-limit errors include the provider's retry delay when available. Provider distributions are preserved, not normalized; they must satisfy the core `DecisionModel` validation, including its current `1e-6` sum tolerance. TypeSafe's rounding behavior has not been verified against the live API.
|
package/ai-docs/package.json
CHANGED
|
@@ -5,14 +5,15 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { Duration, Effect, Random, Schedule, Schema } from "effect"
|
|
7
7
|
|
|
8
|
-
// Production pattern: capped exponential backoff with jitter and
|
|
9
|
-
//
|
|
8
|
+
// Production pattern: capped exponential backoff with jitter and at most 5 retries (6 attempts).
|
|
9
|
+
// Base delays start at 250ms and grow exponentially, capped at 10s before jitter.
|
|
10
10
|
export const productionRetrySchedule = Schedule.min([
|
|
11
11
|
Schedule.exponential("250 millis"),
|
|
12
12
|
// Cap the delay at 10 seconds to avoid excessively long waits.
|
|
13
13
|
Schedule.spaced("10 seconds")
|
|
14
14
|
]).pipe(
|
|
15
15
|
Schedule.jittered,
|
|
16
|
+
Schedule.upTo({ times: 5 }),
|
|
16
17
|
Schedule.setInputType<HttpError>(),
|
|
17
18
|
Schedule.while(({ input }) => input.retryable)
|
|
18
19
|
)
|
|
@@ -44,8 +45,8 @@ export const fetchUserProfile = Effect.fn("fetchUserProfile")(
|
|
|
44
45
|
// Use the schedule with `Effect.retry` to retry failures.
|
|
45
46
|
export const loadUserWithRetry = fetchUserProfile("user-123").pipe(
|
|
46
47
|
Effect.retry(productionRetrySchedule),
|
|
47
|
-
//
|
|
48
|
-
//
|
|
48
|
+
// Turn the final error into a defect, either after exhausting the retries
|
|
49
|
+
// or immediately for a non-retryable error.
|
|
49
50
|
Effect.orDie
|
|
50
51
|
)
|
|
51
52
|
|
|
@@ -21,22 +21,28 @@ import { FetchHttpClient } from "effect/http"
|
|
|
21
21
|
// }
|
|
22
22
|
// }
|
|
23
23
|
//
|
|
24
|
-
// Each nested selection
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
// Each nested object selection has a Schema.Struct const and a same-named
|
|
25
|
+
// interface for its decoded type. The const handles decoding, encoding and
|
|
26
|
+
// `make`; use the interface in explicit type annotations when a named type
|
|
27
|
+
// is useful. Inferred types and editor hovers can expand structurally rather
|
|
28
|
+
// than showing the names, unlike the previous Schema.Opaque classes.
|
|
29
|
+
export const PageInfo = Schema.Struct({
|
|
30
|
+
hasNextPage: Schema.Boolean,
|
|
31
|
+
endCursor: Schema.NullOr(Schema.String)
|
|
32
|
+
})
|
|
33
|
+
export interface PageInfo extends Schema.Struct.Type<typeof PageInfo.fields> {}
|
|
28
34
|
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
) {}
|
|
35
|
+
export const Issue = Schema.Struct({ number: Schema.Int, title: Schema.String })
|
|
36
|
+
export interface Issue extends Schema.Struct.Type<typeof Issue.fields> {}
|
|
32
37
|
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
)
|
|
38
|
+
export const IssueConnection = Schema.Struct({
|
|
39
|
+
pageInfo: PageInfo,
|
|
40
|
+
nodes: Schema.NullOr(Schema.Array(Schema.NullOr(Issue)))
|
|
41
|
+
})
|
|
42
|
+
export interface IssueConnection extends Schema.Struct.Type<typeof IssueConnection.fields> {}
|
|
36
43
|
|
|
37
|
-
export
|
|
38
|
-
|
|
39
|
-
) {}
|
|
44
|
+
export const Repository = Schema.Struct({ issues: IssueConnection })
|
|
45
|
+
export interface Repository extends Schema.Struct.Type<typeof Repository.fields> {}
|
|
40
46
|
|
|
41
47
|
export const RepoIssues = GraphQL.query("RepoIssues", {
|
|
42
48
|
document:
|
|
@@ -26,15 +26,17 @@ declare namespace Shared {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export
|
|
29
|
+
export const Repository = Schema.Struct({
|
|
30
30
|
__typename: Schema.Literal("Repository"),
|
|
31
31
|
nameWithOwner: Schema.String
|
|
32
|
-
})
|
|
32
|
+
})
|
|
33
|
+
export interface Repository extends Schema.Struct.Type<typeof Repository.fields> {}
|
|
33
34
|
|
|
34
35
|
// Unselected node types are represented by `otherTypename`.
|
|
35
|
-
export
|
|
36
|
+
export const NodeOther = Schema.Struct({
|
|
36
37
|
__typename: GraphQL.otherTypename<Shared.Typename.Node>()(["Repository"])
|
|
37
|
-
})
|
|
38
|
+
})
|
|
39
|
+
export interface NodeOther extends Schema.Struct.Type<typeof NodeOther.fields> {}
|
|
38
40
|
|
|
39
41
|
/** `query RepoNodes` */
|
|
40
42
|
export const RepoNodes = GraphQL.query("RepoNodes", {
|
|
@@ -23,14 +23,16 @@ import { GitHubAuth } from "./10_basics.ts"
|
|
|
23
23
|
// "../schema.graphql.ts"`); here `Shared` is declared inline.
|
|
24
24
|
const Shared = { Int: Schema.Number.check(Schema.isInt32()) }
|
|
25
25
|
|
|
26
|
-
export
|
|
26
|
+
export const PullRequestPullRequest = Schema.Struct({
|
|
27
27
|
number: Shared.Int,
|
|
28
28
|
title: Schema.String
|
|
29
|
-
})
|
|
29
|
+
})
|
|
30
|
+
export interface PullRequestPullRequest extends Schema.Struct.Type<typeof PullRequestPullRequest.fields> {}
|
|
30
31
|
|
|
31
|
-
export
|
|
32
|
+
export const Repository = Schema.Struct({
|
|
32
33
|
pullRequest: Schema.NullOr(PullRequestPullRequest)
|
|
33
|
-
})
|
|
34
|
+
})
|
|
35
|
+
export interface Repository extends Schema.Struct.Type<typeof Repository.fields> {}
|
|
34
36
|
|
|
35
37
|
// The generator gives queries and mutations their document as a
|
|
36
38
|
// `GraphQL.DocumentTemplate`. The odd entries of each `body` are the names
|
package/ai-docs/tsconfig.json
CHANGED
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
"plugins": [
|
|
14
14
|
{
|
|
15
15
|
"name": "@effect/language-service",
|
|
16
|
+
"effectFn": ["untraced"],
|
|
16
17
|
"namespaceImportPackages": [],
|
|
17
18
|
"diagnosticSeverity": {
|
|
18
19
|
"floatingEffect": "off",
|
|
19
20
|
"preferSchemaOverJson": "off",
|
|
20
|
-
"unstableApiUsage": "off"
|
|
21
|
+
"unstableApiUsage": "off",
|
|
22
|
+
"effectFnOpportunity": "error"
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeSafeDecisionModel.d.ts","sourceRoot":"","sources":["../src/TypeSafeDecisionModel.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAA;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGpD;;;;;;GAMG;AACH,MAAM,MAAM,KAAK,GAAG,YAAY,GAAG,aAAa,GAAG,YAAY,CAAA;AAE/D;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,UACT,KAAK,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,KAC3B,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,aAAa,CAAC,aAAa,EAAE,cAAc,CACrB,CAAA;AAEnD;;;;;;;;GAQG;AACH,eAAO,MAAM,IAAI;oBAEc,KAAK,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"TypeSafeDecisionModel.d.ts","sourceRoot":"","sources":["../src/TypeSafeDecisionModel.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAA;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGpD;;;;;;GAMG;AACH,MAAM,MAAM,KAAK,GAAG,YAAY,GAAG,aAAa,GAAG,YAAY,CAAA;AAE/D;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,UACT,KAAK,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,KAC3B,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,aAAa,CAAC,aAAa,EAAE,cAAc,CACrB,CAAA;AAEnD;;;;;;;;GAQG;AACH,eAAO,MAAM,IAAI;oBAEc,KAAK,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;uEA2DnD,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,YACP;IAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;CAAE,KACjD,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,EAAE,KAAK,EAAE,cAAc,CACP,CAAA"}
|
|
@@ -50,7 +50,7 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
|
50
50
|
questions[key] = {
|
|
51
51
|
type: "score",
|
|
52
52
|
instructions: decision.instructions,
|
|
53
|
-
criteria: decision.criteria
|
|
53
|
+
criteria: decision.criteria.map(level => level.description)
|
|
54
54
|
};
|
|
55
55
|
break;
|
|
56
56
|
case "Probability":
|
|
@@ -85,7 +85,7 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
|
85
85
|
const probabilities = Object.create(null);
|
|
86
86
|
for (let index = 0; index < levels.length; index++) {
|
|
87
87
|
const probability = answer.probabilities[String(index)];
|
|
88
|
-
if (probability !== undefined) probabilities[levels[index]] = probability;
|
|
88
|
+
if (probability !== undefined) probabilities[levels[index].label] = probability;
|
|
89
89
|
}
|
|
90
90
|
answers[key] = {
|
|
91
91
|
_tag: "Rate",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeSafeDecisionModel.js","names":[],"sources":["../src/TypeSafeDecisionModel.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;AAMA,OAAO,KAAK,aAAa,MAAM,yBAAyB;AACxD,OAAO,KAAK,OAAO,MAAM,iBAAiB;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,SAAS,cAAc,QAAQ,qBAAqB;AAYpD;;;;;;;AAOA,OAAO,MAAM,KAAK,GAChB,KAA4B,IAE5B,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC;EAAE;AAAK,CAAE,CAAC,CAAC;AAEnD;;;;;;;;;AASA,OAAO,MAAM,IAAI,gBAAG,MAAM,CAAC,UAAU,CACnC,WACE,OAAkD;EAElD,MAAM,MAAM,GAAG,OAAO,cAAc;EACpC,OAAO,OAAO,aAAa,CAAC,IAAI,CAAC;IAC/B,oBAAoB,EAAE,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,WAAU;MAAE,KAAK;MAAE;IAAS,CAAE;MACtD,MAAM,SAAS,GAA2D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;MAC7F,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QACvD,QAAQ,QAAQ,CAAC,IAAI;UACnB,KAAK,UAAU;YACb,SAAS,CAAC,GAAG,CAAC,GAAG;cAAE,IAAI,EAAE,QAAQ;cAAE,YAAY,EAAE,QAAQ,CAAC,YAAY;cAAE,QAAQ,EAAE,QAAQ,CAAC;YAAQ,CAAE;YACrG;UACF,KAAK,MAAM;YACT,SAAS,CAAC,GAAG,CAAC,GAAG;
|
|
1
|
+
{"version":3,"file":"TypeSafeDecisionModel.js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GAAG,CAAC,GAAG;gBAAE,IAAI,EAAE,MAAM;gBAAE,MAAM,EAAE,MAAM,CAAC,KAAK;gBAAE,aAAa;gBAAE,UAAU,EAAE,MAAM,CAAC;cAAU,CAAE;cACnG;YACF;UACA,KAAK,MAAM;YACT,OAAO,CAAC,GAAG,CAAC,GAAG;cAAE,IAAI,EAAE,aAAa;cAAE,WAAW,EAAE,MAAM,CAAC;YAAI,CAAE;YAChE;QACJ;MACF;MACA,OAAO;QACL,OAAO;QACP,KAAK,EAAE;UAAE,WAAW,EAAE,QAAQ,CAAC,KAAK,EAAE,YAAY;UAAE,YAAY,EAAE,QAAQ,CAAC,KAAK,EAAE;QAAa;OAChG;IACH,CAAC;GACF,CAAC;AACJ,CAAC,CACF;AAED;;;;;;;AAOA,OAAO,MAAM,KAAK,GAChB,OAAkD,IAElD,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC","ignoreList":[]}
|
package/dist/TypeSafeSchema.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ import * as Schema from "effect/Schema";
|
|
|
14
14
|
*/
|
|
15
15
|
export declare const ChoiceQuestion: Schema.Struct<{
|
|
16
16
|
readonly type: Schema.Literal<"choice">;
|
|
17
|
-
readonly instructions: Schema.String
|
|
18
|
-
readonly criteria: Schema.$Record<Schema.String, Schema.String
|
|
17
|
+
readonly instructions: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
18
|
+
readonly criteria: Schema.$Record<Schema.String, Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>>;
|
|
19
19
|
}>;
|
|
20
20
|
/**
|
|
21
21
|
* An ordered rating question.
|
|
@@ -26,8 +26,8 @@ export declare const ChoiceQuestion: Schema.Struct<{
|
|
|
26
26
|
*/
|
|
27
27
|
export declare const ScoreQuestion: Schema.Struct<{
|
|
28
28
|
readonly type: Schema.Literal<"score">;
|
|
29
|
-
readonly instructions: Schema.String
|
|
30
|
-
readonly criteria: Schema.$Array<Schema.String
|
|
29
|
+
readonly instructions: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
30
|
+
readonly criteria: Schema.$Array<Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>>;
|
|
31
31
|
}>;
|
|
32
32
|
/**
|
|
33
33
|
* A probability question.
|
|
@@ -38,14 +38,14 @@ export declare const ScoreQuestion: Schema.Struct<{
|
|
|
38
38
|
*/
|
|
39
39
|
export declare const NoulQuestion: Schema.Struct<{
|
|
40
40
|
readonly type: Schema.Literal<"noul">;
|
|
41
|
-
readonly instructions: Schema.String
|
|
41
|
+
readonly instructions: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
42
42
|
readonly criteria: Schema.optional<Schema.Struct<{
|
|
43
|
-
readonly false: Schema.String
|
|
44
|
-
readonly true: Schema.String
|
|
43
|
+
readonly false: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
44
|
+
readonly true: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
45
45
|
}>>;
|
|
46
46
|
}>;
|
|
47
47
|
/**
|
|
48
|
-
* A System One question.
|
|
48
|
+
* A System One question with string, JSON object, JSON array, or `null` instructions and descriptions.
|
|
49
49
|
*
|
|
50
50
|
* @stability unstable
|
|
51
51
|
* @category schemas
|
|
@@ -53,18 +53,18 @@ export declare const NoulQuestion: Schema.Struct<{
|
|
|
53
53
|
*/
|
|
54
54
|
export declare const Question: Schema.Union<readonly [Schema.Struct<{
|
|
55
55
|
readonly type: Schema.Literal<"choice">;
|
|
56
|
-
readonly instructions: Schema.String
|
|
57
|
-
readonly criteria: Schema.$Record<Schema.String, Schema.String
|
|
56
|
+
readonly instructions: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
57
|
+
readonly criteria: Schema.$Record<Schema.String, Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>>;
|
|
58
58
|
}>, Schema.Struct<{
|
|
59
59
|
readonly type: Schema.Literal<"score">;
|
|
60
|
-
readonly instructions: Schema.String
|
|
61
|
-
readonly criteria: Schema.$Array<Schema.String
|
|
60
|
+
readonly instructions: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
61
|
+
readonly criteria: Schema.$Array<Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>>;
|
|
62
62
|
}>, Schema.Struct<{
|
|
63
63
|
readonly type: Schema.Literal<"noul">;
|
|
64
|
-
readonly instructions: Schema.String
|
|
64
|
+
readonly instructions: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
65
65
|
readonly criteria: Schema.optional<Schema.Struct<{
|
|
66
|
-
readonly false: Schema.String
|
|
67
|
-
readonly true: Schema.String
|
|
66
|
+
readonly false: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
67
|
+
readonly true: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
68
68
|
}>>;
|
|
69
69
|
}>]>;
|
|
70
70
|
/**
|
|
@@ -79,18 +79,18 @@ export declare const SystemOneRequest: Schema.Struct<{
|
|
|
79
79
|
readonly state: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
80
80
|
readonly questions: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Struct<{
|
|
81
81
|
readonly type: Schema.Literal<"choice">;
|
|
82
|
-
readonly instructions: Schema.String
|
|
83
|
-
readonly criteria: Schema.$Record<Schema.String, Schema.String
|
|
82
|
+
readonly instructions: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
83
|
+
readonly criteria: Schema.$Record<Schema.String, Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>>;
|
|
84
84
|
}>, Schema.Struct<{
|
|
85
85
|
readonly type: Schema.Literal<"score">;
|
|
86
|
-
readonly instructions: Schema.String
|
|
87
|
-
readonly criteria: Schema.$Array<Schema.String
|
|
86
|
+
readonly instructions: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
87
|
+
readonly criteria: Schema.$Array<Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>>;
|
|
88
88
|
}>, Schema.Struct<{
|
|
89
89
|
readonly type: Schema.Literal<"noul">;
|
|
90
|
-
readonly instructions: Schema.String
|
|
90
|
+
readonly instructions: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
91
91
|
readonly criteria: Schema.optional<Schema.Struct<{
|
|
92
|
-
readonly false: Schema.String
|
|
93
|
-
readonly true: Schema.String
|
|
92
|
+
readonly false: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
93
|
+
readonly true: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
|
|
94
94
|
}>>;
|
|
95
95
|
}>]>>;
|
|
96
96
|
}>;
|
|
@@ -108,7 +108,7 @@ export declare const ChoiceAnswer: Schema.Struct<{
|
|
|
108
108
|
readonly confidence: Schema.Number;
|
|
109
109
|
}>;
|
|
110
110
|
/**
|
|
111
|
-
* A zero-based rating and index-keyed distribution.
|
|
111
|
+
* A zero-based rating and index-keyed distribution. `legend` maps indices to descriptions.
|
|
112
112
|
*
|
|
113
113
|
* @stability unstable
|
|
114
114
|
* @category schemas
|
|
@@ -119,7 +119,7 @@ export declare const ScoreAnswer: Schema.Struct<{
|
|
|
119
119
|
readonly score: Schema.Number;
|
|
120
120
|
readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
|
|
121
121
|
readonly confidence: Schema.Number;
|
|
122
|
-
readonly legend: Schema.optional<Schema.$Record<Schema.String, Schema.
|
|
122
|
+
readonly legend: Schema.optional<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
123
123
|
}>;
|
|
124
124
|
/**
|
|
125
125
|
* A Bernoulli probability.
|
|
@@ -149,7 +149,7 @@ export declare const Answer: Schema.Union<readonly [Schema.Struct<{
|
|
|
149
149
|
readonly score: Schema.Number;
|
|
150
150
|
readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
|
|
151
151
|
readonly confidence: Schema.Number;
|
|
152
|
-
readonly legend: Schema.optional<Schema.$Record<Schema.String, Schema.
|
|
152
|
+
readonly legend: Schema.optional<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
153
153
|
}>, Schema.Struct<{
|
|
154
154
|
readonly type: Schema.Literal<"noul">;
|
|
155
155
|
readonly noul: Schema.Number;
|
|
@@ -173,7 +173,7 @@ export declare const SystemOneResponse: Schema.Struct<{
|
|
|
173
173
|
readonly score: Schema.Number;
|
|
174
174
|
readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
|
|
175
175
|
readonly confidence: Schema.Number;
|
|
176
|
-
readonly legend: Schema.optional<Schema.$Record<Schema.String, Schema.
|
|
176
|
+
readonly legend: Schema.optional<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
177
177
|
}>, Schema.Struct<{
|
|
178
178
|
readonly type: Schema.Literal<"noul">;
|
|
179
179
|
readonly noul: Schema.Number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeSafeSchema.d.ts","sourceRoot":"","sources":["../src/TypeSafeSchema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"TypeSafeSchema.d.ts","sourceRoot":"","sources":["../src/TypeSafeSchema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAIvC;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;;EAIzB,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa;;;;EAIxB,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY;;;;;;;EAIvB,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;IAA8D,CAAA;AAEnF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;EAI3B,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY;;;;;EAKvB,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW;;;;;;EAMtB,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU;;;EAAuE,CAAA;AAE9F;;;;;;GAMG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;IAAwD,CAAA;AAE3E;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;EAO5B,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB;;;;;;EAM7B,CAAA"}
|
package/dist/TypeSafeSchema.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @since 4.0.0
|
|
6
6
|
*/
|
|
7
7
|
import * as Schema from "effect/Schema";
|
|
8
|
+
const Entry = /*#__PURE__*/Schema.NullOr(/*#__PURE__*/Schema.Union([Schema.String, Schema.JsonObject, /*#__PURE__*/Schema.Array(Schema.Json)]));
|
|
8
9
|
/**
|
|
9
10
|
* A classification question.
|
|
10
11
|
*
|
|
@@ -14,8 +15,8 @@ import * as Schema from "effect/Schema";
|
|
|
14
15
|
*/
|
|
15
16
|
export const ChoiceQuestion = /*#__PURE__*/Schema.Struct({
|
|
16
17
|
type: /*#__PURE__*/Schema.Literal("choice"),
|
|
17
|
-
instructions:
|
|
18
|
-
criteria: /*#__PURE__*/Schema.Record(Schema.String,
|
|
18
|
+
instructions: Entry,
|
|
19
|
+
criteria: /*#__PURE__*/Schema.Record(Schema.String, Entry)
|
|
19
20
|
});
|
|
20
21
|
/**
|
|
21
22
|
* An ordered rating question.
|
|
@@ -26,8 +27,8 @@ export const ChoiceQuestion = /*#__PURE__*/Schema.Struct({
|
|
|
26
27
|
*/
|
|
27
28
|
export const ScoreQuestion = /*#__PURE__*/Schema.Struct({
|
|
28
29
|
type: /*#__PURE__*/Schema.Literal("score"),
|
|
29
|
-
instructions:
|
|
30
|
-
criteria: /*#__PURE__*/Schema.Array(
|
|
30
|
+
instructions: Entry,
|
|
31
|
+
criteria: /*#__PURE__*/Schema.Array(Entry)
|
|
31
32
|
});
|
|
32
33
|
/**
|
|
33
34
|
* A probability question.
|
|
@@ -38,14 +39,14 @@ export const ScoreQuestion = /*#__PURE__*/Schema.Struct({
|
|
|
38
39
|
*/
|
|
39
40
|
export const NoulQuestion = /*#__PURE__*/Schema.Struct({
|
|
40
41
|
type: /*#__PURE__*/Schema.Literal("noul"),
|
|
41
|
-
instructions:
|
|
42
|
+
instructions: Entry,
|
|
42
43
|
criteria: /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Struct({
|
|
43
|
-
false:
|
|
44
|
-
true:
|
|
44
|
+
false: Entry,
|
|
45
|
+
true: Entry
|
|
45
46
|
}))
|
|
46
47
|
});
|
|
47
48
|
/**
|
|
48
|
-
* A System One question.
|
|
49
|
+
* A System One question with string, JSON object, JSON array, or `null` instructions and descriptions.
|
|
49
50
|
*
|
|
50
51
|
* @stability unstable
|
|
51
52
|
* @category schemas
|
|
@@ -78,7 +79,7 @@ export const ChoiceAnswer = /*#__PURE__*/Schema.Struct({
|
|
|
78
79
|
confidence: Schema.Number
|
|
79
80
|
});
|
|
80
81
|
/**
|
|
81
|
-
* A zero-based rating and index-keyed distribution.
|
|
82
|
+
* A zero-based rating and index-keyed distribution. `legend` maps indices to descriptions.
|
|
82
83
|
*
|
|
83
84
|
* @stability unstable
|
|
84
85
|
* @category schemas
|
|
@@ -89,7 +90,7 @@ export const ScoreAnswer = /*#__PURE__*/Schema.Struct({
|
|
|
89
90
|
score: Schema.Number,
|
|
90
91
|
probabilities: /*#__PURE__*/Schema.Record(Schema.String, Schema.Number),
|
|
91
92
|
confidence: Schema.Number,
|
|
92
|
-
legend: /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Record(Schema.String, Schema.
|
|
93
|
+
legend: /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Record(Schema.String, Schema.Json))
|
|
93
94
|
});
|
|
94
95
|
/**
|
|
95
96
|
* A Bernoulli probability.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeSafeSchema.js","names":[],"sources":["../src/TypeSafeSchema.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;AAMA,OAAO,KAAK,MAAM,MAAM,eAAe;AAEvC;;;;;;;AAOA,OAAO,MAAM,cAAc,gBAAG,MAAM,CAAC,MAAM,CAAC;EAC1C,IAAI,eAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;EAC9B,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"TypeSafeSchema.js","names":[],"sources":["../src/TypeSafeSchema.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;AAMA,OAAO,KAAK,MAAM,MAAM,eAAe;AAEvC,MAAM,KAAK,gBAAG,MAAM,C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QAAQ,cAAC,MAAM,CAAC,MAAM,CAAC;IACnC,YAAY,eAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5C,aAAa,eAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM;GAC7C,CAAC;CACH,CAAC;AAEF;;;;;;;AAOA,OAAO,MAAM,kBAAkB,gBAAG,MAAM,CAAC,MAAM,CAAC;EAC9C,MAAM,eAAE,MAAM,CAAC,KAAK,cAAC,MAAM,CAAC,MAAM,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC,MAAM;IACnB,WAAW,eAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IAC3C,YAAY,eAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM;GAC5C,CAAC;CACH,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/internal/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/internal/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAA;AAG5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAMnE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAmCvC,eAAO,MAAM,cAAc,UAAW,MAAM,CAAC,WAAW,UAAU,MAAM,KAAG,OAAO,CAAC,OAK/E,CAAA;AAEJ,eAAO,MAAM,kBAAkB,0GA8D9B,CAAA"}
|
package/dist/internal/errors.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import * as AiError from "effect/ai/AiError";
|
|
2
|
+
import * as Clock from "effect/Clock";
|
|
2
3
|
import * as Duration from "effect/Duration";
|
|
3
4
|
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Headers from "effect/http/Headers";
|
|
4
6
|
import * as Num from "effect/Number";
|
|
5
7
|
import * as Option from "effect/Option";
|
|
6
8
|
import * as Redactable from "effect/Redactable";
|
|
9
|
+
import * as Result from "effect/Result";
|
|
7
10
|
import * as Schema from "effect/Schema";
|
|
8
11
|
const requestDetails = request => ({
|
|
9
12
|
method: request.method,
|
|
@@ -23,20 +26,20 @@ const nonNegative = value => {
|
|
|
23
26
|
const parsed = Option.getOrUndefined(Num.parse(value));
|
|
24
27
|
return parsed !== undefined && Number.isFinite(parsed) && parsed >= 0 ? parsed : undefined;
|
|
25
28
|
};
|
|
26
|
-
|
|
29
|
+
// `retry-after-ms` is TypeSafe-specific and wins over the standard header;
|
|
30
|
+
// an invalid Retry-After is treated as absent
|
|
31
|
+
const retryAfter = (headers, now) => {
|
|
27
32
|
const ms = nonNegative(headers["retry-after-ms"]);
|
|
28
33
|
if (ms !== undefined) return Duration.millis(ms);
|
|
29
34
|
const raw = headers["retry-after"];
|
|
30
|
-
if (raw === undefined
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const date = Date.parse(raw);
|
|
34
|
-
return Number.isNaN(date) ? undefined : Duration.millis(Math.max(0, date - Date.now()));
|
|
35
|
+
if (raw === undefined) return undefined;
|
|
36
|
+
const retryAfter = Headers.parseRetryAfter(raw);
|
|
37
|
+
return Result.isSuccess(retryAfter) ? Headers.retryAfterDelay(retryAfter.success, now) : undefined;
|
|
35
38
|
};
|
|
36
39
|
export const mapSchemaError = (error, method) => AiError.make({
|
|
37
40
|
module: "TypeSafeClient",
|
|
38
41
|
method,
|
|
39
|
-
reason: AiError.
|
|
42
|
+
reason: AiError.InvalidResponseError.fromSchemaError(error)
|
|
40
43
|
});
|
|
41
44
|
export const mapHttpClientError = /*#__PURE__*/Effect.fnUntraced(function* (error, method) {
|
|
42
45
|
const source = error.reason;
|
|
@@ -86,7 +89,7 @@ export const mapHttpClientError = /*#__PURE__*/Effect.fnUntraced(function* (erro
|
|
|
86
89
|
});
|
|
87
90
|
if (response.status === 429) {
|
|
88
91
|
reason = new AiError.RateLimitError({
|
|
89
|
-
retryAfter: retryAfter(response.headers),
|
|
92
|
+
retryAfter: retryAfter(response.headers, yield* Clock.currentTimeMillis),
|
|
90
93
|
http,
|
|
91
94
|
metadata: {
|
|
92
95
|
typesafe: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../../src/internal/errors.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,mBAAmB;AAC5C,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe;
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../../src/internal/errors.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,mBAAmB;AAC5C,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,OAAO,MAAM,qBAAqB;AAG9C,OAAO,KAAK,GAAG,MAAM,eAAe;AACpC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,UAAU,MAAM,mBAAmB;AAC/C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe;AAEvC,MAAM,cAAc,GAAI,OAA4C,KAAM;EACxE,MAAM,EAAE,OAAO,CAAC,MAAM;EACtB,GAAG,EAAE,OAAO,CAAC,GAAG;EAChB,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;EACxC,IAAI,EAAE,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC;EACzC,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO;CAC3C,CAAC;A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;QACvF;QACA;MACF;EACF;EACA,OAAO,OAAO,OAAO,CAAC,IAAI,CAAC;IAAE,MAAM,EAAE,gBAAgB;IAAE,MAAM;IAAE;EAAM,CAAE,CAAC;AAC1E,CAAC,CACF","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/ai-typesafe",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A TypeSafe DecisionModel provider for Effect",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"provenance": true
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"effect": "^4.0.
|
|
50
|
+
"effect": "^4.0.6"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"effect": "^4.0.
|
|
53
|
+
"effect": "^4.0.6"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"codegen": "effect-utils codegen",
|
|
@@ -56,7 +56,11 @@ export const make = Effect.fnUntraced(
|
|
|
56
56
|
questions[key] = { type: "choice", instructions: decision.instructions, criteria: decision.criteria }
|
|
57
57
|
break
|
|
58
58
|
case "Rate":
|
|
59
|
-
questions[key] = {
|
|
59
|
+
questions[key] = {
|
|
60
|
+
type: "score",
|
|
61
|
+
instructions: decision.instructions,
|
|
62
|
+
criteria: decision.criteria.map((level) => level.description)
|
|
63
|
+
}
|
|
60
64
|
break
|
|
61
65
|
case "Probability":
|
|
62
66
|
questions[key] = { type: "noul", instructions: decision.instructions, criteria: decision.criteria }
|
|
@@ -81,7 +85,7 @@ export const make = Effect.fnUntraced(
|
|
|
81
85
|
const probabilities: Record<string, number> = Object.create(null)
|
|
82
86
|
for (let index = 0; index < levels.length; index++) {
|
|
83
87
|
const probability = answer.probabilities[String(index)]
|
|
84
|
-
if (probability !== undefined) probabilities[levels[index]] = probability
|
|
88
|
+
if (probability !== undefined) probabilities[levels[index].label] = probability
|
|
85
89
|
}
|
|
86
90
|
answers[key] = { _tag: "Rate", rating: answer.score, probabilities, confidence: answer.confidence }
|
|
87
91
|
break
|
package/src/TypeSafeSchema.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import * as Schema from "effect/Schema"
|
|
8
8
|
|
|
9
|
+
const Entry = Schema.NullOr(Schema.Union([Schema.String, Schema.JsonObject, Schema.Array(Schema.Json)]))
|
|
10
|
+
|
|
9
11
|
/**
|
|
10
12
|
* A classification question.
|
|
11
13
|
*
|
|
@@ -15,8 +17,8 @@ import * as Schema from "effect/Schema"
|
|
|
15
17
|
*/
|
|
16
18
|
export const ChoiceQuestion = Schema.Struct({
|
|
17
19
|
type: Schema.Literal("choice"),
|
|
18
|
-
instructions:
|
|
19
|
-
criteria: Schema.Record(Schema.String,
|
|
20
|
+
instructions: Entry,
|
|
21
|
+
criteria: Schema.Record(Schema.String, Entry)
|
|
20
22
|
})
|
|
21
23
|
|
|
22
24
|
/**
|
|
@@ -28,8 +30,8 @@ export const ChoiceQuestion = Schema.Struct({
|
|
|
28
30
|
*/
|
|
29
31
|
export const ScoreQuestion = Schema.Struct({
|
|
30
32
|
type: Schema.Literal("score"),
|
|
31
|
-
instructions:
|
|
32
|
-
criteria: Schema.Array(
|
|
33
|
+
instructions: Entry,
|
|
34
|
+
criteria: Schema.Array(Entry)
|
|
33
35
|
})
|
|
34
36
|
|
|
35
37
|
/**
|
|
@@ -41,12 +43,12 @@ export const ScoreQuestion = Schema.Struct({
|
|
|
41
43
|
*/
|
|
42
44
|
export const NoulQuestion = Schema.Struct({
|
|
43
45
|
type: Schema.Literal("noul"),
|
|
44
|
-
instructions:
|
|
45
|
-
criteria: Schema.optional(Schema.Struct({ false:
|
|
46
|
+
instructions: Entry,
|
|
47
|
+
criteria: Schema.optional(Schema.Struct({ false: Entry, true: Entry }))
|
|
46
48
|
})
|
|
47
49
|
|
|
48
50
|
/**
|
|
49
|
-
* A System One question.
|
|
51
|
+
* A System One question with string, JSON object, JSON array, or `null` instructions and descriptions.
|
|
50
52
|
*
|
|
51
53
|
* @stability unstable
|
|
52
54
|
* @category schemas
|
|
@@ -82,7 +84,7 @@ export const ChoiceAnswer = Schema.Struct({
|
|
|
82
84
|
})
|
|
83
85
|
|
|
84
86
|
/**
|
|
85
|
-
* A zero-based rating and index-keyed distribution.
|
|
87
|
+
* A zero-based rating and index-keyed distribution. `legend` maps indices to descriptions.
|
|
86
88
|
*
|
|
87
89
|
* @stability unstable
|
|
88
90
|
* @category schemas
|
|
@@ -93,7 +95,7 @@ export const ScoreAnswer = Schema.Struct({
|
|
|
93
95
|
score: Schema.Number,
|
|
94
96
|
probabilities: Schema.Record(Schema.String, Schema.Number),
|
|
95
97
|
confidence: Schema.Number,
|
|
96
|
-
legend: Schema.optional(Schema.Record(Schema.String, Schema.
|
|
98
|
+
legend: Schema.optional(Schema.Record(Schema.String, Schema.Json))
|
|
97
99
|
})
|
|
98
100
|
|
|
99
101
|
/**
|
package/src/internal/errors.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import * as AiError from "effect/ai/AiError"
|
|
2
|
+
import * as Clock from "effect/Clock"
|
|
2
3
|
import * as Duration from "effect/Duration"
|
|
3
4
|
import * as Effect from "effect/Effect"
|
|
5
|
+
import * as Headers from "effect/http/Headers"
|
|
4
6
|
import type * as HttpClientError from "effect/http/HttpClientError"
|
|
5
7
|
import type * as HttpClientRequest from "effect/http/HttpClientRequest"
|
|
6
8
|
import * as Num from "effect/Number"
|
|
7
9
|
import * as Option from "effect/Option"
|
|
8
10
|
import * as Redactable from "effect/Redactable"
|
|
11
|
+
import * as Result from "effect/Result"
|
|
9
12
|
import * as Schema from "effect/Schema"
|
|
10
13
|
|
|
11
14
|
const requestDetails = (request: HttpClientRequest.HttpClientRequest) => ({
|
|
@@ -30,22 +33,22 @@ const nonNegative = (value: string | undefined): number | undefined => {
|
|
|
30
33
|
return parsed !== undefined && Number.isFinite(parsed) && parsed >= 0 ? parsed : undefined
|
|
31
34
|
}
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
// `retry-after-ms` is TypeSafe-specific and wins over the standard header;
|
|
37
|
+
// an invalid Retry-After is treated as absent
|
|
38
|
+
const retryAfter = (headers: Readonly<Record<string, string>>, now: number) => {
|
|
34
39
|
const ms = nonNegative(headers["retry-after-ms"])
|
|
35
40
|
if (ms !== undefined) return Duration.millis(ms)
|
|
36
41
|
const raw = headers["retry-after"]
|
|
37
|
-
if (raw === undefined
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
const date = Date.parse(raw)
|
|
41
|
-
return Number.isNaN(date) ? undefined : Duration.millis(Math.max(0, date - Date.now()))
|
|
42
|
+
if (raw === undefined) return undefined
|
|
43
|
+
const retryAfter = Headers.parseRetryAfter(raw)
|
|
44
|
+
return Result.isSuccess(retryAfter) ? Headers.retryAfterDelay(retryAfter.success, now) : undefined
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
export const mapSchemaError = (error: Schema.SchemaError, method: string): AiError.AiError =>
|
|
45
48
|
AiError.make({
|
|
46
49
|
module: "TypeSafeClient",
|
|
47
50
|
method,
|
|
48
|
-
reason: AiError.
|
|
51
|
+
reason: AiError.InvalidResponseError.fromSchemaError(error)
|
|
49
52
|
})
|
|
50
53
|
|
|
51
54
|
export const mapHttpClientError = Effect.fnUntraced(
|
|
@@ -90,7 +93,7 @@ export const mapHttpClientError = Effect.fnUntraced(
|
|
|
90
93
|
})
|
|
91
94
|
if (response.status === 429) {
|
|
92
95
|
reason = new AiError.RateLimitError({
|
|
93
|
-
retryAfter: retryAfter(response.headers),
|
|
96
|
+
retryAfter: retryAfter(response.headers, yield* Clock.currentTimeMillis),
|
|
94
97
|
http,
|
|
95
98
|
metadata: {
|
|
96
99
|
typesafe: {
|