@effect/ai-typesafe 4.0.7 → 4.1.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/README.md +53 -2
- package/dist/TypeSafeClient.d.ts +4 -0
- package/dist/TypeSafeClient.d.ts.map +1 -1
- package/dist/TypeSafeClient.js +7 -1
- package/dist/TypeSafeClient.js.map +1 -1
- package/dist/TypeSafeDecisionModel.d.ts +16 -7
- package/dist/TypeSafeDecisionModel.d.ts.map +1 -1
- package/dist/TypeSafeDecisionModel.js +88 -2
- package/dist/TypeSafeDecisionModel.js.map +1 -1
- package/dist/TypeSafeSchema.d.ts +74 -1
- package/dist/TypeSafeSchema.d.ts.map +1 -1
- package/dist/TypeSafeSchema.js +49 -4
- package/dist/TypeSafeSchema.js.map +1 -1
- package/dist/internal/errors.d.ts.map +1 -1
- package/dist/internal/errors.js +1 -13
- package/dist/internal/errors.js.map +1 -1
- package/package.json +3 -3
- package/src/TypeSafeClient.ts +14 -1
- package/src/TypeSafeDecisionModel.ts +72 -3
- package/src/TypeSafeSchema.ts +47 -4
- package/src/internal/errors.ts +3 -15
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @effect/ai-typesafe
|
|
2
2
|
|
|
3
|
-
TypeSafe System One provider for Effect's `DecisionModel`. Supports classification, ordered ratings, and
|
|
3
|
+
TypeSafe System One provider for Effect's `DecisionModel`. Supports classification, ordered ratings, probabilities, images, and locating things in images through Effect `HttpClient`.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -26,7 +26,7 @@ Whether your team is considering Effect, rolling it out, or already running it i
|
|
|
26
26
|
|
|
27
27
|
## Usage
|
|
28
28
|
|
|
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.
|
|
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.14.0` are also supported.
|
|
30
30
|
|
|
31
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
32
|
|
|
@@ -43,4 +43,55 @@ const severity = Decision.rate({
|
|
|
43
43
|
})
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
### Images
|
|
47
|
+
|
|
48
|
+
Declare images as input fields with `Decision.Image`, and refer to them by path in instructions like any other field. TypeSafe's [image support](https://docs.typesafe.ai/images) is a preview, and the provider sends the `TypeSafe-Danger-Zone-Images: true` header for you. Each image is sent once as an asset, and the state holds its reference where the image was.
|
|
49
|
+
|
|
50
|
+
`Decision.locate` asks where something is in one image field, as a TypeSafe [Box](https://docs.typesafe.ai/primitives/box) question. It needs Jev 1.14 (`jev-preview` or `jev-1.14.0`). The answer is a bounding box whose edges are fractions of the image's width and height. A box comes back even when the target is absent, so ask whether it is there too:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { Schema } from "effect"
|
|
54
|
+
import { Decision, DecisionModel } from "effect/ai"
|
|
55
|
+
|
|
56
|
+
const FindMug = Decision.make({
|
|
57
|
+
input: Schema.Struct({ caption: Schema.String, photo: Decision.Image }),
|
|
58
|
+
decisions: {
|
|
59
|
+
present: Decision.probability({ instructions: "`photo` shows a coffee mug" }),
|
|
60
|
+
mug: Decision.locate({ image: "photo", instructions: "the coffee mug" })
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const program = DecisionModel.decide(FindMug, {
|
|
65
|
+
input: { caption: "Kitchen counter, morning", photo: { mediaType: "image/jpeg", data: photoBytes } }
|
|
66
|
+
})
|
|
67
|
+
// answers.mug.box: { left: 0.44, top: 0.25, right: 0.84, bottom: 0.82 }
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
To define options by example pictures, add the examples as image fields too and refer to them by path. Each image is sent once, however many questions use it:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
const Gesture = Decision.make({
|
|
74
|
+
input: Schema.Struct({
|
|
75
|
+
frame: Decision.Image,
|
|
76
|
+
examples: Schema.Struct({ thumbsUp: Decision.Image, openPalm: Decision.Image })
|
|
77
|
+
}),
|
|
78
|
+
decisions: {
|
|
79
|
+
gesture: Decision.classify({
|
|
80
|
+
instructions: "Which gesture is the hand in `frame` making?",
|
|
81
|
+
criteria: {
|
|
82
|
+
thumbs_up: "The gesture in `examples.thumbsUp`",
|
|
83
|
+
open_palm: "The gesture in `examples.openPalm`",
|
|
84
|
+
none: "No hand, or a gesture unlike the examples"
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
DecisionModel.decide(Gesture, {
|
|
91
|
+
input: { frame, examples: { thumbsUp: thumbsUpExample, openPalm: openPalmExample } }
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Image `data` may be a `Uint8Array`, a base64 string, or a base64 `data:` URL. Images must be PNG or JPEG, 256 to 1568 pixels on each side; TypeSafe rejects other sizes rather than resizing and ignores EXIF orientation. Remote URLs fail with `AiError.InvalidUserInputError` because TypeSafe does not fetch them.
|
|
96
|
+
|
|
46
97
|
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/dist/TypeSafeClient.d.ts
CHANGED
|
@@ -21,6 +21,10 @@ import * as TypeSafeSchema from "./TypeSafeSchema.ts";
|
|
|
21
21
|
*/
|
|
22
22
|
export interface Service {
|
|
23
23
|
readonly client: HttpClient.HttpClient;
|
|
24
|
+
/**
|
|
25
|
+
* Sends `TypeSafe-Danger-Zone-Images: true` when the request has assets or a
|
|
26
|
+
* Box question.
|
|
27
|
+
*/
|
|
24
28
|
readonly systemOne: (request: typeof TypeSafeSchema.SystemOneRequest.Encoded) => Effect.Effect<typeof TypeSafeSchema.SystemOneResponse.Type, AiError.AiError>;
|
|
25
29
|
readonly listModels: () => Effect.Effect<typeof TypeSafeSchema.ListModelsResponse.Type, AiError.AiError>;
|
|
26
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeSafeClient.d.ts","sourceRoot":"","sources":["../src/TypeSafeClient.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAA;AAIpD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAI3C,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;;;;;GAMG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,CAAA;IACtC,QAAQ,CAAC,SAAS,EAAE,CAClB,OAAO,EAAE,OAAO,cAAc,CAAC,gBAAgB,CAAC,OAAO,KACpD,MAAM,CAAC,MAAM,CAAC,OAAO,cAAc,CAAC,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IACjF,QAAQ,CAAC,UAAU,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,cAAc,CAAC,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;CACzG;;AAED;;;;;;GAMG;AACH,qBAAa,cAAe,SAAQ,mBAAgF;CAAG;AAEvH;;;;;;GAMG;AACH,MAAM,WAAW,OAA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SAAQ,mBAAgF;CAAG;AAEvH;;;;;;GAMG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAA;IACvD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,KAAK,UAAU,CAAC,UAAU,CAAC,GAAG,SAAS,CAAA;CAClG;AAWD;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,4EAkDhB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,YAAa,OAAO,KAAG,KAAK,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,EAAE,UAAU,CAAC,UAAU,CACpD,CAAA;AAE7C;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,aAAc;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,GAAG,SAAS,CAAA;IAClF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,SAAS,CAAA;IACnD,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,KAAK,UAAU,CAAC,UAAU,CAAC,GAAG,SAAS,CAAA;CAClG,KAAG,KAAK,CAAC,KAAK,CAAC,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,UAAU,CAUtE,CAAA"}
|
package/dist/TypeSafeClient.js
CHANGED
|
@@ -26,6 +26,10 @@ import * as TypeSafeSchema from "./TypeSafeSchema.js";
|
|
|
26
26
|
*/
|
|
27
27
|
export class TypeSafeClient extends /*#__PURE__*/Context.Service()("@effect/ai-typesafe/TypeSafeClient") {}
|
|
28
28
|
const decodeSystemOne = /*#__PURE__*/HttpClientResponse.schemaBodyJson(TypeSafeSchema.SystemOneResponse);
|
|
29
|
+
const imagesHeader = {
|
|
30
|
+
"TypeSafe-Danger-Zone-Images": "true"
|
|
31
|
+
};
|
|
32
|
+
const usesImages = request => request.assets !== undefined || Object.values(request.questions).some(question => question.type === "box");
|
|
29
33
|
const decodeListModels = /*#__PURE__*/HttpClientResponse.schemaBodyJson(TypeSafeSchema.ListModelsResponse);
|
|
30
34
|
/**
|
|
31
35
|
* Builds a client without automatic retries. Scoped transforms run after the constructor transform.
|
|
@@ -44,7 +48,9 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
|
44
48
|
}));
|
|
45
49
|
return TypeSafeClient.of({
|
|
46
50
|
client,
|
|
47
|
-
systemOne: payload => HttpClientRequest.bodyJson(HttpClientRequest.post("/systemone"
|
|
51
|
+
systemOne: payload => HttpClientRequest.bodyJson(HttpClientRequest.post("/systemone", usesImages(payload) ? {
|
|
52
|
+
headers: imagesHeader
|
|
53
|
+
} : undefined), payload).pipe(Effect.mapError(error => AiError.make({
|
|
48
54
|
module: "TypeSafeClient",
|
|
49
55
|
method: "systemOne",
|
|
50
56
|
reason: new AiError.InvalidRequestError({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeSafeClient.js","names":[],"sources":["../src/TypeSafeClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;AAMA,OAAO,KAAK,OAAO,MAAM,mBAAmB;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,SAAS,IAAI,EAAE,QAAQ,QAAQ,iBAAiB;AAChD,OAAO,KAAK,UAAU,MAAM,wBAAwB;AAEpD,OAAO,KAAK,iBAAiB,MAAM,+BAA+B;AAClE,OAAO,KAAK,kBAAkB,MAAM,gCAAgC;AACpE,OAAO,KA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
3
|
-
*
|
|
4
|
-
* @stability unstable
|
|
5
|
-
* @since 4.0.0
|
|
6
|
-
*/
|
|
7
1
|
import * as DecisionModel from "effect/ai/DecisionModel";
|
|
8
2
|
import * as AiModel from "effect/ai/Model";
|
|
9
3
|
import * as Effect from "effect/Effect";
|
|
@@ -16,7 +10,7 @@ import { TypeSafeClient } from "./TypeSafeClient.ts";
|
|
|
16
10
|
* @category models
|
|
17
11
|
* @since 4.0.0
|
|
18
12
|
*/
|
|
19
|
-
export type Model = "jev-latest" | "jev-preview" | "jev-1.13.0";
|
|
13
|
+
export type Model = "jev-latest" | "jev-preview" | "jev-1.13.0" | "jev-1.14.0";
|
|
20
14
|
/**
|
|
21
15
|
* Creates a decision model with TypeSafe provider metadata.
|
|
22
16
|
*
|
|
@@ -30,6 +24,21 @@ export declare const model: (model: Model | (string & {})) => AiModel.Model<"typ
|
|
|
30
24
|
* DecisionModel rescales small sum drift when it validates distributions and
|
|
31
25
|
* derives rating labels.
|
|
32
26
|
*
|
|
27
|
+
* **Details**
|
|
28
|
+
*
|
|
29
|
+
* Each `Decision.Image` field is sent as a base64 asset keyed by the reference
|
|
30
|
+
* that replaces it in `state`, so instructions name an image by its field path,
|
|
31
|
+
* such as `` `photo` ``. Requests with images opt in to TypeSafe's preview image
|
|
32
|
+
* support. Locate decisions become Box questions whose instructions end with
|
|
33
|
+
* the image path; they need Jev 1.14 (`"jev-preview"` or `"jev-1.14.0"`).
|
|
34
|
+
*
|
|
35
|
+
* **Gotchas**
|
|
36
|
+
*
|
|
37
|
+
* - Images must be PNG or JPEG, 256 to 1568 pixels on each side. The API
|
|
38
|
+
* rejects other sizes rather than resizing, and ignores EXIF orientation.
|
|
39
|
+
* - Remote URLs fail with `AiError.InvalidUserInputError` because TypeSafe
|
|
40
|
+
* does not fetch them.
|
|
41
|
+
*
|
|
33
42
|
* @stability unstable
|
|
34
43
|
* @category constructors
|
|
35
44
|
* @since 4.0.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeSafeDecisionModel.d.ts","sourceRoot":"","sources":["../src/TypeSafeDecisionModel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TypeSafeDecisionModel.d.ts","sourceRoot":"","sources":["../src/TypeSafeDecisionModel.ts"],"names":[],"mappings":"AAOA,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,GAAG,YAAY,CAAA;AAE9E;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,IAAI;oBAEc,KAAK,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;uEA8EnD,CAAA;AAoCD;;;;;;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"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @stability unstable
|
|
5
5
|
* @since 4.0.0
|
|
6
6
|
*/
|
|
7
|
+
import * as AiError from "effect/ai/AiError";
|
|
7
8
|
import * as DecisionModel from "effect/ai/DecisionModel";
|
|
8
9
|
import * as AiModel from "effect/ai/Model";
|
|
9
10
|
import * as Effect from "effect/Effect";
|
|
@@ -24,6 +25,21 @@ export const model = model => AiModel.make("typesafe", model, layer({
|
|
|
24
25
|
* DecisionModel rescales small sum drift when it validates distributions and
|
|
25
26
|
* derives rating labels.
|
|
26
27
|
*
|
|
28
|
+
* **Details**
|
|
29
|
+
*
|
|
30
|
+
* Each `Decision.Image` field is sent as a base64 asset keyed by the reference
|
|
31
|
+
* that replaces it in `state`, so instructions name an image by its field path,
|
|
32
|
+
* such as `` `photo` ``. Requests with images opt in to TypeSafe's preview image
|
|
33
|
+
* support. Locate decisions become Box questions whose instructions end with
|
|
34
|
+
* the image path; they need Jev 1.14 (`"jev-preview"` or `"jev-1.14.0"`).
|
|
35
|
+
*
|
|
36
|
+
* **Gotchas**
|
|
37
|
+
*
|
|
38
|
+
* - Images must be PNG or JPEG, 256 to 1568 pixels on each side. The API
|
|
39
|
+
* rejects other sizes rather than resizing, and ignores EXIF orientation.
|
|
40
|
+
* - Remote URLs fail with `AiError.InvalidUserInputError` because TypeSafe
|
|
41
|
+
* does not fetch them.
|
|
42
|
+
*
|
|
27
43
|
* @stability unstable
|
|
28
44
|
* @category constructors
|
|
29
45
|
* @since 4.0.0
|
|
@@ -32,9 +48,12 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
|
32
48
|
const client = yield* TypeSafeClient;
|
|
33
49
|
return yield* DecisionModel.make({
|
|
34
50
|
probabilityPrecision: 2,
|
|
51
|
+
supportsImages: true,
|
|
52
|
+
supportsLocate: true,
|
|
35
53
|
decide: Effect.fnUntraced(function* ({
|
|
36
54
|
state,
|
|
37
|
-
decisions
|
|
55
|
+
decisions,
|
|
56
|
+
images
|
|
38
57
|
}) {
|
|
39
58
|
const questions = Object.create(null);
|
|
40
59
|
for (const [key, decision] of Object.entries(decisions)) {
|
|
@@ -60,12 +79,30 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
|
60
79
|
criteria: decision.criteria
|
|
61
80
|
};
|
|
62
81
|
break;
|
|
82
|
+
case "Locate":
|
|
83
|
+
questions[key] = {
|
|
84
|
+
type: "box",
|
|
85
|
+
instructions: `${decision.instructions} in \`${decision.image}\``
|
|
86
|
+
};
|
|
87
|
+
break;
|
|
63
88
|
}
|
|
64
89
|
}
|
|
90
|
+
const assets = Object.create(null);
|
|
91
|
+
for (const {
|
|
92
|
+
reference,
|
|
93
|
+
image
|
|
94
|
+
} of images ?? []) {
|
|
95
|
+
const asset = encodeImage(image);
|
|
96
|
+
if (AiError.isAiError(asset)) return yield* Effect.fail(asset);
|
|
97
|
+
assets[reference] = asset;
|
|
98
|
+
}
|
|
65
99
|
const response = yield* client.systemOne({
|
|
66
100
|
model: options.model,
|
|
67
101
|
state,
|
|
68
|
-
questions
|
|
102
|
+
questions,
|
|
103
|
+
...(images === undefined ? undefined : {
|
|
104
|
+
assets
|
|
105
|
+
})
|
|
69
106
|
});
|
|
70
107
|
const answers = Object.create(null);
|
|
71
108
|
for (const [key, decision] of Object.entries(decisions)) {
|
|
@@ -101,6 +138,13 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
|
101
138
|
probability: answer.noul
|
|
102
139
|
};
|
|
103
140
|
break;
|
|
141
|
+
case "box":
|
|
142
|
+
answers[key] = {
|
|
143
|
+
_tag: "Locate",
|
|
144
|
+
box: answer.box,
|
|
145
|
+
confidence: answer.confidence
|
|
146
|
+
};
|
|
147
|
+
break;
|
|
104
148
|
}
|
|
105
149
|
}
|
|
106
150
|
return {
|
|
@@ -113,6 +157,48 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
|
113
157
|
})
|
|
114
158
|
});
|
|
115
159
|
});
|
|
160
|
+
const encodeImage = image => {
|
|
161
|
+
let {
|
|
162
|
+
data,
|
|
163
|
+
mediaType
|
|
164
|
+
} = image;
|
|
165
|
+
if (data instanceof URL) {
|
|
166
|
+
const match = /^data:([^,;]*)[^,]*;base64,(.*)$/si.exec(data.href.split("#", 1)[0]);
|
|
167
|
+
if (match === null) {
|
|
168
|
+
return invalidUserInput("TypeSafe accepts bytes, base64 strings, or base64 data URLs; it does not fetch URLs");
|
|
169
|
+
}
|
|
170
|
+
mediaType = match[1] || mediaType;
|
|
171
|
+
try {
|
|
172
|
+
data = decodeURIComponent(match[2]);
|
|
173
|
+
} catch {
|
|
174
|
+
return invalidUserInput("TypeSafe image data URLs must contain valid percent-encoding");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
switch (mediaType.toLowerCase()) {
|
|
178
|
+
case "image/png":
|
|
179
|
+
return {
|
|
180
|
+
type: "image",
|
|
181
|
+
format: "png",
|
|
182
|
+
data_base64: data
|
|
183
|
+
};
|
|
184
|
+
case "image/jpeg":
|
|
185
|
+
case "image/jpg":
|
|
186
|
+
return {
|
|
187
|
+
type: "image",
|
|
188
|
+
format: "jpg",
|
|
189
|
+
data_base64: data
|
|
190
|
+
};
|
|
191
|
+
default:
|
|
192
|
+
return invalidUserInput(`TypeSafe accepts PNG or JPEG images, not ${mediaType}`);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const invalidUserInput = description => AiError.make({
|
|
196
|
+
module: "TypeSafeDecisionModel",
|
|
197
|
+
method: "decide",
|
|
198
|
+
reason: new AiError.InvalidUserInputError({
|
|
199
|
+
description
|
|
200
|
+
})
|
|
201
|
+
});
|
|
116
202
|
/**
|
|
117
203
|
* Provides DecisionModel using an existing TypeSafeClient.
|
|
118
204
|
*
|
|
@@ -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;;;;;;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M,EAAE,uBAAuB;EAC/B,MAAM,EAAE,QAAQ;EAChB,MAAM,EAAE,IAAI,OAAO,CAAC,qBAAqB,CAAC;IAAE;EAAW,CAAE;CAC1D,CAAC;AAEJ;;;;;;;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
|
@@ -44,6 +44,18 @@ export declare const NoulQuestion: Schema.Struct<{
|
|
|
44
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
|
+
/**
|
|
48
|
+
* A question that finds where something is in an image. Needs Jev 1.14 and
|
|
49
|
+
* the `TypeSafe-Danger-Zone-Images: true` header.
|
|
50
|
+
*
|
|
51
|
+
* @stability unstable
|
|
52
|
+
* @category schemas
|
|
53
|
+
* @since 4.1.0
|
|
54
|
+
*/
|
|
55
|
+
export declare const BoxQuestion: Schema.Struct<{
|
|
56
|
+
readonly type: Schema.Literal<"box">;
|
|
57
|
+
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>>]>>;
|
|
58
|
+
}>;
|
|
47
59
|
/**
|
|
48
60
|
* A System One question with string, JSON object, JSON array, or `null` instructions and descriptions.
|
|
49
61
|
*
|
|
@@ -66,9 +78,27 @@ export declare const Question: Schema.Union<readonly [Schema.Struct<{
|
|
|
66
78
|
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
79
|
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
80
|
}>>;
|
|
81
|
+
}>, Schema.Struct<{
|
|
82
|
+
readonly type: Schema.Literal<"box">;
|
|
83
|
+
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>>]>>;
|
|
69
84
|
}>]>;
|
|
70
85
|
/**
|
|
71
|
-
* A
|
|
86
|
+
* A base64-encoded PNG or JPEG image. Standard alphabet with `=` padding, no
|
|
87
|
+
* whitespace, and no `data:` prefix.
|
|
88
|
+
*
|
|
89
|
+
* @stability unstable
|
|
90
|
+
* @category schemas
|
|
91
|
+
* @since 4.1.0
|
|
92
|
+
*/
|
|
93
|
+
export declare const ImageAsset: Schema.Struct<{
|
|
94
|
+
readonly type: Schema.optional<Schema.Literal<"image">>;
|
|
95
|
+
readonly format: Schema.Literals<readonly ["png", "jpg", "jpeg"]>;
|
|
96
|
+
readonly data_base64: Schema.String;
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* A batch of questions against encoded state. `assets` maps placeholder
|
|
100
|
+
* strings to images; the model sees each image wherever its placeholder
|
|
101
|
+
* appears in `state`, `instructions`, or `criteria`.
|
|
72
102
|
*
|
|
73
103
|
* @stability unstable
|
|
74
104
|
* @category schemas
|
|
@@ -92,7 +122,15 @@ export declare const SystemOneRequest: Schema.Struct<{
|
|
|
92
122
|
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
123
|
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
124
|
}>>;
|
|
125
|
+
}>, Schema.Struct<{
|
|
126
|
+
readonly type: Schema.Literal<"box">;
|
|
127
|
+
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>>]>>;
|
|
95
128
|
}>]>>;
|
|
129
|
+
readonly assets: Schema.optional<Schema.$Record<Schema.String, Schema.Struct<{
|
|
130
|
+
readonly type: Schema.optional<Schema.Literal<"image">>;
|
|
131
|
+
readonly format: Schema.Literals<readonly ["png", "jpg", "jpeg"]>;
|
|
132
|
+
readonly data_base64: Schema.String;
|
|
133
|
+
}>>>;
|
|
96
134
|
}>;
|
|
97
135
|
/**
|
|
98
136
|
* A classification distribution.
|
|
@@ -132,6 +170,23 @@ export declare const NoulAnswer: Schema.Struct<{
|
|
|
132
170
|
readonly type: Schema.Literal<"noul">;
|
|
133
171
|
readonly noul: Schema.Number;
|
|
134
172
|
}>;
|
|
173
|
+
/**
|
|
174
|
+
* A bounding box whose edges are fractions of the image's width and height.
|
|
175
|
+
*
|
|
176
|
+
* @stability unstable
|
|
177
|
+
* @category schemas
|
|
178
|
+
* @since 4.1.0
|
|
179
|
+
*/
|
|
180
|
+
export declare const BoxAnswer: Schema.Struct<{
|
|
181
|
+
readonly type: Schema.Literal<"box">;
|
|
182
|
+
readonly box: Schema.Struct<{
|
|
183
|
+
readonly top: Schema.Number;
|
|
184
|
+
readonly bottom: Schema.Number;
|
|
185
|
+
readonly left: Schema.Number;
|
|
186
|
+
readonly right: Schema.Number;
|
|
187
|
+
}>;
|
|
188
|
+
readonly confidence: Schema.Number;
|
|
189
|
+
}>;
|
|
135
190
|
/**
|
|
136
191
|
* A System One answer.
|
|
137
192
|
*
|
|
@@ -153,6 +208,15 @@ export declare const Answer: Schema.Union<readonly [Schema.Struct<{
|
|
|
153
208
|
}>, Schema.Struct<{
|
|
154
209
|
readonly type: Schema.Literal<"noul">;
|
|
155
210
|
readonly noul: Schema.Number;
|
|
211
|
+
}>, Schema.Struct<{
|
|
212
|
+
readonly type: Schema.Literal<"box">;
|
|
213
|
+
readonly box: Schema.Struct<{
|
|
214
|
+
readonly top: Schema.Number;
|
|
215
|
+
readonly bottom: Schema.Number;
|
|
216
|
+
readonly left: Schema.Number;
|
|
217
|
+
readonly right: Schema.Number;
|
|
218
|
+
}>;
|
|
219
|
+
readonly confidence: Schema.Number;
|
|
156
220
|
}>]>;
|
|
157
221
|
/**
|
|
158
222
|
* Answers and token usage for a batch.
|
|
@@ -177,6 +241,15 @@ export declare const SystemOneResponse: Schema.Struct<{
|
|
|
177
241
|
}>, Schema.Struct<{
|
|
178
242
|
readonly type: Schema.Literal<"noul">;
|
|
179
243
|
readonly noul: Schema.Number;
|
|
244
|
+
}>, Schema.Struct<{
|
|
245
|
+
readonly type: Schema.Literal<"box">;
|
|
246
|
+
readonly box: Schema.Struct<{
|
|
247
|
+
readonly top: Schema.Number;
|
|
248
|
+
readonly bottom: Schema.Number;
|
|
249
|
+
readonly left: Schema.Number;
|
|
250
|
+
readonly right: Schema.Number;
|
|
251
|
+
}>;
|
|
252
|
+
readonly confidence: Schema.Number;
|
|
180
253
|
}>]>>;
|
|
181
254
|
readonly usage: Schema.optional<Schema.Struct<{
|
|
182
255
|
readonly input_tokens: Schema.optional<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;AAIvC;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;;EAIzB,CAAA;AAEF;;;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B,CAAA"}
|
package/dist/TypeSafeSchema.js
CHANGED
|
@@ -45,6 +45,18 @@ export const NoulQuestion = /*#__PURE__*/Schema.Struct({
|
|
|
45
45
|
true: Entry
|
|
46
46
|
}))
|
|
47
47
|
});
|
|
48
|
+
/**
|
|
49
|
+
* A question that finds where something is in an image. Needs Jev 1.14 and
|
|
50
|
+
* the `TypeSafe-Danger-Zone-Images: true` header.
|
|
51
|
+
*
|
|
52
|
+
* @stability unstable
|
|
53
|
+
* @category schemas
|
|
54
|
+
* @since 4.1.0
|
|
55
|
+
*/
|
|
56
|
+
export const BoxQuestion = /*#__PURE__*/Schema.Struct({
|
|
57
|
+
type: /*#__PURE__*/Schema.Literal("box"),
|
|
58
|
+
instructions: Entry
|
|
59
|
+
});
|
|
48
60
|
/**
|
|
49
61
|
* A System One question with string, JSON object, JSON array, or `null` instructions and descriptions.
|
|
50
62
|
*
|
|
@@ -52,9 +64,24 @@ export const NoulQuestion = /*#__PURE__*/Schema.Struct({
|
|
|
52
64
|
* @category schemas
|
|
53
65
|
* @since 4.0.0
|
|
54
66
|
*/
|
|
55
|
-
export const Question = /*#__PURE__*/Schema.Union([ChoiceQuestion, ScoreQuestion, NoulQuestion]);
|
|
67
|
+
export const Question = /*#__PURE__*/Schema.Union([ChoiceQuestion, ScoreQuestion, NoulQuestion, BoxQuestion]);
|
|
56
68
|
/**
|
|
57
|
-
* A
|
|
69
|
+
* A base64-encoded PNG or JPEG image. Standard alphabet with `=` padding, no
|
|
70
|
+
* whitespace, and no `data:` prefix.
|
|
71
|
+
*
|
|
72
|
+
* @stability unstable
|
|
73
|
+
* @category schemas
|
|
74
|
+
* @since 4.1.0
|
|
75
|
+
*/
|
|
76
|
+
export const ImageAsset = /*#__PURE__*/Schema.Struct({
|
|
77
|
+
type: /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Literal("image")),
|
|
78
|
+
format: /*#__PURE__*/Schema.Literals(["png", "jpg", "jpeg"]),
|
|
79
|
+
data_base64: Schema.String
|
|
80
|
+
});
|
|
81
|
+
/**
|
|
82
|
+
* A batch of questions against encoded state. `assets` maps placeholder
|
|
83
|
+
* strings to images; the model sees each image wherever its placeholder
|
|
84
|
+
* appears in `state`, `instructions`, or `criteria`.
|
|
58
85
|
*
|
|
59
86
|
* @stability unstable
|
|
60
87
|
* @category schemas
|
|
@@ -63,7 +90,8 @@ export const Question = /*#__PURE__*/Schema.Union([ChoiceQuestion, ScoreQuestion
|
|
|
63
90
|
export const SystemOneRequest = /*#__PURE__*/Schema.Struct({
|
|
64
91
|
model: Schema.String,
|
|
65
92
|
state: Schema.Json,
|
|
66
|
-
questions: /*#__PURE__*/Schema.Record(Schema.String, Question)
|
|
93
|
+
questions: /*#__PURE__*/Schema.Record(Schema.String, Question),
|
|
94
|
+
assets: /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Record(Schema.String, ImageAsset))
|
|
67
95
|
});
|
|
68
96
|
/**
|
|
69
97
|
* A classification distribution.
|
|
@@ -103,6 +131,23 @@ export const NoulAnswer = /*#__PURE__*/Schema.Struct({
|
|
|
103
131
|
type: /*#__PURE__*/Schema.Literal("noul"),
|
|
104
132
|
noul: Schema.Number
|
|
105
133
|
});
|
|
134
|
+
/**
|
|
135
|
+
* A bounding box whose edges are fractions of the image's width and height.
|
|
136
|
+
*
|
|
137
|
+
* @stability unstable
|
|
138
|
+
* @category schemas
|
|
139
|
+
* @since 4.1.0
|
|
140
|
+
*/
|
|
141
|
+
export const BoxAnswer = /*#__PURE__*/Schema.Struct({
|
|
142
|
+
type: /*#__PURE__*/Schema.Literal("box"),
|
|
143
|
+
box: /*#__PURE__*/Schema.Struct({
|
|
144
|
+
top: Schema.Number,
|
|
145
|
+
bottom: Schema.Number,
|
|
146
|
+
left: Schema.Number,
|
|
147
|
+
right: Schema.Number
|
|
148
|
+
}),
|
|
149
|
+
confidence: Schema.Number
|
|
150
|
+
});
|
|
106
151
|
/**
|
|
107
152
|
* A System One answer.
|
|
108
153
|
*
|
|
@@ -110,7 +155,7 @@ export const NoulAnswer = /*#__PURE__*/Schema.Struct({
|
|
|
110
155
|
* @category schemas
|
|
111
156
|
* @since 4.0.0
|
|
112
157
|
*/
|
|
113
|
-
export const Answer = /*#__PURE__*/Schema.Union([ChoiceAnswer, ScoreAnswer, NoulAnswer]);
|
|
158
|
+
export const Answer = /*#__PURE__*/Schema.Union([ChoiceAnswer, ScoreAnswer, NoulAnswer, BoxAnswer]);
|
|
114
159
|
/**
|
|
115
160
|
* Answers and token usage for a batch.
|
|
116
161
|
*
|
|
@@ -1 +1 @@
|
|
|
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,CAAC,MAAM,cAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,eAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAExG;;;;;;;AAOA,OAAO,MAAM,cAAc,gBAAG,MAAM,CAAC,MAAM,CAAC;EAC1C,IAAI,eAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;EAC9B,YAAY,EAAE,KAAK;EACnB,QAAQ,eAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK;CAC7C,CAAC;AAEF;;;;;;;AAOA,OAAO,MAAM,aAAa,gBAAG,MAAM,CAAC,MAAM,CAAC;EACzC,IAAI,eAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;EAC7B,YAAY,EAAE,KAAK;EACnB,QAAQ,eAAE,MAAM,CAAC,KAAK,CAAC,KAAK;CAC7B,CAAC;AAEF;;;;;;;AAOA,OAAO,MAAM,YAAY,gBAAG,MAAM,CAAC,MAAM,CAAC;EACxC,IAAI,eAAE,MAAM,CAAC,OAA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AAM,iBAAiB,gBAAG,MAAM,CAAC,MAAM,CAAC;EAC7C,KAAK,EAAE,MAAM,CAAC,MAAM;EACpB,OAAO,eAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;EAC7C,KAAK,eAAE,MAAM,CAAC,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;AAG5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,eAAe,MAAM,6BAA6B,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;AAKnE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AA2BvC,eAAO,MAAM,cAAc,UAAW,MAAM,CAAC,WAAW,UAAU,MAAM,KAAG,OAAO,CAAC,OAK/E,CAAA;AAEJ,eAAO,MAAM,kBAAkB,0GA2D9B,CAAA"}
|
package/dist/internal/errors.js
CHANGED
|
@@ -8,13 +8,6 @@ import * as Option from "effect/Option";
|
|
|
8
8
|
import * as Redactable from "effect/Redactable";
|
|
9
9
|
import * as Result from "effect/Result";
|
|
10
10
|
import * as Schema from "effect/Schema";
|
|
11
|
-
const requestDetails = request => ({
|
|
12
|
-
method: request.method,
|
|
13
|
-
url: request.url,
|
|
14
|
-
urlParams: Array.from(request.urlParams),
|
|
15
|
-
hash: Option.getOrUndefined(request.hash),
|
|
16
|
-
headers: Redactable.redact(request.headers)
|
|
17
|
-
});
|
|
18
11
|
const ErrorBody = /*#__PURE__*/Schema.Struct({
|
|
19
12
|
message: /*#__PURE__*/Schema.optional(Schema.String),
|
|
20
13
|
type: /*#__PURE__*/Schema.optional(Schema.String),
|
|
@@ -48,11 +41,7 @@ export const mapHttpClientError = /*#__PURE__*/Effect.fnUntraced(function* (erro
|
|
|
48
41
|
case "TransportError":
|
|
49
42
|
case "EncodeError":
|
|
50
43
|
case "InvalidUrlError":
|
|
51
|
-
reason =
|
|
52
|
-
reason: source._tag,
|
|
53
|
-
description: source.description,
|
|
54
|
-
request: requestDetails(source.request)
|
|
55
|
-
});
|
|
44
|
+
reason = AiError.NetworkError.fromHttpClientError(error);
|
|
56
45
|
break;
|
|
57
46
|
case "DecodeError":
|
|
58
47
|
case "EmptyBodyError":
|
|
@@ -70,7 +59,6 @@ export const mapHttpClientError = /*#__PURE__*/Effect.fnUntraced(function* (erro
|
|
|
70
59
|
const parsed = yield* Effect.try(() => JSON.parse(body ?? "")).pipe(Effect.orElseSucceed(() => undefined));
|
|
71
60
|
const details = Option.getOrUndefined(decodeErrorBody(parsed));
|
|
72
61
|
const http = {
|
|
73
|
-
request: requestDetails(request),
|
|
74
62
|
response: {
|
|
75
63
|
status: response.status,
|
|
76
64
|
headers: Redactable.redact(response.headers)
|
|
@@ -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,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,OAAO,MAAM,qBAAqB;
|
|
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;AAE9C,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,SAAS,gBAAG,MAAM,CAAC,MAAM,CAAC;EAC9B,OAAO,eAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;EACvC,IAAI,eAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;EACpC,IAAI,eAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM;CACpC,CAAC;AAEF,MAAM,eAAe,gBAAG,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC;AAE7D,MAAM,WAAW,GAAI,KAAyB,IAAwB;EACpE,IAAI,KAAK,KAAK,SAAS,EAAE,OAAO,SAAS;EACzC,MAAM,MAAM,GAAG,MAAM,CAAC,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AClC,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,KAAK,CAAC,iBAAiB,CAAC;YACxE,IAAI;YACJ,QAAQ,EAAE;cACR,QAAQ,EAAE;gBACR,SAAS,EAAE,QAAQ,CAAC,OAAO,CAAC,uBAAuB,CAAC,IAAI,IAAI;gBAC5D,SAAS,EAAE,OAAO,EAAE,IAAI,IAAI,IAAI;gBAChC,SAAS,EAAE,OAAO,EAAE,IAAI,IAAI;;;WAGjC,CAAC;QACJ,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;UAC7D,MAAM,GAAG,IAAI,OAAO,CAAC,mBAAmB,CAAC;YAAE,WAAW;YAAE;UAAI,CAAE,CAAC;QACjE,CAAC,MAAM;UACL,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAAE,MAAM,EAAE,QAAQ,CAAC,MAAM;YAAE,WAAW;YAAE;UAAI,CAAE,CAAC;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.1.0",
|
|
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.1.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"effect": "^4.0
|
|
53
|
+
"effect": "^4.1.0"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"codegen": "effect-utils codegen",
|
package/src/TypeSafeClient.ts
CHANGED
|
@@ -29,6 +29,10 @@ import * as TypeSafeSchema from "./TypeSafeSchema.ts"
|
|
|
29
29
|
*/
|
|
30
30
|
export interface Service {
|
|
31
31
|
readonly client: HttpClient.HttpClient
|
|
32
|
+
/**
|
|
33
|
+
* Sends `TypeSafe-Danger-Zone-Images: true` when the request has assets or a
|
|
34
|
+
* Box question.
|
|
35
|
+
*/
|
|
32
36
|
readonly systemOne: (
|
|
33
37
|
request: typeof TypeSafeSchema.SystemOneRequest.Encoded
|
|
34
38
|
) => Effect.Effect<typeof TypeSafeSchema.SystemOneResponse.Type, AiError.AiError>
|
|
@@ -58,6 +62,12 @@ export interface Options {
|
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
const decodeSystemOne = HttpClientResponse.schemaBodyJson(TypeSafeSchema.SystemOneResponse)
|
|
65
|
+
|
|
66
|
+
const imagesHeader = { "TypeSafe-Danger-Zone-Images": "true" }
|
|
67
|
+
|
|
68
|
+
const usesImages = (request: typeof TypeSafeSchema.SystemOneRequest.Encoded): boolean =>
|
|
69
|
+
request.assets !== undefined || Object.values(request.questions).some((question) => question.type === "box")
|
|
70
|
+
|
|
61
71
|
const decodeListModels = HttpClientResponse.schemaBodyJson(TypeSafeSchema.ListModelsResponse)
|
|
62
72
|
|
|
63
73
|
/**
|
|
@@ -101,7 +111,10 @@ export const make = Effect.fnUntraced(
|
|
|
101
111
|
return TypeSafeClient.of({
|
|
102
112
|
client,
|
|
103
113
|
systemOne: (payload) =>
|
|
104
|
-
HttpClientRequest.bodyJson(
|
|
114
|
+
HttpClientRequest.bodyJson(
|
|
115
|
+
HttpClientRequest.post("/systemone", usesImages(payload) ? { headers: imagesHeader } : undefined),
|
|
116
|
+
payload
|
|
117
|
+
).pipe(
|
|
105
118
|
Effect.mapError((error) =>
|
|
106
119
|
AiError.make({
|
|
107
120
|
module: "TypeSafeClient",
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @stability unstable
|
|
5
5
|
* @since 4.0.0
|
|
6
6
|
*/
|
|
7
|
+
import * as AiError from "effect/ai/AiError"
|
|
7
8
|
import * as DecisionModel from "effect/ai/DecisionModel"
|
|
8
9
|
import * as AiModel from "effect/ai/Model"
|
|
9
10
|
import * as Effect from "effect/Effect"
|
|
@@ -18,7 +19,7 @@ import type * as TypeSafeSchema from "./TypeSafeSchema.ts"
|
|
|
18
19
|
* @category models
|
|
19
20
|
* @since 4.0.0
|
|
20
21
|
*/
|
|
21
|
-
export type Model = "jev-latest" | "jev-preview" | "jev-1.13.0"
|
|
22
|
+
export type Model = "jev-latest" | "jev-preview" | "jev-1.13.0" | "jev-1.14.0"
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Creates a decision model with TypeSafe provider metadata.
|
|
@@ -37,6 +38,21 @@ export const model = (
|
|
|
37
38
|
* DecisionModel rescales small sum drift when it validates distributions and
|
|
38
39
|
* derives rating labels.
|
|
39
40
|
*
|
|
41
|
+
* **Details**
|
|
42
|
+
*
|
|
43
|
+
* Each `Decision.Image` field is sent as a base64 asset keyed by the reference
|
|
44
|
+
* that replaces it in `state`, so instructions name an image by its field path,
|
|
45
|
+
* such as `` `photo` ``. Requests with images opt in to TypeSafe's preview image
|
|
46
|
+
* support. Locate decisions become Box questions whose instructions end with
|
|
47
|
+
* the image path; they need Jev 1.14 (`"jev-preview"` or `"jev-1.14.0"`).
|
|
48
|
+
*
|
|
49
|
+
* **Gotchas**
|
|
50
|
+
*
|
|
51
|
+
* - Images must be PNG or JPEG, 256 to 1568 pixels on each side. The API
|
|
52
|
+
* rejects other sizes rather than resizing, and ignores EXIF orientation.
|
|
53
|
+
* - Remote URLs fail with `AiError.InvalidUserInputError` because TypeSafe
|
|
54
|
+
* does not fetch them.
|
|
55
|
+
*
|
|
40
56
|
* @stability unstable
|
|
41
57
|
* @category constructors
|
|
42
58
|
* @since 4.0.0
|
|
@@ -48,7 +64,9 @@ export const make = Effect.fnUntraced(
|
|
|
48
64
|
const client = yield* TypeSafeClient
|
|
49
65
|
return yield* DecisionModel.make({
|
|
50
66
|
probabilityPrecision: 2,
|
|
51
|
-
|
|
67
|
+
supportsImages: true,
|
|
68
|
+
supportsLocate: true,
|
|
69
|
+
decide: Effect.fnUntraced(function*({ state, decisions, images }) {
|
|
52
70
|
const questions: Record<string, typeof TypeSafeSchema.Question.Encoded> = Object.create(null)
|
|
53
71
|
for (const [key, decision] of Object.entries(decisions)) {
|
|
54
72
|
switch (decision._tag) {
|
|
@@ -65,9 +83,23 @@ export const make = Effect.fnUntraced(
|
|
|
65
83
|
case "Probability":
|
|
66
84
|
questions[key] = { type: "noul", instructions: decision.instructions, criteria: decision.criteria }
|
|
67
85
|
break
|
|
86
|
+
case "Locate":
|
|
87
|
+
questions[key] = { type: "box", instructions: `${decision.instructions} in \`${decision.image}\`` }
|
|
88
|
+
break
|
|
68
89
|
}
|
|
69
90
|
}
|
|
70
|
-
const
|
|
91
|
+
const assets: Record<string, typeof TypeSafeSchema.ImageAsset.Encoded> = Object.create(null)
|
|
92
|
+
for (const { reference, image } of images ?? []) {
|
|
93
|
+
const asset = encodeImage(image)
|
|
94
|
+
if (AiError.isAiError(asset)) return yield* Effect.fail(asset)
|
|
95
|
+
assets[reference] = asset
|
|
96
|
+
}
|
|
97
|
+
const response = yield* client.systemOne({
|
|
98
|
+
model: options.model,
|
|
99
|
+
state,
|
|
100
|
+
questions,
|
|
101
|
+
...(images === undefined ? undefined : { assets })
|
|
102
|
+
})
|
|
71
103
|
const answers: Record<string, DecisionModel.ProviderAnswer> = Object.create(null)
|
|
72
104
|
for (const [key, decision] of Object.entries(decisions)) {
|
|
73
105
|
const answer = response.answers[key]
|
|
@@ -93,6 +125,9 @@ export const make = Effect.fnUntraced(
|
|
|
93
125
|
case "noul":
|
|
94
126
|
answers[key] = { _tag: "Probability", probability: answer.noul }
|
|
95
127
|
break
|
|
128
|
+
case "box":
|
|
129
|
+
answers[key] = { _tag: "Locate", box: answer.box, confidence: answer.confidence }
|
|
130
|
+
break
|
|
96
131
|
}
|
|
97
132
|
}
|
|
98
133
|
return {
|
|
@@ -104,6 +139,40 @@ export const make = Effect.fnUntraced(
|
|
|
104
139
|
}
|
|
105
140
|
)
|
|
106
141
|
|
|
142
|
+
const encodeImage = (
|
|
143
|
+
image: DecisionModel.ProviderImage["image"]
|
|
144
|
+
): typeof TypeSafeSchema.ImageAsset.Encoded | AiError.AiError => {
|
|
145
|
+
let { data, mediaType } = image
|
|
146
|
+
if (data instanceof URL) {
|
|
147
|
+
const match = /^data:([^,;]*)[^,]*;base64,(.*)$/si.exec(data.href.split("#", 1)[0])
|
|
148
|
+
if (match === null) {
|
|
149
|
+
return invalidUserInput("TypeSafe accepts bytes, base64 strings, or base64 data URLs; it does not fetch URLs")
|
|
150
|
+
}
|
|
151
|
+
mediaType = match[1] || mediaType
|
|
152
|
+
try {
|
|
153
|
+
data = decodeURIComponent(match[2])
|
|
154
|
+
} catch {
|
|
155
|
+
return invalidUserInput("TypeSafe image data URLs must contain valid percent-encoding")
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
switch (mediaType.toLowerCase()) {
|
|
159
|
+
case "image/png":
|
|
160
|
+
return { type: "image", format: "png", data_base64: data }
|
|
161
|
+
case "image/jpeg":
|
|
162
|
+
case "image/jpg":
|
|
163
|
+
return { type: "image", format: "jpg", data_base64: data }
|
|
164
|
+
default:
|
|
165
|
+
return invalidUserInput(`TypeSafe accepts PNG or JPEG images, not ${mediaType}`)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const invalidUserInput = (description: string): AiError.AiError =>
|
|
170
|
+
AiError.make({
|
|
171
|
+
module: "TypeSafeDecisionModel",
|
|
172
|
+
method: "decide",
|
|
173
|
+
reason: new AiError.InvalidUserInputError({ description })
|
|
174
|
+
})
|
|
175
|
+
|
|
107
176
|
/**
|
|
108
177
|
* Provides DecisionModel using an existing TypeSafeClient.
|
|
109
178
|
*
|
package/src/TypeSafeSchema.ts
CHANGED
|
@@ -47,6 +47,19 @@ export const NoulQuestion = Schema.Struct({
|
|
|
47
47
|
criteria: Schema.optional(Schema.Struct({ false: Entry, true: Entry }))
|
|
48
48
|
})
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* A question that finds where something is in an image. Needs Jev 1.14 and
|
|
52
|
+
* the `TypeSafe-Danger-Zone-Images: true` header.
|
|
53
|
+
*
|
|
54
|
+
* @stability unstable
|
|
55
|
+
* @category schemas
|
|
56
|
+
* @since 4.1.0
|
|
57
|
+
*/
|
|
58
|
+
export const BoxQuestion = Schema.Struct({
|
|
59
|
+
type: Schema.Literal("box"),
|
|
60
|
+
instructions: Entry
|
|
61
|
+
})
|
|
62
|
+
|
|
50
63
|
/**
|
|
51
64
|
* A System One question with string, JSON object, JSON array, or `null` instructions and descriptions.
|
|
52
65
|
*
|
|
@@ -54,10 +67,26 @@ export const NoulQuestion = Schema.Struct({
|
|
|
54
67
|
* @category schemas
|
|
55
68
|
* @since 4.0.0
|
|
56
69
|
*/
|
|
57
|
-
export const Question = Schema.Union([ChoiceQuestion, ScoreQuestion, NoulQuestion])
|
|
70
|
+
export const Question = Schema.Union([ChoiceQuestion, ScoreQuestion, NoulQuestion, BoxQuestion])
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A base64-encoded PNG or JPEG image. Standard alphabet with `=` padding, no
|
|
74
|
+
* whitespace, and no `data:` prefix.
|
|
75
|
+
*
|
|
76
|
+
* @stability unstable
|
|
77
|
+
* @category schemas
|
|
78
|
+
* @since 4.1.0
|
|
79
|
+
*/
|
|
80
|
+
export const ImageAsset = Schema.Struct({
|
|
81
|
+
type: Schema.optional(Schema.Literal("image")),
|
|
82
|
+
format: Schema.Literals(["png", "jpg", "jpeg"]),
|
|
83
|
+
data_base64: Schema.String
|
|
84
|
+
})
|
|
58
85
|
|
|
59
86
|
/**
|
|
60
|
-
* A batch of questions against encoded state.
|
|
87
|
+
* A batch of questions against encoded state. `assets` maps placeholder
|
|
88
|
+
* strings to images; the model sees each image wherever its placeholder
|
|
89
|
+
* appears in `state`, `instructions`, or `criteria`.
|
|
61
90
|
*
|
|
62
91
|
* @stability unstable
|
|
63
92
|
* @category schemas
|
|
@@ -66,7 +95,8 @@ export const Question = Schema.Union([ChoiceQuestion, ScoreQuestion, NoulQuestio
|
|
|
66
95
|
export const SystemOneRequest = Schema.Struct({
|
|
67
96
|
model: Schema.String,
|
|
68
97
|
state: Schema.Json,
|
|
69
|
-
questions: Schema.Record(Schema.String, Question)
|
|
98
|
+
questions: Schema.Record(Schema.String, Question),
|
|
99
|
+
assets: Schema.optional(Schema.Record(Schema.String, ImageAsset))
|
|
70
100
|
})
|
|
71
101
|
|
|
72
102
|
/**
|
|
@@ -107,6 +137,19 @@ export const ScoreAnswer = Schema.Struct({
|
|
|
107
137
|
*/
|
|
108
138
|
export const NoulAnswer = Schema.Struct({ type: Schema.Literal("noul"), noul: Schema.Number })
|
|
109
139
|
|
|
140
|
+
/**
|
|
141
|
+
* A bounding box whose edges are fractions of the image's width and height.
|
|
142
|
+
*
|
|
143
|
+
* @stability unstable
|
|
144
|
+
* @category schemas
|
|
145
|
+
* @since 4.1.0
|
|
146
|
+
*/
|
|
147
|
+
export const BoxAnswer = Schema.Struct({
|
|
148
|
+
type: Schema.Literal("box"),
|
|
149
|
+
box: Schema.Struct({ top: Schema.Number, bottom: Schema.Number, left: Schema.Number, right: Schema.Number }),
|
|
150
|
+
confidence: Schema.Number
|
|
151
|
+
})
|
|
152
|
+
|
|
110
153
|
/**
|
|
111
154
|
* A System One answer.
|
|
112
155
|
*
|
|
@@ -114,7 +157,7 @@ export const NoulAnswer = Schema.Struct({ type: Schema.Literal("noul"), noul: Sc
|
|
|
114
157
|
* @category schemas
|
|
115
158
|
* @since 4.0.0
|
|
116
159
|
*/
|
|
117
|
-
export const Answer = Schema.Union([ChoiceAnswer, ScoreAnswer, NoulAnswer])
|
|
160
|
+
export const Answer = Schema.Union([ChoiceAnswer, ScoreAnswer, NoulAnswer, BoxAnswer])
|
|
118
161
|
|
|
119
162
|
/**
|
|
120
163
|
* Answers and token usage for a batch.
|
package/src/internal/errors.ts
CHANGED
|
@@ -4,21 +4,12 @@ import * as Duration from "effect/Duration"
|
|
|
4
4
|
import * as Effect from "effect/Effect"
|
|
5
5
|
import * as Headers from "effect/http/Headers"
|
|
6
6
|
import type * as HttpClientError from "effect/http/HttpClientError"
|
|
7
|
-
import type * as HttpClientRequest from "effect/http/HttpClientRequest"
|
|
8
7
|
import * as Num from "effect/Number"
|
|
9
8
|
import * as Option from "effect/Option"
|
|
10
9
|
import * as Redactable from "effect/Redactable"
|
|
11
10
|
import * as Result from "effect/Result"
|
|
12
11
|
import * as Schema from "effect/Schema"
|
|
13
12
|
|
|
14
|
-
const requestDetails = (request: HttpClientRequest.HttpClientRequest) => ({
|
|
15
|
-
method: request.method,
|
|
16
|
-
url: request.url,
|
|
17
|
-
urlParams: Array.from(request.urlParams),
|
|
18
|
-
hash: Option.getOrUndefined(request.hash),
|
|
19
|
-
headers: Redactable.redact(request.headers) as Record<string, string>
|
|
20
|
-
})
|
|
21
|
-
|
|
22
13
|
const ErrorBody = Schema.Struct({
|
|
23
14
|
message: Schema.optional(Schema.String),
|
|
24
15
|
type: Schema.optional(Schema.String),
|
|
@@ -59,11 +50,9 @@ export const mapHttpClientError = Effect.fnUntraced(
|
|
|
59
50
|
case "TransportError":
|
|
60
51
|
case "EncodeError":
|
|
61
52
|
case "InvalidUrlError":
|
|
62
|
-
reason =
|
|
63
|
-
reason: source
|
|
64
|
-
|
|
65
|
-
request: requestDetails(source.request)
|
|
66
|
-
})
|
|
53
|
+
reason = AiError.NetworkError.fromHttpClientError(
|
|
54
|
+
error as HttpClientError.HttpClientError & { readonly reason: typeof source }
|
|
55
|
+
)
|
|
67
56
|
break
|
|
68
57
|
case "DecodeError":
|
|
69
58
|
case "EmptyBodyError":
|
|
@@ -77,7 +66,6 @@ export const mapHttpClientError = Effect.fnUntraced(
|
|
|
77
66
|
const parsed = yield* Effect.try(() => JSON.parse(body ?? "")).pipe(Effect.orElseSucceed(() => undefined))
|
|
78
67
|
const details = Option.getOrUndefined(decodeErrorBody(parsed))
|
|
79
68
|
const http = {
|
|
80
|
-
request: requestDetails(request),
|
|
81
69
|
response: { status: response.status, headers: Redactable.redact(response.headers) as Record<string, string> },
|
|
82
70
|
body
|
|
83
71
|
}
|