@effect/ai 0.26.1 → 0.27.1
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/Chat/package.json +6 -0
- package/EmbeddingModel/package.json +6 -0
- package/IdGenerator/package.json +6 -0
- package/LanguageModel/package.json +6 -0
- package/Model/package.json +6 -0
- package/Prompt/package.json +6 -0
- package/Response/package.json +6 -0
- package/Telemetry/package.json +6 -0
- package/Tool/package.json +6 -0
- package/Toolkit/package.json +6 -0
- package/dist/cjs/AiError.js +575 -11
- package/dist/cjs/AiError.js.map +1 -1
- package/dist/cjs/Chat.js +302 -0
- package/dist/cjs/Chat.js.map +1 -0
- package/dist/cjs/EmbeddingModel.js +184 -0
- package/dist/cjs/EmbeddingModel.js.map +1 -0
- package/dist/cjs/IdGenerator.js +255 -0
- package/dist/cjs/IdGenerator.js.map +1 -0
- package/dist/cjs/LanguageModel.js +584 -0
- package/dist/cjs/LanguageModel.js.map +1 -0
- package/dist/cjs/McpServer.js +2 -2
- package/dist/cjs/McpServer.js.map +1 -1
- package/dist/cjs/Model.js +118 -0
- package/dist/cjs/Model.js.map +1 -0
- package/dist/cjs/Prompt.js +649 -0
- package/dist/cjs/Prompt.js.map +1 -0
- package/dist/cjs/Response.js +635 -0
- package/dist/cjs/Response.js.map +1 -0
- package/dist/cjs/Telemetry.js +176 -0
- package/dist/cjs/Telemetry.js.map +1 -0
- package/dist/cjs/Tokenizer.js +87 -8
- package/dist/cjs/Tokenizer.js.map +1 -1
- package/dist/cjs/Tool.js +635 -0
- package/dist/cjs/Tool.js.map +1 -0
- package/dist/cjs/Toolkit.js +279 -0
- package/dist/cjs/Toolkit.js.map +1 -0
- package/dist/cjs/index.js +21 -19
- package/dist/dts/AiError.d.ts +577 -9
- package/dist/dts/AiError.d.ts.map +1 -1
- package/dist/dts/Chat.d.ts +356 -0
- package/dist/dts/Chat.d.ts.map +1 -0
- package/dist/dts/EmbeddingModel.d.ts +153 -0
- package/dist/dts/EmbeddingModel.d.ts.map +1 -0
- package/dist/dts/IdGenerator.d.ts +272 -0
- package/dist/dts/IdGenerator.d.ts.map +1 -0
- package/dist/dts/LanguageModel.d.ts +458 -0
- package/dist/dts/LanguageModel.d.ts.map +1 -0
- package/dist/dts/McpSchema.d.ts +25 -25
- package/dist/dts/McpServer.d.ts +4 -4
- package/dist/dts/McpServer.d.ts.map +1 -1
- package/dist/dts/Model.d.ts +124 -0
- package/dist/dts/Model.d.ts.map +1 -0
- package/dist/dts/Prompt.d.ts +1119 -0
- package/dist/dts/Prompt.d.ts.map +1 -0
- package/dist/dts/Response.d.ts +1519 -0
- package/dist/dts/Response.d.ts.map +1 -0
- package/dist/dts/Telemetry.d.ts +520 -0
- package/dist/dts/Telemetry.d.ts.map +1 -0
- package/dist/dts/Tokenizer.d.ts +131 -13
- package/dist/dts/Tokenizer.d.ts.map +1 -1
- package/dist/dts/Tool.d.ts +884 -0
- package/dist/dts/Tool.d.ts.map +1 -0
- package/dist/dts/Toolkit.d.ts +310 -0
- package/dist/dts/Toolkit.d.ts.map +1 -0
- package/dist/dts/index.d.ts +498 -13
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/AiError.js +570 -10
- package/dist/esm/AiError.js.map +1 -1
- package/dist/esm/Chat.js +291 -0
- package/dist/esm/Chat.js.map +1 -0
- package/dist/esm/EmbeddingModel.js +173 -0
- package/dist/esm/EmbeddingModel.js.map +1 -0
- package/dist/esm/IdGenerator.js +245 -0
- package/dist/esm/IdGenerator.js.map +1 -0
- package/dist/esm/LanguageModel.js +572 -0
- package/dist/esm/LanguageModel.js.map +1 -0
- package/dist/esm/McpServer.js +2 -2
- package/dist/esm/McpServer.js.map +1 -1
- package/dist/esm/Model.js +108 -0
- package/dist/esm/Model.js.map +1 -0
- package/dist/esm/Prompt.js +633 -0
- package/dist/esm/Prompt.js.map +1 -0
- package/dist/esm/Response.js +619 -0
- package/dist/esm/Response.js.map +1 -0
- package/dist/esm/Telemetry.js +166 -0
- package/dist/esm/Telemetry.js.map +1 -0
- package/dist/esm/Tokenizer.js +87 -8
- package/dist/esm/Tokenizer.js.map +1 -1
- package/dist/esm/Tool.js +612 -0
- package/dist/esm/Tool.js.map +1 -0
- package/dist/esm/Toolkit.js +269 -0
- package/dist/esm/Toolkit.js.map +1 -0
- package/dist/esm/index.js +498 -13
- package/dist/esm/index.js.map +1 -1
- package/package.json +76 -68
- package/src/AiError.ts +739 -9
- package/src/Chat.ts +546 -0
- package/src/EmbeddingModel.ts +311 -0
- package/src/IdGenerator.ts +320 -0
- package/src/LanguageModel.ts +1074 -0
- package/src/McpServer.ts +328 -192
- package/src/Model.ts +155 -0
- package/src/Prompt.ts +1621 -0
- package/src/Response.ts +2131 -0
- package/src/Telemetry.ts +655 -0
- package/src/Tokenizer.ts +145 -24
- package/src/Tool.ts +1361 -0
- package/src/Toolkit.ts +516 -0
- package/src/index.ts +499 -13
- package/AiChat/package.json +0 -6
- package/AiEmbeddingModel/package.json +0 -6
- package/AiInput/package.json +0 -6
- package/AiLanguageModel/package.json +0 -6
- package/AiModel/package.json +0 -6
- package/AiResponse/package.json +0 -6
- package/AiTelemetry/package.json +0 -6
- package/AiTool/package.json +0 -6
- package/AiToolkit/package.json +0 -6
- package/dist/cjs/AiChat.js +0 -122
- package/dist/cjs/AiChat.js.map +0 -1
- package/dist/cjs/AiEmbeddingModel.js +0 -109
- package/dist/cjs/AiEmbeddingModel.js.map +0 -1
- package/dist/cjs/AiInput.js +0 -458
- package/dist/cjs/AiInput.js.map +0 -1
- package/dist/cjs/AiLanguageModel.js +0 -351
- package/dist/cjs/AiLanguageModel.js.map +0 -1
- package/dist/cjs/AiModel.js +0 -37
- package/dist/cjs/AiModel.js.map +0 -1
- package/dist/cjs/AiResponse.js +0 -681
- package/dist/cjs/AiResponse.js.map +0 -1
- package/dist/cjs/AiTelemetry.js +0 -58
- package/dist/cjs/AiTelemetry.js.map +0 -1
- package/dist/cjs/AiTool.js +0 -150
- package/dist/cjs/AiTool.js.map +0 -1
- package/dist/cjs/AiToolkit.js +0 -157
- package/dist/cjs/AiToolkit.js.map +0 -1
- package/dist/cjs/internal/common.js +0 -21
- package/dist/cjs/internal/common.js.map +0 -1
- package/dist/dts/AiChat.d.ts +0 -101
- package/dist/dts/AiChat.d.ts.map +0 -1
- package/dist/dts/AiEmbeddingModel.d.ts +0 -65
- package/dist/dts/AiEmbeddingModel.d.ts.map +0 -1
- package/dist/dts/AiInput.d.ts +0 -590
- package/dist/dts/AiInput.d.ts.map +0 -1
- package/dist/dts/AiLanguageModel.d.ts +0 -302
- package/dist/dts/AiLanguageModel.d.ts.map +0 -1
- package/dist/dts/AiModel.d.ts +0 -25
- package/dist/dts/AiModel.d.ts.map +0 -1
- package/dist/dts/AiResponse.d.ts +0 -863
- package/dist/dts/AiResponse.d.ts.map +0 -1
- package/dist/dts/AiTelemetry.d.ts +0 -242
- package/dist/dts/AiTelemetry.d.ts.map +0 -1
- package/dist/dts/AiTool.d.ts +0 -334
- package/dist/dts/AiTool.d.ts.map +0 -1
- package/dist/dts/AiToolkit.d.ts +0 -96
- package/dist/dts/AiToolkit.d.ts.map +0 -1
- package/dist/dts/internal/common.d.ts +0 -2
- package/dist/dts/internal/common.d.ts.map +0 -1
- package/dist/esm/AiChat.js +0 -111
- package/dist/esm/AiChat.js.map +0 -1
- package/dist/esm/AiEmbeddingModel.js +0 -98
- package/dist/esm/AiEmbeddingModel.js.map +0 -1
- package/dist/esm/AiInput.js +0 -433
- package/dist/esm/AiInput.js.map +0 -1
- package/dist/esm/AiLanguageModel.js +0 -340
- package/dist/esm/AiLanguageModel.js.map +0 -1
- package/dist/esm/AiModel.js +0 -29
- package/dist/esm/AiModel.js.map +0 -1
- package/dist/esm/AiResponse.js +0 -657
- package/dist/esm/AiResponse.js.map +0 -1
- package/dist/esm/AiTelemetry.js +0 -48
- package/dist/esm/AiTelemetry.js.map +0 -1
- package/dist/esm/AiTool.js +0 -134
- package/dist/esm/AiTool.js.map +0 -1
- package/dist/esm/AiToolkit.js +0 -147
- package/dist/esm/AiToolkit.js.map +0 -1
- package/dist/esm/internal/common.js +0 -14
- package/dist/esm/internal/common.js.map +0 -1
- package/src/AiChat.ts +0 -251
- package/src/AiEmbeddingModel.ts +0 -169
- package/src/AiInput.ts +0 -602
- package/src/AiLanguageModel.ts +0 -685
- package/src/AiModel.ts +0 -53
- package/src/AiResponse.ts +0 -986
- package/src/AiTelemetry.ts +0 -333
- package/src/AiTool.ts +0 -579
- package/src/AiToolkit.ts +0 -265
- package/src/internal/common.ts +0 -12
package/dist/cjs/Tool.js
ADDED
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.unsafeSecureJsonParse = exports.providerDefined = exports.make = exports.isUserDefined = exports.isProviderDefined = exports.getJsonSchemaFromSchemaAst = exports.getJsonSchema = exports.getDescriptionFromSchemaAst = exports.getDescription = exports.fromTaggedRequest = exports.TypeId = exports.Title = exports.Readonly = exports.ProviderDefinedTypeId = exports.OpenWorld = exports.Idempotent = exports.Destructive = void 0;
|
|
7
|
+
var Context = _interopRequireWildcard(require("effect/Context"));
|
|
8
|
+
var Effect = _interopRequireWildcard(require("effect/Effect"));
|
|
9
|
+
var _Function = require("effect/Function");
|
|
10
|
+
var JsonSchema = _interopRequireWildcard(require("effect/JSONSchema"));
|
|
11
|
+
var Option = _interopRequireWildcard(require("effect/Option"));
|
|
12
|
+
var _Pipeable = require("effect/Pipeable");
|
|
13
|
+
var Predicate = _interopRequireWildcard(require("effect/Predicate"));
|
|
14
|
+
var Schema = _interopRequireWildcard(require("effect/Schema"));
|
|
15
|
+
var AST = _interopRequireWildcard(require("effect/SchemaAST"));
|
|
16
|
+
var AiError = _interopRequireWildcard(require("./AiError.js"));
|
|
17
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
18
|
+
/**
|
|
19
|
+
* The `Tool` module provides functionality for defining and managing tools
|
|
20
|
+
* that language models can call to augment their capabilities.
|
|
21
|
+
*
|
|
22
|
+
* This module enables creation of both user-defined and provider-defined tools,
|
|
23
|
+
* with full schema validation, type safety, and handler support. Tools allow
|
|
24
|
+
* AI models to perform actions like searching databases, calling APIs, or
|
|
25
|
+
* executing code within your application context.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { Tool } from "@effect/ai"
|
|
30
|
+
* import { Schema } from "effect"
|
|
31
|
+
*
|
|
32
|
+
* // Define a simple calculator tool
|
|
33
|
+
* const Calculator = Tool.make("Calculator", {
|
|
34
|
+
* description: "Performs basic arithmetic operations",
|
|
35
|
+
* parameters: {
|
|
36
|
+
* operation: Schema.Literal("add", "subtract", "multiply", "divide"),
|
|
37
|
+
* a: Schema.Number,
|
|
38
|
+
* b: Schema.Number
|
|
39
|
+
* },
|
|
40
|
+
* success: Schema.Number
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @since 1.0.0
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
// =============================================================================
|
|
48
|
+
// Type Ids
|
|
49
|
+
// =============================================================================
|
|
50
|
+
/**
|
|
51
|
+
* Unique identifier for user-defined tools.
|
|
52
|
+
*
|
|
53
|
+
* @since 1.0.0
|
|
54
|
+
* @category Type Ids
|
|
55
|
+
*/
|
|
56
|
+
const TypeId = exports.TypeId = "~@effect/ai/Tool";
|
|
57
|
+
/**
|
|
58
|
+
* Unique identifier for provider-defined tools.
|
|
59
|
+
*
|
|
60
|
+
* @since 1.0.0
|
|
61
|
+
* @category Type Ids
|
|
62
|
+
*/
|
|
63
|
+
const ProviderDefinedTypeId = exports.ProviderDefinedTypeId = "~@effect/ai/Tool/ProviderDefined";
|
|
64
|
+
// =============================================================================
|
|
65
|
+
// Type Guards
|
|
66
|
+
// =============================================================================
|
|
67
|
+
/**
|
|
68
|
+
* Type guard to check if a value is a user-defined tool.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { Tool } from "@effect/ai"
|
|
73
|
+
* import { Schema } from "effect"
|
|
74
|
+
*
|
|
75
|
+
* const UserDefinedTool = Tool.make("Calculator", {
|
|
76
|
+
* description: "Performs basic arithmetic operations",
|
|
77
|
+
* parameters: {
|
|
78
|
+
* operation: Schema.Literal("add", "subtract", "multiply", "divide"),
|
|
79
|
+
* a: Schema.Number,
|
|
80
|
+
* b: Schema.Number
|
|
81
|
+
* },
|
|
82
|
+
* success: Schema.Number
|
|
83
|
+
* })
|
|
84
|
+
*
|
|
85
|
+
* const ProviderDefinedTool = Tool.providerDefined({
|
|
86
|
+
* id: "openai.web_search",
|
|
87
|
+
* toolkitName: "WebSearch",
|
|
88
|
+
* providerName: "web_search",
|
|
89
|
+
* args: {
|
|
90
|
+
* query: Schema.String
|
|
91
|
+
* },
|
|
92
|
+
* success: Schema.Struct({
|
|
93
|
+
* results: Schema.Array(Schema.Struct({
|
|
94
|
+
* title: Schema.String,
|
|
95
|
+
* url: Schema.String,
|
|
96
|
+
* snippet: Schema.String
|
|
97
|
+
* }))
|
|
98
|
+
* })
|
|
99
|
+
* })
|
|
100
|
+
*
|
|
101
|
+
* console.log(Tool.isUserDefined(UserDefinedTool)) // true
|
|
102
|
+
* console.log(Tool.isUserDefined(ProviderDefinedTool)) // false
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @since 1.0.0
|
|
106
|
+
* @category Guards
|
|
107
|
+
*/
|
|
108
|
+
const isUserDefined = u => Predicate.hasProperty(u, TypeId) && !isProviderDefined(u);
|
|
109
|
+
/**
|
|
110
|
+
* Type guard to check if a value is a provider-defined tool.
|
|
111
|
+
*
|
|
112
|
+
* @param u - The value to check
|
|
113
|
+
* @returns `true` if the value is a provider-defined `Tool`, `false` otherwise
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* import { Tool } from "@effect/ai"
|
|
118
|
+
* import { Schema } from "effect"
|
|
119
|
+
*
|
|
120
|
+
* const UserDefinedTool = Tool.make("Calculator", {
|
|
121
|
+
* description: "Performs basic arithmetic operations",
|
|
122
|
+
* parameters: {
|
|
123
|
+
* operation: Schema.Literal("add", "subtract", "multiply", "divide"),
|
|
124
|
+
* a: Schema.Number,
|
|
125
|
+
* b: Schema.Number
|
|
126
|
+
* },
|
|
127
|
+
* success: Schema.Number
|
|
128
|
+
* })
|
|
129
|
+
*
|
|
130
|
+
* const ProviderDefinedTool = Tool.providerDefined({
|
|
131
|
+
* id: "openai.web_search",
|
|
132
|
+
* toolkitName: "WebSearch",
|
|
133
|
+
* providerName: "web_search",
|
|
134
|
+
* args: {
|
|
135
|
+
* query: Schema.String
|
|
136
|
+
* },
|
|
137
|
+
* success: Schema.Struct({
|
|
138
|
+
* results: Schema.Array(Schema.Struct({
|
|
139
|
+
* title: Schema.String,
|
|
140
|
+
* url: Schema.String,
|
|
141
|
+
* snippet: Schema.String
|
|
142
|
+
* }))
|
|
143
|
+
* })
|
|
144
|
+
* })
|
|
145
|
+
*
|
|
146
|
+
* console.log(Tool.isUserDefined(UserDefinedTool)) // false
|
|
147
|
+
* console.log(Tool.isUserDefined(ProviderDefinedTool)) // true
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @since 1.0.0
|
|
151
|
+
* @category Guards
|
|
152
|
+
*/
|
|
153
|
+
exports.isUserDefined = isUserDefined;
|
|
154
|
+
const isProviderDefined = u => Predicate.hasProperty(u, ProviderDefinedTypeId);
|
|
155
|
+
// =============================================================================
|
|
156
|
+
// Constructors
|
|
157
|
+
// =============================================================================
|
|
158
|
+
exports.isProviderDefined = isProviderDefined;
|
|
159
|
+
const Proto = {
|
|
160
|
+
[TypeId]: {
|
|
161
|
+
_Requirements: _Function.identity
|
|
162
|
+
},
|
|
163
|
+
pipe() {
|
|
164
|
+
return (0, _Pipeable.pipeArguments)(this, arguments);
|
|
165
|
+
},
|
|
166
|
+
addDependency() {
|
|
167
|
+
return userDefinedProto({
|
|
168
|
+
...this
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
setParameters(parametersSchema) {
|
|
172
|
+
return userDefinedProto({
|
|
173
|
+
...this,
|
|
174
|
+
parametersSchema: Schema.isSchema(parametersSchema) ? parametersSchema : Schema.Struct(parametersSchema)
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
setSuccess(successSchema) {
|
|
178
|
+
return userDefinedProto({
|
|
179
|
+
...this,
|
|
180
|
+
successSchema
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
setFailure(failureSchema) {
|
|
184
|
+
return userDefinedProto({
|
|
185
|
+
...this,
|
|
186
|
+
failureSchema
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
annotate(tag, value) {
|
|
190
|
+
return userDefinedProto({
|
|
191
|
+
...this,
|
|
192
|
+
annotations: Context.add(this.annotations, tag, value)
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
annotateContext(context) {
|
|
196
|
+
return userDefinedProto({
|
|
197
|
+
...this,
|
|
198
|
+
annotations: Context.merge(this.annotations, context)
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const ProviderDefinedProto = {
|
|
203
|
+
...Proto,
|
|
204
|
+
[ProviderDefinedTypeId]: ProviderDefinedTypeId,
|
|
205
|
+
decodeResult(result) {
|
|
206
|
+
return Schema.decodeUnknown(this.successSchema)(result).pipe(Effect.orElse(() => Schema.decodeUnknown(this.failureSchema)(result)), Effect.mapError(cause => new AiError.MalformedOutput({
|
|
207
|
+
module: "Tool",
|
|
208
|
+
method: "ProviderDefined.decodeResult",
|
|
209
|
+
description: `Failed to decode the result of provider-defined tool '${this.name}'`,
|
|
210
|
+
cause
|
|
211
|
+
})));
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
const userDefinedProto = options => {
|
|
215
|
+
const self = Object.assign(Object.create(Proto), options);
|
|
216
|
+
self.id = `@effect/ai/Tool/${options.name}`;
|
|
217
|
+
return self;
|
|
218
|
+
};
|
|
219
|
+
const providerDefinedProto = options => Object.assign(Object.create(ProviderDefinedProto), options);
|
|
220
|
+
const constEmptyStruct = /*#__PURE__*/Schema.Struct({});
|
|
221
|
+
/**
|
|
222
|
+
* Creates a user-defined tool with the specified name and configuration.
|
|
223
|
+
*
|
|
224
|
+
* This is the primary constructor for creating custom tools that AI models
|
|
225
|
+
* can call. The tool definition includes parameter validation, success/failure
|
|
226
|
+
* schemas, and optional service dependencies.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* import { Tool } from "@effect/ai"
|
|
231
|
+
* import { Schema } from "effect"
|
|
232
|
+
*
|
|
233
|
+
* // Simple tool with no parameters
|
|
234
|
+
* const GetCurrentTime = Tool.make("GetCurrentTime", {
|
|
235
|
+
* description: "Returns the current timestamp",
|
|
236
|
+
* success: Schema.Number
|
|
237
|
+
* })
|
|
238
|
+
* ```
|
|
239
|
+
*
|
|
240
|
+
* @since 1.0.0
|
|
241
|
+
* @category Constructors
|
|
242
|
+
*/
|
|
243
|
+
const make = (
|
|
244
|
+
/**
|
|
245
|
+
* The unique name identifier for this tool.
|
|
246
|
+
*/
|
|
247
|
+
name, options) => {
|
|
248
|
+
const successSchema = options?.success ?? Schema.Void;
|
|
249
|
+
const failureSchema = options?.failure ?? Schema.Never;
|
|
250
|
+
return userDefinedProto({
|
|
251
|
+
name,
|
|
252
|
+
description: options?.description,
|
|
253
|
+
parametersSchema: options?.parameters ? Schema.Struct(options?.parameters) : constEmptyStruct,
|
|
254
|
+
successSchema,
|
|
255
|
+
failureSchema,
|
|
256
|
+
annotations: Context.empty()
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* Creates a provider-defined tool which leverages functionality built into a
|
|
261
|
+
* large language model provider (e.g. web search, code execution).
|
|
262
|
+
*
|
|
263
|
+
* These tools are executed by the large language model provider rather than
|
|
264
|
+
* by your application. However, they can optionally require custom handlers
|
|
265
|
+
* implemented in your application to process provider generated results.
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* import { Tool } from "@effect/ai"
|
|
270
|
+
* import { Schema } from "effect"
|
|
271
|
+
*
|
|
272
|
+
* // Web search tool provided by OpenAI
|
|
273
|
+
* const WebSearch = Tool.providerDefined({
|
|
274
|
+
* id: "openai.web_search",
|
|
275
|
+
* toolkitName: "WebSearch",
|
|
276
|
+
* providerName: "web_search",
|
|
277
|
+
* args: {
|
|
278
|
+
* query: Schema.String
|
|
279
|
+
* },
|
|
280
|
+
* success: Schema.Struct({
|
|
281
|
+
* results: Schema.Array(Schema.Struct({
|
|
282
|
+
* title: Schema.String,
|
|
283
|
+
* url: Schema.String,
|
|
284
|
+
* content: Schema.String
|
|
285
|
+
* }))
|
|
286
|
+
* })
|
|
287
|
+
* })
|
|
288
|
+
* ```
|
|
289
|
+
*
|
|
290
|
+
* @since 1.0.0
|
|
291
|
+
* @category Constructors
|
|
292
|
+
*/
|
|
293
|
+
exports.make = make;
|
|
294
|
+
const providerDefined = options => args => {
|
|
295
|
+
const successSchema = options?.success ?? Schema.Void;
|
|
296
|
+
const failureSchema = options?.failure ?? Schema.Never;
|
|
297
|
+
const resultSchema = Schema.EitherFromUnion({
|
|
298
|
+
right: successSchema,
|
|
299
|
+
left: failureSchema
|
|
300
|
+
});
|
|
301
|
+
return providerDefinedProto({
|
|
302
|
+
id: options.id,
|
|
303
|
+
name: options.toolkitName,
|
|
304
|
+
providerName: options.providerName,
|
|
305
|
+
args,
|
|
306
|
+
argsSchema: Schema.Struct(options.args),
|
|
307
|
+
requiresHandler: options.requiresHandler ?? false,
|
|
308
|
+
parametersSchema: options?.parameters ? Schema.Struct(options?.parameters) : constEmptyStruct,
|
|
309
|
+
successSchema: options.requiresHandler === true ? successSchema : resultSchema,
|
|
310
|
+
failureSchema: options.requiresHandler === true ? failureSchema : Schema.Never
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* Creates a Tool from a Schema.TaggedRequest.
|
|
315
|
+
*
|
|
316
|
+
* This utility function converts Effect's TaggedRequest schemas into Tool
|
|
317
|
+
* definitions, automatically mapping the request parameters, success, and
|
|
318
|
+
* failure schemas.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```ts
|
|
322
|
+
* import { Tool } from "@effect/ai"
|
|
323
|
+
* import { Schema } from "effect"
|
|
324
|
+
*
|
|
325
|
+
* // Define a tagged request for user operations
|
|
326
|
+
* class GetUser extends Schema.TaggedRequest<GetUser>()("GetUser", {
|
|
327
|
+
* success: Schema.Struct({
|
|
328
|
+
* id: Schema.Number,
|
|
329
|
+
* name: Schema.String,
|
|
330
|
+
* email: Schema.String
|
|
331
|
+
* }),
|
|
332
|
+
* failure: Schema.Struct({
|
|
333
|
+
* error: Schema.Literal("UserNotFound", "DatabaseError"),
|
|
334
|
+
* message: Schema.String
|
|
335
|
+
* }),
|
|
336
|
+
* payload: {
|
|
337
|
+
* userId: Schema.Number
|
|
338
|
+
* }
|
|
339
|
+
* }) {}
|
|
340
|
+
*
|
|
341
|
+
* // Convert to a Tool
|
|
342
|
+
* const getUserTool = Tool.fromTaggedRequest(GetUser)
|
|
343
|
+
* ```
|
|
344
|
+
*
|
|
345
|
+
* @since 1.0.0
|
|
346
|
+
* @category Constructors
|
|
347
|
+
*/
|
|
348
|
+
exports.providerDefined = providerDefined;
|
|
349
|
+
const fromTaggedRequest = schema => userDefinedProto({
|
|
350
|
+
name: schema._tag,
|
|
351
|
+
description: Option.getOrUndefined(AST.getDescriptionAnnotation(schema.ast.to)),
|
|
352
|
+
parametersSchema: schema,
|
|
353
|
+
successSchema: schema.success,
|
|
354
|
+
failureSchema: schema.failure,
|
|
355
|
+
annotations: Context.empty()
|
|
356
|
+
});
|
|
357
|
+
// =============================================================================
|
|
358
|
+
// Utilities
|
|
359
|
+
// =============================================================================
|
|
360
|
+
/**
|
|
361
|
+
* Extracts the description from a tool's metadata.
|
|
362
|
+
*
|
|
363
|
+
* Returns the tool's description if explicitly set, otherwise attempts to
|
|
364
|
+
* extract it from the parameter schema's AST annotations.
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* ```ts
|
|
368
|
+
* import { Tool } from "@effect/ai"
|
|
369
|
+
*
|
|
370
|
+
* const myTool = Tool.make("example", {
|
|
371
|
+
* description: "This is an example tool"
|
|
372
|
+
* })
|
|
373
|
+
*
|
|
374
|
+
* const description = Tool.getDescription(myTool)
|
|
375
|
+
* console.log(description) // "This is an example tool"
|
|
376
|
+
* ```
|
|
377
|
+
*
|
|
378
|
+
* @since 1.0.0
|
|
379
|
+
* @category Utilities
|
|
380
|
+
*/
|
|
381
|
+
exports.fromTaggedRequest = fromTaggedRequest;
|
|
382
|
+
const getDescription = (
|
|
383
|
+
/**
|
|
384
|
+
* The tool to get the description from.
|
|
385
|
+
*/
|
|
386
|
+
tool) => {
|
|
387
|
+
if (Predicate.isNotUndefined(tool.description)) {
|
|
388
|
+
return tool.description;
|
|
389
|
+
}
|
|
390
|
+
return getDescriptionFromSchemaAst(tool.parametersSchema.ast);
|
|
391
|
+
};
|
|
392
|
+
/**
|
|
393
|
+
* @since 1.0.0
|
|
394
|
+
* @category Utilities
|
|
395
|
+
*/
|
|
396
|
+
exports.getDescription = getDescription;
|
|
397
|
+
const getDescriptionFromSchemaAst = ast => {
|
|
398
|
+
const annotations = ast._tag === "Transformation" ? {
|
|
399
|
+
...ast.to.annotations,
|
|
400
|
+
...ast.annotations
|
|
401
|
+
} : ast.annotations;
|
|
402
|
+
return AST.DescriptionAnnotationId in annotations ? annotations[AST.DescriptionAnnotationId] : undefined;
|
|
403
|
+
};
|
|
404
|
+
/**
|
|
405
|
+
* Generates a JSON Schema for a tool.
|
|
406
|
+
*
|
|
407
|
+
* This function creates a JSON Schema representation that can be used by
|
|
408
|
+
* large language models to indicate the structure and type of the parameters
|
|
409
|
+
* that a given tool call should receive.
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
* ```ts
|
|
413
|
+
* import { Tool } from "@effect/ai"
|
|
414
|
+
* import { Schema } from "effect"
|
|
415
|
+
*
|
|
416
|
+
* const weatherTool = Tool.make("get_weather", {
|
|
417
|
+
* parameters: {
|
|
418
|
+
* location: Schema.String,
|
|
419
|
+
* units: Schema.optional(Schema.Literal("celsius", "fahrenheit"))
|
|
420
|
+
* }
|
|
421
|
+
* })
|
|
422
|
+
*
|
|
423
|
+
* const jsonSchema = Tool.getJsonSchema(weatherTool)
|
|
424
|
+
* console.log(jsonSchema)
|
|
425
|
+
* // {
|
|
426
|
+
* // type: "object",
|
|
427
|
+
* // properties: {
|
|
428
|
+
* // location: { type: "string" },
|
|
429
|
+
* // units: { type: "string", enum: ["celsius", "fahrenheit"] }
|
|
430
|
+
* // },
|
|
431
|
+
* // required: ["location"]
|
|
432
|
+
* // }
|
|
433
|
+
* ```
|
|
434
|
+
*
|
|
435
|
+
* @since 1.0.0
|
|
436
|
+
* @category Utilities
|
|
437
|
+
*/
|
|
438
|
+
exports.getDescriptionFromSchemaAst = getDescriptionFromSchemaAst;
|
|
439
|
+
const getJsonSchema = tool => getJsonSchemaFromSchemaAst(tool.parametersSchema.ast);
|
|
440
|
+
/**
|
|
441
|
+
* @since 1.0.0
|
|
442
|
+
* @category Utilities
|
|
443
|
+
*/
|
|
444
|
+
exports.getJsonSchema = getJsonSchema;
|
|
445
|
+
const getJsonSchemaFromSchemaAst = ast => {
|
|
446
|
+
const props = AST.getPropertySignatures(ast);
|
|
447
|
+
if (props.length === 0) {
|
|
448
|
+
return {
|
|
449
|
+
type: "object",
|
|
450
|
+
properties: {},
|
|
451
|
+
required: [],
|
|
452
|
+
additionalProperties: false
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
const $defs = {};
|
|
456
|
+
const schema = JsonSchema.fromAST(ast, {
|
|
457
|
+
definitions: $defs,
|
|
458
|
+
topLevelReferenceStrategy: "skip"
|
|
459
|
+
});
|
|
460
|
+
if (Object.keys($defs).length === 0) return schema;
|
|
461
|
+
schema.$defs = $defs;
|
|
462
|
+
return schema;
|
|
463
|
+
};
|
|
464
|
+
// =============================================================================
|
|
465
|
+
// Annotations
|
|
466
|
+
// =============================================================================
|
|
467
|
+
/**
|
|
468
|
+
* Annotation for providing a human-readable title for tools.
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* ```ts
|
|
472
|
+
* import { Tool } from "@effect/ai"
|
|
473
|
+
*
|
|
474
|
+
* const myTool = Tool.make("calculate_tip")
|
|
475
|
+
* .annotate(Tool.Title, "Tip Calculator")
|
|
476
|
+
* ```
|
|
477
|
+
*
|
|
478
|
+
* @since 1.0.0
|
|
479
|
+
* @category Annotations
|
|
480
|
+
*/
|
|
481
|
+
exports.getJsonSchemaFromSchemaAst = getJsonSchemaFromSchemaAst;
|
|
482
|
+
class Title extends /*#__PURE__*/Context.Tag("@effect/ai/Tool/Title")() {}
|
|
483
|
+
/**
|
|
484
|
+
* Annotation indicating whether a tool only reads data without making changes.
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* ```ts
|
|
488
|
+
* import { Tool } from "@effect/ai"
|
|
489
|
+
*
|
|
490
|
+
* const readOnlyTool = Tool.make("get_user_info")
|
|
491
|
+
* .annotate(Tool.Readonly, true)
|
|
492
|
+
* ```
|
|
493
|
+
*
|
|
494
|
+
* @since 1.0.0
|
|
495
|
+
* @category Annotations
|
|
496
|
+
*/
|
|
497
|
+
exports.Title = Title;
|
|
498
|
+
class Readonly extends /*#__PURE__*/Context.Reference()("@effect/ai/Tool/Readonly", {
|
|
499
|
+
defaultValue: _Function.constFalse
|
|
500
|
+
}) {}
|
|
501
|
+
/**
|
|
502
|
+
* Annotation indicating whether a tool performs destructive operations.
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* ```ts
|
|
506
|
+
* import { Tool } from "@effect/ai"
|
|
507
|
+
*
|
|
508
|
+
* const safeTool = Tool.make("search_database")
|
|
509
|
+
* .annotate(Tool.Destructive, false)
|
|
510
|
+
* ```
|
|
511
|
+
*
|
|
512
|
+
* @since 1.0.0
|
|
513
|
+
* @category Annotations
|
|
514
|
+
*/
|
|
515
|
+
exports.Readonly = Readonly;
|
|
516
|
+
class Destructive extends /*#__PURE__*/Context.Reference()("@effect/ai/Tool/Destructive", {
|
|
517
|
+
defaultValue: _Function.constTrue
|
|
518
|
+
}) {}
|
|
519
|
+
/**
|
|
520
|
+
* Annotation indicating whether a tool can be called multiple times safely.
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```ts
|
|
524
|
+
* import { Tool } from "@effect/ai"
|
|
525
|
+
*
|
|
526
|
+
* const idempotentTool = Tool.make("get_current_time")
|
|
527
|
+
* .annotate(Tool.Idempotent, true)
|
|
528
|
+
* ```
|
|
529
|
+
*
|
|
530
|
+
* @since 1.0.0
|
|
531
|
+
* @category Annotations
|
|
532
|
+
*/
|
|
533
|
+
exports.Destructive = Destructive;
|
|
534
|
+
class Idempotent extends /*#__PURE__*/Context.Reference()("@effect/ai/Tool/Idempotent", {
|
|
535
|
+
defaultValue: _Function.constFalse
|
|
536
|
+
}) {}
|
|
537
|
+
/**
|
|
538
|
+
* Annotation indicating whether a tool can handle arbitrary external data.
|
|
539
|
+
*
|
|
540
|
+
* @example
|
|
541
|
+
* ```ts
|
|
542
|
+
* import { Tool } from "@effect/ai"
|
|
543
|
+
*
|
|
544
|
+
* const restrictedTool = Tool.make("internal_operation")
|
|
545
|
+
* .annotate(Tool.OpenWorld, false)
|
|
546
|
+
* ```
|
|
547
|
+
*
|
|
548
|
+
* @since 1.0.0
|
|
549
|
+
* @category Annotations
|
|
550
|
+
*/
|
|
551
|
+
exports.Idempotent = Idempotent;
|
|
552
|
+
class OpenWorld extends /*#__PURE__*/Context.Reference()("@effect/ai/Tool/OpenWorld", {
|
|
553
|
+
defaultValue: _Function.constTrue
|
|
554
|
+
}) {}
|
|
555
|
+
// Licensed under BSD-3-Clause (below code only)
|
|
556
|
+
// Code adapted from https://github.com/fastify/secure-json-parse/blob/783fcb1b5434709466759847cec974381939673a/index.js
|
|
557
|
+
//
|
|
558
|
+
// Copyright (c) Effectful Technologies, Inc (https://effectful.co)
|
|
559
|
+
// Copyright (c) 2019 The Fastify Team
|
|
560
|
+
// Copyright (c) 2019, Sideway Inc, and project contributors
|
|
561
|
+
// All rights reserved.
|
|
562
|
+
//
|
|
563
|
+
// The complete list of contributors can be found at:
|
|
564
|
+
// - https://github.com/hapijs/bourne/graphs/contributors
|
|
565
|
+
// - https://github.com/fastify/secure-json-parse/graphs/contributors
|
|
566
|
+
// - https://github.com/Effect-TS/effect/commits/main/packages/ai/ai/src/Tool.ts
|
|
567
|
+
//
|
|
568
|
+
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
569
|
+
//
|
|
570
|
+
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
571
|
+
//
|
|
572
|
+
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
573
|
+
//
|
|
574
|
+
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
575
|
+
//
|
|
576
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
577
|
+
exports.OpenWorld = OpenWorld;
|
|
578
|
+
const suspectProtoRx = /"__proto__"\s*:/;
|
|
579
|
+
const suspectConstructorRx = /"constructor"\s*:/;
|
|
580
|
+
function _parse(text) {
|
|
581
|
+
// Parse normally
|
|
582
|
+
const obj = JSON.parse(text);
|
|
583
|
+
// Ignore null and non-objects
|
|
584
|
+
if (obj === null || typeof obj !== "object") {
|
|
585
|
+
return obj;
|
|
586
|
+
}
|
|
587
|
+
if (suspectProtoRx.test(text) === false && suspectConstructorRx.test(text) === false) {
|
|
588
|
+
return obj;
|
|
589
|
+
}
|
|
590
|
+
// Scan result for proto keys
|
|
591
|
+
return filter(obj);
|
|
592
|
+
}
|
|
593
|
+
function filter(obj) {
|
|
594
|
+
let next = [obj];
|
|
595
|
+
while (next.length) {
|
|
596
|
+
const nodes = next;
|
|
597
|
+
next = [];
|
|
598
|
+
for (const node of nodes) {
|
|
599
|
+
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
600
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
601
|
+
}
|
|
602
|
+
if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
603
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
604
|
+
}
|
|
605
|
+
for (const key in node) {
|
|
606
|
+
const value = node[key];
|
|
607
|
+
if (value && typeof value === "object") {
|
|
608
|
+
next.push(value);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
return obj;
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* **Unsafe**: This function will throw an error if an insecure property is
|
|
617
|
+
* found in the parsed JSON or if the provided JSON text is not parseable.
|
|
618
|
+
*
|
|
619
|
+
* @since 1.0.0
|
|
620
|
+
* @category Utilities
|
|
621
|
+
*/
|
|
622
|
+
const unsafeSecureJsonParse = text => {
|
|
623
|
+
// Performance optimization, see https://github.com/fastify/secure-json-parse/pull/90
|
|
624
|
+
const {
|
|
625
|
+
stackTraceLimit
|
|
626
|
+
} = Error;
|
|
627
|
+
Error.stackTraceLimit = 0;
|
|
628
|
+
try {
|
|
629
|
+
return _parse(text);
|
|
630
|
+
} finally {
|
|
631
|
+
Error.stackTraceLimit = stackTraceLimit;
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
exports.unsafeSecureJsonParse = unsafeSecureJsonParse;
|
|
635
|
+
//# sourceMappingURL=Tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tool.js","names":["Context","_interopRequireWildcard","require","Effect","_Function","JsonSchema","Option","_Pipeable","Predicate","Schema","AST","AiError","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","TypeId","exports","ProviderDefinedTypeId","isUserDefined","u","hasProperty","isProviderDefined","Proto","_Requirements","identity","pipe","pipeArguments","arguments","addDependency","userDefinedProto","setParameters","parametersSchema","isSchema","Struct","setSuccess","successSchema","setFailure","failureSchema","annotate","tag","value","annotations","add","annotateContext","context","merge","ProviderDefinedProto","decodeResult","result","decodeUnknown","orElse","mapError","cause","MalformedOutput","module","method","description","name","options","self","assign","create","id","providerDefinedProto","constEmptyStruct","make","success","Void","failure","Never","parameters","empty","providerDefined","args","resultSchema","EitherFromUnion","right","left","toolkitName","providerName","argsSchema","requiresHandler","fromTaggedRequest","schema","_tag","getOrUndefined","getDescriptionAnnotation","ast","to","getDescription","tool","isNotUndefined","getDescriptionFromSchemaAst","DescriptionAnnotationId","undefined","getJsonSchema","getJsonSchemaFromSchemaAst","props","getPropertySignatures","length","type","properties","required","additionalProperties","$defs","fromAST","definitions","topLevelReferenceStrategy","keys","Title","Tag","Readonly","Reference","defaultValue","constFalse","Destructive","constTrue","Idempotent","OpenWorld","suspectProtoRx","suspectConstructorRx","_parse","text","obj","JSON","parse","test","filter","next","nodes","node","prototype","SyntaxError","constructor","key","push","unsafeSecureJsonParse","stackTraceLimit","Error"],"sources":["../../src/Tool.ts"],"sourcesContent":[null],"mappings":";;;;;;AA4BA,IAAAA,OAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,uBAAA,CAAAC,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAJ,uBAAA,CAAAC,OAAA;AACA,IAAAI,MAAA,GAAAL,uBAAA,CAAAC,OAAA;AAEA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAP,uBAAA,CAAAC,OAAA;AACA,IAAAO,MAAA,GAAAR,uBAAA,CAAAC,OAAA;AACA,IAAAQ,GAAA,GAAAT,uBAAA,CAAAC,OAAA;AAEA,IAAAS,OAAA,GAAAV,uBAAA,CAAAC,OAAA;AAAuC,SAAAD,wBAAAW,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAb,uBAAA,YAAAA,CAAAW,CAAA,EAAAC,CAAA,SAAAA,CAA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