1
1
/**
2
2
* @since 1.0.0
3
3
*/
4
- import type * as Context_ from "effect/Context"
4
+ import * as Context_ from "effect/Context"
5
5
import type * as Effect from "effect/Effect"
6
+ import { constFalse , constTrue } from "effect/Function"
6
7
import * as Option from "effect/Option"
7
8
import { type Pipeable , pipeArguments } from "effect/Pipeable"
8
9
import * as Predicate from "effect/Predicate"
@@ -75,6 +76,8 @@ export interface AiTool<
75
76
*/
76
77
readonly failureSchema : Failure
77
78
79
+ readonly annotations : Context_ . Context < never >
80
+
78
81
/**
79
82
* Adds a requirement on a particular service for the tool call to be able to
80
83
* be executed.
@@ -88,7 +91,8 @@ export interface AiTool<
88
91
Name ,
89
92
Parameters ,
90
93
SuccessSchema ,
91
- Failure
94
+ Failure ,
95
+ Requirements
92
96
>
93
97
94
98
/**
@@ -98,7 +102,8 @@ export interface AiTool<
98
102
Name ,
99
103
Parameters ,
100
104
Success ,
101
- FailureSchema
105
+ FailureSchema ,
106
+ Requirements
102
107
>
103
108
104
109
/**
@@ -111,7 +116,31 @@ export interface AiTool<
111
116
ParametersSchema extends Schema . Struct < infer _ > ? ParametersSchema
112
117
: ParametersSchema extends Schema . Struct . Fields ? Schema . Struct < ParametersSchema >
113
118
: never ,
114
- Success
119
+ Success ,
120
+ Failure ,
121
+ Requirements
122
+ >
123
+
124
+ /**
125
+ * Add an annotation to the tool.
126
+ */
127
+ annotate < I , S > ( tag : Context_ . Tag < I , S > , value : S ) : AiTool <
128
+ Name ,
129
+ Parameters ,
130
+ Success ,
131
+ Failure ,
132
+ Requirements
133
+ >
134
+
135
+ /**
136
+ * Add many annotations to the tool.
137
+ */
138
+ annotateContext < I > ( context : Context_ . Context < I > ) : AiTool <
139
+ Name ,
140
+ Parameters ,
141
+ Success ,
142
+ Failure ,
143
+ Requirements
115
144
>
116
145
}
117
146
@@ -133,6 +162,7 @@ export interface Any extends Pipeable {
133
162
readonly description ?: string | undefined
134
163
readonly key : string
135
164
readonly parametersSchema : AnyStructSchema
165
+ readonly annotations : Context_ . Context < never >
136
166
}
137
167
138
168
/**
@@ -410,6 +440,18 @@ const Proto = {
410
440
? parametersSchema as any
411
441
: Schema . Struct ( parametersSchema as any )
412
442
} )
443
+ } ,
444
+ annotate < I , S > ( this : AnyWithProtocol , tag : Context_ . Tag < I , S > , value : S ) {
445
+ return makeProto ( {
446
+ ...this ,
447
+ annotations : Context_ . add ( this . annotations , tag , value )
448
+ } )
449
+ } ,
450
+ annotateContext < I > ( this : AnyWithProtocol , context : Context_ . Context < I > ) {
451
+ return makeProto ( {
452
+ ...this ,
453
+ annotations : Context_ . merge ( this . annotations , context )
454
+ } )
413
455
}
414
456
}
415
457
@@ -424,6 +466,7 @@ const makeProto = <
424
466
readonly parametersSchema : Parameters
425
467
readonly successSchema : Success
426
468
readonly failureSchema : Failure
469
+ readonly annotations : Context_ . Context < never >
427
470
} ) : AiTool < Name , Parameters , Success > => {
428
471
const self = Object . assign ( Object . create ( Proto ) , options )
429
472
self . key = `@effect/ai/AiTool/${ options . name } `
@@ -474,7 +517,8 @@ export const make = <
474
517
? Schema . Struct ( options ?. parameters as any )
475
518
: constEmptyStruct ,
476
519
successSchema,
477
- failureSchema
520
+ failureSchema,
521
+ annotations : Context_ . empty ( )
478
522
} ) as any
479
523
}
480
524
@@ -492,5 +536,44 @@ export const fromTaggedRequest = <S extends AnyTaggedRequestSchema>(
492
536
description : Option . getOrUndefined ( AST . getDescriptionAnnotation ( ( schema . ast as any ) . to ) ) ,
493
537
parametersSchema : schema as any ,
494
538
successSchema : schema . success as any ,
495
- failureSchema : schema . failure as any
539
+ failureSchema : schema . failure as any ,
540
+ annotations : Context_ . empty ( )
496
541
} )
542
+
543
+ /**
544
+ * @since 1.0.0
545
+ * @category Annotations
546
+ */
547
+ export class Title extends Context_ . Tag ( "@effect/ai/AiTool/Title" ) < Title , string > ( ) { }
548
+
549
+ /**
550
+ * @since 1.0.0
551
+ * @category Annotations
552
+ */
553
+ export class Readonly extends Context_ . Reference < Readonly > ( ) ( "@effect/ai/AiTool/Readonly" , {
554
+ defaultValue : constFalse
555
+ } ) { }
556
+
557
+ /**
558
+ * @since 1.0.0
559
+ * @category Annotations
560
+ */
561
+ export class Destructive extends Context_ . Reference < Destructive > ( ) ( "@effect/ai/AiTool/Destructive" , {
562
+ defaultValue : constTrue
563
+ } ) { }
564
+
565
+ /**
566
+ * @since 1.0.0
567
+ * @category Annotations
568
+ */
569
+ export class Idempotent extends Context_ . Reference < Idempotent > ( ) ( "@effect/ai/AiTool/Idempotent" , {
570
+ defaultValue : constFalse
571
+ } ) { }
572
+
573
+ /**
574
+ * @since 1.0.0
575
+ * @category Annotations
576
+ */
577
+ export class OpenWorld extends Context_ . Reference < OpenWorld > ( ) ( "@effect/ai/AiTool/OpenWorld" , {
578
+ defaultValue : constTrue
579
+ } ) { }
0 commit comments