@effect/ai 0.14.0 → 0.15.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/AiEmbeddingModel/package.json +6 -0
- package/AiLanguageModel/package.json +6 -0
- package/AiTool/package.json +6 -0
- package/dist/cjs/AiChat.js +65 -86
- package/dist/cjs/AiChat.js.map +1 -1
- package/dist/cjs/{Embeddings.js → AiEmbeddingModel.js} +12 -12
- package/dist/cjs/AiEmbeddingModel.js.map +1 -0
- package/dist/cjs/AiError.js +8 -1
- package/dist/cjs/AiError.js.map +1 -1
- package/dist/cjs/AiInput.js +335 -248
- package/dist/cjs/AiInput.js.map +1 -1
- package/dist/cjs/AiLanguageModel.js +311 -0
- package/dist/cjs/AiLanguageModel.js.map +1 -0
- package/dist/cjs/AiModel.js +11 -5
- package/dist/cjs/AiModel.js.map +1 -1
- package/dist/cjs/AiPlan.js +10 -3
- package/dist/cjs/AiPlan.js.map +1 -1
- package/dist/cjs/AiResponse.js +481 -165
- package/dist/cjs/AiResponse.js.map +1 -1
- package/dist/cjs/AiTelemetry.js +10 -3
- package/dist/cjs/AiTelemetry.js.map +1 -1
- package/dist/cjs/AiTool.js +93 -0
- package/dist/cjs/AiTool.js.map +1 -0
- package/dist/cjs/AiToolkit.js +121 -98
- package/dist/cjs/AiToolkit.js.map +1 -1
- package/dist/cjs/Tokenizer.js +14 -16
- package/dist/cjs/Tokenizer.js.map +1 -1
- package/dist/cjs/index.js +7 -9
- package/dist/cjs/internal/aiPlan.js +6 -9
- package/dist/cjs/internal/aiPlan.js.map +1 -1
- package/dist/cjs/internal/common.js +22 -0
- package/dist/cjs/internal/common.js.map +1 -0
- package/dist/dts/AiChat.d.ts +58 -44
- package/dist/dts/AiChat.d.ts.map +1 -1
- package/dist/dts/{Embeddings.d.ts → AiEmbeddingModel.d.ts} +13 -14
- package/dist/dts/AiEmbeddingModel.d.ts.map +1 -0
- package/dist/dts/AiError.d.ts +4 -3
- package/dist/dts/AiError.d.ts.map +1 -1
- package/dist/dts/AiInput.d.ts +441 -146
- package/dist/dts/AiInput.d.ts.map +1 -1
- package/dist/dts/AiLanguageModel.d.ts +263 -0
- package/dist/dts/AiLanguageModel.d.ts.map +1 -0
- package/dist/dts/AiModel.d.ts +21 -20
- package/dist/dts/AiModel.d.ts.map +1 -1
- package/dist/dts/AiPlan.d.ts +90 -26
- package/dist/dts/AiPlan.d.ts.map +1 -1
- package/dist/dts/AiResponse.d.ts +711 -100
- package/dist/dts/AiResponse.d.ts.map +1 -1
- package/dist/dts/AiTelemetry.d.ts +175 -157
- package/dist/dts/AiTelemetry.d.ts.map +1 -1
- package/dist/dts/AiTool.d.ts +288 -0
- package/dist/dts/AiTool.d.ts.map +1 -0
- package/dist/dts/AiToolkit.d.ts +50 -111
- package/dist/dts/AiToolkit.d.ts.map +1 -1
- package/dist/dts/Tokenizer.d.ts +8 -6
- package/dist/dts/Tokenizer.d.ts.map +1 -1
- package/dist/dts/index.d.ts +8 -12
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/common.d.ts +2 -0
- package/dist/dts/internal/common.d.ts.map +1 -0
- package/dist/esm/AiChat.js +62 -83
- package/dist/esm/AiChat.js.map +1 -1
- package/dist/esm/{Embeddings.js → AiEmbeddingModel.js} +10 -10
- package/dist/esm/AiEmbeddingModel.js.map +1 -0
- package/dist/esm/AiError.js +8 -1
- package/dist/esm/AiError.js.map +1 -1
- package/dist/esm/AiInput.js +316 -238
- package/dist/esm/AiInput.js.map +1 -1
- package/dist/esm/AiLanguageModel.js +300 -0
- package/dist/esm/AiLanguageModel.js.map +1 -0
- package/dist/esm/AiModel.js +11 -5
- package/dist/esm/AiModel.js.map +1 -1
- package/dist/esm/AiPlan.js +8 -2
- package/dist/esm/AiPlan.js.map +1 -1
- package/dist/esm/AiResponse.js +467 -162
- package/dist/esm/AiResponse.js.map +1 -1
- package/dist/esm/AiTelemetry.js +8 -2
- package/dist/esm/AiTelemetry.js.map +1 -1
- package/dist/esm/AiTool.js +82 -0
- package/dist/esm/AiTool.js.map +1 -0
- package/dist/esm/AiToolkit.js +118 -96
- package/dist/esm/AiToolkit.js.map +1 -1
- package/dist/esm/Tokenizer.js +14 -16
- package/dist/esm/Tokenizer.js.map +1 -1
- package/dist/esm/index.js +8 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/aiPlan.js +4 -7
- package/dist/esm/internal/aiPlan.js.map +1 -1
- package/dist/esm/internal/common.js +14 -0
- package/dist/esm/internal/common.js.map +1 -0
- package/package.json +28 -36
- package/src/AiChat.ts +182 -207
- package/src/{Embeddings.ts → AiEmbeddingModel.ts} +19 -18
- package/src/AiError.ts +8 -1
- package/src/AiInput.ts +434 -313
- package/src/AiLanguageModel.ts +569 -0
- package/src/AiModel.ts +47 -29
- package/src/AiPlan.ts +102 -30
- package/src/AiResponse.ts +743 -187
- package/src/AiTelemetry.ts +214 -197
- package/src/AiTool.ts +496 -0
- package/src/AiToolkit.ts +200 -240
- package/src/Tokenizer.ts +18 -22
- package/src/index.ts +9 -14
- package/src/internal/aiPlan.ts +12 -14
- package/src/internal/common.ts +12 -0
- package/AiModels/package.json +0 -6
- package/AiRole/package.json +0 -6
- package/Completions/package.json +0 -6
- package/Embeddings/package.json +0 -6
- package/dist/cjs/AiModels.js +0 -54
- package/dist/cjs/AiModels.js.map +0 -1
- package/dist/cjs/AiRole.js +0 -106
- package/dist/cjs/AiRole.js.map +0 -1
- package/dist/cjs/Completions.js +0 -256
- package/dist/cjs/Completions.js.map +0 -1
- package/dist/cjs/Embeddings.js.map +0 -1
- package/dist/dts/AiModels.d.ts +0 -34
- package/dist/dts/AiModels.d.ts.map +0 -1
- package/dist/dts/AiRole.d.ts +0 -111
- package/dist/dts/AiRole.d.ts.map +0 -1
- package/dist/dts/Completions.d.ts +0 -128
- package/dist/dts/Completions.d.ts.map +0 -1
- package/dist/dts/Embeddings.d.ts.map +0 -1
- package/dist/esm/AiModels.js +0 -44
- package/dist/esm/AiModels.js.map +0 -1
- package/dist/esm/AiRole.js +0 -93
- package/dist/esm/AiRole.js.map +0 -1
- package/dist/esm/Completions.js +0 -245
- package/dist/esm/Completions.js.map +0 -1
- package/dist/esm/Embeddings.js.map +0 -1
- package/src/AiModels.ts +0 -77
- package/src/AiRole.ts +0 -122
- package/src/Completions.ts +0 -434
package/dist/cjs/AiInput.js
CHANGED
|
@@ -3,184 +3,155 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
var FileSystem = _interopRequireWildcard(require("@effect/platform/FileSystem"));
|
|
8
|
-
var Path = _interopRequireWildcard(require("@effect/platform/Path"));
|
|
9
|
-
var Chunk = _interopRequireWildcard(require("effect/Chunk"));
|
|
10
|
-
var Context = _interopRequireWildcard(require("effect/Context"));
|
|
11
|
-
var Effect = _interopRequireWildcard(require("effect/Effect"));
|
|
12
|
-
var Encoding = _interopRequireWildcard(require("effect/Encoding"));
|
|
6
|
+
exports.make = exports.isPart = exports.isMessage = exports.is = exports.empty = exports.concat = exports.UserMessagePart = exports.UserMessage = exports.TypeId = exports.ToolMessagePart = exports.ToolMessage = exports.ToolCallResultPart = exports.ToolCallPart = exports.ToolCallId = exports.TextPart = exports.RedactedReasoningPart = exports.ReasoningPart = exports.PartTypeId = exports.MessageTypeId = exports.Message = exports.ImageUrlPart = exports.ImagePart = exports.FromJson = exports.FileUrlPart = exports.FilePart = exports.AssistantMessagePart = exports.AssistantMessage = exports.AiInput = void 0;
|
|
13
7
|
var _Function = require("effect/Function");
|
|
14
|
-
var Option = _interopRequireWildcard(require("effect/Option"));
|
|
15
|
-
var ParseResult = _interopRequireWildcard(require("effect/ParseResult"));
|
|
16
8
|
var Predicate = _interopRequireWildcard(require("effect/Predicate"));
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
9
|
+
var Schema = _interopRequireWildcard(require("effect/Schema"));
|
|
10
|
+
var AiResponse = _interopRequireWildcard(require("./AiResponse.js"));
|
|
11
|
+
var InternalCommon = _interopRequireWildcard(require("./internal/common.js"));
|
|
20
12
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
13
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
22
|
-
const constDisableValidation = {
|
|
23
|
-
disableValidation: true
|
|
24
|
-
};
|
|
25
14
|
/**
|
|
26
15
|
* @since 1.0.0
|
|
27
|
-
* @category parts
|
|
28
16
|
*/
|
|
29
|
-
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @since 1.0.0
|
|
20
|
+
* @category Type Ids
|
|
21
|
+
*/
|
|
22
|
+
const TypeId = exports.TypeId = /*#__PURE__*/Symbol.for("@effect/ai/AiInput");
|
|
30
23
|
/**
|
|
24
|
+
* Represents input to a large language model.
|
|
25
|
+
*
|
|
31
26
|
* @since 1.0.0
|
|
32
|
-
* @category
|
|
27
|
+
* @category Models
|
|
33
28
|
*/
|
|
34
|
-
class
|
|
35
|
-
|
|
29
|
+
class AiInput extends /*#__PURE__*/Schema.Class("@effect/ai/AiInput")({
|
|
30
|
+
messages: /*#__PURE__*/Schema.Array( /*#__PURE__*/Schema.suspend(() => Message))
|
|
36
31
|
}) {
|
|
37
32
|
/**
|
|
38
33
|
* @since 1.0.0
|
|
39
34
|
*/
|
|
40
|
-
[
|
|
35
|
+
[TypeId] = TypeId;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @since 1.0.0
|
|
39
|
+
* @category Models
|
|
40
|
+
*/
|
|
41
|
+
exports.AiInput = AiInput;
|
|
42
|
+
const FromJson = exports.FromJson = /*#__PURE__*/Schema.parseJson(AiInput);
|
|
43
|
+
// =============================================================================
|
|
44
|
+
// Message
|
|
45
|
+
// =============================================================================
|
|
46
|
+
/**
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
* @category Type Ids
|
|
49
|
+
*/
|
|
50
|
+
const MessageTypeId = exports.MessageTypeId = /*#__PURE__*/Symbol.for("@effect/ai/AiInput/Message");
|
|
51
|
+
/**
|
|
52
|
+
* @since 1.0.0
|
|
53
|
+
* @category Models
|
|
54
|
+
*/
|
|
55
|
+
class UserMessage extends /*#__PURE__*/Schema.TaggedClass("@effect/ai/AiInput/Message/UserMessage")("UserMessage", {
|
|
56
|
+
parts: /*#__PURE__*/Schema.Array( /*#__PURE__*/Schema.suspend(() => UserMessagePart)),
|
|
57
|
+
userName: /*#__PURE__*/Schema.optional(Schema.String)
|
|
58
|
+
}) {
|
|
41
59
|
/**
|
|
42
60
|
* @since 1.0.0
|
|
43
61
|
*/
|
|
44
|
-
|
|
45
|
-
return new TextPart({
|
|
46
|
-
content
|
|
47
|
-
}, constDisableValidation);
|
|
48
|
-
}
|
|
62
|
+
[MessageTypeId] = MessageTypeId;
|
|
49
63
|
}
|
|
50
64
|
/**
|
|
51
65
|
* @since 1.0.0
|
|
52
|
-
* @category
|
|
66
|
+
* @category Models
|
|
53
67
|
*/
|
|
54
|
-
exports.
|
|
55
|
-
|
|
68
|
+
exports.UserMessage = UserMessage;
|
|
69
|
+
class AssistantMessage extends /*#__PURE__*/Schema.TaggedClass("@effect/ai/AiInput/Message/AssistantMessage")("AssistantMessage", {
|
|
70
|
+
parts: /*#__PURE__*/Schema.Array( /*#__PURE__*/Schema.suspend(() => AssistantMessagePart))
|
|
71
|
+
}) {
|
|
72
|
+
/**
|
|
73
|
+
* @since 1.0.0
|
|
74
|
+
*/
|
|
75
|
+
[MessageTypeId] = MessageTypeId;
|
|
76
|
+
}
|
|
56
77
|
/**
|
|
57
78
|
* @since 1.0.0
|
|
58
|
-
* @category
|
|
79
|
+
* @category Models
|
|
59
80
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
81
|
+
exports.AssistantMessage = AssistantMessage;
|
|
82
|
+
class ToolMessage extends /*#__PURE__*/Schema.TaggedClass("@effect/ai/AiInput/Message/ToolMessage")("ToolMessage", {
|
|
83
|
+
parts: /*#__PURE__*/Schema.Array( /*#__PURE__*/Schema.suspend(() => ToolMessagePart))
|
|
63
84
|
}) {
|
|
64
85
|
/**
|
|
65
86
|
* @since 1.0.0
|
|
66
87
|
*/
|
|
67
|
-
[
|
|
88
|
+
[MessageTypeId] = MessageTypeId;
|
|
68
89
|
}
|
|
69
|
-
exports.ImageUrlPart = ImageUrlPart;
|
|
70
|
-
const base64ContentTypeRegex = /^data:(.*?);base64$/;
|
|
71
90
|
/**
|
|
72
91
|
* @since 1.0.0
|
|
73
|
-
* @category
|
|
92
|
+
* @category Models
|
|
74
93
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return ParseResult.fail(new ParseResult.Type(ast, base64Url));
|
|
86
|
-
}
|
|
87
|
-
const header = base64Url.slice(0, commaIndex);
|
|
88
|
-
const data = base64Url.slice(commaIndex + 1);
|
|
89
|
-
const contentType = base64ContentTypeRegex.exec(header);
|
|
90
|
-
if (contentType === null) {
|
|
91
|
-
return ParseResult.fail(new ParseResult.Type(ast, base64Url));
|
|
92
|
-
}
|
|
93
|
-
return Encoding.decodeBase64(data).pipe(ParseResult.mapError(_ => new ParseResult.Type(ast, base64Url)), ParseResult.map(data => ({
|
|
94
|
-
data,
|
|
95
|
-
contentType: contentType[1]
|
|
96
|
-
})));
|
|
97
|
-
},
|
|
98
|
-
encode({
|
|
99
|
-
contentType,
|
|
100
|
-
data
|
|
101
|
-
}) {
|
|
102
|
-
const base64 = Encoding.encodeBase64(data);
|
|
103
|
-
return ParseResult.succeed(`data:${contentType};base64,${base64}`);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
94
|
+
exports.ToolMessage = ToolMessage;
|
|
95
|
+
const Message = exports.Message = /*#__PURE__*/Schema.Union(UserMessage, AssistantMessage, ToolMessage);
|
|
96
|
+
// =============================================================================
|
|
97
|
+
// Part
|
|
98
|
+
// =============================================================================
|
|
99
|
+
/**
|
|
100
|
+
* @since 1.0.0
|
|
101
|
+
* @category Type Ids
|
|
102
|
+
*/
|
|
103
|
+
const PartTypeId = exports.PartTypeId = /*#__PURE__*/Symbol.for("@effect/ai/AiInput/Message/Part");
|
|
106
104
|
/**
|
|
105
|
+
* Represents a text part of a message.
|
|
106
|
+
*
|
|
107
107
|
* @since 1.0.0
|
|
108
|
-
* @category
|
|
108
|
+
* @category Models
|
|
109
109
|
*/
|
|
110
|
-
class
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
class TextPart extends /*#__PURE__*/Schema.TaggedClass("@effect/ai/AiInput/TextPart")("TextPart", {
|
|
111
|
+
/**
|
|
112
|
+
* The text content.
|
|
113
|
+
*/
|
|
114
|
+
text: Schema.String
|
|
113
115
|
}) {
|
|
114
116
|
/**
|
|
115
117
|
* @since 1.0.0
|
|
116
118
|
*/
|
|
117
119
|
[PartTypeId] = PartTypeId;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Represents an image part of a message with binary image data.
|
|
123
|
+
*
|
|
124
|
+
* @since 1.0.0
|
|
125
|
+
* @category Models
|
|
126
|
+
*/
|
|
127
|
+
exports.TextPart = TextPart;
|
|
128
|
+
class ImagePart extends /*#__PURE__*/Schema.TaggedClass("@effect/ai/AiInput/ImagePart")("ImagePart", {
|
|
118
129
|
/**
|
|
119
|
-
*
|
|
130
|
+
* The binary image data.
|
|
120
131
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}) => {
|
|
128
|
-
const ext = Path.extname(path);
|
|
129
|
-
let contentType;
|
|
130
|
-
switch (ext) {
|
|
131
|
-
case ".jpg":
|
|
132
|
-
case ".jpeg":
|
|
133
|
-
{
|
|
134
|
-
contentType = "image/jpeg";
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
default:
|
|
138
|
-
{
|
|
139
|
-
if (ext.startsWith(".")) {
|
|
140
|
-
contentType = `image/${ext.slice(1)}`;
|
|
141
|
-
} else {
|
|
142
|
-
contentType = "image/png";
|
|
143
|
-
}
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return new ImagePart({
|
|
148
|
-
image: {
|
|
149
|
-
data,
|
|
150
|
-
contentType
|
|
151
|
-
},
|
|
152
|
-
quality
|
|
153
|
-
}, constDisableValidation);
|
|
154
|
-
}));
|
|
155
|
-
}
|
|
132
|
+
data: Schema.Uint8ArrayFromBase64,
|
|
133
|
+
/**
|
|
134
|
+
* The optional MIME type for the image.
|
|
135
|
+
*/
|
|
136
|
+
mediaType: /*#__PURE__*/Schema.optional(Schema.String)
|
|
137
|
+
}) {
|
|
156
138
|
/**
|
|
157
139
|
* @since 1.0.0
|
|
158
140
|
*/
|
|
159
|
-
|
|
160
|
-
return Effect.promise(() => blob.arrayBuffer()).pipe(Effect.map(buffer => new ImagePart({
|
|
161
|
-
image: {
|
|
162
|
-
contentType: blob.type,
|
|
163
|
-
data: new Uint8Array(buffer)
|
|
164
|
-
},
|
|
165
|
-
quality
|
|
166
|
-
})));
|
|
167
|
-
}
|
|
168
|
-
get asBase64() {
|
|
169
|
-
return Encoding.encodeBase64(this.image.data);
|
|
170
|
-
}
|
|
171
|
-
get asDataUri() {
|
|
172
|
-
return `data:${this.image.contentType};base64,${this.asBase64}`;
|
|
173
|
-
}
|
|
141
|
+
[PartTypeId] = PartTypeId;
|
|
174
142
|
}
|
|
175
143
|
/**
|
|
144
|
+
* Represents an image part of a message with a URL pointing to the image.
|
|
145
|
+
*
|
|
176
146
|
* @since 1.0.0
|
|
177
|
-
* @category
|
|
147
|
+
* @category Models
|
|
178
148
|
*/
|
|
179
149
|
exports.ImagePart = ImagePart;
|
|
180
|
-
class
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
150
|
+
class ImageUrlPart extends /*#__PURE__*/Schema.TaggedClass("@effect/ai/AiInput/ImageUrlPart")("ImageUrlPart", {
|
|
151
|
+
/**
|
|
152
|
+
* The URL that points to the image.
|
|
153
|
+
*/
|
|
154
|
+
url: Schema.URL
|
|
184
155
|
}) {
|
|
185
156
|
/**
|
|
186
157
|
* @since 1.0.0
|
|
@@ -188,13 +159,25 @@ class ToolCallPart extends /*#__PURE__*/Schema_.TaggedClass("@effect/ai/AiInput/
|
|
|
188
159
|
[PartTypeId] = PartTypeId;
|
|
189
160
|
}
|
|
190
161
|
/**
|
|
162
|
+
* Represents a file part of a message with binary file data.
|
|
163
|
+
*
|
|
191
164
|
* @since 1.0.0
|
|
192
|
-
* @category
|
|
165
|
+
* @category Models
|
|
193
166
|
*/
|
|
194
|
-
exports.
|
|
195
|
-
class
|
|
196
|
-
|
|
197
|
-
|
|
167
|
+
exports.ImageUrlPart = ImageUrlPart;
|
|
168
|
+
class FilePart extends /*#__PURE__*/Schema.TaggedClass("@effect/ai/AiInput/FilePart")("FilePart", {
|
|
169
|
+
/**
|
|
170
|
+
* The binary file data.
|
|
171
|
+
*/
|
|
172
|
+
data: Schema.Uint8ArrayFromBase64,
|
|
173
|
+
/**
|
|
174
|
+
* The optional name of the file.
|
|
175
|
+
*/
|
|
176
|
+
name: /*#__PURE__*/Schema.optional(Schema.String),
|
|
177
|
+
/**
|
|
178
|
+
* The optional MIME type for the image.
|
|
179
|
+
*/
|
|
180
|
+
mediaType: /*#__PURE__*/Schema.optional(Schema.String)
|
|
198
181
|
}) {
|
|
199
182
|
/**
|
|
200
183
|
* @since 1.0.0
|
|
@@ -202,162 +185,266 @@ class ToolCallResolvedPart extends /*#__PURE__*/Schema_.TaggedClass("@effect/ai/
|
|
|
202
185
|
[PartTypeId] = PartTypeId;
|
|
203
186
|
}
|
|
204
187
|
/**
|
|
188
|
+
* Represents a file part of a message with a URL pointing to the file.
|
|
189
|
+
*
|
|
205
190
|
* @since 1.0.0
|
|
206
|
-
* @category
|
|
191
|
+
* @category Models
|
|
207
192
|
*/
|
|
208
|
-
exports.
|
|
209
|
-
|
|
193
|
+
exports.FilePart = FilePart;
|
|
194
|
+
class FileUrlPart extends /*#__PURE__*/Schema.TaggedClass("@effect/ai/AiInput/FileUrlPart")("FileUrlPart", {
|
|
195
|
+
/**
|
|
196
|
+
* The URL that points to the file.
|
|
197
|
+
*/
|
|
198
|
+
url: Schema.URL
|
|
199
|
+
}) {
|
|
200
|
+
/**
|
|
201
|
+
* @since 1.0.0
|
|
202
|
+
*/
|
|
203
|
+
[PartTypeId] = PartTypeId;
|
|
204
|
+
}
|
|
210
205
|
/**
|
|
206
|
+
* Represents a part of a message containing reasoning that the model used to
|
|
207
|
+
* generate its output.
|
|
208
|
+
*
|
|
211
209
|
* @since 1.0.0
|
|
212
|
-
* @category
|
|
210
|
+
* @category Models
|
|
213
211
|
*/
|
|
214
|
-
exports.
|
|
215
|
-
|
|
212
|
+
exports.FileUrlPart = FileUrlPart;
|
|
213
|
+
class ReasoningPart extends /*#__PURE__*/Schema.TaggedClass("@effect/ai/AiInput/ReasoningPart")("ReasoningPart", {
|
|
214
|
+
/**
|
|
215
|
+
* The reasoning text that the model used to return the output.
|
|
216
|
+
*/
|
|
217
|
+
reasoningText: Schema.String,
|
|
218
|
+
/**
|
|
219
|
+
* An optional signature which verifies that the reasoning text was generated
|
|
220
|
+
* by the model.
|
|
221
|
+
*/
|
|
222
|
+
signature: /*#__PURE__*/Schema.optional(Schema.String)
|
|
223
|
+
}) {
|
|
224
|
+
/**
|
|
225
|
+
* @since 1.0.0
|
|
226
|
+
*/
|
|
227
|
+
[PartTypeId] = PartTypeId;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Represents a part of a message containing content in the model's reasoning
|
|
231
|
+
* that was encrypted by the model provider for safety reasons.
|
|
232
|
+
*
|
|
233
|
+
* @since 1.0.0
|
|
234
|
+
* @category Models
|
|
235
|
+
*/
|
|
236
|
+
exports.ReasoningPart = ReasoningPart;
|
|
237
|
+
class RedactedReasoningPart extends /*#__PURE__*/Schema.TaggedClass("@effect/ai/AiInput/RedactedReasoningPart")("RedactedReasoningPart", {
|
|
238
|
+
/**
|
|
239
|
+
* The content in the reasoning that was encrypted by the model provider for
|
|
240
|
+
* safety reasons.
|
|
241
|
+
*/
|
|
242
|
+
redactedText: Schema.String
|
|
243
|
+
}) {
|
|
244
|
+
/**
|
|
245
|
+
* @since 1.0.0
|
|
246
|
+
*/
|
|
247
|
+
[PartTypeId] = PartTypeId;
|
|
248
|
+
}
|
|
216
249
|
/**
|
|
250
|
+
* Represents the identifier generated by a model when a tool call is requested.
|
|
251
|
+
*
|
|
217
252
|
* @since 1.0.0
|
|
218
|
-
* @category
|
|
253
|
+
* @category Models
|
|
219
254
|
*/
|
|
220
|
-
|
|
255
|
+
exports.RedactedReasoningPart = RedactedReasoningPart;
|
|
256
|
+
const ToolCallId = exports.ToolCallId = InternalCommon.ToolCallId;
|
|
221
257
|
/**
|
|
258
|
+
* Represents a part of a message containing a tool call that the model has
|
|
259
|
+
* requested invocation of.
|
|
260
|
+
*
|
|
222
261
|
* @since 1.0.0
|
|
223
|
-
* @category
|
|
262
|
+
* @category Models
|
|
224
263
|
*/
|
|
225
|
-
class
|
|
226
|
-
role: AiRole.AiRole,
|
|
227
|
-
parts: /*#__PURE__*/Schema_.Chunk(Part)
|
|
228
|
-
}) {
|
|
264
|
+
class ToolCallPart extends /*#__PURE__*/Schema.TaggedClass("@effect/ai/AiInput/ToolCallPart")("ToolCallPart", {
|
|
229
265
|
/**
|
|
230
|
-
*
|
|
266
|
+
* The identifier generated by a model when requesting a tool call.
|
|
231
267
|
*/
|
|
232
|
-
|
|
268
|
+
id: ToolCallId,
|
|
233
269
|
/**
|
|
234
|
-
*
|
|
270
|
+
* The name of the tool to call.
|
|
235
271
|
*/
|
|
236
|
-
|
|
237
|
-
return Predicate.hasProperty(u, MessageTypeId);
|
|
238
|
-
}
|
|
272
|
+
name: Schema.String,
|
|
239
273
|
/**
|
|
240
|
-
*
|
|
274
|
+
* The arguments to call the tool with as a JSON-serializable object that
|
|
275
|
+
* matches the tool call input schema.
|
|
241
276
|
*/
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return new Message({
|
|
245
|
-
role,
|
|
246
|
-
parts: Chunk.of(TextPart.fromContent(input))
|
|
247
|
-
}, constDisableValidation);
|
|
248
|
-
} else if (isPart(input)) {
|
|
249
|
-
return new Message({
|
|
250
|
-
role,
|
|
251
|
-
parts: Chunk.of(input)
|
|
252
|
-
}, constDisableValidation);
|
|
253
|
-
}
|
|
254
|
-
return new Message({
|
|
255
|
-
role,
|
|
256
|
-
parts: Chunk.fromIterable(input)
|
|
257
|
-
}, constDisableValidation);
|
|
258
|
-
}
|
|
277
|
+
params: Schema.Unknown
|
|
278
|
+
}) {
|
|
259
279
|
/**
|
|
260
280
|
* @since 1.0.0
|
|
261
281
|
*/
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
return Option.some(new Message({
|
|
267
|
-
role: response.role,
|
|
268
|
-
parts: Chunk.map(response.parts, part => {
|
|
269
|
-
switch (part._tag) {
|
|
270
|
-
case "Text":
|
|
271
|
-
{
|
|
272
|
-
return TextPart.fromContent(part.content);
|
|
273
|
-
}
|
|
274
|
-
case "ToolCall":
|
|
275
|
-
{
|
|
276
|
-
return new ToolCallPart(part, constDisableValidation);
|
|
277
|
-
}
|
|
278
|
-
case "ImageUrl":
|
|
279
|
-
{
|
|
280
|
-
return new ImageUrlPart(part, constDisableValidation);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
})
|
|
284
|
-
}, constDisableValidation));
|
|
282
|
+
[PartTypeId] = PartTypeId;
|
|
283
|
+
constructor(props, options) {
|
|
284
|
+
super(props, options);
|
|
285
285
|
}
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Represents a part of a message containing the results of tool calls that the
|
|
289
|
+
* model requested invocation of.
|
|
290
|
+
*
|
|
291
|
+
* @since 1.0.0
|
|
292
|
+
* @category Models
|
|
293
|
+
*/
|
|
294
|
+
exports.ToolCallPart = ToolCallPart;
|
|
295
|
+
class ToolCallResultPart extends /*#__PURE__*/Schema.TaggedClass("@effect/ai/AiInput/ToolCallResultPart")("ToolCallResultPart", {
|
|
296
|
+
/**
|
|
297
|
+
* The identifier generated by a model when requesting a tool call.
|
|
298
|
+
*/
|
|
299
|
+
id: ToolCallId,
|
|
300
|
+
/**
|
|
301
|
+
* The result of the tool call as a JSON-serializable object.
|
|
302
|
+
*/
|
|
303
|
+
result: Schema.Unknown
|
|
304
|
+
}) {
|
|
286
305
|
/**
|
|
287
306
|
* @since 1.0.0
|
|
288
307
|
*/
|
|
289
|
-
|
|
290
|
-
const toolParts = [];
|
|
291
|
-
for (const [toolCallId, value] of response.encoded) {
|
|
292
|
-
toolParts.push(new ToolCallResolvedPart({
|
|
293
|
-
toolCallId,
|
|
294
|
-
value
|
|
295
|
-
}, constDisableValidation));
|
|
296
|
-
}
|
|
297
|
-
const toolPartsChunk = Chunk.unsafeFromArray(toolParts);
|
|
298
|
-
return Option.match(Message.fromResponse(response.response), {
|
|
299
|
-
onNone: () => new Message({
|
|
300
|
-
role: AiRole.model,
|
|
301
|
-
parts: toolPartsChunk
|
|
302
|
-
}, constDisableValidation),
|
|
303
|
-
onSome: message => new Message({
|
|
304
|
-
role: message.role,
|
|
305
|
-
parts: Chunk.appendAll(message.parts, toolPartsChunk)
|
|
306
|
-
}, constDisableValidation)
|
|
307
|
-
});
|
|
308
|
-
}
|
|
308
|
+
[PartTypeId] = PartTypeId;
|
|
309
309
|
}
|
|
310
310
|
/**
|
|
311
|
+
* The valid parts of a user message.
|
|
312
|
+
*
|
|
311
313
|
* @since 1.0.0
|
|
312
|
-
* @category
|
|
314
|
+
* @category Models
|
|
313
315
|
*/
|
|
314
|
-
exports.
|
|
315
|
-
const
|
|
316
|
-
if (typeof input !== "string" && Predicate.isIterable(input)) {
|
|
317
|
-
const chunk = Chunk.fromIterable(input);
|
|
318
|
-
if (Chunk.isEmpty(chunk)) {
|
|
319
|
-
return chunk;
|
|
320
|
-
} else if (Message.is(Chunk.unsafeHead(chunk))) {
|
|
321
|
-
return chunk;
|
|
322
|
-
}
|
|
323
|
-
return Chunk.of(Message.fromInput(chunk, options?.role));
|
|
324
|
-
} else if (_AiResponse.AiResponse.is(input)) {
|
|
325
|
-
return Option.match(Message.fromResponse(input), {
|
|
326
|
-
onNone: Chunk.empty,
|
|
327
|
-
onSome: Chunk.of
|
|
328
|
-
});
|
|
329
|
-
} else if (_AiResponse.WithResolved.is(input)) {
|
|
330
|
-
return Chunk.of(Message.fromWithResolved(input));
|
|
331
|
-
} else if (Message.is(input)) {
|
|
332
|
-
return Chunk.of(input);
|
|
333
|
-
}
|
|
334
|
-
return Chunk.of(Message.fromInput(input, options?.role));
|
|
335
|
-
};
|
|
316
|
+
exports.ToolCallResultPart = ToolCallResultPart;
|
|
317
|
+
const UserMessagePart = exports.UserMessagePart = /*#__PURE__*/Schema.Union(TextPart, ImagePart, ImageUrlPart, FilePart, FileUrlPart);
|
|
336
318
|
/**
|
|
319
|
+
* The valid parts of an assistant message.
|
|
320
|
+
*
|
|
337
321
|
* @since 1.0.0
|
|
338
|
-
* @category
|
|
322
|
+
* @category Models
|
|
339
323
|
*/
|
|
340
|
-
exports.
|
|
341
|
-
|
|
324
|
+
const AssistantMessagePart = exports.AssistantMessagePart = /*#__PURE__*/Schema.Union(TextPart, ReasoningPart, RedactedReasoningPart, ToolCallPart);
|
|
325
|
+
/**
|
|
326
|
+
* The valid parts of a tool message.
|
|
327
|
+
*
|
|
328
|
+
* @since 1.0.0
|
|
329
|
+
* @category Models
|
|
330
|
+
*/
|
|
331
|
+
const ToolMessagePart = exports.ToolMessagePart = ToolCallResultPart;
|
|
332
|
+
/**
|
|
333
|
+
* @since 1.0.0
|
|
334
|
+
* @category Guards
|
|
335
|
+
*/
|
|
336
|
+
const is = u => Predicate.hasProperty(u, TypeId);
|
|
342
337
|
/**
|
|
343
338
|
* @since 1.0.0
|
|
344
|
-
* @category
|
|
339
|
+
* @category Guards
|
|
345
340
|
*/
|
|
346
|
-
|
|
341
|
+
exports.is = is;
|
|
342
|
+
const isMessage = u => Predicate.hasProperty(u, MessageTypeId);
|
|
343
|
+
/**
|
|
344
|
+
* @since 1.0.0
|
|
345
|
+
* @category Guards
|
|
346
|
+
*/
|
|
347
|
+
exports.isMessage = isMessage;
|
|
348
|
+
const isPart = u => Predicate.hasProperty(u, PartTypeId);
|
|
347
349
|
/**
|
|
348
350
|
* @since 1.0.0
|
|
349
|
-
* @category
|
|
351
|
+
* @category Constructors
|
|
350
352
|
*/
|
|
351
|
-
|
|
353
|
+
exports.isPart = isPart;
|
|
354
|
+
const empty = exports.empty = /*#__PURE__*/new AiInput({
|
|
355
|
+
messages: []
|
|
356
|
+
});
|
|
352
357
|
/**
|
|
358
|
+
* Constructs a new `AiInput` from raw user input.
|
|
359
|
+
*
|
|
353
360
|
* @since 1.0.0
|
|
354
|
-
* @category
|
|
361
|
+
* @category Constructors
|
|
355
362
|
*/
|
|
356
|
-
|
|
363
|
+
const make = input => {
|
|
364
|
+
if (Predicate.isString(input)) {
|
|
365
|
+
const textPart = new TextPart({
|
|
366
|
+
text: input
|
|
367
|
+
});
|
|
368
|
+
const message = new UserMessage({
|
|
369
|
+
parts: [textPart]
|
|
370
|
+
});
|
|
371
|
+
return new AiInput({
|
|
372
|
+
messages: [message]
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
if (isMessage(input)) {
|
|
376
|
+
return new AiInput({
|
|
377
|
+
messages: [input]
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
if (Predicate.isIterable(input)) {
|
|
381
|
+
return new AiInput({
|
|
382
|
+
messages: Array.from(input)
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
if (is(input)) {
|
|
386
|
+
return input;
|
|
387
|
+
}
|
|
388
|
+
if (AiResponse.isStructured(input)) {
|
|
389
|
+
const assistantMessages = fromResponse(input).messages;
|
|
390
|
+
const toolPart = new ToolCallResultPart({
|
|
391
|
+
id: input.id,
|
|
392
|
+
result: input.value
|
|
393
|
+
});
|
|
394
|
+
const toolMessage = new ToolMessage({
|
|
395
|
+
parts: [toolPart]
|
|
396
|
+
});
|
|
397
|
+
return new AiInput({
|
|
398
|
+
messages: [...assistantMessages, toolMessage]
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
if (AiResponse.hasToolCallResults(input)) {
|
|
402
|
+
const assistantMessages = fromResponse(input).messages;
|
|
403
|
+
const toolParts = [];
|
|
404
|
+
for (const [id, result] of input.encodedResults) {
|
|
405
|
+
toolParts.push(new ToolCallResultPart({
|
|
406
|
+
id,
|
|
407
|
+
result
|
|
408
|
+
}));
|
|
409
|
+
}
|
|
410
|
+
const toolMessage = new ToolMessage({
|
|
411
|
+
parts: toolParts
|
|
412
|
+
});
|
|
413
|
+
return new AiInput({
|
|
414
|
+
messages: [...assistantMessages, toolMessage]
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
return fromResponse(input);
|
|
418
|
+
};
|
|
419
|
+
exports.make = make;
|
|
420
|
+
const EXCLUDED_RESPONSE_PARTS = ["MetadataPart", "ReasoningPart", "RedactedReasoningPart", "FinishPart"];
|
|
421
|
+
const validResponseParts = part => !EXCLUDED_RESPONSE_PARTS.includes(part._tag);
|
|
422
|
+
const fromResponse = response => {
|
|
423
|
+
if (response.parts.length === 0) {
|
|
424
|
+
return empty;
|
|
425
|
+
}
|
|
426
|
+
const parts = response.parts.filter(validResponseParts).map(part => part._tag === "TextPart" ? new TextPart({
|
|
427
|
+
text: part.text
|
|
428
|
+
}) : new ToolCallPart({
|
|
429
|
+
id: part.id,
|
|
430
|
+
name: part.name,
|
|
431
|
+
params: part.params
|
|
432
|
+
}));
|
|
433
|
+
const message = new AssistantMessage({
|
|
434
|
+
parts
|
|
435
|
+
});
|
|
436
|
+
return new AiInput({
|
|
437
|
+
messages: [message]
|
|
438
|
+
});
|
|
439
|
+
};
|
|
357
440
|
/**
|
|
441
|
+
* Concatenates the messages of one `AiInput` onto the messages of another,
|
|
442
|
+
* creating a new `AiInput` with the messages from both.
|
|
443
|
+
*
|
|
358
444
|
* @since 1.0.0
|
|
359
|
-
* @category
|
|
445
|
+
* @category Combination
|
|
360
446
|
*/
|
|
361
|
-
exports.
|
|
362
|
-
|
|
447
|
+
const concat = exports.concat = /*#__PURE__*/(0, _Function.dual)(2, (self, other) => AiInput.make({
|
|
448
|
+
messages: [...self.messages, ...other.messages]
|
|
449
|
+
}));
|
|
363
450
|
//# sourceMappingURL=AiInput.js.map
|