@effect/ai-cloudflare 4.0.4 → 4.0.5

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 CHANGED
@@ -37,8 +37,23 @@ const program = DecisionModel.decide(Triage, {
37
37
  }).pipe(Effect.provide(Clef))
38
38
  ```
39
39
 
40
+ Pass `images` to include pictures with the input. Clef shows them to the model before the state:
41
+
42
+ ```ts
43
+ declare const screenshotBytes: Uint8Array
44
+
45
+ const withScreenshot = DecisionModel.decide(Triage, {
46
+ input: "Customers report this checkout error.",
47
+ images: [{ mediaType: "image/png", data: screenshotBytes }]
48
+ })
49
+ ```
50
+
51
+ Image `data` may be a `Uint8Array`, a base64 string, or a `data:` URL. Remote URLs fail with `AiError.InvalidUserInputError` because Clef does not fetch them, so download the image first. The API accepts up to 4 PNG, JPEG, or WebP images, each at most 4 MiB and 16 megapixels, with 8 MiB of decoded images in total and a 13 MiB request body.
52
+
40
53
  Use `"clef"` for the larger model. `CloudflareDecisionModel.model` provides a model descriptor with Cloudflare provider metadata. `CloudflareClient.layer` accepts an explicit account ID and redacted API token; `apiUrl` and `transformClient` customize HTTP access.
41
54
 
55
+ Instructions and descriptions can be strings, JSON objects, or JSON arrays. A rating level with a structured description takes an explicit `label`, which answers use.
56
+
42
57
  The client unwraps Cloudflare's REST envelope and maps failures to `AiError`. It does not retry automatically. Rate-limit errors include `Retry-After` when provided. The decision model validates answers and rescales small probability drift from four-decimal rounding.
43
58
 
44
59
  Cloudflare limits each request to 64 questions, classification to 2–255 choices, and ratings to 2–10 levels. See the [Clef API documentation](https://developers.cloudflare.com/workers-ai/models/clef/) for request limits.
@@ -21,22 +21,28 @@ import { FetchHttpClient } from "effect/http"
21
21
  // }
22
22
  // }
23
23
  //
24
- // Each nested selection is its own class, so editor hovers show its name.
25
- export class PageInfo extends Schema.Opaque<PageInfo>()(
26
- Schema.Struct({ hasNextPage: Schema.Boolean, endCursor: Schema.NullOr(Schema.String) })
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 class Issue extends Schema.Opaque<Issue>()(
30
- Schema.Struct({ number: Schema.Int, title: Schema.String })
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 class IssueConnection extends Schema.Opaque<IssueConnection>()(
34
- Schema.Struct({ pageInfo: PageInfo, nodes: Schema.NullOr(Schema.Array(Schema.NullOr(Issue))) })
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 class Repository extends Schema.Opaque<Repository>()(
38
- Schema.Struct({ issues: IssueConnection })
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 class Repository extends Schema.Opaque<Repository>()(Schema.Struct({
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 class NodeOther extends Schema.Opaque<NodeOther>()(Schema.Struct({
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 class PullRequestPullRequest extends Schema.Opaque<PullRequestPullRequest>()(Schema.Struct({
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 class Repository extends Schema.Opaque<Repository>()(Schema.Struct({
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
@@ -1,9 +1,3 @@
1
- /**
2
- * Cloudflare Clef implementation of DecisionModel over Workers AI REST.
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";
@@ -29,6 +23,16 @@ export declare const model: (model: Model) => AiModel.Model<"cloudflare", Decisi
29
23
  /**
30
24
  * Builds a decision service with tolerance for four-decimal probability rounding.
31
25
  *
26
+ * **Details**
27
+ *
28
+ * Byte arrays and base64 strings are sent as base64 with their media type.
29
+ * `data:` URLs are sent unchanged. The API enforces image limits.
30
+ *
31
+ * **Gotchas**
32
+ *
33
+ * - Remote URLs fail with `AiError.InvalidUserInputError` because Clef does
34
+ * not fetch them.
35
+ *
32
36
  * @stability unstable
33
37
  * @category constructors
34
38
  * @since 4.0.0
@@ -1 +1 @@
1
- {"version":3,"file":"CloudflareDecisionModel.d.ts","sourceRoot":"","sources":["../src/CloudflareDecisionModel.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,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,KAAK,gBAAgB,MAAM,uBAAuB,CAAA;AAE9D;;;;;;GAMG;AACH,MAAM,MAAM,KAAK,GAAG,OAAO,gBAAgB,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAE7E;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,UACT,KAAK,KACX,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,aAAa,CAAC,aAAa,EAAE,gBAAgB,CACvB,CAAA;AAErD;;;;;;GAMG;AACH,eAAO,MAAM,IAAI;oBAEc,KAAK;yEAuDnC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,YACP;IAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CAAE,KACjC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,EAAE,KAAK,EAAE,gBAAgB,CACT,CAAA"}
1
+ {"version":3,"file":"CloudflareDecisionModel.d.ts","sourceRoot":"","sources":["../src/CloudflareDecisionModel.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAA;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,KAAK,gBAAgB,MAAM,uBAAuB,CAAA;AAE9D;;;;;;GAMG;AACH,MAAM,MAAM,KAAK,GAAG,OAAO,gBAAgB,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAE7E;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,UACT,KAAK,KACX,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,aAAa,CAAC,aAAa,EAAE,gBAAgB,CACvB,CAAA;AAErD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,IAAI;oBAEc,KAAK;yEA0EnC,CAAA;AAQD;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,YACP;IAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CAAE,KACjC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,EAAE,KAAK,EAAE,gBAAgB,CACT,CAAA"}
@@ -4,9 +4,11 @@
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";
11
+ import * as Base64 from "effect/encoding/Base64";
10
12
  import * as Layer from "effect/Layer";
11
13
  import { CloudflareClient } from "./CloudflareClient.js";
12
14
  /**
@@ -22,6 +24,16 @@ export const model = model => AiModel.make("cloudflare", model, layer({
22
24
  /**
23
25
  * Builds a decision service with tolerance for four-decimal probability rounding.
24
26
  *
27
+ * **Details**
28
+ *
29
+ * Byte arrays and base64 strings are sent as base64 with their media type.
30
+ * `data:` URLs are sent unchanged. The API enforces image limits.
31
+ *
32
+ * **Gotchas**
33
+ *
34
+ * - Remote URLs fail with `AiError.InvalidUserInputError` because Clef does
35
+ * not fetch them.
36
+ *
25
37
  * @stability unstable
26
38
  * @category constructors
27
39
  * @since 4.0.0
@@ -30,9 +42,11 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
30
42
  const client = yield* CloudflareClient;
31
43
  return yield* DecisionModel.make({
32
44
  probabilityPrecision: 4,
45
+ supportsImages: true,
33
46
  decide: Effect.fnUntraced(function* ({
34
47
  state,
35
- decisions
48
+ decisions,
49
+ images
36
50
  }) {
37
51
  const questions = Object.create(null);
38
52
  for (const [key, decision] of Object.entries(decisions)) {
@@ -48,7 +62,7 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
48
62
  questions[key] = {
49
63
  type: "score",
50
64
  instructions: decision.instructions,
51
- criteria: decision.criteria
65
+ criteria: decision.criteria.map(level => level.description)
52
66
  };
53
67
  break;
54
68
  case "Probability":
@@ -60,10 +74,22 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
60
74
  break;
61
75
  }
62
76
  }
77
+ if (images?.some(image => image.data instanceof URL && image.data.protocol !== "data:")) {
78
+ return yield* Effect.fail(AiError.make({
79
+ module: "CloudflareDecisionModel",
80
+ method: "decide",
81
+ reason: new AiError.InvalidUserInputError({
82
+ description: "Cloudflare Clef accepts base64 or data URL images, not remote URLs"
83
+ })
84
+ }));
85
+ }
63
86
  const response = yield* client.createDecisions({
64
87
  model: options.model,
65
88
  state,
66
- questions
89
+ questions,
90
+ ...(images === undefined ? undefined : {
91
+ images: images.map(encodeImage)
92
+ })
67
93
  });
68
94
  const answers = Object.create(null);
69
95
  for (const [key, decision] of Object.entries(decisions)) {
@@ -83,7 +109,7 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
83
109
  const probabilities = Object.create(null);
84
110
  for (let index = 0; index < levels.length; index++) {
85
111
  const probability = answer.probabilities[String(index)];
86
- if (probability !== undefined) probabilities[levels[index]] = probability;
112
+ if (probability !== undefined) probabilities[levels[index].label] = probability;
87
113
  }
88
114
  answers[key] = {
89
115
  _tag: "Rate",
@@ -111,6 +137,10 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
111
137
  })
112
138
  });
113
139
  });
140
+ const encodeImage = image => image.data instanceof URL ? image.data.href : {
141
+ content_type: image.mediaType,
142
+ base64: typeof image.data === "string" ? image.data : Base64.encode(image.data)
143
+ };
114
144
  /**
115
145
  * Provides DecisionModel using an existing CloudflareClient.
116
146
  *
@@ -1 +1 @@
1
- {"version":3,"file":"CloudflareDecisionModel.js","names":[],"sources":["../src/CloudflareDecisionModel.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,gBAAgB,QAAQ,uBAAuB;AAYxD;;;;;;;AAOA,OAAO,MAAM,KAAK,GAChB,KAAY,IAEZ,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC;EAAE;AAAK,CAAE,CAAC,CAAC;AAErD;;;;;;;AAOA,OAAO,MAAM,IAAI,gBAAG,MAAM,CAAC,UAAU,CACnC,WACE,OAAkC;EAElC,MAAM,MAAM,GAAG,OAAO,gBAAgB;EACtC,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,GAA6D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;MAC/F,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,C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KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;gBAClD,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACvD,IAAI,WAAW,KAAK,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,WAAW;cAC3E;cACA,OAAO,CAAC,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,CAAC,YAAY;UAAE,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC;QAAa;OAC9F;IACH,CAAC;GACF,CAAC;AACJ,CAAC,CACF;AAED;;;;;;;AAOA,OAAO,MAAM,KAAK,GAChB,OAAkC,IAElC,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"CloudflareDecisionModel.js","names":[],"sources":["../src/CloudflareDecisionModel.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;AAMA,OAAO,KAAK,OAAO,MAAM,mBAAmB;AAC5C,OAAO,KAAK,aAAa,MAAM,yBAAyB;AACxD,OAAO,KAAK,OAAO,MAAM,iBAAiB;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,MAAM,MAAM,wBAAwB;AAChD,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,SAAS,gBAAgB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uestion: 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.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.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.Codec<Schema.Json, Schema.Json, never, never>>;
31
31
  }>;
32
32
  /**
33
33
  * A probability question.
@@ -38,14 +38,15 @@ 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.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.Codec<Schema.Json, Schema.Json, never, never>;
44
+ readonly true: Schema.Codec<Schema.Json, Schema.Json, never, never>;
45
45
  }>>;
46
46
  }>;
47
47
  /**
48
- * A Clef classification, rating, or probability question.
48
+ * A Clef question with string, JSON object, or JSON array instructions.
49
+ * Choice descriptions also accept `null`; Score and Noul descriptions accept any JSON value.
49
50
  *
50
51
  * @stability unstable
51
52
  * @category schemas
@@ -53,22 +54,40 @@ export declare const NoulQuestion: Schema.Struct<{
53
54
  */
54
55
  export declare const Question: Schema.Union<readonly [Schema.Struct<{
55
56
  readonly type: Schema.Literal<"choice">;
56
- readonly instructions: Schema.String;
57
- readonly criteria: Schema.$Record<Schema.String, Schema.String>;
57
+ readonly instructions: 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
+ 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
59
  }>, Schema.Struct<{
59
60
  readonly type: Schema.Literal<"score">;
60
- readonly instructions: Schema.String;
61
- readonly criteria: Schema.$Array<Schema.String>;
61
+ readonly instructions: 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
+ readonly criteria: Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
62
63
  }>, Schema.Struct<{
63
64
  readonly type: Schema.Literal<"noul">;
64
- readonly instructions: Schema.String;
65
+ readonly instructions: 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
66
  readonly criteria: Schema.optional<Schema.Struct<{
66
- readonly false: Schema.String;
67
- readonly true: Schema.String;
67
+ readonly false: Schema.Codec<Schema.Json, Schema.Json, never, never>;
68
+ readonly true: Schema.Codec<Schema.Json, Schema.Json, never, never>;
68
69
  }>>;
69
70
  }>]>;
70
71
  /**
71
- * A batch of questions about text or JSON state.
72
+ * An image as a `data:` URL or as base64 data with its media type. Clef
73
+ * rejects remote URLs.
74
+ *
75
+ * @stability unstable
76
+ * @category schemas
77
+ * @since 4.0.5
78
+ */
79
+ export declare const Image: Schema.Union<readonly [Schema.String, Schema.Struct<{
80
+ readonly content_type: Schema.Union<readonly [Schema.Literals<readonly ["image/png", "image/jpeg", "image/webp"]>, Schema.StringForLiteralAutocomplete]>;
81
+ readonly base64: Schema.String;
82
+ }>]>;
83
+ /**
84
+ * A batch of questions about text or JSON state, with optional images shown
85
+ * to the model before the state.
86
+ *
87
+ * **Details**
88
+ *
89
+ * Clef accepts up to 4 images of at most 4 MiB and 16 megapixels each, 8 MiB
90
+ * of decoded images in total, and 13 MiB per request body.
72
91
  *
73
92
  * @stability unstable
74
93
  * @category schemas
@@ -79,20 +98,24 @@ export declare const DecisionsRequest: Schema.Struct<{
79
98
  readonly state: Schema.Codec<Schema.Json, Schema.Json, never, never>;
80
99
  readonly questions: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Struct<{
81
100
  readonly type: Schema.Literal<"choice">;
82
- readonly instructions: Schema.String;
83
- readonly criteria: Schema.$Record<Schema.String, Schema.String>;
101
+ readonly instructions: 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>>]>;
102
+ 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
103
  }>, Schema.Struct<{
85
104
  readonly type: Schema.Literal<"score">;
86
- readonly instructions: Schema.String;
87
- readonly criteria: Schema.$Array<Schema.String>;
105
+ readonly instructions: 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>>]>;
106
+ readonly criteria: Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
88
107
  }>, Schema.Struct<{
89
108
  readonly type: Schema.Literal<"noul">;
90
- readonly instructions: Schema.String;
109
+ readonly instructions: 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
110
  readonly criteria: Schema.optional<Schema.Struct<{
92
- readonly false: Schema.String;
93
- readonly true: Schema.String;
111
+ readonly false: Schema.Codec<Schema.Json, Schema.Json, never, never>;
112
+ readonly true: Schema.Codec<Schema.Json, Schema.Json, never, never>;
94
113
  }>>;
95
114
  }>]>>;
115
+ readonly images: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
116
+ readonly content_type: Schema.Union<readonly [Schema.Literals<readonly ["image/png", "image/jpeg", "image/webp"]>, Schema.StringForLiteralAutocomplete]>;
117
+ readonly base64: Schema.String;
118
+ }>]>>>;
96
119
  }>;
97
120
  /**
98
121
  * A classification distribution.
@@ -108,7 +131,7 @@ export declare const ChoiceAnswer: Schema.Struct<{
108
131
  readonly confidence: Schema.Number;
109
132
  }>;
110
133
  /**
111
- * A zero-based rating and index-keyed distribution.
134
+ * A zero-based rating and index-keyed distribution. `legend` maps indices to descriptions.
112
135
  *
113
136
  * @stability unstable
114
137
  * @category schemas
@@ -119,7 +142,7 @@ export declare const ScoreAnswer: Schema.Struct<{
119
142
  readonly score: Schema.Number;
120
143
  readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
121
144
  readonly confidence: Schema.Number;
122
- readonly legend: Schema.$Record<Schema.String, Schema.String>;
145
+ readonly legend: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
123
146
  }>;
124
147
  /**
125
148
  * A Bernoulli probability.
@@ -149,7 +172,7 @@ export declare const Answer: Schema.Union<readonly [Schema.Struct<{
149
172
  readonly score: Schema.Number;
150
173
  readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
151
174
  readonly confidence: Schema.Number;
152
- readonly legend: Schema.$Record<Schema.String, Schema.String>;
175
+ readonly legend: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
153
176
  }>, Schema.Struct<{
154
177
  readonly type: Schema.Literal<"noul">;
155
178
  readonly noul: Schema.Number;
@@ -173,7 +196,7 @@ export declare const DecisionsResponse: Schema.Struct<{
173
196
  readonly score: Schema.Number;
174
197
  readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
175
198
  readonly confidence: Schema.Number;
176
- readonly legend: Schema.$Record<Schema.String, Schema.String>;
199
+ readonly legend: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
177
200
  }>, Schema.Struct<{
178
201
  readonly type: Schema.Literal<"noul">;
179
202
  readonly noul: Schema.Number;
@@ -1 +1 @@
1
- {"version":3,"file":"CloudflareSchema.d.ts","sourceRoot":"","sources":["../src/CloudflareSchema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC;;;;;;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"}
1
+ {"version":3,"file":"CloudflareSchema.d.ts","sourceRoot":"","sources":["../src/CloudflareSchema.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;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;IAA8D,CAAA;AAEnF;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK;;;IAShB,CAAA;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;EAK3B,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"}
@@ -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.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: Schema.String,
18
- criteria: /*#__PURE__*/Schema.Record(Schema.String, Schema.String)
18
+ instructions: Entry,
19
+ criteria: /*#__PURE__*/Schema.Record(Schema.String, /*#__PURE__*/Schema.NullOr(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: Schema.String,
30
- criteria: /*#__PURE__*/Schema.Array(Schema.String)
30
+ instructions: Entry,
31
+ criteria: /*#__PURE__*/Schema.Array(Schema.Json)
31
32
  });
32
33
  /**
33
34
  * A probability question.
@@ -38,14 +39,15 @@ 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: Schema.String,
42
+ instructions: Entry,
42
43
  criteria: /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Struct({
43
- false: Schema.String,
44
- true: Schema.String
44
+ false: Schema.Json,
45
+ true: Schema.Json
45
46
  }))
46
47
  });
47
48
  /**
48
- * A Clef classification, rating, or probability question.
49
+ * A Clef question with string, JSON object, or JSON array instructions.
50
+ * Choice descriptions also accept `null`; Score and Noul descriptions accept any JSON value.
49
51
  *
50
52
  * @stability unstable
51
53
  * @category schemas
@@ -53,7 +55,25 @@ export const NoulQuestion = /*#__PURE__*/Schema.Struct({
53
55
  */
54
56
  export const Question = /*#__PURE__*/Schema.Union([ChoiceQuestion, ScoreQuestion, NoulQuestion]);
55
57
  /**
56
- * A batch of questions about text or JSON state.
58
+ * An image as a `data:` URL or as base64 data with its media type. Clef
59
+ * rejects remote URLs.
60
+ *
61
+ * @stability unstable
62
+ * @category schemas
63
+ * @since 4.0.5
64
+ */
65
+ export const Image = /*#__PURE__*/Schema.Union([Schema.String, /*#__PURE__*/Schema.Struct({
66
+ content_type: /*#__PURE__*/Schema.Union([/*#__PURE__*/Schema.Literals(["image/png", "image/jpeg", "image/webp"]), Schema.StringForLiteralAutocomplete]),
67
+ base64: Schema.String
68
+ })]);
69
+ /**
70
+ * A batch of questions about text or JSON state, with optional images shown
71
+ * to the model before the state.
72
+ *
73
+ * **Details**
74
+ *
75
+ * Clef accepts up to 4 images of at most 4 MiB and 16 megapixels each, 8 MiB
76
+ * of decoded images in total, and 13 MiB per request body.
57
77
  *
58
78
  * @stability unstable
59
79
  * @category schemas
@@ -62,7 +82,8 @@ export const Question = /*#__PURE__*/Schema.Union([ChoiceQuestion, ScoreQuestion
62
82
  export const DecisionsRequest = /*#__PURE__*/Schema.Struct({
63
83
  model: /*#__PURE__*/Schema.Union([/*#__PURE__*/Schema.Literals(["clef", "clef-flash"]), Schema.StringForLiteralAutocomplete]),
64
84
  state: Schema.Json,
65
- questions: /*#__PURE__*/Schema.Record(Schema.String, Question)
85
+ questions: /*#__PURE__*/Schema.Record(Schema.String, Question),
86
+ images: /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Array(Image))
66
87
  });
67
88
  /**
68
89
  * A classification distribution.
@@ -78,7 +99,7 @@ export const ChoiceAnswer = /*#__PURE__*/Schema.Struct({
78
99
  confidence: Schema.Number
79
100
  });
80
101
  /**
81
- * A zero-based rating and index-keyed distribution.
102
+ * A zero-based rating and index-keyed distribution. `legend` maps indices to descriptions.
82
103
  *
83
104
  * @stability unstable
84
105
  * @category schemas
@@ -89,7 +110,7 @@ export const ScoreAnswer = /*#__PURE__*/Schema.Struct({
89
110
  score: Schema.Number,
90
111
  probabilities: /*#__PURE__*/Schema.Record(Schema.String, Schema.Number),
91
112
  confidence: Schema.Number,
92
- legend: /*#__PURE__*/Schema.Record(Schema.String, Schema.String)
113
+ legend: /*#__PURE__*/Schema.Record(Schema.String, Schema.Json)
93
114
  });
94
115
  /**
95
116
  * A Bernoulli probability.
@@ -1 +1 @@
1
- {"version":3,"file":"CloudflareSchema.js","names":[],"sources":["../src/CloudflareSchema.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,MAAM,CAAC,MAAM;EAC3B,QAAQ,eAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM;CACrD,CAAC;AAEF;;;;;;;AAOA,OAAO,MAAM,aAAa,gBAAG,MAAM,CAAC,MAAM,CAAC;EACzC,IAAI,eAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;EAC7B,YAAY,EAAE,MAAM,CAAC,MAAM;EAC3B,QAAQ,eAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM;CACrC,CAAC;AAEF;;;;;;;AAOA,OAAO,MAAM,YAAY,gBAAG,MAAM,CAAC,MAAM,CAAC;EACxC,IAAI,eAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;EAC5B,YAAY,EAAE,MAAM,CAAC,MAAM;EAC3B,QAAQ,eAAE,MAAM,CAAC,QAAQ,cAAC,MAAM,CAAC,MAAM,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC,MAAM;IAAE,IAAI,EAAE,MAAM,CAAC;EAAM,CAAE,CAAC;CACvF,CAAC;AAEF;;;;;;;AAOA,OAAO,MAAM,QAAQ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AAC,GAAG;IACxB,aAAa,EAAE,MAAM,CAAC;GACvB;CACF,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/ai-cloudflare",
3
- "version": "4.0.4",
3
+ "version": "4.0.5",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "A Cloudflare Workers AI decision provider for Effect",
@@ -47,10 +47,10 @@
47
47
  "provenance": true
48
48
  },
49
49
  "devDependencies": {
50
- "effect": "^4.0.4"
50
+ "effect": "^4.0.5"
51
51
  },
52
52
  "peerDependencies": {
53
- "effect": "^4.0.4"
53
+ "effect": "^4.0.5"
54
54
  },
55
55
  "scripts": {
56
56
  "codegen": "effect-utils codegen",
@@ -4,9 +4,11 @@
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"
11
+ import * as Base64 from "effect/encoding/Base64"
10
12
  import * as Layer from "effect/Layer"
11
13
  import { CloudflareClient } from "./CloudflareClient.ts"
12
14
  import type * as CloudflareSchema from "./CloudflareSchema.ts"
@@ -35,6 +37,16 @@ export const model = (
35
37
  /**
36
38
  * Builds a decision service with tolerance for four-decimal probability rounding.
37
39
  *
40
+ * **Details**
41
+ *
42
+ * Byte arrays and base64 strings are sent as base64 with their media type.
43
+ * `data:` URLs are sent unchanged. The API enforces image limits.
44
+ *
45
+ * **Gotchas**
46
+ *
47
+ * - Remote URLs fail with `AiError.InvalidUserInputError` because Clef does
48
+ * not fetch them.
49
+ *
38
50
  * @stability unstable
39
51
  * @category constructors
40
52
  * @since 4.0.0
@@ -46,7 +58,8 @@ export const make = Effect.fnUntraced(
46
58
  const client = yield* CloudflareClient
47
59
  return yield* DecisionModel.make({
48
60
  probabilityPrecision: 4,
49
- decide: Effect.fnUntraced(function*({ state, decisions }) {
61
+ supportsImages: true,
62
+ decide: Effect.fnUntraced(function*({ state, decisions, images }) {
50
63
  const questions: Record<string, typeof CloudflareSchema.Question.Encoded> = Object.create(null)
51
64
  for (const [key, decision] of Object.entries(decisions)) {
52
65
  switch (decision._tag) {
@@ -54,14 +67,32 @@ export const make = Effect.fnUntraced(
54
67
  questions[key] = { type: "choice", instructions: decision.instructions, criteria: decision.criteria }
55
68
  break
56
69
  case "Rate":
57
- questions[key] = { type: "score", instructions: decision.instructions, criteria: decision.criteria }
70
+ questions[key] = {
71
+ type: "score",
72
+ instructions: decision.instructions,
73
+ criteria: decision.criteria.map((level) => level.description)
74
+ }
58
75
  break
59
76
  case "Probability":
60
77
  questions[key] = { type: "noul", instructions: decision.instructions, criteria: decision.criteria }
61
78
  break
62
79
  }
63
80
  }
64
- const response = yield* client.createDecisions({ model: options.model, state, questions })
81
+ if (images?.some((image) => image.data instanceof URL && image.data.protocol !== "data:")) {
82
+ return yield* Effect.fail(AiError.make({
83
+ module: "CloudflareDecisionModel",
84
+ method: "decide",
85
+ reason: new AiError.InvalidUserInputError({
86
+ description: "Cloudflare Clef accepts base64 or data URL images, not remote URLs"
87
+ })
88
+ }))
89
+ }
90
+ const response = yield* client.createDecisions({
91
+ model: options.model,
92
+ state,
93
+ questions,
94
+ ...(images === undefined ? undefined : { images: images.map(encodeImage) })
95
+ })
65
96
  const answers: Record<string, DecisionModel.ProviderAnswer> = Object.create(null)
66
97
  for (const [key, decision] of Object.entries(decisions)) {
67
98
  const answer = response.answers[key]
@@ -79,7 +110,7 @@ export const make = Effect.fnUntraced(
79
110
  const probabilities: Record<string, number> = Object.create(null)
80
111
  for (let index = 0; index < levels.length; index++) {
81
112
  const probability = answer.probabilities[String(index)]
82
- if (probability !== undefined) probabilities[levels[index]] = probability
113
+ if (probability !== undefined) probabilities[levels[index].label] = probability
83
114
  }
84
115
  answers[key] = { _tag: "Rate", rating: answer.score, probabilities, confidence: answer.confidence }
85
116
  break
@@ -98,6 +129,12 @@ export const make = Effect.fnUntraced(
98
129
  }
99
130
  )
100
131
 
132
+ const encodeImage = (image: DecisionModel.Image): typeof CloudflareSchema.Image.Encoded =>
133
+ image.data instanceof URL ? image.data.href : {
134
+ content_type: image.mediaType,
135
+ base64: typeof image.data === "string" ? image.data : Base64.encode(image.data)
136
+ }
137
+
101
138
  /**
102
139
  * Provides DecisionModel using an existing CloudflareClient.
103
140
  *
@@ -6,6 +6,8 @@
6
6
  */
7
7
  import * as Schema from "effect/Schema"
8
8
 
9
+ const Entry = 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: Schema.String,
19
- criteria: Schema.Record(Schema.String, Schema.String)
20
+ instructions: Entry,
21
+ criteria: Schema.Record(Schema.String, Schema.NullOr(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: Schema.String,
32
- criteria: Schema.Array(Schema.String)
33
+ instructions: Entry,
34
+ criteria: Schema.Array(Schema.Json)
33
35
  })
34
36
 
35
37
  /**
@@ -41,12 +43,13 @@ export const ScoreQuestion = Schema.Struct({
41
43
  */
42
44
  export const NoulQuestion = Schema.Struct({
43
45
  type: Schema.Literal("noul"),
44
- instructions: Schema.String,
45
- criteria: Schema.optional(Schema.Struct({ false: Schema.String, true: Schema.String }))
46
+ instructions: Entry,
47
+ criteria: Schema.optional(Schema.Struct({ false: Schema.Json, true: Schema.Json }))
46
48
  })
47
49
 
48
50
  /**
49
- * A Clef classification, rating, or probability question.
51
+ * A Clef question with string, JSON object, or JSON array instructions.
52
+ * Choice descriptions also accept `null`; Score and Noul descriptions accept any JSON value.
50
53
  *
51
54
  * @stability unstable
52
55
  * @category schemas
@@ -55,7 +58,32 @@ export const NoulQuestion = Schema.Struct({
55
58
  export const Question = Schema.Union([ChoiceQuestion, ScoreQuestion, NoulQuestion])
56
59
 
57
60
  /**
58
- * A batch of questions about text or JSON state.
61
+ * An image as a `data:` URL or as base64 data with its media type. Clef
62
+ * rejects remote URLs.
63
+ *
64
+ * @stability unstable
65
+ * @category schemas
66
+ * @since 4.0.5
67
+ */
68
+ export const Image = Schema.Union([
69
+ Schema.String,
70
+ Schema.Struct({
71
+ content_type: Schema.Union([
72
+ Schema.Literals(["image/png", "image/jpeg", "image/webp"]),
73
+ Schema.StringForLiteralAutocomplete
74
+ ]),
75
+ base64: Schema.String
76
+ })
77
+ ])
78
+
79
+ /**
80
+ * A batch of questions about text or JSON state, with optional images shown
81
+ * to the model before the state.
82
+ *
83
+ * **Details**
84
+ *
85
+ * Clef accepts up to 4 images of at most 4 MiB and 16 megapixels each, 8 MiB
86
+ * of decoded images in total, and 13 MiB per request body.
59
87
  *
60
88
  * @stability unstable
61
89
  * @category schemas
@@ -64,7 +92,8 @@ export const Question = Schema.Union([ChoiceQuestion, ScoreQuestion, NoulQuestio
64
92
  export const DecisionsRequest = Schema.Struct({
65
93
  model: Schema.Union([Schema.Literals(["clef", "clef-flash"]), Schema.StringForLiteralAutocomplete]),
66
94
  state: Schema.Json,
67
- questions: Schema.Record(Schema.String, Question)
95
+ questions: Schema.Record(Schema.String, Question),
96
+ images: Schema.optional(Schema.Array(Image))
68
97
  })
69
98
 
70
99
  /**
@@ -82,7 +111,7 @@ export const ChoiceAnswer = Schema.Struct({
82
111
  })
83
112
 
84
113
  /**
85
- * A zero-based rating and index-keyed distribution.
114
+ * A zero-based rating and index-keyed distribution. `legend` maps indices to descriptions.
86
115
  *
87
116
  * @stability unstable
88
117
  * @category schemas
@@ -93,7 +122,7 @@ export const ScoreAnswer = Schema.Struct({
93
122
  score: Schema.Number,
94
123
  probabilities: Schema.Record(Schema.String, Schema.Number),
95
124
  confidence: Schema.Number,
96
- legend: Schema.Record(Schema.String, Schema.String)
125
+ legend: Schema.Record(Schema.String, Schema.Json)
97
126
  })
98
127
 
99
128
  /**